@atproto/lex-document 0.1.2 → 0.1.3
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 +11 -0
- package/dist/lexicon-indexer.d.ts +1 -1
- package/dist/lexicon-indexer.d.ts.map +1 -1
- package/dist/lexicon-indexer.js.map +1 -1
- package/dist/lexicon-iterable-indexer.d.ts +2 -3
- package/dist/lexicon-iterable-indexer.d.ts.map +1 -1
- package/dist/lexicon-iterable-indexer.js +0 -1
- package/dist/lexicon-iterable-indexer.js.map +1 -1
- package/dist/lexicon-schema-builder.d.ts +3 -3
- package/dist/lexicon-schema-builder.d.ts.map +1 -1
- package/dist/lexicon-schema-builder.js.map +1 -1
- package/package.json +6 -10
- package/src/core-js.d.ts +0 -2
- package/src/index.ts +0 -7
- package/src/lexicon-document.test.ts +0 -113
- package/src/lexicon-document.ts +0 -754
- package/src/lexicon-indexer.ts +0 -60
- package/src/lexicon-iterable-indexer.ts +0 -132
- package/src/lexicon-schema-builder.test.ts +0 -297
- package/src/lexicon-schema-builder.ts +0 -501
- package/tsconfig.build.json +0 -12
- package/tsconfig.json +0 -7
- package/tsconfig.tests.json +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @atproto/lex-document
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update TypeScript build to rely on references to composite internal projects
|
|
8
|
+
|
|
9
|
+
- [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Bundle only necessary files in the NPM tarball, including the `CHANGELOG.md` and `README.md` files (if present).
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07)]:
|
|
12
|
+
- @atproto/lex-schema@0.1.6
|
|
13
|
+
|
|
3
14
|
## 0.1.2
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-indexer.d.ts","sourceRoot":"","sources":["../src/lexicon-indexer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"lexicon-indexer.d.ts","sourceRoot":"","sources":["../src/lexicon-indexer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IAE3C;;;;;;;OAOG;IACH,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAE3C;;;;;;;;;;;;;OAaG;IACH,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,MAAM,aAAa,CAAC,eAAe,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;CAC7E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-indexer.js","sourceRoot":"","sources":["../src/lexicon-indexer.ts"],"names":[],"mappings":"","sourcesContent":["import { LexiconDocument } from './lexicon-document.js'\n\n/**\n * Interface for indexing and retrieving Lexicon documents by their NSID.\n *\n * @example\n * ```ts\n * // Using a custom indexer implementation\n * const networkIndexer: LexiconIndexer = {\n * async get(nsid: string) {\n * const doc = await resolveLexicon(nsid)\n * return doc\n * }\n * }\n *\n * const validator = await LexiconSchemaBuilder.build(networkIndexer, 'com.example.post#main')\n * ```\n */\nexport interface LexiconIndexer {\n /**\n * Retrieves a Lexicon document by its NSID.\n *\n * @param nsid - The Namespaced Identifier of the Lexicon document to retrieve\n * @returns A promise that resolves to the Lexicon document\n * @throws When the document with the given NSID cannot be found\n *\n * @example\n * ```ts\n * const doc = await indexer.get('com.atproto.repo.createRecord')\n * console.log(doc.defs.main?.type) // 'procedure'\n * ```\n */\n get(nsid: string): Promise<LexiconDocument>\n\n /**\n * Optional async disposal method for cleanup.\n *\n * When implemented, allows the indexer to be used with `await using`\n * syntax for automatic resource cleanup.\n *\n * @returns A promise that resolves when disposal is complete\n */\n [Symbol.asyncDispose]?: () => Promise<void>\n\n /**\n * Optional async iterator for iterating over all available Lexicon documents.\n *\n * @returns An async iterator yielding Lexicon documents\n *\n * @example\n * ```ts\n * if (Symbol.asyncIterator in indexer) {\n * for await (const doc of indexer) {\n * console.log(doc.id)\n * }\n * }\n * ```\n */\n [Symbol.asyncIterator]?: () => AsyncIterator<LexiconDocument, void, unknown>\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lexicon-indexer.js","sourceRoot":"","sources":["../src/lexicon-indexer.ts"],"names":[],"mappings":"","sourcesContent":["import type { LexiconDocument } from './lexicon-document.js'\n\n/**\n * Interface for indexing and retrieving Lexicon documents by their NSID.\n *\n * @example\n * ```ts\n * // Using a custom indexer implementation\n * const networkIndexer: LexiconIndexer = {\n * async get(nsid: string) {\n * const doc = await resolveLexicon(nsid)\n * return doc\n * }\n * }\n *\n * const validator = await LexiconSchemaBuilder.build(networkIndexer, 'com.example.post#main')\n * ```\n */\nexport interface LexiconIndexer {\n /**\n * Retrieves a Lexicon document by its NSID.\n *\n * @param nsid - The Namespaced Identifier of the Lexicon document to retrieve\n * @returns A promise that resolves to the Lexicon document\n * @throws When the document with the given NSID cannot be found\n *\n * @example\n * ```ts\n * const doc = await indexer.get('com.atproto.repo.createRecord')\n * console.log(doc.defs.main?.type) // 'procedure'\n * ```\n */\n get(nsid: string): Promise<LexiconDocument>\n\n /**\n * Optional async disposal method for cleanup.\n *\n * When implemented, allows the indexer to be used with `await using`\n * syntax for automatic resource cleanup.\n *\n * @returns A promise that resolves when disposal is complete\n */\n [Symbol.asyncDispose]?: () => Promise<void>\n\n /**\n * Optional async iterator for iterating over all available Lexicon documents.\n *\n * @returns An async iterator yielding Lexicon documents\n *\n * @example\n * ```ts\n * if (Symbol.asyncIterator in indexer) {\n * for await (const doc of indexer) {\n * console.log(doc.id)\n * }\n * }\n * ```\n */\n [Symbol.asyncIterator]?: () => AsyncIterator<LexiconDocument, void, unknown>\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LexiconDocument } from './lexicon-document.js';
|
|
2
|
-
import { LexiconIndexer } from './lexicon-indexer.js';
|
|
1
|
+
import type { LexiconDocument } from './lexicon-document.js';
|
|
2
|
+
import type { LexiconIndexer } from './lexicon-indexer.js';
|
|
3
3
|
/**
|
|
4
4
|
* Lazily indexes Lexicon documents from an iterable source.
|
|
5
5
|
*
|
|
@@ -32,7 +32,6 @@ import { LexiconIndexer } from './lexicon-indexer.js';
|
|
|
32
32
|
*/
|
|
33
33
|
export declare class LexiconIterableIndexer implements LexiconIndexer, AsyncDisposable {
|
|
34
34
|
#private;
|
|
35
|
-
readonly source: AsyncIterable<LexiconDocument> | Iterable<LexiconDocument>;
|
|
36
35
|
/**
|
|
37
36
|
* Creates a new {@link LexiconIterableIndexer} from an iterable source.
|
|
38
37
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-iterable-indexer.d.ts","sourceRoot":"","sources":["../src/lexicon-iterable-indexer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"lexicon-iterable-indexer.d.ts","sourceRoot":"","sources":["../src/lexicon-iterable-indexer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,sBAAuB,YAAW,cAAc,EAAE,eAAe;;IAM5E;;;;;;;;;;;;;;OAcG;IACH,YACE,MAAM,EAAE,aAAa,CAAC,eAAe,CAAC,GAAG,QAAQ,CAAC,eAAe,CAAC,EAMnE;IAED;;;;;;;OAOG;IACG,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAW9C;IAEM,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAC5C,eAAe,EACf,IAAI,EACJ,SAAS,CACV,CAsCA;IAEK,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3C;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-iterable-indexer.js","sourceRoot":"","sources":["../src/lexicon-iterable-indexer.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,sBAAsB;IACxB,SAAS,GAAiC,IAAI,GAAG,EAAE,CAAA;IACnD,SAAS,CAE0B;IAE5C;;;;;;;;;;;;;;OAcG;IACH,
|
|
1
|
+
{"version":3,"file":"lexicon-iterable-indexer.js","sourceRoot":"","sources":["../src/lexicon-iterable-indexer.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,sBAAsB;IACxB,SAAS,GAAiC,IAAI,GAAG,EAAE,CAAA;IACnD,S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GAAG,IAAI,KAAK,CAAC,kCAAkC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAA;gBACnE,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAA;gBACjC,MAAM,GAAG,CAAA,CAAC,0DAA0D;YACtE,CAAC;YAED,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;YACnC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YACtB,MAAM,KAAK,CAAA;QACb,CAAC,QAAQ,IAAI,EAAC;QAEd,0EAA0E;QAC1E,yEAAyE;QACzE,4EAA4E;QAC5E,2EAA2E;QAC3E,4EAA4E;QAC5E,uEAAuE;QACvE,2CAA2C;QAE3C,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC1B,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;gBACpB,MAAM,GAAG,CAAA;YACX,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAA;IACjC,CAAC;CACF","sourcesContent":["import type { LexiconDocument } from './lexicon-document.js'\nimport type { LexiconIndexer } from './lexicon-indexer.js'\n\n/**\n * Lazily indexes Lexicon documents from an iterable source.\n *\n * This class implements `LexiconIndexer` by consuming documents from an\n * iterable (sync or async) and caching them for efficient retrieval.\n * Documents are indexed on-demand as they are requested or iterated over.\n *\n * @example\n * ```ts\n * // From an array of documents\n * const docs = [lexiconDoc1, lexiconDoc2, lexiconDoc3]\n * const indexer = new LexiconIterableIndexer(docs)\n *\n * // Documents are indexed lazily as requested\n * const doc = await indexer.get('com.example.post')\n * ```\n *\n * @example\n * ```ts\n * // From an async generator (e.g., reading from files)\n * async function* loadLexicons() {\n * for (const file of lexiconFiles) {\n * yield JSON.parse(await fs.readFile(file, 'utf8'))\n * }\n * }\n *\n * await using indexer = new LexiconIterableIndexer(loadLexicons())\n * const schemas = await LexiconSchemaBuilder.buildAll(indexer)\n * ```\n */\nexport class LexiconIterableIndexer implements LexiconIndexer, AsyncDisposable {\n readonly #lexicons: Map<string, LexiconDocument> = new Map()\n readonly #iterator:\n | AsyncIterator<LexiconDocument, void, unknown>\n | Iterator<LexiconDocument, void, unknown>\n\n /**\n * Creates a new {@link LexiconIterableIndexer} from an iterable source.\n *\n * @param source - An iterable or async iterable of Lexicon documents.\n * The iterator is consumed lazily as documents are requested.\n *\n * @example\n * ```ts\n * // Sync iterable (array, Set, Map.values(), etc.)\n * const indexer = new LexiconIterableIndexer(lexiconDocuments)\n *\n * // Async iterable (async generator, ReadableStream, etc.)\n * const indexer = new LexiconIterableIndexer(asyncLexiconStream)\n * ```\n */\n constructor(\n source: AsyncIterable<LexiconDocument> | Iterable<LexiconDocument>,\n ) {\n this.#iterator =\n Symbol.asyncIterator in source\n ? source[Symbol.asyncIterator]()\n : source[Symbol.iterator]()\n }\n\n /**\n * Retrieves a Lexicon document by its NSID.\n *\n * If the document has already been indexed, it is returned from cache.\n * Otherwise, the source iterator is consumed until the document is found.\n *\n * @see {@link LexiconIndexer.get}\n */\n async get(id: string): Promise<LexiconDocument> {\n const cached = this.#lexicons.get(id)\n if (cached) return cached\n\n for await (const doc of this) {\n if (doc.id === id) return doc\n }\n\n throw Object.assign(new Error(`Lexicon ${id} not found`), {\n code: 'ENOENT',\n })\n }\n\n async *[Symbol.asyncIterator](): AsyncIterator<\n LexiconDocument,\n void,\n undefined\n > {\n const returned = new Set<string>()\n\n for (const doc of this.#lexicons.values()) {\n returned.add(doc.id)\n yield doc\n }\n\n do {\n const { value, done } = await this.#iterator.next()\n\n if (done) break\n\n if (returned.has(value.id)) {\n const err = new Error(`Duplicate lexicon document id: ${value.id}`)\n await this.#iterator.throw?.(err)\n throw err // In case iterator.throw does not exist or does not throw\n }\n\n this.#lexicons.set(value.id, value)\n returned.add(value.id)\n yield value\n } while (true)\n\n // At this point, the underlying iterator is done. However, there may have\n // been requests (.get()) for documents that caused the iterator to yield\n // those documents during concurrent execution of this loop. If that was the\n // case, new documents may have been added to `#lexicons` that have not yet\n // been yielded. We need to yield those as well. Since we yield control back\n // to the caller, we need to repeat this process until no new documents\n // appear sunce we don't know what happens.\n\n for (const doc of this.#lexicons.values()) {\n if (!returned.has(doc.id)) {\n returned.add(doc.id)\n yield doc\n }\n }\n }\n\n async [Symbol.asyncDispose](): Promise<void> {\n await this.#iterator.return?.()\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { LexValue } from '@atproto/lex-data';
|
|
1
|
+
import type { LexValue } from '@atproto/lex-data';
|
|
2
2
|
import { l } from '@atproto/lex-schema';
|
|
3
|
-
import { LexiconArray, LexiconArrayItems, LexiconDocument, LexiconError, LexiconObject, LexiconParameters, LexiconPayload, LexiconRef, LexiconRefUnion } from './lexicon-document.js';
|
|
4
|
-
import { LexiconIndexer } from './lexicon-indexer.js';
|
|
3
|
+
import type { LexiconArray, LexiconArrayItems, LexiconDocument, LexiconError, LexiconObject, LexiconParameters, LexiconPayload, LexiconRef, LexiconRefUnion } from './lexicon-document.js';
|
|
4
|
+
import type { LexiconIndexer } from './lexicon-indexer.js';
|
|
5
5
|
/**
|
|
6
6
|
* Builds validators for Lexicon documents.
|
|
7
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-schema-builder.d.ts","sourceRoot":"","sources":["../src/lexicon-schema-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"lexicon-schema-builder.d.ts","sourceRoot":"","sources":["../src/lexicon-schema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EAA0B,CAAA;IAC/C,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;QACtB,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAE,CAAA;QAC1C,MAAM,MAAM,GAAG,EAAE,CAAC,GAAG,CAAmB,CAAA;QACxC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACtB,OAAO,MAAM,CAAA;IACf,CAAC,CAAO,CAAA;AACV,CAAC;AAED,SAAS,qBAAqB,CAC5B,GAAM;IAEN,OAAO,CACL,GAAG,IAAI,IAAI;QACX,OAAO,GAAG,KAAK,QAAQ;QACvB,MAAM,CAAC,aAAa,IAAI,GAAG;QAC3B,OAAO,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,UAAU,CAChD,CAAA;AACH,CAAC","sourcesContent":["import { LexValue } from '@atproto/lex-data'\nimport { l } from '@atproto/lex-schema'\nimport {\n LexiconArray,\n LexiconArrayItems,\n LexiconDocument,\n LexiconError,\n LexiconObject,\n LexiconParameters,\n LexiconPayload,\n LexiconRef,\n LexiconRefUnion,\n} from './lexicon-document.js'\nimport { LexiconIndexer } from './lexicon-indexer.js'\n\n/**\n * Builds validators for Lexicon documents.\n *\n * This class converts Lexicon type definitions into runtime validators\n * that can validate data against the schema. It handles reference resolution,\n * supporting both local (`#defName`) and cross-document (`nsid#defName`) refs.\n *\n * @example\n * ```ts\n * import { LexiconSchemaBuilder, LexiconIterableIndexer } from '@atproto/lex-document'\n *\n * // Build a single validator\n * const indexer = new LexiconIterableIndexer(lexiconDocs)\n * const validator = await LexiconSchemaBuilder.build(indexer, 'com.example.post#main')\n *\n * // Validate data\n * const result = validator.safeParse(myPostData)\n * if (result.success) {\n * console.log('Valid:', result.value)\n * } else {\n * console.log('Invalid:', result.error)\n * }\n * ```\n *\n * @example\n * ```ts\n * // Build all validators from an iterable indexer\n * const indexer = new LexiconIterableIndexer(lexiconDocs)\n * const allSchemas = await LexiconSchemaBuilder.buildAll(indexer)\n *\n * for (const [ref, schema] of allSchemas) {\n * console.log(`Built validator for ${ref}`)\n * }\n * ```\n */\nexport class LexiconSchemaBuilder implements AsyncDisposable {\n /**\n * Builds a validator for a single Lexicon definition reference.\n *\n * @param indexer - The Lexicon indexer to resolve documents from\n * @param fullRef - The full reference to build, in format \"nsid#defName\"\n * @returns A promise resolving to a validator for the referenced definition\n * @throws Error if the reference does not point to a schema type\n *\n * @example\n * ```ts\n * const validator = await LexiconSchemaBuilder.build(\n * indexer,\n * 'app.bsky.feed.post#main'\n * )\n *\n * validator.parse(postRecord) // Throws if invalid\n * ```\n */\n static async build(\n indexer: LexiconIndexer,\n fullRef: string,\n ): Promise<l.Schema<LexValue>> {\n const ctx = new LexiconSchemaBuilder(indexer)\n try {\n const result = await ctx.buildFullRef(fullRef)\n if (!(result instanceof l.Schema)) {\n throw new Error(`Ref ${fullRef} is not a schema type`)\n }\n return result\n } finally {\n await ctx.done()\n }\n }\n\n /**\n * Builds validators for all definitions in all documents from an iterable indexer.\n *\n * This method iterates over all Lexicon documents available in the indexer\n * and builds validators for every definition in each document.\n *\n * @param indexer - An iterable Lexicon indexer (must implement `Symbol.asyncIterator`)\n * @returns A promise resolving to a Map of full references to their validators.\n * The map values can be validators, Query, Subscription, Procedure, or PermissionSet.\n * @throws Error if the indexer does not support iteration\n *\n * @example\n * ```ts\n * const indexer = new LexiconIterableIndexer(allLexiconDocs)\n * const schemas = await LexiconSchemaBuilder.buildAll(indexer)\n *\n * // Access a specific schema\n * const postSchema = schemas.get('app.bsky.feed.post#main')\n *\n * // Iterate all schemas\n * for (const [ref, schema] of schemas) {\n * console.log(ref, schema)\n * }\n * ```\n */\n static async buildAll(indexer: LexiconIndexer) {\n const builder = new LexiconSchemaBuilder(indexer)\n const schemas = new Map<\n string,\n | l.Schema<LexValue>\n | l.Query\n | l.Subscription\n | l.Procedure\n | l.PermissionSet\n >()\n if (!isAsyncIterableObject(indexer)) {\n throw new Error('An iterable indexer is required to build all schemas')\n }\n try {\n for await (const doc of indexer) {\n for (const hash of Object.keys(doc.defs)) {\n const fullRef = `${doc.id}#${hash}`\n const schema = await builder.buildFullRef(fullRef)\n schemas.set(fullRef, schema)\n }\n }\n return schemas\n } finally {\n await builder.done()\n }\n }\n\n #asyncTasks = new AsyncTasks()\n\n /**\n * Creates a new LexiconSchemaBuilder instance.\n *\n * Note: For most use cases, prefer using the static `build()` or `buildAll()`\n * methods instead of instantiating directly.\n *\n * @param indexer - The Lexicon indexer to resolve documents from\n */\n constructor(protected indexer: LexiconIndexer) {}\n\n /**\n * Waits for all pending reference resolution tasks to complete.\n *\n * When building schemas with cross-references, the builder schedules\n * async tasks to resolve those references. This method must be called\n * to ensure all references are fully resolved before using the validators.\n *\n * @returns A promise that resolves when all pending tasks are complete\n * @throws Rethrows any errors from failed reference resolution\n */\n async done(): Promise<void> {\n await this.#asyncTasks.done()\n }\n\n async [Symbol.asyncDispose]() {\n await this.done()\n }\n\n /**\n * Builds a validator for a full reference (memoized).\n *\n * Results are cached, so calling with the same reference returns\n * the same promise/result.\n *\n * @param fullRef - The full reference in format \"nsid#defName\"\n * @returns A promise resolving to the built schema or method definition\n */\n buildFullRef = memoize(async (fullRef: string) => {\n const { nsid, hash } = parseRef(fullRef)\n\n const doc = await this.indexer.get(nsid)\n\n return this.compileDef(doc, hash)\n })\n\n protected buildRefGetter(fullRef: string): () => l.Schema<LexValue> {\n let schema: l.Schema<LexValue>\n\n this.#asyncTasks.add(\n this.buildFullRef(fullRef).then((v) => {\n if (!(v instanceof l.Schema)) {\n throw new Error(`Only refs to schema types are allowed`)\n }\n schema = v\n }),\n )\n\n return () => {\n if (schema) return schema\n throw new Error('Validator not yet built. Did you await done()?')\n }\n }\n\n protected buildTypedRefGetter(\n fullRef: string,\n ): () => l.TypedObjectSchema | l.RecordSchema {\n let validator: l.TypedObjectSchema | l.RecordSchema\n\n this.#asyncTasks.add(\n this.buildFullRef(fullRef).then((v) => {\n if (v instanceof l.TypedObjectSchema || v instanceof l.RecordSchema) {\n validator = v\n } else {\n throw new Error(\n 'Only refs to records and object definitions are allowed',\n )\n }\n }),\n )\n\n return () => {\n if (validator) return validator\n throw new Error('Validator not yet built. Did you await done()?')\n }\n }\n\n protected compileDef(doc: LexiconDocument, hash: string) {\n const def = Object.hasOwn(doc.defs, hash) ? doc.defs[hash] : null\n if (!def) {\n throw new Error(\n `No definition found for hash \"${JSON.stringify(hash)}\" in ${doc.id}`,\n )\n }\n switch (def.type) {\n case 'permission-set':\n return l.permissionSet(\n doc.id,\n def.permissions.map(({ resource, type, ...p }) =>\n l.permission(resource, p),\n ),\n def,\n )\n case 'procedure':\n return l.procedure(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayload(doc, def.input),\n this.compilePayload(doc, def.output),\n this.compileErrors(doc, def.errors),\n )\n case 'query':\n return l.query(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayload(doc, def.output),\n this.compileErrors(doc, def.errors),\n )\n case 'subscription':\n return l.subscription(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayloadSchema(doc, def.message.schema),\n this.compileErrors(doc, def.errors),\n )\n case 'token':\n return l.token(doc.id, hash)\n case 'record':\n return l.record(def.key, doc.id, this.compileObject(doc, def.record))\n case 'object':\n return l.typedObject(doc.id, hash, this.compileObject(doc, def))\n default:\n return this.compileLeaf(doc, def)\n }\n }\n\n protected compileLeaf(\n doc: LexiconDocument,\n def: LexiconArray | LexiconArrayItems,\n ): l.Schema<LexValue> {\n if (\n 'const' in def &&\n 'enum' in def &&\n def.enum != null &&\n def.const !== undefined &&\n !(def.enum as readonly unknown[]).includes(def.const)\n ) {\n return l.never()\n }\n\n switch (def.type) {\n case 'string': {\n const schema = l.string(def)\n if (def.default != null) schema.check(def.default)\n if (def.const != null) schema.check(def.const)\n if (def.enum != null) for (const v of def.enum) schema.check(v)\n\n const result =\n def.const != null\n ? l.literal(def.const)\n : def.enum != null\n ? l.enum(def.enum)\n : schema\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'integer': {\n const schema = l.integer(def)\n if (def.default != null) schema.check(def.default)\n if (def.const != null) schema.check(def.const)\n if (def.enum != null) for (const v of def.enum) schema.check(v)\n\n const result =\n def.const != null\n ? l.literal(def.const)\n : def.enum != null\n ? l.enum(def.enum)\n : schema\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'boolean': {\n const result = def.const != null ? l.literal(def.const) : l.boolean()\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'blob':\n return l.blob(def)\n case 'cid-link':\n return l.cid()\n case 'bytes':\n return l.bytes(def)\n case 'unknown':\n return l.lexMap()\n case 'array':\n return l.array(this.compileLeaf(doc, def.items), def)\n default:\n return this.compileRef(doc, def)\n }\n }\n\n protected compileRef(\n doc: LexiconDocument,\n def: LexiconRef | LexiconRefUnion,\n ): l.Schema<LexValue> {\n switch (def.type) {\n case 'ref':\n return l.ref(this.buildRefGetter(buildFullRef(doc, def.ref)))\n case 'union':\n return l.typedUnion(\n def.refs.map((r) =>\n l.typedRef(this.buildTypedRefGetter(buildFullRef(doc, r))),\n ),\n def.closed ?? false,\n )\n default:\n // @ts-expect-error\n throw new Error(`Unknown lexicon type: ${def.type}`)\n }\n }\n\n protected compileObject(doc: LexiconDocument, def: LexiconObject) {\n const props: Record<string, l.Schema<undefined | LexValue>> = {}\n for (const [key, propDef] of Object.entries(def.properties)) {\n if (propDef === undefined) continue\n\n const isNullable = def.nullable?.includes(key)\n const isRequired = def.required?.includes(key)\n\n let schema: l.Schema<undefined | LexValue> = this.compileLeaf(\n doc,\n propDef,\n )\n\n if (isNullable) {\n schema = l.nullable(schema)\n }\n\n if (!isRequired) {\n schema = l.optional(schema)\n }\n\n props[key] = schema\n }\n return l.object(props)\n }\n\n protected compilePayload(\n doc: LexiconDocument,\n def: LexiconPayload | undefined,\n ) {\n return l.payload(\n def?.encoding,\n def?.schema ? this.compilePayloadSchema(doc, def.schema) : undefined,\n )\n }\n\n protected compileErrors(\n _doc: LexiconDocument,\n errors?: readonly LexiconError[],\n ): undefined | string[] {\n return errors?.map((e) => e.name)\n }\n\n protected compilePayloadSchema(\n doc: LexiconDocument,\n def: LexiconObject | LexiconRef | LexiconRefUnion,\n ): l.Schema<LexValue, LexValue> {\n switch (def.type) {\n case 'object':\n return this.compileObject(doc, def)\n default:\n return this.compileRef(doc, def)\n }\n }\n\n protected compileParams(doc: LexiconDocument, def?: LexiconParameters) {\n if (!def) return l.params()\n\n const shape: l.ParamsShape = {}\n for (const [paramName, paramDef] of Object.entries(def.properties)) {\n if (paramDef === undefined) continue\n\n const isRequired = def.required?.includes(paramName)\n\n const propSchema = this.compileLeaf(doc, paramDef) as\n | l.StringSchema\n | l.BooleanSchema\n | l.IntegerSchema\n | l.ArraySchema<l.StringSchema>\n | l.ArraySchema<l.BooleanSchema>\n | l.ArraySchema<l.IntegerSchema>\n\n shape[paramName] = isRequired ? propSchema : l.optional(propSchema)\n }\n\n return l.params(shape)\n }\n}\n\nclass AsyncTasks {\n /**\n * A set that, eventually, contains only rejected promises.\n */\n #promises = new Set<Promise<void>>()\n\n async done(): Promise<void> {\n do {\n // @NOTE this is going to throw on the first rejected promise (which is\n // what we want)\n for (const p of this.#promises) await p\n // At this point, all settled promises should have been removed. If\n // this.#promises is not empty, it means new promises were added during\n // the awaiting process, so we loop again.\n } while (this.#promises.size > 0)\n }\n\n add(p: Promise<void>) {\n const promise = Promise.resolve(p).then(() => {\n // No need to keep the promise any longer\n this.#promises.delete(promise)\n })\n\n void promise.catch((_err) => {\n // ignore errors here, they should be caught though done()\n })\n\n this.#promises.add(promise)\n }\n}\n\nfunction parseRef(fullRef: string) {\n const { length, 0: nsid, 1: hash } = fullRef.split('#')\n if (length !== 2) throw new Error('Uri can only have one hash segment')\n if (!nsid || !hash) throw new Error('Invalid ref, missing hash')\n return { nsid, hash }\n}\n\nfunction buildFullRef(from: LexiconDocument, ref: string) {\n if (ref.startsWith('#')) return `${from.id}${ref}`\n return ref\n}\n\nexport function memoize<Fn extends (arg: string) => unknown>(fn: Fn): Fn {\n const cache = new Map<string, ReturnType<Fn>>()\n return ((arg: string) => {\n if (cache.has(arg)) return cache.get(arg)!\n const result = fn(arg) as ReturnType<Fn>\n cache.set(arg, result)\n return result\n }) as Fn\n}\n\nfunction isAsyncIterableObject<T>(\n obj: T,\n): obj is T & object & AsyncIterable<unknown> {\n return (\n obj != null &&\n typeof obj === 'object' &&\n Symbol.asyncIterator in obj &&\n typeof obj[Symbol.asyncIterator] === 'function'\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lexicon-schema-builder.js","sourceRoot":"","sources":["../src/lexicon-schema-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AAcvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,OAAO,oBAAoB;IAC/B;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,CAChB,OAAuB,EACvB,OAAe;QAEf,MAAM,GAAG,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAA;QAC7C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;YAC9C,IAAI,CAAC,CAAC,MAAM,YAAY,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,KAAK,CAAC,OAAO,OAAO,uBAAuB,CAAC,CAAA;YACxD,CAAC;YACD,OAAO,MAAM,CAAA;QACf,CAAC;gBAAS,CAAC;YACT,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;QAClB,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAuB;QAC3C,MAAM,OAAO,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC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ray,\n LexiconArrayItems,\n LexiconDocument,\n LexiconError,\n LexiconObject,\n LexiconParameters,\n LexiconPayload,\n LexiconRef,\n LexiconRefUnion,\n} from './lexicon-document.js'\nimport type { LexiconIndexer } from './lexicon-indexer.js'\n\n/**\n * Builds validators for Lexicon documents.\n *\n * This class converts Lexicon type definitions into runtime validators\n * that can validate data against the schema. It handles reference resolution,\n * supporting both local (`#defName`) and cross-document (`nsid#defName`) refs.\n *\n * @example\n * ```ts\n * import { LexiconSchemaBuilder, LexiconIterableIndexer } from '@atproto/lex-document'\n *\n * // Build a single validator\n * const indexer = new LexiconIterableIndexer(lexiconDocs)\n * const validator = await LexiconSchemaBuilder.build(indexer, 'com.example.post#main')\n *\n * // Validate data\n * const result = validator.safeParse(myPostData)\n * if (result.success) {\n * console.log('Valid:', result.value)\n * } else {\n * console.log('Invalid:', result.error)\n * }\n * ```\n *\n * @example\n * ```ts\n * // Build all validators from an iterable indexer\n * const indexer = new LexiconIterableIndexer(lexiconDocs)\n * const allSchemas = await LexiconSchemaBuilder.buildAll(indexer)\n *\n * for (const [ref, schema] of allSchemas) {\n * console.log(`Built validator for ${ref}`)\n * }\n * ```\n */\nexport class LexiconSchemaBuilder implements AsyncDisposable {\n /**\n * Builds a validator for a single Lexicon definition reference.\n *\n * @param indexer - The Lexicon indexer to resolve documents from\n * @param fullRef - The full reference to build, in format \"nsid#defName\"\n * @returns A promise resolving to a validator for the referenced definition\n * @throws Error if the reference does not point to a schema type\n *\n * @example\n * ```ts\n * const validator = await LexiconSchemaBuilder.build(\n * indexer,\n * 'app.bsky.feed.post#main'\n * )\n *\n * validator.parse(postRecord) // Throws if invalid\n * ```\n */\n static async build(\n indexer: LexiconIndexer,\n fullRef: string,\n ): Promise<l.Schema<LexValue>> {\n const ctx = new LexiconSchemaBuilder(indexer)\n try {\n const result = await ctx.buildFullRef(fullRef)\n if (!(result instanceof l.Schema)) {\n throw new Error(`Ref ${fullRef} is not a schema type`)\n }\n return result\n } finally {\n await ctx.done()\n }\n }\n\n /**\n * Builds validators for all definitions in all documents from an iterable indexer.\n *\n * This method iterates over all Lexicon documents available in the indexer\n * and builds validators for every definition in each document.\n *\n * @param indexer - An iterable Lexicon indexer (must implement `Symbol.asyncIterator`)\n * @returns A promise resolving to a Map of full references to their validators.\n * The map values can be validators, Query, Subscription, Procedure, or PermissionSet.\n * @throws Error if the indexer does not support iteration\n *\n * @example\n * ```ts\n * const indexer = new LexiconIterableIndexer(allLexiconDocs)\n * const schemas = await LexiconSchemaBuilder.buildAll(indexer)\n *\n * // Access a specific schema\n * const postSchema = schemas.get('app.bsky.feed.post#main')\n *\n * // Iterate all schemas\n * for (const [ref, schema] of schemas) {\n * console.log(ref, schema)\n * }\n * ```\n */\n static async buildAll(indexer: LexiconIndexer) {\n const builder = new LexiconSchemaBuilder(indexer)\n const schemas = new Map<\n string,\n | l.Schema<LexValue>\n | l.Query\n | l.Subscription\n | l.Procedure\n | l.PermissionSet\n >()\n if (!isAsyncIterableObject(indexer)) {\n throw new Error('An iterable indexer is required to build all schemas')\n }\n try {\n for await (const doc of indexer) {\n for (const hash of Object.keys(doc.defs)) {\n const fullRef = `${doc.id}#${hash}`\n const schema = await builder.buildFullRef(fullRef)\n schemas.set(fullRef, schema)\n }\n }\n return schemas\n } finally {\n await builder.done()\n }\n }\n\n #asyncTasks = new AsyncTasks()\n\n /**\n * Creates a new LexiconSchemaBuilder instance.\n *\n * Note: For most use cases, prefer using the static `build()` or `buildAll()`\n * methods instead of instantiating directly.\n *\n * @param indexer - The Lexicon indexer to resolve documents from\n */\n constructor(protected indexer: LexiconIndexer) {}\n\n /**\n * Waits for all pending reference resolution tasks to complete.\n *\n * When building schemas with cross-references, the builder schedules\n * async tasks to resolve those references. This method must be called\n * to ensure all references are fully resolved before using the validators.\n *\n * @returns A promise that resolves when all pending tasks are complete\n * @throws Rethrows any errors from failed reference resolution\n */\n async done(): Promise<void> {\n await this.#asyncTasks.done()\n }\n\n async [Symbol.asyncDispose]() {\n await this.done()\n }\n\n /**\n * Builds a validator for a full reference (memoized).\n *\n * Results are cached, so calling with the same reference returns\n * the same promise/result.\n *\n * @param fullRef - The full reference in format \"nsid#defName\"\n * @returns A promise resolving to the built schema or method definition\n */\n buildFullRef = memoize(async (fullRef: string) => {\n const { nsid, hash } = parseRef(fullRef)\n\n const doc = await this.indexer.get(nsid)\n\n return this.compileDef(doc, hash)\n })\n\n protected buildRefGetter(fullRef: string): () => l.Schema<LexValue> {\n let schema: l.Schema<LexValue>\n\n this.#asyncTasks.add(\n this.buildFullRef(fullRef).then((v) => {\n if (!(v instanceof l.Schema)) {\n throw new Error(`Only refs to schema types are allowed`)\n }\n schema = v\n }),\n )\n\n return () => {\n if (schema) return schema\n throw new Error('Validator not yet built. Did you await done()?')\n }\n }\n\n protected buildTypedRefGetter(\n fullRef: string,\n ): () => l.TypedObjectSchema | l.RecordSchema {\n let validator: l.TypedObjectSchema | l.RecordSchema\n\n this.#asyncTasks.add(\n this.buildFullRef(fullRef).then((v) => {\n if (v instanceof l.TypedObjectSchema || v instanceof l.RecordSchema) {\n validator = v\n } else {\n throw new Error(\n 'Only refs to records and object definitions are allowed',\n )\n }\n }),\n )\n\n return () => {\n if (validator) return validator\n throw new Error('Validator not yet built. Did you await done()?')\n }\n }\n\n protected compileDef(doc: LexiconDocument, hash: string) {\n const def = Object.hasOwn(doc.defs, hash) ? doc.defs[hash] : null\n if (!def) {\n throw new Error(\n `No definition found for hash \"${JSON.stringify(hash)}\" in ${doc.id}`,\n )\n }\n switch (def.type) {\n case 'permission-set':\n return l.permissionSet(\n doc.id,\n def.permissions.map(({ resource, type, ...p }) =>\n l.permission(resource, p),\n ),\n def,\n )\n case 'procedure':\n return l.procedure(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayload(doc, def.input),\n this.compilePayload(doc, def.output),\n this.compileErrors(doc, def.errors),\n )\n case 'query':\n return l.query(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayload(doc, def.output),\n this.compileErrors(doc, def.errors),\n )\n case 'subscription':\n return l.subscription(\n doc.id,\n this.compileParams(doc, def.parameters),\n this.compilePayloadSchema(doc, def.message.schema),\n this.compileErrors(doc, def.errors),\n )\n case 'token':\n return l.token(doc.id, hash)\n case 'record':\n return l.record(def.key, doc.id, this.compileObject(doc, def.record))\n case 'object':\n return l.typedObject(doc.id, hash, this.compileObject(doc, def))\n default:\n return this.compileLeaf(doc, def)\n }\n }\n\n protected compileLeaf(\n doc: LexiconDocument,\n def: LexiconArray | LexiconArrayItems,\n ): l.Schema<LexValue> {\n if (\n 'const' in def &&\n 'enum' in def &&\n def.enum != null &&\n def.const !== undefined &&\n !(def.enum as readonly unknown[]).includes(def.const)\n ) {\n return l.never()\n }\n\n switch (def.type) {\n case 'string': {\n const schema = l.string(def)\n if (def.default != null) schema.check(def.default)\n if (def.const != null) schema.check(def.const)\n if (def.enum != null) for (const v of def.enum) schema.check(v)\n\n const result =\n def.const != null\n ? l.literal(def.const)\n : def.enum != null\n ? l.enum(def.enum)\n : schema\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'integer': {\n const schema = l.integer(def)\n if (def.default != null) schema.check(def.default)\n if (def.const != null) schema.check(def.const)\n if (def.enum != null) for (const v of def.enum) schema.check(v)\n\n const result =\n def.const != null\n ? l.literal(def.const)\n : def.enum != null\n ? l.enum(def.enum)\n : schema\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'boolean': {\n const result = def.const != null ? l.literal(def.const) : l.boolean()\n\n return def.default != null ? l.withDefault(result, def.default) : result\n }\n case 'blob':\n return l.blob(def)\n case 'cid-link':\n return l.cid()\n case 'bytes':\n return l.bytes(def)\n case 'unknown':\n return l.lexMap()\n case 'array':\n return l.array(this.compileLeaf(doc, def.items), def)\n default:\n return this.compileRef(doc, def)\n }\n }\n\n protected compileRef(\n doc: LexiconDocument,\n def: LexiconRef | LexiconRefUnion,\n ): l.Schema<LexValue> {\n switch (def.type) {\n case 'ref':\n return l.ref(this.buildRefGetter(buildFullRef(doc, def.ref)))\n case 'union':\n return l.typedUnion(\n def.refs.map((r) =>\n l.typedRef(this.buildTypedRefGetter(buildFullRef(doc, r))),\n ),\n def.closed ?? false,\n )\n default:\n // @ts-expect-error\n throw new Error(`Unknown lexicon type: ${def.type}`)\n }\n }\n\n protected compileObject(doc: LexiconDocument, def: LexiconObject) {\n const props: Record<string, l.Schema<undefined | LexValue>> = {}\n for (const [key, propDef] of Object.entries(def.properties)) {\n if (propDef === undefined) continue\n\n const isNullable = def.nullable?.includes(key)\n const isRequired = def.required?.includes(key)\n\n let schema: l.Schema<undefined | LexValue> = this.compileLeaf(\n doc,\n propDef,\n )\n\n if (isNullable) {\n schema = l.nullable(schema)\n }\n\n if (!isRequired) {\n schema = l.optional(schema)\n }\n\n props[key] = schema\n }\n return l.object(props)\n }\n\n protected compilePayload(\n doc: LexiconDocument,\n def: LexiconPayload | undefined,\n ) {\n return l.payload(\n def?.encoding,\n def?.schema ? this.compilePayloadSchema(doc, def.schema) : undefined,\n )\n }\n\n protected compileErrors(\n _doc: LexiconDocument,\n errors?: readonly LexiconError[],\n ): undefined | string[] {\n return errors?.map((e) => e.name)\n }\n\n protected compilePayloadSchema(\n doc: LexiconDocument,\n def: LexiconObject | LexiconRef | LexiconRefUnion,\n ): l.Schema<LexValue, LexValue> {\n switch (def.type) {\n case 'object':\n return this.compileObject(doc, def)\n default:\n return this.compileRef(doc, def)\n }\n }\n\n protected compileParams(doc: LexiconDocument, def?: LexiconParameters) {\n if (!def) return l.params()\n\n const shape: l.ParamsShape = {}\n for (const [paramName, paramDef] of Object.entries(def.properties)) {\n if (paramDef === undefined) continue\n\n const isRequired = def.required?.includes(paramName)\n\n const propSchema = this.compileLeaf(doc, paramDef) as\n | l.StringSchema\n | l.BooleanSchema\n | l.IntegerSchema\n | l.ArraySchema<l.StringSchema>\n | l.ArraySchema<l.BooleanSchema>\n | l.ArraySchema<l.IntegerSchema>\n\n shape[paramName] = isRequired ? propSchema : l.optional(propSchema)\n }\n\n return l.params(shape)\n }\n}\n\nclass AsyncTasks {\n /**\n * A set that, eventually, contains only rejected promises.\n */\n #promises = new Set<Promise<void>>()\n\n async done(): Promise<void> {\n do {\n // @NOTE this is going to throw on the first rejected promise (which is\n // what we want)\n for (const p of this.#promises) await p\n // At this point, all settled promises should have been removed. If\n // this.#promises is not empty, it means new promises were added during\n // the awaiting process, so we loop again.\n } while (this.#promises.size > 0)\n }\n\n add(p: Promise<void>) {\n const promise = Promise.resolve(p).then(() => {\n // No need to keep the promise any longer\n this.#promises.delete(promise)\n })\n\n void promise.catch((_err) => {\n // ignore errors here, they should be caught though done()\n })\n\n this.#promises.add(promise)\n }\n}\n\nfunction parseRef(fullRef: string) {\n const { length, 0: nsid, 1: hash } = fullRef.split('#')\n if (length !== 2) throw new Error('Uri can only have one hash segment')\n if (!nsid || !hash) throw new Error('Invalid ref, missing hash')\n return { nsid, hash }\n}\n\nfunction buildFullRef(from: LexiconDocument, ref: string) {\n if (ref.startsWith('#')) return `${from.id}${ref}`\n return ref\n}\n\nexport function memoize<Fn extends (arg: string) => unknown>(fn: Fn): Fn {\n const cache = new Map<string, ReturnType<Fn>>()\n return ((arg: string) => {\n if (cache.has(arg)) return cache.get(arg)!\n const result = fn(arg) as ReturnType<Fn>\n cache.set(arg, result)\n return result\n }) as Fn\n}\n\nfunction isAsyncIterableObject<T>(\n obj: T,\n): obj is T & object & AsyncIterable<unknown> {\n return (\n obj != null &&\n typeof obj === 'object' &&\n Symbol.asyncIterator in obj &&\n typeof obj[Symbol.asyncIterator] === 'function'\n )\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex-document",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"engines": {
|
|
5
|
-
"node": ">=22"
|
|
6
|
-
},
|
|
3
|
+
"version": "0.1.3",
|
|
7
4
|
"license": "MIT",
|
|
8
5
|
"description": "Lexicon document validation tools for AT",
|
|
9
6
|
"keywords": [
|
|
@@ -19,10 +16,6 @@
|
|
|
19
16
|
"directory": "packages/lex/lex-document"
|
|
20
17
|
},
|
|
21
18
|
"files": [
|
|
22
|
-
"./src",
|
|
23
|
-
"./tsconfig.build.json",
|
|
24
|
-
"./tsconfig.tests.json",
|
|
25
|
-
"./tsconfig.json",
|
|
26
19
|
"./dist",
|
|
27
20
|
"./CHANGELOG.md"
|
|
28
21
|
],
|
|
@@ -34,14 +27,17 @@
|
|
|
34
27
|
"default": "./dist/index.js"
|
|
35
28
|
}
|
|
36
29
|
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=22"
|
|
32
|
+
},
|
|
37
33
|
"dependencies": {
|
|
38
34
|
"core-js": "^3",
|
|
39
35
|
"tslib": "^2.8.1",
|
|
40
|
-
"@atproto/lex-schema": "^0.1.
|
|
36
|
+
"@atproto/lex-schema": "^0.1.6"
|
|
41
37
|
},
|
|
42
38
|
"devDependencies": {
|
|
43
39
|
"vitest": "^4.0.16",
|
|
44
|
-
"@atproto/lex-data": "^0.1.
|
|
40
|
+
"@atproto/lex-data": "^0.1.4"
|
|
45
41
|
},
|
|
46
42
|
"scripts": {
|
|
47
43
|
"build": "tsgo --build tsconfig.build.json",
|
package/src/core-js.d.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { lexiconDocumentSchema } from './lexicon-document.js'
|
|
3
|
-
|
|
4
|
-
describe('lexiconDocumentSchema', () => {
|
|
5
|
-
it('allows unknown fields to be present', () => {
|
|
6
|
-
const value = {
|
|
7
|
-
lexicon: 1,
|
|
8
|
-
id: 'com.example.unknownFields',
|
|
9
|
-
defs: {
|
|
10
|
-
test: {
|
|
11
|
-
type: 'object',
|
|
12
|
-
properties: {},
|
|
13
|
-
foo: 3,
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
expect(lexiconDocumentSchema.safeParse(value)).toStrictEqual({
|
|
19
|
-
success: true,
|
|
20
|
-
value,
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('validates a minimal lexicons document', () => {
|
|
25
|
-
expect(
|
|
26
|
-
lexiconDocumentSchema.safeParse({
|
|
27
|
-
lexicon: 1,
|
|
28
|
-
id: 'com.example.lexicon',
|
|
29
|
-
defs: {
|
|
30
|
-
demo: {
|
|
31
|
-
type: 'integer',
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
}),
|
|
35
|
-
).toMatchObject({
|
|
36
|
-
success: true,
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('rejects lexicons with invalid lexicon field', () => {
|
|
41
|
-
expect(
|
|
42
|
-
lexiconDocumentSchema.safeParse({
|
|
43
|
-
lexicon: 'one',
|
|
44
|
-
id: 'com.example.lexicon',
|
|
45
|
-
defs: {
|
|
46
|
-
demo: {
|
|
47
|
-
type: 'integer',
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
}),
|
|
51
|
-
).toMatchObject({
|
|
52
|
-
success: false,
|
|
53
|
-
reason: { issues: [{ code: 'invalid_value', values: [1] }] },
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('rejects lexicons with invalid NSID in id field', () => {
|
|
58
|
-
expect(
|
|
59
|
-
lexiconDocumentSchema.safeParse({
|
|
60
|
-
lexicon: 1,
|
|
61
|
-
id: 'not-an-nsid',
|
|
62
|
-
defs: {
|
|
63
|
-
demo: {
|
|
64
|
-
type: 'integer',
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
}),
|
|
68
|
-
).toMatchObject({
|
|
69
|
-
success: false,
|
|
70
|
-
reason: { issues: [{ code: 'invalid_format', format: 'nsid' }] },
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('rejects lexicons with numeric id field', () => {
|
|
75
|
-
expect(
|
|
76
|
-
lexiconDocumentSchema.safeParse({
|
|
77
|
-
lexicon: 1,
|
|
78
|
-
id: 2,
|
|
79
|
-
defs: {
|
|
80
|
-
demo: {
|
|
81
|
-
type: 'integer',
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
}),
|
|
85
|
-
).toMatchObject({
|
|
86
|
-
success: false,
|
|
87
|
-
reason: { issues: [{ code: 'invalid_type', expected: ['string'] }] },
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('rejects object defs with invalid required fields', () => {
|
|
92
|
-
expect(
|
|
93
|
-
lexiconDocumentSchema.safeParse({
|
|
94
|
-
lexicon: 1,
|
|
95
|
-
id: 'com.example.lexicon',
|
|
96
|
-
defs: {
|
|
97
|
-
demo: {
|
|
98
|
-
type: 'object',
|
|
99
|
-
properties: {
|
|
100
|
-
foo: { type: 'string' },
|
|
101
|
-
},
|
|
102
|
-
required: ['bar'],
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
}),
|
|
106
|
-
).toMatchObject({
|
|
107
|
-
success: false,
|
|
108
|
-
reason: {
|
|
109
|
-
issues: [{ code: 'custom', path: ['defs', 'demo', 'required'] }],
|
|
110
|
-
},
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
})
|