@metaobjectsdev/codegen-ts 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/column-mapper.d.ts.map +1 -1
- package/dist/column-mapper.js +24 -8
- package/dist/column-mapper.js.map +1 -1
- package/dist/constants.d.ts +8 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +16 -0
- package/dist/constants.js.map +1 -1
- package/dist/docs-paths.d.ts +58 -0
- package/dist/docs-paths.d.ts.map +1 -0
- package/dist/docs-paths.js +89 -0
- package/dist/docs-paths.js.map +1 -0
- package/dist/enum-import.d.ts +14 -0
- package/dist/enum-import.d.ts.map +1 -0
- package/dist/enum-import.js +35 -0
- package/dist/enum-import.js.map +1 -0
- package/dist/enum-shared.d.ts +32 -0
- package/dist/enum-shared.d.ts.map +1 -0
- package/dist/enum-shared.js +83 -0
- package/dist/enum-shared.js.map +1 -0
- package/dist/generator-registry.d.ts +22 -0
- package/dist/generator-registry.d.ts.map +1 -0
- package/dist/generator-registry.js +161 -0
- package/dist/generator-registry.js.map +1 -0
- package/dist/generator.d.ts +6 -0
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js.map +1 -1
- package/dist/generators/api-doc-render.d.ts +17 -0
- package/dist/generators/api-doc-render.d.ts.map +1 -0
- package/dist/generators/api-doc-render.js +431 -0
- package/dist/generators/api-doc-render.js.map +1 -0
- package/dist/generators/api-docs-file.d.ts +21 -0
- package/dist/generators/api-docs-file.d.ts.map +1 -0
- package/dist/generators/api-docs-file.js +112 -0
- package/dist/generators/api-docs-file.js.map +1 -0
- package/dist/generators/api-field-shape.d.ts +39 -0
- package/dist/generators/api-field-shape.d.ts.map +1 -0
- package/dist/generators/api-field-shape.js +92 -0
- package/dist/generators/api-field-shape.js.map +1 -0
- package/dist/generators/api-label.d.ts +3 -0
- package/dist/generators/api-label.d.ts.map +1 -0
- package/dist/generators/api-label.js +8 -0
- package/dist/generators/api-label.js.map +1 -0
- package/dist/generators/api-model.d.ts +122 -0
- package/dist/generators/api-model.d.ts.map +1 -0
- package/dist/generators/api-model.js +809 -0
- package/dist/generators/api-model.js.map +1 -0
- package/dist/generators/docs-data-builder.d.ts +26 -4
- package/dist/generators/docs-data-builder.d.ts.map +1 -1
- package/dist/generators/docs-data-builder.js +436 -164
- package/dist/generators/docs-data-builder.js.map +1 -1
- package/dist/generators/docs-data.d.ts +136 -27
- package/dist/generators/docs-data.d.ts.map +1 -1
- package/dist/generators/docs-data.js +1 -1
- package/dist/generators/docs-data.js.map +1 -1
- package/dist/generators/docs-file.d.ts +19 -0
- package/dist/generators/docs-file.d.ts.map +1 -1
- package/dist/generators/docs-file.js +154 -27
- package/dist/generators/docs-file.js.map +1 -1
- package/dist/generators/entity-file.d.ts.map +1 -1
- package/dist/generators/entity-file.js +29 -14
- package/dist/generators/entity-file.js.map +1 -1
- package/dist/generators/extractor-file.d.ts.map +1 -1
- package/dist/generators/extractor-file.js +2 -1
- package/dist/generators/extractor-file.js.map +1 -1
- package/dist/generators/field-anchor.d.ts +7 -0
- package/dist/generators/field-anchor.d.ts.map +1 -0
- package/dist/generators/field-anchor.js +23 -0
- package/dist/generators/field-anchor.js.map +1 -0
- package/dist/generators/index.d.ts +8 -1
- package/dist/generators/index.d.ts.map +1 -1
- package/dist/generators/index.js +6 -0
- package/dist/generators/index.js.map +1 -1
- package/dist/generators/mermaid-er.d.ts +14 -0
- package/dist/generators/mermaid-er.d.ts.map +1 -1
- package/dist/generators/mermaid-er.js +14 -0
- package/dist/generators/mermaid-er.js.map +1 -1
- package/dist/generators/output-parser-file.d.ts.map +1 -1
- package/dist/generators/output-parser-file.js +3 -4
- package/dist/generators/output-parser-file.js.map +1 -1
- package/dist/generators/output-prompt-file.d.ts.map +1 -1
- package/dist/generators/output-prompt-file.js +2 -2
- package/dist/generators/output-prompt-file.js.map +1 -1
- package/dist/generators/prompt-render-file.d.ts.map +1 -1
- package/dist/generators/prompt-render-file.js +3 -4
- package/dist/generators/prompt-render-file.js.map +1 -1
- package/dist/generators/queries-file.d.ts.map +1 -1
- package/dist/generators/queries-file.js +8 -3
- package/dist/generators/queries-file.js.map +1 -1
- package/dist/generators/render-helper-file.d.ts.map +1 -1
- package/dist/generators/render-helper-file.js +2 -2
- package/dist/generators/render-helper-file.js.map +1 -1
- package/dist/generators/routes-file-hono.d.ts.map +1 -1
- package/dist/generators/routes-file-hono.js +5 -1
- package/dist/generators/routes-file-hono.js.map +1 -1
- package/dist/generators/routes-file.d.ts +3 -0
- package/dist/generators/routes-file.d.ts.map +1 -1
- package/dist/generators/routes-file.js +6 -1
- package/dist/generators/routes-file.js.map +1 -1
- package/dist/generators/template-doc-builder.d.ts +19 -0
- package/dist/generators/template-doc-builder.d.ts.map +1 -0
- package/dist/generators/template-doc-builder.js +220 -0
- package/dist/generators/template-doc-builder.js.map +1 -0
- package/dist/generators/template-doc-data.d.ts +62 -0
- package/dist/generators/template-doc-data.d.ts.map +1 -0
- package/dist/generators/template-doc-data.js +16 -0
- package/dist/generators/template-doc-data.js.map +1 -0
- package/dist/generators/template-payload-tree.d.ts +15 -0
- package/dist/generators/template-payload-tree.d.ts.map +1 -0
- package/dist/generators/template-payload-tree.js +61 -0
- package/dist/generators/template-payload-tree.js.map +1 -0
- package/dist/generators/template-source-annotate.d.ts +74 -0
- package/dist/generators/template-source-annotate.d.ts.map +1 -0
- package/dist/generators/template-source-annotate.js +184 -0
- package/dist/generators/template-source-annotate.js.map +1 -0
- package/dist/generators/template-source-render.d.ts +24 -0
- package/dist/generators/template-source-render.d.ts.map +1 -0
- package/dist/generators/template-source-render.js +175 -0
- package/dist/generators/template-source-render.js.map +1 -0
- package/dist/generators/trace-helper-file.d.ts +9 -0
- package/dist/generators/trace-helper-file.d.ts.map +1 -0
- package/dist/generators/trace-helper-file.js +196 -0
- package/dist/generators/trace-helper-file.js.map +1 -0
- package/dist/index.d.ts +29 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -2
- package/dist/index.js.map +1 -1
- package/dist/metaobjects-config.d.ts +75 -2
- package/dist/metaobjects-config.d.ts.map +1 -1
- package/dist/metaobjects-config.js +43 -0
- package/dist/metaobjects-config.js.map +1 -1
- package/dist/naming.d.ts +19 -0
- package/dist/naming.d.ts.map +1 -1
- package/dist/naming.js +41 -0
- package/dist/naming.js.map +1 -1
- package/dist/payload-codegen.d.ts.map +1 -1
- package/dist/payload-codegen.js +12 -4
- package/dist/payload-codegen.js.map +1 -1
- package/dist/projection/extract-view-spec.d.ts.map +1 -1
- package/dist/projection/extract-view-spec.js +51 -25
- package/dist/projection/extract-view-spec.js.map +1 -1
- package/dist/relation-resolver.d.ts +16 -0
- package/dist/relation-resolver.d.ts.map +1 -1
- package/dist/relation-resolver.js +82 -1
- package/dist/relation-resolver.js.map +1 -1
- package/dist/render-context.d.ts +4 -0
- package/dist/render-context.d.ts.map +1 -1
- package/dist/render-context.js.map +1 -1
- package/dist/render-engine/embedded-templates.generated.d.ts +2 -0
- package/dist/render-engine/embedded-templates.generated.d.ts.map +1 -0
- package/dist/render-engine/embedded-templates.generated.js +15 -0
- package/dist/render-engine/embedded-templates.generated.js.map +1 -0
- package/dist/render-engine/framework-provider.d.ts.map +1 -1
- package/dist/render-engine/framework-provider.js +26 -13
- package/dist/render-engine/framework-provider.js.map +1 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +17 -0
- package/dist/runner.js.map +1 -1
- package/dist/templates/docs-file.d.ts +2 -6
- package/dist/templates/docs-file.d.ts.map +1 -1
- package/dist/templates/docs-file.js +2 -5
- package/dist/templates/docs-file.js.map +1 -1
- package/dist/templates/drizzle-schema.d.ts.map +1 -1
- package/dist/templates/drizzle-schema.js +30 -2
- package/dist/templates/drizzle-schema.js.map +1 -1
- package/dist/templates/entity-constants.d.ts +7 -0
- package/dist/templates/entity-constants.d.ts.map +1 -1
- package/dist/templates/entity-constants.js +1 -1
- package/dist/templates/entity-constants.js.map +1 -1
- package/dist/templates/entity-file.d.ts.map +1 -1
- package/dist/templates/entity-file.js +16 -5
- package/dist/templates/entity-file.js.map +1 -1
- package/dist/templates/enums-file.d.ts +11 -0
- package/dist/templates/enums-file.d.ts.map +1 -0
- package/dist/templates/enums-file.js +44 -0
- package/dist/templates/enums-file.js.map +1 -0
- package/dist/templates/extract-delegate-emitter.d.ts.map +1 -1
- package/dist/templates/extract-delegate-emitter.js +5 -7
- package/dist/templates/extract-delegate-emitter.js.map +1 -1
- package/dist/templates/extract-schema-emitter.d.ts.map +1 -1
- package/dist/templates/extract-schema-emitter.js +5 -1
- package/dist/templates/extract-schema-emitter.js.map +1 -1
- package/dist/templates/extractor.d.ts.map +1 -1
- package/dist/templates/extractor.js +56 -39
- package/dist/templates/extractor.js.map +1 -1
- package/dist/templates/field-meta.d.ts.map +1 -1
- package/dist/templates/field-meta.js +1 -5
- package/dist/templates/field-meta.js.map +1 -1
- package/dist/templates/filter-allowlist.d.ts +7 -2
- package/dist/templates/filter-allowlist.d.ts.map +1 -1
- package/dist/templates/filter-allowlist.js +17 -9
- package/dist/templates/filter-allowlist.js.map +1 -1
- package/dist/templates/filter-type.d.ts +7 -1
- package/dist/templates/filter-type.d.ts.map +1 -1
- package/dist/templates/filter-type.js +9 -5
- package/dist/templates/filter-type.js.map +1 -1
- package/dist/templates/find-templates.d.ts +4 -0
- package/dist/templates/find-templates.d.ts.map +1 -0
- package/dist/templates/find-templates.js +15 -0
- package/dist/templates/find-templates.js.map +1 -0
- package/dist/templates/fr010-field-mapping.d.ts +2 -0
- package/dist/templates/fr010-field-mapping.d.ts.map +1 -1
- package/dist/templates/fr010-field-mapping.js +10 -6
- package/dist/templates/fr010-field-mapping.js.map +1 -1
- package/dist/templates/inferred-types.d.ts +44 -7
- package/dist/templates/inferred-types.d.ts.map +1 -1
- package/dist/templates/inferred-types.js +107 -16
- package/dist/templates/inferred-types.js.map +1 -1
- package/dist/templates/mermaid-er.d.ts +35 -2
- package/dist/templates/mermaid-er.d.ts.map +1 -1
- package/dist/templates/mermaid-er.js +174 -7
- package/dist/templates/mermaid-er.js.map +1 -1
- package/dist/templates/output-parser.d.ts.map +1 -1
- package/dist/templates/output-parser.js +30 -79
- package/dist/templates/output-parser.js.map +1 -1
- package/dist/templates/output-prompt.d.ts.map +1 -1
- package/dist/templates/output-prompt.js +2 -2
- package/dist/templates/output-prompt.js.map +1 -1
- package/dist/templates/queries-file.d.ts.map +1 -1
- package/dist/templates/queries-file.js +112 -4
- package/dist/templates/queries-file.js.map +1 -1
- package/dist/templates/queries.d.ts +5 -0
- package/dist/templates/queries.d.ts.map +1 -1
- package/dist/templates/queries.js +7 -7
- package/dist/templates/queries.js.map +1 -1
- package/dist/templates/recover-schema-emitter.d.ts +8 -0
- package/dist/templates/recover-schema-emitter.d.ts.map +1 -0
- package/dist/templates/recover-schema-emitter.js +64 -0
- package/dist/templates/recover-schema-emitter.js.map +1 -0
- package/dist/templates/relations-block.js +10 -0
- package/dist/templates/relations-block.js.map +1 -1
- package/dist/templates/render-helper.d.ts.map +1 -1
- package/dist/templates/render-helper.js +4 -4
- package/dist/templates/render-helper.js.map +1 -1
- package/dist/templates/routes-file.d.ts.map +1 -1
- package/dist/templates/routes-file.js +183 -6
- package/dist/templates/routes-file.js.map +1 -1
- package/dist/templates/tph-discriminator.d.ts +56 -0
- package/dist/templates/tph-discriminator.d.ts.map +1 -0
- package/dist/templates/tph-discriminator.js +180 -0
- package/dist/templates/tph-discriminator.js.map +1 -0
- package/dist/templates/value-object-file.d.ts +2 -1
- package/dist/templates/value-object-file.d.ts.map +1 -1
- package/dist/templates/value-object-file.js +32 -4
- package/dist/templates/value-object-file.js.map +1 -1
- package/dist/templates/zod-validators.d.ts +64 -1
- package/dist/templates/zod-validators.d.ts.map +1 -1
- package/dist/templates/zod-validators.js +181 -8
- package/dist/templates/zod-validators.js.map +1 -1
- package/package.json +103 -34
- package/src/column-mapper.ts +25 -8
- package/src/constants.ts +18 -0
- package/src/docs-paths.ts +128 -0
- package/src/enum-import.ts +43 -0
- package/src/enum-shared.ts +95 -0
- package/src/generator-registry.ts +204 -0
- package/src/generator.ts +6 -0
- package/src/generators/api-doc-render.ts +572 -0
- package/src/generators/api-docs-file.ts +146 -0
- package/src/generators/api-field-shape.ts +114 -0
- package/src/generators/api-label.ts +7 -0
- package/src/generators/api-model.ts +1067 -0
- package/src/generators/docs-data-builder.ts +479 -185
- package/src/generators/docs-data.ts +139 -28
- package/src/generators/docs-file.ts +205 -39
- package/src/generators/entity-file.ts +31 -15
- package/src/generators/extractor-file.ts +2 -1
- package/src/generators/field-anchor.ts +24 -0
- package/src/generators/index.ts +8 -1
- package/src/generators/mermaid-er.ts +14 -0
- package/src/generators/output-parser-file.ts +3 -4
- package/src/generators/output-prompt-file.ts +2 -1
- package/src/generators/prompt-render-file.ts +3 -4
- package/src/generators/queries-file.ts +9 -3
- package/src/generators/render-helper-file.ts +2 -1
- package/src/generators/routes-file-hono.ts +5 -1
- package/src/generators/routes-file.ts +7 -1
- package/src/generators/template-doc-builder.ts +306 -0
- package/src/generators/template-doc-data.ts +85 -0
- package/src/generators/template-payload-tree.ts +71 -0
- package/src/generators/template-source-annotate.ts +290 -0
- package/src/generators/template-source-render.ts +203 -0
- package/src/generators/trace-helper-file.ts +301 -0
- package/src/index.ts +55 -4
- package/src/metaobjects-config.ts +117 -2
- package/src/naming.ts +48 -0
- package/src/payload-codegen.ts +14 -3
- package/src/projection/extract-view-spec.ts +49 -30
- package/src/relation-resolver.ts +103 -1
- package/src/render-context.ts +4 -0
- package/src/render-engine/embedded-templates.generated.ts +14 -0
- package/src/render-engine/framework-provider.ts +25 -11
- package/src/runner.ts +21 -0
- package/src/templates/docs-file.ts +2 -9
- package/src/templates/drizzle-schema.ts +31 -1
- package/src/templates/entity-constants.ts +1 -1
- package/src/templates/entity-file.ts +16 -5
- package/src/templates/enums-file.ts +50 -0
- package/src/templates/extract-delegate-emitter.ts +5 -6
- package/src/templates/extractor.ts +68 -38
- package/src/templates/field-meta.ts +0 -6
- package/src/templates/filter-allowlist.ts +17 -10
- package/src/templates/filter-type.ts +8 -6
- package/src/templates/find-templates.ts +15 -0
- package/src/templates/fr010-field-mapping.ts +10 -8
- package/src/templates/inferred-types.ts +108 -18
- package/src/templates/mermaid-er.ts +176 -8
- package/src/templates/output-parser.ts +30 -79
- package/src/templates/output-prompt.ts +2 -1
- package/src/templates/queries-file.ts +132 -3
- package/src/templates/queries.ts +15 -7
- package/src/templates/relations-block.ts +17 -0
- package/src/templates/render-helper.ts +4 -3
- package/src/templates/routes-file.ts +233 -6
- package/src/templates/tph-discriminator.ts +232 -0
- package/src/templates/value-object-file.ts +38 -4
- package/src/templates/zod-validators.ts +204 -7
- package/templates/api/agent-api.md.mustache +30 -0
- package/templates/api/entity-api.md.mustache +69 -0
- package/templates/api/index.md.mustache +21 -0
- package/templates/docs/entity-page.md.mustache +33 -21
- package/templates/docs/template-page.md.mustache +56 -0
- package/src/templates/extract-schema-emitter.ts +0 -111
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Per-template renderer for template.output codegen. Walks the @payloadRef's
|
|
4
4
|
// value-object into a Zod schema and emits a dual-API parser (parse + safeParse)
|
|
5
|
-
// alongside the schema
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import { extractMapHelpersUsed } from "./fr010-field-mapping.js";
|
|
5
|
+
// alongside the schema, plus (for json/xml outputs) a single tolerant
|
|
6
|
+
// loader-delegating `extractLenient<Name>WithLoader(root, text)` that delegates to
|
|
7
|
+
// the metadata-driven runtime extract. The emitted file derives a local data type
|
|
8
|
+
// via `z.infer<typeof Schema>` and exports it as `<TemplateName>Data`. Consumers
|
|
9
|
+
// wiring `promptRender()` get a structurally identical payload-VO interface in
|
|
10
|
+
// `prompts.ts`; either type can be used interchangeably with parse results.
|
|
11
|
+
import { TYPE_OBJECT, TYPE_FIELD, TYPE_TEMPLATE, TEMPLATE_SUBTYPE_OUTPUT, FIELD_SUBTYPE_OBJECT, FIELD_ATTR_OBJECT_REF, TEMPLATE_ATTR_PAYLOAD_REF, TEMPLATE_ATTR_FORMAT, refMatchesObject, } from "@metaobjectsdev/metadata";
|
|
13
12
|
import { nestedMirrorInterfaces, nestedMappers, rootMapperName, delegateHelpers, usedHelpers, hasNested, } from "./extract-delegate-emitter.js";
|
|
14
13
|
const SCALAR_ZOD = {
|
|
15
14
|
string: "z.string()",
|
|
@@ -23,7 +22,9 @@ const SCALAR_ZOD = {
|
|
|
23
22
|
boolean: "z.boolean()",
|
|
24
23
|
};
|
|
25
24
|
function findObject(root, name) {
|
|
26
|
-
|
|
25
|
+
// FR-032 — @payloadRef is FQN after the desugar/sweep; match on the effective
|
|
26
|
+
// FQN resolution key (with bare back-compat).
|
|
27
|
+
return root.ownChildren().find((c) => c.type === TYPE_OBJECT && refMatchesObject(c, name));
|
|
27
28
|
}
|
|
28
29
|
function findTemplate(root, name) {
|
|
29
30
|
return root.ownChildren().find((c) => c.type === TYPE_TEMPLATE && c.name === name);
|
|
@@ -137,95 +138,49 @@ export function ${safeParseName}(
|
|
|
137
138
|
}
|
|
138
139
|
// ---- FR-010 tolerant extract block (json/xml only) ----
|
|
139
140
|
const extractedName = `${templateName}Extracted`;
|
|
140
|
-
const extractLenientFnName = `extractLenient${templateName}`;
|
|
141
|
-
const tryExtractLenientName = `tryExtractLenient${templateName}`;
|
|
142
141
|
const extractLenientWithName = `extractLenient${templateName}WithLoader`;
|
|
143
|
-
const schemaConstName = `${templateName}ExtractSchema`;
|
|
144
142
|
const payloadFqnConst = `${templateName.toUpperCase()}_PAYLOAD_NAME`;
|
|
145
143
|
const formatEnum = format.toLowerCase() === "xml" ? "Format.XML" : "Format.JSON";
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
// The
|
|
150
|
-
// payload mirror's nested-object / array-of-object components are typed (not `unknown`), and
|
|
151
|
-
// so a mirror interface is emitted for every reachable nested value-object. The payload mirror
|
|
152
|
-
// keeps the canonical `<Template>Extracted` name (instead of `<PayloadVO>Extracted`) so the
|
|
153
|
-
// existing self-contained extract<Name>() initializer continues to satisfy it.
|
|
144
|
+
// The nullable mirror is the return shape of the delegating extract. Use the nested-aware
|
|
145
|
+
// emitter so the payload mirror's nested-object / array-of-object components are typed (not
|
|
146
|
+
// `unknown`), and so a mirror interface is emitted for every reachable nested value-object.
|
|
147
|
+
// The payload mirror keeps the canonical `<Template>Extracted` name.
|
|
154
148
|
const mirrorDecls = nestedMirrorInterfaces(vo, root, extractedName);
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (schemaLit.includes("scalar("))
|
|
160
|
-
renderImports.push("scalar");
|
|
161
|
-
if (schemaLit.includes("enumField("))
|
|
162
|
-
renderImports.push("enumField");
|
|
163
|
-
if (schemaLit.includes("FieldKind."))
|
|
164
|
-
renderImports.push("FieldKind");
|
|
165
|
-
renderImports.push("type ExtractSchema", "type ExtractOptions", "type ExtractionResult");
|
|
166
|
-
renderImports.push(...mapHelpers);
|
|
167
|
-
const selfContained = `/** Baked extract descriptor for the ${templateName} output. */
|
|
168
|
-
const ${schemaConstName}: ExtractSchema = ${schemaLit};
|
|
169
|
-
|
|
170
|
-
${mirrorDecls}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Self-contained tolerant best-effort extraction of a dirty LLM response; never throws.
|
|
174
|
-
* Returns a nullable mirror (\`${extractedName}\`) with fields null where lost/malformed,
|
|
175
|
-
* plus the per-field extraction report. Does NOT populate nested-object / array-of-object
|
|
176
|
-
* components (those stay null — the historical FR-010 gap). For full nested extraction, use
|
|
177
|
-
* \`${extractLenientWithName}(root, text)\`, which delegates to the runtime extract.
|
|
178
|
-
*/
|
|
179
|
-
export function ${extractLenientFnName}(
|
|
180
|
-
text: string,
|
|
181
|
-
opts?: ExtractOptions,
|
|
182
|
-
): ExtractionResult<${extractedName}> {
|
|
183
|
-
const outcome = extract(text, ${schemaConstName}, opts);
|
|
184
|
-
const d = outcome.data;
|
|
185
|
-
const data: ${extractedName} = ${initializer};
|
|
186
|
-
return { data, report: outcome.report };
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Extraction as a bool gate: \`true\` when the response was non-empty and no required
|
|
191
|
-
* field was lost. On success, \`result\` carries the extracted mirror + report.
|
|
192
|
-
*/
|
|
193
|
-
export function ${tryExtractLenientName}(
|
|
194
|
-
text: string,
|
|
195
|
-
): { ok: boolean; result: ExtractionResult<${extractedName}> } {
|
|
196
|
-
const result = ${extractLenientFnName}(text);
|
|
197
|
-
const ok = !result.report.isEmpty() && !result.report.hasLostRequired();
|
|
198
|
-
return { ok, result };
|
|
199
|
-
}
|
|
200
|
-
`;
|
|
201
|
-
// ---- Runtime-delegating extract (closes the nested gap) ----
|
|
149
|
+
// Render-package imports the (single, loader-delegating) extract block needs. Kept minimal so
|
|
150
|
+
// the file has no unused imports (tsc noUnusedLocals-safe).
|
|
151
|
+
const renderImports = ["Format", "type ExtractOptions", "type ExtractionResult"];
|
|
152
|
+
// ---- Runtime-delegating extract (the single metadata-driven extract path) ----
|
|
202
153
|
// Resolves this payload's MetaObject from a loaded MetaRoot by its baked simple name and
|
|
203
154
|
// delegates to extractObject() in @metaobjectsdev/runtime-ts, which assembles the FULL nested
|
|
204
|
-
// object graph reflection-free
|
|
205
|
-
// nullable mirror graph by the generated from<VO>Extracted
|
|
206
|
-
// (a generated DAO calling the dynamic-metadata runtime)
|
|
155
|
+
// object graph reflection-free by reading the live metadata directly. The assembled ValueObject
|
|
156
|
+
// graph is then mapped into the typed nullable mirror graph by the generated from<VO>Extracted
|
|
157
|
+
// mappers. Codegen-wrapping-runtime (a generated DAO calling the dynamic-metadata runtime).
|
|
207
158
|
//
|
|
208
159
|
// The baked PAYLOAD_NAME is the resolved payload VO's SIMPLE name (root.findObject matches on
|
|
209
160
|
// the object's `name`, not its FQN). The root mapper is named for the TEMPLATE (so it returns
|
|
210
161
|
// the canonically-named `<Template>Extracted` mirror); nested mappers use their VO names.
|
|
211
162
|
const payloadName = vo.name;
|
|
212
163
|
const rootMapper = rootMapperName(templateName);
|
|
164
|
+
void hasNested;
|
|
213
165
|
const delegating = `
|
|
214
166
|
/** Payload value-object name this parser extracts — resolved against a loaded MetaRoot at runtime. */
|
|
215
167
|
export const ${payloadFqnConst} = ${JSON.stringify(payloadName)};
|
|
216
168
|
|
|
169
|
+
${mirrorDecls}
|
|
170
|
+
|
|
217
171
|
${nestedMappers(vo, root, rootMapper, extractedName)}
|
|
218
172
|
|
|
219
173
|
${delegateHelpers(usedHelpers(vo, root))}
|
|
220
174
|
|
|
221
175
|
/**
|
|
222
|
-
* Runtime-delegating tolerant extraction; never throws.
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* model), then maps the assembled graph into the typed
|
|
176
|
+
* Runtime-delegating tolerant best-effort extraction; never throws. FULLY populates
|
|
177
|
+
* nested-object and array-of-object components by delegating to the metadata-driven runtime
|
|
178
|
+
* \`extractObject\` (which assembles the whole graph reflection-free via the Phase A object
|
|
179
|
+
* model, reading the live metadata directly), then maps the assembled graph into the typed
|
|
180
|
+
* \`${extractedName}\` mirror.
|
|
226
181
|
*
|
|
227
182
|
* @param root a loaded MetaRoot (e.g. \`(await new MetaDataLoader().load(...)).root\`) that declares
|
|
228
|
-
* the \`${
|
|
183
|
+
* the \`${payloadName}\` value-object.
|
|
229
184
|
*/
|
|
230
185
|
export function ${extractLenientWithName}(
|
|
231
186
|
root: MetaRoot,
|
|
@@ -241,9 +196,6 @@ export function ${extractLenientWithName}(
|
|
|
241
196
|
}
|
|
242
197
|
`;
|
|
243
198
|
// The delegating overload needs runtime-ts (extractObject) + the MetaRoot type from metadata.
|
|
244
|
-
// It is always emitted (the gap-closing path), regardless of whether THIS payload has nested
|
|
245
|
-
// fields — a flat payload still benefits from the loader-driven path and keeps the API uniform.
|
|
246
|
-
void payloadHasNested;
|
|
247
199
|
const metadataImport = `import type { MetaRoot } from "@metaobjectsdev/metadata";\n`;
|
|
248
200
|
const runtimeImport = `import { extractObject } from "@metaobjectsdev/runtime-ts";\n`;
|
|
249
201
|
return (`import { z } from "zod";\n` +
|
|
@@ -252,7 +204,6 @@ export function ${extractLenientWithName}(
|
|
|
252
204
|
runtimeImport +
|
|
253
205
|
`\n` +
|
|
254
206
|
`${strictBody}\n` +
|
|
255
|
-
`${selfContained}\n` +
|
|
256
207
|
`${delegating}`);
|
|
257
208
|
}
|
|
258
209
|
//# sourceMappingURL=output-parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-parser.js","sourceRoot":"","sources":["../../src/templates/output-parser.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,EAAE;AACF,6EAA6E;AAC7E,iFAAiF;AACjF,
|
|
1
|
+
{"version":3,"file":"output-parser.js","sourceRoot":"","sources":["../../src/templates/output-parser.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,EAAE;AACF,6EAA6E;AAC7E,iFAAiF;AACjF,sEAAsE;AACtE,mFAAmF;AACnF,kFAAkF;AAClF,iFAAiF;AACjF,+EAA+E;AAC/E,4EAA4E;AAE5E,OAAO,EAEL,WAAW,EACX,UAAU,EACV,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,cAAc,EACd,eAAe,EACf,WAAW,EACX,SAAS,GACV,MAAM,+BAA+B,CAAC;AAEvC,MAAM,UAAU,GAA2B;IACzC,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,YAAY;IACnB,GAAG,EAAE,kBAAkB;IACvB,KAAK,EAAE,kBAAkB;IACzB,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,kBAAkB;IACxB,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,YAAY;I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eAAe,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;;;;;;;OAOjC,aAAa;;;uBAGG,WAAW;;kBAEhB,sBAAsB;;;;sBAIlB,aAAa;+BACJ,eAAe;;wBAEtB,sBAAsB,iBAAiB,eAAe;;4CAElC,UAAU;mBACnC,UAAU;;CAE5B,CAAC;IAEA,8FAA8F;IAC9F,MAAM,cAAc,GAAG,6DAA6D,CAAC;IACrF,MAAM,aAAa,GAAG,+DAA+D,CAAC;IAEtF,OAAO,CACL,4BAA4B;QAC5B,eAAe,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,uCAAuC;QACjF,cAAc;QACd,aAAa;QACb,IAAI;QACJ,GAAG,UAAU,IAAI;QACjB,GAAG,UAAU,EAAE,CAChB,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-prompt.d.ts","sourceRoot":"","sources":["../../src/templates/output-prompt.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"output-prompt.d.ts","sourceRoot":"","sources":["../../src/templates/output-prompt.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,KAAK,QAAQ,EAOd,MAAM,0BAA0B,CAAC;AAWlC,iGAAiG;AACjG,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAG9D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CA8C/E"}
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
//
|
|
10
10
|
// Mirrors the C# OutputPromptGenerator + OutputFormatSpecEmitter (split into a
|
|
11
11
|
// generator factory + this pure renderer, matching the TS output-parser shape).
|
|
12
|
-
import { TYPE_OBJECT, TYPE_TEMPLATE, TEMPLATE_SUBTYPE_OUTPUT, TEMPLATE_ATTR_PAYLOAD_REF, TEMPLATE_ATTR_FORMAT, } from "@metaobjectsdev/metadata";
|
|
12
|
+
import { TYPE_OBJECT, TYPE_TEMPLATE, TEMPLATE_SUBTYPE_OUTPUT, TEMPLATE_ATTR_PAYLOAD_REF, TEMPLATE_ATTR_FORMAT, refMatchesObject, } from "@metaobjectsdev/metadata";
|
|
13
13
|
import { specLiteral } from "./output-format-spec-emitter.js";
|
|
14
14
|
function findObject(root, name) {
|
|
15
|
-
return root.ownChildren().find((c) => c.type === TYPE_OBJECT && c
|
|
15
|
+
return root.ownChildren().find((c) => c.type === TYPE_OBJECT && refMatchesObject(c, name));
|
|
16
16
|
}
|
|
17
17
|
function findTemplate(root, name) {
|
|
18
18
|
return root.ownChildren().find((c) => c.type === TYPE_TEMPLATE && c.name === name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-prompt.js","sourceRoot":"","sources":["../../src/templates/output-prompt.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,kFAAkF;AAClF,mFAAmF;AACnF,mFAAmF;AACnF,2EAA2E;AAC3E,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAEhF,OAAO,EAEL,WAAW,EACX,aAAa,EACb,uBAAuB,EACvB,yBAAyB,EACzB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"output-prompt.js","sourceRoot":"","sources":["../../src/templates/output-prompt.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,kFAAkF;AAClF,mFAAmF;AACnF,mFAAmF;AACnF,2EAA2E;AAC3E,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAEhF,OAAO,EAEL,WAAW,EACX,aAAa,EACb,uBAAuB,EACvB,yBAAyB,EACzB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,SAAS,UAAU,CAAC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,yBAAyB,CAAC,CAAC;IAC3D,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,aAAa,YAAY,uBAAuB,CAAC,CAAC;IACpE,CAAC;IACD,MAAM,EAAE,GAAG,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACxC,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,IAAI,KAAK,CAAC,aAAa,YAAY,kBAAkB,UAAU,8BAA8B,CAAC,CAAC;IACvG,CAAC;IAED,uEAAuE;IACvE,MAAM,IAAI,GAAG,WAAW,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,GAAG,YAAY,YAAY,CAAC;IAC7C,MAAM,MAAM,GAAG,SAAS,YAAY,QAAQ,CAAC;IAE7C,OAAO;;;;;;;;;QASD,QAAQ,wBAAwB,IAAI;;;oDAGQ,YAAY;;;;;kBAK9C,MAAM;8BACM,QAAQ;;CAErC,CAAC;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries-file.d.ts","sourceRoot":"","sources":["../../src/templates/queries-file.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"queries-file.d.ts","sourceRoot":"","sources":["../../src/templates/queries-file.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,UAAU,EAGX,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAc1D,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,GAAG,MAAM,CA4D7E"}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
// Queries file composer — composes all CRUD function renderers (from queries.ts) into
|
|
2
2
|
// a complete <Entity>.queries.ts file with @generated header and correct imports.
|
|
3
|
-
import { code, joinCode } from "ts-poet";
|
|
4
|
-
import { MetaObject } from "@metaobjectsdev/metadata";
|
|
3
|
+
import { code, joinCode, imp } from "ts-poet";
|
|
4
|
+
import { MetaObject, OBJECT_ATTR_DISCRIMINATOR, OBJECT_ATTR_DISCRIMINATOR_VALUE, } from "@metaobjectsdev/metadata";
|
|
5
5
|
import {} from "../render-context.js";
|
|
6
6
|
import { entityModuleSpecifier } from "../import-path.js";
|
|
7
|
-
import { renderFindByIdFn, renderListFn, renderCreateFn, renderUpdateFn, renderDeleteByIdFn, } from "./queries.js";
|
|
8
|
-
import { variableNameFromEntity } from "../naming.js";
|
|
7
|
+
import { renderFindByIdFn, renderListFn, renderCreateFn, renderUpdateFn, renderDeleteByIdFn, getPkInfo, } from "./queries.js";
|
|
8
|
+
import { variableNameFromEntity, pluralize } from "../naming.js";
|
|
9
9
|
import { GENERATED_HEADER } from "../constants.js";
|
|
10
|
+
import { isTphDiscriminatorBase, tphConcreteSubtypes } from "./tph-discriminator.js";
|
|
10
11
|
export function renderQueriesFile(obj, ctx) {
|
|
12
|
+
// FR-017 Tier 2 — a TPH discriminator base gets a polymorphic queries file:
|
|
13
|
+
// base reads dispatch through parse<Base>, and per-subtype CRUD targets the
|
|
14
|
+
// single base table scoped to the discriminator value. (Subtype entities are
|
|
15
|
+
// filtered out of the queries generator entirely — their CRUD lives here.)
|
|
16
|
+
if (isTphDiscriminatorBase(obj, ctx.loadedRoot)) {
|
|
17
|
+
return renderTphQueriesFile(obj, ctx);
|
|
18
|
+
}
|
|
11
19
|
const entityName = obj.name;
|
|
12
20
|
// Import the entity's own file. Same target → relative "./Entity"; cross
|
|
13
21
|
// target → importBase-qualified package path.
|
|
@@ -47,4 +55,104 @@ import { ${varName}, type ${entityName}, ${entityName}InsertSchema } from ${JSON
|
|
|
47
55
|
`// Customize via ${entityName}.extra.ts in this directory (additional queries, custom logic).\n`;
|
|
48
56
|
return header + body;
|
|
49
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* FR-017 Tier 2 — the polymorphic + per-subtype queries file for a TPH base.
|
|
60
|
+
*
|
|
61
|
+
* Base reads (`find<Base>ById`, `list<BasePlural>`) project every row through
|
|
62
|
+
* `parse<Base>` so they return the discriminated union. There is intentionally
|
|
63
|
+
* NO `create<Base>` / `update<Base>` — you cannot instantiate an abstract base.
|
|
64
|
+
*
|
|
65
|
+
* Each concrete subtype gets list / findById (filtered to the discriminator
|
|
66
|
+
* value, parsed with `<Sub>Schema`) plus create / updateById / deleteById, all
|
|
67
|
+
* against the single base table. Creates inject the discriminator value;
|
|
68
|
+
* updates strip it (a row's subtype is immutable).
|
|
69
|
+
*/
|
|
70
|
+
function renderTphQueriesFile(base, ctx) {
|
|
71
|
+
const baseName = base.name;
|
|
72
|
+
const tableVar = variableNameFromEntity(baseName);
|
|
73
|
+
const discField = base.ownAttr(OBJECT_ATTR_DISCRIMINATOR);
|
|
74
|
+
const { fieldName: pkField, tsType: pkType } = getPkInfo(base, ctx);
|
|
75
|
+
const baseFileSpec = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget, base.package, baseName, ctx.extStyle);
|
|
76
|
+
const tableSym = imp(`${tableVar}@${baseFileSpec}`);
|
|
77
|
+
const baseTypeSym = imp(`t:${baseName}@${baseFileSpec}`);
|
|
78
|
+
const parseSym = imp(`parse${baseName}@${baseFileSpec}`);
|
|
79
|
+
const eqSym = imp("eq@drizzle-orm");
|
|
80
|
+
const andSym = imp("and@drizzle-orm");
|
|
81
|
+
const dbTypeImport = ctx.dialect === "postgres"
|
|
82
|
+
? `import type { NodePgDatabase } from "drizzle-orm/node-postgres";`
|
|
83
|
+
: `import type { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";`;
|
|
84
|
+
const dbTypeAlias = ctx.dialect === "postgres"
|
|
85
|
+
? `type Db = NodePgDatabase<Record<string, never>>;`
|
|
86
|
+
: `type Db = BaseSQLiteDatabase<"async", Record<string, never>>;`;
|
|
87
|
+
// --- Polymorphic base reads ---
|
|
88
|
+
const polymorphic = code `
|
|
89
|
+
export async function find${baseName}ById(db: Db, ${pkField}: ${pkType}): Promise<${baseTypeSym} | null> {
|
|
90
|
+
const [row] = await db.select().from(${tableSym}).where(${eqSym}(${tableSym}.${pkField}, ${pkField})).limit(1);
|
|
91
|
+
return row ? ${parseSym}(row) : null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function list${pluralize(baseName)}(db: Db, opts?: { limit?: number; offset?: number }): Promise<${baseTypeSym}[]> {
|
|
95
|
+
let q = db.select().from(${tableSym}).$dynamic();
|
|
96
|
+
if (opts?.limit !== undefined) q = q.limit(opts.limit);
|
|
97
|
+
if (opts?.offset !== undefined) q = q.offset(opts.offset);
|
|
98
|
+
const rows = await q;
|
|
99
|
+
return rows.map((r) => ${parseSym}(r));
|
|
100
|
+
}
|
|
101
|
+
`;
|
|
102
|
+
// --- Per-subtype CRUD against the single base table ---
|
|
103
|
+
const subtypeSections = [];
|
|
104
|
+
for (const sub of tphConcreteSubtypes(base, ctx.loadedRoot)) {
|
|
105
|
+
const value = sub.ownAttr(OBJECT_ATTR_DISCRIMINATOR_VALUE);
|
|
106
|
+
const valueLit = JSON.stringify(value);
|
|
107
|
+
const subFileSpec = entityModuleSpecifier(ctx.selfTarget, ctx.entityModuleTarget, sub.package, sub.name, ctx.extStyle);
|
|
108
|
+
const subTypeSym = imp(`t:${sub.name}@${subFileSpec}`);
|
|
109
|
+
const subSchemaSym = imp(`${sub.name}Schema@${subFileSpec}`);
|
|
110
|
+
const subInsertSym = imp(`${sub.name}InsertSchema@${subFileSpec}`);
|
|
111
|
+
subtypeSections.push(code `
|
|
112
|
+
export async function list${pluralize(sub.name)}(db: Db, opts?: { limit?: number; offset?: number }): Promise<${subTypeSym}[]> {
|
|
113
|
+
let q = db.select().from(${tableSym}).where(${eqSym}(${tableSym}.${discField}, ${valueLit})).$dynamic();
|
|
114
|
+
if (opts?.limit !== undefined) q = q.limit(opts.limit);
|
|
115
|
+
if (opts?.offset !== undefined) q = q.offset(opts.offset);
|
|
116
|
+
const rows = await q;
|
|
117
|
+
return rows.map((r) => ${subSchemaSym}.parse(r));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export async function find${sub.name}ById(db: Db, ${pkField}: ${pkType}): Promise<${subTypeSym} | null> {
|
|
121
|
+
const [row] = await db.select().from(${tableSym})
|
|
122
|
+
.where(${andSym}(${eqSym}(${tableSym}.${pkField}, ${pkField}), ${eqSym}(${tableSym}.${discField}, ${valueLit}))).limit(1);
|
|
123
|
+
return row ? ${subSchemaSym}.parse(row) : null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function create${sub.name}(db: Db, data: unknown): Promise<${subTypeSym}> {
|
|
127
|
+
const validated = ${subInsertSym}.parse(data);
|
|
128
|
+
const [row] = await db.insert(${tableSym}).values({ ...validated, ${discField}: ${valueLit} }).returning();
|
|
129
|
+
return ${subSchemaSym}.parse(row!);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function update${sub.name}ById(db: Db, ${pkField}: ${pkType}, data: unknown): Promise<${subTypeSym} | null> {
|
|
133
|
+
const validated = ${subInsertSym}.partial().parse(data) as Record<string, unknown>;
|
|
134
|
+
// The discriminator is immutable — a ${sub.name} can never become another subtype.
|
|
135
|
+
const { [${JSON.stringify(discField)}]: _disc, ...safe } = validated;
|
|
136
|
+
const [row] = await db.update(${tableSym}).set(safe)
|
|
137
|
+
.where(${andSym}(${eqSym}(${tableSym}.${pkField}, ${pkField}), ${eqSym}(${tableSym}.${discField}, ${valueLit}))).returning();
|
|
138
|
+
return row ? ${subSchemaSym}.parse(row) : null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export async function delete${sub.name}ById(db: Db, ${pkField}: ${pkType}): Promise<boolean> {
|
|
142
|
+
const deleted = await db.delete(${tableSym})
|
|
143
|
+
.where(${andSym}(${eqSym}(${tableSym}.${pkField}, ${pkField}), ${eqSym}(${tableSym}.${discField}, ${valueLit}))).returning();
|
|
144
|
+
return deleted.length > 0;
|
|
145
|
+
}
|
|
146
|
+
`);
|
|
147
|
+
}
|
|
148
|
+
const literalImports = code `
|
|
149
|
+
${dbTypeImport}
|
|
150
|
+
${dbTypeAlias}
|
|
151
|
+
`;
|
|
152
|
+
const body = joinCode([literalImports, polymorphic, ...subtypeSections], { on: "\n" }).toString();
|
|
153
|
+
const header = `// ${GENERATED_HEADER} — DO NOT EDIT.\n` +
|
|
154
|
+
`// Source metadata: ${baseName} (${base.fqn()}) — TPH discriminator base\n` +
|
|
155
|
+
`// Customize via ${baseName}.extra.ts in this directory (additional queries, custom logic).\n`;
|
|
156
|
+
return header + body;
|
|
157
|
+
}
|
|
50
158
|
//# sourceMappingURL=queries-file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries-file.js","sourceRoot":"","sources":["../../src/templates/queries-file.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,kFAAkF;AAElF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAa,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"queries-file.js","sourceRoot":"","sources":["../../src/templates/queries-file.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,kFAAkF;AAElF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAa,MAAM,SAAS,CAAC;AACzD,OAAO,EACL,UAAU,EACV,yBAAyB,EACzB,+BAA+B,GAChC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAsB,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,SAAS,GACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,wB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AAC,CAAC,QAAQ,EAAE,CAAC;IAClG,MAAM,MAAM,GACV,MAAM,gBAAgB,mBAAmB;QACzC,uBAAuB,QAAQ,KAAK,IAAI,CAAC,GAAG,EAAE,8BAA8B;QAC5E,oBAAoB,QAAQ,mEAAmE,CAAC;IAClG,OAAO,MAAM,GAAG,IAAI,CAAC;AACvB,CAAC"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { type Code } from "ts-poet";
|
|
2
2
|
import type { MetaObject } from "@metaobjectsdev/metadata";
|
|
3
3
|
import type { RenderContext } from "../render-context.js";
|
|
4
|
+
/** Get the PK field name and its TS type for a given entity. */
|
|
5
|
+
export declare function getPkInfo(entity: MetaObject, ctx: RenderContext): {
|
|
6
|
+
fieldName: string;
|
|
7
|
+
tsType: string;
|
|
8
|
+
};
|
|
4
9
|
export declare function renderFindByIdFn(entity: MetaObject, ctx: RenderContext): Code;
|
|
5
10
|
export declare function renderListFn(entity: MetaObject, _ctx: RenderContext): Code;
|
|
6
11
|
export declare function renderCreateFn(entity: MetaObject, _ctx: RenderContext): Code;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/templates/queries.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,KAAK,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/templates/queries.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,KAAK,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAW1D,gEAAgE;AAChE,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAevG;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI,CAc7E;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAe1E;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAc5E;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI,CAgB3E;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI,CAe/E"}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Each returns a ts-poet Code block; composed into a file by queries-file.ts.
|
|
3
3
|
import { code, imp } from "ts-poet";
|
|
4
4
|
import { IDENTITY_ATTR_FIELDS } from "@metaobjectsdev/metadata";
|
|
5
|
-
import { variableNameFromEntity, pluralize } from "../naming.js";
|
|
5
|
+
import { variableNameFromEntity, pluralize, findByIdFnName, listFnName, createFnName, updateFnName, deleteByIdFnName, } from "../naming.js";
|
|
6
6
|
/** Get the PK field name and its TS type for a given entity. */
|
|
7
|
-
function getPkInfo(entity, ctx) {
|
|
7
|
+
export function getPkInfo(entity, ctx) {
|
|
8
8
|
// Use primaryIdentity() to find the primary identity (may be inherited from extends:/super:).
|
|
9
9
|
const primary = entity.primaryIdentity();
|
|
10
10
|
const rawFields = primary?.ownAttr(IDENTITY_ATTR_FIELDS);
|
|
@@ -24,7 +24,7 @@ export function renderFindByIdFn(entity, ctx) {
|
|
|
24
24
|
const entityName = entity.name;
|
|
25
25
|
const singularVar = entityName.charAt(0).toLowerCase() + entityName.slice(1);
|
|
26
26
|
const { fieldName: pkField, tsType: pkType } = getPkInfo(entity, ctx);
|
|
27
|
-
const fnName =
|
|
27
|
+
const fnName = findByIdFnName(entityName);
|
|
28
28
|
const eqSym = imp("eq@drizzle-orm");
|
|
29
29
|
return code `
|
|
30
30
|
export async function ${fnName}(db: Db, ${pkField}: ${pkType}): Promise<${entityName} | null> {
|
|
@@ -38,7 +38,7 @@ export function renderListFn(entity, _ctx) {
|
|
|
38
38
|
const entityName = entity.name;
|
|
39
39
|
// Pluralize the PascalCase entity name, preserving capitalization
|
|
40
40
|
// (e.g., "Category" -> "Categories", not "Categorys").
|
|
41
|
-
const fnName =
|
|
41
|
+
const fnName = listFnName(entityName);
|
|
42
42
|
return code `
|
|
43
43
|
export async function ${fnName}(db: Db, opts?: { limit?: number; offset?: number }): Promise<${entityName}[]> {
|
|
44
44
|
let q = db.select().from(${varName}).$dynamic();
|
|
@@ -52,7 +52,7 @@ export function renderCreateFn(entity, _ctx) {
|
|
|
52
52
|
const varName = variableNameFromEntity(entity.name);
|
|
53
53
|
const entityName = entity.name;
|
|
54
54
|
const singularVar = entityName.charAt(0).toLowerCase() + entityName.slice(1);
|
|
55
|
-
const fnName =
|
|
55
|
+
const fnName = createFnName(entityName);
|
|
56
56
|
const schemaName = `${entityName}InsertSchema`;
|
|
57
57
|
return code `
|
|
58
58
|
export async function ${fnName}(db: Db, data: unknown): Promise<${entityName}> {
|
|
@@ -67,7 +67,7 @@ export function renderUpdateFn(entity, ctx) {
|
|
|
67
67
|
const entityName = entity.name;
|
|
68
68
|
const singularVar = entityName.charAt(0).toLowerCase() + entityName.slice(1);
|
|
69
69
|
const { fieldName: pkField, tsType: pkType } = getPkInfo(entity, ctx);
|
|
70
|
-
const fnName =
|
|
70
|
+
const fnName = updateFnName(entityName);
|
|
71
71
|
const schemaName = `${entityName}InsertSchema`;
|
|
72
72
|
const eqSym = imp("eq@drizzle-orm");
|
|
73
73
|
return code `
|
|
@@ -82,7 +82,7 @@ export function renderDeleteByIdFn(entity, ctx) {
|
|
|
82
82
|
const varName = variableNameFromEntity(entity.name);
|
|
83
83
|
const entityName = entity.name;
|
|
84
84
|
const { fieldName: pkField, tsType: pkType } = getPkInfo(entity, ctx);
|
|
85
|
-
const fnName =
|
|
85
|
+
const fnName = deleteByIdFnName(entityName);
|
|
86
86
|
const eqSym = imp("eq@drizzle-orm");
|
|
87
87
|
return code `
|
|
88
88
|
export async function ${fnName}(db: Db, ${pkField}: ${pkType}): Promise<boolean> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/templates/queries.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,8EAA8E;AAE9E,OAAO,EAAE,IAAI,EAAE,GAAG,EAAa,MAAM,SAAS,CAAC;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/templates/queries.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,8EAA8E;AAE9E,OAAO,EAAE,IAAI,EAAE,GAAG,EAAa,MAAM,SAAS,CAAC;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,EACL,sBAAsB,EACtB,SAAS,EACT,cAAc,EACd,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAEtB,gEAAgE;AAChE,MAAM,UAAU,SAAS,CAAC,MAAkB,EAAE,GAAkB;IAC9D,8FAA8F;IAC9F,MAAM,OAAO,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IACzC,MAAM,SAAS,GAAG,OAAO,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,SAAS,KAAK,QAAQ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,CAAC;IAC7E,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACtE,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;IACxC,MAAM,UAAU,GAAG,GAAG,UAAU,cAAc,CAAC;IAC/C,MAAM,KAAK,GAAG,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAEpC,OAAO,IAAI,CAAA;wBACW,MAAM,YAAY,OAAO,KAAK,MAAM,6BAA6B,UAAU;sBAC7E,UAAU;WACrB,WAAW,uBAAuB,OAAO,0BAA0B,KAAK,IAAI,OAAO,IAAI,OAAO,KAAK,OAAO;WAC1G,WAAW;;CAErB,CAAC;AACF,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAkB,EAAE,GAAkB;IACvE,MAAM,OAAO,GAAG,sBAAsB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC;IAC/B,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACtE,MAAM,MAAM,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAEpC,OAAO,IAAI,CAAA;wBACW,MAAM,YAAY,OAAO,KAAK,MAAM;;;oCAGxB,OAAO,WAAW,KAAK,IAAI,OAAO,IAAI,OAAO,KAAK,OAAO;;;CAG5F,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type MetaData } from "@metaobjectsdev/metadata";
|
|
2
|
+
/** Emit `recoverSchema(Format.X, "rootName", [ … ])`. */
|
|
3
|
+
export declare function schemaLiteral(vo: MetaData, format: string, rootName: string): string;
|
|
4
|
+
/** Emit the all-nullable mirror interface declaration. */
|
|
5
|
+
export declare function mirrorInterface(vo: MetaData, interfaceName: string): string;
|
|
6
|
+
/** Emit `{ prop: asString(d, "prop"), … }` building the mirror from the forgiving map `d`. */
|
|
7
|
+
export declare function mirrorInitializer(vo: MetaData): string;
|
|
8
|
+
//# sourceMappingURL=recover-schema-emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recover-schema-emitter.d.ts","sourceRoot":"","sources":["../../src/templates/recover-schema-emitter.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,KAAK,QAAQ,EAId,MAAM,0BAA0B,CAAC;AAclC,yDAAyD;AACzD,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIpF;AA+BD,0DAA0D;AAC1D,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAc3E;AAED,8FAA8F;AAC9F,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAGtD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// server/typescript/packages/codegen-ts/src/templates/recover-schema-emitter.ts
|
|
2
|
+
//
|
|
3
|
+
// Turns a payload value-object into TS source fragments for the FR-010 recover codegen:
|
|
4
|
+
// • schemaLiteral — a `recoverSchema(Format.JSON, "root", [ … ])` baked descriptor
|
|
5
|
+
// built from FieldSpec factories (scalar / enumField).
|
|
6
|
+
// • mirrorInterface — an all-nullable mirror interface `<Payload>Recovered` (each
|
|
7
|
+
// component `T | null`); recover returns this nullable twin rather
|
|
8
|
+
// than the strict payload (same reasoning as the Java/C#/Kotlin ports).
|
|
9
|
+
// • mirrorInitializer — `{ prop: asString(d, "prop"), … }` building the mirror from the
|
|
10
|
+
// forgiving outcome map `d`.
|
|
11
|
+
//
|
|
12
|
+
// Mirrors the C# RecoverSchemaEmitter (adapted to TS syntax + the `| null` nullable mirror).
|
|
13
|
+
// Bounded scope: scalar / enum / scalar-array. Nested object + array-of-enum deferred.
|
|
14
|
+
import { FIELD_SUBTYPE_ENUM, FIELD_SUBTYPE_OBJECT, FIELD_ATTR_ENUM_ALIAS, } from "@metaobjectsdev/metadata";
|
|
15
|
+
import { fields, isRequired, isArray, scalarKind, mirrorType, recoverMapCall, enumValues, jsonStringLiteral, stringArrayLiteral, propertiesMapLiteral, } from "./fr010-field-mapping.js";
|
|
16
|
+
/** Emit `recoverSchema(Format.X, "rootName", [ … ])`. */
|
|
17
|
+
export function schemaLiteral(vo, format, rootName) {
|
|
18
|
+
const formatEnum = format.toLowerCase() === "xml" ? "Format.XML" : "Format.JSON";
|
|
19
|
+
const specs = fields(vo).map(fieldSpecLiteral);
|
|
20
|
+
return `recoverSchema(${formatEnum}, ${jsonStringLiteral(rootName)}, [${specs.join(", ")}])`;
|
|
21
|
+
}
|
|
22
|
+
function fieldSpecLiteral(field) {
|
|
23
|
+
const name = jsonStringLiteral(field.name);
|
|
24
|
+
const required = isRequired(field);
|
|
25
|
+
if (field.subType === FIELD_SUBTYPE_ENUM) {
|
|
26
|
+
const valuesLit = stringArrayLiteral(enumValues(field));
|
|
27
|
+
const aliasLit = propertiesMapLiteral(field.ownAttr(FIELD_ATTR_ENUM_ALIAS));
|
|
28
|
+
// enumField() sets array:false; enum-array is a bounded deferral (parity with Java/C#).
|
|
29
|
+
return `enumField(${name}, ${required}, ${valuesLit}, ${aliasLit})`;
|
|
30
|
+
}
|
|
31
|
+
if (field.subType === FIELD_SUBTYPE_OBJECT) {
|
|
32
|
+
// FR-010: nested recover deferred — treat as an opaque required/optional string slot.
|
|
33
|
+
return `scalar(${name}, FieldKind.STRING, ${required}) /* FR-010: nested recover deferred */`;
|
|
34
|
+
}
|
|
35
|
+
const kind = scalarKind(field.subType) ?? "STRING";
|
|
36
|
+
// Scalar-array: the scalar() factory only builds singular specs (array:false), so emit a
|
|
37
|
+
// FieldSpec object literal with array:true. Tier-2 win over the Roslyn proof: the emitted
|
|
38
|
+
// recover() actually populates the array at runtime (RecoverMap.asStringList).
|
|
39
|
+
if (isArray(field)) {
|
|
40
|
+
return (`{ name: ${name}, kind: FieldKind.${kind}, required: ${required}, array: true, ` +
|
|
41
|
+
`enumValues: null, enumAlias: null, min: null, max: null, nested: null }`);
|
|
42
|
+
}
|
|
43
|
+
return `scalar(${name}, FieldKind.${kind}, ${required})`;
|
|
44
|
+
}
|
|
45
|
+
/** Emit the all-nullable mirror interface declaration. */
|
|
46
|
+
export function mirrorInterface(vo, interfaceName) {
|
|
47
|
+
const base = interfaceName.endsWith("Recovered")
|
|
48
|
+
? interfaceName.slice(0, -"Recovered".length)
|
|
49
|
+
: interfaceName;
|
|
50
|
+
const lines = [];
|
|
51
|
+
lines.push(`/** Best-effort recovered twin of \`${base}\` — every field nullable (null where lost/malformed). */`);
|
|
52
|
+
lines.push(`export interface ${interfaceName} {`);
|
|
53
|
+
for (const f of fields(vo)) {
|
|
54
|
+
lines.push(` ${f.name}: ${mirrorType(f)};`);
|
|
55
|
+
}
|
|
56
|
+
lines.push("}");
|
|
57
|
+
return lines.join("\n");
|
|
58
|
+
}
|
|
59
|
+
/** Emit `{ prop: asString(d, "prop"), … }` building the mirror from the forgiving map `d`. */
|
|
60
|
+
export function mirrorInitializer(vo) {
|
|
61
|
+
const assigns = fields(vo).map((f) => `${f.name}: ${recoverMapCall(f)}`);
|
|
62
|
+
return `{ ${assigns.join(", ")} }`;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=recover-schema-emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recover-schema-emitter.js","sourceRoot":"","sources":["../../src/templates/recover-schema-emitter.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,EAAE;AACF,wFAAwF;AACxF,yFAAyF;AACzF,+EAA+E;AAC/E,sFAAsF;AACtF,2FAA2F;AAC3F,gGAAgG;AAChG,0FAA0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,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACzE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACrC,CAAC"}
|
|
@@ -32,6 +32,16 @@ ${joinCode(lines, { on: ",\n", trim: false })}
|
|
|
32
32
|
`;
|
|
33
33
|
}
|
|
34
34
|
function renderRelationEntry(entry, ctx, thisVarName, thisEntityPackage) {
|
|
35
|
+
// FR-018 M:N: the source navigates through the junction table, so the Drizzle
|
|
36
|
+
// many() targets the JUNCTION, not the target entity (the relational query API
|
|
37
|
+
// then hops junction → target via the junction's one() sides). The
|
|
38
|
+
// mountM2mRoute the routes generator emits performs the flattened two-stage
|
|
39
|
+
// traversal for the REST contract.
|
|
40
|
+
if (entry.cardinality === CARDINALITY_MANY && entry.junctionEntity !== undefined) {
|
|
41
|
+
const junctionSpec = crossEntitySpecifier(ctx.outputLayout, thisEntityPackage, ctx.packageOf.get(entry.junctionEntity), entry.junctionEntity, ctx.extStyle);
|
|
42
|
+
const junctionVarSym = imp(`${variableNameFromEntity(entry.junctionEntity)}@${junctionSpec}`);
|
|
43
|
+
return code ` ${entry.name}: many(${junctionVarSym})`;
|
|
44
|
+
}
|
|
35
45
|
// Use imp() for cross-entity references so ts-poet tracks and emits the import.
|
|
36
46
|
const targetSpec = crossEntitySpecifier(ctx.outputLayout, thisEntityPackage, ctx.packageOf.get(entry.targetEntity), entry.targetEntity, ctx.extStyle);
|
|
37
47
|
const targetVarSym = imp(`${variableNameFromEntity(entry.targetEntity)}@${targetSpec}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relations-block.js","sourceRoot":"","sources":["../../src/templates/relations-block.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,gEAAgE;AAEhE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,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AAG,CAAC,QAAQ,CACb,CAAC;IACF,MAAM,YAAY,GAAG,GAAG,CAAC,GAAG,sBAAsB,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC;IAExF,IAAI,KAAK,CAAC,WAAW,KAAK,eAAe,EAAE,CAAC;QAC1C,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACjD,MAAM,aAAa,GAAG,MAAM,EAAE,SAAS,IAAI,IAAI,CAAC;QAChD,OAAO,IAAI,CAAA,KAAK,KAAK,CAAC,IAAI,SAAS,YAAY,gBAAgB,WAAW,IAAI,KAAK,CAAC,OAAO,IAAI,IAAI,mBAAmB,YAAY,IAAI,aAAa,MAAM,CAAC;IAC5J,CAAC;IACD,OAAO,IAAI,CAAA,KAAK,KAAK,CAAC,IAAI,UAAU,YAAY,GAAG,CAAC;AACtD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-helper.d.ts","sourceRoot":"","sources":["../../src/templates/render-helper.ts"],"names":[],"mappings":"AA2BA,OAAO,EACL,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"render-helper.d.ts","sourceRoot":"","sources":["../../src/templates/render-helper.ts"],"names":[],"mappings":"AA2BA,OAAO,EACL,KAAK,QAAQ,EAkBd,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAGL,KAAK,QAAQ,EAGd,MAAM,wBAAwB,CAAC;AA2EhC;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,QAAQ,EACd,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,QAAQ,GACjB,MAAM,CAsGR"}
|