@atproto/lex-json 0.0.15 → 0.1.0-next.0
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 +25 -0
- package/dist/blob.js +6 -9
- package/dist/blob.js.map +1 -1
- package/dist/bytes.js +5 -9
- package/dist/bytes.js.map +1 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/dist/json-bytes-decoder.d.ts +24 -0
- package/dist/json-bytes-decoder.d.ts.map +1 -0
- package/dist/json-bytes-decoder.js +581 -0
- package/dist/json-bytes-decoder.js.map +1 -0
- package/dist/json.js +1 -2
- package/dist/lex-json.d.ts +7 -3
- package/dist/lex-json.d.ts.map +1 -1
- package/dist/lex-json.js +40 -61
- package/dist/lex-json.js.map +1 -1
- package/dist/link.js +5 -9
- package/dist/link.js.map +1 -1
- package/package.json +6 -7
- package/src/json-bytes-decoder.bench.ts +252 -0
- package/src/json-bytes-decoder.test.ts +889 -0
- package/src/json-bytes-decoder.ts +672 -0
- package/src/lex-json.bench.ts +125 -0
- package/src/lex-json.test.ts +368 -0
- package/src/lex-json.ts +19 -33
- package/src/link.ts +1 -1
- package/tsconfig.build.json +1 -1
- package/tsconfig.tests.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @atproto/lex-json
|
|
2
2
|
|
|
3
|
+
## 0.1.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#4929](https://github.com/bluesky-social/atproto/pull/4929) [`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Drop support for Node.js 18 and 20. Node.js 22 is now the minimum supported version. Docker images now use Node.js 24.
|
|
8
|
+
|
|
9
|
+
- [#4943](https://github.com/bluesky-social/atproto/pull/4943) [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028) Thanks [@devinivy](https://github.com/devinivy)! - **BREAKING:** Convert to pure ESM. All packages now ship `"type": "module"` with ES module output and Node16 module resolution.
|
|
10
|
+
|
|
11
|
+
Node.js 22's `require()` compatibility layer can still load these packages in CommonJS code.
|
|
12
|
+
|
|
13
|
+
- [#4930](https://github.com/bluesky-social/atproto/pull/4930) [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9) Thanks [@devinivy](https://github.com/devinivy)! - Build with TypeScript 6.0. Emitted `.d.ts` files now use TypeScript 6's stricter `Uint8Array<ArrayBuffer>` typing in places where Web/Node APIs require buffer-backed (not shared-memory) byte arrays. Consumers compiling against these types on older TypeScript should see no runtime impact, but may need to widen or cast in spots that previously relied on `Uint8Array` defaulting to `<ArrayBufferLike>`.
|
|
14
|
+
|
|
15
|
+
Internal: tsconfig `moduleResolution: "node"` is silenced via `ignoreDeprecations: "6.0"` for now; the proper migration to `node16`/`bundler` resolution is deferred.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`bb7491c`](https://github.com/bluesky-social/atproto/commit/bb7491c29e06181e1d2f8cf6eb454f9bb8ab961b), [`07ae5d4`](https://github.com/bluesky-social/atproto/commit/07ae5d4452df51e045e0239da7a04cf0bc154028), [`042df15`](https://github.com/bluesky-social/atproto/commit/042df15087c0e62cd1e715fcbf58852fab875af9)]:
|
|
20
|
+
- @atproto/lex-data@0.1.0-next.0
|
|
21
|
+
|
|
22
|
+
## 0.0.16
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- [#4836](https://github.com/bluesky-social/atproto/pull/4836) [`952354c`](https://github.com/bluesky-social/atproto/commit/952354c1dd458251f8b643d02f4b227d40c5df17) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Improve performances of `lexParseJsonBytes` function
|
|
27
|
+
|
|
3
28
|
## 0.0.15
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/dist/blob.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.parseTypedBlobRef = parseTypedBlobRef;
|
|
4
|
-
const lex_data_1 = require("@atproto/lex-data");
|
|
5
|
-
const link_js_1 = require("./link.js");
|
|
1
|
+
import { isTypedBlobRef, } from '@atproto/lex-data';
|
|
2
|
+
import { parseLexLink } from './link.js';
|
|
6
3
|
/**
|
|
7
4
|
* Parses a blob reference from a JSON object.
|
|
8
5
|
*
|
|
@@ -37,7 +34,7 @@ const link_js_1 = require("./link.js");
|
|
|
37
34
|
* // result is undefined
|
|
38
35
|
* ```
|
|
39
36
|
*/
|
|
40
|
-
function parseTypedBlobRef(input, options) {
|
|
37
|
+
export function parseTypedBlobRef(input, options) {
|
|
41
38
|
if (input.$type !== 'blob')
|
|
42
39
|
return undefined;
|
|
43
40
|
const ref = input?.ref;
|
|
@@ -48,14 +45,14 @@ function parseTypedBlobRef(input, options) {
|
|
|
48
45
|
// jsonToLex), the `ref` property may either be a LexMap with a $link
|
|
49
46
|
// property, or it may already be a CID instance.
|
|
50
47
|
if ('$link' in ref) {
|
|
51
|
-
const cid =
|
|
48
|
+
const cid = parseLexLink(ref);
|
|
52
49
|
if (!cid)
|
|
53
50
|
return undefined;
|
|
54
51
|
const blob = { ...input, ref: cid };
|
|
55
|
-
if (
|
|
52
|
+
if (isTypedBlobRef(blob, options))
|
|
56
53
|
return blob;
|
|
57
54
|
}
|
|
58
|
-
if (
|
|
55
|
+
if (isTypedBlobRef(input)) {
|
|
59
56
|
return input;
|
|
60
57
|
}
|
|
61
58
|
return undefined;
|
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":"AAAA,OAAO,EAIL,cAAc,GACf,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAa,EACb,OAA6B;IAE7B,IAAI,KAAK,CAAC,KAAK,KAAK,MAAM;QAAE,OAAO,SAAS,CAAA;IAE5C,MAAM,GAAG,GAAG,KAAK,EAAE,GAAG,CAAA;IACtB,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAA;IAErD,8EAA8E;IAC9E,oEAAoE;IACpE,qEAAqE;IACrE,iDAAiD;IAEjD,IAAI,OAAO,IAAI,GAAG,EAAE,CAAC;QACnB,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,CAAC,GAAG;YAAE,OAAO,SAAS,CAAA;QAE1B,MAAM,IAAI,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;QACnC,IAAI,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC;YAAE,OAAO,IAAI,CAAA;IAChD,CAAC;IAED,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["import {\n BlobRefCheckOptions,\n LexMap,\n TypedBlobRef,\n isTypedBlobRef,\n} from '@atproto/lex-data'\nimport { parseLexLink } from './link.js'\n\n/**\n * Parses a blob reference from a JSON object.\n *\n * In the AT Protocol, blobs are referenced using a specific object structure\n * with `$type: 'blob'`, a `ref` property containing a CID link, and metadata\n * like `mimeType` and `size`. This function validates and parses such objects\n * into `BlobRef` instances.\n *\n * The function handles both cases where the `ref` property is:\n * - A `{$link: string}` object (when parsing from JSON)\n * - Already a `Cid` instance (when the parent object has been partially converted)\n *\n * @param input - A Lex map potentially representing a blob reference\n * @param options - Optional blob reference validation options\n * @returns The parsed `BlobRef` if the input is a valid blob reference,\n * or `undefined` if the input is not a valid blob representation\n *\n * @example\n * ```typescript\n * // Parse a blob reference from JSON\n * const blobRef = parseTypedBlobRef({\n * $type: 'blob',\n * ref: { $link: 'bafyreib2rxk3rybloqtqwbo' },\n * mimeType: 'image/png',\n * size: 12345\n * })\n *\n * // blobRef.ref is a Cid instance\n *\n * // Returns undefined for non-blob objects\n * const result = parseTypedBlobRef({ foo: 'bar' })\n * // result is undefined\n * ```\n */\nexport function parseTypedBlobRef(\n input: LexMap,\n options?: BlobRefCheckOptions,\n): TypedBlobRef | undefined {\n if (input.$type !== 'blob') return undefined\n\n const ref = input?.ref\n if (!ref || typeof ref !== 'object') return undefined\n\n // @NOTE Because json to lex conversion can be performed both in a depth-first\n // manner (e.g. via lexParse) or in a breadth-first manner (e.g. via\n // jsonToLex), the `ref` property may either be a LexMap with a $link\n // property, or it may already be a CID instance.\n\n if ('$link' in ref) {\n const cid = parseLexLink(ref)\n if (!cid) return undefined\n\n const blob = { ...input, ref: cid }\n if (isTypedBlobRef(blob, options)) return blob\n }\n\n if (isTypedBlobRef(input)) {\n return input\n }\n\n return undefined\n}\n"]}
|
package/dist/bytes.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseLexBytes = parseLexBytes;
|
|
4
|
-
exports.encodeLexBytes = encodeLexBytes;
|
|
5
|
-
const lex_data_1 = require("@atproto/lex-data");
|
|
1
|
+
import { fromBase64, toBase64 } from '@atproto/lex-data';
|
|
6
2
|
/**
|
|
7
3
|
* Parses a `{$bytes: string}` JSON object into a `Uint8Array`.
|
|
8
4
|
*
|
|
@@ -29,7 +25,7 @@ const lex_data_1 = require("@atproto/lex-data");
|
|
|
29
25
|
* // invalid is undefined
|
|
30
26
|
* ```
|
|
31
27
|
*/
|
|
32
|
-
function parseLexBytes(input) {
|
|
28
|
+
export function parseLexBytes(input) {
|
|
33
29
|
if (!input || !('$bytes' in input)) {
|
|
34
30
|
return undefined;
|
|
35
31
|
}
|
|
@@ -42,7 +38,7 @@ function parseLexBytes(input) {
|
|
|
42
38
|
return undefined;
|
|
43
39
|
}
|
|
44
40
|
try {
|
|
45
|
-
return
|
|
41
|
+
return fromBase64(input.$bytes);
|
|
46
42
|
}
|
|
47
43
|
catch {
|
|
48
44
|
return undefined;
|
|
@@ -65,7 +61,7 @@ function parseLexBytes(input) {
|
|
|
65
61
|
* // encoded is { $bytes: 'SGVsbG8sIHdvcmxkIQ==' }
|
|
66
62
|
* ```
|
|
67
63
|
*/
|
|
68
|
-
function encodeLexBytes(bytes) {
|
|
69
|
-
return { $bytes:
|
|
64
|
+
export function encodeLexBytes(bytes) {
|
|
65
|
+
return { $bytes: toBase64(bytes) };
|
|
70
66
|
}
|
|
71
67
|
//# sourceMappingURL=bytes.js.map
|
package/dist/bytes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../src/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAGxD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAC3B,KAA+B;IAE/B,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,IAAI,KAAK,CAAC,EAAE,CAAC;QACnC,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YACrB,OAAO,SAAS,CAAA;QAClB,CAAC;IACH,CAAC;IAED,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,IAAI,CAAC;QACH,OAAO,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,cAAc,CAAC,KAAiB;IAC9C,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAA;AACpC,CAAC","sourcesContent":["import { fromBase64, toBase64 } from '@atproto/lex-data'\nimport { JsonValue } from './json.js'\n\n/**\n * Parses a `{$bytes: string}` JSON object into a `Uint8Array`.\n *\n * In the AT Protocol data model, binary data is represented in JSON as an object\n * with a single `$bytes` property containing a base64-encoded string. This function\n * decodes that representation back into raw bytes.\n *\n * @param input - An object potentially containing a `$bytes` property\n * @returns The decoded `Uint8Array` if the input is a valid `$bytes` object,\n * or `undefined` if the input is not a valid `$bytes` representation\n *\n * @example\n * ```typescript\n * // Parse a $bytes object to Uint8Array\n * const bytes = parseLexBytes({ $bytes: 'SGVsbG8sIHdvcmxkIQ==' })\n * // bytes is Uint8Array containing \"Hello, world!\"\n *\n * // Returns undefined for non-$bytes objects\n * const result = parseLexBytes({ foo: 'bar' })\n * // result is undefined\n *\n * // Returns undefined for objects with extra properties\n * const invalid = parseLexBytes({ $bytes: 'SGVsbG8=', extra: true })\n * // invalid is undefined\n * ```\n */\nexport function parseLexBytes(\n input?: Record<string, unknown>,\n): Uint8Array | undefined {\n if (!input || !('$bytes' in input)) {\n return undefined\n }\n\n for (const key in input) {\n if (key !== '$bytes') {\n return undefined\n }\n }\n\n if (typeof input.$bytes !== 'string') {\n return undefined\n }\n\n try {\n return fromBase64(input.$bytes)\n } catch {\n return undefined\n }\n}\n\n/**\n * Encodes a `Uint8Array` into a `{$bytes: string}` JSON representation.\n *\n * In the AT Protocol data model, binary data is represented in JSON as an object\n * with a single `$bytes` property containing a base64-encoded string. This function\n * performs that encoding.\n *\n * @param bytes - The binary data to encode\n * @returns An object with a `$bytes` property containing the base64-encoded data\n *\n * @example\n * ```typescript\n * const bytes = new TextEncoder().encode('Hello, world!')\n * const encoded = encodeLexBytes(bytes)\n * // encoded is { $bytes: 'SGVsbG8sIHdvcmxkIQ==' }\n * ```\n */\nexport function encodeLexBytes(bytes: Uint8Array): JsonValue {\n return { $bytes: toBase64(bytes) }\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
tslib_1.__exportStar(require("./json.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./lex-json.js"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./link.js"), exports);
|
|
1
|
+
export * from './bytes.js';
|
|
2
|
+
export * from './json.js';
|
|
3
|
+
export * from './lex-json.js';
|
|
4
|
+
export * from './link.js';
|
|
8
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA","sourcesContent":["export * from './bytes.js'\nexport * from './json.js'\nexport * from './lex-json.js'\nexport * from './link.js'\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LexValue } from '@atproto/lex-data';
|
|
2
|
+
export declare const BASE64_NATIVE_THRESHOLD = 256;
|
|
3
|
+
export declare class JsonBytesDecoder {
|
|
4
|
+
private readonly data;
|
|
5
|
+
private readonly strict;
|
|
6
|
+
private pos;
|
|
7
|
+
constructor(data: Uint8Array, strict?: boolean);
|
|
8
|
+
decode(): LexValue;
|
|
9
|
+
private parseValue;
|
|
10
|
+
private parseObject;
|
|
11
|
+
private parseArray;
|
|
12
|
+
private parseString;
|
|
13
|
+
private parseEscapeSequence;
|
|
14
|
+
private parseUnicodeEscape;
|
|
15
|
+
private hexValue;
|
|
16
|
+
private base64Value;
|
|
17
|
+
private decodeUnescapedString;
|
|
18
|
+
private parseNumber;
|
|
19
|
+
private parseTrue;
|
|
20
|
+
private parseFalse;
|
|
21
|
+
private parseNull;
|
|
22
|
+
private skipWhitespace;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=json-bytes-decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-bytes-decoder.d.ts","sourceRoot":"","sources":["../src/json-bytes-decoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAwB,MAAM,mBAAmB,CAAA;AAkElE,eAAO,MAAM,uBAAuB,MAAM,CAAA;AAE1C,qBAAa,gBAAgB;IAIzB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,GAAG,CAAI;gBAGI,IAAI,EAAE,UAAU,EAChB,MAAM,UAAO;IAGhC,MAAM,IAAI,QAAQ;IAYlB,OAAO,CAAC,UAAU;IAuBlB,OAAO,CAAC,WAAW;IA4LnB,OAAO,CAAC,UAAU;IA+BlB,OAAO,CAAC,WAAW;IA+DnB,OAAO,CAAC,mBAAmB;IA2B3B,OAAO,CAAC,kBAAkB;IAwC1B,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,qBAAqB;IAkC7B,OAAO,CAAC,WAAW;IAsGnB,OAAO,CAAC,SAAS;IAcjB,OAAO,CAAC,UAAU;IAelB,OAAO,CAAC,SAAS;IAcjB,OAAO,CAAC,cAAc;CAkBvB"}
|