@atproto/lex-data 0.0.4 → 0.0.5

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 (56) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/blob.d.ts.map +1 -1
  3. package/dist/blob.js +2 -5
  4. package/dist/blob.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/lex-error.d.ts +17 -0
  10. package/dist/lex-error.d.ts.map +1 -0
  11. package/dist/lex-error.js +26 -0
  12. package/dist/lex-error.js.map +1 -0
  13. package/dist/lib/nodejs-buffer.d.ts +1 -0
  14. package/dist/lib/nodejs-buffer.d.ts.map +1 -1
  15. package/dist/lib/nodejs-buffer.js +1 -1
  16. package/dist/lib/nodejs-buffer.js.map +1 -1
  17. package/dist/uint8array-concat.d.ts +3 -0
  18. package/dist/uint8array-concat.d.ts.map +1 -0
  19. package/dist/uint8array-concat.js +24 -0
  20. package/dist/uint8array-concat.js.map +1 -0
  21. package/dist/uint8array-from-base64.d.ts.map +1 -1
  22. package/dist/uint8array-from-base64.js +1 -1
  23. package/dist/uint8array-from-base64.js.map +1 -1
  24. package/dist/uint8array.d.ts +1 -0
  25. package/dist/uint8array.d.ts.map +1 -1
  26. package/dist/uint8array.js +14 -3
  27. package/dist/uint8array.js.map +1 -1
  28. package/dist/utf8-grapheme-len.d.ts.map +1 -1
  29. package/dist/utf8-grapheme-len.js +2 -2
  30. package/dist/utf8-grapheme-len.js.map +1 -1
  31. package/dist/utf8-len.d.ts.map +1 -1
  32. package/dist/utf8-len.js +1 -1
  33. package/dist/utf8-len.js.map +1 -1
  34. package/package.json +5 -5
  35. package/src/blob.test.ts +83 -2
  36. package/src/blob.ts +2 -7
  37. package/src/cid.test.ts +126 -0
  38. package/src/index.ts +1 -0
  39. package/src/language.test.ts +1 -0
  40. package/src/lex-equals.test.ts +30 -0
  41. package/src/lex-error.ts +34 -0
  42. package/src/lex.test.ts +65 -13
  43. package/src/lib/nodejs-buffer.ts +2 -1
  44. package/src/object.test.ts +2 -0
  45. package/src/uint8array-concat.test.ts +197 -0
  46. package/src/uint8array-concat.ts +21 -0
  47. package/src/uint8array-from-base64.test.ts +4 -1
  48. package/src/uint8array-from-base64.ts +1 -1
  49. package/src/uint8array-to-base64.test.ts +1 -1
  50. package/src/uint8array.test.ts +484 -0
  51. package/src/uint8array.ts +14 -2
  52. package/src/utf8-grapheme-len.test.ts +1 -0
  53. package/src/utf8-grapheme-len.ts +2 -2
  54. package/src/utf8-len.test.ts +1 -0
  55. package/src/utf8-len.ts +1 -1
  56. package/tsconfig.tests.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atproto/lex-data
2
2
 
3
+ ## 0.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4443](https://github.com/bluesky-social/atproto/pull/4443) [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `LexErrorData` type, and an `LexError` class to represent structured error information
8
+
9
+ - [#4443](https://github.com/bluesky-social/atproto/pull/4443) [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `ui8Concat` utility for concatenating `Uint8Array`s
10
+
3
11
  ## 0.0.4
4
12
 
5
13
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAKJ,MAAM,UAAU,CAAA;AAGjB;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;IACR,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,wBAAgB,SAAS,CACvB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7B,KAAK,IAAI,OAAO,CAyDlB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CA2BtE"}
1
+ {"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAKJ,MAAM,UAAU,CAAA;AAGjB;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;IACR,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,wBAAgB,SAAS,CACvB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7B,KAAK,IAAI,OAAO,CAoDlB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CA2BtE"}
package/dist/blob.js CHANGED
@@ -16,10 +16,7 @@ function isBlobRef(input, options) {
16
16
  if (typeof mimeType !== 'string' || !mimeType.includes('/')) {
17
17
  return false;
18
18
  }
19
- if (typeof size !== 'number' ||
20
- size < 0 ||
21
- !Number.isInteger(size) ||
22
- !Number.isSafeInteger(size)) {
19
+ if (typeof size !== 'number' || size < 0 || !Number.isSafeInteger(size)) {
23
20
  return false;
24
21
  }
25
22
  if (typeof ref !== 'object' || ref === null) {
@@ -58,7 +55,7 @@ function isLegacyBlobRef(input) {
58
55
  if (typeof cid !== 'string') {
59
56
  return false;
60
57
  }
61
- if (typeof mimeType !== 'string') {
58
+ if (typeof mimeType !== 'string' || mimeType.length === 0) {
62
59
  return false;
63
60
  }
64
61
  for (const key in input) {
package/dist/blob.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"blob.js","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":";;AAmBA,8BA4DC;AAUD,0CA2BC;AApHD,qCAMiB;AACjB,2CAA2C;AAY3C,SAAgB,SAAS,CACvB,KAAc,EACd,OAA8B;IAE9B,IAAI,CAAC,IAAA,yBAAa,EAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,KAAK,EAAE,KAAK,KAAK,MAAM,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK,CAAA;IACrC,mCAAmC;IACnC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5D,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IACE,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,GAAG,CAAC;QACR,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;QACvB,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,EAC3B,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IACE,GAAG,KAAK,OAAO;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P,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import {\n Cid,\n RAW_BIN_MULTICODEC,\n SHA2_256_MULTIHASH_CODE,\n asCid,\n parseCid,\n} from './cid.js'\nimport { isPlainObject } from './object.js'\n\n/**\n * @note {@link BlobRef} is just a {@link LexMap} with a specific shape.\n */\nexport type BlobRef = {\n $type: 'blob'\n mimeType: string\n ref: Cid\n size: number\n}\n\nexport function isBlobRef(\n input: unknown,\n options?: { strict?: boolean },\n): input is BlobRef {\n if (!isPlainObject(input)) {\n return false\n }\n\n if (input?.$type !== 'blob') {\n return false\n }\n\n const { mimeType, size, ref } = input\n // @NOTE Very basic mime validation\n if (typeof mimeType !== 'string' || !mimeType.includes('/')) {\n return false\n }\n\n if (\n typeof size !== 'number' ||\n size < 0 ||\n !Number.isInteger(size) ||\n !Number.isSafeInteger(size)\n ) {\n return false\n }\n\n if (typeof ref !== 'object' || ref === null) {\n return false\n }\n\n for (const key in input) {\n if (\n key !== '$type' &&\n key !== 'mimeType' &&\n key !== 'ref' &&\n key !== 'size'\n ) {\n return false\n }\n }\n\n const cid = asCid(ref)\n if (!cid) {\n return false\n }\n\n if (options?.strict) {\n if (cid.version !== 1) {\n return false\n }\n if (cid.code !== RAW_BIN_MULTICODEC) {\n return false\n }\n if (cid.multihash.code !== SHA2_256_MULTIHASH_CODE) {\n return false\n }\n }\n\n return true\n}\n\n/**\n * @note {@link LegacyBlobRef} is just a {@link LexMap} with a specific shape.\n */\nexport type LegacyBlobRef = {\n cid: string\n mimeType: string\n}\n\nexport function isLegacyBlobRef(input: unknown): input is LegacyBlobRef {\n if (!isPlainObject(input)) {\n return false\n }\n\n const { cid, mimeType } = input\n if (typeof cid !== 'string') {\n return false\n }\n\n if (typeof mimeType !== 'string') {\n return false\n }\n\n for (const key in input) {\n if (key !== 'cid' && key !== 'mimeType') {\n return false\n }\n }\n\n try {\n parseCid(cid)\n } catch {\n return false\n }\n\n return true\n}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I,GAAG,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,KAAK,CAAA;QACd,CAAC;QACD,IAAI,GAAG,CAAC,IAAI,KAAK,2BAAkB,EAAE,CAAC;YACpC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,IAAI,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,gCAAuB,EAAE,CAAC;YACnD,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAUD,SAAgB,eAAe,CAAC,KAAc;IAC5C,IAAI,CAAC,IAAA,yBAAa,EAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IAC/B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1D,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,UAAU,EAAE,CAAC;YACxC,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,IAAI,CAAC;QACH,IAAA,iBAAQ,EAAC,GAAG,CAAC,CAAA;IACf,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import {\n Cid,\n RAW_BIN_MULTICODEC,\n SHA2_256_MULTIHASH_CODE,\n asCid,\n parseCid,\n} from './cid.js'\nimport { isPlainObject } from './object.js'\n\n/**\n * @note {@link BlobRef} is just a {@link LexMap} with a specific shape.\n */\nexport type BlobRef = {\n $type: 'blob'\n mimeType: string\n ref: Cid\n size: number\n}\n\nexport function isBlobRef(\n input: unknown,\n options?: { strict?: boolean },\n): input is BlobRef {\n if (!isPlainObject(input)) {\n return false\n }\n\n if (input?.$type !== 'blob') {\n return false\n }\n\n const { mimeType, size, ref } = input\n // @NOTE Very basic mime validation\n if (typeof mimeType !== 'string' || !mimeType.includes('/')) {\n return false\n }\n\n if (typeof size !== 'number' || size < 0 || !Number.isSafeInteger(size)) {\n return false\n }\n\n if (typeof ref !== 'object' || ref === null) {\n return false\n }\n\n for (const key in input) {\n if (\n key !== '$type' &&\n key !== 'mimeType' &&\n key !== 'ref' &&\n key !== 'size'\n ) {\n return false\n }\n }\n\n const cid = asCid(ref)\n if (!cid) {\n return false\n }\n\n if (options?.strict) {\n if (cid.version !== 1) {\n return false\n }\n if (cid.code !== RAW_BIN_MULTICODEC) {\n return false\n }\n if (cid.multihash.code !== SHA2_256_MULTIHASH_CODE) {\n return false\n }\n }\n\n return true\n}\n\n/**\n * @note {@link LegacyBlobRef} is just a {@link LexMap} with a specific shape.\n */\nexport type LegacyBlobRef = {\n cid: string\n mimeType: string\n}\n\nexport function isLegacyBlobRef(input: unknown): input is LegacyBlobRef {\n if (!isPlainObject(input)) {\n return false\n }\n\n const { cid, mimeType } = input\n if (typeof cid !== 'string') {\n return false\n }\n\n if (typeof mimeType !== 'string' || mimeType.length === 0) {\n return false\n }\n\n for (const key in input) {\n if (key !== 'cid' && key !== 'mimeType') {\n return false\n }\n }\n\n try {\n parseCid(cid)\n } catch {\n return false\n }\n\n return true\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './blob.js';
2
2
  export * from './cid.js';
3
3
  export * from './language.js';
4
4
  export * from './lex-equals.js';
5
+ export * from './lex-error.js';
5
6
  export * from './lex.js';
6
7
  export * from './object.js';
7
8
  export * from './uint8array.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA"}
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ tslib_1.__exportStar(require("./blob.js"), exports);
5
5
  tslib_1.__exportStar(require("./cid.js"), exports);
6
6
  tslib_1.__exportStar(require("./language.js"), exports);
7
7
  tslib_1.__exportStar(require("./lex-equals.js"), exports);
8
+ tslib_1.__exportStar(require("./lex-error.js"), exports);
8
9
  tslib_1.__exportStar(require("./lex.js"), exports);
9
10
  tslib_1.__exportStar(require("./object.js"), exports);
10
11
  tslib_1.__exportStar(require("./uint8array.js"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,mDAAwB;AACxB,wDAA6B;AAC7B,0DAA+B;AAC/B,mDAAwB;AACxB,sDAA2B;AAC3B,0DAA+B;AAC/B,oDAAyB","sourcesContent":["export * from './blob.js'\nexport * from './cid.js'\nexport * from './language.js'\nexport * from './lex-equals.js'\nexport * from './lex.js'\nexport * from './object.js'\nexport * from './uint8array.js'\nexport * from './utf8.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,mDAAwB;AACxB,wDAA6B;AAC7B,0DAA+B;AAC/B,yDAA8B;AAC9B,mDAAwB;AACxB,sDAA2B;AAC3B,0DAA+B;AAC/B,oDAAyB","sourcesContent":["export * from './blob.js'\nexport * from './cid.js'\nexport * from './language.js'\nexport * from './lex-equals.js'\nexport * from './lex-error.js'\nexport * from './lex.js'\nexport * from './object.js'\nexport * from './uint8array.js'\nexport * from './utf8.js'\n"]}
@@ -0,0 +1,17 @@
1
+ export type LexErrorCode = string;
2
+ export type LexErrorData<N extends LexErrorCode = LexErrorCode> = {
3
+ error: N;
4
+ message?: string;
5
+ };
6
+ export declare class LexError<N extends LexErrorCode = LexErrorCode> extends Error {
7
+ readonly error: N;
8
+ name: string;
9
+ constructor(error: N, message?: string, options?: ErrorOptions);
10
+ toString(): string;
11
+ toJSON(): LexErrorData<N>;
12
+ /**
13
+ * Translate into an HTTP response for downstream clients.
14
+ */
15
+ toResponse(): Response;
16
+ }
17
+ //# sourceMappingURL=lex-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lex-error.d.ts","sourceRoot":"","sources":["../src/lex-error.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,CAAA;AAEjC,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI;IAChE,KAAK,EAAE,CAAC,CAAA;IACR,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,qBAAa,QAAQ,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,CAAE,SAAQ,KAAK;IAItE,QAAQ,CAAC,KAAK,EAAE,CAAC;IAHnB,IAAI,SAAa;gBAGN,KAAK,EAAE,CAAC,EACjB,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,YAAY;IAKxB,QAAQ,IAAI,MAAM;IAIlB,MAAM,IAAI,YAAY,CAAC,CAAC,CAAC;IAKzB;;OAEG;IACH,UAAU,IAAI,QAAQ;CAGvB"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LexError = void 0;
4
+ class LexError extends Error {
5
+ error;
6
+ name = 'LexError';
7
+ constructor(error, message, options) {
8
+ super(message, options);
9
+ this.error = error;
10
+ }
11
+ toString() {
12
+ return `${this.name}: [${this.error}] ${this.message}`;
13
+ }
14
+ toJSON() {
15
+ const { error, message } = this;
16
+ return { error, message: message ?? undefined };
17
+ }
18
+ /**
19
+ * Translate into an HTTP response for downstream clients.
20
+ */
21
+ toResponse() {
22
+ return Response.json(this.toJSON(), { status: 400 });
23
+ }
24
+ }
25
+ exports.LexError = LexError;
26
+ //# sourceMappingURL=lex-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lex-error.js","sourceRoot":"","sources":["../src/lex-error.ts"],"names":[],"mappings":";;;AAOA,MAAa,QAAgD,SAAQ,KAAK;IAI7D;IAHX,IAAI,GAAG,UAAU,CAAA;IAEjB,YACW,KAAQ,EACjB,OAAgB,EAChB,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAJd,UAAK,GAAL,KAAK,CAAG;IAKnB,CAAC;IAED,QAAQ;QACN,OAAO,GAAG,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,OAAO,EAAE,CAAA;IACxD,CAAC;IAED,MAAM;QACJ,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;QAC/B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,CAAA;IACjD,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;IACtD,CAAC;CACF;AA1BD,4BA0BC","sourcesContent":["export type LexErrorCode = string\n\nexport type LexErrorData<N extends LexErrorCode = LexErrorCode> = {\n error: N\n message?: string\n}\n\nexport class LexError<N extends LexErrorCode = LexErrorCode> extends Error {\n name = 'LexError'\n\n constructor(\n readonly error: N,\n message?: string,\n options?: ErrorOptions,\n ) {\n super(message, options)\n }\n\n toString(): string {\n return `${this.name}: [${this.error}] ${this.message}`\n }\n\n toJSON(): LexErrorData<N> {\n const { error, message } = this\n return { error, message: message ?? undefined }\n }\n\n /**\n * Translate into an HTTP response for downstream clients.\n */\n toResponse(): Response {\n return Response.json(this.toJSON(), { status: 400 })\n }\n}\n"]}
@@ -7,6 +7,7 @@ interface NodeJSBufferConstructor {
7
7
  new (input: string, encoding?: Encoding): NodeJSBuffer;
8
8
  from(input: Uint8Array | ArrayBuffer | ArrayBufferView): NodeJSBuffer<ArrayBuffer>;
9
9
  from(input: string, encoding?: Encoding): NodeJSBuffer<ArrayBuffer>;
10
+ concat(list: readonly Uint8Array[], totalLength?: number): NodeJSBuffer;
10
11
  byteLength(input: string, encoding?: Encoding): number;
11
12
  prototype: NodeJSBuffer;
12
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"nodejs-buffer.d.ts","sourceRoot":"","sources":["../../src/lib/nodejs-buffer.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAA;AAE/C,UAAU,YAAY,CAAC,YAAY,SAAS,eAAe,GAAG,eAAe,CAC3E,SAAQ,UAAU,CAAC,YAAY,CAAC;IAChC,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAA;CACtC;AAED,UAAU,uBAAuB;IAC/B,KAAK,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,YAAY,CAAA;IACtD,IAAI,CACF,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,eAAe,GAChD,YAAY,CAAC,WAAW,CAAC,CAAA;IAC5B,IAAI,CAAC,KAAK,E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Bu' + 'f'.repeat(2) + 'er')();
8
8
  exports.NodeJSBuffer = globalThis?.[BUFFER]?.prototype instanceof Uint8Array &&
9
9
  'byteLength' in globalThis[BUFFER]
10
10
  ? globalThis[BUFFER]
11
- : null;
11
+ : /* v8 ignore next -- @preserve */ null;
12
12
  //# sourceMappingURL=nodejs-buffer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nodejs-buffer.js","sourceRoot":"","sources":["../../src/lib/nodejs-buffer.ts"],"names":[],"mappings":";;;AAkBA,6EAA6E;AAC7E,6EAA6E;AAC7E,qBAAqB;AACrB,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAc,CAAA;AACjE,QAAA,YAAY,GACtB,UAAkB,EAAE,CAAC,MAAM,CAAC,EAAE,SAAS,YAAY,UAAU;IAC9D,YAAY,IAAK,UAAkB,CAAC,MAAM,CAAC;IACzC,CAAC,CAAG,UAAkB,CAAC,MAAM,CAA6B;IAC1D,CAAC,CAAC,IAAI,CAAA","sourcesContent":["type Encoding = 'utf8' | 'base64' | 'base64url'\n\ninterface NodeJSBuffer<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>\n extends Uint8Array<TArrayBuffer> {\n byteLength: number\n toString(encoding?: Encoding): string\n}\n\ninterface NodeJSBufferConstructor {\n new (input: string, encoding?: Encoding): NodeJSBuffer\n from(\n input: Uint8Array | ArrayBuffer | ArrayBufferView,\n ): NodeJSBuffer<ArrayBuffer>\n from(input: string, encoding?: Encoding): NodeJSBuffer<ArrayBuffer>\n byteLength(input: string, encoding?: Encoding): number\n prototype: NodeJSBuffer\n}\n\n// Avoids a direct reference to Node.js Buffer, which might not exist in some\n// environments (e.g. browsers, Deno, Bun) to prevent bundlers from trying to\n// include polyfills.\nconst BUFFER = /*#__PURE__*/ (() => 'Bu' + 'f'.repeat(2) + 'er')() as 'Buffer'\nexport const NodeJSBuffer: NodeJSBufferConstructor | null =\n (globalThis as any)?.[BUFFER]?.prototype instanceof Uint8Array &&\n 'byteLength' in (globalThis as any)[BUFFER]\n ? ((globalThis as any)[BUFFER] as NodeJSBufferConstructor)\n : null\n"]}
1
+ {"version":3,"file":"nodejs-buffer.js","sourceRoot":"","sources":["../../src/lib/nodejs-buffer.ts"],"names":[],"mappings":";;;AAmBA,6EAA6E;AAC7E,6EAA6E;AAC7E,qBAAqB;AACrB,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAc,CAAA;AACjE,QAAA,YAAY,GACtB,UAAkB,EAAE,CAAC,MAAM,CAAC,EAAE,SAAS,YAAY,UAAU;IAC9D,YAAY,IAAK,UAAkB,CAAC,MAAM,CAAC;IACzC,CAAC,CAAG,UAAkB,CAAC,MAAM,CAA6B;IAC1D,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA","sourcesContent":["type Encoding = 'utf8' | 'base64' | 'base64url'\n\ninterface NodeJSBuffer<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>\n extends Uint8Array<TArrayBuffer> {\n byteLength: number\n toString(encoding?: Encoding): string\n}\n\ninterface NodeJSBufferConstructor {\n new (input: string, encoding?: Encoding): NodeJSBuffer\n from(\n input: Uint8Array | ArrayBuffer | ArrayBufferView,\n ): NodeJSBuffer<ArrayBuffer>\n from(input: string, encoding?: Encoding): NodeJSBuffer<ArrayBuffer>\n concat(list: readonly Uint8Array[], totalLength?: number): NodeJSBuffer\n byteLength(input: string, encoding?: Encoding): number\n prototype: NodeJSBuffer\n}\n\n// Avoids a direct reference to Node.js Buffer, which might not exist in some\n// environments (e.g. browsers, Deno, Bun) to prevent bundlers from trying to\n// include polyfills.\nconst BUFFER = /*#__PURE__*/ (() => 'Bu' + 'f'.repeat(2) + 'er')() as 'Buffer'\nexport const NodeJSBuffer: NodeJSBufferConstructor | null =\n (globalThis as any)?.[BUFFER]?.prototype instanceof Uint8Array &&\n 'byteLength' in (globalThis as any)[BUFFER]\n ? ((globalThis as any)[BUFFER] as NodeJSBufferConstructor)\n : /* v8 ignore next -- @preserve */ null\n"]}
@@ -0,0 +1,3 @@
1
+ export declare const ui8ConcatNode: ((array: readonly Uint8Array[]) => Uint8Array) | null;
2
+ export declare function ui8ConcatPonyfill(array: readonly Uint8Array[]): Uint8Array;
3
+ //# sourceMappingURL=uint8array-concat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint8array-concat.d.ts","sourceRoot":"","sources":["../src/uint8array-concat.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,WACQ,SAAS,UAAU,EAAE,KAAG,UAAU,QAG1B,CAAA;AAE1C,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAU1E"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ui8ConcatNode = void 0;
4
+ exports.ui8ConcatPonyfill = ui8ConcatPonyfill;
5
+ const nodejs_buffer_js_1 = require("./lib/nodejs-buffer.js");
6
+ const Buffer = nodejs_buffer_js_1.NodeJSBuffer;
7
+ exports.ui8ConcatNode = Buffer
8
+ ? function ui8ConcatNode(array) {
9
+ return Buffer.concat(array);
10
+ }
11
+ : /* v8 ignore next -- @preserve */ null;
12
+ function ui8ConcatPonyfill(array) {
13
+ let totalLength = 0;
14
+ for (const arr of array)
15
+ totalLength += arr.length;
16
+ const result = new Uint8Array(totalLength);
17
+ let offset = 0;
18
+ for (const arr of array) {
19
+ result.set(arr, offset);
20
+ offset += arr.length;
21
+ }
22
+ return result;
23
+ }
24
+ //# sourceMappingURL=uint8array-concat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint8array-concat.js","sourceRoot":"","sources":["../src/uint8array-concat.ts"],"names":[],"mappings":";;;AAUA,8CAUC;AApBD,6DAAqD;AAErD,MAAM,MAAM,GAAG,+BAAY,CAAA;AAEd,QAAA,aAAa,GAAG,MAAM;IACjC,CAAC,CAAC,SAAS,aAAa,CAAC,KAA4B;QACjD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,SAAgB,iBAAiB,CAAC,KAA4B;IAC5D,IAAI,WAAW,GAAG,CAAC,CAAA;IACnB,KAAK,MAAM,GAAG,IAAI,KAAK;QAAE,WAAW,IAAI,GAAG,CAAC,MAAM,CAAA;IAClD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAA;IAC1C,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACvB,MAAM,IAAI,GAAG,CAAC,MAAM,CAAA;IACtB,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { NodeJSBuffer } from './lib/nodejs-buffer.js'\n\nconst Buffer = NodeJSBuffer\n\nexport const ui8ConcatNode = Buffer\n ? function ui8ConcatNode(array: readonly Uint8Array[]): Uint8Array {\n return Buffer.concat(array)\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport function ui8ConcatPonyfill(array: readonly Uint8Array[]): Uint8Array {\n let totalLength = 0\n for (const arr of array) totalLength += arr.length\n const result = new Uint8Array(totalLength)\n let offset = 0\n for (const arr of array) {\n result.set(arr, offset)\n offset += arr.length\n }\n return result\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"uint8array-from-base64.d.ts","sourceRoot":"","sources":["../src/uint8array-from-base64.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAIvD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B;;WAEG;QACH,UAAU,CAAC,EAAE,CACX,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;YACR,wBAAwB;YACxB,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAA;YACjC,iBAAiB,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,qBAAqB,CAAA;SAC/D,KACE,UAAU,CAAA;KAChB;CACF;AAED,eAAO,MAAM,gBAAgB,SAGhB,MAAM,aACD,cAAc,KACvB,UAAU,QAMT,CAAA;AAEV,eAAO,MAAM,cAAc,SAEhB,MAAM,aACD,cAAc,KACvB,UAAU,QAQT,CAAA;AAER,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,cAAyB,GAClC,UAAU,CAIZ"}
1
+ {"version":3,"file":"uint8array-from-base64.d.ts","sourceRoot":"","sources":["../src/uint8array-from-base64.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAIvD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B;;WAEG;QACH,UAAU,CAAC,EAAE,CACX,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;YACR,wBAAwB;YACxB,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAA;YACjC,iBAAiB,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,qBAAqB,CAAA;SAC/D,KACE,UAAU,CAAA;KAChB;CACF;AAED,eAAO,MAAM,gBAAgB,SAGhB,MAAM,aACD,cAAc,KACvB,UAAU,QAMT,CAAA;AAEV,eAAO,MAAM,cAAc,SAEhB,MAAM,aACD,cAAc,KACvB,UAAU,QAQyB,CAAA;AAE1C,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,cAAyB,GAClC,UAAU,CAIZ"}
@@ -22,7 +22,7 @@ exports.fromBase64Node = Buffer
22
22
  // results in unexpected behavior downstream (e.g. in tests)
23
23
  return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
24
24
  }
25
- : null;
25
+ : /* v8 ignore next -- @preserve */ null;
26
26
  function fromBase64Ponyfill(b64, alphabet = 'base64') {
27
27
  const bytes = (0, from_string_1.fromString)(b64, b64.endsWith('=') ? `${alphabet}pad` : alphabet);
28
28
  verifyBase64ForBytes(b64, bytes);
@@ -1 +1 @@
1
- {"version":3,"file":"uint8array-from-base64.js","sourceRoot":"","sources":["../src/uint8array-from-base64.ts"],"names":[],"mappings":";;;AAiDA,gDAOC;AAxDD,yDAAoD;AACpD,6DAAqD;AAGrD,MAAM,MAAM,GAAG,+BAAY,CAAA;AAkBd,QAAA,gBAAgB,GAC3B,OAAO,UAAU,CAAC,UAAU,KAAK,UAAU;IACzC,CAAC,CAAC,SAAS,gBAAgB,CACvB,GAAW,EACX,WAA2B,QAAQ;QAEnC,OAAO,UAAU,CAAC,UAAW,CAAC,GAAG,EAAE;YACjC,QAAQ;YACR,iBAAiB,EAAE,OAAO;SAC3B,CAAC,CAAA;IACJ,CAAC;IACH,CAAC,CAAC,IAAI,CAAA;AAEG,QAAA,cAAc,GAAG,MAAM;IAClC,CAAC,CAAC,SAAS,cAAc,CACrB,GAAW,EACX,WAA2B,QAAQ;QAEnC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;QACxC,oBAAoB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QAChC,qEAAqE;QACrE,yEAAyE;QACzE,4DAA4D;QAC5D,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;IACzE,CAAC;IACH,CAAC,CAAC,IAAI,CAAA;AAER,SAAgB,kBAAkB,CAChC,GAAW,EACX,WAA2B,QAAQ;IAEnC,MAAM,KAAK,GAAG,IAAA,wBAAU,EAAC,GAAG,EAAE,GAAG,CAAC,QAAQ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,KACE,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,EACpC,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,YAAY,EAC7B,CAAC,EAAE,EACH,CAAC;QACD,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAC9B,IACE,CAAC,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,IAAI,MAAM;YACrC,CAAC,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,GAAG,CAAC,IAAI,MAAM;YACtC,CAAC,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,IAAI,MAAM;YACrC,IAAI,KAAK,EAAE,IAAI,IAAI;YACnB,IAAI,KAAK,EAAE,CAAC,IAAI;UAChB,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;QAC1C,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { fromString } from 'uint8arrays/from-string'\nimport { NodeJSBuffer } from './lib/nodejs-buffer.js'\nimport { Base64Alphabet } from './uint8array-base64.js'\n\nconst Buffer = NodeJSBuffer\n\ndeclare global {\n interface Uint8ArrayConstructor {\n /**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64 Uint8Array.fromBase64()}\n */\n fromBase64?: (\n b64: string,\n options?: {\n /** @default 'base64' */\n alphabet?: 'base64' | 'base64url'\n lastChunkHandling?: 'loose' | 'strict' | 'stop-before-partial'\n },\n ) => Uint8Array\n }\n}\n\nexport const fromBase64Native =\n typeof Uint8Array.fromBase64 === 'function'\n ? function fromBase64Native(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n ): Uint8Array {\n return Uint8Array.fromBase64!(b64, {\n alphabet,\n lastChunkHandling: 'loose',\n })\n }\n : null\n\nexport const fromBase64Node = Buffer\n ? function fromBase64Node(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n ): Uint8Array {\n const bytes = Buffer.from(b64, alphabet)\n verifyBase64ForBytes(b64, bytes)\n // Convert to Uint8Array because even though Buffer is a sub class of\n // Uint8Array, it serializes differently to Uint8Array (e.g. in JSON) and\n // results in unexpected behavior downstream (e.g. in tests)\n return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n }\n : null\n\nexport function fromBase64Ponyfill(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n): Uint8Array {\n const bytes = fromString(b64, b64.endsWith('=') ? `${alphabet}pad` : alphabet)\n verifyBase64ForBytes(b64, bytes)\n return bytes\n}\n\n// @NOTE NodeJS will silently stop decoding at the first invalid character,\n// while \"uint8arrays/from-string\" will not validate that the padding is\n// correct. The following function performs basic validation to ensure that the\n// input was a valid base64 string. The availability of the \"bytes\" allows\n// to perform checks with O[1] complexity.\nfunction verifyBase64ForBytes(b64: string, bytes: Uint8Array): void {\n const paddingCount = b64.endsWith('==') ? 2 : b64.endsWith('=') ? 1 : 0\n const trimmedLength = b64.length - paddingCount\n const expectedByteLength = Math.floor((trimmedLength * 3) / 4)\n if (bytes.length !== expectedByteLength) {\n throw new Error('Invalid base64 string')\n }\n\n const expectedB64Length = (bytes.length / 3) * 4\n const expectedPaddingCount =\n expectedB64Length % 4 === 0 ? 0 : 4 - (expectedB64Length % 4)\n const expectedFullB64Length = expectedB64Length + expectedPaddingCount\n if (b64.length > expectedFullB64Length) {\n throw new Error('Invalid base64 string')\n }\n\n // The previous might still allow false positive if only the last few\n // chars are invalid.\n for (\n let i = Math.ceil(expectedB64Length);\n i < b64.length - paddingCount;\n i++\n ) {\n const code = b64.charCodeAt(i)\n if (\n !(code >= 65 && code <= 90) && // A-Z\n !(code >= 97 && code <= 122) && // a-z\n !(code >= 48 && code <= 57) && // 0-9\n code !== 43 && // +\n code !== 47 // /\n ) {\n throw new Error('Invalid base64 string')\n }\n }\n}\n"]}
1
+ {"version":3,"file":"uint8array-from-base64.js","sourceRoot":"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,CAAC,IAAI,MAAM;YACrC,CAAC,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,GAAG,CAAC,IAAI,MAAM;YACtC,CAAC,CAAC,IAAI,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,IAAI,MAAM;YACrC,IAAI,KAAK,EAAE,IAAI,IAAI;YACnB,IAAI,KAAK,EAAE,CAAC,IAAI;UAChB,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;QAC1C,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { fromString } from 'uint8arrays/from-string'\nimport { NodeJSBuffer } from './lib/nodejs-buffer.js'\nimport { Base64Alphabet } from './uint8array-base64.js'\n\nconst Buffer = NodeJSBuffer\n\ndeclare global {\n interface Uint8ArrayConstructor {\n /**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64 Uint8Array.fromBase64()}\n */\n fromBase64?: (\n b64: string,\n options?: {\n /** @default 'base64' */\n alphabet?: 'base64' | 'base64url'\n lastChunkHandling?: 'loose' | 'strict' | 'stop-before-partial'\n },\n ) => Uint8Array\n }\n}\n\nexport const fromBase64Native =\n typeof Uint8Array.fromBase64 === 'function'\n ? function fromBase64Native(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n ): Uint8Array {\n return Uint8Array.fromBase64!(b64, {\n alphabet,\n lastChunkHandling: 'loose',\n })\n }\n : null\n\nexport const fromBase64Node = Buffer\n ? function fromBase64Node(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n ): Uint8Array {\n const bytes = Buffer.from(b64, alphabet)\n verifyBase64ForBytes(b64, bytes)\n // Convert to Uint8Array because even though Buffer is a sub class of\n // Uint8Array, it serializes differently to Uint8Array (e.g. in JSON) and\n // results in unexpected behavior downstream (e.g. in tests)\n return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport function fromBase64Ponyfill(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n): Uint8Array {\n const bytes = fromString(b64, b64.endsWith('=') ? `${alphabet}pad` : alphabet)\n verifyBase64ForBytes(b64, bytes)\n return bytes\n}\n\n// @NOTE NodeJS will silently stop decoding at the first invalid character,\n// while \"uint8arrays/from-string\" will not validate that the padding is\n// correct. The following function performs basic validation to ensure that the\n// input was a valid base64 string. The availability of the \"bytes\" allows\n// to perform checks with O[1] complexity.\nfunction verifyBase64ForBytes(b64: string, bytes: Uint8Array): void {\n const paddingCount = b64.endsWith('==') ? 2 : b64.endsWith('=') ? 1 : 0\n const trimmedLength = b64.length - paddingCount\n const expectedByteLength = Math.floor((trimmedLength * 3) / 4)\n if (bytes.length !== expectedByteLength) {\n throw new Error('Invalid base64 string')\n }\n\n const expectedB64Length = (bytes.length / 3) * 4\n const expectedPaddingCount =\n expectedB64Length % 4 === 0 ? 0 : 4 - (expectedB64Length % 4)\n const expectedFullB64Length = expectedB64Length + expectedPaddingCount\n if (b64.length > expectedFullB64Length) {\n throw new Error('Invalid base64 string')\n }\n\n // The previous might still allow false positive if only the last few\n // chars are invalid.\n for (\n let i = Math.ceil(expectedB64Length);\n i < b64.length - paddingCount;\n i++\n ) {\n const code = b64.charCodeAt(i)\n if (\n !(code >= 65 && code <= 90) && // A-Z\n !(code >= 97 && code <= 122) && // a-z\n !(code >= 48 && code <= 57) && // 0-9\n code !== 43 && // +\n code !== 47 // /\n ) {\n throw new Error('Invalid base64 string')\n }\n }\n}\n"]}
@@ -21,4 +21,5 @@ export declare const fromBase64: (b64: string, alphabet?: Base64Alphabet) => Uin
21
21
  */
22
22
  export declare function asUint8Array(input: unknown): Uint8Array | undefined;
23
23
  export declare function ui8Equals(a: Uint8Array, b: Uint8Array): boolean;
24
+ export declare const ui8Concat: (array: readonly Uint8Array[]) => Uint8Array;
24
25
  //# sourceMappingURL=uint8array.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uint8array.d.ts","sourceRoot":"","sources":["../src/uint8array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAYvD,YAAY,EAAE,cAAc,EAAE,CAAA;AAO9B;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,CACrB,KAAK,EAAE,UAAU,EACjB,QAAQ,CAAC,EAAE,cAAc,KACtB,MAA2D,CAAA;AAEhE;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,EAAE,CACvB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,cAAc,KACtB,UAAqE,CAAA;AAS1E;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAkBnE;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAY/D"}
1
+ {"version":3,"file":"uint8array.d.ts","sourceRoot":"","sources":["../src/uint8array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAavD,YAAY,EAAE,cAAc,EAAE,CAAA;AAO9B;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,CACrB,KAAK,EAAE,UAAU,EACjB,QAAQ,CAAC,EAAE,cAAc,KACtB,MAG+C,CAAA;AAEpD;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,EAAE,CACvB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,cAAc,KACtB,UAGiD,CAAA;AAUtD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAkBnE;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAY/D;AAED,eAAO,MAAM,SAAS,8CAE+B,CAAA"}
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fromBase64 = exports.toBase64 = void 0;
3
+ exports.ui8Concat = exports.fromBase64 = exports.toBase64 = void 0;
4
4
  exports.asUint8Array = asUint8Array;
5
5
  exports.ui8Equals = ui8Equals;
6
+ const uint8array_concat_js_1 = require("./uint8array-concat.js");
6
7
  const uint8array_from_base64_js_1 = require("./uint8array-from-base64.js");
7
8
  const uint8array_to_base64_js_1 = require("./uint8array-to-base64.js");
8
9
  // @TODO drop dependency on uint8arrays package once Uint8Array.fromBase64 /
@@ -14,7 +15,10 @@ const uint8array_to_base64_js_1 = require("./uint8array-to-base64.js");
14
15
  *
15
16
  * @returns The base64 encoded string
16
17
  */
17
- exports.toBase64 = uint8array_to_base64_js_1.toBase64Native ?? uint8array_to_base64_js_1.toBase64Node ?? uint8array_to_base64_js_1.toBase64Ponyfill;
18
+ exports.toBase64 =
19
+ /* v8 ignore next -- @preserve */ uint8array_to_base64_js_1.toBase64Native ??
20
+ /* v8 ignore next -- @preserve */ uint8array_to_base64_js_1.toBase64Node ??
21
+ /* v8 ignore next -- @preserve */ uint8array_to_base64_js_1.toBase64Ponyfill;
18
22
  /**
19
23
  * Decodes a base64 string into a Uint8Array. This function supports both padded
20
24
  * and unpadded base64 strings.
@@ -22,7 +26,11 @@ exports.toBase64 = uint8array_to_base64_js_1.toBase64Native ?? uint8array_to_bas
22
26
  * @returns The decoded {@link Uint8Array}
23
27
  * @throws If the input is not a valid base64 string
24
28
  */
25
- exports.fromBase64 = uint8array_from_base64_js_1.fromBase64Native ?? uint8array_from_base64_js_1.fromBase64Node ?? uint8array_from_base64_js_1.fromBase64Ponyfill;
29
+ exports.fromBase64 =
30
+ /* v8 ignore next -- @preserve */ uint8array_from_base64_js_1.fromBase64Native ??
31
+ /* v8 ignore next -- @preserve */ uint8array_from_base64_js_1.fromBase64Node ??
32
+ /* v8 ignore next -- @preserve */ uint8array_from_base64_js_1.fromBase64Ponyfill;
33
+ /* v8 ignore next -- @preserve */
26
34
  if (exports.toBase64 === uint8array_to_base64_js_1.toBase64Ponyfill || exports.fromBase64 === uint8array_from_base64_js_1.fromBase64Ponyfill) {
27
35
  /*#__PURE__*/
28
36
  console.warn('[@atproto/lex-data]: Uint8Array.fromBase64 / Uint8Array.prototype.toBase64 not available in this environment. Falling back to ponyfill implementation.');
@@ -55,4 +63,7 @@ function ui8Equals(a, b) {
55
63
  }
56
64
  return true;
57
65
  }
66
+ exports.ui8Concat =
67
+ /* v8 ignore next -- @preserve */ uint8array_concat_js_1.ui8ConcatNode ??
68
+ /* v8 ignore next -- @preserve */ uint8array_concat_js_1.ui8ConcatPonyfill;
58
69
  //# sourceMappingURL=uint8array.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"uint8array.js","sourceRoot":"","sources":["../src/uint8array.ts"],"names":[],"mappings":";;;AAqDA,oCAkBC;AAED,8BAYC;AApFD,2EAIoC;AACpC,uEAIkC;AAIlC,4EAA4E;AAC5E,2EAA2E;AAC3E,2EAA2E;AAC3E,0CAA0C;AAE1C;;;;GAIG;AACU,QAAA,QAAQ,GAGP,wCAAc,IAAI,sCAAY,IAAI,0CAAgB,CAAA;AAEhE;;;;;;GAMG;AACU,QAAA,UAAU,GAGL,4CAAgB,IAAI,0CAAc,IAAI,8CAAkB,CAAA;AAE1E,IAAI,gBAAQ,KAAK,0CAAgB,IAAI,kBAAU,KAAK,8CAAkB,EAAE,CAAC;IACvE,aAAa;IACb,OAAO,CAAC,IAAI,CACV,wJAAwJ,CACzJ,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,IAAI,UAAU,CACnB,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC,iBAAiB,CAChD,CAAA;IACH,CAAC;IAED,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;QACjC,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,SAAgB,SAAS,CAAC,CAAa,EAAE,CAAa;IACpD,IAAI,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU,EAAE,CAAC;QAClC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAClB,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { Base64Alphabet } from './uint8array-base64.js'\nimport {\n fromBase64Native,\n fromBase64Node,\n fromBase64Ponyfill,\n} from './uint8array-from-base64.js'\nimport {\n toBase64Native,\n toBase64Node,\n toBase64Ponyfill,\n} from './uint8array-to-base64.js'\n\nexport type { Base64Alphabet }\n\n// @TODO drop dependency on uint8arrays package once Uint8Array.fromBase64 /\n// Uint8Array.prototype.toBase64 is widely supported, and mark fromBase64 /\n// toBase64 as deprecated. We can also drop NodeJS specific implementations\n// once NodeJS <24 is no longer supported.\n\n/**\n * Encodes a Uint8Array into a base64 string.\n *\n * @returns The base64 encoded string\n */\nexport const toBase64: (\n bytes: Uint8Array,\n alphabet?: Base64Alphabet,\n) => string = toBase64Native ?? toBase64Node ?? toBase64Ponyfill\n\n/**\n * Decodes a base64 string into a Uint8Array. This function supports both padded\n * and unpadded base64 strings.\n *\n * @returns The decoded {@link Uint8Array}\n * @throws If the input is not a valid base64 string\n */\nexport const fromBase64: (\n b64: string,\n alphabet?: Base64Alphabet,\n) => Uint8Array = fromBase64Native ?? fromBase64Node ?? fromBase64Ponyfill\n\nif (toBase64 === toBase64Ponyfill || fromBase64 === fromBase64Ponyfill) {\n /*#__PURE__*/\n console.warn(\n '[@atproto/lex-data]: Uint8Array.fromBase64 / Uint8Array.prototype.toBase64 not available in this environment. Falling back to ponyfill implementation.',\n )\n}\n\n/**\n * Coerces various binary data representations into a Uint8Array.\n *\n * @return `undefined` if the input could not be coerced into a {@link Uint8Array}.\n */\nexport function asUint8Array(input: unknown): Uint8Array | undefined {\n if (input instanceof Uint8Array) {\n return input\n }\n\n if (ArrayBuffer.isView(input)) {\n return new Uint8Array(\n input.buffer,\n input.byteOffset,\n input.byteLength / Uint8Array.BYTES_PER_ELEMENT,\n )\n }\n\n if (input instanceof ArrayBuffer) {\n return new Uint8Array(input)\n }\n\n return undefined\n}\n\nexport function ui8Equals(a: Uint8Array, b: Uint8Array): boolean {\n if (a.byteLength !== b.byteLength) {\n return false\n }\n\n for (let i = 0; i < a.byteLength; i++) {\n if (a[i] !== b[i]) {\n return false\n }\n }\n\n return true\n}\n"]}
1
+ {"version":3,"file":"uint8array.js","sourceRoot":"","sources":["../src/uint8array.ts"],"names":[],"mappings":";;;AA6DA,oCAkBC;AAED,8BAYC;AA5FD,iEAAyE;AACzE,2EAIoC;AACpC,uEAIkC;AAIlC,4EAA4E;AAC5E,2EAA2E;AAC3E,2EAA2E;AAC3E,0CAA0C;AAE1C;;;;GAIG;AACU,QAAA,QAAQ;AAInB,iCAAiC,CAAC,wCAAc;IAChD,iCAAiC,CAAC,sCAAY;IAC9C,iCAAiC,CAAC,0CAAgB,CAAA;AAEpD;;;;;;GAMG;AACU,QAAA,UAAU;AAIrB,iCAAiC,CAAC,4CAAgB;IAClD,iCAAiC,CAAC,0CAAc;IAChD,iCAAiC,CAAC,8CAAkB,CAAA;AAEtD,iCAAiC;AACjC,IAAI,gBAAQ,KAAK,0CAAgB,IAAI,kBAAU,KAAK,8CAAkB,EAAE,CAAC;IACvE,aAAa;IACb,OAAO,CAAC,IAAI,CACV,wJAAwJ,CACzJ,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;QAChC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,IAAI,UAAU,CACnB,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,UAAU,EAChB,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC,iBAAiB,CAChD,CAAA;IACH,CAAC;IAED,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;QACjC,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,SAAgB,SAAS,CAAC,CAAa,EAAE,CAAa;IACpD,IAAI,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU,EAAE,CAAC;QAClC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAClB,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAEY,QAAA,SAAS;AACpB,iCAAiC,CAAC,oCAAa;IAC/C,iCAAiC,CAAC,wCAAiB,CAAA","sourcesContent":["import { Base64Alphabet } from './uint8array-base64.js'\nimport { ui8ConcatNode, ui8ConcatPonyfill } from './uint8array-concat.js'\nimport {\n fromBase64Native,\n fromBase64Node,\n fromBase64Ponyfill,\n} from './uint8array-from-base64.js'\nimport {\n toBase64Native,\n toBase64Node,\n toBase64Ponyfill,\n} from './uint8array-to-base64.js'\n\nexport type { Base64Alphabet }\n\n// @TODO drop dependency on uint8arrays package once Uint8Array.fromBase64 /\n// Uint8Array.prototype.toBase64 is widely supported, and mark fromBase64 /\n// toBase64 as deprecated. We can also drop NodeJS specific implementations\n// once NodeJS <24 is no longer supported.\n\n/**\n * Encodes a Uint8Array into a base64 string.\n *\n * @returns The base64 encoded string\n */\nexport const toBase64: (\n bytes: Uint8Array,\n alphabet?: Base64Alphabet,\n) => string =\n /* v8 ignore next -- @preserve */ toBase64Native ??\n /* v8 ignore next -- @preserve */ toBase64Node ??\n /* v8 ignore next -- @preserve */ toBase64Ponyfill\n\n/**\n * Decodes a base64 string into a Uint8Array. This function supports both padded\n * and unpadded base64 strings.\n *\n * @returns The decoded {@link Uint8Array}\n * @throws If the input is not a valid base64 string\n */\nexport const fromBase64: (\n b64: string,\n alphabet?: Base64Alphabet,\n) => Uint8Array =\n /* v8 ignore next -- @preserve */ fromBase64Native ??\n /* v8 ignore next -- @preserve */ fromBase64Node ??\n /* v8 ignore next -- @preserve */ fromBase64Ponyfill\n\n/* v8 ignore next -- @preserve */\nif (toBase64 === toBase64Ponyfill || fromBase64 === fromBase64Ponyfill) {\n /*#__PURE__*/\n console.warn(\n '[@atproto/lex-data]: Uint8Array.fromBase64 / Uint8Array.prototype.toBase64 not available in this environment. Falling back to ponyfill implementation.',\n )\n}\n\n/**\n * Coerces various binary data representations into a Uint8Array.\n *\n * @return `undefined` if the input could not be coerced into a {@link Uint8Array}.\n */\nexport function asUint8Array(input: unknown): Uint8Array | undefined {\n if (input instanceof Uint8Array) {\n return input\n }\n\n if (ArrayBuffer.isView(input)) {\n return new Uint8Array(\n input.buffer,\n input.byteOffset,\n input.byteLength / Uint8Array.BYTES_PER_ELEMENT,\n )\n }\n\n if (input instanceof ArrayBuffer) {\n return new Uint8Array(input)\n }\n\n return undefined\n}\n\nexport function ui8Equals(a: Uint8Array, b: Uint8Array): boolean {\n if (a.byteLength !== b.byteLength) {\n return false\n }\n\n for (let i = 0; i < a.byteLength; i++) {\n if (a[i] !== b[i]) {\n return false\n }\n }\n\n return true\n}\n\nexport const ui8Concat =\n /* v8 ignore next -- @preserve */ ui8ConcatNode ??\n /* v8 ignore next -- @preserve */ ui8ConcatPonyfill\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utf8-grapheme-len.d.ts","sourceRoot":"","sources":["../src/utf8-grapheme-len.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,iBAAiB,SACM,MAAM,KAAG,MAAM,QAK3C,CAAA;AAER,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD"}
1
+ {"version":3,"file":"utf8-grapheme-len.d.ts","sourceRoot":"","sources":["../src/utf8-grapheme-len.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,iBAAiB,SACM,MAAM,KAAG,MAAM,QAKT,CAAA;AAE1C,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD"}
@@ -8,7 +8,7 @@ const grapheme_1 = require("unicode-segmenter/grapheme");
8
8
  // https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter
9
9
  const segmenter = 'Segmenter' in Intl && typeof Intl.Segmenter === 'function'
10
10
  ? /*#__PURE__*/ new Intl.Segmenter()
11
- : null;
11
+ : /* v8 ignore next -- @preserve */ null;
12
12
  exports.graphemeLenNative = segmenter
13
13
  ? function graphemeLenNative(str) {
14
14
  let length = 0;
@@ -16,7 +16,7 @@ exports.graphemeLenNative = segmenter
16
16
  length++;
17
17
  return length;
18
18
  }
19
- : null;
19
+ : /* v8 ignore next -- @preserve */ null;
20
20
  function graphemeLenPonyfill(str) {
21
21
  return (0, grapheme_1.countGraphemes)(str);
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"utf8-grapheme-len.js","sourceRoot":"","sources":["../src/utf8-grapheme-len.ts"],"names":[],"mappings":";;;AAkBA,kDAEC;AApBD,yDAA2D;AAE3D,0EAA0E;AAC1E,oBAAoB;AACpB,+FAA+F;AAC/F,MAAM,SAAS,GACb,WAAW,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,UAAU;IACzD,CAAC,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,SAAS,EAAE;IACpC,CAAC,CAAC,IAAI,CAAA;AAEG,QAAA,iBAAiB,GAAG,SAAS;IACxC,CAAC,CAAC,SAAS,iBAAiB,CAAC,GAAW;QACpC,IAAI,MAAM,GAAG,CAAC,CAAA;QACd,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC;YAAE,MAAM,EAAE,CAAA;QAChD,OAAO,MAAM,CAAA;IACf,CAAC;IACH,CAAC,CAAC,IAAI,CAAA;AAER,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,OAAO,IAAA,yBAAc,EAAC,GAAG,CAAC,CAAA;AAC5B,CAAC","sourcesContent":["import { countGraphemes } from 'unicode-segmenter/grapheme'\n\n// @TODO: Drop usage of \"unicode-segmenter\" package when Intl.Segmenter is\n// widely supported.\n// https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter\nconst segmenter =\n 'Segmenter' in Intl && typeof Intl.Segmenter === 'function'\n ? /*#__PURE__*/ new Intl.Segmenter()\n : null\n\nexport const graphemeLenNative = segmenter\n ? function graphemeLenNative(str: string): number {\n let length = 0\n for (const _ of segmenter.segment(str)) length++\n return length\n }\n : null\n\nexport function graphemeLenPonyfill(str: string): number {\n return countGraphemes(str)\n}\n"]}
1
+ {"version":3,"file":"utf8-grapheme-len.js","sourceRoot":"","sources":["../src/utf8-grapheme-len.ts"],"names":[],"mappings":";;;AAkBA,kDAEC;AApBD,yDAA2D;AAE3D,0EAA0E;AAC1E,oBAAoB;AACpB,+FAA+F;AAC/F,MAAM,SAAS,GACb,WAAW,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,UAAU;IACzD,CAAC,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,SAAS,EAAE;IACpC,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE/B,QAAA,iBAAiB,GAAG,SAAS;IACxC,CAAC,CAAC,SAAS,iBAAiB,CAAC,GAAW;QACpC,IAAI,MAAM,GAAG,CAAC,CAAA;QACd,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC;YAAE,MAAM,EAAE,CAAA;QAChD,OAAO,MAAM,CAAA;IACf,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,OAAO,IAAA,yBAAc,EAAC,GAAG,CAAC,CAAA;AAC5B,CAAC","sourcesContent":["import { countGraphemes } from 'unicode-segmenter/grapheme'\n\n// @TODO: Drop usage of \"unicode-segmenter\" package when Intl.Segmenter is\n// widely supported.\n// https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter\nconst segmenter =\n 'Segmenter' in Intl && typeof Intl.Segmenter === 'function'\n ? /*#__PURE__*/ new Intl.Segmenter()\n : /* v8 ignore next -- @preserve */ null\n\nexport const graphemeLenNative = segmenter\n ? function graphemeLenNative(str: string): number {\n let length = 0\n for (const _ of segmenter.segment(str)) length++\n return length\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport function graphemeLenPonyfill(str: string): number {\n return countGraphemes(str)\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utf8-len.d.ts","sourceRoot":"","sources":["../src/utf8-len.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,WAAW,YACS,MAAM,KAAG,MAAM,QAGxC,CAAA;AAER,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAsCrD"}
1
+ {"version":3,"file":"utf8-len.d.ts","sourceRoot":"","sources":["../src/utf8-len.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,WAAW,YACS,MAAM,KAAG,MAAM,QAGN,CAAA;AAE1C,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAsCrD"}
package/dist/utf8-len.js CHANGED
@@ -10,7 +10,7 @@ exports.utf8LenNode = nodejs_buffer_js_1.NodeJSBuffer
10
10
  ? function utf8LenNode(string) {
11
11
  return nodejs_buffer_js_1.NodeJSBuffer.byteLength(string, 'utf8');
12
12
  }
13
- : null;
13
+ : /* v8 ignore next -- @preserve */ null;
14
14
  function utf8LenCompute(string) {
15
15
  // The code below is similar to TextEncoder's implementation of UTF-8
16
16
  // encoding. However, using TextEncoder to get the byte length is slower
@@ -1 +1 @@
1
- {"version":3,"file":"utf8-len.js","sourceRoot":"","sources":["../src/utf8-len.ts"],"names":[],"mappings":";;;AAYA,wCAsCC;AAlDD,6DAAqD;AAErD,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAEjE,QAAA,WAAW,GAAG,+BAAY;IACrC,CAAC,CAAC,SAAS,WAAW,CAAC,MAAc;QACjC,OAAO,+BAAa,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACjD,CAAC;IACH,CAAC,CAAC,IAAI,CAAA;AAER,SAAgB,cAAc,CAAC,MAAc;IAC3C,qEAAqE;IACrE,wEAAwE;IACxE,+DAA+D;IAE/D,qDAAqD;IAErD,mDAAmD;IACnD,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAA;IACvB,IAAI,IAAY,CAAA;IAEhB,gEAAgE;IAChE,uBAAuB;IACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1C,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAE3B,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YACjB,gBAAgB;QAClB,CAAC;aAAM,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,eAAe;YACf,GAAG,IAAI,CAAC,CAAA;QACV,CAAC;aAAM,CAAC;YACN,eAAe;YACf,GAAG,IAAI,CAAC,CAAA;YACR,sEAAsE;YACtE,+DAA+D;YAC/D,wEAAwE;YACxE,OAAO;YACP,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;gBACrC,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;gBAC/B,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;oBACrC,CAAC,EAAE,CAAA;gBACL,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import { NodeJSBuffer } from './lib/nodejs-buffer.js'\n\n// @NOTE This file is not meant to be exported directly. Instead, we re-export\n// public functions from ./utf8.ts. The reason for this separation is that this\n// file allows to test both the NodeJS-optimized and ponyfill implementations.\n\nexport const utf8LenNode = NodeJSBuffer\n ? function utf8LenNode(string: string): number {\n return NodeJSBuffer!.byteLength(string, 'utf8')\n }\n : null\n\nexport function utf8LenCompute(string: string): number {\n // The code below is similar to TextEncoder's implementation of UTF-8\n // encoding. However, using TextEncoder to get the byte length is slower\n // as it requires allocating a new Uint8Array and copying data:\n\n // return new TextEncoder().encode(string).byteLength\n\n // The base length is the string length (all ASCII)\n let len = string.length\n let code: number\n\n // The loop calculates the number of additional bytes needed for\n // non-ASCII characters\n for (let i = 0; i < string.length; i += 1) {\n code = string.charCodeAt(i)\n\n if (code <= 0x7f) {\n // ASCII, 1 byte\n } else if (code <= 0x7ff) {\n // 2 bytes char\n len += 1\n } else {\n // 3 bytes char\n len += 2\n // If the current char is a high surrogate, and the next char is a low\n // surrogate, skip the next char as the total is a 4 bytes char\n // (represented as a surrogate pair in UTF-16) and was already accounted\n // for.\n if (code >= 0xd800 && code <= 0xdbff) {\n code = string.charCodeAt(i + 1)\n if (code >= 0xdc00 && code <= 0xdfff) {\n i++\n }\n }\n }\n }\n\n return len\n}\n"]}
1
+ {"version":3,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,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import { NodeJSBuffer } from './lib/nodejs-buffer.js'\n\n// @NOTE This file is not meant to be exported directly. Instead, we re-export\n// public functions from ./utf8.ts. The reason for this separation is that this\n// file allows to test both the NodeJS-optimized and ponyfill implementations.\n\nexport const utf8LenNode = NodeJSBuffer\n ? function utf8LenNode(string: string): number {\n return NodeJSBuffer!.byteLength(string, 'utf8')\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport function utf8LenCompute(string: string): number {\n // The code below is similar to TextEncoder's implementation of UTF-8\n // encoding. However, using TextEncoder to get the byte length is slower\n // as it requires allocating a new Uint8Array and copying data:\n\n // return new TextEncoder().encode(string).byteLength\n\n // The base length is the string length (all ASCII)\n let len = string.length\n let code: number\n\n // The loop calculates the number of additional bytes needed for\n // non-ASCII characters\n for (let i = 0; i < string.length; i += 1) {\n code = string.charCodeAt(i)\n\n if (code <= 0x7f) {\n // ASCII, 1 byte\n } else if (code <= 0x7ff) {\n // 2 bytes char\n len += 1\n } else {\n // 3 bytes char\n len += 2\n // If the current char is a high surrogate, and the next char is a low\n // surrogate, skip the next char as the total is a 4 bytes char\n // (represented as a surrogate pair in UTF-16) and was already accounted\n // for.\n if (code >= 0xd800 && code <= 0xdbff) {\n code = string.charCodeAt(i + 1)\n if (code >= 0xdc00 && code <= 0xdfff) {\n i++\n }\n }\n }\n }\n\n return len\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lex-data",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "description": "Core utilities for AT Lexicons",
6
6
  "keywords": [
@@ -28,10 +28,10 @@
28
28
  "types": "./dist/index.d.ts",
29
29
  "exports": {
30
30
  ".": {
31
+ "types": "./dist/index.d.ts",
31
32
  "browser": "./dist/index.js",
32
33
  "import": "./dist/index.js",
33
- "require": "./dist/index.js",
34
- "types": "./dist/index.d.ts"
34
+ "require": "./dist/index.js"
35
35
  }
36
36
  },
37
37
  "dependencies": {
@@ -43,10 +43,10 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "core-js": "^3",
46
- "jest": "^28.1.2"
46
+ "vitest": "^4.0.16"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsc --build tsconfig.build.json",
50
- "test": "jest"
50
+ "test": "vitest run"
51
51
  }
52
52
  }
package/src/blob.test.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest'
1
2
  import { isBlobRef, isLegacyBlobRef } from './blob.js'
2
3
  import { parseCid } from './cid.js'
3
4
 
@@ -10,7 +11,7 @@ const lexCid = parseCid(
10
11
  'bafyreic52vzks7wdklat4evp3vimohl55i2unzqpshz2ytka5omzr7exdy',
11
12
  )
12
13
 
13
- describe('isBlobRef', () => {
14
+ describe(isBlobRef, () => {
14
15
  it('tests valid blobCid and lexCid', () => {
15
16
  expect(blobCid.code).toBe(0x55) // raw
16
17
  expect(blobCid.multihash.code).toBe(0x12) // sha2-256
@@ -51,6 +52,25 @@ describe('isBlobRef', () => {
51
52
  size: '10000',
52
53
  }),
53
54
  ).toBe(false)
55
+
56
+ expect(
57
+ isBlobRef({
58
+ // $type: 'blob',
59
+ ref: blobCid,
60
+ mimeType: 'image/jpeg',
61
+ size: 10000,
62
+ }),
63
+ ).toBe(false)
64
+
65
+ expect(
66
+ isBlobRef({
67
+ $type: 'blob',
68
+ ref: blobCid,
69
+ mimeType: { toString: () => 'image/jpeg' },
70
+ size: 10000,
71
+ }),
72
+ ).toBe(false)
73
+
54
74
  expect(
55
75
  isBlobRef(
56
76
  {
@@ -81,6 +101,22 @@ describe('isBlobRef', () => {
81
101
  { strict: true },
82
102
  ),
83
103
  ).toBe(false)
104
+
105
+ expect(isBlobRef('not an object')).toBe(false)
106
+ expect(isBlobRef([])).toBe(false)
107
+ expect(isBlobRef(new Date())).toBe(false)
108
+ expect(isBlobRef(new Map())).toBe(false)
109
+ })
110
+
111
+ it('rejects non-integer size', () => {
112
+ expect(
113
+ isBlobRef({
114
+ $type: 'blob',
115
+ ref: blobCid,
116
+ mimeType: 'image/jpeg',
117
+ size: 10000.5,
118
+ }),
119
+ ).toBe(false)
84
120
  })
85
121
 
86
122
  it('rejects invalid CID/multihash code', () => {
@@ -133,9 +169,28 @@ describe('isBlobRef', () => {
133
169
  ),
134
170
  ).toBe(false)
135
171
  })
172
+
173
+ describe('strict mode', () => {
174
+ it('rejects invalid CID version', () => {
175
+ const cidV0 = parseCid(
176
+ 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG', // CID v0
177
+ )
178
+ expect(
179
+ isBlobRef(
180
+ {
181
+ $type: 'blob',
182
+ ref: cidV0,
183
+ mimeType: 'image/jpeg',
184
+ size: 10000,
185
+ },
186
+ { strict: true },
187
+ ),
188
+ ).toBe(false)
189
+ })
190
+ })
136
191
  })
137
192
 
138
- describe('isLegacyBlobRef', () => {
193
+ describe(isLegacyBlobRef, () => {
139
194
  it('parses valid legacy blob', () => {
140
195
  expect(
141
196
  isLegacyBlobRef({
@@ -172,6 +227,32 @@ describe('isLegacyBlobRef', () => {
172
227
  mimeType: 'image/jpeg',
173
228
  }),
174
229
  ).toBe(false)
230
+
231
+ expect(
232
+ isLegacyBlobRef({
233
+ cid: lexCid.toString(),
234
+ mimeType: { toString: () => 'image/jpeg' },
235
+ }),
236
+ ).toBe(false)
237
+
238
+ expect(
239
+ isLegacyBlobRef({
240
+ cid: lexCid.toString(),
241
+ mimeType: 3,
242
+ }),
243
+ ).toBe(false)
244
+
245
+ expect(
246
+ isLegacyBlobRef({
247
+ cid: lexCid.toString(),
248
+ mimeType: '',
249
+ }),
250
+ ).toBe(false)
251
+
252
+ expect(isLegacyBlobRef([])).toBe(false)
253
+ expect(isLegacyBlobRef('not an object')).toBe(false)
254
+ expect(isLegacyBlobRef(new Date())).toBe(false)
255
+ expect(isLegacyBlobRef(new Map())).toBe(false)
175
256
  })
176
257
 
177
258
  it('rejects extra keys', () => {
package/src/blob.ts CHANGED
@@ -35,12 +35,7 @@ export function isBlobRef(
35
35
  return false
36
36
  }
37
37
 
38
- if (
39
- typeof size !== 'number' ||
40
- size < 0 ||
41
- !Number.isInteger(size) ||
42
- !Number.isSafeInteger(size)
43
- ) {
38
+ if (typeof size !== 'number' || size < 0 || !Number.isSafeInteger(size)) {
44
39
  return false
45
40
  }
46
41
 
@@ -97,7 +92,7 @@ export function isLegacyBlobRef(input: unknown): input is LegacyBlobRef {
97
92
  return false
98
93
  }
99
94
 
100
- if (typeof mimeType !== 'string') {
95
+ if (typeof mimeType !== 'string' || mimeType.length === 0) {
101
96
  return false
102
97
  }
103
98