@prisma-next/target-postgres 0.14.0-dev.80 → 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-Bi9aa8zG.mjs → authoring-ChmUI_tC.mjs} +148 -48
- package/dist/authoring-ChmUI_tC.mjs.map +1 -0
- package/dist/{canonicalize-CAbXtVtB.d.mts → canonicalize-D1F4vUnP.d.mts} +13 -2
- package/dist/canonicalize-D1F4vUnP.d.mts.map +1 -0
- package/dist/contract-free.d.mts +1 -1
- package/dist/contract-free.mjs +2 -2
- package/dist/{control-policy-5LE2kwfb.mjs → control-policy-BfQLCrha.mjs} +4 -4
- package/dist/{control-policy-5LE2kwfb.mjs.map → control-policy-BfQLCrha.mjs.map} +1 -1
- package/dist/control.mjs +4 -4
- package/dist/{ddl-BQzITB_e.mjs → ddl-eBZav_MS.mjs} +2 -2
- package/dist/{ddl-BQzITB_e.mjs.map → ddl-eBZav_MS.mjs.map} +1 -1
- package/dist/ddl.d.mts +2 -2
- package/dist/{descriptor-meta-DzL6vXAz.mjs → descriptor-meta-DAwRBZpA.mjs} +5 -4
- package/dist/descriptor-meta-DAwRBZpA.mjs.map +1 -0
- package/dist/{diff-database-schema-DULhiCNM.mjs → diff-database-schema-jsEOfSYT.mjs} +4 -4
- package/dist/{diff-database-schema-DULhiCNM.mjs.map → diff-database-schema-jsEOfSYT.mjs.map} +1 -1
- package/dist/diff-database-schema.mjs +1 -1
- package/dist/issue-planner.mjs +1 -1
- package/dist/migration.mjs +2 -2
- package/dist/{nodes-Bc2N3tMy.d.mts → nodes-Dv5eCSq9.d.mts} +2 -2
- package/dist/{nodes-Bc2N3tMy.d.mts.map → nodes-Dv5eCSq9.d.mts.map} +1 -1
- package/dist/{op-factory-call-D6yu-PlS.mjs → op-factory-call-Dwsb1xzl.mjs} +3 -3
- package/dist/{op-factory-call-D6yu-PlS.mjs.map → op-factory-call-Dwsb1xzl.mjs.map} +1 -1
- package/dist/op-factory-call.mjs +1 -1
- package/dist/pack.d.mts +21 -0
- package/dist/pack.d.mts.map +1 -1
- package/dist/pack.mjs +1 -1
- package/dist/{planner-DwDxdYxi.mjs → planner-ChCtpEGe.mjs} +8 -8
- package/dist/{planner-DwDxdYxi.mjs.map → planner-ChCtpEGe.mjs.map} +1 -1
- package/dist/{planner-produced-postgres-migration-BGPpq56_.mjs → planner-produced-postgres-migration-Bb16yHNX.mjs} +2 -2
- package/dist/{planner-produced-postgres-migration-BGPpq56_.mjs.map → planner-produced-postgres-migration-Bb16yHNX.mjs.map} +1 -1
- package/dist/planner-produced-postgres-migration.mjs +1 -1
- package/dist/{planner-sql-checks-CDXn2uaS.mjs → planner-sql-checks-Cx0ATsPc.mjs} +2 -2
- package/dist/{planner-sql-checks-CDXn2uaS.mjs.map → planner-sql-checks-Cx0ATsPc.mjs.map} +1 -1
- package/dist/planner-sql-checks.mjs +1 -1
- package/dist/planner.mjs +2 -2
- package/dist/{postgres-contract-view-C3LPCLP_.mjs → postgres-contract-view-BiDhl5Ez.mjs} +3 -3
- package/dist/{postgres-contract-view-C3LPCLP_.mjs.map → postgres-contract-view-BiDhl5Ez.mjs.map} +1 -1
- package/dist/{postgres-migration-et1td40f.mjs → postgres-migration-Cj5Tpj1a.mjs} +3 -3
- package/dist/{postgres-migration-et1td40f.mjs.map → postgres-migration-Cj5Tpj1a.mjs.map} +1 -1
- package/dist/{postgres-schema-DYATroNx.mjs → postgres-schema-ChBj22nX.mjs} +2 -2
- package/dist/{postgres-schema-DYATroNx.mjs.map → postgres-schema-ChBj22nX.mjs.map} +1 -1
- package/dist/{resolve-ddl-schema-DpGte50u.mjs → resolve-ddl-schema-BCSMHFwl.mjs} +2 -2
- package/dist/{resolve-ddl-schema-DpGte50u.mjs.map → resolve-ddl-schema-BCSMHFwl.mjs.map} +1 -1
- package/dist/rls-canonicalize.d.mts +9 -2
- package/dist/rls-canonicalize.d.mts.map +1 -1
- package/dist/rls-canonicalize.mjs +2 -2
- package/dist/runtime.mjs +1 -1
- package/dist/schema-ir-annotations.mjs +1 -1
- package/dist/types.mjs +1 -1
- package/dist/{wire-name-rHHtr1h0.mjs → wire-name-DbQ9-2RC.mjs} +31 -2
- package/dist/wire-name-DbQ9-2RC.mjs.map +1 -0
- package/package.json +20 -20
- package/src/core/authoring.ts +253 -36
- package/src/core/descriptor-meta.ts +2 -0
- package/src/core/rls/canonicalize.ts +17 -0
- package/src/exports/rls-canonicalize.ts +6 -1
- package/dist/authoring-Bi9aa8zG.mjs.map +0 -1
- package/dist/canonicalize-CAbXtVtB.d.mts.map +0 -1
- package/dist/descriptor-meta-DzL6vXAz.mjs.map +0 -1
- package/dist/wire-name-rHHtr1h0.mjs.map +0 -1
package/src/core/authoring.ts
CHANGED
|
@@ -12,7 +12,15 @@ import type {
|
|
|
12
12
|
} from '@prisma-next/framework-components/authoring';
|
|
13
13
|
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
14
14
|
import { modelAttribute } from '@prisma-next/psl-parser';
|
|
15
|
+
import type {
|
|
16
|
+
EntityHandleLoweringInput,
|
|
17
|
+
LoweredPackEntity,
|
|
18
|
+
ResolvedEntityHandleRef,
|
|
19
|
+
ResolvedPslModelRefs,
|
|
20
|
+
} from '@prisma-next/sql-contract/entity-handle-lowering-hook';
|
|
15
21
|
import type { SqlValueSetDerivingEntityTypeOutput } from '@prisma-next/sql-contract/value-set-derivation-hook';
|
|
22
|
+
import { assertDefined } from '@prisma-next/utils/assertions';
|
|
23
|
+
import { blindCast } from '@prisma-next/utils/casts';
|
|
16
24
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
17
25
|
import { PG_ENUM_CODEC_ID } from './codec-ids';
|
|
18
26
|
import { PostgresNativeEnum } from './postgres-native-enum';
|
|
@@ -25,7 +33,11 @@ import {
|
|
|
25
33
|
PostgresRlsPolicySchema,
|
|
26
34
|
PostgresRoleSchema,
|
|
27
35
|
} from './postgres-validators';
|
|
28
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
computeContentHash,
|
|
38
|
+
normalizePredicate,
|
|
39
|
+
POLICY_OPERATION_PREDICATES,
|
|
40
|
+
} from './rls/canonicalize';
|
|
29
41
|
import { formatRlsPolicyWireName } from './rls/wire-name';
|
|
30
42
|
|
|
31
43
|
/**
|
|
@@ -50,6 +62,13 @@ export const postgresAuthoringTypes = {
|
|
|
50
62
|
|
|
51
63
|
export interface RlsPolicyExtensionBlock extends PslExtensionBlock {
|
|
52
64
|
readonly namespaceId: string;
|
|
65
|
+
/**
|
|
66
|
+
* Model refs the family interpreter resolved from the block's descriptor-
|
|
67
|
+
* declared `refKind: 'model'` parameters before invoking this factory
|
|
68
|
+
* (keyed by parameter name). An unresolved required ref is the
|
|
69
|
+
* interpreter's diagnostic; the factory is never called with one missing.
|
|
70
|
+
*/
|
|
71
|
+
readonly resolvedModelRefs?: ResolvedPslModelRefs;
|
|
53
72
|
}
|
|
54
73
|
|
|
55
74
|
/** A parsed `role` block annotated with its lexical namespace id by the interpreter. */
|
|
@@ -70,27 +89,6 @@ const POLICY_KEYWORD_OPERATION: Readonly<Record<string, RlsPolicyOperation>> = {
|
|
|
70
89
|
policy_all: 'all',
|
|
71
90
|
};
|
|
72
91
|
|
|
73
|
-
/**
|
|
74
|
-
* Which predicate each RLS operation admits, mirroring Postgres: SELECT and
|
|
75
|
-
* DELETE decide row visibility/eligibility with `USING` only; INSERT validates
|
|
76
|
-
* the new row with `WITH CHECK` only; UPDATE and ALL take both. A predicate
|
|
77
|
-
* outside this set is a load-time error (see {@link lowerRlsPolicyFromBlock}).
|
|
78
|
-
*/
|
|
79
|
-
const POLICY_OPERATION_PREDICATES: Readonly<
|
|
80
|
-
Record<RlsPolicyOperation, { readonly using: boolean; readonly withCheck: boolean }>
|
|
81
|
-
> = {
|
|
82
|
-
select: { using: true, withCheck: false },
|
|
83
|
-
insert: { using: false, withCheck: true },
|
|
84
|
-
update: { using: true, withCheck: true },
|
|
85
|
-
delete: { using: true, withCheck: false },
|
|
86
|
-
all: { using: true, withCheck: true },
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
function readRefParam(block: PslExtensionBlock, key: string): string | undefined {
|
|
90
|
-
const param = block.parameters[key];
|
|
91
|
-
return param?.kind === 'ref' ? param.identifier : undefined;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
92
|
function readValueParam(block: PslExtensionBlock, key: string): string | undefined {
|
|
95
93
|
const param = block.parameters[key];
|
|
96
94
|
return param?.kind === 'value' ? param.raw : undefined;
|
|
@@ -135,14 +133,61 @@ function unwrapQuotedString(raw: string): string {
|
|
|
135
133
|
return result;
|
|
136
134
|
}
|
|
137
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Assembles a {@link PostgresRlsPolicy} from lowered inputs: normalizes the
|
|
138
|
+
* predicates, computes the content-hash wire name, and constructs the frozen
|
|
139
|
+
* entity. The single hash-assembly body shared by the PSL block lowering
|
|
140
|
+
* ({@link lowerRlsPolicyFromBlock}) and the TS entity-handle lowering
|
|
141
|
+
* ({@link postgresLowerEntityHandles}) so the two surfaces cannot drift.
|
|
142
|
+
*/
|
|
143
|
+
function buildRlsPolicyEntity(input: {
|
|
144
|
+
readonly prefix: string;
|
|
145
|
+
readonly tableName: string;
|
|
146
|
+
readonly namespaceId: string;
|
|
147
|
+
readonly operation: RlsPolicyOperation;
|
|
148
|
+
readonly roles: readonly string[];
|
|
149
|
+
readonly using?: string;
|
|
150
|
+
readonly withCheck?: string;
|
|
151
|
+
}): PostgresRlsPolicy {
|
|
152
|
+
const wireHash = computeContentHash({
|
|
153
|
+
...ifDefined('using', input.using !== undefined ? normalizePredicate(input.using) : undefined),
|
|
154
|
+
...ifDefined(
|
|
155
|
+
'withCheck',
|
|
156
|
+
input.withCheck !== undefined ? normalizePredicate(input.withCheck) : undefined,
|
|
157
|
+
),
|
|
158
|
+
roles: input.roles,
|
|
159
|
+
operation: input.operation,
|
|
160
|
+
permissive: true,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return new PostgresRlsPolicy({
|
|
164
|
+
name: formatRlsPolicyWireName(input.prefix, wireHash),
|
|
165
|
+
prefix: input.prefix,
|
|
166
|
+
tableName: input.tableName,
|
|
167
|
+
namespaceId: input.namespaceId,
|
|
168
|
+
operation: input.operation,
|
|
169
|
+
roles: input.roles,
|
|
170
|
+
...ifDefined('using', input.using),
|
|
171
|
+
...ifDefined('withCheck', input.withCheck),
|
|
172
|
+
permissive: true,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
138
176
|
function lowerRlsPolicyFromBlock(
|
|
139
177
|
block: RlsPolicyExtensionBlock,
|
|
140
178
|
ctx: AuthoringEntityContext,
|
|
141
179
|
): PostgresRlsPolicy | undefined {
|
|
142
180
|
const prefix = block.name;
|
|
143
181
|
const operation = POLICY_KEYWORD_OPERATION[block.keyword] ?? 'select';
|
|
144
|
-
|
|
145
|
-
|
|
182
|
+
// The interpreter resolves the descriptor-declared `target` model ref to
|
|
183
|
+
// its storage table name before invoking this factory (an unresolved or
|
|
184
|
+
// missing required ref is the interpreter's diagnostic), so a lookup miss
|
|
185
|
+
// here is structurally impossible.
|
|
186
|
+
const tableName = block.resolvedModelRefs?.['target']?.tableName;
|
|
187
|
+
assertDefined(
|
|
188
|
+
tableName,
|
|
189
|
+
`lowerRlsPolicyFromBlock: policy "${block.name}" reached the factory without a resolved \`target\` ref; the interpreter resolves same-namespace model refs before invoking entity factories.`,
|
|
190
|
+
);
|
|
146
191
|
const roles = [...readListRefParams(block, 'roles')].sort();
|
|
147
192
|
|
|
148
193
|
const usingRaw = readValueParam(block, 'using');
|
|
@@ -169,17 +214,7 @@ function lowerRlsPolicyFromBlock(
|
|
|
169
214
|
const using = usingRaw !== undefined ? unwrapQuotedString(usingRaw) : undefined;
|
|
170
215
|
const withCheck = withCheckRaw !== undefined ? unwrapQuotedString(withCheckRaw) : undefined;
|
|
171
216
|
|
|
172
|
-
|
|
173
|
-
...ifDefined('using', using !== undefined ? normalizePredicate(using) : undefined),
|
|
174
|
-
...ifDefined('withCheck', withCheck !== undefined ? normalizePredicate(withCheck) : undefined),
|
|
175
|
-
roles,
|
|
176
|
-
operation,
|
|
177
|
-
permissive: true,
|
|
178
|
-
});
|
|
179
|
-
const wireName = formatRlsPolicyWireName(prefix, wireHash);
|
|
180
|
-
|
|
181
|
-
return new PostgresRlsPolicy({
|
|
182
|
-
name: wireName,
|
|
217
|
+
return buildRlsPolicyEntity({
|
|
183
218
|
prefix,
|
|
184
219
|
tableName,
|
|
185
220
|
namespaceId: block.namespaceId,
|
|
@@ -187,7 +222,6 @@ function lowerRlsPolicyFromBlock(
|
|
|
187
222
|
roles,
|
|
188
223
|
...ifDefined('using', using),
|
|
189
224
|
...ifDefined('withCheck', withCheck),
|
|
190
|
-
permissive: true,
|
|
191
225
|
});
|
|
192
226
|
}
|
|
193
227
|
|
|
@@ -635,3 +669,186 @@ export const postgresAuthoringFieldPresets = {
|
|
|
635
669
|
},
|
|
636
670
|
},
|
|
637
671
|
} as const satisfies AuthoringFieldNamespace;
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Postgres identifiers cap at 63 characters and the wire name appends a
|
|
675
|
+
* 9-character `_<8hex>` suffix, so the authored prefix is bounded at 54.
|
|
676
|
+
*/
|
|
677
|
+
const RLS_POLICY_PREFIX_MAX_LENGTH = 54;
|
|
678
|
+
|
|
679
|
+
interface RlsRoleHandleShape {
|
|
680
|
+
readonly entityKind: 'role';
|
|
681
|
+
readonly name: string;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
interface RlsPolicyHandleShape {
|
|
685
|
+
readonly entityKind: 'policy';
|
|
686
|
+
readonly operation: RlsPolicyOperation;
|
|
687
|
+
readonly name: string;
|
|
688
|
+
readonly roles: readonly { readonly name: string }[];
|
|
689
|
+
readonly using?: string;
|
|
690
|
+
readonly withCheck?: string;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
interface RlsTargetCoordinate {
|
|
694
|
+
readonly namespaceId: string;
|
|
695
|
+
readonly tableName: string;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Resolves an entity handle's `target` ref to a table coordinate of this
|
|
700
|
+
* contract, or throws the load-time diagnostic naming the handle: a
|
|
701
|
+
* cross-space target is rejected (you cannot CREATE POLICY on a table
|
|
702
|
+
* another space owns) and an unresolved target names the model.
|
|
703
|
+
*/
|
|
704
|
+
function requireLocalTarget(
|
|
705
|
+
refs: Readonly<Record<string, ResolvedEntityHandleRef>>,
|
|
706
|
+
subject: string,
|
|
707
|
+
): RlsTargetCoordinate {
|
|
708
|
+
const target = refs['target'];
|
|
709
|
+
if (target !== undefined && target.kind === 'resolved') {
|
|
710
|
+
return { namespaceId: target.namespaceId, tableName: target.tableName };
|
|
711
|
+
}
|
|
712
|
+
if (target !== undefined && target.kind === 'cross-space') {
|
|
713
|
+
throw new Error(
|
|
714
|
+
`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.`,
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
throw new Error(
|
|
718
|
+
`defineContract: ${subject} targets model "${target?.modelName ?? '<anonymous>'}", which is not in the contract's models. Add the model to \`models\`.`,
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* The SQL-family entity-handle batch lowering hook for the Postgres pack
|
|
724
|
+
* (`SqlEntityHandleLoweringContribution`). Receives every `entities` handle
|
|
725
|
+
* whose kind this pack registered — batch, so the cross-entity diagnostics
|
|
726
|
+
* (duplicate prefix, policy without rlsEnabled, duplicate role) can see
|
|
727
|
+
* sibling handles — and lowers them with the same keying and hash assembly
|
|
728
|
+
* as the PSL path: `policy` keyed by prefix (wire name via
|
|
729
|
+
* {@link buildRlsPolicyEntity}), `rls` keyed by table name, `role` keyed by
|
|
730
|
+
* name and filed under the default namespace (roles are declared
|
|
731
|
+
* contract-wide; PSL has no role block to set a precedent).
|
|
732
|
+
*/
|
|
733
|
+
export function postgresLowerEntityHandles(
|
|
734
|
+
input: EntityHandleLoweringInput,
|
|
735
|
+
): readonly LoweredPackEntity[] {
|
|
736
|
+
const enablements = new Map<
|
|
737
|
+
string,
|
|
738
|
+
{ coordinate: RlsTargetCoordinate; entity: PostgresRlsEnablement }
|
|
739
|
+
>();
|
|
740
|
+
const roles = new Map<string, PostgresRole>();
|
|
741
|
+
const policies: {
|
|
742
|
+
readonly handle: RlsPolicyHandleShape;
|
|
743
|
+
readonly refs: Readonly<Record<string, ResolvedEntityHandleRef>>;
|
|
744
|
+
}[] = [];
|
|
745
|
+
const coordinateKey = (coordinate: RlsTargetCoordinate): string =>
|
|
746
|
+
`${coordinate.namespaceId} ${coordinate.tableName}`;
|
|
747
|
+
|
|
748
|
+
for (const { handle, refs } of input.handles) {
|
|
749
|
+
switch (handle.entityKind) {
|
|
750
|
+
case 'rls': {
|
|
751
|
+
const coordinate = requireLocalTarget(refs, 'an rlsEnabled entry');
|
|
752
|
+
const key = coordinateKey(coordinate);
|
|
753
|
+
if (!enablements.has(key)) {
|
|
754
|
+
enablements.set(key, {
|
|
755
|
+
coordinate,
|
|
756
|
+
entity: new PostgresRlsEnablement({
|
|
757
|
+
tableName: coordinate.tableName,
|
|
758
|
+
namespaceId: coordinate.namespaceId,
|
|
759
|
+
}),
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
break;
|
|
763
|
+
}
|
|
764
|
+
case 'role': {
|
|
765
|
+
const roleHandle = blindCast<
|
|
766
|
+
RlsRoleHandleShape,
|
|
767
|
+
'role handles are constructed only by the postgres contract-builder role() constructor, which enforces this shape'
|
|
768
|
+
>(handle);
|
|
769
|
+
if (roles.has(roleHandle.name)) {
|
|
770
|
+
throw new Error(
|
|
771
|
+
`defineContract: role "${roleHandle.name}" is declared more than once in the entities list.`,
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
// Roles are cluster-scoped in Postgres, so they always land in the
|
|
775
|
+
// `__unbound__` namespace — identical to a PSL `role` block
|
|
776
|
+
// (`lowerRoleFromBlock`) and matching the `PostgresRole` class's own
|
|
777
|
+
// contract. The declaring surface (TS entities vs PSL) does not move
|
|
778
|
+
// the slot.
|
|
779
|
+
roles.set(
|
|
780
|
+
roleHandle.name,
|
|
781
|
+
new PostgresRole({ name: roleHandle.name, namespaceId: UNBOUND_NAMESPACE_ID }),
|
|
782
|
+
);
|
|
783
|
+
break;
|
|
784
|
+
}
|
|
785
|
+
case 'policy': {
|
|
786
|
+
const policyHandle = blindCast<
|
|
787
|
+
RlsPolicyHandleShape,
|
|
788
|
+
'policy handles are constructed only by the postgres contract-builder policy*() constructors, which enforce this shape'
|
|
789
|
+
>(handle);
|
|
790
|
+
policies.push({ handle: policyHandle, refs });
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
default:
|
|
794
|
+
throw new Error(
|
|
795
|
+
`defineContract: the postgres pack does not lower "${handle.entityKind}" handles from the entities list.`,
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
const rows: LoweredPackEntity[] = [];
|
|
801
|
+
const seenPrefixes = new Set<string>();
|
|
802
|
+
|
|
803
|
+
for (const { handle: policy, refs } of policies) {
|
|
804
|
+
const prefix = policy.name;
|
|
805
|
+
if (prefix.length > RLS_POLICY_PREFIX_MAX_LENGTH) {
|
|
806
|
+
throw new Error(
|
|
807
|
+
`defineContract: policy prefix "${prefix}" exceeds the ${RLS_POLICY_PREFIX_MAX_LENGTH}-character maximum (Postgres identifiers cap at 63 characters and the wire name appends a 9-character hash suffix).`,
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
const coordinate = requireLocalTarget(refs, `policy "${prefix}"`);
|
|
811
|
+
if (!enablements.has(coordinateKey(coordinate))) {
|
|
812
|
+
const target = refs['target'];
|
|
813
|
+
throw new Error(
|
|
814
|
+
`defineContract: policy "${prefix}" targets model "${target?.modelName ?? coordinate.tableName}", whose table is not RLS-enabled. Add rlsEnabled(<model>) to the entities list.`,
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
const prefixKey = `${coordinate.namespaceId} ${prefix}`;
|
|
818
|
+
if (seenPrefixes.has(prefixKey)) {
|
|
819
|
+
throw new Error(
|
|
820
|
+
`defineContract: policy prefix "${prefix}" is declared more than once in namespace "${coordinate.namespaceId}". Policy prefixes must be unique per namespace.`,
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
seenPrefixes.add(prefixKey);
|
|
824
|
+
|
|
825
|
+
const roleNames = [...new Set(policy.roles.map((roleHandle) => roleHandle.name))].sort();
|
|
826
|
+
rows.push({
|
|
827
|
+
namespaceId: coordinate.namespaceId,
|
|
828
|
+
entityKind: 'policy',
|
|
829
|
+
key: prefix,
|
|
830
|
+
entity: buildRlsPolicyEntity({
|
|
831
|
+
prefix,
|
|
832
|
+
tableName: coordinate.tableName,
|
|
833
|
+
namespaceId: coordinate.namespaceId,
|
|
834
|
+
operation: policy.operation,
|
|
835
|
+
roles: roleNames,
|
|
836
|
+
...ifDefined('using', policy.using),
|
|
837
|
+
...ifDefined('withCheck', policy.withCheck),
|
|
838
|
+
}),
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
for (const { coordinate, entity } of enablements.values()) {
|
|
843
|
+
rows.push({
|
|
844
|
+
namespaceId: coordinate.namespaceId,
|
|
845
|
+
entityKind: 'rls',
|
|
846
|
+
key: coordinate.tableName,
|
|
847
|
+
entity,
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
for (const [name, entity] of roles) {
|
|
851
|
+
rows.push({ namespaceId: UNBOUND_NAMESPACE_ID, entityKind: 'role', key: name, entity });
|
|
852
|
+
}
|
|
853
|
+
return rows;
|
|
854
|
+
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
postgresAuthoringModelAttributes,
|
|
6
6
|
postgresAuthoringPslBlockDescriptors,
|
|
7
7
|
postgresAuthoringTypes,
|
|
8
|
+
postgresLowerEntityHandles,
|
|
8
9
|
} from './authoring';
|
|
9
10
|
import { postgresQualifyColumnType } from './codecs';
|
|
10
11
|
import { postgresTargetDescriptorMetaRuntime } from './descriptor-meta-runtime';
|
|
@@ -22,6 +23,7 @@ const postgresTargetDescriptorMetaBase = {
|
|
|
22
23
|
modelAttributes: postgresAuthoringModelAttributes,
|
|
23
24
|
createNamespace: postgresCreateNamespace,
|
|
24
25
|
qualifyColumnType: postgresQualifyColumnType,
|
|
26
|
+
lowerEntityHandles: postgresLowerEntityHandles,
|
|
25
27
|
},
|
|
26
28
|
} as const;
|
|
27
29
|
|
|
@@ -2,6 +2,23 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
|
|
3
3
|
export type RlsPolicyOperation = 'select' | 'insert' | 'update' | 'delete' | 'all';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Which predicate each RLS operation admits, mirroring Postgres: SELECT and
|
|
7
|
+
* DELETE decide row visibility/eligibility with `USING` only; INSERT
|
|
8
|
+
* validates the new row with `WITH CHECK` only; UPDATE and ALL take either
|
|
9
|
+
* or both. Single-homed here so the PSL lowering and the TS handle
|
|
10
|
+
* constructors enforce the same matrix.
|
|
11
|
+
*/
|
|
12
|
+
export const POLICY_OPERATION_PREDICATES: Readonly<
|
|
13
|
+
Record<RlsPolicyOperation, { readonly using: boolean; readonly withCheck: boolean }>
|
|
14
|
+
> = {
|
|
15
|
+
select: { using: true, withCheck: false },
|
|
16
|
+
insert: { using: false, withCheck: true },
|
|
17
|
+
update: { using: true, withCheck: true },
|
|
18
|
+
delete: { using: true, withCheck: false },
|
|
19
|
+
all: { using: true, withCheck: true },
|
|
20
|
+
};
|
|
21
|
+
|
|
5
22
|
export interface ContentHashParts {
|
|
6
23
|
readonly using?: string;
|
|
7
24
|
readonly withCheck?: string;
|
|
@@ -2,6 +2,11 @@ export {
|
|
|
2
2
|
type ContentHashParts,
|
|
3
3
|
computeContentHash,
|
|
4
4
|
normalizePredicate,
|
|
5
|
+
POLICY_OPERATION_PREDICATES,
|
|
5
6
|
type RlsPolicyOperation,
|
|
6
7
|
} from '../core/rls/canonicalize';
|
|
7
|
-
export {
|
|
8
|
+
export {
|
|
9
|
+
formatRlsPolicyWireName,
|
|
10
|
+
parseRlsPolicyWireName,
|
|
11
|
+
type RlsPolicyWireName,
|
|
12
|
+
} from '../core/rls/wire-name';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authoring-Bi9aa8zG.mjs","names":[],"sources":["../src/core/authoring.ts"],"sourcesContent":["import { temporalAuthoringPresets } 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 { SqlValueSetDerivingEntityTypeOutput } from '@prisma-next/sql-contract/value-set-derivation-hook';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { PG_ENUM_CODEC_ID } from './codec-ids';\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, normalizePredicate } from './rls/canonicalize';\nimport { formatRlsPolicyWireName } from './rls/wire-name';\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\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\n/**\n * Which predicate each RLS operation admits, mirroring Postgres: SELECT and\n * DELETE decide row visibility/eligibility with `USING` only; INSERT validates\n * the new row with `WITH CHECK` only; UPDATE and ALL take both. A predicate\n * outside this set is a load-time error (see {@link lowerRlsPolicyFromBlock}).\n */\nconst 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\nfunction readRefParam(block: PslExtensionBlock, key: string): string | undefined {\n const param = block.parameters[key];\n return param?.kind === 'ref' ? param.identifier : undefined;\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\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 const targetModelName = readRefParam(block, 'target') ?? '';\n const tableName = targetModelName.charAt(0).toLowerCase() + targetModelName.slice(1);\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 const wireHash = computeContentHash({\n ...ifDefined('using', using !== undefined ? normalizePredicate(using) : undefined),\n ...ifDefined('withCheck', withCheck !== undefined ? normalizePredicate(withCheck) : undefined),\n roles,\n operation,\n permissive: true,\n });\n const wireName = formatRlsPolicyWireName(prefix, wireHash);\n\n return new PostgresRlsPolicy({\n name: wireName,\n prefix,\n tableName,\n namespaceId: block.namespaceId,\n operation,\n roles,\n ...ifDefined('using', using),\n ...ifDefined('withCheck', withCheck),\n permissive: true,\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: /* @__PURE__ */ temporalAuthoringPresets({\n codecId: 'pg/timestamptz@1',\n nativeType: 'timestamptz',\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"],"mappings":";;;;;;;;;;;;;;;;;AAsCA,MAAa,yBAAyB,EACpC,IAAI,EACF,MAAM;CACJ,MAAM;CACN,cAAc;EAAE,OAAO;EAAG,YAAY;CAAc;CACpD,QAAQ,EACN,SAAS,iBACX;AACF,EACF,EACF;;;;;;AAgBA,MAAM,2BAAyE;CAC7E,eAAe;CACf,eAAe;CACf,eAAe;CACf,eAAe;CACf,YAAY;AACd;;;;;;;AAQA,MAAM,8BAEF;CACF,QAAQ;EAAE,OAAO;EAAM,WAAW;CAAM;CACxC,QAAQ;EAAE,OAAO;EAAO,WAAW;CAAK;CACxC,QAAQ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B,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;CACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"canonicalize-CAbXtVtB.d.mts","names":[],"sources":["../src/core/rls/canonicalize.ts"],"mappings":";KAEY,kBAAA;AAAA,UAEK,gBAAA;EAAA,SACN,KAAA;EAAA,SACA,SAAA;EAAA,SACA,KAAA;EAAA,SACA,SAAA,EAAW,kBAAkB;EAAA,SAC7B,UAAA;AAAA;;;;;;;;;;AAAU;AAiBrB;;;;iBAAgB,kBAAA,CAAmB,GAAW;AAa9C;;;;AAA0D;;;;;AAA1D,iBAAgB,kBAAA,CAAmB,KAAuB,EAAhB,gBAAgB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor-meta-DzL6vXAz.mjs","names":[],"sources":["../src/core/descriptor-meta.ts"],"sourcesContent":["import type { CodecTypes } from '../exports/codec-types';\nimport {\n postgresAuthoringEntityTypes,\n postgresAuthoringFieldPresets,\n postgresAuthoringModelAttributes,\n postgresAuthoringPslBlockDescriptors,\n postgresAuthoringTypes,\n} from './authoring';\nimport { postgresQualifyColumnType } from './codecs';\nimport { postgresTargetDescriptorMetaRuntime } from './descriptor-meta-runtime';\nimport { DEFAULT_NAMESPACE_ID } from './namespace-ids';\nimport { postgresCreateNamespace } from './postgres-schema';\n\nconst postgresTargetDescriptorMetaBase = {\n ...postgresTargetDescriptorMetaRuntime,\n defaultNamespaceId: DEFAULT_NAMESPACE_ID,\n authoring: {\n type: postgresAuthoringTypes,\n field: postgresAuthoringFieldPresets,\n entityTypes: postgresAuthoringEntityTypes,\n pslBlockDescriptors: postgresAuthoringPslBlockDescriptors,\n modelAttributes: postgresAuthoringModelAttributes,\n createNamespace: postgresCreateNamespace,\n qualifyColumnType: postgresQualifyColumnType,\n },\n} as const;\n\nexport const postgresTargetDescriptorMeta: typeof postgresTargetDescriptorMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = postgresTargetDescriptorMetaBase;\n"],"mappings":";;;;;AA2BA,MAAa,+BAET;CAfF,GAAG;CACH,oBAAoB;CACpB,WAAW;EACT,MAAM;EACN,OAAO;EACP,aAAa;EACb,qBAAqB;EACrB,iBAAiB;EACjB,iBAAiB;EACjB,mBAAmB;CACrB;AAKE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wire-name-rHHtr1h0.mjs","names":[],"sources":["../src/core/rls/canonicalize.ts","../src/core/rls/wire-name.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\n\nexport type RlsPolicyOperation = 'select' | 'insert' | 'update' | 'delete' | 'all';\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 * Stabilizes an authored predicate for hashing: trim, and collapse runs of\n * internal whitespace to a single space.\n *\n * This is deliberately minimal. The content hash is the equivalence relation\n * for a policy, and the wire name (prefix + hash) is the only thing ever\n * compared — we never recompute the hash from an introspected policy body, so\n * there is no need to match Postgres's reprinted form. Minimal normalization\n * also protects the no-collision property: aggressive rewriting (lowercasing,\n * paren-stripping, cast-alias folding) risks collapsing two distinct predicates\n * onto one hash. Out-of-band alteration of a hashed policy is unsupported.\n *\n * The normalizer is a stability commitment: any change re-suffixes all wire names.\n */\nexport function normalizePredicate(sql: string): string {\n return sql.replace(/\\s+/g, ' ').trim();\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 * [normalize(using), normalize(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 = normalizePredicate(parts.using ?? '');\n const withCheck = normalizePredicate(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","export interface RlsPolicyWireName {\n /** The user-supplied part before the `_<8hex>` suffix. */\n readonly prefix: string;\n /** The 8-lowercase-hex content-hash suffix. */\n readonly hash: string;\n}\n\nconst WIRE_NAME_PATTERN = /^(.+)_([0-9a-f]{8})$/;\n\n/**\n * Assembles an RLS policy wire name from its user-supplied prefix and its\n * 8-hex content-hash suffix. This module owns the `<prefix>_<hash>` format\n * on both sides — construction here and parsing in\n * {@link parseRlsPolicyWireName} — so the two never drift.\n */\nexport function formatRlsPolicyWireName(prefix: string, hash: string): string {\n return `${prefix}_${hash}`;\n}\n\n/**\n * Splits an RLS policy wire name (`<prefix>_<8hex>`) into its prefix and\n * content-hash suffix. Returns `undefined` when the name does not follow the\n * wire-name shape (e.g. a policy created outside the toolchain) — callers\n * treat such names as all-prefix. Consumed by introspection (prefix\n * extraction) and by rename pairing (same hash, different prefix).\n */\nexport function parseRlsPolicyWireName(name: string): RlsPolicyWireName | undefined {\n const match = WIRE_NAME_PATTERN.exec(name);\n const prefix = match?.[1];\n const hash = match?.[2];\n if (prefix === undefined || hash === undefined) return undefined;\n return { prefix, hash };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,SAAgB,mBAAmB,KAAqB;CACtD,OAAO,IAAI,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;AACvC;;;;;;;;;;AAWA,SAAgB,mBAAmB,OAAiC;CAClE,MAAM,QAAQ,mBAAmB,MAAM,SAAS,EAAE;CAClD,MAAM,YAAY,mBAAmB,MAAM,aAAa,EAAE;CAC1D,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;;;ACxCA,MAAM,oBAAoB;;;;;;;AAQ1B,SAAgB,wBAAwB,QAAgB,MAAsB;CAC5E,OAAO,GAAG,OAAO,GAAG;AACtB;;;;;;;;AASA,SAAgB,uBAAuB,MAA6C;CAClF,MAAM,QAAQ,kBAAkB,KAAK,IAAI;CACzC,MAAM,SAAS,QAAQ;CACvB,MAAM,OAAO,QAAQ;CACrB,IAAI,WAAW,KAAA,KAAa,SAAS,KAAA,GAAW,OAAO,KAAA;CACvD,OAAO;EAAE;EAAQ;CAAK;AACxB"}
|