@dxos/echo-protocol 0.8.4-main.c1de068 → 0.8.4-main.e098934
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 +118 -45
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +118 -45
- 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/query/ast.d.ts +81 -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/query/ast.ts +96 -28
- 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.e098934",
|
|
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.17.
|
|
29
|
-
"@dxos/crypto": "0.8.4-main.
|
|
30
|
-
"@dxos/invariant": "0.8.4-main.
|
|
31
|
-
"@dxos/keys": "0.8.4-main.
|
|
32
|
-
"@dxos/util": "0.8.4-main.
|
|
33
|
-
"@dxos/protocols": "0.8.4-main.
|
|
29
|
+
"effect": "3.17.7",
|
|
30
|
+
"@dxos/crypto": "0.8.4-main.e098934",
|
|
31
|
+
"@dxos/invariant": "0.8.4-main.e098934",
|
|
32
|
+
"@dxos/keys": "0.8.4-main.e098934",
|
|
33
|
+
"@dxos/util": "0.8.4-main.e098934",
|
|
34
|
+
"@dxos/protocols": "0.8.4-main.e098934"
|
|
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/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
|
|
|
@@ -61,6 +61,17 @@ const FilterIn_ = Schema.Struct({
|
|
|
61
61
|
export interface FilterIn extends Schema.Schema.Type<typeof FilterIn_> {}
|
|
62
62
|
export const FilterIn: Schema.Schema<FilterIn> = FilterIn_;
|
|
63
63
|
|
|
64
|
+
const FilterContains_ = Schema.Struct({
|
|
65
|
+
type: Schema.Literal('contains'),
|
|
66
|
+
value: Schema.Any,
|
|
67
|
+
});
|
|
68
|
+
export interface FilterContains extends Schema.Schema.Type<typeof FilterContains_> {}
|
|
69
|
+
/**
|
|
70
|
+
* Predicate for an array property to contain the provided value.
|
|
71
|
+
* Nested objects are matched using strict structural matching.
|
|
72
|
+
*/
|
|
73
|
+
export const FilterContains: Schema.Schema<FilterContains> = FilterContains_;
|
|
74
|
+
|
|
64
75
|
const FilterRange_ = Schema.Struct({
|
|
65
76
|
type: Schema.Literal('range'),
|
|
66
77
|
from: Schema.Any,
|
|
@@ -103,6 +114,7 @@ export const Filter = Schema.Union(
|
|
|
103
114
|
FilterTextSearch,
|
|
104
115
|
FilterCompare,
|
|
105
116
|
FilterIn,
|
|
117
|
+
FilterContains,
|
|
106
118
|
FilterRange,
|
|
107
119
|
FilterNot,
|
|
108
120
|
FilterAnd,
|
|
@@ -205,6 +217,35 @@ const QuerySetDifferenceClause_ = Schema.Struct({
|
|
|
205
217
|
export interface QuerySetDifferenceClause extends Schema.Schema.Type<typeof QuerySetDifferenceClause_> {}
|
|
206
218
|
export const QuerySetDifferenceClause: Schema.Schema<QuerySetDifferenceClause> = QuerySetDifferenceClause_;
|
|
207
219
|
|
|
220
|
+
export const OrderDirection = Schema.Literal('asc', 'desc');
|
|
221
|
+
export type OrderDirection = Schema.Schema.Type<typeof OrderDirection>;
|
|
222
|
+
|
|
223
|
+
const Order_ = Schema.Union(
|
|
224
|
+
Schema.Struct({
|
|
225
|
+
// How database wants to order them (in practice - by id).
|
|
226
|
+
kind: Schema.Literal('natural'),
|
|
227
|
+
}),
|
|
228
|
+
Schema.Struct({
|
|
229
|
+
kind: Schema.Literal('property'),
|
|
230
|
+
property: Schema.String,
|
|
231
|
+
direction: OrderDirection,
|
|
232
|
+
}),
|
|
233
|
+
);
|
|
234
|
+
export type Order = Schema.Schema.Type<typeof Order_>;
|
|
235
|
+
export const Order: Schema.Schema<Order> = Order_;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Order the query results.
|
|
239
|
+
* Left-to-right the orders dominate.
|
|
240
|
+
*/
|
|
241
|
+
const QueryOrderClause_ = Schema.Struct({
|
|
242
|
+
type: Schema.Literal('order'),
|
|
243
|
+
query: Schema.suspend(() => Query),
|
|
244
|
+
order: Schema.Array(Order),
|
|
245
|
+
});
|
|
246
|
+
export interface QueryOrderClause extends Schema.Schema.Type<typeof QueryOrderClause_> {}
|
|
247
|
+
export const QueryOrderClause: Schema.Schema<QueryOrderClause> = QueryOrderClause_;
|
|
248
|
+
|
|
208
249
|
/**
|
|
209
250
|
* Add options to a query.
|
|
210
251
|
*/
|
|
@@ -225,6 +266,7 @@ const Query_ = Schema.Union(
|
|
|
225
266
|
QueryRelationTraversalClause,
|
|
226
267
|
QueryUnionClause,
|
|
227
268
|
QuerySetDifferenceClause,
|
|
269
|
+
QueryOrderClause,
|
|
228
270
|
QueryOptionsClause,
|
|
229
271
|
);
|
|
230
272
|
|
|
@@ -232,37 +274,63 @@ export type Query = Schema.Schema.Type<typeof Query_>;
|
|
|
232
274
|
export const Query: Schema.Schema<Query> = Query_;
|
|
233
275
|
|
|
234
276
|
export const QueryOptions = Schema.Struct({
|
|
277
|
+
/**
|
|
278
|
+
* The nested select statemets will select from the given spaces.
|
|
279
|
+
*
|
|
280
|
+
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
281
|
+
*/
|
|
235
282
|
spaceIds: Schema.optional(Schema.Array(Schema.String)),
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* The nested select statemets will select from the given queues.
|
|
286
|
+
*
|
|
287
|
+
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
288
|
+
*/
|
|
289
|
+
queues: Schema.optional(Schema.Array(DXN.Schema)),
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Nested select statements will use this option to filter deleted objects.
|
|
293
|
+
*/
|
|
236
294
|
deleted: Schema.optional(Schema.Literal('include', 'exclude', 'only')),
|
|
237
295
|
});
|
|
238
296
|
export interface QueryOptions extends Schema.Schema.Type<typeof QueryOptions> {}
|
|
239
297
|
|
|
240
298
|
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
|
-
|
|
299
|
+
visitor(query);
|
|
300
|
+
|
|
301
|
+
Match.value(query).pipe(
|
|
302
|
+
Match.when({ type: 'filter' }, ({ selection }) => visit(selection, visitor)),
|
|
303
|
+
Match.when({ type: 'reference-traversal' }, ({ anchor }) => visit(anchor, visitor)),
|
|
304
|
+
Match.when({ type: 'incoming-references' }, ({ anchor }) => visit(anchor, visitor)),
|
|
305
|
+
Match.when({ type: 'relation' }, ({ anchor }) => visit(anchor, visitor)),
|
|
306
|
+
Match.when({ type: 'options' }, ({ query }) => visit(query, visitor)),
|
|
307
|
+
Match.when({ type: 'relation-traversal' }, ({ anchor }) => visit(anchor, visitor)),
|
|
308
|
+
Match.when({ type: 'union' }, ({ queries }) => queries.forEach((q) => visit(q, visitor))),
|
|
309
|
+
Match.when({ type: 'set-difference' }, ({ source, exclude }) => {
|
|
310
|
+
visit(source, visitor);
|
|
311
|
+
visit(exclude, visitor);
|
|
312
|
+
}),
|
|
313
|
+
Match.when({ type: 'order' }, ({ query }) => visit(query, visitor)),
|
|
314
|
+
Match.when({ type: 'select' }, () => {}),
|
|
315
|
+
Match.exhaustive,
|
|
316
|
+
);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
export const fold = <T>(query: Query, reducer: (node: Query) => T): T[] => {
|
|
320
|
+
return Match.value(query).pipe(
|
|
321
|
+
Match.withReturnType<T[]>(),
|
|
322
|
+
Match.when({ type: 'filter' }, ({ selection }) => fold(selection, reducer)),
|
|
323
|
+
Match.when({ type: 'reference-traversal' }, ({ anchor }) => fold(anchor, reducer)),
|
|
324
|
+
Match.when({ type: 'incoming-references' }, ({ anchor }) => fold(anchor, reducer)),
|
|
325
|
+
Match.when({ type: 'relation' }, ({ anchor }) => fold(anchor, reducer)),
|
|
326
|
+
Match.when({ type: 'options' }, ({ query }) => fold(query, reducer)),
|
|
327
|
+
Match.when({ type: 'relation-traversal' }, ({ anchor }) => fold(anchor, reducer)),
|
|
328
|
+
Match.when({ type: 'union' }, ({ queries }) => queries.flatMap((q) => fold(q, reducer))),
|
|
329
|
+
Match.when({ type: 'set-difference' }, ({ source, exclude }) =>
|
|
330
|
+
fold(source, reducer).concat(fold(exclude, reducer)),
|
|
331
|
+
),
|
|
332
|
+
Match.when({ type: 'order' }, ({ query }) => fold(query, reducer)),
|
|
333
|
+
Match.when({ type: 'select' }, () => []),
|
|
334
|
+
Match.exhaustive,
|
|
335
|
+
);
|
|
268
336
|
};
|
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);
|