@dxos/echo-protocol 0.8.4-main.ead640a → 0.8.4-main.f466a3d56e
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 +102 -5
- package/README.md +1 -1
- package/dist/lib/{browser → neutral}/index.mjs +303 -80
- 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 +18 -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/edge-peer.d.ts +11 -0
- package/dist/types/src/edge-peer.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +5 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/query/ast.d.ts +147 -34
- 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 +14 -15
- package/src/document-structure.ts +23 -1
- package/src/echo-feed-codec.ts +67 -0
- package/src/edge-peer.ts +27 -0
- package/src/index.ts +5 -3
- package/src/query/ast.ts +197 -12
- 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
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
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: [
|
|
21
|
+
License: [FSL-1.1-Apache-2.0](./LICENSE) Copyright 2022 © DXOS
|
|
@@ -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,67 @@ var ObjectStructure = Object.freeze({
|
|
|
288
273
|
var PROPERTY_ID = "id";
|
|
289
274
|
var DATA_NAMESPACE = "data";
|
|
290
275
|
|
|
291
|
-
// src/
|
|
292
|
-
|
|
276
|
+
// src/edge-peer.ts
|
|
277
|
+
import { EdgeService } from "@dxos/protocols";
|
|
278
|
+
import { compositeKey } from "@dxos/util";
|
|
279
|
+
var isEdgePeerId = (peerId, spaceId) => {
|
|
280
|
+
const automergePrefix = spaceId !== void 0 ? compositeKey(EdgeService.AUTOMERGE_REPLICATOR, spaceId) : `${EdgeService.AUTOMERGE_REPLICATOR}:`;
|
|
281
|
+
const subductionPrefix = spaceId !== void 0 ? compositeKey(EdgeService.SUBDUCTION_REPLICATOR, spaceId) : `${EdgeService.SUBDUCTION_REPLICATOR}:`;
|
|
282
|
+
return peerId.startsWith(automergePrefix) || peerId.startsWith(subductionPrefix);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// src/echo-feed-codec.ts
|
|
286
|
+
import { FeedProtocol } from "@dxos/protocols";
|
|
287
|
+
var ATTR_META = "@meta";
|
|
288
|
+
var EchoFeedCodec = class _EchoFeedCodec {
|
|
289
|
+
static #encoder = new TextEncoder();
|
|
290
|
+
static #decoder = new TextDecoder();
|
|
293
291
|
/**
|
|
294
|
-
*
|
|
292
|
+
* Prepares a value for feed storage (strips queue position from metadata) and encodes to bytes.
|
|
295
293
|
*/
|
|
296
|
-
|
|
294
|
+
static encode(value2) {
|
|
295
|
+
const prepared = _EchoFeedCodec.#stripQueuePosition(value2);
|
|
296
|
+
return _EchoFeedCodec.#encoder.encode(JSON.stringify(prepared));
|
|
297
|
+
}
|
|
297
298
|
/**
|
|
298
|
-
*
|
|
299
|
+
* Decodes feed block bytes to a JSON value.
|
|
300
|
+
* If position is provided, injects queue position into the decoded object's metadata.
|
|
299
301
|
*/
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
302
|
+
static decode(data, position) {
|
|
303
|
+
const decoded = JSON.parse(_EchoFeedCodec.#decoder.decode(data));
|
|
304
|
+
if (position !== void 0 && typeof decoded === "object" && decoded !== null) {
|
|
305
|
+
_EchoFeedCodec.#setQueuePosition(decoded, position);
|
|
306
|
+
}
|
|
307
|
+
return decoded;
|
|
308
|
+
}
|
|
309
|
+
static #stripQueuePosition(value2) {
|
|
310
|
+
if (typeof value2 !== "object" || value2 === null) {
|
|
311
|
+
return value2;
|
|
312
|
+
}
|
|
313
|
+
const obj = structuredClone(value2);
|
|
314
|
+
const meta = obj[ATTR_META];
|
|
315
|
+
if (meta?.keys?.some((key) => key.source === FeedProtocol.KEY_QUEUE_POSITION)) {
|
|
316
|
+
meta.keys = meta.keys.filter((key) => key.source !== FeedProtocol.KEY_QUEUE_POSITION);
|
|
317
|
+
}
|
|
318
|
+
return obj;
|
|
319
|
+
}
|
|
320
|
+
static #setQueuePosition(obj, position) {
|
|
321
|
+
obj[ATTR_META] ??= {
|
|
322
|
+
keys: []
|
|
323
|
+
};
|
|
324
|
+
obj[ATTR_META].keys ??= [];
|
|
325
|
+
const keys = obj[ATTR_META].keys;
|
|
326
|
+
for (let i = 0; i < keys.length; i++) {
|
|
327
|
+
if (keys[i].source === FeedProtocol.KEY_QUEUE_POSITION) {
|
|
328
|
+
keys.splice(i, 1);
|
|
329
|
+
i--;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
keys.push({
|
|
333
|
+
source: FeedProtocol.KEY_QUEUE_POSITION,
|
|
334
|
+
id: position.toString()
|
|
335
|
+
});
|
|
312
336
|
}
|
|
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
337
|
};
|
|
319
338
|
|
|
320
339
|
// src/foreign-key.ts
|
|
@@ -342,6 +361,7 @@ var ast_exports = {};
|
|
|
342
361
|
__export(ast_exports, {
|
|
343
362
|
Filter: () => Filter,
|
|
344
363
|
FilterAnd: () => FilterAnd,
|
|
364
|
+
FilterChildOf: () => FilterChildOf,
|
|
345
365
|
FilterCompare: () => FilterCompare,
|
|
346
366
|
FilterContains: () => FilterContains,
|
|
347
367
|
FilterIn: () => FilterIn,
|
|
@@ -351,11 +371,16 @@ __export(ast_exports, {
|
|
|
351
371
|
FilterRange: () => FilterRange,
|
|
352
372
|
FilterTag: () => FilterTag,
|
|
353
373
|
FilterTextSearch: () => FilterTextSearch,
|
|
374
|
+
FilterTimestamp: () => FilterTimestamp,
|
|
354
375
|
Order: () => Order,
|
|
355
376
|
OrderDirection: () => OrderDirection,
|
|
356
377
|
Query: () => Query,
|
|
357
378
|
QueryFilterClause: () => QueryFilterClause,
|
|
379
|
+
QueryFromClause: () => QueryFromClause,
|
|
380
|
+
QueryFromClause_: () => QueryFromClause_,
|
|
381
|
+
QueryHierarchyTraversalClause: () => QueryHierarchyTraversalClause,
|
|
358
382
|
QueryIncomingReferencesClause: () => QueryIncomingReferencesClause,
|
|
383
|
+
QueryLimitClause: () => QueryLimitClause,
|
|
359
384
|
QueryOptions: () => QueryOptions,
|
|
360
385
|
QueryOptionsClause: () => QueryOptionsClause,
|
|
361
386
|
QueryOrderClause: () => QueryOrderClause,
|
|
@@ -365,14 +390,16 @@ __export(ast_exports, {
|
|
|
365
390
|
QuerySelectClause: () => QuerySelectClause,
|
|
366
391
|
QuerySetDifferenceClause: () => QuerySetDifferenceClause,
|
|
367
392
|
QueryUnionClause: () => QueryUnionClause,
|
|
393
|
+
Scope: () => Scope,
|
|
368
394
|
fold: () => fold,
|
|
395
|
+
map: () => map,
|
|
369
396
|
visit: () => visit
|
|
370
397
|
});
|
|
371
398
|
import * as Match from "effect/Match";
|
|
372
399
|
import * as Schema2 from "effect/Schema";
|
|
373
400
|
import { DXN as DXN2, ObjectId } from "@dxos/keys";
|
|
374
401
|
var TypenameSpecifier = Schema2.Union(DXN2.Schema, Schema2.Null).annotations({
|
|
375
|
-
description: "DXN or null
|
|
402
|
+
description: "DXN or null; null matches any type"
|
|
376
403
|
});
|
|
377
404
|
var FilterObject_ = Schema2.Struct({
|
|
378
405
|
type: Schema2.Literal("object"),
|
|
@@ -391,7 +418,16 @@ var FilterObject_ = Schema2.Struct({
|
|
|
391
418
|
/**
|
|
392
419
|
* Objects that have any of the given foreign keys.
|
|
393
420
|
*/
|
|
394
|
-
foreignKeys: Schema2.optional(Schema2.Array(ForeignKey))
|
|
421
|
+
foreignKeys: Schema2.optional(Schema2.Array(ForeignKey)),
|
|
422
|
+
/**
|
|
423
|
+
* Match objects whose meta `key` equals this fully-qualified registry key (FQN format).
|
|
424
|
+
*/
|
|
425
|
+
metaKey: Schema2.optional(Schema2.String),
|
|
426
|
+
/**
|
|
427
|
+
* Semver range matched against the object's meta `version`.
|
|
428
|
+
* Only consulted when {@link metaKey} is set. Objects with no `version` do not satisfy a version-constrained filter.
|
|
429
|
+
*/
|
|
430
|
+
metaVersion: Schema2.optional(Schema2.String)
|
|
395
431
|
});
|
|
396
432
|
var FilterObject = FilterObject_;
|
|
397
433
|
var FilterCompare_ = Schema2.Struct({
|
|
@@ -421,6 +457,13 @@ var FilterRange_ = Schema2.Struct({
|
|
|
421
457
|
to: Schema2.Any
|
|
422
458
|
});
|
|
423
459
|
var FilterRange = FilterRange_;
|
|
460
|
+
var FilterTimestamp_ = Schema2.Struct({
|
|
461
|
+
type: Schema2.Literal("timestamp"),
|
|
462
|
+
field: Schema2.Literal("createdAt", "updatedAt"),
|
|
463
|
+
operator: Schema2.Literal("gt", "gte", "lt", "lte"),
|
|
464
|
+
value: Schema2.Number
|
|
465
|
+
});
|
|
466
|
+
var FilterTimestamp = FilterTimestamp_;
|
|
424
467
|
var FilterTextSearch_ = Schema2.Struct({
|
|
425
468
|
type: Schema2.Literal("text-search"),
|
|
426
469
|
text: Schema2.String,
|
|
@@ -442,8 +485,16 @@ var FilterOr_ = Schema2.Struct({
|
|
|
442
485
|
filters: Schema2.Array(Schema2.suspend(() => Filter))
|
|
443
486
|
});
|
|
444
487
|
var FilterOr = FilterOr_;
|
|
445
|
-
var
|
|
446
|
-
|
|
488
|
+
var FilterChildOf_ = Schema2.Struct({
|
|
489
|
+
type: Schema2.Literal("child-of"),
|
|
490
|
+
/** Parent DXNs to match children of. */
|
|
491
|
+
parents: Schema2.Array(DXN2.Schema),
|
|
492
|
+
/** Whether to match transitively (grandchildren, etc.). Defaults to true. */
|
|
493
|
+
transitive: Schema2.Boolean
|
|
494
|
+
});
|
|
495
|
+
var FilterChildOf = FilterChildOf_;
|
|
496
|
+
var Filter = Schema2.Union(FilterObject, FilterCompare, FilterIn, FilterContains, FilterTag, FilterRange, FilterTimestamp, FilterTextSearch, FilterChildOf, FilterNot, FilterAnd, FilterOr).annotations({
|
|
497
|
+
identifier: "org.dxos.schema.filter"
|
|
447
498
|
});
|
|
448
499
|
var QuerySelectClause_ = Schema2.Struct({
|
|
449
500
|
type: Schema2.Literal("select"),
|
|
@@ -465,7 +516,11 @@ var QueryReferenceTraversalClause = QueryReferenceTraversalClause_;
|
|
|
465
516
|
var QueryIncomingReferencesClause_ = Schema2.Struct({
|
|
466
517
|
type: Schema2.Literal("incoming-references"),
|
|
467
518
|
anchor: Schema2.suspend(() => Query),
|
|
468
|
-
|
|
519
|
+
/**
|
|
520
|
+
* Property path where the reference is located.
|
|
521
|
+
* If null, matches references from any property.
|
|
522
|
+
*/
|
|
523
|
+
property: Schema2.NullOr(Schema2.String),
|
|
469
524
|
typename: TypenameSpecifier
|
|
470
525
|
});
|
|
471
526
|
var QueryIncomingReferencesClause = QueryIncomingReferencesClause_;
|
|
@@ -487,6 +542,16 @@ var QueryRelationTraversalClause_ = Schema2.Struct({
|
|
|
487
542
|
direction: Schema2.Literal("source", "target", "both")
|
|
488
543
|
});
|
|
489
544
|
var QueryRelationTraversalClause = QueryRelationTraversalClause_;
|
|
545
|
+
var QueryHierarchyTraversalClause_ = Schema2.Struct({
|
|
546
|
+
type: Schema2.Literal("hierarchy-traversal"),
|
|
547
|
+
anchor: Schema2.suspend(() => Query),
|
|
548
|
+
/**
|
|
549
|
+
* to-parent: traverse from child to parent.
|
|
550
|
+
* to-children: traverse from parent to children.
|
|
551
|
+
*/
|
|
552
|
+
direction: Schema2.Literal("to-parent", "to-children")
|
|
553
|
+
});
|
|
554
|
+
var QueryHierarchyTraversalClause = QueryHierarchyTraversalClause_;
|
|
490
555
|
var QueryUnionClause_ = Schema2.Struct({
|
|
491
556
|
type: Schema2.Literal("union"),
|
|
492
557
|
queries: Schema2.Array(Schema2.suspend(() => Query))
|
|
@@ -506,6 +571,11 @@ var Order_ = Schema2.Union(Schema2.Struct({
|
|
|
506
571
|
kind: Schema2.Literal("property"),
|
|
507
572
|
property: Schema2.String,
|
|
508
573
|
direction: OrderDirection
|
|
574
|
+
}), Schema2.Struct({
|
|
575
|
+
// Order by relevance rank (for FTS/vector search results).
|
|
576
|
+
// Default direction is 'desc' (higher rank = better match first).
|
|
577
|
+
kind: Schema2.Literal("rank"),
|
|
578
|
+
direction: OrderDirection
|
|
509
579
|
}));
|
|
510
580
|
var Order = Order_;
|
|
511
581
|
var QueryOrderClause_ = Schema2.Struct({
|
|
@@ -520,27 +590,53 @@ var QueryOptionsClause_ = Schema2.Struct({
|
|
|
520
590
|
options: Schema2.suspend(() => QueryOptions)
|
|
521
591
|
});
|
|
522
592
|
var QueryOptionsClause = QueryOptionsClause_;
|
|
523
|
-
var
|
|
524
|
-
|
|
593
|
+
var QueryLimitClause_ = Schema2.Struct({
|
|
594
|
+
type: Schema2.Literal("limit"),
|
|
595
|
+
query: Schema2.suspend(() => Query),
|
|
596
|
+
limit: Schema2.Number
|
|
597
|
+
});
|
|
598
|
+
var QueryLimitClause = QueryLimitClause_;
|
|
599
|
+
var QueryFromClause_ = Schema2.Struct({
|
|
600
|
+
type: Schema2.Literal("from"),
|
|
601
|
+
query: Schema2.suspend(() => Query),
|
|
602
|
+
from: Schema2.Union(Schema2.TaggedStruct("scope", {
|
|
603
|
+
scope: Schema2.suspend(() => Scope)
|
|
604
|
+
}), Schema2.TaggedStruct("query", {
|
|
605
|
+
query: Schema2.suspend(() => Query)
|
|
606
|
+
}))
|
|
607
|
+
});
|
|
608
|
+
var QueryFromClause = QueryFromClause_;
|
|
609
|
+
var Query_ = Schema2.Union(QuerySelectClause, QueryFilterClause, QueryReferenceTraversalClause, QueryIncomingReferencesClause, QueryRelationClause, QueryRelationTraversalClause, QueryHierarchyTraversalClause, QueryUnionClause, QuerySetDifferenceClause, QueryOrderClause, QueryOptionsClause, QueryLimitClause, QueryFromClause).annotations({
|
|
610
|
+
identifier: "org.dxos.schema.query"
|
|
525
611
|
});
|
|
526
612
|
var Query = Query_;
|
|
527
613
|
var QueryOptions = Schema2.Struct({
|
|
614
|
+
/**
|
|
615
|
+
* Nested select statements will use this option to filter deleted objects.
|
|
616
|
+
*/
|
|
617
|
+
deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only")),
|
|
618
|
+
/**
|
|
619
|
+
* Diagnostics-only label for logs / tooling (not used by execution semantics).
|
|
620
|
+
*/
|
|
621
|
+
debugLabel: Schema2.optional(Schema2.String)
|
|
622
|
+
});
|
|
623
|
+
var Scope = Schema2.Struct({
|
|
528
624
|
/**
|
|
529
625
|
* The nested select statemets will select from the given spaces.
|
|
530
626
|
*
|
|
531
|
-
* NOTE: Spaces and
|
|
627
|
+
* NOTE: Spaces and feeds are unioned together if both are specified.
|
|
532
628
|
*/
|
|
533
629
|
spaceIds: Schema2.optional(Schema2.Array(Schema2.String)),
|
|
534
630
|
/**
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
631
|
+
* If true, the nested select statements will select from all feeds in the spaces specified by `spaceIds`.
|
|
538
632
|
*/
|
|
539
|
-
|
|
633
|
+
allFeedsFromSpaces: Schema2.optional(Schema2.Boolean),
|
|
540
634
|
/**
|
|
541
|
-
*
|
|
635
|
+
* The nested select statemets will select from the given feeds (by underlying queue DXN).
|
|
636
|
+
*
|
|
637
|
+
* NOTE: Spaces and feeds are unioned together if both are specified.
|
|
542
638
|
*/
|
|
543
|
-
|
|
639
|
+
feeds: Schema2.optional(Schema2.Array(DXN2.Schema))
|
|
544
640
|
});
|
|
545
641
|
var visit = (query, visitor) => {
|
|
546
642
|
visitor(query);
|
|
@@ -556,6 +652,8 @@ var visit = (query, visitor) => {
|
|
|
556
652
|
type: "options"
|
|
557
653
|
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
558
654
|
type: "relation-traversal"
|
|
655
|
+
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
656
|
+
type: "hierarchy-traversal"
|
|
559
657
|
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
560
658
|
type: "union"
|
|
561
659
|
}, ({ queries }) => queries.forEach((q) => visit(q, visitor))), Match.when({
|
|
@@ -566,10 +664,92 @@ var visit = (query, visitor) => {
|
|
|
566
664
|
}), Match.when({
|
|
567
665
|
type: "order"
|
|
568
666
|
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
667
|
+
type: "limit"
|
|
668
|
+
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
669
|
+
type: "from"
|
|
670
|
+
}, (node) => {
|
|
671
|
+
visit(node.query, visitor);
|
|
672
|
+
if (node.from._tag === "query") {
|
|
673
|
+
visit(node.from.query, visitor);
|
|
674
|
+
}
|
|
675
|
+
}), Match.when({
|
|
569
676
|
type: "select"
|
|
570
677
|
}, () => {
|
|
571
678
|
}), Match.exhaustive);
|
|
572
679
|
};
|
|
680
|
+
var map = (query, mapper) => {
|
|
681
|
+
const mapped = Match.value(query).pipe(Match.when({
|
|
682
|
+
type: "filter"
|
|
683
|
+
}, (node) => ({
|
|
684
|
+
...node,
|
|
685
|
+
selection: map(node.selection, mapper)
|
|
686
|
+
})), Match.when({
|
|
687
|
+
type: "reference-traversal"
|
|
688
|
+
}, (node) => ({
|
|
689
|
+
...node,
|
|
690
|
+
anchor: map(node.anchor, mapper)
|
|
691
|
+
})), Match.when({
|
|
692
|
+
type: "incoming-references"
|
|
693
|
+
}, (node) => ({
|
|
694
|
+
...node,
|
|
695
|
+
anchor: map(node.anchor, mapper)
|
|
696
|
+
})), Match.when({
|
|
697
|
+
type: "relation"
|
|
698
|
+
}, (node) => ({
|
|
699
|
+
...node,
|
|
700
|
+
anchor: map(node.anchor, mapper)
|
|
701
|
+
})), Match.when({
|
|
702
|
+
type: "relation-traversal"
|
|
703
|
+
}, (node) => ({
|
|
704
|
+
...node,
|
|
705
|
+
anchor: map(node.anchor, mapper)
|
|
706
|
+
})), Match.when({
|
|
707
|
+
type: "hierarchy-traversal"
|
|
708
|
+
}, (node) => ({
|
|
709
|
+
...node,
|
|
710
|
+
anchor: map(node.anchor, mapper)
|
|
711
|
+
})), Match.when({
|
|
712
|
+
type: "options"
|
|
713
|
+
}, (node) => ({
|
|
714
|
+
...node,
|
|
715
|
+
query: map(node.query, mapper)
|
|
716
|
+
})), Match.when({
|
|
717
|
+
type: "order"
|
|
718
|
+
}, (node) => ({
|
|
719
|
+
...node,
|
|
720
|
+
query: map(node.query, mapper)
|
|
721
|
+
})), Match.when({
|
|
722
|
+
type: "limit"
|
|
723
|
+
}, (node) => ({
|
|
724
|
+
...node,
|
|
725
|
+
query: map(node.query, mapper)
|
|
726
|
+
})), Match.when({
|
|
727
|
+
type: "from"
|
|
728
|
+
}, (node) => ({
|
|
729
|
+
...node,
|
|
730
|
+
query: map(node.query, mapper),
|
|
731
|
+
...node.from._tag === "query" ? {
|
|
732
|
+
from: {
|
|
733
|
+
_tag: "query",
|
|
734
|
+
query: map(node.from.query, mapper)
|
|
735
|
+
}
|
|
736
|
+
} : {}
|
|
737
|
+
})), Match.when({
|
|
738
|
+
type: "union"
|
|
739
|
+
}, (node) => ({
|
|
740
|
+
...node,
|
|
741
|
+
queries: node.queries.map((q) => map(q, mapper))
|
|
742
|
+
})), Match.when({
|
|
743
|
+
type: "set-difference"
|
|
744
|
+
}, (node) => ({
|
|
745
|
+
...node,
|
|
746
|
+
source: map(node.source, mapper),
|
|
747
|
+
exclude: map(node.exclude, mapper)
|
|
748
|
+
})), Match.when({
|
|
749
|
+
type: "select"
|
|
750
|
+
}, (node) => node), Match.exhaustive);
|
|
751
|
+
return mapper(mapped);
|
|
752
|
+
};
|
|
573
753
|
var fold = (query, reducer) => {
|
|
574
754
|
return Match.value(query).pipe(Match.withReturnType(), Match.when({
|
|
575
755
|
type: "filter"
|
|
@@ -583,6 +763,8 @@ var fold = (query, reducer) => {
|
|
|
583
763
|
type: "options"
|
|
584
764
|
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
585
765
|
type: "relation-traversal"
|
|
766
|
+
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
767
|
+
type: "hierarchy-traversal"
|
|
586
768
|
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
587
769
|
type: "union"
|
|
588
770
|
}, ({ queries }) => queries.flatMap((q) => fold(q, reducer))), Match.when({
|
|
@@ -590,12 +772,52 @@ var fold = (query, reducer) => {
|
|
|
590
772
|
}, ({ source, exclude }) => fold(source, reducer).concat(fold(exclude, reducer))), Match.when({
|
|
591
773
|
type: "order"
|
|
592
774
|
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
775
|
+
type: "limit"
|
|
776
|
+
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
777
|
+
type: "from"
|
|
778
|
+
}, (node) => {
|
|
779
|
+
const results = fold(node.query, reducer);
|
|
780
|
+
if (node.from._tag === "query") {
|
|
781
|
+
return results.concat(fold(node.from.query, reducer));
|
|
782
|
+
}
|
|
783
|
+
return results;
|
|
784
|
+
}), Match.when({
|
|
593
785
|
type: "select"
|
|
594
786
|
}, () => []), Match.exhaustive);
|
|
595
787
|
};
|
|
788
|
+
|
|
789
|
+
// src/space-doc-version.ts
|
|
790
|
+
var SpaceDocVersion = Object.freeze({
|
|
791
|
+
/**
|
|
792
|
+
* For the documents created before the versioning was introduced.
|
|
793
|
+
*/
|
|
794
|
+
LEGACY: 0,
|
|
795
|
+
/**
|
|
796
|
+
* Current version.
|
|
797
|
+
*/
|
|
798
|
+
CURRENT: 1
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
// src/space-id.ts
|
|
802
|
+
import { subtleCrypto } from "@dxos/crypto";
|
|
803
|
+
import { PublicKey, SpaceId } from "@dxos/keys";
|
|
804
|
+
import { ComplexMap } from "@dxos/util";
|
|
805
|
+
var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
|
|
806
|
+
var createIdFromSpaceKey = async (spaceKey) => {
|
|
807
|
+
const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
|
|
808
|
+
if (cachedValue !== void 0) {
|
|
809
|
+
return cachedValue;
|
|
810
|
+
}
|
|
811
|
+
const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
|
|
812
|
+
const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
|
|
813
|
+
const spaceId = SpaceId.encode(bytes);
|
|
814
|
+
SPACE_IDS_CACHE.set(spaceKey, spaceId);
|
|
815
|
+
return spaceId;
|
|
816
|
+
};
|
|
596
817
|
export {
|
|
597
818
|
DATA_NAMESPACE,
|
|
598
819
|
DatabaseDirectory,
|
|
820
|
+
EchoFeedCodec,
|
|
599
821
|
EncodedReference,
|
|
600
822
|
ForeignKey,
|
|
601
823
|
ObjectStructure,
|
|
@@ -607,6 +829,7 @@ export {
|
|
|
607
829
|
createIdFromSpaceKey,
|
|
608
830
|
decodeReference,
|
|
609
831
|
encodeReference,
|
|
832
|
+
isEdgePeerId,
|
|
610
833
|
isEncodedReference
|
|
611
834
|
};
|
|
612
835
|
//# sourceMappingURL=index.mjs.map
|