@manifesto-ai/codegen 0.1.3 → 0.1.5
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 +28 -23
- package/dist/header.d.ts +12 -0
- package/dist/index.d.ts +9 -114
- package/dist/index.js +775 -15
- package/dist/index.js.map +1 -1
- package/dist/path-safety.d.ts +15 -0
- package/dist/plugins/domain-plugin.d.ts +7 -0
- package/dist/plugins/domain-type-inference.d.ts +16 -0
- package/dist/plugins/domain-type-model.d.ts +44 -0
- package/dist/plugins/index.d.ts +6 -0
- package/dist/plugins/ts-plugin.d.ts +16 -0
- package/dist/plugins/zod-plugin.d.ts +11 -0
- package/dist/runner.d.ts +12 -0
- package/dist/stable-hash.d.ts +6 -0
- package/dist/types.d.ts +50 -0
- package/dist/virtual-fs.d.ts +26 -0
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @manifesto-ai/codegen
|
|
2
2
|
|
|
3
|
-
> **Codegen** generates
|
|
3
|
+
> **Codegen** generates canonical domain facade types from a Manifesto DomainSchema through a deterministic plugin pipeline.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -23,7 +23,8 @@ DomainSchema -> CODEGEN -> Generated Files
|
|
|
23
23
|
|
|
24
24
|
| Responsibility | Description |
|
|
25
25
|
|----------------|-------------|
|
|
26
|
-
| Generate
|
|
26
|
+
| Generate canonical domain facades | DomainSchema -> `<domain>.mel.ts` with `state` / `computed` / `actions` |
|
|
27
|
+
| Generate legacy TS/Zod artifacts | Optional low-level `types.ts` / `base.ts` output |
|
|
27
28
|
| Generate Zod schemas | DomainSchema types -> Zod validators with type annotations |
|
|
28
29
|
| Plugin pipeline | Run plugins sequentially with shared artifacts |
|
|
29
30
|
| Path safety | Validate and normalize output file paths |
|
|
@@ -58,7 +59,7 @@ npm install @manifesto-ai/codegen
|
|
|
58
59
|
## Quick Example
|
|
59
60
|
|
|
60
61
|
```typescript
|
|
61
|
-
import { generate,
|
|
62
|
+
import { generate, createDomainPlugin } from "@manifesto-ai/codegen";
|
|
62
63
|
import type { DomainSchema } from "@manifesto-ai/core";
|
|
63
64
|
|
|
64
65
|
const schema: DomainSchema = { /* your domain schema */ };
|
|
@@ -66,35 +67,35 @@ const schema: DomainSchema = { /* your domain schema */ };
|
|
|
66
67
|
const result = await generate({
|
|
67
68
|
schema,
|
|
68
69
|
outDir: "./generated",
|
|
69
|
-
|
|
70
|
+
sourceId: "src/domain/hello.mel",
|
|
71
|
+
plugins: [createDomainPlugin()],
|
|
70
72
|
});
|
|
71
73
|
|
|
72
|
-
// result.files -> [{ path: "
|
|
74
|
+
// result.files -> [{ path: "src/domain/hello.mel.ts", content: "..." }]
|
|
73
75
|
// result.diagnostics -> [] (empty = no warnings or errors)
|
|
74
76
|
```
|
|
75
77
|
|
|
76
|
-
This produces
|
|
78
|
+
This produces a canonical domain facade:
|
|
77
79
|
|
|
78
|
-
**
|
|
80
|
+
**src/domain/hello.mel.ts**
|
|
79
81
|
```typescript
|
|
80
|
-
export interface
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
export interface HelloDomain {
|
|
83
|
+
readonly state: {
|
|
84
|
+
counter: number
|
|
85
|
+
hello: string
|
|
86
|
+
}
|
|
87
|
+
readonly computed: {
|
|
88
|
+
canDecrement: boolean
|
|
89
|
+
doubled: number
|
|
90
|
+
}
|
|
91
|
+
readonly actions: {
|
|
92
|
+
decrement: () => void
|
|
93
|
+
increment: () => void
|
|
94
|
+
}
|
|
84
95
|
}
|
|
85
96
|
```
|
|
86
97
|
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
import { z } from "zod";
|
|
90
|
-
import type { Todo } from "./types";
|
|
91
|
-
|
|
92
|
-
export const TodoSchema: z.ZodType<Todo> = z.object({
|
|
93
|
-
completed: z.boolean(),
|
|
94
|
-
id: z.string(),
|
|
95
|
-
title: z.string(),
|
|
96
|
-
});
|
|
97
|
-
```
|
|
98
|
+
Legacy `createTsPlugin()` and `createZodPlugin()` remain available, but are deprecated in favor of `createDomainPlugin()`.
|
|
98
99
|
|
|
99
100
|
> See [GUIDE.md](docs/GUIDE.md) for the full tutorial.
|
|
100
101
|
|
|
@@ -109,7 +110,10 @@ export const TodoSchema: z.ZodType<Todo> = z.object({
|
|
|
109
110
|
function generate(options: GenerateOptions): Promise<GenerateResult>;
|
|
110
111
|
|
|
111
112
|
// Built-in plugins
|
|
113
|
+
function createDomainPlugin(options?: DomainPluginOptions): CodegenPlugin;
|
|
114
|
+
/** @deprecated */
|
|
112
115
|
function createTsPlugin(options?: TsPluginOptions): CodegenPlugin;
|
|
116
|
+
/** @deprecated */
|
|
113
117
|
function createZodPlugin(options?: ZodPluginOptions): CodegenPlugin;
|
|
114
118
|
|
|
115
119
|
// Key types
|
|
@@ -141,7 +145,7 @@ type CodegenPlugin = {
|
|
|
141
145
|
|
|
142
146
|
### Plugin Pipeline
|
|
143
147
|
|
|
144
|
-
Plugins run in array order. Each plugin receives a context containing the schema and artifacts from all previous plugins. The TS plugin publishes type names
|
|
148
|
+
Plugins run in array order. Each plugin receives a context containing the schema and artifacts from all previous plugins. The canonical domain plugin is self-contained; the legacy TS plugin publishes type names and the legacy Zod plugin reads them to generate type-annotated schemas.
|
|
145
149
|
|
|
146
150
|
### Artifacts
|
|
147
151
|
|
|
@@ -169,6 +173,7 @@ Same DomainSchema always produces byte-identical output files. Fields and types
|
|
|
169
173
|
## When to Use Codegen
|
|
170
174
|
|
|
171
175
|
Use Codegen when:
|
|
176
|
+
- You want a canonical `<domain>.mel.ts` facade for `createManifesto<T>()`
|
|
172
177
|
- You want type-safe TypeScript interfaces from your DomainSchema
|
|
173
178
|
- You want Zod runtime validators that match your schema types
|
|
174
179
|
- You need deterministic, reproducible code generation in CI
|
package/dist/header.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,114 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
readonly path: string;
|
|
11
|
-
readonly content: string;
|
|
12
|
-
} | {
|
|
13
|
-
readonly op: "delete";
|
|
14
|
-
readonly path: string;
|
|
15
|
-
};
|
|
16
|
-
interface CodegenHelpers {
|
|
17
|
-
stableHash(input: unknown): string;
|
|
18
|
-
}
|
|
19
|
-
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
|
-
interface CodegenOutput {
|
|
27
|
-
readonly patches: readonly FilePatch[];
|
|
28
|
-
readonly artifacts?: Readonly<Record<string, unknown>>;
|
|
29
|
-
readonly diagnostics?: readonly Diagnostic[];
|
|
30
|
-
}
|
|
31
|
-
interface CodegenPlugin {
|
|
32
|
-
readonly name: string;
|
|
33
|
-
generate(ctx: CodegenContext): CodegenOutput | Promise<CodegenOutput>;
|
|
34
|
-
}
|
|
35
|
-
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
|
-
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
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Generate typed artifacts from a DomainSchema using plugins.
|
|
53
|
-
*
|
|
54
|
-
* This is the sole entry point for codegen. It orchestrates:
|
|
55
|
-
* - Plugin name uniqueness validation (GEN-2)
|
|
56
|
-
* - Sequential plugin execution (GEN-3, GEN-7)
|
|
57
|
-
* - FilePatch composition with collision detection
|
|
58
|
-
* - Error gating (GEN-5, GEN-8)
|
|
59
|
-
* - outDir clean + file flush (GEN-1)
|
|
60
|
-
*/
|
|
61
|
-
declare function generate(opts: GenerateOptions): Promise<GenerateResult>;
|
|
62
|
-
|
|
63
|
-
interface TsPluginOptions {
|
|
64
|
-
readonly typesFile?: string;
|
|
65
|
-
readonly actionsFile?: string;
|
|
66
|
-
}
|
|
67
|
-
interface TsPluginArtifacts {
|
|
68
|
-
readonly typeNames: string[];
|
|
69
|
-
readonly typeImportPath: string;
|
|
70
|
-
}
|
|
71
|
-
declare function createTsPlugin(options?: TsPluginOptions): CodegenPlugin;
|
|
72
|
-
|
|
73
|
-
interface ZodPluginOptions {
|
|
74
|
-
readonly schemasFile?: string;
|
|
75
|
-
}
|
|
76
|
-
declare function createZodPlugin(options?: ZodPluginOptions): CodegenPlugin;
|
|
77
|
-
|
|
78
|
-
type PathValidationResult = {
|
|
79
|
-
valid: true;
|
|
80
|
-
normalized: string;
|
|
81
|
-
} | {
|
|
82
|
-
valid: false;
|
|
83
|
-
reason: string;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Validate and normalize a file path per FP-1, FP-2, GEN-6.
|
|
87
|
-
*
|
|
88
|
-
* - MUST be a POSIX relative path
|
|
89
|
-
* - MUST NOT contain `..`, absolute prefixes, drive letters, or null bytes
|
|
90
|
-
* - Normalizes backslashes, multiple slashes, and leading `./`
|
|
91
|
-
*/
|
|
92
|
-
declare function validatePath(path: string): PathValidationResult;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Deterministic hash function (DET-1).
|
|
96
|
-
* Same input always produces the same output.
|
|
97
|
-
* Uses Core's canonical form (sorted keys, no undefined) + SHA-256.
|
|
98
|
-
*/
|
|
99
|
-
declare function stableHash(input: unknown): string;
|
|
100
|
-
|
|
101
|
-
interface HeaderOptions {
|
|
102
|
-
readonly sourceId?: string;
|
|
103
|
-
readonly schemaHash: string;
|
|
104
|
-
readonly stamp?: boolean;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Generate the @generated file header (DET-2, DET-3, DET-4).
|
|
108
|
-
*
|
|
109
|
-
* Default mode: no timestamp (deterministic).
|
|
110
|
-
* With stamp=true: appends ISO 8601 timestamp line.
|
|
111
|
-
*/
|
|
112
|
-
declare function generateHeader(options: HeaderOptions): string;
|
|
113
|
-
|
|
114
|
-
export { type CodegenContext, type CodegenHelpers, type CodegenOutput, type CodegenPlugin, type Diagnostic, type FilePatch, type GenerateOptions, type GenerateResult, type HeaderOptions, type PathValidationResult, type TsPluginArtifacts, type TsPluginOptions, type ZodPluginOptions, createTsPlugin, createZodPlugin, generate, generateHeader, stableHash, validatePath };
|
|
1
|
+
export type { Diagnostic, FilePatch, CodegenPlugin, CodegenContext, CodegenOutput, CodegenHelpers, GenerateOptions, GenerateResult, } from "./types.js";
|
|
2
|
+
export { generate } from "./runner.js";
|
|
3
|
+
export { createDomainPlugin, createTsPlugin, createZodPlugin, } from "./plugins/index.js";
|
|
4
|
+
export type { DomainPluginOptions, 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";
|