@dxos/echo-protocol 0.8.4-main.c4373fc → 0.8.4-main.cb12b3f963
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 → neutral}/index.mjs +281 -77
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/document-structure.d.ts +9 -2
- package/dist/types/src/document-structure.d.ts.map +1 -1
- package/dist/types/src/echo-feed-codec.d.ts +17 -0
- package/dist/types/src/echo-feed-codec.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/query/ast.d.ts +135 -31
- package/dist/types/src/query/ast.d.ts.map +1 -1
- package/dist/types/src/reference.d.ts +1 -0
- package/dist/types/src/reference.d.ts.map +1 -1
- package/dist/types/src/space-id.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -14
- package/src/document-structure.ts +12 -1
- package/src/echo-feed-codec.ts +67 -0
- package/src/index.ts +4 -3
- package/src/query/ast.ts +184 -10
- package/src/reference.ts +4 -1
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -613
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
|
@@ -11,20 +11,16 @@ import { visitValues } from "@dxos/util";
|
|
|
11
11
|
// src/reference.ts
|
|
12
12
|
import { assertArgument } from "@dxos/invariant";
|
|
13
13
|
import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
|
|
14
|
-
function _define_property(obj, key, value2) {
|
|
15
|
-
if (key in obj) {
|
|
16
|
-
Object.defineProperty(obj, key, {
|
|
17
|
-
value: value2,
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
obj[key] = value2;
|
|
24
|
-
}
|
|
25
|
-
return obj;
|
|
26
|
-
}
|
|
27
14
|
var Reference = class _Reference {
|
|
15
|
+
_objectId;
|
|
16
|
+
_protocol;
|
|
17
|
+
_host;
|
|
18
|
+
_dxn;
|
|
19
|
+
/**
|
|
20
|
+
* Protocol references to runtime registered types.
|
|
21
|
+
* @deprecated
|
|
22
|
+
*/
|
|
23
|
+
static TYPE_PROTOCOL = "protobuf";
|
|
28
24
|
static fromDXN(dxn) {
|
|
29
25
|
switch (dxn.kind) {
|
|
30
26
|
case DXN.kind.TYPE:
|
|
@@ -62,6 +58,13 @@ var Reference = class _Reference {
|
|
|
62
58
|
static fromObjectIdAndSpaceKey(objectId, spaceKey) {
|
|
63
59
|
return new _Reference(objectId, void 0, spaceKey.toHex());
|
|
64
60
|
}
|
|
61
|
+
// prettier-ignore
|
|
62
|
+
constructor(_objectId, _protocol, _host, _dxn) {
|
|
63
|
+
this._objectId = _objectId;
|
|
64
|
+
this._protocol = _protocol;
|
|
65
|
+
this._host = _host;
|
|
66
|
+
this._dxn = _dxn;
|
|
67
|
+
}
|
|
65
68
|
get dxn() {
|
|
66
69
|
return this._dxn;
|
|
67
70
|
}
|
|
@@ -116,19 +119,7 @@ var Reference = class _Reference {
|
|
|
116
119
|
}
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
|
-
// prettier-ignore
|
|
120
|
-
constructor(_objectId, _protocol, _host, _dxn) {
|
|
121
|
-
_define_property(this, "_objectId", void 0);
|
|
122
|
-
_define_property(this, "_protocol", void 0);
|
|
123
|
-
_define_property(this, "_host", void 0);
|
|
124
|
-
_define_property(this, "_dxn", void 0);
|
|
125
|
-
this._objectId = _objectId;
|
|
126
|
-
this._protocol = _protocol;
|
|
127
|
-
this._host = _host;
|
|
128
|
-
this._dxn = _dxn;
|
|
129
|
-
}
|
|
130
122
|
};
|
|
131
|
-
_define_property(Reference, "TYPE_PROTOCOL", "protobuf");
|
|
132
123
|
var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
133
124
|
var encodeReference = (reference) => ({
|
|
134
125
|
"/": reference.toDXN().toString()
|
|
@@ -154,7 +145,14 @@ var EncodedReference = Object.freeze({
|
|
|
154
145
|
return DXN.parse(EncodedReference.getReferenceString(value2));
|
|
155
146
|
},
|
|
156
147
|
fromDXN: (dxn) => {
|
|
157
|
-
return
|
|
148
|
+
return {
|
|
149
|
+
"/": dxn.toString()
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
fromLegacyTypename: (typename) => {
|
|
153
|
+
return {
|
|
154
|
+
"/": DXN.fromTypename(typename).toString()
|
|
155
|
+
};
|
|
158
156
|
}
|
|
159
157
|
});
|
|
160
158
|
|
|
@@ -170,15 +168,7 @@ var DatabaseDirectory = Object.freeze({
|
|
|
170
168
|
return null;
|
|
171
169
|
}
|
|
172
170
|
const rawKey = String(rawSpaceKey);
|
|
173
|
-
invariant(!rawKey.startsWith("0x"), "Space key must not start with 0x", {
|
|
174
|
-
F: __dxlog_file,
|
|
175
|
-
L: 66,
|
|
176
|
-
S: void 0,
|
|
177
|
-
A: [
|
|
178
|
-
"!rawKey.startsWith('0x')",
|
|
179
|
-
"'Space key must not start with 0x'"
|
|
180
|
-
]
|
|
181
|
-
});
|
|
171
|
+
invariant(!rawKey.startsWith("0x"), "Space key must not start with 0x", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 17, S: void 0, A: ["!rawKey.startsWith('0x')", "'Space key must not start with 0x'"] });
|
|
182
172
|
return rawKey;
|
|
183
173
|
},
|
|
184
174
|
getInlineObject: (doc, id) => {
|
|
@@ -207,15 +197,7 @@ var ObjectStructure = Object.freeze({
|
|
|
207
197
|
*/
|
|
208
198
|
getEntityKind: (object) => {
|
|
209
199
|
const kind = object.system?.kind ?? "object";
|
|
210
|
-
invariant(kind === "object" || kind === "relation", "Invalid kind", {
|
|
211
|
-
F: __dxlog_file,
|
|
212
|
-
L: 124,
|
|
213
|
-
S: void 0,
|
|
214
|
-
A: [
|
|
215
|
-
"kind === 'object' || kind === 'relation'",
|
|
216
|
-
"'Invalid kind'"
|
|
217
|
-
]
|
|
218
|
-
});
|
|
200
|
+
invariant(kind === "object" || kind === "relation", "Invalid kind", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 45, S: void 0, A: ["kind === 'object' || kind === 'relation'", "'Invalid kind'"] });
|
|
219
201
|
return kind;
|
|
220
202
|
},
|
|
221
203
|
isDeleted: (object) => {
|
|
@@ -227,6 +209,9 @@ var ObjectStructure = Object.freeze({
|
|
|
227
209
|
getRelationTarget: (object) => {
|
|
228
210
|
return object.system?.target;
|
|
229
211
|
},
|
|
212
|
+
getParent: (object) => {
|
|
213
|
+
return object.system?.parent;
|
|
214
|
+
},
|
|
230
215
|
/**
|
|
231
216
|
* @returns All references in the data section of the object.
|
|
232
217
|
*/
|
|
@@ -288,33 +273,58 @@ var ObjectStructure = Object.freeze({
|
|
|
288
273
|
var PROPERTY_ID = "id";
|
|
289
274
|
var DATA_NAMESPACE = "data";
|
|
290
275
|
|
|
291
|
-
// src/
|
|
292
|
-
|
|
276
|
+
// src/echo-feed-codec.ts
|
|
277
|
+
import { FeedProtocol } from "@dxos/protocols";
|
|
278
|
+
var ATTR_META = "@meta";
|
|
279
|
+
var EchoFeedCodec = class _EchoFeedCodec {
|
|
280
|
+
static #encoder = new TextEncoder();
|
|
281
|
+
static #decoder = new TextDecoder();
|
|
293
282
|
/**
|
|
294
|
-
*
|
|
283
|
+
* Prepares a value for feed storage (strips queue position from metadata) and encodes to bytes.
|
|
295
284
|
*/
|
|
296
|
-
|
|
285
|
+
static encode(value2) {
|
|
286
|
+
const prepared = _EchoFeedCodec.#stripQueuePosition(value2);
|
|
287
|
+
return _EchoFeedCodec.#encoder.encode(JSON.stringify(prepared));
|
|
288
|
+
}
|
|
297
289
|
/**
|
|
298
|
-
*
|
|
290
|
+
* Decodes feed block bytes to a JSON value.
|
|
291
|
+
* If position is provided, injects queue position into the decoded object's metadata.
|
|
299
292
|
*/
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
293
|
+
static decode(data, position) {
|
|
294
|
+
const decoded = JSON.parse(_EchoFeedCodec.#decoder.decode(data));
|
|
295
|
+
if (position !== void 0 && typeof decoded === "object" && decoded !== null) {
|
|
296
|
+
_EchoFeedCodec.#setQueuePosition(decoded, position);
|
|
297
|
+
}
|
|
298
|
+
return decoded;
|
|
299
|
+
}
|
|
300
|
+
static #stripQueuePosition(value2) {
|
|
301
|
+
if (typeof value2 !== "object" || value2 === null) {
|
|
302
|
+
return value2;
|
|
303
|
+
}
|
|
304
|
+
const obj = structuredClone(value2);
|
|
305
|
+
const meta = obj[ATTR_META];
|
|
306
|
+
if (meta?.keys?.some((key) => key.source === FeedProtocol.KEY_QUEUE_POSITION)) {
|
|
307
|
+
meta.keys = meta.keys.filter((key) => key.source !== FeedProtocol.KEY_QUEUE_POSITION);
|
|
308
|
+
}
|
|
309
|
+
return obj;
|
|
310
|
+
}
|
|
311
|
+
static #setQueuePosition(obj, position) {
|
|
312
|
+
obj[ATTR_META] ??= {
|
|
313
|
+
keys: []
|
|
314
|
+
};
|
|
315
|
+
obj[ATTR_META].keys ??= [];
|
|
316
|
+
const keys = obj[ATTR_META].keys;
|
|
317
|
+
for (let i = 0; i < keys.length; i++) {
|
|
318
|
+
if (keys[i].source === FeedProtocol.KEY_QUEUE_POSITION) {
|
|
319
|
+
keys.splice(i, 1);
|
|
320
|
+
i--;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
keys.push({
|
|
324
|
+
source: FeedProtocol.KEY_QUEUE_POSITION,
|
|
325
|
+
id: position.toString()
|
|
326
|
+
});
|
|
312
327
|
}
|
|
313
|
-
const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
|
|
314
|
-
const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
|
|
315
|
-
const spaceId = SpaceId.encode(bytes);
|
|
316
|
-
SPACE_IDS_CACHE.set(spaceKey, spaceId);
|
|
317
|
-
return spaceId;
|
|
318
328
|
};
|
|
319
329
|
|
|
320
330
|
// src/foreign-key.ts
|
|
@@ -342,6 +352,7 @@ var ast_exports = {};
|
|
|
342
352
|
__export(ast_exports, {
|
|
343
353
|
Filter: () => Filter,
|
|
344
354
|
FilterAnd: () => FilterAnd,
|
|
355
|
+
FilterChildOf: () => FilterChildOf,
|
|
345
356
|
FilterCompare: () => FilterCompare,
|
|
346
357
|
FilterContains: () => FilterContains,
|
|
347
358
|
FilterIn: () => FilterIn,
|
|
@@ -351,11 +362,16 @@ __export(ast_exports, {
|
|
|
351
362
|
FilterRange: () => FilterRange,
|
|
352
363
|
FilterTag: () => FilterTag,
|
|
353
364
|
FilterTextSearch: () => FilterTextSearch,
|
|
365
|
+
FilterTimestamp: () => FilterTimestamp,
|
|
354
366
|
Order: () => Order,
|
|
355
367
|
OrderDirection: () => OrderDirection,
|
|
356
368
|
Query: () => Query,
|
|
357
369
|
QueryFilterClause: () => QueryFilterClause,
|
|
370
|
+
QueryFromClause: () => QueryFromClause,
|
|
371
|
+
QueryFromClause_: () => QueryFromClause_,
|
|
372
|
+
QueryHierarchyTraversalClause: () => QueryHierarchyTraversalClause,
|
|
358
373
|
QueryIncomingReferencesClause: () => QueryIncomingReferencesClause,
|
|
374
|
+
QueryLimitClause: () => QueryLimitClause,
|
|
359
375
|
QueryOptions: () => QueryOptions,
|
|
360
376
|
QueryOptionsClause: () => QueryOptionsClause,
|
|
361
377
|
QueryOrderClause: () => QueryOrderClause,
|
|
@@ -365,14 +381,16 @@ __export(ast_exports, {
|
|
|
365
381
|
QuerySelectClause: () => QuerySelectClause,
|
|
366
382
|
QuerySetDifferenceClause: () => QuerySetDifferenceClause,
|
|
367
383
|
QueryUnionClause: () => QueryUnionClause,
|
|
384
|
+
Scope: () => Scope,
|
|
368
385
|
fold: () => fold,
|
|
386
|
+
map: () => map,
|
|
369
387
|
visit: () => visit
|
|
370
388
|
});
|
|
371
389
|
import * as Match from "effect/Match";
|
|
372
390
|
import * as Schema2 from "effect/Schema";
|
|
373
391
|
import { DXN as DXN2, ObjectId } from "@dxos/keys";
|
|
374
392
|
var TypenameSpecifier = Schema2.Union(DXN2.Schema, Schema2.Null).annotations({
|
|
375
|
-
description: "DXN or null
|
|
393
|
+
description: "DXN or null; null matches any type"
|
|
376
394
|
});
|
|
377
395
|
var FilterObject_ = Schema2.Struct({
|
|
378
396
|
type: Schema2.Literal("object"),
|
|
@@ -421,6 +439,13 @@ var FilterRange_ = Schema2.Struct({
|
|
|
421
439
|
to: Schema2.Any
|
|
422
440
|
});
|
|
423
441
|
var FilterRange = FilterRange_;
|
|
442
|
+
var FilterTimestamp_ = Schema2.Struct({
|
|
443
|
+
type: Schema2.Literal("timestamp"),
|
|
444
|
+
field: Schema2.Literal("createdAt", "updatedAt"),
|
|
445
|
+
operator: Schema2.Literal("gt", "gte", "lt", "lte"),
|
|
446
|
+
value: Schema2.Number
|
|
447
|
+
});
|
|
448
|
+
var FilterTimestamp = FilterTimestamp_;
|
|
424
449
|
var FilterTextSearch_ = Schema2.Struct({
|
|
425
450
|
type: Schema2.Literal("text-search"),
|
|
426
451
|
text: Schema2.String,
|
|
@@ -442,8 +467,16 @@ var FilterOr_ = Schema2.Struct({
|
|
|
442
467
|
filters: Schema2.Array(Schema2.suspend(() => Filter))
|
|
443
468
|
});
|
|
444
469
|
var FilterOr = FilterOr_;
|
|
445
|
-
var
|
|
446
|
-
|
|
470
|
+
var FilterChildOf_ = Schema2.Struct({
|
|
471
|
+
type: Schema2.Literal("child-of"),
|
|
472
|
+
/** Parent DXNs to match children of. */
|
|
473
|
+
parents: Schema2.Array(DXN2.Schema),
|
|
474
|
+
/** Whether to match transitively (grandchildren, etc.). Defaults to true. */
|
|
475
|
+
transitive: Schema2.Boolean
|
|
476
|
+
});
|
|
477
|
+
var FilterChildOf = FilterChildOf_;
|
|
478
|
+
var Filter = Schema2.Union(FilterObject, FilterCompare, FilterIn, FilterContains, FilterTag, FilterRange, FilterTimestamp, FilterTextSearch, FilterChildOf, FilterNot, FilterAnd, FilterOr).annotations({
|
|
479
|
+
identifier: "org.dxos.schema.filter"
|
|
447
480
|
});
|
|
448
481
|
var QuerySelectClause_ = Schema2.Struct({
|
|
449
482
|
type: Schema2.Literal("select"),
|
|
@@ -465,7 +498,11 @@ var QueryReferenceTraversalClause = QueryReferenceTraversalClause_;
|
|
|
465
498
|
var QueryIncomingReferencesClause_ = Schema2.Struct({
|
|
466
499
|
type: Schema2.Literal("incoming-references"),
|
|
467
500
|
anchor: Schema2.suspend(() => Query),
|
|
468
|
-
|
|
501
|
+
/**
|
|
502
|
+
* Property path where the reference is located.
|
|
503
|
+
* If null, matches references from any property.
|
|
504
|
+
*/
|
|
505
|
+
property: Schema2.NullOr(Schema2.String),
|
|
469
506
|
typename: TypenameSpecifier
|
|
470
507
|
});
|
|
471
508
|
var QueryIncomingReferencesClause = QueryIncomingReferencesClause_;
|
|
@@ -487,6 +524,16 @@ var QueryRelationTraversalClause_ = Schema2.Struct({
|
|
|
487
524
|
direction: Schema2.Literal("source", "target", "both")
|
|
488
525
|
});
|
|
489
526
|
var QueryRelationTraversalClause = QueryRelationTraversalClause_;
|
|
527
|
+
var QueryHierarchyTraversalClause_ = Schema2.Struct({
|
|
528
|
+
type: Schema2.Literal("hierarchy-traversal"),
|
|
529
|
+
anchor: Schema2.suspend(() => Query),
|
|
530
|
+
/**
|
|
531
|
+
* to-parent: traverse from child to parent.
|
|
532
|
+
* to-children: traverse from parent to children.
|
|
533
|
+
*/
|
|
534
|
+
direction: Schema2.Literal("to-parent", "to-children")
|
|
535
|
+
});
|
|
536
|
+
var QueryHierarchyTraversalClause = QueryHierarchyTraversalClause_;
|
|
490
537
|
var QueryUnionClause_ = Schema2.Struct({
|
|
491
538
|
type: Schema2.Literal("union"),
|
|
492
539
|
queries: Schema2.Array(Schema2.suspend(() => Query))
|
|
@@ -506,6 +553,11 @@ var Order_ = Schema2.Union(Schema2.Struct({
|
|
|
506
553
|
kind: Schema2.Literal("property"),
|
|
507
554
|
property: Schema2.String,
|
|
508
555
|
direction: OrderDirection
|
|
556
|
+
}), Schema2.Struct({
|
|
557
|
+
// Order by relevance rank (for FTS/vector search results).
|
|
558
|
+
// Default direction is 'desc' (higher rank = better match first).
|
|
559
|
+
kind: Schema2.Literal("rank"),
|
|
560
|
+
direction: OrderDirection
|
|
509
561
|
}));
|
|
510
562
|
var Order = Order_;
|
|
511
563
|
var QueryOrderClause_ = Schema2.Struct({
|
|
@@ -520,11 +572,37 @@ var QueryOptionsClause_ = Schema2.Struct({
|
|
|
520
572
|
options: Schema2.suspend(() => QueryOptions)
|
|
521
573
|
});
|
|
522
574
|
var QueryOptionsClause = QueryOptionsClause_;
|
|
523
|
-
var
|
|
524
|
-
|
|
575
|
+
var QueryLimitClause_ = Schema2.Struct({
|
|
576
|
+
type: Schema2.Literal("limit"),
|
|
577
|
+
query: Schema2.suspend(() => Query),
|
|
578
|
+
limit: Schema2.Number
|
|
579
|
+
});
|
|
580
|
+
var QueryLimitClause = QueryLimitClause_;
|
|
581
|
+
var QueryFromClause_ = Schema2.Struct({
|
|
582
|
+
type: Schema2.Literal("from"),
|
|
583
|
+
query: Schema2.suspend(() => Query),
|
|
584
|
+
from: Schema2.Union(Schema2.TaggedStruct("scope", {
|
|
585
|
+
scope: Schema2.suspend(() => Scope)
|
|
586
|
+
}), Schema2.TaggedStruct("query", {
|
|
587
|
+
query: Schema2.suspend(() => Query)
|
|
588
|
+
}))
|
|
589
|
+
});
|
|
590
|
+
var QueryFromClause = QueryFromClause_;
|
|
591
|
+
var Query_ = Schema2.Union(QuerySelectClause, QueryFilterClause, QueryReferenceTraversalClause, QueryIncomingReferencesClause, QueryRelationClause, QueryRelationTraversalClause, QueryHierarchyTraversalClause, QueryUnionClause, QuerySetDifferenceClause, QueryOrderClause, QueryOptionsClause, QueryLimitClause, QueryFromClause).annotations({
|
|
592
|
+
identifier: "org.dxos.schema.query"
|
|
525
593
|
});
|
|
526
594
|
var Query = Query_;
|
|
527
595
|
var QueryOptions = Schema2.Struct({
|
|
596
|
+
/**
|
|
597
|
+
* Nested select statements will use this option to filter deleted objects.
|
|
598
|
+
*/
|
|
599
|
+
deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only")),
|
|
600
|
+
/**
|
|
601
|
+
* Diagnostics-only label for logs / tooling (not used by execution semantics).
|
|
602
|
+
*/
|
|
603
|
+
debugLabel: Schema2.optional(Schema2.String)
|
|
604
|
+
});
|
|
605
|
+
var Scope = Schema2.Struct({
|
|
528
606
|
/**
|
|
529
607
|
* The nested select statemets will select from the given spaces.
|
|
530
608
|
*
|
|
@@ -532,15 +610,15 @@ var QueryOptions = Schema2.Struct({
|
|
|
532
610
|
*/
|
|
533
611
|
spaceIds: Schema2.optional(Schema2.Array(Schema2.String)),
|
|
534
612
|
/**
|
|
613
|
+
* If true, the nested select statements will select from all queues in the spaces specified by `spaceIds`.
|
|
614
|
+
*/
|
|
615
|
+
allQueuesFromSpaces: Schema2.optional(Schema2.Boolean),
|
|
616
|
+
/**
|
|
535
617
|
* The nested select statemets will select from the given queues.
|
|
536
618
|
*
|
|
537
619
|
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
538
620
|
*/
|
|
539
|
-
queues: Schema2.optional(Schema2.Array(DXN2.Schema))
|
|
540
|
-
/**
|
|
541
|
-
* Nested select statements will use this option to filter deleted objects.
|
|
542
|
-
*/
|
|
543
|
-
deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only"))
|
|
621
|
+
queues: Schema2.optional(Schema2.Array(DXN2.Schema))
|
|
544
622
|
});
|
|
545
623
|
var visit = (query, visitor) => {
|
|
546
624
|
visitor(query);
|
|
@@ -556,6 +634,8 @@ var visit = (query, visitor) => {
|
|
|
556
634
|
type: "options"
|
|
557
635
|
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
558
636
|
type: "relation-traversal"
|
|
637
|
+
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
638
|
+
type: "hierarchy-traversal"
|
|
559
639
|
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
560
640
|
type: "union"
|
|
561
641
|
}, ({ queries }) => queries.forEach((q) => visit(q, visitor))), Match.when({
|
|
@@ -566,10 +646,92 @@ var visit = (query, visitor) => {
|
|
|
566
646
|
}), Match.when({
|
|
567
647
|
type: "order"
|
|
568
648
|
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
649
|
+
type: "limit"
|
|
650
|
+
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
651
|
+
type: "from"
|
|
652
|
+
}, (node) => {
|
|
653
|
+
visit(node.query, visitor);
|
|
654
|
+
if (node.from._tag === "query") {
|
|
655
|
+
visit(node.from.query, visitor);
|
|
656
|
+
}
|
|
657
|
+
}), Match.when({
|
|
569
658
|
type: "select"
|
|
570
659
|
}, () => {
|
|
571
660
|
}), Match.exhaustive);
|
|
572
661
|
};
|
|
662
|
+
var map = (query, mapper) => {
|
|
663
|
+
const mapped = Match.value(query).pipe(Match.when({
|
|
664
|
+
type: "filter"
|
|
665
|
+
}, (node) => ({
|
|
666
|
+
...node,
|
|
667
|
+
selection: map(node.selection, mapper)
|
|
668
|
+
})), Match.when({
|
|
669
|
+
type: "reference-traversal"
|
|
670
|
+
}, (node) => ({
|
|
671
|
+
...node,
|
|
672
|
+
anchor: map(node.anchor, mapper)
|
|
673
|
+
})), Match.when({
|
|
674
|
+
type: "incoming-references"
|
|
675
|
+
}, (node) => ({
|
|
676
|
+
...node,
|
|
677
|
+
anchor: map(node.anchor, mapper)
|
|
678
|
+
})), Match.when({
|
|
679
|
+
type: "relation"
|
|
680
|
+
}, (node) => ({
|
|
681
|
+
...node,
|
|
682
|
+
anchor: map(node.anchor, mapper)
|
|
683
|
+
})), Match.when({
|
|
684
|
+
type: "relation-traversal"
|
|
685
|
+
}, (node) => ({
|
|
686
|
+
...node,
|
|
687
|
+
anchor: map(node.anchor, mapper)
|
|
688
|
+
})), Match.when({
|
|
689
|
+
type: "hierarchy-traversal"
|
|
690
|
+
}, (node) => ({
|
|
691
|
+
...node,
|
|
692
|
+
anchor: map(node.anchor, mapper)
|
|
693
|
+
})), Match.when({
|
|
694
|
+
type: "options"
|
|
695
|
+
}, (node) => ({
|
|
696
|
+
...node,
|
|
697
|
+
query: map(node.query, mapper)
|
|
698
|
+
})), Match.when({
|
|
699
|
+
type: "order"
|
|
700
|
+
}, (node) => ({
|
|
701
|
+
...node,
|
|
702
|
+
query: map(node.query, mapper)
|
|
703
|
+
})), Match.when({
|
|
704
|
+
type: "limit"
|
|
705
|
+
}, (node) => ({
|
|
706
|
+
...node,
|
|
707
|
+
query: map(node.query, mapper)
|
|
708
|
+
})), Match.when({
|
|
709
|
+
type: "from"
|
|
710
|
+
}, (node) => ({
|
|
711
|
+
...node,
|
|
712
|
+
query: map(node.query, mapper),
|
|
713
|
+
...node.from._tag === "query" ? {
|
|
714
|
+
from: {
|
|
715
|
+
_tag: "query",
|
|
716
|
+
query: map(node.from.query, mapper)
|
|
717
|
+
}
|
|
718
|
+
} : {}
|
|
719
|
+
})), Match.when({
|
|
720
|
+
type: "union"
|
|
721
|
+
}, (node) => ({
|
|
722
|
+
...node,
|
|
723
|
+
queries: node.queries.map((q) => map(q, mapper))
|
|
724
|
+
})), Match.when({
|
|
725
|
+
type: "set-difference"
|
|
726
|
+
}, (node) => ({
|
|
727
|
+
...node,
|
|
728
|
+
source: map(node.source, mapper),
|
|
729
|
+
exclude: map(node.exclude, mapper)
|
|
730
|
+
})), Match.when({
|
|
731
|
+
type: "select"
|
|
732
|
+
}, (node) => node), Match.exhaustive);
|
|
733
|
+
return mapper(mapped);
|
|
734
|
+
};
|
|
573
735
|
var fold = (query, reducer) => {
|
|
574
736
|
return Match.value(query).pipe(Match.withReturnType(), Match.when({
|
|
575
737
|
type: "filter"
|
|
@@ -583,6 +745,8 @@ var fold = (query, reducer) => {
|
|
|
583
745
|
type: "options"
|
|
584
746
|
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
585
747
|
type: "relation-traversal"
|
|
748
|
+
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
749
|
+
type: "hierarchy-traversal"
|
|
586
750
|
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
587
751
|
type: "union"
|
|
588
752
|
}, ({ queries }) => queries.flatMap((q) => fold(q, reducer))), Match.when({
|
|
@@ -590,12 +754,52 @@ var fold = (query, reducer) => {
|
|
|
590
754
|
}, ({ source, exclude }) => fold(source, reducer).concat(fold(exclude, reducer))), Match.when({
|
|
591
755
|
type: "order"
|
|
592
756
|
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
757
|
+
type: "limit"
|
|
758
|
+
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
759
|
+
type: "from"
|
|
760
|
+
}, (node) => {
|
|
761
|
+
const results = fold(node.query, reducer);
|
|
762
|
+
if (node.from._tag === "query") {
|
|
763
|
+
return results.concat(fold(node.from.query, reducer));
|
|
764
|
+
}
|
|
765
|
+
return results;
|
|
766
|
+
}), Match.when({
|
|
593
767
|
type: "select"
|
|
594
768
|
}, () => []), Match.exhaustive);
|
|
595
769
|
};
|
|
770
|
+
|
|
771
|
+
// src/space-doc-version.ts
|
|
772
|
+
var SpaceDocVersion = Object.freeze({
|
|
773
|
+
/**
|
|
774
|
+
* For the documents created before the versioning was introduced.
|
|
775
|
+
*/
|
|
776
|
+
LEGACY: 0,
|
|
777
|
+
/**
|
|
778
|
+
* Current version.
|
|
779
|
+
*/
|
|
780
|
+
CURRENT: 1
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
// src/space-id.ts
|
|
784
|
+
import { subtleCrypto } from "@dxos/crypto";
|
|
785
|
+
import { PublicKey, SpaceId } from "@dxos/keys";
|
|
786
|
+
import { ComplexMap } from "@dxos/util";
|
|
787
|
+
var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
|
|
788
|
+
var createIdFromSpaceKey = async (spaceKey) => {
|
|
789
|
+
const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
|
|
790
|
+
if (cachedValue !== void 0) {
|
|
791
|
+
return cachedValue;
|
|
792
|
+
}
|
|
793
|
+
const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
|
|
794
|
+
const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
|
|
795
|
+
const spaceId = SpaceId.encode(bytes);
|
|
796
|
+
SPACE_IDS_CACHE.set(spaceKey, spaceId);
|
|
797
|
+
return spaceId;
|
|
798
|
+
};
|
|
596
799
|
export {
|
|
597
800
|
DATA_NAMESPACE,
|
|
598
801
|
DatabaseDirectory,
|
|
802
|
+
EchoFeedCodec,
|
|
599
803
|
EncodedReference,
|
|
600
804
|
ForeignKey,
|
|
601
805
|
ObjectStructure,
|