@prisma-next/target-postgres 0.14.0-dev.8 → 0.14.0-dev.81
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-ChmUI_tC.mjs +674 -0
- package/dist/authoring-ChmUI_tC.mjs.map +1 -0
- package/dist/canonicalize-D1F4vUnP.d.mts +48 -0
- package/dist/canonicalize-D1F4vUnP.d.mts.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-DHCkwPKE.d.mts → codec-types-BiIWziRO.d.mts} +3 -2
- package/dist/codec-types-BiIWziRO.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/codecs-BemGS69L.mjs +927 -0
- package/dist/codecs-BemGS69L.mjs.map +1 -0
- package/dist/{codecs--0A5_4Bq.d.mts → codecs-Cm-nS4mQ.d.mts} +111 -4
- package/dist/codecs-Cm-nS4mQ.d.mts.map +1 -0
- package/dist/codecs.d.mts +2 -2
- package/dist/codecs.mjs +3 -757
- package/dist/codecs.mjs.map +1 -1
- package/dist/contract-free.d.mts +33 -3
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +23 -7
- package/dist/contract-free.mjs.map +1 -1
- package/dist/control-policy-BfQLCrha.mjs +1285 -0
- package/dist/control-policy-BfQLCrha.mjs.map +1 -0
- package/dist/control.d.mts +2 -2
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +866 -36
- package/dist/control.mjs.map +1 -1
- package/dist/data-transform-BOWpliq8.mjs.map +1 -1
- package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-DPzwBMhW.d.mts} +3 -3
- package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-DPzwBMhW.d.mts.map} +1 -1
- package/dist/data-transform.d.mts +1 -1
- package/dist/{ddl-QDyOSeLc.mjs → ddl-eBZav_MS.mjs} +128 -6
- package/dist/ddl-eBZav_MS.mjs.map +1 -0
- package/dist/ddl.d.mts +3 -2
- package/dist/ddl.mjs +2 -2
- package/dist/default-normalizer.d.mts +1 -1
- package/dist/default-normalizer.d.mts.map +1 -1
- package/dist/default-normalizer.mjs +247 -1
- package/dist/default-normalizer.mjs.map +1 -0
- package/dist/descriptor-meta-DAwRBZpA.mjs +23 -0
- package/dist/descriptor-meta-DAwRBZpA.mjs.map +1 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
- package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
- package/dist/diff-database-schema-jsEOfSYT.mjs +305 -0
- package/dist/diff-database-schema-jsEOfSYT.mjs.map +1 -0
- package/dist/diff-database-schema.d.mts +46 -0
- package/dist/diff-database-schema.d.mts.map +1 -0
- package/dist/diff-database-schema.mjs +2 -0
- package/dist/errors-DO-w0EUS.mjs +35 -0
- package/dist/errors-DO-w0EUS.mjs.map +1 -0
- package/dist/errors.d.mts +11 -9
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/issue-planner.d.mts +35 -11
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +2 -2
- package/dist/migration.d.mts +5 -5
- package/dist/migration.d.mts.map +1 -1
- package/dist/migration.mjs +4 -4
- package/dist/namespace-ids-xtp_ZY86.mjs +7 -0
- package/dist/namespace-ids-xtp_ZY86.mjs.map +1 -0
- package/dist/native-type-normalizer.mjs +37 -1
- package/dist/native-type-normalizer.mjs.map +1 -0
- package/dist/nodes-DJC5B8Id.mjs +192 -0
- package/dist/nodes-DJC5B8Id.mjs.map +1 -0
- package/dist/nodes-Dv5eCSq9.d.mts +170 -0
- package/dist/nodes-Dv5eCSq9.d.mts.map +1 -0
- package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-Bn9zDx4_.d.mts} +114 -15
- package/dist/op-factory-call-Bn9zDx4_.d.mts.map +1 -0
- package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-Dwsb1xzl.mjs} +469 -32
- package/dist/op-factory-call-Dwsb1xzl.mjs.map +1 -0
- package/dist/op-factory-call.d.mts +2 -2
- package/dist/op-factory-call.mjs +2 -2
- package/dist/pack.d.mts +321 -3
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/planner-ChCtpEGe.mjs +390 -0
- package/dist/planner-ChCtpEGe.mjs.map +1 -0
- package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-BKlmGDJl.mjs} +17 -28
- package/dist/planner-ddl-builders-BKlmGDJl.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts +4 -6
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +2 -2
- package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
- package/dist/planner-identity-values.d.mts +8 -2
- package/dist/planner-identity-values.d.mts.map +1 -1
- package/dist/planner-identity-values.mjs +2 -2
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-BEY1T0Xm.d.mts} +4 -4
- package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-BEY1T0Xm.d.mts.map} +1 -1
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-Bb16yHNX.mjs} +3 -3
- package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-Bb16yHNX.mjs.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-jqUUGyQR.mjs → planner-sql-checks-Cx0ATsPc.mjs} +5 -5
- package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-Cx0ATsPc.mjs.map} +1 -1
- package/dist/planner-sql-checks.d.mts +2 -2
- package/dist/planner-sql-checks.d.mts.map +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/{planner-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
- package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
- package/dist/planner-target-details.d.mts +1 -1
- package/dist/planner.d.mts +72 -17
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +3 -2
- package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-BiDhl5Ez.mjs} +45 -41
- package/dist/postgres-contract-view-BiDhl5Ez.mjs.map +1 -0
- package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
- package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
- package/dist/postgres-database-schema-node-CJv5bfbs.d.mts +262 -0
- package/dist/postgres-database-schema-node-CJv5bfbs.d.mts.map +1 -0
- package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-Cj5Tpj1a.mjs} +78 -45
- package/dist/postgres-migration-Cj5Tpj1a.mjs.map +1 -0
- package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-DbckK1su.d.mts} +58 -9
- package/dist/postgres-migration-DbckK1su.d.mts.map +1 -0
- package/dist/postgres-native-enum-BwVNf0Ku.mjs +45 -0
- package/dist/postgres-native-enum-BwVNf0Ku.mjs.map +1 -0
- package/dist/postgres-rls-policy--CSddvMR.d.mts +52 -0
- package/dist/postgres-rls-policy--CSddvMR.d.mts.map +1 -0
- package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs +190 -0
- package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs.map +1 -0
- package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-ChBj22nX.mjs} +200 -11
- package/dist/postgres-schema-ChBj22nX.mjs.map +1 -0
- package/dist/postgres-schema-DKq6s1P3.d.mts +269 -0
- package/dist/postgres-schema-DKq6s1P3.d.mts.map +1 -0
- package/dist/postgres-table-schema-node-D6LvInCe.mjs +216 -0
- package/dist/postgres-table-schema-node-D6LvInCe.mjs.map +1 -0
- package/dist/render-ops.d.mts +1 -1
- package/dist/{render-typescript-KMgosran.mjs → render-typescript-7yqILcwr.mjs} +45 -16
- package/dist/render-typescript-7yqILcwr.mjs.map +1 -0
- package/dist/render-typescript.mjs +1 -1
- package/dist/resolve-ddl-schema-BCSMHFwl.mjs +22 -0
- package/dist/resolve-ddl-schema-BCSMHFwl.mjs.map +1 -0
- package/dist/rls-canonicalize.d.mts +27 -0
- package/dist/rls-canonicalize.d.mts.map +1 -0
- package/dist/rls-canonicalize.mjs +2 -0
- package/dist/runtime.d.mts +6 -8
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +3 -3
- package/dist/runtime.mjs.map +1 -1
- package/dist/schema-ir-annotations.d.mts +15 -0
- package/dist/schema-ir-annotations.d.mts.map +1 -0
- package/dist/schema-ir-annotations.mjs +2 -0
- package/dist/{sql-utils-DcfMz4MQ.mjs → sql-utils-SU4FDvIV.mjs} +12 -3
- package/dist/{sql-utils-DcfMz4MQ.mjs.map → sql-utils-SU4FDvIV.mjs.map} +1 -1
- package/dist/sql-utils.d.mts +8 -1
- package/dist/sql-utils.d.mts.map +1 -1
- package/dist/sql-utils.mjs +2 -2
- package/dist/types.d.mts +4 -140
- package/dist/types.mjs +5 -2
- package/dist/wire-name-DbQ9-2RC.mjs +104 -0
- package/dist/wire-name-DbQ9-2RC.mjs.map +1 -0
- package/package.json +26 -20
- package/src/contract-free/checks.ts +153 -0
- package/src/contract-free/control-bootstrap.ts +20 -3
- package/src/contract-free/ddl.ts +98 -1
- package/src/core/authoring.ts +726 -2
- package/src/core/codec-helpers.ts +33 -7
- package/src/core/codec-ids.ts +1 -0
- package/src/core/codec-type-map.ts +2 -0
- package/src/core/codecs.ts +193 -12
- package/src/core/ddl/nodes.ts +185 -2
- package/src/core/default-normalizer.ts +122 -2
- package/src/core/descriptor-meta.ts +12 -1
- package/src/core/entity-kinds.ts +41 -0
- package/src/core/errors.ts +14 -12
- package/src/core/migrations/bound-schema.ts +10 -0
- package/src/core/migrations/column-ddl-rendering.ts +117 -0
- package/src/core/migrations/contract-to-postgres-database-schema-node.ts +189 -0
- package/src/core/migrations/control-policy.ts +217 -65
- package/src/core/migrations/diff-database-schema.ts +252 -0
- package/src/core/migrations/issue-planner.ts +817 -656
- package/src/core/migrations/op-factory-call.ts +383 -23
- package/src/core/migrations/operations/columns.ts +24 -12
- package/src/core/migrations/operations/constraints.ts +1 -1
- package/src/core/migrations/operations/data-transform.ts +6 -0
- package/src/core/migrations/operations/dependencies.ts +2 -1
- package/src/core/migrations/operations/native-enum-types.ts +62 -0
- package/src/core/migrations/operations/rls.ts +187 -0
- package/src/core/migrations/operations/shared.ts +0 -30
- package/src/core/migrations/planner-ddl-builders.ts +31 -59
- package/src/core/migrations/planner-identity-values.ts +1 -1
- package/src/core/migrations/planner-recipes.ts +31 -13
- package/src/core/migrations/planner-sql-checks.ts +1 -1
- package/src/core/migrations/planner-strategies.ts +248 -216
- package/src/core/migrations/planner-target-details.ts +3 -1
- package/src/core/migrations/planner.ts +357 -67
- package/src/core/migrations/postgres-migration.ts +118 -86
- package/src/core/migrations/render-typescript.ts +42 -15
- package/src/core/migrations/resolve-ddl-schema.ts +26 -0
- package/src/core/migrations/runner.ts +11 -16
- package/src/core/migrations/verify-postgres-namespaces.ts +46 -31
- package/src/core/namespace-ids.ts +3 -0
- package/src/core/postgres-contract-serializer.ts +46 -71
- package/src/core/postgres-contract-view.ts +48 -0
- package/src/core/postgres-native-enum.ts +61 -0
- package/src/core/postgres-rls-enablement.ts +34 -0
- package/src/core/postgres-rls-policy.ts +64 -0
- package/src/core/postgres-role.ts +59 -0
- package/src/core/postgres-schema-verifier.ts +10 -7
- package/src/core/postgres-schema.ts +85 -15
- package/src/core/postgres-validators.ts +34 -0
- package/src/core/psl-infer/infer-psl-contract.ts +1273 -0
- package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
- package/src/core/psl-infer/postgres-type-map.ts +128 -0
- package/src/core/rls/canonicalize.ts +65 -0
- package/src/core/rls/wire-name.ts +33 -0
- package/src/core/schema-ir/node-storage-coordinate.ts +26 -0
- package/src/core/schema-ir/postgres-database-schema-node.ts +61 -0
- package/src/core/schema-ir/postgres-namespace-schema-node.ts +70 -0
- package/src/core/schema-ir/postgres-native-enum-schema-node.ts +83 -0
- package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
- package/src/core/schema-ir/postgres-role-schema-node.ts +65 -0
- package/src/core/schema-ir/postgres-table-schema-node.ts +140 -0
- package/src/core/schema-ir/schema-node-kinds.ts +122 -0
- package/src/core/sql-utils.ts +15 -2
- package/src/exports/codecs.ts +3 -0
- package/src/exports/contract-free.ts +11 -1
- package/src/exports/control.ts +27 -33
- package/src/exports/ddl.ts +8 -0
- package/src/exports/diff-database-schema.ts +7 -0
- package/src/exports/issue-planner.ts +1 -1
- package/src/exports/migration.ts +1 -0
- package/src/exports/op-factory-call.ts +4 -0
- package/src/exports/planner-ddl-builders.ts +0 -2
- package/src/exports/planner-identity-values.ts +4 -1
- package/src/exports/planner.ts +1 -0
- package/src/exports/rls-canonicalize.ts +12 -0
- package/src/exports/runtime.ts +1 -0
- package/src/exports/schema-ir-annotations.ts +1 -0
- package/src/exports/sql-utils.ts +1 -0
- package/src/exports/types.ts +37 -0
- package/dist/codec-ids-BvytN2P8.mjs.map +0 -1
- package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
- package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
- package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
- package/dist/ddl-QDyOSeLc.mjs.map +0 -1
- package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
- package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
- package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
- package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
- package/dist/errors-CUk87ByX.mjs +0 -33
- package/dist/errors-CUk87ByX.mjs.map +0 -1
- package/dist/issue-planner-DL6g3CmE.mjs +0 -824
- package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
- package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
- package/dist/native-type-normalizer-Bc9XJzWC.mjs.map +0 -1
- package/dist/nodes-Bbhs2rwj.mjs +0 -76
- package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
- package/dist/nodes-pLeLgdis.d.mts +0 -67
- package/dist/nodes-pLeLgdis.d.mts.map +0 -1
- package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
- package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
- package/dist/planner-Bs_baQax.mjs +0 -324
- package/dist/planner-Bs_baQax.mjs.map +0 -1
- package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
- package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
- package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
- package/dist/postgres-migration-B5jKrXv3.mjs.map +0 -1
- package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
- package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
- package/dist/render-typescript-KMgosran.mjs.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/src/core/postgres-enum-type-schema.ts +0 -17
|
@@ -1,24 +1,46 @@
|
|
|
1
|
+
import type { Contract } from '@prisma-next/contract/types';
|
|
1
2
|
import {
|
|
2
3
|
freezeNode,
|
|
3
4
|
hydrateNamespaceEntities,
|
|
4
|
-
NamespaceBase,
|
|
5
5
|
UNBOUND_NAMESPACE_ID,
|
|
6
6
|
} from '@prisma-next/framework-components/ir';
|
|
7
7
|
import { composeSqlEntityKinds } from '@prisma-next/sql-contract/entity-kinds';
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
import {
|
|
9
|
+
SqlNamespaceBase,
|
|
10
|
+
type SqlNamespaceEntries,
|
|
11
|
+
type SqlNamespaceInput,
|
|
12
|
+
type SqlStorage,
|
|
13
|
+
type StorageTable,
|
|
14
|
+
type StorageValueSet,
|
|
14
15
|
} from '@prisma-next/sql-contract/types';
|
|
16
|
+
|
|
15
17
|
import { type CfExpr, cfExpr } from '@prisma-next/sql-relational-core/contract-free';
|
|
18
|
+
import { invariant } from '@prisma-next/utils/assertions';
|
|
16
19
|
import { blindCast } from '@prisma-next/utils/casts';
|
|
17
20
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
18
21
|
import { PostgresTableSource } from './ast/table-source';
|
|
19
22
|
import { PG_TEXT_CODEC_ID } from './codec-ids';
|
|
23
|
+
import {
|
|
24
|
+
nativeEnumEntityKind,
|
|
25
|
+
policyEntityKind,
|
|
26
|
+
rlsEnablementEntityKind,
|
|
27
|
+
roleEntityKind,
|
|
28
|
+
} from './entity-kinds';
|
|
29
|
+
import { PostgresNativeEnum } from './postgres-native-enum';
|
|
30
|
+
import type { PostgresRlsEnablement } from './postgres-rls-enablement';
|
|
31
|
+
import type { PostgresRlsPolicy } from './postgres-rls-policy';
|
|
32
|
+
import type { PostgresRole } from './postgres-role';
|
|
20
33
|
import { escapeLiteral } from './sql-utils';
|
|
21
34
|
|
|
35
|
+
export type PostgresContract = Contract<SqlStorage> & { readonly target: 'postgres' };
|
|
36
|
+
|
|
37
|
+
export type PostgresNamespaceEntries = SqlNamespaceEntries & {
|
|
38
|
+
readonly policy?: Readonly<Record<string, PostgresRlsPolicy>>;
|
|
39
|
+
readonly role?: Readonly<Record<string, PostgresRole>>;
|
|
40
|
+
readonly rls?: Readonly<Record<string, PostgresRlsEnablement>>;
|
|
41
|
+
readonly native_enum?: Readonly<Record<string, PostgresNativeEnum>>;
|
|
42
|
+
};
|
|
43
|
+
|
|
22
44
|
export interface PostgresSchemaInput {
|
|
23
45
|
readonly id: string;
|
|
24
46
|
readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
@@ -38,7 +60,7 @@ export interface PostgresSchemaInput {
|
|
|
38
60
|
* prefix entirely — call sites stay polymorphic and never branch on
|
|
39
61
|
* `id === UNBOUND_NAMESPACE_ID`.
|
|
40
62
|
*/
|
|
41
|
-
export class PostgresSchema extends
|
|
63
|
+
export class PostgresSchema extends SqlNamespaceBase {
|
|
42
64
|
/**
|
|
43
65
|
* Stable singleton reference for the late-bound slot. Materialised
|
|
44
66
|
* lazily below the singleton subclass declaration so the static
|
|
@@ -50,13 +72,42 @@ export class PostgresSchema extends NamespaceBase {
|
|
|
50
72
|
|
|
51
73
|
declare readonly kind: 'schema';
|
|
52
74
|
readonly id: string;
|
|
53
|
-
readonly entries:
|
|
75
|
+
readonly entries: PostgresNamespaceEntries;
|
|
54
76
|
|
|
55
77
|
constructor(input: PostgresSchemaInput) {
|
|
56
78
|
super();
|
|
57
79
|
this.id = input.id;
|
|
58
80
|
|
|
59
|
-
const dispatched = hydrateNamespaceEntities(
|
|
81
|
+
const dispatched = hydrateNamespaceEntities(
|
|
82
|
+
input.entries,
|
|
83
|
+
composeSqlEntityKinds([
|
|
84
|
+
policyEntityKind,
|
|
85
|
+
roleEntityKind,
|
|
86
|
+
rlsEnablementEntityKind,
|
|
87
|
+
nativeEnumEntityKind,
|
|
88
|
+
]),
|
|
89
|
+
'carry',
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// A native enum keys under its PHYSICAL type name in storage `entries`
|
|
93
|
+
// (ADR 221 coordinate `entityName`). The family/authoring layer keys every
|
|
94
|
+
// block by its author handle, so re-key the `native_enum` slot by each
|
|
95
|
+
// entity's `typeName` here — target-local Postgres code that already knows
|
|
96
|
+
// this entity kind. This runs at both authoring and hydration; a serialized
|
|
97
|
+
// contract's key already equals the `typeName`, so the re-key is idempotent.
|
|
98
|
+
const nativeEnumSlot = dispatched['native_enum'];
|
|
99
|
+
if (nativeEnumSlot !== undefined) {
|
|
100
|
+
const rekeyed: Record<string, unknown> = {};
|
|
101
|
+
for (const [handle, entity] of Object.entries(nativeEnumSlot)) {
|
|
102
|
+
const physicalName = PostgresNativeEnum.is(entity) ? entity.typeName : handle;
|
|
103
|
+
invariant(
|
|
104
|
+
!Object.hasOwn(rekeyed, physicalName),
|
|
105
|
+
`PostgresSchema "${input.id}": two native_enum entities resolve to the same physical type name "${physicalName}". Give them distinct @@map type names.`,
|
|
106
|
+
);
|
|
107
|
+
rekeyed[physicalName] = entity;
|
|
108
|
+
}
|
|
109
|
+
dispatched['native_enum'] = Object.freeze(rekeyed);
|
|
110
|
+
}
|
|
60
111
|
|
|
61
112
|
// Drop an empty valueSet so presence signals non-emptiness.
|
|
62
113
|
const valueSetRaw = dispatched['valueSet'];
|
|
@@ -65,11 +116,15 @@ export class PostgresSchema extends NamespaceBase {
|
|
|
65
116
|
? { ...dispatched, valueSet: undefined }
|
|
66
117
|
: dispatched;
|
|
67
118
|
|
|
119
|
+
const entriesInput: Record<string, Readonly<Record<string, unknown>> | undefined> = {
|
|
120
|
+
...withPresence,
|
|
121
|
+
};
|
|
122
|
+
|
|
68
123
|
this.entries = Object.freeze(
|
|
69
124
|
blindCast<
|
|
70
|
-
|
|
71
|
-
'composeSqlEntityKinds() supplies table→StorageTable
|
|
72
|
-
>(
|
|
125
|
+
PostgresNamespaceEntries,
|
|
126
|
+
'composeSqlEntityKinds([policyEntityKind, roleEntityKind, rlsEnablementEntityKind, nativeEnumEntityKind]) supplies table→StorageTable, valueSet→StorageValueSet, policy→PostgresRlsPolicy, role→PostgresRole, rls→PostgresRlsEnablement, native_enum→PostgresNativeEnum descriptors'
|
|
127
|
+
>(entriesInput),
|
|
73
128
|
);
|
|
74
129
|
Object.defineProperty(this, 'kind', {
|
|
75
130
|
value: 'schema',
|
|
@@ -88,6 +143,18 @@ export class PostgresSchema extends NamespaceBase {
|
|
|
88
143
|
return this.entries.valueSet;
|
|
89
144
|
}
|
|
90
145
|
|
|
146
|
+
get policy(): Readonly<Record<string, PostgresRlsPolicy>> {
|
|
147
|
+
return this.entries.policy ?? Object.freeze({});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
get role(): Readonly<Record<string, PostgresRole>> {
|
|
151
|
+
return this.entries.role ?? Object.freeze({});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
get rls(): Readonly<Record<string, PostgresRlsEnablement>> {
|
|
155
|
+
return this.entries.rls ?? Object.freeze({});
|
|
156
|
+
}
|
|
157
|
+
|
|
91
158
|
/**
|
|
92
159
|
* The bare schema qualifier as it would appear in a rendered SQL
|
|
93
160
|
* fragment (already quoted). The unbound-schema singleton overrides
|
|
@@ -245,9 +312,12 @@ export function isPostgresSchema(ns: unknown): ns is PostgresSchema {
|
|
|
245
312
|
* The factory has no per-call state — every named id deterministically
|
|
246
313
|
* maps to a distinct schema instance — so callers can pass it through
|
|
247
314
|
* by reference and trust the resulting `SqlStorage.namespaces` map to
|
|
248
|
-
* be value-stable for a given input set.
|
|
315
|
+
* be value-stable for a given input set. Native-enum column type names are
|
|
316
|
+
* schema-qualified earlier, at column construction, via the target's
|
|
317
|
+
* `authoring.qualifyColumnType` hook (`postgresQualifyColumnType`), so this
|
|
318
|
+
* factory just materialises the namespace from already-qualified entries.
|
|
249
319
|
*/
|
|
250
|
-
export function postgresCreateNamespace(input:
|
|
320
|
+
export function postgresCreateNamespace(input: SqlNamespaceInput): PostgresSchema {
|
|
251
321
|
const schemaInput: PostgresSchemaInput = {
|
|
252
322
|
id: input.id,
|
|
253
323
|
entries: {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type } from 'arktype';
|
|
2
|
+
|
|
3
|
+
export const PostgresRoleSchema = type({
|
|
4
|
+
kind: "'role'",
|
|
5
|
+
name: 'string',
|
|
6
|
+
namespaceId: 'string',
|
|
7
|
+
'control?': "'external'",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const PostgresRlsPolicySchema = type({
|
|
11
|
+
kind: "'policy'",
|
|
12
|
+
name: 'string',
|
|
13
|
+
prefix: 'string',
|
|
14
|
+
tableName: 'string',
|
|
15
|
+
namespaceId: 'string',
|
|
16
|
+
operation: "'select' | 'insert' | 'update' | 'delete' | 'all'",
|
|
17
|
+
roles: type.string.array().readonly(),
|
|
18
|
+
'using?': 'string',
|
|
19
|
+
'withCheck?': 'string',
|
|
20
|
+
permissive: 'boolean',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const PostgresRlsEnablementSchema = type({
|
|
24
|
+
kind: "'rls'",
|
|
25
|
+
tableName: 'string',
|
|
26
|
+
namespaceId: 'string',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const PostgresNativeEnumSchema = type({
|
|
30
|
+
kind: "'postgres-enum'",
|
|
31
|
+
typeName: 'string',
|
|
32
|
+
members: type.string.array().readonly(),
|
|
33
|
+
'control?': "'managed' | 'tolerated' | 'external' | 'observed'",
|
|
34
|
+
});
|