@memberjunction/codegen-lib 6.2.0-edge.2 → 6.2.0-edge.4

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.
Files changed (62) hide show
  1. package/README.md +13 -0
  2. package/dist/Angular/angular-codegen.d.ts +15 -0
  3. package/dist/Angular/angular-codegen.d.ts.map +1 -1
  4. package/dist/Angular/angular-codegen.js +57 -16
  5. package/dist/Angular/angular-codegen.js.map +1 -1
  6. package/dist/Config/config.d.ts +15 -24
  7. package/dist/Config/config.d.ts.map +1 -1
  8. package/dist/Config/config.js +2 -5
  9. package/dist/Config/config.js.map +1 -1
  10. package/dist/Config/integrity-check-schema.d.ts +22 -0
  11. package/dist/Config/integrity-check-schema.d.ts.map +1 -0
  12. package/dist/Config/integrity-check-schema.js +18 -0
  13. package/dist/Config/integrity-check-schema.js.map +1 -0
  14. package/dist/Database/json-check-validators.d.ts +98 -0
  15. package/dist/Database/json-check-validators.d.ts.map +1 -0
  16. package/dist/Database/json-check-validators.js +196 -0
  17. package/dist/Database/json-check-validators.js.map +1 -0
  18. package/dist/Database/manage-metadata.d.ts +121 -8
  19. package/dist/Database/manage-metadata.d.ts.map +1 -1
  20. package/dist/Database/manage-metadata.js +403 -59
  21. package/dist/Database/manage-metadata.js.map +1 -1
  22. package/dist/Manifest/GenerateClassRegistrationsManifest.d.ts.map +1 -1
  23. package/dist/Manifest/GenerateClassRegistrationsManifest.js +7 -4
  24. package/dist/Manifest/GenerateClassRegistrationsManifest.js.map +1 -1
  25. package/dist/Misc/advanced_generation.d.ts +42 -0
  26. package/dist/Misc/advanced_generation.d.ts.map +1 -1
  27. package/dist/Misc/advanced_generation.js +50 -0
  28. package/dist/Misc/advanced_generation.js.map +1 -1
  29. package/dist/Misc/entity_subclasses_codegen.d.ts +50 -0
  30. package/dist/Misc/entity_subclasses_codegen.d.ts.map +1 -1
  31. package/dist/Misc/entity_subclasses_codegen.js +185 -68
  32. package/dist/Misc/entity_subclasses_codegen.js.map +1 -1
  33. package/dist/Misc/graphql_server_codegen.d.ts.map +1 -1
  34. package/dist/Misc/graphql_server_codegen.js +3 -5
  35. package/dist/Misc/graphql_server_codegen.js.map +1 -1
  36. package/dist/Misc/json-type-model.d.ts +148 -0
  37. package/dist/Misc/json-type-model.d.ts.map +1 -0
  38. package/dist/Misc/json-type-model.js +421 -0
  39. package/dist/Misc/json-type-model.js.map +1 -0
  40. package/dist/Misc/json-type-rules.d.ts +90 -0
  41. package/dist/Misc/json-type-rules.d.ts.map +1 -0
  42. package/dist/Misc/json-type-rules.js +274 -0
  43. package/dist/Misc/json-type-rules.js.map +1 -0
  44. package/dist/Misc/json-type-zod.d.ts +41 -0
  45. package/dist/Misc/json-type-zod.d.ts.map +1 -0
  46. package/dist/Misc/json-type-zod.js +390 -0
  47. package/dist/Misc/json-type-zod.js.map +1 -0
  48. package/dist/Misc/runCommand.d.ts.map +1 -1
  49. package/dist/Misc/runCommand.js +13 -5
  50. package/dist/Misc/runCommand.js.map +1 -1
  51. package/dist/Misc/system_integrity.d.ts +27 -0
  52. package/dist/Misc/system_integrity.d.ts.map +1 -1
  53. package/dist/Misc/system_integrity.js +17 -0
  54. package/dist/Misc/system_integrity.js.map +1 -1
  55. package/dist/Misc/validator-text.d.ts +11 -0
  56. package/dist/Misc/validator-text.d.ts.map +1 -0
  57. package/dist/Misc/validator-text.js +15 -0
  58. package/dist/Misc/validator-text.js.map +1 -0
  59. package/dist/runCodeGen.d.ts.map +1 -1
  60. package/dist/runCodeGen.js +34 -13
  61. package/dist/runCodeGen.js.map +1 -1
  62. package/package.json +29 -29
@@ -0,0 +1,274 @@
1
+ /**
2
+ * @fileoverview Turns the `@CHECK` tags of an opted-in JSONType into the runtime rule set emitted
3
+ * into a generated entity's `Validate()`, and compile-checks rule code before it is allowed there.
4
+ *
5
+ * Two kinds of rule exist:
6
+ *
7
+ * - `@CHECK ts:(<expression>)` — a TypeScript boolean expression, used directly; no model involved.
8
+ * - `@CHECK (<SQL>)` — translated to TypeScript by an LLM exactly like a table CHECK constraint, then
9
+ * cached in `__mj.GeneratedCode`. This module never calls the model; it consumes results the
10
+ * caller looked up by {@link BuildJSONCheckKey}.
11
+ *
12
+ * Rule code is emitted only after the TypeScript compiler API has accepted it. A rule that fails is
13
+ * skipped with an error — CodeGen never writes code that would break the generated package's build.
14
+ *
15
+ * @module Misc/json-type-rules
16
+ */
17
+ import fs from 'fs';
18
+ import vm from 'vm';
19
+ import ts from 'typescript';
20
+ import { BuildJSONCheckKey, CollectJSONCheckRules, GetAllMembers, PrefixedTypeText, ResolveLocalTarget, } from './json-type-model.js';
21
+ import { CodeLiteral } from './json-type-zod.js';
22
+ /** Escapes a value for a double-quoted TS string literal (see {@link CodeLiteral}). */
23
+ const str = (s) => CodeLiteral(s);
24
+ /** Syntax check of `return (<expression>);` inside a function; returns null when fine, else the first diagnostic. */
25
+ export function CheckTSExpressionSyntax(expression) {
26
+ const wrapped = `function __rule(value: unknown, row: unknown): boolean {\nreturn (\n${expression}\n);\n}`;
27
+ return firstSyntaxError(wrapped);
28
+ }
29
+ function firstSyntaxError(source) {
30
+ const file = ts.createSourceFile('rule.ts', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
31
+ const diagnostics = file.parseDiagnostics ?? [];
32
+ return diagnostics.length > 0 ? ts.flattenDiagnosticMessageText(diagnostics[0].messageText, '\n') : null;
33
+ }
34
+ /**
35
+ * Compile-checks LLM-produced rule code: it must parse, contain a `return`, avoid `${` (generated
36
+ * code can travel through Flyway migrations, which read `${...}` as a placeholder), and — with the
37
+ * definition's own types in scope — type-check against `value`.
38
+ *
39
+ * `row` is typed as an open record here because the code is generated once per JSONType, not per
40
+ * owning entity; the emitted code is checked against the real entity class when the package builds.
41
+ *
42
+ * @param definition - the JSONTypeDefinition source (original, un-prefixed names)
43
+ * @param valueTypeText - the TypeScript type of `value` (original names)
44
+ * @param body - the function body under test
45
+ * @returns null when acceptable, otherwise the reason it was rejected
46
+ */
47
+ export function CompileCheckJSONRuleBody(definition, valueTypeText, body) {
48
+ if (body.includes('${')) {
49
+ return 'the code contains a template-literal placeholder (${...}); use string concatenation';
50
+ }
51
+ if (!/\breturn\b/.test(body)) {
52
+ return 'the code never returns a value';
53
+ }
54
+ const source = `${definition}\ndeclare const __unusedRowShape: { [column: string]: any };\nfunction __rule(value: ${valueTypeText}, row: typeof __unusedRowShape): boolean {\n${body}\n}\n`;
55
+ const syntax = firstSyntaxError(source);
56
+ if (syntax) {
57
+ return `syntax error: ${syntax}`;
58
+ }
59
+ return firstSemanticError(source);
60
+ }
61
+ /** Wall-clock ceiling for one test-case call, so a non-terminating body cannot hang CodeGen. */
62
+ const RULE_TEST_TIMEOUT_MS = 250;
63
+ /**
64
+ * Executes a translated rule body against the model's own test cases, in a separate `vm` context
65
+ * with no host globals and a time limit (microtasks included). `vm` is NOT a security boundary — the
66
+ * same body is emitted into the generated entity class and runs in-process there anyway, so this
67
+ * guards correctness, not trust. This is a self-consistency guard, not proof of equivalence with
68
+ * the SQL: it catches a body that does not do what its own author says it does — most usefully
69
+ * the NULL-passes rule, because `requireAbsentCase` demands at least one case in which an
70
+ * optional/nullable member is absent or null.
71
+ *
72
+ * @param body - the function body (TypeScript)
73
+ * @param cases - test cases returned with the translation
74
+ * @param requireAbsentCase - true when the value type has optional/nullable members
75
+ * @param optionalMembers - names of those members, to recognise an "absent" case
76
+ * @returns null when every case passes, otherwise the reason the translation must be rejected
77
+ */
78
+ export function RunJSONRuleTestCases(body, cases, requireAbsentCase, optionalMembers) {
79
+ if (!cases || cases.length === 0) {
80
+ return 'the model returned no TestCases; at least one is required to check the translation';
81
+ }
82
+ if (requireAbsentCase && !cases.some((c) => isAbsentCase(c.Value, optionalMembers))) {
83
+ return `TestCases must include a case where an optional/nullable member (${optionalMembers.join(', ')}) is absent or null`;
84
+ }
85
+ const source = `(function (value, row) {\n${body}\n})`;
86
+ const js = ts.transpileModule(source, { compilerOptions: { target: ts.ScriptTarget.ES2020 } }).outputText;
87
+ for (const [index, testCase] of cases.entries()) {
88
+ const failure = runOneCase(js, testCase);
89
+ if (failure) {
90
+ return `TestCases[${index}] ${JSON.stringify(testCase.Value)}: ${failure}`;
91
+ }
92
+ }
93
+ return null;
94
+ }
95
+ function isAbsentCase(value, optionalMembers) {
96
+ if (typeof value !== 'object' || value === null) {
97
+ return false;
98
+ }
99
+ const record = value;
100
+ return optionalMembers.some((name) => record[name] === undefined || record[name] === null);
101
+ }
102
+ function runOneCase(js, testCase) {
103
+ try {
104
+ // afterEvaluate: microtasks the body queues run inside runInContext, under the same timeout,
105
+ // instead of on the host's queue where an infinite `.then()` would hang CodeGen.
106
+ const context = vm.createContext({ input: JSON.stringify({ value: testCase.Value, row: testCase.Row ?? {} }) }, { microtaskMode: 'afterEvaluate' });
107
+ const script = new vm.Script(`const args = JSON.parse(input);\n${js.trim().replace(/;$/, '')}(args.value, args.row)`);
108
+ const actual = script.runInContext(context, { timeout: RULE_TEST_TIMEOUT_MS });
109
+ return actual === testCase.Expected ? null : `expected ${testCase.Expected} but the body returned ${String(actual)}`;
110
+ }
111
+ catch (error) {
112
+ return `the body threw: ${error instanceof Error ? error.message : String(error)}`;
113
+ }
114
+ }
115
+ /** Type-checks a single virtual file against the real TypeScript lib. Returns the first error or null. */
116
+ function firstSemanticError(source) {
117
+ const fileName = '/__mj_rule_check.ts';
118
+ const options = {
119
+ noEmit: true, strict: true, target: ts.ScriptTarget.ES2020, lib: ['lib.es2020.d.ts'], types: [], skipLibCheck: true,
120
+ };
121
+ const host = ts.createCompilerHost(options);
122
+ const original = host.getSourceFile.bind(host);
123
+ host.getSourceFile = (name, languageVersion, onError, shouldCreate) => name === fileName ? ts.createSourceFile(name, source, languageVersion, true) : original(name, languageVersion, onError, shouldCreate);
124
+ host.fileExists = (name) => name === fileName || fs.existsSync(name);
125
+ host.readFile = (name) => (name === fileName ? source : fs.readFileSync(name, 'utf8'));
126
+ const program = ts.createProgram([fileName], options, host);
127
+ const diagnostics = ts.getPreEmitDiagnostics(program, program.getSourceFile(fileName));
128
+ if (diagnostics.length === 0) {
129
+ return null;
130
+ }
131
+ return `type error: ${ts.flattenDiagnosticMessageText(diagnostics[0].messageText, '\n')}`;
132
+ }
133
+ /** Original-name text of the type a rule's `value` parameter has. */
134
+ export function RuleValueTypeText(model, rule) {
135
+ return rule.ValueTypeNode ? rule.ValueTypeNode.getText(model.SourceFile) : rule.DeclarationName;
136
+ }
137
+ /** Declared types that transitively contain a rule-bearing type (rule-bearing types included). */
138
+ function typesReachingRules(model, bearing) {
139
+ const reaching = new Set(bearing);
140
+ // Each pass adds at least one declaration or stops, so Declarations.size passes always suffice.
141
+ let changed = true;
142
+ for (let pass = 0; changed && pass <= model.Declarations.size; pass++) {
143
+ changed = false;
144
+ for (const decl of model.Declarations.values()) {
145
+ if (reaching.has(decl.Name)) {
146
+ continue;
147
+ }
148
+ const hits = GetAllMembers(model, decl).some((m) => {
149
+ const target = ResolveLocalTarget(model, m.TypeNode);
150
+ return target !== null && reaching.has(target.Name);
151
+ });
152
+ if (hits) {
153
+ reaching.add(decl.Name);
154
+ changed = true;
155
+ }
156
+ }
157
+ }
158
+ return reaching;
159
+ }
160
+ /** Edges from each type reachable from the root to child types that lead to rules. */
161
+ function buildGraph(model, reaching) {
162
+ const graph = {};
163
+ const queue = [model.RootName];
164
+ const seen = new Set();
165
+ while (queue.length > 0) {
166
+ const name = queue.shift();
167
+ if (seen.has(name) || !model.Declarations.has(name)) {
168
+ continue;
169
+ }
170
+ seen.add(name);
171
+ const edges = [];
172
+ for (const member of GetAllMembers(model, model.Declarations.get(name))) {
173
+ const target = ResolveLocalTarget(model, member.TypeNode);
174
+ if (target && reaching.has(target.Name)) {
175
+ edges.push({ Property: member.Name, Type: target.Name, Shape: target.Shape });
176
+ queue.push(target.Name);
177
+ }
178
+ }
179
+ if (edges.length > 0) {
180
+ graph[name] = edges;
181
+ }
182
+ }
183
+ return graph;
184
+ }
185
+ function indent(text, spaces) {
186
+ const pad = ' '.repeat(spaces);
187
+ return text.split('\n').map((l) => (l.length > 0 ? `${pad}${l}` : l)).join('\n');
188
+ }
189
+ /** Cleans LLM/stored text the way table-CHECK validators are cleaned: escaped \n, \t and \" become real. */
190
+ function cleanStoredCode(code) {
191
+ return code.replace(/\\n/g, '\n').replace(/\\t/g, '\t').replace(/\\"/g, '"');
192
+ }
193
+ /**
194
+ * Builds the `rules` argument of `ValidateJSONField` for an opted-in JSONType.
195
+ *
196
+ * @param model - the parsed definition
197
+ * @param prefix - the entity-prefixed name stem (`<EntityClass>Entity`), giving `${prefix}_${Type}` type names
198
+ * @param entityClassName - the owning entity class, the type of `row`
199
+ * @param isArray - true when the field holds an array of the root type
200
+ * @param translations - SQL check key → translation, for the SQL rules that have one
201
+ * @param entityName - the owning entity's name (part of the key of a rule that reads `row.`)
202
+ */
203
+ export function BuildJSONRuleSet(model, prefix, entityClassName, isArray, translations, entityName) {
204
+ const collected = CollectJSONCheckRules(model);
205
+ const bearing = new Set(collected.map((r) => r.DeclarationName));
206
+ const reaching = typesReachingRules(model, bearing);
207
+ const reachable = new Set(Object.keys(buildGraph(model, reaching)).concat(model.RootName));
208
+ for (const edges of Object.values(buildGraph(model, reaching))) {
209
+ edges.forEach((e) => reachable.add(e.Type));
210
+ }
211
+ const rules = collected.filter((r) => reachable.has(r.DeclarationName));
212
+ const result = { Source: null, Missing: [], Errors: [], SqlRules: rules.filter((r) => r.Kind === 'sql') };
213
+ const emitted = [];
214
+ for (const rule of rules) {
215
+ const entry = renderRule(model, prefix, entityClassName, entityName, rule, translations, result);
216
+ if (entry) {
217
+ emitted.push(entry);
218
+ }
219
+ }
220
+ if (emitted.length === 0) {
221
+ return result;
222
+ }
223
+ const graph = buildGraph(model, reaching);
224
+ const graphSource = Object.entries(graph)
225
+ .map(([type, edges]) => `${str(type)}: [${edges.map((e) => `{ Property: ${str(e.Property)}, Type: ${str(e.Type)}, Shape: ${str(e.Shape)} }`).join(', ')}]`)
226
+ .join(', ');
227
+ result.Source = `{
228
+ RootType: ${str(model.RootName)},
229
+ RootIsArray: ${isArray},
230
+ Graph: { ${graphSource} },
231
+ Rules: [
232
+ ${emitted.join(',\n')},
233
+ ],
234
+ }`;
235
+ return result;
236
+ }
237
+ function renderRule(model, prefix, entityClassName, entityName, rule, translations, result) {
238
+ const where = `${rule.Path} @CHECK`;
239
+ let description;
240
+ let body;
241
+ if (rule.Kind === 'ts') {
242
+ body = `return (\n${indent(rule.Expression, 4)}\n);`;
243
+ // Type-checked, not just parsed: an expression that does not compile against its value type
244
+ // would otherwise break the generated package's build.
245
+ const problem = CheckTSExpressionSyntax(rule.Expression)
246
+ ?? CompileCheckJSONRuleBody(model.SourceFile.text, RuleValueTypeText(model, rule), body);
247
+ if (problem) {
248
+ result.Errors.push(`${where} ts: expression skipped — ${problem}`);
249
+ return null;
250
+ }
251
+ description = `Must satisfy: ${rule.NormalizedText}`;
252
+ }
253
+ else {
254
+ const translation = translations.get(BuildJSONCheckKey(model, rule, entityName));
255
+ if (!translation) {
256
+ result.Missing.push(rule);
257
+ return null;
258
+ }
259
+ description = translation.Description;
260
+ body = cleanStoredCode(translation.Body).trim();
261
+ }
262
+ const valueType = rule.ValueTypeNode ? PrefixedTypeText(model, rule.ValueTypeNode, prefix) : `${prefix}_${rule.DeclarationName}`;
263
+ const lines = [
264
+ `Type: ${str(rule.DeclarationName)},`,
265
+ ...(rule.Property !== undefined ? [`Property: ${str(rule.Property)},`] : []),
266
+ ...(rule.PerElement ? ['PerElement: true,'] : []),
267
+ `Description: ${str(description)},`,
268
+ `Test(value: ${valueType}, row: ${entityClassName}): boolean {`,
269
+ indent(body, 4),
270
+ '},',
271
+ ];
272
+ return ` {\n${indent(lines.join('\n'), 12)}\n }`;
273
+ }
274
+ //# sourceMappingURL=json-type-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-type-rules.js","sourceRoot":"","sources":["../../src/Misc/json-type-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,E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AAU,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,gBAAgB,GAAG,CAAC,WAAW,CAAC,GAAG;QACnC,eAAe,SAAS,UAAU,eAAe,cAAc;QAC/D,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACf,IAAI;KACP,CAAC;IACF,OAAO,cAAc,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC;AACnE,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @fileoverview Converts an opted-in JSONType definition (TypeScript AST) into Zod source.
3
+ *
4
+ * Emitted per declared interface / type alias `X` of a definition prefixed with `P`:
5
+ *
6
+ * ```ts
7
+ * const P_XSchema = z.lazy(() => z.object({ ... })) as z.ZodType<P_X>;
8
+ * ```
9
+ *
10
+ * Every local type is wrapped in `z.lazy`, so references between declarations — including
11
+ * recursion — need no ordering, and the output depends only on the definition text (deterministic,
12
+ * which the codegen-drift gate requires).
13
+ *
14
+ * Constructs with no Zod translation never fail the run: that sub-tree becomes `z.custom<T>()` — no
15
+ * runtime check, exactly like `z.unknown()`, but carrying the declared TypeScript type so the
16
+ * `z.ZodType<P_X>` annotation and the entity's `z.infer` type stay correct — and a warning is
17
+ * reported to the caller.
18
+ *
19
+ * @module Misc/json-type-zod
20
+ */
21
+ import { JSONTypeModel } from './json-type-model.js';
22
+ /** Result of converting a definition. */
23
+ export interface JSONZodResult {
24
+ /** Source of every `const P_XSchema = ...;` line, one per declaration, blank-line separated (exported, so consumers can `z.infer`/`safeParse` the object shape). */
25
+ Source: string;
26
+ /** The same lines keyed by const name, so a caller combining several definitions can emit each const once. */
27
+ Consts: Map<string, string>;
28
+ /** Constructs that were downgraded to `z.custom<T>()`, for the caller to report. */
29
+ Warnings: string[];
30
+ }
31
+ /**
32
+ * A string from the JSONType definition (which comes from metadata) as a TypeScript string literal for
33
+ * generated source. JSON.stringify alone leaves `<`, `>`, `/` and the U+2028/U+2029 line separators
34
+ * unescaped; they are rewritten as `\uXXXX` escapes, so the literal still evaluates to the same string.
35
+ */
36
+ export declare function CodeLiteral(value: string): string;
37
+ /** Name of the emitted schema const for a declared type. */
38
+ export declare function JSONSchemaConstName(prefix: string, declaredName: string): string;
39
+ /** Converts an opted-in model to Zod source. */
40
+ export declare function GenerateJSONTypeZod(model: JSONTypeModel, prefix: string): JSONZodResult;
41
+ //# sourceMappingURL=json-type-zod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-type-zod.d.ts","sourceRoot":"","sources":["../../src/Misc/json-type-zod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAMH,aAAa,EAGhB,MAAM,mBAAmB,CAAC;AAE3B,yCAAyC;AACzC,MAAM,WAAW,aAAa;IAC1B,oKAAoK;IACpK,MAAM,EAAE,MAAM,CAAC;IACf,8GAA8G;IAC9G,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,oFAAoF;IACpF,QAAQ,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,4DAA4D;AAC5D,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAEhF;AAED,gDAAgD;AAChD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAOvF"}