@atproto/lex-builder 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 CHANGED
@@ -1,5 +1,27 @@
1
1
  # @atproto/lex-builder
2
2
 
3
+ ## 0.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4443](https://github.com/bluesky-social/atproto/pull/4443) [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Use `jsonPayload` for json payloads
8
+
9
+ - 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), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c)]:
10
+ - @atproto/lex-schema@0.0.6
11
+ - @atproto/lex-document@0.0.7
12
+
13
+ ## 0.0.7
14
+
15
+ ### Patch Changes
16
+
17
+ - [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Refactor JSDoc generation to use ts-morph's native `JSDocStructure`
18
+
19
+ - [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Build additional `$lxm` utility variable for xrpc methods
20
+
21
+ - 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)]:
22
+ - @atproto/lex-schema@0.0.5
23
+ - @atproto/lex-document@0.0.6
24
+
3
25
  ## 0.0.6
4
26
 
5
27
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  import { SourceFile } from 'ts-morph';
2
- import { LexiconDocument, LexiconIndexer } from '@atproto/lex-document';
3
- import { RefResolverOptions } from './ref-resolver.js';
2
+ import { LexiconDocument, LexiconIndexer, LexiconProcedure, LexiconQuery, LexiconSubscription } from '@atproto/lex-document';
3
+ import { RefResolverOptions, ResolvedRef } from './ref-resolver.js';
4
4
  export type LexDefBuilderOptions = RefResolverOptions & {
5
5
  lib?: string;
6
6
  allowLegacyBlobs?: boolean;
@@ -23,6 +23,7 @@ export declare class LexDefBuilder {
23
23
  private addProcedure;
24
24
  private addQuery;
25
25
  private addSubscription;
26
+ addMethodTypeUtils(ref: ResolvedRef, def: LexiconProcedure | LexiconQuery | LexiconSubscription): void;
26
27
  private addRecord;
27
28
  private addObject;
28
29
  private addToken;
@@ -1 +1 @@
1
- {"version":3,"file":"lex-def-builder.d.ts","sourceRoot":"","sources":["../src/lex-def-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAA2B,MAAM,UAAU,CAAA;AAC9D,OAAO,EAOL,eAAe,EAEf,cAAc,EAef,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAEL,kBAAkB,EAGnB,MAAM,mBAAmB,CAAA;AAG1B,MAAM,MAAM,oBAAoB,GAAG,kBAAkB,GAAG;IACtD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED;;GAEG;AACH,qBAAa,aAAa;IAItB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG;IALtB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;gBAGtB,OAAO,EAAE,oBAAoB,EAC7B,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,eAAe,EACrC,OAAO,EAAE,cAAc;IAKzB,OA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pure(`${ref.varName}.nsid`),
122
124
  $params: this.pure(`${ref.varName}.parameters`),
123
125
  $input: this.pure(`${ref.varName}.input`),
124
126
  $output: this.pure(`${ref.varName}.output`),
125
127
  });
126
- const parametersTypeStmt = this.file.addTypeAlias({
127
- isExported: true,
128
- name: 'Params',
129
- type: `l.InferProcedureParameters<typeof ${ref.varName}>`,
130
- });
131
- addJsDoc(parametersTypeStmt, def.parameters);
132
- const inputTypeStmt = this.file.addTypeAlias({
133
- isExported: true,
134
- name: 'Input',
135
- type: `l.InferProcedureInputBody<typeof ${ref.varName}>`,
136
- });
137
- addJsDoc(inputTypeStmt, def.input);
138
- const outputTypeStmt = this.file.addTypeAlias({
139
- isExported: true,
140
- name: 'Output',
141
- type: `l.InferProcedureOutputBody<typeof ${ref.varName}>`,
142
- });
143
- addJsDoc(outputTypeStmt, def.output);
144
128
  }
145
129
  async addQuery(hash, def) {
146
130
  if (hash !== 'main') {
@@ -157,20 +141,12 @@ class LexDefBuilder {
157
141
  )
158
142
  `),
159
143
  });
144
+ this.addMethodTypeUtils(ref, def);
160
145
  this.addUtils({
146
+ $lxm: this.pure(`${ref.varName}.nsid`),
161
147
  $params: `${ref.varName}.parameters`,
162
148
  $output: `${ref.varName}.output`,
163
149
  });
164
- this.file.addTypeAlias({
165
- isExported: true,
166
- name: 'Params',
167
- type: `l.InferQueryParameters<typeof ${ref.varName}>`,
168
- });
169
- this.file.addTypeAlias({
170
- isExported: true,
171
- name: 'Output',
172
- type: `l.InferQueryOutputBody<typeof ${ref.varName}>`,
173
- });
174
150
  }
175
151
  async addSubscription(hash, def) {
176
152
  if (hash !== 'main') {
@@ -187,20 +163,56 @@ class LexDefBuilder {
187
163
  )
188
164
  `),
189
165
  });
166
+ this.addMethodTypeUtils(ref, def);
190
167
  this.addUtils({
168
+ $lxm: this.pure(`${ref.varName}.nsid`),
191
169
  $params: `${ref.varName}.parameters`,
192
170
  $message: `${ref.varName}.message`,
193
171
  });
172
+ }
173
+ addMethodTypeUtils(ref, def) {
194
174
  this.file.addTypeAlias({
195
175
  isExported: true,
196
176
  name: 'Params',
197
- type: `l.InferSubscriptionParameters<typeof ${ref.varName}>`,
198
- });
199
- this.file.addTypeAlias({
200
- isExported: true,
201
- name: 'Message',
202
- type: `l.InferSubscriptionMessage<typeof ${ref.varName}>`,
177
+ type: `l.InferMethodParams<typeof ${ref.varName}>`,
178
+ docs: compileDocs(def.parameters?.description),
203
179
  });
180
+ if (def.type === 'procedure') {
181
+ this.file.addTypeAlias({
182
+ isExported: true,
183
+ name: 'Input',
184
+ type: `l.InferMethodInput<typeof ${ref.varName}>`,
185
+ docs: compileDocs(def.input?.description),
186
+ });
187
+ this.file.addTypeAlias({
188
+ isExported: true,
189
+ name: 'InputBody',
190
+ type: `l.InferMethodInputBody<typeof ${ref.varName}>`,
191
+ docs: compileDocs(def.input?.description),
192
+ });
193
+ }
194
+ if (def.type === 'procedure' || def.type === 'query') {
195
+ this.file.addTypeAlias({
196
+ isExported: true,
197
+ name: 'Output',
198
+ type: `l.InferMethodOutput<typeof ${ref.varName}>`,
199
+ docs: compileDocs(def.output?.description),
200
+ });
201
+ this.file.addTypeAlias({
202
+ isExported: true,
203
+ name: 'OutputBody',
204
+ type: `l.InferMethodOutputBody<typeof ${ref.varName}>`,
205
+ docs: compileDocs(def.output?.description),
206
+ });
207
+ }
208
+ if (def.type === 'subscription') {
209
+ this.file.addTypeAlias({
210
+ isExported: true,
211
+ name: 'Message',
212
+ type: `l.InferSubscriptionMessage<typeof ${ref.varName}>`,
213
+ docs: compileDocs(def.message?.description),
214
+ });
215
+ }
204
216
  }
205
217
  async addRecord(hash, def) {
206
218
  if (hash !== 'main') {
@@ -260,11 +272,11 @@ class LexDefBuilder {
260
272
  (0, node_assert_1.default)((0, ts_lang_js_1.isSafeIdentifier)(ref.typeName), 'Expected safe type identifier');
261
273
  (0, node_assert_1.default)((0, ts_lang_js_1.isSafeIdentifier)(pub.typeName), 'Expected safe type identifier');
262
274
  if (type) {
263
- const typeStmt = this.file.addTypeAlias({
275
+ this.file.addTypeAlias({
264
276
  name: ref.typeName,
265
277
  type: typeof type === 'function' ? type(ref) : type,
278
+ docs: compileDocs(def.description),
266
279
  });
267
- addJsDoc(typeStmt, def);
268
280
  this.file.addExportDeclaration({
269
281
  isTypeOnly: true,
270
282
  namedExports: [
@@ -276,7 +288,7 @@ class LexDefBuilder {
276
288
  });
277
289
  }
278
290
  if (schema) {
279
- const constStmt = this.file.addVariableStatement({
291
+ this.file.addVariableStatement({
280
292
  declarationKind: ts_morph_1.VariableDeclarationKind.Const,
281
293
  declarations: [
282
294
  {
@@ -284,8 +296,8 @@ class LexDefBuilder {
284
296
  initializer: typeof schema === 'function' ? schema(ref) : schema,
285
297
  },
286
298
  ],
299
+ docs: compileDocs(def.description),
287
300
  });
288
- addJsDoc(constStmt, def);
289
301
  this.file.addExportDeclaration({
290
302
  namedExports: [
291
303
  {
@@ -320,6 +332,11 @@ class LexDefBuilder {
320
332
  async compilePayload(def) {
321
333
  if (!def)
322
334
  return this.pure(`l.payload()`);
335
+ // Special case for JSON object payloads
336
+ if (def.encoding === 'application/json' && def.schema?.type === 'object') {
337
+ const properties = await this.compilePropertiesSchemas(def.schema);
338
+ return this.pure(`l.jsonPayload({${properties.join(',')}})`);
339
+ }
323
340
  const encodedEncoding = JSON.stringify(def.encoding);
324
341
  if (def.schema) {
325
342
  const bodySchema = await this.compileBodySchema(def.schema);
@@ -338,7 +355,7 @@ class LexDefBuilder {
338
355
  }
339
356
  async compileParamsSchema(def) {
340
357
  if (!def)
341
- return this.pure(`l.params({})`);
358
+ return this.pure(`l.params()`);
342
359
  const properties = await this.compilePropertiesSchemas(def);
343
360
  return this.pure(`l.params({${properties.join(',')}})`);
344
361
  }
@@ -664,42 +681,39 @@ function parseDescription(description) {
664
681
  if (/deprecated/i.test(description)) {
665
682
  const deprecationMatch = description.match(/(\s*deprecated\s*(?:--?|:)?\s*([^-]*)(?:-+)?)/i);
666
683
  if (deprecationMatch) {
667
- const [, match, deprecationNotice] = deprecationMatch;
684
+ const { 1: match, 2: deprecationNotice } = deprecationMatch;
668
685
  return {
669
- description: description.replace(match, '').trim(),
670
- deprecated: deprecationNotice?.trim() || true,
686
+ description: description.replace(match, '').trim() || undefined,
687
+ tags: [{ tagName: 'deprecated', text: deprecationNotice?.trim() }],
671
688
  };
672
689
  }
673
690
  else {
674
691
  return {
675
- description: description.trim(),
676
- deprecated: true,
692
+ description: description.trim() || undefined,
693
+ tags: [{ tagName: 'deprecated' }],
677
694
  };
678
695
  }
679
696
  }
680
697
  return {
681
- description: description.trim(),
682
- deprecated: false,
698
+ description: description.trim() || undefined,
683
699
  };
684
700
  }
685
701
  function compileLeadingTrivia(description) {
686
702
  if (!description)
687
703
  return undefined;
688
- return `\n\n/**${compileJsDoc(description).replaceAll('\n', '\n * ')}\n */\n`;
689
- }
690
- function addJsDoc(declaration, def) {
691
- if (def?.description) {
692
- declaration.addJsDoc(compileJsDoc(def.description));
693
- }
694
- }
695
- function compileJsDoc(description) {
696
704
  const parsed = parseDescription(description);
697
- return `\n${parsed.description}${!parsed.deprecated
698
- ? ''
699
- : (parsed.description ? '\n\n' : '') +
700
- (parsed.deprecated === true
701
- ? '@deprecated'
702
- : `@deprecated ${parsed.deprecated}`)}`;
705
+ if (!parsed.description && !parsed.tags?.length)
706
+ return undefined;
707
+ const tags = parsed.tags
708
+ ?.map(({ tagName, text }) => (text ? `@${tagName} ${text}` : `@${tagName}`))
709
+ ?.join('\n');
710
+ const text = `\n${[parsed.description, tags].filter(Boolean).join('\n\n')}`;
711
+ return `\n\n/**${text.replaceAll('\n', '\n * ')}\n */\n`;
712
+ }
713
+ function compileDocs(description) {
714
+ if (!description)
715
+ return undefined;
716
+ return [parseDescription(description)];
703
717
  }
704
718
  function stringifyOptions(obj, include, exclude) {
705
719
  const filtered = Object.entries(obj).filter(([k]) => (!include || include.includes(k)) && !exclude?.includes(k));
@@ -1 +1 @@
1
- {"version":3,"file":"lex-def-builder.js","sourceRoot":"","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AAM;IAEN,OAAO,GAAG,CAAC,IAAI,IAAI,IAAI,CAAA;AACzB,CAAC;AAED,SAAS,QAAQ,CAAmB,CAAI;IACtC,OAAO,iBAAiB,CAAC,EAAE,CAAA;AAC7B,CAAC","sourcesContent":["import assert from 'node:assert'\nimport { SourceFile, VariableDeclarationKind } from 'ts-morph'\nimport {\n LexiconArray,\n LexiconArrayItems,\n LexiconBlob,\n LexiconBoolean,\n LexiconBytes,\n LexiconCid,\n LexiconDocument,\n LexiconError,\n LexiconIndexer,\n LexiconInteger,\n LexiconObject,\n LexiconParameters,\n LexiconPayload,\n LexiconPermissionSet,\n LexiconProcedure,\n LexiconQuery,\n LexiconRecord,\n LexiconRef,\n LexiconRefUnion,\n LexiconString,\n LexiconSubscription,\n LexiconToken,\n LexiconUnknown,\n} from '@atproto/lex-document'\nimport { l } from '@atproto/lex-schema'\nimport {\n RefResolver,\n RefResolverOptions,\n ResolvedRef,\n getPublicIdentifiers,\n} from './ref-resolver.js'\nimport { isSafeIdentifier } from './ts-lang.js'\n\nexport type LexDefBuilderOptions = RefResolverOptions & {\n lib?: string\n allowLegacyBlobs?: boolean\n pureAnnotations?: boolean\n}\n\n/**\n * Utility class to build a TypeScript source file from a lexicon document.\n */\nexport class LexDefBuilder {\n private readonly refResolver: RefResolver\n\n constructor(\n private readonly options: LexDefBuilderOptions,\n private readonly file: SourceFile,\n private readonly doc: LexiconDocument,\n indexer: LexiconIndexer,\n ) {\n this.refResolver = new RefResolver(doc, file, indexer, options)\n }\n\n private pure(code: string) {\n return this.options.pureAnnotations ? markPure(code) : code\n }\n\n async build() {\n this.file.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n { name: '$nsid', initializer: JSON.stringify(this.doc.id) },\n ],\n })\n\n this.file.addExportDeclaration({\n namedExports: [{ name: '$nsid' }],\n })\n\n const defs = Object.keys(this.doc.defs)\n if (defs.length) {\n const moduleSpecifier = this.options?.lib ?? '@atproto/lex-schema'\n this.file\n .addImportDeclaration({ moduleSpecifier })\n .addNamedImports([{ name: 'l' }])\n\n for (const hash of defs) {\n await this.addDef(hash)\n }\n }\n }\n\n private addUtils(definitions: Record<string, undefined | string>) {\n const entries = Object.entries(definitions).filter(\n (e): e is [(typeof e)[0], NonNullable<(typeof e)[1]>] => e[1] != null,\n )\n if (entries.length) {\n this.file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: entries.map(([name, initializer]) => ({\n name,\n initializer,\n })),\n })\n }\n }\n\n private async addDef(hash: string) {\n const def = Object.hasOwn(this.doc.defs, hash) ? this.doc.defs[hash] : null\n if (def == null) return\n\n switch (def.type) {\n case 'permission-set':\n return this.addPermissionSet(hash, def)\n case 'procedure':\n return this.addProcedure(hash, def)\n case 'query':\n return this.addQuery(hash, def)\n case 'subscription':\n return this.addSubscription(hash, def)\n case 'record':\n return this.addRecord(hash, def)\n case 'token':\n return this.addToken(hash, def)\n case 'object':\n return this.addObject(hash, def)\n case 'array':\n return this.addArray(hash, def)\n default:\n await this.addSchema(hash, def, {\n type: await this.compileContainedType(def),\n schema: await this.compileContainedSchema(def),\n validationUtils: true,\n })\n }\n }\n\n private async addPermissionSet(hash: string, def: LexiconPermissionSet) {\n const permission = def.permissions.map((def) => {\n const options = stringifyOptions(def, undefined, ['resource', 'type'])\n return this.pure(\n `l.permission(${JSON.stringify(def.resource)}, ${options})`,\n )\n })\n\n const options = stringifyOptions(def, [\n 'title',\n 'title:lang',\n 'detail',\n 'detail:lang',\n ] satisfies (keyof l.PermissionSetOptions)[])\n\n await this.addSchema(hash, def, {\n schema: this.pure(\n `l.permissionSet($nsid, [${permission.join(',')}], ${options})`,\n ),\n })\n }\n\n private async addProcedure(hash: string, def: LexiconProcedure) {\n if (hash !== 'main') {\n throw new Error(`Definition ${hash} cannot be of type ${def.type}`)\n }\n\n // @TODO Build the types instead of using an inferred type.\n\n const ref = await this.addSchema(hash, def, {\n schema: this.pure(`\n l.procedure(\n $nsid,\n ${await this.compileParamsSchema(def.parameters)},\n ${await this.compilePayload(def.input)},\n ${await this.compilePayload(def.output)},\n ${await this.compileErrors(def.errors)}\n )\n `),\n })\n\n this.addUtils({\n $params: this.pure(`${ref.varName}.parameters`),\n $input: this.pure(`${ref.varName}.input`),\n $output: this.pure(`${ref.varName}.output`),\n })\n\n const parametersTypeStmt = this.file.addTypeAlias({\n isExported: true,\n name: 'Params',\n type: `l.InferProcedureParameters<typeof ${ref.varName}>`,\n })\n\n addJsDoc(parametersTypeStmt, def.parameters)\n\n const inputTypeStmt = this.file.addTypeAlias({\n isExported: true,\n name: 'Input',\n type: `l.InferProcedureInputBody<typeof ${ref.varName}>`,\n })\n\n addJsDoc(inputTypeStmt, def.input)\n\n const outputTypeStmt = this.file.addTypeAlias({\n isExported: true,\n name: 'Output',\n type: `l.InferProcedureOutputBody<typeof ${ref.varName}>`,\n })\n\n addJsDoc(outputTypeStmt, def.output)\n }\n\n private async addQuery(hash: string, def: LexiconQuery) {\n if (hash !== 'main') {\n throw new Error(`Definition ${hash} cannot be of type ${def.type}`)\n }\n\n // @TODO Build the types instead of using an inferred type.\n\n const ref = await this.addSchema(hash, def, {\n schema: this.pure(`\n l.query(\n $nsid,\n ${await this.compileParamsSchema(def.parameters)},\n ${await this.compilePayload(def.output)},\n ${await this.compileErrors(def.errors)}\n )\n `),\n })\n\n this.addUtils({\n $params: `${ref.varName}.parameters`,\n $output: `${ref.varName}.output`,\n })\n\n this.file.addTypeAlias({\n isExported: true,\n name: 'Params',\n type: `l.InferQueryParameters<typeof ${ref.varName}>`,\n })\n\n this.file.addTypeAlias({\n isExported: true,\n name: 'Output',\n type: `l.InferQueryOutputBody<typeof ${ref.varName}>`,\n })\n }\n\n private async addSubscription(hash: string, def: LexiconSubscription) {\n if (hash !== 'main') {\n throw new Error(`Definition ${hash} cannot be of type ${def.type}`)\n }\n\n // @TODO Build the types instead of using an inferred type.\n\n const ref = await this.addSchema(hash, def, {\n schema: this.pure(`\n l.subscription(\n $nsid,\n ${await this.compileParamsSchema(def.parameters)},\n ${await this.compileBodySchema(def.message?.schema)},\n ${await this.compileErrors(def.errors)}\n )\n `),\n })\n\n this.addUtils({\n $params: `${ref.varName}.parameters`,\n $message: `${ref.varName}.message`,\n })\n\n this.file.addTypeAlias({\n isExported: true,\n name: 'Params',\n type: `l.InferSubscriptionParameters<typeof ${ref.varName}>`,\n })\n\n this.file.addTypeAlias({\n isExported: true,\n name: 'Message',\n type: `l.InferSubscriptionMessage<typeof ${ref.varName}>`,\n })\n }\n\n private async addRecord(hash: string, def: LexiconRecord) {\n if (hash !== 'main') {\n throw new Error(`Definition ${hash} cannot be of type ${def.type}`)\n }\n\n const key = JSON.stringify(def.key ?? 'any')\n const objectSchema = await this.compileObjectSchema(def.record)\n\n const properties = await this.compilePropertiesTypes(def.record)\n properties.unshift(`$type: ${JSON.stringify(l.$type(this.doc.id, hash))}`)\n\n await this.addSchema(hash, def, {\n type: `{ ${properties.join(';')} }`,\n schema: (ref) =>\n this.pure(\n `l.record<${key}, ${ref.typeName}>(${key}, $nsid, ${objectSchema})`,\n ),\n objectUtils: true,\n validationUtils: true,\n })\n }\n\n private async addObject(hash: string, def: LexiconObject) {\n const objectSchema = await this.compileObjectSchema(def)\n\n const properties = await this.compilePropertiesTypes(def)\n properties.unshift(`$type?: ${JSON.stringify(l.$type(this.doc.id, hash))}`)\n\n await this.addSchema(hash, def, {\n type: `{ ${properties.join(';')} }`,\n schema: (ref) =>\n this.pure(\n `l.typedObject<${ref.typeName}>($nsid, ${JSON.stringify(hash)}, ${objectSchema})`,\n ),\n objectUtils: true,\n validationUtils: true,\n })\n }\n\n private async addToken(hash: string, def: LexiconToken) {\n await this.addSchema(hash, def, {\n schema: this.pure(`l.token($nsid, ${JSON.stringify(hash)})`),\n type: JSON.stringify(l.$type(this.doc.id, hash)),\n validationUtils: true,\n })\n }\n\n private async addArray(hash: string, def: LexiconArray) {\n // @TODO It could be nice to expose the array item type as a separate type.\n // This was not done (yet) as there is no easy way to name it to avoid\n // collisions.\n\n const itemSchema = await this.compileContainedSchema(def.items)\n const options = stringifyOptions(def, [\n 'minLength',\n 'maxLength',\n ] satisfies (keyof l.ArraySchemaOptions)[])\n\n await this.addSchema(hash, def, {\n type: `(${await this.compileContainedType(def.items)})[]`,\n // @NOTE Not using compileArraySchema to allow specifying the generic\n // parameter to l.array<>.\n schema: (ref) =>\n this.pure(\n `l.array<${ref.typeName}[number]>(${itemSchema}, ${options})`,\n ),\n validationUtils: true,\n })\n }\n\n private async addSchema(\n hash: string,\n def: { description?: string },\n {\n type,\n schema,\n objectUtils,\n validationUtils,\n }: {\n type?: string | ((ref: ResolvedRef) => string)\n schema?: string | ((ref: ResolvedRef) => string)\n objectUtils?: boolean\n validationUtils?: boolean\n },\n ): Promise<ResolvedRef> {\n const ref = await this.refResolver.resolveLocal(hash)\n const pub = getPublicIdentifiers(hash)\n\n // Fool-proofing\n assert(isSafeIdentifier(ref.varName), 'Expected safe type identifier')\n assert(isSafeIdentifier(ref.typeName), 'Expected safe type identifier')\n assert(isSafeIdentifier(pub.typeName), 'Expected safe type identifier')\n\n if (type) {\n const typeStmt = this.file.addTypeAlias({\n name: ref.typeName,\n type: typeof type === 'function' ? type(ref) : type,\n })\n\n addJsDoc(typeStmt, def)\n\n this.file.addExportDeclaration({\n isTypeOnly: true,\n namedExports: [\n {\n name: ref.typeName,\n alias: ref.typeName === pub.typeName ? undefined : pub.typeName,\n },\n ],\n })\n }\n\n if (schema) {\n const constStmt = this.file.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: ref.varName,\n initializer: typeof schema === 'function' ? schema(ref) : schema,\n },\n ],\n })\n\n addJsDoc(constStmt, def)\n\n this.file.addExportDeclaration({\n namedExports: [\n {\n name: ref.varName,\n alias:\n ref.varName === pub.varName\n ? undefined\n : isSafeIdentifier(pub.varName)\n ? pub.varName\n : JSON.stringify(pub.varName),\n },\n ],\n })\n }\n\n if (hash === 'main' && objectUtils) {\n this.addUtils({\n $isTypeOf: markPure(`${ref.varName}.isTypeOf.bind(${ref.varName})`),\n $build: markPure(`${ref.varName}.build.bind(${ref.varName})`),\n $type: markPure(`${ref.varName}.$type`),\n })\n }\n\n if (hash === 'main' && validationUtils) {\n this.addUtils({\n $assert: markPure(`${ref.varName}.assert.bind(${ref.varName})`),\n $ifMatches: markPure(`${ref.varName}.ifMatches.bind(${ref.varName})`),\n $matches: markPure(`${ref.varName}.matches.bind(${ref.varName})`),\n $parse: markPure(`${ref.varName}.parse.bind(${ref.varName})`),\n $safeParse: markPure(`${ref.varName}.safeParse.bind(${ref.varName})`),\n })\n }\n\n return ref\n }\n\n private async compilePayload(def: LexiconPayload | undefined) {\n if (!def) return this.pure(`l.payload()`)\n\n const encodedEncoding = JSON.stringify(def.encoding)\n if (def.schema) {\n const bodySchema = await this.compileBodySchema(def.schema)\n return this.pure(`l.payload(${encodedEncoding}, ${bodySchema})`)\n } else {\n return this.pure(`l.payload(${encodedEncoding})`)\n }\n }\n\n private async compileBodySchema(\n def?: LexiconRef | LexiconRefUnion | LexiconObject,\n ): Promise<string> {\n if (!def) return 'undefined'\n if (def.type === 'object') return this.compileObjectSchema(def)\n return this.compileContainedSchema(def)\n }\n\n private async compileParamsSchema(def: undefined | LexiconParameters) {\n if (!def) return this.pure(`l.params({})`)\n\n const properties = await this.compilePropertiesSchemas(def)\n return this.pure(`l.params({${properties.join(',')}})`)\n }\n\n private async compileErrors(defs?: readonly LexiconError[]) {\n if (!defs?.length) return ''\n return JSON.stringify(defs.map((d) => d.name))\n }\n\n private async compileObjectSchema(def: LexiconObject): Promise<string> {\n const properties = await this.compilePropertiesSchemas(def)\n return this.pure(`l.object({${properties.join(',')}})`)\n }\n\n private async compilePropertiesSchemas(options: {\n properties: Record<string, LexiconArray | LexiconArrayItems>\n required?: readonly string[]\n nullable?: readonly string[]\n }): Promise<string[]> {\n for (const opt of ['required', 'nullable'] as const) {\n if (options[opt]) {\n for (const prop of options[opt]) {\n if (!Object.hasOwn(options.properties, prop)) {\n throw new Error(`No schema found for ${opt} property \"${prop}\"`)\n }\n }\n }\n }\n\n return Promise.all(\n Object.entries(options.properties).map((entry) => {\n return this.compilePropertyEntrySchema(entry, options)\n }),\n )\n }\n\n private async compilePropertiesTypes(options: {\n properties: Record<string, LexiconArray | LexiconArrayItems>\n required?: readonly string[]\n nullable?: readonly string[]\n }) {\n return Promise.all(\n Object.entries(options.properties).map((entry) => {\n return this.compilePropertyEntryType(entry, options)\n }),\n )\n }\n\n private async compilePropertyEntrySchema(\n [key, def]: [string, LexiconArray | LexiconArrayItems],\n options: {\n required?: readonly string[]\n nullable?: readonly string[]\n },\n ) {\n const isNullable = options.nullable?.includes(key)\n const isRequired = options.required?.includes(key)\n\n let schema = await this.compileContainedSchema(def)\n\n if (isNullable) {\n schema = this.pure(`l.nullable(${schema})`)\n }\n\n if (!isRequired) {\n schema = this.pure(`l.optional(${schema})`)\n }\n\n return `${JSON.stringify(key)}:${schema}`\n }\n\n private async compilePropertyEntryType(\n [key, def]: [string, LexiconArray | LexiconArrayItems],\n options: {\n required?: readonly string[]\n nullable?: readonly string[]\n },\n ) {\n const isNullable = options.nullable?.includes(key)\n const isRequired = options.required?.includes(key)\n\n const optional = isRequired ? '' : '?'\n const append = isNullable ? ' | null' : ''\n\n const jsDoc = compileLeadingTrivia(def.description) || ''\n const name = JSON.stringify(key)\n const type = await this.compileContainedType(def)\n\n return `${jsDoc}${name}${optional}:${type}${append}`\n }\n\n private async compileContainedSchema(\n def: LexiconArray | LexiconArrayItems,\n ): Promise<string> {\n switch (def.type) {\n case 'unknown':\n return this.compileUnknownSchema(def)\n case 'boolean':\n return this.compileBooleanSchema(def)\n case 'integer':\n return this.compileIntegerSchema(def)\n case 'string':\n return this.compileStringSchema(def)\n case 'bytes':\n return this.compileBytesSchema(def)\n case 'blob':\n return this.compileBlobSchema(def)\n case 'cid-link':\n return this.compileCidLinkSchema(def)\n case 'ref':\n return this.compileRefSchema(def)\n case 'union':\n return this.compileRefUnionSchema(def)\n case 'array':\n return this.compileArraySchema(def)\n default:\n // @ts-expect-error\n throw new Error(`Unsupported def type: ${def.type}`)\n }\n }\n\n private async compileContainedType(\n def: LexiconArray | LexiconArrayItems,\n ): Promise<string> {\n switch (def.type) {\n case 'unknown':\n return this.compileUnknownType(def)\n case 'boolean':\n return this.compileBooleanType(def)\n case 'integer':\n return this.compileIntegerType(def)\n case 'string':\n return this.compileStringType(def)\n case 'bytes':\n return this.compileBytesType(def)\n case 'blob':\n return this.compileBlobType(def)\n case 'cid-link':\n return this.compileCidLinkType(def)\n case 'ref':\n return this.compileRefType(def)\n case 'union':\n return this.compileRefUnionType(def)\n case 'array':\n return this.compileArrayType(def)\n default:\n // @ts-expect-error\n throw new Error(`Unsupported def type: ${def.type}`)\n }\n }\n\n private async compileArraySchema(def: LexiconArray): Promise<string> {\n const itemSchema = await this.compileContainedSchema(def.items)\n const options = stringifyOptions(def, [\n 'minLength',\n 'maxLength',\n ] satisfies (keyof l.ArraySchemaOptions)[])\n return this.pure(`l.array(${itemSchema}, ${options})`)\n }\n\n private async compileArrayType(def: LexiconArray): Promise<string> {\n return `(${await this.compileContainedType(def.items)})[]`\n }\n\n private async compileUnknownSchema(_def: LexiconUnknown): Promise<string> {\n return this.pure(`l.unknownObject()`)\n }\n\n private async compileUnknownType(_def: LexiconUnknown): Promise<string> {\n return `l.UnknownObject`\n }\n\n private async compileBooleanSchema(def: LexiconBoolean): Promise<string> {\n if (hasConst(def)) return this.compileConstSchema(def)\n\n const options = stringifyOptions(def, [\n 'default',\n ] satisfies (keyof l.BooleanSchemaOptions)[])\n return this.pure(`l.boolean(${options})`)\n }\n\n private async compileBooleanType(def: LexiconBoolean): Promise<string> {\n if (hasConst(def)) return this.compileConstType(def)\n return 'boolean'\n }\n\n private async compileIntegerSchema(def: LexiconInteger): Promise<string> {\n if (hasConst(def)) {\n const schema: l.IntegerSchema = l.integer(def)\n schema.assert(def.const)\n }\n\n if (hasEnum(def)) {\n const schema: l.IntegerSchema = l.integer(def)\n for (const val of def.enum) schema.assert(val)\n }\n\n if (hasConst(def)) return this.compileConstSchema(def)\n if (hasEnum(def)) return this.compileEnumSchema(def)\n\n const options = stringifyOptions(def, [\n 'default',\n 'maximum',\n 'minimum',\n ] satisfies (keyof l.IntegerSchemaOptions)[])\n return this.pure(`l.integer(${options})`)\n }\n\n private async compileIntegerType(def: LexiconInteger): Promise<string> {\n if (hasConst(def)) return this.compileConstType(def)\n if (hasEnum(def)) return this.compileEnumType(def)\n\n return 'number'\n }\n\n private async compileStringSchema(def: LexiconString): Promise<string> {\n if (hasConst(def)) {\n const schema: l.StringSchema = l.string(def)\n schema.assert(def.const)\n } else if (hasEnum(def)) {\n const schema: l.StringSchema = l.string(def)\n for (const val of def.enum) schema.assert(val)\n }\n\n if (hasConst(def)) return this.compileConstSchema(def)\n if (hasEnum(def)) return this.compileEnumSchema(def)\n\n const options = stringifyOptions(def, [\n 'default',\n 'format',\n 'maxGraphemes',\n 'minGraphemes',\n 'maxLength',\n 'minLength',\n ] satisfies (keyof l.StringSchemaOptions)[])\n return this.pure(`l.string(${options})`)\n }\n\n private async compileStringType(def: LexiconString): Promise<string> {\n if (hasConst(def)) return this.compileConstType(def)\n if (hasEnum(def)) return this.compileEnumType(def)\n\n switch (def.format) {\n case undefined:\n break\n case 'datetime':\n return 'l.DatetimeString'\n case 'uri':\n return 'l.UriString'\n case 'at-uri':\n return 'l.AtUriString'\n case 'did':\n return 'l.DidString'\n case 'handle':\n return 'l.HandleString'\n case 'at-identifier':\n return 'l.AtIdentifierString'\n case 'nsid':\n return 'l.NsidString'\n case 'tid':\n return 'l.TidString'\n case 'cid':\n return 'l.CidString'\n case 'language':\n return 'l.LanguageString'\n case 'record-key':\n return 'l.RecordKeyString'\n default:\n throw new Error(`Unknown string format: ${def.format}`)\n }\n\n if (def.knownValues?.length) {\n return (\n def.knownValues.map((v) => JSON.stringify(v)).join(' | ') +\n ' | l.UnknownString'\n )\n }\n\n return 'string'\n }\n\n private async compileBytesSchema(def: LexiconBytes): Promise<string> {\n const options = stringifyOptions(def, [\n 'minLength',\n 'maxLength',\n ] satisfies (keyof l.BytesSchemaOptions)[])\n return this.pure(`l.bytes(${options})`)\n }\n\n private async compileBytesType(_def: LexiconBytes): Promise<string> {\n return 'Uint8Array'\n }\n\n private async compileBlobSchema(def: LexiconBlob): Promise<string> {\n const opts = { ...def, allowLegacy: this.options.allowLegacyBlobs === true }\n const options = stringifyOptions(opts, [\n 'maxSize',\n 'accept',\n 'allowLegacy',\n ] satisfies (keyof l.BlobSchemaOptions)[])\n return this.pure(`l.blob(${options})`)\n }\n\n private async compileBlobType(_def: LexiconBlob): Promise<string> {\n return this.options.allowLegacyBlobs\n ? 'l.BlobRef | l.LegacyBlobRef'\n : 'l.BlobRef'\n }\n\n private async compileCidLinkSchema(_def: LexiconCid): Promise<string> {\n return this.pure(`l.cidLink()`)\n }\n\n private async compileCidLinkType(_def: LexiconCid): Promise<string> {\n return 'l.Cid'\n }\n\n private async compileRefSchema(def: LexiconRef): Promise<string> {\n const { varName, typeName } = await this.refResolver.resolve(def.ref)\n // @NOTE \"as any\" is needed in schemas with circular refs as TypeScript\n // cannot infer the type of a value that depends on its initializer type\n return this.pure(`l.ref<${typeName}>((() => ${varName}) as any)`)\n }\n\n private async compileRefType(def: LexiconRef): Promise<string> {\n const ref = await this.refResolver.resolve(def.ref)\n return ref.typeName\n }\n\n private async compileRefUnionSchema(def: LexiconRefUnion): Promise<string> {\n if (def.refs.length === 0 && def.closed) {\n return this.pure(`l.never()`)\n }\n\n const refs = await Promise.all(\n def.refs.map(async (ref: string) => {\n const { varName, typeName } = await this.refResolver.resolve(ref)\n // @NOTE \"as any\" is needed in schemas with circular refs as TypeScript\n // cannot infer the type of a value that depends on its initializer type\n return this.pure(`l.typedRef<${typeName}>((() => ${varName}) as any)`)\n }),\n )\n\n return this.pure(\n `l.typedUnion([${refs.join(',')}], ${def.closed ?? false})`,\n )\n }\n\n private async compileRefUnionType(def: LexiconRefUnion): Promise<string> {\n const types = await Promise.all(\n def.refs.map(async (ref) => {\n const { typeName } = await this.refResolver.resolve(ref)\n return `l.TypedRef<${typeName}>`\n }),\n )\n if (!def.closed) types.push('l.TypedObject')\n return types.join(' | ') || 'never'\n }\n\n private async compileConstSchema<\n T extends null | number | string | boolean,\n >(def: { const: T; enum?: readonly T[]; default?: T }): Promise<string> {\n if (hasEnum(def) && !def.enum.includes(def.const)) {\n return this.pure(`l.never()`)\n }\n\n const options = stringifyOptions(def, [\n 'default',\n ] satisfies (keyof l.LiteralSchemaOptions<any>)[])\n return this.pure(`l.literal(${JSON.stringify(def.const)}, ${options})`)\n }\n\n private async compileConstType<\n T extends null | number | string | boolean,\n >(def: { const: T; enum?: readonly T[] }): Promise<string> {\n if (hasEnum(def) && !def.enum.includes(def.const)) {\n return 'never'\n }\n return JSON.stringify(def.const)\n }\n\n private async compileEnumSchema<T extends null | number | string>(def: {\n enum: readonly T[]\n default?: T\n }): Promise<string> {\n if (def.enum.length === 0) {\n return this.pure(`l.never()`)\n }\n if (def.enum.length === 1 && def.default === undefined) {\n return this.pure(`l.literal(${JSON.stringify(def.enum[0])})`)\n }\n const options = stringifyOptions(def, [\n 'default',\n ] satisfies (keyof l.EnumSchemaOptions<any>)[])\n return this.pure(`l.enum(${JSON.stringify(def.enum)}, ${options})`)\n }\n\n private async compileEnumType<T extends null | number | string>(def: {\n enum: readonly T[]\n }): Promise<string> {\n return def.enum.map((v) => JSON.stringify(v)).join(' | ') || 'never'\n }\n}\n\ntype ParsedDescription = {\n description: string\n deprecated: boolean | string\n}\n\nfunction parseDescription(description: string): ParsedDescription {\n if (/deprecated/i.test(description)) {\n const deprecationMatch = description.match(\n /(\\s*deprecated\\s*(?:--?|:)?\\s*([^-]*)(?:-+)?)/i,\n )\n if (deprecationMatch) {\n const [, match, deprecationNotice] = deprecationMatch\n return {\n description: description.replace(match, '').trim(),\n deprecated: deprecationNotice?.trim() || true,\n }\n } else {\n return {\n description: description.trim(),\n deprecated: true,\n }\n }\n }\n\n return {\n description: description.trim(),\n deprecated: false,\n }\n}\n\nfunction compileLeadingTrivia(description?: string) {\n if (!description) return undefined\n return `\\n\\n/**${compileJsDoc(description).replaceAll('\\n', '\\n * ')}\\n */\\n`\n}\n\nfunction addJsDoc(\n declaration: { addJsDoc: (text: string) => void },\n def?: { description?: string },\n) {\n if (def?.description) {\n declaration.addJsDoc(compileJsDoc(def.description))\n }\n}\n\nfunction compileJsDoc(description: string) {\n const parsed = parseDescription(description)\n return `\\n${parsed.description}${\n !parsed.deprecated\n ? ''\n : (parsed.description ? '\\n\\n' : '') +\n (parsed.deprecated === true\n ? '@deprecated'\n : `@deprecated ${parsed.deprecated}`)\n }`\n}\n\nfunction stringifyOptions<O extends Record<string, unknown>>(\n obj: O,\n include?: (keyof O)[],\n exclude?: (keyof O)[],\n) {\n const filtered = Object.entries(obj).filter(\n ([k]) => (!include || include.includes(k)) && !exclude?.includes(k),\n )\n return filtered.length ? JSON.stringify(Object.fromEntries(filtered)) : ''\n}\n\nfunction hasConst<T extends { const?: unknown }>(\n def: T,\n): def is T & { const: NonNullable<T['const']> } {\n return def.const != null\n}\n\nfunction hasEnum<T extends { enum?: readonly unknown[] }>(\n def: T,\n): def is T & { enum: unknown[] } {\n return def.enum != null\n}\n\nfunction markPure<T extends string>(v: T): `/*#__PURE__*/ ${T}` {\n return `/*#__PURE__*/ ${v}`\n}\n"]}
1
+ {"version":3,"file":"lex-def-builder.js","sourceRoot":"","sources":["../src/lex-def-builder.ts"],"names":[],"mappings":";;;;AAAA,sEAAgC;AAChC,uCAKiB;AA0BjB,oDAAuC;AACvC,uDAK0B;AAC1B,6CAA+C;AAQ/C;;GAEG;AACH,MAAa,aAAa;IAIL;IACA;IACA;IALF,WAAW,CAAa;IAEzC,YACmB,OAA6B,EAC7B,IAAgB,EAChB,GAAoB,EACrC,OAAuB;QAHN,YAAO,GAAP,OAAO,CAAsB;QAC7B,SAAI,GAAJ,IAAI,CAAY;QAChB,QAAG,GAAH,GAAG,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CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAA;IAC3E,OAAO,UAAU,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAA;AAC1D,CAAC;AAED,SAAS,WAAW,CAAC,WAAoB;IACvC,IAAI,CAAC,WAAW;QAAE,OAAO,SAAS,CAAA;IAClC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAA;AACxC,CAAC;AAED,SAAS,gBAAgB,CACvB,GAAM,EACN,OAAqB,EACrB,OAAqB;IAErB,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CACzC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CACpE,CAAA;IACD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AAC5E,CAAC;AAED,SAAS,QAAQ,CACf,GAAM;IAEN,OAAO,GAAG,CAAC,KAAK,IAAI,IAAI,CAAA;AAC1B,CAAC;AAED,SAAS,OAAO,CACd,GAAM;IAEN,OAAO,GAAG,CAAC,IAAI,IAAI,IAAI,CAAA;AACzB,CAAC;AAED,SAAS,QAAQ,CAAmB,CAAI;IACtC,OAAO,iBAAiB,CAAC,EAAE,CAAA;AAC7B,CAAC","sourcesContent":["import assert from 'node:assert'\nimport {\n JSDocStructure,\n OptionalKind,\n SourceFile,\n VariableDeclarationKind,\n} from 'ts-morph'\nimport {\n LexiconArray,\n LexiconArrayItems,\n LexiconBlob,\n LexiconBoolean,\n LexiconBytes,\n LexiconCid,\n LexiconDocument,\n LexiconError,\n LexiconIndexer,\n LexiconInteger,\n LexiconObject,\n LexiconParameters,\n LexiconPayload,\n LexiconPermissionSet,\n LexiconProcedure,\n LexiconQuery,\n LexiconRecord,\n LexiconRef,\n LexiconRefUnion,\n LexiconString,\n LexiconSubscription,\n LexiconToken,\n LexiconUnknown,\n} from '@atproto/lex-document'\nimport { l } from '@atproto/lex-schema'\nimport {\n RefResolver,\n RefResolverOptions,\n ResolvedRef,\n getPublicIdentifiers,\n} from './ref-resolver.js'\nimport { isSafeIdentifier } from './ts-lang.js'\n\nexport type LexDefBuilderOptions = RefResolverOptions & {\n lib?: string\n allowLegacyBlobs?: boolean\n pureAnnotations?: boolean\n}\n\n/**\n * Utility class to build a TypeScript source file from a lexicon document.\n */\nexport class LexDefBuilder {\n private readonly refResolver: RefResolver\n\n constructor(\n private readonly options: LexDefBuilderOptions,\n private readonly file: SourceFile,\n private readonly doc: LexiconDocument,\n indexer: LexiconIndexer,\n ) {\n this.refResolver = new RefResolver(doc, file, indexer, options)\n }\n\n private pure(code: string) {\n return this.options.pureAnnotations ? markPure(code) : code\n }\n\n async build() {\n this.file.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n { name: '$nsid', initializer: JSON.stringify(this.doc.id) },\n ],\n })\n\n this.file.addExportDeclaration({\n namedExports: [{ name: '$nsid' }],\n })\n\n const defs = Object.keys(this.doc.defs)\n if (defs.length) {\n const moduleSpecifier = this.options?.lib ?? '@atproto/lex-schema'\n this.file\n .addImportDeclaration({ moduleSpecifier })\n .addNamedImports([{ name: 'l' }])\n\n for (const hash of defs) {\n await this.addDef(hash)\n }\n }\n }\n\n private addUtils(definitions: Record<string, undefined | string>) {\n const entries = Object.entries(definitions).filter(\n (e): e is [(typeof e)[0], NonNullable<(typeof e)[1]>] => e[1] != null,\n )\n if (entries.length) {\n this.file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: entries.map(([name, initializer]) => ({\n name,\n initializer,\n })),\n })\n }\n }\n\n private async addDef(hash: string) {\n const def = Object.hasOwn(this.doc.defs, hash) ? this.doc.defs[hash] : null\n if (def == null) return\n\n switch (def.type) {\n case 'permission-set':\n return this.addPermissionSet(hash, def)\n case 'procedure':\n return this.addProcedure(hash, def)\n case 'query':\n return this.addQuery(hash, def)\n case 'subscription':\n return this.addSubscription(hash, def)\n case 'record':\n return this.addRecord(hash, def)\n case 'token':\n return this.addToken(hash, def)\n case 'object':\n return this.addObject(hash, def)\n case 'array':\n return this.addArray(hash, def)\n default:\n await this.addSchema(hash, def, {\n type: await this.compileContainedType(def),\n schema: await this.compileContainedSchema(def),\n validationUtils: true,\n })\n }\n }\n\n private async addPermissionSet(hash: string, def: LexiconPermissionSet) {\n const permission = def.permissions.map((def) => {\n const options = stringifyOptions(def, undefined, ['resource', 'type'])\n return this.pure(\n `l.permission(${JSON.stringify(def.resource)}, ${options})`,\n )\n })\n\n const options = stringifyOptions(def, [\n 'title',\n 'title:lang',\n 'detail',\n 'detail:lang',\n ] satisfies (keyof l.PermissionSetOptions)[])\n\n await this.addSchema(hash, def, {\n schema: this.pure(\n `l.permissionSet($nsid, [${permission.join(',')}], ${options})`,\n ),\n })\n }\n\n private async addProcedure(hash: string, def: LexiconProcedure) {\n if (hash !== 'main') {\n throw new Error(`Definition ${hash} cannot be of type ${def.type}`)\n }\n\n // @TODO Build the types instead of using an inferred type.\n\n const ref = await this.addSchema(hash, def, {\n schema: this.pure(`\n l.procedure(\n $nsid,\n ${await this.compileParamsSchema(def.parameters)},\n ${await this.compilePayload(def.input)},\n ${await this.compilePayload(def.output)},\n ${await this.compileErrors(def.errors)}\n )\n `),\n })\n\n this.addMethodTypeUtils(ref, def)\n this.addUtils({\n $lxm: this.pure(`${ref.varName}.nsid`),\n $params: this.pure(`${ref.varName}.parameters`),\n $input: this.pure(`${ref.varName}.input`),\n $output: this.pure(`${ref.varName}.output`),\n })\n }\n\n private async addQuery(hash: string, def: LexiconQuery) {\n if (hash !== 'main') {\n throw new Error(`Definition ${hash} cannot be of type ${def.type}`)\n }\n\n // @TODO Build the types instead of using an inferred type.\n\n const ref = await this.addSchema(hash, def, {\n schema: this.pure(`\n l.query(\n $nsid,\n ${await this.compileParamsSchema(def.parameters)},\n ${await this.compilePayload(def.output)},\n ${await this.compileErrors(def.errors)}\n )\n `),\n })\n\n this.addMethodTypeUtils(ref, def)\n this.addUtils({\n $lxm: this.pure(`${ref.varName}.nsid`),\n $params: `${ref.varName}.parameters`,\n $output: `${ref.varName}.output`,\n })\n }\n\n private async addSubscription(hash: string, def: LexiconSubscription) {\n if (hash !== 'main') {\n throw new Error(`Definition ${hash} cannot be of type ${def.type}`)\n }\n\n // @TODO Build the types instead of using an inferred type.\n\n const ref = await this.addSchema(hash, def, {\n schema: this.pure(`\n l.subscription(\n $nsid,\n ${await this.compileParamsSchema(def.parameters)},\n ${await this.compileBodySchema(def.message?.schema)},\n ${await this.compileErrors(def.errors)}\n )\n `),\n })\n\n this.addMethodTypeUtils(ref, def)\n this.addUtils({\n $lxm: this.pure(`${ref.varName}.nsid`),\n $params: `${ref.varName}.parameters`,\n $message: `${ref.varName}.message`,\n })\n }\n\n addMethodTypeUtils(\n ref: ResolvedRef,\n def: LexiconProcedure | LexiconQuery | LexiconSubscription,\n ) {\n this.file.addTypeAlias({\n isExported: true,\n name: 'Params',\n type: `l.InferMethodParams<typeof ${ref.varName}>`,\n docs: compileDocs(def.parameters?.description),\n })\n\n if (def.type === 'procedure') {\n this.file.addTypeAlias({\n isExported: true,\n name: 'Input',\n type: `l.InferMethodInput<typeof ${ref.varName}>`,\n docs: compileDocs(def.input?.description),\n })\n\n this.file.addTypeAlias({\n isExported: true,\n name: 'InputBody',\n type: `l.InferMethodInputBody<typeof ${ref.varName}>`,\n docs: compileDocs(def.input?.description),\n })\n }\n\n if (def.type === 'procedure' || def.type === 'query') {\n this.file.addTypeAlias({\n isExported: true,\n name: 'Output',\n type: `l.InferMethodOutput<typeof ${ref.varName}>`,\n docs: compileDocs(def.output?.description),\n })\n\n this.file.addTypeAlias({\n isExported: true,\n name: 'OutputBody',\n type: `l.InferMethodOutputBody<typeof ${ref.varName}>`,\n docs: compileDocs(def.output?.description),\n })\n }\n\n if (def.type === 'subscription') {\n this.file.addTypeAlias({\n isExported: true,\n name: 'Message',\n type: `l.InferSubscriptionMessage<typeof ${ref.varName}>`,\n docs: compileDocs(def.message?.description),\n })\n }\n }\n\n private async addRecord(hash: string, def: LexiconRecord) {\n if (hash !== 'main') {\n throw new Error(`Definition ${hash} cannot be of type ${def.type}`)\n }\n\n const key = JSON.stringify(def.key ?? 'any')\n const objectSchema = await this.compileObjectSchema(def.record)\n\n const properties = await this.compilePropertiesTypes(def.record)\n properties.unshift(`$type: ${JSON.stringify(l.$type(this.doc.id, hash))}`)\n\n await this.addSchema(hash, def, {\n type: `{ ${properties.join(';')} }`,\n schema: (ref) =>\n this.pure(\n `l.record<${key}, ${ref.typeName}>(${key}, $nsid, ${objectSchema})`,\n ),\n objectUtils: true,\n validationUtils: true,\n })\n }\n\n private async addObject(hash: string, def: LexiconObject) {\n const objectSchema = await this.compileObjectSchema(def)\n\n const properties = await this.compilePropertiesTypes(def)\n properties.unshift(`$type?: ${JSON.stringify(l.$type(this.doc.id, hash))}`)\n\n await this.addSchema(hash, def, {\n type: `{ ${properties.join(';')} }`,\n schema: (ref) =>\n this.pure(\n `l.typedObject<${ref.typeName}>($nsid, ${JSON.stringify(hash)}, ${objectSchema})`,\n ),\n objectUtils: true,\n validationUtils: true,\n })\n }\n\n private async addToken(hash: string, def: LexiconToken) {\n await this.addSchema(hash, def, {\n schema: this.pure(`l.token($nsid, ${JSON.stringify(hash)})`),\n type: JSON.stringify(l.$type(this.doc.id, hash)),\n validationUtils: true,\n })\n }\n\n private async addArray(hash: string, def: LexiconArray) {\n // @TODO It could be nice to expose the array item type as a separate type.\n // This was not done (yet) as there is no easy way to name it to avoid\n // collisions.\n\n const itemSchema = await this.compileContainedSchema(def.items)\n const options = stringifyOptions(def, [\n 'minLength',\n 'maxLength',\n ] satisfies (keyof l.ArraySchemaOptions)[])\n\n await this.addSchema(hash, def, {\n type: `(${await this.compileContainedType(def.items)})[]`,\n // @NOTE Not using compileArraySchema to allow specifying the generic\n // parameter to l.array<>.\n schema: (ref) =>\n this.pure(\n `l.array<${ref.typeName}[number]>(${itemSchema}, ${options})`,\n ),\n validationUtils: true,\n })\n }\n\n private async addSchema(\n hash: string,\n def: { description?: string },\n {\n type,\n schema,\n objectUtils,\n validationUtils,\n }: {\n type?: string | ((ref: ResolvedRef) => string)\n schema?: string | ((ref: ResolvedRef) => string)\n objectUtils?: boolean\n validationUtils?: boolean\n },\n ): Promise<ResolvedRef> {\n const ref = await this.refResolver.resolveLocal(hash)\n const pub = getPublicIdentifiers(hash)\n\n // Fool-proofing\n assert(isSafeIdentifier(ref.varName), 'Expected safe type identifier')\n assert(isSafeIdentifier(ref.typeName), 'Expected safe type identifier')\n assert(isSafeIdentifier(pub.typeName), 'Expected safe type identifier')\n\n if (type) {\n this.file.addTypeAlias({\n name: ref.typeName,\n type: typeof type === 'function' ? type(ref) : type,\n docs: compileDocs(def.description),\n })\n\n this.file.addExportDeclaration({\n isTypeOnly: true,\n namedExports: [\n {\n name: ref.typeName,\n alias: ref.typeName === pub.typeName ? undefined : pub.typeName,\n },\n ],\n })\n }\n\n if (schema) {\n this.file.addVariableStatement({\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: ref.varName,\n initializer: typeof schema === 'function' ? schema(ref) : schema,\n },\n ],\n docs: compileDocs(def.description),\n })\n\n this.file.addExportDeclaration({\n namedExports: [\n {\n name: ref.varName,\n alias:\n ref.varName === pub.varName\n ? undefined\n : isSafeIdentifier(pub.varName)\n ? pub.varName\n : JSON.stringify(pub.varName),\n },\n ],\n })\n }\n\n if (hash === 'main' && objectUtils) {\n this.addUtils({\n $isTypeOf: markPure(`${ref.varName}.isTypeOf.bind(${ref.varName})`),\n $build: markPure(`${ref.varName}.build.bind(${ref.varName})`),\n $type: markPure(`${ref.varName}.$type`),\n })\n }\n\n if (hash === 'main' && validationUtils) {\n this.addUtils({\n $assert: markPure(`${ref.varName}.assert.bind(${ref.varName})`),\n $ifMatches: markPure(`${ref.varName}.ifMatches.bind(${ref.varName})`),\n $matches: markPure(`${ref.varName}.matches.bind(${ref.varName})`),\n $parse: markPure(`${ref.varName}.parse.bind(${ref.varName})`),\n $safeParse: markPure(`${ref.varName}.safeParse.bind(${ref.varName})`),\n })\n }\n\n return ref\n }\n\n private async compilePayload(def: LexiconPayload | undefined) {\n if (!def) return this.pure(`l.payload()`)\n\n // Special case for JSON object payloads\n if (def.encoding === 'application/json' && def.schema?.type === 'object') {\n const properties = await this.compilePropertiesSchemas(def.schema)\n return this.pure(`l.jsonPayload({${properties.join(',')}})`)\n }\n\n const encodedEncoding = JSON.stringify(def.encoding)\n if (def.schema) {\n const bodySchema = await this.compileBodySchema(def.schema)\n return this.pure(`l.payload(${encodedEncoding}, ${bodySchema})`)\n } else {\n return this.pure(`l.payload(${encodedEncoding})`)\n }\n }\n\n private async compileBodySchema(\n def?: LexiconRef | LexiconRefUnion | LexiconObject,\n ): Promise<string> {\n if (!def) return 'undefined'\n if (def.type === 'object') return this.compileObjectSchema(def)\n return this.compileContainedSchema(def)\n }\n\n private async compileParamsSchema(def: undefined | LexiconParameters) {\n if (!def) return this.pure(`l.params()`)\n\n const properties = await this.compilePropertiesSchemas(def)\n return this.pure(`l.params({${properties.join(',')}})`)\n }\n\n private async compileErrors(defs?: readonly LexiconError[]) {\n if (!defs?.length) return ''\n return JSON.stringify(defs.map((d) => d.name))\n }\n\n private async compileObjectSchema(def: LexiconObject): Promise<string> {\n const properties = await this.compilePropertiesSchemas(def)\n return this.pure(`l.object({${properties.join(',')}})`)\n }\n\n private async compilePropertiesSchemas(options: {\n properties: Record<string, LexiconArray | LexiconArrayItems>\n required?: readonly string[]\n nullable?: readonly string[]\n }): Promise<string[]> {\n for (const opt of ['required', 'nullable'] as const) {\n if (options[opt]) {\n for (const prop of options[opt]) {\n if (!Object.hasOwn(options.properties, prop)) {\n throw new Error(`No schema found for ${opt} property \"${prop}\"`)\n }\n }\n }\n }\n\n return Promise.all(\n Object.entries(options.properties).map((entry) => {\n return this.compilePropertyEntrySchema(entry, options)\n }),\n )\n }\n\n private async compilePropertiesTypes(options: {\n properties: Record<string, LexiconArray | LexiconArrayItems>\n required?: readonly string[]\n nullable?: readonly string[]\n }) {\n return Promise.all(\n Object.entries(options.properties).map((entry) => {\n return this.compilePropertyEntryType(entry, options)\n }),\n )\n }\n\n private async compilePropertyEntrySchema(\n [key, def]: [string, LexiconArray | LexiconArrayItems],\n options: {\n required?: readonly string[]\n nullable?: readonly string[]\n },\n ) {\n const isNullable = options.nullable?.includes(key)\n const isRequired = options.required?.includes(key)\n\n let schema = await this.compileContainedSchema(def)\n\n if (isNullable) {\n schema = this.pure(`l.nullable(${schema})`)\n }\n\n if (!isRequired) {\n schema = this.pure(`l.optional(${schema})`)\n }\n\n return `${JSON.stringify(key)}:${schema}`\n }\n\n private async compilePropertyEntryType(\n [key, def]: [string, LexiconArray | LexiconArrayItems],\n options: {\n required?: readonly string[]\n nullable?: readonly string[]\n },\n ) {\n const isNullable = options.nullable?.includes(key)\n const isRequired = options.required?.includes(key)\n\n const optional = isRequired ? '' : '?'\n const append = isNullable ? ' | null' : ''\n\n const jsDoc = compileLeadingTrivia(def.description) || ''\n const name = JSON.stringify(key)\n const type = await this.compileContainedType(def)\n\n return `${jsDoc}${name}${optional}:${type}${append}`\n }\n\n private async compileContainedSchema(\n def: LexiconArray | LexiconArrayItems,\n ): Promise<string> {\n switch (def.type) {\n case 'unknown':\n return this.compileUnknownSchema(def)\n case 'boolean':\n return this.compileBooleanSchema(def)\n case 'integer':\n return this.compileIntegerSchema(def)\n case 'string':\n return this.compileStringSchema(def)\n case 'bytes':\n return this.compileBytesSchema(def)\n case 'blob':\n return this.compileBlobSchema(def)\n case 'cid-link':\n return this.compileCidLinkSchema(def)\n case 'ref':\n return this.compileRefSchema(def)\n case 'union':\n return this.compileRefUnionSchema(def)\n case 'array':\n return this.compileArraySchema(def)\n default:\n // @ts-expect-error\n throw new Error(`Unsupported def type: ${def.type}`)\n }\n }\n\n private async compileContainedType(\n def: LexiconArray | LexiconArrayItems,\n ): Promise<string> {\n switch (def.type) {\n case 'unknown':\n return this.compileUnknownType(def)\n case 'boolean':\n return this.compileBooleanType(def)\n case 'integer':\n return this.compileIntegerType(def)\n case 'string':\n return this.compileStringType(def)\n case 'bytes':\n return this.compileBytesType(def)\n case 'blob':\n return this.compileBlobType(def)\n case 'cid-link':\n return this.compileCidLinkType(def)\n case 'ref':\n return this.compileRefType(def)\n case 'union':\n return this.compileRefUnionType(def)\n case 'array':\n return this.compileArrayType(def)\n default:\n // @ts-expect-error\n throw new Error(`Unsupported def type: ${def.type}`)\n }\n }\n\n private async compileArraySchema(def: LexiconArray): Promise<string> {\n const itemSchema = await this.compileContainedSchema(def.items)\n const options = stringifyOptions(def, [\n 'minLength',\n 'maxLength',\n ] satisfies (keyof l.ArraySchemaOptions)[])\n return this.pure(`l.array(${itemSchema}, ${options})`)\n }\n\n private async compileArrayType(def: LexiconArray): Promise<string> {\n return `(${await this.compileContainedType(def.items)})[]`\n }\n\n private async compileUnknownSchema(_def: LexiconUnknown): Promise<string> {\n return this.pure(`l.unknownObject()`)\n }\n\n private async compileUnknownType(_def: LexiconUnknown): Promise<string> {\n return `l.UnknownObject`\n }\n\n private async compileBooleanSchema(def: LexiconBoolean): Promise<string> {\n if (hasConst(def)) return this.compileConstSchema(def)\n\n const options = stringifyOptions(def, [\n 'default',\n ] satisfies (keyof l.BooleanSchemaOptions)[])\n return this.pure(`l.boolean(${options})`)\n }\n\n private async compileBooleanType(def: LexiconBoolean): Promise<string> {\n if (hasConst(def)) return this.compileConstType(def)\n return 'boolean'\n }\n\n private async compileIntegerSchema(def: LexiconInteger): Promise<string> {\n if (hasConst(def)) {\n const schema: l.IntegerSchema = l.integer(def)\n schema.assert(def.const)\n }\n\n if (hasEnum(def)) {\n const schema: l.IntegerSchema = l.integer(def)\n for (const val of def.enum) schema.assert(val)\n }\n\n if (hasConst(def)) return this.compileConstSchema(def)\n if (hasEnum(def)) return this.compileEnumSchema(def)\n\n const options = stringifyOptions(def, [\n 'default',\n 'maximum',\n 'minimum',\n ] satisfies (keyof l.IntegerSchemaOptions)[])\n return this.pure(`l.integer(${options})`)\n }\n\n private async compileIntegerType(def: LexiconInteger): Promise<string> {\n if (hasConst(def)) return this.compileConstType(def)\n if (hasEnum(def)) return this.compileEnumType(def)\n\n return 'number'\n }\n\n private async compileStringSchema(def: LexiconString): Promise<string> {\n if (hasConst(def)) {\n const schema: l.StringSchema = l.string(def)\n schema.assert(def.const)\n } else if (hasEnum(def)) {\n const schema: l.StringSchema = l.string(def)\n for (const val of def.enum) schema.assert(val)\n }\n\n if (hasConst(def)) return this.compileConstSchema(def)\n if (hasEnum(def)) return this.compileEnumSchema(def)\n\n const options = stringifyOptions(def, [\n 'default',\n 'format',\n 'maxGraphemes',\n 'minGraphemes',\n 'maxLength',\n 'minLength',\n ] satisfies (keyof l.StringSchemaOptions)[])\n return this.pure(`l.string(${options})`)\n }\n\n private async compileStringType(def: LexiconString): Promise<string> {\n if (hasConst(def)) return this.compileConstType(def)\n if (hasEnum(def)) return this.compileEnumType(def)\n\n switch (def.format) {\n case undefined:\n break\n case 'datetime':\n return 'l.DatetimeString'\n case 'uri':\n return 'l.UriString'\n case 'at-uri':\n return 'l.AtUriString'\n case 'did':\n return 'l.DidString'\n case 'handle':\n return 'l.HandleString'\n case 'at-identifier':\n return 'l.AtIdentifierString'\n case 'nsid':\n return 'l.NsidString'\n case 'tid':\n return 'l.TidString'\n case 'cid':\n return 'l.CidString'\n case 'language':\n return 'l.LanguageString'\n case 'record-key':\n return 'l.RecordKeyString'\n default:\n throw new Error(`Unknown string format: ${def.format}`)\n }\n\n if (def.knownValues?.length) {\n return (\n def.knownValues.map((v) => JSON.stringify(v)).join(' | ') +\n ' | l.UnknownString'\n )\n }\n\n return 'string'\n }\n\n private async compileBytesSchema(def: LexiconBytes): Promise<string> {\n const options = stringifyOptions(def, [\n 'minLength',\n 'maxLength',\n ] satisfies (keyof l.BytesSchemaOptions)[])\n return this.pure(`l.bytes(${options})`)\n }\n\n private async compileBytesType(_def: LexiconBytes): Promise<string> {\n return 'Uint8Array'\n }\n\n private async compileBlobSchema(def: LexiconBlob): Promise<string> {\n const opts = { ...def, allowLegacy: this.options.allowLegacyBlobs === true }\n const options = stringifyOptions(opts, [\n 'maxSize',\n 'accept',\n 'allowLegacy',\n ] satisfies (keyof l.BlobSchemaOptions)[])\n return this.pure(`l.blob(${options})`)\n }\n\n private async compileBlobType(_def: LexiconBlob): Promise<string> {\n return this.options.allowLegacyBlobs\n ? 'l.BlobRef | l.LegacyBlobRef'\n : 'l.BlobRef'\n }\n\n private async compileCidLinkSchema(_def: LexiconCid): Promise<string> {\n return this.pure(`l.cidLink()`)\n }\n\n private async compileCidLinkType(_def: LexiconCid): Promise<string> {\n return 'l.Cid'\n }\n\n private async compileRefSchema(def: LexiconRef): Promise<string> {\n const { varName, typeName } = await this.refResolver.resolve(def.ref)\n // @NOTE \"as any\" is needed in schemas with circular refs as TypeScript\n // cannot infer the type of a value that depends on its initializer type\n return this.pure(`l.ref<${typeName}>((() => ${varName}) as any)`)\n }\n\n private async compileRefType(def: LexiconRef): Promise<string> {\n const ref = await this.refResolver.resolve(def.ref)\n return ref.typeName\n }\n\n private async compileRefUnionSchema(def: LexiconRefUnion): Promise<string> {\n if (def.refs.length === 0 && def.closed) {\n return this.pure(`l.never()`)\n }\n\n const refs = await Promise.all(\n def.refs.map(async (ref: string) => {\n const { varName, typeName } = await this.refResolver.resolve(ref)\n // @NOTE \"as any\" is needed in schemas with circular refs as TypeScript\n // cannot infer the type of a value that depends on its initializer type\n return this.pure(`l.typedRef<${typeName}>((() => ${varName}) as any)`)\n }),\n )\n\n return this.pure(\n `l.typedUnion([${refs.join(',')}], ${def.closed ?? false})`,\n )\n }\n\n private async compileRefUnionType(def: LexiconRefUnion): Promise<string> {\n const types = await Promise.all(\n def.refs.map(async (ref) => {\n const { typeName } = await this.refResolver.resolve(ref)\n return `l.TypedRef<${typeName}>`\n }),\n )\n if (!def.closed) types.push('l.TypedObject')\n return types.join(' | ') || 'never'\n }\n\n private async compileConstSchema<\n T extends null | number | string | boolean,\n >(def: { const: T; enum?: readonly T[]; default?: T }): Promise<string> {\n if (hasEnum(def) && !def.enum.includes(def.const)) {\n return this.pure(`l.never()`)\n }\n\n const options = stringifyOptions(def, [\n 'default',\n ] satisfies (keyof l.LiteralSchemaOptions<any>)[])\n return this.pure(`l.literal(${JSON.stringify(def.const)}, ${options})`)\n }\n\n private async compileConstType<\n T extends null | number | string | boolean,\n >(def: { const: T; enum?: readonly T[] }): Promise<string> {\n if (hasEnum(def) && !def.enum.includes(def.const)) {\n return 'never'\n }\n return JSON.stringify(def.const)\n }\n\n private async compileEnumSchema<T extends null | number | string>(def: {\n enum: readonly T[]\n default?: T\n }): Promise<string> {\n if (def.enum.length === 0) {\n return this.pure(`l.never()`)\n }\n if (def.enum.length === 1 && def.default === undefined) {\n return this.pure(`l.literal(${JSON.stringify(def.enum[0])})`)\n }\n const options = stringifyOptions(def, [\n 'default',\n ] satisfies (keyof l.EnumSchemaOptions<any>)[])\n return this.pure(`l.enum(${JSON.stringify(def.enum)}, ${options})`)\n }\n\n private async compileEnumType<T extends null | number | string>(def: {\n enum: readonly T[]\n }): Promise<string> {\n return def.enum.map((v) => JSON.stringify(v)).join(' | ') || 'never'\n }\n}\n\ntype ParsedDescription = OptionalKind<JSDocStructure> & {\n description?: string\n tags?: { tagName: string; text?: string }[]\n}\n\nfunction parseDescription(description: string): ParsedDescription {\n if (/deprecated/i.test(description)) {\n const deprecationMatch = description.match(\n /(\\s*deprecated\\s*(?:--?|:)?\\s*([^-]*)(?:-+)?)/i,\n )\n if (deprecationMatch) {\n const { 1: match, 2: deprecationNotice } = deprecationMatch\n return {\n description: description.replace(match, '').trim() || undefined,\n tags: [{ tagName: 'deprecated', text: deprecationNotice?.trim() }],\n }\n } else {\n return {\n description: description.trim() || undefined,\n tags: [{ tagName: 'deprecated' }],\n }\n }\n }\n\n return {\n description: description.trim() || undefined,\n }\n}\n\nfunction compileLeadingTrivia(description?: string) {\n if (!description) return undefined\n const parsed = parseDescription(description)\n if (!parsed.description && !parsed.tags?.length) return undefined\n const tags = parsed.tags\n ?.map(({ tagName, text }) => (text ? `@${tagName} ${text}` : `@${tagName}`))\n ?.join('\\n')\n const text = `\\n${[parsed.description, tags].filter(Boolean).join('\\n\\n')}`\n return `\\n\\n/**${text.replaceAll('\\n', '\\n * ')}\\n */\\n`\n}\n\nfunction compileDocs(description?: string) {\n if (!description) return undefined\n return [parseDescription(description)]\n}\n\nfunction stringifyOptions<O extends Record<string, unknown>>(\n obj: O,\n include?: (keyof O)[],\n exclude?: (keyof O)[],\n) {\n const filtered = Object.entries(obj).filter(\n ([k]) => (!include || include.includes(k)) && !exclude?.includes(k),\n )\n return filtered.length ? JSON.stringify(Object.fromEntries(filtered)) : ''\n}\n\nfunction hasConst<T extends { const?: unknown }>(\n def: T,\n): def is T & { const: NonNullable<T['const']> } {\n return def.const != null\n}\n\nfunction hasEnum<T extends { enum?: readonly unknown[] }>(\n def: T,\n): def is T & { enum: unknown[] } {\n return def.enum != null\n}\n\nfunction markPure<T extends string>(v: T): `/*#__PURE__*/ ${T}` {\n return `/*#__PURE__*/ ${v}`\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lex-builder",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "license": "MIT",
5
5
  "description": "TypeScript schema builder for AT Lexicons",
6
6
  "keywords": [
@@ -29,25 +29,25 @@
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
  "require": "./dist/index.js",
34
- "import": "./dist/index.js",
35
- "types": "./dist/index.d.ts"
35
+ "import": "./dist/index.js"
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
39
  "prettier": "^3.2.5",
40
40
  "ts-morph": "^27.0.0",
41
41
  "tslib": "^2.8.1",
42
- "@atproto/lex-document": "0.0.5",
43
- "@atproto/lex-schema": "0.0.4"
42
+ "@atproto/lex-document": "0.0.7",
43
+ "@atproto/lex-schema": "0.0.6"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@ts-morph/common": "^0.28.0",
47
- "jest": "^28.1.2"
47
+ "vitest": "^4.0.16"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "tsc --build tsconfig.build.json",
51
- "test": "jest"
51
+ "test": "vitest run"
52
52
  }
53
53
  }
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest'
1
2
  import { LexiconDocument, LexiconIndexer } from '@atproto/lex-document'
2
3
  import { FilteredIndexer } from './filtered-indexer.js'
3
4
 
@@ -1,5 +1,10 @@
1
1
  import assert from 'node:assert'
2
- import { SourceFile, VariableDeclarationKind } from 'ts-morph'
2
+ import {
3
+ JSDocStructure,
4
+ OptionalKind,
5
+ SourceFile,
6
+ VariableDeclarationKind,
7
+ } from 'ts-morph'
3
8
  import {
4
9
  LexiconArray,
5
10
  LexiconArrayItems,
@@ -171,35 +176,13 @@ export class LexDefBuilder {
171
176
  `),
172
177
  })
173
178
 
179
+ this.addMethodTypeUtils(ref, def)
174
180
  this.addUtils({
181
+ $lxm: this.pure(`${ref.varName}.nsid`),
175
182
  $params: this.pure(`${ref.varName}.parameters`),
176
183
  $input: this.pure(`${ref.varName}.input`),
177
184
  $output: this.pure(`${ref.varName}.output`),
178
185
  })
179
-
180
- const parametersTypeStmt = this.file.addTypeAlias({
181
- isExported: true,
182
- name: 'Params',
183
- type: `l.InferProcedureParameters<typeof ${ref.varName}>`,
184
- })
185
-
186
- addJsDoc(parametersTypeStmt, def.parameters)
187
-
188
- const inputTypeStmt = this.file.addTypeAlias({
189
- isExported: true,
190
- name: 'Input',
191
- type: `l.InferProcedureInputBody<typeof ${ref.varName}>`,
192
- })
193
-
194
- addJsDoc(inputTypeStmt, def.input)
195
-
196
- const outputTypeStmt = this.file.addTypeAlias({
197
- isExported: true,
198
- name: 'Output',
199
- type: `l.InferProcedureOutputBody<typeof ${ref.varName}>`,
200
- })
201
-
202
- addJsDoc(outputTypeStmt, def.output)
203
186
  }
204
187
 
205
188
  private async addQuery(hash: string, def: LexiconQuery) {
@@ -220,22 +203,12 @@ export class LexDefBuilder {
220
203
  `),
221
204
  })
222
205
 
206
+ this.addMethodTypeUtils(ref, def)
223
207
  this.addUtils({
208
+ $lxm: this.pure(`${ref.varName}.nsid`),
224
209
  $params: `${ref.varName}.parameters`,
225
210
  $output: `${ref.varName}.output`,
226
211
  })
227
-
228
- this.file.addTypeAlias({
229
- isExported: true,
230
- name: 'Params',
231
- type: `l.InferQueryParameters<typeof ${ref.varName}>`,
232
- })
233
-
234
- this.file.addTypeAlias({
235
- isExported: true,
236
- name: 'Output',
237
- type: `l.InferQueryOutputBody<typeof ${ref.varName}>`,
238
- })
239
212
  }
240
213
 
241
214
  private async addSubscription(hash: string, def: LexiconSubscription) {
@@ -256,22 +229,65 @@ export class LexDefBuilder {
256
229
  `),
257
230
  })
258
231
 
232
+ this.addMethodTypeUtils(ref, def)
259
233
  this.addUtils({
234
+ $lxm: this.pure(`${ref.varName}.nsid`),
260
235
  $params: `${ref.varName}.parameters`,
261
236
  $message: `${ref.varName}.message`,
262
237
  })
238
+ }
263
239
 
240
+ addMethodTypeUtils(
241
+ ref: ResolvedRef,
242
+ def: LexiconProcedure | LexiconQuery | LexiconSubscription,
243
+ ) {
264
244
  this.file.addTypeAlias({
265
245
  isExported: true,
266
246
  name: 'Params',
267
- type: `l.InferSubscriptionParameters<typeof ${ref.varName}>`,
247
+ type: `l.InferMethodParams<typeof ${ref.varName}>`,
248
+ docs: compileDocs(def.parameters?.description),
268
249
  })
269
250
 
270
- this.file.addTypeAlias({
271
- isExported: true,
272
- name: 'Message',
273
- type: `l.InferSubscriptionMessage<typeof ${ref.varName}>`,
274
- })
251
+ if (def.type === 'procedure') {
252
+ this.file.addTypeAlias({
253
+ isExported: true,
254
+ name: 'Input',
255
+ type: `l.InferMethodInput<typeof ${ref.varName}>`,
256
+ docs: compileDocs(def.input?.description),
257
+ })
258
+
259
+ this.file.addTypeAlias({
260
+ isExported: true,
261
+ name: 'InputBody',
262
+ type: `l.InferMethodInputBody<typeof ${ref.varName}>`,
263
+ docs: compileDocs(def.input?.description),
264
+ })
265
+ }
266
+
267
+ if (def.type === 'procedure' || def.type === 'query') {
268
+ this.file.addTypeAlias({
269
+ isExported: true,
270
+ name: 'Output',
271
+ type: `l.InferMethodOutput<typeof ${ref.varName}>`,
272
+ docs: compileDocs(def.output?.description),
273
+ })
274
+
275
+ this.file.addTypeAlias({
276
+ isExported: true,
277
+ name: 'OutputBody',
278
+ type: `l.InferMethodOutputBody<typeof ${ref.varName}>`,
279
+ docs: compileDocs(def.output?.description),
280
+ })
281
+ }
282
+
283
+ if (def.type === 'subscription') {
284
+ this.file.addTypeAlias({
285
+ isExported: true,
286
+ name: 'Message',
287
+ type: `l.InferSubscriptionMessage<typeof ${ref.varName}>`,
288
+ docs: compileDocs(def.message?.description),
289
+ })
290
+ }
275
291
  }
276
292
 
277
293
  private async addRecord(hash: string, def: LexiconRecord) {
@@ -368,13 +384,12 @@ export class LexDefBuilder {
368
384
  assert(isSafeIdentifier(pub.typeName), 'Expected safe type identifier')
369
385
 
370
386
  if (type) {
371
- const typeStmt = this.file.addTypeAlias({
387
+ this.file.addTypeAlias({
372
388
  name: ref.typeName,
373
389
  type: typeof type === 'function' ? type(ref) : type,
390
+ docs: compileDocs(def.description),
374
391
  })
375
392
 
376
- addJsDoc(typeStmt, def)
377
-
378
393
  this.file.addExportDeclaration({
379
394
  isTypeOnly: true,
380
395
  namedExports: [
@@ -387,7 +402,7 @@ export class LexDefBuilder {
387
402
  }
388
403
 
389
404
  if (schema) {
390
- const constStmt = this.file.addVariableStatement({
405
+ this.file.addVariableStatement({
391
406
  declarationKind: VariableDeclarationKind.Const,
392
407
  declarations: [
393
408
  {
@@ -395,10 +410,9 @@ export class LexDefBuilder {
395
410
  initializer: typeof schema === 'function' ? schema(ref) : schema,
396
411
  },
397
412
  ],
413
+ docs: compileDocs(def.description),
398
414
  })
399
415
 
400
- addJsDoc(constStmt, def)
401
-
402
416
  this.file.addExportDeclaration({
403
417
  namedExports: [
404
418
  {
@@ -438,6 +452,12 @@ export class LexDefBuilder {
438
452
  private async compilePayload(def: LexiconPayload | undefined) {
439
453
  if (!def) return this.pure(`l.payload()`)
440
454
 
455
+ // Special case for JSON object payloads
456
+ if (def.encoding === 'application/json' && def.schema?.type === 'object') {
457
+ const properties = await this.compilePropertiesSchemas(def.schema)
458
+ return this.pure(`l.jsonPayload({${properties.join(',')}})`)
459
+ }
460
+
441
461
  const encodedEncoding = JSON.stringify(def.encoding)
442
462
  if (def.schema) {
443
463
  const bodySchema = await this.compileBodySchema(def.schema)
@@ -456,7 +476,7 @@ export class LexDefBuilder {
456
476
  }
457
477
 
458
478
  private async compileParamsSchema(def: undefined | LexiconParameters) {
459
- if (!def) return this.pure(`l.params({})`)
479
+ if (!def) return this.pure(`l.params()`)
460
480
 
461
481
  const properties = await this.compilePropertiesSchemas(def)
462
482
  return this.pure(`l.params({${properties.join(',')}})`)
@@ -862,9 +882,9 @@ export class LexDefBuilder {
862
882
  }
863
883
  }
864
884
 
865
- type ParsedDescription = {
866
- description: string
867
- deprecated: boolean | string
885
+ type ParsedDescription = OptionalKind<JSDocStructure> & {
886
+ description?: string
887
+ tags?: { tagName: string; text?: string }[]
868
888
  }
869
889
 
870
890
  function parseDescription(description: string): ParsedDescription {
@@ -873,49 +893,38 @@ function parseDescription(description: string): ParsedDescription {
873
893
  /(\s*deprecated\s*(?:--?|:)?\s*([^-]*)(?:-+)?)/i,
874
894
  )
875
895
  if (deprecationMatch) {
876
- const [, match, deprecationNotice] = deprecationMatch
896
+ const { 1: match, 2: deprecationNotice } = deprecationMatch
877
897
  return {
878
- description: description.replace(match, '').trim(),
879
- deprecated: deprecationNotice?.trim() || true,
898
+ description: description.replace(match, '').trim() || undefined,
899
+ tags: [{ tagName: 'deprecated', text: deprecationNotice?.trim() }],
880
900
  }
881
901
  } else {
882
902
  return {
883
- description: description.trim(),
884
- deprecated: true,
903
+ description: description.trim() || undefined,
904
+ tags: [{ tagName: 'deprecated' }],
885
905
  }
886
906
  }
887
907
  }
888
908
 
889
909
  return {
890
- description: description.trim(),
891
- deprecated: false,
910
+ description: description.trim() || undefined,
892
911
  }
893
912
  }
894
913
 
895
914
  function compileLeadingTrivia(description?: string) {
896
915
  if (!description) return undefined
897
- return `\n\n/**${compileJsDoc(description).replaceAll('\n', '\n * ')}\n */\n`
898
- }
899
-
900
- function addJsDoc(
901
- declaration: { addJsDoc: (text: string) => void },
902
- def?: { description?: string },
903
- ) {
904
- if (def?.description) {
905
- declaration.addJsDoc(compileJsDoc(def.description))
906
- }
916
+ const parsed = parseDescription(description)
917
+ if (!parsed.description && !parsed.tags?.length) return undefined
918
+ const tags = parsed.tags
919
+ ?.map(({ tagName, text }) => (text ? `@${tagName} ${text}` : `@${tagName}`))
920
+ ?.join('\n')
921
+ const text = `\n${[parsed.description, tags].filter(Boolean).join('\n\n')}`
922
+ return `\n\n/**${text.replaceAll('\n', '\n * ')}\n */\n`
907
923
  }
908
924
 
909
- function compileJsDoc(description: string) {
910
- const parsed = parseDescription(description)
911
- return `\n${parsed.description}${
912
- !parsed.deprecated
913
- ? ''
914
- : (parsed.description ? '\n\n' : '') +
915
- (parsed.deprecated === true
916
- ? '@deprecated'
917
- : `@deprecated ${parsed.deprecated}`)
918
- }`
925
+ function compileDocs(description?: string) {
926
+ if (!description) return undefined
927
+ return [parseDescription(description)]
919
928
  }
920
929
 
921
930
  function stringifyOptions<O extends Record<string, unknown>>(
@@ -1,6 +1,6 @@
1
1
  {
2
- "extends": "../../../tsconfig/tests.json",
3
- "include": ["./tests", "./src/**.test.ts"],
2
+ "extends": "../../../tsconfig/vitest.json",
3
+ "include": ["./tests", "./src/**/*.test.ts"],
4
4
  "compilerOptions": {
5
5
  "noImplicitAny": true,
6
6
  "rootDir": "./",