@prisma-next/target-postgres 0.14.0-dev.44 → 0.14.0-dev.46
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-DzHOdWTl.mjs +364 -0
- package/dist/authoring-DzHOdWTl.mjs.map +1 -0
- package/dist/{codec-ids-CnXu9Qy3.d.mts → codec-ids-BzrFF-I4.d.mts} +3 -2
- package/dist/codec-ids-BzrFF-I4.d.mts.map +1 -0
- package/dist/{codec-ids-BvytN2P8.mjs → codec-ids-C_-Hj6bL.mjs} +3 -2
- package/dist/codec-ids-C_-Hj6bL.mjs.map +1 -0
- package/dist/codec-ids.d.mts +2 -2
- package/dist/codec-ids.mjs +2 -2
- package/dist/{codec-types-CueCoGD0.d.mts → codec-types-BDVmvKAW.d.mts} +3 -2
- package/dist/codec-types-BDVmvKAW.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-Ca8upop6.d.mts → codecs-Dk2sxGLv.d.mts} +66 -4
- package/dist/codecs-Dk2sxGLv.d.mts.map +1 -0
- package/dist/codecs.d.mts +1 -1
- package/dist/codecs.mjs +83 -1
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.mjs +3 -3
- package/dist/control.d.mts +1 -1
- package/dist/control.mjs +138 -13
- package/dist/control.mjs.map +1 -1
- package/dist/{data-transform-qKy1U5V9.d.mts → data-transform-DPzwBMhW.d.mts} +2 -2
- package/dist/{data-transform-qKy1U5V9.d.mts.map → data-transform-DPzwBMhW.d.mts.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/{ddl-BmLIe1z_.mjs → ddl-ujxH2A7r.mjs} +3 -3
- package/dist/{ddl-BmLIe1z_.mjs.map → ddl-ujxH2A7r.mjs.map} +1 -1
- package/dist/{descriptor-meta-tjatyhtZ.mjs → descriptor-meta-CuGDsrG4.mjs} +5 -4
- package/dist/descriptor-meta-CuGDsrG4.mjs.map +1 -0
- package/dist/{issue-planner-DbFvaAgu.mjs → issue-planner-Cbh-xTEr.mjs} +6 -6
- package/dist/{issue-planner-DbFvaAgu.mjs.map → issue-planner-Cbh-xTEr.mjs.map} +1 -1
- package/dist/issue-planner.d.mts +2 -2
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +3 -3
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +2 -2
- package/dist/namespace-ids-xtp_ZY86.mjs +7 -0
- package/dist/namespace-ids-xtp_ZY86.mjs.map +1 -0
- package/dist/{op-factory-call-t65c4jyY.mjs → op-factory-call-BuoGT5UI.mjs} +6 -5
- package/dist/op-factory-call-BuoGT5UI.mjs.map +1 -0
- package/dist/{op-factory-call-CJWUxyUW.d.mts → op-factory-call-Caqus-Qg.d.mts} +2 -2
- package/dist/{op-factory-call-CJWUxyUW.d.mts.map → op-factory-call-Caqus-Qg.d.mts.map} +1 -1
- package/dist/op-factory-call.d.mts +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.d.mts +43 -3
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-CG2pLHk-.mjs → planner-CMXuFrQB.mjs} +10 -9
- package/dist/planner-CMXuFrQB.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +1 -1
- package/dist/planner-identity-values.d.mts +1 -1
- package/dist/{planner-produced-postgres-migration-BolD0Mvc.mjs → planner-produced-postgres-migration-CikV-edi.mjs} +2 -2
- package/dist/{planner-produced-postgres-migration-BolD0Mvc.mjs.map → planner-produced-postgres-migration-CikV-edi.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-Cz9--XOT.d.mts → planner-produced-postgres-migration-CtJi4sgS.d.mts} +2 -2
- package/dist/{planner-produced-postgres-migration-Cz9--XOT.d.mts.map → planner-produced-postgres-migration-CtJi4sgS.d.mts.map} +1 -1
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-DE9c4519.mjs → planner-sql-checks-Cze3vMfe.mjs} +2 -2
- package/dist/{planner-sql-checks-DE9c4519.mjs.map → planner-sql-checks-Cze3vMfe.mjs.map} +1 -1
- package/dist/planner-sql-checks.d.mts +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/planner.d.mts +3 -3
- package/dist/planner.mjs +1 -1
- package/dist/{postgres-contract-view-BegduLr6.mjs → postgres-contract-view-V3rGJCoe.mjs} +23 -14
- package/dist/postgres-contract-view-V3rGJCoe.mjs.map +1 -0
- package/dist/{postgres-migration-BfMmK6tv.mjs → postgres-migration-CZApTUCK.mjs} +3 -3
- package/dist/{postgres-migration-BfMmK6tv.mjs.map → postgres-migration-CZApTUCK.mjs.map} +1 -1
- package/dist/{postgres-migration-D7kNVWVG.d.mts → postgres-migration-CfyKDT7b.d.mts} +4 -4
- package/dist/{postgres-migration-D7kNVWVG.d.mts.map → postgres-migration-CfyKDT7b.d.mts.map} +1 -1
- package/dist/postgres-native-enum-xdiqmBf_.mjs +41 -0
- package/dist/postgres-native-enum-xdiqmBf_.mjs.map +1 -0
- package/dist/{postgres-schema-BLIHBEfX.mjs → postgres-schema-CajYAwny.mjs} +32 -7
- package/dist/postgres-schema-CajYAwny.mjs.map +1 -0
- package/dist/{postgres-schema-BywoeKlt.d.mts → postgres-schema-DqnhQRvR.d.mts} +40 -3
- package/dist/postgres-schema-DqnhQRvR.d.mts.map +1 -0
- package/dist/{postgres-table-schema-node-1nNc8XDT.mjs → postgres-table-schema-node-Clei_xel.mjs} +2 -2
- package/dist/{postgres-table-schema-node-1nNc8XDT.mjs.map → postgres-table-schema-node-Clei_xel.mjs.map} +1 -1
- package/dist/{resolve-ddl-schema-CL1RR1mx.mjs → resolve-ddl-schema-Bv1ZvjX8.mjs} +8 -6
- package/dist/resolve-ddl-schema-Bv1ZvjX8.mjs.map +1 -0
- package/dist/runtime.d.mts +9 -0
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/schema-ir-annotations.d.mts +4 -3
- package/dist/schema-ir-annotations.d.mts.map +1 -1
- package/dist/schema-ir-annotations.mjs +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs +2 -2
- package/package.json +20 -20
- package/src/core/authoring.ts +173 -2
- package/src/core/codec-ids.ts +1 -0
- package/src/core/codec-type-map.ts +2 -0
- package/src/core/codecs.ts +106 -0
- package/src/core/descriptor-meta.ts +2 -1
- package/src/core/entity-kinds.ts +15 -1
- package/src/core/migrations/operations/dependencies.ts +2 -1
- package/src/core/migrations/resolve-ddl-schema.ts +6 -4
- package/src/core/migrations/verify-postgres-namespaces.ts +2 -1
- package/src/core/namespace-ids.ts +3 -0
- package/src/core/postgres-contract-serializer.ts +27 -21
- package/src/core/postgres-native-enum.ts +51 -0
- package/src/core/postgres-schema.ts +28 -4
- package/src/core/postgres-validators.ts +7 -0
- package/src/core/psl-infer/infer-psl-contract.ts +246 -7
- package/src/exports/control.ts +2 -2
- package/dist/authoring-BX1WHIdN.mjs +0 -220
- package/dist/authoring-BX1WHIdN.mjs.map +0 -1
- package/dist/codec-ids-BvytN2P8.mjs.map +0 -1
- package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
- package/dist/codec-types-CueCoGD0.d.mts.map +0 -1
- package/dist/codecs-Ca8upop6.d.mts.map +0 -1
- package/dist/descriptor-meta-tjatyhtZ.mjs.map +0 -1
- package/dist/op-factory-call-t65c4jyY.mjs.map +0 -1
- package/dist/planner-CG2pLHk-.mjs.map +0 -1
- package/dist/postgres-contract-view-BegduLr6.mjs.map +0 -1
- package/dist/postgres-schema-BLIHBEfX.mjs.map +0 -1
- package/dist/postgres-schema-BywoeKlt.d.mts.map +0 -1
- package/dist/resolve-ddl-schema-CL1RR1mx.mjs.map +0 -1
- package/src/core/postgres-enum-type-schema.ts +0 -17
package/dist/control.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-
|
|
2
|
-
import { a as PostgresDatabaseSchemaNode } from "./postgres-table-schema-node-
|
|
3
|
-
import { i as contractToPostgresDatabaseSchemaNode, n as diffPostgresDatabaseSchema, r as verifyPostgresDatabaseSchema, t as createPostgresMigrationPlanner } from "./planner-
|
|
1
|
+
import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-CuGDsrG4.mjs";
|
|
2
|
+
import { a as PostgresDatabaseSchemaNode } from "./postgres-table-schema-node-Clei_xel.mjs";
|
|
3
|
+
import { i as contractToPostgresDatabaseSchemaNode, n as diffPostgresDatabaseSchema, r as verifyPostgresDatabaseSchema, t as createPostgresMigrationPlanner } from "./planner-CMXuFrQB.mjs";
|
|
4
4
|
import { r as renderDefaultLiteral } from "./planner-ddl-builders-B8Nn6nHN.mjs";
|
|
5
|
-
import { n as PostgresContractSerializer } from "./postgres-contract-view-
|
|
5
|
+
import { n as PostgresContractSerializer } from "./postgres-contract-view-V3rGJCoe.mjs";
|
|
6
|
+
import { UNBOUND_NAMESPACE_ID, coordinateKey, elementCoordinates } from "@prisma-next/framework-components/ir";
|
|
6
7
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
7
8
|
import { extractCodecControlHooks, runnerFailure, runnerSuccess } from "@prisma-next/family-sql/control";
|
|
8
9
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
9
|
-
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
10
10
|
import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
|
|
11
11
|
import { notOk, ok, okVoid } from "@prisma-next/utils/result";
|
|
12
12
|
import { SqlSchemaVerifierBase } from "@prisma-next/family-sql/ir";
|
|
13
13
|
import { SqlQueryError } from "@prisma-next/sql-errors";
|
|
14
|
-
import { inferRelations, mapDefault, parseRawDefault, toFieldName, toModelName, toNamedTypeName } from "@prisma-next/family-sql/psl-infer";
|
|
14
|
+
import { buildChildRelationField, deriveRelationFieldName, inferRelations, mapDefault, parseRawDefault, toFieldName, toModelName, toNamedTypeName } from "@prisma-next/family-sql/psl-infer";
|
|
15
15
|
import { UNSPECIFIED_PSL_NAMESPACE_ID, makePslNamespace, makePslNamespaceEntries } from "@prisma-next/framework-components/psl-ast";
|
|
16
16
|
//#region src/core/migrations/runner.ts
|
|
17
17
|
const LOCK_DOMAIN = "prisma_next.contract.marker";
|
|
@@ -621,6 +621,108 @@ const PSL_SCALAR_TYPE_NAMES = new Set([
|
|
|
621
621
|
"Bytes"
|
|
622
622
|
]);
|
|
623
623
|
/**
|
|
624
|
+
* Coordinates every element a set of already-assembled contracts declare,
|
|
625
|
+
* mapped to the {@link SqlDescribedContractSpace} that owns it and keyed by
|
|
626
|
+
* the shared {@link coordinateKey} helper. `contract infer` uses this to omit
|
|
627
|
+
* database elements a stack extension pack's contract space already
|
|
628
|
+
* describes — reusing the same coordinate walk the contract-space aggregate
|
|
629
|
+
* and cross-space collision check use (`elementCoordinates`), rather than a
|
|
630
|
+
* bespoke per-entity-kind membership test — and, for a foreign key whose
|
|
631
|
+
* referenced table an entry owns, to resolve the qualified cross-space
|
|
632
|
+
* relation it describes.
|
|
633
|
+
*/
|
|
634
|
+
function describedContractOwners(describedContracts) {
|
|
635
|
+
const owners = /* @__PURE__ */ new Map();
|
|
636
|
+
for (const entry of describedContracts) for (const coordinate of elementCoordinates(entry.contract.storage)) owners.set(coordinateKey(coordinate), entry);
|
|
637
|
+
return owners;
|
|
638
|
+
}
|
|
639
|
+
function resolveCrossSpaceTarget(owner, namespaceId, tableName) {
|
|
640
|
+
const domainNamespace = owner.contract.domain.namespaces[namespaceId];
|
|
641
|
+
if (domainNamespace === void 0) return;
|
|
642
|
+
for (const [modelName, model] of Object.entries(domainNamespace.models)) {
|
|
643
|
+
const storage = blindCast(model.storage);
|
|
644
|
+
if (storage.namespaceId !== namespaceId || storage.table !== tableName) continue;
|
|
645
|
+
const fieldNamesByColumn = /* @__PURE__ */ new Map();
|
|
646
|
+
for (const [fieldName, fieldStorage] of Object.entries(storage.fields)) fieldNamesByColumn.set(fieldStorage.column, { fieldName });
|
|
647
|
+
return {
|
|
648
|
+
spaceId: owner.spaceId,
|
|
649
|
+
namespaceId,
|
|
650
|
+
modelName,
|
|
651
|
+
fieldNamesByColumn
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Classifies every foreign key on a surviving table into one of three cases.
|
|
657
|
+
* A foreign key that carries a `referencedSchema` is checked against the
|
|
658
|
+
* pack-owned coordinates first, so a pack-owned target wins even when a local
|
|
659
|
+
* table happens to share its bare name; only foreign keys with no owned
|
|
660
|
+
* coordinate fall through to the local/dangling distinction.
|
|
661
|
+
*
|
|
662
|
+
* - **Cross-space**: `referencedSchema` is set and a described contract owns
|
|
663
|
+
* the coordinate `(referencedSchema, 'table', referencedTable)`. The
|
|
664
|
+
* referenced table is absent from the tree (omitted because the pack
|
|
665
|
+
* describes it, or never introspected — `contract infer` walks a single
|
|
666
|
+
* namespace). Removed from `foreignKeys` (so `inferRelations` never falls
|
|
667
|
+
* back to a bare, unqualified table name for it) and replaced with a
|
|
668
|
+
* `RelationField` qualified with the owning pack's space id and namespace
|
|
669
|
+
* id. `owners` holds only pack-declared coordinates, so an app's own table
|
|
670
|
+
* (e.g. `public.users`) is never owned and cannot be captured here.
|
|
671
|
+
* - **Local**: not a pack-owned coordinate, and the referenced table survived
|
|
672
|
+
* introspection — left untouched, `inferRelations` handles it as before.
|
|
673
|
+
* - **Dangling**: not a pack-owned coordinate, and the referenced table is
|
|
674
|
+
* neither in the tree nor owned by any described contract. Removed from
|
|
675
|
+
* `foreignKeys`, keeping the scalar column, rather than emitting a relation
|
|
676
|
+
* to a model that was never defined.
|
|
677
|
+
*
|
|
678
|
+
* A pack that owns the referenced coordinate but declares no domain model
|
|
679
|
+
* mapped to it is malformed; that case throws rather than degrading to a
|
|
680
|
+
* silent drop, which would contradict the dangling definition above.
|
|
681
|
+
*/
|
|
682
|
+
function resolveForeignKeys(tables, owners) {
|
|
683
|
+
const resultTables = {};
|
|
684
|
+
const extraRelationsByTable = /* @__PURE__ */ new Map();
|
|
685
|
+
const crossSpaceFieldNamesByTable = /* @__PURE__ */ new Map();
|
|
686
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
687
|
+
const keptForeignKeys = [];
|
|
688
|
+
for (const fk of table.foreignKeys) {
|
|
689
|
+
if (fk.referencedSchema !== void 0) {
|
|
690
|
+
const owner = owners.get(coordinateKey({
|
|
691
|
+
namespaceId: fk.referencedSchema,
|
|
692
|
+
entityKind: "table",
|
|
693
|
+
entityName: fk.referencedTable
|
|
694
|
+
}));
|
|
695
|
+
if (owner !== void 0) {
|
|
696
|
+
const target = resolveCrossSpaceTarget(owner, fk.referencedSchema, fk.referencedTable);
|
|
697
|
+
if (target === void 0) throw new Error(`contract infer: described contract space "${owner.spaceId}" owns storage coordinate "${fk.referencedSchema}.${fk.referencedTable}" but declares no domain model mapped to it. A pack that describes a table must also declare the domain model it maps to; this pack is malformed.`);
|
|
698
|
+
if (!crossSpaceFieldNamesByTable.has(fk.referencedTable)) crossSpaceFieldNamesByTable.set(fk.referencedTable, target.fieldNamesByColumn);
|
|
699
|
+
const fieldName = deriveRelationFieldName(fk.columns, fk.referencedTable);
|
|
700
|
+
const optional = fk.columns.some((columnName) => table.columns[columnName]?.nullable ?? false);
|
|
701
|
+
const relationField = {
|
|
702
|
+
...buildChildRelationField(fieldName, target.modelName, fk, optional),
|
|
703
|
+
typeNamespaceId: target.namespaceId,
|
|
704
|
+
typeContractSpaceId: target.spaceId
|
|
705
|
+
};
|
|
706
|
+
const existingRelations = extraRelationsByTable.get(tableName);
|
|
707
|
+
if (existingRelations) existingRelations.push(relationField);
|
|
708
|
+
else extraRelationsByTable.set(tableName, [relationField]);
|
|
709
|
+
continue;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
if (tables[fk.referencedTable] !== void 0) keptForeignKeys.push(fk);
|
|
713
|
+
}
|
|
714
|
+
resultTables[tableName] = keptForeignKeys.length === table.foreignKeys.length ? table : {
|
|
715
|
+
...table,
|
|
716
|
+
foreignKeys: keptForeignKeys
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
return {
|
|
720
|
+
tables: resultTables,
|
|
721
|
+
extraRelationsByTable,
|
|
722
|
+
crossSpaceFieldNamesByTable
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
624
726
|
* Infers a PSL AST (for `printPsl`) from an introspected Postgres schema tree.
|
|
625
727
|
*
|
|
626
728
|
* Target-owned inference: it walks the `PostgresDatabaseSchemaNode` tree and
|
|
@@ -633,9 +735,20 @@ const PSL_SCALAR_TYPE_NAMES = new Set([
|
|
|
633
735
|
* introspects a single live namespace) are gathered into the model set and
|
|
634
736
|
* emitted as one `UNSPECIFIED_PSL_NAMESPACE_ID` bucket. Top-level entities
|
|
635
737
|
* (policies/roles → PSL extension blocks) are a later slice.
|
|
738
|
+
*
|
|
739
|
+
* `describedContracts` — the stack's extension packs' already-assembled
|
|
740
|
+
* contracts, each paired with its space id — is consulted while gathering
|
|
741
|
+
* tables: a table whose coordinate `(schemaName, 'table', tableName)` one of
|
|
742
|
+
* those contracts already declares is omitted, before the duplicate-name
|
|
743
|
+
* check below and before relation inference, so it cannot spuriously
|
|
744
|
+
* collide with an app table and never contributes a bare relation field. A
|
|
745
|
+
* surviving table's foreign key into an omitted, pack-owned table is not
|
|
746
|
+
* dropped: {@link resolveForeignKeys} rewrites it into a relation qualified
|
|
747
|
+
* with the pack's space id (`<spaceId>:<namespaceId>.<Model>`) instead.
|
|
636
748
|
*/
|
|
637
|
-
function inferPostgresPslContract(tree) {
|
|
749
|
+
function inferPostgresPslContract(tree, describedContracts) {
|
|
638
750
|
const namespaces = Object.values(tree.namespaces);
|
|
751
|
+
const owners = describedContractOwners(describedContracts ?? []);
|
|
639
752
|
const enumTypeNames = [...new Set(namespaces.flatMap((ns) => ns.nativeEnumTypeNames))];
|
|
640
753
|
if (enumTypeNames.length > 0) {
|
|
641
754
|
const names = enumTypeNames.join(", ");
|
|
@@ -643,25 +756,35 @@ function inferPostgresPslContract(tree) {
|
|
|
643
756
|
}
|
|
644
757
|
const tables = {};
|
|
645
758
|
for (const namespace of namespaces) for (const [tableName, table] of Object.entries(namespace.tables)) {
|
|
759
|
+
if (owners.has(coordinateKey({
|
|
760
|
+
namespaceId: namespace.schemaName,
|
|
761
|
+
entityKind: "table",
|
|
762
|
+
entityName: tableName
|
|
763
|
+
}))) continue;
|
|
646
764
|
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).`);
|
|
647
765
|
tables[tableName] = table;
|
|
648
766
|
}
|
|
649
|
-
|
|
767
|
+
const { tables: resolvedTables, extraRelationsByTable, crossSpaceFieldNamesByTable } = resolveForeignKeys(tables, owners);
|
|
768
|
+
return buildPslDocumentAst({ tables: resolvedTables }, {
|
|
650
769
|
typeMap: createPostgresTypeMap(/* @__PURE__ */ new Set()),
|
|
651
770
|
defaultMapping: createPostgresDefaultMapping(),
|
|
652
771
|
parseRawDefault
|
|
772
|
+
}, {
|
|
773
|
+
extraRelationsByTable,
|
|
774
|
+
crossSpaceFieldNamesByTable
|
|
653
775
|
});
|
|
654
776
|
}
|
|
655
|
-
function buildPslDocumentAst(schemaIR, options) {
|
|
777
|
+
function buildPslDocumentAst(schemaIR, options, foreignKeyExtras) {
|
|
656
778
|
const { typeMap, defaultMapping, parseRawDefault: rawDefaultParser } = options;
|
|
779
|
+
const { extraRelationsByTable, crossSpaceFieldNamesByTable } = foreignKeyExtras;
|
|
657
780
|
const modelNames = buildTopLevelNameMap(Object.keys(schemaIR.tables), toModelName, "model", "table");
|
|
658
781
|
const modelNameMap = new Map([...modelNames].map(([tableName, result]) => [tableName, result.name]));
|
|
659
782
|
const reservedNamedTypeNames = createReservedNamedTypeNames(modelNames);
|
|
660
|
-
const fieldNamesByTable = buildFieldNamesByTable(schemaIR.tables);
|
|
783
|
+
const fieldNamesByTable = new Map([...crossSpaceFieldNamesByTable, ...buildFieldNamesByTable(schemaIR.tables)]);
|
|
661
784
|
const { relationsByTable } = inferRelations(schemaIR.tables, modelNameMap);
|
|
662
785
|
const namedTypes = seedNamedTypeRegistry(schemaIR, typeMap, /* @__PURE__ */ new Map(), reservedNamedTypeNames);
|
|
663
786
|
const models = [];
|
|
664
|
-
for (const table of Object.values(schemaIR.tables)) models.push(buildModel(table, typeMap, /* @__PURE__ */ new Map(), fieldNamesByTable, namedTypes, defaultMapping, rawDefaultParser, relationsByTable.get(table.name) ?? []));
|
|
787
|
+
for (const table of Object.values(schemaIR.tables)) models.push(buildModel(table, typeMap, /* @__PURE__ */ new Map(), fieldNamesByTable, namedTypes, defaultMapping, rawDefaultParser, [...relationsByTable.get(table.name) ?? [], ...extraRelationsByTable.get(table.name) ?? []]));
|
|
665
788
|
const sortedModels = topologicalSort(models, schemaIR.tables, modelNameMap);
|
|
666
789
|
const namedTypeEntries = [...namedTypes.entriesByKey.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
667
790
|
const types = namedTypeEntries.length > 0 ? {
|
|
@@ -786,6 +909,8 @@ function buildRelationField(rel, hostTableName, fieldNamesByTable, usedFieldName
|
|
|
786
909
|
kind: "field",
|
|
787
910
|
name: fieldName,
|
|
788
911
|
typeName: rel.typeName,
|
|
912
|
+
...ifDefined("typeNamespaceId", rel.typeNamespaceId),
|
|
913
|
+
...ifDefined("typeContractSpaceId", rel.typeContractSpaceId),
|
|
789
914
|
optional: rel.optional,
|
|
790
915
|
list: rel.list,
|
|
791
916
|
attributes: attrs,
|
|
@@ -1023,9 +1148,9 @@ const postgresTargetDescriptor = {
|
|
|
1023
1148
|
...postgresTargetDescriptorMeta,
|
|
1024
1149
|
contractSerializer: new PostgresContractSerializer(),
|
|
1025
1150
|
schemaVerifier: new PostgresSchemaVerifier(),
|
|
1026
|
-
inferPslContract(schema) {
|
|
1151
|
+
inferPslContract(schema, describedContracts) {
|
|
1027
1152
|
PostgresDatabaseSchemaNode.assert(schema);
|
|
1028
|
-
return inferPostgresPslContract(schema);
|
|
1153
|
+
return inferPostgresPslContract(schema, describedContracts);
|
|
1029
1154
|
},
|
|
1030
1155
|
diffDatabaseSchema(input) {
|
|
1031
1156
|
return diffPostgresDatabaseSchema({
|