@dxos/echo 0.8.3-staging.0fa589b → 0.8.4-main.84f28bd

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.
@@ -1,644 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_4HQE2F3L_exports = {};
30
- __export(chunk_4HQE2F3L_exports, {
31
- DXN: () => import_keys4.DXN,
32
- Filter: () => Filter,
33
- Key_exports: () => Key_exports,
34
- Obj_exports: () => Obj_exports,
35
- Query: () => Query,
36
- Ref_exports: () => Ref_exports,
37
- Relation_exports: () => Relation_exports,
38
- Type_exports: () => Type_exports
39
- });
40
- module.exports = __toCommonJS(chunk_4HQE2F3L_exports);
41
- var import_keys = require("@dxos/keys");
42
- var import_effect = require("effect");
43
- var EchoSchema = __toESM(require("@dxos/echo-schema"));
44
- var import_invariant = require("@dxos/invariant");
45
- var import_live_object = require("@dxos/live-object");
46
- var import_util = require("@dxos/util");
47
- var EchoSchema2 = __toESM(require("@dxos/echo-schema"));
48
- var import_debug = require("@dxos/debug");
49
- var EchoSchema3 = __toESM(require("@dxos/echo-schema"));
50
- var import_invariant2 = require("@dxos/invariant");
51
- var import_keys2 = require("@dxos/keys");
52
- var import_live_object2 = require("@dxos/live-object");
53
- var import_util2 = require("@dxos/util");
54
- var EchoSchema4 = __toESM(require("@dxos/echo-schema"));
55
- var import_invariant3 = require("@dxos/invariant");
56
- var import_echo_schema = require("@dxos/echo-schema");
57
- var import_keys3 = require("@dxos/keys");
58
- var import_echo_schema2 = require("@dxos/echo-schema");
59
- var import_keys4 = require("@dxos/keys");
60
- var import_effect2 = require("effect");
61
- var import_debug2 = require("@dxos/debug");
62
- var import_echo_schema3 = require("@dxos/echo-schema");
63
- var import_invariant4 = require("@dxos/invariant");
64
- var import_keys5 = require("@dxos/keys");
65
- var __defProp2 = Object.defineProperty;
66
- var __export2 = (target, all) => {
67
- for (var name in all)
68
- __defProp2(target, name, { get: all[name], enumerable: true });
69
- };
70
- var Key_exports = {};
71
- __export2(Key_exports, {
72
- ObjectId: () => import_keys.ObjectId,
73
- SpaceId: () => import_keys.SpaceId
74
- });
75
- var Obj_exports = {};
76
- __export2(Obj_exports, {
77
- fromJSON: () => fromJSON,
78
- getDXN: () => getDXN,
79
- getLabel: () => getLabel2,
80
- getMeta: () => getMeta2,
81
- getSchema: () => getSchema2,
82
- getTypeDXN: () => getTypeDXN,
83
- getTypename: () => getTypename,
84
- instanceOf: () => instanceOf,
85
- isDeleted: () => isDeleted2,
86
- isObject: () => isObject,
87
- make: () => make,
88
- toJSON: () => toJSON
89
- });
90
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/echo/echo/src/Obj.ts";
91
- var make = (schema, props, meta) => {
92
- (0, import_invariant.assertArgument)(EchoSchema.getTypeAnnotation(schema)?.kind === EchoSchema.EntityKind.Object, "Expected an object schema");
93
- if (props[EchoSchema.MetaId] != null) {
94
- meta = props[EchoSchema.MetaId];
95
- delete props[EchoSchema.MetaId];
96
- }
97
- return (0, import_live_object.live)(schema, props, meta);
98
- };
99
- var isObject = (obj) => {
100
- (0, import_util.assumeType)(obj);
101
- return typeof obj === "object" && obj !== null && obj[EchoSchema.EntityKindId] === EchoSchema.EntityKind.Object;
102
- };
103
- var instanceOf = (...args) => {
104
- if (args.length === 1) {
105
- return (obj) => EchoSchema.isInstanceOf(args[0], obj);
106
- }
107
- return EchoSchema.isInstanceOf(args[0], args[1]);
108
- };
109
- var getSchema2 = EchoSchema.getSchema;
110
- var getDXN = (obj) => {
111
- (0, import_invariant.assertArgument)(!import_effect.Schema.isSchema(obj), "Object should not be a schema.");
112
- const dxn = EchoSchema.getObjectDXN(obj);
113
- (0, import_invariant.invariant)(dxn != null, "Invalid object.", {
114
- F: __dxlog_file,
115
- L: 96,
116
- S: void 0,
117
- A: [
118
- "dxn != null",
119
- "'Invalid object.'"
120
- ]
121
- });
122
- return dxn;
123
- };
124
- var getTypeDXN = EchoSchema.getType;
125
- var getTypename = (obj) => {
126
- const schema = getSchema2(obj);
127
- if (schema == null) {
128
- return EchoSchema.getType(obj)?.asTypeDXN()?.type;
129
- }
130
- return EchoSchema.getSchemaTypename(schema);
131
- };
132
- var getMeta2 = (obj) => {
133
- const meta = EchoSchema.getMeta(obj);
134
- (0, import_invariant.invariant)(meta != null, "Invalid object.", {
135
- F: __dxlog_file,
136
- L: 124,
137
- S: void 0,
138
- A: [
139
- "meta != null",
140
- "'Invalid object.'"
141
- ]
142
- });
143
- return meta;
144
- };
145
- var isDeleted2 = (obj) => {
146
- const deleted = EchoSchema.isDeleted(obj);
147
- (0, import_invariant.invariant)(typeof deleted === "boolean", "Invalid object.", {
148
- F: __dxlog_file,
149
- L: 131,
150
- S: void 0,
151
- A: [
152
- "typeof deleted === 'boolean'",
153
- "'Invalid object.'"
154
- ]
155
- });
156
- return deleted;
157
- };
158
- var getLabel2 = (obj) => {
159
- const schema = getSchema2(obj);
160
- if (schema != null) {
161
- return EchoSchema.getLabel(schema, obj);
162
- }
163
- };
164
- var toJSON = (obj) => EchoSchema.objectToJSON(obj);
165
- var fromJSON = EchoSchema.objectFromJSON;
166
- var Ref_exports = {};
167
- __export2(Ref_exports, {
168
- Array: () => Array2,
169
- fromDXN: () => fromDXN,
170
- isRef: () => isRef,
171
- make: () => make2
172
- });
173
- var Array2 = EchoSchema2.RefArray;
174
- var isRef = EchoSchema2.Ref.isRef;
175
- var make2 = EchoSchema2.Ref.make;
176
- var fromDXN = EchoSchema2.Ref.fromDXN;
177
- var Relation_exports = {};
178
- __export2(Relation_exports, {
179
- Source: () => Source,
180
- Target: () => Target,
181
- getSource: () => getSource,
182
- getSourceDXN: () => getSourceDXN,
183
- getTarget: () => getTarget,
184
- getTargetDXN: () => getTargetDXN,
185
- isRelation: () => isRelation,
186
- make: () => make3
187
- });
188
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/echo/echo/src/Relation.ts";
189
- var Source = EchoSchema3.RelationSourceId;
190
- var Target = EchoSchema3.RelationTargetId;
191
- var make3 = (schema, props, meta) => {
192
- (0, import_invariant2.assertArgument)(EchoSchema3.getTypeAnnotation(schema)?.kind === EchoSchema3.EntityKind.Relation, "Expected a relation schema");
193
- if (props[EchoSchema3.MetaId] != null) {
194
- meta = props[EchoSchema3.MetaId];
195
- delete props[EchoSchema3.MetaId];
196
- }
197
- const sourceDXN = EchoSchema3.getObjectDXN(props[Source]) ?? (0, import_debug.raise)(new Error("Unresolved relation source"));
198
- const targetDXN = EchoSchema3.getObjectDXN(props[Target]) ?? (0, import_debug.raise)(new Error("Unresolved relation target"));
199
- props[EchoSchema3.RelationSourceDXNId] = sourceDXN;
200
- props[EchoSchema3.RelationTargetDXNId] = targetDXN;
201
- return (0, import_live_object2.live)(schema, props, meta);
202
- };
203
- var isRelation = (value) => {
204
- if (typeof value !== "object" || value === null) {
205
- return false;
206
- }
207
- if (EchoSchema3.ATTR_RELATION_SOURCE in value || EchoSchema3.ATTR_RELATION_TARGET in value) {
208
- return true;
209
- }
210
- const kind = value[EchoSchema3.EntityKindId];
211
- return kind === EchoSchema3.EntityKind.Relation;
212
- };
213
- var getSourceDXN = (value) => {
214
- (0, import_invariant2.assertArgument)(isRelation(value), "Expected a relation");
215
- (0, import_util2.assumeType)(value);
216
- const dxn = value[EchoSchema3.RelationSourceDXNId];
217
- (0, import_invariant2.invariant)(dxn instanceof import_keys2.DXN, void 0, {
218
- F: __dxlog_file2,
219
- L: 98,
220
- S: void 0,
221
- A: [
222
- "dxn instanceof DXN",
223
- ""
224
- ]
225
- });
226
- return dxn;
227
- };
228
- var getTargetDXN = (value) => {
229
- (0, import_invariant2.assertArgument)(isRelation(value), "Expected a relation");
230
- (0, import_util2.assumeType)(value);
231
- const dxn = value[EchoSchema3.RelationTargetDXNId];
232
- (0, import_invariant2.invariant)(dxn instanceof import_keys2.DXN, void 0, {
233
- F: __dxlog_file2,
234
- L: 110,
235
- S: void 0,
236
- A: [
237
- "dxn instanceof DXN",
238
- ""
239
- ]
240
- });
241
- return dxn;
242
- };
243
- var getSource = (relation) => {
244
- (0, import_invariant2.assertArgument)(isRelation(relation), "Expected a relation");
245
- (0, import_util2.assumeType)(relation);
246
- const obj = relation[EchoSchema3.RelationSourceId];
247
- (0, import_invariant2.invariant)(obj !== void 0, `Invalid source: ${relation.id}`, {
248
- F: __dxlog_file2,
249
- L: 122,
250
- S: void 0,
251
- A: [
252
- "obj !== undefined",
253
- "`Invalid source: ${relation.id}`"
254
- ]
255
- });
256
- return obj;
257
- };
258
- var getTarget = (relation) => {
259
- (0, import_invariant2.assertArgument)(isRelation(relation), "Expected a relation");
260
- (0, import_util2.assumeType)(relation);
261
- const obj = relation[EchoSchema3.RelationTargetId];
262
- (0, import_invariant2.invariant)(obj !== void 0, `Invalid target: ${relation.id}`, {
263
- F: __dxlog_file2,
264
- L: 134,
265
- S: void 0,
266
- A: [
267
- "obj !== undefined",
268
- "`Invalid target: ${relation.id}`"
269
- ]
270
- });
271
- return obj;
272
- };
273
- var Type_exports = {};
274
- __export2(Type_exports, {
275
- DXN: () => import_keys3.DXN,
276
- Expando: () => Expando2,
277
- Format: () => import_echo_schema2.Format,
278
- JsonSchema: () => import_echo_schema2.JsonSchemaType,
279
- Kind: () => import_echo_schema.EntityKind,
280
- KindId: () => KindId,
281
- Obj: () => Obj,
282
- ObjectId: () => import_keys3.ObjectId,
283
- Ref: () => Ref3,
284
- Relation: () => Relation,
285
- SpaceId: () => import_keys3.SpaceId,
286
- getDXN: () => getDXN2,
287
- getMeta: () => getMeta3,
288
- getTypename: () => getTypename2,
289
- getVersion: () => getVersion,
290
- isMutable: () => isMutable2,
291
- toEffectSchema: () => import_echo_schema2.toEffectSchema,
292
- toJsonSchema: () => import_echo_schema2.toJsonSchema
293
- });
294
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/echo/echo/src/Type.ts";
295
- var KindId = EchoSchema4.EntityKindId;
296
- var Obj = EchoSchema4.EchoObject;
297
- var Relation = EchoSchema4.EchoRelation;
298
- var Ref3 = EchoSchema4.Ref;
299
- var getDXN2 = (schema) => {
300
- return EchoSchema4.getSchemaDXN(schema);
301
- };
302
- var getTypename2 = (schema) => {
303
- const typename = EchoSchema4.getSchemaTypename(schema);
304
- (0, import_invariant3.invariant)(typeof typename === "string" && !typename.startsWith("dxn:"), "Invalid typename", {
305
- F: __dxlog_file3,
306
- L: 182,
307
- S: void 0,
308
- A: [
309
- "typeof typename === 'string' && !typename.startsWith('dxn:')",
310
- "'Invalid typename'"
311
- ]
312
- });
313
- return typename;
314
- };
315
- var getVersion = (schema) => {
316
- const version = EchoSchema4.getSchemaVersion(schema);
317
- (0, import_invariant3.invariant)(typeof version === "string" && version.match(/^\d+\.\d+\.\d+$/), "Invalid version", {
318
- F: __dxlog_file3,
319
- L: 192,
320
- S: void 0,
321
- A: [
322
- "typeof version === 'string' && version.match(/^\\d+\\.\\d+\\.\\d+$/)",
323
- "'Invalid version'"
324
- ]
325
- });
326
- return version;
327
- };
328
- var getMeta3 = (schema) => {
329
- return EchoSchema4.getTypeAnnotation(schema);
330
- };
331
- var isMutable2 = EchoSchema4.isMutable;
332
- var Expando2 = EchoSchema4.Expando;
333
- var FilterClass = class _FilterClass {
334
- static {
335
- this.variance = {};
336
- }
337
- static is(value) {
338
- return typeof value === "object" && value !== null && "~Filter" in value;
339
- }
340
- static everything() {
341
- return new _FilterClass({
342
- type: "object",
343
- typename: null,
344
- props: {}
345
- });
346
- }
347
- static nothing() {
348
- return new _FilterClass({
349
- type: "not",
350
- filter: {
351
- type: "object",
352
- typename: null,
353
- props: {}
354
- }
355
- });
356
- }
357
- static relation() {
358
- return new _FilterClass({
359
- type: "object",
360
- typename: null,
361
- props: {}
362
- });
363
- }
364
- static ids(...ids) {
365
- (0, import_invariant4.assertArgument)(ids.every((id) => import_keys5.ObjectId.isValid(id)), "ids must be valid");
366
- if (ids.length === 0) {
367
- return Filter.nothing();
368
- }
369
- return new _FilterClass({
370
- type: "object",
371
- typename: null,
372
- id: ids,
373
- props: {}
374
- });
375
- }
376
- static type(schema, props) {
377
- const dxn = (0, import_echo_schema3.getTypeReference)(schema)?.toDXN() ?? (0, import_debug2.raise)(new TypeError("Schema has no DXN"));
378
- return new _FilterClass({
379
- type: "object",
380
- typename: dxn.toString(),
381
- ...propsFilterToAst(props ?? {})
382
- });
383
- }
384
- static typename(typename) {
385
- (0, import_invariant4.assertArgument)(!typename.startsWith("dxn:"), "Typename must no be qualified");
386
- return new _FilterClass({
387
- type: "object",
388
- typename: import_keys5.DXN.fromTypename(typename).toString(),
389
- props: {}
390
- });
391
- }
392
- static typeDXN(dxn) {
393
- return new _FilterClass({
394
- type: "object",
395
- typename: dxn.toString(),
396
- props: {}
397
- });
398
- }
399
- /**
400
- * @internal
401
- */
402
- static _props(props) {
403
- return new _FilterClass({
404
- type: "object",
405
- typename: null,
406
- ...propsFilterToAst(props)
407
- });
408
- }
409
- static text(text, options) {
410
- return new _FilterClass({
411
- type: "text-search",
412
- text,
413
- searchKind: options?.type
414
- });
415
- }
416
- static foreignKeys(schema, keys) {
417
- const dxn = (0, import_echo_schema3.getTypeReference)(schema)?.toDXN() ?? (0, import_debug2.raise)(new TypeError("Schema has no DXN"));
418
- return new _FilterClass({
419
- type: "object",
420
- typename: dxn.toString(),
421
- props: {},
422
- foreignKeys: keys
423
- });
424
- }
425
- static eq(value) {
426
- if (!isRef(value) && typeof value === "object" && value !== null) {
427
- throw new TypeError("Cannot use object as a value for eq filter");
428
- }
429
- return new _FilterClass({
430
- type: "compare",
431
- operator: "eq",
432
- value: isRef(value) ? value.noInline().encode() : value
433
- });
434
- }
435
- static neq(value) {
436
- return new _FilterClass({
437
- type: "compare",
438
- operator: "neq",
439
- value
440
- });
441
- }
442
- static gt(value) {
443
- return new _FilterClass({
444
- type: "compare",
445
- operator: "gt",
446
- value
447
- });
448
- }
449
- static gte(value) {
450
- return new _FilterClass({
451
- type: "compare",
452
- operator: "gte",
453
- value
454
- });
455
- }
456
- static lt(value) {
457
- return new _FilterClass({
458
- type: "compare",
459
- operator: "lt",
460
- value
461
- });
462
- }
463
- static lte(value) {
464
- return new _FilterClass({
465
- type: "compare",
466
- operator: "lte",
467
- value
468
- });
469
- }
470
- static in(...values) {
471
- return new _FilterClass({
472
- type: "in",
473
- values
474
- });
475
- }
476
- static between(from, to) {
477
- return new _FilterClass({
478
- type: "range",
479
- from,
480
- to
481
- });
482
- }
483
- static not(filter) {
484
- return new _FilterClass({
485
- type: "not",
486
- filter: filter.ast
487
- });
488
- }
489
- static and(...filters) {
490
- return new _FilterClass({
491
- type: "and",
492
- filters: filters.map((f) => f.ast)
493
- });
494
- }
495
- static or(...filters) {
496
- return new _FilterClass({
497
- type: "or",
498
- filters: filters.map((f) => f.ast)
499
- });
500
- }
501
- constructor(ast) {
502
- this.ast = ast;
503
- this["~Filter"] = _FilterClass.variance;
504
- }
505
- };
506
- var Filter = FilterClass;
507
- var propsFilterToAst = (predicates) => {
508
- let idFilter;
509
- if ("id" in predicates) {
510
- (0, import_invariant4.assertArgument)(typeof predicates.id === "string" || Array.isArray(predicates.id), "invalid id filter");
511
- idFilter = typeof predicates.id === "string" ? [
512
- predicates.id
513
- ] : predicates.id;
514
- import_effect2.Schema.Array(import_keys5.ObjectId).pipe(import_effect2.Schema.validateSync)(idFilter);
515
- }
516
- return {
517
- id: idFilter,
518
- props: Object.fromEntries(Object.entries(predicates).filter(([prop, _value]) => prop !== "id").map(([prop, predicate]) => [
519
- prop,
520
- Filter.is(predicate) ? predicate.ast : Filter.eq(predicate).ast
521
- ]))
522
- };
523
- };
524
- var QueryClass = class _QueryClass {
525
- static {
526
- this.variance = {};
527
- }
528
- static is(value) {
529
- return typeof value === "object" && value !== null && "~Query" in value;
530
- }
531
- static select(filter) {
532
- return new _QueryClass({
533
- type: "select",
534
- filter: filter.ast
535
- });
536
- }
537
- static type(schema, predicates) {
538
- return new _QueryClass({
539
- type: "select",
540
- filter: FilterClass.type(schema, predicates).ast
541
- });
542
- }
543
- static all(...queries) {
544
- if (queries.length === 0) {
545
- throw new TypeError("Query.all combines results of multiple queries, to query all objects use Query.select(Filter.everything())");
546
- }
547
- return new _QueryClass({
548
- type: "union",
549
- queries: queries.map((q) => q.ast)
550
- });
551
- }
552
- static without(source, exclude) {
553
- return new _QueryClass({
554
- type: "set-difference",
555
- source: source.ast,
556
- exclude: exclude.ast
557
- });
558
- }
559
- constructor(ast) {
560
- this.ast = ast;
561
- this["~Query"] = _QueryClass.variance;
562
- }
563
- select(filter) {
564
- if (Filter.is(filter)) {
565
- return new _QueryClass({
566
- type: "filter",
567
- selection: this.ast,
568
- filter: filter.ast
569
- });
570
- } else {
571
- return new _QueryClass({
572
- type: "filter",
573
- selection: this.ast,
574
- filter: FilterClass._props(filter).ast
575
- });
576
- }
577
- }
578
- reference(key) {
579
- return new _QueryClass({
580
- type: "reference-traversal",
581
- anchor: this.ast,
582
- property: key
583
- });
584
- }
585
- referencedBy(target, key) {
586
- const dxn = (0, import_echo_schema3.getTypeReference)(target)?.toDXN() ?? (0, import_debug2.raise)(new TypeError("Target schema has no DXN"));
587
- return new _QueryClass({
588
- type: "incoming-references",
589
- anchor: this.ast,
590
- property: key,
591
- typename: dxn.toString()
592
- });
593
- }
594
- sourceOf(relation, predicates) {
595
- return new _QueryClass({
596
- type: "relation",
597
- anchor: this.ast,
598
- direction: "outgoing",
599
- filter: FilterClass.type(relation, predicates).ast
600
- });
601
- }
602
- targetOf(relation, predicates) {
603
- return new _QueryClass({
604
- type: "relation",
605
- anchor: this.ast,
606
- direction: "incoming",
607
- filter: FilterClass.type(relation, predicates).ast
608
- });
609
- }
610
- source() {
611
- return new _QueryClass({
612
- type: "relation-traversal",
613
- anchor: this.ast,
614
- direction: "source"
615
- });
616
- }
617
- target() {
618
- return new _QueryClass({
619
- type: "relation-traversal",
620
- anchor: this.ast,
621
- direction: "target"
622
- });
623
- }
624
- options(options) {
625
- return new _QueryClass({
626
- type: "options",
627
- query: this.ast,
628
- options
629
- });
630
- }
631
- };
632
- var Query = QueryClass;
633
- // Annotate the CommonJS export names for ESM import in node:
634
- 0 && (module.exports = {
635
- DXN,
636
- Filter,
637
- Key_exports,
638
- Obj_exports,
639
- Query,
640
- Ref_exports,
641
- Relation_exports,
642
- Type_exports
643
- });
644
- //# sourceMappingURL=chunk-4HQE2F3L.cjs.map