@memberjunction/codegen-lib 6.2.0-edge.5 → 6.2.0-edge.7
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 -0
- package/dist/Angular/angular-codegen.d.ts +12 -1
- package/dist/Angular/angular-codegen.d.ts.map +1 -1
- package/dist/Angular/angular-codegen.js +36 -1
- package/dist/Angular/angular-codegen.js.map +1 -1
- package/dist/Config/config.d.ts +301 -0
- package/dist/Config/config.d.ts.map +1 -1
- package/dist/Config/config.js +188 -84
- package/dist/Config/config.js.map +1 -1
- package/dist/Database/codeGenDatabaseProvider.d.ts +101 -4
- package/dist/Database/codeGenDatabaseProvider.d.ts.map +1 -1
- package/dist/Database/codeGenDatabaseProvider.js +170 -4
- package/dist/Database/codeGenDatabaseProvider.js.map +1 -1
- package/dist/Database/manage-metadata.d.ts +379 -24
- package/dist/Database/manage-metadata.d.ts.map +1 -1
- package/dist/Database/manage-metadata.js +1021 -237
- package/dist/Database/manage-metadata.js.map +1 -1
- package/dist/Database/materializationAnalysis.d.ts +18 -4
- package/dist/Database/materializationAnalysis.d.ts.map +1 -1
- package/dist/Database/materializationAnalysis.js +113 -99
- package/dist/Database/materializationAnalysis.js.map +1 -1
- package/dist/Database/materializationBroadRender.d.ts +7 -3
- package/dist/Database/materializationBroadRender.d.ts.map +1 -1
- package/dist/Database/materializationBroadRender.js +89 -56
- package/dist/Database/materializationBroadRender.js.map +1 -1
- package/dist/Database/materializationParamClassifier.d.ts +1 -1
- package/dist/Database/materializationParamClassifier.js +2 -2
- package/dist/Database/materializationParamVerifier.d.ts +1 -1
- package/dist/Database/materializationParamVerifier.d.ts.map +1 -1
- package/dist/Database/materializationParamVerifier.js +127 -221
- package/dist/Database/materializationParamVerifier.js.map +1 -1
- package/dist/Database/materializationSqlAst.d.ts +107 -79
- package/dist/Database/materializationSqlAst.d.ts.map +1 -1
- package/dist/Database/materializationSqlAst.js +307 -134
- package/dist/Database/materializationSqlAst.js.map +1 -1
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.d.ts +25 -5
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.d.ts.map +1 -1
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.js +135 -26
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.js.map +1 -1
- package/dist/Database/providers/postgresql/__tests__/MetadataSupportObjectsDDL.test.js +9 -5
- package/dist/Database/providers/postgresql/__tests__/MetadataSupportObjectsDDL.test.js.map +1 -1
- package/dist/Database/providers/postgresql/metadataSupportObjects.js +289 -90
- package/dist/Database/providers/postgresql/metadataSupportObjects.js.map +1 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.d.ts +48 -12
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.d.ts.map +1 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.js +146 -54
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.js.map +1 -1
- package/dist/Database/providers/sqlserver/__tests__/VerifiedJoinIndexes.test.js +66 -0
- package/dist/Database/providers/sqlserver/__tests__/VerifiedJoinIndexes.test.js.map +1 -1
- package/dist/Database/providers/sqlserver/sqlServerDefaultValues.d.ts +47 -0
- package/dist/Database/providers/sqlserver/sqlServerDefaultValues.d.ts.map +1 -0
- package/dist/Database/providers/sqlserver/sqlServerDefaultValues.js +167 -0
- package/dist/Database/providers/sqlserver/sqlServerDefaultValues.js.map +1 -0
- package/dist/Database/providers/sqlserver/sqlServerScriptText.d.ts +31 -0
- package/dist/Database/providers/sqlserver/sqlServerScriptText.d.ts.map +1 -0
- package/dist/Database/providers/sqlserver/sqlServerScriptText.js +116 -0
- package/dist/Database/providers/sqlserver/sqlServerScriptText.js.map +1 -0
- package/dist/Database/queryRebindPass.d.ts +37 -0
- package/dist/Database/queryRebindPass.d.ts.map +1 -0
- package/dist/Database/queryRebindPass.js +110 -0
- package/dist/Database/queryRebindPass.js.map +1 -0
- package/dist/Database/schema-scope.d.ts +12 -0
- package/dist/Database/schema-scope.d.ts.map +1 -1
- package/dist/Database/schema-scope.js +15 -0
- package/dist/Database/schema-scope.js.map +1 -1
- package/dist/Database/sql.d.ts +13 -0
- package/dist/Database/sql.d.ts.map +1 -1
- package/dist/Database/sql.js +39 -8
- package/dist/Database/sql.js.map +1 -1
- package/dist/Database/sql_codegen.d.ts +212 -6
- package/dist/Database/sql_codegen.d.ts.map +1 -1
- package/dist/Database/sql_codegen.js +765 -63
- package/dist/Database/sql_codegen.js.map +1 -1
- package/dist/Misc/advanced_generation.d.ts +129 -5
- package/dist/Misc/advanced_generation.d.ts.map +1 -1
- package/dist/Misc/advanced_generation.js +212 -8
- package/dist/Misc/advanced_generation.js.map +1 -1
- package/dist/Misc/display-name-heuristics.d.ts +57 -0
- package/dist/Misc/display-name-heuristics.d.ts.map +1 -0
- package/dist/Misc/display-name-heuristics.js +97 -0
- package/dist/Misc/display-name-heuristics.js.map +1 -0
- package/dist/Misc/entity_subclasses_codegen.d.ts +31 -3
- package/dist/Misc/entity_subclasses_codegen.d.ts.map +1 -1
- package/dist/Misc/entity_subclasses_codegen.js +79 -17
- package/dist/Misc/entity_subclasses_codegen.js.map +1 -1
- package/dist/Misc/remote_operations_codegen.d.ts.map +1 -1
- package/dist/Misc/remote_operations_codegen.js +21 -4
- package/dist/Misc/remote_operations_codegen.js.map +1 -1
- package/dist/Misc/sql_logging.d.ts +12 -0
- package/dist/Misc/sql_logging.d.ts.map +1 -1
- package/dist/Misc/sql_logging.js +21 -8
- package/dist/Misc/sql_logging.js.map +1 -1
- package/dist/Misc/system_integrity.d.ts +48 -0
- package/dist/Misc/system_integrity.d.ts.map +1 -1
- package/dist/Misc/system_integrity.js +151 -75
- package/dist/Misc/system_integrity.js.map +1 -1
- package/dist/Misc/validator-text.d.ts +17 -0
- package/dist/Misc/validator-text.d.ts.map +1 -1
- package/dist/Misc/validator-text.js +59 -0
- package/dist/Misc/validator-text.js.map +1 -1
- package/dist/runCodeGen.d.ts +37 -3
- package/dist/runCodeGen.d.ts.map +1 -1
- package/dist/runCodeGen.js +161 -51
- package/dist/runCodeGen.js.map +1 -1
- package/package.json +29 -29
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why an entity name was judged opaque (or not). Surfaced so CodeGen can log the
|
|
3
|
+
* reason, and so a reviewer reading the log can tell a deliberate skip from a bug.
|
|
4
|
+
*/
|
|
5
|
+
export type DisplayNameOpacityReason = 'no-vowel-token' | 'short-unknown-token' | 'digit-in-token' | 'clean';
|
|
6
|
+
export interface DisplayNameOpacityResult {
|
|
7
|
+
/** True when the mechanical display name still looks like schema jargon. */
|
|
8
|
+
IsOpaque: boolean;
|
|
9
|
+
/** What triggered the verdict. */
|
|
10
|
+
Reason: DisplayNameOpacityReason;
|
|
11
|
+
/** The mechanical display name that was judged. */
|
|
12
|
+
MechanicalDisplayName: string;
|
|
13
|
+
/** The specific token that looked opaque, when one did. */
|
|
14
|
+
OffendingToken?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Judges whether an entity name is still opaque after the mechanical
|
|
18
|
+
* `createDisplayName()` pass — that is, whether asking an LLM to rewrite it
|
|
19
|
+
* stands to produce anything the deterministic heuristic could not.
|
|
20
|
+
*
|
|
21
|
+
* This is a COST FILTER, not a correctness gate. `createDisplayName()` already
|
|
22
|
+
* splits underscores, normalizes ALL-CAPS, splits compound words and converts
|
|
23
|
+
* camelCase to spaces, so it handles the common cases outright: `CustomerOrder`
|
|
24
|
+
* becomes `Customer Order` with no model involved. Sending that to an LLM buys
|
|
25
|
+
* nothing but latency and tokens.
|
|
26
|
+
*
|
|
27
|
+
* Where it cannot help is vocabulary. `ACCT_STAT_CD` mechanically becomes
|
|
28
|
+
* `Acct Stat Cd` — correctly spaced, still unreadable — because expanding
|
|
29
|
+
* `Acct` to `Account` requires knowing what the abbreviation means. That is the
|
|
30
|
+
* case worth a model call, and this function is how those cases are spotted.
|
|
31
|
+
*
|
|
32
|
+
* The signals, in order of confidence:
|
|
33
|
+
*
|
|
34
|
+
* 1. **A token with no vowel** (`Mbr`, `Cd`, `Txn`, `Hdr`) — near-certain
|
|
35
|
+
* abbreviation, since English words need a vowel sound.
|
|
36
|
+
* 2. **A digit inside an alphabetic token** (`Addr2`, `L1Cache`) — a positional
|
|
37
|
+
* or versioned column whose meaning is rarely self-evident.
|
|
38
|
+
* 3. **A short token not in the common-word list** (`Amt`, `Qty`, `Chg`) — the
|
|
39
|
+
* weakest signal, and the one the allowlist exists to temper.
|
|
40
|
+
*
|
|
41
|
+
* KNOWN LIMITATION. Four-letter abbreviations that contain a vowel and stand
|
|
42
|
+
* alone — `Addr`, `Dept`, `Prod` — are NOT detected. Widening the short-token
|
|
43
|
+
* rule to length 4 would also catch `Item`, `Type`, `Rate`, `Line` and `Code`,
|
|
44
|
+
* which are whole words appearing in most schemas, so the rule would fire almost
|
|
45
|
+
* everywhere and the filter would stop filtering. Since this trades coverage for
|
|
46
|
+
* cost by design, the `alwaysGenerate` feature option bypasses it entirely for
|
|
47
|
+
* deployments that would rather pay for a thorough pass.
|
|
48
|
+
*
|
|
49
|
+
* @param entityName - The entity's `Name` (typically derived from the table name).
|
|
50
|
+
* @returns The verdict, the mechanical name it judged, and the reason.
|
|
51
|
+
*/
|
|
52
|
+
export declare function AssessDisplayNameOpacity(entityName: string): DisplayNameOpacityResult;
|
|
53
|
+
/**
|
|
54
|
+
* Convenience predicate over {@link AssessDisplayNameOpacity}.
|
|
55
|
+
*/
|
|
56
|
+
export declare function IsLikelyOpaqueEntityName(entityName: string): boolean;
|
|
57
|
+
//# sourceMappingURL=display-name-heuristics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display-name-heuristics.d.ts","sourceRoot":"","sources":["../../src/Misc/display-name-heuristics.ts"],"names":[],"mappings":"AA2BA;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAC9B,gBAAgB,GAChB,qBAAqB,GACrB,gBAAgB,GAChB,OAAO,CAAC;AAEd,MAAM,WAAW,wBAAwB;IACrC,4EAA4E;IAC5E,QAAQ,EAAE,OAAO,CAAC;IAElB,kCAAkC;IAClC,MAAM,EAAE,wBAAwB,CAAC;IAEjC,mDAAmD;IACnD,qBAAqB,EAAE,MAAM,CAAC;IAE9B,2DAA2D;IAC3D,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,wBAAwB,CAqCrF;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEpE"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createDisplayName } from "@memberjunction/global";
|
|
2
|
+
/**
|
|
3
|
+
* Short words that are legitimate English on their own, so a display name
|
|
4
|
+
* containing one is NOT evidence of an unexpanded abbreviation.
|
|
5
|
+
*
|
|
6
|
+
* This list exists to suppress needless LLM calls, not to be exhaustive. A word
|
|
7
|
+
* missing from it costs one wasted call whose result is very likely identical to
|
|
8
|
+
* the mechanical name; a word wrongly ON it costs a missed improvement. The list
|
|
9
|
+
* is therefore kept to words that are unambiguously whole words in a schema
|
|
10
|
+
* context, and errs toward being short.
|
|
11
|
+
*/
|
|
12
|
+
const COMMON_SHORT_WORDS = new Set([
|
|
13
|
+
'add', 'age', 'ai', 'all', 'and', 'any', 'api', 'app', 'are', 'bio', 'bot', 'box',
|
|
14
|
+
'buy', 'can', 'car', 'cc', 'city', 'code', 'cost', 'data', 'date', 'day',
|
|
15
|
+
'doc', 'due', 'end', 'eta', 'fax', 'fee', 'file', 'for', 'geo', 'has', 'id',
|
|
16
|
+
'ids', 'job', 'key', 'kind', 'lat', 'law', 'link', 'list', 'log', 'long',
|
|
17
|
+
'map', 'max', 'me', 'min', 'mode', 'name', 'net', 'new', 'no', 'note', 'now',
|
|
18
|
+
'num', 'old', 'one', 'own', 'page', 'paid', 'past', 'pay', 'per', 'plan',
|
|
19
|
+
'run', 'row', 'sex', 'sku', 'sms', 'sum', 'tag', 'tax', 'tel', 'the', 'tier',
|
|
20
|
+
'time', 'tip', 'top', 'try', 'two', 'url', 'use', 'user', 'uri', 'via', 'vat',
|
|
21
|
+
'war', 'way', 'web', 'who', 'why', 'win', 'yes', 'zip', 'zone'
|
|
22
|
+
]);
|
|
23
|
+
/** Vowels, including `y`, which carries a syllable in words like `sync` and `type`. */
|
|
24
|
+
const VOWELS = /[aeiouy]/i;
|
|
25
|
+
/**
|
|
26
|
+
* Judges whether an entity name is still opaque after the mechanical
|
|
27
|
+
* `createDisplayName()` pass — that is, whether asking an LLM to rewrite it
|
|
28
|
+
* stands to produce anything the deterministic heuristic could not.
|
|
29
|
+
*
|
|
30
|
+
* This is a COST FILTER, not a correctness gate. `createDisplayName()` already
|
|
31
|
+
* splits underscores, normalizes ALL-CAPS, splits compound words and converts
|
|
32
|
+
* camelCase to spaces, so it handles the common cases outright: `CustomerOrder`
|
|
33
|
+
* becomes `Customer Order` with no model involved. Sending that to an LLM buys
|
|
34
|
+
* nothing but latency and tokens.
|
|
35
|
+
*
|
|
36
|
+
* Where it cannot help is vocabulary. `ACCT_STAT_CD` mechanically becomes
|
|
37
|
+
* `Acct Stat Cd` — correctly spaced, still unreadable — because expanding
|
|
38
|
+
* `Acct` to `Account` requires knowing what the abbreviation means. That is the
|
|
39
|
+
* case worth a model call, and this function is how those cases are spotted.
|
|
40
|
+
*
|
|
41
|
+
* The signals, in order of confidence:
|
|
42
|
+
*
|
|
43
|
+
* 1. **A token with no vowel** (`Mbr`, `Cd`, `Txn`, `Hdr`) — near-certain
|
|
44
|
+
* abbreviation, since English words need a vowel sound.
|
|
45
|
+
* 2. **A digit inside an alphabetic token** (`Addr2`, `L1Cache`) — a positional
|
|
46
|
+
* or versioned column whose meaning is rarely self-evident.
|
|
47
|
+
* 3. **A short token not in the common-word list** (`Amt`, `Qty`, `Chg`) — the
|
|
48
|
+
* weakest signal, and the one the allowlist exists to temper.
|
|
49
|
+
*
|
|
50
|
+
* KNOWN LIMITATION. Four-letter abbreviations that contain a vowel and stand
|
|
51
|
+
* alone — `Addr`, `Dept`, `Prod` — are NOT detected. Widening the short-token
|
|
52
|
+
* rule to length 4 would also catch `Item`, `Type`, `Rate`, `Line` and `Code`,
|
|
53
|
+
* which are whole words appearing in most schemas, so the rule would fire almost
|
|
54
|
+
* everywhere and the filter would stop filtering. Since this trades coverage for
|
|
55
|
+
* cost by design, the `alwaysGenerate` feature option bypasses it entirely for
|
|
56
|
+
* deployments that would rather pay for a thorough pass.
|
|
57
|
+
*
|
|
58
|
+
* @param entityName - The entity's `Name` (typically derived from the table name).
|
|
59
|
+
* @returns The verdict, the mechanical name it judged, and the reason.
|
|
60
|
+
*/
|
|
61
|
+
export function AssessDisplayNameOpacity(entityName) {
|
|
62
|
+
const mechanicalDisplayName = createDisplayName(entityName ?? '').trim();
|
|
63
|
+
// A schema prefix ("CRM: Accounts", "MJ: AI Agents") is a namespace, not part of the name:
|
|
64
|
+
// judge only what follows it. Stripping just its punctuation left "CRM"/"MJ" as vowel-less
|
|
65
|
+
// tokens, so every prefixed entity read as opaque.
|
|
66
|
+
const colon = mechanicalDisplayName.indexOf(':');
|
|
67
|
+
const judged = colon >= 0 ? mechanicalDisplayName.slice(colon + 1) : mechanicalDisplayName;
|
|
68
|
+
// Split on whitespace; any remaining punctuation is stripped from each token.
|
|
69
|
+
const tokens = judged
|
|
70
|
+
.split(/\s+/)
|
|
71
|
+
.map(t => t.replace(/[^A-Za-z0-9]/g, ''))
|
|
72
|
+
.filter(t => t.length > 0);
|
|
73
|
+
for (const token of tokens) {
|
|
74
|
+
const hasLetter = /[A-Za-z]/.test(token);
|
|
75
|
+
// A purely numeric token carries no vocabulary to expand.
|
|
76
|
+
if (!hasLetter) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (!VOWELS.test(token)) {
|
|
80
|
+
return { IsOpaque: true, Reason: 'no-vowel-token', MechanicalDisplayName: mechanicalDisplayName, OffendingToken: token };
|
|
81
|
+
}
|
|
82
|
+
if (/\d/.test(token)) {
|
|
83
|
+
return { IsOpaque: true, Reason: 'digit-in-token', MechanicalDisplayName: mechanicalDisplayName, OffendingToken: token };
|
|
84
|
+
}
|
|
85
|
+
if (token.length <= 3 && !COMMON_SHORT_WORDS.has(token.toLowerCase())) {
|
|
86
|
+
return { IsOpaque: true, Reason: 'short-unknown-token', MechanicalDisplayName: mechanicalDisplayName, OffendingToken: token };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return { IsOpaque: false, Reason: 'clean', MechanicalDisplayName: mechanicalDisplayName };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Convenience predicate over {@link AssessDisplayNameOpacity}.
|
|
93
|
+
*/
|
|
94
|
+
export function IsLikelyOpaqueEntityName(entityName) {
|
|
95
|
+
return AssessDisplayNameOpacity(entityName).IsOpaque;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=display-name-heuristics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display-name-heuristics.js","sourceRoot":"","sources":["../../src/Misc/display-name-heuristics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;;;;GASG;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IAC/B,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IACjF,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK;IACxE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KA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C;IAED,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,CAAC;AAC9F,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,UAAkB;IACvD,OAAO,wBAAwB,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC;AACzD,CAAC"}
|
|
@@ -105,9 +105,13 @@ export declare class EntitySubClassGeneratorBase {
|
|
|
105
105
|
protected resolveEmitOptions(options?: SchemaEmitOptions): Required<SchemaEmitOptions>;
|
|
106
106
|
/** Delegates so both generators write identically; override to change that. */
|
|
107
107
|
protected emitFile(filePath: string, content: string, useWriteIfChanged: boolean): void;
|
|
108
|
-
|
|
108
|
+
/**
|
|
109
|
+
* @param includeLoadModule - Emit the `loadModule` no-op export.
|
|
110
|
+
* @param usesUUIDsEqual - Import `UUIDsEqual` as well; set when a generated validator in the file calls it.
|
|
111
|
+
*/
|
|
112
|
+
GenerateEntitySubClassFileHeader(includeLoadModule?: boolean, usesUUIDsEqual?: boolean): string;
|
|
109
113
|
/** @deprecated Use {@link GenerateEntitySubClassFileHeader}. */
|
|
110
|
-
generateEntitySubClassFileHeader(includeLoadModule?: boolean): string;
|
|
114
|
+
generateEntitySubClassFileHeader(includeLoadModule?: boolean, usesUUIDsEqual?: boolean): string;
|
|
111
115
|
/**
|
|
112
116
|
* Resolves an entity's generated base class and the import statement that class requires.
|
|
113
117
|
* Pure (no side effects) so BOTH {@link generateEntitySubClass} and the file assembler can call it —
|
|
@@ -187,12 +191,24 @@ export declare class EntitySubClassGeneratorBase {
|
|
|
187
191
|
*/
|
|
188
192
|
protected static RenderRelatedRecordCollection(entity: EntityInfo, relationship: EntityRelationshipInfo, config: RelatedRecordCollectionConfig): string;
|
|
189
193
|
/**
|
|
190
|
-
* Escapes a value for safe embedding in a single-quoted TypeScript string literal
|
|
194
|
+
* Escapes a value for safe embedding in a single-quoted TypeScript string literal: backslash,
|
|
195
|
+
* single quote, and the line terminators a string literal cannot hold (CR, LF, U+2028, U+2029).
|
|
191
196
|
*
|
|
192
197
|
* @param value - The raw value.
|
|
193
198
|
* @returns The escaped value.
|
|
194
199
|
*/
|
|
195
200
|
protected static EscapeSingleQuotes(value: string): string;
|
|
201
|
+
/**
|
|
202
|
+
* Escapes a value for embedding in a template literal (the `describe()` text): backslash, backtick and `${`.
|
|
203
|
+
*
|
|
204
|
+
* @param value - The raw value.
|
|
205
|
+
* @returns The escaped value.
|
|
206
|
+
*/
|
|
207
|
+
protected static EscapeTemplateLiteralText(value: string): string;
|
|
208
|
+
/** Whether generated class source calls `UUIDsEqual`, so the file header must import it. */
|
|
209
|
+
protected static CallsUUIDsEqual(source: string): boolean;
|
|
210
|
+
/** Quotes a value-list value for the TS union / `z.literal`, escaping it when the field's values are strings. */
|
|
211
|
+
protected static ValueListLiteral(field: EntityFieldInfo, value: string): string;
|
|
196
212
|
/**
|
|
197
213
|
* Emits `{Field}_Object` / `{Field}_EnsureObject()` for every FK field whose
|
|
198
214
|
* `EmbeddedRecord` column holds a config object.
|
|
@@ -261,6 +277,18 @@ export declare class EntitySubClassGeneratorBase {
|
|
|
261
277
|
};
|
|
262
278
|
/** Key → translation for every resolved SQL `@CHECK` of the run. Tolerates a manage-metadata that predates them. */
|
|
263
279
|
private collectJSONTranslations;
|
|
280
|
+
/**
|
|
281
|
+
* Keeps one validator per CHECK constraint source (#5834). Two stored `GeneratedCode` rows can
|
|
282
|
+
* carry the same constraint under different function names (an app's pinned row beside the one
|
|
283
|
+
* CodeGen generated earlier); emitting both would run the same check twice. The key is the field
|
|
284
|
+
* (or table level) plus the constraint text; the first validator in the given order is kept and
|
|
285
|
+
* the dropped rows' GeneratedCode IDs are logged so they can be cleaned up.
|
|
286
|
+
*
|
|
287
|
+
* @param entityName - Entity name, for the warning.
|
|
288
|
+
* @param validators - The entity's validators, already in emit order.
|
|
289
|
+
* @returns The validators with later same-source duplicates removed.
|
|
290
|
+
*/
|
|
291
|
+
protected static DedupeValidatorsBySource(entityName: string, validators: ValidatorResult[]): ValidatorResult[];
|
|
264
292
|
GenerateValidateFunction(entity: EntityInfo): null | {
|
|
265
293
|
code: string;
|
|
266
294
|
validators: ValidatorResult[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity_subclasses_codegen.d.ts","sourceRoot":"","sources":["../../src/Misc/entity_subclasses_codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,eAAe,EAA4B,UAAU,EAAE,sBAAsB,EAAuC,MAAM,sBAAsB,CAAC;AAO/L,OAAO,EAAE,eAAe,EAAsB,MAAM,6BAA6B,CAAC;AAElF,OAAO,EAA6B,aAAa,EAAsD,MAAM,mBAAmB,CAAC;AAGjI,OAAO,EAAoE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAErH,OAAO,EAAE,iBAAiB,EAAkC,MAAM,qCAAqC,CAAC;AAMxG,OAAO,EACL,iBAAiB,EASlB,MAAM,eAAe,CAAC;AA2DvB;;;;;;;;;;GAUG;AACH;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,mGAAmG;IACnG,IAAI,EAAE,MAAM,CAAC;IACb,sEAAsE;IACtE,IAAI,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;IACnD,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1C,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAA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E,UAAU,GAAG,MAAM;IAqExD;;;;;;OAMG;IACI,sBAAsB,CAAC,WAAW,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM;CA0BzF"}
|
|
@@ -13,7 +13,7 @@ import { configInfo, DbPlatform, MjCoreSchema, ResolveEntityImportPackage } from
|
|
|
13
13
|
import { SQLLogging } from './sql_logging.js';
|
|
14
14
|
import { ResolveCodeGenDatabaseProvider } from '../Database/codeGenDatabaseProvider.js';
|
|
15
15
|
import { CodeGenReporter } from './codegen-reporter.js';
|
|
16
|
-
import { NormalizeGeneratedValidatorText } from './validator-text.js';
|
|
16
|
+
import { NormalizeGeneratedValidatorText, RewriteUUIDComparisons, UUIDS_EQUAL_FUNCTION_NAME } from './validator-text.js';
|
|
17
17
|
import { v4 as uuidv4 } from 'uuid';
|
|
18
18
|
import { EmitStats } from './emit-stats.js';
|
|
19
19
|
import { BuildSchemaBarrel, GroupEntitiesBySchema, MapLimit, EmitSchemaFile, PruneOrphanedSchemaFiles, ResolveSchemaEmitOptions, SanitizeSchemaFileName, SchemasToEmit, } from './schema-emit.js';
|
|
@@ -215,7 +215,8 @@ export class EntitySubClassGeneratorBase {
|
|
|
215
215
|
const peerImports = entitiesWithPK.flatMap((e) => EntitySubClassGeneratorBase.CollectPeerClassImports(e, localClassNames));
|
|
216
216
|
const peerImportStatements = EntitySubClassGeneratorBase.FormatPeerImportStatements(peerImports).join('');
|
|
217
217
|
const subclassImports = `${baseClassImports}${peerImportStatements}`;
|
|
218
|
-
|
|
218
|
+
const usesUUIDsEqual = EntitySubClassGeneratorBase.CallsUUIDsEqual(sContent);
|
|
219
|
+
return `${this.GenerateEntitySubClassFileHeader(includeLoadModule, usesUUIDsEqual)} \n ${subclassImports}${zodContent} \n ${sContent}`;
|
|
219
220
|
}
|
|
220
221
|
/** @deprecated Use {@link AssembleEntitySubclassFile}. */
|
|
221
222
|
async assembleEntitySubclassFile(pool, entities, skipDBUpdate, includeLoadModule) {
|
|
@@ -229,7 +230,11 @@ export class EntitySubClassGeneratorBase {
|
|
|
229
230
|
emitFile(filePath, content, useWriteIfChanged) {
|
|
230
231
|
EmitSchemaFile(filePath, content, useWriteIfChanged);
|
|
231
232
|
}
|
|
232
|
-
|
|
233
|
+
/**
|
|
234
|
+
* @param includeLoadModule - Emit the `loadModule` no-op export.
|
|
235
|
+
* @param usesUUIDsEqual - Import `UUIDsEqual` as well; set when a generated validator in the file calls it.
|
|
236
|
+
*/
|
|
237
|
+
GenerateEntitySubClassFileHeader(includeLoadModule = true, usesUUIDsEqual = false) {
|
|
233
238
|
const loadModule = includeLoadModule
|
|
234
239
|
? `
|
|
235
240
|
export const loadModule = () => {
|
|
@@ -238,14 +243,14 @@ export const loadModule = () => {
|
|
|
238
243
|
`
|
|
239
244
|
: '';
|
|
240
245
|
return `import { BaseEntity, EntitySaveOptions, EntityDeleteOptions, CompositeKey, ValidationResult, ValidationErrorInfo, ValidationErrorType, Metadata, ProviderType, DatabaseProviderBase, RunView } from "@memberjunction/core";
|
|
241
|
-
import { RegisterClass } from "@memberjunction/global";
|
|
246
|
+
import { RegisterClass${usesUUIDsEqual ? `, ${UUIDS_EQUAL_FUNCTION_NAME}` : ''} } from "@memberjunction/global";
|
|
242
247
|
import { z } from "zod";
|
|
243
248
|
${loadModule}
|
|
244
249
|
`;
|
|
245
250
|
}
|
|
246
251
|
/** @deprecated Use {@link GenerateEntitySubClassFileHeader}. */
|
|
247
|
-
generateEntitySubClassFileHeader(includeLoadModule = true) {
|
|
248
|
-
return this.GenerateEntitySubClassFileHeader(includeLoadModule);
|
|
252
|
+
generateEntitySubClassFileHeader(includeLoadModule = true, usesUUIDsEqual = false) {
|
|
253
|
+
return this.GenerateEntitySubClassFileHeader(includeLoadModule, usesUUIDsEqual);
|
|
249
254
|
}
|
|
250
255
|
/**
|
|
251
256
|
* Resolves an entity's generated base class and the import statement that class requires.
|
|
@@ -357,7 +362,7 @@ ${loadModule}
|
|
|
357
362
|
if (e.ValueListType && e.ValueListType.length > 0 && e.ValueListType.trim().toLowerCase() !== 'none') {
|
|
358
363
|
// Sort by Sequence to ensure consistent ordering in comments
|
|
359
364
|
const sortedValues = SortBySequenceAndCreatedAt([...e.EntityFieldValues]);
|
|
360
|
-
values = sortedValues.map((v) => `\n * * ${v.Value}${v.Description && v.Description.length > 0 ? ' - ' + EntitySubClassGeneratorBase.SanitizeDescription(v.Description) : ''}`).join('');
|
|
365
|
+
values = sortedValues.map((v) => `\n * * ${EntitySubClassGeneratorBase.SanitizeDescription(v.Value)}${v.Description && v.Description.length > 0 ? ' - ' + EntitySubClassGeneratorBase.SanitizeDescription(v.Description) : ''}`).join('');
|
|
361
366
|
valueList = `\n * * Value List Type: ${e.ValueListType}\n * * Possible Values ` + values;
|
|
362
367
|
}
|
|
363
368
|
// JSONType: when a field has JSONType metadata, we emit the standard string getter/setter
|
|
@@ -377,10 +382,9 @@ ${loadModule}
|
|
|
377
382
|
}
|
|
378
383
|
if (!hasJSONType && EmitsValueListUnion(e)) {
|
|
379
384
|
// construct a typeString that is a union of the possible values
|
|
380
|
-
const quotes = e.NeedsQuotes ? "'" : '';
|
|
381
385
|
// Sort deterministically by Sequence, CreatedAt, then Value to prevent flip-flopping across runs
|
|
382
386
|
const sortedValues = SortBySequenceAndCreatedAt([...e.EntityFieldValues]);
|
|
383
|
-
typeString = sortedValues.map((v) =>
|
|
387
|
+
typeString = sortedValues.map((v) => EntitySubClassGeneratorBase.ValueListLiteral(e, v.Value)).join(' | ');
|
|
384
388
|
if (e.ValueListTypeEnum === EntityFieldValueListType.ListOrUserEntry) {
|
|
385
389
|
// special case becuase a user can enter whatever they want
|
|
386
390
|
typeString += ' | ' + TypeScriptTypeFromSQLType(e.Type);
|
|
@@ -576,7 +580,7 @@ ${fields}
|
|
|
576
580
|
}
|
|
577
581
|
`;
|
|
578
582
|
if (includeFileHeader)
|
|
579
|
-
sRet = this.GenerateEntitySubClassFileHeader() + sRet;
|
|
583
|
+
sRet = this.GenerateEntitySubClassFileHeader(true, EntitySubClassGeneratorBase.CallsUUIDsEqual(sRet)) + sRet;
|
|
580
584
|
return sRet;
|
|
581
585
|
}
|
|
582
586
|
/** @deprecated Use {@link GenerateEntitySubClass}. */
|
|
@@ -807,13 +811,37 @@ ${fields}
|
|
|
807
811
|
`;
|
|
808
812
|
}
|
|
809
813
|
/**
|
|
810
|
-
* Escapes a value for safe embedding in a single-quoted TypeScript string literal
|
|
814
|
+
* Escapes a value for safe embedding in a single-quoted TypeScript string literal: backslash,
|
|
815
|
+
* single quote, and the line terminators a string literal cannot hold (CR, LF, U+2028, U+2029).
|
|
811
816
|
*
|
|
812
817
|
* @param value - The raw value.
|
|
813
818
|
* @returns The escaped value.
|
|
814
819
|
*/
|
|
815
820
|
static EscapeSingleQuotes(value) {
|
|
816
|
-
return String(value ?? '')
|
|
821
|
+
return String(value ?? '')
|
|
822
|
+
.replace(/\\/g, '\\\\')
|
|
823
|
+
.replace(/'/g, "\\'")
|
|
824
|
+
.replace(/\n/g, '\\n')
|
|
825
|
+
.replace(/\r/g, '\\r')
|
|
826
|
+
.replace(/\u2028/g, '\\u2028')
|
|
827
|
+
.replace(/\u2029/g, '\\u2029');
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Escapes a value for embedding in a template literal (the `describe()` text): backslash, backtick and `${`.
|
|
831
|
+
*
|
|
832
|
+
* @param value - The raw value.
|
|
833
|
+
* @returns The escaped value.
|
|
834
|
+
*/
|
|
835
|
+
static EscapeTemplateLiteralText(value) {
|
|
836
|
+
return String(value ?? '').replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${');
|
|
837
|
+
}
|
|
838
|
+
/** Whether generated class source calls `UUIDsEqual`, so the file header must import it. */
|
|
839
|
+
static CallsUUIDsEqual(source) {
|
|
840
|
+
return source.includes(`${UUIDS_EQUAL_FUNCTION_NAME}(`);
|
|
841
|
+
}
|
|
842
|
+
/** Quotes a value-list value for the TS union / `z.literal`, escaping it when the field's values are strings. */
|
|
843
|
+
static ValueListLiteral(field, value) {
|
|
844
|
+
return field.NeedsQuotes ? `'${EntitySubClassGeneratorBase.EscapeSingleQuotes(value)}'` : value;
|
|
817
845
|
}
|
|
818
846
|
/**
|
|
819
847
|
* Emits `{Field}_Object` / `{Field}_EnsureObject()` for every FK field whose
|
|
@@ -1211,6 +1239,39 @@ VALUES (${lit(newGeneratedCodeId)}, ${validatorCodeCategoryID}, ${lit(v.aiModelI
|
|
|
1211
1239
|
const resolved = ManageMetadataBase.GeneratedJSONValidators ?? [];
|
|
1212
1240
|
return new Map(resolved.map((r) => [r.Key, { Description: r.FunctionDescription, Body: r.FunctionText }]));
|
|
1213
1241
|
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Keeps one validator per CHECK constraint source (#5834). Two stored `GeneratedCode` rows can
|
|
1244
|
+
* carry the same constraint under different function names (an app's pinned row beside the one
|
|
1245
|
+
* CodeGen generated earlier); emitting both would run the same check twice. The key is the field
|
|
1246
|
+
* (or table level) plus the constraint text; the first validator in the given order is kept and
|
|
1247
|
+
* the dropped rows' GeneratedCode IDs are logged so they can be cleaned up.
|
|
1248
|
+
*
|
|
1249
|
+
* @param entityName - Entity name, for the warning.
|
|
1250
|
+
* @param validators - The entity's validators, already in emit order.
|
|
1251
|
+
* @returns The validators with later same-source duplicates removed.
|
|
1252
|
+
*/
|
|
1253
|
+
static DedupeValidatorsBySource(entityName, validators) {
|
|
1254
|
+
const firstBySource = new Map();
|
|
1255
|
+
const result = [];
|
|
1256
|
+
for (const v of validators) {
|
|
1257
|
+
const key = `${v.fieldName ? v.fieldName.trim().toLowerCase() : ''}\u0000${(v.sourceCheckConstraint ?? '').trim()}`;
|
|
1258
|
+
const existing = firstBySource.get(key);
|
|
1259
|
+
if (existing) {
|
|
1260
|
+
existing.Dropped.push(v);
|
|
1261
|
+
}
|
|
1262
|
+
else {
|
|
1263
|
+
firstBySource.set(key, { Kept: v, Dropped: [] });
|
|
1264
|
+
result.push(v);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
for (const { Kept, Dropped } of firstBySource.values()) {
|
|
1268
|
+
if (Dropped.length === 0)
|
|
1269
|
+
continue;
|
|
1270
|
+
const ids = Dropped.map((v) => v.generatedCodeId || '(unsaved)').join(', ');
|
|
1271
|
+
LogWarning(`${entityName}${Kept.fieldName ? '.' + Kept.fieldName : ' (table level)'}: ${Dropped.length + 1} generated validators share one CHECK constraint; emitting ${Kept.functionName} (GeneratedCode ${Kept.generatedCodeId || '(unsaved)'}) and dropping GeneratedCode ${ids}. Delete the dropped rows to stop this warning.`);
|
|
1272
|
+
}
|
|
1273
|
+
return result;
|
|
1274
|
+
}
|
|
1214
1275
|
GenerateValidateFunction(entity) {
|
|
1215
1276
|
// go through the ManageMetadataBase.generatedFieldValidators to see if we have anything to generate
|
|
1216
1277
|
const unsortedValidators = ManageMetadataBase.generatedValidators.filter((f) => f.entityName.trim().toLowerCase() === entity.Name.trim().toLowerCase());
|
|
@@ -1239,7 +1300,7 @@ VALUES (${lit(newGeneratedCodeId)}, ${validatorCodeCategoryID}, ${lit(v.aiModelI
|
|
|
1239
1300
|
// previously failed to match (e.g., whitespace differences in CHECK constraint text).
|
|
1240
1301
|
// Keep the first occurrence of each functionName (which is the earliest by sort order).
|
|
1241
1302
|
const seenFunctionNames = new Set();
|
|
1242
|
-
const validators = sortedValidators.filter((v) => {
|
|
1303
|
+
const validators = EntitySubClassGeneratorBase.DedupeValidatorsBySource(entity.Name, sortedValidators).filter((v) => {
|
|
1243
1304
|
if (seenFunctionNames.has(v.functionName)) {
|
|
1244
1305
|
return false;
|
|
1245
1306
|
}
|
|
@@ -1251,9 +1312,11 @@ VALUES (${lit(newGeneratedCodeId)}, ${validatorCodeCategoryID}, ${lit(v.aiModelI
|
|
|
1251
1312
|
return null;
|
|
1252
1313
|
}
|
|
1253
1314
|
else {
|
|
1315
|
+
// Property names of the UUID fields, so validator comparisons between them use UUIDsEqual (#3984).
|
|
1316
|
+
const uuidFieldNames = new Set((entity.Fields ?? []).filter((ef) => ef.IsUniqueIdentifier).map((ef) => SafeCodeName(ef)));
|
|
1254
1317
|
const validationFunctions = validators.map((f) => {
|
|
1255
1318
|
// output the function text and the function description in a JSDoc block
|
|
1256
|
-
const cleansedText = NormalizeGeneratedValidatorText(f.functionText);
|
|
1319
|
+
const cleansedText = RewriteUUIDComparisons(NormalizeGeneratedValidatorText(f.functionText), uuidFieldNames);
|
|
1257
1320
|
// next up, format the function text to have proper indentation with 4 spaces preceding the start of each line
|
|
1258
1321
|
const formattedText = cleansedText.split('\n').map((l) => ` ${l}`).join('\n');
|
|
1259
1322
|
return ` /**
|
|
@@ -1345,12 +1408,11 @@ ${validationFunctions.length > 0 ? '\n' + validationFunctions : ''}`;
|
|
|
1345
1408
|
}
|
|
1346
1409
|
else if (EmitsValueListUnion(e)) {
|
|
1347
1410
|
// construct a typeString that is a union of the possible values
|
|
1348
|
-
const quotes = e.NeedsQuotes ? "'" : '';
|
|
1349
1411
|
// Sort deterministically by Sequence, CreatedAt, then Value to prevent flip-flopping across runs
|
|
1350
1412
|
const sortedValues = SortBySequenceAndCreatedAt([...e.EntityFieldValues]);
|
|
1351
1413
|
// z.union() requires at least 2 members. When there's only one allowed
|
|
1352
1414
|
// value (single-value CHECK constraint), emit z.literal() directly.
|
|
1353
|
-
const literals = sortedValues.map((v) => `z.literal(${
|
|
1415
|
+
const literals = sortedValues.map((v) => `z.literal(${EntitySubClassGeneratorBase.ValueListLiteral(e, v.Value)})`);
|
|
1354
1416
|
typeString = literals.length === 1
|
|
1355
1417
|
? literals[0].substring(2) // strip leading 'z.' since caller prepends it
|
|
1356
1418
|
: `union([${literals.join(', ')}])`;
|
|
@@ -1394,7 +1456,7 @@ export type ${entity.ClassName}EntityType = z.infer<typeof ${schemaName}>;
|
|
|
1394
1456
|
if (entityField.ValueListType && entityField.ValueListType.length > 0 && entityField.ValueListType.trim().toLowerCase() !== 'none') {
|
|
1395
1457
|
// Sort by Sequence to ensure consistent ordering in comments
|
|
1396
1458
|
const sortedValues = SortBySequenceAndCreatedAt([...entityField.EntityFieldValues]);
|
|
1397
|
-
let values = sortedValues.map((v) => `\n * * ${v.Value}${v.Description && v.Description.length > 0 ? ' - ' + EntitySubClassGeneratorBase.SanitizeDescription(v.Description) : ''}`).join('');
|
|
1459
|
+
let values = sortedValues.map((v) => `\n * * ${EntitySubClassGeneratorBase.EscapeTemplateLiteralText(v.Value)}${v.Description && v.Description.length > 0 ? ' - ' + EntitySubClassGeneratorBase.SanitizeDescription(v.Description) : ''}`).join('');
|
|
1398
1460
|
valueList = `\n * * Value List Type: ${entityField.ValueListType}\n * * Possible Values ` + values;
|
|
1399
1461
|
}
|
|
1400
1462
|
result += ` * * Field Name: ${entityField.Name}${entityField.DisplayName && entityField.DisplayName.length > 0 ? '\n * * Display Name: ' + entityField.DisplayName : ''}\n`;
|