@memberjunction/codegen-lib 6.2.0-edge.4 → 6.2.0-edge.5
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 +7 -0
- package/dist/Angular/angular-codegen.d.ts.map +1 -1
- package/dist/Angular/angular-codegen.js +2 -0
- package/dist/Angular/angular-codegen.js.map +1 -1
- package/dist/Config/config.d.ts +36 -0
- package/dist/Config/config.d.ts.map +1 -1
- package/dist/Config/config.js +33 -0
- package/dist/Config/config.js.map +1 -1
- package/dist/Database/codeGenDatabaseProvider.d.ts +118 -2
- package/dist/Database/codeGenDatabaseProvider.d.ts.map +1 -1
- package/dist/Database/codeGenDatabaseProvider.js +234 -4
- package/dist/Database/codeGenDatabaseProvider.js.map +1 -1
- package/dist/Database/heal-schema-params.d.ts +7 -0
- package/dist/Database/heal-schema-params.d.ts.map +1 -1
- package/dist/Database/heal-schema-params.js +5 -0
- package/dist/Database/heal-schema-params.js.map +1 -1
- package/dist/Database/manage-metadata.d.ts +169 -1
- package/dist/Database/manage-metadata.d.ts.map +1 -1
- package/dist/Database/manage-metadata.js +399 -9
- package/dist/Database/manage-metadata.js.map +1 -1
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.d.ts +36 -3
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.d.ts.map +1 -1
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.js +104 -23
- package/dist/Database/providers/postgresql/PostgreSQLCodeGenProvider.js.map +1 -1
- package/dist/Database/providers/postgresql/__tests__/MetadataSupportObjectsDDL.test.d.ts +2 -0
- package/dist/Database/providers/postgresql/__tests__/MetadataSupportObjectsDDL.test.d.ts.map +1 -0
- package/dist/Database/providers/postgresql/__tests__/MetadataSupportObjectsDDL.test.js +127 -0
- package/dist/Database/providers/postgresql/__tests__/MetadataSupportObjectsDDL.test.js.map +1 -0
- package/dist/Database/providers/postgresql/metadataSupportObjects.js +155 -2
- package/dist/Database/providers/postgresql/metadataSupportObjects.js.map +1 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.d.ts +23 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.d.ts.map +1 -1
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.js +77 -19
- package/dist/Database/providers/sqlserver/SQLServerCodeGenProvider.js.map +1 -1
- package/dist/Database/providers/sqlserver/__tests__/VerifiedJoinIndexes.test.d.ts +2 -0
- package/dist/Database/providers/sqlserver/__tests__/VerifiedJoinIndexes.test.d.ts.map +1 -0
- package/dist/Database/providers/sqlserver/__tests__/VerifiedJoinIndexes.test.js +141 -0
- package/dist/Database/providers/sqlserver/__tests__/VerifiedJoinIndexes.test.js.map +1 -0
- package/dist/Database/sql_codegen.d.ts +39 -1
- package/dist/Database/sql_codegen.d.ts.map +1 -1
- package/dist/Database/sql_codegen.js +100 -2
- package/dist/Database/sql_codegen.js.map +1 -1
- package/dist/Manifest/GenerateClassRegistrationsManifest.d.ts +9 -0
- package/dist/Manifest/GenerateClassRegistrationsManifest.d.ts.map +1 -1
- package/dist/Manifest/GenerateClassRegistrationsManifest.js +28 -7
- package/dist/Manifest/GenerateClassRegistrationsManifest.js.map +1 -1
- package/dist/Misc/entity_subclasses_codegen.d.ts.map +1 -1
- package/dist/Misc/entity_subclasses_codegen.js +18 -2
- package/dist/Misc/entity_subclasses_codegen.js.map +1 -1
- package/dist/runCodeGen.d.ts +14 -0
- package/dist/runCodeGen.d.ts.map +1 -1
- package/dist/runCodeGen.js +21 -1
- package/dist/runCodeGen.js.map +1 -1
- package/package.json +29 -29
|
@@ -79,6 +79,12 @@ export class SQLCodeGenBase {
|
|
|
79
79
|
* while the entity itself is not in newEntityList/modifiedEntityList.
|
|
80
80
|
*/
|
|
81
81
|
this.existingRoutines = null;
|
|
82
|
+
/**
|
|
83
|
+
* Map of `schema.routine` (lowercased) to its live `OBJECT_DEFINITION` text on SQL Server,
|
|
84
|
+
* used by {@link isRoutineSaveReturnModeChanged} to detect when `Entity.Configuration.SaveReturnMode`
|
|
85
|
+
* changed via `mj sync push` without a physical table/column change.
|
|
86
|
+
*/
|
|
87
|
+
this.existingRoutineDefinitions = null;
|
|
82
88
|
}
|
|
83
89
|
get SQLUtilityObject() {
|
|
84
90
|
return this._sqlUtilityObject;
|
|
@@ -92,6 +98,7 @@ export class SQLCodeGenBase {
|
|
|
92
98
|
async ManageSQLScriptsAndExecution(pool, entities, directory, currentUser) {
|
|
93
99
|
try {
|
|
94
100
|
this.existingRoutines = null;
|
|
101
|
+
this.existingRoutineDefinitions = null;
|
|
95
102
|
// Build list of entities qualified for forced regeneration if entityWhereClause is provided
|
|
96
103
|
if (configInfo.forceRegeneration?.enabled && configInfo.forceRegeneration?.entityWhereClause) {
|
|
97
104
|
this.filterEntitiesQualifiedForRegeneration = true; // Enable filtering
|
|
@@ -322,11 +329,21 @@ export class SQLCodeGenBase {
|
|
|
322
329
|
// Pass 2 (this call) only re-runs to pick up new virtual fields from regenerated views and to apply advanced
|
|
323
330
|
// generation. Scoping to changed entities collapses the SP scans to seeks; an empty list means no work to do.
|
|
324
331
|
// forceRegeneration override skips the scoping so all entities get reprocessed (used when prompts change, etc.).
|
|
332
|
+
//
|
|
333
|
+
// The two lists only ever contain entities something changed on during THIS run, so an
|
|
334
|
+
// entity whose virtual-field row was missed once drops out of scope forever and its
|
|
335
|
+
// record forms stay broken until someone runs forceRegeneration over the whole database.
|
|
336
|
+
// The drift probe closes that: it asks the catalog which entities have a view-only
|
|
337
|
+
// column with no EntityField and unions those in, so recovery is a normal run.
|
|
338
|
+
const driftEntities = configInfo.forceRegeneration?.enabled
|
|
339
|
+
? []
|
|
340
|
+
: await manageMD.FindVirtualFieldDriftEntities(pool, configInfo.excludeSchemas);
|
|
325
341
|
const pass2EntityFilter = configInfo.forceRegeneration?.enabled
|
|
326
342
|
? undefined
|
|
327
343
|
: [...new Set([
|
|
328
344
|
...ManageMetadataBase.newEntityList,
|
|
329
345
|
...ManageMetadataBase.modifiedEntityList,
|
|
346
|
+
...driftEntities,
|
|
330
347
|
])];
|
|
331
348
|
StartSpinner('Managing entity fields metadata...');
|
|
332
349
|
if (!await manageMD.manageEntityFields(pool, configInfo.excludeSchemas, true, true, currentUser, false, false, pass2EntityFilter)) {
|
|
@@ -645,8 +662,11 @@ export class SQLCodeGenBase {
|
|
|
645
662
|
// captured-dependent-restore fails because it doesn't know that
|
|
646
663
|
// dependent will be re-emitted in a subsequent batch.
|
|
647
664
|
const willRegenerate = options.willRegenerate ?? new Set(options.entities.map(e => `${e.SchemaName}.${e.BaseView}`));
|
|
665
|
+
const phaseLabel = options.progressLabel ?? (options.onlyPermissions ? 'Applying permissions' : 'Generating SQL');
|
|
666
|
+
const phaseStart = Date.now();
|
|
648
667
|
for (let i = 0; i < totalEntities; i += options.batchSize) {
|
|
649
668
|
const batch = options.entities.slice(i, i + options.batchSize);
|
|
669
|
+
this.reportEntityBatchProgress(phaseLabel, i, totalEntities, batch[0], phaseStart);
|
|
650
670
|
const promises = batch.map(async (e) => {
|
|
651
671
|
const pkeyField = e.Fields.find(f => f.IsPrimaryKey);
|
|
652
672
|
if (!pkeyField) {
|
|
@@ -1385,10 +1405,12 @@ export class SQLCodeGenBase {
|
|
|
1385
1405
|
/**
|
|
1386
1406
|
* Snapshot every CRUD routine currently in the database (one query) so
|
|
1387
1407
|
* generate-and-log can force-emit CREATE PROC for objects that vanished
|
|
1388
|
-
* without the entity landing on newEntityList/modifiedEntityList
|
|
1408
|
+
* without the entity landing on newEntityList/modifiedEntityList, or whose
|
|
1409
|
+
* return-row mode (`SaveReturnMode`) changed via `mj sync push`.
|
|
1389
1410
|
*/
|
|
1390
1411
|
async loadExistingRoutines(pool, entities) {
|
|
1391
1412
|
this.existingRoutines = new Set();
|
|
1413
|
+
this.existingRoutineDefinitions = null;
|
|
1392
1414
|
const schemas = [...new Set(entities.map((e) => e.SchemaName).filter((s) => !!s))];
|
|
1393
1415
|
const sql = this._dbProvider.getRoutineNamesBySchemaSQL(schemas);
|
|
1394
1416
|
if (!sql || !sql.trim()) {
|
|
@@ -1403,10 +1425,25 @@ export class SQLCodeGenBase {
|
|
|
1403
1425
|
this.existingRoutines.add(`${schemaName}.${routineName}`);
|
|
1404
1426
|
}
|
|
1405
1427
|
}
|
|
1428
|
+
if (this._dbProvider.PlatformKey === 'sqlserver' && schemas.length > 0) {
|
|
1429
|
+
const inList = schemas.map((s) => `'${s.replace(/'/g, "''")}'`).join(', ');
|
|
1430
|
+
const defResult = await pool.query(`SELECT s.name AS schema_name, p.name AS routine_name, OBJECT_DEFINITION(p.object_id) AS routine_definition ` +
|
|
1431
|
+
`FROM sys.procedures p INNER JOIN sys.schemas s ON s.schema_id = p.schema_id WHERE s.name IN (${inList})`);
|
|
1432
|
+
this.existingRoutineDefinitions = new Map();
|
|
1433
|
+
for (const row of defResult.recordset ?? []) {
|
|
1434
|
+
const schemaName = String(row.schema_name ?? '').toLowerCase();
|
|
1435
|
+
const routineName = String(row.routine_name ?? '').toLowerCase();
|
|
1436
|
+
const routineDef = row.routine_definition != null ? String(row.routine_definition) : '';
|
|
1437
|
+
if (schemaName && routineName && routineDef) {
|
|
1438
|
+
this.existingRoutineDefinitions.set(`${schemaName}.${routineName}`, routineDef);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1406
1442
|
}
|
|
1407
1443
|
catch (e) {
|
|
1408
1444
|
LogWarning(`Could not load existing CRUD routines (missing-proc self-heal disabled this run): ${e instanceof Error ? e.message : String(e)}`);
|
|
1409
1445
|
this.existingRoutines = null;
|
|
1446
|
+
this.existingRoutineDefinitions = null;
|
|
1410
1447
|
}
|
|
1411
1448
|
}
|
|
1412
1449
|
isRoutineMissing(schema, routineName) {
|
|
@@ -1415,8 +1452,36 @@ export class SQLCodeGenBase {
|
|
|
1415
1452
|
}
|
|
1416
1453
|
return !this.existingRoutines.has(`${schema}.${routineName}`.toLowerCase());
|
|
1417
1454
|
}
|
|
1455
|
+
/**
|
|
1456
|
+
* Returns true when `spCreate` or `spUpdate` in the database was generated under a different
|
|
1457
|
+
* `SaveReturnMode` (`'full'` vs `'datestamps_only'`) than the entity's current metadata.
|
|
1458
|
+
* This ensures that when `Entity.Configuration.SaveReturnMode` is updated via `mj sync push`,
|
|
1459
|
+
* the subsequent `mj codegen` run automatically logs and executes the updated stored procedures.
|
|
1460
|
+
*/
|
|
1461
|
+
isRoutineSaveReturnModeChanged(entity, routineName) {
|
|
1462
|
+
if (!this.existingRoutineDefinitions || !entity.BaseView) {
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
const createSpName = this.GetSPName(entity, SPType.Create).toLowerCase();
|
|
1466
|
+
const updateSpName = this.GetSPName(entity, SPType.Update).toLowerCase();
|
|
1467
|
+
const lowerRoutine = routineName.toLowerCase();
|
|
1468
|
+
if (lowerRoutine !== createSpName && lowerRoutine !== updateSpName) {
|
|
1469
|
+
return false;
|
|
1470
|
+
}
|
|
1471
|
+
const def = this.existingRoutineDefinitions.get(`${entity.SchemaName}.${routineName}`.toLowerCase());
|
|
1472
|
+
if (!def) {
|
|
1473
|
+
return false;
|
|
1474
|
+
}
|
|
1475
|
+
const selectsFromBaseView = def.toLowerCase().includes(`[${entity.BaseView.toLowerCase()}]`);
|
|
1476
|
+
if (entity.SaveReturnMode === 'datestamps_only') {
|
|
1477
|
+
return selectsFromBaseView;
|
|
1478
|
+
}
|
|
1479
|
+
return !selectsFromBaseView;
|
|
1480
|
+
}
|
|
1418
1481
|
forceLogForRoutine(entity, routineName, baseViewChanged) {
|
|
1419
|
-
return baseViewChanged ||
|
|
1482
|
+
return baseViewChanged ||
|
|
1483
|
+
this.isRoutineMissing(entity.SchemaName, routineName) ||
|
|
1484
|
+
this.isRoutineSaveReturnModeChanged(entity, routineName);
|
|
1420
1485
|
}
|
|
1421
1486
|
GetEntityPermissionFileNames(entity) {
|
|
1422
1487
|
const files = [];
|
|
@@ -1512,6 +1577,13 @@ export class SQLCodeGenBase {
|
|
|
1512
1577
|
if (!await e.Save())
|
|
1513
1578
|
throw new Error(`Could not update the FullTextSearchFunction for entity ${entity.Name}`);
|
|
1514
1579
|
}
|
|
1580
|
+
// Say what enabling full-text search costs, at the one moment the person who enabled it is
|
|
1581
|
+
// still in the room. The objects below are charged on every write to the table from here on
|
|
1582
|
+
// and are not removed by turning the entity's flags back off.
|
|
1583
|
+
const costDisclosure = this._dbProvider.FullTextSearchCostDisclosure(entity, searchFields);
|
|
1584
|
+
if (costDisclosure) {
|
|
1585
|
+
LogWarning(` > ${costDisclosure}`);
|
|
1586
|
+
}
|
|
1515
1587
|
// Delegate SQL generation to the provider
|
|
1516
1588
|
const result = this._dbProvider.generateFullTextSearch(entity, searchFields, primaryKeyIndexName);
|
|
1517
1589
|
// Add permissions if function was generated
|
|
@@ -1544,6 +1616,32 @@ export class SQLCodeGenBase {
|
|
|
1544
1616
|
generateAllEntitiesSQLFileHeader() {
|
|
1545
1617
|
return this.GenerateAllEntitiesSQLFileHeader();
|
|
1546
1618
|
}
|
|
1619
|
+
/**
|
|
1620
|
+
* Emits the one live progress line for the entity generation/permissions loop: which phase, how
|
|
1621
|
+
* far through, which entity is being worked on, and how long the phase has been running.
|
|
1622
|
+
*
|
|
1623
|
+
* WHY. The spinner already re-renders an elapsed timer every 100 ms, so a long run is not silent
|
|
1624
|
+
* — but the message it re-renders was set ONCE before the loop ("Generating SQL for 1,200
|
|
1625
|
+
* entities…") and never changed again. A run that has been sitting on entity 3 for four minutes
|
|
1626
|
+
* and a run that is on entity 1,180 render identically, which makes a stall and normal progress
|
|
1627
|
+
* indistinguishable. `N/total` is the whole difference.
|
|
1628
|
+
*
|
|
1629
|
+
* Called per BATCH rather than per entity: the batch is the unit of concurrency (its members run
|
|
1630
|
+
* under one `Promise.all`), so a per-entity line would just interleave five entities' names at
|
|
1631
|
+
* random. The named entity is the batch's first, which is what the run is demonstrably on.
|
|
1632
|
+
*
|
|
1633
|
+
* `UpdateSpinner` covers both output modes by construction — in verbose mode it routes to
|
|
1634
|
+
* `logStatus`, so a verbose run gets the same information as a line per batch instead of a
|
|
1635
|
+
* re-rendered spinner.
|
|
1636
|
+
*/
|
|
1637
|
+
reportEntityBatchProgress(phaseLabel, completed, total, currentEntity, phaseStartMs) {
|
|
1638
|
+
if (total === 0) {
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
const elapsed = ((Date.now() - phaseStartMs) / 1000).toFixed(1);
|
|
1642
|
+
const where = currentEntity ? ` — ${currentEntity.SchemaName}.${currentEntity.Name}` : '';
|
|
1643
|
+
UpdateSpinner(`${phaseLabel}: ${completed}/${total} entities, ${elapsed}s elapsed${where}`);
|
|
1644
|
+
}
|
|
1547
1645
|
GenerateSingleEntitySQLFileHeader(entity, itemName) {
|
|
1548
1646
|
return this._dbProvider.generateSQLFileHeader(entity, itemName);
|
|
1549
1647
|
}
|