@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/src/Relation.ts
CHANGED
|
@@ -19,7 +19,6 @@ import * as entityInternal from './internal/Entity/index.ts';
|
|
|
19
19
|
import * as internal from './internal/index.ts';
|
|
20
20
|
import * as objInternal from './internal/Obj/index.ts';
|
|
21
21
|
import * as Obj from './Obj.ts';
|
|
22
|
-
import type * as Ref from './Ref.ts';
|
|
23
22
|
import type * as Tag from './Tag.ts';
|
|
24
23
|
import * as Type from './Type.ts';
|
|
25
24
|
|
|
@@ -538,9 +537,9 @@ export const deleteKeys = (entity: Mutable<Unknown>, source: string): void => in
|
|
|
538
537
|
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
539
538
|
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
540
539
|
*
|
|
541
|
-
* @performance O(t) in the tag count; dedupes by
|
|
540
|
+
* @performance O(t) in the tag count; dedupes by tag id before appending.
|
|
542
541
|
*/
|
|
543
|
-
export const addTag = (entity: Mutable<Unknown>, tag:
|
|
542
|
+
export const addTag = (entity: Mutable<Unknown>, tag: Tag.Tag): void => internal.addTag(entity, tag);
|
|
544
543
|
|
|
545
544
|
/**
|
|
546
545
|
* Remove a tag from the relation.
|
|
@@ -551,7 +550,7 @@ export const addTag = (entity: Mutable<Unknown>, tag: Ref.Ref<Tag.Tag>): void =>
|
|
|
551
550
|
*
|
|
552
551
|
* @performance O(t) in the tag count.
|
|
553
552
|
*/
|
|
554
|
-
export const removeTag = (entity: Mutable<Unknown>, tag:
|
|
553
|
+
export const removeTag = (entity: Mutable<Unknown>, tag: Tag.Tag): void => internal.removeTag(entity, tag);
|
|
555
554
|
|
|
556
555
|
/**
|
|
557
556
|
* Check if the relation is deleted.
|
package/src/Scope.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
import { type QueryAST } from '@dxos/echo-protocol';
|
|
8
8
|
|
|
9
|
+
import type * as Feed from './Feed.ts';
|
|
10
|
+
|
|
9
11
|
/**
|
|
10
12
|
* Scope targeting a space's automerge documents.
|
|
11
13
|
*
|
|
@@ -45,6 +47,26 @@ export const registry = (location: 'local' | 'remote' = 'local'): QueryAST.Regis
|
|
|
45
47
|
location,
|
|
46
48
|
});
|
|
47
49
|
|
|
50
|
+
/** Options for {@link feed}. */
|
|
51
|
+
export type FeedScopeOptions = {
|
|
52
|
+
/**
|
|
53
|
+
* Only items that are members of these branches: a branch id, or `null` for the main branch;
|
|
54
|
+
* `'all'` reads every branch. Omit to read the main branch only.
|
|
55
|
+
*
|
|
56
|
+
* The filter is by membership only: a branch's ancestor items up to its fork point are not
|
|
57
|
+
* included — read them with `Feed.readBranch` over the whole feed.
|
|
58
|
+
*/
|
|
59
|
+
branches?: ReadonlyArray<Feed.BranchId | null> | 'all';
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Reads the feed as a walk along the path from the root branch to `branch`, in local order; select
|
|
63
|
+
* with {@link Filter.feedCursor} to start after a local cursor and order with `Order.natural` for the
|
|
64
|
+
* direction. `'all'` walks every branch in local order. `forks` also gives the base item of each
|
|
65
|
+
* branch that forks at a block the walk gives.
|
|
66
|
+
*/
|
|
67
|
+
walk?: { branch?: Feed.BranchId | null | 'all'; forks?: boolean };
|
|
68
|
+
};
|
|
69
|
+
|
|
48
70
|
/**
|
|
49
71
|
* Scope targeting a specific feed (by its underlying queue EID).
|
|
50
72
|
*
|
|
@@ -54,11 +76,31 @@ export const registry = (location: 'local' | 'remote' = 'local'): QueryAST.Regis
|
|
|
54
76
|
* @example
|
|
55
77
|
* ```ts
|
|
56
78
|
* db.query(Query.select(Filter.feedCursor(cursor)).from(Scope.feed(feedUri)));
|
|
79
|
+
* db.query(Query.select(Filter.everything()).from(Scope.feed(feedUri, { branches: [null] })));
|
|
80
|
+
*
|
|
81
|
+
* // Walk the root branch and then the branch, 50 items at a time.
|
|
82
|
+
* db.query(
|
|
83
|
+
* Query.select(Filter.feedCursor({ begin: cursor, positions: 'local' }))
|
|
84
|
+
* .from(Scope.feed(feedUri, { walk: { branch } }))
|
|
85
|
+
* .orderBy(Order.natural('asc'))
|
|
86
|
+
* .limit(50),
|
|
87
|
+
* );
|
|
57
88
|
* ```
|
|
58
89
|
*
|
|
59
90
|
* @performance O(1); builds a scope node.
|
|
60
91
|
*/
|
|
61
|
-
export const feed = (feedUri: string): QueryAST.FeedScope => ({
|
|
92
|
+
export const feed = (feedUri: string, options?: FeedScopeOptions): QueryAST.FeedScope => ({
|
|
62
93
|
_tag: 'feed',
|
|
63
94
|
feedUri,
|
|
95
|
+
...(options?.branches === undefined
|
|
96
|
+
? {}
|
|
97
|
+
: { branches: options.branches === 'all' ? ('all' as const) : [...options.branches] }),
|
|
98
|
+
...(options?.walk === undefined
|
|
99
|
+
? {}
|
|
100
|
+
: {
|
|
101
|
+
walk: {
|
|
102
|
+
...(options.walk.branch !== undefined ? { branch: options.walk.branch } : {}),
|
|
103
|
+
...(options.walk.forks !== undefined ? { forks: options.walk.forks } : {}),
|
|
104
|
+
},
|
|
105
|
+
}),
|
|
64
106
|
});
|
package/src/Tag.md
CHANGED
|
@@ -22,17 +22,16 @@ Helpers on the same module:
|
|
|
22
22
|
|
|
23
23
|
Three ways an object can carry tags. Pick the one that matches your storage shape:
|
|
24
24
|
|
|
25
|
-
### 1. `Obj.getMeta(obj).tags` —
|
|
25
|
+
### 1. `Obj.getMeta(obj).tags` — `Tag` objects on the object's metadata
|
|
26
26
|
|
|
27
|
-
The canonical user-tagging path. Each tag lives as a standalone `Tag` object in the space; the _target_ object holds an array of
|
|
27
|
+
The canonical user-tagging path. Each tag lives as a standalone `Tag` object in the space; the _target_ object's metadata holds an editable array of those `Tag` objects. They are strong dependencies, like a parent or a relation's endpoints: persisted as references, loaded with the object, and an object whose tags are not available is not surfaced by queries. Deleting a tag does not delete the objects that carry it; the deleted tag stays in their arrays (filter with `Obj.isDeleted`). The form layer's [`ObjectProperties`](../../ui/react-ui-form/src/components/ObjectProperties) writes these via the `pinnedTags` control.
|
|
28
28
|
|
|
29
29
|
Use when: the target object is mutable. Tags can be added/removed cheaply by editing the metadata.
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
|
-
const tag =
|
|
33
|
-
|
|
34
|
-
Obj.
|
|
35
|
-
Obj.getMeta(t).tags = [tag.dxn];
|
|
32
|
+
const tag = db.add(Tag.make({ label: 'important', hue: 'amber' }));
|
|
33
|
+
Obj.update(target, (target) => {
|
|
34
|
+
Obj.addTag(target, tag); // Or edit the array: `Obj.getMeta(target).tags.push(tag)`.
|
|
36
35
|
});
|
|
37
36
|
```
|
|
38
37
|
|
package/src/Tag.ts
CHANGED
|
@@ -15,10 +15,11 @@ import * as Obj from './Obj.ts';
|
|
|
15
15
|
import * as Type from './Type.ts';
|
|
16
16
|
|
|
17
17
|
export class Tag extends Type.makeObject<Tag>(internal.TagTypeDXN)(
|
|
18
|
-
|
|
18
|
+
{
|
|
19
19
|
label: Schema.String,
|
|
20
20
|
hue: Schema.optional(Schema.String), // TODO(burdon): Color name?
|
|
21
|
-
}
|
|
21
|
+
},
|
|
22
|
+
internal.LabelAnnotation.set(['label']),
|
|
22
23
|
) {}
|
|
23
24
|
|
|
24
25
|
/**
|
package/src/Type.test.ts
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
// Copyright 2026 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { flow } from 'effect/Function';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
5
7
|
import * as Schema from 'effect/Schema';
|
|
6
8
|
import { describe, test } from 'vitest';
|
|
7
9
|
|
|
8
10
|
import { DXN, EntityId } from '@dxos/keys';
|
|
9
11
|
|
|
12
|
+
import * as Annotation from './Annotation.ts';
|
|
10
13
|
import * as Entity from './Entity.ts';
|
|
11
14
|
import * as Filter from './Filter.ts';
|
|
12
15
|
import * as JsonSchema from './JsonSchema.ts';
|
|
@@ -282,4 +285,53 @@ describe('Type', () => {
|
|
|
282
285
|
expect(filter).toBeDefined();
|
|
283
286
|
});
|
|
284
287
|
});
|
|
288
|
+
|
|
289
|
+
// Type-level behavior is covered by `Type.tst.ts`.
|
|
290
|
+
describe('makeObject with struct fields', () => {
|
|
291
|
+
test('builds the struct and applies the annotations', ({ expect }) => {
|
|
292
|
+
class Labeled extends Type.makeObject<Labeled>(DXN.make('com.example.type.labeled', '0.1.0'))(
|
|
293
|
+
{ label: Schema.String },
|
|
294
|
+
flow(Annotation.LabelAnnotation.set(['label']), Annotation.DescriptionAnnotation.set('A labeled type.')),
|
|
295
|
+
) {}
|
|
296
|
+
|
|
297
|
+
const obj = Obj.make(Labeled, { label: 'Hello' });
|
|
298
|
+
expect(obj.label).toBe('Hello');
|
|
299
|
+
expect(Obj.getLabel(obj)).toBe('Hello');
|
|
300
|
+
expect(Option.getOrUndefined(Annotation.DescriptionAnnotation.get(Type.getSchema(Labeled)))).toBe(
|
|
301
|
+
'A labeled type.',
|
|
302
|
+
);
|
|
303
|
+
expect(Type.getTypename(Labeled)).toBe('com.example.type.labeled');
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test('accepts fields without an annotate function', ({ expect }) => {
|
|
307
|
+
class Plain extends Type.makeObject<Plain>(DXN.make('com.example.type.plain', '0.1.0'))({
|
|
308
|
+
name: Schema.String,
|
|
309
|
+
}) {}
|
|
310
|
+
|
|
311
|
+
expect(Obj.make(Plain, { name: 'Test' }).name).toBe('Test');
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe('makeRelation with struct fields', () => {
|
|
316
|
+
test('builds the struct and applies the annotations', ({ expect }) => {
|
|
317
|
+
class Employs extends Type.makeRelation<Employs>(DXN.make('com.example.type.employs', '0.1.0'))({
|
|
318
|
+
source: TestSchema.Organization,
|
|
319
|
+
target: TestSchema.Person,
|
|
320
|
+
})(
|
|
321
|
+
{ role: Schema.String },
|
|
322
|
+
flow(Annotation.LabelAnnotation.set(['role']), Annotation.DescriptionAnnotation.set('Employs a person.')),
|
|
323
|
+
) {}
|
|
324
|
+
|
|
325
|
+
const org = Obj.make(TestSchema.Organization, { name: 'DXOS' });
|
|
326
|
+
const person = Obj.make(TestSchema.Person, { name: 'Alice' });
|
|
327
|
+
const rel = Relation.make(Employs, { [Relation.Source]: org, [Relation.Target]: person, role: 'Engineer' });
|
|
328
|
+
expect(rel.role).toBe('Engineer');
|
|
329
|
+
expect(Relation.getSource(rel)).toBe(org);
|
|
330
|
+
expect(Relation.getTarget(rel)).toBe(person);
|
|
331
|
+
expect(Option.getOrUndefined(Annotation.LabelAnnotation.get(Type.getSchema(Employs)))).toEqual(['role']);
|
|
332
|
+
expect(Option.getOrUndefined(Annotation.DescriptionAnnotation.get(Type.getSchema(Employs)))).toBe(
|
|
333
|
+
'Employs a person.',
|
|
334
|
+
);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
285
337
|
});
|
package/src/Type.ts
CHANGED
|
@@ -126,11 +126,19 @@ export type AnyObj = Obj<unknown>;
|
|
|
126
126
|
* declaration emit: structural expansion (which can pull in unnameable union
|
|
127
127
|
* members from referenced schemas) is replaced by a reference to the class.
|
|
128
128
|
*
|
|
129
|
+
* The second call takes either a schema, or struct fields (wrapped in `Schema.Struct`) with an optional function
|
|
130
|
+
* that pipes annotations onto the struct.
|
|
131
|
+
*
|
|
129
132
|
* @example
|
|
130
133
|
* ```ts
|
|
131
134
|
* export class Person extends Type.makeObject<Person>(DXN.make('com.example.type.myType', '0.1.0'))(Schema.Struct({
|
|
132
135
|
* name: Schema.String,
|
|
133
136
|
* })) {}
|
|
137
|
+
*
|
|
138
|
+
* export class Tag extends Type.makeObject<Tag>(DXN.make('com.example.type.tag', '0.1.0'))(
|
|
139
|
+
* { label: Schema.String },
|
|
140
|
+
* Annotation.LabelAnnotation.set(['label']),
|
|
141
|
+
* ) {}
|
|
134
142
|
* ```
|
|
135
143
|
*
|
|
136
144
|
* @performance O(schema size) once at definition time; builds the type entity eagerly, so call it at module scope, not
|
|
@@ -138,13 +146,42 @@ export type AnyObj = Obj<unknown>;
|
|
|
138
146
|
*/
|
|
139
147
|
// TODO(burdon): Require { typename, version } in options.
|
|
140
148
|
export const makeObject: {
|
|
141
|
-
<Self>(
|
|
142
|
-
dxn: DXN.DXN,
|
|
143
|
-
options?: { id?: EntityId },
|
|
144
|
-
): <_Schema extends Schema.Top>(schema: _Schema) => ObjClass<Self, Schema.Schema.Type<_Schema>, {}>;
|
|
149
|
+
<Self>(dxn: DXN.DXN, options?: { id?: EntityId }): MakeObject<Self>;
|
|
145
150
|
// Boundary cast: overload implementation bodies cannot access outer generic params (`Self`),
|
|
146
151
|
// so TypeScript cannot verify that makeObjectType's return matches the declared ObjClass<Self,…>.
|
|
147
|
-
} = (dxn, options) =>
|
|
152
|
+
} = (dxn, options) =>
|
|
153
|
+
((input: Schema.Top | Schema.Struct.Fields, annotate?: (schema: Schema.Top) => Schema.Top) =>
|
|
154
|
+
internal.makeObjectType(dxn, buildSchema(input, annotate), options)) as any;
|
|
155
|
+
|
|
156
|
+
/** Wraps struct fields in `Schema.Struct` and applies the optional annotate function. */
|
|
157
|
+
const buildSchema = (
|
|
158
|
+
input: Schema.Top | Schema.Struct.Fields,
|
|
159
|
+
annotate?: (schema: Schema.Top) => Schema.Top,
|
|
160
|
+
): Schema.Top => {
|
|
161
|
+
const schema = Schema.isSchema(input) ? input : Schema.Struct(input);
|
|
162
|
+
return annotate ? annotate(schema) : schema;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Second stage of {@link makeObject}: takes a schema, or struct fields plus an optional annotation pipe.
|
|
167
|
+
*/
|
|
168
|
+
// A single generic signature (not overloads) so that `Schema.Struct(...).pipe(Type.makeObject(dxn))` still infers.
|
|
169
|
+
export type MakeObject<Self> = <
|
|
170
|
+
const Input extends Schema.Top | Schema.Struct.Fields,
|
|
171
|
+
_Schema extends Schema.Top = ToSchema<Input>,
|
|
172
|
+
>(
|
|
173
|
+
input: Input,
|
|
174
|
+
annotate?: (schema: ToSchema<Input>) => _Schema,
|
|
175
|
+
) => ObjClass<Self, Schema.Schema.Type<_Schema>, {}>;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Schema for the input of {@link MakeObject} / {@link MakeRelation}: a schema as is, or struct fields wrapped in `Schema.Struct`.
|
|
179
|
+
*/
|
|
180
|
+
export type ToSchema<Input> = Input extends Schema.Top
|
|
181
|
+
? Input
|
|
182
|
+
: Input extends Schema.Struct.Fields
|
|
183
|
+
? Schema.Struct<Input>
|
|
184
|
+
: never;
|
|
148
185
|
|
|
149
186
|
//
|
|
150
187
|
// Type — the ECHO entity that holds a schema and metadata.
|
|
@@ -305,6 +342,11 @@ export type AnyRelation = Relation<unknown, unknown, unknown>;
|
|
|
305
342
|
* class WorksFor extends Type.makeRelation<WorksFor>(DXN.make('com.example.type.worksFor', '0.1.0'))(
|
|
306
343
|
* { source: Person, target: Company },
|
|
307
344
|
* )(Schema.Struct({ role: Schema.String })) {}
|
|
345
|
+
*
|
|
346
|
+
* // Like `makeObject`, the last call also takes struct fields and an optional annotate function.
|
|
347
|
+
* class Employs extends Type.makeRelation<Employs>(DXN.make('com.example.type.employs', '0.1.0'))(
|
|
348
|
+
* { source: Company, target: Person },
|
|
349
|
+
* )({ role: Schema.String }, Annotation.LabelAnnotation.set(['role'])) {}
|
|
308
350
|
* ```
|
|
309
351
|
*
|
|
310
352
|
* @performance O(schema size) once at definition time; builds the type entity eagerly, so call it at module scope, not
|
|
@@ -319,25 +361,36 @@ export const makeRelation: {
|
|
|
319
361
|
* see `Type.makeObject` for the workerd motivation.
|
|
320
362
|
*/
|
|
321
363
|
id?: EntityId;
|
|
322
|
-
}) => <
|
|
323
|
-
|
|
324
|
-
) => RelationClass<
|
|
325
|
-
Self,
|
|
326
|
-
Schema.Schema.Type<_Schema>,
|
|
327
|
-
SourceInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>,
|
|
328
|
-
TargetInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>,
|
|
329
|
-
{}
|
|
330
|
-
>;
|
|
331
|
-
} = (dxn) => (opts) => (schema) =>
|
|
364
|
+
}) => MakeRelation<Self, SourceInstance, TargetInstance>;
|
|
365
|
+
} = (dxn) => (opts) =>
|
|
332
366
|
// Boundary cast: makeRelationType erases generic params since the constructor/prototype
|
|
333
367
|
// wiring cannot thread them through the type system.
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
368
|
+
((input: Schema.Top | Schema.Struct.Fields, annotate?: (schema: Schema.Top) => Schema.Top) =>
|
|
369
|
+
internal.makeRelationType({
|
|
370
|
+
dxn,
|
|
371
|
+
source: opts.source,
|
|
372
|
+
target: opts.target,
|
|
373
|
+
schema: buildSchema(input, annotate),
|
|
374
|
+
id: opts.id,
|
|
375
|
+
})) as any;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Last stage of {@link makeRelation}: takes a schema, or struct fields plus an optional annotation pipe.
|
|
379
|
+
*/
|
|
380
|
+
// A single generic signature (not overloads); see {@link MakeObject}.
|
|
381
|
+
export type MakeRelation<Self, SourceInstance, TargetInstance> = <
|
|
382
|
+
const Input extends Schema.Top | Schema.Struct.Fields,
|
|
383
|
+
_Schema extends Schema.Top = ToSchema<Input>,
|
|
384
|
+
>(
|
|
385
|
+
input: Input,
|
|
386
|
+
annotate?: (schema: ToSchema<Input>) => _Schema,
|
|
387
|
+
) => RelationClass<
|
|
388
|
+
Self,
|
|
389
|
+
Schema.Schema.Type<_Schema>,
|
|
390
|
+
SourceInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>,
|
|
391
|
+
TargetInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>,
|
|
392
|
+
{}
|
|
393
|
+
>;
|
|
341
394
|
|
|
342
395
|
/**
|
|
343
396
|
* Type that represents any ECHO type-kind entity — a `Type.Type` meta-schema
|
package/src/Type.tst.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { flow } from 'effect/Function';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
import { describe, expect, it } from 'tstyche';
|
|
8
|
+
|
|
9
|
+
import { DXN } from '@dxos/keys';
|
|
10
|
+
|
|
11
|
+
import * as Annotation from './Annotation.ts';
|
|
12
|
+
import * as Obj from './Obj.ts';
|
|
13
|
+
import * as Relation from './Relation.ts';
|
|
14
|
+
import { TestSchema } from './testing/index.ts';
|
|
15
|
+
import * as Type from './Type.ts';
|
|
16
|
+
|
|
17
|
+
class Labeled extends Type.makeObject<Labeled>(DXN.make('com.example.type.labeled', '0.1.0'))(
|
|
18
|
+
{
|
|
19
|
+
label: Schema.String,
|
|
20
|
+
count: Schema.optional(Schema.Number),
|
|
21
|
+
},
|
|
22
|
+
Annotation.LabelAnnotation.set(['label']),
|
|
23
|
+
) {}
|
|
24
|
+
|
|
25
|
+
class FromStruct extends Type.makeObject<FromStruct>(DXN.make('com.example.type.fromStruct', '0.1.0'))(
|
|
26
|
+
Schema.Struct({ label: Schema.String, count: Schema.optional(Schema.Number) }),
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
describe('Type.makeObject', () => {
|
|
30
|
+
it('infers the same instance type from fields as from Schema.Struct', () => {
|
|
31
|
+
expect<Type.InstanceType<typeof Labeled>>().type.toBe<Type.InstanceType<typeof FromStruct>>();
|
|
32
|
+
expect<Type.InstanceType<typeof Labeled>['label']>().type.toBe<string>();
|
|
33
|
+
expect<Type.InstanceType<typeof Labeled>['count']>().type.toBe<number | undefined>();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('accepts fields without an annotate function', () => {
|
|
37
|
+
class Plain extends Type.makeObject<Plain>(DXN.make('com.example.type.plain', '0.1.0'))({
|
|
38
|
+
name: Schema.String,
|
|
39
|
+
}) {}
|
|
40
|
+
expect<Type.InstanceType<typeof Plain>['name']>().type.toBe<string>();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('accepts several annotations composed with flow', () => {
|
|
44
|
+
class Flowed extends Type.makeObject<Flowed>(DXN.make('com.example.type.flowed', '0.1.0'))(
|
|
45
|
+
{ label: Schema.String },
|
|
46
|
+
flow(Annotation.LabelAnnotation.set(['label']), Annotation.DescriptionAnnotation.set('A flowed type.')),
|
|
47
|
+
) {}
|
|
48
|
+
expect<Type.InstanceType<typeof Flowed>['label']>().type.toBe<string>();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('accepts several annotations piped onto the struct', () => {
|
|
52
|
+
class Piped extends Type.makeObject<Piped>(DXN.make('com.example.type.piped', '0.1.0'))(
|
|
53
|
+
{ label: Schema.String },
|
|
54
|
+
(schema) =>
|
|
55
|
+
schema.pipe(Annotation.LabelAnnotation.set(['label']), Annotation.DescriptionAnnotation.set('A piped type.')),
|
|
56
|
+
) {}
|
|
57
|
+
expect<Type.InstanceType<typeof Piped>['label']>().type.toBe<string>();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('infers the instance type from a combinator that changes the schema', () => {
|
|
61
|
+
class Extended extends Type.makeObject<Extended>(DXN.make('com.example.type.extended', '0.1.0'))(
|
|
62
|
+
{ label: Schema.String },
|
|
63
|
+
flow(Schema.fieldsAssign({ extra: Schema.Number }), Annotation.LabelAnnotation.set(['label'])),
|
|
64
|
+
) {}
|
|
65
|
+
expect<Type.InstanceType<typeof Extended>['extra']>().type.toBe<number>();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('still infers when piped as a schema combinator', () => {
|
|
69
|
+
const Piped = Schema.Struct({ label: Schema.String }).pipe(
|
|
70
|
+
Type.makeObject(DXN.make('com.example.type.pipedSchema', '0.1.0')),
|
|
71
|
+
);
|
|
72
|
+
expect<Type.InstanceType<typeof Piped>['label']>().type.toBe<string>();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('passes the same struct schema to the annotate function as Schema.Struct builds', () => {
|
|
76
|
+
const struct = Schema.Struct({ name: Schema.String });
|
|
77
|
+
Type.makeObject(DXN.make('com.example.type.annotateArg', '0.1.0'))({ name: Schema.String }, (schema) => {
|
|
78
|
+
expect(schema).type.toBe<typeof struct>();
|
|
79
|
+
return schema;
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('rejects field values that are not schemas', () => {
|
|
84
|
+
expect(Type.makeObject(DXN.make('com.example.type.badField', '0.1.0'))({ name: 'not a schema' })).type.toRaiseError(
|
|
85
|
+
'is not assignable',
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('rejects an annotate function that does not return a schema', () => {
|
|
90
|
+
expect(
|
|
91
|
+
Type.makeObject(DXN.make('com.example.type.badAnnotate', '0.1.0'))({ name: Schema.String }, () => 'x'),
|
|
92
|
+
).type.toRaiseError();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('rejects props that do not match the fields', () => {
|
|
96
|
+
expect(Obj.make(Labeled, { label: 1 })).type.toRaiseError();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
class Employs extends Type.makeRelation<Employs>(DXN.make('com.example.type.employs', '0.1.0'))({
|
|
101
|
+
source: TestSchema.Organization,
|
|
102
|
+
target: TestSchema.Person,
|
|
103
|
+
})(
|
|
104
|
+
{ role: Schema.String },
|
|
105
|
+
flow(Annotation.LabelAnnotation.set(['role']), Annotation.DescriptionAnnotation.set('Employs a person.')),
|
|
106
|
+
) {}
|
|
107
|
+
|
|
108
|
+
class EmploysFromStruct extends Type.makeRelation<EmploysFromStruct>(
|
|
109
|
+
DXN.make('com.example.type.employsFromStruct', '0.1.0'),
|
|
110
|
+
)({
|
|
111
|
+
source: TestSchema.Organization,
|
|
112
|
+
target: TestSchema.Person,
|
|
113
|
+
})(Schema.Struct({ role: Schema.String })) {}
|
|
114
|
+
|
|
115
|
+
describe('Type.makeRelation', () => {
|
|
116
|
+
it('infers the same instance type from fields as from Schema.Struct', () => {
|
|
117
|
+
expect<Type.InstanceType<typeof Employs>>().type.toBe<Type.InstanceType<typeof EmploysFromStruct>>();
|
|
118
|
+
expect<Type.InstanceType<typeof Employs>['role']>().type.toBe<string>();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('keeps the source and target types', () => {
|
|
122
|
+
expect<Relation.SourceOf<Type.InstanceType<typeof Employs>>>().type.toBe<
|
|
123
|
+
Relation.SourceOf<Type.InstanceType<typeof EmploysFromStruct>>
|
|
124
|
+
>();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('accepts several annotations piped onto the struct', () => {
|
|
128
|
+
class Piped extends Type.makeRelation<Piped>(DXN.make('com.example.type.pipedRelation', '0.1.0'))({
|
|
129
|
+
source: TestSchema.Organization,
|
|
130
|
+
target: TestSchema.Person,
|
|
131
|
+
})({ role: Schema.String }, (schema) =>
|
|
132
|
+
schema.pipe(Annotation.LabelAnnotation.set(['role']), Annotation.DescriptionAnnotation.set('Piped.')),
|
|
133
|
+
) {}
|
|
134
|
+
expect<Type.InstanceType<typeof Piped>['role']>().type.toBe<string>();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('still infers when piped as a schema combinator', () => {
|
|
138
|
+
const Piped = Schema.Struct({ role: Schema.String }).pipe(
|
|
139
|
+
Type.makeRelation(DXN.make('com.example.type.pipedRelationSchema', '0.1.0'))({
|
|
140
|
+
source: TestSchema.Organization,
|
|
141
|
+
target: TestSchema.Person,
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
expect<Type.InstanceType<typeof Piped>['role']>().type.toBe<string>();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('rejects field values that are not schemas', () => {
|
|
148
|
+
expect(
|
|
149
|
+
Type.makeRelation(DXN.make('com.example.type.badRelation', '0.1.0'))({
|
|
150
|
+
source: TestSchema.Organization,
|
|
151
|
+
target: TestSchema.Person,
|
|
152
|
+
})({ role: 'not a schema' }),
|
|
153
|
+
).type.toRaiseError('is not assignable');
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -15,11 +15,14 @@ import { EchoObjectSchema } from '../Entity/index.ts';
|
|
|
15
15
|
import {
|
|
16
16
|
LabelAnnotation,
|
|
17
17
|
PropertyMeta,
|
|
18
|
+
RawStringAnnotation,
|
|
18
19
|
SetParentAnnotation,
|
|
19
20
|
TypenameSchema,
|
|
20
21
|
VersionSchema,
|
|
22
|
+
containsRawStringAnnotation,
|
|
21
23
|
getLabelWithSchema,
|
|
22
24
|
getTypeAnnotation,
|
|
25
|
+
hasRawStringAnnotation,
|
|
23
26
|
} from './annotations.ts';
|
|
24
27
|
|
|
25
28
|
// TODO(dmaretskyi): Use one of the testing schemas.
|
|
@@ -184,3 +187,19 @@ describe('SetParentAnnotation', () => {
|
|
|
184
187
|
expect(SetParentAnnotation.get(field)).toEqual(Option.some({ value: true, override: false }));
|
|
185
188
|
});
|
|
186
189
|
});
|
|
190
|
+
|
|
191
|
+
describe('RawStringAnnotation', () => {
|
|
192
|
+
const RawRecord = Schema.Record(Schema.String, Schema.Any).pipe(RawStringAnnotation.set(true));
|
|
193
|
+
|
|
194
|
+
test('is found through an optional wrapper', ({ expect }) => {
|
|
195
|
+
const struct = Schema.Struct({ snapshots: RawRecord.pipe(Schema.optional) });
|
|
196
|
+
const [property] = struct.ast.propertySignatures;
|
|
197
|
+
expect(hasRawStringAnnotation(property.type)).toBe(true);
|
|
198
|
+
expect(hasRawStringAnnotation(Schema.String.ast)).toBe(false);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('containment covers nested fields and is false for schemas without it', ({ expect }) => {
|
|
202
|
+
expect(containsRawStringAnnotation(Schema.Struct({ spec: Schema.Struct({ cache: RawRecord }) }).ast)).toBe(true);
|
|
203
|
+
expect(containsRawStringAnnotation(Schema.Struct({ title: Schema.String }).ast)).toBe(false);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -427,7 +427,8 @@ export const FormOrderedAnnotationId = '@dxos/schema/annotation/FormOrdered';
|
|
|
427
427
|
export const FormOrderedAnnotation = createAnnotationHelper<boolean>(FormOrderedAnnotationId);
|
|
428
428
|
|
|
429
429
|
/**
|
|
430
|
-
* How a form presents an array of references
|
|
430
|
+
* How a form presents an array of references, or (`tag` only) of the values its element's `OptionsLookup` offers. The
|
|
431
|
+
* two options are independent.
|
|
431
432
|
*/
|
|
432
433
|
export type ArrayPresentation = {
|
|
433
434
|
/** Rows (or chips) reorder by drag and keyboard, and the order is persisted; `false` by default. */
|
|
@@ -500,6 +501,47 @@ export type GeneratorAnnotationValue =
|
|
|
500
501
|
|
|
501
502
|
export const GeneratorAnnotation = createAnnotationHelper<GeneratorAnnotationValue>(GeneratorAnnotationId);
|
|
502
503
|
|
|
504
|
+
export const RawStringAnnotationId = 'org.dxos.annotation.rawString';
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Stores every string under the annotated field as an immutable Automerge string: one op per write
|
|
508
|
+
* instead of one per character, at the cost of collaborative (character-level) merging. For
|
|
509
|
+
* machine-written state that is replaced wholesale, never edited as text.
|
|
510
|
+
*/
|
|
511
|
+
export const RawStringAnnotation = createAnnotationHelper<boolean>(RawStringAnnotationId);
|
|
512
|
+
|
|
513
|
+
/** True when `ast` (or, for an optional field, one of its union members) carries {@link RawStringAnnotation}. */
|
|
514
|
+
export const hasRawStringAnnotation = (ast: SchemaAST.AST): boolean =>
|
|
515
|
+
RawStringAnnotation.getFromAst(ast).pipe(Option.getOrElse(() => false)) ||
|
|
516
|
+
(SchemaAST.isUnion(ast) && ast.types.some(hasRawStringAnnotation));
|
|
517
|
+
|
|
518
|
+
const containsRawStringCache = new WeakMap<SchemaAST.AST, boolean>();
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* True when {@link RawStringAnnotation} appears anywhere within `ast`; cached, so a write to a type that
|
|
522
|
+
* never uses it skips the per-value schema walk.
|
|
523
|
+
*/
|
|
524
|
+
export const containsRawStringAnnotation = (ast: SchemaAST.AST): boolean => {
|
|
525
|
+
const cached = containsRawStringCache.get(ast);
|
|
526
|
+
if (cached !== undefined) {
|
|
527
|
+
return cached;
|
|
528
|
+
}
|
|
529
|
+
// Seeded before descending so a recursive (suspended) schema terminates.
|
|
530
|
+
containsRawStringCache.set(ast, false);
|
|
531
|
+
const children: readonly SchemaAST.AST[] = SchemaAST.isObjects(ast)
|
|
532
|
+
? [...ast.propertySignatures.map((property) => property.type), ...ast.indexSignatures.map((index) => index.type)]
|
|
533
|
+
: SchemaAST.isArrays(ast)
|
|
534
|
+
? [...ast.elements, ...ast.rest]
|
|
535
|
+
: SchemaAST.isUnion(ast)
|
|
536
|
+
? ast.types
|
|
537
|
+
: SchemaAST.isSuspend(ast)
|
|
538
|
+
? [ast.thunk()]
|
|
539
|
+
: [];
|
|
540
|
+
const result = hasRawStringAnnotation(ast) || children.some(containsRawStringAnnotation);
|
|
541
|
+
containsRawStringCache.set(ast, result);
|
|
542
|
+
return result;
|
|
543
|
+
};
|
|
544
|
+
|
|
503
545
|
interface MakeAnnoationsProps<T> {
|
|
504
546
|
id: string;
|
|
505
547
|
schema: Schema.Codec<T, any, never>;
|
|
@@ -650,6 +692,30 @@ export const SetParentAnnotation: Omit<Annotation.Annotation<SetParentAnnotation
|
|
|
650
692
|
set: ({ override = true }: SetParentAnnotationOptions = {}) => setParentAnnotation.set({ value: true, override }),
|
|
651
693
|
};
|
|
652
694
|
|
|
695
|
+
/** Value of {@link ContentVersionAnnotation}. */
|
|
696
|
+
export type ContentVersionAnnotationValue = {
|
|
697
|
+
/** Sibling fields whose format the annotated field versions. */
|
|
698
|
+
readonly fields: readonly string[];
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Marks a string field of an object schema as the content version of named sibling fields: the
|
|
703
|
+
* format and revision (e.g. `dxos.org/scene/1`) of data ECHO stores opaquely. Content migrations
|
|
704
|
+
* (`Migration.defineContent`) find the version through it.
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```ts
|
|
708
|
+
* Schema.Struct({
|
|
709
|
+
* schema: Schema.String.pipe(Annotation.ContentVersionAnnotation.set({ fields: ['content'] }), Schema.optional),
|
|
710
|
+
* content: Schema.Record(Schema.String, Schema.Any),
|
|
711
|
+
* })
|
|
712
|
+
* ```
|
|
713
|
+
*/
|
|
714
|
+
export const ContentVersionAnnotation = makeUserAnnotation<ContentVersionAnnotationValue>({
|
|
715
|
+
id: 'org.dxos.annotation.contentVersion',
|
|
716
|
+
schema: Schema.Struct({ fields: Schema.Array(Schema.String) }),
|
|
717
|
+
});
|
|
718
|
+
|
|
653
719
|
/** Value of {@link UserTypeAnnotation}. */
|
|
654
720
|
export type UserTypeAnnotationValue = {
|
|
655
721
|
/** Keys a surface filters on (e.g. which types a collection's create dialog offers); opaque to ECHO. */
|