@prisma-next/target-postgres 0.14.0-dev.60 → 0.14.0-dev.61

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.
Files changed (71) hide show
  1. package/dist/{authoring-WkqG_MkU.mjs → authoring-BLkL4fFG.mjs} +147 -38
  2. package/dist/authoring-BLkL4fFG.mjs.map +1 -0
  3. package/dist/contract-free.mjs +2 -2
  4. package/dist/{control-policy-Co_13Hxa.mjs → control-policy-BpmChlAK.mjs} +27 -4
  5. package/dist/{control-policy-Co_13Hxa.mjs.map → control-policy-BpmChlAK.mjs.map} +1 -1
  6. package/dist/control.mjs +6 -5
  7. package/dist/control.mjs.map +1 -1
  8. package/dist/{ddl-B-krEXY1.mjs → ddl-BovUVFVi.mjs} +2 -2
  9. package/dist/{ddl-B-krEXY1.mjs.map → ddl-BovUVFVi.mjs.map} +1 -1
  10. package/dist/{descriptor-meta-BOcKPaLE.mjs → descriptor-meta-C1T4BXJ8.mjs} +3 -3
  11. package/dist/{descriptor-meta-BOcKPaLE.mjs.map → descriptor-meta-C1T4BXJ8.mjs.map} +1 -1
  12. package/dist/{diff-database-schema-BOsDnH64.mjs → diff-database-schema-RMwnSOnz.mjs} +46 -14
  13. package/dist/diff-database-schema-RMwnSOnz.mjs.map +1 -0
  14. package/dist/diff-database-schema.d.mts +4 -4
  15. package/dist/diff-database-schema.d.mts.map +1 -1
  16. package/dist/diff-database-schema.mjs +1 -1
  17. package/dist/issue-planner.mjs +1 -1
  18. package/dist/migration.mjs +2 -2
  19. package/dist/{op-factory-call-DxNNKUeZ.mjs → op-factory-call-CI00nS4z.mjs} +3 -3
  20. package/dist/{op-factory-call-DxNNKUeZ.mjs.map → op-factory-call-CI00nS4z.mjs.map} +1 -1
  21. package/dist/op-factory-call.mjs +1 -1
  22. package/dist/pack.d.mts +146 -3
  23. package/dist/pack.d.mts.map +1 -1
  24. package/dist/pack.mjs +1 -1
  25. package/dist/{planner-CNrc1Odu.mjs → planner-CAHZN1Ez.mjs} +8 -8
  26. package/dist/planner-CAHZN1Ez.mjs.map +1 -0
  27. package/dist/{planner-produced-postgres-migration-NI-oGKcw.mjs → planner-produced-postgres-migration-flkG4Y7n.mjs} +2 -2
  28. package/dist/{planner-produced-postgres-migration-NI-oGKcw.mjs.map → planner-produced-postgres-migration-flkG4Y7n.mjs.map} +1 -1
  29. package/dist/planner-produced-postgres-migration.mjs +1 -1
  30. package/dist/{planner-sql-checks-AXoxB1Jl.mjs → planner-sql-checks-C1-Kk3Eu.mjs} +2 -2
  31. package/dist/{planner-sql-checks-AXoxB1Jl.mjs.map → planner-sql-checks-C1-Kk3Eu.mjs.map} +1 -1
  32. package/dist/planner-sql-checks.mjs +1 -1
  33. package/dist/planner.d.mts +2 -2
  34. package/dist/planner.d.mts.map +1 -1
  35. package/dist/planner.mjs +2 -2
  36. package/dist/{postgres-contract-view-Dg-N7KA7.mjs → postgres-contract-view-DWLNQbdR.mjs} +3 -3
  37. package/dist/{postgres-contract-view-Dg-N7KA7.mjs.map → postgres-contract-view-DWLNQbdR.mjs.map} +1 -1
  38. package/dist/{postgres-database-schema-node-CfdTY-Qs.d.mts → postgres-database-schema-node-BVdOffjC.d.mts} +9 -6
  39. package/dist/{postgres-database-schema-node-CfdTY-Qs.d.mts.map → postgres-database-schema-node-BVdOffjC.d.mts.map} +1 -1
  40. package/dist/{postgres-migration-ChyRsWvE.mjs → postgres-migration-C92swCzd.mjs} +3 -3
  41. package/dist/{postgres-migration-ChyRsWvE.mjs.map → postgres-migration-C92swCzd.mjs.map} +1 -1
  42. package/dist/{postgres-role-schema-node-BiSTCTNg.mjs → postgres-role-schema-node-BmCboEa_.mjs} +10 -7
  43. package/dist/postgres-role-schema-node-BmCboEa_.mjs.map +1 -0
  44. package/dist/{postgres-schema-DTLA_aRi.mjs → postgres-schema-COEca21H.mjs} +20 -3
  45. package/dist/postgres-schema-COEca21H.mjs.map +1 -0
  46. package/dist/{postgres-schema-CU4gF6QZ.d.mts → postgres-schema-DsrtYp2v.d.mts} +13 -1
  47. package/dist/postgres-schema-DsrtYp2v.d.mts.map +1 -0
  48. package/dist/postgres-table-schema-node-9FCtCUz2.mjs.map +1 -1
  49. package/dist/{resolve-ddl-schema-Ca88Tg6W.mjs → resolve-ddl-schema-ZkKxt2Fm.mjs} +2 -2
  50. package/dist/{resolve-ddl-schema-Ca88Tg6W.mjs.map → resolve-ddl-schema-ZkKxt2Fm.mjs.map} +1 -1
  51. package/dist/runtime.mjs +1 -1
  52. package/dist/schema-ir-annotations.mjs +1 -1
  53. package/dist/types.d.mts +2 -2
  54. package/dist/types.mjs +2 -2
  55. package/package.json +20 -20
  56. package/src/core/authoring.ts +136 -25
  57. package/src/core/migrations/control-policy.ts +29 -0
  58. package/src/core/migrations/diff-database-schema.ts +47 -11
  59. package/src/core/migrations/planner.ts +5 -0
  60. package/src/core/postgres-role.ts +22 -0
  61. package/src/core/postgres-validators.ts +1 -0
  62. package/src/core/psl-infer/infer-psl-contract.ts +1 -0
  63. package/src/core/schema-ir/postgres-database-schema-node.ts +5 -4
  64. package/src/core/schema-ir/postgres-role-schema-node.ts +4 -2
  65. package/src/core/schema-ir/schema-node-kinds.ts +7 -0
  66. package/dist/authoring-WkqG_MkU.mjs.map +0 -1
  67. package/dist/diff-database-schema-BOsDnH64.mjs.map +0 -1
  68. package/dist/planner-CNrc1Odu.mjs.map +0 -1
  69. package/dist/postgres-role-schema-node-BiSTCTNg.mjs.map +0 -1
  70. package/dist/postgres-schema-CU4gF6QZ.d.mts.map +0 -1
  71. package/dist/postgres-schema-DTLA_aRi.mjs.map +0 -1
@@ -1,8 +1,9 @@
1
1
  import { a as PG_ENUM_CODEC_ID } from "./codec-ids-C_-Hj6bL.mjs";
2
2
  import { t as PostgresNativeEnum } from "./postgres-native-enum-xdiqmBf_.mjs";
3
- import { d as PostgresRlsEnablementSchema, f as PostgresRlsPolicySchema, g as PostgresRlsEnablement, h as PostgresRlsPolicy, m as PostgresRole, p as PostgresRoleSchema, u as PostgresNativeEnumSchema } from "./postgres-schema-DTLA_aRi.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-COEca21H.mjs";
4
4
  import { i as normalizePredicate, r as computeContentHash, t as formatRlsPolicyWireName } from "./wire-name-rHHtr1h0.mjs";
5
5
  import { temporalAuthoringPresets } from "@prisma-next/family-sql/control";
6
+ import { ifDefined } from "@prisma-next/utils/defined";
6
7
  import { modelAttribute } from "@prisma-next/psl-parser";
7
8
  //#region src/core/authoring.ts
8
9
  /**
@@ -21,6 +22,46 @@ const postgresAuthoringTypes = { pg: { enum: {
21
22
  },
22
23
  output: { codecId: PG_ENUM_CODEC_ID }
23
24
  } } };
25
+ /**
26
+ * Maps a `policy_<op>` keyword to the RLS operation it authors. The keyword
27
+ * IS the operation (per the project's rejection of a `policy { operation = … }`
28
+ * conditional block).
29
+ */
30
+ const POLICY_KEYWORD_OPERATION = {
31
+ policy_select: "select",
32
+ policy_insert: "insert",
33
+ policy_update: "update",
34
+ policy_delete: "delete",
35
+ policy_all: "all"
36
+ };
37
+ /**
38
+ * Which predicate each RLS operation admits, mirroring Postgres: SELECT and
39
+ * DELETE decide row visibility/eligibility with `USING` only; INSERT validates
40
+ * the new row with `WITH CHECK` only; UPDATE and ALL take both. A predicate
41
+ * outside this set is a load-time error (see {@link lowerRlsPolicyFromBlock}).
42
+ */
43
+ const POLICY_OPERATION_PREDICATES = {
44
+ select: {
45
+ using: true,
46
+ withCheck: false
47
+ },
48
+ insert: {
49
+ using: false,
50
+ withCheck: true
51
+ },
52
+ update: {
53
+ using: true,
54
+ withCheck: true
55
+ },
56
+ delete: {
57
+ using: true,
58
+ withCheck: false
59
+ },
60
+ all: {
61
+ using: true,
62
+ withCheck: true
63
+ }
64
+ };
24
65
  function readRefParam(block, key) {
25
66
  const param = block.parameters[key];
26
67
  return param?.kind === "ref" ? param.identifier : void 0;
@@ -61,25 +102,42 @@ function unwrapQuotedString(raw) {
61
102
  }
62
103
  return result;
63
104
  }
64
- function lowerRlsPolicyFromBlock(block, _ctx) {
105
+ function lowerRlsPolicyFromBlock(block, ctx) {
65
106
  const prefix = block.name;
107
+ const operation = POLICY_KEYWORD_OPERATION[block.keyword] ?? "select";
66
108
  const targetModelName = readRefParam(block, "target") ?? "";
67
109
  const tableName = targetModelName.charAt(0).toLowerCase() + targetModelName.slice(1);
68
110
  const roles = [...readListRefParams(block, "roles")].sort();
69
- const using = unwrapQuotedString(readValueParam(block, "using") ?? "");
111
+ const usingRaw = readValueParam(block, "using");
112
+ const withCheckRaw = readValueParam(block, "withCheck");
113
+ const support = POLICY_OPERATION_PREDICATES[operation];
114
+ const rejectPredicate = (predicate) => {
115
+ ctx.diagnostics?.push({
116
+ code: "PSL_RLS_PREDICATE_NOT_FOR_OPERATION",
117
+ 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"}.`,
118
+ sourceId: ctx.sourceId ?? "unknown",
119
+ span: block.parameters[predicate]?.span ?? block.span
120
+ });
121
+ };
122
+ if (usingRaw !== void 0 && !support.using) return rejectPredicate("using");
123
+ if (withCheckRaw !== void 0 && !support.withCheck) return rejectPredicate("withCheck");
124
+ const using = usingRaw !== void 0 ? unwrapQuotedString(usingRaw) : void 0;
125
+ const withCheck = withCheckRaw !== void 0 ? unwrapQuotedString(withCheckRaw) : void 0;
70
126
  return new PostgresRlsPolicy({
71
127
  name: formatRlsPolicyWireName(prefix, computeContentHash({
72
- using: normalizePredicate(using),
128
+ ...ifDefined("using", using !== void 0 ? normalizePredicate(using) : void 0),
129
+ ...ifDefined("withCheck", withCheck !== void 0 ? normalizePredicate(withCheck) : void 0),
73
130
  roles,
74
- operation: "select",
131
+ operation,
75
132
  permissive: true
76
133
  })),
77
134
  prefix,
78
135
  tableName,
79
136
  namespaceId: block.namespaceId,
80
- operation: "select",
137
+ operation,
81
138
  roles,
82
- using,
139
+ ...ifDefined("using", using),
140
+ ...ifDefined("withCheck", withCheck),
83
141
  permissive: true
84
142
  });
85
143
  }
@@ -224,13 +282,10 @@ const postgresAuthoringEntityTypes = {
224
282
  * the family pack instead.
225
283
  */
226
284
  /**
227
- * PSL block descriptor for `policy_select`.
228
- *
229
- * The parser learns the block shape from this descriptor; lowering from
230
- * `PslExtensionBlock` to `PostgresRlsPolicy` is wired in the PSL
231
- * interpreter (a later dispatch). The `discriminator` matches
232
- * `PostgresRlsPolicy.kind` so the parsed block node carries the same
233
- * discriminant as the IR class it will lower to.
285
+ * Shared parameter descriptors for the five `policy_<op>` PSL block
286
+ * keywords. All five share the `policy` discriminator — the parser
287
+ * dispatches by keyword (see the framework's PSL-block SPI), and every
288
+ * keyword's factory lowers to `PostgresRlsPolicy` via `lowerRlsPolicyFromBlock`.
234
289
  *
235
290
  * The `roles` list uses `scope:'cross-space'` because same-namespace
236
291
  * role ref resolution requires PSL namespace entries keyed by `refKind`
@@ -239,6 +294,29 @@ const postgresAuthoringEntityTypes = {
239
294
  * slice 4 (cross-space roles). Until then cross-space passes validation
240
295
  * unconditionally and the authored role names flow through unchanged.
241
296
  */
297
+ const policyTargetParam = {
298
+ kind: "ref",
299
+ refKind: "model",
300
+ scope: "same-namespace",
301
+ required: true
302
+ };
303
+ const policyRolesParam = {
304
+ kind: "list",
305
+ of: {
306
+ kind: "ref",
307
+ refKind: "role",
308
+ scope: "cross-space"
309
+ }
310
+ };
311
+ const policyPredicateParam = {
312
+ kind: "value",
313
+ codecId: "pg/text@1",
314
+ required: true
315
+ };
316
+ const policyRequiresRls = {
317
+ parameter: "target",
318
+ attribute: "rls"
319
+ };
242
320
  const postgresAuthoringPslBlockDescriptors = {
243
321
  policy_select: {
244
322
  kind: "pslBlock",
@@ -246,30 +324,61 @@ const postgresAuthoringPslBlockDescriptors = {
246
324
  discriminator: "policy",
247
325
  name: { required: true },
248
326
  parameters: {
249
- target: {
250
- kind: "ref",
251
- refKind: "model",
252
- scope: "same-namespace",
253
- required: true
254
- },
255
- roles: {
256
- kind: "list",
257
- of: {
258
- kind: "ref",
259
- refKind: "role",
260
- scope: "cross-space"
261
- }
262
- },
263
- using: {
264
- kind: "value",
265
- codecId: "pg/text@1",
266
- required: true
267
- }
327
+ target: policyTargetParam,
328
+ roles: policyRolesParam,
329
+ using: policyPredicateParam
268
330
  },
269
- requiresModelAttribute: {
270
- parameter: "target",
271
- attribute: "rls"
272
- }
331
+ requiresModelAttribute: policyRequiresRls
332
+ },
333
+ policy_delete: {
334
+ kind: "pslBlock",
335
+ keyword: "policy_delete",
336
+ discriminator: "policy",
337
+ name: { required: true },
338
+ parameters: {
339
+ target: policyTargetParam,
340
+ roles: policyRolesParam,
341
+ using: policyPredicateParam
342
+ },
343
+ requiresModelAttribute: policyRequiresRls
344
+ },
345
+ policy_insert: {
346
+ kind: "pslBlock",
347
+ keyword: "policy_insert",
348
+ discriminator: "policy",
349
+ name: { required: true },
350
+ parameters: {
351
+ target: policyTargetParam,
352
+ roles: policyRolesParam,
353
+ withCheck: policyPredicateParam
354
+ },
355
+ requiresModelAttribute: policyRequiresRls
356
+ },
357
+ policy_update: {
358
+ kind: "pslBlock",
359
+ keyword: "policy_update",
360
+ discriminator: "policy",
361
+ name: { required: true },
362
+ parameters: {
363
+ target: policyTargetParam,
364
+ roles: policyRolesParam,
365
+ using: policyPredicateParam,
366
+ withCheck: policyPredicateParam
367
+ },
368
+ requiresModelAttribute: policyRequiresRls
369
+ },
370
+ policy_all: {
371
+ kind: "pslBlock",
372
+ keyword: "policy_all",
373
+ discriminator: "policy",
374
+ name: { required: true },
375
+ parameters: {
376
+ target: policyTargetParam,
377
+ roles: policyRolesParam,
378
+ using: policyPredicateParam,
379
+ withCheck: policyPredicateParam
380
+ },
381
+ requiresModelAttribute: policyRequiresRls
273
382
  },
274
383
  /**
275
384
  * PSL block descriptor for `native_enum`.
@@ -416,4 +525,4 @@ const postgresAuthoringFieldPresets = {
416
525
  //#endregion
417
526
  export { postgresAuthoringTypes as a, postgresAuthoringPslBlockDescriptors as i, postgresAuthoringFieldPresets as n, postgresAuthoringModelAttributes as r, postgresAuthoringEntityTypes as t };
418
527
 
419
- //# sourceMappingURL=authoring-WkqG_MkU.mjs.map
528
+ //# sourceMappingURL=authoring-BLkL4fFG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authoring-BLkL4fFG.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 { 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, type PostgresRoleInput } 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/**\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\nexport const postgresAuthoringEntityTypes = {\n role: {\n kind: 'entity',\n discriminator: 'role',\n validatorSchema: PostgresRoleSchema,\n output: {\n factory: (input: PostgresRoleInput): PostgresRole => new PostgresRole(input),\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} 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 sat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,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;CACF;AACF"}
@@ -1,6 +1,6 @@
1
1
  import { _ as PG_TEXT_ARRAY_CODEC_ID, d as PG_INT8_CODEC_ID, m as PG_JSONB_CODEC_ID, u as PG_INT4_CODEC_ID, v as PG_TEXT_CODEC_ID, y as PG_TIMESTAMPTZ_CODEC_ID } from "./codec-ids-C_-Hj6bL.mjs";
2
- import { l as PostgresTableSource } from "./postgres-schema-DTLA_aRi.mjs";
3
- import { C as toRegclass, S as tablePrimaryKeyAst, _ as noNullValuesAst, a as createSchema, b as tableExistsAst, c as dropDefaultAction, d as columnExistsAst, f as columnNullabilityAst, g as indexExistsAst, h as extensionExistsAst, m as constraintExistsAst, o as createTable, p as columnTypeAst, r as alterTable, t as addColumnAction, u as columnDefaultAst, v as rlsEnabledAst, x as tableIsEmptyAst, y as rlsPolicyExistsAst } from "./ddl-B-krEXY1.mjs";
2
+ import { l as PostgresTableSource } from "./postgres-schema-COEca21H.mjs";
3
+ import { C as toRegclass, S as tablePrimaryKeyAst, _ as noNullValuesAst, a as createSchema, b as tableExistsAst, c as dropDefaultAction, d as columnExistsAst, f as columnNullabilityAst, g as indexExistsAst, h as extensionExistsAst, m as constraintExistsAst, o as createTable, p as columnTypeAst, r as alterTable, t as addColumnAction, u as columnDefaultAst, v as rlsEnabledAst, x as tableIsEmptyAst, y as rlsPolicyExistsAst } from "./ddl-BovUVFVi.mjs";
4
4
  import { col, fn, lit, table } from "@prisma-next/sql-relational-core/contract-free";
5
5
  import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
6
6
  //#region src/contract-free/columns.ts
@@ -1,8 +1,8 @@
1
- import { r as isPostgresSchema } from "./postgres-schema-DTLA_aRi.mjs";
1
+ import { r as isPostgresSchema } from "./postgres-schema-COEca21H.mjs";
2
2
  import { i as quoteIdentifier } from "./sql-utils-DcfMz4MQ.mjs";
3
3
  import { n as PostgresSchemaNodeKind, t as PostgresTableSchemaNode } from "./postgres-table-schema-node-9FCtCUz2.mjs";
4
- import { A as buildTargetDetails, C as DropTableCall, D as SetDefaultCall, O as SetNotNullCall, T as RawSqlCall, _ as DropColumnCall, a as AddNotNullColumnWithTempDefaultCall, b as DropIndexCall, c as AlterColumnTypeCall, f as CreateSchemaCall, g as DropCheckConstraintCall, h as DisableRowLevelSecurityCall, i as AddNotNullColumnDirectCall, k as postgresDefaultToDdlColumnDefault, m as DataTransformCall, n as AddColumnCall, o as AddPrimaryKeyCall, p as CreateTableCall, r as AddForeignKeyCall, s as AddUniqueCall, t as AddCheckConstraintCall, u as CreateIndexCall, v as DropConstraintCall, w as EnableRowLevelSecurityCall, x as DropNotNullCall, y as DropDefaultCall } from "./op-factory-call-DxNNKUeZ.mjs";
5
- import { t as buildExpectedFormatType } from "./planner-sql-checks-AXoxB1Jl.mjs";
4
+ import { A as buildTargetDetails, C as DropTableCall, D as SetDefaultCall, O as SetNotNullCall, T as RawSqlCall, _ as DropColumnCall, a as AddNotNullColumnWithTempDefaultCall, b as DropIndexCall, c as AlterColumnTypeCall, f as CreateSchemaCall, g as DropCheckConstraintCall, h as DisableRowLevelSecurityCall, i as AddNotNullColumnDirectCall, k as postgresDefaultToDdlColumnDefault, m as DataTransformCall, n as AddColumnCall, o as AddPrimaryKeyCall, p as CreateTableCall, r as AddForeignKeyCall, s as AddUniqueCall, t as AddCheckConstraintCall, u as CreateIndexCall, v as DropConstraintCall, w as EnableRowLevelSecurityCall, x as DropNotNullCall, y as DropDefaultCall } from "./op-factory-call-CI00nS4z.mjs";
5
+ import { t as buildExpectedFormatType } from "./planner-sql-checks-C1-Kk3Eu.mjs";
6
6
  import { n as buildColumnTypeSql, t as buildColumnDefaultSql } from "./planner-ddl-builders-B8Nn6nHN.mjs";
7
7
  import { n as resolveIdentityValue } from "./planner-identity-values-CJPha2Sz.mjs";
8
8
  import { i as hasUniqueConstraint, n as hasForeignKey, t as buildSchemaLookupMap } from "./planner-schema-lookup-CiVaAQP-.mjs";
@@ -1096,6 +1096,17 @@ function resolvePostgresNodeIssueCreationFactoryName(issue) {
1096
1096
  * `namespaceId` falls back to {@link UNBOUND_NAMESPACE_ID} via
1097
1097
  * `resolveNamespaceIdForTable`'s own fallback — the call-side resolver does
1098
1098
  * the same for the `DropTableCall` it produces.
1099
+ *
1100
+ * A role node resolves against the `PostgresRole` contract entity at that
1101
+ * role's name (roles are root-level diff subjects, so the name is the
1102
+ * second path segment after the tree root). A `not-found` role is declared,
1103
+ * so the entity is always found and its `control` read directly — which is
1104
+ * always {@link ROLE_DEFAULT_CONTROL_POLICY} today, since no authoring
1105
+ * surface sets it otherwise. A `not-expected` role has no contract entity
1106
+ * (an undeclared live role, by definition), so the subject falls back to
1107
+ * the same default — roles are referenced but never owned, so an
1108
+ * undeclared role gets exactly the same governance as a declared one.
1109
+ * Never creates a new object: role provisioning is a non-goal.
1099
1110
  */
1100
1111
  function resolvePostgresNodeIssueControlPolicySubject(issue, contract) {
1101
1112
  const node = issue.expected ?? issue.actual;
@@ -1104,6 +1115,18 @@ function resolvePostgresNodeIssueControlPolicySubject(issue, contract) {
1104
1115
  namespaceId: resolveNamespaceIdForDdlSchema(contract, blindCast(node).schemaName),
1105
1116
  createsNewObject: issue.reason === "not-found"
1106
1117
  };
1118
+ if (node.nodeKind === PostgresSchemaNodeKind.role) {
1119
+ const roleName = issue.path[1];
1120
+ return {
1121
+ namespaceId: UNBOUND_NAMESPACE_ID,
1122
+ explicitNodeControlPolicy: (roleName === void 0 ? void 0 : entityAt(contract.storage, {
1123
+ namespaceId: UNBOUND_NAMESPACE_ID,
1124
+ entityKind: "role",
1125
+ entityName: roleName
1126
+ }))?.control ?? "external",
1127
+ createsNewObject: false
1128
+ };
1129
+ }
1107
1130
  const tableName = issue.path[2];
1108
1131
  if (tableName === void 0) return void 0;
1109
1132
  const ddlSchemaName = issue.path[1];
@@ -1125,4 +1148,4 @@ function resolvePostgresNodeIssueControlPolicySubject(issue, contract) {
1125
1148
  //#endregion
1126
1149
  export { resolvePostgresNodeIssueCreationFactoryName as a, issueSchemaName as c, postgresPlannerStrategies as d, resolvePostgresNodeIssueControlPolicySubject as i, issueTableName as l, resolveNamespaceIdForDdlSchema as n, coalesceSubtreeIssues as o, resolvePostgresCallControlPolicySubject as r, issueNode as s, formatPostgresControlPolicySubjectLabel as t, planIssues as u };
1127
1150
 
1128
- //# sourceMappingURL=control-policy-Co_13Hxa.mjs.map
1151
+ //# sourceMappingURL=control-policy-BpmChlAK.mjs.map