effect-qb 4.0.0-beta.66 → 4.0.0-beta.98

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 (129) hide show
  1. package/README.md +5 -2
  2. package/dist/index.js +9376 -0
  3. package/dist/mysql.js +3921 -2573
  4. package/dist/postgres/metadata.js +2491 -1373
  5. package/dist/postgres.js +5453 -5155
  6. package/dist/sqlite.js +6895 -5529
  7. package/dist/standard.js +9330 -0
  8. package/package.json +9 -2
  9. package/src/casing.ts +71 -0
  10. package/src/index.ts +2 -0
  11. package/src/internal/casing.ts +89 -0
  12. package/src/internal/coercion/rules.ts +13 -1
  13. package/src/internal/column-state.ts +21 -15
  14. package/src/internal/column.ts +44 -7
  15. package/src/internal/datatypes/define.ts +7 -1
  16. package/src/internal/datatypes/enrich.ts +23 -0
  17. package/src/internal/datatypes/lookup.ts +81 -25
  18. package/src/internal/datatypes/matrix.ts +903 -0
  19. package/src/internal/datatypes/shape.ts +2 -0
  20. package/src/internal/derived-table.ts +4 -36
  21. package/src/{mysql/internal/sql-expression-renderer.ts → internal/dialect-renderers/mysql.ts} +552 -361
  22. package/src/{postgres/internal/sql-expression-renderer.ts → internal/dialect-renderers/postgres.ts} +657 -400
  23. package/src/{sqlite/internal/sql-expression-renderer.ts → internal/dialect-renderers/sqlite.ts} +505 -347
  24. package/src/internal/dialect.ts +35 -0
  25. package/src/internal/dsl-mutation-runtime.ts +12 -162
  26. package/src/internal/dsl-plan-runtime.ts +10 -138
  27. package/src/internal/dsl-query-runtime.ts +5 -79
  28. package/src/internal/dsl-transaction-ddl-runtime.ts +41 -65
  29. package/src/internal/executor.ts +14 -16
  30. package/src/internal/grouping-key.ts +87 -20
  31. package/src/internal/implication-runtime.ts +1 -1
  32. package/src/internal/json/path-access.ts +351 -0
  33. package/src/internal/predicate/runtime.ts +3 -0
  34. package/src/internal/query.d.ts +38 -11
  35. package/src/internal/query.ts +64 -25
  36. package/src/internal/renderer.ts +26 -14
  37. package/src/internal/runtime/normalize.ts +12 -5
  38. package/src/internal/scalar.ts +7 -1
  39. package/src/internal/schema-derivation.d.ts +7 -7
  40. package/src/internal/schema-derivation.ts +9 -9
  41. package/src/internal/schema-expression.ts +2 -2
  42. package/src/internal/sql-expression-renderer.ts +19 -0
  43. package/src/internal/standard-dsl.ts +6978 -0
  44. package/src/internal/table-options.ts +126 -66
  45. package/src/internal/table.ts +652 -219
  46. package/src/mysql/column-extension.ts +3 -0
  47. package/src/mysql/column.ts +8 -9
  48. package/src/mysql/datatypes/index.ts +4 -2
  49. package/src/mysql/datatypes/spec.ts +6 -176
  50. package/src/mysql/errors/normalize.ts +0 -1
  51. package/src/mysql/executor.ts +7 -7
  52. package/src/mysql/internal/dialect.ts +9 -4
  53. package/src/mysql/internal/dsl.ts +312 -154
  54. package/src/mysql/internal/renderer.ts +6 -2
  55. package/src/mysql/json.ts +7 -2
  56. package/src/mysql/query-extension.ts +16 -0
  57. package/src/mysql/renderer.ts +37 -3
  58. package/src/mysql/type.ts +60 -0
  59. package/src/mysql.ts +7 -13
  60. package/src/postgres/check.ts +1 -0
  61. package/src/postgres/column-extension.ts +28 -0
  62. package/src/postgres/column.ts +2 -8
  63. package/src/postgres/datatypes/index.d.ts +2 -1
  64. package/src/postgres/datatypes/index.ts +4 -2
  65. package/src/postgres/datatypes/spec.ts +6 -260
  66. package/src/postgres/errors/normalize.ts +0 -1
  67. package/src/postgres/executor.ts +7 -7
  68. package/src/postgres/foreign-key.ts +24 -0
  69. package/src/postgres/function/core.ts +1 -3
  70. package/src/postgres/function/index.ts +1 -17
  71. package/src/postgres/index.ts +1 -0
  72. package/src/postgres/internal/dialect.ts +9 -4
  73. package/src/postgres/internal/dsl.ts +306 -163
  74. package/src/postgres/internal/renderer.ts +6 -2
  75. package/src/postgres/internal/schema-ddl.ts +22 -10
  76. package/src/postgres/internal/schema-model.ts +238 -7
  77. package/src/postgres/json-extension.ts +7 -0
  78. package/src/postgres/json.ts +762 -173
  79. package/src/postgres/jsonb.ts +37 -0
  80. package/src/postgres/primary-key.ts +24 -0
  81. package/src/postgres/query-extension.ts +2 -0
  82. package/src/postgres/renderer.ts +37 -3
  83. package/src/postgres/schema-management.ts +12 -11
  84. package/src/postgres/schema.ts +106 -15
  85. package/src/postgres/table.ts +205 -530
  86. package/src/postgres/type.ts +93 -10
  87. package/src/postgres/unique.ts +32 -0
  88. package/src/postgres.ts +20 -16
  89. package/src/sqlite/column-extension.ts +3 -0
  90. package/src/sqlite/column.ts +8 -9
  91. package/src/sqlite/datatypes/index.ts +4 -2
  92. package/src/sqlite/datatypes/spec.ts +6 -94
  93. package/src/sqlite/errors/normalize.ts +0 -1
  94. package/src/sqlite/executor.ts +7 -7
  95. package/src/sqlite/internal/dialect.ts +9 -4
  96. package/src/sqlite/internal/dsl.ts +301 -154
  97. package/src/sqlite/internal/renderer.ts +6 -2
  98. package/src/sqlite/json.ts +8 -2
  99. package/src/sqlite/query-extension.ts +2 -0
  100. package/src/sqlite/renderer.ts +37 -3
  101. package/src/sqlite/type.ts +40 -0
  102. package/src/sqlite.ts +7 -13
  103. package/src/standard/cast.ts +113 -0
  104. package/src/standard/check.ts +17 -0
  105. package/src/standard/column.ts +163 -0
  106. package/src/standard/datatypes/index.ts +83 -0
  107. package/src/standard/datatypes/spec.ts +12 -0
  108. package/src/standard/dialect.ts +40 -0
  109. package/src/standard/foreign-key.ts +37 -0
  110. package/src/standard/function/aggregate.ts +2 -0
  111. package/src/standard/function/core.ts +2 -0
  112. package/src/standard/function/index.ts +18 -0
  113. package/src/standard/function/string.ts +2 -0
  114. package/src/standard/function/temporal.ts +78 -0
  115. package/src/standard/function/window.ts +2 -0
  116. package/src/standard/index.ts +17 -0
  117. package/src/standard/internal/renderer.ts +45 -0
  118. package/src/standard/json.ts +883 -0
  119. package/src/standard/primary-key.ts +17 -0
  120. package/src/standard/query.ts +152 -0
  121. package/src/standard/renderer.ts +49 -0
  122. package/src/standard/table.ts +151 -0
  123. package/src/standard/unique.ts +17 -0
  124. package/src/standard.ts +32 -0
  125. package/src/internal/aggregation-validation.ts +0 -57
  126. package/src/internal/table.d.ts +0 -180
  127. package/src/mysql/table.ts +0 -186
  128. package/src/postgres/cast.ts +0 -45
  129. package/src/sqlite/table.ts +0 -175
@@ -0,0 +1,883 @@
1
+ import * as Expression from "../internal/scalar.js"
2
+ import * as ExpressionAst from "../internal/expression-ast.js"
3
+ import type { JsonPathUsageError } from "../internal/json/errors.js"
4
+ import * as JsonPath from "../internal/json/path.js"
5
+ import type {
6
+ JsonDeleteAtPath,
7
+ JsonInsertAtPath,
8
+ JsonSetAtPath,
9
+ JsonTextResult as JsonTextRuntimeResult,
10
+ JsonValueAtPath
11
+ } from "../internal/json/types.js"
12
+ import type { LiteralStringInput } from "../internal/table-options.js"
13
+ import type { JsonObjectKeyOf, WithJsonPathAccess } from "../internal/json/path-access.js"
14
+ import type { standardDatatypes } from "./datatypes/index.js"
15
+ import { json as standardJson } from "../internal/standard-dsl.js"
16
+
17
+ type JsonExpression<Runtime = unknown> = Expression.Scalar<
18
+ Runtime,
19
+ Expression.DbType.Json<any, any>,
20
+ Expression.Nullability,
21
+ string,
22
+ Expression.ScalarKind,
23
+ Expression.BindingId
24
+ >
25
+
26
+ type JsonPathInput = JsonPath.CanonicalSegment | JsonPath.Path<any>
27
+
28
+ type TextDb = ReturnType<typeof standardDatatypes.text>
29
+ type BoolDb = ReturnType<typeof standardDatatypes.boolean>
30
+ type DialectOf<Value extends Expression.Any> = Value[typeof Expression.TypeId]["dialect"]
31
+
32
+ type JsonPathPredicateExpression = Expression.Scalar<
33
+ string | null,
34
+ Expression.DbType.Any,
35
+ Expression.Nullability,
36
+ string,
37
+ Expression.ScalarKind,
38
+ Expression.BindingId
39
+ >
40
+
41
+ type JsonPathPredicateQuery = JsonPath.Path<any> | JsonPathPredicateExpression | string
42
+
43
+ type JsonPathPredicateQueryInput<Query extends JsonPathPredicateQuery> =
44
+ Query extends string ? LiteralStringInput<Query> : Query
45
+
46
+ type JsonPathExistsQuery = JsonPathInput | JsonPathPredicateQuery
47
+
48
+ type JsonPathExistsQueryInput<Query extends JsonPathExistsQuery> =
49
+ Query extends string ? LiteralStringInput<Query> : Query
50
+
51
+ type SegmentTuple<Segments> = Segments extends readonly JsonPath.CanonicalSegment[]
52
+ ? Segments
53
+ : readonly JsonPath.CanonicalSegment[]
54
+
55
+ type JsonPathSegmentsOf<Target extends JsonPathInput> =
56
+ Target extends JsonPath.Path<infer Segments extends readonly JsonPath.CanonicalSegment[]> ? Segments :
57
+ Target extends JsonPath.CanonicalSegment ? readonly [Target] :
58
+ readonly []
59
+
60
+ type JsonPathOutputOf<
61
+ Root,
62
+ Target extends JsonPathInput,
63
+ Operation extends string
64
+ > = Target extends JsonPath.Path<any>
65
+ ? JsonValueAtPath<Root, Target, Operation>
66
+ : Target extends JsonPath.CanonicalSegment
67
+ ? JsonValueAtPath<Root, JsonPath.Path<[Target]>, Operation>
68
+ : never
69
+
70
+ type JsonDeleteOutputOf<
71
+ Root,
72
+ Target extends JsonPathInput,
73
+ Operation extends string
74
+ > = Target extends JsonPath.Path<any>
75
+ ? JsonDeleteAtPath<Root, Target, Operation>
76
+ : Target extends JsonPath.CanonicalSegment
77
+ ? JsonDeleteAtPath<Root, JsonPath.Path<[Target]>, Operation>
78
+ : never
79
+
80
+ type JsonSetOutputOf<
81
+ Root,
82
+ Target extends JsonPathInput,
83
+ Next,
84
+ Operation extends string
85
+ > = Target extends JsonPath.Path<any>
86
+ ? JsonSetAtPath<Root, Target, Next, Operation>
87
+ : Target extends JsonPath.CanonicalSegment
88
+ ? JsonSetAtPath<Root, JsonPath.Path<[Target]>, Next, Operation>
89
+ : never
90
+
91
+ type JsonSetOutputWithCreateMissing<
92
+ Root,
93
+ Target extends JsonPathInput,
94
+ Next,
95
+ Operation extends string,
96
+ CreateMissing extends boolean
97
+ > = false extends CreateMissing
98
+ ? Root | JsonSetOutputOf<Root, Target, Next, Operation>
99
+ : JsonSetOutputOf<Root, Target, Next, Operation>
100
+
101
+ type JsonInsertOutputOf<
102
+ Root,
103
+ Target extends JsonPathInput,
104
+ Next,
105
+ InsertAfter extends boolean,
106
+ Operation extends string
107
+ > = Target extends JsonPath.Path<any>
108
+ ? JsonInsertAtPath<Root, Target, Next, InsertAfter, Operation>
109
+ : Target extends JsonPath.CanonicalSegment
110
+ ? JsonInsertAtPath<Root, JsonPath.Path<[Target]>, Next, InsertAfter, Operation>
111
+ : never
112
+
113
+ type JsonValuePathGuard<
114
+ Root,
115
+ Target extends JsonPathInput,
116
+ Operation extends string
117
+ > = JsonPathOutputOf<Root, Target, Operation> extends JsonPathUsageError<any, any, any, any>
118
+ ? JsonPathOutputOf<Root, Target, Operation>
119
+ : unknown
120
+
121
+ type JsonDeletePathGuard<
122
+ Root,
123
+ Target extends JsonPathInput,
124
+ Operation extends string
125
+ > = JsonDeleteOutputOf<Root, Target, Operation> extends JsonPathUsageError<any, any, any, any>
126
+ ? JsonDeleteOutputOf<Root, Target, Operation>
127
+ : unknown
128
+
129
+ type JsonSetPathGuard<
130
+ Root,
131
+ Target extends JsonPathInput,
132
+ Next,
133
+ Operation extends string
134
+ > = JsonSetOutputOf<Root, Target, Next, Operation> extends JsonPathUsageError<any, any, any, any>
135
+ ? JsonSetOutputOf<Root, Target, Next, Operation>
136
+ : unknown
137
+
138
+ type JsonInsertPathGuard<
139
+ Root,
140
+ Target extends JsonPathInput,
141
+ Next,
142
+ InsertAfter extends boolean,
143
+ Operation extends string
144
+ > = JsonInsertOutputOf<Root, Target, Next, InsertAfter, Operation> extends JsonPathUsageError<any, any, any, any>
145
+ ? JsonInsertOutputOf<Root, Target, Next, InsertAfter, Operation>
146
+ : unknown
147
+
148
+ type JsonMutationPathUsageError<Target, Operation extends string> = {
149
+ readonly __effect_qb_error__: "effect-qb: json mutation helpers only accept exact key/index paths"
150
+ readonly __effect_qb_operation__: Operation
151
+ readonly __effect_qb_json_path__: Target
152
+ }
153
+
154
+ type ExactJsonPathGuard<Target, Operation extends string> = Target extends JsonPath.Path<any>
155
+ ? JsonPath.IsExactPath<Target> extends true ? unknown : JsonMutationPathUsageError<Target, Operation>
156
+ : Target extends JsonPath.ExactSegment
157
+ ? unknown
158
+ : JsonMutationPathUsageError<Target, Operation>
159
+
160
+ type JsonKindOf<Value extends Expression.Any> = Expression.KindOf<Value>
161
+
162
+ type JsonAccessKind<Target extends JsonPathInput> =
163
+ Target extends JsonPath.Path<any>
164
+ ? JsonPath.IsExactPath<Target> extends true ? "jsonPath" : "jsonTraverse"
165
+ : Target extends JsonPath.ExactSegment ? "jsonGet" : "jsonAccess"
166
+
167
+ type JsonTextAccessKind<Target extends JsonPathInput> =
168
+ Target extends JsonPath.Path<any>
169
+ ? JsonPath.IsExactPath<Target> extends true ? "jsonPathText" : "jsonTraverseText"
170
+ : Target extends JsonPath.ExactSegment ? "jsonGetText" : "jsonAccessText"
171
+
172
+ type JsonDbOf<Base extends JsonExpression<any>> =
173
+ Expression.DbTypeOf<Base> extends Expression.DbType.Json<infer Dialect, infer Variant>
174
+ ? Expression.DbType.Json<Dialect, Variant>
175
+ : Expression.DbType.Json
176
+
177
+ type JsonResultExpression<
178
+ Runtime,
179
+ Db extends Expression.DbType.Json<any, any>,
180
+ Kind extends Expression.ScalarKind = Expression.ScalarKind,
181
+ Dependencies extends Expression.BindingId = Expression.BindingId,
182
+ Ast extends ExpressionAst.Any = never,
183
+ Dialect extends string = string
184
+ > = Expression.Scalar<
185
+ Runtime,
186
+ Db,
187
+ Expression.Nullability,
188
+ Dialect,
189
+ Kind,
190
+ Dependencies
191
+ > & ([Ast] extends [never] ? unknown : {
192
+ readonly [ExpressionAst.TypeId]: Ast
193
+ })
194
+
195
+ type JsonGetResultExpression<
196
+ Base extends JsonExpression<any>,
197
+ Target extends JsonPathInput,
198
+ Operation extends string
199
+ > = WithJsonPathAccess<JsonResultExpression<
200
+ JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, Operation>,
201
+ JsonDbOf<Base>,
202
+ Expression.KindOf<Base>,
203
+ Expression.DependenciesOf<Base>,
204
+ ExpressionAst.JsonAccessNode<JsonAccessKind<Target>, Base, JsonPathSegmentsOf<Target>>,
205
+ DialectOf<Base>
206
+ >>
207
+
208
+ type JsonTextRuntime<
209
+ Base extends JsonExpression<any>,
210
+ Target extends JsonPathInput
211
+ > =
212
+ JsonTextRuntimeResult<Exclude<JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.text">, JsonPathUsageError<any, any, any, any> | null>> |
213
+ (null extends JsonPathOutputOf<Expression.RuntimeOf<Base>, Target, "json.text"> ? null : never)
214
+
215
+ type JsonTextResultExpression<
216
+ Base extends JsonExpression<any>,
217
+ Target extends JsonPathInput
218
+ > = Expression.Scalar<
219
+ JsonTextRuntime<Base, Target>,
220
+ TextDb,
221
+ Expression.Nullability,
222
+ DialectOf<Base>,
223
+ JsonKindOf<Base>,
224
+ Expression.DependenciesOf<Base>
225
+ > & {
226
+ readonly [ExpressionAst.TypeId]: ExpressionAst.JsonAccessNode<JsonTextAccessKind<Target>, Base, JsonPathSegmentsOf<Target>>
227
+ }
228
+
229
+ type JsonTextTerminalExpression<
230
+ Base extends JsonExpression<any>
231
+ > = Expression.Scalar<
232
+ string | null,
233
+ TextDb,
234
+ Expression.Nullability,
235
+ DialectOf<Base>,
236
+ JsonKindOf<Base>,
237
+ Expression.DependenciesOf<Base>
238
+ >
239
+
240
+ type JsonDeleteResultExpression<
241
+ Base extends JsonExpression<any>,
242
+ Target extends JsonPathInput
243
+ > = WithJsonPathAccess<JsonResultExpression<
244
+ JsonDeleteOutputOf<Expression.RuntimeOf<Base>, Target, "json.delete">,
245
+ JsonDbOf<Base>,
246
+ JsonKindOf<Base>,
247
+ Expression.DependenciesOf<Base>,
248
+ never,
249
+ DialectOf<Base>
250
+ >>
251
+
252
+ type JsonDeleteTerminalExpression<
253
+ Base extends JsonExpression<any>
254
+ > = WithJsonPathAccess<JsonResultExpression<
255
+ unknown,
256
+ JsonDbOf<Base>,
257
+ JsonKindOf<Base>,
258
+ Expression.DependenciesOf<Base>,
259
+ never,
260
+ DialectOf<Base>
261
+ >>
262
+
263
+ type JsonPredicateExpression<
264
+ Base extends Expression.Any
265
+ > = Expression.Scalar<
266
+ boolean,
267
+ BoolDb,
268
+ "never",
269
+ DialectOf<Base>,
270
+ JsonKindOf<Base>,
271
+ Expression.DependenciesOf<Base>
272
+ >
273
+
274
+ type JsonAccessAst<Value> = Value extends {
275
+ readonly [ExpressionAst.TypeId]: infer Ast
276
+ } ? Ast : never
277
+
278
+ type JsonAccessExpression = {
279
+ readonly [ExpressionAst.TypeId]: ExpressionAst.JsonAccessNode<any, any, any>
280
+ }
281
+
282
+ type NotJsonAccess<Value> = Value extends JsonAccessExpression ? never : unknown
283
+
284
+ type JsonAccessParts<
285
+ Value,
286
+ Acc extends readonly JsonPath.CanonicalSegment[] = readonly [],
287
+ Depth extends readonly unknown[] = []
288
+ > =
289
+ Depth["length"] extends 8 ? readonly [Value, readonly JsonPath.CanonicalSegment[]] :
290
+ [JsonAccessAst<Value>] extends [never]
291
+ ? Acc extends readonly [] ? never : readonly [Value, Acc]
292
+ : JsonAccessAst<Value> extends ExpressionAst.JsonAccessNode<any, infer Base extends Expression.Any, infer Segments>
293
+ ? JsonAccessParts<Base, readonly [...SegmentTuple<Segments>, ...Acc], readonly [...Depth, unknown]>
294
+ : Acc extends readonly [] ? never : readonly [Value, Acc]
295
+
296
+ type JsonAccessRoot<Value> =
297
+ JsonAccessParts<Value> extends readonly [infer Base, readonly JsonPath.CanonicalSegment[]]
298
+ ? Base
299
+ : Value
300
+
301
+ type JsonAccessSegments<Value> =
302
+ JsonAccessParts<Value> extends readonly [any, infer Segments extends readonly JsonPath.CanonicalSegment[]]
303
+ ? Segments
304
+ : never
305
+
306
+ type JsonAccessPath<Value> = JsonPath.Path<JsonAccessSegments<Value>>
307
+
308
+ type JsonAccessBase<Value extends Expression.Any> =
309
+ [JsonAccessSegments<Value>] extends [never]
310
+ ? Value
311
+ : JsonAccessRoot<Value> extends Expression.Any
312
+ ? JsonAccessRoot<Value>
313
+ : Value
314
+
315
+ type JsonTextValueRuntime<Value extends Expression.Any> =
316
+ (Exclude<Expression.RuntimeOf<Value>, JsonPathUsageError<any, any, any, any> | null> extends infer Runtime
317
+ ? Runtime extends string ? Runtime : string
318
+ : string) |
319
+ (null extends Expression.RuntimeOf<Value> ? null : never)
320
+
321
+ type JsonTextValueNullability<Value extends Expression.Any> =
322
+ null extends JsonTextValueRuntime<Value> ? "maybe" : "never"
323
+
324
+ type JsonAccessTextResultExpression<Value extends JsonExpression<any>> =
325
+ Value extends JsonAccessExpression
326
+ ? Expression.Scalar<
327
+ JsonTextValueRuntime<Value>,
328
+ TextDb,
329
+ JsonTextValueNullability<Value>,
330
+ DialectOf<Value>,
331
+ JsonKindOf<Value>,
332
+ Expression.DependenciesOf<Value>
333
+ > & {
334
+ readonly [ExpressionAst.TypeId]: ExpressionAst.JsonAccessNode<
335
+ "jsonPathText",
336
+ JsonAccessBase<Value>,
337
+ JsonAccessSegments<Value>
338
+ >
339
+ }
340
+ : JsonTextTerminalExpression<Value>
341
+
342
+ type JsonAccessGetResultExpression<
343
+ Value extends JsonExpression<any>,
344
+ Operation extends string
345
+ > = Value extends JsonAccessExpression
346
+ ? JsonAccessRoot<Value> extends JsonExpression<any>
347
+ ? JsonGetResultExpression<JsonAccessRoot<Value>, JsonAccessPath<Value>, Operation>
348
+ : never
349
+ : Value
350
+
351
+ type JsonAccessDeleteResultExpression<
352
+ Value extends JsonExpression<any>,
353
+ Operation extends string
354
+ > = Value extends JsonAccessExpression
355
+ ? JsonAccessRoot<Value> extends JsonExpression<any>
356
+ ? WithJsonPathAccess<JsonResultExpression<
357
+ JsonDeleteOutputOf<Expression.RuntimeOf<JsonAccessRoot<Value>>, JsonAccessPath<Value>, Operation>,
358
+ JsonDbOf<JsonAccessRoot<Value>>,
359
+ JsonKindOf<JsonAccessRoot<Value>>,
360
+ Expression.DependenciesOf<JsonAccessRoot<Value>>,
361
+ never,
362
+ DialectOf<JsonAccessRoot<Value>>
363
+ >>
364
+ : never
365
+ : JsonDeleteTerminalExpression<Value>
366
+
367
+ type JsonAccessSetResultExpression<
368
+ Value extends JsonExpression<any>,
369
+ Next,
370
+ CreateMissing extends boolean
371
+ > = Value extends JsonAccessExpression
372
+ ? JsonAccessRoot<Value> extends JsonExpression<any>
373
+ ? WithJsonPathAccess<JsonResultExpression<
374
+ JsonSetOutputWithCreateMissing<Expression.RuntimeOf<JsonAccessRoot<Value>>, JsonAccessPath<Value>, Next, "json.set", CreateMissing>,
375
+ JsonDbOf<JsonAccessRoot<Value>>,
376
+ JsonKindOf<JsonAccessRoot<Value>>,
377
+ Expression.DependenciesOf<JsonAccessRoot<Value>>,
378
+ never,
379
+ DialectOf<JsonAccessRoot<Value>>
380
+ >>
381
+ : never
382
+ : WithJsonPathAccess<JsonResultExpression<
383
+ unknown,
384
+ JsonDbOf<Value>,
385
+ JsonKindOf<Value>,
386
+ Expression.DependenciesOf<Value>,
387
+ never,
388
+ DialectOf<Value>
389
+ >>
390
+
391
+ type JsonAccessInsertResultExpression<
392
+ Value extends JsonExpression<any>,
393
+ Next,
394
+ InsertAfter extends boolean
395
+ > = Value extends JsonAccessExpression
396
+ ? JsonAccessRoot<Value> extends JsonExpression<any>
397
+ ? WithJsonPathAccess<JsonResultExpression<
398
+ JsonInsertOutputOf<Expression.RuntimeOf<JsonAccessRoot<Value>>, JsonAccessPath<Value>, Next, InsertAfter, "json.insert">,
399
+ JsonDbOf<JsonAccessRoot<Value>>,
400
+ JsonKindOf<JsonAccessRoot<Value>>,
401
+ Expression.DependenciesOf<JsonAccessRoot<Value>>,
402
+ never,
403
+ DialectOf<JsonAccessRoot<Value>>
404
+ >>
405
+ : never
406
+ : WithJsonPathAccess<JsonResultExpression<
407
+ unknown,
408
+ JsonDbOf<Value>,
409
+ JsonKindOf<Value>,
410
+ Expression.DependenciesOf<Value>,
411
+ never,
412
+ DialectOf<Value>
413
+ >>
414
+
415
+ type JsonAccessDeleteGuard<
416
+ Value,
417
+ Operation extends "json.delete" | "json.remove"
418
+ > = Value extends JsonExpression<any>
419
+ ? Value extends JsonAccessExpression
420
+ ? JsonAccessRoot<Value> extends JsonExpression<any>
421
+ ? ExactJsonPathGuard<JsonAccessPath<Value>, Operation> &
422
+ JsonDeletePathGuard<Expression.RuntimeOf<JsonAccessRoot<Value>>, JsonAccessPath<Value>, Operation>
423
+ : unknown
424
+ : unknown
425
+ : unknown
426
+
427
+ type JsonAccessSetGuard<
428
+ Value,
429
+ Next,
430
+ CreateMissing extends boolean
431
+ > = Value extends JsonExpression<any>
432
+ ? Value extends JsonAccessExpression
433
+ ? JsonAccessRoot<Value> extends JsonExpression<any>
434
+ ? ExactJsonPathGuard<JsonAccessPath<Value>, "json.set"> &
435
+ JsonSetPathGuard<Expression.RuntimeOf<JsonAccessRoot<Value>>, JsonAccessPath<Value>, Next, "json.set">
436
+ : unknown
437
+ : unknown
438
+ : unknown
439
+
440
+ type JsonAccessInsertGuard<
441
+ Value,
442
+ Next,
443
+ InsertAfter extends boolean
444
+ > = Value extends JsonExpression<any>
445
+ ? Value extends JsonAccessExpression
446
+ ? JsonAccessRoot<Value> extends JsonExpression<any>
447
+ ? ExactJsonPathGuard<JsonAccessPath<Value>, "json.insert"> &
448
+ JsonInsertPathGuard<Expression.RuntimeOf<JsonAccessRoot<Value>>, JsonAccessPath<Value>, Next, InsertAfter, "json.insert">
449
+ : unknown
450
+ : unknown
451
+ : unknown
452
+
453
+ interface BaseSegmentOperation<Segment extends JsonPath.CanonicalSegment> {
454
+ <Base extends JsonExpression<any>>(base: Base): JsonGetResultExpression<Base, Segment, "json.get">
455
+ }
456
+
457
+ interface KeySegmentOperation<Key extends string>
458
+ extends BaseSegmentOperation<JsonPath.KeySegment<Key>>, JsonPath.KeySegment<Key> {}
459
+
460
+ interface IndexSegmentOperation<Index extends number>
461
+ extends BaseSegmentOperation<JsonPath.IndexSegment<Index>>, JsonPath.IndexSegment<Index> {}
462
+
463
+ interface WildcardSegmentOperation
464
+ extends BaseSegmentOperation<JsonPath.WildcardSegment>, JsonPath.WildcardSegment {}
465
+
466
+ interface SliceSegmentOperation<
467
+ Start extends number | undefined,
468
+ End extends number | undefined
469
+ > extends BaseSegmentOperation<JsonPath.SliceSegment<Start, End>>, JsonPath.SliceSegment<Start, End> {}
470
+
471
+ interface DescendSegmentOperation
472
+ extends BaseSegmentOperation<JsonPath.DescendSegment>, JsonPath.DescendSegment {}
473
+
474
+ type SegmentOperation<Segment extends JsonPath.CanonicalSegment> =
475
+ Segment extends JsonPath.KeySegment<infer Key extends string> ? KeySegmentOperation<Key> :
476
+ Segment extends JsonPath.IndexSegment<infer Index extends number> ? IndexSegmentOperation<Index> :
477
+ Segment extends JsonPath.WildcardSegment ? WildcardSegmentOperation :
478
+ Segment extends JsonPath.SliceSegment<infer Start extends number | undefined, infer End extends number | undefined> ? SliceSegmentOperation<Start, End> :
479
+ Segment extends JsonPath.DescendSegment ? DescendSegmentOperation :
480
+ never
481
+
482
+ const emptyPath = JsonPath.path()
483
+
484
+ const isObjectLike = (value: unknown): value is object =>
485
+ (typeof value === "object" || typeof value === "function") && value !== null
486
+
487
+ const isExpression = (value: unknown): value is Expression.Any =>
488
+ isObjectLike(value) && Expression.TypeId in value
489
+
490
+ const isPath = (value: unknown): value is JsonPath.Path<any> =>
491
+ isObjectLike(value) && JsonPath.TypeId in value
492
+
493
+ const isSegment = (value: unknown): value is JsonPath.CanonicalSegment =>
494
+ isObjectLike(value) && JsonPath.SegmentTypeId in value
495
+
496
+ const isTarget = (value: unknown): value is JsonPathInput =>
497
+ isPath(value) || isSegment(value)
498
+
499
+ const normalizeSegment = <Segment extends JsonPath.CanonicalSegment>(
500
+ segment: Segment
501
+ ): Segment => {
502
+ switch (segment.kind) {
503
+ case "key":
504
+ return JsonPath.key(segment.key) as Segment
505
+ case "index":
506
+ return JsonPath.index(segment.index) as Segment
507
+ case "wildcard":
508
+ return JsonPath.wildcard() as Segment
509
+ case "slice":
510
+ return JsonPath.slice(segment.start, segment.end) as Segment
511
+ case "descend":
512
+ return JsonPath.descend() as Segment
513
+ }
514
+ }
515
+
516
+ const normalizeTarget = <Target extends JsonPathInput>(
517
+ target: Target
518
+ ): Target =>
519
+ isPath(target)
520
+ ? JsonPath.path(...target.segments.map(normalizeSegment)) as Target
521
+ : normalizeSegment(target as JsonPath.CanonicalSegment) as unknown as Target
522
+
523
+ const normalizeTargetPath = <Target extends JsonPathInput>(
524
+ target: Target
525
+ ): JsonPath.Path<JsonPathSegmentsOf<Target>> =>
526
+ isPath(target)
527
+ ? JsonPath.path(...target.segments.map(normalizeSegment)) as JsonPath.Path<JsonPathSegmentsOf<Target>>
528
+ : JsonPath.path(normalizeSegment(target as JsonPath.CanonicalSegment)) as unknown as JsonPath.Path<JsonPathSegmentsOf<Target>>
529
+
530
+ const accessKinds = new Set<string>([
531
+ "jsonGet",
532
+ "jsonPath",
533
+ "jsonAccess",
534
+ "jsonTraverse",
535
+ "jsonGetText",
536
+ "jsonPathText",
537
+ "jsonAccessText",
538
+ "jsonTraverseText"
539
+ ])
540
+
541
+ const accessPathOf = (value: Expression.Any): {
542
+ readonly base: Expression.Any
543
+ readonly path: JsonPath.Path<readonly JsonPath.CanonicalSegment[]>
544
+ } | undefined => {
545
+ const segments: JsonPath.CanonicalSegment[] = []
546
+ let base: Expression.Any = value
547
+ while (isExpression(base)) {
548
+ const ast = (base as Expression.Any & {
549
+ readonly [ExpressionAst.TypeId]: ExpressionAst.Any
550
+ })[ExpressionAst.TypeId] as { readonly kind?: unknown; readonly base?: unknown; readonly segments?: unknown }
551
+ if (typeof ast.kind !== "string" || !accessKinds.has(ast.kind) || !isExpression(ast.base) || !Array.isArray(ast.segments)) {
552
+ break
553
+ }
554
+ segments.unshift(...ast.segments.map(normalizeSegment))
555
+ base = ast.base
556
+ }
557
+ return segments.length === 0
558
+ ? undefined
559
+ : {
560
+ base,
561
+ path: JsonPath.path(...segments)
562
+ }
563
+ }
564
+
565
+ const targetOrAccessPath = (
566
+ value: unknown
567
+ ): {
568
+ readonly base: Expression.Any
569
+ readonly path: JsonPath.Path<readonly JsonPath.CanonicalSegment[]>
570
+ } | undefined =>
571
+ isExpression(value) ? accessPathOf(value) : undefined
572
+
573
+ const segmentOperation = <Segment extends JsonPath.CanonicalSegment>(
574
+ segment: Segment
575
+ ): SegmentOperation<Segment> =>
576
+ Object.assign(
577
+ ((base: JsonExpression<any>) => standardJson.get(base as never, segment as never)) as unknown as SegmentOperation<Segment>,
578
+ segment
579
+ )
580
+
581
+ export const key = <const Key extends string>(value: Key): SegmentOperation<JsonPath.KeySegment<Key>> =>
582
+ segmentOperation(JsonPath.key(value))
583
+
584
+ export const index = <const Index extends number>(value: Index): SegmentOperation<JsonPath.IndexSegment<Index>> =>
585
+ segmentOperation(JsonPath.index(value))
586
+
587
+ export const wildcard = (): SegmentOperation<JsonPath.WildcardSegment> =>
588
+ segmentOperation(JsonPath.wildcard())
589
+
590
+ export const slice = <
591
+ const Start extends number | undefined = undefined,
592
+ const End extends number | undefined = undefined
593
+ >(
594
+ start?: Start,
595
+ end?: End
596
+ ): SegmentOperation<JsonPath.SliceSegment<Start, End>> =>
597
+ segmentOperation(JsonPath.slice(start, end))
598
+
599
+ export const descend = (): SegmentOperation<JsonPath.DescendSegment> =>
600
+ segmentOperation(JsonPath.descend())
601
+
602
+ export interface Get {
603
+ <Base extends JsonExpression<any>, Target extends JsonPathInput>(
604
+ base: Base,
605
+ target: Target & JsonValuePathGuard<Expression.RuntimeOf<Base>, Target, "json.get">
606
+ ): JsonGetResultExpression<Base, Target, "json.get">
607
+ <Target extends JsonPathInput>(
608
+ target: Target & JsonValuePathGuard<any, Target, "json.get">
609
+ ): <Base extends JsonExpression<any>>(base: Base) => JsonGetResultExpression<Base, Target, "json.get">
610
+ <Base extends JsonExpression<any>>(base: Base): JsonAccessGetResultExpression<Base, "json.get">
611
+ }
612
+
613
+ export const get = ((...args: readonly [unknown] | readonly [unknown, unknown]) => {
614
+ if (args.length === 1) {
615
+ const [first] = args
616
+ if (isTarget(first)) {
617
+ return (base: JsonExpression<any>) => standardJson.get(base as never, normalizeTarget(first) as never)
618
+ }
619
+ const access = targetOrAccessPath(first)
620
+ return access === undefined
621
+ ? first
622
+ : standardJson.get(access.base as never, access.path as never)
623
+ }
624
+ const [base, target] = args
625
+ return standardJson.get(base as never, normalizeTarget(target as JsonPathInput) as never)
626
+ }) as Get
627
+
628
+ type TextPipe = <Base extends JsonExpression<any>>(
629
+ base: Base
630
+ ) => Base extends JsonAccessExpression
631
+ ? JsonAccessTextResultExpression<Base>
632
+ : JsonTextTerminalExpression<Base>
633
+
634
+ type Text = TextPipe
635
+
636
+ export const text = (((...args: readonly [unknown] | readonly [unknown, unknown]) => {
637
+ if (args.length === 1) {
638
+ const [first] = args
639
+ if (isTarget(first)) {
640
+ return (base: JsonExpression<any>) => standardJson.text(base as never, normalizeTarget(first) as never)
641
+ }
642
+ const access = targetOrAccessPath(first)
643
+ return access === undefined
644
+ ? standardJson.text(first as never, emptyPath as never)
645
+ : standardJson.text(access.base as never, access.path as never)
646
+ }
647
+ const [base, target] = args
648
+ return standardJson.text(base as never, normalizeTarget(target as JsonPathInput) as never)
649
+ }) as unknown) as Text
650
+
651
+ type DeletePipe = <Base extends JsonExpression<any> & JsonAccessExpression>(
652
+ base: Base & JsonAccessDeleteGuard<Base, "json.delete">
653
+ ) => JsonAccessDeleteResultExpression<Base, "json.delete">
654
+
655
+ type Delete = DeletePipe
656
+
657
+ export const delete_ = (((...args: readonly [unknown] | readonly [unknown, unknown]) => {
658
+ if (args.length === 1) {
659
+ const [first] = args
660
+ if (isTarget(first)) {
661
+ return (base: JsonExpression<any>) => standardJson.delete(base as never, normalizeTarget(first) as never)
662
+ }
663
+ const access = targetOrAccessPath(first)
664
+ if (access === undefined) {
665
+ throw new Error("Json.delete requires a piped JSON path or an explicit target")
666
+ }
667
+ return standardJson.delete(access.base as never, access.path as never)
668
+ }
669
+ const [base, target] = args
670
+ return standardJson.delete(base as never, normalizeTarget(target as JsonPathInput) as never)
671
+ }) as unknown) as Delete
672
+
673
+ export { delete_ as delete }
674
+
675
+ export const access = standardJson.access
676
+ export const traverse = standardJson.traverse
677
+ export const accessText = standardJson.accessText
678
+ export const traverseText = standardJson.traverseText
679
+ export const contains = standardJson.contains
680
+ export const containedBy = standardJson.containedBy
681
+
682
+ export const hasKey = ((...args: readonly [unknown] | readonly [unknown, unknown]) => {
683
+ if (args.length === 1) {
684
+ const [key] = args
685
+ return (base: JsonExpression<any>) => standardJson.hasKey(base as never, key as never)
686
+ }
687
+ const [base, key] = args
688
+ return standardJson.hasKey(base as never, key as never)
689
+ }) as {
690
+ <Base extends JsonExpression<any>, Key extends JsonObjectKeyOf<Base>>(
691
+ base: Base,
692
+ key: Key
693
+ ): JsonPredicateExpression<Base>
694
+ <Key extends string>(
695
+ key: Key
696
+ ): <Base extends JsonExpression<any>>(
697
+ base: Base & (Key extends JsonObjectKeyOf<Base> ? unknown : never)
698
+ ) => JsonPredicateExpression<Base>
699
+ }
700
+
701
+ export const keyExists = hasKey
702
+
703
+ export const hasAnyKeys = ((base: JsonExpression<any>, ...keys: readonly string[]) =>
704
+ standardJson.hasAnyKeys(base as never, ...(keys as [string, ...string[]]) as never)) as {
705
+ <Base extends JsonExpression<any>, Keys extends readonly [JsonObjectKeyOf<Base>, ...JsonObjectKeyOf<Base>[]]>(
706
+ base: Base,
707
+ ...keys: Keys
708
+ ): JsonPredicateExpression<Base>
709
+ }
710
+
711
+ export const hasAllKeys = ((base: JsonExpression<any>, ...keys: readonly string[]) =>
712
+ standardJson.hasAllKeys(base as never, ...(keys as [string, ...string[]]) as never)) as {
713
+ <Base extends JsonExpression<any>, Keys extends readonly [JsonObjectKeyOf<Base>, ...JsonObjectKeyOf<Base>[]]>(
714
+ base: Base,
715
+ ...keys: Keys
716
+ ): JsonPredicateExpression<Base>
717
+ }
718
+
719
+ type RemovePipe = <Base extends JsonExpression<any> & JsonAccessExpression>(
720
+ base: Base & JsonAccessDeleteGuard<Base, "json.remove">
721
+ ) => JsonAccessDeleteResultExpression<Base, "json.remove">
722
+
723
+ type Remove = RemovePipe
724
+
725
+ export const remove = (((...args: readonly [unknown] | readonly [unknown, unknown]) => {
726
+ if (args.length === 1) {
727
+ const [first] = args
728
+ if (isTarget(first)) {
729
+ return (base: JsonExpression<any>) => standardJson.remove(base as never, normalizeTarget(first) as never)
730
+ }
731
+ const access = targetOrAccessPath(first)
732
+ if (access === undefined) {
733
+ throw new Error("Json.remove requires a piped JSON path or an explicit target")
734
+ }
735
+ return standardJson.remove(access.base as never, access.path as never)
736
+ }
737
+ const [base, target] = args
738
+ return standardJson.remove(base as never, normalizeTarget(target as JsonPathInput) as never)
739
+ }) as unknown) as Remove
740
+
741
+ export const set = ((...args: readonly unknown[]) => {
742
+ if (args.length === 1 || (args.length === 2 && !isExpression(args[0]))) {
743
+ const [next, options] = args
744
+ return (base: JsonExpression<any>) => {
745
+ const access = accessPathOf(base)
746
+ if (access === undefined) {
747
+ throw new Error("Json.set requires a piped JSON path or an explicit target")
748
+ }
749
+ return standardJson.set(access.base as never, access.path as never, next as never, options as never)
750
+ }
751
+ }
752
+ if ((args.length === 2 || args.length === 3) && isExpression(args[0]) && !isTarget(args[1])) {
753
+ const [base, next, options] = args
754
+ const access = accessPathOf(base)
755
+ if (access === undefined) {
756
+ throw new Error("Json.set requires a piped JSON path or an explicit target")
757
+ }
758
+ return standardJson.set(access.base as never, access.path as never, next as never, options as never)
759
+ }
760
+ const [base, target, next, options] = args
761
+ return standardJson.set(base as never, normalizeTarget(target as JsonPathInput) as never, next as never, options as never)
762
+ }) as unknown as {
763
+ <Next extends Parameters<typeof standardJson.set>[2], CreateMissing extends boolean = true>(
764
+ next: Next,
765
+ options?: {
766
+ readonly createMissing?: CreateMissing
767
+ }
768
+ ): <Base extends JsonExpression<any> & JsonAccessExpression>(
769
+ base: Base & JsonAccessSetGuard<Base, NoInfer<Next>, NoInfer<CreateMissing>>
770
+ ) => JsonAccessSetResultExpression<Base, Next, CreateMissing>
771
+ <Base extends JsonExpression<any> & JsonAccessExpression, Next extends Parameters<typeof standardJson.set>[2], CreateMissing extends boolean = true>(
772
+ base: Base & JsonAccessSetGuard<Base, NoInfer<Next>, NoInfer<CreateMissing>>,
773
+ next: Next,
774
+ options?: {
775
+ readonly createMissing?: CreateMissing
776
+ }
777
+ ): JsonAccessSetResultExpression<Base, Next, CreateMissing>
778
+ <Base extends JsonExpression<any>, Target extends JsonPathInput, Next extends Parameters<typeof standardJson.set>[2], CreateMissing extends boolean = true>(
779
+ base: Base,
780
+ target: Target & ExactJsonPathGuard<Target, "json.set"> & JsonSetPathGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, "json.set">,
781
+ next: Next,
782
+ options?: {
783
+ readonly createMissing?: CreateMissing
784
+ }
785
+ ): JsonResultExpression<
786
+ JsonSetOutputWithCreateMissing<Expression.RuntimeOf<Base>, Target, Next, "json.set", CreateMissing>,
787
+ JsonDbOf<Base>,
788
+ JsonKindOf<Base>,
789
+ Expression.DependenciesOf<Base>,
790
+ never,
791
+ DialectOf<Base>
792
+ >
793
+ }
794
+
795
+ export const insert = ((...args: readonly unknown[]) => {
796
+ if (args.length === 1 || (args.length === 2 && !isExpression(args[0]))) {
797
+ const [next, options] = args
798
+ return (base: JsonExpression<any>) => {
799
+ const access = accessPathOf(base)
800
+ if (access === undefined) {
801
+ throw new Error("Json.insert requires a piped JSON path or an explicit target")
802
+ }
803
+ return standardJson.insert(access.base as never, access.path as never, next as never, options as never)
804
+ }
805
+ }
806
+ if ((args.length === 2 || args.length === 3) && isExpression(args[0]) && !isTarget(args[1])) {
807
+ const [base, next, options] = args
808
+ const access = accessPathOf(base)
809
+ if (access === undefined) {
810
+ throw new Error("Json.insert requires a piped JSON path or an explicit target")
811
+ }
812
+ return standardJson.insert(access.base as never, access.path as never, next as never, options as never)
813
+ }
814
+ const [base, target, next, options] = args
815
+ return standardJson.insert(base as never, normalizeTarget(target as JsonPathInput) as never, next as never, options as never)
816
+ }) as unknown as {
817
+ <Next extends Parameters<typeof standardJson.insert>[2], InsertAfter extends boolean = false>(
818
+ next: Next,
819
+ options?: {
820
+ readonly insertAfter?: InsertAfter
821
+ }
822
+ ): <Base extends JsonExpression<any> & JsonAccessExpression>(
823
+ base: Base & JsonAccessInsertGuard<Base, NoInfer<Next>, NoInfer<InsertAfter>>
824
+ ) => JsonAccessInsertResultExpression<Base, Next, InsertAfter>
825
+ <Base extends JsonExpression<any> & JsonAccessExpression, Next extends Parameters<typeof standardJson.insert>[2], InsertAfter extends boolean = false>(
826
+ base: Base & JsonAccessInsertGuard<Base, NoInfer<Next>, NoInfer<InsertAfter>>,
827
+ next: Next,
828
+ options?: {
829
+ readonly insertAfter?: InsertAfter
830
+ }
831
+ ): JsonAccessInsertResultExpression<Base, Next, InsertAfter>
832
+ <Base extends JsonExpression<any>, Target extends JsonPathInput, Next extends Parameters<typeof standardJson.insert>[2], InsertAfter extends boolean = false>(
833
+ base: Base,
834
+ target: Target & ExactJsonPathGuard<Target, "json.insert"> & JsonInsertPathGuard<Expression.RuntimeOf<Base>, Target, NoInfer<Next>, NoInfer<InsertAfter>, "json.insert">,
835
+ next: Next,
836
+ options?: {
837
+ readonly insertAfter?: InsertAfter
838
+ }
839
+ ): JsonResultExpression<
840
+ JsonInsertOutputOf<Expression.RuntimeOf<Base>, Target, Next, InsertAfter, "json.insert">,
841
+ JsonDbOf<Base>,
842
+ JsonKindOf<Base>,
843
+ Expression.DependenciesOf<Base>,
844
+ never,
845
+ DialectOf<Base>
846
+ >
847
+ }
848
+
849
+ export const concat = standardJson.concat
850
+ export const merge = standardJson.merge
851
+ export const buildObject = standardJson.buildObject
852
+ export const buildArray = standardJson.buildArray
853
+ export const toJson = standardJson.toJson
854
+ export const toJsonb = standardJson.toJsonb
855
+ export const typeOf = standardJson.typeOf
856
+ export const length = standardJson.length
857
+ export const keys = standardJson.keys
858
+
859
+ export const pathExists = ((...args: readonly [unknown] | readonly [unknown, unknown]) => {
860
+ if (args.length === 1) {
861
+ const [first] = args
862
+ if (isTarget(first) || typeof first === "string") {
863
+ return (base: JsonExpression<any>) =>
864
+ standardJson.pathExists(base as never, isTarget(first) ? normalizeTargetPath(first) as never : first as never)
865
+ }
866
+ const access = targetOrAccessPath(first)
867
+ if (access === undefined) {
868
+ throw new Error("Json.pathExists requires a piped JSON path or an explicit query")
869
+ }
870
+ return standardJson.pathExists(access.base as never, access.path as never)
871
+ }
872
+ const [base, query] = args
873
+ return standardJson.pathExists(base as never, isTarget(query) ? normalizeTargetPath(query) as never : query as never)
874
+ }) as unknown as {
875
+ <Base extends JsonExpression<any>, Query extends JsonPathExistsQuery>(
876
+ base: Base,
877
+ query: JsonPathExistsQueryInput<Query>
878
+ ): JsonPredicateExpression<Base>
879
+ <Query extends JsonPathExistsQuery>(
880
+ query: JsonPathExistsQueryInput<Query>
881
+ ): <Base extends JsonExpression<any>>(base: Base) => JsonPredicateExpression<Base>
882
+ <Base extends JsonExpression<any>>(base: Base): JsonPredicateExpression<Base>
883
+ }