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
@@ -0,0 +1,1015 @@
1
+ // src/model/relational.ts
2
+ var ComparisonOperator = /* @__PURE__ */ ((ComparisonOperator2) => {
3
+ ComparisonOperator2["EQUAL"] = "EQUAL";
4
+ ComparisonOperator2["NOT_EQUAL"] = "NOT_EQUAL";
5
+ ComparisonOperator2["LESS_THAN"] = "LESS_THAN";
6
+ ComparisonOperator2["GREATER_THAN"] = "GREATER_THAN";
7
+ ComparisonOperator2["LESS_THAN_OR_EQUAL_TO"] = "LESS_THAN_OR_EQUAL_TO";
8
+ ComparisonOperator2["GREATER_THAN_OR_EQUAL_TO"] = "GREATER_THAN_OR_EQUAL_TO";
9
+ ComparisonOperator2["LIKE"] = "LIKE";
10
+ ComparisonOperator2["NOT_LIKE"] = "NOT_LIKE";
11
+ return ComparisonOperator2;
12
+ })(ComparisonOperator || {});
13
+ var LIKE_ESCAPE = "!";
14
+ function escapeLike(value) {
15
+ return value.replaceAll(LIKE_ESCAPE, LIKE_ESCAPE + LIKE_ESCAPE).replaceAll("%", LIKE_ESCAPE + "%").replaceAll("_", LIKE_ESCAPE + "_");
16
+ }
17
+ var LogicalOperator = /* @__PURE__ */ ((LogicalOperator2) => {
18
+ LogicalOperator2["AND"] = "AND";
19
+ LogicalOperator2["OR"] = "OR";
20
+ return LogicalOperator2;
21
+ })(LogicalOperator || {});
22
+ var AggregateOperator = /* @__PURE__ */ ((AggregateOperator2) => {
23
+ AggregateOperator2["COUNT"] = "COUNT";
24
+ AggregateOperator2["SUM"] = "SUM";
25
+ AggregateOperator2["MIN"] = "MIN";
26
+ AggregateOperator2["MAX"] = "MAX";
27
+ AggregateOperator2["AVERAGE"] = "AVERAGE";
28
+ AggregateOperator2["STRING_AGG"] = "STRING_AGG";
29
+ AggregateOperator2["COUNT_DISTINCT"] = "COUNT_DISTINCT";
30
+ AggregateOperator2["STDDEV_SAMP"] = "STDDEV_SAMP";
31
+ AggregateOperator2["STDDEV_POP"] = "STDDEV_POP";
32
+ AggregateOperator2["VAR_SAMP"] = "VAR_SAMP";
33
+ AggregateOperator2["VAR_POP"] = "VAR_POP";
34
+ AggregateOperator2["BOOL_AND"] = "BOOL_AND";
35
+ AggregateOperator2["BOOL_OR"] = "BOOL_OR";
36
+ return AggregateOperator2;
37
+ })(AggregateOperator || {});
38
+ var ScalarFunction = /* @__PURE__ */ ((ScalarFunction2) => {
39
+ ScalarFunction2["ABS"] = "ABS";
40
+ ScalarFunction2["CEILING"] = "CEILING";
41
+ ScalarFunction2["FLOOR"] = "FLOOR";
42
+ ScalarFunction2["MOD"] = "MOD";
43
+ ScalarFunction2["POWER"] = "POWER";
44
+ ScalarFunction2["SQRT"] = "SQRT";
45
+ ScalarFunction2["ROUND"] = "ROUND";
46
+ ScalarFunction2["UPPER"] = "UPPER";
47
+ ScalarFunction2["LOWER"] = "LOWER";
48
+ ScalarFunction2["TRIM"] = "TRIM";
49
+ ScalarFunction2["LTRIM"] = "LTRIM";
50
+ ScalarFunction2["RTRIM"] = "RTRIM";
51
+ ScalarFunction2["LENGTH"] = "LENGTH";
52
+ ScalarFunction2["REVERSE"] = "REVERSE";
53
+ ScalarFunction2["LEFT"] = "LEFT";
54
+ ScalarFunction2["RIGHT"] = "RIGHT";
55
+ ScalarFunction2["REPEAT"] = "REPEAT";
56
+ ScalarFunction2["REPLACE"] = "REPLACE";
57
+ ScalarFunction2["SUBSTRING"] = "SUBSTRING";
58
+ ScalarFunction2["COALESCE"] = "COALESCE";
59
+ return ScalarFunction2;
60
+ })(ScalarFunction || {});
61
+ var DatePart = /* @__PURE__ */ ((DatePart2) => {
62
+ DatePart2["YEAR"] = "YEAR";
63
+ DatePart2["MONTH"] = "MONTH";
64
+ DatePart2["DAY"] = "DAY";
65
+ DatePart2["HOUR"] = "HOUR";
66
+ DatePart2["MINUTE"] = "MINUTE";
67
+ DatePart2["SECOND"] = "SECOND";
68
+ DatePart2["QUARTER"] = "QUARTER";
69
+ DatePart2["WEEK"] = "WEEK";
70
+ DatePart2["DOW"] = "DOW";
71
+ return DatePart2;
72
+ })(DatePart || {});
73
+ var SortDirection = /* @__PURE__ */ ((SortDirection2) => {
74
+ SortDirection2["ASC"] = "ASC";
75
+ SortDirection2["DESC"] = "DESC";
76
+ return SortDirection2;
77
+ })(SortDirection || {});
78
+ var RelationalOperationElement = class {
79
+ };
80
+ var Operation = class extends RelationalOperationElement {
81
+ /** Name this column in the result: `f.price().sum().alias('Total')`, `f.age().gt(30).alias('Adult')`. */
82
+ alias(name) {
83
+ return new Alias(this, name);
84
+ }
85
+ and(other) {
86
+ return new LogicalOperation(this, "AND" /* AND */, other);
87
+ }
88
+ /** Combine with `other` using OR. A chain reads left to right: `a.or(b).and(c)` is `(a OR b) AND c`. */
89
+ or(other) {
90
+ return new LogicalOperation(this, "OR" /* OR */, other);
91
+ }
92
+ };
93
+ var NoOperation = class extends Operation {
94
+ and(other) {
95
+ return other;
96
+ }
97
+ /** No filter matches every row, so OR-ing anything with it still matches every row. */
98
+ or(_other) {
99
+ return this;
100
+ }
101
+ };
102
+ var ConstantOperation = class extends RelationalOperationElement {
103
+ /** Name this column in the result. */
104
+ alias(name) {
105
+ return new Alias(this, name);
106
+ }
107
+ /** Sort by this expression, smallest first. */
108
+ ascending() {
109
+ return new SortOperation(this, "ASC" /* ASC */);
110
+ }
111
+ /** Sort by this expression, largest first. */
112
+ descending() {
113
+ return new SortOperation(this, "DESC" /* DESC */);
114
+ }
115
+ };
116
+ var NumericConstantOperation = class extends ConstantOperation {
117
+ arithmeticOperand() {
118
+ return this;
119
+ }
120
+ };
121
+ var IntegerConstantOperation = class extends NumericConstantOperation {
122
+ constructor(value) {
123
+ super();
124
+ this.value = value;
125
+ }
126
+ value;
127
+ };
128
+ var FloatConstantOperation = class extends NumericConstantOperation {
129
+ constructor(value) {
130
+ super();
131
+ this.value = value;
132
+ }
133
+ value;
134
+ };
135
+ var StringConstantOperation = class extends ConstantOperation {
136
+ constructor(value) {
137
+ super();
138
+ this.value = value;
139
+ }
140
+ value;
141
+ };
142
+ var DATE_ONLY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
143
+ var DateOnly = class extends Date {
144
+ };
145
+ var DateConstantOperation = class extends ConstantOperation {
146
+ constructor(value) {
147
+ super();
148
+ this.value = value;
149
+ }
150
+ value;
151
+ };
152
+ var DateTimeConstantOperation = class extends ConstantOperation {
153
+ constructor(value) {
154
+ super();
155
+ this.value = value;
156
+ }
157
+ value;
158
+ };
159
+ var DecimalConstantOperation = class extends NumericConstantOperation {
160
+ constructor(value) {
161
+ super();
162
+ this.value = value;
163
+ }
164
+ value;
165
+ };
166
+ var BooleanConstantOperation = class extends ConstantOperation {
167
+ constructor(value) {
168
+ super();
169
+ this.value = value;
170
+ }
171
+ value;
172
+ };
173
+ var UnaryOperation = class extends Operation {
174
+ constructor(element) {
175
+ super();
176
+ this.element = element;
177
+ }
178
+ element;
179
+ };
180
+ var BinaryOperation = class extends Operation {
181
+ constructor(left, right) {
182
+ super();
183
+ this.left = left;
184
+ this.right = right;
185
+ }
186
+ left;
187
+ right;
188
+ };
189
+ var IsNullOperation = class extends UnaryOperation {
190
+ };
191
+ var IsNotNullOperation = class extends UnaryOperation {
192
+ };
193
+ var InOperation = class extends UnaryOperation {
194
+ constructor(element, values) {
195
+ super(element);
196
+ this.values = values;
197
+ }
198
+ values;
199
+ };
200
+ var NotInOperation = class extends UnaryOperation {
201
+ constructor(element, values) {
202
+ super(element);
203
+ this.values = values;
204
+ }
205
+ values;
206
+ };
207
+ var ComparisonOperation = class extends BinaryOperation {
208
+ constructor(left, operator, right) {
209
+ super(left, right);
210
+ this.operator = operator;
211
+ }
212
+ operator;
213
+ };
214
+ var LogicalOperation = class extends BinaryOperation {
215
+ constructor(left, operator, right) {
216
+ super(left, right);
217
+ this.operator = operator;
218
+ }
219
+ operator;
220
+ };
221
+ var WindowSpecification = class {
222
+ constructor(partitionBy = [], orderBy = []) {
223
+ this.partitionBy = partitionBy;
224
+ this.orderBy = orderBy;
225
+ }
226
+ partitionBy;
227
+ orderBy;
228
+ };
229
+ var AggregateOperation = class _AggregateOperation extends UnaryOperation {
230
+ constructor(element, operator, displayName, window, separator, orderBy = []) {
231
+ super(element);
232
+ this.operator = operator;
233
+ this.displayName = displayName;
234
+ this.window = window;
235
+ this.separator = separator;
236
+ this.orderBy = orderBy;
237
+ }
238
+ operator;
239
+ displayName;
240
+ window;
241
+ separator;
242
+ orderBy;
243
+ /** Sort by this expression, smallest first. */
244
+ ascending() {
245
+ return new SortOperation(this, "ASC" /* ASC */);
246
+ }
247
+ /** Sort by this expression, largest first. */
248
+ descending() {
249
+ return new SortOperation(this, "DESC" /* DESC */);
250
+ }
251
+ arithmeticOperand() {
252
+ return this;
253
+ }
254
+ comparisonOperand() {
255
+ return this;
256
+ }
257
+ over(partitionBy, orderBy) {
258
+ return new _AggregateOperation(
259
+ this.element,
260
+ this.operator,
261
+ this.displayName,
262
+ new WindowSpecification(partitionBy ?? [], orderBy ?? []),
263
+ this.separator,
264
+ this.orderBy
265
+ );
266
+ }
267
+ };
268
+ var WindowFunction = /* @__PURE__ */ ((WindowFunction2) => {
269
+ WindowFunction2["ROW_NUMBER"] = "ROW_NUMBER";
270
+ WindowFunction2["RANK"] = "RANK";
271
+ WindowFunction2["DENSE_RANK"] = "DENSE_RANK";
272
+ WindowFunction2["NTILE"] = "NTILE";
273
+ WindowFunction2["LAG"] = "LAG";
274
+ WindowFunction2["LEAD"] = "LEAD";
275
+ WindowFunction2["FIRST_VALUE"] = "FIRST_VALUE";
276
+ WindowFunction2["LAST_VALUE"] = "LAST_VALUE";
277
+ WindowFunction2["CUME_DIST"] = "CUME_DIST";
278
+ WindowFunction2["PERCENT_RANK"] = "PERCENT_RANK";
279
+ return WindowFunction2;
280
+ })(WindowFunction || {});
281
+ var WindowFunctionOperation = class _WindowFunctionOperation extends UnaryOperation {
282
+ constructor(element, func, displayName, secondArg, extraArgs = [], window) {
283
+ super(element);
284
+ this.func = func;
285
+ this.displayName = displayName;
286
+ this.secondArg = secondArg;
287
+ this.extraArgs = extraArgs;
288
+ this.window = window;
289
+ }
290
+ func;
291
+ displayName;
292
+ secondArg;
293
+ extraArgs;
294
+ window;
295
+ /** Sort by this expression, smallest first. */
296
+ ascending() {
297
+ return new SortOperation(this, "ASC" /* ASC */);
298
+ }
299
+ /** Sort by this expression, largest first. */
300
+ descending() {
301
+ return new SortOperation(this, "DESC" /* DESC */);
302
+ }
303
+ over(partitionBy, orderBy) {
304
+ return new _WindowFunctionOperation(
305
+ this.element,
306
+ this.func,
307
+ this.displayName,
308
+ this.secondArg,
309
+ [...this.extraArgs],
310
+ new WindowSpecification(partitionBy ?? [], orderBy ?? [])
311
+ );
312
+ }
313
+ };
314
+ var ScalarFunctionOperation = class extends UnaryOperation {
315
+ constructor(element, func, displayName, secondArg, extraArgs = []) {
316
+ super(element);
317
+ this.func = func;
318
+ this.displayName = displayName;
319
+ this.secondArg = secondArg;
320
+ this.extraArgs = extraArgs;
321
+ }
322
+ func;
323
+ displayName;
324
+ secondArg;
325
+ extraArgs;
326
+ /** Sort by this expression, smallest first. */
327
+ ascending() {
328
+ return new SortOperation(this, "ASC" /* ASC */);
329
+ }
330
+ /** Sort by this expression, largest first. */
331
+ descending() {
332
+ return new SortOperation(this, "DESC" /* DESC */);
333
+ }
334
+ /** This expression as an operand of a comparison. */
335
+ comparisonOperand() {
336
+ return this;
337
+ }
338
+ arithmeticOperand() {
339
+ return this;
340
+ }
341
+ /** Only a function that gives a number can be used in arithmetic. */
342
+ assertNumeric() {
343
+ if (!NUMERIC_FUNCTIONS.has(this.func)) {
344
+ throw new TypeError(`${this.func} does not give a number, so it cannot be used in arithmetic`);
345
+ }
346
+ }
347
+ };
348
+ var NUMERIC_FUNCTIONS = /* @__PURE__ */ new Set([
349
+ "ABS" /* ABS */,
350
+ "CEILING" /* CEILING */,
351
+ "FLOOR" /* FLOOR */,
352
+ "MOD" /* MOD */,
353
+ "POWER" /* POWER */,
354
+ "SQRT" /* SQRT */,
355
+ "ROUND" /* ROUND */,
356
+ "LENGTH" /* LENGTH */
357
+ ]);
358
+ var DateExtractOperation = class extends UnaryOperation {
359
+ constructor(element, part, displayName) {
360
+ super(element);
361
+ this.part = part;
362
+ this.displayName = displayName;
363
+ }
364
+ part;
365
+ displayName;
366
+ /** Sort by this expression, smallest first. */
367
+ ascending() {
368
+ return new SortOperation(this, "ASC" /* ASC */);
369
+ }
370
+ /** Sort by this expression, largest first. */
371
+ descending() {
372
+ return new SortOperation(this, "DESC" /* DESC */);
373
+ }
374
+ };
375
+ var DateTruncOperation = class extends UnaryOperation {
376
+ constructor(element, part, displayName) {
377
+ super(element);
378
+ this.part = part;
379
+ this.displayName = displayName;
380
+ }
381
+ part;
382
+ displayName;
383
+ /** Sort by this expression, earliest first. */
384
+ ascending() {
385
+ return new SortOperation(this, "ASC" /* ASC */);
386
+ }
387
+ /** Sort by this expression, latest first. */
388
+ descending() {
389
+ return new SortOperation(this, "DESC" /* DESC */);
390
+ }
391
+ comparisonOperand() {
392
+ return this;
393
+ }
394
+ };
395
+ var DateArithmeticOperation = class extends UnaryOperation {
396
+ constructor(element, n, unit, isAdd = true, displayName) {
397
+ super(element);
398
+ this.n = n;
399
+ this.unit = unit;
400
+ this.isAdd = isAdd;
401
+ this.displayName = displayName;
402
+ }
403
+ n;
404
+ unit;
405
+ isAdd;
406
+ displayName;
407
+ /** Sort by this expression, smallest first. */
408
+ ascending() {
409
+ return new SortOperation(this, "ASC" /* ASC */);
410
+ }
411
+ /** Sort by this expression, largest first. */
412
+ descending() {
413
+ return new SortOperation(this, "DESC" /* DESC */);
414
+ }
415
+ };
416
+ var DateDiffOperation = class extends UnaryOperation {
417
+ constructor(element, other, unit, displayName) {
418
+ super(element);
419
+ this.other = other;
420
+ this.unit = unit;
421
+ this.displayName = displayName;
422
+ }
423
+ other;
424
+ unit;
425
+ displayName;
426
+ /** Sort by this expression, smallest first. */
427
+ ascending() {
428
+ return new SortOperation(this, "ASC" /* ASC */);
429
+ }
430
+ /** Sort by this expression, largest first. */
431
+ descending() {
432
+ return new SortOperation(this, "DESC" /* DESC */);
433
+ }
434
+ };
435
+ var Column = class extends RelationalOperationElement {
436
+ constructor(name, type, owner, primaryKey = false, nullable = true) {
437
+ super();
438
+ this.name = name;
439
+ this.type = type;
440
+ this.owner = owner;
441
+ this.primaryKey = primaryKey;
442
+ this.nullable = nullable && !primaryKey;
443
+ }
444
+ name;
445
+ type;
446
+ owner;
447
+ primaryKey;
448
+ table;
449
+ /** Whether the column may hold NULL. As in Legend, a primary key is never null. */
450
+ nullable;
451
+ };
452
+ var ForeignKey = class {
453
+ constructor(column, references) {
454
+ this.column = column;
455
+ this.references = references;
456
+ }
457
+ column;
458
+ references;
459
+ };
460
+ var DataStore = class {
461
+ constructor(name) {
462
+ this.name = name;
463
+ }
464
+ name;
465
+ schemas = [];
466
+ };
467
+ var Database = class extends DataStore {
468
+ constructor(name, location) {
469
+ super(name);
470
+ this.location = location;
471
+ }
472
+ location;
473
+ namespace(schemaName) {
474
+ return schemaName;
475
+ }
476
+ };
477
+ var DataCatalog = class extends DataStore {
478
+ constructor(name) {
479
+ super(name);
480
+ }
481
+ namespace(schemaName) {
482
+ return `${this.name}.${schemaName}`;
483
+ }
484
+ };
485
+ var Schema = class {
486
+ constructor(name, datastore) {
487
+ this.name = name;
488
+ this.datastore = datastore;
489
+ datastore?.schemas.push(this);
490
+ }
491
+ name;
492
+ datastore;
493
+ tables = [];
494
+ };
495
+ var Table = class {
496
+ constructor(name, columns, schema) {
497
+ this.name = name;
498
+ this.schema = schema;
499
+ for (const col of columns) {
500
+ if (this._columnsByName.has(col.name)) {
501
+ throw new Error(`Duplicate column name '${col.name}' in table '${name}'`);
502
+ }
503
+ this._columnsByName.set(col.name, col);
504
+ col.table = this;
505
+ }
506
+ schema?.tables.push(this);
507
+ }
508
+ name;
509
+ schema;
510
+ _columnsByName = /* @__PURE__ */ new Map();
511
+ foreignKeys = [];
512
+ get columns() {
513
+ return Array.from(this._columnsByName.values());
514
+ }
515
+ get qualifiedName() {
516
+ if (!this.schema) return this.name;
517
+ if (!this.schema.datastore) return `${this.schema.name}.${this.name}`;
518
+ return `${this.schema.datastore.namespace(this.schema.name)}.${this.name}`;
519
+ }
520
+ };
521
+ var JoinOperation = class {
522
+ constructor(name, target, left, right, filter) {
523
+ this.name = name;
524
+ this.target = target;
525
+ this.left = left;
526
+ this.right = right;
527
+ this.filter = filter;
528
+ }
529
+ name;
530
+ target;
531
+ left;
532
+ right;
533
+ filter;
534
+ /** Property-equality filters on the join target (property id -> value), set by a related finder given a filter. */
535
+ filterKwargs = {};
536
+ /** Maps property ids to [column, type, table] for `filterKwargs`. */
537
+ filterColumnMap = {};
538
+ };
539
+ var JoinTreeNodeOperation = class {
540
+ constructor(join, parent, many = false, optional = false) {
541
+ this.join = join;
542
+ this.parent = parent;
543
+ this.many = many;
544
+ this.optional = optional;
545
+ }
546
+ join;
547
+ parent;
548
+ many;
549
+ optional;
550
+ };
551
+ var ColumnWithJoin = class extends RelationalOperationElement {
552
+ /**
553
+ * `embedded` is an alternate reference to a flat (denormalized) column on the owning table that
554
+ * holds the same value without the join; the SQL generator uses it when the join can be elided.
555
+ */
556
+ constructor(column, parent, embedded, _optional = false) {
557
+ super();
558
+ this.column = column;
559
+ this.parent = parent;
560
+ this.embedded = embedded;
561
+ this._optional = _optional;
562
+ }
563
+ column;
564
+ parent;
565
+ embedded;
566
+ _optional;
567
+ /** Whether the value can be missing: its property is optional, or a navigation on the way to it is. */
568
+ get optional() {
569
+ for (let node = this.parent; node !== void 0; node = node.parent) {
570
+ if (node.optional) return true;
571
+ }
572
+ return this._optional;
573
+ }
574
+ };
575
+ var SortOperation = class {
576
+ constructor(column, direction) {
577
+ this.column = column;
578
+ this.direction = direction;
579
+ }
580
+ column;
581
+ direction;
582
+ };
583
+ var CountAllOperation = class extends RelationalOperationElement {
584
+ constructor(table) {
585
+ super();
586
+ this.table = table;
587
+ }
588
+ table;
589
+ /** Name this column in the result. */
590
+ alias(name) {
591
+ return new Alias(this, name);
592
+ }
593
+ /** Sort by this expression, smallest first. */
594
+ ascending() {
595
+ return new SortOperation(this, "ASC" /* ASC */);
596
+ }
597
+ /** Sort by this expression, largest first. */
598
+ descending() {
599
+ return new SortOperation(this, "DESC" /* DESC */);
600
+ }
601
+ comparisonOperand() {
602
+ return this;
603
+ }
604
+ };
605
+ var Alias = class _Alias extends RelationalOperationElement {
606
+ constructor(element, name) {
607
+ super();
608
+ this.element = element;
609
+ this.name = name;
610
+ }
611
+ element;
612
+ name;
613
+ alias(name) {
614
+ return new _Alias(this.element, name);
615
+ }
616
+ /** Sorts by the column the alias names. */
617
+ ascending() {
618
+ return new SortOperation(this.element, "ASC" /* ASC */);
619
+ }
620
+ /** Sorts by the column the alias names. */
621
+ descending() {
622
+ return new SortOperation(this.element, "DESC" /* DESC */);
623
+ }
624
+ };
625
+ var CaseOperation = class extends Operation {
626
+ constructor(condition, then, fallback, displayName) {
627
+ super();
628
+ this.condition = condition;
629
+ this.then = then;
630
+ this.fallback = fallback;
631
+ this.displayName = displayName;
632
+ }
633
+ condition;
634
+ then;
635
+ fallback;
636
+ displayName;
637
+ };
638
+ var ExistsOperation = class extends RelationalOperationElement {
639
+ constructor(node) {
640
+ super();
641
+ this.node = node;
642
+ }
643
+ node;
644
+ /** Name this column in the result. */
645
+ alias(name) {
646
+ return new Alias(this, name);
647
+ }
648
+ and(other) {
649
+ return new LogicalOperation(this, "AND" /* AND */, other);
650
+ }
651
+ or(other) {
652
+ return new LogicalOperation(this, "OR" /* OR */, other);
653
+ }
654
+ };
655
+ var NotExistsOperation = class extends RelationalOperationElement {
656
+ constructor(node) {
657
+ super();
658
+ this.node = node;
659
+ }
660
+ node;
661
+ /** Name this column in the result. */
662
+ alias(name) {
663
+ return new Alias(this, name);
664
+ }
665
+ and(other) {
666
+ return new LogicalOperation(this, "AND" /* AND */, other);
667
+ }
668
+ or(other) {
669
+ return new LogicalOperation(this, "OR" /* OR */, other);
670
+ }
671
+ };
672
+ var SelectOperation = class {
673
+ constructor(display, filter, orderBy = [], groupBy = [], limit, table, joinFilters = /* @__PURE__ */ new Map(), distinct = false, offset, having) {
674
+ this.display = display;
675
+ this.filter = filter;
676
+ this.orderBy = orderBy;
677
+ this.groupBy = groupBy;
678
+ this.limit = limit;
679
+ this.table = table;
680
+ this.joinFilters = joinFilters;
681
+ this.distinct = distinct;
682
+ this.offset = offset;
683
+ this.having = having;
684
+ }
685
+ display;
686
+ filter;
687
+ orderBy;
688
+ groupBy;
689
+ limit;
690
+ table;
691
+ joinFilters;
692
+ distinct;
693
+ offset;
694
+ having;
695
+ };
696
+ function containsAggregateOrWindow(op) {
697
+ if (op instanceof AggregateOperation || op instanceof WindowFunctionOperation || op instanceof CountAllOperation) return true;
698
+ if (op instanceof BinaryOperation) return containsAggregateOrWindow(op.left) || containsAggregateOrWindow(op.right);
699
+ if (op instanceof UnaryOperation || op instanceof Alias) return containsAggregateOrWindow(op.element);
700
+ return false;
701
+ }
702
+ function containsAggregate(op) {
703
+ if (op instanceof AggregateOperation || op instanceof CountAllOperation) return true;
704
+ if (op instanceof BinaryOperation) return containsAggregate(op.left) || containsAggregate(op.right);
705
+ if (op instanceof UnaryOperation || op instanceof Alias) return containsAggregate(op.element);
706
+ return false;
707
+ }
708
+ function valueOperand(value) {
709
+ if (typeof value === "boolean") return new BooleanConstantOperation(value);
710
+ if (typeof value === "number" && Number.isFinite(value)) {
711
+ return Number.isInteger(value) ? new IntegerConstantOperation(value) : new FloatConstantOperation(value);
712
+ }
713
+ if (typeof value === "string") return new StringConstantOperation(value);
714
+ if (value instanceof DateOnly) return new DateConstantOperation(value);
715
+ if (value instanceof Date) return new DateTimeConstantOperation(value);
716
+ 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}`);
717
+ }
718
+ function operandOf(other) {
719
+ if (other instanceof RelationalOperationElement) return other;
720
+ if (typeof other?.cwj === "function") return other.cwj();
721
+ return valueOperand(other);
722
+ }
723
+ var Comparable = class {
724
+ _compared(operator, other) {
725
+ return new ComparisonOperation(this.comparisonOperand(), operator, operandOf(other));
726
+ }
727
+ /** Filter to rows where this expression equals `other`. */
728
+ eq(other) {
729
+ return this._compared("EQUAL" /* EQUAL */, other);
730
+ }
731
+ /** Filter to rows where this expression does not equal `other`. */
732
+ ne(other) {
733
+ return this._compared("NOT_EQUAL" /* NOT_EQUAL */, other);
734
+ }
735
+ /** Filter to rows where this expression is less than `other`. */
736
+ lt(other) {
737
+ return this._compared("LESS_THAN" /* LESS_THAN */, other);
738
+ }
739
+ /** Filter to rows where this expression is at most `other`. */
740
+ lte(other) {
741
+ return this._compared("LESS_THAN_OR_EQUAL_TO" /* LESS_THAN_OR_EQUAL_TO */, other);
742
+ }
743
+ /** Filter to rows where this expression is greater than `other`. */
744
+ gt(other) {
745
+ return this._compared("GREATER_THAN" /* GREATER_THAN */, other);
746
+ }
747
+ /** Filter to rows where this expression is at least `other`. */
748
+ gte(other) {
749
+ return this._compared("GREATER_THAN_OR_EQUAL_TO" /* GREATER_THAN_OR_EQUAL_TO */, other);
750
+ }
751
+ };
752
+ function sample(ddof) {
753
+ if (ddof !== 0 && ddof !== 1) throw new RangeError(`ddof is 0 (population) or 1 (sample), not ${ddof}`);
754
+ return ddof === 1;
755
+ }
756
+ var StringPredicates = class {
757
+ _like(pattern) {
758
+ return new ComparisonOperation(this.comparisonOperand(), "LIKE" /* LIKE */, new StringConstantOperation(pattern));
759
+ }
760
+ /** Filter to rows where this text contains `value`. */
761
+ contains(value) {
762
+ return this._like(`%${escapeLike(value)}%`);
763
+ }
764
+ /** Filter to rows where this text starts with `prefix`. */
765
+ startsWith(prefix) {
766
+ return this._like(`${escapeLike(prefix)}%`);
767
+ }
768
+ /** Filter to rows where this text ends with `suffix`. */
769
+ endsWith(suffix) {
770
+ return this._like(`%${escapeLike(suffix)}`);
771
+ }
772
+ };
773
+ var Aggregates = class {
774
+ _aggregate(operator, label) {
775
+ return new AggregateOperation(this, operator, label + " Expression");
776
+ }
777
+ /** Sum of the values in the group. */
778
+ sum() {
779
+ return this._aggregate("SUM" /* SUM */, "Sum");
780
+ }
781
+ /** Smallest value in the group. */
782
+ min() {
783
+ return this._aggregate("MIN" /* MIN */, "Min");
784
+ }
785
+ /** Largest value in the group. */
786
+ max() {
787
+ return this._aggregate("MAX" /* MAX */, "Max");
788
+ }
789
+ /** Arithmetic mean of the values in the group. */
790
+ average() {
791
+ return this._aggregate("AVERAGE" /* AVERAGE */, "Average");
792
+ }
793
+ /** Number of non-null values in the group. */
794
+ count() {
795
+ return this._aggregate("COUNT" /* COUNT */, "Count");
796
+ }
797
+ /** Standard deviation of the values in the group: the sample one by default, `ddof = 0` for the population one. */
798
+ std(ddof = 1) {
799
+ return this._aggregate(sample(ddof) ? "STDDEV_SAMP" /* STDDEV_SAMP */ : "STDDEV_POP" /* STDDEV_POP */, "Std");
800
+ }
801
+ /** Variance of the values in the group: the sample one by default, `ddof = 0` for the population one. */
802
+ var(ddof = 1) {
803
+ return this._aggregate(sample(ddof) ? "VAR_SAMP" /* VAR_SAMP */ : "VAR_POP" /* VAR_POP */, "Var");
804
+ }
805
+ };
806
+ var BooleanAggregates = class {
807
+ /** True for a group where every row satisfies the condition. */
808
+ all() {
809
+ return new AggregateOperation(this, "BOOL_AND" /* BOOL_AND */, "All Expression");
810
+ }
811
+ /** True for a group where at least one row satisfies the condition. */
812
+ any() {
813
+ return new AggregateOperation(this, "BOOL_OR" /* BOOL_OR */, "Any Expression");
814
+ }
815
+ };
816
+ function applyMixins(derived, bases) {
817
+ for (const base of bases) {
818
+ for (const name of Object.getOwnPropertyNames(base.prototype)) {
819
+ if (name === "constructor" || Object.prototype.hasOwnProperty.call(derived.prototype, name)) continue;
820
+ Object.defineProperty(derived.prototype, name, Object.getOwnPropertyDescriptor(base.prototype, name));
821
+ }
822
+ }
823
+ }
824
+ var ArithmeticOperator = /* @__PURE__ */ ((ArithmeticOperator2) => {
825
+ ArithmeticOperator2["ADD"] = "+";
826
+ ArithmeticOperator2["SUBTRACT"] = "-";
827
+ ArithmeticOperator2["MULTIPLY"] = "*";
828
+ ArithmeticOperator2["DIVIDE"] = "/";
829
+ return ArithmeticOperator2;
830
+ })(ArithmeticOperator || {});
831
+ var Arithmetic = class {
832
+ /** Raises if this expression is not a number. */
833
+ assertNumeric() {
834
+ }
835
+ _arithmetic(operator, other) {
836
+ this.assertNumeric();
837
+ let operand;
838
+ if (typeof other === "number") {
839
+ if (!Number.isFinite(other)) throw new TypeError("Arithmetic is between numbers and numeric columns, not a non-finite number");
840
+ operand = valueOperand(other);
841
+ } else if (other !== null && typeof other === "object" && typeof other.arithmeticOperand === "function") {
842
+ other.assertNumeric?.();
843
+ operand = other.arithmeticOperand();
844
+ } else {
845
+ throw new TypeError(`Arithmetic is between numbers and numeric columns, not ${other === null ? "null" : typeof other}`);
846
+ }
847
+ return new ArithmeticOperation(this.arithmeticOperand(), operator, operand);
848
+ }
849
+ /** `this + other`. */
850
+ plus(other) {
851
+ return this._arithmetic("+" /* ADD */, other);
852
+ }
853
+ /** `this - other`. */
854
+ minus(other) {
855
+ return this._arithmetic("-" /* SUBTRACT */, other);
856
+ }
857
+ /** `this * other`. */
858
+ times(other) {
859
+ return this._arithmetic("*" /* MULTIPLY */, other);
860
+ }
861
+ /** `this / other`. */
862
+ dividedBy(other) {
863
+ return this._arithmetic("/" /* DIVIDE */, other);
864
+ }
865
+ };
866
+ var ArithmeticOperation = class extends BinaryOperation {
867
+ constructor(left, operator, right, displayName) {
868
+ super(left, right);
869
+ this.operator = operator;
870
+ this.displayName = displayName;
871
+ }
872
+ operator;
873
+ displayName;
874
+ /** Sort by this expression, smallest first. */
875
+ ascending() {
876
+ return new SortOperation(this, "ASC" /* ASC */);
877
+ }
878
+ /** Sort by this expression, largest first. */
879
+ descending() {
880
+ return new SortOperation(this, "DESC" /* DESC */);
881
+ }
882
+ arithmeticOperand() {
883
+ return this;
884
+ }
885
+ comparisonOperand() {
886
+ return this;
887
+ }
888
+ };
889
+ var ConcatOperation = class extends Operation {
890
+ constructor(parts, displayName) {
891
+ super();
892
+ this.parts = parts;
893
+ this.displayName = displayName;
894
+ }
895
+ parts;
896
+ displayName;
897
+ /** Join more text on the end: `f.first().concat(' ', f.last())`. A concatenation joins into one. */
898
+ concat(...more) {
899
+ return concat(this, ...more);
900
+ }
901
+ /** Sort by this expression, smallest first. */
902
+ ascending() {
903
+ return new SortOperation(this, "ASC" /* ASC */);
904
+ }
905
+ /** Sort by this expression, largest first. */
906
+ descending() {
907
+ return new SortOperation(this, "DESC" /* DESC */);
908
+ }
909
+ comparisonOperand() {
910
+ return this;
911
+ }
912
+ };
913
+ function concat(...parts) {
914
+ const partsOf = (part) => {
915
+ if (part instanceof ConcatOperation) return part.parts;
916
+ if (typeof part === "string") return [new StringConstantOperation(part)];
917
+ if (part instanceof RelationalOperationElement) return [part];
918
+ if (part !== null && typeof part === "object" && typeof part.functionInput === "function") return [part.functionInput()];
919
+ throw new TypeError(`Text is joined with text, not ${part === null ? "null" : typeof part}`);
920
+ };
921
+ return new ConcatOperation(parts.flatMap(partsOf));
922
+ }
923
+ applyMixins(ConcatOperation, [Comparable, StringPredicates]);
924
+ applyMixins(DateTruncOperation, [Comparable]);
925
+ applyMixins(ArithmeticOperation, [Arithmetic, Comparable]);
926
+ applyMixins(ScalarFunctionOperation, [Comparable, Arithmetic, StringPredicates]);
927
+ applyMixins(AggregateOperation, [Arithmetic, Comparable, StringPredicates]);
928
+ applyMixins(CountAllOperation, [Comparable]);
929
+ applyMixins(NumericConstantOperation, [Arithmetic]);
930
+ applyMixins(ConstantOperation, [Aggregates]);
931
+ applyMixins(ArithmeticOperation, [Aggregates]);
932
+ applyMixins(ScalarFunctionOperation, [Aggregates]);
933
+ applyMixins(CaseOperation, [Aggregates]);
934
+ applyMixins(IsNullOperation, [BooleanAggregates]);
935
+ applyMixins(IsNotNullOperation, [BooleanAggregates]);
936
+ applyMixins(InOperation, [BooleanAggregates]);
937
+ applyMixins(NotInOperation, [BooleanAggregates]);
938
+ applyMixins(ComparisonOperation, [BooleanAggregates]);
939
+ applyMixins(LogicalOperation, [BooleanAggregates]);
940
+
941
+ export {
942
+ ComparisonOperator,
943
+ LIKE_ESCAPE,
944
+ escapeLike,
945
+ LogicalOperator,
946
+ AggregateOperator,
947
+ ScalarFunction,
948
+ DatePart,
949
+ SortDirection,
950
+ RelationalOperationElement,
951
+ Operation,
952
+ NoOperation,
953
+ ConstantOperation,
954
+ NumericConstantOperation,
955
+ IntegerConstantOperation,
956
+ FloatConstantOperation,
957
+ StringConstantOperation,
958
+ DATE_ONLY_PATTERN,
959
+ DateOnly,
960
+ DateConstantOperation,
961
+ DateTimeConstantOperation,
962
+ DecimalConstantOperation,
963
+ BooleanConstantOperation,
964
+ UnaryOperation,
965
+ BinaryOperation,
966
+ IsNullOperation,
967
+ IsNotNullOperation,
968
+ InOperation,
969
+ NotInOperation,
970
+ ComparisonOperation,
971
+ LogicalOperation,
972
+ WindowSpecification,
973
+ AggregateOperation,
974
+ WindowFunction,
975
+ WindowFunctionOperation,
976
+ ScalarFunctionOperation,
977
+ NUMERIC_FUNCTIONS,
978
+ DateExtractOperation,
979
+ DateTruncOperation,
980
+ DateArithmeticOperation,
981
+ DateDiffOperation,
982
+ Column,
983
+ ForeignKey,
984
+ DataStore,
985
+ Database,
986
+ DataCatalog,
987
+ Schema,
988
+ Table,
989
+ JoinOperation,
990
+ JoinTreeNodeOperation,
991
+ ColumnWithJoin,
992
+ SortOperation,
993
+ CountAllOperation,
994
+ Alias,
995
+ CaseOperation,
996
+ ExistsOperation,
997
+ NotExistsOperation,
998
+ SelectOperation,
999
+ containsAggregateOrWindow,
1000
+ containsAggregate,
1001
+ valueOperand,
1002
+ operandOf,
1003
+ Comparable,
1004
+ sample,
1005
+ StringPredicates,
1006
+ Aggregates,
1007
+ BooleanAggregates,
1008
+ applyMixins,
1009
+ ArithmeticOperator,
1010
+ Arithmetic,
1011
+ ArithmeticOperation,
1012
+ ConcatOperation,
1013
+ concat
1014
+ };
1015
+ //# sourceMappingURL=chunk-PF6EJZHB.js.map