@dxos/echo-protocol 0.8.4-main.84f28bd → 0.8.4-main.a4bbb77
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 +130 -47
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +130 -47
- 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.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 +118 -18
- 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 +1 -1
- package/src/foreign-key.ts +2 -2
- package/src/index.ts +1 -1
- package/src/query/ast.ts +137 -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.a4bbb77",
|
|
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/keys": "0.8.4-main.
|
|
32
|
-
"@dxos/protocols": "0.8.4-main.
|
|
33
|
-
"@dxos/util": "0.8.4-main.
|
|
29
|
+
"effect": "3.18.3",
|
|
30
|
+
"@dxos/crypto": "0.8.4-main.a4bbb77",
|
|
31
|
+
"@dxos/invariant": "0.8.4-main.a4bbb77",
|
|
32
|
+
"@dxos/keys": "0.8.4-main.a4bbb77",
|
|
33
|
+
"@dxos/protocols": "0.8.4-main.a4bbb77",
|
|
34
|
+
"@dxos/util": "0.8.4-main.a4bbb77"
|
|
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 = {
|
package/src/foreign-key.ts
CHANGED
|
@@ -15,8 +15,8 @@ const ForeignKey_ = Schema.Struct({
|
|
|
15
15
|
* Id within the foreign database.
|
|
16
16
|
*/
|
|
17
17
|
// 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 }),
|
|
18
|
+
// TODO(dmaretskyi): `false` is not a valid value for the annotation. Use a different annotation.
|
|
19
|
+
id: Schema.String.annotations({ [SchemaAST.IdentifierAnnotationId]: 'false' }),
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
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,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
5
|
+
import { Match, Schema } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { DXN, ObjectId } from '@dxos/keys';
|
|
8
8
|
|
|
@@ -46,6 +46,9 @@ const FilterObject_ = Schema.Struct({
|
|
|
46
46
|
export interface FilterObject extends Schema.Schema.Type<typeof FilterObject_> {}
|
|
47
47
|
export const FilterObject: Schema.Schema<FilterObject> = FilterObject_;
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Compare.
|
|
51
|
+
*/
|
|
49
52
|
const FilterCompare_ = Schema.Struct({
|
|
50
53
|
type: Schema.Literal('compare'),
|
|
51
54
|
operator: Schema.Literal('eq', 'neq', 'gt', 'gte', 'lt', 'lte'),
|
|
@@ -54,6 +57,9 @@ const FilterCompare_ = Schema.Struct({
|
|
|
54
57
|
export interface FilterCompare extends Schema.Schema.Type<typeof FilterCompare_> {}
|
|
55
58
|
export const FilterCompare: Schema.Schema<FilterCompare> = FilterCompare_;
|
|
56
59
|
|
|
60
|
+
/**
|
|
61
|
+
* In.
|
|
62
|
+
*/
|
|
57
63
|
const FilterIn_ = Schema.Struct({
|
|
58
64
|
type: Schema.Literal('in'),
|
|
59
65
|
values: Schema.Array(Schema.Any),
|
|
@@ -61,6 +67,33 @@ const FilterIn_ = Schema.Struct({
|
|
|
61
67
|
export interface FilterIn extends Schema.Schema.Type<typeof FilterIn_> {}
|
|
62
68
|
export const FilterIn: Schema.Schema<FilterIn> = FilterIn_;
|
|
63
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Contains.
|
|
72
|
+
*/
|
|
73
|
+
const FilterContains_ = Schema.Struct({
|
|
74
|
+
type: Schema.Literal('contains'),
|
|
75
|
+
value: Schema.Any,
|
|
76
|
+
});
|
|
77
|
+
export interface FilterContains extends Schema.Schema.Type<typeof FilterContains_> {}
|
|
78
|
+
/**
|
|
79
|
+
* Predicate for an array property to contain the provided value.
|
|
80
|
+
* Nested objects are matched using strict structural matching.
|
|
81
|
+
*/
|
|
82
|
+
export const FilterContains: Schema.Schema<FilterContains> = FilterContains_;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Tag.
|
|
86
|
+
*/
|
|
87
|
+
const FilterTag_ = Schema.Struct({
|
|
88
|
+
type: Schema.Literal('tag'),
|
|
89
|
+
tag: Schema.String, // TODO(burdon): Make OR-collection?
|
|
90
|
+
});
|
|
91
|
+
export interface FilterTag extends Schema.Schema.Type<typeof FilterTag_> {}
|
|
92
|
+
export const FilterTag: Schema.Schema<FilterTag> = FilterTag_;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Range.
|
|
96
|
+
*/
|
|
64
97
|
const FilterRange_ = Schema.Struct({
|
|
65
98
|
type: Schema.Literal('range'),
|
|
66
99
|
from: Schema.Any,
|
|
@@ -69,6 +102,9 @@ const FilterRange_ = Schema.Struct({
|
|
|
69
102
|
export interface FilterRange extends Schema.Schema.Type<typeof FilterRange_> {}
|
|
70
103
|
export const FilterRange: Schema.Schema<FilterRange> = FilterRange_;
|
|
71
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Text search.
|
|
107
|
+
*/
|
|
72
108
|
const FilterTextSearch_ = Schema.Struct({
|
|
73
109
|
type: Schema.Literal('text-search'),
|
|
74
110
|
text: Schema.String,
|
|
@@ -77,6 +113,9 @@ const FilterTextSearch_ = Schema.Struct({
|
|
|
77
113
|
export interface FilterTextSearch extends Schema.Schema.Type<typeof FilterTextSearch_> {}
|
|
78
114
|
export const FilterTextSearch: Schema.Schema<FilterTextSearch> = FilterTextSearch_;
|
|
79
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Not.
|
|
118
|
+
*/
|
|
80
119
|
const FilterNot_ = Schema.Struct({
|
|
81
120
|
type: Schema.Literal('not'),
|
|
82
121
|
filter: Schema.suspend(() => Filter),
|
|
@@ -84,6 +123,9 @@ const FilterNot_ = Schema.Struct({
|
|
|
84
123
|
export interface FilterNot extends Schema.Schema.Type<typeof FilterNot_> {}
|
|
85
124
|
export const FilterNot: Schema.Schema<FilterNot> = FilterNot_;
|
|
86
125
|
|
|
126
|
+
/**
|
|
127
|
+
* And.
|
|
128
|
+
*/
|
|
87
129
|
const FilterAnd_ = Schema.Struct({
|
|
88
130
|
type: Schema.Literal('and'),
|
|
89
131
|
filters: Schema.Array(Schema.suspend(() => Filter)),
|
|
@@ -91,6 +133,9 @@ const FilterAnd_ = Schema.Struct({
|
|
|
91
133
|
export interface FilterAnd extends Schema.Schema.Type<typeof FilterAnd_> {}
|
|
92
134
|
export const FilterAnd: Schema.Schema<FilterAnd> = FilterAnd_;
|
|
93
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Or.
|
|
138
|
+
*/
|
|
94
139
|
const FilterOr_ = Schema.Struct({
|
|
95
140
|
type: Schema.Literal('or'),
|
|
96
141
|
filters: Schema.Array(Schema.suspend(() => Filter)),
|
|
@@ -98,16 +143,21 @@ const FilterOr_ = Schema.Struct({
|
|
|
98
143
|
export interface FilterOr extends Schema.Schema.Type<typeof FilterOr_> {}
|
|
99
144
|
export const FilterOr: Schema.Schema<FilterOr> = FilterOr_;
|
|
100
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Union of filters.
|
|
148
|
+
*/
|
|
101
149
|
export const Filter = Schema.Union(
|
|
102
150
|
FilterObject,
|
|
103
|
-
FilterTextSearch,
|
|
104
151
|
FilterCompare,
|
|
105
152
|
FilterIn,
|
|
153
|
+
FilterContains,
|
|
154
|
+
FilterTag,
|
|
106
155
|
FilterRange,
|
|
156
|
+
FilterTextSearch,
|
|
107
157
|
FilterNot,
|
|
108
158
|
FilterAnd,
|
|
109
159
|
FilterOr,
|
|
110
|
-
);
|
|
160
|
+
).annotations({ identifier: 'dxos.org/schema/Filter' });
|
|
111
161
|
export type Filter = Schema.Schema.Type<typeof Filter>;
|
|
112
162
|
|
|
113
163
|
/**
|
|
@@ -205,6 +255,35 @@ const QuerySetDifferenceClause_ = Schema.Struct({
|
|
|
205
255
|
export interface QuerySetDifferenceClause extends Schema.Schema.Type<typeof QuerySetDifferenceClause_> {}
|
|
206
256
|
export const QuerySetDifferenceClause: Schema.Schema<QuerySetDifferenceClause> = QuerySetDifferenceClause_;
|
|
207
257
|
|
|
258
|
+
export const OrderDirection = Schema.Literal('asc', 'desc');
|
|
259
|
+
export type OrderDirection = Schema.Schema.Type<typeof OrderDirection>;
|
|
260
|
+
|
|
261
|
+
const Order_ = Schema.Union(
|
|
262
|
+
Schema.Struct({
|
|
263
|
+
// How database wants to order them (in practice - by id).
|
|
264
|
+
kind: Schema.Literal('natural'),
|
|
265
|
+
}),
|
|
266
|
+
Schema.Struct({
|
|
267
|
+
kind: Schema.Literal('property'),
|
|
268
|
+
property: Schema.String,
|
|
269
|
+
direction: OrderDirection,
|
|
270
|
+
}),
|
|
271
|
+
);
|
|
272
|
+
export type Order = Schema.Schema.Type<typeof Order_>;
|
|
273
|
+
export const Order: Schema.Schema<Order> = Order_;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Order the query results.
|
|
277
|
+
* Left-to-right the orders dominate.
|
|
278
|
+
*/
|
|
279
|
+
const QueryOrderClause_ = Schema.Struct({
|
|
280
|
+
type: Schema.Literal('order'),
|
|
281
|
+
query: Schema.suspend(() => Query),
|
|
282
|
+
order: Schema.Array(Order),
|
|
283
|
+
});
|
|
284
|
+
export interface QueryOrderClause extends Schema.Schema.Type<typeof QueryOrderClause_> {}
|
|
285
|
+
export const QueryOrderClause: Schema.Schema<QueryOrderClause> = QueryOrderClause_;
|
|
286
|
+
|
|
208
287
|
/**
|
|
209
288
|
* Add options to a query.
|
|
210
289
|
*/
|
|
@@ -225,44 +304,71 @@ const Query_ = Schema.Union(
|
|
|
225
304
|
QueryRelationTraversalClause,
|
|
226
305
|
QueryUnionClause,
|
|
227
306
|
QuerySetDifferenceClause,
|
|
307
|
+
QueryOrderClause,
|
|
228
308
|
QueryOptionsClause,
|
|
229
|
-
);
|
|
309
|
+
).annotations({ identifier: 'dxos.org/schema/Query' });
|
|
230
310
|
|
|
231
311
|
export type Query = Schema.Schema.Type<typeof Query_>;
|
|
232
312
|
export const Query: Schema.Schema<Query> = Query_;
|
|
233
313
|
|
|
234
314
|
export const QueryOptions = Schema.Struct({
|
|
315
|
+
/**
|
|
316
|
+
* The nested select statemets will select from the given spaces.
|
|
317
|
+
*
|
|
318
|
+
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
319
|
+
*/
|
|
235
320
|
spaceIds: Schema.optional(Schema.Array(Schema.String)),
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* The nested select statemets will select from the given queues.
|
|
324
|
+
*
|
|
325
|
+
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
326
|
+
*/
|
|
327
|
+
queues: Schema.optional(Schema.Array(DXN.Schema)),
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Nested select statements will use this option to filter deleted objects.
|
|
331
|
+
*/
|
|
236
332
|
deleted: Schema.optional(Schema.Literal('include', 'exclude', 'only')),
|
|
237
333
|
});
|
|
238
334
|
export interface QueryOptions extends Schema.Schema.Type<typeof QueryOptions> {}
|
|
239
335
|
|
|
240
336
|
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
|
-
|
|
337
|
+
visitor(query);
|
|
338
|
+
|
|
339
|
+
Match.value(query).pipe(
|
|
340
|
+
Match.when({ type: 'filter' }, ({ selection }) => visit(selection, visitor)),
|
|
341
|
+
Match.when({ type: 'reference-traversal' }, ({ anchor }) => visit(anchor, visitor)),
|
|
342
|
+
Match.when({ type: 'incoming-references' }, ({ anchor }) => visit(anchor, visitor)),
|
|
343
|
+
Match.when({ type: 'relation' }, ({ anchor }) => visit(anchor, visitor)),
|
|
344
|
+
Match.when({ type: 'options' }, ({ query }) => visit(query, visitor)),
|
|
345
|
+
Match.when({ type: 'relation-traversal' }, ({ anchor }) => visit(anchor, visitor)),
|
|
346
|
+
Match.when({ type: 'union' }, ({ queries }) => queries.forEach((q) => visit(q, visitor))),
|
|
347
|
+
Match.when({ type: 'set-difference' }, ({ source, exclude }) => {
|
|
348
|
+
visit(source, visitor);
|
|
349
|
+
visit(exclude, visitor);
|
|
350
|
+
}),
|
|
351
|
+
Match.when({ type: 'order' }, ({ query }) => visit(query, visitor)),
|
|
352
|
+
Match.when({ type: 'select' }, () => {}),
|
|
353
|
+
Match.exhaustive,
|
|
354
|
+
);
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
export const fold = <T>(query: Query, reducer: (node: Query) => T): T[] => {
|
|
358
|
+
return Match.value(query).pipe(
|
|
359
|
+
Match.withReturnType<T[]>(),
|
|
360
|
+
Match.when({ type: 'filter' }, ({ selection }) => fold(selection, reducer)),
|
|
361
|
+
Match.when({ type: 'reference-traversal' }, ({ anchor }) => fold(anchor, reducer)),
|
|
362
|
+
Match.when({ type: 'incoming-references' }, ({ anchor }) => fold(anchor, reducer)),
|
|
363
|
+
Match.when({ type: 'relation' }, ({ anchor }) => fold(anchor, reducer)),
|
|
364
|
+
Match.when({ type: 'options' }, ({ query }) => fold(query, reducer)),
|
|
365
|
+
Match.when({ type: 'relation-traversal' }, ({ anchor }) => fold(anchor, reducer)),
|
|
366
|
+
Match.when({ type: 'union' }, ({ queries }) => queries.flatMap((q) => fold(q, reducer))),
|
|
367
|
+
Match.when({ type: 'set-difference' }, ({ source, exclude }) =>
|
|
368
|
+
fold(source, reducer).concat(fold(exclude, reducer)),
|
|
369
|
+
),
|
|
370
|
+
Match.when({ type: 'order' }, ({ query }) => fold(query, reducer)),
|
|
371
|
+
Match.when({ type: 'select' }, () => []),
|
|
372
|
+
Match.exhaustive,
|
|
373
|
+
);
|
|
268
374
|
};
|
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);
|