@dxos/echo-protocol 0.8.4-staging.ac66bdf99f → 0.9.0

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/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -18,4 +18,4 @@ pnpm i @dxos/echo-protocol
18
18
 
19
19
  Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
20
20
 
21
- License: [MIT](./LICENSE) Copyright 2022 © DXOS
21
+ License: [FSL-1.1-Apache-2.0](./LICENSE) Copyright 2022 © DXOS
@@ -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 `EID.isEID(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) => {
@@ -193,7 +61,7 @@ var DatabaseDirectory = Object.freeze({
193
61
  links: links ?? {}
194
62
  })
195
63
  });
196
- var ObjectStructure = Object.freeze({
64
+ var EntityStructure = Object.freeze({
197
65
  /**
198
66
  * @throws On invalid object structure.
199
67
  */
@@ -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,11 +144,34 @@ 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
 
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
+
292
175
  // src/echo-feed-codec.ts
293
176
  import { FeedProtocol } from "@dxos/protocols";
294
177
  var ATTR_META = "@meta";
@@ -366,6 +249,7 @@ var ForeignKey = ForeignKey_;
366
249
  // src/query/ast.ts
367
250
  var ast_exports = {};
368
251
  __export(ast_exports, {
252
+ FeedScope: () => FeedScope,
369
253
  Filter: () => Filter,
370
254
  FilterAnd: () => FilterAnd,
371
255
  FilterChildOf: () => FilterChildOf,
@@ -397,21 +281,21 @@ __export(ast_exports, {
397
281
  QuerySelectClause: () => QuerySelectClause,
398
282
  QuerySetDifferenceClause: () => QuerySetDifferenceClause,
399
283
  QueryUnionClause: () => QueryUnionClause,
284
+ RegistryScope: () => RegistryScope,
400
285
  Scope: () => Scope,
286
+ SpaceScope: () => SpaceScope,
401
287
  fold: () => fold,
402
288
  map: () => map,
403
289
  visit: () => visit
404
290
  });
405
291
  import * as Match from "effect/Match";
406
292
  import * as Schema2 from "effect/Schema";
407
- import { DXN as DXN2, ObjectId } from "@dxos/keys";
408
- var TypenameSpecifier = Schema2.Union(DXN2.Schema, Schema2.Null).annotations({
409
- description: "DXN or null; null matches any type"
410
- });
293
+ import { EID, EntityId, URI } from "@dxos/keys";
294
+ var TypenameSpecifier = Schema2.Union(URI.Schema, Schema2.Null);
411
295
  var FilterObject_ = Schema2.Struct({
412
296
  type: Schema2.Literal("object"),
413
297
  typename: TypenameSpecifier,
414
- id: Schema2.optional(Schema2.Array(ObjectId)),
298
+ id: Schema2.optional(Schema2.Array(EntityId)),
415
299
  /**
416
300
  * Filter by property.
417
301
  * Must not include object ID.
@@ -425,7 +309,16 @@ var FilterObject_ = Schema2.Struct({
425
309
  /**
426
310
  * Objects that have any of the given foreign keys.
427
311
  */
428
- foreignKeys: Schema2.optional(Schema2.Array(ForeignKey))
312
+ foreignKeys: Schema2.optional(Schema2.Array(ForeignKey)),
313
+ /**
314
+ * Match objects whose meta `key` equals this fully-qualified registry key (FQN format).
315
+ */
316
+ metaKey: Schema2.optional(Schema2.String),
317
+ /**
318
+ * Semver range matched against the object's meta `version`.
319
+ * Only consulted when {@link metaKey} is set. Objects with no `version` do not satisfy a version-constrained filter.
320
+ */
321
+ metaVersion: Schema2.optional(Schema2.String)
429
322
  });
430
323
  var FilterObject = FilterObject_;
431
324
  var FilterCompare_ = Schema2.Struct({
@@ -486,7 +379,7 @@ var FilterOr = FilterOr_;
486
379
  var FilterChildOf_ = Schema2.Struct({
487
380
  type: Schema2.Literal("child-of"),
488
381
  /** Parent DXNs to match children of. */
489
- parents: Schema2.Array(DXN2.Schema),
382
+ parents: Schema2.Array(EID.Schema),
490
383
  /** Whether to match transitively (grandchildren, etc.). Defaults to true. */
491
384
  transitive: Schema2.Boolean
492
385
  });
@@ -574,6 +467,11 @@ var Order_ = Schema2.Union(Schema2.Struct({
574
467
  // Default direction is 'desc' (higher rank = better match first).
575
468
  kind: Schema2.Literal("rank"),
576
469
  direction: OrderDirection
470
+ }), Schema2.Struct({
471
+ // Order by system timestamp (createdAt / updatedAt) from the object meta index.
472
+ kind: Schema2.Literal("timestamp"),
473
+ field: Schema2.Literal("createdAt", "updatedAt"),
474
+ direction: OrderDirection
577
475
  }));
578
476
  var Order = Order_;
579
477
  var QueryOrderClause_ = Schema2.Struct({
@@ -598,7 +496,7 @@ var QueryFromClause_ = Schema2.Struct({
598
496
  type: Schema2.Literal("from"),
599
497
  query: Schema2.suspend(() => Query),
600
498
  from: Schema2.Union(Schema2.TaggedStruct("scope", {
601
- scope: Schema2.suspend(() => Scope)
499
+ scopes: Schema2.Array(Schema2.suspend(() => Scope))
602
500
  }), Schema2.TaggedStruct("query", {
603
501
  query: Schema2.suspend(() => Query)
604
502
  }))
@@ -612,26 +510,23 @@ var QueryOptions = Schema2.Struct({
612
510
  /**
613
511
  * Nested select statements will use this option to filter deleted objects.
614
512
  */
615
- deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only"))
616
- });
617
- var Scope = Schema2.Struct({
513
+ deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only")),
618
514
  /**
619
- * The nested select statemets will select from the given spaces.
620
- *
621
- * NOTE: Spaces and queues are unioned together if both are specified.
515
+ * Diagnostics-only label for logs / tooling (not used by execution semantics).
622
516
  */
623
- spaceIds: Schema2.optional(Schema2.Array(Schema2.String)),
624
- /**
625
- * If true, the nested select statements will select from all queues in the spaces specified by `spaceIds`.
626
- */
627
- allQueuesFromSpaces: Schema2.optional(Schema2.Boolean),
628
- /**
629
- * The nested select statemets will select from the given queues.
630
- *
631
- * NOTE: Spaces and queues are unioned together if both are specified.
632
- */
633
- queues: Schema2.optional(Schema2.Array(DXN2.Schema))
517
+ debugLabel: Schema2.optional(Schema2.String)
518
+ });
519
+ var SpaceScope = Schema2.TaggedStruct("space", {
520
+ spaceId: Schema2.optional(Schema2.String),
521
+ includeAllFeeds: Schema2.optional(Schema2.Boolean)
522
+ });
523
+ var FeedScope = Schema2.TaggedStruct("feed", {
524
+ feedUri: Schema2.String
525
+ });
526
+ var RegistryScope = Schema2.TaggedStruct("registry", {
527
+ location: Schema2.Literal("local", "remote")
634
528
  });
529
+ var Scope = Schema2.Union(SpaceScope, FeedScope, RegistryScope);
635
530
  var visit = (query, visitor) => {
636
531
  visitor(query);
637
532
  Match.value(query).pipe(Match.when({
@@ -813,16 +708,14 @@ export {
813
708
  DatabaseDirectory,
814
709
  EchoFeedCodec,
815
710
  EncodedReference,
711
+ EntityStructure,
816
712
  ForeignKey,
817
- ObjectStructure,
818
713
  PROPERTY_ID,
819
714
  ast_exports as QueryAST,
820
715
  REFERENCE_TYPE_TAG,
821
- Reference,
822
716
  SpaceDocVersion,
823
717
  createIdFromSpaceKey,
824
- decodeReference,
825
- encodeReference,
718
+ isEdgePeerId,
826
719
  isEncodedReference
827
720
  };
828
721
  //# sourceMappingURL=index.mjs.map