@atproto/lex-data 0.0.3 → 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.
- package/CHANGELOG.md +22 -0
- package/dist/blob.d.ts +6 -0
- package/dist/blob.d.ts.map +1 -1
- package/dist/blob.js +2 -2
- package/dist/blob.js.map +1 -1
- package/dist/cid.d.ts +2 -3
- package/dist/cid.d.ts.map +1 -1
- package/dist/cid.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/language.d.ts +2 -2
- package/dist/language.d.ts.map +1 -1
- package/dist/language.js +4 -4
- package/dist/language.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/lex.d.ts.map +1 -1
- package/dist/lex.js +49 -48
- package/dist/lex.js.map +1 -1
- 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/object.d.ts +13 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +15 -2
- package/dist/object.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 +1 -1
- package/dist/uint8array-from-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-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/package.json +5 -5
- package/src/blob.test.ts +83 -2
- package/src/blob.ts +8 -2
- package/src/cid.test.ts +126 -0
- package/src/cid.ts +7 -7
- package/src/index.ts +1 -0
- package/src/language.test.ts +34 -33
- package/src/language.ts +2 -2
- package/src/lex-equals.test.ts +30 -0
- package/src/lex-error.ts +34 -0
- package/src/lex.test.ts +156 -1
- package/src/lex.ts +50 -43
- package/src/lib/nodejs-buffer.ts +2 -1
- package/src/object.test.ts +2 -0
- package/src/object.ts +16 -4
- 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 +1 -1
- package/src/uint8array-to-base64.test.ts +1 -1
- package/src/uint8array.test.ts +484 -0
- package/src/uint8array.ts +14 -2
- package/src/utf8-grapheme-len.test.ts +1 -0
- package/src/utf8-grapheme-len.ts +2 -2
- package/src/utf8-len.test.ts +1 -0
- package/src/utf8-len.ts +1 -1
- package/tsconfig.tests.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
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
|
+
|
|
11
|
+
## 0.0.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Use stack based approach in `isLexValue` allowing to be called with very deep structures;
|
|
16
|
+
|
|
17
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Do not throw an error from `isLexScalar` (return `false` instead)
|
|
18
|
+
|
|
19
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Forbid use of unsafe integers
|
|
20
|
+
|
|
21
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Expose `isPlainProto` utility to check if an object is a plain object.
|
|
22
|
+
|
|
23
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rename `parseLanguage` and `isLanguage` exports to `parseLanguageString` and `isLanguageString` respectively
|
|
24
|
+
|
|
3
25
|
## 0.0.3
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/blob.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Cid } from './cid.js';
|
|
2
|
+
/**
|
|
3
|
+
* @note {@link BlobRef} is just a {@link LexMap} with a specific shape.
|
|
4
|
+
*/
|
|
2
5
|
export type BlobRef = {
|
|
3
6
|
$type: 'blob';
|
|
4
7
|
mimeType: string;
|
|
@@ -8,6 +11,9 @@ export type BlobRef = {
|
|
|
8
11
|
export declare function isBlobRef(input: unknown, options?: {
|
|
9
12
|
strict?: boolean;
|
|
10
13
|
}): input is BlobRef;
|
|
14
|
+
/**
|
|
15
|
+
* @note {@link LegacyBlobRef} is just a {@link LexMap} with a specific shape.
|
|
16
|
+
*/
|
|
11
17
|
export type LegacyBlobRef = {
|
|
12
18
|
cid: string;
|
|
13
19
|
mimeType: string;
|
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;AAGjB,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,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,7 +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' || size < 0 || !Number.
|
|
19
|
+
if (typeof size !== 'number' || size < 0 || !Number.isSafeInteger(size)) {
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
22
22
|
if (typeof ref !== 'object' || ref === null) {
|
|
@@ -55,7 +55,7 @@ function isLegacyBlobRef(input) {
|
|
|
55
55
|
if (typeof cid !== 'string') {
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
|
-
if (typeof mimeType !== 'string') {
|
|
58
|
+
if (typeof mimeType !== 'string' || mimeType.length === 0) {
|
|
59
59
|
return false;
|
|
60
60
|
}
|
|
61
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":";;
|
|
1
|
+
{"version":3,"file":"blob.js","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":";;AAmBA,8BAuDC;AAUD,0CA2BC;AA/GD,qCAMiB;AACjB,2CAA2C;AAY3C,SAAgB,SAAS,CACv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A;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/cid.d.ts
CHANGED
|
@@ -18,15 +18,14 @@ declare module 'multiformats/cid' {
|
|
|
18
18
|
* `multiformats/cid` in dependent packages, and instead have them rely on the
|
|
19
19
|
* {@link Cid} interface from `@atproto/lex-data`. The {@link CID} class from
|
|
20
20
|
* `multiformats` version <10 has compatibility issues with certain TypeScript
|
|
21
|
-
*
|
|
22
|
-
* packages.
|
|
21
|
+
* configuration, which can lead to type errors in dependent packages.
|
|
23
22
|
*
|
|
24
23
|
* We are stuck with version 9 because `@atproto` packages did not drop
|
|
25
24
|
* CommonJS support yet, and multiformats version 10 only supports ES modules.
|
|
26
25
|
*
|
|
27
26
|
* In order to avoid compatibility issues, while preparing for future breaking
|
|
28
27
|
* changes (CID in multiformats v10+ has a slightly different interface), as
|
|
29
|
-
* we update or swap out `multiformats`, we provide our own stable
|
|
28
|
+
* we update or swap out `multiformats`, we provide our own stable {@link Cid}
|
|
30
29
|
* interface.
|
|
31
30
|
*/
|
|
32
31
|
interface CID {
|
package/dist/cid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["../src/cid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAEtC,eAAO,MAAM,mBAAmB,MAAO,CAAA;AACvC,eAAO,MAAM,kBAAkB,KAAO,CAAA;AAEtC,eAAO,MAAM,uBAAuB,KAAO,CAAA;AAE3C,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,IAAI;IAC1D,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,UAAU,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,UAAU,CAAA;CAClB,CAAA;AAED,OAAO,QAAQ,kBAAkB,CAAC;IAChC
|
|
1
|
+
{"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["../src/cid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAEtC,eAAO,MAAM,mBAAmB,MAAO,CAAA;AACvC,eAAO,MAAM,kBAAkB,KAAO,CAAA;AAEtC,eAAO,MAAM,uBAAuB,KAAO,CAAA;AAE3C,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,IAAI;IAC1D,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,UAAU,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,UAAU,CAAA;CAClB,CAAA;AAED,OAAO,QAAQ,kBAAkB,CAAC;IAChC;;;;;;;;;;;;;;;;;;OAkBG;IACH,UAAU,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AAC,KAAa;IAC1C,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED,SAAgB,oBAAoB,CAAC,KAAa;IAChD,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;IACvC,CAAC;AACH,CAAC","sourcesContent":["import { CID } from 'multiformats/cid'\n\nexport const DAG_CBOR_MULTICODEC = 0x71\nexport const RAW_BIN_MULTICODEC = 0x55\n\nexport const SHA2_256_MULTIHASH_CODE = 0x12\n\nexport type MultihashDigest<Code extends number = number> = {\n code: Code\n digest: Uint8Array\n size: number\n bytes: Uint8Array\n}\n\ndeclare module 'multiformats/cid' {\n /**\n * @deprecated use the {@link Cid} interface from `@atproto/lex-data`, and\n * related helpers ({@link asCid}, {@link parseCid}, {@link decodeCid},\n * {@link createCid}, {@link isCid}), instead.\n *\n * This is marked as deprecated because we want to discourage direct usage of\n * `multiformats/cid` in dependent packages, and instead have them rely on the\n * {@link Cid} interface from `@atproto/lex-data`. The {@link CID} class from\n * `multiformats` version <10 has compatibility issues with certain TypeScript\n *
|
|
1
|
+
{"version":3,"file":"cid.js","sourceRoot":"","sources":["../src/cid.ts"],"names":[],"mappings":";;;AAuEA,sBAEC;AAED,4BAEC;AAED,8BAEC;AAED,8BAEC;AAED,sBAsBC;AAED,8CAEC;AAED,wCAMC;AAED,oDAIC;AA/HD,0CAAsC;AAwD7B,oFAxDA,SAAG,OAwDA;AAtDC,QAAA,mBAAmB,GAAG,IAAI,CAAA;AAC1B,QAAA,kBAAkB,GAAG,IAAI,CAAA;AAEzB,QAAA,uBAAuB,GAAG,IAAI,CAAA;AAkE3C,SAAgB,KAAK,CAAC,KAAc;IAClC,OAAO,SAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AACzB,CAA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iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;IACvC,CAAC;AACH,CAAC","sourcesContent":["import { CID } from 'multiformats/cid'\n\nexport const DAG_CBOR_MULTICODEC = 0x71\nexport const RAW_BIN_MULTICODEC = 0x55\n\nexport const SHA2_256_MULTIHASH_CODE = 0x12\n\nexport type MultihashDigest<Code extends number = number> = {\n code: Code\n digest: Uint8Array\n size: number\n bytes: Uint8Array\n}\n\ndeclare module 'multiformats/cid' {\n /**\n * @deprecated use the {@link Cid} interface from `@atproto/lex-data`, and\n * related helpers ({@link asCid}, {@link parseCid}, {@link decodeCid},\n * {@link createCid}, {@link isCid}), instead.\n *\n * This is marked as deprecated because we want to discourage direct usage of\n * `multiformats/cid` in dependent packages, and instead have them rely on the\n * {@link Cid} interface from `@atproto/lex-data`. The {@link CID} class from\n * `multiformats` version <10 has compatibility issues with certain TypeScript\n * configuration, which can lead to type errors in dependent packages.\n *\n * We are stuck with version 9 because `@atproto` packages did not drop\n * CommonJS support yet, and multiformats version 10 only supports ES modules.\n *\n * In order to avoid compatibility issues, while preparing for future breaking\n * changes (CID in multiformats v10+ has a slightly different interface), as\n * we update or swap out `multiformats`, we provide our own stable {@link Cid}\n * interface.\n */\n interface CID {}\n}\n\n// multiformats' CID class is not very portable because:\n//\n// - In dependent packages that use \"moduleResolution\" set to \"node16\",\n// \"nodenext\" or \"bundler\", TypeScript fails to properly resolve the\n// multiformats package when importing CID from @atproto/lex-data. This causes\n// type errors in those packages. This is caused by the fact that the\n// multiformats version <10 (which is the last version that supports CommonJS)\n// uses \"exports\" field in package.json, which do not contain \"types\"\n// entrypoints.\n// https://www.npmjs.com/package/multiformats/v/9.9.0?activeTab=code\n// - By defining our own interface and helper functions, we can have more\n// control over the public API exposed by this package.\n// - It allow us to have a stable interface in case we need to swap out, or\n// eventually update multiformats (should we choose to drop CommonJS support)\n// in the future.\n\n// @NOTE Even though it is not portable, we still re-export CID here so that\n// dependent packages where it can be used, have access to it (instead of\n// importing directly from \"multiformats\" or\"multiformats/cid\").\nexport { CID }\n\n/**\n * Interface for working with decoded CID string, compatible with\n * {@link CID} implementation.\n */\nexport interface Cid {\n version: 0 | 1\n code: number\n multihash: MultihashDigest\n bytes: Uint8Array\n equals(other: unknown): boolean\n toString(): string\n}\n\nexport function asCid(value: unknown): Cid | null {\n return CID.asCID(value)\n}\n\nexport function parseCid(input: string): Cid {\n return CID.parse(input)\n}\n\nexport function decodeCid(bytes: Uint8Array): Cid {\n return CID.decode(bytes)\n}\n\nexport function createCid(code: number, digest: MultihashDigest): Cid {\n return CID.createV1(code, digest)\n}\n\nexport function isCid(\n value: unknown,\n options?: { strict?: boolean },\n): value is Cid {\n const cid = asCid(value)\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 && cid.code !== DAG_CBOR_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\nexport function validateCidString(input: string): boolean {\n return parseCidString(input)?.toString() === input\n}\n\nexport function parseCidString(input: string): Cid | undefined {\n try {\n return parseCid(input)\n } catch {\n return undefined\n }\n}\n\nexport function ensureValidCidString(input: string): void {\n if (!validateCidString(input)) {\n throw new Error(`Invalid CID string`)\n }\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"]}
|
package/dist/language.d.ts
CHANGED
|
@@ -8,11 +8,11 @@ export type LanguageTag = {
|
|
|
8
8
|
extension?: string;
|
|
9
9
|
privateUse?: string;
|
|
10
10
|
};
|
|
11
|
-
export declare function
|
|
11
|
+
export declare function parseLanguageString(input: string): LanguageTag | null;
|
|
12
12
|
/**
|
|
13
13
|
* Validates well-formed BCP 47 syntax
|
|
14
14
|
*
|
|
15
15
|
* @see {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.1}
|
|
16
16
|
*/
|
|
17
|
-
export declare function
|
|
17
|
+
export declare function isLanguageString(input: string): boolean;
|
|
18
18
|
//# sourceMappingURL=language.d.ts.map
|
package/dist/language.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language.d.ts","sourceRoot":"","sources":["../src/language.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,WAAW,GAAG;IACxB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,wBAAgB,
|
|
1
|
+
{"version":3,"file":"language.d.ts","sourceRoot":"","sources":["../src/language.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,WAAW,GAAG;IACxB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAerE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD"}
|
package/dist/language.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.parseLanguageString = parseLanguageString;
|
|
4
|
+
exports.isLanguageString = isLanguageString;
|
|
5
5
|
const BCP47_REGEXP = /^((?<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?<language>([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?<script>[A-Za-z]{4}))?(-(?<region>[A-Za-z]{2}|[0-9]{3}))?(-(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?<extension>[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?<privateUseA>x(-[A-Za-z0-9]{1,8})+))?)|(?<privateUseB>x(-[A-Za-z0-9]{1,8})+))$/;
|
|
6
|
-
function
|
|
6
|
+
function parseLanguageString(input) {
|
|
7
7
|
const parsed = input.match(BCP47_REGEXP);
|
|
8
8
|
if (!parsed?.groups)
|
|
9
9
|
return null;
|
|
@@ -24,7 +24,7 @@ function parseLanguage(input) {
|
|
|
24
24
|
*
|
|
25
25
|
* @see {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.1}
|
|
26
26
|
*/
|
|
27
|
-
function
|
|
27
|
+
function isLanguageString(input) {
|
|
28
28
|
return BCP47_REGEXP.test(input);
|
|
29
29
|
}
|
|
30
30
|
//# sourceMappingURL=language.js.map
|
package/dist/language.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language.js","sourceRoot":"","sources":["../src/language.ts"],"names":[],"mappings":";;AAcA,
|
|
1
|
+
{"version":3,"file":"language.js","sourceRoot":"","sources":["../src/language.ts"],"names":[],"mappings":";;AAcA,kDAeC;AAOD,4CAEC;AAtCD,MAAM,YAAY,GAChB,mlBAAmlB,CAAA;AAarlB,SAAgB,mBAAmB,CAAC,KAAa;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;IACxC,IAAI,CAAC,MAAM,EAAE,MAAM;QAAE,OAAO,IAAI,CAAA;IAEhC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IACzB,OAAO;QACL,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,UAAU,EAAE,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW;KACrD,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACjC,CAAC","sourcesContent":["const BCP47_REGEXP =\n /^((?<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?<language>([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?<script>[A-Za-z]{4}))?(-(?<region>[A-Za-z]{2}|[0-9]{3}))?(-(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?<extension>[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?<privateUseA>x(-[A-Za-z0-9]{1,8})+))?)|(?<privateUseB>x(-[A-Za-z0-9]{1,8})+))$/\n\nexport type LanguageTag = {\n grandfathered?: string\n language?: string\n extlang?: string\n script?: string\n region?: string\n variant?: string\n extension?: string\n privateUse?: string\n}\n\nexport function parseLanguageString(input: string): LanguageTag | null {\n const parsed = input.match(BCP47_REGEXP)\n if (!parsed?.groups) return null\n\n const { groups } = parsed\n return {\n grandfathered: groups.grandfathered,\n language: groups.language,\n extlang: groups.extlang,\n script: groups.script,\n region: groups.region,\n variant: groups.variant,\n extension: groups.extension,\n privateUse: groups.privateUseA || groups.privateUseB,\n }\n}\n\n/**\n * Validates well-formed BCP 47 syntax\n *\n * @see {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.1}\n */\nexport function isLanguageString(input: string): boolean {\n return BCP47_REGEXP.test(input)\n}\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"]}
|
package/dist/lex.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lex.d.ts","sourceRoot":"","sources":["../src/lex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAS,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"lex.d.ts","sourceRoot":"","sources":["../src/lex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAS,MAAM,UAAU,CAAA;AAGrC,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,GAAG,GAAG,UAAU,CAAA;AAC3E,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,QAAQ,EAAE,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,QAAQ;CAAE,CAAA;AAC5E,MAAM,MAAM,MAAM,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,QAAQ;CAAE,CAAA;AACjD,MAAM,MAAM,QAAQ,GAAG,QAAQ,EAAE,CAAA;AAEjC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE5D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAa9D;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CA8C5D;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AACpD,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,IAAI,WAAW,CAInE"}
|
package/dist/lex.js
CHANGED
|
@@ -8,74 +8,75 @@ exports.isTypedLexMap = isTypedLexMap;
|
|
|
8
8
|
const cid_js_1 = require("./cid.js");
|
|
9
9
|
const object_js_1 = require("./object.js");
|
|
10
10
|
function isLexMap(value) {
|
|
11
|
-
|
|
12
|
-
return false;
|
|
13
|
-
for (const key in value) {
|
|
14
|
-
if (!isLexValue(value[key]))
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
11
|
+
return (0, object_js_1.isPlainObject)(value) && Object.values(value).every(isLexValue);
|
|
18
12
|
}
|
|
19
13
|
function isLexArray(value) {
|
|
20
|
-
|
|
21
|
-
return false;
|
|
22
|
-
for (let i = 0; i < value.length; i++) {
|
|
23
|
-
if (!isLexValue(value[i]))
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
14
|
+
return Array.isArray(value) && value.every(isLexValue);
|
|
27
15
|
}
|
|
28
16
|
function isLexScalar(value) {
|
|
29
17
|
switch (typeof value) {
|
|
30
18
|
case 'object':
|
|
31
|
-
|
|
32
|
-
return true;
|
|
33
|
-
return value instanceof Uint8Array || (0, cid_js_1.isCid)(value);
|
|
19
|
+
return value === null || value instanceof Uint8Array || (0, cid_js_1.isCid)(value);
|
|
34
20
|
case 'string':
|
|
35
21
|
case 'boolean':
|
|
36
22
|
return true;
|
|
37
23
|
case 'number':
|
|
38
24
|
if (Number.isInteger(value))
|
|
39
25
|
return true;
|
|
40
|
-
|
|
26
|
+
// fallthrough
|
|
41
27
|
default:
|
|
42
|
-
|
|
28
|
+
return false;
|
|
43
29
|
}
|
|
44
30
|
}
|
|
45
31
|
function isLexValue(value) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
// Using a stack to avoid recursion depth issues.
|
|
33
|
+
const stack = [value];
|
|
34
|
+
// Cyclic structures are not valid LexValues as they cannot be serialized to
|
|
35
|
+
// JSON or CBOR. This also allows us to avoid infinite loops when traversing
|
|
36
|
+
// the structure.
|
|
37
|
+
const visited = new Set();
|
|
38
|
+
do {
|
|
39
|
+
const value = stack.pop();
|
|
40
|
+
// Optimization: we are not using `isLexScalar` here to avoid extra function
|
|
41
|
+
// calls, and to avoid computing `typeof value` multiple times.
|
|
42
|
+
switch (typeof value) {
|
|
43
|
+
case 'object':
|
|
44
|
+
if (value === null) {
|
|
45
|
+
// LexScalar
|
|
46
|
+
}
|
|
47
|
+
else if ((0, object_js_1.isPlainProto)(value)) {
|
|
48
|
+
if (visited.has(value))
|
|
60
49
|
return false;
|
|
50
|
+
visited.add(value);
|
|
51
|
+
stack.push(...Object.values(value));
|
|
61
52
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if ((0, object_js_1.isPlainObject)(value)) {
|
|
65
|
-
for (const key in value) {
|
|
66
|
-
if (!isLexValue(value[key]))
|
|
53
|
+
else if (Array.isArray(value)) {
|
|
54
|
+
if (visited.has(value))
|
|
67
55
|
return false;
|
|
56
|
+
visited.add(value);
|
|
57
|
+
stack.push(...value);
|
|
68
58
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
59
|
+
else if (value instanceof Uint8Array || (0, cid_js_1.isCid)(value)) {
|
|
60
|
+
// LexScalar
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case 'string':
|
|
67
|
+
case 'boolean':
|
|
68
|
+
break;
|
|
69
|
+
case 'number':
|
|
70
|
+
if (Number.isInteger(value))
|
|
71
|
+
break;
|
|
72
|
+
// fallthrough
|
|
73
|
+
default:
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
} while (stack.length > 0);
|
|
77
|
+
// Optimization: ease GC's work
|
|
78
|
+
visited.clear();
|
|
79
|
+
return true;
|
|
79
80
|
}
|
|
80
81
|
function isTypedLexMap(value) {
|
|
81
82
|
return (isLexMap(value) && typeof value.$type === 'string' && value.$type.length > 0);
|
package/dist/lex.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lex.js","sourceRoot":"","sources":["../src/lex.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"lex.js","sourceRoot":"","sources":["../src/lex.ts"],"names":[],"mappings":";;AAQA,4BAEC;AAED,gCAEC;AAED,kCAaC;AAED,gCA8CC;AAGD,sCAIC;AApFD,qCAAqC;AACrC,2CAAyD;AAOzD,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,IAAA,yBAAa,EAAC,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;AACvE,CAAC;AAED,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;AACxD,CAAC;AAED,SAAgB,WAAW,CAAC,KAAc;IACxC,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,YAAY,UAAU,IAAI,IAAA,cAAK,EAAC,KAAK,CAAC,CAAA;QACtE,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACZ,OAAO,IAAI,CAAA;QACb,KAAK,QAAQ;YACX,IAAI,MAAM,CA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YACP,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS;gBACZ,MAAK;YACP,KAAK,QAAQ;gBACX,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;oBAAE,MAAK;YACpC,cAAc;YACd;gBACE,OAAO,KAAK,CAAA;QAChB,CAAC;IACH,CAAC,QAAQ,KAAK,CAAC,MAAM,GAAG,CAAC,EAAC;IAE1B,+BAA+B;IAC/B,OAAO,CAAC,KAAK,EAAE,CAAA;IAEf,OAAO,IAAI,CAAA;AACb,CAAC;AAGD,SAAgB,aAAa,CAAC,KAAe;IAC3C,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAC7E,CAAA;AACH,CAAC","sourcesContent":["import { Cid, isCid } from './cid.js'\nimport { isPlainObject, isPlainProto } from './object.js'\n\nexport type LexScalar = number | string | boolean | null | Cid | Uint8Array\nexport type LexValue = LexScalar | LexValue[] | { [_ in string]?: LexValue }\nexport type LexMap = { [_ in string]?: LexValue }\nexport type LexArray = LexValue[]\n\nexport function isLexMap(value: unknown): value is LexMap {\n return isPlainObject(value) && Object.values(value).every(isLexValue)\n}\n\nexport function isLexArray(value: unknown): value is LexArray {\n return Array.isArray(value) && value.every(isLexValue)\n}\n\nexport function isLexScalar(value: unknown): value is LexScalar {\n switch (typeof value) {\n case 'object':\n return value === null || value instanceof Uint8Array || isCid(value)\n case 'string':\n case 'boolean':\n return true\n case 'number':\n if (Number.isInteger(value)) return true\n // fallthrough\n default:\n return false\n }\n}\n\nexport function isLexValue(value: unknown): value is LexValue {\n // Using a stack to avoid recursion depth issues.\n const stack: unknown[] = [value]\n // Cyclic structures are not valid LexValues as they cannot be serialized to\n // JSON or CBOR. This also allows us to avoid infinite loops when traversing\n // the structure.\n const visited = new Set<object>()\n\n do {\n const value = stack.pop()!\n\n // Optimization: we are not using `isLexScalar` here to avoid extra function\n // calls, and to avoid computing `typeof value` multiple times.\n switch (typeof value) {\n case 'object':\n if (value === null) {\n // LexScalar\n } else if (isPlainProto(value)) {\n if (visited.has(value)) return false\n visited.add(value)\n stack.push(...Object.values(value))\n } else if (Array.isArray(value)) {\n if (visited.has(value)) return false\n visited.add(value)\n stack.push(...value)\n } else if (value instanceof Uint8Array || isCid(value)) {\n // LexScalar\n } else {\n return false\n }\n break\n case 'string':\n case 'boolean':\n break\n case 'number':\n if (Number.isInteger(value)) break\n // fallthrough\n default:\n return false\n }\n } while (stack.length > 0)\n\n // Optimization: ease GC's work\n visited.clear()\n\n return true\n}\n\nexport type TypedLexMap = LexMap & { $type: string }\nexport function isTypedLexMap(value: LexValue): value is TypedLexMap {\n return (\n isLexMap(value) && typeof value.$type === 'string' && value.$type.length > 0\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,CAA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,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"]}
|
package/dist/object.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the input is an object (not null).
|
|
3
|
+
*/
|
|
1
4
|
export declare function isObject(input: unknown): input is object;
|
|
2
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether the input is an object (not null) whose prototype is either
|
|
7
|
+
* null or `Object.prototype`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isPlainObject(input: unknown): input is Record<string, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Checks whether the prototype of the input object is either null or
|
|
12
|
+
* `Object.prototype`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isPlainProto(input: object): input is Record<string, unknown>;
|
|
3
15
|
//# sourceMappingURL=object.d.ts.map
|
package/dist/object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAKD,wBAAgB,aAAa,
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAKD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,oCAE3C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAU5E"}
|
package/dist/object.js
CHANGED
|
@@ -2,14 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isObject = isObject;
|
|
4
4
|
exports.isPlainObject = isPlainObject;
|
|
5
|
+
exports.isPlainProto = isPlainProto;
|
|
6
|
+
/**
|
|
7
|
+
* Checks whether the input is an object (not null).
|
|
8
|
+
*/
|
|
5
9
|
function isObject(input) {
|
|
6
10
|
return input != null && typeof input === 'object';
|
|
7
11
|
}
|
|
8
12
|
const ObjectProto = Object.prototype;
|
|
9
13
|
const ObjectToString = Object.prototype.toString;
|
|
14
|
+
/**
|
|
15
|
+
* Checks whether the input is an object (not null) whose prototype is either
|
|
16
|
+
* null or `Object.prototype`.
|
|
17
|
+
*/
|
|
10
18
|
function isPlainObject(input) {
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
return isObject(input) && isPlainProto(input);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checks whether the prototype of the input object is either null or
|
|
23
|
+
* `Object.prototype`.
|
|
24
|
+
*/
|
|
25
|
+
function isPlainProto(input) {
|
|
13
26
|
const proto = Object.getPrototypeOf(input);
|
|
14
27
|
if (proto === null)
|
|
15
28
|
return true;
|
package/dist/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":";;AAGA,4BAEC;AASD,sCAEC;AAMD,oCAUC;AAhCD;;GAEG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAA;AACnD,CAAC;AAED,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAA;AACpC,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAA;AAEhD;;;GAGG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,CAAA;AAC/C,CAAC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAa;IACxC,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IAC1C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC/B,OAAO,CACL,CAAC,KAAK,KAAK,WAAW;QACpB,sEAAsE;QACtE,6BAA6B;QAC7B,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;QACxC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CACjD,CAAA;AACH,CAAC","sourcesContent":["/**\n * Checks whether the input is an object (not null).\n */\nexport function isObject(input: unknown): input is object {\n return input != null && typeof input === 'object'\n}\n\nconst ObjectProto = Object.prototype\nconst ObjectToString = Object.prototype.toString\n\n/**\n * Checks whether the input is an object (not null) whose prototype is either\n * null or `Object.prototype`.\n */\nexport function isPlainObject(input: unknown) {\n return isObject(input) && isPlainProto(input)\n}\n\n/**\n * Checks whether the prototype of the input object is either null or\n * `Object.prototype`.\n */\nexport function isPlainProto(input: object): input is Record<string, unknown> {\n const proto = Object.getPrototypeOf(input)\n if (proto === null) return true\n return (\n (proto === ObjectProto ||\n // Needed to support NodeJS's `runInNewContext` which produces objects\n // with a different prototype\n Object.getPrototypeOf(proto) === null) &&\n ObjectToString.call(input) === '[object Object]'\n )\n}\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
|