langium-zod 0.3.6 → 0.5.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.
- package/README.md +40 -0
- package/dist/api.d.ts +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +55 -5
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts +23 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +298 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/conformance.d.ts +17 -0
- package/dist/conformance.d.ts.map +1 -0
- package/dist/conformance.js +100 -0
- package/dist/conformance.js.map +1 -0
- package/dist/di.d.ts.map +1 -1
- package/dist/di.js +2 -1
- package/dist/di.js.map +1 -1
- package/dist/extractor.d.ts.map +1 -1
- package/dist/extractor.js +17 -1
- package/dist/extractor.js.map +1 -1
- package/dist/generator.d.ts +7 -1
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +117 -21
- package/dist/generator.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/projection.d.ts +20 -0
- package/dist/projection.d.ts.map +1 -0
- package/dist/projection.js +104 -0
- package/dist/projection.js.map +1 -0
- package/dist/ref-utils.d.ts +3 -0
- package/dist/ref-utils.d.ts.map +1 -0
- package/dist/ref-utils.js +14 -0
- package/dist/ref-utils.js.map +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -1
package/README.md
CHANGED
|
@@ -16,6 +16,46 @@ import { generateZodSchemas } from 'langium-zod';
|
|
|
16
16
|
const source = generateZodSchemas({ grammar, services });
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
### Programmatic options
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
generateZodSchemas({
|
|
23
|
+
grammar,
|
|
24
|
+
outputPath: 'src/generated/zod-schemas.ts',
|
|
25
|
+
include: ['Greeting', 'Tag'],
|
|
26
|
+
exclude: ['InternalNode'],
|
|
27
|
+
stripInternals: true,
|
|
28
|
+
projection: {
|
|
29
|
+
defaults: { strip: ['$container', '$document'] },
|
|
30
|
+
types: {
|
|
31
|
+
Greeting: { fields: ['name', 'tags'] }
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
conformance: {
|
|
35
|
+
astTypesPath: 'src/generated/ast.ts'
|
|
36
|
+
},
|
|
37
|
+
crossRefValidation: true
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### CLI options
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
langium-zod generate \
|
|
45
|
+
--config langium-config.json \
|
|
46
|
+
--out src/generated/zod-schemas.ts \
|
|
47
|
+
--include Greeting,Tag \
|
|
48
|
+
--exclude InternalNode \
|
|
49
|
+
--projection projection.json \
|
|
50
|
+
--strip-internals \
|
|
51
|
+
--conformance \
|
|
52
|
+
--ast-types src/generated/ast.ts \
|
|
53
|
+
--conformance-out src/generated/zod-schemas.conformance.ts \
|
|
54
|
+
--cross-ref-validation
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`zRef` is exported from the package for manual schema customization in runtime-aware validation flows.
|
|
58
|
+
|
|
19
59
|
Generated output uses Zod 4 and exports named schemas like `<TypeName>Schema`.
|
|
20
60
|
|
|
21
61
|
## Requirements
|
package/dist/api.d.ts
CHANGED
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAStD,MAAM,MAAM,wBAAwB,GAAG,kBAAkB,CAAC;AAS1D,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CA8FrE"}
|
package/dist/api.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
3
|
import { collectAst } from 'langium/grammar';
|
|
4
|
+
import { generateConformanceSource, inferConformanceOutputPath } from './conformance.js';
|
|
4
5
|
import { ZodGeneratorError } from './errors.js';
|
|
5
6
|
import { extractTypeDescriptors } from './extractor.js';
|
|
6
7
|
import { generateZodCode } from './generator.js';
|
|
8
|
+
import { applyProjectionToDescriptors, resolveEffectiveStripFields } from './projection.js';
|
|
7
9
|
import { detectRecursiveTypes } from './recursion-detector.js';
|
|
8
10
|
function resolveAstTypes(astTypes) {
|
|
9
11
|
return {
|
|
@@ -25,10 +27,7 @@ export function generateZodSchemas(config) {
|
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
const astTypes = resolveAstTypes(rawAstTypes);
|
|
28
|
-
const rawDescriptors =
|
|
29
|
-
include: config.include,
|
|
30
|
-
exclude: config.exclude
|
|
31
|
-
});
|
|
30
|
+
const rawDescriptors = buildDescriptorPipeline(astTypes, config);
|
|
32
31
|
// Apply regexOverrides: upgrade primitive-alias schemas to regex-enum for types
|
|
33
32
|
// whose Langium grammar rule is too complex for automatic regex derivation.
|
|
34
33
|
const overrides = config.regexOverrides ?? {};
|
|
@@ -45,11 +44,62 @@ export function generateZodSchemas(config) {
|
|
|
45
44
|
return d;
|
|
46
45
|
});
|
|
47
46
|
const recursiveTypes = detectRecursiveTypes(descriptors);
|
|
48
|
-
const
|
|
47
|
+
const surfaceDescriptors = applyProjectionToDescriptors(descriptors, {
|
|
48
|
+
projection: config.projection,
|
|
49
|
+
stripInternals: config.stripInternals
|
|
50
|
+
});
|
|
51
|
+
const source = generateZodCode(descriptors, recursiveTypes, {
|
|
52
|
+
projection: config.projection,
|
|
53
|
+
stripInternals: config.stripInternals,
|
|
54
|
+
crossRefValidation: config.crossRefValidation
|
|
55
|
+
});
|
|
49
56
|
if (config.outputPath) {
|
|
50
57
|
mkdirSync(dirname(config.outputPath), { recursive: true });
|
|
51
58
|
writeFileSync(config.outputPath, source, 'utf8');
|
|
52
59
|
}
|
|
60
|
+
if (config.conformance) {
|
|
61
|
+
if (!config.outputPath) {
|
|
62
|
+
throw new ZodGeneratorError('Conformance generation requires outputPath', {
|
|
63
|
+
suggestion: 'Provide outputPath when conformance generation is enabled'
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (!config.conformance.astTypesPath) {
|
|
67
|
+
throw new ZodGeneratorError('Conformance generation requires astTypesPath', {
|
|
68
|
+
suggestion: 'Provide conformance.astTypesPath or use CLI --ast-types/auto-resolution'
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const schemaTypeNames = surfaceDescriptors
|
|
72
|
+
.filter((descriptor) => descriptor.kind === 'object')
|
|
73
|
+
.map((descriptor) => descriptor.name);
|
|
74
|
+
if (schemaTypeNames.length === 0) {
|
|
75
|
+
console.warn('Warning: Conformance generation skipped because no schemas remain after filtering.');
|
|
76
|
+
return source;
|
|
77
|
+
}
|
|
78
|
+
const conformanceOutputPath = inferConformanceOutputPath(config.outputPath, config.conformance.outputPath);
|
|
79
|
+
const conformance = generateConformanceSource({
|
|
80
|
+
schemaOutputPath: config.outputPath,
|
|
81
|
+
conformanceOutputPath,
|
|
82
|
+
astTypesPath: config.conformance.astTypesPath,
|
|
83
|
+
schemaTypeNames,
|
|
84
|
+
stripFields: resolveEffectiveStripFields({
|
|
85
|
+
projection: config.projection,
|
|
86
|
+
stripInternals: config.stripInternals
|
|
87
|
+
}),
|
|
88
|
+
projection: config.projection
|
|
89
|
+
});
|
|
90
|
+
for (const missingType of conformance.missingAstTypes) {
|
|
91
|
+
console.warn(`Warning: Missing AST export for conformance type ${missingType}; skipping.`);
|
|
92
|
+
}
|
|
93
|
+
mkdirSync(dirname(conformanceOutputPath), { recursive: true });
|
|
94
|
+
writeFileSync(conformanceOutputPath, conformance.source, 'utf8');
|
|
95
|
+
}
|
|
53
96
|
return source;
|
|
54
97
|
}
|
|
98
|
+
function buildDescriptorPipeline(astTypes, config) {
|
|
99
|
+
const descriptors = extractTypeDescriptors(astTypes, {
|
|
100
|
+
include: config.include,
|
|
101
|
+
exclude: config.exclude
|
|
102
|
+
});
|
|
103
|
+
return descriptors;
|
|
104
|
+
}
|
|
55
105
|
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,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QAAQ,EAAE;QACpD,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,OAAO,EAAE,MAAM,CAAC,OAAO;KACvB,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACpB,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import type { ZodGeneratorConfig } from './config.js';
|
|
3
|
+
/** User-facing config file shape (langium-zod.config.js / .ts) */
|
|
4
|
+
export interface LangiumZodConfig extends Omit<ZodGeneratorConfig, 'grammar' | 'services' | 'astTypes'> {
|
|
5
|
+
/**
|
|
6
|
+
* Path to `langium-config.json`. Defaults to `langium-config.json` in cwd.
|
|
7
|
+
* Only used when picked up via the CLI; programmatic API ignores it.
|
|
8
|
+
*/
|
|
9
|
+
langiumConfig?: string;
|
|
10
|
+
/** Explicit output path. Overrides derived path from langium-config.json `out` field. */
|
|
11
|
+
outputPath?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function resolveFilterOverrides(base: Pick<LangiumZodConfig, 'include' | 'exclude'>, includeArg?: string, excludeArg?: string): Pick<LangiumZodConfig, 'include' | 'exclude'>;
|
|
14
|
+
export declare function getUnknownFilterNames(requested: string[] | undefined, availableTypeNames: string[]): string[];
|
|
15
|
+
export interface GenerateOptions {
|
|
16
|
+
/** Absolute path to langium-config.json */
|
|
17
|
+
langiumConfigPath: string;
|
|
18
|
+
/** Merged generator config (from user's langium-zod.config.js + CLI flags) */
|
|
19
|
+
config?: LangiumZodConfig;
|
|
20
|
+
}
|
|
21
|
+
export declare function generate(opts: GenerateOptions): Promise<void>;
|
|
22
|
+
export declare function main(): Promise<void>;
|
|
23
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAgBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAQtD,kEAAkE;AAClE,MAAM,WAAW,gBAChB,SAAQ,IAAI,CAAC,kBAAkB,EAAE,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;IACrE;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yFAAyF;IACzF,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAuCD,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,SAAS,CAAC,EACnD,UAAU,CAAC,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GACjB,IAAI,CAAC,gBAAgB,EAAE,SAAS,GAAG,SAAS,CAAC,CAc/C;AAoBD,wBAAgB,qBAAqB,CACpC,SAAS,EAAE,MAAM,EAAE,GAAG,SAAS,EAC/B,kBAAkB,EAAE,MAAM,EAAE,GAC1B,MAAM,EAAE,CAOV;AAyED,MAAM,WAAW,eAAe;IAC/B,2CAA2C;IAC3C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,8EAA8E;IAC9E,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC1B;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CA0FnE;AAMD,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAmG1C"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* langium-zod CLI
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* langium-zod generate [--config langium-config.json] [--out src/generated/zod-schemas.ts]
|
|
7
|
+
* langium-zod --help
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
10
|
+
import { dirname, join, resolve } from 'node:path';
|
|
11
|
+
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import { URI } from 'langium';
|
|
13
|
+
import { createLangiumGrammarServices, resolveImportUri } from 'langium/grammar';
|
|
14
|
+
import { NodeFileSystem } from 'langium/node';
|
|
15
|
+
import { generateZodSchemas } from './api.js';
|
|
16
|
+
import { resolveAstTypesPath } from './conformance.js';
|
|
17
|
+
import { loadProjectionConfig } from './projection.js';
|
|
18
|
+
function parseCsvList(value) {
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
const parsed = [];
|
|
21
|
+
for (const entry of value.split(',')) {
|
|
22
|
+
const normalized = entry.trim();
|
|
23
|
+
if (!normalized || seen.has(normalized)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
seen.add(normalized);
|
|
27
|
+
parsed.push(normalized);
|
|
28
|
+
}
|
|
29
|
+
return parsed;
|
|
30
|
+
}
|
|
31
|
+
function getArgValue(args, flag) {
|
|
32
|
+
const idx = args.indexOf(flag);
|
|
33
|
+
if (idx < 0) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
const value = args[idx + 1];
|
|
37
|
+
if (value == null || value.startsWith('--')) {
|
|
38
|
+
throw new Error(`Missing value for ${flag}`);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
export function resolveFilterOverrides(base, includeArg, excludeArg) {
|
|
43
|
+
const includeFromCli = includeArg === undefined ? undefined : parseCsvList(includeArg);
|
|
44
|
+
const excludeFromCli = excludeArg === undefined ? undefined : parseCsvList(excludeArg);
|
|
45
|
+
const includeSource = includeFromCli ?? base.include ?? [];
|
|
46
|
+
const excludeSource = excludeFromCli ?? base.exclude ?? [];
|
|
47
|
+
const excludeSet = new Set(excludeSource);
|
|
48
|
+
const include = includeSource.filter((name) => !excludeSet.has(name));
|
|
49
|
+
return {
|
|
50
|
+
include,
|
|
51
|
+
exclude: excludeSource
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function warnUnknownFilterNames(filterName, requested, availableTypeNames) {
|
|
55
|
+
const unknown = getUnknownFilterNames(requested, availableTypeNames);
|
|
56
|
+
if (unknown.length === 0) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const availableList = availableTypeNames.length > 0
|
|
60
|
+
? availableTypeNames.join(', ')
|
|
61
|
+
: '(none)';
|
|
62
|
+
console.warn(`Warning: Unknown ${filterName} type name(s): ${unknown.join(', ')}. Available types: ${availableList}`);
|
|
63
|
+
}
|
|
64
|
+
export function getUnknownFilterNames(requested, availableTypeNames) {
|
|
65
|
+
if (!requested || requested.length === 0) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
const available = new Set(availableTypeNames);
|
|
69
|
+
return requested.filter((name) => !available.has(name));
|
|
70
|
+
}
|
|
71
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
72
|
+
// Helpers
|
|
73
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
74
|
+
function printHelp() {
|
|
75
|
+
console.log(`
|
|
76
|
+
langium-zod — generate Zod schemas from Langium grammar files
|
|
77
|
+
|
|
78
|
+
USAGE
|
|
79
|
+
langium-zod generate [options]
|
|
80
|
+
|
|
81
|
+
OPTIONS
|
|
82
|
+
--config <path> Path to langium-config.json (default: langium-config.json)
|
|
83
|
+
--out <path> Output file path (default: <out>/zod-schemas.ts)
|
|
84
|
+
--include <csv> Comma-separated type allowlist
|
|
85
|
+
--exclude <csv> Comma-separated type blocklist
|
|
86
|
+
--projection <file> Projection config JSON file
|
|
87
|
+
--strip-internals Strip internal Langium metadata fields
|
|
88
|
+
--conformance Generate conformance artifact
|
|
89
|
+
--ast-types <path> Path to generated AST declarations (ast.ts)
|
|
90
|
+
--conformance-out <path> Output path for conformance artifact
|
|
91
|
+
--cross-ref-validation Emit runtime cross-reference schema factories
|
|
92
|
+
--help Show this help message
|
|
93
|
+
|
|
94
|
+
CONFIGURATION
|
|
95
|
+
Create a langium-zod.config.js (or .mjs) in the same directory as
|
|
96
|
+
langium-config.json to customise generation:
|
|
97
|
+
|
|
98
|
+
// langium-zod.config.js
|
|
99
|
+
export default {
|
|
100
|
+
outputPath: 'src/generated/zod-schemas.ts',
|
|
101
|
+
regexOverrides: {
|
|
102
|
+
BigDecimal: String.raw\`^[+-]?(\\.[0-9]+|[0-9]+\\.[0-9]*)([eE][+-]?[0-9]+)?$\`,
|
|
103
|
+
},
|
|
104
|
+
include: [], // allowlist of type names to include
|
|
105
|
+
exclude: [], // blocklist of type names to exclude
|
|
106
|
+
};
|
|
107
|
+
`);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Recursively load imported grammar files so that DocumentBuilder can link
|
|
111
|
+
* cross-file references correctly (mirrors langium-cli's eagerLoad strategy).
|
|
112
|
+
*/
|
|
113
|
+
async function eagerLoad(document, documents, visited = new Set()) {
|
|
114
|
+
const key = document.uri.toString();
|
|
115
|
+
if (visited.has(key))
|
|
116
|
+
return;
|
|
117
|
+
visited.add(key);
|
|
118
|
+
const grammar = document.parseResult?.value;
|
|
119
|
+
if (!grammar)
|
|
120
|
+
return;
|
|
121
|
+
// Grammar.imports is an array of GrammarImport nodes; resolveImportUri handles the URI
|
|
122
|
+
const imports = grammar.imports ?? [];
|
|
123
|
+
for (const imp of imports) {
|
|
124
|
+
const importUri = resolveImportUri(imp);
|
|
125
|
+
if (importUri) {
|
|
126
|
+
const importedDoc = await documents.getOrCreateDocument(importUri);
|
|
127
|
+
await eagerLoad(importedDoc, documents, visited);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export async function generate(opts) {
|
|
132
|
+
const { langiumConfigPath } = opts;
|
|
133
|
+
const userConfig = opts.config ?? {};
|
|
134
|
+
// ── 1. Load langium-config.json ─────────────────────────────────────────
|
|
135
|
+
if (!existsSync(langiumConfigPath)) {
|
|
136
|
+
throw new Error(`langium-config.json not found: ${langiumConfigPath}`);
|
|
137
|
+
}
|
|
138
|
+
const langiumConfig = JSON.parse(readFileSync(langiumConfigPath, 'utf8'));
|
|
139
|
+
const configDir = dirname(langiumConfigPath);
|
|
140
|
+
const languages = langiumConfig.languages;
|
|
141
|
+
if (!languages || languages.length === 0) {
|
|
142
|
+
throw new Error('No languages defined in langium-config.json');
|
|
143
|
+
}
|
|
144
|
+
const grammarRelPath = languages[0].grammar;
|
|
145
|
+
const grammarAbsPath = resolve(configDir, grammarRelPath);
|
|
146
|
+
if (!existsSync(grammarAbsPath)) {
|
|
147
|
+
throw new Error(`Grammar file not found: ${grammarAbsPath}`);
|
|
148
|
+
}
|
|
149
|
+
// ── 2. Resolve output path ───────────────────────────────────────────────
|
|
150
|
+
const outDir = langiumConfig.out
|
|
151
|
+
? resolve(configDir, langiumConfig.out)
|
|
152
|
+
: resolve(configDir, 'src/generated');
|
|
153
|
+
const outputPath = userConfig.outputPath ?? join(outDir, 'zod-schemas.ts');
|
|
154
|
+
const conformanceConfig = userConfig.conformance;
|
|
155
|
+
if (conformanceConfig) {
|
|
156
|
+
const resolvedAstTypesPath = conformanceConfig.astTypesPath
|
|
157
|
+
? resolve(configDir, conformanceConfig.astTypesPath)
|
|
158
|
+
: langiumConfig.astTypes
|
|
159
|
+
? resolve(configDir, langiumConfig.astTypes)
|
|
160
|
+
: resolveAstTypesPath(configDir, outDir);
|
|
161
|
+
if (!existsSync(resolvedAstTypesPath)) {
|
|
162
|
+
throw new Error(`Unable to resolve ast types path for conformance: ${resolvedAstTypesPath}`);
|
|
163
|
+
}
|
|
164
|
+
userConfig.conformance = {
|
|
165
|
+
astTypesPath: resolvedAstTypesPath,
|
|
166
|
+
outputPath: conformanceConfig.outputPath
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
// ── 3. Parse grammar using Langium services ──────────────────────────────
|
|
170
|
+
const { shared, grammar: grammarServices } = createLangiumGrammarServices(NodeFileSystem);
|
|
171
|
+
void grammarServices; // used only for type-checking if needed later
|
|
172
|
+
const langiumDocuments = shared.workspace.LangiumDocuments;
|
|
173
|
+
const documentBuilder = shared.workspace.DocumentBuilder;
|
|
174
|
+
const grammarUri = URI.file(grammarAbsPath);
|
|
175
|
+
const entryDocument = await langiumDocuments.getOrCreateDocument(grammarUri);
|
|
176
|
+
// Recursively load imported files so references resolve correctly
|
|
177
|
+
await eagerLoad(entryDocument, langiumDocuments);
|
|
178
|
+
// Build (parse + link) all loaded documents
|
|
179
|
+
await documentBuilder.build(langiumDocuments.all.toArray(), {
|
|
180
|
+
validation: false,
|
|
181
|
+
});
|
|
182
|
+
const grammar = entryDocument.parseResult.value;
|
|
183
|
+
const availableTypeNames = [
|
|
184
|
+
...(grammar.interfaces ?? []).map((entry) => entry.name),
|
|
185
|
+
...(grammar.types ?? []).map((entry) => entry.name)
|
|
186
|
+
]
|
|
187
|
+
.filter((name) => typeof name === 'string')
|
|
188
|
+
.sort((left, right) => left.localeCompare(right));
|
|
189
|
+
warnUnknownFilterNames('include', userConfig.include, availableTypeNames);
|
|
190
|
+
warnUnknownFilterNames('exclude', userConfig.exclude, availableTypeNames);
|
|
191
|
+
// ── 4. Generate schemas ──────────────────────────────────────────────────
|
|
192
|
+
const { langiumConfig: _ignored, outputPath: _op, ...restConfig } = userConfig;
|
|
193
|
+
generateZodSchemas({
|
|
194
|
+
grammar,
|
|
195
|
+
outputPath,
|
|
196
|
+
...restConfig,
|
|
197
|
+
});
|
|
198
|
+
console.log(`✓ Generated Zod schemas → ${outputPath}`);
|
|
199
|
+
}
|
|
200
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
201
|
+
// CLI entry point
|
|
202
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
203
|
+
export async function main() {
|
|
204
|
+
const args = process.argv.slice(2);
|
|
205
|
+
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
|
|
206
|
+
printHelp();
|
|
207
|
+
process.exit(0);
|
|
208
|
+
}
|
|
209
|
+
const command = args[0];
|
|
210
|
+
if (command !== 'generate') {
|
|
211
|
+
console.error(`Unknown command: ${command}`);
|
|
212
|
+
printHelp();
|
|
213
|
+
process.exit(1);
|
|
214
|
+
}
|
|
215
|
+
// ── Parse flags ──────────────────────────────────────────────────────────
|
|
216
|
+
const configFlagIdx = args.indexOf('--config');
|
|
217
|
+
const configFlagValue = configFlagIdx >= 0 ? args[configFlagIdx + 1] : undefined;
|
|
218
|
+
const outFlagIdx = args.indexOf('--out');
|
|
219
|
+
const outFlagValue = outFlagIdx >= 0 ? args[outFlagIdx + 1] : undefined;
|
|
220
|
+
const includeFlagValue = getArgValue(args, '--include');
|
|
221
|
+
const excludeFlagValue = getArgValue(args, '--exclude');
|
|
222
|
+
const projectionFlagValue = getArgValue(args, '--projection');
|
|
223
|
+
const astTypesFlagValue = getArgValue(args, '--ast-types');
|
|
224
|
+
const conformanceOutFlagValue = getArgValue(args, '--conformance-out');
|
|
225
|
+
const stripInternalsEnabled = args.includes('--strip-internals');
|
|
226
|
+
const conformanceEnabled = args.includes('--conformance');
|
|
227
|
+
const crossRefValidationEnabled = args.includes('--cross-ref-validation');
|
|
228
|
+
// ── Locate langium-config.json ───────────────────────────────────────────
|
|
229
|
+
const configFileName = configFlagValue ?? 'langium-config.json';
|
|
230
|
+
const langiumConfigPath = resolve(process.cwd(), configFileName);
|
|
231
|
+
// ── Load optional langium-zod.config.js ──────────────────────────────────
|
|
232
|
+
const configDir = dirname(langiumConfigPath);
|
|
233
|
+
let userConfig = {};
|
|
234
|
+
for (const candidate of [
|
|
235
|
+
'langium-zod.config.js',
|
|
236
|
+
'langium-zod.config.mjs',
|
|
237
|
+
]) {
|
|
238
|
+
const candidatePath = join(configDir, candidate);
|
|
239
|
+
if (existsSync(candidatePath)) {
|
|
240
|
+
const mod = await import(pathToFileURL(candidatePath).href);
|
|
241
|
+
userConfig = (mod.default ?? mod);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// CLI --out flag overrides config file outputPath
|
|
246
|
+
if (outFlagValue) {
|
|
247
|
+
userConfig = { ...userConfig, outputPath: resolve(process.cwd(), outFlagValue) };
|
|
248
|
+
}
|
|
249
|
+
const filterOverrides = resolveFilterOverrides(userConfig, includeFlagValue, excludeFlagValue);
|
|
250
|
+
userConfig = {
|
|
251
|
+
...userConfig,
|
|
252
|
+
...filterOverrides
|
|
253
|
+
};
|
|
254
|
+
if (projectionFlagValue) {
|
|
255
|
+
const projectionPath = resolve(process.cwd(), projectionFlagValue);
|
|
256
|
+
userConfig = {
|
|
257
|
+
...userConfig,
|
|
258
|
+
projection: loadProjectionConfig(projectionPath)
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
if (stripInternalsEnabled) {
|
|
262
|
+
userConfig = {
|
|
263
|
+
...userConfig,
|
|
264
|
+
stripInternals: true
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
if (conformanceEnabled) {
|
|
268
|
+
userConfig = {
|
|
269
|
+
...userConfig,
|
|
270
|
+
conformance: {
|
|
271
|
+
astTypesPath: astTypesFlagValue ? resolve(process.cwd(), astTypesFlagValue) : undefined,
|
|
272
|
+
outputPath: conformanceOutFlagValue ? resolve(process.cwd(), conformanceOutFlagValue) : undefined
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
if (crossRefValidationEnabled) {
|
|
277
|
+
userConfig = {
|
|
278
|
+
...userConfig,
|
|
279
|
+
crossRefValidation: true
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
await generate({ langiumConfigPath, config: userConfig });
|
|
284
|
+
}
|
|
285
|
+
catch (err) {
|
|
286
|
+
console.error('Error:', err instanceof Error ? err.message : String(err));
|
|
287
|
+
process.exit(1);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
// Guard against library imports running the CLI
|
|
291
|
+
const isMain = process.argv[1] != null &&
|
|
292
|
+
(process.argv[1].endsWith('/cli.js') ||
|
|
293
|
+
process.argv[1].endsWith('/cli.ts') ||
|
|
294
|
+
process.argv[1].endsWith('langium-zod'));
|
|
295
|
+
if (isMain) {
|
|
296
|
+
void main();
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.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CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;AACF,CAAC;AAED,gDAAgD;AAChD,MAAM,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI;IACvB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;QACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;QACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;AAE3C,IAAI,MAAM,EAAE,CAAC;IACZ,KAAK,IAAI,EAAE,CAAC;AACb,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Grammar, LangiumCoreServices } from 'langium';
|
|
2
2
|
import type { AstTypesLike } from './types.js';
|
|
3
|
+
import type { ProjectionConfig } from './projection.js';
|
|
3
4
|
export interface FilterConfig {
|
|
4
5
|
include?: string[];
|
|
5
6
|
exclude?: string[];
|
|
@@ -9,6 +10,13 @@ export interface ZodGeneratorConfig extends FilterConfig {
|
|
|
9
10
|
services?: LangiumCoreServices;
|
|
10
11
|
outputPath?: string;
|
|
11
12
|
astTypes?: AstTypesLike;
|
|
13
|
+
projection?: ProjectionConfig;
|
|
14
|
+
stripInternals?: boolean;
|
|
15
|
+
crossRefValidation?: boolean;
|
|
16
|
+
conformance?: {
|
|
17
|
+
astTypesPath?: string;
|
|
18
|
+
outputPath?: string;
|
|
19
|
+
};
|
|
12
20
|
/**
|
|
13
21
|
* Override the generated schema for specific type names.
|
|
14
22
|
*
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,WAAW,YAAY;IAC5B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACvD,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,WAAW,CAAC,EAAE;QACb,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF;;;;;;;;;;;;;;;OAeG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AAED,eAAO,MAAM,mBAAmB,iCAAiC,CAAC;AAElE,wBAAgB,qBAAqB,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC,CAKnF"}
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAwCA,MAAM,CAAC,MAAM,mBAAmB,GAAG,8BAA8B,CAAC;AAElE,MAAM,UAAU,qBAAqB,CAAC,MAAqB;IAC1D,OAAO;QACN,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,EAAE;QAC9B,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,EAAE;KAC9B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ProjectionConfig } from './projection.js';
|
|
2
|
+
export interface ConformanceGenerationOptions {
|
|
3
|
+
schemaOutputPath: string;
|
|
4
|
+
conformanceOutputPath?: string;
|
|
5
|
+
astTypesPath: string;
|
|
6
|
+
schemaTypeNames: string[];
|
|
7
|
+
stripFields: string[];
|
|
8
|
+
projection?: ProjectionConfig;
|
|
9
|
+
}
|
|
10
|
+
export declare function inferConformanceOutputPath(schemaOutputPath: string, overridePath?: string): string;
|
|
11
|
+
export declare function collectAstExportNames(astTypesPath: string): Set<string>;
|
|
12
|
+
export declare function generateConformanceSource(options: ConformanceGenerationOptions): {
|
|
13
|
+
source: string;
|
|
14
|
+
missingAstTypes: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare function resolveAstTypesPath(configDir: string, langiumOutDir: string, explicitAstTypesPath?: string): string;
|
|
17
|
+
//# sourceMappingURL=conformance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../src/conformance.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,WAAW,4BAA4B;IAC5C,gBAAgB,EAAE,MAAM,CAAC;IACzB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAuBD,wBAAgB,0BAA0B,CACzC,gBAAgB,EAAE,MAAM,EACxB,YAAY,CAAC,EAAE,MAAM,GACnB,MAAM,CASR;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAevE;AAED,wBAAgB,yBAAyB,CACxC,OAAO,EAAE,4BAA4B,GACnC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,EAAE,CAAA;CAAE,CA2D/C;AAED,wBAAgB,mBAAmB,CAClC,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,oBAAoB,CAAC,EAAE,MAAM,GAC3B,MAAM,CAKR"}
|