@dxos/echo-protocol 0.8.4-main.5ea62a8 → 0.8.4-main.66e292d
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 +145 -77
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +145 -77
- 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/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 +7 -7
- package/src/document-structure.ts +12 -0
- package/src/foreign-key.ts +4 -3
- package/src/query/ast.ts +160 -32
- package/src/reference.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.66e292d",
|
|
4
4
|
"description": "Core ECHO APIs.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"src"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"effect": "3.
|
|
30
|
-
"@dxos/crypto": "0.8.4-main.
|
|
31
|
-
"@dxos/invariant": "0.8.4-main.
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/protocols": "0.8.4-main.
|
|
34
|
-
"@dxos/
|
|
29
|
+
"effect": "3.18.3",
|
|
30
|
+
"@dxos/crypto": "0.8.4-main.66e292d",
|
|
31
|
+
"@dxos/invariant": "0.8.4-main.66e292d",
|
|
32
|
+
"@dxos/util": "0.8.4-main.66e292d",
|
|
33
|
+
"@dxos/protocols": "0.8.4-main.66e292d",
|
|
34
|
+
"@dxos/keys": "0.8.4-main.66e292d"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"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
|
/**
|
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/query/ast.ts
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
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
|
|
|
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
|
|
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,53 +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
|
+
*/
|
|
74
|
+
const FilterContains_ = Schema.Struct({
|
|
75
|
+
type: Schema.Literal('contains'),
|
|
76
|
+
value: Schema.Any,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export interface FilterContains extends Schema.Schema.Type<typeof FilterContains_> {}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Predicate for an array property to contain the provided value.
|
|
83
|
+
* Nested objects are matched using strict structural matching.
|
|
84
|
+
*/
|
|
85
|
+
export const FilterContains: Schema.Schema<FilterContains> = FilterContains_;
|
|
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
|
+
*/
|
|
64
101
|
const FilterRange_ = Schema.Struct({
|
|
65
102
|
type: Schema.Literal('range'),
|
|
66
103
|
from: Schema.Any,
|
|
67
104
|
to: Schema.Any,
|
|
68
105
|
});
|
|
106
|
+
|
|
69
107
|
export interface FilterRange extends Schema.Schema.Type<typeof FilterRange_> {}
|
|
70
108
|
export const FilterRange: Schema.Schema<FilterRange> = FilterRange_;
|
|
71
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Text search.
|
|
112
|
+
*/
|
|
72
113
|
const FilterTextSearch_ = Schema.Struct({
|
|
73
114
|
type: Schema.Literal('text-search'),
|
|
74
115
|
text: Schema.String,
|
|
75
116
|
searchKind: Schema.optional(Schema.Literal('full-text', 'vector')),
|
|
76
117
|
});
|
|
118
|
+
|
|
77
119
|
export interface FilterTextSearch extends Schema.Schema.Type<typeof FilterTextSearch_> {}
|
|
78
120
|
export const FilterTextSearch: Schema.Schema<FilterTextSearch> = FilterTextSearch_;
|
|
79
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Not.
|
|
124
|
+
*/
|
|
80
125
|
const FilterNot_ = Schema.Struct({
|
|
81
126
|
type: Schema.Literal('not'),
|
|
82
127
|
filter: Schema.suspend(() => Filter),
|
|
83
128
|
});
|
|
129
|
+
|
|
84
130
|
export interface FilterNot extends Schema.Schema.Type<typeof FilterNot_> {}
|
|
85
131
|
export const FilterNot: Schema.Schema<FilterNot> = FilterNot_;
|
|
86
132
|
|
|
133
|
+
/**
|
|
134
|
+
* And.
|
|
135
|
+
*/
|
|
87
136
|
const FilterAnd_ = Schema.Struct({
|
|
88
137
|
type: Schema.Literal('and'),
|
|
89
138
|
filters: Schema.Array(Schema.suspend(() => Filter)),
|
|
90
139
|
});
|
|
140
|
+
|
|
91
141
|
export interface FilterAnd extends Schema.Schema.Type<typeof FilterAnd_> {}
|
|
92
142
|
export const FilterAnd: Schema.Schema<FilterAnd> = FilterAnd_;
|
|
93
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Or.
|
|
146
|
+
*/
|
|
94
147
|
const FilterOr_ = Schema.Struct({
|
|
95
148
|
type: Schema.Literal('or'),
|
|
96
149
|
filters: Schema.Array(Schema.suspend(() => Filter)),
|
|
97
150
|
});
|
|
151
|
+
|
|
98
152
|
export interface FilterOr extends Schema.Schema.Type<typeof FilterOr_> {}
|
|
99
153
|
export const FilterOr: Schema.Schema<FilterOr> = FilterOr_;
|
|
100
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Union of filters.
|
|
157
|
+
*/
|
|
101
158
|
export const Filter = Schema.Union(
|
|
102
159
|
FilterObject,
|
|
103
|
-
FilterTextSearch,
|
|
104
160
|
FilterCompare,
|
|
105
161
|
FilterIn,
|
|
162
|
+
FilterContains,
|
|
163
|
+
FilterTag,
|
|
106
164
|
FilterRange,
|
|
165
|
+
FilterTextSearch,
|
|
107
166
|
FilterNot,
|
|
108
167
|
FilterAnd,
|
|
109
168
|
FilterOr,
|
|
110
|
-
);
|
|
169
|
+
).annotations({ identifier: 'dxos.org/schema/Filter' });
|
|
170
|
+
|
|
111
171
|
export type Filter = Schema.Schema.Type<typeof Filter>;
|
|
112
172
|
|
|
113
173
|
/**
|
|
@@ -117,6 +177,7 @@ const QuerySelectClause_ = Schema.Struct({
|
|
|
117
177
|
type: Schema.Literal('select'),
|
|
118
178
|
filter: Schema.suspend(() => Filter),
|
|
119
179
|
});
|
|
180
|
+
|
|
120
181
|
export interface QuerySelectClause extends Schema.Schema.Type<typeof QuerySelectClause_> {}
|
|
121
182
|
export const QuerySelectClause: Schema.Schema<QuerySelectClause> = QuerySelectClause_;
|
|
122
183
|
|
|
@@ -128,6 +189,7 @@ const QueryFilterClause_ = Schema.Struct({
|
|
|
128
189
|
selection: Schema.suspend(() => Query),
|
|
129
190
|
filter: Schema.suspend(() => Filter),
|
|
130
191
|
});
|
|
192
|
+
|
|
131
193
|
export interface QueryFilterClause extends Schema.Schema.Type<typeof QueryFilterClause_> {}
|
|
132
194
|
export const QueryFilterClause: Schema.Schema<QueryFilterClause> = QueryFilterClause_;
|
|
133
195
|
|
|
@@ -139,6 +201,7 @@ const QueryReferenceTraversalClause_ = Schema.Struct({
|
|
|
139
201
|
anchor: Schema.suspend(() => Query),
|
|
140
202
|
property: Schema.String, // TODO(dmaretskyi): Change to EscapedPropPath.
|
|
141
203
|
});
|
|
204
|
+
|
|
142
205
|
export interface QueryReferenceTraversalClause extends Schema.Schema.Type<typeof QueryReferenceTraversalClause_> {}
|
|
143
206
|
export const QueryReferenceTraversalClause: Schema.Schema<QueryReferenceTraversalClause> =
|
|
144
207
|
QueryReferenceTraversalClause_;
|
|
@@ -152,6 +215,7 @@ const QueryIncomingReferencesClause_ = Schema.Struct({
|
|
|
152
215
|
property: Schema.String,
|
|
153
216
|
typename: TypenameSpecifier,
|
|
154
217
|
});
|
|
218
|
+
|
|
155
219
|
export interface QueryIncomingReferencesClause extends Schema.Schema.Type<typeof QueryIncomingReferencesClause_> {}
|
|
156
220
|
export const QueryIncomingReferencesClause: Schema.Schema<QueryIncomingReferencesClause> =
|
|
157
221
|
QueryIncomingReferencesClause_;
|
|
@@ -170,6 +234,7 @@ const QueryRelationClause_ = Schema.Struct({
|
|
|
170
234
|
direction: Schema.Literal('outgoing', 'incoming', 'both'),
|
|
171
235
|
filter: Schema.optional(Schema.suspend(() => Filter)),
|
|
172
236
|
});
|
|
237
|
+
|
|
173
238
|
export interface QueryRelationClause extends Schema.Schema.Type<typeof QueryRelationClause_> {}
|
|
174
239
|
export const QueryRelationClause: Schema.Schema<QueryRelationClause> = QueryRelationClause_;
|
|
175
240
|
|
|
@@ -181,6 +246,7 @@ const QueryRelationTraversalClause_ = Schema.Struct({
|
|
|
181
246
|
anchor: Schema.suspend(() => Query),
|
|
182
247
|
direction: Schema.Literal('source', 'target', 'both'),
|
|
183
248
|
});
|
|
249
|
+
|
|
184
250
|
export interface QueryRelationTraversalClause extends Schema.Schema.Type<typeof QueryRelationTraversalClause_> {}
|
|
185
251
|
export const QueryRelationTraversalClause: Schema.Schema<QueryRelationTraversalClause> = QueryRelationTraversalClause_;
|
|
186
252
|
|
|
@@ -191,6 +257,7 @@ const QueryUnionClause_ = Schema.Struct({
|
|
|
191
257
|
type: Schema.Literal('union'),
|
|
192
258
|
queries: Schema.Array(Schema.suspend(() => Query)),
|
|
193
259
|
});
|
|
260
|
+
|
|
194
261
|
export interface QueryUnionClause extends Schema.Schema.Type<typeof QueryUnionClause_> {}
|
|
195
262
|
export const QueryUnionClause: Schema.Schema<QueryUnionClause> = QueryUnionClause_;
|
|
196
263
|
|
|
@@ -202,9 +269,41 @@ const QuerySetDifferenceClause_ = Schema.Struct({
|
|
|
202
269
|
source: Schema.suspend(() => Query),
|
|
203
270
|
exclude: Schema.suspend(() => Query),
|
|
204
271
|
});
|
|
272
|
+
|
|
205
273
|
export interface QuerySetDifferenceClause extends Schema.Schema.Type<typeof QuerySetDifferenceClause_> {}
|
|
206
274
|
export const QuerySetDifferenceClause: Schema.Schema<QuerySetDifferenceClause> = QuerySetDifferenceClause_;
|
|
207
275
|
|
|
276
|
+
export const OrderDirection = Schema.Literal('asc', 'desc');
|
|
277
|
+
export type OrderDirection = Schema.Schema.Type<typeof OrderDirection>;
|
|
278
|
+
|
|
279
|
+
const Order_ = Schema.Union(
|
|
280
|
+
Schema.Struct({
|
|
281
|
+
// How database wants to order them (in practice - by id).
|
|
282
|
+
kind: Schema.Literal('natural'),
|
|
283
|
+
}),
|
|
284
|
+
Schema.Struct({
|
|
285
|
+
kind: Schema.Literal('property'),
|
|
286
|
+
property: Schema.String,
|
|
287
|
+
direction: OrderDirection,
|
|
288
|
+
}),
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
export type Order = Schema.Schema.Type<typeof Order_>;
|
|
292
|
+
export const Order: Schema.Schema<Order> = Order_;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Order the query results.
|
|
296
|
+
* Left-to-right the orders dominate.
|
|
297
|
+
*/
|
|
298
|
+
const QueryOrderClause_ = Schema.Struct({
|
|
299
|
+
type: Schema.Literal('order'),
|
|
300
|
+
query: Schema.suspend(() => Query),
|
|
301
|
+
order: Schema.Array(Order),
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
export interface QueryOrderClause extends Schema.Schema.Type<typeof QueryOrderClause_> {}
|
|
305
|
+
export const QueryOrderClause: Schema.Schema<QueryOrderClause> = QueryOrderClause_;
|
|
306
|
+
|
|
208
307
|
/**
|
|
209
308
|
* Add options to a query.
|
|
210
309
|
*/
|
|
@@ -213,6 +312,7 @@ const QueryOptionsClause_ = Schema.Struct({
|
|
|
213
312
|
query: Schema.suspend(() => Query),
|
|
214
313
|
options: Schema.suspend(() => QueryOptions),
|
|
215
314
|
});
|
|
315
|
+
|
|
216
316
|
export interface QueryOptionsClause extends Schema.Schema.Type<typeof QueryOptionsClause_> {}
|
|
217
317
|
export const QueryOptionsClause: Schema.Schema<QueryOptionsClause> = QueryOptionsClause_;
|
|
218
318
|
|
|
@@ -225,44 +325,72 @@ const Query_ = Schema.Union(
|
|
|
225
325
|
QueryRelationTraversalClause,
|
|
226
326
|
QueryUnionClause,
|
|
227
327
|
QuerySetDifferenceClause,
|
|
328
|
+
QueryOrderClause,
|
|
228
329
|
QueryOptionsClause,
|
|
229
|
-
);
|
|
330
|
+
).annotations({ identifier: 'dxos.org/schema/Query' });
|
|
230
331
|
|
|
231
332
|
export type Query = Schema.Schema.Type<typeof Query_>;
|
|
232
333
|
export const Query: Schema.Schema<Query> = Query_;
|
|
233
334
|
|
|
234
335
|
export const QueryOptions = Schema.Struct({
|
|
336
|
+
/**
|
|
337
|
+
* The nested select statemets will select from the given spaces.
|
|
338
|
+
*
|
|
339
|
+
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
340
|
+
*/
|
|
235
341
|
spaceIds: Schema.optional(Schema.Array(Schema.String)),
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The nested select statemets will select from the given queues.
|
|
345
|
+
*
|
|
346
|
+
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
347
|
+
*/
|
|
348
|
+
queues: Schema.optional(Schema.Array(DXN.Schema)),
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Nested select statements will use this option to filter deleted objects.
|
|
352
|
+
*/
|
|
236
353
|
deleted: Schema.optional(Schema.Literal('include', 'exclude', 'only')),
|
|
237
354
|
});
|
|
355
|
+
|
|
238
356
|
export interface QueryOptions extends Schema.Schema.Type<typeof QueryOptions> {}
|
|
239
357
|
|
|
240
358
|
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
|
-
|
|
359
|
+
visitor(query);
|
|
360
|
+
|
|
361
|
+
Match.value(query).pipe(
|
|
362
|
+
Match.when({ type: 'filter' }, ({ selection }) => visit(selection, visitor)),
|
|
363
|
+
Match.when({ type: 'reference-traversal' }, ({ anchor }) => visit(anchor, visitor)),
|
|
364
|
+
Match.when({ type: 'incoming-references' }, ({ anchor }) => visit(anchor, visitor)),
|
|
365
|
+
Match.when({ type: 'relation' }, ({ anchor }) => visit(anchor, visitor)),
|
|
366
|
+
Match.when({ type: 'options' }, ({ query }) => visit(query, visitor)),
|
|
367
|
+
Match.when({ type: 'relation-traversal' }, ({ anchor }) => visit(anchor, visitor)),
|
|
368
|
+
Match.when({ type: 'union' }, ({ queries }) => queries.forEach((q) => visit(q, visitor))),
|
|
369
|
+
Match.when({ type: 'set-difference' }, ({ source, exclude }) => {
|
|
370
|
+
visit(source, visitor);
|
|
371
|
+
visit(exclude, visitor);
|
|
372
|
+
}),
|
|
373
|
+
Match.when({ type: 'order' }, ({ query }) => visit(query, visitor)),
|
|
374
|
+
Match.when({ type: 'select' }, () => {}),
|
|
375
|
+
Match.exhaustive,
|
|
376
|
+
);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
export const fold = <T>(query: Query, reducer: (node: Query) => T): T[] => {
|
|
380
|
+
return Match.value(query).pipe(
|
|
381
|
+
Match.withReturnType<T[]>(),
|
|
382
|
+
Match.when({ type: 'filter' }, ({ selection }) => fold(selection, reducer)),
|
|
383
|
+
Match.when({ type: 'reference-traversal' }, ({ anchor }) => fold(anchor, reducer)),
|
|
384
|
+
Match.when({ type: 'incoming-references' }, ({ anchor }) => fold(anchor, reducer)),
|
|
385
|
+
Match.when({ type: 'relation' }, ({ anchor }) => fold(anchor, reducer)),
|
|
386
|
+
Match.when({ type: 'options' }, ({ query }) => fold(query, reducer)),
|
|
387
|
+
Match.when({ type: 'relation-traversal' }, ({ anchor }) => fold(anchor, reducer)),
|
|
388
|
+
Match.when({ type: 'union' }, ({ queries }) => queries.flatMap((q) => fold(q, reducer))),
|
|
389
|
+
Match.when({ type: 'set-difference' }, ({ source, exclude }) =>
|
|
390
|
+
fold(source, reducer).concat(fold(exclude, reducer)),
|
|
391
|
+
),
|
|
392
|
+
Match.when({ type: 'order' }, ({ query }) => fold(query, reducer)),
|
|
393
|
+
Match.when({ type: 'select' }, () => []),
|
|
394
|
+
Match.exhaustive,
|
|
395
|
+
);
|
|
268
396
|
};
|
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 => {
|