@manifesto-ai/codegen 0.1.0 → 0.1.1
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/package.json +1 -1
- package/dist/header.d.ts +0 -13
- package/dist/header.d.ts.map +0 -1
- package/dist/header.js +0 -18
- package/dist/header.js.map +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -14
- package/dist/index.js.map +0 -1
- package/dist/path-safety.d.ts +0 -16
- package/dist/path-safety.d.ts.map +0 -1
- package/dist/path-safety.js +0 -47
- package/dist/path-safety.js.map +0 -1
- package/dist/plugins/index.d.ts +0 -5
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -3
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/ts-plugin.d.ts +0 -11
- package/dist/plugins/ts-plugin.d.ts.map +0 -1
- package/dist/plugins/ts-plugin.js +0 -202
- package/dist/plugins/ts-plugin.js.map +0 -1
- package/dist/plugins/zod-plugin.d.ts +0 -6
- package/dist/plugins/zod-plugin.d.ts.map +0 -1
- package/dist/plugins/zod-plugin.js +0 -138
- package/dist/plugins/zod-plugin.js.map +0 -1
- package/dist/runner.d.ts +0 -13
- package/dist/runner.d.ts.map +0 -1
- package/dist/runner.js +0 -126
- package/dist/runner.js.map +0 -1
- package/dist/stable-hash.d.ts +0 -7
- package/dist/stable-hash.d.ts.map +0 -1
- package/dist/stable-hash.js +0 -11
- package/dist/stable-hash.js.map +0 -1
- package/dist/types.d.ts +0 -50
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/virtual-fs.d.ts +0 -27
- package/dist/virtual-fs.d.ts.map +0 -1
- package/dist/virtual-fs.js +0 -74
- package/dist/virtual-fs.js.map +0 -1
package/package.json
CHANGED
package/dist/header.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface HeaderOptions {
|
|
2
|
-
readonly sourceId?: string;
|
|
3
|
-
readonly schemaHash: string;
|
|
4
|
-
readonly stamp?: boolean;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Generate the @generated file header (DET-2, DET-3, DET-4).
|
|
8
|
-
*
|
|
9
|
-
* Default mode: no timestamp (deterministic).
|
|
10
|
-
* With stamp=true: appends ISO 8601 timestamp line.
|
|
11
|
-
*/
|
|
12
|
-
export declare function generateHeader(options: HeaderOptions): string;
|
|
13
|
-
//# sourceMappingURL=header.d.ts.map
|
package/dist/header.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../src/header.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAY7D"}
|
package/dist/header.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate the @generated file header (DET-2, DET-3, DET-4).
|
|
3
|
-
*
|
|
4
|
-
* Default mode: no timestamp (deterministic).
|
|
5
|
-
* With stamp=true: appends ISO 8601 timestamp line.
|
|
6
|
-
*/
|
|
7
|
-
export function generateHeader(options) {
|
|
8
|
-
const source = options.sourceId ?? "unknown";
|
|
9
|
-
const lines = [
|
|
10
|
-
"// @generated by @manifesto-ai/codegen \u2014 DO NOT EDIT",
|
|
11
|
-
`// Source: ${source} | Schema hash: ${options.schemaHash}`,
|
|
12
|
-
];
|
|
13
|
-
if (options.stamp) {
|
|
14
|
-
lines.push(`// Generated at: ${new Date().toISOString()}`);
|
|
15
|
-
}
|
|
16
|
-
return lines.join("\n") + "\n";
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=header.js.map
|
package/dist/header.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"header.js","sourceRoot":"","sources":["../src/header.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAAsB;IACnD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,IAAI,SAAS,CAAC;IAC7C,MAAM,KAAK,GAAG;QACZ,2DAA2D;QAC3D,cAAc,MAAM,mBAAmB,OAAO,CAAC,UAAU,EAAE;KAC5D,CAAC;IAEF,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,KAAK,CAAC,IAAI,CAAC,oBAAoB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AACjC,CAAC"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type { Diagnostic, FilePatch, CodegenPlugin, CodegenContext, CodegenOutput, CodegenHelpers, GenerateOptions, GenerateResult, } from "./types.js";
|
|
2
|
-
export { generate } from "./runner.js";
|
|
3
|
-
export { createTsPlugin, createZodPlugin } from "./plugins/index.js";
|
|
4
|
-
export type { TsPluginOptions, TsPluginArtifacts, ZodPluginOptions } from "./plugins/index.js";
|
|
5
|
-
export { validatePath } from "./path-safety.js";
|
|
6
|
-
export type { PathValidationResult } from "./path-safety.js";
|
|
7
|
-
export { stableHash } from "./stable-hash.js";
|
|
8
|
-
export { generateHeader } from "./header.js";
|
|
9
|
-
export type { HeaderOptions } from "./header.js";
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,YAAY,EACV,UAAU,EACV,SAAS,EACT,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG/F,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// @manifesto-ai/codegen
|
|
2
|
-
// Plugin-based code generation from DomainSchema
|
|
3
|
-
//
|
|
4
|
-
// See: docs/SPEC-v0.1.1.md for specification
|
|
5
|
-
// See: docs/ADR-CODEGEN-001.md for architecture decisions
|
|
6
|
-
// Runner
|
|
7
|
-
export { generate } from "./runner.js";
|
|
8
|
-
// Plugins
|
|
9
|
-
export { createTsPlugin, createZodPlugin } from "./plugins/index.js";
|
|
10
|
-
// Utilities (for custom plugin authors)
|
|
11
|
-
export { validatePath } from "./path-safety.js";
|
|
12
|
-
export { stableHash } from "./stable-hash.js";
|
|
13
|
-
export { generateHeader } from "./header.js";
|
|
14
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,iDAAiD;AACjD,EAAE;AACF,6CAA6C;AAC7C,0DAA0D;AAc1D,SAAS;AACT,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,UAAU;AACV,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrE,wCAAwC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/path-safety.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type PathValidationResult = {
|
|
2
|
-
valid: true;
|
|
3
|
-
normalized: string;
|
|
4
|
-
} | {
|
|
5
|
-
valid: false;
|
|
6
|
-
reason: string;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Validate and normalize a file path per FP-1, FP-2, GEN-6.
|
|
10
|
-
*
|
|
11
|
-
* - MUST be a POSIX relative path
|
|
12
|
-
* - MUST NOT contain `..`, absolute prefixes, drive letters, or null bytes
|
|
13
|
-
* - Normalizes backslashes, multiple slashes, and leading `./`
|
|
14
|
-
*/
|
|
15
|
-
export declare function validatePath(path: string): PathValidationResult;
|
|
16
|
-
//# sourceMappingURL=path-safety.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"path-safety.d.ts","sourceRoot":"","sources":["../src/path-safety.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAC5B;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAErC;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAgD/D"}
|
package/dist/path-safety.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validate and normalize a file path per FP-1, FP-2, GEN-6.
|
|
3
|
-
*
|
|
4
|
-
* - MUST be a POSIX relative path
|
|
5
|
-
* - MUST NOT contain `..`, absolute prefixes, drive letters, or null bytes
|
|
6
|
-
* - Normalizes backslashes, multiple slashes, and leading `./`
|
|
7
|
-
*/
|
|
8
|
-
export function validatePath(path) {
|
|
9
|
-
if (!path) {
|
|
10
|
-
return { valid: false, reason: "Path must not be empty" };
|
|
11
|
-
}
|
|
12
|
-
if (path.includes("\0")) {
|
|
13
|
-
return { valid: false, reason: "Path must not contain null bytes" };
|
|
14
|
-
}
|
|
15
|
-
// Normalize backslashes to forward slashes (GEN-6)
|
|
16
|
-
let normalized = path.replace(/\\/g, "/");
|
|
17
|
-
// Check for drive letters (e.g., C:/)
|
|
18
|
-
if (/^[a-zA-Z]:/.test(normalized)) {
|
|
19
|
-
return { valid: false, reason: "Path must not contain drive letters" };
|
|
20
|
-
}
|
|
21
|
-
// Check for absolute path
|
|
22
|
-
if (normalized.startsWith("/")) {
|
|
23
|
-
return { valid: false, reason: "Path must be relative, not absolute" };
|
|
24
|
-
}
|
|
25
|
-
// Collapse multiple slashes
|
|
26
|
-
normalized = normalized.replace(/\/+/g, "/");
|
|
27
|
-
// Remove leading ./
|
|
28
|
-
if (normalized.startsWith("./")) {
|
|
29
|
-
normalized = normalized.slice(2);
|
|
30
|
-
}
|
|
31
|
-
// Remove trailing slash
|
|
32
|
-
if (normalized.endsWith("/") && normalized.length > 1) {
|
|
33
|
-
normalized = normalized.slice(0, -1);
|
|
34
|
-
}
|
|
35
|
-
// Check for .. traversal (after normalization)
|
|
36
|
-
const segments = normalized.split("/");
|
|
37
|
-
for (const segment of segments) {
|
|
38
|
-
if (segment === "..") {
|
|
39
|
-
return { valid: false, reason: "Path must not contain '..' traversal" };
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (!normalized) {
|
|
43
|
-
return { valid: false, reason: "Path resolves to empty after normalization" };
|
|
44
|
-
}
|
|
45
|
-
return { valid: true, normalized };
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=path-safety.js.map
|
package/dist/path-safety.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"path-safety.js","sourceRoot":"","sources":["../src/path-safety.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,wBAAwB,EAAE,CAAC;IAC5D,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,kCAAkC,EAAE,CAAC;IACtE,CAAC;IAED,mDAAmD;IACnD,IAAI,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE1C,sCAAsC;IACtC,IAAI,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,qCAAqC,EAAE,CAAC;IACzE,CAAC;IAED,0BAA0B;IAC1B,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,qCAAqC,EAAE,CAAC;IACzE,CAAC;IAED,4BAA4B;IAC5B,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE7C,oBAAoB;IACpB,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IAED,wBAAwB;IACxB,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtD,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,+CAA+C;IAC/C,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,sCAAsC,EAAE,CAAC;QAC1E,CAAC;IACH,CAAC;IAED,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,4CAA4C,EAAE,CAAC;IAChF,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AACrC,CAAC"}
|
package/dist/plugins/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { createTsPlugin } from "./ts-plugin.js";
|
|
2
|
-
export type { TsPluginOptions, TsPluginArtifacts } from "./ts-plugin.js";
|
|
3
|
-
export { createZodPlugin } from "./zod-plugin.js";
|
|
4
|
-
export type { ZodPluginOptions } from "./zod-plugin.js";
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/plugins/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { CodegenPlugin } from "../types.js";
|
|
2
|
-
export interface TsPluginOptions {
|
|
3
|
-
readonly typesFile?: string;
|
|
4
|
-
readonly actionsFile?: string;
|
|
5
|
-
}
|
|
6
|
-
export interface TsPluginArtifacts {
|
|
7
|
-
readonly typeNames: string[];
|
|
8
|
-
readonly typeImportPath: string;
|
|
9
|
-
}
|
|
10
|
-
export declare function createTsPlugin(options?: TsPluginOptions): CodegenPlugin;
|
|
11
|
-
//# sourceMappingURL=ts-plugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ts-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/ts-plugin.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC;AAED,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,aAAa,CAmDvE"}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
const PLUGIN_NAME = "codegen-plugin-ts";
|
|
2
|
-
export function createTsPlugin(options) {
|
|
3
|
-
const typesFile = options?.typesFile ?? "types.ts";
|
|
4
|
-
const actionsFile = options?.actionsFile ?? "actions.ts";
|
|
5
|
-
return {
|
|
6
|
-
name: PLUGIN_NAME,
|
|
7
|
-
generate(ctx) {
|
|
8
|
-
const diagnostics = [];
|
|
9
|
-
const typeNames = [];
|
|
10
|
-
// Generate types from schema.types (GEN-10, TS-6: lexicographic order)
|
|
11
|
-
const sortedTypeNames = Object.keys(ctx.schema.types).sort();
|
|
12
|
-
const typeDecls = [];
|
|
13
|
-
for (const name of sortedTypeNames) {
|
|
14
|
-
const spec = ctx.schema.types[name];
|
|
15
|
-
typeNames.push(name);
|
|
16
|
-
typeDecls.push(renderNamedType(name, spec, diagnostics));
|
|
17
|
-
}
|
|
18
|
-
const typesContent = typeDecls.join("\n\n") + "\n";
|
|
19
|
-
// Generate action input types
|
|
20
|
-
const sortedActionNames = Object.keys(ctx.schema.actions).sort();
|
|
21
|
-
const actionDecls = [];
|
|
22
|
-
for (const actionName of sortedActionNames) {
|
|
23
|
-
const spec = ctx.schema.actions[actionName];
|
|
24
|
-
if (spec.input) {
|
|
25
|
-
const typeName = pascalCase(actionName) + "Input";
|
|
26
|
-
actionDecls.push(renderActionInputType(typeName, spec, diagnostics));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const patches = [
|
|
30
|
-
{ op: "set", path: typesFile, content: typesContent },
|
|
31
|
-
];
|
|
32
|
-
if (actionDecls.length > 0) {
|
|
33
|
-
const actionsContent = actionDecls.join("\n\n") + "\n";
|
|
34
|
-
patches.push({ op: "set", path: actionsFile, content: actionsContent });
|
|
35
|
-
}
|
|
36
|
-
const artifacts = {
|
|
37
|
-
typeNames,
|
|
38
|
-
typeImportPath: `./${typesFile.replace(/\.ts$/, "")}`,
|
|
39
|
-
};
|
|
40
|
-
return { patches, artifacts: artifacts, diagnostics };
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
// --- Type rendering ---
|
|
45
|
-
function renderNamedType(name, spec, diagnostics) {
|
|
46
|
-
const def = spec.definition;
|
|
47
|
-
// TS-3: top-level named object -> export interface
|
|
48
|
-
if (def.kind === "object") {
|
|
49
|
-
return renderInterface(name, def.fields, diagnostics);
|
|
50
|
-
}
|
|
51
|
-
// TS-3: all other named types -> export type
|
|
52
|
-
const tsType = mapTypeDefinition(def, diagnostics);
|
|
53
|
-
return `export type ${name} = ${tsType};`;
|
|
54
|
-
}
|
|
55
|
-
function renderInterface(name, fields, diagnostics) {
|
|
56
|
-
const sortedFields = Object.keys(fields).sort();
|
|
57
|
-
const lines = [];
|
|
58
|
-
for (const fieldName of sortedFields) {
|
|
59
|
-
const field = fields[fieldName];
|
|
60
|
-
const tsType = mapTypeDefinition(field.type, diagnostics);
|
|
61
|
-
// TS-5: optional -> ?
|
|
62
|
-
const opt = field.optional ? "?" : "";
|
|
63
|
-
lines.push(` ${fieldName}${opt}: ${tsType};`);
|
|
64
|
-
}
|
|
65
|
-
return `export interface ${name} {\n${lines.join("\n")}\n}`;
|
|
66
|
-
}
|
|
67
|
-
function mapTypeDefinition(def, diagnostics) {
|
|
68
|
-
switch (def.kind) {
|
|
69
|
-
case "primitive":
|
|
70
|
-
return mapPrimitive(def.type);
|
|
71
|
-
case "literal":
|
|
72
|
-
return renderLiteral(def.value);
|
|
73
|
-
case "array":
|
|
74
|
-
return `${wrapComplex(mapTypeDefinition(def.element, diagnostics), def.element)}[]`;
|
|
75
|
-
case "record":
|
|
76
|
-
return `Record<${mapTypeDefinition(def.key, diagnostics)}, ${mapTypeDefinition(def.value, diagnostics)}>`;
|
|
77
|
-
case "object": {
|
|
78
|
-
const sortedFields = Object.keys(def.fields).sort();
|
|
79
|
-
const parts = [];
|
|
80
|
-
for (const fieldName of sortedFields) {
|
|
81
|
-
const field = def.fields[fieldName];
|
|
82
|
-
const tsType = mapTypeDefinition(field.type, diagnostics);
|
|
83
|
-
const opt = field.optional ? "?" : "";
|
|
84
|
-
parts.push(`${fieldName}${opt}: ${tsType}`);
|
|
85
|
-
}
|
|
86
|
-
return `{ ${parts.join("; ")} }`;
|
|
87
|
-
}
|
|
88
|
-
case "union":
|
|
89
|
-
// TS-2: nullable uses T | null
|
|
90
|
-
return def.types.map((t) => mapTypeDefinition(t, diagnostics)).join(" | ");
|
|
91
|
-
case "ref":
|
|
92
|
-
return def.name;
|
|
93
|
-
default: {
|
|
94
|
-
// PLG-3, TS-1: unknown kind fallback
|
|
95
|
-
diagnostics.push({
|
|
96
|
-
level: "warn",
|
|
97
|
-
plugin: PLUGIN_NAME,
|
|
98
|
-
message: `Unknown TypeDefinition kind: "${def.kind}". Emitting "unknown".`,
|
|
99
|
-
});
|
|
100
|
-
return "unknown";
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function mapPrimitive(type) {
|
|
105
|
-
switch (type) {
|
|
106
|
-
case "string":
|
|
107
|
-
return "string";
|
|
108
|
-
case "number":
|
|
109
|
-
return "number";
|
|
110
|
-
case "boolean":
|
|
111
|
-
return "boolean";
|
|
112
|
-
case "null":
|
|
113
|
-
return "null";
|
|
114
|
-
default:
|
|
115
|
-
return "unknown";
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function renderLiteral(value) {
|
|
119
|
-
if (typeof value === "string") {
|
|
120
|
-
return JSON.stringify(value);
|
|
121
|
-
}
|
|
122
|
-
return String(value);
|
|
123
|
-
}
|
|
124
|
-
/** Wrap union types in parens when used as array element */
|
|
125
|
-
function wrapComplex(tsType, def) {
|
|
126
|
-
if (def.kind === "union") {
|
|
127
|
-
return `(${tsType})`;
|
|
128
|
-
}
|
|
129
|
-
return tsType;
|
|
130
|
-
}
|
|
131
|
-
// --- Action input rendering ---
|
|
132
|
-
function renderActionInputType(typeName, spec, diagnostics) {
|
|
133
|
-
if (!spec.input) {
|
|
134
|
-
return "";
|
|
135
|
-
}
|
|
136
|
-
const tsType = mapFieldSpec(spec.input, diagnostics);
|
|
137
|
-
return `export type ${typeName} = ${tsType};`;
|
|
138
|
-
}
|
|
139
|
-
function mapFieldSpec(spec, diagnostics) {
|
|
140
|
-
const baseType = mapFieldType(spec.type, spec, diagnostics);
|
|
141
|
-
// GEN-12: degrade for unknown structures
|
|
142
|
-
if (!spec.required && baseType !== "unknown") {
|
|
143
|
-
return `${baseType} | null`;
|
|
144
|
-
}
|
|
145
|
-
return baseType;
|
|
146
|
-
}
|
|
147
|
-
function mapFieldType(type, spec, diagnostics) {
|
|
148
|
-
if (typeof type === "object" && "enum" in type) {
|
|
149
|
-
// Enum -> union of literals
|
|
150
|
-
return type.enum.map((v) => renderLiteral(v)).join(" | ");
|
|
151
|
-
}
|
|
152
|
-
switch (type) {
|
|
153
|
-
case "string":
|
|
154
|
-
return "string";
|
|
155
|
-
case "number":
|
|
156
|
-
return "number";
|
|
157
|
-
case "boolean":
|
|
158
|
-
return "boolean";
|
|
159
|
-
case "null":
|
|
160
|
-
return "null";
|
|
161
|
-
case "object": {
|
|
162
|
-
if (spec.fields) {
|
|
163
|
-
const sortedFields = Object.keys(spec.fields).sort();
|
|
164
|
-
const parts = [];
|
|
165
|
-
for (const name of sortedFields) {
|
|
166
|
-
const field = spec.fields[name];
|
|
167
|
-
const fieldType = mapFieldSpec(field, diagnostics);
|
|
168
|
-
const opt = field.required ? "" : "?";
|
|
169
|
-
parts.push(`${name}${opt}: ${fieldType}`);
|
|
170
|
-
}
|
|
171
|
-
return `{ ${parts.join("; ")} }`;
|
|
172
|
-
}
|
|
173
|
-
// GEN-12: unstructured object -> unknown
|
|
174
|
-
diagnostics.push({
|
|
175
|
-
level: "warn",
|
|
176
|
-
plugin: PLUGIN_NAME,
|
|
177
|
-
message: "Object field without fields spec, degrading to Record<string, unknown>",
|
|
178
|
-
});
|
|
179
|
-
return "Record<string, unknown>";
|
|
180
|
-
}
|
|
181
|
-
case "array": {
|
|
182
|
-
if (spec.items) {
|
|
183
|
-
return `${mapFieldSpec(spec.items, diagnostics)}[]`;
|
|
184
|
-
}
|
|
185
|
-
diagnostics.push({
|
|
186
|
-
level: "warn",
|
|
187
|
-
plugin: PLUGIN_NAME,
|
|
188
|
-
message: "Array field without items spec, degrading to unknown[]",
|
|
189
|
-
});
|
|
190
|
-
return "unknown[]";
|
|
191
|
-
}
|
|
192
|
-
default:
|
|
193
|
-
return "unknown";
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function pascalCase(str) {
|
|
197
|
-
return str
|
|
198
|
-
.split(/[-_\s]+/)
|
|
199
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
200
|
-
.join("");
|
|
201
|
-
}
|
|
202
|
-
//# sourceMappingURL=ts-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ts-plugin.js","sourceRoot":"","sources":["../../src/plugins/ts-plugin.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAYxC,MAAM,UAAU,cAAc,CAAC,OAAyB;IACtD,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,UAAU,CAAC;IACnD,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,YAAY,CAAC;IAEzD,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,QAAQ,CAAC,GAAmB;YAC1B,MAAM,WAAW,GAAiB,EAAE,CAAC;YACrC,MAAM,SAAS,GAAa,EAAE,CAAC;YAE/B,uEAAuE;YACvE,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;YAC7D,MAAM,SAAS,GAAa,EAAE,CAAC;YAE/B,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;gBACnC,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACpC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACrB,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;YAC3D,CAAC;YAED,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,M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AC;AAMrB,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,aAAa,CA2CzE"}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
const PLUGIN_NAME = "codegen-plugin-zod";
|
|
2
|
-
const TS_PLUGIN_NAME = "codegen-plugin-ts";
|
|
3
|
-
export function createZodPlugin(options) {
|
|
4
|
-
const schemasFile = options?.schemasFile ?? "base.ts";
|
|
5
|
-
return {
|
|
6
|
-
name: PLUGIN_NAME,
|
|
7
|
-
generate(ctx) {
|
|
8
|
-
const diagnostics = [];
|
|
9
|
-
// PLG-11: Optional TS artifacts dependency
|
|
10
|
-
const tsArtifacts = ctx.artifacts[TS_PLUGIN_NAME];
|
|
11
|
-
const sortedTypeNames = Object.keys(ctx.schema.types).sort();
|
|
12
|
-
const schemaDecls = [];
|
|
13
|
-
// Collect all type names for forward declarations with z.lazy
|
|
14
|
-
const allTypeNames = new Set(sortedTypeNames);
|
|
15
|
-
for (const name of sortedTypeNames) {
|
|
16
|
-
const spec = ctx.schema.types[name];
|
|
17
|
-
schemaDecls.push(renderNamedSchema(name, spec, allTypeNames, tsArtifacts, diagnostics));
|
|
18
|
-
}
|
|
19
|
-
// Build imports
|
|
20
|
-
const imports = ['import { z } from "zod";'];
|
|
21
|
-
// ZOD-4: Import TS types for annotations when available
|
|
22
|
-
if (tsArtifacts && tsArtifacts.typeNames.length > 0) {
|
|
23
|
-
const typeImports = sortedTypeNames
|
|
24
|
-
.filter((n) => tsArtifacts.typeNames.includes(n))
|
|
25
|
-
.join(", ");
|
|
26
|
-
if (typeImports) {
|
|
27
|
-
imports.push(`import type { ${typeImports} } from "${tsArtifacts.typeImportPath}";`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const content = imports.join("\n") + "\n\n" + schemaDecls.join("\n\n") + "\n";
|
|
31
|
-
return {
|
|
32
|
-
patches: [{ op: "set", path: schemasFile, content }],
|
|
33
|
-
diagnostics,
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
// --- Schema rendering ---
|
|
39
|
-
function renderNamedSchema(name, spec, allTypeNames, tsArtifacts, diagnostics) {
|
|
40
|
-
const schemaName = `${name}Schema`;
|
|
41
|
-
const zodExpr = mapTypeDefinition(spec.definition, allTypeNames, diagnostics);
|
|
42
|
-
// ZOD-4/ZOD-5: Type annotation when TS artifacts available
|
|
43
|
-
const hasTypeAnnotation = tsArtifacts && tsArtifacts.typeNames.includes(name);
|
|
44
|
-
const annotation = hasTypeAnnotation ? `: z.ZodType<${name}>` : "";
|
|
45
|
-
return `export const ${schemaName}${annotation} = ${zodExpr};`;
|
|
46
|
-
}
|
|
47
|
-
function mapTypeDefinition(def, allTypeNames, diagnostics) {
|
|
48
|
-
switch (def.kind) {
|
|
49
|
-
case "primitive":
|
|
50
|
-
return mapPrimitiveZod(def.type);
|
|
51
|
-
case "literal":
|
|
52
|
-
return `z.literal(${renderLiteralValue(def.value)})`;
|
|
53
|
-
case "array":
|
|
54
|
-
return `z.array(${mapTypeDefinition(def.element, allTypeNames, diagnostics)})`;
|
|
55
|
-
case "record":
|
|
56
|
-
return handleRecord(def, allTypeNames, diagnostics);
|
|
57
|
-
case "object":
|
|
58
|
-
return renderZodObject(def.fields, allTypeNames, diagnostics);
|
|
59
|
-
case "union":
|
|
60
|
-
return handleUnion(def.types, allTypeNames, diagnostics);
|
|
61
|
-
case "ref":
|
|
62
|
-
// ZOD-2: Always z.lazy for circular reference support
|
|
63
|
-
return `z.lazy(() => ${def.name}Schema)`;
|
|
64
|
-
default: {
|
|
65
|
-
// ZOD-1: Unknown kind fallback
|
|
66
|
-
diagnostics.push({
|
|
67
|
-
level: "warn",
|
|
68
|
-
plugin: PLUGIN_NAME,
|
|
69
|
-
message: `Unknown TypeDefinition kind: "${def.kind}". Emitting "z.unknown()".`,
|
|
70
|
-
});
|
|
71
|
-
return "z.unknown()";
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function mapPrimitiveZod(type) {
|
|
76
|
-
switch (type) {
|
|
77
|
-
case "string":
|
|
78
|
-
return "z.string()";
|
|
79
|
-
case "number":
|
|
80
|
-
return "z.number()";
|
|
81
|
-
case "boolean":
|
|
82
|
-
return "z.boolean()";
|
|
83
|
-
case "null":
|
|
84
|
-
return "z.null()";
|
|
85
|
-
default:
|
|
86
|
-
return "z.unknown()";
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function renderLiteralValue(value) {
|
|
90
|
-
if (typeof value === "string") {
|
|
91
|
-
return JSON.stringify(value);
|
|
92
|
-
}
|
|
93
|
-
if (value === null) {
|
|
94
|
-
return "null";
|
|
95
|
-
}
|
|
96
|
-
return String(value);
|
|
97
|
-
}
|
|
98
|
-
function handleRecord(def, allTypeNames, diagnostics) {
|
|
99
|
-
const valueSchema = mapTypeDefinition(def.value, allTypeNames, diagnostics);
|
|
100
|
-
// ZOD-7: Non-string record key -> degrade to z.record(z.string(), ...)
|
|
101
|
-
if (def.key.kind !== "primitive" || def.key.type !== "string") {
|
|
102
|
-
diagnostics.push({
|
|
103
|
-
level: "warn",
|
|
104
|
-
plugin: PLUGIN_NAME,
|
|
105
|
-
message: `Record key type is not string (got ${JSON.stringify(def.key)}). Degrading to z.record(z.string(), ...).`,
|
|
106
|
-
});
|
|
107
|
-
return `z.record(z.string(), ${valueSchema})`;
|
|
108
|
-
}
|
|
109
|
-
return `z.record(z.string(), ${valueSchema})`;
|
|
110
|
-
}
|
|
111
|
-
function renderZodObject(fields, allTypeNames, diagnostics) {
|
|
112
|
-
const sortedFields = Object.keys(fields).sort();
|
|
113
|
-
const parts = [];
|
|
114
|
-
for (const fieldName of sortedFields) {
|
|
115
|
-
const field = fields[fieldName];
|
|
116
|
-
let zodType = mapTypeDefinition(field.type, allTypeNames, diagnostics);
|
|
117
|
-
// ZOD-6: optional -> .optional()
|
|
118
|
-
if (field.optional) {
|
|
119
|
-
zodType += ".optional()";
|
|
120
|
-
}
|
|
121
|
-
parts.push(` ${fieldName}: ${zodType},`);
|
|
122
|
-
}
|
|
123
|
-
return `z.object({\n${parts.join("\n")}\n})`;
|
|
124
|
-
}
|
|
125
|
-
function handleUnion(types, allTypeNames, diagnostics) {
|
|
126
|
-
// ZOD-3: 2-variant union with null -> z.nullable(T)
|
|
127
|
-
if (types.length === 2) {
|
|
128
|
-
const nullIdx = types.findIndex((t) => t.kind === "primitive" && t.type === "null");
|
|
129
|
-
if (nullIdx !== -1) {
|
|
130
|
-
const otherIdx = nullIdx === 0 ? 1 : 0;
|
|
131
|
-
const otherSchema = mapTypeDefinition(types[otherIdx], allTypeNames, diagnostics);
|
|
132
|
-
return `z.nullable(${otherSchema})`;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
const schemas = types.map((t) => mapTypeDefinition(t, allTypeNames, diagnostics));
|
|
136
|
-
return `z.union([${schemas.join(", ")}])`;
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=zod-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zod-plugin.js","sourceRoot":"","sources":["../../src/plugins/zod-plugin.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,GAAG,oBAAoB,CAAC;AACzC,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAM3C,MAAM,UAAU,eAAe,CAAC,OAA0B;IACxD,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,SAAS,CAAC;IAEtD,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,QAAQ,CAAC,GAAmB;YAC1B,MAAM,WAAW,GAAiB,EAAE,CAAC;YAErC,2CAA2C;YAC3C,MAAM,WAAW,GAAG,GAAG,CAAC,SAAS,CAAC,cAAc,CAAkC,CAAC;YAEnF,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,M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,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;YAClF,OAAO,cAAc,WAAW,GAAG,CAAC;QACtC,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,CAAC,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC;IAClF,OAAO,YAAY,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAC5C,CAAC"}
|
package/dist/runner.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { GenerateOptions, GenerateResult } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Generate typed artifacts from a DomainSchema using plugins.
|
|
4
|
-
*
|
|
5
|
-
* This is the sole entry point for codegen. It orchestrates:
|
|
6
|
-
* - Plugin name uniqueness validation (GEN-2)
|
|
7
|
-
* - Sequential plugin execution (GEN-3, GEN-7)
|
|
8
|
-
* - FilePatch composition with collision detection
|
|
9
|
-
* - Error gating (GEN-5, GEN-8)
|
|
10
|
-
* - outDir clean + file flush (GEN-1)
|
|
11
|
-
*/
|
|
12
|
-
export declare function generate(opts: GenerateOptions): Promise<GenerateResult>;
|
|
13
|
-
//# sourceMappingURL=runner.d.ts.map
|
package/dist/runner.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAIV,eAAe,EACf,cAAc,EACf,MAAM,YAAY,CAAC;AAMpB;;;;;;;;;GASG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAqG7E"}
|
package/dist/runner.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs/promises";
|
|
2
|
-
import * as nodePath from "node:path";
|
|
3
|
-
import { VirtualFS } from "./virtual-fs.js";
|
|
4
|
-
import { validatePath } from "./path-safety.js";
|
|
5
|
-
import { stableHash } from "./stable-hash.js";
|
|
6
|
-
import { generateHeader } from "./header.js";
|
|
7
|
-
/**
|
|
8
|
-
* Generate typed artifacts from a DomainSchema using plugins.
|
|
9
|
-
*
|
|
10
|
-
* This is the sole entry point for codegen. It orchestrates:
|
|
11
|
-
* - Plugin name uniqueness validation (GEN-2)
|
|
12
|
-
* - Sequential plugin execution (GEN-3, GEN-7)
|
|
13
|
-
* - FilePatch composition with collision detection
|
|
14
|
-
* - Error gating (GEN-5, GEN-8)
|
|
15
|
-
* - outDir clean + file flush (GEN-1)
|
|
16
|
-
*/
|
|
17
|
-
export async function generate(opts) {
|
|
18
|
-
const diagnostics = [];
|
|
19
|
-
const allArtifacts = {};
|
|
20
|
-
const vfs = new VirtualFS();
|
|
21
|
-
// GEN-2: Validate plugin name uniqueness
|
|
22
|
-
const nameError = validatePluginNames(opts.plugins);
|
|
23
|
-
if (nameError) {
|
|
24
|
-
return {
|
|
25
|
-
files: [],
|
|
26
|
-
artifacts: {},
|
|
27
|
-
diagnostics: [nameError],
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
// GEN-3, GEN-7: Execute plugins sequentially in array order
|
|
31
|
-
for (const plugin of opts.plugins) {
|
|
32
|
-
const ctx = {
|
|
33
|
-
schema: opts.schema,
|
|
34
|
-
sourceId: opts.sourceId,
|
|
35
|
-
outDir: opts.outDir,
|
|
36
|
-
artifacts: Object.freeze({ ...allArtifacts }), // PLG-9: frozen snapshot
|
|
37
|
-
helpers: { stableHash },
|
|
38
|
-
};
|
|
39
|
-
let output;
|
|
40
|
-
try {
|
|
41
|
-
output = await plugin.generate(ctx);
|
|
42
|
-
}
|
|
43
|
-
catch (err) {
|
|
44
|
-
// Convert plugin exceptions to error diagnostics (errors as values)
|
|
45
|
-
diagnostics.push({
|
|
46
|
-
level: "error",
|
|
47
|
-
plugin: plugin.name,
|
|
48
|
-
message: `Plugin threw: ${err instanceof Error ? err.message : String(err)}`,
|
|
49
|
-
});
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
// GEN-4: Merge plugin diagnostics
|
|
53
|
-
if (output.diagnostics) {
|
|
54
|
-
diagnostics.push(...output.diagnostics);
|
|
55
|
-
}
|
|
56
|
-
// Validate and apply patches
|
|
57
|
-
for (const patch of output.patches) {
|
|
58
|
-
const validation = validatePath(patch.path);
|
|
59
|
-
if (!validation.valid) {
|
|
60
|
-
diagnostics.push({
|
|
61
|
-
level: "error",
|
|
62
|
-
plugin: plugin.name,
|
|
63
|
-
message: `Invalid path "${patch.path}": ${validation.reason}`,
|
|
64
|
-
});
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
// Apply with normalized path
|
|
68
|
-
const normalizedPatch = patch.op === "set"
|
|
69
|
-
? { op: "set", path: validation.normalized, content: patch.content }
|
|
70
|
-
: { op: "delete", path: validation.normalized };
|
|
71
|
-
const collision = vfs.applyPatch(normalizedPatch, plugin.name);
|
|
72
|
-
if (collision) {
|
|
73
|
-
diagnostics.push(collision);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// PLG-8: Store artifacts at allArtifacts[plugin.name]
|
|
77
|
-
if (output.artifacts) {
|
|
78
|
-
allArtifacts[plugin.name] = output.artifacts;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
// Collect files from VFS
|
|
82
|
-
const files = vfs.getFiles();
|
|
83
|
-
// GEN-5, GEN-8: Error gate — no disk mutation on error
|
|
84
|
-
const hasErrors = diagnostics.some((d) => d.level === "error");
|
|
85
|
-
if (hasErrors) {
|
|
86
|
-
return { files, artifacts: allArtifacts, diagnostics };
|
|
87
|
-
}
|
|
88
|
-
// GEN-1: Clean outDir before write
|
|
89
|
-
await fs.rm(opts.outDir, { recursive: true, force: true });
|
|
90
|
-
// Build header
|
|
91
|
-
const header = generateHeader({
|
|
92
|
-
sourceId: opts.sourceId,
|
|
93
|
-
schemaHash: opts.schema.hash,
|
|
94
|
-
stamp: opts.stamp,
|
|
95
|
-
});
|
|
96
|
-
// Flush files to disk (GEN-6: OS path conversion only at write time)
|
|
97
|
-
for (const file of files) {
|
|
98
|
-
const absPath = nodePath.join(opts.outDir, ...file.path.split("/"));
|
|
99
|
-
const dir = nodePath.dirname(absPath);
|
|
100
|
-
await fs.mkdir(dir, { recursive: true });
|
|
101
|
-
await fs.writeFile(absPath, header + file.content, "utf-8");
|
|
102
|
-
}
|
|
103
|
-
return { files, artifacts: allArtifacts, diagnostics };
|
|
104
|
-
}
|
|
105
|
-
function validatePluginNames(plugins) {
|
|
106
|
-
const seen = new Set();
|
|
107
|
-
for (const plugin of plugins) {
|
|
108
|
-
if (!plugin.name) {
|
|
109
|
-
return {
|
|
110
|
-
level: "error",
|
|
111
|
-
plugin: "",
|
|
112
|
-
message: "Plugin name must not be empty (PLG-1)",
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
if (seen.has(plugin.name)) {
|
|
116
|
-
return {
|
|
117
|
-
level: "error",
|
|
118
|
-
plugin: plugin.name,
|
|
119
|
-
message: `Duplicate plugin name "${plugin.name}" (GEN-2)`,
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
seen.add(plugin.name);
|
|
123
|
-
}
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=runner.js.map
|
package/dist/runner.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAC;AAStC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;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AC;IAC/B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACjB,OAAO;gBACL,KAAK,EAAE,OAAO;gBACd,MAAM,EAAE,EAAE;gBACV,OAAO,EAAE,uCAAuC;aACjD,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,OAAO;gBACL,KAAK,EAAE,OAAO;gBACd,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,OAAO,EAAE,0BAA0B,MAAM,CAAC,IAAI,WAAW;aAC1D,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/stable-hash.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deterministic hash function (DET-1).
|
|
3
|
-
* Same input always produces the same output.
|
|
4
|
-
* Uses Core's canonical form (sorted keys, no undefined) + SHA-256.
|
|
5
|
-
*/
|
|
6
|
-
export declare function stableHash(input: unknown): string;
|
|
7
|
-
//# sourceMappingURL=stable-hash.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stable-hash.d.ts","sourceRoot":"","sources":["../src/stable-hash.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGjD"}
|
package/dist/stable-hash.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { toCanonical, sha256Sync } from "@manifesto-ai/core";
|
|
2
|
-
/**
|
|
3
|
-
* Deterministic hash function (DET-1).
|
|
4
|
-
* Same input always produces the same output.
|
|
5
|
-
* Uses Core's canonical form (sorted keys, no undefined) + SHA-256.
|
|
6
|
-
*/
|
|
7
|
-
export function stableHash(input) {
|
|
8
|
-
const canonical = toCanonical(input);
|
|
9
|
-
return sha256Sync(canonical);
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=stable-hash.js.map
|
package/dist/stable-hash.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stable-hash.js","sourceRoot":"","sources":["../src/stable-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,MAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACrC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC;AAC/B,CAAC"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { DomainSchema } from "@manifesto-ai/core";
|
|
2
|
-
export type { DomainSchema };
|
|
3
|
-
export type Diagnostic = {
|
|
4
|
-
readonly level: "warn" | "error";
|
|
5
|
-
readonly plugin: string;
|
|
6
|
-
readonly message: string;
|
|
7
|
-
};
|
|
8
|
-
export type FilePatch = {
|
|
9
|
-
readonly op: "set";
|
|
10
|
-
readonly path: string;
|
|
11
|
-
readonly content: string;
|
|
12
|
-
} | {
|
|
13
|
-
readonly op: "delete";
|
|
14
|
-
readonly path: string;
|
|
15
|
-
};
|
|
16
|
-
export interface CodegenHelpers {
|
|
17
|
-
stableHash(input: unknown): string;
|
|
18
|
-
}
|
|
19
|
-
export interface CodegenContext {
|
|
20
|
-
readonly schema: DomainSchema;
|
|
21
|
-
readonly sourceId?: string;
|
|
22
|
-
readonly outDir: string;
|
|
23
|
-
readonly artifacts: Readonly<Record<string, unknown>>;
|
|
24
|
-
readonly helpers: CodegenHelpers;
|
|
25
|
-
}
|
|
26
|
-
export interface CodegenOutput {
|
|
27
|
-
readonly patches: readonly FilePatch[];
|
|
28
|
-
readonly artifacts?: Readonly<Record<string, unknown>>;
|
|
29
|
-
readonly diagnostics?: readonly Diagnostic[];
|
|
30
|
-
}
|
|
31
|
-
export interface CodegenPlugin {
|
|
32
|
-
readonly name: string;
|
|
33
|
-
generate(ctx: CodegenContext): CodegenOutput | Promise<CodegenOutput>;
|
|
34
|
-
}
|
|
35
|
-
export interface GenerateOptions {
|
|
36
|
-
readonly schema: DomainSchema;
|
|
37
|
-
readonly outDir: string;
|
|
38
|
-
readonly plugins: readonly CodegenPlugin[];
|
|
39
|
-
readonly sourceId?: string;
|
|
40
|
-
readonly stamp?: boolean;
|
|
41
|
-
}
|
|
42
|
-
export interface GenerateResult {
|
|
43
|
-
readonly files: ReadonlyArray<{
|
|
44
|
-
readonly path: string;
|
|
45
|
-
readonly content: string;
|
|
46
|
-
}>;
|
|
47
|
-
readonly artifacts: Readonly<Record<string, unknown>>;
|
|
48
|
-
readonly diagnostics: readonly Diagnostic[];
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,SAAS,GACjB;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACvE;IAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;I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CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnF,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACtD,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/virtual-fs.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Diagnostic, FilePatch } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Virtual filesystem for composing FilePatch operations.
|
|
4
|
-
*
|
|
5
|
-
* Maintains an in-memory FS and detects collisions per FP-5, FP-6, FP-7.
|
|
6
|
-
* Paths are assumed to be already validated/normalized.
|
|
7
|
-
*/
|
|
8
|
-
export declare class VirtualFS {
|
|
9
|
-
private readonly files;
|
|
10
|
-
private readonly deleted;
|
|
11
|
-
/**
|
|
12
|
-
* Apply a FilePatch to the virtual FS.
|
|
13
|
-
* Returns a Diagnostic if a collision/warning condition is detected.
|
|
14
|
-
*/
|
|
15
|
-
applyPatch(patch: FilePatch, pluginName: string): Diagnostic | undefined;
|
|
16
|
-
private applySet;
|
|
17
|
-
private applyDelete;
|
|
18
|
-
/**
|
|
19
|
-
* Get all files in deterministic (lexicographic) order (DET-5).
|
|
20
|
-
*/
|
|
21
|
-
getFiles(): Array<{
|
|
22
|
-
path: string;
|
|
23
|
-
content: string;
|
|
24
|
-
}>;
|
|
25
|
-
has(path: string): boolean;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=virtual-fs.d.ts.map
|
package/dist/virtual-fs.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-fs.d.ts","sourceRoot":"","sources":["../src/virtual-fs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAOxD;;;;;GAKG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgC;IACtD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C;;;OAGG;IACH,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAOxE,OAAO,CAAC,QAAQ;IAqBhB,OAAO,CAAC,WAAW;IA4BnB;;OAEG;IACH,QAAQ,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAMpD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAG3B"}
|
package/dist/virtual-fs.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Virtual filesystem for composing FilePatch operations.
|
|
3
|
-
*
|
|
4
|
-
* Maintains an in-memory FS and detects collisions per FP-5, FP-6, FP-7.
|
|
5
|
-
* Paths are assumed to be already validated/normalized.
|
|
6
|
-
*/
|
|
7
|
-
export class VirtualFS {
|
|
8
|
-
files = new Map();
|
|
9
|
-
deleted = new Set();
|
|
10
|
-
/**
|
|
11
|
-
* Apply a FilePatch to the virtual FS.
|
|
12
|
-
* Returns a Diagnostic if a collision/warning condition is detected.
|
|
13
|
-
*/
|
|
14
|
-
applyPatch(patch, pluginName) {
|
|
15
|
-
if (patch.op === "set") {
|
|
16
|
-
return this.applySet(patch.path, patch.content, pluginName);
|
|
17
|
-
}
|
|
18
|
-
return this.applyDelete(patch.path, pluginName);
|
|
19
|
-
}
|
|
20
|
-
applySet(path, content, pluginName) {
|
|
21
|
-
const existing = this.files.get(path);
|
|
22
|
-
if (existing) {
|
|
23
|
-
// FP-5: Duplicate set on same path -> error
|
|
24
|
-
const samePlugin = existing.source === pluginName;
|
|
25
|
-
return {
|
|
26
|
-
level: "error",
|
|
27
|
-
plugin: pluginName,
|
|
28
|
-
message: samePlugin
|
|
29
|
-
? `Duplicate set on "${path}" within plugin "${pluginName}"`
|
|
30
|
-
: `File "${path}" already set by plugin "${existing.source}", cannot be set again by "${pluginName}"`,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
// delete-then-set is allowed (intentional regeneration)
|
|
34
|
-
this.deleted.delete(path);
|
|
35
|
-
this.files.set(path, { content, source: pluginName });
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
applyDelete(path, pluginName) {
|
|
39
|
-
const existing = this.files.get(path);
|
|
40
|
-
if (!existing && !this.deleted.has(path)) {
|
|
41
|
-
// FP-7: Delete on nonexistent path -> warn
|
|
42
|
-
return {
|
|
43
|
-
level: "warn",
|
|
44
|
-
plugin: pluginName,
|
|
45
|
-
message: `Delete on nonexistent path "${path}"`,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (existing) {
|
|
49
|
-
// FP-6: set-then-delete -> allowed with warning
|
|
50
|
-
this.files.delete(path);
|
|
51
|
-
this.deleted.add(path);
|
|
52
|
-
return {
|
|
53
|
-
level: "warn",
|
|
54
|
-
plugin: pluginName,
|
|
55
|
-
message: `File "${path}" set by plugin "${existing.source}" is being deleted by "${pluginName}". Prior work is voided.`,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
// Already deleted - just track it
|
|
59
|
-
this.deleted.add(path);
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Get all files in deterministic (lexicographic) order (DET-5).
|
|
64
|
-
*/
|
|
65
|
-
getFiles() {
|
|
66
|
-
const entries = Array.from(this.files.entries());
|
|
67
|
-
entries.sort(([a], [b]) => a.localeCompare(b));
|
|
68
|
-
return entries.map(([path, { content }]) => ({ path, content }));
|
|
69
|
-
}
|
|
70
|
-
has(path) {
|
|
71
|
-
return this.files.has(path);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=virtual-fs.js.map
|
package/dist/virtual-fs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-fs.js","sourceRoot":"","sources":["../src/virtual-fs.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IACH,KAAK,GAAG,IAAI,GAAG,EAAqB,CAAC;IACrC,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAE7C;;;OAGG;IACH,UAAU,CAAC,KAAgB,EAAE,UAAkB;QAC7C,IAAI,KAAK,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAClD,CAAC;IAEO,QAAQ,CAAC,IAAY,EAAE,OAAe,EAAE,UAAkB;QAChE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAEtC,IAAI,QAAQ,EAAE,CAAC;YACb,4CAA4C;YAC5C,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;YAClD,OAAO;gBACL,KAAK,EAAE,OAAO;gBACd,MAAM,EAAE,UAAU;gBAClB,OAAO,EAAE,UAAU;oBACjB,CAAC,CAAC,qBAAqB,IAAI,oBAAoB,UAAU,GAAG;oBAC5D,CAAC,CAAC,SAAS,IAAI,4BAA4B,QAAQ,CAAC,MAAM,8BAA8B,UAAU,GAAG;aACxG,CAAC;QACJ,CAAC;QAED,wDAAwD;QACxD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,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