@fluid-internal/client-utils 2.0.0-internal.6.3.1

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.
Files changed (149) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +3 -0
  4. package/LICENSE +21 -0
  5. package/README.md +70 -0
  6. package/api-extractor.json +16 -0
  7. package/dist/base64Encoding.d.ts +28 -0
  8. package/dist/base64Encoding.d.ts.map +1 -0
  9. package/dist/base64Encoding.js +43 -0
  10. package/dist/base64Encoding.js.map +1 -0
  11. package/dist/bufferBrowser.d.ts +81 -0
  12. package/dist/bufferBrowser.d.ts.map +1 -0
  13. package/dist/bufferBrowser.js +195 -0
  14. package/dist/bufferBrowser.js.map +1 -0
  15. package/dist/bufferNode.d.ts +58 -0
  16. package/dist/bufferNode.d.ts.map +1 -0
  17. package/dist/bufferNode.js +54 -0
  18. package/dist/bufferNode.js.map +1 -0
  19. package/dist/bufferShared.d.ts +12 -0
  20. package/dist/bufferShared.d.ts.map +1 -0
  21. package/dist/bufferShared.js +21 -0
  22. package/dist/bufferShared.js.map +1 -0
  23. package/dist/eventForwarder.d.ts +33 -0
  24. package/dist/eventForwarder.d.ts.map +1 -0
  25. package/dist/eventForwarder.js +98 -0
  26. package/dist/eventForwarder.js.map +1 -0
  27. package/dist/hashFileBrowser.d.ts +30 -0
  28. package/dist/hashFileBrowser.d.ts.map +1 -0
  29. package/dist/hashFileBrowser.js +95 -0
  30. package/dist/hashFileBrowser.js.map +1 -0
  31. package/dist/hashFileNode.d.ts +30 -0
  32. package/dist/hashFileNode.d.ts.map +1 -0
  33. package/dist/hashFileNode.js +60 -0
  34. package/dist/hashFileNode.js.map +1 -0
  35. package/dist/index.d.ts +20 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +41 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/indexBrowser.d.ts +8 -0
  40. package/dist/indexBrowser.d.ts.map +1 -0
  41. package/dist/indexBrowser.js +19 -0
  42. package/dist/indexBrowser.js.map +1 -0
  43. package/dist/indexNode.d.ts +8 -0
  44. package/dist/indexNode.d.ts.map +1 -0
  45. package/dist/indexNode.js +19 -0
  46. package/dist/indexNode.js.map +1 -0
  47. package/dist/performanceBrowser.d.ts +10 -0
  48. package/dist/performanceBrowser.d.ts.map +1 -0
  49. package/dist/performanceBrowser.js +12 -0
  50. package/dist/performanceBrowser.js.map +1 -0
  51. package/dist/performanceIsomorphic.d.ts +12 -0
  52. package/dist/performanceIsomorphic.d.ts.map +1 -0
  53. package/dist/performanceIsomorphic.js +7 -0
  54. package/dist/performanceIsomorphic.js.map +1 -0
  55. package/dist/performanceNode.d.ts +10 -0
  56. package/dist/performanceNode.d.ts.map +1 -0
  57. package/dist/performanceNode.js +14 -0
  58. package/dist/performanceNode.js.map +1 -0
  59. package/dist/trace.d.ts +40 -0
  60. package/dist/trace.d.ts.map +1 -0
  61. package/dist/trace.js +36 -0
  62. package/dist/trace.js.map +1 -0
  63. package/dist/tsdoc-metadata.json +11 -0
  64. package/dist/typedEventEmitter.d.ts +37 -0
  65. package/dist/typedEventEmitter.d.ts.map +1 -0
  66. package/dist/typedEventEmitter.js +27 -0
  67. package/dist/typedEventEmitter.js.map +1 -0
  68. package/jest-puppeteer.config.js +13 -0
  69. package/jest.config.js +20 -0
  70. package/lib/base64Encoding.d.ts +28 -0
  71. package/lib/base64Encoding.d.ts.map +1 -0
  72. package/lib/base64Encoding.js +37 -0
  73. package/lib/base64Encoding.js.map +1 -0
  74. package/lib/bufferBrowser.d.ts +81 -0
  75. package/lib/bufferBrowser.d.ts.map +1 -0
  76. package/lib/bufferBrowser.js +168 -0
  77. package/lib/bufferBrowser.js.map +1 -0
  78. package/lib/bufferNode.d.ts +58 -0
  79. package/lib/bufferNode.d.ts.map +1 -0
  80. package/lib/bufferNode.js +48 -0
  81. package/lib/bufferNode.js.map +1 -0
  82. package/lib/bufferShared.d.ts +12 -0
  83. package/lib/bufferShared.d.ts.map +1 -0
  84. package/lib/bufferShared.js +17 -0
  85. package/lib/bufferShared.js.map +1 -0
  86. package/lib/eventForwarder.d.ts +33 -0
  87. package/lib/eventForwarder.d.ts.map +1 -0
  88. package/lib/eventForwarder.js +94 -0
  89. package/lib/eventForwarder.js.map +1 -0
  90. package/lib/hashFileBrowser.d.ts +30 -0
  91. package/lib/hashFileBrowser.d.ts.map +1 -0
  92. package/lib/hashFileBrowser.js +71 -0
  93. package/lib/hashFileBrowser.js.map +1 -0
  94. package/lib/hashFileNode.d.ts +30 -0
  95. package/lib/hashFileNode.d.ts.map +1 -0
  96. package/lib/hashFileNode.js +52 -0
  97. package/lib/hashFileNode.js.map +1 -0
  98. package/lib/index.d.ts +20 -0
  99. package/lib/index.d.ts.map +1 -0
  100. package/lib/index.js +21 -0
  101. package/lib/index.js.map +1 -0
  102. package/lib/indexBrowser.d.ts +8 -0
  103. package/lib/indexBrowser.d.ts.map +1 -0
  104. package/lib/indexBrowser.js +8 -0
  105. package/lib/indexBrowser.js.map +1 -0
  106. package/lib/indexNode.d.ts +8 -0
  107. package/lib/indexNode.d.ts.map +1 -0
  108. package/lib/indexNode.js +8 -0
  109. package/lib/indexNode.js.map +1 -0
  110. package/lib/performanceBrowser.d.ts +10 -0
  111. package/lib/performanceBrowser.d.ts.map +1 -0
  112. package/lib/performanceBrowser.js +9 -0
  113. package/lib/performanceBrowser.js.map +1 -0
  114. package/lib/performanceIsomorphic.d.ts +12 -0
  115. package/lib/performanceIsomorphic.d.ts.map +1 -0
  116. package/lib/performanceIsomorphic.js +6 -0
  117. package/lib/performanceIsomorphic.js.map +1 -0
  118. package/lib/performanceNode.d.ts +10 -0
  119. package/lib/performanceNode.d.ts.map +1 -0
  120. package/lib/performanceNode.js +11 -0
  121. package/lib/performanceNode.js.map +1 -0
  122. package/lib/trace.d.ts +40 -0
  123. package/lib/trace.d.ts.map +1 -0
  124. package/lib/trace.js +32 -0
  125. package/lib/trace.js.map +1 -0
  126. package/lib/typedEventEmitter.d.ts +37 -0
  127. package/lib/typedEventEmitter.d.ts.map +1 -0
  128. package/lib/typedEventEmitter.js +23 -0
  129. package/lib/typedEventEmitter.js.map +1 -0
  130. package/package.json +140 -0
  131. package/prettier.config.cjs +8 -0
  132. package/src/base64Encoding.ts +42 -0
  133. package/src/bufferBrowser.ts +188 -0
  134. package/src/bufferNode.ts +75 -0
  135. package/src/bufferShared.ts +17 -0
  136. package/src/eventForwarder.ts +120 -0
  137. package/src/hashFileBrowser.ts +82 -0
  138. package/src/hashFileNode.ts +59 -0
  139. package/src/index.ts +22 -0
  140. package/src/indexBrowser.ts +14 -0
  141. package/src/indexNode.ts +14 -0
  142. package/src/performanceBrowser.ts +11 -0
  143. package/src/performanceIsomorphic.ts +13 -0
  144. package/src/performanceNode.ts +13 -0
  145. package/src/trace.ts +58 -0
  146. package/src/typedEventEmitter.ts +76 -0
  147. package/tsconfig.esnext.json +7 -0
  148. package/tsconfig.json +14 -0
  149. package/types/perf_hooks.d.ts +10 -0
@@ -0,0 +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,CAAC,GAAG,CAAC,CAAC;SACnC;QACD,KAAK,MAAM,CAAC;QACZ,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;;;;;;;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AAC;gBAC9C,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aACrC;YACD,OAAO,CAAC,CAAC;gBACR,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;aAChD;SACD;IACF,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,GAAQ;QACvB,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(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: any): 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 * @param value - (string | ArrayBuffer)\n\t * @param encodingOrOffset - (string | number)\n\t * @param length - (number)\n\t */\n\tstatic from(value, encodingOrOffset?, length?): 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} 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\treturn IsoBuffer.fromArrayBuffer(value.buffer, value.byteOffset, value.byteLength);\n\t\t} else if (isArrayBuffer(value)) {\n\t\t\treturn IsoBuffer.fromArrayBuffer(value, encodingOrOffset as number | undefined, length);\n\t\t} else {\n\t\t\tthrow new TypeError();\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();\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: any): 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"]}
@@ -0,0 +1,58 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Declare the subset of Buffer functionality we want to make available instead of
7
+ * exposing the entirely of Node's typings. This should match the public interface
8
+ * of the browser implementation, so any changes made in one should be made in both.
9
+ *
10
+ * @internal
11
+ */
12
+ export declare class Buffer extends Uint8Array {
13
+ toString(encoding?: string): string;
14
+ /**
15
+ * @param value - (string | ArrayBuffer).
16
+ * @param encodingOrOffset - (string | number).
17
+ * @param length - (number).
18
+ */
19
+ static from(value: any, encodingOrOffset?: any, length?: any): IsoBuffer;
20
+ static isBuffer(obj: any): obj is Buffer;
21
+ }
22
+ /**
23
+ * @internal
24
+ */
25
+ export declare const IsoBuffer: typeof Buffer;
26
+ /**
27
+ * @internal
28
+ */
29
+ export declare type IsoBuffer = Buffer;
30
+ /**
31
+ * Converts a Uint8Array to a string of the provided encoding.
32
+ * @remarks Useful when the array might be an IsoBuffer.
33
+ * @param arr - The array to convert.
34
+ * @param encoding - Optional target encoding; only "utf8" and "base64" are
35
+ * supported, with "utf8" being default.
36
+ * @returns The converted string.
37
+ *
38
+ * @internal
39
+ */
40
+ export declare function Uint8ArrayToString(arr: Uint8Array, encoding?: string): string;
41
+ /**
42
+ * Convert base64 or utf8 string to array buffer.
43
+ * @param encoding - The input string's encoding.
44
+ *
45
+ * @internal
46
+ */
47
+ export declare function stringToBuffer(input: string, encoding: string): ArrayBufferLike;
48
+ /**
49
+ * Convert binary blob to string format
50
+ *
51
+ * @param blob - The binary blob
52
+ * @param encoding - Output string's encoding
53
+ * @returns The blob in string format
54
+ *
55
+ * @internal
56
+ */
57
+ export declare const bufferToString: (blob: ArrayBufferLike, encoding: string) => string;
58
+ //# sourceMappingURL=bufferNode.d.ts.map
@@ -0,0 +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;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IACnC;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,KAAA,EAAE,gBAAgB,CAAC,KAAA,EAAE,MAAM,CAAC,KAAA,GAAG,SAAS;IACzD,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM;CACxC;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,eAAS,CAAC;AAEhC;;GAEG;AACH,oBAAY,SAAS,GAAG,MAAM,CAAC;AAE/B;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAG7E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,eAAe,CAQ/E;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,SAAU,eAAe,YAAY,MAAM,KAAG,MACjC,CAAC"}
@@ -0,0 +1,48 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * @internal
7
+ */
8
+ export const IsoBuffer = Buffer;
9
+ /**
10
+ * Converts a Uint8Array to a string of the provided encoding.
11
+ * @remarks Useful when the array might be an IsoBuffer.
12
+ * @param arr - The array to convert.
13
+ * @param encoding - Optional target encoding; only "utf8" and "base64" are
14
+ * supported, with "utf8" being default.
15
+ * @returns The converted string.
16
+ *
17
+ * @internal
18
+ */
19
+ export function Uint8ArrayToString(arr, encoding) {
20
+ // Make this check because Buffer.from(arr) will always do a buffer copy
21
+ return Buffer.isBuffer(arr) ? arr.toString(encoding) : Buffer.from(arr).toString(encoding);
22
+ }
23
+ /**
24
+ * Convert base64 or utf8 string to array buffer.
25
+ * @param encoding - The input string's encoding.
26
+ *
27
+ * @internal
28
+ */
29
+ export function stringToBuffer(input, encoding) {
30
+ const iso = IsoBuffer.from(input, encoding);
31
+ // In a Node environment, IsoBuffer may be a Node.js Buffer. Node.js will
32
+ // pool multiple small Buffer instances into a single ArrayBuffer, in which
33
+ // case we need to slice the appropriate span of bytes.
34
+ return iso.byteLength === iso.buffer.byteLength
35
+ ? iso.buffer
36
+ : iso.buffer.slice(iso.byteOffset, iso.byteOffset + iso.byteLength);
37
+ }
38
+ /**
39
+ * Convert binary blob to string format
40
+ *
41
+ * @param blob - The binary blob
42
+ * @param encoding - Output string's encoding
43
+ * @returns The blob in string format
44
+ *
45
+ * @internal
46
+ */
47
+ export const bufferToString = (blob, encoding) => IsoBuffer.from(blob).toString(encoding);
48
+ //# sourceMappingURL=bufferNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferNode.js","sourceRoot":"","sources":["../src/bufferNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoBH;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC;AAOhC;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAe,EAAE,QAAiB;IACpE,wEAAwE;IACxE,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC5F,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,CAAC,IAAqB,EAAE,QAAgB,EAAU,EAAE,CACjF,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\ttoString(encoding?: string): string;\n\t/**\n\t * @param value - (string | ArrayBuffer).\n\t * @param encodingOrOffset - (string | number).\n\t * @param length - (number).\n\t */\n\tstatic from(value, encodingOrOffset?, length?): IsoBuffer;\n\tstatic isBuffer(obj: any): 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(arr: Uint8Array, encoding?: string): string {\n\t// Make this check because Buffer.from(arr) will always do a buffer copy\n\treturn Buffer.isBuffer(arr) ? arr.toString(encoding) : 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 = (blob: ArrayBufferLike, encoding: string): string =>\n\tIsoBuffer.from(blob).toString(encoding);\n"]}
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Converts a Uint8Array array to an ArrayBuffer.
7
+ * @param array - Array to convert to ArrayBuffer.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare function Uint8ArrayToArrayBuffer(array: Uint8Array): ArrayBuffer;
12
+ //# sourceMappingURL=bufferShared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferShared.d.ts","sourceRoot":"","sources":["../src/bufferShared.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAKtE"}
@@ -0,0 +1,17 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Converts a Uint8Array array to an ArrayBuffer.
7
+ * @param array - Array to convert to ArrayBuffer.
8
+ *
9
+ * @internal
10
+ */
11
+ export function Uint8ArrayToArrayBuffer(array) {
12
+ if (array.byteOffset === 0 && array.byteLength === array.buffer.byteLength) {
13
+ return array.buffer;
14
+ }
15
+ return array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);
16
+ }
17
+ //# sourceMappingURL=bufferShared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferShared.js","sourceRoot":"","sources":["../src/bufferShared.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAiB;IACxD,IAAI,KAAK,CAAC,UAAU,KAAK,CAAC,IAAI,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE;QAC3E,OAAO,KAAK,CAAC,MAAM,CAAC;KACpB;IACD,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;AAClF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Converts a Uint8Array array to an ArrayBuffer.\n * @param array - Array to convert to ArrayBuffer.\n *\n * @internal\n */\nexport function Uint8ArrayToArrayBuffer(array: Uint8Array): ArrayBuffer {\n\tif (array.byteOffset === 0 && array.byteLength === array.buffer.byteLength) {\n\t\treturn array.buffer;\n\t}\n\treturn array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);\n}\n"]}
@@ -0,0 +1,33 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { EventEmitter } from "events";
6
+ import { IDisposable, IEvent, IEventProvider } from "@fluidframework/core-interfaces";
7
+ import { TypedEventEmitter } from "./typedEventEmitter";
8
+ /**
9
+ * Base class used for forwarding events from a source EventEmitter.
10
+ * This can be useful when all arbitrary listeners need to be removed,
11
+ * but the primary source needs to stay intact.
12
+ *
13
+ * @internal
14
+ */
15
+ export declare class EventForwarder<TEvent = IEvent> extends TypedEventEmitter<TEvent> implements IDisposable {
16
+ protected static isEmitterEvent(event: string): boolean;
17
+ private static readonly newListenerEvent;
18
+ private static readonly removeListenerEvent;
19
+ /**
20
+ * {@inheritDoc @fluidframework/core-interfaces#IDisposable.disposed}
21
+ */
22
+ get disposed(): boolean;
23
+ private isDisposed;
24
+ private readonly forwardingEvents;
25
+ constructor(source?: EventEmitter | IEventProvider<TEvent & IEvent>);
26
+ /**
27
+ * {@inheritDoc @fluidframework/core-interfaces#IDisposable.dispose}
28
+ */
29
+ dispose(): void;
30
+ protected forwardEvent(source: EventEmitter | IEventProvider<TEvent & IEvent>, ...events: string[]): void;
31
+ protected unforwardEvent(source: EventEmitter | IEventProvider<TEvent & IEvent>, ...events: string[]): void;
32
+ }
33
+ //# sourceMappingURL=eventForwarder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventForwarder.d.ts","sourceRoot":"","sources":["../src/eventForwarder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,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"}
@@ -0,0 +1,94 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { TypedEventEmitter } from "./typedEventEmitter";
6
+ /**
7
+ * Base class used for forwarding events from a source EventEmitter.
8
+ * This can be useful when all arbitrary listeners need to be removed,
9
+ * but the primary source needs to stay intact.
10
+ *
11
+ * @internal
12
+ */
13
+ export class EventForwarder extends TypedEventEmitter {
14
+ constructor(source) {
15
+ super();
16
+ this.isDisposed = false;
17
+ this.forwardingEvents = new Map();
18
+ if (source !== undefined) {
19
+ // NewListener event is raised whenever someone starts listening to this events, so
20
+ // we keep track of events being listened to, and start forwarding from the source
21
+ // event emitter per event listened to on this
22
+ const removeListenerHandler = (event) => this.unforwardEvent(source, event);
23
+ const newListenerHandler = (event) => this.forwardEvent(source, event);
24
+ this.on(EventForwarder.removeListenerEvent, removeListenerHandler);
25
+ this.on(EventForwarder.newListenerEvent, newListenerHandler);
26
+ }
27
+ }
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
+ /**
39
+ * {@inheritDoc @fluidframework/core-interfaces#IDisposable.dispose}
40
+ */
41
+ dispose() {
42
+ this.isDisposed = true;
43
+ for (const listenerRemovers of this.forwardingEvents.values()) {
44
+ for (const listenerRemover of listenerRemovers.values()) {
45
+ try {
46
+ listenerRemover();
47
+ }
48
+ catch {
49
+ // Should be fine because of removeAllListeners below
50
+ }
51
+ }
52
+ }
53
+ this.removeAllListeners();
54
+ this.forwardingEvents.clear();
55
+ }
56
+ forwardEvent(source, ...events) {
57
+ for (const event of events) {
58
+ if (source !== undefined &&
59
+ event !== undefined &&
60
+ !EventForwarder.isEmitterEvent(event)) {
61
+ let sources = this.forwardingEvents.get(event);
62
+ if (sources === undefined) {
63
+ sources = new Map();
64
+ this.forwardingEvents.set(event, sources);
65
+ }
66
+ if (!sources.has(source)) {
67
+ const listener = (...args) => this.emit(event, ...args);
68
+ sources.set(source, () => source.off(event, listener));
69
+ source.on(event, listener);
70
+ }
71
+ }
72
+ }
73
+ }
74
+ unforwardEvent(source, ...events) {
75
+ for (const event of events) {
76
+ if (event !== undefined && !EventForwarder.isEmitterEvent(event)) {
77
+ const sources = this.forwardingEvents.get(event);
78
+ if (sources?.has(source) === true && this.listenerCount(event) === 0) {
79
+ const listenerRemover = sources.get(source);
80
+ if (listenerRemover !== undefined) {
81
+ listenerRemover();
82
+ }
83
+ sources.delete(source);
84
+ if (sources.size === 0) {
85
+ this.forwardingEvents.delete(event);
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ }
92
+ EventForwarder.newListenerEvent = "newListener";
93
+ EventForwarder.removeListenerEvent = "removeListener";
94
+ //# sourceMappingURL=eventForwarder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eventForwarder.js","sourceRoot":"","sources":["../src/eventForwarder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;;GAMG;AACH,MAAM,OAAO,cACZ,SAAQ,iBAAyB;IA0BjC,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,CAA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C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\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: any[]): 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"]}
@@ -0,0 +1,30 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IsoBuffer } from "./bufferBrowser";
6
+ /**
7
+ * Hash a file. Consistent within a session, but should not be persisted and
8
+ * is not consistent with git.
9
+ * If called under an insecure context for a browser, this will fallback to
10
+ * using the node implementation.
11
+ *
12
+ * @param file - The contents of the file in a buffer.
13
+ * @param algorithm - The hash algorithm to use, artificially constrained by what is used internally.
14
+ * @param hashEncoding - The encoding of the returned hash, also artificially constrained.
15
+ * @returns The hash of the content of the buffer.
16
+ *
17
+ * @internal
18
+ */
19
+ export declare function hashFile(file: IsoBuffer, algorithm?: "SHA-1" | "SHA-256", hashEncoding?: "hex" | "base64"): Promise<string>;
20
+ /**
21
+ * Create a github hash (Github hashes the string with blob and size)
22
+ * Must be called under secure context for browsers
23
+ *
24
+ * @param file - The contents of the file in a buffer
25
+ * @returns The sha1 hash of the content of the buffer with the `blob` prefix and size
26
+ *
27
+ * @internal
28
+ */
29
+ export declare function gitHashFile(file: IsoBuffer): Promise<string>;
30
+ //# sourceMappingURL=hashFileBrowser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashFileBrowser.d.ts","sourceRoot":"","sources":["../src/hashFileBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAwB5C;;;;;;;;;;;;GAYG;AACH,wBAAsB,QAAQ,CAC7B,IAAI,EAAE,SAAS,EACf,SAAS,GAAE,OAAO,GAAG,SAAmB,EACxC,YAAY,GAAE,KAAK,GAAG,QAAgB,GACpC,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAOlE"}
@@ -0,0 +1,71 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import * as base64js from "base64-js";
6
+ import { IsoBuffer } from "./bufferBrowser";
7
+ async function digestBuffer(file, algorithm) {
8
+ const hash = await crypto.subtle.digest(algorithm, file);
9
+ return new Uint8Array(hash);
10
+ }
11
+ function encodeDigest(hashArray, encoding) {
12
+ // eslint-disable-next-line default-case
13
+ switch (encoding) {
14
+ case "hex": {
15
+ const hashHex = Array.prototype.map
16
+ .call(hashArray, (byte) => {
17
+ return byte.toString(16).padStart(2, "0");
18
+ })
19
+ .join("");
20
+ return hashHex;
21
+ }
22
+ case "base64": {
23
+ return base64js.fromByteArray(hashArray);
24
+ }
25
+ }
26
+ }
27
+ /**
28
+ * Hash a file. Consistent within a session, but should not be persisted and
29
+ * is not consistent with git.
30
+ * If called under an insecure context for a browser, this will fallback to
31
+ * using the node implementation.
32
+ *
33
+ * @param file - The contents of the file in a buffer.
34
+ * @param algorithm - The hash algorithm to use, artificially constrained by what is used internally.
35
+ * @param hashEncoding - The encoding of the returned hash, also artificially constrained.
36
+ * @returns The hash of the content of the buffer.
37
+ *
38
+ * @internal
39
+ */
40
+ export async function hashFile(file, algorithm = "SHA-1", hashEncoding = "hex") {
41
+ // Handle insecure contexts (e.g. running with local services)
42
+ // by deferring to Node version, which uses a hash polyfill
43
+ // When packed, this chunk will show as "FluidFramework-HashFallback" separately
44
+ // from the main chunk and will be of non-trivial size. It will not be served
45
+ // under normal circumstances.
46
+ if (crypto.subtle === undefined) {
47
+ return import(
48
+ /* webpackChunkName: "FluidFramework-HashFallback" */
49
+ "./hashFileNode").then(async (m) => m.hashFile(file, algorithm, hashEncoding));
50
+ }
51
+ // This is split up this way to facilitate testing (see the test for more info)
52
+ const hashArray = await digestBuffer(file, algorithm);
53
+ return encodeDigest(hashArray, hashEncoding);
54
+ }
55
+ /**
56
+ * Create a github hash (Github hashes the string with blob and size)
57
+ * Must be called under secure context for browsers
58
+ *
59
+ * @param file - The contents of the file in a buffer
60
+ * @returns The sha1 hash of the content of the buffer with the `blob` prefix and size
61
+ *
62
+ * @internal
63
+ */
64
+ export async function gitHashFile(file) {
65
+ const size = file.byteLength;
66
+ const filePrefix = `blob ${size.toString()}${String.fromCharCode(0)}`;
67
+ const hashBuffer = IsoBuffer.from(filePrefix + file.toString());
68
+ // hashFile uses sha1; if that changes this will need to change too
69
+ return hashFile(hashBuffer);
70
+ }
71
+ //# sourceMappingURL=hashFileBrowser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashFileBrowser.js","sourceRoot":"","sources":["../src/hashFileBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,KAAK,UAAU,YAAY,CAAC,IAAe,EAAE,SAA8B;IAC1E,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACzD,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,YAAY,CAAC,SAAqB,EAAE,QAA0B;IACtE,wCAAwC;IACxC,QAAQ,QAAQ,EAAE;QACjB,KAAK,KAAK,CAAC,CAAC;YACX,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG;iBACjC,IAAI,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE;gBACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAW,CAAC;YACrD,CAAC,CAAC;iBACD,IAAI,CAAC,EAAE,CAAC,CAAC;YACX,OAAO,OAAO,CAAC;SACf;QACD,KAAK,QAAQ,CAAC,CAAC;YACd,OAAO,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;SACzC;KACD;AACF,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,IAAe,EACf,YAAiC,OAAO,EACxC,eAAiC,KAAK;IAEtC,8DAA8D;IAC9D,2DAA2D;IAC3D,gFAAgF;IAChF,8EAA8E;IAC9E,8BAA8B;IAC9B,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE;QAChC,OAAO,MAAM;QACZ,qDAAqD;QACrD,gBAAgB,CAChB,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;KAC/D;IAED,+EAA+E;IAC/E,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACtD,OAAO,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAe;IAChD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC;IAC7B,MAAM,UAAU,GAAG,QAAQ,IAAI,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,MAAM,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEhE,mEAAmE;IACnE,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC7B,CAAC","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\";\nimport { IsoBuffer } from \"./bufferBrowser\";\n\nasync function digestBuffer(file: IsoBuffer, algorithm: \"SHA-1\" | \"SHA-256\"): Promise<Uint8Array> {\n\tconst hash = await crypto.subtle.digest(algorithm, file);\n\treturn new Uint8Array(hash);\n}\n\nfunction encodeDigest(hashArray: Uint8Array, encoding: \"hex\" | \"base64\"): string {\n\t// eslint-disable-next-line default-case\n\tswitch (encoding) {\n\t\tcase \"hex\": {\n\t\t\tconst hashHex = Array.prototype.map\n\t\t\t\t.call(hashArray, (byte) => {\n\t\t\t\t\treturn byte.toString(16).padStart(2, \"0\") as string;\n\t\t\t\t})\n\t\t\t\t.join(\"\");\n\t\t\treturn hashHex;\n\t\t}\n\t\tcase \"base64\": {\n\t\t\treturn base64js.fromByteArray(hashArray);\n\t\t}\n\t}\n}\n\n/**\n * Hash a file. Consistent within a session, but should not be persisted and\n * is not consistent with git.\n * If called under an insecure context for a browser, this will fallback to\n * using the node implementation.\n *\n * @param file - The contents of the file in a buffer.\n * @param algorithm - The hash algorithm to use, artificially constrained by what is used internally.\n * @param hashEncoding - The encoding of the returned hash, also artificially constrained.\n * @returns The hash of the content of the buffer.\n *\n * @internal\n */\nexport async function hashFile(\n\tfile: IsoBuffer,\n\talgorithm: \"SHA-1\" | \"SHA-256\" = \"SHA-1\",\n\thashEncoding: \"hex\" | \"base64\" = \"hex\",\n): Promise<string> {\n\t// Handle insecure contexts (e.g. running with local services)\n\t// by deferring to Node version, which uses a hash polyfill\n\t// When packed, this chunk will show as \"FluidFramework-HashFallback\" separately\n\t// from the main chunk and will be of non-trivial size. It will not be served\n\t// under normal circumstances.\n\tif (crypto.subtle === undefined) {\n\t\treturn import(\n\t\t\t/* webpackChunkName: \"FluidFramework-HashFallback\" */\n\t\t\t\"./hashFileNode\"\n\t\t).then(async (m) => m.hashFile(file, algorithm, hashEncoding));\n\t}\n\n\t// This is split up this way to facilitate testing (see the test for more info)\n\tconst hashArray = await digestBuffer(file, algorithm);\n\treturn encodeDigest(hashArray, hashEncoding);\n}\n\n/**\n * Create a github hash (Github hashes the string with blob and size)\n * Must be called under secure context for browsers\n *\n * @param file - The contents of the file in a buffer\n * @returns The sha1 hash of the content of the buffer with the `blob` prefix and size\n *\n * @internal\n */\nexport async function gitHashFile(file: IsoBuffer): Promise<string> {\n\tconst size = file.byteLength;\n\tconst filePrefix = `blob ${size.toString()}${String.fromCharCode(0)}`;\n\tconst hashBuffer = IsoBuffer.from(filePrefix + file.toString());\n\n\t// hashFile uses sha1; if that changes this will need to change too\n\treturn hashFile(hashBuffer);\n}\n"]}
@@ -0,0 +1,30 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IsoBuffer } from "./bufferNode";
6
+ /**
7
+ * Hash a file. Consistent within a session, but should not be persisted and
8
+ * is not consistent with git.
9
+ * If called under an insecure context for a browser, this will fallback to
10
+ * using the node implementation.
11
+ *
12
+ * @param file - The contents of the file in a buffer.
13
+ * @param algorithm - The hash algorithm to use, artificially constrained by what is used internally.
14
+ * @param hashEncoding - The encoding of the returned hash, also artificially constrained.
15
+ * @returns The hash of the content of the buffer.
16
+ *
17
+ * @internal
18
+ */
19
+ export declare function hashFile(file: IsoBuffer, algorithm?: "SHA-1" | "SHA-256", hashEncoding?: "hex" | "base64"): Promise<string>;
20
+ /**
21
+ * Create a github hash (Github hashes the string with blob and size)
22
+ * Must be called under secure context for browsers
23
+ *
24
+ * @param file - The contents of the file in a buffer
25
+ * @returns The sha1 hash of the content of the buffer with the `blob` prefix and size
26
+ *
27
+ * @internal
28
+ */
29
+ export declare function gitHashFile(file: IsoBuffer): Promise<string>;
30
+ //# sourceMappingURL=hashFileNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashFileNode.d.ts","sourceRoot":"","sources":["../src/hashFileNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;;;;;;;;;;GAYG;AACH,wBAAsB,QAAQ,CAC7B,IAAI,EAAE,SAAS,EACf,SAAS,GAAE,OAAO,GAAG,SAAmB,EACxC,YAAY,GAAE,KAAK,GAAG,QAAgB,GACpC,OAAO,CAAC,MAAM,CAAC,CAcjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAKlE"}
@@ -0,0 +1,52 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ // eslint-disable-next-line import/no-internal-modules
6
+ import sha1 from "sha.js/sha1";
7
+ // eslint-disable-next-line import/no-internal-modules
8
+ import sha256 from "sha.js/sha256";
9
+ /**
10
+ * Hash a file. Consistent within a session, but should not be persisted and
11
+ * is not consistent with git.
12
+ * If called under an insecure context for a browser, this will fallback to
13
+ * using the node implementation.
14
+ *
15
+ * @param file - The contents of the file in a buffer.
16
+ * @param algorithm - The hash algorithm to use, artificially constrained by what is used internally.
17
+ * @param hashEncoding - The encoding of the returned hash, also artificially constrained.
18
+ * @returns The hash of the content of the buffer.
19
+ *
20
+ * @internal
21
+ */
22
+ export async function hashFile(file, algorithm = "SHA-1", hashEncoding = "hex") {
23
+ let engine;
24
+ // eslint-disable-next-line default-case
25
+ switch (algorithm) {
26
+ case "SHA-1": {
27
+ engine = new sha1();
28
+ break;
29
+ }
30
+ case "SHA-256": {
31
+ engine = new sha256();
32
+ break;
33
+ }
34
+ }
35
+ return engine.update(file).digest(hashEncoding);
36
+ }
37
+ /**
38
+ * Create a github hash (Github hashes the string with blob and size)
39
+ * Must be called under secure context for browsers
40
+ *
41
+ * @param file - The contents of the file in a buffer
42
+ * @returns The sha1 hash of the content of the buffer with the `blob` prefix and size
43
+ *
44
+ * @internal
45
+ */
46
+ export async function gitHashFile(file) {
47
+ const size = file.byteLength;
48
+ const filePrefix = `blob ${size.toString()}${String.fromCharCode(0)}`;
49
+ const engine = new sha1();
50
+ return engine.update(filePrefix).update(file).digest("hex");
51
+ }
52
+ //# sourceMappingURL=hashFileNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashFileNode.js","sourceRoot":"","sources":["../src/hashFileNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sDAAsD;AACtD,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,sDAAsD;AACtD,OAAO,MAAM,MAAM,eAAe,CAAC;AAGnC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,IAAe,EACf,YAAiC,OAAO,EACxC,eAAiC,KAAK;IAEtC,IAAI,MAAM,CAAC;IACX,wCAAwC;IACxC,QAAQ,SAAS,EAAE;QAClB,KAAK,OAAO,CAAC,CAAC;YACb,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACpB,MAAM;SACN;QACD,KAAK,SAAS,CAAC,CAAC;YACf,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YACtB,MAAM;SACN;KACD;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,YAAY,CAAW,CAAC;AAC3D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAe;IAChD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC;IAC7B,MAAM,UAAU,GAAG,QAAQ,IAAI,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,MAAM,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;IAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAW,CAAC;AACvE,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// eslint-disable-next-line import/no-internal-modules\nimport sha1 from \"sha.js/sha1\";\n// eslint-disable-next-line import/no-internal-modules\nimport sha256 from \"sha.js/sha256\";\nimport { IsoBuffer } from \"./bufferNode\";\n\n/**\n * Hash a file. Consistent within a session, but should not be persisted and\n * is not consistent with git.\n * If called under an insecure context for a browser, this will fallback to\n * using the node implementation.\n *\n * @param file - The contents of the file in a buffer.\n * @param algorithm - The hash algorithm to use, artificially constrained by what is used internally.\n * @param hashEncoding - The encoding of the returned hash, also artificially constrained.\n * @returns The hash of the content of the buffer.\n *\n * @internal\n */\nexport async function hashFile(\n\tfile: IsoBuffer,\n\talgorithm: \"SHA-1\" | \"SHA-256\" = \"SHA-1\",\n\thashEncoding: \"hex\" | \"base64\" = \"hex\",\n): Promise<string> {\n\tlet engine;\n\t// eslint-disable-next-line default-case\n\tswitch (algorithm) {\n\t\tcase \"SHA-1\": {\n\t\t\tengine = new sha1();\n\t\t\tbreak;\n\t\t}\n\t\tcase \"SHA-256\": {\n\t\t\tengine = new sha256();\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn engine.update(file).digest(hashEncoding) as string;\n}\n\n/**\n * Create a github hash (Github hashes the string with blob and size)\n * Must be called under secure context for browsers\n *\n * @param file - The contents of the file in a buffer\n * @returns The sha1 hash of the content of the buffer with the `blob` prefix and size\n *\n * @internal\n */\nexport async function gitHashFile(file: IsoBuffer): Promise<string> {\n\tconst size = file.byteLength;\n\tconst filePrefix = `blob ${size.toString()}${String.fromCharCode(0)}`;\n\tconst engine = new sha1();\n\treturn engine.update(filePrefix).update(file).digest(\"hex\") as string;\n}\n"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { fromBase64ToUtf8, fromUtf8ToBase64, toUtf8 } from "./base64Encoding";
6
+ export { Uint8ArrayToArrayBuffer } from "./bufferShared";
7
+ export { EventForwarder } from "./eventForwarder";
8
+ /**
9
+ * NOTE: This export is remapped to export from "./indexBrowser" in browser environments via package.json.
10
+ * Because the two files don't have fully isomorphic exports, using named exports for the full API surface
11
+ * is problematic if that named export includes values not in their intersection.
12
+ *
13
+ * In a future breaking change of client-utils, we could use a named export for their intersection if we
14
+ * desired.
15
+ */
16
+ export * from "./indexNode";
17
+ export { IsomorphicPerformance } from "./performanceIsomorphic";
18
+ export { ITraceEvent, Trace } from "./trace";
19
+ export { EventEmitterEventType, TypedEventEmitter, TypedEventTransform } from "./typedEventEmitter";
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD;;;;;;;GAOG;AAEH,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { fromBase64ToUtf8, fromUtf8ToBase64, toUtf8 } from "./base64Encoding";
6
+ export { Uint8ArrayToArrayBuffer } from "./bufferShared";
7
+ export { EventForwarder } from "./eventForwarder";
8
+ /**
9
+ * NOTE: This export is remapped to export from "./indexBrowser" in browser environments via package.json.
10
+ * Because the two files don't have fully isomorphic exports, using named exports for the full API surface
11
+ * is problematic if that named export includes values not in their intersection.
12
+ *
13
+ * In a future breaking change of client-utils, we could use a named export for their intersection if we
14
+ * desired.
15
+ */
16
+ // eslint-disable-next-line no-restricted-syntax
17
+ export * from "./indexNode";
18
+ // export { IRange, IRangeTrackerSnapshot, RangeTracker } from "./rangeTracker";
19
+ export { Trace } from "./trace";
20
+ export { TypedEventEmitter } from "./typedEventEmitter";
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD;;;;;;;GAOG;AACH,gDAAgD;AAChD,cAAc,aAAa,CAAC;AAE5B,gFAAgF;AAChF,OAAO,EAAe,KAAK,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAyB,iBAAiB,EAAuB,MAAM,qBAAqB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { fromBase64ToUtf8, fromUtf8ToBase64, toUtf8 } from \"./base64Encoding\";\nexport { Uint8ArrayToArrayBuffer } from \"./bufferShared\";\nexport { EventForwarder } from \"./eventForwarder\";\n/**\n * NOTE: This export is remapped to export from \"./indexBrowser\" in browser environments via package.json.\n * Because the two files don't have fully isomorphic exports, using named exports for the full API surface\n * is problematic if that named export includes values not in their intersection.\n *\n * In a future breaking change of client-utils, we could use a named export for their intersection if we\n * desired.\n */\n// eslint-disable-next-line no-restricted-syntax\nexport * from \"./indexNode\";\nexport { IsomorphicPerformance } from \"./performanceIsomorphic\";\n// export { IRange, IRangeTrackerSnapshot, RangeTracker } from \"./rangeTracker\";\nexport { ITraceEvent, Trace } from \"./trace\";\nexport { EventEmitterEventType, TypedEventEmitter, TypedEventTransform } from \"./typedEventEmitter\";\n"]}
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { bufferToString, isArrayBuffer, IsoBuffer, stringToBuffer, Uint8ArrayToString, } from "./bufferBrowser";
6
+ export { gitHashFile, hashFile } from "./hashFileBrowser";
7
+ export { performance } from "./performanceBrowser";
8
+ //# sourceMappingURL=indexBrowser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexBrowser.d.ts","sourceRoot":"","sources":["../src/indexBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,cAAc,EACd,aAAa,EACb,SAAS,EACT,cAAc,EACd,kBAAkB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ export { bufferToString, isArrayBuffer, IsoBuffer, stringToBuffer, Uint8ArrayToString, } from "./bufferBrowser";
6
+ export { gitHashFile, hashFile } from "./hashFileBrowser";
7
+ export { performance } from "./performanceBrowser";
8
+ //# sourceMappingURL=indexBrowser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexBrowser.js","sourceRoot":"","sources":["../src/indexBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,cAAc,EACd,aAAa,EACb,SAAS,EACT,cAAc,EACd,kBAAkB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tbufferToString,\n\tisArrayBuffer,\n\tIsoBuffer,\n\tstringToBuffer,\n\tUint8ArrayToString,\n} from \"./bufferBrowser\";\nexport { gitHashFile, hashFile } from \"./hashFileBrowser\";\nexport { performance } from \"./performanceBrowser\";\n"]}