@prisma-next/target-postgres 0.14.0-dev.7 → 0.14.0-dev.71

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 (265) hide show
  1. package/dist/authoring-Bi9aa8zG.mjs +574 -0
  2. package/dist/authoring-Bi9aa8zG.mjs.map +1 -0
  3. package/dist/canonicalize-CAbXtVtB.d.mts +37 -0
  4. package/dist/canonicalize-CAbXtVtB.d.mts.map +1 -0
  5. package/dist/{codec-ids-CnXu9Qy3.d.mts → codec-ids-BzrFF-I4.d.mts} +3 -2
  6. package/dist/codec-ids-BzrFF-I4.d.mts.map +1 -0
  7. package/dist/{codec-ids-BvytN2P8.mjs → codec-ids-C_-Hj6bL.mjs} +3 -2
  8. package/dist/codec-ids-C_-Hj6bL.mjs.map +1 -0
  9. package/dist/codec-ids.d.mts +2 -2
  10. package/dist/codec-ids.mjs +2 -2
  11. package/dist/{codec-types-DHCkwPKE.d.mts → codec-types-BiIWziRO.d.mts} +3 -2
  12. package/dist/codec-types-BiIWziRO.d.mts.map +1 -0
  13. package/dist/codec-types.d.mts +1 -1
  14. package/dist/codecs-Cl_hQHg-.mjs +913 -0
  15. package/dist/codecs-Cl_hQHg-.mjs.map +1 -0
  16. package/dist/{codecs--0A5_4Bq.d.mts → codecs-Cm-nS4mQ.d.mts} +111 -4
  17. package/dist/codecs-Cm-nS4mQ.d.mts.map +1 -0
  18. package/dist/codecs.d.mts +2 -2
  19. package/dist/codecs.mjs +3 -757
  20. package/dist/codecs.mjs.map +1 -1
  21. package/dist/contract-free.d.mts +33 -3
  22. package/dist/contract-free.d.mts.map +1 -1
  23. package/dist/contract-free.mjs +23 -7
  24. package/dist/contract-free.mjs.map +1 -1
  25. package/dist/control-policy-CuUhjWnn.mjs +1258 -0
  26. package/dist/control-policy-CuUhjWnn.mjs.map +1 -0
  27. package/dist/control.d.mts +2 -2
  28. package/dist/control.d.mts.map +1 -1
  29. package/dist/control.mjs +866 -36
  30. package/dist/control.mjs.map +1 -1
  31. package/dist/data-transform-BOWpliq8.mjs.map +1 -1
  32. package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-DPzwBMhW.d.mts} +3 -3
  33. package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-DPzwBMhW.d.mts.map} +1 -1
  34. package/dist/data-transform.d.mts +1 -1
  35. package/dist/{ddl-QDyOSeLc.mjs → ddl-Dqgs-bDc.mjs} +93 -6
  36. package/dist/ddl-Dqgs-bDc.mjs.map +1 -0
  37. package/dist/ddl.d.mts +3 -2
  38. package/dist/ddl.mjs +2 -2
  39. package/dist/default-normalizer.d.mts +1 -1
  40. package/dist/default-normalizer.d.mts.map +1 -1
  41. package/dist/default-normalizer.mjs +247 -1
  42. package/dist/default-normalizer.mjs.map +1 -0
  43. package/dist/descriptor-meta-UugzVM-U.mjs +22 -0
  44. package/dist/descriptor-meta-UugzVM-U.mjs.map +1 -0
  45. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
  46. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
  47. package/dist/diff-database-schema-ClN3bkRS.mjs +305 -0
  48. package/dist/diff-database-schema-ClN3bkRS.mjs.map +1 -0
  49. package/dist/diff-database-schema.d.mts +46 -0
  50. package/dist/diff-database-schema.d.mts.map +1 -0
  51. package/dist/diff-database-schema.mjs +2 -0
  52. package/dist/errors-DO-w0EUS.mjs +35 -0
  53. package/dist/errors-DO-w0EUS.mjs.map +1 -0
  54. package/dist/errors.d.mts +11 -9
  55. package/dist/errors.d.mts.map +1 -1
  56. package/dist/errors.mjs +1 -1
  57. package/dist/issue-planner.d.mts +35 -11
  58. package/dist/issue-planner.d.mts.map +1 -1
  59. package/dist/issue-planner.mjs +2 -2
  60. package/dist/migration.d.mts +5 -5
  61. package/dist/migration.d.mts.map +1 -1
  62. package/dist/migration.mjs +4 -4
  63. package/dist/namespace-ids-xtp_ZY86.mjs +7 -0
  64. package/dist/namespace-ids-xtp_ZY86.mjs.map +1 -0
  65. package/dist/native-type-normalizer.mjs +37 -1
  66. package/dist/native-type-normalizer.mjs.map +1 -0
  67. package/dist/nodes-Bc2N3tMy.d.mts +170 -0
  68. package/dist/nodes-Bc2N3tMy.d.mts.map +1 -0
  69. package/dist/nodes-DJC5B8Id.mjs +192 -0
  70. package/dist/nodes-DJC5B8Id.mjs.map +1 -0
  71. package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-CSIg5XDu.d.mts} +91 -15
  72. package/dist/op-factory-call-CSIg5XDu.d.mts.map +1 -0
  73. package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-DtVSP_7Y.mjs} +400 -32
  74. package/dist/op-factory-call-DtVSP_7Y.mjs.map +1 -0
  75. package/dist/op-factory-call.d.mts +2 -2
  76. package/dist/op-factory-call.mjs +2 -2
  77. package/dist/pack.d.mts +300 -3
  78. package/dist/pack.d.mts.map +1 -1
  79. package/dist/pack.mjs +1 -1
  80. package/dist/planner-ChVasl04.mjs +390 -0
  81. package/dist/planner-ChVasl04.mjs.map +1 -0
  82. package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-BKlmGDJl.mjs} +17 -28
  83. package/dist/planner-ddl-builders-BKlmGDJl.mjs.map +1 -0
  84. package/dist/planner-ddl-builders.d.mts +4 -6
  85. package/dist/planner-ddl-builders.d.mts.map +1 -1
  86. package/dist/planner-ddl-builders.mjs +2 -2
  87. package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
  88. package/dist/planner-identity-values.d.mts +8 -2
  89. package/dist/planner-identity-values.d.mts.map +1 -1
  90. package/dist/planner-identity-values.mjs +2 -2
  91. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-CXue-6M9.d.mts} +4 -4
  92. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-CXue-6M9.d.mts.map} +1 -1
  93. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-qpU05c__.mjs} +3 -3
  94. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-qpU05c__.mjs.map} +1 -1
  95. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  96. package/dist/planner-produced-postgres-migration.mjs +1 -1
  97. package/dist/{planner-sql-checks-jqUUGyQR.mjs → planner-sql-checks-CDXn2uaS.mjs} +5 -5
  98. package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-CDXn2uaS.mjs.map} +1 -1
  99. package/dist/planner-sql-checks.d.mts +2 -2
  100. package/dist/planner-sql-checks.d.mts.map +1 -1
  101. package/dist/planner-sql-checks.mjs +1 -1
  102. package/dist/{planner-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
  103. package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
  104. package/dist/planner-target-details.d.mts +1 -1
  105. package/dist/planner.d.mts +72 -17
  106. package/dist/planner.d.mts.map +1 -1
  107. package/dist/planner.mjs +3 -2
  108. package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-C3LPCLP_.mjs} +45 -41
  109. package/dist/postgres-contract-view-C3LPCLP_.mjs.map +1 -0
  110. package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
  111. package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
  112. package/dist/postgres-database-schema-node-CJv5bfbs.d.mts +262 -0
  113. package/dist/postgres-database-schema-node-CJv5bfbs.d.mts.map +1 -0
  114. package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-DkmgGNcv.d.mts} +47 -9
  115. package/dist/postgres-migration-DkmgGNcv.d.mts.map +1 -0
  116. package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-fndp3Mbm.mjs} +69 -45
  117. package/dist/postgres-migration-fndp3Mbm.mjs.map +1 -0
  118. package/dist/postgres-native-enum-BwVNf0Ku.mjs +45 -0
  119. package/dist/postgres-native-enum-BwVNf0Ku.mjs.map +1 -0
  120. package/dist/postgres-rls-policy--CSddvMR.d.mts +52 -0
  121. package/dist/postgres-rls-policy--CSddvMR.d.mts.map +1 -0
  122. package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs +190 -0
  123. package/dist/postgres-role-schema-node-Cm-j0ZGM.mjs.map +1 -0
  124. package/dist/postgres-schema-DKq6s1P3.d.mts +269 -0
  125. package/dist/postgres-schema-DKq6s1P3.d.mts.map +1 -0
  126. package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-DYATroNx.mjs} +200 -11
  127. package/dist/postgres-schema-DYATroNx.mjs.map +1 -0
  128. package/dist/postgres-table-schema-node-D6LvInCe.mjs +216 -0
  129. package/dist/postgres-table-schema-node-D6LvInCe.mjs.map +1 -0
  130. package/dist/render-ops.d.mts +1 -1
  131. package/dist/{render-typescript-KMgosran.mjs → render-typescript-7yqILcwr.mjs} +45 -16
  132. package/dist/render-typescript-7yqILcwr.mjs.map +1 -0
  133. package/dist/render-typescript.mjs +1 -1
  134. package/dist/resolve-ddl-schema-DpGte50u.mjs +22 -0
  135. package/dist/resolve-ddl-schema-DpGte50u.mjs.map +1 -0
  136. package/dist/rls-canonicalize.d.mts +20 -0
  137. package/dist/rls-canonicalize.d.mts.map +1 -0
  138. package/dist/rls-canonicalize.mjs +2 -0
  139. package/dist/runtime.d.mts +6 -8
  140. package/dist/runtime.d.mts.map +1 -1
  141. package/dist/runtime.mjs +3 -3
  142. package/dist/runtime.mjs.map +1 -1
  143. package/dist/schema-ir-annotations.d.mts +15 -0
  144. package/dist/schema-ir-annotations.d.mts.map +1 -0
  145. package/dist/schema-ir-annotations.mjs +2 -0
  146. package/dist/{sql-utils-DcfMz4MQ.mjs → sql-utils-SU4FDvIV.mjs} +12 -3
  147. package/dist/{sql-utils-DcfMz4MQ.mjs.map → sql-utils-SU4FDvIV.mjs.map} +1 -1
  148. package/dist/sql-utils.d.mts +8 -1
  149. package/dist/sql-utils.d.mts.map +1 -1
  150. package/dist/sql-utils.mjs +2 -2
  151. package/dist/types.d.mts +4 -140
  152. package/dist/types.mjs +5 -2
  153. package/dist/wire-name-rHHtr1h0.mjs +75 -0
  154. package/dist/wire-name-rHHtr1h0.mjs.map +1 -0
  155. package/package.json +26 -20
  156. package/src/contract-free/checks.ts +73 -0
  157. package/src/contract-free/control-bootstrap.ts +20 -3
  158. package/src/contract-free/ddl.ts +98 -1
  159. package/src/core/authoring.ts +509 -2
  160. package/src/core/codec-ids.ts +1 -0
  161. package/src/core/codec-type-map.ts +2 -0
  162. package/src/core/codecs.ts +180 -1
  163. package/src/core/ddl/nodes.ts +185 -2
  164. package/src/core/default-normalizer.ts +122 -2
  165. package/src/core/descriptor-meta.ts +10 -1
  166. package/src/core/entity-kinds.ts +41 -0
  167. package/src/core/errors.ts +14 -12
  168. package/src/core/migrations/bound-schema.ts +10 -0
  169. package/src/core/migrations/column-ddl-rendering.ts +117 -0
  170. package/src/core/migrations/contract-to-postgres-database-schema-node.ts +189 -0
  171. package/src/core/migrations/control-policy.ts +217 -65
  172. package/src/core/migrations/diff-database-schema.ts +252 -0
  173. package/src/core/migrations/issue-planner.ts +769 -656
  174. package/src/core/migrations/op-factory-call.ts +273 -21
  175. package/src/core/migrations/operations/columns.ts +24 -12
  176. package/src/core/migrations/operations/constraints.ts +1 -1
  177. package/src/core/migrations/operations/data-transform.ts +6 -0
  178. package/src/core/migrations/operations/dependencies.ts +2 -1
  179. package/src/core/migrations/operations/native-enum-types.ts +62 -0
  180. package/src/core/migrations/operations/rls.ts +187 -0
  181. package/src/core/migrations/operations/shared.ts +0 -30
  182. package/src/core/migrations/planner-ddl-builders.ts +31 -59
  183. package/src/core/migrations/planner-identity-values.ts +1 -1
  184. package/src/core/migrations/planner-recipes.ts +31 -13
  185. package/src/core/migrations/planner-sql-checks.ts +1 -1
  186. package/src/core/migrations/planner-strategies.ts +248 -216
  187. package/src/core/migrations/planner-target-details.ts +3 -1
  188. package/src/core/migrations/planner.ts +357 -67
  189. package/src/core/migrations/postgres-migration.ts +101 -86
  190. package/src/core/migrations/render-typescript.ts +42 -15
  191. package/src/core/migrations/resolve-ddl-schema.ts +26 -0
  192. package/src/core/migrations/runner.ts +11 -16
  193. package/src/core/migrations/verify-postgres-namespaces.ts +46 -31
  194. package/src/core/namespace-ids.ts +3 -0
  195. package/src/core/postgres-contract-serializer.ts +46 -71
  196. package/src/core/postgres-contract-view.ts +48 -0
  197. package/src/core/postgres-native-enum.ts +61 -0
  198. package/src/core/postgres-rls-enablement.ts +34 -0
  199. package/src/core/postgres-rls-policy.ts +64 -0
  200. package/src/core/postgres-role.ts +59 -0
  201. package/src/core/postgres-schema-verifier.ts +10 -7
  202. package/src/core/postgres-schema.ts +85 -15
  203. package/src/core/postgres-validators.ts +34 -0
  204. package/src/core/psl-infer/infer-psl-contract.ts +1273 -0
  205. package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
  206. package/src/core/psl-infer/postgres-type-map.ts +128 -0
  207. package/src/core/rls/canonicalize.ts +48 -0
  208. package/src/core/rls/wire-name.ts +33 -0
  209. package/src/core/schema-ir/node-storage-coordinate.ts +26 -0
  210. package/src/core/schema-ir/postgres-database-schema-node.ts +61 -0
  211. package/src/core/schema-ir/postgres-namespace-schema-node.ts +70 -0
  212. package/src/core/schema-ir/postgres-native-enum-schema-node.ts +83 -0
  213. package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
  214. package/src/core/schema-ir/postgres-role-schema-node.ts +65 -0
  215. package/src/core/schema-ir/postgres-table-schema-node.ts +140 -0
  216. package/src/core/schema-ir/schema-node-kinds.ts +122 -0
  217. package/src/core/sql-utils.ts +15 -2
  218. package/src/exports/codecs.ts +3 -0
  219. package/src/exports/contract-free.ts +11 -1
  220. package/src/exports/control.ts +27 -33
  221. package/src/exports/ddl.ts +8 -0
  222. package/src/exports/diff-database-schema.ts +7 -0
  223. package/src/exports/issue-planner.ts +1 -1
  224. package/src/exports/migration.ts +1 -0
  225. package/src/exports/op-factory-call.ts +3 -0
  226. package/src/exports/planner-ddl-builders.ts +0 -2
  227. package/src/exports/planner-identity-values.ts +4 -1
  228. package/src/exports/planner.ts +1 -0
  229. package/src/exports/rls-canonicalize.ts +7 -0
  230. package/src/exports/runtime.ts +1 -0
  231. package/src/exports/schema-ir-annotations.ts +1 -0
  232. package/src/exports/sql-utils.ts +1 -0
  233. package/src/exports/types.ts +37 -0
  234. package/dist/codec-ids-BvytN2P8.mjs.map +0 -1
  235. package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
  236. package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
  237. package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
  238. package/dist/ddl-QDyOSeLc.mjs.map +0 -1
  239. package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
  240. package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
  241. package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
  242. package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
  243. package/dist/errors-CUk87ByX.mjs +0 -33
  244. package/dist/errors-CUk87ByX.mjs.map +0 -1
  245. package/dist/issue-planner-DL6g3CmE.mjs +0 -824
  246. package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
  247. package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
  248. package/dist/native-type-normalizer-Bc9XJzWC.mjs.map +0 -1
  249. package/dist/nodes-Bbhs2rwj.mjs +0 -76
  250. package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
  251. package/dist/nodes-pLeLgdis.d.mts +0 -67
  252. package/dist/nodes-pLeLgdis.d.mts.map +0 -1
  253. package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
  254. package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
  255. package/dist/planner-Bs_baQax.mjs +0 -324
  256. package/dist/planner-Bs_baQax.mjs.map +0 -1
  257. package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
  258. package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
  259. package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
  260. package/dist/postgres-migration-B5jKrXv3.mjs.map +0 -1
  261. package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
  262. package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
  263. package/dist/render-typescript-KMgosran.mjs.map +0 -1
  264. package/dist/types.d.mts.map +0 -1
  265. package/src/core/postgres-enum-type-schema.ts +0 -17
@@ -0,0 +1,574 @@
1
+ import { a as PG_ENUM_CODEC_ID } from "./codec-ids-C_-Hj6bL.mjs";
2
+ 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-DYATroNx.mjs";
4
+ import { i as normalizePredicate, r as computeContentHash, t as formatRlsPolicyWireName } from "./wire-name-rHHtr1h0.mjs";
5
+ import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
6
+ import { temporalAuthoringPresets } from "@prisma-next/family-sql/control";
7
+ import { ifDefined } from "@prisma-next/utils/defined";
8
+ import { modelAttribute } from "@prisma-next/psl-parser";
9
+ //#region src/core/authoring.ts
10
+ /**
11
+ * `pg.enum(<ref>)` registers as an ordinary type constructor whose sole
12
+ * positional argument names a `native_enum` entity instead of carrying a
13
+ * literal value. The interpreter resolves the ref to the `native_enum`
14
+ * entity generically (driven by `entityRefArg`); the `pg/enum@1` codec
15
+ * descriptor's `columnFromEntity` hook (see `codecs.ts`) converts that
16
+ * entity into the column's `typeParams` and native type.
17
+ */
18
+ const postgresAuthoringTypes = { pg: { enum: {
19
+ kind: "typeConstructor",
20
+ entityRefArg: {
21
+ index: 0,
22
+ entityKind: "native_enum"
23
+ },
24
+ output: { codecId: PG_ENUM_CODEC_ID }
25
+ } } };
26
+ /**
27
+ * Maps a `policy_<op>` keyword to the RLS operation it authors. The keyword
28
+ * IS the operation (per the project's rejection of a `policy { operation = … }`
29
+ * conditional block).
30
+ */
31
+ const POLICY_KEYWORD_OPERATION = {
32
+ policy_select: "select",
33
+ policy_insert: "insert",
34
+ policy_update: "update",
35
+ policy_delete: "delete",
36
+ policy_all: "all"
37
+ };
38
+ /**
39
+ * Which predicate each RLS operation admits, mirroring Postgres: SELECT and
40
+ * DELETE decide row visibility/eligibility with `USING` only; INSERT validates
41
+ * the new row with `WITH CHECK` only; UPDATE and ALL take both. A predicate
42
+ * outside this set is a load-time error (see {@link lowerRlsPolicyFromBlock}).
43
+ */
44
+ const POLICY_OPERATION_PREDICATES = {
45
+ select: {
46
+ using: true,
47
+ withCheck: false
48
+ },
49
+ insert: {
50
+ using: false,
51
+ withCheck: true
52
+ },
53
+ update: {
54
+ using: true,
55
+ withCheck: true
56
+ },
57
+ delete: {
58
+ using: true,
59
+ withCheck: false
60
+ },
61
+ all: {
62
+ using: true,
63
+ withCheck: true
64
+ }
65
+ };
66
+ function readRefParam(block, key) {
67
+ const param = block.parameters[key];
68
+ return param?.kind === "ref" ? param.identifier : void 0;
69
+ }
70
+ function readValueParam(block, key) {
71
+ const param = block.parameters[key];
72
+ return param?.kind === "value" ? param.raw : void 0;
73
+ }
74
+ function readListRefParams(block, key) {
75
+ const param = block.parameters[key];
76
+ if (param?.kind !== "list") return [];
77
+ return param.items.flatMap((item) => item.kind === "ref" ? [item.identifier] : []);
78
+ }
79
+ /**
80
+ * Unwraps a quoted PSL string argument, inverting the printer's
81
+ * `escapePslString` escapes (`\\`, `\"`, `\n`, `\r`). An unknown escape
82
+ * sequence is kept verbatim, matching the printer-side `unescapePslString`
83
+ * convention.
84
+ */
85
+ function unwrapQuotedString(raw) {
86
+ if (!(raw.startsWith("\"") && raw.endsWith("\"") && raw.length >= 2)) return raw;
87
+ const inner = raw.slice(1, -1);
88
+ let result = "";
89
+ for (let i = 0; i < inner.length; i++) {
90
+ if (inner[i] !== "\\" || i + 1 >= inner.length) {
91
+ result += inner[i];
92
+ continue;
93
+ }
94
+ const next = inner[i + 1];
95
+ if (next === "\\" || next === "\"") result += next;
96
+ else if (next === "n") result += "\n";
97
+ else if (next === "r") result += "\r";
98
+ else {
99
+ result += "\\";
100
+ result += next;
101
+ }
102
+ i++;
103
+ }
104
+ return result;
105
+ }
106
+ function lowerRlsPolicyFromBlock(block, ctx) {
107
+ const prefix = block.name;
108
+ const operation = POLICY_KEYWORD_OPERATION[block.keyword] ?? "select";
109
+ const targetModelName = readRefParam(block, "target") ?? "";
110
+ const tableName = targetModelName.charAt(0).toLowerCase() + targetModelName.slice(1);
111
+ const roles = [...readListRefParams(block, "roles")].sort();
112
+ const usingRaw = readValueParam(block, "using");
113
+ const withCheckRaw = readValueParam(block, "withCheck");
114
+ const support = POLICY_OPERATION_PREDICATES[operation];
115
+ const rejectPredicate = (predicate) => {
116
+ ctx.diagnostics?.push({
117
+ code: "PSL_RLS_PREDICATE_NOT_FOR_OPERATION",
118
+ 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"}.`,
119
+ sourceId: ctx.sourceId ?? "unknown",
120
+ span: block.parameters[predicate]?.span ?? block.span
121
+ });
122
+ };
123
+ if (usingRaw !== void 0 && !support.using) return rejectPredicate("using");
124
+ if (withCheckRaw !== void 0 && !support.withCheck) return rejectPredicate("withCheck");
125
+ const using = usingRaw !== void 0 ? unwrapQuotedString(usingRaw) : void 0;
126
+ const withCheck = withCheckRaw !== void 0 ? unwrapQuotedString(withCheckRaw) : void 0;
127
+ return new PostgresRlsPolicy({
128
+ name: formatRlsPolicyWireName(prefix, computeContentHash({
129
+ ...ifDefined("using", using !== void 0 ? normalizePredicate(using) : void 0),
130
+ ...ifDefined("withCheck", withCheck !== void 0 ? normalizePredicate(withCheck) : void 0),
131
+ roles,
132
+ operation,
133
+ permissive: true
134
+ })),
135
+ prefix,
136
+ tableName,
137
+ namespaceId: block.namespaceId,
138
+ operation,
139
+ roles,
140
+ ...ifDefined("using", using),
141
+ ...ifDefined("withCheck", withCheck),
142
+ permissive: true
143
+ });
144
+ }
145
+ /**
146
+ * Lowers a `native_enum { memberName = "value" … @@map("type_name") }` block
147
+ * into a {@link PostgresNativeEnum}. Members must be authored as explicit
148
+ * `key = "value"` pairs — a bare (value-less) member is a diagnostic, not
149
+ * accepted (authoring-design.md §2.1). The parsed `memberName` is only used
150
+ * to duplicate-check and report diagnostics; the lowered entity carries just
151
+ * the member values (a native enum is value-only — the member "name" isn't
152
+ * a separate authoring concept from the value). `typeName` comes from
153
+ * `@@map` or defaults to the block name verbatim.
154
+ */
155
+ function lowerNativeEnumFromBlock(block, ctx) {
156
+ const sourceId = ctx.sourceId ?? "unknown";
157
+ const diagnostics = ctx.diagnostics;
158
+ const mapAttr = block.blockAttributes.find((a) => a.name === "map");
159
+ let typeName = block.name;
160
+ if (mapAttr) {
161
+ const rawArg = mapAttr.args[0]?.value;
162
+ const mapped = rawArg !== void 0 ? unwrapQuotedString(rawArg) : void 0;
163
+ if (mapped === void 0) {
164
+ diagnostics?.push({
165
+ code: "PSL_NATIVE_ENUM_INVALID_MAP",
166
+ message: `native_enum "${block.name}" @@map attribute must have a quoted type-name argument`,
167
+ sourceId,
168
+ span: mapAttr.span
169
+ });
170
+ return;
171
+ }
172
+ typeName = mapped;
173
+ }
174
+ let memberError = false;
175
+ const seenValues = /* @__PURE__ */ new Set();
176
+ const members = [];
177
+ for (const [memberName, paramValue] of Object.entries(block.parameters)) {
178
+ if (paramValue.kind === "bare") {
179
+ diagnostics?.push({
180
+ code: "PSL_NATIVE_ENUM_BARE_MEMBER",
181
+ message: `native_enum "${block.name}" member "${memberName}" has no value; members must be authored as "${memberName} = \\"value\\""`,
182
+ sourceId,
183
+ span: paramValue.span
184
+ });
185
+ memberError = true;
186
+ continue;
187
+ }
188
+ if (paramValue.kind !== "value") continue;
189
+ let jsonValue;
190
+ try {
191
+ jsonValue = JSON.parse(paramValue.raw);
192
+ } catch {
193
+ diagnostics?.push({
194
+ code: "PSL_EXTENSION_INVALID_VALUE",
195
+ message: `native_enum "${block.name}" member "${memberName}" value "${paramValue.raw}" is not valid JSON`,
196
+ sourceId,
197
+ span: paramValue.span
198
+ });
199
+ memberError = true;
200
+ continue;
201
+ }
202
+ if (typeof jsonValue !== "string") {
203
+ diagnostics?.push({
204
+ code: "PSL_EXTENSION_INVALID_VALUE",
205
+ message: `native_enum "${block.name}" member "${memberName}" value must be a string`,
206
+ sourceId,
207
+ span: paramValue.span
208
+ });
209
+ memberError = true;
210
+ continue;
211
+ }
212
+ if (seenValues.has(jsonValue)) {
213
+ diagnostics?.push({
214
+ code: "PSL_NATIVE_ENUM_DUPLICATE_MEMBER_VALUE",
215
+ message: `native_enum "${block.name}": duplicate member value "${jsonValue}"`,
216
+ sourceId,
217
+ span: paramValue.span
218
+ });
219
+ memberError = true;
220
+ continue;
221
+ }
222
+ seenValues.add(jsonValue);
223
+ members.push(jsonValue);
224
+ }
225
+ if (memberError) return void 0;
226
+ if (members.length === 0) {
227
+ diagnostics?.push({
228
+ code: "PSL_NATIVE_ENUM_MISSING_MEMBERS",
229
+ message: `native_enum "${block.name}" must have at least one member`,
230
+ sourceId,
231
+ span: block.span
232
+ });
233
+ return;
234
+ }
235
+ return new PostgresNativeEnum({
236
+ typeName,
237
+ members
238
+ });
239
+ }
240
+ /**
241
+ * `native_enum`'s entity-type factory output, checked separately from the assembled
242
+ * `postgresAuthoringEntityTypes` map below: `deriveValueSet` is SQL-family surface
243
+ * ({@link SqlValueSetDerivingEntityTypeOutput}), not part of the framework
244
+ * `AuthoringEntityTypeFactoryOutput` shape, so folding it directly into the map's single
245
+ * `satisfies AuthoringEntityTypeNamespace` check would trip an excess-property error. Checking it
246
+ * here against the intersection of both shapes keeps it structurally valid against each without
247
+ * widening the map's own check.
248
+ */
249
+ const nativeEnumEntityTypeOutput = {
250
+ factory: lowerNativeEnumFromBlock,
251
+ deriveValueSet: (entity) => ({
252
+ kind: "valueSet",
253
+ values: [...entity.members]
254
+ })
255
+ };
256
+ /**
257
+ * Lowers a `role <name> {}` block into a {@link PostgresRole}. Roles are
258
+ * cluster-scoped in Postgres, so the block must be declared inside
259
+ * `namespace unbound { … }` — any other lexical namespace (a named schema,
260
+ * or the default bucket top-level declarations resolve to) is a load-time
261
+ * diagnostic. The lowered entity carries the unbound coordinate.
262
+ */
263
+ function lowerRoleFromBlock(block, ctx) {
264
+ if (block.namespaceId !== UNBOUND_NAMESPACE_ID) {
265
+ ctx.diagnostics?.push({
266
+ code: "PSL_ROLE_BLOCK_OUTSIDE_UNBOUND_NAMESPACE",
267
+ message: `\`role\` block "${block.name}" must be declared inside \`namespace unbound { }\`, not in namespace "${block.namespaceId}"`,
268
+ sourceId: ctx.sourceId ?? "unknown",
269
+ span: block.span
270
+ });
271
+ return;
272
+ }
273
+ return new PostgresRole({
274
+ name: block.name,
275
+ namespaceId: UNBOUND_NAMESPACE_ID
276
+ });
277
+ }
278
+ const postgresAuthoringEntityTypes = {
279
+ role: {
280
+ kind: "entity",
281
+ discriminator: "role",
282
+ validatorSchema: PostgresRoleSchema,
283
+ output: { factory: lowerRoleFromBlock }
284
+ },
285
+ rls: {
286
+ kind: "entity",
287
+ discriminator: "rls",
288
+ validatorSchema: PostgresRlsEnablementSchema,
289
+ output: { factory: (input) => new PostgresRlsEnablement(input) }
290
+ },
291
+ policy: {
292
+ kind: "entity",
293
+ discriminator: "policy",
294
+ validatorSchema: PostgresRlsPolicySchema,
295
+ output: { factory: lowerRlsPolicyFromBlock }
296
+ },
297
+ native_enum: {
298
+ kind: "entity",
299
+ discriminator: "native_enum",
300
+ validatorSchema: PostgresNativeEnumSchema,
301
+ output: nativeEnumEntityTypeOutput
302
+ }
303
+ };
304
+ /**
305
+ * Field presets contributed by the Postgres target pack.
306
+ *
307
+ * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter
308
+ * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field
309
+ * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar
310
+ * surface (e.g. `Int`) lowers to byte-identical contracts.
311
+ *
312
+ * The `uuidNative` / `id.uuidv4Native` / `id.uuidv7Native` presets use the
313
+ * native Postgres `uuid` type (codecId `pg/uuid@1`). For cross-target
314
+ * portability use `uuidString` / `id.uuidv4String` / `id.uuidv7String` from
315
+ * the family pack instead.
316
+ */
317
+ /**
318
+ * Shared parameter descriptors for the five `policy_<op>` PSL block
319
+ * keywords. All five share the `policy` discriminator — the parser
320
+ * dispatches by keyword (see the framework's PSL-block SPI), and every
321
+ * keyword's factory lowers to `PostgresRlsPolicy` via `lowerRlsPolicyFromBlock`.
322
+ *
323
+ * The `roles` list uses `scope:'cross-space'` because same-namespace
324
+ * role ref resolution requires PSL namespace entries keyed by `refKind`
325
+ * (i.e. `'role'`), which in turn requires the role block discriminator to
326
+ * equal `'role'`. Aligning discriminator with refKind is tracked for
327
+ * slice 4 (cross-space roles). Until then cross-space passes validation
328
+ * unconditionally and the authored role names flow through unchanged.
329
+ */
330
+ const policyTargetParam = {
331
+ kind: "ref",
332
+ refKind: "model",
333
+ scope: "same-namespace",
334
+ required: true
335
+ };
336
+ const policyRolesParam = {
337
+ kind: "list",
338
+ of: {
339
+ kind: "ref",
340
+ refKind: "role",
341
+ scope: "cross-space"
342
+ }
343
+ };
344
+ const policyPredicateParam = {
345
+ kind: "value",
346
+ codecId: "pg/text@1",
347
+ required: true
348
+ };
349
+ const policyRequiresRls = {
350
+ parameter: "target",
351
+ attribute: "rls"
352
+ };
353
+ const postgresAuthoringPslBlockDescriptors = {
354
+ policy_select: {
355
+ kind: "pslBlock",
356
+ keyword: "policy_select",
357
+ discriminator: "policy",
358
+ name: { required: true },
359
+ parameters: {
360
+ target: policyTargetParam,
361
+ roles: policyRolesParam,
362
+ using: policyPredicateParam
363
+ },
364
+ requiresModelAttribute: policyRequiresRls
365
+ },
366
+ policy_delete: {
367
+ kind: "pslBlock",
368
+ keyword: "policy_delete",
369
+ discriminator: "policy",
370
+ name: { required: true },
371
+ parameters: {
372
+ target: policyTargetParam,
373
+ roles: policyRolesParam,
374
+ using: policyPredicateParam
375
+ },
376
+ requiresModelAttribute: policyRequiresRls
377
+ },
378
+ policy_insert: {
379
+ kind: "pslBlock",
380
+ keyword: "policy_insert",
381
+ discriminator: "policy",
382
+ name: { required: true },
383
+ parameters: {
384
+ target: policyTargetParam,
385
+ roles: policyRolesParam,
386
+ withCheck: policyPredicateParam
387
+ },
388
+ requiresModelAttribute: policyRequiresRls
389
+ },
390
+ policy_update: {
391
+ kind: "pslBlock",
392
+ keyword: "policy_update",
393
+ discriminator: "policy",
394
+ name: { required: true },
395
+ parameters: {
396
+ target: policyTargetParam,
397
+ roles: policyRolesParam,
398
+ using: policyPredicateParam,
399
+ withCheck: policyPredicateParam
400
+ },
401
+ requiresModelAttribute: policyRequiresRls
402
+ },
403
+ policy_all: {
404
+ kind: "pslBlock",
405
+ keyword: "policy_all",
406
+ discriminator: "policy",
407
+ name: { required: true },
408
+ parameters: {
409
+ target: policyTargetParam,
410
+ roles: policyRolesParam,
411
+ using: policyPredicateParam,
412
+ withCheck: policyPredicateParam
413
+ },
414
+ requiresModelAttribute: policyRequiresRls
415
+ },
416
+ /**
417
+ * PSL block descriptor for `native_enum`.
418
+ *
419
+ * Reuses the existing variadic-block mechanism (the same shape the SQL
420
+ * family's `enum` block ships): the body is an open `memberName = "value"`
421
+ * list. `variadicParameters: true` opens the block to arbitrary keys
422
+ * beyond the declared (empty) `parameters` set — the lowering factory
423
+ * (`lowerNativeEnumFromBlock`) turns the variadic entries into ordered
424
+ * members and rejects a bare (value-less) member.
425
+ */
426
+ native_enum: {
427
+ kind: "pslBlock",
428
+ keyword: "native_enum",
429
+ discriminator: "native_enum",
430
+ name: { required: true },
431
+ parameters: {},
432
+ variadicParameters: true
433
+ },
434
+ /**
435
+ * PSL block descriptor for `role` (e.g. `role anon {}`). Name-only, no
436
+ * parameters and no body content. Declared inside `namespace unbound { }`
437
+ * — see {@link lowerRoleFromBlock} for the placement check and the
438
+ * coordinate the lowered entity carries.
439
+ */
440
+ role: {
441
+ kind: "pslBlock",
442
+ keyword: "role",
443
+ discriminator: "role",
444
+ name: { required: true },
445
+ parameters: {}
446
+ }
447
+ };
448
+ /**
449
+ * `@@` model attributes contributed by the Postgres target pack.
450
+ *
451
+ * `@@rls` is argument-less: presence marks the model's table
452
+ * RLS-controlled. It lowers to a {@link PostgresRlsEnablement} marker in
453
+ * the namespace's `entries.rls`, keyed by the model's table name — the
454
+ * marker (never the policy set) is what drives
455
+ * `ENABLE`/`DISABLE ROW LEVEL SECURITY` planning.
456
+ */
457
+ const postgresAuthoringModelAttributes = { rls: {
458
+ kind: "modelAttribute",
459
+ attribute: "rls",
460
+ spec: modelAttribute("rls", {}),
461
+ lower: (_parsed, ctx) => ({
462
+ key: ctx.storageName,
463
+ entity: new PostgresRlsEnablement({
464
+ tableName: ctx.storageName,
465
+ namespaceId: ctx.namespaceId
466
+ })
467
+ })
468
+ } };
469
+ const postgresAuthoringFieldPresets = {
470
+ text: {
471
+ kind: "fieldPreset",
472
+ output: {
473
+ codecId: "pg/text@1",
474
+ nativeType: "text"
475
+ }
476
+ },
477
+ int: {
478
+ kind: "fieldPreset",
479
+ output: {
480
+ codecId: "pg/int4@1",
481
+ nativeType: "int4"
482
+ }
483
+ },
484
+ bigint: {
485
+ kind: "fieldPreset",
486
+ output: {
487
+ codecId: "pg/int8@1",
488
+ nativeType: "int8"
489
+ }
490
+ },
491
+ float: {
492
+ kind: "fieldPreset",
493
+ output: {
494
+ codecId: "pg/float8@1",
495
+ nativeType: "float8"
496
+ }
497
+ },
498
+ decimal: {
499
+ kind: "fieldPreset",
500
+ output: {
501
+ codecId: "pg/numeric@1",
502
+ nativeType: "numeric"
503
+ }
504
+ },
505
+ boolean: {
506
+ kind: "fieldPreset",
507
+ output: {
508
+ codecId: "pg/bool@1",
509
+ nativeType: "bool"
510
+ }
511
+ },
512
+ json: {
513
+ kind: "fieldPreset",
514
+ output: {
515
+ codecId: "pg/jsonb@1",
516
+ nativeType: "jsonb"
517
+ }
518
+ },
519
+ bytes: {
520
+ kind: "fieldPreset",
521
+ output: {
522
+ codecId: "pg/bytea@1",
523
+ nativeType: "bytea"
524
+ }
525
+ },
526
+ dateTime: {
527
+ kind: "fieldPreset",
528
+ output: {
529
+ codecId: "pg/timestamptz@1",
530
+ nativeType: "timestamptz"
531
+ }
532
+ },
533
+ temporal: /* @__PURE__ */ temporalAuthoringPresets({
534
+ codecId: "pg/timestamptz@1",
535
+ nativeType: "timestamptz"
536
+ }),
537
+ uuidNative: {
538
+ kind: "fieldPreset",
539
+ output: {
540
+ codecId: "pg/uuid@1",
541
+ nativeType: "uuid"
542
+ }
543
+ },
544
+ id: {
545
+ uuidv4Native: {
546
+ kind: "fieldPreset",
547
+ output: {
548
+ codecId: "pg/uuid@1",
549
+ nativeType: "uuid",
550
+ executionDefaults: { onCreate: {
551
+ kind: "generator",
552
+ id: "uuidv4"
553
+ } },
554
+ id: true
555
+ }
556
+ },
557
+ uuidv7Native: {
558
+ kind: "fieldPreset",
559
+ output: {
560
+ codecId: "pg/uuid@1",
561
+ nativeType: "uuid",
562
+ executionDefaults: { onCreate: {
563
+ kind: "generator",
564
+ id: "uuidv7"
565
+ } },
566
+ id: true
567
+ }
568
+ }
569
+ }
570
+ };
571
+ //#endregion
572
+ export { postgresAuthoringTypes as a, postgresAuthoringPslBlockDescriptors as i, postgresAuthoringFieldPresets as n, postgresAuthoringModelAttributes as r, postgresAuthoringEntityTypes as t };
573
+
574
+ //# sourceMappingURL=authoring-Bi9aa8zG.mjs.map
@@ -0,0 +1 @@
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;EAAE,OAAO;EAAM,WAAW;CAAK;CACvC,QAAQ;EAAE,OAAO;EAAM,WAAW;CAAM;CACxC,KAAK;EAAE,OAAO;EAAM,WAAW;CAAK;AACtC;AAEA,SAAS,aAAa,OAA0B,KAAiC;CAC/E,MAAM,QAAQ,MAAM,WAAW;CAC/B,OAAO,OAAO,SAAS,QAAQ,MAAM,aAAa,KAAA;AACpD;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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,YAAY;EACd;CACF;CACA,QAAQ;EACN,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,OAAO;EACL,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,SAAS;EACP,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,SAAS;EACP,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,OAAO;EACL,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,UAAU;EACR,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,UAA0B,yCAAyB;EACjD,SAAS;EACT,YAAY;CACd,CAAC;CACD,YAAY;EACV,MAAM;EACN,QAAQ;GACN,SAAS;GACT,YAAY;EACd;CACF;CACA,IAAI;EACF,cAAc;GACZ,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;EACA,cAAc;GACZ,MAAM;GACN,QAAQ;IACN,SAAS;IACT,YAAY;IACZ,mBAAmB,EACjB,UAAU;KACR,MAAM;KACN,IAAI;IACN,EACF;IACA,IAAI;GACN;EACF;CACF;AACF"}
@@ -0,0 +1,37 @@
1
+ //#region src/core/rls/canonicalize.d.ts
2
+ type RlsPolicyOperation = 'select' | 'insert' | 'update' | 'delete' | 'all';
3
+ interface ContentHashParts {
4
+ readonly using?: string;
5
+ readonly withCheck?: string;
6
+ readonly roles: readonly string[];
7
+ readonly operation: RlsPolicyOperation;
8
+ readonly permissive: boolean;
9
+ }
10
+ /**
11
+ * Stabilizes an authored predicate for hashing: trim, and collapse runs of
12
+ * internal whitespace to a single space.
13
+ *
14
+ * This is deliberately minimal. The content hash is the equivalence relation
15
+ * for a policy, and the wire name (prefix + hash) is the only thing ever
16
+ * compared — we never recompute the hash from an introspected policy body, so
17
+ * there is no need to match Postgres's reprinted form. Minimal normalization
18
+ * also protects the no-collision property: aggressive rewriting (lowercasing,
19
+ * paren-stripping, cast-alias folding) risks collapsing two distinct predicates
20
+ * onto one hash. Out-of-band alteration of a hashed policy is unsupported.
21
+ *
22
+ * The normalizer is a stability commitment: any change re-suffixes all wire names.
23
+ */
24
+ declare function normalizePredicate(sql: string): string;
25
+ /**
26
+ * Returns the first 8 lowercase hex characters of the SHA-256 digest over the
27
+ * canonical content tuple for an RLS policy:
28
+ *
29
+ * [normalize(using), normalize(withCheck), sortedRoles, operation, permissive]
30
+ *
31
+ * Schema and table are excluded (they are orthogonal to policy equivalence).
32
+ * Uses `JSON.stringify` for a deterministic encoding.
33
+ */
34
+ declare function computeContentHash(parts: ContentHashParts): string;
35
+ //#endregion
36
+ export { normalizePredicate as i, RlsPolicyOperation as n, computeContentHash as r, ContentHashParts as t };
37
+ //# sourceMappingURL=canonicalize-CAbXtVtB.d.mts.map
@@ -0,0 +1 @@
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"}