@prisma-next/target-postgres 0.13.0-dev.35 → 0.13.0-dev.37

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 (81) hide show
  1. package/dist/contract-free.d.mts +147 -14
  2. package/dist/contract-free.d.mts.map +1 -1
  3. package/dist/contract-free.mjs +3 -16
  4. package/dist/contract-free.mjs.map +1 -1
  5. package/dist/control.mjs +2 -2
  6. package/dist/ddl-QDyOSeLc.mjs +251 -0
  7. package/dist/ddl-QDyOSeLc.mjs.map +1 -0
  8. package/dist/{issue-planner-9AVUEL74.mjs → issue-planner-CoI_0uM1.mjs} +8 -118
  9. package/dist/issue-planner-CoI_0uM1.mjs.map +1 -0
  10. package/dist/issue-planner.d.mts +1 -1
  11. package/dist/issue-planner.d.mts.map +1 -1
  12. package/dist/issue-planner.mjs +1 -1
  13. package/dist/migration.d.mts +4 -80
  14. package/dist/migration.d.mts.map +1 -1
  15. package/dist/migration.mjs +3 -3
  16. package/dist/{op-factory-call-CvDOetGa.mjs → op-factory-call-B1bXWtfa.mjs} +551 -241
  17. package/dist/op-factory-call-B1bXWtfa.mjs.map +1 -0
  18. package/dist/{op-factory-call-CdtMyrlU.d.mts → op-factory-call-DmQEc3XV.d.mts} +111 -20
  19. package/dist/op-factory-call-DmQEc3XV.d.mts.map +1 -0
  20. package/dist/op-factory-call.d.mts +1 -1
  21. package/dist/op-factory-call.mjs +1 -1
  22. package/dist/{planner-BZxjjT8T.mjs → planner-DS5XBhmi.mjs} +4 -4
  23. package/dist/{planner-BZxjjT8T.mjs.map → planner-DS5XBhmi.mjs.map} +1 -1
  24. package/dist/{planner-produced-postgres-migration-CkECqqTy.mjs → planner-produced-postgres-migration-DTwCCek_.mjs} +2 -2
  25. package/dist/{planner-produced-postgres-migration-CkECqqTy.mjs.map → planner-produced-postgres-migration-DTwCCek_.mjs.map} +1 -1
  26. package/dist/{planner-produced-postgres-migration-wLhnJMMA.d.mts → planner-produced-postgres-migration-QqHa2C2l.d.mts} +2 -2
  27. package/dist/{planner-produced-postgres-migration-wLhnJMMA.d.mts.map → planner-produced-postgres-migration-QqHa2C2l.d.mts.map} +1 -1
  28. package/dist/planner-produced-postgres-migration.d.mts +1 -1
  29. package/dist/planner-produced-postgres-migration.mjs +1 -1
  30. package/dist/planner-sql-checks-jqUUGyQR.mjs +152 -0
  31. package/dist/planner-sql-checks-jqUUGyQR.mjs.map +1 -0
  32. package/dist/planner-sql-checks.d.mts +1 -47
  33. package/dist/planner-sql-checks.d.mts.map +1 -1
  34. package/dist/planner-sql-checks.mjs +2 -2
  35. package/dist/planner.d.mts +1 -1
  36. package/dist/planner.mjs +1 -1
  37. package/dist/{postgres-contract-serializer-sdg1B6Og.mjs → postgres-contract-serializer-E92REOFk.mjs} +2 -2
  38. package/dist/{postgres-contract-serializer-sdg1B6Og.mjs.map → postgres-contract-serializer-E92REOFk.mjs.map} +1 -1
  39. package/dist/postgres-migration-Y4YBJqkS.d.mts +181 -0
  40. package/dist/postgres-migration-Y4YBJqkS.d.mts.map +1 -0
  41. package/dist/postgres-migration-otiaw3Ru.mjs +145 -0
  42. package/dist/postgres-migration-otiaw3Ru.mjs.map +1 -0
  43. package/dist/{postgres-schema-CDaLWZwd.mjs → postgres-schema-COGZ1ark.mjs} +61 -8
  44. package/dist/postgres-schema-COGZ1ark.mjs.map +1 -0
  45. package/dist/runtime.mjs +1 -1
  46. package/dist/table-source-BvFo7gVs.d.mts +15 -0
  47. package/dist/table-source-BvFo7gVs.d.mts.map +1 -0
  48. package/dist/types.d.mts +26 -6
  49. package/dist/types.d.mts.map +1 -1
  50. package/dist/types.mjs +1 -1
  51. package/package.json +17 -17
  52. package/src/contract-free/checks.ts +363 -0
  53. package/src/core/migrations/op-factory-call.ts +417 -94
  54. package/src/core/migrations/operations/columns.ts +175 -140
  55. package/src/core/migrations/operations/constraints.ts +79 -108
  56. package/src/core/migrations/operations/dependencies.ts +16 -14
  57. package/src/core/migrations/operations/indexes.ts +31 -28
  58. package/src/core/migrations/operations/shared.ts +2 -2
  59. package/src/core/migrations/operations/tables.ts +13 -14
  60. package/src/core/migrations/planner-recipes.ts +42 -33
  61. package/src/core/migrations/planner-sql-checks.ts +1 -172
  62. package/src/core/migrations/planner-strategies.ts +25 -73
  63. package/src/core/migrations/postgres-migration.ts +272 -7
  64. package/src/core/postgres-schema.ts +47 -6
  65. package/src/exports/contract-free.ts +21 -0
  66. package/src/exports/migration.ts +1 -22
  67. package/src/exports/planner-sql-checks.ts +0 -7
  68. package/dist/ddl-DY2R_Yqz.mjs +0 -45
  69. package/dist/ddl-DY2R_Yqz.mjs.map +0 -1
  70. package/dist/issue-planner-9AVUEL74.mjs.map +0 -1
  71. package/dist/op-factory-call-CdtMyrlU.d.mts.map +0 -1
  72. package/dist/op-factory-call-CvDOetGa.mjs.map +0 -1
  73. package/dist/planner-sql-checks-Bj4G0_gO.mjs +0 -272
  74. package/dist/planner-sql-checks-Bj4G0_gO.mjs.map +0 -1
  75. package/dist/postgres-migration-DLXL0GBf.d.mts +0 -77
  76. package/dist/postgres-migration-DLXL0GBf.d.mts.map +0 -1
  77. package/dist/postgres-migration-DMnWjdni.mjs +0 -75
  78. package/dist/postgres-migration-DMnWjdni.mjs.map +0 -1
  79. package/dist/postgres-schema-CDaLWZwd.mjs.map +0 -1
  80. package/dist/shared-jcsbXxiW.d.mts +0 -25
  81. package/dist/shared-jcsbXxiW.d.mts.map +0 -1
@@ -0,0 +1,181 @@
1
+ import { t as PostgresPlanTargetDetails } from "./planner-target-details-CIY6tLeo.mjs";
2
+ import { n as DataTransformOptions } from "./data-transform-DDgWdB5o.mjs";
3
+ import { s as AlterColumnTypeOptions, w as ForeignKeySpec } from "./op-factory-call-DmQEc3XV.mjs";
4
+ import { DdlColumn, DdlTableConstraint } from "@prisma-next/sql-relational-core/ast";
5
+ import { SqlMigrationPlanOperation } from "@prisma-next/family-sql/control";
6
+ import { SqlStorage } from "@prisma-next/sql-contract/types";
7
+ import { Migration } from "@prisma-next/family-sql/migration";
8
+ import { ControlStack } from "@prisma-next/framework-components/control";
9
+ import { Contract } from "@prisma-next/contract/types";
10
+ import { ExecuteRequestLowerer, SqlControlAdapter } from "@prisma-next/family-sql/control-adapter";
11
+
12
+ //#region src/core/migrations/operations/indexes.d.ts
13
+ interface CreateIndexExtras {
14
+ readonly type?: string;
15
+ readonly options?: Record<string, unknown>;
16
+ }
17
+ //#endregion
18
+ //#region src/core/migrations/postgres-migration.d.ts
19
+ /**
20
+ * Target-owned base class for Postgres migrations.
21
+ *
22
+ * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the
23
+ * abstract `targetId` to the Postgres target-id string literal, so both
24
+ * user-authored migrations and renderer-generated scaffolds (the output of
25
+ * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without
26
+ * redeclaring target-local identity.
27
+ *
28
+ * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer
29
+ * emits `extends Migration` against a facade re-export of this class
30
+ * from `@prisma-next/postgres/migration`, keeping the authoring surface
31
+ * target-scoped rather than family-scoped.
32
+ *
33
+ * The constructor materializes a single Postgres `SqlControlAdapter` from
34
+ * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`
35
+ * instance method forwards to the free `dataTransform` factory with that
36
+ * stored adapter, so user migrations can write `this.dataTransform(...)`
37
+ * without threading the adapter through every call.
38
+ *
39
+ * Every method requires an explicit `schema`. Postgres migrations name their
40
+ * schema deliberately — there is no default and no `search_path`-relative
41
+ * option. A migration that left the schema unspecified would resolve against
42
+ * whatever `search_path` the connection happened to carry, and that ambiguity
43
+ * is an antipattern in a migration. (The unbound/unspecified namespace concept
44
+ * remains for SQLite, which has no schemas, and for Mongo's connection `db`.)
45
+ */
46
+ declare abstract class PostgresMigration extends Migration<PostgresPlanTargetDetails, 'postgres'> {
47
+ readonly targetId: "postgres";
48
+ /**
49
+ * Materialized Postgres control adapter, created once per migration
50
+ * instance from the injected stack. `undefined` only when the migration
51
+ * was instantiated without a stack (test fixtures); `dataTransform`
52
+ * throws in that case to surface the misuse.
53
+ */
54
+ protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;
55
+ constructor(stack?: ControlStack<'sql', 'postgres'>);
56
+ /**
57
+ * Instance-method wrapper around the free `dataTransform` factory that
58
+ * supplies the stored control adapter. Authors call this from inside
59
+ * `get operations()`; the adapter argument is hidden from the call site.
60
+ */
61
+ protected dataTransform<TContract extends Contract<SqlStorage>>(contract: TContract, name: string, options: DataTransformOptions): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
62
+ /**
63
+ * Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from
64
+ * the supplied options and lowers it through the stored control adapter.
65
+ * Throws if no adapter is present (i.e. migration instantiated without a stack).
66
+ */
67
+ protected createTable(options: {
68
+ readonly schema: string;
69
+ readonly table: string;
70
+ readonly ifNotExists?: boolean;
71
+ readonly columns: readonly DdlColumn[];
72
+ readonly constraints?: readonly DdlTableConstraint[];
73
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
74
+ /**
75
+ * Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from
76
+ * the supplied options and lowers it through the stored control adapter.
77
+ * Throws if no adapter is present (i.e. migration instantiated without a stack).
78
+ */
79
+ protected createSchema(options: {
80
+ readonly schema: string;
81
+ readonly ifNotExists?: boolean;
82
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
83
+ protected addColumn(options: {
84
+ readonly schema: string;
85
+ readonly table: string;
86
+ readonly column: DdlColumn;
87
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
88
+ protected addPrimaryKey(options: {
89
+ readonly schema: string;
90
+ readonly table: string;
91
+ readonly constraint: string;
92
+ readonly columns: readonly string[];
93
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
94
+ protected addUnique(options: {
95
+ readonly schema: string;
96
+ readonly table: string;
97
+ readonly constraint: string;
98
+ readonly columns: readonly string[];
99
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
100
+ protected addForeignKey(options: {
101
+ readonly schema: string;
102
+ readonly table: string;
103
+ readonly foreignKey: ForeignKeySpec;
104
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
105
+ protected addCheckConstraint(options: {
106
+ readonly schema: string;
107
+ readonly table: string;
108
+ readonly constraint: string;
109
+ readonly column: string;
110
+ readonly values: readonly string[];
111
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
112
+ protected dropCheckConstraint(options: {
113
+ readonly schema: string;
114
+ readonly table: string;
115
+ readonly constraint: string;
116
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
117
+ protected dropConstraint(options: {
118
+ readonly schema: string;
119
+ readonly table: string;
120
+ readonly constraint: string;
121
+ readonly kind?: 'foreignKey' | 'unique' | 'primaryKey';
122
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
123
+ protected dropTable(options: {
124
+ readonly schema: string;
125
+ readonly table: string;
126
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
127
+ protected dropColumn(options: {
128
+ readonly schema: string;
129
+ readonly table: string;
130
+ readonly column: string;
131
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
132
+ protected alterColumnType(options: {
133
+ readonly schema: string;
134
+ readonly table: string;
135
+ readonly column: string;
136
+ readonly options: AlterColumnTypeOptions;
137
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
138
+ protected setNotNull(options: {
139
+ readonly schema: string;
140
+ readonly table: string;
141
+ readonly column: string;
142
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
143
+ protected dropNotNull(options: {
144
+ readonly schema: string;
145
+ readonly table: string;
146
+ readonly column: string;
147
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
148
+ protected setDefault(options: {
149
+ readonly schema: string;
150
+ readonly table: string;
151
+ readonly column: string;
152
+ readonly defaultSql: string;
153
+ readonly operationClass?: 'additive' | 'widening';
154
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
155
+ protected dropDefault(options: {
156
+ readonly schema: string;
157
+ readonly table: string;
158
+ readonly column: string;
159
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
160
+ protected createIndex(options: {
161
+ readonly schema: string;
162
+ readonly table: string;
163
+ readonly index: string;
164
+ readonly columns: readonly string[];
165
+ readonly extras?: CreateIndexExtras;
166
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
167
+ protected dropIndex(options: {
168
+ readonly schema: string;
169
+ readonly table: string;
170
+ readonly index: string;
171
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
172
+ protected installExtension(options: {
173
+ readonly extensionName: string;
174
+ readonly invariantId: string;
175
+ readonly id: string;
176
+ readonly label?: string;
177
+ }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>>;
178
+ }
179
+ //#endregion
180
+ export { PostgresMigration as t };
181
+ //# sourceMappingURL=postgres-migration-Y4YBJqkS.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-migration-Y4YBJqkS.d.mts","names":[],"sources":["../src/core/migrations/operations/indexes.ts","../src/core/migrations/postgres-migration.ts"],"mappings":";;;;;;;;;;;;UAmBiB,iBAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA,GAAU,MAAM;AAAA;;;AAF3B;;;;;;;;AAE2B;;;;ACyC3B;;;;;;;;;;;;;;;AD3CA,uBC2CsB,iBAAA,SAA0B,SAAA,CAC9C,yBAAA;EAAA,SAGS,QAAA;EA+CL;;;;;;EAAA,mBAvCe,cAAA,EAAgB,iBAAA;cAEvB,KAAA,GAAQ,YAAA;EAkFkB;;;;;EAAA,UAnE5B,aAAA,mBAAgC,QAAA,CAAS,UAAA,GACjD,QAAA,EAAU,SAAA,EACV,IAAA,UACA,OAAA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A;EAAA,IAChB,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EAAA,UAa5B,SAAA,CAAU,OAAA;IAAA,SACT,MAAA;IAAA,SACA,KAAA;IAAA,SACA,KAAA;EAAA,IACP,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;EAAA,UAS5B,gBAAA,CAAiB,OAAA;IAAA,SAChB,aAAA;IAAA,SACA,WAAA;IAAA,SACA,EAAA;IAAA,SACA,KAAA;EAAA,IACP,OAAA,CAAQ,yBAAA,CAA0B,yBAAA;AAAA"}
@@ -0,0 +1,145 @@
1
+ import { C as SetNotNullCall, D as installExtension, S as SetDefaultCall, _ as DropDefaultCall, b as DropTableCall, c as AlterColumnTypeCall, d as CreateSchemaCall, f as CreateTableCall, g as DropConstraintCall, h as DropColumnCall, m as DropCheckConstraintCall, n as AddColumnCall, o as AddPrimaryKeyCall, r as AddForeignKeyCall, s as AddUniqueCall, t as AddCheckConstraintCall, u as CreateIndexCall, v as DropIndexCall, y as DropNotNullCall } from "./op-factory-call-B1bXWtfa.mjs";
2
+ import { t as errorPostgresMigrationStackMissing } from "./errors-CUk87ByX.mjs";
3
+ import { t as dataTransform } from "./data-transform-BOWpliq8.mjs";
4
+ import { Migration } from "@prisma-next/family-sql/migration";
5
+ //#region src/core/migrations/postgres-migration.ts
6
+ /**
7
+ * Target-owned base class for Postgres migrations.
8
+ *
9
+ * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the
10
+ * abstract `targetId` to the Postgres target-id string literal, so both
11
+ * user-authored migrations and renderer-generated scaffolds (the output of
12
+ * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without
13
+ * redeclaring target-local identity.
14
+ *
15
+ * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer
16
+ * emits `extends Migration` against a facade re-export of this class
17
+ * from `@prisma-next/postgres/migration`, keeping the authoring surface
18
+ * target-scoped rather than family-scoped.
19
+ *
20
+ * The constructor materializes a single Postgres `SqlControlAdapter` from
21
+ * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`
22
+ * instance method forwards to the free `dataTransform` factory with that
23
+ * stored adapter, so user migrations can write `this.dataTransform(...)`
24
+ * without threading the adapter through every call.
25
+ *
26
+ * Every method requires an explicit `schema`. Postgres migrations name their
27
+ * schema deliberately — there is no default and no `search_path`-relative
28
+ * option. A migration that left the schema unspecified would resolve against
29
+ * whatever `search_path` the connection happened to carry, and that ambiguity
30
+ * is an antipattern in a migration. (The unbound/unspecified namespace concept
31
+ * remains for SQLite, which has no schemas, and for Mongo's connection `db`.)
32
+ */
33
+ var PostgresMigration = class extends Migration {
34
+ targetId = "postgres";
35
+ /**
36
+ * Materialized Postgres control adapter, created once per migration
37
+ * instance from the injected stack. `undefined` only when the migration
38
+ * was instantiated without a stack (test fixtures); `dataTransform`
39
+ * throws in that case to surface the misuse.
40
+ */
41
+ controlAdapter;
42
+ constructor(stack) {
43
+ super(stack);
44
+ this.controlAdapter = stack?.adapter ? stack.adapter.create(stack) : void 0;
45
+ }
46
+ /**
47
+ * Instance-method wrapper around the free `dataTransform` factory that
48
+ * supplies the stored control adapter. Authors call this from inside
49
+ * `get operations()`; the adapter argument is hidden from the call site.
50
+ */
51
+ dataTransform(contract, name, options) {
52
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
53
+ return dataTransform(contract, name, options, this.controlAdapter);
54
+ }
55
+ /**
56
+ * Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from
57
+ * the supplied options and lowers it through the stored control adapter.
58
+ * Throws if no adapter is present (i.e. migration instantiated without a stack).
59
+ */
60
+ createTable(options) {
61
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
62
+ return new CreateTableCall(options.schema, options.table, options.columns, options.constraints).toOp(this.controlAdapter);
63
+ }
64
+ /**
65
+ * Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from
66
+ * the supplied options and lowers it through the stored control adapter.
67
+ * Throws if no adapter is present (i.e. migration instantiated without a stack).
68
+ */
69
+ createSchema(options) {
70
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
71
+ return new CreateSchemaCall(options.schema).toOp(this.controlAdapter);
72
+ }
73
+ addColumn(options) {
74
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
75
+ return new AddColumnCall(options.schema, options.table, options.column).toOp(this.controlAdapter);
76
+ }
77
+ addPrimaryKey(options) {
78
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
79
+ return new AddPrimaryKeyCall(options.schema, options.table, options.constraint, options.columns).toOp(this.controlAdapter);
80
+ }
81
+ addUnique(options) {
82
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
83
+ return new AddUniqueCall(options.schema, options.table, options.constraint, options.columns).toOp(this.controlAdapter);
84
+ }
85
+ addForeignKey(options) {
86
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
87
+ return new AddForeignKeyCall(options.schema, options.table, options.foreignKey).toOp(this.controlAdapter);
88
+ }
89
+ addCheckConstraint(options) {
90
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
91
+ return new AddCheckConstraintCall(options.schema, options.table, options.constraint, options.column, options.values).toOp(this.controlAdapter);
92
+ }
93
+ dropCheckConstraint(options) {
94
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
95
+ return new DropCheckConstraintCall(options.schema, options.table, options.constraint).toOp(this.controlAdapter);
96
+ }
97
+ dropConstraint(options) {
98
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
99
+ return new DropConstraintCall(options.schema, options.table, options.constraint, options.kind ?? "unique").toOp(this.controlAdapter);
100
+ }
101
+ dropTable(options) {
102
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
103
+ return new DropTableCall(options.schema, options.table).toOp(this.controlAdapter);
104
+ }
105
+ dropColumn(options) {
106
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
107
+ return new DropColumnCall(options.schema, options.table, options.column).toOp(this.controlAdapter);
108
+ }
109
+ alterColumnType(options) {
110
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
111
+ return new AlterColumnTypeCall(options.schema, options.table, options.column, options.options).toOp(this.controlAdapter);
112
+ }
113
+ setNotNull(options) {
114
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
115
+ return new SetNotNullCall(options.schema, options.table, options.column).toOp(this.controlAdapter);
116
+ }
117
+ dropNotNull(options) {
118
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
119
+ return new DropNotNullCall(options.schema, options.table, options.column).toOp(this.controlAdapter);
120
+ }
121
+ setDefault(options) {
122
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
123
+ return new SetDefaultCall(options.schema, options.table, options.column, options.defaultSql, options.operationClass).toOp(this.controlAdapter);
124
+ }
125
+ dropDefault(options) {
126
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
127
+ return new DropDefaultCall(options.schema, options.table, options.column).toOp(this.controlAdapter);
128
+ }
129
+ createIndex(options) {
130
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
131
+ return new CreateIndexCall(options.schema, options.table, options.index, options.columns, options.extras).toOp(this.controlAdapter);
132
+ }
133
+ dropIndex(options) {
134
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
135
+ return new DropIndexCall(options.schema, options.table, options.index).toOp(this.controlAdapter);
136
+ }
137
+ installExtension(options) {
138
+ if (!this.controlAdapter) throw errorPostgresMigrationStackMissing();
139
+ return installExtension(options, this.controlAdapter);
140
+ }
141
+ };
142
+ //#endregion
143
+ export { PostgresMigration as t };
144
+
145
+ //# sourceMappingURL=postgres-migration-otiaw3Ru.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-migration-otiaw3Ru.mjs","names":["SqlMigration"],"sources":["../src/core/migrations/postgres-migration.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport type { SqlMigrationPlanOperation } from '@prisma-next/family-sql/control';\nimport type { SqlControlAdapter } from '@prisma-next/family-sql/control-adapter';\nimport { Migration as SqlMigration } from '@prisma-next/family-sql/migration';\nimport type { ControlStack } from '@prisma-next/framework-components/control';\nimport type { SqlStorage } from '@prisma-next/sql-contract/types';\nimport type { DdlColumn, DdlTableConstraint } from '@prisma-next/sql-relational-core/ast';\nimport { errorPostgresMigrationStackMissing } from '../errors';\nimport {\n AddCheckConstraintCall,\n AddColumnCall,\n AddForeignKeyCall,\n AddPrimaryKeyCall,\n AddUniqueCall,\n AlterColumnTypeCall,\n type AlterColumnTypeOptions,\n CreateIndexCall,\n CreateSchemaCall,\n CreateTableCall,\n DropCheckConstraintCall,\n DropColumnCall,\n DropConstraintCall,\n DropDefaultCall,\n DropIndexCall,\n DropNotNullCall,\n DropTableCall,\n SetDefaultCall,\n SetNotNullCall,\n} from './op-factory-call';\nimport { type DataTransformOptions, dataTransform } from './operations/data-transform';\nimport { installExtension } from './operations/dependencies';\nimport type { CreateIndexExtras } from './operations/indexes';\nimport type { ForeignKeySpec } from './operations/shared';\nimport type { PostgresPlanTargetDetails } from './planner-target-details';\n\n/**\n * Target-owned base class for Postgres migrations.\n *\n * Fixes the `SqlMigration` generic to `PostgresPlanTargetDetails` and the\n * abstract `targetId` to the Postgres target-id string literal, so both\n * user-authored migrations and renderer-generated scaffolds (the output of\n * `renderCallsToTypeScript`) can extend `PostgresMigration` directly without\n * redeclaring target-local identity.\n *\n * Mirrors `MongoMigration` in `@prisma-next/family-mongo`: the renderer\n * emits `extends Migration` against a facade re-export of this class\n * from `@prisma-next/postgres/migration`, keeping the authoring surface\n * target-scoped rather than family-scoped.\n *\n * The constructor materializes a single Postgres `SqlControlAdapter` from\n * `stack.adapter.create(stack)` and stores it; the protected `dataTransform`\n * instance method forwards to the free `dataTransform` factory with that\n * stored adapter, so user migrations can write `this.dataTransform(...)`\n * without threading the adapter through every call.\n *\n * Every method requires an explicit `schema`. Postgres migrations name their\n * schema deliberately — there is no default and no `search_path`-relative\n * option. A migration that left the schema unspecified would resolve against\n * whatever `search_path` the connection happened to carry, and that ambiguity\n * is an antipattern in a migration. (The unbound/unspecified namespace concept\n * remains for SQLite, which has no schemas, and for Mongo's connection `db`.)\n */\nexport abstract class PostgresMigration extends SqlMigration<\n PostgresPlanTargetDetails,\n 'postgres'\n> {\n readonly targetId = 'postgres' as const;\n\n /**\n * Materialized Postgres control adapter, created once per migration\n * instance from the injected stack. `undefined` only when the migration\n * was instantiated without a stack (test fixtures); `dataTransform`\n * throws in that case to surface the misuse.\n */\n protected readonly controlAdapter: SqlControlAdapter<'postgres'> | undefined;\n\n constructor(stack?: ControlStack<'sql', 'postgres'>) {\n super(stack);\n // The descriptor `create()` is typed as the wider `ControlAdapterInstance`;\n // the Postgres descriptor concretely returns a `SqlControlAdapter<'postgres'>`,\n // so the cast holds for any Postgres-target stack assembled at runtime.\n this.controlAdapter = stack?.adapter\n ? (stack.adapter.create(stack) as SqlControlAdapter<'postgres'>)\n : undefined;\n }\n\n /**\n * Instance-method wrapper around the free `dataTransform` factory that\n * supplies the stored control adapter. Authors call this from inside\n * `get operations()`; the adapter argument is hidden from the call site.\n */\n protected dataTransform<TContract extends Contract<SqlStorage>>(\n contract: TContract,\n name: string,\n options: DataTransformOptions,\n ): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return dataTransform(contract, name, options, this.controlAdapter);\n }\n\n /**\n * Emit a `CREATE TABLE` migration operation. Builds a typed DDL node from\n * the supplied options and lowers it through the stored control adapter.\n * Throws if no adapter is present (i.e. migration instantiated without a stack).\n */\n protected createTable(options: {\n readonly schema: string;\n readonly table: string;\n readonly ifNotExists?: boolean;\n readonly columns: readonly DdlColumn[];\n readonly constraints?: readonly DdlTableConstraint[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateTableCall(\n options.schema,\n options.table,\n options.columns,\n options.constraints,\n ).toOp(this.controlAdapter);\n }\n\n /**\n * Emit a `CREATE SCHEMA` migration operation. Builds a typed DDL node from\n * the supplied options and lowers it through the stored control adapter.\n * Throws if no adapter is present (i.e. migration instantiated without a stack).\n */\n protected createSchema(options: {\n readonly schema: string;\n readonly ifNotExists?: boolean;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateSchemaCall(options.schema).toOp(this.controlAdapter);\n }\n\n protected addColumn(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: DdlColumn;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddColumnCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected addPrimaryKey(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly columns: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddPrimaryKeyCall(\n options.schema,\n options.table,\n options.constraint,\n options.columns,\n ).toOp(this.controlAdapter);\n }\n\n protected addUnique(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly columns: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddUniqueCall(\n options.schema,\n options.table,\n options.constraint,\n options.columns,\n ).toOp(this.controlAdapter);\n }\n\n protected addForeignKey(options: {\n readonly schema: string;\n readonly table: string;\n readonly foreignKey: ForeignKeySpec;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddForeignKeyCall(options.schema, options.table, options.foreignKey).toOp(\n this.controlAdapter,\n );\n }\n\n protected addCheckConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly column: string;\n readonly values: readonly string[];\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AddCheckConstraintCall(\n options.schema,\n options.table,\n options.constraint,\n options.column,\n options.values,\n ).toOp(this.controlAdapter);\n }\n\n protected dropCheckConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropCheckConstraintCall(options.schema, options.table, options.constraint).toOp(\n this.controlAdapter,\n );\n }\n\n protected dropConstraint(options: {\n readonly schema: string;\n readonly table: string;\n readonly constraint: string;\n readonly kind?: 'foreignKey' | 'unique' | 'primaryKey';\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropConstraintCall(\n options.schema,\n options.table,\n options.constraint,\n options.kind ?? 'unique',\n ).toOp(this.controlAdapter);\n }\n\n protected dropTable(options: {\n readonly schema: string;\n readonly table: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropTableCall(options.schema, options.table).toOp(this.controlAdapter);\n }\n\n protected dropColumn(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropColumnCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected alterColumnType(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n readonly options: AlterColumnTypeOptions;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new AlterColumnTypeCall(\n options.schema,\n options.table,\n options.column,\n options.options,\n ).toOp(this.controlAdapter);\n }\n\n protected setNotNull(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new SetNotNullCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected dropNotNull(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropNotNullCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected setDefault(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n readonly defaultSql: string;\n readonly operationClass?: 'additive' | 'widening';\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new SetDefaultCall(\n options.schema,\n options.table,\n options.column,\n options.defaultSql,\n options.operationClass,\n ).toOp(this.controlAdapter);\n }\n\n protected dropDefault(options: {\n readonly schema: string;\n readonly table: string;\n readonly column: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropDefaultCall(options.schema, options.table, options.column).toOp(\n this.controlAdapter,\n );\n }\n\n protected createIndex(options: {\n readonly schema: string;\n readonly table: string;\n readonly index: string;\n readonly columns: readonly string[];\n readonly extras?: CreateIndexExtras;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new CreateIndexCall(\n options.schema,\n options.table,\n options.index,\n options.columns,\n options.extras,\n ).toOp(this.controlAdapter);\n }\n\n protected dropIndex(options: {\n readonly schema: string;\n readonly table: string;\n readonly index: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return new DropIndexCall(options.schema, options.table, options.index).toOp(\n this.controlAdapter,\n );\n }\n\n protected installExtension(options: {\n readonly extensionName: string;\n readonly invariantId: string;\n readonly id: string;\n readonly label?: string;\n }): Promise<SqlMigrationPlanOperation<PostgresPlanTargetDetails>> {\n if (!this.controlAdapter) {\n throw errorPostgresMigrationStackMissing();\n }\n return installExtension(options, this.controlAdapter);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,IAAsB,oBAAtB,cAAgDA,UAG9C;CACA,WAAoB;;;;;;;CAQpB;CAEA,YAAY,OAAyC;EACnD,MAAM,KAAK;EAIX,KAAK,iBAAiB,OAAO,UACxB,MAAM,QAAQ,OAAO,KAAK,IAC3B,KAAA;CACN;;;;;;CAOA,cACE,UACA,MACA,SAC+D;EAC/D,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,cAAc,UAAU,MAAM,SAAS,KAAK,cAAc;CACnE;;;;;;CAOA,YAAsB,SAM4C;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,gBACT,QAAQ,QACR,QAAQ,OACR,QAAQ,SACR,QAAQ,WACV,CAAC,CAAC,KAAK,KAAK,cAAc;CAC5B;;;;;;CAOA,aAAuB,SAG2C;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,iBAAiB,QAAQ,MAAM,CAAC,CAAC,KAAK,KAAK,cAAc;CACtE;CAEA,UAAoB,SAI8C;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,cAAc,QAAQ,QAAQ,QAAQ,OAAO,QAAQ,MAAM,CAAC,CAAC,KACtE,KAAK,cAC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AAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,IAAI,cAAc,QAAQ,QAAQ,QAAQ,OAAO,QAAQ,KAAK,CAAC,CAAC,KACrE,KAAK,cACP;CACF;CAEA,iBAA2B,SAKuC;EAChE,IAAI,CAAC,KAAK,gBACR,MAAM,mCAAmC;EAE3C,OAAO,iBAAiB,SAAS,KAAK,cAAc;CACtD;AACF"}
@@ -1,7 +1,24 @@
1
+ import { _ as PG_TEXT_CODEC_ID } from "./codec-ids-BvytN2P8.mjs";
1
2
  import { n as escapeLiteral } from "./sql-utils-DcfMz4MQ.mjs";
3
+ import { TableSource } from "@prisma-next/sql-relational-core/ast";
2
4
  import { blindCast } from "@prisma-next/utils/casts";
5
+ import { ifDefined } from "@prisma-next/utils/defined";
3
6
  import { NamespaceBase, UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from "@prisma-next/framework-components/ir";
4
7
  import { composeSqlEntityKinds } from "@prisma-next/sql-contract/entity-kinds";
8
+ import { cfExpr } from "@prisma-next/sql-relational-core/contract-free";
9
+ //#region src/core/ast/table-source.ts
10
+ var PostgresTableSource = class extends TableSource {
11
+ schema;
12
+ constructor(options) {
13
+ super(options.name, options.alias);
14
+ this.schema = options.schema;
15
+ this.freeze();
16
+ }
17
+ rewrite(rewriter) {
18
+ return rewriter.tableSource ? rewriter.tableSource(this) : this;
19
+ }
20
+ };
21
+ //#endregion
5
22
  //#region src/core/postgres-schema.ts
6
23
  /**
7
24
  * Postgres target `Namespace` concretion — a Postgres schema (`CREATE
@@ -90,15 +107,39 @@ var PostgresSchema = class extends NamespaceBase {
90
107
  return `'${escapeLiteral(this.id)}'`;
91
108
  }
92
109
  /**
110
+ * Typed-AST counterpart of {@link schemaSqlExpression}: the expression a
111
+ * builder-built catalog check compares `n.nspname` / `table_schema`
112
+ * against. Named schemas bind the schema name as a text parameter; the
113
+ * unbound singleton overrides this to the opaque `current_schema()`
114
+ * expression so the live connection's `search_path` decides at runtime.
115
+ */
116
+ schemaFilterExpression() {
117
+ return cfExpr.param(this.id, PG_TEXT_CODEC_ID);
118
+ }
119
+ /**
120
+ * Typed-AST counterpart of {@link qualifyTable}: the FROM source a
121
+ * builder-built check uses to address a user table in this namespace.
122
+ * Named schemas qualify (`"schema"."table"`); the unbound singleton
123
+ * overrides this to leave the table unqualified so `search_path`
124
+ * resolves it at runtime.
125
+ */
126
+ tableSource(tableName, alias) {
127
+ return new PostgresTableSource({
128
+ name: tableName,
129
+ schema: this.id,
130
+ ...ifDefined("alias", alias)
131
+ });
132
+ }
133
+ /**
93
134
  * The bare schema name a DDL planner should target when emitting
94
135
  * statements that need to identify this namespace in the live
95
136
  * database (e.g. `CREATE TABLE "<ddlSchemaName>"."<table>" …`,
96
137
  * catalog filters, planner conflict lookups). Named schemas resolve
97
138
  * to their own id. The `PostgresUnboundSchema` singleton inherits
98
139
  * this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch
99
- * through `qualifyTableName` / `toRegclassLiteral` route through the
100
- * polymorphic `PostgresUnboundSchema` overrides and produce
101
- * unqualified (search-path-resolved) output automatically.
140
+ * through `qualifyTableName` route through the polymorphic
141
+ * `PostgresUnboundSchema` overrides and produce unqualified
142
+ * (search-path-resolved) output automatically.
102
143
  */
103
144
  ddlSchemaName(_storage) {
104
145
  return this.id;
@@ -119,9 +160,9 @@ var PostgresSchema = class extends NamespaceBase {
119
160
  * `search_path`).
120
161
  *
121
162
  * `ddlSchemaName` is inherited from `PostgresSchema` and returns
122
- * `UNBOUND_NAMESPACE_ID`. Downstream helpers (`qualifyTableName`,
123
- * `toRegclassLiteral`) route through the polymorphic factory and
124
- * produce unqualified output automatically.
163
+ * `UNBOUND_NAMESPACE_ID`. Downstream helpers such as `qualifyTableName`
164
+ * route through the polymorphic factory and produce unqualified output
165
+ * automatically.
125
166
  */
126
167
  var PostgresUnboundSchema = class PostgresUnboundSchema extends PostgresSchema {
127
168
  static instance = new PostgresUnboundSchema();
@@ -140,6 +181,18 @@ var PostgresUnboundSchema = class PostgresUnboundSchema extends PostgresSchema {
140
181
  schemaSqlExpression() {
141
182
  return "current_schema()";
142
183
  }
184
+ schemaFilterExpression() {
185
+ return cfExpr.raw("current_schema()", {
186
+ codecId: PG_TEXT_CODEC_ID,
187
+ nullable: false
188
+ });
189
+ }
190
+ tableSource(tableName, alias) {
191
+ return new PostgresTableSource({
192
+ name: tableName,
193
+ ...ifDefined("alias", alias)
194
+ });
195
+ }
143
196
  };
144
197
  PostgresSchema.unbound = PostgresUnboundSchema.instance;
145
198
  /**
@@ -177,6 +230,6 @@ function postgresCreateNamespace(input) {
177
230
  return new PostgresSchema(schemaInput);
178
231
  }
179
232
  //#endregion
180
- export { postgresCreateNamespace as i, PostgresUnboundSchema as n, isPostgresSchema as r, PostgresSchema as t };
233
+ export { PostgresTableSource as a, postgresCreateNamespace as i, PostgresUnboundSchema as n, isPostgresSchema as r, PostgresSchema as t };
181
234
 
182
- //# sourceMappingURL=postgres-schema-CDaLWZwd.mjs.map
235
+ //# sourceMappingURL=postgres-schema-COGZ1ark.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-schema-COGZ1ark.mjs","names":[],"sources":["../src/core/ast/table-source.ts","../src/core/postgres-schema.ts"],"sourcesContent":["import {\n type AnyFromSource,\n type AstRewriter,\n TableSource,\n} from '@prisma-next/sql-relational-core/ast';\n\nexport class PostgresTableSource extends TableSource {\n readonly schema: string | undefined;\n\n constructor(options: {\n readonly name: string;\n readonly schema?: string;\n readonly alias?: string;\n }) {\n super(options.name, options.alias);\n this.schema = options.schema;\n this.freeze();\n }\n\n override rewrite(rewriter: AstRewriter): AnyFromSource {\n return rewriter.tableSource ? rewriter.tableSource(this) : this;\n }\n}\n","import {\n freezeNode,\n hydrateNamespaceEntities,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { composeSqlEntityKinds } from '@prisma-next/sql-contract/entity-kinds';\nimport type {\n SqlNamespaceEntries,\n SqlNamespaceTablesInput,\n SqlStorage,\n StorageTable,\n StorageValueSet,\n} from '@prisma-next/sql-contract/types';\nimport { type CfExpr, cfExpr } from '@prisma-next/sql-relational-core/contract-free';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { PostgresTableSource } from './ast/table-source';\nimport { PG_TEXT_CODEC_ID } from './codec-ids';\nimport { escapeLiteral } from './sql-utils';\n\nexport interface PostgresSchemaInput {\n readonly id: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n}\n\n/**\n * Postgres target `Namespace` concretion — a Postgres schema (`CREATE\n * SCHEMA …`). Each Postgres `SqlStorage` carries a\n * `namespaces: Record<NamespaceId, PostgresSchema>` map populated by\n * the Postgres PSL interpreter from `namespace { … }` AST buckets.\n *\n * `entries` holds entity-kind maps (`table`, `valueSet`). Qualifier\n * emission is the rendering seam: DDL / SQL emission asks the namespace\n * for its qualifier (`\"<schema>\"`) or for a qualified table name\n * (`\"<schema>\".\"<table>\"`) and consumes the result polymorphically.\n * The unbound singleton below overrides these methods to elide the\n * prefix entirely — call sites stay polymorphic and never branch on\n * `id === UNBOUND_NAMESPACE_ID`.\n */\nexport class PostgresSchema extends NamespaceBase {\n /**\n * Stable singleton reference for the late-bound slot. Materialised\n * lazily below the singleton subclass declaration so the static\n * initialiser sees the subclass before assigning. Consumers always\n * reach for `PostgresSchema.unbound` (or `PostgresUnboundSchema.instance`\n * — same identity).\n */\n static unbound: PostgresUnboundSchema;\n\n declare readonly kind: 'schema';\n readonly id: string;\n readonly entries: SqlNamespaceEntries;\n\n constructor(input: PostgresSchemaInput) {\n super();\n this.id = input.id;\n\n const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), 'carry');\n\n // Drop an empty valueSet so presence signals non-emptiness.\n const valueSetRaw = dispatched['valueSet'];\n const withPresence =\n valueSetRaw !== undefined && Object.keys(valueSetRaw).length === 0\n ? { ...dispatched, valueSet: undefined }\n : dispatched;\n\n this.entries = Object.freeze(\n blindCast<\n SqlNamespaceEntries,\n 'composeSqlEntityKinds() supplies table→StorageTable and valueSet→StorageValueSet descriptors, so this open-dict result holds exactly the typed members SqlNamespaceEntries declares; the descriptor Map erases those per-kind Node types from the return.'\n >(withPresence),\n );\n Object.defineProperty(this, 'kind', {\n value: 'schema',\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n get table(): Readonly<Record<string, StorageTable>> {\n return this.entries.table ?? Object.freeze({});\n }\n\n get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined {\n return this.entries.valueSet;\n }\n\n /**\n * The bare schema qualifier as it would appear in a rendered SQL\n * fragment (already quoted). The unbound-schema singleton overrides\n * this to return `''`.\n */\n qualifier(): string {\n return `\"${this.id}\"`;\n }\n\n /**\n * Qualify a table name with the schema prefix\n * (`\"<schema>\".\"<table>\"`). The unbound-schema singleton overrides\n * this to emit just `\"<table>\"` so the resolved DDL is unqualified\n * and `search_path` decides where the object lands at runtime.\n */\n qualifyTable(tableName: string): string {\n return `\"${this.id}\".\"${tableName}\"`;\n }\n\n /**\n * Render a SQL string-literal containing the qualified-name form\n * suitable for `to_regclass(...)` arguments (e.g. `'\"public\".\"user\"'`).\n * The unbound singleton overrides this to elide the schema prefix\n * (`'\"user\"'`) so `search_path` resolves the object at runtime.\n */\n regclassLiteral(name: string): string {\n return `'${escapeLiteral(this.qualifyTable(name))}'`;\n }\n\n /**\n * Render a SQL expression that evaluates to this namespace's schema\n * name at runtime, ready to drop into a `WHERE table_schema = …` /\n * `WHERE n.nspname = …` clause. Named schemas emit a quoted SQL\n * literal (`'public'`); the unbound singleton overrides this to emit\n * `current_schema()` so catalog queries match whichever schema the\n * connection's `search_path` resolved at runtime.\n */\n schemaSqlExpression(): string {\n return `'${escapeLiteral(this.id)}'`;\n }\n\n /**\n * Typed-AST counterpart of {@link schemaSqlExpression}: the expression a\n * builder-built catalog check compares `n.nspname` / `table_schema`\n * against. Named schemas bind the schema name as a text parameter; the\n * unbound singleton overrides this to the opaque `current_schema()`\n * expression so the live connection's `search_path` decides at runtime.\n */\n schemaFilterExpression(): CfExpr {\n return cfExpr.param(this.id, PG_TEXT_CODEC_ID);\n }\n\n /**\n * Typed-AST counterpart of {@link qualifyTable}: the FROM source a\n * builder-built check uses to address a user table in this namespace.\n * Named schemas qualify (`\"schema\".\"table\"`); the unbound singleton\n * overrides this to leave the table unqualified so `search_path`\n * resolves it at runtime.\n */\n tableSource(tableName: string, alias?: string): PostgresTableSource {\n return new PostgresTableSource({\n name: tableName,\n schema: this.id,\n ...ifDefined('alias', alias),\n });\n }\n\n /**\n * The bare schema name a DDL planner should target when emitting\n * statements that need to identify this namespace in the live\n * database (e.g. `CREATE TABLE \"<ddlSchemaName>\".\"<table>\" …`,\n * catalog filters, planner conflict lookups). Named schemas resolve\n * to their own id. The `PostgresUnboundSchema` singleton inherits\n * this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch\n * through `qualifyTableName` route through the polymorphic\n * `PostgresUnboundSchema` overrides and produce unqualified\n * (search-path-resolved) output automatically.\n */\n ddlSchemaName(_storage: SqlStorage): string {\n return this.id;\n }\n}\n\n/**\n * Singleton subclass for the reserved sentinel namespace id\n * (`UNBOUND_NAMESPACE_ID`) — the late-bound Postgres slot whose binding\n * the connection's `search_path` resolves at runtime. Overrides\n * qualifier emission to elide the schema prefix; call sites that consume\n * `qualifier()` / `qualifyTable()` get unqualified output without\n * branching on the namespace id.\n *\n * This is the target-side materialization of \"the framework provides\n * affordances; targets implement specifics\": the framework names the\n * sentinel; Postgres decides what late-bound means here (the table\n * name, naked — the schema is supplied by the live connection's\n * `search_path`).\n *\n * `ddlSchemaName` is inherited from `PostgresSchema` and returns\n * `UNBOUND_NAMESPACE_ID`. Downstream helpers such as `qualifyTableName`\n * route through the polymorphic factory and produce unqualified output\n * automatically.\n */\nexport class PostgresUnboundSchema extends PostgresSchema {\n static readonly instance: PostgresUnboundSchema = new PostgresUnboundSchema();\n\n constructor(input?: PostgresSchemaInput) {\n super(input ?? { id: UNBOUND_NAMESPACE_ID, entries: { table: {} } });\n }\n\n override qualifier(): string {\n return '';\n }\n\n override qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n\n override schemaSqlExpression(): string {\n return 'current_schema()';\n }\n\n override schemaFilterExpression(): CfExpr {\n return cfExpr.raw('current_schema()', { codecId: PG_TEXT_CODEC_ID, nullable: false });\n }\n\n override tableSource(tableName: string, alias?: string): PostgresTableSource {\n return new PostgresTableSource({\n name: tableName,\n ...ifDefined('alias', alias),\n });\n }\n}\n\nPostgresSchema.unbound = PostgresUnboundSchema.instance;\n\n/**\n * Narrow an arbitrary namespace (or `undefined`) to `PostgresSchema`\n * so callers can dispatch to the polymorphic emission methods without\n * branching at the call site. Uses the structural `kind` discriminator\n * (`'schema'`) rather than `instanceof` so the check survives realm /\n * bundle / hot-reload boundaries — matching the rest of the IR's\n * narrowing convention. `PostgresUnboundSchema` passes through because\n * it inherits the same `kind: 'schema'` from `PostgresSchema`.\n */\nexport function isPostgresSchema(ns: unknown): ns is PostgresSchema {\n return (ns as { kind?: unknown } | null | undefined)?.kind === 'schema';\n}\n\n/**\n * Target-supplied `Namespace` factory the Postgres target plumbs\n * through `defineContract({ createNamespace })` and the SQL PSL\n * interpreter. Returns the unbound singleton for the framework\n * sentinel and a fresh `PostgresSchema` for any other coordinate.\n *\n * The factory has no per-call state — every named id deterministically\n * maps to a distinct schema instance — so callers can pass it through\n * by reference and trust the resulting `SqlStorage.namespaces` map to\n * be value-stable for a given input set.\n */\nexport function postgresCreateNamespace(input: SqlNamespaceTablesInput): PostgresSchema {\n const schemaInput: PostgresSchemaInput = {\n id: input.id,\n entries: {\n ...input.entries,\n table: input.entries['table'] ?? {},\n },\n };\n if (input.id === UNBOUND_NAMESPACE_ID) {\n return new PostgresUnboundSchema(schemaInput);\n }\n return new PostgresSchema(schemaInput);\n}\n"],"mappings":";;;;;;;;;AAMA,IAAa,sBAAb,cAAyC,YAA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C;EAClE,OAAO,IAAI,oBAAoB;GAC7B,MAAM;GACN,QAAQ,KAAK;GACb,GAAG,UAAU,SAAS,KAAK;EAC7B,CAAC;CACH;;;;;;;;;;;;CAaA,cAAc,UAA8B;EAC1C,OAAO,KAAK;CACd;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,wBAAb,MAAa,8BAA8B,eAAe;CACxD,OAAgB,WAAkC,IAAI,sBAAsB;CAE5E,YAAY,OAA6B;EACvC,MAAM,SAAS;GAAE,IAAI;GAAsB,SAAS,EAAE,OAAO,CAAC,EAAE;EAAE,CAAC;CACrE;CAEA,YAA6B;EAC3B,OAAO;CACT;CAEA,aAAsB,WAA2B;EAC/C,OAAO,IAAI,UAAU;CACvB;CAEA,sBAAuC;EACrC,OAAO;CACT;CAEA,yBAA0C;EACxC,OAAO,OAAO,IAAI,oBAAoB;GAAE,SAAS;GAAkB,UAAU;EAAM,CAAC;CACtF;CAEA,YAAqB,WAAmB,OAAqC;EAC3E,OAAO,IAAI,oBAAoB;GAC7B,MAAM;GACN,GAAG,UAAU,SAAS,KAAK;EAC7B,CAAC;CACH;AACF;AAEA,eAAe,UAAU,sBAAsB;;;;;;;;;;AAW/C,SAAgB,iBAAiB,IAAmC;CAClE,OAAQ,IAA8C,SAAS;AACjE;;;;;;;;;;;;AAaA,SAAgB,wBAAwB,OAAgD;CACtF,MAAM,cAAmC;EACvC,IAAI,MAAM;EACV,SAAS;GACP,GAAG,MAAM;GACT,OAAO,MAAM,QAAQ,YAAY,CAAC;EACpC;CACF;CACA,IAAI,MAAM,OAAO,sBACf,OAAO,IAAI,sBAAsB,WAAW;CAE9C,OAAO,IAAI,eAAe,WAAW;AACvC"}
package/dist/runtime.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as postgresTargetDescriptorMetaRuntime } from "./descriptor-meta-runtime-e5f2tscJ.mjs";
2
- import { t as PostgresContractSerializer } from "./postgres-contract-serializer-sdg1B6Og.mjs";
2
+ import { t as PostgresContractSerializer } from "./postgres-contract-serializer-E92REOFk.mjs";
3
3
  //#region src/exports/runtime.ts
4
4
  /**
5
5
  * Target-postgres deliberately does NOT import `SqlRuntimeTargetDescriptor` from `@prisma-next/sql-runtime`. The target package is a control-plane residence and must not pull the SQL execution-plane package into its dependency closure. The runtime descriptor here is shaped to satisfy the framework's `RuntimeTargetDescriptor` plus the structural `SqlStaticContributions` (`codecs:` returning a descriptor list) that
@@ -0,0 +1,15 @@
1
+ import { AnyFromSource, AstRewriter, TableSource } from "@prisma-next/sql-relational-core/ast";
2
+
3
+ //#region src/core/ast/table-source.d.ts
4
+ declare class PostgresTableSource extends TableSource {
5
+ readonly schema: string | undefined;
6
+ constructor(options: {
7
+ readonly name: string;
8
+ readonly schema?: string;
9
+ readonly alias?: string;
10
+ });
11
+ rewrite(rewriter: AstRewriter): AnyFromSource;
12
+ }
13
+ //#endregion
14
+ export { PostgresTableSource as t };
15
+ //# sourceMappingURL=table-source-BvFo7gVs.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-source-BvFo7gVs.d.mts","names":[],"sources":["../src/core/ast/table-source.ts"],"mappings":";;;cAMa,mBAAA,SAA4B,WAAA;EAAA,SAC9B,MAAA;cAEG,OAAA;IAAA,SACD,IAAA;IAAA,SACA,MAAA;IAAA,SACA,KAAA;EAAA;EAOF,OAAA,CAAQ,QAAA,EAAU,WAAA,GAAc,aAAA;AAAA"}
package/dist/types.d.mts CHANGED
@@ -1,5 +1,7 @@
1
+ import { t as PostgresTableSource } from "./table-source-BvFo7gVs.mjs";
1
2
  import { t as PostgresColumnDefault } from "./types-BDKkx8MA.mjs";
2
3
  import { NamespaceBase } from "@prisma-next/framework-components/ir";
4
+ import { CfExpr } from "@prisma-next/sql-relational-core/contract-free";
3
5
  import { SqlNamespaceEntries, SqlNamespaceTablesInput, SqlStorage, StorageTable, StorageValueSet } from "@prisma-next/sql-contract/types";
4
6
 
5
7
  //#region src/core/postgres-schema.d.ts
@@ -65,6 +67,22 @@ declare class PostgresSchema extends NamespaceBase {
65
67
  * connection's `search_path` resolved at runtime.
66
68
  */
67
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;
68
86
  /**
69
87
  * The bare schema name a DDL planner should target when emitting
70
88
  * statements that need to identify this namespace in the live
@@ -72,9 +90,9 @@ declare class PostgresSchema extends NamespaceBase {
72
90
  * catalog filters, planner conflict lookups). Named schemas resolve
73
91
  * to their own id. The `PostgresUnboundSchema` singleton inherits
74
92
  * this and returns `UNBOUND_NAMESPACE_ID` — callers that dispatch
75
- * through `qualifyTableName` / `toRegclassLiteral` route through the
76
- * polymorphic `PostgresUnboundSchema` overrides and produce
77
- * unqualified (search-path-resolved) output automatically.
93
+ * through `qualifyTableName` route through the polymorphic
94
+ * `PostgresUnboundSchema` overrides and produce unqualified
95
+ * (search-path-resolved) output automatically.
78
96
  */
79
97
  ddlSchemaName(_storage: SqlStorage): string;
80
98
  }
@@ -93,9 +111,9 @@ declare class PostgresSchema extends NamespaceBase {
93
111
  * `search_path`).
94
112
  *
95
113
  * `ddlSchemaName` is inherited from `PostgresSchema` and returns
96
- * `UNBOUND_NAMESPACE_ID`. Downstream helpers (`qualifyTableName`,
97
- * `toRegclassLiteral`) route through the polymorphic factory and
98
- * produce unqualified output automatically.
114
+ * `UNBOUND_NAMESPACE_ID`. Downstream helpers such as `qualifyTableName`
115
+ * route through the polymorphic factory and produce unqualified output
116
+ * automatically.
99
117
  */
100
118
  declare class PostgresUnboundSchema extends PostgresSchema {
101
119
  static readonly instance: PostgresUnboundSchema;
@@ -103,6 +121,8 @@ declare class PostgresUnboundSchema extends PostgresSchema {
103
121
  qualifier(): string;
104
122
  qualifyTable(tableName: string): string;
105
123
  schemaSqlExpression(): string;
124
+ schemaFilterExpression(): CfExpr;
125
+ tableSource(tableName: string, alias?: string): PostgresTableSource;
106
126
  }
107
127
  /**
108
128
  * Target-supplied `Namespace` factory the Postgres target plumbs
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../src/core/postgres-schema.ts"],"mappings":";;;;;UAiBiB,mBAAA;EAAA,SACN,EAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,QAAA,CAAS,MAAA;AAAA;;;;;;;;;;;;;;;cAiBxC,cAAA,SAAuB,aAAA;EAjBuB;AAiB3D;;;;;;EAjB2D,OAyBlD,OAAA,EAAS,qBAAA;EAAA,SAEC,IAAA;EAAA,SACR,EAAA;EAAA,SACA,OAAA,EAAS,mBAAA;cAEN,KAAA,EAAO,mBAAA;EAAA,IA4Bf,KAAA,IAAS,QAAA,CAAS,MAAA,SAAe,YAAA;EAAA,IAIjC,QAAA,IAAY,QAAA,CAAS,MAAA,SAAe,eAAA;EA9CN;;;;;EAuDlC,SAAA;EA7CiB;;;;;;EAuDjB,YAAA,CAAa,SAAA;EAvBT;;;;;;EAiCJ,eAAA,CAAgB,IAAA;EA7BwB;;;;;;;;EAyCxC,mBAAA;EAec;;AAAoB;AAwBpC;;;;;;;;EAxBE,aAAA,CAAc,QAAA,EAAU,UAAA;AAAA;;;;;;;;;;AAuCI;AA+B9B;;;;;;;;AAAuF;cA9C1E,qBAAA,SAA8B,cAAA;EAAA,gBACzB,QAAA,EAAU,qBAAA;cAEd,KAAA,GAAQ,mBAAA;EAIX,SAAA;EAIA,YAAA,CAAa,SAAA;EA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/types.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { i as postgresCreateNamespace, n as PostgresUnboundSchema, t as PostgresSchema } from "./postgres-schema-CDaLWZwd.mjs";
1
+ import { i as postgresCreateNamespace, n as PostgresUnboundSchema, t as PostgresSchema } from "./postgres-schema-COGZ1ark.mjs";
2
2
  export { PostgresSchema, PostgresUnboundSchema, postgresCreateNamespace };