@dxos/echo-protocol 0.8.4-main.84f28bd → 0.8.4-main.ae835ea
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/browser/index.mjs +137 -58
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +137 -58
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/document-structure.d.ts +8 -0
- package/dist/types/src/document-structure.d.ts.map +1 -1
- package/dist/types/src/foreign-key.d.ts +1 -1
- package/dist/types/src/foreign-key.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/query/ast.d.ts +119 -19
- package/dist/types/src/query/ast.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/src/document-structure.ts +13 -1
- package/src/foreign-key.ts +4 -3
- package/src/index.ts +1 -1
- package/src/query/ast.ts +138 -31
- package/src/reference.ts +1 -1
- package/src/space-id.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-protocol",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.ae835ea",
|
|
4
4
|
"description": "Core ECHO APIs.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
+
"source": "./src/index.ts",
|
|
14
15
|
"types": "./dist/types/src/index.d.ts",
|
|
15
16
|
"browser": "./dist/lib/browser/index.mjs",
|
|
16
17
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
@@ -25,12 +26,12 @@
|
|
|
25
26
|
"src"
|
|
26
27
|
],
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"effect": "3.
|
|
29
|
-
"@dxos/crypto": "0.8.4-main.
|
|
30
|
-
"@dxos/invariant": "0.8.4-main.
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/util": "0.8.4-main.
|
|
29
|
+
"effect": "3.18.3",
|
|
30
|
+
"@dxos/crypto": "0.8.4-main.ae835ea",
|
|
31
|
+
"@dxos/invariant": "0.8.4-main.ae835ea",
|
|
32
|
+
"@dxos/protocols": "0.8.4-main.ae835ea",
|
|
33
|
+
"@dxos/keys": "0.8.4-main.ae835ea",
|
|
34
|
+
"@dxos/util": "0.8.4-main.ae835ea"
|
|
34
35
|
},
|
|
35
36
|
"publishConfig": {
|
|
36
37
|
"access": "public"
|
|
@@ -8,7 +8,7 @@ import { visitValues } from '@dxos/util';
|
|
|
8
8
|
|
|
9
9
|
import { type RawString } from './automerge';
|
|
10
10
|
import type { ForeignKey } from './foreign-key';
|
|
11
|
-
import {
|
|
11
|
+
import { type EncodedReference, isEncodedReference } from './reference';
|
|
12
12
|
import { type SpaceDocVersion } from './space-doc-version';
|
|
13
13
|
|
|
14
14
|
export type SpaceState = {
|
|
@@ -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
|
/**
|
package/src/foreign-key.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
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/index.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
export * from './document-structure';
|
|
6
6
|
export * from './reference';
|
|
7
7
|
export * from './space-doc-version';
|
|
8
|
-
export * from './collection-sync';
|
|
8
|
+
export type * from './collection-sync';
|
|
9
9
|
export * from './space-id';
|
|
10
10
|
export * from './foreign-key';
|
|
11
11
|
export * from './query';
|
package/src/query/ast.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
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
|
|
|
@@ -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,6 +68,33 @@ 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
|
+
*/
|
|
74
|
+
const FilterContains_ = Schema.Struct({
|
|
75
|
+
type: Schema.Literal('contains'),
|
|
76
|
+
value: Schema.Any,
|
|
77
|
+
});
|
|
78
|
+
export interface FilterContains extends Schema.Schema.Type<typeof FilterContains_> {}
|
|
79
|
+
/**
|
|
80
|
+
* Predicate for an array property to contain the provided value.
|
|
81
|
+
* Nested objects are matched using strict structural matching.
|
|
82
|
+
*/
|
|
83
|
+
export const FilterContains: Schema.Schema<FilterContains> = FilterContains_;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Filters objects that have certain tag.
|
|
87
|
+
*/
|
|
88
|
+
const FilterTag_ = Schema.Struct({
|
|
89
|
+
type: Schema.Literal('tag'),
|
|
90
|
+
tag: Schema.String, // TODO(burdon): Make OR-collection?
|
|
91
|
+
});
|
|
92
|
+
export interface FilterTag extends Schema.Schema.Type<typeof FilterTag_> {}
|
|
93
|
+
export const FilterTag: Schema.Schema<FilterTag> = FilterTag_;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Range.
|
|
97
|
+
*/
|
|
64
98
|
const FilterRange_ = Schema.Struct({
|
|
65
99
|
type: Schema.Literal('range'),
|
|
66
100
|
from: Schema.Any,
|
|
@@ -69,6 +103,9 @@ const FilterRange_ = Schema.Struct({
|
|
|
69
103
|
export interface FilterRange extends Schema.Schema.Type<typeof FilterRange_> {}
|
|
70
104
|
export const FilterRange: Schema.Schema<FilterRange> = FilterRange_;
|
|
71
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Text search.
|
|
108
|
+
*/
|
|
72
109
|
const FilterTextSearch_ = Schema.Struct({
|
|
73
110
|
type: Schema.Literal('text-search'),
|
|
74
111
|
text: Schema.String,
|
|
@@ -77,6 +114,9 @@ const FilterTextSearch_ = Schema.Struct({
|
|
|
77
114
|
export interface FilterTextSearch extends Schema.Schema.Type<typeof FilterTextSearch_> {}
|
|
78
115
|
export const FilterTextSearch: Schema.Schema<FilterTextSearch> = FilterTextSearch_;
|
|
79
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Not.
|
|
119
|
+
*/
|
|
80
120
|
const FilterNot_ = Schema.Struct({
|
|
81
121
|
type: Schema.Literal('not'),
|
|
82
122
|
filter: Schema.suspend(() => Filter),
|
|
@@ -84,6 +124,9 @@ const FilterNot_ = Schema.Struct({
|
|
|
84
124
|
export interface FilterNot extends Schema.Schema.Type<typeof FilterNot_> {}
|
|
85
125
|
export const FilterNot: Schema.Schema<FilterNot> = FilterNot_;
|
|
86
126
|
|
|
127
|
+
/**
|
|
128
|
+
* And.
|
|
129
|
+
*/
|
|
87
130
|
const FilterAnd_ = Schema.Struct({
|
|
88
131
|
type: Schema.Literal('and'),
|
|
89
132
|
filters: Schema.Array(Schema.suspend(() => Filter)),
|
|
@@ -91,6 +134,9 @@ const FilterAnd_ = Schema.Struct({
|
|
|
91
134
|
export interface FilterAnd extends Schema.Schema.Type<typeof FilterAnd_> {}
|
|
92
135
|
export const FilterAnd: Schema.Schema<FilterAnd> = FilterAnd_;
|
|
93
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Or.
|
|
139
|
+
*/
|
|
94
140
|
const FilterOr_ = Schema.Struct({
|
|
95
141
|
type: Schema.Literal('or'),
|
|
96
142
|
filters: Schema.Array(Schema.suspend(() => Filter)),
|
|
@@ -98,16 +144,21 @@ const FilterOr_ = Schema.Struct({
|
|
|
98
144
|
export interface FilterOr extends Schema.Schema.Type<typeof FilterOr_> {}
|
|
99
145
|
export const FilterOr: Schema.Schema<FilterOr> = FilterOr_;
|
|
100
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Union of filters.
|
|
149
|
+
*/
|
|
101
150
|
export const Filter = Schema.Union(
|
|
102
151
|
FilterObject,
|
|
103
|
-
FilterTextSearch,
|
|
104
152
|
FilterCompare,
|
|
105
153
|
FilterIn,
|
|
154
|
+
FilterContains,
|
|
155
|
+
FilterTag,
|
|
106
156
|
FilterRange,
|
|
157
|
+
FilterTextSearch,
|
|
107
158
|
FilterNot,
|
|
108
159
|
FilterAnd,
|
|
109
160
|
FilterOr,
|
|
110
|
-
);
|
|
161
|
+
).annotations({ identifier: 'dxos.org/schema/Filter' });
|
|
111
162
|
export type Filter = Schema.Schema.Type<typeof Filter>;
|
|
112
163
|
|
|
113
164
|
/**
|
|
@@ -205,6 +256,35 @@ const QuerySetDifferenceClause_ = Schema.Struct({
|
|
|
205
256
|
export interface QuerySetDifferenceClause extends Schema.Schema.Type<typeof QuerySetDifferenceClause_> {}
|
|
206
257
|
export const QuerySetDifferenceClause: Schema.Schema<QuerySetDifferenceClause> = QuerySetDifferenceClause_;
|
|
207
258
|
|
|
259
|
+
export const OrderDirection = Schema.Literal('asc', 'desc');
|
|
260
|
+
export type OrderDirection = Schema.Schema.Type<typeof OrderDirection>;
|
|
261
|
+
|
|
262
|
+
const Order_ = Schema.Union(
|
|
263
|
+
Schema.Struct({
|
|
264
|
+
// How database wants to order them (in practice - by id).
|
|
265
|
+
kind: Schema.Literal('natural'),
|
|
266
|
+
}),
|
|
267
|
+
Schema.Struct({
|
|
268
|
+
kind: Schema.Literal('property'),
|
|
269
|
+
property: Schema.String,
|
|
270
|
+
direction: OrderDirection,
|
|
271
|
+
}),
|
|
272
|
+
);
|
|
273
|
+
export type Order = Schema.Schema.Type<typeof Order_>;
|
|
274
|
+
export const Order: Schema.Schema<Order> = Order_;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Order the query results.
|
|
278
|
+
* Left-to-right the orders dominate.
|
|
279
|
+
*/
|
|
280
|
+
const QueryOrderClause_ = Schema.Struct({
|
|
281
|
+
type: Schema.Literal('order'),
|
|
282
|
+
query: Schema.suspend(() => Query),
|
|
283
|
+
order: Schema.Array(Order),
|
|
284
|
+
});
|
|
285
|
+
export interface QueryOrderClause extends Schema.Schema.Type<typeof QueryOrderClause_> {}
|
|
286
|
+
export const QueryOrderClause: Schema.Schema<QueryOrderClause> = QueryOrderClause_;
|
|
287
|
+
|
|
208
288
|
/**
|
|
209
289
|
* Add options to a query.
|
|
210
290
|
*/
|
|
@@ -225,44 +305,71 @@ const Query_ = Schema.Union(
|
|
|
225
305
|
QueryRelationTraversalClause,
|
|
226
306
|
QueryUnionClause,
|
|
227
307
|
QuerySetDifferenceClause,
|
|
308
|
+
QueryOrderClause,
|
|
228
309
|
QueryOptionsClause,
|
|
229
|
-
);
|
|
310
|
+
).annotations({ identifier: 'dxos.org/schema/Query' });
|
|
230
311
|
|
|
231
312
|
export type Query = Schema.Schema.Type<typeof Query_>;
|
|
232
313
|
export const Query: Schema.Schema<Query> = Query_;
|
|
233
314
|
|
|
234
315
|
export const QueryOptions = Schema.Struct({
|
|
316
|
+
/**
|
|
317
|
+
* The nested select statemets will select from the given spaces.
|
|
318
|
+
*
|
|
319
|
+
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
320
|
+
*/
|
|
235
321
|
spaceIds: Schema.optional(Schema.Array(Schema.String)),
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* The nested select statemets will select from the given queues.
|
|
325
|
+
*
|
|
326
|
+
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
327
|
+
*/
|
|
328
|
+
queues: Schema.optional(Schema.Array(DXN.Schema)),
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Nested select statements will use this option to filter deleted objects.
|
|
332
|
+
*/
|
|
236
333
|
deleted: Schema.optional(Schema.Literal('include', 'exclude', 'only')),
|
|
237
334
|
});
|
|
238
335
|
export interface QueryOptions extends Schema.Schema.Type<typeof QueryOptions> {}
|
|
239
336
|
|
|
240
337
|
export const visit = (query: Query, visitor: (node: Query) => void) => {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
visit(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
338
|
+
visitor(query);
|
|
339
|
+
|
|
340
|
+
Match.value(query).pipe(
|
|
341
|
+
Match.when({ type: 'filter' }, ({ selection }) => visit(selection, visitor)),
|
|
342
|
+
Match.when({ type: 'reference-traversal' }, ({ anchor }) => visit(anchor, visitor)),
|
|
343
|
+
Match.when({ type: 'incoming-references' }, ({ anchor }) => visit(anchor, visitor)),
|
|
344
|
+
Match.when({ type: 'relation' }, ({ anchor }) => visit(anchor, visitor)),
|
|
345
|
+
Match.when({ type: 'options' }, ({ query }) => visit(query, visitor)),
|
|
346
|
+
Match.when({ type: 'relation-traversal' }, ({ anchor }) => visit(anchor, visitor)),
|
|
347
|
+
Match.when({ type: 'union' }, ({ queries }) => queries.forEach((q) => visit(q, visitor))),
|
|
348
|
+
Match.when({ type: 'set-difference' }, ({ source, exclude }) => {
|
|
349
|
+
visit(source, visitor);
|
|
350
|
+
visit(exclude, visitor);
|
|
351
|
+
}),
|
|
352
|
+
Match.when({ type: 'order' }, ({ query }) => visit(query, visitor)),
|
|
353
|
+
Match.when({ type: 'select' }, () => {}),
|
|
354
|
+
Match.exhaustive,
|
|
355
|
+
);
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
export const fold = <T>(query: Query, reducer: (node: Query) => T): T[] => {
|
|
359
|
+
return Match.value(query).pipe(
|
|
360
|
+
Match.withReturnType<T[]>(),
|
|
361
|
+
Match.when({ type: 'filter' }, ({ selection }) => fold(selection, reducer)),
|
|
362
|
+
Match.when({ type: 'reference-traversal' }, ({ anchor }) => fold(anchor, reducer)),
|
|
363
|
+
Match.when({ type: 'incoming-references' }, ({ anchor }) => fold(anchor, reducer)),
|
|
364
|
+
Match.when({ type: 'relation' }, ({ anchor }) => fold(anchor, reducer)),
|
|
365
|
+
Match.when({ type: 'options' }, ({ query }) => fold(query, reducer)),
|
|
366
|
+
Match.when({ type: 'relation-traversal' }, ({ anchor }) => fold(anchor, reducer)),
|
|
367
|
+
Match.when({ type: 'union' }, ({ queries }) => queries.flatMap((q) => fold(q, reducer))),
|
|
368
|
+
Match.when({ type: 'set-difference' }, ({ source, exclude }) =>
|
|
369
|
+
fold(source, reducer).concat(fold(exclude, reducer)),
|
|
370
|
+
),
|
|
371
|
+
Match.when({ type: 'order' }, ({ query }) => fold(query, reducer)),
|
|
372
|
+
Match.when({ type: 'select' }, () => []),
|
|
373
|
+
Match.exhaustive,
|
|
374
|
+
);
|
|
268
375
|
};
|
package/src/reference.ts
CHANGED
|
@@ -170,7 +170,7 @@ export const isEncodedReference = (value: any): value is EncodedReference =>
|
|
|
170
170
|
export const EncodedReference = Object.freeze({
|
|
171
171
|
isEncodedReference,
|
|
172
172
|
getReferenceString: (value: EncodedReference): string => {
|
|
173
|
-
assertArgument(isEncodedReference(value), 'invalid reference');
|
|
173
|
+
assertArgument(isEncodedReference(value), 'value', 'invalid reference');
|
|
174
174
|
return value['/'];
|
|
175
175
|
},
|
|
176
176
|
toDXN: (value: EncodedReference): DXN => {
|
package/src/space-id.ts
CHANGED
|
@@ -18,7 +18,7 @@ export const createIdFromSpaceKey = async (spaceKey: PublicKey): Promise<SpaceId
|
|
|
18
18
|
return cachedValue;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const digest = await subtleCrypto.digest('SHA-256', spaceKey.asUint8Array());
|
|
21
|
+
const digest = await subtleCrypto.digest('SHA-256', spaceKey.asUint8Array() as Uint8Array<ArrayBuffer>);
|
|
22
22
|
|
|
23
23
|
const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
|
|
24
24
|
const spaceId = SpaceId.encode(bytes);
|