Skip to content
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
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9e6eec4
Copy Deferred to server-services-core
alexvy86 Mar 6, 2025
3d5e648
Remove common-utils from server-services-core
alexvy86 Mar 6, 2025
0cc0179
Remove common-utils from server-lambdas
alexvy86 Mar 6, 2025
f6d3793
Remove common-utils from server-memory-orderer
alexvy86 Mar 6, 2025
ea50fd7
Remove common-utils from server-routerlicious-base
alexvy86 Mar 6, 2025
dac8602
Remove common-utils from server-services
alexvy86 Mar 6, 2025
a0041bb
Remove common-utils from server-services-shared
alexvy86 Mar 6, 2025
8d42abc
Remove common-utils from server-services-telemetry
alexvy86 Mar 6, 2025
11f9146
Remove common-utils from tinylicious
alexvy86 Mar 6, 2025
647b54e
Remove common-utils from server-test-utils
alexvy86 Mar 6, 2025
a1c251c
Move to new server-common-utils
alexvy86 Mar 6, 2025
fb6d9f2
Move protocol-base to server-common-utils
alexvy86 Mar 6, 2025
c9bf24a
Move some things to the single packages that use them
alexvy86 Mar 6, 2025
3fbb74b
Remove commented code
alexvy86 Mar 6, 2025
800b0e0
Remove some deprecated tags
alexvy86 Mar 6, 2025
cc345b6
Formatting
alexvy86 Mar 6, 2025
b3ee169
Use assert from server-common-utils
alexvy86 Mar 6, 2025
7c83341
Formatting
alexvy86 Mar 6, 2025
a883e05
Remove more unneded lint disable comments
alexvy86 Mar 6, 2025
01001de
Fix docs
alexvy86 Mar 6, 2025
abc1360
Undo assert changes
alexvy86 Mar 6, 2025
545804d
Cleanup and fix build of server-common-utils
alexvy86 Mar 6, 2025
5ae6f21
Cleanup tests; remove jest
alexvy86 Mar 6, 2025
d8e488d
Move assert to server-services-client
alexvy86 Mar 6, 2025
186ef46
Move Deferred to services-core
alexvy86 Mar 6, 2025
2d60abf
Move delay to services-core
alexvy86 Mar 6, 2025
d533b2b
Move unreachable to the packages that use it
alexvy86 Mar 6, 2025
02eb780
Move TypedEventEmitter
alexvy86 Mar 6, 2025
838bc6f
Move node+browser utils to services-client
alexvy86 Mar 6, 2025
10730f8
Remove server-common-utils
alexvy86 Mar 7, 2025
3b0fe6d
Cleanup
alexvy86 Mar 7, 2025
10f6549
Add puppeteer devDep
alexvy86 Mar 7, 2025
c479fa7
Fix protocol-base use of events/events_pkg
alexvy86 Mar 7, 2025
fe43244
Try adding missing jest-environment-puppeteer
alexvy86 Mar 7, 2025
e8981f0
Change how we run jest tests in CI
alexvy86 Mar 7, 2025
1e25cd4
Dep for jest tests in Dockerfile
alexvy86 Mar 7, 2025
617ea8a
More deps for jest tests
alexvy86 Mar 7, 2025
fe22d79
More deps
alexvy86 Mar 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions server/routerlicious/packages/common-utils/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

module.exports = {
extends: [
require.resolve("@fluidframework/eslint-config-fluid/minimal-deprecated"),
"prettier",
],
parserOptions: {
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
},
rules: {
"import/no-nodejs-modules": "off",
"promise/catch-or-return": ["error", { allowFinally: true }],

// TODO: enable strict null checks in tsconfig and remove these overrides
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/strict-boolean-expressions": "off",

// TODO: remove usages of deprecated APIs and remove this override
"import/no-deprecated": "warn",
},
};
52 changes: 52 additions & 0 deletions server/routerlicious/packages/common-utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Compiled TypeScript and CSS
dist
lib

# Babel
public/scripts/es5

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
.cache-loader

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Typings
typings

# Debug log from npm
npm-debug.log

# Code coverage
nyc
.nyc_output/

# Chart dependencies
**/charts/*.tgz

# Generated modules
intel_modules/
temp_modules/
7 changes: 7 additions & 0 deletions server/routerlicious/packages/common-utils/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nyc
*.log
**/*.tsbuildinfo
src/test
dist/test
lib/test
**/_api-extractor-temp/**
5 changes: 5 additions & 0 deletions server/routerlicious/packages/common-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @fluidframework/server-common-utils

## 6.0.0

Initial version
21 changes: 21 additions & 0 deletions server/routerlicious/packages/common-utils/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) Microsoft Corporation and contributors. All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions server/routerlicious/packages/common-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @fluidframework/server-common-utils

Non-Fluid-specific utilities that can be reused across server code.
115 changes: 115 additions & 0 deletions server/routerlicious/packages/common-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"name": "@fluidframework/server-common-utils",
"version": "6.0.0",
"description": "Common utilities for Fluid server code",
"homepage": "https://fluidframework.com",
"repository": {
"type": "git",
"url": "https://github.com/microsoft/FluidFramework.git",
"directory": "server/routerlicious/packages/common-utils"
},
"license": "MIT",
"author": "Microsoft and contributors",
"sideEffects": false,
"main": "dist/index.js",
"module": "lib/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "npm run build:compile && concurrently npm:lint npm:build:docs",
"build:commonjs": "npm run tsc && npm run typetests:gen && npm run build:test",
"build:compile": "concurrently npm:build:commonjs npm:build:esnext",
"build:docs": "api-extractor run --local --typescript-compiler-folder ./node_modules/typescript && copyfiles -u 1 \"./_api-extractor-temp/doc-models/*\" ../../../_api-extractor-temp/",
"build:esnext": "tsc --project ./tsconfig.esnext.json",
"build:genver": "gen-version",
"build:test": "concurrently npm:build:test:mocha npm:build:test:jest npm:build:test:types",
"build:test:jest": "tsc --project ./src/test/jest/tsconfig.json",
"build:test:mocha": "tsc --project ./src/test/mocha/tsconfig.json",
"build:test:types": "tsc --project ./src/test/types/tsconfig.json",
"clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" nyc",
"eslint": "eslint --format stylish src",
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
"format": "npm run prettier:fix",
"lint": "npm run prettier && npm run eslint",
"lint:fix": "npm run prettier:fix && npm run eslint:fix",
"prettier": "prettier --check . --cache --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --cache --ignore-path ../../.prettierignore",
"test": "npm run test:mocha && npm run test:jest",
"test:coverage": "c8 npm run test:report",
"test:jest": "jest --ci",
"test:jest:report": "npm run test:jest -- --coverage",
"test:mocha": "mocha --unhandled-rejections=strict --recursive \"dist/test/mocha/**/*.spec.*js\"",
"test:mocha:multireport": "cross-env FLUID_TEST_MULTIREPORT=1 npm run test:mocha",
"test:mocha:report": "npm run test:mocha -- -- --reporter xunit --reporter-option output=nyc/mocha-junit-report.xml",
"test:report": "npm run test:mocha:report && npm run test:jest:report",
"tsc": "tsc",
"typetests:gen": "flub generate typetests --dir . -v",
"typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
},
"dependencies": {
"@types/events": "^3.0.0",
"base64-js": "^1.5.1",
"buffer": "^6.0.3",
"events": "^3.1.0",
"lodash": "^4.17.21",
"sha.js": "^2.4.11"
},
"devDependencies": {
"@fluid-tools/build-cli": "^0.49.0",
"@fluidframework/build-common": "^2.0.3",
"@fluidframework/build-tools": "^0.49.0",
"@fluidframework/eslint-config-fluid": "^5.5.1",
"@microsoft/api-extractor": "^7.45.1",
"@types/base64-js": "^1.3.0",
"@types/benchmark": "^2.1.0",
"@types/jest": "29.5.3",
"@types/jest-environment-puppeteer": "2.2.0",
"@types/mocha": "^10.0.10",
"@types/node": "^18.19.39",
"@types/sinon": "^17.0.3",
"benchmark": "^2.1.4",
"c8": "^8.0.1",
"concurrently": "^8.2.1",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"eslint": "~8.55.0",
"eslint-config-prettier": "~9.0.0",
"jest": "^29.6.2",
"jest-junit": "^10.0.0",
"jest-puppeteer": "^10.1.3",
"mocha": "^10.2.0",
"mocha-multi-reporters": "^1.5.1",
"moment": "^2.21.0",
"prettier": "~3.0.3",
"puppeteer": "^23.6.0",
"rewire": "^5.0.0",
"rimraf": "^4.4.1",
"sinon": "^18.0.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "~5.4.5"
},
"fluidBuild": {
"tasks": {
"eslint": [
"tsc",
"build:test:mocha",
"build:test:jest",
"build:test:types"
],
"build:test:jest": [
"tsc"
],
"build:test:mocha": [
"tsc"
],
"build:test:types": [
"tsc"
]
}
},
"typeValidation": {
"disabled": true,
"broken": {},
"entrypoint": "public"
}
}
25 changes: 25 additions & 0 deletions server/routerlicious/packages/common-utils/src/assert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

/**
* A browser friendly assert library.
* Use this instead of the 'assert' package, which has a big impact on bundle sizes.
* @param condition - The condition that should be true, if the condition is false an error will be thrown.
* Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.
* @param message - The message to include in the error when the condition does not hold.
* A number should not be specified manually: use a string.
* Before a release, policy-check should be run, which will convert any asserts still using strings to
* use numbered error codes instead.
*
* @deprecated Moved to the `@fluidframework/core-utils` package.
* @internal
*/
export function assert(condition: boolean, message: string | number): asserts condition {
if (!condition) {
throw new Error(
typeof message === "number" ? `0x${message.toString(16).padStart(3, "0")}` : message,
);
}
}
41 changes: 41 additions & 0 deletions server/routerlicious/packages/common-utils/src/base64Encoding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

import { IsoBuffer } from "./buffer";

/**
* Converts the provided {@link https://en.wikipedia.org/wiki/Base64 | base64}-encoded string
* to {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}.
* @internal
*/
export const fromBase64ToUtf8 = (input: string): string =>
IsoBuffer.from(input, "base64").toString("utf-8");

/**
* Converts the provided {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}-encoded string
* to {@link https://en.wikipedia.org/wiki/Base64 | base64}.
* @internal
*/
export const fromUtf8ToBase64 = (input: string): string =>
IsoBuffer.from(input, "utf8").toString("base64");

/**
* Convenience function to convert unknown encoding to utf8 that avoids
* buffer copies/encode ops when no conversion is needed.
* @param input - The source string to convert.
* @param encoding - The source string's encoding.
* @internal
*/
export const toUtf8 = (input: string, encoding: string): string => {
switch (encoding) {
case "utf8":
case "utf-8": {
return input;
}
default: {
return IsoBuffer.from(input, encoding).toString();
}
}
};
71 changes: 71 additions & 0 deletions server/routerlicious/packages/common-utils/src/buffer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

/**
* Declare the subset of Buffer functionality we want to make available instead of
* exposing the entirely of Node's typings. This should match the public interface
* of the browser implementation, so any changes made in one should be made in both.
* @internal
*/
export declare class Buffer extends Uint8Array {
toString(encoding?: string): string;
/**
* @param value - (string | ArrayBuffer).
* @param encodingOrOffset - (string | number).
* @param length - (number).
*/
static from(value, encodingOrOffset?, length?): IsoBuffer;
static isBuffer(obj: any): obj is Buffer;
}

/**
* @internal
*/
export const IsoBuffer = Buffer;

/**
* @internal
*/
export type IsoBuffer = Buffer;

/**
* Converts a Uint8Array to a string of the provided encoding.
* @remarks Useful when the array might be an IsoBuffer.
* @param arr - The array to convert.
* @param encoding - Optional target encoding; only "utf8" and "base64" are
* supported, with "utf8" being default.
* @returns The converted string.
* @internal
*/
export function Uint8ArrayToString(arr: Uint8Array, encoding?: string): string {
// Make this check because Buffer.from(arr) will always do a buffer copy
return (Buffer.isBuffer(arr) ? arr : Buffer.from(arr)).toString(encoding);
}

/**
* Convert base64 or utf8 string to array buffer.
* @param encoding - The input string's encoding.
* @internal
*/
export function stringToBuffer(input: string, encoding: string): ArrayBufferLike {
const iso = IsoBuffer.from(input, encoding);
// In a Node environment, IsoBuffer may be a Node.js Buffer. Node.js will
// pool multiple small Buffer instances into a single ArrayBuffer, in which
// case we need to slice the appropriate span of bytes.
return iso.byteLength === iso.buffer.byteLength
? iso.buffer
: iso.buffer.slice(iso.byteOffset, iso.byteOffset + iso.byteLength);
}

/**
* Convert binary blob to string format
*
* @param blob - The binary blob
* @param encoding - Output string's encoding
* @returns The blob in string format
* @internal
*/
export const bufferToString = (blob: ArrayBufferLike, encoding: string): string =>
IsoBuffer.from(blob).toString(encoding);
Loading