@prisma-next/target-postgres 0.14.0-dev.6 → 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 (253) hide show
  1. package/dist/authoring-BLkL4fFG.mjs +528 -0
  2. package/dist/authoring-BLkL4fFG.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-CkVQrZ4G.mjs +913 -0
  15. package/dist/codecs-CkVQrZ4G.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 +4 -4
  24. package/dist/control-policy-BpmChlAK.mjs +1151 -0
  25. package/dist/control-policy-BpmChlAK.mjs.map +1 -0
  26. package/dist/control.d.mts +2 -2
  27. package/dist/control.d.mts.map +1 -1
  28. package/dist/control.mjs +901 -35
  29. package/dist/control.mjs.map +1 -1
  30. package/dist/data-transform-BOWpliq8.mjs.map +1 -1
  31. package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-DPzwBMhW.d.mts} +3 -3
  32. package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-DPzwBMhW.d.mts.map} +1 -1
  33. package/dist/data-transform.d.mts +1 -1
  34. package/dist/{ddl-QDyOSeLc.mjs → ddl-BovUVFVi.mjs} +77 -6
  35. package/dist/ddl-BovUVFVi.mjs.map +1 -0
  36. package/dist/ddl.d.mts +3 -2
  37. package/dist/ddl.mjs +2 -2
  38. package/dist/default-normalizer.d.mts +1 -1
  39. package/dist/default-normalizer.d.mts.map +1 -1
  40. package/dist/default-normalizer.mjs +247 -1
  41. package/dist/default-normalizer.mjs.map +1 -0
  42. package/dist/descriptor-meta-C1T4BXJ8.mjs +22 -0
  43. package/dist/descriptor-meta-C1T4BXJ8.mjs.map +1 -0
  44. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs +12 -0
  45. package/dist/descriptor-meta-runtime-UwYdV8fD.mjs.map +1 -0
  46. package/dist/diff-database-schema-RMwnSOnz.mjs +298 -0
  47. package/dist/diff-database-schema-RMwnSOnz.mjs.map +1 -0
  48. package/dist/diff-database-schema.d.mts +46 -0
  49. package/dist/diff-database-schema.d.mts.map +1 -0
  50. package/dist/diff-database-schema.mjs +2 -0
  51. package/dist/errors-DO-w0EUS.mjs +35 -0
  52. package/dist/errors-DO-w0EUS.mjs.map +1 -0
  53. package/dist/errors.d.mts +11 -9
  54. package/dist/errors.d.mts.map +1 -1
  55. package/dist/errors.mjs +1 -1
  56. package/dist/issue-planner.d.mts +35 -11
  57. package/dist/issue-planner.d.mts.map +1 -1
  58. package/dist/issue-planner.mjs +2 -2
  59. package/dist/migration.d.mts +5 -5
  60. package/dist/migration.d.mts.map +1 -1
  61. package/dist/migration.mjs +4 -4
  62. package/dist/namespace-ids-xtp_ZY86.mjs +7 -0
  63. package/dist/namespace-ids-xtp_ZY86.mjs.map +1 -0
  64. package/dist/native-type-normalizer.mjs +37 -1
  65. package/dist/native-type-normalizer.mjs.map +1 -0
  66. package/dist/nodes-B815pj_X.mjs +162 -0
  67. package/dist/nodes-B815pj_X.mjs.map +1 -0
  68. package/dist/nodes-BtQyZha6.d.mts +146 -0
  69. package/dist/nodes-BtQyZha6.d.mts.map +1 -0
  70. package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-CI00nS4z.mjs} +300 -31
  71. package/dist/op-factory-call-CI00nS4z.mjs.map +1 -0
  72. package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-D6_7-7Vc.d.mts} +68 -15
  73. package/dist/op-factory-call-D6_7-7Vc.d.mts.map +1 -0
  74. package/dist/op-factory-call.d.mts +2 -2
  75. package/dist/op-factory-call.mjs +2 -2
  76. package/dist/pack.d.mts +287 -3
  77. package/dist/pack.d.mts.map +1 -1
  78. package/dist/pack.mjs +1 -1
  79. package/dist/planner-CAHZN1Ez.mjs +422 -0
  80. package/dist/planner-CAHZN1Ez.mjs.map +1 -0
  81. package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-B8Nn6nHN.mjs} +12 -27
  82. package/dist/planner-ddl-builders-B8Nn6nHN.mjs.map +1 -0
  83. package/dist/planner-ddl-builders.d.mts +4 -6
  84. package/dist/planner-ddl-builders.d.mts.map +1 -1
  85. package/dist/planner-ddl-builders.mjs +2 -2
  86. package/dist/planner-identity-values-CJPha2Sz.mjs.map +1 -1
  87. package/dist/planner-identity-values.d.mts +8 -2
  88. package/dist/planner-identity-values.d.mts.map +1 -1
  89. package/dist/planner-identity-values.mjs +2 -2
  90. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-a-tjfKsA.d.mts} +4 -4
  91. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-a-tjfKsA.d.mts.map} +1 -1
  92. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-flkG4Y7n.mjs} +3 -3
  93. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-flkG4Y7n.mjs.map} +1 -1
  94. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  95. package/dist/planner-produced-postgres-migration.mjs +1 -1
  96. package/dist/{planner-sql-checks-jqUUGyQR.mjs → planner-sql-checks-C1-Kk3Eu.mjs} +2 -2
  97. package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-C1-Kk3Eu.mjs.map} +1 -1
  98. package/dist/planner-sql-checks.d.mts +2 -2
  99. package/dist/planner-sql-checks.d.mts.map +1 -1
  100. package/dist/planner-sql-checks.mjs +1 -1
  101. package/dist/{planner-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
  102. package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
  103. package/dist/planner-target-details.d.mts +1 -1
  104. package/dist/planner.d.mts +72 -17
  105. package/dist/planner.d.mts.map +1 -1
  106. package/dist/planner.mjs +3 -2
  107. package/dist/postgres-contract-view-C9j5cqP0.d.mts +34 -0
  108. package/dist/postgres-contract-view-C9j5cqP0.d.mts.map +1 -0
  109. package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-view-DWLNQbdR.mjs} +45 -41
  110. package/dist/postgres-contract-view-DWLNQbdR.mjs.map +1 -0
  111. package/dist/postgres-database-schema-node-BVdOffjC.d.mts +221 -0
  112. package/dist/postgres-database-schema-node-BVdOffjC.d.mts.map +1 -0
  113. package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-Bzzi0Asr.d.mts} +28 -9
  114. package/dist/postgres-migration-Bzzi0Asr.d.mts.map +1 -0
  115. package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-C92swCzd.mjs} +53 -45
  116. package/dist/postgres-migration-C92swCzd.mjs.map +1 -0
  117. package/dist/postgres-native-enum-xdiqmBf_.mjs +41 -0
  118. package/dist/postgres-native-enum-xdiqmBf_.mjs.map +1 -0
  119. package/dist/postgres-rls-policy--CSddvMR.d.mts +52 -0
  120. package/dist/postgres-rls-policy--CSddvMR.d.mts.map +1 -0
  121. package/dist/postgres-role-schema-node-BmCboEa_.mjs +198 -0
  122. package/dist/postgres-role-schema-node-BmCboEa_.mjs.map +1 -0
  123. package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-COEca21H.mjs} +188 -10
  124. package/dist/postgres-schema-COEca21H.mjs.map +1 -0
  125. package/dist/postgres-schema-DsrtYp2v.d.mts +269 -0
  126. package/dist/postgres-schema-DsrtYp2v.d.mts.map +1 -0
  127. package/dist/postgres-table-schema-node-9FCtCUz2.mjs +153 -0
  128. package/dist/postgres-table-schema-node-9FCtCUz2.mjs.map +1 -0
  129. package/dist/render-ops.d.mts +1 -1
  130. package/dist/{render-typescript-KMgosran.mjs → render-typescript-7yqILcwr.mjs} +45 -16
  131. package/dist/render-typescript-7yqILcwr.mjs.map +1 -0
  132. package/dist/render-typescript.mjs +1 -1
  133. package/dist/resolve-ddl-schema-ZkKxt2Fm.mjs +22 -0
  134. package/dist/resolve-ddl-schema-ZkKxt2Fm.mjs.map +1 -0
  135. package/dist/rls-canonicalize.d.mts +20 -0
  136. package/dist/rls-canonicalize.d.mts.map +1 -0
  137. package/dist/rls-canonicalize.mjs +2 -0
  138. package/dist/runtime.d.mts +6 -8
  139. package/dist/runtime.d.mts.map +1 -1
  140. package/dist/runtime.mjs +3 -3
  141. package/dist/runtime.mjs.map +1 -1
  142. package/dist/schema-ir-annotations.d.mts +15 -0
  143. package/dist/schema-ir-annotations.d.mts.map +1 -0
  144. package/dist/schema-ir-annotations.mjs +2 -0
  145. package/dist/types.d.mts +4 -140
  146. package/dist/types.mjs +5 -2
  147. package/dist/wire-name-rHHtr1h0.mjs +75 -0
  148. package/dist/wire-name-rHHtr1h0.mjs.map +1 -0
  149. package/package.json +23 -17
  150. package/src/contract-free/checks.ts +73 -0
  151. package/src/contract-free/ddl.ts +71 -1
  152. package/src/core/authoring.ts +467 -2
  153. package/src/core/codec-ids.ts +1 -0
  154. package/src/core/codec-type-map.ts +2 -0
  155. package/src/core/codecs.ts +180 -1
  156. package/src/core/ddl/nodes.ts +141 -2
  157. package/src/core/default-normalizer.ts +122 -2
  158. package/src/core/descriptor-meta.ts +10 -1
  159. package/src/core/entity-kinds.ts +41 -0
  160. package/src/core/errors.ts +14 -12
  161. package/src/core/migrations/bound-schema.ts +10 -0
  162. package/src/core/migrations/column-ddl-rendering.ts +117 -0
  163. package/src/core/migrations/contract-to-postgres-database-schema-node.ts +160 -0
  164. package/src/core/migrations/control-policy.ts +126 -44
  165. package/src/core/migrations/diff-database-schema.ts +253 -0
  166. package/src/core/migrations/issue-planner.ts +692 -652
  167. package/src/core/migrations/op-factory-call.ts +189 -21
  168. package/src/core/migrations/operations/columns.ts +24 -12
  169. package/src/core/migrations/operations/constraints.ts +1 -1
  170. package/src/core/migrations/operations/data-transform.ts +6 -0
  171. package/src/core/migrations/operations/dependencies.ts +2 -1
  172. package/src/core/migrations/operations/rls.ts +187 -0
  173. package/src/core/migrations/operations/shared.ts +0 -30
  174. package/src/core/migrations/planner-ddl-builders.ts +20 -58
  175. package/src/core/migrations/planner-identity-values.ts +1 -1
  176. package/src/core/migrations/planner-recipes.ts +31 -13
  177. package/src/core/migrations/planner-sql-checks.ts +1 -1
  178. package/src/core/migrations/planner-strategies.ts +248 -216
  179. package/src/core/migrations/planner-target-details.ts +3 -1
  180. package/src/core/migrations/planner.ts +386 -59
  181. package/src/core/migrations/postgres-migration.ts +70 -86
  182. package/src/core/migrations/render-typescript.ts +42 -15
  183. package/src/core/migrations/resolve-ddl-schema.ts +26 -0
  184. package/src/core/migrations/runner.ts +10 -16
  185. package/src/core/migrations/verify-postgres-namespaces.ts +47 -31
  186. package/src/core/namespace-ids.ts +3 -0
  187. package/src/core/postgres-contract-serializer.ts +46 -71
  188. package/src/core/postgres-contract-view.ts +48 -0
  189. package/src/core/postgres-native-enum.ts +51 -0
  190. package/src/core/postgres-rls-enablement.ts +34 -0
  191. package/src/core/postgres-rls-policy.ts +64 -0
  192. package/src/core/postgres-role.ts +59 -0
  193. package/src/core/postgres-schema-verifier.ts +10 -7
  194. package/src/core/postgres-schema.ts +64 -15
  195. package/src/core/postgres-validators.ts +34 -0
  196. package/src/core/psl-infer/infer-psl-contract.ts +1326 -0
  197. package/src/core/psl-infer/postgres-default-mapping.ts +16 -0
  198. package/src/core/psl-infer/postgres-type-map.ts +128 -0
  199. package/src/core/rls/canonicalize.ts +48 -0
  200. package/src/core/rls/wire-name.ts +33 -0
  201. package/src/core/schema-ir/postgres-database-schema-node.ts +61 -0
  202. package/src/core/schema-ir/postgres-namespace-schema-node.ts +79 -0
  203. package/src/core/schema-ir/postgres-policy-schema-node.ts +90 -0
  204. package/src/core/schema-ir/postgres-role-schema-node.ts +65 -0
  205. package/src/core/schema-ir/postgres-table-schema-node.ts +140 -0
  206. package/src/core/schema-ir/schema-node-kinds.ts +113 -0
  207. package/src/exports/codecs.ts +3 -0
  208. package/src/exports/contract-free.ts +11 -1
  209. package/src/exports/control.ts +27 -33
  210. package/src/exports/ddl.ts +6 -0
  211. package/src/exports/diff-database-schema.ts +7 -0
  212. package/src/exports/issue-planner.ts +1 -1
  213. package/src/exports/migration.ts +1 -0
  214. package/src/exports/op-factory-call.ts +1 -0
  215. package/src/exports/planner-ddl-builders.ts +0 -2
  216. package/src/exports/planner-identity-values.ts +4 -1
  217. package/src/exports/planner.ts +1 -0
  218. package/src/exports/rls-canonicalize.ts +7 -0
  219. package/src/exports/runtime.ts +1 -0
  220. package/src/exports/schema-ir-annotations.ts +1 -0
  221. package/src/exports/types.ts +34 -0
  222. package/dist/codec-ids-BvytN2P8.mjs.map +0 -1
  223. package/dist/codec-ids-CnXu9Qy3.d.mts.map +0 -1
  224. package/dist/codec-types-DHCkwPKE.d.mts.map +0 -1
  225. package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
  226. package/dist/ddl-QDyOSeLc.mjs.map +0 -1
  227. package/dist/default-normalizer-DyyCHQWs.mjs +0 -131
  228. package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
  229. package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
  230. package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
  231. package/dist/errors-CUk87ByX.mjs +0 -33
  232. package/dist/errors-CUk87ByX.mjs.map +0 -1
  233. package/dist/issue-planner-DL6g3CmE.mjs +0 -824
  234. package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
  235. package/dist/native-type-normalizer-Bc9XJzWC.mjs +0 -38
  236. package/dist/native-type-normalizer-Bc9XJzWC.mjs.map +0 -1
  237. package/dist/nodes-Bbhs2rwj.mjs +0 -76
  238. package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
  239. package/dist/nodes-pLeLgdis.d.mts +0 -67
  240. package/dist/nodes-pLeLgdis.d.mts.map +0 -1
  241. package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
  242. package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
  243. package/dist/planner-Bs_baQax.mjs +0 -324
  244. package/dist/planner-Bs_baQax.mjs.map +0 -1
  245. package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
  246. package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
  247. package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
  248. package/dist/postgres-migration-B5jKrXv3.mjs.map +0 -1
  249. package/dist/postgres-migration-Y4YBJqkS.d.mts.map +0 -1
  250. package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
  251. package/dist/render-typescript-KMgosran.mjs.map +0 -1
  252. package/dist/types.d.mts.map +0 -1
  253. package/src/core/postgres-enum-type-schema.ts +0 -17
@@ -0,0 +1,528 @@
1
+ import { a as PG_ENUM_CODEC_ID } from "./codec-ids-C_-Hj6bL.mjs";
2
+ import { t as PostgresNativeEnum } from "./postgres-native-enum-xdiqmBf_.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
+ import { i as normalizePredicate, r as computeContentHash, t as formatRlsPolicyWireName } from "./wire-name-rHHtr1h0.mjs";
5
+ import { temporalAuthoringPresets } from "@prisma-next/family-sql/control";
6
+ import { ifDefined } from "@prisma-next/utils/defined";
7
+ import { modelAttribute } from "@prisma-next/psl-parser";
8
+ //#region src/core/authoring.ts
9
+ /**
10
+ * `pg.enum(<ref>)` registers as an ordinary type constructor whose sole
11
+ * positional argument names a `native_enum` entity instead of carrying a
12
+ * literal value. The interpreter resolves the ref to the `native_enum`
13
+ * entity generically (driven by `entityRefArg`); the `pg/enum@1` codec
14
+ * descriptor's `columnFromEntity` hook (see `codecs.ts`) converts that
15
+ * entity into the column's `typeParams` and native type.
16
+ */
17
+ const postgresAuthoringTypes = { pg: { enum: {
18
+ kind: "typeConstructor",
19
+ entityRefArg: {
20
+ index: 0,
21
+ entityKind: "native_enum"
22
+ },
23
+ output: { codecId: PG_ENUM_CODEC_ID }
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
+ };
65
+ function readRefParam(block, key) {
66
+ const param = block.parameters[key];
67
+ return param?.kind === "ref" ? param.identifier : void 0;
68
+ }
69
+ function readValueParam(block, key) {
70
+ const param = block.parameters[key];
71
+ return param?.kind === "value" ? param.raw : void 0;
72
+ }
73
+ function readListRefParams(block, key) {
74
+ const param = block.parameters[key];
75
+ if (param?.kind !== "list") return [];
76
+ return param.items.flatMap((item) => item.kind === "ref" ? [item.identifier] : []);
77
+ }
78
+ /**
79
+ * Unwraps a quoted PSL string argument, inverting the printer's
80
+ * `escapePslString` escapes (`\\`, `\"`, `\n`, `\r`). An unknown escape
81
+ * sequence is kept verbatim, matching the printer-side `unescapePslString`
82
+ * convention.
83
+ */
84
+ function unwrapQuotedString(raw) {
85
+ if (!(raw.startsWith("\"") && raw.endsWith("\"") && raw.length >= 2)) return raw;
86
+ const inner = raw.slice(1, -1);
87
+ let result = "";
88
+ for (let i = 0; i < inner.length; i++) {
89
+ if (inner[i] !== "\\" || i + 1 >= inner.length) {
90
+ result += inner[i];
91
+ continue;
92
+ }
93
+ const next = inner[i + 1];
94
+ if (next === "\\" || next === "\"") result += next;
95
+ else if (next === "n") result += "\n";
96
+ else if (next === "r") result += "\r";
97
+ else {
98
+ result += "\\";
99
+ result += next;
100
+ }
101
+ i++;
102
+ }
103
+ return result;
104
+ }
105
+ function lowerRlsPolicyFromBlock(block, ctx) {
106
+ const prefix = block.name;
107
+ const operation = POLICY_KEYWORD_OPERATION[block.keyword] ?? "select";
108
+ const targetModelName = readRefParam(block, "target") ?? "";
109
+ const tableName = targetModelName.charAt(0).toLowerCase() + targetModelName.slice(1);
110
+ const roles = [...readListRefParams(block, "roles")].sort();
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;
126
+ return new PostgresRlsPolicy({
127
+ name: formatRlsPolicyWireName(prefix, computeContentHash({
128
+ ...ifDefined("using", using !== void 0 ? normalizePredicate(using) : void 0),
129
+ ...ifDefined("withCheck", withCheck !== void 0 ? normalizePredicate(withCheck) : void 0),
130
+ roles,
131
+ operation,
132
+ permissive: true
133
+ })),
134
+ prefix,
135
+ tableName,
136
+ namespaceId: block.namespaceId,
137
+ operation,
138
+ roles,
139
+ ...ifDefined("using", using),
140
+ ...ifDefined("withCheck", withCheck),
141
+ permissive: true
142
+ });
143
+ }
144
+ /**
145
+ * Lowers a `native_enum { memberName = "value" … @@map("type_name") }` block
146
+ * into a {@link PostgresNativeEnum}. Members must be authored as explicit
147
+ * `key = "value"` pairs — a bare (value-less) member is a diagnostic, not
148
+ * accepted (authoring-design.md §2.1). The parsed `memberName` is only used
149
+ * to duplicate-check and report diagnostics; the lowered entity carries just
150
+ * the member values (a native enum is value-only — the member "name" isn't
151
+ * a separate authoring concept from the value). `typeName` comes from
152
+ * `@@map` or defaults to the block name verbatim.
153
+ */
154
+ function lowerNativeEnumFromBlock(block, ctx) {
155
+ const sourceId = ctx.sourceId ?? "unknown";
156
+ const diagnostics = ctx.diagnostics;
157
+ const mapAttr = block.blockAttributes.find((a) => a.name === "map");
158
+ let typeName = block.name;
159
+ if (mapAttr) {
160
+ const rawArg = mapAttr.args[0]?.value;
161
+ const mapped = rawArg !== void 0 ? unwrapQuotedString(rawArg) : void 0;
162
+ if (mapped === void 0) {
163
+ diagnostics?.push({
164
+ code: "PSL_NATIVE_ENUM_INVALID_MAP",
165
+ message: `native_enum "${block.name}" @@map attribute must have a quoted type-name argument`,
166
+ sourceId,
167
+ span: mapAttr.span
168
+ });
169
+ return;
170
+ }
171
+ typeName = mapped;
172
+ }
173
+ let memberError = false;
174
+ const seenValues = /* @__PURE__ */ new Set();
175
+ const members = [];
176
+ for (const [memberName, paramValue] of Object.entries(block.parameters)) {
177
+ if (paramValue.kind === "bare") {
178
+ diagnostics?.push({
179
+ code: "PSL_NATIVE_ENUM_BARE_MEMBER",
180
+ message: `native_enum "${block.name}" member "${memberName}" has no value; members must be authored as "${memberName} = \\"value\\""`,
181
+ sourceId,
182
+ span: paramValue.span
183
+ });
184
+ memberError = true;
185
+ continue;
186
+ }
187
+ if (paramValue.kind !== "value") continue;
188
+ let jsonValue;
189
+ try {
190
+ jsonValue = JSON.parse(paramValue.raw);
191
+ } catch {
192
+ diagnostics?.push({
193
+ code: "PSL_EXTENSION_INVALID_VALUE",
194
+ message: `native_enum "${block.name}" member "${memberName}" value "${paramValue.raw}" is not valid JSON`,
195
+ sourceId,
196
+ span: paramValue.span
197
+ });
198
+ memberError = true;
199
+ continue;
200
+ }
201
+ if (typeof jsonValue !== "string") {
202
+ diagnostics?.push({
203
+ code: "PSL_EXTENSION_INVALID_VALUE",
204
+ message: `native_enum "${block.name}" member "${memberName}" value must be a string`,
205
+ sourceId,
206
+ span: paramValue.span
207
+ });
208
+ memberError = true;
209
+ continue;
210
+ }
211
+ if (seenValues.has(jsonValue)) {
212
+ diagnostics?.push({
213
+ code: "PSL_NATIVE_ENUM_DUPLICATE_MEMBER_VALUE",
214
+ message: `native_enum "${block.name}": duplicate member value "${jsonValue}"`,
215
+ sourceId,
216
+ span: paramValue.span
217
+ });
218
+ memberError = true;
219
+ continue;
220
+ }
221
+ seenValues.add(jsonValue);
222
+ members.push(jsonValue);
223
+ }
224
+ if (memberError) return void 0;
225
+ if (members.length === 0) {
226
+ diagnostics?.push({
227
+ code: "PSL_NATIVE_ENUM_MISSING_MEMBERS",
228
+ message: `native_enum "${block.name}" must have at least one member`,
229
+ sourceId,
230
+ span: block.span
231
+ });
232
+ return;
233
+ }
234
+ return new PostgresNativeEnum({
235
+ typeName,
236
+ members
237
+ });
238
+ }
239
+ const postgresAuthoringEntityTypes = {
240
+ role: {
241
+ kind: "entity",
242
+ discriminator: "role",
243
+ validatorSchema: PostgresRoleSchema,
244
+ output: { factory: (input) => new PostgresRole(input) }
245
+ },
246
+ rls: {
247
+ kind: "entity",
248
+ discriminator: "rls",
249
+ validatorSchema: PostgresRlsEnablementSchema,
250
+ output: { factory: (input) => new PostgresRlsEnablement(input) }
251
+ },
252
+ policy: {
253
+ kind: "entity",
254
+ discriminator: "policy",
255
+ validatorSchema: PostgresRlsPolicySchema,
256
+ output: { factory: lowerRlsPolicyFromBlock }
257
+ },
258
+ native_enum: {
259
+ kind: "entity",
260
+ discriminator: "native_enum",
261
+ validatorSchema: PostgresNativeEnumSchema,
262
+ output: {
263
+ factory: lowerNativeEnumFromBlock,
264
+ deriveValueSet: (entity) => ({
265
+ kind: "valueSet",
266
+ values: [...entity.members]
267
+ })
268
+ }
269
+ }
270
+ };
271
+ /**
272
+ * Field presets contributed by the Postgres target pack.
273
+ *
274
+ * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter
275
+ * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field
276
+ * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar
277
+ * surface (e.g. `Int`) lowers to byte-identical contracts.
278
+ *
279
+ * The `uuidNative` / `id.uuidv4Native` / `id.uuidv7Native` presets use the
280
+ * native Postgres `uuid` type (codecId `pg/uuid@1`). For cross-target
281
+ * portability use `uuidString` / `id.uuidv4String` / `id.uuidv7String` from
282
+ * the family pack instead.
283
+ */
284
+ /**
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`.
289
+ *
290
+ * The `roles` list uses `scope:'cross-space'` because same-namespace
291
+ * role ref resolution requires PSL namespace entries keyed by `refKind`
292
+ * (i.e. `'role'`), which in turn requires the role block discriminator to
293
+ * equal `'role'`. Aligning discriminator with refKind is tracked for
294
+ * slice 4 (cross-space roles). Until then cross-space passes validation
295
+ * unconditionally and the authored role names flow through unchanged.
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
+ };
320
+ const postgresAuthoringPslBlockDescriptors = {
321
+ policy_select: {
322
+ kind: "pslBlock",
323
+ keyword: "policy_select",
324
+ discriminator: "policy",
325
+ name: { required: true },
326
+ parameters: {
327
+ target: policyTargetParam,
328
+ roles: policyRolesParam,
329
+ using: policyPredicateParam
330
+ },
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
382
+ },
383
+ /**
384
+ * PSL block descriptor for `native_enum`.
385
+ *
386
+ * Reuses the existing variadic-block mechanism (the same shape the SQL
387
+ * family's `enum` block ships): the body is an open `memberName = "value"`
388
+ * list. `variadicParameters: true` opens the block to arbitrary keys
389
+ * beyond the declared (empty) `parameters` set — the lowering factory
390
+ * (`lowerNativeEnumFromBlock`) turns the variadic entries into ordered
391
+ * members and rejects a bare (value-less) member.
392
+ */
393
+ native_enum: {
394
+ kind: "pslBlock",
395
+ keyword: "native_enum",
396
+ discriminator: "native_enum",
397
+ name: { required: true },
398
+ parameters: {},
399
+ variadicParameters: true
400
+ }
401
+ };
402
+ /**
403
+ * `@@` model attributes contributed by the Postgres target pack.
404
+ *
405
+ * `@@rls` is argument-less: presence marks the model's table
406
+ * RLS-controlled. It lowers to a {@link PostgresRlsEnablement} marker in
407
+ * the namespace's `entries.rls`, keyed by the model's table name — the
408
+ * marker (never the policy set) is what drives
409
+ * `ENABLE`/`DISABLE ROW LEVEL SECURITY` planning.
410
+ */
411
+ const postgresAuthoringModelAttributes = { rls: {
412
+ kind: "modelAttribute",
413
+ attribute: "rls",
414
+ spec: modelAttribute("rls", {}),
415
+ lower: (_parsed, ctx) => ({
416
+ key: ctx.storageName,
417
+ entity: new PostgresRlsEnablement({
418
+ tableName: ctx.storageName,
419
+ namespaceId: ctx.namespaceId
420
+ })
421
+ })
422
+ } };
423
+ const postgresAuthoringFieldPresets = {
424
+ text: {
425
+ kind: "fieldPreset",
426
+ output: {
427
+ codecId: "pg/text@1",
428
+ nativeType: "text"
429
+ }
430
+ },
431
+ int: {
432
+ kind: "fieldPreset",
433
+ output: {
434
+ codecId: "pg/int4@1",
435
+ nativeType: "int4"
436
+ }
437
+ },
438
+ bigint: {
439
+ kind: "fieldPreset",
440
+ output: {
441
+ codecId: "pg/int8@1",
442
+ nativeType: "int8"
443
+ }
444
+ },
445
+ float: {
446
+ kind: "fieldPreset",
447
+ output: {
448
+ codecId: "pg/float8@1",
449
+ nativeType: "float8"
450
+ }
451
+ },
452
+ decimal: {
453
+ kind: "fieldPreset",
454
+ output: {
455
+ codecId: "pg/numeric@1",
456
+ nativeType: "numeric"
457
+ }
458
+ },
459
+ boolean: {
460
+ kind: "fieldPreset",
461
+ output: {
462
+ codecId: "pg/bool@1",
463
+ nativeType: "bool"
464
+ }
465
+ },
466
+ json: {
467
+ kind: "fieldPreset",
468
+ output: {
469
+ codecId: "pg/jsonb@1",
470
+ nativeType: "jsonb"
471
+ }
472
+ },
473
+ bytes: {
474
+ kind: "fieldPreset",
475
+ output: {
476
+ codecId: "pg/bytea@1",
477
+ nativeType: "bytea"
478
+ }
479
+ },
480
+ dateTime: {
481
+ kind: "fieldPreset",
482
+ output: {
483
+ codecId: "pg/timestamptz@1",
484
+ nativeType: "timestamptz"
485
+ }
486
+ },
487
+ temporal: /* @__PURE__ */ temporalAuthoringPresets({
488
+ codecId: "pg/timestamptz@1",
489
+ nativeType: "timestamptz"
490
+ }),
491
+ uuidNative: {
492
+ kind: "fieldPreset",
493
+ output: {
494
+ codecId: "pg/uuid@1",
495
+ nativeType: "uuid"
496
+ }
497
+ },
498
+ id: {
499
+ uuidv4Native: {
500
+ kind: "fieldPreset",
501
+ output: {
502
+ codecId: "pg/uuid@1",
503
+ nativeType: "uuid",
504
+ executionDefaults: { onCreate: {
505
+ kind: "generator",
506
+ id: "uuidv4"
507
+ } },
508
+ id: true
509
+ }
510
+ },
511
+ uuidv7Native: {
512
+ kind: "fieldPreset",
513
+ output: {
514
+ codecId: "pg/uuid@1",
515
+ nativeType: "uuid",
516
+ executionDefaults: { onCreate: {
517
+ kind: "generator",
518
+ id: "uuidv7"
519
+ } },
520
+ id: true
521
+ }
522
+ }
523
+ }
524
+ };
525
+ //#endregion
526
+ export { postgresAuthoringTypes as a, postgresAuthoringPslBlockDescriptors as i, postgresAuthoringFieldPresets as n, postgresAuthoringModelAttributes as r, postgresAuthoringEntityTypes as t };
527
+
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 satisfies AuthoringFieldNamespace;\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAa,yBAAyB,EACpC,IAAI,EACF,MAAM;CACJ,MAAM;CACN,cAAc;EAAE,OAAO;EAAG,YAAY;CAAc;CACpD,QAAQ,EACN,SAAS,iBACX;AACF,EACF,EACF;;;;;;AAWA,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,WAAW;CAC/B,IAAI,OAAO,SAAS,QAAQ,OAAO,CAAC;CACpC,OAAO,MA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ACF;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"}
@@ -3,6 +3,7 @@ import { SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC
3
3
  //#region src/core/codec-ids.d.ts
4
4
  declare const PG_TEXT_CODEC_ID: "pg/text@1";
5
5
  declare const PG_TEXT_ARRAY_CODEC_ID: "pg/text-array@1";
6
+ declare const PG_ENUM_CODEC_ID: "pg/enum@1";
6
7
  declare const PG_CHAR_CODEC_ID: "pg/char@1";
7
8
  declare const PG_VARCHAR_CODEC_ID: "pg/varchar@1";
8
9
  declare const PG_INT_CODEC_ID: "pg/int@1";
@@ -26,5 +27,5 @@ declare const PG_JSONB_CODEC_ID: "pg/jsonb@1";
26
27
  declare const PG_BYTEA_CODEC_ID: "pg/bytea@1";
27
28
  declare const PG_UUID_CODEC_ID: "pg/uuid@1";
28
29
  //#endregion
29
- export { SQL_VARCHAR_CODEC_ID as A, PG_VARBIT_CODEC_ID as C, SQL_INT_CODEC_ID as D, SQL_FLOAT_CODEC_ID as E, SQL_TEXT_CODEC_ID as O, PG_UUID_CODEC_ID as S, SQL_CHAR_CODEC_ID as T, PG_TEXT_CODEC_ID as _, PG_FLOAT4_CODEC_ID as a, PG_TIMETZ_CODEC_ID as b, PG_INT2_CODEC_ID as c, PG_INTERVAL_CODEC_ID as d, PG_INT_CODEC_ID as f, PG_TEXT_ARRAY_CODEC_ID as g, PG_NUMERIC_CODEC_ID as h, PG_CHAR_CODEC_ID as i, SQL_TIMESTAMP_CODEC_ID as k, PG_INT4_CODEC_ID as l, PG_JSON_CODEC_ID as m, PG_BOOL_CODEC_ID as n, PG_FLOAT8_CODEC_ID as o, PG_JSONB_CODEC_ID as p, PG_BYTEA_CODEC_ID as r, PG_FLOAT_CODEC_ID as s, PG_BIT_CODEC_ID as t, PG_INT8_CODEC_ID as u, PG_TIMESTAMPTZ_CODEC_ID as v, PG_VARCHAR_CODEC_ID as w, PG_TIME_CODEC_ID as x, PG_TIMESTAMP_CODEC_ID as y };
30
- //# sourceMappingURL=codec-ids-CnXu9Qy3.d.mts.map
30
+ export { SQL_TIMESTAMP_CODEC_ID as A, PG_UUID_CODEC_ID as C, SQL_FLOAT_CODEC_ID as D, SQL_CHAR_CODEC_ID as E, SQL_INT_CODEC_ID as O, PG_TIME_CODEC_ID as S, PG_VARCHAR_CODEC_ID as T, PG_TEXT_ARRAY_CODEC_ID as _, PG_ENUM_CODEC_ID as a, PG_TIMESTAMP_CODEC_ID as b, PG_FLOAT_CODEC_ID as c, PG_INT8_CODEC_ID as d, PG_INTERVAL_CODEC_ID as f, PG_NUMERIC_CODEC_ID as g, PG_JSON_CODEC_ID as h, PG_CHAR_CODEC_ID as i, SQL_VARCHAR_CODEC_ID as j, SQL_TEXT_CODEC_ID as k, PG_INT2_CODEC_ID as l, PG_JSONB_CODEC_ID as m, PG_BOOL_CODEC_ID as n, PG_FLOAT4_CODEC_ID as o, PG_INT_CODEC_ID as p, PG_BYTEA_CODEC_ID as r, PG_FLOAT8_CODEC_ID as s, PG_BIT_CODEC_ID as t, PG_INT4_CODEC_ID as u, PG_TEXT_CODEC_ID as v, PG_VARBIT_CODEC_ID as w, PG_TIMETZ_CODEC_ID as x, PG_TIMESTAMPTZ_CODEC_ID as y };
31
+ //# sourceMappingURL=codec-ids-BzrFF-I4.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec-ids-BzrFF-I4.d.mts","names":[],"sources":["../src/core/codec-ids.ts"],"mappings":";;;cAQa,gBAAA;AAAA,cACA,sBAAA;AAAA,cACA,gBAAA;AAAA,cACA,gBAAA;AAAA,cACA,mBAAA;AAAA,cACA,eAAA;AAAA,cACA,gBAAA;AAAA,cACA,gBAAA;AAAA,cACA,gBAAA;AAAA,cACA,iBAAA;AAAA,cACA,kBAAA;AAAA,cACA,kBAAA;AAAA,cACA,mBAAA;AAAA,cACA,gBAAA;AAAA,cACA,eAAA;AAAA,cACA,kBAAA;AAAA,cACA,qBAAA;AAAA,cACA,uBAAA;AAAA,cACA,gBAAA;AAAA,cACA,kBAAA;AAAA,cACA,oBAAA;AAAA,cACA,gBAAA;AAAA,cACA,iBAAA;AAAA,cACA,iBAAA;AAAA,cACA,gBAAA"}
@@ -2,6 +2,7 @@ import { SQL_CHAR_CODEC_ID, SQL_FLOAT_CODEC_ID, SQL_INT_CODEC_ID, SQL_TEXT_CODEC
2
2
  //#region src/core/codec-ids.ts
3
3
  const PG_TEXT_CODEC_ID = "pg/text@1";
4
4
  const PG_TEXT_ARRAY_CODEC_ID = "pg/text-array@1";
5
+ const PG_ENUM_CODEC_ID = "pg/enum@1";
5
6
  const PG_CHAR_CODEC_ID = "pg/char@1";
6
7
  const PG_VARCHAR_CODEC_ID = "pg/varchar@1";
7
8
  const PG_INT_CODEC_ID = "pg/int@1";
@@ -25,6 +26,6 @@ const PG_JSONB_CODEC_ID = "pg/jsonb@1";
25
26
  const PG_BYTEA_CODEC_ID = "pg/bytea@1";
26
27
  const PG_UUID_CODEC_ID = "pg/uuid@1";
27
28
  //#endregion
28
- export { SQL_VARCHAR_CODEC_ID as A, PG_VARBIT_CODEC_ID as C, SQL_INT_CODEC_ID as D, SQL_FLOAT_CODEC_ID as E, SQL_TEXT_CODEC_ID as O, PG_UUID_CODEC_ID as S, SQL_CHAR_CODEC_ID as T, PG_TEXT_CODEC_ID as _, PG_FLOAT4_CODEC_ID as a, PG_TIMETZ_CODEC_ID as b, PG_INT2_CODEC_ID as c, PG_INTERVAL_CODEC_ID as d, PG_INT_CODEC_ID as f, PG_TEXT_ARRAY_CODEC_ID as g, PG_NUMERIC_CODEC_ID as h, PG_CHAR_CODEC_ID as i, SQL_TIMESTAMP_CODEC_ID as k, PG_INT4_CODEC_ID as l, PG_JSON_CODEC_ID as m, PG_BOOL_CODEC_ID as n, PG_FLOAT8_CODEC_ID as o, PG_JSONB_CODEC_ID as p, PG_BYTEA_CODEC_ID as r, PG_FLOAT_CODEC_ID as s, PG_BIT_CODEC_ID as t, PG_INT8_CODEC_ID as u, PG_TIMESTAMPTZ_CODEC_ID as v, PG_VARCHAR_CODEC_ID as w, PG_TIME_CODEC_ID as x, PG_TIMESTAMP_CODEC_ID as y };
29
+ export { SQL_TIMESTAMP_CODEC_ID as A, PG_UUID_CODEC_ID as C, SQL_FLOAT_CODEC_ID as D, SQL_CHAR_CODEC_ID as E, SQL_INT_CODEC_ID as O, PG_TIME_CODEC_ID as S, PG_VARCHAR_CODEC_ID as T, PG_TEXT_ARRAY_CODEC_ID as _, PG_ENUM_CODEC_ID as a, PG_TIMESTAMP_CODEC_ID as b, PG_FLOAT_CODEC_ID as c, PG_INT8_CODEC_ID as d, PG_INTERVAL_CODEC_ID as f, PG_NUMERIC_CODEC_ID as g, PG_JSON_CODEC_ID as h, PG_CHAR_CODEC_ID as i, SQL_VARCHAR_CODEC_ID as j, SQL_TEXT_CODEC_ID as k, PG_INT2_CODEC_ID as l, PG_JSONB_CODEC_ID as m, PG_BOOL_CODEC_ID as n, PG_FLOAT4_CODEC_ID as o, PG_INT_CODEC_ID as p, PG_BYTEA_CODEC_ID as r, PG_FLOAT8_CODEC_ID as s, PG_BIT_CODEC_ID as t, PG_INT4_CODEC_ID as u, PG_TEXT_CODEC_ID as v, PG_VARBIT_CODEC_ID as w, PG_TIMETZ_CODEC_ID as x, PG_TIMESTAMPTZ_CODEC_ID as y };
29
30
 
30
- //# sourceMappingURL=codec-ids-BvytN2P8.mjs.map
31
+ //# sourceMappingURL=codec-ids-C_-Hj6bL.mjs.map