@memberjunction/schema-engine 0.0.1 → 5.17.0
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/dist/DDLGenerator.d.ts +48 -0
- package/dist/DDLGenerator.d.ts.map +1 -0
- package/dist/DDLGenerator.js +159 -0
- package/dist/DDLGenerator.js.map +1 -0
- package/dist/MigrationFileWriter.d.ts +32 -0
- package/dist/MigrationFileWriter.d.ts.map +1 -0
- package/dist/MigrationFileWriter.js +69 -0
- package/dist/MigrationFileWriter.js.map +1 -0
- package/dist/RSUMetrics.d.ts +48 -0
- package/dist/RSUMetrics.d.ts.map +1 -0
- package/dist/RSUMetrics.js +102 -0
- package/dist/RSUMetrics.js.map +1 -0
- package/dist/RuntimeSchemaManager.d.ts +454 -0
- package/dist/RuntimeSchemaManager.d.ts.map +1 -0
- package/dist/RuntimeSchemaManager.js +1395 -0
- package/dist/RuntimeSchemaManager.js.map +1 -0
- package/dist/SchemaEngine.d.ts +51 -0
- package/dist/SchemaEngine.d.ts.map +1 -0
- package/dist/SchemaEngine.js +100 -0
- package/dist/SchemaEngine.js.map +1 -0
- package/dist/SchemaEvolution.d.ts +30 -0
- package/dist/SchemaEvolution.d.ts.map +1 -0
- package/dist/SchemaEvolution.js +95 -0
- package/dist/SchemaEvolution.js.map +1 -0
- package/dist/SchemaValidator.d.ts +22 -0
- package/dist/SchemaValidator.d.ts.map +1 -0
- package/dist/SchemaValidator.js +93 -0
- package/dist/SchemaValidator.js.map +1 -0
- package/dist/SoftFKConfigEmitter.d.ts +59 -0
- package/dist/SoftFKConfigEmitter.d.ts.map +1 -0
- package/dist/SoftFKConfigEmitter.js +87 -0
- package/dist/SoftFKConfigEmitter.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +175 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/interfaces.js +9 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +16 -0
- package/dist/utils.js.map +1 -0
- package/package.json +31 -7
- package/README.md +0 -45
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages soft PK and FK definitions in the additionalSchemaInfo JSON file.
|
|
3
|
+
* Mirrors the integration schema-builder's SoftFKConfigEmitter but works
|
|
4
|
+
* with SchemaEngine's generic TableDefinition types.
|
|
5
|
+
*/
|
|
6
|
+
export class SoftFKConfigEmitter {
|
|
7
|
+
/**
|
|
8
|
+
* Parse existing additionalSchemaInfo JSON content.
|
|
9
|
+
* Returns empty object if content is empty/null.
|
|
10
|
+
*/
|
|
11
|
+
ParseExistingConfig(jsonContent) {
|
|
12
|
+
if (!jsonContent || jsonContent.trim() === '') {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
return JSON.parse(jsonContent);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Merge new soft FK entries into an existing config.
|
|
19
|
+
* Deduplicates — won't add the same FK twice.
|
|
20
|
+
*/
|
|
21
|
+
MergeSchemaConfig(existing, newEntries) {
|
|
22
|
+
const result = JSON.parse(JSON.stringify(existing));
|
|
23
|
+
for (const entry of newEntries) {
|
|
24
|
+
if (!result[entry.SchemaName]) {
|
|
25
|
+
result[entry.SchemaName] = [];
|
|
26
|
+
}
|
|
27
|
+
const schemaEntries = result[entry.SchemaName];
|
|
28
|
+
let tableEntry = schemaEntries.find(t => t.TableName === entry.TableName);
|
|
29
|
+
if (!tableEntry) {
|
|
30
|
+
tableEntry = { TableName: entry.TableName, ForeignKeys: [] };
|
|
31
|
+
schemaEntries.push(tableEntry);
|
|
32
|
+
}
|
|
33
|
+
if (!tableEntry.ForeignKeys) {
|
|
34
|
+
tableEntry.ForeignKeys = [];
|
|
35
|
+
}
|
|
36
|
+
const exists = tableEntry.ForeignKeys.some(fk => fk.FieldName === entry.FieldName &&
|
|
37
|
+
fk.SchemaName === entry.TargetSchemaName &&
|
|
38
|
+
fk.RelatedTable === entry.TargetTableName &&
|
|
39
|
+
fk.RelatedField === entry.TargetFieldName);
|
|
40
|
+
if (!exists) {
|
|
41
|
+
tableEntry.ForeignKeys.push({
|
|
42
|
+
FieldName: entry.FieldName,
|
|
43
|
+
SchemaName: entry.TargetSchemaName,
|
|
44
|
+
RelatedTable: entry.TargetTableName,
|
|
45
|
+
RelatedField: entry.TargetFieldName,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Add soft PK entries for tables.
|
|
53
|
+
* Uses SoftPrimaryKeys from TableDefinition.
|
|
54
|
+
*/
|
|
55
|
+
MergeSoftPKs(existing, tableDefs) {
|
|
56
|
+
const result = JSON.parse(JSON.stringify(existing));
|
|
57
|
+
for (const table of tableDefs) {
|
|
58
|
+
if (!table.SoftPrimaryKeys || table.SoftPrimaryKeys.length === 0)
|
|
59
|
+
continue;
|
|
60
|
+
if (!result[table.SchemaName]) {
|
|
61
|
+
result[table.SchemaName] = [];
|
|
62
|
+
}
|
|
63
|
+
const schemaEntries = result[table.SchemaName];
|
|
64
|
+
let tableEntry = schemaEntries.find(t => t.TableName === table.TableName);
|
|
65
|
+
if (!tableEntry) {
|
|
66
|
+
tableEntry = { TableName: table.TableName };
|
|
67
|
+
schemaEntries.push(tableEntry);
|
|
68
|
+
}
|
|
69
|
+
tableEntry.PrimaryKey = table.SoftPrimaryKeys.map(fieldName => ({
|
|
70
|
+
FieldName: fieldName,
|
|
71
|
+
Description: `Primary key from source system`,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Produce an EmittedFile with the updated additionalSchemaInfo JSON.
|
|
78
|
+
*/
|
|
79
|
+
EmitConfigFile(configPath, mergedConfig) {
|
|
80
|
+
return {
|
|
81
|
+
FilePath: configPath,
|
|
82
|
+
Content: JSON.stringify(mergedConfig, null, 4) + '\n',
|
|
83
|
+
Description: 'Updated additionalSchemaInfo with soft PK and FK definitions',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=SoftFKConfigEmitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SoftFKConfigEmitter.js","sourceRoot":"","sources":["../src/SoftFKConfigEmitter.ts"],"names":[],"mappings":"AAgCA;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAC5B;;;OAGG;IACH,mBAAmB,CAAC,WAA0B;QAC1C,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC5C,OAAO,EAAE,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAyB,CAAC;IAC3D,CAAC;IAED;;;OAGG;IACH,iBAAiB,CAAC,QAA8B,EAAE,UAAyB;QACvE,MAAM,MAAM,GAAyB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE1E,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC5B,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;YAClC,CAAC;YAED,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC/C,IAAI,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC;YAE1E,IAAI,CAAC,UAAU,EAAE,CAAC;gBACd,UAAU,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,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AC;YAED,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC/C,IAAI,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC;YAE1E,IAAI,CAAC,UAAU,EAAE,CAAC;gBACd,UAAU,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;gBAC5C,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACnC,CAAC;YAED,UAAU,CAAC,UAAU,GAAG,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;gBAC5D,SAAS,EAAE,SAAS;gBACpB,WAAW,EAAE,gCAAgC;aAChD,CAAC,CAAC,CAAC;QACR,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,UAAkB,EAAE,YAAkC;QACjE,OAAO;YACH,QAAQ,EAAE,UAAU;YACpB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI;YACrD,WAAW,EAAE,8DAA8D;SAC9E,CAAC;IACN,CAAC;CACJ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @memberjunction/schema-engine — Public API
|
|
3
|
+
*
|
|
4
|
+
* Generic, platform-aware DDL generation for any MJ consumer.
|
|
5
|
+
* Import from this package for all schema/DDL operations.
|
|
6
|
+
*/
|
|
7
|
+
export type { DatabasePlatform, SchemaFieldType, TableDefinition, ColumnDefinition, ForeignKeyDefinition, ExistingTableInfo, ExistingColumnInfo, SchemaDiff, ColumnModification, SchemaEvolutionInput, TypeMappingEntry, MigrationOutput, MigrationMetadata, EmittedFile, ValidationResult, } from './interfaces.js';
|
|
8
|
+
export { SchemaEngine } from './SchemaEngine.js';
|
|
9
|
+
export { SchemaValidator } from './SchemaValidator.js';
|
|
10
|
+
export { DDLGenerator, GetDialect, ValidateIdentifier, EscapeSqlString, resolveSqlType } from './DDLGenerator.js';
|
|
11
|
+
/** @deprecated Use GetDialect() instead. */
|
|
12
|
+
export { GetDialect as GetPlatformProvider } from './DDLGenerator.js';
|
|
13
|
+
export { MigrationFileWriter, FormatTimestamp, SanitizeForFileName } from './MigrationFileWriter.js';
|
|
14
|
+
export { SchemaEvolution } from './SchemaEvolution.js';
|
|
15
|
+
export { SoftFKConfigEmitter } from './SoftFKConfigEmitter.js';
|
|
16
|
+
export type { SoftFKEntry } from './SoftFKConfigEmitter.js';
|
|
17
|
+
export { RuntimeSchemaManager, ValidateMigrationSQL, RSUError } from './RuntimeSchemaManager.js';
|
|
18
|
+
export type { RSUPipelineBatchResult, RSUPipelineInput, RSUPipelineResult, RSUPipelineStep, RSUPreviewResult, RSUStatus, SQLValidationResult, IRSUCodeGenRunner, RSUPendingWork, } from './RuntimeSchemaManager.js';
|
|
19
|
+
export { RSUMetrics } from './RSUMetrics.js';
|
|
20
|
+
export type { PipelineRunMetric, RSUMetricsSummary } from './RSUMetrics.js';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAElH,4CAA4C;AAC5C,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAEtE,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACjG,YAAY,EACV,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,GACf,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @memberjunction/schema-engine — Public API
|
|
3
|
+
*
|
|
4
|
+
* Generic, platform-aware DDL generation for any MJ consumer.
|
|
5
|
+
* Import from this package for all schema/DDL operations.
|
|
6
|
+
*/
|
|
7
|
+
// ─── Core Classes ────────────────────────────────────────────────────
|
|
8
|
+
export { SchemaEngine } from './SchemaEngine.js';
|
|
9
|
+
export { SchemaValidator } from './SchemaValidator.js';
|
|
10
|
+
export { DDLGenerator, GetDialect, ValidateIdentifier, EscapeSqlString, resolveSqlType } from './DDLGenerator.js';
|
|
11
|
+
/** @deprecated Use GetDialect() instead. */
|
|
12
|
+
export { GetDialect as GetPlatformProvider } from './DDLGenerator.js';
|
|
13
|
+
export { MigrationFileWriter, FormatTimestamp, SanitizeForFileName } from './MigrationFileWriter.js';
|
|
14
|
+
export { SchemaEvolution } from './SchemaEvolution.js';
|
|
15
|
+
export { SoftFKConfigEmitter } from './SoftFKConfigEmitter.js';
|
|
16
|
+
// ─── Runtime Schema Manager ─────────────────────────────────────────
|
|
17
|
+
export { RuntimeSchemaManager, ValidateMigrationSQL, RSUError } from './RuntimeSchemaManager.js';
|
|
18
|
+
// ─── Metrics & Observability ────────────────────────────────────────
|
|
19
|
+
export { RSUMetrics } from './RSUMetrics.js';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqBH,wEAAwE;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAElH,4CAA4C;AAC5C,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAEtE,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,uEAAuE;AACvE,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAajG,uEAAuE;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @memberjunction/schema-engine — Shared Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Generic, platform-agnostic types for DDL generation.
|
|
5
|
+
* Any MJ consumer (integrations, AI agents, developers) can use these
|
|
6
|
+
* to describe tables and let SchemaEngine produce platform-correct SQL.
|
|
7
|
+
*/
|
|
8
|
+
/** Supported database platforms for DDL generation. */
|
|
9
|
+
export type DatabasePlatform = 'sqlserver' | 'postgresql';
|
|
10
|
+
/**
|
|
11
|
+
* Abstract field types understood by SchemaEngine.
|
|
12
|
+
* TypeMapper converts these to platform-specific SQL types.
|
|
13
|
+
*/
|
|
14
|
+
export type SchemaFieldType = 'string' | 'text' | 'integer' | 'bigint' | 'decimal' | 'boolean' | 'datetime' | 'date' | 'uuid' | 'json' | 'float' | 'time';
|
|
15
|
+
/**
|
|
16
|
+
* Platform-agnostic table definition — the universal input for DDL generation.
|
|
17
|
+
* Any consumer provides this; SchemaEngine produces platform-correct SQL.
|
|
18
|
+
*/
|
|
19
|
+
export interface TableDefinition {
|
|
20
|
+
/** Target database schema (e.g., "custom", "hubspot", "dbo"). */
|
|
21
|
+
SchemaName: string;
|
|
22
|
+
/** SQL table name (e.g., "UD_ProjectMilestones", "HubSpotContacts"). */
|
|
23
|
+
TableName: string;
|
|
24
|
+
/** MJ entity display name (e.g., "User: Project Milestones"). */
|
|
25
|
+
EntityName: string;
|
|
26
|
+
/** Human-readable description for the table. */
|
|
27
|
+
Description?: string;
|
|
28
|
+
/** Column definitions (in order). */
|
|
29
|
+
Columns: ColumnDefinition[];
|
|
30
|
+
/**
|
|
31
|
+
* Column names that form the soft primary key (UNIQUE constraint only).
|
|
32
|
+
* No DB-level PK is created — the unique constraint serves as the natural key.
|
|
33
|
+
*/
|
|
34
|
+
SoftPrimaryKeys?: string[];
|
|
35
|
+
/** Foreign key relationships (soft or hard). */
|
|
36
|
+
ForeignKeys?: ForeignKeyDefinition[];
|
|
37
|
+
/**
|
|
38
|
+
* Additional columns injected by the consumer (e.g., integration sync columns).
|
|
39
|
+
* SchemaEngine appends these after the user-defined Columns.
|
|
40
|
+
*/
|
|
41
|
+
AdditionalColumns?: ColumnDefinition[];
|
|
42
|
+
}
|
|
43
|
+
/** Definition of a single column. */
|
|
44
|
+
export interface ColumnDefinition {
|
|
45
|
+
/** Column name. */
|
|
46
|
+
Name: string;
|
|
47
|
+
/**
|
|
48
|
+
* Abstract type — TypeMapper converts to platform SQL type.
|
|
49
|
+
* Alternatively, pass a raw SQL type string via RawSqlType.
|
|
50
|
+
*/
|
|
51
|
+
Type: SchemaFieldType;
|
|
52
|
+
/**
|
|
53
|
+
* Optional: override with a raw platform-specific SQL type
|
|
54
|
+
* (e.g., "NVARCHAR(200)", "INT"). When set, Type is ignored.
|
|
55
|
+
*/
|
|
56
|
+
RawSqlType?: string;
|
|
57
|
+
/** Whether the column accepts NULL. */
|
|
58
|
+
IsNullable: boolean;
|
|
59
|
+
/** Max length for string types (ignored for non-string types). */
|
|
60
|
+
MaxLength?: number;
|
|
61
|
+
/** Precision for decimal types. */
|
|
62
|
+
Precision?: number;
|
|
63
|
+
/** Scale for decimal types. */
|
|
64
|
+
Scale?: number;
|
|
65
|
+
/** SQL expression for default value (e.g., "'Active'", "GETUTCDATE()"). */
|
|
66
|
+
DefaultValue?: string;
|
|
67
|
+
/** Human-readable description (sp_addextendedproperty in SQL Server, COMMENT ON in Postgres). */
|
|
68
|
+
Description?: string;
|
|
69
|
+
}
|
|
70
|
+
/** A foreign key relationship definition. */
|
|
71
|
+
export interface ForeignKeyDefinition {
|
|
72
|
+
/** Column in this table that holds the FK value. */
|
|
73
|
+
ColumnName: string;
|
|
74
|
+
/** Referenced schema. */
|
|
75
|
+
ReferencedSchema: string;
|
|
76
|
+
/** Referenced table name. */
|
|
77
|
+
ReferencedTable: string;
|
|
78
|
+
/** Referenced column name (typically "ID"). */
|
|
79
|
+
ReferencedColumn: string;
|
|
80
|
+
/**
|
|
81
|
+
* Whether this is a soft FK (metadata-only, no DB constraint)
|
|
82
|
+
* or a hard FK (real REFERENCES constraint).
|
|
83
|
+
*/
|
|
84
|
+
IsSoft: boolean;
|
|
85
|
+
}
|
|
86
|
+
/** Current state of an existing table in the target database. */
|
|
87
|
+
export interface ExistingTableInfo {
|
|
88
|
+
SchemaName: string;
|
|
89
|
+
TableName: string;
|
|
90
|
+
Columns: ExistingColumnInfo[];
|
|
91
|
+
}
|
|
92
|
+
/** Current state of a single column. */
|
|
93
|
+
export interface ExistingColumnInfo {
|
|
94
|
+
Name: string;
|
|
95
|
+
SqlType: string;
|
|
96
|
+
IsNullable: boolean;
|
|
97
|
+
MaxLength: number | null;
|
|
98
|
+
Precision: number | null;
|
|
99
|
+
Scale: number | null;
|
|
100
|
+
}
|
|
101
|
+
/** Result of comparing desired vs existing table state. */
|
|
102
|
+
export interface SchemaDiff {
|
|
103
|
+
/** Columns in desired that are not in existing — need ALTER TABLE ADD. */
|
|
104
|
+
AddedColumns: ColumnDefinition[];
|
|
105
|
+
/** Columns in both with different types/nullability — need ALTER TABLE ALTER. */
|
|
106
|
+
ModifiedColumns: ColumnModification[];
|
|
107
|
+
/** Columns in existing that are not in desired — deprecated (no physical drop). */
|
|
108
|
+
RemovedColumns: string[];
|
|
109
|
+
}
|
|
110
|
+
/** A single column type/nullability change. */
|
|
111
|
+
export interface ColumnModification {
|
|
112
|
+
ColumnName: string;
|
|
113
|
+
OldType: string;
|
|
114
|
+
NewType: string;
|
|
115
|
+
OldNullable: boolean;
|
|
116
|
+
NewNullable: boolean;
|
|
117
|
+
}
|
|
118
|
+
/** Input for schema evolution: desired state + existing state. */
|
|
119
|
+
export interface SchemaEvolutionInput {
|
|
120
|
+
/** The desired table definition. */
|
|
121
|
+
Desired: TableDefinition;
|
|
122
|
+
/** Current state of the table in the database. */
|
|
123
|
+
ExistingTable: ExistingTableInfo;
|
|
124
|
+
}
|
|
125
|
+
/** Maps a generic abstract type to platform-specific SQL types. */
|
|
126
|
+
export interface TypeMappingEntry {
|
|
127
|
+
/** Abstract type (e.g., "string", "integer"). */
|
|
128
|
+
SourceType: string;
|
|
129
|
+
/** SQL Server type template (e.g., "NVARCHAR"). */
|
|
130
|
+
SqlServerType: string;
|
|
131
|
+
/** PostgreSQL type template (e.g., "VARCHAR"). */
|
|
132
|
+
PostgresType: string;
|
|
133
|
+
/** MJ EntityField.Type value (informational — CodeGen discovers actual type). */
|
|
134
|
+
MJFieldType: string;
|
|
135
|
+
}
|
|
136
|
+
/** Output from SchemaEngine.GenerateMigration(). */
|
|
137
|
+
export interface MigrationOutput {
|
|
138
|
+
/** The generated SQL (CREATE TABLE, ALTER TABLE, CREATE SCHEMA, etc.). */
|
|
139
|
+
SQL: string;
|
|
140
|
+
/** Suggested migration file name in Flyway format (relative to repo root). */
|
|
141
|
+
FileName: string;
|
|
142
|
+
/** Fully-qualified table names affected (e.g., ["hubspot.Contacts"]). */
|
|
143
|
+
AffectedTables: string[];
|
|
144
|
+
/** Short human-readable summary for commit messages. */
|
|
145
|
+
Summary: string;
|
|
146
|
+
}
|
|
147
|
+
/** Metadata embedded in the migration file header comment. */
|
|
148
|
+
export interface MigrationMetadata {
|
|
149
|
+
/** Consumer name (e.g., "Integration", "Agent", "Custom"). */
|
|
150
|
+
SourceType: string;
|
|
151
|
+
/** Object being created/modified (e.g., table name). */
|
|
152
|
+
ObjectName: string;
|
|
153
|
+
/** Action description (e.g., "CreateTable", "AlterTable"). */
|
|
154
|
+
Action: string;
|
|
155
|
+
/** Who or what generated this migration. */
|
|
156
|
+
GeneratedBy: string;
|
|
157
|
+
/** ISO timestamp of generation. */
|
|
158
|
+
Timestamp: string;
|
|
159
|
+
}
|
|
160
|
+
/** A file produced by SchemaEngine (e.g., migration SQL). */
|
|
161
|
+
export interface EmittedFile {
|
|
162
|
+
/** Relative path from repo root. */
|
|
163
|
+
FilePath: string;
|
|
164
|
+
/** Full file content. */
|
|
165
|
+
Content: string;
|
|
166
|
+
/** Human-readable description. */
|
|
167
|
+
Description: string;
|
|
168
|
+
}
|
|
169
|
+
/** Result of validating a TableDefinition. */
|
|
170
|
+
export interface ValidationResult {
|
|
171
|
+
Valid: boolean;
|
|
172
|
+
Errors: string[];
|
|
173
|
+
Warnings: string[];
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,uDAAuD;AACvD,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,YAAY,CAAC;AAI1D;;;GAGG;AACH,MAAM,MAAM,eAAe,GACrB,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GACpD,SAAS,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GACjD,OAAO,GAAG,MAAM,CAAC;AAIvB;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC5B,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAC;IAEnB,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;IAElB,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAC;IAEnB,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,qCAAqC;IACrC,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAE5B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B,gDAAgD;IAChD,WAAW,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAErC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC1C;AAED,qCAAqC;AACrC,MAAM,WAAW,gBAAgB;IAC7B,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,EAAE,eAAe,CAAC;IAEtB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,uCAAuC;IACvC,UAAU,EAAE,OAAO,CAAC;IAEpB,k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AAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACtB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @memberjunction/schema-engine — Shared Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Generic, platform-agnostic types for DDL generation.
|
|
5
|
+
* Any MJ consumer (integrations, AI agents, developers) can use these
|
|
6
|
+
* to describe tables and let SchemaEngine produce platform-correct SQL.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=interfaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for SchemaEngine — identifier validation and SQL escaping.
|
|
3
|
+
*/
|
|
4
|
+
/** Validates that an identifier contains only safe characters. */
|
|
5
|
+
export declare function ValidateIdentifier(name: string, kind: string): void;
|
|
6
|
+
/** Escapes single quotes in a string for use in SQL string literals. */
|
|
7
|
+
export declare function EscapeSqlString(value: string): string;
|
|
8
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,kEAAkE;AAClE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAInE;AAED,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAErD"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for SchemaEngine — identifier validation and SQL escaping.
|
|
3
|
+
*/
|
|
4
|
+
/** Characters allowed in SQL identifiers (schema, table, column names). */
|
|
5
|
+
const IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
6
|
+
/** Validates that an identifier contains only safe characters. */
|
|
7
|
+
export function ValidateIdentifier(name, kind) {
|
|
8
|
+
if (!IDENTIFIER_RE.test(name)) {
|
|
9
|
+
throw new Error(`Invalid ${kind} name "${name}": must match ${IDENTIFIER_RE.source}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Escapes single quotes in a string for use in SQL string literals. */
|
|
13
|
+
export function EscapeSqlString(value) {
|
|
14
|
+
return value.replace(/'/g, "''");
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,2EAA2E;AAC3E,MAAM,aAAa,GAAG,0BAA0B,CAAC;AAEjD,kEAAkE;AAClE,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,IAAY;IAC3D,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,UAAU,IAAI,iBAAiB,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;IACxF,CAAC;AACH,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/schema-engine",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "5.17.0",
|
|
5
|
+
"description": "MemberJunction Schema Engine - generic, platform-aware DDL generation for any MJ consumer (integrations, agents, developers)",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"/dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc && tsc-alias -f",
|
|
13
|
+
"test": "vitest run",
|
|
14
|
+
"test:watch": "vitest"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@memberjunction/global": "5.17.0",
|
|
18
|
+
"@memberjunction/core": "5.17.0",
|
|
19
|
+
"@memberjunction/sql-dialect": "5.17.0",
|
|
20
|
+
"@memberjunction/queue": "5.17.0",
|
|
21
|
+
"@octokit/rest": "^21.1.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.9.3",
|
|
25
|
+
"tsc-alias": "^1.8.16",
|
|
26
|
+
"vitest": "^4.0.18"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/MemberJunction/MJ"
|
|
31
|
+
},
|
|
32
|
+
"author": "MemberJunction.com",
|
|
33
|
+
"license": "ISC"
|
|
10
34
|
}
|
package/README.md
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# @memberjunction/schema-engine
|
|
2
|
-
|
|
3
|
-
## ⚠️ IMPORTANT NOTICE ⚠️
|
|
4
|
-
|
|
5
|
-
**This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
|
|
6
|
-
|
|
7
|
-
This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
|
|
8
|
-
|
|
9
|
-
## Purpose
|
|
10
|
-
|
|
11
|
-
This package exists to:
|
|
12
|
-
1. Configure OIDC trusted publishing for the package name `@memberjunction/schema-engine`
|
|
13
|
-
2. Enable secure, token-less publishing from CI/CD workflows
|
|
14
|
-
3. Establish provenance for packages published under this name
|
|
15
|
-
|
|
16
|
-
## What is OIDC Trusted Publishing?
|
|
17
|
-
|
|
18
|
-
OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
|
|
19
|
-
|
|
20
|
-
## Setup Instructions
|
|
21
|
-
|
|
22
|
-
To properly configure OIDC trusted publishing for this package:
|
|
23
|
-
|
|
24
|
-
1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
|
|
25
|
-
2. Configure the trusted publisher (e.g., GitHub Actions)
|
|
26
|
-
3. Specify the repository and workflow that should be allowed to publish
|
|
27
|
-
4. Use the configured workflow to publish your actual package
|
|
28
|
-
|
|
29
|
-
## DO NOT USE THIS PACKAGE
|
|
30
|
-
|
|
31
|
-
This package is a placeholder for OIDC configuration only. It:
|
|
32
|
-
- Contains no executable code
|
|
33
|
-
- Provides no functionality
|
|
34
|
-
- Should not be installed as a dependency
|
|
35
|
-
- Exists only for administrative purposes
|
|
36
|
-
|
|
37
|
-
## More Information
|
|
38
|
-
|
|
39
|
-
For more details about npm's trusted publishing feature, see:
|
|
40
|
-
- [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
|
|
41
|
-
- [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
**Maintained for OIDC setup purposes only**
|