@dxos/echo-protocol 0.8.4-main.a4bbb77 → 0.8.4-main.abd8ff62ef
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 +306 -97
- 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 +137 -33
- 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 +2 -1
- package/src/index.ts +4 -3
- package/src/query/ast.ts +187 -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 -608
- 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.
|
|
@@ -338,6 +352,7 @@ var ast_exports = {};
|
|
|
338
352
|
__export(ast_exports, {
|
|
339
353
|
Filter: () => Filter,
|
|
340
354
|
FilterAnd: () => FilterAnd,
|
|
355
|
+
FilterChildOf: () => FilterChildOf,
|
|
341
356
|
FilterCompare: () => FilterCompare,
|
|
342
357
|
FilterContains: () => FilterContains,
|
|
343
358
|
FilterIn: () => FilterIn,
|
|
@@ -347,11 +362,16 @@ __export(ast_exports, {
|
|
|
347
362
|
FilterRange: () => FilterRange,
|
|
348
363
|
FilterTag: () => FilterTag,
|
|
349
364
|
FilterTextSearch: () => FilterTextSearch,
|
|
365
|
+
FilterTimestamp: () => FilterTimestamp,
|
|
350
366
|
Order: () => Order,
|
|
351
367
|
OrderDirection: () => OrderDirection,
|
|
352
368
|
Query: () => Query,
|
|
353
369
|
QueryFilterClause: () => QueryFilterClause,
|
|
370
|
+
QueryFromClause: () => QueryFromClause,
|
|
371
|
+
QueryFromClause_: () => QueryFromClause_,
|
|
372
|
+
QueryHierarchyTraversalClause: () => QueryHierarchyTraversalClause,
|
|
354
373
|
QueryIncomingReferencesClause: () => QueryIncomingReferencesClause,
|
|
374
|
+
QueryLimitClause: () => QueryLimitClause,
|
|
355
375
|
QueryOptions: () => QueryOptions,
|
|
356
376
|
QueryOptionsClause: () => QueryOptionsClause,
|
|
357
377
|
QueryOrderClause: () => QueryOrderClause,
|
|
@@ -361,13 +381,16 @@ __export(ast_exports, {
|
|
|
361
381
|
QuerySelectClause: () => QuerySelectClause,
|
|
362
382
|
QuerySetDifferenceClause: () => QuerySetDifferenceClause,
|
|
363
383
|
QueryUnionClause: () => QueryUnionClause,
|
|
384
|
+
Scope: () => Scope,
|
|
364
385
|
fold: () => fold,
|
|
386
|
+
map: () => map,
|
|
365
387
|
visit: () => visit
|
|
366
388
|
});
|
|
367
|
-
import
|
|
389
|
+
import * as Match from "effect/Match";
|
|
390
|
+
import * as Schema2 from "effect/Schema";
|
|
368
391
|
import { DXN as DXN2, ObjectId } from "@dxos/keys";
|
|
369
392
|
var TypenameSpecifier = Schema2.Union(DXN2.Schema, Schema2.Null).annotations({
|
|
370
|
-
description: "DXN or null
|
|
393
|
+
description: "DXN or null; null matches any type"
|
|
371
394
|
});
|
|
372
395
|
var FilterObject_ = Schema2.Struct({
|
|
373
396
|
type: Schema2.Literal("object"),
|
|
@@ -416,6 +439,13 @@ var FilterRange_ = Schema2.Struct({
|
|
|
416
439
|
to: Schema2.Any
|
|
417
440
|
});
|
|
418
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_;
|
|
419
449
|
var FilterTextSearch_ = Schema2.Struct({
|
|
420
450
|
type: Schema2.Literal("text-search"),
|
|
421
451
|
text: Schema2.String,
|
|
@@ -437,8 +467,16 @@ var FilterOr_ = Schema2.Struct({
|
|
|
437
467
|
filters: Schema2.Array(Schema2.suspend(() => Filter))
|
|
438
468
|
});
|
|
439
469
|
var FilterOr = FilterOr_;
|
|
440
|
-
var
|
|
441
|
-
|
|
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"
|
|
442
480
|
});
|
|
443
481
|
var QuerySelectClause_ = Schema2.Struct({
|
|
444
482
|
type: Schema2.Literal("select"),
|
|
@@ -460,7 +498,11 @@ var QueryReferenceTraversalClause = QueryReferenceTraversalClause_;
|
|
|
460
498
|
var QueryIncomingReferencesClause_ = Schema2.Struct({
|
|
461
499
|
type: Schema2.Literal("incoming-references"),
|
|
462
500
|
anchor: Schema2.suspend(() => Query),
|
|
463
|
-
|
|
501
|
+
/**
|
|
502
|
+
* Property path where the reference is located.
|
|
503
|
+
* If null, matches references from any property.
|
|
504
|
+
*/
|
|
505
|
+
property: Schema2.NullOr(Schema2.String),
|
|
464
506
|
typename: TypenameSpecifier
|
|
465
507
|
});
|
|
466
508
|
var QueryIncomingReferencesClause = QueryIncomingReferencesClause_;
|
|
@@ -482,6 +524,16 @@ var QueryRelationTraversalClause_ = Schema2.Struct({
|
|
|
482
524
|
direction: Schema2.Literal("source", "target", "both")
|
|
483
525
|
});
|
|
484
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_;
|
|
485
537
|
var QueryUnionClause_ = Schema2.Struct({
|
|
486
538
|
type: Schema2.Literal("union"),
|
|
487
539
|
queries: Schema2.Array(Schema2.suspend(() => Query))
|
|
@@ -501,6 +553,11 @@ var Order_ = Schema2.Union(Schema2.Struct({
|
|
|
501
553
|
kind: Schema2.Literal("property"),
|
|
502
554
|
property: Schema2.String,
|
|
503
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
|
|
504
561
|
}));
|
|
505
562
|
var Order = Order_;
|
|
506
563
|
var QueryOrderClause_ = Schema2.Struct({
|
|
@@ -515,11 +572,37 @@ var QueryOptionsClause_ = Schema2.Struct({
|
|
|
515
572
|
options: Schema2.suspend(() => QueryOptions)
|
|
516
573
|
});
|
|
517
574
|
var QueryOptionsClause = QueryOptionsClause_;
|
|
518
|
-
var
|
|
519
|
-
|
|
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"
|
|
520
593
|
});
|
|
521
594
|
var Query = Query_;
|
|
522
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({
|
|
523
606
|
/**
|
|
524
607
|
* The nested select statemets will select from the given spaces.
|
|
525
608
|
*
|
|
@@ -527,15 +610,15 @@ var QueryOptions = Schema2.Struct({
|
|
|
527
610
|
*/
|
|
528
611
|
spaceIds: Schema2.optional(Schema2.Array(Schema2.String)),
|
|
529
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
|
+
/**
|
|
530
617
|
* The nested select statemets will select from the given queues.
|
|
531
618
|
*
|
|
532
619
|
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
533
620
|
*/
|
|
534
|
-
queues: Schema2.optional(Schema2.Array(DXN2.Schema))
|
|
535
|
-
/**
|
|
536
|
-
* Nested select statements will use this option to filter deleted objects.
|
|
537
|
-
*/
|
|
538
|
-
deleted: Schema2.optional(Schema2.Literal("include", "exclude", "only"))
|
|
621
|
+
queues: Schema2.optional(Schema2.Array(DXN2.Schema))
|
|
539
622
|
});
|
|
540
623
|
var visit = (query, visitor) => {
|
|
541
624
|
visitor(query);
|
|
@@ -551,6 +634,8 @@ var visit = (query, visitor) => {
|
|
|
551
634
|
type: "options"
|
|
552
635
|
}, ({ query: query2 }) => visit(query2, visitor)), Match.when({
|
|
553
636
|
type: "relation-traversal"
|
|
637
|
+
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
638
|
+
type: "hierarchy-traversal"
|
|
554
639
|
}, ({ anchor }) => visit(anchor, visitor)), Match.when({
|
|
555
640
|
type: "union"
|
|
556
641
|
}, ({ queries }) => queries.forEach((q) => visit(q, visitor))), Match.when({
|
|
@@ -561,10 +646,92 @@ var visit = (query, visitor) => {
|
|
|
561
646
|
}), Match.when({
|
|
562
647
|
type: "order"
|
|
563
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({
|
|
564
658
|
type: "select"
|
|
565
659
|
}, () => {
|
|
566
660
|
}), Match.exhaustive);
|
|
567
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);
|
|
734
|
+
};
|
|
568
735
|
var fold = (query, reducer) => {
|
|
569
736
|
return Match.value(query).pipe(Match.withReturnType(), Match.when({
|
|
570
737
|
type: "filter"
|
|
@@ -578,6 +745,8 @@ var fold = (query, reducer) => {
|
|
|
578
745
|
type: "options"
|
|
579
746
|
}, ({ query: query2 }) => fold(query2, reducer)), Match.when({
|
|
580
747
|
type: "relation-traversal"
|
|
748
|
+
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
749
|
+
type: "hierarchy-traversal"
|
|
581
750
|
}, ({ anchor }) => fold(anchor, reducer)), Match.when({
|
|
582
751
|
type: "union"
|
|
583
752
|
}, ({ queries }) => queries.flatMap((q) => fold(q, reducer))), Match.when({
|
|
@@ -585,12 +754,52 @@ var fold = (query, reducer) => {
|
|
|
585
754
|
}, ({ source, exclude }) => fold(source, reducer).concat(fold(exclude, reducer))), Match.when({
|
|
586
755
|
type: "order"
|
|
587
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({
|
|
588
767
|
type: "select"
|
|
589
768
|
}, () => []), Match.exhaustive);
|
|
590
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;
|
|
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;
|
|
798
|
+
};
|
|
591
799
|
export {
|
|
592
800
|
DATA_NAMESPACE,
|
|
593
801
|
DatabaseDirectory,
|
|
802
|
+
EchoFeedCodec,
|
|
594
803
|
EncodedReference,
|
|
595
804
|
ForeignKey,
|
|
596
805
|
ObjectStructure,
|