@fluid-internal/client-utils 2.0.0-dev.6.4.0.192049 → 2.0.0-dev.7.2.0.204906
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +4 -3
- package/api-extractor.json +1 -13
- package/api-report/client-utils.api.md +127 -0
- package/dist/base64Encoding.d.ts.map +1 -1
- package/dist/base64Encoding.js +6 -3
- package/dist/base64Encoding.js.map +1 -1
- package/dist/bufferBrowser.d.ts +3 -3
- package/dist/bufferBrowser.d.ts.map +1 -1
- package/dist/bufferBrowser.js +14 -3
- package/dist/bufferBrowser.js.map +1 -1
- package/dist/bufferNode.d.ts +7 -7
- package/dist/bufferNode.d.ts.map +1 -1
- package/dist/bufferNode.js +10 -5
- package/dist/bufferNode.js.map +1 -1
- package/dist/client-utils-alpha.d.ts +46 -0
- package/dist/client-utils-beta.d.ts +46 -0
- package/dist/client-utils-public.d.ts +46 -0
- package/dist/client-utils-untrimmed.d.ts +241 -0
- package/dist/eventForwarder.d.ts.map +1 -1
- package/dist/eventForwarder.js +10 -10
- package/dist/eventForwarder.js.map +1 -1
- package/dist/hashFileBrowser.js +5 -1
- package/dist/hashFileBrowser.js.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/performanceIsomorphic.d.ts +1 -1
- package/dist/performanceIsomorphic.d.ts.map +1 -1
- package/dist/performanceNode.d.ts.map +1 -1
- package/dist/performanceNode.js +2 -1
- package/dist/performanceNode.js.map +1 -1
- package/dist/trace.js +4 -4
- package/dist/trace.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/typedEventEmitter.d.ts +2 -2
- package/dist/typedEventEmitter.d.ts.map +1 -1
- package/dist/typedEventEmitter.js +2 -0
- package/dist/typedEventEmitter.js.map +1 -1
- package/lib/base64Encoding.d.ts.map +1 -1
- package/lib/base64Encoding.js +6 -3
- package/lib/base64Encoding.js.map +1 -1
- package/lib/bufferBrowser.d.ts +3 -3
- package/lib/bufferBrowser.d.ts.map +1 -1
- package/lib/bufferBrowser.js +9 -2
- package/lib/bufferBrowser.js.map +1 -1
- package/lib/bufferNode.d.ts +7 -7
- package/lib/bufferNode.d.ts.map +1 -1
- package/lib/bufferNode.js +10 -5
- package/lib/bufferNode.js.map +1 -1
- package/lib/eventForwarder.d.ts.map +1 -1
- package/lib/eventForwarder.js +10 -10
- package/lib/eventForwarder.js.map +1 -1
- package/lib/performanceIsomorphic.d.ts +1 -1
- package/lib/performanceIsomorphic.d.ts.map +1 -1
- package/lib/performanceNode.d.ts.map +1 -1
- package/lib/performanceNode.js +2 -1
- package/lib/performanceNode.js.map +1 -1
- package/lib/trace.js +4 -4
- package/lib/trace.js.map +1 -1
- package/lib/typedEventEmitter.d.ts +2 -2
- package/lib/typedEventEmitter.d.ts.map +1 -1
- package/lib/typedEventEmitter.js +2 -0
- package/lib/typedEventEmitter.js.map +1 -1
- package/package.json +15 -17
- package/src/base64Encoding.ts +6 -3
- package/src/bufferBrowser.ts +14 -4
- package/src/bufferNode.ts +18 -9
- package/src/eventForwarder.ts +2 -0
- package/src/performanceNode.ts +2 -1
- package/src/typedEventEmitter.ts +2 -0
- package/tsconfig.json +1 -0
package/lib/bufferBrowser.js
CHANGED
|
@@ -14,12 +14,15 @@ import * as base64js from "base64-js";
|
|
|
14
14
|
*
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
17
|
-
export function Uint8ArrayToString(arr,
|
|
17
|
+
export function Uint8ArrayToString(arr,
|
|
18
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
19
|
+
encoding) {
|
|
18
20
|
switch (encoding) {
|
|
19
21
|
case "base64": {
|
|
20
22
|
return base64js.fromByteArray(arr);
|
|
21
23
|
}
|
|
22
24
|
case "utf8":
|
|
25
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
23
26
|
case "utf-8":
|
|
24
27
|
case undefined: {
|
|
25
28
|
return new TextDecoder().decode(arr);
|
|
@@ -47,7 +50,9 @@ export const stringToBuffer = (input, encoding) => IsoBuffer.from(input, encodin
|
|
|
47
50
|
*
|
|
48
51
|
* @internal
|
|
49
52
|
*/
|
|
50
|
-
export const bufferToString = (blob,
|
|
53
|
+
export const bufferToString = (blob,
|
|
54
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
55
|
+
encoding) => IsoBuffer.from(blob).toString(encoding);
|
|
51
56
|
/**
|
|
52
57
|
* Determines if an object is an array buffer.
|
|
53
58
|
*
|
|
@@ -85,6 +90,7 @@ export class IsoBuffer extends Uint8Array {
|
|
|
85
90
|
*
|
|
86
91
|
* @param encoding - The encoding to use.
|
|
87
92
|
*/
|
|
93
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
88
94
|
toString(encoding) {
|
|
89
95
|
return Uint8ArrayToString(this, encoding);
|
|
90
96
|
}
|
|
@@ -136,6 +142,7 @@ export class IsoBuffer extends Uint8Array {
|
|
|
136
142
|
return new IsoBuffer(encoded.buffer);
|
|
137
143
|
}
|
|
138
144
|
case "utf8":
|
|
145
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
139
146
|
case "utf-8":
|
|
140
147
|
case undefined: {
|
|
141
148
|
const encoded = new TextEncoder().encode(str);
|
package/lib/bufferBrowser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bufferBrowser.js","sourceRoot":"","sources":["../src/bufferBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAC;AAEtC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAe,EAAE,QAAiB;IACpE,QAAQ,QAAQ,EAAE;QACjB,KAAK,QAAQ,CAAC,CAAC;YACd,OAAO,QAAQ,CAAC,aAAa,C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Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as base64js from \"base64-js\";\n\n/**\n * Converts a Uint8Array to a string of the provided encoding\n * Useful when the array might be an {@link IsoBuffer}.\n *\n * @param arr - The array to convert.\n * @param encoding - Optional target encoding; only \"utf8\" and \"base64\" are\n * supported, with \"utf8\" being default.\n * @returns The converted string.\n *\n * @internal\n */\nexport function Uint8ArrayToString(arr: Uint8Array, encoding?: string): string {\n\tswitch (encoding) {\n\t\tcase \"base64\": {\n\t\t\treturn base64js.fromByteArray(arr);\n\t\t}\n\t\tcase \"utf8\":\n\t\tcase \"utf-8\":\n\t\tcase undefined: {\n\t\t\treturn new TextDecoder().decode(arr);\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new Error(\"invalid/unsupported encoding\");\n\t\t}\n\t}\n}\n\n/**\n * Converts a {@link https://en.wikipedia.org/wiki/Base64 | base64} or\n * {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8} string to array buffer.\n *\n * @param encoding - The input string's encoding.\n *\n * @internal\n */\nexport const stringToBuffer = (input: string, encoding: string): ArrayBufferLike =>\n\tIsoBuffer.from(input, encoding).buffer;\n\n/**\n * Convert binary blob to string format\n *\n * @param blob - the binary blob\n * @param encoding - output string's encoding\n * @returns the blob in string format\n *\n * @internal\n */\nexport const bufferToString = (blob: ArrayBufferLike, encoding: string): string =>\n\tIsoBuffer.from(blob).toString(encoding);\n\n/**\n * Determines if an object is an array buffer.\n *\n * @remarks Will detect and reject TypedArrays, like Uint8Array.\n * Reason - they can be viewport into Array, they can be accepted, but caller has to deal with\n * math properly (i.e. Take into account byteOffset at minimum).\n * For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or\n * new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and\n * ignoring byteOffice, length).\n *\n * @param obj - The object to determine if it is an ArrayBuffer.\n *\n * @internal\n */\nexport function isArrayBuffer(obj: unknown): obj is ArrayBuffer {\n\tconst maybe = obj as (Partial<ArrayBuffer> & Partial<Uint8Array>) | undefined;\n\treturn (\n\t\tobj instanceof ArrayBuffer ||\n\t\t(typeof maybe === \"object\" &&\n\t\t\tmaybe !== null &&\n\t\t\ttypeof maybe.byteLength === \"number\" &&\n\t\t\ttypeof maybe.slice === \"function\" &&\n\t\t\tmaybe.byteOffset === undefined &&\n\t\t\tmaybe.buffer === undefined)\n\t);\n}\n\n/**\n * Minimal implementation of Buffer for our usages in the browser environment.\n *\n * @internal\n */\nexport class IsoBuffer extends Uint8Array {\n\t/**\n\t * Convert the buffer to a string.\n\t * Only supports encoding the whole string (unlike the Node Buffer equivalent)\n\t * and only utf8 and base64 encodings.\n\t *\n\t * @param encoding - The encoding to use.\n\t */\n\tpublic toString(encoding?: string): string {\n\t\treturn Uint8ArrayToString(this, encoding);\n\t}\n\n\t/**\n\t * Static constructor\n\t * @param value - (string | ArrayBuffer)\n\t * @param encodingOrOffset - (string | number)\n\t * @param length - (number)\n\t *\n\t * @privateRemarks TODO: Use actual types\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any\n\tstatic from(value: any, encodingOrOffset?: any, length?: any): IsoBuffer {\n\t\tif (typeof value === \"string\") {\n\t\t\treturn IsoBuffer.fromString(value, encodingOrOffset as string | undefined);\n\t\t\t// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!)\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t} else if (value !== null && typeof value === \"object\" && isArrayBuffer(value.buffer)) {\n\t\t\t// The version of the from function for the node buffer, which takes a buffer or typed array\n\t\t\t// as first parameter, does not have any offset or length parameters. Those are just silently\n\t\t\t// ignored and not taken into account\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access\n\t\t\treturn IsoBuffer.fromArrayBuffer(value.buffer, value.byteOffset, value.byteLength);\n\t\t} else if (isArrayBuffer(value)) {\n\t\t\treturn IsoBuffer.fromArrayBuffer(\n\t\t\t\tvalue,\n\t\t\t\tencodingOrOffset as number | undefined,\n\t\t\t\tlength as number,\n\t\t\t);\n\t\t} else {\n\t\t\tthrow new TypeError(\"Input value was neither a string nor an ArrayBuffer.\");\n\t\t}\n\t}\n\n\tstatic fromArrayBuffer(\n\t\tarrayBuffer: ArrayBuffer,\n\t\tbyteOffset?: number,\n\t\tbyteLength?: number,\n\t): IsoBuffer {\n\t\tconst offset = byteOffset ?? 0;\n\t\tconst validLength = byteLength ?? arrayBuffer.byteLength - offset;\n\t\tif (\n\t\t\toffset < 0 ||\n\t\t\toffset > arrayBuffer.byteLength ||\n\t\t\tvalidLength < 0 ||\n\t\t\tvalidLength + offset > arrayBuffer.byteLength\n\t\t) {\n\t\t\tthrow new RangeError(\"Invalid range specified.\");\n\t\t}\n\n\t\treturn new IsoBuffer(arrayBuffer, offset, validLength);\n\t}\n\n\tstatic fromString(str: string, encoding?: string): IsoBuffer {\n\t\tswitch (encoding) {\n\t\t\tcase \"base64\": {\n\t\t\t\tconst sanitizedString = this.sanitizeBase64(str);\n\t\t\t\tconst encoded = base64js.toByteArray(sanitizedString);\n\t\t\t\treturn new IsoBuffer(encoded.buffer);\n\t\t\t}\n\t\t\tcase \"utf8\":\n\t\t\tcase \"utf-8\":\n\t\t\tcase undefined: {\n\t\t\t\tconst encoded = new TextEncoder().encode(str);\n\t\t\t\treturn new IsoBuffer(encoded.buffer);\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new Error(\"invalid/unsupported encoding\");\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic isBuffer(obj: unknown): boolean {\n\t\tthrow new Error(\"unimplemented\");\n\t}\n\n\t/**\n\t * Sanitize a base64 string to provide to base64-js library.\n\t * {@link https://www.npmjs.com/package/base64-js} is not as tolerant of the same malformed base64 as Node'\n\t * Buffer is.\n\t */\n\tprivate static sanitizeBase64(str: string): string {\n\t\tlet sanitizedStr = str;\n\t\t// Remove everything after padding - Node buffer ignores everything\n\t\t// after any padding whereas base64-js does not\n\t\tsanitizedStr = sanitizedStr.split(\"=\")[0];\n\n\t\t// Remove invalid characters - Node buffer strips invalid characters\n\t\t// whereas base64-js replaces them with \"A\"\n\t\tsanitizedStr = sanitizedStr.replace(/[^\\w+-/]/g, \"\");\n\n\t\t// Check for missing padding - Node buffer tolerates missing padding\n\t\t// whereas base64-js does not\n\t\tif (sanitizedStr.length % 4 !== 0) {\n\t\t\tconst paddingArray = [\"\", \"===\", \"==\", \"=\"];\n\t\t\tsanitizedStr += paddingArray[sanitizedStr.length % 4];\n\t\t}\n\t\treturn sanitizedStr;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bufferBrowser.js","sourceRoot":"","sources":["../src/bufferBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAC;AAEtC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CACjC,GAAe;AACf,8GAA8G;AAC9G,QAAsC;IAEtC,QAAQ,QAAQ,EAAE;QACjB,KAAK,QAAQ,CAAC,CAAC;YACd,OAAO,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;SACnC;QACD,KAAK,MAAM,CAAC;QACZ,8GAA8G;QAC9G,KAAK,OAAO,CAAC;QACb,KAAK,SAAS,CAAC,CAAC;YACf,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;SACrC;QACD,OAAO,CAAC,CAAC;YACR,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SAChD;KACD;AACF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,QAAgB,EAAmB,EAAE,CAClF,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC7B,IAAq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gBACR,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;aAChD;SACD;IACF,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,GAAY;QAC3B,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACK,MAAM,CAAC,cAAc,CAAC,GAAW;QACxC,IAAI,YAAY,GAAG,GAAG,CAAC;QACvB,mEAAmE;QACnE,+CAA+C;QAC/C,YAAY,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAE1C,oEAAoE;QACpE,2CAA2C;QAC3C,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAErD,oEAAoE;QACpE,6BAA6B;QAC7B,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE;YAClC,MAAM,YAAY,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;YAC5C,YAAY,IAAI,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;SACtD;QACD,OAAO,YAAY,CAAC;IACrB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as base64js from \"base64-js\";\n\n/**\n * Converts a Uint8Array to a string of the provided encoding\n * Useful when the array might be an {@link IsoBuffer}.\n *\n * @param arr - The array to convert.\n * @param encoding - Optional target encoding; only \"utf8\" and \"base64\" are\n * supported, with \"utf8\" being default.\n * @returns The converted string.\n *\n * @internal\n */\nexport function Uint8ArrayToString(\n\tarr: Uint8Array,\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\tencoding?: \"utf8\" | \"utf-8\" | \"base64\",\n): string {\n\tswitch (encoding) {\n\t\tcase \"base64\": {\n\t\t\treturn base64js.fromByteArray(arr);\n\t\t}\n\t\tcase \"utf8\":\n\t\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\t\tcase \"utf-8\":\n\t\tcase undefined: {\n\t\t\treturn new TextDecoder().decode(arr);\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new Error(\"invalid/unsupported encoding\");\n\t\t}\n\t}\n}\n\n/**\n * Converts a {@link https://en.wikipedia.org/wiki/Base64 | base64} or\n * {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8} string to array buffer.\n *\n * @param encoding - The input string's encoding.\n *\n * @internal\n */\nexport const stringToBuffer = (input: string, encoding: string): ArrayBufferLike =>\n\tIsoBuffer.from(input, encoding).buffer;\n\n/**\n * Convert binary blob to string format\n *\n * @param blob - the binary blob\n * @param encoding - output string's encoding\n * @returns the blob in string format\n *\n * @internal\n */\nexport const bufferToString = (\n\tblob: ArrayBufferLike,\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\tencoding: \"utf8\" | \"utf-8\" | \"base64\",\n): string => IsoBuffer.from(blob).toString(encoding);\n\n/**\n * Determines if an object is an array buffer.\n *\n * @remarks Will detect and reject TypedArrays, like Uint8Array.\n * Reason - they can be viewport into Array, they can be accepted, but caller has to deal with\n * math properly (i.e. Take into account byteOffset at minimum).\n * For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or\n * new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and\n * ignoring byteOffice, length).\n *\n * @param obj - The object to determine if it is an ArrayBuffer.\n *\n * @internal\n */\nexport function isArrayBuffer(obj: unknown): obj is ArrayBuffer {\n\tconst maybe = obj as (Partial<ArrayBuffer> & Partial<Uint8Array>) | undefined;\n\treturn (\n\t\tobj instanceof ArrayBuffer ||\n\t\t(typeof maybe === \"object\" &&\n\t\t\tmaybe !== null &&\n\t\t\ttypeof maybe.byteLength === \"number\" &&\n\t\t\ttypeof maybe.slice === \"function\" &&\n\t\t\tmaybe.byteOffset === undefined &&\n\t\t\tmaybe.buffer === undefined)\n\t);\n}\n\n/**\n * Minimal implementation of Buffer for our usages in the browser environment.\n *\n * @internal\n */\nexport class IsoBuffer extends Uint8Array {\n\t/**\n\t * Convert the buffer to a string.\n\t * Only supports encoding the whole string (unlike the Node Buffer equivalent)\n\t * and only utf8 and base64 encodings.\n\t *\n\t * @param encoding - The encoding to use.\n\t */\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\tpublic toString(encoding?: \"utf8\" | \"utf-8\" | \"base64\"): string {\n\t\treturn Uint8ArrayToString(this, encoding);\n\t}\n\n\t/**\n\t * Static constructor\n\t * @param value - (string | ArrayBuffer)\n\t * @param encodingOrOffset - (string | number)\n\t * @param length - (number)\n\t *\n\t * @privateRemarks TODO: Use actual types\n\t */\n\t// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any\n\tstatic from(value: any, encodingOrOffset?: any, length?: any): IsoBuffer {\n\t\tif (typeof value === \"string\") {\n\t\t\treturn IsoBuffer.fromString(value, encodingOrOffset as string | undefined);\n\t\t\t// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!)\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t} else if (value !== null && typeof value === \"object\" && isArrayBuffer(value.buffer)) {\n\t\t\t// The version of the from function for the node buffer, which takes a buffer or typed array\n\t\t\t// as first parameter, does not have any offset or length parameters. Those are just silently\n\t\t\t// ignored and not taken into account\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access\n\t\t\treturn IsoBuffer.fromArrayBuffer(value.buffer, value.byteOffset, value.byteLength);\n\t\t} else if (isArrayBuffer(value)) {\n\t\t\treturn IsoBuffer.fromArrayBuffer(\n\t\t\t\tvalue,\n\t\t\t\tencodingOrOffset as number | undefined,\n\t\t\t\tlength as number,\n\t\t\t);\n\t\t} else {\n\t\t\tthrow new TypeError(\"Input value was neither a string nor an ArrayBuffer.\");\n\t\t}\n\t}\n\n\tstatic fromArrayBuffer(\n\t\tarrayBuffer: ArrayBuffer,\n\t\tbyteOffset?: number,\n\t\tbyteLength?: number,\n\t): IsoBuffer {\n\t\tconst offset = byteOffset ?? 0;\n\t\tconst validLength = byteLength ?? arrayBuffer.byteLength - offset;\n\t\tif (\n\t\t\toffset < 0 ||\n\t\t\toffset > arrayBuffer.byteLength ||\n\t\t\tvalidLength < 0 ||\n\t\t\tvalidLength + offset > arrayBuffer.byteLength\n\t\t) {\n\t\t\tthrow new RangeError(\"Invalid range specified.\");\n\t\t}\n\n\t\treturn new IsoBuffer(arrayBuffer, offset, validLength);\n\t}\n\n\tstatic fromString(str: string, encoding?: string): IsoBuffer {\n\t\tswitch (encoding) {\n\t\t\tcase \"base64\": {\n\t\t\t\tconst sanitizedString = this.sanitizeBase64(str);\n\t\t\t\tconst encoded = base64js.toByteArray(sanitizedString);\n\t\t\t\treturn new IsoBuffer(encoded.buffer);\n\t\t\t}\n\t\t\tcase \"utf8\":\n\t\t\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\t\t\tcase \"utf-8\":\n\t\t\tcase undefined: {\n\t\t\t\tconst encoded = new TextEncoder().encode(str);\n\t\t\t\treturn new IsoBuffer(encoded.buffer);\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new Error(\"invalid/unsupported encoding\");\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic isBuffer(obj: unknown): boolean {\n\t\tthrow new Error(\"unimplemented\");\n\t}\n\n\t/**\n\t * Sanitize a base64 string to provide to base64-js library.\n\t * {@link https://www.npmjs.com/package/base64-js} is not as tolerant of the same malformed base64 as Node'\n\t * Buffer is.\n\t */\n\tprivate static sanitizeBase64(str: string): string {\n\t\tlet sanitizedStr = str;\n\t\t// Remove everything after padding - Node buffer ignores everything\n\t\t// after any padding whereas base64-js does not\n\t\tsanitizedStr = sanitizedStr.split(\"=\")[0];\n\n\t\t// Remove invalid characters - Node buffer strips invalid characters\n\t\t// whereas base64-js replaces them with \"A\"\n\t\tsanitizedStr = sanitizedStr.replace(/[^\\w+-/]/g, \"\");\n\n\t\t// Check for missing padding - Node buffer tolerates missing padding\n\t\t// whereas base64-js does not\n\t\tif (sanitizedStr.length % 4 !== 0) {\n\t\t\tconst paddingArray = [\"\", \"===\", \"==\", \"=\"];\n\t\t\tsanitizedStr += paddingArray[sanitizedStr.length % 4];\n\t\t}\n\t\treturn sanitizedStr;\n\t}\n}\n"]}
|
package/lib/bufferNode.d.ts
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* exposing the entirely of Node's typings. This should match the public interface
|
|
8
8
|
* of the browser implementation, so any changes made in one should be made in both.
|
|
9
9
|
*
|
|
10
|
-
* @
|
|
10
|
+
* @internal
|
|
11
11
|
*/
|
|
12
12
|
export declare class Buffer extends Uint8Array {
|
|
13
|
-
toString(encoding?:
|
|
13
|
+
toString(encoding?: "utf8" | "utf-8" | "base64"): string;
|
|
14
14
|
/**
|
|
15
15
|
* Static constructor
|
|
16
16
|
*
|
|
@@ -24,13 +24,13 @@ export declare class Buffer extends Uint8Array {
|
|
|
24
24
|
static isBuffer(obj: unknown): obj is Buffer;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* @
|
|
27
|
+
* @internal
|
|
28
28
|
*/
|
|
29
29
|
export declare const IsoBuffer: typeof Buffer;
|
|
30
30
|
/**
|
|
31
|
-
* @
|
|
31
|
+
* @internal
|
|
32
32
|
*/
|
|
33
|
-
export
|
|
33
|
+
export type IsoBuffer = Buffer;
|
|
34
34
|
/**
|
|
35
35
|
* Converts a Uint8Array to a string of the provided encoding.
|
|
36
36
|
* @remarks Useful when the array might be an IsoBuffer.
|
|
@@ -41,7 +41,7 @@ export declare type IsoBuffer = Buffer;
|
|
|
41
41
|
*
|
|
42
42
|
* @internal
|
|
43
43
|
*/
|
|
44
|
-
export declare function Uint8ArrayToString(arr: Uint8Array, encoding?:
|
|
44
|
+
export declare function Uint8ArrayToString(arr: Uint8Array, encoding?: "utf8" | "utf-8" | "base64"): string;
|
|
45
45
|
/**
|
|
46
46
|
* Convert base64 or utf8 string to array buffer.
|
|
47
47
|
* @param encoding - The input string's encoding.
|
|
@@ -58,5 +58,5 @@ export declare function stringToBuffer(input: string, encoding: string): ArrayBu
|
|
|
58
58
|
*
|
|
59
59
|
* @internal
|
|
60
60
|
*/
|
|
61
|
-
export declare const bufferToString: (blob: ArrayBufferLike, encoding:
|
|
61
|
+
export declare const bufferToString: (blob: ArrayBufferLike, encoding: "utf8" | "utf-8" | "base64") => string;
|
|
62
62
|
//# sourceMappingURL=bufferNode.d.ts.map
|
package/lib/bufferNode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bufferNode.d.ts","sourceRoot":"","sources":["../src/bufferNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,UAAU;
|
|
1
|
+
{"version":3,"file":"bufferNode.d.ts","sourceRoot":"","sources":["../src/bufferNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,UAAU;IAE7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM;IAExD;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,gBAAgB,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS;IACpF,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM;CAC5C;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,eAAS,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,UAAU,EAEf,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GACpC,MAAM,CAIR;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,eAAe,CAQ/E;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,SACpB,eAAe,YAEX,MAAM,GAAG,OAAO,GAAG,QAAQ,KACnC,MAAiD,CAAC"}
|
package/lib/bufferNode.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* @
|
|
6
|
+
* @internal
|
|
7
7
|
*/
|
|
8
8
|
export const IsoBuffer = Buffer;
|
|
9
9
|
/**
|
|
@@ -16,9 +16,12 @@ export const IsoBuffer = Buffer;
|
|
|
16
16
|
*
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
|
-
export function Uint8ArrayToString(arr,
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export function Uint8ArrayToString(arr,
|
|
20
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
21
|
+
encoding) {
|
|
22
|
+
// Buffer extends Uint8Array. Therefore, 'arr' may already be a Buffer, in
|
|
23
|
+
// which case we can avoid copying the Uint8Array into a new Buffer instance.
|
|
24
|
+
return (Buffer.isBuffer(arr) ? arr : Buffer.from(arr)).toString(encoding);
|
|
22
25
|
}
|
|
23
26
|
/**
|
|
24
27
|
* Convert base64 or utf8 string to array buffer.
|
|
@@ -44,5 +47,7 @@ export function stringToBuffer(input, encoding) {
|
|
|
44
47
|
*
|
|
45
48
|
* @internal
|
|
46
49
|
*/
|
|
47
|
-
export const bufferToString = (blob,
|
|
50
|
+
export const bufferToString = (blob,
|
|
51
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
52
|
+
encoding) => IsoBuffer.from(blob).toString(encoding);
|
|
48
53
|
//# sourceMappingURL=bufferNode.js.map
|
package/lib/bufferNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bufferNode.js","sourceRoot":"","sources":["../src/bufferNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"bufferNode.js","sourceRoot":"","sources":["../src/bufferNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0BH;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC;AAOhC;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CACjC,GAAe;AACf,8GAA8G;AAC9G,QAAsC;IAEtC,2EAA2E;IAC3E,6EAA6E;IAC7E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,QAAgB;IAC7D,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5C,0EAA0E;IAC1E,2EAA2E;IAC3E,uDAAuD;IACvD,OAAO,GAAG,CAAC,UAAU,KAAK,GAAG,CAAC,MAAM,CAAC,UAAU;QAC9C,CAAC,CAAC,GAAG,CAAC,MAAM;QACZ,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC7B,IAAqB;AACrB,8GAA8G;AAC9G,QAAqC,EAC5B,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Declare the subset of Buffer functionality we want to make available instead of\n * exposing the entirely of Node's typings. This should match the public interface\n * of the browser implementation, so any changes made in one should be made in both.\n *\n * @internal\n */\nexport declare class Buffer extends Uint8Array {\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\ttoString(encoding?: \"utf8\" | \"utf-8\" | \"base64\"): string;\n\n\t/**\n\t * Static constructor\n\t *\n\t * @param value - (string | ArrayBuffer).\n\t * @param encodingOrOffset - (string | number).\n\t * @param length - (number).\n\t *\n\t * @privateRemarks TODO: Use actual types\n\t */\n\tstatic from(value: unknown, encodingOrOffset?: unknown, length?: unknown): IsoBuffer;\n\tstatic isBuffer(obj: unknown): obj is Buffer;\n}\n\n/**\n * @internal\n */\nexport const IsoBuffer = Buffer;\n\n/**\n * @internal\n */\nexport type IsoBuffer = Buffer;\n\n/**\n * Converts a Uint8Array to a string of the provided encoding.\n * @remarks Useful when the array might be an IsoBuffer.\n * @param arr - The array to convert.\n * @param encoding - Optional target encoding; only \"utf8\" and \"base64\" are\n * supported, with \"utf8\" being default.\n * @returns The converted string.\n *\n * @internal\n */\nexport function Uint8ArrayToString(\n\tarr: Uint8Array,\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\tencoding?: \"utf8\" | \"utf-8\" | \"base64\",\n): string {\n\t// Buffer extends Uint8Array. Therefore, 'arr' may already be a Buffer, in\n\t// which case we can avoid copying the Uint8Array into a new Buffer instance.\n\treturn (Buffer.isBuffer(arr) ? arr : Buffer.from(arr)).toString(encoding);\n}\n\n/**\n * Convert base64 or utf8 string to array buffer.\n * @param encoding - The input string's encoding.\n *\n * @internal\n */\nexport function stringToBuffer(input: string, encoding: string): ArrayBufferLike {\n\tconst iso = IsoBuffer.from(input, encoding);\n\t// In a Node environment, IsoBuffer may be a Node.js Buffer. Node.js will\n\t// pool multiple small Buffer instances into a single ArrayBuffer, in which\n\t// case we need to slice the appropriate span of bytes.\n\treturn iso.byteLength === iso.buffer.byteLength\n\t\t? iso.buffer\n\t\t: iso.buffer.slice(iso.byteOffset, iso.byteOffset + iso.byteLength);\n}\n\n/**\n * Convert binary blob to string format\n *\n * @param blob - The binary blob\n * @param encoding - Output string's encoding\n * @returns The blob in string format\n *\n * @internal\n */\nexport const bufferToString = (\n\tblob: ArrayBufferLike,\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\tencoding: \"utf8\" | \"utf-8\" | \"base64\",\n): string => IsoBuffer.from(blob).toString(encoding);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventForwarder.d.ts","sourceRoot":"","sources":["../src/eventForwarder.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"eventForwarder.d.ts","sourceRoot":"","sources":["../src/eventForwarder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;;GAMG;AACH,qBAAa,cAAc,CAAC,MAAM,GAAG,MAAM,CAC1C,SAAQ,iBAAiB,CAAC,MAAM,CAChC,YAAW,WAAW;IAEtB,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAOvD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAiB;IACzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAoB;IAE/D;;OAEG;IACH,IAAW,QAAQ,IAAI,OAAO,CAE7B;IACD,OAAO,CAAC,UAAU,CAAkB;IAEpC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAG7B;gBAEQ,MAAM,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,MAAM,GAAG,MAAM,CAAC;IAcnE;;OAEG;IACI,OAAO,IAAI,IAAI;IAetB,SAAS,CAAC,YAAY,CACrB,MAAM,EAAE,YAAY,GAAG,cAAc,CAAC,MAAM,GAAG,MAAM,CAAC,EACtD,GAAG,MAAM,EAAE,MAAM,EAAE,GACjB,IAAI;IAqBP,SAAS,CAAC,cAAc,CACvB,MAAM,EAAE,YAAY,GAAG,cAAc,CAAC,MAAM,GAAG,MAAM,CAAC,EACtD,GAAG,MAAM,EAAE,MAAM,EAAE,GACjB,IAAI;CAiBP"}
|
package/lib/eventForwarder.js
CHANGED
|
@@ -11,6 +11,16 @@ import { TypedEventEmitter } from "./typedEventEmitter";
|
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
13
|
export class EventForwarder extends TypedEventEmitter {
|
|
14
|
+
static isEmitterEvent(event) {
|
|
15
|
+
return (event === EventForwarder.newListenerEvent ||
|
|
16
|
+
event === EventForwarder.removeListenerEvent);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* {@inheritDoc @fluidframework/core-interfaces#IDisposable.disposed}
|
|
20
|
+
*/
|
|
21
|
+
get disposed() {
|
|
22
|
+
return this.isDisposed;
|
|
23
|
+
}
|
|
14
24
|
constructor(source) {
|
|
15
25
|
super();
|
|
16
26
|
this.isDisposed = false;
|
|
@@ -25,16 +35,6 @@ export class EventForwarder extends TypedEventEmitter {
|
|
|
25
35
|
this.on(EventForwarder.newListenerEvent, newListenerHandler);
|
|
26
36
|
}
|
|
27
37
|
}
|
|
28
|
-
static isEmitterEvent(event) {
|
|
29
|
-
return (event === EventForwarder.newListenerEvent ||
|
|
30
|
-
event === EventForwarder.removeListenerEvent);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* {@inheritDoc @fluidframework/core-interfaces#IDisposable.disposed}
|
|
34
|
-
*/
|
|
35
|
-
get disposed() {
|
|
36
|
-
return this.isDisposed;
|
|
37
|
-
}
|
|
38
38
|
/**
|
|
39
39
|
* {@inheritDoc @fluidframework/core-interfaces#IDisposable.dispose}
|
|
40
40
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventForwarder.js","sourceRoot":"","sources":["../src/eventForwarder.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"eventForwarder.js","sourceRoot":"","sources":["../src/eventForwarder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;;GAMG;AACH,MAAM,OAAO,cACZ,SAAQ,iBAAyB;IAGvB,MAAM,CAAC,cAAc,CAAC,KAAa;QAC5C,OAAO,CACN,KAAK,KAAK,cAAc,CAAC,gBAAgB;YACzC,KAAK,KAAK,cAAc,CAAC,mBAAmB,CAC5C,CAAC;IACH,CAAC;IAKD;;OAEG;IACH,IAAW,QAAQ;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAQD,YAAY,MAAuD;QAClE,KAAK,EAAE,CAAC;QARD,eAAU,GAAY,KAAK,CAAC;QAEnB,qBAAgB,GAAG,IAAI,GAAG,EAGxC,CAAC;QAIH,IAAI,MAAM,KAAK,SAAS,EAAE;YACzB,mFAAmF;YACnF,kFAAkF;YAClF,8CAA8C;YAC9C,MAAM,qBAAqB,GAAG,CAAC,KAAa,EAAQ,EAAE,CACrD,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACpC,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAQ,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACrF,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC,mBAAmB,EAA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K,EAAE,QAAQ,CAAC,CAAC,CAAC;oBACvD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;iBAC3B;aACD;SACD;IACF,CAAC;IAES,cAAc,CACvB,MAAsD,EACtD,GAAG,MAAgB;QAEnB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC3B,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;gBACjE,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACjD,IAAI,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;oBACrE,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;oBAC5C,IAAI,eAAe,KAAK,SAAS,EAAE;wBAClC,eAAe,EAAE,CAAC;qBAClB;oBACD,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBACvB,IAAI,OAAO,CAAC,IAAI,KAAK,CAAC,EAAE;wBACvB,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;qBACpC;iBACD;aACD;SACD;IACF,CAAC;;AA3FuB,+BAAgB,GAAG,aAAa,AAAhB,CAAiB;AACjC,kCAAmB,GAAG,gBAAgB,AAAnB,CAAoB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// False positive: this is an import from the `events` package, not from Node.\n// eslint-disable-next-line unicorn/prefer-node-protocol\nimport { EventEmitter } from \"events\";\nimport { IDisposable, IEvent, IEventProvider } from \"@fluidframework/core-interfaces\";\nimport { TypedEventEmitter } from \"./typedEventEmitter\";\n\n/**\n * Base class used for forwarding events from a source EventEmitter.\n * This can be useful when all arbitrary listeners need to be removed,\n * but the primary source needs to stay intact.\n *\n * @internal\n */\nexport class EventForwarder<TEvent = IEvent>\n\textends TypedEventEmitter<TEvent>\n\timplements IDisposable\n{\n\tprotected static isEmitterEvent(event: string): boolean {\n\t\treturn (\n\t\t\tevent === EventForwarder.newListenerEvent ||\n\t\t\tevent === EventForwarder.removeListenerEvent\n\t\t);\n\t}\n\n\tprivate static readonly newListenerEvent = \"newListener\";\n\tprivate static readonly removeListenerEvent = \"removeListener\";\n\n\t/**\n\t * {@inheritDoc @fluidframework/core-interfaces#IDisposable.disposed}\n\t */\n\tpublic get disposed(): boolean {\n\t\treturn this.isDisposed;\n\t}\n\tprivate isDisposed: boolean = false;\n\n\tprivate readonly forwardingEvents = new Map<\n\t\tstring,\n\t\tMap<EventEmitter | IEventProvider<TEvent & IEvent>, () => void>\n\t>();\n\n\tconstructor(source?: EventEmitter | IEventProvider<TEvent & IEvent>) {\n\t\tsuper();\n\t\tif (source !== undefined) {\n\t\t\t// NewListener event is raised whenever someone starts listening to this events, so\n\t\t\t// we keep track of events being listened to, and start forwarding from the source\n\t\t\t// event emitter per event listened to on this\n\t\t\tconst removeListenerHandler = (event: string): void =>\n\t\t\t\tthis.unforwardEvent(source, event);\n\t\t\tconst newListenerHandler = (event: string): void => this.forwardEvent(source, event);\n\t\t\tthis.on(EventForwarder.removeListenerEvent, removeListenerHandler);\n\t\t\tthis.on(EventForwarder.newListenerEvent, newListenerHandler);\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/core-interfaces#IDisposable.dispose}\n\t */\n\tpublic dispose(): void {\n\t\tthis.isDisposed = true;\n\t\tfor (const listenerRemovers of this.forwardingEvents.values()) {\n\t\t\tfor (const listenerRemover of listenerRemovers.values()) {\n\t\t\t\ttry {\n\t\t\t\t\tlistenerRemover();\n\t\t\t\t} catch {\n\t\t\t\t\t// Should be fine because of removeAllListeners below\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.removeAllListeners();\n\t\tthis.forwardingEvents.clear();\n\t}\n\n\tprotected forwardEvent(\n\t\tsource: EventEmitter | IEventProvider<TEvent & IEvent>,\n\t\t...events: string[]\n\t): void {\n\t\tfor (const event of events) {\n\t\t\tif (\n\t\t\t\tsource !== undefined &&\n\t\t\t\tevent !== undefined &&\n\t\t\t\t!EventForwarder.isEmitterEvent(event)\n\t\t\t) {\n\t\t\t\tlet sources = this.forwardingEvents.get(event);\n\t\t\t\tif (sources === undefined) {\n\t\t\t\t\tsources = new Map();\n\t\t\t\t\tthis.forwardingEvents.set(event, sources);\n\t\t\t\t}\n\t\t\t\tif (!sources.has(source)) {\n\t\t\t\t\tconst listener = (...args: unknown[]): boolean => this.emit(event, ...args);\n\t\t\t\t\tsources.set(source, () => source.off(event, listener));\n\t\t\t\t\tsource.on(event, listener);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected unforwardEvent(\n\t\tsource: EventEmitter | IEventProvider<TEvent & IEvent>,\n\t\t...events: string[]\n\t): void {\n\t\tfor (const event of events) {\n\t\t\tif (event !== undefined && !EventForwarder.isEmitterEvent(event)) {\n\t\t\t\tconst sources = this.forwardingEvents.get(event);\n\t\t\t\tif (sources?.has(source) === true && this.listenerCount(event) === 0) {\n\t\t\t\t\tconst listenerRemover = sources.get(source);\n\t\t\t\t\tif (listenerRemover !== undefined) {\n\t\t\t\t\t\tlistenerRemover();\n\t\t\t\t\t}\n\t\t\t\t\tsources.delete(source);\n\t\t\t\t\tif (sources.size === 0) {\n\t\t\t\t\t\tthis.forwardingEvents.delete(event);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export type IsomorphicPerformance = Partial<Performance> & Pick<Performance, "clearMarks" | "mark" | "measure" | "now">;
|
|
12
12
|
//# sourceMappingURL=performanceIsomorphic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performanceIsomorphic.d.ts","sourceRoot":"","sources":["../src/performanceIsomorphic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"performanceIsomorphic.d.ts","sourceRoot":"","sources":["../src/performanceIsomorphic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC,GACvD,IAAI,CAAC,WAAW,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performanceNode.d.ts","sourceRoot":"","sources":["../src/performanceNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"performanceNode.d.ts","sourceRoot":"","sources":["../src/performanceNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,qBAAuC,CAAC"}
|
package/lib/performanceNode.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
//
|
|
5
|
+
// This is referring to our own `perf_hooks`, not Node's.
|
|
6
|
+
// eslint-disable-next-line import/no-nodejs-modules, unicorn/prefer-node-protocol
|
|
6
7
|
import { performance as nodePerformance } from "perf_hooks";
|
|
7
8
|
/**
|
|
8
9
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performanceNode.js","sourceRoot":"","sources":["../src/performanceNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,
|
|
1
|
+
{"version":3,"file":"performanceNode.js","sourceRoot":"","sources":["../src/performanceNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,yDAAyD;AACzD,kFAAkF;AAClF,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,YAAY,CAAC;AAG5D;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAA0B,eAAe,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// This is referring to our own `perf_hooks`, not Node's.\n// eslint-disable-next-line import/no-nodejs-modules, unicorn/prefer-node-protocol\nimport { performance as nodePerformance } from \"perf_hooks\";\nimport { IsomorphicPerformance } from \"./performanceIsomorphic\";\n\n/**\n * @internal\n */\nexport const performance: IsomorphicPerformance = nodePerformance;\n"]}
|
package/lib/trace.js
CHANGED
|
@@ -10,14 +10,14 @@ import { performance } from "./indexNode";
|
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
12
|
export class Trace {
|
|
13
|
-
constructor(startTick) {
|
|
14
|
-
this.startTick = startTick;
|
|
15
|
-
this.lastTick = startTick;
|
|
16
|
-
}
|
|
17
13
|
static start() {
|
|
18
14
|
const startTick = performance.now();
|
|
19
15
|
return new Trace(startTick);
|
|
20
16
|
}
|
|
17
|
+
constructor(startTick) {
|
|
18
|
+
this.startTick = startTick;
|
|
19
|
+
this.lastTick = startTick;
|
|
20
|
+
}
|
|
21
21
|
trace() {
|
|
22
22
|
const tick = performance.now();
|
|
23
23
|
const event = {
|
package/lib/trace.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,OAAO,KAAK;
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,OAAO,KAAK;IACV,MAAM,CAAC,KAAK;QAClB,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACpC,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAGD,YAAsC,SAAiB;QAAjB,cAAS,GAAT,SAAS,CAAQ;QACtD,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC3B,CAAC;IAEM,KAAK;QACX,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAG;YACb,gBAAgB,EAAE,IAAI,GAAG,IAAI,CAAC,SAAS;YACvC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC,QAAQ;YAC9B,IAAI;SACJ,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,OAAO,KAAK,CAAC;IACd,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"./indexNode\";\n\n/**\n * Helper class for tracing performance of events\n * Time measurements are in milliseconds as a floating point with a decimal\n *\n * @internal\n */\nexport class Trace {\n\tpublic static start(): Trace {\n\t\tconst startTick = performance.now();\n\t\treturn new Trace(startTick);\n\t}\n\n\tprotected lastTick: number;\n\tprotected constructor(public readonly startTick: number) {\n\t\tthis.lastTick = startTick;\n\t}\n\n\tpublic trace(): ITraceEvent {\n\t\tconst tick = performance.now();\n\t\tconst event = {\n\t\t\ttotalTimeElapsed: tick - this.startTick,\n\t\t\tduration: tick - this.lastTick,\n\t\t\ttick,\n\t\t};\n\t\tthis.lastTick = tick;\n\t\treturn event;\n\t}\n}\n\n/**\n * Event in a performance trace including time elapsed.\n *\n * @internal\n */\nexport interface ITraceEvent {\n\t/**\n\t * Total time elapsed since the start of the Trace.\n\t * Measured in milliseconds as a floating point with a decimal\n\t */\n\treadonly totalTimeElapsed: number;\n\t/**\n\t * Time elapsed since the last trace event.\n\t * Measured in milliseconds as a floating point with a decimal\n\t */\n\treadonly duration: number;\n\t/**\n\t * This number represents a relative time which should\n\t * be consistent for all trace ticks.\n\t */\n\treadonly tick: number;\n}\n"]}
|
|
@@ -12,13 +12,13 @@ import { IEvent, TransformedEvent, IEventTransformer, IEventProvider } from "@fl
|
|
|
12
12
|
*
|
|
13
13
|
* @internal
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export type EventEmitterEventType = EventEmitter extends {
|
|
16
16
|
on(event: infer E, listener: any): any;
|
|
17
17
|
} ? E : never;
|
|
18
18
|
/**
|
|
19
19
|
* @internal
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
21
|
+
export type TypedEventTransform<TThis, TEvent> = TransformedEvent<TThis, "newListener" | "removeListener", Parameters<(event: string, listener: (...args: any[]) => void) => void>> & IEventTransformer<TThis, TEvent & IEvent> & TransformedEvent<TThis, EventEmitterEventType, any[]>;
|
|
22
22
|
/**
|
|
23
23
|
* Event Emitter helper class the supports emitting typed events
|
|
24
24
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typedEventEmitter.d.ts","sourceRoot":"","sources":["../src/typedEventEmitter.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"typedEventEmitter.d.ts","sourceRoot":"","sources":["../src/typedEventEmitter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EACN,MAAM,EACN,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,MAAM,iCAAiC,CAAC;AAEzC;;;;;;;GAOG;AAEH,MAAM,MAAM,qBAAqB,GAAG,YAAY,SAAS;IAAE,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,GAAG,OAAC;CAAE,GAC3F,CAAC,GACD,KAAK,CAAC;AAET;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,KAAK,EAAE,MAAM,IAK5C,gBAAgB,CACf,KAAK,EACL,aAAa,GAAG,gBAAgB,EAEhC,UAAU,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,KAAK,IAAI,CAAC,CACvE,GAEA,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,GAGzC,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC;AAExD;;;;GAIG;AACH,qBAAa,iBAAiB,CAAC,MAAM,CACpC,SAAQ,YACR,YAAW,cAAc,CAAC,MAAM,GAAG,MAAM,CAAC;;IAkB1C,QAAQ,CAAC,WAAW,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxD,QAAQ,CAAC,EAAE,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACjD,QAAQ,CAAC,eAAe,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5D,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAChE,QAAQ,CAAC,cAAc,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC3D,QAAQ,CAAC,GAAG,EAAE,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;CAChD"}
|
package/lib/typedEventEmitter.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
+
// False positive: this is an import from the `events` package, not from Node.
|
|
6
|
+
// eslint-disable-next-line unicorn/prefer-node-protocol
|
|
5
7
|
import { EventEmitter } from "events";
|
|
6
8
|
/**
|
|
7
9
|
* Event Emitter helper class the supports emitting typed events
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typedEventEmitter.js","sourceRoot":"","sources":["../src/typedEventEmitter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAyCtC;;;;GAIG;AACH,MAAM,OAAO,iBACZ,SAAQ,YAAY;IAGpB;QACC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QACrF,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QACnE,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QACvE,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAGrD,CAAC;QACF,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAG7D,CAAC;QACF,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QAC3F,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;IACtE,CAAC;CAQD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\nimport {\n\tIEvent,\n\tTransformedEvent,\n\tIEventTransformer,\n\tIEventProvider,\n} from \"@fluidframework/core-interfaces\";\n\n/**\n * The event emitter polyfill and the node event emitter have different event types:\n * string | symbol vs. string | number\n *\n * This type allow us to correctly handle either type\n *\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type EventEmitterEventType = EventEmitter extends { on(event: infer E, listener: any) }\n\t? E\n\t: never;\n\n/**\n * @internal\n */\nexport type TypedEventTransform<TThis, TEvent> =\n\t// Event emitter supports some special events for the emitter itself to use\n\t// this exposes those events for the TypedEventEmitter.\n\t// Since we know what the shape of these events are, we can describe them directly via a TransformedEvent\n\t// which easier than trying to extend TEvent directly\n\tTransformedEvent<\n\t\tTThis,\n\t\t\"newListener\" | \"removeListener\",\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tParameters<(event: string, listener: (...args: any[]) => void) => void>\n\t> &\n\t\t// Expose all the events provides by TEvent\n\t\tIEventTransformer<TThis, TEvent & IEvent> &\n\t\t// Add the default overload so this is covertable to EventEmitter regardless of environment\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tTransformedEvent<TThis, EventEmitterEventType, any[]>;\n\n/**\n * Event Emitter helper class the supports emitting typed events\n *\n * @internal\n */\nexport class TypedEventEmitter<TEvent>\n\textends EventEmitter\n\timplements IEventProvider<TEvent & IEvent>\n{\n\tconstructor() {\n\t\tsuper();\n\t\tthis.addListener = super.addListener.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.on = super.on.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.once = super.once.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.prependListener = super.prependListener.bind(this) as TypedEventTransform<\n\t\t\tthis,\n\t\t\tTEvent\n\t\t>;\n\t\tthis.prependOnceListener = super.prependOnceListener.bind(this) as TypedEventTransform<\n\t\t\tthis,\n\t\t\tTEvent\n\t\t>;\n\t\tthis.removeListener = super.removeListener.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.off = super.off.bind(this) as TypedEventTransform<this, TEvent>;\n\t}\n\treadonly addListener: TypedEventTransform<this, TEvent>;\n\treadonly on: TypedEventTransform<this, TEvent>;\n\treadonly once: TypedEventTransform<this, TEvent>;\n\treadonly prependListener: TypedEventTransform<this, TEvent>;\n\treadonly prependOnceListener: TypedEventTransform<this, TEvent>;\n\treadonly removeListener: TypedEventTransform<this, TEvent>;\n\treadonly off: TypedEventTransform<this, TEvent>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"typedEventEmitter.js","sourceRoot":"","sources":["../src/typedEventEmitter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,8EAA8E;AAC9E,wDAAwD;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAyCtC;;;;GAIG;AACH,MAAM,OAAO,iBACZ,SAAQ,YAAY;IAGpB;QACC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QACrF,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QACnE,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QACvE,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAGrD,CAAC;QACF,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAG7D,CAAC;QACF,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;QAC3F,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAsC,CAAC;IACtE,CAAC;CAQD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// False positive: this is an import from the `events` package, not from Node.\n// eslint-disable-next-line unicorn/prefer-node-protocol\nimport { EventEmitter } from \"events\";\nimport {\n\tIEvent,\n\tTransformedEvent,\n\tIEventTransformer,\n\tIEventProvider,\n} from \"@fluidframework/core-interfaces\";\n\n/**\n * The event emitter polyfill and the node event emitter have different event types:\n * string | symbol vs. string | number\n *\n * This type allow us to correctly handle either type\n *\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type EventEmitterEventType = EventEmitter extends { on(event: infer E, listener: any) }\n\t? E\n\t: never;\n\n/**\n * @internal\n */\nexport type TypedEventTransform<TThis, TEvent> =\n\t// Event emitter supports some special events for the emitter itself to use\n\t// this exposes those events for the TypedEventEmitter.\n\t// Since we know what the shape of these events are, we can describe them directly via a TransformedEvent\n\t// which easier than trying to extend TEvent directly\n\tTransformedEvent<\n\t\tTThis,\n\t\t\"newListener\" | \"removeListener\",\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tParameters<(event: string, listener: (...args: any[]) => void) => void>\n\t> &\n\t\t// Expose all the events provides by TEvent\n\t\tIEventTransformer<TThis, TEvent & IEvent> &\n\t\t// Add the default overload so this is covertable to EventEmitter regardless of environment\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tTransformedEvent<TThis, EventEmitterEventType, any[]>;\n\n/**\n * Event Emitter helper class the supports emitting typed events\n *\n * @internal\n */\nexport class TypedEventEmitter<TEvent>\n\textends EventEmitter\n\timplements IEventProvider<TEvent & IEvent>\n{\n\tconstructor() {\n\t\tsuper();\n\t\tthis.addListener = super.addListener.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.on = super.on.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.once = super.once.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.prependListener = super.prependListener.bind(this) as TypedEventTransform<\n\t\t\tthis,\n\t\t\tTEvent\n\t\t>;\n\t\tthis.prependOnceListener = super.prependOnceListener.bind(this) as TypedEventTransform<\n\t\t\tthis,\n\t\t\tTEvent\n\t\t>;\n\t\tthis.removeListener = super.removeListener.bind(this) as TypedEventTransform<this, TEvent>;\n\t\tthis.off = super.off.bind(this) as TypedEventTransform<this, TEvent>;\n\t}\n\treadonly addListener: TypedEventTransform<this, TEvent>;\n\treadonly on: TypedEventTransform<this, TEvent>;\n\treadonly once: TypedEventTransform<this, TEvent>;\n\treadonly prependListener: TypedEventTransform<this, TEvent>;\n\treadonly prependOnceListener: TypedEventTransform<this, TEvent>;\n\treadonly removeListener: TypedEventTransform<this, TEvent>;\n\treadonly off: TypedEventTransform<this, TEvent>;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-internal/client-utils",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.7.2.0.204906",
|
|
4
4
|
"description": "Not intended for use outside the Fluid Framework.",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"temp-directory": "nyc/.nyc_output"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@fluidframework/core-interfaces": "2.0.0-dev.
|
|
43
|
-
"@fluidframework/core-utils": "2.0.0-dev.
|
|
42
|
+
"@fluidframework/core-interfaces": "2.0.0-dev.7.2.0.204906",
|
|
43
|
+
"@fluidframework/core-utils": "2.0.0-dev.7.2.0.204906",
|
|
44
44
|
"@types/events": "^3.0.0",
|
|
45
45
|
"base64-js": "^1.5.1",
|
|
46
46
|
"buffer": "^6.0.3",
|
|
@@ -49,13 +49,12 @@
|
|
|
49
49
|
"sha.js": "^2.4.11"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@fluid-tools/build-cli": "
|
|
53
|
-
"@fluidframework/build-common": "^2.0.
|
|
54
|
-
"@fluidframework/build-tools": "
|
|
55
|
-
"@fluidframework/eslint-config-fluid": "^
|
|
56
|
-
"@fluidframework/mocha-test-setup": "2.0.0-dev.
|
|
57
|
-
"@microsoft/api-extractor": "^7.
|
|
58
|
-
"@rushstack/eslint-config": "^2.5.1",
|
|
52
|
+
"@fluid-tools/build-cli": "0.26.0-203096",
|
|
53
|
+
"@fluidframework/build-common": "^2.0.2",
|
|
54
|
+
"@fluidframework/build-tools": "0.26.0-203096",
|
|
55
|
+
"@fluidframework/eslint-config-fluid": "^3.0.0",
|
|
56
|
+
"@fluidframework/mocha-test-setup": "2.0.0-dev.7.2.0.204906",
|
|
57
|
+
"@microsoft/api-extractor": "^7.37.0",
|
|
59
58
|
"@types/base64-js": "^1.3.0",
|
|
60
59
|
"@types/jest": "29.5.3",
|
|
61
60
|
"@types/jest-environment-puppeteer": "2.2.0",
|
|
@@ -67,10 +66,9 @@
|
|
|
67
66
|
"@types/sinon": "^7.0.13",
|
|
68
67
|
"c8": "^7.7.1",
|
|
69
68
|
"concurrently": "^8.2.1",
|
|
70
|
-
"copyfiles": "^2.4.1",
|
|
71
69
|
"cross-env": "^7.0.3",
|
|
72
|
-
"eslint": "~8.
|
|
73
|
-
"eslint-config-prettier": "~
|
|
70
|
+
"eslint": "~8.50.0",
|
|
71
|
+
"eslint-config-prettier": "~9.0.0",
|
|
74
72
|
"jest": "^29.6.2",
|
|
75
73
|
"jest-junit": "^10.0.0",
|
|
76
74
|
"jest-puppeteer": "^6.2.0",
|
|
@@ -78,14 +76,14 @@
|
|
|
78
76
|
"mocha-json-output-reporter": "^2.0.1",
|
|
79
77
|
"mocha-multi-reporters": "^1.5.1",
|
|
80
78
|
"moment": "^2.21.0",
|
|
81
|
-
"prettier": "~
|
|
79
|
+
"prettier": "~3.0.3",
|
|
82
80
|
"puppeteer": "^17.1.3",
|
|
83
81
|
"rewire": "^5.0.0",
|
|
84
82
|
"rimraf": "^4.4.0",
|
|
85
83
|
"sinon": "^7.4.2",
|
|
86
84
|
"ts-jest": "^29.1.1",
|
|
87
85
|
"ts-node": "^10.9.1",
|
|
88
|
-
"typescript": "~
|
|
86
|
+
"typescript": "~5.1.6"
|
|
89
87
|
},
|
|
90
88
|
"fluidBuild": {
|
|
91
89
|
"tasks": {
|
|
@@ -114,13 +112,13 @@
|
|
|
114
112
|
"build": "fluid-build . --task build",
|
|
115
113
|
"build:commonjs": "fluid-build . --task commonjs",
|
|
116
114
|
"build:compile": "fluid-build . --task compile",
|
|
117
|
-
"build:docs": "api-extractor run --local
|
|
115
|
+
"build:docs": "api-extractor run --local",
|
|
118
116
|
"build:esnext": "tsc --project ./tsconfig.esnext.json",
|
|
119
117
|
"build:test": "concurrently npm:build:test:mocha npm:build:test:jest npm:build:test:types",
|
|
120
118
|
"build:test:jest": "tsc --project ./src/test/jest/tsconfig.json",
|
|
121
119
|
"build:test:mocha": "tsc --project ./src/test/mocha/tsconfig.json",
|
|
122
120
|
"build:test:types": "tsc --project ./src/test/types/tsconfig.json",
|
|
123
|
-
"ci:build:docs": "api-extractor run
|
|
121
|
+
"ci:build:docs": "api-extractor run",
|
|
124
122
|
"clean": "rimraf --glob '_api-extractor-temp' 'dist' 'lib' '*.tsbuildinfo' '*.build.log' 'nyc'",
|
|
125
123
|
"eslint": "eslint --format stylish src",
|
|
126
124
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
package/src/base64Encoding.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { IsoBuffer } from "./indexNode";
|
|
|
12
12
|
* @internal
|
|
13
13
|
*/
|
|
14
14
|
export const fromBase64ToUtf8 = (input: string): string =>
|
|
15
|
-
IsoBuffer.from(input, "base64").toString("
|
|
15
|
+
IsoBuffer.from(input, "base64").toString("utf8");
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Converts the provided {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}-encoded string
|
|
@@ -34,9 +34,12 @@ export const fromUtf8ToBase64 = (input: string): string =>
|
|
|
34
34
|
export const toUtf8 = (input: string, encoding: string): string => {
|
|
35
35
|
switch (encoding) {
|
|
36
36
|
case "utf8":
|
|
37
|
-
case
|
|
37
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
38
|
+
case "utf-8": {
|
|
38
39
|
return input;
|
|
39
|
-
|
|
40
|
+
}
|
|
41
|
+
default: {
|
|
40
42
|
return IsoBuffer.from(input, encoding).toString();
|
|
43
|
+
}
|
|
41
44
|
}
|
|
42
45
|
};
|
package/src/bufferBrowser.ts
CHANGED
|
@@ -16,12 +16,17 @@ import * as base64js from "base64-js";
|
|
|
16
16
|
*
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
|
-
export function Uint8ArrayToString(
|
|
19
|
+
export function Uint8ArrayToString(
|
|
20
|
+
arr: Uint8Array,
|
|
21
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
22
|
+
encoding?: "utf8" | "utf-8" | "base64",
|
|
23
|
+
): string {
|
|
20
24
|
switch (encoding) {
|
|
21
25
|
case "base64": {
|
|
22
26
|
return base64js.fromByteArray(arr);
|
|
23
27
|
}
|
|
24
28
|
case "utf8":
|
|
29
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
25
30
|
case "utf-8":
|
|
26
31
|
case undefined: {
|
|
27
32
|
return new TextDecoder().decode(arr);
|
|
@@ -52,8 +57,11 @@ export const stringToBuffer = (input: string, encoding: string): ArrayBufferLike
|
|
|
52
57
|
*
|
|
53
58
|
* @internal
|
|
54
59
|
*/
|
|
55
|
-
export const bufferToString = (
|
|
56
|
-
|
|
60
|
+
export const bufferToString = (
|
|
61
|
+
blob: ArrayBufferLike,
|
|
62
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
63
|
+
encoding: "utf8" | "utf-8" | "base64",
|
|
64
|
+
): string => IsoBuffer.from(blob).toString(encoding);
|
|
57
65
|
|
|
58
66
|
/**
|
|
59
67
|
* Determines if an object is an array buffer.
|
|
@@ -95,7 +103,8 @@ export class IsoBuffer extends Uint8Array {
|
|
|
95
103
|
*
|
|
96
104
|
* @param encoding - The encoding to use.
|
|
97
105
|
*/
|
|
98
|
-
|
|
106
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
107
|
+
public toString(encoding?: "utf8" | "utf-8" | "base64"): string {
|
|
99
108
|
return Uint8ArrayToString(this, encoding);
|
|
100
109
|
}
|
|
101
110
|
|
|
@@ -157,6 +166,7 @@ export class IsoBuffer extends Uint8Array {
|
|
|
157
166
|
return new IsoBuffer(encoded.buffer);
|
|
158
167
|
}
|
|
159
168
|
case "utf8":
|
|
169
|
+
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
160
170
|
case "utf-8":
|
|
161
171
|
case undefined: {
|
|
162
172
|
const encoded = new TextEncoder().encode(str);
|