@dxos/echo-protocol 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8
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 +315 -197
- 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 +81 -34
- 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 +203 -41
- 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 +98 -37
- 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 +229 -21
- 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 -604
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
|
@@ -10,142 +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
|
-
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
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return
|
|
25
|
+
/**
|
|
26
|
+
* Creates an encoded reference from an opaque URI.
|
|
27
|
+
*/
|
|
28
|
+
fromURI: (uri) => {
|
|
29
|
+
return {
|
|
30
|
+
"/": uri
|
|
31
|
+
};
|
|
149
32
|
}
|
|
150
33
|
});
|
|
151
34
|
|
|
@@ -161,15 +44,7 @@ var DatabaseDirectory = Object.freeze({
|
|
|
161
44
|
return null;
|
|
162
45
|
}
|
|
163
46
|
const rawKey = String(rawSpaceKey);
|
|
164
|
-
invariant(!rawKey.startsWith("0x"), "Space key must not start with 0x", {
|
|
165
|
-
F: __dxlog_file,
|
|
166
|
-
L: 66,
|
|
167
|
-
S: void 0,
|
|
168
|
-
A: [
|
|
169
|
-
"!rawKey.startsWith('0x')",
|
|
170
|
-
"'Space key must not start with 0x'"
|
|
171
|
-
]
|
|
172
|
-
});
|
|
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'"] });
|
|
173
48
|
return rawKey;
|
|
174
49
|
},
|
|
175
50
|
getInlineObject: (doc, id) => {
|
|
@@ -186,7 +61,7 @@ var DatabaseDirectory = Object.freeze({
|
|
|
186
61
|
links: links ?? {}
|
|
187
62
|
})
|
|
188
63
|
});
|
|
189
|
-
var
|
|
64
|
+
var EntityStructure = Object.freeze({
|
|
190
65
|
/**
|
|
191
66
|
* @throws On invalid object structure.
|
|
192
67
|
*/
|
|
@@ -198,15 +73,7 @@ var ObjectStructure = Object.freeze({
|
|
|
198
73
|
*/
|
|
199
74
|
getEntityKind: (object) => {
|
|
200
75
|
const kind = object.system?.kind ?? "object";
|
|
201
|
-
invariant(kind === "object" || kind === "relation", "Invalid kind", {
|
|
202
|
-
F: __dxlog_file,
|
|
203
|
-
L: 124,
|
|
204
|
-
S: void 0,
|
|
205
|
-
A: [
|
|
206
|
-
"kind === 'object' || kind === 'relation'",
|
|
207
|
-
"'Invalid kind'"
|
|
208
|
-
]
|
|
209
|
-
});
|
|
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'"] });
|
|
210
77
|
return kind;
|
|
211
78
|
},
|
|
212
79
|
isDeleted: (object) => {
|
|
@@ -218,6 +85,9 @@ var ObjectStructure = Object.freeze({
|
|
|
218
85
|
getRelationTarget: (object) => {
|
|
219
86
|
return object.system?.target;
|
|
220
87
|
},
|
|
88
|
+
getParent: (object) => {
|
|
89
|
+
return object.system?.parent;
|
|
90
|
+
},
|
|
221
91
|
/**
|
|
222
92
|
* @returns All references in the data section of the object.
|
|
223
93
|
*/
|
|
@@ -274,38 +144,86 @@ var ObjectStructure = Object.freeze({
|
|
|
274
144
|
},
|
|
275
145
|
data: data ?? {}
|
|
276
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
|
+
};
|
|
277
161
|
}
|
|
278
162
|
});
|
|
279
163
|
var PROPERTY_ID = "id";
|
|
280
164
|
var DATA_NAMESPACE = "data";
|
|
281
165
|
|
|
282
|
-
// src/
|
|
283
|
-
|
|
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();
|
|
284
181
|
/**
|
|
285
|
-
*
|
|
182
|
+
* Prepares a value for feed storage (strips queue position from metadata) and encodes to bytes.
|
|
286
183
|
*/
|
|
287
|
-
|
|
184
|
+
static encode(value2) {
|
|
185
|
+
const prepared = _EchoFeedCodec.#stripQueuePosition(value2);
|
|
186
|
+
return _EchoFeedCodec.#encoder.encode(JSON.stringify(prepared));
|
|
187
|
+
}
|
|
288
188
|
/**
|
|
289
|
-
*
|
|
189
|
+
* Decodes feed block bytes to a JSON value.
|
|
190
|
+
* If position is provided, injects queue position into the decoded object's metadata.
|
|
290
191
|
*/
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
+
});
|
|
303
226
|
}
|
|
304
|
-
const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
|
|
305
|
-
const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
|
|
306
|
-
const spaceId = SpaceId.encode(bytes);
|
|
307
|
-
SPACE_IDS_CACHE.set(spaceKey, spaceId);
|
|
308
|
-
return spaceId;
|
|
309
227
|
};
|
|
310
228
|
|
|
311
229
|
// src/foreign-key.ts
|
|
@@ -331,8 +249,10 @@ var ForeignKey = ForeignKey_;
|
|
|
331
249
|
// src/query/ast.ts
|
|
332
250
|
var ast_exports = {};
|
|
333
251
|
__export(ast_exports, {
|
|
252
|
+
FeedScope: () => FeedScope,
|
|
334
253
|
Filter: () => Filter,
|
|
335
254
|
FilterAnd: () => FilterAnd,
|
|
255
|
+
FilterChildOf: () => FilterChildOf,
|
|
336
256
|
FilterCompare: () => FilterCompare,
|
|
337
257
|
FilterContains: () => FilterContains,
|
|
338
258
|
FilterIn: () => FilterIn,
|
|
@@ -342,11 +262,16 @@ __export(ast_exports, {
|
|
|
342
262
|
FilterRange: () => FilterRange,
|
|
343
263
|
FilterTag: () => FilterTag,
|
|
344
264
|
FilterTextSearch: () => FilterTextSearch,
|
|
265
|
+
FilterTimestamp: () => FilterTimestamp,
|
|
345
266
|
Order: () => Order,
|
|
346
267
|
OrderDirection: () => OrderDirection,
|
|
347
268
|
Query: () => Query,
|
|
348
269
|
QueryFilterClause: () => QueryFilterClause,
|
|
270
|
+
QueryFromClause: () => QueryFromClause,
|
|
271
|
+
QueryFromClause_: () => QueryFromClause_,
|
|
272
|
+
QueryHierarchyTraversalClause: () => QueryHierarchyTraversalClause,
|
|
349
273
|
QueryIncomingReferencesClause: () => QueryIncomingReferencesClause,
|
|
274
|
+
QueryLimitClause: () => QueryLimitClause,
|
|
350
275
|
QueryOptions: () => QueryOptions,
|
|
351
276
|
QueryOptionsClause: () => QueryOptionsClause,
|
|
352
277
|
QueryOrderClause: () => QueryOrderClause,
|
|
@@ -356,19 +281,21 @@ __export(ast_exports, {
|
|
|
356
281
|
QuerySelectClause: () => QuerySelectClause,
|
|
357
282
|
QuerySetDifferenceClause: () => QuerySetDifferenceClause,
|
|
358
283
|
QueryUnionClause: () => QueryUnionClause,
|
|
284
|
+
RegistryScope: () => RegistryScope,
|
|
285
|
+
Scope: () => Scope,
|
|
286
|
+
SpaceScope: () => SpaceScope,
|
|
359
287
|
fold: () => fold,
|
|
288
|
+
map: () => map,
|
|
360
289
|
visit: () => visit
|
|
361
290
|
});
|
|
362
291
|
import * as Match from "effect/Match";
|
|
363
292
|
import * as Schema2 from "effect/Schema";
|
|
364
|
-
import {
|
|
365
|
-
var TypenameSpecifier = Schema2.Union(
|
|
366
|
-
description: "DXN or null. Null means any type will match"
|
|
367
|
-
});
|
|
293
|
+
import { EID, EntityId, URI } from "@dxos/keys";
|
|
294
|
+
var TypenameSpecifier = Schema2.Union(URI.Schema, Schema2.Null);
|
|
368
295
|
var FilterObject_ = Schema2.Struct({
|
|
369
296
|
type: Schema2.Literal("object"),
|
|
370
297
|
typename: TypenameSpecifier,
|
|
371
|
-
id: Schema2.optional(Schema2.Array(
|
|
298
|
+
id: Schema2.optional(Schema2.Array(EntityId)),
|
|
372
299
|
/**
|
|
373
300
|
* Filter by property.
|
|
374
301
|
* Must not include object ID.
|
|
@@ -382,7 +309,16 @@ var FilterObject_ = Schema2.Struct({
|
|
|
382
309
|
/**
|
|
383
310
|
* Objects that have any of the given foreign keys.
|
|
384
311
|
*/
|
|
385
|
-
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)
|
|
386
322
|
});
|
|
387
323
|
var FilterObject = FilterObject_;
|
|
388
324
|
var FilterCompare_ = Schema2.Struct({
|
|
@@ -412,6 +348,13 @@ var FilterRange_ = Schema2.Struct({
|
|
|
412
348
|
to: Schema2.Any
|
|
413
349
|
});
|
|
414
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_;
|
|
415
358
|
var FilterTextSearch_ = Schema2.Struct({
|
|
416
359
|
type: Schema2.Literal("text-search"),
|
|
417
360
|
text: Schema2.String,
|
|
@@ -433,8 +376,16 @@ var FilterOr_ = Schema2.Struct({
|
|
|
433
376
|
filters: Schema2.Array(Schema2.suspend(() => Filter))
|
|
434
377
|
});
|
|
435
378
|
var FilterOr = FilterOr_;
|
|
436
|
-
var
|
|
437
|
-
|
|
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({
|
|
388
|
+
identifier: "org.dxos.schema.filter"
|
|
438
389
|
});
|
|
439
390
|
var QuerySelectClause_ = Schema2.Struct({
|
|
440
391
|
type: Schema2.Literal("select"),
|
|
@@ -456,7 +407,11 @@ var QueryReferenceTraversalClause = QueryReferenceTraversalClause_;
|
|
|
456
407
|
var QueryIncomingReferencesClause_ = Schema2.Struct({
|
|
457
408
|
type: Schema2.Literal("incoming-references"),
|
|
458
409
|
anchor: Schema2.suspend(() => Query),
|
|
459
|
-
|
|
410
|
+
/**
|
|
411
|
+
* Property path where the reference is located.
|
|
412
|
+
* If null, matches references from any property.
|
|
413
|
+
*/
|
|
414
|
+
property: Schema2.NullOr(Schema2.String),
|
|
460
415
|
typename: TypenameSpecifier
|
|
461
416
|
});
|
|
462
417
|
var QueryIncomingReferencesClause = QueryIncomingReferencesClause_;
|
|
@@ -478,6 +433,16 @@ var QueryRelationTraversalClause_ = Schema2.Struct({
|
|
|
478
433
|
direction: Schema2.Literal("source", "target", "both")
|
|
479
434
|
});
|
|
480
435
|
var QueryRelationTraversalClause = QueryRelationTraversalClause_;
|
|
436
|
+
var QueryHierarchyTraversalClause_ = Schema2.Struct({
|
|
437
|
+
type: Schema2.Literal("hierarchy-traversal"),
|
|
438
|
+
anchor: Schema2.suspend(() => Query),
|
|
439
|
+
/**
|
|
440
|
+
* to-parent: traverse from child to parent.
|
|
441
|
+
* to-children: traverse from parent to children.
|
|
442
|
+
*/
|
|
443
|
+
direction: Schema2.Literal("to-parent", "to-children")
|
|
444
|
+
});
|
|
445
|
+
var QueryHierarchyTraversalClause = QueryHierarchyTraversalClause_;
|
|
481
446
|
var QueryUnionClause_ = Schema2.Struct({
|
|
482
447
|
type: Schema2.Literal("union"),
|
|
483
448
|
queries: Schema2.Array(Schema2.suspend(() => Query))
|
|
@@ -497,6 +462,16 @@ var Order_ = Schema2.Union(Schema2.Struct({
|
|
|
497
462
|
kind: Schema2.Literal("property"),
|
|
498
463
|
property: Schema2.String,
|
|
499
464
|
direction: OrderDirection
|
|
465
|
+
}), Schema2.Struct({
|
|
466
|
+
// Order by relevance rank (for FTS/vector search results).
|
|
467
|
+
// Default direction is 'desc' (higher rank = better match first).
|
|
468
|
+
kind: Schema2.Literal("rank"),
|
|
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
|
|
500
475
|
}));
|
|
501
476
|
var Order = Order_;
|
|
502
477
|
var QueryOrderClause_ = Schema2.Struct({
|
|
@@ -511,28 +486,47 @@ var QueryOptionsClause_ = Schema2.Struct({
|
|
|
511
486
|
options: Schema2.suspend(() => QueryOptions)
|
|
512
487
|
});
|
|
513
488
|
var QueryOptionsClause = QueryOptionsClause_;
|
|
514
|
-
var
|
|
515
|
-
|
|
489
|
+
var QueryLimitClause_ = Schema2.Struct({
|
|
490
|
+
type: Schema2.Literal("limit"),
|
|
491
|
+
query: Schema2.suspend(() => Query),
|
|
492
|
+
limit: Schema2.Number
|
|
493
|
+
});
|
|
494
|
+
var QueryLimitClause = QueryLimitClause_;
|
|
495
|
+
var QueryFromClause_ = Schema2.Struct({
|
|
496
|
+
type: Schema2.Literal("from"),
|
|
497
|
+
query: Schema2.suspend(() => Query),
|
|
498
|
+
from: Schema2.Union(Schema2.TaggedStruct("scope", {
|
|
499
|
+
scopes: Schema2.Array(Schema2.suspend(() => Scope))
|
|
500
|
+
}), Schema2.TaggedStruct("query", {
|
|
501
|
+
query: Schema2.suspend(() => Query)
|
|
502
|
+
}))
|
|
503
|
+
});
|
|
504
|
+
var QueryFromClause = QueryFromClause_;
|
|
505
|
+
var Query_ = Schema2.Union(QuerySelectClause, QueryFilterClause, QueryReferenceTraversalClause, QueryIncomingReferencesClause, QueryRelationClause, QueryRelationTraversalClause, QueryHierarchyTraversalClause, QueryUnionClause, QuerySetDifferenceClause, QueryOrderClause, QueryOptionsClause, QueryLimitClause, QueryFromClause).annotations({
|
|
506
|
+
identifier: "org.dxos.schema.query"
|
|
516
507
|
});
|
|
517
508
|
var Query = Query_;
|
|
518
509
|
var QueryOptions = Schema2.Struct({
|
|
519
510
|
/**
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
511
|
+
* Nested select statements will use this option to filter deleted objects.
|
|
523
512
|
*/
|
|
524
|
-
|
|
513
|
+
deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only")),
|
|
525
514
|
/**
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
515
|
+
* Diagnostics-only label for logs / tooling (not used by execution semantics).
|
|
529
516
|
*/
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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
|
|
535
525
|
});
|
|
526
|
+
var RegistryScope = Schema2.TaggedStruct("registry", {
|
|
527
|
+
location: Schema2.Literal("local", "remote")
|
|
528
|
+
});
|
|
529
|
+
var Scope = Schema2.Union(SpaceScope, FeedScope, RegistryScope);
|
|
536
530
|
var visit = (query, visitor) => {
|
|
537
531
|
visitor(query);
|
|
538
532
|
Match.value(query).pipe(Match.when({
|
|
@@ -547,6 +541,8 @@ var visit = (query, visitor) => {
|
|
|
547
541
|
type: "options"
|
|
548
542
|
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
549
543
|
type: "relation-traversal"
|
|
544
|
+
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
545
|
+
type: "hierarchy-traversal"
|
|
550
546
|
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
551
547
|
type: "union"
|
|
552
548
|
}, ({ queries }) => queries.forEach((q) => visit(q, visitor))), Match.when({
|
|
@@ -557,10 +553,92 @@ var visit = (query, visitor) => {
|
|
|
557
553
|
}), Match.when({
|
|
558
554
|
type: "order"
|
|
559
555
|
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
556
|
+
type: "limit"
|
|
557
|
+
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
558
|
+
type: "from"
|
|
559
|
+
}, (node) => {
|
|
560
|
+
visit(node.query, visitor);
|
|
561
|
+
if (node.from._tag === "query") {
|
|
562
|
+
visit(node.from.query, visitor);
|
|
563
|
+
}
|
|
564
|
+
}), Match.when({
|
|
560
565
|
type: "select"
|
|
561
566
|
}, () => {
|
|
562
567
|
}), Match.exhaustive);
|
|
563
568
|
};
|
|
569
|
+
var map = (query, mapper) => {
|
|
570
|
+
const mapped = Match.value(query).pipe(Match.when({
|
|
571
|
+
type: "filter"
|
|
572
|
+
}, (node) => ({
|
|
573
|
+
...node,
|
|
574
|
+
selection: map(node.selection, mapper)
|
|
575
|
+
})), Match.when({
|
|
576
|
+
type: "reference-traversal"
|
|
577
|
+
}, (node) => ({
|
|
578
|
+
...node,
|
|
579
|
+
anchor: map(node.anchor, mapper)
|
|
580
|
+
})), Match.when({
|
|
581
|
+
type: "incoming-references"
|
|
582
|
+
}, (node) => ({
|
|
583
|
+
...node,
|
|
584
|
+
anchor: map(node.anchor, mapper)
|
|
585
|
+
})), Match.when({
|
|
586
|
+
type: "relation"
|
|
587
|
+
}, (node) => ({
|
|
588
|
+
...node,
|
|
589
|
+
anchor: map(node.anchor, mapper)
|
|
590
|
+
})), Match.when({
|
|
591
|
+
type: "relation-traversal"
|
|
592
|
+
}, (node) => ({
|
|
593
|
+
...node,
|
|
594
|
+
anchor: map(node.anchor, mapper)
|
|
595
|
+
})), Match.when({
|
|
596
|
+
type: "hierarchy-traversal"
|
|
597
|
+
}, (node) => ({
|
|
598
|
+
...node,
|
|
599
|
+
anchor: map(node.anchor, mapper)
|
|
600
|
+
})), Match.when({
|
|
601
|
+
type: "options"
|
|
602
|
+
}, (node) => ({
|
|
603
|
+
...node,
|
|
604
|
+
query: map(node.query, mapper)
|
|
605
|
+
})), Match.when({
|
|
606
|
+
type: "order"
|
|
607
|
+
}, (node) => ({
|
|
608
|
+
...node,
|
|
609
|
+
query: map(node.query, mapper)
|
|
610
|
+
})), Match.when({
|
|
611
|
+
type: "limit"
|
|
612
|
+
}, (node) => ({
|
|
613
|
+
...node,
|
|
614
|
+
query: map(node.query, mapper)
|
|
615
|
+
})), Match.when({
|
|
616
|
+
type: "from"
|
|
617
|
+
}, (node) => ({
|
|
618
|
+
...node,
|
|
619
|
+
query: map(node.query, mapper),
|
|
620
|
+
...node.from._tag === "query" ? {
|
|
621
|
+
from: {
|
|
622
|
+
_tag: "query",
|
|
623
|
+
query: map(node.from.query, mapper)
|
|
624
|
+
}
|
|
625
|
+
} : {}
|
|
626
|
+
})), Match.when({
|
|
627
|
+
type: "union"
|
|
628
|
+
}, (node) => ({
|
|
629
|
+
...node,
|
|
630
|
+
queries: node.queries.map((q) => map(q, mapper))
|
|
631
|
+
})), Match.when({
|
|
632
|
+
type: "set-difference"
|
|
633
|
+
}, (node) => ({
|
|
634
|
+
...node,
|
|
635
|
+
source: map(node.source, mapper),
|
|
636
|
+
exclude: map(node.exclude, mapper)
|
|
637
|
+
})), Match.when({
|
|
638
|
+
type: "select"
|
|
639
|
+
}, (node) => node), Match.exhaustive);
|
|
640
|
+
return mapper(mapped);
|
|
641
|
+
};
|
|
564
642
|
var fold = (query, reducer) => {
|
|
565
643
|
return Match.value(query).pipe(Match.withReturnType(), Match.when({
|
|
566
644
|
type: "filter"
|
|
@@ -574,6 +652,8 @@ var fold = (query, reducer) => {
|
|
|
574
652
|
type: "options"
|
|
575
653
|
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
576
654
|
type: "relation-traversal"
|
|
655
|
+
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
656
|
+
type: "hierarchy-traversal"
|
|
577
657
|
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
578
658
|
type: "union"
|
|
579
659
|
}, ({ queries }) => queries.flatMap((q) => fold(q, reducer))), Match.when({
|
|
@@ -581,23 +661,61 @@ var fold = (query, reducer) => {
|
|
|
581
661
|
}, ({ source, exclude }) => fold(source, reducer).concat(fold(exclude, reducer))), Match.when({
|
|
582
662
|
type: "order"
|
|
583
663
|
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
664
|
+
type: "limit"
|
|
665
|
+
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
666
|
+
type: "from"
|
|
667
|
+
}, (node) => {
|
|
668
|
+
const results = fold(node.query, reducer);
|
|
669
|
+
if (node.from._tag === "query") {
|
|
670
|
+
return results.concat(fold(node.from.query, reducer));
|
|
671
|
+
}
|
|
672
|
+
return results;
|
|
673
|
+
}), Match.when({
|
|
584
674
|
type: "select"
|
|
585
675
|
}, () => []), Match.exhaustive);
|
|
586
676
|
};
|
|
677
|
+
|
|
678
|
+
// src/space-doc-version.ts
|
|
679
|
+
var SpaceDocVersion = Object.freeze({
|
|
680
|
+
/**
|
|
681
|
+
* For the documents created before the versioning was introduced.
|
|
682
|
+
*/
|
|
683
|
+
LEGACY: 0,
|
|
684
|
+
/**
|
|
685
|
+
* Current version.
|
|
686
|
+
*/
|
|
687
|
+
CURRENT: 1
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
// src/space-id.ts
|
|
691
|
+
import { subtleCrypto } from "@dxos/crypto";
|
|
692
|
+
import { PublicKey, SpaceId } from "@dxos/keys";
|
|
693
|
+
import { ComplexMap } from "@dxos/util";
|
|
694
|
+
var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
|
|
695
|
+
var createIdFromSpaceKey = async (spaceKey) => {
|
|
696
|
+
const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
|
|
697
|
+
if (cachedValue !== void 0) {
|
|
698
|
+
return cachedValue;
|
|
699
|
+
}
|
|
700
|
+
const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
|
|
701
|
+
const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
|
|
702
|
+
const spaceId = SpaceId.encode(bytes);
|
|
703
|
+
SPACE_IDS_CACHE.set(spaceKey, spaceId);
|
|
704
|
+
return spaceId;
|
|
705
|
+
};
|
|
587
706
|
export {
|
|
588
707
|
DATA_NAMESPACE,
|
|
589
708
|
DatabaseDirectory,
|
|
709
|
+
EchoFeedCodec,
|
|
590
710
|
EncodedReference,
|
|
711
|
+
EntityStructure,
|
|
591
712
|
ForeignKey,
|
|
592
|
-
ObjectStructure,
|
|
593
713
|
PROPERTY_ID,
|
|
594
714
|
ast_exports as QueryAST,
|
|
595
715
|
REFERENCE_TYPE_TAG,
|
|
596
|
-
Reference,
|
|
597
716
|
SpaceDocVersion,
|
|
598
717
|
createIdFromSpaceKey,
|
|
599
|
-
|
|
600
|
-
encodeReference,
|
|
718
|
+
isEdgePeerId,
|
|
601
719
|
isEncodedReference
|
|
602
720
|
};
|
|
603
721
|
//# sourceMappingURL=index.mjs.map
|