@prisma-next/target-postgres 0.16.0-dev.3 → 0.16.0-dev.31
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/README.md +1 -1
- package/dist/{authoring-34L18kA1.mjs → authoring-DnO1B0N9.mjs} +29 -18
- package/dist/authoring-DnO1B0N9.mjs.map +1 -0
- package/dist/canonicalize-C7zKHw8m.mjs +59 -0
- package/dist/canonicalize-C7zKHw8m.mjs.map +1 -0
- package/dist/{canonicalize-D1F4vUnP.d.mts → canonicalize-CQlxSR4D.d.mts} +3 -18
- package/dist/canonicalize-CQlxSR4D.d.mts.map +1 -0
- package/dist/{codec-types-CQ07nOz-.d.mts → codec-types-DdoPc2dy.d.mts} +3 -2
- package/dist/codec-types-DdoPc2dy.d.mts.map +1 -0
- package/dist/codec-types.d.mts +1 -1
- package/dist/{codecs-G4DTY0F_.d.mts → codecs-CGE5dh94.d.mts} +7 -2
- package/dist/codecs-CGE5dh94.d.mts.map +1 -0
- package/dist/{codecs-TCsGgW-Y.mjs → codecs-Deand7sy.mjs} +84 -26
- package/dist/codecs-Deand7sy.mjs.map +1 -0
- package/dist/codecs.d.mts +2 -2
- package/dist/codecs.mjs +2 -2
- package/dist/contract-free.d.mts +1 -1
- package/dist/contract-free.d.mts.map +1 -1
- package/dist/contract-free.mjs +2 -2
- package/dist/{control-policy-CZKdMztu.mjs → control-policy-DEwdS3oK.mjs} +29 -29
- package/dist/control-policy-DEwdS3oK.mjs.map +1 -0
- package/dist/control.mjs +91 -239
- package/dist/control.mjs.map +1 -1
- package/dist/data-transform-BOWpliq8.mjs.map +1 -1
- package/dist/{ddl-DHXKzQ99.mjs → ddl-BQC6u-L9.mjs} +28 -4
- package/dist/{ddl-DHXKzQ99.mjs.map → ddl-BQC6u-L9.mjs.map} +1 -1
- package/dist/ddl.d.mts +3 -3
- package/dist/ddl.mjs +2 -2
- package/dist/{descriptor-meta-qubYaxQA.mjs → descriptor-meta-DGlJurgA.mjs} +4 -4
- package/dist/{descriptor-meta-qubYaxQA.mjs.map → descriptor-meta-DGlJurgA.mjs.map} +1 -1
- package/dist/{diff-database-schema-C-hnJ5mr.mjs → diff-database-schema-qRPwuYBH.mjs} +37 -15
- package/dist/diff-database-schema-qRPwuYBH.mjs.map +1 -0
- package/dist/diff-database-schema.mjs +1 -1
- package/dist/{errors-ByDS0xJL.mjs → errors-DBSNx7EJ.mjs} +6 -2
- package/dist/errors-DBSNx7EJ.mjs.map +1 -0
- package/dist/errors.d.mts +4 -1
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +2 -2
- package/dist/issue-planner.d.mts +2 -2
- package/dist/issue-planner.d.mts.map +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.d.mts +2 -2
- package/dist/migration.mjs +2 -2
- package/dist/{nodes-DJC5B8Id.mjs → nodes-04EILM-z.mjs} +65 -2
- package/dist/nodes-04EILM-z.mjs.map +1 -0
- package/dist/{nodes-CQzM2hR0.d.mts → nodes-DjCsN-uv.d.mts} +69 -4
- package/dist/nodes-DjCsN-uv.d.mts.map +1 -0
- package/dist/{op-factory-call-DT7kdjVP.d.mts → op-factory-call-0TB5XNij.d.mts} +46 -8
- package/dist/op-factory-call-0TB5XNij.d.mts.map +1 -0
- package/dist/{op-factory-call-DuRj7WXX.mjs → op-factory-call-CIaPDDUc.mjs} +147 -64
- package/dist/op-factory-call-CIaPDDUc.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 +2 -2
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-DPGxFcXo.mjs → planner-BhnkIJX-.mjs} +121 -13
- package/dist/planner-BhnkIJX-.mjs.map +1 -0
- package/dist/{planner-ddl-builders-BKlmGDJl.mjs → planner-ddl-builders-CVo3L7Nd.mjs} +12 -7
- package/dist/planner-ddl-builders-CVo3L7Nd.mjs.map +1 -0
- package/dist/planner-ddl-builders.d.mts.map +1 -1
- package/dist/planner-ddl-builders.mjs +1 -1
- package/dist/{planner-produced-postgres-migration-CFDpqWWE.mjs → planner-produced-postgres-migration-BE3EJIRK.mjs} +9 -6
- package/dist/planner-produced-postgres-migration-BE3EJIRK.mjs.map +1 -0
- package/dist/{planner-produced-postgres-migration-C-dwGdb2.d.mts → planner-produced-postgres-migration-CRAHl6ak.d.mts} +3 -3
- package/dist/planner-produced-postgres-migration-CRAHl6ak.d.mts.map +1 -0
- package/dist/planner-produced-postgres-migration.d.mts +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-schema-lookup-CiVaAQP-.mjs → planner-schema-lookup-D3Y_OL-C.mjs} +3 -3
- package/dist/planner-schema-lookup-D3Y_OL-C.mjs.map +1 -0
- package/dist/planner-schema-lookup.mjs +1 -1
- package/dist/{planner-sql-checks-BuB877wH.mjs → planner-sql-checks-CmiQ6Nei.mjs} +3 -3
- package/dist/{planner-sql-checks-BuB877wH.mjs.map → planner-sql-checks-CmiQ6Nei.mjs.map} +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/planner.d.mts +27 -1
- package/dist/planner.d.mts.map +1 -1
- package/dist/planner.mjs +2 -2
- package/dist/{postgres-contract-view-DebHMqGR.mjs → postgres-contract-view-BeIEyZfD.mjs} +3 -3
- package/dist/{postgres-contract-view-DebHMqGR.mjs.map → postgres-contract-view-BeIEyZfD.mjs.map} +1 -1
- package/dist/{postgres-migration-C_OPFhIF.mjs → postgres-migration--BzvpA92.mjs} +9 -6
- package/dist/postgres-migration--BzvpA92.mjs.map +1 -0
- package/dist/{postgres-migration-DLIvzHjX.d.mts → postgres-migration-BXelnqHO.d.mts} +15 -10
- package/dist/postgres-migration-BXelnqHO.d.mts.map +1 -0
- package/dist/{postgres-schema-CewLYHB7.mjs → postgres-schema-CTplQZDK.mjs} +2 -2
- package/dist/{postgres-schema-CewLYHB7.mjs.map → postgres-schema-CTplQZDK.mjs.map} +1 -1
- package/dist/{render-ops-BREh1kHe.mjs → render-ops-TcY9XEkz.mjs} +7 -2
- package/dist/render-ops-TcY9XEkz.mjs.map +1 -0
- package/dist/render-ops.d.mts.map +1 -1
- package/dist/render-ops.mjs +1 -1
- package/dist/{render-typescript-7yqILcwr.mjs → render-typescript-Ta7_6CGf.mjs} +20 -8
- package/dist/render-typescript-Ta7_6CGf.mjs.map +1 -0
- package/dist/render-typescript.d.mts +2 -0
- package/dist/render-typescript.d.mts.map +1 -1
- package/dist/render-typescript.mjs +1 -1
- package/dist/{resolve-ddl-schema-D0wi_P9Q.mjs → resolve-ddl-schema-BAsJEKW8.mjs} +2 -2
- package/dist/{resolve-ddl-schema-D0wi_P9Q.mjs.map → resolve-ddl-schema-BAsJEKW8.mjs.map} +1 -1
- package/dist/rls-canonicalize.d.mts +2 -26
- package/dist/rls-canonicalize.mjs +2 -2
- package/dist/runtime.mjs +1 -1
- package/dist/schema-ir-annotations.mjs +1 -1
- package/dist/{sql-utils-SU4FDvIV.mjs → sql-utils-B2lzkKfP.mjs} +22 -19
- package/dist/sql-utils-B2lzkKfP.mjs.map +1 -0
- package/dist/sql-utils.d.mts +4 -9
- package/dist/sql-utils.d.mts.map +1 -1
- package/dist/sql-utils.mjs +2 -2
- package/dist/types.mjs +1 -1
- package/package.json +20 -20
- package/src/contract-free/ddl.ts +47 -0
- package/src/core/authoring.ts +35 -26
- package/src/core/codec-helpers.ts +69 -16
- package/src/core/codec-type-map.ts +2 -0
- package/src/core/codecs.ts +29 -14
- package/src/core/ddl/nodes.ts +104 -0
- package/src/core/errors.ts +30 -0
- package/src/core/migrations/column-ddl-rendering.ts +2 -1
- package/src/core/migrations/contract-to-postgres-database-schema-node.ts +38 -14
- package/src/core/migrations/issue-planner.ts +40 -13
- package/src/core/migrations/op-factory-call.ts +189 -44
- package/src/core/migrations/operations/constraints.ts +3 -2
- package/src/core/migrations/operations/data-transform.ts +1 -1
- package/src/core/migrations/operations/indexes.ts +80 -32
- package/src/core/migrations/operations/rls.ts +4 -1
- package/src/core/migrations/planner-ddl-builders.ts +16 -6
- package/src/core/migrations/planner-produced-postgres-migration.ts +8 -1
- package/src/core/migrations/planner-schema-lookup.ts +2 -2
- package/src/core/migrations/planner.ts +163 -5
- package/src/core/migrations/postgres-migration.ts +26 -8
- package/src/core/migrations/render-ops.ts +4 -1
- package/src/core/migrations/render-typescript.ts +20 -8
- package/src/core/migrations/runner.ts +7 -3
- package/src/core/psl-infer/infer-psl-contract.ts +36 -185
- package/src/core/psl-infer/postgres-type-map.ts +43 -65
- package/src/core/rls/canonicalize.ts +4 -21
- package/src/core/sql-utils.ts +16 -27
- package/src/exports/codecs.ts +2 -0
- package/src/exports/ddl.ts +4 -0
- package/src/exports/errors.ts +1 -1
- package/src/exports/op-factory-call.ts +1 -0
- package/src/exports/rls-canonicalize.ts +0 -6
- package/src/exports/sql-utils.ts +0 -1
- package/dist/authoring-34L18kA1.mjs.map +0 -1
- package/dist/canonicalize-D1F4vUnP.d.mts.map +0 -1
- package/dist/codec-types-CQ07nOz-.d.mts.map +0 -1
- package/dist/codecs-G4DTY0F_.d.mts.map +0 -1
- package/dist/codecs-TCsGgW-Y.mjs.map +0 -1
- package/dist/control-policy-CZKdMztu.mjs.map +0 -1
- package/dist/diff-database-schema-C-hnJ5mr.mjs.map +0 -1
- package/dist/errors-ByDS0xJL.mjs.map +0 -1
- package/dist/nodes-CQzM2hR0.d.mts.map +0 -1
- package/dist/nodes-DJC5B8Id.mjs.map +0 -1
- package/dist/op-factory-call-DT7kdjVP.d.mts.map +0 -1
- package/dist/op-factory-call-DuRj7WXX.mjs.map +0 -1
- package/dist/planner-DPGxFcXo.mjs.map +0 -1
- package/dist/planner-ddl-builders-BKlmGDJl.mjs.map +0 -1
- package/dist/planner-produced-postgres-migration-C-dwGdb2.d.mts.map +0 -1
- package/dist/planner-produced-postgres-migration-CFDpqWWE.mjs.map +0 -1
- package/dist/planner-schema-lookup-CiVaAQP-.mjs.map +0 -1
- package/dist/postgres-migration-C_OPFhIF.mjs.map +0 -1
- package/dist/postgres-migration-DLIvzHjX.d.mts.map +0 -1
- package/dist/render-ops-BREh1kHe.mjs.map +0 -1
- package/dist/render-typescript-7yqILcwr.mjs.map +0 -1
- package/dist/rls-canonicalize.d.mts.map +0 -1
- package/dist/sql-utils-SU4FDvIV.mjs.map +0 -1
- package/dist/wire-name-DbQ9-2RC.mjs +0 -104
- package/dist/wire-name-DbQ9-2RC.mjs.map +0 -1
- package/src/core/rls/wire-name.ts +0 -33
package/README.md
CHANGED
|
@@ -107,7 +107,7 @@ import { defineContract } from '@prisma-next/sql-contract-ts/contract-builder';
|
|
|
107
107
|
export const contract = defineContract({
|
|
108
108
|
family: sqlFamily,
|
|
109
109
|
target: postgresPack,
|
|
110
|
-
|
|
110
|
+
extensions: { pgvector },
|
|
111
111
|
});
|
|
112
112
|
```
|
|
113
113
|
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { o as PG_ENUM_CODEC_ID } from "./codec-ids-D3G8K0YM.mjs";
|
|
2
|
+
import { n as postgresError } from "./errors-DBSNx7EJ.mjs";
|
|
2
3
|
import { t as PostgresNativeEnum } from "./postgres-native-enum-BwVNf0Ku.mjs";
|
|
3
|
-
import { _ as PostgresRlsEnablement, d as PostgresRlsEnablementSchema, f as PostgresRlsPolicySchema, g as PostgresRlsPolicy, m as PostgresRole, p as PostgresRoleSchema, u as PostgresNativeEnumSchema } from "./postgres-schema-
|
|
4
|
-
import {
|
|
4
|
+
import { _ as PostgresRlsEnablement, d as PostgresRlsEnablementSchema, f as PostgresRlsPolicySchema, g as PostgresRlsPolicy, m as PostgresRole, p as PostgresRoleSchema, u as PostgresNativeEnumSchema } from "./postgres-schema-CTplQZDK.mjs";
|
|
5
|
+
import { n as computeContentHash, t as POLICY_OPERATION_PREDICATES } from "./canonicalize-C7zKHw8m.mjs";
|
|
5
6
|
import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
|
|
6
7
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
7
8
|
import { temporalAuthoringPresets, temporalCodecPresetWithPrecision } from "@prisma-next/family-sql/control";
|
|
8
9
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
9
10
|
import { modelAttribute } from "@prisma-next/psl-parser";
|
|
11
|
+
import { assertWireNamePrefixLength, formatWireName, normalizeSqlBody } from "@prisma-next/sql-schema-ir/naming";
|
|
10
12
|
import { assertDefined } from "@prisma-next/utils/assertions";
|
|
11
13
|
//#region src/core/authoring.ts
|
|
12
14
|
/**
|
|
@@ -82,14 +84,14 @@ function unwrapQuotedString(raw) {
|
|
|
82
84
|
*/
|
|
83
85
|
function buildRlsPolicyEntity(input) {
|
|
84
86
|
const wireHash = computeContentHash({
|
|
85
|
-
...ifDefined("using", input.using !== void 0 ?
|
|
86
|
-
...ifDefined("withCheck", input.withCheck !== void 0 ?
|
|
87
|
+
...ifDefined("using", input.using !== void 0 ? normalizeSqlBody(input.using) : void 0),
|
|
88
|
+
...ifDefined("withCheck", input.withCheck !== void 0 ? normalizeSqlBody(input.withCheck) : void 0),
|
|
87
89
|
roles: input.roles,
|
|
88
90
|
operation: input.operation,
|
|
89
91
|
permissive: true
|
|
90
92
|
});
|
|
91
93
|
return new PostgresRlsPolicy({
|
|
92
|
-
name:
|
|
94
|
+
name: formatWireName(input.prefix, wireHash),
|
|
93
95
|
prefix: input.prefix,
|
|
94
96
|
tableName: input.tableName,
|
|
95
97
|
namespaceId: input.namespaceId,
|
|
@@ -568,11 +570,6 @@ const postgresAuthoringFieldPresets = {
|
|
|
568
570
|
}
|
|
569
571
|
};
|
|
570
572
|
/**
|
|
571
|
-
* Postgres identifiers cap at 63 characters and the wire name appends a
|
|
572
|
-
* 9-character `_<8hex>` suffix, so the authored prefix is bounded at 54.
|
|
573
|
-
*/
|
|
574
|
-
const RLS_POLICY_PREFIX_MAX_LENGTH = 54;
|
|
575
|
-
/**
|
|
576
573
|
* Resolves an entity handle's `target` ref to a table coordinate of this
|
|
577
574
|
* contract, or throws the load-time diagnostic naming the handle: a
|
|
578
575
|
* cross-space target is rejected (you cannot CREATE POLICY on a table
|
|
@@ -584,8 +581,11 @@ function requireLocalTarget(refs, subject) {
|
|
|
584
581
|
namespaceId: target.namespaceId,
|
|
585
582
|
tableName: target.tableName
|
|
586
583
|
};
|
|
587
|
-
if (target !== void 0 && target.kind === "cross-space") throw
|
|
588
|
-
|
|
584
|
+
if (target !== void 0 && target.kind === "cross-space") throw postgresError("CONTRACT.POLICY_INVALID", `defineContract: ${subject} targets model "${target.modelName ?? target.tableName}", which lives in another contract space. Policies and rlsEnabled entries must target a model declared in this contract.`, { meta: {
|
|
585
|
+
model: target.modelName ?? target.tableName,
|
|
586
|
+
reason: "cross-space-target"
|
|
587
|
+
} });
|
|
588
|
+
throw postgresError("CONTRACT.MODEL_UNKNOWN", `defineContract: ${subject} targets model "${target?.modelName ?? "<anonymous>"}", which is not in the contract's models. Add the model to \`models\`.`, { meta: { model: target?.modelName ?? "<anonymous>" } });
|
|
589
589
|
}
|
|
590
590
|
/**
|
|
591
591
|
* The SQL-family entity-handle batch lowering hook for the Postgres pack
|
|
@@ -618,7 +618,10 @@ function postgresLowerEntityHandles(input) {
|
|
|
618
618
|
}
|
|
619
619
|
case "role": {
|
|
620
620
|
const roleHandle = blindCast(handle);
|
|
621
|
-
if (roles.has(roleHandle.name)) throw
|
|
621
|
+
if (roles.has(roleHandle.name)) throw postgresError("CONTRACT.ROLE_INVALID", `defineContract: role "${roleHandle.name}" is declared more than once in the entities list.`, { meta: {
|
|
622
|
+
role: roleHandle.name,
|
|
623
|
+
reason: "duplicate"
|
|
624
|
+
} });
|
|
622
625
|
roles.set(roleHandle.name, new PostgresRole({
|
|
623
626
|
name: roleHandle.name,
|
|
624
627
|
namespaceId: UNBOUND_NAMESPACE_ID
|
|
@@ -633,20 +636,28 @@ function postgresLowerEntityHandles(input) {
|
|
|
633
636
|
});
|
|
634
637
|
break;
|
|
635
638
|
}
|
|
636
|
-
default: throw
|
|
639
|
+
default: throw postgresError("CONTRACT.ENTITY_KIND_INVALID", `defineContract: the postgres pack does not lower "${handle.entityKind}" handles from the entities list.`, { meta: { entityKind: handle.entityKind } });
|
|
637
640
|
}
|
|
638
641
|
const rows = [];
|
|
639
642
|
const seenPrefixes = /* @__PURE__ */ new Set();
|
|
640
643
|
for (const { handle: policy, refs } of policies) {
|
|
641
644
|
const prefix = policy.name;
|
|
642
|
-
|
|
645
|
+
assertWireNamePrefixLength(prefix, "defineContract: policy prefix");
|
|
643
646
|
const coordinate = requireLocalTarget(refs, `policy "${prefix}"`);
|
|
644
647
|
if (!enablements.has(coordinateKey(coordinate))) {
|
|
645
648
|
const target = refs["target"];
|
|
646
|
-
throw
|
|
649
|
+
throw postgresError("CONTRACT.POLICY_INVALID", `defineContract: policy "${prefix}" targets model "${target?.modelName ?? coordinate.tableName}", whose table is not RLS-enabled. Add rlsEnabled(<model>) to the entities list.`, { meta: {
|
|
650
|
+
prefix,
|
|
651
|
+
model: target?.modelName ?? coordinate.tableName,
|
|
652
|
+
reason: "target-not-rls-enabled"
|
|
653
|
+
} });
|
|
647
654
|
}
|
|
648
655
|
const prefixKey = `${coordinate.namespaceId} ${prefix}`;
|
|
649
|
-
if (seenPrefixes.has(prefixKey)) throw
|
|
656
|
+
if (seenPrefixes.has(prefixKey)) throw postgresError("CONTRACT.POLICY_INVALID", `defineContract: policy prefix "${prefix}" is declared more than once in namespace "${coordinate.namespaceId}". Policy prefixes must be unique per namespace.`, { meta: {
|
|
657
|
+
prefix,
|
|
658
|
+
namespaceId: coordinate.namespaceId,
|
|
659
|
+
reason: "duplicate-prefix"
|
|
660
|
+
} });
|
|
650
661
|
seenPrefixes.add(prefixKey);
|
|
651
662
|
const roleNames = [...new Set(policy.roles.map((roleHandle) => roleHandle.name))].sort();
|
|
652
663
|
rows.push({
|
|
@@ -681,4 +692,4 @@ function postgresLowerEntityHandles(input) {
|
|
|
681
692
|
//#endregion
|
|
682
693
|
export { postgresAuthoringTypes as a, postgresAuthoringPslBlockDescriptors as i, postgresAuthoringFieldPresets as n, postgresLowerEntityHandles as o, postgresAuthoringModelAttributes as r, postgresAuthoringEntityTypes as t };
|
|
683
694
|
|
|
684
|
-
//# sourceMappingURL=authoring-
|
|
695
|
+
//# sourceMappingURL=authoring-DnO1B0N9.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authoring-DnO1B0N9.mjs","names":[],"sources":["../src/core/authoring.ts"],"sourcesContent":["import {\n temporalAuthoringPresets,\n temporalCodecPresetWithPrecision,\n} from '@prisma-next/family-sql/control';\nimport type {\n AuthoringEntityContext,\n AuthoringEntityTypeFactoryOutput,\n AuthoringEntityTypeNamespace,\n AuthoringFieldNamespace,\n AuthoringModelAttributeContext,\n AuthoringModelAttributeDescriptorNamespace,\n AuthoringPslBlockDescriptorNamespace,\n AuthoringTypeNamespace,\n PslExtensionBlock,\n} from '@prisma-next/framework-components/authoring';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport { modelAttribute } from '@prisma-next/psl-parser';\nimport type {\n EntityHandleLoweringInput,\n LoweredPackEntity,\n ResolvedEntityHandleRef,\n ResolvedPslModelRefs,\n} from '@prisma-next/sql-contract/entity-handle-lowering-hook';\nimport type { SqlValueSetDerivingEntityTypeOutput } from '@prisma-next/sql-contract/value-set-derivation-hook';\nimport {\n assertWireNamePrefixLength,\n formatWireName,\n normalizeSqlBody,\n} from '@prisma-next/sql-schema-ir/naming';\nimport { assertDefined } from '@prisma-next/utils/assertions';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { PG_ENUM_CODEC_ID } from './codec-ids';\nimport { postgresError } from './errors';\nimport { PostgresNativeEnum } from './postgres-native-enum';\nimport { PostgresRlsEnablement, type PostgresRlsEnablementInput } from './postgres-rls-enablement';\nimport { PostgresRlsPolicy, type RlsPolicyOperation } from './postgres-rls-policy';\nimport { PostgresRole } from './postgres-role';\nimport {\n PostgresNativeEnumSchema,\n PostgresRlsEnablementSchema,\n PostgresRlsPolicySchema,\n PostgresRoleSchema,\n} from './postgres-validators';\nimport { computeContentHash, POLICY_OPERATION_PREDICATES } from './rls/canonicalize';\n\n/**\n * `pg.enum(<ref>)` registers as an ordinary type constructor whose sole\n * positional argument names a `native_enum` entity instead of carrying a\n * literal value. The interpreter resolves the ref to the `native_enum`\n * entity generically (driven by `entityRefArg`); the `pg/enum@1` codec\n * descriptor's `columnFromEntity` hook (see `codecs.ts`) converts that\n * entity into the column's `typeParams` and native type.\n */\nexport const postgresAuthoringTypes = {\n pg: {\n enum: {\n kind: 'typeConstructor',\n entityRefArg: { index: 0, entityKind: 'native_enum' },\n output: {\n codecId: PG_ENUM_CODEC_ID,\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n\nexport interface RlsPolicyExtensionBlock extends PslExtensionBlock {\n readonly namespaceId: string;\n /**\n * Model refs the family interpreter resolved from the block's descriptor-\n * declared `refKind: 'model'` parameters before invoking this factory\n * (keyed by parameter name). An unresolved required ref is the\n * interpreter's diagnostic; the factory is never called with one missing.\n */\n readonly resolvedModelRefs?: ResolvedPslModelRefs;\n}\n\n/** A parsed `role` block annotated with its lexical namespace id by the interpreter. */\nexport interface RoleExtensionBlock extends PslExtensionBlock {\n readonly namespaceId: string;\n}\n\n/**\n * Maps a `policy_<op>` keyword to the RLS operation it authors. The keyword\n * IS the operation (per the project's rejection of a `policy { operation = … }`\n * conditional block).\n */\nconst POLICY_KEYWORD_OPERATION: Readonly<Record<string, RlsPolicyOperation>> = {\n policy_select: 'select',\n policy_insert: 'insert',\n policy_update: 'update',\n policy_delete: 'delete',\n policy_all: 'all',\n};\n\nfunction readValueParam(block: PslExtensionBlock, key: string): string | undefined {\n const param = block.parameters[key];\n return param?.kind === 'value' ? param.raw : undefined;\n}\n\nfunction readListRefParams(block: PslExtensionBlock, key: string): string[] {\n const param = block.parameters[key];\n if (param?.kind !== 'list') return [];\n return param.items.flatMap((item) => (item.kind === 'ref' ? [item.identifier] : []));\n}\n\n/**\n * Unwraps a quoted PSL string argument, inverting the printer's\n * `escapePslString` escapes (`\\\\`, `\\\"`, `\\n`, `\\r`). An unknown escape\n * sequence is kept verbatim, matching the printer-side `unescapePslString`\n * convention.\n */\nfunction unwrapQuotedString(raw: string): string {\n if (!(raw.startsWith('\"') && raw.endsWith('\"') && raw.length >= 2)) {\n return raw;\n }\n const inner = raw.slice(1, -1);\n let result = '';\n for (let i = 0; i < inner.length; i++) {\n if (inner[i] !== '\\\\' || i + 1 >= inner.length) {\n result += inner[i];\n continue;\n }\n const next = inner[i + 1];\n if (next === '\\\\' || next === '\"') {\n result += next;\n } else if (next === 'n') {\n result += '\\n';\n } else if (next === 'r') {\n result += '\\r';\n } else {\n result += '\\\\';\n result += next;\n }\n i++;\n }\n return result;\n}\n\n/**\n * Assembles a {@link PostgresRlsPolicy} from lowered inputs: normalizes the\n * predicates, computes the content-hash wire name, and constructs the frozen\n * entity. The single hash-assembly body shared by the PSL block lowering\n * ({@link lowerRlsPolicyFromBlock}) and the TS entity-handle lowering\n * ({@link postgresLowerEntityHandles}) so the two surfaces cannot drift.\n */\nfunction buildRlsPolicyEntity(input: {\n readonly prefix: string;\n readonly tableName: string;\n readonly namespaceId: string;\n readonly operation: RlsPolicyOperation;\n readonly roles: readonly string[];\n readonly using?: string;\n readonly withCheck?: string;\n}): PostgresRlsPolicy {\n const wireHash = computeContentHash({\n ...ifDefined('using', input.using !== undefined ? normalizeSqlBody(input.using) : undefined),\n ...ifDefined(\n 'withCheck',\n input.withCheck !== undefined ? normalizeSqlBody(input.withCheck) : undefined,\n ),\n roles: input.roles,\n operation: input.operation,\n permissive: true,\n });\n\n return new PostgresRlsPolicy({\n name: formatWireName(input.prefix, wireHash),\n prefix: input.prefix,\n tableName: input.tableName,\n namespaceId: input.namespaceId,\n operation: input.operation,\n roles: input.roles,\n ...ifDefined('using', input.using),\n ...ifDefined('withCheck', input.withCheck),\n permissive: true,\n });\n}\n\nfunction lowerRlsPolicyFromBlock(\n block: RlsPolicyExtensionBlock,\n ctx: AuthoringEntityContext,\n): PostgresRlsPolicy | undefined {\n const prefix = block.name;\n const operation = POLICY_KEYWORD_OPERATION[block.keyword] ?? 'select';\n // The interpreter resolves the descriptor-declared `target` model ref to\n // its storage table name before invoking this factory (an unresolved or\n // missing required ref is the interpreter's diagnostic), so a lookup miss\n // here is structurally impossible.\n const tableName = block.resolvedModelRefs?.['target']?.tableName;\n assertDefined(\n tableName,\n `lowerRlsPolicyFromBlock: policy \"${block.name}\" reached the factory without a resolved \\`target\\` ref; the interpreter resolves same-namespace model refs before invoking entity factories.`,\n );\n const roles = [...readListRefParams(block, 'roles')].sort();\n\n const usingRaw = readValueParam(block, 'using');\n const withCheckRaw = readValueParam(block, 'withCheck');\n\n // Reject a predicate the operation does not take (e.g. `using` on INSERT, or\n // `withCheck` on SELECT/DELETE). The descriptor's param set already omits it,\n // but the generic descriptor validator is not wired into the SQL-family\n // interpreter, so the lowering enforces the per-operation predicate matrix\n // directly — a wrong predicate is a load-time diagnostic, not a silent drop.\n const support = POLICY_OPERATION_PREDICATES[operation];\n const rejectPredicate = (predicate: 'using' | 'withCheck'): undefined => {\n ctx.diagnostics?.push({\n code: 'PSL_RLS_PREDICATE_NOT_FOR_OPERATION',\n message: `\\`${block.keyword}\\` policy \"${block.name}\" does not take a \\`${predicate}\\` predicate; the ${operation.toUpperCase()} operation uses ${support.using ? '`using`' : '`withCheck`'}${support.using && support.withCheck ? ' and `withCheck`' : ' only'}.`,\n sourceId: ctx.sourceId ?? 'unknown',\n span: block.parameters[predicate]?.span ?? block.span,\n });\n return undefined;\n };\n if (usingRaw !== undefined && !support.using) return rejectPredicate('using');\n if (withCheckRaw !== undefined && !support.withCheck) return rejectPredicate('withCheck');\n\n const using = usingRaw !== undefined ? unwrapQuotedString(usingRaw) : undefined;\n const withCheck = withCheckRaw !== undefined ? unwrapQuotedString(withCheckRaw) : undefined;\n\n return buildRlsPolicyEntity({\n prefix,\n tableName,\n namespaceId: block.namespaceId,\n operation,\n roles,\n ...ifDefined('using', using),\n ...ifDefined('withCheck', withCheck),\n });\n}\n\n/**\n * Lowers a `native_enum { memberName = \"value\" … @@map(\"type_name\") }` block\n * into a {@link PostgresNativeEnum}. Members must be authored as explicit\n * `key = \"value\"` pairs — a bare (value-less) member is a diagnostic, not\n * accepted (authoring-design.md §2.1). The parsed `memberName` is only used\n * to duplicate-check and report diagnostics; the lowered entity carries just\n * the member values (a native enum is value-only — the member \"name\" isn't\n * a separate authoring concept from the value). `typeName` comes from\n * `@@map` or defaults to the block name verbatim.\n */\nfunction lowerNativeEnumFromBlock(\n block: PslExtensionBlock,\n ctx: AuthoringEntityContext,\n): PostgresNativeEnum | undefined {\n const sourceId = ctx.sourceId ?? 'unknown';\n const diagnostics = ctx.diagnostics;\n\n const mapAttr = block.blockAttributes.find((a) => a.name === 'map');\n let typeName = block.name;\n if (mapAttr) {\n const rawArg = mapAttr.args[0]?.value;\n const mapped = rawArg !== undefined ? unwrapQuotedString(rawArg) : undefined;\n if (mapped === undefined) {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_INVALID_MAP',\n message: `native_enum \"${block.name}\" @@map attribute must have a quoted type-name argument`,\n sourceId,\n span: mapAttr.span,\n });\n return undefined;\n }\n typeName = mapped;\n }\n\n let memberError = false;\n const seenValues = new Set<string>();\n const members: string[] = [];\n for (const [memberName, paramValue] of Object.entries(block.parameters)) {\n if (paramValue.kind === 'bare') {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_BARE_MEMBER',\n message: `native_enum \"${block.name}\" member \"${memberName}\" has no value; members must be authored as \"${memberName} = \\\\\"value\\\\\"\"`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n if (paramValue.kind !== 'value') continue;\n\n let jsonValue: unknown;\n try {\n jsonValue = JSON.parse(paramValue.raw);\n } catch {\n diagnostics?.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `native_enum \"${block.name}\" member \"${memberName}\" value \"${paramValue.raw}\" is not valid JSON`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n if (typeof jsonValue !== 'string') {\n diagnostics?.push({\n code: 'PSL_EXTENSION_INVALID_VALUE',\n message: `native_enum \"${block.name}\" member \"${memberName}\" value must be a string`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n if (seenValues.has(jsonValue)) {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_DUPLICATE_MEMBER_VALUE',\n message: `native_enum \"${block.name}\": duplicate member value \"${jsonValue}\"`,\n sourceId,\n span: paramValue.span,\n });\n memberError = true;\n continue;\n }\n seenValues.add(jsonValue);\n members.push(jsonValue);\n }\n\n if (memberError) return undefined;\n\n if (members.length === 0) {\n diagnostics?.push({\n code: 'PSL_NATIVE_ENUM_MISSING_MEMBERS',\n message: `native_enum \"${block.name}\" must have at least one member`,\n sourceId,\n span: block.span,\n });\n return undefined;\n }\n\n // `control` stays unset — the effective grade is resolved at read time via `effectiveControlPolicy`, like `StorageTable`/`StorageColumn`.\n return new PostgresNativeEnum({ typeName, members });\n}\n\n/**\n * `native_enum`'s entity-type factory output, checked separately from the assembled\n * `postgresAuthoringEntityTypes` map below: `deriveValueSet` is SQL-family surface\n * ({@link SqlValueSetDerivingEntityTypeOutput}), not part of the framework\n * `AuthoringEntityTypeFactoryOutput` shape, so folding it directly into the map's single\n * `satisfies AuthoringEntityTypeNamespace` check would trip an excess-property error. Checking it\n * here against the intersection of both shapes keeps it structurally valid against each without\n * widening the map's own check.\n */\nconst nativeEnumEntityTypeOutput = {\n factory: lowerNativeEnumFromBlock,\n deriveValueSet: (entity: PostgresNativeEnum) => ({\n kind: 'valueSet' as const,\n values: [...entity.members],\n }),\n} satisfies AuthoringEntityTypeFactoryOutput<PslExtensionBlock, PostgresNativeEnum | undefined> &\n SqlValueSetDerivingEntityTypeOutput;\n\n/**\n * Lowers a `role <name> {}` block into a {@link PostgresRole}. Roles are\n * cluster-scoped in Postgres, so the block must be declared inside\n * `namespace unbound { … }` — any other lexical namespace (a named schema,\n * or the default bucket top-level declarations resolve to) is a load-time\n * diagnostic. The lowered entity carries the unbound coordinate.\n */\nfunction lowerRoleFromBlock(\n block: RoleExtensionBlock,\n ctx: AuthoringEntityContext,\n): PostgresRole | undefined {\n if (block.namespaceId !== UNBOUND_NAMESPACE_ID) {\n ctx.diagnostics?.push({\n code: 'PSL_ROLE_BLOCK_OUTSIDE_UNBOUND_NAMESPACE',\n message: `\\`role\\` block \"${block.name}\" must be declared inside \\`namespace unbound { }\\`, not in namespace \"${block.namespaceId}\"`,\n sourceId: ctx.sourceId ?? 'unknown',\n span: block.span,\n });\n return undefined;\n }\n return new PostgresRole({ name: block.name, namespaceId: UNBOUND_NAMESPACE_ID });\n}\n\nexport const postgresAuthoringEntityTypes = {\n role: {\n kind: 'entity',\n discriminator: 'role',\n validatorSchema: PostgresRoleSchema,\n output: {\n factory: lowerRoleFromBlock,\n },\n },\n rls: {\n kind: 'entity',\n discriminator: 'rls',\n validatorSchema: PostgresRlsEnablementSchema,\n output: {\n factory: (input: PostgresRlsEnablementInput): PostgresRlsEnablement =>\n new PostgresRlsEnablement(input),\n },\n },\n policy: {\n kind: 'entity',\n discriminator: 'policy',\n validatorSchema: PostgresRlsPolicySchema,\n output: {\n factory: lowerRlsPolicyFromBlock,\n },\n },\n native_enum: {\n kind: 'entity',\n discriminator: 'native_enum',\n validatorSchema: PostgresNativeEnumSchema,\n output: nativeEnumEntityTypeOutput,\n },\n} as const satisfies AuthoringEntityTypeNamespace;\n\n/**\n * Field presets contributed by the Postgres target pack.\n *\n * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter\n * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field\n * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar\n * surface (e.g. `Int`) lowers to byte-identical contracts.\n *\n * The `uuidNative` / `id.uuidv4Native` / `id.uuidv7Native` presets use the\n * native Postgres `uuid` type (codecId `pg/uuid@1`). For cross-target\n * portability use `uuidString` / `id.uuidv4String` / `id.uuidv7String` from\n * the family pack instead.\n */\n/**\n * Shared parameter descriptors for the five `policy_<op>` PSL block\n * keywords. All five share the `policy` discriminator — the parser\n * dispatches by keyword (see the framework's PSL-block SPI), and every\n * keyword's factory lowers to `PostgresRlsPolicy` via `lowerRlsPolicyFromBlock`.\n *\n * The `roles` list uses `scope:'cross-space'` because same-namespace\n * role ref resolution requires PSL namespace entries keyed by `refKind`\n * (i.e. `'role'`), which in turn requires the role block discriminator to\n * equal `'role'`. Aligning discriminator with refKind is tracked for\n * slice 4 (cross-space roles). Until then cross-space passes validation\n * unconditionally and the authored role names flow through unchanged.\n */\nconst policyTargetParam = {\n kind: 'ref',\n refKind: 'model',\n scope: 'same-namespace',\n required: true,\n} as const;\nconst policyRolesParam = {\n kind: 'list',\n of: { kind: 'ref', refKind: 'role', scope: 'cross-space' },\n} as const;\nconst policyPredicateParam = { kind: 'value', codecId: 'pg/text@1', required: true } as const;\n// A policy may only target an RLS-controlled model: the model named by\n// `target` must declare `@@rls`, or the load fails with a diagnostic naming\n// the model and the policy prefix.\nconst policyRequiresRls = { parameter: 'target', attribute: 'rls' } as const;\n\nexport const postgresAuthoringPslBlockDescriptors = {\n // The predicate param set per keyword mirrors Postgres: SELECT/DELETE take\n // USING only; INSERT takes WITH CHECK only; UPDATE/ALL take both. The\n // per-operation predicate matrix is enforced in `lowerRlsPolicyFromBlock`\n // (a wrong predicate for the operation is a load-time diagnostic there),\n // since the generic descriptor validator is not wired into the SQL-family\n // interpreter.\n policy_select: {\n kind: 'pslBlock',\n keyword: 'policy_select',\n discriminator: 'policy',\n name: { required: true },\n parameters: { target: policyTargetParam, roles: policyRolesParam, using: policyPredicateParam },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_delete: {\n kind: 'pslBlock',\n keyword: 'policy_delete',\n discriminator: 'policy',\n name: { required: true },\n parameters: { target: policyTargetParam, roles: policyRolesParam, using: policyPredicateParam },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_insert: {\n kind: 'pslBlock',\n keyword: 'policy_insert',\n discriminator: 'policy',\n name: { required: true },\n parameters: {\n target: policyTargetParam,\n roles: policyRolesParam,\n withCheck: policyPredicateParam,\n },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_update: {\n kind: 'pslBlock',\n keyword: 'policy_update',\n discriminator: 'policy',\n name: { required: true },\n parameters: {\n target: policyTargetParam,\n roles: policyRolesParam,\n using: policyPredicateParam,\n withCheck: policyPredicateParam,\n },\n requiresModelAttribute: policyRequiresRls,\n },\n policy_all: {\n kind: 'pslBlock',\n keyword: 'policy_all',\n discriminator: 'policy',\n name: { required: true },\n parameters: {\n target: policyTargetParam,\n roles: policyRolesParam,\n using: policyPredicateParam,\n withCheck: policyPredicateParam,\n },\n requiresModelAttribute: policyRequiresRls,\n },\n /**\n * PSL block descriptor for `native_enum`.\n *\n * Reuses the existing variadic-block mechanism (the same shape the SQL\n * family's `enum` block ships): the body is an open `memberName = \"value\"`\n * list. `variadicParameters: true` opens the block to arbitrary keys\n * beyond the declared (empty) `parameters` set — the lowering factory\n * (`lowerNativeEnumFromBlock`) turns the variadic entries into ordered\n * members and rejects a bare (value-less) member.\n */\n native_enum: {\n kind: 'pslBlock',\n keyword: 'native_enum',\n discriminator: 'native_enum',\n name: { required: true },\n parameters: {},\n variadicParameters: true,\n },\n /**\n * PSL block descriptor for `role` (e.g. `role anon {}`). Name-only, no\n * parameters and no body content. Declared inside `namespace unbound { }`\n * — see {@link lowerRoleFromBlock} for the placement check and the\n * coordinate the lowered entity carries.\n */\n role: {\n kind: 'pslBlock',\n keyword: 'role',\n discriminator: 'role',\n name: { required: true },\n parameters: {},\n },\n} as const satisfies AuthoringPslBlockDescriptorNamespace;\n\n/**\n * `@@` model attributes contributed by the Postgres target pack.\n *\n * `@@rls` is argument-less: presence marks the model's table\n * RLS-controlled. It lowers to a {@link PostgresRlsEnablement} marker in\n * the namespace's `entries.rls`, keyed by the model's table name — the\n * marker (never the policy set) is what drives\n * `ENABLE`/`DISABLE ROW LEVEL SECURITY` planning.\n */\nexport const postgresAuthoringModelAttributes = {\n rls: {\n kind: 'modelAttribute',\n attribute: 'rls',\n spec: modelAttribute('rls', {}),\n lower: (_parsed: Record<never, never>, ctx: AuthoringModelAttributeContext) => ({\n key: ctx.storageName,\n entity: new PostgresRlsEnablement({\n tableName: ctx.storageName,\n namespaceId: ctx.namespaceId,\n }),\n }),\n },\n} as const satisfies AuthoringModelAttributeDescriptorNamespace;\n\nexport const postgresAuthoringFieldPresets = {\n text: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/text@1',\n nativeType: 'text',\n },\n },\n int: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int4@1',\n nativeType: 'int4',\n },\n },\n bigint: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/int8@1',\n nativeType: 'int8',\n },\n },\n float: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/float8@1',\n nativeType: 'float8',\n },\n },\n decimal: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/numeric@1',\n nativeType: 'numeric',\n },\n },\n boolean: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bool@1',\n nativeType: 'bool',\n },\n },\n json: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/jsonb@1',\n nativeType: 'jsonb',\n },\n },\n bytes: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/bytea@1',\n nativeType: 'bytea',\n },\n },\n dateTime: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n },\n },\n temporal: {\n .../* @__PURE__ */ temporalAuthoringPresets({\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n }),\n timestamp: /* @__PURE__ */ temporalCodecPresetWithPrecision({\n codecId: 'pg/timestamp@1',\n nativeType: 'timestamp',\n }),\n timestamptz: /* @__PURE__ */ temporalCodecPresetWithPrecision({\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\n }),\n },\n uuidNative: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n },\n },\n id: {\n uuidv4Native: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv4',\n },\n },\n id: true,\n },\n },\n uuidv7Native: {\n kind: 'fieldPreset',\n output: {\n codecId: 'pg/uuid@1',\n nativeType: 'uuid',\n executionDefaults: {\n onCreate: {\n kind: 'generator',\n id: 'uuidv7',\n },\n },\n id: true,\n },\n },\n },\n} as const satisfies AuthoringFieldNamespace;\n\ninterface RlsRoleHandleShape {\n readonly entityKind: 'role';\n readonly name: string;\n}\n\ninterface RlsPolicyHandleShape {\n readonly entityKind: 'policy';\n readonly operation: RlsPolicyOperation;\n readonly name: string;\n readonly roles: readonly { readonly name: string }[];\n readonly using?: string;\n readonly withCheck?: string;\n}\n\ninterface RlsTargetCoordinate {\n readonly namespaceId: string;\n readonly tableName: string;\n}\n\n/**\n * Resolves an entity handle's `target` ref to a table coordinate of this\n * contract, or throws the load-time diagnostic naming the handle: a\n * cross-space target is rejected (you cannot CREATE POLICY on a table\n * another space owns) and an unresolved target names the model.\n */\nfunction requireLocalTarget(\n refs: Readonly<Record<string, ResolvedEntityHandleRef>>,\n subject: string,\n): RlsTargetCoordinate {\n const target = refs['target'];\n if (target !== undefined && target.kind === 'resolved') {\n return { namespaceId: target.namespaceId, tableName: target.tableName };\n }\n if (target !== undefined && target.kind === 'cross-space') {\n throw postgresError(\n 'CONTRACT.POLICY_INVALID',\n `defineContract: ${subject} targets model \"${target.modelName ?? target.tableName}\", which lives in another contract space. Policies and rlsEnabled entries must target a model declared in this contract.`,\n { meta: { model: target.modelName ?? target.tableName, reason: 'cross-space-target' } },\n );\n }\n throw postgresError(\n 'CONTRACT.MODEL_UNKNOWN',\n `defineContract: ${subject} targets model \"${target?.modelName ?? '<anonymous>'}\", which is not in the contract's models. Add the model to \\`models\\`.`,\n { meta: { model: target?.modelName ?? '<anonymous>' } },\n );\n}\n\n/**\n * The SQL-family entity-handle batch lowering hook for the Postgres pack\n * (`SqlEntityHandleLoweringContribution`). Receives every `entities` handle\n * whose kind this pack registered — batch, so the cross-entity diagnostics\n * (duplicate prefix, policy without rlsEnabled, duplicate role) can see\n * sibling handles — and lowers them with the same keying and hash assembly\n * as the PSL path: `policy` keyed by prefix (wire name via\n * {@link buildRlsPolicyEntity}), `rls` keyed by table name, `role` keyed by\n * name and filed under the default namespace (roles are declared\n * contract-wide; PSL has no role block to set a precedent).\n */\nexport function postgresLowerEntityHandles(\n input: EntityHandleLoweringInput,\n): readonly LoweredPackEntity[] {\n const enablements = new Map<\n string,\n { coordinate: RlsTargetCoordinate; entity: PostgresRlsEnablement }\n >();\n const roles = new Map<string, PostgresRole>();\n const policies: {\n readonly handle: RlsPolicyHandleShape;\n readonly refs: Readonly<Record<string, ResolvedEntityHandleRef>>;\n }[] = [];\n const coordinateKey = (coordinate: RlsTargetCoordinate): string =>\n `${coordinate.namespaceId} ${coordinate.tableName}`;\n\n for (const { handle, refs } of input.handles) {\n switch (handle.entityKind) {\n case 'rls': {\n const coordinate = requireLocalTarget(refs, 'an rlsEnabled entry');\n const key = coordinateKey(coordinate);\n if (!enablements.has(key)) {\n enablements.set(key, {\n coordinate,\n entity: new PostgresRlsEnablement({\n tableName: coordinate.tableName,\n namespaceId: coordinate.namespaceId,\n }),\n });\n }\n break;\n }\n case 'role': {\n const roleHandle = blindCast<\n RlsRoleHandleShape,\n 'role handles are constructed only by the postgres contract-builder role() constructor, which enforces this shape'\n >(handle);\n if (roles.has(roleHandle.name)) {\n throw postgresError(\n 'CONTRACT.ROLE_INVALID',\n `defineContract: role \"${roleHandle.name}\" is declared more than once in the entities list.`,\n { meta: { role: roleHandle.name, reason: 'duplicate' } },\n );\n }\n // Roles are cluster-scoped in Postgres, so they always land in the\n // `__unbound__` namespace — identical to a PSL `role` block\n // (`lowerRoleFromBlock`) and matching the `PostgresRole` class's own\n // contract. The declaring surface (TS entities vs PSL) does not move\n // the slot.\n roles.set(\n roleHandle.name,\n new PostgresRole({ name: roleHandle.name, namespaceId: UNBOUND_NAMESPACE_ID }),\n );\n break;\n }\n case 'policy': {\n const policyHandle = blindCast<\n RlsPolicyHandleShape,\n 'policy handles are constructed only by the postgres contract-builder policy*() constructors, which enforce this shape'\n >(handle);\n policies.push({ handle: policyHandle, refs });\n break;\n }\n default:\n throw postgresError(\n 'CONTRACT.ENTITY_KIND_INVALID',\n `defineContract: the postgres pack does not lower \"${handle.entityKind}\" handles from the entities list.`,\n { meta: { entityKind: handle.entityKind } },\n );\n }\n }\n\n const rows: LoweredPackEntity[] = [];\n const seenPrefixes = new Set<string>();\n\n for (const { handle: policy, refs } of policies) {\n const prefix = policy.name;\n assertWireNamePrefixLength(prefix, 'defineContract: policy prefix');\n const coordinate = requireLocalTarget(refs, `policy \"${prefix}\"`);\n if (!enablements.has(coordinateKey(coordinate))) {\n const target = refs['target'];\n throw postgresError(\n 'CONTRACT.POLICY_INVALID',\n `defineContract: policy \"${prefix}\" targets model \"${target?.modelName ?? coordinate.tableName}\", whose table is not RLS-enabled. Add rlsEnabled(<model>) to the entities list.`,\n {\n meta: {\n prefix,\n model: target?.modelName ?? coordinate.tableName,\n reason: 'target-not-rls-enabled',\n },\n },\n );\n }\n const prefixKey = `${coordinate.namespaceId} ${prefix}`;\n if (seenPrefixes.has(prefixKey)) {\n throw postgresError(\n 'CONTRACT.POLICY_INVALID',\n `defineContract: policy prefix \"${prefix}\" is declared more than once in namespace \"${coordinate.namespaceId}\". Policy prefixes must be unique per namespace.`,\n { meta: { prefix, namespaceId: coordinate.namespaceId, reason: 'duplicate-prefix' } },\n );\n }\n seenPrefixes.add(prefixKey);\n\n const roleNames = [...new Set(policy.roles.map((roleHandle) => roleHandle.name))].sort();\n rows.push({\n namespaceId: coordinate.namespaceId,\n entityKind: 'policy',\n key: prefix,\n entity: buildRlsPolicyEntity({\n prefix,\n tableName: coordinate.tableName,\n namespaceId: coordinate.namespaceId,\n operation: policy.operation,\n roles: roleNames,\n ...ifDefined('using', policy.using),\n ...ifDefined('withCheck', policy.withCheck),\n }),\n });\n }\n\n for (const { coordinate, entity } of enablements.values()) {\n rows.push({\n namespaceId: coordinate.namespaceId,\n entityKind: 'rls',\n key: coordinate.tableName,\n entity,\n });\n }\n for (const [name, entity] of roles) {\n rows.push({ namespaceId: UNBOUND_NAMESPACE_ID, entityKind: 'role', key: name, entity });\n }\n return rows;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsDA,MAAa,yBAAyB,EACpC,IAAI,EACF,MAAM;CACJ,MAAM;CACN,cAAc;EAAE,OAAO;EAAG,YAAY;CAAc;CACpD,QAAQ,EACN,SAAS,iBACX;AACF,EACF,EACF;;;;;;AAuBA,MAAM,2BAAyE;CAC7E,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,YAAY;AACd;AAEA,SAAS,eAAe,OAA0B,KAAiC;CACjF,MAAM,QAAQ,MAAM,WAAW;CAC/B,OAAO,OAAO,SAAS,UAAU,MAAM,MAAM,KAAA;AAC/C;AAEA,SAAS,kBAAkB,OAA0B,KAAuB;CAC1E,MAAM,QAAQ,MAAM,WAAW;CAC/B,IAAI,OAAO,SAAS,QAAQ,OAAO,CAAC;CACpC,OAAO,MAAM,MAAM,SAAS,SAAU,KAAK,SAAS,QAAQ,CAAC,KAAK,UAAU,IAAI,CAAC,CAAE;AACrF;;;;;;;AAQA,SAAS,mBAAmB,KAAqB;CAC/C,IAAI,EAAE,IAAI,WAAW,IAAG,KAAK,IAAI,SAAS,IAAG,KAAK,IAAI,UAAU,IAC9D,OAAO;CAET,MAAM,QAAQ,IAAI,MAAM,GAAG,EAAE;CAC7B,IAAI,SAAS;CACb,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,IAAI,MAAM,OAAO,QAAQ,I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|
1
|
+
import { normalizeSqlBody } from "@prisma-next/sql-schema-ir/naming";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
//#region src/core/rls/canonicalize.ts
|
|
4
|
+
/**
|
|
5
|
+
* Which predicate each RLS operation admits, mirroring Postgres: SELECT and
|
|
6
|
+
* DELETE decide row visibility/eligibility with `USING` only; INSERT
|
|
7
|
+
* validates the new row with `WITH CHECK` only; UPDATE and ALL take either
|
|
8
|
+
* or both. Single-homed here so the PSL lowering and the TS handle
|
|
9
|
+
* constructors enforce the same matrix.
|
|
10
|
+
*/
|
|
11
|
+
const POLICY_OPERATION_PREDICATES = {
|
|
12
|
+
select: {
|
|
13
|
+
using: true,
|
|
14
|
+
withCheck: false
|
|
15
|
+
},
|
|
16
|
+
insert: {
|
|
17
|
+
using: false,
|
|
18
|
+
withCheck: true
|
|
19
|
+
},
|
|
20
|
+
update: {
|
|
21
|
+
using: true,
|
|
22
|
+
withCheck: true
|
|
23
|
+
},
|
|
24
|
+
delete: {
|
|
25
|
+
using: true,
|
|
26
|
+
withCheck: false
|
|
27
|
+
},
|
|
28
|
+
all: {
|
|
29
|
+
using: true,
|
|
30
|
+
withCheck: true
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Returns the first 8 lowercase hex characters of the SHA-256 digest over the
|
|
35
|
+
* canonical content tuple for an RLS policy:
|
|
36
|
+
*
|
|
37
|
+
* [normalizeSqlBody(using), normalizeSqlBody(withCheck), sortedRoles, operation, permissive]
|
|
38
|
+
*
|
|
39
|
+
* Schema and table are excluded (they are orthogonal to policy equivalence).
|
|
40
|
+
* Uses `JSON.stringify` for a deterministic encoding.
|
|
41
|
+
*/
|
|
42
|
+
function computeContentHash(parts) {
|
|
43
|
+
const using = normalizeSqlBody(parts.using ?? "");
|
|
44
|
+
const withCheck = normalizeSqlBody(parts.withCheck ?? "");
|
|
45
|
+
const roles = [...new Set(parts.roles)].sort();
|
|
46
|
+
const permissive = parts.permissive ? "permissive" : "restrictive";
|
|
47
|
+
const tuple = JSON.stringify([
|
|
48
|
+
using,
|
|
49
|
+
withCheck,
|
|
50
|
+
roles,
|
|
51
|
+
parts.operation,
|
|
52
|
+
permissive
|
|
53
|
+
]);
|
|
54
|
+
return createHash("sha256").update(tuple).digest("hex").slice(0, 8);
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { computeContentHash as n, POLICY_OPERATION_PREDICATES as t };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=canonicalize-C7zKHw8m.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalize-C7zKHw8m.mjs","names":[],"sources":["../src/core/rls/canonicalize.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { normalizeSqlBody } from '@prisma-next/sql-schema-ir/naming';\n\nexport type RlsPolicyOperation = 'select' | 'insert' | 'update' | 'delete' | 'all';\n\n/**\n * Which predicate each RLS operation admits, mirroring Postgres: SELECT and\n * DELETE decide row visibility/eligibility with `USING` only; INSERT\n * validates the new row with `WITH CHECK` only; UPDATE and ALL take either\n * or both. Single-homed here so the PSL lowering and the TS handle\n * constructors enforce the same matrix.\n */\nexport const POLICY_OPERATION_PREDICATES: Readonly<\n Record<RlsPolicyOperation, { readonly using: boolean; readonly withCheck: boolean }>\n> = {\n select: { using: true, withCheck: false },\n insert: { using: false, withCheck: true },\n update: { using: true, withCheck: true },\n delete: { using: true, withCheck: false },\n all: { using: true, withCheck: true },\n};\n\nexport interface ContentHashParts {\n readonly using?: string;\n readonly withCheck?: string;\n readonly roles: readonly string[];\n readonly operation: RlsPolicyOperation;\n readonly permissive: boolean;\n}\n\n/**\n * Returns the first 8 lowercase hex characters of the SHA-256 digest over the\n * canonical content tuple for an RLS policy:\n *\n * [normalizeSqlBody(using), normalizeSqlBody(withCheck), sortedRoles, operation, permissive]\n *\n * Schema and table are excluded (they are orthogonal to policy equivalence).\n * Uses `JSON.stringify` for a deterministic encoding.\n */\nexport function computeContentHash(parts: ContentHashParts): string {\n const using = normalizeSqlBody(parts.using ?? '');\n const withCheck = normalizeSqlBody(parts.withCheck ?? '');\n const roles = [...new Set(parts.roles)].sort();\n const permissive = parts.permissive ? 'permissive' : 'restrictive';\n\n const tuple = JSON.stringify([using, withCheck, roles, parts.operation, permissive]);\n return createHash('sha256').update(tuple).digest('hex').slice(0, 8);\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAa,8BAET;CACF,QAAQ;EAAE,OAAO;EAAM,WAAW;CAAM;CACxC,QAAQ;EAAE,OAAO;EAAO,WAAW;CAAK;CACxC,QAAQ;EAAE,OAAO;EAAM,WAAW;CAAK;CACvC,QAAQ;EAAE,OAAO;EAAM,WAAW;CAAM;CACxC,KAAK;EAAE,OAAO;EAAM,WAAW;CAAK;AACtC;;;;;;;;;;AAmBA,SAAgB,mBAAmB,OAAiC;CAClE,MAAM,QAAQ,iBAAiB,MAAM,SAAS,EAAE;CAChD,MAAM,YAAY,iBAAiB,MAAM,aAAa,EAAE;CACxD,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,MAAM,KAAK,CAAC,CAAC,CAAC,KAAK;CAC7C,MAAM,aAAa,MAAM,aAAa,eAAe;CAErD,MAAM,QAAQ,KAAK,UAAU;EAAC;EAAO;EAAW;EAAO,MAAM;EAAW;CAAU,CAAC;CACnF,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC;AACpE"}
|
|
@@ -18,31 +18,16 @@ interface ContentHashParts {
|
|
|
18
18
|
readonly operation: RlsPolicyOperation;
|
|
19
19
|
readonly permissive: boolean;
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Stabilizes an authored predicate for hashing: trim, and collapse runs of
|
|
23
|
-
* internal whitespace to a single space.
|
|
24
|
-
*
|
|
25
|
-
* This is deliberately minimal. The content hash is the equivalence relation
|
|
26
|
-
* for a policy, and the wire name (prefix + hash) is the only thing ever
|
|
27
|
-
* compared — we never recompute the hash from an introspected policy body, so
|
|
28
|
-
* there is no need to match Postgres's reprinted form. Minimal normalization
|
|
29
|
-
* also protects the no-collision property: aggressive rewriting (lowercasing,
|
|
30
|
-
* paren-stripping, cast-alias folding) risks collapsing two distinct predicates
|
|
31
|
-
* onto one hash. Out-of-band alteration of a hashed policy is unsupported.
|
|
32
|
-
*
|
|
33
|
-
* The normalizer is a stability commitment: any change re-suffixes all wire names.
|
|
34
|
-
*/
|
|
35
|
-
declare function normalizePredicate(sql: string): string;
|
|
36
21
|
/**
|
|
37
22
|
* Returns the first 8 lowercase hex characters of the SHA-256 digest over the
|
|
38
23
|
* canonical content tuple for an RLS policy:
|
|
39
24
|
*
|
|
40
|
-
* [
|
|
25
|
+
* [normalizeSqlBody(using), normalizeSqlBody(withCheck), sortedRoles, operation, permissive]
|
|
41
26
|
*
|
|
42
27
|
* Schema and table are excluded (they are orthogonal to policy equivalence).
|
|
43
28
|
* Uses `JSON.stringify` for a deterministic encoding.
|
|
44
29
|
*/
|
|
45
30
|
declare function computeContentHash(parts: ContentHashParts): string;
|
|
46
31
|
//#endregion
|
|
47
|
-
export {
|
|
48
|
-
//# sourceMappingURL=canonicalize-
|
|
32
|
+
export { computeContentHash as i, POLICY_OPERATION_PREDICATES as n, RlsPolicyOperation as r, ContentHashParts as t };
|
|
33
|
+
//# sourceMappingURL=canonicalize-CQlxSR4D.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalize-CQlxSR4D.d.mts","names":[],"sources":["../src/core/rls/canonicalize.ts"],"mappings":";KAGY;;;;;;;;cASC,6BAA6B,SACxC,OAAO;WAA+B;WAAyB;;UAShD;WACN;WACA;WACA;WACA,WAAW;WACX;;;;;;;;;;;iBAYK,mBAAmB,OAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as PgTimestampDescriptor, D as PgVarbitDescriptor, E as PgUuidDescriptor, O as PgVarcharDescriptor, S as PgTimeDescriptor, T as PgTimetzDescriptor, _ as PgIntervalDescriptor, a as PgDateDescriptor, b as PgNumericDescriptor, d as PgFloatDescriptor, f as PgInetDescriptor, g as PgIntDescriptor, h as PgInt8Descriptor, i as PgCharDescriptor, l as PgFloat4Descriptor, m as PgInt4Descriptor, n as PgBoolDescriptor, p as PgInt2Descriptor, r as PgByteaDescriptor, s as PgEnumDescriptor, t as PgBitDescriptor, u as PgFloat8Descriptor, v as PgJsonDescriptor, w as PgTimestamptzDescriptor, x as PgTextDescriptor, y as PgJsonbDescriptor } from "./codecs-CGE5dh94.mjs";
|
|
2
2
|
import { ExtractCodecTypes } from "@prisma-next/sql-relational-core/ast";
|
|
3
3
|
import { JsonValue as JsonValue$1 } from "@prisma-next/contract/types";
|
|
4
4
|
//#region src/core/codec-type-map.d.ts
|
|
@@ -21,6 +21,7 @@ declare const codecDescriptorMap: {
|
|
|
21
21
|
readonly float4: PgFloat4Descriptor;
|
|
22
22
|
readonly float8: PgFloat8Descriptor;
|
|
23
23
|
readonly numeric: PgNumericDescriptor;
|
|
24
|
+
readonly date: PgDateDescriptor;
|
|
24
25
|
readonly timestamp: PgTimestampDescriptor;
|
|
25
26
|
readonly timestamptz: PgTimestamptzDescriptor;
|
|
26
27
|
readonly time: PgTimeDescriptor;
|
|
@@ -76,4 +77,4 @@ type Interval<P extends number | undefined = undefined> = BrandedString<{
|
|
|
76
77
|
}>;
|
|
77
78
|
//#endregion
|
|
78
79
|
export { JsonValue$1 as a, Timestamp as c, VarBit as d, Varchar as f, Interval as i, Timestamptz as l, Char as n, Numeric as o, CodecTypes as r, Time as s, Bit as t, Timetz as u };
|
|
79
|
-
//# sourceMappingURL=codec-types-
|
|
80
|
+
//# sourceMappingURL=codec-types-DdoPc2dy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec-types-DdoPc2dy.d.mts","names":[],"sources":["../src/core/codec-type-map.ts","../src/exports/codec-types.ts"],"mappings":";;;;cA+Ca;;;;;;;iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmCD,QAAQ,iBAAiB,WAAW,gBAAgB,WAAW,EAAE,KAAK,EAAE,GAAG;KAE3E,4BAA4B;KAE5B,sBAAsB,kBAAkB;;;KC3ExC,aAAa,QAAQ;KAI5B,QAAQ,GAAG,cAAc,2BAA2B,gBAC7C,WAAW,QAAQ,MAAM;KAGhC,cAAc,cAAc,2BAA2B,gBAAgB;KAEhE,KAAK,oBAAoB;EAAgB,cAAc;;KACvD,QAAQ,oBAAoB;EAAgB,iBAAiB;;KAC7D,QAAQ,kBAAkB,4CAA4C;EAChF,oBAAoB;EACpB,gBAAgB;;KAEN,IAAI,oBAAoB;EAAgB,aAAa;;KACrD,OAAO,oBAAoB;EAAgB,gBAAgB;;KAC3D,UAAU,4CAA4C;EAChE,sBAAsB;;KAEZ,YAAY,4CAA4C;EAClE,wBAAwB;;KAEd,KAAK,4CAA4C;EAAgB,iBAAiB;;KAClF,OAAO,4CAA4C;EAC7D,mBAAmB;;KAET,SAAS,4CAA4C;EAC/D,qBAAqB"}
|
package/dist/codec-types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as JsonValue, c as Timestamp, d as VarBit, f as Varchar, i as Interval, l as Timestamptz, n as Char, o as Numeric, r as CodecTypes, s as Time, t as Bit, u as Timetz } from "./codec-types-
|
|
1
|
+
import { a as JsonValue, c as Timestamp, d as VarBit, f as Varchar, i as Interval, l as Timestamptz, n as Char, o as Numeric, r as CodecTypes, s as Time, t as Bit, u as Timetz } from "./codec-types-DdoPc2dy.mjs";
|
|
2
2
|
export { Bit, Char, CodecTypes, Interval, type JsonValue, Numeric, Time, Timestamp, Timestamptz, Timetz, VarBit, Varchar };
|
|
@@ -63,6 +63,11 @@ declare class PgEnumCodec extends CodecImpl<typeof PG_ENUM_CODEC_ID, readonly ['
|
|
|
63
63
|
type PgEnumParams = {
|
|
64
64
|
readonly typeName: string;
|
|
65
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Narrows codec `typeParams` to {@link PgEnumParams} — the shape that binds a
|
|
68
|
+
* column to a named database type (a native enum's `CREATE TYPE` name).
|
|
69
|
+
*/
|
|
70
|
+
declare function isPgEnumParams(value: unknown): value is PgEnumParams;
|
|
66
71
|
declare class PgEnumDescriptor extends CodecDescriptorImpl<PgEnumParams> {
|
|
67
72
|
readonly codecId: "pg/enum@1";
|
|
68
73
|
readonly traits: readonly ["equality", "order", "textual"];
|
|
@@ -713,5 +718,5 @@ declare class PgFloatDescriptor extends CodecDescriptorImpl<void> {
|
|
|
713
718
|
}
|
|
714
719
|
declare const pgFloatColumn: () => import("@prisma-next/framework-components/codec").ColumnSpec<SqlFloatCodec, undefined>;
|
|
715
720
|
//#endregion
|
|
716
|
-
export {
|
|
717
|
-
//# sourceMappingURL=codecs-
|
|
721
|
+
export { pgVarbitColumn as $, pgBitColumn as A, pgInt4Column as B, PgTimestampDescriptor as C, PgVarbitDescriptor as D, PgUuidDescriptor as E, pgFloat4Column as F, pgJsonbColumn as G, pgIntColumn as H, pgFloat8Column as I, pgTimeColumn as J, pgNumericColumn as K, pgFloatColumn as L, pgCharColumn as M, pgDateColumn as N, PgVarcharDescriptor as O, pgEnumDescriptor as P, pgUuidColumn as Q, pgInetColumn as R, PgTimeDescriptor as S, PgTimetzDescriptor as T, pgIntervalColumn as U, pgInt8Column as V, pgJsonColumn as W, pgTimestamptzColumn as X, pgTimestampColumn as Y, pgTimetzColumn as Z, PgIntervalDescriptor as _, PgDateDescriptor as a, PgNumericDescriptor as b, PgEnumParams as c, PgFloatDescriptor as d, pgVarcharColumn as et, PgInetDescriptor as f, PgIntDescriptor as g, PgInt8Descriptor as h, PgCharDescriptor as i, pgBoolColumn as j, isPgEnumParams as k, PgFloat4Descriptor as l, PgInt4Descriptor as m, PgBoolDescriptor as n, PgEnumCodec as o, PgInt2Descriptor as p, pgTextColumn as q, PgByteaDescriptor as r, PgEnumDescriptor as s, PgBitDescriptor as t, postgresQualifyColumnType as tt, PgFloat8Descriptor as u, PgJsonDescriptor as v, PgTimestamptzDescriptor as w, PgTextDescriptor as x, PgJsonbDescriptor as y, pgInt2Column as z };
|
|
722
|
+
//# sourceMappingURL=codecs-CGE5dh94.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codecs-CGE5dh94.d.mts","names":[],"sources":["../src/core/codecs.ts"],"mappings":";;;;;;KAkGK;WAA0B;;KAC1B;WAA6B;;KAC7B;WAA2B;WAA6B;;cAwChD,oBAAoB,iBACxB;EAKD,OAAO,eAAe,MAAM,mBAAmB;EAG/C,OAAO,cAAc,MAAM,mBAAmB;EAGpD,WAAW,gBAAgB;EAG3B,WAAW,MAAM;;cAKN,yBAAyB;WAClB;WACA;WACA;WACA;;;;;;;;;WACA,cAAc;EACvB,mBAAmB,OAAO;EAG1B,YAAY,KAAK,yBAAyB;;cAOxC,sEAAY,WAAA;;;;;;;;;;;;;;;;;cAsBZ,oBAAoB,iBACxB;EAKD,OAAO,eAAe,MAAM,mBAAmB;EAG/C,OAAO,cAAc,MAAM,mBAAmB;EAGpD,WAAW,gBAAgB;EAG3B,WAAW,MAAM;;KAQP;WAA0B;;;;;;iBAMtB,eAAe,iBAAiB,SAAS;cAc5C,yBAAyB,oBAAoB;WACtC;WACA;WACA;WACA;;;;;;;;;WACA,4DAAY;;;EACrB,mBAAmB,OAAO;EAG1B,QAAQ,YAAY,wBAAwB;EAK5C,QAAQ,SAAS,gBAAgB,KAAK,yBAAyB;;;;;;;;;;;;;;;;;EAoBxE,iBACE;aACY,YAAY;aAAuB;;;;;;;;;;;EAcjD,kBAAkB,kBAAkB;;cAOzB,kBAAgB;;;;;;;;;;;;;iBAcb,0BACd;WACW;WACA;WACA,aAAa;GAExB;WACY;WAA6B,aAAa;;cAiD3C,oBAAoB,iBACxB;EAKD,OAAO,eAAe,MAAM,mBAAmB;EAG/C,OAAO,cAAc,MAAM,mB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;WACnB;WACA;WACA;;;;;;;;;WACA;WACA,cAAY;EACrB,mBAAmB,OAAO;EAG1B,YAAY,KAAK,yBAAyB;;cAOxC,uEAAa,WAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { C as PG_TIMETZ_CODEC_ID, D as PG_VARCHAR_CODEC_ID, E as PG_VARBIT_CODEC_ID, S as PG_TIMESTAMP_CODEC_ID, T as PG_UUID_CODEC_ID, _ as PG_JSON_CODEC_ID, a as PG_DATE_CODEC_ID, b as PG_TEXT_CODEC_ID, c as PG_FLOAT8_CODEC_ID, d as PG_INT2_CODEC_ID, f as PG_INT4_CODEC_ID, g as PG_JSONB_CODEC_ID, h as PG_INT_CODEC_ID, i as PG_CHAR_CODEC_ID, l as PG_FLOAT_CODEC_ID, m as PG_INTERVAL_CODEC_ID, n as PG_BOOL_CODEC_ID, o as PG_ENUM_CODEC_ID, p as PG_INT8_CODEC_ID, r as PG_BYTEA_CODEC_ID, s as PG_FLOAT4_CODEC_ID, t as PG_BIT_CODEC_ID, u as PG_INET_CODEC_ID, v as PG_NUMERIC_CODEC_ID, w as PG_TIME_CODEC_ID, x as PG_TIMESTAMPTZ_CODEC_ID, y as PG_TEXT_ARRAY_CODEC_ID } from "./codec-ids-D3G8K0YM.mjs";
|
|
2
|
+
import { n as postgresError } from "./errors-DBSNx7EJ.mjs";
|
|
2
3
|
import "./namespace-ids-xtp_ZY86.mjs";
|
|
3
4
|
import { t as PostgresNativeEnum } from "./postgres-native-enum-BwVNf0Ku.mjs";
|
|
4
5
|
import { SqlCharCodec, SqlFloatCodec, SqlIntCodec, SqlVarcharCodec, sqlCharDescriptor, sqlFloatDescriptor, sqlIntDescriptor, sqlTextDescriptor, sqlTimestampDescriptor, sqlVarcharDescriptor } from "@prisma-next/sql-relational-core/ast";
|
|
@@ -10,13 +11,21 @@ import { type } from "arktype";
|
|
|
10
11
|
function renderLength(typeName, typeParams) {
|
|
11
12
|
const length = typeParams["length"];
|
|
12
13
|
if (length === void 0) return;
|
|
13
|
-
if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length)) throw
|
|
14
|
+
if (typeof length !== "number" || !Number.isFinite(length) || !Number.isInteger(length)) throw postgresError("RUNTIME.TYPE_PARAMS_INVALID", `renderOutputType: expected integer "length" in typeParams for ${typeName}, got ${String(length)}`, { meta: {
|
|
15
|
+
nativeType: typeName,
|
|
16
|
+
param: "length",
|
|
17
|
+
received: String(length)
|
|
18
|
+
} });
|
|
14
19
|
return `${typeName}<${length}>`;
|
|
15
20
|
}
|
|
16
21
|
function renderPrecision(typeName, typeParams) {
|
|
17
22
|
const precision = typeParams["precision"];
|
|
18
23
|
if (precision === void 0) return typeName;
|
|
19
|
-
if (typeof precision !== "number" || !Number.isFinite(precision) || !Number.isInteger(precision)) throw
|
|
24
|
+
if (typeof precision !== "number" || !Number.isFinite(precision) || !Number.isInteger(precision)) throw postgresError("RUNTIME.TYPE_PARAMS_INVALID", `renderOutputType: expected integer "precision" in typeParams for ${typeName}, got ${String(precision)}`, { meta: {
|
|
25
|
+
nativeType: typeName,
|
|
26
|
+
param: "precision",
|
|
27
|
+
received: String(precision)
|
|
28
|
+
} });
|
|
20
29
|
return `${typeName}<${precision}>`;
|
|
21
30
|
}
|
|
22
31
|
const pgNumericDecode = (wire) => {
|
|
@@ -26,28 +35,54 @@ const pgNumericDecode = (wire) => {
|
|
|
26
35
|
const pgNumericRenderOutputType = (typeParams) => {
|
|
27
36
|
const precision = typeParams.precision;
|
|
28
37
|
if (precision === void 0) return void 0;
|
|
29
|
-
if (typeof precision !== "number" || !Number.isFinite(precision) || !Number.isInteger(precision)) throw
|
|
38
|
+
if (typeof precision !== "number" || !Number.isFinite(precision) || !Number.isInteger(precision)) throw postgresError("RUNTIME.TYPE_PARAMS_INVALID", `renderOutputType: expected integer "precision" in typeParams for Numeric, got ${String(precision)}`, { meta: {
|
|
39
|
+
nativeType: "Numeric",
|
|
40
|
+
param: "precision",
|
|
41
|
+
received: String(precision)
|
|
42
|
+
} });
|
|
30
43
|
const scale = typeParams.scale;
|
|
31
44
|
if (scale === void 0) return `Numeric<${precision}>`;
|
|
32
|
-
if (typeof scale !== "number" || !Number.isFinite(scale) || !Number.isInteger(scale)) throw
|
|
45
|
+
if (typeof scale !== "number" || !Number.isFinite(scale) || !Number.isInteger(scale)) throw postgresError("RUNTIME.TYPE_PARAMS_INVALID", `renderOutputType: expected integer "scale" in typeParams for Numeric, got ${String(scale)}`, { meta: {
|
|
46
|
+
nativeType: "Numeric",
|
|
47
|
+
param: "scale",
|
|
48
|
+
received: String(scale)
|
|
49
|
+
} });
|
|
33
50
|
return `Numeric<${precision}, ${scale}>`;
|
|
34
51
|
};
|
|
35
52
|
const ISO_8601_TIMESTAMP = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?$/;
|
|
36
53
|
const ISO_8601_TIMESTAMPTZ = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
37
54
|
const pgTimestampEncodeJson = (value) => value.toISOString().slice(0, -1);
|
|
38
55
|
const pgTimestampDecodeJson = (json) => {
|
|
39
|
-
if (typeof json !== "string") throw
|
|
40
|
-
|
|
56
|
+
if (typeof json !== "string") throw postgresError("RUNTIME.DECODE_FAILED", `Expected ISO date string for pg/timestamp@1, got ${typeof json}`, { meta: {
|
|
57
|
+
codecId: "pg/timestamp@1",
|
|
58
|
+
received: typeof json
|
|
59
|
+
} });
|
|
60
|
+
if (!ISO_8601_TIMESTAMP.test(json)) throw postgresError("RUNTIME.DECODE_FAILED", `Invalid ISO date string for pg/timestamp@1: ${json}`, { meta: {
|
|
61
|
+
codecId: "pg/timestamp@1",
|
|
62
|
+
received: json
|
|
63
|
+
} });
|
|
41
64
|
const date = /* @__PURE__ */ new Date(`${json}Z`);
|
|
42
|
-
if (Number.isNaN(date.getTime())) throw
|
|
65
|
+
if (Number.isNaN(date.getTime())) throw postgresError("RUNTIME.DECODE_FAILED", `Invalid ISO date string for pg/timestamp@1: ${json}`, { meta: {
|
|
66
|
+
codecId: "pg/timestamp@1",
|
|
67
|
+
received: json
|
|
68
|
+
} });
|
|
43
69
|
return date;
|
|
44
70
|
};
|
|
45
71
|
const pgTimestamptzEncodeJson = (value) => value.toISOString().replace(/Z$/, "+00:00");
|
|
46
72
|
const pgTimestamptzDecodeJson = (json) => {
|
|
47
|
-
if (typeof json !== "string") throw
|
|
48
|
-
|
|
73
|
+
if (typeof json !== "string") throw postgresError("RUNTIME.DECODE_FAILED", `Expected ISO date string for pg/timestamptz@1, got ${typeof json}`, { meta: {
|
|
74
|
+
codecId: "pg/timestamptz@1",
|
|
75
|
+
received: typeof json
|
|
76
|
+
} });
|
|
77
|
+
if (!ISO_8601_TIMESTAMPTZ.test(json)) throw postgresError("RUNTIME.DECODE_FAILED", `Invalid ISO date string for pg/timestamptz@1: ${json}`, { meta: {
|
|
78
|
+
codecId: "pg/timestamptz@1",
|
|
79
|
+
received: json
|
|
80
|
+
} });
|
|
49
81
|
const date = new Date(json);
|
|
50
|
-
if (Number.isNaN(date.getTime())) throw
|
|
82
|
+
if (Number.isNaN(date.getTime())) throw postgresError("RUNTIME.DECODE_FAILED", `Invalid ISO date string for pg/timestamptz@1: ${json}`, { meta: {
|
|
83
|
+
codecId: "pg/timestamptz@1",
|
|
84
|
+
received: json
|
|
85
|
+
} });
|
|
51
86
|
return date;
|
|
52
87
|
};
|
|
53
88
|
const ISO_8601_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
@@ -77,15 +112,24 @@ const pgDateEncode = (value) => formatDateOnly(value.getUTCFullYear(), value.get
|
|
|
77
112
|
const pgDateDecode = (wire) => new Date(Date.UTC(wire.getFullYear(), wire.getMonth(), wire.getDate()));
|
|
78
113
|
const pgDateEncodeJson = (value) => pgDateEncode(value);
|
|
79
114
|
const pgDateDecodeJson = (json) => {
|
|
80
|
-
if (typeof json !== "string") throw
|
|
115
|
+
if (typeof json !== "string") throw postgresError("RUNTIME.DECODE_FAILED", `Expected date string for pg/date@1, got ${typeof json}`, { meta: {
|
|
116
|
+
codecId: "pg/date@1",
|
|
117
|
+
received: typeof json
|
|
118
|
+
} });
|
|
81
119
|
const match = ISO_8601_DATE.exec(json);
|
|
82
|
-
if (!match) throw
|
|
120
|
+
if (!match) throw postgresError("RUNTIME.DECODE_FAILED", `Invalid date string for pg/date@1: ${json}`, { meta: {
|
|
121
|
+
codecId: "pg/date@1",
|
|
122
|
+
received: json
|
|
123
|
+
} });
|
|
83
124
|
const [, yearText, monthText, dayText] = match;
|
|
84
125
|
const year = Number(yearText);
|
|
85
126
|
const month = Number(monthText) - 1;
|
|
86
127
|
const day = Number(dayText);
|
|
87
128
|
const date = new Date(Date.UTC(year, month, day));
|
|
88
|
-
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) throw
|
|
129
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) throw postgresError("RUNTIME.DECODE_FAILED", `Invalid date string for pg/date@1: ${json}`, { meta: {
|
|
130
|
+
codecId: "pg/date@1",
|
|
131
|
+
received: json
|
|
132
|
+
} });
|
|
89
133
|
return date;
|
|
90
134
|
};
|
|
91
135
|
const pgIntervalDecode = (wire) => {
|
|
@@ -94,13 +138,19 @@ const pgIntervalDecode = (wire) => {
|
|
|
94
138
|
};
|
|
95
139
|
const pgByteaEncodeJson = (value) => `\\x${Buffer.from(value).toString("hex")}`;
|
|
96
140
|
const pgByteaDecodeJson = (value) => {
|
|
97
|
-
if (typeof value !== "string" || !value.startsWith("\\x")) throw
|
|
141
|
+
if (typeof value !== "string" || !value.startsWith("\\x")) throw postgresError("RUNTIME.DECODE_FAILED", `Expected Postgres bytea hex text to start with "\\x"`, { meta: { codecId: "pg/bytea@1" } });
|
|
98
142
|
const hex = value.slice(2);
|
|
99
|
-
if (hex.length % 2 !== 0) throw
|
|
143
|
+
if (hex.length % 2 !== 0) throw postgresError("RUNTIME.DECODE_FAILED", `Invalid Postgres bytea hex text length: ${hex.length}`, { meta: {
|
|
144
|
+
codecId: "pg/bytea@1",
|
|
145
|
+
received: hex.length
|
|
146
|
+
} });
|
|
100
147
|
const bytes = new Uint8Array(hex.length / 2);
|
|
101
148
|
for (let offset = 0; offset < hex.length; offset += 2) {
|
|
102
149
|
const pair = hex.slice(offset, offset + 2);
|
|
103
|
-
if (!/^[0-9a-fA-F]{2}$/.test(pair)) throw
|
|
150
|
+
if (!/^[0-9a-fA-F]{2}$/.test(pair)) throw postgresError("RUNTIME.DECODE_FAILED", `Invalid Postgres bytea hex pair "${pair}" at offset ${offset}`, { meta: {
|
|
151
|
+
codecId: "pg/bytea@1",
|
|
152
|
+
received: pair
|
|
153
|
+
} });
|
|
104
154
|
bytes[offset / 2] = Number.parseInt(pair, 16);
|
|
105
155
|
}
|
|
106
156
|
return bytes;
|
|
@@ -200,10 +250,14 @@ var PgEnumCodec = class extends CodecImpl {
|
|
|
200
250
|
return blindCast(json);
|
|
201
251
|
}
|
|
202
252
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
253
|
+
/**
|
|
254
|
+
* Narrows codec `typeParams` to {@link PgEnumParams} — the shape that binds a
|
|
255
|
+
* column to a named database type (a native enum's `CREATE TYPE` name).
|
|
256
|
+
*/
|
|
257
|
+
function isPgEnumParams(value) {
|
|
258
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && "typeName" in value && typeof value.typeName === "string";
|
|
206
259
|
}
|
|
260
|
+
const pgEnumParamsSchema = type({ typeName: "string" });
|
|
207
261
|
var PgEnumDescriptor = class extends CodecDescriptorImpl {
|
|
208
262
|
codecId = PG_ENUM_CODEC_ID;
|
|
209
263
|
traits = [
|
|
@@ -218,9 +272,7 @@ var PgEnumDescriptor = class extends CodecDescriptorImpl {
|
|
|
218
272
|
return renderTsLiteral(value);
|
|
219
273
|
}
|
|
220
274
|
metaFor(typeParams) {
|
|
221
|
-
|
|
222
|
-
const typeName = typeParams["typeName"];
|
|
223
|
-
return typeof typeName === "string" ? { db: { sql: { postgres: { nativeType: typeName } } } } : this.meta;
|
|
275
|
+
return isPgEnumParams(typeParams) ? { db: { sql: { postgres: { nativeType: typeParams.typeName } } } } : this.meta;
|
|
224
276
|
}
|
|
225
277
|
factory(_params) {
|
|
226
278
|
return () => new PgEnumCodec(this);
|
|
@@ -523,11 +575,17 @@ var PgNumericCodec = class extends CodecImpl {
|
|
|
523
575
|
}
|
|
524
576
|
encodeJson(value) {
|
|
525
577
|
const number = Number(value);
|
|
526
|
-
if (!Number.isFinite(number)) throw
|
|
578
|
+
if (!Number.isFinite(number)) throw postgresError("RUNTIME.ENCODE_FAILED", "pg/numeric@1 database JSON value must be a finite number", { meta: {
|
|
579
|
+
codecId: "pg/numeric@1",
|
|
580
|
+
received: value
|
|
581
|
+
} });
|
|
527
582
|
return number;
|
|
528
583
|
}
|
|
529
584
|
decodeJson(json) {
|
|
530
|
-
if (typeof json !== "number") throw
|
|
585
|
+
if (typeof json !== "number") throw postgresError("RUNTIME.DECODE_FAILED", "pg/numeric@1 database JSON value must be a number", { meta: {
|
|
586
|
+
codecId: "pg/numeric@1",
|
|
587
|
+
received: typeof json
|
|
588
|
+
} });
|
|
531
589
|
return pgNumericDecode(json);
|
|
532
590
|
}
|
|
533
591
|
};
|
|
@@ -1022,6 +1080,6 @@ const codecDescriptors = [
|
|
|
1022
1080
|
pgTextArrayDescriptor
|
|
1023
1081
|
];
|
|
1024
1082
|
//#endregion
|
|
1025
|
-
export {
|
|
1083
|
+
export { pgTimestamptzColumn as C, pgVarcharColumn as D, pgVarbitColumn as E, postgresQualifyColumnType as O, pgTimestampColumn as S, pgUuidColumn as T, pgJsonColumn as _, pgCharColumn as a, pgTextColumn as b, pgFloat4Column as c, pgInetColumn as d, pgInt2Column as f, pgIntervalColumn as g, pgIntColumn as h, pgBoolColumn as i, pgFloat8Column as l, pgInt8Column as m, isPgEnumParams as n, pgDateColumn as o, pgInt4Column as p, pgBitColumn as r, pgEnumDescriptor as s, codecDescriptors as t, pgFloatColumn as u, pgJsonbColumn as v, pgTimetzColumn as w, pgTimeColumn as x, pgNumericColumn as y };
|
|
1026
1084
|
|
|
1027
|
-
//# sourceMappingURL=codecs-
|
|
1085
|
+
//# sourceMappingURL=codecs-Deand7sy.mjs.map
|