@dxos/echo-query 0.8.4-main.3eb6e50203 → 0.8.4-main.3fbcb4aa9b
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/dist/lib/neutral/index.mjs +216 -18
- package/dist/lib/neutral/index.mjs.map +3 -3
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/query-lite/index.d.ts +1399 -223
- package/dist/query-lite/index.d.ts.map +1 -1
- package/dist/query-lite/index.js +184 -17
- package/dist/query-lite/index.js.map +1 -1
- package/dist/types/src/parser/gen/index.d.ts.map +1 -1
- package/dist/types/src/parser/query-builder.d.ts +7 -0
- package/dist/types/src/parser/query-builder.d.ts.map +1 -1
- package/dist/types/src/query-lite/query-lite.d.ts.map +1 -1
- package/dist/types/src/sandbox/query-sandbox.d.ts +1 -1
- package/dist/types/src/sandbox/query-sandbox.d.ts.map +1 -1
- package/dist/types/src/sandbox/quickjs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -16
- package/src/parser/query-builder.ts +269 -9
- package/src/parser/query.test.ts +144 -31
- package/src/query-lite/query-lite.ts +260 -21
- package/src/sandbox/query-sandbox.test.ts +10 -10
- package/src/sandbox/query-sandbox.ts +1 -1
|
@@ -16,7 +16,7 @@ import type { DXN, ObjectId } from '@dxos/keys';
|
|
|
16
16
|
// TODO(wittjosiah): The `export * as ...` syntax causes tsdown to genereate multiple files which breaks the sandbox.
|
|
17
17
|
|
|
18
18
|
class OrderClass implements Order$.Any {
|
|
19
|
-
private static variance: Order$.Any['~Order'] = {} as Order$.Any['~Order'];
|
|
19
|
+
private static 'variance': Order$.Any['~Order'] = {} as Order$.Any['~Order'];
|
|
20
20
|
|
|
21
21
|
static is(value: unknown): value is Order$.Any {
|
|
22
22
|
return typeof value === 'object' && value !== null && '~Order' in value;
|
|
@@ -46,7 +46,7 @@ const Order2: typeof Order$ = Order1;
|
|
|
46
46
|
export { Order2 as Order };
|
|
47
47
|
|
|
48
48
|
class FilterClass implements Filter$.Any {
|
|
49
|
-
private static variance: Filter$.Any['~Filter'] = {} as Filter$.Any['~Filter'];
|
|
49
|
+
private static 'variance': Filter$.Any['~Filter'] = {} as Filter$.Any['~Filter'];
|
|
50
50
|
|
|
51
51
|
static is(value: unknown): value is Filter$.Any {
|
|
52
52
|
return typeof value === 'object' && value !== null && '~Filter' in value;
|
|
@@ -221,7 +221,7 @@ class FilterClass implements Filter$.Any {
|
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
static in<T>(...values: T[]): Filter$.Filter<T
|
|
224
|
+
static in<T>(...values: T[]): Filter$.Filter<T> {
|
|
225
225
|
return new FilterClass({
|
|
226
226
|
type: 'in',
|
|
227
227
|
values,
|
|
@@ -235,7 +235,7 @@ class FilterClass implements Filter$.Any {
|
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
static between<T>(from: T, to: T): Filter$.Filter<
|
|
238
|
+
static between<T>(from: T, to: T): Filter$.Filter<T> {
|
|
239
239
|
return new FilterClass({
|
|
240
240
|
type: 'range',
|
|
241
241
|
from,
|
|
@@ -243,6 +243,47 @@ class FilterClass implements Filter$.Any {
|
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
+
static updated(range: { after?: Date | number; before?: Date | number }): Filter$.Any {
|
|
247
|
+
return FilterClass._timeRangeFilter('updatedAt', range);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
static created(range: { after?: Date | number; before?: Date | number }): Filter$.Any {
|
|
251
|
+
return FilterClass._timeRangeFilter('createdAt', range);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
static childOf(parents: unknown | DXN | (unknown | DXN)[], options?: { transitive?: boolean }): Filter$.Any {
|
|
255
|
+
const items = Array.isArray(parents) ? parents : [parents];
|
|
256
|
+
const dxns = items.map((item) => {
|
|
257
|
+
if (isDxnLike(item)) {
|
|
258
|
+
return item.toString();
|
|
259
|
+
}
|
|
260
|
+
throw new TypeError('childOf requires DXN values in query-lite');
|
|
261
|
+
});
|
|
262
|
+
return new FilterClass({
|
|
263
|
+
type: 'child-of',
|
|
264
|
+
parents: dxns,
|
|
265
|
+
transitive: options?.transitive ?? true,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private static _timeRangeFilter(
|
|
270
|
+
field: 'updatedAt' | 'createdAt',
|
|
271
|
+
range: { after?: Date | number; before?: Date | number },
|
|
272
|
+
): Filter$.Any {
|
|
273
|
+
const toMs = (d: Date | number) => (typeof d === 'number' ? d : d.getTime());
|
|
274
|
+
const filters: Filter$.Any[] = [];
|
|
275
|
+
if (range.after != null) {
|
|
276
|
+
filters.push(new FilterClass({ type: 'timestamp', field, operator: 'gte', value: toMs(range.after) }));
|
|
277
|
+
}
|
|
278
|
+
if (range.before != null) {
|
|
279
|
+
filters.push(new FilterClass({ type: 'timestamp', field, operator: 'lte', value: toMs(range.before) }));
|
|
280
|
+
}
|
|
281
|
+
if (filters.length === 0) {
|
|
282
|
+
return FilterClass.everything();
|
|
283
|
+
}
|
|
284
|
+
return filters.length === 1 ? filters[0] : FilterClass.and(...filters);
|
|
285
|
+
}
|
|
286
|
+
|
|
246
287
|
static not<F extends Filter$.Any>(filter: F): Filter$.Filter<Filter$.Type<F>> {
|
|
247
288
|
return new FilterClass({
|
|
248
289
|
type: 'not',
|
|
@@ -268,6 +309,11 @@ class FilterClass implements Filter$.Any {
|
|
|
268
309
|
});
|
|
269
310
|
}
|
|
270
311
|
|
|
312
|
+
/** Returns a human-readable string representation of a Filter AST. */
|
|
313
|
+
static pretty(filter: Filter$.Any): string {
|
|
314
|
+
return prettyFilter(filter.ast);
|
|
315
|
+
}
|
|
316
|
+
|
|
271
317
|
private constructor(public readonly ast: QueryAST.Filter) {}
|
|
272
318
|
|
|
273
319
|
'~Filter' = FilterClass.variance;
|
|
@@ -328,7 +374,7 @@ const processPredicate = (predicate: any): QueryAST.Filter => {
|
|
|
328
374
|
};
|
|
329
375
|
|
|
330
376
|
class QueryClass implements Query$.Any {
|
|
331
|
-
private static variance: Query$.Any['~Query'] = {} as Query$.Any['~Query'];
|
|
377
|
+
private static 'variance': Query$.Any['~Query'] = {} as Query$.Any['~Query'];
|
|
332
378
|
|
|
333
379
|
static is(value: unknown): value is Query$.Any {
|
|
334
380
|
return typeof value === 'object' && value !== null && '~Query' in value;
|
|
@@ -345,6 +391,22 @@ class QueryClass implements Query$.Any {
|
|
|
345
391
|
});
|
|
346
392
|
}
|
|
347
393
|
|
|
394
|
+
select(filter: Filter$.Any | Filter$.Props<any>): Query$.Any {
|
|
395
|
+
if (FilterClass.is(filter)) {
|
|
396
|
+
return new QueryClass({
|
|
397
|
+
type: 'filter',
|
|
398
|
+
selection: this.ast,
|
|
399
|
+
filter: filter.ast,
|
|
400
|
+
});
|
|
401
|
+
} else {
|
|
402
|
+
return new QueryClass({
|
|
403
|
+
type: 'filter',
|
|
404
|
+
selection: this.ast,
|
|
405
|
+
filter: FilterClass.props(filter).ast,
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
348
410
|
static type(schema: Schema.Schema.All | string, predicates?: Filter$.Props<unknown>): Query$.Any {
|
|
349
411
|
return new QueryClass({
|
|
350
412
|
type: 'select',
|
|
@@ -372,26 +434,49 @@ class QueryClass implements Query$.Any {
|
|
|
372
434
|
});
|
|
373
435
|
}
|
|
374
436
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
437
|
+
static from(source: any, options?: { includeFeeds?: boolean }): Query$.Any {
|
|
438
|
+
const baseQuery: QueryAST.Query = {
|
|
439
|
+
type: 'select',
|
|
440
|
+
filter: FilterClass.everything().ast,
|
|
441
|
+
};
|
|
442
|
+
const wrapper = new QueryClass(baseQuery);
|
|
443
|
+
return wrapper.from(source, options);
|
|
444
|
+
}
|
|
378
445
|
|
|
379
|
-
|
|
380
|
-
if (
|
|
446
|
+
from(arg: any, options?: { includeFeeds?: boolean }): Query$.Any {
|
|
447
|
+
if (arg === 'all-accessible-spaces') {
|
|
381
448
|
return new QueryClass({
|
|
382
|
-
type: '
|
|
383
|
-
|
|
384
|
-
|
|
449
|
+
type: 'from',
|
|
450
|
+
query: this.ast,
|
|
451
|
+
from: {
|
|
452
|
+
_tag: 'scope',
|
|
453
|
+
scope: {
|
|
454
|
+
...(options?.includeFeeds ? { allQueuesFromSpaces: true } : {}),
|
|
455
|
+
},
|
|
456
|
+
},
|
|
385
457
|
});
|
|
386
|
-
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (_isScopeLike(arg)) {
|
|
387
461
|
return new QueryClass({
|
|
388
|
-
type: '
|
|
389
|
-
|
|
390
|
-
|
|
462
|
+
type: 'from',
|
|
463
|
+
query: this.ast,
|
|
464
|
+
from: { _tag: 'scope', scope: arg },
|
|
391
465
|
});
|
|
392
466
|
}
|
|
467
|
+
|
|
468
|
+
throw new TypeError('Database and Feed objects are not supported in query-lite sandbox');
|
|
393
469
|
}
|
|
394
470
|
|
|
471
|
+
/** Returns a human-readable string representation of a Query AST. */
|
|
472
|
+
static pretty(query: Query$.Any): string {
|
|
473
|
+
return prettyQuery(query.ast);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
constructor(public readonly ast: QueryAST.Query) {}
|
|
477
|
+
|
|
478
|
+
'~Query' = QueryClass.variance;
|
|
479
|
+
|
|
395
480
|
reference(key: string): Query$.Any {
|
|
396
481
|
return new QueryClass({
|
|
397
482
|
type: 'reference-traversal',
|
|
@@ -415,21 +500,21 @@ class QueryClass implements Query$.Any {
|
|
|
415
500
|
});
|
|
416
501
|
}
|
|
417
502
|
|
|
418
|
-
sourceOf(relation
|
|
503
|
+
sourceOf(relation?: Schema.Schema.All | string, predicates?: Filter$.Props<unknown> | undefined): Query$.Any {
|
|
419
504
|
return new QueryClass({
|
|
420
505
|
type: 'relation',
|
|
421
506
|
anchor: this.ast,
|
|
422
507
|
direction: 'outgoing',
|
|
423
|
-
filter: FilterClass.type(relation, predicates).ast,
|
|
508
|
+
filter: relation !== undefined ? FilterClass.type(relation, predicates).ast : undefined,
|
|
424
509
|
});
|
|
425
510
|
}
|
|
426
511
|
|
|
427
|
-
targetOf(relation
|
|
512
|
+
targetOf(relation?: Schema.Schema.All | string, predicates?: Filter$.Props<unknown> | undefined): Query$.Any {
|
|
428
513
|
return new QueryClass({
|
|
429
514
|
type: 'relation',
|
|
430
515
|
anchor: this.ast,
|
|
431
516
|
direction: 'incoming',
|
|
432
|
-
filter: FilterClass.type(relation, predicates).ast,
|
|
517
|
+
filter: relation !== undefined ? FilterClass.type(relation, predicates).ast : undefined,
|
|
433
518
|
});
|
|
434
519
|
}
|
|
435
520
|
|
|
@@ -488,6 +573,21 @@ class QueryClass implements Query$.Any {
|
|
|
488
573
|
options,
|
|
489
574
|
});
|
|
490
575
|
}
|
|
576
|
+
|
|
577
|
+
debugLabel(label: string): Query$.Any {
|
|
578
|
+
if (this.ast.type === 'options') {
|
|
579
|
+
return new QueryClass({
|
|
580
|
+
type: 'options',
|
|
581
|
+
query: this.ast.query,
|
|
582
|
+
options: { ...this.ast.options, debugLabel: label },
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
return new QueryClass({
|
|
586
|
+
type: 'options',
|
|
587
|
+
query: this.ast,
|
|
588
|
+
options: { debugLabel: label },
|
|
589
|
+
});
|
|
590
|
+
}
|
|
491
591
|
}
|
|
492
592
|
|
|
493
593
|
export const Query1: typeof Query$ = QueryClass;
|
|
@@ -503,3 +603,142 @@ const makeTypeDxn = (typename: string) => {
|
|
|
503
603
|
assertArgument(!typename.startsWith('dxn:'), 'typename');
|
|
504
604
|
return `dxn:type:${typename}`;
|
|
505
605
|
};
|
|
606
|
+
|
|
607
|
+
const isDxnLike = (value: unknown): value is DXN => {
|
|
608
|
+
return (
|
|
609
|
+
typeof value === 'object' &&
|
|
610
|
+
value !== null &&
|
|
611
|
+
'toString' in value &&
|
|
612
|
+
typeof value.toString === 'function' &&
|
|
613
|
+
value.toString().startsWith('dxn:')
|
|
614
|
+
);
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
const SCOPE_KEYS = new Set(['spaceIds', 'queues', 'allQueuesFromSpaces']);
|
|
618
|
+
|
|
619
|
+
const _isScopeLike = (value: unknown): value is QueryAST.Scope => {
|
|
620
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
621
|
+
return false;
|
|
622
|
+
}
|
|
623
|
+
return Object.keys(value).every((key) => SCOPE_KEYS.has(key));
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
const prettyFilter = (filter: QueryAST.Filter): string => {
|
|
627
|
+
switch (filter.type) {
|
|
628
|
+
case 'object': {
|
|
629
|
+
const parts: string[] = [];
|
|
630
|
+
if (filter.typename !== null) {
|
|
631
|
+
parts.push(JSON.stringify(filter.typename));
|
|
632
|
+
}
|
|
633
|
+
const propEntries = Object.entries(filter.props);
|
|
634
|
+
if (propEntries.length > 0) {
|
|
635
|
+
const propsStr = propEntries.map(([k, v]) => `${k}: ${prettyFilter(v)}`).join(', ');
|
|
636
|
+
parts.push(`{ ${propsStr} }`);
|
|
637
|
+
}
|
|
638
|
+
if (filter.id !== undefined) {
|
|
639
|
+
parts.push(`id: [${filter.id.join(', ')}]`);
|
|
640
|
+
}
|
|
641
|
+
return parts.length > 0 ? `Filter.type(${parts.join(', ')})` : 'Filter.everything()';
|
|
642
|
+
}
|
|
643
|
+
case 'compare':
|
|
644
|
+
return `Filter.${filter.operator}(${JSON.stringify(filter.value)})`;
|
|
645
|
+
case 'in':
|
|
646
|
+
return `Filter.in(${filter.values.map((v) => JSON.stringify(v)).join(', ')})`;
|
|
647
|
+
case 'contains':
|
|
648
|
+
return `Filter.contains(${JSON.stringify(filter.value)})`;
|
|
649
|
+
case 'range':
|
|
650
|
+
return `Filter.between(${JSON.stringify(filter.from)}, ${JSON.stringify(filter.to)})`;
|
|
651
|
+
case 'text-search':
|
|
652
|
+
return `Filter.text(${JSON.stringify(filter.text)})`;
|
|
653
|
+
case 'tag':
|
|
654
|
+
return `Filter.tag(${JSON.stringify(filter.tag)})`;
|
|
655
|
+
case 'child-of':
|
|
656
|
+
return `Filter.childOf([${filter.parents.map((parent) => JSON.stringify(parent)).join(', ')}], { transitive: ${filter.transitive} })`;
|
|
657
|
+
case 'timestamp':
|
|
658
|
+
return `Filter.${filter.field}.${filter.operator}(${filter.value})`;
|
|
659
|
+
case 'not':
|
|
660
|
+
return `Filter.not(${prettyFilter(filter.filter)})`;
|
|
661
|
+
case 'and':
|
|
662
|
+
return `Filter.and(${filter.filters.map(prettyFilter).join(', ')})`;
|
|
663
|
+
case 'or':
|
|
664
|
+
return `Filter.or(${filter.filters.map(prettyFilter).join(', ')})`;
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
const prettyQuery = (query: QueryAST.Query): string => {
|
|
669
|
+
switch (query.type) {
|
|
670
|
+
case 'select':
|
|
671
|
+
return `Query.select(${prettyFilter(query.filter)})`;
|
|
672
|
+
case 'filter':
|
|
673
|
+
return `${prettyQuery(query.selection)}.select(${prettyFilter(query.filter)})`;
|
|
674
|
+
case 'reference-traversal':
|
|
675
|
+
return `${prettyQuery(query.anchor)}.reference(${JSON.stringify(query.property)})`;
|
|
676
|
+
case 'incoming-references': {
|
|
677
|
+
const args: string[] = [];
|
|
678
|
+
if (query.typename !== null) {
|
|
679
|
+
args.push(JSON.stringify(query.typename));
|
|
680
|
+
}
|
|
681
|
+
if (query.property !== null) {
|
|
682
|
+
args.push(JSON.stringify(query.property));
|
|
683
|
+
}
|
|
684
|
+
return `${prettyQuery(query.anchor)}.referencedBy(${args.join(', ')})`;
|
|
685
|
+
}
|
|
686
|
+
case 'relation': {
|
|
687
|
+
const method =
|
|
688
|
+
query.direction === 'outgoing' ? 'sourceOf' : query.direction === 'incoming' ? 'targetOf' : 'relationOf';
|
|
689
|
+
const filterStr = query.filter !== undefined ? prettyFilter(query.filter) : '';
|
|
690
|
+
return `${prettyQuery(query.anchor)}.${method}(${filterStr})`;
|
|
691
|
+
}
|
|
692
|
+
case 'relation-traversal':
|
|
693
|
+
return `${prettyQuery(query.anchor)}.${query.direction}()`;
|
|
694
|
+
case 'hierarchy-traversal':
|
|
695
|
+
return query.direction === 'to-parent'
|
|
696
|
+
? `${prettyQuery(query.anchor)}.parent()`
|
|
697
|
+
: `${prettyQuery(query.anchor)}.children()`;
|
|
698
|
+
case 'union':
|
|
699
|
+
return `Query.all(${query.queries.map(prettyQuery).join(', ')})`;
|
|
700
|
+
case 'set-difference':
|
|
701
|
+
return `Query.without(${prettyQuery(query.source)}, ${prettyQuery(query.exclude)})`;
|
|
702
|
+
case 'order': {
|
|
703
|
+
const orders = query.order.map((o) => {
|
|
704
|
+
if (o.kind === 'natural') {
|
|
705
|
+
return 'Order.natural';
|
|
706
|
+
}
|
|
707
|
+
if (o.kind === 'rank') {
|
|
708
|
+
return `Order.rank(${JSON.stringify(o.direction)})`;
|
|
709
|
+
}
|
|
710
|
+
return `Order.property(${JSON.stringify(o.property)}, ${JSON.stringify(o.direction)})`;
|
|
711
|
+
});
|
|
712
|
+
return `${prettyQuery(query.query)}.orderBy(${orders.join(', ')})`;
|
|
713
|
+
}
|
|
714
|
+
case 'options': {
|
|
715
|
+
const parts: string[] = [];
|
|
716
|
+
if (query.options.deleted !== undefined) {
|
|
717
|
+
parts.push(`deleted: ${JSON.stringify(query.options.deleted)}`);
|
|
718
|
+
}
|
|
719
|
+
if (query.options.debugLabel !== undefined) {
|
|
720
|
+
parts.push(`debugLabel: ${JSON.stringify(query.options.debugLabel)}`);
|
|
721
|
+
}
|
|
722
|
+
return `${prettyQuery(query.query)}.options({ ${parts.join(', ')} })`;
|
|
723
|
+
}
|
|
724
|
+
case 'from': {
|
|
725
|
+
if (query.from._tag === 'scope') {
|
|
726
|
+
const scope = query.from.scope;
|
|
727
|
+
const parts: string[] = [];
|
|
728
|
+
if (scope.spaceIds !== undefined) {
|
|
729
|
+
parts.push(`spaceIds: [${scope.spaceIds.join(', ')}]`);
|
|
730
|
+
}
|
|
731
|
+
if (scope.queues !== undefined) {
|
|
732
|
+
parts.push(`queues: [${scope.queues.join(', ')}]`);
|
|
733
|
+
}
|
|
734
|
+
if (scope.allQueuesFromSpaces !== undefined) {
|
|
735
|
+
parts.push(`allQueuesFromSpaces: ${scope.allQueuesFromSpaces}`);
|
|
736
|
+
}
|
|
737
|
+
return `${prettyQuery(query.query)}.from({ ${parts.join(', ')} })`;
|
|
738
|
+
}
|
|
739
|
+
return `${prettyQuery(query.query)}.from(${prettyQuery(query.from.query)})`;
|
|
740
|
+
}
|
|
741
|
+
case 'limit':
|
|
742
|
+
return `${prettyQuery(query.query)}.limit(${query.limit})`;
|
|
743
|
+
}
|
|
744
|
+
};
|
|
@@ -16,37 +16,37 @@ describe('QuerySandbox', () => {
|
|
|
16
16
|
|
|
17
17
|
test('works', { timeout: 10_000 }, async () => {
|
|
18
18
|
const ast = sandbox.eval(trim`
|
|
19
|
-
Query.select(Filter.typename('dxos.
|
|
19
|
+
Query.select(Filter.typename('org.dxos.type.person'))
|
|
20
20
|
`);
|
|
21
|
-
expect(ast).toEqual(Query.select(Filter.typename('dxos.
|
|
21
|
+
expect(ast).toEqual(Query.select(Filter.typename('org.dxos.type.person')).ast);
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
test('works with just Filter passed in', () => {
|
|
25
25
|
const ast = sandbox.eval(trim`
|
|
26
|
-
Filter.typename('dxos.
|
|
26
|
+
Filter.typename('org.dxos.type.person')
|
|
27
27
|
`);
|
|
28
|
-
expect(ast).toEqual(Query.select(Filter.typename('dxos.
|
|
28
|
+
expect(ast).toEqual(Query.select(Filter.typename('org.dxos.type.person')).ast);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
test('Order', () => {
|
|
32
32
|
const ast = sandbox.eval(trim`
|
|
33
|
-
Query.type('dxos.
|
|
33
|
+
Query.type('org.dxos.type.person').orderBy(Order.property('name', 'desc'))
|
|
34
34
|
`);
|
|
35
|
-
expect(ast).toEqual(Query.type('dxos.
|
|
35
|
+
expect(ast).toEqual(Query.type('org.dxos.type.person').orderBy(Order.property('name', 'desc')).ast);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
test('traversal', () => {
|
|
39
39
|
const ast = sandbox.eval(trim`
|
|
40
|
-
Query.select(Filter.type('dxos.
|
|
40
|
+
Query.select(Filter.type('org.dxos.type.person', { jobTitle: 'investor' }))
|
|
41
41
|
.reference('organization')
|
|
42
|
-
.targetOf('dxos.
|
|
42
|
+
.targetOf('org.dxos.relation.hasSubject')
|
|
43
43
|
.source()
|
|
44
44
|
`);
|
|
45
45
|
|
|
46
46
|
expect(ast).toEqual(
|
|
47
|
-
Query.select(Filter.type('dxos.
|
|
47
|
+
Query.select(Filter.type('org.dxos.type.person', { jobTitle: 'investor' }))
|
|
48
48
|
.reference('organization')
|
|
49
|
-
.targetOf('dxos.
|
|
49
|
+
.targetOf('org.dxos.relation.hasSubject')
|
|
50
50
|
.source().ast,
|
|
51
51
|
);
|
|
52
52
|
});
|
|
@@ -49,7 +49,7 @@ export class QuerySandbox extends Resource {
|
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Evaluates the query code.
|
|
52
|
-
* @param queryCode Example: `Query.select(Filter.typename('dxos.
|
|
52
|
+
* @param queryCode Example: `Query.select(Filter.typename('org.dxos.type.person'))`
|
|
53
53
|
*/
|
|
54
54
|
eval(queryCode: string): QueryAST.Query {
|
|
55
55
|
using context = this.#runtime.newContext();
|