@dxos/echo-protocol 0.8.4-main.1da679c → 0.8.4-main.21d9917

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,13 +1,16 @@
1
1
  {
2
2
  "name": "@dxos/echo-protocol",
3
- "version": "0.8.4-main.1da679c",
3
+ "version": "0.8.4-main.21d9917",
4
4
  "description": "Core ECHO APIs.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
- "repository": "github:dxos/dxos",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
8
11
  "license": "MIT",
9
12
  "author": "DXOS.org",
10
- "sideEffects": true,
13
+ "sideEffects": false,
11
14
  "type": "module",
12
15
  "exports": {
13
16
  ".": {
@@ -26,12 +29,12 @@
26
29
  "src"
27
30
  ],
28
31
  "dependencies": {
29
- "effect": "3.17.7",
30
- "@dxos/crypto": "0.8.4-main.1da679c",
31
- "@dxos/invariant": "0.8.4-main.1da679c",
32
- "@dxos/keys": "0.8.4-main.1da679c",
33
- "@dxos/protocols": "0.8.4-main.1da679c",
34
- "@dxos/util": "0.8.4-main.1da679c"
32
+ "effect": "3.19.11",
33
+ "@dxos/crypto": "0.8.4-main.21d9917",
34
+ "@dxos/invariant": "0.8.4-main.21d9917",
35
+ "@dxos/keys": "0.8.4-main.21d9917",
36
+ "@dxos/protocols": "0.8.4-main.21d9917",
37
+ "@dxos/util": "0.8.4-main.21d9917"
35
38
  },
36
39
  "publishConfig": {
37
40
  "access": "public"
@@ -153,6 +153,10 @@ export const ObjectStructure = Object.freeze({
153
153
  return references;
154
154
  },
155
155
 
156
+ getTags: (object: ObjectStructure): string[] => {
157
+ return object.meta.tags ?? [];
158
+ },
159
+
156
160
  makeObject: ({
157
161
  type,
158
162
  data,
@@ -214,6 +218,14 @@ export type ObjectMeta = {
214
218
  * Foreign keys.
215
219
  */
216
220
  keys: ForeignKey[];
221
+
222
+ /**
223
+ * Tags.
224
+ * An array of DXNs of Tag objects within the space.
225
+ *
226
+ * NOTE: Optional for backwards compatibilty.
227
+ */
228
+ tags?: string[];
217
229
  };
218
230
 
219
231
  /**
@@ -2,7 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema, SchemaAST } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
+ import * as SchemaAST from 'effect/SchemaAST';
6
7
 
7
8
  const ForeignKey_ = Schema.Struct({
8
9
  /**
@@ -15,8 +16,8 @@ const ForeignKey_ = Schema.Struct({
15
16
  * Id within the foreign database.
16
17
  */
17
18
  // TODO(wittjosiah): This annotation is currently used to ensure id field shows up in forms.
18
- // TODO(dmaretskyi): `false` is not a valid value for the annotation.
19
- id: Schema.String.annotations({ [SchemaAST.IdentifierAnnotationId]: false }),
19
+ // TODO(dmaretskyi): `false` is not a valid value for the annotation. Use a different annotation.
20
+ id: Schema.String.annotations({ [SchemaAST.IdentifierAnnotationId]: 'false' }),
20
21
  });
21
22
 
22
23
  export type ForeignKey = Schema.Schema.Type<typeof ForeignKey_>;
package/src/query/ast.ts CHANGED
@@ -2,14 +2,15 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Match, Schema } from 'effect';
5
+ import * as Match from 'effect/Match';
6
+ import * as Schema from 'effect/Schema';
6
7
 
7
8
  import { DXN, ObjectId } from '@dxos/keys';
8
9
 
9
10
  import { ForeignKey } from '../foreign-key';
10
11
 
11
12
  const TypenameSpecifier = Schema.Union(DXN.Schema, Schema.Null).annotations({
12
- description: 'DXN or null. Null means any type will match',
13
+ description: 'DXN or null; null matches any type',
13
14
  });
14
15
 
15
16
  // NOTE: This pattern with 3 definitions per schema is need to make the types opaque, and circular references in AST to not cause compiler errors.
@@ -46,6 +47,9 @@ const FilterObject_ = Schema.Struct({
46
47
  export interface FilterObject extends Schema.Schema.Type<typeof FilterObject_> {}
47
48
  export const FilterObject: Schema.Schema<FilterObject> = FilterObject_;
48
49
 
50
+ /**
51
+ * Compare.
52
+ */
49
53
  const FilterCompare_ = Schema.Struct({
50
54
  type: Schema.Literal('compare'),
51
55
  operator: Schema.Literal('eq', 'neq', 'gt', 'gte', 'lt', 'lte'),
@@ -54,6 +58,9 @@ const FilterCompare_ = Schema.Struct({
54
58
  export interface FilterCompare extends Schema.Schema.Type<typeof FilterCompare_> {}
55
59
  export const FilterCompare: Schema.Schema<FilterCompare> = FilterCompare_;
56
60
 
61
+ /**
62
+ * In.
63
+ */
57
64
  const FilterIn_ = Schema.Struct({
58
65
  type: Schema.Literal('in'),
59
66
  values: Schema.Array(Schema.Any),
@@ -61,65 +68,106 @@ const FilterIn_ = Schema.Struct({
61
68
  export interface FilterIn extends Schema.Schema.Type<typeof FilterIn_> {}
62
69
  export const FilterIn: Schema.Schema<FilterIn> = FilterIn_;
63
70
 
71
+ /**
72
+ * Contains.
73
+ */
64
74
  const FilterContains_ = Schema.Struct({
65
75
  type: Schema.Literal('contains'),
66
76
  value: Schema.Any,
67
77
  });
78
+
68
79
  export interface FilterContains extends Schema.Schema.Type<typeof FilterContains_> {}
80
+
69
81
  /**
70
82
  * Predicate for an array property to contain the provided value.
71
83
  * Nested objects are matched using strict structural matching.
72
84
  */
73
85
  export const FilterContains: Schema.Schema<FilterContains> = FilterContains_;
74
86
 
87
+ /**
88
+ * Filters objects that have certain tag.
89
+ */
90
+ const FilterTag_ = Schema.Struct({
91
+ type: Schema.Literal('tag'),
92
+ tag: Schema.String, // TODO(burdon): Make OR-collection?
93
+ });
94
+
95
+ export interface FilterTag extends Schema.Schema.Type<typeof FilterTag_> {}
96
+ export const FilterTag: Schema.Schema<FilterTag> = FilterTag_;
97
+
98
+ /**
99
+ * Range.
100
+ */
75
101
  const FilterRange_ = Schema.Struct({
76
102
  type: Schema.Literal('range'),
77
103
  from: Schema.Any,
78
104
  to: Schema.Any,
79
105
  });
106
+
80
107
  export interface FilterRange extends Schema.Schema.Type<typeof FilterRange_> {}
81
108
  export const FilterRange: Schema.Schema<FilterRange> = FilterRange_;
82
109
 
110
+ /**
111
+ * Text search.
112
+ */
83
113
  const FilterTextSearch_ = Schema.Struct({
84
114
  type: Schema.Literal('text-search'),
85
115
  text: Schema.String,
86
116
  searchKind: Schema.optional(Schema.Literal('full-text', 'vector')),
87
117
  });
118
+
88
119
  export interface FilterTextSearch extends Schema.Schema.Type<typeof FilterTextSearch_> {}
89
120
  export const FilterTextSearch: Schema.Schema<FilterTextSearch> = FilterTextSearch_;
90
121
 
122
+ /**
123
+ * Not.
124
+ */
91
125
  const FilterNot_ = Schema.Struct({
92
126
  type: Schema.Literal('not'),
93
127
  filter: Schema.suspend(() => Filter),
94
128
  });
129
+
95
130
  export interface FilterNot extends Schema.Schema.Type<typeof FilterNot_> {}
96
131
  export const FilterNot: Schema.Schema<FilterNot> = FilterNot_;
97
132
 
133
+ /**
134
+ * And.
135
+ */
98
136
  const FilterAnd_ = Schema.Struct({
99
137
  type: Schema.Literal('and'),
100
138
  filters: Schema.Array(Schema.suspend(() => Filter)),
101
139
  });
140
+
102
141
  export interface FilterAnd extends Schema.Schema.Type<typeof FilterAnd_> {}
103
142
  export const FilterAnd: Schema.Schema<FilterAnd> = FilterAnd_;
104
143
 
144
+ /**
145
+ * Or.
146
+ */
105
147
  const FilterOr_ = Schema.Struct({
106
148
  type: Schema.Literal('or'),
107
149
  filters: Schema.Array(Schema.suspend(() => Filter)),
108
150
  });
151
+
109
152
  export interface FilterOr extends Schema.Schema.Type<typeof FilterOr_> {}
110
153
  export const FilterOr: Schema.Schema<FilterOr> = FilterOr_;
111
154
 
155
+ /**
156
+ * Union of filters.
157
+ */
112
158
  export const Filter = Schema.Union(
113
159
  FilterObject,
114
- FilterTextSearch,
115
160
  FilterCompare,
116
161
  FilterIn,
117
162
  FilterContains,
163
+ FilterTag,
118
164
  FilterRange,
165
+ FilterTextSearch,
119
166
  FilterNot,
120
167
  FilterAnd,
121
168
  FilterOr,
122
- );
169
+ ).annotations({ identifier: 'dxos.org/schema/Filter' });
170
+
123
171
  export type Filter = Schema.Schema.Type<typeof Filter>;
124
172
 
125
173
  /**
@@ -129,6 +177,7 @@ const QuerySelectClause_ = Schema.Struct({
129
177
  type: Schema.Literal('select'),
130
178
  filter: Schema.suspend(() => Filter),
131
179
  });
180
+
132
181
  export interface QuerySelectClause extends Schema.Schema.Type<typeof QuerySelectClause_> {}
133
182
  export const QuerySelectClause: Schema.Schema<QuerySelectClause> = QuerySelectClause_;
134
183
 
@@ -140,6 +189,7 @@ const QueryFilterClause_ = Schema.Struct({
140
189
  selection: Schema.suspend(() => Query),
141
190
  filter: Schema.suspend(() => Filter),
142
191
  });
192
+
143
193
  export interface QueryFilterClause extends Schema.Schema.Type<typeof QueryFilterClause_> {}
144
194
  export const QueryFilterClause: Schema.Schema<QueryFilterClause> = QueryFilterClause_;
145
195
 
@@ -151,6 +201,7 @@ const QueryReferenceTraversalClause_ = Schema.Struct({
151
201
  anchor: Schema.suspend(() => Query),
152
202
  property: Schema.String, // TODO(dmaretskyi): Change to EscapedPropPath.
153
203
  });
204
+
154
205
  export interface QueryReferenceTraversalClause extends Schema.Schema.Type<typeof QueryReferenceTraversalClause_> {}
155
206
  export const QueryReferenceTraversalClause: Schema.Schema<QueryReferenceTraversalClause> =
156
207
  QueryReferenceTraversalClause_;
@@ -161,9 +212,14 @@ export const QueryReferenceTraversalClause: Schema.Schema<QueryReferenceTraversa
161
212
  const QueryIncomingReferencesClause_ = Schema.Struct({
162
213
  type: Schema.Literal('incoming-references'),
163
214
  anchor: Schema.suspend(() => Query),
164
- property: Schema.String,
215
+ /**
216
+ * Property path where the reference is located.
217
+ * If null, matches references from any property.
218
+ */
219
+ property: Schema.NullOr(Schema.String),
165
220
  typename: TypenameSpecifier,
166
221
  });
222
+
167
223
  export interface QueryIncomingReferencesClause extends Schema.Schema.Type<typeof QueryIncomingReferencesClause_> {}
168
224
  export const QueryIncomingReferencesClause: Schema.Schema<QueryIncomingReferencesClause> =
169
225
  QueryIncomingReferencesClause_;
@@ -182,6 +238,7 @@ const QueryRelationClause_ = Schema.Struct({
182
238
  direction: Schema.Literal('outgoing', 'incoming', 'both'),
183
239
  filter: Schema.optional(Schema.suspend(() => Filter)),
184
240
  });
241
+
185
242
  export interface QueryRelationClause extends Schema.Schema.Type<typeof QueryRelationClause_> {}
186
243
  export const QueryRelationClause: Schema.Schema<QueryRelationClause> = QueryRelationClause_;
187
244
 
@@ -193,6 +250,7 @@ const QueryRelationTraversalClause_ = Schema.Struct({
193
250
  anchor: Schema.suspend(() => Query),
194
251
  direction: Schema.Literal('source', 'target', 'both'),
195
252
  });
253
+
196
254
  export interface QueryRelationTraversalClause extends Schema.Schema.Type<typeof QueryRelationTraversalClause_> {}
197
255
  export const QueryRelationTraversalClause: Schema.Schema<QueryRelationTraversalClause> = QueryRelationTraversalClause_;
198
256
 
@@ -203,6 +261,7 @@ const QueryUnionClause_ = Schema.Struct({
203
261
  type: Schema.Literal('union'),
204
262
  queries: Schema.Array(Schema.suspend(() => Query)),
205
263
  });
264
+
206
265
  export interface QueryUnionClause extends Schema.Schema.Type<typeof QueryUnionClause_> {}
207
266
  export const QueryUnionClause: Schema.Schema<QueryUnionClause> = QueryUnionClause_;
208
267
 
@@ -214,6 +273,7 @@ const QuerySetDifferenceClause_ = Schema.Struct({
214
273
  source: Schema.suspend(() => Query),
215
274
  exclude: Schema.suspend(() => Query),
216
275
  });
276
+
217
277
  export interface QuerySetDifferenceClause extends Schema.Schema.Type<typeof QuerySetDifferenceClause_> {}
218
278
  export const QuerySetDifferenceClause: Schema.Schema<QuerySetDifferenceClause> = QuerySetDifferenceClause_;
219
279
 
@@ -230,7 +290,14 @@ const Order_ = Schema.Union(
230
290
  property: Schema.String,
231
291
  direction: OrderDirection,
232
292
  }),
293
+ Schema.Struct({
294
+ // Order by relevance rank (for FTS/vector search results).
295
+ // Default direction is 'desc' (higher rank = better match first).
296
+ kind: Schema.Literal('rank'),
297
+ direction: OrderDirection,
298
+ }),
233
299
  );
300
+
234
301
  export type Order = Schema.Schema.Type<typeof Order_>;
235
302
  export const Order: Schema.Schema<Order> = Order_;
236
303
 
@@ -243,6 +310,7 @@ const QueryOrderClause_ = Schema.Struct({
243
310
  query: Schema.suspend(() => Query),
244
311
  order: Schema.Array(Order),
245
312
  });
313
+
246
314
  export interface QueryOrderClause extends Schema.Schema.Type<typeof QueryOrderClause_> {}
247
315
  export const QueryOrderClause: Schema.Schema<QueryOrderClause> = QueryOrderClause_;
248
316
 
@@ -254,9 +322,22 @@ const QueryOptionsClause_ = Schema.Struct({
254
322
  query: Schema.suspend(() => Query),
255
323
  options: Schema.suspend(() => QueryOptions),
256
324
  });
325
+
257
326
  export interface QueryOptionsClause extends Schema.Schema.Type<typeof QueryOptionsClause_> {}
258
327
  export const QueryOptionsClause: Schema.Schema<QueryOptionsClause> = QueryOptionsClause_;
259
328
 
329
+ /**
330
+ * Limit the number of results.
331
+ */
332
+ const QueryLimitClause_ = Schema.Struct({
333
+ type: Schema.Literal('limit'),
334
+ query: Schema.suspend(() => Query),
335
+ limit: Schema.Number,
336
+ });
337
+
338
+ export interface QueryLimitClause extends Schema.Schema.Type<typeof QueryLimitClause_> {}
339
+ export const QueryLimitClause: Schema.Schema<QueryLimitClause> = QueryLimitClause_;
340
+
260
341
  const Query_ = Schema.Union(
261
342
  QuerySelectClause,
262
343
  QueryFilterClause,
@@ -268,7 +349,8 @@ const Query_ = Schema.Union(
268
349
  QuerySetDifferenceClause,
269
350
  QueryOrderClause,
270
351
  QueryOptionsClause,
271
- );
352
+ QueryLimitClause,
353
+ ).annotations({ identifier: 'dxos.org/schema/Query' });
272
354
 
273
355
  export type Query = Schema.Schema.Type<typeof Query_>;
274
356
  export const Query: Schema.Schema<Query> = Query_;
@@ -281,6 +363,11 @@ export const QueryOptions = Schema.Struct({
281
363
  */
282
364
  spaceIds: Schema.optional(Schema.Array(Schema.String)),
283
365
 
366
+ /**
367
+ * If true, the nested select statements will select from all queues in the spaces specified by `spaceIds`.
368
+ */
369
+ allQueuesFromSpaces: Schema.optional(Schema.Boolean),
370
+
284
371
  /**
285
372
  * The nested select statemets will select from the given queues.
286
373
  *
@@ -293,6 +380,7 @@ export const QueryOptions = Schema.Struct({
293
380
  */
294
381
  deleted: Schema.optional(Schema.Literal('include', 'exclude', 'only')),
295
382
  });
383
+
296
384
  export interface QueryOptions extends Schema.Schema.Type<typeof QueryOptions> {}
297
385
 
298
386
  export const visit = (query: Query, visitor: (node: Query) => void) => {
@@ -311,6 +399,7 @@ export const visit = (query: Query, visitor: (node: Query) => void) => {
311
399
  visit(exclude, visitor);
312
400
  }),
313
401
  Match.when({ type: 'order' }, ({ query }) => visit(query, visitor)),
402
+ Match.when({ type: 'limit' }, ({ query }) => visit(query, visitor)),
314
403
  Match.when({ type: 'select' }, () => {}),
315
404
  Match.exhaustive,
316
405
  );
@@ -330,6 +419,7 @@ export const fold = <T>(query: Query, reducer: (node: Query) => T): T[] => {
330
419
  fold(source, reducer).concat(fold(exclude, reducer)),
331
420
  ),
332
421
  Match.when({ type: 'order' }, ({ query }) => fold(query, reducer)),
422
+ Match.when({ type: 'limit' }, ({ query }) => fold(query, reducer)),
333
423
  Match.when({ type: 'select' }, () => []),
334
424
  Match.exhaustive,
335
425
  );
package/src/reference.ts CHANGED
@@ -177,6 +177,9 @@ export const EncodedReference = Object.freeze({
177
177
  return DXN.parse(EncodedReference.getReferenceString(value));
178
178
  },
179
179
  fromDXN: (dxn: DXN): EncodedReference => {
180
- return encodeReference(Reference.fromDXN(dxn));
180
+ return { '/': dxn.toString() };
181
+ },
182
+ fromLegacyTypename: (typename: string): EncodedReference => {
183
+ return { '/': DXN.fromTypename(typename).toString() };
181
184
  },
182
185
  });