@dxos/echo 0.16.0 → 0.17.0
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/Annotation.mjs +2 -2
- package/dist/lib/Database.mjs +1 -1
- package/dist/lib/Error.mjs +1 -1
- package/dist/lib/Feed.mjs +1 -1
- package/dist/lib/Format.mjs +2 -2
- package/dist/lib/Migration.mjs +1 -1
- package/dist/lib/chunk-Annotation.mjs +14 -11
- package/dist/lib/chunk-Annotation.mjs.map +1 -1
- package/dist/lib/chunk-Blob.mjs +1 -1
- package/dist/lib/chunk-Collection.mjs +1 -1
- package/dist/lib/chunk-Database.mjs +93 -7
- package/dist/lib/chunk-Database.mjs.map +1 -1
- package/dist/lib/chunk-Dataset.mjs +1 -1
- package/dist/lib/chunk-Entity.mjs +2 -2
- package/dist/lib/chunk-Entity.mjs.map +1 -1
- package/dist/lib/chunk-Error.mjs +13 -1
- package/dist/lib/chunk-Error.mjs.map +1 -1
- package/dist/lib/chunk-Feed.mjs +311 -17
- package/dist/lib/chunk-Feed.mjs.map +1 -1
- package/dist/lib/chunk-Filter.mjs +4 -3
- package/dist/lib/chunk-Filter.mjs.map +1 -1
- package/dist/lib/chunk-Format.mjs +2 -1
- package/dist/lib/chunk-Hypergraph.mjs +1 -1
- package/dist/lib/chunk-Hypergraph.mjs.map +1 -1
- package/dist/lib/chunk-Migration.mjs +155 -5
- package/dist/lib/chunk-Migration.mjs.map +1 -1
- package/dist/lib/chunk-Obj.mjs +12 -5
- package/dist/lib/chunk-Obj.mjs.map +1 -1
- package/dist/lib/chunk-Query.mjs +2 -2
- package/dist/lib/chunk-QueryResult.mjs.map +1 -1
- package/dist/lib/chunk-Ref2.mjs +2 -2
- package/dist/lib/chunk-Registry.mjs +1 -1
- package/dist/lib/chunk-Registry.mjs.map +1 -1
- package/dist/lib/chunk-Relation.mjs +5 -5
- package/dist/lib/chunk-Relation.mjs.map +1 -1
- package/dist/lib/chunk-Scope.mjs +16 -2
- package/dist/lib/chunk-Scope.mjs.map +1 -1
- package/dist/lib/chunk-Tag.mjs +4 -4
- package/dist/lib/chunk-Tag.mjs.map +1 -1
- package/dist/lib/chunk-Text.mjs +2 -2
- package/dist/lib/chunk-Type.mjs +26 -7
- package/dist/lib/chunk-Type.mjs.map +1 -1
- package/dist/lib/chunk-View.mjs +1 -1
- package/dist/lib/chunk-atom-snapshot.mjs +29 -1
- package/dist/lib/chunk-atom-snapshot.mjs.map +1 -1
- package/dist/lib/chunk-entity-dictionary.mjs +28 -19
- package/dist/lib/chunk-entity-dictionary.mjs.map +1 -1
- package/dist/lib/chunk-internal.mjs +231 -79
- package/dist/lib/chunk-internal.mjs.map +1 -1
- package/dist/lib/chunk-json-schema.mjs +1 -1
- package/dist/lib/chunk-ref.mjs +38 -34
- package/dist/lib/chunk-ref.mjs.map +1 -1
- package/dist/lib/chunk-select.mjs +7 -3
- package/dist/lib/chunk-select.mjs.map +1 -1
- package/dist/lib/index.mjs +2 -2
- package/dist/lib/internal.mjs +6 -6
- package/dist/lib/testing.mjs +2 -2
- package/dist/lib/testing.mjs.map +1 -1
- package/dist/types/src/Annotation.d.ts +1 -1
- package/dist/types/src/Annotation.d.ts.map +1 -1
- package/dist/types/src/Database.d.ts +30 -13
- package/dist/types/src/Database.d.ts.map +1 -1
- package/dist/types/src/Entity.d.ts +3 -4
- package/dist/types/src/Entity.d.ts.map +1 -1
- package/dist/types/src/Error.d.ts +36 -0
- package/dist/types/src/Error.d.ts.map +1 -1
- package/dist/types/src/Feed.d.ts +261 -18
- package/dist/types/src/Feed.d.ts.map +1 -1
- package/dist/types/src/Filter.d.ts +7 -1
- package/dist/types/src/Filter.d.ts.map +1 -1
- package/dist/types/src/Hypergraph.d.ts +1 -1
- package/dist/types/src/Migration.d.ts +213 -2
- package/dist/types/src/Migration.d.ts.map +1 -1
- package/dist/types/src/Migration.test.d.ts +2 -0
- package/dist/types/src/Migration.test.d.ts.map +1 -0
- package/dist/types/src/Obj.d.ts +4 -4
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/QueryResult.d.ts +16 -0
- package/dist/types/src/QueryResult.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +3 -4
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Scope.d.ts +32 -1
- package/dist/types/src/Scope.d.ts.map +1 -1
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +27 -2
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/annotations.d.ts +35 -1
- package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/atoms.d.ts +2 -2
- package/dist/types/src/internal/Annotation/atoms.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/api.d.ts +11 -0
- package/dist/types/src/internal/Entity/api.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/model.d.ts +3 -2
- package/dist/types/src/internal/Entity/model.d.ts.map +1 -1
- package/dist/types/src/internal/Format/string.d.ts +5 -1
- package/dist/types/src/internal/Format/string.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/atoms.d.ts +1 -1
- package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/Query/pretty.d.ts.map +1 -1
- package/dist/types/src/internal/Ref/ref.d.ts +5 -1
- package/dist/types/src/internal/Ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/Ref/strong-deps.d.ts +3 -1
- package/dist/types/src/internal/Ref/strong-deps.d.ts.map +1 -1
- package/dist/types/src/internal/common/api/meta.d.ts +4 -5
- package/dist/types/src/internal/common/api/meta.d.ts.map +1 -1
- package/dist/types/src/internal/common/atom-snapshot.d.ts +10 -0
- package/dist/types/src/internal/common/atom-snapshot.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/change-context.d.ts +4 -0
- package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/ownership.d.ts +5 -0
- package/dist/types/src/internal/common/proxy/ownership.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/schema-validator.d.ts +17 -2
- package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/symbols.d.ts +10 -0
- package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts +0 -1
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/meta.d.ts +8 -4
- package/dist/types/src/internal/common/types/meta.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/model-symbols.d.ts +6 -0
- package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -1
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -15
- package/src/Annotation.test.ts +34 -0
- package/src/Annotation.ts +3 -0
- package/src/Database.ts +46 -15
- package/src/Entity.ts +3 -4
- package/src/Error.ts +9 -0
- package/src/Feed.test.ts +160 -0
- package/src/Feed.ts +412 -29
- package/src/Filter.ts +8 -1
- package/src/Hypergraph.ts +1 -1
- package/src/Migration.test.ts +137 -0
- package/src/Migration.ts +376 -4
- package/src/Obj.test.ts +44 -4
- package/src/Obj.ts +19 -5
- package/src/QueryResult.ts +14 -0
- package/src/Relation.ts +3 -4
- package/src/Scope.ts +43 -1
- package/src/Tag.md +5 -6
- package/src/Tag.ts +3 -2
- package/src/Type.test.ts +52 -0
- package/src/Type.ts +75 -22
- package/src/Type.tst.ts +155 -0
- package/src/internal/Annotation/annotations.test.ts +19 -0
- package/src/internal/Annotation/annotations.ts +67 -1
- package/src/internal/Annotation/atoms.ts +10 -9
- package/src/internal/Entity/api.ts +20 -1
- package/src/internal/Entity/model.ts +3 -0
- package/src/internal/Filter/match.ts +2 -2
- package/src/internal/Format/string.ts +7 -2
- package/src/internal/JsonSchema/json-schema.test.ts +2 -2
- package/src/internal/Obj/atoms.ts +9 -5
- package/src/internal/Obj/json-serializer.test.ts +34 -7
- package/src/internal/Obj/json-serializer.ts +18 -3
- package/src/internal/Query/pretty.ts +3 -2
- package/src/internal/Ref/ref.test.ts +27 -2
- package/src/internal/Ref/ref.ts +18 -2
- package/src/internal/Ref/strong-deps.ts +21 -2
- package/src/internal/common/api/meta.ts +7 -8
- package/src/internal/common/atom-snapshot.ts +61 -0
- package/src/internal/common/proxy/change-context.ts +5 -0
- package/src/internal/common/proxy/change.test.ts +62 -31
- package/src/internal/common/proxy/json-serializer.ts +3 -2
- package/src/internal/common/proxy/ownership.ts +14 -1
- package/src/internal/common/proxy/proxy-utils.ts +7 -1
- package/src/internal/common/proxy/schema-validator.ts +116 -27
- package/src/internal/common/proxy/symbols.ts +12 -0
- package/src/internal/common/proxy/typed-handler.test.ts +43 -0
- package/src/internal/common/proxy/typed-handler.ts +105 -33
- package/src/internal/common/types/meta.ts +25 -20
- package/src/internal/common/types/model-symbols.ts +7 -0
- package/src/internal/index.ts +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "ECHO API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -179,26 +179,30 @@
|
|
|
179
179
|
"src"
|
|
180
180
|
],
|
|
181
181
|
"dependencies": {
|
|
182
|
+
"@dxos/async": "0.17.0",
|
|
183
|
+
"@dxos/blob": "0.17.0",
|
|
184
|
+
"@dxos/debug": "0.17.0",
|
|
185
|
+
"@dxos/echo-protocol": "0.17.0",
|
|
186
|
+
"@dxos/effect": "0.17.0",
|
|
187
|
+
"@dxos/errors": "0.17.0",
|
|
188
|
+
"@dxos/invariant": "0.17.0",
|
|
189
|
+
"@dxos/keys": "0.17.0",
|
|
190
|
+
"@dxos/log": "0.17.0",
|
|
191
|
+
"@dxos/node-std": "0.17.0",
|
|
192
|
+
"@dxos/util": "0.17.0",
|
|
182
193
|
"effect": "4.0.4",
|
|
183
|
-
"semver": "^7.7.4"
|
|
184
|
-
"@dxos/async": "0.16.0",
|
|
185
|
-
"@dxos/blob": "0.16.0",
|
|
186
|
-
"@dxos/debug": "0.16.0",
|
|
187
|
-
"@dxos/echo-protocol": "0.16.0",
|
|
188
|
-
"@dxos/effect": "0.16.0",
|
|
189
|
-
"@dxos/errors": "0.16.0",
|
|
190
|
-
"@dxos/invariant": "0.16.0",
|
|
191
|
-
"@dxos/keys": "0.16.0",
|
|
192
|
-
"@dxos/log": "0.16.0",
|
|
193
|
-
"@dxos/node-std": "0.16.0",
|
|
194
|
-
"@dxos/util": "0.16.0"
|
|
194
|
+
"semver": "^7.7.4"
|
|
195
195
|
},
|
|
196
196
|
"devDependencies": {
|
|
197
197
|
"@types/node": "22.10.2",
|
|
198
|
-
"@types/semver": "^7.7.1"
|
|
198
|
+
"@types/semver": "^7.7.1",
|
|
199
|
+
"typedoc": "0.28.1"
|
|
199
200
|
},
|
|
200
201
|
"publishConfig": {
|
|
201
202
|
"access": "public"
|
|
202
203
|
},
|
|
203
|
-
"beast": {}
|
|
204
|
+
"beast": {},
|
|
205
|
+
"scripts": {
|
|
206
|
+
"typedoc": "typedoc --out typedoc"
|
|
207
|
+
}
|
|
204
208
|
}
|
package/src/Annotation.test.ts
CHANGED
|
@@ -524,6 +524,40 @@ describe('Annotation', () => {
|
|
|
524
524
|
setOrder(obj, { typeA: ['x'] });
|
|
525
525
|
expect(Option.getOrThrow(registry.get(wholeAtom))).toEqual({ typeA: ['x'] });
|
|
526
526
|
});
|
|
527
|
+
|
|
528
|
+
test('atom hands a nested value changed in place to its readers as a new value, and keeps an unchanged one', ({
|
|
529
|
+
expect,
|
|
530
|
+
}) => {
|
|
531
|
+
const LayoutAnnotation = Annotation.make({
|
|
532
|
+
id: 'org.dxos.test.layout',
|
|
533
|
+
schema: Schema.Struct({ positions: Schema.Record(Schema.String, Schema.Struct({ x: Schema.Number })) }),
|
|
534
|
+
});
|
|
535
|
+
const registry = AtomRegistry.make();
|
|
536
|
+
const obj = Obj.make(Container, { name: 'A' });
|
|
537
|
+
Obj.update(obj, (obj) => {
|
|
538
|
+
Annotation.set(obj, LayoutAnnotation, { positions: { a: { x: 0 } } });
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
const layoutAtom = Annotation.atom(obj, LayoutAnnotation);
|
|
542
|
+
let fires = 0;
|
|
543
|
+
registry.subscribe(layoutAtom, () => {
|
|
544
|
+
fires++;
|
|
545
|
+
});
|
|
546
|
+
const before = Option.getOrThrow(registry.get(layoutAtom)).positions;
|
|
547
|
+
Annotation.update(obj, LayoutAnnotation, (layout) => {
|
|
548
|
+
layout.positions.b = { x: 1 };
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
const after = Option.getOrThrow(registry.get(layoutAtom)).positions;
|
|
552
|
+
expect(after).toEqual({ a: { x: 0 }, b: { x: 1 } });
|
|
553
|
+
expect(after).not.toBe(before);
|
|
554
|
+
|
|
555
|
+
const changes = fires;
|
|
556
|
+
Obj.update(obj, (obj) => {
|
|
557
|
+
obj.name = 'B';
|
|
558
|
+
});
|
|
559
|
+
expect(fires).toBe(changes);
|
|
560
|
+
});
|
|
527
561
|
});
|
|
528
562
|
|
|
529
563
|
describe('reactive in-place mutation', () => {
|
package/src/Annotation.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
export {
|
|
8
8
|
type ArrayPresentation,
|
|
9
9
|
ArrayPresentationAnnotation,
|
|
10
|
+
ContentVersionAnnotation,
|
|
11
|
+
type ContentVersionAnnotationValue,
|
|
10
12
|
DEFAULT_LAYOUT_NAME,
|
|
11
13
|
DescriptionAnnotation,
|
|
12
14
|
FieldLookupAnnotationId,
|
|
@@ -24,6 +26,7 @@ export {
|
|
|
24
26
|
IconAnnotation,
|
|
25
27
|
IconFromRefAnnotation,
|
|
26
28
|
LabelAnnotation,
|
|
29
|
+
RawStringAnnotation,
|
|
27
30
|
ReferenceAnnotation,
|
|
28
31
|
ReferenceAnnotationId,
|
|
29
32
|
type ReferenceAnnotationValue,
|
package/src/Database.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { type AnyProperties, EntityKind, KindId } from './internal/common/types/
|
|
|
27
27
|
import { isInstanceOf } from './internal/Entity/type-uri.ts';
|
|
28
28
|
import * as queryInternal from './internal/Query/index.ts';
|
|
29
29
|
import type { LoadOptions, Ref } from './internal/Ref/ref.ts';
|
|
30
|
+
import type * as Migration from './Migration.ts';
|
|
30
31
|
import type * as Obj from './Obj.ts';
|
|
31
32
|
import type * as Query from './Query.ts';
|
|
32
33
|
import type * as QueryResult from './QueryResult.ts';
|
|
@@ -53,8 +54,6 @@ export type GetObjectByIdOptions = {
|
|
|
53
54
|
deleted?: boolean;
|
|
54
55
|
};
|
|
55
56
|
|
|
56
|
-
export type ObjectPlacement = 'root-doc' | 'linked-doc';
|
|
57
|
-
|
|
58
57
|
/**
|
|
59
58
|
* Whether a write was a person's own action, reported with ECHO's trace events. `system` is everything a person
|
|
60
59
|
* did not directly do: agents, syncs and imports, seeded content, migrations and automation. When no origin is
|
|
@@ -91,16 +90,6 @@ export type WriteOptions = {
|
|
|
91
90
|
};
|
|
92
91
|
|
|
93
92
|
export type AddOptions = {
|
|
94
|
-
/**
|
|
95
|
-
* Where to place the object in the Automerge document tree.
|
|
96
|
-
* Root document is always loaded with the space.
|
|
97
|
-
* Linked documents are loaded lazily.
|
|
98
|
-
* Placing large number of objects in the root document may slow down the initial load.
|
|
99
|
-
*
|
|
100
|
-
* @default 'linked-doc'
|
|
101
|
-
*/
|
|
102
|
-
placeIn?: ObjectPlacement;
|
|
103
|
-
|
|
104
93
|
/** See {@link Origin}. */
|
|
105
94
|
origin?: Origin;
|
|
106
95
|
|
|
@@ -108,7 +97,7 @@ export type AddOptions = {
|
|
|
108
97
|
* Append the object to this feed instead of the automerge-backed space database. The object is
|
|
109
98
|
* returned synchronously (a live feed object) and persisted in the background — confirm the write
|
|
110
99
|
* completed with {@link Database.flush}. Synchronous alternative to the async
|
|
111
|
-
* {@link Database.appendToFeed}
|
|
100
|
+
* {@link Database.appendToFeed}.
|
|
112
101
|
*/
|
|
113
102
|
to?: Feed.Feed;
|
|
114
103
|
};
|
|
@@ -268,6 +257,19 @@ export interface Database extends Queryable {
|
|
|
268
257
|
*/
|
|
269
258
|
appendToFeed(feed: Feed.Feed, entities: Entity.Unknown[], opts?: WriteOptions): Promise<void>;
|
|
270
259
|
|
|
260
|
+
/**
|
|
261
|
+
* Appends `base` as the base block of a new branch of the feed, with the fork point `at` (an item,
|
|
262
|
+
* at the block it was read from, or a block id) as its predecessor. Resolves to the id of the new
|
|
263
|
+
* branch, the block id of the base, once the base is written.
|
|
264
|
+
*
|
|
265
|
+
* @performance Async; one append of one entity.
|
|
266
|
+
*/
|
|
267
|
+
forkFeed(
|
|
268
|
+
feed: Feed.Feed,
|
|
269
|
+
base: Entity.Unknown,
|
|
270
|
+
opts: { at: Entity.Unknown | Entity.Snapshot | Feed.BlockId },
|
|
271
|
+
): Promise<Feed.BranchId>;
|
|
272
|
+
|
|
271
273
|
/**
|
|
272
274
|
* Removes entities from a feed.
|
|
273
275
|
*
|
|
@@ -284,6 +286,14 @@ export interface Database extends Queryable {
|
|
|
284
286
|
*/
|
|
285
287
|
flush(opts?: FlushOptions): Promise<void>;
|
|
286
288
|
|
|
289
|
+
/**
|
|
290
|
+
* Starts staging structural changes that commit atomically; see {@link Migration.Transaction}.
|
|
291
|
+
*
|
|
292
|
+
* @throws When the database cannot commit with the chosen {@link Migration.TransactionOptions.root}.
|
|
293
|
+
* @performance Async; loads the transaction code on first use, then O(1).
|
|
294
|
+
*/
|
|
295
|
+
beginMigration(options?: Migration.TransactionOptions): Promise<Migration.Transaction>;
|
|
296
|
+
|
|
287
297
|
//
|
|
288
298
|
// Branching. A branch is a writable alternate timeline of an object subtree (same object ids,
|
|
289
299
|
// shared automerge history, true CRDT merge-back). The registry is synced on the space root;
|
|
@@ -376,11 +386,16 @@ export interface Database extends Queryable {
|
|
|
376
386
|
branch<T extends Obj.Unknown>(obj: T, name: string): Promise<BranchBinding<T>>;
|
|
377
387
|
|
|
378
388
|
/**
|
|
379
|
-
* Removes feed items by ID.
|
|
389
|
+
* Removes feed items by ID. `branches` names the branch of each item by index (`null` for the root),
|
|
390
|
+
* for an item this client holds no live copy of; without it such an item is removed from the root branch.
|
|
380
391
|
*
|
|
381
392
|
* @performance Async; O(n) in ids, deleted in one batch.
|
|
382
393
|
*/
|
|
383
|
-
removeFeedItemsByIds(
|
|
394
|
+
removeFeedItemsByIds(
|
|
395
|
+
feed: Feed.Feed,
|
|
396
|
+
ids: string[],
|
|
397
|
+
options?: { branches?: ReadonlyArray<string | null> },
|
|
398
|
+
): Promise<void>;
|
|
384
399
|
|
|
385
400
|
/**
|
|
386
401
|
* Syncs a feed with the server.
|
|
@@ -614,6 +629,22 @@ export const resolve: {
|
|
|
614
629
|
return object as any;
|
|
615
630
|
}).pipe(Effect.withSpan('Database.resolve'), withSpaceId)) as any;
|
|
616
631
|
|
|
632
|
+
/**
|
|
633
|
+
* Starts staging structural changes in the current database; see {@link Migration.Transaction}.
|
|
634
|
+
*
|
|
635
|
+
* @performance Async; loads the transaction code on first use, then O(1).
|
|
636
|
+
*/
|
|
637
|
+
export const beginMigration = (
|
|
638
|
+
options?: Migration.TransactionOptions,
|
|
639
|
+
): Effect.Effect<Migration.Transaction, Error.MigrationError, Service> =>
|
|
640
|
+
Effect.gen(function* () {
|
|
641
|
+
const { db } = yield* Service;
|
|
642
|
+
return yield* Effect.tryPromise({
|
|
643
|
+
try: () => db.beginMigration(options),
|
|
644
|
+
catch: (cause) => new Error.MigrationError({ operation: 'begin' }, { cause }),
|
|
645
|
+
});
|
|
646
|
+
}).pipe(Effect.withSpan('Database.beginMigration'), withSpaceId);
|
|
647
|
+
|
|
617
648
|
/**
|
|
618
649
|
* Loads an object reference. A deleted target reads as absent unless `{ deleted: 'include' }` asks
|
|
619
650
|
* for it.
|
package/src/Entity.ts
CHANGED
|
@@ -11,7 +11,6 @@ import type { EntityId, URI } from '@dxos/keys';
|
|
|
11
11
|
|
|
12
12
|
import * as internal from './internal/index.ts';
|
|
13
13
|
import * as objInternal from './internal/Obj/index.ts';
|
|
14
|
-
import type * as Ref from './Ref.ts';
|
|
15
14
|
import type * as Relation from './Relation.ts';
|
|
16
15
|
import type * as Tag from './Tag.ts';
|
|
17
16
|
import * as Type from './Type.ts';
|
|
@@ -370,9 +369,9 @@ export const update = <T extends Unknown>(entity: T, callback: internal.ChangeCa
|
|
|
370
369
|
* Add a tag to an entity.
|
|
371
370
|
* Must be called within an `Entity.update`, `Obj.update`, or `Relation.update` callback.
|
|
372
371
|
*
|
|
373
|
-
* @performance O(t) in the tag count; dedupes by
|
|
372
|
+
* @performance O(t) in the tag count; dedupes by tag id before appending.
|
|
374
373
|
*/
|
|
375
|
-
export const addTag = (entity: Mutable<Unknown>, tag:
|
|
374
|
+
export const addTag = (entity: Mutable<Unknown>, tag: Tag.Tag): void => internal.addTag(entity, tag);
|
|
376
375
|
|
|
377
376
|
/**
|
|
378
377
|
* Remove a tag from an entity.
|
|
@@ -380,7 +379,7 @@ export const addTag = (entity: Mutable<Unknown>, tag: Ref.Ref<Tag.Tag>): void =>
|
|
|
380
379
|
*
|
|
381
380
|
* @performance O(t) in the tag count.
|
|
382
381
|
*/
|
|
383
|
-
export const removeTag = (entity: Mutable<Unknown>, tag:
|
|
382
|
+
export const removeTag = (entity: Mutable<Unknown>, tag: Tag.Tag): void => internal.removeTag(entity, tag);
|
|
384
383
|
|
|
385
384
|
//
|
|
386
385
|
// Atoms
|
package/src/Error.ts
CHANGED
|
@@ -96,3 +96,12 @@ export class GetReactiveError extends BaseError.extend(
|
|
|
96
96
|
super({ context: { reason: options.reason, snapshotId: options.snapshotId }, ...options });
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Thrown when a migration transaction cannot read or write the documents it stages.
|
|
102
|
+
*/
|
|
103
|
+
export class MigrationError extends BaseError.extend('MigrationError', 'Migration failed') {
|
|
104
|
+
constructor(context: { operation: string; id?: string }, options?: BaseErrorOptions) {
|
|
105
|
+
super({ context, ...options });
|
|
106
|
+
}
|
|
107
|
+
}
|
package/src/Feed.test.ts
CHANGED
|
@@ -2,13 +2,67 @@
|
|
|
2
2
|
// Copyright 2026 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import * as Duration from 'effect/Duration';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Exit from 'effect/Exit';
|
|
8
|
+
import * as Schema from 'effect/Schema';
|
|
5
9
|
import { describe, test } from 'vitest';
|
|
6
10
|
|
|
11
|
+
import { KEY_FEED_BLOCK, KEY_FEED_BRANCH, KEY_FEED_FORK, KEY_FEED_PREV } from '@dxos/echo-protocol';
|
|
12
|
+
|
|
7
13
|
import * as Feed from './Feed.ts';
|
|
8
14
|
import * as Obj from './Obj.ts';
|
|
9
15
|
import { TestSchema } from './testing/index.ts';
|
|
10
16
|
|
|
11
17
|
describe('Feed', () => {
|
|
18
|
+
describe('options', () => {
|
|
19
|
+
test('RetentionOptions accepts either limit, both, or neither', ({ expect }) => {
|
|
20
|
+
const decode = Schema.decodeUnknownExit(Feed.RetentionOptions);
|
|
21
|
+
expect(Exit.isSuccess(decode({}))).toBe(true);
|
|
22
|
+
expect(Exit.isSuccess(decode({ maxLength: 1 }))).toBe(true);
|
|
23
|
+
expect(Exit.isSuccess(decode({ maxAge: 1_000 }))).toBe(true);
|
|
24
|
+
expect(Exit.isSuccess(decode({ maxLength: 100, maxAge: 1_000 }))).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('RetentionOptions rejects a length below 1, a fractional length, and a non-positive age', ({ expect }) => {
|
|
28
|
+
const decode = Schema.decodeUnknownExit(Feed.RetentionOptions);
|
|
29
|
+
expect(Exit.isFailure(decode({ maxLength: 0 }))).toBe(true);
|
|
30
|
+
expect(Exit.isFailure(decode({ maxLength: 1.5 }))).toBe(true);
|
|
31
|
+
expect(Exit.isFailure(decode({ maxAge: 0 }))).toBe(true);
|
|
32
|
+
expect(Exit.isFailure(decode({ maxAge: -1 }))).toBe(true);
|
|
33
|
+
expect(Exit.isFailure(decode({ maxAge: Number.POSITIVE_INFINITY }))).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('FeedOptions round-trips through JSON', ({ expect }) => {
|
|
37
|
+
const options: Feed.FeedOptions = { indexing: { enabled: false }, retention: { maxLength: 5 } };
|
|
38
|
+
const codec = Schema.fromJsonString(Feed.FeedOptions);
|
|
39
|
+
expect(Schema.decodeUnknownSync(codec)(Schema.encodeSync(codec)(options))).toEqual(options);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('setRetention stores maxAge in milliseconds', ({ expect }) => {
|
|
43
|
+
const feed = Feed.make({ name: 'log' });
|
|
44
|
+
Effect.runSync(Feed.setRetention(feed, { maxLength: 100, maxAge: Duration.days(7) }));
|
|
45
|
+
expect(feed.retention).toEqual({ maxLength: 100, maxAge: Duration.toMillis(Duration.days(7)) });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('setRetention with an invalid value fails and leaves the object unchanged', ({ expect }) => {
|
|
49
|
+
const feed = Feed.make({ name: 'log' });
|
|
50
|
+
Effect.runSync(Feed.setRetention(feed, { maxLength: 10 }));
|
|
51
|
+
expect(Exit.isFailure(Effect.runSyncExit(Feed.setRetention(feed, { maxLength: 0 })))).toBe(true);
|
|
52
|
+
expect(Exit.isFailure(Effect.runSyncExit(Feed.setRetention(feed, { maxAge: Duration.millis(-1) })))).toBe(true);
|
|
53
|
+
expect(Exit.isFailure(Effect.runSyncExit(Feed.setRetention(feed, { maxAge: Duration.infinity })))).toBe(true);
|
|
54
|
+
expect(feed.retention).toEqual({ maxLength: 10 });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('setIndexing writes the indexing field', ({ expect }) => {
|
|
58
|
+
const feed = Feed.make({ name: 'log' });
|
|
59
|
+
expect(feed.indexing).toBeUndefined();
|
|
60
|
+
Effect.runSync(Feed.setIndexing(feed, { enabled: false }));
|
|
61
|
+
expect(feed.indexing).toEqual({ enabled: false });
|
|
62
|
+
expect(Obj.toJSON(feed)).toMatchObject({ indexing: { enabled: false } });
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
12
66
|
describe('getParent / setParent', () => {
|
|
13
67
|
test('an item has no explicit parent by default', ({ expect }) => {
|
|
14
68
|
expect(Feed.getParent(Obj.make(TestSchema.Task, { title: 'm1' }))).toBeUndefined();
|
|
@@ -206,6 +260,112 @@ describe('Feed', () => {
|
|
|
206
260
|
});
|
|
207
261
|
});
|
|
208
262
|
});
|
|
263
|
+
|
|
264
|
+
describe('branches', () => {
|
|
265
|
+
type Stamp = { block: string; branch?: string; fork?: boolean; prev?: string };
|
|
266
|
+
|
|
267
|
+
// Puts on each item the keys the store stamps on read, as if it was read from the block in its stamp.
|
|
268
|
+
const read = (...stamps: [string, Stamp][]) =>
|
|
269
|
+
stamps.map(([title, stamp]) =>
|
|
270
|
+
Obj.make(TestSchema.Task, {
|
|
271
|
+
title,
|
|
272
|
+
[Obj.Meta]: {
|
|
273
|
+
keys: [
|
|
274
|
+
{ source: KEY_FEED_BLOCK, id: stamp.block },
|
|
275
|
+
...(stamp.branch !== undefined ? [{ source: KEY_FEED_BRANCH, id: stamp.branch }] : []),
|
|
276
|
+
...(stamp.prev !== undefined ? [{ source: KEY_FEED_PREV, id: stamp.prev }] : []),
|
|
277
|
+
...(stamp.prev !== undefined && stamp.fork ? [{ source: KEY_FEED_FORK, id: stamp.prev }] : []),
|
|
278
|
+
],
|
|
279
|
+
},
|
|
280
|
+
}),
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
test('an item read from a root block has no branch and no fork flag', ({ expect }) => {
|
|
284
|
+
const [a1] = read(['a1', { block: '0@a' }]);
|
|
285
|
+
expect(Feed.getBranch(a1)).toBeUndefined();
|
|
286
|
+
expect(Feed.isFork(a1)).toBe(false);
|
|
287
|
+
expect(Feed.getBlockId(a1)).toBe('0@a');
|
|
288
|
+
expect(Feed.getPredecessor(a1)).toBeUndefined();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test('a base item names its own branch, and its predecessor is the fork point', ({ expect }) => {
|
|
292
|
+
const [b1, b2] = read(
|
|
293
|
+
['b1', { block: '2@a', branch: '2@a', fork: true, prev: '0@a' }],
|
|
294
|
+
['b2', { block: '3@a', branch: '2@a', prev: '2@a' }],
|
|
295
|
+
);
|
|
296
|
+
expect(Feed.getBranch(b1)).toBe('2@a');
|
|
297
|
+
expect(Feed.isFork(b1)).toBe(true);
|
|
298
|
+
expect(Feed.getPredecessor(b1)).toBe('0@a');
|
|
299
|
+
expect(Feed.getBranch(b2)).toBe('2@a');
|
|
300
|
+
expect(Feed.isFork(b2)).toBe(false);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('the local cursor of an item holds its branch and its block', ({ expect }) => {
|
|
304
|
+
const [a1, b1] = read(['a1', { block: '0@a' }], ['b1', { block: '1@a', branch: '1@a', fork: true, prev: '0@a' }]);
|
|
305
|
+
expect(Feed.getLocalCursor(a1)).toBe('|0@a');
|
|
306
|
+
expect(Feed.getLocalCursor(b1)).toBe('1@a|1@a');
|
|
307
|
+
expect(Feed.getLocalCursor(Obj.make(TestSchema.Task, { title: 'unread' }))).toBeUndefined();
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
// The worked example from the JSDoc: a branch sees its parent up to the fork point, then itself.
|
|
311
|
+
test('readBranch gives the root without branch items, and a branch its ancestors up to the fork', ({ expect }) => {
|
|
312
|
+
const log = read(
|
|
313
|
+
['a1', { block: '0@a' }],
|
|
314
|
+
['a2', { block: '1@a', prev: '0@a' }],
|
|
315
|
+
['a3', { block: '2@a', prev: '1@a' }],
|
|
316
|
+
['b1', { block: '3@a', branch: '3@a', fork: true, prev: '1@a' }],
|
|
317
|
+
['a4', { block: '4@a', prev: '2@a' }],
|
|
318
|
+
['b2', { block: '5@a', branch: '3@a', prev: '3@a' }],
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
const root = Feed.readBranch(log);
|
|
322
|
+
expect(titles(root)).toEqual(['a1', 'a2', 'a3', 'a4']);
|
|
323
|
+
expect(root.shallow).toBe(false);
|
|
324
|
+
|
|
325
|
+
const forked = Feed.readBranch(log, Feed.BranchId.make('3@a'));
|
|
326
|
+
expect(titles(forked)).toEqual(['a1', 'a2', 'b1', 'b2']);
|
|
327
|
+
expect(forked.shallow).toBe(false);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test('a nested branch cuts each ancestor at its own fork point', ({ expect }) => {
|
|
331
|
+
const log = read(
|
|
332
|
+
['a1', { block: '0@a' }],
|
|
333
|
+
['a2', { block: '1@a', prev: '0@a' }],
|
|
334
|
+
['b1', { block: '2@a', branch: '2@a', fork: true, prev: '0@a' }],
|
|
335
|
+
['a3', { block: '3@a', prev: '1@a' }],
|
|
336
|
+
['b2', { block: '4@a', branch: '2@a', prev: '2@a' }],
|
|
337
|
+
['c1', { block: '5@a', branch: '5@a', fork: true, prev: '4@a' }],
|
|
338
|
+
['b3', { block: '6@a', branch: '2@a', prev: '4@a' }],
|
|
339
|
+
['c2', { block: '7@a', branch: '5@a', prev: '5@a' }],
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
expect(titles(Feed.readBranch(log, Feed.BranchId.make('5@a')))).toEqual(['a1', 'b1', 'b2', 'c1', 'c2']);
|
|
343
|
+
expect(titles(Feed.readBranch(log, Feed.BranchId.make('2@a')))).toEqual(['a1', 'b1', 'b2', 'b3']);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
describe('shallow', () => {
|
|
347
|
+
test('a missing base returns the branch items and reports shallow', ({ expect }) => {
|
|
348
|
+
const log = read(['a1', { block: '0@a' }], ['b2', { block: '2@a', branch: '1@a', prev: '1@a' }]);
|
|
349
|
+
const branch = Feed.readBranch(log, Feed.BranchId.make('1@a'));
|
|
350
|
+
expect(titles(branch)).toEqual(['b2']);
|
|
351
|
+
expect(branch.shallow).toBe(true);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test('a missing fork point returns the branch items and reports shallow', ({ expect }) => {
|
|
355
|
+
const log = read(['b1', { block: '1@a', branch: '1@a', fork: true, prev: '0@a' }]);
|
|
356
|
+
const branch = Feed.readBranch(log, Feed.BranchId.make('1@a'));
|
|
357
|
+
expect(titles(branch)).toEqual(['b1']);
|
|
358
|
+
expect(branch.shallow).toBe(true);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test('a fork point after the base is a forward reference', ({ expect }) => {
|
|
362
|
+
const log = read(['b1', { block: '0@a', branch: '0@a', fork: true, prev: '1@a' }], ['a1', { block: '1@a' }]);
|
|
363
|
+
const branch = Feed.readBranch(log, Feed.BranchId.make('0@a'));
|
|
364
|
+
expect(titles(branch)).toEqual(['b1']);
|
|
365
|
+
expect(branch.shallow).toBe(true);
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
});
|
|
209
369
|
});
|
|
210
370
|
|
|
211
371
|
const titles = (history: Feed.History<TestSchema.Task>) => history.items.map((item) => item.title);
|