@metaobjectsdev/codegen-ts 0.6.0 → 0.7.0-rc.2
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 +161 -4
- package/dist/column-mapper.d.ts +16 -0
- package/dist/column-mapper.d.ts.map +1 -1
- package/dist/column-mapper.js +73 -2
- package/dist/column-mapper.js.map +1 -1
- package/dist/generators/entity-file.d.ts +15 -0
- package/dist/generators/entity-file.d.ts.map +1 -1
- package/dist/generators/entity-file.js +2 -1
- package/dist/generators/entity-file.js.map +1 -1
- package/dist/generators/index.d.ts +2 -0
- package/dist/generators/index.d.ts.map +1 -1
- package/dist/generators/index.js +2 -0
- package/dist/generators/index.js.map +1 -1
- package/dist/generators/output-parser-file.d.ts +9 -0
- package/dist/generators/output-parser-file.d.ts.map +1 -0
- package/dist/generators/output-parser-file.js +37 -0
- package/dist/generators/output-parser-file.js.map +1 -0
- package/dist/generators/prompt-render-file.d.ts +9 -0
- package/dist/generators/prompt-render-file.d.ts.map +1 -0
- package/dist/generators/prompt-render-file.js +70 -0
- package/dist/generators/prompt-render-file.js.map +1 -0
- package/dist/generators/queries-file.d.ts +1 -1
- package/dist/generators/queries-file.d.ts.map +1 -1
- package/dist/generators/queries-file.js +11 -3
- package/dist/generators/queries-file.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/metaobjects-config.d.ts +3 -1
- package/dist/metaobjects-config.d.ts.map +1 -1
- package/dist/metaobjects-config.js +2 -1
- package/dist/metaobjects-config.js.map +1 -1
- package/dist/naming.d.ts +3 -12
- package/dist/naming.d.ts.map +1 -1
- package/dist/naming.js +14 -44
- package/dist/naming.js.map +1 -1
- package/dist/payload-codegen.d.ts +8 -0
- package/dist/payload-codegen.d.ts.map +1 -1
- package/dist/payload-codegen.js +33 -3
- package/dist/payload-codegen.js.map +1 -1
- package/dist/projection/extract-view-spec.d.ts +1 -1
- package/dist/projection/extract-view-spec.js +1 -1
- package/dist/source-detect.d.ts +10 -0
- package/dist/source-detect.d.ts.map +1 -0
- package/dist/source-detect.js +30 -0
- package/dist/source-detect.js.map +1 -0
- package/dist/templates/drizzle-schema.js +27 -3
- package/dist/templates/drizzle-schema.js.map +1 -1
- package/dist/templates/entity-file.d.ts +15 -1
- package/dist/templates/entity-file.d.ts.map +1 -1
- package/dist/templates/entity-file.js +15 -5
- package/dist/templates/entity-file.js.map +1 -1
- package/dist/templates/inferred-types.d.ts +9 -0
- package/dist/templates/inferred-types.d.ts.map +1 -1
- package/dist/templates/inferred-types.js +88 -2
- package/dist/templates/inferred-types.js.map +1 -1
- package/dist/templates/output-parser.d.ts +8 -0
- package/dist/templates/output-parser.d.ts.map +1 -0
- package/dist/templates/output-parser.js +129 -0
- package/dist/templates/output-parser.js.map +1 -0
- package/dist/templates/projection-decl.d.ts +1 -1
- package/dist/templates/projection-decl.js +1 -1
- package/dist/templates/queries-file.d.ts.map +1 -1
- package/dist/templates/queries-file.js +15 -4
- package/dist/templates/queries-file.js.map +1 -1
- package/dist/templates/queries.d.ts.map +1 -1
- package/dist/templates/queries.js +11 -30
- package/dist/templates/queries.js.map +1 -1
- package/dist/templates/value-object-file.d.ts +3 -0
- package/dist/templates/value-object-file.d.ts.map +1 -0
- package/dist/templates/value-object-file.js +27 -0
- package/dist/templates/value-object-file.js.map +1 -0
- package/dist/templates/zod-validators.d.ts +10 -0
- package/dist/templates/zod-validators.d.ts.map +1 -1
- package/dist/templates/zod-validators.js +108 -30
- package/dist/templates/zod-validators.js.map +1 -1
- package/package.json +4 -4
- package/src/column-mapper.ts +86 -1
- package/src/generators/entity-file.ts +17 -1
- package/src/generators/index.ts +2 -0
- package/src/generators/output-parser-file.ts +50 -0
- package/src/generators/prompt-render-file.ts +95 -0
- package/src/generators/queries-file.ts +13 -4
- package/src/index.ts +1 -1
- package/src/metaobjects-config.ts +4 -2
- package/src/naming.ts +22 -46
- package/src/payload-codegen.ts +34 -2
- package/src/projection/extract-view-spec.ts +1 -1
- package/src/source-detect.ts +28 -0
- package/src/templates/drizzle-schema.ts +27 -3
- package/src/templates/entity-file.ts +36 -5
- package/src/templates/inferred-types.ts +117 -3
- package/src/templates/output-parser.ts +143 -0
- package/src/templates/projection-decl.ts +1 -1
- package/src/templates/queries-file.ts +18 -4
- package/src/templates/queries.ts +11 -33
- package/src/templates/value-object-file.ts +30 -0
- package/src/templates/zod-validators.ts +121 -35
package/README.md
CHANGED
|
@@ -12,11 +12,13 @@ npm install @metaobjectsdev/codegen-ts @metaobjectsdev/metadata drizzle-orm zod
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
|
-
import {
|
|
15
|
+
import { MetaDataLoader } from "@metaobjectsdev/metadata";
|
|
16
|
+
import { FileSource } from "@metaobjectsdev/metadata/core";
|
|
16
17
|
import { generate } from "@metaobjectsdev/codegen-ts";
|
|
17
18
|
|
|
18
|
-
const
|
|
19
|
-
|
|
19
|
+
const { root } = await new MetaDataLoader().load([
|
|
20
|
+
new FileSource("metaobjects/meta.blog.json"),
|
|
21
|
+
]);
|
|
20
22
|
|
|
21
23
|
const result = await generate({
|
|
22
24
|
metadata: root,
|
|
@@ -34,7 +36,7 @@ Per entity, codegen emits **two files**:
|
|
|
34
36
|
|
|
35
37
|
- `<Entity>.ts` — Drizzle table definition (with FK `.references()` + `relations()` blocks
|
|
36
38
|
auto-emitted from metadata relationships) + Drizzle-inferred types + Zod validators
|
|
37
|
-
- `<Entity>.queries.ts` — typed CRUD query functions
|
|
39
|
+
- `<Entity>.queries.ts` — typed CRUD query functions
|
|
38
40
|
(`findPostById`, `listPosts`, `createPost`, `updatePost`, `deletePostById`)
|
|
39
41
|
|
|
40
42
|
Plus a barrel `index.ts` re-exporting from each `<Entity>.ts`.
|
|
@@ -55,6 +57,44 @@ codegen-ts overwrites files with the header but refuses to touch files
|
|
|
55
57
|
without it. Hand-customizations live in sibling `<Entity>.extra.ts` files
|
|
56
58
|
(for custom queries, derived-column indexes, etc. that metadata can't express).
|
|
57
59
|
|
|
60
|
+
### Allowlists opt-in
|
|
61
|
+
|
|
62
|
+
By default, every generated `<Entity>.ts` file emits a `<Entity>FilterAllowlist`
|
|
63
|
+
and `<Entity>SortAllowlist` block, which type-only-imports `FilterAllowlist` /
|
|
64
|
+
`SortAllowlist` from `@metaobjectsdev/runtime-ts/drizzle-fastify`. These power
|
|
65
|
+
the Fastify-flavored CRUD routes emitted by `routesFile()`.
|
|
66
|
+
|
|
67
|
+
Worker / Lambda / edge consumers that don't mount Fastify-style server routes
|
|
68
|
+
can opt out — the entity file then has no `runtime-ts/drizzle-fastify` imports
|
|
69
|
+
at all, and `@metaobjectsdev/runtime-ts` can be dropped from the consumer's
|
|
70
|
+
dependency tree entirely:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// metaobjects.config.ts
|
|
74
|
+
import { defineConfig } from "@metaobjectsdev/cli";
|
|
75
|
+
import { entityFile, queriesFile, barrel } from "@metaobjectsdev/codegen-ts/generators";
|
|
76
|
+
|
|
77
|
+
export default defineConfig({
|
|
78
|
+
generators: [entityFile({ allowlists: false }), queriesFile(), barrel()],
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The client-side `<Entity>Filter` type is still emitted regardless — it has zero
|
|
83
|
+
runtime-ts dependency and consumers want it for typed client calls. Default is
|
|
84
|
+
`true` for back-compat with existing projects.
|
|
85
|
+
|
|
86
|
+
If you keep `routesFile()` wired in, leave `allowlists` at its default — the
|
|
87
|
+
generated routes reference the allowlists by name and won't compile without
|
|
88
|
+
them.
|
|
89
|
+
|
|
90
|
+
### Consumer wiring
|
|
91
|
+
|
|
92
|
+
Generated query helpers accept a Drizzle `db` instance as their first
|
|
93
|
+
parameter. See [wiring-generated-queries.md](../../../../docs/recipes/wiring-generated-queries.md)
|
|
94
|
+
for per-dialect setup, edge (Workers / D1) examples, and a 0.6.0 → 0.7.0
|
|
95
|
+
migration guide. The cross-language design decision is in
|
|
96
|
+
[ADR-0008](../../../../spec/decisions/ADR-0008-parameter-passing-generated-repo-helpers.md).
|
|
97
|
+
|
|
58
98
|
## Output targets
|
|
59
99
|
|
|
60
100
|
Each generator can be routed to its own output directory via a named **target**
|
|
@@ -96,6 +136,123 @@ It does **not** work on `better-sqlite3` or `bun:sqlite` (no native
|
|
|
96
136
|
functions in the sibling `<Entity>.extra.ts` file with a non-`.returning()`
|
|
97
137
|
form, or switch to a supported driver.
|
|
98
138
|
|
|
139
|
+
## `outputParser()` — typed parsers for `template.output`
|
|
140
|
+
|
|
141
|
+
For every `template.output` declared in your metadata, `outputParser()` emits
|
|
142
|
+
`<TemplateName>.output.ts` containing a Zod schema + dual-API parser:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
// metaobjects.config.ts
|
|
146
|
+
import { defineConfig } from "@metaobjectsdev/cli";
|
|
147
|
+
import { entityFile, queriesFile, barrel, promptRender, outputParser } from "@metaobjectsdev/codegen-ts/generators";
|
|
148
|
+
|
|
149
|
+
export default defineConfig({
|
|
150
|
+
generators: [entityFile(), queriesFile(), barrel(), promptRender(), outputParser()],
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
For a `template.output` named `NpcResponseOutput` with `@payloadRef: "NpcResponsePayload"`:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
// Generated NpcResponseOutput.output.ts — self-contained, no cross-file imports
|
|
158
|
+
import { z } from "zod";
|
|
159
|
+
|
|
160
|
+
const NpcResponseOutputSchema = z.object({
|
|
161
|
+
name: z.string(),
|
|
162
|
+
age: z.number().int(),
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
export type NpcResponseOutputData = z.infer<typeof NpcResponseOutputSchema>;
|
|
166
|
+
export type NpcResponseOutputValidationError = z.ZodError;
|
|
167
|
+
|
|
168
|
+
/** Throws ZodError on validation failure. */
|
|
169
|
+
export function parseNpcResponseOutput(text: string): NpcResponseOutputData { ... }
|
|
170
|
+
|
|
171
|
+
/** Result-style; never throws. */
|
|
172
|
+
export function safeParseNpcResponseOutput(text: string):
|
|
173
|
+
| { success: true; data: NpcResponseOutputData }
|
|
174
|
+
| { success: false; error: NpcResponseOutputValidationError } { ... }
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`parseXxx` and `safeParseXxx` return the local `<Name>Data` type, derived from
|
|
178
|
+
the schema via `z.infer<>`. It is structurally identical to the payload-VO
|
|
179
|
+
interface emitted by `promptRender()` (e.g., `NpcResponsePayload` in
|
|
180
|
+
`prompts.ts`) — consumers who wire both generators can assign back and forth
|
|
181
|
+
between `NpcResponseOutputData` and `NpcResponsePayload` interchangeably. The
|
|
182
|
+
output-parser file is intentionally self-contained so it compiles standalone
|
|
183
|
+
even when `promptRender()` is not wired in.
|
|
184
|
+
|
|
185
|
+
Consumer usage:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import { parseNpcResponseOutput, safeParseNpcResponseOutput } from "./generated/NpcResponseOutput.output";
|
|
189
|
+
|
|
190
|
+
const npc = parseNpcResponseOutput(llmResponseText); // throws on bad shape
|
|
191
|
+
|
|
192
|
+
const r = safeParseNpcResponseOutput(llmResponseText);
|
|
193
|
+
if (!r.success) { /* handle r.error (a ZodError) */ } else { /* use r.data */ }
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
**Field-type → Zod-type mapping:**
|
|
197
|
+
|
|
198
|
+
| Field subtype | Emitted Zod |
|
|
199
|
+
|---|---|
|
|
200
|
+
| `field.string`, `field.class` | `z.string()` |
|
|
201
|
+
| `field.int`, `field.long`, `field.short`, `field.byte` | `z.number().int()` |
|
|
202
|
+
| `field.double`, `field.float` | `z.number()` |
|
|
203
|
+
| `field.boolean` | `z.boolean()` |
|
|
204
|
+
| `field.object` (with `@objectRef`) | nested `z.object({ ... })` |
|
|
205
|
+
| `isArray: true` on any of the above | wrapped in `z.array(...)` |
|
|
206
|
+
|
|
207
|
+
**Options:**
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
outputParser({
|
|
211
|
+
outDir: "src/generated/outputs", // default: emits at the target's root
|
|
212
|
+
target: "default", // default: "default" (the entity-module target)
|
|
213
|
+
})
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**`meta verify` integration:** when `meta verify` runs, every `template.output`'s
|
|
217
|
+
`@payloadRef` resolution is checked. Unresolved refs fail the build (`exit 1`)
|
|
218
|
+
with a `(output)` prefix on the diagnostic. See [ADR-0010](../../../../spec/decisions/ADR-0010-template-output-parser-codegen.md)
|
|
219
|
+
for the cross-language design rationale.
|
|
220
|
+
|
|
221
|
+
## Naming conventions: camelCase TS ↔ snake_case SQL
|
|
222
|
+
|
|
223
|
+
`@metaobjectsdev/codegen-ts` maps `snake_case` metadata field names to
|
|
224
|
+
`camelCase` TS property names by default. The underlying SQL column stays
|
|
225
|
+
`snake_case`.
|
|
226
|
+
|
|
227
|
+
```jsonc
|
|
228
|
+
// Metadata
|
|
229
|
+
{ "field.long": { "name": "council_id" } }
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
// Generated TS — property is camelCase
|
|
234
|
+
import { councils } from "./generated/Council";
|
|
235
|
+
const id = council.councilId;
|
|
236
|
+
db.select().from(councils).where(eq(councils.councilId, "abc"));
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
```sql
|
|
240
|
+
-- Generated DDL — column stays snake_case
|
|
241
|
+
CREATE TABLE councils (
|
|
242
|
+
council_id TEXT NOT NULL PRIMARY KEY,
|
|
243
|
+
...
|
|
244
|
+
);
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
To override the SQL column name per-field, use `@dbColumn`:
|
|
248
|
+
|
|
249
|
+
```jsonc
|
|
250
|
+
{ "field.long": { "name": "councilId", "@dbColumn": "council_uuid" } }
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
The mapping policy is project-wide via `columnNamingStrategy` in
|
|
254
|
+
`metaobjects.config.ts`: `snake_case` (default) | `literal` | `kebab-case`.
|
|
255
|
+
|
|
99
256
|
## License
|
|
100
257
|
|
|
101
258
|
Apache-2.0.
|
package/dist/column-mapper.d.ts
CHANGED
|
@@ -35,6 +35,22 @@ export interface ColumnSpec {
|
|
|
35
35
|
leadingComment?: string;
|
|
36
36
|
/** Optional CHECK constraint expression for the column (e.g., `status IN ('A', 'B')`). */
|
|
37
37
|
checkConstraint?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Optional `.$type<...>()` chain target. Renderer (drizzle-schema.ts) emits
|
|
40
|
+
* `.$type<TS[]>()` ahead of the modifiers chain, using ts-poet `imp()` for
|
|
41
|
+
* objectRef variants so the cross-module type import auto-hoists.
|
|
42
|
+
* `kind: "scalar"` covers string[]/number[]/boolean[] — no import needed.
|
|
43
|
+
* `kind: "objectRef"` covers SourceLens[]/Dissent[]/etc. — `module` is the
|
|
44
|
+
* relative import path to that entity's emitted module.
|
|
45
|
+
*/
|
|
46
|
+
dollarTypeRef?: {
|
|
47
|
+
kind: "scalar";
|
|
48
|
+
tsType: "string" | "number" | "boolean";
|
|
49
|
+
} | {
|
|
50
|
+
kind: "objectRef";
|
|
51
|
+
name: string;
|
|
52
|
+
module: string;
|
|
53
|
+
};
|
|
38
54
|
}
|
|
39
55
|
export declare function mapColumnType(field: MetaField, dialect: Dialect, strategy?: ColumnNamingStrategy): ColumnSpec;
|
|
40
56
|
//# sourceMappingURL=column-mapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-mapper.d.ts","sourceRoot":"","sources":["../src/column-mapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"column-mapper.d.ts","sourceRoot":"","sources":["../src/column-mapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AA4B1D,OAAO,KAAK,EAAE,OAA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
|
1
1
|
// Field-type → Drizzle column type mapping. Per design §6.
|
|
2
2
|
// Uses the typed MetaField.validators() accessor (effective — includes inherited) for all validator checks.
|
|
3
|
-
import { FIELD_SUBTYPE_STRING, FIELD_SUBTYPE_INT, FIELD_SUBTYPE_LONG, FIELD_SUBTYPE_CURRENCY, FIELD_SUBTYPE_DOUBLE, FIELD_SUBTYPE_FLOAT, FIELD_SUBTYPE_DECIMAL, FIELD_SUBTYPE_BOOLEAN, FIELD_SUBTYPE_DATE, FIELD_SUBTYPE_TIME, FIELD_SUBTYPE_TIMESTAMP, FIELD_SUBTYPE_OBJECT, FIELD_SUBTYPE_CLASS, FIELD_SUBTYPE_ENUM, VALIDATOR_SUBTYPE_REQUIRED, VALIDATOR_SUBTYPE_LENGTH, FIELD_ATTR_MAX_LENGTH, FIELD_ATTR_REQUIRED, FIELD_ATTR_UNIQUE, FIELD_ATTR_DEFAULT, VALIDATOR_ATTR_MAX, } from "@metaobjectsdev/metadata";
|
|
3
|
+
import { FIELD_SUBTYPE_STRING, FIELD_SUBTYPE_INT, FIELD_SUBTYPE_LONG, FIELD_SUBTYPE_CURRENCY, FIELD_SUBTYPE_DOUBLE, FIELD_SUBTYPE_FLOAT, FIELD_SUBTYPE_DECIMAL, FIELD_SUBTYPE_BOOLEAN, FIELD_SUBTYPE_DATE, FIELD_SUBTYPE_TIME, FIELD_SUBTYPE_TIMESTAMP, FIELD_SUBTYPE_OBJECT, FIELD_SUBTYPE_CLASS, FIELD_SUBTYPE_ENUM, VALIDATOR_SUBTYPE_REQUIRED, VALIDATOR_SUBTYPE_LENGTH, FIELD_ATTR_MAX_LENGTH, FIELD_ATTR_REQUIRED, FIELD_ATTR_UNIQUE, FIELD_ATTR_DEFAULT, FIELD_ATTR_OBJECT_REF, VALIDATOR_ATTR_MAX, } from "@metaobjectsdev/metadata";
|
|
4
4
|
import { columnNameFromField } from "./naming.js";
|
|
5
5
|
import { enumValues } from "./enum-meta.js";
|
|
6
|
+
import { DEFAULT_COLUMN_NAMING_STRATEGY } from "@metaobjectsdev/metadata";
|
|
6
7
|
/**
|
|
7
8
|
* Patterns recognized as SQL expressions in a default value. Anything matching
|
|
8
9
|
* these is treated as a SQL expression, not a string literal. Mirrors
|
|
@@ -21,6 +22,35 @@ const SQL_EXPR_PATTERNS = [
|
|
|
21
22
|
function isSqlExprDefault(value) {
|
|
22
23
|
return SQL_EXPR_PATTERNS.some((re) => re.test(value));
|
|
23
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* For an isArray:true field stored in SQLite as text(...,{mode:"json"}), return
|
|
27
|
+
* the TS element type used in the emitted .$type<E[]>() chain. Returns undefined
|
|
28
|
+
* when the field's subType doesn't have a stable scalar TS mapping (e.g.,
|
|
29
|
+
* field.object — leave the inferred `unknown[]` so the consumer can layer a
|
|
30
|
+
* richer schema on top).
|
|
31
|
+
*/
|
|
32
|
+
function sqliteJsonArrayElementTsType(subType) {
|
|
33
|
+
switch (subType) {
|
|
34
|
+
case FIELD_SUBTYPE_STRING:
|
|
35
|
+
case FIELD_SUBTYPE_ENUM:
|
|
36
|
+
case FIELD_SUBTYPE_CLASS:
|
|
37
|
+
case FIELD_SUBTYPE_DATE:
|
|
38
|
+
case FIELD_SUBTYPE_TIME:
|
|
39
|
+
case FIELD_SUBTYPE_TIMESTAMP:
|
|
40
|
+
case FIELD_SUBTYPE_DECIMAL:
|
|
41
|
+
return "string";
|
|
42
|
+
case FIELD_SUBTYPE_INT:
|
|
43
|
+
case FIELD_SUBTYPE_LONG:
|
|
44
|
+
case FIELD_SUBTYPE_CURRENCY:
|
|
45
|
+
case FIELD_SUBTYPE_DOUBLE:
|
|
46
|
+
case FIELD_SUBTYPE_FLOAT:
|
|
47
|
+
return "number";
|
|
48
|
+
case FIELD_SUBTYPE_BOOLEAN:
|
|
49
|
+
return "boolean";
|
|
50
|
+
default:
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
24
54
|
/** Map a recognized SQL expression to its canonical raw form (uppercase keywords). */
|
|
25
55
|
function canonicalizeSqlExpr(value) {
|
|
26
56
|
const lower = value.toLowerCase();
|
|
@@ -55,7 +85,7 @@ function isRequired(field) {
|
|
|
55
85
|
return true;
|
|
56
86
|
return field.validators().some((child) => child.subType === VALIDATOR_SUBTYPE_REQUIRED);
|
|
57
87
|
}
|
|
58
|
-
export function mapColumnType(field, dialect, strategy =
|
|
88
|
+
export function mapColumnType(field, dialect, strategy = DEFAULT_COLUMN_NAMING_STRATEGY) {
|
|
59
89
|
const dbName = field.column ?? columnNameFromField(field.name, strategy);
|
|
60
90
|
const importModule = dialect === "sqlite" ? "drizzle-orm/sqlite-core" : "drizzle-orm/pg-core";
|
|
61
91
|
const subType = field.subType;
|
|
@@ -155,10 +185,32 @@ export function mapColumnType(field, dialect, strategy = "snake_case") {
|
|
|
155
185
|
break;
|
|
156
186
|
}
|
|
157
187
|
}
|
|
188
|
+
// Enum literal types: pass the values as `{ enum: [...] as const }` to
|
|
189
|
+
// Drizzle's text(...) so the inferred column type is a literal union
|
|
190
|
+
// ("a" | "b" | ...) instead of bare `string`. Skip when isArray — JSON
|
|
191
|
+
// arrays use { mode: "json" }, and the enum members go through Zod
|
|
192
|
+
// validation at the Insert/Update layer instead. Mirrors the Zod
|
|
193
|
+
// emission, which already uses z.enum([...]).
|
|
194
|
+
if (subType === FIELD_SUBTYPE_ENUM && !isArray && fnName === "text") {
|
|
195
|
+
const values = enumValues(field);
|
|
196
|
+
if (values !== undefined && values.length > 0) {
|
|
197
|
+
fnOptions = { ...(fnOptions ?? {}), enum: values };
|
|
198
|
+
}
|
|
199
|
+
}
|
|
158
200
|
const modifiers = [];
|
|
159
201
|
if (dialect === "postgres" && isArray) {
|
|
160
202
|
modifiers.push(".array()");
|
|
161
203
|
}
|
|
204
|
+
// SQLite stores arrays as JSON in a text column; Drizzle's text(...,{mode:"json"})
|
|
205
|
+
// infers the column as `unknown` without a $type<T>() annotation. Emit the
|
|
206
|
+
// chain via spec.dollarTypeRef so the renderer can hoist a type-only import
|
|
207
|
+
// for object refs (SourceLens[], Dissent[], etc.). Scalars (string/number/
|
|
208
|
+
// boolean) need no import. Postgres uses .array() above which is already
|
|
209
|
+
// element-typed by Drizzle.
|
|
210
|
+
// Determined ABOVE the modifiers chain so the renderer can position
|
|
211
|
+
// `.$type<>()` ahead of `.notNull()` etc.
|
|
212
|
+
// Note: dollarTypeRef is read alongside (and rendered ahead of) `modifiers`
|
|
213
|
+
// by `renderColumn` — see drizzle-schema.ts.
|
|
162
214
|
if (isRequired(field)) {
|
|
163
215
|
modifiers.push(".notNull()");
|
|
164
216
|
}
|
|
@@ -190,6 +242,23 @@ export function mapColumnType(field, dialect, strategy = "snake_case") {
|
|
|
190
242
|
defaultExpr = { kind: "literal", value: typedValue };
|
|
191
243
|
}
|
|
192
244
|
}
|
|
245
|
+
// SQLite isArray columns route through {mode:"json"} above; compute the
|
|
246
|
+
// $type<E[]>() target so the renderer can hoist any cross-module imports.
|
|
247
|
+
let dollarTypeRef;
|
|
248
|
+
if (dialect === "sqlite" && isArray) {
|
|
249
|
+
if (subType === FIELD_SUBTYPE_OBJECT) {
|
|
250
|
+
const ref = field.ownAttr(FIELD_ATTR_OBJECT_REF);
|
|
251
|
+
if (typeof ref === "string" && ref.length > 0) {
|
|
252
|
+
dollarTypeRef = { kind: "objectRef", name: ref, module: `./${ref}.js` };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
const scalar = sqliteJsonArrayElementTsType(subType);
|
|
257
|
+
if (scalar !== undefined) {
|
|
258
|
+
dollarTypeRef = { kind: "scalar", tsType: scalar };
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
193
262
|
const result = {
|
|
194
263
|
fnName,
|
|
195
264
|
dbName,
|
|
@@ -201,6 +270,8 @@ export function mapColumnType(field, dialect, strategy = "snake_case") {
|
|
|
201
270
|
result.fnOptions = fnOptions;
|
|
202
271
|
if (defaultExpr !== undefined)
|
|
203
272
|
result.defaultExpr = defaultExpr;
|
|
273
|
+
if (dollarTypeRef !== undefined)
|
|
274
|
+
result.dollarTypeRef = dollarTypeRef;
|
|
204
275
|
if (leadingComment !== undefined)
|
|
205
276
|
result.leadingComment = leadingComment;
|
|
206
277
|
// Enum fields: emit a CHECK constraint listing the valid member values.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-mapper.js","sourceRoot":"","sources":["../src/column-mapper.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,4GAA4G;AAG5G,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"column-mapper.js","sourceRoot":"","sources":["../src/column-mapper.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,4GAA4G;AAG5G,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,0BAA0B,EAC1B,wBAAwB,EACxB,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AA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,MAAM,EAAE,EAAE;QACV,SAAS;QACT,YAAY;KACb,CAAC;IACF,IAAI,SAAS,KAAK,SAAS;QAAE,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;IAC1D,IAAI,WAAW,KAAK,SAAS;QAAE,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;IAChE,IAAI,aAAa,KAAK,SAAS;QAAE,MAAM,CAAC,aAAa,GAAG,aAAa,CAAC;IACtE,IAAI,cAAc,KAAK,SAAS;QAAE,MAAM,CAAC,cAAc,GAAG,cAAc,CAAC;IAEzE,wEAAwE;IACxE,IAAI,OAAO,KAAK,kBAAkB,IAAI,CAAC,OAAO,EAAE,CAAC;QAC/C,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9C,6DAA6D;YAC7D,yEAAyE;YACzE,qEAAqE;YACrE,MAAM,IAAI,GAAG,MAAM;iBAChB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;iBACxC,IAAI,CAAC,IAAI,CAAC,CAAC;YACd,MAAM,CAAC,eAAe,GAAG,GAAG,MAAM,QAAQ,IAAI,GAAG,CAAC;QACpD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -3,6 +3,21 @@ import { type GeneratorFactory } from "../generator.js";
|
|
|
3
3
|
export interface EntityFileOpts {
|
|
4
4
|
filter?: (entity: MetaObject) => boolean;
|
|
5
5
|
target?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Whether generated entity files include the Fastify-flavored
|
|
8
|
+
* `<Entity>FilterAllowlist` + `<Entity>SortAllowlist` blocks (and the
|
|
9
|
+
* `@metaobjectsdev/runtime-ts/drizzle-fastify` type-only imports they
|
|
10
|
+
* require). Default `true` for back-compat.
|
|
11
|
+
*
|
|
12
|
+
* Set to `false` for Worker/Lambda-style consumers that don't mount
|
|
13
|
+
* Fastify-style server routes — the generated entity file then has no
|
|
14
|
+
* `runtime-ts/drizzle-fastify` imports at all and `@metaobjectsdev/runtime-ts`
|
|
15
|
+
* can be omitted from the consumer's dependency tree.
|
|
16
|
+
*
|
|
17
|
+
* The client-side `<Entity>Filter` type is always emitted — it's a pure
|
|
18
|
+
* client-side type with no runtime-ts dependency.
|
|
19
|
+
*/
|
|
20
|
+
allowlists?: boolean;
|
|
6
21
|
}
|
|
7
22
|
export declare const entityFile: GeneratorFactory<EntityFileOpts>;
|
|
8
23
|
//# sourceMappingURL=entity-file.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-file.d.ts","sourceRoot":"","sources":["../../src/generators/entity-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAA6B,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKnF,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"entity-file.d.ts","sourceRoot":"","sources":["../../src/generators/entity-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAA6B,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKnF,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,UAAU,EAsBlB,gBAAgB,CAAC,cAAc,CAAC,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { renderEntityFile } from "../templates/entity-file.js";
|
|
|
3
3
|
import { formatTs } from "../format.js";
|
|
4
4
|
import { entityOutputPath } from "../import-path.js";
|
|
5
5
|
export const entityFile = function entityFile(opts) {
|
|
6
|
+
const allowlists = opts?.allowlists ?? true;
|
|
6
7
|
const generator = {
|
|
7
8
|
name: "entity-file",
|
|
8
9
|
emitsEntityModule: true,
|
|
@@ -12,7 +13,7 @@ export const entityFile = function entityFile(opts) {
|
|
|
12
13
|
}
|
|
13
14
|
return {
|
|
14
15
|
path: entityOutputPath(ctx.config.outputLayout ?? "flat", entity.package, `${entity.name}.ts`),
|
|
15
|
-
content: await formatTs(renderEntityFile(entity, ctx.renderContext)),
|
|
16
|
+
content: await formatTs(renderEntityFile(entity, ctx.renderContext, { allowlists })),
|
|
16
17
|
};
|
|
17
18
|
}),
|
|
18
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-file.js","sourceRoot":"","sources":["../../src/generators/entity-file.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAyC,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"entity-file.js","sourceRoot":"","sources":["../../src/generators/entity-file.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAyC,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAsBrD,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,UAAU,CAAC,IAAqB;IACjE,MAAM,UAAU,GAAG,IAAI,EAAE,UAAU,IAAI,IAAI,CAAC;IAC5C,MAAM,SAAS,GAAc;QAC3B,IAAI,EAAE,aAAa;QACnB,iBAAiB,EAAE,IAAI;QACvB,QAAQ,EAAE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE;YACxC,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;gBACvB,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;YACjF,CAAC;YACD,OAAO;gBACL,IAAI,EAAE,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,IAAI,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,IAAI,KAAK,CAAC;gBAC9F,OAAO,EAAE,MAAM,QAAQ,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,CAAC,aAAa,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;aACrF,CAAC;QACJ,CAAC,CAAC;KACH,CAAC;IACF,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC;QACjB,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IACD,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC;QACjB,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAqC,CAAC"}
|
|
@@ -3,4 +3,6 @@ export { queriesFile, type QueriesFileOpts } from "./queries-file.js";
|
|
|
3
3
|
export { routesFile, type RoutesFileOpts } from "./routes-file.js";
|
|
4
4
|
export { barrel, type BarrelOpts } from "./barrel.js";
|
|
5
5
|
export { mermaidErDiagram, type MermaidErOptions } from "./mermaid-er.js";
|
|
6
|
+
export { promptRender, type PromptRenderOpts } from "./prompt-render-file.js";
|
|
7
|
+
export { outputParser, type OutputParserOpts } from "./output-parser-file.js";
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/generators/index.js
CHANGED
|
@@ -3,4 +3,6 @@ export { queriesFile } from "./queries-file.js";
|
|
|
3
3
|
export { routesFile } from "./routes-file.js";
|
|
4
4
|
export { barrel } from "./barrel.js";
|
|
5
5
|
export { mermaidErDiagram } from "./mermaid-er.js";
|
|
6
|
+
export { promptRender } from "./prompt-render-file.js";
|
|
7
|
+
export { outputParser } from "./output-parser-file.js";
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAuB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAwB,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAuB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAmB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAyB,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAuB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAwB,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAuB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAmB,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAyB,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAyB,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAyB,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type GeneratorFactory } from "../generator.js";
|
|
2
|
+
export interface OutputParserOpts {
|
|
3
|
+
/** Output directory prefix relative to the target's outDir. Default: "" (root). */
|
|
4
|
+
outDir?: string;
|
|
5
|
+
/** Optional named output target (registry key). Defaults to "default". */
|
|
6
|
+
target?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const outputParser: GeneratorFactory<OutputParserOpts>;
|
|
9
|
+
//# sourceMappingURL=output-parser-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-parser-file.d.ts","sourceRoot":"","sources":["../../src/generators/output-parser-file.ts"],"names":[],"mappings":"AAYA,OAAO,EAGL,KAAK,gBAAgB,EAEtB,MAAM,iBAAiB,CAAC;AAGzB,MAAM,WAAW,gBAAgB;IAC/B,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,YAAY,EAsBpB,gBAAgB,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// server/typescript/packages/codegen-ts/src/generators/output-parser-file.ts
|
|
2
|
+
//
|
|
3
|
+
// Stock generator that emits one <TemplateName>.output.ts file per declared
|
|
4
|
+
// template.output node. Wraps renderOutputParser() from templates/output-parser.ts.
|
|
5
|
+
//
|
|
6
|
+
// Consumer wiring (metaobjects.config.ts):
|
|
7
|
+
// generators: [..., promptRender(), outputParser()]
|
|
8
|
+
//
|
|
9
|
+
// Custom output directory:
|
|
10
|
+
// generators: [..., outputParser({ outDir: "src/generated/outputs" })]
|
|
11
|
+
import { TYPE_TEMPLATE, TEMPLATE_SUBTYPE_OUTPUT } from "@metaobjectsdev/metadata";
|
|
12
|
+
import { oncePerRun, } from "../generator.js";
|
|
13
|
+
import { renderOutputParser } from "../templates/output-parser.js";
|
|
14
|
+
export const outputParser = function outputParser(opts) {
|
|
15
|
+
const dirPrefix = opts?.outDir ? `${opts.outDir.replace(/\/$/, "")}/` : "";
|
|
16
|
+
const generator = {
|
|
17
|
+
name: "output-parser",
|
|
18
|
+
generate: oncePerRun((_entities, ctx) => {
|
|
19
|
+
const outputs = ctx.loadedRoot
|
|
20
|
+
.ownChildren()
|
|
21
|
+
.filter((c) => c.type === TYPE_TEMPLATE && c.subType === TEMPLATE_SUBTYPE_OUTPUT);
|
|
22
|
+
const files = [];
|
|
23
|
+
for (const t of outputs) {
|
|
24
|
+
files.push({
|
|
25
|
+
path: `${dirPrefix}${t.name}.output.ts`,
|
|
26
|
+
content: renderOutputParser(ctx.loadedRoot, t.name),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return files;
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
if (opts?.target) {
|
|
33
|
+
generator.target = opts.target;
|
|
34
|
+
}
|
|
35
|
+
return generator;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=output-parser-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-parser-file.js","sourceRoot":"","sources":["../../src/generators/output-parser-file.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,EAAE;AACF,4EAA4E;AAC5E,oFAAoF;AACpF,EAAE;AACF,2CAA2C;AAC3C,sDAAsD;AACtD,EAAE;AACF,2BAA2B;AAC3B,yEAAyE;AAEzE,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAClF,OAAO,EAIL,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AASnE,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,YAAY,CAAC,IAAuB;IACvE,MAAM,SAAS,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3E,MAAM,SAAS,GAAc;QAC3B,IAAI,EAAE,eAAe;QACrB,QAAQ,EAAE,UAAU,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE;YACtC,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU;iBAC3B,WAAW,EAAE;iBACb,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,IAAI,CAAC,CAAC,OAAO,KAAK,uBAAuB,CAAC,CAAC;YACpF,MAAM,KAAK,GAAkB,EAAE,CAAC;YAChC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;gBACxB,KAAK,CAAC,IAAI,CAAC;oBACT,IAAI,EAAE,GAAG,SAAS,GAAG,CAAC,CAAC,IAAI,YAAY;oBACvC,OAAO,EAAE,kBAAkB,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC;iBACpD,CAAC,CAAC;YACL,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;KACH,CAAC;IACF,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC;QACjB,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAuC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type GeneratorFactory } from "../generator.js";
|
|
2
|
+
export interface PromptRenderOpts {
|
|
3
|
+
/** Output file path relative to the target's outDir. Default: "prompts.ts". */
|
|
4
|
+
outFile?: string;
|
|
5
|
+
/** Optional named output target (registry key). Defaults to "default". */
|
|
6
|
+
target?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const promptRender: GeneratorFactory<PromptRenderOpts>;
|
|
9
|
+
//# sourceMappingURL=prompt-render-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-render-file.d.ts","sourceRoot":"","sources":["../../src/generators/prompt-render-file.ts"],"names":[],"mappings":"AAYA,OAAO,EAEL,KAAK,gBAAgB,EAEtB,MAAM,iBAAiB,CAAC;AAOzB,MAAM,WAAW,gBAAgB;IAC/B,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAaD,eAAO,MAAM,YAAY,EAqDpB,gBAAgB,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Stock generator that wraps generatePayloadInterfaces() + generateRenderHandle()
|
|
2
|
+
// from payload-codegen.ts into a Generator factory. Emits ONE file aggregating
|
|
3
|
+
// typed payload interfaces (for object.value entities) and render handles (for
|
|
4
|
+
// template.prompt nodes).
|
|
5
|
+
//
|
|
6
|
+
// Consumer wiring (metaobjects.config.ts):
|
|
7
|
+
// generators: [..., promptRender()]
|
|
8
|
+
//
|
|
9
|
+
// Custom output path:
|
|
10
|
+
// generators: [..., promptRender({ outFile: "src/render/generated/prompts.ts" })]
|
|
11
|
+
import { TYPE_TEMPLATE, TEMPLATE_SUBTYPE_PROMPT, OBJECT_SUBTYPE_VALUE } from "@metaobjectsdev/metadata";
|
|
12
|
+
import { oncePerRun, } from "../generator.js";
|
|
13
|
+
import { generatePayloadInterfacesBatch, generateRenderHandle, } from "../payload-codegen.js";
|
|
14
|
+
import { GENERATED_HEADER } from "../constants.js";
|
|
15
|
+
// Hoisted into the emitted file once. generateRenderHandle() emits this line
|
|
16
|
+
// per-handle (for the standalone scenario); we strip its per-handle copies.
|
|
17
|
+
const RENDER_IMPORT = `import { render, type Provider } from "@metaobjectsdev/render";`;
|
|
18
|
+
// Matches the `import type { ... } from "./payloads.js";` that generateRenderHandle
|
|
19
|
+
// emits for the standalone two-file scenario. In the single-file output here the
|
|
20
|
+
// payload interfaces are already defined above, so the import is dead.
|
|
21
|
+
function isStandalonePayloadImport(line) {
|
|
22
|
+
return line.startsWith("import type {") && line.includes('"./payloads.js"');
|
|
23
|
+
}
|
|
24
|
+
export const promptRender = function promptRender(opts) {
|
|
25
|
+
const outFile = opts?.outFile ?? "prompts.ts";
|
|
26
|
+
const generator = {
|
|
27
|
+
name: "prompt-render",
|
|
28
|
+
generate: oncePerRun((entities, ctx) => {
|
|
29
|
+
const payloads = entities.filter((e) => e.subType === OBJECT_SUBTYPE_VALUE);
|
|
30
|
+
const prompts = ctx.loadedRoot
|
|
31
|
+
.ownChildren()
|
|
32
|
+
.filter((c) => c.type === TYPE_TEMPLATE && c.subType === TEMPLATE_SUBTYPE_PROMPT);
|
|
33
|
+
if (payloads.length === 0 && prompts.length === 0) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const parts = [`// ${GENERATED_HEADER} — DO NOT EDIT.`];
|
|
37
|
+
// Hoist the @metaobjectsdev/render import once (only when prompts emit handles).
|
|
38
|
+
if (prompts.length > 0) {
|
|
39
|
+
parts.push(RENDER_IMPORT);
|
|
40
|
+
}
|
|
41
|
+
// Emit payload interfaces with a single shared dedupe set so a lens
|
|
42
|
+
// referenced by multiple payloads appears exactly once.
|
|
43
|
+
const payloadInterfaces = generatePayloadInterfacesBatch(ctx.loadedRoot, payloads.map((p) => p.name));
|
|
44
|
+
if (payloadInterfaces.length > 0) {
|
|
45
|
+
parts.push(payloadInterfaces);
|
|
46
|
+
}
|
|
47
|
+
// Append each render handle with its per-handle imports stripped — both
|
|
48
|
+
// the now-hoisted render/Provider import and the standalone payloads.js
|
|
49
|
+
// import. Also drop any leading blank lines left behind by the strip so
|
|
50
|
+
// the joined output doesn't accumulate double blank gaps between parts.
|
|
51
|
+
for (const t of prompts) {
|
|
52
|
+
const lines = generateRenderHandle(ctx.loadedRoot, t.name)
|
|
53
|
+
.split("\n")
|
|
54
|
+
.filter((line) => line !== RENDER_IMPORT && !isStandalonePayloadImport(line));
|
|
55
|
+
while (lines.length > 0 && lines[0].trim() === "")
|
|
56
|
+
lines.shift();
|
|
57
|
+
parts.push(lines.join("\n"));
|
|
58
|
+
}
|
|
59
|
+
return [{
|
|
60
|
+
path: outFile,
|
|
61
|
+
content: parts.filter((s) => s.length > 0).map((s) => s.trimEnd()).join("\n\n") + "\n",
|
|
62
|
+
}];
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
if (opts?.target) {
|
|
66
|
+
generator.target = opts.target;
|
|
67
|
+
}
|
|
68
|
+
return generator;
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=prompt-render-file.js.map
|
|
@@ -0,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AAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAC/B,CAAC;YAED,OAAO,CAAC;oBACN,IAAI,EAAE,OAAO;oBACb,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI;iBACvF,CAAC,CAAC;QACL,CAAC,CAAC;KACH,CAAC;IACF,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC;QACjB,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAuC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries-file.d.ts","sourceRoot":"","sources":["../../src/generators/queries-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"queries-file.d.ts","sourceRoot":"","sources":["../../src/generators/queries-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAA6B,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKnF,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAQD,eAAO,MAAM,WAAW,EAuBnB,gBAAgB,CAAC,eAAe,CAAC,CAAC"}
|