@atproto/lex-json 0.0.14 → 0.0.16
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 +15 -0
- package/dist/blob.d.ts +4 -4
- package/dist/blob.d.ts.map +1 -1
- package/dist/blob.js +6 -6
- package/dist/blob.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 +600 -0
- package/dist/json-bytes-decoder.js.map +1 -0
- package/dist/lex-json.d.ts +9 -1
- package/dist/lex-json.d.ts.map +1 -1
- package/dist/lex-json.js +25 -24
- package/dist/lex-json.js.map +1 -1
- package/package.json +2 -2
- package/src/blob.ts +8 -8
- 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 +535 -69
- package/src/lex-json.ts +29 -23
- package/tsconfig.build.json +1 -1
- package/tsconfig.tests.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atproto/lex-json
|
|
2
2
|
|
|
3
|
+
## 0.0.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
9
|
+
## 0.0.15
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#4835](https://github.com/bluesky-social/atproto/pull/4835) [`f6f100c`](https://github.com/bluesky-social/atproto/commit/f6f100c33700a7ff58a1458109cc7420131feed0) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `lexParseJsonBytes` utility to parse a byte array containing a json string directly into lex data
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`c62651d`](https://github.com/bluesky-social/atproto/commit/c62651dd69f1e18bd854b66e499b91fee9eaa856), [`f6f100c`](https://github.com/bluesky-social/atproto/commit/f6f100c33700a7ff58a1458109cc7420131feed0), [`c62651d`](https://github.com/bluesky-social/atproto/commit/c62651dd69f1e18bd854b66e499b91fee9eaa856), [`c62651d`](https://github.com/bluesky-social/atproto/commit/c62651dd69f1e18bd854b66e499b91fee9eaa856)]:
|
|
16
|
+
- @atproto/lex-data@0.0.15
|
|
17
|
+
|
|
3
18
|
## 0.0.14
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/blob.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlobRefCheckOptions, LexMap, TypedBlobRef } from '@atproto/lex-data';
|
|
2
2
|
/**
|
|
3
3
|
* Parses a blob reference from a JSON object.
|
|
4
4
|
*
|
|
@@ -19,7 +19,7 @@ import { BlobRef, BlobRefCheckOptions, LexMap } from '@atproto/lex-data';
|
|
|
19
19
|
* @example
|
|
20
20
|
* ```typescript
|
|
21
21
|
* // Parse a blob reference from JSON
|
|
22
|
-
* const blobRef =
|
|
22
|
+
* const blobRef = parseTypedBlobRef({
|
|
23
23
|
* $type: 'blob',
|
|
24
24
|
* ref: { $link: 'bafyreib2rxk3rybloqtqwbo' },
|
|
25
25
|
* mimeType: 'image/png',
|
|
@@ -29,9 +29,9 @@ import { BlobRef, BlobRefCheckOptions, LexMap } from '@atproto/lex-data';
|
|
|
29
29
|
* // blobRef.ref is a Cid instance
|
|
30
30
|
*
|
|
31
31
|
* // Returns undefined for non-blob objects
|
|
32
|
-
* const result =
|
|
32
|
+
* const result = parseTypedBlobRef({ foo: 'bar' })
|
|
33
33
|
* // result is undefined
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export declare function
|
|
36
|
+
export declare function parseTypedBlobRef(input: LexMap, options?: BlobRefCheckOptions): TypedBlobRef | undefined;
|
|
37
37
|
//# 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,
|
|
1
|
+
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,MAAM,EACN,YAAY,EAEb,MAAM,mBAAmB,CAAA;AAG1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,mBAAmB,GAC5B,YAAY,GAAG,SAAS,CAwB1B"}
|
package/dist/blob.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.parseTypedBlobRef = parseTypedBlobRef;
|
|
4
4
|
const lex_data_1 = require("@atproto/lex-data");
|
|
5
5
|
const link_js_1 = require("./link.js");
|
|
6
6
|
/**
|
|
@@ -23,7 +23,7 @@ const link_js_1 = require("./link.js");
|
|
|
23
23
|
* @example
|
|
24
24
|
* ```typescript
|
|
25
25
|
* // Parse a blob reference from JSON
|
|
26
|
-
* const blobRef =
|
|
26
|
+
* const blobRef = parseTypedBlobRef({
|
|
27
27
|
* $type: 'blob',
|
|
28
28
|
* ref: { $link: 'bafyreib2rxk3rybloqtqwbo' },
|
|
29
29
|
* mimeType: 'image/png',
|
|
@@ -33,11 +33,11 @@ const link_js_1 = require("./link.js");
|
|
|
33
33
|
* // blobRef.ref is a Cid instance
|
|
34
34
|
*
|
|
35
35
|
* // Returns undefined for non-blob objects
|
|
36
|
-
* const result =
|
|
36
|
+
* const result = parseTypedBlobRef({ foo: 'bar' })
|
|
37
37
|
* // result is undefined
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
function
|
|
40
|
+
function parseTypedBlobRef(input, options) {
|
|
41
41
|
if (input.$type !== 'blob')
|
|
42
42
|
return undefined;
|
|
43
43
|
const ref = input?.ref;
|
|
@@ -52,10 +52,10 @@ function parseBlobRef(input, options) {
|
|
|
52
52
|
if (!cid)
|
|
53
53
|
return undefined;
|
|
54
54
|
const blob = { ...input, ref: cid };
|
|
55
|
-
if ((0, lex_data_1.
|
|
55
|
+
if ((0, lex_data_1.isTypedBlobRef)(blob, options))
|
|
56
56
|
return blob;
|
|
57
57
|
}
|
|
58
|
-
if ((0, lex_data_1.
|
|
58
|
+
if ((0, lex_data_1.isTypedBlobRef)(input)) {
|
|
59
59
|
return input;
|
|
60
60
|
}
|
|
61
61
|
return undefined;
|
package/dist/blob.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.js","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":";;AA0CA,
|
|
1
|
+
{"version":3,"file":"blob.js","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":";;AA0CA,8CA2BC;AArED,gDAK0B;AAC1B,uCAAwC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,SAAgB,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,IAAA,sBAAY,EAAC,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,IAAA,yBAAc,EAAC,IAAI,EAAE,OAAO,CAAC;YAAE,OAAO,IAAI,CAAA;IAChD,CAAC;IAED,IAAI,IAAA,yBAAc,EAAC,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"]}
|
|
@@ -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"}
|