@atproto/lex-cli 0.10.1 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/bin.js +8 -4
- package/dist/codegen/client.d.ts +1 -1
- package/dist/codegen/client.d.ts.map +1 -1
- package/dist/codegen/client.js +1 -1
- package/dist/codegen/client.js.map +1 -1
- package/dist/codegen/common.d.ts +4 -4
- package/dist/codegen/common.d.ts.map +1 -1
- package/dist/codegen/common.js +1 -1
- package/dist/codegen/common.js.map +1 -1
- package/dist/codegen/lex-gen.js +2 -1
- package/dist/codegen/lex-gen.js.map +1 -1
- package/dist/codegen/server.d.ts +1 -1
- package/dist/codegen/server.d.ts.map +1 -1
- package/dist/codegen/server.js +1 -1
- package/dist/codegen/server.js.map +1 -1
- package/dist/codegen/util.js +1 -0
- package/dist/codegen/util.js.map +1 -1
- package/dist/mdgen/index.js +3 -2
- package/dist/mdgen/index.js.map +1 -1
- package/dist/util.d.ts +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js.map +1 -1
- package/package.json +17 -13
- package/src/codegen/client.ts +0 -566
- package/src/codegen/common.ts +0 -283
- package/src/codegen/lex-gen.ts +0 -720
- package/src/codegen/server.ts +0 -448
- package/src/codegen/util.ts +0 -84
- package/src/index.ts +0 -105
- package/src/mdgen/index.ts +0 -77
- package/src/types.ts +0 -14
- package/src/util.ts +0 -151
- package/tsconfig.build.json +0 -8
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @atproto/lex-cli
|
|
2
2
|
|
|
3
|
+
## 0.10.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update TypeScript build to rely on references to composite internal projects
|
|
8
|
+
|
|
9
|
+
- [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Build using `verbatimModuleSyntax`, reducing runtime import graph
|
|
10
|
+
|
|
11
|
+
- [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Bundle only necessary files in the NPM tarball, including the `CHANGELOG.md` and `README.md` files (if present).
|
|
12
|
+
|
|
13
|
+
- [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Build with `noImplicitAny` enabled
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`28a0b58`](https://github.com/bluesky-social/atproto/commit/28a0b588147863eaef948cd2bb8fc0f19d08cda9), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07)]:
|
|
16
|
+
- @atproto/syntax@0.6.4
|
|
17
|
+
- @atproto/lexicon@0.7.4
|
|
18
|
+
|
|
19
|
+
## 0.10.2
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#5151](https://github.com/bluesky-social/atproto/pull/5151) [`a51c45d`](https://github.com/bluesky-social/atproto/commit/a51c45d38f6bd7b8765f640e564cf921d52162e7) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update dependencies
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`a51c45d`](https://github.com/bluesky-social/atproto/commit/a51c45d38f6bd7b8765f640e564cf921d52162e7)]:
|
|
26
|
+
- @atproto/lexicon@0.7.3
|
|
27
|
+
- @atproto/syntax@0.6.3
|
|
28
|
+
|
|
3
29
|
## 0.10.1
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/bin.js
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
/* eslint-env node */
|
|
4
4
|
|
|
5
|
-
// @NOTE This file exists so that pnpm can properly link the "bin"
|
|
6
|
-
// the monorepo is being setup (during initial "pnpm install"), but
|
|
7
|
-
// built.
|
|
5
|
+
// @NOTE This file exists as a .js file so that pnpm can properly link the "bin"
|
|
6
|
+
// scripts when the monorepo is being setup (during initial "pnpm install"), but
|
|
7
|
+
// was never built.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// @NOTE Self-referencing the package name (rather than importing
|
|
10
|
+
// "./dist/index.js") lets Node resolve through this package's own "exports"
|
|
11
|
+
// map.
|
|
12
|
+
|
|
13
|
+
import '@atproto/lex-cli'
|
package/dist/codegen/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type LexiconDoc } from '@atproto/lexicon';
|
|
2
|
-
import {
|
|
2
|
+
import type { GeneratedAPI } from '../types.js';
|
|
3
3
|
export declare function genClientApi(lexiconDocs: LexiconDoc[]): Promise<GeneratedAPI>;
|
|
4
4
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/codegen/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkB,KAAK,UAAU,EAAY,MAAM,kBAAkB,CAAA;AAE5E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/codegen/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAkB,KAAK,UAAU,EAAY,MAAM,kBAAkB,CAAA;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AA4B/C,wBAAsB,YAAY,CAChC,WAAW,EAAE,UAAU,EAAE,GACxB,OAAO,CAAC,YAAY,CAAC,CAgBvB"}
|
package/dist/codegen/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IndentationText, Project, VariableDeclarationKind, } from 'ts-morph';
|
|
1
|
+
import { IndentationText, Project, SourceFile, VariableDeclarationKind, } from 'ts-morph';
|
|
2
2
|
import { Lexicons } from '@atproto/lexicon';
|
|
3
3
|
import { NSID } from '@atproto/syntax';
|
|
4
4
|
import { gen, lexiconsTs, utilTs } from './common.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/codegen/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,OAAO,EAEP,uBAAuB,GACxB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAmC,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,aAAa,EACb,aAAa,GACd,MAAM,cAAc,CAAA;AACrB,OAAO,EAEL,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACpB,WAAW,GACZ,MAAM,WAAW,CAAA;AAElB,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,8BAA8B;IACpC,GAAG,EAAE,4BAA4B;IACjC,MAAM,EAAE,+BAA+B;IACvC,GAAG,EAAE,4BAA4B;IACjC,MAAM,EAAE,+BAA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C;QACxC,UAAU,EAAE,YAAY,CAAC,MAAM;YAC7B,CAAC,CAAC;gBACE,+BAA+B;gBAC/B,GAAG,YAAY,CAAC,GAAG,CACjB,CAAC,GAAG,EAAE,EAAE,CAAC,oBAAoB,GAAG,CAAC,IAAI,iBAAiB,GAAG,CAAC,GAAG,KAAK,CACnE;gBACD,GAAG;gBACH,UAAU;aACX;YACH,CAAC,CAAC,CAAC,UAAU,CAAC;KACjB,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {\n IndentationText,\n Project,\n SourceFile,\n VariableDeclarationKind,\n} from 'ts-morph'\nimport { type LexRecord, type LexiconDoc, Lexicons } from '@atproto/lexicon'\nimport { NSID } from '@atproto/syntax'\nimport { type GeneratedAPI } from '../types.js'\nimport { gen, lexiconsTs, utilTs } from './common.js'\nimport {\n genCommonImports,\n genImports,\n genRecord,\n genUserType,\n genXrpcInput,\n genXrpcOutput,\n genXrpcParams,\n} from './lex-gen.js'\nimport {\n type DefTreeNode,\n lexiconsToDefTree,\n schemasToNsidTokens,\n toCamelCase,\n toScreamingSnakeCase,\n toTitleCase,\n} from './util.js'\n\nconst ATP_METHODS = {\n list: 'com.atproto.repo.listRecords',\n get: 'com.atproto.repo.getRecord',\n create: 'com.atproto.repo.createRecord',\n put: 'com.atproto.repo.putRecord',\n delete: 'com.atproto.repo.deleteRecord',\n}\n\nexport async function genClientApi(\n lexiconDocs: LexiconDoc[],\n): Promise<GeneratedAPI> {\n const project = new Project({\n useInMemoryFileSystem: true,\n manipulationSettings: { indentationText: IndentationText.TwoSpaces },\n })\n const api: GeneratedAPI = { files: [] }\n const lexicons = new Lexicons(lexiconDocs)\n const nsidTree = lexiconsToDefTree(lexiconDocs)\n const nsidTokens = schemasToNsidTokens(lexiconDocs)\n for (const lexiconDoc of lexiconDocs) {\n api.files.push(await lexiconTs(project, lexicons, lexiconDoc))\n }\n api.files.push(await utilTs(project))\n api.files.push(await lexiconsTs(project, lexiconDocs))\n api.files.push(await indexTs(project, lexiconDocs, nsidTree, nsidTokens))\n return api\n}\n\nconst indexTs = (\n project: Project,\n lexiconDocs: LexiconDoc[],\n nsidTree: DefTreeNode[],\n nsidTokens: Record<string, string[]>,\n) =>\n gen(project, '/index.ts', async (file) => {\n //= import { XrpcClient, type FetchHandler, type FetchHandlerOptions } from '@atproto/xrpc'\n const xrpcImport = file.addImportDeclaration({\n moduleSpecifier: '@atproto/xrpc',\n })\n xrpcImport.addNamedImports([\n { name: 'XrpcClient' },\n { name: 'FetchHandler', isTypeOnly: true },\n { name: 'FetchHandlerOptions', isTypeOnly: true },\n ])\n //= import {schemas} from './lexicons.js'\n file\n .addImportDeclaration({ moduleSpecifier: './lexicons.js' })\n .addNamedImports([{ name: 'schemas' }])\n //= import {CID} from 'multiformats/cid'\n file\n .addImportDeclaration({\n moduleSpecifier: 'multiformats/cid',\n })\n .addNamedImports([{ name: 'CID' }])\n\n //= import { type OmitKey, type Un$Typed } from './util.js'\n file\n .addImportDeclaration({ moduleSpecifier: `./util.js` })\n .addNamedImports([\n { name: 'OmitKey', isTypeOnly: true },\n { name: 'Un$Typed', isTypeOnly: true },\n ])\n\n // generate type imports and re-exports\n for (const lexicon of lexiconDocs) {\n const moduleSpecifier = `./types/${lexicon.id.split('.').join('/')}.js`\n file\n .addImportDeclaration({ moduleSpecifier })\n .setNamespaceImport(toTitleCase(lexicon.id))\n file\n .addExportDeclaration({ moduleSpecifier })\n .setNamespaceExport(toTitleCase(lexicon.id))\n }\n\n // generate token enums\n for (const nsidAuthority in nsidTokens) {\n // export const {THE_AUTHORITY} = {\n // {Name}: \"{authority.the.name}\"\n // }\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: toScreamingSnakeCase(nsidAuthority),\n initializer: [\n '{',\n ...nsidTokens[nsidAuthority].map(\n (nsidName) =>\n `${toTitleCase(nsidName)}: \"${nsidAuthority}.${nsidName}\",`,\n ),\n '}',\n ].join('\\n'),\n },\n ],\n })\n }\n\n //= export class AtpBaseClient {...}\n const clientCls = file.addClass({\n name: 'AtpBaseClient',\n isExported: true,\n extends: 'XrpcClient',\n })\n\n for (const ns of nsidTree) {\n //= ns: NS\n clientCls.addProperty({\n name: ns.propName,\n type: ns.className,\n })\n }\n\n //= constructor (options: FetchHandler | FetchHandlerOptions) {\n //= super(options, schemas)\n //= {namespace declarations}\n //= }\n clientCls.addConstructor({\n parameters: [\n { name: 'options', type: 'FetchHandler | FetchHandlerOptions' },\n ],\n statements: [\n 'super(options, schemas)',\n ...nsidTree.map(\n (ns) => `this.${ns.propName} = new ${ns.className}(this)`,\n ),\n ],\n })\n\n //= /** @deprecated use `this` instead */\n //= get xrpc(): XrpcClient {\n //= return this\n //= }\n clientCls\n .addGetAccessor({\n name: 'xrpc',\n returnType: 'XrpcClient',\n statements: ['return this'],\n })\n .addJsDoc('@deprecated use `this` instead')\n\n // generate classes for the schemas\n for (const ns of nsidTree) {\n genNamespaceCls(file, ns)\n }\n })\n\nfunction genNamespaceCls(file: SourceFile, ns: DefTreeNode) {\n //= export class {ns}NS {...}\n const cls = file.addClass({\n name: ns.className,\n isExported: true,\n })\n //= _client: XrpcClient\n cls.addProperty({\n name: '_client',\n type: 'XrpcClient',\n })\n\n for (const userType of ns.userTypes) {\n if (userType.def.type !== 'record') {\n continue\n }\n //= type: TypeRecord\n const name = NSID.parse(userType.nsid).name || ''\n cls.addProperty({\n name: toCamelCase(name),\n type: `${toTitleCase(userType.nsid)}Record`,\n })\n }\n\n for (const child of ns.children) {\n //= child: ChildNS\n cls.addProperty({\n name: child.propName,\n type: child.className,\n })\n\n // recurse\n genNamespaceCls(file, child)\n }\n\n //= constructor(public client: XrpcClient) {\n //= this._client = client\n //= {child namespace prop declarations}\n //= {record prop declarations}\n //= }\n cls.addConstructor({\n parameters: [\n {\n name: 'client',\n type: 'XrpcClient',\n },\n ],\n statements: [\n `this._client = client`,\n ...ns.children.map(\n (ns) => `this.${ns.propName} = new ${ns.className}(client)`,\n ),\n ...ns.userTypes\n .filter((ut) => ut.def.type === 'record')\n .map((ut) => {\n const name = NSID.parse(ut.nsid).name || ''\n return `this.${toCamelCase(name)} = new ${toTitleCase(\n ut.nsid,\n )}Record(client)`\n }),\n ],\n })\n\n // methods\n for (const userType of ns.userTypes) {\n if (userType.def.type !== 'query' && userType.def.type !== 'procedure') {\n continue\n }\n const isGetReq = userType.def.type === 'query'\n const moduleName = toTitleCase(userType.nsid)\n const name = toCamelCase(NSID.parse(userType.nsid).name || '')\n const method = cls.addMethod({\n name,\n returnType: `Promise<${moduleName}.Response>`,\n })\n if (isGetReq) {\n method.addParameter({\n name: 'params?',\n type: `${moduleName}.QueryParams`,\n })\n } else if (userType.def.type === 'procedure') {\n method.addParameter({\n name: 'data?',\n type: `${moduleName}.InputSchema`,\n })\n }\n method.addParameter({\n name: 'opts?',\n type: `${moduleName}.CallOptions`,\n })\n method.setBodyText(\n [\n `return this._client`,\n isGetReq\n ? `.call('${userType.nsid}', params, undefined, opts)`\n : `.call('${userType.nsid}', opts?.qp, data, opts)`,\n userType.def.errors?.length\n ? // Only add a catch block if there are custom errors\n ` .catch((e) => { throw ${moduleName}.toKnownErr(e) })`\n : '',\n ].join('\\n'),\n )\n }\n\n // record api classes\n for (const userType of ns.userTypes) {\n if (userType.def.type !== 'record') {\n continue\n }\n genRecordCls(file, userType.nsid, userType.def)\n }\n}\n\nfunction genRecordCls(file: SourceFile, nsid: string, lexRecord: LexRecord) {\n //= export class {type}Record {...}\n const cls = file.addClass({\n name: `${toTitleCase(nsid)}Record`,\n isExported: true,\n })\n //= _client: XrpcClient\n cls.addProperty({\n name: '_client',\n type: 'XrpcClient',\n })\n\n //= constructor(client: XrpcClient) {\n //= this._client = client\n //= }\n const cons = cls.addConstructor()\n cons.addParameter({\n name: 'client',\n type: 'XrpcClient',\n })\n cons.setBodyText(`this._client = client`)\n\n // methods\n const typeModule = toTitleCase(nsid)\n {\n //= list()\n const method = cls.addMethod({\n isAsync: true,\n name: 'list',\n returnType: `Promise<{cursor?: string, records: ({uri: string, value: ${typeModule}.Record})[]}>`,\n })\n method.addParameter({\n name: 'params',\n type: `OmitKey<${toTitleCase(ATP_METHODS.list)}.QueryParams, \"collection\">`,\n })\n method.setBodyText(\n [\n `const res = await this._client.call('${ATP_METHODS.list}', { collection: '${nsid}', ...params })`,\n `return res.data`,\n ].join('\\n'),\n )\n }\n {\n //= get()\n const method = cls.addMethod({\n isAsync: true,\n name: 'get',\n returnType: `Promise<{uri: string, cid: string, value: ${typeModule}.Record}>`,\n })\n method.addParameter({\n name: 'params',\n type: `OmitKey<${toTitleCase(ATP_METHODS.get)}.QueryParams, \"collection\">`,\n })\n method.setBodyText(\n [\n `const res = await this._client.call('${ATP_METHODS.get}', { collection: '${nsid}', ...params })`,\n `return res.data`,\n ].join('\\n'),\n )\n }\n {\n //= create()\n const method = cls.addMethod({\n isAsync: true,\n name: 'create',\n returnType: 'Promise<{uri: string, cid: string}>',\n })\n method.addParameter({\n name: 'params',\n type: `OmitKey<${toTitleCase(\n ATP_METHODS.create,\n )}.InputSchema, \"collection\" | \"record\">`,\n })\n method.addParameter({\n name: 'record',\n type: `Un$Typed<${typeModule}.Record>`,\n })\n method.addParameter({\n name: 'headers?',\n type: `Record<string, string>`,\n })\n const maybeRkeyPart = lexRecord.key?.startsWith('literal:')\n ? `rkey: '${lexRecord.key.replace('literal:', '')}', `\n : ''\n method.setBodyText(\n [\n `const collection = '${nsid}'`,\n `const res = await this._client.call('${ATP_METHODS.create}', undefined, { collection, ${maybeRkeyPart}...params, record: { ...record, $type: collection } }, { encoding: 'application/json', headers })`,\n `return res.data`,\n ].join('\\n'),\n )\n }\n {\n //= put()\n const method = cls.addMethod({\n isAsync: true,\n name: 'put',\n returnType: 'Promise<{uri: string, cid: string}>',\n })\n method.addParameter({\n name: 'params',\n type: `OmitKey<${toTitleCase(ATP_METHODS.put)}.InputSchema, \"collection\" | \"record\">`,\n })\n method.addParameter({\n name: 'record',\n type: `Un$Typed<${typeModule}.Record>`,\n })\n method.addParameter({\n name: 'headers?',\n type: `Record<string, string>`,\n })\n method.setBodyText(\n [\n `const collection = '${nsid}'`,\n `const res = await this._client.call('${ATP_METHODS.put}', undefined, { collection, ...params, record: { ...record, $type: collection } }, { encoding: 'application/json', headers })`,\n `return res.data`,\n ].join('\\n'),\n )\n }\n {\n //= delete()\n const method = cls.addMethod({\n isAsync: true,\n name: 'delete',\n returnType: 'Promise<void>',\n })\n method.addParameter({\n name: 'params',\n type: `OmitKey<${toTitleCase(\n ATP_METHODS.delete,\n )}.InputSchema, \"collection\">`,\n })\n method.addParameter({\n name: 'headers?',\n type: `Record<string, string>`,\n })\n\n method.setBodyText(\n [\n `await this._client.call('${ATP_METHODS.delete}', undefined, { collection: '${nsid}', ...params }, { headers })`,\n ].join('\\n'),\n )\n }\n}\n\nconst lexiconTs = (project, lexicons: Lexicons, lexiconDoc: LexiconDoc) =>\n gen(\n project,\n `/types/${lexiconDoc.id.split('.').join('/')}.ts`,\n async (file) => {\n const main = lexiconDoc.defs.main\n if (\n main?.type === 'query' ||\n main?.type === 'subscription' ||\n main?.type === 'procedure'\n ) {\n //= import {HeadersMap, XRPCError} from '@atproto/xrpc'\n const xrpcImport = file.addImportDeclaration({\n moduleSpecifier: '@atproto/xrpc',\n })\n xrpcImport.addNamedImports([\n { name: 'HeadersMap' },\n { name: 'XRPCError' },\n ])\n }\n\n genCommonImports(file, lexiconDoc.id)\n\n const imports: Set<string> = new Set()\n for (const defId in lexiconDoc.defs) {\n const def = lexiconDoc.defs[defId]\n const lexUri = `${lexiconDoc.id}#${defId}`\n if (defId === 'main') {\n if (def.type === 'query' || def.type === 'procedure') {\n genXrpcParams(file, lexicons, lexUri, false)\n genXrpcInput(file, imports, lexicons, lexUri, false)\n genXrpcOutput(file, imports, lexicons, lexUri)\n genClientXrpcCommon(file, lexicons, lexUri)\n } else if (def.type === 'subscription') {\n continue\n } else if (def.type === 'record') {\n genRecord(file, imports, lexicons, lexUri)\n } else {\n genUserType(file, imports, lexicons, lexUri)\n }\n } else {\n genUserType(file, imports, lexicons, lexUri)\n }\n }\n genImports(file, imports, lexiconDoc.id)\n },\n )\n\nfunction genClientXrpcCommon(\n file: SourceFile,\n lexicons: Lexicons,\n lexUri: string,\n) {\n const def = lexicons.getDefOrThrow(lexUri, ['query', 'procedure'])\n\n //= export interface CallOptions {...}\n const opts = file.addInterface({\n name: 'CallOptions',\n isExported: true,\n })\n opts.addProperty({ name: 'signal?', type: 'AbortSignal' })\n opts.addProperty({ name: 'headers?', type: 'HeadersMap' })\n if (def.type === 'procedure') {\n opts.addProperty({ name: 'qp?', type: 'QueryParams' })\n }\n if (def.type === 'procedure' && def.input) {\n let encodingType = 'string'\n if (def.input.encoding !== '*/*') {\n encodingType = def.input.encoding\n .split(',')\n .map((v) => `'${v.trim()}'`)\n .join(' | ')\n }\n opts.addProperty({\n name: 'encoding?',\n type: encodingType,\n })\n }\n\n // export interface Response {...}\n const res = file.addInterface({\n name: 'Response',\n isExported: true,\n })\n res.addProperty({ name: 'success', type: 'boolean' })\n res.addProperty({ name: 'headers', type: 'HeadersMap' })\n if (def.output?.schema) {\n if (def.output.encoding?.includes(',')) {\n res.addProperty({ name: 'data', type: 'OutputSchema | Uint8Array' })\n } else {\n res.addProperty({ name: 'data', type: 'OutputSchema' })\n }\n } else if (def.output?.encoding) {\n res.addProperty({ name: 'data', type: 'Uint8Array' })\n }\n\n // export class {errcode}Error {...}\n const customErrors: { name: string; cls: string }[] = []\n for (const error of def.errors || []) {\n let name = toTitleCase(error.name)\n if (!name.endsWith('Error')) name += 'Error'\n const errCls = file.addClass({\n name,\n extends: 'XRPCError',\n isExported: true,\n })\n errCls.addConstructor({\n parameters: [{ name: 'src', type: 'XRPCError' }],\n statements: [\n 'super(src.status, src.error, src.message, src.headers, { cause: src })',\n ],\n })\n\n customErrors.push({ name: error.name, cls: name })\n }\n\n // export function toKnownErr(err: any) {...}\n file.addFunction({\n name: 'toKnownErr',\n isExported: true,\n parameters: [{ name: 'e', type: 'any' }],\n statements: customErrors.length\n ? [\n 'if (e instanceof XRPCError) {',\n ...customErrors.map(\n (err) => `if (e.error === '${err.name}') return new ${err.cls}(e)`,\n ),\n '}',\n 'return e',\n ]\n : ['return e'],\n })\n}\n"]}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/codegen/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,OAAO,EACP,UAAU,EACV,uBAAuB,GACxB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAmC,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,aAAa,EACb,aAAa,GACd,MAAM,cAAc,CAAA;AACrB,OAAO,EAEL,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACpB,WAAW,GACZ,MAAM,WAAW,CAAA;AAElB,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,8BAA8B;IACpC,GAAG,EAAE,4BAA4B;IACjC,MAAM,EAAE,+BAA+B;IACvC,GAAG,EAAE,4BAA4B;IACjC,MAAM,EAAE,+BAA+B;CACxC,CAAA;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,WAAyB;IAEzB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC;QAC1B,qBAAqB,EAAE,IAAI;QAC3B,oBAAoB,EAAE,EAAE,eAAe,EAAE,eAAe,CAAC,SAAS,EAAE;KACrE,CAAC,CAAA;IACF,MAAM,GAAG,GAAiB,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;IACvC,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,WAAW,CAAC,CAAA;IAC1C,MAAM,QAAQ,GAAG,iBAAiB,CAAC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ord, type LexiconDoc, Lexicons } from '@atproto/lexicon'\nimport { NSID } from '@atproto/syntax'\nimport type { GeneratedAPI } from '../types.js'\nimport { gen, lexiconsTs, utilTs } from './common.js'\nimport {\n genCommonImports,\n genImports,\n genRecord,\n genUserType,\n genXrpcInput,\n genXrpcOutput,\n genXrpcParams,\n} from './lex-gen.js'\nimport {\n type DefTreeNode,\n lexiconsToDefTree,\n schemasToNsidTokens,\n toCamelCase,\n toScreamingSnakeCase,\n toTitleCase,\n} from './util.js'\n\nconst ATP_METHODS = {\n list: 'com.atproto.repo.listRecords',\n get: 'com.atproto.repo.getRecord',\n create: 'com.atproto.repo.createRecord',\n put: 'com.atproto.repo.putRecord',\n delete: 'com.atproto.repo.deleteRecord',\n}\n\nexport async function genClientApi(\n lexiconDocs: LexiconDoc[],\n): Promise<GeneratedAPI> {\n const project = new Project({\n useInMemoryFileSystem: true,\n manipulationSettings: { indentationText: IndentationText.TwoSpaces },\n })\n const api: GeneratedAPI = { files: [] }\n const lexicons = new Lexicons(lexiconDocs)\n const nsidTree = lexiconsToDefTree(lexiconDocs)\n const nsidTokens = schemasToNsidTokens(lexiconDocs)\n for (const lexiconDoc of lexiconDocs) {\n api.files.push(await lexiconTs(project, lexicons, lexiconDoc))\n }\n api.files.push(await utilTs(project))\n api.files.push(await lexiconsTs(project, lexiconDocs))\n api.files.push(await indexTs(project, lexiconDocs, nsidTree, nsidTokens))\n return api\n}\n\nconst indexTs = (\n project: Project,\n lexiconDocs: LexiconDoc[],\n nsidTree: DefTreeNode[],\n nsidTokens: Record<string, string[]>,\n) =>\n gen(project, '/index.ts', async (file) => {\n //= import { XrpcClient, type FetchHandler, type FetchHandlerOptions } from '@atproto/xrpc'\n const xrpcImport = file.addImportDeclaration({\n moduleSpecifier: '@atproto/xrpc',\n })\n xrpcImport.addNamedImports([\n { name: 'XrpcClient' },\n { name: 'FetchHandler', isTypeOnly: true },\n { name: 'FetchHandlerOptions', isTypeOnly: true },\n ])\n //= import {schemas} from './lexicons.js'\n file\n .addImportDeclaration({ moduleSpecifier: './lexicons.js' })\n .addNamedImports([{ name: 'schemas' }])\n //= import {CID} from 'multiformats/cid'\n file\n .addImportDeclaration({\n moduleSpecifier: 'multiformats/cid',\n })\n .addNamedImports([{ name: 'CID' }])\n\n //= import { type OmitKey, type Un$Typed } from './util.js'\n file\n .addImportDeclaration({ moduleSpecifier: `./util.js` })\n .addNamedImports([\n { name: 'OmitKey', isTypeOnly: true },\n { name: 'Un$Typed', isTypeOnly: true },\n ])\n\n // generate type imports and re-exports\n for (const lexicon of lexiconDocs) {\n const moduleSpecifier = `./types/${lexicon.id.split('.').join('/')}.js`\n file\n .addImportDeclaration({ moduleSpecifier })\n .setNamespaceImport(toTitleCase(lexicon.id))\n file\n .addExportDeclaration({ moduleSpecifier })\n .setNamespaceExport(toTitleCase(lexicon.id))\n }\n\n // generate token enums\n for (const nsidAuthority in nsidTokens) {\n // export const {THE_AUTHORITY} = {\n // {Name}: \"{authority.the.name}\"\n // }\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: toScreamingSnakeCase(nsidAuthority),\n initializer: [\n '{',\n ...nsidTokens[nsidAuthority].map(\n (nsidName) =>\n `${toTitleCase(nsidName)}: \"${nsidAuthority}.${nsidName}\",`,\n ),\n '}',\n ].join('\\n'),\n },\n ],\n })\n }\n\n //= export class AtpBaseClient {...}\n const clientCls = file.addClass({\n name: 'AtpBaseClient',\n isExported: true,\n extends: 'XrpcClient',\n })\n\n for (const ns of nsidTree) {\n //= ns: NS\n clientCls.addProperty({\n name: ns.propName,\n type: ns.className,\n })\n }\n\n //= constructor (options: FetchHandler | FetchHandlerOptions) {\n //= super(options, schemas)\n //= {namespace declarations}\n //= }\n clientCls.addConstructor({\n parameters: [\n { name: 'options', type: 'FetchHandler | FetchHandlerOptions' },\n ],\n statements: [\n 'super(options, schemas)',\n ...nsidTree.map(\n (ns) => `this.${ns.propName} = new ${ns.className}(this)`,\n ),\n ],\n })\n\n //= /** @deprecated use `this` instead */\n //= get xrpc(): XrpcClient {\n //= return this\n //= }\n clientCls\n .addGetAccessor({\n name: 'xrpc',\n returnType: 'XrpcClient',\n statements: ['return this'],\n })\n .addJsDoc('@deprecated use `this` instead')\n\n // generate classes for the schemas\n for (const ns of nsidTree) {\n genNamespaceCls(file, ns)\n }\n })\n\nfunction genNamespaceCls(file: SourceFile, ns: DefTreeNode) {\n //= export class {ns}NS {...}\n const cls = file.addClass({\n name: ns.className,\n isExported: true,\n })\n //= _client: XrpcClient\n cls.addProperty({\n name: '_client',\n type: 'XrpcClient',\n })\n\n for (const userType of ns.userTypes) {\n if (userType.def.type !== 'record') {\n continue\n }\n //= type: TypeRecord\n const name = NSID.parse(userType.nsid).name || ''\n cls.addProperty({\n name: toCamelCase(name),\n type: `${toTitleCase(userType.nsid)}Record`,\n })\n }\n\n for (const child of ns.children) {\n //= child: ChildNS\n cls.addProperty({\n name: child.propName,\n type: child.className,\n })\n\n // recurse\n genNamespaceCls(file, child)\n }\n\n //= constructor(public client: XrpcClient) {\n //= this._client = client\n //= {child namespace prop declarations}\n //= {record prop declarations}\n //= }\n cls.addConstructor({\n parameters: [\n {\n name: 'client',\n type: 'XrpcClient',\n },\n ],\n statements: [\n `this._client = client`,\n ...ns.children.map(\n (ns) => `this.${ns.propName} = new ${ns.className}(client)`,\n ),\n ...ns.userTypes\n .filter((ut) => ut.def.type === 'record')\n .map((ut) => {\n const name = NSID.parse(ut.nsid).name || ''\n return `this.${toCamelCase(name)} = new ${toTitleCase(\n ut.nsid,\n )}Record(client)`\n }),\n ],\n })\n\n // methods\n for (const userType of ns.userTypes) {\n if (userType.def.type !== 'query' && userType.def.type !== 'procedure') {\n continue\n }\n const isGetReq = userType.def.type === 'query'\n const moduleName = toTitleCase(userType.nsid)\n const name = toCamelCase(NSID.parse(userType.nsid).name || '')\n const method = cls.addMethod({\n name,\n returnType: `Promise<${moduleName}.Response>`,\n })\n if (isGetReq) {\n method.addParameter({\n name: 'params?',\n type: `${moduleName}.QueryParams`,\n })\n } else if (userType.def.type === 'procedure') {\n method.addParameter({\n name: 'data?',\n type: `${moduleName}.InputSchema`,\n })\n }\n method.addParameter({\n name: 'opts?',\n type: `${moduleName}.CallOptions`,\n })\n method.setBodyText(\n [\n `return this._client`,\n isGetReq\n ? `.call('${userType.nsid}', params, undefined, opts)`\n : `.call('${userType.nsid}', opts?.qp, data, opts)`,\n userType.def.errors?.length\n ? // Only add a catch block if there are custom errors\n ` .catch((e) => { throw ${moduleName}.toKnownErr(e) })`\n : '',\n ].join('\\n'),\n )\n }\n\n // record api classes\n for (const userType of ns.userTypes) {\n if (userType.def.type !== 'record') {\n continue\n }\n genRecordCls(file, userType.nsid, userType.def)\n }\n}\n\nfunction genRecordCls(file: SourceFile, nsid: string, lexRecord: LexRecord) {\n //= export class {type}Record {...}\n const cls = file.addClass({\n name: `${toTitleCase(nsid)}Record`,\n isExported: true,\n })\n //= _client: XrpcClient\n cls.addProperty({\n name: '_client',\n type: 'XrpcClient',\n })\n\n //= constructor(client: XrpcClient) {\n //= this._client = client\n //= }\n const cons = cls.addConstructor()\n cons.addParameter({\n name: 'client',\n type: 'XrpcClient',\n })\n cons.setBodyText(`this._client = client`)\n\n // methods\n const typeModule = toTitleCase(nsid)\n {\n //= list()\n const method = cls.addMethod({\n isAsync: true,\n name: 'list',\n returnType: `Promise<{cursor?: string, records: ({uri: string, value: ${typeModule}.Record})[]}>`,\n })\n method.addParameter({\n name: 'params',\n type: `OmitKey<${toTitleCase(ATP_METHODS.list)}.QueryParams, \"collection\">`,\n })\n method.setBodyText(\n [\n `const res = await this._client.call('${ATP_METHODS.list}', { collection: '${nsid}', ...params })`,\n `return res.data`,\n ].join('\\n'),\n )\n }\n {\n //= get()\n const method = cls.addMethod({\n isAsync: true,\n name: 'get',\n returnType: `Promise<{uri: string, cid: string, value: ${typeModule}.Record}>`,\n })\n method.addParameter({\n name: 'params',\n type: `OmitKey<${toTitleCase(ATP_METHODS.get)}.QueryParams, \"collection\">`,\n })\n method.setBodyText(\n [\n `const res = await this._client.call('${ATP_METHODS.get}', { collection: '${nsid}', ...params })`,\n `return res.data`,\n ].join('\\n'),\n )\n }\n {\n //= create()\n const method = cls.addMethod({\n isAsync: true,\n name: 'create',\n returnType: 'Promise<{uri: string, cid: string}>',\n })\n method.addParameter({\n name: 'params',\n type: `OmitKey<${toTitleCase(\n ATP_METHODS.create,\n )}.InputSchema, \"collection\" | \"record\">`,\n })\n method.addParameter({\n name: 'record',\n type: `Un$Typed<${typeModule}.Record>`,\n })\n method.addParameter({\n name: 'headers?',\n type: `Record<string, string>`,\n })\n const maybeRkeyPart = lexRecord.key?.startsWith('literal:')\n ? `rkey: '${lexRecord.key.replace('literal:', '')}', `\n : ''\n method.setBodyText(\n [\n `const collection = '${nsid}'`,\n `const res = await this._client.call('${ATP_METHODS.create}', undefined, { collection, ${maybeRkeyPart}...params, record: { ...record, $type: collection } }, { encoding: 'application/json', headers })`,\n `return res.data`,\n ].join('\\n'),\n )\n }\n {\n //= put()\n const method = cls.addMethod({\n isAsync: true,\n name: 'put',\n returnType: 'Promise<{uri: string, cid: string}>',\n })\n method.addParameter({\n name: 'params',\n type: `OmitKey<${toTitleCase(ATP_METHODS.put)}.InputSchema, \"collection\" | \"record\">`,\n })\n method.addParameter({\n name: 'record',\n type: `Un$Typed<${typeModule}.Record>`,\n })\n method.addParameter({\n name: 'headers?',\n type: `Record<string, string>`,\n })\n method.setBodyText(\n [\n `const collection = '${nsid}'`,\n `const res = await this._client.call('${ATP_METHODS.put}', undefined, { collection, ...params, record: { ...record, $type: collection } }, { encoding: 'application/json', headers })`,\n `return res.data`,\n ].join('\\n'),\n )\n }\n {\n //= delete()\n const method = cls.addMethod({\n isAsync: true,\n name: 'delete',\n returnType: 'Promise<void>',\n })\n method.addParameter({\n name: 'params',\n type: `OmitKey<${toTitleCase(\n ATP_METHODS.delete,\n )}.InputSchema, \"collection\">`,\n })\n method.addParameter({\n name: 'headers?',\n type: `Record<string, string>`,\n })\n\n method.setBodyText(\n [\n `await this._client.call('${ATP_METHODS.delete}', undefined, { collection: '${nsid}', ...params }, { headers })`,\n ].join('\\n'),\n )\n }\n}\n\nconst lexiconTs = (\n project: Project,\n lexicons: Lexicons,\n lexiconDoc: LexiconDoc,\n) =>\n gen(\n project,\n `/types/${lexiconDoc.id.split('.').join('/')}.ts`,\n async (file) => {\n const main = lexiconDoc.defs.main\n if (\n main?.type === 'query' ||\n main?.type === 'subscription' ||\n main?.type === 'procedure'\n ) {\n //= import {HeadersMap, XRPCError} from '@atproto/xrpc'\n const xrpcImport = file.addImportDeclaration({\n moduleSpecifier: '@atproto/xrpc',\n })\n xrpcImport.addNamedImports([\n { name: 'HeadersMap' },\n { name: 'XRPCError' },\n ])\n }\n\n genCommonImports(file, lexiconDoc.id)\n\n const imports: Set<string> = new Set()\n for (const defId in lexiconDoc.defs) {\n const def = lexiconDoc.defs[defId]\n const lexUri = `${lexiconDoc.id}#${defId}`\n if (defId === 'main') {\n if (def.type === 'query' || def.type === 'procedure') {\n genXrpcParams(file, lexicons, lexUri, false)\n genXrpcInput(file, imports, lexicons, lexUri, false)\n genXrpcOutput(file, imports, lexicons, lexUri)\n genClientXrpcCommon(file, lexicons, lexUri)\n } else if (def.type === 'subscription') {\n continue\n } else if (def.type === 'record') {\n genRecord(file, imports, lexicons, lexUri)\n } else {\n genUserType(file, imports, lexicons, lexUri)\n }\n } else {\n genUserType(file, imports, lexicons, lexUri)\n }\n }\n genImports(file, imports, lexiconDoc.id)\n },\n )\n\nfunction genClientXrpcCommon(\n file: SourceFile,\n lexicons: Lexicons,\n lexUri: string,\n) {\n const def = lexicons.getDefOrThrow(lexUri, ['query', 'procedure'])\n\n //= export interface CallOptions {...}\n const opts = file.addInterface({\n name: 'CallOptions',\n isExported: true,\n })\n opts.addProperty({ name: 'signal?', type: 'AbortSignal' })\n opts.addProperty({ name: 'headers?', type: 'HeadersMap' })\n if (def.type === 'procedure') {\n opts.addProperty({ name: 'qp?', type: 'QueryParams' })\n }\n if (def.type === 'procedure' && def.input) {\n let encodingType = 'string'\n if (def.input.encoding !== '*/*') {\n encodingType = def.input.encoding\n .split(',')\n .map((v) => `'${v.trim()}'`)\n .join(' | ')\n }\n opts.addProperty({\n name: 'encoding?',\n type: encodingType,\n })\n }\n\n // export interface Response {...}\n const res = file.addInterface({\n name: 'Response',\n isExported: true,\n })\n res.addProperty({ name: 'success', type: 'boolean' })\n res.addProperty({ name: 'headers', type: 'HeadersMap' })\n if (def.output?.schema) {\n if (def.output.encoding?.includes(',')) {\n res.addProperty({ name: 'data', type: 'OutputSchema | Uint8Array' })\n } else {\n res.addProperty({ name: 'data', type: 'OutputSchema' })\n }\n } else if (def.output?.encoding) {\n res.addProperty({ name: 'data', type: 'Uint8Array' })\n }\n\n // export class {errcode}Error {...}\n const customErrors: { name: string; cls: string }[] = []\n for (const error of def.errors || []) {\n let name = toTitleCase(error.name)\n if (!name.endsWith('Error')) name += 'Error'\n const errCls = file.addClass({\n name,\n extends: 'XRPCError',\n isExported: true,\n })\n errCls.addConstructor({\n parameters: [{ name: 'src', type: 'XRPCError' }],\n statements: [\n 'super(src.status, src.error, src.message, src.headers, { cause: src })',\n ],\n })\n\n customErrors.push({ name: error.name, cls: name })\n }\n\n // export function toKnownErr(err: any) {...}\n file.addFunction({\n name: 'toKnownErr',\n isExported: true,\n parameters: [{ name: 'e', type: 'any' }],\n statements: customErrors.length\n ? [\n 'if (e instanceof XRPCError) {',\n ...customErrors.map(\n (err) => `if (e.error === '${err.name}') return new ${err.cls}(e)`,\n ),\n '}',\n 'return e',\n ]\n : ['return e'],\n })\n}\n"]}
|
package/dist/codegen/common.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Project, SourceFile } from 'ts-morph';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export declare const utilTs: (project:
|
|
5
|
-
export declare const lexiconsTs: (project:
|
|
2
|
+
import type { LexiconDoc } from '@atproto/lexicon';
|
|
3
|
+
import type { GeneratedFile } from '../types.js';
|
|
4
|
+
export declare const utilTs: (project: Project) => Promise<GeneratedFile>;
|
|
5
|
+
export declare const lexiconsTs: (project: Project, lexicons: LexiconDoc[]) => Promise<GeneratedFile>;
|
|
6
6
|
export declare function gen(project: Project, path: string, gen: (file: SourceFile) => Promise<void>): Promise<GeneratedFile>;
|
|
7
7
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/codegen/common.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,UAAU,EAA2B,MAAM,UAAU,CAAA;AACvE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/codegen/common.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,UAAU,EAA2B,MAAM,UAAU,CAAA;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAWhD,eAAO,MAAM,MAAM,YAAa,OAAO,2BAuHnC,CAAA;AAEJ,eAAO,MAAM,UAAU,YAAa,OAAO,YAAY,UAAU,EAAE,2BA8H/D,CAAA;AAEJ,wBAAsB,GAAG,CACvB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,GACvC,OAAO,CAAC,aAAa,CAAC,CAQxB"}
|
package/dist/codegen/common.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/codegen/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,MAAM,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EAAuB,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAGvE,OAA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AAK,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAClE;qBACA,IAAI,CAAC,EAAE,CAAC,cAAc;aAC1B;SACF;KACF,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEJ,MAAM,CAAC,KAAK,UAAU,GAAG,CACvB,OAAgB,EAChB,IAAY,EACZ,GAAwC;IAExC,MAAM,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC3C,MAAM,GAAG,CAAC,IAAI,CAAC,CAAA;IACf,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA,CAAC,sCAAsC;IACxD,MAAM,GAAG,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,EAAE,CAAA;IAC9C,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;IAEhD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAC1B,CAAC;AAED,SAAS,MAAM;IACb,OAAO;;;CAGR,CAAA;AACD,CAAC","sourcesContent":["import { Options as PrettierOptions, format } from 'prettier'\nimport { Project, SourceFile, VariableDeclarationKind } from 'ts-morph'\nimport { type LexiconDoc } from '@atproto/lexicon'\nimport { type GeneratedFile } from '../types.js'\nimport { toTitleCase } from './util.js'\n\nconst PRETTIER_OPTS: PrettierOptions = {\n parser: 'typescript',\n tabWidth: 2,\n semi: false,\n singleQuote: true,\n trailingComma: 'all',\n}\n\nexport const utilTs = (project) =>\n gen(project, '/util.ts', async (file) => {\n file.replaceWithText(`\nimport { type ValidationResult } from '@atproto/lexicon'\n\nexport type OmitKey<T, K extends keyof T> = {\n [K2 in keyof T as K2 extends K ? never : K2]: T[K2]\n}\n\nexport type $Typed<V, T extends string = string> = V & { $type: T }\nexport type Un$Typed<V extends { $type?: string }> = OmitKey<V, '$type'>\n\nexport type $Type<Id extends string, Hash extends string> = Hash extends 'main'\n ? Id\n : \\`\\${Id}#\\${Hash}\\`\n\nfunction isObject<V>(v: V): v is V & object {\n return v != null && typeof v === 'object'\n}\n\nfunction is$type<Id extends string, Hash extends string>(\n $type: unknown,\n id: Id,\n hash: Hash,\n): $type is $Type<Id, Hash> {\n return hash === 'main'\n ? $type === id\n : // $type === \\`\\${id}#\\${hash}\\`\n typeof $type === 'string' &&\n $type.length === id.length + 1 + hash.length &&\n $type.charCodeAt(id.length) === 35 /* '#' */ &&\n $type.startsWith(id) &&\n $type.endsWith(hash)\n}\n${\n /**\n * The construct below allows to properly distinguish open unions. Consider\n * the following example:\n *\n * ```ts\n * type Foo = { $type?: $Type<'foo', 'main'>; foo: string }\n * type Bar = { $type?: $Type<'bar', 'main'>; bar: string }\n * type OpenFooBarUnion = $Typed<Foo> | $Typed<Bar> | { $type: string }\n * ```\n *\n * In the context of lexicons, when there is a open union as shown above, the\n * if `$type` if either `foo` or `bar`, then the object IS of type `Foo` or\n * `Bar`.\n *\n * ```ts\n * declare const obj1: OpenFooBarUnion\n * if (is$typed(obj1, 'foo', 'main')) {\n * obj1.$type // $Type<'foo', 'main'>\n * obj1.foo // string\n * }\n * ```\n *\n * Similarly, if an object is of type `unknown`, then the `is$typed` function\n * should only return assurance about the `$type` property, which is what it\n * actually checks:\n *\n * ```ts\n * declare const obj2: unknown\n * if (is$typed(obj2, 'foo', 'main')) {\n * obj2.$type // $Type<'foo', 'main'>\n * // @ts-expect-error\n * obj2.foo\n * }\n * ```\n *\n * The construct bellow is what makes these two scenarios possible.\n */\n ''\n}\nexport type $TypedObject<V, Id extends string, Hash extends string> = V extends {\n $type: $Type<Id, Hash>\n}\n ? V\n : V extends { $type?: string }\n ? V extends { $type?: infer T extends $Type<Id, Hash> }\n ? V & { $type: T }\n : never\n : V & { $type: $Type<Id, Hash> }\n\nexport function is$typed<V, Id extends string, Hash extends string>(\n v: V,\n id: Id,\n hash: Hash,\n): v is $TypedObject<V, Id, Hash> {\n return isObject(v) && '$type' in v && is$type(v.$type, id, hash)\n}\n\nexport function maybe$typed<V, Id extends string, Hash extends string>(\n v: V,\n id: Id,\n hash: Hash,\n): v is V & object & { $type?: $Type<Id, Hash> } {\n return (\n isObject(v) &&\n ('$type' in v\n ? v.$type === undefined || is$type(v.$type, id, hash)\n : true)\n )\n}\n\nexport type Validator<R = unknown> = (v: unknown) => ValidationResult<R>\nexport type ValidatorParam<V extends Validator> =\n V extends Validator<infer R> ? R : never\n\n/**\n * Utility function that allows to convert a \"validate*\" utility function into a\n * type predicate.\n */\nexport function asPredicate<V extends Validator>(validate: V) {\n return function <T>(v: T): v is T & ValidatorParam<V> {\n return validate(v).success\n }\n}\n`)\n })\n\nexport const lexiconsTs = (project, lexicons: LexiconDoc[]) =>\n gen(project, '/lexicons.ts', async (file) => {\n //= import { type LexiconDoc, Lexicons } from '@atproto/lexicon'\n file\n .addImportDeclaration({\n moduleSpecifier: '@atproto/lexicon',\n })\n .addNamedImports([\n { name: 'LexiconDoc', isTypeOnly: true },\n { name: 'Lexicons' },\n { name: 'ValidationError' },\n { name: 'ValidationResult', isTypeOnly: true },\n ])\n\n //= import { is$typed, maybe$typed, type $Typed } from './util.js'\n file\n .addImportDeclaration({\n moduleSpecifier: './util.js',\n })\n .addNamedImports([\n { name: '$Typed', isTypeOnly: true },\n { name: 'is$typed' },\n { name: 'maybe$typed' },\n ])\n\n //= export const schemaDict = {...} as const satisfies Record<string, LexiconDoc>\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: 'schemaDict',\n initializer:\n JSON.stringify(\n lexicons.reduce(\n (acc, cur) => ({\n ...acc,\n [toTitleCase(cur.id)]: cur,\n }),\n {},\n ),\n null,\n 2,\n ) + ' as const satisfies Record<string, LexiconDoc>',\n },\n ],\n })\n\n //= export const schemas = Object.values(schemaDict) satisfies LexiconDoc[]\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: 'schemas',\n initializer: 'Object.values(schemaDict) satisfies LexiconDoc[]',\n },\n ],\n })\n\n //= export const lexicons: Lexicons = new Lexicons(schemas)\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: 'lexicons',\n type: 'Lexicons',\n initializer: 'new Lexicons(schemas)',\n },\n ],\n })\n\n file.addFunction({\n isExported: true,\n name: 'validate',\n overloads: [\n {\n typeParameters: ['T extends { $type: string }'],\n parameters: [\n { name: 'v', type: 'unknown' },\n { name: 'id', type: 'string' },\n { name: 'hash', type: 'string' },\n { name: 'requiredType', type: 'true' },\n ],\n returnType: 'ValidationResult<T>',\n },\n {\n typeParameters: ['T extends { $type?: string }'],\n parameters: [\n { name: 'v', type: 'unknown' },\n { name: 'id', type: 'string' },\n { name: 'hash', type: 'string' },\n { name: 'requiredType', type: 'false', hasQuestionToken: true },\n ],\n returnType: 'ValidationResult<T>',\n },\n ],\n parameters: [\n { name: 'v', type: 'unknown' },\n { name: 'id', type: 'string' },\n { name: 'hash', type: 'string' },\n { name: 'requiredType', type: 'boolean', hasQuestionToken: true },\n ],\n statements: [\n // If $type is present, make sure it is valid before validating the rest of the object\n 'return (requiredType ? is$typed : maybe$typed)(v, id, hash) ? lexicons.validate(`${id}#${hash}`, v) : { success: false, error: new ValidationError(`Must be an object with \"${hash === \\'main\\' ? id : `${id}#${hash}`}\" $type property`) }',\n ],\n returnType: 'ValidationResult',\n })\n\n //= export const ids = {...}\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: 'ids',\n initializer: `{${lexicons\n .map(\n (lex) => `\\n ${toTitleCase(lex.id)}: ${JSON.stringify(lex.id)},`,\n )\n .join('')}\\n} as const`,\n },\n ],\n })\n })\n\nexport async function gen(\n project: Project,\n path: string,\n gen: (file: SourceFile) => Promise<void>,\n): Promise<GeneratedFile> {\n const file = project.createSourceFile(path)\n await gen(file)\n await file.save() // Save in the \"in memory\" file system\n const src = `${banner()}${file.getFullText()}`\n const content = await format(src, PRETTIER_OPTS)\n\n return { path, content }\n}\n\nfunction banner() {\n return `/**\n * GENERATED CODE - DO NOT MODIFY\n */\n`\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/codegen/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,MAAM,EAAE,MAAM,UAAU,CAAA;AAClE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAGvE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,MAAM,aAAa,GAAoB;IACrC,MAAM,EAAE,YAAY;IACpB,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,KAAK;IACX,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,KAAK;CACrB,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAgB,EAAE,EAAE,CACzC,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;IACtC,IAAI,CAAC,eAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCvB;IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,EACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6CC,CAAC,CAAA;AACA,CAAC,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAgB,EAAE,QAAsB,EAAE,EAAE,CACrE,GAAG,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;IAC1C,gEAAgE;IAChE,IAAI;SACD,oBAAoB,CAAC;QACpB,eAAe,EAAE,kBAAkB;KACpC,CAAC;SACD,eAAe,CAAC;QACf,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE;QACxC,EAAE,IAAI,EAAE,UAAU,EAAE;QACpB,EAAE,IAAI,EAAE,i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C/B,CAAC,CAAA;IAEF,4BAA4B;IAC5B,IAAI,CAAC,oBAAoB,CAAC;QACxB,UAAU,EAAE,IAAI;QAChB,eAAe,EAAE,uBAAuB,CAAC,KAAK;QAC9C,YAAY,EAAE;YACZ;gBACE,IAAI,EAAE,KAAK;gBACX,WAAW,EAAE,IAAI,QAAQ;qBACtB,GAAG,CACF,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAClE;qBACA,IAAI,CAAC,EAAE,CAAC,cAAc;aAC1B;SACF;KACF,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEJ,MAAM,CAAC,KAAK,UAAU,GAAG,CACvB,OAAgB,EAChB,IAAY,EACZ,GAAwC;IAExC,MAAM,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC3C,MAAM,GAAG,CAAC,IAAI,CAAC,CAAA;IACf,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA,CAAC,sCAAsC;IACxD,MAAM,GAAG,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,EAAE,CAAA;IAC9C,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;IAEhD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAC1B,CAAC;AAED,SAAS,MAAM;IACb,OAAO;;;CAGR,CAAA;AACD,CAAC","sourcesContent":["import { type Options as PrettierOptions, format } from 'prettier'\nimport { Project, SourceFile, VariableDeclarationKind } from 'ts-morph'\nimport type { LexiconDoc } from '@atproto/lexicon'\nimport type { GeneratedFile } from '../types.js'\nimport { toTitleCase } from './util.js'\n\nconst PRETTIER_OPTS: PrettierOptions = {\n parser: 'typescript',\n tabWidth: 2,\n semi: false,\n singleQuote: true,\n trailingComma: 'all',\n}\n\nexport const utilTs = (project: Project) =>\n gen(project, '/util.ts', async (file) => {\n file.replaceWithText(`\nimport { type ValidationResult } from '@atproto/lexicon'\n\nexport type OmitKey<T, K extends keyof T> = {\n [K2 in keyof T as K2 extends K ? never : K2]: T[K2]\n}\n\nexport type $Typed<V, T extends string = string> = V & { $type: T }\nexport type Un$Typed<V extends { $type?: string }> = OmitKey<V, '$type'>\n\nexport type $Type<Id extends string, Hash extends string> = Hash extends 'main'\n ? Id\n : \\`\\${Id}#\\${Hash}\\`\n\nfunction isObject<V>(v: V): v is V & object {\n return v != null && typeof v === 'object'\n}\n\nfunction is$type<Id extends string, Hash extends string>(\n $type: unknown,\n id: Id,\n hash: Hash,\n): $type is $Type<Id, Hash> {\n return hash === 'main'\n ? $type === id\n : // $type === \\`\\${id}#\\${hash}\\`\n typeof $type === 'string' &&\n $type.length === id.length + 1 + hash.length &&\n $type.charCodeAt(id.length) === 35 /* '#' */ &&\n $type.startsWith(id) &&\n $type.endsWith(hash)\n}\n${\n /**\n * The construct below allows to properly distinguish open unions. Consider\n * the following example:\n *\n * ```ts\n * type Foo = { $type?: $Type<'foo', 'main'>; foo: string }\n * type Bar = { $type?: $Type<'bar', 'main'>; bar: string }\n * type OpenFooBarUnion = $Typed<Foo> | $Typed<Bar> | { $type: string }\n * ```\n *\n * In the context of lexicons, when there is a open union as shown above, the\n * if `$type` if either `foo` or `bar`, then the object IS of type `Foo` or\n * `Bar`.\n *\n * ```ts\n * declare const obj1: OpenFooBarUnion\n * if (is$typed(obj1, 'foo', 'main')) {\n * obj1.$type // $Type<'foo', 'main'>\n * obj1.foo // string\n * }\n * ```\n *\n * Similarly, if an object is of type `unknown`, then the `is$typed` function\n * should only return assurance about the `$type` property, which is what it\n * actually checks:\n *\n * ```ts\n * declare const obj2: unknown\n * if (is$typed(obj2, 'foo', 'main')) {\n * obj2.$type // $Type<'foo', 'main'>\n * // @ts-expect-error\n * obj2.foo\n * }\n * ```\n *\n * The construct bellow is what makes these two scenarios possible.\n */\n ''\n}\nexport type $TypedObject<V, Id extends string, Hash extends string> = V extends {\n $type: $Type<Id, Hash>\n}\n ? V\n : V extends { $type?: string }\n ? V extends { $type?: infer T extends $Type<Id, Hash> }\n ? V & { $type: T }\n : never\n : V & { $type: $Type<Id, Hash> }\n\nexport function is$typed<V, Id extends string, Hash extends string>(\n v: V,\n id: Id,\n hash: Hash,\n): v is $TypedObject<V, Id, Hash> {\n return isObject(v) && '$type' in v && is$type(v.$type, id, hash)\n}\n\nexport function maybe$typed<V, Id extends string, Hash extends string>(\n v: V,\n id: Id,\n hash: Hash,\n): v is V & object & { $type?: $Type<Id, Hash> } {\n return (\n isObject(v) &&\n ('$type' in v\n ? v.$type === undefined || is$type(v.$type, id, hash)\n : true)\n )\n}\n\nexport type Validator<R = unknown> = (v: unknown) => ValidationResult<R>\nexport type ValidatorParam<V extends Validator> =\n V extends Validator<infer R> ? R : never\n\n/**\n * Utility function that allows to convert a \"validate*\" utility function into a\n * type predicate.\n */\nexport function asPredicate<V extends Validator>(validate: V) {\n return function <T>(v: T): v is T & ValidatorParam<V> {\n return validate(v).success\n }\n}\n`)\n })\n\nexport const lexiconsTs = (project: Project, lexicons: LexiconDoc[]) =>\n gen(project, '/lexicons.ts', async (file) => {\n //= import { type LexiconDoc, Lexicons } from '@atproto/lexicon'\n file\n .addImportDeclaration({\n moduleSpecifier: '@atproto/lexicon',\n })\n .addNamedImports([\n { name: 'LexiconDoc', isTypeOnly: true },\n { name: 'Lexicons' },\n { name: 'ValidationError' },\n { name: 'ValidationResult', isTypeOnly: true },\n ])\n\n //= import { is$typed, maybe$typed, type $Typed } from './util.js'\n file\n .addImportDeclaration({\n moduleSpecifier: './util.js',\n })\n .addNamedImports([\n { name: '$Typed', isTypeOnly: true },\n { name: 'is$typed' },\n { name: 'maybe$typed' },\n ])\n\n //= export const schemaDict = {...} as const satisfies Record<string, LexiconDoc>\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: 'schemaDict',\n initializer:\n JSON.stringify(\n lexicons.reduce(\n (acc, cur) => ({\n ...acc,\n [toTitleCase(cur.id)]: cur,\n }),\n {},\n ),\n null,\n 2,\n ) + ' as const satisfies Record<string, LexiconDoc>',\n },\n ],\n })\n\n //= export const schemas = Object.values(schemaDict) satisfies LexiconDoc[]\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: 'schemas',\n initializer: 'Object.values(schemaDict) satisfies LexiconDoc[]',\n },\n ],\n })\n\n //= export const lexicons: Lexicons = new Lexicons(schemas)\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: 'lexicons',\n type: 'Lexicons',\n initializer: 'new Lexicons(schemas)',\n },\n ],\n })\n\n file.addFunction({\n isExported: true,\n name: 'validate',\n overloads: [\n {\n typeParameters: ['T extends { $type: string }'],\n parameters: [\n { name: 'v', type: 'unknown' },\n { name: 'id', type: 'string' },\n { name: 'hash', type: 'string' },\n { name: 'requiredType', type: 'true' },\n ],\n returnType: 'ValidationResult<T>',\n },\n {\n typeParameters: ['T extends { $type?: string }'],\n parameters: [\n { name: 'v', type: 'unknown' },\n { name: 'id', type: 'string' },\n { name: 'hash', type: 'string' },\n { name: 'requiredType', type: 'false', hasQuestionToken: true },\n ],\n returnType: 'ValidationResult<T>',\n },\n ],\n parameters: [\n { name: 'v', type: 'unknown' },\n { name: 'id', type: 'string' },\n { name: 'hash', type: 'string' },\n { name: 'requiredType', type: 'boolean', hasQuestionToken: true },\n ],\n statements: [\n // If $type is present, make sure it is valid before validating the rest of the object\n 'return (requiredType ? is$typed : maybe$typed)(v, id, hash) ? lexicons.validate(`${id}#${hash}`, v) : { success: false, error: new ValidationError(`Must be an object with \"${hash === \\'main\\' ? id : `${id}#${hash}`}\" $type property`) }',\n ],\n returnType: 'ValidationResult',\n })\n\n //= export const ids = {...}\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: 'ids',\n initializer: `{${lexicons\n .map(\n (lex) => `\\n ${toTitleCase(lex.id)}: ${JSON.stringify(lex.id)},`,\n )\n .join('')}\\n} as const`,\n },\n ],\n })\n })\n\nexport async function gen(\n project: Project,\n path: string,\n gen: (file: SourceFile) => Promise<void>,\n): Promise<GeneratedFile> {\n const file = project.createSourceFile(path)\n await gen(file)\n await file.save() // Save in the \"in memory\" file system\n const src = `${banner()}${file.getFullText()}`\n const content = await format(src, PRETTIER_OPTS)\n\n return { path, content }\n}\n\nfunction banner() {\n return `/**\n * GENERATED CODE - DO NOT MODIFY\n */\n`\n}\n"]}
|
package/dist/codegen/lex-gen.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { relative as getRelativePath } from 'node:path/posix';
|
|
2
|
-
import { VariableDeclarationKind } from 'ts-morph';
|
|
2
|
+
import { JSDoc, SourceFile, VariableDeclarationKind } from 'ts-morph';
|
|
3
|
+
import { Lexicons, } from '@atproto/lexicon';
|
|
3
4
|
import { toCamelCase, toScreamingSnakeCase, toTitleCase } from './util.js';
|
|
4
5
|
export function genComment(commentable, def) {
|
|
5
6
|
if (def.description) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lex-gen.js","sourceRoot":"","sources":["../../src/codegen/lex-gen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAqB,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAYrE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAK1E,MAAM,UAAU,UAAU,CACxB,WAAc,EACd,GAA6B;IAE7B,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC;QACpB,WAAW,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,CAAC,CAAA;IACxD,CAAC;IACD,OAAO,WAAW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,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACxE,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CACf,MAAyB,EACzB,IAA8C;IAE9C,MAAM,KAAK,GAAI,EAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC7C,IAAI,IAAI,EAAE,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACtC,MAAM,GAAG,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACnC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAA;IACpD,IAAI,GAAG;QAAE,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAA;IAC9C,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC1B,CAAC","sourcesContent":["import { relative as getRelativePath } from 'node:path/posix'\nimport { JSDoc, SourceFile, VariableDeclarationKind } from 'ts-morph'\nimport {\n type LexArray,\n type LexBlob,\n type LexBytes,\n type LexCidLink,\n type LexIpldType,\n type LexObject,\n type LexPrimitive,\n type LexToken,\n Lexicons,\n} from '@atproto/lexicon'\nimport { toCamelCase, toScreamingSnakeCase, toTitleCase } from './util.js'\n\ninterface Commentable {\n addJsDoc: ({ description }: { description: string }) => JSDoc\n}\nexport function genComment<T extends Commentable>(\n commentable: T,\n def: { description?: string },\n): T {\n if (def.description) {\n commentable.addJsDoc({ description: def.description })\n }\n return commentable\n}\n\nexport function genCommonImports(file: SourceFile, baseNsid: string) {\n //= import {ValidationResult, BlobRef} from '@atproto/lexicon'\n file\n .addImportDeclaration({\n moduleSpecifier: '@atproto/lexicon',\n })\n .addNamedImports([\n { name: 'ValidationResult', isTypeOnly: true },\n { name: 'BlobRef' },\n ])\n\n //= import {CID} from 'multiformats/cid'\n file\n .addImportDeclaration({\n moduleSpecifier: 'multiformats/cid',\n })\n .addNamedImports([{ name: 'CID' }])\n\n //= import { validate as _validate } from '../../lexicons.ts'\n file\n .addImportDeclaration({\n moduleSpecifier: `${baseNsid\n .split('.')\n .map((_str) => '..')\n .join('/')}/lexicons.js`,\n })\n .addNamedImports([{ name: 'validate', alias: '_validate' }])\n\n //= import { type $Typed, is$typed as _is$typed, type OmitKey } from '../[...]/util.ts'\n file\n .addImportDeclaration({\n moduleSpecifier: `${baseNsid\n .split('.')\n .map((_str) => '..')\n .join('/')}/util.js`,\n })\n .addNamedImports([\n { name: '$Typed', isTypeOnly: true },\n { name: 'is$typed', alias: '_is$typed' },\n { name: 'OmitKey', isTypeOnly: true },\n ])\n\n // TypeScript adds protection against circular imports, which hurts bundle\n // size. Since we know that lexicon.ts and util.ts do not depend on the file\n // being generated, we can safely bypass this protection. Note that we are not\n // using `import * as util from '../../util.js'` because typescript will emit\n // is own helpers for the import, which we want to avoid.\n file.addVariableStatement({\n isExported: false,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n { name: 'is$typed', initializer: '_is$typed' },\n { name: 'validate', initializer: '_validate' },\n ],\n })\n\n //= const id = \"{baseNsid}\"\n file.addVariableStatement({\n isExported: false, // Do not export to allow tree-shaking\n declarationKind: VariableDeclarationKind.Const,\n declarations: [{ name: 'id', initializer: JSON.stringify(baseNsid) }],\n })\n}\n\nexport function genImports(\n file: SourceFile,\n imports: Set<string>,\n baseNsid: string,\n) {\n const startPath = '/' + baseNsid.split('.').slice(0, -1).join('/')\n\n for (const nsid of imports) {\n const targetPath = '/' + nsid.split('.').join('/') + '.js'\n let resolvedPath = getRelativePath(startPath, targetPath)\n if (!resolvedPath.startsWith('.')) {\n resolvedPath = `./${resolvedPath}`\n }\n file.addImportDeclaration({\n isTypeOnly: true,\n moduleSpecifier: resolvedPath,\n namespaceImport: toTitleCase(nsid),\n })\n }\n}\n\nexport function genUserType(\n file: SourceFile,\n imports: Set<string>,\n lexicons: Lexicons,\n lexUri: string,\n) {\n const def = lexicons.getDefOrThrow(lexUri)\n switch (def.type) {\n case 'array':\n genArray(file, imports, lexUri, def)\n break\n case 'token':\n genToken(file, lexUri, def)\n break\n case 'object': {\n const ifaceName: string = toTitleCase(getHash(lexUri))\n genObject(file, imports, lexUri, def, ifaceName, {\n typeProperty: true,\n })\n genObjHelpers(file, lexUri, ifaceName, {\n requireTypeProperty: false,\n })\n break\n }\n\n case 'blob':\n case 'bytes':\n case 'cid-link':\n case 'boolean':\n case 'integer':\n case 'string':\n case 'unknown':\n genPrimitiveOrBlob(file, lexUri, def)\n break\n\n default:\n throw new Error(\n `genLexUserType() called with wrong definition type (${def.type}) in ${lexUri}`,\n )\n }\n}\n\nfunction genObject(\n file: SourceFile,\n imports: Set<string>,\n lexUri: string,\n def: LexObject,\n ifaceName: string,\n {\n defaultsArePresent = true,\n allowUnknownProperties = false,\n typeProperty = false,\n }: {\n defaultsArePresent?: boolean\n allowUnknownProperties?: boolean\n typeProperty?: boolean | 'required'\n } = {},\n) {\n const iface = file.addInterface({\n name: ifaceName,\n isExported: true,\n })\n genComment(iface, def)\n\n if (typeProperty) {\n const hash = getHash(lexUri)\n const baseNsid = stripScheme(stripHash(lexUri))\n\n //= $type?: <uri>\n iface.addProperty({\n name: typeProperty === 'required' ? `$type` : `$type?`,\n type:\n // Not using $Type here because it is less readable than a plain string\n // `$Type<${JSON.stringify(baseNsid)}, ${JSON.stringify(hash)}>`\n hash === 'main'\n ? JSON.stringify(`${baseNsid}`)\n : JSON.stringify(`${baseNsid}#${hash}`),\n })\n }\n\n const nullableProps = new Set(def.nullable)\n if (def.properties) {\n for (const propKey in def.properties) {\n const propDef = def.properties[propKey]\n const propNullable = nullableProps.has(propKey)\n const req =\n def.required?.includes(propKey) ||\n (defaultsArePresent &&\n 'default' in propDef &&\n propDef.default !== undefined)\n if (propDef.type === 'ref' || propDef.type === 'union') {\n //= propName: External|External\n const types =\n propDef.type === 'union'\n ? propDef.refs.map((ref) => refToUnionType(ref, lexUri, imports))\n : [refToType(propDef.ref, stripScheme(stripHash(lexUri)), imports)]\n if (propDef.type === 'union' && !propDef.closed) {\n types.push('{ $type: string }')\n }\n iface.addProperty({\n name: `${propKey}${req ? '' : '?'}`,\n type: makeType(types, { nullable: propNullable }),\n })\n continue\n } else {\n if (propDef.type === 'array') {\n //= propName: type[]\n let propAst\n if (propDef.items.type === 'ref') {\n propAst = iface.addProperty({\n name: `${propKey}${req ? '' : '?'}`,\n type: makeType(\n refToType(\n propDef.items.ref,\n stripScheme(stripHash(lexUri)),\n imports,\n ),\n {\n nullable: propNullable,\n array: true,\n },\n ),\n })\n } else if (propDef.items.type === 'union') {\n const types = propDef.items.refs.map((ref) =>\n refToUnionType(ref, lexUri, imports),\n )\n if (!propDef.items.closed) {\n types.push('{ $type: string }')\n }\n propAst = iface.addProperty({\n name: `${propKey}${req ? '' : '?'}`,\n type: makeType(types, {\n nullable: propNullable,\n array: true,\n }),\n })\n } else {\n propAst = iface.addProperty({\n name: `${propKey}${req ? '' : '?'}`,\n type: makeType(primitiveOrBlobToType(propDef.items), {\n nullable: propNullable,\n array: true,\n }),\n })\n }\n genComment(propAst, propDef)\n } else {\n //= propName: type\n genComment(\n iface.addProperty({\n name: `${propKey}${req ? '' : '?'}`,\n type: makeType(primitiveOrBlobToType(propDef), {\n nullable: propNullable,\n }),\n }),\n propDef,\n )\n }\n }\n }\n\n if (allowUnknownProperties) {\n //= [k: string]: unknown\n iface.addIndexSignature({\n keyName: 'k',\n keyType: 'string',\n returnType: 'unknown',\n })\n }\n }\n}\n\nexport function genToken(file: SourceFile, lexUri: string, def: LexToken) {\n //= /** <comment> */\n //= export const <TOKEN> = `${id}#<token>`\n genComment(\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: toScreamingSnakeCase(getHash(lexUri)),\n initializer: `\\`\\${id}#${getHash(lexUri)}\\``,\n },\n ],\n }),\n def,\n )\n}\n\nexport function genArray(\n file: SourceFile,\n imports: Set<string>,\n lexUri: string,\n def: LexArray,\n) {\n if (def.items.type === 'ref') {\n file.addTypeAlias({\n name: toTitleCase(getHash(lexUri)),\n type: `${refToType(\n def.items.ref,\n stripScheme(stripHash(lexUri)),\n imports,\n )}[]`,\n isExported: true,\n })\n } else if (def.items.type === 'union') {\n const types = def.items.refs.map((ref) =>\n refToUnionType(ref, lexUri, imports),\n )\n if (!def.items.closed) {\n types.push('{ $type: string }')\n }\n file.addTypeAlias({\n name: toTitleCase(getHash(lexUri)),\n type: `(${types.join('|')})[]`,\n isExported: true,\n })\n } else {\n genComment(\n file.addTypeAlias({\n name: toTitleCase(getHash(lexUri)),\n type: `${primitiveOrBlobToType(def.items)}[]`,\n isExported: true,\n }),\n def,\n )\n }\n}\n\nexport function genPrimitiveOrBlob(\n file: SourceFile,\n lexUri: string,\n def: LexPrimitive | LexBlob | LexIpldType,\n) {\n genComment(\n file.addTypeAlias({\n name: toTitleCase(getHash(lexUri)),\n type: primitiveOrBlobToType(def),\n isExported: true,\n }),\n def,\n )\n}\n\nexport function genXrpcParams(\n file: SourceFile,\n lexicons: Lexicons,\n lexUri: string,\n defaultsArePresent = true,\n) {\n const def = lexicons.getDefOrThrow(lexUri, [\n 'query',\n 'subscription',\n 'procedure',\n ])\n\n // @NOTE We need to use a `type` here instead of an `interface` because we\n // need the generated type to be used as generic type parameter like this:\n //\n // type QueryParams = {} // Generated by this function\n //\n // type MyUtil<P extends xrpcServer.QueryParam> = (...)\n // type NsType = MyUtil<NS.QueryParams> // ERROR if `NS.QueryParams` is an `interface`\n //\n // Second line will fail if `NS.QueryParams` is an `interface` that does\n // not explicitly extend `xrpcServer.QueryParam`, or have a string index\n // signature that encompasses `xrpcServer.QueryParam`.\n\n //= export type QueryParams = {...}\n if (def.parameters) {\n genComment(\n file.addTypeAlias({\n name: 'QueryParams',\n isExported: true,\n type: `{\n ${Object.entries(def.parameters.properties)\n .map(([paramKey, paramDef]) => {\n const req =\n def.parameters!.required?.includes(paramKey) ||\n (defaultsArePresent &&\n 'default' in paramDef &&\n paramDef.default !== undefined)\n const jsDoc = paramDef.description\n ? `/** ${paramDef.description} */\\n`\n : ''\n return `${jsDoc}${paramKey}${req ? '' : '?'}: ${\n paramDef.type === 'array'\n ? primitiveToType(paramDef.items) + '[]'\n : primitiveToType(paramDef)\n }`\n })\n .join('\\n')}\n }`,\n }),\n def.parameters,\n )\n } else {\n file.addTypeAlias({\n name: 'QueryParams',\n isExported: true,\n type: '{}',\n })\n }\n}\n\nexport function genXrpcInput(\n file: SourceFile,\n imports: Set<string>,\n lexicons: Lexicons,\n lexUri: string,\n defaultsArePresent = true,\n) {\n const def = lexicons.getDefOrThrow(lexUri, ['query', 'procedure'])\n\n if (def.type === 'procedure' && def.input?.schema) {\n if (def.input.schema.type === 'ref' || def.input.schema.type === 'union') {\n //= export type InputSchema = ...\n\n const types =\n def.input.schema.type === 'union'\n ? def.input.schema.refs.map((ref) =>\n refToUnionType(ref, lexUri, imports),\n )\n : [\n refToType(\n def.input.schema.ref,\n stripScheme(stripHash(lexUri)),\n imports,\n ),\n ]\n\n if (def.input.schema.type === 'union' && !def.input.schema.closed) {\n types.push('{ $type: string }')\n }\n file.addTypeAlias({\n name: 'InputSchema',\n type: types.join('|'),\n isExported: true,\n })\n } else {\n //= export interface InputSchema {...}\n genObject(file, imports, lexUri, def.input.schema, `InputSchema`, {\n defaultsArePresent,\n })\n }\n } else if (def.type === 'procedure' && def.input?.encoding) {\n //= export type InputSchema = string | Uint8Array | Blob\n file.addTypeAlias({\n isExported: true,\n name: 'InputSchema',\n type: 'string | Uint8Array | Blob',\n })\n } else {\n //= export type InputSchema = undefined\n file.addTypeAlias({\n isExported: true,\n name: 'InputSchema',\n type: 'undefined',\n })\n }\n}\n\nexport function genXrpcOutput(\n file: SourceFile,\n imports: Set<string>,\n lexicons: Lexicons,\n lexUri: string,\n defaultsArePresent = true,\n) {\n const def = lexicons.getDefOrThrow(lexUri, [\n 'query',\n 'subscription',\n 'procedure',\n ])\n\n const schema =\n def.type === 'subscription' ? def.message?.schema : def.output?.schema\n if (schema) {\n if (schema.type === 'ref' || schema.type === 'union') {\n //= export type OutputSchema = ...\n const types =\n schema.type === 'union'\n ? schema.refs.map((ref) => refToUnionType(ref, lexUri, imports))\n : [refToType(schema.ref, stripScheme(stripHash(lexUri)), imports)]\n if (schema.type === 'union' && !schema.closed) {\n types.push('{ $type: string }')\n }\n file.addTypeAlias({\n name: 'OutputSchema',\n type: types.join('|'),\n isExported: true,\n })\n } else {\n //= export interface OutputSchema {...}\n genObject(file, imports, lexUri, schema, `OutputSchema`, {\n defaultsArePresent,\n })\n }\n }\n}\n\nexport function genRecord(\n file: SourceFile,\n imports: Set<string>,\n lexicons: Lexicons,\n lexUri: string,\n) {\n const hash = getHash(lexUri)\n const ifaceName: string = toTitleCase(hash)\n const def = lexicons.getDefOrThrow(lexUri, ['record'])\n\n //= export interface {X} {...}\n genObject(file, imports, lexUri, def.record, ifaceName, {\n defaultsArePresent: true,\n allowUnknownProperties: true,\n typeProperty: 'required',\n })\n\n //= export function is{X}(v: unknown): v is {X} {...}\n genObjHelpers(file, lexUri, ifaceName, {\n requireTypeProperty: true,\n })\n\n // For convenience, we re-export the type and the type guard under the generic\n // names \"Record\", \"isRecord\" and \"validateRecord\".\n // @NOTE This does not account for potential name clashes with a potential\n // \"#record\" def.\n\n //= export { {X} as Record, is{X} as isRecord }\n file.addExportDeclaration({\n namedExports: [\n {\n isTypeOnly: true,\n name: ifaceName,\n alias: 'Record',\n },\n {\n name: `is${ifaceName}`,\n alias: 'isRecord',\n },\n {\n name: `validate${ifaceName}`,\n alias: 'validateRecord',\n },\n ],\n })\n}\n\nfunction genObjHelpers(\n file: SourceFile,\n lexUri: string,\n ifaceName: string,\n {\n requireTypeProperty,\n }: {\n requireTypeProperty: boolean\n },\n) {\n const hash = getHash(lexUri)\n\n const hashVar = `hash${ifaceName}`\n\n file.addVariableStatement({\n isExported: false,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [{ name: hashVar, initializer: JSON.stringify(hash) }],\n })\n\n const isX = toCamelCase(`is-${ifaceName}`)\n\n //= export function is{X}<V>(v: V) {...}\n file\n .addFunction({\n name: isX,\n typeParameters: [{ name: `V` }],\n parameters: [{ name: `v`, type: `V` }],\n isExported: true,\n })\n .setBodyText(`return is$typed(v, id, ${hashVar})`)\n\n const validateX = toCamelCase(`validate-${ifaceName}`)\n\n //= export function validate{X}(v: unknown) {...}\n file\n .addFunction({\n name: validateX,\n typeParameters: [{ name: `V` }],\n parameters: [{ name: `v`, type: `V` }],\n isExported: true,\n })\n .setBodyText(\n `return validate<${ifaceName} & V>(v, id, ${hashVar}${requireTypeProperty ? ', true' : ''})`,\n )\n}\n\nexport function stripScheme(uri: string): string {\n if (uri.startsWith('lex:')) return uri.slice(4)\n return uri\n}\n\nexport function stripHash(uri: string): string {\n return uri.split('#')[0] || ''\n}\n\nexport function getHash(uri: string): string {\n return uri.split('#').pop() || ''\n}\n\nexport function ipldToType(def: LexCidLink | LexBytes) {\n if (def.type === 'bytes') {\n return 'Uint8Array'\n }\n return 'CID'\n}\n\nfunction refToUnionType(\n ref: string,\n lexUri: string,\n imports: Set<string>,\n): string {\n const baseNsid = stripScheme(stripHash(lexUri))\n return `$Typed<${refToType(ref, baseNsid, imports)}>`\n}\n\nfunction refToType(\n ref: string,\n baseNsid: string,\n imports: Set<string>,\n): string {\n // TODO: import external types!\n let [refBase, refHash] = ref.split('#')\n refBase = stripScheme(refBase)\n if (!refHash) refHash = 'main'\n\n // internal\n if (!refBase || baseNsid === refBase) {\n return toTitleCase(refHash)\n }\n\n // external\n imports.add(refBase)\n return `${toTitleCase(refBase)}.${toTitleCase(refHash)}`\n}\n\nexport function primitiveOrBlobToType(\n def: LexBlob | LexPrimitive | LexIpldType,\n): string {\n switch (def.type) {\n case 'blob':\n return 'BlobRef'\n case 'bytes':\n return 'Uint8Array'\n case 'cid-link':\n return 'CID'\n default:\n return primitiveToType(def)\n }\n}\n\nexport function primitiveToType(def: LexPrimitive): string {\n switch (def.type) {\n case 'string':\n if (def.knownValues?.length) {\n return `${def.knownValues\n .map((v) => JSON.stringify(v))\n .join(' | ')} | (string & {})`\n } else if (def.enum) {\n return def.enum.map((v) => JSON.stringify(v)).join(' | ')\n } else if (def.const) {\n return JSON.stringify(def.const)\n }\n return 'string'\n case 'integer':\n if (def.enum) {\n return def.enum.map((v) => JSON.stringify(v)).join(' | ')\n } else if (def.const) {\n return JSON.stringify(def.const)\n }\n return 'number'\n case 'boolean':\n if (def.const) {\n return JSON.stringify(def.const)\n }\n return 'boolean'\n case 'unknown':\n // @TODO Should we use \"object\" here ?\n // the \"Record\" identifier from typescript get overwritten by the Record\n // interface created by lex-cli.\n return '{ [_ in string]: unknown }' // Record<string, unknown>\n default:\n throw new Error(`Unexpected primitive type: ${JSON.stringify(def)}`)\n }\n}\n\nfunction makeType(\n _types: string | string[],\n opts?: { array?: boolean; nullable?: boolean },\n) {\n const types = ([] as string[]).concat(_types)\n if (opts?.nullable) types.push('null')\n const arr = opts?.array ? '[]' : ''\n if (types.length === 1) return `(${types[0]})${arr}`\n if (arr) return `(${types.join(' | ')})${arr}`\n return types.join(' | ')\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lex-gen.js","sourceRoot":"","sources":["../../src/codegen/lex-gen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AACrE,OAAO,EASL,QAAQ,GACT,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAK1E,MAAM,UAAU,UAAU,CACxB,WAAc,EACd,GAA6B;IAE7B,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC;QACpB,WAAW,CAAC,QAAQ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CAAgC;YAChC,OAAO,4BAA4B,CAAA,CAAC,0BAA0B;QAChE;YACE,MAAM,IAAI,KAAK,CAAC,8BAA8B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACxE,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CACf,MAAyB,EACzB,IAA8C;IAE9C,MAAM,KAAK,GAAI,EAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC7C,IAAI,IAAI,EAAE,QAAQ;QAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACtC,MAAM,GAAG,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACnC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAA;IACpD,IAAI,GAAG;QAAE,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAA;IAC9C,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC1B,CAAC","sourcesContent":["import { relative as getRelativePath } from 'node:path/posix'\nimport { JSDoc, SourceFile, VariableDeclarationKind } from 'ts-morph'\nimport {\n type LexArray,\n type LexBlob,\n type LexBytes,\n type LexCidLink,\n type LexIpldType,\n type LexObject,\n type LexPrimitive,\n type LexToken,\n Lexicons,\n} from '@atproto/lexicon'\nimport { toCamelCase, toScreamingSnakeCase, toTitleCase } from './util.js'\n\ninterface Commentable {\n addJsDoc: ({ description }: { description: string }) => JSDoc\n}\nexport function genComment<T extends Commentable>(\n commentable: T,\n def: { description?: string },\n): T {\n if (def.description) {\n commentable.addJsDoc({ description: def.description })\n }\n return commentable\n}\n\nexport function genCommonImports(file: SourceFile, baseNsid: string) {\n //= import {ValidationResult, BlobRef} from '@atproto/lexicon'\n file\n .addImportDeclaration({\n moduleSpecifier: '@atproto/lexicon',\n })\n .addNamedImports([\n { name: 'ValidationResult', isTypeOnly: true },\n { name: 'BlobRef' },\n ])\n\n //= import {CID} from 'multiformats/cid'\n file\n .addImportDeclaration({\n moduleSpecifier: 'multiformats/cid',\n })\n .addNamedImports([{ name: 'CID' }])\n\n //= import { validate as _validate } from '../../lexicons.ts'\n file\n .addImportDeclaration({\n moduleSpecifier: `${baseNsid\n .split('.')\n .map((_str) => '..')\n .join('/')}/lexicons.js`,\n })\n .addNamedImports([{ name: 'validate', alias: '_validate' }])\n\n //= import { type $Typed, is$typed as _is$typed, type OmitKey } from '../[...]/util.ts'\n file\n .addImportDeclaration({\n moduleSpecifier: `${baseNsid\n .split('.')\n .map((_str) => '..')\n .join('/')}/util.js`,\n })\n .addNamedImports([\n { name: '$Typed', isTypeOnly: true },\n { name: 'is$typed', alias: '_is$typed' },\n { name: 'OmitKey', isTypeOnly: true },\n ])\n\n // TypeScript adds protection against circular imports, which hurts bundle\n // size. Since we know that lexicon.ts and util.ts do not depend on the file\n // being generated, we can safely bypass this protection. Note that we are not\n // using `import * as util from '../../util.js'` because typescript will emit\n // is own helpers for the import, which we want to avoid.\n file.addVariableStatement({\n isExported: false,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n { name: 'is$typed', initializer: '_is$typed' },\n { name: 'validate', initializer: '_validate' },\n ],\n })\n\n //= const id = \"{baseNsid}\"\n file.addVariableStatement({\n isExported: false, // Do not export to allow tree-shaking\n declarationKind: VariableDeclarationKind.Const,\n declarations: [{ name: 'id', initializer: JSON.stringify(baseNsid) }],\n })\n}\n\nexport function genImports(\n file: SourceFile,\n imports: Set<string>,\n baseNsid: string,\n) {\n const startPath = '/' + baseNsid.split('.').slice(0, -1).join('/')\n\n for (const nsid of imports) {\n const targetPath = '/' + nsid.split('.').join('/') + '.js'\n let resolvedPath = getRelativePath(startPath, targetPath)\n if (!resolvedPath.startsWith('.')) {\n resolvedPath = `./${resolvedPath}`\n }\n file.addImportDeclaration({\n isTypeOnly: true,\n moduleSpecifier: resolvedPath,\n namespaceImport: toTitleCase(nsid),\n })\n }\n}\n\nexport function genUserType(\n file: SourceFile,\n imports: Set<string>,\n lexicons: Lexicons,\n lexUri: string,\n) {\n const def = lexicons.getDefOrThrow(lexUri)\n switch (def.type) {\n case 'array':\n genArray(file, imports, lexUri, def)\n break\n case 'token':\n genToken(file, lexUri, def)\n break\n case 'object': {\n const ifaceName: string = toTitleCase(getHash(lexUri))\n genObject(file, imports, lexUri, def, ifaceName, {\n typeProperty: true,\n })\n genObjHelpers(file, lexUri, ifaceName, {\n requireTypeProperty: false,\n })\n break\n }\n\n case 'blob':\n case 'bytes':\n case 'cid-link':\n case 'boolean':\n case 'integer':\n case 'string':\n case 'unknown':\n genPrimitiveOrBlob(file, lexUri, def)\n break\n\n default:\n throw new Error(\n `genLexUserType() called with wrong definition type (${def.type}) in ${lexUri}`,\n )\n }\n}\n\nfunction genObject(\n file: SourceFile,\n imports: Set<string>,\n lexUri: string,\n def: LexObject,\n ifaceName: string,\n {\n defaultsArePresent = true,\n allowUnknownProperties = false,\n typeProperty = false,\n }: {\n defaultsArePresent?: boolean\n allowUnknownProperties?: boolean\n typeProperty?: boolean | 'required'\n } = {},\n) {\n const iface = file.addInterface({\n name: ifaceName,\n isExported: true,\n })\n genComment(iface, def)\n\n if (typeProperty) {\n const hash = getHash(lexUri)\n const baseNsid = stripScheme(stripHash(lexUri))\n\n //= $type?: <uri>\n iface.addProperty({\n name: typeProperty === 'required' ? `$type` : `$type?`,\n type:\n // Not using $Type here because it is less readable than a plain string\n // `$Type<${JSON.stringify(baseNsid)}, ${JSON.stringify(hash)}>`\n hash === 'main'\n ? JSON.stringify(`${baseNsid}`)\n : JSON.stringify(`${baseNsid}#${hash}`),\n })\n }\n\n const nullableProps = new Set(def.nullable)\n if (def.properties) {\n for (const propKey in def.properties) {\n const propDef = def.properties[propKey]\n const propNullable = nullableProps.has(propKey)\n const req =\n def.required?.includes(propKey) ||\n (defaultsArePresent &&\n 'default' in propDef &&\n propDef.default !== undefined)\n if (propDef.type === 'ref' || propDef.type === 'union') {\n //= propName: External|External\n const types =\n propDef.type === 'union'\n ? propDef.refs.map((ref) => refToUnionType(ref, lexUri, imports))\n : [refToType(propDef.ref, stripScheme(stripHash(lexUri)), imports)]\n if (propDef.type === 'union' && !propDef.closed) {\n types.push('{ $type: string }')\n }\n iface.addProperty({\n name: `${propKey}${req ? '' : '?'}`,\n type: makeType(types, { nullable: propNullable }),\n })\n continue\n } else {\n if (propDef.type === 'array') {\n //= propName: type[]\n let propAst\n if (propDef.items.type === 'ref') {\n propAst = iface.addProperty({\n name: `${propKey}${req ? '' : '?'}`,\n type: makeType(\n refToType(\n propDef.items.ref,\n stripScheme(stripHash(lexUri)),\n imports,\n ),\n {\n nullable: propNullable,\n array: true,\n },\n ),\n })\n } else if (propDef.items.type === 'union') {\n const types = propDef.items.refs.map((ref) =>\n refToUnionType(ref, lexUri, imports),\n )\n if (!propDef.items.closed) {\n types.push('{ $type: string }')\n }\n propAst = iface.addProperty({\n name: `${propKey}${req ? '' : '?'}`,\n type: makeType(types, {\n nullable: propNullable,\n array: true,\n }),\n })\n } else {\n propAst = iface.addProperty({\n name: `${propKey}${req ? '' : '?'}`,\n type: makeType(primitiveOrBlobToType(propDef.items), {\n nullable: propNullable,\n array: true,\n }),\n })\n }\n genComment(propAst, propDef)\n } else {\n //= propName: type\n genComment(\n iface.addProperty({\n name: `${propKey}${req ? '' : '?'}`,\n type: makeType(primitiveOrBlobToType(propDef), {\n nullable: propNullable,\n }),\n }),\n propDef,\n )\n }\n }\n }\n\n if (allowUnknownProperties) {\n //= [k: string]: unknown\n iface.addIndexSignature({\n keyName: 'k',\n keyType: 'string',\n returnType: 'unknown',\n })\n }\n }\n}\n\nexport function genToken(file: SourceFile, lexUri: string, def: LexToken) {\n //= /** <comment> */\n //= export const <TOKEN> = `${id}#<token>`\n genComment(\n file.addVariableStatement({\n isExported: true,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [\n {\n name: toScreamingSnakeCase(getHash(lexUri)),\n initializer: `\\`\\${id}#${getHash(lexUri)}\\``,\n },\n ],\n }),\n def,\n )\n}\n\nexport function genArray(\n file: SourceFile,\n imports: Set<string>,\n lexUri: string,\n def: LexArray,\n) {\n if (def.items.type === 'ref') {\n file.addTypeAlias({\n name: toTitleCase(getHash(lexUri)),\n type: `${refToType(\n def.items.ref,\n stripScheme(stripHash(lexUri)),\n imports,\n )}[]`,\n isExported: true,\n })\n } else if (def.items.type === 'union') {\n const types = def.items.refs.map((ref) =>\n refToUnionType(ref, lexUri, imports),\n )\n if (!def.items.closed) {\n types.push('{ $type: string }')\n }\n file.addTypeAlias({\n name: toTitleCase(getHash(lexUri)),\n type: `(${types.join('|')})[]`,\n isExported: true,\n })\n } else {\n genComment(\n file.addTypeAlias({\n name: toTitleCase(getHash(lexUri)),\n type: `${primitiveOrBlobToType(def.items)}[]`,\n isExported: true,\n }),\n def,\n )\n }\n}\n\nexport function genPrimitiveOrBlob(\n file: SourceFile,\n lexUri: string,\n def: LexPrimitive | LexBlob | LexIpldType,\n) {\n genComment(\n file.addTypeAlias({\n name: toTitleCase(getHash(lexUri)),\n type: primitiveOrBlobToType(def),\n isExported: true,\n }),\n def,\n )\n}\n\nexport function genXrpcParams(\n file: SourceFile,\n lexicons: Lexicons,\n lexUri: string,\n defaultsArePresent = true,\n) {\n const def = lexicons.getDefOrThrow(lexUri, [\n 'query',\n 'subscription',\n 'procedure',\n ])\n\n // @NOTE We need to use a `type` here instead of an `interface` because we\n // need the generated type to be used as generic type parameter like this:\n //\n // type QueryParams = {} // Generated by this function\n //\n // type MyUtil<P extends xrpcServer.QueryParam> = (...)\n // type NsType = MyUtil<NS.QueryParams> // ERROR if `NS.QueryParams` is an `interface`\n //\n // Second line will fail if `NS.QueryParams` is an `interface` that does\n // not explicitly extend `xrpcServer.QueryParam`, or have a string index\n // signature that encompasses `xrpcServer.QueryParam`.\n\n //= export type QueryParams = {...}\n if (def.parameters) {\n genComment(\n file.addTypeAlias({\n name: 'QueryParams',\n isExported: true,\n type: `{\n ${Object.entries(def.parameters.properties)\n .map(([paramKey, paramDef]) => {\n const req =\n def.parameters!.required?.includes(paramKey) ||\n (defaultsArePresent &&\n 'default' in paramDef &&\n paramDef.default !== undefined)\n const jsDoc = paramDef.description\n ? `/** ${paramDef.description} */\\n`\n : ''\n return `${jsDoc}${paramKey}${req ? '' : '?'}: ${\n paramDef.type === 'array'\n ? primitiveToType(paramDef.items) + '[]'\n : primitiveToType(paramDef)\n }`\n })\n .join('\\n')}\n }`,\n }),\n def.parameters,\n )\n } else {\n file.addTypeAlias({\n name: 'QueryParams',\n isExported: true,\n type: '{}',\n })\n }\n}\n\nexport function genXrpcInput(\n file: SourceFile,\n imports: Set<string>,\n lexicons: Lexicons,\n lexUri: string,\n defaultsArePresent = true,\n) {\n const def = lexicons.getDefOrThrow(lexUri, ['query', 'procedure'])\n\n if (def.type === 'procedure' && def.input?.schema) {\n if (def.input.schema.type === 'ref' || def.input.schema.type === 'union') {\n //= export type InputSchema = ...\n\n const types =\n def.input.schema.type === 'union'\n ? def.input.schema.refs.map((ref) =>\n refToUnionType(ref, lexUri, imports),\n )\n : [\n refToType(\n def.input.schema.ref,\n stripScheme(stripHash(lexUri)),\n imports,\n ),\n ]\n\n if (def.input.schema.type === 'union' && !def.input.schema.closed) {\n types.push('{ $type: string }')\n }\n file.addTypeAlias({\n name: 'InputSchema',\n type: types.join('|'),\n isExported: true,\n })\n } else {\n //= export interface InputSchema {...}\n genObject(file, imports, lexUri, def.input.schema, `InputSchema`, {\n defaultsArePresent,\n })\n }\n } else if (def.type === 'procedure' && def.input?.encoding) {\n //= export type InputSchema = string | Uint8Array | Blob\n file.addTypeAlias({\n isExported: true,\n name: 'InputSchema',\n type: 'string | Uint8Array | Blob',\n })\n } else {\n //= export type InputSchema = undefined\n file.addTypeAlias({\n isExported: true,\n name: 'InputSchema',\n type: 'undefined',\n })\n }\n}\n\nexport function genXrpcOutput(\n file: SourceFile,\n imports: Set<string>,\n lexicons: Lexicons,\n lexUri: string,\n defaultsArePresent = true,\n) {\n const def = lexicons.getDefOrThrow(lexUri, [\n 'query',\n 'subscription',\n 'procedure',\n ])\n\n const schema =\n def.type === 'subscription' ? def.message?.schema : def.output?.schema\n if (schema) {\n if (schema.type === 'ref' || schema.type === 'union') {\n //= export type OutputSchema = ...\n const types =\n schema.type === 'union'\n ? schema.refs.map((ref) => refToUnionType(ref, lexUri, imports))\n : [refToType(schema.ref, stripScheme(stripHash(lexUri)), imports)]\n if (schema.type === 'union' && !schema.closed) {\n types.push('{ $type: string }')\n }\n file.addTypeAlias({\n name: 'OutputSchema',\n type: types.join('|'),\n isExported: true,\n })\n } else {\n //= export interface OutputSchema {...}\n genObject(file, imports, lexUri, schema, `OutputSchema`, {\n defaultsArePresent,\n })\n }\n }\n}\n\nexport function genRecord(\n file: SourceFile,\n imports: Set<string>,\n lexicons: Lexicons,\n lexUri: string,\n) {\n const hash = getHash(lexUri)\n const ifaceName: string = toTitleCase(hash)\n const def = lexicons.getDefOrThrow(lexUri, ['record'])\n\n //= export interface {X} {...}\n genObject(file, imports, lexUri, def.record, ifaceName, {\n defaultsArePresent: true,\n allowUnknownProperties: true,\n typeProperty: 'required',\n })\n\n //= export function is{X}(v: unknown): v is {X} {...}\n genObjHelpers(file, lexUri, ifaceName, {\n requireTypeProperty: true,\n })\n\n // For convenience, we re-export the type and the type guard under the generic\n // names \"Record\", \"isRecord\" and \"validateRecord\".\n // @NOTE This does not account for potential name clashes with a potential\n // \"#record\" def.\n\n //= export { {X} as Record, is{X} as isRecord }\n file.addExportDeclaration({\n namedExports: [\n {\n isTypeOnly: true,\n name: ifaceName,\n alias: 'Record',\n },\n {\n name: `is${ifaceName}`,\n alias: 'isRecord',\n },\n {\n name: `validate${ifaceName}`,\n alias: 'validateRecord',\n },\n ],\n })\n}\n\nfunction genObjHelpers(\n file: SourceFile,\n lexUri: string,\n ifaceName: string,\n {\n requireTypeProperty,\n }: {\n requireTypeProperty: boolean\n },\n) {\n const hash = getHash(lexUri)\n\n const hashVar = `hash${ifaceName}`\n\n file.addVariableStatement({\n isExported: false,\n declarationKind: VariableDeclarationKind.Const,\n declarations: [{ name: hashVar, initializer: JSON.stringify(hash) }],\n })\n\n const isX = toCamelCase(`is-${ifaceName}`)\n\n //= export function is{X}<V>(v: V) {...}\n file\n .addFunction({\n name: isX,\n typeParameters: [{ name: `V` }],\n parameters: [{ name: `v`, type: `V` }],\n isExported: true,\n })\n .setBodyText(`return is$typed(v, id, ${hashVar})`)\n\n const validateX = toCamelCase(`validate-${ifaceName}`)\n\n //= export function validate{X}(v: unknown) {...}\n file\n .addFunction({\n name: validateX,\n typeParameters: [{ name: `V` }],\n parameters: [{ name: `v`, type: `V` }],\n isExported: true,\n })\n .setBodyText(\n `return validate<${ifaceName} & V>(v, id, ${hashVar}${requireTypeProperty ? ', true' : ''})`,\n )\n}\n\nexport function stripScheme(uri: string): string {\n if (uri.startsWith('lex:')) return uri.slice(4)\n return uri\n}\n\nexport function stripHash(uri: string): string {\n return uri.split('#')[0] || ''\n}\n\nexport function getHash(uri: string): string {\n return uri.split('#').pop() || ''\n}\n\nexport function ipldToType(def: LexCidLink | LexBytes) {\n if (def.type === 'bytes') {\n return 'Uint8Array'\n }\n return 'CID'\n}\n\nfunction refToUnionType(\n ref: string,\n lexUri: string,\n imports: Set<string>,\n): string {\n const baseNsid = stripScheme(stripHash(lexUri))\n return `$Typed<${refToType(ref, baseNsid, imports)}>`\n}\n\nfunction refToType(\n ref: string,\n baseNsid: string,\n imports: Set<string>,\n): string {\n // TODO: import external types!\n let [refBase, refHash] = ref.split('#')\n refBase = stripScheme(refBase)\n if (!refHash) refHash = 'main'\n\n // internal\n if (!refBase || baseNsid === refBase) {\n return toTitleCase(refHash)\n }\n\n // external\n imports.add(refBase)\n return `${toTitleCase(refBase)}.${toTitleCase(refHash)}`\n}\n\nexport function primitiveOrBlobToType(\n def: LexBlob | LexPrimitive | LexIpldType,\n): string {\n switch (def.type) {\n case 'blob':\n return 'BlobRef'\n case 'bytes':\n return 'Uint8Array'\n case 'cid-link':\n return 'CID'\n default:\n return primitiveToType(def)\n }\n}\n\nexport function primitiveToType(def: LexPrimitive): string {\n switch (def.type) {\n case 'string':\n if (def.knownValues?.length) {\n return `${def.knownValues\n .map((v) => JSON.stringify(v))\n .join(' | ')} | (string & {})`\n } else if (def.enum) {\n return def.enum.map((v) => JSON.stringify(v)).join(' | ')\n } else if (def.const) {\n return JSON.stringify(def.const)\n }\n return 'string'\n case 'integer':\n if (def.enum) {\n return def.enum.map((v) => JSON.stringify(v)).join(' | ')\n } else if (def.const) {\n return JSON.stringify(def.const)\n }\n return 'number'\n case 'boolean':\n if (def.const) {\n return JSON.stringify(def.const)\n }\n return 'boolean'\n case 'unknown':\n // @TODO Should we use \"object\" here ?\n // the \"Record\" identifier from typescript get overwritten by the Record\n // interface created by lex-cli.\n return '{ [_ in string]: unknown }' // Record<string, unknown>\n default:\n throw new Error(`Unexpected primitive type: ${JSON.stringify(def)}`)\n }\n}\n\nfunction makeType(\n _types: string | string[],\n opts?: { array?: boolean; nullable?: boolean },\n) {\n const types = ([] as string[]).concat(_types)\n if (opts?.nullable) types.push('null')\n const arr = opts?.array ? '[]' : ''\n if (types.length === 1) return `(${types[0]})${arr}`\n if (arr) return `(${types.join(' | ')})${arr}`\n return types.join(' | ')\n}\n"]}
|
package/dist/codegen/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type LexiconDoc } from '@atproto/lexicon';
|
|
2
|
-
import {
|
|
2
|
+
import type { GeneratedAPI } from '../types.js';
|
|
3
3
|
export declare function genServerApi(lexiconDocs: LexiconDoc[]): Promise<GeneratedAPI>;
|
|
4
4
|
//# sourceMappingURL=server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/codegen/server.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,UAAU,EAAY,MAAM,kBAAkB,CAAA;AAE5D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/codegen/server.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,UAAU,EAAY,MAAM,kBAAkB,CAAA;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAoB/C,wBAAsB,YAAY,CAChC,WAAW,EAAE,UAAU,EAAE,GACxB,OAAO,CAAC,YAAY,CAAC,CAgBvB"}
|
package/dist/codegen/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IndentationText, Project, VariableDeclarationKind, } from 'ts-morph';
|
|
1
|
+
import { IndentationText, Project, SourceFile, VariableDeclarationKind, } from 'ts-morph';
|
|
2
2
|
import { Lexicons } from '@atproto/lexicon';
|
|
3
3
|
import { NSID } from '@atproto/syntax';
|
|
4
4
|
import { gen, lexiconsTs, utilTs } from './common.js';
|