unframer 2.7.6 → 2.7.8

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 (78) hide show
  1. package/README.md +5 -6
  2. package/dist/babel-plugin-imports.d.ts +21 -0
  3. package/dist/babel-plugin-imports.d.ts.map +1 -0
  4. package/dist/babel-plugin-imports.js +375 -0
  5. package/dist/babel-plugin-imports.js.map +1 -0
  6. package/dist/cli.d.ts +14 -0
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +9 -42
  9. package/dist/cli.js.map +1 -1
  10. package/dist/css.d.ts.map +1 -1
  11. package/dist/css.js +4 -3
  12. package/dist/css.js.map +1 -1
  13. package/dist/esbuild.d.ts +7 -0
  14. package/dist/esbuild.d.ts.map +1 -1
  15. package/dist/esbuild.js +15 -1
  16. package/dist/esbuild.js.map +1 -1
  17. package/dist/exporter.d.ts +6 -14
  18. package/dist/exporter.d.ts.map +1 -1
  19. package/dist/exporter.js +79 -38
  20. package/dist/exporter.js.map +1 -1
  21. package/dist/exporter.test.js +48 -0
  22. package/dist/exporter.test.js.map +1 -1
  23. package/dist/framer.d.ts.map +1 -1
  24. package/dist/framer.js +26 -1788
  25. package/dist/framer.js.map +1 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/renamer.d.ts +12 -0
  29. package/dist/renamer.d.ts.map +1 -0
  30. package/dist/renamer.js +169 -0
  31. package/dist/renamer.js.map +1 -0
  32. package/dist/unframer-loader.d.ts.map +1 -1
  33. package/dist/unframer-loader.js +4 -3
  34. package/dist/unframer-loader.js.map +1 -1
  35. package/esm/babel-plugin-imports.d.ts +21 -0
  36. package/esm/babel-plugin-imports.d.ts.map +1 -0
  37. package/esm/babel-plugin-imports.js +344 -0
  38. package/esm/babel-plugin-imports.js.map +1 -0
  39. package/esm/cli.d.ts +14 -0
  40. package/esm/cli.d.ts.map +1 -1
  41. package/esm/cli.js +9 -42
  42. package/esm/cli.js.map +1 -1
  43. package/esm/css.d.ts.map +1 -1
  44. package/esm/css.js +3 -2
  45. package/esm/css.js.map +1 -1
  46. package/esm/esbuild.d.ts +7 -0
  47. package/esm/esbuild.d.ts.map +1 -1
  48. package/esm/esbuild.js +13 -0
  49. package/esm/esbuild.js.map +1 -1
  50. package/esm/exporter.d.ts +6 -14
  51. package/esm/exporter.d.ts.map +1 -1
  52. package/esm/exporter.js +78 -37
  53. package/esm/exporter.js.map +1 -1
  54. package/esm/exporter.test.js +48 -0
  55. package/esm/exporter.test.js.map +1 -1
  56. package/esm/framer.d.ts.map +1 -1
  57. package/esm/framer.js +27 -1788
  58. package/esm/framer.js.map +1 -1
  59. package/esm/index.d.ts.map +1 -1
  60. package/esm/index.js.map +1 -1
  61. package/esm/renamer.d.ts +12 -0
  62. package/esm/renamer.d.ts.map +1 -0
  63. package/esm/renamer.js +140 -0
  64. package/esm/renamer.js.map +1 -0
  65. package/esm/unframer-loader.d.ts.map +1 -1
  66. package/esm/unframer-loader.js +4 -3
  67. package/esm/unframer-loader.js.map +1 -1
  68. package/package.json +6 -4
  69. package/src/babel-plugin-imports.ts +441 -0
  70. package/src/cli.tsx +11 -52
  71. package/src/css.ts +3 -2
  72. package/src/esbuild.ts +24 -2
  73. package/src/exporter.test.ts +66 -0
  74. package/src/exporter.ts +95 -42
  75. package/src/framer.js +25 -1827
  76. package/src/index.ts +2 -0
  77. package/src/renamer.ts +184 -0
  78. package/src/unframer-loader.ts +7 -3
package/dist/framer.js CHANGED
@@ -102,7 +102,6 @@ exports.getFontsFromComponentPreset = getFontsFromComponentPreset;
102
102
  exports.getFontsFromSharedStyle = getFontsFromSharedStyle;
103
103
  exports.getLoadingLazyAtYPosition = getLoadingLazyAtYPosition;
104
104
  exports.getMeasurableCodeComponentChildren = getMeasurableCodeComponentChildren;
105
- exports.getMergedConstraintsProps = getMergedConstraintsProps;
106
105
  exports.getPropertyControls = getPropertyControls;
107
106
  exports.getWhereExpressionFromPathVariables = getWhereExpressionFromPathVariables;
108
107
  exports.gradientForShape = gradientForShape;
@@ -5709,9 +5708,9 @@ function velocityPerSecond(velocity, frameDuration) {
5709
5708
  return frameDuration ? velocity * (1e3 / frameDuration) : 0;
5710
5709
  }
5711
5710
  var velocitySampleDuration = 5;
5712
- function calcGeneratorVelocity(resolveValue2, t, current) {
5711
+ function calcGeneratorVelocity(resolveValue, t, current) {
5713
5712
  const prevT = Math.max(t - velocitySampleDuration, 0);
5714
- return velocityPerSecond(current - resolveValue2(prevT), t - prevT);
5713
+ return velocityPerSecond(current - resolveValue(prevT), t - prevT);
5715
5714
  }
5716
5715
  var durationKeys = ['duration', 'bounce',];
5717
5716
  var physicsKeys = ['stiffness', 'damping', 'mass',];
@@ -14631,7 +14630,7 @@ function steps(numSteps, direction = 'end') {
14631
14630
  return clamp(0, 1, rounded / numSteps);
14632
14631
  };
14633
14632
  }
14634
- // https :https://app.framerstatic.com/framer.7SGKTLCE.mjs
14633
+ // https :https://app.framerstatic.com/framer.NFOIY3CW.mjs
14635
14634
  init_chunk_QLPHEVXG();
14636
14635
  const react_11 = __importDefault(require("react"));
14637
14636
  const react_12 = require("react");
@@ -16107,41 +16106,6 @@ var require_hoist_non_react_statics_cjs = __commonJS({
16107
16106
  module.exports = hoistNonReactStatics;
16108
16107
  },
16109
16108
  });
16110
- var require_archy = __commonJS({
16111
- '../../../node_modules/archy/index.js'(exports, module) {
16112
- module.exports = function archy2(obj, prefix2, opts) {
16113
- if (prefix2 === void 0)
16114
- prefix2 = '';
16115
- if (!opts)
16116
- opts = {};
16117
- var chr = function (s) {
16118
- var chars = {
16119
- '\u2502': '|',
16120
- '\u2514': '`',
16121
- '\u251C': '+',
16122
- '\u2500': '-',
16123
- '\u252C': '-',
16124
- };
16125
- return opts.unicode === false ? chars[s] : s;
16126
- };
16127
- if (typeof obj === 'string') {
16128
- obj = {
16129
- label: obj,
16130
- };
16131
- }
16132
- var nodes = obj.nodes || [];
16133
- var lines = (obj.label || '').split('\n');
16134
- var splitter = '\n' + prefix2 + (nodes.length ? chr('\u2502') : ' ') + ' ';
16135
- return prefix2 + lines.join(splitter) + '\n' + nodes.map(function (node, ix) {
16136
- var last = ix === nodes.length - 1;
16137
- var more = node.nodes && node.nodes.length;
16138
- var prefix_ = prefix2 + (last ? ' ' : chr('\u2502')) + ' ';
16139
- return prefix2 + (last ? chr('\u2514') : chr('\u251C')) + chr('\u2500') + (more ? chr('\u252C') : chr('\u2500')) + ' ' +
16140
- archy2(node, prefix_, opts).slice(prefix2.length + 2);
16141
- }).join('');
16142
- };
16143
- },
16144
- });
16145
16109
  var require_fontfaceobserver_standalone = __commonJS({
16146
16110
  '../../../node_modules/fontfaceobserver/fontfaceobserver.standalone.js'(exports, module) {
16147
16111
  (function () {
@@ -22628,7 +22592,9 @@ function getConstraintValue(constraint, value, parentSize, viewport) {
22628
22592
  break;
22629
22593
  }
22630
22594
  }
22631
- if (value.endsWith('vh') && viewport) {
22595
+ if (value.endsWith('vh')) {
22596
+ if (!viewport)
22597
+ return constraintValueForUncalculatedViewport(constraint);
22632
22598
  switch (constraint) {
22633
22599
  case 'maxWidth':
22634
22600
  case 'minWidth':
@@ -22644,6 +22610,18 @@ function getConstraintValue(constraint, value, parentSize, viewport) {
22644
22610
  }
22645
22611
  return value;
22646
22612
  }
22613
+ function constraintValueForUncalculatedViewport(constraint) {
22614
+ switch (constraint) {
22615
+ case 'minWidth':
22616
+ case 'minHeight':
22617
+ return Number.NEGATIVE_INFINITY;
22618
+ case 'maxWidth':
22619
+ case 'maxHeight':
22620
+ return Number.POSITIVE_INFINITY;
22621
+ default:
22622
+ assertNever(constraint, 'unknown constraint key');
22623
+ }
22624
+ }
22647
22625
  function constrainHeight(height, values, parentSize, viewport) {
22648
22626
  if (values.minHeight) {
22649
22627
  height = Math.max(getConstraintValue('minHeight', values.minHeight, parentSize, viewport), height);
@@ -22689,16 +22667,6 @@ function pinnedOffset(start, end) {
22689
22667
  return null;
22690
22668
  return start + end;
22691
22669
  }
22692
- function getMergedConstraintsProps(props, constraints) {
22693
- const result = {};
22694
- if (props.constraints) {
22695
- result.constraints = Object.assign(Object.assign({}, props.constraints), constraints);
22696
- }
22697
- else {
22698
- Object.assign(result, constraints);
22699
- }
22700
- return result;
22701
- }
22702
22670
  function containsInvalidStringValues(props) {
22703
22671
  if (typeof props.right === 'string')
22704
22672
  return true;
@@ -23063,8 +23031,8 @@ var richTextLinkHoverStylesRule = `
23063
23031
  }
23064
23032
  `;
23065
23033
  var richTextLinkCurrentStylesRule = `
23066
- a[data-framer-page-link-current],
23067
- a[data-framer-page-link-current] span:not([data-text-fill]):not([data-nested-link]) {
23034
+ [data-framer-component-type="DeprecatedRichText"] a[data-framer-page-link-current],
23035
+ [data-framer-component-type="DeprecatedRichText"] a[data-framer-page-link-current] span:not([data-text-fill]):not([data-nested-link]) {
23068
23036
  font-family: var(--framer-link-current-font-family, var(--framer-link-font-family, var(--framer-font-family, Inter, Inter Placeholder, sans-serif)));
23069
23037
  font-style: var(--framer-link-current-font-style, var(--framer-link-font-style, var(--framer-font-style, normal)));
23070
23038
  font-weight: var(--framer-link-current-font-weight, var(--framer-link-font-weight, var(--framer-font-weight, 400)));
@@ -23075,8 +23043,8 @@ a[data-framer-page-link-current] span:not([data-text-fill]):not([data-nested-lin
23075
23043
  }
23076
23044
  `;
23077
23045
  var richTextLinkCurrentHoverStylesRule = `
23078
- a[data-framer-page-link-current]:hover,
23079
- a[data-framer-page-link-current]:hover span:not([data-text-fill]):not([data-nested-link]) {
23046
+ [data-framer-component-type="DeprecatedRichText"] a[data-framer-page-link-current]:hover,
23047
+ [data-framer-component-type="DeprecatedRichText"] a[data-framer-page-link-current]:hover span:not([data-text-fill]):not([data-nested-link]) {
23080
23048
  font-family: var(--framer-link-hover-font-family, var(--framer-link-current-font-family, var(--framer-link-font-family, var(--framer-font-family, Inter, Inter Placeholder, sans-serif))));
23081
23049
  font-style: var(--framer-link-hover-font-style, var(--framer-link-current-font-style, var(--framer-link-font-style, var(--framer-font-style, normal))));
23082
23050
  font-weight: var(--framer-link-hover-font-weight, var(--framer-link-current-font-weight, var(--framer-link-font-weight, var(--framer-font-weight, 400))));
@@ -37429,7 +37397,6 @@ var Fetcher = /* @__PURE__ */ React2.forwardRef(function Fetcher2(_j, ref) {
37429
37397
  exports.Fetcher = Fetcher;
37430
37398
  var callEach = (...fns) => fns.forEach((fn) => fn && fn());
37431
37399
  exports.callEach = callEach;
37432
- var import_archy = __toESM(require_archy(), 1);
37433
37400
  function getLogger(name) {
37434
37401
  return {
37435
37402
  trace(...args) {
@@ -37628,11 +37595,6 @@ function castDate(value) {
37628
37595
  }
37629
37596
  return null;
37630
37597
  }
37631
- function toDate(value) {
37632
- var _j;
37633
- const cast = castDate(value);
37634
- return (_j = (cast == null ? void 0 : cast.value)) !== null && _j !== void 0 ? _j : null;
37635
- }
37636
37598
  function castEnum(value) {
37637
37599
  switch (value == null ? void 0 : value.type) {
37638
37600
  case 'enum': {
@@ -38127,1431 +38089,6 @@ function compare(left, right, collation10) {
38127
38089
  }
38128
38090
  }
38129
38091
  }
38130
- var INDEX_IDENTIFIER = 'index';
38131
- var ScalarExpression = class {
38132
- static from(expression, schema) {
38133
- return convertExpression(expression, schema, void 0);
38134
- }
38135
- };
38136
- var ScalarIdentifier = class extends ScalarExpression {
38137
- constructor(schema, name, collection) {
38138
- var _j;
38139
- super();
38140
- this.schema = schema;
38141
- this.name = name;
38142
- this.collection = collection;
38143
- __publicField(this, 'definition');
38144
- if (name === INDEX_IDENTIFIER) {
38145
- this.definition = {
38146
- type: 'number',
38147
- isNullable: false,
38148
- };
38149
- }
38150
- else {
38151
- this.definition = (_j = schema[name]) !== null && _j !== void 0 ? _j : null;
38152
- }
38153
- }
38154
- stringify() {
38155
- return this.name;
38156
- }
38157
- equals(other) {
38158
- return other instanceof ScalarIdentifier && isEqual(this.definition, other.definition) && isEqual(other.name, this.name) &&
38159
- isEqual(other.collection, this.collection);
38160
- }
38161
- evaluate(item) {
38162
- var _j, _k, _l;
38163
- const name = this.name;
38164
- if (isUndefined(item) || name === INDEX_IDENTIFIER) {
38165
- throw new Error(`Can't evaluate identifier: ${name}`);
38166
- }
38167
- if (this.collection) {
38168
- const scopedName = `${this.collection}_${name}`;
38169
- return (_k = (_j = item.data[scopedName]) !== null && _j !== void 0 ? _j : item.data[name]) !== null && _k !== void 0 ? _k : null;
38170
- }
38171
- return (_l = item.data[name]) !== null && _l !== void 0 ? _l : null;
38172
- }
38173
- canEvaluate() {
38174
- return false;
38175
- }
38176
- };
38177
- var ScalarLiteralValue = class extends ScalarExpression {
38178
- constructor(definition, value) {
38179
- super();
38180
- this.definition = definition;
38181
- this.value = value;
38182
- }
38183
- stringify() {
38184
- return DatabaseValue.stringify(this.value);
38185
- }
38186
- static fromNull() {
38187
- return new ScalarLiteralValue(null, null);
38188
- }
38189
- static fromBoolean(value) {
38190
- return new ScalarLiteralValue({
38191
- type: 'boolean',
38192
- isNullable: isNull(value),
38193
- }, isNull(value) ? null : {
38194
- type: 'boolean',
38195
- value,
38196
- });
38197
- }
38198
- static fromDate(value) {
38199
- return new ScalarLiteralValue({
38200
- type: 'date',
38201
- isNullable: isNull(value),
38202
- }, isNull(value) ? null : {
38203
- type: 'date',
38204
- value,
38205
- });
38206
- }
38207
- static fromEnum(value) {
38208
- return new ScalarLiteralValue({
38209
- type: 'enum',
38210
- isNullable: isNull(value),
38211
- }, isNull(value) ? null : {
38212
- type: 'enum',
38213
- value,
38214
- });
38215
- }
38216
- static fromNumber(value) {
38217
- return new ScalarLiteralValue({
38218
- type: 'number',
38219
- isNullable: isNull(value),
38220
- }, isNull(value) ? null : {
38221
- type: 'number',
38222
- value,
38223
- });
38224
- }
38225
- static fromString(value) {
38226
- return new ScalarLiteralValue({
38227
- type: 'string',
38228
- isNullable: isNull(value),
38229
- }, isNull(value) ? null : {
38230
- type: 'string',
38231
- value,
38232
- });
38233
- }
38234
- equals(other) {
38235
- return other instanceof ScalarLiteralValue && isEqual(this.definition, other.definition) && isEqual(other.value, this.value);
38236
- }
38237
- evaluate() {
38238
- return this.value;
38239
- }
38240
- canEvaluate() {
38241
- return true;
38242
- }
38243
- };
38244
- var ScalarFunctionCall = class extends ScalarExpression {
38245
- constructor(argumentExpressions) {
38246
- super();
38247
- this.argumentExpressions = argumentExpressions;
38248
- __publicField(this, 'collation', {
38249
- type: 0,
38250
- /* CaseInsensitive */
38251
- });
38252
- }
38253
- getArgumentExpression(index) {
38254
- const argument = this.argumentExpressions[index];
38255
- if (isUndefined(argument)) {
38256
- throw new Error('Missing argument in function call');
38257
- }
38258
- return argument;
38259
- }
38260
- equals(other) {
38261
- return other instanceof ScalarFunctionCall && isEqual(this.constructor, other.constructor) &&
38262
- isEqual(this.argumentExpressions, other.argumentExpressions);
38263
- }
38264
- canEvaluate() {
38265
- return this.argumentExpressions.every((expression) => {
38266
- return expression.canEvaluate();
38267
- });
38268
- }
38269
- };
38270
- var ScalarFunctionCallContains = class extends ScalarFunctionCall {
38271
- constructor() {
38272
- super(...arguments);
38273
- __publicField(this, 'definition', ScalarFunctionCallContains.getDefinition());
38274
- __publicField(this, 'sourceExpression', this.getArgumentExpression(0));
38275
- __publicField(this, 'targetExpression', this.getArgumentExpression(1));
38276
- }
38277
- static getDefinition() {
38278
- return {
38279
- type: 'boolean',
38280
- isNullable: false,
38281
- };
38282
- }
38283
- stringify() {
38284
- return `CONTAINS(${this.sourceExpression.stringify()}, ${this.targetExpression.stringify()})`;
38285
- }
38286
- getValue(source, target) {
38287
- if (isNull(source) || source.type !== 'string')
38288
- return false;
38289
- if (isNull(target) || target.type !== 'string')
38290
- return false;
38291
- let sourceValue = source.value;
38292
- let targetValue = target.value;
38293
- if (this.collation.type === 0) {
38294
- sourceValue = sourceValue.toLowerCase();
38295
- targetValue = targetValue.toLowerCase();
38296
- }
38297
- return sourceValue.includes(targetValue);
38298
- }
38299
- evaluate(item) {
38300
- const source = this.sourceExpression.evaluate(item);
38301
- const target = this.targetExpression.evaluate(item);
38302
- return {
38303
- type: 'boolean',
38304
- value: this.getValue(source, target),
38305
- };
38306
- }
38307
- };
38308
- var ScalarFunctionCallStartsWith = class extends ScalarFunctionCall {
38309
- constructor() {
38310
- super(...arguments);
38311
- __publicField(this, 'definition', ScalarFunctionCallStartsWith.getDefinition());
38312
- __publicField(this, 'sourceExpression', this.getArgumentExpression(0));
38313
- __publicField(this, 'targetExpression', this.getArgumentExpression(1));
38314
- }
38315
- static getDefinition() {
38316
- return {
38317
- type: 'boolean',
38318
- isNullable: false,
38319
- };
38320
- }
38321
- stringify() {
38322
- return `STARTS_WITH(${this.sourceExpression.stringify()}, ${this.targetExpression.stringify()})`;
38323
- }
38324
- getValue(source, target) {
38325
- if (isNull(source) || source.type !== 'string')
38326
- return false;
38327
- if (isNull(target) || target.type !== 'string')
38328
- return false;
38329
- let sourceValue = source.value;
38330
- let targetValue = target.value;
38331
- if (this.collation.type === 0) {
38332
- sourceValue = sourceValue.toLowerCase();
38333
- targetValue = targetValue.toLowerCase();
38334
- }
38335
- return sourceValue.startsWith(targetValue);
38336
- }
38337
- evaluate(item) {
38338
- const source = this.sourceExpression.evaluate(item);
38339
- const target = this.targetExpression.evaluate(item);
38340
- return {
38341
- type: 'boolean',
38342
- value: this.getValue(source, target),
38343
- };
38344
- }
38345
- };
38346
- var ScalarFunctionCallEndsWith = class extends ScalarFunctionCall {
38347
- constructor() {
38348
- super(...arguments);
38349
- __publicField(this, 'definition', ScalarFunctionCallEndsWith.getDefinition());
38350
- __publicField(this, 'sourceExpression', this.getArgumentExpression(0));
38351
- __publicField(this, 'targetExpression', this.getArgumentExpression(1));
38352
- }
38353
- static getDefinition() {
38354
- return {
38355
- type: 'boolean',
38356
- isNullable: false,
38357
- };
38358
- }
38359
- stringify() {
38360
- return `ENDS_WITH(${this.sourceExpression.stringify()}, ${this.targetExpression.stringify()})`;
38361
- }
38362
- getValue(source, target) {
38363
- if (isNull(source) || source.type !== 'string')
38364
- return false;
38365
- if (isNull(target) || target.type !== 'string')
38366
- return false;
38367
- let sourceValue = source.value;
38368
- let targetValue = target.value;
38369
- if (this.collation.type === 0) {
38370
- sourceValue = sourceValue.toLowerCase();
38371
- targetValue = targetValue.toLowerCase();
38372
- }
38373
- return sourceValue.endsWith(targetValue);
38374
- }
38375
- evaluate(item) {
38376
- const source = this.sourceExpression.evaluate(item);
38377
- const target = this.targetExpression.evaluate(item);
38378
- return {
38379
- type: 'boolean',
38380
- value: this.getValue(source, target),
38381
- };
38382
- }
38383
- };
38384
- var ScalarCase = class extends ScalarExpression {
38385
- constructor(valueExpression, conditions, elseExpression) {
38386
- super();
38387
- this.valueExpression = valueExpression;
38388
- this.conditions = conditions;
38389
- this.elseExpression = elseExpression;
38390
- __publicField(this, 'definition');
38391
- __publicField(this, 'collation', {
38392
- type: 0,
38393
- /* CaseInsensitive */
38394
- });
38395
- const definitions = [];
38396
- for (const { thenExpression, } of conditions) {
38397
- definitions.push(thenExpression.definition);
38398
- }
38399
- if (elseExpression) {
38400
- definitions.push(elseExpression.definition);
38401
- }
38402
- this.definition = ScalarCase.getDefinition(definitions);
38403
- }
38404
- static getDefinition(definitions) {
38405
- var _j;
38406
- let result = null;
38407
- let isNullable = false;
38408
- for (const definition of definitions) {
38409
- result !== null && result !== void 0 ? result : (result = definition);
38410
- if (result && definition && result.type !== definition.type) {
38411
- throw new Error('Incompatible types in CASE expression');
38412
- }
38413
- isNullable || (isNullable = (_j = (definition == null ? void 0 : definition.isNullable)) !== null && _j !== void 0 ? _j : true);
38414
- }
38415
- return result
38416
- ? Object.assign(Object.assign({}, result), { isNullable }) : null;
38417
- }
38418
- stringify() {
38419
- let result = 'CASE';
38420
- if (this.valueExpression) {
38421
- result += ` ${this.valueExpression.stringify()}`;
38422
- }
38423
- for (const { whenExpression, thenExpression, } of this.conditions) {
38424
- result += ` WHEN ${whenExpression.stringify()} THEN ${thenExpression.stringify()}`;
38425
- }
38426
- if (this.elseExpression) {
38427
- result += ` ELSE ${this.elseExpression.stringify()}`;
38428
- }
38429
- result += ' END';
38430
- return result;
38431
- }
38432
- equals(other) {
38433
- return other instanceof ScalarCase && isEqual(this.valueExpression, other.valueExpression) &&
38434
- isEqual(this.conditions, other.conditions) && isEqual(this.elseExpression, other.elseExpression);
38435
- }
38436
- evaluate(item) {
38437
- var _j, _k;
38438
- var _a, _b;
38439
- const value = (_j = ((_a = this.valueExpression) == null ? void 0 : _a.evaluate(item))) !== null && _j !== void 0 ? _j : null;
38440
- for (const { whenExpression, thenExpression, } of this.conditions) {
38441
- const when = whenExpression.evaluate(item);
38442
- const isMatching = this.valueExpression ? DatabaseValue.equal(when, value, this.collation) : toBoolean(when);
38443
- if (isMatching)
38444
- return thenExpression.evaluate(item);
38445
- }
38446
- return (_k = ((_b = this.elseExpression) == null ? void 0 : _b.evaluate(item))) !== null && _k !== void 0 ? _k : null;
38447
- }
38448
- canEvaluate() {
38449
- const expressions = [];
38450
- if (this.valueExpression) {
38451
- expressions.push(this.valueExpression);
38452
- }
38453
- for (const condition of this.conditions) {
38454
- expressions.push(condition.whenExpression);
38455
- expressions.push(condition.thenExpression);
38456
- }
38457
- if (this.elseExpression) {
38458
- expressions.push(this.elseExpression);
38459
- }
38460
- return expressions.every((expression) => {
38461
- return expression.canEvaluate();
38462
- });
38463
- }
38464
- };
38465
- var ScalarCaseCondition = class {
38466
- constructor(whenExpression, thenExpression) {
38467
- this.whenExpression = whenExpression;
38468
- this.thenExpression = thenExpression;
38469
- }
38470
- };
38471
- var ScalarUnaryOperation = class extends ScalarExpression {
38472
- constructor(valueExpression) {
38473
- super();
38474
- this.valueExpression = valueExpression;
38475
- }
38476
- equals(other) {
38477
- return other instanceof ScalarUnaryOperation && isEqual(this.constructor, other.constructor) &&
38478
- isEqual(this.valueExpression, other.valueExpression);
38479
- }
38480
- canEvaluate() {
38481
- return this.valueExpression.canEvaluate();
38482
- }
38483
- };
38484
- var ScalarUnaryOperationNot = class extends ScalarUnaryOperation {
38485
- constructor() {
38486
- super(...arguments);
38487
- __publicField(this, 'definition', ScalarUnaryOperationNot.getDefinition());
38488
- }
38489
- static getDefinition() {
38490
- return {
38491
- type: 'boolean',
38492
- isNullable: false,
38493
- };
38494
- }
38495
- stringify() {
38496
- return `NOT ${this.valueExpression.stringify()}`;
38497
- }
38498
- evaluate(item) {
38499
- const value = this.valueExpression.evaluate(item);
38500
- return {
38501
- type: 'boolean',
38502
- value: !toBoolean(value),
38503
- };
38504
- }
38505
- };
38506
- var ScalarLogicalOperation = class extends ScalarExpression {
38507
- constructor(operandExpressions) {
38508
- super();
38509
- this.operandExpressions = operandExpressions;
38510
- __publicField(this, 'definition', ScalarLogicalOperation.getDefinition());
38511
- }
38512
- static getDefinition() {
38513
- return {
38514
- type: 'boolean',
38515
- isNullable: false,
38516
- };
38517
- }
38518
- stringify() {
38519
- return this.operandExpressions.map((expression) => expression.stringify()).join(' AND ');
38520
- }
38521
- equals(other) {
38522
- return other instanceof ScalarLogicalOperation && isEqual(this.constructor, other.constructor) &&
38523
- isEqual(this.operandExpressions, other.operandExpressions);
38524
- }
38525
- canEvaluate() {
38526
- return this.operandExpressions.every((expression) => {
38527
- return expression.canEvaluate();
38528
- });
38529
- }
38530
- };
38531
- var ScalarLogicalOperationAnd = class extends ScalarLogicalOperation {
38532
- constructor() {
38533
- super(...arguments);
38534
- __publicField(this, 'operator', 'AND');
38535
- }
38536
- evaluate(item) {
38537
- const result = this.operandExpressions.every((expression) => {
38538
- const value = expression.evaluate(item);
38539
- return toBoolean(value);
38540
- });
38541
- return {
38542
- type: 'boolean',
38543
- value: result,
38544
- };
38545
- }
38546
- };
38547
- var ScalarLogicalOperationOr = class extends ScalarLogicalOperation {
38548
- constructor() {
38549
- super(...arguments);
38550
- __publicField(this, 'operator', 'OR');
38551
- }
38552
- evaluate(item) {
38553
- const result = this.operandExpressions.some((expression) => {
38554
- const value = expression.evaluate(item);
38555
- return toBoolean(value);
38556
- });
38557
- return {
38558
- type: 'boolean',
38559
- value: result,
38560
- };
38561
- }
38562
- };
38563
- var ScalarComparison = class extends ScalarExpression {
38564
- constructor(leftExpression, rightExpression) {
38565
- super();
38566
- this.leftExpression = leftExpression;
38567
- this.rightExpression = rightExpression;
38568
- __publicField(this, 'definition', ScalarComparison.getDefinition());
38569
- __publicField(this, 'collation', {
38570
- type: 0,
38571
- /* CaseInsensitive */
38572
- });
38573
- }
38574
- static getDefinition() {
38575
- return {
38576
- type: 'boolean',
38577
- isNullable: false,
38578
- };
38579
- }
38580
- stringify() {
38581
- return `${this.leftExpression.stringify()} ${this.operator} ${this.rightExpression.stringify()}`;
38582
- }
38583
- equals(other) {
38584
- return other instanceof ScalarComparison && isEqual(this.constructor, other.constructor) &&
38585
- isEqual(this.leftExpression, other.leftExpression) && isEqual(this.rightExpression, other.rightExpression);
38586
- }
38587
- canEvaluate() {
38588
- return this.leftExpression.canEvaluate() && this.rightExpression.canEvaluate();
38589
- }
38590
- };
38591
- var ScalarComparisonEquals = class extends ScalarComparison {
38592
- constructor() {
38593
- super(...arguments);
38594
- __publicField(this, 'operator', '=');
38595
- }
38596
- evaluate(item) {
38597
- const leftValue = this.leftExpression.evaluate(item);
38598
- const rightValue = this.rightExpression.evaluate(item);
38599
- return {
38600
- type: 'boolean',
38601
- value: DatabaseValue.equal(leftValue, rightValue, this.collation),
38602
- };
38603
- }
38604
- };
38605
- var ScalarComparisonNotEquals = class extends ScalarComparison {
38606
- constructor() {
38607
- super(...arguments);
38608
- __publicField(this, 'operator', '!=');
38609
- }
38610
- evaluate(item) {
38611
- const leftValue = this.leftExpression.evaluate(item);
38612
- const rightValue = this.rightExpression.evaluate(item);
38613
- return {
38614
- type: 'boolean',
38615
- value: !DatabaseValue.equal(leftValue, rightValue, this.collation),
38616
- };
38617
- }
38618
- };
38619
- var ScalarComparisonLessThan = class extends ScalarComparison {
38620
- constructor() {
38621
- super(...arguments);
38622
- __publicField(this, 'operator', '<');
38623
- }
38624
- evaluate(item) {
38625
- const leftValue = this.leftExpression.evaluate(item);
38626
- const rightValue = this.rightExpression.evaluate(item);
38627
- return {
38628
- type: 'boolean',
38629
- value: DatabaseValue.lessThan(leftValue, rightValue, this.collation),
38630
- };
38631
- }
38632
- };
38633
- var ScalarComparisonLessThanOrEqual = class extends ScalarComparison {
38634
- constructor() {
38635
- super(...arguments);
38636
- __publicField(this, 'operator', '<=');
38637
- }
38638
- evaluate(item) {
38639
- const leftValue = this.leftExpression.evaluate(item);
38640
- const rightValue = this.rightExpression.evaluate(item);
38641
- return {
38642
- type: 'boolean',
38643
- value: DatabaseValue.lessThanOrEqual(leftValue, rightValue, this.collation),
38644
- };
38645
- }
38646
- };
38647
- var ScalarComparisonGreaterThan = class extends ScalarComparison {
38648
- constructor() {
38649
- super(...arguments);
38650
- __publicField(this, 'operator', '>');
38651
- }
38652
- evaluate(item) {
38653
- const leftValue = this.leftExpression.evaluate(item);
38654
- const rightValue = this.rightExpression.evaluate(item);
38655
- return {
38656
- type: 'boolean',
38657
- value: DatabaseValue.greaterThan(leftValue, rightValue, this.collation),
38658
- };
38659
- }
38660
- };
38661
- var ScalarComparisonGreaterThanOrEqual = class extends ScalarComparison {
38662
- constructor() {
38663
- super(...arguments);
38664
- __publicField(this, 'operator', '>=');
38665
- }
38666
- evaluate(item) {
38667
- const leftValue = this.leftExpression.evaluate(item);
38668
- const rightValue = this.rightExpression.evaluate(item);
38669
- return {
38670
- type: 'boolean',
38671
- value: DatabaseValue.greaterThanOrEqual(leftValue, rightValue, this.collation),
38672
- };
38673
- }
38674
- };
38675
- var ScalarTypeCast = class extends ScalarExpression {
38676
- constructor(valueExpression) {
38677
- super();
38678
- this.valueExpression = valueExpression;
38679
- }
38680
- stringify() {
38681
- return `CAST(${this.valueExpression.stringify()} AS ${this.dataType})`;
38682
- }
38683
- equals(other) {
38684
- return other instanceof ScalarTypeCast && isEqual(this.constructor, other.constructor) &&
38685
- isEqual(this.valueExpression, other.valueExpression);
38686
- }
38687
- canEvaluate() {
38688
- return this.valueExpression.canEvaluate();
38689
- }
38690
- };
38691
- var ScalarTypeCastBoolean = class extends ScalarTypeCast {
38692
- constructor() {
38693
- super(...arguments);
38694
- __publicField(this, 'dataType', 'BOOLEAN');
38695
- __publicField(this, 'definition', ScalarTypeCastBoolean.getDefinition());
38696
- }
38697
- static getDefinition() {
38698
- return {
38699
- type: 'boolean',
38700
- isNullable: true,
38701
- };
38702
- }
38703
- evaluate(item) {
38704
- const value = this.valueExpression.evaluate(item);
38705
- return DatabaseValue.cast(value, this.definition);
38706
- }
38707
- };
38708
- var ScalarTypeCastDate = class extends ScalarTypeCast {
38709
- constructor() {
38710
- super(...arguments);
38711
- __publicField(this, 'dataType', 'DATE');
38712
- __publicField(this, 'definition', ScalarTypeCastDate.getDefinition());
38713
- }
38714
- static getDefinition() {
38715
- return {
38716
- type: 'date',
38717
- isNullable: true,
38718
- };
38719
- }
38720
- evaluate(item) {
38721
- const value = this.valueExpression.evaluate(item);
38722
- return DatabaseValue.cast(value, this.definition);
38723
- }
38724
- };
38725
- var ScalarTypeCastNumber = class extends ScalarTypeCast {
38726
- constructor() {
38727
- super(...arguments);
38728
- __publicField(this, 'dataType', 'NUMBER');
38729
- __publicField(this, 'definition', ScalarTypeCastNumber.getDefinition());
38730
- }
38731
- static getDefinition() {
38732
- return {
38733
- type: 'number',
38734
- isNullable: true,
38735
- };
38736
- }
38737
- evaluate(item) {
38738
- const value = this.valueExpression.evaluate(item);
38739
- return DatabaseValue.cast(value, this.definition);
38740
- }
38741
- };
38742
- var ScalarTypeCastString = class extends ScalarTypeCast {
38743
- constructor() {
38744
- super(...arguments);
38745
- __publicField(this, 'dataType', 'STRING');
38746
- __publicField(this, 'definition', ScalarTypeCastString.getDefinition());
38747
- }
38748
- static getDefinition() {
38749
- return {
38750
- type: 'string',
38751
- isNullable: true,
38752
- };
38753
- }
38754
- evaluate(item) {
38755
- const value = this.valueExpression.evaluate(item);
38756
- return DatabaseValue.cast(value, this.definition);
38757
- }
38758
- };
38759
- function convertExpression(expression, schema, typeAffinity) {
38760
- const scalarExpression = getScalarExpression(expression, schema, typeAffinity);
38761
- const isLiteralValue = scalarExpression instanceof ScalarLiteralValue;
38762
- if (scalarExpression.canEvaluate() && !isLiteralValue) {
38763
- const value = scalarExpression.evaluate();
38764
- return new ScalarLiteralValue(scalarExpression.definition, value);
38765
- }
38766
- return scalarExpression;
38767
- }
38768
- function getScalarExpression(expression, schema, typeAffinity) {
38769
- switch (expression.type) {
38770
- case 'Identifier':
38771
- return convertIdentifier(expression, schema);
38772
- case 'LiteralValue':
38773
- return convertLiteralValue(expression, typeAffinity);
38774
- case 'FunctionCall':
38775
- return convertFunctionCall(expression, schema);
38776
- case 'Case':
38777
- return convertCase(expression, schema, typeAffinity);
38778
- case 'UnaryOperation':
38779
- return convertUnaryOperation(expression, schema);
38780
- case 'BinaryOperation':
38781
- return convertBinaryOperation(expression, schema);
38782
- case 'TypeCast':
38783
- return convertTypeCast(expression, schema);
38784
- default:
38785
- throw new Error(`Unsupported expression: ${JSON.stringify(expression)}`);
38786
- }
38787
- }
38788
- function convertIdentifier(expression, schema) {
38789
- return new ScalarIdentifier(schema, expression.name, expression.collection);
38790
- }
38791
- function convertLiteralValue(expression, typeAffinity) {
38792
- var _a;
38793
- const scalarExpression = getScalarLiteralValue(expression.value);
38794
- switch (typeAffinity == null ? void 0 : typeAffinity.type) {
38795
- case 'boolean': {
38796
- const value = toBoolean(scalarExpression.value);
38797
- return ScalarLiteralValue.fromBoolean(value);
38798
- }
38799
- case 'date': {
38800
- const value = toDate(scalarExpression.value);
38801
- return ScalarLiteralValue.fromDate(value);
38802
- }
38803
- case 'enum': {
38804
- if (((_a = scalarExpression.value) == null ? void 0 : _a.type) === 'string') {
38805
- return ScalarLiteralValue.fromEnum(scalarExpression.value.value);
38806
- }
38807
- return scalarExpression;
38808
- }
38809
- case 'number': {
38810
- const value = toNumber2(scalarExpression.value);
38811
- return ScalarLiteralValue.fromNumber(value);
38812
- }
38813
- case 'string': {
38814
- const value = toString(scalarExpression.value);
38815
- return ScalarLiteralValue.fromString(value);
38816
- }
38817
- }
38818
- return scalarExpression;
38819
- }
38820
- function getScalarLiteralValue(value) {
38821
- if (isBoolean(value)) {
38822
- return ScalarLiteralValue.fromBoolean(value);
38823
- }
38824
- if (isValidDate(value)) {
38825
- const string = value.toISOString();
38826
- return ScalarLiteralValue.fromDate(string);
38827
- }
38828
- if (isNumber2(value)) {
38829
- return ScalarLiteralValue.fromNumber(value);
38830
- }
38831
- if (isString2(value)) {
38832
- return ScalarLiteralValue.fromString(value);
38833
- }
38834
- return ScalarLiteralValue.fromNull();
38835
- }
38836
- function convertFunctionCall(expression, schema) {
38837
- const argumentExpressions = expression.arguments.map((argument) => {
38838
- return convertExpression(argument, schema, void 0);
38839
- });
38840
- switch (expression.functionName) {
38841
- case 'CONTAINS':
38842
- return new ScalarFunctionCallContains(argumentExpressions);
38843
- case 'STARTS_WITH':
38844
- return new ScalarFunctionCallStartsWith(argumentExpressions);
38845
- case 'ENDS_WITH':
38846
- return new ScalarFunctionCallEndsWith(argumentExpressions);
38847
- default:
38848
- throw new Error(`Unsupported function name: ${expression.functionName}`);
38849
- }
38850
- }
38851
- function convertCase(expression, schema, typeAffinity) {
38852
- const valueExpression = expression.value && convertExpression(expression.value, schema, void 0);
38853
- const valueTypeAffinity = expression.value && getExpressionType(expression.value, schema);
38854
- const conditions = expression.conditions.map((condition) => {
38855
- const whenExpression = convertExpression(condition.when, schema, valueTypeAffinity);
38856
- const thenExpression = convertExpression(condition.then, schema, typeAffinity);
38857
- return new ScalarCaseCondition(whenExpression, thenExpression);
38858
- });
38859
- const elseExpression = expression.else && convertExpression(expression.else, schema, typeAffinity);
38860
- return new ScalarCase(valueExpression, conditions, elseExpression);
38861
- }
38862
- function convertUnaryOperation(expression, schema) {
38863
- const valueExpression = convertExpression(expression.value, schema, void 0);
38864
- switch (expression.operator) {
38865
- case 'not':
38866
- return getScalarUnaryOperationNot(valueExpression);
38867
- default:
38868
- throw new Error(`Unsupported unary operator: ${expression.operator}`);
38869
- }
38870
- }
38871
- function getScalarUnaryOperationNot(valueExpression) {
38872
- var _a;
38873
- if (valueExpression instanceof ScalarUnaryOperationNot) {
38874
- const innerExpression = valueExpression.valueExpression;
38875
- if (((_a = innerExpression.definition) == null ? void 0 : _a.type) === 'boolean') {
38876
- return innerExpression;
38877
- }
38878
- return new ScalarTypeCastBoolean(innerExpression);
38879
- }
38880
- if (valueExpression instanceof ScalarComparisonEquals) {
38881
- const { leftExpression, rightExpression, } = valueExpression;
38882
- return new ScalarComparisonNotEquals(leftExpression, rightExpression);
38883
- }
38884
- if (valueExpression instanceof ScalarComparisonNotEquals) {
38885
- const { leftExpression, rightExpression, } = valueExpression;
38886
- return new ScalarComparisonEquals(leftExpression, rightExpression);
38887
- }
38888
- if (valueExpression instanceof ScalarComparisonLessThan) {
38889
- const { leftExpression, rightExpression, } = valueExpression;
38890
- return new ScalarComparisonGreaterThanOrEqual(leftExpression, rightExpression);
38891
- }
38892
- if (valueExpression instanceof ScalarComparisonLessThanOrEqual) {
38893
- const { leftExpression, rightExpression, } = valueExpression;
38894
- return new ScalarComparisonGreaterThan(leftExpression, rightExpression);
38895
- }
38896
- if (valueExpression instanceof ScalarComparisonGreaterThan) {
38897
- const { leftExpression, rightExpression, } = valueExpression;
38898
- return new ScalarComparisonLessThanOrEqual(leftExpression, rightExpression);
38899
- }
38900
- if (valueExpression instanceof ScalarComparisonGreaterThanOrEqual) {
38901
- const { leftExpression, rightExpression, } = valueExpression;
38902
- return new ScalarComparisonLessThan(leftExpression, rightExpression);
38903
- }
38904
- if (valueExpression instanceof ScalarLogicalOperationAnd) {
38905
- const { operandExpressions, } = valueExpression;
38906
- const notExpressions = operandExpressions.map(getScalarUnaryOperationNot);
38907
- return new ScalarLogicalOperationOr(notExpressions);
38908
- }
38909
- if (valueExpression instanceof ScalarLogicalOperationAnd) {
38910
- const { operandExpressions, } = valueExpression;
38911
- const notExpressions = operandExpressions.map(getScalarUnaryOperationNot);
38912
- return new ScalarLogicalOperationAnd(notExpressions);
38913
- }
38914
- return new ScalarUnaryOperationNot(valueExpression);
38915
- }
38916
- function getTypeAffinityForBinaryOperation(expression, schema) {
38917
- if (expression.operator !== 'and' && expression.operator !== 'or') {
38918
- return getExpressionType(expression.left, schema) || getExpressionType(expression.right, schema);
38919
- }
38920
- }
38921
- function convertBinaryOperation(expression, schema) {
38922
- const typeAffinity = getTypeAffinityForBinaryOperation(expression, schema);
38923
- const leftExpression = convertExpression(expression.left, schema, typeAffinity);
38924
- const rightExpression = convertExpression(expression.right, schema, typeAffinity);
38925
- switch (expression.operator) {
38926
- case 'and':
38927
- return getScalarLogicalOperationAnd(leftExpression, rightExpression);
38928
- case 'or':
38929
- return getScalarLogicalOperationOr(leftExpression, rightExpression);
38930
- case '==':
38931
- return getScalarComparisonEquals(leftExpression, rightExpression);
38932
- case '!=':
38933
- return getScalarComparisonNotEquals(leftExpression, rightExpression);
38934
- case '<':
38935
- return getScalarComparisonLessThan(leftExpression, rightExpression);
38936
- case '<=':
38937
- return getScalarComparisonLessThanOrEqual(leftExpression, rightExpression);
38938
- case '>':
38939
- return getScalarComparisonGreaterThan(leftExpression, rightExpression);
38940
- case '>=':
38941
- return getScalarComparisonGreaterThanOrEqual(leftExpression, rightExpression);
38942
- default:
38943
- throw new Error(`Unsupported binary operator: ${expression.operator}`);
38944
- }
38945
- }
38946
- function getScalarLogicalOperationAnd(leftExpression, rightExpression) {
38947
- const operandExpressions = [];
38948
- if (leftExpression instanceof ScalarLogicalOperationAnd) {
38949
- operandExpressions.push(...leftExpression.operandExpressions);
38950
- }
38951
- else {
38952
- operandExpressions.push(leftExpression);
38953
- }
38954
- if (rightExpression instanceof ScalarLogicalOperationAnd) {
38955
- operandExpressions.push(...rightExpression.operandExpressions);
38956
- }
38957
- else {
38958
- operandExpressions.push(rightExpression);
38959
- }
38960
- return new ScalarLogicalOperationAnd(operandExpressions);
38961
- }
38962
- function getScalarLogicalOperationOr(leftExpression, rightExpression) {
38963
- const operandExpressions = [];
38964
- if (leftExpression instanceof ScalarLogicalOperationOr) {
38965
- operandExpressions.push(...leftExpression.operandExpressions);
38966
- }
38967
- else {
38968
- operandExpressions.push(leftExpression);
38969
- }
38970
- if (rightExpression instanceof ScalarLogicalOperationOr) {
38971
- operandExpressions.push(...rightExpression.operandExpressions);
38972
- }
38973
- else {
38974
- operandExpressions.push(rightExpression);
38975
- }
38976
- return new ScalarLogicalOperationOr(operandExpressions);
38977
- }
38978
- function getScalarComparisonEquals(leftExpression, rightExpression) {
38979
- const isLeftIdentifier = leftExpression instanceof ScalarIdentifier;
38980
- const isRightIdentifier = rightExpression instanceof ScalarIdentifier;
38981
- if (isRightIdentifier && !isLeftIdentifier) {
38982
- return new ScalarComparisonEquals(rightExpression, leftExpression);
38983
- }
38984
- return new ScalarComparisonEquals(leftExpression, rightExpression);
38985
- }
38986
- function getScalarComparisonNotEquals(leftExpression, rightExpression) {
38987
- const isLeftIdentifier = leftExpression instanceof ScalarIdentifier;
38988
- const isRightIdentifier = rightExpression instanceof ScalarIdentifier;
38989
- if (isRightIdentifier && !isLeftIdentifier) {
38990
- return new ScalarComparisonNotEquals(rightExpression, leftExpression);
38991
- }
38992
- return new ScalarComparisonNotEquals(leftExpression, rightExpression);
38993
- }
38994
- function getScalarComparisonLessThan(leftExpression, rightExpression) {
38995
- const isLeftIdentifier = leftExpression instanceof ScalarIdentifier;
38996
- const isRightIdentifier = rightExpression instanceof ScalarIdentifier;
38997
- if (isRightIdentifier && !isLeftIdentifier) {
38998
- return new ScalarComparisonGreaterThan(rightExpression, leftExpression);
38999
- }
39000
- return new ScalarComparisonLessThan(leftExpression, rightExpression);
39001
- }
39002
- function getScalarComparisonLessThanOrEqual(leftExpression, rightExpression) {
39003
- const isLeftIdentifier = leftExpression instanceof ScalarIdentifier;
39004
- const isRightIdentifier = rightExpression instanceof ScalarIdentifier;
39005
- if (isRightIdentifier && !isLeftIdentifier) {
39006
- return new ScalarComparisonGreaterThanOrEqual(rightExpression, leftExpression);
39007
- }
39008
- return new ScalarComparisonLessThanOrEqual(leftExpression, rightExpression);
39009
- }
39010
- function getScalarComparisonGreaterThan(leftExpression, rightExpression) {
39011
- const isLeftIdentifier = leftExpression instanceof ScalarIdentifier;
39012
- const isRightIdentifier = rightExpression instanceof ScalarIdentifier;
39013
- if (isRightIdentifier && !isLeftIdentifier) {
39014
- return new ScalarComparisonLessThan(rightExpression, leftExpression);
39015
- }
39016
- return new ScalarComparisonGreaterThan(leftExpression, rightExpression);
39017
- }
39018
- function getScalarComparisonGreaterThanOrEqual(leftExpression, rightExpression) {
39019
- const isLeftIdentifier = leftExpression instanceof ScalarIdentifier;
39020
- const isRightIdentifier = rightExpression instanceof ScalarIdentifier;
39021
- if (isRightIdentifier && !isLeftIdentifier) {
39022
- return new ScalarComparisonLessThanOrEqual(rightExpression, leftExpression);
39023
- }
39024
- return new ScalarComparisonGreaterThanOrEqual(leftExpression, rightExpression);
39025
- }
39026
- function convertTypeCast(expression, schema) {
39027
- const valueExpression = convertExpression(expression.value, schema, void 0);
39028
- switch (expression.dataType) {
39029
- case 'BOOLEAN':
39030
- return getScalarTypeCastBoolean(valueExpression);
39031
- case 'DATE':
39032
- return getScalarTypeCastDate(valueExpression);
39033
- case 'NUMBER':
39034
- return getScalarTypeCastNumber(valueExpression);
39035
- case 'STRING':
39036
- return getScalarTypeCastString(valueExpression);
39037
- default:
39038
- throw new Error(`Unsupported data type: ${expression.dataType}`);
39039
- }
39040
- }
39041
- function getScalarTypeCastBoolean(valueExpression) {
39042
- var _a;
39043
- if (((_a = valueExpression.definition) == null ? void 0 : _a.type) === 'boolean') {
39044
- return valueExpression;
39045
- }
39046
- return new ScalarTypeCastBoolean(valueExpression);
39047
- }
39048
- function getScalarTypeCastDate(valueExpression) {
39049
- var _a;
39050
- if (((_a = valueExpression.definition) == null ? void 0 : _a.type) === 'date') {
39051
- return valueExpression;
39052
- }
39053
- return new ScalarTypeCastDate(valueExpression);
39054
- }
39055
- function getScalarTypeCastNumber(valueExpression) {
39056
- var _a;
39057
- if (((_a = valueExpression.definition) == null ? void 0 : _a.type) === 'number') {
39058
- return valueExpression;
39059
- }
39060
- return new ScalarTypeCastNumber(valueExpression);
39061
- }
39062
- function getScalarTypeCastString(valueExpression) {
39063
- var _a;
39064
- if (((_a = valueExpression.definition) == null ? void 0 : _a.type) === 'string') {
39065
- return valueExpression;
39066
- }
39067
- return new ScalarTypeCastString(valueExpression);
39068
- }
39069
- function getExpressionType(expression, schema) {
39070
- switch (expression.type) {
39071
- case 'Identifier':
39072
- return getIdentifierType(expression, schema);
39073
- case 'LiteralValue':
39074
- return void 0;
39075
- case 'FunctionCall':
39076
- return getFunctionCallType(expression);
39077
- case 'Case':
39078
- return getCaseType(expression, schema);
39079
- case 'UnaryOperation':
39080
- return getUnaryOperationType(expression);
39081
- case 'BinaryOperation':
39082
- return getBinaryOperationType(expression);
39083
- case 'TypeCast':
39084
- return getTypeCastType(expression);
39085
- default:
39086
- throw new Error(`Unsupported expression: ${JSON.stringify(expression)}`);
39087
- }
39088
- }
39089
- function getIdentifierType(expression, schema) {
39090
- return schema[expression.name];
39091
- }
39092
- function getFunctionCallType(expression) {
39093
- switch (expression.functionName) {
39094
- case 'CONTAINS':
39095
- return ScalarFunctionCallContains.getDefinition();
39096
- case 'STARTS_WITH':
39097
- return ScalarFunctionCallStartsWith.getDefinition();
39098
- case 'ENDS_WITH':
39099
- return ScalarFunctionCallEndsWith.getDefinition();
39100
- default:
39101
- throw new Error(`Unsupported function name: ${expression.functionName}`);
39102
- }
39103
- }
39104
- function getCaseType(expression, schema) {
39105
- var _j;
39106
- const definitions = [];
39107
- for (const condition of expression.conditions) {
39108
- const type = getExpressionType(condition.then, schema);
39109
- if (!isUndefined(type))
39110
- definitions.push(type);
39111
- }
39112
- if (expression.else) {
39113
- const type = getExpressionType(expression.else, schema);
39114
- if (!isUndefined(type))
39115
- definitions.push(type);
39116
- }
39117
- return (_j = ScalarCase.getDefinition(definitions)) !== null && _j !== void 0 ? _j : void 0;
39118
- }
39119
- function getUnaryOperationType(expression) {
39120
- switch (expression.operator) {
39121
- case 'not':
39122
- return ScalarUnaryOperationNot.getDefinition();
39123
- default:
39124
- throw new Error(`Unsupported unary operator: ${expression.operator}`);
39125
- }
39126
- }
39127
- function getBinaryOperationType(expression) {
39128
- switch (expression.operator) {
39129
- case 'and':
39130
- case 'or':
39131
- return ScalarLogicalOperation.getDefinition();
39132
- case '==':
39133
- case '!=':
39134
- case '<':
39135
- case '<=':
39136
- case '>':
39137
- case '>=':
39138
- return ScalarComparison.getDefinition();
39139
- default:
39140
- throw new Error(`Unsupported binary operator: ${expression.operator}`);
39141
- }
39142
- }
39143
- function getTypeCastType(expression) {
39144
- switch (expression.dataType) {
39145
- case 'BOOLEAN':
39146
- return ScalarTypeCastBoolean.getDefinition();
39147
- case 'DATE':
39148
- return ScalarTypeCastDate.getDefinition();
39149
- case 'NUMBER':
39150
- return ScalarTypeCastNumber.getDefinition();
39151
- case 'STRING':
39152
- return ScalarTypeCastString.getDefinition();
39153
- default:
39154
- throw new Error(`Unsupported data type: ${expression.dataType}`);
39155
- }
39156
- }
39157
- function stringifyExecutionTime(self2, total) {
39158
- return `(self: ${self2}ms${total ? `, total: ${total}ms` : ''})`;
39159
- }
39160
- function stringifyItems(items) {
39161
- return `(items: ${items})`;
39162
- }
39163
- var QueryPlan = class {
39164
- constructor() {
39165
- __publicField(this, 'executionTime', 0);
39166
- __publicField(this, 'itemCount', 0);
39167
- }
39168
- execute() {
39169
- return __awaiter(this, void 0, void 0, function* () {
39170
- const start = performance.now();
39171
- const result = yield this._execute();
39172
- this.executionTime = performance.now() - start;
39173
- this.itemCount = result.length;
39174
- return result;
39175
- });
39176
- }
39177
- };
39178
- var ScanCollectionPlan = class extends QueryPlan {
39179
- constructor(collection, alias) {
39180
- super();
39181
- this.collection = collection;
39182
- this.alias = alias;
39183
- }
39184
- inspect() {
39185
- return {
39186
- label: `ScanCollectionPlan ${stringifyExecutionTime(this.executionTime)} ${stringifyItems(this.itemCount)}`,
39187
- };
39188
- }
39189
- _execute() {
39190
- return __awaiter(this, void 0, void 0, function* () {
39191
- const items = yield this.collection.scanItems();
39192
- if (isUndefined(this.alias))
39193
- return items;
39194
- return items.map((item) => {
39195
- const data2 = Object.assign({}, item.data);
39196
- const dataEntries = Object.entries(data2);
39197
- for (const [key7, value,] of dataEntries) {
39198
- data2[`${this.alias}_${key7}`] = value;
39199
- }
39200
- return {
39201
- pointer: item.pointer,
39202
- data: data2,
39203
- };
39204
- });
39205
- });
39206
- }
39207
- };
39208
- var LeftJoinPlan = class extends QueryPlan {
39209
- constructor(leftPlan, rightPlan, constraint) {
39210
- super();
39211
- this.leftPlan = leftPlan;
39212
- this.rightPlan = rightPlan;
39213
- this.constraint = constraint;
39214
- }
39215
- inspect() {
39216
- var _j, _k;
39217
- const childPlansTime = Math.max((_j = this.leftPlan.executionTime) !== null && _j !== void 0 ? _j : 0, (_k = this.rightPlan.executionTime) !== null && _k !== void 0 ? _k : 0);
39218
- return {
39219
- label: `LeftJoinPlan ${stringifyExecutionTime(this.executionTime - childPlansTime, this.executionTime)} ${stringifyItems(this.itemCount)}`,
39220
- nodes: [this.leftPlan.inspect(), this.rightPlan.inspect(),],
39221
- };
39222
- }
39223
- _execute() {
39224
- return __awaiter(this, void 0, void 0, function* () {
39225
- var _a;
39226
- const leftItems = yield this.leftPlan.execute();
39227
- const rightItems = yield this.rightPlan.execute();
39228
- const result = [];
39229
- for (const leftItem of leftItems) {
39230
- let hasMatch = false;
39231
- for (const rightItem of rightItems) {
39232
- const combinedItem = {
39233
- pointer: leftItem.pointer,
39234
- data: Object.assign(Object.assign({}, leftItem.data), rightItem.data),
39235
- };
39236
- if ((_a = this.constraint.evaluate(combinedItem)) == null ? void 0 : _a.value) {
39237
- result.push(combinedItem);
39238
- hasMatch = true;
39239
- }
39240
- }
39241
- if (!hasMatch) {
39242
- result.push(leftItem);
39243
- }
39244
- }
39245
- return result;
39246
- });
39247
- }
39248
- };
39249
- var LookupIndexPlan = class extends QueryPlan {
39250
- constructor(index, query) {
39251
- super();
39252
- this.index = index;
39253
- this.query = query;
39254
- }
39255
- inspect() {
39256
- const queries = [];
39257
- const stringifyDatabaseLookupType = (indexLookup) => {
39258
- switch (indexLookup.type) {
39259
- case 'All':
39260
- return indexLookup.type;
39261
- case 'Equals':
39262
- case 'NotEquals':
39263
- case 'LessThan':
39264
- case 'GreaterThan':
39265
- case 'Contains':
39266
- case 'StartsWith':
39267
- case 'EndsWith':
39268
- return `${indexLookup.type} ${DatabaseValue.stringify(indexLookup.value)}`;
39269
- default: {
39270
- assertNever(indexLookup);
39271
- }
39272
- }
39273
- };
39274
- for (let i = 0; i < this.index.fields.length; i++) {
39275
- const field = this.index.fields[i];
39276
- const query = this.query[i];
39277
- if (!field || field.type !== 'Identifier')
39278
- continue;
39279
- if (!query || query.type === 'All')
39280
- continue;
39281
- queries.push(`${field.name} ${stringifyDatabaseLookupType(query)}`);
39282
- }
39283
- return {
39284
- label: `LookupIndexPlan(${queries.join(', ')}) ${stringifyExecutionTime(this.executionTime)} ${stringifyItems(this.itemCount)}`,
39285
- };
39286
- }
39287
- _execute() {
39288
- return __awaiter(this, void 0, void 0, function* () {
39289
- return this.index.lookupItems(this.query);
39290
- });
39291
- }
39292
- };
39293
- var UnionPlan = class extends QueryPlan {
39294
- constructor(childPlans) {
39295
- super();
39296
- this.childPlans = childPlans;
39297
- }
39298
- inspect() {
39299
- const childPlansTime = Math.max(...this.childPlans.map((childPlan) => { var _j; return (_j = childPlan.executionTime) !== null && _j !== void 0 ? _j : 0; }));
39300
- return {
39301
- label: `UnionPlan ${stringifyExecutionTime(this.executionTime - childPlansTime, this.executionTime)} ${stringifyItems(this.itemCount)}`,
39302
- nodes: this.childPlans.map((childPlan) => childPlan.inspect()),
39303
- };
39304
- }
39305
- _execute() {
39306
- return __awaiter(this, void 0, void 0, function* () {
39307
- var _j;
39308
- const childItemMaps = yield Promise.all(this.childPlans.map((childPlan) => __awaiter(this, void 0, void 0, function* () {
39309
- const items = yield childPlan.execute();
39310
- return new DatabaseItemMap(items);
39311
- })));
39312
- let result;
39313
- for (const itemMap of childItemMaps) {
39314
- if (result) {
39315
- result = result.union(itemMap);
39316
- }
39317
- else {
39318
- result = itemMap;
39319
- }
39320
- }
39321
- return (_j = (result == null ? void 0 : result.items())) !== null && _j !== void 0 ? _j : [];
39322
- });
39323
- }
39324
- };
39325
- var IntersectionPlan = class extends QueryPlan {
39326
- constructor(childPlans) {
39327
- super();
39328
- this.childPlans = childPlans;
39329
- }
39330
- inspect() {
39331
- const childPlansTime = Math.max(...this.childPlans.map((childPlan) => { var _j; return (_j = childPlan.executionTime) !== null && _j !== void 0 ? _j : 0; }));
39332
- return {
39333
- label: `IntersectionPlan ${stringifyExecutionTime(this.executionTime - childPlansTime, this.executionTime)} ${stringifyItems(this.itemCount)} ${stringifyItems(this.itemCount)}`,
39334
- nodes: this.childPlans.map((childPlan) => childPlan.inspect()),
39335
- };
39336
- }
39337
- _execute() {
39338
- return __awaiter(this, void 0, void 0, function* () {
39339
- var _j;
39340
- const childItemMaps = yield Promise.all(this.childPlans.map((childPlan) => __awaiter(this, void 0, void 0, function* () {
39341
- const items = yield childPlan.execute();
39342
- return new DatabaseItemMap(items);
39343
- })));
39344
- let result;
39345
- for (const itemMap of childItemMaps) {
39346
- if (result) {
39347
- result = result.intersection(itemMap);
39348
- }
39349
- else {
39350
- result = itemMap;
39351
- }
39352
- }
39353
- return (_j = (result == null ? void 0 : result.items())) !== null && _j !== void 0 ? _j : [];
39354
- });
39355
- }
39356
- };
39357
- var ResolveItemsPlan = class extends QueryPlan {
39358
- constructor(childPlan, collection, richTextResolver, select) {
39359
- super();
39360
- this.childPlan = childPlan;
39361
- this.collection = collection;
39362
- this.richTextResolver = richTextResolver;
39363
- this.select = select;
39364
- }
39365
- inspect() {
39366
- return {
39367
- label: `ResolveItemsPlan ${stringifyExecutionTime(this.executionTime - this.childPlan.executionTime, this.executionTime)} ${stringifyItems(this.itemCount)}`,
39368
- nodes: [this.childPlan.inspect(),],
39369
- };
39370
- }
39371
- _execute() {
39372
- return __awaiter(this, void 0, void 0, function* () {
39373
- const childItems = yield this.childPlan.execute();
39374
- const childPointers = childItems.map((item) => item.pointer);
39375
- for (const item of childItems) {
39376
- for (const expression of this.select) {
39377
- if (expression.type !== 'Identifier')
39378
- continue;
39379
- const value = item.data[expression.name];
39380
- if ((value == null ? void 0 : value.type) !== 'richtext')
39381
- continue;
39382
- void this.richTextResolver.resolve(expression.name, value.value);
39383
- }
39384
- }
39385
- return this.collection.resolveItems(childPointers);
39386
- });
39387
- }
39388
- };
39389
- var FilterItemsPlan = class extends QueryPlan {
39390
- constructor(childPlan, filterExpression) {
39391
- super();
39392
- this.childPlan = childPlan;
39393
- this.filterExpression = filterExpression;
39394
- }
39395
- inspect() {
39396
- return {
39397
- label: `FilterItemsPlan(${this.filterExpression.stringify()}) ${stringifyExecutionTime(this.executionTime - this.childPlan.executionTime, this.executionTime)} ${stringifyItems(this.itemCount)} ${stringifyItems(this.itemCount)}`,
39398
- nodes: [this.childPlan.inspect(),],
39399
- };
39400
- }
39401
- _execute() {
39402
- return __awaiter(this, void 0, void 0, function* () {
39403
- const childItems = yield this.childPlan.execute();
39404
- return childItems.filter((item) => {
39405
- const result = this.filterExpression.evaluate(item);
39406
- return toBoolean(result);
39407
- });
39408
- });
39409
- }
39410
- };
39411
- var SortItemsPlan = class extends QueryPlan {
39412
- constructor(childPlan, orderExpressions, collection) {
39413
- super();
39414
- this.childPlan = childPlan;
39415
- this.orderExpressions = orderExpressions;
39416
- this.collection = collection;
39417
- }
39418
- inspect() {
39419
- const order = this.orderExpressions.map((expression) => `${expression.expression.stringify()} ${expression.direction.toUpperCase()}`)
39420
- .join(', ');
39421
- return {
39422
- label: `SortItemsPlan(${order}) ${stringifyExecutionTime(this.executionTime - this.childPlan.executionTime, this.executionTime)} ${stringifyItems(this.itemCount)}`,
39423
- nodes: [this.childPlan.inspect(),],
39424
- };
39425
- }
39426
- _execute() {
39427
- return __awaiter(this, void 0, void 0, function* () {
39428
- const childItems = yield this.childPlan.execute();
39429
- return childItems.sort((leftItem, rightItem) => {
39430
- const leftSortItem = Object.assign(Object.assign({}, leftItem), { data: {} });
39431
- const rightSortItem = Object.assign(Object.assign({}, rightItem), { data: {} });
39432
- for (const { expression, direction, collation: collation10, } of this.orderExpressions) {
39433
- const isAscending = direction === 'asc';
39434
- if (expression instanceof ScalarIdentifier && expression.name === INDEX_IDENTIFIER) {
39435
- const order = this.collection.compareItems(leftSortItem, rightSortItem);
39436
- return isAscending ? order : -order;
39437
- }
39438
- const left = expression.evaluate(leftItem);
39439
- const right = expression.evaluate(rightItem);
39440
- if (DatabaseValue.equal(left, right, collation10)) {
39441
- continue;
39442
- }
39443
- if (DatabaseValue.lessThan(left, right, collation10) || isNullish2(left)) {
39444
- return isAscending ? -1 : 1;
39445
- }
39446
- if (DatabaseValue.greaterThan(left, right, collation10) || isNullish2(right)) {
39447
- return isAscending ? 1 : -1;
39448
- }
39449
- throw new Error('Invalid comparison result.');
39450
- }
39451
- return this.collection.compareItems(leftSortItem, rightSortItem);
39452
- });
39453
- });
39454
- }
39455
- };
39456
- var ScalarOrderExpression = class {
39457
- constructor(expression, direction, collation10) {
39458
- this.expression = expression;
39459
- this.direction = direction;
39460
- this.collation = collation10;
39461
- }
39462
- };
39463
- var SliceItemsPlan = class extends QueryPlan {
39464
- constructor(childPlan, offsetExpression, limitExpression) {
39465
- super();
39466
- this.childPlan = childPlan;
39467
- this.offsetExpression = offsetExpression;
39468
- this.limitExpression = limitExpression;
39469
- }
39470
- inspect() {
39471
- var _j, _k;
39472
- var _a, _b;
39473
- return {
39474
- label: `SliceItemsPlan(LIMIT ${(_j = ((_a = this.limitExpression) == null ? void 0 : _a.stringify())) !== null && _j !== void 0 ? _j : 'Infinity'}, OFFSET ${(_k = ((_b = this.offsetExpression) == null ? void 0 : _b.stringify())) !== null && _k !== void 0 ? _k : '0'}) ${stringifyExecutionTime(this.executionTime - this.childPlan.executionTime, this.executionTime)} ${stringifyItems(this.itemCount)}`,
39475
- nodes: [this.childPlan.inspect(),],
39476
- };
39477
- }
39478
- getOffset() {
39479
- var _a;
39480
- const value = (_a = this.offsetExpression) == null ? void 0 : _a.evaluate();
39481
- if (isNullish2(value) || value.type !== 'number')
39482
- return;
39483
- return value.value;
39484
- }
39485
- getLimit() {
39486
- var _a;
39487
- const value = (_a = this.limitExpression) == null ? void 0 : _a.evaluate();
39488
- if (isNullish2(value) || value.type !== 'number')
39489
- return;
39490
- return value.value;
39491
- }
39492
- _execute() {
39493
- return __awaiter(this, void 0, void 0, function* () {
39494
- var _j, _k;
39495
- const childItems = yield this.childPlan.execute();
39496
- const offset = (_j = this.getOffset()) !== null && _j !== void 0 ? _j : 0;
39497
- const limit = (_k = this.getLimit()) !== null && _k !== void 0 ? _k : Infinity;
39498
- return childItems.slice(offset, offset + limit);
39499
- });
39500
- }
39501
- };
39502
- var DatabaseItemMap = class extends Map {
39503
- constructor(items = []) {
39504
- super();
39505
- for (const item of items) {
39506
- this.set(item.pointer, item);
39507
- }
39508
- }
39509
- union(other) {
39510
- const result = new DatabaseItemMap();
39511
- for (const [pointer, item,] of this) {
39512
- result.set(pointer, item);
39513
- }
39514
- for (const [pointer, item,] of other) {
39515
- result.set(pointer, item);
39516
- }
39517
- return result;
39518
- }
39519
- intersection(other) {
39520
- const result = new DatabaseItemMap();
39521
- for (const [pointer, item,] of this) {
39522
- if (other.has(pointer)) {
39523
- result.set(pointer, item);
39524
- }
39525
- }
39526
- return result;
39527
- }
39528
- items() {
39529
- const values = this.values();
39530
- return [...values,];
39531
- }
39532
- };
39533
- var RichTextResolver = class {
39534
- constructor(collections) {
39535
- this.collections = collections;
39536
- __publicField(this, 'cache', /* @__PURE__ */ new Map());
39537
- }
39538
- resolve(key7, pointer) {
39539
- var _j;
39540
- const scopedCache = (_j = this.cache.get(key7)) !== null && _j !== void 0 ? _j : new Map();
39541
- this.cache.set(key7, scopedCache);
39542
- const cachedPromise = scopedCache.get(pointer);
39543
- if (cachedPromise)
39544
- return cachedPromise;
39545
- for (const collection of this.collections) {
39546
- if (key7 in collection.schema) {
39547
- const promise = collection.resolveRichText(pointer);
39548
- scopedCache.set(pointer, promise);
39549
- return promise;
39550
- }
39551
- }
39552
- throw new Error(`Rich text field not found: ${key7}`);
39553
- }
39554
- };
39555
38092
  var unknownDefinition = {
39556
38093
  type: 'unknown',
39557
38094
  isNullable: true,
@@ -40113,7 +38650,7 @@ var CaseCondition = class {
40113
38650
  return calculateHash('CaseCondition', this.when, this.then);
40114
38651
  }
40115
38652
  };
40116
- var ScalarCase2 = class extends ScalarNode {
38653
+ var ScalarCase = class extends ScalarNode {
40117
38654
  constructor(input, conditions, otherwise) {
40118
38655
  const referencedFields = new Fields();
40119
38656
  const referencedOuterFields = new Fields();
@@ -40180,7 +38717,7 @@ var ScalarCase2 = class extends ScalarNode {
40180
38717
  return new CaseCondition(when, then);
40181
38718
  });
40182
38719
  const otherwise = (_b = this.otherwise) == null ? void 0 : _b.getOptimized();
40183
- return new ScalarCase2(input, conditions, otherwise);
38720
+ return new ScalarCase(input, conditions, otherwise);
40184
38721
  }
40185
38722
  *evaluate(context, tuple) {
40186
38723
  var _j, _k;
@@ -42996,7 +41533,7 @@ var Normalizer = class {
42996
41533
  }
42997
41534
  conditions = castConditions;
42998
41535
  }
42999
- const node = new ScalarCase2(input, conditions, otherwise);
41536
+ const node = new ScalarCase(input, conditions, otherwise);
43000
41537
  return this.finishScalar(node);
43001
41538
  }
43002
41539
  newScalarContains(source, target) {
@@ -43225,37 +41762,8 @@ function stringifyQuery(query) {
43225
41762
  return autoIndentSql(queryString);
43226
41763
  }
43227
41764
  var log = /* @__PURE__ */ getLogger('query-engine');
43228
- function getDatabaseCollection({ data: data2, }, locale) {
43229
- if (isAnyLegacyCollection(data2)) {
43230
- return new CompatibilityDatabaseCollection(data2, locale);
43231
- }
43232
- if (isDatabaseCollection(data2)) {
43233
- return data2;
43234
- }
43235
- if (isLocalizedDatabaseCollection(data2)) {
43236
- while (locale) {
43237
- const collection = data2.collectionByLocaleId[locale.id];
43238
- if (collection)
43239
- return collection;
43240
- locale = locale.fallback;
43241
- }
43242
- return data2.collectionByLocaleId.default;
43243
- }
43244
- assertNever(data2, 'Unsupported collection type');
43245
- }
43246
41765
  var QueryEngine = class {
43247
- constructor() {
43248
- __publicField(this, 'useNewOptimizer', false);
43249
- }
43250
41766
  query(query, locale) {
43251
- return __awaiter(this, void 0, void 0, function* () {
43252
- if (this.useNewOptimizer || needsNewQueryOptimizer(query)) {
43253
- return this.queryNew(query, locale);
43254
- }
43255
- return this.queryOld(query, locale);
43256
- });
43257
- }
43258
- queryNew(query, locale) {
43259
41767
  return __awaiter(this, void 0, void 0, function* () {
43260
41768
  log.debug(`Query:
43261
41769
  ${stringifyQuery(query)}`);
@@ -43297,278 +41805,8 @@ ${stringifyQuery(query)}`);
43297
41805
  return (_j = (value == null ? void 0 : value.value)) !== null && _j !== void 0 ? _j : null;
43298
41806
  });
43299
41807
  }
43300
- queryOld(query, locale) {
43301
- return __awaiter(this, void 0, void 0, function* () {
43302
- const [plan, schema, richTextResolver,] = this.createQueryPlan(query, locale);
43303
- const items = yield this.executeQueryPlan(schema, richTextResolver, query, plan);
43304
- log.debug(`Query:
43305
- ${stringifyQuery(query)}
43306
-
43307
- ${(0, import_archy.default)(plan.inspect())}`);
43308
- return items;
43309
- });
43310
- }
43311
- buildFrom(from, schema, collections, locale) {
43312
- switch (from.type) {
43313
- case 'Collection': {
43314
- const collection = getDatabaseCollection(from, locale);
43315
- collections.push(collection);
43316
- Object.assign(schema, collection.schema);
43317
- return new ScanCollectionPlan(collection, from.alias);
43318
- }
43319
- case 'LeftJoin': {
43320
- const left = this.buildFrom(from.left, schema, collections, locale);
43321
- const right = this.buildFrom(from.right, schema, collections, locale);
43322
- const constraint = ScalarExpression.from(from.constraint, schema);
43323
- return new LeftJoinPlan(left, right, constraint);
43324
- }
43325
- default:
43326
- assertNever(from, 'Unsupported data source');
43327
- }
43328
- }
43329
- createQueryPlan(query, locale) {
43330
- var _a;
43331
- const schema = {};
43332
- const collections = [];
43333
- let plan = this.buildFrom(query.from, schema, collections, locale);
43334
- const [firstCollection,] = collections;
43335
- assert(firstCollection, 'At least one collection must exist');
43336
- const richTextResolver = new RichTextResolver(collections);
43337
- if (query.where) {
43338
- const filterExpression = ScalarExpression.from(query.where, schema);
43339
- if (collections.length === 1) {
43340
- plan = createPlanForWhereClause(firstCollection, filterExpression);
43341
- }
43342
- else {
43343
- plan = new FilterItemsPlan(plan, filterExpression);
43344
- }
43345
- }
43346
- const sortExpressions = (_a = query.orderBy) == null
43347
- ? void 0
43348
- : _a.map((expression) => {
43349
- var _j;
43350
- return new ScalarOrderExpression(ScalarExpression.from(expression, schema), (_j = expression.direction) !== null && _j !== void 0 ? _j : 'asc', {
43351
- type: 0,
43352
- /* CaseInsensitive */
43353
- });
43354
- });
43355
- plan = new SortItemsPlan(plan, sortExpressions !== null && sortExpressions !== void 0 ? sortExpressions : [], firstCollection);
43356
- let offsetExpression;
43357
- if (query.offset) {
43358
- offsetExpression = ScalarExpression.from(query.offset, schema);
43359
- }
43360
- let limitExpression;
43361
- if (query.limit) {
43362
- limitExpression = ScalarExpression.from(query.limit, schema);
43363
- }
43364
- if (offsetExpression || limitExpression) {
43365
- plan = new SliceItemsPlan(plan, offsetExpression, limitExpression);
43366
- }
43367
- if (query.select.length > 0 && collections.length === 1) {
43368
- plan = new ResolveItemsPlan(plan, firstCollection, richTextResolver, query.select);
43369
- }
43370
- return [plan, schema, richTextResolver,];
43371
- }
43372
- executeQueryPlan(schema, richTextResolver, query, plan) {
43373
- return __awaiter(this, void 0, void 0, function* () {
43374
- const items = yield plan.execute();
43375
- return Promise.all(items.map((item) => __awaiter(this, void 0, void 0, function* () {
43376
- const data2 = {};
43377
- for (const expression of query.select) {
43378
- const scalarExpression = ScalarExpression.from(expression, schema);
43379
- const key7 = getSelectKey(expression);
43380
- const value = scalarExpression.evaluate(item);
43381
- data2[key7] = yield resolveValue(richTextResolver, expression.type === 'Identifier' ? expression.name : void 0, value);
43382
- }
43383
- return data2;
43384
- })));
43385
- });
43386
- }
43387
41808
  };
43388
41809
  exports.QueryEngine = QueryEngine;
43389
- function getSelectKey(expression) {
43390
- if (expression.alias) {
43391
- return expression.alias;
43392
- }
43393
- if (expression.type === 'Identifier') {
43394
- return expression.name;
43395
- }
43396
- throw new Error('Can\'t serialize expression');
43397
- }
43398
- function resolveValue(richTextResolver, key7, value) {
43399
- return __awaiter(this, void 0, void 0, function* () {
43400
- if (isNullish2(value)) {
43401
- return null;
43402
- }
43403
- if (value.type === 'richtext') {
43404
- assert(isString2(key7), 'Rich text field must be a string');
43405
- return richTextResolver.resolve(key7, value.value);
43406
- }
43407
- return value.value;
43408
- });
43409
- }
43410
- function createPlanForWhereClause(collection, expression) {
43411
- var _j;
43412
- if (expression instanceof ScalarLogicalOperationAnd) {
43413
- const childPlans = expression.operandExpressions.map((expression2) => createPlanForWhereClause(collection, expression2));
43414
- return new IntersectionPlan(childPlans);
43415
- }
43416
- if (expression instanceof ScalarLogicalOperationOr) {
43417
- const childPlans = expression.operandExpressions.map((expression2) => createPlanForWhereClause(collection, expression2));
43418
- return new UnionPlan(childPlans);
43419
- }
43420
- return (_j = findLookupIndexPlan(collection, expression)) !== null && _j !== void 0 ? _j : createScanCollectionPlan(collection, expression);
43421
- }
43422
- function findLookupIndexPlan(collection, expression) {
43423
- var _a, _b;
43424
- if (expression instanceof ScalarComparison) {
43425
- return findLookupIndexPlanForComparison(collection, expression);
43426
- }
43427
- if (expression instanceof ScalarFunctionCall) {
43428
- return findLookupIndexPlanForFunctionCall(collection, expression);
43429
- }
43430
- if (expression instanceof ScalarIdentifier && ((_a = expression.definition) == null ? void 0 : _a.type) === 'boolean') {
43431
- const value = ScalarLiteralValue.fromBoolean(true);
43432
- const comparison = new ScalarComparisonEquals(expression, value);
43433
- return findLookupIndexPlanForComparison(collection, comparison);
43434
- }
43435
- if (expression instanceof ScalarUnaryOperationNot && expression.valueExpression instanceof ScalarIdentifier &&
43436
- ((_b = expression.valueExpression.definition) == null ? void 0 : _b.type) === 'boolean') {
43437
- const value = ScalarLiteralValue.fromBoolean(true);
43438
- const comparison = new ScalarComparisonNotEquals(expression.valueExpression, value);
43439
- return findLookupIndexPlanForComparison(collection, comparison);
43440
- }
43441
- }
43442
- function findLookupIndexPlanForComparison(collection, expression) {
43443
- const leftExpression = expression.leftExpression;
43444
- const rightExpression = expression.rightExpression;
43445
- if (!(rightExpression instanceof ScalarLiteralValue))
43446
- return;
43447
- for (const index of collection.indexes) {
43448
- const field = index.fields[0];
43449
- if (isUndefined(field))
43450
- continue;
43451
- const fieldExpression = ScalarExpression.from(field, collection.schema);
43452
- if (!leftExpression.equals(fieldExpression))
43453
- continue;
43454
- const fillerAllQueries = new Array(index.fields.length - 1).fill({
43455
- type: 'All',
43456
- /* All */
43457
- });
43458
- if (expression instanceof ScalarComparisonEquals && index.supportedLookupTypes.includes('Equals')) {
43459
- return new LookupIndexPlan(index, [{
43460
- type: 'Equals',
43461
- value: rightExpression.evaluate(),
43462
- }, ...fillerAllQueries,]);
43463
- }
43464
- if (expression instanceof ScalarComparisonNotEquals && index.supportedLookupTypes.includes('NotEquals')) {
43465
- return new LookupIndexPlan(index, [{
43466
- type: 'NotEquals',
43467
- value: rightExpression.evaluate(),
43468
- }, ...fillerAllQueries,]);
43469
- }
43470
- if (expression instanceof ScalarComparisonLessThan && index.supportedLookupTypes.includes('LessThan')) {
43471
- return new LookupIndexPlan(index, [{
43472
- type: 'LessThan',
43473
- value: rightExpression.evaluate(),
43474
- inclusive: false,
43475
- }, ...fillerAllQueries,]);
43476
- }
43477
- if (expression instanceof ScalarComparisonLessThanOrEqual && index.supportedLookupTypes.includes('LessThan')) {
43478
- return new LookupIndexPlan(index, [{
43479
- type: 'LessThan',
43480
- value: rightExpression.evaluate(),
43481
- inclusive: true,
43482
- }, ...fillerAllQueries,]);
43483
- }
43484
- if (expression instanceof ScalarComparisonGreaterThan && index.supportedLookupTypes.includes('GreaterThan')) {
43485
- return new LookupIndexPlan(index, [{
43486
- type: 'GreaterThan',
43487
- value: rightExpression.evaluate(),
43488
- inclusive: false,
43489
- }, ...fillerAllQueries,]);
43490
- }
43491
- if (expression instanceof ScalarComparisonGreaterThanOrEqual && index.supportedLookupTypes.includes('GreaterThan')) {
43492
- return new LookupIndexPlan(index, [{
43493
- type: 'GreaterThan',
43494
- value: rightExpression.evaluate(),
43495
- inclusive: true,
43496
- }, ...fillerAllQueries,]);
43497
- }
43498
- }
43499
- }
43500
- function findLookupIndexPlanForFunctionCall(collection, expression) {
43501
- if (expression.argumentExpressions.length !== 2)
43502
- return;
43503
- const sourceExpression = expression.argumentExpressions[0];
43504
- const targetExpression = expression.argumentExpressions[1];
43505
- if (isUndefined(sourceExpression))
43506
- return;
43507
- if (isUndefined(targetExpression))
43508
- return;
43509
- if (!(targetExpression instanceof ScalarLiteralValue))
43510
- return;
43511
- for (const index of collection.indexes) {
43512
- const field = index.fields[0];
43513
- if (isUndefined(field))
43514
- continue;
43515
- const fieldExpression = ScalarExpression.from(field, collection.schema);
43516
- if (!sourceExpression.equals(fieldExpression))
43517
- continue;
43518
- const fillerAllQueries = new Array(index.fields.length - 1).fill({
43519
- type: 'All',
43520
- /* All */
43521
- });
43522
- if (expression instanceof ScalarFunctionCallContains && index.supportedLookupTypes.includes('Contains')) {
43523
- return new LookupIndexPlan(index, [{
43524
- type: 'Contains',
43525
- value: targetExpression.evaluate(),
43526
- }, ...fillerAllQueries,]);
43527
- }
43528
- if (expression instanceof ScalarFunctionCallStartsWith && index.supportedLookupTypes.includes('StartsWith')) {
43529
- return new LookupIndexPlan(index, [{
43530
- type: 'StartsWith',
43531
- value: targetExpression.evaluate(),
43532
- }, ...fillerAllQueries,]);
43533
- }
43534
- if (expression instanceof ScalarFunctionCallEndsWith && index.supportedLookupTypes.includes('EndsWith')) {
43535
- return new LookupIndexPlan(index, [{
43536
- type: 'EndsWith',
43537
- value: targetExpression.evaluate(),
43538
- }, ...fillerAllQueries,]);
43539
- }
43540
- }
43541
- }
43542
- function createScanCollectionPlan(collection, expression) {
43543
- const plan = new ScanCollectionPlan(collection, void 0);
43544
- return new FilterItemsPlan(plan, expression);
43545
- }
43546
- function needsNewQueryOptimizer(query) {
43547
- if (query.from.type !== 'Collection')
43548
- return true;
43549
- for (const expression of query.select) {
43550
- if (expression.type === 'Identifier')
43551
- return true;
43552
- }
43553
- if (query.where)
43554
- return hasScalarIn(query.where);
43555
- return false;
43556
- }
43557
- function hasScalarIn(expression) {
43558
- switch (expression.type) {
43559
- case 'UnaryOperation': {
43560
- return hasScalarIn(expression.value);
43561
- }
43562
- case 'BinaryOperation': {
43563
- if (expression.operator === 'in') {
43564
- return true;
43565
- }
43566
- return hasScalarIn(expression.left) || hasScalarIn(expression.right);
43567
- }
43568
- default:
43569
- return false;
43570
- }
43571
- }
43572
41810
  var defaultVariantKey = 'default';
43573
41811
  var defaultVariants = /* @__PURE__ */ new Set([defaultVariantKey,]);
43574
41812
  var _variantHashes;
@@ -50458,7 +48696,7 @@ MotionValue.prototype.addChild = function ({ transformer = (v) => v, }) {
50458
48696
  return child;
50459
48697
  };
50460
48698
  if (false) {
50461
- MainLoop.start();
48699
+ MainLoop2.start();
50462
48700
  }
50463
48701
  /**
50464
48702
  * @license Emotion v11.0.0