@atproto/lex-document 0.0.6 → 0.0.8
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 +16 -0
- package/dist/lexicon-schema-builder.d.ts.map +1 -1
- package/dist/lexicon-schema-builder.js +32 -28
- package/dist/lexicon-schema-builder.js.map +1 -1
- package/package.json +7 -7
- package/src/lexicon-document.test.ts +1 -0
- package/src/lexicon-schema-builder.test.ts +1 -0
- package/src/lexicon-schema-builder.ts +33 -25
- package/tsconfig.tests.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atproto/lex-document
|
|
2
2
|
|
|
3
|
+
## 0.0.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`2f78893`](https://github.com/bluesky-social/atproto/commit/2f78893ace3bbf14d4bac36837820ddb46658c98)]:
|
|
8
|
+
- @atproto/lex-schema@0.0.7
|
|
9
|
+
|
|
10
|
+
## 0.0.7
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#4443](https://github.com/bluesky-social/atproto/pull/4443) [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Ensure that default values match constraints
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c)]:
|
|
17
|
+
- @atproto/lex-schema@0.0.6
|
|
18
|
+
|
|
3
19
|
## 0.0.6
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -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,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;WAanB,QAAQ,CAAC,OAAO,EAAE,cAAc;gBA6BvB,OAAO,EAAE,cAAc;IAEvC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,YAAY,YAA2B,MAAM;;;;+BAM3C;IAEF,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;IAkBrE,SAAS,CAAC,mBAAmB,CAC3B,OAAO,EAAE,MAAM,GACd,MAAM,CAAC,CAAC,iBAAiB,GAAG,CAAC,CAAC,YAAY;IAqB7C,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe,EAAE,IAA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,CAAC,SAAS,CAAC,OAAO,CAAC;IAkEvB,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"}
|
|
@@ -128,41 +128,45 @@ class LexiconSchemaBuilder {
|
|
|
128
128
|
switch (def.type) {
|
|
129
129
|
case 'string': {
|
|
130
130
|
const schema = lex_schema_1.l.string(def);
|
|
131
|
-
if (def.
|
|
132
|
-
schema.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
if (def.default != null)
|
|
132
|
+
schema.check(def.default);
|
|
133
|
+
if (def.const != null)
|
|
134
|
+
schema.check(def.const);
|
|
135
|
+
if (def.enum != null)
|
|
136
136
|
for (const v of def.enum)
|
|
137
|
-
schema.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
schema.check(v);
|
|
138
|
+
const result = def.const != null
|
|
139
|
+
? lex_schema_1.l.literal(def.const, def)
|
|
140
|
+
: def.enum != null
|
|
141
|
+
? lex_schema_1.l.enum(def.enum, def)
|
|
142
|
+
: schema;
|
|
143
|
+
if (def.default != null)
|
|
144
|
+
result.check(def.default);
|
|
145
|
+
return result;
|
|
143
146
|
}
|
|
144
147
|
case 'integer': {
|
|
145
148
|
const schema = lex_schema_1.l.integer(def);
|
|
146
|
-
if (def.
|
|
147
|
-
schema.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
if (def.default != null)
|
|
150
|
+
schema.check(def.default);
|
|
151
|
+
if (def.const != null)
|
|
152
|
+
schema.check(def.const);
|
|
153
|
+
if (def.enum != null)
|
|
151
154
|
for (const v of def.enum)
|
|
152
|
-
schema.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
schema.check(v);
|
|
156
|
+
const result = def.const != null
|
|
157
|
+
? lex_schema_1.l.literal(def.const, def)
|
|
158
|
+
: def.enum != null
|
|
159
|
+
? lex_schema_1.l.enum(def.enum, def)
|
|
160
|
+
: schema;
|
|
161
|
+
if (def.default != null)
|
|
162
|
+
result.check(def.default);
|
|
163
|
+
return result;
|
|
158
164
|
}
|
|
159
165
|
case 'boolean': {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return lex_schema_1.l.boolean(def);
|
|
165
|
-
}
|
|
166
|
+
const result = def.const != null ? lex_schema_1.l.literal(def.const, def) : lex_schema_1.l.boolean(def);
|
|
167
|
+
if (def.default != null)
|
|
168
|
+
result.check(def.default);
|
|
169
|
+
return result;
|
|
166
170
|
}
|
|
167
171
|
case 'blob':
|
|
168
172
|
return lex_schema_1.l.blob(def);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-schema-builder.js","sourceRoot":"","sources":["../src/lexicon-schema-builder.ts"],"names":[],"mappings":";;;AAyXA,0BAQC;AAjYD,oDAA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,CAAA;IACvD,IAAI,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IACvE,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;IAChE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AACvB,CAAC;AAED,SAAS,YAAY,CAAC,IAAqB,EAAE,GAAW;IACtD,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,EAAE,CAAA;IAClD,OAAO,GAAG,CAAA;AACZ,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"]}
|
|
1
|
+
{"version":3,"file":"lexicon-schema-builder.js","sourceRoot":"","sources":["../src/lexicon-schema-builder.ts"],"names":[],"mappings":";;;AAiYA,0BAQC;AAzYD,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,MAAM,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ACvB,CAAC;AAED,SAAS,YAAY,CAAC,IAAqB,EAAE,GAAW;IACtD,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,EAAE,CAAA;IAClD,OAAO,GAAG,CAAA;AACZ,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.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, def)\n : def.enum != null\n ? l.enum(def.enum, def)\n : schema\n\n if (def.default != null) result.check(def.default)\n return 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, def)\n : def.enum != null\n ? l.enum(def.enum, def)\n : schema\n\n if (def.default != null) result.check(def.default)\n return result\n }\n case 'boolean': {\n const result =\n def.const != null ? l.literal(def.const, def) : l.boolean(def)\n\n if (def.default != null) result.check(def.default)\n return result\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.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Lexicon document validation tools for AT",
|
|
6
6
|
"keywords": [
|
|
@@ -29,23 +29,23 @@
|
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
32
33
|
"browser": "./dist/index.js",
|
|
33
34
|
"import": "./dist/index.js",
|
|
34
|
-
"require": "./dist/index.js"
|
|
35
|
-
"types": "./dist/index.d.ts"
|
|
35
|
+
"require": "./dist/index.js"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
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.7"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"
|
|
45
|
-
"@atproto/lex-data": "0.0.
|
|
44
|
+
"vitest": "^4.0.16",
|
|
45
|
+
"@atproto/lex-data": "0.0.6"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsc --build tsconfig.build.json",
|
|
49
|
-
"test": "
|
|
49
|
+
"test": "vitest run"
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -191,35 +191,43 @@ export class LexiconSchemaBuilder {
|
|
|
191
191
|
|
|
192
192
|
switch (def.type) {
|
|
193
193
|
case 'string': {
|
|
194
|
-
const schema
|
|
195
|
-
if (def.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
194
|
+
const schema = l.string(def)
|
|
195
|
+
if (def.default != null) schema.check(def.default)
|
|
196
|
+
if (def.const != null) schema.check(def.const)
|
|
197
|
+
if (def.enum != null) for (const v of def.enum) schema.check(v)
|
|
198
|
+
|
|
199
|
+
const result =
|
|
200
|
+
def.const != null
|
|
201
|
+
? l.literal(def.const, def)
|
|
202
|
+
: def.enum != null
|
|
203
|
+
? l.enum(def.enum, def)
|
|
204
|
+
: schema
|
|
205
|
+
|
|
206
|
+
if (def.default != null) result.check(def.default)
|
|
207
|
+
return result
|
|
204
208
|
}
|
|
205
209
|
case 'integer': {
|
|
206
|
-
const schema
|
|
207
|
-
if (def.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
210
|
+
const schema = l.integer(def)
|
|
211
|
+
if (def.default != null) schema.check(def.default)
|
|
212
|
+
if (def.const != null) schema.check(def.const)
|
|
213
|
+
if (def.enum != null) for (const v of def.enum) schema.check(v)
|
|
214
|
+
|
|
215
|
+
const result =
|
|
216
|
+
def.const != null
|
|
217
|
+
? l.literal(def.const, def)
|
|
218
|
+
: def.enum != null
|
|
219
|
+
? l.enum(def.enum, def)
|
|
220
|
+
: schema
|
|
221
|
+
|
|
222
|
+
if (def.default != null) result.check(def.default)
|
|
223
|
+
return result
|
|
216
224
|
}
|
|
217
225
|
case 'boolean': {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
226
|
+
const result =
|
|
227
|
+
def.const != null ? l.literal(def.const, def) : l.boolean(def)
|
|
228
|
+
|
|
229
|
+
if (def.default != null) result.check(def.default)
|
|
230
|
+
return result
|
|
223
231
|
}
|
|
224
232
|
case 'blob':
|
|
225
233
|
return l.blob(def)
|
package/tsconfig.tests.json
CHANGED