@atproto/lex-builder 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @atproto/lex-builder
2
2
 
3
+ ## 0.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4967](https://github.com/bluesky-social/atproto/pull/4967) [`9fc720c`](https://github.com/bluesky-social/atproto/commit/9fc720ce75f3ee88a5e48a9be919b07c7647f6f5) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Use TypeScript 7 to build package
8
+
9
+ - Updated dependencies [[`9fc720c`](https://github.com/bluesky-social/atproto/commit/9fc720ce75f3ee88a5e48a9be919b07c7647f6f5)]:
10
+ - @atproto/lex-document@0.1.1
11
+ - @atproto/lex-schema@0.1.4
12
+
13
+ ## 0.1.2
14
+
15
+ ### Patch Changes
16
+
17
+ - [#4981](https://github.com/bluesky-social/atproto/pull/4981) [`3aae4fe`](https://github.com/bluesky-social/atproto/commit/3aae4fe43448dca860fc6c4a24d18bfa64de084b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove need for inference when computing XRPC method derived types
18
+
19
+ - [#4984](https://github.com/bluesky-social/atproto/pull/4984) [`5bdb4ad`](https://github.com/bluesky-social/atproto/commit/5bdb4addd6a3798bf6c8c391c74044b3e251008a) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `default` export of "main" schema in the namespace file
20
+
21
+ - [#4981](https://github.com/bluesky-social/atproto/pull/4981) [`3aae4fe`](https://github.com/bluesky-social/atproto/commit/3aae4fe43448dca860fc6c4a24d18bfa64de084b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Export `lexiconMessageSchema` (and type) for subscription messages
22
+
23
+ - [#4979](https://github.com/bluesky-social/atproto/pull/4979) [`314df62`](https://github.com/bluesky-social/atproto/commit/314df62537bb519231aa375dd3a38360afc79ce0) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Always add `#__PURE__` annotations to function calls
24
+
25
+ - [#4983](https://github.com/bluesky-social/atproto/pull/4983) [`1259646`](https://github.com/bluesky-social/atproto/commit/125964673962a86282a05bf22f410fad8ad06b41) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Make the generation of the `$defs` namespace optional by default
26
+
3
27
  ## 0.1.1
4
28
 
5
29
  ### Patch Changes
@@ -15,11 +15,13 @@ export declare class FilteredIndexer implements LexiconIndexer, AsyncDisposable
15
15
  [Symbol.asyncIterator](): AsyncGenerator<{
16
16
  lexicon: 1;
17
17
  id: `${string}.${string}.${string}`;
18
+ revision?: number | undefined;
19
+ description?: string | undefined;
18
20
  defs: {
19
21
  [x: string]: {
20
22
  type: "permission-set";
21
23
  permissions: {
22
- [x: string]: string | number | boolean | string[] | boolean[] | number[];
24
+ [x: string]: string | number | boolean | string[] | number[] | boolean[];
23
25
  type: "permission";
24
26
  resource: string;
25
27
  }[];
@@ -659,19 +661,10 @@ export declare class FilteredIndexer implements LexiconIndexer, AsyncDisposable
659
661
  nullable?: string[] | undefined;
660
662
  description?: string | undefined;
661
663
  };
662
- key: import("@atproto/lex-schema").LexiconRecordKey;
663
664
  description?: string | undefined;
665
+ key: import("@atproto/lex-schema").LexiconRecordKey;
664
666
  } | {
665
667
  type: "subscription";
666
- message: {
667
- schema: {
668
- type: "union";
669
- refs: string[];
670
- closed?: boolean | undefined;
671
- description?: string | undefined;
672
- };
673
- description?: string | undefined;
674
- };
675
668
  description?: string | undefined;
676
669
  parameters?: {
677
670
  type: "params";
@@ -735,6 +728,15 @@ export declare class FilteredIndexer implements LexiconIndexer, AsyncDisposable
735
728
  required?: string[] | undefined;
736
729
  description?: string | undefined;
737
730
  } | undefined;
731
+ message: {
732
+ description?: string | undefined;
733
+ schema: {
734
+ type: "union";
735
+ refs: string[];
736
+ closed?: boolean | undefined;
737
+ description?: string | undefined;
738
+ };
739
+ };
738
740
  errors?: {
739
741
  name: string;
740
742
  description?: string | undefined;
@@ -1161,7 +1163,7 @@ export declare class FilteredIndexer implements LexiconIndexer, AsyncDisposable
1161
1163
  main?: {
1162
1164
  type: "permission-set";
1163
1165
  permissions: {
1164
- [x: string]: string | number | boolean | string[] | boolean[] | number[];
1166
+ [x: string]: string | number | boolean | string[] | number[] | boolean[];
1165
1167
  type: "permission";
1166
1168
  resource: string;
1167
1169
  }[];
@@ -1801,19 +1803,10 @@ export declare class FilteredIndexer implements LexiconIndexer, AsyncDisposable
1801
1803
  nullable?: string[] | undefined;
1802
1804
  description?: string | undefined;
1803
1805
  };
1804
- key: import("@atproto/lex-schema").LexiconRecordKey;
1805
1806
  description?: string | undefined;
1807
+ key: import("@atproto/lex-schema").LexiconRecordKey;
1806
1808
  } | {
1807
1809
  type: "subscription";
1808
- message: {
1809
- schema: {
1810
- type: "union";
1811
- refs: string[];
1812
- closed?: boolean | undefined;
1813
- description?: string | undefined;
1814
- };
1815
- description?: string | undefined;
1816
- };
1817
1810
  description?: string | undefined;
1818
1811
  parameters?: {
1819
1812
  type: "params";
@@ -1877,6 +1870,15 @@ export declare class FilteredIndexer implements LexiconIndexer, AsyncDisposable
1877
1870
  required?: string[] | undefined;
1878
1871
  description?: string | undefined;
1879
1872
  } | undefined;
1873
+ message: {
1874
+ description?: string | undefined;
1875
+ schema: {
1876
+ type: "union";
1877
+ refs: string[];
1878
+ closed?: boolean | undefined;
1879
+ description?: string | undefined;
1880
+ };
1881
+ };
1880
1882
  errors?: {
1881
1883
  name: string;
1882
1884
  description?: string | undefined;
@@ -2092,8 +2094,6 @@ export declare class FilteredIndexer implements LexiconIndexer, AsyncDisposable
2092
2094
  description?: string | undefined;
2093
2095
  } | undefined;
2094
2096
  };
2095
- revision?: number | undefined;
2096
- description?: string | undefined;
2097
2097
  }, void, unknown>;
2098
2098
  [Symbol.asyncDispose](): Promise<void>;
2099
2099
  }
@@ -1 +1 @@
1
- {"version":3,"file":"filtered-indexer.d.ts","sourceRoot":"","sources":["../src/filtered-indexer.ts"],"names":[],"mappings":"AAAA,OAA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;;;;;;;;;;;;;;;;;;;;;;;;sBAgC5B;IAEK,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3C;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAA4B,MAAM,UAAU,CAAA;AAc/E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,eAAe,CAAA;IAClC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED;;;;;;;;;GASG;AACH,qBAAa,SAAS;IACpB,uDAAuD;IACvD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,6DAA6D;IAC7D,QAAQ,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI,CAAA;IAEhD;;;;OAIG;gBACS,OAAO,GAAE,gBAAqB;IAS1C;;;;;;;OAOG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM;CAQ1B"}
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAA4B,MAAM,UAAU,CAAA;AAc/E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,eAAe,CAAA;IAClC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED;;;;;;;;;GASG;AACH,qBAAa,SAAS;IACpB,uDAAuD;IACvD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,6DAA6D;IAC7D,QAAQ,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI,CAAA;IAEhD;;;;OAIG;IACH,YAAY,OAAO,GAAE,gBAAqB,EAOzC;IAED;;;;;;;OAOG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,mBAOxB;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,MAAM,IAAI,cAAc,EAAE,MAAM,UAAU,CAAA;AAE/E,MAAM,sBAAsB,GAAoB;IAC9C,MAAM,EAAE,YAAY;IACpB,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,KAAK;IACX,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,KAAK;CACrB,CAAA;AAED,MAAM,cAAc,GAAG;;IAEnB,CAAA;AAwBJ;;;;;;;;;GASG;AACH,MAAM,OAAO,SAAS;IAMpB;;;;OAIG;IACH,YAAY,UAA4B,EAAE;QACxC,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,cAAc,CAAA;QAE/C,IAAI,CAAC,eAAe;YAClB,OAAO,EAAE,MAAM,KAAK,IAAI;gBACtB,CAAC,CAAC,sBAAsB;gBACxB,CAAC,CAAC,OAAO,EAAE,MAAM,IAAI,IAAI,CAAA;IAC/B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY;QACvB,MAAM,aAAa,GACjB,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;QAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe;YACrC,CAAC,CAAC,MAAM,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,eAAe,CAAC;YAClD,CAAC,CAAC,IAAI,CAAA;QACR,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,aAAa,GAAG,UAAU,EAAE,CAAA;IACtD,CAAC;CACF","sourcesContent":["import { Options as PrettierOptions, format as prettierFormat } from 'prettier'\n\nconst DEFAULT_FORMAT_OPTIONS: PrettierOptions = {\n parser: 'typescript',\n tabWidth: 2,\n semi: false,\n singleQuote: true,\n trailingComma: 'all',\n}\n\nconst DEFAULT_BANNER = `/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */`\n\n/**\n * Options for configuring the code formatter.\n */\nexport type FormatterOptions = {\n /**\n * Whether to format the generated code with Prettier.\n *\n * - `false`: No formatting (default)\n * - `true`: Format with default Prettier options\n * - `PrettierOptions`: Format with custom Prettier configuration\n *\n * @default false\n */\n pretty?: boolean | PrettierOptions\n /**\n * A banner comment to prepend to each generated file.\n *\n * @default '/* THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT. *\\/'\n */\n banner?: string\n}\n\n/**\n * Formats generated TypeScript code with optional Prettier formatting\n * and banner comments.\n *\n * @example\n * ```ts\n * const formatter = new Formatter({ pretty: true })\n * const formatted = await formatter.format(generatedCode)\n * ```\n */\nexport class Formatter {\n /** The banner comment to prepend to formatted code. */\n readonly banner: string\n /** Prettier options, or `null` if formatting is disabled. */\n readonly prettierOptions: PrettierOptions | null\n\n /**\n * Creates a new Formatter instance.\n *\n * @param options - Formatting configuration options\n */\n constructor(options: FormatterOptions = {}) {\n this.banner = options?.banner ?? DEFAULT_BANNER\n\n this.prettierOptions =\n options?.pretty === true\n ? DEFAULT_FORMAT_OPTIONS\n : options?.pretty || null\n }\n\n /**\n * Formats the given code string.\n *\n * Applies Prettier formatting if enabled, and prepends the banner comment.\n *\n * @param code - The TypeScript code to format\n * @returns The formatted code with banner\n */\n async format(code: string) {\n const bannerPadding =\n this.banner && !this.banner.endsWith('\\n') ? '\\n\\n' : ''\n const codePretty = this.prettierOptions\n ? await prettierFormat(code, this.prettierOptions)\n : code\n return `${this.banner}${bannerPadding}${codePretty}`\n }\n}\n"]}
1
+ {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../src/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,MAAM,IAAI,cAAc,EAAE,MAAM,UAAU,CAAA;AAE/E,MAAM,sBAAsB,GAAoB;IAC9C,MAAM,EAAE,YAAY;IACpB,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,KAAK;IACX,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,KAAK;CACrB,CAAA;AAED,MAAM,cAAc,GAAG;;IAEnB,CAAA;AAwBJ;;;;;;;;;GASG;AACH,MAAM,OAAO,SAAS;IAMpB;;;;OAIG;IACH,YAAY,OAAO,GAAqB,EAAE;QACxC,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,cAAc,CAAA;QAE/C,IAAI,CAAC,eAAe;YAClB,OAAO,EAAE,MAAM,KAAK,IAAI;gBACtB,CAAC,CAAC,sBAAsB;gBACxB,CAAC,CAAC,OAAO,EAAE,MAAM,IAAI,IAAI,CAAA;IAC/B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CAAC,IAAY;QACvB,MAAM,aAAa,GACjB,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;QAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe;YACrC,CAAC,CAAC,MAAM,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,eAAe,CAAC;YAClD,CAAC,CAAC,IAAI,CAAA;QACR,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,aAAa,GAAG,UAAU,EAAE,CAAA;IACtD,CAAC;CACF","sourcesContent":["import { Options as PrettierOptions, format as prettierFormat } from 'prettier'\n\nconst DEFAULT_FORMAT_OPTIONS: PrettierOptions = {\n parser: 'typescript',\n tabWidth: 2,\n semi: false,\n singleQuote: true,\n trailingComma: 'all',\n}\n\nconst DEFAULT_BANNER = `/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */`\n\n/**\n * Options for configuring the code formatter.\n */\nexport type FormatterOptions = {\n /**\n * Whether to format the generated code with Prettier.\n *\n * - `false`: No formatting (default)\n * - `true`: Format with default Prettier options\n * - `PrettierOptions`: Format with custom Prettier configuration\n *\n * @default false\n */\n pretty?: boolean | PrettierOptions\n /**\n * A banner comment to prepend to each generated file.\n *\n * @default '/* THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT. *\\/'\n */\n banner?: string\n}\n\n/**\n * Formats generated TypeScript code with optional Prettier formatting\n * and banner comments.\n *\n * @example\n * ```ts\n * const formatter = new Formatter({ pretty: true })\n * const formatted = await formatter.format(generatedCode)\n * ```\n */\nexport class Formatter {\n /** The banner comment to prepend to formatted code. */\n readonly banner: string\n /** Prettier options, or `null` if formatting is disabled. */\n readonly prettierOptions: PrettierOptions | null\n\n /**\n * Creates a new Formatter instance.\n *\n * @param options - Formatting configuration options\n */\n constructor(options: FormatterOptions = {}) {\n this.banner = options?.banner ?? DEFAULT_BANNER\n\n this.prettierOptions =\n options?.pretty === true\n ? DEFAULT_FORMAT_OPTIONS\n : options?.pretty || null\n }\n\n /**\n * Formats the given code string.\n *\n * Applies Prettier formatting if enabled, and prepends the banner comment.\n *\n * @param code - The TypeScript code to format\n * @returns The formatted code with banner\n */\n async format(code: string) {\n const bannerPadding =\n this.banner && !this.banner.endsWith('\\n') ? '\\n\\n' : ''\n const codePretty = this.prettierOptions\n ? await prettierFormat(code, this.prettierOptions)\n : code\n return `${this.banner}${bannerPadding}${codePretty}`\n }\n}\n"]}
@@ -31,6 +31,40 @@ export type LexBuilderOptions = LexDefBuilderOptions & {
31
31
  * @default '.ts'
32
32
  */
33
33
  fileExt?: string;
34
+ /**
35
+ * Whether to export the whole defs file as a namespace export (`export * as
36
+ * $defs from './xyz.defs.js'`). This is useful to have an escape hatch to
37
+ * access the definitions in case of name conflicts with child namespaces.
38
+ *
39
+ * For example if two documents with if `com.example.foo` and
40
+ * `com.example.foo.bar` coexist, the `com.example.foo.bar` namespace would
41
+ * shadow any `bar` definition from the `com.example.foo` namespace. In that
42
+ * case, having the `$defs` namespace export allows to still access those
43
+ * definitions via `com.example.foo.$defs.bar`.
44
+ *
45
+ * @note enabling this will negatively impact bundle size because and
46
+ * additional namespace object will be generated for each lexicon document.
47
+ *
48
+ * @default false
49
+ */
50
+ defsExport?: boolean;
51
+ /**
52
+ * Whether to generate a default export for the "main" lexicon definition
53
+ * schema in the parent namespace file.
54
+ *
55
+ * This allows simpler access the main schema when importing directly from the
56
+ * file instead of using the full namespace as in:
57
+ * `com.atproto.repo.getRecord`.
58
+ *
59
+ * ```ts
60
+ * import getRecord from './com/atproto/repo/getRecord.js'
61
+ * // instead of
62
+ * import { main as getRecord } from './com/atproto/repo/getRecord.js'
63
+ * ```
64
+ *
65
+ * @default false
66
+ */
67
+ defaultExport?: boolean;
34
68
  };
35
69
  /**
36
70
  * Options for loading lexicon documents into the builder.
@@ -1 +1 @@
1
- {"version":3,"file":"lex-builder.d.ts","sourceRoot":"","sources":["../src/lex-builder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAe,MAAM,aAAa,CAAA;AAE7D,OAAO,EAAa,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAC5D,OAAO,EAAiB,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC1E,OAAO,EAEL,8BAA8B,EAC/B,MAAM,gCAAgC,CAAA;AAGvC;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG,oBAAoB,GAAG;IACrD;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,qBAAqB,GAAG,8BAA8B,GAChE,kBAAkB,CAAA;AAEpB;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG;IACr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AIG;AACH,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG;IACrD;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,UAAU;;IAOT,OAAO,CAAC,QAAQ,CAAC,OAAO;IAApC,YAA6B,OAAO,GAAE,iBAAsB,EAAI;IAEhE,IAAI,OAAO,WAEV;IAED,IAAI,SAAS,WAEZ;IAEY,IAAI,CAAC,OAAO,EAAE,qBAAqB,iBAgB/C;IAEY,IAAI,CAAC,OAAO,EAAE,qBAAqB,iBA0B/C;IAED,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,OAAO;YAID,gBAAgB;YAmEhB,cAAc;CAU7B"}
@@ -128,15 +128,24 @@ export class LexBuilder {
128
128
  file.addExportDeclaration({
129
129
  moduleSpecifier: `./${namespaces.at(-1)}.defs${this.importExt}`,
130
130
  });
131
- // @NOTE Individual exports exports from the defs file might conflict with
132
- // child namespaces. For this reason, we also add a namespace export for the
133
- // defs (export * as $defs from './xyz.defs.js'). This is an escape hatch
134
- // allowing to still access the definitions if a hash get shadowed by a
135
- // child namespace.
136
- file.addExportDeclaration({
137
- moduleSpecifier: `./${namespaces.at(-1)}.defs${this.importExt}`,
138
- namespaceExport: '$defs',
139
- });
131
+ if (this.options.defsExport) {
132
+ // @NOTE Individual exports exports from the defs file might conflict with
133
+ // child namespaces. For this reason, we also add a namespace export for the
134
+ // defs (export * as $defs from './xyz.defs.js'). This is an escape hatch
135
+ // allowing to still access the definitions if a hash get shadowed by a
136
+ // child namespace.
137
+ file.addExportDeclaration({
138
+ moduleSpecifier: `./${namespaces.at(-1)}.defs${this.importExt}`,
139
+ namespaceExport: '$defs',
140
+ });
141
+ }
142
+ if (this.options.defaultExport && doc.defs.main != null) {
143
+ // export { main as default } from './xyz.defs.js'
144
+ file.addExportDeclaration({
145
+ moduleSpecifier: `./${namespaces.at(-1)}.defs${this.importExt}`,
146
+ namedExports: [{ name: 'main', alias: 'default' }],
147
+ });
148
+ }
140
149
  }
141
150
  async createDefsFile(doc, indexer) {
142
151
  const path = join('/', ...doc.id.split('.'));
@@ -1 +1 @@
1
- {"version":3,"file":"lex-builder.js","sourceRoot":"","sources":["../src/lex-builder.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAEnD,OAAO,EAAsB,WAAW,EAAE,MAAM,aAAa,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,SAAS,EAAoB,MAAM,gBAAgB,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAwB,MAAM,sBAAsB,CAAA;AAC1E,OAAO,EACL,uBAAuB,GAExB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAyEhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,UAAU;IACZ,SAAS,GAAG,IAAI,GAAG,EAAU,CAAA;IAC7B,QAAQ,GAAG,IAAI,OAAO,CAAC;QAC9B,qBAAqB,EAAE,IAAI;QAC3B,oBAAoB,EAAE,EAAE,eAAe,EAAE,eAAe,CAAC,SAAS,EAAE;KACrE,CAAC,CAAA;IAEF,YAA6B,UAA6B,EAAE;QAA/B,YAAO,GAAP,OAAO,CAAwB;IAAG,CAAC;IAEhE,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,K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wBAAwB,IAAI,EAAE,CAAC,CAAA;IACjD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,KAAK,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAM;QAC1E,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC","sourcesContent":["import assert from 'node:assert'\nimport { mkdir, rm, stat, writeFile } from 'node:fs/promises'\nimport { join, resolve } from 'node:path'\nimport { IndentationText, Project } from 'ts-morph'\nimport { LexiconDocument, LexiconIndexer } from '@atproto/lex-document'\nimport { BuildFilterOptions, buildFilter } from './filter.js'\nimport { FilteredIndexer } from './filtered-indexer.js'\nimport { Formatter, FormatterOptions } from './formatter.js'\nimport { LexDefBuilder, LexDefBuilderOptions } from './lex-def-builder.js'\nimport {\n LexiconDirectoryIndexer,\n LexiconDirectoryIndexerOptions,\n} from './lexicon-directory-indexer.js'\nimport { asNamespaceExport } from './ts-lang.js'\n\n/**\n * Configuration options for the {@link LexBuilder} class.\n *\n * Extends {@link LexDefBuilderOptions} with additional settings for\n * controlling the generated TypeScript project structure.\n *\n * @see {@link LexDefBuilderOptions} for definition generation options\n */\nexport type LexBuilderOptions = LexDefBuilderOptions & {\n /**\n * Whether to generate an index file at the root exporting all top-level\n * namespaces.\n *\n * @note This could theoretically cause name conflicts if a\n * @default false\n */\n indexFile?: boolean\n /**\n * The file extension to use for import specifiers in the generated code.\n *\n * @default '.js'\n */\n importExt?: string\n /**\n * The file extension to use for generated TypeScript files.\n *\n * @default '.ts'\n */\n fileExt?: string\n}\n\n/**\n * Options for loading lexicon documents into the builder.\n *\n * Combines directory indexing options with filtering options to control\n * which lexicon documents are processed.\n *\n * @see {@link LexiconDirectoryIndexerOptions} for directory scanning options\n * @see {@link BuildFilterOptions} for include/exclude filtering\n */\nexport type LexBuilderLoadOptions = LexiconDirectoryIndexerOptions &\n BuildFilterOptions\n\n/**\n * Options for saving generated TypeScript files.\n *\n * Combines formatting options with output directory configuration.\n */\nexport type LexBuilderSaveOptions = FormatterOptions & {\n /**\n * The output directory path where generated TypeScript files will be written.\n */\n out: string\n /**\n * Whether to clear the output directory before writing files.\n *\n * When `true`, the entire output directory is deleted before writing new files.\n *\n * @default false\n */\n clear?: boolean\n /**\n * Whether to allow overwriting existing files.\n *\n * When `false`, an error is thrown if any output file already exists.\n *\n * @default false\n */\n override?: boolean\n}\n\n/**\n * Main builder class for generating TypeScript schemas from Lexicon documents.\n *\n * The LexBuilder orchestrates the entire code generation process:\n * 1. Loading and indexing lexicon documents from the filesystem\n * 2. Generating TypeScript type definitions and runtime schemas\n * 3. Creating namespace export trees for convenient imports\n * 4. Saving formatted output files\n *\n * @example\n * ```ts\n * const builder = new LexBuilder({ indexFile: true, pretty: true })\n *\n * // Load lexicons from a directory\n * await builder.load({ lexicons: './lexicons' })\n *\n * // Save generated TypeScript to output directory\n * await builder.save({ out: './src/generated', clear: true })\n * ```\n */\nexport class LexBuilder {\n readonly #imported = new Set<string>()\n readonly #project = new Project({\n useInMemoryFileSystem: true,\n manipulationSettings: { indentationText: IndentationText.TwoSpaces },\n })\n\n constructor(private readonly options: LexBuilderOptions = {}) {}\n\n get fileExt() {\n return this.options.fileExt ?? '.ts'\n }\n\n get importExt() {\n return this.options.importExt ?? '.js'\n }\n\n public async load(options: LexBuilderLoadOptions) {\n await using indexer = new FilteredIndexer(\n new LexiconDirectoryIndexer(options),\n buildFilter(options),\n )\n\n for await (const doc of indexer) {\n if (!this.#imported.has(doc.id)) {\n this.#imported.add(doc.id)\n } else {\n throw new Error(`Duplicate lexicon document id: ${doc.id}`)\n }\n\n await this.createDefsFile(doc, indexer)\n await this.createExportTree(doc)\n }\n }\n\n public async save(options: LexBuilderSaveOptions) {\n const files = this.#project.getSourceFiles()\n\n const destination = resolve(options.out)\n\n if (options.clear) {\n await rm(destination, { recursive: true, force: true })\n } else if (!options.override) {\n await Promise.all(\n files.map(async (f) =>\n assertNotFileExists(join(destination, f.getFilePath())),\n ),\n )\n }\n\n const formatter = new Formatter(options)\n\n await Promise.all(\n Array.from(files, async (file) => {\n const filePath = join(destination, file.getFilePath())\n const content = await formatter.format(file.getFullText())\n await mkdir(join(filePath, '..'), { recursive: true })\n await rm(filePath, { recursive: true, force: true })\n await writeFile(filePath, content, 'utf8')\n }),\n )\n }\n\n private createFile(path: string) {\n return this.#project.createSourceFile(path)\n }\n\n private getFile(path: string) {\n return this.#project.getSourceFile(path) || this.createFile(path)\n }\n\n private async createExportTree(doc: LexiconDocument) {\n const namespaces = doc.id.split('.')\n\n if (this.options.indexFile) {\n const indexFile = this.getFile(`/index${this.fileExt}`)\n\n const tldNs = namespaces[0]!\n assert(\n tldNs !== 'index',\n 'The \"indexFile\" options cannot be used with namespaces using a \".index\" tld.',\n )\n const tldNsSpecifier = `./${tldNs}${this.importExt}`\n if (!indexFile.getExportDeclaration(tldNsSpecifier)) {\n indexFile.addExportDeclaration({\n moduleSpecifier: tldNsSpecifier,\n namespaceExport: asNamespaceExport(tldNs),\n })\n }\n }\n\n // First create the parent namespaces\n for (let i = 0; i < namespaces.length - 1; i++) {\n const currentNs = namespaces[i]\n const childNs = namespaces[i + 1]\n\n const path = join('/', ...namespaces.slice(0, i + 1))\n const file = this.getFile(`${path}${this.fileExt}`)\n\n const childModuleSpecifier = `./${currentNs}/${childNs}${this.importExt}`\n const dec = file.getExportDeclaration(childModuleSpecifier)\n if (!dec) {\n file.addExportDeclaration({\n moduleSpecifier: childModuleSpecifier,\n namespaceExport: asNamespaceExport(childNs),\n })\n }\n }\n\n // The child file exports the schemas (as *)\n const path = join('/', ...namespaces)\n const file = this.getFile(`${path}${this.fileExt}`)\n\n file.addExportDeclaration({\n moduleSpecifier: `./${namespaces.at(-1)}.defs${this.importExt}`,\n })\n\n // @NOTE Individual exports exports from the defs file might conflict with\n // child namespaces. For this reason, we also add a namespace export for the\n // defs (export * as $defs from './xyz.defs.js'). This is an escape hatch\n // allowing to still access the definitions if a hash get shadowed by a\n // child namespace.\n file.addExportDeclaration({\n moduleSpecifier: `./${namespaces.at(-1)}.defs${this.importExt}`,\n namespaceExport: '$defs',\n })\n }\n\n private async createDefsFile(\n doc: LexiconDocument,\n indexer: LexiconIndexer,\n ): Promise<void> {\n const path = join('/', ...doc.id.split('.'))\n const file = this.createFile(`${path}.defs${this.fileExt}`)\n\n const fileBuilder = new LexDefBuilder(this.options, file, doc, indexer)\n await fileBuilder.build()\n }\n}\n\nasync function assertNotFileExists(file: string): Promise<void> {\n try {\n await stat(file)\n throw new Error(`File already exists: ${file}`)\n } catch (err) {\n if (err instanceof Error && 'code' in err && err.code === 'ENOENT') return\n throw err\n }\n}\n"]}
1
+ {"version":3,"file":"lex-builder.js","sourceRoot":"","sources":["../src/lex-builder.ts"],"names":[],"mappings":";AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAEnD,OAAO,EAAsB,WAAW,EAAE,MAAM,aAAa,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,SAAS,EAAoB,MAAM,gBAAgB,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAwB,MAAM,sBAAsB,CAAA;AAC1E,OAAO,EACL,uBAAuB,GAExB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AA2GhD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,UAAU;IACZ,SAAS,GAAG,IAAI,GAAG,EAAU,CAAA;IAC7B,QAAQ,GAAG,IAAI,OAAO,CAAC;QAC9B,qBAAqB,EAAE,IAAI;QAC3B,oBAAoB,EAAE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AAS,EAAE,CAAC;aACnD,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,cAAc,CAC1B,GAAoB,EACpB,OAAuB;QAEvB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,QAAQ,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;QAE3D,MAAM,WAAW,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;QACvE,MAAM,WAAW,CAAC,KAAK,EAAE,CAAA;IAC3B,CAAC;CACF;AAED,KAAK,UAAU,mBAAmB,CAAC,IAAY;IAC7C,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,IAAI,CAAC,CAAA;QAChB,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,EAAE,CAAC,CAAA;IACjD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,KAAK,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAM;QAC1E,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC","sourcesContent":["import assert from 'node:assert'\nimport { mkdir, rm, stat, writeFile } from 'node:fs/promises'\nimport { join, resolve } from 'node:path'\nimport { IndentationText, Project } from 'ts-morph'\nimport { LexiconDocument, LexiconIndexer } from '@atproto/lex-document'\nimport { BuildFilterOptions, buildFilter } from './filter.js'\nimport { FilteredIndexer } from './filtered-indexer.js'\nimport { Formatter, FormatterOptions } from './formatter.js'\nimport { LexDefBuilder, LexDefBuilderOptions } from './lex-def-builder.js'\nimport {\n LexiconDirectoryIndexer,\n LexiconDirectoryIndexerOptions,\n} from './lexicon-directory-indexer.js'\nimport { asNamespaceExport } from './ts-lang.js'\n\n/**\n * Configuration options for the {@link LexBuilder} class.\n *\n * Extends {@link LexDefBuilderOptions} with additional settings for\n * controlling the generated TypeScript project structure.\n *\n * @see {@link LexDefBuilderOptions} for definition generation options\n */\nexport type LexBuilderOptions = LexDefBuilderOptions & {\n /**\n * Whether to generate an index file at the root exporting all top-level\n * namespaces.\n *\n * @note This could theoretically cause name conflicts if a\n * @default false\n */\n indexFile?: boolean\n /**\n * The file extension to use for import specifiers in the generated code.\n *\n * @default '.js'\n */\n importExt?: string\n /**\n * The file extension to use for generated TypeScript files.\n *\n * @default '.ts'\n */\n fileExt?: string\n /**\n * Whether to export the whole defs file as a namespace export (`export * as\n * $defs from './xyz.defs.js'`). This is useful to have an escape hatch to\n * access the definitions in case of name conflicts with child namespaces.\n *\n * For example if two documents with if `com.example.foo` and\n * `com.example.foo.bar` coexist, the `com.example.foo.bar` namespace would\n * shadow any `bar` definition from the `com.example.foo` namespace. In that\n * case, having the `$defs` namespace export allows to still access those\n * definitions via `com.example.foo.$defs.bar`.\n *\n * @note enabling this will negatively impact bundle size because and\n * additional namespace object will be generated for each lexicon document.\n *\n * @default false\n */\n defsExport?: boolean\n /**\n * Whether to generate a default export for the \"main\" lexicon definition\n * schema in the parent namespace file.\n *\n * This allows simpler access the main schema when importing directly from the\n * file instead of using the full namespace as in:\n * `com.atproto.repo.getRecord`.\n *\n * ```ts\n * import getRecord from './com/atproto/repo/getRecord.js'\n * // instead of\n * import { main as getRecord } from './com/atproto/repo/getRecord.js'\n * ```\n *\n * @default false\n */\n defaultExport?: boolean\n}\n\n/**\n * Options for loading lexicon documents into the builder.\n *\n * Combines directory indexing options with filtering options to control\n * which lexicon documents are processed.\n *\n * @see {@link LexiconDirectoryIndexerOptions} for directory scanning options\n * @see {@link BuildFilterOptions} for include/exclude filtering\n */\nexport type LexBuilderLoadOptions = LexiconDirectoryIndexerOptions &\n BuildFilterOptions\n\n/**\n * Options for saving generated TypeScript files.\n *\n * Combines formatting options with output directory configuration.\n */\nexport type LexBuilderSaveOptions = FormatterOptions & {\n /**\n * The output directory path where generated TypeScript files will be written.\n */\n out: string\n /**\n * Whether to clear the output directory before writing files.\n *\n * When `true`, the entire output directory is deleted before writing new files.\n *\n * @default false\n */\n clear?: boolean\n /**\n * Whether to allow overwriting existing files.\n *\n * When `false`, an error is thrown if any output file already exists.\n *\n * @default false\n */\n override?: boolean\n}\n\n/**\n * Main builder class for generating TypeScript schemas from Lexicon documents.\n *\n * The LexBuilder orchestrates the entire code generation process:\n * 1. Loading and indexing lexicon documents from the filesystem\n * 2. Generating TypeScript type definitions and runtime schemas\n * 3. Creating namespace export trees for convenient imports\n * 4. Saving formatted output files\n *\n * @example\n * ```ts\n * const builder = new LexBuilder({ indexFile: true, pretty: true })\n *\n * // Load lexicons from a directory\n * await builder.load({ lexicons: './lexicons' })\n *\n * // Save generated TypeScript to output directory\n * await builder.save({ out: './src/generated', clear: true })\n * ```\n */\nexport class LexBuilder {\n readonly #imported = new Set<string>()\n readonly #project = new Project({\n useInMemoryFileSystem: true,\n manipulationSettings: { indentationText: IndentationText.TwoSpaces },\n })\n\n constructor(private readonly options: LexBuilderOptions = {}) {}\n\n get fileExt() {\n return this.options.fileExt ?? '.ts'\n }\n\n get importExt() {\n return this.options.importExt ?? '.js'\n }\n\n public async load(options: LexBuilderLoadOptions) {\n await using indexer = new FilteredIndexer(\n new LexiconDirectoryIndexer(options),\n buildFilter(options),\n )\n\n for await (const doc of indexer) {\n if (!this.#imported.has(doc.id)) {\n this.#imported.add(doc.id)\n } else {\n throw new Error(`Duplicate lexicon document id: ${doc.id}`)\n }\n\n await this.createDefsFile(doc, indexer)\n await this.createExportTree(doc)\n }\n }\n\n public async save(options: LexBuilderSaveOptions) {\n const files = this.#project.getSourceFiles()\n\n const destination = resolve(options.out)\n\n if (options.clear) {\n await rm(destination, { recursive: true, force: true })\n } else if (!options.override) {\n await Promise.all(\n files.map(async (f) =>\n assertNotFileExists(join(destination, f.getFilePath())),\n ),\n )\n }\n\n const formatter = new Formatter(options)\n\n await Promise.all(\n Array.from(files, async (file) => {\n const filePath = join(destination, file.getFilePath())\n const content = await formatter.format(file.getFullText())\n await mkdir(join(filePath, '..'), { recursive: true })\n await rm(filePath, { recursive: true, force: true })\n await writeFile(filePath, content, 'utf8')\n }),\n )\n }\n\n private createFile(path: string) {\n return this.#project.createSourceFile(path)\n }\n\n private getFile(path: string) {\n return this.#project.getSourceFile(path) || this.createFile(path)\n }\n\n private async createExportTree(doc: LexiconDocument) {\n const namespaces = doc.id.split('.')\n\n if (this.options.indexFile) {\n const indexFile = this.getFile(`/index${this.fileExt}`)\n\n const tldNs = namespaces[0]!\n assert(\n tldNs !== 'index',\n 'The \"indexFile\" options cannot be used with namespaces using a \".index\" tld.',\n )\n const tldNsSpecifier = `./${tldNs}${this.importExt}`\n if (!indexFile.getExportDeclaration(tldNsSpecifier)) {\n indexFile.addExportDeclaration({\n moduleSpecifier: tldNsSpecifier,\n namespaceExport: asNamespaceExport(tldNs),\n })\n }\n }\n\n // First create the parent namespaces\n for (let i = 0; i < namespaces.length - 1; i++) {\n const currentNs = namespaces[i]\n const childNs = namespaces[i + 1]\n\n const path = join('/', ...namespaces.slice(0, i + 1))\n const file = this.getFile(`${path}${this.fileExt}`)\n\n const childModuleSpecifier = `./${currentNs}/${childNs}${this.importExt}`\n const dec = file.getExportDeclaration(childModuleSpecifier)\n if (!dec) {\n file.addExportDeclaration({\n moduleSpecifier: childModuleSpecifier,\n namespaceExport: asNamespaceExport(childNs),\n })\n }\n }\n\n // The child file exports the schemas (as *)\n const path = join('/', ...namespaces)\n const file = this.getFile(`${path}${this.fileExt}`)\n\n file.addExportDeclaration({\n moduleSpecifier: `./${namespaces.at(-1)}.defs${this.importExt}`,\n })\n\n if (this.options.defsExport) {\n // @NOTE Individual exports exports from the defs file might conflict with\n // child namespaces. For this reason, we also add a namespace export for the\n // defs (export * as $defs from './xyz.defs.js'). This is an escape hatch\n // allowing to still access the definitions if a hash get shadowed by a\n // child namespace.\n file.addExportDeclaration({\n moduleSpecifier: `./${namespaces.at(-1)}.defs${this.importExt}`,\n namespaceExport: '$defs',\n })\n }\n\n if (this.options.defaultExport && doc.defs.main != null) {\n // export { main as default } from './xyz.defs.js'\n file.addExportDeclaration({\n moduleSpecifier: `./${namespaces.at(-1)}.defs${this.importExt}`,\n namedExports: [{ name: 'main', alias: 'default' }],\n })\n }\n }\n\n private async createDefsFile(\n doc: LexiconDocument,\n indexer: LexiconIndexer,\n ): Promise<void> {\n const path = join('/', ...doc.id.split('.'))\n const file = this.createFile(`${path}.defs${this.fileExt}`)\n\n const fileBuilder = new LexDefBuilder(this.options, file, doc, indexer)\n await fileBuilder.build()\n }\n}\n\nasync function assertNotFileExists(file: string): Promise<void> {\n try {\n await stat(file)\n throw new Error(`File already exists: ${file}`)\n } catch (err) {\n if (err instanceof Error && 'code' in err && err.code === 'ENOENT') return\n throw err\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { SourceFile } from 'ts-morph';
2
- import { LexiconDocument, LexiconIndexer, LexiconProcedure, LexiconQuery, LexiconSubscription } from '@atproto/lex-document';
3
- import { RefResolverOptions, ResolvedRef } from './ref-resolver.js';
2
+ import { LexiconDocument, LexiconIndexer } from '@atproto/lex-document';
3
+ import { RefResolverOptions } from './ref-resolver.js';
4
4
  /**
5
5
  * Configuration options for the {@link LexDefBuilder} class.
6
6
  *
@@ -13,15 +13,6 @@ export type LexDefBuilderOptions = RefResolverOptions & {
13
13
  * @default '@atproto/lex-schema'
14
14
  */
15
15
  lib?: string;
16
- /**
17
- * Whether to add `#__PURE__` annotations to function calls.
18
- *
19
- * These annotations help bundlers with tree-shaking by marking
20
- * side-effect-free function calls.
21
- *
22
- * @default false
23
- */
24
- pureAnnotations?: boolean;
25
16
  };
26
17
  /**
27
18
  * Builds TypeScript type definitions and runtime schemas from a single
@@ -42,15 +33,17 @@ export declare class LexDefBuilder {
42
33
  private readonly doc;
43
34
  private readonly refResolver;
44
35
  constructor(options: LexDefBuilderOptions, file: SourceFile, doc: LexiconDocument, indexer: LexiconIndexer);
45
- private pure;
46
36
  build(): Promise<void>;
47
37
  private addUtils;
48
38
  private addDef;
49
39
  private addPermissionSet;
40
+ private addParameters;
41
+ private addInput;
42
+ private addOutput;
43
+ private addMessage;
50
44
  private addProcedure;
51
45
  private addQuery;
52
46
  private addSubscription;
53
- addMethodTypeUtils(ref: ResolvedRef, def: LexiconProcedure | LexiconQuery | LexiconSubscription): void;
54
47
  private addRecord;
55
48
  private addObject;
56
49
  private addToken;
@@ -1 +1 @@
1
- {"version":3,"file":"lex-def-builder.d.ts","sourceRoot":"","sources":["../src/lex-def-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EAEX,MAAM,UAAU,CAAA;AACjB,OAAO,EAOL,eAAe,EAEf,cAAc,EAMd,gBAAgB,EAChB,YAAY,EAKZ,mBAAmB,EAGpB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAEL,kBAAkB,EAClB,WAAW,EAEZ,MAAM,mBAAmB,CAAA;AAG1B;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,kBAAkB,GAAG;IACtD;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAa;IAItB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG;IALtB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;gBAGtB,OAAO,EAAE,oBAAoB,EAC7B,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,eAAe,EACrC,OAAO,EAAE,cAAc;IAKzB,OAAO,CAAC,IAAI;IAIN,KAAK;IAyBX,OAAO,CAAC,QAAQ;YAYF,MAAM;YA8BN,gBAAgB;YAsBhB,YAAY;Y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