data-finder-ts 0.1.4 → 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 (58) hide show
  1. package/dist/{chunk-4JVW4TAB.js → chunk-BGEX377Q.js} +58 -8
  2. package/dist/chunk-BGEX377Q.js.map +1 -0
  3. package/dist/chunk-BKPWV3OF.js +962 -0
  4. package/dist/chunk-BKPWV3OF.js.map +1 -0
  5. package/dist/{chunk-PMPLCEWQ.js → chunk-GPHWC533.js} +2 -2
  6. package/dist/{chunk-FJYA2ASS.js → chunk-KAK75RVS.js} +74 -12
  7. package/dist/chunk-KAK75RVS.js.map +1 -0
  8. package/dist/{chunk-4LNZV6EN.js → chunk-MGEL5RWM.js} +206 -78
  9. package/dist/chunk-MGEL5RWM.js.map +1 -0
  10. package/dist/chunk-PF6EJZHB.js +1015 -0
  11. package/dist/chunk-PF6EJZHB.js.map +1 -0
  12. package/dist/datafinder/attribute.cjs +537 -11
  13. package/dist/datafinder/attribute.cjs.map +1 -1
  14. package/dist/datafinder/attribute.d.cts +29 -7
  15. package/dist/datafinder/attribute.d.ts +29 -7
  16. package/dist/datafinder/attribute.js +2 -2
  17. package/dist/datafinder/runner.cjs +1267 -215
  18. package/dist/datafinder/runner.cjs.map +1 -1
  19. package/dist/datafinder/runner.d.cts +28 -5
  20. package/dist/datafinder/runner.d.ts +28 -5
  21. package/dist/datafinder/runner.js +6 -6
  22. package/dist/datafinder/sql-generator.cjs +1203 -206
  23. package/dist/datafinder/sql-generator.cjs.map +1 -1
  24. package/dist/datafinder/sql-generator.d.cts +19 -5
  25. package/dist/datafinder/sql-generator.d.ts +19 -5
  26. package/dist/datafinder/sql-generator.js +9 -5
  27. package/dist/datafinder/typed-attributes.cjs +693 -88
  28. package/dist/datafinder/typed-attributes.cjs.map +1 -1
  29. package/dist/datafinder/typed-attributes.d.cts +3 -242
  30. package/dist/datafinder/typed-attributes.d.ts +3 -242
  31. package/dist/datafinder/typed-attributes.js +3 -3
  32. package/dist/dialect-CogGPm_y.d.cts +38 -0
  33. package/dist/dialect-aaG1bDi5.d.ts +38 -0
  34. package/dist/index.cjs +1677 -408
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +109 -5
  37. package/dist/index.d.ts +109 -5
  38. package/dist/index.js +321 -11
  39. package/dist/index.js.map +1 -1
  40. package/dist/model/milestoning.cjs +529 -0
  41. package/dist/model/milestoning.cjs.map +1 -1
  42. package/dist/model/milestoning.js +2 -2
  43. package/dist/model/relational.cjs +547 -16
  44. package/dist/model/relational.cjs.map +1 -1
  45. package/dist/model/relational.d.cts +421 -57
  46. package/dist/model/relational.d.ts +421 -57
  47. package/dist/model/relational.js +53 -3
  48. package/dist/typed-attributes-CUTf_6Ru.d.ts +328 -0
  49. package/dist/typed-attributes-CdWXq_78.d.cts +328 -0
  50. package/package.json +3 -2
  51. package/dist/chunk-4JVW4TAB.js.map +0 -1
  52. package/dist/chunk-4LNZV6EN.js.map +0 -1
  53. package/dist/chunk-FJYA2ASS.js.map +0 -1
  54. package/dist/chunk-MH4XMYVB.js +0 -696
  55. package/dist/chunk-MH4XMYVB.js.map +0 -1
  56. package/dist/chunk-UYMOE6YU.js +0 -509
  57. package/dist/chunk-UYMOE6YU.js.map +0 -1
  58. /package/dist/{chunk-PMPLCEWQ.js.map → chunk-GPHWC533.js.map} +0 -0
@@ -22,15 +22,24 @@ var relational_exports = {};
22
22
  __export(relational_exports, {
23
23
  AggregateOperation: () => AggregateOperation,
24
24
  AggregateOperator: () => AggregateOperator,
25
+ Aggregates: () => Aggregates,
25
26
  Alias: () => Alias,
27
+ Arithmetic: () => Arithmetic,
28
+ ArithmeticOperation: () => ArithmeticOperation,
29
+ ArithmeticOperator: () => ArithmeticOperator,
26
30
  BinaryOperation: () => BinaryOperation,
31
+ BooleanAggregates: () => BooleanAggregates,
27
32
  BooleanConstantOperation: () => BooleanConstantOperation,
33
+ CaseOperation: () => CaseOperation,
28
34
  Column: () => Column,
29
35
  ColumnWithJoin: () => ColumnWithJoin,
36
+ Comparable: () => Comparable,
30
37
  ComparisonOperation: () => ComparisonOperation,
31
38
  ComparisonOperator: () => ComparisonOperator,
39
+ ConcatOperation: () => ConcatOperation,
32
40
  ConstantOperation: () => ConstantOperation,
33
41
  CountAllOperation: () => CountAllOperation,
42
+ DATE_ONLY_PATTERN: () => DATE_ONLY_PATTERN,
34
43
  DataCatalog: () => DataCatalog,
35
44
  DataStore: () => DataStore,
36
45
  Database: () => Database,
@@ -38,21 +47,28 @@ __export(relational_exports, {
38
47
  DateConstantOperation: () => DateConstantOperation,
39
48
  DateDiffOperation: () => DateDiffOperation,
40
49
  DateExtractOperation: () => DateExtractOperation,
50
+ DateOnly: () => DateOnly,
41
51
  DatePart: () => DatePart,
42
52
  DateTimeConstantOperation: () => DateTimeConstantOperation,
53
+ DateTruncOperation: () => DateTruncOperation,
43
54
  DecimalConstantOperation: () => DecimalConstantOperation,
44
55
  ExistsOperation: () => ExistsOperation,
45
56
  FloatConstantOperation: () => FloatConstantOperation,
46
57
  ForeignKey: () => ForeignKey,
58
+ InOperation: () => InOperation,
47
59
  IntegerConstantOperation: () => IntegerConstantOperation,
48
60
  IsNotNullOperation: () => IsNotNullOperation,
49
61
  IsNullOperation: () => IsNullOperation,
50
62
  JoinOperation: () => JoinOperation,
51
63
  JoinTreeNodeOperation: () => JoinTreeNodeOperation,
64
+ LIKE_ESCAPE: () => LIKE_ESCAPE,
52
65
  LogicalOperation: () => LogicalOperation,
53
66
  LogicalOperator: () => LogicalOperator,
67
+ NUMERIC_FUNCTIONS: () => NUMERIC_FUNCTIONS,
54
68
  NoOperation: () => NoOperation,
55
69
  NotExistsOperation: () => NotExistsOperation,
70
+ NotInOperation: () => NotInOperation,
71
+ NumericConstantOperation: () => NumericConstantOperation,
56
72
  Operation: () => Operation,
57
73
  RelationalOperationElement: () => RelationalOperationElement,
58
74
  ScalarFunction: () => ScalarFunction,
@@ -62,11 +78,20 @@ __export(relational_exports, {
62
78
  SortDirection: () => SortDirection,
63
79
  SortOperation: () => SortOperation,
64
80
  StringConstantOperation: () => StringConstantOperation,
81
+ StringPredicates: () => StringPredicates,
65
82
  Table: () => Table,
66
83
  UnaryOperation: () => UnaryOperation,
67
84
  WindowFunction: () => WindowFunction,
68
85
  WindowFunctionOperation: () => WindowFunctionOperation,
69
- 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
70
95
  });
71
96
  module.exports = __toCommonJS(relational_exports);
72
97
  var ComparisonOperator = /* @__PURE__ */ ((ComparisonOperator2) => {
@@ -80,6 +105,10 @@ var ComparisonOperator = /* @__PURE__ */ ((ComparisonOperator2) => {
80
105
  ComparisonOperator2["NOT_LIKE"] = "NOT_LIKE";
81
106
  return ComparisonOperator2;
82
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
+ }
83
112
  var LogicalOperator = /* @__PURE__ */ ((LogicalOperator2) => {
84
113
  LogicalOperator2["AND"] = "AND";
85
114
  LogicalOperator2["OR"] = "OR";
@@ -91,6 +120,14 @@ var AggregateOperator = /* @__PURE__ */ ((AggregateOperator2) => {
91
120
  AggregateOperator2["MIN"] = "MIN";
92
121
  AggregateOperator2["MAX"] = "MAX";
93
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";
94
131
  return AggregateOperator2;
95
132
  })(AggregateOperator || {});
96
133
  var ScalarFunction = /* @__PURE__ */ ((ScalarFunction2) => {
@@ -113,6 +150,7 @@ var ScalarFunction = /* @__PURE__ */ ((ScalarFunction2) => {
113
150
  ScalarFunction2["REPEAT"] = "REPEAT";
114
151
  ScalarFunction2["REPLACE"] = "REPLACE";
115
152
  ScalarFunction2["SUBSTRING"] = "SUBSTRING";
153
+ ScalarFunction2["COALESCE"] = "COALESCE";
116
154
  return ScalarFunction2;
117
155
  })(ScalarFunction || {});
118
156
  var DatePart = /* @__PURE__ */ ((DatePart2) => {
@@ -135,25 +173,54 @@ var SortDirection = /* @__PURE__ */ ((SortDirection2) => {
135
173
  var RelationalOperationElement = class {
136
174
  };
137
175
  var Operation = class extends RelationalOperationElement {
138
- 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) {
139
181
  return new LogicalOperation(this, "AND" /* AND */, other);
140
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
+ }
141
187
  };
142
188
  var NoOperation = class extends Operation {
143
- andOp(other) {
189
+ and(other) {
144
190
  return other;
145
191
  }
192
+ /** No filter matches every row, so OR-ing anything with it still matches every row. */
193
+ or(_other) {
194
+ return this;
195
+ }
146
196
  };
147
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
+ }
148
215
  };
149
- var IntegerConstantOperation = class extends ConstantOperation {
216
+ var IntegerConstantOperation = class extends NumericConstantOperation {
150
217
  constructor(value) {
151
218
  super();
152
219
  this.value = value;
153
220
  }
154
221
  value;
155
222
  };
156
- var FloatConstantOperation = class extends ConstantOperation {
223
+ var FloatConstantOperation = class extends NumericConstantOperation {
157
224
  constructor(value) {
158
225
  super();
159
226
  this.value = value;
@@ -167,6 +234,9 @@ var StringConstantOperation = class extends ConstantOperation {
167
234
  }
168
235
  value;
169
236
  };
237
+ var DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
238
+ var DateOnly = class extends Date {
239
+ };
170
240
  var DateConstantOperation = class extends ConstantOperation {
171
241
  constructor(value) {
172
242
  super();
@@ -181,7 +251,7 @@ var DateTimeConstantOperation = class extends ConstantOperation {
181
251
  }
182
252
  value;
183
253
  };
184
- var DecimalConstantOperation = class extends ConstantOperation {
254
+ var DecimalConstantOperation = class extends NumericConstantOperation {
185
255
  constructor(value) {
186
256
  super();
187
257
  this.value = value;
@@ -215,6 +285,20 @@ var IsNullOperation = class extends UnaryOperation {
215
285
  };
216
286
  var IsNotNullOperation = class extends UnaryOperation {
217
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
+ };
218
302
  var ComparisonOperation = class extends BinaryOperation {
219
303
  constructor(left, operator, right) {
220
304
  super(left, right);
@@ -238,21 +322,41 @@ var WindowSpecification = class {
238
322
  orderBy;
239
323
  };
240
324
  var AggregateOperation = class _AggregateOperation extends UnaryOperation {
241
- constructor(element, operator, displayName, window) {
325
+ constructor(element, operator, displayName, window, separator, orderBy = []) {
242
326
  super(element);
243
327
  this.operator = operator;
244
328
  this.displayName = displayName;
245
329
  this.window = window;
330
+ this.separator = separator;
331
+ this.orderBy = orderBy;
246
332
  }
247
333
  operator;
248
334
  displayName;
249
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
+ }
250
352
  over(partitionBy, orderBy) {
251
353
  return new _AggregateOperation(
252
354
  this.element,
253
355
  this.operator,
254
356
  this.displayName,
255
- new WindowSpecification(partitionBy ?? [], orderBy ?? [])
357
+ new WindowSpecification(partitionBy ?? [], orderBy ?? []),
358
+ this.separator,
359
+ this.orderBy
256
360
  );
257
361
  }
258
362
  };
@@ -283,6 +387,14 @@ var WindowFunctionOperation = class _WindowFunctionOperation extends UnaryOperat
283
387
  secondArg;
284
388
  extraArgs;
285
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
+ }
286
398
  over(partitionBy, orderBy) {
287
399
  return new _WindowFunctionOperation(
288
400
  this.element,
@@ -306,7 +418,38 @@ var ScalarFunctionOperation = class extends UnaryOperation {
306
418
  displayName;
307
419
  secondArg;
308
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
+ }
309
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
+ ]);
310
453
  var DateExtractOperation = class extends UnaryOperation {
311
454
  constructor(element, part, displayName) {
312
455
  super(element);
@@ -315,6 +458,34 @@ var DateExtractOperation = class extends UnaryOperation {
315
458
  }
316
459
  part;
317
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
+ }
318
489
  };
319
490
  var DateArithmeticOperation = class extends UnaryOperation {
320
491
  constructor(element, n, unit, isAdd = true, displayName) {
@@ -328,6 +499,14 @@ var DateArithmeticOperation = class extends UnaryOperation {
328
499
  unit;
329
500
  isAdd;
330
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
+ }
331
510
  };
332
511
  var DateDiffOperation = class extends UnaryOperation {
333
512
  constructor(element, other, unit, displayName) {
@@ -339,20 +518,31 @@ var DateDiffOperation = class extends UnaryOperation {
339
518
  other;
340
519
  unit;
341
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
+ }
342
529
  };
343
530
  var Column = class extends RelationalOperationElement {
344
- constructor(name, type, owner, primaryKey = false) {
531
+ constructor(name, type, owner, primaryKey = false, nullable = true) {
345
532
  super();
346
533
  this.name = name;
347
534
  this.type = type;
348
535
  this.owner = owner;
349
536
  this.primaryKey = primaryKey;
537
+ this.nullable = nullable && !primaryKey;
350
538
  }
351
539
  name;
352
540
  type;
353
541
  owner;
354
542
  primaryKey;
355
543
  table;
544
+ /** Whether the column may hold NULL. As in Legend, a primary key is never null. */
545
+ nullable;
356
546
  };
357
547
  var ForeignKey = class {
358
548
  constructor(column, references) {
@@ -442,27 +632,40 @@ var JoinOperation = class {
442
632
  filterColumnMap = {};
443
633
  };
444
634
  var JoinTreeNodeOperation = class {
445
- constructor(join, parent) {
635
+ constructor(join, parent, many = false, optional = false) {
446
636
  this.join = join;
447
637
  this.parent = parent;
638
+ this.many = many;
639
+ this.optional = optional;
448
640
  }
449
641
  join;
450
642
  parent;
643
+ many;
644
+ optional;
451
645
  };
452
646
  var ColumnWithJoin = class extends RelationalOperationElement {
453
647
  /**
454
648
  * `embedded` is an alternate reference to a flat (denormalized) column on the owning table that
455
649
  * holds the same value without the join; the SQL generator uses it when the join can be elided.
456
650
  */
457
- constructor(column, parent, embedded) {
651
+ constructor(column, parent, embedded, _optional = false) {
458
652
  super();
459
653
  this.column = column;
460
654
  this.parent = parent;
461
655
  this.embedded = embedded;
656
+ this._optional = _optional;
462
657
  }
463
658
  column;
464
659
  parent;
465
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
+ }
466
669
  };
467
670
  var SortOperation = class {
468
671
  constructor(column, direction) {
@@ -478,8 +681,23 @@ var CountAllOperation = class extends RelationalOperationElement {
478
681
  this.table = table;
479
682
  }
480
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
+ }
481
699
  };
482
- var Alias = class extends RelationalOperationElement {
700
+ var Alias = class _Alias extends RelationalOperationElement {
483
701
  constructor(element, name) {
484
702
  super();
485
703
  this.element = element;
@@ -487,6 +705,30 @@ var Alias = class extends RelationalOperationElement {
487
705
  }
488
706
  element;
489
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;
490
732
  };
491
733
  var ExistsOperation = class extends RelationalOperationElement {
492
734
  constructor(node) {
@@ -494,9 +736,16 @@ var ExistsOperation = class extends RelationalOperationElement {
494
736
  this.node = node;
495
737
  }
496
738
  node;
497
- andOp(other) {
739
+ /** Name this column in the result. */
740
+ alias(name) {
741
+ return new Alias(this, name);
742
+ }
743
+ and(other) {
498
744
  return new LogicalOperation(this, "AND" /* AND */, other);
499
745
  }
746
+ or(other) {
747
+ return new LogicalOperation(this, "OR" /* OR */, other);
748
+ }
500
749
  };
501
750
  var NotExistsOperation = class extends RelationalOperationElement {
502
751
  constructor(node) {
@@ -504,12 +753,19 @@ var NotExistsOperation = class extends RelationalOperationElement {
504
753
  this.node = node;
505
754
  }
506
755
  node;
507
- andOp(other) {
756
+ /** Name this column in the result. */
757
+ alias(name) {
758
+ return new Alias(this, name);
759
+ }
760
+ and(other) {
508
761
  return new LogicalOperation(this, "AND" /* AND */, other);
509
762
  }
763
+ or(other) {
764
+ return new LogicalOperation(this, "OR" /* OR */, other);
765
+ }
510
766
  };
511
767
  var SelectOperation = class {
512
- constructor(display, filter, orderBy = [], groupBy = [], limit, table, joinFilters = /* @__PURE__ */ new Map()) {
768
+ constructor(display, filter, orderBy = [], groupBy = [], limit, table, joinFilters = /* @__PURE__ */ new Map(), distinct = false, offset, having) {
513
769
  this.display = display;
514
770
  this.filter = filter;
515
771
  this.orderBy = orderBy;
@@ -517,6 +773,9 @@ var SelectOperation = class {
517
773
  this.limit = limit;
518
774
  this.table = table;
519
775
  this.joinFilters = joinFilters;
776
+ this.distinct = distinct;
777
+ this.offset = offset;
778
+ this.having = having;
520
779
  }
521
780
  display;
522
781
  filter;
@@ -525,20 +784,276 @@ var SelectOperation = class {
525
784
  limit;
526
785
  table;
527
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
+ }
528
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]);
529
1035
  // Annotate the CommonJS export names for ESM import in node:
530
1036
  0 && (module.exports = {
531
1037
  AggregateOperation,
532
1038
  AggregateOperator,
1039
+ Aggregates,
533
1040
  Alias,
1041
+ Arithmetic,
1042
+ ArithmeticOperation,
1043
+ ArithmeticOperator,
534
1044
  BinaryOperation,
1045
+ BooleanAggregates,
535
1046
  BooleanConstantOperation,
1047
+ CaseOperation,
536
1048
  Column,
537
1049
  ColumnWithJoin,
1050
+ Comparable,
538
1051
  ComparisonOperation,
539
1052
  ComparisonOperator,
1053
+ ConcatOperation,
540
1054
  ConstantOperation,
541
1055
  CountAllOperation,
1056
+ DATE_ONLY_PATTERN,
542
1057
  DataCatalog,
543
1058
  DataStore,
544
1059
  Database,
@@ -546,21 +1061,28 @@ var SelectOperation = class {
546
1061
  DateConstantOperation,
547
1062
  DateDiffOperation,
548
1063
  DateExtractOperation,
1064
+ DateOnly,
549
1065
  DatePart,
550
1066
  DateTimeConstantOperation,
1067
+ DateTruncOperation,
551
1068
  DecimalConstantOperation,
552
1069
  ExistsOperation,
553
1070
  FloatConstantOperation,
554
1071
  ForeignKey,
1072
+ InOperation,
555
1073
  IntegerConstantOperation,
556
1074
  IsNotNullOperation,
557
1075
  IsNullOperation,
558
1076
  JoinOperation,
559
1077
  JoinTreeNodeOperation,
1078
+ LIKE_ESCAPE,
560
1079
  LogicalOperation,
561
1080
  LogicalOperator,
1081
+ NUMERIC_FUNCTIONS,
562
1082
  NoOperation,
563
1083
  NotExistsOperation,
1084
+ NotInOperation,
1085
+ NumericConstantOperation,
564
1086
  Operation,
565
1087
  RelationalOperationElement,
566
1088
  ScalarFunction,
@@ -570,10 +1092,19 @@ var SelectOperation = class {
570
1092
  SortDirection,
571
1093
  SortOperation,
572
1094
  StringConstantOperation,
1095
+ StringPredicates,
573
1096
  Table,
574
1097
  UnaryOperation,
575
1098
  WindowFunction,
576
1099
  WindowFunctionOperation,
577
- WindowSpecification
1100
+ WindowSpecification,
1101
+ applyMixins,
1102
+ concat,
1103
+ containsAggregate,
1104
+ containsAggregateOrWindow,
1105
+ escapeLike,
1106
+ operandOf,
1107
+ sample,
1108
+ valueOperand
578
1109
  });
579
1110
  //# sourceMappingURL=relational.cjs.map