@tstdl/base 0.93.78 → 0.93.80
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/authentication/server/drizzle/{0001_condemned_pretty_boy.sql → 0000_violet_callisto.sql} +34 -5
- package/authentication/server/drizzle/meta/0000_snapshot.json +500 -6
- package/authentication/server/drizzle/meta/_journal.json +2 -9
- package/document-management/server/drizzle/{0000_ordinary_pretty_boy.sql → 0000_glamorous_lorna_dane.sql} +96 -76
- package/document-management/server/drizzle/meta/0000_snapshot.json +360 -142
- package/document-management/server/drizzle/meta/_journal.json +2 -16
- package/orm/server/drizzle/schema-converter.js +53 -32
- package/package.json +1 -1
- package/authentication/server/drizzle/0000_calm_warlock.sql +0 -28
- package/authentication/server/drizzle/meta/0001_snapshot.json +0 -651
- package/document-management/server/drizzle/0001_lyrical_wong.sql +0 -123
- package/document-management/server/drizzle/0002_round_warbird.sql +0 -1
- package/document-management/server/drizzle/meta/0001_snapshot.json +0 -2728
- package/document-management/server/drizzle/meta/0002_snapshot.json +0 -2722
|
@@ -5,22 +5,8 @@
|
|
|
5
5
|
{
|
|
6
6
|
"idx": 0,
|
|
7
7
|
"version": "7",
|
|
8
|
-
"when":
|
|
9
|
-
"tag": "
|
|
10
|
-
"breakpoints": true
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"idx": 1,
|
|
14
|
-
"version": "7",
|
|
15
|
-
"when": 1764857079867,
|
|
16
|
-
"tag": "0001_lyrical_wong",
|
|
17
|
-
"breakpoints": true
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"idx": 2,
|
|
21
|
-
"version": "7",
|
|
22
|
-
"when": 1767824153882,
|
|
23
|
-
"tag": "0002_round_warbird",
|
|
8
|
+
"when": 1767826943882,
|
|
9
|
+
"tag": "0000_glamorous_lorna_dane",
|
|
24
10
|
"breakpoints": true
|
|
25
11
|
}
|
|
26
12
|
]
|
|
@@ -33,19 +33,10 @@ export function getColumnDefinitionsMap(table) {
|
|
|
33
33
|
return table[columnDefinitionsMapSymbol];
|
|
34
34
|
}
|
|
35
35
|
export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
36
|
-
const
|
|
37
|
-
assertDefined(metadata, `Type ${type.name} does not have reflection metadata.`);
|
|
38
|
-
const tableReflectionDatas = [];
|
|
39
|
-
for (let currentMetadata = metadata; isNotNullOrUndefined(currentMetadata?.parent); currentMetadata = reflectionRegistry.getMetadata(currentMetadata.parent)) {
|
|
40
|
-
const tableReflectionData = currentMetadata.data.tryGet('orm');
|
|
41
|
-
if (isDefined(tableReflectionData)) {
|
|
42
|
-
tableReflectionDatas.push(tableReflectionData);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
36
|
+
const tableReflectionDatas = getTableReflectionDatas(type);
|
|
45
37
|
const mergedTableReflectionData = tableReflectionDatas.reduceRight((merged, data) => ({ ...merged, ...data }), {});
|
|
46
|
-
const tableReflectionData = tableReflectionDatas[0];
|
|
47
38
|
const schema = assertDefinedPass(mergedTableReflectionData.schema ?? fallbackSchemaName, 'Table schema not provided');
|
|
48
|
-
const tableName =
|
|
39
|
+
const tableName = getTableName(type);
|
|
49
40
|
const dbSchema = getDbSchema(schema);
|
|
50
41
|
const columnDefinitions = getPostgresColumnEntries(type, dbSchema, tableName);
|
|
51
42
|
const columnDefinitionsMap = new Map(columnDefinitions.map((column) => [column.objectPath.path, column]));
|
|
@@ -194,7 +185,7 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
194
185
|
const foreignTable = getDrizzleTableFromType(tenantReferenceData.target(), dbSchema.schemaName);
|
|
195
186
|
const nonTenantColumn = tenantReferenceData.targetColumn ?? 'id';
|
|
196
187
|
return foreignKey({
|
|
197
|
-
name: getForeignKeyName(tableName, [nonTenantColumn]),
|
|
188
|
+
name: getForeignKeyName(tableName, getTableName(tenantReferenceData.target()), [nonTenantColumn]),
|
|
198
189
|
columns: [getColumn(table, 'tenantId'), getColumn(table, columnDefinition.name)],
|
|
199
190
|
foreignColumns: [getColumn(foreignTable, 'tenantId'), getColumn(foreignTable, nonTenantColumn)],
|
|
200
191
|
});
|
|
@@ -204,7 +195,7 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
204
195
|
return tableReflectionData.foreignKeys?.map((foreignKeyData) => {
|
|
205
196
|
const foreignTable = getDrizzleTableFromType(foreignKeyData.target(), dbSchema.schemaName);
|
|
206
197
|
return foreignKey({
|
|
207
|
-
name: foreignKeyData.options?.name ?? getForeignKeyName(tableName, foreignKeyData.columns, { naming: foreignKeyData.options?.naming }),
|
|
198
|
+
name: foreignKeyData.options?.name ?? getForeignKeyName(tableName, getTableName(foreignKeyData.target()), foreignKeyData.columns, { naming: foreignKeyData.options?.naming }),
|
|
208
199
|
columns: foreignKeyData.columns.map((column) => getColumn(table, column)),
|
|
209
200
|
foreignColumns: foreignKeyData.foreignColumns.map((column) => getColumn(foreignTable, column)),
|
|
210
201
|
});
|
|
@@ -227,6 +218,25 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
227
218
|
drizzleSchema[columnDefinitionsMapSymbol] = columnDefinitionsMap;
|
|
228
219
|
return drizzleSchema;
|
|
229
220
|
}
|
|
221
|
+
function unwrapSchema(schema) {
|
|
222
|
+
let nullable = false;
|
|
223
|
+
let array = false;
|
|
224
|
+
let currentSchema = schema;
|
|
225
|
+
while (true) {
|
|
226
|
+
if ((currentSchema instanceof NullableSchema) || (currentSchema instanceof OptionalSchema)) {
|
|
227
|
+
nullable = true;
|
|
228
|
+
currentSchema = currentSchema.schema;
|
|
229
|
+
}
|
|
230
|
+
else if (currentSchema instanceof ArraySchema) {
|
|
231
|
+
array = true;
|
|
232
|
+
currentSchema = currentSchema.itemSchema;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return { schema: currentSchema, nullable, array };
|
|
239
|
+
}
|
|
230
240
|
function getPostgresColumnEntries(type, dbSchema, tableName, path = new JsonPath({ dollar: false }), prefix = '') {
|
|
231
241
|
const metadata = reflectionRegistry.getMetadata(type);
|
|
232
242
|
assertDefined(metadata, `Type ${type.name} does not have reflection metadata (path: ${path.toString()}).`);
|
|
@@ -269,23 +279,8 @@ function getPostgresColumnEntries(type, dbSchema, tableName, path = new JsonPath
|
|
|
269
279
|
return entries;
|
|
270
280
|
}
|
|
271
281
|
function getPostgresColumn(tableName, columnName, dbSchema, propertySchema, reflectionData, options, context) {
|
|
272
|
-
|
|
273
|
-
let
|
|
274
|
-
let baseSchema = propertySchema;
|
|
275
|
-
while (true) {
|
|
276
|
-
if ((baseSchema instanceof NullableSchema) || (baseSchema instanceof OptionalSchema)) {
|
|
277
|
-
nullable = true;
|
|
278
|
-
baseSchema = baseSchema.schema;
|
|
279
|
-
}
|
|
280
|
-
else if (baseSchema instanceof ArraySchema) {
|
|
281
|
-
array = true;
|
|
282
|
-
baseSchema = baseSchema.itemSchema;
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
let column = getPostgresBaseColumn(columnName, dbSchema, baseSchema, reflectionData, context);
|
|
282
|
+
const { schema, nullable, array } = unwrapSchema(propertySchema);
|
|
283
|
+
let column = getPostgresBaseColumn(columnName, dbSchema, schema, reflectionData, context);
|
|
289
284
|
if (array) {
|
|
290
285
|
column = column.array();
|
|
291
286
|
}
|
|
@@ -371,8 +366,34 @@ function getIndexName(tableName, columnsOrBaseName, options) {
|
|
|
371
366
|
function getUniqueName(tableName, columnsOrBaseName, options) {
|
|
372
367
|
return getIdentifier(tableName, columnsOrBaseName, 'unique', options);
|
|
373
368
|
}
|
|
374
|
-
function getForeignKeyName(tableName, columnsOrBaseName, options) {
|
|
375
|
-
|
|
369
|
+
function getForeignKeyName(tableName, foreignTableName, columnsOrBaseName, options) {
|
|
370
|
+
const middle = isString(columnsOrBaseName) ? columnsOrBaseName : getColumnNames(columnsOrBaseName).join('_');
|
|
371
|
+
const identifier = `${getTablePrefix(tableName, options?.naming)}_${middle}_${getTablePrefix(foreignTableName, options?.naming)}_fkey`;
|
|
372
|
+
if (identifier.length > 63) {
|
|
373
|
+
if (options?.naming != 'abbreviated-table') {
|
|
374
|
+
return getForeignKeyName(tableName, foreignTableName, columnsOrBaseName, { naming: 'abbreviated-table' });
|
|
375
|
+
}
|
|
376
|
+
throw new Error(`Identifier "${identifier}" for table "${tableName}" is too long. Maximum length is 63 characters.`);
|
|
377
|
+
}
|
|
378
|
+
console.log(tableName, foreignTableName, columnsOrBaseName, 'Foreign key name:', identifier);
|
|
379
|
+
return identifier;
|
|
380
|
+
}
|
|
381
|
+
function getTableName(type) {
|
|
382
|
+
const tableReflectionDatas = getTableReflectionDatas(type);
|
|
383
|
+
const tableReflectionData = tableReflectionDatas[0];
|
|
384
|
+
return tableReflectionData?.name ?? getDefaultTableName(type);
|
|
385
|
+
}
|
|
386
|
+
function getTableReflectionDatas(type) {
|
|
387
|
+
const metadata = reflectionRegistry.getMetadata(type);
|
|
388
|
+
assertDefined(metadata, `Type ${type.name} does not have reflection metadata.`);
|
|
389
|
+
const tableReflectionDatas = [];
|
|
390
|
+
for (let currentMetadata = metadata; isNotNullOrUndefined(currentMetadata?.parent); currentMetadata = reflectionRegistry.getMetadata(currentMetadata.parent)) {
|
|
391
|
+
const tableReflectionData = currentMetadata.data.tryGet('orm');
|
|
392
|
+
if (isDefined(tableReflectionData)) {
|
|
393
|
+
tableReflectionDatas.push(tableReflectionData);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return tableReflectionDatas;
|
|
376
397
|
}
|
|
377
398
|
function getIdentifier(tableName, columnsOrBaseName, suffix, options) {
|
|
378
399
|
const middle = isString(columnsOrBaseName) ? columnsOrBaseName : getColumnNames(columnsOrBaseName).join('_');
|
package/package.json
CHANGED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
CREATE TABLE "authentication"."credentials" (
|
|
2
|
-
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
3
|
-
"subject" text NOT NULL,
|
|
4
|
-
"hash_version" integer NOT NULL,
|
|
5
|
-
"salt" "bytea" NOT NULL,
|
|
6
|
-
"hash" "bytea" NOT NULL,
|
|
7
|
-
"revision" integer NOT NULL,
|
|
8
|
-
"revision_timestamp" timestamp with time zone NOT NULL,
|
|
9
|
-
"create_timestamp" timestamp with time zone NOT NULL,
|
|
10
|
-
"delete_timestamp" timestamp with time zone,
|
|
11
|
-
"attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
12
|
-
CONSTRAINT "credentials_subject_unique" UNIQUE("subject")
|
|
13
|
-
);
|
|
14
|
-
--> statement-breakpoint
|
|
15
|
-
CREATE TABLE "authentication"."session" (
|
|
16
|
-
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
17
|
-
"subject" text NOT NULL,
|
|
18
|
-
"begin" timestamp with time zone NOT NULL,
|
|
19
|
-
"end" timestamp with time zone NOT NULL,
|
|
20
|
-
"refresh_token_hash_version" integer NOT NULL,
|
|
21
|
-
"refresh_token_salt" "bytea" NOT NULL,
|
|
22
|
-
"refresh_token_hash" "bytea" NOT NULL,
|
|
23
|
-
"revision" integer NOT NULL,
|
|
24
|
-
"revision_timestamp" timestamp with time zone NOT NULL,
|
|
25
|
-
"create_timestamp" timestamp with time zone NOT NULL,
|
|
26
|
-
"delete_timestamp" timestamp with time zone,
|
|
27
|
-
"attributes" jsonb DEFAULT '{}'::jsonb NOT NULL
|
|
28
|
-
);
|