@dxos/echo-protocol 0.8.4-main.d05673bc65 → 0.8.4-main.d9fc60f731

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,8 +249,10 @@ 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,
255
+ FilterChildOf: () => FilterChildOf,
371
256
  FilterCompare: () => FilterCompare,
372
257
  FilterContains: () => FilterContains,
373
258
  FilterIn: () => FilterIn,
@@ -377,6 +262,7 @@ __export(ast_exports, {
377
262
  FilterRange: () => FilterRange,
378
263
  FilterTag: () => FilterTag,
379
264
  FilterTextSearch: () => FilterTextSearch,
265
+ FilterTimestamp: () => FilterTimestamp,
380
266
  Order: () => Order,
381
267
  OrderDirection: () => OrderDirection,
382
268
  Query: () => Query,
@@ -395,21 +281,21 @@ __export(ast_exports, {
395
281
  QuerySelectClause: () => QuerySelectClause,
396
282
  QuerySetDifferenceClause: () => QuerySetDifferenceClause,
397
283
  QueryUnionClause: () => QueryUnionClause,
284
+ RegistryScope: () => RegistryScope,
398
285
  Scope: () => Scope,
286
+ SpaceScope: () => SpaceScope,
399
287
  fold: () => fold,
400
288
  map: () => map,
401
289
  visit: () => visit
402
290
  });
403
291
  import * as Match from "effect/Match";
404
292
  import * as Schema2 from "effect/Schema";
405
- import { DXN as DXN2, ObjectId } from "@dxos/keys";
406
- var TypenameSpecifier = Schema2.Union(DXN2.Schema, Schema2.Null).annotations({
407
- description: "DXN or null; null matches any type"
408
- });
293
+ import { EID, EntityId, URI } from "@dxos/keys";
294
+ var TypenameSpecifier = Schema2.Union(URI.Schema, Schema2.Null);
409
295
  var FilterObject_ = Schema2.Struct({
410
296
  type: Schema2.Literal("object"),
411
297
  typename: TypenameSpecifier,
412
- id: Schema2.optional(Schema2.Array(ObjectId)),
298
+ id: Schema2.optional(Schema2.Array(EntityId)),
413
299
  /**
414
300
  * Filter by property.
415
301
  * Must not include object ID.
@@ -423,7 +309,16 @@ var FilterObject_ = Schema2.Struct({
423
309
  /**
424
310
  * Objects that have any of the given foreign keys.
425
311
  */
426
- 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)
427
322
  });
428
323
  var FilterObject = FilterObject_;
429
324
  var FilterCompare_ = Schema2.Struct({
@@ -453,6 +348,13 @@ var FilterRange_ = Schema2.Struct({
453
348
  to: Schema2.Any
454
349
  });
455
350
  var FilterRange = FilterRange_;
351
+ var FilterTimestamp_ = Schema2.Struct({
352
+ type: Schema2.Literal("timestamp"),
353
+ field: Schema2.Literal("createdAt", "updatedAt"),
354
+ operator: Schema2.Literal("gt", "gte", "lt", "lte"),
355
+ value: Schema2.Number
356
+ });
357
+ var FilterTimestamp = FilterTimestamp_;
456
358
  var FilterTextSearch_ = Schema2.Struct({
457
359
  type: Schema2.Literal("text-search"),
458
360
  text: Schema2.String,
@@ -474,7 +376,15 @@ var FilterOr_ = Schema2.Struct({
474
376
  filters: Schema2.Array(Schema2.suspend(() => Filter))
475
377
  });
476
378
  var FilterOr = FilterOr_;
477
- var Filter = Schema2.Union(FilterObject, FilterCompare, FilterIn, FilterContains, FilterTag, FilterRange, FilterTextSearch, FilterNot, FilterAnd, FilterOr).annotations({
379
+ var FilterChildOf_ = Schema2.Struct({
380
+ type: Schema2.Literal("child-of"),
381
+ /** Parent DXNs to match children of. */
382
+ parents: Schema2.Array(EID.Schema),
383
+ /** Whether to match transitively (grandchildren, etc.). Defaults to true. */
384
+ transitive: Schema2.Boolean
385
+ });
386
+ var FilterChildOf = FilterChildOf_;
387
+ var Filter = Schema2.Union(FilterObject, FilterCompare, FilterIn, FilterContains, FilterTag, FilterRange, FilterTimestamp, FilterTextSearch, FilterChildOf, FilterNot, FilterAnd, FilterOr).annotations({
478
388
  identifier: "org.dxos.schema.filter"
479
389
  });
480
390
  var QuerySelectClause_ = Schema2.Struct({
@@ -581,7 +491,7 @@ var QueryFromClause_ = Schema2.Struct({
581
491
  type: Schema2.Literal("from"),
582
492
  query: Schema2.suspend(() => Query),
583
493
  from: Schema2.Union(Schema2.TaggedStruct("scope", {
584
- scope: Schema2.suspend(() => Scope)
494
+ scopes: Schema2.Array(Schema2.suspend(() => Scope))
585
495
  }), Schema2.TaggedStruct("query", {
586
496
  query: Schema2.suspend(() => Query)
587
497
  }))
@@ -595,26 +505,23 @@ var QueryOptions = Schema2.Struct({
595
505
  /**
596
506
  * Nested select statements will use this option to filter deleted objects.
597
507
  */
598
- deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only"))
599
- });
600
- var Scope = Schema2.Struct({
508
+ deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only")),
601
509
  /**
602
- * The nested select statemets will select from the given spaces.
603
- *
604
- * NOTE: Spaces and queues are unioned together if both are specified.
510
+ * Diagnostics-only label for logs / tooling (not used by execution semantics).
605
511
  */
606
- spaceIds: Schema2.optional(Schema2.Array(Schema2.String)),
607
- /**
608
- * If true, the nested select statements will select from all queues in the spaces specified by `spaceIds`.
609
- */
610
- allQueuesFromSpaces: Schema2.optional(Schema2.Boolean),
611
- /**
612
- * The nested select statemets will select from the given queues.
613
- *
614
- * NOTE: Spaces and queues are unioned together if both are specified.
615
- */
616
- queues: Schema2.optional(Schema2.Array(DXN2.Schema))
512
+ debugLabel: Schema2.optional(Schema2.String)
513
+ });
514
+ var SpaceScope = Schema2.TaggedStruct("space", {
515
+ spaceId: Schema2.optional(Schema2.String),
516
+ includeAllFeeds: Schema2.optional(Schema2.Boolean)
517
+ });
518
+ var FeedScope = Schema2.TaggedStruct("feed", {
519
+ feedUri: Schema2.String
520
+ });
521
+ var RegistryScope = Schema2.TaggedStruct("registry", {
522
+ location: Schema2.Literal("local", "remote")
617
523
  });
524
+ var Scope = Schema2.Union(SpaceScope, FeedScope, RegistryScope);
618
525
  var visit = (query, visitor) => {
619
526
  visitor(query);
620
527
  Match.value(query).pipe(Match.when({
@@ -796,16 +703,14 @@ export {
796
703
  DatabaseDirectory,
797
704
  EchoFeedCodec,
798
705
  EncodedReference,
706
+ EntityStructure,
799
707
  ForeignKey,
800
- ObjectStructure,
801
708
  PROPERTY_ID,
802
709
  ast_exports as QueryAST,
803
710
  REFERENCE_TYPE_TAG,
804
- Reference,
805
711
  SpaceDocVersion,
806
712
  createIdFromSpaceKey,
807
- decodeReference,
808
- encodeReference,
713
+ isEdgePeerId,
809
714
  isEncodedReference
810
715
  };
811
716
  //# sourceMappingURL=index.mjs.map