@dxos/echo-query 0.8.4-main.69d29f4 → 0.8.4-main.6fa680abb7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/echo-query",
3
- "version": "0.8.4-main.69d29f4",
3
+ "version": "0.8.4-main.6fa680abb7",
4
4
  "description": "ECHO queries.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -19,8 +19,7 @@
19
19
  ".": {
20
20
  "source": "./src/index.ts",
21
21
  "types": "./dist/types/src/index.d.ts",
22
- "browser": "./dist/lib/browser/index.mjs",
23
- "node": "./dist/lib/node-esm/index.mjs"
22
+ "default": "./dist/lib/neutral/index.mjs"
24
23
  },
25
24
  "./api.d.ts": "./dist/query-lite/index.d.ts"
26
25
  },
@@ -36,22 +35,22 @@
36
35
  "@lezer/common": "^1.2.2",
37
36
  "@lezer/lezer": "^1.1.2",
38
37
  "@lezer/lr": "^1.4.2",
39
- "@dxos/context": "0.8.4-main.69d29f4",
40
- "@dxos/debug": "0.8.4-main.69d29f4",
41
- "@dxos/echo": "0.8.4-main.69d29f4",
42
- "@dxos/invariant": "0.8.4-main.69d29f4",
43
- "@dxos/errors": "0.8.4-main.69d29f4",
44
- "@dxos/echo-protocol": "0.8.4-main.69d29f4",
45
- "@dxos/node-std": "0.8.4-main.69d29f4",
46
- "@dxos/util": "0.8.4-main.69d29f4",
47
- "@dxos/vendor-quickjs": "0.8.4-main.69d29f4"
38
+ "@dxos/debug": "0.8.4-main.6fa680abb7",
39
+ "@dxos/errors": "0.8.4-main.6fa680abb7",
40
+ "@dxos/echo": "0.8.4-main.6fa680abb7",
41
+ "@dxos/context": "0.8.4-main.6fa680abb7",
42
+ "@dxos/echo-protocol": "0.8.4-main.6fa680abb7",
43
+ "@dxos/invariant": "0.8.4-main.6fa680abb7",
44
+ "@dxos/util": "0.8.4-main.6fa680abb7",
45
+ "@dxos/vendor-quickjs": "0.8.4-main.6fa680abb7",
46
+ "@dxos/node-std": "0.8.4-main.6fa680abb7"
48
47
  },
49
48
  "devDependencies": {
50
49
  "@lezer/generator": "^1.7.1",
51
50
  "tsdown": "^0.16.7",
52
51
  "typescript": "^5.9.3",
53
- "@dxos/random": "0.8.4-main.69d29f4",
54
- "@dxos/echo-generator": "0.8.4-main.69d29f4"
52
+ "@dxos/echo-generator": "0.8.4-main.6fa680abb7",
53
+ "@dxos/random": "0.8.4-main.6fa680abb7"
55
54
  },
56
55
  "publishConfig": {
57
56
  "access": "public"
@@ -51,10 +51,10 @@ describe('query', () => {
51
51
  },
52
52
  // Type
53
53
  {
54
- input: 'type:dxos.org/type/Person',
54
+ input: 'type:org.dxos.type.person',
55
55
  expected: [
56
56
  'Query',
57
- // type:dxos.org/type/Person
57
+ // type:org.dxos.type.person
58
58
  'Filter',
59
59
  'TypeFilter',
60
60
  'TypeKeyword',
@@ -111,10 +111,10 @@ describe('query', () => {
111
111
  ],
112
112
  },
113
113
  {
114
- input: 'type:dxos.org/type/Person OR type:dxos.org/type/Organization',
114
+ input: 'type:org.dxos.type.person OR type:org.dxos.type.organization',
115
115
  expected: [
116
116
  'Query',
117
- // type:dxos.org/type/Person
117
+ // type:org.dxos.type.person
118
118
  'Filter',
119
119
  'TypeFilter',
120
120
  'TypeKeyword',
@@ -122,7 +122,7 @@ describe('query', () => {
122
122
  'Identifier',
123
123
  // OR
124
124
  'Or',
125
- // type:dxos.org/type/Organization
125
+ // type:org.dxos.type.organization
126
126
  'Filter',
127
127
  'TypeFilter',
128
128
  'TypeKeyword',
@@ -131,11 +131,11 @@ describe('query', () => {
131
131
  ],
132
132
  },
133
133
  {
134
- input: '(type:dxos.org/type/Person OR type:dxos.org/type/Organization) AND { name: "DXOS" }',
134
+ input: '(type:org.dxos.type.person OR type:org.dxos.type.organization) AND { name: "DXOS" }',
135
135
  expected: [
136
136
  'Query',
137
137
  '(',
138
- // type:dxos.org/type/Person
138
+ // type:org.dxos.type.person
139
139
  'Filter',
140
140
  'TypeFilter',
141
141
  'TypeKeyword',
@@ -143,7 +143,7 @@ describe('query', () => {
143
143
  'Identifier',
144
144
  // OR
145
145
  'Or',
146
- // type:dxos.org/type/Organization
146
+ // type:org.dxos.type.organization
147
147
  'Filter',
148
148
  'TypeFilter',
149
149
  'TypeKeyword',
@@ -164,10 +164,10 @@ describe('query', () => {
164
164
  ],
165
165
  },
166
166
  {
167
- input: 'type:dxos.org/type/Person -> type:dxos.org/type/Organization',
167
+ input: 'type:org.dxos.type.person -> type:org.dxos.type.organization',
168
168
  expected: [
169
169
  'Query',
170
- // type:dxos.org/type/Person
170
+ // type:org.dxos.type.person
171
171
  'Filter',
172
172
  'TypeFilter',
173
173
  'TypeKeyword',
@@ -175,7 +175,7 @@ describe('query', () => {
175
175
  'Identifier',
176
176
  'Relation',
177
177
  'ArrowRight',
178
- // type:dxos.org/type/Organization
178
+ // type:org.dxos.type.organization
179
179
  'Filter',
180
180
  'TypeFilter',
181
181
  'TypeKeyword',
@@ -184,10 +184,10 @@ describe('query', () => {
184
184
  ],
185
185
  },
186
186
  {
187
- input: 'type:dxos.org/type/Organization <- type:dxos.org/type/Person',
187
+ input: 'type:org.dxos.type.organization <- type:org.dxos.type.person',
188
188
  expected: [
189
189
  'Query',
190
- // type:dxos.org/type/Organization
190
+ // type:org.dxos.type.organization
191
191
  'Filter',
192
192
  'TypeFilter',
193
193
  'TypeKeyword',
@@ -195,7 +195,7 @@ describe('query', () => {
195
195
  'Identifier',
196
196
  'Relation',
197
197
  'ArrowLeft',
198
- // type:dxos.org/type/Person
198
+ // type:org.dxos.type.person
199
199
  'Filter',
200
200
  'TypeFilter',
201
201
  'TypeKeyword',
@@ -206,7 +206,7 @@ describe('query', () => {
206
206
  {
207
207
  // Persons for Organizations with name "DXOS"
208
208
  // TODO(burdon): Filter relations.
209
- input: '((type:dxos.org/type/Organization AND { name: "DXOS" }) -> type:dxos.org/type/Person)',
209
+ input: '((type:org.dxos.type.organization AND { name: "DXOS" }) -> type:org.dxos.type.person)',
210
210
  expected: [
211
211
  'Query',
212
212
  '(',
@@ -238,7 +238,7 @@ describe('query', () => {
238
238
  ],
239
239
  },
240
240
  {
241
- input: 'type:dxos.org/type/Person and { name: "DXOS" }',
241
+ input: 'type:org.dxos.type.person and { name: "DXOS" }',
242
242
  expected: [
243
243
  'Query',
244
244
  'Filter',
@@ -259,7 +259,7 @@ describe('query', () => {
259
259
  ],
260
260
  },
261
261
  {
262
- input: 'x = ( type: dxos.org/type/Person )',
262
+ input: 'x = ( type: org.dxos.type.person )',
263
263
  expected: [
264
264
  'Query',
265
265
  'Assignment',
@@ -305,9 +305,9 @@ describe('query', () => {
305
305
  const tests: Test[] = [
306
306
  // Types
307
307
  {
308
- input: 'type:dxos.org/type/Person',
308
+ input: 'type:org.dxos.type.person',
309
309
  expected: {
310
- filter: Filter.typename('dxos.org/type/Person'),
310
+ filter: Filter.typename('org.dxos.type.person'),
311
311
  },
312
312
  },
313
313
  // Tags
@@ -357,32 +357,32 @@ describe('query', () => {
357
357
  },
358
358
  },
359
359
  {
360
- input: 'type:dxos.org/type/Person OR type:dxos.org/type/Organization',
360
+ input: 'type:org.dxos.type.person OR type:org.dxos.type.organization',
361
361
  expected: {
362
- filter: Filter.or(Filter.typename('dxos.org/type/Person'), Filter.typename('dxos.org/type/Organization')),
362
+ filter: Filter.or(Filter.typename('org.dxos.type.person'), Filter.typename('org.dxos.type.organization')),
363
363
  },
364
364
  },
365
365
  {
366
- input: '(type:dxos.org/type/Person OR type:dxos.org/type/Organization) AND { name: "DXOS" }',
366
+ input: '(type:org.dxos.type.person OR type:org.dxos.type.organization) AND { name: "DXOS" }',
367
367
  expected: {
368
368
  filter: Filter.and(
369
- Filter.or(Filter.typename('dxos.org/type/Person'), Filter.typename('dxos.org/type/Organization')),
369
+ Filter.or(Filter.typename('org.dxos.type.person'), Filter.typename('org.dxos.type.organization')),
370
370
  Filter.props({ name: 'DXOS' }),
371
371
  ),
372
372
  },
373
373
  },
374
374
  {
375
- input: 'type:dxos.org/type/Person and { name: "DXOS" }',
375
+ input: 'type:org.dxos.type.person and { name: "DXOS" }',
376
376
  expected: {
377
- filter: Filter.and(Filter.typename('dxos.org/type/Person'), Filter.props({ name: 'DXOS' })),
377
+ filter: Filter.and(Filter.typename('org.dxos.type.person'), Filter.props({ name: 'DXOS' })),
378
378
  },
379
379
  },
380
380
  // Assignment
381
381
  {
382
- input: 'x = ( type:dxos.org/type/Person )',
382
+ input: 'x = ( type:org.dxos.type.person )',
383
383
  expected: {
384
384
  name: 'x',
385
- filter: Filter.typename('dxos.org/type/Person'),
385
+ filter: Filter.typename('org.dxos.type.person'),
386
386
  },
387
387
  },
388
388
  {
@@ -401,9 +401,9 @@ describe('query', () => {
401
401
  //
402
402
  // {
403
403
  // input: '',
404
- // expected: Query.select(Filter.typename('dxos.org/type/Person', { jobTitle: 'investor' }))
404
+ // expected: Query.select(Filter.typename('org.dxos.type.person', { jobTitle: 'investor' }))
405
405
  // .reference('organization')
406
- // .targetOf(Relation.of('dxos.org/relation/HasSubject')) // TODO(burdon): Invert?
406
+ // .targetOf(Relation.of('org.dxos.relation.has-subject')) // TODO(burdon): Invert?
407
407
  // .source(),
408
408
  // },
409
409
  ];
@@ -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;
@@ -328,7 +328,7 @@ const processPredicate = (predicate: any): QueryAST.Filter => {
328
328
  };
329
329
 
330
330
  class QueryClass implements Query$.Any {
331
- private static variance: Query$.Any['~Query'] = {} as Query$.Any['~Query'];
331
+ private static 'variance': Query$.Any['~Query'] = {} as Query$.Any['~Query'];
332
332
 
333
333
  static is(value: unknown): value is Query$.Any {
334
334
  return typeof value === 'object' && value !== null && '~Query' in value;
@@ -372,6 +372,15 @@ class QueryClass implements Query$.Any {
372
372
  });
373
373
  }
374
374
 
375
+ static from(source: any, options?: { includeFeeds?: boolean }): Query$.Any {
376
+ const baseQuery: QueryAST.Query = {
377
+ type: 'select',
378
+ filter: FilterClass.everything().ast,
379
+ };
380
+ const wrapper = new QueryClass(baseQuery);
381
+ return wrapper.from(source, options);
382
+ }
383
+
375
384
  constructor(public readonly ast: QueryAST.Query) {}
376
385
 
377
386
  '~Query' = QueryClass.variance;
@@ -415,21 +424,21 @@ class QueryClass implements Query$.Any {
415
424
  });
416
425
  }
417
426
 
418
- sourceOf(relation: Schema.Schema.All | string, predicates?: Filter$.Props<unknown> | undefined): Query$.Any {
427
+ sourceOf(relation?: Schema.Schema.All | string, predicates?: Filter$.Props<unknown> | undefined): Query$.Any {
419
428
  return new QueryClass({
420
429
  type: 'relation',
421
430
  anchor: this.ast,
422
431
  direction: 'outgoing',
423
- filter: FilterClass.type(relation, predicates).ast,
432
+ filter: relation !== undefined ? FilterClass.type(relation, predicates).ast : undefined,
424
433
  });
425
434
  }
426
435
 
427
- targetOf(relation: Schema.Schema.All | string, predicates?: Filter$.Props<unknown> | undefined): Query$.Any {
436
+ targetOf(relation?: Schema.Schema.All | string, predicates?: Filter$.Props<unknown> | undefined): Query$.Any {
428
437
  return new QueryClass({
429
438
  type: 'relation',
430
439
  anchor: this.ast,
431
440
  direction: 'incoming',
432
- filter: FilterClass.type(relation, predicates).ast,
441
+ filter: relation !== undefined ? FilterClass.type(relation, predicates).ast : undefined,
433
442
  });
434
443
  }
435
444
 
@@ -449,6 +458,22 @@ class QueryClass implements Query$.Any {
449
458
  });
450
459
  }
451
460
 
461
+ parent(): Query$.Any {
462
+ return new QueryClass({
463
+ type: 'hierarchy-traversal',
464
+ anchor: this.ast,
465
+ direction: 'to-parent',
466
+ });
467
+ }
468
+
469
+ children(): Query$.Any {
470
+ return new QueryClass({
471
+ type: 'hierarchy-traversal',
472
+ anchor: this.ast,
473
+ direction: 'to-children',
474
+ });
475
+ }
476
+
452
477
  orderBy(...order: Order$.Any[]): Query$.Any {
453
478
  return new QueryClass({
454
479
  type: 'order',
@@ -465,6 +490,31 @@ class QueryClass implements Query$.Any {
465
490
  });
466
491
  }
467
492
 
493
+ from(arg: any, options?: { includeFeeds?: boolean }): Query$.Any {
494
+ if (arg === 'all-accessible-spaces') {
495
+ return new QueryClass({
496
+ type: 'from',
497
+ query: this.ast,
498
+ from: {
499
+ _tag: 'scope',
500
+ scope: {
501
+ ...(options?.includeFeeds ? { allQueuesFromSpaces: true } : {}),
502
+ },
503
+ },
504
+ });
505
+ }
506
+
507
+ if (_isScopeLike(arg)) {
508
+ return new QueryClass({
509
+ type: 'from',
510
+ query: this.ast,
511
+ from: { _tag: 'scope', scope: arg },
512
+ });
513
+ }
514
+
515
+ throw new TypeError('Database and Feed objects are not supported in query-lite sandbox');
516
+ }
517
+
468
518
  options(options: QueryAST.QueryOptions): Query$.Any {
469
519
  return new QueryClass({
470
520
  type: 'options',
@@ -487,3 +537,12 @@ const makeTypeDxn = (typename: string) => {
487
537
  assertArgument(!typename.startsWith('dxn:'), 'typename');
488
538
  return `dxn:type:${typename}`;
489
539
  };
540
+
541
+ const SCOPE_KEYS = new Set(['spaceIds', 'queues', 'allQueuesFromSpaces']);
542
+
543
+ const _isScopeLike = (value: unknown): value is QueryAST.Scope => {
544
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
545
+ return false;
546
+ }
547
+ return Object.keys(value).every((key) => SCOPE_KEYS.has(key));
548
+ };
@@ -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.org/type/Person'))
19
+ Query.select(Filter.typename('org.dxos.type.person'))
20
20
  `);
21
- expect(ast).toEqual(Query.select(Filter.typename('dxos.org/type/Person')).ast);
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.org/type/Person')
26
+ Filter.typename('org.dxos.type.person')
27
27
  `);
28
- expect(ast).toEqual(Query.select(Filter.typename('dxos.org/type/Person')).ast);
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.org/type/Person').orderBy(Order.property('name', 'desc'))
33
+ Query.type('org.dxos.type.person').orderBy(Order.property('name', 'desc'))
34
34
  `);
35
- expect(ast).toEqual(Query.type('dxos.org/type/Person').orderBy(Order.property('name', 'desc')).ast);
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.org/type/Person', { jobTitle: 'investor' }))
40
+ Query.select(Filter.type('org.dxos.type.person', { jobTitle: 'investor' }))
41
41
  .reference('organization')
42
- .targetOf('dxos.org/relation/HasSubject')
42
+ .targetOf('org.dxos.relation.has-subject')
43
43
  .source()
44
44
  `);
45
45
 
46
46
  expect(ast).toEqual(
47
- Query.select(Filter.type('dxos.org/type/Person', { jobTitle: 'investor' }))
47
+ Query.select(Filter.type('org.dxos.type.person', { jobTitle: 'investor' }))
48
48
  .reference('organization')
49
- .targetOf('dxos.org/relation/HasSubject')
49
+ .targetOf('org.dxos.relation.has-subject')
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.org/type/Person'))`
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();