@powerhousedao/reactor-hypercore 6.2.3-dev.4 → 6.2.3-dev.41

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/dist/index.js CHANGED
@@ -1,7 +1,4598 @@
1
- import "@powerhousedao/shared/document-model";
1
+ import { DOCUMENT_SCOPE_ACTION_TYPES, isPurgeMarker } from "@powerhousedao/shared/document-model";
2
2
  import Corestore from "corestore";
3
3
  import Hyperbee from "hyperbee";
4
- //#region ../reactor/dist/drive-container-types-yZrksiJR.js
4
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/util/object-utils.js
5
+ function isUndefined(obj) {
6
+ return typeof obj === "undefined" || obj === void 0;
7
+ }
8
+ function isString(obj) {
9
+ return typeof obj === "string";
10
+ }
11
+ function isNumber(obj) {
12
+ return typeof obj === "number";
13
+ }
14
+ function isBoolean(obj) {
15
+ return typeof obj === "boolean";
16
+ }
17
+ function isNull(obj) {
18
+ return obj === null;
19
+ }
20
+ function isBigInt(obj) {
21
+ return typeof obj === "bigint";
22
+ }
23
+ function isFunction(obj) {
24
+ return typeof obj === "function";
25
+ }
26
+ function isObject(obj) {
27
+ return typeof obj === "object" && obj !== null;
28
+ }
29
+ function freeze(obj) {
30
+ return Object.freeze(obj);
31
+ }
32
+ function asArray(arg) {
33
+ if (isReadonlyArray(arg)) return arg;
34
+ else return [arg];
35
+ }
36
+ function isReadonlyArray(arg) {
37
+ return Array.isArray(arg);
38
+ }
39
+ //#endregion
40
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/identifier-node.js
41
+ /**
42
+ * @internal
43
+ */
44
+ const IdentifierNode = freeze({
45
+ is(node) {
46
+ return node.kind === "IdentifierNode";
47
+ },
48
+ create(name) {
49
+ return freeze({
50
+ kind: "IdentifierNode",
51
+ name
52
+ });
53
+ }
54
+ });
55
+ //#endregion
56
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/schemable-identifier-node.js
57
+ /**
58
+ * @internal
59
+ */
60
+ const SchemableIdentifierNode = freeze({
61
+ is(node) {
62
+ return node.kind === "SchemableIdentifierNode";
63
+ },
64
+ create(identifier) {
65
+ return freeze({
66
+ kind: "SchemableIdentifierNode",
67
+ identifier: IdentifierNode.create(identifier)
68
+ });
69
+ },
70
+ createWithSchema(schema, identifier) {
71
+ return freeze({
72
+ kind: "SchemableIdentifierNode",
73
+ schema: IdentifierNode.create(schema),
74
+ identifier: IdentifierNode.create(identifier)
75
+ });
76
+ }
77
+ });
78
+ //#endregion
79
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/alias-node.js
80
+ /**
81
+ * @internal
82
+ */
83
+ const AliasNode = freeze({
84
+ is(node) {
85
+ return node.kind === "AliasNode";
86
+ },
87
+ create(node, alias) {
88
+ return freeze({
89
+ kind: "AliasNode",
90
+ node,
91
+ alias
92
+ });
93
+ }
94
+ });
95
+ //#endregion
96
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/table-node.js
97
+ /**
98
+ * @internal
99
+ */
100
+ const TableNode = freeze({
101
+ is(node) {
102
+ return node.kind === "TableNode";
103
+ },
104
+ create(table) {
105
+ return freeze({
106
+ kind: "TableNode",
107
+ table: SchemableIdentifierNode.create(table)
108
+ });
109
+ },
110
+ createWithSchema(schema, table) {
111
+ return freeze({
112
+ kind: "TableNode",
113
+ table: SchemableIdentifierNode.createWithSchema(schema, table)
114
+ });
115
+ }
116
+ });
117
+ //#endregion
118
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/operation-node-source.js
119
+ function isOperationNodeSource(obj) {
120
+ return isObject(obj) && isFunction(obj.toOperationNode);
121
+ }
122
+ //#endregion
123
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/expression/expression.js
124
+ function isExpression(obj) {
125
+ return isObject(obj) && "expressionType" in obj && isOperationNodeSource(obj);
126
+ }
127
+ function isAliasedExpression(obj) {
128
+ return isObject(obj) && "expression" in obj && isString(obj.alias) && isOperationNodeSource(obj);
129
+ }
130
+ //#endregion
131
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/select-modifier-node.js
132
+ /**
133
+ * @internal
134
+ */
135
+ const SelectModifierNode = freeze({
136
+ is(node) {
137
+ return node.kind === "SelectModifierNode";
138
+ },
139
+ create(modifier, of) {
140
+ return freeze({
141
+ kind: "SelectModifierNode",
142
+ modifier,
143
+ of
144
+ });
145
+ },
146
+ createWithExpression(modifier) {
147
+ return freeze({
148
+ kind: "SelectModifierNode",
149
+ rawModifier: modifier
150
+ });
151
+ }
152
+ });
153
+ //#endregion
154
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/and-node.js
155
+ /**
156
+ * @internal
157
+ */
158
+ const AndNode = freeze({
159
+ is(node) {
160
+ return node.kind === "AndNode";
161
+ },
162
+ create(left, right) {
163
+ return freeze({
164
+ kind: "AndNode",
165
+ left,
166
+ right
167
+ });
168
+ }
169
+ });
170
+ //#endregion
171
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/or-node.js
172
+ /**
173
+ * @internal
174
+ */
175
+ const OrNode = freeze({
176
+ is(node) {
177
+ return node.kind === "OrNode";
178
+ },
179
+ create(left, right) {
180
+ return freeze({
181
+ kind: "OrNode",
182
+ left,
183
+ right
184
+ });
185
+ }
186
+ });
187
+ //#endregion
188
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/on-node.js
189
+ /**
190
+ * @internal
191
+ */
192
+ const OnNode = freeze({
193
+ is(node) {
194
+ return node.kind === "OnNode";
195
+ },
196
+ create(filter) {
197
+ return freeze({
198
+ kind: "OnNode",
199
+ on: filter
200
+ });
201
+ },
202
+ cloneWithOperation(onNode, operator, operation) {
203
+ return freeze({
204
+ ...onNode,
205
+ on: operator === "And" ? AndNode.create(onNode.on, operation) : OrNode.create(onNode.on, operation)
206
+ });
207
+ }
208
+ });
209
+ //#endregion
210
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/join-node.js
211
+ /**
212
+ * @internal
213
+ */
214
+ const JoinNode = freeze({
215
+ is(node) {
216
+ return node.kind === "JoinNode";
217
+ },
218
+ create(joinType, table) {
219
+ return freeze({
220
+ kind: "JoinNode",
221
+ joinType,
222
+ table,
223
+ on: void 0
224
+ });
225
+ },
226
+ createWithOn(joinType, table, on) {
227
+ return freeze({
228
+ kind: "JoinNode",
229
+ joinType,
230
+ table,
231
+ on: OnNode.create(on)
232
+ });
233
+ },
234
+ cloneWithOn(joinNode, operation) {
235
+ return freeze({
236
+ ...joinNode,
237
+ on: joinNode.on ? OnNode.cloneWithOperation(joinNode.on, "And", operation) : OnNode.create(operation)
238
+ });
239
+ }
240
+ });
241
+ //#endregion
242
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/binary-operation-node.js
243
+ /**
244
+ * @internal
245
+ */
246
+ const BinaryOperationNode = freeze({
247
+ is(node) {
248
+ return node.kind === "BinaryOperationNode";
249
+ },
250
+ create(leftOperand, operator, rightOperand) {
251
+ return freeze({
252
+ kind: "BinaryOperationNode",
253
+ leftOperand,
254
+ operator,
255
+ rightOperand
256
+ });
257
+ }
258
+ });
259
+ //#endregion
260
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/operator-node.js
261
+ const COMPARISON_OPERATORS = [
262
+ "=",
263
+ "==",
264
+ "!=",
265
+ "<>",
266
+ ">",
267
+ ">=",
268
+ "<",
269
+ "<=",
270
+ "in",
271
+ "not in",
272
+ "is",
273
+ "is not",
274
+ "like",
275
+ "not like",
276
+ "match",
277
+ "ilike",
278
+ "not ilike",
279
+ "@>",
280
+ "<@",
281
+ "^@",
282
+ "&&",
283
+ "?",
284
+ "?&",
285
+ "?|",
286
+ "!<",
287
+ "!>",
288
+ "<=>",
289
+ "!~",
290
+ "~",
291
+ "~*",
292
+ "!~*",
293
+ "@@",
294
+ "@@@",
295
+ "!!",
296
+ "<->",
297
+ "regexp",
298
+ "is distinct from",
299
+ "is not distinct from"
300
+ ];
301
+ const ARITHMETIC_OPERATORS = [
302
+ "+",
303
+ "-",
304
+ "*",
305
+ "/",
306
+ "%",
307
+ "^",
308
+ "&",
309
+ "|",
310
+ "#",
311
+ "<<",
312
+ ">>"
313
+ ];
314
+ const JSON_OPERATORS = ["->", "->>"];
315
+ const BINARY_OPERATORS = [
316
+ ...COMPARISON_OPERATORS,
317
+ ...ARITHMETIC_OPERATORS,
318
+ "&&",
319
+ "||"
320
+ ];
321
+ const UNARY_OPERATORS = [
322
+ "not",
323
+ "-",
324
+ ...["exists", "not exists"]
325
+ ];
326
+ const OPERATORS = [
327
+ ...BINARY_OPERATORS,
328
+ ...JSON_OPERATORS,
329
+ ...UNARY_OPERATORS,
330
+ "between",
331
+ "between symmetric"
332
+ ];
333
+ /**
334
+ * @internal
335
+ */
336
+ const OperatorNode = freeze({
337
+ is(node) {
338
+ return node.kind === "OperatorNode";
339
+ },
340
+ create(operator) {
341
+ return freeze({
342
+ kind: "OperatorNode",
343
+ operator
344
+ });
345
+ }
346
+ });
347
+ function isJSONOperator(op) {
348
+ return isString(op) && JSON_OPERATORS.includes(op);
349
+ }
350
+ //#endregion
351
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/column-node.js
352
+ /**
353
+ * @internal
354
+ */
355
+ const ColumnNode = freeze({
356
+ is(node) {
357
+ return node.kind === "ColumnNode";
358
+ },
359
+ create(column) {
360
+ return freeze({
361
+ kind: "ColumnNode",
362
+ column: IdentifierNode.create(column)
363
+ });
364
+ }
365
+ });
366
+ //#endregion
367
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/select-all-node.js
368
+ /**
369
+ * @internal
370
+ */
371
+ const SelectAllNode = freeze({
372
+ is(node) {
373
+ return node.kind === "SelectAllNode";
374
+ },
375
+ create() {
376
+ return freeze({ kind: "SelectAllNode" });
377
+ }
378
+ });
379
+ //#endregion
380
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/reference-node.js
381
+ /**
382
+ * @internal
383
+ */
384
+ const ReferenceNode = freeze({
385
+ is(node) {
386
+ return node.kind === "ReferenceNode";
387
+ },
388
+ create(column, table) {
389
+ return freeze({
390
+ kind: "ReferenceNode",
391
+ table,
392
+ column
393
+ });
394
+ },
395
+ createSelectAll(table) {
396
+ return freeze({
397
+ kind: "ReferenceNode",
398
+ table,
399
+ column: SelectAllNode.create()
400
+ });
401
+ }
402
+ });
403
+ //#endregion
404
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/dynamic/dynamic-reference-builder.js
405
+ function isDynamicReferenceBuilder(obj) {
406
+ return isObject(obj) && isOperationNodeSource(obj) && isString(obj.dynamicReference);
407
+ }
408
+ //#endregion
409
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/order-by-item-node.js
410
+ /**
411
+ * @internal
412
+ */
413
+ const OrderByItemNode = freeze({
414
+ is(node) {
415
+ return node.kind === "OrderByItemNode";
416
+ },
417
+ create(orderBy, direction) {
418
+ return freeze({
419
+ kind: "OrderByItemNode",
420
+ orderBy,
421
+ direction
422
+ });
423
+ },
424
+ cloneWith(node, props) {
425
+ return freeze({
426
+ ...node,
427
+ ...props
428
+ });
429
+ }
430
+ });
431
+ //#endregion
432
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/raw-node.js
433
+ /**
434
+ * @internal
435
+ */
436
+ const RawNode = freeze({
437
+ is(node) {
438
+ return node.kind === "RawNode";
439
+ },
440
+ create(sqlFragments, parameters) {
441
+ return freeze({
442
+ kind: "RawNode",
443
+ sqlFragments: freeze(sqlFragments),
444
+ parameters: freeze(parameters)
445
+ });
446
+ },
447
+ createWithSql(sql) {
448
+ return RawNode.create([sql], []);
449
+ },
450
+ createWithChild(child) {
451
+ return RawNode.create(["", ""], [child]);
452
+ },
453
+ createWithChildren(children) {
454
+ return RawNode.create(new Array(children.length + 1).fill(""), children);
455
+ }
456
+ });
457
+ //#endregion
458
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/collate-node.js
459
+ /**
460
+ * @internal
461
+ */
462
+ const CollateNode = freeze({
463
+ is(node) {
464
+ return node.kind === "CollateNode";
465
+ },
466
+ create(collation) {
467
+ return freeze({
468
+ kind: "CollateNode",
469
+ collation: IdentifierNode.create(collation)
470
+ });
471
+ }
472
+ });
473
+ //#endregion
474
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/order-by-item-builder.js
475
+ var OrderByItemBuilder = class OrderByItemBuilder {
476
+ #props;
477
+ constructor(props) {
478
+ this.#props = freeze(props);
479
+ }
480
+ /**
481
+ * Adds `desc` to the `order by` item.
482
+ *
483
+ * See {@link asc} for the opposite.
484
+ */
485
+ desc() {
486
+ return new OrderByItemBuilder({ node: OrderByItemNode.cloneWith(this.#props.node, { direction: RawNode.createWithSql("desc") }) });
487
+ }
488
+ /**
489
+ * Adds `asc` to the `order by` item.
490
+ *
491
+ * See {@link desc} for the opposite.
492
+ */
493
+ asc() {
494
+ return new OrderByItemBuilder({ node: OrderByItemNode.cloneWith(this.#props.node, { direction: RawNode.createWithSql("asc") }) });
495
+ }
496
+ /**
497
+ * Adds `nulls last` to the `order by` item.
498
+ *
499
+ * This is only supported by some dialects like PostgreSQL and SQLite.
500
+ *
501
+ * See {@link nullsFirst} for the opposite.
502
+ */
503
+ nullsLast() {
504
+ return new OrderByItemBuilder({ node: OrderByItemNode.cloneWith(this.#props.node, { nulls: "last" }) });
505
+ }
506
+ /**
507
+ * Adds `nulls first` to the `order by` item.
508
+ *
509
+ * This is only supported by some dialects like PostgreSQL and SQLite.
510
+ *
511
+ * See {@link nullsLast} for the opposite.
512
+ */
513
+ nullsFirst() {
514
+ return new OrderByItemBuilder({ node: OrderByItemNode.cloneWith(this.#props.node, { nulls: "first" }) });
515
+ }
516
+ /**
517
+ * Adds `collate <collationName>` to the `order by` item.
518
+ */
519
+ collate(collation) {
520
+ return new OrderByItemBuilder({ node: OrderByItemNode.cloneWith(this.#props.node, { collation: CollateNode.create(collation) }) });
521
+ }
522
+ toOperationNode() {
523
+ return this.#props.node;
524
+ }
525
+ };
526
+ //#endregion
527
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/util/log-once.js
528
+ const LOGGED_MESSAGES = /* @__PURE__ */ new Set();
529
+ /**
530
+ * Use for system-level logging, such as deprecation messages.
531
+ * Logs a message and ensures it won't be logged again.
532
+ */
533
+ function logOnce(message) {
534
+ if (LOGGED_MESSAGES.has(message)) return;
535
+ LOGGED_MESSAGES.add(message);
536
+ console.log(message);
537
+ }
538
+ //#endregion
539
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/order-by-parser.js
540
+ function isOrderByDirection(thing) {
541
+ return thing === "asc" || thing === "desc";
542
+ }
543
+ function parseOrderBy(args) {
544
+ if (args.length === 2) return [parseOrderByItem(args[0], args[1])];
545
+ if (args.length === 1) {
546
+ const [orderBy] = args;
547
+ if (Array.isArray(orderBy)) {
548
+ logOnce("orderBy(array) is deprecated, use multiple orderBy calls instead.");
549
+ return orderBy.map((item) => parseOrderByItem(item));
550
+ }
551
+ return [parseOrderByItem(orderBy)];
552
+ }
553
+ throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${args.length}`);
554
+ }
555
+ function parseOrderByItem(expr, modifiers) {
556
+ const parsedRef = parseOrderByExpression(expr);
557
+ if (OrderByItemNode.is(parsedRef)) {
558
+ if (modifiers) throw new Error("Cannot specify direction twice!");
559
+ return parsedRef;
560
+ }
561
+ return parseOrderByWithModifiers(parsedRef, modifiers);
562
+ }
563
+ function parseOrderByExpression(expr) {
564
+ if (isExpressionOrFactory(expr)) return parseExpression(expr);
565
+ if (isDynamicReferenceBuilder(expr)) return expr.toOperationNode();
566
+ const [ref, direction] = expr.split(" ");
567
+ if (direction) {
568
+ logOnce("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead.");
569
+ return parseOrderByWithModifiers(parseStringReference(ref), direction);
570
+ }
571
+ return parseStringReference(expr);
572
+ }
573
+ function parseOrderByWithModifiers(expr, modifiers) {
574
+ if (typeof modifiers === "string") {
575
+ if (!isOrderByDirection(modifiers)) throw new Error(`Invalid order by direction: ${modifiers}`);
576
+ return OrderByItemNode.create(expr, RawNode.createWithSql(modifiers));
577
+ }
578
+ if (isExpression(modifiers)) {
579
+ logOnce("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead.");
580
+ return OrderByItemNode.create(expr, modifiers.toOperationNode());
581
+ }
582
+ const node = OrderByItemNode.create(expr);
583
+ if (!modifiers) return node;
584
+ return modifiers(new OrderByItemBuilder({ node })).toOperationNode();
585
+ }
586
+ //#endregion
587
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/json-reference-node.js
588
+ /**
589
+ * @internal
590
+ */
591
+ const JSONReferenceNode = freeze({
592
+ is(node) {
593
+ return node.kind === "JSONReferenceNode";
594
+ },
595
+ create(reference, traversal) {
596
+ return freeze({
597
+ kind: "JSONReferenceNode",
598
+ reference,
599
+ traversal
600
+ });
601
+ },
602
+ cloneWithTraversal(node, traversal) {
603
+ return freeze({
604
+ ...node,
605
+ traversal
606
+ });
607
+ }
608
+ });
609
+ //#endregion
610
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/json-operator-chain-node.js
611
+ /**
612
+ * @internal
613
+ */
614
+ const JSONOperatorChainNode = freeze({
615
+ is(node) {
616
+ return node.kind === "JSONOperatorChainNode";
617
+ },
618
+ create(operator) {
619
+ return freeze({
620
+ kind: "JSONOperatorChainNode",
621
+ operator,
622
+ values: freeze([])
623
+ });
624
+ },
625
+ cloneWithValue(node, value) {
626
+ return freeze({
627
+ ...node,
628
+ values: freeze([...node.values, value])
629
+ });
630
+ }
631
+ });
632
+ //#endregion
633
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/json-path-node.js
634
+ /**
635
+ * @internal
636
+ */
637
+ const JSONPathNode = freeze({
638
+ is(node) {
639
+ return node.kind === "JSONPathNode";
640
+ },
641
+ create(inOperator) {
642
+ return freeze({
643
+ kind: "JSONPathNode",
644
+ inOperator,
645
+ pathLegs: freeze([])
646
+ });
647
+ },
648
+ cloneWithLeg(jsonPathNode, pathLeg) {
649
+ return freeze({
650
+ ...jsonPathNode,
651
+ pathLegs: freeze([...jsonPathNode.pathLegs, pathLeg])
652
+ });
653
+ }
654
+ });
655
+ //#endregion
656
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/reference-parser.js
657
+ function parseSimpleReferenceExpression(exp) {
658
+ if (isString(exp)) return parseStringReference(exp);
659
+ return exp.toOperationNode();
660
+ }
661
+ function parseReferenceExpressionOrList(arg) {
662
+ if (isReadonlyArray(arg)) return arg.map((it) => parseReferenceExpression(it));
663
+ else return [parseReferenceExpression(arg)];
664
+ }
665
+ function parseReferenceExpression(exp) {
666
+ if (isExpressionOrFactory(exp)) return parseExpression(exp);
667
+ return parseSimpleReferenceExpression(exp);
668
+ }
669
+ function parseJSONReference(ref, op) {
670
+ const referenceNode = parseStringReference(ref);
671
+ if (isJSONOperator(op)) return JSONReferenceNode.create(referenceNode, JSONOperatorChainNode.create(OperatorNode.create(op)));
672
+ const opWithoutLastChar = op.slice(0, -1);
673
+ if (isJSONOperator(opWithoutLastChar)) return JSONReferenceNode.create(referenceNode, JSONPathNode.create(OperatorNode.create(opWithoutLastChar)));
674
+ throw new Error(`Invalid JSON operator: ${op}`);
675
+ }
676
+ function parseStringReference(ref) {
677
+ const COLUMN_SEPARATOR = ".";
678
+ if (!ref.includes(COLUMN_SEPARATOR)) return ReferenceNode.create(ColumnNode.create(ref));
679
+ const parts = ref.split(COLUMN_SEPARATOR).map(trim$1);
680
+ if (parts.length === 3) return parseStringReferenceWithTableAndSchema(parts);
681
+ if (parts.length === 2) return parseStringReferenceWithTable(parts);
682
+ throw new Error(`invalid column reference ${ref}`);
683
+ }
684
+ function parseAliasedStringReference(ref) {
685
+ const ALIAS_SEPARATOR = " as ";
686
+ if (ref.includes(ALIAS_SEPARATOR)) {
687
+ const [columnRef, alias] = ref.split(ALIAS_SEPARATOR).map(trim$1);
688
+ return AliasNode.create(parseStringReference(columnRef), IdentifierNode.create(alias));
689
+ } else return parseStringReference(ref);
690
+ }
691
+ function parseStringReferenceWithTableAndSchema(parts) {
692
+ const [schema, table, column] = parts;
693
+ return ReferenceNode.create(ColumnNode.create(column), TableNode.createWithSchema(schema, table));
694
+ }
695
+ function parseStringReferenceWithTable(parts) {
696
+ const [table, column] = parts;
697
+ return ReferenceNode.create(ColumnNode.create(column), TableNode.create(table));
698
+ }
699
+ function trim$1(str) {
700
+ return str.trim();
701
+ }
702
+ //#endregion
703
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/primitive-value-list-node.js
704
+ /**
705
+ * @internal
706
+ */
707
+ const PrimitiveValueListNode = freeze({
708
+ is(node) {
709
+ return node.kind === "PrimitiveValueListNode";
710
+ },
711
+ create(values) {
712
+ return freeze({
713
+ kind: "PrimitiveValueListNode",
714
+ values: freeze([...values])
715
+ });
716
+ }
717
+ });
718
+ //#endregion
719
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/value-list-node.js
720
+ /**
721
+ * @internal
722
+ */
723
+ const ValueListNode = freeze({
724
+ is(node) {
725
+ return node.kind === "ValueListNode";
726
+ },
727
+ create(values) {
728
+ return freeze({
729
+ kind: "ValueListNode",
730
+ values: freeze(values)
731
+ });
732
+ }
733
+ });
734
+ //#endregion
735
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/value-node.js
736
+ /**
737
+ * @internal
738
+ */
739
+ const ValueNode = freeze({
740
+ is(node) {
741
+ return node.kind === "ValueNode";
742
+ },
743
+ create(value) {
744
+ return freeze({
745
+ kind: "ValueNode",
746
+ value
747
+ });
748
+ },
749
+ createImmediate(value) {
750
+ return freeze({
751
+ kind: "ValueNode",
752
+ value,
753
+ immediate: true
754
+ });
755
+ }
756
+ });
757
+ //#endregion
758
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/value-parser.js
759
+ function parseValueExpressionOrList(arg) {
760
+ if (isReadonlyArray(arg)) return parseValueExpressionList(arg);
761
+ return parseValueExpression(arg);
762
+ }
763
+ function parseValueExpression(exp) {
764
+ if (isExpressionOrFactory(exp)) return parseExpression(exp);
765
+ return ValueNode.create(exp);
766
+ }
767
+ function isSafeImmediateValue(value) {
768
+ return isNumber(value) || isBoolean(value) || isNull(value);
769
+ }
770
+ function parseSafeImmediateValue(value) {
771
+ if (!isSafeImmediateValue(value)) throw new Error(`unsafe immediate value ${JSON.stringify(value)}`);
772
+ return ValueNode.createImmediate(value);
773
+ }
774
+ function parseValueExpressionList(arg) {
775
+ if (arg.some(isExpressionOrFactory)) return ValueListNode.create(arg.map((it) => parseValueExpression(it)));
776
+ return PrimitiveValueListNode.create(arg);
777
+ }
778
+ //#endregion
779
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/parens-node.js
780
+ /**
781
+ * @internal
782
+ */
783
+ const ParensNode = freeze({
784
+ is(node) {
785
+ return node.kind === "ParensNode";
786
+ },
787
+ create(node) {
788
+ return freeze({
789
+ kind: "ParensNode",
790
+ node
791
+ });
792
+ }
793
+ });
794
+ //#endregion
795
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/binary-operation-parser.js
796
+ function parseValueBinaryOperationOrExpression(args) {
797
+ if (args.length === 3) return parseValueBinaryOperation(args[0], args[1], args[2]);
798
+ else if (args.length === 1) return parseValueExpression(args[0]);
799
+ throw new Error(`invalid arguments: ${JSON.stringify(args)}`);
800
+ }
801
+ function parseValueBinaryOperation(left, operator, right) {
802
+ if (isIsOperator(operator) && needsIsOperator(right)) return BinaryOperationNode.create(parseReferenceExpression(left), parseOperator(operator), ValueNode.createImmediate(right));
803
+ return BinaryOperationNode.create(parseReferenceExpression(left), parseOperator(operator), parseValueExpressionOrList(right));
804
+ }
805
+ function parseReferentialBinaryOperation(left, operator, right) {
806
+ return BinaryOperationNode.create(parseReferenceExpression(left), parseOperator(operator), parseReferenceExpression(right));
807
+ }
808
+ function parseFilterObject(obj, combinator) {
809
+ return parseFilterList(Object.entries(obj).filter(([, v]) => !isUndefined(v)).map(([k, v]) => parseValueBinaryOperation(k, needsIsOperator(v) ? "is" : "=", v)), combinator);
810
+ }
811
+ function parseFilterList(list, combinator, withParens = true) {
812
+ const combine = combinator === "and" ? AndNode.create : OrNode.create;
813
+ if (list.length === 0) return BinaryOperationNode.create(ValueNode.createImmediate(1), OperatorNode.create("="), ValueNode.createImmediate(combinator === "and" ? 1 : 0));
814
+ let node = toOperationNode(list[0]);
815
+ for (let i = 1; i < list.length; ++i) node = combine(node, toOperationNode(list[i]));
816
+ if (list.length > 1 && withParens) return ParensNode.create(node);
817
+ return node;
818
+ }
819
+ function isIsOperator(operator) {
820
+ return operator === "is" || operator === "is not";
821
+ }
822
+ function needsIsOperator(value) {
823
+ return isNull(value) || isBoolean(value);
824
+ }
825
+ function parseOperator(operator) {
826
+ if (isString(operator) && OPERATORS.includes(operator)) return OperatorNode.create(operator);
827
+ if (isOperationNodeSource(operator)) return operator.toOperationNode();
828
+ throw new Error(`invalid operator ${JSON.stringify(operator)}`);
829
+ }
830
+ function toOperationNode(nodeOrSource) {
831
+ return isOperationNodeSource(nodeOrSource) ? nodeOrSource.toOperationNode() : nodeOrSource;
832
+ }
833
+ //#endregion
834
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/order-by-node.js
835
+ /**
836
+ * @internal
837
+ */
838
+ const OrderByNode = freeze({
839
+ is(node) {
840
+ return node.kind === "OrderByNode";
841
+ },
842
+ create(items) {
843
+ return freeze({
844
+ kind: "OrderByNode",
845
+ items: freeze([...items])
846
+ });
847
+ },
848
+ cloneWithItems(orderBy, items) {
849
+ return freeze({
850
+ ...orderBy,
851
+ items: freeze([...orderBy.items, ...items])
852
+ });
853
+ }
854
+ });
855
+ //#endregion
856
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/partition-by-node.js
857
+ /**
858
+ * @internal
859
+ */
860
+ const PartitionByNode = freeze({
861
+ is(node) {
862
+ return node.kind === "PartitionByNode";
863
+ },
864
+ create(items) {
865
+ return freeze({
866
+ kind: "PartitionByNode",
867
+ items: freeze(items)
868
+ });
869
+ },
870
+ cloneWithItems(partitionBy, items) {
871
+ return freeze({
872
+ ...partitionBy,
873
+ items: freeze([...partitionBy.items, ...items])
874
+ });
875
+ }
876
+ });
877
+ //#endregion
878
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/over-node.js
879
+ /**
880
+ * @internal
881
+ */
882
+ const OverNode = freeze({
883
+ is(node) {
884
+ return node.kind === "OverNode";
885
+ },
886
+ create() {
887
+ return freeze({ kind: "OverNode" });
888
+ },
889
+ cloneWithOrderByItems(overNode, items) {
890
+ return freeze({
891
+ ...overNode,
892
+ orderBy: overNode.orderBy ? OrderByNode.cloneWithItems(overNode.orderBy, items) : OrderByNode.create(items)
893
+ });
894
+ },
895
+ cloneWithPartitionByItems(overNode, items) {
896
+ return freeze({
897
+ ...overNode,
898
+ partitionBy: overNode.partitionBy ? PartitionByNode.cloneWithItems(overNode.partitionBy, items) : PartitionByNode.create(items)
899
+ });
900
+ }
901
+ });
902
+ //#endregion
903
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/from-node.js
904
+ /**
905
+ * @internal
906
+ */
907
+ const FromNode = freeze({
908
+ is(node) {
909
+ return node.kind === "FromNode";
910
+ },
911
+ create(froms) {
912
+ return freeze({
913
+ kind: "FromNode",
914
+ froms: freeze(froms)
915
+ });
916
+ },
917
+ cloneWithFroms(from, froms) {
918
+ return freeze({
919
+ ...from,
920
+ froms: freeze([...from.froms, ...froms])
921
+ });
922
+ }
923
+ });
924
+ //#endregion
925
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/group-by-node.js
926
+ /**
927
+ * @internal
928
+ */
929
+ const GroupByNode = freeze({
930
+ is(node) {
931
+ return node.kind === "GroupByNode";
932
+ },
933
+ create(items) {
934
+ return freeze({
935
+ kind: "GroupByNode",
936
+ items: freeze(items)
937
+ });
938
+ },
939
+ cloneWithItems(groupBy, items) {
940
+ return freeze({
941
+ ...groupBy,
942
+ items: freeze([...groupBy.items, ...items])
943
+ });
944
+ }
945
+ });
946
+ //#endregion
947
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/having-node.js
948
+ /**
949
+ * @internal
950
+ */
951
+ const HavingNode = freeze({
952
+ is(node) {
953
+ return node.kind === "HavingNode";
954
+ },
955
+ create(filter) {
956
+ return freeze({
957
+ kind: "HavingNode",
958
+ having: filter
959
+ });
960
+ },
961
+ cloneWithOperation(havingNode, operator, operation) {
962
+ return freeze({
963
+ ...havingNode,
964
+ having: operator === "And" ? AndNode.create(havingNode.having, operation) : OrNode.create(havingNode.having, operation)
965
+ });
966
+ }
967
+ });
968
+ //#endregion
969
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/insert-query-node.js
970
+ /**
971
+ * @internal
972
+ */
973
+ const InsertQueryNode = freeze({
974
+ is(node) {
975
+ return node.kind === "InsertQueryNode";
976
+ },
977
+ create(into, withNode, replace) {
978
+ return freeze({
979
+ kind: "InsertQueryNode",
980
+ into,
981
+ ...withNode && { with: withNode },
982
+ replace
983
+ });
984
+ },
985
+ createWithoutInto() {
986
+ return freeze({ kind: "InsertQueryNode" });
987
+ },
988
+ cloneWith(insertQuery, props) {
989
+ return freeze({
990
+ ...insertQuery,
991
+ ...props
992
+ });
993
+ }
994
+ });
995
+ //#endregion
996
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/list-node.js
997
+ /**
998
+ * @internal
999
+ */
1000
+ const ListNode = freeze({
1001
+ is(node) {
1002
+ return node.kind === "ListNode";
1003
+ },
1004
+ create(items) {
1005
+ return freeze({
1006
+ kind: "ListNode",
1007
+ items: freeze(items)
1008
+ });
1009
+ }
1010
+ });
1011
+ //#endregion
1012
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/update-query-node.js
1013
+ /**
1014
+ * @internal
1015
+ */
1016
+ const UpdateQueryNode = freeze({
1017
+ is(node) {
1018
+ return node.kind === "UpdateQueryNode";
1019
+ },
1020
+ create(tables, withNode) {
1021
+ return freeze({
1022
+ kind: "UpdateQueryNode",
1023
+ table: tables.length === 1 ? tables[0] : ListNode.create(tables),
1024
+ ...withNode && { with: withNode }
1025
+ });
1026
+ },
1027
+ createWithoutTable() {
1028
+ return freeze({ kind: "UpdateQueryNode" });
1029
+ },
1030
+ cloneWithFromItems(updateQuery, fromItems) {
1031
+ return freeze({
1032
+ ...updateQuery,
1033
+ from: updateQuery.from ? FromNode.cloneWithFroms(updateQuery.from, fromItems) : FromNode.create(fromItems)
1034
+ });
1035
+ },
1036
+ cloneWithUpdates(updateQuery, updates) {
1037
+ return freeze({
1038
+ ...updateQuery,
1039
+ updates: updateQuery.updates ? freeze([...updateQuery.updates, ...updates]) : updates
1040
+ });
1041
+ },
1042
+ cloneWithLimit(updateQuery, limit) {
1043
+ return freeze({
1044
+ ...updateQuery,
1045
+ limit
1046
+ });
1047
+ }
1048
+ });
1049
+ //#endregion
1050
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/using-node.js
1051
+ /**
1052
+ * @internal
1053
+ */
1054
+ const UsingNode = freeze({
1055
+ is(node) {
1056
+ return node.kind === "UsingNode";
1057
+ },
1058
+ create(tables) {
1059
+ return freeze({
1060
+ kind: "UsingNode",
1061
+ tables: freeze(tables)
1062
+ });
1063
+ },
1064
+ cloneWithTables(using, tables) {
1065
+ return freeze({
1066
+ ...using,
1067
+ tables: freeze([...using.tables, ...tables])
1068
+ });
1069
+ }
1070
+ });
1071
+ //#endregion
1072
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/delete-query-node.js
1073
+ /**
1074
+ * @internal
1075
+ */
1076
+ const DeleteQueryNode = freeze({
1077
+ is(node) {
1078
+ return node.kind === "DeleteQueryNode";
1079
+ },
1080
+ create(fromItems, withNode) {
1081
+ return freeze({
1082
+ kind: "DeleteQueryNode",
1083
+ from: FromNode.create(fromItems),
1084
+ ...withNode && { with: withNode }
1085
+ });
1086
+ },
1087
+ /**
1088
+ * @deprecated Use `QueryNode.cloneWithoutOrderBy` instead.
1089
+ */
1090
+ cloneWithOrderByItems: (node, items) => QueryNode.cloneWithOrderByItems(node, items),
1091
+ /**
1092
+ * @deprecated Use `QueryNode.cloneWithoutOrderBy` instead.
1093
+ */
1094
+ cloneWithoutOrderBy: (node) => QueryNode.cloneWithoutOrderBy(node),
1095
+ cloneWithLimit(deleteNode, limit) {
1096
+ return freeze({
1097
+ ...deleteNode,
1098
+ limit
1099
+ });
1100
+ },
1101
+ cloneWithoutLimit(deleteNode) {
1102
+ return freeze({
1103
+ ...deleteNode,
1104
+ limit: void 0
1105
+ });
1106
+ },
1107
+ cloneWithUsing(deleteNode, tables) {
1108
+ return freeze({
1109
+ ...deleteNode,
1110
+ using: deleteNode.using !== void 0 ? UsingNode.cloneWithTables(deleteNode.using, tables) : UsingNode.create(tables)
1111
+ });
1112
+ }
1113
+ });
1114
+ //#endregion
1115
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/where-node.js
1116
+ /**
1117
+ * @internal
1118
+ */
1119
+ const WhereNode = freeze({
1120
+ is(node) {
1121
+ return node.kind === "WhereNode";
1122
+ },
1123
+ create(filter) {
1124
+ return freeze({
1125
+ kind: "WhereNode",
1126
+ where: filter
1127
+ });
1128
+ },
1129
+ cloneWithOperation(whereNode, operator, operation) {
1130
+ return freeze({
1131
+ ...whereNode,
1132
+ where: operator === "And" ? AndNode.create(whereNode.where, operation) : OrNode.create(whereNode.where, operation)
1133
+ });
1134
+ }
1135
+ });
1136
+ //#endregion
1137
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/returning-node.js
1138
+ /**
1139
+ * @internal
1140
+ */
1141
+ const ReturningNode = freeze({
1142
+ is(node) {
1143
+ return node.kind === "ReturningNode";
1144
+ },
1145
+ create(selections) {
1146
+ return freeze({
1147
+ kind: "ReturningNode",
1148
+ selections: freeze(selections)
1149
+ });
1150
+ },
1151
+ cloneWithSelections(returning, selections) {
1152
+ return freeze({
1153
+ ...returning,
1154
+ selections: returning.selections ? freeze([...returning.selections, ...selections]) : freeze(selections)
1155
+ });
1156
+ }
1157
+ });
1158
+ //#endregion
1159
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/explain-node.js
1160
+ /**
1161
+ * @internal
1162
+ */
1163
+ const ExplainNode = freeze({
1164
+ is(node) {
1165
+ return node.kind === "ExplainNode";
1166
+ },
1167
+ create(format, options) {
1168
+ return freeze({
1169
+ kind: "ExplainNode",
1170
+ format,
1171
+ options
1172
+ });
1173
+ }
1174
+ });
1175
+ //#endregion
1176
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/when-node.js
1177
+ /**
1178
+ * @internal
1179
+ */
1180
+ const WhenNode = freeze({
1181
+ is(node) {
1182
+ return node.kind === "WhenNode";
1183
+ },
1184
+ create(condition) {
1185
+ return freeze({
1186
+ kind: "WhenNode",
1187
+ condition
1188
+ });
1189
+ },
1190
+ cloneWithResult(whenNode, result) {
1191
+ return freeze({
1192
+ ...whenNode,
1193
+ result
1194
+ });
1195
+ }
1196
+ });
1197
+ //#endregion
1198
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/merge-query-node.js
1199
+ /**
1200
+ * @internal
1201
+ */
1202
+ const MergeQueryNode = freeze({
1203
+ is(node) {
1204
+ return node.kind === "MergeQueryNode";
1205
+ },
1206
+ create(into, withNode) {
1207
+ return freeze({
1208
+ kind: "MergeQueryNode",
1209
+ into,
1210
+ ...withNode && { with: withNode }
1211
+ });
1212
+ },
1213
+ cloneWithUsing(mergeNode, using) {
1214
+ return freeze({
1215
+ ...mergeNode,
1216
+ using
1217
+ });
1218
+ },
1219
+ cloneWithWhen(mergeNode, when) {
1220
+ return freeze({
1221
+ ...mergeNode,
1222
+ whens: mergeNode.whens ? freeze([...mergeNode.whens, when]) : freeze([when])
1223
+ });
1224
+ },
1225
+ cloneWithThen(mergeNode, then) {
1226
+ return freeze({
1227
+ ...mergeNode,
1228
+ whens: mergeNode.whens ? freeze([...mergeNode.whens.slice(0, -1), WhenNode.cloneWithResult(mergeNode.whens[mergeNode.whens.length - 1], then)]) : void 0
1229
+ });
1230
+ }
1231
+ });
1232
+ //#endregion
1233
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/output-node.js
1234
+ /**
1235
+ * @internal
1236
+ */
1237
+ const OutputNode = freeze({
1238
+ is(node) {
1239
+ return node.kind === "OutputNode";
1240
+ },
1241
+ create(selections) {
1242
+ return freeze({
1243
+ kind: "OutputNode",
1244
+ selections: freeze(selections)
1245
+ });
1246
+ },
1247
+ cloneWithSelections(output, selections) {
1248
+ return freeze({
1249
+ ...output,
1250
+ selections: output.selections ? freeze([...output.selections, ...selections]) : freeze(selections)
1251
+ });
1252
+ }
1253
+ });
1254
+ //#endregion
1255
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/query-node.js
1256
+ /**
1257
+ * @internal
1258
+ */
1259
+ const QueryNode = freeze({
1260
+ is(node) {
1261
+ return SelectQueryNode.is(node) || InsertQueryNode.is(node) || UpdateQueryNode.is(node) || DeleteQueryNode.is(node) || MergeQueryNode.is(node);
1262
+ },
1263
+ cloneWithEndModifier(node, modifier) {
1264
+ return freeze({
1265
+ ...node,
1266
+ endModifiers: node.endModifiers ? freeze([...node.endModifiers, modifier]) : freeze([modifier])
1267
+ });
1268
+ },
1269
+ cloneWithWhere(node, operation) {
1270
+ return freeze({
1271
+ ...node,
1272
+ where: node.where ? WhereNode.cloneWithOperation(node.where, "And", operation) : WhereNode.create(operation)
1273
+ });
1274
+ },
1275
+ cloneWithJoin(node, join) {
1276
+ return freeze({
1277
+ ...node,
1278
+ joins: node.joins ? freeze([...node.joins, join]) : freeze([join])
1279
+ });
1280
+ },
1281
+ cloneWithReturning(node, selections) {
1282
+ return freeze({
1283
+ ...node,
1284
+ returning: node.returning ? ReturningNode.cloneWithSelections(node.returning, selections) : ReturningNode.create(selections)
1285
+ });
1286
+ },
1287
+ cloneWithoutReturning(node) {
1288
+ return freeze({
1289
+ ...node,
1290
+ returning: void 0
1291
+ });
1292
+ },
1293
+ cloneWithoutWhere(node) {
1294
+ return freeze({
1295
+ ...node,
1296
+ where: void 0
1297
+ });
1298
+ },
1299
+ cloneWithExplain(node, format, options) {
1300
+ return freeze({
1301
+ ...node,
1302
+ explain: ExplainNode.create(format, options?.toOperationNode())
1303
+ });
1304
+ },
1305
+ cloneWithTop(node, top) {
1306
+ return freeze({
1307
+ ...node,
1308
+ top
1309
+ });
1310
+ },
1311
+ cloneWithOutput(node, selections) {
1312
+ return freeze({
1313
+ ...node,
1314
+ output: node.output ? OutputNode.cloneWithSelections(node.output, selections) : OutputNode.create(selections)
1315
+ });
1316
+ },
1317
+ cloneWithOrderByItems(node, items) {
1318
+ return freeze({
1319
+ ...node,
1320
+ orderBy: node.orderBy ? OrderByNode.cloneWithItems(node.orderBy, items) : OrderByNode.create(items)
1321
+ });
1322
+ },
1323
+ cloneWithoutOrderBy(node) {
1324
+ return freeze({
1325
+ ...node,
1326
+ orderBy: void 0
1327
+ });
1328
+ }
1329
+ });
1330
+ //#endregion
1331
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/select-query-node.js
1332
+ /**
1333
+ * @internal
1334
+ */
1335
+ const SelectQueryNode = freeze({
1336
+ is(node) {
1337
+ return node.kind === "SelectQueryNode";
1338
+ },
1339
+ create(withNode) {
1340
+ return freeze({
1341
+ kind: "SelectQueryNode",
1342
+ ...withNode && { with: withNode }
1343
+ });
1344
+ },
1345
+ createFrom(fromItems, withNode) {
1346
+ return freeze({
1347
+ kind: "SelectQueryNode",
1348
+ from: FromNode.create(fromItems),
1349
+ ...withNode && { with: withNode }
1350
+ });
1351
+ },
1352
+ cloneWithSelections(select, selections) {
1353
+ return freeze({
1354
+ ...select,
1355
+ selections: select.selections ? freeze([...select.selections, ...selections]) : freeze(selections)
1356
+ });
1357
+ },
1358
+ cloneWithDistinctOn(select, expressions) {
1359
+ return freeze({
1360
+ ...select,
1361
+ distinctOn: select.distinctOn ? freeze([...select.distinctOn, ...expressions]) : freeze(expressions)
1362
+ });
1363
+ },
1364
+ cloneWithFrontModifier(select, modifier) {
1365
+ return freeze({
1366
+ ...select,
1367
+ frontModifiers: select.frontModifiers ? freeze([...select.frontModifiers, modifier]) : freeze([modifier])
1368
+ });
1369
+ },
1370
+ /**
1371
+ * @deprecated Use `QueryNode.cloneWithoutOrderBy` instead.
1372
+ */
1373
+ cloneWithOrderByItems: (node, items) => QueryNode.cloneWithOrderByItems(node, items),
1374
+ cloneWithGroupByItems(selectNode, items) {
1375
+ return freeze({
1376
+ ...selectNode,
1377
+ groupBy: selectNode.groupBy ? GroupByNode.cloneWithItems(selectNode.groupBy, items) : GroupByNode.create(items)
1378
+ });
1379
+ },
1380
+ cloneWithLimit(selectNode, limit) {
1381
+ return freeze({
1382
+ ...selectNode,
1383
+ limit
1384
+ });
1385
+ },
1386
+ cloneWithOffset(selectNode, offset) {
1387
+ return freeze({
1388
+ ...selectNode,
1389
+ offset
1390
+ });
1391
+ },
1392
+ cloneWithFetch(selectNode, fetch) {
1393
+ return freeze({
1394
+ ...selectNode,
1395
+ fetch
1396
+ });
1397
+ },
1398
+ cloneWithHaving(selectNode, operation) {
1399
+ return freeze({
1400
+ ...selectNode,
1401
+ having: selectNode.having ? HavingNode.cloneWithOperation(selectNode.having, "And", operation) : HavingNode.create(operation)
1402
+ });
1403
+ },
1404
+ cloneWithSetOperations(selectNode, setOperations) {
1405
+ return freeze({
1406
+ ...selectNode,
1407
+ setOperations: selectNode.setOperations ? freeze([...selectNode.setOperations, ...setOperations]) : freeze([...setOperations])
1408
+ });
1409
+ },
1410
+ cloneWithoutSelections(select) {
1411
+ return freeze({
1412
+ ...select,
1413
+ selections: []
1414
+ });
1415
+ },
1416
+ cloneWithoutLimit(select) {
1417
+ return freeze({
1418
+ ...select,
1419
+ limit: void 0
1420
+ });
1421
+ },
1422
+ cloneWithoutOffset(select) {
1423
+ return freeze({
1424
+ ...select,
1425
+ offset: void 0
1426
+ });
1427
+ },
1428
+ /**
1429
+ * @deprecated Use `QueryNode.cloneWithoutOrderBy` instead.
1430
+ */
1431
+ cloneWithoutOrderBy: (node) => QueryNode.cloneWithoutOrderBy(node),
1432
+ cloneWithoutGroupBy(select) {
1433
+ return freeze({
1434
+ ...select,
1435
+ groupBy: void 0
1436
+ });
1437
+ }
1438
+ });
1439
+ //#endregion
1440
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/join-builder.js
1441
+ var JoinBuilder = class JoinBuilder {
1442
+ #props;
1443
+ constructor(props) {
1444
+ this.#props = freeze(props);
1445
+ }
1446
+ on(...args) {
1447
+ return new JoinBuilder({
1448
+ ...this.#props,
1449
+ joinNode: JoinNode.cloneWithOn(this.#props.joinNode, parseValueBinaryOperationOrExpression(args))
1450
+ });
1451
+ }
1452
+ /**
1453
+ * Just like {@link WhereInterface.whereRef} but adds an item to the join's
1454
+ * `on` clause instead.
1455
+ *
1456
+ * See {@link WhereInterface.whereRef} for documentation and examples.
1457
+ */
1458
+ onRef(lhs, op, rhs) {
1459
+ return new JoinBuilder({
1460
+ ...this.#props,
1461
+ joinNode: JoinNode.cloneWithOn(this.#props.joinNode, parseReferentialBinaryOperation(lhs, op, rhs))
1462
+ });
1463
+ }
1464
+ /**
1465
+ * Adds `on true`.
1466
+ */
1467
+ onTrue() {
1468
+ return new JoinBuilder({
1469
+ ...this.#props,
1470
+ joinNode: JoinNode.cloneWithOn(this.#props.joinNode, RawNode.createWithSql("true"))
1471
+ });
1472
+ }
1473
+ /**
1474
+ * Simply calls the provided function passing `this` as the only argument. `$call` returns
1475
+ * what the provided function returns.
1476
+ */
1477
+ $call(func) {
1478
+ return func(this);
1479
+ }
1480
+ toOperationNode() {
1481
+ return this.#props.joinNode;
1482
+ }
1483
+ };
1484
+ //#endregion
1485
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/partition-by-item-node.js
1486
+ /**
1487
+ * @internal
1488
+ */
1489
+ const PartitionByItemNode = freeze({
1490
+ is(node) {
1491
+ return node.kind === "PartitionByItemNode";
1492
+ },
1493
+ create(partitionBy) {
1494
+ return freeze({
1495
+ kind: "PartitionByItemNode",
1496
+ partitionBy
1497
+ });
1498
+ }
1499
+ });
1500
+ //#endregion
1501
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/partition-by-parser.js
1502
+ function parsePartitionBy(partitionBy) {
1503
+ return parseReferenceExpressionOrList(partitionBy).map(PartitionByItemNode.create);
1504
+ }
1505
+ //#endregion
1506
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/over-builder.js
1507
+ var OverBuilder = class OverBuilder {
1508
+ #props;
1509
+ constructor(props) {
1510
+ this.#props = freeze(props);
1511
+ }
1512
+ orderBy(...args) {
1513
+ return new OverBuilder({ overNode: OverNode.cloneWithOrderByItems(this.#props.overNode, parseOrderBy(args)) });
1514
+ }
1515
+ clearOrderBy() {
1516
+ return new OverBuilder({ overNode: QueryNode.cloneWithoutOrderBy(this.#props.overNode) });
1517
+ }
1518
+ partitionBy(partitionBy) {
1519
+ return new OverBuilder({ overNode: OverNode.cloneWithPartitionByItems(this.#props.overNode, parsePartitionBy(partitionBy)) });
1520
+ }
1521
+ /**
1522
+ * Simply calls the provided function passing `this` as the only argument. `$call` returns
1523
+ * what the provided function returns.
1524
+ */
1525
+ $call(func) {
1526
+ return func(this);
1527
+ }
1528
+ toOperationNode() {
1529
+ return this.#props.overNode;
1530
+ }
1531
+ };
1532
+ //#endregion
1533
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/selection-node.js
1534
+ /**
1535
+ * @internal
1536
+ */
1537
+ const SelectionNode = freeze({
1538
+ is(node) {
1539
+ return node.kind === "SelectionNode";
1540
+ },
1541
+ create(selection) {
1542
+ return freeze({
1543
+ kind: "SelectionNode",
1544
+ selection
1545
+ });
1546
+ },
1547
+ createSelectAll() {
1548
+ return freeze({
1549
+ kind: "SelectionNode",
1550
+ selection: SelectAllNode.create()
1551
+ });
1552
+ },
1553
+ createSelectAllFromTable(table) {
1554
+ return freeze({
1555
+ kind: "SelectionNode",
1556
+ selection: ReferenceNode.createSelectAll(table)
1557
+ });
1558
+ }
1559
+ });
1560
+ //#endregion
1561
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/select-parser.js
1562
+ function parseSelectArg(selection) {
1563
+ if (isFunction(selection)) return parseSelectArg(selection(expressionBuilder()));
1564
+ else if (isReadonlyArray(selection)) return selection.map((it) => parseSelectExpression(it));
1565
+ else return [parseSelectExpression(selection)];
1566
+ }
1567
+ function parseSelectExpression(selection) {
1568
+ if (isString(selection)) return SelectionNode.create(parseAliasedStringReference(selection));
1569
+ else if (isDynamicReferenceBuilder(selection)) return SelectionNode.create(selection.toOperationNode());
1570
+ else return SelectionNode.create(parseAliasedExpression(selection));
1571
+ }
1572
+ function parseSelectAll(table) {
1573
+ if (!table) return [SelectionNode.createSelectAll()];
1574
+ else if (Array.isArray(table)) return table.map(parseSelectAllArg);
1575
+ else return [parseSelectAllArg(table)];
1576
+ }
1577
+ function parseSelectAllArg(table) {
1578
+ if (isString(table)) return SelectionNode.createSelectAllFromTable(parseTable(table));
1579
+ throw new Error(`invalid value selectAll expression: ${JSON.stringify(table)}`);
1580
+ }
1581
+ //#endregion
1582
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/no-result-error.js
1583
+ var NoResultError = class extends Error {
1584
+ /**
1585
+ * The operation node tree of the query that was executed.
1586
+ */
1587
+ node;
1588
+ constructor(node) {
1589
+ super("no result");
1590
+ this.node = node;
1591
+ }
1592
+ };
1593
+ function isNoResultErrorConstructor(fn) {
1594
+ return Object.prototype.hasOwnProperty.call(fn, "prototype");
1595
+ }
1596
+ //#endregion
1597
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/top-node.js
1598
+ /**
1599
+ * @internal
1600
+ */
1601
+ const TopNode = freeze({
1602
+ is(node) {
1603
+ return node.kind === "TopNode";
1604
+ },
1605
+ create(expression, modifiers) {
1606
+ return freeze({
1607
+ kind: "TopNode",
1608
+ expression,
1609
+ modifiers
1610
+ });
1611
+ }
1612
+ });
1613
+ //#endregion
1614
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/top-parser.js
1615
+ function parseTop(expression, modifiers) {
1616
+ if (!isNumber(expression) && !isBigInt(expression)) throw new Error(`Invalid top expression: ${expression}`);
1617
+ if (!isUndefined(modifiers) && !isTopModifiers(modifiers)) throw new Error(`Invalid top modifiers: ${modifiers}`);
1618
+ return TopNode.create(expression, modifiers);
1619
+ }
1620
+ function isTopModifiers(modifiers) {
1621
+ return modifiers === "percent" || modifiers === "with ties" || modifiers === "percent with ties";
1622
+ }
1623
+ //#endregion
1624
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/limit-node.js
1625
+ /**
1626
+ * @internal
1627
+ */
1628
+ const LimitNode = freeze({
1629
+ is(node) {
1630
+ return node.kind === "LimitNode";
1631
+ },
1632
+ create(limit) {
1633
+ return freeze({
1634
+ kind: "LimitNode",
1635
+ limit
1636
+ });
1637
+ }
1638
+ });
1639
+ //#endregion
1640
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/util/random-string.js
1641
+ const CHARS = [
1642
+ "A",
1643
+ "B",
1644
+ "C",
1645
+ "D",
1646
+ "E",
1647
+ "F",
1648
+ "G",
1649
+ "H",
1650
+ "I",
1651
+ "J",
1652
+ "K",
1653
+ "L",
1654
+ "M",
1655
+ "N",
1656
+ "O",
1657
+ "P",
1658
+ "Q",
1659
+ "R",
1660
+ "S",
1661
+ "T",
1662
+ "U",
1663
+ "V",
1664
+ "W",
1665
+ "X",
1666
+ "Y",
1667
+ "Z",
1668
+ "a",
1669
+ "b",
1670
+ "c",
1671
+ "d",
1672
+ "e",
1673
+ "f",
1674
+ "g",
1675
+ "h",
1676
+ "i",
1677
+ "j",
1678
+ "k",
1679
+ "l",
1680
+ "m",
1681
+ "n",
1682
+ "o",
1683
+ "p",
1684
+ "q",
1685
+ "r",
1686
+ "s",
1687
+ "t",
1688
+ "u",
1689
+ "v",
1690
+ "w",
1691
+ "x",
1692
+ "y",
1693
+ "z",
1694
+ "0",
1695
+ "1",
1696
+ "2",
1697
+ "3",
1698
+ "4",
1699
+ "5",
1700
+ "6",
1701
+ "7",
1702
+ "8",
1703
+ "9"
1704
+ ];
1705
+ function randomString(length) {
1706
+ let chars = "";
1707
+ for (let i = 0; i < length; ++i) chars += randomChar();
1708
+ return chars;
1709
+ }
1710
+ function randomChar() {
1711
+ return CHARS[~~(Math.random() * CHARS.length)];
1712
+ }
1713
+ //#endregion
1714
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/util/query-id.js
1715
+ function createQueryId() {
1716
+ return new LazyQueryId();
1717
+ }
1718
+ var LazyQueryId = class {
1719
+ #queryId;
1720
+ get queryId() {
1721
+ if (this.#queryId === void 0) this.#queryId = randomString(8);
1722
+ return this.#queryId;
1723
+ }
1724
+ };
1725
+ //#endregion
1726
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/util/require-all-props.js
1727
+ /**
1728
+ * Helper function to check listed properties according to given type. Check if all properties has been used when object is initialised.
1729
+ *
1730
+ * Example use:
1731
+ *
1732
+ * ```ts
1733
+ * type SomeType = { propA: string; propB?: number; }
1734
+ *
1735
+ * // propB has to be mentioned even it is optional. It still should be initialized with undefined.
1736
+ * const a: SomeType = requireAllProps<SomeType>({ propA: "value A", propB: undefined });
1737
+ *
1738
+ * // checked type is implicit for variable.
1739
+ * const b = requireAllProps<SomeType>({ propA: "value A", propB: undefined });
1740
+ * ```
1741
+ *
1742
+ * Wrong use of this helper:
1743
+ *
1744
+ * 1. Omit checked type - all checked properties will be expect as of type never
1745
+ *
1746
+ * ```ts
1747
+ * type SomeType = { propA: string; propB?: number; }
1748
+ * // const z: SomeType = requireAllProps({ propC: "no type will work" }); // Property 'propA' is missing in type '{ propC: string; }' but required in type 'SomeType'.
1749
+ * ```
1750
+ *
1751
+ * 2. Apply to spreaded object - there is no way how to check in compile time if spreaded object contains all properties
1752
+ *
1753
+ * ```ts
1754
+ * type SomeType = { propA: string; propB?: number; }
1755
+ * const y: SomeType = { propA: "" }; // valid object according to SomeType declaration
1756
+ * // const x = requireAllProps<SomeType>({ ...y }); // Argument of type '{ propA: string; propB?: number; }' is not assignable to parameter of type 'AllProps<SomeType>'.
1757
+ * ```
1758
+ *
1759
+ * @param obj object to check if all properties has been used
1760
+ * @returns untouched obj parameter is returned
1761
+ */
1762
+ function requireAllProps(obj) {
1763
+ return obj;
1764
+ }
1765
+ //#endregion
1766
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/operation-node-transformer.js
1767
+ /**
1768
+ * Transforms an operation node tree into another one.
1769
+ *
1770
+ * Kysely queries are expressed internally as a tree of objects (operation nodes).
1771
+ * `OperationNodeTransformer` takes such a tree as its input and returns a
1772
+ * transformed deep copy of it. By default the `OperationNodeTransformer`
1773
+ * does nothing. You need to override one or more methods to make it do
1774
+ * something.
1775
+ *
1776
+ * There's a method for each node type. For example if you'd like to convert
1777
+ * each identifier (table name, column name, alias etc.) from camelCase to
1778
+ * snake_case, you'd do something like this:
1779
+ *
1780
+ * ```ts
1781
+ * import { type IdentifierNode, OperationNodeTransformer } from 'kysely'
1782
+ * import snakeCase from 'lodash/snakeCase'
1783
+ *
1784
+ * class CamelCaseTransformer extends OperationNodeTransformer {
1785
+ * override transformIdentifier(node: IdentifierNode): IdentifierNode {
1786
+ * node = super.transformIdentifier(node)
1787
+ *
1788
+ * return {
1789
+ * ...node,
1790
+ * name: snakeCase(node.name),
1791
+ * }
1792
+ * }
1793
+ * }
1794
+ *
1795
+ * const transformer = new CamelCaseTransformer()
1796
+ *
1797
+ * const query = db.selectFrom('person').select(['first_name', 'last_name'])
1798
+ *
1799
+ * const tree = transformer.transformNode(query.toOperationNode())
1800
+ * ```
1801
+ */
1802
+ var OperationNodeTransformer = class {
1803
+ nodeStack = [];
1804
+ #transformers = freeze({
1805
+ AliasNode: this.transformAlias.bind(this),
1806
+ ColumnNode: this.transformColumn.bind(this),
1807
+ IdentifierNode: this.transformIdentifier.bind(this),
1808
+ SchemableIdentifierNode: this.transformSchemableIdentifier.bind(this),
1809
+ RawNode: this.transformRaw.bind(this),
1810
+ ReferenceNode: this.transformReference.bind(this),
1811
+ SelectQueryNode: this.transformSelectQuery.bind(this),
1812
+ SelectionNode: this.transformSelection.bind(this),
1813
+ TableNode: this.transformTable.bind(this),
1814
+ FromNode: this.transformFrom.bind(this),
1815
+ SelectAllNode: this.transformSelectAll.bind(this),
1816
+ AndNode: this.transformAnd.bind(this),
1817
+ OrNode: this.transformOr.bind(this),
1818
+ ValueNode: this.transformValue.bind(this),
1819
+ ValueListNode: this.transformValueList.bind(this),
1820
+ PrimitiveValueListNode: this.transformPrimitiveValueList.bind(this),
1821
+ ParensNode: this.transformParens.bind(this),
1822
+ JoinNode: this.transformJoin.bind(this),
1823
+ OperatorNode: this.transformOperator.bind(this),
1824
+ WhereNode: this.transformWhere.bind(this),
1825
+ InsertQueryNode: this.transformInsertQuery.bind(this),
1826
+ DeleteQueryNode: this.transformDeleteQuery.bind(this),
1827
+ ReturningNode: this.transformReturning.bind(this),
1828
+ CreateTableNode: this.transformCreateTable.bind(this),
1829
+ AddColumnNode: this.transformAddColumn.bind(this),
1830
+ ColumnDefinitionNode: this.transformColumnDefinition.bind(this),
1831
+ DropTableNode: this.transformDropTable.bind(this),
1832
+ DataTypeNode: this.transformDataType.bind(this),
1833
+ OrderByNode: this.transformOrderBy.bind(this),
1834
+ OrderByItemNode: this.transformOrderByItem.bind(this),
1835
+ GroupByNode: this.transformGroupBy.bind(this),
1836
+ GroupByItemNode: this.transformGroupByItem.bind(this),
1837
+ UpdateQueryNode: this.transformUpdateQuery.bind(this),
1838
+ ColumnUpdateNode: this.transformColumnUpdate.bind(this),
1839
+ LimitNode: this.transformLimit.bind(this),
1840
+ OffsetNode: this.transformOffset.bind(this),
1841
+ OnConflictNode: this.transformOnConflict.bind(this),
1842
+ OnDuplicateKeyNode: this.transformOnDuplicateKey.bind(this),
1843
+ CreateIndexNode: this.transformCreateIndex.bind(this),
1844
+ DropIndexNode: this.transformDropIndex.bind(this),
1845
+ ListNode: this.transformList.bind(this),
1846
+ PrimaryKeyConstraintNode: this.transformPrimaryKeyConstraint.bind(this),
1847
+ UniqueConstraintNode: this.transformUniqueConstraint.bind(this),
1848
+ ReferencesNode: this.transformReferences.bind(this),
1849
+ CheckConstraintNode: this.transformCheckConstraint.bind(this),
1850
+ WithNode: this.transformWith.bind(this),
1851
+ CommonTableExpressionNode: this.transformCommonTableExpression.bind(this),
1852
+ CommonTableExpressionNameNode: this.transformCommonTableExpressionName.bind(this),
1853
+ HavingNode: this.transformHaving.bind(this),
1854
+ CreateSchemaNode: this.transformCreateSchema.bind(this),
1855
+ DropSchemaNode: this.transformDropSchema.bind(this),
1856
+ AlterTableNode: this.transformAlterTable.bind(this),
1857
+ DropColumnNode: this.transformDropColumn.bind(this),
1858
+ RenameColumnNode: this.transformRenameColumn.bind(this),
1859
+ AlterColumnNode: this.transformAlterColumn.bind(this),
1860
+ ModifyColumnNode: this.transformModifyColumn.bind(this),
1861
+ AddConstraintNode: this.transformAddConstraint.bind(this),
1862
+ DropConstraintNode: this.transformDropConstraint.bind(this),
1863
+ RenameConstraintNode: this.transformRenameConstraint.bind(this),
1864
+ ForeignKeyConstraintNode: this.transformForeignKeyConstraint.bind(this),
1865
+ CreateViewNode: this.transformCreateView.bind(this),
1866
+ RefreshMaterializedViewNode: this.transformRefreshMaterializedView.bind(this),
1867
+ DropViewNode: this.transformDropView.bind(this),
1868
+ GeneratedNode: this.transformGenerated.bind(this),
1869
+ DefaultValueNode: this.transformDefaultValue.bind(this),
1870
+ OnNode: this.transformOn.bind(this),
1871
+ ValuesNode: this.transformValues.bind(this),
1872
+ SelectModifierNode: this.transformSelectModifier.bind(this),
1873
+ CreateTypeNode: this.transformCreateType.bind(this),
1874
+ DropTypeNode: this.transformDropType.bind(this),
1875
+ ExplainNode: this.transformExplain.bind(this),
1876
+ DefaultInsertValueNode: this.transformDefaultInsertValue.bind(this),
1877
+ AggregateFunctionNode: this.transformAggregateFunction.bind(this),
1878
+ OverNode: this.transformOver.bind(this),
1879
+ PartitionByNode: this.transformPartitionBy.bind(this),
1880
+ PartitionByItemNode: this.transformPartitionByItem.bind(this),
1881
+ SetOperationNode: this.transformSetOperation.bind(this),
1882
+ BinaryOperationNode: this.transformBinaryOperation.bind(this),
1883
+ UnaryOperationNode: this.transformUnaryOperation.bind(this),
1884
+ UsingNode: this.transformUsing.bind(this),
1885
+ FunctionNode: this.transformFunction.bind(this),
1886
+ CaseNode: this.transformCase.bind(this),
1887
+ WhenNode: this.transformWhen.bind(this),
1888
+ JSONReferenceNode: this.transformJSONReference.bind(this),
1889
+ JSONPathNode: this.transformJSONPath.bind(this),
1890
+ JSONPathLegNode: this.transformJSONPathLeg.bind(this),
1891
+ JSONOperatorChainNode: this.transformJSONOperatorChain.bind(this),
1892
+ TupleNode: this.transformTuple.bind(this),
1893
+ MergeQueryNode: this.transformMergeQuery.bind(this),
1894
+ MatchedNode: this.transformMatched.bind(this),
1895
+ AddIndexNode: this.transformAddIndex.bind(this),
1896
+ CastNode: this.transformCast.bind(this),
1897
+ FetchNode: this.transformFetch.bind(this),
1898
+ TopNode: this.transformTop.bind(this),
1899
+ OutputNode: this.transformOutput.bind(this),
1900
+ OrActionNode: this.transformOrAction.bind(this),
1901
+ CollateNode: this.transformCollate.bind(this)
1902
+ });
1903
+ transformNode(node, queryId) {
1904
+ if (!node) return node;
1905
+ this.nodeStack.push(node);
1906
+ const out = this.transformNodeImpl(node, queryId);
1907
+ this.nodeStack.pop();
1908
+ return freeze(out);
1909
+ }
1910
+ transformNodeImpl(node, queryId) {
1911
+ return this.#transformers[node.kind](node, queryId);
1912
+ }
1913
+ transformNodeList(list, queryId) {
1914
+ if (!list) return list;
1915
+ return freeze(list.map((node) => this.transformNode(node, queryId)));
1916
+ }
1917
+ transformSelectQuery(node, queryId) {
1918
+ return requireAllProps({
1919
+ kind: "SelectQueryNode",
1920
+ from: this.transformNode(node.from, queryId),
1921
+ selections: this.transformNodeList(node.selections, queryId),
1922
+ distinctOn: this.transformNodeList(node.distinctOn, queryId),
1923
+ joins: this.transformNodeList(node.joins, queryId),
1924
+ groupBy: this.transformNode(node.groupBy, queryId),
1925
+ orderBy: this.transformNode(node.orderBy, queryId),
1926
+ where: this.transformNode(node.where, queryId),
1927
+ frontModifiers: this.transformNodeList(node.frontModifiers, queryId),
1928
+ endModifiers: this.transformNodeList(node.endModifiers, queryId),
1929
+ limit: this.transformNode(node.limit, queryId),
1930
+ offset: this.transformNode(node.offset, queryId),
1931
+ with: this.transformNode(node.with, queryId),
1932
+ having: this.transformNode(node.having, queryId),
1933
+ explain: this.transformNode(node.explain, queryId),
1934
+ setOperations: this.transformNodeList(node.setOperations, queryId),
1935
+ fetch: this.transformNode(node.fetch, queryId),
1936
+ top: this.transformNode(node.top, queryId)
1937
+ });
1938
+ }
1939
+ transformSelection(node, queryId) {
1940
+ return requireAllProps({
1941
+ kind: "SelectionNode",
1942
+ selection: this.transformNode(node.selection, queryId)
1943
+ });
1944
+ }
1945
+ transformColumn(node, queryId) {
1946
+ return requireAllProps({
1947
+ kind: "ColumnNode",
1948
+ column: this.transformNode(node.column, queryId)
1949
+ });
1950
+ }
1951
+ transformAlias(node, queryId) {
1952
+ return requireAllProps({
1953
+ kind: "AliasNode",
1954
+ node: this.transformNode(node.node, queryId),
1955
+ alias: this.transformNode(node.alias, queryId)
1956
+ });
1957
+ }
1958
+ transformTable(node, queryId) {
1959
+ return requireAllProps({
1960
+ kind: "TableNode",
1961
+ table: this.transformNode(node.table, queryId)
1962
+ });
1963
+ }
1964
+ transformFrom(node, queryId) {
1965
+ return requireAllProps({
1966
+ kind: "FromNode",
1967
+ froms: this.transformNodeList(node.froms, queryId)
1968
+ });
1969
+ }
1970
+ transformReference(node, queryId) {
1971
+ return requireAllProps({
1972
+ kind: "ReferenceNode",
1973
+ column: this.transformNode(node.column, queryId),
1974
+ table: this.transformNode(node.table, queryId)
1975
+ });
1976
+ }
1977
+ transformAnd(node, queryId) {
1978
+ return requireAllProps({
1979
+ kind: "AndNode",
1980
+ left: this.transformNode(node.left, queryId),
1981
+ right: this.transformNode(node.right, queryId)
1982
+ });
1983
+ }
1984
+ transformOr(node, queryId) {
1985
+ return requireAllProps({
1986
+ kind: "OrNode",
1987
+ left: this.transformNode(node.left, queryId),
1988
+ right: this.transformNode(node.right, queryId)
1989
+ });
1990
+ }
1991
+ transformValueList(node, queryId) {
1992
+ return requireAllProps({
1993
+ kind: "ValueListNode",
1994
+ values: this.transformNodeList(node.values, queryId)
1995
+ });
1996
+ }
1997
+ transformParens(node, queryId) {
1998
+ return requireAllProps({
1999
+ kind: "ParensNode",
2000
+ node: this.transformNode(node.node, queryId)
2001
+ });
2002
+ }
2003
+ transformJoin(node, queryId) {
2004
+ return requireAllProps({
2005
+ kind: "JoinNode",
2006
+ joinType: node.joinType,
2007
+ table: this.transformNode(node.table, queryId),
2008
+ on: this.transformNode(node.on, queryId)
2009
+ });
2010
+ }
2011
+ transformRaw(node, queryId) {
2012
+ return requireAllProps({
2013
+ kind: "RawNode",
2014
+ sqlFragments: freeze([...node.sqlFragments]),
2015
+ parameters: this.transformNodeList(node.parameters, queryId)
2016
+ });
2017
+ }
2018
+ transformWhere(node, queryId) {
2019
+ return requireAllProps({
2020
+ kind: "WhereNode",
2021
+ where: this.transformNode(node.where, queryId)
2022
+ });
2023
+ }
2024
+ transformInsertQuery(node, queryId) {
2025
+ return requireAllProps({
2026
+ kind: "InsertQueryNode",
2027
+ into: this.transformNode(node.into, queryId),
2028
+ columns: this.transformNodeList(node.columns, queryId),
2029
+ values: this.transformNode(node.values, queryId),
2030
+ returning: this.transformNode(node.returning, queryId),
2031
+ onConflict: this.transformNode(node.onConflict, queryId),
2032
+ onDuplicateKey: this.transformNode(node.onDuplicateKey, queryId),
2033
+ endModifiers: this.transformNodeList(node.endModifiers, queryId),
2034
+ with: this.transformNode(node.with, queryId),
2035
+ ignore: node.ignore,
2036
+ orAction: this.transformNode(node.orAction, queryId),
2037
+ replace: node.replace,
2038
+ explain: this.transformNode(node.explain, queryId),
2039
+ defaultValues: node.defaultValues,
2040
+ top: this.transformNode(node.top, queryId),
2041
+ output: this.transformNode(node.output, queryId)
2042
+ });
2043
+ }
2044
+ transformValues(node, queryId) {
2045
+ return requireAllProps({
2046
+ kind: "ValuesNode",
2047
+ values: this.transformNodeList(node.values, queryId)
2048
+ });
2049
+ }
2050
+ transformDeleteQuery(node, queryId) {
2051
+ return requireAllProps({
2052
+ kind: "DeleteQueryNode",
2053
+ from: this.transformNode(node.from, queryId),
2054
+ using: this.transformNode(node.using, queryId),
2055
+ joins: this.transformNodeList(node.joins, queryId),
2056
+ where: this.transformNode(node.where, queryId),
2057
+ returning: this.transformNode(node.returning, queryId),
2058
+ endModifiers: this.transformNodeList(node.endModifiers, queryId),
2059
+ with: this.transformNode(node.with, queryId),
2060
+ orderBy: this.transformNode(node.orderBy, queryId),
2061
+ limit: this.transformNode(node.limit, queryId),
2062
+ explain: this.transformNode(node.explain, queryId),
2063
+ top: this.transformNode(node.top, queryId),
2064
+ output: this.transformNode(node.output, queryId)
2065
+ });
2066
+ }
2067
+ transformReturning(node, queryId) {
2068
+ return requireAllProps({
2069
+ kind: "ReturningNode",
2070
+ selections: this.transformNodeList(node.selections, queryId)
2071
+ });
2072
+ }
2073
+ transformCreateTable(node, queryId) {
2074
+ return requireAllProps({
2075
+ kind: "CreateTableNode",
2076
+ table: this.transformNode(node.table, queryId),
2077
+ columns: this.transformNodeList(node.columns, queryId),
2078
+ constraints: this.transformNodeList(node.constraints, queryId),
2079
+ temporary: node.temporary,
2080
+ ifNotExists: node.ifNotExists,
2081
+ onCommit: node.onCommit,
2082
+ frontModifiers: this.transformNodeList(node.frontModifiers, queryId),
2083
+ endModifiers: this.transformNodeList(node.endModifiers, queryId),
2084
+ selectQuery: this.transformNode(node.selectQuery, queryId)
2085
+ });
2086
+ }
2087
+ transformColumnDefinition(node, queryId) {
2088
+ return requireAllProps({
2089
+ kind: "ColumnDefinitionNode",
2090
+ column: this.transformNode(node.column, queryId),
2091
+ dataType: this.transformNode(node.dataType, queryId),
2092
+ references: this.transformNode(node.references, queryId),
2093
+ primaryKey: node.primaryKey,
2094
+ autoIncrement: node.autoIncrement,
2095
+ unique: node.unique,
2096
+ notNull: node.notNull,
2097
+ unsigned: node.unsigned,
2098
+ defaultTo: this.transformNode(node.defaultTo, queryId),
2099
+ check: this.transformNode(node.check, queryId),
2100
+ generated: this.transformNode(node.generated, queryId),
2101
+ frontModifiers: this.transformNodeList(node.frontModifiers, queryId),
2102
+ endModifiers: this.transformNodeList(node.endModifiers, queryId),
2103
+ nullsNotDistinct: node.nullsNotDistinct,
2104
+ identity: node.identity,
2105
+ ifNotExists: node.ifNotExists
2106
+ });
2107
+ }
2108
+ transformAddColumn(node, queryId) {
2109
+ return requireAllProps({
2110
+ kind: "AddColumnNode",
2111
+ column: this.transformNode(node.column, queryId)
2112
+ });
2113
+ }
2114
+ transformDropTable(node, queryId) {
2115
+ return requireAllProps({
2116
+ kind: "DropTableNode",
2117
+ table: this.transformNode(node.table, queryId),
2118
+ ifExists: node.ifExists,
2119
+ cascade: node.cascade
2120
+ });
2121
+ }
2122
+ transformOrderBy(node, queryId) {
2123
+ return requireAllProps({
2124
+ kind: "OrderByNode",
2125
+ items: this.transformNodeList(node.items, queryId)
2126
+ });
2127
+ }
2128
+ transformOrderByItem(node, queryId) {
2129
+ return requireAllProps({
2130
+ kind: "OrderByItemNode",
2131
+ orderBy: this.transformNode(node.orderBy, queryId),
2132
+ direction: this.transformNode(node.direction, queryId),
2133
+ collation: this.transformNode(node.collation, queryId),
2134
+ nulls: node.nulls
2135
+ });
2136
+ }
2137
+ transformGroupBy(node, queryId) {
2138
+ return requireAllProps({
2139
+ kind: "GroupByNode",
2140
+ items: this.transformNodeList(node.items, queryId)
2141
+ });
2142
+ }
2143
+ transformGroupByItem(node, queryId) {
2144
+ return requireAllProps({
2145
+ kind: "GroupByItemNode",
2146
+ groupBy: this.transformNode(node.groupBy, queryId)
2147
+ });
2148
+ }
2149
+ transformUpdateQuery(node, queryId) {
2150
+ return requireAllProps({
2151
+ kind: "UpdateQueryNode",
2152
+ table: this.transformNode(node.table, queryId),
2153
+ from: this.transformNode(node.from, queryId),
2154
+ joins: this.transformNodeList(node.joins, queryId),
2155
+ where: this.transformNode(node.where, queryId),
2156
+ updates: this.transformNodeList(node.updates, queryId),
2157
+ returning: this.transformNode(node.returning, queryId),
2158
+ endModifiers: this.transformNodeList(node.endModifiers, queryId),
2159
+ with: this.transformNode(node.with, queryId),
2160
+ explain: this.transformNode(node.explain, queryId),
2161
+ limit: this.transformNode(node.limit, queryId),
2162
+ top: this.transformNode(node.top, queryId),
2163
+ output: this.transformNode(node.output, queryId),
2164
+ orderBy: this.transformNode(node.orderBy, queryId)
2165
+ });
2166
+ }
2167
+ transformColumnUpdate(node, queryId) {
2168
+ return requireAllProps({
2169
+ kind: "ColumnUpdateNode",
2170
+ column: this.transformNode(node.column, queryId),
2171
+ value: this.transformNode(node.value, queryId)
2172
+ });
2173
+ }
2174
+ transformLimit(node, queryId) {
2175
+ return requireAllProps({
2176
+ kind: "LimitNode",
2177
+ limit: this.transformNode(node.limit, queryId)
2178
+ });
2179
+ }
2180
+ transformOffset(node, queryId) {
2181
+ return requireAllProps({
2182
+ kind: "OffsetNode",
2183
+ offset: this.transformNode(node.offset, queryId)
2184
+ });
2185
+ }
2186
+ transformOnConflict(node, queryId) {
2187
+ return requireAllProps({
2188
+ kind: "OnConflictNode",
2189
+ columns: this.transformNodeList(node.columns, queryId),
2190
+ constraint: this.transformNode(node.constraint, queryId),
2191
+ indexExpression: this.transformNode(node.indexExpression, queryId),
2192
+ indexWhere: this.transformNode(node.indexWhere, queryId),
2193
+ updates: this.transformNodeList(node.updates, queryId),
2194
+ updateWhere: this.transformNode(node.updateWhere, queryId),
2195
+ doNothing: node.doNothing
2196
+ });
2197
+ }
2198
+ transformOnDuplicateKey(node, queryId) {
2199
+ return requireAllProps({
2200
+ kind: "OnDuplicateKeyNode",
2201
+ updates: this.transformNodeList(node.updates, queryId)
2202
+ });
2203
+ }
2204
+ transformCreateIndex(node, queryId) {
2205
+ return requireAllProps({
2206
+ kind: "CreateIndexNode",
2207
+ name: this.transformNode(node.name, queryId),
2208
+ table: this.transformNode(node.table, queryId),
2209
+ columns: this.transformNodeList(node.columns, queryId),
2210
+ unique: node.unique,
2211
+ using: this.transformNode(node.using, queryId),
2212
+ ifNotExists: node.ifNotExists,
2213
+ where: this.transformNode(node.where, queryId),
2214
+ nullsNotDistinct: node.nullsNotDistinct
2215
+ });
2216
+ }
2217
+ transformList(node, queryId) {
2218
+ return requireAllProps({
2219
+ kind: "ListNode",
2220
+ items: this.transformNodeList(node.items, queryId)
2221
+ });
2222
+ }
2223
+ transformDropIndex(node, queryId) {
2224
+ return requireAllProps({
2225
+ kind: "DropIndexNode",
2226
+ name: this.transformNode(node.name, queryId),
2227
+ table: this.transformNode(node.table, queryId),
2228
+ ifExists: node.ifExists,
2229
+ cascade: node.cascade
2230
+ });
2231
+ }
2232
+ transformPrimaryKeyConstraint(node, queryId) {
2233
+ return requireAllProps({
2234
+ kind: "PrimaryKeyConstraintNode",
2235
+ columns: this.transformNodeList(node.columns, queryId),
2236
+ name: this.transformNode(node.name, queryId),
2237
+ deferrable: node.deferrable,
2238
+ initiallyDeferred: node.initiallyDeferred
2239
+ });
2240
+ }
2241
+ transformUniqueConstraint(node, queryId) {
2242
+ return requireAllProps({
2243
+ kind: "UniqueConstraintNode",
2244
+ columns: this.transformNodeList(node.columns, queryId),
2245
+ name: this.transformNode(node.name, queryId),
2246
+ nullsNotDistinct: node.nullsNotDistinct,
2247
+ deferrable: node.deferrable,
2248
+ initiallyDeferred: node.initiallyDeferred
2249
+ });
2250
+ }
2251
+ transformForeignKeyConstraint(node, queryId) {
2252
+ return requireAllProps({
2253
+ kind: "ForeignKeyConstraintNode",
2254
+ columns: this.transformNodeList(node.columns, queryId),
2255
+ references: this.transformNode(node.references, queryId),
2256
+ name: this.transformNode(node.name, queryId),
2257
+ onDelete: node.onDelete,
2258
+ onUpdate: node.onUpdate,
2259
+ deferrable: node.deferrable,
2260
+ initiallyDeferred: node.initiallyDeferred
2261
+ });
2262
+ }
2263
+ transformSetOperation(node, queryId) {
2264
+ return requireAllProps({
2265
+ kind: "SetOperationNode",
2266
+ operator: node.operator,
2267
+ expression: this.transformNode(node.expression, queryId),
2268
+ all: node.all
2269
+ });
2270
+ }
2271
+ transformReferences(node, queryId) {
2272
+ return requireAllProps({
2273
+ kind: "ReferencesNode",
2274
+ table: this.transformNode(node.table, queryId),
2275
+ columns: this.transformNodeList(node.columns, queryId),
2276
+ onDelete: node.onDelete,
2277
+ onUpdate: node.onUpdate
2278
+ });
2279
+ }
2280
+ transformCheckConstraint(node, queryId) {
2281
+ return requireAllProps({
2282
+ kind: "CheckConstraintNode",
2283
+ expression: this.transformNode(node.expression, queryId),
2284
+ name: this.transformNode(node.name, queryId)
2285
+ });
2286
+ }
2287
+ transformWith(node, queryId) {
2288
+ return requireAllProps({
2289
+ kind: "WithNode",
2290
+ expressions: this.transformNodeList(node.expressions, queryId),
2291
+ recursive: node.recursive
2292
+ });
2293
+ }
2294
+ transformCommonTableExpression(node, queryId) {
2295
+ return requireAllProps({
2296
+ kind: "CommonTableExpressionNode",
2297
+ name: this.transformNode(node.name, queryId),
2298
+ materialized: node.materialized,
2299
+ expression: this.transformNode(node.expression, queryId)
2300
+ });
2301
+ }
2302
+ transformCommonTableExpressionName(node, queryId) {
2303
+ return requireAllProps({
2304
+ kind: "CommonTableExpressionNameNode",
2305
+ table: this.transformNode(node.table, queryId),
2306
+ columns: this.transformNodeList(node.columns, queryId)
2307
+ });
2308
+ }
2309
+ transformHaving(node, queryId) {
2310
+ return requireAllProps({
2311
+ kind: "HavingNode",
2312
+ having: this.transformNode(node.having, queryId)
2313
+ });
2314
+ }
2315
+ transformCreateSchema(node, queryId) {
2316
+ return requireAllProps({
2317
+ kind: "CreateSchemaNode",
2318
+ schema: this.transformNode(node.schema, queryId),
2319
+ ifNotExists: node.ifNotExists
2320
+ });
2321
+ }
2322
+ transformDropSchema(node, queryId) {
2323
+ return requireAllProps({
2324
+ kind: "DropSchemaNode",
2325
+ schema: this.transformNode(node.schema, queryId),
2326
+ ifExists: node.ifExists,
2327
+ cascade: node.cascade
2328
+ });
2329
+ }
2330
+ transformAlterTable(node, queryId) {
2331
+ return requireAllProps({
2332
+ kind: "AlterTableNode",
2333
+ table: this.transformNode(node.table, queryId),
2334
+ renameTo: this.transformNode(node.renameTo, queryId),
2335
+ setSchema: this.transformNode(node.setSchema, queryId),
2336
+ columnAlterations: this.transformNodeList(node.columnAlterations, queryId),
2337
+ addConstraint: this.transformNode(node.addConstraint, queryId),
2338
+ dropConstraint: this.transformNode(node.dropConstraint, queryId),
2339
+ renameConstraint: this.transformNode(node.renameConstraint, queryId),
2340
+ addIndex: this.transformNode(node.addIndex, queryId),
2341
+ dropIndex: this.transformNode(node.dropIndex, queryId)
2342
+ });
2343
+ }
2344
+ transformDropColumn(node, queryId) {
2345
+ return requireAllProps({
2346
+ kind: "DropColumnNode",
2347
+ column: this.transformNode(node.column, queryId)
2348
+ });
2349
+ }
2350
+ transformRenameColumn(node, queryId) {
2351
+ return requireAllProps({
2352
+ kind: "RenameColumnNode",
2353
+ column: this.transformNode(node.column, queryId),
2354
+ renameTo: this.transformNode(node.renameTo, queryId)
2355
+ });
2356
+ }
2357
+ transformAlterColumn(node, queryId) {
2358
+ return requireAllProps({
2359
+ kind: "AlterColumnNode",
2360
+ column: this.transformNode(node.column, queryId),
2361
+ dataType: this.transformNode(node.dataType, queryId),
2362
+ dataTypeExpression: this.transformNode(node.dataTypeExpression, queryId),
2363
+ setDefault: this.transformNode(node.setDefault, queryId),
2364
+ dropDefault: node.dropDefault,
2365
+ setNotNull: node.setNotNull,
2366
+ dropNotNull: node.dropNotNull
2367
+ });
2368
+ }
2369
+ transformModifyColumn(node, queryId) {
2370
+ return requireAllProps({
2371
+ kind: "ModifyColumnNode",
2372
+ column: this.transformNode(node.column, queryId)
2373
+ });
2374
+ }
2375
+ transformAddConstraint(node, queryId) {
2376
+ return requireAllProps({
2377
+ kind: "AddConstraintNode",
2378
+ constraint: this.transformNode(node.constraint, queryId)
2379
+ });
2380
+ }
2381
+ transformDropConstraint(node, queryId) {
2382
+ return requireAllProps({
2383
+ kind: "DropConstraintNode",
2384
+ constraintName: this.transformNode(node.constraintName, queryId),
2385
+ ifExists: node.ifExists,
2386
+ modifier: node.modifier
2387
+ });
2388
+ }
2389
+ transformRenameConstraint(node, queryId) {
2390
+ return requireAllProps({
2391
+ kind: "RenameConstraintNode",
2392
+ oldName: this.transformNode(node.oldName, queryId),
2393
+ newName: this.transformNode(node.newName, queryId)
2394
+ });
2395
+ }
2396
+ transformCreateView(node, queryId) {
2397
+ return requireAllProps({
2398
+ kind: "CreateViewNode",
2399
+ name: this.transformNode(node.name, queryId),
2400
+ temporary: node.temporary,
2401
+ orReplace: node.orReplace,
2402
+ ifNotExists: node.ifNotExists,
2403
+ materialized: node.materialized,
2404
+ columns: this.transformNodeList(node.columns, queryId),
2405
+ as: this.transformNode(node.as, queryId)
2406
+ });
2407
+ }
2408
+ transformRefreshMaterializedView(node, queryId) {
2409
+ return requireAllProps({
2410
+ kind: "RefreshMaterializedViewNode",
2411
+ name: this.transformNode(node.name, queryId),
2412
+ concurrently: node.concurrently,
2413
+ withNoData: node.withNoData
2414
+ });
2415
+ }
2416
+ transformDropView(node, queryId) {
2417
+ return requireAllProps({
2418
+ kind: "DropViewNode",
2419
+ name: this.transformNode(node.name, queryId),
2420
+ ifExists: node.ifExists,
2421
+ materialized: node.materialized,
2422
+ cascade: node.cascade
2423
+ });
2424
+ }
2425
+ transformGenerated(node, queryId) {
2426
+ return requireAllProps({
2427
+ kind: "GeneratedNode",
2428
+ byDefault: node.byDefault,
2429
+ always: node.always,
2430
+ identity: node.identity,
2431
+ stored: node.stored,
2432
+ expression: this.transformNode(node.expression, queryId)
2433
+ });
2434
+ }
2435
+ transformDefaultValue(node, queryId) {
2436
+ return requireAllProps({
2437
+ kind: "DefaultValueNode",
2438
+ defaultValue: this.transformNode(node.defaultValue, queryId)
2439
+ });
2440
+ }
2441
+ transformOn(node, queryId) {
2442
+ return requireAllProps({
2443
+ kind: "OnNode",
2444
+ on: this.transformNode(node.on, queryId)
2445
+ });
2446
+ }
2447
+ transformSelectModifier(node, queryId) {
2448
+ return requireAllProps({
2449
+ kind: "SelectModifierNode",
2450
+ modifier: node.modifier,
2451
+ rawModifier: this.transformNode(node.rawModifier, queryId),
2452
+ of: this.transformNodeList(node.of, queryId)
2453
+ });
2454
+ }
2455
+ transformCreateType(node, queryId) {
2456
+ return requireAllProps({
2457
+ kind: "CreateTypeNode",
2458
+ name: this.transformNode(node.name, queryId),
2459
+ enum: this.transformNode(node.enum, queryId)
2460
+ });
2461
+ }
2462
+ transformDropType(node, queryId) {
2463
+ return requireAllProps({
2464
+ kind: "DropTypeNode",
2465
+ name: this.transformNode(node.name, queryId),
2466
+ ifExists: node.ifExists
2467
+ });
2468
+ }
2469
+ transformExplain(node, queryId) {
2470
+ return requireAllProps({
2471
+ kind: "ExplainNode",
2472
+ format: node.format,
2473
+ options: this.transformNode(node.options, queryId)
2474
+ });
2475
+ }
2476
+ transformSchemableIdentifier(node, queryId) {
2477
+ return requireAllProps({
2478
+ kind: "SchemableIdentifierNode",
2479
+ schema: this.transformNode(node.schema, queryId),
2480
+ identifier: this.transformNode(node.identifier, queryId)
2481
+ });
2482
+ }
2483
+ transformAggregateFunction(node, queryId) {
2484
+ return requireAllProps({
2485
+ kind: "AggregateFunctionNode",
2486
+ func: node.func,
2487
+ aggregated: this.transformNodeList(node.aggregated, queryId),
2488
+ distinct: node.distinct,
2489
+ orderBy: this.transformNode(node.orderBy, queryId),
2490
+ withinGroup: this.transformNode(node.withinGroup, queryId),
2491
+ filter: this.transformNode(node.filter, queryId),
2492
+ over: this.transformNode(node.over, queryId)
2493
+ });
2494
+ }
2495
+ transformOver(node, queryId) {
2496
+ return requireAllProps({
2497
+ kind: "OverNode",
2498
+ orderBy: this.transformNode(node.orderBy, queryId),
2499
+ partitionBy: this.transformNode(node.partitionBy, queryId)
2500
+ });
2501
+ }
2502
+ transformPartitionBy(node, queryId) {
2503
+ return requireAllProps({
2504
+ kind: "PartitionByNode",
2505
+ items: this.transformNodeList(node.items, queryId)
2506
+ });
2507
+ }
2508
+ transformPartitionByItem(node, queryId) {
2509
+ return requireAllProps({
2510
+ kind: "PartitionByItemNode",
2511
+ partitionBy: this.transformNode(node.partitionBy, queryId)
2512
+ });
2513
+ }
2514
+ transformBinaryOperation(node, queryId) {
2515
+ return requireAllProps({
2516
+ kind: "BinaryOperationNode",
2517
+ leftOperand: this.transformNode(node.leftOperand, queryId),
2518
+ operator: this.transformNode(node.operator, queryId),
2519
+ rightOperand: this.transformNode(node.rightOperand, queryId)
2520
+ });
2521
+ }
2522
+ transformUnaryOperation(node, queryId) {
2523
+ return requireAllProps({
2524
+ kind: "UnaryOperationNode",
2525
+ operator: this.transformNode(node.operator, queryId),
2526
+ operand: this.transformNode(node.operand, queryId)
2527
+ });
2528
+ }
2529
+ transformUsing(node, queryId) {
2530
+ return requireAllProps({
2531
+ kind: "UsingNode",
2532
+ tables: this.transformNodeList(node.tables, queryId)
2533
+ });
2534
+ }
2535
+ transformFunction(node, queryId) {
2536
+ return requireAllProps({
2537
+ kind: "FunctionNode",
2538
+ func: node.func,
2539
+ arguments: this.transformNodeList(node.arguments, queryId)
2540
+ });
2541
+ }
2542
+ transformCase(node, queryId) {
2543
+ return requireAllProps({
2544
+ kind: "CaseNode",
2545
+ value: this.transformNode(node.value, queryId),
2546
+ when: this.transformNodeList(node.when, queryId),
2547
+ else: this.transformNode(node.else, queryId),
2548
+ isStatement: node.isStatement
2549
+ });
2550
+ }
2551
+ transformWhen(node, queryId) {
2552
+ return requireAllProps({
2553
+ kind: "WhenNode",
2554
+ condition: this.transformNode(node.condition, queryId),
2555
+ result: this.transformNode(node.result, queryId)
2556
+ });
2557
+ }
2558
+ transformJSONReference(node, queryId) {
2559
+ return requireAllProps({
2560
+ kind: "JSONReferenceNode",
2561
+ reference: this.transformNode(node.reference, queryId),
2562
+ traversal: this.transformNode(node.traversal, queryId)
2563
+ });
2564
+ }
2565
+ transformJSONPath(node, queryId) {
2566
+ return requireAllProps({
2567
+ kind: "JSONPathNode",
2568
+ inOperator: this.transformNode(node.inOperator, queryId),
2569
+ pathLegs: this.transformNodeList(node.pathLegs, queryId)
2570
+ });
2571
+ }
2572
+ transformJSONPathLeg(node, _queryId) {
2573
+ return requireAllProps({
2574
+ kind: "JSONPathLegNode",
2575
+ type: node.type,
2576
+ value: node.value
2577
+ });
2578
+ }
2579
+ transformJSONOperatorChain(node, queryId) {
2580
+ return requireAllProps({
2581
+ kind: "JSONOperatorChainNode",
2582
+ operator: this.transformNode(node.operator, queryId),
2583
+ values: this.transformNodeList(node.values, queryId)
2584
+ });
2585
+ }
2586
+ transformTuple(node, queryId) {
2587
+ return requireAllProps({
2588
+ kind: "TupleNode",
2589
+ values: this.transformNodeList(node.values, queryId)
2590
+ });
2591
+ }
2592
+ transformMergeQuery(node, queryId) {
2593
+ return requireAllProps({
2594
+ kind: "MergeQueryNode",
2595
+ into: this.transformNode(node.into, queryId),
2596
+ using: this.transformNode(node.using, queryId),
2597
+ whens: this.transformNodeList(node.whens, queryId),
2598
+ with: this.transformNode(node.with, queryId),
2599
+ top: this.transformNode(node.top, queryId),
2600
+ endModifiers: this.transformNodeList(node.endModifiers, queryId),
2601
+ output: this.transformNode(node.output, queryId),
2602
+ returning: this.transformNode(node.returning, queryId)
2603
+ });
2604
+ }
2605
+ transformMatched(node, _queryId) {
2606
+ return requireAllProps({
2607
+ kind: "MatchedNode",
2608
+ not: node.not,
2609
+ bySource: node.bySource
2610
+ });
2611
+ }
2612
+ transformAddIndex(node, queryId) {
2613
+ return requireAllProps({
2614
+ kind: "AddIndexNode",
2615
+ name: this.transformNode(node.name, queryId),
2616
+ columns: this.transformNodeList(node.columns, queryId),
2617
+ unique: node.unique,
2618
+ using: this.transformNode(node.using, queryId),
2619
+ ifNotExists: node.ifNotExists
2620
+ });
2621
+ }
2622
+ transformCast(node, queryId) {
2623
+ return requireAllProps({
2624
+ kind: "CastNode",
2625
+ expression: this.transformNode(node.expression, queryId),
2626
+ dataType: this.transformNode(node.dataType, queryId)
2627
+ });
2628
+ }
2629
+ transformFetch(node, queryId) {
2630
+ return requireAllProps({
2631
+ kind: "FetchNode",
2632
+ rowCount: this.transformNode(node.rowCount, queryId),
2633
+ modifier: node.modifier
2634
+ });
2635
+ }
2636
+ transformTop(node, _queryId) {
2637
+ return requireAllProps({
2638
+ kind: "TopNode",
2639
+ expression: node.expression,
2640
+ modifiers: node.modifiers
2641
+ });
2642
+ }
2643
+ transformOutput(node, queryId) {
2644
+ return requireAllProps({
2645
+ kind: "OutputNode",
2646
+ selections: this.transformNodeList(node.selections, queryId)
2647
+ });
2648
+ }
2649
+ transformDataType(node, _queryId) {
2650
+ return node;
2651
+ }
2652
+ transformSelectAll(node, _queryId) {
2653
+ return node;
2654
+ }
2655
+ transformIdentifier(node, _queryId) {
2656
+ return node;
2657
+ }
2658
+ transformValue(node, _queryId) {
2659
+ return node;
2660
+ }
2661
+ transformPrimitiveValueList(node, _queryId) {
2662
+ return node;
2663
+ }
2664
+ transformOperator(node, _queryId) {
2665
+ return node;
2666
+ }
2667
+ transformDefaultInsertValue(node, _queryId) {
2668
+ return node;
2669
+ }
2670
+ transformOrAction(node, _queryId) {
2671
+ return node;
2672
+ }
2673
+ transformCollate(node, _queryId) {
2674
+ return node;
2675
+ }
2676
+ };
2677
+ //#endregion
2678
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/plugin/with-schema/with-schema-transformer.js
2679
+ const ROOT_OPERATION_NODES = freeze({
2680
+ AlterTableNode: true,
2681
+ CreateIndexNode: true,
2682
+ CreateSchemaNode: true,
2683
+ CreateTableNode: true,
2684
+ CreateTypeNode: true,
2685
+ CreateViewNode: true,
2686
+ RefreshMaterializedViewNode: true,
2687
+ DeleteQueryNode: true,
2688
+ DropIndexNode: true,
2689
+ DropSchemaNode: true,
2690
+ DropTableNode: true,
2691
+ DropTypeNode: true,
2692
+ DropViewNode: true,
2693
+ InsertQueryNode: true,
2694
+ RawNode: true,
2695
+ SelectQueryNode: true,
2696
+ UpdateQueryNode: true,
2697
+ MergeQueryNode: true
2698
+ });
2699
+ const SCHEMALESS_FUNCTIONS = {
2700
+ json_agg: true,
2701
+ to_json: true
2702
+ };
2703
+ var WithSchemaTransformer = class extends OperationNodeTransformer {
2704
+ #schema;
2705
+ #schemableIds = /* @__PURE__ */ new Set();
2706
+ #ctes = /* @__PURE__ */ new Set();
2707
+ constructor(schema) {
2708
+ super();
2709
+ this.#schema = schema;
2710
+ }
2711
+ transformNodeImpl(node, queryId) {
2712
+ if (!this.#isRootOperationNode(node)) return super.transformNodeImpl(node, queryId);
2713
+ const ctes = this.#collectCTEs(node);
2714
+ for (const cte of ctes) this.#ctes.add(cte);
2715
+ const tables = this.#collectSchemableIds(node);
2716
+ for (const table of tables) this.#schemableIds.add(table);
2717
+ const transformed = super.transformNodeImpl(node, queryId);
2718
+ for (const table of tables) this.#schemableIds.delete(table);
2719
+ for (const cte of ctes) this.#ctes.delete(cte);
2720
+ return transformed;
2721
+ }
2722
+ transformSchemableIdentifier(node, queryId) {
2723
+ const transformed = super.transformSchemableIdentifier(node, queryId);
2724
+ if (transformed.schema || !this.#schemableIds.has(node.identifier.name)) return transformed;
2725
+ return {
2726
+ ...transformed,
2727
+ schema: IdentifierNode.create(this.#schema)
2728
+ };
2729
+ }
2730
+ transformReferences(node, queryId) {
2731
+ const transformed = super.transformReferences(node, queryId);
2732
+ if (transformed.table.table.schema) return transformed;
2733
+ return {
2734
+ ...transformed,
2735
+ table: TableNode.createWithSchema(this.#schema, transformed.table.table.identifier.name)
2736
+ };
2737
+ }
2738
+ transformAggregateFunction(node, queryId) {
2739
+ return {
2740
+ ...super.transformAggregateFunction({
2741
+ ...node,
2742
+ aggregated: []
2743
+ }, queryId),
2744
+ aggregated: this.#transformTableArgsWithoutSchemas(node, queryId, "aggregated")
2745
+ };
2746
+ }
2747
+ transformFunction(node, queryId) {
2748
+ return {
2749
+ ...super.transformFunction({
2750
+ ...node,
2751
+ arguments: []
2752
+ }, queryId),
2753
+ arguments: this.#transformTableArgsWithoutSchemas(node, queryId, "arguments")
2754
+ };
2755
+ }
2756
+ transformSelectModifier(node, queryId) {
2757
+ return {
2758
+ ...super.transformSelectModifier({
2759
+ ...node,
2760
+ of: void 0
2761
+ }, queryId),
2762
+ of: node.of?.map((item) => TableNode.is(item) && !item.table.schema ? {
2763
+ ...item,
2764
+ table: this.transformIdentifier(item.table.identifier, queryId)
2765
+ } : this.transformNode(item, queryId))
2766
+ };
2767
+ }
2768
+ #transformTableArgsWithoutSchemas(node, queryId, argsKey) {
2769
+ return SCHEMALESS_FUNCTIONS[node.func] ? node[argsKey].map((arg) => !TableNode.is(arg) || arg.table.schema ? this.transformNode(arg, queryId) : {
2770
+ ...arg,
2771
+ table: this.transformIdentifier(arg.table.identifier, queryId)
2772
+ }) : this.transformNodeList(node[argsKey], queryId);
2773
+ }
2774
+ #isRootOperationNode(node) {
2775
+ return node.kind in ROOT_OPERATION_NODES;
2776
+ }
2777
+ #collectSchemableIds(node) {
2778
+ const schemableIds = /* @__PURE__ */ new Set();
2779
+ if ("name" in node && node.name && SchemableIdentifierNode.is(node.name)) this.#collectSchemableId(node.name, schemableIds);
2780
+ if ("from" in node && node.from) for (const from of node.from.froms) this.#collectSchemableIdsFromTableExpr(from, schemableIds);
2781
+ if ("into" in node && node.into) this.#collectSchemableIdsFromTableExpr(node.into, schemableIds);
2782
+ if ("table" in node && node.table) this.#collectSchemableIdsFromTableExpr(node.table, schemableIds);
2783
+ if ("joins" in node && node.joins) for (const join of node.joins) this.#collectSchemableIdsFromTableExpr(join.table, schemableIds);
2784
+ if ("using" in node && node.using) {
2785
+ if (JoinNode.is(node.using)) this.#collectSchemableIdsFromTableExpr(node.using.table, schemableIds);
2786
+ else this.#collectSchemableIdsFromTableExpr(node.using, schemableIds);
2787
+ }
2788
+ return schemableIds;
2789
+ }
2790
+ #collectCTEs(node) {
2791
+ const ctes = /* @__PURE__ */ new Set();
2792
+ if ("with" in node && node.with) this.#collectCTEIds(node.with, ctes);
2793
+ return ctes;
2794
+ }
2795
+ #collectSchemableIdsFromTableExpr(node, schemableIds) {
2796
+ if (TableNode.is(node)) return this.#collectSchemableId(node.table, schemableIds);
2797
+ if (AliasNode.is(node) && TableNode.is(node.node)) return this.#collectSchemableId(node.node.table, schemableIds);
2798
+ if (ListNode.is(node)) {
2799
+ for (const table of node.items) this.#collectSchemableIdsFromTableExpr(table, schemableIds);
2800
+ return;
2801
+ }
2802
+ if (UsingNode.is(node)) {
2803
+ for (const table of node.tables) this.#collectSchemableIdsFromTableExpr(table, schemableIds);
2804
+ return;
2805
+ }
2806
+ }
2807
+ #collectSchemableId(node, schemableIds) {
2808
+ const id = node.identifier.name;
2809
+ if (!this.#schemableIds.has(id) && !this.#ctes.has(id)) schemableIds.add(id);
2810
+ }
2811
+ #collectCTEIds(node, ctes) {
2812
+ for (const expr of node.expressions) {
2813
+ const cteId = expr.name.table.table.identifier.name;
2814
+ if (!this.#ctes.has(cteId)) ctes.add(cteId);
2815
+ }
2816
+ }
2817
+ };
2818
+ //#endregion
2819
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/plugin/with-schema/with-schema-plugin.js
2820
+ var WithSchemaPlugin = class {
2821
+ #transformer;
2822
+ constructor(schema) {
2823
+ this.#transformer = new WithSchemaTransformer(schema);
2824
+ }
2825
+ transformQuery(args) {
2826
+ return this.#transformer.transformNode(args.node, args.queryId);
2827
+ }
2828
+ async transformResult(args) {
2829
+ return args.result;
2830
+ }
2831
+ };
2832
+ //#endregion
2833
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/util/deferred.js
2834
+ var Deferred = class {
2835
+ #promise;
2836
+ #resolve;
2837
+ #reject;
2838
+ constructor() {
2839
+ this.#promise = new Promise((resolve, reject) => {
2840
+ this.#reject = reject;
2841
+ this.#resolve = resolve;
2842
+ });
2843
+ }
2844
+ get promise() {
2845
+ return this.#promise;
2846
+ }
2847
+ resolve = (value) => {
2848
+ if (this.#resolve) this.#resolve(value);
2849
+ };
2850
+ reject = (reason) => {
2851
+ if (this.#reject) this.#reject(reason);
2852
+ };
2853
+ };
2854
+ //#endregion
2855
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/util/provide-controlled-connection.js
2856
+ async function provideControlledConnection(connectionProvider) {
2857
+ const connectionDefer = new Deferred();
2858
+ const connectionReleaseDefer = new Deferred();
2859
+ connectionProvider.provideConnection(async (connection) => {
2860
+ connectionDefer.resolve(connection);
2861
+ return await connectionReleaseDefer.promise;
2862
+ }).catch((ex) => connectionDefer.reject(ex));
2863
+ return freeze({
2864
+ connection: await connectionDefer.promise,
2865
+ release: connectionReleaseDefer.resolve
2866
+ });
2867
+ }
2868
+ //#endregion
2869
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-executor/query-executor-base.js
2870
+ const NO_PLUGINS = freeze([]);
2871
+ var QueryExecutorBase = class {
2872
+ #plugins;
2873
+ constructor(plugins = NO_PLUGINS) {
2874
+ this.#plugins = plugins;
2875
+ }
2876
+ get plugins() {
2877
+ return this.#plugins;
2878
+ }
2879
+ transformQuery(node, queryId) {
2880
+ for (const plugin of this.#plugins) {
2881
+ const transformedNode = plugin.transformQuery({
2882
+ node,
2883
+ queryId
2884
+ });
2885
+ if (transformedNode.kind === node.kind) node = transformedNode;
2886
+ else throw new Error([
2887
+ `KyselyPlugin.transformQuery must return a node`,
2888
+ `of the same kind that was given to it.`,
2889
+ `The plugin was given a ${node.kind}`,
2890
+ `but it returned a ${transformedNode.kind}`
2891
+ ].join(" "));
2892
+ }
2893
+ return node;
2894
+ }
2895
+ async executeQuery(compiledQuery) {
2896
+ return await this.provideConnection(async (connection) => {
2897
+ const result = await connection.executeQuery(compiledQuery);
2898
+ if ("numUpdatedOrDeletedRows" in result) logOnce("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");
2899
+ return await this.#transformResult(result, compiledQuery.queryId);
2900
+ });
2901
+ }
2902
+ async *stream(compiledQuery, chunkSize) {
2903
+ const { connection, release } = await provideControlledConnection(this);
2904
+ try {
2905
+ for await (const result of connection.streamQuery(compiledQuery, chunkSize)) yield await this.#transformResult(result, compiledQuery.queryId);
2906
+ } finally {
2907
+ release();
2908
+ }
2909
+ }
2910
+ async #transformResult(result, queryId) {
2911
+ for (const plugin of this.#plugins) result = await plugin.transformResult({
2912
+ result,
2913
+ queryId
2914
+ });
2915
+ return result;
2916
+ }
2917
+ };
2918
+ const NOOP_QUERY_EXECUTOR = new class NoopQueryExecutor extends QueryExecutorBase {
2919
+ get adapter() {
2920
+ throw new Error("this query cannot be compiled to SQL");
2921
+ }
2922
+ compileQuery() {
2923
+ throw new Error("this query cannot be compiled to SQL");
2924
+ }
2925
+ provideConnection() {
2926
+ throw new Error("this query cannot be executed");
2927
+ }
2928
+ withConnectionProvider() {
2929
+ throw new Error("this query cannot have a connection provider");
2930
+ }
2931
+ withPlugin(plugin) {
2932
+ return new NoopQueryExecutor([...this.plugins, plugin]);
2933
+ }
2934
+ withPlugins(plugins) {
2935
+ return new NoopQueryExecutor([...this.plugins, ...plugins]);
2936
+ }
2937
+ withPluginAtFront(plugin) {
2938
+ return new NoopQueryExecutor([plugin, ...this.plugins]);
2939
+ }
2940
+ withoutPlugins() {
2941
+ return new NoopQueryExecutor([]);
2942
+ }
2943
+ }();
2944
+ //#endregion
2945
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/parse-utils.js
2946
+ function createJoinBuilder(joinType, table) {
2947
+ return new JoinBuilder({ joinNode: JoinNode.create(joinType, parseTableExpression(table)) });
2948
+ }
2949
+ function createOverBuilder() {
2950
+ return new OverBuilder({ overNode: OverNode.create() });
2951
+ }
2952
+ //#endregion
2953
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/join-parser.js
2954
+ function parseJoin(joinType, args) {
2955
+ if (args.length === 3) return parseSingleOnJoin(joinType, args[0], args[1], args[2]);
2956
+ else if (args.length === 2) return parseCallbackJoin(joinType, args[0], args[1]);
2957
+ else if (args.length === 1) return parseOnlessJoin(joinType, args[0]);
2958
+ else throw new Error("not implemented");
2959
+ }
2960
+ function parseCallbackJoin(joinType, from, callback) {
2961
+ return callback(createJoinBuilder(joinType, from)).toOperationNode();
2962
+ }
2963
+ function parseSingleOnJoin(joinType, from, lhsColumn, rhsColumn) {
2964
+ return JoinNode.createWithOn(joinType, parseTableExpression(from), parseReferentialBinaryOperation(lhsColumn, "=", rhsColumn));
2965
+ }
2966
+ function parseOnlessJoin(joinType, from) {
2967
+ return JoinNode.create(joinType, parseTableExpression(from));
2968
+ }
2969
+ //#endregion
2970
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/offset-node.js
2971
+ /**
2972
+ * @internal
2973
+ */
2974
+ const OffsetNode = freeze({
2975
+ is(node) {
2976
+ return node.kind === "OffsetNode";
2977
+ },
2978
+ create(offset) {
2979
+ return freeze({
2980
+ kind: "OffsetNode",
2981
+ offset
2982
+ });
2983
+ }
2984
+ });
2985
+ //#endregion
2986
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/group-by-item-node.js
2987
+ /**
2988
+ * @internal
2989
+ */
2990
+ const GroupByItemNode = freeze({
2991
+ is(node) {
2992
+ return node.kind === "GroupByItemNode";
2993
+ },
2994
+ create(groupBy) {
2995
+ return freeze({
2996
+ kind: "GroupByItemNode",
2997
+ groupBy
2998
+ });
2999
+ }
3000
+ });
3001
+ //#endregion
3002
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/group-by-parser.js
3003
+ function parseGroupBy(groupBy) {
3004
+ groupBy = isFunction(groupBy) ? groupBy(expressionBuilder()) : groupBy;
3005
+ return parseReferenceExpressionOrList(groupBy).map(GroupByItemNode.create);
3006
+ }
3007
+ //#endregion
3008
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/set-operation-node.js
3009
+ /**
3010
+ * @internal
3011
+ */
3012
+ const SetOperationNode = freeze({
3013
+ is(node) {
3014
+ return node.kind === "SetOperationNode";
3015
+ },
3016
+ create(operator, expression, all) {
3017
+ return freeze({
3018
+ kind: "SetOperationNode",
3019
+ operator,
3020
+ expression,
3021
+ all
3022
+ });
3023
+ }
3024
+ });
3025
+ //#endregion
3026
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/set-operation-parser.js
3027
+ function parseSetOperations(operator, expression, all) {
3028
+ if (isFunction(expression)) expression = expression(createExpressionBuilder());
3029
+ if (!isReadonlyArray(expression)) expression = [expression];
3030
+ return expression.map((expr) => SetOperationNode.create(operator, parseExpression(expr), all));
3031
+ }
3032
+ //#endregion
3033
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/expression/expression-wrapper.js
3034
+ var ExpressionWrapper = class ExpressionWrapper {
3035
+ #node;
3036
+ constructor(node) {
3037
+ this.#node = node;
3038
+ }
3039
+ /** @private */
3040
+ get expressionType() {}
3041
+ as(alias) {
3042
+ return new AliasedExpressionWrapper(this, alias);
3043
+ }
3044
+ or(...args) {
3045
+ return new OrWrapper(OrNode.create(this.#node, parseValueBinaryOperationOrExpression(args)));
3046
+ }
3047
+ and(...args) {
3048
+ return new AndWrapper(AndNode.create(this.#node, parseValueBinaryOperationOrExpression(args)));
3049
+ }
3050
+ /**
3051
+ * Change the output type of the expression.
3052
+ *
3053
+ * This method call doesn't change the SQL in any way. This methods simply
3054
+ * returns a copy of this `ExpressionWrapper` with a new output type.
3055
+ */
3056
+ $castTo() {
3057
+ return new ExpressionWrapper(this.#node);
3058
+ }
3059
+ /**
3060
+ * Omit null from the expression's type.
3061
+ *
3062
+ * This function can be useful in cases where you know an expression can't be
3063
+ * null, but Kysely is unable to infer it.
3064
+ *
3065
+ * This method call doesn't change the SQL in any way. This methods simply
3066
+ * returns a copy of `this` with a new output type.
3067
+ */
3068
+ $notNull() {
3069
+ return new ExpressionWrapper(this.#node);
3070
+ }
3071
+ toOperationNode() {
3072
+ return this.#node;
3073
+ }
3074
+ };
3075
+ var AliasedExpressionWrapper = class {
3076
+ #expr;
3077
+ #alias;
3078
+ constructor(expr, alias) {
3079
+ this.#expr = expr;
3080
+ this.#alias = alias;
3081
+ }
3082
+ /** @private */
3083
+ get expression() {
3084
+ return this.#expr;
3085
+ }
3086
+ /** @private */
3087
+ get alias() {
3088
+ return this.#alias;
3089
+ }
3090
+ toOperationNode() {
3091
+ return AliasNode.create(this.#expr.toOperationNode(), isOperationNodeSource(this.#alias) ? this.#alias.toOperationNode() : IdentifierNode.create(this.#alias));
3092
+ }
3093
+ };
3094
+ var OrWrapper = class OrWrapper {
3095
+ #node;
3096
+ constructor(node) {
3097
+ this.#node = node;
3098
+ }
3099
+ /** @private */
3100
+ get expressionType() {}
3101
+ as(alias) {
3102
+ return new AliasedExpressionWrapper(this, alias);
3103
+ }
3104
+ or(...args) {
3105
+ return new OrWrapper(OrNode.create(this.#node, parseValueBinaryOperationOrExpression(args)));
3106
+ }
3107
+ /**
3108
+ * Change the output type of the expression.
3109
+ *
3110
+ * This method call doesn't change the SQL in any way. This methods simply
3111
+ * returns a copy of this `OrWrapper` with a new output type.
3112
+ */
3113
+ $castTo() {
3114
+ return new OrWrapper(this.#node);
3115
+ }
3116
+ toOperationNode() {
3117
+ return ParensNode.create(this.#node);
3118
+ }
3119
+ };
3120
+ var AndWrapper = class AndWrapper {
3121
+ #node;
3122
+ constructor(node) {
3123
+ this.#node = node;
3124
+ }
3125
+ /** @private */
3126
+ get expressionType() {}
3127
+ as(alias) {
3128
+ return new AliasedExpressionWrapper(this, alias);
3129
+ }
3130
+ and(...args) {
3131
+ return new AndWrapper(AndNode.create(this.#node, parseValueBinaryOperationOrExpression(args)));
3132
+ }
3133
+ /**
3134
+ * Change the output type of the expression.
3135
+ *
3136
+ * This method call doesn't change the SQL in any way. This methods simply
3137
+ * returns a copy of this `AndWrapper` with a new output type.
3138
+ */
3139
+ $castTo() {
3140
+ return new AndWrapper(this.#node);
3141
+ }
3142
+ toOperationNode() {
3143
+ return ParensNode.create(this.#node);
3144
+ }
3145
+ };
3146
+ //#endregion
3147
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/fetch-node.js
3148
+ /**
3149
+ * @internal
3150
+ */
3151
+ const FetchNode = freeze({
3152
+ is(node) {
3153
+ return node.kind === "FetchNode";
3154
+ },
3155
+ create(rowCount, modifier) {
3156
+ return {
3157
+ kind: "FetchNode",
3158
+ rowCount: ValueNode.create(rowCount),
3159
+ modifier
3160
+ };
3161
+ }
3162
+ });
3163
+ //#endregion
3164
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/fetch-parser.js
3165
+ function parseFetch(rowCount, modifier) {
3166
+ if (!isNumber(rowCount) && !isBigInt(rowCount)) throw new Error(`Invalid fetch row count: ${rowCount}`);
3167
+ if (!isFetchModifier(modifier)) throw new Error(`Invalid fetch modifier: ${modifier}`);
3168
+ return FetchNode.create(rowCount, modifier);
3169
+ }
3170
+ function isFetchModifier(value) {
3171
+ return value === "only" || value === "with ties";
3172
+ }
3173
+ //#endregion
3174
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/select-query-builder.js
3175
+ var _a;
3176
+ var SelectQueryBuilderImpl = class {
3177
+ #props;
3178
+ constructor(props) {
3179
+ this.#props = freeze(props);
3180
+ }
3181
+ get expressionType() {}
3182
+ get isSelectQueryBuilder() {
3183
+ return true;
3184
+ }
3185
+ where(...args) {
3186
+ return new _a({
3187
+ ...this.#props,
3188
+ queryNode: QueryNode.cloneWithWhere(this.#props.queryNode, parseValueBinaryOperationOrExpression(args))
3189
+ });
3190
+ }
3191
+ whereRef(lhs, op, rhs) {
3192
+ return new _a({
3193
+ ...this.#props,
3194
+ queryNode: QueryNode.cloneWithWhere(this.#props.queryNode, parseReferentialBinaryOperation(lhs, op, rhs))
3195
+ });
3196
+ }
3197
+ having(...args) {
3198
+ return new _a({
3199
+ ...this.#props,
3200
+ queryNode: SelectQueryNode.cloneWithHaving(this.#props.queryNode, parseValueBinaryOperationOrExpression(args))
3201
+ });
3202
+ }
3203
+ havingRef(lhs, op, rhs) {
3204
+ return new _a({
3205
+ ...this.#props,
3206
+ queryNode: SelectQueryNode.cloneWithHaving(this.#props.queryNode, parseReferentialBinaryOperation(lhs, op, rhs))
3207
+ });
3208
+ }
3209
+ select(selection) {
3210
+ return new _a({
3211
+ ...this.#props,
3212
+ queryNode: SelectQueryNode.cloneWithSelections(this.#props.queryNode, parseSelectArg(selection))
3213
+ });
3214
+ }
3215
+ distinctOn(selection) {
3216
+ return new _a({
3217
+ ...this.#props,
3218
+ queryNode: SelectQueryNode.cloneWithDistinctOn(this.#props.queryNode, parseReferenceExpressionOrList(selection))
3219
+ });
3220
+ }
3221
+ modifyFront(modifier) {
3222
+ return new _a({
3223
+ ...this.#props,
3224
+ queryNode: SelectQueryNode.cloneWithFrontModifier(this.#props.queryNode, SelectModifierNode.createWithExpression(modifier.toOperationNode()))
3225
+ });
3226
+ }
3227
+ modifyEnd(modifier) {
3228
+ return new _a({
3229
+ ...this.#props,
3230
+ queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.createWithExpression(modifier.toOperationNode()))
3231
+ });
3232
+ }
3233
+ distinct() {
3234
+ return new _a({
3235
+ ...this.#props,
3236
+ queryNode: SelectQueryNode.cloneWithFrontModifier(this.#props.queryNode, SelectModifierNode.create("Distinct"))
3237
+ });
3238
+ }
3239
+ forUpdate(of) {
3240
+ return new _a({
3241
+ ...this.#props,
3242
+ queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("ForUpdate", of ? asArray(of).map(parseTable) : void 0))
3243
+ });
3244
+ }
3245
+ forShare(of) {
3246
+ return new _a({
3247
+ ...this.#props,
3248
+ queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("ForShare", of ? asArray(of).map(parseTable) : void 0))
3249
+ });
3250
+ }
3251
+ forKeyShare(of) {
3252
+ return new _a({
3253
+ ...this.#props,
3254
+ queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("ForKeyShare", of ? asArray(of).map(parseTable) : void 0))
3255
+ });
3256
+ }
3257
+ forNoKeyUpdate(of) {
3258
+ return new _a({
3259
+ ...this.#props,
3260
+ queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("ForNoKeyUpdate", of ? asArray(of).map(parseTable) : void 0))
3261
+ });
3262
+ }
3263
+ skipLocked() {
3264
+ return new _a({
3265
+ ...this.#props,
3266
+ queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("SkipLocked"))
3267
+ });
3268
+ }
3269
+ noWait() {
3270
+ return new _a({
3271
+ ...this.#props,
3272
+ queryNode: QueryNode.cloneWithEndModifier(this.#props.queryNode, SelectModifierNode.create("NoWait"))
3273
+ });
3274
+ }
3275
+ selectAll(table) {
3276
+ return new _a({
3277
+ ...this.#props,
3278
+ queryNode: SelectQueryNode.cloneWithSelections(this.#props.queryNode, parseSelectAll(table))
3279
+ });
3280
+ }
3281
+ innerJoin(...args) {
3282
+ return this.#join("InnerJoin", args);
3283
+ }
3284
+ leftJoin(...args) {
3285
+ return this.#join("LeftJoin", args);
3286
+ }
3287
+ rightJoin(...args) {
3288
+ return this.#join("RightJoin", args);
3289
+ }
3290
+ fullJoin(...args) {
3291
+ return this.#join("FullJoin", args);
3292
+ }
3293
+ crossJoin(...args) {
3294
+ return this.#join("CrossJoin", args);
3295
+ }
3296
+ innerJoinLateral(...args) {
3297
+ return this.#join("LateralInnerJoin", args);
3298
+ }
3299
+ leftJoinLateral(...args) {
3300
+ return this.#join("LateralLeftJoin", args);
3301
+ }
3302
+ crossJoinLateral(...args) {
3303
+ return this.#join("LateralCrossJoin", args);
3304
+ }
3305
+ crossApply(...args) {
3306
+ return this.#join("CrossApply", args);
3307
+ }
3308
+ outerApply(...args) {
3309
+ return this.#join("OuterApply", args);
3310
+ }
3311
+ #join(joinType, args) {
3312
+ return new _a({
3313
+ ...this.#props,
3314
+ queryNode: QueryNode.cloneWithJoin(this.#props.queryNode, parseJoin(joinType, args))
3315
+ });
3316
+ }
3317
+ orderBy(...args) {
3318
+ return new _a({
3319
+ ...this.#props,
3320
+ queryNode: QueryNode.cloneWithOrderByItems(this.#props.queryNode, parseOrderBy(args))
3321
+ });
3322
+ }
3323
+ groupBy(groupBy) {
3324
+ return new _a({
3325
+ ...this.#props,
3326
+ queryNode: SelectQueryNode.cloneWithGroupByItems(this.#props.queryNode, parseGroupBy(groupBy))
3327
+ });
3328
+ }
3329
+ limit(limit) {
3330
+ return new _a({
3331
+ ...this.#props,
3332
+ queryNode: SelectQueryNode.cloneWithLimit(this.#props.queryNode, LimitNode.create(parseValueExpression(limit)))
3333
+ });
3334
+ }
3335
+ offset(offset) {
3336
+ return new _a({
3337
+ ...this.#props,
3338
+ queryNode: SelectQueryNode.cloneWithOffset(this.#props.queryNode, OffsetNode.create(parseValueExpression(offset)))
3339
+ });
3340
+ }
3341
+ fetch(rowCount, modifier = "only") {
3342
+ return new _a({
3343
+ ...this.#props,
3344
+ queryNode: SelectQueryNode.cloneWithFetch(this.#props.queryNode, parseFetch(rowCount, modifier))
3345
+ });
3346
+ }
3347
+ top(expression, modifiers) {
3348
+ return new _a({
3349
+ ...this.#props,
3350
+ queryNode: QueryNode.cloneWithTop(this.#props.queryNode, parseTop(expression, modifiers))
3351
+ });
3352
+ }
3353
+ union(expression) {
3354
+ return new _a({
3355
+ ...this.#props,
3356
+ queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("union", expression, false))
3357
+ });
3358
+ }
3359
+ unionAll(expression) {
3360
+ return new _a({
3361
+ ...this.#props,
3362
+ queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("union", expression, true))
3363
+ });
3364
+ }
3365
+ intersect(expression) {
3366
+ return new _a({
3367
+ ...this.#props,
3368
+ queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("intersect", expression, false))
3369
+ });
3370
+ }
3371
+ intersectAll(expression) {
3372
+ return new _a({
3373
+ ...this.#props,
3374
+ queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("intersect", expression, true))
3375
+ });
3376
+ }
3377
+ except(expression) {
3378
+ return new _a({
3379
+ ...this.#props,
3380
+ queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("except", expression, false))
3381
+ });
3382
+ }
3383
+ exceptAll(expression) {
3384
+ return new _a({
3385
+ ...this.#props,
3386
+ queryNode: SelectQueryNode.cloneWithSetOperations(this.#props.queryNode, parseSetOperations("except", expression, true))
3387
+ });
3388
+ }
3389
+ as(alias) {
3390
+ return new AliasedSelectQueryBuilderImpl(this, alias);
3391
+ }
3392
+ clearSelect() {
3393
+ return new _a({
3394
+ ...this.#props,
3395
+ queryNode: SelectQueryNode.cloneWithoutSelections(this.#props.queryNode)
3396
+ });
3397
+ }
3398
+ clearWhere() {
3399
+ return new _a({
3400
+ ...this.#props,
3401
+ queryNode: QueryNode.cloneWithoutWhere(this.#props.queryNode)
3402
+ });
3403
+ }
3404
+ clearLimit() {
3405
+ return new _a({
3406
+ ...this.#props,
3407
+ queryNode: SelectQueryNode.cloneWithoutLimit(this.#props.queryNode)
3408
+ });
3409
+ }
3410
+ clearOffset() {
3411
+ return new _a({
3412
+ ...this.#props,
3413
+ queryNode: SelectQueryNode.cloneWithoutOffset(this.#props.queryNode)
3414
+ });
3415
+ }
3416
+ clearOrderBy() {
3417
+ return new _a({
3418
+ ...this.#props,
3419
+ queryNode: QueryNode.cloneWithoutOrderBy(this.#props.queryNode)
3420
+ });
3421
+ }
3422
+ clearGroupBy() {
3423
+ return new _a({
3424
+ ...this.#props,
3425
+ queryNode: SelectQueryNode.cloneWithoutGroupBy(this.#props.queryNode)
3426
+ });
3427
+ }
3428
+ $call(func) {
3429
+ return func(this);
3430
+ }
3431
+ $if(condition, func) {
3432
+ if (condition) return func(this);
3433
+ return new _a({ ...this.#props });
3434
+ }
3435
+ $castTo() {
3436
+ return new _a(this.#props);
3437
+ }
3438
+ $narrowType() {
3439
+ return new _a(this.#props);
3440
+ }
3441
+ $assertType() {
3442
+ return new _a(this.#props);
3443
+ }
3444
+ $asTuple() {
3445
+ return new ExpressionWrapper(this.toOperationNode());
3446
+ }
3447
+ $asScalar() {
3448
+ return new ExpressionWrapper(this.toOperationNode());
3449
+ }
3450
+ withPlugin(plugin) {
3451
+ return new _a({
3452
+ ...this.#props,
3453
+ executor: this.#props.executor.withPlugin(plugin)
3454
+ });
3455
+ }
3456
+ toOperationNode() {
3457
+ return this.#props.executor.transformQuery(this.#props.queryNode, this.#props.queryId);
3458
+ }
3459
+ compile() {
3460
+ return this.#props.executor.compileQuery(this.toOperationNode(), this.#props.queryId);
3461
+ }
3462
+ async execute() {
3463
+ const compiledQuery = this.compile();
3464
+ return (await this.#props.executor.executeQuery(compiledQuery)).rows;
3465
+ }
3466
+ async executeTakeFirst() {
3467
+ const [result] = await this.execute();
3468
+ return result;
3469
+ }
3470
+ async executeTakeFirstOrThrow(errorConstructor = NoResultError) {
3471
+ const result = await this.executeTakeFirst();
3472
+ if (result === void 0) throw isNoResultErrorConstructor(errorConstructor) ? new errorConstructor(this.toOperationNode()) : errorConstructor(this.toOperationNode());
3473
+ return result;
3474
+ }
3475
+ async *stream(chunkSize = 100) {
3476
+ const compiledQuery = this.compile();
3477
+ const stream = this.#props.executor.stream(compiledQuery, chunkSize);
3478
+ for await (const item of stream) yield* item.rows;
3479
+ }
3480
+ async explain(format, options) {
3481
+ return await new _a({
3482
+ ...this.#props,
3483
+ queryNode: QueryNode.cloneWithExplain(this.#props.queryNode, format, options)
3484
+ }).execute();
3485
+ }
3486
+ };
3487
+ _a = SelectQueryBuilderImpl;
3488
+ function createSelectQueryBuilder(props) {
3489
+ return new SelectQueryBuilderImpl(props);
3490
+ }
3491
+ /**
3492
+ * {@link SelectQueryBuilder} with an alias. The result of calling {@link SelectQueryBuilder.as}.
3493
+ */
3494
+ var AliasedSelectQueryBuilderImpl = class {
3495
+ #queryBuilder;
3496
+ #alias;
3497
+ constructor(queryBuilder, alias) {
3498
+ this.#queryBuilder = queryBuilder;
3499
+ this.#alias = alias;
3500
+ }
3501
+ get expression() {
3502
+ return this.#queryBuilder;
3503
+ }
3504
+ get alias() {
3505
+ return this.#alias;
3506
+ }
3507
+ get isAliasedSelectQueryBuilder() {
3508
+ return true;
3509
+ }
3510
+ toOperationNode() {
3511
+ return AliasNode.create(this.#queryBuilder.toOperationNode(), IdentifierNode.create(this.#alias));
3512
+ }
3513
+ };
3514
+ //#endregion
3515
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/aggregate-function-node.js
3516
+ /**
3517
+ * @internal
3518
+ */
3519
+ const AggregateFunctionNode = freeze({
3520
+ is(node) {
3521
+ return node.kind === "AggregateFunctionNode";
3522
+ },
3523
+ create(aggregateFunction, aggregated = []) {
3524
+ return freeze({
3525
+ kind: "AggregateFunctionNode",
3526
+ func: aggregateFunction,
3527
+ aggregated
3528
+ });
3529
+ },
3530
+ cloneWithDistinct(aggregateFunctionNode) {
3531
+ return freeze({
3532
+ ...aggregateFunctionNode,
3533
+ distinct: true
3534
+ });
3535
+ },
3536
+ cloneWithOrderBy(aggregateFunctionNode, orderItems, withinGroup = false) {
3537
+ const prop = withinGroup ? "withinGroup" : "orderBy";
3538
+ return freeze({
3539
+ ...aggregateFunctionNode,
3540
+ [prop]: aggregateFunctionNode[prop] ? OrderByNode.cloneWithItems(aggregateFunctionNode[prop], orderItems) : OrderByNode.create(orderItems)
3541
+ });
3542
+ },
3543
+ cloneWithFilter(aggregateFunctionNode, filter) {
3544
+ return freeze({
3545
+ ...aggregateFunctionNode,
3546
+ filter: aggregateFunctionNode.filter ? WhereNode.cloneWithOperation(aggregateFunctionNode.filter, "And", filter) : WhereNode.create(filter)
3547
+ });
3548
+ },
3549
+ cloneWithOrFilter(aggregateFunctionNode, filter) {
3550
+ return freeze({
3551
+ ...aggregateFunctionNode,
3552
+ filter: aggregateFunctionNode.filter ? WhereNode.cloneWithOperation(aggregateFunctionNode.filter, "Or", filter) : WhereNode.create(filter)
3553
+ });
3554
+ },
3555
+ cloneWithOver(aggregateFunctionNode, over) {
3556
+ return freeze({
3557
+ ...aggregateFunctionNode,
3558
+ over
3559
+ });
3560
+ }
3561
+ });
3562
+ //#endregion
3563
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/function-node.js
3564
+ /**
3565
+ * @internal
3566
+ */
3567
+ const FunctionNode = freeze({
3568
+ is(node) {
3569
+ return node.kind === "FunctionNode";
3570
+ },
3571
+ create(func, args) {
3572
+ return freeze({
3573
+ kind: "FunctionNode",
3574
+ func,
3575
+ arguments: args
3576
+ });
3577
+ }
3578
+ });
3579
+ //#endregion
3580
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/aggregate-function-builder.js
3581
+ var AggregateFunctionBuilder = class AggregateFunctionBuilder {
3582
+ #props;
3583
+ constructor(props) {
3584
+ this.#props = freeze(props);
3585
+ }
3586
+ /** @private */
3587
+ get expressionType() {}
3588
+ /**
3589
+ * Returns an aliased version of the function.
3590
+ *
3591
+ * In addition to slapping `as "the_alias"` to the end of the SQL,
3592
+ * this method also provides strict typing:
3593
+ *
3594
+ * ```ts
3595
+ * const result = await db
3596
+ * .selectFrom('person')
3597
+ * .select(
3598
+ * (eb) => eb.fn.count<number>('id').as('person_count')
3599
+ * )
3600
+ * .executeTakeFirstOrThrow()
3601
+ *
3602
+ * // `person_count: number` field exists in the result type.
3603
+ * console.log(result.person_count)
3604
+ * ```
3605
+ *
3606
+ * The generated SQL (PostgreSQL):
3607
+ *
3608
+ * ```sql
3609
+ * select count("id") as "person_count"
3610
+ * from "person"
3611
+ * ```
3612
+ */
3613
+ as(alias) {
3614
+ return new AliasedAggregateFunctionBuilder(this, alias);
3615
+ }
3616
+ /**
3617
+ * Adds a `distinct` clause inside the function.
3618
+ *
3619
+ * ### Examples
3620
+ *
3621
+ * ```ts
3622
+ * const result = await db
3623
+ * .selectFrom('person')
3624
+ * .select((eb) =>
3625
+ * eb.fn.count<number>('first_name').distinct().as('first_name_count')
3626
+ * )
3627
+ * .executeTakeFirstOrThrow()
3628
+ * ```
3629
+ *
3630
+ * The generated SQL (PostgreSQL):
3631
+ *
3632
+ * ```sql
3633
+ * select count(distinct "first_name") as "first_name_count"
3634
+ * from "person"
3635
+ * ```
3636
+ */
3637
+ distinct() {
3638
+ return new AggregateFunctionBuilder({
3639
+ ...this.#props,
3640
+ aggregateFunctionNode: AggregateFunctionNode.cloneWithDistinct(this.#props.aggregateFunctionNode)
3641
+ });
3642
+ }
3643
+ orderBy(...args) {
3644
+ return new AggregateFunctionBuilder({
3645
+ ...this.#props,
3646
+ aggregateFunctionNode: QueryNode.cloneWithOrderByItems(this.#props.aggregateFunctionNode, parseOrderBy(args))
3647
+ });
3648
+ }
3649
+ clearOrderBy() {
3650
+ return new AggregateFunctionBuilder({
3651
+ ...this.#props,
3652
+ aggregateFunctionNode: QueryNode.cloneWithoutOrderBy(this.#props.aggregateFunctionNode)
3653
+ });
3654
+ }
3655
+ withinGroupOrderBy(...args) {
3656
+ return new AggregateFunctionBuilder({
3657
+ ...this.#props,
3658
+ aggregateFunctionNode: AggregateFunctionNode.cloneWithOrderBy(this.#props.aggregateFunctionNode, parseOrderBy(args), true)
3659
+ });
3660
+ }
3661
+ filterWhere(...args) {
3662
+ return new AggregateFunctionBuilder({
3663
+ ...this.#props,
3664
+ aggregateFunctionNode: AggregateFunctionNode.cloneWithFilter(this.#props.aggregateFunctionNode, parseValueBinaryOperationOrExpression(args))
3665
+ });
3666
+ }
3667
+ /**
3668
+ * Adds a `filter` clause with a nested `where` clause after the function, where
3669
+ * both sides of the operator are references to columns.
3670
+ *
3671
+ * Similar to {@link WhereInterface}'s `whereRef` method.
3672
+ *
3673
+ * ### Examples
3674
+ *
3675
+ * Count people with same first and last names versus general public:
3676
+ *
3677
+ * ```ts
3678
+ * const result = await db
3679
+ * .selectFrom('person')
3680
+ * .select((eb) => [
3681
+ * eb.fn
3682
+ * .count<number>('id')
3683
+ * .filterWhereRef('first_name', '=', 'last_name')
3684
+ * .as('repeat_name_count'),
3685
+ * eb.fn.count<number>('id').as('total_count'),
3686
+ * ])
3687
+ * .executeTakeFirstOrThrow()
3688
+ * ```
3689
+ *
3690
+ * The generated SQL (PostgreSQL):
3691
+ *
3692
+ * ```sql
3693
+ * select
3694
+ * count("id") filter(where "first_name" = "last_name") as "repeat_name_count",
3695
+ * count("id") as "total_count"
3696
+ * from "person"
3697
+ * ```
3698
+ */
3699
+ filterWhereRef(lhs, op, rhs) {
3700
+ return new AggregateFunctionBuilder({
3701
+ ...this.#props,
3702
+ aggregateFunctionNode: AggregateFunctionNode.cloneWithFilter(this.#props.aggregateFunctionNode, parseReferentialBinaryOperation(lhs, op, rhs))
3703
+ });
3704
+ }
3705
+ /**
3706
+ * Adds an `over` clause (window functions) after the function.
3707
+ *
3708
+ * ### Examples
3709
+ *
3710
+ * ```ts
3711
+ * const result = await db
3712
+ * .selectFrom('person')
3713
+ * .select(
3714
+ * (eb) => eb.fn.avg<number>('age').over().as('average_age')
3715
+ * )
3716
+ * .execute()
3717
+ * ```
3718
+ *
3719
+ * The generated SQL (PostgreSQL):
3720
+ *
3721
+ * ```sql
3722
+ * select avg("age") over() as "average_age"
3723
+ * from "person"
3724
+ * ```
3725
+ *
3726
+ * Also supports passing a callback that returns an over builder,
3727
+ * allowing to add partition by and sort by clauses inside over.
3728
+ *
3729
+ * ```ts
3730
+ * const result = await db
3731
+ * .selectFrom('person')
3732
+ * .select(
3733
+ * (eb) => eb.fn.avg<number>('age').over(
3734
+ * ob => ob.partitionBy('last_name').orderBy('first_name', 'asc')
3735
+ * ).as('average_age')
3736
+ * )
3737
+ * .execute()
3738
+ * ```
3739
+ *
3740
+ * The generated SQL (PostgreSQL):
3741
+ *
3742
+ * ```sql
3743
+ * select avg("age") over(partition by "last_name" order by "first_name" asc) as "average_age"
3744
+ * from "person"
3745
+ * ```
3746
+ */
3747
+ over(over) {
3748
+ const builder = createOverBuilder();
3749
+ return new AggregateFunctionBuilder({
3750
+ ...this.#props,
3751
+ aggregateFunctionNode: AggregateFunctionNode.cloneWithOver(this.#props.aggregateFunctionNode, (over ? over(builder) : builder).toOperationNode())
3752
+ });
3753
+ }
3754
+ /**
3755
+ * Simply calls the provided function passing `this` as the only argument. `$call` returns
3756
+ * what the provided function returns.
3757
+ */
3758
+ $call(func) {
3759
+ return func(this);
3760
+ }
3761
+ /**
3762
+ * Casts the expression to the given type.
3763
+ *
3764
+ * This method call doesn't change the SQL in any way. This methods simply
3765
+ * returns a copy of this `AggregateFunctionBuilder` with a new output type.
3766
+ */
3767
+ $castTo() {
3768
+ return new AggregateFunctionBuilder(this.#props);
3769
+ }
3770
+ /**
3771
+ * Omit null from the expression's type.
3772
+ *
3773
+ * This function can be useful in cases where you know an expression can't be
3774
+ * null, but Kysely is unable to infer it.
3775
+ *
3776
+ * This method call doesn't change the SQL in any way. This methods simply
3777
+ * returns a copy of `this` with a new output type.
3778
+ */
3779
+ $notNull() {
3780
+ return new AggregateFunctionBuilder(this.#props);
3781
+ }
3782
+ toOperationNode() {
3783
+ return this.#props.aggregateFunctionNode;
3784
+ }
3785
+ };
3786
+ /**
3787
+ * {@link AggregateFunctionBuilder} with an alias. The result of calling {@link AggregateFunctionBuilder.as}.
3788
+ */
3789
+ var AliasedAggregateFunctionBuilder = class {
3790
+ #aggregateFunctionBuilder;
3791
+ #alias;
3792
+ constructor(aggregateFunctionBuilder, alias) {
3793
+ this.#aggregateFunctionBuilder = aggregateFunctionBuilder;
3794
+ this.#alias = alias;
3795
+ }
3796
+ /** @private */
3797
+ get expression() {
3798
+ return this.#aggregateFunctionBuilder;
3799
+ }
3800
+ /** @private */
3801
+ get alias() {
3802
+ return this.#alias;
3803
+ }
3804
+ toOperationNode() {
3805
+ return AliasNode.create(this.#aggregateFunctionBuilder.toOperationNode(), IdentifierNode.create(this.#alias));
3806
+ }
3807
+ };
3808
+ //#endregion
3809
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/function-module.js
3810
+ function createFunctionModule() {
3811
+ const fn = (name, args) => {
3812
+ return new ExpressionWrapper(FunctionNode.create(name, parseReferenceExpressionOrList(args ?? [])));
3813
+ };
3814
+ const agg = (name, args) => {
3815
+ return new AggregateFunctionBuilder({ aggregateFunctionNode: AggregateFunctionNode.create(name, args ? parseReferenceExpressionOrList(args) : void 0) });
3816
+ };
3817
+ return Object.assign(fn, {
3818
+ agg,
3819
+ avg(column) {
3820
+ return agg("avg", [column]);
3821
+ },
3822
+ coalesce(...values) {
3823
+ return fn("coalesce", values);
3824
+ },
3825
+ count(column) {
3826
+ return agg("count", [column]);
3827
+ },
3828
+ countAll(table) {
3829
+ return new AggregateFunctionBuilder({ aggregateFunctionNode: AggregateFunctionNode.create("count", parseSelectAll(table)) });
3830
+ },
3831
+ max(column) {
3832
+ return agg("max", [column]);
3833
+ },
3834
+ min(column) {
3835
+ return agg("min", [column]);
3836
+ },
3837
+ sum(column) {
3838
+ return agg("sum", [column]);
3839
+ },
3840
+ any(column) {
3841
+ return fn("any", [column]);
3842
+ },
3843
+ jsonAgg(table) {
3844
+ return new AggregateFunctionBuilder({ aggregateFunctionNode: AggregateFunctionNode.create("json_agg", [isString(table) ? parseTable(table) : table.toOperationNode()]) });
3845
+ },
3846
+ toJson(table) {
3847
+ return new ExpressionWrapper(FunctionNode.create("to_json", [isString(table) ? parseTable(table) : table.toOperationNode()]));
3848
+ }
3849
+ });
3850
+ }
3851
+ //#endregion
3852
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/unary-operation-node.js
3853
+ /**
3854
+ * @internal
3855
+ */
3856
+ const UnaryOperationNode = freeze({
3857
+ is(node) {
3858
+ return node.kind === "UnaryOperationNode";
3859
+ },
3860
+ create(operator, operand) {
3861
+ return freeze({
3862
+ kind: "UnaryOperationNode",
3863
+ operator,
3864
+ operand
3865
+ });
3866
+ }
3867
+ });
3868
+ //#endregion
3869
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/unary-operation-parser.js
3870
+ function parseUnaryOperation(operator, operand) {
3871
+ return UnaryOperationNode.create(OperatorNode.create(operator), parseReferenceExpression(operand));
3872
+ }
3873
+ //#endregion
3874
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/case-node.js
3875
+ /**
3876
+ * @internal
3877
+ */
3878
+ const CaseNode = freeze({
3879
+ is(node) {
3880
+ return node.kind === "CaseNode";
3881
+ },
3882
+ create(value) {
3883
+ return freeze({
3884
+ kind: "CaseNode",
3885
+ value
3886
+ });
3887
+ },
3888
+ cloneWithWhen(caseNode, when) {
3889
+ return freeze({
3890
+ ...caseNode,
3891
+ when: freeze(caseNode.when ? [...caseNode.when, when] : [when])
3892
+ });
3893
+ },
3894
+ cloneWithThen(caseNode, then) {
3895
+ return freeze({
3896
+ ...caseNode,
3897
+ when: caseNode.when ? freeze([...caseNode.when.slice(0, -1), WhenNode.cloneWithResult(caseNode.when[caseNode.when.length - 1], then)]) : void 0
3898
+ });
3899
+ },
3900
+ cloneWith(caseNode, props) {
3901
+ return freeze({
3902
+ ...caseNode,
3903
+ ...props
3904
+ });
3905
+ }
3906
+ });
3907
+ //#endregion
3908
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/case-builder.js
3909
+ var CaseBuilder = class {
3910
+ #props;
3911
+ constructor(props) {
3912
+ this.#props = freeze(props);
3913
+ }
3914
+ when(...args) {
3915
+ return new CaseThenBuilder({
3916
+ ...this.#props,
3917
+ node: CaseNode.cloneWithWhen(this.#props.node, WhenNode.create(parseValueBinaryOperationOrExpression(args)))
3918
+ });
3919
+ }
3920
+ };
3921
+ var CaseThenBuilder = class {
3922
+ #props;
3923
+ constructor(props) {
3924
+ this.#props = freeze(props);
3925
+ }
3926
+ then(valueExpression) {
3927
+ return new CaseWhenBuilder({
3928
+ ...this.#props,
3929
+ node: CaseNode.cloneWithThen(this.#props.node, isSafeImmediateValue(valueExpression) ? parseSafeImmediateValue(valueExpression) : parseValueExpression(valueExpression))
3930
+ });
3931
+ }
3932
+ };
3933
+ var CaseWhenBuilder = class {
3934
+ #props;
3935
+ constructor(props) {
3936
+ this.#props = freeze(props);
3937
+ }
3938
+ when(...args) {
3939
+ return new CaseThenBuilder({
3940
+ ...this.#props,
3941
+ node: CaseNode.cloneWithWhen(this.#props.node, WhenNode.create(parseValueBinaryOperationOrExpression(args)))
3942
+ });
3943
+ }
3944
+ else(valueExpression) {
3945
+ return new CaseEndBuilder({
3946
+ ...this.#props,
3947
+ node: CaseNode.cloneWith(this.#props.node, { else: isSafeImmediateValue(valueExpression) ? parseSafeImmediateValue(valueExpression) : parseValueExpression(valueExpression) })
3948
+ });
3949
+ }
3950
+ end() {
3951
+ return new ExpressionWrapper(CaseNode.cloneWith(this.#props.node, { isStatement: false }));
3952
+ }
3953
+ endCase() {
3954
+ return new ExpressionWrapper(CaseNode.cloneWith(this.#props.node, { isStatement: true }));
3955
+ }
3956
+ };
3957
+ var CaseEndBuilder = class {
3958
+ #props;
3959
+ constructor(props) {
3960
+ this.#props = freeze(props);
3961
+ }
3962
+ end() {
3963
+ return new ExpressionWrapper(CaseNode.cloneWith(this.#props.node, { isStatement: false }));
3964
+ }
3965
+ endCase() {
3966
+ return new ExpressionWrapper(CaseNode.cloneWith(this.#props.node, { isStatement: true }));
3967
+ }
3968
+ };
3969
+ //#endregion
3970
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/json-path-leg-node.js
3971
+ /**
3972
+ * @internal
3973
+ */
3974
+ const JSONPathLegNode = freeze({
3975
+ is(node) {
3976
+ return node.kind === "JSONPathLegNode";
3977
+ },
3978
+ create(type, value) {
3979
+ return freeze({
3980
+ kind: "JSONPathLegNode",
3981
+ type,
3982
+ value
3983
+ });
3984
+ }
3985
+ });
3986
+ //#endregion
3987
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/query-builder/json-path-builder.js
3988
+ var JSONPathBuilder = class {
3989
+ #node;
3990
+ constructor(node) {
3991
+ this.#node = node;
3992
+ }
3993
+ /**
3994
+ * Access an element of a JSON array in a specific location.
3995
+ *
3996
+ * Since there's no guarantee an element exists in the given array location, the
3997
+ * resulting type is always nullable. If you're sure the element exists, you
3998
+ * should use {@link SelectQueryBuilder.$assertType} to narrow the type safely.
3999
+ *
4000
+ * See also {@link key} to access properties of JSON objects.
4001
+ *
4002
+ * ### Examples
4003
+ *
4004
+ * ```ts
4005
+ * await db.selectFrom('person')
4006
+ * .select(eb =>
4007
+ * eb.ref('nicknames', '->').at(0).as('primary_nickname')
4008
+ * )
4009
+ * .execute()
4010
+ * ```
4011
+ *
4012
+ * The generated SQL (PostgreSQL):
4013
+ *
4014
+ * ```sql
4015
+ * select "nicknames"->0 as "primary_nickname" from "person"
4016
+ *```
4017
+ *
4018
+ * Combined with {@link key}:
4019
+ *
4020
+ * ```ts
4021
+ * db.selectFrom('person').select(eb =>
4022
+ * eb.ref('experience', '->').at(0).key('role').as('first_role')
4023
+ * )
4024
+ * ```
4025
+ *
4026
+ * The generated SQL (PostgreSQL):
4027
+ *
4028
+ * ```sql
4029
+ * select "experience"->0->'role' as "first_role" from "person"
4030
+ * ```
4031
+ *
4032
+ * You can use `'last'` to access the last element of the array in MySQL:
4033
+ *
4034
+ * ```ts
4035
+ * db.selectFrom('person').select(eb =>
4036
+ * eb.ref('nicknames', '->$').at('last').as('last_nickname')
4037
+ * )
4038
+ * ```
4039
+ *
4040
+ * The generated SQL (MySQL):
4041
+ *
4042
+ * ```sql
4043
+ * select `nicknames`->'$[last]' as `last_nickname` from `person`
4044
+ * ```
4045
+ *
4046
+ * Or `'#-1'` in SQLite:
4047
+ *
4048
+ * ```ts
4049
+ * db.selectFrom('person').select(eb =>
4050
+ * eb.ref('nicknames', '->>$').at('#-1').as('last_nickname')
4051
+ * )
4052
+ * ```
4053
+ *
4054
+ * The generated SQL (SQLite):
4055
+ *
4056
+ * ```sql
4057
+ * select "nicknames"->>'$[#-1]' as `last_nickname` from `person`
4058
+ * ```
4059
+ */
4060
+ at(index) {
4061
+ return this.#createBuilderWithPathLeg("ArrayLocation", index);
4062
+ }
4063
+ /**
4064
+ * Access a property of a JSON object.
4065
+ *
4066
+ * If a field is optional, the resulting type will be nullable.
4067
+ *
4068
+ * See also {@link at} to access elements of JSON arrays.
4069
+ *
4070
+ * ### Examples
4071
+ *
4072
+ * ```ts
4073
+ * db.selectFrom('person').select(eb =>
4074
+ * eb.ref('address', '->').key('city').as('city')
4075
+ * )
4076
+ * ```
4077
+ *
4078
+ * The generated SQL (PostgreSQL):
4079
+ *
4080
+ * ```sql
4081
+ * select "address"->'city' as "city" from "person"
4082
+ * ```
4083
+ *
4084
+ * Going deeper:
4085
+ *
4086
+ * ```ts
4087
+ * db.selectFrom('person').select(eb =>
4088
+ * eb.ref('profile', '->$').key('website').key('url').as('website_url')
4089
+ * )
4090
+ * ```
4091
+ *
4092
+ * The generated SQL (MySQL):
4093
+ *
4094
+ * ```sql
4095
+ * select `profile`->'$.website.url' as `website_url` from `person`
4096
+ * ```
4097
+ *
4098
+ * Combined with {@link at}:
4099
+ *
4100
+ * ```ts
4101
+ * db.selectFrom('person').select(eb =>
4102
+ * eb.ref('profile', '->').key('addresses').at(0).key('city').as('city')
4103
+ * )
4104
+ * ```
4105
+ *
4106
+ * The generated SQL (PostgreSQL):
4107
+ *
4108
+ * ```sql
4109
+ * select "profile"->'addresses'->0->'city' as "city" from "person"
4110
+ * ```
4111
+ */
4112
+ key(key) {
4113
+ return this.#createBuilderWithPathLeg("Member", key);
4114
+ }
4115
+ #createBuilderWithPathLeg(legType, value) {
4116
+ if (JSONReferenceNode.is(this.#node)) return new TraversedJSONPathBuilder(JSONReferenceNode.cloneWithTraversal(this.#node, JSONPathNode.is(this.#node.traversal) ? JSONPathNode.cloneWithLeg(this.#node.traversal, JSONPathLegNode.create(legType, value)) : JSONOperatorChainNode.cloneWithValue(this.#node.traversal, ValueNode.createImmediate(value))));
4117
+ return new TraversedJSONPathBuilder(JSONPathNode.cloneWithLeg(this.#node, JSONPathLegNode.create(legType, value)));
4118
+ }
4119
+ };
4120
+ var TraversedJSONPathBuilder = class TraversedJSONPathBuilder extends JSONPathBuilder {
4121
+ #node;
4122
+ constructor(node) {
4123
+ super(node);
4124
+ this.#node = node;
4125
+ }
4126
+ /** @private */
4127
+ get expressionType() {}
4128
+ as(alias) {
4129
+ return new AliasedJSONPathBuilder(this, alias);
4130
+ }
4131
+ /**
4132
+ * Change the output type of the json path.
4133
+ *
4134
+ * This method call doesn't change the SQL in any way. This methods simply
4135
+ * returns a copy of this `JSONPathBuilder` with a new output type.
4136
+ */
4137
+ $castTo() {
4138
+ return new TraversedJSONPathBuilder(this.#node);
4139
+ }
4140
+ $notNull() {
4141
+ return new TraversedJSONPathBuilder(this.#node);
4142
+ }
4143
+ toOperationNode() {
4144
+ return this.#node;
4145
+ }
4146
+ };
4147
+ var AliasedJSONPathBuilder = class {
4148
+ #jsonPath;
4149
+ #alias;
4150
+ constructor(jsonPath, alias) {
4151
+ this.#jsonPath = jsonPath;
4152
+ this.#alias = alias;
4153
+ }
4154
+ /** @private */
4155
+ get expression() {
4156
+ return this.#jsonPath;
4157
+ }
4158
+ /** @private */
4159
+ get alias() {
4160
+ return this.#alias;
4161
+ }
4162
+ toOperationNode() {
4163
+ return AliasNode.create(this.#jsonPath.toOperationNode(), isOperationNodeSource(this.#alias) ? this.#alias.toOperationNode() : IdentifierNode.create(this.#alias));
4164
+ }
4165
+ };
4166
+ //#endregion
4167
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/tuple-node.js
4168
+ /**
4169
+ * @internal
4170
+ */
4171
+ const TupleNode = freeze({
4172
+ is(node) {
4173
+ return node.kind === "TupleNode";
4174
+ },
4175
+ create(values) {
4176
+ return freeze({
4177
+ kind: "TupleNode",
4178
+ values: freeze(values)
4179
+ });
4180
+ }
4181
+ });
4182
+ //#endregion
4183
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/data-type-node.js
4184
+ const SIMPLE_COLUMN_DATA_TYPES = [
4185
+ "varchar",
4186
+ "char",
4187
+ "text",
4188
+ "integer",
4189
+ "int2",
4190
+ "int4",
4191
+ "int8",
4192
+ "smallint",
4193
+ "bigint",
4194
+ "boolean",
4195
+ "real",
4196
+ "double precision",
4197
+ "float4",
4198
+ "float8",
4199
+ "decimal",
4200
+ "numeric",
4201
+ "binary",
4202
+ "bytea",
4203
+ "date",
4204
+ "datetime",
4205
+ "time",
4206
+ "timetz",
4207
+ "timestamp",
4208
+ "timestamptz",
4209
+ "serial",
4210
+ "bigserial",
4211
+ "uuid",
4212
+ "json",
4213
+ "jsonb",
4214
+ "blob",
4215
+ "varbinary",
4216
+ "int4range",
4217
+ "int4multirange",
4218
+ "int8range",
4219
+ "int8multirange",
4220
+ "numrange",
4221
+ "nummultirange",
4222
+ "tsrange",
4223
+ "tsmultirange",
4224
+ "tstzrange",
4225
+ "tstzmultirange",
4226
+ "daterange",
4227
+ "datemultirange"
4228
+ ];
4229
+ const COLUMN_DATA_TYPE_REGEX = [
4230
+ /^varchar\(\d+\)$/,
4231
+ /^char\(\d+\)$/,
4232
+ /^decimal\(\d+, \d+\)$/,
4233
+ /^numeric\(\d+, \d+\)$/,
4234
+ /^binary\(\d+\)$/,
4235
+ /^datetime\(\d+\)$/,
4236
+ /^time\(\d+\)$/,
4237
+ /^timetz\(\d+\)$/,
4238
+ /^timestamp\(\d+\)$/,
4239
+ /^timestamptz\(\d+\)$/,
4240
+ /^varbinary\(\d+\)$/
4241
+ ];
4242
+ /**
4243
+ * @internal
4244
+ */
4245
+ const DataTypeNode = freeze({
4246
+ is(node) {
4247
+ return node.kind === "DataTypeNode";
4248
+ },
4249
+ create(dataType) {
4250
+ return freeze({
4251
+ kind: "DataTypeNode",
4252
+ dataType
4253
+ });
4254
+ }
4255
+ });
4256
+ function isColumnDataType(dataType) {
4257
+ if (SIMPLE_COLUMN_DATA_TYPES.includes(dataType)) return true;
4258
+ if (COLUMN_DATA_TYPE_REGEX.some((r) => r.test(dataType))) return true;
4259
+ return false;
4260
+ }
4261
+ //#endregion
4262
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/data-type-parser.js
4263
+ function parseDataTypeExpression(dataType) {
4264
+ if (isOperationNodeSource(dataType)) return dataType.toOperationNode();
4265
+ if (isColumnDataType(dataType)) return DataTypeNode.create(dataType);
4266
+ throw new Error(`invalid column data type ${JSON.stringify(dataType)}`);
4267
+ }
4268
+ //#endregion
4269
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/operation-node/cast-node.js
4270
+ /**
4271
+ * @internal
4272
+ */
4273
+ const CastNode = freeze({
4274
+ is(node) {
4275
+ return node.kind === "CastNode";
4276
+ },
4277
+ create(expression, dataType) {
4278
+ return freeze({
4279
+ kind: "CastNode",
4280
+ expression,
4281
+ dataType
4282
+ });
4283
+ }
4284
+ });
4285
+ //#endregion
4286
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/expression/expression-builder.js
4287
+ function createExpressionBuilder(executor = NOOP_QUERY_EXECUTOR) {
4288
+ function binary(lhs, op, rhs) {
4289
+ return new ExpressionWrapper(parseValueBinaryOperation(lhs, op, rhs));
4290
+ }
4291
+ function unary(op, expr) {
4292
+ return new ExpressionWrapper(parseUnaryOperation(op, expr));
4293
+ }
4294
+ const eb = Object.assign(binary, {
4295
+ fn: void 0,
4296
+ eb: void 0,
4297
+ selectFrom(table) {
4298
+ return createSelectQueryBuilder({
4299
+ queryId: createQueryId(),
4300
+ executor,
4301
+ queryNode: SelectQueryNode.createFrom(parseTableExpressionOrList(table))
4302
+ });
4303
+ },
4304
+ case(reference) {
4305
+ return new CaseBuilder({ node: CaseNode.create(isUndefined(reference) ? void 0 : parseReferenceExpression(reference)) });
4306
+ },
4307
+ ref(reference, op) {
4308
+ if (isUndefined(op)) return new ExpressionWrapper(parseStringReference(reference));
4309
+ return new JSONPathBuilder(parseJSONReference(reference, op));
4310
+ },
4311
+ jsonPath() {
4312
+ return new JSONPathBuilder(JSONPathNode.create());
4313
+ },
4314
+ table(table) {
4315
+ return new ExpressionWrapper(parseTable(table));
4316
+ },
4317
+ val(value) {
4318
+ return new ExpressionWrapper(parseValueExpression(value));
4319
+ },
4320
+ refTuple(...values) {
4321
+ return new ExpressionWrapper(TupleNode.create(values.map(parseReferenceExpression)));
4322
+ },
4323
+ tuple(...values) {
4324
+ return new ExpressionWrapper(TupleNode.create(values.map(parseValueExpression)));
4325
+ },
4326
+ lit(value) {
4327
+ return new ExpressionWrapper(parseSafeImmediateValue(value));
4328
+ },
4329
+ unary,
4330
+ not(expr) {
4331
+ return unary("not", expr);
4332
+ },
4333
+ exists(expr) {
4334
+ return unary("exists", expr);
4335
+ },
4336
+ neg(expr) {
4337
+ return unary("-", expr);
4338
+ },
4339
+ between(expr, start, end) {
4340
+ return new ExpressionWrapper(BinaryOperationNode.create(parseReferenceExpression(expr), OperatorNode.create("between"), AndNode.create(parseValueExpression(start), parseValueExpression(end))));
4341
+ },
4342
+ betweenSymmetric(expr, start, end) {
4343
+ return new ExpressionWrapper(BinaryOperationNode.create(parseReferenceExpression(expr), OperatorNode.create("between symmetric"), AndNode.create(parseValueExpression(start), parseValueExpression(end))));
4344
+ },
4345
+ and(exprs) {
4346
+ if (isReadonlyArray(exprs)) return new ExpressionWrapper(parseFilterList(exprs, "and"));
4347
+ return new ExpressionWrapper(parseFilterObject(exprs, "and"));
4348
+ },
4349
+ or(exprs) {
4350
+ if (isReadonlyArray(exprs)) return new ExpressionWrapper(parseFilterList(exprs, "or"));
4351
+ return new ExpressionWrapper(parseFilterObject(exprs, "or"));
4352
+ },
4353
+ parens(...args) {
4354
+ const node = parseValueBinaryOperationOrExpression(args);
4355
+ if (ParensNode.is(node)) return new ExpressionWrapper(node);
4356
+ else return new ExpressionWrapper(ParensNode.create(node));
4357
+ },
4358
+ cast(expr, dataType) {
4359
+ return new ExpressionWrapper(CastNode.create(parseReferenceExpression(expr), parseDataTypeExpression(dataType)));
4360
+ },
4361
+ withSchema(schema) {
4362
+ return createExpressionBuilder(executor.withPluginAtFront(new WithSchemaPlugin(schema)));
4363
+ }
4364
+ });
4365
+ eb.fn = createFunctionModule();
4366
+ eb.eb = eb;
4367
+ return eb;
4368
+ }
4369
+ function expressionBuilder(_) {
4370
+ return createExpressionBuilder();
4371
+ }
4372
+ //#endregion
4373
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/expression-parser.js
4374
+ function parseExpression(exp) {
4375
+ if (isOperationNodeSource(exp)) return exp.toOperationNode();
4376
+ else if (isFunction(exp)) return exp(expressionBuilder()).toOperationNode();
4377
+ throw new Error(`invalid expression: ${JSON.stringify(exp)}`);
4378
+ }
4379
+ function parseAliasedExpression(exp) {
4380
+ if (isOperationNodeSource(exp)) return exp.toOperationNode();
4381
+ else if (isFunction(exp)) return exp(expressionBuilder()).toOperationNode();
4382
+ throw new Error(`invalid aliased expression: ${JSON.stringify(exp)}`);
4383
+ }
4384
+ function isExpressionOrFactory(obj) {
4385
+ return isExpression(obj) || isAliasedExpression(obj) || isFunction(obj);
4386
+ }
4387
+ //#endregion
4388
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/dynamic/dynamic-table-builder.js
4389
+ function isAliasedDynamicTableBuilder(obj) {
4390
+ return isObject(obj) && isOperationNodeSource(obj) && isString(obj.table) && isString(obj.alias);
4391
+ }
4392
+ //#endregion
4393
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/parser/table-parser.js
4394
+ function parseTableExpressionOrList(table) {
4395
+ if (isReadonlyArray(table)) return table.map((it) => parseTableExpression(it));
4396
+ else return [parseTableExpression(table)];
4397
+ }
4398
+ function parseTableExpression(table) {
4399
+ if (isString(table)) return parseAliasedTable(table);
4400
+ else if (isAliasedDynamicTableBuilder(table)) return table.toOperationNode();
4401
+ else return parseAliasedExpression(table);
4402
+ }
4403
+ function parseAliasedTable(from) {
4404
+ const ALIAS_SEPARATOR = " as ";
4405
+ if (from.includes(ALIAS_SEPARATOR)) {
4406
+ const [table, alias] = from.split(ALIAS_SEPARATOR).map(trim);
4407
+ return AliasNode.create(parseTable(table), IdentifierNode.create(alias));
4408
+ } else return parseTable(from);
4409
+ }
4410
+ function parseTable(from) {
4411
+ const SCHEMA_SEPARATOR = ".";
4412
+ if (from.includes(SCHEMA_SEPARATOR)) {
4413
+ const [schema, table] = from.split(SCHEMA_SEPARATOR).map(trim);
4414
+ return TableNode.createWithSchema(schema, table);
4415
+ } else return TableNode.create(from);
4416
+ }
4417
+ function trim(str) {
4418
+ return str.trim();
4419
+ }
4420
+ //#endregion
4421
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/raw-builder/raw-builder.js
4422
+ var RawBuilderImpl = class RawBuilderImpl {
4423
+ #props;
4424
+ constructor(props) {
4425
+ this.#props = freeze(props);
4426
+ }
4427
+ get expressionType() {}
4428
+ get isRawBuilder() {
4429
+ return true;
4430
+ }
4431
+ as(alias) {
4432
+ return new AliasedRawBuilderImpl(this, alias);
4433
+ }
4434
+ $castTo() {
4435
+ return new RawBuilderImpl({ ...this.#props });
4436
+ }
4437
+ $notNull() {
4438
+ return new RawBuilderImpl(this.#props);
4439
+ }
4440
+ withPlugin(plugin) {
4441
+ return new RawBuilderImpl({
4442
+ ...this.#props,
4443
+ plugins: this.#props.plugins !== void 0 ? freeze([...this.#props.plugins, plugin]) : freeze([plugin])
4444
+ });
4445
+ }
4446
+ toOperationNode() {
4447
+ return this.#toOperationNode(this.#getExecutor());
4448
+ }
4449
+ compile(executorProvider) {
4450
+ return this.#compile(this.#getExecutor(executorProvider));
4451
+ }
4452
+ async execute(executorProvider) {
4453
+ const executor = this.#getExecutor(executorProvider);
4454
+ return executor.executeQuery(this.#compile(executor));
4455
+ }
4456
+ #getExecutor(executorProvider) {
4457
+ const executor = executorProvider !== void 0 ? executorProvider.getExecutor() : NOOP_QUERY_EXECUTOR;
4458
+ return this.#props.plugins !== void 0 ? executor.withPlugins(this.#props.plugins) : executor;
4459
+ }
4460
+ #toOperationNode(executor) {
4461
+ return executor.transformQuery(this.#props.rawNode, this.#props.queryId);
4462
+ }
4463
+ #compile(executor) {
4464
+ return executor.compileQuery(this.#toOperationNode(executor), this.#props.queryId);
4465
+ }
4466
+ };
4467
+ function createRawBuilder(props) {
4468
+ return new RawBuilderImpl(props);
4469
+ }
4470
+ var AliasedRawBuilderImpl = class {
4471
+ #rawBuilder;
4472
+ #alias;
4473
+ constructor(rawBuilder, alias) {
4474
+ this.#rawBuilder = rawBuilder;
4475
+ this.#alias = alias;
4476
+ }
4477
+ get expression() {
4478
+ return this.#rawBuilder;
4479
+ }
4480
+ get alias() {
4481
+ return this.#alias;
4482
+ }
4483
+ get rawBuilder() {
4484
+ return this.#rawBuilder;
4485
+ }
4486
+ toOperationNode() {
4487
+ return AliasNode.create(this.#rawBuilder.toOperationNode(), isOperationNodeSource(this.#alias) ? this.#alias.toOperationNode() : IdentifierNode.create(this.#alias));
4488
+ }
4489
+ };
4490
+ //#endregion
4491
+ //#region ../../node_modules/.pnpm/kysely@0.28.16/node_modules/kysely/dist/esm/raw-builder/sql.js
4492
+ const sql = Object.assign((sqlFragments, ...parameters) => {
4493
+ return createRawBuilder({
4494
+ queryId: createQueryId(),
4495
+ rawNode: RawNode.create(sqlFragments, parameters?.map(parseParameter) ?? [])
4496
+ });
4497
+ }, {
4498
+ ref(columnReference) {
4499
+ return createRawBuilder({
4500
+ queryId: createQueryId(),
4501
+ rawNode: RawNode.createWithChild(parseStringReference(columnReference))
4502
+ });
4503
+ },
4504
+ val(value) {
4505
+ return createRawBuilder({
4506
+ queryId: createQueryId(),
4507
+ rawNode: RawNode.createWithChild(parseValueExpression(value))
4508
+ });
4509
+ },
4510
+ value(value) {
4511
+ return this.val(value);
4512
+ },
4513
+ table(tableReference) {
4514
+ return createRawBuilder({
4515
+ queryId: createQueryId(),
4516
+ rawNode: RawNode.createWithChild(parseTable(tableReference))
4517
+ });
4518
+ },
4519
+ id(...ids) {
4520
+ const fragments = new Array(ids.length + 1).fill(".");
4521
+ fragments[0] = "";
4522
+ fragments[fragments.length - 1] = "";
4523
+ return createRawBuilder({
4524
+ queryId: createQueryId(),
4525
+ rawNode: RawNode.create(fragments, ids.map(IdentifierNode.create))
4526
+ });
4527
+ },
4528
+ lit(value) {
4529
+ return createRawBuilder({
4530
+ queryId: createQueryId(),
4531
+ rawNode: RawNode.createWithChild(ValueNode.createImmediate(value))
4532
+ });
4533
+ },
4534
+ literal(value) {
4535
+ return this.lit(value);
4536
+ },
4537
+ raw(sql) {
4538
+ return createRawBuilder({
4539
+ queryId: createQueryId(),
4540
+ rawNode: RawNode.createWithSql(sql)
4541
+ });
4542
+ },
4543
+ join(array, separator = sql`, `) {
4544
+ const nodes = new Array(Math.max(2 * array.length - 1, 0));
4545
+ const sep = separator.toOperationNode();
4546
+ for (let i = 0; i < array.length; ++i) {
4547
+ nodes[2 * i] = parseParameter(array[i]);
4548
+ if (i !== array.length - 1) nodes[2 * i + 1] = sep;
4549
+ }
4550
+ return createRawBuilder({
4551
+ queryId: createQueryId(),
4552
+ rawNode: RawNode.createWithChildren(nodes)
4553
+ });
4554
+ }
4555
+ });
4556
+ function parseParameter(param) {
4557
+ if (isOperationNodeSource(param)) return param.toOperationNode();
4558
+ return parseValueExpression(param);
4559
+ }
4560
+ //#endregion
4561
+ //#region ../reactor/dist/forwarding-logger-BKDP4JnD.js
4562
+ /**
4563
+ * Error thrown when a document is not found (no operations exist for the document ID).
4564
+ */
4565
+ var DocumentNotFoundError = class DocumentNotFoundError extends Error {
4566
+ documentId;
4567
+ /**
4568
+ * @param message Overrides the default text. A handler that knows which of
4569
+ * several documents an action reads - a relationship's source, say - says so
4570
+ * here rather than rewrapping in a bare Error, which would strip the name the
4571
+ * executor classifies by.
4572
+ */
4573
+ constructor(documentId, message) {
4574
+ super(message ?? `Document ${documentId} not found`);
4575
+ this.name = "DocumentNotFoundError";
4576
+ this.documentId = documentId;
4577
+ Error.captureStackTrace(this, DocumentNotFoundError);
4578
+ }
4579
+ /** Also true for DocumentPurgedError: only the name crosses the queue. */
4580
+ static isError(error) {
4581
+ return Error.isError(error) && (error.name === "DocumentNotFoundError" || error.name === "DocumentPurgedError");
4582
+ }
4583
+ };
4584
+ /** The document was purged; readers treat it as absent. Terminal. */
4585
+ var DocumentPurgedError = class DocumentPurgedError extends DocumentNotFoundError {
4586
+ purged = true;
4587
+ constructor(documentId, message) {
4588
+ super(documentId, message ?? `Document ${documentId} was purged`);
4589
+ this.name = "DocumentPurgedError";
4590
+ Error.captureStackTrace(this, DocumentPurgedError);
4591
+ }
4592
+ static isError(error) {
4593
+ return Error.isError(error) && error.name === "DocumentPurgedError";
4594
+ }
4595
+ };
5
4596
  /**
6
4597
  * Thrown when an operation with the same identity already exists in the store.
7
4598
  */
@@ -43,6 +4634,7 @@ const APPEND_CONDITION_FAILED_PREFIX = "Append condition failed: ";
43
4634
  * conflict, not a fault: the caller retries against the new stream heads.
44
4635
  */
45
4636
  var AppendConditionFailedError = class extends Error {
4637
+ condition;
46
4638
  constructor(condition) {
47
4639
  const streams = condition.streams.map((s) => `${s.documentId}:${s.scope}:${s.branch}@${s.revision}`).join(", ");
48
4640
  super(`${APPEND_CONDITION_FAILED_PREFIX}a read-set stream advanced [${streams}]`);
@@ -57,19 +4649,15 @@ var AppendConditionFailedError = class extends Error {
57
4649
  return message.startsWith(APPEND_CONDITION_FAILED_PREFIX);
58
4650
  }
59
4651
  };
60
- /** Actions the reactor reduces itself, onto the document scope. */
61
- const DOCUMENT_SCOPE_ACTIONS = new Set([
62
- "CREATE_DOCUMENT",
63
- "DELETE_DOCUMENT",
64
- "UPGRADE_DOCUMENT",
65
- "ADD_RELATIONSHIP",
66
- "REMOVE_RELATIONSHIP",
67
- "UPDATE_RELATIONSHIP"
68
- ]);
69
- new Set([...DOCUMENT_SCOPE_ACTIONS].filter((type) => type !== "CREATE_DOCUMENT"));
4652
+ new Set([...DOCUMENT_SCOPE_ACTION_TYPES].filter((type) => type !== "CREATE_DOCUMENT"));
4653
+ sql`action->>'type' = 'DELETE_DOCUMENT' and coalesce(error, '') = '' and coalesce("deniedReason", '') = ''`;
70
4654
  //#endregion
71
4655
  //#region src/hypercore-atomic-transaction.ts
72
4656
  var HypercoreAtomicTransaction = class {
4657
+ documentId;
4658
+ documentType;
4659
+ scope;
4660
+ branch;
73
4661
  operations = [];
74
4662
  constructor(documentId, documentType, scope, branch) {
75
4663
  this.documentId = documentId;
@@ -131,6 +4719,7 @@ function parseOperationKey(key) {
131
4719
  //#endregion
132
4720
  //#region src/hypercore-operation-store.ts
133
4721
  var HypercoreOperationStore = class {
4722
+ bee;
134
4723
  applyLock = Promise.resolve();
135
4724
  constructor(bee) {
136
4725
  this.bee = bee;
@@ -165,6 +4754,11 @@ var HypercoreOperationStore = class {
165
4754
  const atomicTxn = new HypercoreAtomicTransaction(documentId, documentType, scope, branch);
166
4755
  await fn(atomicTxn);
167
4756
  const operations = atomicTxn.getOperations();
4757
+ const marker = await this.purgeMarkerAtHead(documentId);
4758
+ if (marker !== void 0 && operations.length > 0) {
4759
+ if (!operations.every((op) => isPurgeMarker(op))) throw new DocumentPurgedError(documentId);
4760
+ return [marker];
4761
+ }
168
4762
  if (currentRevision !== revision - 1) {
169
4763
  if (revision === 0 && this.isCreate(operations)) throw new DocumentAlreadyExistsError(documentId, scope, currentRevision);
170
4764
  throw new RevisionMismatchError(currentRevision + 1, revision);
@@ -203,15 +4797,32 @@ var HypercoreOperationStore = class {
203
4797
  await batch.flush();
204
4798
  return operations.map((op) => this.toOperation(op));
205
4799
  }
4800
+ /** A purge marker is written to document/main whichever branch it erases. */
4801
+ async purgeMarkerAtHead(documentId) {
4802
+ const branch = "main";
4803
+ const head = await this.bee.get(headKey(documentId, "document", branch));
4804
+ if (!head) return;
4805
+ const index = head.value.index;
4806
+ const stored = (await this.bee.get(operationKey(documentId, "document", branch, index)))?.value;
4807
+ return stored && isPurgeMarker(stored) ? this.toOperation(stored) : void 0;
4808
+ }
206
4809
  isCreate(operations) {
207
4810
  return operations.some((op) => op.action.type === "CREATE_DOCUMENT");
208
4811
  }
4812
+ /**
4813
+ * The paging cursor encodes the index to resume from (one past the last
4814
+ * row returned), not the last row's own index; "" or "0" (or anything
4815
+ * unparsable) means the start of the stream. This keeps "0" an unambiguous
4816
+ * start-of-stream sentinel even when a page ends at index 0, which would
4817
+ * otherwise make `nextCursor` equal the start cursor and loop a caller that
4818
+ * walks pages forever. Mirrors the encoding in the Kysely store.
4819
+ */
209
4820
  async getSince(documentId, scope, branch, revision, filter, paging, signal) {
210
4821
  if (signal?.aborted) throw new Error("Operation aborted");
211
4822
  const prefix = operationPrefix(documentId, scope, branch);
212
4823
  const startIndex = revision + 1;
213
- const cursorIndex = paging?.cursor && parseInt(paging.cursor, 10) > 0 ? parseInt(paging.cursor, 10) + 1 : startIndex;
214
- const gt = prefix + pad(Math.max(startIndex, cursorIndex) - 1);
4824
+ const parsedCursor = paging?.cursor ? Number.parseInt(paging.cursor, 10) : NaN;
4825
+ const gt = prefix + pad(Math.max(startIndex, Number.isFinite(parsedCursor) && parsedCursor > 0 ? parsedCursor : startIndex) - 1);
215
4826
  const lt = prefix + RANGE_UPPER_BOUND;
216
4827
  const limit = paging?.limit ? paging.limit + 1 : void 0;
217
4828
  const items = [];
@@ -236,7 +4847,7 @@ var HypercoreOperationStore = class {
236
4847
  hasMore = true;
237
4848
  resultItems = items.slice(0, paging.limit);
238
4849
  }
239
- const nextCursor = hasMore && resultItems.length > 0 ? resultItems[resultItems.length - 1].index.toString() : void 0;
4850
+ const nextCursor = hasMore && resultItems.length > 0 ? (resultItems[resultItems.length - 1].index + 1).toString() : void 0;
240
4851
  const cursor = paging?.cursor || "0";
241
4852
  const resultLimit = paging?.limit || 100;
242
4853
  return {
@@ -252,11 +4863,20 @@ var HypercoreOperationStore = class {
252
4863
  }, signal) : void 0
253
4864
  };
254
4865
  }
4866
+ /**
4867
+ * The paging cursor encodes the ordinal to resume from (one past the last
4868
+ * ordinal returned), not the last ordinal itself; "" or "0" (or anything
4869
+ * unparsable) means the start of the stream. Unlike the Kysely store's
4870
+ * `getSinceId` (whose auto-increment id starts at 1), this store's ordinal
4871
+ * counter starts at 0, so 0 is a real, valid ordinal and the same
4872
+ * ambiguous-cursor hazard as `getSince`/`getConflicting` applies here too.
4873
+ */
255
4874
  async getSinceId(id, paging, signal) {
256
4875
  if (signal?.aborted) throw new Error("Operation aborted");
257
- const cursorValue = paging?.cursor && parseInt(paging.cursor, 10) > 0 ? parseInt(paging.cursor, 10) : id;
258
- const effectiveId = Math.max(id, cursorValue);
259
- const gt = ordinalPrefix() + pad(effectiveId);
4876
+ const startId = id + 1;
4877
+ const parsedCursor = paging?.cursor ? Number.parseInt(paging.cursor, 10) : NaN;
4878
+ const effectiveStart = Math.max(startId, Number.isFinite(parsedCursor) && parsedCursor > 0 ? parsedCursor : startId);
4879
+ const gt = ordinalPrefix() + pad(effectiveStart - 1);
260
4880
  const lt = ordinalPrefix() + RANGE_UPPER_BOUND;
261
4881
  const limit = paging?.limit ? paging.limit + 1 : void 0;
262
4882
  const items = [];
@@ -285,7 +4905,7 @@ var HypercoreOperationStore = class {
285
4905
  hasMore = true;
286
4906
  resultItems = items.slice(0, paging.limit);
287
4907
  }
288
- const nextCursor = hasMore && resultItems.length > 0 ? resultItems[resultItems.length - 1].context.ordinal.toString() : void 0;
4908
+ const nextCursor = hasMore && resultItems.length > 0 ? (resultItems[resultItems.length - 1].context.ordinal + 1).toString() : void 0;
289
4909
  const cursor = paging?.cursor || "0";
290
4910
  const resultLimit = paging?.limit || 100;
291
4911
  return {
@@ -301,21 +4921,31 @@ var HypercoreOperationStore = class {
301
4921
  }, signal) : void 0
302
4922
  };
303
4923
  }
4924
+ /**
4925
+ * The paging cursor here encodes the index to resume from (one past the
4926
+ * last row returned), not the last row's own index, for the same reason as
4927
+ * `getSince`: a page ending at index 0 must not produce a cursor that is
4928
+ * indistinguishable from the start-of-stream sentinel.
4929
+ */
304
4930
  async getConflicting(documentId, scope, branch, minTimestamp, paging, signal) {
305
4931
  if (signal?.aborted) throw new Error("Operation aborted");
306
4932
  const prefix = operationPrefix(documentId, scope, branch);
307
- const cursorIndex = paging?.cursor && parseInt(paging.cursor, 10) > 0 ? parseInt(paging.cursor, 10) : -1;
308
- const gt = cursorIndex >= 0 ? prefix + pad(cursorIndex) : prefix;
4933
+ const parsedCursor = paging?.cursor ? Number.parseInt(paging.cursor, 10) : NaN;
4934
+ const cursorIndex = Number.isFinite(parsedCursor) && parsedCursor > 0 ? parsedCursor : -1;
4935
+ const gte = cursorIndex >= 0 ? prefix + pad(cursorIndex) : prefix;
309
4936
  const lt = prefix + RANGE_UPPER_BOUND;
310
4937
  const stream = this.bee.createReadStream({
311
- gt: cursorIndex >= 0 ? gt : void 0,
312
- gte: cursorIndex >= 0 ? void 0 : gt,
4938
+ gte,
313
4939
  lt
314
4940
  });
4941
+ const readLimit = paging?.limit ? paging.limit + 1 : void 0;
315
4942
  const items = [];
316
4943
  for await (const entry of stream) {
317
4944
  const stored = entry.value;
318
- if (stored.timestampUtcMs >= minTimestamp) items.push(this.toOperation(stored));
4945
+ if (stored.timestampUtcMs >= minTimestamp) {
4946
+ items.push(this.toOperation(stored));
4947
+ if (readLimit !== void 0 && items.length >= readLimit) break;
4948
+ }
319
4949
  }
320
4950
  let hasMore = false;
321
4951
  let resultItems = items;
@@ -323,7 +4953,7 @@ var HypercoreOperationStore = class {
323
4953
  hasMore = true;
324
4954
  resultItems = items.slice(0, paging.limit);
325
4955
  }
326
- const nextCursor = hasMore && resultItems.length > 0 ? resultItems[resultItems.length - 1].index.toString() : void 0;
4956
+ const nextCursor = hasMore && resultItems.length > 0 ? (resultItems[resultItems.length - 1].index + 1).toString() : void 0;
327
4957
  const cursor = paging?.cursor || "0";
328
4958
  const resultLimit = paging?.limit || 100;
329
4959
  return {
@@ -373,6 +5003,24 @@ var HypercoreOperationStore = class {
373
5003
  for (const operation of stored.results) if (latest === void 0 || operation.timestampUtcMs > latest) latest = operation.timestampUtcMs;
374
5004
  return latest;
375
5005
  }
5006
+ async findOperationIds(documentId, scope, branch, opIds, signal) {
5007
+ if (signal?.aborted) throw new Error("Operation aborted");
5008
+ const found = /* @__PURE__ */ new Set();
5009
+ if (opIds.length === 0) return found;
5010
+ const wanted = new Set(opIds);
5011
+ const stored = await this.getSince(documentId, scope, branch, -1, void 0, void 0, signal);
5012
+ for (const operation of stored.results) if (wanted.has(operation.id)) found.add(operation.id);
5013
+ return found;
5014
+ }
5015
+ async getOperationsByIds(documentId, scope, branch, opIds, signal) {
5016
+ if (signal?.aborted) throw new Error("Operation aborted");
5017
+ if (opIds.length === 0) return [];
5018
+ const wanted = new Set(opIds);
5019
+ const stored = await this.getSince(documentId, scope, branch, -1, void 0, void 0, signal);
5020
+ const latest = /* @__PURE__ */ new Map();
5021
+ for (const operation of stored.results) if (wanted.has(operation.id)) latest.set(operation.id, operation);
5022
+ return [...latest.values()];
5023
+ }
376
5024
  serializeOperation(op) {
377
5025
  return {
378
5026
  id: op.id,
@@ -412,7 +5060,8 @@ var StorageManager = class {
412
5060
  }
413
5061
  async open() {
414
5062
  await this.store.ready();
415
- this.bee = new Hyperbee(this.store.get({ name: "operations" }), {
5063
+ const core = this.store.get({ name: "operations" });
5064
+ this.bee = new Hyperbee(core, {
416
5065
  keyEncoding: "utf-8",
417
5066
  valueEncoding: "json"
418
5067
  });