@prisma-next/target-postgres 0.14.0-dev.11 → 0.14.0-dev.13

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 (126) hide show
  1. package/dist/canonicalize-Bn3BM1Cn.mjs +46 -0
  2. package/dist/canonicalize-Bn3BM1Cn.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/contract-free.d.mts +1 -1
  6. package/dist/contract-free.d.mts.map +1 -1
  7. package/dist/contract-free.mjs +2 -2
  8. package/dist/control.d.mts +1 -1
  9. package/dist/control.mjs +4 -4
  10. package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-qKy1U5V9.d.mts} +2 -2
  11. package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-qKy1U5V9.d.mts.map} +1 -1
  12. package/dist/data-transform.d.mts +1 -1
  13. package/dist/{ddl-QDyOSeLc.mjs → ddl-BlsTIBeP.mjs} +54 -4
  14. package/dist/ddl-BlsTIBeP.mjs.map +1 -0
  15. package/dist/ddl.d.mts +3 -2
  16. package/dist/ddl.mjs +2 -2
  17. package/dist/descriptor-meta-b_SzXwen.mjs +239 -0
  18. package/dist/descriptor-meta-b_SzXwen.mjs.map +1 -0
  19. package/dist/{issue-planner-DL6g3CmE.mjs → issue-planner-CwoeupPM.mjs} +9 -6
  20. package/dist/{issue-planner-DL6g3CmE.mjs.map → issue-planner-CwoeupPM.mjs.map} +1 -1
  21. package/dist/issue-planner.d.mts +3 -3
  22. package/dist/issue-planner.d.mts.map +1 -1
  23. package/dist/issue-planner.mjs +1 -1
  24. package/dist/migration.d.mts +3 -3
  25. package/dist/migration.mjs +2 -2
  26. package/dist/{nodes-Bbhs2rwj.mjs → nodes-DhDIIhBT.mjs} +44 -2
  27. package/dist/nodes-DhDIIhBT.mjs.map +1 -0
  28. package/dist/{nodes-pLeLgdis.d.mts → nodes-YvdohJ2X.d.mts} +40 -3
  29. package/dist/nodes-YvdohJ2X.d.mts.map +1 -0
  30. package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-DXHAIisl.d.mts} +37 -4
  31. package/dist/op-factory-call-DXHAIisl.d.mts.map +1 -0
  32. package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-tMksrGIq.mjs} +146 -4
  33. package/dist/op-factory-call-tMksrGIq.mjs.map +1 -0
  34. package/dist/op-factory-call.d.mts +1 -1
  35. package/dist/op-factory-call.mjs +1 -1
  36. package/dist/pack.d.mts +74 -1
  37. package/dist/pack.d.mts.map +1 -1
  38. package/dist/pack.mjs +1 -1
  39. package/dist/{planner-Bs_baQax.mjs → planner-BbSZJVW7.mjs} +114 -22
  40. package/dist/planner-BbSZJVW7.mjs.map +1 -0
  41. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-C0FHnEsV.mjs} +2 -2
  42. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-C0FHnEsV.mjs.map} +1 -1
  43. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-DfM5lBv1.d.mts} +3 -3
  44. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-DfM5lBv1.d.mts.map} +1 -1
  45. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  46. package/dist/planner-produced-postgres-migration.mjs +1 -1
  47. package/dist/{planner-sql-checks-jqUUGyQR.mjs → planner-sql-checks-CI6Z21mm.mjs} +2 -2
  48. package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-CI6Z21mm.mjs.map} +1 -1
  49. package/dist/planner-sql-checks.mjs +1 -1
  50. package/dist/{planner-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
  51. package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
  52. package/dist/planner-target-details.d.mts +1 -1
  53. package/dist/planner.d.mts +35 -3
  54. package/dist/planner.d.mts.map +1 -1
  55. package/dist/planner.mjs +2 -2
  56. package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-serializer-k5eg5ZUZ.mjs} +29 -16
  57. package/dist/postgres-contract-serializer-k5eg5ZUZ.mjs.map +1 -0
  58. package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-BJWxullf.mjs} +2 -2
  59. package/dist/{postgres-migration-B5jKrXv3.mjs.map → postgres-migration-BJWxullf.mjs.map} +1 -1
  60. package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-D22a2y0l.d.mts} +4 -4
  61. package/dist/{postgres-migration-Y4YBJqkS.d.mts.map → postgres-migration-D22a2y0l.d.mts.map} +1 -1
  62. package/dist/postgres-rls-policy-D_z1osEq.d.mts +60 -0
  63. package/dist/postgres-rls-policy-D_z1osEq.d.mts.map +1 -0
  64. package/dist/postgres-role-_CCuyPCQ.d.mts +33 -0
  65. package/dist/postgres-role-_CCuyPCQ.d.mts.map +1 -0
  66. package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-BVDr_61a.mjs} +139 -3
  67. package/dist/postgres-schema-BVDr_61a.mjs.map +1 -0
  68. package/dist/postgres-schema-D0h4lsw2.d.mts +158 -0
  69. package/dist/postgres-schema-D0h4lsw2.d.mts.map +1 -0
  70. package/dist/postgres-schema-ir-BF0X8jit.mjs +66 -0
  71. package/dist/postgres-schema-ir-BF0X8jit.mjs.map +1 -0
  72. package/dist/postgres-schema-ir-BQ3RpZMz.d.mts +60 -0
  73. package/dist/postgres-schema-ir-BQ3RpZMz.d.mts.map +1 -0
  74. package/dist/postgres-schema-ir-annotations-El62Sywa.mjs +14 -0
  75. package/dist/postgres-schema-ir-annotations-El62Sywa.mjs.map +1 -0
  76. package/dist/render-ops.d.mts +1 -1
  77. package/dist/rls-canonicalize.d.mts +2 -0
  78. package/dist/rls-canonicalize.mjs +2 -0
  79. package/dist/runtime.d.mts +3 -2
  80. package/dist/runtime.d.mts.map +1 -1
  81. package/dist/runtime.mjs +2 -2
  82. package/dist/schema-ir-annotations.d.mts +8 -0
  83. package/dist/schema-ir-annotations.d.mts.map +1 -0
  84. package/dist/schema-ir-annotations.mjs +2 -0
  85. package/dist/types.d.mts +5 -140
  86. package/dist/types.mjs +3 -2
  87. package/package.json +21 -17
  88. package/src/contract-free/checks.ts +73 -0
  89. package/src/contract-free/ddl.ts +35 -0
  90. package/src/core/authoring.ts +115 -1
  91. package/src/core/ddl/nodes.ts +68 -1
  92. package/src/core/descriptor-meta.ts +4 -0
  93. package/src/core/entity-kinds.ts +16 -0
  94. package/src/core/migrations/control-policy.ts +3 -0
  95. package/src/core/migrations/issue-planner.ts +8 -0
  96. package/src/core/migrations/op-factory-call.ts +96 -0
  97. package/src/core/migrations/operations/rls.ts +106 -0
  98. package/src/core/migrations/planner-target-details.ts +3 -1
  99. package/src/core/migrations/planner.ts +99 -1
  100. package/src/core/migrations/verify-postgres-namespaces.ts +12 -15
  101. package/src/core/migrations/verify-postgres-rls-policies.ts +62 -0
  102. package/src/core/postgres-contract-serializer.ts +43 -19
  103. package/src/core/postgres-rls-policy.ts +103 -0
  104. package/src/core/postgres-role.ts +53 -0
  105. package/src/core/postgres-schema-ir-annotations.ts +22 -0
  106. package/src/core/postgres-schema-ir.ts +101 -0
  107. package/src/core/postgres-schema.ts +24 -4
  108. package/src/core/postgres-validators.ts +20 -0
  109. package/src/core/rls/canonicalize.ts +48 -0
  110. package/src/exports/ddl.ts +3 -0
  111. package/src/exports/planner.ts +1 -0
  112. package/src/exports/rls-canonicalize.ts +6 -0
  113. package/src/exports/schema-ir-annotations.ts +1 -0
  114. package/src/exports/types.ts +12 -0
  115. package/dist/ddl-QDyOSeLc.mjs.map +0 -1
  116. package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
  117. package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
  118. package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
  119. package/dist/nodes-pLeLgdis.d.mts.map +0 -1
  120. package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
  121. package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
  122. package/dist/planner-Bs_baQax.mjs.map +0 -1
  123. package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
  124. package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
  125. package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
  126. package/dist/types.d.mts.map +0 -1
@@ -0,0 +1,46 @@
1
+ import { createHash } from "node:crypto";
2
+ //#region src/core/rls/canonicalize.ts
3
+ /**
4
+ * Stabilizes an authored predicate for hashing: trim, and collapse runs of
5
+ * internal whitespace to a single space.
6
+ *
7
+ * This is deliberately minimal. The content hash is the equivalence relation
8
+ * for a policy, and the wire name (prefix + hash) is the only thing ever
9
+ * compared — we never recompute the hash from an introspected policy body, so
10
+ * there is no need to match Postgres's reprinted form. Minimal normalization
11
+ * also protects the no-collision property: aggressive rewriting (lowercasing,
12
+ * paren-stripping, cast-alias folding) risks collapsing two distinct predicates
13
+ * onto one hash. Out-of-band alteration of a hashed policy is unsupported.
14
+ *
15
+ * The normalizer is a stability commitment: any change re-suffixes all wire names.
16
+ */
17
+ function normalizePredicate(sql) {
18
+ return sql.replace(/\s+/g, " ").trim();
19
+ }
20
+ /**
21
+ * Returns the first 8 lowercase hex characters of the SHA-256 digest over the
22
+ * canonical content tuple for an RLS policy:
23
+ *
24
+ * [normalize(using), normalize(withCheck), sortedRoles, operation, permissive]
25
+ *
26
+ * Schema and table are excluded (they are orthogonal to policy equivalence).
27
+ * Uses `JSON.stringify` for a deterministic encoding.
28
+ */
29
+ function computeContentHash(parts) {
30
+ const using = normalizePredicate(parts.using ?? "");
31
+ const withCheck = normalizePredicate(parts.withCheck ?? "");
32
+ const roles = [...new Set(parts.roles)].sort();
33
+ const permissive = parts.permissive ? "permissive" : "restrictive";
34
+ const tuple = JSON.stringify([
35
+ using,
36
+ withCheck,
37
+ roles,
38
+ parts.operation,
39
+ permissive
40
+ ]);
41
+ return createHash("sha256").update(tuple).digest("hex").slice(0, 8);
42
+ }
43
+ //#endregion
44
+ export { normalizePredicate as n, computeContentHash as t };
45
+
46
+ //# sourceMappingURL=canonicalize-Bn3BM1Cn.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonicalize-Bn3BM1Cn.mjs","names":[],"sources":["../src/core/rls/canonicalize.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\n\nexport type RlsPolicyOperation = 'select' | 'insert' | 'update' | 'delete' | 'all';\n\nexport interface ContentHashParts {\n readonly using?: string;\n readonly withCheck?: string;\n readonly roles: readonly string[];\n readonly operation: RlsPolicyOperation;\n readonly permissive: boolean;\n}\n\n/**\n * Stabilizes an authored predicate for hashing: trim, and collapse runs of\n * internal whitespace to a single space.\n *\n * This is deliberately minimal. The content hash is the equivalence relation\n * for a policy, and the wire name (prefix + hash) is the only thing ever\n * compared — we never recompute the hash from an introspected policy body, so\n * there is no need to match Postgres's reprinted form. Minimal normalization\n * also protects the no-collision property: aggressive rewriting (lowercasing,\n * paren-stripping, cast-alias folding) risks collapsing two distinct predicates\n * onto one hash. Out-of-band alteration of a hashed policy is unsupported.\n *\n * The normalizer is a stability commitment: any change re-suffixes all wire names.\n */\nexport function normalizePredicate(sql: string): string {\n return sql.replace(/\\s+/g, ' ').trim();\n}\n\n/**\n * Returns the first 8 lowercase hex characters of the SHA-256 digest over the\n * canonical content tuple for an RLS policy:\n *\n * [normalize(using), normalize(withCheck), sortedRoles, operation, permissive]\n *\n * Schema and table are excluded (they are orthogonal to policy equivalence).\n * Uses `JSON.stringify` for a deterministic encoding.\n */\nexport function computeContentHash(parts: ContentHashParts): string {\n const using = normalizePredicate(parts.using ?? '');\n const withCheck = normalizePredicate(parts.withCheck ?? '');\n const roles = [...new Set(parts.roles)].sort();\n const permissive = parts.permissive ? 'permissive' : 'restrictive';\n\n const tuple = JSON.stringify([using, withCheck, roles, parts.operation, permissive]);\n return createHash('sha256').update(tuple).digest('hex').slice(0, 8);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,SAAgB,mBAAmB,KAAqB;CACtD,OAAO,IAAI,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;AACvC;;;;;;;;;;AAWA,SAAgB,mBAAmB,OAAiC;CAClE,MAAM,QAAQ,mBAAmB,MAAM,SAAS,EAAE;CAClD,MAAM,YAAY,mBAAmB,MAAM,aAAa,EAAE;CAC1D,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,MAAM,KAAK,CAAC,CAAC,CAAC,KAAK;CAC7C,MAAM,aAAa,MAAM,aAAa,eAAe;CAErD,MAAM,QAAQ,KAAK,UAAU;EAAC;EAAO;EAAW;EAAO,MAAM;EAAW;CAAU,CAAC;CACnF,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC;AACpE"}
@@ -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"}
@@ -1,4 +1,4 @@
1
- import { a as PostgresAlterTable, o as PostgresCreateSchema, r as AnyAlterTableAction, s as PostgresCreateTable, t as AddColumnAction } from "./nodes-pLeLgdis.mjs";
1
+ import { a as PostgresAlterTable, c as PostgresCreateTable, r as AnyAlterTableAction, s as PostgresCreateSchema, t as AddColumnAction } from "./nodes-YvdohJ2X.mjs";
2
2
  import { t as PostgresTableSource } from "./table-source-BvFo7gVs.mjs";
3
3
  import { DdlColumn, DdlNode, DdlTableConstraint, SelectAst } from "@prisma-next/sql-relational-core/ast";
4
4
  import { CfExpr, ColumnDescriptor, ColumnSchema, TableHandle } from "@prisma-next/sql-relational-core/contract-free";
@@ -1 +1 @@
1
- {"version":3,"file":"contract-free.d.mts","names":[],"sources":["../src/contract-free/checks.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WAAA,CAAY,OAAA;EAAA,SACjB,KAAA;EAAA,SACA,MAAA;EAAA,SACA,WAAA;EAAA,SACA,OAAA,WAAkB,SAAA;EAAA,SAClB,WAAA,YAAuB,kBAAA;AAAA,IAC9B,mBAAA;;;;;iBAQY,YAAA,CAAa,OAAA;EAAA,SAClB,MAAA;EAAA,SACA,WAAA;AAAA,IACP,oBAAoB;;;;;;iBASR,eAAA,CAAgB,MAAA,EAAQ,SAAA,GAAY,eAAe;;;AHIpC;AAiB/B;iBGbgB,UAAA,CAAW,OAAA;EAAA,SAChB,KAAA;EAAA,SACA,MAAA;EAAA,SACA,OAAA,WAAkB,mBAAA;AAAA,IACzB,kBAAkB"}
1
+ {"version":3,"file":"contract-free.d.mts","names":[],"sources":["../src/contract-free/checks.ts","../src/contract-free/columns.ts","../src/contract-free/control-bootstrap.ts","../src/contract-free/ddl.ts"],"mappings":";;;;;;;;;;AAiBA;iBAAgB,UAAA,CAAW,aAAA,WAAwB,MAAM;AAAA,UASxC,uBAAA;EACf,WAAA,IAAe,SAAA;EACf,YAAA,IAAgB,SAAS;AAAA;;;;;;;;;AAAA;iBAYX,cAAA,CAAe,MAAA,UAAgB,KAAA,WAAgB,uBAAuB;AAAA,UAWrE,4BAAA;EACf,iBAAA,IAAqB,SAAA;EACrB,gBAAA,IAAoB,SAAS;AAAA;;;;AAbuD;AAWtF;;;;;;;;;AAE+B;iBAiBf,mBAAA,CAAoB,OAAA;EAAA,SACzB,cAAA;EAAA,SACA,MAAA;EAAA,SACA,KAAA;AAAA,IACP,4BAA4B;AAAA,UAuDf,wBAAA;EACf,aAAA,IAAiB,SAAA;EACjB,YAAA,IAAgB,SAAS;AAAA;;AAzDK;AAuDhC;;;iBAUgB,eAAA,CAAgB,OAAA;EAAA,SACrB,MAAA;EAAA,SACA,KAAA;EAAA,SACA,MAAA;AAAA,IACP,wBAAwB;;AAZD;AAQ3B;;iBAgBgB,oBAAA,CAAqB,OAAA;EAAA,SAC1B,MAAA;EAAA,SACA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AO,OAAA,KAAU,gBAAgD;AAAA,cACzE,KAAA,GAAS,IAAA,GAAO,OAAA,KAAU,gBAAiD;AAAA,cAC3E,SAAA,GAAa,IAAA,GAAO,OAAA,KAAU,gBAAsD;AAAA,cACpF,WAAA,GAAe,IAAA,GAAO,OAAA,KAAU,gBACR;ADZoB;AASzD;;;;;;;;;AAE2B;AAY3B;AAvByD,iBC0BzC,OAAA,gBAAuB,YAAA,EACrC,MAAA;EAAA,SAAmB,IAAA;EAAA,SAAuB,MAAA;EAAA,SAA0B,KAAA;AAAA,GACpE,OAAA,EAAS,MAAA,GACR,WAAA,CAAY,MAAA;;;iBCEC,+BAAA,aAA4C,OAAO;AAAA,iBAInD,iCAAA,aAA8C,OAAO;;;;;;;AFnCrE;;;;AAAyD;AASzD;;;;;iBGAgB,WAAA,CAAY,OAAA;EAAA,SACjB,KAAA;EAAA,SACA,MAAA;EAAA,SACA,WAAA;EAAA,SACA,OAAA,WAAkB,SAAA;EAAA,SAClB,WAAA,YAAuB,kBAAA;AAAA,IAC9B,mBAAA;;;;;iBAQY,YAAA,CAAa,OAAA;EAAA,SAClB,MAAA;EAAA,SACA,WAAA;AAAA,IACP,oBAAoB;;;;;;iBASR,eAAA,CAAgB,MAAA,EAAQ,SAAA,GAAY,eAAe;;;AHCpC;AAiB/B;iBGVgB,UAAA,CAAW,OAAA;EAAA,SAChB,KAAA;EAAA,SACA,MAAA;EAAA,SACA,OAAA,WAAkB,mBAAA;AAAA,IACzB,kBAAkB"}
@@ -1,6 +1,6 @@
1
1
  import { _ as PG_TEXT_CODEC_ID, g as PG_TEXT_ARRAY_CODEC_ID, l as PG_INT4_CODEC_ID, p as PG_JSONB_CODEC_ID, u as PG_INT8_CODEC_ID, v as PG_TIMESTAMPTZ_CODEC_ID } from "./codec-ids-BvytN2P8.mjs";
2
- import { a as PostgresTableSource } from "./postgres-schema-COGZ1ark.mjs";
3
- import { a as columnDefaultAst, c as columnTypeAst, d as indexExistsAst, f as noNullValuesAst, g as toRegclass, h as tablePrimaryKeyAst, i as createTable, l as constraintExistsAst, m as tableIsEmptyAst, n as alterTable, o as columnExistsAst, p as tableExistsAst, r as createSchema, s as columnNullabilityAst, t as addColumnAction, u as extensionExistsAst } from "./ddl-QDyOSeLc.mjs";
2
+ import { s as PostgresTableSource } from "./postgres-schema-BVDr_61a.mjs";
3
+ import { _ as tableExistsAst, a as createTable, b as toRegclass, c as columnExistsAst, d as constraintExistsAst, f as extensionExistsAst, i as createSchema, l as columnNullabilityAst, m as noNullValuesAst, n as alterTable, p as indexExistsAst, s as columnDefaultAst, t as addColumnAction, u as columnTypeAst, v as tableIsEmptyAst, y as tablePrimaryKeyAst } from "./ddl-BlsTIBeP.mjs";
4
4
  import { col, fn, lit, table } from "@prisma-next/sql-relational-core/contract-free";
5
5
  import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
6
6
  //#region src/contract-free/columns.ts
@@ -1,4 +1,4 @@
1
- import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
1
+ import { t as PostgresPlanTargetDetails } from "./planner-target-details-HkP4RrRO.mjs";
2
2
  import { SqlControlTargetDescriptor } from "@prisma-next/family-sql/control";
3
3
  import { StorageColumn } from "@prisma-next/sql-contract/types";
4
4
  import { ColumnDefault } from "@prisma-next/contract/types";
package/dist/control.mjs CHANGED
@@ -1,14 +1,14 @@
1
- import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-CpGygXpI.mjs";
1
+ import { t as postgresTargetDescriptorMeta } from "./descriptor-meta-b_SzXwen.mjs";
2
2
  import { t as parsePostgresDefault } from "./default-normalizer-DyyCHQWs.mjs";
3
3
  import { t as normalizeSchemaNativeType } from "./native-type-normalizer-Bc9XJzWC.mjs";
4
- import { t as createPostgresMigrationPlanner } from "./planner-Bs_baQax.mjs";
4
+ import { t as createPostgresMigrationPlanner } from "./planner-BbSZJVW7.mjs";
5
5
  import { a as renderDefaultLiteral } from "./planner-ddl-builders-B2wOwLqI.mjs";
6
- import { t as PostgresContractSerializer } from "./postgres-contract-serializer-k3TAcPMY.mjs";
6
+ import { t as PostgresContractSerializer } from "./postgres-contract-serializer-k5eg5ZUZ.mjs";
7
7
  import { blindCast } from "@prisma-next/utils/casts";
8
8
  import { contractToSchemaIR, extractCodecControlHooks, runnerFailure, runnerSuccess } from "@prisma-next/family-sql/control";
9
9
  import { ifDefined } from "@prisma-next/utils/defined";
10
- import { verifySqlSchema } from "@prisma-next/family-sql/schema-verify";
11
10
  import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
11
+ import { verifySqlSchema } from "@prisma-next/family-sql/schema-verify";
12
12
  import { notOk, ok, okVoid } from "@prisma-next/utils/result";
13
13
  import { APP_SPACE_ID } from "@prisma-next/framework-components/control";
14
14
  import { SqlQueryError } from "@prisma-next/sql-errors";
@@ -1,4 +1,4 @@
1
- import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
1
+ import { t as PostgresPlanTargetDetails } from "./planner-target-details-HkP4RrRO.mjs";
2
2
  import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
3
3
  import { SqlStorage } from "@prisma-next/sql-contract/types";
4
4
  import { Contract } from "@prisma-next/contract/types";
@@ -35,4 +35,4 @@ interface DataTransformOptions {
35
35
  declare function dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions, adapter: SqlControlAdapter<'postgres'>): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
36
36
  //#endregion
37
37
  export { DataTransformOptions as n, dataTransform as r, DataTransformClosure as t };
38
- //# sourceMappingURL=data-transform-DDgWdB5o.d.mts.map
38
+ //# sourceMappingURL=data-transform-qKy1U5V9.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"data-transform-DDgWdB5o.d.mts","names":[],"sources":["../src/core/migrations/operations/data-transform.ts"],"mappings":";;;;;;;;UAqEU,SAAA;EACR,KAAA,IAAS,YAAY,CAAC,CAAA;AAAA;;;AAiCsC;;KA1BlD,oBAAA,SAA6B,YAAA,GAAe,SAAS;AAAA,UAEhD,oBAAA;;;;;;WAMN,WAAA;;;;;;;;WAQA,KAAA,GAAQ,oBAAA;;WAER,GAAA,EAAK,oBAAA,YAAgC,oBAAA;AAAA;AAAA,iBAG1B,aAAA,mBAAgC,QAAA,CAAS,UAAA,GAC7D,QAAA,EAAU,SAAA,EACV,IAAA,UACA,OAAA,EAAS,oBAAA,EACT,OAAA,EAAS,iBAAA,eACR,OAAA,CAAQ,yBAAA,CAA0B,yBAAA"}
1
+ {"version":3,"file":"data-transform-qKy1U5V9.d.mts","names":[],"sources":["../src/core/migrations/operations/data-transform.ts"],"mappings":";;;;;;;;UAqEU,SAAA;EACR,KAAA,IAAS,YAAY,CAAC,CAAA;AAAA;;;AAiCsC;;KA1BlD,oBAAA,SAA6B,YAAA,GAAe,SAAS;AAAA,UAEhD,oBAAA;;;;;;WAMN,WAAA;;;;;;;;WAQA,KAAA,GAAQ,oBAAA;;WAER,GAAA,EAAK,oBAAA,YAAgC,oBAAA;AAAA;AAAA,iBAG1B,aAAA,mBAAgC,QAAA,CAAS,UAAA,GAC7D,QAAA,EAAU,SAAA,EACV,IAAA,UACA,OAAA,EAAS,oBAAA,EACT,OAAA,EAAS,iBAAA,eACR,OAAA,CAAQ,yBAAA,CAA0B,yBAAA"}
@@ -1,2 +1,2 @@
1
- import { r as dataTransform } from "./data-transform-DDgWdB5o.mjs";
1
+ import { r as dataTransform } from "./data-transform-qKy1U5V9.mjs";
2
2
  export { dataTransform };
@@ -1,6 +1,6 @@
1
1
  import { _ as PG_TEXT_CODEC_ID } from "./codec-ids-BvytN2P8.mjs";
2
- import { a as PostgresTableSource, i as postgresCreateNamespace } from "./postgres-schema-COGZ1ark.mjs";
3
- import { i as PostgresCreateTable, n as PostgresAlterTable, r as PostgresCreateSchema, t as AddColumnAction } from "./nodes-Bbhs2rwj.mjs";
2
+ import { i as postgresCreateNamespace, s as PostgresTableSource } from "./postgres-schema-BVDr_61a.mjs";
3
+ import { a as PostgresCreateTable, i as PostgresCreateSchema, n as PostgresAlterTable, r as PostgresCreatePolicy, s as PostgresDropPolicy, t as AddColumnAction } from "./nodes-DhDIIhBT.mjs";
4
4
  import { cfExpr, cfTable, exprSelect } from "@prisma-next/sql-relational-core/contract-free";
5
5
  //#region src/contract-free/checks.ts
6
6
  /**
@@ -194,6 +194,39 @@ function extensionExistsAst(extensionName) {
194
194
  };
195
195
  }
196
196
  /**
197
+ * Typed RLS-policy existence check over `pg_policies`, with schema, table,
198
+ * and policy names bound as text parameters (never inlined). The `schema`
199
+ * coordinate is the resolved live-database schema name (e.g. `'public'`),
200
+ * compared against `pg_policies.schemaname` as a bound parameter.
201
+ */
202
+ function rlsPolicyExistsAst(options) {
203
+ const inner = () => exprSelect().from(cfTable("pg_policies")).project("one", cfExpr.lit(1)).where(cfExpr.allOf([
204
+ cfExpr.identifierRef("schemaname").eqParam(options.schema, PG_TEXT_CODEC_ID),
205
+ cfExpr.identifierRef("tablename").eqParam(options.table, PG_TEXT_CODEC_ID),
206
+ cfExpr.identifierRef("policyname").eqParam(options.policyName, PG_TEXT_CODEC_ID)
207
+ ]));
208
+ return {
209
+ policyPresent: () => exprSelect().project("result", cfExpr.exists(inner())).build(),
210
+ policyAbsent: () => exprSelect().project("result", cfExpr.notExists(inner())).build()
211
+ };
212
+ }
213
+ /**
214
+ * Typed row-level-security enabled check over `pg_class` joined to
215
+ * `pg_namespace`, comparing `pg_class.relrowsecurity` against the expected
216
+ * boolean. Schema and table names are bound as text parameters.
217
+ */
218
+ function rlsEnabledAst(schema, table) {
219
+ const inner = (enabled) => exprSelect().from(cfTable("pg_class", "c")).join(cfTable("pg_namespace", "n"), cfExpr.columnRef("n", "oid").eqExpr(cfExpr.columnRef("c", "relnamespace"))).project("one", cfExpr.lit(1)).where(cfExpr.allOf([
220
+ cfExpr.columnRef("n", "nspname").eqParam(schema, PG_TEXT_CODEC_ID),
221
+ cfExpr.columnRef("c", "relname").eqParam(table, PG_TEXT_CODEC_ID),
222
+ enabled ? cfExpr.columnRef("c", "relrowsecurity") : cfExpr.columnRef("c", "relrowsecurity").not()
223
+ ]));
224
+ return {
225
+ rlsEnabled: () => exprSelect().project("result", cfExpr.exists(inner(true))).build(),
226
+ rlsDisabled: () => exprSelect().project("result", cfExpr.exists(inner(false))).build()
227
+ };
228
+ }
229
+ /**
197
230
  * Typed index existence check riding the same `to_regclass` vocabulary as
198
231
  * `tableExistsAst`, with the qualified index name bound as a text parameter.
199
232
  */
@@ -245,7 +278,24 @@ function addColumnAction(column) {
245
278
  function alterTable(options) {
246
279
  return new PostgresAlterTable(options);
247
280
  }
281
+ /**
282
+ * Build a Postgres `CREATE POLICY` DDL node.
283
+ *
284
+ * Identifiers (`schema`, `table`, `name`) are quoted by the renderer.
285
+ * `using` and `withCheck` are emitted verbatim as predicate SQL — callers
286
+ * must supply safe, pre-validated SQL expressions.
287
+ */
288
+ function createPolicy(options) {
289
+ return new PostgresCreatePolicy(options);
290
+ }
291
+ /**
292
+ * Build a Postgres `DROP POLICY` DDL node.
293
+ * Identifiers (`schema`, `table`, `name`) are quoted by the renderer.
294
+ */
295
+ function dropPolicy(options) {
296
+ return new PostgresDropPolicy(options);
297
+ }
248
298
  //#endregion
249
- export { columnDefaultAst as a, columnTypeAst as c, indexExistsAst as d, noNullValuesAst as f, toRegclass as g, tablePrimaryKeyAst as h, createTable as i, constraintExistsAst as l, tableIsEmptyAst as m, alterTable as n, columnExistsAst as o, tableExistsAst as p, createSchema as r, columnNullabilityAst as s, addColumnAction as t, extensionExistsAst as u };
299
+ export { tableExistsAst as _, createTable as a, toRegclass as b, columnExistsAst as c, constraintExistsAst as d, extensionExistsAst as f, rlsPolicyExistsAst as g, rlsEnabledAst as h, createSchema as i, columnNullabilityAst as l, noNullValuesAst as m, alterTable as n, dropPolicy as o, indexExistsAst as p, createPolicy as r, columnDefaultAst as s, addColumnAction as t, columnTypeAst as u, tableIsEmptyAst as v, tablePrimaryKeyAst as y };
250
300
 
251
- //# sourceMappingURL=ddl-QDyOSeLc.mjs.map
301
+ //# sourceMappingURL=ddl-BlsTIBeP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ddl-BlsTIBeP.mjs","names":[],"sources":["../src/contract-free/checks.ts","../src/contract-free/ddl.ts"],"sourcesContent":["import type { SelectAst } from '@prisma-next/sql-relational-core/ast';\nimport {\n type CfExpr,\n type CfExprSelectQuery,\n cfExpr,\n cfTable,\n exprSelect,\n} from '@prisma-next/sql-relational-core/contract-free';\nimport { PostgresTableSource } from '../core/ast/table-source';\nimport { PG_TEXT_CODEC_ID } from '../core/codec-ids';\nimport { postgresCreateNamespace } from '../core/postgres-schema';\n\n/**\n * `to_regclass($1)` with the qualified table name bound as a text parameter.\n * Thin vocabulary wrapper over the core `cfExpr.fn` helper — the target\n * supplies only the template and the codec'd operand.\n */\nexport function toRegclass(qualifiedName: string): CfExpr {\n return cfExpr.fn({\n method: 'to_regclass',\n template: 'to_regclass({{self}})',\n self: cfExpr.param(qualifiedName, PG_TEXT_CODEC_ID),\n returns: { codecId: PG_TEXT_CODEC_ID, nullable: true },\n });\n}\n\nexport interface TableExistsCheckBuilder {\n tableAbsent(): SelectAst;\n tablePresent(): SelectAst;\n}\n\n/**\n * Typed builder for the migration planner's table-existence checks. Produces\n * FROM-less `SELECT to_regclass($1) IS [NOT] NULL AS \"result\"` ASTs with the\n * qualified table name bound as a text parameter — never inlined into the SQL.\n *\n * `schema` is a namespace coordinate: the framework `__unbound__` sentinel\n * elides the qualifier (search_path decides at runtime); any other id\n * qualifies as `\"schema\".\"table\"`.\n */\nexport function tableExistsAst(schema: string, table: string): TableExistsCheckBuilder {\n const qualified = postgresCreateNamespace({ id: schema, entries: { table: {} } }).qualifyTable(\n table,\n );\n const regclass = toRegclass(qualified);\n return {\n tableAbsent: () => exprSelect().project('result', regclass.isNull()).build(),\n tablePresent: () => exprSelect().project('result', regclass.isNotNull()).build(),\n };\n}\n\nexport interface ConstraintExistsCheckBuilder {\n constraintPresent(): SelectAst;\n constraintAbsent(): SelectAst;\n}\n\n/**\n * Typed builder for the migration planner's constraint-existence checks.\n * Produces `SELECT [NOT ]EXISTS (SELECT 1 FROM pg_constraint c JOIN\n * pg_namespace n ON n.oid = c.connamespace WHERE c.conname = $1 AND\n * n.nspname = $2 [AND c.conrelid = to_regclass($3)]) AS \"result\"` with the\n * constraint name, schema name, and qualified table name bound as text\n * parameters.\n *\n * When `table` is omitted the check matches by name + schema across all\n * tables. Pass `table` to scope the check to a single table (prevents false\n * matches on identically-named constraints in different tables). `schema`\n * is a namespace coordinate: the `__unbound__` sentinel compares `nspname`\n * against `current_schema()` instead of a bound parameter.\n */\nexport function constraintExistsAst(options: {\n readonly constraintName: string;\n readonly schema: string;\n readonly table?: string;\n}): ConstraintExistsCheckBuilder {\n const namespace = postgresCreateNamespace({ id: options.schema, entries: { table: {} } });\n const conditions = [\n cfExpr.columnRef('c', 'conname').eqParam(options.constraintName, PG_TEXT_CODEC_ID),\n cfExpr.columnRef('n', 'nspname').eqExpr(namespace.schemaFilterExpression()),\n ];\n if (options.table !== undefined) {\n conditions.push(\n cfExpr.columnRef('c', 'conrelid').eqExpr(toRegclass(namespace.qualifyTable(options.table))),\n );\n }\n const inner = (): CfExprSelectQuery =>\n exprSelect()\n .from(cfTable('pg_constraint', 'c'))\n .join(\n cfTable('pg_namespace', 'n'),\n cfExpr.columnRef('n', 'oid').eqExpr(cfExpr.columnRef('c', 'connamespace')),\n )\n .project('one', cfExpr.lit(1))\n .where(cfExpr.allOf(conditions));\n return {\n constraintPresent: () => exprSelect().project('result', cfExpr.exists(inner())).build(),\n constraintAbsent: () => exprSelect().project('result', cfExpr.notExists(inner())).build(),\n };\n}\n\nfunction checkNamespace(schema: string) {\n return postgresCreateNamespace({ id: schema, entries: { table: {} } });\n}\n\nfunction informationSchemaColumns(): PostgresTableSource {\n return new PostgresTableSource({ schema: 'information_schema', name: 'columns' });\n}\n\nfunction infoSchemaColumnConditions(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n}): CfExpr[] {\n return [\n cfExpr\n .identifierRef('table_schema')\n .eqExpr(checkNamespace(options.schema).schemaFilterExpression()),\n cfExpr.identifierRef('table_name').eqParam(options.table, PG_TEXT_CODEC_ID),\n cfExpr.identifierRef('column_name').eqParam(options.column, PG_TEXT_CODEC_ID),\n ];\n}\n\nfunction infoSchemaColumnQuery(conditions: ReadonlyArray<CfExpr>): CfExprSelectQuery {\n return exprSelect()\n .from(informationSchemaColumns())\n .project('one', cfExpr.lit(1))\n .where(cfExpr.allOf(conditions));\n}\n\nexport interface ColumnExistsCheckBuilder {\n columnPresent(): SelectAst;\n columnAbsent(): SelectAst;\n}\n\n/**\n * Typed builder for column-existence checks over\n * `information_schema.columns`, with schema, table, and column names bound\n * as text parameters.\n */\nexport function columnExistsAst(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n}): ColumnExistsCheckBuilder {\n const inner = () => infoSchemaColumnQuery(infoSchemaColumnConditions(options));\n return {\n columnPresent: () => exprSelect().project('result', cfExpr.exists(inner())).build(),\n columnAbsent: () => exprSelect().project('result', cfExpr.notExists(inner())).build(),\n };\n}\n\n/**\n * Typed nullability check: EXISTS over `information_schema.columns` with\n * `is_nullable` compared against the bound `'YES'` / `'NO'` marker.\n */\nexport function columnNullabilityAst(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n readonly nullable: boolean;\n}): SelectAst {\n const conditions = [\n ...infoSchemaColumnConditions(options),\n cfExpr.identifierRef('is_nullable').eqParam(options.nullable ? 'YES' : 'NO', PG_TEXT_CODEC_ID),\n ];\n return exprSelect()\n .project('result', cfExpr.exists(infoSchemaColumnQuery(conditions)))\n .build();\n}\n\nexport interface ColumnDefaultCheckBuilder {\n defaultPresent(): SelectAst;\n defaultAbsent(): SelectAst;\n noDefault(): SelectAst;\n}\n\n/**\n * Typed default-presence checks over `information_schema.columns`.\n * `defaultPresent` / `defaultAbsent` assert the column row exists with a\n * non-null / null `column_default`; `noDefault` is the NOT EXISTS variant\n * (also true when the column row is missing entirely).\n */\nexport function columnDefaultAst(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n}): ColumnDefaultCheckBuilder {\n const withDefault = () =>\n infoSchemaColumnQuery([\n ...infoSchemaColumnConditions(options),\n cfExpr.identifierRef('column_default').isNotNull(),\n ]);\n const withoutDefault = () =>\n infoSchemaColumnQuery([\n ...infoSchemaColumnConditions(options),\n cfExpr.identifierRef('column_default').isNull(),\n ]);\n return {\n defaultPresent: () => exprSelect().project('result', cfExpr.exists(withDefault())).build(),\n defaultAbsent: () => exprSelect().project('result', cfExpr.exists(withoutDefault())).build(),\n noDefault: () => exprSelect().project('result', cfExpr.notExists(withDefault())).build(),\n };\n}\n\n/**\n * Typed column-type check: EXISTS over `pg_attribute` joined to `pg_class`\n * and `pg_namespace`, comparing `format_type(a.atttypid, a.atttypmod)`\n * against the bound expected display type and excluding dropped columns.\n */\nexport function columnTypeAst(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n readonly expectedType: string;\n}): SelectAst {\n const formatType = cfExpr.fn({\n method: 'format_type',\n template: 'format_type({{self}}, {{arg0}})',\n self: cfExpr.columnRef('a', 'atttypid'),\n args: [cfExpr.columnRef('a', 'atttypmod')],\n returns: { codecId: PG_TEXT_CODEC_ID, nullable: false },\n });\n const inner = exprSelect()\n .from(cfTable('pg_attribute', 'a'))\n .join(\n cfTable('pg_class', 'c'),\n cfExpr.columnRef('c', 'oid').eqExpr(cfExpr.columnRef('a', 'attrelid')),\n )\n .join(\n cfTable('pg_namespace', 'n'),\n cfExpr.columnRef('n', 'oid').eqExpr(cfExpr.columnRef('c', 'relnamespace')),\n )\n .project('one', cfExpr.lit(1))\n .where(\n cfExpr.allOf([\n cfExpr\n .columnRef('n', 'nspname')\n .eqExpr(checkNamespace(options.schema).schemaFilterExpression()),\n cfExpr.columnRef('c', 'relname').eqParam(options.table, PG_TEXT_CODEC_ID),\n cfExpr.columnRef('a', 'attname').eqParam(options.column, PG_TEXT_CODEC_ID),\n formatType.eqParam(options.expectedType, PG_TEXT_CODEC_ID),\n cfExpr.columnRef('a', 'attisdropped').not(),\n ]),\n );\n return exprSelect().project('result', cfExpr.exists(inner)).build();\n}\n\nexport interface TablePrimaryKeyCheckBuilder {\n pkPresent(): SelectAst;\n pkAbsent(): SelectAst;\n}\n\n/**\n * Typed primary-key existence check over `pg_index` joined to `pg_class`\n * and `pg_namespace`, with a LEFT JOIN on the index relation so an\n * optional `constraintName` can scope the match to a named constraint.\n */\nexport function tablePrimaryKeyAst(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraintName?: string;\n}): TablePrimaryKeyCheckBuilder {\n const conditions = [\n cfExpr\n .columnRef('n', 'nspname')\n .eqExpr(checkNamespace(options.schema).schemaFilterExpression()),\n cfExpr.columnRef('c', 'relname').eqParam(options.table, PG_TEXT_CODEC_ID),\n cfExpr.columnRef('i', 'indisprimary'),\n ];\n if (options.constraintName !== undefined) {\n conditions.push(\n cfExpr.columnRef('c2', 'relname').eqParam(options.constraintName, PG_TEXT_CODEC_ID),\n );\n }\n const inner = () =>\n exprSelect()\n .from(cfTable('pg_index', 'i'))\n .join(\n cfTable('pg_class', 'c'),\n cfExpr.columnRef('c', 'oid').eqExpr(cfExpr.columnRef('i', 'indrelid')),\n )\n .join(\n cfTable('pg_namespace', 'n'),\n cfExpr.columnRef('n', 'oid').eqExpr(cfExpr.columnRef('c', 'relnamespace')),\n )\n .leftJoin(\n cfTable('pg_class', 'c2'),\n cfExpr.columnRef('c2', 'oid').eqExpr(cfExpr.columnRef('i', 'indexrelid')),\n )\n .project('one', cfExpr.lit(1))\n .where(cfExpr.allOf(conditions));\n return {\n pkPresent: () => exprSelect().project('result', cfExpr.exists(inner())).build(),\n pkAbsent: () => exprSelect().project('result', cfExpr.notExists(inner())).build(),\n };\n}\n\n/**\n * Typed emptiness check: NOT EXISTS over the user table itself with\n * `LIMIT 1`. The table is addressed through the namespace's polymorphic\n * `tableSource` (qualified for named schemas, bare for the unbound slot).\n */\nexport function tableIsEmptyAst(schema: string, table: string): SelectAst {\n const inner = exprSelect()\n .from(checkNamespace(schema).tableSource(table))\n .project('one', cfExpr.lit(1))\n .limit(1);\n return exprSelect().project('result', cfExpr.notExists(inner)).build();\n}\n\n/**\n * Typed no-NULL-values data check used by `SET NOT NULL` prechecks:\n * NOT EXISTS over the user table where the column IS NULL.\n */\nexport function noNullValuesAst(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n}): SelectAst {\n const inner = exprSelect()\n .from(checkNamespace(options.schema).tableSource(options.table))\n .project('one', cfExpr.lit(1))\n .where(cfExpr.identifierRef(options.column).isNull());\n return exprSelect().project('result', cfExpr.notExists(inner)).build();\n}\n\nexport interface ExtensionExistsCheckBuilder {\n extensionPresent(): SelectAst;\n extensionAbsent(): SelectAst;\n}\n\n/**\n * Typed extension existence check over `pg_extension`, with the extension\n * name bound as a text parameter.\n */\nexport function extensionExistsAst(extensionName: string): ExtensionExistsCheckBuilder {\n const inner = () =>\n exprSelect()\n .from(cfTable('pg_extension'))\n .project('one', cfExpr.lit(1))\n .where(cfExpr.identifierRef('extname').eqParam(extensionName, PG_TEXT_CODEC_ID));\n return {\n extensionPresent: () => exprSelect().project('result', cfExpr.exists(inner())).build(),\n extensionAbsent: () => exprSelect().project('result', cfExpr.notExists(inner())).build(),\n };\n}\n\nexport interface RlsPolicyExistsCheckBuilder {\n policyPresent(): SelectAst;\n policyAbsent(): SelectAst;\n}\n\n/**\n * Typed RLS-policy existence check over `pg_policies`, with schema, table,\n * and policy names bound as text parameters (never inlined). The `schema`\n * coordinate is the resolved live-database schema name (e.g. `'public'`),\n * compared against `pg_policies.schemaname` as a bound parameter.\n */\nexport function rlsPolicyExistsAst(options: {\n readonly schema: string;\n readonly table: string;\n readonly policyName: string;\n}): RlsPolicyExistsCheckBuilder {\n const inner = () =>\n exprSelect()\n .from(cfTable('pg_policies'))\n .project('one', cfExpr.lit(1))\n .where(\n cfExpr.allOf([\n cfExpr.identifierRef('schemaname').eqParam(options.schema, PG_TEXT_CODEC_ID),\n cfExpr.identifierRef('tablename').eqParam(options.table, PG_TEXT_CODEC_ID),\n cfExpr.identifierRef('policyname').eqParam(options.policyName, PG_TEXT_CODEC_ID),\n ]),\n );\n return {\n policyPresent: () => exprSelect().project('result', cfExpr.exists(inner())).build(),\n policyAbsent: () => exprSelect().project('result', cfExpr.notExists(inner())).build(),\n };\n}\n\nexport interface RlsEnabledCheckBuilder {\n rlsEnabled(): SelectAst;\n rlsDisabled(): SelectAst;\n}\n\n/**\n * Typed row-level-security enabled check over `pg_class` joined to\n * `pg_namespace`, comparing `pg_class.relrowsecurity` against the expected\n * boolean. Schema and table names are bound as text parameters.\n */\nexport function rlsEnabledAst(schema: string, table: string): RlsEnabledCheckBuilder {\n const inner = (enabled: boolean) =>\n exprSelect()\n .from(cfTable('pg_class', 'c'))\n .join(\n cfTable('pg_namespace', 'n'),\n cfExpr.columnRef('n', 'oid').eqExpr(cfExpr.columnRef('c', 'relnamespace')),\n )\n .project('one', cfExpr.lit(1))\n .where(\n cfExpr.allOf([\n cfExpr.columnRef('n', 'nspname').eqParam(schema, PG_TEXT_CODEC_ID),\n cfExpr.columnRef('c', 'relname').eqParam(table, PG_TEXT_CODEC_ID),\n enabled\n ? cfExpr.columnRef('c', 'relrowsecurity')\n : cfExpr.columnRef('c', 'relrowsecurity').not(),\n ]),\n );\n return {\n rlsEnabled: () =>\n exprSelect()\n .project('result', cfExpr.exists(inner(true)))\n .build(),\n rlsDisabled: () =>\n exprSelect()\n .project('result', cfExpr.exists(inner(false)))\n .build(),\n };\n}\n\nexport interface IndexExistsCheckBuilder {\n indexPresent(): SelectAst;\n indexAbsent(): SelectAst;\n}\n\n/**\n * Typed index existence check riding the same `to_regclass` vocabulary as\n * `tableExistsAst`, with the qualified index name bound as a text parameter.\n */\nexport function indexExistsAst(schema: string, indexName: string): IndexExistsCheckBuilder {\n const regclass = toRegclass(checkNamespace(schema).qualifyTable(indexName));\n return {\n indexPresent: () => exprSelect().project('result', regclass.isNotNull()).build(),\n indexAbsent: () => exprSelect().project('result', regclass.isNull()).build(),\n };\n}\n","import type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';\nimport {\n AddColumnAction,\n type AnyAlterTableAction,\n PostgresAlterTable,\n PostgresCreatePolicy,\n PostgresCreateSchema,\n PostgresCreateTable,\n PostgresDropPolicy,\n type RlsPolicyOperation,\n} from '../core/ddl/nodes';\n\n/**\n * Build a Postgres `CREATE TABLE` query node.\n *\n * Pass `constraints` for table-level composite primary keys, foreign keys, and\n * unique constraints — use the {@link PrimaryKeyConstraint}, {@link ForeignKeyConstraint},\n * and {@link UniqueConstraint} classes from `@prisma-next/sql-relational-core/ast`.\n *\n * Precondition: identifiers (`table`, `schema`, column names/types) are\n * emitted to SQL verbatim — they are not quoted or escaped, so callers must\n * pass pre-trusted values (e.g. fixed control-plane identifiers). String-literal\n * default values, by contrast, are single-quote-escaped (embedded `'` doubled)\n * by the renderer. Identifier quoting for untrusted identifiers is added when\n * the migration planner adopts this lowering path.\n */\nexport function createTable(options: {\n readonly table: string;\n readonly schema?: string;\n readonly ifNotExists?: boolean;\n readonly columns: readonly DdlColumn[];\n readonly constraints?: readonly DdlTableConstraint[];\n}): PostgresCreateTable {\n return new PostgresCreateTable(options);\n}\n\n/**\n * Build a Postgres `CREATE SCHEMA` query node. See {@link createTable} for the\n * pre-trusted-identifier precondition.\n */\nexport function createSchema(options: {\n readonly schema: string;\n readonly ifNotExists?: boolean;\n}): PostgresCreateSchema {\n return new PostgresCreateSchema(options);\n}\n\n/**\n * Build an `ADD COLUMN` action for use inside {@link alterTable}.\n * The column is a structured `DdlColumn` so codec-encoded defaults flow\n * through the adapter's `pgRenderDdlColumn` → `pgRenderDdlColumnDefault` path.\n */\nexport function addColumnAction(column: DdlColumn): AddColumnAction {\n return new AddColumnAction(column);\n}\n\n/**\n * Build a Postgres `ALTER TABLE` query node carrying one or more actions.\n * See {@link addColumnAction} for building actions.\n */\nexport function alterTable(options: {\n readonly table: string;\n readonly schema?: string;\n readonly actions: readonly AnyAlterTableAction[];\n}): PostgresAlterTable {\n return new PostgresAlterTable(options);\n}\n\n/**\n * Build a Postgres `CREATE POLICY` DDL node.\n *\n * Identifiers (`schema`, `table`, `name`) are quoted by the renderer.\n * `using` and `withCheck` are emitted verbatim as predicate SQL — callers\n * must supply safe, pre-validated SQL expressions.\n */\nexport function createPolicy(options: {\n readonly schema: string;\n readonly table: string;\n readonly name: string;\n readonly permissive: boolean;\n readonly operation: RlsPolicyOperation;\n readonly roles: readonly string[];\n readonly using?: string;\n readonly withCheck?: string;\n}): PostgresCreatePolicy {\n return new PostgresCreatePolicy(options);\n}\n\n/**\n * Build a Postgres `DROP POLICY` DDL node.\n * Identifiers (`schema`, `table`, `name`) are quoted by the renderer.\n */\nexport function dropPolicy(options: {\n readonly schema: string;\n readonly table: string;\n readonly name: string;\n}): PostgresDropPolicy {\n return new PostgresDropPolicy(options);\n}\n"],"mappings":";;;;;;;;;;AAiBA,SAAgB,WAAW,eAA+B;CACxD,OAAO,OAAO,GAAG;EACf,QAAQ;EACR,UAAU;EACV,MAAM,OAAO,MAAM,eAAe,gBAAgB;EAClD,SAAS;GAAE,SAAS;GAAkB,UAAU;EAAK;CACvD,CAAC;AACH;;;;;;;;;;AAgBA,SAAgB,eAAe,QAAgB,OAAwC;CAIrF,MAAM,WAAW,WAHC,wBAAwB;EAAE,IAAI;EAAQ,SAAS,EAAE,OAAO,CAAC,EAAE;CAAE,CAAC,CAAC,CAAC,aAChF,KAEkC,CAAC;CACrC,OAAO;EACL,mBAAmB,WAAW,CAAC,CAAC,QAAQ,UAAU,SAAS,OAAO,CAAC,CAAC,CAAC,MAAM;EAC3E,oBAAoB,WAAW,CAAC,CAAC,QAAQ,UAAU,SAAS,UAAU,CAAC,CAAC,CAAC,MAAM;CACjF;AACF;;;;;;;;;;;;;;;AAqBA,SAAgB,oBAAoB,SAIH;CAC/B,MAAM,YAAY,wBAAw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AU,SAAS,UAAU,CAAC,CAAC,CAAC,MAAM;EAC/E,mBAAmB,WAAW,CAAC,CAAC,QAAQ,UAAU,SAAS,OAAO,CAAC,CAAC,CAAC,MAAM;CAC7E;AACF;;;;;;;;;;;;;;;;;ACzZA,SAAgB,YAAY,SAMJ;CACtB,OAAO,IAAI,oBAAoB,OAAO;AACxC;;;;;AAMA,SAAgB,aAAa,SAGJ;CACvB,OAAO,IAAI,qBAAqB,OAAO;AACzC;;;;;;AAOA,SAAgB,gBAAgB,QAAoC;CAClE,OAAO,IAAI,gBAAgB,MAAM;AACnC;;;;;AAMA,SAAgB,WAAW,SAIJ;CACrB,OAAO,IAAI,mBAAmB,OAAO;AACvC;;;;;;;;AASA,SAAgB,aAAa,SASJ;CACvB,OAAO,IAAI,qBAAqB,OAAO;AACzC;;;;;AAMA,SAAgB,WAAW,SAIJ;CACrB,OAAO,IAAI,mBAAmB,OAAO;AACvC"}
package/dist/ddl.d.mts CHANGED
@@ -1,2 +1,3 @@
1
- import { a as PostgresAlterTable, c as PostgresDdlNode, i as AnyPostgresDdlNode, l as PostgresDdlVisitor, n as AlterTableActionVisitor, o as PostgresCreateSchema, r as AnyAlterTableAction, s as PostgresCreateTable, t as AddColumnAction } from "./nodes-pLeLgdis.mjs";
2
- export { AddColumnAction, type AlterTableActionVisitor, type AnyAlterTableAction, type AnyPostgresDdlNode, PostgresAlterTable, PostgresCreateSchema, PostgresCreateTable, PostgresDdlNode, type PostgresDdlVisitor };
1
+ import { n as RlsPolicyOperation } from "./canonicalize-CAbXtVtB.mjs";
2
+ import { a as PostgresAlterTable, c as PostgresCreateTable, d as PostgresDropPolicy, i as AnyPostgresDdlNode, l as PostgresDdlNode, n as AlterTableActionVisitor, o as PostgresCreatePolicy, r as AnyAlterTableAction, s as PostgresCreateSchema, t as AddColumnAction, u as PostgresDdlVisitor } from "./nodes-YvdohJ2X.mjs";
3
+ export { AddColumnAction, type AlterTableActionVisitor, type AnyAlterTableAction, type AnyPostgresDdlNode, PostgresAlterTable, PostgresCreatePolicy, PostgresCreateSchema, PostgresCreateTable, PostgresDdlNode, type PostgresDdlVisitor, PostgresDropPolicy, type RlsPolicyOperation };
package/dist/ddl.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as PostgresDdlNode, i as PostgresCreateTable, n as PostgresAlterTable, r as PostgresCreateSchema, t as AddColumnAction } from "./nodes-Bbhs2rwj.mjs";
2
- export { AddColumnAction, PostgresAlterTable, PostgresCreateSchema, PostgresCreateTable, PostgresDdlNode };
1
+ import { a as PostgresCreateTable, i as PostgresCreateSchema, n as PostgresAlterTable, o as PostgresDdlNode, r as PostgresCreatePolicy, s as PostgresDropPolicy, t as AddColumnAction } from "./nodes-DhDIIhBT.mjs";
2
+ export { AddColumnAction, PostgresAlterTable, PostgresCreatePolicy, PostgresCreateSchema, PostgresCreateTable, PostgresDdlNode, PostgresDropPolicy };
@@ -0,0 +1,239 @@
1
+ import { c as PostgresRlsPolicySchema, d as PostgresRlsPolicy, i as postgresCreateNamespace, l as PostgresRoleSchema, u as PostgresRole } from "./postgres-schema-BVDr_61a.mjs";
2
+ import { n as normalizePredicate, t as computeContentHash } from "./canonicalize-Bn3BM1Cn.mjs";
3
+ import { temporalAuthoringPresets } from "@prisma-next/family-sql/control";
4
+ //#region src/core/authoring.ts
5
+ const postgresAuthoringTypes = {};
6
+ function readRefParam(block, key) {
7
+ const param = block.parameters[key];
8
+ return param?.kind === "ref" ? param.identifier : void 0;
9
+ }
10
+ function readValueParam(block, key) {
11
+ const param = block.parameters[key];
12
+ return param?.kind === "value" ? param.raw : void 0;
13
+ }
14
+ function readListRefParams(block, key) {
15
+ const param = block.parameters[key];
16
+ if (param?.kind !== "list") return [];
17
+ return param.items.flatMap((item) => item.kind === "ref" ? [item.identifier] : []);
18
+ }
19
+ function unwrapQuotedString(raw) {
20
+ if (raw.startsWith("\"") && raw.endsWith("\"") && raw.length >= 2) return raw.slice(1, -1).replace(/\\"/g, "\"");
21
+ return raw;
22
+ }
23
+ function lowerRlsPolicyFromBlock(block, _ctx) {
24
+ const prefix = block.name;
25
+ const targetModelName = readRefParam(block, "target") ?? "";
26
+ const tableName = targetModelName.charAt(0).toLowerCase() + targetModelName.slice(1);
27
+ const roles = [...readListRefParams(block, "roles")].sort();
28
+ const using = unwrapQuotedString(readValueParam(block, "using") ?? "");
29
+ return new PostgresRlsPolicy({
30
+ name: `${prefix}_${computeContentHash({
31
+ using: normalizePredicate(using),
32
+ roles,
33
+ operation: "select",
34
+ permissive: true
35
+ })}`,
36
+ prefix,
37
+ tableName,
38
+ namespaceId: block.namespaceId,
39
+ operation: "select",
40
+ roles,
41
+ using,
42
+ permissive: true
43
+ });
44
+ }
45
+ const postgresAuthoringEntityTypes = {
46
+ role: {
47
+ kind: "entity",
48
+ discriminator: "role",
49
+ validatorSchema: PostgresRoleSchema,
50
+ output: { factory: (input) => new PostgresRole(input) }
51
+ },
52
+ policy: {
53
+ kind: "entity",
54
+ discriminator: "policy",
55
+ validatorSchema: PostgresRlsPolicySchema,
56
+ output: { factory: lowerRlsPolicyFromBlock }
57
+ }
58
+ };
59
+ /**
60
+ * Field presets contributed by the Postgres target pack.
61
+ *
62
+ * These mirror the PSL scalar-to-codec mapping used by the Postgres adapter
63
+ * (see `createPostgresPslScalarTypeDescriptors`), so that authoring a field
64
+ * via the TS callback surface (e.g. `field.int()`) and via the PSL scalar
65
+ * surface (e.g. `Int`) lowers to byte-identical contracts.
66
+ *
67
+ * The `uuidNative` / `id.uuidv4Native` / `id.uuidv7Native` presets use the
68
+ * native Postgres `uuid` type (codecId `pg/uuid@1`). For cross-target
69
+ * portability use `uuidString` / `id.uuidv4String` / `id.uuidv7String` from
70
+ * the family pack instead.
71
+ */
72
+ /**
73
+ * PSL block descriptor for `policy_select`.
74
+ *
75
+ * The parser learns the block shape from this descriptor; lowering from
76
+ * `PslExtensionBlock` to `PostgresRlsPolicy` is wired in the PSL
77
+ * interpreter (a later dispatch). The `discriminator` matches
78
+ * `PostgresRlsPolicy.kind` so the parsed block node carries the same
79
+ * discriminant as the IR class it will lower to.
80
+ *
81
+ * The `roles` list uses `scope:'cross-space'` because same-namespace
82
+ * role ref resolution requires PSL namespace entries keyed by `refKind`
83
+ * (i.e. `'role'`), which in turn requires the role block discriminator to
84
+ * equal `'role'`. Aligning discriminator with refKind is tracked for
85
+ * slice 4 (cross-space roles). Until then cross-space passes validation
86
+ * unconditionally and the authored role names flow through unchanged.
87
+ */
88
+ const postgresAuthoringPslBlockDescriptors = { policy_select: {
89
+ kind: "pslBlock",
90
+ keyword: "policy_select",
91
+ discriminator: "policy",
92
+ name: { required: true },
93
+ parameters: {
94
+ target: {
95
+ kind: "ref",
96
+ refKind: "model",
97
+ scope: "same-namespace",
98
+ required: true
99
+ },
100
+ roles: {
101
+ kind: "list",
102
+ of: {
103
+ kind: "ref",
104
+ refKind: "role",
105
+ scope: "cross-space"
106
+ }
107
+ },
108
+ using: {
109
+ kind: "value",
110
+ codecId: "pg/text@1",
111
+ required: true
112
+ }
113
+ }
114
+ } };
115
+ const postgresAuthoringFieldPresets = {
116
+ text: {
117
+ kind: "fieldPreset",
118
+ output: {
119
+ codecId: "pg/text@1",
120
+ nativeType: "text"
121
+ }
122
+ },
123
+ int: {
124
+ kind: "fieldPreset",
125
+ output: {
126
+ codecId: "pg/int4@1",
127
+ nativeType: "int4"
128
+ }
129
+ },
130
+ bigint: {
131
+ kind: "fieldPreset",
132
+ output: {
133
+ codecId: "pg/int8@1",
134
+ nativeType: "int8"
135
+ }
136
+ },
137
+ float: {
138
+ kind: "fieldPreset",
139
+ output: {
140
+ codecId: "pg/float8@1",
141
+ nativeType: "float8"
142
+ }
143
+ },
144
+ decimal: {
145
+ kind: "fieldPreset",
146
+ output: {
147
+ codecId: "pg/numeric@1",
148
+ nativeType: "numeric"
149
+ }
150
+ },
151
+ boolean: {
152
+ kind: "fieldPreset",
153
+ output: {
154
+ codecId: "pg/bool@1",
155
+ nativeType: "bool"
156
+ }
157
+ },
158
+ json: {
159
+ kind: "fieldPreset",
160
+ output: {
161
+ codecId: "pg/jsonb@1",
162
+ nativeType: "jsonb"
163
+ }
164
+ },
165
+ bytes: {
166
+ kind: "fieldPreset",
167
+ output: {
168
+ codecId: "pg/bytea@1",
169
+ nativeType: "bytea"
170
+ }
171
+ },
172
+ dateTime: {
173
+ kind: "fieldPreset",
174
+ output: {
175
+ codecId: "pg/timestamptz@1",
176
+ nativeType: "timestamptz"
177
+ }
178
+ },
179
+ temporal: /* @__PURE__ */ temporalAuthoringPresets({
180
+ codecId: "pg/timestamptz@1",
181
+ nativeType: "timestamptz"
182
+ }),
183
+ uuidNative: {
184
+ kind: "fieldPreset",
185
+ output: {
186
+ codecId: "pg/uuid@1",
187
+ nativeType: "uuid"
188
+ }
189
+ },
190
+ id: {
191
+ uuidv4Native: {
192
+ kind: "fieldPreset",
193
+ output: {
194
+ codecId: "pg/uuid@1",
195
+ nativeType: "uuid",
196
+ executionDefaults: { onCreate: {
197
+ kind: "generator",
198
+ id: "uuidv4"
199
+ } },
200
+ id: true
201
+ }
202
+ },
203
+ uuidv7Native: {
204
+ kind: "fieldPreset",
205
+ output: {
206
+ codecId: "pg/uuid@1",
207
+ nativeType: "uuid",
208
+ executionDefaults: { onCreate: {
209
+ kind: "generator",
210
+ id: "uuidv7"
211
+ } },
212
+ id: true
213
+ }
214
+ }
215
+ }
216
+ };
217
+ const postgresTargetDescriptorMetaRuntime = {
218
+ kind: "target",
219
+ familyId: "sql",
220
+ targetId: "postgres",
221
+ id: "postgres",
222
+ version: "0.0.1",
223
+ capabilities: {}
224
+ };
225
+ const postgresTargetDescriptorMeta = {
226
+ ...postgresTargetDescriptorMetaRuntime,
227
+ defaultNamespaceId: "public",
228
+ authoring: {
229
+ type: postgresAuthoringTypes,
230
+ field: postgresAuthoringFieldPresets,
231
+ entityTypes: postgresAuthoringEntityTypes,
232
+ pslBlockDescriptors: postgresAuthoringPslBlockDescriptors,
233
+ createNamespace: postgresCreateNamespace
234
+ }
235
+ };
236
+ //#endregion
237
+ export { postgresTargetDescriptorMetaRuntime as n, postgresAuthoringEntityTypes as r, postgresTargetDescriptorMeta as t };
238
+
239
+ //# sourceMappingURL=descriptor-meta-b_SzXwen.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-meta-b_SzXwen.mjs","names":[],"sources":["../src/core/authoring.ts","../src/core/descriptor-meta-runtime.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import { temporalAuthoringPresets } from '@prisma-next/family-sql/control';\nimport type {\n AuthoringEntityContext,\n AuthoringEntityTypeNamespace,\n AuthoringFieldNamespace,\n AuthoringPslBlockDescriptorNamespace,\n AuthoringTypeNamespace,\n PslExtensionBlock,\n} from '@prisma-next/framework-components/authoring';\nimport { PostgresRlsPolicy } from './postgres-rls-policy';\nimport { PostgresRole, type PostgresRoleInput } from './postgres-role';\nimport { PostgresRlsPolicySchema, PostgresRoleSchema } from './postgres-validators';\nimport { computeContentHash, normalizePredicate } from './rls/canonicalize';\n\nexport const postgresAuthoringTypes = {} as const satisfies AuthoringTypeNamespace;\n\nexport interface RlsPolicyExtensionBlock extends PslExtensionBlock {\n readonly namespaceId: string;\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\nfunction unwrapQuotedString(raw: string): string {\n if (raw.startsWith('\"') && raw.endsWith('\"') && raw.length >= 2) {\n return raw.slice(1, -1).replace(/\\\\\"/g, '\"');\n }\n return raw;\n}\n\nfunction lowerRlsPolicyFromBlock(\n block: RlsPolicyExtensionBlock,\n _ctx: AuthoringEntityContext,\n): PostgresRlsPolicy {\n const prefix = block.name;\n const targetModelName = readRefParam(block, 'target') ?? '';\n const tableName = targetModelName.charAt(0).toLowerCase() + targetModelName.slice(1);\n const roles = [...readListRefParams(block, 'roles')].sort();\n const using = unwrapQuotedString(readValueParam(block, 'using') ?? '');\n\n const wireHash = computeContentHash({\n using: normalizePredicate(using),\n roles,\n operation: 'select',\n permissive: true,\n });\n const wireName = `${prefix}_${wireHash}`;\n\n return new PostgresRlsPolicy({\n name: wireName,\n prefix,\n tableName,\n namespaceId: block.namespaceId,\n operation: 'select',\n roles,\n using,\n permissive: true,\n });\n}\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 policy: {\n kind: 'entity',\n discriminator: 'policy',\n validatorSchema: PostgresRlsPolicySchema,\n output: {\n factory: lowerRlsPolicyFromBlock,\n },\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 * PSL block descriptor for `policy_select`.\n *\n * The parser learns the block shape from this descriptor; lowering from\n * `PslExtensionBlock` to `PostgresRlsPolicy` is wired in the PSL\n * interpreter (a later dispatch). The `discriminator` matches\n * `PostgresRlsPolicy.kind` so the parsed block node carries the same\n * discriminant as the IR class it will lower to.\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 */\nexport const postgresAuthoringPslBlockDescriptors = {\n policy_select: {\n kind: 'pslBlock',\n keyword: 'policy_select',\n discriminator: 'policy',\n name: { required: true },\n parameters: {\n target: { kind: 'ref', refKind: 'model', scope: 'same-namespace', required: true },\n roles: {\n kind: 'list',\n of: { kind: 'ref', refKind: 'role', scope: 'cross-space' },\n },\n using: { kind: 'value', codecId: 'pg/text@1', required: true },\n },\n },\n} as const satisfies AuthoringPslBlockDescriptorNamespace;\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","// Runtime-safe slice of the postgres target descriptor metadata.\n//\n// This file exists separately from ./descriptor-meta on purpose: the runtime\n// plane reads only `kind/familyId/targetId/id/version/capabilities` (plus the\n// `__codecTypes` phantom). The `authoring` slot lives on the pack/control\n// descriptor only, because authoring contributions are consumed at\n// contract-construction time by `assembleAuthoringContributions` (control\n// plane) and the PSL interpreter — never at runtime.\n//\n// Keeping the runtime closure free of the `./authoring` import is what lets\n// the bundler tree-shake `@prisma-next/family-sql/control` (and its\n// transitive `verify-sql-schema` chunk) out of the runtime entry. Do not\n// add an `authoring` field here — if you need to, the pack/control meta in\n// `./descriptor-meta` is the right place. See TML-2766 for context.\nimport type { CodecTypes } from '../exports/codec-types';\n\nconst postgresTargetDescriptorMetaRuntimeBase = {\n kind: 'target',\n familyId: 'sql',\n targetId: 'postgres',\n id: 'postgres',\n version: '0.0.1',\n capabilities: {},\n} as const;\n\nexport const postgresTargetDescriptorMetaRuntime: typeof postgresTargetDescriptorMetaRuntimeBase & {\n readonly __codecTypes?: CodecTypes;\n} = postgresTargetDescriptorMetaRuntimeBase;\n","import type { CodecTypes } from '../exports/codec-types';\nimport {\n postgresAuthoringEntityTypes,\n postgresAuthoringFieldPresets,\n postgresAuthoringPslBlockDescriptors,\n postgresAuthoringTypes,\n} from './authoring';\nimport { postgresTargetDescriptorMetaRuntime } from './descriptor-meta-runtime';\nimport { postgresCreateNamespace } from './postgres-schema';\n\nconst postgresTargetDescriptorMetaBase = {\n ...postgresTargetDescriptorMetaRuntime,\n defaultNamespaceId: 'public',\n authoring: {\n type: postgresAuthoringTypes,\n field: postgresAuthoringFieldPresets,\n entityTypes: postgresAuthoringEntityTypes,\n pslBlockDescriptors: postgresAuthoringPslBlockDescriptors,\n createNamespace: postgresCreateNamespace,\n },\n} as const;\n\nexport const postgresTargetDescriptorMeta: typeof postgresTargetDescriptorMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = postgresTargetDescriptorMetaBase;\n"],"mappings":";;;;AAcA,MAAa,yBAAyB,CAAC;AAMvC,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,MAAM,MAAM,SAAS,SAAU,KAAK,SAAS,QAAQ,CAAC,KAAK,UAAU,IAAI,CAAC,CAAE;AACrF;AAEA,SAAS,mBAAmB,KAAqB;CAC/C,IAAI,IAAI,WAAW,IAAG,KAAK,IAAI,SAAS,IAAG,KAAK,IAAI,UAAU,GAC5D,OAAO,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC,QAAQ,QAAQ,IAAG;CAE7C,OAAO;AACT;AAEA,SAAS,wBACP,OACA,MACmB;CACnB,MAAM,SAAS,MAAM;CACrB,MAAM,kBAAkB,aAAa,OAAO,QAAQ,KAAK;CACzD,MAAM,YAAY,gBAAgB,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,gBAAgB,MAAM,CAAC;CACnF,MAAM,QAAQ,CAAC,GAAG,kBAAkB,OAAO,OAAO,CAAC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