@dxos/echo-protocol 0.8.4-main.f5c0578 → 0.8.4-main.fcc0d83b33
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 +384 -94
- 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 +229 -25
- 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 +315 -34
- package/src/reference.ts +5 -2
- 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 -527
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
|
@@ -35,8 +35,8 @@ var Reference = class _Reference {
|
|
|
35
35
|
return new _Reference(dxn.parts[0], void 0, dxn.parts[0], dxn);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
static fromValue(
|
|
39
|
-
return new _Reference(
|
|
38
|
+
static fromValue(value2) {
|
|
39
|
+
return new _Reference(value2.objectId, value2.protocol, value2.host);
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Reference an object in the local space.
|
|
@@ -124,28 +124,35 @@ var REFERENCE_TYPE_TAG = "dxos.echo.model.document.Reference";
|
|
|
124
124
|
var encodeReference = (reference) => ({
|
|
125
125
|
"/": reference.toDXN().toString()
|
|
126
126
|
});
|
|
127
|
-
var decodeReference = (
|
|
128
|
-
if (typeof
|
|
127
|
+
var decodeReference = (value2) => {
|
|
128
|
+
if (typeof value2 !== "object" || value2 === null || typeof value2["/"] !== "string") {
|
|
129
129
|
throw new Error("Invalid reference");
|
|
130
130
|
}
|
|
131
|
-
const dxnString =
|
|
131
|
+
const dxnString = value2["/"];
|
|
132
132
|
if (dxnString.length % 2 === 0 && dxnString.slice(0, dxnString.length / 2) === dxnString.slice(dxnString.length / 2) && dxnString.includes("dxn:echo")) {
|
|
133
133
|
throw new Error("Automerge bug detected!");
|
|
134
134
|
}
|
|
135
135
|
return Reference.fromDXN(DXN.parse(dxnString));
|
|
136
136
|
};
|
|
137
|
-
var isEncodedReference = (
|
|
137
|
+
var isEncodedReference = (value2) => typeof value2 === "object" && value2 !== null && Object.keys(value2).length === 1 && typeof value2["/"] === "string";
|
|
138
138
|
var EncodedReference = Object.freeze({
|
|
139
139
|
isEncodedReference,
|
|
140
|
-
getReferenceString: (
|
|
141
|
-
assertArgument(isEncodedReference(
|
|
142
|
-
return
|
|
140
|
+
getReferenceString: (value2) => {
|
|
141
|
+
assertArgument(isEncodedReference(value2), "value", "invalid reference");
|
|
142
|
+
return value2["/"];
|
|
143
143
|
},
|
|
144
|
-
toDXN: (
|
|
145
|
-
return DXN.parse(EncodedReference.getReferenceString(
|
|
144
|
+
toDXN: (value2) => {
|
|
145
|
+
return DXN.parse(EncodedReference.getReferenceString(value2));
|
|
146
146
|
},
|
|
147
147
|
fromDXN: (dxn) => {
|
|
148
|
-
return
|
|
148
|
+
return {
|
|
149
|
+
"/": dxn.toString()
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
fromLegacyTypename: (typename) => {
|
|
153
|
+
return {
|
|
154
|
+
"/": DXN.fromTypename(typename).toString()
|
|
155
|
+
};
|
|
149
156
|
}
|
|
150
157
|
});
|
|
151
158
|
|
|
@@ -161,15 +168,7 @@ var DatabaseDirectory = Object.freeze({
|
|
|
161
168
|
return null;
|
|
162
169
|
}
|
|
163
170
|
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
|
-
});
|
|
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'"] });
|
|
173
172
|
return rawKey;
|
|
174
173
|
},
|
|
175
174
|
getInlineObject: (doc, id) => {
|
|
@@ -198,15 +197,7 @@ var ObjectStructure = Object.freeze({
|
|
|
198
197
|
*/
|
|
199
198
|
getEntityKind: (object) => {
|
|
200
199
|
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
|
-
});
|
|
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'"] });
|
|
210
201
|
return kind;
|
|
211
202
|
},
|
|
212
203
|
isDeleted: (object) => {
|
|
@@ -218,29 +209,35 @@ var ObjectStructure = Object.freeze({
|
|
|
218
209
|
getRelationTarget: (object) => {
|
|
219
210
|
return object.system?.target;
|
|
220
211
|
},
|
|
212
|
+
getParent: (object) => {
|
|
213
|
+
return object.system?.parent;
|
|
214
|
+
},
|
|
221
215
|
/**
|
|
222
216
|
* @returns All references in the data section of the object.
|
|
223
217
|
*/
|
|
224
218
|
getAllOutgoingReferences: (object) => {
|
|
225
219
|
const references = [];
|
|
226
|
-
const visit2 = (path,
|
|
227
|
-
if (isEncodedReference(
|
|
220
|
+
const visit2 = (path, value2) => {
|
|
221
|
+
if (isEncodedReference(value2)) {
|
|
228
222
|
references.push({
|
|
229
223
|
path,
|
|
230
|
-
reference:
|
|
224
|
+
reference: value2
|
|
231
225
|
});
|
|
232
226
|
} else {
|
|
233
|
-
visitValues(
|
|
227
|
+
visitValues(value2, (value3, key) => visit2([
|
|
234
228
|
...path,
|
|
235
229
|
String(key)
|
|
236
|
-
],
|
|
230
|
+
], value3));
|
|
237
231
|
}
|
|
238
232
|
};
|
|
239
|
-
visitValues(object.data, (
|
|
233
|
+
visitValues(object.data, (value2, key) => visit2([
|
|
240
234
|
String(key)
|
|
241
|
-
],
|
|
235
|
+
], value2));
|
|
242
236
|
return references;
|
|
243
237
|
},
|
|
238
|
+
getTags: (object) => {
|
|
239
|
+
return object.meta.tags ?? [];
|
|
240
|
+
},
|
|
244
241
|
makeObject: ({ type, data, keys }) => {
|
|
245
242
|
return {
|
|
246
243
|
system: {
|
|
@@ -276,37 +273,63 @@ var ObjectStructure = Object.freeze({
|
|
|
276
273
|
var PROPERTY_ID = "id";
|
|
277
274
|
var DATA_NAMESPACE = "data";
|
|
278
275
|
|
|
279
|
-
// src/
|
|
280
|
-
|
|
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();
|
|
281
282
|
/**
|
|
282
|
-
*
|
|
283
|
+
* Prepares a value for feed storage (strips queue position from metadata) and encodes to bytes.
|
|
283
284
|
*/
|
|
284
|
-
|
|
285
|
+
static encode(value2) {
|
|
286
|
+
const prepared = _EchoFeedCodec.#stripQueuePosition(value2);
|
|
287
|
+
return _EchoFeedCodec.#encoder.encode(JSON.stringify(prepared));
|
|
288
|
+
}
|
|
285
289
|
/**
|
|
286
|
-
*
|
|
290
|
+
* Decodes feed block bytes to a JSON value.
|
|
291
|
+
* If position is provided, injects queue position into the decoded object's metadata.
|
|
287
292
|
*/
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
+
});
|
|
300
327
|
}
|
|
301
|
-
const digest = await subtleCrypto.digest("SHA-256", spaceKey.asUint8Array());
|
|
302
|
-
const bytes = new Uint8Array(digest).slice(0, SpaceId.byteLength);
|
|
303
|
-
const spaceId = SpaceId.encode(bytes);
|
|
304
|
-
SPACE_IDS_CACHE.set(spaceKey, spaceId);
|
|
305
|
-
return spaceId;
|
|
306
328
|
};
|
|
307
329
|
|
|
308
330
|
// src/foreign-key.ts
|
|
309
|
-
import
|
|
331
|
+
import * as Schema from "effect/Schema";
|
|
332
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
310
333
|
var ForeignKey_ = Schema.Struct({
|
|
311
334
|
/**
|
|
312
335
|
* Name of the foreign database/system.
|
|
@@ -317,9 +340,9 @@ var ForeignKey_ = Schema.Struct({
|
|
|
317
340
|
* Id within the foreign database.
|
|
318
341
|
*/
|
|
319
342
|
// TODO(wittjosiah): This annotation is currently used to ensure id field shows up in forms.
|
|
320
|
-
// 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.
|
|
321
344
|
id: Schema.String.annotations({
|
|
322
|
-
[SchemaAST.IdentifierAnnotationId]: false
|
|
345
|
+
[SchemaAST.IdentifierAnnotationId]: "false"
|
|
323
346
|
})
|
|
324
347
|
});
|
|
325
348
|
var ForeignKey = ForeignKey_;
|
|
@@ -329,30 +352,45 @@ var ast_exports = {};
|
|
|
329
352
|
__export(ast_exports, {
|
|
330
353
|
Filter: () => Filter,
|
|
331
354
|
FilterAnd: () => FilterAnd,
|
|
355
|
+
FilterChildOf: () => FilterChildOf,
|
|
332
356
|
FilterCompare: () => FilterCompare,
|
|
357
|
+
FilterContains: () => FilterContains,
|
|
333
358
|
FilterIn: () => FilterIn,
|
|
334
359
|
FilterNot: () => FilterNot,
|
|
335
360
|
FilterObject: () => FilterObject,
|
|
336
361
|
FilterOr: () => FilterOr,
|
|
337
362
|
FilterRange: () => FilterRange,
|
|
363
|
+
FilterTag: () => FilterTag,
|
|
338
364
|
FilterTextSearch: () => FilterTextSearch,
|
|
365
|
+
FilterTimestamp: () => FilterTimestamp,
|
|
366
|
+
Order: () => Order,
|
|
367
|
+
OrderDirection: () => OrderDirection,
|
|
339
368
|
Query: () => Query,
|
|
340
369
|
QueryFilterClause: () => QueryFilterClause,
|
|
370
|
+
QueryFromClause: () => QueryFromClause,
|
|
371
|
+
QueryFromClause_: () => QueryFromClause_,
|
|
372
|
+
QueryHierarchyTraversalClause: () => QueryHierarchyTraversalClause,
|
|
341
373
|
QueryIncomingReferencesClause: () => QueryIncomingReferencesClause,
|
|
374
|
+
QueryLimitClause: () => QueryLimitClause,
|
|
342
375
|
QueryOptions: () => QueryOptions,
|
|
343
376
|
QueryOptionsClause: () => QueryOptionsClause,
|
|
377
|
+
QueryOrderClause: () => QueryOrderClause,
|
|
344
378
|
QueryReferenceTraversalClause: () => QueryReferenceTraversalClause,
|
|
345
379
|
QueryRelationClause: () => QueryRelationClause,
|
|
346
380
|
QueryRelationTraversalClause: () => QueryRelationTraversalClause,
|
|
347
381
|
QuerySelectClause: () => QuerySelectClause,
|
|
348
382
|
QuerySetDifferenceClause: () => QuerySetDifferenceClause,
|
|
349
383
|
QueryUnionClause: () => QueryUnionClause,
|
|
384
|
+
Scope: () => Scope,
|
|
385
|
+
fold: () => fold,
|
|
386
|
+
map: () => map,
|
|
350
387
|
visit: () => visit
|
|
351
388
|
});
|
|
352
|
-
import
|
|
389
|
+
import * as Match from "effect/Match";
|
|
390
|
+
import * as Schema2 from "effect/Schema";
|
|
353
391
|
import { DXN as DXN2, ObjectId } from "@dxos/keys";
|
|
354
392
|
var TypenameSpecifier = Schema2.Union(DXN2.Schema, Schema2.Null).annotations({
|
|
355
|
-
description: "DXN or null
|
|
393
|
+
description: "DXN or null; null matches any type"
|
|
356
394
|
});
|
|
357
395
|
var FilterObject_ = Schema2.Struct({
|
|
358
396
|
type: Schema2.Literal("object"),
|
|
@@ -385,12 +423,29 @@ var FilterIn_ = Schema2.Struct({
|
|
|
385
423
|
values: Schema2.Array(Schema2.Any)
|
|
386
424
|
});
|
|
387
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_;
|
|
388
436
|
var FilterRange_ = Schema2.Struct({
|
|
389
437
|
type: Schema2.Literal("range"),
|
|
390
438
|
from: Schema2.Any,
|
|
391
439
|
to: Schema2.Any
|
|
392
440
|
});
|
|
393
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_;
|
|
394
449
|
var FilterTextSearch_ = Schema2.Struct({
|
|
395
450
|
type: Schema2.Literal("text-search"),
|
|
396
451
|
text: Schema2.String,
|
|
@@ -412,7 +467,17 @@ var FilterOr_ = Schema2.Struct({
|
|
|
412
467
|
filters: Schema2.Array(Schema2.suspend(() => Filter))
|
|
413
468
|
});
|
|
414
469
|
var FilterOr = FilterOr_;
|
|
415
|
-
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
|
+
});
|
|
416
481
|
var QuerySelectClause_ = Schema2.Struct({
|
|
417
482
|
type: Schema2.Literal("select"),
|
|
418
483
|
filter: Schema2.suspend(() => Filter)
|
|
@@ -433,7 +498,11 @@ var QueryReferenceTraversalClause = QueryReferenceTraversalClause_;
|
|
|
433
498
|
var QueryIncomingReferencesClause_ = Schema2.Struct({
|
|
434
499
|
type: Schema2.Literal("incoming-references"),
|
|
435
500
|
anchor: Schema2.suspend(() => Query),
|
|
436
|
-
|
|
501
|
+
/**
|
|
502
|
+
* Property path where the reference is located.
|
|
503
|
+
* If null, matches references from any property.
|
|
504
|
+
*/
|
|
505
|
+
property: Schema2.NullOr(Schema2.String),
|
|
437
506
|
typename: TypenameSpecifier
|
|
438
507
|
});
|
|
439
508
|
var QueryIncomingReferencesClause = QueryIncomingReferencesClause_;
|
|
@@ -455,6 +524,16 @@ var QueryRelationTraversalClause_ = Schema2.Struct({
|
|
|
455
524
|
direction: Schema2.Literal("source", "target", "both")
|
|
456
525
|
});
|
|
457
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_;
|
|
458
537
|
var QueryUnionClause_ = Schema2.Struct({
|
|
459
538
|
type: Schema2.Literal("union"),
|
|
460
539
|
queries: Schema2.Array(Schema2.suspend(() => Query))
|
|
@@ -466,50 +545,261 @@ var QuerySetDifferenceClause_ = Schema2.Struct({
|
|
|
466
545
|
exclude: Schema2.suspend(() => Query)
|
|
467
546
|
});
|
|
468
547
|
var QuerySetDifferenceClause = QuerySetDifferenceClause_;
|
|
548
|
+
var OrderDirection = Schema2.Literal("asc", "desc");
|
|
549
|
+
var Order_ = Schema2.Union(Schema2.Struct({
|
|
550
|
+
// How database wants to order them (in practice - by id).
|
|
551
|
+
kind: Schema2.Literal("natural")
|
|
552
|
+
}), Schema2.Struct({
|
|
553
|
+
kind: Schema2.Literal("property"),
|
|
554
|
+
property: Schema2.String,
|
|
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
|
|
561
|
+
}));
|
|
562
|
+
var Order = Order_;
|
|
563
|
+
var QueryOrderClause_ = Schema2.Struct({
|
|
564
|
+
type: Schema2.Literal("order"),
|
|
565
|
+
query: Schema2.suspend(() => Query),
|
|
566
|
+
order: Schema2.Array(Order)
|
|
567
|
+
});
|
|
568
|
+
var QueryOrderClause = QueryOrderClause_;
|
|
469
569
|
var QueryOptionsClause_ = Schema2.Struct({
|
|
470
570
|
type: Schema2.Literal("options"),
|
|
471
571
|
query: Schema2.suspend(() => Query),
|
|
472
572
|
options: Schema2.suspend(() => QueryOptions)
|
|
473
573
|
});
|
|
474
574
|
var QueryOptionsClause = QueryOptionsClause_;
|
|
475
|
-
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
|
+
});
|
|
476
594
|
var Query = Query_;
|
|
477
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({
|
|
606
|
+
/**
|
|
607
|
+
* The nested select statemets will select from the given spaces.
|
|
608
|
+
*
|
|
609
|
+
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
610
|
+
*/
|
|
478
611
|
spaceIds: Schema2.optional(Schema2.Array(Schema2.String)),
|
|
479
|
-
|
|
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
|
+
/**
|
|
617
|
+
* The nested select statemets will select from the given queues.
|
|
618
|
+
*
|
|
619
|
+
* NOTE: Spaces and queues are unioned together if both are specified.
|
|
620
|
+
*/
|
|
621
|
+
queues: Schema2.optional(Schema2.Array(DXN2.Schema))
|
|
480
622
|
});
|
|
481
623
|
var visit = (query, visitor) => {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
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);
|
|
734
|
+
};
|
|
735
|
+
var fold = (query, reducer) => {
|
|
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;
|
|
508
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;
|
|
509
798
|
};
|
|
510
799
|
export {
|
|
511
800
|
DATA_NAMESPACE,
|
|
512
801
|
DatabaseDirectory,
|
|
802
|
+
EchoFeedCodec,
|
|
513
803
|
EncodedReference,
|
|
514
804
|
ForeignKey,
|
|
515
805
|
ObjectStructure,
|