@prisma-next/target-postgres 0.16.0-dev.27 → 0.16.0-dev.29
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/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/target-postgres",
|
|
3
|
-
"version": "0.16.0-dev.
|
|
3
|
+
"version": "0.16.0-dev.29",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "Postgres target pack for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/cli": "0.16.0-dev.
|
|
10
|
-
"@prisma-next/contract": "0.16.0-dev.
|
|
11
|
-
"@prisma-next/errors": "0.16.0-dev.
|
|
12
|
-
"@prisma-next/family-sql": "0.16.0-dev.
|
|
13
|
-
"@prisma-next/framework-components": "0.16.0-dev.
|
|
14
|
-
"@prisma-next/migration-tools": "0.16.0-dev.
|
|
15
|
-
"@prisma-next/psl-parser": "0.16.0-dev.
|
|
16
|
-
"@prisma-next/sql-contract": "0.16.0-dev.
|
|
17
|
-
"@prisma-next/sql-errors": "0.16.0-dev.
|
|
18
|
-
"@prisma-next/sql-operations": "0.16.0-dev.
|
|
19
|
-
"@prisma-next/sql-relational-core": "0.16.0-dev.
|
|
20
|
-
"@prisma-next/sql-schema-ir": "0.16.0-dev.
|
|
21
|
-
"@prisma-next/ts-render": "0.16.0-dev.
|
|
22
|
-
"@prisma-next/utils": "0.16.0-dev.
|
|
9
|
+
"@prisma-next/cli": "0.16.0-dev.29",
|
|
10
|
+
"@prisma-next/contract": "0.16.0-dev.29",
|
|
11
|
+
"@prisma-next/errors": "0.16.0-dev.29",
|
|
12
|
+
"@prisma-next/family-sql": "0.16.0-dev.29",
|
|
13
|
+
"@prisma-next/framework-components": "0.16.0-dev.29",
|
|
14
|
+
"@prisma-next/migration-tools": "0.16.0-dev.29",
|
|
15
|
+
"@prisma-next/psl-parser": "0.16.0-dev.29",
|
|
16
|
+
"@prisma-next/sql-contract": "0.16.0-dev.29",
|
|
17
|
+
"@prisma-next/sql-errors": "0.16.0-dev.29",
|
|
18
|
+
"@prisma-next/sql-operations": "0.16.0-dev.29",
|
|
19
|
+
"@prisma-next/sql-relational-core": "0.16.0-dev.29",
|
|
20
|
+
"@prisma-next/sql-schema-ir": "0.16.0-dev.29",
|
|
21
|
+
"@prisma-next/ts-render": "0.16.0-dev.29",
|
|
22
|
+
"@prisma-next/utils": "0.16.0-dev.29",
|
|
23
23
|
"@standard-schema/spec": "^1.1.0",
|
|
24
24
|
"arktype": "^2.2.2",
|
|
25
25
|
"pathe": "^2.0.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@prisma-next/psl-printer": "0.16.0-dev.
|
|
29
|
-
"@prisma-next/sql-contract-psl": "0.16.0-dev.
|
|
30
|
-
"@prisma-next/test-utils": "0.16.0-dev.
|
|
31
|
-
"@prisma-next/tsconfig": "0.16.0-dev.
|
|
32
|
-
"@prisma-next/tsdown": "0.16.0-dev.
|
|
28
|
+
"@prisma-next/psl-printer": "0.16.0-dev.29",
|
|
29
|
+
"@prisma-next/sql-contract-psl": "0.16.0-dev.29",
|
|
30
|
+
"@prisma-next/test-utils": "0.16.0-dev.29",
|
|
31
|
+
"@prisma-next/tsconfig": "0.16.0-dev.29",
|
|
32
|
+
"@prisma-next/tsdown": "0.16.0-dev.29",
|
|
33
33
|
"tsdown": "0.22.8",
|
|
34
34
|
"typescript": "5.9.3",
|
|
35
35
|
"vitest": "4.1.10"
|
package/src/core/codecs.ts
CHANGED
|
@@ -1351,7 +1351,7 @@ export const codecDescriptors: readonly AnyCodecDescriptor[] = [
|
|
|
1351
1351
|
pgFloat4Descriptor,
|
|
1352
1352
|
pgFloat8Descriptor,
|
|
1353
1353
|
pgNumericDescriptor,
|
|
1354
|
-
// PSL
|
|
1354
|
+
// PSL `Date` pins this codec by ID rather than activating a second target-type mapping.
|
|
1355
1355
|
pgDateDescriptor,
|
|
1356
1356
|
pgTimestampDescriptor,
|
|
1357
1357
|
pgTimestamptzDescriptor,
|
|
@@ -3,7 +3,6 @@ import type { SqlDescribedContractSpace } from '@prisma-next/family-sql/control'
|
|
|
3
3
|
import type {
|
|
4
4
|
DefaultMappingOptions,
|
|
5
5
|
EnumInfo,
|
|
6
|
-
PslNativeTypeAttribute,
|
|
7
6
|
PslPrinterOptions,
|
|
8
7
|
PslTypeMap,
|
|
9
8
|
RelationField,
|
|
@@ -18,7 +17,6 @@ import {
|
|
|
18
17
|
toEnumName,
|
|
19
18
|
toFieldName,
|
|
20
19
|
toModelName,
|
|
21
|
-
toNamedTypeName,
|
|
22
20
|
} from '@prisma-next/family-sql/psl-infer';
|
|
23
21
|
import { coordinateKey, elementCoordinates } from '@prisma-next/framework-components/ir';
|
|
24
22
|
import type {
|
|
@@ -31,10 +29,8 @@ import type {
|
|
|
31
29
|
PslFieldAttribute,
|
|
32
30
|
PslModel,
|
|
33
31
|
PslModelAttribute,
|
|
34
|
-
PslNamedTypeDeclaration,
|
|
35
32
|
PslSpan,
|
|
36
33
|
PslTypeConstructorCall,
|
|
37
|
-
PslTypesBlock,
|
|
38
34
|
} from '@prisma-next/framework-components/psl-ast';
|
|
39
35
|
import {
|
|
40
36
|
makePslNamespace,
|
|
@@ -46,7 +42,6 @@ import type { SqlColumnIR, SqlForeignKeyIR } from '@prisma-next/sql-schema-ir/ty
|
|
|
46
42
|
import { SqlSchemaIR, SqlTableIR } from '@prisma-next/sql-schema-ir/types';
|
|
47
43
|
import { blindCast } from '@prisma-next/utils/casts';
|
|
48
44
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
49
|
-
import { InternalError } from '@prisma-next/utils/internal-error';
|
|
50
45
|
import { postgresError } from '../errors';
|
|
51
46
|
import type { PostgresDatabaseSchemaNode } from '../schema-ir/postgres-database-schema-node';
|
|
52
47
|
import { createPostgresDefaultMapping } from './postgres-default-mapping';
|
|
@@ -76,17 +71,6 @@ type ResolvedColumnFieldName = {
|
|
|
76
71
|
|
|
77
72
|
type TableColumnFieldNameMap = ReadonlyMap<string, ResolvedColumnFieldName>;
|
|
78
73
|
|
|
79
|
-
type NamedTypeRegistryEntry = {
|
|
80
|
-
readonly name: string;
|
|
81
|
-
readonly baseType: string;
|
|
82
|
-
readonly nativeTypeAttribute: PslNativeTypeAttribute;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
type NamedTypeRegistry = {
|
|
86
|
-
readonly entriesByKey: Map<string, NamedTypeRegistryEntry>;
|
|
87
|
-
readonly usedNames: Set<string>;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
74
|
type TopLevelNameResult = {
|
|
91
75
|
readonly name: string;
|
|
92
76
|
readonly map?: string | undefined;
|
|
@@ -521,8 +505,6 @@ export function buildPslDocumentAst(
|
|
|
521
505
|
}
|
|
522
506
|
}
|
|
523
507
|
|
|
524
|
-
const reservedNamedTypeNames = createReservedNamedTypeNames(modelNames, enumNameMap);
|
|
525
|
-
|
|
526
508
|
// Cross-space entries are seeded first so a real local table of the same
|
|
527
509
|
// bare name (an existing single-namespace-flat-bucket limitation, not new
|
|
528
510
|
// here) always wins the merge, matching `resolveForeignKeys`'s own
|
|
@@ -532,7 +514,6 @@ export function buildPslDocumentAst(
|
|
|
532
514
|
...buildFieldNamesByTable(schemaIR.tables),
|
|
533
515
|
]);
|
|
534
516
|
const { relationsByTable } = inferRelations(schemaIR.tables, modelNameMap);
|
|
535
|
-
const namedTypes = seedNamedTypeRegistry(schemaIR, typeMap, enumNameMap, reservedNamedTypeNames);
|
|
536
517
|
|
|
537
518
|
const models: PslModel[] = [];
|
|
538
519
|
for (const table of Object.values(schemaIR.tables)) {
|
|
@@ -542,7 +523,6 @@ export function buildPslDocumentAst(
|
|
|
542
523
|
typeMap,
|
|
543
524
|
enumNameMap,
|
|
544
525
|
fieldNamesByTable,
|
|
545
|
-
namedTypes,
|
|
546
526
|
defaultMapping,
|
|
547
527
|
rawDefaultParser,
|
|
548
528
|
[
|
|
@@ -556,18 +536,6 @@ export function buildPslDocumentAst(
|
|
|
556
536
|
|
|
557
537
|
const sortedModels = topologicalSort(models, schemaIR.tables, modelNameMap);
|
|
558
538
|
|
|
559
|
-
const namedTypeEntries = [...namedTypes.entriesByKey.values()].sort((a, b) =>
|
|
560
|
-
a.name.localeCompare(b.name),
|
|
561
|
-
);
|
|
562
|
-
const types: PslTypesBlock | undefined =
|
|
563
|
-
namedTypeEntries.length > 0
|
|
564
|
-
? {
|
|
565
|
-
kind: 'types',
|
|
566
|
-
declarations: namedTypeEntries.map(buildNamedTypeDeclaration),
|
|
567
|
-
span: SYNTHETIC_SPAN,
|
|
568
|
-
}
|
|
569
|
-
: undefined;
|
|
570
|
-
|
|
571
539
|
// Inferred PSL nodes will eventually be routed into per-namespace buckets
|
|
572
540
|
// matching the source storage; for now everything lands in a single bucket.
|
|
573
541
|
// Without a `namespaceName` that bucket is the synthesised `__unspecified__`
|
|
@@ -586,7 +554,6 @@ export function buildPslDocumentAst(
|
|
|
586
554
|
span: SYNTHETIC_SPAN,
|
|
587
555
|
}),
|
|
588
556
|
],
|
|
589
|
-
...(types ? { types } : {}),
|
|
590
557
|
span: SYNTHETIC_SPAN,
|
|
591
558
|
};
|
|
592
559
|
|
|
@@ -680,7 +647,6 @@ function buildModel(
|
|
|
680
647
|
typeMap: PslTypeMap,
|
|
681
648
|
enumNameMap: ReadonlyMap<string, string>,
|
|
682
649
|
fieldNamesByTable: ReadonlyMap<string, TableColumnFieldNameMap>,
|
|
683
|
-
namedTypes: NamedTypeRegistry,
|
|
684
650
|
defaultMapping: DefaultMappingOptions | undefined,
|
|
685
651
|
rawDefaultParser: PslPrinterOptions['parseRawDefault'],
|
|
686
652
|
relationFields: readonly RelationField[],
|
|
@@ -713,7 +679,6 @@ function buildModel(
|
|
|
713
679
|
typeMap,
|
|
714
680
|
enumNameMap,
|
|
715
681
|
fieldNameMap,
|
|
716
|
-
namedTypes,
|
|
717
682
|
defaultMapping,
|
|
718
683
|
rawDefaultParser,
|
|
719
684
|
pkColumns,
|
|
@@ -832,7 +797,6 @@ function buildScalarField(
|
|
|
832
797
|
typeMap: PslTypeMap,
|
|
833
798
|
enumNameMap: ReadonlyMap<string, string>,
|
|
834
799
|
fieldNameMap: TableColumnFieldNameMap | undefined,
|
|
835
|
-
namedTypes: NamedTypeRegistry,
|
|
836
800
|
defaultMapping: DefaultMappingOptions | undefined,
|
|
837
801
|
rawDefaultParser: PslPrinterOptions['parseRawDefault'],
|
|
838
802
|
pkColumns: ReadonlySet<string>,
|
|
@@ -866,8 +830,15 @@ function buildScalarField(
|
|
|
866
830
|
// the Phase-1 authoring form a `native_enum` ref field takes — not a bare
|
|
867
831
|
// name substitution. The printer renders `typeConstructor` when present and
|
|
868
832
|
// composes `?`/`[]` exactly like any other field type.
|
|
869
|
-
let typeName = resolution.pslType;
|
|
870
|
-
let typeConstructor: PslTypeConstructorCall | undefined
|
|
833
|
+
let typeName = resolution.pslType.name;
|
|
834
|
+
let typeConstructor: PslTypeConstructorCall | undefined = resolution.pslType.args
|
|
835
|
+
? {
|
|
836
|
+
kind: 'typeConstructor',
|
|
837
|
+
path: [resolution.pslType.name],
|
|
838
|
+
args: resolution.pslType.args.map(positionalArg),
|
|
839
|
+
span: SYNTHETIC_SPAN,
|
|
840
|
+
}
|
|
841
|
+
: undefined;
|
|
871
842
|
const enumPslName = enumNameMap.get(column.nativeType);
|
|
872
843
|
if (enumPslName) {
|
|
873
844
|
typeName = enumPslName;
|
|
@@ -878,9 +849,6 @@ function buildScalarField(
|
|
|
878
849
|
span: SYNTHETIC_SPAN,
|
|
879
850
|
};
|
|
880
851
|
}
|
|
881
|
-
if (resolution.nativeTypeAttribute && !enumPslName) {
|
|
882
|
-
typeName = resolveNamedTypeName(namedTypes, resolution);
|
|
883
|
-
}
|
|
884
852
|
|
|
885
853
|
const attributes: PslFieldAttribute[] = [];
|
|
886
854
|
const isId = isSinglePk && pkColumns.has(column.name);
|
|
@@ -1080,21 +1048,6 @@ function namedArg(name: string, value: string): PslAttributeArgument {
|
|
|
1080
1048
|
return { kind: 'named', name, value, span: SYNTHETIC_SPAN };
|
|
1081
1049
|
}
|
|
1082
1050
|
|
|
1083
|
-
function buildNamedTypeDeclaration(entry: NamedTypeRegistryEntry): PslNamedTypeDeclaration {
|
|
1084
|
-
const attribute = buildAttribute(
|
|
1085
|
-
'namedType',
|
|
1086
|
-
entry.nativeTypeAttribute.name,
|
|
1087
|
-
(entry.nativeTypeAttribute.args ?? []).map(positionalArg),
|
|
1088
|
-
);
|
|
1089
|
-
return {
|
|
1090
|
-
kind: 'namedType',
|
|
1091
|
-
name: entry.name,
|
|
1092
|
-
baseType: entry.baseType,
|
|
1093
|
-
attributes: [attribute],
|
|
1094
|
-
span: SYNTHETIC_SPAN,
|
|
1095
|
-
};
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
1051
|
function escapePslString(value: string): string {
|
|
1099
1052
|
return value
|
|
1100
1053
|
.replace(/\\/g, '\\\\')
|
|
@@ -1249,131 +1202,6 @@ function buildTopLevelNameMap(
|
|
|
1249
1202
|
return results;
|
|
1250
1203
|
}
|
|
1251
1204
|
|
|
1252
|
-
function createReservedNamedTypeNames(
|
|
1253
|
-
modelNames: ReadonlyMap<string, TopLevelNameResult>,
|
|
1254
|
-
enumNameMap: ReadonlyMap<string, string>,
|
|
1255
|
-
): Set<string> {
|
|
1256
|
-
const reservedNames = new Set<string>(PSL_SCALAR_TYPE_NAMES);
|
|
1257
|
-
|
|
1258
|
-
for (const result of modelNames.values()) {
|
|
1259
|
-
reservedNames.add(result.name);
|
|
1260
|
-
}
|
|
1261
|
-
for (const enumPslName of enumNameMap.values()) {
|
|
1262
|
-
reservedNames.add(enumPslName);
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
return reservedNames;
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
function seedNamedTypeRegistry(
|
|
1269
|
-
schemaIR: SqlSchemaIR,
|
|
1270
|
-
typeMap: PslTypeMap,
|
|
1271
|
-
enumNameMap: ReadonlyMap<string, string>,
|
|
1272
|
-
reservedNames: ReadonlySet<string>,
|
|
1273
|
-
): NamedTypeRegistry {
|
|
1274
|
-
type Seed = {
|
|
1275
|
-
readonly baseType: string;
|
|
1276
|
-
readonly desiredName: string;
|
|
1277
|
-
readonly nativeTypeAttribute: PslNativeTypeAttribute;
|
|
1278
|
-
};
|
|
1279
|
-
|
|
1280
|
-
const seeds = new Map<string, Seed>();
|
|
1281
|
-
|
|
1282
|
-
for (const tableName of Object.keys(schemaIR.tables).sort()) {
|
|
1283
|
-
const table = schemaIR.tables[tableName];
|
|
1284
|
-
if (!table) {
|
|
1285
|
-
continue;
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
for (const columnName of Object.keys(table.columns).sort()) {
|
|
1289
|
-
const column = table.columns[columnName];
|
|
1290
|
-
if (!column) {
|
|
1291
|
-
continue;
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
const resolution = typeMap.resolve(column.nativeType, table.annotations);
|
|
1295
|
-
if (
|
|
1296
|
-
'unsupported' in resolution ||
|
|
1297
|
-
enumNameMap.has(column.nativeType) ||
|
|
1298
|
-
!resolution.nativeTypeAttribute
|
|
1299
|
-
) {
|
|
1300
|
-
continue;
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
const signatureKey = createNamedTypeSignatureKey(resolution);
|
|
1304
|
-
if (!seeds.has(signatureKey)) {
|
|
1305
|
-
seeds.set(signatureKey, {
|
|
1306
|
-
baseType: resolution.pslType,
|
|
1307
|
-
desiredName: toNamedTypeName(column.name),
|
|
1308
|
-
nativeTypeAttribute: resolution.nativeTypeAttribute,
|
|
1309
|
-
});
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1314
|
-
const registry: NamedTypeRegistry = {
|
|
1315
|
-
entriesByKey: new Map<string, NamedTypeRegistryEntry>(),
|
|
1316
|
-
usedNames: new Set<string>(reservedNames),
|
|
1317
|
-
};
|
|
1318
|
-
|
|
1319
|
-
const sortedSeeds = [...seeds.entries()].sort((left, right) => {
|
|
1320
|
-
const desiredNameComparison = left[1].desiredName.localeCompare(right[1].desiredName);
|
|
1321
|
-
if (desiredNameComparison !== 0) {
|
|
1322
|
-
return desiredNameComparison;
|
|
1323
|
-
}
|
|
1324
|
-
return left[0].localeCompare(right[0]);
|
|
1325
|
-
});
|
|
1326
|
-
|
|
1327
|
-
for (const [signatureKey, seed] of sortedSeeds) {
|
|
1328
|
-
const name = createUniqueFieldName(seed.desiredName, registry.usedNames);
|
|
1329
|
-
registry.entriesByKey.set(signatureKey, {
|
|
1330
|
-
name,
|
|
1331
|
-
baseType: seed.baseType,
|
|
1332
|
-
nativeTypeAttribute: seed.nativeTypeAttribute,
|
|
1333
|
-
});
|
|
1334
|
-
registry.usedNames.add(name);
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
return registry;
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
function resolveNamedTypeName(
|
|
1341
|
-
registry: NamedTypeRegistry,
|
|
1342
|
-
resolution: {
|
|
1343
|
-
readonly pslType: string;
|
|
1344
|
-
readonly nativeType: string;
|
|
1345
|
-
readonly typeParams?: Record<string, unknown>;
|
|
1346
|
-
readonly nativeTypeAttribute?: PslNativeTypeAttribute;
|
|
1347
|
-
},
|
|
1348
|
-
): string {
|
|
1349
|
-
const key = createNamedTypeSignatureKey(resolution);
|
|
1350
|
-
const existing = registry.entriesByKey.get(key);
|
|
1351
|
-
if (existing) {
|
|
1352
|
-
return existing.name;
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
throw new InternalError(
|
|
1356
|
-
`Named type registry was not seeded for native type "${resolution.nativeType}"`,
|
|
1357
|
-
);
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
function createNamedTypeSignatureKey(resolution: {
|
|
1361
|
-
readonly pslType: string;
|
|
1362
|
-
readonly nativeType: string;
|
|
1363
|
-
readonly typeParams?: Record<string, unknown>;
|
|
1364
|
-
readonly nativeTypeAttribute?: PslNativeTypeAttribute;
|
|
1365
|
-
}): string {
|
|
1366
|
-
return JSON.stringify({
|
|
1367
|
-
baseType: resolution.pslType,
|
|
1368
|
-
nativeTypeAttribute: resolution.nativeTypeAttribute
|
|
1369
|
-
? {
|
|
1370
|
-
name: resolution.nativeTypeAttribute.name,
|
|
1371
|
-
args: resolution.nativeTypeAttribute.args ?? null,
|
|
1372
|
-
}
|
|
1373
|
-
: null,
|
|
1374
|
-
});
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
1205
|
function topologicalSort(
|
|
1378
1206
|
models: PslModel[],
|
|
1379
1207
|
tables: Record<string, SqlTableIR>,
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
PslNativeTypeAttribute,
|
|
3
|
-
PslTypeMap,
|
|
4
|
-
PslTypeResolution,
|
|
5
|
-
} from '@prisma-next/family-sql/psl-infer';
|
|
1
|
+
import type { PslTypeMap, PslTypeResolution } from '@prisma-next/family-sql/psl-infer';
|
|
6
2
|
|
|
7
3
|
const POSTGRES_TO_PSL: Record<string, string> = {
|
|
8
4
|
text: 'String',
|
|
@@ -14,51 +10,46 @@ const POSTGRES_TO_PSL: Record<string, string> = {
|
|
|
14
10
|
bigint: 'BigInt',
|
|
15
11
|
float8: 'Float',
|
|
16
12
|
'double precision': 'Float',
|
|
17
|
-
numeric: 'Decimal',
|
|
18
|
-
decimal: 'Decimal',
|
|
19
|
-
timestamptz: 'DateTime',
|
|
20
|
-
'timestamp with time zone': 'DateTime',
|
|
21
13
|
jsonb: 'Jsonb',
|
|
22
14
|
bytea: 'Bytes',
|
|
23
15
|
};
|
|
24
16
|
|
|
25
|
-
const PRESERVED_NATIVE_TYPES: Record<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
timestamp
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
17
|
+
const PRESERVED_NATIVE_TYPES: Record<string, string> = {
|
|
18
|
+
'character varying': 'VarChar',
|
|
19
|
+
character: 'Char',
|
|
20
|
+
char: 'Char',
|
|
21
|
+
varchar: 'VarChar',
|
|
22
|
+
uuid: 'Uuid',
|
|
23
|
+
inet: 'Inet',
|
|
24
|
+
int2: 'SmallInt',
|
|
25
|
+
smallint: 'SmallInt',
|
|
26
|
+
float4: 'Real',
|
|
27
|
+
real: 'Real',
|
|
28
|
+
numeric: 'Numeric',
|
|
29
|
+
decimal: 'Numeric',
|
|
30
|
+
timestamp: 'Timestamp',
|
|
31
|
+
'timestamp without time zone': 'Timestamp',
|
|
32
|
+
timestamptz: 'Timestamptz',
|
|
33
|
+
'timestamp with time zone': 'Timestamptz',
|
|
34
|
+
date: 'Date',
|
|
35
|
+
time: 'Time',
|
|
36
|
+
'time without time zone': 'Time',
|
|
37
|
+
timetz: 'Timetz',
|
|
38
|
+
'time with time zone': 'Timetz',
|
|
39
|
+
json: 'Json',
|
|
47
40
|
};
|
|
48
41
|
|
|
49
|
-
const PARAMETERIZED_NATIVE_TYPES: Record<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
time: { pslType: 'DateTime', attributeName: 'db.Time' },
|
|
61
|
-
timetz: { pslType: 'DateTime', attributeName: 'db.Timetz' },
|
|
42
|
+
const PARAMETERIZED_NATIVE_TYPES: Record<string, string> = {
|
|
43
|
+
'character varying': 'VarChar',
|
|
44
|
+
character: 'Char',
|
|
45
|
+
char: 'Char',
|
|
46
|
+
varchar: 'VarChar',
|
|
47
|
+
numeric: 'Numeric',
|
|
48
|
+
decimal: 'Numeric',
|
|
49
|
+
timestamp: 'Timestamp',
|
|
50
|
+
timestamptz: 'Timestamptz',
|
|
51
|
+
time: 'Time',
|
|
52
|
+
timetz: 'Timetz',
|
|
62
53
|
};
|
|
63
54
|
|
|
64
55
|
const PARAMETERIZED_TYPE_PATTERN = /^(.+?)\((.+)\)$/;
|
|
@@ -67,14 +58,6 @@ function getOwnMappingValue(map: Record<string, string>, key: string): string |
|
|
|
67
58
|
return Object.hasOwn(map, key) ? map[key] : undefined;
|
|
68
59
|
}
|
|
69
60
|
|
|
70
|
-
function getOwnRecordValue<T>(map: Record<string, T>, key: string): T | undefined {
|
|
71
|
-
return Object.hasOwn(map, key) ? map[key] : undefined;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function createNativeTypeAttribute(name: string, args?: readonly string[]): PslNativeTypeAttribute {
|
|
75
|
-
return args && args.length > 0 ? { name, args } : { name };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
61
|
function splitTypeParameterList(params: string): readonly string[] {
|
|
79
62
|
return params
|
|
80
63
|
.split(',')
|
|
@@ -86,39 +69,34 @@ export function createPostgresTypeMap(enumTypeNames?: ReadonlySet<string>): PslT
|
|
|
86
69
|
return {
|
|
87
70
|
resolve(nativeType: string): PslTypeResolution {
|
|
88
71
|
if (enumTypeNames?.has(nativeType)) {
|
|
89
|
-
return { pslType: nativeType, nativeType };
|
|
72
|
+
return { pslType: { name: nativeType }, nativeType };
|
|
90
73
|
}
|
|
91
74
|
|
|
92
75
|
const paramMatch = nativeType.match(PARAMETERIZED_TYPE_PATTERN);
|
|
93
76
|
if (paramMatch) {
|
|
94
77
|
const [, baseType = nativeType, params = ''] = paramMatch;
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
78
|
+
const typeName = getOwnMappingValue(PARAMETERIZED_NATIVE_TYPES, baseType);
|
|
79
|
+
if (typeName) {
|
|
97
80
|
return {
|
|
98
|
-
pslType:
|
|
81
|
+
pslType: { name: typeName, args: splitTypeParameterList(params) },
|
|
99
82
|
nativeType,
|
|
100
83
|
typeParams: { baseType, params },
|
|
101
|
-
nativeTypeAttribute: createNativeTypeAttribute(
|
|
102
|
-
template.attributeName,
|
|
103
|
-
splitTypeParameterList(params),
|
|
104
|
-
),
|
|
105
84
|
};
|
|
106
85
|
}
|
|
107
86
|
}
|
|
108
87
|
|
|
109
|
-
const preservedType =
|
|
88
|
+
const preservedType = getOwnMappingValue(PRESERVED_NATIVE_TYPES, nativeType);
|
|
110
89
|
if (preservedType) {
|
|
111
90
|
return {
|
|
112
|
-
pslType: preservedType
|
|
91
|
+
pslType: { name: preservedType },
|
|
113
92
|
nativeType,
|
|
114
|
-
nativeTypeAttribute: createNativeTypeAttribute(preservedType.attributeName),
|
|
115
93
|
};
|
|
116
94
|
}
|
|
117
95
|
|
|
118
96
|
const pslType = getOwnMappingValue(POSTGRES_TO_PSL, nativeType);
|
|
119
97
|
if (pslType) {
|
|
120
98
|
return {
|
|
121
|
-
pslType,
|
|
99
|
+
pslType: { name: pslType },
|
|
122
100
|
nativeType,
|
|
123
101
|
};
|
|
124
102
|
}
|