@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
package/dist/runCodeGen.js
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
* Supports both SQL Server and PostgreSQL database platforms via the dbPlatform configuration.
|
|
8
8
|
*/
|
|
9
9
|
import { GraphQLServerGeneratorBase } from './Misc/graphql_server_codegen.js';
|
|
10
|
-
import { SQLCodeGenBase } from './Database/sql_codegen.js';
|
|
10
|
+
import { SQLCodeGenBase, EntitiesNotInExcludedSchemas } from './Database/sql_codegen.js';
|
|
11
11
|
import { EntitySubClassGeneratorBase } from './Misc/entity_subclasses_codegen.js';
|
|
12
12
|
import { ManageMetadataBase } from './Database/manage-metadata.js';
|
|
13
13
|
import { ApplyIncludeSchemaScope } from './Database/schema-scope.js';
|
|
14
14
|
import { PartitionEntitiesByOutputDirectory } from './Config/schema-output.js';
|
|
15
|
-
import { OutputDir, Commands, configInfo, GetSettingValue, DbPlatform, GetExternalEntitySchemas, InitializeConfig, ApplyInProcessAdvancedGenerationPolicy, IN_PROCESS_ADVANCED_GENERATION_ENV } from './Config/config.js';
|
|
15
|
+
import { OutputDir, Commands, configInfo, GetSettingValue, DbPlatform, GetExternalEntitySchemas, InitializeConfig, ApplyInProcessAdvancedGenerationPolicy, IN_PROCESS_ADVANCED_GENERATION_ENV, FindUnknownAdvancedGenerationFeatures, KNOWN_ADVANCED_GENERATION_FEATURES } from './Config/config.js';
|
|
16
16
|
import { ResolveDirtySchemasForEmit, SchemaKey } from './Misc/schema-emit.js';
|
|
17
17
|
import { EmitStats } from './Misc/emit-stats.js';
|
|
18
18
|
import { logError, logStatus, LogWarning, StartSpinner, UpdateSpinner, SucceedSpinner, FailSpinner, WarnSpinner } from './Misc/status_logging.js';
|
|
@@ -29,24 +29,74 @@ import { SQLLogging } from './Misc/sql_logging.js';
|
|
|
29
29
|
import { ResolveCodeGenDatabaseProvider } from './Database/codeGenDatabaseProvider.js';
|
|
30
30
|
import { SystemIntegrityBase } from './Misc/system_integrity.js';
|
|
31
31
|
import { ReconcileFieldLevelSecurity } from './Database/reconcileFieldLevelSecurity.js';
|
|
32
|
+
import { RunQueryRebindPass } from './Database/queryRebindPass.js';
|
|
32
33
|
import { ActionEngineBase } from '@memberjunction/actions-base';
|
|
33
34
|
import { AIEngine } from '@memberjunction/aiengine';
|
|
34
35
|
// Import pre-built MJ class registrations manifest (covers all @memberjunction/* packages)
|
|
35
36
|
import '@memberjunction/server-bootstrap-lite/mj-class-registrations';
|
|
36
37
|
/** Extract core schema name from configuration */
|
|
37
38
|
const { mjCoreSchema } = configInfo;
|
|
39
|
+
/**
|
|
40
|
+
* Failure context for the SQL generation/execution pass. Named so the CRUD self-heal can clear
|
|
41
|
+
* exactly this entry when it repairs what the pass left missing.
|
|
42
|
+
*/
|
|
43
|
+
const SQL_PASS_FAILURE_CONTEXT = 'SQL_PASS';
|
|
38
44
|
/**
|
|
39
45
|
* Main orchestrator class for the MemberJunction code generation process.
|
|
40
46
|
*/
|
|
47
|
+
/**
|
|
48
|
+
* Counts validators by identity (`entityName|functionName`, entity compared case-insensitively),
|
|
49
|
+
* so a validator regenerated or loaded twice is reported once.
|
|
50
|
+
*/
|
|
51
|
+
export function CountDistinctValidators(validators) {
|
|
52
|
+
return new Set(validators.map((v) => `${v.entityName.toLowerCase()}|${v.functionName}`)).size;
|
|
53
|
+
}
|
|
41
54
|
export class RunCodeGenBase {
|
|
42
55
|
constructor() {
|
|
43
56
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
57
|
+
* Every step failure captured during a pipeline run: BEFORE/AFTER commands, SQL scripts,
|
|
58
|
+
* metadata management, the SQL pass, validators, file generation and integrity checks.
|
|
59
|
+
* The pipeline runs every step to the end, then fails (success=false, non-zero exit) with
|
|
60
|
+
* this full list, instead of stopping at the first failure or logging and reporting success.
|
|
47
61
|
*/
|
|
48
62
|
this.commandFailures = [];
|
|
49
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* The entities the post-run CRUD validator expects routines for: IncludeInAPI and in scope. An
|
|
66
|
+
* out-of-scope schema's routines belong to another run (#3384).
|
|
67
|
+
*/
|
|
68
|
+
static CRUDValidationBaseline(entities, excludeSchemas) {
|
|
69
|
+
return EntitiesNotInExcludedSchemas(entities.filter(e => e.IncludeInAPI), excludeSchemas ?? []);
|
|
70
|
+
}
|
|
71
|
+
/** Records a step failure for the end-of-run list, and logs it now. */
|
|
72
|
+
RecordStepFailure(context, message) {
|
|
73
|
+
this.commandFailures.push({ context, message });
|
|
74
|
+
logError(`${context}: ${message}`);
|
|
75
|
+
CodeGenReporter.Instance.note(`${context}: ${message}`);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* True when a CORE file-generation pass has no in-scope entities, so it must not run (#3384). Those
|
|
79
|
+
* passes rewrite whole files from the entity list, so running one on an empty list (the core schema
|
|
80
|
+
* left out of `includeSchemas`, or excluded) would empty its output. The skip is logged as a warning.
|
|
81
|
+
* @param passLabel name of the pass, for the log
|
|
82
|
+
* @param entities the pass's scope-narrowed entity list
|
|
83
|
+
*/
|
|
84
|
+
static SkipEmptyCorePass(passLabel, entities) {
|
|
85
|
+
if (entities.length > 0) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
LogWarning(`Skipping ${passLabel}: no in-scope core entities (the core schema is excluded or not in includeSchemas); existing output left unchanged`);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Formats the end-of-run failure list. Returns an empty string when there are none.
|
|
93
|
+
*/
|
|
94
|
+
static FormatStepFailures(failures) {
|
|
95
|
+
if (failures.length === 0)
|
|
96
|
+
return '';
|
|
97
|
+
const lines = failures.map((f, i) => ` ${i + 1}. [${f.context}] ${f.message}`);
|
|
98
|
+
return `CodeGen finished with ${failures.length} failure${failures.length === 1 ? '' : 's'}:\n${lines.join('\n')}`;
|
|
99
|
+
}
|
|
50
100
|
/**
|
|
51
101
|
* Record any failed entries from a BEFORE/AFTER command batch, paired by index.
|
|
52
102
|
*
|
|
@@ -198,12 +248,15 @@ export class RunCodeGenBase {
|
|
|
198
248
|
const { provider, connection: conn, currentUser } = dataSource;
|
|
199
249
|
const startTime = new Date();
|
|
200
250
|
ManageMetadataBase.clearFieldTracking();
|
|
251
|
+
ManageMetadataBase.ClearFieldShapeChanges();
|
|
201
252
|
const reporter = CodeGenReporter.Instance;
|
|
202
253
|
reporter.startRun();
|
|
203
254
|
reporter.mark('platform', DbPlatform());
|
|
204
255
|
reporter.mark('skipDB', skipDatabaseGeneration || GetSettingValue('skip_database_generation', false));
|
|
205
256
|
let pipelineSuccess = true;
|
|
206
257
|
this.commandFailures = [];
|
|
258
|
+
// Saved queries the re-bind pass could not refresh. Warnings only: never a step failure.
|
|
259
|
+
let queryRebindWarnings = [];
|
|
207
260
|
try {
|
|
208
261
|
const md = await reporter.phase('loadMetadata', async () => {
|
|
209
262
|
const m = new MJ.Metadata();
|
|
@@ -215,6 +268,9 @@ export class RunCodeGenBase {
|
|
|
215
268
|
StartSpinner('Initializing AI Engine for advanced generation...');
|
|
216
269
|
await AIEngine.Instance.Config(false, currentUser);
|
|
217
270
|
SucceedSpinner('AI Engine initialized');
|
|
271
|
+
for (const name of FindUnknownAdvancedGenerationFeatures(configInfo.advancedGeneration.features)) {
|
|
272
|
+
LogWarning(`advancedGeneration.features: CodeGen does not read a feature named '${name}', so it has no effect. Known features: ${KNOWN_ADVANCED_GENERATION_FEATURES.join(', ')}.`);
|
|
273
|
+
}
|
|
218
274
|
}
|
|
219
275
|
return m;
|
|
220
276
|
});
|
|
@@ -246,8 +302,10 @@ export class RunCodeGenBase {
|
|
|
246
302
|
}
|
|
247
303
|
}
|
|
248
304
|
UpdateSpinner('Executing before-all SQL Scripts...');
|
|
249
|
-
if (!(await sqlCodeGenObject.runCustomSQLScripts(conn, 'before-all')))
|
|
250
|
-
|
|
305
|
+
if (!(await sqlCodeGenObject.runCustomSQLScripts(conn, 'before-all'))) {
|
|
306
|
+
this.RecordStepFailure('BEFORE_ALL_SQL', 'One or more before-all SQL scripts failed');
|
|
307
|
+
pipelineSuccess = false;
|
|
308
|
+
}
|
|
251
309
|
const newUserSetup = configInfo.newUserSetup;
|
|
252
310
|
if (newUserSetup) {
|
|
253
311
|
UpdateSpinner('Setting up new user...');
|
|
@@ -255,8 +313,8 @@ export class RunCodeGenBase {
|
|
|
255
313
|
const result = await newUserObject.createNewUser(newUserSetup);
|
|
256
314
|
if (!result.Success) {
|
|
257
315
|
if (result.Severity === 'error') {
|
|
258
|
-
|
|
259
|
-
|
|
316
|
+
this.RecordStepFailure('NEW_USER_SETUP', result.Message);
|
|
317
|
+
pipelineSuccess = false;
|
|
260
318
|
}
|
|
261
319
|
else {
|
|
262
320
|
LogWarning('Warning: (New User Setup) ' + result.Message);
|
|
@@ -275,6 +333,7 @@ export class RunCodeGenBase {
|
|
|
275
333
|
await this.refreshMetadataAfterManageMetadata(provider);
|
|
276
334
|
if (!metadataSuccess) {
|
|
277
335
|
FailSpinner('ERROR managing metadata (refresh applied; downstream will use latest available state)');
|
|
336
|
+
this.RecordStepFailure('MANAGE_METADATA', 'Metadata management reported a failure; see the errors logged above');
|
|
278
337
|
pipelineSuccess = false;
|
|
279
338
|
}
|
|
280
339
|
else {
|
|
@@ -285,7 +344,11 @@ export class RunCodeGenBase {
|
|
|
285
344
|
// FLS-enabled entity a field with no permission rows is DENIED, so a column added
|
|
286
345
|
// without this step would be invisible to every user until something else reconciled.
|
|
287
346
|
// It also removes rows orphaned by a dropped column or a revoked role.
|
|
288
|
-
await reporter.phase('reconcileFieldPermissions', () => ReconcileFieldLevelSecurity(provider, currentUser));
|
|
347
|
+
const flsOk = await reporter.phase('reconcileFieldPermissions', () => ReconcileFieldLevelSecurity(provider, currentUser));
|
|
348
|
+
if (flsOk === false) {
|
|
349
|
+
this.RecordStepFailure('FIELD_LEVEL_SECURITY', 'Field-level security reconciliation failed');
|
|
350
|
+
pipelineSuccess = false;
|
|
351
|
+
}
|
|
289
352
|
const sqlOutputDir = OutputDir('SQL', true);
|
|
290
353
|
let sqlGenerationSucceeded = true;
|
|
291
354
|
if (sqlOutputDir) {
|
|
@@ -293,6 +356,7 @@ export class RunCodeGenBase {
|
|
|
293
356
|
const sqlSuccess = await reporter.phase('manageSQLScriptsAndExecution', () => sqlCodeGenObject.manageSQLScriptsAndExecution(conn, md.Entities, sqlOutputDir, currentUser));
|
|
294
357
|
if (!sqlSuccess) {
|
|
295
358
|
FailSpinner('Error managing SQL scripts and execution');
|
|
359
|
+
this.RecordStepFailure(SQL_PASS_FAILURE_CONTEXT, 'SQL generation/execution reported a failure; see the errors logged above');
|
|
296
360
|
sqlGenerationSucceeded = false;
|
|
297
361
|
pipelineSuccess = false;
|
|
298
362
|
}
|
|
@@ -303,6 +367,15 @@ export class RunCodeGenBase {
|
|
|
303
367
|
else {
|
|
304
368
|
WarnSpinner('SQL output directory NOT found in config file, skipping...');
|
|
305
369
|
}
|
|
370
|
+
// Saved queries that read an entity whose columns changed shape in this run are re-bound
|
|
371
|
+
// once the field sync (both passes) is complete; their SQL is never edited. The pass never
|
|
372
|
+
// fails the run (nor does the metadata refresh it needs): what it could not refresh comes
|
|
373
|
+
// back as warnings, repeated beside the final summary.
|
|
374
|
+
const shapeChanges = ManageMetadataBase.FieldShapeChangedEntities;
|
|
375
|
+
if (sqlGenerationSucceeded && shapeChanges.IDs.length + shapeChanges.Names.length > 0) {
|
|
376
|
+
const rebind = await reporter.phase('queryRebind', () => RunQueryRebindPass(provider, currentUser, () => this.refreshMetadataAfterManageMetadata(provider)));
|
|
377
|
+
queryRebindWarnings = rebind.Warnings;
|
|
378
|
+
}
|
|
306
379
|
// ── Post-run CRUD validator ─────────────────────────────────────────
|
|
307
380
|
// Runs UNCONDITIONALLY even when the SQL pipeline reported failure so
|
|
308
381
|
// we always surface the runtime impact: which entities are about to
|
|
@@ -324,8 +397,9 @@ export class RunCodeGenBase {
|
|
|
324
397
|
StartSpinner('Validating expected CRUD routines exist in database...');
|
|
325
398
|
try {
|
|
326
399
|
// Use the same baseline filter as manageSQLScriptsAndExecution: only
|
|
327
|
-
// entities flagged IncludeInAPI=true
|
|
328
|
-
|
|
400
|
+
// entities flagged IncludeInAPI=true and in scope (not in an excluded schema) are
|
|
401
|
+
// expected to have routines. An out-of-scope schema's routines are another run's (#3384).
|
|
402
|
+
const baseline = RunCodeGenBase.CRUDValidationBaseline(md.Entities, configInfo.excludeSchemas);
|
|
329
403
|
let missing = await sqlCodeGenObject.DBProvider.validateExpectedCRUDFunctions(conn, baseline);
|
|
330
404
|
// Self-heal pass: when the validator finds missing routines, the
|
|
331
405
|
// root cause is almost always that a downstream view CASCADE-drop
|
|
@@ -358,6 +432,7 @@ export class RunCodeGenBase {
|
|
|
358
432
|
missing = await sqlCodeGenObject.DBProvider.validateExpectedCRUDFunctions(conn, baseline);
|
|
359
433
|
if (missing.length === 0) {
|
|
360
434
|
logStatus('Self-heal succeeded — all expected CRUD routines now exist');
|
|
435
|
+
this.commandFailures = this.commandFailures.filter((f) => f.context !== SQL_PASS_FAILURE_CONTEXT);
|
|
361
436
|
// Self-heal closed the runtime gap that the upstream batch
|
|
362
437
|
// failure left behind. Clear the upstream failure flag so
|
|
363
438
|
// codegen reports success: every entity that runtime needs
|
|
@@ -386,7 +461,8 @@ export class RunCodeGenBase {
|
|
|
386
461
|
` • Stale entity-field metadata caused per-entity PK detection to fail\n` +
|
|
387
462
|
` • Cascade-delete dependency analysis dropped entities silently\n` +
|
|
388
463
|
`Run codegen again on the same DB to see if the issue persists; if it does, this is a real generation bug.`);
|
|
389
|
-
|
|
464
|
+
this.commandFailures.push({ context: 'CRUD_VALIDATION', message: `${missing.length} expected CRUD routine(s) missing:\n${list}` });
|
|
465
|
+
pipelineSuccess = false;
|
|
390
466
|
}
|
|
391
467
|
else {
|
|
392
468
|
SucceedSpinner(`Post-CodeGen CRUD validation passed (${md.Entities.length} entities checked)`);
|
|
@@ -394,8 +470,8 @@ export class RunCodeGenBase {
|
|
|
394
470
|
}
|
|
395
471
|
catch (e) {
|
|
396
472
|
FailSpinner('Post-CodeGen CRUD validation errored');
|
|
397
|
-
|
|
398
|
-
|
|
473
|
+
this.RecordStepFailure('CRUD_VALIDATION', `CRUD validator threw: ${e instanceof Error ? e.message : String(e)}`);
|
|
474
|
+
pipelineSuccess = false;
|
|
399
475
|
}
|
|
400
476
|
}
|
|
401
477
|
// Metadata/view coherence. The CRUD validator asks "can the runtime WRITE this
|
|
@@ -434,11 +510,13 @@ export class RunCodeGenBase {
|
|
|
434
510
|
`CREATE OR REPLACE VIEW, so no DROP/CASCADE is required.`;
|
|
435
511
|
if (strict) {
|
|
436
512
|
FailSpinner(`Field-resolution validation FAILED: ${gaps.length} unreadable field(s)`);
|
|
437
|
-
|
|
438
|
-
|
|
513
|
+
this.RecordStepFailure('FIELD_RESOLUTION', summary);
|
|
514
|
+
pipelineSuccess = false;
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
WarnSpinner(`Field-resolution validation found ${gaps.length} unreadable field(s)`);
|
|
518
|
+
LogWarning(summary);
|
|
439
519
|
}
|
|
440
|
-
WarnSpinner(`Field-resolution validation found ${gaps.length} unreadable field(s)`);
|
|
441
|
-
LogWarning(summary);
|
|
442
520
|
}
|
|
443
521
|
else {
|
|
444
522
|
SucceedSpinner('Entity fields all resolve against their base views');
|
|
@@ -449,11 +527,12 @@ export class RunCodeGenBase {
|
|
|
449
527
|
WarnSpinner('Field-resolution validation could not run');
|
|
450
528
|
LogWarning(`Field-resolution validator threw: ${e instanceof Error ? e.message : String(e)}`);
|
|
451
529
|
}
|
|
452
|
-
//
|
|
453
|
-
// green validator just means whatever DID get generated is
|
|
454
|
-
// it doesn't whitewash an upstream batch error.
|
|
530
|
+
// An upstream SQL-pipeline failure stays recorded (SQL_PASS_FAILURE_CONTEXT) even if the
|
|
531
|
+
// validators passed: a green validator just means whatever DID get generated is
|
|
532
|
+
// consistent; it doesn't whitewash an upstream batch error. The run continues so every
|
|
533
|
+
// later step's failures are reported too.
|
|
455
534
|
if (!sqlGenerationSucceeded) {
|
|
456
|
-
|
|
535
|
+
pipelineSuccess = false;
|
|
457
536
|
}
|
|
458
537
|
}
|
|
459
538
|
else {
|
|
@@ -482,8 +561,10 @@ export class RunCodeGenBase {
|
|
|
482
561
|
const metadataSuccess = await reporter.phase('loadGeneratedCode', () => manageMD.loadGeneratedCode(conn, currentUser));
|
|
483
562
|
if (!metadataSuccess) {
|
|
484
563
|
FailSpinner('ERROR checking/loading AI Generated Code from Metadata');
|
|
564
|
+
// File generation is skipped below: emitting without the loaded validators would delete
|
|
565
|
+
// every committed Validate() override (see above).
|
|
566
|
+
this.RecordStepFailure('LOAD_GENERATED_CODE', 'Loading AI generated code from metadata failed; file generation was skipped');
|
|
485
567
|
pipelineSuccess = false;
|
|
486
|
-
return false;
|
|
487
568
|
}
|
|
488
569
|
else {
|
|
489
570
|
// Report the COUNT, not just success. Loading zero validators is a legitimate state for a
|
|
@@ -491,7 +572,7 @@ export class RunCodeGenBase {
|
|
|
491
572
|
// generation emits each entity as though it had no `Validate()` override, silently deleting
|
|
492
573
|
// whatever was committed. Both times that regression shipped, the log said exactly this
|
|
493
574
|
// line and nothing else. A number here makes the next one visible in CI output.
|
|
494
|
-
const loadedValidators = ManageMetadataBase.generatedValidators
|
|
575
|
+
const loadedValidators = CountDistinctValidators(ManageMetadataBase.generatedValidators);
|
|
495
576
|
SucceedSpinner(`AI Generated Code loaded from Metadata (${loadedValidators} validator${loadedValidators === 1 ? '' : 's'})`);
|
|
496
577
|
}
|
|
497
578
|
const skipFiles = skipFileGeneration || GetSettingValue('skip_file_generation', false);
|
|
@@ -499,9 +580,11 @@ export class RunCodeGenBase {
|
|
|
499
580
|
WarnSpinner('Skipping file generation (skip_file_generation = true)');
|
|
500
581
|
SQLLogging.finishSQLLogging();
|
|
501
582
|
}
|
|
583
|
+
else if (!metadataSuccess) {
|
|
584
|
+
SQLLogging.finishSQLLogging();
|
|
585
|
+
}
|
|
502
586
|
else if (!(await this.runFileGenerationPhase(conn, currentUser, md, skipDB))) {
|
|
503
587
|
pipelineSuccess = false;
|
|
504
|
-
return false;
|
|
505
588
|
}
|
|
506
589
|
StartSpinner('Running system integrity checks...');
|
|
507
590
|
// Three outcomes, not two. `SystemIntegrityBase.ClassifyResults` owns the distinction and is
|
|
@@ -529,10 +612,7 @@ export class RunCodeGenBase {
|
|
|
529
612
|
FailSpinner(`System integrity checks FAILED: ${integrityOutcome.Failures.map((f) => f.Name).join(', ')}`);
|
|
530
613
|
pipelineSuccess = false;
|
|
531
614
|
for (const failure of integrityOutcome.Failures) {
|
|
532
|
-
|
|
533
|
-
logError(msg);
|
|
534
|
-
reporter.note(msg);
|
|
535
|
-
this.commandFailures.push({ context: 'INTEGRITY_CHECK', message: msg });
|
|
615
|
+
this.RecordStepFailure('INTEGRITY_CHECK', `Integrity check '${failure.Name}' failed: ${failure.Message}`);
|
|
536
616
|
}
|
|
537
617
|
break;
|
|
538
618
|
}
|
|
@@ -558,8 +638,11 @@ export class RunCodeGenBase {
|
|
|
558
638
|
}
|
|
559
639
|
if (!skipDB) {
|
|
560
640
|
StartSpinner('Executing after-all SQL Scripts...');
|
|
561
|
-
if (!(await sqlCodeGenObject.runCustomSQLScripts(conn, 'after-all')))
|
|
641
|
+
if (!(await sqlCodeGenObject.runCustomSQLScripts(conn, 'after-all'))) {
|
|
562
642
|
FailSpinner('ERROR running after-all SQL Scripts');
|
|
643
|
+
this.RecordStepFailure('AFTER_ALL_SQL', 'One or more after-all SQL scripts failed');
|
|
644
|
+
pipelineSuccess = false;
|
|
645
|
+
}
|
|
563
646
|
else
|
|
564
647
|
SucceedSpinner('After-all SQL Scripts completed');
|
|
565
648
|
}
|
|
@@ -568,11 +651,23 @@ export class RunCodeGenBase {
|
|
|
568
651
|
// Visible final summary (succeedSpinner persists a ✔ line in both verbose and
|
|
569
652
|
// non-verbose modes). The detailed/timestamped form stays on logStatus for the
|
|
570
653
|
// verbose log + report.
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
//
|
|
574
|
-
|
|
575
|
-
|
|
654
|
+
// Any recorded step failure fails the run (success=false, exit 1) so it isn't silently
|
|
655
|
+
// swallowed. A failure that set pipelineSuccess without recording a message still fails
|
|
656
|
+
// it, with a generic entry so the list is never empty on a failed run.
|
|
657
|
+
if (!pipelineSuccess && this.commandFailures.length === 0) {
|
|
658
|
+
this.commandFailures.push({ context: 'PIPELINE', message: 'CodeGen pipeline reported a failure — see the log output above for detail.' });
|
|
659
|
+
}
|
|
660
|
+
pipelineSuccess = this.commandFailures.length === 0;
|
|
661
|
+
if (queryRebindWarnings.length > 0)
|
|
662
|
+
WarnSpinner(queryRebindWarnings.join('\n'));
|
|
663
|
+
if (pipelineSuccess) {
|
|
664
|
+
SucceedSpinner(`MJ CodeGen complete — ${md.Entities.length} entities in ${totalSeconds.toFixed(2)}s`);
|
|
665
|
+
logStatus('MJ CodeGen Complete! ' + md.Entities.length + ' entities processed in ' + totalSeconds + 's @ ' + endTime.toLocaleString());
|
|
666
|
+
}
|
|
667
|
+
else {
|
|
668
|
+
FailSpinner(`MJ CodeGen finished with ${this.commandFailures.length} failure(s) — ${md.Entities.length} entities in ${totalSeconds.toFixed(2)}s`);
|
|
669
|
+
logError(RunCodeGenBase.FormatStepFailures(this.commandFailures));
|
|
670
|
+
}
|
|
576
671
|
return pipelineSuccess;
|
|
577
672
|
}
|
|
578
673
|
catch (err) {
|
|
@@ -643,6 +738,8 @@ export class RunCodeGenBase {
|
|
|
643
738
|
*/
|
|
644
739
|
async runFileGenerationPhase(conn, currentUser, md, skipDB) {
|
|
645
740
|
const reporter = CodeGenReporter.Instance;
|
|
741
|
+
// Every generator runs even after one fails, so the run reports all failures at once.
|
|
742
|
+
let allSucceeded = true;
|
|
646
743
|
EmitStats.Reset();
|
|
647
744
|
const apiEntities = md.Entities.filter((e) => e.IncludeInAPI);
|
|
648
745
|
const excludedSchemaNames = configInfo.excludeSchemas.map(s => SchemaKey(s));
|
|
@@ -676,14 +773,15 @@ export class RunCodeGenBase {
|
|
|
676
773
|
if (!isVerbose)
|
|
677
774
|
StartSpinner('Generating TypeScript code...');
|
|
678
775
|
const graphQLCoreResolversOutputDir = OutputDir('GraphQLCoreEntityResolvers', false);
|
|
679
|
-
if (graphQLCoreResolversOutputDir) {
|
|
776
|
+
if (graphQLCoreResolversOutputDir && !RunCodeGenBase.SkipEmptyCorePass('CORE GraphQL resolvers', coreEntities)) {
|
|
680
777
|
if (isVerbose)
|
|
681
778
|
StartSpinner('Generating CORE Entity GraphQL Resolver Code...');
|
|
682
779
|
const graphQLGenerator = MJGlobal.Instance.ClassFactory.CreateInstance(GraphQLServerGeneratorBase);
|
|
683
780
|
const ok = await reporter.phase('generateGraphQLCore', async () => graphQLGenerator.generateGraphQLServerCode(coreEntities, graphQLCoreResolversOutputDir, '@memberjunction/core-entities', true, this.buildSchemaEmitOptions(coreEntities, skipDB)));
|
|
684
781
|
if (!ok) {
|
|
685
782
|
FailSpinner('Error generating GraphQL server code');
|
|
686
|
-
|
|
783
|
+
this.RecordStepFailure('FILE_GENERATION', 'Error generating CORE GraphQL server code');
|
|
784
|
+
allSucceeded = false;
|
|
687
785
|
}
|
|
688
786
|
else if (isVerbose)
|
|
689
787
|
SucceedSpinner('CORE Entity GraphQL Resolver Code generated');
|
|
@@ -708,7 +806,8 @@ export class RunCodeGenBase {
|
|
|
708
806
|
});
|
|
709
807
|
if (!ok) {
|
|
710
808
|
FailSpinner('Error generating GraphQL Resolver code');
|
|
711
|
-
|
|
809
|
+
this.RecordStepFailure('FILE_GENERATION', 'Error generating GraphQL Resolver code');
|
|
810
|
+
allSucceeded = false;
|
|
712
811
|
}
|
|
713
812
|
else if (isVerbose)
|
|
714
813
|
SucceedSpinner('GraphQL Resolver Code generated');
|
|
@@ -716,14 +815,15 @@ export class RunCodeGenBase {
|
|
|
716
815
|
else if (isVerbose)
|
|
717
816
|
WarnSpinner('GraphQL server output directory NOT found in config file, skipping...');
|
|
718
817
|
const coreEntitySubClassOutputDir = OutputDir('CoreEntitySubClasses', false);
|
|
719
|
-
if (coreEntitySubClassOutputDir && coreEntitySubClassOutputDir.length > 0) {
|
|
818
|
+
if (coreEntitySubClassOutputDir && coreEntitySubClassOutputDir.length > 0 && !RunCodeGenBase.SkipEmptyCorePass('CORE entity subclasses', coreEntities)) {
|
|
720
819
|
if (isVerbose)
|
|
721
820
|
StartSpinner('Generating CORE Entity Subclass Code...');
|
|
722
821
|
const entitySubClassGeneratorObject = MJGlobal.Instance.ClassFactory.CreateInstance(EntitySubClassGeneratorBase);
|
|
723
822
|
const ok = await reporter.phase('generateEntitySubclassesCore', () => entitySubClassGeneratorObject.generateAllEntitySubClasses(conn, coreEntities, coreEntitySubClassOutputDir, skipDB, this.buildSchemaEmitOptions(coreEntities, skipDB)));
|
|
724
823
|
if (!ok) {
|
|
725
824
|
FailSpinner('Error generating entity subclass code');
|
|
726
|
-
|
|
825
|
+
this.RecordStepFailure('FILE_GENERATION', 'Error generating CORE entity subclass code');
|
|
826
|
+
allSucceeded = false;
|
|
727
827
|
}
|
|
728
828
|
else if (isVerbose)
|
|
729
829
|
SucceedSpinner('CORE Entity Subclass Code generated');
|
|
@@ -745,7 +845,8 @@ export class RunCodeGenBase {
|
|
|
745
845
|
});
|
|
746
846
|
if (!ok) {
|
|
747
847
|
FailSpinner('Error generating entity subclass code');
|
|
748
|
-
|
|
848
|
+
this.RecordStepFailure('FILE_GENERATION', 'Error generating entity subclass code');
|
|
849
|
+
allSucceeded = false;
|
|
749
850
|
}
|
|
750
851
|
else if (isVerbose)
|
|
751
852
|
SucceedSpinner('Entity Subclass Code generated');
|
|
@@ -753,14 +854,15 @@ export class RunCodeGenBase {
|
|
|
753
854
|
else if (isVerbose)
|
|
754
855
|
WarnSpinner('Entity subclass output directory NOT found in config file, skipping...');
|
|
755
856
|
const angularCoreEntitiesOutputDir = OutputDir('AngularCoreEntities', false);
|
|
756
|
-
if (angularCoreEntitiesOutputDir) {
|
|
857
|
+
if (angularCoreEntitiesOutputDir && !RunCodeGenBase.SkipEmptyCorePass('Angular CORE entity forms', coreEntities)) {
|
|
757
858
|
if (isVerbose)
|
|
758
859
|
StartSpinner('Generating Angular CORE Entities Code...');
|
|
759
860
|
const angularGenerator = MJGlobal.Instance.ClassFactory.CreateInstance(AngularClientGeneratorBase);
|
|
760
861
|
const ok = await reporter.phase('generateAngularCore', () => angularGenerator.generateAngularCode(coreEntities, angularCoreEntitiesOutputDir, 'Core', currentUser, 'AngularCoreEntities'));
|
|
761
862
|
if (!ok) {
|
|
762
863
|
FailSpinner('Error generating Angular CORE Entities code');
|
|
763
|
-
|
|
864
|
+
this.RecordStepFailure('FILE_GENERATION', 'Error generating Angular CORE Entities code');
|
|
865
|
+
allSucceeded = false;
|
|
764
866
|
}
|
|
765
867
|
else if (isVerbose)
|
|
766
868
|
SucceedSpinner('Angular CORE Entities Code generated');
|
|
@@ -782,7 +884,8 @@ export class RunCodeGenBase {
|
|
|
782
884
|
});
|
|
783
885
|
if (!ok) {
|
|
784
886
|
FailSpinner('Error generating Angular code');
|
|
785
|
-
|
|
887
|
+
this.RecordStepFailure('FILE_GENERATION', 'Error generating Angular code');
|
|
888
|
+
allSucceeded = false;
|
|
786
889
|
}
|
|
787
890
|
else if (isVerbose)
|
|
788
891
|
SucceedSpinner('Angular Code generated');
|
|
@@ -813,7 +916,8 @@ export class RunCodeGenBase {
|
|
|
813
916
|
const ok = await reporter.phase('generateActionsCore', () => actionsGenerator.generateActions(ActionEngineBase.Instance.CoreActions, coreActionsOutputDir));
|
|
814
917
|
if (!ok) {
|
|
815
918
|
FailSpinner('Error generating CORE Actions code');
|
|
816
|
-
|
|
919
|
+
this.RecordStepFailure('FILE_GENERATION', 'Error generating CORE Actions code');
|
|
920
|
+
allSucceeded = false;
|
|
817
921
|
}
|
|
818
922
|
else if (isVerbose)
|
|
819
923
|
SucceedSpinner('CORE Actions Code generated');
|
|
@@ -826,7 +930,8 @@ export class RunCodeGenBase {
|
|
|
826
930
|
const ok = await reporter.phase('generateActions', () => actionsGenerator.generateActions(ActionEngineBase.Instance.NonCoreActions, actionsOutputDir));
|
|
827
931
|
if (!ok) {
|
|
828
932
|
FailSpinner('Error generating Actions code');
|
|
829
|
-
|
|
933
|
+
this.RecordStepFailure('FILE_GENERATION', 'Error generating Actions code');
|
|
934
|
+
allSucceeded = false;
|
|
830
935
|
}
|
|
831
936
|
else if (isVerbose)
|
|
832
937
|
SucceedSpinner('Actions Code generated');
|
|
@@ -906,7 +1011,8 @@ export class RunCodeGenBase {
|
|
|
906
1011
|
const ok = await reporter.phase(target.phase, () => remoteOpsGenerator.generateRemoteOperations(target.ops, target.dir));
|
|
907
1012
|
if (!ok) {
|
|
908
1013
|
FailSpinner(`Error generating ${target.label} code`);
|
|
909
|
-
|
|
1014
|
+
this.RecordStepFailure('FILE_GENERATION', `Error generating ${target.label} code`);
|
|
1015
|
+
allSucceeded = false;
|
|
910
1016
|
}
|
|
911
1017
|
else if (isVerbose)
|
|
912
1018
|
SucceedSpinner(`${target.label} typed bases generated`);
|
|
@@ -924,9 +1030,13 @@ export class RunCodeGenBase {
|
|
|
924
1030
|
`schemas emitted ${emit.schemasEmitted} / skipped ${emit.schemasSkipped} ` +
|
|
925
1031
|
`(assemble ${emit.assembleMs}ms)`);
|
|
926
1032
|
SQLLogging.finishSQLLogging();
|
|
927
|
-
if (!isVerbose)
|
|
928
|
-
|
|
929
|
-
|
|
1033
|
+
if (!isVerbose) {
|
|
1034
|
+
if (allSucceeded)
|
|
1035
|
+
SucceedSpinner('TypeScript code generation completed');
|
|
1036
|
+
else
|
|
1037
|
+
FailSpinner('TypeScript code generation finished with failures');
|
|
1038
|
+
}
|
|
1039
|
+
return allSucceeded;
|
|
930
1040
|
}
|
|
931
1041
|
}
|
|
932
1042
|
/**
|