data-finder-ts 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +17 -55
  2. package/dist/chunk-BGEX377Q.js +230 -0
  3. package/dist/chunk-BGEX377Q.js.map +1 -0
  4. package/dist/chunk-BKPWV3OF.js +962 -0
  5. package/dist/chunk-BKPWV3OF.js.map +1 -0
  6. package/dist/{chunk-EYXBYV2X.js → chunk-GPHWC533.js} +2 -2
  7. package/dist/chunk-KAK75RVS.js +198 -0
  8. package/dist/chunk-KAK75RVS.js.map +1 -0
  9. package/dist/chunk-MGEL5RWM.js +628 -0
  10. package/dist/chunk-MGEL5RWM.js.map +1 -0
  11. package/dist/chunk-PF6EJZHB.js +1015 -0
  12. package/dist/chunk-PF6EJZHB.js.map +1 -0
  13. package/dist/datafinder/attribute.cjs +595 -18
  14. package/dist/datafinder/attribute.cjs.map +1 -1
  15. package/dist/datafinder/attribute.d.cts +73 -10
  16. package/dist/datafinder/attribute.d.ts +73 -10
  17. package/dist/datafinder/attribute.js +2 -2
  18. package/dist/datafinder/runner.cjs +1589 -288
  19. package/dist/datafinder/runner.cjs.map +1 -1
  20. package/dist/datafinder/runner.d.cts +41 -7
  21. package/dist/datafinder/runner.d.ts +41 -7
  22. package/dist/datafinder/runner.js +12 -6
  23. package/dist/datafinder/sql-generator.cjs +1484 -281
  24. package/dist/datafinder/sql-generator.cjs.map +1 -1
  25. package/dist/datafinder/sql-generator.d.cts +19 -14
  26. package/dist/datafinder/sql-generator.d.ts +19 -14
  27. package/dist/datafinder/sql-generator.js +9 -7
  28. package/dist/datafinder/typed-attributes.cjs +856 -93
  29. package/dist/datafinder/typed-attributes.cjs.map +1 -1
  30. package/dist/datafinder/typed-attributes.d.cts +3 -135
  31. package/dist/datafinder/typed-attributes.d.ts +3 -135
  32. package/dist/datafinder/typed-attributes.js +3 -3
  33. package/dist/dialect-CogGPm_y.d.cts +38 -0
  34. package/dist/dialect-aaG1bDi5.d.ts +38 -0
  35. package/dist/index.cjs +2080 -480
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.cts +119 -14
  38. package/dist/index.d.ts +119 -14
  39. package/dist/index.js +362 -12
  40. package/dist/index.js.map +1 -1
  41. package/dist/model/milestoning.cjs +529 -0
  42. package/dist/model/milestoning.cjs.map +1 -1
  43. package/dist/model/milestoning.js +2 -2
  44. package/dist/model/relational.cjs +608 -12
  45. package/dist/model/relational.cjs.map +1 -1
  46. package/dist/model/relational.d.cts +456 -47
  47. package/dist/model/relational.d.ts +456 -47
  48. package/dist/model/relational.js +61 -3
  49. package/dist/typed-attributes-CUTf_6Ru.d.ts +328 -0
  50. package/dist/typed-attributes-CdWXq_78.d.cts +328 -0
  51. package/package.json +5 -2
  52. package/dist/chunk-3SSWFES4.js +0 -448
  53. package/dist/chunk-3SSWFES4.js.map +0 -1
  54. package/dist/chunk-5K2Z3YDY.js +0 -393
  55. package/dist/chunk-5K2Z3YDY.js.map +0 -1
  56. package/dist/chunk-6QTCGJWX.js +0 -98
  57. package/dist/chunk-6QTCGJWX.js.map +0 -1
  58. package/dist/chunk-DFYZVBII.js +0 -652
  59. package/dist/chunk-DFYZVBII.js.map +0 -1
  60. package/dist/chunk-V647VNMY.js +0 -135
  61. package/dist/chunk-V647VNMY.js.map +0 -1
  62. /package/dist/{chunk-EYXBYV2X.js.map → chunk-GPHWC533.js.map} +0 -0
@@ -22,14 +22,24 @@ var relational_exports = {};
22
22
  __export(relational_exports, {
23
23
  AggregateOperation: () => AggregateOperation,
24
24
  AggregateOperator: () => AggregateOperator,
25
+ Aggregates: () => Aggregates,
26
+ Alias: () => Alias,
27
+ Arithmetic: () => Arithmetic,
28
+ ArithmeticOperation: () => ArithmeticOperation,
29
+ ArithmeticOperator: () => ArithmeticOperator,
25
30
  BinaryOperation: () => BinaryOperation,
31
+ BooleanAggregates: () => BooleanAggregates,
26
32
  BooleanConstantOperation: () => BooleanConstantOperation,
33
+ CaseOperation: () => CaseOperation,
27
34
  Column: () => Column,
28
35
  ColumnWithJoin: () => ColumnWithJoin,
36
+ Comparable: () => Comparable,
29
37
  ComparisonOperation: () => ComparisonOperation,
30
38
  ComparisonOperator: () => ComparisonOperator,
39
+ ConcatOperation: () => ConcatOperation,
31
40
  ConstantOperation: () => ConstantOperation,
32
41
  CountAllOperation: () => CountAllOperation,
42
+ DATE_ONLY_PATTERN: () => DATE_ONLY_PATTERN,
33
43
  DataCatalog: () => DataCatalog,
34
44
  DataStore: () => DataStore,
35
45
  Database: () => Database,
@@ -37,32 +47,51 @@ __export(relational_exports, {
37
47
  DateConstantOperation: () => DateConstantOperation,
38
48
  DateDiffOperation: () => DateDiffOperation,
39
49
  DateExtractOperation: () => DateExtractOperation,
50
+ DateOnly: () => DateOnly,
40
51
  DatePart: () => DatePart,
41
52
  DateTimeConstantOperation: () => DateTimeConstantOperation,
53
+ DateTruncOperation: () => DateTruncOperation,
42
54
  DecimalConstantOperation: () => DecimalConstantOperation,
55
+ ExistsOperation: () => ExistsOperation,
43
56
  FloatConstantOperation: () => FloatConstantOperation,
44
57
  ForeignKey: () => ForeignKey,
58
+ InOperation: () => InOperation,
45
59
  IntegerConstantOperation: () => IntegerConstantOperation,
46
60
  IsNotNullOperation: () => IsNotNullOperation,
47
61
  IsNullOperation: () => IsNullOperation,
48
62
  JoinOperation: () => JoinOperation,
49
63
  JoinTreeNodeOperation: () => JoinTreeNodeOperation,
64
+ LIKE_ESCAPE: () => LIKE_ESCAPE,
50
65
  LogicalOperation: () => LogicalOperation,
51
66
  LogicalOperator: () => LogicalOperator,
67
+ NUMERIC_FUNCTIONS: () => NUMERIC_FUNCTIONS,
52
68
  NoOperation: () => NoOperation,
69
+ NotExistsOperation: () => NotExistsOperation,
70
+ NotInOperation: () => NotInOperation,
71
+ NumericConstantOperation: () => NumericConstantOperation,
53
72
  Operation: () => Operation,
54
73
  RelationalOperationElement: () => RelationalOperationElement,
55
74
  ScalarFunction: () => ScalarFunction,
56
75
  ScalarFunctionOperation: () => ScalarFunctionOperation,
57
76
  Schema: () => Schema,
77
+ SelectOperation: () => SelectOperation,
58
78
  SortDirection: () => SortDirection,
59
79
  SortOperation: () => SortOperation,
60
80
  StringConstantOperation: () => StringConstantOperation,
81
+ StringPredicates: () => StringPredicates,
61
82
  Table: () => Table,
62
83
  UnaryOperation: () => UnaryOperation,
63
84
  WindowFunction: () => WindowFunction,
64
85
  WindowFunctionOperation: () => WindowFunctionOperation,
65
- WindowSpecification: () => WindowSpecification
86
+ WindowSpecification: () => WindowSpecification,
87
+ applyMixins: () => applyMixins,
88
+ concat: () => concat,
89
+ containsAggregate: () => containsAggregate,
90
+ containsAggregateOrWindow: () => containsAggregateOrWindow,
91
+ escapeLike: () => escapeLike,
92
+ operandOf: () => operandOf,
93
+ sample: () => sample,
94
+ valueOperand: () => valueOperand
66
95
  });
67
96
  module.exports = __toCommonJS(relational_exports);
68
97
  var ComparisonOperator = /* @__PURE__ */ ((ComparisonOperator2) => {
@@ -76,6 +105,10 @@ var ComparisonOperator = /* @__PURE__ */ ((ComparisonOperator2) => {
76
105
  ComparisonOperator2["NOT_LIKE"] = "NOT_LIKE";
77
106
  return ComparisonOperator2;
78
107
  })(ComparisonOperator || {});
108
+ var LIKE_ESCAPE = "!";
109
+ function escapeLike(value) {
110
+ return value.replaceAll(LIKE_ESCAPE, LIKE_ESCAPE + LIKE_ESCAPE).replaceAll("%", LIKE_ESCAPE + "%").replaceAll("_", LIKE_ESCAPE + "_");
111
+ }
79
112
  var LogicalOperator = /* @__PURE__ */ ((LogicalOperator2) => {
80
113
  LogicalOperator2["AND"] = "AND";
81
114
  LogicalOperator2["OR"] = "OR";
@@ -87,6 +120,14 @@ var AggregateOperator = /* @__PURE__ */ ((AggregateOperator2) => {
87
120
  AggregateOperator2["MIN"] = "MIN";
88
121
  AggregateOperator2["MAX"] = "MAX";
89
122
  AggregateOperator2["AVERAGE"] = "AVERAGE";
123
+ AggregateOperator2["STRING_AGG"] = "STRING_AGG";
124
+ AggregateOperator2["COUNT_DISTINCT"] = "COUNT_DISTINCT";
125
+ AggregateOperator2["STDDEV_SAMP"] = "STDDEV_SAMP";
126
+ AggregateOperator2["STDDEV_POP"] = "STDDEV_POP";
127
+ AggregateOperator2["VAR_SAMP"] = "VAR_SAMP";
128
+ AggregateOperator2["VAR_POP"] = "VAR_POP";
129
+ AggregateOperator2["BOOL_AND"] = "BOOL_AND";
130
+ AggregateOperator2["BOOL_OR"] = "BOOL_OR";
90
131
  return AggregateOperator2;
91
132
  })(AggregateOperator || {});
92
133
  var ScalarFunction = /* @__PURE__ */ ((ScalarFunction2) => {
@@ -109,6 +150,7 @@ var ScalarFunction = /* @__PURE__ */ ((ScalarFunction2) => {
109
150
  ScalarFunction2["REPEAT"] = "REPEAT";
110
151
  ScalarFunction2["REPLACE"] = "REPLACE";
111
152
  ScalarFunction2["SUBSTRING"] = "SUBSTRING";
153
+ ScalarFunction2["COALESCE"] = "COALESCE";
112
154
  return ScalarFunction2;
113
155
  })(ScalarFunction || {});
114
156
  var DatePart = /* @__PURE__ */ ((DatePart2) => {
@@ -131,25 +173,54 @@ var SortDirection = /* @__PURE__ */ ((SortDirection2) => {
131
173
  var RelationalOperationElement = class {
132
174
  };
133
175
  var Operation = class extends RelationalOperationElement {
134
- andOp(other) {
176
+ /** Name this column in the result: `f.price().sum().alias('Total')`, `f.age().gt(30).alias('Adult')`. */
177
+ alias(name) {
178
+ return new Alias(this, name);
179
+ }
180
+ and(other) {
135
181
  return new LogicalOperation(this, "AND" /* AND */, other);
136
182
  }
183
+ /** Combine with `other` using OR. A chain reads left to right: `a.or(b).and(c)` is `(a OR b) AND c`. */
184
+ or(other) {
185
+ return new LogicalOperation(this, "OR" /* OR */, other);
186
+ }
137
187
  };
138
188
  var NoOperation = class extends Operation {
139
- andOp(other) {
189
+ and(other) {
140
190
  return other;
141
191
  }
192
+ /** No filter matches every row, so OR-ing anything with it still matches every row. */
193
+ or(_other) {
194
+ return this;
195
+ }
142
196
  };
143
197
  var ConstantOperation = class extends RelationalOperationElement {
198
+ /** Name this column in the result. */
199
+ alias(name) {
200
+ return new Alias(this, name);
201
+ }
202
+ /** Sort by this expression, smallest first. */
203
+ ascending() {
204
+ return new SortOperation(this, "ASC" /* ASC */);
205
+ }
206
+ /** Sort by this expression, largest first. */
207
+ descending() {
208
+ return new SortOperation(this, "DESC" /* DESC */);
209
+ }
210
+ };
211
+ var NumericConstantOperation = class extends ConstantOperation {
212
+ arithmeticOperand() {
213
+ return this;
214
+ }
144
215
  };
145
- var IntegerConstantOperation = class extends ConstantOperation {
216
+ var IntegerConstantOperation = class extends NumericConstantOperation {
146
217
  constructor(value) {
147
218
  super();
148
219
  this.value = value;
149
220
  }
150
221
  value;
151
222
  };
152
- var FloatConstantOperation = class extends ConstantOperation {
223
+ var FloatConstantOperation = class extends NumericConstantOperation {
153
224
  constructor(value) {
154
225
  super();
155
226
  this.value = value;
@@ -163,6 +234,9 @@ var StringConstantOperation = class extends ConstantOperation {
163
234
  }
164
235
  value;
165
236
  };
237
+ var DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
238
+ var DateOnly = class extends Date {
239
+ };
166
240
  var DateConstantOperation = class extends ConstantOperation {
167
241
  constructor(value) {
168
242
  super();
@@ -177,7 +251,7 @@ var DateTimeConstantOperation = class extends ConstantOperation {
177
251
  }
178
252
  value;
179
253
  };
180
- var DecimalConstantOperation = class extends ConstantOperation {
254
+ var DecimalConstantOperation = class extends NumericConstantOperation {
181
255
  constructor(value) {
182
256
  super();
183
257
  this.value = value;
@@ -211,6 +285,20 @@ var IsNullOperation = class extends UnaryOperation {
211
285
  };
212
286
  var IsNotNullOperation = class extends UnaryOperation {
213
287
  };
288
+ var InOperation = class extends UnaryOperation {
289
+ constructor(element, values) {
290
+ super(element);
291
+ this.values = values;
292
+ }
293
+ values;
294
+ };
295
+ var NotInOperation = class extends UnaryOperation {
296
+ constructor(element, values) {
297
+ super(element);
298
+ this.values = values;
299
+ }
300
+ values;
301
+ };
214
302
  var ComparisonOperation = class extends BinaryOperation {
215
303
  constructor(left, operator, right) {
216
304
  super(left, right);
@@ -234,21 +322,41 @@ var WindowSpecification = class {
234
322
  orderBy;
235
323
  };
236
324
  var AggregateOperation = class _AggregateOperation extends UnaryOperation {
237
- constructor(element, operator, displayName, window) {
325
+ constructor(element, operator, displayName, window, separator, orderBy = []) {
238
326
  super(element);
239
327
  this.operator = operator;
240
328
  this.displayName = displayName;
241
329
  this.window = window;
330
+ this.separator = separator;
331
+ this.orderBy = orderBy;
242
332
  }
243
333
  operator;
244
334
  displayName;
245
335
  window;
336
+ separator;
337
+ orderBy;
338
+ /** Sort by this expression, smallest first. */
339
+ ascending() {
340
+ return new SortOperation(this, "ASC" /* ASC */);
341
+ }
342
+ /** Sort by this expression, largest first. */
343
+ descending() {
344
+ return new SortOperation(this, "DESC" /* DESC */);
345
+ }
346
+ arithmeticOperand() {
347
+ return this;
348
+ }
349
+ comparisonOperand() {
350
+ return this;
351
+ }
246
352
  over(partitionBy, orderBy) {
247
353
  return new _AggregateOperation(
248
354
  this.element,
249
355
  this.operator,
250
356
  this.displayName,
251
- new WindowSpecification(partitionBy ?? [], orderBy ?? [])
357
+ new WindowSpecification(partitionBy ?? [], orderBy ?? []),
358
+ this.separator,
359
+ this.orderBy
252
360
  );
253
361
  }
254
362
  };
@@ -279,6 +387,14 @@ var WindowFunctionOperation = class _WindowFunctionOperation extends UnaryOperat
279
387
  secondArg;
280
388
  extraArgs;
281
389
  window;
390
+ /** Sort by this expression, smallest first. */
391
+ ascending() {
392
+ return new SortOperation(this, "ASC" /* ASC */);
393
+ }
394
+ /** Sort by this expression, largest first. */
395
+ descending() {
396
+ return new SortOperation(this, "DESC" /* DESC */);
397
+ }
282
398
  over(partitionBy, orderBy) {
283
399
  return new _WindowFunctionOperation(
284
400
  this.element,
@@ -302,7 +418,38 @@ var ScalarFunctionOperation = class extends UnaryOperation {
302
418
  displayName;
303
419
  secondArg;
304
420
  extraArgs;
421
+ /** Sort by this expression, smallest first. */
422
+ ascending() {
423
+ return new SortOperation(this, "ASC" /* ASC */);
424
+ }
425
+ /** Sort by this expression, largest first. */
426
+ descending() {
427
+ return new SortOperation(this, "DESC" /* DESC */);
428
+ }
429
+ /** This expression as an operand of a comparison. */
430
+ comparisonOperand() {
431
+ return this;
432
+ }
433
+ arithmeticOperand() {
434
+ return this;
435
+ }
436
+ /** Only a function that gives a number can be used in arithmetic. */
437
+ assertNumeric() {
438
+ if (!NUMERIC_FUNCTIONS.has(this.func)) {
439
+ throw new TypeError(`${this.func} does not give a number, so it cannot be used in arithmetic`);
440
+ }
441
+ }
305
442
  };
443
+ var NUMERIC_FUNCTIONS = /* @__PURE__ */ new Set([
444
+ "ABS" /* ABS */,
445
+ "CEILING" /* CEILING */,
446
+ "FLOOR" /* FLOOR */,
447
+ "MOD" /* MOD */,
448
+ "POWER" /* POWER */,
449
+ "SQRT" /* SQRT */,
450
+ "ROUND" /* ROUND */,
451
+ "LENGTH" /* LENGTH */
452
+ ]);
306
453
  var DateExtractOperation = class extends UnaryOperation {
307
454
  constructor(element, part, displayName) {
308
455
  super(element);
@@ -311,6 +458,34 @@ var DateExtractOperation = class extends UnaryOperation {
311
458
  }
312
459
  part;
313
460
  displayName;
461
+ /** Sort by this expression, smallest first. */
462
+ ascending() {
463
+ return new SortOperation(this, "ASC" /* ASC */);
464
+ }
465
+ /** Sort by this expression, largest first. */
466
+ descending() {
467
+ return new SortOperation(this, "DESC" /* DESC */);
468
+ }
469
+ };
470
+ var DateTruncOperation = class extends UnaryOperation {
471
+ constructor(element, part, displayName) {
472
+ super(element);
473
+ this.part = part;
474
+ this.displayName = displayName;
475
+ }
476
+ part;
477
+ displayName;
478
+ /** Sort by this expression, earliest first. */
479
+ ascending() {
480
+ return new SortOperation(this, "ASC" /* ASC */);
481
+ }
482
+ /** Sort by this expression, latest first. */
483
+ descending() {
484
+ return new SortOperation(this, "DESC" /* DESC */);
485
+ }
486
+ comparisonOperand() {
487
+ return this;
488
+ }
314
489
  };
315
490
  var DateArithmeticOperation = class extends UnaryOperation {
316
491
  constructor(element, n, unit, isAdd = true, displayName) {
@@ -324,6 +499,14 @@ var DateArithmeticOperation = class extends UnaryOperation {
324
499
  unit;
325
500
  isAdd;
326
501
  displayName;
502
+ /** Sort by this expression, smallest first. */
503
+ ascending() {
504
+ return new SortOperation(this, "ASC" /* ASC */);
505
+ }
506
+ /** Sort by this expression, largest first. */
507
+ descending() {
508
+ return new SortOperation(this, "DESC" /* DESC */);
509
+ }
327
510
  };
328
511
  var DateDiffOperation = class extends UnaryOperation {
329
512
  constructor(element, other, unit, displayName) {
@@ -335,20 +518,31 @@ var DateDiffOperation = class extends UnaryOperation {
335
518
  other;
336
519
  unit;
337
520
  displayName;
521
+ /** Sort by this expression, smallest first. */
522
+ ascending() {
523
+ return new SortOperation(this, "ASC" /* ASC */);
524
+ }
525
+ /** Sort by this expression, largest first. */
526
+ descending() {
527
+ return new SortOperation(this, "DESC" /* DESC */);
528
+ }
338
529
  };
339
530
  var Column = class extends RelationalOperationElement {
340
- constructor(name, type, owner, primaryKey = false) {
531
+ constructor(name, type, owner, primaryKey = false, nullable = true) {
341
532
  super();
342
533
  this.name = name;
343
534
  this.type = type;
344
535
  this.owner = owner;
345
536
  this.primaryKey = primaryKey;
537
+ this.nullable = nullable && !primaryKey;
346
538
  }
347
539
  name;
348
540
  type;
349
541
  owner;
350
542
  primaryKey;
351
543
  table;
544
+ /** Whether the column may hold NULL. As in Legend, a primary key is never null. */
545
+ nullable;
352
546
  };
353
547
  var ForeignKey = class {
354
548
  constructor(column, references) {
@@ -432,23 +626,46 @@ var JoinOperation = class {
432
626
  left;
433
627
  right;
434
628
  filter;
629
+ /** Property-equality filters on the join target (property id -> value), set by a related finder given a filter. */
630
+ filterKwargs = {};
631
+ /** Maps property ids to [column, type, table] for `filterKwargs`. */
632
+ filterColumnMap = {};
435
633
  };
436
634
  var JoinTreeNodeOperation = class {
437
- constructor(join, parent) {
635
+ constructor(join, parent, many = false, optional = false) {
438
636
  this.join = join;
439
637
  this.parent = parent;
638
+ this.many = many;
639
+ this.optional = optional;
440
640
  }
441
641
  join;
442
642
  parent;
643
+ many;
644
+ optional;
443
645
  };
444
646
  var ColumnWithJoin = class extends RelationalOperationElement {
445
- constructor(column, parent) {
647
+ /**
648
+ * `embedded` is an alternate reference to a flat (denormalized) column on the owning table that
649
+ * holds the same value without the join; the SQL generator uses it when the join can be elided.
650
+ */
651
+ constructor(column, parent, embedded, _optional = false) {
446
652
  super();
447
653
  this.column = column;
448
654
  this.parent = parent;
655
+ this.embedded = embedded;
656
+ this._optional = _optional;
449
657
  }
450
658
  column;
451
659
  parent;
660
+ embedded;
661
+ _optional;
662
+ /** Whether the value can be missing: its property is optional, or a navigation on the way to it is. */
663
+ get optional() {
664
+ for (let node = this.parent; node !== void 0; node = node.parent) {
665
+ if (node.optional) return true;
666
+ }
667
+ return this._optional;
668
+ }
452
669
  };
453
670
  var SortOperation = class {
454
671
  constructor(column, direction) {
@@ -464,19 +681,379 @@ var CountAllOperation = class extends RelationalOperationElement {
464
681
  this.table = table;
465
682
  }
466
683
  table;
684
+ /** Name this column in the result. */
685
+ alias(name) {
686
+ return new Alias(this, name);
687
+ }
688
+ /** Sort by this expression, smallest first. */
689
+ ascending() {
690
+ return new SortOperation(this, "ASC" /* ASC */);
691
+ }
692
+ /** Sort by this expression, largest first. */
693
+ descending() {
694
+ return new SortOperation(this, "DESC" /* DESC */);
695
+ }
696
+ comparisonOperand() {
697
+ return this;
698
+ }
699
+ };
700
+ var Alias = class _Alias extends RelationalOperationElement {
701
+ constructor(element, name) {
702
+ super();
703
+ this.element = element;
704
+ this.name = name;
705
+ }
706
+ element;
707
+ name;
708
+ alias(name) {
709
+ return new _Alias(this.element, name);
710
+ }
711
+ /** Sorts by the column the alias names. */
712
+ ascending() {
713
+ return new SortOperation(this.element, "ASC" /* ASC */);
714
+ }
715
+ /** Sorts by the column the alias names. */
716
+ descending() {
717
+ return new SortOperation(this.element, "DESC" /* DESC */);
718
+ }
719
+ };
720
+ var CaseOperation = class extends Operation {
721
+ constructor(condition, then, fallback, displayName) {
722
+ super();
723
+ this.condition = condition;
724
+ this.then = then;
725
+ this.fallback = fallback;
726
+ this.displayName = displayName;
727
+ }
728
+ condition;
729
+ then;
730
+ fallback;
731
+ displayName;
732
+ };
733
+ var ExistsOperation = class extends RelationalOperationElement {
734
+ constructor(node) {
735
+ super();
736
+ this.node = node;
737
+ }
738
+ node;
739
+ /** Name this column in the result. */
740
+ alias(name) {
741
+ return new Alias(this, name);
742
+ }
743
+ and(other) {
744
+ return new LogicalOperation(this, "AND" /* AND */, other);
745
+ }
746
+ or(other) {
747
+ return new LogicalOperation(this, "OR" /* OR */, other);
748
+ }
749
+ };
750
+ var NotExistsOperation = class extends RelationalOperationElement {
751
+ constructor(node) {
752
+ super();
753
+ this.node = node;
754
+ }
755
+ node;
756
+ /** Name this column in the result. */
757
+ alias(name) {
758
+ return new Alias(this, name);
759
+ }
760
+ and(other) {
761
+ return new LogicalOperation(this, "AND" /* AND */, other);
762
+ }
763
+ or(other) {
764
+ return new LogicalOperation(this, "OR" /* OR */, other);
765
+ }
766
+ };
767
+ var SelectOperation = class {
768
+ constructor(display, filter, orderBy = [], groupBy = [], limit, table, joinFilters = /* @__PURE__ */ new Map(), distinct = false, offset, having) {
769
+ this.display = display;
770
+ this.filter = filter;
771
+ this.orderBy = orderBy;
772
+ this.groupBy = groupBy;
773
+ this.limit = limit;
774
+ this.table = table;
775
+ this.joinFilters = joinFilters;
776
+ this.distinct = distinct;
777
+ this.offset = offset;
778
+ this.having = having;
779
+ }
780
+ display;
781
+ filter;
782
+ orderBy;
783
+ groupBy;
784
+ limit;
785
+ table;
786
+ joinFilters;
787
+ distinct;
788
+ offset;
789
+ having;
790
+ };
791
+ function containsAggregateOrWindow(op) {
792
+ if (op instanceof AggregateOperation || op instanceof WindowFunctionOperation || op instanceof CountAllOperation) return true;
793
+ if (op instanceof BinaryOperation) return containsAggregateOrWindow(op.left) || containsAggregateOrWindow(op.right);
794
+ if (op instanceof UnaryOperation || op instanceof Alias) return containsAggregateOrWindow(op.element);
795
+ return false;
796
+ }
797
+ function containsAggregate(op) {
798
+ if (op instanceof AggregateOperation || op instanceof CountAllOperation) return true;
799
+ if (op instanceof BinaryOperation) return containsAggregate(op.left) || containsAggregate(op.right);
800
+ if (op instanceof UnaryOperation || op instanceof Alias) return containsAggregate(op.element);
801
+ return false;
802
+ }
803
+ function valueOperand(value) {
804
+ if (typeof value === "boolean") return new BooleanConstantOperation(value);
805
+ if (typeof value === "number" && Number.isFinite(value)) {
806
+ return Number.isInteger(value) ? new IntegerConstantOperation(value) : new FloatConstantOperation(value);
807
+ }
808
+ if (typeof value === "string") return new StringConstantOperation(value);
809
+ if (value instanceof DateOnly) return new DateConstantOperation(value);
810
+ if (value instanceof Date) return new DateTimeConstantOperation(value);
811
+ throw new TypeError(`A value to compare with is a boolean, a finite number, a string or a date, not ${value === null ? "null" : typeof value}`);
812
+ }
813
+ function operandOf(other) {
814
+ if (other instanceof RelationalOperationElement) return other;
815
+ if (typeof other?.cwj === "function") return other.cwj();
816
+ return valueOperand(other);
817
+ }
818
+ var Comparable = class {
819
+ _compared(operator, other) {
820
+ return new ComparisonOperation(this.comparisonOperand(), operator, operandOf(other));
821
+ }
822
+ /** Filter to rows where this expression equals `other`. */
823
+ eq(other) {
824
+ return this._compared("EQUAL" /* EQUAL */, other);
825
+ }
826
+ /** Filter to rows where this expression does not equal `other`. */
827
+ ne(other) {
828
+ return this._compared("NOT_EQUAL" /* NOT_EQUAL */, other);
829
+ }
830
+ /** Filter to rows where this expression is less than `other`. */
831
+ lt(other) {
832
+ return this._compared("LESS_THAN" /* LESS_THAN */, other);
833
+ }
834
+ /** Filter to rows where this expression is at most `other`. */
835
+ lte(other) {
836
+ return this._compared("LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, other);
837
+ }
838
+ /** Filter to rows where this expression is greater than `other`. */
839
+ gt(other) {
840
+ return this._compared("GREATER_THAN" /* GREATER_THAN */, other);
841
+ }
842
+ /** Filter to rows where this expression is at least `other`. */
843
+ gte(other) {
844
+ return this._compared("GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, other);
845
+ }
846
+ };
847
+ function sample(ddof) {
848
+ if (ddof !== 0 && ddof !== 1) throw new RangeError(`ddof is 0 (population) or 1 (sample), not ${ddof}`);
849
+ return ddof === 1;
850
+ }
851
+ var StringPredicates = class {
852
+ _like(pattern) {
853
+ return new ComparisonOperation(this.comparisonOperand(), "LIKE" /* LIKE */, new StringConstantOperation(pattern));
854
+ }
855
+ /** Filter to rows where this text contains `value`. */
856
+ contains(value) {
857
+ return this._like(`%${escapeLike(value)}%`);
858
+ }
859
+ /** Filter to rows where this text starts with `prefix`. */
860
+ startsWith(prefix) {
861
+ return this._like(`${escapeLike(prefix)}%`);
862
+ }
863
+ /** Filter to rows where this text ends with `suffix`. */
864
+ endsWith(suffix) {
865
+ return this._like(`%${escapeLike(suffix)}`);
866
+ }
867
+ };
868
+ var Aggregates = class {
869
+ _aggregate(operator, label) {
870
+ return new AggregateOperation(this, operator, label + " Expression");
871
+ }
872
+ /** Sum of the values in the group. */
873
+ sum() {
874
+ return this._aggregate("SUM" /* SUM */, "Sum");
875
+ }
876
+ /** Smallest value in the group. */
877
+ min() {
878
+ return this._aggregate("MIN" /* MIN */, "Min");
879
+ }
880
+ /** Largest value in the group. */
881
+ max() {
882
+ return this._aggregate("MAX" /* MAX */, "Max");
883
+ }
884
+ /** Arithmetic mean of the values in the group. */
885
+ average() {
886
+ return this._aggregate("AVERAGE" /* AVERAGE */, "Average");
887
+ }
888
+ /** Number of non-null values in the group. */
889
+ count() {
890
+ return this._aggregate("COUNT" /* COUNT */, "Count");
891
+ }
892
+ /** Standard deviation of the values in the group: the sample one by default, `ddof = 0` for the population one. */
893
+ std(ddof = 1) {
894
+ return this._aggregate(sample(ddof) ? "STDDEV_SAMP" /* STDDEV_SAMP */ : "STDDEV_POP" /* STDDEV_POP */, "Std");
895
+ }
896
+ /** Variance of the values in the group: the sample one by default, `ddof = 0` for the population one. */
897
+ var(ddof = 1) {
898
+ return this._aggregate(sample(ddof) ? "VAR_SAMP" /* VAR_SAMP */ : "VAR_POP" /* VAR_POP */, "Var");
899
+ }
900
+ };
901
+ var BooleanAggregates = class {
902
+ /** True for a group where every row satisfies the condition. */
903
+ all() {
904
+ return new AggregateOperation(this, "BOOL_AND" /* BOOL_AND */, "All Expression");
905
+ }
906
+ /** True for a group where at least one row satisfies the condition. */
907
+ any() {
908
+ return new AggregateOperation(this, "BOOL_OR" /* BOOL_OR */, "Any Expression");
909
+ }
910
+ };
911
+ function applyMixins(derived, bases) {
912
+ for (const base of bases) {
913
+ for (const name of Object.getOwnPropertyNames(base.prototype)) {
914
+ if (name === "constructor" || Object.prototype.hasOwnProperty.call(derived.prototype, name)) continue;
915
+ Object.defineProperty(derived.prototype, name, Object.getOwnPropertyDescriptor(base.prototype, name));
916
+ }
917
+ }
918
+ }
919
+ var ArithmeticOperator = /* @__PURE__ */ ((ArithmeticOperator2) => {
920
+ ArithmeticOperator2["ADD"] = "+";
921
+ ArithmeticOperator2["SUBTRACT"] = "-";
922
+ ArithmeticOperator2["MULTIPLY"] = "*";
923
+ ArithmeticOperator2["DIVIDE"] = "/";
924
+ return ArithmeticOperator2;
925
+ })(ArithmeticOperator || {});
926
+ var Arithmetic = class {
927
+ /** Raises if this expression is not a number. */
928
+ assertNumeric() {
929
+ }
930
+ _arithmetic(operator, other) {
931
+ this.assertNumeric();
932
+ let operand;
933
+ if (typeof other === "number") {
934
+ if (!Number.isFinite(other)) throw new TypeError("Arithmetic is between numbers and numeric columns, not a non-finite number");
935
+ operand = valueOperand(other);
936
+ } else if (other !== null && typeof other === "object" && typeof other.arithmeticOperand === "function") {
937
+ other.assertNumeric?.();
938
+ operand = other.arithmeticOperand();
939
+ } else {
940
+ throw new TypeError(`Arithmetic is between numbers and numeric columns, not ${other === null ? "null" : typeof other}`);
941
+ }
942
+ return new ArithmeticOperation(this.arithmeticOperand(), operator, operand);
943
+ }
944
+ /** `this + other`. */
945
+ plus(other) {
946
+ return this._arithmetic("+" /* ADD */, other);
947
+ }
948
+ /** `this - other`. */
949
+ minus(other) {
950
+ return this._arithmetic("-" /* SUBTRACT */, other);
951
+ }
952
+ /** `this * other`. */
953
+ times(other) {
954
+ return this._arithmetic("*" /* MULTIPLY */, other);
955
+ }
956
+ /** `this / other`. */
957
+ dividedBy(other) {
958
+ return this._arithmetic("/" /* DIVIDE */, other);
959
+ }
960
+ };
961
+ var ArithmeticOperation = class extends BinaryOperation {
962
+ constructor(left, operator, right, displayName) {
963
+ super(left, right);
964
+ this.operator = operator;
965
+ this.displayName = displayName;
966
+ }
967
+ operator;
968
+ displayName;
969
+ /** Sort by this expression, smallest first. */
970
+ ascending() {
971
+ return new SortOperation(this, "ASC" /* ASC */);
972
+ }
973
+ /** Sort by this expression, largest first. */
974
+ descending() {
975
+ return new SortOperation(this, "DESC" /* DESC */);
976
+ }
977
+ arithmeticOperand() {
978
+ return this;
979
+ }
980
+ comparisonOperand() {
981
+ return this;
982
+ }
983
+ };
984
+ var ConcatOperation = class extends Operation {
985
+ constructor(parts, displayName) {
986
+ super();
987
+ this.parts = parts;
988
+ this.displayName = displayName;
989
+ }
990
+ parts;
991
+ displayName;
992
+ /** Join more text on the end: `f.first().concat(' ', f.last())`. A concatenation joins into one. */
993
+ concat(...more) {
994
+ return concat(this, ...more);
995
+ }
996
+ /** Sort by this expression, smallest first. */
997
+ ascending() {
998
+ return new SortOperation(this, "ASC" /* ASC */);
999
+ }
1000
+ /** Sort by this expression, largest first. */
1001
+ descending() {
1002
+ return new SortOperation(this, "DESC" /* DESC */);
1003
+ }
1004
+ comparisonOperand() {
1005
+ return this;
1006
+ }
467
1007
  };
1008
+ function concat(...parts) {
1009
+ const partsOf = (part) => {
1010
+ if (part instanceof ConcatOperation) return part.parts;
1011
+ if (typeof part === "string") return [new StringConstantOperation(part)];
1012
+ if (part instanceof RelationalOperationElement) return [part];
1013
+ if (part !== null && typeof part === "object" && typeof part.functionInput === "function") return [part.functionInput()];
1014
+ throw new TypeError(`Text is joined with text, not ${part === null ? "null" : typeof part}`);
1015
+ };
1016
+ return new ConcatOperation(parts.flatMap(partsOf));
1017
+ }
1018
+ applyMixins(ConcatOperation, [Comparable, StringPredicates]);
1019
+ applyMixins(DateTruncOperation, [Comparable]);
1020
+ applyMixins(ArithmeticOperation, [Arithmetic, Comparable]);
1021
+ applyMixins(ScalarFunctionOperation, [Comparable, Arithmetic, StringPredicates]);
1022
+ applyMixins(AggregateOperation, [Arithmetic, Comparable, StringPredicates]);
1023
+ applyMixins(CountAllOperation, [Comparable]);
1024
+ applyMixins(NumericConstantOperation, [Arithmetic]);
1025
+ applyMixins(ConstantOperation, [Aggregates]);
1026
+ applyMixins(ArithmeticOperation, [Aggregates]);
1027
+ applyMixins(ScalarFunctionOperation, [Aggregates]);
1028
+ applyMixins(CaseOperation, [Aggregates]);
1029
+ applyMixins(IsNullOperation, [BooleanAggregates]);
1030
+ applyMixins(IsNotNullOperation, [BooleanAggregates]);
1031
+ applyMixins(InOperation, [BooleanAggregates]);
1032
+ applyMixins(NotInOperation, [BooleanAggregates]);
1033
+ applyMixins(ComparisonOperation, [BooleanAggregates]);
1034
+ applyMixins(LogicalOperation, [BooleanAggregates]);
468
1035
  // Annotate the CommonJS export names for ESM import in node:
469
1036
  0 && (module.exports = {
470
1037
  AggregateOperation,
471
1038
  AggregateOperator,
1039
+ Aggregates,
1040
+ Alias,
1041
+ Arithmetic,
1042
+ ArithmeticOperation,
1043
+ ArithmeticOperator,
472
1044
  BinaryOperation,
1045
+ BooleanAggregates,
473
1046
  BooleanConstantOperation,
1047
+ CaseOperation,
474
1048
  Column,
475
1049
  ColumnWithJoin,
1050
+ Comparable,
476
1051
  ComparisonOperation,
477
1052
  ComparisonOperator,
1053
+ ConcatOperation,
478
1054
  ConstantOperation,
479
1055
  CountAllOperation,
1056
+ DATE_ONLY_PATTERN,
480
1057
  DataCatalog,
481
1058
  DataStore,
482
1059
  Database,
@@ -484,31 +1061,50 @@ var CountAllOperation = class extends RelationalOperationElement {
484
1061
  DateConstantOperation,
485
1062
  DateDiffOperation,
486
1063
  DateExtractOperation,
1064
+ DateOnly,
487
1065
  DatePart,
488
1066
  DateTimeConstantOperation,
1067
+ DateTruncOperation,
489
1068
  DecimalConstantOperation,
1069
+ ExistsOperation,
490
1070
  FloatConstantOperation,
491
1071
  ForeignKey,
1072
+ InOperation,
492
1073
  IntegerConstantOperation,
493
1074
  IsNotNullOperation,
494
1075
  IsNullOperation,
495
1076
  JoinOperation,
496
1077
  JoinTreeNodeOperation,
1078
+ LIKE_ESCAPE,
497
1079
  LogicalOperation,
498
1080
  LogicalOperator,
1081
+ NUMERIC_FUNCTIONS,
499
1082
  NoOperation,
1083
+ NotExistsOperation,
1084
+ NotInOperation,
1085
+ NumericConstantOperation,
500
1086
  Operation,
501
1087
  RelationalOperationElement,
502
1088
  ScalarFunction,
503
1089
  ScalarFunctionOperation,
504
1090
  Schema,
1091
+ SelectOperation,
505
1092
  SortDirection,
506
1093
  SortOperation,
507
1094
  StringConstantOperation,
1095
+ StringPredicates,
508
1096
  Table,
509
1097
  UnaryOperation,
510
1098
  WindowFunction,
511
1099
  WindowFunctionOperation,
512
- WindowSpecification
1100
+ WindowSpecification,
1101
+ applyMixins,
1102
+ concat,
1103
+ containsAggregate,
1104
+ containsAggregateOrWindow,
1105
+ escapeLike,
1106
+ operandOf,
1107
+ sample,
1108
+ valueOperand
513
1109
  });
514
1110
  //# sourceMappingURL=relational.cjs.map