@dxos/echo-protocol 0.8.4-main.dedc0f3 → 0.8.4-main.e00bdcdb52
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/dist/lib/{browser → neutral}/index.mjs +368 -145
- 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 +16 -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/foreign-key.d.ts +1 -1
- package/dist/types/src/foreign-key.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +4 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/query/ast.d.ts +184 -32
- 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 +13 -14
- package/src/document-structure.ts +23 -1
- package/src/echo-feed-codec.ts +67 -0
- package/src/foreign-key.ts +4 -3
- package/src/index.ts +4 -3
- package/src/query/ast.ts +271 -61
- 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 -594
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
|
@@ -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, value) {
|
|
15
|
-
if (key in obj) {
|
|
16
|
-
Object.defineProperty(obj, key, {
|
|
17
|
-
value,
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
obj[key] = value;
|
|
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:
|
|
@@ -39,8 +35,8 @@ var Reference = class _Reference {
|
|
|
39
35
|
return new _Reference(dxn.parts[0], void 0, dxn.parts[0], dxn);
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
|
-
static fromValue(
|
|
43
|
-
return new _Reference(
|
|
38
|
+
static fromValue(value2) {
|
|
39
|
+
return new _Reference(value2.objectId, value2.protocol, value2.host);
|
|
44
40
|
}
|
|
45
41
|
/**
|
|
46
42
|
* Reference an object in the local space.
|
|
@@ -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,45 +119,40 @@ 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()
|
|
135
126
|
});
|
|
136
|
-
var decodeReference = (
|
|
137
|
-
if (typeof
|
|
127
|
+
var decodeReference = (value2) => {
|
|
128
|
+
if (typeof value2 !== "object" || value2 === null || typeof value2["/"] !== "string") {
|
|
138
129
|
throw new Error("Invalid reference");
|
|
139
130
|
}
|
|
140
|
-
const dxnString =
|
|
131
|
+
const dxnString = value2["/"];
|
|
141
132
|
if (dxnString.length % 2 === 0 && dxnString.slice(0, dxnString.length / 2) === dxnString.slice(dxnString.length / 2) && dxnString.includes("dxn:echo")) {
|
|
142
133
|
throw new Error("Automerge bug detected!");
|
|
143
134
|
}
|
|
144
135
|
return Reference.fromDXN(DXN.parse(dxnString));
|
|
145
136
|
};
|
|
146
|
-
var isEncodedReference = (
|
|
137
|
+
var isEncodedReference = (value2) => typeof value2 === "object" && value2 !== null && Object.keys(value2).length === 1 && typeof value2["/"] === "string";
|
|
147
138
|
var EncodedReference = Object.freeze({
|
|
148
139
|
isEncodedReference,
|
|
149
|
-
getReferenceString: (
|
|
150
|
-
assertArgument(isEncodedReference(
|
|
151
|
-
return
|
|
140
|
+
getReferenceString: (value2) => {
|
|
141
|
+
assertArgument(isEncodedReference(value2), "value", "invalid reference");
|
|
142
|
+
return value2["/"];
|
|
152
143
|
},
|
|
153
|
-
toDXN: (
|
|
154
|
-
return DXN.parse(EncodedReference.getReferenceString(
|
|
144
|
+
toDXN: (value2) => {
|
|
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,29 +209,35 @@ 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
|
*/
|
|
233
218
|
getAllOutgoingReferences: (object) => {
|
|
234
219
|
const references = [];
|
|
235
|
-
const visit2 = (path,
|
|
236
|
-
if (isEncodedReference(
|
|
220
|
+
const visit2 = (path, value2) => {
|
|
221
|
+
if (isEncodedReference(value2)) {
|
|
237
222
|
references.push({
|
|
238
223
|
path,
|
|
239
|
-
reference:
|
|
224
|
+
reference: value2
|
|
240
225
|
});
|
|
241
226
|
} else {
|
|
242
|
-
visitValues(
|
|
227
|
+
visitValues(value2, (value3, key) => visit2([
|
|
243
228
|
...path,
|
|
244
229
|
String(key)
|
|
245
|
-
],
|
|
230
|
+
], value3));
|
|
246
231
|
}
|
|
247
232
|
};
|
|
248
|
-
visitValues(object.data, (
|
|
233
|
+
visitValues(object.data, (value2, key) => visit2([
|
|
249
234
|
String(key)
|
|
250
|
-
],
|
|
235
|
+
], value2));
|
|
251
236
|
return references;
|
|
252
237
|
},
|
|
238
|
+
getTags: (object) => {
|
|
239
|
+
return object.meta.tags ?? [];
|
|
240
|
+
},
|
|
253
241
|
makeObject: ({ type, data, keys }) => {
|
|
254
242
|
return {
|
|
255
243
|
system: {
|
|
@@ -285,37 +273,63 @@ var ObjectStructure = Object.freeze({
|
|
|
285
273
|
var PROPERTY_ID = "id";
|
|
286
274
|
var DATA_NAMESPACE = "data";
|
|
287
275
|
|
|
288
|
-
// src/
|
|
289
|
-
|
|
276
|
+
// src/echo-feed-codec.ts
|
|
277
|
+
import { FeedProtocol } from "@dxos/protocols";
|
|
278
|
+
var ATTR_META = "@meta";
|
|
279
|
+
var EchoFeedCodec = class _EchoFeedCodec {
|
|
280
|
+
static #encoder = new TextEncoder();
|
|
281
|
+
static #decoder = new TextDecoder();
|
|
290
282
|
/**
|
|
291
|
-
*
|
|
283
|
+
* Prepares a value for feed storage (strips queue position from metadata) and encodes to bytes.
|
|
292
284
|
*/
|
|
293
|
-
|
|
285
|
+
static encode(value2) {
|
|
286
|
+
const prepared = _EchoFeedCodec.#stripQueuePosition(value2);
|
|
287
|
+
return _EchoFeedCodec.#encoder.encode(JSON.stringify(prepared));
|
|
288
|
+
}
|
|
294
289
|
/**
|
|
295
|
-
*
|
|
290
|
+
* Decodes feed block bytes to a JSON value.
|
|
291
|
+
* If position is provided, injects queue position into the decoded object's metadata.
|
|
296
292
|
*/
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
293
|
+
static decode(data, position) {
|
|
294
|
+
const decoded = JSON.parse(_EchoFeedCodec.#decoder.decode(data));
|
|
295
|
+
if (position !== void 0 && typeof decoded === "object" && decoded !== null) {
|
|
296
|
+
_EchoFeedCodec.#setQueuePosition(decoded, position);
|
|
297
|
+
}
|
|
298
|
+
return decoded;
|
|
299
|
+
}
|
|
300
|
+
static #stripQueuePosition(value2) {
|
|
301
|
+
if (typeof value2 !== "object" || value2 === null) {
|
|
302
|
+
return value2;
|
|
303
|
+
}
|
|
304
|
+
const obj = structuredClone(value2);
|
|
305
|
+
const meta = obj[ATTR_META];
|
|
306
|
+
if (meta?.keys?.some((key) => key.source === FeedProtocol.KEY_QUEUE_POSITION)) {
|
|
307
|
+
meta.keys = meta.keys.filter((key) => key.source !== FeedProtocol.KEY_QUEUE_POSITION);
|
|
308
|
+
}
|
|
309
|
+
return obj;
|
|
310
|
+
}
|
|
311
|
+
static #setQueuePosition(obj, position) {
|
|
312
|
+
obj[ATTR_META] ??= {
|
|
313
|
+
keys: []
|
|
314
|
+
};
|
|
315
|
+
obj[ATTR_META].keys ??= [];
|
|
316
|
+
const keys = obj[ATTR_META].keys;
|
|
317
|
+
for (let i = 0; i < keys.length; i++) {
|
|
318
|
+
if (keys[i].source === FeedProtocol.KEY_QUEUE_POSITION) {
|
|
319
|
+
keys.splice(i, 1);
|
|
320
|
+
i--;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
keys.push({
|
|
324
|
+
source: FeedProtocol.KEY_QUEUE_POSITION,
|
|
325
|
+
id: position.toString()
|
|
326
|
+
});
|
|
309
327
|
}
|
|
310
|
-
const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
|
|
311
|
-
const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
|
|
312
|
-
const spaceId = SpaceId.encode(bytes);
|
|
313
|
-
SPACE_IDS_CACHE.set(spaceKey, spaceId);
|
|
314
|
-
return spaceId;
|
|
315
328
|
};
|
|
316
329
|
|
|
317
330
|
// src/foreign-key.ts
|
|
318
|
-
import
|
|
331
|
+
import * as Schema from "effect/Schema";
|
|
332
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
319
333
|
var ForeignKey_ = Schema.Struct({
|
|
320
334
|
/**
|
|
321
335
|
* Name of the foreign database/system.
|
|
@@ -326,9 +340,9 @@ var ForeignKey_ = Schema.Struct({
|
|
|
326
340
|
* Id within the foreign database.
|
|
327
341
|
*/
|
|
328
342
|
// TODO(wittjosiah): This annotation is currently used to ensure id field shows up in forms.
|
|
329
|
-
// TODO(dmaretskyi): `false` is not a valid value for the annotation.
|
|
343
|
+
// TODO(dmaretskyi): `false` is not a valid value for the annotation. Use a different annotation.
|
|
330
344
|
id: Schema.String.annotations({
|
|
331
|
-
[SchemaAST.IdentifierAnnotationId]: false
|
|
345
|
+
[SchemaAST.IdentifierAnnotationId]: "false"
|
|
332
346
|
})
|
|
333
347
|
});
|
|
334
348
|
var ForeignKey = ForeignKey_;
|
|
@@ -338,18 +352,26 @@ var ast_exports = {};
|
|
|
338
352
|
__export(ast_exports, {
|
|
339
353
|
Filter: () => Filter,
|
|
340
354
|
FilterAnd: () => FilterAnd,
|
|
355
|
+
FilterChildOf: () => FilterChildOf,
|
|
341
356
|
FilterCompare: () => FilterCompare,
|
|
357
|
+
FilterContains: () => FilterContains,
|
|
342
358
|
FilterIn: () => FilterIn,
|
|
343
359
|
FilterNot: () => FilterNot,
|
|
344
360
|
FilterObject: () => FilterObject,
|
|
345
361
|
FilterOr: () => FilterOr,
|
|
346
362
|
FilterRange: () => FilterRange,
|
|
363
|
+
FilterTag: () => FilterTag,
|
|
347
364
|
FilterTextSearch: () => FilterTextSearch,
|
|
365
|
+
FilterTimestamp: () => FilterTimestamp,
|
|
348
366
|
Order: () => Order,
|
|
349
367
|
OrderDirection: () => OrderDirection,
|
|
350
368
|
Query: () => Query,
|
|
351
369
|
QueryFilterClause: () => QueryFilterClause,
|
|
370
|
+
QueryFromClause: () => QueryFromClause,
|
|
371
|
+
QueryFromClause_: () => QueryFromClause_,
|
|
372
|
+
QueryHierarchyTraversalClause: () => QueryHierarchyTraversalClause,
|
|
352
373
|
QueryIncomingReferencesClause: () => QueryIncomingReferencesClause,
|
|
374
|
+
QueryLimitClause: () => QueryLimitClause,
|
|
353
375
|
QueryOptions: () => QueryOptions,
|
|
354
376
|
QueryOptionsClause: () => QueryOptionsClause,
|
|
355
377
|
QueryOrderClause: () => QueryOrderClause,
|
|
@@ -359,13 +381,16 @@ __export(ast_exports, {
|
|
|
359
381
|
QuerySelectClause: () => QuerySelectClause,
|
|
360
382
|
QuerySetDifferenceClause: () => QuerySetDifferenceClause,
|
|
361
383
|
QueryUnionClause: () => QueryUnionClause,
|
|
384
|
+
Scope: () => Scope,
|
|
362
385
|
fold: () => fold,
|
|
386
|
+
map: () => map,
|
|
363
387
|
visit: () => visit
|
|
364
388
|
});
|
|
365
|
-
import
|
|
389
|
+
import * as Match from "effect/Match";
|
|
390
|
+
import * as Schema2 from "effect/Schema";
|
|
366
391
|
import { DXN as DXN2, ObjectId } from "@dxos/keys";
|
|
367
392
|
var TypenameSpecifier = Schema2.Union(DXN2.Schema, Schema2.Null).annotations({
|
|
368
|
-
description: "DXN or null
|
|
393
|
+
description: "DXN or null; null matches any type"
|
|
369
394
|
});
|
|
370
395
|
var FilterObject_ = Schema2.Struct({
|
|
371
396
|
type: Schema2.Literal("object"),
|
|
@@ -398,12 +423,29 @@ var FilterIn_ = Schema2.Struct({
|
|
|
398
423
|
values: Schema2.Array(Schema2.Any)
|
|
399
424
|
});
|
|
400
425
|
var FilterIn = FilterIn_;
|
|
426
|
+
var FilterContains_ = Schema2.Struct({
|
|
427
|
+
type: Schema2.Literal("contains"),
|
|
428
|
+
value: Schema2.Any
|
|
429
|
+
});
|
|
430
|
+
var FilterContains = FilterContains_;
|
|
431
|
+
var FilterTag_ = Schema2.Struct({
|
|
432
|
+
type: Schema2.Literal("tag"),
|
|
433
|
+
tag: Schema2.String
|
|
434
|
+
});
|
|
435
|
+
var FilterTag = FilterTag_;
|
|
401
436
|
var FilterRange_ = Schema2.Struct({
|
|
402
437
|
type: Schema2.Literal("range"),
|
|
403
438
|
from: Schema2.Any,
|
|
404
439
|
to: Schema2.Any
|
|
405
440
|
});
|
|
406
441
|
var FilterRange = FilterRange_;
|
|
442
|
+
var FilterTimestamp_ = Schema2.Struct({
|
|
443
|
+
type: Schema2.Literal("timestamp"),
|
|
444
|
+
field: Schema2.Literal("createdAt", "updatedAt"),
|
|
445
|
+
operator: Schema2.Literal("gt", "gte", "lt", "lte"),
|
|
446
|
+
value: Schema2.Number
|
|
447
|
+
});
|
|
448
|
+
var FilterTimestamp = FilterTimestamp_;
|
|
407
449
|
var FilterTextSearch_ = Schema2.Struct({
|
|
408
450
|
type: Schema2.Literal("text-search"),
|
|
409
451
|
text: Schema2.String,
|
|
@@ -425,7 +467,17 @@ var FilterOr_ = Schema2.Struct({
|
|
|
425
467
|
filters: Schema2.Array(Schema2.suspend(() => Filter))
|
|
426
468
|
});
|
|
427
469
|
var FilterOr = FilterOr_;
|
|
428
|
-
var
|
|
470
|
+
var FilterChildOf_ = Schema2.Struct({
|
|
471
|
+
type: Schema2.Literal("child-of"),
|
|
472
|
+
/** Parent DXNs to match children of. */
|
|
473
|
+
parents: Schema2.Array(DXN2.Schema),
|
|
474
|
+
/** Whether to match transitively (grandchildren, etc.). Defaults to true. */
|
|
475
|
+
transitive: Schema2.Boolean
|
|
476
|
+
});
|
|
477
|
+
var FilterChildOf = FilterChildOf_;
|
|
478
|
+
var Filter = Schema2.Union(FilterObject, FilterCompare, FilterIn, FilterContains, FilterTag, FilterRange, FilterTimestamp, FilterTextSearch, FilterChildOf, FilterNot, FilterAnd, FilterOr).annotations({
|
|
479
|
+
identifier: "org.dxos.schema.filter"
|
|
480
|
+
});
|
|
429
481
|
var QuerySelectClause_ = Schema2.Struct({
|
|
430
482
|
type: Schema2.Literal("select"),
|
|
431
483
|
filter: Schema2.suspend(() => Filter)
|
|
@@ -446,7 +498,11 @@ var QueryReferenceTraversalClause = QueryReferenceTraversalClause_;
|
|
|
446
498
|
var QueryIncomingReferencesClause_ = Schema2.Struct({
|
|
447
499
|
type: Schema2.Literal("incoming-references"),
|
|
448
500
|
anchor: Schema2.suspend(() => Query),
|
|
449
|
-
|
|
501
|
+
/**
|
|
502
|
+
* Property path where the reference is located.
|
|
503
|
+
* If null, matches references from any property.
|
|
504
|
+
*/
|
|
505
|
+
property: Schema2.NullOr(Schema2.String),
|
|
450
506
|
typename: TypenameSpecifier
|
|
451
507
|
});
|
|
452
508
|
var QueryIncomingReferencesClause = QueryIncomingReferencesClause_;
|
|
@@ -468,6 +524,16 @@ var QueryRelationTraversalClause_ = Schema2.Struct({
|
|
|
468
524
|
direction: Schema2.Literal("source", "target", "both")
|
|
469
525
|
});
|
|
470
526
|
var QueryRelationTraversalClause = QueryRelationTraversalClause_;
|
|
527
|
+
var QueryHierarchyTraversalClause_ = Schema2.Struct({
|
|
528
|
+
type: Schema2.Literal("hierarchy-traversal"),
|
|
529
|
+
anchor: Schema2.suspend(() => Query),
|
|
530
|
+
/**
|
|
531
|
+
* to-parent: traverse from child to parent.
|
|
532
|
+
* to-children: traverse from parent to children.
|
|
533
|
+
*/
|
|
534
|
+
direction: Schema2.Literal("to-parent", "to-children")
|
|
535
|
+
});
|
|
536
|
+
var QueryHierarchyTraversalClause = QueryHierarchyTraversalClause_;
|
|
471
537
|
var QueryUnionClause_ = Schema2.Struct({
|
|
472
538
|
type: Schema2.Literal("union"),
|
|
473
539
|
queries: Schema2.Array(Schema2.suspend(() => Query))
|
|
@@ -487,6 +553,11 @@ var Order_ = Schema2.Union(Schema2.Struct({
|
|
|
487
553
|
kind: Schema2.Literal("property"),
|
|
488
554
|
property: Schema2.String,
|
|
489
555
|
direction: OrderDirection
|
|
556
|
+
}), Schema2.Struct({
|
|
557
|
+
// Order by relevance rank (for FTS/vector search results).
|
|
558
|
+
// Default direction is 'desc' (higher rank = better match first).
|
|
559
|
+
kind: Schema2.Literal("rank"),
|
|
560
|
+
direction: OrderDirection
|
|
490
561
|
}));
|
|
491
562
|
var Order = Order_;
|
|
492
563
|
var QueryOrderClause_ = Schema2.Struct({
|
|
@@ -501,9 +572,37 @@ var QueryOptionsClause_ = Schema2.Struct({
|
|
|
501
572
|
options: Schema2.suspend(() => QueryOptions)
|
|
502
573
|
});
|
|
503
574
|
var QueryOptionsClause = QueryOptionsClause_;
|
|
504
|
-
var
|
|
575
|
+
var QueryLimitClause_ = Schema2.Struct({
|
|
576
|
+
type: Schema2.Literal("limit"),
|
|
577
|
+
query: Schema2.suspend(() => Query),
|
|
578
|
+
limit: Schema2.Number
|
|
579
|
+
});
|
|
580
|
+
var QueryLimitClause = QueryLimitClause_;
|
|
581
|
+
var QueryFromClause_ = Schema2.Struct({
|
|
582
|
+
type: Schema2.Literal("from"),
|
|
583
|
+
query: Schema2.suspend(() => Query),
|
|
584
|
+
from: Schema2.Union(Schema2.TaggedStruct("scope", {
|
|
585
|
+
scope: Schema2.suspend(() => Scope)
|
|
586
|
+
}), Schema2.TaggedStruct("query", {
|
|
587
|
+
query: Schema2.suspend(() => Query)
|
|
588
|
+
}))
|
|
589
|
+
});
|
|
590
|
+
var QueryFromClause = QueryFromClause_;
|
|
591
|
+
var Query_ = Schema2.Union(QuerySelectClause, QueryFilterClause, QueryReferenceTraversalClause, QueryIncomingReferencesClause, QueryRelationClause, QueryRelationTraversalClause, QueryHierarchyTraversalClause, QueryUnionClause, QuerySetDifferenceClause, QueryOrderClause, QueryOptionsClause, QueryLimitClause, QueryFromClause).annotations({
|
|
592
|
+
identifier: "org.dxos.schema.query"
|
|
593
|
+
});
|
|
505
594
|
var Query = Query_;
|
|
506
595
|
var QueryOptions = Schema2.Struct({
|
|
596
|
+
/**
|
|
597
|
+
* Nested select statements will use this option to filter deleted objects.
|
|
598
|
+
*/
|
|
599
|
+
deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only")),
|
|
600
|
+
/**
|
|
601
|
+
* Diagnostics-only label for logs / tooling (not used by execution semantics).
|
|
602
|
+
*/
|
|
603
|
+
debugLabel: Schema2.optional(Schema2.String)
|
|
604
|
+
});
|
|
605
|
+
var Scope = Schema2.Struct({
|
|
507
606
|
/**
|
|
508
607
|
* The nested select statemets will select from the given spaces.
|
|
509
608
|
*
|
|
@@ -511,72 +610,196 @@ var QueryOptions = Schema2.Struct({
|
|
|
511
610
|
*/
|
|
512
611
|
spaceIds: Schema2.optional(Schema2.Array(Schema2.String)),
|
|
513
612
|
/**
|
|
613
|
+
* If true, the nested select statements will select from all queues in the spaces specified by `spaceIds`.
|
|
614
|
+
*/
|
|
615
|
+
allQueuesFromSpaces: Schema2.optional(Schema2.Boolean),
|
|
616
|
+
/**
|
|
514
617
|
* The nested select statemets will select from the given queues.
|
|
515
618
|
*
|
|
516
619
|
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
517
620
|
*/
|
|
518
|
-
queues: Schema2.optional(Schema2.Array(DXN2.Schema))
|
|
519
|
-
/**
|
|
520
|
-
* Nested select statements will use this option to filter deleted objects.
|
|
521
|
-
*/
|
|
522
|
-
deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only"))
|
|
621
|
+
queues: Schema2.optional(Schema2.Array(DXN2.Schema))
|
|
523
622
|
});
|
|
524
623
|
var visit = (query, visitor) => {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
624
|
+
visitor(query);
|
|
625
|
+
Match.value(query).pipe(Match.when({
|
|
626
|
+
type: "filter"
|
|
627
|
+
}, ({ selection }) => visit(selection, visitor)), Match.when({
|
|
628
|
+
type: "reference-traversal"
|
|
629
|
+
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
630
|
+
type: "incoming-references"
|
|
631
|
+
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
632
|
+
type: "relation"
|
|
633
|
+
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
634
|
+
type: "options"
|
|
635
|
+
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
636
|
+
type: "relation-traversal"
|
|
637
|
+
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
638
|
+
type: "hierarchy-traversal"
|
|
639
|
+
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
640
|
+
type: "union"
|
|
641
|
+
}, ({ queries }) => queries.forEach((q) => visit(q, visitor))), Match.when({
|
|
642
|
+
type: "set-difference"
|
|
643
|
+
}, ({ source, exclude }) => {
|
|
644
|
+
visit(source, visitor);
|
|
645
|
+
visit(exclude, visitor);
|
|
646
|
+
}), Match.when({
|
|
647
|
+
type: "order"
|
|
648
|
+
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
649
|
+
type: "limit"
|
|
650
|
+
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
651
|
+
type: "from"
|
|
652
|
+
}, (node) => {
|
|
653
|
+
visit(node.query, visitor);
|
|
654
|
+
if (node.from._tag === "query") {
|
|
655
|
+
visit(node.from.query, visitor);
|
|
656
|
+
}
|
|
657
|
+
}), Match.when({
|
|
658
|
+
type: "select"
|
|
659
|
+
}, () => {
|
|
660
|
+
}), Match.exhaustive);
|
|
661
|
+
};
|
|
662
|
+
var map = (query, mapper) => {
|
|
663
|
+
const mapped = Match.value(query).pipe(Match.when({
|
|
664
|
+
type: "filter"
|
|
665
|
+
}, (node) => ({
|
|
666
|
+
...node,
|
|
667
|
+
selection: map(node.selection, mapper)
|
|
668
|
+
})), Match.when({
|
|
669
|
+
type: "reference-traversal"
|
|
670
|
+
}, (node) => ({
|
|
671
|
+
...node,
|
|
672
|
+
anchor: map(node.anchor, mapper)
|
|
673
|
+
})), Match.when({
|
|
674
|
+
type: "incoming-references"
|
|
675
|
+
}, (node) => ({
|
|
676
|
+
...node,
|
|
677
|
+
anchor: map(node.anchor, mapper)
|
|
678
|
+
})), Match.when({
|
|
679
|
+
type: "relation"
|
|
680
|
+
}, (node) => ({
|
|
681
|
+
...node,
|
|
682
|
+
anchor: map(node.anchor, mapper)
|
|
683
|
+
})), Match.when({
|
|
684
|
+
type: "relation-traversal"
|
|
685
|
+
}, (node) => ({
|
|
686
|
+
...node,
|
|
687
|
+
anchor: map(node.anchor, mapper)
|
|
688
|
+
})), Match.when({
|
|
689
|
+
type: "hierarchy-traversal"
|
|
690
|
+
}, (node) => ({
|
|
691
|
+
...node,
|
|
692
|
+
anchor: map(node.anchor, mapper)
|
|
693
|
+
})), Match.when({
|
|
694
|
+
type: "options"
|
|
695
|
+
}, (node) => ({
|
|
696
|
+
...node,
|
|
697
|
+
query: map(node.query, mapper)
|
|
698
|
+
})), Match.when({
|
|
699
|
+
type: "order"
|
|
700
|
+
}, (node) => ({
|
|
701
|
+
...node,
|
|
702
|
+
query: map(node.query, mapper)
|
|
703
|
+
})), Match.when({
|
|
704
|
+
type: "limit"
|
|
705
|
+
}, (node) => ({
|
|
706
|
+
...node,
|
|
707
|
+
query: map(node.query, mapper)
|
|
708
|
+
})), Match.when({
|
|
709
|
+
type: "from"
|
|
710
|
+
}, (node) => ({
|
|
711
|
+
...node,
|
|
712
|
+
query: map(node.query, mapper),
|
|
713
|
+
...node.from._tag === "query" ? {
|
|
714
|
+
from: {
|
|
715
|
+
_tag: "query",
|
|
716
|
+
query: map(node.from.query, mapper)
|
|
717
|
+
}
|
|
718
|
+
} : {}
|
|
719
|
+
})), Match.when({
|
|
720
|
+
type: "union"
|
|
721
|
+
}, (node) => ({
|
|
722
|
+
...node,
|
|
723
|
+
queries: node.queries.map((q) => map(q, mapper))
|
|
724
|
+
})), Match.when({
|
|
725
|
+
type: "set-difference"
|
|
726
|
+
}, (node) => ({
|
|
727
|
+
...node,
|
|
728
|
+
source: map(node.source, mapper),
|
|
729
|
+
exclude: map(node.exclude, mapper)
|
|
730
|
+
})), Match.when({
|
|
731
|
+
type: "select"
|
|
732
|
+
}, (node) => node), Match.exhaustive);
|
|
733
|
+
return mapper(mapped);
|
|
552
734
|
};
|
|
553
735
|
var fold = (query, reducer) => {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
736
|
+
return Match.value(query).pipe(Match.withReturnType(), Match.when({
|
|
737
|
+
type: "filter"
|
|
738
|
+
}, ({ selection }) => fold(selection, reducer)), Match.when({
|
|
739
|
+
type: "reference-traversal"
|
|
740
|
+
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
741
|
+
type: "incoming-references"
|
|
742
|
+
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
743
|
+
type: "relation"
|
|
744
|
+
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
745
|
+
type: "options"
|
|
746
|
+
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
747
|
+
type: "relation-traversal"
|
|
748
|
+
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
749
|
+
type: "hierarchy-traversal"
|
|
750
|
+
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
751
|
+
type: "union"
|
|
752
|
+
}, ({ queries }) => queries.flatMap((q) => fold(q, reducer))), Match.when({
|
|
753
|
+
type: "set-difference"
|
|
754
|
+
}, ({ source, exclude }) => fold(source, reducer).concat(fold(exclude, reducer))), Match.when({
|
|
755
|
+
type: "order"
|
|
756
|
+
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
757
|
+
type: "limit"
|
|
758
|
+
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
759
|
+
type: "from"
|
|
760
|
+
}, (node) => {
|
|
761
|
+
const results = fold(node.query, reducer);
|
|
762
|
+
if (node.from._tag === "query") {
|
|
763
|
+
return results.concat(fold(node.from.query, reducer));
|
|
764
|
+
}
|
|
765
|
+
return results;
|
|
766
|
+
}), Match.when({
|
|
767
|
+
type: "select"
|
|
768
|
+
}, () => []), Match.exhaustive);
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
// src/space-doc-version.ts
|
|
772
|
+
var SpaceDocVersion = Object.freeze({
|
|
773
|
+
/**
|
|
774
|
+
* For the documents created before the versioning was introduced.
|
|
775
|
+
*/
|
|
776
|
+
LEGACY: 0,
|
|
777
|
+
/**
|
|
778
|
+
* Current version.
|
|
779
|
+
*/
|
|
780
|
+
CURRENT: 1
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
// src/space-id.ts
|
|
784
|
+
import { subtleCrypto } from "@dxos/crypto";
|
|
785
|
+
import { PublicKey, SpaceId } from "@dxos/keys";
|
|
786
|
+
import { ComplexMap } from "@dxos/util";
|
|
787
|
+
var SPACE_IDS_CACHE = new ComplexMap(PublicKey.hash);
|
|
788
|
+
var createIdFromSpaceKey = async (spaceKey) => {
|
|
789
|
+
const cachedValue = SPACE_IDS_CACHE.get(spaceKey);
|
|
790
|
+
if (cachedValue !== void 0) {
|
|
791
|
+
return cachedValue;
|
|
575
792
|
}
|
|
793
|
+
const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
|
|
794
|
+
const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
|
|
795
|
+
const spaceId = SpaceId.encode(bytes);
|
|
796
|
+
SPACE_IDS_CACHE.set(spaceKey, spaceId);
|
|
797
|
+
return spaceId;
|
|
576
798
|
};
|
|
577
799
|
export {
|
|
578
800
|
DATA_NAMESPACE,
|
|
579
801
|
DatabaseDirectory,
|
|
802
|
+
EchoFeedCodec,
|
|
580
803
|
EncodedReference,
|
|
581
804
|
ForeignKey,
|
|
582
805
|
ObjectStructure,
|