@dxos/echo-protocol 0.8.4-main.dedc0f3 → 0.8.4-main.e8ec1fe
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 +108 -98
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +108 -98
- 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 +57 -9
- 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 +89 -53
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.e8ec1fe",
|
|
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/
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
29
|
+
"effect": "3.18.3",
|
|
30
|
+
"@dxos/crypto": "0.8.4-main.e8ec1fe",
|
|
31
|
+
"@dxos/invariant": "0.8.4-main.e8ec1fe",
|
|
32
|
+
"@dxos/keys": "0.8.4-main.e8ec1fe",
|
|
33
|
+
"@dxos/util": "0.8.4-main.e8ec1fe",
|
|
34
|
+
"@dxos/protocols": "0.8.4-main.e8ec1fe"
|
|
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,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
|
/**
|
|
@@ -256,7 +307,7 @@ const Query_ = Schema.Union(
|
|
|
256
307
|
QuerySetDifferenceClause,
|
|
257
308
|
QueryOrderClause,
|
|
258
309
|
QueryOptionsClause,
|
|
259
|
-
);
|
|
310
|
+
).annotations({ identifier: 'dxos.org/schema/Query' });
|
|
260
311
|
|
|
261
312
|
export type Query = Schema.Schema.Type<typeof Query_>;
|
|
262
313
|
export const Query: Schema.Schema<Query> = Query_;
|
|
@@ -284,56 +335,41 @@ export const QueryOptions = Schema.Struct({
|
|
|
284
335
|
export interface QueryOptions extends Schema.Schema.Type<typeof QueryOptions> {}
|
|
285
336
|
|
|
286
337
|
export const visit = (query: Query, visitor: (node: Query) => void) => {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
visit(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
break;
|
|
306
|
-
case 'union':
|
|
307
|
-
query.queries.forEach((q) => visit(q, visitor));
|
|
308
|
-
break;
|
|
309
|
-
case 'set-difference':
|
|
310
|
-
visit(query.source, visitor);
|
|
311
|
-
visit(query.exclude, visitor);
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
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
|
+
);
|
|
314
356
|
};
|
|
315
357
|
|
|
316
358
|
export const fold = <T>(query: Query, reducer: (node: Query) => T): T[] => {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
return fold(query.source, reducer);
|
|
334
|
-
case 'order':
|
|
335
|
-
return fold(query.query, reducer);
|
|
336
|
-
case 'select':
|
|
337
|
-
return [];
|
|
338
|
-
}
|
|
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
|
+
);
|
|
339
375
|
};
|