@dxos/echo-query 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc

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 (36) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/{browser → neutral}/index.mjs +373 -19
  4. package/dist/lib/neutral/index.mjs.map +7 -0
  5. package/dist/lib/neutral/meta.json +1 -0
  6. package/dist/query-lite/index.d.ts +10005 -0
  7. package/dist/query-lite/index.d.ts.map +1 -0
  8. package/dist/query-lite/index.js +545 -375
  9. package/dist/query-lite/index.js.map +1 -0
  10. package/dist/types/src/index.d.ts +1 -0
  11. package/dist/types/src/index.d.ts.map +1 -1
  12. package/dist/types/src/parser/gen/index.d.ts.map +1 -1
  13. package/dist/types/src/parser/query-builder.d.ts +8 -1
  14. package/dist/types/src/parser/query-builder.d.ts.map +1 -1
  15. package/dist/types/src/query-lite/query-lite.d.ts +4 -4
  16. package/dist/types/src/query-lite/query-lite.d.ts.map +1 -1
  17. package/dist/types/src/sandbox/index.d.ts +2 -0
  18. package/dist/types/src/sandbox/index.d.ts.map +1 -0
  19. package/dist/types/src/sandbox/query-sandbox.d.ts +1 -1
  20. package/dist/types/src/sandbox/query-sandbox.d.ts.map +1 -1
  21. package/dist/types/src/sandbox/quickjs.d.ts.map +1 -1
  22. package/dist/types/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +22 -20
  24. package/src/index.ts +1 -0
  25. package/src/parser/query-builder.ts +270 -10
  26. package/src/parser/query.test.ts +144 -31
  27. package/src/query-lite/query-lite.ts +360 -73
  28. package/src/sandbox/index.ts +5 -0
  29. package/src/sandbox/query-sandbox.test.ts +10 -10
  30. package/src/sandbox/query-sandbox.ts +1 -1
  31. package/src/sandbox/quickjs.ts +1 -2
  32. package/dist/lib/browser/index.mjs.map +0 -7
  33. package/dist/lib/browser/meta.json +0 -1
  34. package/dist/lib/node-esm/index.mjs +0 -563
  35. package/dist/lib/node-esm/index.mjs.map +0 -7
  36. package/dist/lib/node-esm/meta.json +0 -1
package/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -18,4 +18,4 @@ pnpm i @dxos/echo-query
18
18
 
19
19
  Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
20
20
 
21
- License: [MIT](./LICENSE) Copyright 2022 © DXOS
21
+ License: [FSL-1.1-Apache-2.0](./LICENSE) Copyright 2022 © DXOS
@@ -70,7 +70,7 @@ __export(query_terms_exports, {
70
70
  PropertyPath: () => PropertyPath,
71
71
  Query: () => Query,
72
72
  Relation: () => Relation,
73
- String: () => String,
73
+ String: () => String2,
74
74
  Tag: () => Tag,
75
75
  TagFilter: () => TagFilter,
76
76
  TextFilter: () => TextFilter,
@@ -85,7 +85,7 @@ var Filter = 7;
85
85
  var TagFilter = 8;
86
86
  var Tag = 9;
87
87
  var TextFilter = 10;
88
- var String = 11;
88
+ var String2 = 11;
89
89
  var TypeFilter = 12;
90
90
  var TypeKeyword = 13;
91
91
  var PropertyFilter = 15;
@@ -134,7 +134,7 @@ var QueryBuilder = class {
134
134
  */
135
135
  validate(input) {
136
136
  try {
137
- const tree = this._parser.parse(input);
137
+ const tree = this._parser.parse(normalizeInput(input));
138
138
  return tree.cursor().node.name === "Query";
139
139
  } catch {
140
140
  return false;
@@ -145,8 +145,9 @@ var QueryBuilder = class {
145
145
  */
146
146
  build(input) {
147
147
  try {
148
- const tree = this._parser.parse(input);
149
- return this.buildQuery(tree, input);
148
+ const normalized = normalizeInput(input);
149
+ const tree = this._parser.parse(normalized);
150
+ return this.buildQuery(tree, normalized);
150
151
  } catch {
151
152
  return {};
152
153
  }
@@ -311,8 +312,9 @@ var QueryBuilder = class {
311
312
  const exprStart = cursor.from;
312
313
  let exprEnd = cursor.to;
313
314
  while (cursor.nextSibling() && depth > 0) {
314
- if (cursor.node.name === "(") depth++;
315
- else if (cursor.node.name === ")") {
315
+ if (cursor.node.name === "(") {
316
+ depth++;
317
+ } else if (cursor.node.name === ")") {
316
318
  depth--;
317
319
  if (depth === 0) {
318
320
  exprEnd = cursor.from;
@@ -401,7 +403,7 @@ var QueryBuilder = class {
401
403
  cursor.firstChild();
402
404
  const text = this._getNodeText(cursor, input);
403
405
  cursor.parent();
404
- return Filter2.text(text.slice(1, -1));
406
+ return Filter2.text(unescapeStringLiteral(text.slice(1, -1)));
405
407
  }
406
408
  /**
407
409
  * Parse an ObjectLiteral node.
@@ -488,15 +490,7 @@ var QueryBuilder = class {
488
490
  * Parse a TagFilter node (#tag).
489
491
  */
490
492
  _parseTagFilter(cursor, input) {
491
- invariant(this._tags, void 0, {
492
- F: __dxlog_file,
493
- L: 468,
494
- S: this,
495
- A: [
496
- "this._tags",
497
- ""
498
- ]
499
- });
493
+ invariant(this._tags, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 400, S: this, A: ["this._tags", ""] });
500
494
  const str = this._getNodeText(cursor, input).slice(1).toLowerCase();
501
495
  const [key] = Object.entries(this._tags).find(([, value]) => value.label.toLowerCase() === str) ?? [];
502
496
  return key ? Filter2.tag(key) : void 0;
@@ -509,7 +503,7 @@ var QueryBuilder = class {
509
503
  switch (valueType) {
510
504
  case "String": {
511
505
  const str = this._getNodeText(cursor, input);
512
- return str.slice(1, -1);
506
+ return unescapeStringLiteral(str.slice(1, -1));
513
507
  }
514
508
  case "Number":
515
509
  return Number(this._getNodeText(cursor, input));
@@ -556,8 +550,368 @@ var QueryBuilder = class {
556
550
  return input.slice(cursor.from, cursor.to);
557
551
  }
558
552
  };
553
+ var KEYWORDS = /* @__PURE__ */ new Set([
554
+ "AND",
555
+ "OR",
556
+ "NOT"
557
+ ]);
558
+ var VALUE_LITERALS = /* @__PURE__ */ new Set([
559
+ "true",
560
+ "false",
561
+ "null"
562
+ ]);
563
+ var SPECIAL_CHARS = /[\s(){}\[\],"']/;
564
+ var PROPERTY_KEY = /^[a-zA-Z_][a-zA-Z0-9_.]*$/;
565
+ var NUMBER_LITERAL = /^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
566
+ var URL_SCHEMES = /* @__PURE__ */ new Set([
567
+ "http",
568
+ "https",
569
+ "ftp",
570
+ "ftps",
571
+ "file",
572
+ "mailto",
573
+ "tel",
574
+ "sms",
575
+ "data",
576
+ "javascript",
577
+ "ws",
578
+ "wss",
579
+ "ssh",
580
+ "git"
581
+ ]);
582
+ var normalizeInput = (input) => {
583
+ const out = [];
584
+ let pos = 0;
585
+ while (pos < input.length) {
586
+ const currentChar = input[pos];
587
+ if (/\s/.test(currentChar)) {
588
+ out.push(currentChar);
589
+ pos++;
590
+ continue;
591
+ }
592
+ const prevChar = pos > 0 ? input[pos - 1] : "";
593
+ const isStringOpener = currentChar === '"' || currentChar === "'" && (pos === 0 || !/[a-zA-Z0-9_]/.test(prevChar));
594
+ if (isStringOpener) {
595
+ const quoteChar = currentChar;
596
+ let scanIndex2 = pos + 1;
597
+ while (scanIndex2 < input.length && input[scanIndex2] !== quoteChar) {
598
+ if (input[scanIndex2] === "\\" && scanIndex2 + 1 < input.length) {
599
+ scanIndex2 += 2;
600
+ } else {
601
+ scanIndex2++;
602
+ }
603
+ }
604
+ out.push(input.slice(pos, Math.min(scanIndex2 + 1, input.length)));
605
+ pos = scanIndex2 + 1;
606
+ continue;
607
+ }
608
+ if (currentChar === "{" || currentChar === "[") {
609
+ const closeChar = currentChar === "{" ? "}" : "]";
610
+ let depth = 1;
611
+ let scanIndex2 = pos + 1;
612
+ while (scanIndex2 < input.length && depth > 0) {
613
+ const innerChar = input[scanIndex2];
614
+ if (innerChar === '"' || innerChar === "'") {
615
+ const quoteChar = innerChar;
616
+ scanIndex2++;
617
+ while (scanIndex2 < input.length && input[scanIndex2] !== quoteChar) {
618
+ if (input[scanIndex2] === "\\" && scanIndex2 + 1 < input.length) {
619
+ scanIndex2 += 2;
620
+ } else {
621
+ scanIndex2++;
622
+ }
623
+ }
624
+ scanIndex2++;
625
+ } else if (innerChar === currentChar) {
626
+ depth++;
627
+ scanIndex2++;
628
+ } else if (innerChar === closeChar) {
629
+ depth--;
630
+ scanIndex2++;
631
+ } else {
632
+ scanIndex2++;
633
+ }
634
+ }
635
+ out.push(input.slice(pos, scanIndex2));
636
+ pos = scanIndex2;
637
+ continue;
638
+ }
639
+ if (currentChar === "(" || currentChar === ")" || currentChar === "=" || currentChar === "," || currentChar === "}" || currentChar === "]") {
640
+ out.push(currentChar);
641
+ pos++;
642
+ continue;
643
+ }
644
+ if (currentChar === "-" && input[pos + 1] === ">" || currentChar === "<" && input[pos + 1] === "-") {
645
+ out.push(input.slice(pos, pos + 2));
646
+ pos += 2;
647
+ continue;
648
+ }
649
+ if (currentChar === "!") {
650
+ out.push(currentChar);
651
+ pos++;
652
+ continue;
653
+ }
654
+ if (currentChar === "#") {
655
+ let scanIndex2 = pos + 1;
656
+ while (scanIndex2 < input.length && /[a-zA-Z0-9_-]/.test(input[scanIndex2])) {
657
+ scanIndex2++;
658
+ }
659
+ out.push(input.slice(pos, scanIndex2));
660
+ pos = scanIndex2;
661
+ continue;
662
+ }
663
+ let scanIndex = pos;
664
+ while (scanIndex < input.length) {
665
+ const innerChar = input[scanIndex];
666
+ if (innerChar === '"') {
667
+ break;
668
+ }
669
+ if (innerChar === "'" && scanIndex > pos && !/[a-zA-Z0-9_]/.test(input[scanIndex - 1])) {
670
+ break;
671
+ }
672
+ if (innerChar === "'" && scanIndex === pos) {
673
+ break;
674
+ }
675
+ if (innerChar !== "'" && SPECIAL_CHARS.test(innerChar)) {
676
+ break;
677
+ }
678
+ if (innerChar === "-" && input[scanIndex + 1] === ">") {
679
+ break;
680
+ }
681
+ if (innerChar === "<" && input[scanIndex + 1] === "-") {
682
+ break;
683
+ }
684
+ scanIndex++;
685
+ }
686
+ if (scanIndex === pos) {
687
+ out.push(currentChar);
688
+ pos++;
689
+ continue;
690
+ }
691
+ const token = input.slice(pos, scanIndex);
692
+ pos = scanIndex;
693
+ if (KEYWORDS.has(token.toUpperCase())) {
694
+ out.push(token);
695
+ continue;
696
+ }
697
+ const colonIdx = token.indexOf(":");
698
+ if (colonIdx > 0) {
699
+ const key = token.slice(0, colonIdx);
700
+ const rest = token.slice(colonIdx + 1);
701
+ if (key === "type") {
702
+ out.push(token);
703
+ continue;
704
+ }
705
+ const isUrlScheme = URL_SCHEMES.has(key.toLowerCase()) || rest.startsWith("//");
706
+ if (!isUrlScheme && PROPERTY_KEY.test(key)) {
707
+ if (rest.length === 0) {
708
+ out.push(token);
709
+ continue;
710
+ }
711
+ const firstValueChar = rest[0];
712
+ if (firstValueChar === '"' || firstValueChar === "'") {
713
+ out.push(token);
714
+ continue;
715
+ }
716
+ if (firstValueChar === "{" || firstValueChar === "[") {
717
+ out.push(token);
718
+ continue;
719
+ }
720
+ if (VALUE_LITERALS.has(rest) || NUMBER_LITERAL.test(rest)) {
721
+ out.push(token);
722
+ continue;
723
+ }
724
+ out.push(`${key}:"${escapeStringLiteral(rest)}"`);
725
+ continue;
726
+ }
727
+ }
728
+ if (PROPERTY_KEY.test(token)) {
729
+ let lookahead = pos;
730
+ while (lookahead < input.length && /\s/.test(input[lookahead])) {
731
+ lookahead++;
732
+ }
733
+ if (input[lookahead] === "=") {
734
+ out.push(token);
735
+ continue;
736
+ }
737
+ }
738
+ out.push(`"${escapeStringLiteral(token)}"`);
739
+ }
740
+ return out.join("");
741
+ };
742
+ var escapeStringLiteral = (value) => value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
743
+ var unescapeStringLiteral = (literalBody) => {
744
+ let out = "";
745
+ for (let i = 0; i < literalBody.length; i++) {
746
+ const ch = literalBody[i];
747
+ if (ch === "\\" && i + 1 < literalBody.length) {
748
+ out += literalBody[i + 1];
749
+ i++;
750
+ } else {
751
+ out += ch;
752
+ }
753
+ }
754
+ return out;
755
+ };
756
+
757
+ // src/sandbox/query-sandbox.ts
758
+ import { Resource } from "@dxos/context";
759
+ import { Query as Query2 } from "@dxos/echo";
760
+ import { trim } from "@dxos/util";
761
+ import { createQuickJS } from "@dxos/vendor-quickjs";
762
+ import envCode from "#query-lite?raw";
763
+
764
+ // src/sandbox/quickjs.ts
765
+ var unwrapResult = (context, result) => {
766
+ if (result.error) {
767
+ const contextError = context.dump(result.error);
768
+ result.error.dispose();
769
+ if (typeof contextError === "object" && typeof contextError.name === "string" && typeof contextError.message === "string") {
770
+ const error = new Error(contextError.message);
771
+ Object.defineProperty(error, "name", {
772
+ value: contextError.name
773
+ });
774
+ const originalStack = error.stack;
775
+ error.stack = `${contextError.name}: ${contextError.message}
776
+ ${contextError.stack}${originalStack?.split("\n").slice(1).join("\n") ?? ""}`;
777
+ throw error;
778
+ } else {
779
+ throw new Error(String(contextError));
780
+ }
781
+ }
782
+ return result.value;
783
+ };
784
+
785
+ // src/sandbox/query-sandbox.ts
786
+ function _ts_add_disposable_resource(env, value, async) {
787
+ if (value !== null && value !== void 0) {
788
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
789
+ var dispose, inner;
790
+ if (async) {
791
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
792
+ dispose = value[Symbol.asyncDispose];
793
+ }
794
+ if (dispose === void 0) {
795
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
796
+ dispose = value[Symbol.dispose];
797
+ if (async) inner = dispose;
798
+ }
799
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
800
+ if (inner) dispose = function() {
801
+ try {
802
+ inner.call(this);
803
+ } catch (e) {
804
+ return Promise.reject(e);
805
+ }
806
+ };
807
+ env.stack.push({
808
+ value,
809
+ dispose,
810
+ async
811
+ });
812
+ } else if (async) {
813
+ env.stack.push({
814
+ async: true
815
+ });
816
+ }
817
+ return value;
818
+ }
819
+ function _ts_dispose_resources(env) {
820
+ var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
821
+ var e = new Error(message);
822
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
823
+ };
824
+ return (_ts_dispose_resources = function _ts_dispose_resources2(env2) {
825
+ function fail(e) {
826
+ env2.error = env2.hasError ? new _SuppressedError(e, env2.error, "An error was suppressed during disposal.") : e;
827
+ env2.hasError = true;
828
+ }
829
+ var r, s = 0;
830
+ function next() {
831
+ while (r = env2.stack.pop()) {
832
+ try {
833
+ if (!r.async && s === 1) return s = 0, env2.stack.push(r), Promise.resolve().then(next);
834
+ if (r.dispose) {
835
+ var result = r.dispose.call(r.value);
836
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
837
+ fail(e);
838
+ return next();
839
+ });
840
+ } else s |= 1;
841
+ } catch (e) {
842
+ fail(e);
843
+ }
844
+ }
845
+ if (s === 1) return env2.hasError ? Promise.reject(env2.error) : Promise.resolve();
846
+ if (env2.hasError) throw env2.error;
847
+ }
848
+ return next();
849
+ })(env);
850
+ }
851
+ var QuerySandbox = class _QuerySandbox extends Resource {
852
+ // Caching the wasm module.
853
+ static quickJS = null;
854
+ static getQuickJS() {
855
+ if (!_QuerySandbox.quickJS) {
856
+ _QuerySandbox.quickJS = createQuickJS();
857
+ }
858
+ return _QuerySandbox.quickJS;
859
+ }
860
+ #runtime;
861
+ async _open() {
862
+ const quickJS = await _QuerySandbox.getQuickJS();
863
+ this.#runtime = quickJS.newRuntime({
864
+ moduleLoader: (moduleName, _context) => {
865
+ switch (moduleName) {
866
+ case "dxos:query-lite":
867
+ return envCode;
868
+ default:
869
+ throw new Error(`Module not found: ${moduleName}`);
870
+ }
871
+ }
872
+ });
873
+ }
874
+ async _close() {
875
+ this.#runtime.dispose();
876
+ }
877
+ /**
878
+ * Evaluates the query code.
879
+ * @param queryCode Example: `Query.select(Filter.typename('org.dxos.type.person'))`
880
+ */
881
+ eval(queryCode) {
882
+ const env = {
883
+ stack: [],
884
+ error: void 0,
885
+ hasError: false
886
+ };
887
+ try {
888
+ const context = _ts_add_disposable_resource(env, this.#runtime.newContext(), false);
889
+ const globals = trim`
890
+ import { Filter, Order, Query } from 'dxos:query-lite';
891
+ globalThis.Filter = Filter;
892
+ globalThis.Order = Order;
893
+ globalThis.Query = Query;
894
+ `;
895
+ unwrapResult(context, context.evalCode(globals)).dispose();
896
+ const query = _ts_add_disposable_resource(env, unwrapResult(context, context.evalCode(queryCode)), false);
897
+ const result = context.dump(query);
898
+ if ("~Filter" in result) {
899
+ return Query2.select(result).ast;
900
+ } else {
901
+ return result.ast;
902
+ }
903
+ } catch (e) {
904
+ env.error = e;
905
+ env.hasError = true;
906
+ } finally {
907
+ _ts_dispose_resources(env);
908
+ }
909
+ }
910
+ };
559
911
  export {
560
912
  QueryBuilder,
561
- QueryDSL
913
+ QueryDSL,
914
+ QuerySandbox,
915
+ normalizeInput
562
916
  };
563
917
  //# sourceMappingURL=index.mjs.map