@atproto/lex-cli 0.9.9 → 0.10.0-next.0

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.
@@ -1,30 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.genServerApi = genServerApi;
4
- const ts_morph_1 = require("ts-morph");
5
- const lexicon_1 = require("@atproto/lexicon");
6
- const syntax_1 = require("@atproto/syntax");
7
- const common_1 = require("./common");
8
- const lex_gen_1 = require("./lex-gen");
9
- const util_1 = require("./util");
10
- async function genServerApi(lexiconDocs) {
11
- const project = new ts_morph_1.Project({
1
+ import { IndentationText, Project, VariableDeclarationKind, } from 'ts-morph';
2
+ import { Lexicons } from '@atproto/lexicon';
3
+ import { NSID } from '@atproto/syntax';
4
+ import { gen, lexiconsTs, utilTs } from './common.js';
5
+ import { genCommonImports, genImports, genRecord, genUserType, genXrpcInput, genXrpcOutput, genXrpcParams, } from './lex-gen.js';
6
+ import { lexiconsToDefTree, schemasToNsidTokens, toCamelCase, toScreamingSnakeCase, toTitleCase, } from './util.js';
7
+ export async function genServerApi(lexiconDocs) {
8
+ const project = new Project({
12
9
  useInMemoryFileSystem: true,
13
- manipulationSettings: { indentationText: ts_morph_1.IndentationText.TwoSpaces },
10
+ manipulationSettings: { indentationText: IndentationText.TwoSpaces },
14
11
  });
15
12
  const api = { files: [] };
16
- const lexicons = new lexicon_1.Lexicons(lexiconDocs);
17
- const nsidTree = (0, util_1.lexiconsToDefTree)(lexiconDocs);
18
- const nsidTokens = (0, util_1.schemasToNsidTokens)(lexiconDocs);
13
+ const lexicons = new Lexicons(lexiconDocs);
14
+ const nsidTree = lexiconsToDefTree(lexiconDocs);
15
+ const nsidTokens = schemasToNsidTokens(lexiconDocs);
19
16
  for (const lexiconDoc of lexiconDocs) {
20
17
  api.files.push(await lexiconTs(project, lexicons, lexiconDoc));
21
18
  }
22
- api.files.push(await (0, common_1.utilTs)(project));
23
- api.files.push(await (0, common_1.lexiconsTs)(project, lexiconDocs));
19
+ api.files.push(await utilTs(project));
20
+ api.files.push(await lexiconsTs(project, lexiconDocs));
24
21
  api.files.push(await indexTs(project, lexiconDocs, nsidTree, nsidTokens));
25
22
  return api;
26
23
  }
27
- const indexTs = (project, lexiconDocs, nsidTree, nsidTokens) => (0, common_1.gen)(project, '/index.ts', async (file) => {
24
+ const indexTs = (project, lexiconDocs, nsidTree, nsidTokens) => gen(project, '/index.ts', async (file) => {
28
25
  //= import {createServer as createXrpcServer, Server as XrpcServer} from '@atproto/xrpc-server'
29
26
  file.addImportDeclaration({
30
27
  moduleSpecifier: '@atproto/xrpc-server',
@@ -56,7 +53,7 @@ const indexTs = (project, lexiconDocs, nsidTree, nsidTokens) => (0, common_1.gen
56
53
  .addImportDeclaration({
57
54
  moduleSpecifier: `./types/${lexiconDoc.id.split('.').join('/')}.js`,
58
55
  })
59
- .setNamespaceImport((0, util_1.toTitleCase)(lexiconDoc.id));
56
+ .setNamespaceImport(toTitleCase(lexiconDoc.id));
60
57
  }
61
58
  // generate token enums
62
59
  for (const nsidAuthority in nsidTokens) {
@@ -65,13 +62,13 @@ const indexTs = (project, lexiconDocs, nsidTree, nsidTokens) => (0, common_1.gen
65
62
  // }
66
63
  file.addVariableStatement({
67
64
  isExported: true,
68
- declarationKind: ts_morph_1.VariableDeclarationKind.Const,
65
+ declarationKind: VariableDeclarationKind.Const,
69
66
  declarations: [
70
67
  {
71
- name: (0, util_1.toScreamingSnakeCase)(nsidAuthority),
68
+ name: toScreamingSnakeCase(nsidAuthority),
72
69
  initializer: [
73
70
  '{',
74
- ...nsidTokens[nsidAuthority].map((nsidName) => `${(0, util_1.toTitleCase)(nsidName)}: "${nsidAuthority}.${nsidName}",`),
71
+ ...nsidTokens[nsidAuthority].map((nsidName) => `${toTitleCase(nsidName)}: "${nsidAuthority}.${nsidName}",`),
75
72
  '}',
76
73
  ].join('\n'),
77
74
  },
@@ -163,8 +160,8 @@ function genNamespaceCls(file, ns) {
163
160
  userType.def.type !== 'procedure') {
164
161
  continue;
165
162
  }
166
- const moduleName = (0, util_1.toTitleCase)(userType.nsid);
167
- const name = (0, util_1.toCamelCase)(syntax_1.NSID.parse(userType.nsid).name || '');
163
+ const moduleName = toTitleCase(userType.nsid);
164
+ const name = toCamelCase(NSID.parse(userType.nsid).name || '');
168
165
  const isSubscription = userType.def.type === 'subscription';
169
166
  const method = cls.addMethod({
170
167
  name,
@@ -200,7 +197,7 @@ function genNamespaceCls(file, ns) {
200
197
  ].join('\n'));
201
198
  }
202
199
  }
203
- const lexiconTs = (project, lexicons, lexiconDoc) => (0, common_1.gen)(project, `/types/${lexiconDoc.id.split('.').join('/')}.ts`, async (file) => {
200
+ const lexiconTs = (project, lexicons, lexiconDoc) => gen(project, `/types/${lexiconDoc.id.split('.').join('/')}.ts`, async (file) => {
204
201
  const main = lexiconDoc.defs.main;
205
202
  if (main?.type === 'query' || main?.type === 'procedure') {
206
203
  const streamingInput = main?.type === 'procedure' &&
@@ -215,35 +212,35 @@ const lexiconTs = (project, lexicons, lexiconDoc) => (0, common_1.gen)(project,
215
212
  });
216
213
  }
217
214
  }
218
- (0, lex_gen_1.genCommonImports)(file, lexiconDoc.id);
215
+ genCommonImports(file, lexiconDoc.id);
219
216
  const imports = new Set();
220
217
  for (const defId in lexiconDoc.defs) {
221
218
  const def = lexiconDoc.defs[defId];
222
219
  const lexUri = `${lexiconDoc.id}#${defId}`;
223
220
  if (defId === 'main') {
224
221
  if (def.type === 'query' || def.type === 'procedure') {
225
- (0, lex_gen_1.genXrpcParams)(file, lexicons, lexUri);
226
- (0, lex_gen_1.genXrpcInput)(file, imports, lexicons, lexUri);
227
- (0, lex_gen_1.genXrpcOutput)(file, imports, lexicons, lexUri, false);
222
+ genXrpcParams(file, lexicons, lexUri);
223
+ genXrpcInput(file, imports, lexicons, lexUri);
224
+ genXrpcOutput(file, imports, lexicons, lexUri, false);
228
225
  genServerXrpcMethod(file, lexicons, lexUri);
229
226
  }
230
227
  else if (def.type === 'subscription') {
231
- (0, lex_gen_1.genXrpcParams)(file, lexicons, lexUri);
232
- (0, lex_gen_1.genXrpcOutput)(file, imports, lexicons, lexUri, false);
228
+ genXrpcParams(file, lexicons, lexUri);
229
+ genXrpcOutput(file, imports, lexicons, lexUri, false);
233
230
  genServerXrpcStreaming(file, lexicons, lexUri);
234
231
  }
235
232
  else if (def.type === 'record') {
236
- (0, lex_gen_1.genRecord)(file, imports, lexicons, lexUri);
233
+ genRecord(file, imports, lexicons, lexUri);
237
234
  }
238
235
  else {
239
- (0, lex_gen_1.genUserType)(file, imports, lexicons, lexUri);
236
+ genUserType(file, imports, lexicons, lexUri);
240
237
  }
241
238
  }
242
239
  else {
243
- (0, lex_gen_1.genUserType)(file, imports, lexicons, lexUri);
240
+ genUserType(file, imports, lexicons, lexUri);
244
241
  }
245
242
  }
246
- (0, lex_gen_1.genImports)(file, imports, lexiconDoc.id);
243
+ genImports(file, imports, lexiconDoc.id);
247
244
  });
248
245
  function genServerXrpcMethod(file, lexicons, lexUri) {
249
246
  const def = lexicons.getDefOrThrow(lexUri, ['query', 'procedure']);
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/codegen/server.ts"],"names":[],"mappings":";;AA4BA,oCAkBC;AA9CD,uCAKiB;AACjB,8CAA4D;AAC5D,4CAAsC;AAEtC,qCAAkD;AAClD,uCAQkB;AAClB,iCAOe;AAER,KAAK,UAAU,YAAY,CAChC,WAAyB;IAEzB,MAAM,OAAO,GAAG,IAAI,kBAAO,CAAC;QAC1B,qBAAqB,EAAE,IAAI;QAC3B,oBAAoB,EAAE,EAAE,eAAe,EAAE,0BAAe,CAAC,SAAS,EAAE;KACrE,CAAC,CAAA;IACF,MAAM,GAAG,GAAiB,EAAE,KAAK,EAAE,EAAE,EAAE,CAAA;IACvC,MAAM,QAAQ,GAAG,IAAI,kBAAQ,CAAC,WAAW,CAAC,CAAA;IAC1C,MAAM,QAAQ,GAAG,IAAA,wBAAi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AAkB,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,EAAE;KACxE,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,GAAc;IAClC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC;QACjB,OAAO,OAAO,CAAA;IAChB,CAAC;IACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACnD,CAAC","sourcesContent":["import {\n IndentationText,\n Project,\n SourceFile,\n VariableDeclarationKind,\n} from 'ts-morph'\nimport { type LexiconDoc, Lexicons } from '@atproto/lexicon'\nimport { NSID } from '@atproto/syntax'\nimport { type GeneratedAPI } from '../types'\nimport { gen, lexiconsTs, utilTs } from './common'\nimport {\n genCommonImports,\n genImports,\n genRecord,\n genUserType,\n genXrpcInput,\n genXrpcOutput,\n genXrpcParams,\n} from './lex-gen'\nimport {\n type DefTreeNode,\n lexiconsToDefTree,\n schemasToNsidTokens,\n toCamelCase,\n toScreamingSnakeCase,\n toTitleCase,\n} from './util'\n\nexport async function genServerApi(\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 {createServer as createXrpcServer, Server as XrpcServer} from '@atproto/xrpc-server'\n file.addImportDeclaration({\n moduleSpecifier: '@atproto/xrpc-server',\n namedImports: [\n { name: 'Auth', isTypeOnly: true },\n { name: 'Options', alias: 'XrpcOptions', isTypeOnly: true },\n { name: 'Server', alias: 'XrpcServer' },\n { name: 'StreamConfigOrHandler', isTypeOnly: true },\n { name: 'MethodConfigOrHandler', isTypeOnly: true },\n { name: 'createServer', alias: 'createXrpcServer' },\n ],\n })\n //= import {schemas} from './lexicons.js'\n file\n .addImportDeclaration({\n moduleSpecifier: './lexicons.js',\n })\n .addNamedImport({\n name: 'schemas',\n })\n\n // generate type imports\n for (const lexiconDoc of lexiconDocs) {\n if (\n lexiconDoc.defs.main?.type !== 'query' &&\n lexiconDoc.defs.main?.type !== 'subscription' &&\n lexiconDoc.defs.main?.type !== 'procedure'\n ) {\n continue\n }\n file\n .addImportDeclaration({\n moduleSpecifier: `./types/${lexiconDoc.id.split('.').join('/')}.js`,\n })\n .setNamespaceImport(toTitleCase(lexiconDoc.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 function createServer(options?: XrpcOptions) { ... }\n const createServerFn = file.addFunction({\n name: 'createServer',\n returnType: 'Server',\n parameters: [\n { name: 'options', type: 'XrpcOptions', hasQuestionToken: true },\n ],\n isExported: true,\n })\n createServerFn.setBodyText(`return new Server(options)`)\n\n //= export class Server {...}\n const serverCls = file.addClass({\n name: 'Server',\n isExported: true,\n })\n //= xrpc: XrpcServer = createXrpcServer(methodSchemas)\n serverCls.addProperty({\n name: 'xrpc',\n type: 'XrpcServer',\n })\n\n // generate classes for the schemas\n for (const ns of nsidTree) {\n //= ns: NS\n serverCls.addProperty({\n name: ns.propName,\n type: ns.className,\n })\n\n // class...\n genNamespaceCls(file, ns)\n }\n\n //= constructor (options?: XrpcOptions) {\n //= this.xrpc = createXrpcServer(schemas, options)\n //= {namespace declarations}\n //= }\n serverCls\n .addConstructor({\n parameters: [\n { name: 'options', type: 'XrpcOptions', hasQuestionToken: true },\n ],\n })\n .setBodyText(\n [\n 'this.xrpc = createXrpcServer(schemas, options)',\n ...nsidTree.map(\n (ns) => `this.${ns.propName} = new ${ns.className}(this)`,\n ),\n ].join('\\n'),\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 //= _server: Server\n cls.addProperty({\n name: '_server',\n type: 'Server',\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(server: Server) {\n //= this._server = server\n //= {child namespace declarations}\n //= }\n const cons = cls.addConstructor()\n cons.addParameter({\n name: 'server',\n type: 'Server',\n })\n cons.setBodyText(\n [\n `this._server = server`,\n ...ns.children.map(\n (ns) => `this.${ns.propName} = new ${ns.className}(server)`,\n ),\n ].join('\\n'),\n )\n\n // methods\n for (const userType of ns.userTypes) {\n if (\n userType.def.type !== 'query' &&\n userType.def.type !== 'subscription' &&\n userType.def.type !== 'procedure'\n ) {\n continue\n }\n const moduleName = toTitleCase(userType.nsid)\n const name = toCamelCase(NSID.parse(userType.nsid).name || '')\n const isSubscription = userType.def.type === 'subscription'\n const method = cls.addMethod({\n name,\n typeParameters: [\n {\n name: 'A',\n constraint: 'Auth',\n default: 'void',\n },\n ],\n })\n method.addParameter({\n name: 'cfg',\n type: isSubscription\n ? `StreamConfigOrHandler<\n A,\n ${moduleName}.QueryParams,\n ${moduleName}.HandlerOutput,\n >`\n : `MethodConfigOrHandler<\n A,\n ${moduleName}.QueryParams,\n ${moduleName}.HandlerInput,\n ${moduleName}.HandlerOutput,\n >`,\n })\n const methodType = isSubscription ? 'streamMethod' : 'method'\n method.setBodyText(\n [\n // Placing schema on separate line, since the following one was being formatted\n // into multiple lines and causing the ts-ignore to ignore the wrong line.\n `const nsid = '${userType.nsid}' // @ts-ignore`,\n `return this._server.xrpc.${methodType}(nsid, cfg)`,\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 (main?.type === 'query' || main?.type === 'procedure') {\n const streamingInput =\n main?.type === 'procedure' &&\n main.input?.encoding &&\n !main.input.schema\n const streamingOutput = main.output?.encoding && !main.output.schema\n if (streamingInput || streamingOutput) {\n //= import stream from 'node:stream'\n file.addImportDeclaration({\n moduleSpecifier: 'node:stream',\n defaultImport: 'stream',\n })\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)\n genXrpcInput(file, imports, lexicons, lexUri)\n genXrpcOutput(file, imports, lexicons, lexUri, false)\n genServerXrpcMethod(file, lexicons, lexUri)\n } else if (def.type === 'subscription') {\n genXrpcParams(file, lexicons, lexUri)\n genXrpcOutput(file, imports, lexicons, lexUri, false)\n genServerXrpcStreaming(file, lexicons, lexUri)\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 genServerXrpcMethod(\n file: SourceFile,\n lexicons: Lexicons,\n lexUri: string,\n) {\n const def = lexicons.getDefOrThrow(lexUri, ['query', 'procedure'])\n\n //= export interface HandlerInput {...}\n if (def.type === 'procedure' && def.input?.encoding) {\n const handlerInput = file.addInterface({\n name: 'HandlerInput',\n isExported: true,\n })\n\n handlerInput.addProperty({\n name: 'encoding',\n type: def.input.encoding\n .split(',')\n .map((v) => `'${v.trim()}'`)\n .join(' | '),\n })\n handlerInput.addProperty({\n name: 'body',\n type: def.input.schema\n ? def.input.encoding.includes(',')\n ? 'InputSchema | stream.Readable'\n : 'InputSchema'\n : 'stream.Readable',\n })\n } else {\n file.addTypeAlias({\n isExported: true,\n name: 'HandlerInput',\n type: 'void',\n })\n }\n\n // export interface HandlerSuccess {...}\n let hasHandlerSuccess = false\n if (def.output?.schema || def.output?.encoding) {\n hasHandlerSuccess = true\n const handlerSuccess = file.addInterface({\n name: 'HandlerSuccess',\n isExported: true,\n })\n\n if (def.output.encoding) {\n handlerSuccess.addProperty({\n name: 'encoding',\n type: def.output.encoding\n .split(',')\n .map((v) => `'${v.trim()}'`)\n .join(' | '),\n })\n }\n if (def.output?.schema) {\n if (def.output.encoding.includes(',')) {\n handlerSuccess.addProperty({\n name: 'body',\n type: 'OutputSchema | Uint8Array | stream.Readable',\n })\n } else {\n handlerSuccess.addProperty({ name: 'body', type: 'OutputSchema' })\n }\n } else if (def.output?.encoding) {\n handlerSuccess.addProperty({\n name: 'body',\n type: 'Uint8Array | stream.Readable',\n })\n }\n handlerSuccess.addProperty({\n name: 'headers?',\n type: '{ [key: string]: string }',\n })\n }\n\n // export interface HandlerError {...}\n const handlerError = file.addInterface({\n name: 'HandlerError',\n isExported: true,\n })\n handlerError.addProperties([\n { name: 'status', type: 'number' },\n { name: 'message?', type: 'string' },\n ])\n if (def.errors?.length) {\n handlerError.addProperty({\n name: 'error?',\n type: def.errors.map((err) => `'${err.name}'`).join(' | '),\n })\n }\n\n // export type HandlerOutput = ...\n file.addTypeAlias({\n isExported: true,\n name: 'HandlerOutput',\n type: `HandlerError | ${hasHandlerSuccess ? 'HandlerSuccess' : 'void'}`,\n })\n}\n\nfunction genServerXrpcStreaming(\n file: SourceFile,\n lexicons: Lexicons,\n lexUri: string,\n) {\n const def = lexicons.getDefOrThrow(lexUri, ['subscription'])\n\n file.addImportDeclaration({\n moduleSpecifier: '@atproto/xrpc-server',\n namedImports: [{ name: 'ErrorFrame' }],\n })\n\n file.addImportDeclaration({\n moduleSpecifier: 'node:http',\n namedImports: [{ name: 'IncomingMessage' }],\n })\n\n // export type HandlerError = ...\n file.addTypeAlias({\n name: 'HandlerError',\n isExported: true,\n type: `ErrorFrame<${arrayToUnion(def.errors?.map((e) => e.name))}>`,\n })\n\n // export type HandlerOutput = ...\n file.addTypeAlias({\n isExported: true,\n name: 'HandlerOutput',\n type: `HandlerError | ${def.message?.schema ? 'OutputSchema' : 'void'}`,\n })\n}\n\nfunction arrayToUnion(arr?: string[]) {\n if (!arr?.length) {\n return 'never'\n }\n return arr.map((item) => `'${item}'`).join(' | ')\n}\n"]}
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/codegen/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,OAAO,EAEP,uBAAuB,GACxB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAmB,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC5D,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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,EAAE,IAAI;QAChB,IAAI,EAAE,cAAc,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG;KACpE,CAAC,CAAA;IAEF,kCAAkC;IAClC,IAAI,CAAC,YAAY,CAAC;QAChB,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,eAAe;QACrB,IAAI,EAAE,kBAAkB,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,EAAE;KACxE,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,GAAc;IAClC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC;QACjB,OAAO,OAAO,CAAA;IAChB,CAAC;IACD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACnD,CAAC","sourcesContent":["import {\n IndentationText,\n Project,\n SourceFile,\n VariableDeclarationKind,\n} from 'ts-morph'\nimport { 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\nexport async function genServerApi(\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 {createServer as createXrpcServer, Server as XrpcServer} from '@atproto/xrpc-server'\n file.addImportDeclaration({\n moduleSpecifier: '@atproto/xrpc-server',\n namedImports: [\n { name: 'Auth', isTypeOnly: true },\n { name: 'Options', alias: 'XrpcOptions', isTypeOnly: true },\n { name: 'Server', alias: 'XrpcServer' },\n { name: 'StreamConfigOrHandler', isTypeOnly: true },\n { name: 'MethodConfigOrHandler', isTypeOnly: true },\n { name: 'createServer', alias: 'createXrpcServer' },\n ],\n })\n //= import {schemas} from './lexicons.js'\n file\n .addImportDeclaration({\n moduleSpecifier: './lexicons.js',\n })\n .addNamedImport({\n name: 'schemas',\n })\n\n // generate type imports\n for (const lexiconDoc of lexiconDocs) {\n if (\n lexiconDoc.defs.main?.type !== 'query' &&\n lexiconDoc.defs.main?.type !== 'subscription' &&\n lexiconDoc.defs.main?.type !== 'procedure'\n ) {\n continue\n }\n file\n .addImportDeclaration({\n moduleSpecifier: `./types/${lexiconDoc.id.split('.').join('/')}.js`,\n })\n .setNamespaceImport(toTitleCase(lexiconDoc.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 function createServer(options?: XrpcOptions) { ... }\n const createServerFn = file.addFunction({\n name: 'createServer',\n returnType: 'Server',\n parameters: [\n { name: 'options', type: 'XrpcOptions', hasQuestionToken: true },\n ],\n isExported: true,\n })\n createServerFn.setBodyText(`return new Server(options)`)\n\n //= export class Server {...}\n const serverCls = file.addClass({\n name: 'Server',\n isExported: true,\n })\n //= xrpc: XrpcServer = createXrpcServer(methodSchemas)\n serverCls.addProperty({\n name: 'xrpc',\n type: 'XrpcServer',\n })\n\n // generate classes for the schemas\n for (const ns of nsidTree) {\n //= ns: NS\n serverCls.addProperty({\n name: ns.propName,\n type: ns.className,\n })\n\n // class...\n genNamespaceCls(file, ns)\n }\n\n //= constructor (options?: XrpcOptions) {\n //= this.xrpc = createXrpcServer(schemas, options)\n //= {namespace declarations}\n //= }\n serverCls\n .addConstructor({\n parameters: [\n { name: 'options', type: 'XrpcOptions', hasQuestionToken: true },\n ],\n })\n .setBodyText(\n [\n 'this.xrpc = createXrpcServer(schemas, options)',\n ...nsidTree.map(\n (ns) => `this.${ns.propName} = new ${ns.className}(this)`,\n ),\n ].join('\\n'),\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 //= _server: Server\n cls.addProperty({\n name: '_server',\n type: 'Server',\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(server: Server) {\n //= this._server = server\n //= {child namespace declarations}\n //= }\n const cons = cls.addConstructor()\n cons.addParameter({\n name: 'server',\n type: 'Server',\n })\n cons.setBodyText(\n [\n `this._server = server`,\n ...ns.children.map(\n (ns) => `this.${ns.propName} = new ${ns.className}(server)`,\n ),\n ].join('\\n'),\n )\n\n // methods\n for (const userType of ns.userTypes) {\n if (\n userType.def.type !== 'query' &&\n userType.def.type !== 'subscription' &&\n userType.def.type !== 'procedure'\n ) {\n continue\n }\n const moduleName = toTitleCase(userType.nsid)\n const name = toCamelCase(NSID.parse(userType.nsid).name || '')\n const isSubscription = userType.def.type === 'subscription'\n const method = cls.addMethod({\n name,\n typeParameters: [\n {\n name: 'A',\n constraint: 'Auth',\n default: 'void',\n },\n ],\n })\n method.addParameter({\n name: 'cfg',\n type: isSubscription\n ? `StreamConfigOrHandler<\n A,\n ${moduleName}.QueryParams,\n ${moduleName}.HandlerOutput,\n >`\n : `MethodConfigOrHandler<\n A,\n ${moduleName}.QueryParams,\n ${moduleName}.HandlerInput,\n ${moduleName}.HandlerOutput,\n >`,\n })\n const methodType = isSubscription ? 'streamMethod' : 'method'\n method.setBodyText(\n [\n // Placing schema on separate line, since the following one was being formatted\n // into multiple lines and causing the ts-ignore to ignore the wrong line.\n `const nsid = '${userType.nsid}' // @ts-ignore`,\n `return this._server.xrpc.${methodType}(nsid, cfg)`,\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 (main?.type === 'query' || main?.type === 'procedure') {\n const streamingInput =\n main?.type === 'procedure' &&\n main.input?.encoding &&\n !main.input.schema\n const streamingOutput = main.output?.encoding && !main.output.schema\n if (streamingInput || streamingOutput) {\n //= import stream from 'node:stream'\n file.addImportDeclaration({\n moduleSpecifier: 'node:stream',\n defaultImport: 'stream',\n })\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)\n genXrpcInput(file, imports, lexicons, lexUri)\n genXrpcOutput(file, imports, lexicons, lexUri, false)\n genServerXrpcMethod(file, lexicons, lexUri)\n } else if (def.type === 'subscription') {\n genXrpcParams(file, lexicons, lexUri)\n genXrpcOutput(file, imports, lexicons, lexUri, false)\n genServerXrpcStreaming(file, lexicons, lexUri)\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 genServerXrpcMethod(\n file: SourceFile,\n lexicons: Lexicons,\n lexUri: string,\n) {\n const def = lexicons.getDefOrThrow(lexUri, ['query', 'procedure'])\n\n //= export interface HandlerInput {...}\n if (def.type === 'procedure' && def.input?.encoding) {\n const handlerInput = file.addInterface({\n name: 'HandlerInput',\n isExported: true,\n })\n\n handlerInput.addProperty({\n name: 'encoding',\n type: def.input.encoding\n .split(',')\n .map((v) => `'${v.trim()}'`)\n .join(' | '),\n })\n handlerInput.addProperty({\n name: 'body',\n type: def.input.schema\n ? def.input.encoding.includes(',')\n ? 'InputSchema | stream.Readable'\n : 'InputSchema'\n : 'stream.Readable',\n })\n } else {\n file.addTypeAlias({\n isExported: true,\n name: 'HandlerInput',\n type: 'void',\n })\n }\n\n // export interface HandlerSuccess {...}\n let hasHandlerSuccess = false\n if (def.output?.schema || def.output?.encoding) {\n hasHandlerSuccess = true\n const handlerSuccess = file.addInterface({\n name: 'HandlerSuccess',\n isExported: true,\n })\n\n if (def.output.encoding) {\n handlerSuccess.addProperty({\n name: 'encoding',\n type: def.output.encoding\n .split(',')\n .map((v) => `'${v.trim()}'`)\n .join(' | '),\n })\n }\n if (def.output?.schema) {\n if (def.output.encoding.includes(',')) {\n handlerSuccess.addProperty({\n name: 'body',\n type: 'OutputSchema | Uint8Array | stream.Readable',\n })\n } else {\n handlerSuccess.addProperty({ name: 'body', type: 'OutputSchema' })\n }\n } else if (def.output?.encoding) {\n handlerSuccess.addProperty({\n name: 'body',\n type: 'Uint8Array | stream.Readable',\n })\n }\n handlerSuccess.addProperty({\n name: 'headers?',\n type: '{ [key: string]: string }',\n })\n }\n\n // export interface HandlerError {...}\n const handlerError = file.addInterface({\n name: 'HandlerError',\n isExported: true,\n })\n handlerError.addProperties([\n { name: 'status', type: 'number' },\n { name: 'message?', type: 'string' },\n ])\n if (def.errors?.length) {\n handlerError.addProperty({\n name: 'error?',\n type: def.errors.map((err) => `'${err.name}'`).join(' | '),\n })\n }\n\n // export type HandlerOutput = ...\n file.addTypeAlias({\n isExported: true,\n name: 'HandlerOutput',\n type: `HandlerError | ${hasHandlerSuccess ? 'HandlerSuccess' : 'void'}`,\n })\n}\n\nfunction genServerXrpcStreaming(\n file: SourceFile,\n lexicons: Lexicons,\n lexUri: string,\n) {\n const def = lexicons.getDefOrThrow(lexUri, ['subscription'])\n\n file.addImportDeclaration({\n moduleSpecifier: '@atproto/xrpc-server',\n namedImports: [{ name: 'ErrorFrame' }],\n })\n\n file.addImportDeclaration({\n moduleSpecifier: 'node:http',\n namedImports: [{ name: 'IncomingMessage' }],\n })\n\n // export type HandlerError = ...\n file.addTypeAlias({\n name: 'HandlerError',\n isExported: true,\n type: `ErrorFrame<${arrayToUnion(def.errors?.map((e) => e.name))}>`,\n })\n\n // export type HandlerOutput = ...\n file.addTypeAlias({\n isExported: true,\n name: 'HandlerOutput',\n type: `HandlerError | ${def.message?.schema ? 'OutputSchema' : 'void'}`,\n })\n}\n\nfunction arrayToUnion(arr?: string[]) {\n if (!arr?.length) {\n return 'never'\n }\n return arr.map((item) => `'${item}'`).join(' | ')\n}\n"]}
@@ -1,12 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lexiconsToDefTree = lexiconsToDefTree;
4
- exports.schemasToNsidTokens = schemasToNsidTokens;
5
- exports.toTitleCase = toTitleCase;
6
- exports.toCamelCase = toCamelCase;
7
- exports.toScreamingSnakeCase = toScreamingSnakeCase;
8
- const syntax_1 = require("@atproto/syntax");
9
- function lexiconsToDefTree(lexicons) {
1
+ import { NSID } from '@atproto/syntax';
2
+ export function lexiconsToDefTree(lexicons) {
10
3
  const tree = [];
11
4
  for (const lexicon of lexicons) {
12
5
  if (!lexicon.defs.main) {
@@ -38,10 +31,10 @@ function getOrCreateNode(tree, path) {
38
31
  throw new Error(`Invalid schema path: ${path.join('.')}`);
39
32
  return node;
40
33
  }
41
- function schemasToNsidTokens(lexiconDocs) {
34
+ export function schemasToNsidTokens(lexiconDocs) {
42
35
  const nsidTokens = {};
43
36
  for (const lexiconDoc of lexiconDocs) {
44
- const nsidp = syntax_1.NSID.parse(lexiconDoc.id);
37
+ const nsidp = NSID.parse(lexiconDoc.id);
45
38
  if (!nsidp.name)
46
39
  continue;
47
40
  for (const defId in lexiconDoc.defs) {
@@ -49,22 +42,22 @@ function schemasToNsidTokens(lexiconDocs) {
49
42
  if (def.type !== 'token')
50
43
  continue;
51
44
  const authority = nsidp.segments.slice(0, -1).join('.');
52
- nsidTokens[authority] ?? (nsidTokens[authority] = []);
45
+ nsidTokens[authority] ??= [];
53
46
  nsidTokens[authority].push(nsidp.name + (defId === 'main' ? '' : `#${defId}`));
54
47
  }
55
48
  }
56
49
  return nsidTokens;
57
50
  }
58
- function toTitleCase(v) {
51
+ export function toTitleCase(v) {
59
52
  v = v.replace(/^([a-z])/gi, (_, g) => g.toUpperCase()); // upper-case first letter
60
53
  v = v.replace(/[.#-]([a-z])/gi, (_, g) => g.toUpperCase()); // uppercase any dash, dot, or hash segments
61
54
  return v.replace(/[.-]/g, ''); // remove lefover dashes or dots
62
55
  }
63
- function toCamelCase(v) {
56
+ export function toCamelCase(v) {
64
57
  v = v.replace(/[.#-]([a-z])/gi, (_, g) => g.toUpperCase()); // uppercase any dash, dot, or hash segments
65
58
  return v.replace(/[.-]/g, ''); // remove lefover dashes or dots
66
59
  }
67
- function toScreamingSnakeCase(v) {
60
+ export function toScreamingSnakeCase(v) {
68
61
  v = v.replace(/[.#-]+/gi, '_'); // convert dashes, dots, and hashes into underscores
69
62
  return v.toUpperCase(); // and scream!
70
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/codegen/util.ts"],"names":[],"mappings":";;AAgBA,8CAUC;AAuBD,kDAkBC;AAED,kCAIC;AAED,kCAGC;AAED,oDAGC;AAlFD,4CAAsC;AAetC,SAAgB,iBAAiB,CAAC,QAAsB;IACtD,MAAM,IAAI,GAAkB,EAAE,CAAA;IAC9B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACvB,SAAQ;QACV,CAAC;QACD,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;QACtE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IACnE,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,eAAe,CAAC,IAAmB,EAAE,IAAc;IAC1D,IAAI,IAA6B,CAAA;IACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;QACvB,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAA;QAC3C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,GAAG;gBAC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CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC,CACnD,CAAA;QACH,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,SAAgB,WAAW,CAAC,CAAS;IACnC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA,CAAC,0BAA0B;IACjF,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA,CAAC,4CAA4C;IACvG,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA,CAAC,gCAAgC;AAChE,CAAC;AAED,SAAgB,WAAW,CAAC,CAAS;IACnC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA,CAAC,4CAA4C;IACvG,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA,CAAC,gCAAgC;AAChE,CAAC;AAED,SAAgB,oBAAoB,CAAC,CAAS;IAC5C,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA,CAAC,oDAAoD;IACnF,OAAO,CAAC,CAAC,WAAW,EAAE,CAAA,CAAC,cAAc;AACvC,CAAC","sourcesContent":["import { type LexUserType, type LexiconDoc } from '@atproto/lexicon'\nimport { NSID } from '@atproto/syntax'\n\nexport interface DefTreeNodeUserType {\n nsid: string\n def: LexUserType\n}\n\nexport interface DefTreeNode {\n name: string\n className: string\n propName: string\n children: DefTreeNode[]\n userTypes: DefTreeNodeUserType[]\n}\n\nexport function lexiconsToDefTree(lexicons: LexiconDoc[]): DefTreeNode[] {\n const tree: DefTreeNode[] = []\n for (const lexicon of lexicons) {\n if (!lexicon.defs.main) {\n continue\n }\n const node = getOrCreateNode(tree, lexicon.id.split('.').slice(0, -1))\n node.userTypes.push({ nsid: lexicon.id, def: lexicon.defs.main })\n }\n return tree\n}\n\nfunction getOrCreateNode(tree: DefTreeNode[], path: string[]): DefTreeNode {\n let node: DefTreeNode | undefined\n for (let i = 0; i < path.length; i++) {\n const segment = path[i]\n node = tree.find((v) => v.name === segment)\n if (!node) {\n node = {\n name: segment,\n className: `${toTitleCase(path.slice(0, i + 1).join('-'))}NS`,\n propName: toCamelCase(segment),\n children: [],\n userTypes: [],\n } as DefTreeNode\n tree.push(node)\n }\n tree = node.children\n }\n if (!node) throw new Error(`Invalid schema path: ${path.join('.')}`)\n return node\n}\n\nexport function schemasToNsidTokens(\n lexiconDocs: LexiconDoc[],\n): Record<string, string[]> {\n const nsidTokens: Record<string, string[]> = {}\n for (const lexiconDoc of lexiconDocs) {\n const nsidp = NSID.parse(lexiconDoc.id)\n if (!nsidp.name) continue\n for (const defId in lexiconDoc.defs) {\n const def = lexiconDoc.defs[defId]\n if (def.type !== 'token') continue\n const authority = nsidp.segments.slice(0, -1).join('.')\n nsidTokens[authority] ??= []\n nsidTokens[authority].push(\n nsidp.name + (defId === 'main' ? '' : `#${defId}`),\n )\n }\n }\n return nsidTokens\n}\n\nexport function toTitleCase(v: string): string {\n v = v.replace(/^([a-z])/gi, (_, g) => g.toUpperCase()) // upper-case first letter\n v = v.replace(/[.#-]([a-z])/gi, (_, g) => g.toUpperCase()) // uppercase any dash, dot, or hash segments\n return v.replace(/[.-]/g, '') // remove lefover dashes or dots\n}\n\nexport function toCamelCase(v: string): string {\n v = v.replace(/[.#-]([a-z])/gi, (_, g) => g.toUpperCase()) // uppercase any dash, dot, or hash segments\n return v.replace(/[.-]/g, '') // remove lefover dashes or dots\n}\n\nexport function toScreamingSnakeCase(v: string): string {\n v = v.replace(/[.#-]+/gi, '_') // convert dashes, dots, and hashes into underscores\n return v.toUpperCase() // and scream!\n}\n"]}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/codegen/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAetC,MAAM,UAAU,iBAAiB,CAAC,QAAsB;IACtD,MAAM,IAAI,GAAkB,EAAE,CAAA;IAC9B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACvB,SAAQ;QACV,CAAC;QACD,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;QACtE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IACnE,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,eAAe,CAAC,IAAmB,EAAE,IAAc;IAC1D,IAAI,IAA6B,CAAA;IACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;QACvB,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAA;QAC3C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,GAAG;gBACL,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,K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,CAAC,CACnD,CAAA;QACH,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAS;IACnC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA,CAAC,0BAA0B;IACjF,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA,CAAC,4CAA4C;IACvG,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA,CAAC,gCAAgC;AAChE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAS;IACnC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAA,CAAC,4CAA4C;IACvG,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA,CAAC,gCAAgC;AAChE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,CAAS;IAC5C,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA,CAAC,oDAAoD;IACnF,OAAO,CAAC,CAAC,WAAW,EAAE,CAAA,CAAC,cAAc;AACvC,CAAC","sourcesContent":["import { type LexUserType, type LexiconDoc } from '@atproto/lexicon'\nimport { NSID } from '@atproto/syntax'\n\nexport interface DefTreeNodeUserType {\n nsid: string\n def: LexUserType\n}\n\nexport interface DefTreeNode {\n name: string\n className: string\n propName: string\n children: DefTreeNode[]\n userTypes: DefTreeNodeUserType[]\n}\n\nexport function lexiconsToDefTree(lexicons: LexiconDoc[]): DefTreeNode[] {\n const tree: DefTreeNode[] = []\n for (const lexicon of lexicons) {\n if (!lexicon.defs.main) {\n continue\n }\n const node = getOrCreateNode(tree, lexicon.id.split('.').slice(0, -1))\n node.userTypes.push({ nsid: lexicon.id, def: lexicon.defs.main })\n }\n return tree\n}\n\nfunction getOrCreateNode(tree: DefTreeNode[], path: string[]): DefTreeNode {\n let node: DefTreeNode | undefined\n for (let i = 0; i < path.length; i++) {\n const segment = path[i]\n node = tree.find((v) => v.name === segment)\n if (!node) {\n node = {\n name: segment,\n className: `${toTitleCase(path.slice(0, i + 1).join('-'))}NS`,\n propName: toCamelCase(segment),\n children: [],\n userTypes: [],\n } as DefTreeNode\n tree.push(node)\n }\n tree = node.children\n }\n if (!node) throw new Error(`Invalid schema path: ${path.join('.')}`)\n return node\n}\n\nexport function schemasToNsidTokens(\n lexiconDocs: LexiconDoc[],\n): Record<string, string[]> {\n const nsidTokens: Record<string, string[]> = {}\n for (const lexiconDoc of lexiconDocs) {\n const nsidp = NSID.parse(lexiconDoc.id)\n if (!nsidp.name) continue\n for (const defId in lexiconDoc.defs) {\n const def = lexiconDoc.defs[defId]\n if (def.type !== 'token') continue\n const authority = nsidp.segments.slice(0, -1).join('.')\n nsidTokens[authority] ??= []\n nsidTokens[authority].push(\n nsidp.name + (defId === 'main' ? '' : `#${defId}`),\n )\n }\n }\n return nsidTokens\n}\n\nexport function toTitleCase(v: string): string {\n v = v.replace(/^([a-z])/gi, (_, g) => g.toUpperCase()) // upper-case first letter\n v = v.replace(/[.#-]([a-z])/gi, (_, g) => g.toUpperCase()) // uppercase any dash, dot, or hash segments\n return v.replace(/[.-]/g, '') // remove lefover dashes or dots\n}\n\nexport function toCamelCase(v: string): string {\n v = v.replace(/[.#-]([a-z])/gi, (_, g) => g.toUpperCase()) // uppercase any dash, dot, or hash segments\n return v.replace(/[.-]/g, '') // remove lefover dashes or dots\n}\n\nexport function toScreamingSnakeCase(v: string): string {\n v = v.replace(/[.#-]+/gi, '_') // convert dashes, dots, and hashes into underscores\n return v.toUpperCase() // and scream!\n}\n"]}
package/dist/index.js CHANGED
@@ -1,50 +1,12 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
- var __importDefault = (this && this.__importDefault) || function (mod) {
37
- return (mod && mod.__esModule) ? mod : { "default": mod };
38
- };
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- const node_path_1 = __importDefault(require("node:path"));
41
- const commander_1 = require("commander");
42
- const yesno_1 = __importDefault(require("yesno"));
43
- const client_1 = require("./codegen/client");
44
- const server_1 = require("./codegen/server");
45
- const mdGen = __importStar(require("./mdgen"));
46
- const util_1 = require("./util");
47
- const program = new commander_1.Command();
2
+ import path from 'node:path';
3
+ import { Command } from 'commander';
4
+ import yesno from 'yesno';
5
+ import { genClientApi } from './codegen/client.js';
6
+ import { genServerApi } from './codegen/server.js';
7
+ import * as mdGen from './mdgen/index.js';
8
+ import { applyFileDiff, genFileDiff, genTsObj, printFileDiff, readAllLexicons, } from './util.js';
9
+ const program = new Command();
48
10
  program.name('lex').description('Lexicon CLI').version('0.0.0');
49
11
  program
50
12
  .command('gen-md')
@@ -60,7 +22,7 @@ program
60
22
  if (!o?.yes)
61
23
  await confirmOrExit();
62
24
  console.log('Writing', outFile);
63
- const lexicons = (0, util_1.readAllLexicons)(lexiconPaths);
25
+ const lexicons = readAllLexicons(lexiconPaths);
64
26
  await mdGen.process(outFile, lexicons);
65
27
  });
66
28
  program
@@ -68,8 +30,8 @@ program
68
30
  .description('Generate a TS file that exports an array of lexicons')
69
31
  .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)
70
32
  .action((lexiconPaths) => {
71
- const lexicons = (0, util_1.readAllLexicons)(lexiconPaths);
72
- console.log((0, util_1.genTsObj)(lexicons));
33
+ const lexicons = readAllLexicons(lexiconPaths);
34
+ console.log(genTsObj(lexicons));
73
35
  });
74
36
  program
75
37
  .command('gen-api')
@@ -78,14 +40,14 @@ program
78
40
  .argument('<outdir>', 'path of the directory to write to', toPath)
79
41
  .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)
80
42
  .action(async (outDir, lexiconPaths, o) => {
81
- const lexicons = (0, util_1.readAllLexicons)(lexiconPaths);
82
- const api = await (0, client_1.genClientApi)(lexicons);
83
- const diff = (0, util_1.genFileDiff)(outDir, api);
43
+ const lexicons = readAllLexicons(lexiconPaths);
44
+ const api = await genClientApi(lexicons);
45
+ const diff = genFileDiff(outDir, api);
84
46
  console.log('This will write the following files:');
85
- (0, util_1.printFileDiff)(diff);
47
+ printFileDiff(diff);
86
48
  if (!o?.yes)
87
49
  await confirmOrExit();
88
- (0, util_1.applyFileDiff)(diff);
50
+ applyFileDiff(diff);
89
51
  console.log('API generated.');
90
52
  });
91
53
  program
@@ -95,27 +57,27 @@ program
95
57
  .argument('<outdir>', 'path of the directory to write to', toPath)
96
58
  .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)
97
59
  .action(async (outDir, lexiconPaths, o) => {
98
- const lexicons = (0, util_1.readAllLexicons)(lexiconPaths);
99
- const api = await (0, server_1.genServerApi)(lexicons);
100
- const diff = (0, util_1.genFileDiff)(outDir, api);
60
+ const lexicons = readAllLexicons(lexiconPaths);
61
+ const api = await genServerApi(lexicons);
62
+ const diff = genFileDiff(outDir, api);
101
63
  console.log('This will write the following files:');
102
- (0, util_1.printFileDiff)(diff);
64
+ printFileDiff(diff);
103
65
  if (!o?.yes)
104
66
  await confirmOrExit();
105
- (0, util_1.applyFileDiff)(diff);
67
+ applyFileDiff(diff);
106
68
  console.log('API generated.');
107
69
  });
108
70
  program.parse();
109
71
  function toPath(v) {
110
- return v ? node_path_1.default.resolve(v) : undefined;
72
+ return v ? path.resolve(v) : undefined;
111
73
  }
112
74
  function toPaths(v, acc) {
113
75
  acc = acc || [];
114
- acc.push(node_path_1.default.resolve(v));
76
+ acc.push(path.resolve(v));
115
77
  return acc;
116
78
  }
117
79
  async function confirmOrExit() {
118
- const ok = await (0, yesno_1.default)({
80
+ const ok = await yesno({
119
81
  question: 'Are you sure you want to continue? [y/N]',
120
82
  defaultValue: false,
121
83
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,0DAA4B;AAC5B,yCAAmC;AACnC,kDAAyB;AACzB,6CAA+C;AAC/C,6CAA+C;AAC/C,+CAAgC;AAChC,iCAMe;AAEf,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAA;AAC7B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAE/D,OAAO;KACJ,O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IAAA,oBAAa,EAAC,IAAI,CAAC,CAAA;IACnB,IAAI,CAAC,CAAC,EAAE,GAAG;QAAE,MAAM,aAAa,EAAE,CAAA;IAClC,IAAA,oBAAa,EAAC,IAAI,CAAC,CAAA;IACnB,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;AAC/B,CAAC,CAAC,CAAA;AAEJ,OAAO,CAAC,KAAK,EAAE,CAAA;AAEf,SAAS,MAAM,CAAC,CAAS;IACvB,OAAO,CAAC,CAAC,CAAC,CAAC,mBAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACxC,CAAC;AAED,SAAS,OAAO,CAAC,CAAS,EAAE,GAAa;IACvC,GAAG,GAAG,GAAG,IAAI,EAAE,CAAA;IACf,GAAG,CAAC,IAAI,CAAC,mBAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;IACzB,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,KAAK,UAAU,aAAa;IAC1B,MAAM,EAAE,GAAG,MAAM,IAAA,eAAK,EAAC;QACrB,QAAQ,EAAE,0CAA0C;QACpD,YAAY,EAAE,KAAK;KACpB,CAAC,CAAA;IACF,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QACvB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'node:path'\nimport { Command } from 'commander'\nimport yesno from 'yesno'\nimport { genClientApi } from './codegen/client'\nimport { genServerApi } from './codegen/server'\nimport * as mdGen from './mdgen'\nimport {\n applyFileDiff,\n genFileDiff,\n genTsObj,\n printFileDiff,\n readAllLexicons,\n} from './util'\n\nconst program = new Command()\nprogram.name('lex').description('Lexicon CLI').version('0.0.0')\n\nprogram\n .command('gen-md')\n .description('Generate markdown documentation')\n .option('--yes', 'skip confirmation')\n .argument('<outfile>', 'path of the file to write to', toPath)\n .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)\n .action(\n async (outFile: string, lexiconPaths: string[], o: { yes?: true }) => {\n if (!outFile.endsWith('.md')) {\n console.error(\n 'Must supply the path to a .md file as the first parameter',\n )\n process.exit(1)\n }\n if (!o?.yes) await confirmOrExit()\n console.log('Writing', outFile)\n const lexicons = readAllLexicons(lexiconPaths)\n await mdGen.process(outFile, lexicons)\n },\n )\n\nprogram\n .command('gen-ts-obj')\n .description('Generate a TS file that exports an array of lexicons')\n .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)\n .action((lexiconPaths: string[]) => {\n const lexicons = readAllLexicons(lexiconPaths)\n console.log(genTsObj(lexicons))\n })\n\nprogram\n .command('gen-api')\n .description('Generate a TS client API')\n .option('--yes', 'skip confirmation')\n .argument('<outdir>', 'path of the directory to write to', toPath)\n .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)\n .action(async (outDir: string, lexiconPaths: string[], o: { yes?: true }) => {\n const lexicons = readAllLexicons(lexiconPaths)\n const api = await genClientApi(lexicons)\n const diff = genFileDiff(outDir, api)\n console.log('This will write the following files:')\n printFileDiff(diff)\n if (!o?.yes) await confirmOrExit()\n applyFileDiff(diff)\n console.log('API generated.')\n })\n\nprogram\n .command('gen-server')\n .description('Generate a TS server API')\n .option('--yes', 'skip confirmation')\n .argument('<outdir>', 'path of the directory to write to', toPath)\n .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)\n .action(async (outDir: string, lexiconPaths: string[], o: { yes?: true }) => {\n const lexicons = readAllLexicons(lexiconPaths)\n const api = await genServerApi(lexicons)\n const diff = genFileDiff(outDir, api)\n console.log('This will write the following files:')\n printFileDiff(diff)\n if (!o?.yes) await confirmOrExit()\n applyFileDiff(diff)\n console.log('API generated.')\n })\n\nprogram.parse()\n\nfunction toPath(v: string) {\n return v ? path.resolve(v) : undefined\n}\n\nfunction toPaths(v: string, acc: string[]) {\n acc = acc || []\n acc.push(path.resolve(v))\n return acc\n}\n\nasync function confirmOrExit() {\n const ok = await yesno({\n question: 'Are you sure you want to continue? [y/N]',\n defaultValue: false,\n })\n if (!ok) {\n console.log('Aborted.')\n process.exit(0)\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,OAAO,EACL,aAAa,EACb,WAAW,EACX,QAAQ,EACR,aAAa,EACb,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;AAC7B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAE/D,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,WAAW,CAAC,iCAAiC,CAAC;KAC9C,MAAM,CAAC,OAAO,EAAE,mBAAmB,CAAC;KACpC,QAAQ,CAAC,WAAW,EAAE,8BAA8B,EAAE,MAAM,CAAC;KAC7D,QAAQ,CAAC,eAAe,EAAE,uCAAuC,EAAE,OAAO,CAAC;KAC3E,MAAM,CACL,KAAK,EAAE,OAAe,EAAE,YAAsB,EAAE,CAAiB,EAAE,EAAE;IACnE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,CAAC,KAAK,CACX,2DAA2D,CAC5D,CAAA;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IACD,IAAI,CAAC,CAAC,EAAE,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,CAAC;AAED,KAAK,UAAU,aAAa;IAC1B,MAAM,EAAE,GAAG,MAAM,KAAK,CAAC;QACrB,QAAQ,EAAE,0CAA0C;QACpD,YAAY,EAAE,KAAK;KACpB,CAAC,CAAA;IACF,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QACvB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'node:path'\nimport { Command } from 'commander'\nimport yesno from 'yesno'\nimport { genClientApi } from './codegen/client.js'\nimport { genServerApi } from './codegen/server.js'\nimport * as mdGen from './mdgen/index.js'\nimport {\n applyFileDiff,\n genFileDiff,\n genTsObj,\n printFileDiff,\n readAllLexicons,\n} from './util.js'\n\nconst program = new Command()\nprogram.name('lex').description('Lexicon CLI').version('0.0.0')\n\nprogram\n .command('gen-md')\n .description('Generate markdown documentation')\n .option('--yes', 'skip confirmation')\n .argument('<outfile>', 'path of the file to write to', toPath)\n .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)\n .action(\n async (outFile: string, lexiconPaths: string[], o: { yes?: true }) => {\n if (!outFile.endsWith('.md')) {\n console.error(\n 'Must supply the path to a .md file as the first parameter',\n )\n process.exit(1)\n }\n if (!o?.yes) await confirmOrExit()\n console.log('Writing', outFile)\n const lexicons = readAllLexicons(lexiconPaths)\n await mdGen.process(outFile, lexicons)\n },\n )\n\nprogram\n .command('gen-ts-obj')\n .description('Generate a TS file that exports an array of lexicons')\n .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)\n .action((lexiconPaths: string[]) => {\n const lexicons = readAllLexicons(lexiconPaths)\n console.log(genTsObj(lexicons))\n })\n\nprogram\n .command('gen-api')\n .description('Generate a TS client API')\n .option('--yes', 'skip confirmation')\n .argument('<outdir>', 'path of the directory to write to', toPath)\n .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)\n .action(async (outDir: string, lexiconPaths: string[], o: { yes?: true }) => {\n const lexicons = readAllLexicons(lexiconPaths)\n const api = await genClientApi(lexicons)\n const diff = genFileDiff(outDir, api)\n console.log('This will write the following files:')\n printFileDiff(diff)\n if (!o?.yes) await confirmOrExit()\n applyFileDiff(diff)\n console.log('API generated.')\n })\n\nprogram\n .command('gen-server')\n .description('Generate a TS server API')\n .option('--yes', 'skip confirmation')\n .argument('<outdir>', 'path of the directory to write to', toPath)\n .argument('<lexicons...>', 'paths of the lexicon files to include', toPaths)\n .action(async (outDir: string, lexiconPaths: string[], o: { yes?: true }) => {\n const lexicons = readAllLexicons(lexiconPaths)\n const api = await genServerApi(lexicons)\n const diff = genFileDiff(outDir, api)\n console.log('This will write the following files:')\n printFileDiff(diff)\n if (!o?.yes) await confirmOrExit()\n applyFileDiff(diff)\n console.log('API generated.')\n })\n\nprogram.parse()\n\nfunction toPath(v: string) {\n return v ? path.resolve(v) : undefined\n}\n\nfunction toPaths(v: string, acc: string[]) {\n acc = acc || []\n acc.push(path.resolve(v))\n return acc\n}\n\nasync function confirmOrExit() {\n const ok = await yesno({\n question: 'Are you sure you want to continue? [y/N]',\n defaultValue: false,\n })\n if (!ok) {\n console.log('Aborted.')\n process.exit(0)\n }\n}\n"]}
@@ -1,10 +1,4 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.process = process;
7
- const node_fs_1 = __importDefault(require("node:fs"));
1
+ import fs from 'node:fs';
8
2
  const INSERT_START = [
9
3
  '<!-- START lex generated content. Please keep comment here to allow auto update -->',
10
4
  "<!-- DON'T EDIT THIS SECTION! INSTEAD RE-RUN lex TO UPDATE -->",
@@ -12,12 +6,12 @@ const INSERT_START = [
12
6
  const INSERT_END = [
13
7
  '<!-- END lex generated TOC please keep comment here to allow auto update -->',
14
8
  ];
15
- async function process(outFilePath, lexicons) {
9
+ export async function process(outFilePath, lexicons) {
16
10
  let existingContent = '';
17
11
  try {
18
- existingContent = node_fs_1.default.readFileSync(outFilePath, 'utf8');
12
+ existingContent = fs.readFileSync(outFilePath, 'utf8');
19
13
  }
20
- catch (e) {
14
+ catch {
21
15
  // ignore - no existing content
22
16
  }
23
17
  const fileLines = existingContent.split('\n');
@@ -36,7 +30,7 @@ async function process(outFilePath, lexicons) {
36
30
  await genMdLines(lexicons),
37
31
  INSERT_END,
38
32
  ]);
39
- node_fs_1.default.writeFileSync(outFilePath, merge(fileLines), 'utf8');
33
+ fs.writeFileSync(outFilePath, merge(fileLines), 'utf8');
40
34
  }
41
35
  async function genMdLines(lexicons) {
42
36
  const doc = [];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mdgen/index.ts"],"names":[],"mappings":";;;;;AAWA,0BA2BC;AAtCD,sDAAwB;AAGxB,MAAM,YAAY,GAAG;IACnB,qFAAqF;IACrF,gEAAgE;CACjE,CAAA;AACD,MAAM,UAAU,GAAG;IACjB,8EAA8E;CAC/E,CAAA;AAEM,KAAK,UAAU,OAAO,CAAC,WAAmB,EAAE,QAAsB;IACvE,IAAI,eAAe,GAAG,EAAE,CAAA;IACxB,IAAI,CAAC;QACH,eAAe,GAAG,iBAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;IACxD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,+BAA+B;IACjC,CAAC;IACD,MAAM,SAAS,GAAe,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAEzD,oCAAoC;IACpC,IAAI,UAAU,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAA;IAClE,IAAI,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;IAC9D,IAA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Q,CAAC;SACpC,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC;AAED,SAAS,YAAY,CAAC,IAAI;IACxB,OAAO,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACrC,CAAC;AAED,SAAS,UAAU,CAAC,IAAI;IACtB,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACnC,CAAC","sourcesContent":["import fs from 'node:fs'\nimport { type LexiconDoc } from '@atproto/lexicon'\n\nconst INSERT_START = [\n '<!-- START lex generated content. Please keep comment here to allow auto update -->',\n \"<!-- DON'T EDIT THIS SECTION! INSTEAD RE-RUN lex TO UPDATE -->\",\n]\nconst INSERT_END = [\n '<!-- END lex generated TOC please keep comment here to allow auto update -->',\n]\n\nexport async function process(outFilePath: string, lexicons: LexiconDoc[]) {\n let existingContent = ''\n try {\n existingContent = fs.readFileSync(outFilePath, 'utf8')\n } catch (e) {\n // ignore - no existing content\n }\n const fileLines: StringTree = existingContent.split('\\n')\n\n // find previously generated content\n let startIndex = fileLines.findIndex((line) => matchesStart(line))\n let endIndex = fileLines.findIndex((line) => matchesEnd(line))\n if (startIndex === -1) {\n startIndex = fileLines.length\n }\n if (endIndex === -1) {\n endIndex = fileLines.length\n }\n\n // generate & insert content\n fileLines.splice(startIndex, endIndex - startIndex + 1, [\n INSERT_START,\n await genMdLines(lexicons),\n INSERT_END,\n ])\n\n fs.writeFileSync(outFilePath, merge(fileLines), 'utf8')\n}\n\nasync function genMdLines(lexicons: LexiconDoc[]): Promise<StringTree> {\n const doc: StringTree = []\n for (const lexicon of lexicons) {\n console.log(lexicon.id)\n const desc: StringTree = []\n if (lexicon.description) {\n desc.push(lexicon.description, ``)\n }\n doc.push([\n `---`,\n ``,\n `## ${lexicon.id}`,\n '',\n desc,\n '```json',\n JSON.stringify(lexicon, null, 2),\n '```',\n ])\n }\n return doc\n}\n\ntype StringTree = (StringTree | string | undefined)[]\nfunction merge(arr: StringTree): string {\n return arr\n .flat(10)\n .filter((v) => typeof v === 'string')\n .join('\\n')\n}\n\nfunction matchesStart(line) {\n return /<!-- START lex /.test(line)\n}\n\nfunction matchesEnd(line) {\n return /<!-- END lex /.test(line)\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mdgen/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AAGxB,MAAM,YAAY,GAAG;IACnB,qFAAqF;IACrF,gEAAgE;CACjE,CAAA;AACD,MAAM,UAAU,GAAG;IACjB,8EAA8E;CAC/E,CAAA;AAED,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,WAAmB,EAAE,QAAsB;IACvE,IAAI,eAAe,GAAG,EAAE,CAAA;IACxB,IAAI,CAAC;QACH,eAAe,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,+BAA+B;IACjC,CAAC;IACD,MAAM,SAAS,GAAe,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAEzD,oCAAoC;IACpC,IAAI,UAAU,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAA;IAClE,IAAI,QAAQ,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;IAC9D,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;QACtB,UAAU,GAAG,SAAS,CAAC,MAAM,CAAA;IAC/B,CAAC;IACD,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;QACpB,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAA;IAC7B,CAAC;IAED,4BAA4B;IAC5B,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,GAAG,UAAU,GAAG,CAAC,EAAE;QACtD,YAAY;QACZ,MAAM,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= [\n '<!-- START lex generated content. Please keep comment here to allow auto update -->',\n \"<!-- DON'T EDIT THIS SECTION! INSTEAD RE-RUN lex TO UPDATE -->\",\n]\nconst INSERT_END = [\n '<!-- END lex generated TOC please keep comment here to allow auto update -->',\n]\n\nexport async function process(outFilePath: string, lexicons: LexiconDoc[]) {\n let existingContent = ''\n try {\n existingContent = fs.readFileSync(outFilePath, 'utf8')\n } catch {\n // ignore - no existing content\n }\n const fileLines: StringTree = existingContent.split('\\n')\n\n // find previously generated content\n let startIndex = fileLines.findIndex((line) => matchesStart(line))\n let endIndex = fileLines.findIndex((line) => matchesEnd(line))\n if (startIndex === -1) {\n startIndex = fileLines.length\n }\n if (endIndex === -1) {\n endIndex = fileLines.length\n }\n\n // generate & insert content\n fileLines.splice(startIndex, endIndex - startIndex + 1, [\n INSERT_START,\n await genMdLines(lexicons),\n INSERT_END,\n ])\n\n fs.writeFileSync(outFilePath, merge(fileLines), 'utf8')\n}\n\nasync function genMdLines(lexicons: LexiconDoc[]): Promise<StringTree> {\n const doc: StringTree = []\n for (const lexicon of lexicons) {\n console.log(lexicon.id)\n const desc: StringTree = []\n if (lexicon.description) {\n desc.push(lexicon.description, ``)\n }\n doc.push([\n `---`,\n ``,\n `## ${lexicon.id}`,\n '',\n desc,\n '```json',\n JSON.stringify(lexicon, null, 2),\n '```',\n ])\n }\n return doc\n}\n\ntype StringTree = (StringTree | string | undefined)[]\nfunction merge(arr: StringTree): string {\n return arr\n .flat(10)\n .filter((v) => typeof v === 'string')\n .join('\\n')\n}\n\nfunction matchesStart(line) {\n return /<!-- START lex /.test(line)\n}\n\nfunction matchesEnd(line) {\n return /<!-- END lex /.test(line)\n}\n"]}
package/dist/types.js CHANGED
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=types.js.map
package/dist/util.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type LexiconDoc } from '@atproto/lexicon';
2
- import { type FileDiff, type GeneratedAPI } from './types';
2
+ import { type FileDiff, type GeneratedAPI } from './types.js';
3
3
  export declare function readAllLexicons(paths: string[]): LexiconDoc[];
4
4
  export declare function readLexicon(path: string): LexiconDoc;
5
5
  export declare function genTsObj(lexicons: LexiconDoc[]): string;
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAmB,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAE1D,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,CAc7D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAiCpD;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,MAAM,CAEvD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,cAqB5D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,QAc7C;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,QAa7C"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAmB,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAE7D,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,CAc7D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAiCpD;AAED,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE,GAAG,MAAM,CAEvD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,cAqB5D;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,QAc7C;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,QAa7C"}