@prisma-next/adapter-postgres 0.3.0-dev.7 → 0.3.0-dev.70
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.
- package/LICENSE +201 -0
- package/README.md +64 -2
- package/dist/adapter-DtehReRR.mjs +271 -0
- package/dist/adapter-DtehReRR.mjs.map +1 -0
- package/dist/adapter.d.mts +23 -0
- package/dist/adapter.d.mts.map +1 -0
- package/dist/adapter.mjs +3 -0
- package/dist/codec-ids-Bsm9c7ns.mjs +29 -0
- package/dist/codec-ids-Bsm9c7ns.mjs.map +1 -0
- package/dist/codec-types.d.mts +141 -0
- package/dist/codec-types.d.mts.map +1 -0
- package/dist/codec-types.mjs +3 -0
- package/dist/codecs-BfC_5c-4.mjs +207 -0
- package/dist/codecs-BfC_5c-4.mjs.map +1 -0
- package/dist/column-types.d.mts +110 -0
- package/dist/column-types.d.mts.map +1 -0
- package/dist/column-types.mjs +180 -0
- package/dist/column-types.mjs.map +1 -0
- package/dist/control.d.mts +111 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +462 -0
- package/dist/control.mjs.map +1 -0
- package/dist/descriptor-meta-ilnFI7bx.mjs +921 -0
- package/dist/descriptor-meta-ilnFI7bx.mjs.map +1 -0
- package/dist/runtime.d.mts +19 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +85 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/sql-utils-CSfAGEwF.mjs +78 -0
- package/dist/sql-utils-CSfAGEwF.mjs.map +1 -0
- package/dist/types-CXO7EB60.d.mts +19 -0
- package/dist/types-CXO7EB60.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +37 -46
- package/src/core/adapter.ts +139 -28
- package/src/core/codec-ids.ts +28 -0
- package/src/core/codecs.ts +325 -23
- package/src/core/control-adapter.ts +400 -178
- package/src/core/default-normalizer.ts +90 -0
- package/src/core/descriptor-meta.ts +221 -9
- package/src/core/enum-control-hooks.ts +735 -0
- package/src/core/json-schema-type-expression.ts +131 -0
- package/src/core/json-schema-validator.ts +53 -0
- package/src/core/parameterized-types.ts +118 -0
- package/src/core/sql-utils.ts +111 -0
- package/src/core/standard-schema.ts +71 -0
- package/src/exports/codec-types.ts +73 -1
- package/src/exports/column-types.ts +233 -9
- package/src/exports/control.ts +16 -9
- package/src/exports/runtime.ts +61 -18
- package/dist/chunk-HD5YISNQ.js +0 -47
- package/dist/chunk-HD5YISNQ.js.map +0 -1
- package/dist/chunk-J3XSOAM2.js +0 -162
- package/dist/chunk-J3XSOAM2.js.map +0 -1
- package/dist/chunk-T6S3A6VT.js +0 -301
- package/dist/chunk-T6S3A6VT.js.map +0 -1
- package/dist/core/adapter.d.ts +0 -19
- package/dist/core/adapter.d.ts.map +0 -1
- package/dist/core/codecs.d.ts +0 -110
- package/dist/core/codecs.d.ts.map +0 -1
- package/dist/core/control-adapter.d.ts +0 -33
- package/dist/core/control-adapter.d.ts.map +0 -1
- package/dist/core/descriptor-meta.d.ts +0 -72
- package/dist/core/descriptor-meta.d.ts.map +0 -1
- package/dist/core/types.d.ts +0 -16
- package/dist/core/types.d.ts.map +0 -1
- package/dist/exports/adapter.d.ts +0 -2
- package/dist/exports/adapter.d.ts.map +0 -1
- package/dist/exports/adapter.js +0 -8
- package/dist/exports/adapter.js.map +0 -1
- package/dist/exports/codec-types.d.ts +0 -11
- package/dist/exports/codec-types.d.ts.map +0 -1
- package/dist/exports/codec-types.js +0 -7
- package/dist/exports/codec-types.js.map +0 -1
- package/dist/exports/column-types.d.ts +0 -17
- package/dist/exports/column-types.d.ts.map +0 -1
- package/dist/exports/column-types.js +0 -49
- package/dist/exports/column-types.js.map +0 -1
- package/dist/exports/control.d.ts +0 -8
- package/dist/exports/control.d.ts.map +0 -1
- package/dist/exports/control.js +0 -279
- package/dist/exports/control.js.map +0 -1
- package/dist/exports/runtime.d.ts +0 -15
- package/dist/exports/runtime.d.ts.map +0 -1
- package/dist/exports/runtime.js +0 -20
- package/dist/exports/runtime.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -1
- package/dist/exports/types.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [Prisma Data, Inc]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ Provide PostgreSQL-specific adapter implementation, codecs, and capabilities. En
|
|
|
27
27
|
- **Codec Definitions**: Define PostgreSQL codecs for type conversion
|
|
28
28
|
- Wire format to JavaScript type decoding
|
|
29
29
|
- JavaScript type to wire format encoding
|
|
30
|
+
- **Storage Type Control Hooks**: Provide control-plane hooks for contract-defined storage types (e.g., enums)
|
|
30
31
|
- **Codec Types**: Export TypeScript types for PostgreSQL codecs
|
|
31
32
|
- **Descriptors**: Provide adapter descriptors declaring capabilities and codec type imports
|
|
32
33
|
|
|
@@ -97,7 +98,11 @@ flowchart TD
|
|
|
97
98
|
**Codecs (`codecs.ts`)**
|
|
98
99
|
- PostgreSQL codec definitions
|
|
99
100
|
- Type conversion between wire format and JavaScript
|
|
100
|
-
-
|
|
101
|
+
- SQL base codecs: `sql/char`, `sql/varchar`, `sql/int`, `sql/float`
|
|
102
|
+
- PostgreSQL aliases for base codecs: `pg/char`, `pg/varchar`, `pg/int`, `pg/float`
|
|
103
|
+
- Supports PostgreSQL types: `int2`, `int4`, `int8`, `float4`, `float8`, `text`, `bool`, `enum`
|
|
104
|
+
- Supports PostgreSQL types: `int2`, `int4`, `int8`, `float4`, `float8`, `text`, `timestamp`, `timestamptz`, `bool`, `enum`, `json`, `jsonb`
|
|
105
|
+
- Parameterized types: `character(n)`, `character varying(n)`, `numeric(p,s)`, `bit(n)`, `bit varying(n)`, `timestamp(p)`, `timestamptz(p)`, `time(p)`, `timetz(p)`, `interval(p)`
|
|
101
106
|
|
|
102
107
|
**Types (`types.ts`)**
|
|
103
108
|
- PostgreSQL-specific types and utilities
|
|
@@ -122,6 +127,15 @@ flowchart TD
|
|
|
122
127
|
**Types Export (`types.ts`)**
|
|
123
128
|
- Re-exports PostgreSQL-specific types
|
|
124
129
|
|
|
130
|
+
**Column Types Export (`column-types.ts`)**
|
|
131
|
+
- Exports column descriptors for built-in types and enum helpers (`enumType`, `enumColumn(typeRef, nativeType)`)
|
|
132
|
+
- Parameterized helpers: `charColumn(length)`, `varcharColumn(length)`, `numericColumn(precision, scale?)`, `bitColumn(length)`, `varbitColumn(length)`, `timeColumn(precision?)`, `timetzColumn(precision?)`, `intervalColumn(precision?)`
|
|
133
|
+
|
|
134
|
+
- Exports JSON helpers:
|
|
135
|
+
- `jsonColumn`, `jsonbColumn`
|
|
136
|
+
- `json(schema?)`, `jsonb(schema?)` where `schema` is a Standard Schema value (e.g., Arktype)
|
|
137
|
+
- When a schema is provided, `typeParams` metadata is derived from the schema's `~standard` interface
|
|
138
|
+
|
|
125
139
|
## Dependencies
|
|
126
140
|
|
|
127
141
|
- **`@prisma-next/sql-contract`**: SQL contract types
|
|
@@ -142,6 +156,7 @@ flowchart TD
|
|
|
142
156
|
- [ADR 068 - Error mapping to RuntimeError](../../../../docs/architecture%20docs/adrs/ADR%20068%20-%20Error%20mapping%20to%20RuntimeError.md)
|
|
143
157
|
- [ADR 112 - Target Extension Packs](../../../../docs/architecture%20docs/adrs/ADR%20112%20-%20Target%20Extension%20Packs.md)
|
|
144
158
|
- [ADR 114 - Extension codecs & branded types](../../../../docs/architecture%20docs/adrs/ADR%20114%20-%20Extension%20codecs%20&%20branded%20types.md)
|
|
159
|
+
- [ADR 163 - Postgres JSON and JSONB typed columns](../../../../docs/architecture%20docs/adrs/ADR%20163%20-%20Postgres%20JSON%20and%20JSONB%20typed%20columns.md)
|
|
145
160
|
|
|
146
161
|
## Usage
|
|
147
162
|
|
|
@@ -180,6 +195,7 @@ The adapter declares the following PostgreSQL capabilities:
|
|
|
180
195
|
- **`lateral: true`** - Supports LATERAL joins for `includeMany` nested array includes
|
|
181
196
|
- **`jsonAgg: true`** - Supports JSON aggregation functions (`json_agg`) for `includeMany`
|
|
182
197
|
- **`returning: true`** - Supports RETURNING clauses for DML operations (INSERT, UPDATE, DELETE)
|
|
198
|
+
- **`sql.enums: true`** - Supports contract-defined enum storage types
|
|
183
199
|
|
|
184
200
|
**Important**: Capabilities must be declared in **both** places:
|
|
185
201
|
|
|
@@ -241,10 +257,56 @@ DELETE FROM "user" WHERE "user"."id" = $1 RETURNING "user"."id", "user"."email"
|
|
|
241
257
|
|
|
242
258
|
**Note:** MySQL does not support RETURNING clauses. A future MySQL adapter would declare `returning: false` and either reject plans with RETURNING or provide an alternative implementation.
|
|
243
259
|
|
|
260
|
+
## JSON and JSONB support
|
|
261
|
+
|
|
262
|
+
The adapter supports PostgreSQL-native `json` and `jsonb` columns.
|
|
263
|
+
|
|
264
|
+
### Value semantics
|
|
265
|
+
|
|
266
|
+
Both `json` and `jsonb` accept any valid JSON value:
|
|
267
|
+
|
|
268
|
+
- object
|
|
269
|
+
- array
|
|
270
|
+
- string
|
|
271
|
+
- number
|
|
272
|
+
- boolean
|
|
273
|
+
- JSON `null` (distinct from SQL `NULL`)
|
|
274
|
+
|
|
275
|
+
`jsonb` uses normalized binary storage, so whitespace and object key order are not preserved.
|
|
276
|
+
|
|
277
|
+
### Authoring helpers
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
import { json, jsonb } from '@prisma-next/adapter-postgres/column-types';
|
|
281
|
+
import { type as arktype } from 'arktype';
|
|
282
|
+
|
|
283
|
+
const auditPayloadSchema = arktype({
|
|
284
|
+
action: 'string',
|
|
285
|
+
actorId: 'number',
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
table('event', (t) =>
|
|
289
|
+
t
|
|
290
|
+
.column('payload', { type: jsonb(auditPayloadSchema), nullable: false })
|
|
291
|
+
.column('raw', { type: json(), nullable: true }),
|
|
292
|
+
);
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Typed fallback behavior
|
|
296
|
+
|
|
297
|
+
- If a schema value is provided, emitted `contract.d.ts` derives a concrete type from that schema.
|
|
298
|
+
- If no schema is provided, emitted type falls back to `JsonValue`.
|
|
299
|
+
- Runtime values still encode/decode as JSON-compatible values.
|
|
300
|
+
|
|
301
|
+
### Standard Schema integration
|
|
302
|
+
|
|
303
|
+
`json(schema)` and `jsonb(schema)` accept Standard Schema values. Arktype schemas work out of the box via their Standard Schema adapter (`schema['~standard']`).
|
|
304
|
+
|
|
244
305
|
## Exports
|
|
245
306
|
|
|
246
307
|
- `./adapter`: Adapter implementation (`createPostgresAdapter`)
|
|
247
|
-
- `./codec-types`: PostgreSQL codec types (`CodecTypes`, `dataTypes`)
|
|
308
|
+
- `./codec-types`: PostgreSQL codec types (`CodecTypes`, `JsonValue`, `dataTypes`)
|
|
309
|
+
- `./column-types`: Column type descriptors and authoring helpers (`json`, `jsonb`, `jsonColumn`, `jsonbColumn`, `enumType`, `enumColumn`, `textColumn`, `int4Column`, etc.)
|
|
248
310
|
- `./types`: PostgreSQL-specific types
|
|
249
311
|
- `./control`: Control-plane entry point (adapter descriptor)
|
|
250
312
|
- `./runtime`: Runtime-plane entry point (runtime adapter descriptor)
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { m as PG_JSON_CODEC_ID, p as PG_JSONB_CODEC_ID } from "./codec-ids-Bsm9c7ns.mjs";
|
|
2
|
+
import { t as codecDefinitions } from "./codecs-BfC_5c-4.mjs";
|
|
3
|
+
import { n as escapeLiteral } from "./sql-utils-CSfAGEwF.mjs";
|
|
4
|
+
import { createCodecRegistry, isOperationExpr } from "@prisma-next/sql-relational-core/ast";
|
|
5
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
6
|
+
|
|
7
|
+
//#region src/core/adapter.ts
|
|
8
|
+
const VECTOR_CODEC_ID = "pg/vector@1";
|
|
9
|
+
function getCodecParamCast(codecId) {
|
|
10
|
+
if (codecId === VECTOR_CODEC_ID) return "vector";
|
|
11
|
+
if (codecId === PG_JSON_CODEC_ID) return "json";
|
|
12
|
+
if (codecId === PG_JSONB_CODEC_ID) return "jsonb";
|
|
13
|
+
}
|
|
14
|
+
function renderTypedParam(index, codecId) {
|
|
15
|
+
const cast = getCodecParamCast(codecId);
|
|
16
|
+
return cast ? `$${index}::${cast}` : `$${index}`;
|
|
17
|
+
}
|
|
18
|
+
const defaultCapabilities = Object.freeze({
|
|
19
|
+
postgres: {
|
|
20
|
+
orderBy: true,
|
|
21
|
+
limit: true,
|
|
22
|
+
lateral: true,
|
|
23
|
+
jsonAgg: true,
|
|
24
|
+
returning: true
|
|
25
|
+
},
|
|
26
|
+
sql: { enums: true }
|
|
27
|
+
});
|
|
28
|
+
const parameterizedCodecs = Object.values(codecDefinitions).map((definition) => definition.codec).filter((codec$1) => codec$1.paramsSchema !== void 0).map((codec$1) => Object.freeze({
|
|
29
|
+
codecId: codec$1.id,
|
|
30
|
+
paramsSchema: codec$1.paramsSchema,
|
|
31
|
+
...ifDefined("init", codec$1.init)
|
|
32
|
+
}));
|
|
33
|
+
var PostgresAdapterImpl = class {
|
|
34
|
+
familyId = "sql";
|
|
35
|
+
targetId = "postgres";
|
|
36
|
+
profile;
|
|
37
|
+
codecRegistry = (() => {
|
|
38
|
+
const registry = createCodecRegistry();
|
|
39
|
+
for (const definition of Object.values(codecDefinitions)) registry.register(definition.codec);
|
|
40
|
+
return registry;
|
|
41
|
+
})();
|
|
42
|
+
constructor(options) {
|
|
43
|
+
this.profile = Object.freeze({
|
|
44
|
+
id: options?.profileId ?? "postgres/default@1",
|
|
45
|
+
target: "postgres",
|
|
46
|
+
capabilities: defaultCapabilities,
|
|
47
|
+
codecs: () => this.codecRegistry
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
parameterizedCodecs() {
|
|
51
|
+
return parameterizedCodecs;
|
|
52
|
+
}
|
|
53
|
+
lower(ast, context) {
|
|
54
|
+
let sql;
|
|
55
|
+
const params = context.params ? [...context.params] : [];
|
|
56
|
+
if (ast.kind === "select") sql = renderSelect(ast, context.contract);
|
|
57
|
+
else if (ast.kind === "insert") sql = renderInsert(ast, context.contract);
|
|
58
|
+
else if (ast.kind === "update") sql = renderUpdate(ast, context.contract);
|
|
59
|
+
else if (ast.kind === "delete") sql = renderDelete(ast, context.contract);
|
|
60
|
+
else throw new Error(`Unsupported AST kind: ${ast.kind}`);
|
|
61
|
+
return Object.freeze({
|
|
62
|
+
profileId: this.profile.id,
|
|
63
|
+
body: Object.freeze({
|
|
64
|
+
sql,
|
|
65
|
+
params
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
function renderSelect(ast, contract) {
|
|
71
|
+
const selectClause = `SELECT ${renderProjection(ast, contract)}`;
|
|
72
|
+
const fromClause = `FROM ${quoteIdentifier(ast.from.name)}`;
|
|
73
|
+
const joinsClause = ast.joins?.length ? ast.joins.map((join) => renderJoin(join, contract)).join(" ") : "";
|
|
74
|
+
const includesClause = ast.includes?.length ? ast.includes.map((include) => renderInclude(include, contract)).join(" ") : "";
|
|
75
|
+
const whereClause = ast.where ? ` WHERE ${renderWhere(ast.where, contract)}` : "";
|
|
76
|
+
const orderClause = ast.orderBy?.length ? ` ORDER BY ${ast.orderBy.map((order) => {
|
|
77
|
+
return `${renderExpr(order.expr, contract)} ${order.dir.toUpperCase()}`;
|
|
78
|
+
}).join(", ")}` : "";
|
|
79
|
+
const limitClause = typeof ast.limit === "number" ? ` LIMIT ${ast.limit}` : "";
|
|
80
|
+
const clauses = [joinsClause, includesClause].filter(Boolean).join(" ");
|
|
81
|
+
return `${selectClause} ${fromClause}${clauses ? ` ${clauses}` : ""}${whereClause}${orderClause}${limitClause}`.trim();
|
|
82
|
+
}
|
|
83
|
+
function renderProjection(ast, contract) {
|
|
84
|
+
return ast.project.map((item) => {
|
|
85
|
+
const expr = item.expr;
|
|
86
|
+
if (expr.kind === "includeRef") return `${quoteIdentifier(`${expr.alias}_lateral`)}.${quoteIdentifier(expr.alias)} AS ${quoteIdentifier(item.alias)}`;
|
|
87
|
+
if (expr.kind === "operation") return `${renderOperation(expr, contract)} AS ${quoteIdentifier(item.alias)}`;
|
|
88
|
+
if (expr.kind === "literal") return `${renderLiteral(expr)} AS ${quoteIdentifier(item.alias)}`;
|
|
89
|
+
return `${renderColumn(expr)} AS ${quoteIdentifier(item.alias)}`;
|
|
90
|
+
}).join(", ");
|
|
91
|
+
}
|
|
92
|
+
function renderWhere(expr, contract) {
|
|
93
|
+
if (expr.kind === "exists") return `${expr.not ? "NOT " : ""}EXISTS (${renderSelect(expr.subquery, contract)})`;
|
|
94
|
+
if (expr.kind === "nullCheck") return renderNullCheck(expr, contract);
|
|
95
|
+
if (expr.kind === "and") {
|
|
96
|
+
if (expr.exprs.length === 0) return "TRUE";
|
|
97
|
+
return `(${expr.exprs.map((part) => renderWhere(part, contract)).join(" AND ")})`;
|
|
98
|
+
}
|
|
99
|
+
if (expr.kind === "or") {
|
|
100
|
+
if (expr.exprs.length === 0) return "FALSE";
|
|
101
|
+
return `(${expr.exprs.map((part) => renderWhere(part, contract)).join(" OR ")})`;
|
|
102
|
+
}
|
|
103
|
+
return renderBinary(expr, contract);
|
|
104
|
+
}
|
|
105
|
+
function renderNullCheck(expr, contract) {
|
|
106
|
+
const rendered = renderExpr(expr.expr, contract);
|
|
107
|
+
const renderedExpr = isOperationExpr(expr.expr) ? `(${rendered})` : rendered;
|
|
108
|
+
return expr.isNull ? `${renderedExpr} IS NULL` : `${renderedExpr} IS NOT NULL`;
|
|
109
|
+
}
|
|
110
|
+
function renderBinary(expr, contract) {
|
|
111
|
+
if (expr.right.kind === "listLiteral" && expr.right.values.length === 0) {
|
|
112
|
+
if (expr.op === "in") return "FALSE";
|
|
113
|
+
if (expr.op === "notIn") return "TRUE";
|
|
114
|
+
}
|
|
115
|
+
const leftExpr = expr.left;
|
|
116
|
+
const left = renderExpr(leftExpr, contract);
|
|
117
|
+
const leftRendered = isOperationExpr(leftExpr) ? `(${left})` : left;
|
|
118
|
+
const leftCol = leftExpr.kind === "col" ? leftExpr : void 0;
|
|
119
|
+
const rightExpr = expr.right;
|
|
120
|
+
let right;
|
|
121
|
+
if (rightExpr.kind === "listLiteral") right = renderListLiteral(rightExpr, contract, leftCol?.table, leftCol?.column);
|
|
122
|
+
else if (rightExpr.kind === "literal") right = renderLiteral(rightExpr);
|
|
123
|
+
else if (rightExpr.kind === "col") right = renderColumn(rightExpr);
|
|
124
|
+
else if (rightExpr.kind === "param") right = renderParam(rightExpr, contract, leftCol?.table, leftCol?.column);
|
|
125
|
+
else if (rightExpr.kind === "operation") right = renderOperation(rightExpr, contract);
|
|
126
|
+
else right = renderColumn(rightExpr);
|
|
127
|
+
return `${leftRendered} ${{
|
|
128
|
+
eq: "=",
|
|
129
|
+
neq: "!=",
|
|
130
|
+
gt: ">",
|
|
131
|
+
lt: "<",
|
|
132
|
+
gte: ">=",
|
|
133
|
+
lte: "<=",
|
|
134
|
+
like: "LIKE",
|
|
135
|
+
ilike: "ILIKE",
|
|
136
|
+
in: "IN",
|
|
137
|
+
notIn: "NOT IN"
|
|
138
|
+
}[expr.op]} ${right}`;
|
|
139
|
+
}
|
|
140
|
+
function renderListLiteral(expr, contract, tableName, columnName) {
|
|
141
|
+
if (expr.values.length === 0) return "(NULL)";
|
|
142
|
+
return `(${expr.values.map((v) => v.kind === "param" ? renderParam(v, contract, tableName, columnName) : renderLiteral(v)).join(", ")})`;
|
|
143
|
+
}
|
|
144
|
+
function renderColumn(ref) {
|
|
145
|
+
return `${quoteIdentifier(ref.table)}.${quoteIdentifier(ref.column)}`;
|
|
146
|
+
}
|
|
147
|
+
function renderExpr(expr, contract) {
|
|
148
|
+
if (isOperationExpr(expr)) return renderOperation(expr, contract);
|
|
149
|
+
return renderColumn(expr);
|
|
150
|
+
}
|
|
151
|
+
function renderParam(ref, contract, tableName, columnName) {
|
|
152
|
+
if (contract && tableName && columnName) {
|
|
153
|
+
const columnMeta = contract.storage.tables[tableName]?.columns[columnName];
|
|
154
|
+
return renderTypedParam(ref.index, columnMeta?.codecId);
|
|
155
|
+
}
|
|
156
|
+
return `$${ref.index}`;
|
|
157
|
+
}
|
|
158
|
+
function renderLiteral(expr) {
|
|
159
|
+
if (typeof expr.value === "string") return `'${escapeLiteral(expr.value)}'`;
|
|
160
|
+
if (typeof expr.value === "number" || typeof expr.value === "boolean") return String(expr.value);
|
|
161
|
+
if (expr.value === null) return "NULL";
|
|
162
|
+
if (Array.isArray(expr.value)) return `ARRAY[${expr.value.map((v) => renderLiteral({
|
|
163
|
+
kind: "literal",
|
|
164
|
+
value: v
|
|
165
|
+
})).join(", ")}]`;
|
|
166
|
+
return JSON.stringify(expr.value);
|
|
167
|
+
}
|
|
168
|
+
function renderOperation(expr, contract) {
|
|
169
|
+
const self = renderExpr(expr.self, contract);
|
|
170
|
+
const isVectorOperation = expr.forTypeId === VECTOR_CODEC_ID;
|
|
171
|
+
const args = expr.args.map((arg) => {
|
|
172
|
+
if (arg.kind === "col") return renderColumn(arg);
|
|
173
|
+
if (arg.kind === "param") return isVectorOperation ? `$${arg.index}::vector` : renderParam(arg, contract);
|
|
174
|
+
if (arg.kind === "literal") return renderLiteral(arg);
|
|
175
|
+
if (arg.kind === "operation") return renderOperation(arg, contract);
|
|
176
|
+
const _exhaustive = arg;
|
|
177
|
+
throw new Error(`Unsupported argument kind: ${_exhaustive.kind}`);
|
|
178
|
+
});
|
|
179
|
+
let result = expr.lowering.template;
|
|
180
|
+
result = result.replace(/\$\{self\}/g, self);
|
|
181
|
+
for (let i = 0; i < args.length; i++) result = result.replace(new RegExp(`\\$\\{arg${i}\\}`, "g"), args[i] ?? "");
|
|
182
|
+
if (expr.lowering.strategy === "function") return result;
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
function renderJoin(join, contract) {
|
|
186
|
+
return `${join.joinType.toUpperCase()} JOIN ${quoteIdentifier(join.table.name)} ON ${renderJoinOn(join.on, contract)}`;
|
|
187
|
+
}
|
|
188
|
+
function renderJoinOn(on, contract) {
|
|
189
|
+
if (on.kind === "eqCol") return `${renderColumn(on.left)} = ${renderColumn(on.right)}`;
|
|
190
|
+
return renderWhere(on, contract);
|
|
191
|
+
}
|
|
192
|
+
function renderInclude(include, contract) {
|
|
193
|
+
const alias = include.alias;
|
|
194
|
+
const jsonBuildObject = `json_build_object(${include.child.project.map((item) => {
|
|
195
|
+
const expr = renderExpr(item.expr, contract);
|
|
196
|
+
return `'${item.alias}', ${expr}`;
|
|
197
|
+
}).join(", ")})`;
|
|
198
|
+
let whereClause = ` WHERE ${renderJoinOn(include.child.on, contract)}`;
|
|
199
|
+
if (include.child.where) whereClause += ` AND ${renderWhere(include.child.where, contract)}`;
|
|
200
|
+
const childOrderBy = include.child.orderBy?.length ? ` ORDER BY ${include.child.orderBy.map((order) => `${renderExpr(order.expr, contract)} ${order.dir.toUpperCase()}`).join(", ")}` : "";
|
|
201
|
+
const childLimit = typeof include.child.limit === "number" ? ` LIMIT ${include.child.limit}` : "";
|
|
202
|
+
const childTable = quoteIdentifier(include.child.table.name);
|
|
203
|
+
let subquery;
|
|
204
|
+
if (typeof include.child.limit === "number") {
|
|
205
|
+
const columnAliasMap = /* @__PURE__ */ new Map();
|
|
206
|
+
for (const item of include.child.project) if (item.expr.kind === "col") {
|
|
207
|
+
const columnKey = `${item.expr.table}.${item.expr.column}`;
|
|
208
|
+
columnAliasMap.set(columnKey, item.alias);
|
|
209
|
+
}
|
|
210
|
+
const innerColumns = include.child.project.map((item) => {
|
|
211
|
+
return `${renderExpr(item.expr, contract)} AS ${quoteIdentifier(item.alias)}`;
|
|
212
|
+
}).join(", ");
|
|
213
|
+
const childOrderByWithAliases = include.child.orderBy?.length ? ` ORDER BY ${include.child.orderBy.map((order) => {
|
|
214
|
+
if (order.expr.kind === "col") {
|
|
215
|
+
const columnKey = `${order.expr.table}.${order.expr.column}`;
|
|
216
|
+
const alias$1 = columnAliasMap.get(columnKey);
|
|
217
|
+
if (alias$1) return `${quoteIdentifier(alias$1)} ${order.dir.toUpperCase()}`;
|
|
218
|
+
}
|
|
219
|
+
return `${renderExpr(order.expr, contract)} ${order.dir.toUpperCase()}`;
|
|
220
|
+
}).join(", ")}` : "";
|
|
221
|
+
const innerSelect = `SELECT ${innerColumns} FROM ${childTable}${whereClause}${childOrderByWithAliases}${childLimit}`;
|
|
222
|
+
subquery = `(SELECT json_agg(row_to_json(sub.*)) AS ${quoteIdentifier(alias)} FROM (${innerSelect}) sub)`;
|
|
223
|
+
} else if (childOrderBy) subquery = `(SELECT json_agg(${jsonBuildObject}${childOrderBy}) AS ${quoteIdentifier(alias)} FROM ${childTable}${whereClause})`;
|
|
224
|
+
else subquery = `(SELECT json_agg(${jsonBuildObject}) AS ${quoteIdentifier(alias)} FROM ${childTable}${whereClause})`;
|
|
225
|
+
const tableAlias = `${alias}_lateral`;
|
|
226
|
+
return `LEFT JOIN LATERAL ${subquery} AS ${quoteIdentifier(tableAlias)} ON true`;
|
|
227
|
+
}
|
|
228
|
+
function quoteIdentifier(identifier) {
|
|
229
|
+
return `"${identifier.replace(/"/g, "\"\"")}"`;
|
|
230
|
+
}
|
|
231
|
+
function renderInsert(ast, contract) {
|
|
232
|
+
const table = quoteIdentifier(ast.table.name);
|
|
233
|
+
const columns = Object.keys(ast.values).map((col) => quoteIdentifier(col));
|
|
234
|
+
const tableMeta = contract.storage.tables[ast.table.name];
|
|
235
|
+
const values = Object.entries(ast.values).map(([colName, val]) => {
|
|
236
|
+
if (val.kind === "param") {
|
|
237
|
+
const columnMeta = tableMeta?.columns[colName];
|
|
238
|
+
return renderTypedParam(val.index, columnMeta?.codecId);
|
|
239
|
+
}
|
|
240
|
+
if (val.kind === "col") return `${quoteIdentifier(val.table)}.${quoteIdentifier(val.column)}`;
|
|
241
|
+
throw new Error(`Unsupported value kind in INSERT: ${val.kind}`);
|
|
242
|
+
});
|
|
243
|
+
return `${columns.length === 0 ? `INSERT INTO ${table} DEFAULT VALUES` : `INSERT INTO ${table} (${columns.join(", ")}) VALUES (${values.join(", ")})`}${ast.returning?.length ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(", ")}` : ""}`;
|
|
244
|
+
}
|
|
245
|
+
function renderUpdate(ast, contract) {
|
|
246
|
+
const table = quoteIdentifier(ast.table.name);
|
|
247
|
+
const tableMeta = contract.storage.tables[ast.table.name];
|
|
248
|
+
const setClauses = Object.entries(ast.set).map(([col, val]) => {
|
|
249
|
+
const column = quoteIdentifier(col);
|
|
250
|
+
let value;
|
|
251
|
+
if (val.kind === "param") {
|
|
252
|
+
const columnMeta = tableMeta?.columns[col];
|
|
253
|
+
value = renderTypedParam(val.index, columnMeta?.codecId);
|
|
254
|
+
} else if (val.kind === "col") value = `${quoteIdentifier(val.table)}.${quoteIdentifier(val.column)}`;
|
|
255
|
+
else throw new Error(`Unsupported value kind in UPDATE: ${val.kind}`);
|
|
256
|
+
return `${column} = ${value}`;
|
|
257
|
+
});
|
|
258
|
+
const whereClause = ast.where ? ` WHERE ${renderWhere(ast.where, contract)}` : "";
|
|
259
|
+
const returningClause = ast.returning?.length ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(", ")}` : "";
|
|
260
|
+
return `UPDATE ${table} SET ${setClauses.join(", ")}${whereClause}${returningClause}`;
|
|
261
|
+
}
|
|
262
|
+
function renderDelete(ast, contract) {
|
|
263
|
+
return `DELETE FROM ${quoteIdentifier(ast.table.name)}${ast.where ? ` WHERE ${renderWhere(ast.where, contract)}` : ""}${ast.returning?.length ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(", ")}` : ""}`;
|
|
264
|
+
}
|
|
265
|
+
function createPostgresAdapter(options) {
|
|
266
|
+
return Object.freeze(new PostgresAdapterImpl(options));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
//#endregion
|
|
270
|
+
export { createPostgresAdapter as t };
|
|
271
|
+
//# sourceMappingURL=adapter-DtehReRR.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-DtehReRR.mjs","names":["parameterizedCodecs: ReadonlyArray<CodecParamsDescriptor>","codec","sql: string","right: string","_exhaustive: never","subquery: string","alias","value: string"],"sources":["../src/core/adapter.ts"],"sourcesContent":["import type {\n Adapter,\n AdapterProfile,\n BinaryExpr,\n CodecParamsDescriptor,\n ColumnRef,\n DeleteAst,\n IncludeRef,\n InsertAst,\n JoinAst,\n JoinOnExpr,\n ListLiteralExpr,\n LiteralExpr,\n LowererContext,\n NullCheckExpr,\n OperationExpr,\n ParamRef,\n QueryAst,\n SelectAst,\n UpdateAst,\n WhereExpr,\n} from '@prisma-next/sql-relational-core/ast';\nimport { createCodecRegistry, isOperationExpr } from '@prisma-next/sql-relational-core/ast';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { PG_JSON_CODEC_ID, PG_JSONB_CODEC_ID } from './codec-ids';\nimport { codecDefinitions } from './codecs';\nimport { escapeLiteral } from './sql-utils';\nimport type { PostgresAdapterOptions, PostgresContract, PostgresLoweredStatement } from './types';\n\nconst VECTOR_CODEC_ID = 'pg/vector@1' as const;\n\nfunction getCodecParamCast(codecId: string | undefined): string | undefined {\n if (codecId === VECTOR_CODEC_ID) {\n return 'vector';\n }\n if (codecId === PG_JSON_CODEC_ID) {\n return 'json';\n }\n if (codecId === PG_JSONB_CODEC_ID) {\n return 'jsonb';\n }\n return undefined;\n}\n\nfunction renderTypedParam(index: number, codecId: string | undefined): string {\n const cast = getCodecParamCast(codecId);\n return cast ? `$${index}::${cast}` : `$${index}`;\n}\n\nconst defaultCapabilities = Object.freeze({\n postgres: {\n orderBy: true,\n limit: true,\n lateral: true,\n jsonAgg: true,\n returning: true,\n },\n sql: {\n enums: true,\n },\n});\n\ntype AdapterCodec = (typeof codecDefinitions)[keyof typeof codecDefinitions]['codec'];\ntype ParameterizedCodec = AdapterCodec & {\n readonly paramsSchema: NonNullable<AdapterCodec['paramsSchema']>;\n};\n\nconst parameterizedCodecs: ReadonlyArray<CodecParamsDescriptor> = Object.values(codecDefinitions)\n .map((definition) => definition.codec)\n .filter((codec): codec is ParameterizedCodec => codec.paramsSchema !== undefined)\n .map((codec) =>\n Object.freeze({\n codecId: codec.id,\n paramsSchema: codec.paramsSchema,\n ...ifDefined('init', codec.init),\n }),\n );\n\nclass PostgresAdapterImpl implements Adapter<QueryAst, PostgresContract, PostgresLoweredStatement> {\n // These fields make the adapter instance structurally compatible with\n // RuntimeAdapterInstance<'sql', 'postgres'> without introducing a runtime-plane dependency.\n readonly familyId = 'sql' as const;\n readonly targetId = 'postgres' as const;\n\n readonly profile: AdapterProfile<'postgres'>;\n private readonly codecRegistry = (() => {\n const registry = createCodecRegistry();\n for (const definition of Object.values(codecDefinitions)) {\n registry.register(definition.codec);\n }\n return registry;\n })();\n\n constructor(options?: PostgresAdapterOptions) {\n this.profile = Object.freeze({\n id: options?.profileId ?? 'postgres/default@1',\n target: 'postgres',\n capabilities: defaultCapabilities,\n codecs: () => this.codecRegistry,\n });\n }\n\n parameterizedCodecs(): ReadonlyArray<CodecParamsDescriptor> {\n return parameterizedCodecs;\n }\n\n lower(ast: QueryAst, context: LowererContext<PostgresContract>) {\n let sql: string;\n const params = context.params ? [...context.params] : [];\n\n if (ast.kind === 'select') {\n sql = renderSelect(ast, context.contract);\n } else if (ast.kind === 'insert') {\n sql = renderInsert(ast, context.contract);\n } else if (ast.kind === 'update') {\n sql = renderUpdate(ast, context.contract);\n } else if (ast.kind === 'delete') {\n sql = renderDelete(ast, context.contract);\n } else {\n throw new Error(`Unsupported AST kind: ${(ast as { kind: string }).kind}`);\n }\n\n return Object.freeze({\n profileId: this.profile.id,\n body: Object.freeze({ sql, params }),\n });\n }\n}\n\nfunction renderSelect(ast: SelectAst, contract?: PostgresContract): string {\n const selectClause = `SELECT ${renderProjection(ast, contract)}`;\n const fromClause = `FROM ${quoteIdentifier(ast.from.name)}`;\n\n const joinsClause = ast.joins?.length\n ? ast.joins.map((join) => renderJoin(join, contract)).join(' ')\n : '';\n const includesClause = ast.includes?.length\n ? ast.includes.map((include) => renderInclude(include, contract)).join(' ')\n : '';\n\n const whereClause = ast.where ? ` WHERE ${renderWhere(ast.where, contract)}` : '';\n const orderClause = ast.orderBy?.length\n ? ` ORDER BY ${ast.orderBy\n .map((order) => {\n const expr = renderExpr(order.expr as ColumnRef | OperationExpr, contract);\n return `${expr} ${order.dir.toUpperCase()}`;\n })\n .join(', ')}`\n : '';\n const limitClause = typeof ast.limit === 'number' ? ` LIMIT ${ast.limit}` : '';\n\n const clauses = [joinsClause, includesClause].filter(Boolean).join(' ');\n return `${selectClause} ${fromClause}${clauses ? ` ${clauses}` : ''}${whereClause}${orderClause}${limitClause}`.trim();\n}\n\nfunction renderProjection(ast: SelectAst, contract?: PostgresContract): string {\n return ast.project\n .map((item) => {\n const expr = item.expr as ColumnRef | IncludeRef | OperationExpr | LiteralExpr;\n if (expr.kind === 'includeRef') {\n // For include references, select the column from the LATERAL join alias\n // The LATERAL subquery returns a single column (the JSON array) with the alias\n // The table is aliased as {alias}_lateral, and the column inside is aliased as the include alias\n // We select it using table_alias.column_alias\n const tableAlias = `${expr.alias}_lateral`;\n return `${quoteIdentifier(tableAlias)}.${quoteIdentifier(expr.alias)} AS ${quoteIdentifier(item.alias)}`;\n }\n if (expr.kind === 'operation') {\n const operation = renderOperation(expr, contract);\n const alias = quoteIdentifier(item.alias);\n return `${operation} AS ${alias}`;\n }\n if (expr.kind === 'literal') {\n const literal = renderLiteral(expr);\n const alias = quoteIdentifier(item.alias);\n return `${literal} AS ${alias}`;\n }\n const column = renderColumn(expr as ColumnRef);\n const alias = quoteIdentifier(item.alias);\n return `${column} AS ${alias}`;\n })\n .join(', ');\n}\n\nfunction renderWhere(expr: WhereExpr, contract?: PostgresContract): string {\n if (expr.kind === 'exists') {\n const notKeyword = expr.not ? 'NOT ' : '';\n const subquery = renderSelect(expr.subquery, contract);\n return `${notKeyword}EXISTS (${subquery})`;\n }\n if (expr.kind === 'nullCheck') {\n return renderNullCheck(expr, contract);\n }\n if (expr.kind === 'and') {\n if (expr.exprs.length === 0) {\n return 'TRUE';\n }\n return `(${expr.exprs.map((part) => renderWhere(part, contract)).join(' AND ')})`;\n }\n if (expr.kind === 'or') {\n if (expr.exprs.length === 0) {\n return 'FALSE';\n }\n return `(${expr.exprs.map((part) => renderWhere(part, contract)).join(' OR ')})`;\n }\n return renderBinary(expr, contract);\n}\n\nfunction renderNullCheck(expr: NullCheckExpr, contract?: PostgresContract): string {\n const rendered = renderExpr(expr.expr as ColumnRef | OperationExpr, contract);\n // Only wrap in parentheses if it's an operation expression\n const renderedExpr = isOperationExpr(expr.expr) ? `(${rendered})` : rendered;\n return expr.isNull ? `${renderedExpr} IS NULL` : `${renderedExpr} IS NOT NULL`;\n}\n\nfunction renderBinary(expr: BinaryExpr, contract?: PostgresContract): string {\n if (expr.right.kind === 'listLiteral' && expr.right.values.length === 0) {\n if (expr.op === 'in') {\n return 'FALSE';\n }\n if (expr.op === 'notIn') {\n return 'TRUE';\n }\n }\n\n const leftExpr = expr.left as ColumnRef | OperationExpr;\n const left = renderExpr(leftExpr, contract);\n const leftRendered = isOperationExpr(leftExpr) ? `(${left})` : left;\n const leftCol = leftExpr.kind === 'col' ? leftExpr : undefined;\n\n const rightExpr = expr.right;\n let right: string;\n if (rightExpr.kind === 'listLiteral') {\n right = renderListLiteral(\n rightExpr as ListLiteralExpr,\n contract,\n leftCol?.table,\n leftCol?.column,\n );\n } else if (rightExpr.kind === 'literal') {\n right = renderLiteral(rightExpr);\n } else if (rightExpr.kind === 'col') {\n right = renderColumn(rightExpr);\n } else if (rightExpr.kind === 'param') {\n right = renderParam(rightExpr, contract, leftCol?.table, leftCol?.column);\n } else if (rightExpr.kind === 'operation') {\n right = renderOperation(rightExpr, contract);\n } else {\n right = renderColumn(rightExpr as ColumnRef);\n }\n\n const operatorMap: Record<BinaryExpr['op'], string> = {\n eq: '=',\n neq: '!=',\n gt: '>',\n lt: '<',\n gte: '>=',\n lte: '<=',\n like: 'LIKE',\n ilike: 'ILIKE',\n in: 'IN',\n notIn: 'NOT IN',\n };\n\n return `${leftRendered} ${operatorMap[expr.op]} ${right}`;\n}\n\nfunction renderListLiteral(\n expr: ListLiteralExpr,\n contract?: PostgresContract,\n tableName?: string,\n columnName?: string,\n): string {\n if (expr.values.length === 0) {\n return '(NULL)';\n }\n const values = expr.values\n .map((v) =>\n v.kind === 'param' ? renderParam(v, contract, tableName, columnName) : renderLiteral(v),\n )\n .join(', ');\n return `(${values})`;\n}\n\nfunction renderColumn(ref: ColumnRef): string {\n return `${quoteIdentifier(ref.table)}.${quoteIdentifier(ref.column)}`;\n}\n\nfunction renderExpr(expr: ColumnRef | OperationExpr, contract?: PostgresContract): string {\n if (isOperationExpr(expr)) {\n return renderOperation(expr, contract);\n }\n return renderColumn(expr);\n}\n\nfunction renderParam(\n ref: ParamRef,\n contract?: PostgresContract,\n tableName?: string,\n columnName?: string,\n): string {\n if (contract && tableName && columnName) {\n const tableMeta = contract.storage.tables[tableName];\n const columnMeta = tableMeta?.columns[columnName];\n return renderTypedParam(ref.index, columnMeta?.codecId);\n }\n return `$${ref.index}`;\n}\n\nfunction renderLiteral(expr: LiteralExpr): string {\n if (typeof expr.value === 'string') {\n return `'${escapeLiteral(expr.value)}'`;\n }\n if (typeof expr.value === 'number' || typeof expr.value === 'boolean') {\n return String(expr.value);\n }\n if (expr.value === null) {\n return 'NULL';\n }\n if (Array.isArray(expr.value)) {\n return `ARRAY[${expr.value.map((v: unknown) => renderLiteral({ kind: 'literal', value: v })).join(', ')}]`;\n }\n return JSON.stringify(expr.value);\n}\n\nfunction renderOperation(expr: OperationExpr, contract?: PostgresContract): string {\n const self = renderExpr(expr.self, contract);\n // For vector operations, cast param arguments to vector type\n const isVectorOperation = expr.forTypeId === VECTOR_CODEC_ID;\n const args = expr.args.map((arg: ColumnRef | ParamRef | LiteralExpr | OperationExpr) => {\n if (arg.kind === 'col') {\n return renderColumn(arg);\n }\n if (arg.kind === 'param') {\n // Cast vector operation parameters to vector type\n return isVectorOperation ? `$${arg.index}::vector` : renderParam(arg, contract);\n }\n if (arg.kind === 'literal') {\n return renderLiteral(arg);\n }\n if (arg.kind === 'operation') {\n return renderOperation(arg, contract);\n }\n const _exhaustive: never = arg;\n throw new Error(`Unsupported argument kind: ${(_exhaustive as { kind: string }).kind}`);\n });\n\n let result = expr.lowering.template;\n result = result.replace(/\\$\\{self\\}/g, self);\n for (let i = 0; i < args.length; i++) {\n result = result.replace(new RegExp(`\\\\$\\\\{arg${i}\\\\}`, 'g'), args[i] ?? '');\n }\n\n if (expr.lowering.strategy === 'function') {\n return result;\n }\n\n return result;\n}\n\nfunction renderJoin(join: JoinAst, contract?: PostgresContract): string {\n const joinType = join.joinType.toUpperCase();\n const table = quoteIdentifier(join.table.name);\n const onClause = renderJoinOn(join.on, contract);\n return `${joinType} JOIN ${table} ON ${onClause}`;\n}\n\nfunction renderJoinOn(on: JoinOnExpr, contract?: PostgresContract): string {\n if (on.kind === 'eqCol') {\n const left = renderColumn(on.left);\n const right = renderColumn(on.right);\n return `${left} = ${right}`;\n }\n return renderWhere(on, contract);\n}\n\nfunction renderInclude(\n include: NonNullable<SelectAst['includes']>[number],\n contract?: PostgresContract,\n): string {\n const alias = include.alias;\n\n // Build the lateral subquery\n const childProjection = include.child.project\n .map((item: { alias: string; expr: ColumnRef | OperationExpr }) => {\n const expr = renderExpr(item.expr, contract);\n return `'${item.alias}', ${expr}`;\n })\n .join(', ');\n\n const jsonBuildObject = `json_build_object(${childProjection})`;\n\n // Build the ON condition from the include's ON clause - this goes in the WHERE clause\n const onCondition = renderJoinOn(include.child.on, contract);\n\n // Build WHERE clause: combine ON condition with any additional WHERE clauses\n let whereClause = ` WHERE ${onCondition}`;\n if (include.child.where) {\n whereClause += ` AND ${renderWhere(include.child.where, contract)}`;\n }\n\n // Add ORDER BY if present - it goes inside json_agg() call\n const childOrderBy = include.child.orderBy?.length\n ? ` ORDER BY ${include.child.orderBy\n .map(\n (order: { expr: ColumnRef | OperationExpr; dir: string }) =>\n `${renderExpr(order.expr, contract)} ${order.dir.toUpperCase()}`,\n )\n .join(', ')}`\n : '';\n\n // Add LIMIT if present\n const childLimit = typeof include.child.limit === 'number' ? ` LIMIT ${include.child.limit}` : '';\n\n // Build the lateral subquery\n // When ORDER BY is present without LIMIT, it goes inside json_agg() call: json_agg(expr ORDER BY ...)\n // When LIMIT is present (with or without ORDER BY), we need to wrap in a subquery\n const childTable = quoteIdentifier(include.child.table.name);\n let subquery: string;\n if (typeof include.child.limit === 'number') {\n // With LIMIT, we need to wrap in a subquery\n // Select individual columns in inner query, then aggregate\n // Create a map of column references to their aliases for ORDER BY\n // Only ColumnRef can be mapped (OperationExpr doesn't have table/column properties)\n const columnAliasMap = new Map<string, string>();\n for (const item of include.child.project) {\n if (item.expr.kind === 'col') {\n const columnKey = `${item.expr.table}.${item.expr.column}`;\n columnAliasMap.set(columnKey, item.alias);\n }\n }\n\n const innerColumns = include.child.project\n .map((item: { alias: string; expr: ColumnRef | OperationExpr }) => {\n const expr = renderExpr(item.expr, contract);\n return `${expr} AS ${quoteIdentifier(item.alias)}`;\n })\n .join(', ');\n\n // For ORDER BY, use column aliases if the column is in the SELECT list\n const childOrderByWithAliases = include.child.orderBy?.length\n ? ` ORDER BY ${include.child.orderBy\n .map((order: { expr: ColumnRef | OperationExpr; dir: string }) => {\n if (order.expr.kind === 'col') {\n const columnKey = `${order.expr.table}.${order.expr.column}`;\n const alias = columnAliasMap.get(columnKey);\n if (alias) {\n return `${quoteIdentifier(alias)} ${order.dir.toUpperCase()}`;\n }\n }\n return `${renderExpr(order.expr, contract)} ${order.dir.toUpperCase()}`;\n })\n .join(', ')}`\n : '';\n\n const innerSelect = `SELECT ${innerColumns} FROM ${childTable}${whereClause}${childOrderByWithAliases}${childLimit}`;\n subquery = `(SELECT json_agg(row_to_json(sub.*)) AS ${quoteIdentifier(alias)} FROM (${innerSelect}) sub)`;\n } else if (childOrderBy) {\n // With ORDER BY but no LIMIT, ORDER BY goes inside json_agg()\n subquery = `(SELECT json_agg(${jsonBuildObject}${childOrderBy}) AS ${quoteIdentifier(alias)} FROM ${childTable}${whereClause})`;\n } else {\n // No ORDER BY or LIMIT\n subquery = `(SELECT json_agg(${jsonBuildObject}) AS ${quoteIdentifier(alias)} FROM ${childTable}${whereClause})`;\n }\n\n // Return the LATERAL join with ON true (the condition is in the WHERE clause)\n // The subquery returns a single column (the JSON array) with the alias\n // We use a different alias for the table to avoid ambiguity when selecting the column\n const tableAlias = `${alias}_lateral`;\n return `LEFT JOIN LATERAL ${subquery} AS ${quoteIdentifier(tableAlias)} ON true`;\n}\n\nfunction quoteIdentifier(identifier: string): string {\n return `\"${identifier.replace(/\"/g, '\"\"')}\"`;\n}\n\nfunction renderInsert(ast: InsertAst, contract: PostgresContract): string {\n const table = quoteIdentifier(ast.table.name);\n const columns = Object.keys(ast.values).map((col) => quoteIdentifier(col));\n const tableMeta = contract.storage.tables[ast.table.name];\n const values = Object.entries(ast.values).map(([colName, val]) => {\n if (val.kind === 'param') {\n const columnMeta = tableMeta?.columns[colName];\n return renderTypedParam(val.index, columnMeta?.codecId);\n }\n if (val.kind === 'col') {\n return `${quoteIdentifier(val.table)}.${quoteIdentifier(val.column)}`;\n }\n throw new Error(`Unsupported value kind in INSERT: ${(val as { kind: string }).kind}`);\n });\n\n const insertClause =\n columns.length === 0\n ? `INSERT INTO ${table} DEFAULT VALUES`\n : `INSERT INTO ${table} (${columns.join(', ')}) VALUES (${values.join(', ')})`;\n const returningClause = ast.returning?.length\n ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(', ')}`\n : '';\n\n return `${insertClause}${returningClause}`;\n}\n\nfunction renderUpdate(ast: UpdateAst, contract: PostgresContract): string {\n const table = quoteIdentifier(ast.table.name);\n const tableMeta = contract.storage.tables[ast.table.name];\n const setClauses = Object.entries(ast.set).map(([col, val]) => {\n const column = quoteIdentifier(col);\n let value: string;\n if (val.kind === 'param') {\n const columnMeta = tableMeta?.columns[col];\n value = renderTypedParam(val.index, columnMeta?.codecId);\n } else if (val.kind === 'col') {\n value = `${quoteIdentifier(val.table)}.${quoteIdentifier(val.column)}`;\n } else {\n throw new Error(`Unsupported value kind in UPDATE: ${(val as { kind: string }).kind}`);\n }\n return `${column} = ${value}`;\n });\n\n const whereClause = ast.where ? ` WHERE ${renderWhere(ast.where, contract)}` : '';\n const returningClause = ast.returning?.length\n ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(', ')}`\n : '';\n\n return `UPDATE ${table} SET ${setClauses.join(', ')}${whereClause}${returningClause}`;\n}\n\nfunction renderDelete(ast: DeleteAst, contract?: PostgresContract): string {\n const table = quoteIdentifier(ast.table.name);\n const whereClause = ast.where ? ` WHERE ${renderWhere(ast.where, contract)}` : '';\n const returningClause = ast.returning?.length\n ? ` RETURNING ${ast.returning.map((col) => `${quoteIdentifier(col.table)}.${quoteIdentifier(col.column)}`).join(', ')}`\n : '';\n\n return `DELETE FROM ${table}${whereClause}${returningClause}`;\n}\n\nexport function createPostgresAdapter(options?: PostgresAdapterOptions) {\n return Object.freeze(new PostgresAdapterImpl(options));\n}\n"],"mappings":";;;;;;;AA6BA,MAAM,kBAAkB;AAExB,SAAS,kBAAkB,SAAiD;AAC1E,KAAI,YAAY,gBACd,QAAO;AAET,KAAI,YAAY,iBACd,QAAO;AAET,KAAI,YAAY,kBACd,QAAO;;AAKX,SAAS,iBAAiB,OAAe,SAAqC;CAC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