@abapify/ts-xsd 0.4.0 → 0.4.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.
@@ -0,0 +1,262 @@
1
+ import { p as parseXsd } from "./runner-BSGqj8LM.mjs";
2
+
3
+ //#region src/codegen/generate.ts
4
+ /**
5
+ * Schema Literal Generator
6
+ *
7
+ * Transforms a parsed Schema object into a TypeScript literal string
8
+ * that preserves type information for InferSchema<T>.
9
+ */
10
+ /**
11
+ * Generate a TypeScript literal string from XSD content.
12
+ *
13
+ * @param xsdContent - XSD file content as string
14
+ * @param options - Generation options
15
+ * @returns TypeScript code with schema as const literal
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const xsd = `<xs:schema>...</xs:schema>`;
20
+ * const code = generateSchemaLiteral(xsd, { name: 'PersonSchema' });
21
+ * // export const PersonSchema = { ... } as const;
22
+ * ```
23
+ */
24
+ function generateSchemaLiteral(xsdContent, options = {}) {
25
+ const schema = parseXsd(xsdContent);
26
+ const features = options.features ?? {};
27
+ const exclude = new Set(options.exclude ?? []);
28
+ let outputSchema = { ...schema };
29
+ if (features.$filename && options.name) outputSchema = {
30
+ $filename: `${options.name}.xsd`,
31
+ ...outputSchema
32
+ };
33
+ outputSchema = applyTransforms(outputSchema, features, exclude);
34
+ return schemaToLiteral(outputSchema, options);
35
+ }
36
+ /**
37
+ * Apply transformations: features ($xmlns, $imports) and exclude filter.
38
+ * Used by generateSchemaLiteral (without imports).
39
+ */
40
+ function applyTransforms(schema, features, exclude) {
41
+ return applyTransformsWithImports(schema, features, exclude, []);
42
+ }
43
+ /**
44
+ * Special marker for schema references (not serialized as strings).
45
+ */
46
+ var SchemaRef = class {
47
+ name;
48
+ constructor(name) {
49
+ this.name = name;
50
+ }
51
+ };
52
+ /**
53
+ * Apply transformations with schema imports as references.
54
+ */
55
+ function applyTransformsWithImports(schema, features, exclude, importedSchemaNames) {
56
+ const result = {};
57
+ for (const [key, value] of Object.entries(schema)) {
58
+ if (exclude.has(key)) continue;
59
+ if (key === "$xmlns") {
60
+ if (features.$xmlns) result[key] = value;
61
+ } else if (key === "import") {
62
+ if (features.$imports && importedSchemaNames.length > 0) result["$imports"] = importedSchemaNames.map((name) => new SchemaRef(name));
63
+ } else result[key] = filterDeep(value, exclude);
64
+ }
65
+ return result;
66
+ }
67
+ /**
68
+ * Recursively filter excluded properties from nested structures.
69
+ */
70
+ function filterDeep(value, exclude) {
71
+ if (Array.isArray(value)) return value.map((item) => filterDeep(item, exclude));
72
+ if (value !== null && typeof value === "object") {
73
+ const result = {};
74
+ for (const [k, v] of Object.entries(value)) if (!exclude.has(k)) result[k] = filterDeep(v, exclude);
75
+ return result;
76
+ }
77
+ return value;
78
+ }
79
+ /**
80
+ * Generate a complete TypeScript file from XSD content.
81
+ *
82
+ * @param xsdContent - XSD file content as string
83
+ * @param options - Generation options
84
+ * @returns Complete TypeScript file content
85
+ */
86
+ function generateSchemaFile(xsdContent, options = {}) {
87
+ const { name = "schema", comment, features = {}, importResolver, isolatedDeclarations = false } = options;
88
+ const xsdImports = parseXsd(xsdContent).import ?? [];
89
+ const tsImports = [];
90
+ const importedSchemaNames = [];
91
+ if (isolatedDeclarations) tsImports.push("import type { Schema } from '@abapify/ts-xsd';");
92
+ if (features.$imports && importResolver) {
93
+ for (const imp of xsdImports) if (imp.schemaLocation) {
94
+ const modulePath = importResolver(imp.schemaLocation);
95
+ if (modulePath) {
96
+ const schemaName = imp.schemaLocation.replace(/\.xsd$/, "").replace(/^.*\//, "");
97
+ tsImports.push(`import ${schemaName} from '${modulePath}';`);
98
+ importedSchemaNames.push(schemaName);
99
+ }
100
+ }
101
+ }
102
+ return [
103
+ "/**",
104
+ " * Auto-generated schema literal from XSD",
105
+ " * ",
106
+ " * DO NOT EDIT - Generated by ts-xsd codegen",
107
+ comment ? ` * ${comment}` : null,
108
+ " */",
109
+ "",
110
+ ...tsImports,
111
+ tsImports.length > 0 ? "" : null,
112
+ generateSchemaLiteralWithImports(xsdContent, options, importedSchemaNames),
113
+ "",
114
+ `export type ${pascalCase(name)}Type = typeof ${name};`,
115
+ ""
116
+ ].filter((line) => line !== null).join("\n");
117
+ }
118
+ /**
119
+ * Generate schema literal with $imports as schema references.
120
+ */
121
+ function generateSchemaLiteralWithImports(xsdContent, options, importedSchemaNames) {
122
+ const schema = parseXsd(xsdContent);
123
+ const features = options.features ?? {};
124
+ const exclude = new Set(options.exclude ?? []);
125
+ let outputSchema = { ...schema };
126
+ if (features.$filename && options.name) outputSchema = {
127
+ $filename: `${options.name}.xsd`,
128
+ ...outputSchema
129
+ };
130
+ outputSchema = applyTransformsWithImports(outputSchema, features, exclude, importedSchemaNames);
131
+ return schemaToLiteral(outputSchema, options);
132
+ }
133
+ /**
134
+ * Escape reserved words by adding underscore suffix.
135
+ */
136
+ function escapeReservedWord(name) {
137
+ return RESERVED_WORDS.has(name) ? `${name}_` : name;
138
+ }
139
+ /**
140
+ * Convert a Schema object to a TypeScript literal string.
141
+ */
142
+ function schemaToLiteral(schema, options = {}) {
143
+ const { name = "schema", pretty = true, indent = " ", isolatedDeclarations = false, singleQuote = false } = options;
144
+ return `export const ${escapeReservedWord(name)} = ${objectToLiteral(schema, pretty, indent, 0, singleQuote)} ${isolatedDeclarations ? "satisfies Schema as const" : "as const"};`;
145
+ }
146
+ /**
147
+ * Format a string value as a single-quoted literal, unescaping JSON double quotes
148
+ * and escaping any single quotes.
149
+ */
150
+ function toSingleQuoteLiteral(jsonStr) {
151
+ return `'${jsonStr.slice(1, -1).replaceAll("\\\"", "\"").replaceAll("'", "\\'")}'`;
152
+ }
153
+ /**
154
+ * Convert any value to a TypeScript literal string.
155
+ */
156
+ function objectToLiteral(value, pretty, indent, depth, singleQuote = false) {
157
+ if (value === null || value === void 0) return "undefined";
158
+ if (value instanceof SchemaRef) return value.name;
159
+ if (typeof value === "string") {
160
+ const json = JSON.stringify(value);
161
+ if (singleQuote) return toSingleQuoteLiteral(json);
162
+ return json;
163
+ }
164
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
165
+ if (Array.isArray(value)) {
166
+ if (value.length === 0) return "[]";
167
+ const items = value.map((item) => objectToLiteral(item, pretty, indent, depth + 1, singleQuote));
168
+ if (pretty) {
169
+ const itemIndent = indent.repeat(depth + 1);
170
+ const closeIndent = indent.repeat(depth);
171
+ return `[\n${items.map((item) => `${itemIndent}${item}`).join(",\n")},\n${closeIndent}]`;
172
+ }
173
+ return `[${items.join(", ")}]`;
174
+ }
175
+ if (typeof value === "object") {
176
+ const entries = Object.entries(value).filter(([, v]) => v !== void 0);
177
+ if (entries.length === 0) return "{}";
178
+ const props = entries.map(([key, val]) => {
179
+ let keyStr = key;
180
+ if (!isValidIdentifier(key)) {
181
+ const json = JSON.stringify(key);
182
+ keyStr = singleQuote ? toSingleQuoteLiteral(json) : json;
183
+ }
184
+ const valStr = objectToLiteral(val, pretty, indent, depth + 1, singleQuote);
185
+ return `${keyStr}: ${valStr}`;
186
+ });
187
+ if (pretty) {
188
+ const propIndent = indent.repeat(depth + 1);
189
+ const closeIndent = indent.repeat(depth);
190
+ return `{\n${props.map((prop) => `${propIndent}${prop}`).join(",\n")},\n${closeIndent}}`;
191
+ }
192
+ return `{ ${props.join(", ")} }`;
193
+ }
194
+ return "undefined";
195
+ }
196
+ /**
197
+ * JavaScript reserved words that cannot be used as variable names.
198
+ */
199
+ const RESERVED_WORDS = /* @__PURE__ */ new Set([
200
+ "break",
201
+ "case",
202
+ "catch",
203
+ "continue",
204
+ "debugger",
205
+ "default",
206
+ "delete",
207
+ "do",
208
+ "else",
209
+ "finally",
210
+ "for",
211
+ "function",
212
+ "if",
213
+ "in",
214
+ "instanceof",
215
+ "new",
216
+ "return",
217
+ "switch",
218
+ "this",
219
+ "throw",
220
+ "try",
221
+ "typeof",
222
+ "var",
223
+ "void",
224
+ "while",
225
+ "with",
226
+ "class",
227
+ "const",
228
+ "enum",
229
+ "export",
230
+ "extends",
231
+ "import",
232
+ "super",
233
+ "implements",
234
+ "interface",
235
+ "let",
236
+ "package",
237
+ "private",
238
+ "protected",
239
+ "public",
240
+ "static",
241
+ "yield",
242
+ "await",
243
+ "null",
244
+ "true",
245
+ "false"
246
+ ]);
247
+ /**
248
+ * Check if a string is a valid JavaScript identifier.
249
+ */
250
+ function isValidIdentifier(str) {
251
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(str) && !RESERVED_WORDS.has(str);
252
+ }
253
+ /**
254
+ * Convert string to PascalCase.
255
+ */
256
+ function pascalCase(str) {
257
+ return str.replaceAll(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : "").replace(/^./, (s) => s.toUpperCase());
258
+ }
259
+
260
+ //#endregion
261
+ export { generateSchemaLiteral as n, generateSchemaFile as t };
262
+ //# sourceMappingURL=generate-Br6rW6sE.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-Br6rW6sE.mjs","names":["obj"],"sources":["../src/codegen/generate.ts"],"sourcesContent":["/**\n * Schema Literal Generator\n *\n * Transforms a parsed Schema object into a TypeScript literal string\n * that preserves type information for InferSchema<T>.\n */\n\nimport { parseXsd } from '../xsd';\nimport type { Schema } from '../xsd/types';\n\nexport interface GenerateOptions {\n /** Variable name for the exported schema */\n name?: string;\n /** Add JSDoc comment */\n comment?: string;\n /** Pretty print with indentation */\n pretty?: boolean;\n /** Indentation string (default: ' ') */\n indent?: string;\n /**\n * Enable specific $ metadata features in output.\n * - `$xmlns`: Keep `$xmlns` in output (already parsed as $xmlns)\n * - `$imports`: Rename `import` → `$imports` for schema linking\n * - `$filename`: Include `$filename` (uses `name` option + '.xsd')\n *\n * @example\n * ```typescript\n * features: { $xmlns: true, $imports: true, $filename: true }\n * ```\n */\n features?: {\n /** Keep `$xmlns` in output */\n $xmlns?: boolean;\n /** Rename `import` → `$imports` for schema linking */\n $imports?: boolean;\n /** Include `$filename` (uses `name` + '.xsd') */\n $filename?: boolean;\n };\n /**\n * Property names to exclude from output.\n * Useful for removing annotations, documentation, etc.\n *\n * @example\n * ```typescript\n * exclude: ['annotation'] // Remove all annotation elements\n * ```\n */\n exclude?: string[];\n /** Resolver for import paths (schemaLocation -> module path) */\n importResolver?: (schemaLocation: string) => string | null;\n /**\n * Generate isolatedDeclarations-compatible output.\n * Uses `satisfies Schema as const` instead of just `as const`.\n */\n isolatedDeclarations?: boolean;\n /** Use single quotes for string literals and property names */\n singleQuote?: boolean;\n}\n\n/**\n * Generate a TypeScript literal string from XSD content.\n *\n * @param xsdContent - XSD file content as string\n * @param options - Generation options\n * @returns TypeScript code with schema as const literal\n *\n * @example\n * ```typescript\n * const xsd = `<xs:schema>...</xs:schema>`;\n * const code = generateSchemaLiteral(xsd, { name: 'PersonSchema' });\n * // export const PersonSchema = { ... } as const;\n * ```\n */\nexport function generateSchemaLiteral(\n xsdContent: string,\n options: GenerateOptions = {},\n): string {\n const schema = parseXsd(xsdContent);\n const features = options.features ?? {};\n const exclude = new Set(options.exclude ?? []);\n\n // Transform schema\n let outputSchema: Record<string, unknown> = { ...schema };\n\n // Add $filename when enabled (uses name option)\n if (features.$filename && options.name) {\n outputSchema = { $filename: `${options.name}.xsd`, ...outputSchema };\n }\n\n // Apply transformations (features + exclude)\n outputSchema = applyTransforms(outputSchema, features, exclude);\n\n return schemaToLiteral(outputSchema as Schema, options);\n}\n\n/**\n * Apply transformations: features ($xmlns, $imports) and exclude filter.\n * Used by generateSchemaLiteral (without imports).\n */\nfunction applyTransforms(\n schema: Record<string, unknown>,\n features: NonNullable<GenerateOptions['features']>,\n exclude: Set<string>,\n): Record<string, unknown> {\n return applyTransformsWithImports(schema, features, exclude, []);\n}\n\n/**\n * Special marker for schema references (not serialized as strings).\n */\nclass SchemaRef {\n constructor(public readonly name: string) {}\n}\n\n/**\n * Apply transformations with schema imports as references.\n */\nfunction applyTransformsWithImports(\n schema: Record<string, unknown>,\n features: NonNullable<GenerateOptions['features']>,\n exclude: Set<string>,\n importedSchemaNames: string[],\n): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(schema)) {\n // Skip excluded properties\n if (exclude.has(key)) {\n continue;\n }\n\n if (key === '$xmlns') {\n // $xmlns is already parsed - keep only if feature enabled\n if (features.$xmlns) {\n result[key] = value;\n }\n } else if (key === 'import') {\n // Convert import to $imports with schema references\n if (features.$imports && importedSchemaNames.length > 0) {\n result['$imports'] = importedSchemaNames.map(\n (name) => new SchemaRef(name),\n );\n }\n // If no imports resolved, skip the import property entirely\n } else {\n // Recursively filter nested objects/arrays for exclude\n result[key] = filterDeep(value, exclude);\n }\n }\n\n return result;\n}\n\n/**\n * Recursively filter excluded properties from nested structures.\n */\nfunction filterDeep(value: unknown, exclude: Set<string>): unknown {\n if (Array.isArray(value)) {\n return value.map((item) => filterDeep(item, exclude));\n }\n\n if (value !== null && typeof value === 'object') {\n const result: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(value)) {\n if (!exclude.has(k)) {\n result[k] = filterDeep(v, exclude);\n }\n }\n return result;\n }\n\n return value;\n}\n\n/**\n * Generate a complete TypeScript file from XSD content.\n *\n * @param xsdContent - XSD file content as string\n * @param options - Generation options\n * @returns Complete TypeScript file content\n */\nexport function generateSchemaFile(\n xsdContent: string,\n options: GenerateOptions = {},\n): string {\n const {\n name = 'schema',\n comment,\n features = {},\n importResolver,\n isolatedDeclarations = false,\n } = options;\n\n // Parse to extract imports\n const schema = parseXsd(xsdContent);\n const xsdImports = (schema.import ?? []) as Array<{\n schemaLocation?: string;\n namespace?: string;\n }>;\n\n // Generate TypeScript import statements if $imports feature enabled\n const tsImports: string[] = [];\n const importedSchemaNames: string[] = [];\n\n // Add Schema type import for isolatedDeclarations mode\n if (isolatedDeclarations) {\n tsImports.push(\"import type { Schema } from '@abapify/ts-xsd';\");\n }\n\n if (features.$imports && importResolver) {\n for (const imp of xsdImports) {\n if (imp.schemaLocation) {\n const modulePath = importResolver(imp.schemaLocation);\n if (modulePath) {\n // Derive schema name from schemaLocation basename (e.g., \"../sap/adtcore.xsd\" → \"adtcore\")\n const schemaName = imp.schemaLocation\n .replace(/\\.xsd$/, '')\n .replace(/^.*\\//, '');\n tsImports.push(`import ${schemaName} from '${modulePath}';`);\n importedSchemaNames.push(schemaName);\n }\n }\n }\n }\n\n const lines: string[] = [\n '/**',\n ' * Auto-generated schema literal from XSD',\n ' * ',\n ' * DO NOT EDIT - Generated by ts-xsd codegen',\n comment ? ` * ${comment}` : null,\n ' */',\n '',\n // Add TypeScript imports\n ...tsImports,\n tsImports.length > 0 ? '' : null,\n // Generate schema with $imports as array of schema references\n generateSchemaLiteralWithImports(xsdContent, options, importedSchemaNames),\n '',\n `export type ${pascalCase(name)}Type = typeof ${name};`,\n '',\n ].filter((line): line is string => line !== null);\n\n return lines.join('\\n');\n}\n\n/**\n * Generate schema literal with $imports as schema references.\n */\nfunction generateSchemaLiteralWithImports(\n xsdContent: string,\n options: GenerateOptions,\n importedSchemaNames: string[],\n): string {\n const schema = parseXsd(xsdContent);\n const features = options.features ?? {};\n const exclude = new Set(options.exclude ?? []);\n\n // Transform schema\n let outputSchema: Record<string, unknown> = { ...schema };\n\n // Add $filename when enabled (uses name option)\n if (features.$filename && options.name) {\n outputSchema = { $filename: `${options.name}.xsd`, ...outputSchema };\n }\n\n // Apply transformations (features + exclude), passing imported schema names\n outputSchema = applyTransformsWithImports(\n outputSchema,\n features,\n exclude,\n importedSchemaNames,\n );\n\n return schemaToLiteral(outputSchema as Schema, options);\n}\n\n/**\n * Escape reserved words by adding underscore suffix.\n */\nfunction escapeReservedWord(name: string): string {\n return RESERVED_WORDS.has(name) ? `${name}_` : name;\n}\n\n/**\n * Convert a Schema object to a TypeScript literal string.\n */\nfunction schemaToLiteral(\n schema: Schema,\n options: GenerateOptions = {},\n): string {\n const {\n name = 'schema',\n pretty = true,\n indent = ' ',\n isolatedDeclarations = false,\n singleQuote = false,\n } = options;\n\n const safeName = escapeReservedWord(name);\n const literal = objectToLiteral(schema, pretty, indent, 0, singleQuote);\n\n // For isolatedDeclarations compatibility, use `satisfies Schema as const`\n // This makes the type explicit so TypeScript can emit declarations\n const typeAssertion = isolatedDeclarations\n ? 'satisfies Schema as const'\n : 'as const';\n\n return `export const ${safeName} = ${literal} ${typeAssertion};`;\n}\n\n/**\n * Format a string value as a single-quoted literal, unescaping JSON double quotes\n * and escaping any single quotes.\n */\nfunction toSingleQuoteLiteral(jsonStr: string): string {\n const inner = jsonStr\n .slice(1, -1)\n .replaceAll('\\\\\"', '\"')\n .replaceAll(\"'\", \"\\\\'\");\n return `'${inner}'`;\n}\n\n/**\n * Convert any value to a TypeScript literal string.\n */\nfunction objectToLiteral(\n value: unknown,\n pretty: boolean,\n indent: string,\n depth: number,\n singleQuote = false,\n): string {\n if (value === null || value === undefined) {\n return 'undefined';\n }\n\n // Handle SchemaRef - output as bare identifier (not quoted)\n if (value instanceof SchemaRef) {\n return value.name;\n }\n\n if (typeof value === 'string') {\n const json = JSON.stringify(value);\n if (singleQuote) {\n return toSingleQuoteLiteral(json);\n }\n return json;\n }\n\n if (typeof value === 'number' || typeof value === 'boolean') {\n return String(value);\n }\n\n if (Array.isArray(value)) {\n if (value.length === 0) {\n return '[]';\n }\n\n const items = value.map((item) =>\n objectToLiteral(item, pretty, indent, depth + 1, singleQuote),\n );\n\n if (pretty) {\n const itemIndent = indent.repeat(depth + 1);\n const closeIndent = indent.repeat(depth);\n return `[\\n${items\n .map((item) => `${itemIndent}${item}`)\n .join(',\\n')},\\n${closeIndent}]`;\n }\n\n return `[${items.join(', ')}]`;\n }\n\n if (typeof value === 'object') {\n const obj = value as Record<string, unknown>;\n const entries = Object.entries(obj).filter(([, v]) => v !== undefined);\n\n if (entries.length === 0) {\n return '{}';\n }\n\n const props = entries.map(([key, val]) => {\n let keyStr = key;\n if (!isValidIdentifier(key)) {\n const json = JSON.stringify(key);\n keyStr = singleQuote ? toSingleQuoteLiteral(json) : json;\n }\n const valStr = objectToLiteral(\n val,\n pretty,\n indent,\n depth + 1,\n singleQuote,\n );\n return `${keyStr}: ${valStr}`;\n });\n\n if (pretty) {\n const propIndent = indent.repeat(depth + 1);\n const closeIndent = indent.repeat(depth);\n return `{\\n${props\n .map((prop) => `${propIndent}${prop}`)\n .join(',\\n')},\\n${closeIndent}}`;\n }\n\n return `{ ${props.join(', ')} }`;\n }\n\n return 'undefined';\n}\n\n/**\n * JavaScript reserved words that cannot be used as variable names.\n */\nconst RESERVED_WORDS = new Set([\n 'break',\n 'case',\n 'catch',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'else',\n 'finally',\n 'for',\n 'function',\n 'if',\n 'in',\n 'instanceof',\n 'new',\n 'return',\n 'switch',\n 'this',\n 'throw',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'while',\n 'with',\n 'class',\n 'const',\n 'enum',\n 'export',\n 'extends',\n 'import',\n 'super',\n 'implements',\n 'interface',\n 'let',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'static',\n 'yield',\n 'await',\n 'null',\n 'true',\n 'false',\n]);\n\n/**\n * Check if a string is a valid JavaScript identifier.\n */\nfunction isValidIdentifier(str: string): boolean {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(str) && !RESERVED_WORDS.has(str);\n}\n\n/**\n * Convert string to PascalCase.\n */\nfunction pascalCase(str: string): string {\n return str\n .replaceAll(/[-_\\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''))\n .replace(/^./, (s) => s.toUpperCase());\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyEA,SAAgB,sBACd,YACA,UAA2B,CAAC,GACpB;CACR,MAAM,SAAS,SAAS,UAAU;CAClC,MAAM,WAAW,QAAQ,YAAY,CAAC;CACtC,MAAM,UAAU,IAAI,IAAI,QAAQ,WAAW,CAAC,CAAC;CAG7C,IAAI,eAAwC,EAAE,GAAG,OAAO;CAGxD,IAAI,SAAS,aAAa,QAAQ,MAChC,eAAe;EAAE,WAAW,GAAG,QAAQ,KAAK;EAAO,GAAG;CAAa;CAIrE,eAAe,gBAAgB,cAAc,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GAAG;IAC3B,MAAM,OAAO,KAAK,UAAU,GAAG;IAC/B,SAAS,cAAc,qBAAqB,IAAI,IAAI;GACtD;GACA,MAAM,SAAS,gBACb,KACA,QACA,QACA,QAAQ,GACR,WACF;GACA,OAAO,GAAG,OAAO,IAAI;EACvB,CAAC;EAED,IAAI,QAAQ;GACV,MAAM,aAAa,OAAO,OAAO,QAAQ,CAAC;GAC1C,MAAM,cAAc,OAAO,OAAO,KAAK;GACvC,OAAO,MAAM,MACV,KAAK,SAAS,GAAG,aAAa,MAAM,CAAC,CACrC,KAAK,KAAK,EAAE,KAAK,YAAY;EAClC;EAEA,OAAO,KAAK,MAAM,KAAK,IAAI,EAAE;CAC/B;CAEA,OAAO;AACT;;;;AAKA,MAAM,iCAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;AAKD,SAAS,kBAAkB,KAAsB;CAC/C,OAAO,6BAA6B,KAAK,GAAG,KAAK,CAAC,eAAe,IAAI,GAAG;AAC1E;;;;AAKA,SAAS,WAAW,KAAqB;CACvC,OAAO,IACJ,WAAW,iBAAiB,GAAG,MAAO,IAAI,EAAE,YAAY,IAAI,EAAG,CAAC,CAChE,QAAQ,OAAO,MAAM,EAAE,YAAY,CAAC;AACzC"}
@@ -0,0 +1,197 @@
1
+ import { _ as TransformContext, c as CodegenConfig, d as GeneratorPlugin, f as HookContext, g as SourceInfo, h as SourceConfig, i as ResolveOptions, l as FinalizeContext, m as SetupContext, n as RunnerResult, p as SchemaInfo, r as runCodegen, s as AfterAllContext, t as RunnerOptions, u as GeneratedFile, v as defineConfig } from "../runner-D1RCU_go.mjs";
2
+ //#region src/generators/raw-schema.d.ts
3
+ interface RawSchemaOptions {
4
+ /** Use default export (default: true) */
5
+ defaultExport?: boolean;
6
+ /** Use named export with this name (alternative to default export) */
7
+ namedExport?: string;
8
+ /** Include $xmlns in output (default: true) */
9
+ $xmlns?: boolean;
10
+ /** Include $imports in output for xs:import (default: true) */
11
+ $imports?: boolean;
12
+ /** Include $includes in output for xs:include (default: true) */
13
+ $includes?: boolean;
14
+ /** Include $filename in output (default: false) */
15
+ $filename?: boolean;
16
+ /** Properties to exclude from output */
17
+ exclude?: string[];
18
+ /** Add file header comment */
19
+ header?: boolean;
20
+ /**
21
+ * Resolve schema - merge imports, expand extensions and substitution groups.
22
+ * When enabled, produces a self-contained schema with no $imports dependencies.
23
+ * Can be boolean (true = all options) or ResolveOptions for fine control.
24
+ */
25
+ resolve?: boolean | ResolveOptions;
26
+ /**
27
+ * Resolve includes - merge included schema content directly into the main schema.
28
+ * When enabled, xs:include content is merged recursively and no $includes or include
29
+ * properties appear in the output. The schema becomes self-contained.
30
+ */
31
+ resolveIncludes?: boolean;
32
+ /**
33
+ * Resolve ALL dependencies - merge both $includes AND $imports into a single schema.
34
+ * Creates a fully self-contained schema with all elements and types from the entire
35
+ * dependency tree. Useful for generating a schema that can parse the complete XML
36
+ * document structure (e.g., abapGit root element + asx:abap + values).
37
+ *
38
+ * When enabled, no $includes, $imports, include, or import properties appear in output.
39
+ */
40
+ resolveAll?: boolean;
41
+ /**
42
+ * Generate isolatedDeclarations-compatible output.
43
+ * Uses `satisfies Schema as const` instead of just `as const`.
44
+ * Also adds `import type { Schema } from '@abapify/ts-xsd';`
45
+ */
46
+ isolatedDeclarations?: boolean;
47
+ /** Use single quotes for string literals and property names */
48
+ singleQuote?: boolean;
49
+ }
50
+ /**
51
+ * Create a raw schema generator plugin
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { rawSchema } from '@abapify/ts-xsd/generators';
56
+ *
57
+ * export default defineConfig({
58
+ * generators: [
59
+ * rawSchema(), // default export
60
+ * rawSchema({ namedExport: 'mySchema' }), // named export
61
+ * ],
62
+ * });
63
+ * ```
64
+ */
65
+ declare function rawSchema(options?: RawSchemaOptions): GeneratorPlugin;
66
+ //#endregion
67
+ //#region src/generators/inferred-types.d.ts
68
+ interface InferredTypesOptions {
69
+ /** Import path for InferSchema (default: 'ts-xsd') */
70
+ inferSchemaImport?: string;
71
+ /** Type name pattern. Use {Name} for PascalCase schema name (default: '{Name}') */
72
+ typeNamePattern?: string;
73
+ /** Schema variable name to infer from (default: 'schema' for default export) */
74
+ schemaVariable?: string;
75
+ }
76
+ /**
77
+ * Create an inferred types generator plugin
78
+ *
79
+ * This generator should be used AFTER rawSchema() in the pipeline.
80
+ * It modifies the generated schema file to add type exports.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { rawSchema, inferredTypes } from '@abapify/ts-xsd/generators';
85
+ *
86
+ * export default defineConfig({
87
+ * generators: [
88
+ * rawSchema(),
89
+ * inferredTypes(), // Adds: export type Intf = InferSchema<typeof schema>;
90
+ * ],
91
+ * });
92
+ * ```
93
+ */
94
+ declare function inferredTypes(options?: InferredTypesOptions): GeneratorPlugin;
95
+ //#endregion
96
+ //#region src/generators/interfaces.d.ts
97
+ interface InterfacesOptions {
98
+ /** Output file name pattern. Use {name} for schema name, {source} for source name */
99
+ filePattern?: string;
100
+ /** Add file header comment */
101
+ header?: boolean;
102
+ /**
103
+ * If true, generates a single flattened type with all nested types inlined.
104
+ * If false (default), generates interfaces with imports and extends.
105
+ */
106
+ flatten?: boolean;
107
+ /** Custom root type name pattern. Use {name} for schema name (default: '{Name}Schema') */
108
+ rootTypePattern?: string;
109
+ /** Add JSDoc comments to generated types */
110
+ addJsDoc?: boolean;
111
+ }
112
+ /**
113
+ * Create an interfaces generator plugin
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * import { interfaces } from '@abapify/ts-xsd/generators';
118
+ *
119
+ * export default defineConfig({
120
+ * generators: [
121
+ * interfaces(), // interfaces with imports
122
+ * interfaces({ flatten: true }), // fully flattened types
123
+ * ],
124
+ * });
125
+ * ```
126
+ */
127
+ declare function interfaces(options?: InterfacesOptions): GeneratorPlugin;
128
+ //#endregion
129
+ //#region src/generators/index-barrel.d.ts
130
+ interface IndexBarrelOptions {
131
+ /** File name for the barrel (default: 'index.ts') */
132
+ filename?: string;
133
+ /** Use named re-exports instead of star exports */
134
+ namedExports?: boolean;
135
+ /** Export types from .typed.ts files if they exist */
136
+ includeTypedExports?: boolean;
137
+ /** Add file header comment */
138
+ header?: boolean;
139
+ /** Import extension to use: '.ts' for Node.js native, '' for bundlers (default: '' for bundler compatibility) */
140
+ importExtension?: '.ts' | '';
141
+ }
142
+ /**
143
+ * Create an index barrel generator plugin
144
+ *
145
+ * This generator runs in finalize() after all schemas are processed.
146
+ * It generates an index.ts that re-exports all schemas.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * import { rawSchema, indexBarrel } from '@abapify/ts-xsd/generators';
151
+ *
152
+ * export default defineConfig({
153
+ * generators: [
154
+ * rawSchema(),
155
+ * indexBarrel(), // Generates index.ts with all exports
156
+ * ],
157
+ * });
158
+ * ```
159
+ */
160
+ declare function indexBarrel(options?: IndexBarrelOptions): GeneratorPlugin;
161
+ //#endregion
162
+ //#region src/generators/typed-schemas.d.ts
163
+ interface TypedSchemasOptions {
164
+ /** Output file path relative to package root (default: 'src/schemas/generated/index.ts') */
165
+ outputPath?: string;
166
+ /** Path to ts-xsd module from output file (default: 'ts-xsd') */
167
+ tsXsdPath?: string;
168
+ /** Path prefix to schemas from output file (default: './schemas') */
169
+ schemasPath?: string;
170
+ /** Path prefix to types from output file (default: './types') */
171
+ typesPath?: string;
172
+ /** Add file header comment */
173
+ header?: boolean;
174
+ }
175
+ /**
176
+ * Create a typed schemas generator plugin
177
+ *
178
+ * This generator runs in finalize() after all schemas are processed.
179
+ * It generates a single index file that exports typed schema wrappers.
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * import { rawSchema, interfaces, typedSchemas } from '@abapify/ts-xsd/generators';
184
+ *
185
+ * export default defineConfig({
186
+ * generators: [
187
+ * rawSchema(),
188
+ * interfaces(),
189
+ * typedSchemas(), // Generates typed wrappers
190
+ * ],
191
+ * });
192
+ * ```
193
+ */
194
+ declare function typedSchemas(options?: TypedSchemasOptions): GeneratorPlugin;
195
+ //#endregion
196
+ export { type AfterAllContext, type CodegenConfig, type FinalizeContext, type GeneratedFile, type GeneratorPlugin, type HookContext, type IndexBarrelOptions, type InferredTypesOptions, type InterfacesOptions, type RawSchemaOptions, type RunnerOptions, type RunnerResult, type SchemaInfo, type SetupContext, type SourceConfig, type SourceInfo, type TransformContext, type TypedSchemasOptions, defineConfig, indexBarrel, inferredTypes, interfaces, rawSchema, runCodegen, typedSchemas };
197
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/generators/raw-schema.ts","../../src/generators/inferred-types.ts","../../src/generators/interfaces.ts","../../src/generators/index-barrel.ts","../../src/generators/typed-schemas.ts"],"mappings":";;UAmBiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;EAMA,oBAAoB;;;;;;EAMpB;;;;;;;;;EASA;;;;;;EAMA;;EAEA;;;;;;;;;;;;;;;;;iBAsBc,UAAU,UAAS,mBAAwB;;;UCnE1C;;EAEf;;EAEA;;EAEA;;;;;;;;;;;;;;;;;;;;iBAyBc,cACd,UAAS,uBACR;;;UC7Bc;;EAEf;;EAEA;;;;;EAKA;;EAEA;;EAEA;;;;;;;;;;;;;;;;;iBAwCc,WAAW,UAAS,oBAAyB;;;UC1D5C;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;;;;;;;;iBAyBc,YAAY,UAAS,qBAA0B;;;UCvB9C;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;;;;;;;;;;;;iBA0Bc,aACd,UAAS,sBACR"}