data-finder-ts 0.1.3 → 0.1.4

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 (52) hide show
  1. package/README.md +17 -55
  2. package/dist/{chunk-V647VNMY.js → chunk-4JVW4TAB.js} +59 -14
  3. package/dist/chunk-4JVW4TAB.js.map +1 -0
  4. package/dist/{chunk-5K2Z3YDY.js → chunk-4LNZV6EN.js} +138 -31
  5. package/dist/chunk-4LNZV6EN.js.map +1 -0
  6. package/dist/{chunk-6QTCGJWX.js → chunk-FJYA2ASS.js} +46 -8
  7. package/dist/chunk-FJYA2ASS.js.map +1 -0
  8. package/dist/{chunk-DFYZVBII.js → chunk-MH4XMYVB.js} +186 -142
  9. package/dist/chunk-MH4XMYVB.js.map +1 -0
  10. package/dist/{chunk-EYXBYV2X.js → chunk-PMPLCEWQ.js} +2 -2
  11. package/dist/{chunk-3SSWFES4.js → chunk-UYMOE6YU.js} +64 -3
  12. package/dist/chunk-UYMOE6YU.js.map +1 -0
  13. package/dist/datafinder/attribute.cjs +64 -13
  14. package/dist/datafinder/attribute.cjs.map +1 -1
  15. package/dist/datafinder/attribute.d.cts +48 -7
  16. package/dist/datafinder/attribute.d.ts +48 -7
  17. package/dist/datafinder/attribute.js +2 -2
  18. package/dist/datafinder/runner.cjs +389 -140
  19. package/dist/datafinder/runner.cjs.map +1 -1
  20. package/dist/datafinder/runner.d.cts +14 -3
  21. package/dist/datafinder/runner.d.ts +14 -3
  22. package/dist/datafinder/runner.js +12 -6
  23. package/dist/datafinder/sql-generator.cjs +344 -138
  24. package/dist/datafinder/sql-generator.cjs.map +1 -1
  25. package/dist/datafinder/sql-generator.d.cts +4 -13
  26. package/dist/datafinder/sql-generator.d.ts +4 -13
  27. package/dist/datafinder/sql-generator.js +5 -7
  28. package/dist/datafinder/typed-attributes.cjs +199 -41
  29. package/dist/datafinder/typed-attributes.cjs.map +1 -1
  30. package/dist/datafinder/typed-attributes.d.cts +120 -13
  31. package/dist/datafinder/typed-attributes.d.ts +120 -13
  32. package/dist/datafinder/typed-attributes.js +3 -3
  33. package/dist/index.cjs +507 -176
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +16 -15
  36. package/dist/index.d.ts +16 -15
  37. package/dist/index.js +49 -9
  38. package/dist/index.js.map +1 -1
  39. package/dist/model/milestoning.cjs.map +1 -1
  40. package/dist/model/milestoning.js +2 -2
  41. package/dist/model/relational.cjs +66 -1
  42. package/dist/model/relational.cjs.map +1 -1
  43. package/dist/model/relational.d.cts +47 -2
  44. package/dist/model/relational.d.ts +47 -2
  45. package/dist/model/relational.js +9 -1
  46. package/package.json +4 -2
  47. package/dist/chunk-3SSWFES4.js.map +0 -1
  48. package/dist/chunk-5K2Z3YDY.js.map +0 -1
  49. package/dist/chunk-6QTCGJWX.js.map +0 -1
  50. package/dist/chunk-DFYZVBII.js.map +0 -1
  51. package/dist/chunk-V647VNMY.js.map +0 -1
  52. /package/dist/{chunk-EYXBYV2X.js.map → chunk-PMPLCEWQ.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -22,6 +22,7 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  AggregateOperation: () => AggregateOperation,
24
24
  AggregateOperator: () => AggregateOperator,
25
+ Alias: () => Alias,
25
26
  Attribute: () => Attribute,
26
27
  BiTemporalColumns: () => BiTemporalColumns,
27
28
  BinaryOperation: () => BinaryOperation,
@@ -34,6 +35,7 @@ __export(src_exports, {
34
35
  ComparisonOperator: () => ComparisonOperator,
35
36
  ConstantOperation: () => ConstantOperation,
36
37
  CountAllOperation: () => CountAllOperation,
38
+ DEFAULT_TIMEOUT_MS: () => DEFAULT_TIMEOUT_MS,
37
39
  DataCatalog: () => DataCatalog,
38
40
  DataStore: () => DataStore,
39
41
  Database: () => Database,
@@ -68,11 +70,13 @@ __export(src_exports, {
68
70
  NumericAttribute: () => NumericAttribute,
69
71
  Operation: () => Operation,
70
72
  ProcessingTemporalColumns: () => ProcessingTemporalColumns,
73
+ QueryTimeoutError: () => QueryTimeoutError,
71
74
  RelatedFinder: () => RelatedFinder,
72
75
  RelationalOperationElement: () => RelationalOperationElement,
73
76
  ScalarFunction: () => ScalarFunction,
74
77
  ScalarFunctionOperation: () => ScalarFunctionOperation,
75
78
  Schema: () => Schema,
79
+ SelectOperation: () => SelectOperation,
76
80
  SingleBusinessDateColumn: () => SingleBusinessDateColumn,
77
81
  SortDirection: () => SortDirection,
78
82
  SortOperation: () => SortOperation,
@@ -85,11 +89,14 @@ __export(src_exports, {
85
89
  WindowSpecification: () => WindowSpecification,
86
90
  clearRunner: () => clearRunner,
87
91
  convertInputsAndSelect: () => convertInputsAndSelect,
92
+ convertInputsAndSelectForDateRange: () => convertInputsAndSelectForDateRange,
93
+ embeddedUnder: () => embeddedUnder,
88
94
  getRelatedFinderClass: () => getRelatedFinderClass,
89
95
  getRunner: () => getRunner,
90
96
  registerRelatedFinderClass: () => registerRelatedFinderClass,
91
97
  registerRunner: () => registerRunner,
92
98
  selectSqlToString: () => selectSqlToString,
99
+ titleCase: () => titleCase,
93
100
  toSql: () => toSql
94
101
  });
95
102
  module.exports = __toCommonJS(src_exports);
@@ -462,6 +469,10 @@ var JoinOperation = class {
462
469
  left;
463
470
  right;
464
471
  filter;
472
+ /** Property-equality filters on the join target (property id -> value), set by a related finder given a filter. */
473
+ filterKwargs = {};
474
+ /** Maps property ids to [column, type, table] for `filterKwargs`. */
475
+ filterColumnMap = {};
465
476
  };
466
477
  var JoinTreeNodeOperation = class {
467
478
  constructor(join, parent) {
@@ -472,13 +483,19 @@ var JoinTreeNodeOperation = class {
472
483
  parent;
473
484
  };
474
485
  var ColumnWithJoin = class extends RelationalOperationElement {
475
- constructor(column, parent) {
486
+ /**
487
+ * `embedded` is an alternate reference to a flat (denormalized) column on the owning table that
488
+ * holds the same value without the join; the SQL generator uses it when the join can be elided.
489
+ */
490
+ constructor(column, parent, embedded) {
476
491
  super();
477
492
  this.column = column;
478
493
  this.parent = parent;
494
+ this.embedded = embedded;
479
495
  }
480
496
  column;
481
497
  parent;
498
+ embedded;
482
499
  };
483
500
  var SortOperation = class {
484
501
  constructor(column, direction) {
@@ -495,18 +512,67 @@ var CountAllOperation = class extends RelationalOperationElement {
495
512
  }
496
513
  table;
497
514
  };
515
+ var Alias = class extends RelationalOperationElement {
516
+ constructor(element, name) {
517
+ super();
518
+ this.element = element;
519
+ this.name = name;
520
+ }
521
+ element;
522
+ name;
523
+ };
524
+ var ExistsOperation = class extends RelationalOperationElement {
525
+ constructor(node) {
526
+ super();
527
+ this.node = node;
528
+ }
529
+ node;
530
+ andOp(other) {
531
+ return new LogicalOperation(this, "AND" /* AND */, other);
532
+ }
533
+ };
534
+ var NotExistsOperation = class extends RelationalOperationElement {
535
+ constructor(node) {
536
+ super();
537
+ this.node = node;
538
+ }
539
+ node;
540
+ andOp(other) {
541
+ return new LogicalOperation(this, "AND" /* AND */, other);
542
+ }
543
+ };
544
+ var SelectOperation = class {
545
+ constructor(display, filter, orderBy = [], groupBy = [], limit, table, joinFilters = /* @__PURE__ */ new Map()) {
546
+ this.display = display;
547
+ this.filter = filter;
548
+ this.orderBy = orderBy;
549
+ this.groupBy = groupBy;
550
+ this.limit = limit;
551
+ this.table = table;
552
+ this.joinFilters = joinFilters;
553
+ }
554
+ display;
555
+ filter;
556
+ orderBy;
557
+ groupBy;
558
+ limit;
559
+ table;
560
+ joinFilters;
561
+ };
498
562
 
499
563
  // src/datafinder/attribute.ts
500
- var Attribute = class {
564
+ var Attribute = class _Attribute {
501
565
  _displayName;
502
566
  _column;
503
567
  _owner;
504
568
  _parent;
505
- constructor(displayName, columnName, columnDbType, owner, parent) {
569
+ _embedded;
570
+ constructor(displayName, columnName, columnDbType, owner, parent, embedded) {
506
571
  this._displayName = displayName;
507
572
  this._column = new Column(columnName, columnDbType, owner);
508
573
  this._owner = owner;
509
574
  this._parent = parent;
575
+ this._embedded = embedded;
510
576
  }
511
577
  column() {
512
578
  return this._column;
@@ -520,33 +586,58 @@ var Attribute = class {
520
586
  displayName() {
521
587
  return this._displayName;
522
588
  }
589
+ /** Alternate attribute on a flat column of the owning table, used in place of this one when its join is elided. */
590
+ embedded() {
591
+ return this._embedded;
592
+ }
523
593
  cwj() {
524
- return new ColumnWithJoin(this._column, this._parent);
594
+ return new ColumnWithJoin(this._column, this._parent, this._embedded?.cwj());
525
595
  }
596
+ /** Count the number of non-null values. Use in a projection with `groupByOp` to aggregate per group. */
526
597
  count() {
527
598
  return new AggregateOperation(
528
- new ColumnWithJoin(this._column, this._parent),
599
+ this.cwj(),
529
600
  "COUNT" /* COUNT */,
530
601
  this._displayName + " Count"
531
602
  );
532
603
  }
604
+ /** Sort this attribute in ascending order. Pass to `orderByOp` or a window function's `orderBy`. */
533
605
  ascending() {
534
- return new SortOperation(new ColumnWithJoin(this._column, this._parent), "ASC" /* ASC */);
606
+ return new SortOperation(this.cwj(), "ASC" /* ASC */);
535
607
  }
608
+ /** Sort this attribute in descending order. Pass to `orderByOp` or a window function's `orderBy`. */
536
609
  descending() {
537
- return new SortOperation(new ColumnWithJoin(this._column, this._parent), "DESC" /* DESC */);
610
+ return new SortOperation(this.cwj(), "DESC" /* DESC */);
538
611
  }
612
+ /** Filter to rows where this attribute has no value. */
539
613
  isNull() {
540
- return new IsNullOperation(new ColumnWithJoin(this._column, this._parent));
614
+ return new IsNullOperation(this.cwj());
541
615
  }
616
+ /** Filter to rows where this attribute has a value. */
542
617
  isNotNull() {
543
- return new IsNotNullOperation(new ColumnWithJoin(this._column, this._parent));
618
+ return new IsNotNullOperation(this.cwj());
544
619
  }
545
620
  _windowSpec(partitionBy, orderBy) {
546
- const pb = partitionBy === void 0 ? [] : Array.isArray(partitionBy) ? partitionBy : [partitionBy];
621
+ const pbArr = partitionBy === void 0 ? [] : Array.isArray(partitionBy) ? partitionBy : [partitionBy];
622
+ const pb = pbArr.map((x) => x instanceof _Attribute ? x.cwj() : x);
547
623
  const ob = orderBy === void 0 ? [] : Array.isArray(orderBy) ? orderBy : [orderBy];
548
624
  return new WindowSpecification(pb, ob);
549
625
  }
626
+ /**
627
+ * Assign a rank to each row within the ordered window, following pandas `Series.rank` conventions.
628
+ *
629
+ * `method` controls tie-breaking (default `'min'`):
630
+ * - `'min'` — tied rows share the lowest rank; the next rank skips.
631
+ * - `'dense'` — like `'min'` but ranks are contiguous (no gaps).
632
+ * - `'first'` — each row gets a unique sequential integer (no ties).
633
+ * - `'max'` — only meaningful with `pct: true` (see below).
634
+ *
635
+ * When `pct: true` the result is a relative rank between 0 and 1:
636
+ * - `method: 'min'` (default) → fraction of values strictly below this row (PERCENT_RANK).
637
+ * - `method: 'max'` → fraction of values at or below this row (cumulative distribution).
638
+ *
639
+ * `partitionBy` restarts the ranking within each group of distinct values.
640
+ */
550
641
  rank(opts = {}) {
551
642
  const { method = "min", pct = false, partitionBy, orderBy } = opts;
552
643
  let func;
@@ -571,6 +662,11 @@ var Attribute = class {
571
662
  }
572
663
  return new WindowFunctionOperation(null, func, name, void 0, [], this._windowSpec(partitionBy, orderBy));
573
664
  }
665
+ /**
666
+ * Split rows into `buckets` equal-sized quantile bins ordered by `orderBy`.
667
+ * Each row receives a bucket number from 1 (lowest) to `buckets` (highest).
668
+ * Named after `pandas.qcut`.
669
+ */
574
670
  qcut(buckets, opts = {}) {
575
671
  return new WindowFunctionOperation(
576
672
  null,
@@ -581,12 +677,17 @@ var Attribute = class {
581
677
  this._windowSpec(opts.partitionBy, opts.orderBy)
582
678
  );
583
679
  }
680
+ /**
681
+ * Return the value of this attribute from `periods` rows earlier (positive) or later (negative)
682
+ * within the ordered window, following `pandas.Series.shift`.
683
+ * Rows with no neighbour at the given offset return `null` (or `fillValue` if provided).
684
+ */
584
685
  shift(periods = 1, opts = {}) {
585
686
  const extraArgs = opts.fillValue !== void 0 ? [opts.fillValue] : [];
586
687
  const func = periods >= 0 ? "LAG" /* LAG */ : "LEAD" /* LEAD */;
587
688
  const label = periods >= 0 ? "Lag" : "Lead";
588
689
  return new WindowFunctionOperation(
589
- new ColumnWithJoin(this._column, this._parent),
690
+ this.cwj(),
590
691
  func,
591
692
  label + " " + this._displayName,
592
693
  Math.abs(periods),
@@ -594,9 +695,13 @@ var Attribute = class {
594
695
  this._windowSpec(opts.partitionBy, opts.orderBy)
595
696
  );
596
697
  }
698
+ /**
699
+ * Return the first value of this attribute in the window frame.
700
+ * Use `partitionBy` to restart the frame for each group.
701
+ */
597
702
  first(opts = {}) {
598
703
  return new WindowFunctionOperation(
599
- new ColumnWithJoin(this._column, this._parent),
704
+ this.cwj(),
600
705
  "FIRST_VALUE" /* FIRST_VALUE */,
601
706
  "First " + this._displayName,
602
707
  void 0,
@@ -604,9 +709,13 @@ var Attribute = class {
604
709
  this._windowSpec(opts.partitionBy, opts.orderBy)
605
710
  );
606
711
  }
712
+ /**
713
+ * Return the last value of this attribute in the window frame.
714
+ * Use `partitionBy` to restart the frame for each group.
715
+ */
607
716
  last(opts = {}) {
608
717
  return new WindowFunctionOperation(
609
- new ColumnWithJoin(this._column, this._parent),
718
+ this.cwj(),
610
719
  "LAST_VALUE" /* LAST_VALUE */,
611
720
  "Last " + this._displayName,
612
721
  void 0,
@@ -627,183 +736,236 @@ function getRelatedFinderClass(name) {
627
736
 
628
737
  // src/datafinder/typed-attributes.ts
629
738
  var StringAttribute = class extends Attribute {
630
- constructor(displayName, columnName, columnDbType, owner, parent) {
631
- super(displayName, columnName, columnDbType, owner, parent);
739
+ constructor(displayName, columnName, columnDbType, owner, parent, embedded) {
740
+ super(displayName, columnName, columnDbType, owner, parent, embedded);
632
741
  }
633
- upper() {
742
+ /** Convert every character to uppercase. */
743
+ toUpperCase() {
634
744
  return new ScalarFunctionOperation(this.cwj(), "UPPER" /* UPPER */, "Upper " + this.displayName());
635
745
  }
636
- lower() {
746
+ /** Convert every character to lowercase. */
747
+ toLowerCase() {
637
748
  return new ScalarFunctionOperation(this.cwj(), "LOWER" /* LOWER */, "Lower " + this.displayName());
638
749
  }
639
- strip() {
640
- return new ScalarFunctionOperation(this.cwj(), "TRIM" /* TRIM */, "Strip " + this.displayName());
750
+ /** Remove leading and trailing whitespace. */
751
+ trim() {
752
+ return new ScalarFunctionOperation(this.cwj(), "TRIM" /* TRIM */, "Trim " + this.displayName());
641
753
  }
642
- lstrip() {
643
- return new ScalarFunctionOperation(this.cwj(), "LTRIM" /* LTRIM */, "LStrip " + this.displayName());
754
+ /** Remove leading whitespace. */
755
+ trimStart() {
756
+ return new ScalarFunctionOperation(this.cwj(), "LTRIM" /* LTRIM */, "Trim Start " + this.displayName());
644
757
  }
645
- rstrip() {
646
- return new ScalarFunctionOperation(this.cwj(), "RTRIM" /* RTRIM */, "RStrip " + this.displayName());
758
+ /** Remove trailing whitespace. */
759
+ trimEnd() {
760
+ return new ScalarFunctionOperation(this.cwj(), "RTRIM" /* RTRIM */, "Trim End " + this.displayName());
647
761
  }
762
+ /** Return the number of characters in the string. */
648
763
  length() {
649
764
  return new ScalarFunctionOperation(this.cwj(), "LENGTH" /* LENGTH */, "Length " + this.displayName());
650
765
  }
766
+ /** Return the string with characters in reverse order. */
651
767
  reverse() {
652
768
  return new ScalarFunctionOperation(this.cwj(), "REVERSE" /* REVERSE */, "Reverse " + this.displayName());
653
769
  }
770
+ /** Return the first `n` characters. */
654
771
  left(n) {
655
772
  return new ScalarFunctionOperation(this.cwj(), "LEFT" /* LEFT */, "Left " + this.displayName(), n);
656
773
  }
774
+ /** Return the last `n` characters. */
657
775
  right(n) {
658
776
  return new ScalarFunctionOperation(this.cwj(), "RIGHT" /* RIGHT */, "Right " + this.displayName(), n);
659
777
  }
778
+ /** Return the string repeated `n` times. */
660
779
  repeat(n) {
661
780
  return new ScalarFunctionOperation(this.cwj(), "REPEAT" /* REPEAT */, "Repeat " + this.displayName(), n);
662
781
  }
782
+ /** Replace all occurrences of `fromStr` with `toStr`. */
663
783
  replace(fromStr, toStr) {
664
784
  return new ScalarFunctionOperation(this.cwj(), "REPLACE" /* REPLACE */, "Replace " + this.displayName(), void 0, [fromStr, toStr]);
665
785
  }
786
+ /**
787
+ * Extract a portion of the string.
788
+ * `start` is zero-based (following Python convention); `length` is optional.
789
+ */
666
790
  substring(start, length) {
667
791
  const args = length !== void 0 ? [start + 1, length] : [start + 1];
668
792
  return new ScalarFunctionOperation(this.cwj(), "SUBSTRING" /* SUBSTRING */, "Substring " + this.displayName(), void 0, args);
669
793
  }
794
+ /** Filter to rows where this attribute equals `value`. */
670
795
  eq(value) {
671
796
  return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new StringConstantOperation(value));
672
797
  }
798
+ /** Filter to rows where this attribute does not equal `value`. */
673
799
  ne(value) {
674
800
  return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new StringConstantOperation(value));
675
801
  }
802
+ /** Filter to rows where this attribute contains `value` as a substring. */
676
803
  contains(value) {
677
804
  return new ComparisonOperation(this.cwj(), "LIKE" /* LIKE */, new StringConstantOperation(`%${value}%`));
678
805
  }
806
+ /** Filter to rows where this attribute begins with `prefix`. */
679
807
  startsWith(prefix) {
680
808
  return new ComparisonOperation(this.cwj(), "LIKE" /* LIKE */, new StringConstantOperation(`${prefix}%`));
681
809
  }
810
+ /** Filter to rows where this attribute ends with `suffix`. */
682
811
  endsWith(suffix) {
683
812
  return new ComparisonOperation(this.cwj(), "LIKE" /* LIKE */, new StringConstantOperation(`%${suffix}`));
684
813
  }
814
+ /** Filter to rows where this attribute does not contain `value` as a substring. */
685
815
  notContains(value) {
686
816
  return new ComparisonOperation(this.cwj(), "NOT_LIKE" /* NOT_LIKE */, new StringConstantOperation(`%${value}%`));
687
817
  }
688
818
  };
689
819
  var NumericAttribute = class extends Attribute {
690
- constructor(displayName, columnName, columnDbType, owner, parent) {
691
- super(displayName, columnName, columnDbType, owner, parent);
820
+ constructor(displayName, columnName, columnDbType, owner, parent, embedded) {
821
+ super(displayName, columnName, columnDbType, owner, parent, embedded);
692
822
  }
823
+ /** Sum of all values in the group. */
693
824
  sum() {
694
- return new AggregateOperation(this.cwj(), "SUM" /* SUM */, this.displayName() + " Sum");
825
+ return new AggregateOperation(this.cwj(), "SUM" /* SUM */, "Sum " + this.displayName());
695
826
  }
827
+ /** Smallest value in the group. */
696
828
  min() {
697
- return new AggregateOperation(this.cwj(), "MIN" /* MIN */, this.displayName() + " Min");
829
+ return new AggregateOperation(this.cwj(), "MIN" /* MIN */, "Min " + this.displayName());
698
830
  }
831
+ /** Largest value in the group. */
699
832
  max() {
700
- return new AggregateOperation(this.cwj(), "MAX" /* MAX */, this.displayName() + " Max");
833
+ return new AggregateOperation(this.cwj(), "MAX" /* MAX */, "Max " + this.displayName());
701
834
  }
835
+ /** Arithmetic mean of all values in the group. */
702
836
  average() {
703
- return new AggregateOperation(this.cwj(), "AVERAGE" /* AVERAGE */, this.displayName() + " Average");
837
+ return new AggregateOperation(this.cwj(), "AVERAGE" /* AVERAGE */, "Average " + this.displayName());
704
838
  }
839
+ /** Absolute value (distance from zero, always non-negative). */
705
840
  abs() {
706
841
  return new ScalarFunctionOperation(this.cwj(), "ABS" /* ABS */, "Abs " + this.displayName());
707
842
  }
843
+ /** Round up to the nearest integer. */
708
844
  ceil() {
709
845
  return new ScalarFunctionOperation(this.cwj(), "CEILING" /* CEILING */, "Ceil " + this.displayName());
710
846
  }
847
+ /** Round down to the nearest integer. */
711
848
  floor() {
712
849
  return new ScalarFunctionOperation(this.cwj(), "FLOOR" /* FLOOR */, "Floor " + this.displayName());
713
850
  }
851
+ /** Square root. */
714
852
  sqrt() {
715
853
  return new ScalarFunctionOperation(this.cwj(), "SQRT" /* SQRT */, "Sqrt " + this.displayName());
716
854
  }
855
+ /** Remainder after dividing by `n`. */
717
856
  mod(n) {
718
857
  return new ScalarFunctionOperation(this.cwj(), "MOD" /* MOD */, "Mod " + this.displayName(), n);
719
858
  }
859
+ /** Raise to the power of `n`. */
720
860
  power(n) {
721
861
  return new ScalarFunctionOperation(this.cwj(), "POWER" /* POWER */, "Power " + this.displayName(), n);
722
862
  }
863
+ /** Round to `d` decimal places, or to the nearest integer when `d` is omitted. */
723
864
  round(d) {
724
865
  return new ScalarFunctionOperation(this.cwj(), "ROUND" /* ROUND */, "Round " + this.displayName(), d);
725
866
  }
726
867
  };
727
868
  var DoubleAttribute = class extends NumericAttribute {
728
- constructor(displayName, columnName, columnDbType, owner, parent) {
729
- super(displayName, columnName, columnDbType, owner, parent);
869
+ constructor(displayName, columnName, columnDbType, owner, parent, embedded) {
870
+ super(displayName, columnName, columnDbType, owner, parent, embedded);
730
871
  }
872
+ /** Filter to rows where this attribute equals `value`. */
731
873
  eq(value) {
732
874
  return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new FloatConstantOperation(value));
733
875
  }
876
+ /** Filter to rows where this attribute does not equal `value`. */
734
877
  ne(value) {
735
878
  return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new FloatConstantOperation(value));
736
879
  }
880
+ /** Filter to rows where this attribute is greater than `value`. */
737
881
  gt(value) {
738
882
  return new ComparisonOperation(this.cwj(), "GREATER_THAN" /* GREATER_THAN */, new FloatConstantOperation(value));
739
883
  }
884
+ /** Filter to rows where this attribute is less than `value`. */
740
885
  lt(value) {
741
886
  return new ComparisonOperation(this.cwj(), "LESS_THAN" /* LESS_THAN */, new FloatConstantOperation(value));
742
887
  }
888
+ /** Filter to rows where this attribute is greater than or equal to `value`. */
743
889
  gte(value) {
744
890
  return new ComparisonOperation(this.cwj(), "GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, new FloatConstantOperation(value));
745
891
  }
892
+ /** Filter to rows where this attribute is less than or equal to `value`. */
746
893
  lte(value) {
747
894
  return new ComparisonOperation(this.cwj(), "LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, new FloatConstantOperation(value));
748
895
  }
749
896
  };
750
897
  var FloatAttribute = DoubleAttribute;
751
898
  var DecimalAttribute = class extends NumericAttribute {
752
- constructor(displayName, columnName, columnDbType, owner, parent) {
753
- super(displayName, columnName, columnDbType, owner, parent);
899
+ constructor(displayName, columnName, columnDbType, owner, parent, embedded) {
900
+ super(displayName, columnName, columnDbType, owner, parent, embedded);
754
901
  }
902
+ /** Filter to rows where this attribute equals `value`. */
755
903
  eq(value) {
756
904
  return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new DecimalConstantOperation(value));
757
905
  }
906
+ /** Filter to rows where this attribute does not equal `value`. */
758
907
  ne(value) {
759
908
  return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new DecimalConstantOperation(value));
760
909
  }
910
+ /** Filter to rows where this attribute is greater than `value`. */
761
911
  gt(value) {
762
912
  return new ComparisonOperation(this.cwj(), "GREATER_THAN" /* GREATER_THAN */, new DecimalConstantOperation(value));
763
913
  }
914
+ /** Filter to rows where this attribute is less than `value`. */
764
915
  lt(value) {
765
916
  return new ComparisonOperation(this.cwj(), "LESS_THAN" /* LESS_THAN */, new DecimalConstantOperation(value));
766
917
  }
918
+ /** Filter to rows where this attribute is greater than or equal to `value`. */
767
919
  gte(value) {
768
920
  return new ComparisonOperation(this.cwj(), "GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, new DecimalConstantOperation(value));
769
921
  }
922
+ /** Filter to rows where this attribute is less than or equal to `value`. */
770
923
  lte(value) {
771
924
  return new ComparisonOperation(this.cwj(), "LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, new DecimalConstantOperation(value));
772
925
  }
773
926
  };
774
927
  var IntegerAttribute = class extends NumericAttribute {
775
- constructor(displayName, columnName, columnDbType, owner, parent) {
776
- super(displayName, columnName, columnDbType, owner, parent);
928
+ constructor(displayName, columnName, columnDbType, owner, parent, embedded) {
929
+ super(displayName, columnName, columnDbType, owner, parent, embedded);
777
930
  }
931
+ /** Filter to rows where this attribute equals `value`. */
778
932
  eq(value) {
779
933
  return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new IntegerConstantOperation(value));
780
934
  }
935
+ /** Filter to rows where this attribute does not equal `value`. */
781
936
  ne(value) {
782
937
  return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new IntegerConstantOperation(value));
783
938
  }
939
+ /** Filter to rows where this attribute is greater than `value`. */
784
940
  gt(value) {
785
941
  return new ComparisonOperation(this.cwj(), "GREATER_THAN" /* GREATER_THAN */, new IntegerConstantOperation(value));
786
942
  }
943
+ /** Filter to rows where this attribute is less than `value`. */
787
944
  lt(value) {
788
945
  return new ComparisonOperation(this.cwj(), "LESS_THAN" /* LESS_THAN */, new IntegerConstantOperation(value));
789
946
  }
947
+ /** Filter to rows where this attribute is greater than or equal to `value`. */
790
948
  gte(value) {
791
949
  return new ComparisonOperation(this.cwj(), "GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, new IntegerConstantOperation(value));
792
950
  }
951
+ /** Filter to rows where this attribute is less than or equal to `value`. */
793
952
  lte(value) {
794
953
  return new ComparisonOperation(this.cwj(), "LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, new IntegerConstantOperation(value));
795
954
  }
796
955
  };
797
956
  var BooleanAttribute = class extends Attribute {
798
- constructor(displayName, columnName, columnDbType, owner, parent) {
799
- super(displayName, columnName, columnDbType, owner, parent);
957
+ constructor(displayName, columnName, columnDbType, owner, parent, embedded) {
958
+ super(displayName, columnName, columnDbType, owner, parent, embedded);
800
959
  }
960
+ /** Filter to rows where this attribute equals `value`. */
801
961
  eq(value) {
802
962
  return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new BooleanConstantOperation(value));
803
963
  }
964
+ /** Filter to rows where this attribute is true. */
804
965
  isTrue() {
805
966
  return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new BooleanConstantOperation(true));
806
967
  }
968
+ /** Filter to rows where this attribute is false. */
807
969
  isFalse() {
808
970
  return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new BooleanConstantOperation(false));
809
971
  }
@@ -815,173 +977,227 @@ function parseDate(value) {
815
977
  return d;
816
978
  }
817
979
  var DateAttribute = class extends Attribute {
818
- constructor(displayName, columnName, columnDbType, owner, parent) {
819
- super(displayName, columnName, columnDbType, owner, parent);
980
+ constructor(displayName, columnName, columnDbType, owner, parent, embedded) {
981
+ super(displayName, columnName, columnDbType, owner, parent, embedded);
820
982
  }
983
+ /** Filter to rows where this date equals `value`. */
821
984
  eq(value) {
822
985
  return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new DateConstantOperation(parseDate(value)));
823
986
  }
987
+ /** Filter to rows where this date does not equal `value`. */
824
988
  ne(value) {
825
989
  return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new DateConstantOperation(parseDate(value)));
826
990
  }
991
+ /** Filter to rows where this date is after `value`. */
827
992
  gt(value) {
828
993
  return new ComparisonOperation(this.cwj(), "GREATER_THAN" /* GREATER_THAN */, new DateConstantOperation(parseDate(value)));
829
994
  }
995
+ /** Filter to rows where this date is before `value`. */
830
996
  lt(value) {
831
997
  return new ComparisonOperation(this.cwj(), "LESS_THAN" /* LESS_THAN */, new DateConstantOperation(parseDate(value)));
832
998
  }
999
+ /** Filter to rows where this date is on or after `value`. */
833
1000
  gte(value) {
834
1001
  return new ComparisonOperation(this.cwj(), "GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, new DateConstantOperation(parseDate(value)));
835
1002
  }
1003
+ /** Filter to rows where this date is on or before `value`. */
836
1004
  lte(value) {
837
1005
  return new ComparisonOperation(this.cwj(), "LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, new DateConstantOperation(parseDate(value)));
838
1006
  }
1007
+ /** Extract the four-digit calendar year. */
839
1008
  year() {
840
1009
  return new DateExtractOperation(this.cwj(), "YEAR" /* YEAR */, "Year " + this.displayName());
841
1010
  }
1011
+ /** Extract the month number (1–12). */
842
1012
  month() {
843
1013
  return new DateExtractOperation(this.cwj(), "MONTH" /* MONTH */, "Month " + this.displayName());
844
1014
  }
1015
+ /** Extract the day of the month (1–31). */
845
1016
  day() {
846
1017
  return new DateExtractOperation(this.cwj(), "DAY" /* DAY */, "Day " + this.displayName());
847
1018
  }
1019
+ /** Extract the quarter (1–4). */
848
1020
  quarter() {
849
1021
  return new DateExtractOperation(this.cwj(), "QUARTER" /* QUARTER */, "Quarter " + this.displayName());
850
1022
  }
1023
+ /** Extract the ISO week number (1–53). */
851
1024
  week() {
852
1025
  return new DateExtractOperation(this.cwj(), "WEEK" /* WEEK */, "Week " + this.displayName());
853
1026
  }
1027
+ /** Extract the day of the week (0 = Sunday through 6 = Saturday). */
854
1028
  dayOfWeek() {
855
1029
  return new DateExtractOperation(this.cwj(), "DOW" /* DOW */, "Day Of Week " + this.displayName());
856
1030
  }
1031
+ /** Add `n` days to this date. */
857
1032
  addDays(n) {
858
1033
  return new DateArithmeticOperation(this.cwj(), n, "DAY" /* DAY */, true, "Add Days " + this.displayName());
859
1034
  }
1035
+ /** Add `n` months to this date. */
860
1036
  addMonths(n) {
861
1037
  return new DateArithmeticOperation(this.cwj(), n, "MONTH" /* MONTH */, true, "Add Months " + this.displayName());
862
1038
  }
1039
+ /** Add `n` years to this date. */
863
1040
  addYears(n) {
864
1041
  return new DateArithmeticOperation(this.cwj(), n, "YEAR" /* YEAR */, true, "Add Years " + this.displayName());
865
1042
  }
1043
+ /** Subtract `n` days from this date. */
866
1044
  subtractDays(n) {
867
1045
  return new DateArithmeticOperation(this.cwj(), n, "DAY" /* DAY */, false, "Subtract Days " + this.displayName());
868
1046
  }
1047
+ /** Subtract `n` months from this date. */
869
1048
  subtractMonths(n) {
870
1049
  return new DateArithmeticOperation(this.cwj(), n, "MONTH" /* MONTH */, false, "Subtract Months " + this.displayName());
871
1050
  }
1051
+ /** Subtract `n` years from this date. */
872
1052
  subtractYears(n) {
873
1053
  return new DateArithmeticOperation(this.cwj(), n, "YEAR" /* YEAR */, false, "Subtract Years " + this.displayName());
874
1054
  }
1055
+ /** Number of whole days between this date and `other`. */
875
1056
  diffDays(other) {
876
1057
  return new DateDiffOperation(this.cwj(), other, "DAY" /* DAY */, "Diff Days " + this.displayName());
877
1058
  }
1059
+ /** Number of whole months between this date and `other`. */
878
1060
  diffMonths(other) {
879
1061
  return new DateDiffOperation(this.cwj(), other, "MONTH" /* MONTH */, "Diff Months " + this.displayName());
880
1062
  }
1063
+ /** Number of whole years between this date and `other`. */
881
1064
  diffYears(other) {
882
1065
  return new DateDiffOperation(this.cwj(), other, "YEAR" /* YEAR */, "Diff Years " + this.displayName());
883
1066
  }
884
1067
  };
885
1068
  var DateTimeAttribute = class extends Attribute {
886
- constructor(displayName, columnName, columnDbType, owner, parent) {
887
- super(displayName, columnName, columnDbType, owner, parent);
1069
+ constructor(displayName, columnName, columnDbType, owner, parent, embedded) {
1070
+ super(displayName, columnName, columnDbType, owner, parent, embedded);
888
1071
  }
1072
+ /** Filter to rows where this timestamp equals `value`. */
889
1073
  eq(value) {
890
1074
  return new ComparisonOperation(this.cwj(), "EQUAL" /* EQUAL */, new DateTimeConstantOperation(parseDate(value)));
891
1075
  }
1076
+ /** Filter to rows where this timestamp does not equal `value`. */
892
1077
  ne(value) {
893
1078
  return new ComparisonOperation(this.cwj(), "NOT_EQUAL" /* NOT_EQUAL */, new DateTimeConstantOperation(parseDate(value)));
894
1079
  }
1080
+ /** Filter to rows where this timestamp is after `value`. */
895
1081
  gt(value) {
896
1082
  return new ComparisonOperation(this.cwj(), "GREATER_THAN" /* GREATER_THAN */, new DateTimeConstantOperation(parseDate(value)));
897
1083
  }
1084
+ /** Filter to rows where this timestamp is before `value`. */
898
1085
  lt(value) {
899
1086
  return new ComparisonOperation(this.cwj(), "LESS_THAN" /* LESS_THAN */, new DateTimeConstantOperation(parseDate(value)));
900
1087
  }
1088
+ /** Filter to rows where this timestamp is on or after `value`. */
901
1089
  gte(value) {
902
1090
  return new ComparisonOperation(this.cwj(), "GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, new DateTimeConstantOperation(parseDate(value)));
903
1091
  }
1092
+ /** Filter to rows where this timestamp is on or before `value`. */
904
1093
  lte(value) {
905
1094
  return new ComparisonOperation(this.cwj(), "LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, new DateTimeConstantOperation(parseDate(value)));
906
1095
  }
1096
+ /** Extract the four-digit calendar year. */
907
1097
  year() {
908
1098
  return new DateExtractOperation(this.cwj(), "YEAR" /* YEAR */, "Year " + this.displayName());
909
1099
  }
1100
+ /** Extract the month number (1–12). */
910
1101
  month() {
911
1102
  return new DateExtractOperation(this.cwj(), "MONTH" /* MONTH */, "Month " + this.displayName());
912
1103
  }
1104
+ /** Extract the day of the month (1–31). */
913
1105
  day() {
914
1106
  return new DateExtractOperation(this.cwj(), "DAY" /* DAY */, "Day " + this.displayName());
915
1107
  }
1108
+ /** Extract the hour (0–23). */
916
1109
  hour() {
917
1110
  return new DateExtractOperation(this.cwj(), "HOUR" /* HOUR */, "Hour " + this.displayName());
918
1111
  }
1112
+ /** Extract the minute (0–59). */
919
1113
  minute() {
920
1114
  return new DateExtractOperation(this.cwj(), "MINUTE" /* MINUTE */, "Minute " + this.displayName());
921
1115
  }
1116
+ /** Extract the second (0–59). */
922
1117
  second() {
923
1118
  return new DateExtractOperation(this.cwj(), "SECOND" /* SECOND */, "Second " + this.displayName());
924
1119
  }
1120
+ /** Extract the quarter (1–4). */
925
1121
  quarter() {
926
1122
  return new DateExtractOperation(this.cwj(), "QUARTER" /* QUARTER */, "Quarter " + this.displayName());
927
1123
  }
1124
+ /** Extract the ISO week number (1–53). */
928
1125
  week() {
929
1126
  return new DateExtractOperation(this.cwj(), "WEEK" /* WEEK */, "Week " + this.displayName());
930
1127
  }
1128
+ /** Extract the day of the week (0 = Sunday through 6 = Saturday). */
931
1129
  dayOfWeek() {
932
1130
  return new DateExtractOperation(this.cwj(), "DOW" /* DOW */, "Day Of Week " + this.displayName());
933
1131
  }
1132
+ /** Add `n` days to this timestamp. */
934
1133
  addDays(n) {
935
1134
  return new DateArithmeticOperation(this.cwj(), n, "DAY" /* DAY */, true, "Add Days " + this.displayName());
936
1135
  }
1136
+ /** Add `n` months to this timestamp. */
937
1137
  addMonths(n) {
938
1138
  return new DateArithmeticOperation(this.cwj(), n, "MONTH" /* MONTH */, true, "Add Months " + this.displayName());
939
1139
  }
1140
+ /** Add `n` years to this timestamp. */
940
1141
  addYears(n) {
941
1142
  return new DateArithmeticOperation(this.cwj(), n, "YEAR" /* YEAR */, true, "Add Years " + this.displayName());
942
1143
  }
1144
+ /** Add `n` hours to this timestamp. */
943
1145
  addHours(n) {
944
1146
  return new DateArithmeticOperation(this.cwj(), n, "HOUR" /* HOUR */, true, "Add Hours " + this.displayName());
945
1147
  }
1148
+ /** Add `n` minutes to this timestamp. */
946
1149
  addMinutes(n) {
947
1150
  return new DateArithmeticOperation(this.cwj(), n, "MINUTE" /* MINUTE */, true, "Add Minutes " + this.displayName());
948
1151
  }
1152
+ /** Add `n` seconds to this timestamp. */
949
1153
  addSeconds(n) {
950
1154
  return new DateArithmeticOperation(this.cwj(), n, "SECOND" /* SECOND */, true, "Add Seconds " + this.displayName());
951
1155
  }
1156
+ /** Subtract `n` days from this timestamp. */
952
1157
  subtractDays(n) {
953
1158
  return new DateArithmeticOperation(this.cwj(), n, "DAY" /* DAY */, false, "Subtract Days " + this.displayName());
954
1159
  }
1160
+ /** Subtract `n` months from this timestamp. */
955
1161
  subtractMonths(n) {
956
1162
  return new DateArithmeticOperation(this.cwj(), n, "MONTH" /* MONTH */, false, "Subtract Months " + this.displayName());
957
1163
  }
1164
+ /** Subtract `n` years from this timestamp. */
958
1165
  subtractYears(n) {
959
1166
  return new DateArithmeticOperation(this.cwj(), n, "YEAR" /* YEAR */, false, "Subtract Years " + this.displayName());
960
1167
  }
1168
+ /** Subtract `n` hours from this timestamp. */
961
1169
  subtractHours(n) {
962
1170
  return new DateArithmeticOperation(this.cwj(), n, "HOUR" /* HOUR */, false, "Subtract Hours " + this.displayName());
963
1171
  }
1172
+ /** Subtract `n` minutes from this timestamp. */
964
1173
  subtractMinutes(n) {
965
1174
  return new DateArithmeticOperation(this.cwj(), n, "MINUTE" /* MINUTE */, false, "Subtract Minutes " + this.displayName());
966
1175
  }
1176
+ /** Subtract `n` seconds from this timestamp. */
967
1177
  subtractSeconds(n) {
968
1178
  return new DateArithmeticOperation(this.cwj(), n, "SECOND" /* SECOND */, false, "Subtract Seconds " + this.displayName());
969
1179
  }
1180
+ /** Number of whole days between this timestamp and `other`. */
970
1181
  diffDays(other) {
971
1182
  return new DateDiffOperation(this.cwj(), other, "DAY" /* DAY */, "Diff Days " + this.displayName());
972
1183
  }
1184
+ /** Number of whole months between this timestamp and `other`. */
973
1185
  diffMonths(other) {
974
1186
  return new DateDiffOperation(this.cwj(), other, "MONTH" /* MONTH */, "Diff Months " + this.displayName());
975
1187
  }
1188
+ /** Number of whole years between this timestamp and `other`. */
976
1189
  diffYears(other) {
977
1190
  return new DateDiffOperation(this.cwj(), other, "YEAR" /* YEAR */, "Diff Years " + this.displayName());
978
1191
  }
1192
+ /** Number of whole hours between this timestamp and `other`. */
979
1193
  diffHours(other) {
980
1194
  return new DateDiffOperation(this.cwj(), other, "HOUR" /* HOUR */, "Diff Hours " + this.displayName());
981
1195
  }
1196
+ /** Number of whole minutes between this timestamp and `other`. */
982
1197
  diffMinutes(other) {
983
1198
  return new DateDiffOperation(this.cwj(), other, "MINUTE" /* MINUTE */, "Diff Minutes " + this.displayName());
984
1199
  }
1200
+ /** Number of whole seconds between this timestamp and `other`. */
985
1201
  diffSeconds(other) {
986
1202
  return new DateDiffOperation(this.cwj(), other, "SECOND" /* SECOND */, "Diff Seconds " + this.displayName());
987
1203
  }
@@ -1064,49 +1280,7 @@ var MilestonedTable = class extends Table {
1064
1280
  milestoningColumns;
1065
1281
  };
1066
1282
 
1067
- // src/datafinder/finder.ts
1068
- var ExistsOperation = class extends RelationalOperationElement {
1069
- constructor(node) {
1070
- super();
1071
- this.node = node;
1072
- }
1073
- node;
1074
- andOp(other) {
1075
- return new LogicalOperation(this, "AND" /* AND */, other);
1076
- }
1077
- };
1078
- var NotExistsOperation = class extends RelationalOperationElement {
1079
- constructor(node) {
1080
- super();
1081
- this.node = node;
1082
- }
1083
- node;
1084
- andOp(other) {
1085
- return new LogicalOperation(this, "AND" /* AND */, other);
1086
- }
1087
- };
1088
- var RelatedFinder = class {
1089
- constructor(_node) {
1090
- this._node = _node;
1091
- }
1092
- _node;
1093
- exists() {
1094
- return new ExistsOperation(this._node);
1095
- }
1096
- notExists() {
1097
- return new NotExistsOperation(this._node);
1098
- }
1099
- };
1100
-
1101
1283
  // src/datafinder/sql-generator.ts
1102
- var Alias = class {
1103
- constructor(element, name) {
1104
- this.element = element;
1105
- this.name = name;
1106
- }
1107
- element;
1108
- name;
1109
- };
1110
1284
  var TableAlias = class {
1111
1285
  constructor(table, alias) {
1112
1286
  this.table = table;
@@ -1134,22 +1308,6 @@ var Join = class {
1134
1308
  target;
1135
1309
  filterOp;
1136
1310
  };
1137
- var SelectOperation = class {
1138
- constructor(display, filter, orderBy = [], groupBy = [], limit, table) {
1139
- this.display = display;
1140
- this.filter = filter;
1141
- this.orderBy = orderBy;
1142
- this.groupBy = groupBy;
1143
- this.limit = limit;
1144
- this.table = table;
1145
- }
1146
- display;
1147
- filter;
1148
- orderBy;
1149
- groupBy;
1150
- limit;
1151
- table;
1152
- };
1153
1311
  function sqlFormatDatetime(value) {
1154
1312
  const pad = (n, w = 2) => String(n).padStart(w, "0");
1155
1313
  return `'${value.getUTCFullYear()}-${pad(value.getUTCMonth() + 1)}-${pad(value.getUTCDate())} ${pad(value.getUTCHours())}:${pad(value.getUTCMinutes())}:${pad(value.getUTCSeconds())}'`;
@@ -1281,6 +1439,9 @@ function sqlOperationToString(operation) {
1281
1439
  }
1282
1440
  throw new TypeError("Unknown operation in sqlOperationToString: " + operation.constructor.name);
1283
1441
  }
1442
+ function embeddedOf(ref) {
1443
+ return ref instanceof Attribute ? ref.embedded() : ref.embedded;
1444
+ }
1284
1445
  function findColumn(operation) {
1285
1446
  if (operation instanceof UnaryOperation) return findColumn(operation.element);
1286
1447
  if (operation instanceof ColumnWithJoin) return operation;
@@ -1330,38 +1491,125 @@ function buildMilestoningFilterOperation(businessDate, processingDatetime, table
1330
1491
  if (ops.length === 1) return ops[0];
1331
1492
  return new LogicalOperation(ops[0], "AND" /* AND */, ops[1]);
1332
1493
  }
1333
- function buildQueryOperation(businessDate, processingDatetime, columns, table, op, orderBy = [], groupBy = [], limit) {
1494
+ function buildMilestoningFilterOperationForDateRange(businessDateFrom, businessDateTo, processingDatetime, table, joinNode) {
1495
+ const mc = table.milestoningColumns;
1496
+ const ops = [];
1497
+ const hasRange = businessDateFrom !== null && businessDateTo !== null;
1498
+ const processingOp = (m) => {
1499
+ const startAt = new DateTimeAttribute("start_at", m.startAtColumn.name, m.startAtColumn.type, m.startAtColumn.table.qualifiedName, joinNode);
1500
+ const endAt = new DateTimeAttribute("end_at", m.endAtColumn.name, m.endAtColumn.type, m.endAtColumn.table.qualifiedName, joinNode);
1501
+ return new LogicalOperation(startAt.lte(processingDatetime), "AND" /* AND */, openEndClause(endAt, processingDatetime, m.infiniteDatetime));
1502
+ };
1503
+ if (mc instanceof BiTemporalColumns) {
1504
+ if (hasRange) {
1505
+ const dateFrom = new DateAttribute("business_date_from", mc.businessDateFromColumn.name, mc.businessDateFromColumn.type, mc.businessDateFromColumn.table.qualifiedName, joinNode);
1506
+ const dateTo = new DateAttribute("business_date_to", mc.businessDateToColumn.name, mc.businessDateToColumn.type, mc.businessDateToColumn.table.qualifiedName, joinNode);
1507
+ ops.push(new LogicalOperation(dateFrom.lte(businessDateTo), "AND" /* AND */, openEndClause(dateTo, businessDateFrom, mc.infiniteDatetime)));
1508
+ }
1509
+ if (processingDatetime !== null) ops.push(processingOp(mc));
1510
+ } else if (mc instanceof BusinessDateAndProcessingTemporalColumns) {
1511
+ if (hasRange) {
1512
+ const businessAtt = new DateAttribute("business_date", mc.businessDateColumn.name, mc.businessDateColumn.type, mc.businessDateColumn.table.qualifiedName, joinNode);
1513
+ ops.push(new LogicalOperation(businessAtt.gte(businessDateFrom), "AND" /* AND */, businessAtt.lte(businessDateTo)));
1514
+ }
1515
+ if (processingDatetime !== null) ops.push(processingOp(mc));
1516
+ } else if (mc instanceof ProcessingTemporalColumns) {
1517
+ if (processingDatetime !== null) ops.push(processingOp(mc));
1518
+ } else if (mc instanceof SingleBusinessDateColumn && hasRange) {
1519
+ const businessAtt = new DateAttribute("business_date", mc.businessDateColumn.name, mc.businessDateColumn.type, mc.businessDateColumn.table.qualifiedName, joinNode);
1520
+ ops.push(new LogicalOperation(businessAtt.gte(businessDateFrom), "AND" /* AND */, businessAtt.lte(businessDateTo)));
1521
+ }
1522
+ if (ops.length === 0) return null;
1523
+ if (ops.length === 1) return ops[0];
1524
+ return new LogicalOperation(ops[0], "AND" /* AND */, ops[1]);
1525
+ }
1526
+ function walkRefs(op, visit, visitExists) {
1527
+ if (op === null || op === void 0) return;
1528
+ if (op instanceof Attribute || op instanceof ColumnWithJoin) {
1529
+ visit(op);
1530
+ } else if (op instanceof ExistsOperation || op instanceof NotExistsOperation) {
1531
+ visitExists?.(op.node);
1532
+ } else if (op instanceof AggregateOperation) {
1533
+ walkRefs(op.element, visit, visitExists);
1534
+ if (op.window) walkWindowSpec(op.window, visit, visitExists);
1535
+ } else if (op instanceof WindowFunctionOperation) {
1536
+ if (op.element) walkRefs(op.element, visit, visitExists);
1537
+ if (op.window) walkWindowSpec(op.window, visit, visitExists);
1538
+ } else if (op instanceof ScalarFunctionOperation || op instanceof DateExtractOperation || op instanceof DateArithmeticOperation || op instanceof DateDiffOperation || op instanceof IsNullOperation || op instanceof IsNotNullOperation) {
1539
+ walkRefs(op.element, visit, visitExists);
1540
+ } else if (op instanceof SortOperation) {
1541
+ walkRefs(op.column, visit, visitExists);
1542
+ } else if (op instanceof LogicalOperation || op instanceof ComparisonOperation) {
1543
+ walkRefs(op.left, visit, visitExists);
1544
+ walkRefs(op.right, visit, visitExists);
1545
+ }
1546
+ }
1547
+ function walkWindowSpec(window, visit, visitExists) {
1548
+ for (const p of window.partitionBy) walkRefs(p, visit, visitExists);
1549
+ for (const s of window.orderBy) walkRefs(s.column, visit, visitExists);
1550
+ }
1551
+ function buildJoinFilterFromProperties(node, filter, columnMap) {
1552
+ const ops = [];
1553
+ for (const [key, value] of Object.entries(filter)) {
1554
+ const entry = columnMap[key];
1555
+ if (entry === void 0) {
1556
+ throw new Error(`Unknown property '${key}' \u2014 valid properties are: ${Object.keys(columnMap).sort().join(", ")}`);
1557
+ }
1558
+ const [name, type, table] = entry;
1559
+ const col = new ColumnWithJoin(new Column(name, type, table), node);
1560
+ let constant;
1561
+ if (typeof value === "boolean") constant = new BooleanConstantOperation(value);
1562
+ else if (typeof value === "number") constant = Number.isInteger(value) ? new IntegerConstantOperation(value) : new FloatConstantOperation(value);
1563
+ else if (value instanceof Date) constant = type.toUpperCase() === "DATE" ? new DateConstantOperation(value) : new DateTimeConstantOperation(value);
1564
+ else constant = new StringConstantOperation(String(value));
1565
+ ops.push(new ComparisonOperation(col, "EQUAL" /* EQUAL */, constant));
1566
+ }
1567
+ return ops.reduce((acc, op) => new LogicalOperation(acc, "AND" /* AND */, op));
1568
+ }
1569
+ function withAncestors(nodes) {
1570
+ const ordered = /* @__PURE__ */ new Set();
1571
+ const add = (node) => {
1572
+ if (ordered.has(node)) return;
1573
+ if (node.parent !== void 0) add(node.parent);
1574
+ ordered.add(node);
1575
+ };
1576
+ for (const node of nodes) add(node);
1577
+ return [...ordered];
1578
+ }
1579
+ function buildQueryOperation(businessDate, processingDatetime, columns, table, op, orderBy = [], groupBy = [], limit, businessDateTo = null) {
1334
1580
  let filter = op;
1581
+ const milestoningFor = (t, node) => businessDateTo !== null ? buildMilestoningFilterOperationForDateRange(businessDate, businessDateTo, processingDatetime, t, node) : buildMilestoningFilterOperation(businessDate, processingDatetime, t, node);
1335
1582
  if (table instanceof MilestonedTable) {
1336
- const milestonedOp = buildMilestoningFilterOperation(businessDate, processingDatetime, table);
1583
+ const milestonedOp = milestoningFor(table);
1337
1584
  if (milestonedOp !== null) {
1338
1585
  filter = filter instanceof NoOperation ? milestonedOp : new LogicalOperation(filter, "AND" /* AND */, milestonedOp);
1339
1586
  }
1340
1587
  }
1341
- const requiredJoins = [];
1342
- const requiredJoinIds = /* @__PURE__ */ new Set();
1343
- for (const col of columns) {
1344
- if (col instanceof CountAllOperation) continue;
1345
- let node;
1346
- if (col instanceof Attribute) {
1347
- node = col.parent();
1348
- } else {
1349
- node = findColumn(col).parent;
1588
+ const requiredJoins = /* @__PURE__ */ new Set();
1589
+ const collect = (ref) => {
1590
+ const parent = ref instanceof Attribute ? ref.parent() : ref.parent;
1591
+ if (parent !== void 0) requiredJoins.add(parent);
1592
+ };
1593
+ const collectNode = (node) => requiredJoins.add(node);
1594
+ for (const col of columns) walkRefs(col, collect, collectNode);
1595
+ for (const expr of groupBy) walkRefs(expr, collect, collectNode);
1596
+ for (const sort of orderBy) walkRefs(sort, collect, collectNode);
1597
+ walkRefs(op, collect, collectNode);
1598
+ const joinFilters = /* @__PURE__ */ new Map();
1599
+ for (const node of withAncestors(requiredJoins)) {
1600
+ let combined;
1601
+ if (Object.keys(node.join.filterKwargs).length > 0) {
1602
+ combined = buildJoinFilterFromProperties(node, node.join.filterKwargs, node.join.filterColumnMap);
1350
1603
  }
1351
- if (node !== void 0 && !requiredJoinIds.has(node)) {
1352
- requiredJoinIds.add(node);
1353
- requiredJoins.push(node);
1354
- }
1355
- }
1356
- for (const node of requiredJoins) {
1357
1604
  if (node.join.target instanceof MilestonedTable) {
1358
- const milestonedOp = buildMilestoningFilterOperation(businessDate, processingDatetime, node.join.target, node);
1605
+ const milestonedOp = milestoningFor(node.join.target, node);
1359
1606
  if (milestonedOp !== null) {
1360
- node.join.filter = milestonedOp;
1607
+ combined = combined === void 0 ? milestonedOp : new LogicalOperation(combined, "AND" /* AND */, milestonedOp);
1361
1608
  }
1362
1609
  }
1610
+ if (combined !== void 0) joinFilters.set(node, combined);
1363
1611
  }
1364
- return new SelectOperation(columns, filter, orderBy, groupBy, limit, table);
1612
+ return new SelectOperation(columns, filter, orderBy, groupBy, limit, table, joinFilters);
1365
1613
  }
1366
1614
  var SQLQueryGenerator = class {
1367
1615
  _select = [];
@@ -1375,8 +1623,12 @@ var SQLQueryGenerator = class {
1375
1623
  _tableAliasesByTable = /* @__PURE__ */ new Map();
1376
1624
  _addedJoinIds = /* @__PURE__ */ new Set();
1377
1625
  _rootTable;
1626
+ _elidableNodes = /* @__PURE__ */ new Set();
1627
+ _joinFilters = /* @__PURE__ */ new Map();
1378
1628
  generate(select) {
1379
1629
  this._rootTable = select.table;
1630
+ this._elidableNodes = this._computeElidableNodes(select);
1631
+ this._joinFilters = select.joinFilters;
1380
1632
  if (this._rootTable !== void 0) {
1381
1633
  this._from.add(this._tableAliasForTable(this._rootTable.qualifiedName, this._rootTable.qualifiedName));
1382
1634
  }
@@ -1396,39 +1648,49 @@ var SQLQueryGenerator = class {
1396
1648
  this._limit = select.limit;
1397
1649
  }
1398
1650
  _attrToColString(attr) {
1399
- const node = attr.parent();
1400
- const ta = this._tableAliasForTable(attr.owner(), node ?? attr.owner());
1401
- return ta.alias + "." + attr.column().name;
1651
+ const { column, parent } = this._resolve(attr);
1652
+ const ta = this._tableAliasForTable(column.owner, parent ?? column.owner);
1653
+ return ta.alias + "." + column.name;
1402
1654
  }
1403
1655
  _collectRequiredJoins(op, out) {
1404
- if (op === null || op === void 0) return;
1405
- if (op instanceof Attribute) {
1406
- const p = op.parent();
1407
- if (p !== void 0) out.set(p, p);
1408
- } else if (op instanceof ColumnWithJoin) {
1409
- if (op.parent !== void 0) out.set(op.parent, op.parent);
1410
- } else if (op instanceof AggregateOperation) {
1411
- this._collectRequiredJoins(op.element, out);
1412
- if (op.window) this._collectRequiredJoins(op.window, out);
1413
- } else if (op instanceof WindowFunctionOperation) {
1414
- if (op.element) this._collectRequiredJoins(op.element, out);
1415
- if (op.window) this._collectRequiredJoinsFromWindowSpec(op.window, out);
1416
- } else if (op instanceof ScalarFunctionOperation || op instanceof DateExtractOperation || op instanceof DateArithmeticOperation || op instanceof DateDiffOperation) {
1417
- this._collectRequiredJoins(op.element, out);
1418
- } else if (op instanceof SortOperation) {
1419
- this._collectRequiredJoins(op.column, out);
1420
- } else if (op instanceof LogicalOperation || op instanceof ComparisonOperation) {
1421
- this._collectRequiredJoins(op.left, out);
1422
- this._collectRequiredJoins(op.right, out);
1656
+ walkRefs(op, (ref) => {
1657
+ const { parent } = this._resolve(ref);
1658
+ if (parent !== void 0) out.set(parent, parent);
1659
+ });
1660
+ }
1661
+ /**
1662
+ * Determine upfront which join nodes can be satisfied entirely by embedded (join-less) alternates:
1663
+ * a node is elidable when every reference to it has an embedded alternate. A reference without one
1664
+ * (e.g. a milestoning column) keeps the join for every reference to that node.
1665
+ */
1666
+ _computeElidableNodes(select) {
1667
+ const refsByNode = /* @__PURE__ */ new Map();
1668
+ const record = (ref) => {
1669
+ const parent = ref instanceof Attribute ? ref.parent() : ref.parent;
1670
+ if (parent === void 0) return;
1671
+ const refs = refsByNode.get(parent);
1672
+ if (refs) refs.push(ref);
1673
+ else refsByNode.set(parent, [ref]);
1674
+ };
1675
+ for (const col of select.display) walkRefs(col, record);
1676
+ for (const expr of select.groupBy) walkRefs(expr, record);
1677
+ for (const sort of select.orderBy) walkRefs(sort, record);
1678
+ walkRefs(select.filter, record);
1679
+ const elidable = /* @__PURE__ */ new Set();
1680
+ for (const [node, refs] of refsByNode) {
1681
+ if (refs.every((ref) => embeddedOf(ref) !== void 0)) elidable.add(node);
1423
1682
  }
1424
- }
1425
- _collectRequiredJoinsFromWindowSpec(window, out) {
1426
- for (const p of window.partitionBy) {
1427
- this._collectRequiredJoins(p, out);
1428
- }
1429
- for (const s of window.orderBy) {
1430
- this._collectRequiredJoins(s.column, out);
1683
+ return elidable;
1684
+ }
1685
+ /** The (column, parent) a reference should resolve to, substituting its embedded alternate when its join is elided. */
1686
+ _resolve(ref) {
1687
+ const column = ref instanceof Attribute ? ref.column() : ref.column;
1688
+ const parent = ref instanceof Attribute ? ref.parent() : ref.parent;
1689
+ if (parent !== void 0 && this._elidableNodes.has(parent)) {
1690
+ const embedded = embeddedOf(ref);
1691
+ if (embedded !== void 0) return this._resolve(embedded);
1431
1692
  }
1693
+ return { column, parent };
1432
1694
  }
1433
1695
  _rewriteWindowSpec(window) {
1434
1696
  const partitionBy = window.partitionBy.map((p) => this._rewriteOperation(p));
@@ -1436,13 +1698,9 @@ var SQLQueryGenerator = class {
1436
1698
  return new WindowSpecification(partitionBy, orderBy);
1437
1699
  }
1438
1700
  _rewriteOperation(op) {
1439
- if (op instanceof Attribute) {
1440
- const ta = this._tableAliasForTable(op.owner(), op.parent() ?? op.owner());
1441
- return new TableAliasColumn(op.column(), ta);
1442
- }
1443
- if (op instanceof ColumnWithJoin) {
1444
- const ta = op.parent !== void 0 ? this._tableAliasForTable(op.column.owner, op.parent) : this._tableAliasForTable(op.column.owner, op.column.owner);
1445
- return new TableAliasColumn(op.column, ta);
1701
+ if (op instanceof Attribute || op instanceof ColumnWithJoin) {
1702
+ const { column, parent } = this._resolve(op);
1703
+ return new TableAliasColumn(column, this._tableAliasForTable(column.owner, parent ?? column.owner));
1446
1704
  }
1447
1705
  if (op instanceof Column) {
1448
1706
  const ta = this._tableAliasForTable(op.owner, op.owner);
@@ -1491,15 +1749,15 @@ var SQLQueryGenerator = class {
1491
1749
  }
1492
1750
  for (const col of cols) {
1493
1751
  if (col instanceof Attribute) {
1494
- const node = col.parent();
1752
+ const { column, parent: node } = this._resolve(col);
1495
1753
  let ta;
1496
1754
  if (node !== void 0) {
1497
- ta = this._tableAliasForTable(col.owner(), node);
1755
+ ta = this._tableAliasForTable(column.owner, node);
1498
1756
  } else {
1499
- ta = this._tableAliasForTable(col.owner(), col.owner());
1757
+ ta = this._tableAliasForTable(column.owner, column.owner);
1500
1758
  this._from.add(ta);
1501
1759
  }
1502
- this._select.push(new Alias(new TableAliasColumn(col.column(), ta), col.displayName()));
1760
+ this._select.push(new Alias(new TableAliasColumn(column, ta), col.displayName()));
1503
1761
  } else if (col instanceof WindowFunctionOperation) {
1504
1762
  const rewritten = this._rewriteOperation(col);
1505
1763
  let alias;
@@ -1514,7 +1772,7 @@ var SQLQueryGenerator = class {
1514
1772
  }
1515
1773
  this._select.push(new Alias(rewritten, alias));
1516
1774
  } else if (col instanceof AggregateOperation) {
1517
- const colNested = findColumn(col);
1775
+ const colNested = this._resolve(findColumn(col));
1518
1776
  const node = colNested.parent;
1519
1777
  let ta;
1520
1778
  if (node !== void 0) {
@@ -1523,7 +1781,7 @@ var SQLQueryGenerator = class {
1523
1781
  ta = this._tableAliasForTable(colNested.column.owner, colNested.column.owner);
1524
1782
  this._from.add(ta);
1525
1783
  }
1526
- const alias = col.displayName ?? col.operator + " " + colNested.column.name;
1784
+ const alias = col.displayName ?? col.operator + " " + findColumn(col).column.name;
1527
1785
  const rewrittenAgg = new AggregateOperation(
1528
1786
  new TableAliasColumn(colNested.column, ta),
1529
1787
  col.operator,
@@ -1532,7 +1790,7 @@ var SQLQueryGenerator = class {
1532
1790
  );
1533
1791
  this._select.push(new Alias(rewrittenAgg, alias));
1534
1792
  } else if (col instanceof ScalarFunctionOperation) {
1535
- const colNested = findColumn(col);
1793
+ const colNested = this._resolve(findColumn(col));
1536
1794
  const node = colNested.parent;
1537
1795
  let ta;
1538
1796
  if (node !== void 0) {
@@ -1541,13 +1799,13 @@ var SQLQueryGenerator = class {
1541
1799
  ta = this._tableAliasForTable(colNested.column.owner, colNested.column.owner);
1542
1800
  this._from.add(ta);
1543
1801
  }
1544
- const alias = col.displayName ?? col.func + " " + colNested.column.name;
1802
+ const alias = col.displayName ?? col.func + " " + findColumn(col).column.name;
1545
1803
  this._select.push(new Alias(
1546
1804
  new ScalarFunctionOperation(new TableAliasColumn(colNested.column, ta), col.func, void 0, col.secondArg, col.extraArgs),
1547
1805
  alias
1548
1806
  ));
1549
1807
  } else if (col instanceof DateExtractOperation || col instanceof DateArithmeticOperation || col instanceof DateDiffOperation) {
1550
- const colNested = findColumn(col);
1808
+ const colNested = this._resolve(findColumn(col));
1551
1809
  const node = colNested.parent;
1552
1810
  let ta;
1553
1811
  if (node !== void 0) {
@@ -1556,7 +1814,7 @@ var SQLQueryGenerator = class {
1556
1814
  ta = this._tableAliasForTable(colNested.column.owner, colNested.column.owner);
1557
1815
  this._from.add(ta);
1558
1816
  }
1559
- const alias = col.displayName ?? colNested.column.name;
1817
+ const alias = col.displayName ?? findColumn(col).column.name;
1560
1818
  let aliasedOp;
1561
1819
  if (col instanceof DateExtractOperation) {
1562
1820
  aliasedOp = new DateExtractOperation(new TableAliasColumn(colNested.column, ta), col.part);
@@ -1584,7 +1842,9 @@ var SQLQueryGenerator = class {
1584
1842
  const sc = new TableAliasColumn(left, srcTa);
1585
1843
  const right = join.right;
1586
1844
  const tc = new TableAliasColumn(right, this._tableAliasForTable(right.owner, node));
1587
- this._join.push(new Join(sc, tc, join.filter));
1845
+ const queryFilter = this._joinFilters.get(node);
1846
+ const filterOp = join.filter !== void 0 && queryFilter !== void 0 ? new LogicalOperation(join.filter, "AND" /* AND */, queryFilter) : join.filter ?? queryFilter;
1847
+ this._join.push(new Join(sc, tc, filterOp));
1588
1848
  }
1589
1849
  buildFilter(op) {
1590
1850
  if (op instanceof NoOperation) return "";
@@ -1610,15 +1870,15 @@ var SQLQueryGenerator = class {
1610
1870
  }
1611
1871
  if (op instanceof ConstantOperation) return constantValueString(op);
1612
1872
  if (op instanceof ColumnWithJoin) {
1613
- const node = op.parent;
1873
+ const { column, parent: node } = this._resolve(op);
1614
1874
  let ta;
1615
1875
  if (node !== void 0) {
1616
- ta = this._tableAliasForTable(op.column.owner, node);
1876
+ ta = this._tableAliasForTable(column.owner, node);
1617
1877
  this._addJoin(node);
1618
1878
  } else {
1619
- ta = this._tableAliasForTable(op.column.owner, op.column.owner);
1879
+ ta = this._tableAliasForTable(column.owner, column.owner);
1620
1880
  }
1621
- return ta.alias + "." + op.column.name;
1881
+ return ta.alias + "." + column.name;
1622
1882
  }
1623
1883
  if (op instanceof Column) {
1624
1884
  const ta = this._tableAliasForTable(op.owner, op.owner);
@@ -1658,12 +1918,50 @@ function selectSqlToString(selectOperation) {
1658
1918
  qg.generate(selectOperation);
1659
1919
  return qg.buildQueryString();
1660
1920
  }
1661
- function toSql(businessDate, processingDatetime, columns, table, op, orderBy = [], groupBy = [], limit) {
1662
- const selectOp = buildQueryOperation(businessDate, processingDatetime, columns, table, op, orderBy, groupBy, limit);
1921
+ function toSql(businessDate, processingDatetime, columns, table, op, orderBy = [], groupBy = [], limit, businessDateTo = null) {
1922
+ const selectOp = buildQueryOperation(businessDate, processingDatetime, columns, table, op, orderBy, groupBy, limit, businessDateTo);
1663
1923
  return selectSqlToString(selectOp);
1664
1924
  }
1665
1925
 
1926
+ // src/datafinder/naming.ts
1927
+ function titleCase(value) {
1928
+ return value.replace(/[A-Za-z]+/g, (w) => w[0].toUpperCase() + w.slice(1).toLowerCase());
1929
+ }
1930
+
1931
+ // src/datafinder/embedded.ts
1932
+ function embeddedUnder(embedded, prefix) {
1933
+ if (!embedded) return void 0;
1934
+ const result = {};
1935
+ for (const [key, attr] of Object.entries(embedded)) {
1936
+ if (key.startsWith(prefix)) result[key.slice(prefix.length)] = attr;
1937
+ }
1938
+ return Object.keys(result).length > 0 ? result : void 0;
1939
+ }
1940
+
1941
+ // src/datafinder/finder.ts
1942
+ var RelatedFinder = class {
1943
+ constructor(_node) {
1944
+ this._node = _node;
1945
+ }
1946
+ _node;
1947
+ exists() {
1948
+ return new ExistsOperation(this._node);
1949
+ }
1950
+ notExists() {
1951
+ return new NotExistsOperation(this._node);
1952
+ }
1953
+ };
1954
+
1666
1955
  // src/datafinder/runner.ts
1956
+ var DEFAULT_TIMEOUT_MS = 6e4;
1957
+ var QueryTimeoutError = class extends Error {
1958
+ constructor(timeoutMs) {
1959
+ super(`Query exceeded ${timeoutMs}ms timeout`);
1960
+ this.timeoutMs = timeoutMs;
1961
+ this.name = "QueryTimeoutError";
1962
+ }
1963
+ timeoutMs;
1964
+ };
1667
1965
  var _runner = null;
1668
1966
  function registerRunner(runner) {
1669
1967
  _runner = runner;
@@ -1676,21 +1974,24 @@ function getRunner() {
1676
1974
  return _runner;
1677
1975
  }
1678
1976
  var FinderResult = class {
1679
- constructor(_businessDate, _processingDatetime, _columns, _table, _op) {
1977
+ constructor(_businessDate, _processingDatetime, _columns, _table, _op, _businessDateTo = null) {
1680
1978
  this._businessDate = _businessDate;
1681
1979
  this._processingDatetime = _processingDatetime;
1682
1980
  this._columns = _columns;
1683
1981
  this._table = _table;
1684
1982
  this._op = _op;
1983
+ this._businessDateTo = _businessDateTo;
1685
1984
  }
1686
1985
  _businessDate;
1687
1986
  _processingDatetime;
1688
1987
  _columns;
1689
1988
  _table;
1690
1989
  _op;
1990
+ _businessDateTo;
1691
1991
  _orderBy = [];
1692
1992
  _groupBy = [];
1693
1993
  _limit;
1994
+ _timeoutMs = DEFAULT_TIMEOUT_MS;
1694
1995
  orderByOp(...sorts) {
1695
1996
  this._orderBy = sorts;
1696
1997
  return this;
@@ -1703,6 +2004,11 @@ var FinderResult = class {
1703
2004
  this._limit = n;
1704
2005
  return this;
1705
2006
  }
2007
+ /** Abort the query and throw QueryTimeoutError if it runs longer than `milliseconds` (default 60000). */
2008
+ timeout(milliseconds) {
2009
+ this._timeoutMs = milliseconds;
2010
+ return this;
2011
+ }
1706
2012
  toSql() {
1707
2013
  return toSql(
1708
2014
  this._businessDate,
@@ -1712,7 +2018,8 @@ var FinderResult = class {
1712
2018
  this._op,
1713
2019
  this._orderBy,
1714
2020
  this._groupBy,
1715
- this._limit
2021
+ this._limit,
2022
+ this._businessDateTo
1716
2023
  );
1717
2024
  }
1718
2025
  async toRows() {
@@ -1724,14 +2031,18 @@ var FinderResult = class {
1724
2031
  this._op,
1725
2032
  this._orderBy,
1726
2033
  this._groupBy,
1727
- this._limit
2034
+ this._limit,
2035
+ this._timeoutMs,
2036
+ this._businessDateTo
1728
2037
  );
1729
2038
  }
1730
2039
  };
1731
2040
  function convertDate(value) {
1732
2041
  if (value === null) return null;
1733
2042
  if (value instanceof Date) return value;
1734
- const normalized = /^\d{4}-\d{2}-\d{2}$/.test(value) ? value + "T00:00:00Z" : value;
2043
+ let normalized = value;
2044
+ if (/^\d{4}-\d{2}-\d{2}$/.test(value)) normalized = value + "T00:00:00Z";
2045
+ else if (/^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}(:\d{2}(\.\d+)?)?$/.test(value)) normalized = value.replace(" ", "T") + "Z";
1735
2046
  const d = new Date(normalized);
1736
2047
  if (isNaN(d.getTime())) throw new Error(`Cannot parse date: ${value}`);
1737
2048
  return d;
@@ -1745,10 +2056,24 @@ function convertInputsAndSelect(businessDate, processingDatetime, columns, table
1745
2056
  op
1746
2057
  );
1747
2058
  }
2059
+ function convertInputsAndSelectForDateRange(businessDateFrom, businessDateTo, processingDatetime, columns, table, op = new NoOperation()) {
2060
+ if (businessDateFrom == null) throw new Error("businessDateFrom is required for findForDateRange");
2061
+ if (businessDateTo == null) throw new Error("businessDateTo is required for findForDateRange");
2062
+ if (processingDatetime == null) throw new Error("processingValidAt is required for findForDateRange");
2063
+ return new FinderResult(
2064
+ convertDate(businessDateFrom),
2065
+ convertDate(processingDatetime),
2066
+ columns,
2067
+ table,
2068
+ op,
2069
+ convertDate(businessDateTo)
2070
+ );
2071
+ }
1748
2072
  // Annotate the CommonJS export names for ESM import in node:
1749
2073
  0 && (module.exports = {
1750
2074
  AggregateOperation,
1751
2075
  AggregateOperator,
2076
+ Alias,
1752
2077
  Attribute,
1753
2078
  BiTemporalColumns,
1754
2079
  BinaryOperation,
@@ -1761,6 +2086,7 @@ function convertInputsAndSelect(businessDate, processingDatetime, columns, table
1761
2086
  ComparisonOperator,
1762
2087
  ConstantOperation,
1763
2088
  CountAllOperation,
2089
+ DEFAULT_TIMEOUT_MS,
1764
2090
  DataCatalog,
1765
2091
  DataStore,
1766
2092
  Database,
@@ -1795,11 +2121,13 @@ function convertInputsAndSelect(businessDate, processingDatetime, columns, table
1795
2121
  NumericAttribute,
1796
2122
  Operation,
1797
2123
  ProcessingTemporalColumns,
2124
+ QueryTimeoutError,
1798
2125
  RelatedFinder,
1799
2126
  RelationalOperationElement,
1800
2127
  ScalarFunction,
1801
2128
  ScalarFunctionOperation,
1802
2129
  Schema,
2130
+ SelectOperation,
1803
2131
  SingleBusinessDateColumn,
1804
2132
  SortDirection,
1805
2133
  SortOperation,
@@ -1812,11 +2140,14 @@ function convertInputsAndSelect(businessDate, processingDatetime, columns, table
1812
2140
  WindowSpecification,
1813
2141
  clearRunner,
1814
2142
  convertInputsAndSelect,
2143
+ convertInputsAndSelectForDateRange,
2144
+ embeddedUnder,
1815
2145
  getRelatedFinderClass,
1816
2146
  getRunner,
1817
2147
  registerRelatedFinderClass,
1818
2148
  registerRunner,
1819
2149
  selectSqlToString,
2150
+ titleCase,
1820
2151
  toSql
1821
2152
  });
1822
2153
  //# sourceMappingURL=index.cjs.map