-
Notifications
You must be signed in to change notification settings - Fork 539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(server): Remove dependency on common-utils #23998
Draft
alexvy86
wants to merge
38
commits into
microsoft:main
Choose a base branch
from
alexvy86:ff-remove-common-utils
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+7,630
−291
Draft
Changes from 30 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
9e6eec4
Copy Deferred to server-services-core
alexvy86 3d5e648
Remove common-utils from server-services-core
alexvy86 0cc0179
Remove common-utils from server-lambdas
alexvy86 f6d3793
Remove common-utils from server-memory-orderer
alexvy86 ea50fd7
Remove common-utils from server-routerlicious-base
alexvy86 dac8602
Remove common-utils from server-services
alexvy86 a0041bb
Remove common-utils from server-services-shared
alexvy86 8d42abc
Remove common-utils from server-services-telemetry
alexvy86 11f9146
Remove common-utils from tinylicious
alexvy86 647b54e
Remove common-utils from server-test-utils
alexvy86 a1c251c
Move to new server-common-utils
alexvy86 fb6d9f2
Move protocol-base to server-common-utils
alexvy86 c9bf24a
Move some things to the single packages that use them
alexvy86 3fbb74b
Remove commented code
alexvy86 800b0e0
Remove some deprecated tags
alexvy86 cc345b6
Formatting
alexvy86 b3ee169
Use assert from server-common-utils
alexvy86 7c83341
Formatting
alexvy86 a883e05
Remove more unneded lint disable comments
alexvy86 01001de
Fix docs
alexvy86 abc1360
Undo assert changes
alexvy86 545804d
Cleanup and fix build of server-common-utils
alexvy86 5ae6f21
Cleanup tests; remove jest
alexvy86 d8e488d
Move assert to server-services-client
alexvy86 186ef46
Move Deferred to services-core
alexvy86 2d60abf
Move delay to services-core
alexvy86 d533b2b
Move unreachable to the packages that use it
alexvy86 02eb780
Move TypedEventEmitter
alexvy86 838bc6f
Move node+browser utils to services-client
alexvy86 10730f8
Remove server-common-utils
alexvy86 3b0fe6d
Cleanup
alexvy86 10f6549
Add puppeteer devDep
alexvy86 c479fa7
Fix protocol-base use of events/events_pkg
alexvy86 fe43244
Try adding missing jest-environment-puppeteer
alexvy86 e8981f0
Change how we run jest tests in CI
alexvy86 1e25cd4
Dep for jest tests in Dockerfile
alexvy86 617ea8a
More deps for jest tests
alexvy86 fe22d79
More deps
alexvy86 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
/** | ||
* Interface for a comparer. | ||
*/ | ||
export interface IComparer<T> { | ||
/** | ||
* The minimum value of type T. | ||
*/ | ||
min: T; | ||
|
||
/** | ||
* Compare the two value | ||
* | ||
* @returns 0 if the value is equal, negative number if a is smaller then b, positive number otherwise | ||
*/ | ||
compare(a: T, b: T): number; | ||
} | ||
|
||
/** | ||
* Interface to a node in {@link Heap}. | ||
*/ | ||
export interface IHeapNode<T> { | ||
value: T; | ||
position: number; | ||
} | ||
|
||
/** | ||
* Ordered {@link https://en.wikipedia.org/wiki/Heap_(data_structure) | Heap} data structure implementation. | ||
*/ | ||
export class Heap<T> { | ||
private L: IHeapNode<T>[]; | ||
|
||
/** | ||
* Creates an instance of `Heap` with comparer. | ||
* @param comp - A comparer that specify how elements are ordered. | ||
*/ | ||
constructor(public comp: IComparer<T>) { | ||
this.L = [{ value: comp.min, position: 0 }]; | ||
} | ||
|
||
/** | ||
* Return the smallest element in the heap as determined by the order of the comparer | ||
* | ||
* @returns Heap node containing the smallest element | ||
*/ | ||
public peek(): IHeapNode<T> { | ||
return this.L[1]; | ||
} | ||
|
||
/** | ||
* Get and remove the smallest element in the heap as determined by the order of the comparer | ||
* | ||
* @returns The smallest value in the heap | ||
*/ | ||
public get(): T { | ||
this.swap(1, this.count()); | ||
const x = this.L.pop(); | ||
this.fixdown(1); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return x!.value; | ||
} | ||
|
||
/** | ||
* Add a value to the heap | ||
* | ||
* @param x - value to add | ||
* @returns The heap node that contains the value | ||
*/ | ||
public add(x: T): IHeapNode<T> { | ||
const node = { value: x, position: this.L.length }; | ||
this.L.push(node); | ||
this.fixup(this.count()); | ||
|
||
return node; | ||
} | ||
|
||
/** | ||
* Allows for the Heap to be updated after a node's value changes. | ||
*/ | ||
public update(node: IHeapNode<T>): void { | ||
const k = node.position; | ||
if (this.isGreaterThanParent(k)) { | ||
this.fixup(k); | ||
} else { | ||
this.fixdown(k); | ||
} | ||
} | ||
|
||
/** | ||
* Removes the given node from the heap. | ||
* | ||
* @param node - The node to remove from the heap. | ||
*/ | ||
public remove(node: IHeapNode<T>): void { | ||
// Move the node we want to remove to the end of the array | ||
const position = node.position; | ||
this.swap(node.position, this.L.length - 1); | ||
this.L.splice(-1); | ||
|
||
// Update the swapped node assuming we didn't remove the end of the list | ||
if (position !== this.L.length) { | ||
this.update(this.L[position]); | ||
} | ||
} | ||
|
||
/** | ||
* Get the number of elements in the Heap. | ||
* | ||
* @returns The number of elements in the Heap. | ||
*/ | ||
public count(): number { | ||
return this.L.length - 1; | ||
} | ||
|
||
private fixup(pos: number): void { | ||
let k = pos; | ||
while (this.isGreaterThanParent(k)) { | ||
// eslint-disable-next-line no-bitwise | ||
const parent = k >> 1; | ||
this.swap(k, parent); | ||
k = parent; | ||
} | ||
} | ||
|
||
private isGreaterThanParent(k: number): boolean { | ||
// eslint-disable-next-line no-bitwise | ||
return k > 1 && this.comp.compare(this.L[k >> 1].value, this.L[k].value) > 0; | ||
} | ||
|
||
private fixdown(pos: number): void { | ||
let k = pos; | ||
// eslint-disable-next-line no-bitwise | ||
while (k << 1 <= this.count()) { | ||
// eslint-disable-next-line no-bitwise | ||
let j = k << 1; | ||
if (j < this.count() && this.comp.compare(this.L[j].value, this.L[j + 1].value) > 0) { | ||
j++; | ||
} | ||
if (this.comp.compare(this.L[k].value, this.L[j].value) <= 0) { | ||
break; | ||
} | ||
this.swap(k, j); | ||
k = j; | ||
} | ||
} | ||
|
||
private swap(k: number, j: number): void { | ||
const tmp = this.L[k]; | ||
this.L[k] = this.L[j]; | ||
this.L[k].position = k; | ||
this.L[j] = tmp; | ||
this.L[j].position = j; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Server code only runs in node, it can use the native
performance.now()
directly, no need to try to proxy through an isomorphic performance object (which incidentally was already removed in main for the client release group).