@prisma-next/target-postgres 0.14.0-dev.53 → 0.14.0-dev.55
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/{authoring-ohGMgi8g.mjs → authoring-BBIGcFZM.mjs} +27 -4
- package/dist/authoring-BBIGcFZM.mjs.map +1 -0
- package/dist/contract-free.mjs +2 -2
- package/dist/{control-policy-CafkzSUC.mjs → control-policy-DievMCOV.mjs} +4 -4
- package/dist/{control-policy-CafkzSUC.mjs.map → control-policy-DievMCOV.mjs.map} +1 -1
- package/dist/control.mjs +174 -31
- package/dist/control.mjs.map +1 -1
- package/dist/{ddl-CZNFMoCp.mjs → ddl-D5j4JiAB.mjs} +2 -2
- package/dist/{ddl-CZNFMoCp.mjs.map → ddl-D5j4JiAB.mjs.map} +1 -1
- package/dist/{descriptor-meta-Cok-1QEK.mjs → descriptor-meta-C-tyS25s.mjs} +3 -3
- package/dist/{descriptor-meta-Cok-1QEK.mjs.map → descriptor-meta-C-tyS25s.mjs.map} +1 -1
- package/dist/{diff-database-schema-BivMht-X.mjs → diff-database-schema-ff3ioNtK.mjs} +7 -6
- package/dist/diff-database-schema-ff3ioNtK.mjs.map +1 -0
- package/dist/diff-database-schema.d.mts +1 -1
- package/dist/diff-database-schema.d.mts.map +1 -1
- package/dist/diff-database-schema.mjs +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.mjs +2 -2
- package/dist/{op-factory-call-zo3HqJiO.mjs → op-factory-call-DZWTTjKM.mjs} +3 -3
- package/dist/{op-factory-call-zo3HqJiO.mjs.map → op-factory-call-DZWTTjKM.mjs.map} +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-r4iLpxD7.mjs → planner-DWQYPxP8.mjs} +8 -8
- package/dist/{planner-r4iLpxD7.mjs.map → planner-DWQYPxP8.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-kVlK1Dts.mjs → planner-produced-postgres-migration-Ch1L8RiV.mjs} +2 -2
- package/dist/{planner-produced-postgres-migration-kVlK1Dts.mjs.map → planner-produced-postgres-migration-Ch1L8RiV.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-q58sWl7M.mjs → planner-sql-checks-D8Q5ck4o.mjs} +2 -2
- package/dist/{planner-sql-checks-q58sWl7M.mjs.map → planner-sql-checks-D8Q5ck4o.mjs.map} +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/planner.d.mts +1 -1
- package/dist/planner.mjs +2 -2
- package/dist/{postgres-contract-view-C5RSIHFm.mjs → postgres-contract-view-C-By7rOB.mjs} +3 -3
- package/dist/postgres-contract-view-C-By7rOB.mjs.map +1 -0
- package/dist/{postgres-database-schema-node-C9bTuMrd.d.mts → postgres-database-schema-node-UpzA0Ug5.d.mts} +15 -2
- package/dist/{postgres-database-schema-node-C9bTuMrd.d.mts.map → postgres-database-schema-node-UpzA0Ug5.d.mts.map} +1 -1
- package/dist/{postgres-migration-CiA7wpQD.mjs → postgres-migration-D3XACWKM.mjs} +3 -3
- package/dist/{postgres-migration-CiA7wpQD.mjs.map → postgres-migration-D3XACWKM.mjs.map} +1 -1
- package/dist/postgres-schema-9vFZLwGo.d.mts.map +1 -1
- package/dist/{postgres-schema-CsOBpCwV.mjs → postgres-schema-DcG72fcT.mjs} +3 -12
- package/dist/postgres-schema-DcG72fcT.mjs.map +1 -0
- package/dist/{postgres-table-schema-node-BgaSrxYN.mjs → postgres-table-schema-node-BZWWEo7B.mjs} +12 -1
- package/dist/postgres-table-schema-node-BZWWEo7B.mjs.map +1 -0
- package/dist/{resolve-ddl-schema-gmgUaHK3.mjs → resolve-ddl-schema-BOtCoeKV.mjs} +2 -2
- package/dist/{resolve-ddl-schema-gmgUaHK3.mjs.map → resolve-ddl-schema-BOtCoeKV.mjs.map} +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/schema-ir-annotations.mjs +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +2 -2
- package/package.json +20 -20
- package/src/core/authoring.ts +29 -3
- package/src/core/migrations/diff-database-schema.ts +1 -0
- package/src/core/postgres-contract-serializer.ts +2 -3
- package/src/core/postgres-schema.ts +0 -18
- package/src/core/psl-infer/infer-psl-contract.ts +288 -31
- package/src/core/psl-infer/postgres-type-map.ts +0 -29
- package/src/core/schema-ir/postgres-namespace-schema-node.ts +19 -0
- package/src/exports/types.ts +1 -0
- package/dist/authoring-ohGMgi8g.mjs.map +0 -1
- package/dist/diff-database-schema-BivMht-X.mjs.map +0 -1
- package/dist/postgres-contract-view-C5RSIHFm.mjs.map +0 -1
- package/dist/postgres-schema-CsOBpCwV.mjs.map +0 -1
- package/dist/postgres-table-schema-node-BgaSrxYN.mjs.map +0 -1
package/dist/control.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as PostgresNativeEnum } from "./postgres-native-enum-xdiqmBf_.mjs";
|
|
2
|
+
import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-C-tyS25s.mjs";
|
|
2
3
|
import { n as postgresDiffSubjectEntityKind, r as postgresDiffSubjectGranularity } from "./schema-node-kinds-ClScchhi.mjs";
|
|
3
|
-
import { a as PostgresDatabaseSchemaNode } from "./postgres-table-schema-node-
|
|
4
|
-
import { n as diffPostgresSchema, r as contractToPostgresDatabaseSchemaNode } from "./diff-database-schema-
|
|
4
|
+
import { a as PostgresDatabaseSchemaNode } from "./postgres-table-schema-node-BZWWEo7B.mjs";
|
|
5
|
+
import { n as diffPostgresSchema, r as contractToPostgresDatabaseSchemaNode } from "./diff-database-schema-ff3ioNtK.mjs";
|
|
5
6
|
import { r as renderDefaultLiteral } from "./planner-ddl-builders-B8Nn6nHN.mjs";
|
|
6
|
-
import { n as PostgresContractSerializer } from "./postgres-contract-view-
|
|
7
|
-
import { t as createPostgresMigrationPlanner } from "./planner-
|
|
8
|
-
import { UNBOUND_NAMESPACE_ID, coordinateKey, elementCoordinates } from "@prisma-next/framework-components/ir";
|
|
7
|
+
import { n as PostgresContractSerializer } from "./postgres-contract-view-C-By7rOB.mjs";
|
|
8
|
+
import { t as createPostgresMigrationPlanner } from "./planner-DWQYPxP8.mjs";
|
|
9
|
+
import { UNBOUND_NAMESPACE_ID, coordinateKey, elementCoordinates, isPlainRecord } from "@prisma-next/framework-components/ir";
|
|
9
10
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
10
11
|
import { buildNativeTypeExpander, runnerFailure, runnerSuccess } from "@prisma-next/family-sql/control";
|
|
11
12
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
@@ -14,7 +15,7 @@ import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
|
|
|
14
15
|
import { notOk, ok, okVoid } from "@prisma-next/utils/result";
|
|
15
16
|
import { SqlSchemaVerifierBase } from "@prisma-next/family-sql/ir";
|
|
16
17
|
import { SqlQueryError } from "@prisma-next/sql-errors";
|
|
17
|
-
import { buildChildRelationField, deriveRelationFieldName, inferRelations, mapDefault, parseRawDefault, toFieldName, toModelName, toNamedTypeName } from "@prisma-next/family-sql/psl-infer";
|
|
18
|
+
import { buildChildRelationField, deriveRelationFieldName, inferRelations, mapDefault, parseRawDefault, toEnumMemberName, toEnumName, toFieldName, toModelName, toNamedTypeName } from "@prisma-next/family-sql/psl-infer";
|
|
18
19
|
import { UNSPECIFIED_PSL_NAMESPACE_ID, makePslNamespace, makePslNamespaceEntries } from "@prisma-next/framework-components/psl-ast";
|
|
19
20
|
//#region src/core/migrations/runner.ts
|
|
20
21
|
const LOCK_DOMAIN = "prisma_next.contract.marker";
|
|
@@ -752,42 +753,118 @@ function resolveForeignKeys(tables, owners) {
|
|
|
752
753
|
function inferPostgresPslContract(tree, describedContracts) {
|
|
753
754
|
const namespaces = Object.values(tree.namespaces);
|
|
754
755
|
const owners = describedContractOwners(describedContracts ?? []);
|
|
755
|
-
const
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
756
|
+
const enumOwners = describedNativeEnumOwnersByTypeName(describedContracts ?? []);
|
|
757
|
+
const enumDefinitions = /* @__PURE__ */ new Map();
|
|
758
|
+
const packOwnedEnumTypesByNamespace = /* @__PURE__ */ new Map();
|
|
759
|
+
const enumNamespaceNames = /* @__PURE__ */ new Set();
|
|
760
|
+
for (const namespace of namespaces) {
|
|
761
|
+
const definitionsForNamespace = new Set(namespace.nativeEnums.map((e) => e.typeName));
|
|
762
|
+
for (const typeName of namespace.nativeEnumTypeNames) if (!definitionsForNamespace.has(typeName)) throw new Error(`contract infer: introspection reported native enum type "${typeName}" in schema "${namespace.schemaName}" without member values — the introspected tree's \`nativeEnumTypeNames\` and \`nativeEnums\` are out of sync (internal invariant).`);
|
|
763
|
+
for (const { typeName, values } of namespace.nativeEnums) {
|
|
764
|
+
const owner = enumOwners.get(coordinateKey({
|
|
765
|
+
namespaceId: namespace.schemaName,
|
|
766
|
+
entityKind: "native_enum",
|
|
767
|
+
entityName: typeName
|
|
768
|
+
}));
|
|
769
|
+
if (owner !== void 0) {
|
|
770
|
+
const owned = packOwnedEnumTypesByNamespace.get(namespace.schemaName) ?? /* @__PURE__ */ new Map();
|
|
771
|
+
owned.set(typeName, owner.spaceId);
|
|
772
|
+
owned.set(`${namespace.schemaName}.${typeName}`, owner.spaceId);
|
|
773
|
+
packOwnedEnumTypesByNamespace.set(namespace.schemaName, owned);
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
776
|
+
enumDefinitions.set(typeName, values);
|
|
777
|
+
enumNamespaceNames.add(namespace.schemaName);
|
|
778
|
+
}
|
|
759
779
|
}
|
|
760
780
|
const tables = {};
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
781
|
+
const tableNamespaceNames = /* @__PURE__ */ new Set();
|
|
782
|
+
for (const namespace of namespaces) {
|
|
783
|
+
const ownedEnumTypes = packOwnedEnumTypesByNamespace.get(namespace.schemaName);
|
|
784
|
+
for (const [tableName, table] of Object.entries(namespace.tables)) {
|
|
785
|
+
if (owners.has(coordinateKey({
|
|
786
|
+
namespaceId: namespace.schemaName,
|
|
787
|
+
entityKind: "table",
|
|
788
|
+
entityName: tableName
|
|
789
|
+
}))) continue;
|
|
790
|
+
if (tables[tableName] !== void 0) throw new Error(`contract infer: duplicate table name "${tableName}" across schemas is not yet supported (single-namespace PSL inference emits one flat bucket; multi-namespace \`namespace { … }\` output is a later slice).`);
|
|
791
|
+
if (ownedEnumTypes !== void 0) for (const column of Object.values(table.columns)) {
|
|
792
|
+
const owningSpaceId = ownedEnumTypes.get(column.nativeType);
|
|
793
|
+
if (owningSpaceId !== void 0) throw new Error(`contract infer: column "${tableName}"."${column.name}" is typed by native enum type "${column.nativeType}", which extension pack space "${owningSpaceId}" already describes. A cross-space enum-typed column has no authorable PSL form yet; describe the table in that pack's contract or retype the column before re-running contract infer.`);
|
|
794
|
+
}
|
|
795
|
+
tables[tableName] = new SqlTableIR(table);
|
|
796
|
+
tableNamespaceNames.add(namespace.schemaName);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
let wrapNamespaceName;
|
|
800
|
+
if (enumDefinitions.size > 0) {
|
|
801
|
+
const contentNamespaces = new Set([...enumNamespaceNames, ...tableNamespaceNames]);
|
|
802
|
+
if (contentNamespaces.size > 1) throw new Error(`contract infer: native enum adoption with content across multiple schemas is not yet supported (single-namespace PSL inference emits one \`namespace { … }\` block; multi-namespace output is a later slice). Schemas: ${[...contentNamespaces].sort().join(", ")}.`);
|
|
803
|
+
wrapNamespaceName = [...contentNamespaces][0];
|
|
769
804
|
}
|
|
770
805
|
const { tables: resolvedTables, extraRelationsByTable, crossSpaceFieldNamesByTable } = resolveForeignKeys(tables, owners);
|
|
771
|
-
|
|
772
|
-
|
|
806
|
+
const schemaIR = new SqlSchemaIR({ tables: resolvedTables });
|
|
807
|
+
const enumTypeNames = new Set(enumDefinitions.keys());
|
|
808
|
+
if (wrapNamespaceName !== void 0) for (const typeName of enumDefinitions.keys()) enumTypeNames.add(`${wrapNamespaceName}.${typeName}`);
|
|
809
|
+
const enumInfo = {
|
|
810
|
+
typeNames: enumTypeNames,
|
|
811
|
+
definitions: enumDefinitions
|
|
812
|
+
};
|
|
813
|
+
return buildPslDocumentAst(schemaIR, {
|
|
814
|
+
typeMap: createPostgresTypeMap(enumInfo.typeNames),
|
|
773
815
|
defaultMapping: createPostgresDefaultMapping(),
|
|
774
|
-
parseRawDefault
|
|
816
|
+
parseRawDefault,
|
|
817
|
+
...enumDefinitions.size > 0 ? { enumInfo } : {}
|
|
775
818
|
}, {
|
|
776
819
|
extraRelationsByTable,
|
|
777
820
|
crossSpaceFieldNamesByTable
|
|
778
|
-
});
|
|
821
|
+
}, wrapNamespaceName);
|
|
779
822
|
}
|
|
780
|
-
|
|
823
|
+
/**
|
|
824
|
+
* Native-enum ownership index for pack subtraction, keyed by TYPE NAME
|
|
825
|
+
* coordinate. A pack contract keys `entries.native_enum` by HANDLE name
|
|
826
|
+
* (`AalLevel`) while introspection sees the Postgres type name (`aal_level`);
|
|
827
|
+
* the entity's `typeName` field carries the mapping, so this walk indexes by
|
|
828
|
+
* it rather than reusing {@link describedContractOwners}' entries-key
|
|
829
|
+
* coordinates.
|
|
830
|
+
*
|
|
831
|
+
* Reads `entries.native_enum` directly: the kind map is carried
|
|
832
|
+
* non-enumerable on `PostgresSchema.entries`, so the generic
|
|
833
|
+
* `elementCoordinates` walk never yields it. Serialized pack contracts do
|
|
834
|
+
* not carry `native_enum` entries at all (`PostgresContractSerializer`
|
|
835
|
+
* strips them; only the derived `valueSet` survives), so this subtraction
|
|
836
|
+
* currently matches in-memory described contracts only.
|
|
837
|
+
*/
|
|
838
|
+
function describedNativeEnumOwnersByTypeName(describedContracts) {
|
|
839
|
+
const owners = /* @__PURE__ */ new Map();
|
|
840
|
+
for (const entry of describedContracts) for (const [namespaceId, ns] of Object.entries(entry.contract.storage.namespaces)) {
|
|
841
|
+
const kindMap = ns.entries["native_enum"];
|
|
842
|
+
if (!isPlainRecord(kindMap)) continue;
|
|
843
|
+
for (const entity of Object.values(kindMap)) {
|
|
844
|
+
if (!PostgresNativeEnum.is(entity)) continue;
|
|
845
|
+
owners.set(coordinateKey({
|
|
846
|
+
namespaceId,
|
|
847
|
+
entityKind: "native_enum",
|
|
848
|
+
entityName: entity.typeName
|
|
849
|
+
}), entry);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
return owners;
|
|
853
|
+
}
|
|
854
|
+
function buildPslDocumentAst(schemaIR, options, foreignKeyExtras, namespaceName) {
|
|
781
855
|
const { typeMap, defaultMapping, parseRawDefault: rawDefaultParser } = options;
|
|
782
856
|
const { extraRelationsByTable, crossSpaceFieldNamesByTable } = foreignKeyExtras;
|
|
783
857
|
const modelNames = buildTopLevelNameMap(Object.keys(schemaIR.tables), toModelName, "model", "table");
|
|
784
858
|
const modelNameMap = new Map([...modelNames].map(([tableName, result]) => [tableName, result.name]));
|
|
785
|
-
const
|
|
859
|
+
const { enumNameMap: bareEnumNameMap, enumBlocks } = buildNativeEnumBlocks(options.enumInfo?.definitions ?? /* @__PURE__ */ new Map(), modelNames);
|
|
860
|
+
const enumNameMap = new Map(bareEnumNameMap);
|
|
861
|
+
if (namespaceName !== void 0) for (const [typeName, pslName] of bareEnumNameMap) enumNameMap.set(`${namespaceName}.${typeName}`, pslName);
|
|
862
|
+
const reservedNamedTypeNames = createReservedNamedTypeNames(modelNames, enumNameMap);
|
|
786
863
|
const fieldNamesByTable = new Map([...crossSpaceFieldNamesByTable, ...buildFieldNamesByTable(schemaIR.tables)]);
|
|
787
864
|
const { relationsByTable } = inferRelations(schemaIR.tables, modelNameMap);
|
|
788
|
-
const namedTypes = seedNamedTypeRegistry(schemaIR, typeMap,
|
|
865
|
+
const namedTypes = seedNamedTypeRegistry(schemaIR, typeMap, enumNameMap, reservedNamedTypeNames);
|
|
789
866
|
const models = [];
|
|
790
|
-
for (const table of Object.values(schemaIR.tables)) models.push(buildModel(table, typeMap,
|
|
867
|
+
for (const table of Object.values(schemaIR.tables)) models.push(buildModel(table, typeMap, enumNameMap, fieldNamesByTable, namedTypes, defaultMapping, rawDefaultParser, [...relationsByTable.get(table.name) ?? [], ...extraRelationsByTable.get(table.name) ?? []]));
|
|
791
868
|
const sortedModels = topologicalSort(models, schemaIR.tables, modelNameMap);
|
|
792
869
|
const namedTypeEntries = [...namedTypes.entriesByKey.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
793
870
|
const types = namedTypeEntries.length > 0 ? {
|
|
@@ -800,14 +877,69 @@ function buildPslDocumentAst(schemaIR, options, foreignKeyExtras) {
|
|
|
800
877
|
sourceId: "<sql-schema-ir>",
|
|
801
878
|
namespaces: [makePslNamespace({
|
|
802
879
|
kind: "namespace",
|
|
803
|
-
name: UNSPECIFIED_PSL_NAMESPACE_ID,
|
|
804
|
-
entries: makePslNamespaceEntries(sortedModels, [],
|
|
880
|
+
name: namespaceName ?? UNSPECIFIED_PSL_NAMESPACE_ID,
|
|
881
|
+
entries: makePslNamespaceEntries(sortedModels, [], enumBlocks),
|
|
805
882
|
span: SYNTHETIC_SPAN
|
|
806
883
|
})],
|
|
807
884
|
...types ? { types } : {},
|
|
808
885
|
span: SYNTHETIC_SPAN
|
|
809
886
|
};
|
|
810
887
|
}
|
|
888
|
+
/**
|
|
889
|
+
* Builds one `native_enum` extension-block AST node per introspected enum
|
|
890
|
+
* definition. Block names go through the shared top-level transform
|
|
891
|
+
* (`toEnumName`, intra-enum collisions throw like model collisions) and are
|
|
892
|
+
* then reserved against the model names — an enum whose PSL name a model
|
|
893
|
+
* already claims gets a numeric suffix, with `@@map` carrying the real type
|
|
894
|
+
* name. Members print as explicit `member = "value"` pairs: the member name
|
|
895
|
+
* is the sanitized value (deduplicated within the block), the JSON-encoded
|
|
896
|
+
* value carries the truth verbatim.
|
|
897
|
+
*/
|
|
898
|
+
function buildNativeEnumBlocks(definitions, modelNames) {
|
|
899
|
+
const enumNames = buildTopLevelNameMap([...definitions.keys()].sort(), toEnumName, "enum", "enum type");
|
|
900
|
+
const usedTopLevelNames = new Set(PSL_SCALAR_TYPE_NAMES);
|
|
901
|
+
for (const result of modelNames.values()) usedTopLevelNames.add(result.name);
|
|
902
|
+
const enumNameMap = /* @__PURE__ */ new Map();
|
|
903
|
+
const enumBlocks = [];
|
|
904
|
+
for (const [typeName, result] of enumNames) {
|
|
905
|
+
const name = createUniqueFieldName(result.name, usedTopLevelNames);
|
|
906
|
+
usedTopLevelNames.add(name);
|
|
907
|
+
enumNameMap.set(typeName, name);
|
|
908
|
+
enumBlocks.push(buildNativeEnumBlock(name, typeName, definitions.get(typeName) ?? []));
|
|
909
|
+
}
|
|
910
|
+
return {
|
|
911
|
+
enumNameMap,
|
|
912
|
+
enumBlocks
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
function buildNativeEnumBlock(name, typeName, values) {
|
|
916
|
+
const usedMemberNames = /* @__PURE__ */ new Set();
|
|
917
|
+
const parameters = {};
|
|
918
|
+
for (const value of values) {
|
|
919
|
+
const memberName = createUniqueFieldName(toEnumMemberName(value), usedMemberNames);
|
|
920
|
+
usedMemberNames.add(memberName);
|
|
921
|
+
parameters[memberName] = {
|
|
922
|
+
kind: "value",
|
|
923
|
+
raw: JSON.stringify(value),
|
|
924
|
+
span: SYNTHETIC_SPAN
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
return {
|
|
928
|
+
kind: "native_enum",
|
|
929
|
+
name,
|
|
930
|
+
parameters,
|
|
931
|
+
blockAttributes: name === typeName ? [] : [{
|
|
932
|
+
name: "map",
|
|
933
|
+
args: [{
|
|
934
|
+
kind: "positional",
|
|
935
|
+
value: `"${escapePslString(typeName)}"`,
|
|
936
|
+
span: SYNTHETIC_SPAN
|
|
937
|
+
}],
|
|
938
|
+
span: SYNTHETIC_SPAN
|
|
939
|
+
}],
|
|
940
|
+
span: SYNTHETIC_SPAN
|
|
941
|
+
};
|
|
942
|
+
}
|
|
811
943
|
function buildModel(table, typeMap, enumNameMap, fieldNamesByTable, namedTypes, defaultMapping, rawDefaultParser, relationFields) {
|
|
812
944
|
const { name: modelName, map: mapName } = toModelName(table.name);
|
|
813
945
|
const fieldNameMap = fieldNamesByTable.get(table.name);
|
|
@@ -867,8 +999,17 @@ function buildScalarField(column, table, typeMap, enumNameMap, fieldNameMap, nam
|
|
|
867
999
|
};
|
|
868
1000
|
}
|
|
869
1001
|
let typeName = resolution.pslType;
|
|
1002
|
+
let typeConstructor;
|
|
870
1003
|
const enumPslName = enumNameMap.get(column.nativeType);
|
|
871
|
-
if (enumPslName)
|
|
1004
|
+
if (enumPslName) {
|
|
1005
|
+
typeName = enumPslName;
|
|
1006
|
+
typeConstructor = {
|
|
1007
|
+
kind: "typeConstructor",
|
|
1008
|
+
path: ["pg", "enum"],
|
|
1009
|
+
args: [positionalArg(enumPslName)],
|
|
1010
|
+
span: SYNTHETIC_SPAN
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
872
1013
|
if (resolution.nativeTypeAttribute && !enumPslName) typeName = resolveNamedTypeName(namedTypes, resolution);
|
|
873
1014
|
const attributes = [];
|
|
874
1015
|
const isId = isSinglePk && pkColumns.has(column.name);
|
|
@@ -889,6 +1030,7 @@ function buildScalarField(column, table, typeMap, enumNameMap, fieldNameMap, nam
|
|
|
889
1030
|
kind: "field",
|
|
890
1031
|
name: fieldName,
|
|
891
1032
|
typeName,
|
|
1033
|
+
...ifDefined("typeConstructor", typeConstructor),
|
|
892
1034
|
optional: column.nullable,
|
|
893
1035
|
list: column.many === true,
|
|
894
1036
|
attributes,
|
|
@@ -1038,9 +1180,10 @@ function buildTopLevelNameMap(sources, normalize, kind, sourceKind) {
|
|
|
1038
1180
|
}
|
|
1039
1181
|
return results;
|
|
1040
1182
|
}
|
|
1041
|
-
function createReservedNamedTypeNames(modelNames) {
|
|
1183
|
+
function createReservedNamedTypeNames(modelNames, enumNameMap) {
|
|
1042
1184
|
const reservedNames = new Set(PSL_SCALAR_TYPE_NAMES);
|
|
1043
1185
|
for (const result of modelNames.values()) reservedNames.add(result.name);
|
|
1186
|
+
for (const enumPslName of enumNameMap.values()) reservedNames.add(enumPslName);
|
|
1044
1187
|
return reservedNames;
|
|
1045
1188
|
}
|
|
1046
1189
|
function seedNamedTypeRegistry(schemaIR, typeMap, enumNameMap, reservedNames) {
|