@prisma-next/target-postgres 0.14.0-dev.3 → 0.14.0-dev.30

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 (166) 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/{codec-types-DHCkwPKE.d.mts → codec-types-CueCoGD0.d.mts} +2 -2
  6. package/dist/{codec-types-DHCkwPKE.d.mts.map → codec-types-CueCoGD0.d.mts.map} +1 -1
  7. package/dist/codec-types.d.mts +1 -1
  8. package/dist/{codecs--0A5_4Bq.d.mts → codecs-Ca8upop6.d.mts} +12 -1
  9. package/dist/codecs-Ca8upop6.d.mts.map +1 -0
  10. package/dist/codecs.d.mts +1 -1
  11. package/dist/codecs.mjs +34 -1
  12. package/dist/codecs.mjs.map +1 -1
  13. package/dist/contract-free.d.mts +8 -3
  14. package/dist/contract-free.d.mts.map +1 -1
  15. package/dist/contract-free.mjs +3 -3
  16. package/dist/control.d.mts +1 -1
  17. package/dist/control.d.mts.map +1 -1
  18. package/dist/control.mjs +11 -10
  19. package/dist/control.mjs.map +1 -1
  20. package/dist/data-transform-BOWpliq8.mjs.map +1 -1
  21. package/dist/{data-transform-DDgWdB5o.d.mts → data-transform-qKy1U5V9.d.mts} +2 -2
  22. package/dist/{data-transform-DDgWdB5o.d.mts.map → data-transform-qKy1U5V9.d.mts.map} +1 -1
  23. package/dist/data-transform.d.mts +1 -1
  24. package/dist/{ddl-QDyOSeLc.mjs → ddl-CGf6UABz.mjs} +62 -5
  25. package/dist/ddl-CGf6UABz.mjs.map +1 -0
  26. package/dist/ddl.d.mts +3 -2
  27. package/dist/ddl.mjs +2 -2
  28. package/dist/{default-normalizer-DyyCHQWs.mjs → default-normalizer-CzV8-QSu.mjs} +58 -2
  29. package/dist/default-normalizer-CzV8-QSu.mjs.map +1 -0
  30. package/dist/default-normalizer.d.mts +1 -1
  31. package/dist/default-normalizer.d.mts.map +1 -1
  32. package/dist/default-normalizer.mjs +1 -1
  33. package/dist/descriptor-meta-Dvvpu_jU.mjs +17 -0
  34. package/dist/descriptor-meta-Dvvpu_jU.mjs.map +1 -0
  35. package/dist/descriptor-meta-runtime-D5zHFKUz.mjs +228 -0
  36. package/dist/descriptor-meta-runtime-D5zHFKUz.mjs.map +1 -0
  37. package/dist/{issue-planner-DL6g3CmE.mjs → issue-planner-D5H1VuVP.mjs} +11 -9
  38. package/dist/issue-planner-D5H1VuVP.mjs.map +1 -0
  39. package/dist/issue-planner.d.mts +3 -3
  40. package/dist/issue-planner.d.mts.map +1 -1
  41. package/dist/issue-planner.mjs +1 -1
  42. package/dist/migration.d.mts +3 -3
  43. package/dist/migration.mjs +2 -2
  44. package/dist/nodes-CSkPX3rI.d.mts +120 -0
  45. package/dist/nodes-CSkPX3rI.d.mts.map +1 -0
  46. package/dist/{nodes-Bbhs2rwj.mjs → nodes-Dh__NS58.mjs} +56 -2
  47. package/dist/nodes-Dh__NS58.mjs.map +1 -0
  48. package/dist/{op-factory-call-D_p5vxwt.mjs → op-factory-call-DIdBDwmO.mjs} +199 -28
  49. package/dist/op-factory-call-DIdBDwmO.mjs.map +1 -0
  50. package/dist/{op-factory-call-DmQEc3XV.d.mts → op-factory-call-DPJR7tJc.d.mts} +44 -13
  51. package/dist/op-factory-call-DPJR7tJc.d.mts.map +1 -0
  52. package/dist/op-factory-call.d.mts +1 -1
  53. package/dist/op-factory-call.mjs +1 -1
  54. package/dist/pack.d.mts +74 -2
  55. package/dist/pack.d.mts.map +1 -1
  56. package/dist/pack.mjs +1 -1
  57. package/dist/{planner-Bs_baQax.mjs → planner-BnNEtGYM.mjs} +156 -24
  58. package/dist/planner-BnNEtGYM.mjs.map +1 -0
  59. package/dist/{planner-ddl-builders-B2wOwLqI.mjs → planner-ddl-builders-B8Nn6nHN.mjs} +12 -27
  60. package/dist/planner-ddl-builders-B8Nn6nHN.mjs.map +1 -0
  61. package/dist/planner-ddl-builders.d.mts +2 -4
  62. package/dist/planner-ddl-builders.d.mts.map +1 -1
  63. package/dist/planner-ddl-builders.mjs +2 -2
  64. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts → planner-produced-postgres-migration-BO-frvvN.d.mts} +3 -3
  65. package/dist/{planner-produced-postgres-migration-QqHa2C2l.d.mts.map → planner-produced-postgres-migration-BO-frvvN.d.mts.map} +1 -1
  66. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs → planner-produced-postgres-migration-DzvdQ-7K.mjs} +2 -2
  67. package/dist/{planner-produced-postgres-migration-Cji5vxUf.mjs.map → planner-produced-postgres-migration-DzvdQ-7K.mjs.map} +1 -1
  68. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  69. package/dist/planner-produced-postgres-migration.mjs +1 -1
  70. package/dist/{planner-sql-checks-jqUUGyQR.mjs → planner-sql-checks-CyjaoKhm.mjs} +2 -2
  71. package/dist/{planner-sql-checks-jqUUGyQR.mjs.map → planner-sql-checks-CyjaoKhm.mjs.map} +1 -1
  72. package/dist/planner-sql-checks.mjs +1 -1
  73. package/dist/{planner-target-details-CIY6tLeo.d.mts → planner-target-details-HkP4RrRO.d.mts} +2 -2
  74. package/dist/planner-target-details-HkP4RrRO.d.mts.map +1 -0
  75. package/dist/planner-target-details.d.mts +1 -1
  76. package/dist/planner.d.mts +31 -4
  77. package/dist/planner.d.mts.map +1 -1
  78. package/dist/planner.mjs +2 -2
  79. package/dist/{postgres-contract-serializer-k3TAcPMY.mjs → postgres-contract-serializer-tGMiJcl4.mjs} +30 -21
  80. package/dist/postgres-contract-serializer-tGMiJcl4.mjs.map +1 -0
  81. package/dist/{postgres-migration-B5jKrXv3.mjs → postgres-migration-C8JZyTSJ.mjs} +2 -2
  82. package/dist/{postgres-migration-B5jKrXv3.mjs.map → postgres-migration-C8JZyTSJ.mjs.map} +1 -1
  83. package/dist/{postgres-migration-Y4YBJqkS.d.mts → postgres-migration-Cs7zMOe1.d.mts} +5 -5
  84. package/dist/{postgres-migration-Y4YBJqkS.d.mts.map → postgres-migration-Cs7zMOe1.d.mts.map} +1 -1
  85. package/dist/postgres-rls-policy-12wAEQhs.d.mts +60 -0
  86. package/dist/postgres-rls-policy-12wAEQhs.d.mts.map +1 -0
  87. package/dist/postgres-schema-DJUEkWg-.d.mts +190 -0
  88. package/dist/postgres-schema-DJUEkWg-.d.mts.map +1 -0
  89. package/dist/{postgres-schema-COGZ1ark.mjs → postgres-schema-DLcc3W2-.mjs} +138 -5
  90. package/dist/postgres-schema-DLcc3W2-.mjs.map +1 -0
  91. package/dist/postgres-schema-ir-BJl_a3J7.d.mts +102 -0
  92. package/dist/postgres-schema-ir-BJl_a3J7.d.mts.map +1 -0
  93. package/dist/postgres-schema-ir-I_FiUndw.mjs +133 -0
  94. package/dist/postgres-schema-ir-I_FiUndw.mjs.map +1 -0
  95. package/dist/postgres-schema-ir-annotations-BbDSiwx2.mjs +14 -0
  96. package/dist/postgres-schema-ir-annotations-BbDSiwx2.mjs.map +1 -0
  97. package/dist/render-ops.d.mts +1 -1
  98. package/dist/rls-canonicalize.d.mts +2 -0
  99. package/dist/rls-canonicalize.mjs +2 -0
  100. package/dist/runtime.d.mts +5 -5
  101. package/dist/runtime.d.mts.map +1 -1
  102. package/dist/runtime.mjs +2 -2
  103. package/dist/schema-ir-annotations.d.mts +8 -0
  104. package/dist/schema-ir-annotations.d.mts.map +1 -0
  105. package/dist/schema-ir-annotations.mjs +2 -0
  106. package/dist/types.d.mts +4 -140
  107. package/dist/types.mjs +3 -2
  108. package/package.json +21 -17
  109. package/src/contract-free/checks.ts +73 -0
  110. package/src/contract-free/ddl.ts +45 -1
  111. package/src/core/authoring.ts +115 -1
  112. package/src/core/codecs.ts +35 -1
  113. package/src/core/ddl/nodes.ts +94 -2
  114. package/src/core/default-normalizer.ts +60 -2
  115. package/src/core/descriptor-meta.ts +4 -0
  116. package/src/core/entity-kinds.ts +16 -0
  117. package/src/core/migrations/bound-schema.ts +10 -0
  118. package/src/core/migrations/contract-to-postgres-schema-ir.ts +91 -0
  119. package/src/core/migrations/control-policy.ts +3 -0
  120. package/src/core/migrations/diff-postgres-schema.ts +55 -0
  121. package/src/core/migrations/issue-planner.ts +8 -0
  122. package/src/core/migrations/op-factory-call.ts +106 -21
  123. package/src/core/migrations/operations/columns.ts +24 -12
  124. package/src/core/migrations/operations/data-transform.ts +6 -0
  125. package/src/core/migrations/operations/rls.ts +106 -0
  126. package/src/core/migrations/operations/shared.ts +0 -30
  127. package/src/core/migrations/planner-ddl-builders.ts +15 -56
  128. package/src/core/migrations/planner-recipes.ts +31 -13
  129. package/src/core/migrations/planner-strategies.ts +3 -11
  130. package/src/core/migrations/planner-target-details.ts +3 -1
  131. package/src/core/migrations/planner.ts +84 -1
  132. package/src/core/migrations/verify-postgres-namespaces.ts +12 -15
  133. package/src/core/postgres-contract-serializer.ts +48 -33
  134. package/src/core/postgres-schema.ts +37 -13
  135. package/src/core/postgres-validators.ts +20 -0
  136. package/src/core/rls/canonicalize.ts +48 -0
  137. package/src/core/schema-ir/postgres-rls-policy.ts +101 -0
  138. package/src/core/schema-ir/postgres-role.ts +52 -0
  139. package/src/core/schema-ir/postgres-schema-ir-annotations.ts +22 -0
  140. package/src/core/schema-ir/postgres-schema-ir.ts +138 -0
  141. package/src/core/schema-ir/postgres-table-ir.ts +96 -0
  142. package/src/exports/contract-free.ts +7 -1
  143. package/src/exports/control.ts +11 -12
  144. package/src/exports/ddl.ts +4 -0
  145. package/src/exports/planner-ddl-builders.ts +0 -2
  146. package/src/exports/planner.ts +5 -0
  147. package/src/exports/rls-canonicalize.ts +6 -0
  148. package/src/exports/schema-ir-annotations.ts +1 -0
  149. package/src/exports/types.ts +20 -0
  150. package/dist/codecs--0A5_4Bq.d.mts.map +0 -1
  151. package/dist/ddl-QDyOSeLc.mjs.map +0 -1
  152. package/dist/default-normalizer-DyyCHQWs.mjs.map +0 -1
  153. package/dist/descriptor-meta-CpGygXpI.mjs +0 -140
  154. package/dist/descriptor-meta-CpGygXpI.mjs.map +0 -1
  155. package/dist/issue-planner-DL6g3CmE.mjs.map +0 -1
  156. package/dist/nodes-Bbhs2rwj.mjs.map +0 -1
  157. package/dist/nodes-pLeLgdis.d.mts +0 -67
  158. package/dist/nodes-pLeLgdis.d.mts.map +0 -1
  159. package/dist/op-factory-call-D_p5vxwt.mjs.map +0 -1
  160. package/dist/op-factory-call-DmQEc3XV.d.mts.map +0 -1
  161. package/dist/planner-Bs_baQax.mjs.map +0 -1
  162. package/dist/planner-ddl-builders-B2wOwLqI.mjs.map +0 -1
  163. package/dist/planner-target-details-CIY6tLeo.d.mts.map +0 -1
  164. package/dist/postgres-contract-serializer-k3TAcPMY.mjs.map +0 -1
  165. package/dist/postgres-schema-COGZ1ark.mjs.map +0 -1
  166. package/dist/types.d.mts.map +0 -1
package/dist/types.d.mts CHANGED
@@ -1,141 +1,5 @@
1
- import { t as PostgresTableSource } from "./table-source-BvFo7gVs.mjs";
1
+ import { n as PostgresRlsPolicyInput, r as RlsPolicyOperation, t as PostgresRlsPolicy } from "./postgres-rls-policy-12wAEQhs.mjs";
2
2
  import { t as PostgresColumnDefault } from "./types-BDKkx8MA.mjs";
3
- import { NamespaceBase } from "@prisma-next/framework-components/ir";
4
- import { CfExpr } from "@prisma-next/sql-relational-core/contract-free";
5
- import { SqlNamespaceEntries, SqlNamespaceTablesInput, SqlStorage, StorageTable, StorageValueSet } from "@prisma-next/sql-contract/types";
6
-
7
- //#region src/core/postgres-schema.d.ts
8
- interface PostgresSchemaInput {
9
- readonly id: string;
10
- readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
11
- }
12
- /**
13
- * Postgres target `Namespace` concretion — a Postgres schema (`CREATE
14
- * SCHEMA …`). Each Postgres `SqlStorage` carries a
15
- * `namespaces: Record<NamespaceId, PostgresSchema>` map populated by
16
- * the Postgres PSL interpreter from `namespace { … }` AST buckets.
17
- *
18
- * `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier
19
- * emission is the rendering seam: DDL / SQL emission asks the namespace
20
- * for its qualifier (`"<schema>"`) or for a qualified table name
21
- * (`"<schema>"."<table>"`) and consumes the result polymorphically.
22
- * The unbound singleton below overrides these methods to elide the
23
- * prefix entirely — call sites stay polymorphic and never branch on
24
- * `id === UNBOUND_NAMESPACE_ID`.
25
- */
26
- declare class PostgresSchema extends NamespaceBase {
27
- /**
28
- * Stable singleton reference for the late-bound slot. Materialised
29
- * lazily below the singleton subclass declaration so the static
30
- * initialiser sees the subclass before assigning. Consumers always
31
- * reach for `PostgresSchema.unbound` (or `PostgresUnboundSchema.instance`
32
- * — same identity).
33
- */
34
- static unbound: PostgresUnboundSchema;
35
- readonly kind: 'schema';
36
- readonly id: string;
37
- readonly entries: SqlNamespaceEntries;
38
- constructor(input: PostgresSchemaInput);
39
- get table(): Readonly<Record<string, StorageTable>>;
40
- get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined;
41
- /**
42
- * The bare schema qualifier as it would appear in a rendered SQL
43
- * fragment (already quoted). The unbound-schema singleton overrides
44
- * this to return `''`.
45
- */
46
- qualifier(): string;
47
- /**
48
- * Qualify a table name with the schema prefix
49
- * (`"<schema>"."<table>"`). The unbound-schema singleton overrides
50
- * this to emit just `"<table>"` so the resolved DDL is unqualified
51
- * and `search_path` decides where the object lands at runtime.
52
- */
53
- qualifyTable(tableName: string): string;
54
- /**
55
- * Render a SQL string-literal containing the qualified-name form
56
- * suitable for `to_regclass(...)` arguments (e.g. `'"public"."user"'`).
57
- * The unbound singleton overrides this to elide the schema prefix
58
- * (`'"user"'`) so `search_path` resolves the object at runtime.
59
- */
60
- regclassLiteral(name: string): string;
61
- /**
62
- * Render a SQL expression that evaluates to this namespace's schema
63
- * name at runtime, ready to drop into a `WHERE table_schema = …` /
64
- * `WHERE n.nspname = …` clause. Named schemas emit a quoted SQL
65
- * literal (`'public'`); the unbound singleton overrides this to emit
66
- * `current_schema()` so catalog queries match whichever schema the
67
- * connection's `search_path` resolved at runtime.
68
- */
69
- schemaSqlExpression(): string;
70
- /**
71
- * Typed-AST counterpart of {@link schemaSqlExpression}: the expression a
72
- * builder-built catalog check compares `n.nspname` / `table_schema`
73
- * against. Named schemas bind the schema name as a text parameter; the
74
- * unbound singleton overrides this to the opaque `current_schema()`
75
- * expression so the live connection's `search_path` decides at runtime.
76
- */
77
- schemaFilterExpression(): CfExpr;
78
- /**
79
- * Typed-AST counterpart of {@link qualifyTable}: the FROM source a
80
- * builder-built check uses to address a user table in this namespace.
81
- * Named schemas qualify (`"schema"."table"`); the unbound singleton
82
- * overrides this to leave the table unqualified so `search_path`
83
- * resolves it at runtime.
84
- */
85
- tableSource(tableName: string, alias?: string): PostgresTableSource;
86
- /**
87
- * The bare schema name a DDL planner should target when emitting
88
- * statements that need to identify this namespace in the live
89
- * database (e.g. `CREATE TABLE "<ddlSchemaName>"."<table>" …`,
90
- * catalog filters, planner conflict lookups). Named schemas resolve
91
- * to their own id. The `PostgresUnboundSchema` singleton inherits
92
- * this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch
93
- * through `qualifyTableName` route through the polymorphic
94
- * `PostgresUnboundSchema` overrides and produce unqualified
95
- * (search-path-resolved) output automatically.
96
- */
97
- ddlSchemaName(_storage: SqlStorage): string;
98
- }
99
- /**
100
- * Singleton subclass for the reserved sentinel namespace id
101
- * (`UNBOUND_NAMESPACE_ID`) — the late-bound Postgres slot whose binding
102
- * the connection's `search_path` resolves at runtime. Overrides
103
- * qualifier emission to elide the schema prefix; call sites that consume
104
- * `qualifier()` / `qualifyTable()` get unqualified output without
105
- * branching on the namespace id.
106
- *
107
- * This is the target-side materialization of "the framework provides
108
- * affordances; targets implement specifics": the framework names the
109
- * sentinel; Postgres decides what late-bound means here (the table
110
- * name, naked — the schema is supplied by the live connection's
111
- * `search_path`).
112
- *
113
- * `ddlSchemaName` is inherited from `PostgresSchema` and returns
114
- * `UNBOUND_NAMESPACE_ID`. Downstream helpers such as `qualifyTableName`
115
- * route through the polymorphic factory and produce unqualified output
116
- * automatically.
117
- */
118
- declare class PostgresUnboundSchema extends PostgresSchema {
119
- static readonly instance: PostgresUnboundSchema;
120
- constructor(input?: PostgresSchemaInput);
121
- qualifier(): string;
122
- qualifyTable(tableName: string): string;
123
- schemaSqlExpression(): string;
124
- schemaFilterExpression(): CfExpr;
125
- tableSource(tableName: string, alias?: string): PostgresTableSource;
126
- }
127
- /**
128
- * Target-supplied `Namespace` factory the Postgres target plumbs
129
- * through `defineContract({ createNamespace })` and the SQL PSL
130
- * interpreter. Returns the unbound singleton for the framework
131
- * sentinel and a fresh `PostgresSchema` for any other coordinate.
132
- *
133
- * The factory has no per-call state — every named id deterministically
134
- * maps to a distinct schema instance — so callers can pass it through
135
- * by reference and trust the resulting `SqlStorage.namespaces` map to
136
- * be value-stable for a given input set.
137
- */
138
- declare function postgresCreateNamespace(input: SqlNamespaceTablesInput): PostgresSchema;
139
- //#endregion
140
- export { type PostgresColumnDefault, PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
141
- //# sourceMappingURL=types.d.mts.map
3
+ import { a as postgresCreateNamespace, i as isPostgresSchema, n as PostgresSchema, o as PostgresRole, r as PostgresUnboundSchema, s as PostgresRoleInput, t as PostgresContract } from "./postgres-schema-DJUEkWg-.mjs";
4
+ import { a as isPostgresSchemaIR, c as isPostgresTableIR, i as ensurePostgresSchemaIR, n as PostgresSchemaIRInput, o as PostgresTableIR, r as assertPostgresSchemaIR, s as PostgresTableIRInput, t as PostgresSchemaIR } from "./postgres-schema-ir-BJl_a3J7.mjs";
5
+ export { type PostgresColumnDefault, type PostgresContract, PostgresRlsPolicy, type PostgresRlsPolicyInput, PostgresRole, type PostgresRoleInput, PostgresSchema, PostgresSchemaIR, type PostgresSchemaIRInput, PostgresTableIR, type PostgresTableIRInput, PostgresUnboundSchema, type RlsPolicyOperation, assertPostgresSchemaIR, ensurePostgresSchemaIR, isPostgresSchema, isPostgresSchemaIR, isPostgresTableIR, postgresCreateNamespace };
package/dist/types.mjs CHANGED
@@ -1,2 +1,3 @@
1
- import { i as postgresCreateNamespace, n as PostgresUnboundSchema, t as PostgresSchema } from "./postgres-schema-COGZ1ark.mjs";
2
- export { PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };
1
+ import { c as PostgresRole, i as postgresCreateNamespace, l as PostgresRlsPolicy, n as PostgresUnboundSchema, r as isPostgresSchema, t as PostgresSchema } from "./postgres-schema-DLcc3W2-.mjs";
2
+ import { a as PostgresTableIR, i as isPostgresSchemaIR, n as assertPostgresSchemaIR, o as isPostgresTableIR, r as ensurePostgresSchemaIR, t as PostgresSchemaIR } from "./postgres-schema-ir-I_FiUndw.mjs";
3
+ export { PostgresRlsPolicy, PostgresRole, PostgresSchema, PostgresSchemaIR, PostgresTableIR, PostgresUnboundSchema, assertPostgresSchemaIR, ensurePostgresSchemaIR, isPostgresSchema, isPostgresSchemaIR, isPostgresTableIR, postgresCreateNamespace };
package/package.json CHANGED
@@ -1,32 +1,34 @@
1
1
  {
2
2
  "name": "@prisma-next/target-postgres",
3
- "version": "0.14.0-dev.3",
3
+ "version": "0.14.0-dev.30",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "Postgres target pack for Prisma Next",
8
8
  "dependencies": {
9
- "@prisma-next/cli": "0.14.0-dev.3",
10
- "@prisma-next/contract": "0.14.0-dev.3",
11
- "@prisma-next/errors": "0.14.0-dev.3",
12
- "@prisma-next/family-sql": "0.14.0-dev.3",
13
- "@prisma-next/framework-components": "0.14.0-dev.3",
14
- "@prisma-next/migration-tools": "0.14.0-dev.3",
15
- "@prisma-next/ts-render": "0.14.0-dev.3",
16
- "@prisma-next/sql-contract": "0.14.0-dev.3",
17
- "@prisma-next/sql-errors": "0.14.0-dev.3",
18
- "@prisma-next/sql-operations": "0.14.0-dev.3",
19
- "@prisma-next/sql-relational-core": "0.14.0-dev.3",
20
- "@prisma-next/sql-schema-ir": "0.14.0-dev.3",
21
- "@prisma-next/utils": "0.14.0-dev.3",
9
+ "@prisma-next/cli": "0.14.0-dev.30",
10
+ "@prisma-next/contract": "0.14.0-dev.30",
11
+ "@prisma-next/errors": "0.14.0-dev.30",
12
+ "@prisma-next/family-sql": "0.14.0-dev.30",
13
+ "@prisma-next/framework-components": "0.14.0-dev.30",
14
+ "@prisma-next/migration-tools": "0.14.0-dev.30",
15
+ "@prisma-next/ts-render": "0.14.0-dev.30",
16
+ "@prisma-next/sql-contract": "0.14.0-dev.30",
17
+ "@prisma-next/sql-errors": "0.14.0-dev.30",
18
+ "@prisma-next/sql-operations": "0.14.0-dev.30",
19
+ "@prisma-next/sql-relational-core": "0.14.0-dev.30",
20
+ "@prisma-next/sql-schema-ir": "0.14.0-dev.30",
21
+ "@prisma-next/utils": "0.14.0-dev.30",
22
22
  "@standard-schema/spec": "^1.1.0",
23
23
  "arktype": "^2.2.0",
24
24
  "pathe": "^2.0.3"
25
25
  },
26
26
  "devDependencies": {
27
- "@prisma-next/test-utils": "0.14.0-dev.3",
28
- "@prisma-next/tsconfig": "0.14.0-dev.3",
29
- "@prisma-next/tsdown": "0.14.0-dev.3",
27
+ "@prisma-next/psl-parser": "0.14.0-dev.30",
28
+ "@prisma-next/sql-contract-psl": "0.14.0-dev.30",
29
+ "@prisma-next/test-utils": "0.14.0-dev.30",
30
+ "@prisma-next/tsconfig": "0.14.0-dev.30",
31
+ "@prisma-next/tsdown": "0.14.0-dev.30",
30
32
  "tsdown": "0.22.1",
31
33
  "typescript": "5.9.3",
32
34
  "vitest": "4.1.8"
@@ -68,7 +70,9 @@
68
70
  "./planner-target-details": "./dist/planner-target-details.mjs",
69
71
  "./render-ops": "./dist/render-ops.mjs",
70
72
  "./render-typescript": "./dist/render-typescript.mjs",
73
+ "./rls-canonicalize": "./dist/rls-canonicalize.mjs",
71
74
  "./runtime": "./dist/runtime.mjs",
75
+ "./schema-ir-annotations": "./dist/schema-ir-annotations.mjs",
72
76
  "./sql-utils": "./dist/sql-utils.mjs",
73
77
  "./types": "./dist/types.mjs",
74
78
  "./package.json": "./package.json"
@@ -345,6 +345,79 @@ export function extensionExistsAst(extensionName: string): ExtensionExistsCheckB
345
345
  };
346
346
  }
347
347
 
348
+ export interface RlsPolicyExistsCheckBuilder {
349
+ policyPresent(): SelectAst;
350
+ policyAbsent(): SelectAst;
351
+ }
352
+
353
+ /**
354
+ * Typed RLS-policy existence check over `pg_policies`, with schema, table,
355
+ * and policy names bound as text parameters (never inlined). The `schema`
356
+ * coordinate is the resolved live-database schema name (e.g. `'public'`),
357
+ * compared against `pg_policies.schemaname` as a bound parameter.
358
+ */
359
+ export function rlsPolicyExistsAst(options: {
360
+ readonly schema: string;
361
+ readonly table: string;
362
+ readonly policyName: string;
363
+ }): RlsPolicyExistsCheckBuilder {
364
+ const inner = () =>
365
+ exprSelect()
366
+ .from(cfTable('pg_policies'))
367
+ .project('one', cfExpr.lit(1))
368
+ .where(
369
+ cfExpr.allOf([
370
+ cfExpr.identifierRef('schemaname').eqParam(options.schema, PG_TEXT_CODEC_ID),
371
+ cfExpr.identifierRef('tablename').eqParam(options.table, PG_TEXT_CODEC_ID),
372
+ cfExpr.identifierRef('policyname').eqParam(options.policyName, PG_TEXT_CODEC_ID),
373
+ ]),
374
+ );
375
+ return {
376
+ policyPresent: () => exprSelect().project('result', cfExpr.exists(inner())).build(),
377
+ policyAbsent: () => exprSelect().project('result', cfExpr.notExists(inner())).build(),
378
+ };
379
+ }
380
+
381
+ export interface RlsEnabledCheckBuilder {
382
+ rlsEnabled(): SelectAst;
383
+ rlsDisabled(): SelectAst;
384
+ }
385
+
386
+ /**
387
+ * Typed row-level-security enabled check over `pg_class` joined to
388
+ * `pg_namespace`, comparing `pg_class.relrowsecurity` against the expected
389
+ * boolean. Schema and table names are bound as text parameters.
390
+ */
391
+ export function rlsEnabledAst(schema: string, table: string): RlsEnabledCheckBuilder {
392
+ const inner = (enabled: boolean) =>
393
+ exprSelect()
394
+ .from(cfTable('pg_class', 'c'))
395
+ .join(
396
+ cfTable('pg_namespace', 'n'),
397
+ cfExpr.columnRef('n', 'oid').eqExpr(cfExpr.columnRef('c', 'relnamespace')),
398
+ )
399
+ .project('one', cfExpr.lit(1))
400
+ .where(
401
+ cfExpr.allOf([
402
+ cfExpr.columnRef('n', 'nspname').eqParam(schema, PG_TEXT_CODEC_ID),
403
+ cfExpr.columnRef('c', 'relname').eqParam(table, PG_TEXT_CODEC_ID),
404
+ enabled
405
+ ? cfExpr.columnRef('c', 'relrowsecurity')
406
+ : cfExpr.columnRef('c', 'relrowsecurity').not(),
407
+ ]),
408
+ );
409
+ return {
410
+ rlsEnabled: () =>
411
+ exprSelect()
412
+ .project('result', cfExpr.exists(inner(true)))
413
+ .build(),
414
+ rlsDisabled: () =>
415
+ exprSelect()
416
+ .project('result', cfExpr.exists(inner(false)))
417
+ .build(),
418
+ };
419
+ }
420
+
348
421
  export interface IndexExistsCheckBuilder {
349
422
  indexPresent(): SelectAst;
350
423
  indexAbsent(): SelectAst;
@@ -2,9 +2,13 @@ import type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-
2
2
  import {
3
3
  AddColumnAction,
4
4
  type AnyAlterTableAction,
5
+ DropDefaultAction,
5
6
  PostgresAlterTable,
7
+ PostgresCreatePolicy,
6
8
  PostgresCreateSchema,
7
9
  PostgresCreateTable,
10
+ PostgresDropPolicy,
11
+ type RlsPolicyOperation,
8
12
  } from '../core/ddl/nodes';
9
13
 
10
14
  /**
@@ -51,9 +55,17 @@ export function addColumnAction(column: DdlColumn): AddColumnAction {
51
55
  return new AddColumnAction(column);
52
56
  }
53
57
 
58
+ /**
59
+ * Build a `DROP DEFAULT` action (`ALTER COLUMN "<name>" DROP DEFAULT`) for
60
+ * use inside {@link alterTable}. The renderer quotes the column name.
61
+ */
62
+ export function dropDefaultAction(columnName: string): DropDefaultAction {
63
+ return new DropDefaultAction(columnName);
64
+ }
65
+
54
66
  /**
55
67
  * Build a Postgres `ALTER TABLE` query node carrying one or more actions.
56
- * See {@link addColumnAction} for building actions.
68
+ * See {@link addColumnAction} / {@link dropDefaultAction} for building actions.
57
69
  */
58
70
  export function alterTable(options: {
59
71
  readonly table: string;
@@ -62,3 +74,35 @@ export function alterTable(options: {
62
74
  }): PostgresAlterTable {
63
75
  return new PostgresAlterTable(options);
64
76
  }
77
+
78
+ /**
79
+ * Build a Postgres `CREATE POLICY` DDL node.
80
+ *
81
+ * Identifiers (`schema`, `table`, `name`) are quoted by the renderer.
82
+ * `using` and `withCheck` are emitted verbatim as predicate SQL — callers
83
+ * must supply safe, pre-validated SQL expressions.
84
+ */
85
+ export function createPolicy(options: {
86
+ readonly schema: string;
87
+ readonly table: string;
88
+ readonly name: string;
89
+ readonly permissive: boolean;
90
+ readonly operation: RlsPolicyOperation;
91
+ readonly roles: readonly string[];
92
+ readonly using?: string;
93
+ readonly withCheck?: string;
94
+ }): PostgresCreatePolicy {
95
+ return new PostgresCreatePolicy(options);
96
+ }
97
+
98
+ /**
99
+ * Build a Postgres `DROP POLICY` DDL node.
100
+ * Identifiers (`schema`, `table`, `name`) are quoted by the renderer.
101
+ */
102
+ export function dropPolicy(options: {
103
+ readonly schema: string;
104
+ readonly table: string;
105
+ readonly name: string;
106
+ }): PostgresDropPolicy {
107
+ return new PostgresDropPolicy(options);
108
+ }
@@ -1,13 +1,94 @@
1
1
  import { temporalAuthoringPresets } from '@prisma-next/family-sql/control';
2
2
  import type {
3
+ AuthoringEntityContext,
3
4
  AuthoringEntityTypeNamespace,
4
5
  AuthoringFieldNamespace,
6
+ AuthoringPslBlockDescriptorNamespace,
5
7
  AuthoringTypeNamespace,
8
+ PslExtensionBlock,
6
9
  } from '@prisma-next/framework-components/authoring';
10
+ import { PostgresRlsPolicySchema, PostgresRoleSchema } from './postgres-validators';
11
+ import { computeContentHash, normalizePredicate } from './rls/canonicalize';
12
+ import { PostgresRlsPolicy } from './schema-ir/postgres-rls-policy';
13
+ import { PostgresRole, type PostgresRoleInput } from './schema-ir/postgres-role';
7
14
 
8
15
  export const postgresAuthoringTypes = {} as const satisfies AuthoringTypeNamespace;
9
16
 
10
- export const postgresAuthoringEntityTypes = {} as const satisfies AuthoringEntityTypeNamespace;
17
+ export interface RlsPolicyExtensionBlock extends PslExtensionBlock {
18
+ readonly namespaceId: string;
19
+ }
20
+
21
+ function readRefParam(block: PslExtensionBlock, key: string): string | undefined {
22
+ const param = block.parameters[key];
23
+ return param?.kind === 'ref' ? param.identifier : undefined;
24
+ }
25
+
26
+ function readValueParam(block: PslExtensionBlock, key: string): string | undefined {
27
+ const param = block.parameters[key];
28
+ return param?.kind === 'value' ? param.raw : undefined;
29
+ }
30
+
31
+ function readListRefParams(block: PslExtensionBlock, key: string): string[] {
32
+ const param = block.parameters[key];
33
+ if (param?.kind !== 'list') return [];
34
+ return param.items.flatMap((item) => (item.kind === 'ref' ? [item.identifier] : []));
35
+ }
36
+
37
+ function unwrapQuotedString(raw: string): string {
38
+ if (raw.startsWith('"') && raw.endsWith('"') && raw.length >= 2) {
39
+ return raw.slice(1, -1).replace(/\\"/g, '"');
40
+ }
41
+ return raw;
42
+ }
43
+
44
+ function lowerRlsPolicyFromBlock(
45
+ block: RlsPolicyExtensionBlock,
46
+ _ctx: AuthoringEntityContext,
47
+ ): PostgresRlsPolicy {
48
+ const prefix = block.name;
49
+ const targetModelName = readRefParam(block, 'target') ?? '';
50
+ const tableName = targetModelName.charAt(0).toLowerCase() + targetModelName.slice(1);
51
+ const roles = [...readListRefParams(block, 'roles')].sort();
52
+ const using = unwrapQuotedString(readValueParam(block, 'using') ?? '');
53
+
54
+ const wireHash = computeContentHash({
55
+ using: normalizePredicate(using),
56
+ roles,
57
+ operation: 'select',
58
+ permissive: true,
59
+ });
60
+ const wireName = `${prefix}_${wireHash}`;
61
+
62
+ return new PostgresRlsPolicy({
63
+ name: wireName,
64
+ prefix,
65
+ tableName,
66
+ namespaceId: block.namespaceId,
67
+ operation: 'select',
68
+ roles,
69
+ using,
70
+ permissive: true,
71
+ });
72
+ }
73
+
74
+ export const postgresAuthoringEntityTypes = {
75
+ role: {
76
+ kind: 'entity',
77
+ discriminator: 'role',
78
+ validatorSchema: PostgresRoleSchema,
79
+ output: {
80
+ factory: (input: PostgresRoleInput): PostgresRole => new PostgresRole(input),
81
+ },
82
+ },
83
+ policy: {
84
+ kind: 'entity',
85
+ discriminator: 'policy',
86
+ validatorSchema: PostgresRlsPolicySchema,
87
+ output: {
88
+ factory: lowerRlsPolicyFromBlock,
89
+ },
90
+ },
91
+ } as const satisfies AuthoringEntityTypeNamespace;
11
92
 
12
93
  /**
13
94
  * Field presets contributed by the Postgres target pack.
@@ -22,6 +103,39 @@ export const postgresAuthoringEntityTypes = {} as const satisfies AuthoringEntit
22
103
  * portability use `uuidString` / `id.uuidv4String` / `id.uuidv7String` from
23
104
  * the family pack instead.
24
105
  */
106
+ /**
107
+ * PSL block descriptor for `policy_select`.
108
+ *
109
+ * The parser learns the block shape from this descriptor; lowering from
110
+ * `PslExtensionBlock` to `PostgresRlsPolicy` is wired in the PSL
111
+ * interpreter (a later dispatch). The `discriminator` matches
112
+ * `PostgresRlsPolicy.kind` so the parsed block node carries the same
113
+ * discriminant as the IR class it will lower to.
114
+ *
115
+ * The `roles` list uses `scope:'cross-space'` because same-namespace
116
+ * role ref resolution requires PSL namespace entries keyed by `refKind`
117
+ * (i.e. `'role'`), which in turn requires the role block discriminator to
118
+ * equal `'role'`. Aligning discriminator with refKind is tracked for
119
+ * slice 4 (cross-space roles). Until then cross-space passes validation
120
+ * unconditionally and the authored role names flow through unchanged.
121
+ */
122
+ export const postgresAuthoringPslBlockDescriptors = {
123
+ policy_select: {
124
+ kind: 'pslBlock',
125
+ keyword: 'policy_select',
126
+ discriminator: 'policy',
127
+ name: { required: true },
128
+ parameters: {
129
+ target: { kind: 'ref', refKind: 'model', scope: 'same-namespace', required: true },
130
+ roles: {
131
+ kind: 'list',
132
+ of: { kind: 'ref', refKind: 'role', scope: 'cross-space' },
133
+ },
134
+ using: { kind: 'value', codecId: 'pg/text@1', required: true },
135
+ },
136
+ },
137
+ } as const satisfies AuthoringPslBlockDescriptorNamespace;
138
+
25
139
  export const postgresAuthoringFieldPresets = {
26
140
  text: {
27
141
  kind: 'fieldPreset',
@@ -4,7 +4,7 @@
4
4
  * Each codec ships as three artifacts:
5
5
  *
6
6
  * 1. A `PgXCodec` class extending {@link CodecImpl} that wraps the module-level encode/decode/encodeJson/decodeJson constants exported from `codec-helpers.ts` (the single source of truth for non-trivial runtime conversions; trivial identity passthroughs are inlined). 2. A `PgXDescriptor` class extending {@link CodecDescriptorImpl} declaring the codec id, traits, target types, params schema, meta, and (where applicable)
7
- * the emit-path `renderOutputType`. 3. A per-codec column helper (`pgXColumn`) that calls `descriptor.factory(...)` directly and packages the result into a {@link ColumnSpec} via the framework {@link column} packager. The helper is tied to its descriptor with `satisfies ColumnHelperFor` (and `ColumnHelperForStrict` where the resolved codec type is well-defined).
7
+ * the emit-path `renderOutputType`. 3. A per-codec column helper (`pgXColumn`) that calls `descriptor.factory(...)` directly and packages the result into a framework `ColumnSpec` via the framework {@link column} packager. The helper is tied to its descriptor with `satisfies ColumnHelperFor` (and `ColumnHelperForStrict` where the resolved codec type is well-defined).
8
8
  *
9
9
  * After TML-2357 this is the canonical source of Postgres codec metadata and runtime behaviour — the legacy `mkCodec` / `defineCodec` carriers (and the parallel `byScalar`/`codecDescriptorDefinitions`/ `codecDescriptorList` collection exports) retired with the deletion sweep.
10
10
  *
@@ -22,6 +22,7 @@ import {
22
22
  type ColumnHelperFor,
23
23
  type ColumnHelperForStrict,
24
24
  column,
25
+ renderTsLiteral,
25
26
  voidParamsSchema,
26
27
  } from '@prisma-next/framework-components/codec';
27
28
  import {
@@ -148,6 +149,9 @@ export class PgTextDescriptor extends CodecDescriptorImpl<void> {
148
149
  override readonly targetTypes = ['text'] as const;
149
150
  override readonly meta = PG_TEXT_META;
150
151
  override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
152
+ override renderValueLiteral(value: JsonValue): string | undefined {
153
+ return renderTsLiteral(value);
154
+ }
151
155
  override factory(): (ctx: CodecInstanceContext) => PgTextCodec {
152
156
  return () => new PgTextCodec(this);
153
157
  }
@@ -228,6 +232,9 @@ export class PgInt4Descriptor extends CodecDescriptorImpl<void> {
228
232
  override readonly targetTypes = ['int4'] as const;
229
233
  override readonly meta = PG_INT4_META;
230
234
  override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
235
+ override renderValueLiteral(value: JsonValue): string | undefined {
236
+ return renderTsLiteral(value);
237
+ }
231
238
  override factory(): (ctx: CodecInstanceContext) => PgInt4Codec {
232
239
  return () => new PgInt4Codec(this);
233
240
  }
@@ -267,6 +274,9 @@ export class PgInt2Descriptor extends CodecDescriptorImpl<void> {
267
274
  override readonly targetTypes = ['int2'] as const;
268
275
  override readonly meta = PG_INT2_META;
269
276
  override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
277
+ override renderValueLiteral(value: JsonValue): string | undefined {
278
+ return renderTsLiteral(value);
279
+ }
270
280
  override factory(): (ctx: CodecInstanceContext) => PgInt2Codec {
271
281
  return () => new PgInt2Codec(this);
272
282
  }
@@ -306,6 +316,9 @@ export class PgInt8Descriptor extends CodecDescriptorImpl<void> {
306
316
  override readonly targetTypes = ['int8'] as const;
307
317
  override readonly meta = PG_INT8_META;
308
318
  override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
319
+ override renderValueLiteral(value: JsonValue): string | undefined {
320
+ return renderTsLiteral(value);
321
+ }
309
322
  override factory(): (ctx: CodecInstanceContext) => PgInt8Codec {
310
323
  return () => new PgInt8Codec(this);
311
324
  }
@@ -345,6 +358,9 @@ export class PgFloat4Descriptor extends CodecDescriptorImpl<void> {
345
358
  override readonly targetTypes = ['float4'] as const;
346
359
  override readonly meta = PG_FLOAT4_META;
347
360
  override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
361
+ override renderValueLiteral(value: JsonValue): string | undefined {
362
+ return renderTsLiteral(value);
363
+ }
348
364
  override factory(): (ctx: CodecInstanceContext) => PgFloat4Codec {
349
365
  return () => new PgFloat4Codec(this);
350
366
  }
@@ -384,6 +400,9 @@ export class PgFloat8Descriptor extends CodecDescriptorImpl<void> {
384
400
  override readonly targetTypes = ['float8'] as const;
385
401
  override readonly meta = PG_FLOAT8_META;
386
402
  override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
403
+ override renderValueLiteral(value: JsonValue): string | undefined {
404
+ return renderTsLiteral(value);
405
+ }
387
406
  override factory(): (ctx: CodecInstanceContext) => PgFloat8Codec {
388
407
  return () => new PgFloat8Codec(this);
389
408
  }
@@ -423,6 +442,9 @@ export class PgBoolDescriptor extends CodecDescriptorImpl<void> {
423
442
  override readonly targetTypes = ['bool'] as const;
424
443
  override readonly meta = PG_BOOL_META;
425
444
  override readonly paramsSchema: StandardSchemaV1<void> = voidParamsSchema;
445
+ override renderValueLiteral(value: JsonValue): string | undefined {
446
+ return renderTsLiteral(value);
447
+ }
426
448
  override factory(): (ctx: CodecInstanceContext) => PgBoolCodec {
427
449
  return () => new PgBoolCodec(this);
428
450
  }
@@ -968,6 +990,9 @@ export class PgCharDescriptor extends CodecDescriptorImpl<LengthParams> {
968
990
  override renderOutputType(params: LengthParams): string | undefined {
969
991
  return sqlCharDescriptor.renderOutputType(params);
970
992
  }
993
+ override renderValueLiteral(value: JsonValue): string | undefined {
994
+ return renderTsLiteral(value);
995
+ }
971
996
  override factory(_params: LengthParams): (ctx: CodecInstanceContext) => SqlCharCodec {
972
997
  return () => new SqlCharCodec(this);
973
998
  }
@@ -989,6 +1014,9 @@ export class PgVarcharDescriptor extends CodecDescriptorImpl<LengthParams> {
989
1014
  override renderOutputType(params: LengthParams): string | undefined {
990
1015
  return sqlVarcharDescriptor.renderOutputType(params);
991
1016
  }
1017
+ override renderValueLiteral(value: JsonValue): string | undefined {
1018
+ return renderTsLiteral(value);
1019
+ }
992
1020
  override factory(_params: LengthParams): (ctx: CodecInstanceContext) => SqlVarcharCodec {
993
1021
  return () => new SqlVarcharCodec(this);
994
1022
  }
@@ -1012,6 +1040,9 @@ export class PgIntDescriptor extends CodecDescriptorImpl<void> {
1012
1040
  override readonly meta = PG_INT_META;
1013
1041
  override readonly traits = sqlIntDescriptor.traits;
1014
1042
  override readonly paramsSchema = sqlIntDescriptor.paramsSchema;
1043
+ override renderValueLiteral(value: JsonValue): string | undefined {
1044
+ return renderTsLiteral(value);
1045
+ }
1015
1046
  override factory(): (ctx: CodecInstanceContext) => SqlIntCodec {
1016
1047
  return () => new SqlIntCodec(this);
1017
1048
  }
@@ -1030,6 +1061,9 @@ export class PgFloatDescriptor extends CodecDescriptorImpl<void> {
1030
1061
  override readonly meta = PG_FLOAT_META;
1031
1062
  override readonly traits = sqlFloatDescriptor.traits;
1032
1063
  override readonly paramsSchema = sqlFloatDescriptor.paramsSchema;
1064
+ override renderValueLiteral(value: JsonValue): string | undefined {
1065
+ return renderTsLiteral(value);
1066
+ }
1033
1067
  override factory(): (ctx: CodecInstanceContext) => SqlFloatCodec {
1034
1068
  return () => new SqlFloatCodec(this);
1035
1069
  }