@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadataSupportObjects.js","sourceRoot":"","sources":["../../../../src/Database/providers/postgresql/metadataSupportObjects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,8BAA8B,CAAC,YAAoB;IAC/D,OAAO,4BAA4B,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACzE,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,8BAA8B,CAAC,YAAoB;IACjE,OAAO,8BAA8B,CAAC,YAAY,CAAC,CAAC;AACtD,CAAC;AACD,MAAM,4BAA4B,GAAW,MAAM,CAAC,GAAG,CAAA
|
|
1
|
+
{"version":3,"file":"metadataSupportObjects.js","sourceRoot":"","sources":["../../../../src/Database/providers/postgresql/metadataSupportObjects.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,8BAA8B,CAAC,YAAoB;IAC/D,OAAO,4BAA4B,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACzE,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,8BAA8B,CAAC,YAAoB;IACjE,OAAO,8BAA8B,CAAC,YAAY,CAAC,CAAC;AACtD,CAAC;AACD,MAAM,4BAA4B,GAAW,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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@@ import { DatabasePlatform, SQLDialect } from '@memberjunction/sql-dialect';
|
|
|
13
13
|
* override codegen behavior — same extension hook every other MJ class uses.
|
|
14
14
|
*/
|
|
15
15
|
export declare class SQLServerCodeGenProvider extends CodeGenDatabaseProvider {
|
|
16
|
+
/** Widest key SQL Server accepts for a nonclustered index without failing later writes. */
|
|
17
|
+
private static readonly MAX_NONCLUSTERED_INDEX_KEY_BYTES;
|
|
16
18
|
/** @inheritdoc */
|
|
17
19
|
get Dialect(): SQLDialect;
|
|
18
20
|
/** @inheritdoc */
|
|
@@ -154,7 +156,19 @@ export declare class SQLServerCodeGenProvider extends CodeGenDatabaseProvider {
|
|
|
154
156
|
* rather than an empty one.
|
|
155
157
|
*/
|
|
156
158
|
protected isIndexableKeyColumn(f: EntityFieldInfo): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* SQL Server refuses an unbounded column as an index key (error 1919), so the statement fails
|
|
161
|
+
* on every run. A key wider than 1,700 bytes is created with only a warning (1945), and any
|
|
162
|
+
* later insert or update of a longer value then fails. `Length` is in bytes for `nvarchar`.
|
|
163
|
+
*/
|
|
164
|
+
protected ForeignKeyIndexSkipReason(f: EntityFieldInfo): string | null;
|
|
157
165
|
protected formatCompositeIndexStatement(entity: EntityInfo, fields: EntityFieldInfo[], indexName: string): string;
|
|
166
|
+
/**
|
|
167
|
+
* True: the `CREATE FULLTEXT INDEX … KEY INDEX <name>` below names the table's unique
|
|
168
|
+
* primary-key index, so CodeGen must resolve that name before the DDL can be composed.
|
|
169
|
+
* See {@link CodeGenDatabaseProvider.FullTextIndexNeedsPrimaryKeyIndexName}.
|
|
170
|
+
*/
|
|
171
|
+
get FullTextIndexNeedsPrimaryKeyIndexName(): boolean;
|
|
158
172
|
/**
|
|
159
173
|
* Generates SQL Server full-text search infrastructure for an entity, conditionally
|
|
160
174
|
* producing up to three components based on entity metadata flags:
|
|
@@ -270,6 +284,10 @@ export declare class SQLServerCodeGenProvider extends CodeGenDatabaseProvider {
|
|
|
270
284
|
*/
|
|
271
285
|
private generateFieldSecurityDenies;
|
|
272
286
|
/** @inheritdoc */
|
|
287
|
+
GenerateViewPermissionsForTarget(entity: EntityInfo, targetSchemaName: string, targetViewName: string): string;
|
|
288
|
+
/** @inheritdoc */
|
|
289
|
+
GenerateDisabledViewRevokePermissionsForTarget(entity: EntityInfo, targetSchemaName: string, targetViewName: string): string;
|
|
290
|
+
/** @inheritdoc */
|
|
273
291
|
generateViewPermissions(entity: EntityInfo): string;
|
|
274
292
|
/**
|
|
275
293
|
* Generates `GRANT EXECUTE` SQL for a CRUD stored procedure, granting permission only
|
|
@@ -316,14 +334,27 @@ export declare class SQLServerCodeGenProvider extends CodeGenDatabaseProvider {
|
|
|
316
334
|
/** @inheritdoc */
|
|
317
335
|
generateAllEntitiesSQLFileHeader(): string;
|
|
318
336
|
/**
|
|
319
|
-
* Formats a
|
|
320
|
-
*
|
|
321
|
-
* `
|
|
322
|
-
* `
|
|
323
|
-
*
|
|
324
|
-
*
|
|
337
|
+
* Formats a column default for embedding in generated SQL. The value is classified by
|
|
338
|
+
* {@link ClassifySQLServerDefaultValue}: literals keep the long-standing quoting rule
|
|
339
|
+
* (`needsQuotes`), inline-safe functions such as `GETUTCDATE()` are emitted verbatim, a
|
|
340
|
+
* bare `NEWSEQUENTIALID()` becomes `NEWID()` (it is legal only in a DEFAULT constraint), and
|
|
341
|
+
* expressions are emitted verbatim rather than string-quoted. Returns `'NULL'` for empty or
|
|
342
|
+
* whitespace-only inputs.
|
|
325
343
|
*/
|
|
326
344
|
formatDefaultValue(defaultValue: string, needsQuotes: boolean): string;
|
|
345
|
+
/**
|
|
346
|
+
* An expression default (`NEXT VALUE FOR`, string concatenation, most function calls) is
|
|
347
|
+
* resolved into its parameter before the INSERT: T-SQL rejects `NEXT VALUE FOR` inside the
|
|
348
|
+
* `ISNULL`/`CASE` wrap the value list otherwise uses (#4000).
|
|
349
|
+
*/
|
|
350
|
+
protected isPreInsertDefault(ef: EntityFieldInfo): boolean;
|
|
351
|
+
/**
|
|
352
|
+
* Emits `IF @P IS NULL SET @P = <expr>;` for every create-routine parameter whose default is an
|
|
353
|
+
* expression. Mirrors the value-list branches of {@link GenerateInsertFieldString}: a NOT NULL
|
|
354
|
+
* uniqueidentifier also treats the empty GUID as "not supplied", and a nullable column skips the
|
|
355
|
+
* default when the caller set its `_Clear` companion.
|
|
356
|
+
*/
|
|
357
|
+
GeneratePreInsertDefaultAssignments(entity: EntityInfo): string;
|
|
327
358
|
/**
|
|
328
359
|
* Builds the four SQL fragments needed to work with an entity's primary key columns
|
|
329
360
|
* in cursor-based cascade operations:
|
|
@@ -412,6 +443,8 @@ export declare class SQLServerCodeGenProvider extends CodeGenDatabaseProvider {
|
|
|
412
443
|
/** @inheritdoc */
|
|
413
444
|
generateViewRefreshSQL(schema: string, viewName: string): string;
|
|
414
445
|
/** @inheritdoc */
|
|
446
|
+
getViewDependenciesSQL(schema: string, viewName: string): string;
|
|
447
|
+
/** @inheritdoc */
|
|
415
448
|
generateIfViewExistsSQL(schema: string, viewName: string, innerSQL: string): string;
|
|
416
449
|
/** @inheritdoc */
|
|
417
450
|
generateViewTestQuerySQL(schema: string, viewName: string): string;
|
|
@@ -481,13 +514,16 @@ export declare class SQLServerCodeGenProvider extends CodeGenDatabaseProvider {
|
|
|
481
514
|
/** @inheritdoc */
|
|
482
515
|
getFixVirtualFieldNullabilitySQL(_mjCoreSchema: string): string;
|
|
483
516
|
/**
|
|
484
|
-
* Executes a SQL file against SQL Server
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
517
|
+
* Executes a SQL file against SQL Server over the shared in-process mssql pool, one `GO`
|
|
518
|
+
* batch at a time. Every batch runs even after one fails, so a single run reports the
|
|
519
|
+
* complete set of broken objects; each failure is logged as an error naming the object the
|
|
520
|
+
* batch acts on (`CREATE PROCEDURE [s].[spX]`, `GRANT ON [s].[vwX]`). Returns `false` when
|
|
521
|
+
* any batch failed or the file could not be read, `true` otherwise. A failed batch used to be
|
|
522
|
+
* logged as a warning with the file still reported as successful, which hid procedures that
|
|
523
|
+
* had been dropped and never recreated (#4000).
|
|
490
524
|
*/
|
|
491
525
|
executeSQLFileViaShell(filePath: string): Promise<boolean>;
|
|
526
|
+
/** @inheritdoc */
|
|
527
|
+
NormalizeRoutineDefinitionForComparison(definition: string): string | null;
|
|
492
528
|
}
|
|
493
529
|
//# sourceMappingURL=SQLServerCodeGenProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SQLServerCodeGenProvider.d.ts","sourceRoot":"","sources":["../../../../src/Database/providers/sqlserver/SQLServerCodeGenProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAA0C,MAAM,sBAAsB,CAAC;AAC3G,OAAO,EACH,uBAAuB,EACvB,QAAQ,EACR,yBAAyB,EACzB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,gBAAgB,EAEnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAoB,gBAAgB,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"SQLServerCodeGenProvider.d.ts","sourceRoot":"","sources":["../../../../src/Database/providers/sqlserver/SQLServerCodeGenProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAA0C,MAAM,sBAAsB,CAAC;AAC3G,OAAO,EACH,uBAAuB,EACvB,QAAQ,EACR,yBAAyB,EACzB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,gBAAgB,EAEnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAoB,gBAAgB,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAgB7F;;;;;;;;;;GAUG;AACH,qBACa,wBAAyB,SAAQ,uBAAuB;IACjE,2FAA2F;IAC3F,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gCAAgC,CAAQ;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zC;;;;;;;;;;OAUG;IACH,uBAAuB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAU/D;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAOhC;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IASzB;;;;;;;;;;;OAWG;IACH,yBAAyB,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM;IAMxG;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IAuBpC;;;;OAIG;IACH,OAAO,CAAC,2BAA2B;IAsFnC;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAQjC,kBAAkB;IAClB,+BAA+B,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,MAAM;IAQjE,kBAAkB;IAClB,sCAAsC,IAAI,MAAM;IAIhD,kBAAkB;IAClB,gCAAgC,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;IAM/D;;;;;;;;OAQG;IACG,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoChE,kBAAkB;IACT,uCAAuC,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAItF"}
|
|
@@ -4,6 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
+
var SQLServerCodeGenProvider_1;
|
|
7
8
|
import { EntityInfo, CodeNameFromString, ResolveStartupMode } from '@memberjunction/core';
|
|
8
9
|
import { CodeGenDatabaseProvider, ExcludedBaseViewFieldNames, } from '../../codeGenDatabaseProvider.js';
|
|
9
10
|
import { SQLServerDialect } from '@memberjunction/sql-dialect';
|
|
@@ -15,6 +16,8 @@ import { logError, logStatus, LogWarning, StartSpinner, SucceedSpinner } from '.
|
|
|
15
16
|
import { SQLServerProviderConfigData, setupSQLServerClient } from '@memberjunction/sqlserver-dataprovider';
|
|
16
17
|
import { UserCache } from '@memberjunction/generic-database-provider';
|
|
17
18
|
import { SQLServerCodeGenConnection } from './SQLServerCodeGenConnection.js';
|
|
19
|
+
import { ClassifySQLServerDefaultValue } from './sqlServerDefaultValues.js';
|
|
20
|
+
import { DescribeSQLBatchObject, NormalizeSQLServerRoutineDefinition, SplitSQLServerBatches } from './sqlServerScriptText.js';
|
|
18
21
|
import * as fs from 'fs';
|
|
19
22
|
import * as path from 'path';
|
|
20
23
|
const ssDialect = new SQLServerDialect();
|
|
@@ -42,6 +45,9 @@ let SQLServerCodeGenProvider = class SQLServerCodeGenProvider extends CodeGenDat
|
|
|
42
45
|
/** Service-protected DENY skips are warned once per role per run (see generateFieldSecurityDenies). */
|
|
43
46
|
this._serviceProtectedDenySkipsWarned = new Set();
|
|
44
47
|
}
|
|
48
|
+
static { SQLServerCodeGenProvider_1 = this; }
|
|
49
|
+
/** Widest key SQL Server accepts for a nonclustered index without failing later writes. */
|
|
50
|
+
static { this.MAX_NONCLUSTERED_INDEX_KEY_BYTES = 1700; }
|
|
45
51
|
/** @inheritdoc */
|
|
46
52
|
get Dialect() {
|
|
47
53
|
return ssDialect;
|
|
@@ -235,6 +241,10 @@ ${this.trimStatementTerminator(selectSQL)}`;
|
|
|
235
241
|
const identityKey = entity.PrimaryKeys.find(k => k.AutoIncrement);
|
|
236
242
|
const efString = this.generateCRUDParamString(entity.Fields, false);
|
|
237
243
|
const permissions = this.generateCRUDPermissions(entity, spName, 'Create');
|
|
244
|
+
// Expression defaults (#4000) are resolved into their parameters ahead of every INSERT
|
|
245
|
+
// branch below. Empty for the common case, which keeps those procedures byte-identical.
|
|
246
|
+
const assignmentSQL = this.GeneratePreInsertDefaultAssignments(entity);
|
|
247
|
+
const defaultAssignments = assignmentSQL.length > 0 ? `${assignmentSQL}\n ` : '';
|
|
238
248
|
let preInsertCode = '';
|
|
239
249
|
let outputCode = '';
|
|
240
250
|
let selectInsertedRecord = '';
|
|
@@ -372,7 +382,7 @@ CREATE PROCEDURE [${entity.SchemaName}].[${spName}]
|
|
|
372
382
|
AS
|
|
373
383
|
BEGIN
|
|
374
384
|
SET NOCOUNT ON;
|
|
375
|
-
${preInsertCode}${insertBlock}
|
|
385
|
+
${defaultAssignments}${preInsertCode}${insertBlock}
|
|
376
386
|
-- return the new record from the base view, which might have some calculated fields
|
|
377
387
|
${selectInsertedRecord}
|
|
378
388
|
END
|
|
@@ -612,6 +622,20 @@ CREATE INDEX ${indexName} ON [${entity.SchemaName}].[${entity.BaseTable}] ([${f.
|
|
|
612
622
|
isIndexableKeyColumn(f) {
|
|
613
623
|
return f.Length !== -1;
|
|
614
624
|
}
|
|
625
|
+
/**
|
|
626
|
+
* SQL Server refuses an unbounded column as an index key (error 1919), so the statement fails
|
|
627
|
+
* on every run. A key wider than 1,700 bytes is created with only a warning (1945), and any
|
|
628
|
+
* later insert or update of a longer value then fails. `Length` is in bytes for `nvarchar`.
|
|
629
|
+
*/
|
|
630
|
+
ForeignKeyIndexSkipReason(f) {
|
|
631
|
+
if (!this.isIndexableKeyColumn(f)) {
|
|
632
|
+
return 'unbounded, which SQL Server cannot use as an index key';
|
|
633
|
+
}
|
|
634
|
+
if (f.Length > SQLServerCodeGenProvider_1.MAX_NONCLUSTERED_INDEX_KEY_BYTES) {
|
|
635
|
+
return `${f.Length} bytes, over SQL Server's ${SQLServerCodeGenProvider_1.MAX_NONCLUSTERED_INDEX_KEY_BYTES}-byte index key limit`;
|
|
636
|
+
}
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
615
639
|
formatCompositeIndexStatement(entity, fields, indexName) {
|
|
616
640
|
const cols = fields.map(f => `[${f.Name}]`).join(', ');
|
|
617
641
|
return `-- Index for the soft primary key (${fields.map(f => f.Name).join(', ')}) in table ${entity.BaseTable}.
|
|
@@ -626,6 +650,14 @@ IF NOT EXISTS (
|
|
|
626
650
|
CREATE INDEX ${indexName} ON [${entity.SchemaName}].[${entity.BaseTable}] (${cols});`;
|
|
627
651
|
}
|
|
628
652
|
// ─── FULL-TEXT SEARCH ────────────────────────────────────────────────
|
|
653
|
+
/**
|
|
654
|
+
* True: the `CREATE FULLTEXT INDEX … KEY INDEX <name>` below names the table's unique
|
|
655
|
+
* primary-key index, so CodeGen must resolve that name before the DDL can be composed.
|
|
656
|
+
* See {@link CodeGenDatabaseProvider.FullTextIndexNeedsPrimaryKeyIndexName}.
|
|
657
|
+
*/
|
|
658
|
+
get FullTextIndexNeedsPrimaryKeyIndexName() {
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
629
661
|
/**
|
|
630
662
|
* Generates SQL Server full-text search infrastructure for an entity, conditionally
|
|
631
663
|
* producing up to three components based on entity metadata flags:
|
|
@@ -1099,7 +1131,7 @@ GO
|
|
|
1099
1131
|
* - **Unrestrictable targets** (PKs, `__mj_` columns, the security/identity entities) are
|
|
1100
1132
|
* filtered defensively even though save-time guards should make such rows impossible.
|
|
1101
1133
|
*/
|
|
1102
|
-
generateFieldSecurityDenies(entity) {
|
|
1134
|
+
generateFieldSecurityDenies(entity, targetSchemaName = entity.SchemaName, targetViewName = entity.BaseView) {
|
|
1103
1135
|
const context = this._fieldSecurityRunContext;
|
|
1104
1136
|
if (!context)
|
|
1105
1137
|
return '';
|
|
@@ -1134,16 +1166,16 @@ GO
|
|
|
1134
1166
|
}
|
|
1135
1167
|
let sOutput = '';
|
|
1136
1168
|
for (const [sqlName, columns] of [...deniedColumnsByRole.entries()].sort(([a], [b]) => ordinalCompare(a, b))) {
|
|
1137
|
-
sOutput += `\nDENY SELECT (${columns.map(c => `[${c}]`).join(', ')}) ON [${
|
|
1169
|
+
sOutput += `\nDENY SELECT (${columns.map(c => `[${c}]`).join(', ')}) ON [${targetSchemaName}].[${targetViewName}] TO [${sqlName}]`;
|
|
1138
1170
|
}
|
|
1139
1171
|
return sOutput;
|
|
1140
1172
|
}
|
|
1141
1173
|
/** @inheritdoc */
|
|
1142
|
-
|
|
1174
|
+
GenerateViewPermissionsForTarget(entity, targetSchemaName, targetViewName) {
|
|
1143
1175
|
let sOutput = '';
|
|
1144
1176
|
for (const ep of entity.Permissions) {
|
|
1145
1177
|
if (ep.RoleSQLName && ep.RoleSQLName.length > 0) {
|
|
1146
|
-
sOutput += (sOutput === '' ? `GRANT SELECT ON [${
|
|
1178
|
+
sOutput += (sOutput === '' ? `GRANT SELECT ON [${targetSchemaName}].[${targetViewName}] TO ` : ', ') + `[${ep.RoleSQLName}]`;
|
|
1147
1179
|
}
|
|
1148
1180
|
else {
|
|
1149
1181
|
this.logAppTierOnlyRoleSkip(ep.Role);
|
|
@@ -1151,11 +1183,32 @@ GO
|
|
|
1151
1183
|
}
|
|
1152
1184
|
// Order matters: wipe (REVOKE within the managed scope) → assert grants → assert
|
|
1153
1185
|
// field-security DENYs. The whole body executes every run via applyPermissions.
|
|
1154
|
-
const revokes = this.generateManagedPermissionRevokes(
|
|
1186
|
+
const revokes = this.generateManagedPermissionRevokes(targetSchemaName, targetViewName);
|
|
1155
1187
|
const grants = (sOutput === '' ? '' : '\n') + sOutput;
|
|
1156
|
-
const denies = this.generateFieldSecurityDenies(entity);
|
|
1188
|
+
const denies = this.generateFieldSecurityDenies(entity, targetSchemaName, targetViewName);
|
|
1157
1189
|
return revokes + grants + denies;
|
|
1158
1190
|
}
|
|
1191
|
+
/** @inheritdoc */
|
|
1192
|
+
GenerateDisabledViewRevokePermissionsForTarget(entity, targetSchemaName, targetViewName) {
|
|
1193
|
+
const revokes = this.generateManagedPermissionRevokes(targetSchemaName, targetViewName);
|
|
1194
|
+
if (revokes.trim().length > 0) {
|
|
1195
|
+
return revokes;
|
|
1196
|
+
}
|
|
1197
|
+
const roles = [];
|
|
1198
|
+
for (const ep of entity.Permissions) {
|
|
1199
|
+
if (ep.RoleSQLName && ep.RoleSQLName.length > 0 && !roles.includes(ep.RoleSQLName)) {
|
|
1200
|
+
roles.push(ep.RoleSQLName);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
if (roles.length === 0) {
|
|
1204
|
+
return '';
|
|
1205
|
+
}
|
|
1206
|
+
return `\nREVOKE SELECT ON [${targetSchemaName}].[${targetViewName}] FROM ${roles.map((r) => `[${r}]`).join(', ')}`;
|
|
1207
|
+
}
|
|
1208
|
+
/** @inheritdoc */
|
|
1209
|
+
generateViewPermissions(entity) {
|
|
1210
|
+
return this.GenerateViewPermissionsForTarget(entity, entity.SchemaName, entity.BaseView);
|
|
1211
|
+
}
|
|
1159
1212
|
/**
|
|
1160
1213
|
* Generates `GRANT EXECUTE` SQL for a CRUD stored procedure, granting permission only
|
|
1161
1214
|
* to roles whose `EntityPermission` record allows the specified CRUD operation type.
|
|
@@ -1406,40 +1459,51 @@ WHERE s.name IN (${inList})`;
|
|
|
1406
1459
|
}
|
|
1407
1460
|
// ─── UTILITY ─────────────────────────────────────────────────────────
|
|
1408
1461
|
/**
|
|
1409
|
-
* Formats a
|
|
1410
|
-
*
|
|
1411
|
-
* `
|
|
1412
|
-
* `
|
|
1413
|
-
*
|
|
1414
|
-
*
|
|
1462
|
+
* Formats a column default for embedding in generated SQL. The value is classified by
|
|
1463
|
+
* {@link ClassifySQLServerDefaultValue}: literals keep the long-standing quoting rule
|
|
1464
|
+
* (`needsQuotes`), inline-safe functions such as `GETUTCDATE()` are emitted verbatim, a
|
|
1465
|
+
* bare `NEWSEQUENTIALID()` becomes `NEWID()` (it is legal only in a DEFAULT constraint), and
|
|
1466
|
+
* expressions are emitted verbatim rather than string-quoted. Returns `'NULL'` for empty or
|
|
1467
|
+
* whitespace-only inputs.
|
|
1415
1468
|
*/
|
|
1416
1469
|
formatDefaultValue(defaultValue, needsQuotes) {
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1470
|
+
return ClassifySQLServerDefaultValue(defaultValue, needsQuotes).SQL;
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* An expression default (`NEXT VALUE FOR`, string concatenation, most function calls) is
|
|
1474
|
+
* resolved into its parameter before the INSERT: T-SQL rejects `NEXT VALUE FOR` inside the
|
|
1475
|
+
* `ISNULL`/`CASE` wrap the value list otherwise uses (#4000).
|
|
1476
|
+
*/
|
|
1477
|
+
isPreInsertDefault(ef) {
|
|
1478
|
+
return ClassifySQLServerDefaultValue(ef.DefaultValue, ef.NeedsQuotes).Kind === 'Expression';
|
|
1479
|
+
}
|
|
1480
|
+
/**
|
|
1481
|
+
* Emits `IF @P IS NULL SET @P = <expr>;` for every create-routine parameter whose default is an
|
|
1482
|
+
* expression. Mirrors the value-list branches of {@link GenerateInsertFieldString}: a NOT NULL
|
|
1483
|
+
* uniqueidentifier also treats the empty GUID as "not supplied", and a nullable column skips the
|
|
1484
|
+
* default when the caller set its `_Clear` companion.
|
|
1485
|
+
*/
|
|
1486
|
+
GeneratePreInsertDefaultAssignments(entity) {
|
|
1487
|
+
const lines = [];
|
|
1488
|
+
for (const ef of entity.Fields) {
|
|
1489
|
+
if (ef.IsPrimaryKey || ef.IsVirtual || !ef.AllowUpdateAPI || ef.AutoIncrement || ef.IsSpecialDateField) {
|
|
1490
|
+
continue;
|
|
1433
1491
|
}
|
|
1492
|
+
if (!ef.HasDefaultValue || !this.isPreInsertDefault(ef)) {
|
|
1493
|
+
continue;
|
|
1494
|
+
}
|
|
1495
|
+
const param = `@${ef.CodeName}`;
|
|
1496
|
+
const expr = this.formatDefaultValue(ef.DefaultValue, ef.NeedsQuotes);
|
|
1497
|
+
let condition = `${param} IS NULL`;
|
|
1498
|
+
if (!ef.AllowsNull && ef.IsUniqueIdentifier) {
|
|
1499
|
+
condition = `(${param} IS NULL OR ${param} = ${this.Dialect.EmptyUUIDLiteral()})`;
|
|
1500
|
+
}
|
|
1501
|
+
else if (ef.AllowsNull && this.needsClearCompanion(ef)) {
|
|
1502
|
+
condition = `${param} IS NULL AND ISNULL(@${ef.CodeName}_Clear, 0) = 0`;
|
|
1503
|
+
}
|
|
1504
|
+
lines.push(`IF ${condition} SET ${param} = ${expr};`);
|
|
1434
1505
|
}
|
|
1435
|
-
|
|
1436
|
-
if (cleanValue.startsWith("'") && cleanValue.endsWith("'")) {
|
|
1437
|
-
cleanValue = cleanValue.substring(1, cleanValue.length - 1);
|
|
1438
|
-
}
|
|
1439
|
-
if (needsQuotes) {
|
|
1440
|
-
return `'${cleanValue}'`;
|
|
1441
|
-
}
|
|
1442
|
-
return cleanValue;
|
|
1506
|
+
return lines.join('\n ');
|
|
1443
1507
|
}
|
|
1444
1508
|
/**
|
|
1445
1509
|
* Builds the four SQL fragments needed to work with an entity's primary key columns
|
|
@@ -1706,6 +1770,18 @@ ORDER BY
|
|
|
1706
1770
|
return `EXEC sp_refreshview '${schema}.${viewName}';`;
|
|
1707
1771
|
}
|
|
1708
1772
|
/** @inheritdoc */
|
|
1773
|
+
getViewDependenciesSQL(schema, viewName) {
|
|
1774
|
+
const escapedSchema = EscapeSQLString(schema);
|
|
1775
|
+
const escapedView = EscapeSQLString(viewName);
|
|
1776
|
+
return `SELECT
|
|
1777
|
+
COALESCE(OBJECT_SCHEMA_NAME(d.referenced_id), d.referenced_schema_name, '${escapedSchema}') AS ReferencedSchema,
|
|
1778
|
+
COALESCE(OBJECT_NAME(d.referenced_id), d.referenced_entity_name) AS ReferencedObject,
|
|
1779
|
+
COALESCE(o.type_desc, 'UNKNOWN') AS ReferencedType
|
|
1780
|
+
FROM sys.sql_expression_dependencies d
|
|
1781
|
+
LEFT JOIN sys.objects o ON o.object_id = d.referenced_id
|
|
1782
|
+
WHERE d.referencing_id = OBJECT_ID('[${escapedSchema}].[${escapedView}]')`;
|
|
1783
|
+
}
|
|
1784
|
+
/** @inheritdoc */
|
|
1709
1785
|
generateIfViewExistsSQL(schema, viewName, innerSQL) {
|
|
1710
1786
|
// sp_executesql rather than the statements inline: the guarded body includes GRANT, and
|
|
1711
1787
|
// routing everything through one dynamic-SQL call keeps the emitted shape uniform no matter
|
|
@@ -1942,32 +2018,44 @@ DROP TABLE #__mj__CodeGen__vwTableUniqueKeys;
|
|
|
1942
2018
|
}
|
|
1943
2019
|
// ─── METADATA MANAGEMENT: SQL FILE EXECUTION ─────────────────────
|
|
1944
2020
|
/**
|
|
1945
|
-
* Executes a SQL file against SQL Server
|
|
1946
|
-
*
|
|
1947
|
-
*
|
|
1948
|
-
*
|
|
1949
|
-
*
|
|
1950
|
-
*
|
|
2021
|
+
* Executes a SQL file against SQL Server over the shared in-process mssql pool, one `GO`
|
|
2022
|
+
* batch at a time. Every batch runs even after one fails, so a single run reports the
|
|
2023
|
+
* complete set of broken objects; each failure is logged as an error naming the object the
|
|
2024
|
+
* batch acts on (`CREATE PROCEDURE [s].[spX]`, `GRANT ON [s].[vwX]`). Returns `false` when
|
|
2025
|
+
* any batch failed or the file could not be read, `true` otherwise. A failed batch used to be
|
|
2026
|
+
* logged as a warning with the file still reported as successful, which hid procedures that
|
|
2027
|
+
* had been dropped and never recreated (#4000).
|
|
1951
2028
|
*/
|
|
1952
2029
|
async executeSQLFileViaShell(filePath) {
|
|
2030
|
+
let sql;
|
|
2031
|
+
try {
|
|
2032
|
+
sql = fs.readFileSync(filePath, 'utf-8');
|
|
2033
|
+
}
|
|
2034
|
+
catch (e) {
|
|
2035
|
+
logError(`[CodeGen] Failed to read SQL file ${filePath}: ${e instanceof Error ? e.message : e}`);
|
|
2036
|
+
return false;
|
|
2037
|
+
}
|
|
2038
|
+
if (!sql.trim())
|
|
2039
|
+
return true;
|
|
1953
2040
|
try {
|
|
1954
|
-
const sql = fs.readFileSync(filePath, 'utf-8');
|
|
1955
|
-
if (!sql.trim())
|
|
1956
|
-
return true;
|
|
1957
|
-
const batches = sql
|
|
1958
|
-
.split(/^\s*GO\s*$/gim)
|
|
1959
|
-
.map(b => b.trim())
|
|
1960
|
-
.filter(b => b.length > 0);
|
|
1961
2041
|
const pool = await MSSQLConnection();
|
|
1962
|
-
|
|
2042
|
+
const failures = [];
|
|
2043
|
+
for (const batch of SplitSQLServerBatches(sql)) {
|
|
1963
2044
|
try {
|
|
1964
2045
|
await pool.request().query(batch);
|
|
1965
2046
|
}
|
|
1966
2047
|
catch (err) {
|
|
1967
|
-
|
|
1968
|
-
|
|
2048
|
+
failures.push({
|
|
2049
|
+
Object: DescribeSQLBatchObject(batch),
|
|
2050
|
+
Message: err instanceof Error ? err.message : String(err),
|
|
2051
|
+
});
|
|
1969
2052
|
}
|
|
1970
2053
|
}
|
|
2054
|
+
if (failures.length > 0) {
|
|
2055
|
+
const list = failures.map(f => ` - ${f.Object}: ${f.Message.substring(0, 400)}`).join('\n');
|
|
2056
|
+
logError(`[CodeGen] ${failures.length} SQL batch(es) failed in ${path.basename(filePath)}:\n${list}`);
|
|
2057
|
+
return false;
|
|
2058
|
+
}
|
|
1971
2059
|
return true;
|
|
1972
2060
|
}
|
|
1973
2061
|
catch (e) {
|
|
@@ -1975,8 +2063,12 @@ DROP TABLE #__mj__CodeGen__vwTableUniqueKeys;
|
|
|
1975
2063
|
return false;
|
|
1976
2064
|
}
|
|
1977
2065
|
}
|
|
2066
|
+
/** @inheritdoc */
|
|
2067
|
+
NormalizeRoutineDefinitionForComparison(definition) {
|
|
2068
|
+
return NormalizeSQLServerRoutineDefinition(definition);
|
|
2069
|
+
}
|
|
1978
2070
|
};
|
|
1979
|
-
SQLServerCodeGenProvider = __decorate([
|
|
2071
|
+
SQLServerCodeGenProvider = SQLServerCodeGenProvider_1 = __decorate([
|
|
1980
2072
|
RegisterClass(CodeGenDatabaseProvider, 'sqlserver')
|
|
1981
2073
|
], SQLServerCodeGenProvider);
|
|
1982
2074
|
export { SQLServerCodeGenProvider };
|