@dxos/echo-protocol 0.8.4-main.ead640a → 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.
- package/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/{browser → neutral}/index.mjs +306 -198
- 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 +40 -9
- 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 +150 -36
- package/dist/types/src/query/ast.d.ts.map +1 -1
- package/dist/types/src/reference.d.ts +11 -64
- 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 +55 -10
- 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 +201 -15
- package/src/reference.ts +12 -157
- 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
|
@@ -10,151 +10,25 @@ 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
|
-
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
|
-
var Reference = class _Reference {
|
|
28
|
-
static fromDXN(dxn) {
|
|
29
|
-
switch (dxn.kind) {
|
|
30
|
-
case DXN.kind.TYPE:
|
|
31
|
-
return new _Reference(dxn.parts[0], _Reference.TYPE_PROTOCOL, "dxos.org", dxn);
|
|
32
|
-
case DXN.kind.ECHO:
|
|
33
|
-
if (dxn.parts[0] === LOCAL_SPACE_TAG) {
|
|
34
|
-
return new _Reference(dxn.parts[1], void 0, void 0, dxn);
|
|
35
|
-
} else {
|
|
36
|
-
return new _Reference(dxn.parts[1], void 0, dxn.parts[0], dxn);
|
|
37
|
-
}
|
|
38
|
-
default:
|
|
39
|
-
return new _Reference(dxn.parts[0], void 0, dxn.parts[0], dxn);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
static fromValue(value2) {
|
|
43
|
-
return new _Reference(value2.objectId, value2.protocol, value2.host);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Reference an object in the local space.
|
|
47
|
-
*/
|
|
48
|
-
static localObjectReference(objectId) {
|
|
49
|
-
return new _Reference(objectId);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated
|
|
53
|
-
*/
|
|
54
|
-
// TODO(dmaretskyi): Remove.
|
|
55
|
-
static fromLegacyTypename(type) {
|
|
56
|
-
return new _Reference(type, _Reference.TYPE_PROTOCOL, "dxos.org");
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* @deprecated
|
|
60
|
-
*/
|
|
61
|
-
// TODO(dmaretskyi): Remove
|
|
62
|
-
static fromObjectIdAndSpaceKey(objectId, spaceKey) {
|
|
63
|
-
return new _Reference(objectId, void 0, spaceKey.toHex());
|
|
64
|
-
}
|
|
65
|
-
get dxn() {
|
|
66
|
-
return this._dxn;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @deprecated
|
|
70
|
-
*/
|
|
71
|
-
// TODO(dmaretskyi): Remove.
|
|
72
|
-
get objectId() {
|
|
73
|
-
return this._objectId;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* @deprecated
|
|
77
|
-
*/
|
|
78
|
-
// TODO(dmaretskyi): Remove.
|
|
79
|
-
get protocol() {
|
|
80
|
-
return this._protocol;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* @deprecated
|
|
84
|
-
*/
|
|
85
|
-
// TODO(dmaretskyi): Remove.
|
|
86
|
-
get host() {
|
|
87
|
-
return this._host;
|
|
88
|
-
}
|
|
89
|
-
encode() {
|
|
90
|
-
return {
|
|
91
|
-
objectId: this.objectId,
|
|
92
|
-
host: this.host,
|
|
93
|
-
protocol: this.protocol
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
// TODO(dmaretskyi): Remove in favor of `reference.dxn`.
|
|
97
|
-
toDXN() {
|
|
98
|
-
if (this._dxn) {
|
|
99
|
-
return this._dxn;
|
|
100
|
-
}
|
|
101
|
-
if (this.protocol === _Reference.TYPE_PROTOCOL) {
|
|
102
|
-
return new DXN(DXN.kind.TYPE, [
|
|
103
|
-
this.objectId
|
|
104
|
-
]);
|
|
105
|
-
} else {
|
|
106
|
-
if (this.host) {
|
|
107
|
-
return new DXN(DXN.kind.ECHO, [
|
|
108
|
-
this.host,
|
|
109
|
-
this.objectId
|
|
110
|
-
]);
|
|
111
|
-
} else {
|
|
112
|
-
return new DXN(DXN.kind.ECHO, [
|
|
113
|
-
LOCAL_SPACE_TAG,
|
|
114
|
-
this.objectId
|
|
115
|
-
]);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
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
|
-
};
|
|
131
|
-
_define_property(Reference, "TYPE_PROTOCOL", "protobuf");
|
|
132
13
|
var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
133
|
-
var encodeReference = (reference) => ({
|
|
134
|
-
"/": reference.toDXN().toString()
|
|
135
|
-
});
|
|
136
|
-
var decodeReference = (value2) => {
|
|
137
|
-
if (typeof value2 !== "object" || value2 === null || typeof value2["/"] !== "string") {
|
|
138
|
-
throw new Error("Invalid reference");
|
|
139
|
-
}
|
|
140
|
-
const dxnString = value2["/"];
|
|
141
|
-
if (dxnString.length % 2 === 0 && dxnString.slice(0, dxnString.length / 2) === dxnString.slice(dxnString.length / 2) && dxnString.includes("dxn:echo")) {
|
|
142
|
-
throw new Error("Automerge bug detected!");
|
|
143
|
-
}
|
|
144
|
-
return Reference.fromDXN(DXN.parse(dxnString));
|
|
145
|
-
};
|
|
146
14
|
var isEncodedReference = (value2) => typeof value2 === "object" && value2 !== null && Object.keys(value2).length === 1 && typeof value2["/"] === "string";
|
|
147
15
|
var EncodedReference = Object.freeze({
|
|
148
16
|
isEncodedReference,
|
|
149
|
-
|
|
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) => {
|
|
150
22
|
assertArgument(isEncodedReference(value2), "value", "invalid reference");
|
|
151
23
|
return value2["/"];
|
|
152
24
|
},
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return
|
|
25
|
+
/**
|
|
26
|
+
* Creates an encoded reference from an opaque URI.
|
|
27
|
+
*/
|
|
28
|
+
fromURI: (uri) => {
|
|
29
|
+
return {
|
|
30
|
+
"/": uri
|
|
31
|
+
};
|
|
158
32
|
}
|
|
159
33
|
});
|
|
160
34
|
|
|
@@ -170,15 +44,7 @@ var DatabaseDirectory = Object.freeze({
|
|
|
170
44
|
return null;
|
|
171
45
|
}
|
|
172
46
|
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
|
-
});
|
|
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'"] });
|
|
182
48
|
return rawKey;
|
|
183
49
|
},
|
|
184
50
|
getInlineObject: (doc, id) => {
|
|
@@ -207,15 +73,7 @@ var ObjectStructure = Object.freeze({
|
|
|
207
73
|
*/
|
|
208
74
|
getEntityKind: (object) => {
|
|
209
75
|
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
|
-
});
|
|
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'"] });
|
|
219
77
|
return kind;
|
|
220
78
|
},
|
|
221
79
|
isDeleted: (object) => {
|
|
@@ -227,6 +85,9 @@ var ObjectStructure = Object.freeze({
|
|
|
227
85
|
getRelationTarget: (object) => {
|
|
228
86
|
return object.system?.target;
|
|
229
87
|
},
|
|
88
|
+
getParent: (object) => {
|
|
89
|
+
return object.system?.parent;
|
|
90
|
+
},
|
|
230
91
|
/**
|
|
231
92
|
* @returns All references in the data section of the object.
|
|
232
93
|
*/
|
|
@@ -283,38 +144,86 @@ var ObjectStructure = Object.freeze({
|
|
|
283
144
|
},
|
|
284
145
|
data: data ?? {}
|
|
285
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
|
+
};
|
|
286
161
|
}
|
|
287
162
|
});
|
|
288
163
|
var PROPERTY_ID = "id";
|
|
289
164
|
var DATA_NAMESPACE = "data";
|
|
290
165
|
|
|
291
|
-
// src/
|
|
292
|
-
|
|
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();
|
|
293
181
|
/**
|
|
294
|
-
*
|
|
182
|
+
* Prepares a value for feed storage (strips queue position from metadata) and encodes to bytes.
|
|
295
183
|
*/
|
|
296
|
-
|
|
184
|
+
static encode(value2) {
|
|
185
|
+
const prepared = _EchoFeedCodec.#stripQueuePosition(value2);
|
|
186
|
+
return _EchoFeedCodec.#encoder.encode(JSON.stringify(prepared));
|
|
187
|
+
}
|
|
297
188
|
/**
|
|
298
|
-
*
|
|
189
|
+
* Decodes feed block bytes to a JSON value.
|
|
190
|
+
* If position is provided, injects queue position into the decoded object's metadata.
|
|
299
191
|
*/
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
+
});
|
|
312
226
|
}
|
|
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
227
|
};
|
|
319
228
|
|
|
320
229
|
// src/foreign-key.ts
|
|
@@ -342,6 +251,7 @@ var ast_exports = {};
|
|
|
342
251
|
__export(ast_exports, {
|
|
343
252
|
Filter: () => Filter,
|
|
344
253
|
FilterAnd: () => FilterAnd,
|
|
254
|
+
FilterChildOf: () => FilterChildOf,
|
|
345
255
|
FilterCompare: () => FilterCompare,
|
|
346
256
|
FilterContains: () => FilterContains,
|
|
347
257
|
FilterIn: () => FilterIn,
|
|
@@ -351,11 +261,16 @@ __export(ast_exports, {
|
|
|
351
261
|
FilterRange: () => FilterRange,
|
|
352
262
|
FilterTag: () => FilterTag,
|
|
353
263
|
FilterTextSearch: () => FilterTextSearch,
|
|
264
|
+
FilterTimestamp: () => FilterTimestamp,
|
|
354
265
|
Order: () => Order,
|
|
355
266
|
OrderDirection: () => OrderDirection,
|
|
356
267
|
Query: () => Query,
|
|
357
268
|
QueryFilterClause: () => QueryFilterClause,
|
|
269
|
+
QueryFromClause: () => QueryFromClause,
|
|
270
|
+
QueryFromClause_: () => QueryFromClause_,
|
|
271
|
+
QueryHierarchyTraversalClause: () => QueryHierarchyTraversalClause,
|
|
358
272
|
QueryIncomingReferencesClause: () => QueryIncomingReferencesClause,
|
|
273
|
+
QueryLimitClause: () => QueryLimitClause,
|
|
359
274
|
QueryOptions: () => QueryOptions,
|
|
360
275
|
QueryOptionsClause: () => QueryOptionsClause,
|
|
361
276
|
QueryOrderClause: () => QueryOrderClause,
|
|
@@ -365,15 +280,15 @@ __export(ast_exports, {
|
|
|
365
280
|
QuerySelectClause: () => QuerySelectClause,
|
|
366
281
|
QuerySetDifferenceClause: () => QuerySetDifferenceClause,
|
|
367
282
|
QueryUnionClause: () => QueryUnionClause,
|
|
283
|
+
Scope: () => Scope,
|
|
368
284
|
fold: () => fold,
|
|
285
|
+
map: () => map,
|
|
369
286
|
visit: () => visit
|
|
370
287
|
});
|
|
371
288
|
import * as Match from "effect/Match";
|
|
372
289
|
import * as Schema2 from "effect/Schema";
|
|
373
|
-
import {
|
|
374
|
-
var TypenameSpecifier = Schema2.Union(
|
|
375
|
-
description: "DXN or null. Null means any type will match"
|
|
376
|
-
});
|
|
290
|
+
import { EchoURI, ObjectId, URI } from "@dxos/keys";
|
|
291
|
+
var TypenameSpecifier = Schema2.Union(URI.Schema, Schema2.Null);
|
|
377
292
|
var FilterObject_ = Schema2.Struct({
|
|
378
293
|
type: Schema2.Literal("object"),
|
|
379
294
|
typename: TypenameSpecifier,
|
|
@@ -391,7 +306,16 @@ var FilterObject_ = Schema2.Struct({
|
|
|
391
306
|
/**
|
|
392
307
|
* Objects that have any of the given foreign keys.
|
|
393
308
|
*/
|
|
394
|
-
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)
|
|
395
319
|
});
|
|
396
320
|
var FilterObject = FilterObject_;
|
|
397
321
|
var FilterCompare_ = Schema2.Struct({
|
|
@@ -421,6 +345,13 @@ var FilterRange_ = Schema2.Struct({
|
|
|
421
345
|
to: Schema2.Any
|
|
422
346
|
});
|
|
423
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_;
|
|
424
355
|
var FilterTextSearch_ = Schema2.Struct({
|
|
425
356
|
type: Schema2.Literal("text-search"),
|
|
426
357
|
text: Schema2.String,
|
|
@@ -442,8 +373,16 @@ var FilterOr_ = Schema2.Struct({
|
|
|
442
373
|
filters: Schema2.Array(Schema2.suspend(() => Filter))
|
|
443
374
|
});
|
|
444
375
|
var FilterOr = FilterOr_;
|
|
445
|
-
var
|
|
446
|
-
|
|
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"
|
|
447
386
|
});
|
|
448
387
|
var QuerySelectClause_ = Schema2.Struct({
|
|
449
388
|
type: Schema2.Literal("select"),
|
|
@@ -465,7 +404,11 @@ var QueryReferenceTraversalClause = QueryReferenceTraversalClause_;
|
|
|
465
404
|
var QueryIncomingReferencesClause_ = Schema2.Struct({
|
|
466
405
|
type: Schema2.Literal("incoming-references"),
|
|
467
406
|
anchor: Schema2.suspend(() => Query),
|
|
468
|
-
|
|
407
|
+
/**
|
|
408
|
+
* Property path where the reference is located.
|
|
409
|
+
* If null, matches references from any property.
|
|
410
|
+
*/
|
|
411
|
+
property: Schema2.NullOr(Schema2.String),
|
|
469
412
|
typename: TypenameSpecifier
|
|
470
413
|
});
|
|
471
414
|
var QueryIncomingReferencesClause = QueryIncomingReferencesClause_;
|
|
@@ -487,6 +430,16 @@ var QueryRelationTraversalClause_ = Schema2.Struct({
|
|
|
487
430
|
direction: Schema2.Literal("source", "target", "both")
|
|
488
431
|
});
|
|
489
432
|
var QueryRelationTraversalClause = QueryRelationTraversalClause_;
|
|
433
|
+
var QueryHierarchyTraversalClause_ = Schema2.Struct({
|
|
434
|
+
type: Schema2.Literal("hierarchy-traversal"),
|
|
435
|
+
anchor: Schema2.suspend(() => Query),
|
|
436
|
+
/**
|
|
437
|
+
* to-parent: traverse from child to parent.
|
|
438
|
+
* to-children: traverse from parent to children.
|
|
439
|
+
*/
|
|
440
|
+
direction: Schema2.Literal("to-parent", "to-children")
|
|
441
|
+
});
|
|
442
|
+
var QueryHierarchyTraversalClause = QueryHierarchyTraversalClause_;
|
|
490
443
|
var QueryUnionClause_ = Schema2.Struct({
|
|
491
444
|
type: Schema2.Literal("union"),
|
|
492
445
|
queries: Schema2.Array(Schema2.suspend(() => Query))
|
|
@@ -506,6 +459,11 @@ var Order_ = Schema2.Union(Schema2.Struct({
|
|
|
506
459
|
kind: Schema2.Literal("property"),
|
|
507
460
|
property: Schema2.String,
|
|
508
461
|
direction: OrderDirection
|
|
462
|
+
}), Schema2.Struct({
|
|
463
|
+
// Order by relevance rank (for FTS/vector search results).
|
|
464
|
+
// Default direction is 'desc' (higher rank = better match first).
|
|
465
|
+
kind: Schema2.Literal("rank"),
|
|
466
|
+
direction: OrderDirection
|
|
509
467
|
}));
|
|
510
468
|
var Order = Order_;
|
|
511
469
|
var QueryOrderClause_ = Schema2.Struct({
|
|
@@ -520,27 +478,53 @@ var QueryOptionsClause_ = Schema2.Struct({
|
|
|
520
478
|
options: Schema2.suspend(() => QueryOptions)
|
|
521
479
|
});
|
|
522
480
|
var QueryOptionsClause = QueryOptionsClause_;
|
|
523
|
-
var
|
|
524
|
-
|
|
481
|
+
var QueryLimitClause_ = Schema2.Struct({
|
|
482
|
+
type: Schema2.Literal("limit"),
|
|
483
|
+
query: Schema2.suspend(() => Query),
|
|
484
|
+
limit: Schema2.Number
|
|
485
|
+
});
|
|
486
|
+
var QueryLimitClause = QueryLimitClause_;
|
|
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"
|
|
525
499
|
});
|
|
526
500
|
var Query = Query_;
|
|
527
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({
|
|
528
512
|
/**
|
|
529
513
|
* The nested select statemets will select from the given spaces.
|
|
530
514
|
*
|
|
531
|
-
* NOTE: Spaces and
|
|
515
|
+
* NOTE: Spaces and feeds are unioned together if both are specified.
|
|
532
516
|
*/
|
|
533
517
|
spaceIds: Schema2.optional(Schema2.Array(Schema2.String)),
|
|
534
518
|
/**
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
519
|
+
* If true, the nested select statements will select from all feeds in the spaces specified by `spaceIds`.
|
|
538
520
|
*/
|
|
539
|
-
|
|
521
|
+
allFeedsFromSpaces: Schema2.optional(Schema2.Boolean),
|
|
540
522
|
/**
|
|
541
|
-
*
|
|
523
|
+
* The nested select statemets will select from the given feeds (by EchoURI or legacy DXN).
|
|
524
|
+
*
|
|
525
|
+
* NOTE: Spaces and feeds are unioned together if both are specified.
|
|
542
526
|
*/
|
|
543
|
-
|
|
527
|
+
feeds: Schema2.optional(Schema2.Array(EchoURI.Schema))
|
|
544
528
|
});
|
|
545
529
|
var visit = (query, visitor) => {
|
|
546
530
|
visitor(query);
|
|
@@ -556,6 +540,8 @@ var visit = (query, visitor) => {
|
|
|
556
540
|
type: "options"
|
|
557
541
|
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
558
542
|
type: "relation-traversal"
|
|
543
|
+
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
544
|
+
type: "hierarchy-traversal"
|
|
559
545
|
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
560
546
|
type: "union"
|
|
561
547
|
}, ({ queries }) => queries.forEach((q) => visit(q, visitor))), Match.when({
|
|
@@ -566,10 +552,92 @@ var visit = (query, visitor) => {
|
|
|
566
552
|
}), Match.when({
|
|
567
553
|
type: "order"
|
|
568
554
|
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
555
|
+
type: "limit"
|
|
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({
|
|
569
564
|
type: "select"
|
|
570
565
|
}, () => {
|
|
571
566
|
}), Match.exhaustive);
|
|
572
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
|
+
};
|
|
573
641
|
var fold = (query, reducer) => {
|
|
574
642
|
return Match.value(query).pipe(Match.withReturnType(), Match.when({
|
|
575
643
|
type: "filter"
|
|
@@ -583,6 +651,8 @@ var fold = (query, reducer) => {
|
|
|
583
651
|
type: "options"
|
|
584
652
|
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
585
653
|
type: "relation-traversal"
|
|
654
|
+
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
655
|
+
type: "hierarchy-traversal"
|
|
586
656
|
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
587
657
|
type: "union"
|
|
588
658
|
}, ({ queries }) => queries.flatMap((q) => fold(q, reducer))), Match.when({
|
|
@@ -590,23 +660,61 @@ var fold = (query, reducer) => {
|
|
|
590
660
|
}, ({ source, exclude }) => fold(source, reducer).concat(fold(exclude, reducer))), Match.when({
|
|
591
661
|
type: "order"
|
|
592
662
|
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
663
|
+
type: "limit"
|
|
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({
|
|
593
673
|
type: "select"
|
|
594
674
|
}, () => []), Match.exhaustive);
|
|
595
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
|
+
};
|
|
596
705
|
export {
|
|
597
706
|
DATA_NAMESPACE,
|
|
598
707
|
DatabaseDirectory,
|
|
708
|
+
EchoFeedCodec,
|
|
599
709
|
EncodedReference,
|
|
600
710
|
ForeignKey,
|
|
601
711
|
ObjectStructure,
|
|
602
712
|
PROPERTY_ID,
|
|
603
713
|
ast_exports as QueryAST,
|
|
604
714
|
REFERENCE_TYPE_TAG,
|
|
605
|
-
Reference,
|
|
606
715
|
SpaceDocVersion,
|
|
607
716
|
createIdFromSpaceKey,
|
|
608
|
-
|
|
609
|
-
encodeReference,
|
|
717
|
+
isEdgePeerId,
|
|
610
718
|
isEncodedReference
|
|
611
719
|
};
|
|
612
720
|
//# sourceMappingURL=index.mjs.map
|