@amritk/helpers 0.6.1 → 0.7.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.
Files changed (67) hide show
  1. package/dist/build-dynamic-ref-map.d.ts +1 -0
  2. package/dist/build-dynamic-ref-map.d.ts.map +1 -0
  3. package/dist/build-dynamic-ref-map.js +31 -107
  4. package/dist/derive-root-type-name.d.ts +1 -0
  5. package/dist/derive-root-type-name.d.ts.map +1 -0
  6. package/dist/derive-root-type-name.js +37 -17
  7. package/dist/extract-dynamic-anchor-defs.d.ts +20 -0
  8. package/dist/extract-dynamic-anchor-defs.d.ts.map +1 -0
  9. package/dist/extract-dynamic-anchor-defs.js +30 -0
  10. package/dist/extract-refs.d.ts +1 -0
  11. package/dist/extract-refs.d.ts.map +1 -0
  12. package/dist/extract-refs.js +64 -33
  13. package/dist/generate-index-barrel.d.ts +29 -0
  14. package/dist/generate-index-barrel.d.ts.map +1 -0
  15. package/dist/generate-index-barrel.js +43 -0
  16. package/dist/generate-type-definition.d.ts +1 -0
  17. package/dist/generate-type-definition.d.ts.map +1 -0
  18. package/dist/generate-type-definition.js +449 -567
  19. package/dist/has-ref.d.ts +1 -0
  20. package/dist/has-ref.d.ts.map +1 -0
  21. package/dist/has-ref.js +7 -6
  22. package/dist/is-object.d.ts +1 -0
  23. package/dist/is-object.d.ts.map +1 -0
  24. package/dist/is-object.js +14 -5
  25. package/dist/mjst-extension.d.ts +1 -0
  26. package/dist/mjst-extension.d.ts.map +1 -0
  27. package/dist/mjst-extension.js +50 -122
  28. package/dist/parse-documentation.d.ts +1 -0
  29. package/dist/parse-documentation.d.ts.map +1 -0
  30. package/dist/parse-documentation.js +124 -87
  31. package/dist/ref-to-filename.d.ts +1 -0
  32. package/dist/ref-to-filename.d.ts.map +1 -0
  33. package/dist/ref-to-filename.js +106 -42
  34. package/dist/ref-to-name.d.ts +1 -0
  35. package/dist/ref-to-name.d.ts.map +1 -0
  36. package/dist/ref-to-name.js +39 -53
  37. package/dist/resolve-dynamic-refs.d.ts +1 -0
  38. package/dist/resolve-dynamic-refs.d.ts.map +1 -0
  39. package/dist/resolve-dynamic-refs.js +36 -28
  40. package/dist/resolve-ref.d.ts +1 -0
  41. package/dist/resolve-ref.d.ts.map +1 -0
  42. package/dist/resolve-ref.js +74 -39
  43. package/dist/safe-accessor.d.ts +1 -0
  44. package/dist/safe-accessor.d.ts.map +1 -0
  45. package/dist/safe-accessor.js +42 -19
  46. package/dist/schema-guards.d.ts +2 -1
  47. package/dist/schema-guards.d.ts.map +1 -0
  48. package/dist/schema-guards.js +119 -120
  49. package/dist/upgrade-draft07-schema.d.ts +1 -0
  50. package/dist/upgrade-draft07-schema.d.ts.map +1 -0
  51. package/dist/upgrade-draft07-schema.js +152 -130
  52. package/dist/validate-array.d.ts +1 -0
  53. package/dist/validate-array.d.ts.map +1 -0
  54. package/dist/validate-array.js +12 -14
  55. package/dist/validate-record.d.ts +1 -0
  56. package/dist/validate-record.d.ts.map +1 -0
  57. package/dist/validate-record.js +15 -17
  58. package/dist/walk-ref-graph.d.ts +54 -0
  59. package/dist/walk-ref-graph.d.ts.map +1 -0
  60. package/dist/walk-ref-graph.js +123 -0
  61. package/package.json +9 -88
  62. package/src/extract-dynamic-anchor-defs.test.ts +29 -0
  63. package/src/extract-dynamic-anchor-defs.ts +33 -0
  64. package/src/generate-index-barrel.test.ts +41 -0
  65. package/src/generate-index-barrel.ts +62 -0
  66. package/src/walk-ref-graph.test.ts +103 -0
  67. package/src/walk-ref-graph.ts +184 -0
@@ -15,3 +15,4 @@ import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
15
15
  * // Returns: { "#meta": "#/$defs/schema" }
16
16
  */
17
17
  export declare const buildDynamicRefMap: (rootSchema: JSONSchema) => Record<string, string>;
18
+ //# sourceMappingURL=build-dynamic-ref-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-dynamic-ref-map.d.ts","sourceRoot":"","sources":["../src/build-dynamic-ref-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAIjE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,eAAgB,UAAU,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAsBhF,CAAA"}
@@ -1,109 +1,33 @@
1
- // src/has-ref.ts
2
- var hasRef = (value) => {
3
- return typeof value === "object" && value !== null && !Array.isArray(value) && "$ref" in value && typeof value.$ref === "string";
4
- };
5
-
6
- // src/schema-guards.ts
7
- var isSchemaObject = (schema) => {
8
- return typeof schema === "object" && schema !== null && typeof schema !== "boolean";
9
- };
10
- var hasType = (schema) => {
11
- return isSchemaObject(schema) && "type" in schema && typeof schema.type === "string";
12
- };
13
- var isObjectSchema = (schema) => {
14
- return isSchemaObject(schema) && (("type" in schema) && schema.type === "object" || ("properties" in schema));
15
- };
16
- var hasProperties = (schema) => {
17
- return isSchemaObject(schema) && "properties" in schema && typeof schema.properties === "object" && schema.properties !== null;
18
- };
19
- var hasEnum = (schema) => {
20
- return isSchemaObject(schema) && "enum" in schema && Array.isArray(schema.enum);
21
- };
22
- var hasConst = (schema) => {
23
- return isSchemaObject(schema) && "const" in schema;
24
- };
25
- var hasPattern = (schema) => {
26
- return isSchemaObject(schema) && "pattern" in schema && typeof schema.pattern === "string";
27
- };
28
- var hasFormat = (schema) => {
29
- return isSchemaObject(schema) && "format" in schema && typeof schema.format === "string";
30
- };
31
- var hasDefault = (schema) => {
32
- return isSchemaObject(schema) && "default" in schema;
33
- };
34
- var hasExamples = (schema) => {
35
- return isSchemaObject(schema) && "examples" in schema && Array.isArray(schema.examples);
36
- };
37
- var hasOneOf = (schema) => {
38
- return isSchemaObject(schema) && "oneOf" in schema && Array.isArray(schema.oneOf);
39
- };
40
- var hasAnyOf = (schema) => {
41
- return isSchemaObject(schema) && "anyOf" in schema && Array.isArray(schema.anyOf);
42
- };
43
- var hasAllOf = (schema) => {
44
- return isSchemaObject(schema) && "allOf" in schema && Array.isArray(schema.allOf);
45
- };
46
- var hasRequired = (schema) => {
47
- return isSchemaObject(schema) && "required" in schema && Array.isArray(schema.required);
48
- };
49
- var hasItems = (schema) => {
50
- return isSchemaObject(schema) && "items" in schema && typeof schema.items === "object" && schema.items !== null && typeof schema.items !== "boolean";
51
- };
52
- var hasAdditionalProperties = (schema) => {
53
- return isSchemaObject(schema) && "additionalProperties" in schema;
54
- };
55
- var hasMinLength = (schema) => {
56
- return isSchemaObject(schema) && "minLength" in schema && typeof schema.minLength === "number";
57
- };
58
- var hasMaxLength = (schema) => {
59
- return isSchemaObject(schema) && "maxLength" in schema && typeof schema.maxLength === "number";
60
- };
61
- var hasMinimum = (schema) => {
62
- return isSchemaObject(schema) && "minimum" in schema && typeof schema.minimum === "number";
63
- };
64
- var hasMaximum = (schema) => {
65
- return isSchemaObject(schema) && "maximum" in schema && typeof schema.maximum === "number";
66
- };
67
- var hasExclusiveMinimum = (schema) => {
68
- return isSchemaObject(schema) && "exclusiveMinimum" in schema && typeof schema.exclusiveMinimum === "number";
69
- };
70
- var hasExclusiveMaximum = (schema) => {
71
- return isSchemaObject(schema) && "exclusiveMaximum" in schema && typeof schema.exclusiveMaximum === "number";
72
- };
73
- var hasMultipleOf = (schema) => {
74
- return isSchemaObject(schema) && "multipleOf" in schema && typeof schema.multipleOf === "number";
75
- };
76
- var hasMinItems = (schema) => {
77
- return isSchemaObject(schema) && "minItems" in schema && typeof schema.minItems === "number";
78
- };
79
- var hasMaxItems = (schema) => {
80
- return isSchemaObject(schema) && "maxItems" in schema && typeof schema.maxItems === "number";
81
- };
82
- var hasUniqueItems = (schema) => {
83
- return isSchemaObject(schema) && "uniqueItems" in schema && typeof schema.uniqueItems === "boolean";
84
- };
85
- var hasMinProperties = (schema) => {
86
- return isSchemaObject(schema) && "minProperties" in schema && typeof schema.minProperties === "number";
87
- };
88
- var hasMaxProperties = (schema) => {
89
- return isSchemaObject(schema) && "maxProperties" in schema && typeof schema.maxProperties === "number";
90
- };
91
-
92
- // src/build-dynamic-ref-map.ts
93
- var buildDynamicRefMap = (rootSchema) => {
94
- const map = {};
95
- if (!isSchemaObject(rootSchema) || !("$defs" in rootSchema)) {
96
- return map;
97
- }
98
- const defs = rootSchema.$defs;
99
- for (const [key, value] of Object.entries(defs)) {
100
- if (typeof value === "object" && value !== null && "$dynamicAnchor" in value && typeof value["$dynamicAnchor"] === "string") {
101
- const anchor = value["$dynamicAnchor"];
102
- map[`#${anchor}`] = `#/$defs/${key}`;
1
+ import { isSchemaObject } from './schema-guards.js';
2
+ /**
3
+ * Builds a map of $dynamicRef anchor values to their corresponding $ref paths.
4
+ *
5
+ * JSON Schema 2020-12 uses $dynamicAnchor and $dynamicRef for late-binding references.
6
+ * In the OpenAPI spec, $dynamicAnchor: "meta" on the schema definition allows properties
7
+ * like media-type.schema to reference it via $dynamicRef: "#meta".
8
+ *
9
+ * This function scans all $defs for entries with $dynamicAnchor and builds a lookup
10
+ * so we can convert $dynamicRef values to concrete $ref paths.
11
+ *
12
+ * @example
13
+ * // Given a schema with $defs.schema having $dynamicAnchor: "meta"
14
+ * buildDynamicRefMap(rootSchema)
15
+ * // Returns: { "#meta": "#/$defs/schema" }
16
+ */
17
+ export const buildDynamicRefMap = (rootSchema) => {
18
+ const map = {};
19
+ if (!isSchemaObject(rootSchema) || !('$defs' in rootSchema)) {
20
+ return map;
103
21
  }
104
- }
105
- return map;
106
- };
107
- export {
108
- buildDynamicRefMap
22
+ const defs = rootSchema.$defs;
23
+ for (const [key, value] of Object.entries(defs)) {
24
+ if (typeof value === 'object' &&
25
+ value !== null &&
26
+ '$dynamicAnchor' in value &&
27
+ typeof value['$dynamicAnchor'] === 'string') {
28
+ const anchor = value['$dynamicAnchor'];
29
+ map[`#${anchor}`] = `#/$defs/${key}`;
30
+ }
31
+ }
32
+ return map;
109
33
  };
@@ -18,3 +18,4 @@
18
18
  * ```
19
19
  */
20
20
  export declare const deriveRootTypeName: (schema: unknown) => string;
21
+ //# sourceMappingURL=derive-root-type-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derive-root-type-name.d.ts","sourceRoot":"","sources":["../src/derive-root-type-name.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,kBAAkB,WAAY,OAAO,KAAG,MAOpD,CAAA"}
@@ -1,19 +1,39 @@
1
- // src/is-object.ts
2
- var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
3
-
4
- // src/derive-root-type-name.ts
5
- var titleToPascalCase = (title) => {
6
- const words = title.split(/[^a-zA-Z0-9]+/).filter(Boolean);
7
- const pascal = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
8
- return pascal.replace(/^\d+/, "");
1
+ import { isObject } from './is-object.js';
2
+ /**
3
+ * Converts an arbitrary title string into a PascalCase TypeScript identifier.
4
+ * Splits on any run of non-alphanumeric characters, capitalizes the first
5
+ * letter of each word while preserving the rest (so acronyms like "API" or
6
+ * "JSON" survive intact), and drops leading digits since an identifier may not
7
+ * start with a number.
8
+ */
9
+ const titleToPascalCase = (title) => {
10
+ const words = title.split(/[^a-zA-Z0-9]+/).filter(Boolean);
11
+ const pascal = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join('');
12
+ return pascal.replace(/^\d+/, '');
9
13
  };
10
- var deriveRootTypeName = (schema) => {
11
- if (!isObject(schema) || typeof schema["title"] !== "string") {
12
- return "Document";
13
- }
14
- const name = titleToPascalCase(schema["title"]);
15
- return name || "Document";
16
- };
17
- export {
18
- deriveRootTypeName
14
+ /**
15
+ * Derives the root type name for a generated schema from its `title` keyword.
16
+ *
17
+ * We name the root after the schema itself instead of a generic "Document" so
18
+ * the generated types and parsers read naturally (e.g. an OpenAPI schema yields
19
+ * `OpenApi` / `parseOpenApi`). When the schema has no usable `title`, we fall
20
+ * back to "Document" to keep output deterministic.
21
+ *
22
+ * @param schema - The root JSON Schema. A boolean schema or one without a
23
+ * string `title` falls back to the default.
24
+ * @returns A PascalCase type name derived from the title, or "Document".
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * deriveRootTypeName({ title: 'OpenAPI Document' }) // 'OpenAPIDocument'
29
+ * deriveRootTypeName({ title: 'my-config' }) // 'MyConfig'
30
+ * deriveRootTypeName({ type: 'object' }) // 'Document'
31
+ * ```
32
+ */
33
+ export const deriveRootTypeName = (schema) => {
34
+ if (!isObject(schema) || typeof schema['title'] !== 'string') {
35
+ return 'Document';
36
+ }
37
+ const name = titleToPascalCase(schema['title']);
38
+ return name || 'Document';
19
39
  };
@@ -0,0 +1,20 @@
1
+ import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
2
+ /**
3
+ * Collects `#/$defs/<key>` refs for every root definition that carries a
4
+ * `$dynamicAnchor`.
5
+ *
6
+ * These definitions are reachable only through `$dynamicRef`, which the ref
7
+ * walker does not follow directly (a `$dynamicRef` is rewritten to a concrete
8
+ * `$ref` by `resolveDynamicRefs` *after* the schema is extracted, so plain
9
+ * `extractRefs` never sees it). Seeding them explicitly guarantees a file is
10
+ * generated for each dynamic-anchor target — without this, a generator would
11
+ * emit code that imports a type whose file was never produced.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // $defs.schema has $dynamicAnchor: "meta"
16
+ * extractDynamicAnchorDefs(rootSchema) // ['#/$defs/schema']
17
+ * ```
18
+ */
19
+ export declare const extractDynamicAnchorDefs: (schema: JSONSchema) => string[];
20
+ //# sourceMappingURL=extract-dynamic-anchor-defs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-dynamic-anchor-defs.d.ts","sourceRoot":"","sources":["../src/extract-dynamic-anchor-defs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAEjE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,wBAAwB,WAAY,UAAU,KAAG,MAAM,EAanE,CAAA"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Collects `#/$defs/<key>` refs for every root definition that carries a
3
+ * `$dynamicAnchor`.
4
+ *
5
+ * These definitions are reachable only through `$dynamicRef`, which the ref
6
+ * walker does not follow directly (a `$dynamicRef` is rewritten to a concrete
7
+ * `$ref` by `resolveDynamicRefs` *after* the schema is extracted, so plain
8
+ * `extractRefs` never sees it). Seeding them explicitly guarantees a file is
9
+ * generated for each dynamic-anchor target — without this, a generator would
10
+ * emit code that imports a type whose file was never produced.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // $defs.schema has $dynamicAnchor: "meta"
15
+ * extractDynamicAnchorDefs(rootSchema) // ['#/$defs/schema']
16
+ * ```
17
+ */
18
+ export const extractDynamicAnchorDefs = (schema) => {
19
+ const refs = [];
20
+ if (typeof schema !== 'object' || schema === null)
21
+ return refs;
22
+ if (!('$defs' in schema) || typeof schema['$defs'] !== 'object' || schema['$defs'] === null)
23
+ return refs;
24
+ for (const [key, value] of Object.entries(schema['$defs'])) {
25
+ if (typeof value === 'object' && value !== null && '$dynamicAnchor' in value) {
26
+ refs.push(`#/$defs/${key}`);
27
+ }
28
+ }
29
+ return refs;
30
+ };
@@ -21,3 +21,4 @@ import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
21
21
  * ```
22
22
  */
23
23
  export declare const extractRefs: (schema: JSONSchema) => Set<string>;
24
+ //# sourceMappingURL=extract-refs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-refs.d.ts","sourceRoot":"","sources":["../src/extract-refs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAsBjE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,WAAW,WAAY,UAAU,KAAG,GAAG,CAAC,MAAM,CA6B1D,CAAA"}
@@ -1,36 +1,67 @@
1
- // src/extract-refs.ts
2
- var isResolvableRef = (ref) => {
3
- if (ref === "#")
1
+ /**
2
+ * Returns true if a $ref value should be queued for processing.
3
+ *
4
+ * Accepted forms:
5
+ * - Internal: `#/$defs/foo` or `#/definitions/foo`
6
+ * - URI key: `http://example.com/foo.json` (no fragment, or empty fragment)
7
+ * - URI with fragment: `http://example.com/foo.json#/definitions/bar`
8
+ *
9
+ * Excluded:
10
+ * - `#` alone (self-reference, not a standalone definition)
11
+ * - Relative path refs (e.g. `/components/messages/foo`) — these point into
12
+ * example data in the schema document, not into type definitions
13
+ */
14
+ const isResolvableRef = (ref) => {
15
+ if (ref === '#')
16
+ return false;
17
+ if (ref.startsWith('#'))
18
+ return true;
19
+ if (ref.startsWith('http://') || ref.startsWith('https://'))
20
+ return true;
4
21
  return false;
5
- if (ref.startsWith("#"))
6
- return true;
7
- if (ref.startsWith("http://") || ref.startsWith("https://"))
8
- return true;
9
- return false;
10
22
  };
11
- var extractRefs = (schema) => {
12
- const refs = new Set;
13
- const traverse = (obj) => {
14
- if (typeof obj !== "object" || obj === null) {
15
- return;
16
- }
17
- if (Array.isArray(obj)) {
18
- for (const item of obj) {
19
- traverse(item);
20
- }
21
- return;
22
- }
23
- const record = obj;
24
- if ("$ref" in record && typeof record["$ref"] === "string" && isResolvableRef(record["$ref"])) {
25
- refs.add(record["$ref"]);
26
- }
27
- for (const key in record) {
28
- traverse(record[key]);
29
- }
30
- };
31
- traverse(schema);
32
- return refs;
33
- };
34
- export {
35
- extractRefs
23
+ /**
24
+ * Extracts all $ref values from a JSON Schema recursively.
25
+ * Returns both internal (`#`-prefixed) and URI refs so the build pipeline
26
+ * can resolve and generate files for all referenced definitions.
27
+ *
28
+ * @param schema - The JSON Schema to extract refs from
29
+ * @returns A Set of unique ref strings found in the schema
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const schema = {
34
+ * type: 'object',
35
+ * properties: {
36
+ * contact: { $ref: '#/$defs/contact' },
37
+ * channel: { $ref: 'http://example.com/channel.json' },
38
+ * }
39
+ * }
40
+ * const refs = extractRefs(schema)
41
+ * // refs = Set(['#/$defs/contact', 'http://example.com/channel.json'])
42
+ * ```
43
+ */
44
+ export const extractRefs = (schema) => {
45
+ const refs = new Set();
46
+ const traverse = (obj) => {
47
+ if (typeof obj !== 'object' || obj === null) {
48
+ return;
49
+ }
50
+ if (Array.isArray(obj)) {
51
+ for (const item of obj) {
52
+ traverse(item);
53
+ }
54
+ return;
55
+ }
56
+ const record = obj;
57
+ if ('$ref' in record && typeof record['$ref'] === 'string' && isResolvableRef(record['$ref'])) {
58
+ refs.add(record['$ref']);
59
+ }
60
+ // Recursively traverse all properties using for...in to avoid intermediate array allocation
61
+ for (const key in record) {
62
+ traverse(record[key]);
63
+ }
64
+ };
65
+ traverse(schema);
66
+ return refs;
36
67
  };
@@ -0,0 +1,29 @@
1
+ /** A generated file: its name (with extension) and TypeScript source. */
2
+ export type IndexBarrelFile = {
3
+ filename: string;
4
+ content: string;
5
+ };
6
+ /** Options controlling how the barrel re-exports each module. */
7
+ export type GenerateIndexBarrelOptions = {
8
+ /**
9
+ * When true, every re-export is type-only (`export type { ... }`). Used by the
10
+ * types-only parser output, where no runtime values exist to re-export.
11
+ * Defaults to `false`.
12
+ */
13
+ readonly typesOnly?: boolean;
14
+ };
15
+ /**
16
+ * Builds the `index.ts` barrel that re-exports every generated module. This is
17
+ * the shared version of the near-identical barrel each generator used to build
18
+ * inline: it scans each file's source for `export type` / `export const`
19
+ * declarations and emits one re-export line per module, sorted by filename.
20
+ *
21
+ * Files under `_helpers/` are internal runtime helpers (embedded-mode output)
22
+ * and are never re-exported. Modules that expose nothing are skipped.
23
+ *
24
+ * @param files - The generated files to barrel (the `index.ts` itself excluded).
25
+ * @param options - See {@link GenerateIndexBarrelOptions}.
26
+ * @returns The `index.ts` file content.
27
+ */
28
+ export declare const generateIndexBarrel: (files: IndexBarrelFile[], options?: GenerateIndexBarrelOptions) => string;
29
+ //# sourceMappingURL=generate-index-barrel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-index-barrel.d.ts","sourceRoot":"","sources":["../src/generate-index-barrel.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,iEAAiE;AACjE,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAOD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,UAAW,eAAe,EAAE,YAAW,0BAA0B,KAAQ,MA2BxG,CAAA"}
@@ -0,0 +1,43 @@
1
+ // Generated files declare their public surface with these two forms, so we can
2
+ // recover the export names from the source text without parsing it.
3
+ const TYPE_EXPORT_RE = /^export type (\w+)/gm;
4
+ const CONST_EXPORT_RE = /^export const (\w+)/gm;
5
+ /**
6
+ * Builds the `index.ts` barrel that re-exports every generated module. This is
7
+ * the shared version of the near-identical barrel each generator used to build
8
+ * inline: it scans each file's source for `export type` / `export const`
9
+ * declarations and emits one re-export line per module, sorted by filename.
10
+ *
11
+ * Files under `_helpers/` are internal runtime helpers (embedded-mode output)
12
+ * and are never re-exported. Modules that expose nothing are skipped.
13
+ *
14
+ * @param files - The generated files to barrel (the `index.ts` itself excluded).
15
+ * @param options - See {@link GenerateIndexBarrelOptions}.
16
+ * @returns The `index.ts` file content.
17
+ */
18
+ export const generateIndexBarrel = (files, options = {}) => {
19
+ const typesOnly = options.typesOnly ?? false;
20
+ const sortedFiles = files
21
+ .filter((file) => !file.filename.startsWith('_helpers/'))
22
+ .sort((a, b) => a.filename.localeCompare(b.filename));
23
+ let indexContent = '';
24
+ for (const file of sortedFiles) {
25
+ const moduleName = file.filename.replace(/\.ts$/, '');
26
+ const typeNames = [];
27
+ const constNames = [];
28
+ for (const match of file.content.matchAll(TYPE_EXPORT_RE))
29
+ typeNames.push(match[1]);
30
+ for (const match of file.content.matchAll(CONST_EXPORT_RE))
31
+ constNames.push(match[1]);
32
+ if (typeNames.length === 0 && constNames.length === 0)
33
+ continue;
34
+ if (typesOnly) {
35
+ indexContent += `export type { ${typeNames.join(', ')} } from './${moduleName}';\n`;
36
+ }
37
+ else {
38
+ const typeExports = typeNames.map((name) => `type ${name}`);
39
+ indexContent += `export { ${[...typeExports, ...constNames].join(', ')} } from './${moduleName}';\n`;
40
+ }
41
+ }
42
+ return indexContent;
43
+ };
@@ -15,3 +15,4 @@ export type TypeOptions = {
15
15
  * Uses $comment as inline JSDoc description when present.
16
16
  */
17
17
  export declare const generateTypeDefinition: (schema: JSONSchema, typeName: string, options?: TypeOptions) => string;
18
+ //# sourceMappingURL=generate-type-definition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-type-definition.d.ts","sourceRoot":"","sources":["../src/generate-type-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;AAYjE,iDAAiD;AACjD,MAAM,MAAM,WAAW,GAAG;IACxB,kGAAkG;IAClG,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B,CAAA;AAmZD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,WAAY,UAAU,YAAY,MAAM,YAAW,WAAW,KAAQ,MAsJxG,CAAA"}