@dxos/echo-query 0.8.3 → 0.8.4-main.1068cf700f
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.
- package/README.md +1 -1
- package/dist/lib/neutral/index.mjs +719 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/query-lite/index.d.ts +8799 -0
- package/dist/query-lite/index.d.ts.map +1 -0
- package/dist/query-lite/index.js +381 -0
- package/dist/query-lite/index.js.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/parser/gen/index.d.ts +8 -0
- package/dist/types/src/parser/gen/index.d.ts.map +1 -0
- package/dist/types/src/parser/gen/query.d.ts +3 -0
- package/dist/types/src/parser/gen/query.d.ts.map +1 -0
- package/dist/types/src/parser/gen/query.terms.d.ts +2 -0
- package/dist/types/src/parser/gen/query.terms.d.ts.map +1 -0
- package/dist/types/src/parser/index.d.ts +3 -0
- package/dist/types/src/parser/index.d.ts.map +1 -0
- package/dist/types/src/parser/query-builder.d.ts +82 -0
- package/dist/types/src/parser/query-builder.d.ts.map +1 -0
- package/dist/types/src/parser/query.test.d.ts +2 -0
- package/dist/types/src/parser/query.test.d.ts.map +1 -0
- package/dist/types/src/query-lite/index.d.ts +2 -0
- package/dist/types/src/query-lite/index.d.ts.map +1 -0
- package/dist/types/src/query-lite/query-lite.d.ts +8 -0
- package/dist/types/src/query-lite/query-lite.d.ts.map +1 -0
- package/dist/types/src/sandbox/index.d.ts +2 -0
- package/dist/types/src/sandbox/index.d.ts.map +1 -0
- package/dist/types/src/sandbox/query-sandbox.d.ts +21 -0
- package/dist/types/src/sandbox/query-sandbox.d.ts.map +1 -0
- package/dist/types/src/sandbox/query-sandbox.test.d.ts +2 -0
- package/dist/types/src/sandbox/query-sandbox.test.d.ts.map +1 -0
- package/dist/types/src/sandbox/quickjs.d.ts +8 -0
- package/dist/types/src/sandbox/quickjs.d.ts.map +1 -0
- package/dist/types/src/sandbox/quickjs.test.d.ts +2 -0
- package/dist/types/src/sandbox/quickjs.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +30 -10
- package/src/env.d.ts +8 -0
- package/src/index.ts +3 -0
- package/src/parser/gen/index.ts +13 -0
- package/src/parser/gen/query.terms.ts +27 -0
- package/src/parser/gen/query.ts +18 -0
- package/src/parser/index.ts +6 -0
- package/src/parser/query-builder.ts +539 -0
- package/src/parser/query.grammar +130 -0
- package/src/parser/query.test.ts +416 -0
- package/src/query-lite/index.ts +5 -0
- package/src/query-lite/query-lite.ts +505 -0
- package/src/sandbox/index.ts +5 -0
- package/src/sandbox/query-sandbox.test.ts +53 -0
- package/src/sandbox/query-sandbox.ts +72 -0
- package/src/sandbox/quickjs.test.ts +67 -0
- package/src/sandbox/quickjs.ts +33 -0
- package/dist/lib/browser/index.mjs +0 -2
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node/index.cjs +0 -2
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -2
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/types/src/search.test.d.ts +0 -2
- package/dist/types/src/search.test.d.ts.map +0 -1
- package/src/search.test.ts +0 -49
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
//#region ../../../common/invariant/dist/lib/browser/index.mjs
|
|
2
|
+
var assertArgument = (condition, argumentName, message) => {
|
|
3
|
+
if (!condition) {
|
|
4
|
+
const error = /* @__PURE__ */ new TypeError(`Invalid argument \`${argumentName}\`` + (message ? `: ${message}` : ""));
|
|
5
|
+
Error.captureStackTrace(error, assertArgument);
|
|
6
|
+
throw error;
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/query-lite/query-lite.ts
|
|
12
|
+
var OrderClass = class OrderClass {
|
|
13
|
+
static variance = {};
|
|
14
|
+
static is(value) {
|
|
15
|
+
return typeof value === "object" && value !== null && "~Order" in value;
|
|
16
|
+
}
|
|
17
|
+
constructor(ast) {
|
|
18
|
+
this.ast = ast;
|
|
19
|
+
}
|
|
20
|
+
"~Order" = OrderClass.variance;
|
|
21
|
+
};
|
|
22
|
+
let Order1;
|
|
23
|
+
(function(_Order) {
|
|
24
|
+
_Order.natural = new OrderClass({ kind: "natural" });
|
|
25
|
+
_Order.property = (property, direction) => new OrderClass({
|
|
26
|
+
kind: "property",
|
|
27
|
+
property,
|
|
28
|
+
direction
|
|
29
|
+
});
|
|
30
|
+
_Order.rank = (direction = "desc") => new OrderClass({
|
|
31
|
+
kind: "rank",
|
|
32
|
+
direction
|
|
33
|
+
});
|
|
34
|
+
})(Order1 || (Order1 = {}));
|
|
35
|
+
const Order2 = Order1;
|
|
36
|
+
var FilterClass = class FilterClass {
|
|
37
|
+
static variance = {};
|
|
38
|
+
static is(value) {
|
|
39
|
+
return typeof value === "object" && value !== null && "~Filter" in value;
|
|
40
|
+
}
|
|
41
|
+
static fromAst(ast) {
|
|
42
|
+
return new FilterClass(ast);
|
|
43
|
+
}
|
|
44
|
+
static everything() {
|
|
45
|
+
return new FilterClass({
|
|
46
|
+
type: "object",
|
|
47
|
+
typename: null,
|
|
48
|
+
props: {}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
static nothing() {
|
|
52
|
+
return new FilterClass({
|
|
53
|
+
type: "not",
|
|
54
|
+
filter: {
|
|
55
|
+
type: "object",
|
|
56
|
+
typename: null,
|
|
57
|
+
props: {}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
static relation() {
|
|
62
|
+
return new FilterClass({
|
|
63
|
+
type: "object",
|
|
64
|
+
typename: null,
|
|
65
|
+
props: {}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
static id(...ids) {
|
|
69
|
+
if (ids.length === 0) return FilterClass.nothing();
|
|
70
|
+
return new FilterClass({
|
|
71
|
+
type: "object",
|
|
72
|
+
typename: null,
|
|
73
|
+
id: ids,
|
|
74
|
+
props: {}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
static type(schema, props) {
|
|
78
|
+
if (typeof schema !== "string") throw new TypeError("expected typename as the first paramter");
|
|
79
|
+
return new FilterClass({
|
|
80
|
+
type: "object",
|
|
81
|
+
typename: makeTypeDxn(schema),
|
|
82
|
+
...propsFilterToAst(props ?? {})
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
static typename(typename) {
|
|
86
|
+
return new FilterClass({
|
|
87
|
+
type: "object",
|
|
88
|
+
typename: makeTypeDxn(typename),
|
|
89
|
+
props: {}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
static typeDXN(dxn) {
|
|
93
|
+
return new FilterClass({
|
|
94
|
+
type: "object",
|
|
95
|
+
typename: dxn.toString(),
|
|
96
|
+
props: {}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
static tag(tag) {
|
|
100
|
+
return new FilterClass({
|
|
101
|
+
type: "tag",
|
|
102
|
+
tag
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
static props(props) {
|
|
106
|
+
return new FilterClass({
|
|
107
|
+
type: "object",
|
|
108
|
+
typename: null,
|
|
109
|
+
...propsFilterToAst(props)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
static text(text, options) {
|
|
113
|
+
return new FilterClass({
|
|
114
|
+
type: "text-search",
|
|
115
|
+
text,
|
|
116
|
+
searchKind: options?.type
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
static foreignKeys(schema, keys) {
|
|
120
|
+
assertArgument(typeof schema === "string", "schema");
|
|
121
|
+
assertArgument(!schema.startsWith("dxn:"), "schema");
|
|
122
|
+
return new FilterClass({
|
|
123
|
+
type: "object",
|
|
124
|
+
typename: `dxn:type:${schema}`,
|
|
125
|
+
props: {},
|
|
126
|
+
foreignKeys: keys
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
static eq(value) {
|
|
130
|
+
if (!isRef(value) && typeof value === "object" && value !== null) throw new TypeError("Cannot use object as a value for eq filter");
|
|
131
|
+
return new FilterClass({
|
|
132
|
+
type: "compare",
|
|
133
|
+
operator: "eq",
|
|
134
|
+
value: isRef(value) ? value.noInline().encode() : value
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
static neq(value) {
|
|
138
|
+
return new FilterClass({
|
|
139
|
+
type: "compare",
|
|
140
|
+
operator: "neq",
|
|
141
|
+
value
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
static gt(value) {
|
|
145
|
+
return new FilterClass({
|
|
146
|
+
type: "compare",
|
|
147
|
+
operator: "gt",
|
|
148
|
+
value
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
static gte(value) {
|
|
152
|
+
return new FilterClass({
|
|
153
|
+
type: "compare",
|
|
154
|
+
operator: "gte",
|
|
155
|
+
value
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
static lt(value) {
|
|
159
|
+
return new FilterClass({
|
|
160
|
+
type: "compare",
|
|
161
|
+
operator: "lt",
|
|
162
|
+
value
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
static lte(value) {
|
|
166
|
+
return new FilterClass({
|
|
167
|
+
type: "compare",
|
|
168
|
+
operator: "lte",
|
|
169
|
+
value
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
static in(...values) {
|
|
173
|
+
return new FilterClass({
|
|
174
|
+
type: "in",
|
|
175
|
+
values
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
static contains(value) {
|
|
179
|
+
return new FilterClass({
|
|
180
|
+
type: "contains",
|
|
181
|
+
value
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
static between(from, to) {
|
|
185
|
+
return new FilterClass({
|
|
186
|
+
type: "range",
|
|
187
|
+
from,
|
|
188
|
+
to
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
static not(filter) {
|
|
192
|
+
return new FilterClass({
|
|
193
|
+
type: "not",
|
|
194
|
+
filter: filter.ast
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
static and(...filters) {
|
|
198
|
+
return new FilterClass({
|
|
199
|
+
type: "and",
|
|
200
|
+
filters: filters.map((f) => f.ast)
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
static or(...filters) {
|
|
204
|
+
return new FilterClass({
|
|
205
|
+
type: "or",
|
|
206
|
+
filters: filters.map((f) => f.ast)
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
constructor(ast) {
|
|
210
|
+
this.ast = ast;
|
|
211
|
+
}
|
|
212
|
+
"~Filter" = FilterClass.variance;
|
|
213
|
+
};
|
|
214
|
+
const Filter1 = FilterClass;
|
|
215
|
+
const propsFilterToAst = (predicates) => {
|
|
216
|
+
let idFilter;
|
|
217
|
+
if ("id" in predicates) {
|
|
218
|
+
assertArgument(typeof predicates.id === "string" || Array.isArray(predicates.id), "predicates.id", "invalid id filter");
|
|
219
|
+
idFilter = typeof predicates.id === "string" ? [predicates.id] : predicates.id;
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
id: idFilter,
|
|
223
|
+
props: Object.fromEntries(Object.entries(predicates).filter(([prop, _value]) => prop !== "id").map(([prop, predicate]) => [prop, processPredicate(predicate)]))
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
const processPredicate = (predicate) => {
|
|
227
|
+
if (FilterClass.is(predicate)) return predicate.ast;
|
|
228
|
+
if (Array.isArray(predicate)) throw new Error("Array predicates are not yet supported.");
|
|
229
|
+
if (!isRef(predicate) && typeof predicate === "object" && predicate !== null) return {
|
|
230
|
+
type: "object",
|
|
231
|
+
typename: null,
|
|
232
|
+
props: Object.fromEntries(Object.entries(predicate).map(([key, value]) => [key, processPredicate(value)]))
|
|
233
|
+
};
|
|
234
|
+
return FilterClass.eq(predicate).ast;
|
|
235
|
+
};
|
|
236
|
+
var QueryClass = class QueryClass {
|
|
237
|
+
static variance = {};
|
|
238
|
+
static is(value) {
|
|
239
|
+
return typeof value === "object" && value !== null && "~Query" in value;
|
|
240
|
+
}
|
|
241
|
+
static fromAst(ast) {
|
|
242
|
+
return new QueryClass(ast);
|
|
243
|
+
}
|
|
244
|
+
static select(filter) {
|
|
245
|
+
return new QueryClass({
|
|
246
|
+
type: "select",
|
|
247
|
+
filter: filter.ast
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
static type(schema, predicates) {
|
|
251
|
+
return new QueryClass({
|
|
252
|
+
type: "select",
|
|
253
|
+
filter: FilterClass.type(schema, predicates).ast
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
static all(...queries) {
|
|
257
|
+
if (queries.length === 0) throw new TypeError("Query.all combines results of multiple queries, to query all objects use Query.select(Filter.everything())");
|
|
258
|
+
return new QueryClass({
|
|
259
|
+
type: "union",
|
|
260
|
+
queries: queries.map((q) => q.ast)
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
static without(source, exclude) {
|
|
264
|
+
return new QueryClass({
|
|
265
|
+
type: "set-difference",
|
|
266
|
+
source: source.ast,
|
|
267
|
+
exclude: exclude.ast
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
constructor(ast) {
|
|
271
|
+
this.ast = ast;
|
|
272
|
+
}
|
|
273
|
+
"~Query" = QueryClass.variance;
|
|
274
|
+
select(filter) {
|
|
275
|
+
if (FilterClass.is(filter)) return new QueryClass({
|
|
276
|
+
type: "filter",
|
|
277
|
+
selection: this.ast,
|
|
278
|
+
filter: filter.ast
|
|
279
|
+
});
|
|
280
|
+
else return new QueryClass({
|
|
281
|
+
type: "filter",
|
|
282
|
+
selection: this.ast,
|
|
283
|
+
filter: FilterClass.props(filter).ast
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
reference(key) {
|
|
287
|
+
return new QueryClass({
|
|
288
|
+
type: "reference-traversal",
|
|
289
|
+
anchor: this.ast,
|
|
290
|
+
property: key
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
referencedBy(target, key) {
|
|
294
|
+
const typename = target !== void 0 ? (assertArgument(typeof target === "string", "target"), assertArgument(!target.startsWith("dxn:"), "target"), target) : null;
|
|
295
|
+
return new QueryClass({
|
|
296
|
+
type: "incoming-references",
|
|
297
|
+
anchor: this.ast,
|
|
298
|
+
property: key ?? null,
|
|
299
|
+
typename
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
sourceOf(relation, predicates) {
|
|
303
|
+
return new QueryClass({
|
|
304
|
+
type: "relation",
|
|
305
|
+
anchor: this.ast,
|
|
306
|
+
direction: "outgoing",
|
|
307
|
+
filter: FilterClass.type(relation, predicates).ast
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
targetOf(relation, predicates) {
|
|
311
|
+
return new QueryClass({
|
|
312
|
+
type: "relation",
|
|
313
|
+
anchor: this.ast,
|
|
314
|
+
direction: "incoming",
|
|
315
|
+
filter: FilterClass.type(relation, predicates).ast
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
source() {
|
|
319
|
+
return new QueryClass({
|
|
320
|
+
type: "relation-traversal",
|
|
321
|
+
anchor: this.ast,
|
|
322
|
+
direction: "source"
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
target() {
|
|
326
|
+
return new QueryClass({
|
|
327
|
+
type: "relation-traversal",
|
|
328
|
+
anchor: this.ast,
|
|
329
|
+
direction: "target"
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
parent() {
|
|
333
|
+
return new QueryClass({
|
|
334
|
+
type: "hierarchy-traversal",
|
|
335
|
+
anchor: this.ast,
|
|
336
|
+
direction: "to-parent"
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
children() {
|
|
340
|
+
return new QueryClass({
|
|
341
|
+
type: "hierarchy-traversal",
|
|
342
|
+
anchor: this.ast,
|
|
343
|
+
direction: "to-children"
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
orderBy(...order) {
|
|
347
|
+
return new QueryClass({
|
|
348
|
+
type: "order",
|
|
349
|
+
query: this.ast,
|
|
350
|
+
order: order.map((o) => o.ast)
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
limit(limit) {
|
|
354
|
+
return new QueryClass({
|
|
355
|
+
type: "limit",
|
|
356
|
+
query: this.ast,
|
|
357
|
+
limit
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
options(options) {
|
|
361
|
+
return new QueryClass({
|
|
362
|
+
type: "options",
|
|
363
|
+
query: this.ast,
|
|
364
|
+
options
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
const Query1 = QueryClass;
|
|
369
|
+
const RefTypeId = Symbol("@dxos/echo-query/Ref");
|
|
370
|
+
const isRef = (obj) => {
|
|
371
|
+
return obj && typeof obj === "object" && RefTypeId in obj;
|
|
372
|
+
};
|
|
373
|
+
const makeTypeDxn = (typename) => {
|
|
374
|
+
assertArgument(typeof typename === "string", "typename");
|
|
375
|
+
assertArgument(!typename.startsWith("dxn:"), "typename");
|
|
376
|
+
return `dxn:type:${typename}`;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
//#endregion
|
|
380
|
+
export { Filter1 as Filter, Filter1, Order2 as Order, Query1 as Query, Query1 };
|
|
381
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["ast: QueryAST.Order","Order2: typeof Order$","ast: QueryAST.Filter","Filter1: typeof Filter$","idFilter: readonly ObjectId[] | undefined","ast: QueryAST.Query","Query1: typeof Query$","RefTypeId: unique symbol"],"sources":["../../../../../common/invariant/dist/lib/browser/index.mjs","../../src/query-lite/query-lite.ts"],"sourcesContent":["// src/invariant.ts\nvar invariant = (condition, message, meta) => {\n if (condition) {\n return;\n }\n if (message?.startsWith(\"BUG\")) {\n debugger;\n }\n let errorMessage = \"invariant violation\";\n if (message) {\n errorMessage += `: ${message}`;\n }\n if (meta?.A) {\n errorMessage += ` [${meta.A[0]}]`;\n }\n if (meta?.F) {\n errorMessage += ` at ${getRelativeFilename(meta.F)}:${meta.L}`;\n }\n const error = new InvariantViolation(errorMessage);\n Error.captureStackTrace(error, invariant);\n throw error;\n};\nvar InvariantViolation = class extends Error {\n constructor(message) {\n super(message);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n};\nvar getRelativeFilename = (filename) => {\n const match = filename.match(/.+\\/(packages\\/.+\\/.+)/);\n if (match) {\n const [, filePath] = match;\n return filePath;\n }\n return filename;\n};\nvar failedInvariant = (message1, message2, meta) => {\n let errorMessage = \"invariant violation\";\n const message = [\n message1,\n message2\n ].filter((str) => typeof str === \"string\").join(\" \");\n if (message) {\n errorMessage += `: ${message}`;\n }\n if (meta?.A) {\n errorMessage += ` [${meta.A[0]}]`;\n }\n if (meta?.F) {\n errorMessage += ` at ${getRelativeFilename(meta.F)}:${meta.L}`;\n }\n throw new InvariantViolation(errorMessage);\n};\n\n// src/assert.ts\nvar assertArgument = (condition, argumentName, message) => {\n if (!condition) {\n const error = new TypeError(`Invalid argument \\`${argumentName}\\`` + (message ? `: ${message}` : \"\"));\n Error.captureStackTrace(error, assertArgument);\n throw error;\n }\n};\nvar assertState = (condition, message) => {\n if (!condition) {\n const error = new InvalidStateError(message);\n Error.captureStackTrace(error, assertState);\n throw error;\n }\n};\nvar InvalidStateError = class extends Error {\n};\nexport {\n InvalidStateError,\n InvariantViolation,\n assertArgument,\n assertState,\n failedInvariant,\n invariant\n};\n//# sourceMappingURL=index.mjs.map\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\n\nimport type { Filter as Filter$, Order as Order$, Query as Query$, Ref } from '@dxos/echo';\nimport type { ForeignKey, QueryAST } from '@dxos/echo-protocol';\nimport { assertArgument } from '@dxos/invariant';\nimport type { DXN, ObjectId } from '@dxos/keys';\n\n//\n// Light-weight implementation of query execution.\n//\n\n// TODO(wittjosiah): The `export * as ...` syntax causes tsdown to genereate multiple files which breaks the sandbox.\n\nclass OrderClass implements Order$.Any {\n private static variance: Order$.Any['~Order'] = {} as Order$.Any['~Order'];\n\n static is(value: unknown): value is Order$.Any {\n return typeof value === 'object' && value !== null && '~Order' in value;\n }\n\n constructor(public readonly ast: QueryAST.Order) {}\n\n '~Order' = OrderClass.variance;\n}\n\nnamespace Order1 {\n export const natural: Order$.Any = new OrderClass({ kind: 'natural' });\n export const property = <T>(property: keyof T & string, direction: QueryAST.OrderDirection): Order$.Order<T> =>\n new OrderClass({\n kind: 'property',\n property,\n direction,\n });\n export const rank = <T>(direction: QueryAST.OrderDirection = 'desc'): Order$.Order<T> =>\n new OrderClass({\n kind: 'rank',\n direction,\n });\n}\n\nconst Order2: typeof Order$ = Order1;\nexport { Order2 as Order };\n\nclass FilterClass implements Filter$.Any {\n private static variance: Filter$.Any['~Filter'] = {} as Filter$.Any['~Filter'];\n\n static is(value: unknown): value is Filter$.Any {\n return typeof value === 'object' && value !== null && '~Filter' in value;\n }\n\n static fromAst(ast: QueryAST.Filter): Filter$.Any {\n return new FilterClass(ast);\n }\n\n static everything(): FilterClass {\n return new FilterClass({\n type: 'object',\n typename: null,\n props: {},\n });\n }\n\n static nothing(): FilterClass {\n return new FilterClass({\n type: 'not',\n filter: {\n type: 'object',\n typename: null,\n props: {},\n },\n });\n }\n\n static relation() {\n return new FilterClass({\n type: 'object',\n typename: null,\n props: {},\n });\n }\n\n static id(...ids: ObjectId[]): Filter$.Any {\n // assertArgument(\n // ids.every((id) => ObjectId.isValid(id)),\n // 'ids',\n // 'ids must be valid',\n // );\n\n if (ids.length === 0) {\n return FilterClass.nothing();\n }\n\n return new FilterClass({\n type: 'object',\n typename: null,\n id: ids,\n props: {},\n });\n }\n\n static type<S extends Schema.Schema.All>(\n schema: S | string,\n props?: Filter$.Props<Schema.Schema.Type<S>>,\n ): Filter$.Filter<Schema.Schema.Type<S>> {\n if (typeof schema !== 'string') {\n throw new TypeError('expected typename as the first paramter');\n }\n return new FilterClass({\n type: 'object',\n typename: makeTypeDxn(schema),\n ...propsFilterToAst(props ?? {}),\n });\n }\n\n static typename(typename: string): Filter$.Any {\n return new FilterClass({\n type: 'object',\n typename: makeTypeDxn(typename),\n props: {},\n });\n }\n\n static typeDXN(dxn: DXN): Filter$.Any {\n return new FilterClass({\n type: 'object',\n typename: dxn.toString(),\n props: {},\n });\n }\n\n static tag(tag: string): Filter$.Any {\n return new FilterClass({\n type: 'tag',\n tag,\n });\n }\n\n static props<T>(props: Filter$.Props<T>): Filter$.Filter<T> {\n return new FilterClass({\n type: 'object',\n typename: null,\n ...propsFilterToAst(props),\n });\n }\n\n static text(text: string, options?: Filter$.TextSearchOptions): Filter$.Any {\n return new FilterClass({\n type: 'text-search',\n text,\n searchKind: options?.type,\n });\n }\n\n static foreignKeys<S extends Schema.Schema.All>(\n schema: S | string,\n keys: ForeignKey[],\n ): Filter$.Filter<Schema.Schema.Type<S>> {\n assertArgument(typeof schema === 'string', 'schema');\n assertArgument(!schema.startsWith('dxn:'), 'schema');\n return new FilterClass({\n type: 'object',\n typename: `dxn:type:${schema}`,\n props: {},\n foreignKeys: keys,\n });\n }\n\n static eq<T>(value: T): Filter$.Filter<T | undefined> {\n if (!isRef(value) && typeof value === 'object' && value !== null) {\n throw new TypeError('Cannot use object as a value for eq filter');\n }\n\n return new FilterClass({\n type: 'compare',\n operator: 'eq',\n value: isRef(value) ? value.noInline().encode() : value,\n });\n }\n\n static neq<T>(value: T): Filter$.Filter<T | undefined> {\n return new FilterClass({\n type: 'compare',\n operator: 'neq',\n value,\n });\n }\n\n static gt<T>(value: T): Filter$.Filter<T | undefined> {\n return new FilterClass({\n type: 'compare',\n operator: 'gt',\n value,\n });\n }\n\n static gte<T>(value: T): Filter$.Filter<T | undefined> {\n return new FilterClass({\n type: 'compare',\n operator: 'gte',\n value,\n });\n }\n\n static lt<T>(value: T): Filter$.Filter<T | undefined> {\n return new FilterClass({\n type: 'compare',\n operator: 'lt',\n value,\n });\n }\n\n static lte<T>(value: T): Filter$.Filter<T | undefined> {\n return new FilterClass({\n type: 'compare',\n operator: 'lte',\n value,\n });\n }\n\n static in<T>(...values: T[]): Filter$.Filter<T | undefined> {\n return new FilterClass({\n type: 'in',\n values,\n });\n }\n\n static contains<T>(value: T): Filter$.Filter<readonly T[] | undefined> {\n return new FilterClass({\n type: 'contains',\n value,\n });\n }\n\n static between<T>(from: T, to: T): Filter$.Filter<unknown> {\n return new FilterClass({\n type: 'range',\n from,\n to,\n });\n }\n\n static not<F extends Filter$.Any>(filter: F): Filter$.Filter<Filter$.Type<F>> {\n return new FilterClass({\n type: 'not',\n filter: filter.ast,\n });\n }\n\n static and<Filters extends readonly Filter$.Any[]>(\n ...filters: Filters\n ): Filter$.Filter<Filter$.Type<Filters[number]>> {\n return new FilterClass({\n type: 'and',\n filters: filters.map((f) => f.ast),\n });\n }\n\n static or<Filters extends readonly Filter$.Any[]>(\n ...filters: Filters\n ): Filter$.Filter<Filter$.Type<Filters[number]>> {\n return new FilterClass({\n type: 'or',\n filters: filters.map((f) => f.ast),\n });\n }\n\n private constructor(public readonly ast: QueryAST.Filter) {}\n\n '~Filter' = FilterClass.variance;\n}\n\nexport const Filter1: typeof Filter$ = FilterClass;\nexport { Filter1 as Filter };\n\n/**\n * All property paths inside T that are references.\n */\n// TODO(dmaretskyi): Filter only properties that are references (or optional references, or unions that include references).\ntype RefPropKey<T> = keyof T & string;\n\nconst propsFilterToAst = (predicates: Filter$.Props<any>): Pick<QueryAST.FilterObject, 'id' | 'props'> => {\n let idFilter: readonly ObjectId[] | undefined;\n if ('id' in predicates) {\n assertArgument(\n typeof predicates.id === 'string' || Array.isArray(predicates.id),\n 'predicates.id',\n 'invalid id filter',\n );\n idFilter = typeof predicates.id === 'string' ? [predicates.id] : predicates.id;\n }\n\n return {\n id: idFilter,\n props: Object.fromEntries(\n Object.entries(predicates)\n .filter(([prop, _value]) => prop !== 'id')\n .map(([prop, predicate]) => [prop, processPredicate(predicate)]),\n ) as Record<string, QueryAST.Filter>,\n };\n};\n\nconst processPredicate = (predicate: any): QueryAST.Filter => {\n if (FilterClass.is(predicate)) {\n return predicate.ast;\n }\n\n if (Array.isArray(predicate)) {\n throw new Error('Array predicates are not yet supported.');\n }\n\n if (!isRef(predicate) && typeof predicate === 'object' && predicate !== null) {\n const nestedProps = Object.fromEntries(\n Object.entries(predicate).map(([key, value]) => [key, processPredicate(value)]),\n );\n\n return {\n type: 'object',\n typename: null,\n props: nestedProps,\n };\n }\n\n return FilterClass.eq(predicate).ast;\n};\n\nclass QueryClass implements Query$.Any {\n private static variance: Query$.Any['~Query'] = {} as Query$.Any['~Query'];\n\n static is(value: unknown): value is Query$.Any {\n return typeof value === 'object' && value !== null && '~Query' in value;\n }\n\n static fromAst(ast: QueryAST.Query): Query$.Any {\n return new QueryClass(ast);\n }\n\n static select<F extends Filter$.Any>(filter: F): Query$.Query<Filter$.Type<F>> {\n return new QueryClass({\n type: 'select',\n filter: filter.ast,\n });\n }\n\n static type(schema: Schema.Schema.All | string, predicates?: Filter$.Props<unknown>): Query$.Any {\n return new QueryClass({\n type: 'select',\n filter: FilterClass.type(schema, predicates).ast,\n });\n }\n\n static all(...queries: Query$.Any[]): Query$.Any {\n if (queries.length === 0) {\n throw new TypeError(\n 'Query.all combines results of multiple queries, to query all objects use Query.select(Filter.everything())',\n );\n }\n return new QueryClass({\n type: 'union',\n queries: queries.map((q) => q.ast),\n });\n }\n\n static without<T>(source: Query$.Query<T>, exclude: Query$.Query<T>): Query$.Query<T> {\n return new QueryClass({\n type: 'set-difference',\n source: source.ast,\n exclude: exclude.ast,\n });\n }\n\n constructor(public readonly ast: QueryAST.Query) {}\n\n '~Query' = QueryClass.variance;\n\n select(filter: Filter$.Any | Filter$.Props<any>): Query$.Any {\n if (FilterClass.is(filter)) {\n return new QueryClass({\n type: 'filter',\n selection: this.ast,\n filter: filter.ast,\n });\n } else {\n return new QueryClass({\n type: 'filter',\n selection: this.ast,\n filter: FilterClass.props(filter).ast,\n });\n }\n }\n\n reference(key: string): Query$.Any {\n return new QueryClass({\n type: 'reference-traversal',\n anchor: this.ast,\n property: key,\n });\n }\n\n referencedBy(target?: Schema.Schema.All | string, key?: string): Query$.Any {\n const typename =\n target !== undefined\n ? (assertArgument(typeof target === 'string', 'target'),\n assertArgument(!target.startsWith('dxn:'), 'target'),\n target)\n : null;\n return new QueryClass({\n type: 'incoming-references',\n anchor: this.ast,\n property: key ?? null,\n typename,\n });\n }\n\n sourceOf(relation: Schema.Schema.All | string, predicates?: Filter$.Props<unknown> | undefined): Query$.Any {\n return new QueryClass({\n type: 'relation',\n anchor: this.ast,\n direction: 'outgoing',\n filter: FilterClass.type(relation, predicates).ast,\n });\n }\n\n targetOf(relation: Schema.Schema.All | string, predicates?: Filter$.Props<unknown> | undefined): Query$.Any {\n return new QueryClass({\n type: 'relation',\n anchor: this.ast,\n direction: 'incoming',\n filter: FilterClass.type(relation, predicates).ast,\n });\n }\n\n source(): Query$.Any {\n return new QueryClass({\n type: 'relation-traversal',\n anchor: this.ast,\n direction: 'source',\n });\n }\n\n target(): Query$.Any {\n return new QueryClass({\n type: 'relation-traversal',\n anchor: this.ast,\n direction: 'target',\n });\n }\n\n parent(): Query$.Any {\n return new QueryClass({\n type: 'hierarchy-traversal',\n anchor: this.ast,\n direction: 'to-parent',\n });\n }\n\n children(): Query$.Any {\n return new QueryClass({\n type: 'hierarchy-traversal',\n anchor: this.ast,\n direction: 'to-children',\n });\n }\n\n orderBy(...order: Order$.Any[]): Query$.Any {\n return new QueryClass({\n type: 'order',\n query: this.ast,\n order: order.map((o) => o.ast),\n });\n }\n\n limit(limit: number): Query$.Any {\n return new QueryClass({\n type: 'limit',\n query: this.ast,\n limit,\n });\n }\n\n options(options: QueryAST.QueryOptions): Query$.Any {\n return new QueryClass({\n type: 'options',\n query: this.ast,\n options,\n });\n }\n}\n\nexport const Query1: typeof Query$ = QueryClass;\nexport { Query1 as Query };\n\nconst RefTypeId: unique symbol = Symbol('@dxos/echo-query/Ref');\nconst isRef = (obj: any): obj is Ref.Ref<any> => {\n return obj && typeof obj === 'object' && RefTypeId in obj;\n};\n\nconst makeTypeDxn = (typename: string) => {\n assertArgument(typeof typename === 'string', 'typename');\n assertArgument(!typename.startsWith('dxn:'), 'typename');\n return `dxn:type:${typename}`;\n};\n"],"mappings":";AAuDA,IAAI,kBAAkB,WAAW,cAAc,YAAY;AACzD,KAAI,CAAC,WAAW;EACd,MAAM,wBAAQ,IAAI,UAAU,sBAAsB,aAAa,OAAO,UAAU,KAAK,YAAY,IAAI;AACrG,QAAM,kBAAkB,OAAO,eAAe;AAC9C,QAAM;;;;;;AC1CV,IAAM,aAAN,MAAM,WAAiC;CACrC,OAAe,WAAiC,EAAE;CAElD,OAAO,GAAG,OAAqC;AAC7C,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,YAAY;;CAGpE,YAAY,AAAgBA,KAAqB;EAArB;;CAE5B,WAAW,WAAW;;;;kBAIa,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;oBAC1C,UAA4B,cACtD,IAAI,WAAW;EACb,MAAM;EACN;EACA;EACD,CAAC;gBACoB,YAAqC,WAC3D,IAAI,WAAW;EACb,MAAM;EACN;EACD,CAAC;;AAGN,MAAMC,SAAwB;AAG9B,IAAM,cAAN,MAAM,YAAmC;CACvC,OAAe,WAAmC,EAAE;CAEpD,OAAO,GAAG,OAAsC;AAC9C,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa;;CAGrE,OAAO,QAAQ,KAAmC;AAChD,SAAO,IAAI,YAAY,IAAI;;CAG7B,OAAO,aAA0B;AAC/B,SAAO,IAAI,YAAY;GACrB,MAAM;GACN,UAAU;GACV,OAAO,EAAE;GACV,CAAC;;CAGJ,OAAO,UAAuB;AAC5B,SAAO,IAAI,YAAY;GACrB,MAAM;GACN,QAAQ;IACN,MAAM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index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/parser/gen/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,KAAK,KAAK,MAAM,eAAe,CAAC;AAEvC,yBAAiB,QAAQ,CAAC;IACjB,MAAM,MAAM,EAAE,QAAiB,CAAC;IAChC,MAAM,IAAI,cAAQ,CAAC;IACnB,MAAM,MAAM,UAAgC,CAAC;CACrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../../../src/parser/gen/query.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAA;AAElC,eAAO,MAAM,MAAM,UAcjB,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const Query = 1, Assignment = 2, Identifier = 3, Filter = 7, TagFilter = 8, Tag = 9, TextFilter = 10, String = 11, TypeFilter = 12, TypeKeyword = 13, PropertyFilter = 15, PropertyPath = 16, Value = 18, Number = 19, Boolean = 20, Null = 21, ObjectLiteral = 22, ObjectProperty = 24, ArrayLiteral = 27, Not = 30, And = 31, Or = 32, Relation = 33, ArrowRight = 34, ArrowLeft = 35;
|
|
2
|
+
//# sourceMappingURL=query.terms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.terms.d.ts","sourceRoot":"","sources":["../../../../../src/parser/gen/query.terms.ts"],"names":[],"mappings":"AACA,eAAO,MACL,KAAK,IAAI,EACT,UAAU,IAAI,EACd,UAAU,IAAI,EACd,MAAM,IAAI,EACV,SAAS,IAAI,EACb,GAAG,IAAI,EACP,UAAU,KAAK,EACf,MAAM,KAAK,EACX,UAAU,KAAK,EACf,WAAW,KAAK,EAChB,cAAc,KAAK,EACnB,YAAY,KAAK,EACjB,KAAK,KAAK,EACV,MAAM,KAAK,EACX,OAAO,KAAK,EACZ,IAAI,KAAK,EACT,aAAa,KAAK,EAClB,cAAc,KAAK,EACnB,YAAY,KAAK,EACjB,GAAG,KAAK,EACR,GAAG,KAAK,EACR,EAAE,KAAK,EACP,QAAQ,KAAK,EACb,UAAU,KAAK,EACf,SAAS,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/parser/index.ts"],"names":[],"mappings":"AAIA,cAAc,OAAO,CAAC;AACtB,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type Tree } from '@lezer/common';
|
|
2
|
+
import { Filter, type Tag } from '@dxos/echo';
|
|
3
|
+
export type BuildResult = {
|
|
4
|
+
filter?: Filter.Any;
|
|
5
|
+
name?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Stateless query builder that parses DSL trees into filters.
|
|
9
|
+
*
|
|
10
|
+
* NOTE: QueryBuilder was largely developed using Claude Sonnet 4.5 (in Windsurf)..
|
|
11
|
+
* To modify the functionality, create a minimal breaking test and direct the LLM to fix either the grammar or builder.
|
|
12
|
+
*/
|
|
13
|
+
export declare class QueryBuilder {
|
|
14
|
+
private readonly _tags?;
|
|
15
|
+
private readonly _parser;
|
|
16
|
+
constructor(_tags?: Tag.Map | undefined);
|
|
17
|
+
/**
|
|
18
|
+
* Check valid input.
|
|
19
|
+
*/
|
|
20
|
+
validate(input: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Build a query from the input string.
|
|
23
|
+
*/
|
|
24
|
+
build(input: string): BuildResult;
|
|
25
|
+
/**
|
|
26
|
+
* Build a query from a parsed DSL tree.
|
|
27
|
+
*/
|
|
28
|
+
buildQuery(tree: Tree, input: string): BuildResult;
|
|
29
|
+
/**
|
|
30
|
+
* Parse an assignment node.
|
|
31
|
+
*/
|
|
32
|
+
private _parseAssignment;
|
|
33
|
+
/**
|
|
34
|
+
* Parse an expression node.
|
|
35
|
+
*/
|
|
36
|
+
private _parseExpression;
|
|
37
|
+
/**
|
|
38
|
+
* Parse a binary expression (AND/OR).
|
|
39
|
+
*/
|
|
40
|
+
private _parseBinaryExpression;
|
|
41
|
+
/**
|
|
42
|
+
* Parse a Filter node.
|
|
43
|
+
*/
|
|
44
|
+
private _parseFilter;
|
|
45
|
+
/**
|
|
46
|
+
* Parse a TypeFilter node (type:typename).
|
|
47
|
+
*/
|
|
48
|
+
private _parseTypeFilter;
|
|
49
|
+
/**
|
|
50
|
+
* Parse a TextFilter node (quoted string).
|
|
51
|
+
*/
|
|
52
|
+
private _parseTextFilter;
|
|
53
|
+
/**
|
|
54
|
+
* Parse an ObjectLiteral node.
|
|
55
|
+
*/
|
|
56
|
+
private _parseObjectLiteral;
|
|
57
|
+
/**
|
|
58
|
+
* Parse an ObjectProperty node.
|
|
59
|
+
*/
|
|
60
|
+
private _parseObjectProperty;
|
|
61
|
+
/**
|
|
62
|
+
* Parse a PropertyFilter node (property:value).
|
|
63
|
+
*/
|
|
64
|
+
private _parsePropertyFilter;
|
|
65
|
+
/**
|
|
66
|
+
* Parse a PropertyPath node (supports dot notation).
|
|
67
|
+
*/
|
|
68
|
+
private _parsePropertyPath;
|
|
69
|
+
/**
|
|
70
|
+
* Parse a TagFilter node (#tag).
|
|
71
|
+
*/
|
|
72
|
+
private _parseTagFilter;
|
|
73
|
+
/**
|
|
74
|
+
* Parse a Value node.
|
|
75
|
+
*/
|
|
76
|
+
private _parseValue;
|
|
77
|
+
/**
|
|
78
|
+
* Get the text content of the current node.
|
|
79
|
+
*/
|
|
80
|
+
private _getNodeText;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=query-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-builder.d.ts","s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|
1
|
+
{"version":3,"file":"query.test.d.ts","sourceRoot":"","sources":["../../../../src/parser/query.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/query-lite/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Filter as Filter$, Order as Order$, Query as Query$ } from '@dxos/echo';
|
|
2
|
+
declare const Order2: typeof Order$;
|
|
3
|
+
export { Order2 as Order };
|
|
4
|
+
export declare const Filter1: typeof Filter$;
|
|
5
|
+
export { Filter1 as Filter };
|
|
6
|
+
export declare const Query1: typeof Query$;
|
|
7
|
+
export { Query1 as Query };
|
|
8
|
+
//# sourceMappingURL=query-lite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-lite.d.ts","sourceRoot":"","sources":["../../../../src/query-lite/query-lite.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,IAAI,OAAO,EAAE,KAAK,IAAI,MAAM,EAAE,KAAK,IAAI,MAAM,EAAO,MAAM,YAAY,CAAC;AAsC3F,QAAA,MAAM,MAAM,EAAE,OAAO,MAAe,CAAC;AACrC,OAAO,EAAE,MAAM,IAAI,KAAK,EAAE,CAAC;AAsO3B,eAAO,MAAM,OAAO,EAAE,OAAO,OAAqB,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,CAAC;AAwN7B,eAAO,MAAM,MAAM,EAAE,OAAO,MAAmB,CAAC;AAChD,OAAO,EAAE,MAAM,IAAI,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/sandbox/index.ts"],"names":[],"mappings":"AAIA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Resource } from '@dxos/context';
|
|
2
|
+
import { type QueryAST } from '@dxos/echo';
|
|
3
|
+
import { type QuickJSWASMModule } from '@dxos/vendor-quickjs';
|
|
4
|
+
/**
|
|
5
|
+
* Evaluates queries written in JavaScript using QuickJS.
|
|
6
|
+
* Queries are expected to use the echo Query API.
|
|
7
|
+
* `Query`, `Filter` and `Order` are provided as globals.
|
|
8
|
+
*/
|
|
9
|
+
export declare class QuerySandbox extends Resource {
|
|
10
|
+
#private;
|
|
11
|
+
private static quickJS;
|
|
12
|
+
static getQuickJS(): Promise<QuickJSWASMModule>;
|
|
13
|
+
protected _open(): Promise<void>;
|
|
14
|
+
protected _close(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Evaluates the query code.
|
|
17
|
+
* @param queryCode Example: `Query.select(Filter.typename('dxos.org/type/Person'))`
|
|
18
|
+
*/
|
|
19
|
+
eval(queryCode: string): QueryAST.Query;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=query-sandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-sandbox.d.ts","sourceRoot":"","sources":["../../../../src/sandbox/query-sandbox.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAS,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAuB,KAAK,iBAAiB,EAAiB,MAAM,sBAAsB,CAAC;AAMlG;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,QAAQ;;IAExC,OAAO,CAAC,MAAM,CAAC,OAAO,CAA2C;IACjE,MAAM,CAAC,UAAU;cAUQ,KAAK;cAcL,MAAM;IAI/B;;;OAGG;IACH,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,CAAC,KAAK;CAkBxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-sandbox.test.d.ts","sourceRoot":"","sources":["../../../../src/sandbox/query-sandbox.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type QuickJSContext, type QuickJSHandle, type SuccessOrFail } from '@dxos/vendor-quickjs';
|
|
2
|
+
/**
|
|
3
|
+
* Unwraps a result and throws the underlying error.
|
|
4
|
+
*
|
|
5
|
+
* Replacement for `QuickJScontext.unwrapResult` because that seems to cause an OOM.
|
|
6
|
+
*/
|
|
7
|
+
export declare const unwrapResult: <T>(context: QuickJSContext, result: SuccessOrFail<T, QuickJSHandle>) => T;
|
|
8
|
+
//# sourceMappingURL=quickjs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickjs.d.ts","sourceRoot":"","sources":["../../../../src/sandbox/quickjs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEnG;;;;GAIG;AAEH,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,SAAS,cAAc,EAAE,QAAQ,aAAa,CAAC,CAAC,EAAE,aAAa,CAAC,KAAG,CAoBlG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quickjs.test.d.ts","sourceRoot":"","sources":["../../../../src/sandbox/quickjs.test.ts"],"names":[],"mappings":""}
|