@atproto/lex-data 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/blob.d.ts +28 -2
- package/dist/blob.d.ts.map +1 -1
- package/dist/blob.js +43 -6
- package/dist/blob.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lex-error.d.ts +17 -0
- package/dist/lex-error.d.ts.map +1 -0
- package/dist/lex-error.js +26 -0
- package/dist/lex-error.js.map +1 -0
- package/dist/lib/nodejs-buffer.d.ts +1 -0
- package/dist/lib/nodejs-buffer.d.ts.map +1 -1
- package/dist/lib/nodejs-buffer.js +1 -1
- package/dist/lib/nodejs-buffer.js.map +1 -1
- package/dist/uint8array-concat.d.ts +3 -0
- package/dist/uint8array-concat.d.ts.map +1 -0
- package/dist/uint8array-concat.js +24 -0
- package/dist/uint8array-concat.js.map +1 -0
- package/dist/uint8array-from-base64.d.ts.map +1 -1
- package/dist/uint8array-from-base64.js +2 -2
- package/dist/uint8array-from-base64.js.map +1 -1
- package/dist/uint8array-to-base64.d.ts.map +1 -1
- package/dist/uint8array-to-base64.js +2 -2
- package/dist/uint8array-to-base64.js.map +1 -1
- package/dist/uint8array.d.ts +1 -0
- package/dist/uint8array.d.ts.map +1 -1
- package/dist/uint8array.js +14 -3
- package/dist/uint8array.js.map +1 -1
- package/dist/utf8-from-base64.d.ts +4 -0
- package/dist/utf8-from-base64.d.ts.map +1 -0
- package/dist/utf8-from-base64.js +18 -0
- package/dist/utf8-from-base64.js.map +1 -0
- package/dist/utf8-grapheme-len.d.ts.map +1 -1
- package/dist/utf8-grapheme-len.js +2 -2
- package/dist/utf8-grapheme-len.js.map +1 -1
- package/dist/utf8-len.d.ts.map +1 -1
- package/dist/utf8-len.js +1 -1
- package/dist/utf8-len.js.map +1 -1
- package/dist/utf8-to-base64.d.ts +4 -0
- package/dist/utf8-to-base64.d.ts.map +1 -0
- package/dist/utf8-to-base64.js +20 -0
- package/dist/utf8-to-base64.js.map +1 -0
- package/dist/utf8.d.ts +3 -0
- package/dist/utf8.d.ts.map +1 -1
- package/dist/utf8.js +16 -3
- package/dist/utf8.js.map +1 -1
- package/package.json +5 -5
- package/src/blob.test.ts +223 -20
- package/src/blob.ts +82 -10
- package/src/cid.test.ts +126 -0
- package/src/index.ts +1 -0
- package/src/language.test.ts +1 -0
- package/src/lex-equals.test.ts +30 -0
- package/src/lex-error.ts +34 -0
- package/src/lex.test.ts +65 -13
- package/src/lib/nodejs-buffer.ts +2 -1
- package/src/object.test.ts +2 -0
- package/src/uint8array-concat.test.ts +197 -0
- package/src/uint8array-concat.ts +21 -0
- package/src/uint8array-from-base64.test.ts +4 -1
- package/src/uint8array-from-base64.ts +2 -2
- package/src/uint8array-to-base64.test.ts +3 -3
- package/src/uint8array-to-base64.ts +2 -2
- package/src/uint8array.test.ts +484 -0
- package/src/uint8array.ts +14 -2
- package/src/utf8-from-base64.test.ts +39 -0
- package/src/utf8-from-base64.ts +23 -0
- package/src/utf8-grapheme-len.test.ts +3 -2
- package/src/utf8-grapheme-len.ts +2 -2
- package/src/utf8-len.test.ts +3 -2
- package/src/utf8-len.ts +1 -1
- package/src/utf8-to-base64.test.ts +35 -0
- package/src/utf8-to-base64.ts +22 -0
- package/src/utf8.ts +23 -2
- package/tsconfig.tests.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atproto/lex-data
|
|
2
2
|
|
|
3
|
+
## 0.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4501](https://github.com/bluesky-social/atproto/pull/4501) [`2f78893`](https://github.com/bluesky-social/atproto/commit/2f78893ace3bbf14d4bac36837820ddb46658c98) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `enumBlobRefs` utility function
|
|
8
|
+
|
|
9
|
+
- [#4501](https://github.com/bluesky-social/atproto/pull/4501) [`2f78893`](https://github.com/bluesky-social/atproto/commit/2f78893ace3bbf14d4bac36837820ddb46658c98) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Perform strict `BlobRef` validation by default
|
|
10
|
+
|
|
11
|
+
- [#4501](https://github.com/bluesky-social/atproto/pull/4501) [`2f78893`](https://github.com/bluesky-social/atproto/commit/2f78893ace3bbf14d4bac36837820ddb46658c98) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `base64ToUtf8` and `utf8ToBase64` utilities
|
|
12
|
+
|
|
13
|
+
## 0.0.5
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#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
|
|
18
|
+
|
|
19
|
+
- [#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
|
|
20
|
+
|
|
3
21
|
## 0.0.4
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/blob.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Cid } from './cid.js';
|
|
2
|
+
import { LexValue } from './lex.js';
|
|
2
3
|
/**
|
|
3
4
|
* @note {@link BlobRef} is just a {@link LexMap} with a specific shape.
|
|
4
5
|
*/
|
|
@@ -8,9 +9,17 @@ export type BlobRef = {
|
|
|
8
9
|
ref: Cid;
|
|
9
10
|
size: number;
|
|
10
11
|
};
|
|
11
|
-
export
|
|
12
|
+
export type BlobRefValidationOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* If `false`, skips strict CID validation of {@link BlobRef.ref}, allowing
|
|
15
|
+
* any valid CID. Otherwise, validates that the CID is v1, uses the raw
|
|
16
|
+
* multicodec, and has a sha256 multihash.
|
|
17
|
+
*
|
|
18
|
+
* @defaults to `true`
|
|
19
|
+
*/
|
|
12
20
|
strict?: boolean;
|
|
13
|
-
}
|
|
21
|
+
};
|
|
22
|
+
export declare function isBlobRef(input: unknown, options?: BlobRefValidationOptions): input is BlobRef;
|
|
14
23
|
/**
|
|
15
24
|
* @note {@link LegacyBlobRef} is just a {@link LexMap} with a specific shape.
|
|
16
25
|
*/
|
|
@@ -19,4 +28,21 @@ export type LegacyBlobRef = {
|
|
|
19
28
|
mimeType: string;
|
|
20
29
|
};
|
|
21
30
|
export declare function isLegacyBlobRef(input: unknown): input is LegacyBlobRef;
|
|
31
|
+
export type EnumBlobRefsOptions = BlobRefValidationOptions & {
|
|
32
|
+
/**
|
|
33
|
+
* @defaults to `false`
|
|
34
|
+
*/
|
|
35
|
+
allowLegacy?: boolean;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Enumerates all {@link BlobRef}s (and, optionally, {@link LegacyBlobRef}s)
|
|
39
|
+
* found within a {@link LexValue}.
|
|
40
|
+
*/
|
|
41
|
+
export declare function enumBlobRefs(input: LexValue, options: EnumBlobRefsOptions & {
|
|
42
|
+
allowLegacy: true;
|
|
43
|
+
}): Generator<BlobRef | LegacyBlobRef, void, unknown>;
|
|
44
|
+
export declare function enumBlobRefs(input: LexValue, options?: EnumBlobRefsOptions & {
|
|
45
|
+
allowLegacy?: false;
|
|
46
|
+
}): Generator<BlobRef, void, unknown>;
|
|
47
|
+
export declare function enumBlobRefs(input: LexValue, options?: EnumBlobRefsOptions): Generator<BlobRef | LegacyBlobRef, void, unknown>;
|
|
22
48
|
//# sourceMappingURL=blob.d.ts.map
|
package/dist/blob.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAKJ,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAKJ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAGnC;;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,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,wBAAgB,SAAS,CACvB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,wBAAwB,GACjC,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;AAED,MAAM,MAAM,mBAAmB,GAAG,wBAAwB,GAAG;IAC3D;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,mBAAmB,GAAG;IAAE,WAAW,EAAE,IAAI,CAAA;CAAE,GACnD,SAAS,CAAC,OAAO,GAAG,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;AACpD,wBAAgB,YAAY,CAC1B,KAAK,EAAE,QAAQ,EACf,OAAO,CAAC,EAAE,mBAAmB,GAAG;IAAE,WAAW,CAAC,EAAE,KAAK,CAAA;CAAE,GACtD,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;AACpC,wBAAgB,YAAY,CAC1B,KAAK,EAAE,QAAQ,EACf,OAAO,CAAC,EAAE,mBAAmB,GAC5B,SAAS,CAAC,OAAO,GAAG,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA"}
|
package/dist/blob.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isBlobRef = isBlobRef;
|
|
4
4
|
exports.isLegacyBlobRef = isLegacyBlobRef;
|
|
5
|
+
exports.enumBlobRefs = enumBlobRefs;
|
|
5
6
|
const cid_js_1 = require("./cid.js");
|
|
6
7
|
const object_js_1 = require("./object.js");
|
|
7
8
|
function isBlobRef(input, options) {
|
|
@@ -16,10 +17,7 @@ function isBlobRef(input, options) {
|
|
|
16
17
|
if (typeof mimeType !== 'string' || !mimeType.includes('/')) {
|
|
17
18
|
return false;
|
|
18
19
|
}
|
|
19
|
-
if (typeof size !== 'number' ||
|
|
20
|
-
size < 0 ||
|
|
21
|
-
!Number.isInteger(size) ||
|
|
22
|
-
!Number.isSafeInteger(size)) {
|
|
20
|
+
if (typeof size !== 'number' || size < 0 || !Number.isSafeInteger(size)) {
|
|
23
21
|
return false;
|
|
24
22
|
}
|
|
25
23
|
if (typeof ref !== 'object' || ref === null) {
|
|
@@ -37,7 +35,7 @@ function isBlobRef(input, options) {
|
|
|
37
35
|
if (!cid) {
|
|
38
36
|
return false;
|
|
39
37
|
}
|
|
40
|
-
if (options?.strict) {
|
|
38
|
+
if (options?.strict !== false) {
|
|
41
39
|
if (cid.version !== 1) {
|
|
42
40
|
return false;
|
|
43
41
|
}
|
|
@@ -58,7 +56,7 @@ function isLegacyBlobRef(input) {
|
|
|
58
56
|
if (typeof cid !== 'string') {
|
|
59
57
|
return false;
|
|
60
58
|
}
|
|
61
|
-
if (typeof mimeType !== 'string') {
|
|
59
|
+
if (typeof mimeType !== 'string' || mimeType.length === 0) {
|
|
62
60
|
return false;
|
|
63
61
|
}
|
|
64
62
|
for (const key in input) {
|
|
@@ -74,4 +72,43 @@ function isLegacyBlobRef(input) {
|
|
|
74
72
|
}
|
|
75
73
|
return true;
|
|
76
74
|
}
|
|
75
|
+
function* enumBlobRefs(input, options) {
|
|
76
|
+
const includeLegacy = options?.allowLegacy === true;
|
|
77
|
+
// Using a stack to avoid recursion depth issues.
|
|
78
|
+
const stack = [input];
|
|
79
|
+
// Since we are using a stack, we could end-up in an infinite loop with cyclic
|
|
80
|
+
// structures. Cyclic structures are not valid LexValues and should, thus,
|
|
81
|
+
// never occur, but let's be safe.
|
|
82
|
+
const visited = new Set();
|
|
83
|
+
do {
|
|
84
|
+
const value = stack.pop();
|
|
85
|
+
if (value != null && typeof value === 'object') {
|
|
86
|
+
if (Array.isArray(value)) {
|
|
87
|
+
if (visited.has(value))
|
|
88
|
+
continue;
|
|
89
|
+
visited.add(value);
|
|
90
|
+
stack.push(...value);
|
|
91
|
+
}
|
|
92
|
+
else if ((0, object_js_1.isPlainProto)(value)) {
|
|
93
|
+
if (visited.has(value))
|
|
94
|
+
continue;
|
|
95
|
+
visited.add(value);
|
|
96
|
+
if (isBlobRef(value, options)) {
|
|
97
|
+
yield value;
|
|
98
|
+
}
|
|
99
|
+
else if (includeLegacy && isLegacyBlobRef(value)) {
|
|
100
|
+
yield value;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
for (const v of Object.values(value)) {
|
|
104
|
+
if (v != null)
|
|
105
|
+
stack.push(v);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} while (stack.length > 0);
|
|
111
|
+
// Optimization: ease GC's work
|
|
112
|
+
visited.clear();
|
|
113
|
+
}
|
|
77
114
|
//# sourceMappingURL=blob.js.map
|
package/dist/blob.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.js","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"blob.js","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":";;AA+BA,8BAuDC;AAUD,0CA2BC;AAyBD,oCAwCC;AA5LD,qCAMiB;AAEjB,2CAAyD;AAuBzD,SAAgB,SAAS,CACvB,KAAc,EACd,OAAkC;IAElC,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,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACxE,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;YACf,GAAG,KAAK,UAAU;YAClB,GAAG,KAAK,KAAK;YACb,GAAG,KAAK,MAAM,EACd,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,MAAM,GAAG,GAAG,IAAA,cAAK,EAAC,GAAG,CAAC,CAAA;IACtB,IAAI,CAAC,GAAG,EAAE,CAAC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AO,CAAC,KAAK,EAAE,CAAA;AACjB,CAAC","sourcesContent":["import {\n Cid,\n RAW_BIN_MULTICODEC,\n SHA2_256_MULTIHASH_CODE,\n asCid,\n parseCid,\n} from './cid.js'\nimport { LexValue } from './lex.js'\nimport { isPlainObject, isPlainProto } 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 type BlobRefValidationOptions = {\n /**\n * If `false`, skips strict CID validation of {@link BlobRef.ref}, allowing\n * any valid CID. Otherwise, validates that the CID is v1, uses the raw\n * multicodec, and has a sha256 multihash.\n *\n * @defaults to `true`\n */\n strict?: boolean\n}\n\nexport function isBlobRef(\n input: unknown,\n options?: BlobRefValidationOptions,\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 !== false) {\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\nexport type EnumBlobRefsOptions = BlobRefValidationOptions & {\n /**\n * @defaults to `false`\n */\n allowLegacy?: boolean\n}\n\n/**\n * Enumerates all {@link BlobRef}s (and, optionally, {@link LegacyBlobRef}s)\n * found within a {@link LexValue}.\n */\nexport function enumBlobRefs(\n input: LexValue,\n options: EnumBlobRefsOptions & { allowLegacy: true },\n): Generator<BlobRef | LegacyBlobRef, void, unknown>\nexport function enumBlobRefs(\n input: LexValue,\n options?: EnumBlobRefsOptions & { allowLegacy?: false },\n): Generator<BlobRef, void, unknown>\nexport function enumBlobRefs(\n input: LexValue,\n options?: EnumBlobRefsOptions,\n): Generator<BlobRef | LegacyBlobRef, void, unknown>\nexport function* enumBlobRefs(\n input: LexValue,\n options?: EnumBlobRefsOptions,\n): Generator<BlobRef | LegacyBlobRef, void, unknown> {\n const includeLegacy = options?.allowLegacy === true\n\n // Using a stack to avoid recursion depth issues.\n const stack: LexValue[] = [input]\n\n // Since we are using a stack, we could end-up in an infinite loop with cyclic\n // structures. Cyclic structures are not valid LexValues and should, thus,\n // never occur, but let's be safe.\n const visited = new Set<object>()\n\n do {\n const value = stack.pop()!\n\n if (value != null && typeof value === 'object') {\n if (Array.isArray(value)) {\n if (visited.has(value)) continue\n visited.add(value)\n stack.push(...value)\n } else if (isPlainProto(value)) {\n if (visited.has(value)) continue\n visited.add(value)\n if (isBlobRef(value, options)) {\n yield value\n } else if (includeLegacy && isLegacyBlobRef(value)) {\n yield value\n } else {\n for (const v of Object.values(value)) {\n if (v != null) stack.push(v)\n }\n }\n }\n }\n } while (stack.length > 0)\n\n // Optimization: ease GC's work\n visited.clear()\n}\n"]}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -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,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,YAAY,CAAC,WAAW,CAAC,CAAA;IACnE,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAA;IACtD,SAAS,EAAE,YAAY,CAAA;CACxB;AAMD,eAAO,MAAM,YAAY,EAAE,uBAAuB,GAAG,
|
|
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,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,YAAY,CAAC,WAAW,CAAC,CAAA;IACnE,MAAM,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,YAAY,CAAA;IACvE,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAA;IACtD,SAAS,EAAE,YAAY,CAAA;CACxB;AAMD,eAAO,MAAM,YAAY,EAAE,uBAAuB,GAAG,IAIT,CAAA"}
|
|
@@ -8,5 +8,5 @@ const BUFFER = /*#__PURE__*/ (() => '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":";;;
|
|
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 @@
|
|
|
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,
|
|
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,QAMyB,CAAA;AAE5C,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"}
|
|
@@ -12,7 +12,7 @@ exports.fromBase64Native = typeof Uint8Array.fromBase64 === 'function'
|
|
|
12
12
|
lastChunkHandling: 'loose',
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
-
: null;
|
|
15
|
+
: /* v8 ignore next -- @preserve */ null;
|
|
16
16
|
exports.fromBase64Node = Buffer
|
|
17
17
|
? function fromBase64Node(b64, alphabet = 'base64') {
|
|
18
18
|
const bytes = Buffer.from(b64, alphabet);
|
|
@@ -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;
|
|
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,iCAAiC,CAAC,IAAI,CAAA;AAE/B,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,q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iB,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAA;IAC/D,MAAM,qBAAqB,GAAG,iBAAiB,GAAG,oBAAoB,CAAA;IACtE,IAAI,GAAG,CAAC,MAAM,GAAG,qBAAqB,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;IAC1C,CAAC;IAED,qEAAqE;IACrE,qBAAqB;IACrB,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 : /* v8 ignore next -- @preserve */ 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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array-to-base64.d.ts","sourceRoot":"","sources":["../src/uint8array-to-base64.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAIvD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;WAEG;QACH,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE;YACpB,wBAAwB;YACxB,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAA;YACjC,WAAW,CAAC,EAAE,OAAO,CAAA;SACtB,KAAK,MAAM,CAAA;KACb;CACF;AAED,eAAO,MAAM,cAAc,WAGZ,UAAU,aACP,cAAc,KACvB,MAAM,
|
|
1
|
+
{"version":3,"file":"uint8array-to-base64.d.ts","sourceRoot":"","sources":["../src/uint8array-to-base64.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAIvD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;WAEG;QACH,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE;YACpB,wBAAwB;YACxB,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAA;YACjC,WAAW,CAAC,EAAE,OAAO,CAAA;SACtB,KAAK,MAAM,CAAA;KACb;CACF;AAED,eAAO,MAAM,cAAc,WAGZ,UAAU,aACP,cAAc,KACvB,MAAM,QAG6B,CAAA;AAE5C,eAAO,MAAM,YAAY,WAEZ,UAAU,aACP,cAAc,KACvB,MAAM,QAc6B,CAAA;AAE1C,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,UAAU,EACjB,QAAQ,GAAE,cAAyB,GAClC,MAAM,CAER"}
|
|
@@ -9,7 +9,7 @@ exports.toBase64Native = typeof Uint8Array.prototype.toBase64 === 'function'
|
|
|
9
9
|
? function toBase64Native(bytes, alphabet = 'base64') {
|
|
10
10
|
return bytes.toBase64({ alphabet, omitPadding: true });
|
|
11
11
|
}
|
|
12
|
-
: null;
|
|
12
|
+
: /* v8 ignore next -- @preserve */ null;
|
|
13
13
|
exports.toBase64Node = Buffer
|
|
14
14
|
? function toBase64Node(bytes, alphabet = 'base64') {
|
|
15
15
|
const buffer = bytes instanceof Buffer ? bytes : Buffer.from(bytes);
|
|
@@ -24,7 +24,7 @@ exports.toBase64Node = Buffer
|
|
|
24
24
|
: b64.slice(0, -1) // '='
|
|
25
25
|
: b64;
|
|
26
26
|
}
|
|
27
|
-
: null;
|
|
27
|
+
: /* v8 ignore next -- @preserve */ null;
|
|
28
28
|
function toBase64Ponyfill(bytes, alphabet = 'base64') {
|
|
29
29
|
return (0, to_string_1.toString)(bytes, alphabet);
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array-to-base64.js","sourceRoot":"","sources":["../src/uint8array-to-base64.ts"],"names":[],"mappings":";;;AAiDA,4CAKC;AAtDD,qDAAgD;AAChD,6DAAqD;AAGrD,MAAM,MAAM,GAAG,+BAAY,CAAA;AAed,QAAA,cAAc,GACzB,OAAO,UAAU,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU;IACjD,CAAC,CAAC,SAAS,cAAc,CACrB,KAAiB,EACjB,WAA2B,QAAQ;QAEnC,OAAO,KAAK,CAAC,QAAS,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;IACzD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AC,GAAG,CAAA;IACT,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,SAAgB,gBAAgB,CAC9B,KAAiB,EACjB,WAA2B,QAAQ;IAEnC,OAAO,IAAA,oBAAQ,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAClC,CAAC","sourcesContent":["import { toString } from 'uint8arrays/to-string'\nimport { NodeJSBuffer } from './lib/nodejs-buffer.js'\nimport { Base64Alphabet } from './uint8array-base64.js'\n\nconst Buffer = NodeJSBuffer\n\ndeclare global {\n interface Uint8Array {\n /**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64 Uint8Array.prototype.toBase64()}\n */\n toBase64?: (options?: {\n /** @default 'base64' */\n alphabet?: 'base64' | 'base64url'\n omitPadding?: boolean\n }) => string\n }\n}\n\nexport const toBase64Native =\n typeof Uint8Array.prototype.toBase64 === 'function'\n ? function toBase64Native(\n bytes: Uint8Array,\n alphabet: Base64Alphabet = 'base64',\n ): string {\n return bytes.toBase64!({ alphabet, omitPadding: true })\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport const toBase64Node = Buffer\n ? function toBase64Node(\n bytes: Uint8Array,\n alphabet: Base64Alphabet = 'base64',\n ): string {\n const buffer = bytes instanceof Buffer ? bytes : Buffer.from(bytes)\n const b64 = buffer.toString(alphabet)\n\n // @NOTE We strip padding for strict compatibility with\n // uint8arrays.toString behavior. Tests failing because of the presence of\n // padding are not really synonymous with an actual error and we might\n // (should?) actually want to keep the padding at some point.\n return b64.charCodeAt(b64.length - 1) === /* '=' */ 0x3d\n ? b64.charCodeAt(b64.length - 2) === /* '=' */ 0x3d\n ? b64.slice(0, -2) // '=='\n : b64.slice(0, -1) // '='\n : b64\n }\n : /* v8 ignore next -- @preserve */ null\n\nexport function toBase64Ponyfill(\n bytes: Uint8Array,\n alphabet: Base64Alphabet = 'base64',\n): string {\n return toString(bytes, alphabet)\n}\n"]}
|
package/dist/uint8array.d.ts
CHANGED
|
@@ -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
|
package/dist/uint8array.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array.d.ts","sourceRoot":"","sources":["../src/uint8array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;
|
|
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"}
|
package/dist/uint8array.js
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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
|
package/dist/uint8array.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array.js","sourceRoot":"","sources":["../src/uint8array.ts"],"names":[],"mappings":";;;
|
|
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"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Base64Alphabet } from './uint8array-base64.js';
|
|
2
|
+
export declare const utf8FromBase64Node: ((b64: string, alphabet?: Base64Alphabet) => string) | null;
|
|
3
|
+
export declare function utf8FromBase64Ponyfill(b64: string, alphabet?: Base64Alphabet): string;
|
|
4
|
+
//# sourceMappingURL=utf8-from-base64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utf8-from-base64.d.ts","sourceRoot":"","sources":["../src/utf8-from-base64.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAIvD,eAAO,MAAM,kBAAkB,SAEpB,MAAM,aACD,cAAc,KACvB,MAAM,QAG6B,CAAA;AAG1C,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,cAAc,GACxB,MAAM,CAGR"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.utf8FromBase64Node = void 0;
|
|
4
|
+
exports.utf8FromBase64Ponyfill = utf8FromBase64Ponyfill;
|
|
5
|
+
const from_string_1 = require("uint8arrays/from-string");
|
|
6
|
+
const nodejs_buffer_js_1 = require("./lib/nodejs-buffer.js");
|
|
7
|
+
const Buffer = nodejs_buffer_js_1.NodeJSBuffer;
|
|
8
|
+
exports.utf8FromBase64Node = Buffer
|
|
9
|
+
? function utf8FromBase64Node(b64, alphabet = 'base64') {
|
|
10
|
+
return Buffer.from(b64, alphabet).toString('utf8');
|
|
11
|
+
}
|
|
12
|
+
: /* v8 ignore next -- @preserve */ null;
|
|
13
|
+
const textDecoder = /*#__PURE__*/ new TextDecoder();
|
|
14
|
+
function utf8FromBase64Ponyfill(b64, alphabet) {
|
|
15
|
+
const bytes = (0, from_string_1.fromString)(b64, alphabet);
|
|
16
|
+
return textDecoder.decode(bytes);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=utf8-from-base64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utf8-from-base64.js","sourceRoot":"","sources":["../src/utf8-from-base64.ts"],"names":[],"mappings":";;;AAgBA,wDAMC;AAtBD,yDAAoD;AACpD,6DAAqD;AAGrD,MAAM,MAAM,GAAG,+BAAY,CAAA;AAEd,QAAA,kBAAkB,GAAG,MAAM;IACtC,CAAC,CAAC,SAAS,kBAAkB,CACzB,GAAW,EACX,WAA2B,QAAQ;QAEnC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACpD,CAAC;IACH,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAA;AAE1C,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,WAAW,EAAE,CAAA;AACnD,SAAgB,sBAAsB,CACpC,GAAW,EACX,QAAyB;IAEzB,MAAM,KAAK,GAAG,IAAA,wBAAU,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;IACvC,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAClC,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\nexport const utf8FromBase64Node = Buffer\n ? function utf8FromBase64Node(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n ): string {\n return Buffer.from(b64, alphabet).toString('utf8')\n }\n : /* v8 ignore next -- @preserve */ null\n\nconst textDecoder = /*#__PURE__*/ new TextDecoder()\nexport function utf8FromBase64Ponyfill(\n b64: string,\n alphabet?: Base64Alphabet,\n): string {\n const bytes = fromString(b64, alphabet)\n return textDecoder.decode(bytes)\n}\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,
|
|
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;
|
|
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"]}
|