effect-qb 0.13.0 → 0.15.0

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 (146) hide show
  1. package/README.md +6 -1431
  2. package/dist/mysql.js +61945 -3611
  3. package/dist/postgres/metadata.js +2818 -0
  4. package/dist/postgres.js +9942 -5591
  5. package/package.json +21 -10
  6. package/src/internal/aggregation-validation.ts +3 -3
  7. package/src/internal/case-analysis.d.ts +18 -0
  8. package/src/internal/case-analysis.ts +4 -4
  9. package/src/internal/coercion/analysis.d.ts +7 -0
  10. package/src/internal/{coercion-analysis.ts → coercion/analysis.ts} +3 -3
  11. package/src/internal/coercion/errors.d.ts +17 -0
  12. package/src/internal/{coercion-errors.ts → coercion/errors.ts} +1 -1
  13. package/src/internal/coercion/kind.d.ts +4 -0
  14. package/src/internal/{coercion-kind.ts → coercion/kind.ts} +2 -2
  15. package/src/internal/{coercion-normalize.ts → coercion/normalize.ts} +1 -1
  16. package/src/internal/coercion/rules.d.ts +6 -0
  17. package/src/internal/{coercion-rules.ts → coercion/rules.ts} +2 -2
  18. package/src/internal/column-state.d.ts +190 -0
  19. package/src/internal/column-state.ts +119 -56
  20. package/src/internal/column.ts +387 -149
  21. package/src/internal/datatypes/define.d.ts +17 -0
  22. package/src/internal/datatypes/define.ts +18 -34
  23. package/src/internal/datatypes/lookup.d.ts +44 -0
  24. package/src/internal/datatypes/lookup.ts +61 -152
  25. package/src/internal/datatypes/shape.d.ts +16 -0
  26. package/src/internal/datatypes/shape.ts +1 -1
  27. package/src/internal/derived-table.d.ts +4 -0
  28. package/src/internal/derived-table.ts +21 -16
  29. package/src/internal/dsl-mutation-runtime.ts +378 -0
  30. package/src/internal/dsl-plan-runtime.ts +387 -0
  31. package/src/internal/dsl-query-runtime.ts +160 -0
  32. package/src/internal/dsl-transaction-ddl-runtime.ts +263 -0
  33. package/src/internal/executor.ts +173 -38
  34. package/src/internal/expression-ast.ts +19 -5
  35. package/src/internal/grouping-key.d.ts +3 -0
  36. package/src/internal/grouping-key.ts +1 -1
  37. package/src/internal/implication-runtime.d.ts +15 -0
  38. package/src/internal/implication-runtime.ts +171 -0
  39. package/src/internal/json/ast.d.ts +30 -0
  40. package/src/internal/json/ast.ts +1 -1
  41. package/src/internal/json/errors.d.ts +8 -0
  42. package/src/internal/json/path.d.ts +75 -0
  43. package/src/internal/json/path.ts +1 -1
  44. package/src/internal/json/types.d.ts +62 -0
  45. package/src/internal/predicate/analysis.d.ts +20 -0
  46. package/src/internal/{predicate-analysis.ts → predicate/analysis.ts} +13 -3
  47. package/src/internal/predicate/atom.d.ts +28 -0
  48. package/src/internal/{predicate-branches.ts → predicate/branches.ts} +2 -2
  49. package/src/internal/predicate/context.d.ts +67 -0
  50. package/src/internal/{predicate-context.ts → predicate/context.ts} +111 -32
  51. package/src/internal/predicate/formula.d.ts +35 -0
  52. package/src/internal/{predicate-formula.ts → predicate/formula.ts} +32 -20
  53. package/src/internal/predicate/key.d.ts +11 -0
  54. package/src/internal/{predicate-key.ts → predicate/key.ts} +2 -2
  55. package/src/internal/{predicate-nnf.ts → predicate/nnf.ts} +2 -2
  56. package/src/internal/predicate/normalize.d.ts +53 -0
  57. package/src/internal/predicate/normalize.ts +273 -0
  58. package/src/internal/predicate/runtime.d.ts +31 -0
  59. package/src/internal/predicate/runtime.ts +679 -0
  60. package/src/internal/projection-alias.d.ts +13 -0
  61. package/src/internal/projections.d.ts +31 -0
  62. package/src/internal/projections.ts +1 -1
  63. package/src/internal/query-ast.d.ts +217 -0
  64. package/src/internal/query-ast.ts +1 -1
  65. package/src/internal/query-requirements.d.ts +20 -0
  66. package/src/internal/query.d.ts +775 -0
  67. package/src/internal/query.ts +767 -275
  68. package/src/internal/renderer.ts +7 -21
  69. package/src/internal/row-set.d.ts +53 -0
  70. package/src/internal/{plan.ts → row-set.ts} +23 -11
  71. package/src/internal/{runtime-normalize.ts → runtime/normalize.ts} +9 -31
  72. package/src/internal/{runtime-schema.ts → runtime/schema.ts} +84 -55
  73. package/src/internal/runtime/value.d.ts +22 -0
  74. package/src/internal/{runtime-value.ts → runtime/value.ts} +2 -2
  75. package/src/internal/scalar.d.ts +107 -0
  76. package/src/internal/scalar.ts +191 -0
  77. package/src/internal/schema-derivation.d.ts +105 -0
  78. package/src/internal/schema-derivation.ts +93 -21
  79. package/src/internal/schema-expression.d.ts +18 -0
  80. package/src/internal/schema-expression.ts +75 -0
  81. package/src/internal/table-options.d.ts +94 -0
  82. package/src/internal/table-options.ts +94 -8
  83. package/src/internal/table.d.ts +173 -0
  84. package/src/internal/table.ts +135 -54
  85. package/src/mysql/column.ts +95 -18
  86. package/src/mysql/datatypes/index.ts +58 -3
  87. package/src/mysql/errors/generated.ts +57336 -0
  88. package/src/mysql/errors/index.ts +1 -0
  89. package/src/mysql/errors/normalize.ts +55 -53
  90. package/src/mysql/errors/types.ts +74 -0
  91. package/src/mysql/executor.ts +69 -7
  92. package/src/mysql/function/aggregate.ts +1 -5
  93. package/src/mysql/function/core.ts +1 -3
  94. package/src/mysql/function/index.ts +1 -1
  95. package/src/mysql/function/string.ts +1 -5
  96. package/src/mysql/function/temporal.ts +12 -15
  97. package/src/mysql/function/window.ts +1 -6
  98. package/src/{internal/mysql-dialect.ts → mysql/internal/dialect.ts} +1 -1
  99. package/src/mysql/internal/dsl.ts +6115 -0
  100. package/src/{internal/mysql-renderer.ts → mysql/internal/renderer.ts} +6 -6
  101. package/src/mysql/internal/sql-expression-renderer.ts +1455 -0
  102. package/src/mysql/json.ts +2 -0
  103. package/src/mysql/query.ts +111 -86
  104. package/src/mysql/renderer.ts +1 -1
  105. package/src/mysql/table.ts +1 -1
  106. package/src/mysql.ts +6 -4
  107. package/src/postgres/cast.ts +30 -0
  108. package/src/postgres/column.ts +178 -20
  109. package/src/postgres/datatypes/index.d.ts +515 -0
  110. package/src/postgres/datatypes/index.ts +49 -5
  111. package/src/postgres/datatypes/spec.d.ts +412 -0
  112. package/src/postgres/errors/generated.ts +2636 -0
  113. package/src/postgres/errors/index.ts +1 -0
  114. package/src/postgres/errors/normalize.ts +47 -62
  115. package/src/postgres/errors/types.ts +92 -34
  116. package/src/postgres/executor.ts +37 -5
  117. package/src/postgres/function/aggregate.ts +1 -5
  118. package/src/postgres/function/core.ts +20 -2
  119. package/src/postgres/function/index.ts +1 -1
  120. package/src/postgres/function/string.ts +1 -5
  121. package/src/postgres/function/temporal.ts +12 -15
  122. package/src/postgres/function/window.ts +1 -6
  123. package/src/{internal/postgres-dialect.ts → postgres/internal/dialect.ts} +1 -1
  124. package/src/{internal/query-factory.ts → postgres/internal/dsl.ts} +1568 -2120
  125. package/src/{internal/postgres-renderer.ts → postgres/internal/renderer.ts} +6 -6
  126. package/src/postgres/internal/schema-ddl.ts +108 -0
  127. package/src/postgres/internal/schema-model.ts +150 -0
  128. package/src/{internal → postgres/internal}/sql-expression-renderer.ts +112 -46
  129. package/src/postgres/json.ts +493 -0
  130. package/src/postgres/metadata.ts +31 -0
  131. package/src/postgres/query.ts +113 -86
  132. package/src/postgres/renderer.ts +3 -13
  133. package/src/postgres/schema-expression.ts +17 -0
  134. package/src/postgres/schema-management.ts +204 -0
  135. package/src/postgres/schema.ts +35 -0
  136. package/src/postgres/table.ts +316 -42
  137. package/src/postgres/type.ts +31 -0
  138. package/src/postgres.ts +20 -4
  139. package/CHANGELOG.md +0 -134
  140. package/src/internal/expression.ts +0 -327
  141. package/src/internal/predicate-normalize.ts +0 -202
  142. package/src/mysql/function/json.ts +0 -4
  143. package/src/mysql/private/query.ts +0 -13
  144. package/src/postgres/function/json.ts +0 -4
  145. package/src/postgres/private/query.ts +0 -13
  146. /package/src/internal/{predicate-atom.ts → predicate/atom.ts} +0 -0
@@ -0,0 +1,493 @@
1
+ import * as Expression from "../internal/scalar.js"
2
+ import type { JsonPathUsageError } from "../internal/json/errors.js"
3
+ import * as JsonPath from "../internal/json/path.js"
4
+ import type {
5
+ JsonDeleteAtPath,
6
+ JsonInsertAtPath,
7
+ JsonSetAtPath,
8
+ JsonValueAtPath
9
+ } from "../internal/json/types.js"
10
+ import { json as postgresJson, jsonb as postgresJsonb } from "./internal/dsl.js"
11
+
12
+ type PostgresJsonExpression<Runtime = unknown> = Expression.Scalar<
13
+ Runtime,
14
+ Expression.DbType.Json<"postgres", "json" | "jsonb">,
15
+ Expression.Nullability,
16
+ string,
17
+ Expression.ScalarKind,
18
+ Expression.BindingId
19
+ >
20
+
21
+ type PostgresJsonbExpression<Runtime = unknown> = Expression.Scalar<
22
+ Runtime,
23
+ Expression.DbType.Json<"postgres", "jsonb">,
24
+ Expression.Nullability,
25
+ string,
26
+ Expression.ScalarKind,
27
+ Expression.BindingId
28
+ >
29
+
30
+ type ExactJsonPathInput = JsonPath.ExactSegment | JsonPath.Path<any>
31
+
32
+ type ExactJsonPathUsageError<Target> = {
33
+ readonly __effect_qb_error__: "effect-qb: postgres json helpers only accept exact key/index paths"
34
+ readonly __effect_qb_json_path__: Target
35
+ readonly __effect_qb_hint__: "Use Postgres.Json.jsonb.path(...) when you need wildcard(), slice(), or descend() segments"
36
+ }
37
+
38
+ type ExactJsonPathGuard<Target> = Target extends JsonPath.Path<any>
39
+ ? JsonPath.IsExactPath<Target> extends true ? unknown : ExactJsonPathUsageError<Target>
40
+ : Target extends JsonPath.ExactSegment
41
+ ? unknown
42
+ : ExactJsonPathUsageError<Target>
43
+
44
+ type ExactJsonPathSegmentsGuard<Segments extends readonly JsonPath.CanonicalSegment[]> =
45
+ JsonPath.IsExactPath<JsonPath.Path<Segments>> extends true ? unknown : ExactJsonPathUsageError<JsonPath.Path<Segments>>
46
+
47
+ type JsonPathOutputOf<
48
+ Root,
49
+ Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
50
+ Operation extends string
51
+ > = Target extends JsonPath.Path<any>
52
+ ? JsonValueAtPath<Root, Target, Operation>
53
+ : Target extends JsonPath.CanonicalSegment
54
+ ? JsonValueAtPath<Root, JsonPath.Path<[Target]>, Operation>
55
+ : never
56
+
57
+ type JsonDeleteOutputOf<
58
+ Root,
59
+ Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
60
+ Operation extends string
61
+ > = Target extends JsonPath.Path<any>
62
+ ? JsonDeleteAtPath<Root, Target, Operation>
63
+ : Target extends JsonPath.CanonicalSegment
64
+ ? JsonDeleteAtPath<Root, JsonPath.Path<[Target]>, Operation>
65
+ : never
66
+
67
+ type JsonSetOutputOf<
68
+ Root,
69
+ Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
70
+ Next,
71
+ Operation extends string
72
+ > = Target extends JsonPath.Path<any>
73
+ ? JsonSetAtPath<Root, Target, Next, Operation>
74
+ : Target extends JsonPath.CanonicalSegment
75
+ ? JsonSetAtPath<Root, JsonPath.Path<[Target]>, Next, Operation>
76
+ : never
77
+
78
+ type JsonInsertOutputOf<
79
+ Root,
80
+ Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
81
+ Next,
82
+ InsertAfter extends boolean,
83
+ Operation extends string
84
+ > = Target extends JsonPath.Path<any>
85
+ ? JsonInsertAtPath<Root, Target, Next, InsertAfter, Operation>
86
+ : Target extends JsonPath.CanonicalSegment
87
+ ? JsonInsertAtPath<Root, JsonPath.Path<[Target]>, Next, InsertAfter, Operation>
88
+ : never
89
+
90
+ type JsonValuePathGuard<
91
+ Root,
92
+ Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
93
+ Operation extends string
94
+ > = JsonPathOutputOf<Root, Target, Operation> extends JsonPathUsageError<any, any, any, any>
95
+ ? JsonPathOutputOf<Root, Target, Operation>
96
+ : unknown
97
+
98
+ type JsonDeletePathGuard<
99
+ Root,
100
+ Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
101
+ Operation extends string
102
+ > = JsonDeleteOutputOf<Root, Target, Operation> extends JsonPathUsageError<any, any, any, any>
103
+ ? JsonDeleteOutputOf<Root, Target, Operation>
104
+ : unknown
105
+
106
+ type JsonSetPathGuard<
107
+ Root,
108
+ Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
109
+ Next,
110
+ Operation extends string
111
+ > = JsonSetOutputOf<Root, Target, Next, Operation> extends JsonPathUsageError<any, any, any, any>
112
+ ? JsonSetOutputOf<Root, Target, Next, Operation>
113
+ : unknown
114
+
115
+ type JsonInsertPathGuard<
116
+ Root,
117
+ Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
118
+ Next,
119
+ InsertAfter extends boolean,
120
+ Operation extends string
121
+ > = JsonInsertOutputOf<Root, Target, Next, InsertAfter, Operation> extends JsonPathUsageError<any, any, any, any>
122
+ ? JsonInsertOutputOf<Root, Target, Next, InsertAfter, Operation>
123
+ : unknown
124
+
125
+ type JsonbOnlyUsageError<
126
+ Operation extends string,
127
+ Value extends PostgresJsonExpression<any>
128
+ > = {
129
+ readonly __effect_qb_error__: "effect-qb: postgres jsonb helpers require a jsonb expression"
130
+ readonly __effect_qb_json_operation__: Operation
131
+ readonly __effect_qb_received_kind__: Expression.DbTypeOf<Value>["kind"]
132
+ readonly __effect_qb_hint__: "Use Column.jsonb(...), Cast.to(..., Type.jsonb()), or Postgres.Json.jsonb.toJsonb(...)"
133
+ }
134
+
135
+ type JsonbBaseGuard<
136
+ Base extends PostgresJsonExpression<any>,
137
+ Operation extends string
138
+ > = Expression.DbTypeOf<Base> extends Expression.DbType.Json<"postgres", "jsonb">
139
+ ? unknown
140
+ : JsonbOnlyUsageError<Operation, Base>
141
+
142
+ type JsonNullabilityOf<Output> =
143
+ null extends Output
144
+ ? Exclude<Output, null> extends never ? "always" : "maybe"
145
+ : "never"
146
+
147
+ type JsonResultExpression<
148
+ Runtime,
149
+ Db extends Expression.DbType.Json<any, any>
150
+ > = Expression.Scalar<
151
+ Runtime,
152
+ Db,
153
+ JsonNullabilityOf<Runtime>,
154
+ string,
155
+ Expression.ScalarKind,
156
+ Expression.BindingId
157
+ >
158
+
159
+ type JsonDbOf<Base extends PostgresJsonExpression<any>> =
160
+ Expression.DbTypeOf<Base> extends Expression.DbType.Json<"postgres", infer Variant>
161
+ ? Expression.DbType.Json<"postgres", Variant>
162
+ : Expression.DbType.Json<"postgres", "json">
163
+
164
+ type JsonGetResultExpression<
165
+ Base extends PostgresJsonExpression<any>,
166
+ Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment,
167
+ Operation extends string
168
+ > = JsonResultExpression<
169
+ JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, Operation>,
170
+ JsonDbOf<Base>
171
+ >
172
+
173
+ type JsonTextRuntime<
174
+ Base extends PostgresJsonExpression<any>,
175
+ Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment
176
+ > =
177
+ Extract<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.text">, string> |
178
+ (null extends JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.text"> ? null : never)
179
+
180
+ type JsonTextResultExpression<
181
+ Base extends PostgresJsonExpression<any>,
182
+ Target extends JsonPath.Path<any> | JsonPath.CanonicalSegment
183
+ > = Expression.Scalar<
184
+ JsonTextRuntime<Base, Target>,
185
+ Expression.DbType.Base<"postgres", "text">,
186
+ JsonNullabilityOf<JsonTextRuntime<Base, Target>>,
187
+ string,
188
+ Expression.ScalarKind,
189
+ Expression.BindingId
190
+ >
191
+
192
+ const exactPath = <Segments extends readonly JsonPath.CanonicalSegment[]>(
193
+ ...segments: Segments & ExactJsonPathSegmentsGuard<Segments>
194
+ ): JsonPath.Path<Segments> => JsonPath.path(...segments) as unknown as JsonPath.Path<Segments>
195
+
196
+ const jsonGetDirect = <
197
+ Base extends PostgresJsonExpression<any>,
198
+ Target extends ExactJsonPathInput
199
+ >(
200
+ base: Base,
201
+ target: Target & ExactJsonPathGuard<Target>
202
+ ): JsonGetResultExpression<Base, Target, "json.get"> =>
203
+ postgresJson.get(base as never, target as never) as unknown as JsonGetResultExpression<Base, Target, "json.get">
204
+
205
+ const jsonTextDirect = <
206
+ Base extends PostgresJsonExpression<any>,
207
+ Target extends ExactJsonPathInput
208
+ >(
209
+ base: Base,
210
+ target: Target & ExactJsonPathGuard<Target>
211
+ ): JsonTextResultExpression<Base, Target> =>
212
+ postgresJson.text(base as never, target as never) as unknown as JsonTextResultExpression<Base, Target>
213
+
214
+ const json = {
215
+ key: postgresJson.key,
216
+ index: postgresJson.index,
217
+ path: exactPath,
218
+ get: ((...args: [PostgresJsonExpression<any>, ExactJsonPathInput] | [ExactJsonPathInput]) =>
219
+ args.length === 1
220
+ ? ((base: PostgresJsonExpression<any>) => jsonGetDirect(base as never, args[0] as never))
221
+ : jsonGetDirect(args[0] as never, args[1] as never)) as unknown as
222
+ typeof jsonGetDirect & {
223
+ <Target extends ExactJsonPathInput>(
224
+ target: Target & ExactJsonPathGuard<Target>
225
+ ): <Base extends PostgresJsonExpression<any>>(base: Base) => ReturnType<typeof jsonGetDirect>
226
+ },
227
+ access: <
228
+ Base extends PostgresJsonExpression<any>,
229
+ Target extends ExactJsonPathInput
230
+ >(
231
+ base: Base,
232
+ target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.access">
233
+ ) => postgresJson.access(base, target),
234
+ traverse: <
235
+ Base extends PostgresJsonExpression<any>,
236
+ Target extends ExactJsonPathInput
237
+ >(
238
+ base: Base,
239
+ target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverse">
240
+ ) => postgresJson.traverse(base, target),
241
+ text: ((...args: [PostgresJsonExpression<any>, ExactJsonPathInput] | [ExactJsonPathInput]) =>
242
+ args.length === 1
243
+ ? ((base: PostgresJsonExpression<any>) => jsonTextDirect(base as never, args[0] as never))
244
+ : jsonTextDirect(args[0] as never, args[1] as never)) as unknown as
245
+ typeof jsonTextDirect & {
246
+ <Target extends ExactJsonPathInput>(
247
+ target: Target & ExactJsonPathGuard<Target>
248
+ ): <Base extends PostgresJsonExpression<any>>(base: Base) => ReturnType<typeof jsonTextDirect>
249
+ },
250
+ accessText: <
251
+ Base extends PostgresJsonExpression<any>,
252
+ Target extends ExactJsonPathInput
253
+ >(
254
+ base: Base,
255
+ target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.accessText">
256
+ ) => postgresJson.accessText(base, target),
257
+ traverseText: <
258
+ Base extends PostgresJsonExpression<any>,
259
+ Target extends ExactJsonPathInput
260
+ >(
261
+ base: Base,
262
+ target: Target & ExactJsonPathGuard<Target> & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverseText">
263
+ ) => postgresJson.traverseText(base, target),
264
+ buildObject: postgresJson.buildObject,
265
+ buildArray: postgresJson.buildArray,
266
+ toJson: postgresJson.toJson,
267
+ typeOf: postgresJson.typeOf,
268
+ length: postgresJson.length,
269
+ keys: postgresJson.keys,
270
+ stripNulls: postgresJson.stripNulls,
271
+ delete: <
272
+ Base extends PostgresJsonExpression<any>,
273
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
274
+ >(
275
+ base: Base,
276
+ target: Target & JsonDeletePathGuard<Expression.RuntimeOf<Base>, Target, "json.delete">
277
+ ): JsonResultExpression<
278
+ JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
279
+ Expression.DbTypeOf<Base>
280
+ > => postgresJson.delete(base as any, target as any) as unknown as JsonResultExpression<
281
+ JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
282
+ Expression.DbTypeOf<Base>
283
+ >,
284
+ remove: <
285
+ Base extends PostgresJsonExpression<any>,
286
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
287
+ >(
288
+ base: Base,
289
+ target: Target & JsonDeletePathGuard<Expression.RuntimeOf<Base>, Target, "json.remove">
290
+ ): JsonResultExpression<
291
+ JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
292
+ Expression.DbTypeOf<Base>
293
+ > => postgresJson.remove(base as any, target as any) as unknown as JsonResultExpression<
294
+ JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
295
+ Expression.DbTypeOf<Base>
296
+ >
297
+ }
298
+
299
+ const jsonb = {
300
+ key: postgresJsonb.key,
301
+ index: postgresJsonb.index,
302
+ wildcard: postgresJsonb.wildcard,
303
+ slice: postgresJsonb.slice,
304
+ descend: postgresJsonb.descend,
305
+ path: postgresJsonb.path,
306
+ get: <
307
+ Base extends PostgresJsonExpression<any>,
308
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
309
+ >(
310
+ base: Base & JsonbBaseGuard<Base, "jsonb.get">,
311
+ target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.get">
312
+ ) => postgresJsonb.get(base as Base, target),
313
+ access: <
314
+ Base extends PostgresJsonExpression<any>,
315
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
316
+ >(
317
+ base: Base & JsonbBaseGuard<Base, "jsonb.access">,
318
+ target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.access">
319
+ ) => postgresJsonb.access(base as Base, target),
320
+ traverse: <
321
+ Base extends PostgresJsonExpression<any>,
322
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
323
+ >(
324
+ base: Base & JsonbBaseGuard<Base, "jsonb.traverse">,
325
+ target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverse">
326
+ ) => postgresJsonb.traverse(base as Base, target),
327
+ text: <
328
+ Base extends PostgresJsonExpression<any>,
329
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
330
+ >(
331
+ base: Base & JsonbBaseGuard<Base, "jsonb.text">,
332
+ target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.text">
333
+ ) => postgresJsonb.text(base as Base, target),
334
+ accessText: <
335
+ Base extends PostgresJsonExpression<any>,
336
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
337
+ >(
338
+ base: Base & JsonbBaseGuard<Base, "jsonb.accessText">,
339
+ target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.accessText">
340
+ ) => postgresJsonb.accessText(base as Base, target),
341
+ traverseText: <
342
+ Base extends PostgresJsonExpression<any>,
343
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
344
+ >(
345
+ base: Base & JsonbBaseGuard<Base, "jsonb.traverseText">,
346
+ target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.traverseText">
347
+ ) => postgresJsonb.traverseText(base as Base, target),
348
+ contains: <
349
+ Left extends PostgresJsonExpression<any>,
350
+ Right extends Parameters<typeof postgresJsonb.contains>[1]
351
+ >(
352
+ left: Left & JsonbBaseGuard<Left, "jsonb.contains">,
353
+ right: Right
354
+ ) => postgresJsonb.contains(left as Left, right),
355
+ containedBy: <
356
+ Left extends PostgresJsonExpression<any>,
357
+ Right extends Parameters<typeof postgresJsonb.containedBy>[1]
358
+ >(
359
+ left: Left & JsonbBaseGuard<Left, "jsonb.containedBy">,
360
+ right: Right
361
+ ) => postgresJsonb.containedBy(left as Left, right),
362
+ hasKey: <
363
+ Base extends PostgresJsonExpression<any>,
364
+ Key extends string
365
+ >(
366
+ base: Base & JsonbBaseGuard<Base, "jsonb.hasKey">,
367
+ key: Key
368
+ ) => postgresJsonb.hasKey(base as Base, key),
369
+ keyExists: <
370
+ Base extends PostgresJsonExpression<any>,
371
+ Key extends string
372
+ >(
373
+ base: Base & JsonbBaseGuard<Base, "jsonb.keyExists">,
374
+ key: Key
375
+ ) => postgresJsonb.keyExists(base as Base, key),
376
+ hasAnyKeys: <
377
+ Base extends PostgresJsonExpression<any>,
378
+ Keys extends readonly [string, ...string[]]
379
+ >(
380
+ base: Base & JsonbBaseGuard<Base, "jsonb.hasAnyKeys">,
381
+ ...keys: Keys
382
+ ) => postgresJsonb.hasAnyKeys(base as Base, ...keys),
383
+ hasAllKeys: <
384
+ Base extends PostgresJsonExpression<any>,
385
+ Keys extends readonly [string, ...string[]]
386
+ >(
387
+ base: Base & JsonbBaseGuard<Base, "jsonb.hasAllKeys">,
388
+ ...keys: Keys
389
+ ) => postgresJsonb.hasAllKeys(base as Base, ...keys),
390
+ delete: <
391
+ Base extends PostgresJsonExpression<any>,
392
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
393
+ >(
394
+ base: Base & JsonbBaseGuard<Base, "jsonb.delete">,
395
+ target: Target & JsonDeletePathGuard<Expression.RuntimeOf<Base>, Target, "json.delete">
396
+ ): JsonResultExpression<
397
+ JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
398
+ Expression.DbTypeOf<Base>
399
+ > => postgresJsonb.delete(base as any, target as any) as unknown as JsonResultExpression<
400
+ JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
401
+ Expression.DbTypeOf<Base>
402
+ >,
403
+ remove: <
404
+ Base extends PostgresJsonExpression<any>,
405
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>
406
+ >(
407
+ base: Base & JsonbBaseGuard<Base, "jsonb.remove">,
408
+ target: Target & JsonDeletePathGuard<Expression.RuntimeOf<Base>, Target, "json.remove">
409
+ ): JsonResultExpression<
410
+ JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
411
+ Expression.DbTypeOf<Base>
412
+ > => postgresJsonb.remove(base as any, target as any) as unknown as JsonResultExpression<
413
+ JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.remove">,
414
+ Expression.DbTypeOf<Base>
415
+ >,
416
+ set: <
417
+ Base extends PostgresJsonExpression<any>,
418
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>,
419
+ Next extends Parameters<typeof postgresJsonb.set>[2]
420
+ >(
421
+ base: Base & JsonbBaseGuard<Base, "jsonb.set">,
422
+ target: Target & JsonSetPathGuard<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
423
+ next: Next,
424
+ options?: Parameters<typeof postgresJsonb.set>[3]
425
+ ): JsonResultExpression<
426
+ JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
427
+ Expression.DbTypeOf<Base>
428
+ > => postgresJsonb.set(base as any, target as any, next, options) as unknown as JsonResultExpression<
429
+ JsonSetOutputOf<Expression.RuntimeOf<Base>, Target, Next, "json.set">,
430
+ Expression.DbTypeOf<Base>
431
+ >,
432
+ insert: <
433
+ Base extends PostgresJsonExpression<any>,
434
+ Target extends JsonPath.CanonicalSegment | JsonPath.Path<any>,
435
+ Next extends Parameters<typeof postgresJsonb.insert>[2],
436
+ InsertAfter extends boolean = false
437
+ >(
438
+ base: Base & JsonbBaseGuard<Base, "jsonb.insert">,
439
+ target: Target & JsonInsertPathGuard<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
440
+ next: Next,
441
+ options?: {
442
+ readonly insertAfter?: InsertAfter
443
+ }
444
+ ): JsonResultExpression<
445
+ JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
446
+ Expression.DbTypeOf<Base>
447
+ > => postgresJsonb.insert(base as any, target as any, next, options) as unknown as JsonResultExpression<
448
+ JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
449
+ Expression.DbTypeOf<Base>
450
+ >,
451
+ concat: postgresJsonb.concat,
452
+ merge: postgresJsonb.merge,
453
+ buildObject: postgresJsonb.buildObject,
454
+ buildArray: postgresJsonb.buildArray,
455
+ toJsonb: postgresJsonb.toJsonb,
456
+ typeOf: <
457
+ Base extends PostgresJsonExpression<any>
458
+ >(
459
+ base: Base & JsonbBaseGuard<Base, "jsonb.typeOf">
460
+ ) => postgresJsonb.typeOf(base as Base),
461
+ length: <
462
+ Base extends PostgresJsonExpression<any>
463
+ >(
464
+ base: Base & JsonbBaseGuard<Base, "jsonb.length">
465
+ ) => postgresJsonb.length(base as Base),
466
+ keys: <
467
+ Base extends PostgresJsonExpression<any>
468
+ >(
469
+ base: Base & JsonbBaseGuard<Base, "jsonb.keys">
470
+ ) => postgresJsonb.keys(base as Base),
471
+ stripNulls: <
472
+ Base extends PostgresJsonExpression<any>
473
+ >(
474
+ base: Base & JsonbBaseGuard<Base, "jsonb.stripNulls">
475
+ ) => postgresJsonb.stripNulls(base as Base),
476
+ pathExists: <
477
+ Base extends PostgresJsonExpression<any>
478
+ >(
479
+ base: Base & JsonbBaseGuard<Base, "jsonb.pathExists">,
480
+ query: Parameters<typeof postgresJsonb.pathExists>[1]
481
+ ) => postgresJsonb.pathExists(base as Base, query),
482
+ pathMatch: <
483
+ Base extends PostgresJsonExpression<any>
484
+ >(
485
+ base: Base & JsonbBaseGuard<Base, "jsonb.pathMatch">,
486
+ query: Parameters<typeof postgresJsonb.pathMatch>[1]
487
+ ) => postgresJsonb.pathMatch(base as Base, query)
488
+ }
489
+
490
+ /** Postgres shared JSON helpers for exact paths and functions that work on both json and jsonb. */
491
+ export { json }
492
+ /** Postgres jsonb-only helpers for containment, mutation, wildcard paths, and SQL/JSON path predicates. */
493
+ export { jsonb }
@@ -0,0 +1,31 @@
1
+ export {
2
+ fromDiscoveredValues,
3
+ isEnumDefinition,
4
+ isTableDefinition,
5
+ tableKey,
6
+ enumKey,
7
+ toEnumModel,
8
+ toTableModel,
9
+ type ColumnModel,
10
+ type EnumModel,
11
+ type SchemaModel,
12
+ type TableModel
13
+ } from "./internal/schema-model.js"
14
+
15
+ export {
16
+ EnumTypeId,
17
+ type AnyDefinition,
18
+ type EnumDefinition
19
+ } from "../postgres/schema-management.js"
20
+
21
+ export type {
22
+ DdlExpressionLike,
23
+ IndexKeySpec,
24
+ ReferentialAction,
25
+ TableOptionSpec
26
+ } from "../internal/table-options.js"
27
+
28
+ export {
29
+ normalizeDdlExpressionSql,
30
+ renderDdlExpressionSql
31
+ } from "./internal/schema-ddl.js"