@atproto/lex-document 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/lexicon-schema-builder.d.ts +7 -7
- package/dist/lexicon-schema-builder.d.ts.map +1 -1
- package/dist/lexicon-schema-builder.js +1 -3
- package/dist/lexicon-schema-builder.js.map +1 -1
- package/package.json +3 -3
- package/src/lexicon-document.test.ts +4 -4
- package/src/lexicon-schema-builder.test.ts +2 -2
- package/src/lexicon-schema-builder.ts +2 -3
- package/tsconfig.tests.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atproto/lex-document
|
|
2
2
|
|
|
3
|
+
## 0.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece)]:
|
|
8
|
+
- @atproto/lex-schema@0.0.5
|
|
9
|
+
|
|
3
10
|
## 0.0.5
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -18,21 +18,21 @@ export declare class LexiconSchemaBuilder {
|
|
|
18
18
|
#private;
|
|
19
19
|
protected indexer: LexiconIndexer;
|
|
20
20
|
static build(indexer: LexiconIndexer, fullRef: string): Promise<l.Validator<unknown>>;
|
|
21
|
-
static buildAll(indexer: LexiconIndexer): Promise<Map<string, l.Validator<unknown> | l.Query<
|
|
21
|
+
static buildAll(indexer: LexiconIndexer): Promise<Map<string, l.Validator<unknown> | l.Query<`${string}.${string}.${string}`, l.ParamsSchema<l.ParamsSchemaShape>, l.Payload<string | undefined, l.Schema<any> | undefined>, readonly string[] | undefined> | l.Subscription<`${string}.${string}.${string}`, l.ParamsSchema<l.ParamsSchemaShape>, l.Schema<any>, readonly string[] | undefined> | l.Procedure<`${string}.${string}.${string}`, l.ParamsSchema<l.ParamsSchemaShape>, l.Payload<string | undefined, l.Schema<any> | undefined>, l.Payload<string | undefined, l.Schema<any> | undefined>, readonly string[] | undefined> | l.PermissionSet<any, any>>>;
|
|
22
22
|
constructor(indexer: LexiconIndexer);
|
|
23
23
|
done(): Promise<void>;
|
|
24
24
|
buildFullRef: (fullRef: string) => Promise<l.Validator<unknown> | l.PermissionSet<`${string}.${string}.${string}`, l.Permission<string, {
|
|
25
25
|
[x: string]: string | number | boolean | (string | number | boolean)[];
|
|
26
|
-
}>[]> | l.Procedure<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.
|
|
26
|
+
}>[]> | l.Procedure<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.Schema<any> | undefined>, l.Payload<string | undefined, l.Schema<any> | undefined>, string[]> | l.Query<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.Schema<any> | undefined>, string[]> | l.Subscription<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.ObjectSchema<any> | l.RefSchema<unknown> | l.TypedUnionSchema<l.TypedRefSchema<{
|
|
27
27
|
[x: string]: any;
|
|
28
|
-
}>[], boolean
|
|
28
|
+
}>[], boolean>, string[]>>;
|
|
29
29
|
protected buildRefGetter(fullRef: string): () => l.Validator<unknown>;
|
|
30
30
|
protected buildTypedRefGetter(fullRef: string): () => l.TypedObjectSchema | l.RecordSchema;
|
|
31
31
|
protected compileDef(doc: LexiconDocument, hash: string): l.Validator<unknown> | l.PermissionSet<`${string}.${string}.${string}`, l.Permission<string, {
|
|
32
32
|
[x: string]: string | number | boolean | (string | number | boolean)[];
|
|
33
|
-
}>[]> | l.Procedure<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.
|
|
33
|
+
}>[]> | l.Procedure<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.Schema<any> | undefined>, l.Payload<string | undefined, l.Schema<any> | undefined>, string[]> | l.Query<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.Payload<string | undefined, l.Schema<any> | undefined>, string[]> | l.Subscription<`${string}.${string}.${string}`, l.ParamsSchema<{}>, l.ObjectSchema<any> | l.RefSchema<unknown> | l.TypedUnionSchema<l.TypedRefSchema<{
|
|
34
34
|
[x: string]: any;
|
|
35
|
-
}>[], boolean
|
|
35
|
+
}>[], boolean>, string[]>;
|
|
36
36
|
protected compileLeaf(doc: LexiconDocument, def: LexiconArray | LexiconArrayItems): l.Validator<unknown>;
|
|
37
37
|
protected compileRef(doc: LexiconDocument, def: LexiconRef | LexiconRefUnion): l.RefSchema<unknown> | l.TypedUnionSchema<l.TypedRefSchema<{
|
|
38
38
|
[x: string]: any;
|
|
@@ -40,9 +40,9 @@ export declare class LexiconSchemaBuilder {
|
|
|
40
40
|
protected compileObject(doc: LexiconDocument, def: LexiconObject): l.ObjectSchema;
|
|
41
41
|
protected compilePayload(doc: LexiconDocument, def: LexiconPayload | undefined): l.Payload;
|
|
42
42
|
protected compileErrors(_doc: LexiconDocument, errors?: readonly LexiconError[]): undefined | string[];
|
|
43
|
-
protected compilePayloadSchema(doc: LexiconDocument, def
|
|
43
|
+
protected compilePayloadSchema(doc: LexiconDocument, def: LexiconObject | LexiconRef | LexiconRefUnion): l.ObjectSchema<any> | l.RefSchema<unknown> | l.TypedUnionSchema<l.TypedRefSchema<{
|
|
44
44
|
[x: string]: any;
|
|
45
|
-
}>[], boolean
|
|
45
|
+
}>[], boolean>;
|
|
46
46
|
protected compileParams(doc: LexiconDocument, def?: LexiconParameters): l.ParamsSchema<{}>;
|
|
47
47
|
}
|
|
48
48
|
export declare function memoize<Fn extends (arg: string) => unknown>(fn: Fn): Fn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-schema-builder.d.ts","sourceRoot":"","sources":["../src/lexicon-schema-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AACvC,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,eAAe,EAChB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD;;;;;;;;;;;;GAYG;AACH,qBAAa,oBAAoB;;IA8CnB,SAAS,CAAC,OAAO,EAAE,cAAc;WA7ChC,KAAK,CAChB,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,MAAM,GACd,OAA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E,YAAY,GAAG,iBAAiB,GACpC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;IA0DvB,SAAS,CAAC,UAAU,CAClB,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,UAAU,GAAG,eAAe;;;IAkBnC,SAAS,CAAC,aAAa,CACrB,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,aAAa,GACjB,CAAC,CAAC,YAAY;IAuBjB,SAAS,CAAC,cAAc,CACtB,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,GAAG,SAAS,GAC9B,CAAC,CAAC,OAAO;IAOZ,SAAS,CAAC,aAAa,CACrB,IAAI,EAAE,eAAe,EACrB,MAAM,CAAC,EAAE,SAAS,YAAY,EAAE,GAC/B,SAAS,GAAG,MAAM,EAAE;IAIvB,SAAS,CAAC,oBAAoB,CAC5B,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,aAAa,GAAG,UAAU,GAAG,eAAe;;;IAUnD,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,CAAC,EAAE,iBAAiB;CAmBtE;AA6CD,wBAAgB,OAAO,CAAC,EAAE,SAAS,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,CAQvE"}
|
|
@@ -106,7 +106,7 @@ class LexiconSchemaBuilder {
|
|
|
106
106
|
case 'query':
|
|
107
107
|
return lex_schema_1.l.query(doc.id, this.compileParams(doc, def.parameters), this.compilePayload(doc, def.output), this.compileErrors(doc, def.errors));
|
|
108
108
|
case 'subscription':
|
|
109
|
-
return lex_schema_1.l.subscription(doc.id, this.compileParams(doc, def.parameters), this.compilePayloadSchema(doc, def.message
|
|
109
|
+
return lex_schema_1.l.subscription(doc.id, this.compileParams(doc, def.parameters), this.compilePayloadSchema(doc, def.message.schema), this.compileErrors(doc, def.errors));
|
|
110
110
|
case 'token':
|
|
111
111
|
return lex_schema_1.l.token(doc.id, hash);
|
|
112
112
|
case 'record':
|
|
@@ -214,8 +214,6 @@ class LexiconSchemaBuilder {
|
|
|
214
214
|
return errors?.map((e) => e.name);
|
|
215
215
|
}
|
|
216
216
|
compilePayloadSchema(doc, def) {
|
|
217
|
-
if (!def)
|
|
218
|
-
return undefined;
|
|
219
217
|
switch (def.type) {
|
|
220
218
|
case 'object':
|
|
221
219
|
return this.compileObject(doc, def);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-schema-builder.js","sourceRoot":"","sources":["../src/lexicon-schema-builder.ts"],"names":[],"mappings":";;;AA0XA,0BAQC;AAlYD,oDAAuC;AAcvC;;;;;;;;;;;;GAYG;AACH,MAAa,oBAAoB;IA8CT;IA7CtB,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,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAuB;QAC3C,MAAM,OAAO,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAA;QACjD,MAAM,OAAO,GAAG,IAAI,GAAG,EAOpB,CAAA;QACH,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;QACzE,CAAC;QACD,IAAI,CAAC;YACH,IAAI,KAAK,EAAE,MA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AO,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 { 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 a validator for a given lexicon \"ref\" from a lexicon indexer.\n *\n * @example\n *\n * ```ts\n * import { LexiconSchemaBuilder } from '@atproto/lex/doc'\n * import { LexiconStreamIndexer } from '@atproto/lex/doc'\n *\n * const indexer = new LexiconStreamIndexer(lexiconDocs)\n * const validator = await LexiconSchemaBuilder.build(indexer, 'com.example.foo#bar')\n * ```\n */\nexport class LexiconSchemaBuilder {\n static async build(\n indexer: LexiconIndexer,\n fullRef: string,\n ): Promise<l.Validator<unknown>> {\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 static async buildAll(indexer: LexiconIndexer) {\n const builder = new LexiconSchemaBuilder(indexer)\n const schemas = new Map<\n string,\n | l.Validator<unknown>\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 constructor(protected indexer: LexiconIndexer) {}\n\n async done(): Promise<void> {\n await this.#asyncTasks.done()\n }\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.Validator<unknown> {\n let validator: l.Validator<unknown>\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 validator = v\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 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.Validator<unknown> {\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.StringSchema = l.string(def)\n if (def.const != null) {\n schema.assert(def.const)\n return l.literal(def.const, def)\n } else if (def.enum != null) {\n for (const v of def.enum) schema.assert(v)\n return l.enum(def.enum, def)\n } else {\n return schema\n }\n }\n case 'integer': {\n const schema: l.IntegerSchema = l.integer(def)\n if (def.const != null) {\n schema.assert(def.const)\n return l.literal(def.const, def)\n } else if (def.enum != null) {\n for (const v of def.enum) schema.assert(v)\n return l.enum(def.enum, def)\n } else {\n return schema\n }\n }\n case 'boolean': {\n if (def.const != null) {\n return l.literal(def.const, def)\n } else {\n return l.boolean(def)\n }\n }\n case 'blob':\n return l.blob(def)\n case 'cid-link':\n return l.cidLink()\n case 'bytes':\n return l.bytes(def)\n case 'unknown':\n return l.unknown()\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 ) {\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(\n doc: LexiconDocument,\n def: LexiconObject,\n ): l.ObjectSchema {\n const props: Record<string, l.Validator> = {}\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 = this.compileLeaf(doc, propDef)\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 ): l.Payload {\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 ) {\n if (!def) return undefined\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 props: Record<string, l.Validator> = {}\n for (const [key, propDef] of Object.entries(def.properties)) {\n if (propDef === undefined) continue\n\n const isRequired = def.required?.includes(key)\n\n let schema = this.compileLeaf(doc, propDef)\n\n if (!isRequired) {\n schema = l.optional(schema)\n }\n\n props[key] = schema\n }\n return l.params(props)\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":";;;AAyXA,0BAQC;AAjYD,oDAAuC;AAcvC;;;;;;;;;;;;GAYG;AACH,MAAa,oBAAoB;IA8CT;IA7CtB,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,CA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,CAAC;AAED,SAAgB,OAAO,CAAsC,EAAM;IACjE,MAAM,KAAK,GAAG,IAAI,GAAG,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 { 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 a validator for a given lexicon \"ref\" from a lexicon indexer.\n *\n * @example\n *\n * ```ts\n * import { LexiconSchemaBuilder } from '@atproto/lex/doc'\n * import { LexiconStreamIndexer } from '@atproto/lex/doc'\n *\n * const indexer = new LexiconStreamIndexer(lexiconDocs)\n * const validator = await LexiconSchemaBuilder.build(indexer, 'com.example.foo#bar')\n * ```\n */\nexport class LexiconSchemaBuilder {\n static async build(\n indexer: LexiconIndexer,\n fullRef: string,\n ): Promise<l.Validator<unknown>> {\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 static async buildAll(indexer: LexiconIndexer) {\n const builder = new LexiconSchemaBuilder(indexer)\n const schemas = new Map<\n string,\n | l.Validator<unknown>\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 constructor(protected indexer: LexiconIndexer) {}\n\n async done(): Promise<void> {\n await this.#asyncTasks.done()\n }\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.Validator<unknown> {\n let validator: l.Validator<unknown>\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 validator = v\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 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.Validator<unknown> {\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.StringSchema = l.string(def)\n if (def.const != null) {\n schema.assert(def.const)\n return l.literal(def.const, def)\n } else if (def.enum != null) {\n for (const v of def.enum) schema.assert(v)\n return l.enum(def.enum, def)\n } else {\n return schema\n }\n }\n case 'integer': {\n const schema: l.IntegerSchema = l.integer(def)\n if (def.const != null) {\n schema.assert(def.const)\n return l.literal(def.const, def)\n } else if (def.enum != null) {\n for (const v of def.enum) schema.assert(v)\n return l.enum(def.enum, def)\n } else {\n return schema\n }\n }\n case 'boolean': {\n if (def.const != null) {\n return l.literal(def.const, def)\n } else {\n return l.boolean(def)\n }\n }\n case 'blob':\n return l.blob(def)\n case 'cid-link':\n return l.cidLink()\n case 'bytes':\n return l.bytes(def)\n case 'unknown':\n return l.unknown()\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 ) {\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(\n doc: LexiconDocument,\n def: LexiconObject,\n ): l.ObjectSchema {\n const props: Record<string, l.Validator> = {}\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 = this.compileLeaf(doc, propDef)\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 ): l.Payload {\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 ) {\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 props: Record<string, l.Validator> = {}\n for (const [key, propDef] of Object.entries(def.properties)) {\n if (propDef === undefined) continue\n\n const isRequired = def.required?.includes(key)\n\n let schema = this.compileLeaf(doc, propDef)\n\n if (!isRequired) {\n schema = l.optional(schema)\n }\n\n props[key] = schema\n }\n return l.params(props)\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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex-document",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Lexicon document validation tools for AT",
|
|
6
6
|
"keywords": [
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"core-js": "^3",
|
|
40
40
|
"tslib": "^2.8.1",
|
|
41
|
-
"@atproto/lex-schema": "0.0.
|
|
41
|
+
"@atproto/lex-schema": "0.0.5"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"jest": "^28.1.2",
|
|
45
|
-
"@atproto/lex-data": "0.0.
|
|
45
|
+
"@atproto/lex-data": "0.0.4"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsc --build tsconfig.build.json",
|
|
@@ -49,7 +49,7 @@ describe('lexiconDocumentSchema', () => {
|
|
|
49
49
|
}),
|
|
50
50
|
).toMatchObject({
|
|
51
51
|
success: false,
|
|
52
|
-
|
|
52
|
+
reason: { issues: [{ code: 'invalid_value', values: [1] }] },
|
|
53
53
|
})
|
|
54
54
|
})
|
|
55
55
|
|
|
@@ -66,7 +66,7 @@ describe('lexiconDocumentSchema', () => {
|
|
|
66
66
|
}),
|
|
67
67
|
).toMatchObject({
|
|
68
68
|
success: false,
|
|
69
|
-
|
|
69
|
+
reason: { issues: [{ code: 'invalid_format', format: 'nsid' }] },
|
|
70
70
|
})
|
|
71
71
|
})
|
|
72
72
|
|
|
@@ -83,7 +83,7 @@ describe('lexiconDocumentSchema', () => {
|
|
|
83
83
|
}),
|
|
84
84
|
).toMatchObject({
|
|
85
85
|
success: false,
|
|
86
|
-
|
|
86
|
+
reason: { issues: [{ code: 'invalid_type', expected: ['string'] }] },
|
|
87
87
|
})
|
|
88
88
|
})
|
|
89
89
|
|
|
@@ -104,7 +104,7 @@ describe('lexiconDocumentSchema', () => {
|
|
|
104
104
|
}),
|
|
105
105
|
).toMatchObject({
|
|
106
106
|
success: false,
|
|
107
|
-
|
|
107
|
+
reason: {
|
|
108
108
|
issues: [{ code: 'custom', path: ['defs', 'demo', 'required'] }],
|
|
109
109
|
},
|
|
110
110
|
})
|
|
@@ -160,7 +160,7 @@ describe('LexiconSchemaBuilder', () => {
|
|
|
160
160
|
|
|
161
161
|
expect(schema.safeParse(value)).toMatchObject({
|
|
162
162
|
success: false,
|
|
163
|
-
|
|
163
|
+
reason: {
|
|
164
164
|
issues: [
|
|
165
165
|
{
|
|
166
166
|
code: 'invalid_value',
|
|
@@ -231,7 +231,7 @@ describe('LexiconSchemaBuilder', () => {
|
|
|
231
231
|
|
|
232
232
|
expect(schema.safeParse(value)).toMatchObject({
|
|
233
233
|
success: false,
|
|
234
|
-
|
|
234
|
+
reason: { issues: [{ code: 'required_key', key: 'array' }] },
|
|
235
235
|
})
|
|
236
236
|
})
|
|
237
237
|
|
|
@@ -161,7 +161,7 @@ export class LexiconSchemaBuilder {
|
|
|
161
161
|
return l.subscription(
|
|
162
162
|
doc.id,
|
|
163
163
|
this.compileParams(doc, def.parameters),
|
|
164
|
-
this.compilePayloadSchema(doc, def.message
|
|
164
|
+
this.compilePayloadSchema(doc, def.message.schema),
|
|
165
165
|
this.compileErrors(doc, def.errors),
|
|
166
166
|
)
|
|
167
167
|
case 'token':
|
|
@@ -301,9 +301,8 @@ export class LexiconSchemaBuilder {
|
|
|
301
301
|
|
|
302
302
|
protected compilePayloadSchema(
|
|
303
303
|
doc: LexiconDocument,
|
|
304
|
-
def
|
|
304
|
+
def: LexiconObject | LexiconRef | LexiconRefUnion,
|
|
305
305
|
) {
|
|
306
|
-
if (!def) return undefined
|
|
307
306
|
switch (def.type) {
|
|
308
307
|
case 'object':
|
|
309
308
|
return this.compileObject(doc, def)
|