@dxos/echo-protocol 0.8.4-main.ef1bc66f44 → 0.8.4-main.effb148878

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.
@@ -10,148 +10,24 @@ import { visitValues } from "@dxos/util";
10
10
 
11
11
  // src/reference.ts
12
12
  import { assertArgument } from "@dxos/invariant";
13
- import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
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";
24
- static fromDXN(dxn) {
25
- switch (dxn.kind) {
26
- case DXN.kind.TYPE:
27
- return new _Reference(dxn.parts[0], _Reference.TYPE_PROTOCOL, "dxos.org", dxn);
28
- case DXN.kind.ECHO:
29
- if (dxn.parts[0] === LOCAL_SPACE_TAG) {
30
- return new _Reference(dxn.parts[1], void 0, void 0, dxn);
31
- } else {
32
- return new _Reference(dxn.parts[1], void 0, dxn.parts[0], dxn);
33
- }
34
- default:
35
- return new _Reference(dxn.parts[0], void 0, dxn.parts[0], dxn);
36
- }
37
- }
38
- static fromValue(value2) {
39
- return new _Reference(value2.objectId, value2.protocol, value2.host);
40
- }
41
- /**
42
- * Reference an object in the local space.
43
- */
44
- static localObjectReference(objectId) {
45
- return new _Reference(objectId);
46
- }
47
- /**
48
- * @deprecated
49
- */
50
- // TODO(dmaretskyi): Remove.
51
- static fromLegacyTypename(type) {
52
- return new _Reference(type, _Reference.TYPE_PROTOCOL, "dxos.org");
53
- }
54
- /**
55
- * @deprecated
56
- */
57
- // TODO(dmaretskyi): Remove
58
- static fromObjectIdAndSpaceKey(objectId, spaceKey) {
59
- return new _Reference(objectId, void 0, spaceKey.toHex());
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
- }
68
- get dxn() {
69
- return this._dxn;
70
- }
71
- /**
72
- * @deprecated
73
- */
74
- // TODO(dmaretskyi): Remove.
75
- get objectId() {
76
- return this._objectId;
77
- }
78
- /**
79
- * @deprecated
80
- */
81
- // TODO(dmaretskyi): Remove.
82
- get protocol() {
83
- return this._protocol;
84
- }
85
- /**
86
- * @deprecated
87
- */
88
- // TODO(dmaretskyi): Remove.
89
- get host() {
90
- return this._host;
91
- }
92
- encode() {
93
- return {
94
- objectId: this.objectId,
95
- host: this.host,
96
- protocol: this.protocol
97
- };
98
- }
99
- // TODO(dmaretskyi): Remove in favor of `reference.dxn`.
100
- toDXN() {
101
- if (this._dxn) {
102
- return this._dxn;
103
- }
104
- if (this.protocol === _Reference.TYPE_PROTOCOL) {
105
- return new DXN(DXN.kind.TYPE, [
106
- this.objectId
107
- ]);
108
- } else {
109
- if (this.host) {
110
- return new DXN(DXN.kind.ECHO, [
111
- this.host,
112
- this.objectId
113
- ]);
114
- } else {
115
- return new DXN(DXN.kind.ECHO, [
116
- LOCAL_SPACE_TAG,
117
- this.objectId
118
- ]);
119
- }
120
- }
121
- }
122
- };
123
13
  var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
124
- var encodeReference = (reference) => ({
125
- "/": reference.toDXN().toString()
126
- });
127
- var decodeReference = (value2) => {
128
- if (typeof value2 !== "object" || value2 === null || typeof value2["/"] !== "string") {
129
- throw new Error("Invalid reference");
130
- }
131
- const dxnString = value2["/"];
132
- if (dxnString.length % 2 === 0 && dxnString.slice(0, dxnString.length / 2) === dxnString.slice(dxnString.length / 2) && dxnString.includes("dxn:echo")) {
133
- throw new Error("Automerge bug detected!");
134
- }
135
- return Reference.fromDXN(DXN.parse(dxnString));
136
- };
137
14
  var isEncodedReference = (value2) => typeof value2 === "object" && value2 !== null && Object.keys(value2).length === 1 && typeof value2["/"] === "string";
138
15
  var EncodedReference = Object.freeze({
139
16
  isEncodedReference,
140
- getReferenceString: (value2) => {
17
+ /**
18
+ * Returns the opaque URI stored in the encoded reference (any scheme: `echo:` or `dxn:`).
19
+ * Consumers can narrow with `EchoURI.isEchoURI(uri)` / `DXN.isDXN(uri)`.
20
+ */
21
+ toURI: (value2) => {
141
22
  assertArgument(isEncodedReference(value2), "value", "invalid reference");
142
23
  return value2["/"];
143
24
  },
144
- toDXN: (value2) => {
145
- return DXN.parse(EncodedReference.getReferenceString(value2));
146
- },
147
- fromDXN: (dxn) => {
148
- return {
149
- "/": dxn.toString()
150
- };
151
- },
152
- fromLegacyTypename: (typename) => {
25
+ /**
26
+ * Creates an encoded reference from an opaque URI.
27
+ */
28
+ fromURI: (uri) => {
153
29
  return {
154
- "/": DXN.fromTypename(typename).toString()
30
+ "/": uri
155
31
  };
156
32
  }
157
33
  });
@@ -168,15 +44,7 @@ var DatabaseDirectory = Object.freeze({
168
44
  return null;
169
45
  }
170
46
  const rawKey = String(rawSpaceKey);
171
- invariant(!rawKey.startsWith("0x"), "Space key must not start with 0x", {
172
- F: __dxlog_file,
173
- L: 66,
174
- S: void 0,
175
- A: [
176
- "!rawKey.startsWith('0x')",
177
- "'Space key must not start with 0x'"
178
- ]
179
- });
47
+ 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'"] });
180
48
  return rawKey;
181
49
  },
182
50
  getInlineObject: (doc, id) => {
@@ -205,15 +73,7 @@ var ObjectStructure = Object.freeze({
205
73
  */
206
74
  getEntityKind: (object) => {
207
75
  const kind = object.system?.kind ?? "object";
208
- invariant(kind === "object" || kind === "relation", "Invalid kind", {
209
- F: __dxlog_file,
210
- L: 124,
211
- S: void 0,
212
- A: [
213
- "kind === 'object' || kind === 'relation'",
214
- "'Invalid kind'"
215
- ]
216
- });
76
+ invariant(kind === "object" || kind === "relation" || kind === "type", "Invalid kind", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 45, S: void 0, A: ["kind === 'object' || kind === 'relation' || kind === 'type'", "'Invalid kind'"] });
217
77
  return kind;
218
78
  },
219
79
  isDeleted: (object) => {
@@ -284,38 +144,86 @@ var ObjectStructure = Object.freeze({
284
144
  },
285
145
  data: data ?? {}
286
146
  };
147
+ },
148
+ makeType: ({ type, keys, data }) => {
149
+ return {
150
+ system: {
151
+ kind: "type",
152
+ type: {
153
+ "/": type
154
+ }
155
+ },
156
+ meta: {
157
+ keys: keys ?? []
158
+ },
159
+ data: data ?? {}
160
+ };
287
161
  }
288
162
  });
289
163
  var PROPERTY_ID = "id";
290
164
  var DATA_NAMESPACE = "data";
291
165
 
292
- // src/space-doc-version.ts
293
- var SpaceDocVersion = Object.freeze({
166
+ // src/edge-peer.ts
167
+ import { EdgeService } from "@dxos/protocols";
168
+ import { compositeKey } from "@dxos/util";
169
+ var isEdgePeerId = (peerId, spaceId) => {
170
+ const automergePrefix = spaceId !== void 0 ? compositeKey(EdgeService.AUTOMERGE_REPLICATOR, spaceId) : `${EdgeService.AUTOMERGE_REPLICATOR}:`;
171
+ const subductionPrefix = spaceId !== void 0 ? compositeKey(EdgeService.SUBDUCTION_REPLICATOR, spaceId) : `${EdgeService.SUBDUCTION_REPLICATOR}:`;
172
+ return peerId.startsWith(automergePrefix) || peerId.startsWith(subductionPrefix);
173
+ };
174
+
175
+ // src/echo-feed-codec.ts
176
+ import { FeedProtocol } from "@dxos/protocols";
177
+ var ATTR_META = "@meta";
178
+ var EchoFeedCodec = class _EchoFeedCodec {
179
+ static #encoder = new TextEncoder();
180
+ static #decoder = new TextDecoder();
294
181
  /**
295
- * For the documents created before the versioning was introduced.
182
+ * Prepares a value for feed storage (strips queue position from metadata) and encodes to bytes.
296
183
  */
297
- LEGACY: 0,
184
+ static encode(value2) {
185
+ const prepared = _EchoFeedCodec.#stripQueuePosition(value2);
186
+ return _EchoFeedCodec.#encoder.encode(JSON.stringify(prepared));
187
+ }
298
188
  /**
299
- * Current version.
189
+ * Decodes feed block bytes to a JSON value.
190
+ * If position is provided, injects queue position into the decoded object's metadata.
300
191
  */
301
- CURRENT: 1
302
- });
303
-
304
- // src/space-id.ts
305
- import { subtleCrypto } from "@dxos/crypto";
306
- import { PublicKey, SpaceId } from "@dxos/keys";
307
- import { ComplexMap } from "@dxos/util";
308
- var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
309
- var createIdFromSpaceKey = async (spaceKey) => {
310
- const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
311
- if (cachedValue !== void 0) {
312
- return cachedValue;
192
+ static decode(data, position) {
193
+ const decoded = JSON.parse(_EchoFeedCodec.#decoder.decode(data));
194
+ if (position !== void 0 && typeof decoded === "object" && decoded !== null) {
195
+ _EchoFeedCodec.#setQueuePosition(decoded, position);
196
+ }
197
+ return decoded;
198
+ }
199
+ static #stripQueuePosition(value2) {
200
+ if (typeof value2 !== "object" || value2 === null) {
201
+ return value2;
202
+ }
203
+ const obj = structuredClone(value2);
204
+ const meta = obj[ATTR_META];
205
+ if (meta?.keys?.some((key) => key.source === FeedProtocol.KEY_QUEUE_POSITION)) {
206
+ meta.keys = meta.keys.filter((key) => key.source !== FeedProtocol.KEY_QUEUE_POSITION);
207
+ }
208
+ return obj;
209
+ }
210
+ static #setQueuePosition(obj, position) {
211
+ obj[ATTR_META] ??= {
212
+ keys: []
213
+ };
214
+ obj[ATTR_META].keys ??= [];
215
+ const keys = obj[ATTR_META].keys;
216
+ for (let i = 0; i < keys.length; i++) {
217
+ if (keys[i].source === FeedProtocol.KEY_QUEUE_POSITION) {
218
+ keys.splice(i, 1);
219
+ i--;
220
+ }
221
+ }
222
+ keys.push({
223
+ source: FeedProtocol.KEY_QUEUE_POSITION,
224
+ id: position.toString()
225
+ });
313
226
  }
314
- const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
315
- const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
316
- const spaceId = SpaceId.encode(bytes);
317
- SPACE_IDS_CACHE.set(spaceKey, spaceId);
318
- return spaceId;
319
227
  };
320
228
 
321
229
  // src/foreign-key.ts
@@ -343,6 +251,7 @@ var ast_exports = {};
343
251
  __export(ast_exports, {
344
252
  Filter: () => Filter,
345
253
  FilterAnd: () => FilterAnd,
254
+ FilterChildOf: () => FilterChildOf,
346
255
  FilterCompare: () => FilterCompare,
347
256
  FilterContains: () => FilterContains,
348
257
  FilterIn: () => FilterIn,
@@ -352,10 +261,13 @@ __export(ast_exports, {
352
261
  FilterRange: () => FilterRange,
353
262
  FilterTag: () => FilterTag,
354
263
  FilterTextSearch: () => FilterTextSearch,
264
+ FilterTimestamp: () => FilterTimestamp,
355
265
  Order: () => Order,
356
266
  OrderDirection: () => OrderDirection,
357
267
  Query: () => Query,
358
268
  QueryFilterClause: () => QueryFilterClause,
269
+ QueryFromClause: () => QueryFromClause,
270
+ QueryFromClause_: () => QueryFromClause_,
359
271
  QueryHierarchyTraversalClause: () => QueryHierarchyTraversalClause,
360
272
  QueryIncomingReferencesClause: () => QueryIncomingReferencesClause,
361
273
  QueryLimitClause: () => QueryLimitClause,
@@ -368,15 +280,15 @@ __export(ast_exports, {
368
280
  QuerySelectClause: () => QuerySelectClause,
369
281
  QuerySetDifferenceClause: () => QuerySetDifferenceClause,
370
282
  QueryUnionClause: () => QueryUnionClause,
283
+ Scope: () => Scope,
371
284
  fold: () => fold,
285
+ map: () => map,
372
286
  visit: () => visit
373
287
  });
374
288
  import * as Match from "effect/Match";
375
289
  import * as Schema2 from "effect/Schema";
376
- import { DXN as DXN2, ObjectId } from "@dxos/keys";
377
- var TypenameSpecifier = Schema2.Union(DXN2.Schema, Schema2.Null).annotations({
378
- description: "DXN or null; null matches any type"
379
- });
290
+ import { EchoURI, ObjectId, URI } from "@dxos/keys";
291
+ var TypenameSpecifier = Schema2.Union(URI.Schema, Schema2.Null);
380
292
  var FilterObject_ = Schema2.Struct({
381
293
  type: Schema2.Literal("object"),
382
294
  typename: TypenameSpecifier,
@@ -394,7 +306,16 @@ var FilterObject_ = Schema2.Struct({
394
306
  /**
395
307
  * Objects that have any of the given foreign keys.
396
308
  */
397
- foreignKeys: Schema2.optional(Schema2.Array(ForeignKey))
309
+ foreignKeys: Schema2.optional(Schema2.Array(ForeignKey)),
310
+ /**
311
+ * Match objects whose meta `key` equals this fully-qualified registry key (FQN format).
312
+ */
313
+ metaKey: Schema2.optional(Schema2.String),
314
+ /**
315
+ * Semver range matched against the object's meta `version`.
316
+ * Only consulted when {@link metaKey} is set. Objects with no `version` do not satisfy a version-constrained filter.
317
+ */
318
+ metaVersion: Schema2.optional(Schema2.String)
398
319
  });
399
320
  var FilterObject = FilterObject_;
400
321
  var FilterCompare_ = Schema2.Struct({
@@ -424,6 +345,13 @@ var FilterRange_ = Schema2.Struct({
424
345
  to: Schema2.Any
425
346
  });
426
347
  var FilterRange = FilterRange_;
348
+ var FilterTimestamp_ = Schema2.Struct({
349
+ type: Schema2.Literal("timestamp"),
350
+ field: Schema2.Literal("createdAt", "updatedAt"),
351
+ operator: Schema2.Literal("gt", "gte", "lt", "lte"),
352
+ value: Schema2.Number
353
+ });
354
+ var FilterTimestamp = FilterTimestamp_;
427
355
  var FilterTextSearch_ = Schema2.Struct({
428
356
  type: Schema2.Literal("text-search"),
429
357
  text: Schema2.String,
@@ -445,8 +373,16 @@ var FilterOr_ = Schema2.Struct({
445
373
  filters: Schema2.Array(Schema2.suspend(() => Filter))
446
374
  });
447
375
  var FilterOr = FilterOr_;
448
- var Filter = Schema2.Union(FilterObject, FilterCompare, FilterIn, FilterContains, FilterTag, FilterRange, FilterTextSearch, FilterNot, FilterAnd, FilterOr).annotations({
449
- identifier: "dxos.org/schema/Filter"
376
+ var FilterChildOf_ = Schema2.Struct({
377
+ type: Schema2.Literal("child-of"),
378
+ /** Parent DXNs to match children of. */
379
+ parents: Schema2.Array(EchoURI.Schema),
380
+ /** Whether to match transitively (grandchildren, etc.). Defaults to true. */
381
+ transitive: Schema2.Boolean
382
+ });
383
+ var FilterChildOf = FilterChildOf_;
384
+ var Filter = Schema2.Union(FilterObject, FilterCompare, FilterIn, FilterContains, FilterTag, FilterRange, FilterTimestamp, FilterTextSearch, FilterChildOf, FilterNot, FilterAnd, FilterOr).annotations({
385
+ identifier: "org.dxos.schema.filter"
450
386
  });
451
387
  var QuerySelectClause_ = Schema2.Struct({
452
388
  type: Schema2.Literal("select"),
@@ -548,31 +484,47 @@ var QueryLimitClause_ = Schema2.Struct({
548
484
  limit: Schema2.Number
549
485
  });
550
486
  var QueryLimitClause = QueryLimitClause_;
551
- var Query_ = Schema2.Union(QuerySelectClause, QueryFilterClause, QueryReferenceTraversalClause, QueryIncomingReferencesClause, QueryRelationClause, QueryRelationTraversalClause, QueryHierarchyTraversalClause, QueryUnionClause, QuerySetDifferenceClause, QueryOrderClause, QueryOptionsClause, QueryLimitClause).annotations({
552
- identifier: "dxos.org/schema/Query"
487
+ var QueryFromClause_ = Schema2.Struct({
488
+ type: Schema2.Literal("from"),
489
+ query: Schema2.suspend(() => Query),
490
+ from: Schema2.Union(Schema2.TaggedStruct("scope", {
491
+ scope: Schema2.suspend(() => Scope)
492
+ }), Schema2.TaggedStruct("query", {
493
+ query: Schema2.suspend(() => Query)
494
+ }))
495
+ });
496
+ var QueryFromClause = QueryFromClause_;
497
+ var Query_ = Schema2.Union(QuerySelectClause, QueryFilterClause, QueryReferenceTraversalClause, QueryIncomingReferencesClause, QueryRelationClause, QueryRelationTraversalClause, QueryHierarchyTraversalClause, QueryUnionClause, QuerySetDifferenceClause, QueryOrderClause, QueryOptionsClause, QueryLimitClause, QueryFromClause).annotations({
498
+ identifier: "org.dxos.schema.query"
553
499
  });
554
500
  var Query = Query_;
555
501
  var QueryOptions = Schema2.Struct({
502
+ /**
503
+ * Nested select statements will use this option to filter deleted objects.
504
+ */
505
+ deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only")),
506
+ /**
507
+ * Diagnostics-only label for logs / tooling (not used by execution semantics).
508
+ */
509
+ debugLabel: Schema2.optional(Schema2.String)
510
+ });
511
+ var Scope = Schema2.Struct({
556
512
  /**
557
513
  * The nested select statemets will select from the given spaces.
558
514
  *
559
- * NOTE: Spaces and queues are unioned together if both are specified.
515
+ * NOTE: Spaces and feeds are unioned together if both are specified.
560
516
  */
561
517
  spaceIds: Schema2.optional(Schema2.Array(Schema2.String)),
562
518
  /**
563
- * If true, the nested select statements will select from all queues in the spaces specified by `spaceIds`.
519
+ * If true, the nested select statements will select from all feeds in the spaces specified by `spaceIds`.
564
520
  */
565
- allQueuesFromSpaces: Schema2.optional(Schema2.Boolean),
521
+ allFeedsFromSpaces: Schema2.optional(Schema2.Boolean),
566
522
  /**
567
- * The nested select statemets will select from the given queues.
523
+ * The nested select statemets will select from the given feeds (by EchoURI or legacy DXN).
568
524
  *
569
- * NOTE: Spaces and queues are unioned together if both are specified.
525
+ * NOTE: Spaces and feeds are unioned together if both are specified.
570
526
  */
571
- queues: Schema2.optional(Schema2.Array(DXN2.Schema)),
572
- /**
573
- * Nested select statements will use this option to filter deleted objects.
574
- */
575
- deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only"))
527
+ feeds: Schema2.optional(Schema2.Array(EchoURI.Schema))
576
528
  });
577
529
  var visit = (query, visitor) => {
578
530
  visitor(query);
@@ -602,10 +554,90 @@ var visit = (query, visitor) => {
602
554
  }, ({ query: query2 }) => visit(query2, visitor)), Match.when({
603
555
  type: "limit"
604
556
  }, ({ query: query2 }) => visit(query2, visitor)), Match.when({
557
+ type: "from"
558
+ }, (node) => {
559
+ visit(node.query, visitor);
560
+ if (node.from._tag === "query") {
561
+ visit(node.from.query, visitor);
562
+ }
563
+ }), Match.when({
605
564
  type: "select"
606
565
  }, () => {
607
566
  }), Match.exhaustive);
608
567
  };
568
+ var map = (query, mapper) => {
569
+ const mapped = Match.value(query).pipe(Match.when({
570
+ type: "filter"
571
+ }, (node) => ({
572
+ ...node,
573
+ selection: map(node.selection, mapper)
574
+ })), Match.when({
575
+ type: "reference-traversal"
576
+ }, (node) => ({
577
+ ...node,
578
+ anchor: map(node.anchor, mapper)
579
+ })), Match.when({
580
+ type: "incoming-references"
581
+ }, (node) => ({
582
+ ...node,
583
+ anchor: map(node.anchor, mapper)
584
+ })), Match.when({
585
+ type: "relation"
586
+ }, (node) => ({
587
+ ...node,
588
+ anchor: map(node.anchor, mapper)
589
+ })), Match.when({
590
+ type: "relation-traversal"
591
+ }, (node) => ({
592
+ ...node,
593
+ anchor: map(node.anchor, mapper)
594
+ })), Match.when({
595
+ type: "hierarchy-traversal"
596
+ }, (node) => ({
597
+ ...node,
598
+ anchor: map(node.anchor, mapper)
599
+ })), Match.when({
600
+ type: "options"
601
+ }, (node) => ({
602
+ ...node,
603
+ query: map(node.query, mapper)
604
+ })), Match.when({
605
+ type: "order"
606
+ }, (node) => ({
607
+ ...node,
608
+ query: map(node.query, mapper)
609
+ })), Match.when({
610
+ type: "limit"
611
+ }, (node) => ({
612
+ ...node,
613
+ query: map(node.query, mapper)
614
+ })), Match.when({
615
+ type: "from"
616
+ }, (node) => ({
617
+ ...node,
618
+ query: map(node.query, mapper),
619
+ ...node.from._tag === "query" ? {
620
+ from: {
621
+ _tag: "query",
622
+ query: map(node.from.query, mapper)
623
+ }
624
+ } : {}
625
+ })), Match.when({
626
+ type: "union"
627
+ }, (node) => ({
628
+ ...node,
629
+ queries: node.queries.map((q) => map(q, mapper))
630
+ })), Match.when({
631
+ type: "set-difference"
632
+ }, (node) => ({
633
+ ...node,
634
+ source: map(node.source, mapper),
635
+ exclude: map(node.exclude, mapper)
636
+ })), Match.when({
637
+ type: "select"
638
+ }, (node) => node), Match.exhaustive);
639
+ return mapper(mapped);
640
+ };
609
641
  var fold = (query, reducer) => {
610
642
  return Match.value(query).pipe(Match.withReturnType(), Match.when({
611
643
  type: "filter"
@@ -630,23 +662,59 @@ var fold = (query, reducer) => {
630
662
  }, ({ query: query2 }) => fold(query2, reducer)), Match.when({
631
663
  type: "limit"
632
664
  }, ({ query: query2 }) => fold(query2, reducer)), Match.when({
665
+ type: "from"
666
+ }, (node) => {
667
+ const results = fold(node.query, reducer);
668
+ if (node.from._tag === "query") {
669
+ return results.concat(fold(node.from.query, reducer));
670
+ }
671
+ return results;
672
+ }), Match.when({
633
673
  type: "select"
634
674
  }, () => []), Match.exhaustive);
635
675
  };
676
+
677
+ // src/space-doc-version.ts
678
+ var SpaceDocVersion = Object.freeze({
679
+ /**
680
+ * For the documents created before the versioning was introduced.
681
+ */
682
+ LEGACY: 0,
683
+ /**
684
+ * Current version.
685
+ */
686
+ CURRENT: 1
687
+ });
688
+
689
+ // src/space-id.ts
690
+ import { subtleCrypto } from "@dxos/crypto";
691
+ import { PublicKey, SpaceId } from "@dxos/keys";
692
+ import { ComplexMap } from "@dxos/util";
693
+ var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
694
+ var createIdFromSpaceKey = async (spaceKey) => {
695
+ const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
696
+ if (cachedValue !== void 0) {
697
+ return cachedValue;
698
+ }
699
+ const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
700
+ const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
701
+ const spaceId = SpaceId.encode(bytes);
702
+ SPACE_IDS_CACHE.set(spaceKey, spaceId);
703
+ return spaceId;
704
+ };
636
705
  export {
637
706
  DATA_NAMESPACE,
638
707
  DatabaseDirectory,
708
+ EchoFeedCodec,
639
709
  EncodedReference,
640
710
  ForeignKey,
641
711
  ObjectStructure,
642
712
  PROPERTY_ID,
643
713
  ast_exports as QueryAST,
644
714
  REFERENCE_TYPE_TAG,
645
- Reference,
646
715
  SpaceDocVersion,
647
716
  createIdFromSpaceKey,
648
- decodeReference,
649
- encodeReference,
717
+ isEdgePeerId,
650
718
  isEncodedReference
651
719
  };
652
720
  //# sourceMappingURL=index.mjs.map