@dxos/echo 0.8.4-main.72ec0f3 → 0.8.4-main.7ace549
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{chunk-BIDAASFK.mjs → chunk-7GH6RXJ3.mjs} +2246 -2290
- package/dist/lib/browser/chunk-7GH6RXJ3.mjs.map +7 -0
- package/dist/lib/browser/chunk-E4UTVJNF.mjs +1111 -0
- package/dist/lib/browser/chunk-E4UTVJNF.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +18 -8
- package/dist/lib/browser/internal/index.mjs +45 -45
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +252 -191
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/chunk-JE5RXM2I.mjs +1111 -0
- package/dist/lib/node-esm/chunk-JE5RXM2I.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-3SVRRCUU.mjs → chunk-M4B6BMD2.mjs} +2246 -2290
- package/dist/lib/node-esm/chunk-M4B6BMD2.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +18 -8
- package/dist/lib/node-esm/internal/index.mjs +45 -45
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +252 -191
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/Annotation.d.ts +2 -0
- package/dist/types/src/Annotation.d.ts.map +1 -0
- package/dist/types/src/Database.d.ts +137 -0
- package/dist/types/src/Database.d.ts.map +1 -0
- package/dist/types/src/Entity.d.ts +36 -0
- package/dist/types/src/Entity.d.ts.map +1 -0
- package/dist/types/src/Format.d.ts +4 -0
- package/dist/types/src/Format.d.ts.map +1 -0
- package/dist/types/src/JsonSchema.d.ts +9 -0
- package/dist/types/src/JsonSchema.d.ts.map +1 -0
- package/dist/types/src/Key.d.ts +1 -0
- package/dist/types/src/Key.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +79 -70
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +10 -10
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +14 -11
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Tag.d.ts +1 -1
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +39 -49
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +6 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/annotations/annotations.d.ts +174 -0
- package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/annotations.test.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/index.d.ts +3 -0
- package/dist/types/src/internal/annotations/index.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/util.d.ts +26 -0
- package/dist/types/src/internal/annotations/util.d.ts.map +1 -0
- package/dist/types/src/internal/entities/entity.d.ts +10 -0
- package/dist/types/src/internal/entities/entity.d.ts.map +1 -0
- package/dist/types/src/internal/{object → entities}/expando.d.ts +3 -1
- package/dist/types/src/internal/entities/expando.d.ts.map +1 -0
- package/dist/types/src/internal/entities/index.d.ts +6 -0
- package/dist/types/src/internal/entities/index.d.ts.map +1 -0
- package/dist/types/src/internal/entities/model.d.ts +70 -0
- package/dist/types/src/internal/entities/model.d.ts.map +1 -0
- package/dist/types/src/internal/entities/object.d.ts +11 -0
- package/dist/types/src/internal/entities/object.d.ts.map +1 -0
- package/dist/types/src/internal/entities/relation.d.ts +55 -0
- package/dist/types/src/internal/entities/relation.d.ts.map +1 -0
- package/dist/types/src/internal/entities/util.d.ts +2 -0
- package/dist/types/src/internal/entities/util.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.d.ts +2 -0
- package/dist/types/src/internal/formats/format.d.ts.map +1 -1
- package/dist/types/src/internal/formats/types.d.ts +7 -7
- package/dist/types/src/internal/formats/types.d.ts.map +1 -1
- package/dist/types/src/internal/index.d.ts +6 -10
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/src/internal/json-schema/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/index.d.ts +2 -0
- package/dist/types/src/internal/json-schema/index.d.ts.map +1 -1
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -1
- package/dist/types/src/internal/{json → json-schema}/json-schema.d.ts +2 -1
- package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/common.d.ts.map +1 -1
- package/dist/types/src/internal/object/{create.d.ts → create-object.d.ts} +8 -9
- package/dist/types/src/internal/object/create-object.d.ts.map +1 -0
- package/dist/types/src/internal/object/create-object.test.d.ts +2 -0
- package/dist/types/src/internal/object/create-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/deleted.d.ts +2 -2
- package/dist/types/src/internal/object/deleted.d.ts.map +1 -1
- package/dist/types/src/internal/object/ids.d.ts.map +1 -1
- package/dist/types/src/internal/object/index.d.ts +3 -11
- package/dist/types/src/internal/object/index.d.ts.map +1 -1
- package/dist/types/src/internal/object/json-serializer.d.ts +1 -2
- package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -1
- package/dist/types/src/internal/object/typed-object.d.ts +1 -1
- package/dist/types/src/internal/object/typed-object.d.ts.map +1 -1
- package/dist/types/src/internal/proxy/index.d.ts +3 -0
- package/dist/types/src/internal/proxy/index.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/make-object.d.ts +16 -0
- package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts +1 -1
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -1
- package/dist/types/src/internal/ref/ref.d.ts +15 -12
- package/dist/types/src/internal/ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/schema/compose.d.ts.map +1 -0
- package/dist/types/src/internal/schema/compose.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts +9 -9
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -1
- package/dist/types/src/internal/schema/index.d.ts +3 -4
- package/dist/types/src/internal/schema/index.d.ts.map +1 -1
- package/dist/types/src/internal/schema/persistent-schema.d.ts +18 -0
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -0
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts +1 -1
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts.map +1 -1
- package/dist/types/src/internal/types/base.d.ts +37 -0
- package/dist/types/src/internal/types/base.d.ts.map +1 -0
- package/dist/types/src/internal/{ast/entity-kind.d.ts → types/entity.d.ts} +3 -1
- package/dist/types/src/internal/types/entity.d.ts.map +1 -0
- package/dist/types/src/internal/types/index.d.ts +5 -2
- package/dist/types/src/internal/types/index.d.ts.map +1 -1
- package/dist/types/src/internal/{object → types}/meta.d.ts +20 -11
- package/dist/types/src/internal/types/meta.d.ts.map +1 -0
- package/dist/types/src/internal/types/typename.d.ts +13 -0
- package/dist/types/src/internal/types/typename.d.ts.map +1 -0
- package/dist/types/src/internal/{object → types}/version.d.ts +3 -2
- package/dist/types/src/internal/types/version.d.ts.map +1 -0
- package/dist/types/src/query/filter.d.ts +167 -0
- package/dist/types/src/query/filter.d.ts.map +1 -0
- package/dist/types/src/query/index.d.ts +3 -0
- package/dist/types/src/query/index.d.ts.map +1 -1
- package/dist/types/src/query/order.d.ts +12 -0
- package/dist/types/src/query/order.d.ts.map +1 -0
- package/dist/types/src/query/query.d.ts +9 -145
- package/dist/types/src/query/query.d.ts.map +1 -1
- package/dist/types/src/query/testing.d.ts +51 -0
- package/dist/types/src/query/testing.d.ts.map +1 -0
- package/dist/types/src/{internal/query/query.d.ts → query/types.d.ts} +1 -1
- package/dist/types/src/query/types.d.ts.map +1 -0
- package/dist/types/src/query/util.d.ts +8 -0
- package/dist/types/src/query/util.d.ts.map +1 -0
- package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +3 -3
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +18 -0
- package/dist/types/src/testing/test-data.d.ts.map +1 -0
- package/dist/types/src/testing/{types.d.ts → test-schema.d.ts} +166 -57
- package/dist/types/src/testing/test-schema.d.ts.map +1 -0
- package/dist/types/src/{internal/testing/utils.d.ts → testing/util.d.ts} +11 -5
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +46 -38
- package/src/Annotation.ts +17 -0
- package/src/Database.ts +189 -0
- package/src/Entity.ts +51 -0
- package/src/Format.ts +11 -0
- package/src/JsonSchema.ts +16 -0
- package/src/Key.ts +3 -0
- package/src/Obj.ts +248 -181
- package/src/Ref.ts +9 -9
- package/src/Relation.ts +58 -44
- package/src/Tag.ts +2 -1
- package/src/Type.ts +96 -83
- package/src/index.ts +9 -4
- package/src/internal/README.md +83 -0
- package/src/internal/{ast → annotations}/annotations.test.ts +13 -15
- package/src/internal/annotations/annotations.ts +463 -0
- package/src/internal/annotations/index.ts +6 -0
- package/src/internal/annotations/util.ts +70 -0
- package/src/internal/entities/entity.ts +109 -0
- package/src/internal/{object → entities}/expando.ts +7 -5
- package/src/internal/entities/index.ts +9 -0
- package/src/internal/{object → entities}/model.ts +49 -90
- package/src/internal/entities/object.ts +45 -0
- package/src/internal/entities/relation.ts +155 -0
- package/src/internal/entities/util.ts +33 -0
- package/src/internal/formats/date.test.ts +1 -1
- package/src/internal/formats/date.ts +5 -5
- package/src/internal/formats/format.test.ts +5 -5
- package/src/internal/formats/format.ts +3 -0
- package/src/internal/formats/number.ts +5 -5
- package/src/internal/formats/object.ts +2 -2
- package/src/internal/formats/string.ts +9 -9
- package/src/internal/formats/types.ts +44 -39
- package/src/internal/index.ts +29 -13
- package/src/internal/{json → json-schema}/annotations.ts +1 -1
- package/src/internal/json-schema/index.ts +2 -0
- package/src/internal/json-schema/json-schema-type.ts +4 -3
- package/src/internal/{json → json-schema}/json-schema.test.ts +48 -38
- package/src/internal/{json → json-schema}/json-schema.ts +16 -7
- package/src/internal/object/common.ts +3 -4
- package/src/internal/object/{create.test.ts → create-object.test.ts} +30 -32
- package/src/internal/object/{create.ts → create-object.ts} +33 -34
- package/src/internal/object/deleted.ts +6 -6
- package/src/internal/object/ids.ts +1 -1
- package/src/internal/object/index.ts +3 -11
- package/src/internal/object/inspect.ts +3 -5
- package/src/internal/object/json-serializer.test.ts +33 -38
- package/src/internal/object/json-serializer.ts +43 -38
- package/src/internal/object/schema-validator.ts +3 -2
- package/src/internal/object/typed-object.test.ts +1 -1
- package/src/internal/object/typed-object.ts +11 -5
- package/src/internal/proxy/handler.test.ts +30 -20
- package/src/internal/proxy/index.ts +6 -0
- package/src/internal/proxy/{reactive-object.ts → make-object.ts} +19 -14
- package/src/internal/proxy/schema.test.ts +5 -4
- package/src/internal/proxy/typed-handler.test.ts +28 -28
- package/src/internal/proxy/typed-handler.ts +8 -3
- package/src/internal/proxy/typed-object.test.ts +16 -11
- package/src/internal/ref/ref.test.ts +8 -7
- package/src/internal/ref/ref.ts +24 -20
- package/src/internal/{projection → schema}/compose.test.ts +5 -6
- package/src/internal/{projection → schema}/compose.ts +2 -1
- package/src/internal/schema/echo-schema.ts +30 -28
- package/src/internal/schema/index.ts +3 -4
- package/src/internal/schema/manipulation.ts +1 -1
- package/src/internal/schema/persistent-schema.ts +28 -0
- package/src/internal/schema/runtime-schema-registry.ts +4 -4
- package/src/internal/types/base.ts +58 -0
- package/src/internal/{ast/entity-kind.ts → types/entity.ts} +8 -0
- package/src/internal/types/index.ts +5 -2
- package/src/internal/{object → types}/meta.ts +32 -17
- package/src/internal/types/typename.ts +45 -0
- package/src/internal/types/version.ts +20 -0
- package/src/query/filter.ts +455 -0
- package/src/query/index.ts +4 -1
- package/src/query/order.ts +34 -0
- package/src/query/query.test.ts +48 -115
- package/src/query/query.ts +16 -502
- package/src/query/testing.ts +64 -0
- package/src/query/util.ts +25 -0
- package/src/testing/api.test.ts +100 -0
- package/src/testing/index.ts +3 -3
- package/src/testing/test-data.ts +130 -0
- package/src/testing/test-schema.ts +213 -0
- package/src/{internal/testing/utils.ts → testing/util.ts} +38 -14
- package/dist/lib/browser/chunk-BIDAASFK.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZDLCWGEW.mjs +0 -410
- package/dist/lib/browser/chunk-ZDLCWGEW.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZFRJKT4A.mjs +0 -585
- package/dist/lib/browser/chunk-ZFRJKT4A.mjs.map +0 -7
- package/dist/lib/browser/query/index.mjs +0 -13
- package/dist/lib/browser/query/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3SVRRCUU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CGDHRZWH.mjs +0 -585
- package/dist/lib/node-esm/chunk-CGDHRZWH.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HWS6VBQC.mjs +0 -410
- package/dist/lib/node-esm/chunk-HWS6VBQC.mjs.map +0 -7
- package/dist/lib/node-esm/query/index.mjs +0 -13
- package/dist/lib/node-esm/query/index.mjs.map +0 -7
- package/dist/types/src/internal/ast/annotation-helper.d.ts +0 -8
- package/dist/types/src/internal/ast/annotation-helper.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotations.d.ts +0 -131
- package/dist/types/src/internal/ast/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotations.test.d.ts.map +0 -1
- package/dist/types/src/internal/ast/entity-kind.d.ts.map +0 -1
- package/dist/types/src/internal/ast/index.d.ts +0 -5
- package/dist/types/src/internal/ast/index.d.ts.map +0 -1
- package/dist/types/src/internal/ast/types.d.ts +0 -6
- package/dist/types/src/internal/ast/types.d.ts.map +0 -1
- package/dist/types/src/internal/json/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/json/effect-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/json/index.d.ts +0 -2
- package/dist/types/src/internal/json/index.d.ts.map +0 -1
- package/dist/types/src/internal/json/json-schema.d.ts.map +0 -1
- package/dist/types/src/internal/json/json-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/accessors.d.ts +0 -37
- package/dist/types/src/internal/object/accessors.d.ts.map +0 -1
- package/dist/types/src/internal/object/create.d.ts.map +0 -1
- package/dist/types/src/internal/object/create.test.d.ts +0 -2
- package/dist/types/src/internal/object/create.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/entity.d.ts +0 -33
- package/dist/types/src/internal/object/entity.d.ts.map +0 -1
- package/dist/types/src/internal/object/expando.d.ts.map +0 -1
- package/dist/types/src/internal/object/meta.d.ts.map +0 -1
- package/dist/types/src/internal/object/model.d.ts +0 -117
- package/dist/types/src/internal/object/model.d.ts.map +0 -1
- package/dist/types/src/internal/object/relation.d.ts +0 -17
- package/dist/types/src/internal/object/relation.d.ts.map +0 -1
- package/dist/types/src/internal/object/typename.d.ts +0 -15
- package/dist/types/src/internal/object/typename.d.ts.map +0 -1
- package/dist/types/src/internal/object/version.d.ts.map +0 -1
- package/dist/types/src/internal/projection/compose.d.ts.map +0 -1
- package/dist/types/src/internal/projection/compose.test.d.ts.map +0 -1
- package/dist/types/src/internal/projection/index.d.ts +0 -2
- package/dist/types/src/internal/projection/index.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/reactive-object.d.ts +0 -15
- package/dist/types/src/internal/proxy/reactive-object.d.ts.map +0 -1
- package/dist/types/src/internal/query/index.d.ts +0 -2
- package/dist/types/src/internal/query/index.d.ts.map +0 -1
- package/dist/types/src/internal/query/query.d.ts.map +0 -1
- package/dist/types/src/internal/schema/stored-schema.d.ts +0 -13
- package/dist/types/src/internal/schema/stored-schema.d.ts.map +0 -1
- package/dist/types/src/internal/testing/index.d.ts +0 -3
- package/dist/types/src/internal/testing/index.d.ts.map +0 -1
- package/dist/types/src/internal/testing/types.d.ts +0 -381
- package/dist/types/src/internal/testing/types.d.ts.map +0 -1
- package/dist/types/src/internal/testing/utils.d.ts.map +0 -1
- package/dist/types/src/internal/types/types.d.ts +0 -79
- package/dist/types/src/internal/types/types.d.ts.map +0 -1
- package/dist/types/src/internal/types/types.test.d.ts +0 -2
- package/dist/types/src/internal/types/types.test.d.ts.map +0 -1
- package/dist/types/src/internal/types/util.d.ts +0 -5
- package/dist/types/src/internal/types/util.d.ts.map +0 -1
- package/dist/types/src/testing/echo-schema.d.ts +0 -7
- package/dist/types/src/testing/echo-schema.d.ts.map +0 -1
- package/dist/types/src/testing/types.d.ts.map +0 -1
- package/src/internal/ast/annotation-helper.ts +0 -22
- package/src/internal/ast/annotations.ts +0 -226
- package/src/internal/ast/index.ts +0 -8
- package/src/internal/ast/types.ts +0 -17
- package/src/internal/json/index.ts +0 -5
- package/src/internal/object/accessors.ts +0 -153
- package/src/internal/object/entity.ts +0 -248
- package/src/internal/object/relation.ts +0 -24
- package/src/internal/object/typename.ts +0 -61
- package/src/internal/object/version.ts +0 -22
- package/src/internal/projection/index.ts +0 -5
- package/src/internal/query/index.ts +0 -5
- package/src/internal/schema/stored-schema.ts +0 -26
- package/src/internal/testing/index.ts +0 -6
- package/src/internal/testing/types.ts +0 -144
- package/src/internal/types/types.test.ts +0 -48
- package/src/internal/types/types.ts +0 -176
- package/src/internal/types/util.ts +0 -9
- package/src/test/api.test.ts +0 -180
- package/src/testing/echo-schema.ts +0 -39
- package/src/testing/types.ts +0 -108
- /package/dist/types/src/internal/{ast → annotations}/annotations.test.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/annotations.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/effect-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/json-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{projection → schema}/compose.d.ts +0 -0
- /package/dist/types/src/internal/{projection → schema}/compose.test.d.ts +0 -0
- /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
- /package/src/internal/{json → json-schema}/effect-schema.test.ts +0 -0
- /package/src/{internal/query/query.ts → query/types.ts} +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { raise } from '@dxos/debug';
|
|
9
|
+
|
|
10
|
+
import { Entity, Obj, Ref, Relation, Type } from '../index';
|
|
11
|
+
|
|
12
|
+
import { TestSchema } from './test-schema';
|
|
13
|
+
|
|
14
|
+
describe('Experimental API review', () => {
|
|
15
|
+
test('type checks', ({ expect }) => {
|
|
16
|
+
const contact = Obj.make(TestSchema.Person, { name: 'Test' });
|
|
17
|
+
const type: Schema.Schema<TestSchema.Person> = Obj.getSchema(contact) ?? raise(new Error('No schema found'));
|
|
18
|
+
|
|
19
|
+
expect(Type.getDXN(type)?.typename).to.eq(TestSchema.Person.typename);
|
|
20
|
+
expect(Type.getTypename(type)).to.eq('example.com/type/Person');
|
|
21
|
+
expect(Type.getVersion(type)).to.eq('0.1.0');
|
|
22
|
+
expect(Type.getMeta(type)).to.deep.eq({
|
|
23
|
+
kind: Entity.Kind.Object,
|
|
24
|
+
typename: 'example.com/type/Person',
|
|
25
|
+
version: '0.1.0',
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('instance checks', ({ expect }) => {
|
|
30
|
+
const organization = Obj.make(TestSchema.Organization, { name: 'DXOS' });
|
|
31
|
+
const contact = Obj.make(TestSchema.Person, {
|
|
32
|
+
name: 'Test',
|
|
33
|
+
employer: Ref.make(organization),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(Schema.is(TestSchema.Person)(contact)).to.be.true;
|
|
37
|
+
expect(Obj.instanceOf(TestSchema.Person, contact)).to.be.true;
|
|
38
|
+
expect(Obj.instanceOf(TestSchema.Organization, organization)).to.be.true;
|
|
39
|
+
|
|
40
|
+
const isPerson = Obj.instanceOf(TestSchema.Person);
|
|
41
|
+
const x: any = {};
|
|
42
|
+
if (isPerson(x)) {
|
|
43
|
+
x.name;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('default props', ({ expect }) => {
|
|
48
|
+
const message = Obj.make(TestSchema.Message, TestSchema.MessageStruct.make({}));
|
|
49
|
+
expect(message.timestamp).to.exist;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('Obj.isObject', ({ expect }) => {
|
|
53
|
+
const guy = Obj.make(TestSchema.Person, { name: 'Test' });
|
|
54
|
+
expect(Obj.isObject(guy)).to.be.true;
|
|
55
|
+
expect(Obj.isObject(null)).to.be.false;
|
|
56
|
+
expect(Obj.isObject(undefined)).to.be.false;
|
|
57
|
+
expect(Obj.isObject(1)).to.be.false;
|
|
58
|
+
expect(Obj.isObject('string')).to.be.false;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('create relation', ({ expect }) => {
|
|
62
|
+
const person = Obj.make(TestSchema.Person, { name: 'Test' });
|
|
63
|
+
const organization = Obj.make(TestSchema.Organization, { name: 'DXOS' });
|
|
64
|
+
const worksFor = Relation.make(TestSchema.EmployedBy, {
|
|
65
|
+
[Relation.Source]: person,
|
|
66
|
+
[Relation.Target]: organization,
|
|
67
|
+
role: 'CEO',
|
|
68
|
+
});
|
|
69
|
+
expect(Relation.getSource(worksFor)).to.eq(person);
|
|
70
|
+
expect(Relation.getTarget(worksFor)).to.eq(organization);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('version', ({ expect }) => {
|
|
74
|
+
const person = Obj.make(TestSchema.Person, { name: 'Test' });
|
|
75
|
+
const version = Obj.version(person);
|
|
76
|
+
expect(Obj.isVersion(version)).to.be.true;
|
|
77
|
+
expect(Obj.versionValid(version)).to.be.false;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// TODO(burdon): Implement test.
|
|
81
|
+
test.skip('type narrowing', () => {
|
|
82
|
+
const any: Entity.Unknown = null as any;
|
|
83
|
+
|
|
84
|
+
{
|
|
85
|
+
if (Obj.isObject(any)) {
|
|
86
|
+
any;
|
|
87
|
+
} else {
|
|
88
|
+
any;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
{
|
|
93
|
+
if (Relation.isRelation(any)) {
|
|
94
|
+
any;
|
|
95
|
+
} else {
|
|
96
|
+
any;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
package/src/testing/index.ts
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
5
|
+
export * from './test-data';
|
|
6
|
+
export * from './test-schema';
|
|
7
|
+
export * from './util';
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { DatabaseDirectory, ObjectStructure } from '@dxos/echo-protocol';
|
|
6
|
+
import { DXN, ObjectId, PublicKey } from '@dxos/keys';
|
|
7
|
+
|
|
8
|
+
import { Type } from '../index';
|
|
9
|
+
|
|
10
|
+
import { TestSchema } from './test-schema';
|
|
11
|
+
|
|
12
|
+
const spaceKey = PublicKey.random();
|
|
13
|
+
|
|
14
|
+
// TODO(burdon): Use Obj.make.
|
|
15
|
+
|
|
16
|
+
export const PEOPLE = {
|
|
17
|
+
alice: DatabaseDirectory.make({
|
|
18
|
+
spaceKey: spaceKey.toHex(),
|
|
19
|
+
objects: {
|
|
20
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
21
|
+
type: Type.getDXN(TestSchema.Person)!.toString(),
|
|
22
|
+
data: {
|
|
23
|
+
name: 'Alice',
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
bob: DatabaseDirectory.make({
|
|
29
|
+
spaceKey: spaceKey.toHex(),
|
|
30
|
+
objects: {
|
|
31
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
32
|
+
type: Type.getDXN(TestSchema.Person)!.toString(),
|
|
33
|
+
data: {
|
|
34
|
+
name: 'Bob',
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const ORGS = {
|
|
42
|
+
dxos: DatabaseDirectory.make({
|
|
43
|
+
spaceKey: spaceKey.toHex(),
|
|
44
|
+
objects: {
|
|
45
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
46
|
+
type: Type.getDXN(TestSchema.Organization)!.toString(),
|
|
47
|
+
data: {
|
|
48
|
+
name: 'DXOS',
|
|
49
|
+
founded: '2023',
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
cyberdyne: DatabaseDirectory.make({
|
|
55
|
+
spaceKey: spaceKey.toHex(),
|
|
56
|
+
objects: {
|
|
57
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
58
|
+
type: Type.getDXN(TestSchema.Organization)!.toString(),
|
|
59
|
+
data: {
|
|
60
|
+
name: 'Cyberdyne Systems',
|
|
61
|
+
founded: '1984',
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const WORKS_FOR = {
|
|
69
|
+
fredWorksForCyberdyne: DatabaseDirectory.make({
|
|
70
|
+
spaceKey: spaceKey.toHex(),
|
|
71
|
+
objects: {
|
|
72
|
+
[ObjectId.random()]: ObjectStructure.makeRelation({
|
|
73
|
+
type: Type.getDXN(TestSchema.EmployedBy)!.toString(),
|
|
74
|
+
source: { '/': DXN.fromLocalObjectId(Object.keys(PEOPLE.bob.objects!)[0]).toString() },
|
|
75
|
+
target: { '/': DXN.fromLocalObjectId(Object.keys(ORGS.cyberdyne.objects!)[0]).toString() },
|
|
76
|
+
data: {
|
|
77
|
+
since: '2020',
|
|
78
|
+
position: 'Engineer',
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
83
|
+
aliceWorksForAperture: DatabaseDirectory.make({
|
|
84
|
+
spaceKey: spaceKey.toHex(),
|
|
85
|
+
objects: {
|
|
86
|
+
[ObjectId.random()]: ObjectStructure.makeRelation({
|
|
87
|
+
type: Type.getDXN(TestSchema.EmployedBy)!.toString(),
|
|
88
|
+
source: { '/': DXN.fromLocalObjectId(Object.keys(PEOPLE.alice.objects!)[0]).toString() },
|
|
89
|
+
target: { '/': DXN.fromLocalObjectId(Object.keys(ORGS.dxos.objects!)[0]).toString() },
|
|
90
|
+
data: {
|
|
91
|
+
since: '2018',
|
|
92
|
+
position: 'Research Scientist',
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const TASKS = {
|
|
100
|
+
task1: DatabaseDirectory.make({
|
|
101
|
+
spaceKey: spaceKey.toHex(),
|
|
102
|
+
objects: {
|
|
103
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
104
|
+
type: Type.getDXN(TestSchema.Task)!.toString(),
|
|
105
|
+
data: {
|
|
106
|
+
title: 'Complete project documentation',
|
|
107
|
+
description: 'Write comprehensive documentation for the new system',
|
|
108
|
+
status: 'in-progress',
|
|
109
|
+
dueDate: '2023-12-31',
|
|
110
|
+
assignee: { '/': DXN.fromLocalObjectId(Object.keys(PEOPLE.bob.objects!)[0]).toString() },
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
},
|
|
114
|
+
}),
|
|
115
|
+
task2: DatabaseDirectory.make({
|
|
116
|
+
spaceKey: spaceKey.toHex(),
|
|
117
|
+
objects: {
|
|
118
|
+
[ObjectId.random()]: ObjectStructure.makeObject({
|
|
119
|
+
type: Type.getDXN(TestSchema.Task)!.toString(),
|
|
120
|
+
data: {
|
|
121
|
+
title: 'Run experiments',
|
|
122
|
+
description: 'Conduct series of experiments on the portal device',
|
|
123
|
+
status: 'pending',
|
|
124
|
+
dueDate: '2023-11-15',
|
|
125
|
+
assignee: { '/': DXN.fromLocalObjectId(Object.keys(PEOPLE.alice.objects!)[0]).toString() },
|
|
126
|
+
},
|
|
127
|
+
}),
|
|
128
|
+
},
|
|
129
|
+
}),
|
|
130
|
+
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import * as Obj from '../Obj';
|
|
8
|
+
import * as Type from '../Type';
|
|
9
|
+
|
|
10
|
+
export namespace TestSchema {
|
|
11
|
+
//
|
|
12
|
+
// Example
|
|
13
|
+
//
|
|
14
|
+
|
|
15
|
+
const Nested = Schema.Struct({
|
|
16
|
+
field: Schema.String,
|
|
17
|
+
}).pipe(Schema.mutable);
|
|
18
|
+
|
|
19
|
+
export class TestClass {
|
|
20
|
+
field = 'value';
|
|
21
|
+
toJSON() {
|
|
22
|
+
return { field: this.field };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @deprecated Use another test schema or create a specific local test schema. */
|
|
27
|
+
export const ExampleSchema = Schema.Struct({
|
|
28
|
+
string: Schema.String,
|
|
29
|
+
number: Schema.Number,
|
|
30
|
+
boolean: Schema.Boolean,
|
|
31
|
+
null: Schema.Null,
|
|
32
|
+
undefined: Schema.Undefined,
|
|
33
|
+
stringArray: Schema.mutable(Schema.Array(Schema.String)),
|
|
34
|
+
twoDimNumberArray: Schema.mutable(Schema.Array(Schema.mutable(Schema.Array(Schema.Number)))),
|
|
35
|
+
nested: Schema.mutable(Nested),
|
|
36
|
+
nestedArray: Schema.mutable(Schema.Array(Nested)),
|
|
37
|
+
nestedNullableArray: Schema.mutable(Schema.Array(Schema.Union(Nested, Schema.Null))),
|
|
38
|
+
reference: Schema.suspend((): Type.Ref<Example> => Type.Ref(Example)),
|
|
39
|
+
referenceArray: Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Example> => Type.Ref(Example)))),
|
|
40
|
+
classInstance: Schema.instanceOf(TestClass),
|
|
41
|
+
other: Schema.Any,
|
|
42
|
+
}).pipe(Schema.partial, Schema.mutable);
|
|
43
|
+
|
|
44
|
+
/** @deprecated Use another test schema or create a specific local test schema. */
|
|
45
|
+
export interface ExampleSchema extends Schema.Schema.Type<typeof ExampleSchema> {}
|
|
46
|
+
|
|
47
|
+
/** @deprecated Use another test schema or create a specific local test schema. */
|
|
48
|
+
export const Example = ExampleSchema.pipe(
|
|
49
|
+
Type.Obj({
|
|
50
|
+
typename: 'example.com/type/Example',
|
|
51
|
+
version: '0.1.0',
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
/** @deprecated Use another test schema or create a specific local test schema. */
|
|
56
|
+
export interface Example extends Schema.Schema.Type<typeof Example> {}
|
|
57
|
+
|
|
58
|
+
//
|
|
59
|
+
// Message
|
|
60
|
+
//
|
|
61
|
+
|
|
62
|
+
// TODO(burdon): Support defaults directly on Type: `make` is erased by `pipe(Type.Obj)`.
|
|
63
|
+
export const MessageStruct = Schema.Struct({
|
|
64
|
+
// TODO(burdon): Support S.Date; Custom Timestamp (with defaults).
|
|
65
|
+
// TODO(burdon): Support defaults (update create and create).
|
|
66
|
+
timestamp: Schema.String.pipe(
|
|
67
|
+
Schema.propertySignature,
|
|
68
|
+
Schema.withConstructorDefault(() => new Date().toISOString()),
|
|
69
|
+
),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const Message = MessageStruct.pipe(
|
|
73
|
+
Type.Obj({
|
|
74
|
+
typename: 'example.com/type/Message',
|
|
75
|
+
version: '0.1.0',
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export interface Message extends Schema.Schema.Type<typeof Message> {}
|
|
80
|
+
|
|
81
|
+
//
|
|
82
|
+
// Organization
|
|
83
|
+
//
|
|
84
|
+
|
|
85
|
+
export const Organization = Schema.Struct({
|
|
86
|
+
name: Schema.String,
|
|
87
|
+
}).pipe(
|
|
88
|
+
Type.Obj({
|
|
89
|
+
typename: 'example.com/type/Organization',
|
|
90
|
+
version: '0.1.0',
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
export interface Organization extends Schema.Schema.Type<typeof Organization> {}
|
|
95
|
+
|
|
96
|
+
//
|
|
97
|
+
// Person
|
|
98
|
+
//
|
|
99
|
+
|
|
100
|
+
export const Person = Schema.Struct({
|
|
101
|
+
name: Schema.String,
|
|
102
|
+
username: Schema.String,
|
|
103
|
+
email: Schema.String,
|
|
104
|
+
tasks: Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task)))),
|
|
105
|
+
employer: Schema.optional(Type.Ref(Organization)),
|
|
106
|
+
address: Schema.Struct({
|
|
107
|
+
city: Schema.optional(Schema.String),
|
|
108
|
+
state: Schema.optional(Schema.String),
|
|
109
|
+
zip: Schema.optional(Schema.String),
|
|
110
|
+
coordinates: Schema.Struct({
|
|
111
|
+
lat: Schema.optional(Schema.Number),
|
|
112
|
+
lng: Schema.optional(Schema.Number),
|
|
113
|
+
}),
|
|
114
|
+
}),
|
|
115
|
+
}).pipe(
|
|
116
|
+
Schema.partial,
|
|
117
|
+
Type.Obj({
|
|
118
|
+
typename: 'example.com/type/Person',
|
|
119
|
+
version: '0.1.0',
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
export interface Person extends Schema.Schema.Type<typeof Person> {}
|
|
124
|
+
|
|
125
|
+
//
|
|
126
|
+
// Task
|
|
127
|
+
//
|
|
128
|
+
|
|
129
|
+
export const Task = Schema.Struct({
|
|
130
|
+
title: Schema.optional(Schema.String),
|
|
131
|
+
deadline: Schema.optional(Schema.String),
|
|
132
|
+
completed: Schema.optional(Schema.Boolean),
|
|
133
|
+
assignee: Schema.optional(Type.Ref(Person)),
|
|
134
|
+
previous: Schema.optional(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))),
|
|
135
|
+
subTasks: Schema.optional(Schema.mutable(Schema.Array(Schema.suspend((): Type.Ref<Task> => Type.Ref(Task))))),
|
|
136
|
+
description: Schema.optional(Schema.String),
|
|
137
|
+
}).pipe(
|
|
138
|
+
Schema.partial,
|
|
139
|
+
Type.Obj({
|
|
140
|
+
typename: 'example.com/type/Task',
|
|
141
|
+
version: '0.1.0',
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
export interface Task extends Schema.Schema.Type<typeof Task> {}
|
|
146
|
+
|
|
147
|
+
//
|
|
148
|
+
// HasManager
|
|
149
|
+
//
|
|
150
|
+
|
|
151
|
+
export const HasManager = Schema.Struct({}).pipe(
|
|
152
|
+
Type.Relation({
|
|
153
|
+
typename: 'example.com/type/HasManager',
|
|
154
|
+
version: '0.1.0',
|
|
155
|
+
source: Person,
|
|
156
|
+
target: Person,
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
export interface HasManager extends Schema.Schema.Type<typeof HasManager> {}
|
|
161
|
+
|
|
162
|
+
//
|
|
163
|
+
// EmployedBy
|
|
164
|
+
//
|
|
165
|
+
|
|
166
|
+
export const EmployedBy = Schema.Struct({
|
|
167
|
+
role: Schema.String,
|
|
168
|
+
since: Schema.optional(Schema.String),
|
|
169
|
+
}).pipe(
|
|
170
|
+
Type.Relation({
|
|
171
|
+
typename: 'example.com/type/EmployedBy',
|
|
172
|
+
version: '0.1.0',
|
|
173
|
+
source: Person,
|
|
174
|
+
target: Organization,
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
export interface EmployedBy extends Schema.Schema.Type<typeof EmployedBy> {}
|
|
179
|
+
|
|
180
|
+
//
|
|
181
|
+
// RecordType
|
|
182
|
+
//
|
|
183
|
+
|
|
184
|
+
export enum RecordType {
|
|
185
|
+
UNDEFINED = 0,
|
|
186
|
+
PERSONAL = 1,
|
|
187
|
+
WORK = 2,
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export const Container = Schema.Struct({
|
|
191
|
+
objects: Schema.mutable(Schema.Array(Type.Ref(Obj.Any))),
|
|
192
|
+
records: Schema.mutable(
|
|
193
|
+
Schema.Array(
|
|
194
|
+
Schema.partial(
|
|
195
|
+
Schema.Struct({
|
|
196
|
+
title: Schema.String,
|
|
197
|
+
description: Schema.String,
|
|
198
|
+
contacts: Schema.mutable(Schema.Array(Type.Ref(Person))),
|
|
199
|
+
type: Schema.Enums(RecordType),
|
|
200
|
+
}),
|
|
201
|
+
),
|
|
202
|
+
),
|
|
203
|
+
),
|
|
204
|
+
}).pipe(
|
|
205
|
+
Schema.partial,
|
|
206
|
+
Type.Obj({
|
|
207
|
+
typename: 'example.com/type/Container',
|
|
208
|
+
version: '0.1.0',
|
|
209
|
+
}),
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
export interface Container extends Schema.Schema.Type<typeof Container> {}
|
|
213
|
+
}
|
|
@@ -3,35 +3,41 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { effect } from '@preact/signals-core';
|
|
6
|
+
import type * as Schema from 'effect/Schema';
|
|
6
7
|
import type * as SchemaAST from 'effect/SchemaAST';
|
|
7
8
|
|
|
8
9
|
import { registerSignalsRuntime } from '@dxos/echo-signals';
|
|
10
|
+
import { assertArgument } from '@dxos/invariant';
|
|
9
11
|
import { deepMapValues } from '@dxos/util';
|
|
10
12
|
|
|
13
|
+
import { EchoSchema, PersistentSchema, getSchemaTypename, makeObject, toJsonSchema } from '../internal';
|
|
14
|
+
|
|
11
15
|
registerSignalsRuntime();
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Create a reactive mutable schema that updates when the JSON schema is updated.
|
|
19
|
+
*/
|
|
20
|
+
// TODO(dmaretskyi): Should be replaced by registration of typed object.
|
|
21
|
+
export const createEchoSchema = (schema: Schema.Schema.AnyNoContext, version = '0.1.0'): EchoSchema => {
|
|
22
|
+
const jsonSchema = toJsonSchema(schema);
|
|
23
|
+
const typename = getSchemaTypename(schema);
|
|
24
|
+
assertArgument(typename, 'typename', 'Schema does not have a typename.');
|
|
25
|
+
const echoSchema = new EchoSchema(makeObject(PersistentSchema, { typename, version, jsonSchema }));
|
|
26
|
+
|
|
27
|
+
// TODO(burdon): Unsubscribe is never called.
|
|
28
|
+
effect(() => {
|
|
29
|
+
const _ = echoSchema.jsonSchema;
|
|
30
|
+
echoSchema._invalidate();
|
|
19
31
|
});
|
|
20
32
|
|
|
21
|
-
return
|
|
22
|
-
// https://github.com/tc39/proposal-explicit-resource-management
|
|
23
|
-
[Symbol.dispose]: unsubscribe,
|
|
24
|
-
get count() {
|
|
25
|
-
return updateCount;
|
|
26
|
-
},
|
|
27
|
-
};
|
|
33
|
+
return echoSchema;
|
|
28
34
|
};
|
|
29
35
|
|
|
30
36
|
/**
|
|
31
37
|
* Converts AST to a format that can be compared with test matchers.
|
|
32
38
|
*/
|
|
33
39
|
export const prepareAstForCompare = (obj: SchemaAST.AST): any =>
|
|
34
|
-
deepMapValues(obj, (value: any, recurse) => {
|
|
40
|
+
deepMapValues(obj, (value: any, recurse: any) => {
|
|
35
41
|
if (typeof value === 'function') {
|
|
36
42
|
return null;
|
|
37
43
|
}
|
|
@@ -47,8 +53,26 @@ export const prepareAstForCompare = (obj: SchemaAST.AST): any =>
|
|
|
47
53
|
clone[sym.toString()] = clone[sym];
|
|
48
54
|
delete clone[sym];
|
|
49
55
|
}
|
|
56
|
+
|
|
50
57
|
return recurse(clone);
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
return recurse(value);
|
|
54
61
|
});
|
|
62
|
+
|
|
63
|
+
// TODO(burdon): Use @dxos/util.
|
|
64
|
+
export const updateCounter = (touch: () => void) => {
|
|
65
|
+
let updateCount = -1;
|
|
66
|
+
const unsubscribe = effect(() => {
|
|
67
|
+
touch();
|
|
68
|
+
updateCount++;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
// https://github.com/tc39/proposal-explicit-resource-management
|
|
73
|
+
[Symbol.dispose]: unsubscribe,
|
|
74
|
+
get count() {
|
|
75
|
+
return updateCount;
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
};
|