@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 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/codegen/common.ts"],"names":[],"mappings":";;;AAuQA,kBAYC;AAnRD,uCAA6D;AAC7D,uCAAuE;AAGvE,iCAAoC;AAEpC,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;AAEM,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,EAAE,CAChC,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;AAvHS,QAAA,MAAM,UAuHf;AAEG,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,QAAsB,EAAE,EAAE,CAC5D,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,iBAAiB,EAAE;QAC3B,EAAE,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,IAAI,EA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QACxB,UAAU,EAAE,IAAI;QAChB,eAAe,EAAE,kCAAuB,CAAC,KAAK;QAC9C,YAAY,EAAE;YACZ;gBACE,IAAI,EAAE,KAAK;gBACX,WAAW,EAAE,IAAI,QAAQ;qBACtB,GAAG,CACF,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,IAAA,kBAAW,EAAC,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;AA9HS,QAAA,UAAU,cA8HnB;AAEG,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,IAAA,iBAAM,EAAC,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'\nimport { toTitleCase } from './util'\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'\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,EAA8B,MAAM,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EAAuB,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,OAAO,EAAE,EAAE,CAChC,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,OAAO,EAAE,QAAsB,EAAE,EAAE,CAC5D,GAAG,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,EA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\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,32 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.genComment = genComment;
4
- exports.genCommonImports = genCommonImports;
5
- exports.genImports = genImports;
6
- exports.genUserType = genUserType;
7
- exports.genToken = genToken;
8
- exports.genArray = genArray;
9
- exports.genPrimitiveOrBlob = genPrimitiveOrBlob;
10
- exports.genXrpcParams = genXrpcParams;
11
- exports.genXrpcInput = genXrpcInput;
12
- exports.genXrpcOutput = genXrpcOutput;
13
- exports.genRecord = genRecord;
14
- exports.stripScheme = stripScheme;
15
- exports.stripHash = stripHash;
16
- exports.getHash = getHash;
17
- exports.ipldToType = ipldToType;
18
- exports.primitiveOrBlobToType = primitiveOrBlobToType;
19
- exports.primitiveToType = primitiveToType;
20
- const posix_1 = require("node:path/posix");
21
- const ts_morph_1 = require("ts-morph");
22
- const util_1 = require("./util");
23
- function genComment(commentable, def) {
1
+ import { relative as getRelativePath } from 'node:path/posix';
2
+ import { VariableDeclarationKind } from 'ts-morph';
3
+ import { toCamelCase, toScreamingSnakeCase, toTitleCase } from './util.js';
4
+ export function genComment(commentable, def) {
24
5
  if (def.description) {
25
6
  commentable.addJsDoc({ description: def.description });
26
7
  }
27
8
  return commentable;
28
9
  }
29
- function genCommonImports(file, baseNsid) {
10
+ export function genCommonImports(file, baseNsid) {
30
11
  //= import {ValidationResult, BlobRef} from '@atproto/lexicon'
31
12
  file
32
13
  .addImportDeclaration({
@@ -48,7 +29,7 @@ function genCommonImports(file, baseNsid) {
48
29
  moduleSpecifier: `${baseNsid
49
30
  .split('.')
50
31
  .map((_str) => '..')
51
- .join('/')}/lexicons`,
32
+ .join('/')}/lexicons.js`,
52
33
  })
53
34
  .addNamedImports([{ name: 'validate', alias: '_validate' }]);
54
35
  //= import { type $Typed, is$typed as _is$typed, type OmitKey } from '../[...]/util.ts'
@@ -57,7 +38,7 @@ function genCommonImports(file, baseNsid) {
57
38
  moduleSpecifier: `${baseNsid
58
39
  .split('.')
59
40
  .map((_str) => '..')
60
- .join('/')}/util`,
41
+ .join('/')}/util.js`,
61
42
  })
62
43
  .addNamedImports([
63
44
  { name: '$Typed', isTypeOnly: true },
@@ -67,11 +48,11 @@ function genCommonImports(file, baseNsid) {
67
48
  // tsc adds protection against circular imports, which hurts bundle size.
68
49
  // Since we know that lexicon.ts and util.ts do not depend on the file being
69
50
  // generated, we can safely bypass this protection.
70
- // Note that we are not using `import * as util from '../../util'` because
51
+ // Note that we are not using `import * as util from '../../util.js'` because
71
52
  // typescript will emit is own helpers for the import, which we want to avoid.
72
53
  file.addVariableStatement({
73
54
  isExported: false,
74
- declarationKind: ts_morph_1.VariableDeclarationKind.Const,
55
+ declarationKind: VariableDeclarationKind.Const,
75
56
  declarations: [
76
57
  { name: 'is$typed', initializer: '_is$typed' },
77
58
  { name: 'validate', initializer: '_validate' },
@@ -80,26 +61,26 @@ function genCommonImports(file, baseNsid) {
80
61
  //= const id = "{baseNsid}"
81
62
  file.addVariableStatement({
82
63
  isExported: false, // Do not export to allow tree-shaking
83
- declarationKind: ts_morph_1.VariableDeclarationKind.Const,
64
+ declarationKind: VariableDeclarationKind.Const,
84
65
  declarations: [{ name: 'id', initializer: JSON.stringify(baseNsid) }],
85
66
  });
86
67
  }
87
- function genImports(file, imports, baseNsid) {
68
+ export function genImports(file, imports, baseNsid) {
88
69
  const startPath = '/' + baseNsid.split('.').slice(0, -1).join('/');
89
70
  for (const nsid of imports) {
90
71
  const targetPath = '/' + nsid.split('.').join('/') + '.js';
91
- let resolvedPath = (0, posix_1.relative)(startPath, targetPath);
72
+ let resolvedPath = getRelativePath(startPath, targetPath);
92
73
  if (!resolvedPath.startsWith('.')) {
93
74
  resolvedPath = `./${resolvedPath}`;
94
75
  }
95
76
  file.addImportDeclaration({
96
77
  isTypeOnly: true,
97
78
  moduleSpecifier: resolvedPath,
98
- namespaceImport: (0, util_1.toTitleCase)(nsid),
79
+ namespaceImport: toTitleCase(nsid),
99
80
  });
100
81
  }
101
82
  }
102
- function genUserType(file, imports, lexicons, lexUri) {
83
+ export function genUserType(file, imports, lexicons, lexUri) {
103
84
  const def = lexicons.getDefOrThrow(lexUri);
104
85
  switch (def.type) {
105
86
  case 'array':
@@ -109,7 +90,7 @@ function genUserType(file, imports, lexicons, lexUri) {
109
90
  genToken(file, lexUri, def);
110
91
  break;
111
92
  case 'object': {
112
- const ifaceName = (0, util_1.toTitleCase)(getHash(lexUri));
93
+ const ifaceName = toTitleCase(getHash(lexUri));
113
94
  genObject(file, imports, lexUri, def, ifaceName, {
114
95
  typeProperty: true,
115
96
  });
@@ -232,24 +213,24 @@ function genObject(file, imports, lexUri, def, ifaceName, { defaultsArePresent =
232
213
  }
233
214
  }
234
215
  }
235
- function genToken(file, lexUri, def) {
216
+ export function genToken(file, lexUri, def) {
236
217
  //= /** <comment> */
237
218
  //= export const <TOKEN> = `${id}#<token>`
238
219
  genComment(file.addVariableStatement({
239
220
  isExported: true,
240
- declarationKind: ts_morph_1.VariableDeclarationKind.Const,
221
+ declarationKind: VariableDeclarationKind.Const,
241
222
  declarations: [
242
223
  {
243
- name: (0, util_1.toScreamingSnakeCase)(getHash(lexUri)),
224
+ name: toScreamingSnakeCase(getHash(lexUri)),
244
225
  initializer: `\`\${id}#${getHash(lexUri)}\``,
245
226
  },
246
227
  ],
247
228
  }), def);
248
229
  }
249
- function genArray(file, imports, lexUri, def) {
230
+ export function genArray(file, imports, lexUri, def) {
250
231
  if (def.items.type === 'ref') {
251
232
  file.addTypeAlias({
252
- name: (0, util_1.toTitleCase)(getHash(lexUri)),
233
+ name: toTitleCase(getHash(lexUri)),
253
234
  type: `${refToType(def.items.ref, stripScheme(stripHash(lexUri)), imports)}[]`,
254
235
  isExported: true,
255
236
  });
@@ -260,27 +241,27 @@ function genArray(file, imports, lexUri, def) {
260
241
  types.push('{ $type: string }');
261
242
  }
262
243
  file.addTypeAlias({
263
- name: (0, util_1.toTitleCase)(getHash(lexUri)),
244
+ name: toTitleCase(getHash(lexUri)),
264
245
  type: `(${types.join('|')})[]`,
265
246
  isExported: true,
266
247
  });
267
248
  }
268
249
  else {
269
250
  genComment(file.addTypeAlias({
270
- name: (0, util_1.toTitleCase)(getHash(lexUri)),
251
+ name: toTitleCase(getHash(lexUri)),
271
252
  type: `${primitiveOrBlobToType(def.items)}[]`,
272
253
  isExported: true,
273
254
  }), def);
274
255
  }
275
256
  }
276
- function genPrimitiveOrBlob(file, lexUri, def) {
257
+ export function genPrimitiveOrBlob(file, lexUri, def) {
277
258
  genComment(file.addTypeAlias({
278
- name: (0, util_1.toTitleCase)(getHash(lexUri)),
259
+ name: toTitleCase(getHash(lexUri)),
279
260
  type: primitiveOrBlobToType(def),
280
261
  isExported: true,
281
262
  }), def);
282
263
  }
283
- function genXrpcParams(file, lexicons, lexUri, defaultsArePresent = true) {
264
+ export function genXrpcParams(file, lexicons, lexUri, defaultsArePresent = true) {
284
265
  const def = lexicons.getDefOrThrow(lexUri, [
285
266
  'query',
286
267
  'subscription',
@@ -328,7 +309,7 @@ function genXrpcParams(file, lexicons, lexUri, defaultsArePresent = true) {
328
309
  });
329
310
  }
330
311
  }
331
- function genXrpcInput(file, imports, lexicons, lexUri, defaultsArePresent = true) {
312
+ export function genXrpcInput(file, imports, lexicons, lexUri, defaultsArePresent = true) {
332
313
  const def = lexicons.getDefOrThrow(lexUri, ['query', 'procedure']);
333
314
  if (def.type === 'procedure' && def.input?.schema) {
334
315
  if (def.input.schema.type === 'ref' || def.input.schema.type === 'union') {
@@ -371,7 +352,7 @@ function genXrpcInput(file, imports, lexicons, lexUri, defaultsArePresent = true
371
352
  });
372
353
  }
373
354
  }
374
- function genXrpcOutput(file, imports, lexicons, lexUri, defaultsArePresent = true) {
355
+ export function genXrpcOutput(file, imports, lexicons, lexUri, defaultsArePresent = true) {
375
356
  const def = lexicons.getDefOrThrow(lexUri, [
376
357
  'query',
377
358
  'subscription',
@@ -401,9 +382,9 @@ function genXrpcOutput(file, imports, lexicons, lexUri, defaultsArePresent = tru
401
382
  }
402
383
  }
403
384
  }
404
- function genRecord(file, imports, lexicons, lexUri) {
385
+ export function genRecord(file, imports, lexicons, lexUri) {
405
386
  const hash = getHash(lexUri);
406
- const ifaceName = (0, util_1.toTitleCase)(hash);
387
+ const ifaceName = toTitleCase(hash);
407
388
  const def = lexicons.getDefOrThrow(lexUri, ['record']);
408
389
  //= export interface {X} {...}
409
390
  genObject(file, imports, lexUri, def.record, ifaceName, {
@@ -443,10 +424,10 @@ function genObjHelpers(file, lexUri, ifaceName, { requireTypeProperty, }) {
443
424
  const hashVar = `hash${ifaceName}`;
444
425
  file.addVariableStatement({
445
426
  isExported: false,
446
- declarationKind: ts_morph_1.VariableDeclarationKind.Const,
427
+ declarationKind: VariableDeclarationKind.Const,
447
428
  declarations: [{ name: hashVar, initializer: JSON.stringify(hash) }],
448
429
  });
449
- const isX = (0, util_1.toCamelCase)(`is-${ifaceName}`);
430
+ const isX = toCamelCase(`is-${ifaceName}`);
450
431
  //= export function is{X}<V>(v: V) {...}
451
432
  file
452
433
  .addFunction({
@@ -456,7 +437,7 @@ function genObjHelpers(file, lexUri, ifaceName, { requireTypeProperty, }) {
456
437
  isExported: true,
457
438
  })
458
439
  .setBodyText(`return is$typed(v, id, ${hashVar})`);
459
- const validateX = (0, util_1.toCamelCase)(`validate-${ifaceName}`);
440
+ const validateX = toCamelCase(`validate-${ifaceName}`);
460
441
  //= export function validate{X}(v: unknown) {...}
461
442
  file
462
443
  .addFunction({
@@ -467,18 +448,18 @@ function genObjHelpers(file, lexUri, ifaceName, { requireTypeProperty, }) {
467
448
  })
468
449
  .setBodyText(`return validate<${ifaceName} & V>(v, id, ${hashVar}${requireTypeProperty ? ', true' : ''})`);
469
450
  }
470
- function stripScheme(uri) {
451
+ export function stripScheme(uri) {
471
452
  if (uri.startsWith('lex:'))
472
453
  return uri.slice(4);
473
454
  return uri;
474
455
  }
475
- function stripHash(uri) {
456
+ export function stripHash(uri) {
476
457
  return uri.split('#')[0] || '';
477
458
  }
478
- function getHash(uri) {
459
+ export function getHash(uri) {
479
460
  return uri.split('#').pop() || '';
480
461
  }
481
- function ipldToType(def) {
462
+ export function ipldToType(def) {
482
463
  if (def.type === 'bytes') {
483
464
  return 'Uint8Array';
484
465
  }
@@ -496,13 +477,13 @@ function refToType(ref, baseNsid, imports) {
496
477
  refHash = 'main';
497
478
  // internal
498
479
  if (!refBase || baseNsid === refBase) {
499
- return (0, util_1.toTitleCase)(refHash);
480
+ return toTitleCase(refHash);
500
481
  }
501
482
  // external
502
483
  imports.add(refBase);
503
- return `${(0, util_1.toTitleCase)(refBase)}.${(0, util_1.toTitleCase)(refHash)}`;
484
+ return `${toTitleCase(refBase)}.${toTitleCase(refHash)}`;
504
485
  }
505
- function primitiveOrBlobToType(def) {
486
+ export function primitiveOrBlobToType(def) {
506
487
  switch (def.type) {
507
488
  case 'blob':
508
489
  return 'BlobRef';
@@ -514,7 +495,7 @@ function primitiveOrBlobToType(def) {
514
495
  return primitiveToType(def);
515
496
  }
516
497
  }
517
- function primitiveToType(def) {
498
+ export function primitiveToType(def) {
518
499
  switch (def.type) {
519
500
  case 'string':
520
501
  if (def.knownValues?.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"lex-gen.js","sourceRoot":"","sources":["../../src/codegen/lex-gen.ts"],"names":[],"mappings":";;AAkBA,gCAQC;AAED,4CA8DC;AAED,gCAmBC;AAED,kCAwCC;AAqID,4BAgBC;AAED,4BAsCC;AAED,gDAaC;AAED,sCA2DC;AAED,oCAuDC;AAED,sCAqCC;AAED,8BA6CC;AAiDD,kCAGC;AAED,8BAEC;AAED,0BAEC;AAED,gCAKC;AA+BD,sDAaC;AAED,0CAiCC;AAnsBD,2CAA6D;AAC7D,uCAAqE;AAYrE,iCAAuE;AAKvE,SAAgB,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,CAAA;AACpB,CAAC;AAED,SAAgB,gBAAgB,CAAC,IAAgB,EAAE,QAAgB;IACjE,8DAA8D;IAC9D,IAAI;SACD,oBAAoB,CAAC;QACpB,eAAe,EAAE,kBAAkB;KACpC,CAAC;SACD,eAAe,CAAC;QACf,EAAE,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,IAAI,EAAE;QAC9C,EAAE,IAAI,EAAE,SAAS,EAAE;KACpB,CAAC,CAAA;IAEJ,wCAAwC;IACxC,IAAI;SACD,oBAAoB,CAAC;QACpB,eAAe,EAAE,kBAAkB;KACpC,CAAC;SACD,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;IAErC,6DAA6D;IAC7D,IAAI;SACD,oBAAoB,CAAC;QACpB,eAAe,EAAE,GAAG,QAAQ;aACzB,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,E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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'\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`,\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`,\n })\n .addNamedImports([\n { name: '$Typed', isTypeOnly: true },\n { name: 'is$typed', alias: '_is$typed' },\n { name: 'OmitKey', isTypeOnly: true },\n ])\n\n // tsc adds protection against circular imports, which hurts bundle size.\n // Since we know that lexicon.ts and util.ts do not depend on the file being\n // generated, we can safely bypass this protection.\n // Note that we are not using `import * as util from '../../util'` because\n // typescript will emit 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,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,CAAA;AACpB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAgB,EAAE,QAAgB;IACjE,8DAA8D;IAC9D,IAAI;SACD,oBAAoB,CAAC;QACpB,eAAe,EAAE,kBAAkB;KACpC,CAAC;SACD,eAAe,CAAC;QACf,EAAE,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,IAAI,EAAE;QAC9C,EAAE,IAAI,EAAE,SAAS,EAAE;KACpB,CAAC,CAAA;IAEJ,wCAAwC;IACxC,IAAI;SACD,oBAAoB,CAAC;QACpB,eAAe,EAAE,kBAAkB;KACpC,CAAC;SACD,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;IAErC,6DAA6D;IAC7D,IAAI;SACD,oBAAoB,CAAC;QACpB,eAAe,EAAE,GAAG,QAAQ;aACzB,KAAK,CAAC,GAAG,CAAC;aACV,GAAG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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 // tsc adds protection against circular imports, which hurts bundle size.\n // Since we know that lexicon.ts and util.ts do not depend on the file being\n // generated, we can safely bypass this protection.\n // Note that we are not using `import * as util from '../../util.js'` because\n // typescript will emit 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,4 +1,4 @@
1
1
  import { type LexiconDoc } from '@atproto/lexicon';
2
- import { type GeneratedAPI } from '../types';
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,KAAK,YAAY,EAAE,MAAM,UAAU,CAAA;AAoB5C,wBAAsB,YAAY,CAChC,WAAW,EAAE,UAAU,EAAE,GACxB,OAAO,CAAC,YAAY,CAAC,CAgBvB"}
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,KAAK,YAAY,EAAE,MAAM,aAAa,CAAA;AAoB/C,wBAAsB,YAAY,CAChC,WAAW,EAAE,UAAU,EAAE,GACxB,OAAO,CAAC,YAAY,CAAC,CAgBvB"}