@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
|
@@ -11,42 +11,51 @@ import { DXN, ObjectId } from '@dxos/keys';
|
|
|
11
11
|
import { defineHiddenProperty } from '@dxos/live-object';
|
|
12
12
|
import { assumeType, deepMapValues, visitValues } from '@dxos/util';
|
|
13
13
|
|
|
14
|
-
import {
|
|
15
|
-
import { Ref, type RefResolver, refFromEncodedReference, setRefResolver } from '../ref';
|
|
16
|
-
import { type AnyEchoObject } from '../types';
|
|
17
|
-
|
|
18
|
-
import { setSchema } from './accessors';
|
|
19
|
-
import { ObjectMetaSchema } from './meta';
|
|
14
|
+
import { getTypeDXN, setTypename } from '../annotations';
|
|
20
15
|
import {
|
|
21
16
|
ATTR_DELETED,
|
|
22
|
-
ATTR_META,
|
|
23
17
|
ATTR_RELATION_SOURCE,
|
|
24
18
|
ATTR_RELATION_TARGET,
|
|
25
19
|
ATTR_SELF_DXN,
|
|
26
|
-
ATTR_TYPE,
|
|
27
|
-
EntityKindId,
|
|
28
|
-
MetaId,
|
|
29
20
|
type ObjectJSON,
|
|
30
21
|
RelationSourceDXNId,
|
|
31
22
|
RelationSourceId,
|
|
32
23
|
RelationTargetDXNId,
|
|
33
24
|
RelationTargetId,
|
|
34
25
|
SelfDXNId,
|
|
26
|
+
assertObjectModel,
|
|
27
|
+
} from '../entities';
|
|
28
|
+
import { Ref, type RefResolver, refFromEncodedReference, setRefResolver } from '../ref';
|
|
29
|
+
import {
|
|
30
|
+
ATTR_META,
|
|
31
|
+
ATTR_TYPE,
|
|
32
|
+
type AnyEchoObject,
|
|
33
|
+
EntityKind,
|
|
34
|
+
KindId,
|
|
35
|
+
MetaId,
|
|
36
|
+
ObjectMetaSchema,
|
|
35
37
|
TypeId,
|
|
36
|
-
|
|
37
|
-
} from '
|
|
38
|
-
import { getType, setTypename } from './typename';
|
|
38
|
+
setSchema,
|
|
39
|
+
} from '../types';
|
|
39
40
|
|
|
40
41
|
type DeepReplaceRef<T> =
|
|
41
|
-
T extends Ref<any>
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
T extends Ref<any>
|
|
43
|
+
? EncodedReference
|
|
44
|
+
: T extends object
|
|
45
|
+
? {
|
|
46
|
+
[K in keyof T]: DeepReplaceRef<T[K]>;
|
|
47
|
+
}
|
|
48
|
+
: T;
|
|
49
|
+
|
|
50
|
+
type SerializedObject<T extends { id: string }> = {
|
|
51
|
+
[K in keyof T]: DeepReplaceRef<T[K]>;
|
|
52
|
+
} & ObjectJSON;
|
|
44
53
|
|
|
45
54
|
/**
|
|
46
55
|
* Converts object to it's JSON representation.
|
|
47
56
|
*/
|
|
48
57
|
export const objectToJSON = <T extends AnyEchoObject>(obj: T): SerializedObject<T> => {
|
|
49
|
-
const typename =
|
|
58
|
+
const typename = getTypeDXN(obj)?.toString();
|
|
50
59
|
invariant(typename && typeof typename === 'string');
|
|
51
60
|
return typedJsonSerializer.call(obj);
|
|
52
61
|
};
|
|
@@ -55,7 +64,6 @@ export const objectToJSON = <T extends AnyEchoObject>(obj: T): SerializedObject<
|
|
|
55
64
|
* Creates an object from it's json representation.
|
|
56
65
|
* Performs schema validation.
|
|
57
66
|
* References and schema will be resolvable if the `refResolver` is provided.
|
|
58
|
-
*
|
|
59
67
|
* The function need to be async to support resolving the schema as well as the relation endpoints.
|
|
60
68
|
*/
|
|
61
69
|
export const objectFromJSON = async (
|
|
@@ -82,7 +90,6 @@ export const objectFromJSON = async (
|
|
|
82
90
|
}
|
|
83
91
|
|
|
84
92
|
invariant(ObjectId.isValid(obj.id), 'Invalid object id');
|
|
85
|
-
|
|
86
93
|
setTypename(obj, type);
|
|
87
94
|
if (schema) {
|
|
88
95
|
setSchema(obj, schema);
|
|
@@ -94,25 +101,21 @@ export const objectFromJSON = async (
|
|
|
94
101
|
const sourceDxn: DXN = DXN.parse(jsonData[ATTR_RELATION_SOURCE] ?? raise(new TypeError('Missing relation source')));
|
|
95
102
|
const targetDxn: DXN = DXN.parse(jsonData[ATTR_RELATION_TARGET] ?? raise(new TypeError('Missing relation target')));
|
|
96
103
|
|
|
97
|
-
// TODO(dmaretskyi): Async!
|
|
98
104
|
const source = (await refResolver?.resolve(sourceDxn)) as AnyEchoObject | undefined;
|
|
99
105
|
const target = (await refResolver?.resolve(targetDxn)) as AnyEchoObject | undefined;
|
|
100
106
|
|
|
101
|
-
defineHiddenProperty(obj,
|
|
107
|
+
defineHiddenProperty(obj, KindId, EntityKind.Relation);
|
|
102
108
|
defineHiddenProperty(obj, RelationSourceDXNId, sourceDxn);
|
|
103
109
|
defineHiddenProperty(obj, RelationTargetDXNId, targetDxn);
|
|
104
110
|
defineHiddenProperty(obj, RelationSourceId, source);
|
|
105
111
|
defineHiddenProperty(obj, RelationTargetId, target);
|
|
106
112
|
} else {
|
|
107
|
-
defineHiddenProperty(obj,
|
|
113
|
+
defineHiddenProperty(obj, KindId, EntityKind.Object);
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
if (typeof jsonData[ATTR_META] === 'object') {
|
|
111
117
|
const meta = await ObjectMetaSchema.pipe(Schema.decodeUnknownPromise)(jsonData[ATTR_META]);
|
|
112
|
-
|
|
113
|
-
// Defensive programming.
|
|
114
118
|
invariant(Array.isArray(meta.keys));
|
|
115
|
-
|
|
116
119
|
defineHiddenProperty(obj, MetaId, meta);
|
|
117
120
|
}
|
|
118
121
|
|
|
@@ -120,13 +123,13 @@ export const objectFromJSON = async (
|
|
|
120
123
|
defineHiddenProperty(obj, SelfDXNId, dxn);
|
|
121
124
|
}
|
|
122
125
|
|
|
123
|
-
|
|
126
|
+
assertObjectModel(obj);
|
|
124
127
|
invariant((obj as any)[ATTR_TYPE] === undefined, 'Invalid object model');
|
|
125
|
-
invariant((obj as any)[
|
|
128
|
+
invariant((obj as any)[ATTR_META] === undefined, 'Invalid object model');
|
|
126
129
|
invariant((obj as any)[ATTR_DELETED] === undefined, 'Invalid object model');
|
|
130
|
+
invariant((obj as any)[ATTR_SELF_DXN] === undefined, 'Invalid object model');
|
|
127
131
|
invariant((obj as any)[ATTR_RELATION_SOURCE] === undefined, 'Invalid object model');
|
|
128
132
|
invariant((obj as any)[ATTR_RELATION_TARGET] === undefined, 'Invalid object model');
|
|
129
|
-
invariant((obj as any)[ATTR_META] === undefined, 'Invalid object model');
|
|
130
133
|
return obj;
|
|
131
134
|
};
|
|
132
135
|
|
|
@@ -135,30 +138,31 @@ const decodeGeneric = (jsonData: unknown, options: { refResolver?: RefResolver }
|
|
|
135
138
|
[ATTR_TYPE]: _type,
|
|
136
139
|
[ATTR_META]: _meta,
|
|
137
140
|
[ATTR_DELETED]: _deleted,
|
|
141
|
+
[ATTR_SELF_DXN]: _selfDxn,
|
|
138
142
|
[ATTR_RELATION_SOURCE]: _relationSource,
|
|
139
143
|
[ATTR_RELATION_TARGET]: _relationTarget,
|
|
140
|
-
[ATTR_SELF_DXN]: _selfDxn,
|
|
141
144
|
...props
|
|
142
145
|
} = jsonData as any;
|
|
143
146
|
|
|
144
|
-
return deepMapValues(props, (value,
|
|
147
|
+
return deepMapValues(props, (value, visitor) => {
|
|
145
148
|
if (isEncodedReference(value)) {
|
|
146
149
|
return refFromEncodedReference(value, options.refResolver);
|
|
147
150
|
}
|
|
148
|
-
|
|
151
|
+
|
|
152
|
+
return visitor(value);
|
|
149
153
|
});
|
|
150
154
|
};
|
|
151
155
|
|
|
152
156
|
export const setRefResolverOnData = (obj: AnyEchoObject, refResolver: RefResolver) => {
|
|
153
|
-
const
|
|
157
|
+
const visitor = (value: unknown) => {
|
|
154
158
|
if (Ref.isRef(value)) {
|
|
155
159
|
setRefResolver(value, refResolver);
|
|
156
160
|
} else {
|
|
157
|
-
visitValues(value,
|
|
161
|
+
visitValues(value, visitor);
|
|
158
162
|
}
|
|
159
163
|
};
|
|
160
164
|
|
|
161
|
-
|
|
165
|
+
visitor(obj);
|
|
162
166
|
};
|
|
163
167
|
|
|
164
168
|
export const attachTypedJsonSerializer = (obj: any) => {
|
|
@@ -187,6 +191,10 @@ const typedJsonSerializer = function (this: any) {
|
|
|
187
191
|
result[ATTR_TYPE] = this[TypeId].toString();
|
|
188
192
|
}
|
|
189
193
|
|
|
194
|
+
if (this[MetaId]) {
|
|
195
|
+
result[ATTR_META] = serializeMeta(this[MetaId]);
|
|
196
|
+
}
|
|
197
|
+
|
|
190
198
|
if (this[SelfDXNId]) {
|
|
191
199
|
result[ATTR_SELF_DXN] = this[SelfDXNId].toString();
|
|
192
200
|
}
|
|
@@ -202,10 +210,6 @@ const typedJsonSerializer = function (this: any) {
|
|
|
202
210
|
result[ATTR_RELATION_TARGET] = targetDXN.toString();
|
|
203
211
|
}
|
|
204
212
|
|
|
205
|
-
if (this[MetaId]) {
|
|
206
|
-
result[ATTR_META] = serializeMeta(this[MetaId]);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
213
|
Object.assign(result, serializeData(rest));
|
|
210
214
|
return result;
|
|
211
215
|
};
|
|
@@ -216,6 +220,7 @@ const serializeData = (data: unknown) => {
|
|
|
216
220
|
// TODO(dmaretskyi): Should this be configurable?
|
|
217
221
|
return value.noInline().encode();
|
|
218
222
|
}
|
|
223
|
+
|
|
219
224
|
return recurse(value);
|
|
220
225
|
});
|
|
221
226
|
};
|
|
@@ -7,7 +7,7 @@ import * as SchemaAST from 'effect/SchemaAST';
|
|
|
7
7
|
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
9
|
|
|
10
|
-
import { SchemaId } from '
|
|
10
|
+
import { SchemaId } from '../types';
|
|
11
11
|
|
|
12
12
|
// TODO(burdon): Reconcile with @dxos/effect visit().
|
|
13
13
|
|
|
@@ -46,7 +46,7 @@ export class SchemaValidator {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return type.ast.annotations[annotation] != null;
|
|
49
|
-
} catch
|
|
49
|
+
} catch {
|
|
50
50
|
return false;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -238,4 +238,5 @@ export const checkIdNotPresentOnSchema = (schema: Schema.Schema<any, any, any>)
|
|
|
238
238
|
}
|
|
239
239
|
};
|
|
240
240
|
|
|
241
|
+
// TODO(burdon): Reconcile with JsonPath.
|
|
241
242
|
type KeyPath = readonly (string | number)[];
|
|
@@ -15,7 +15,7 @@ class Organization extends TypedObject({
|
|
|
15
15
|
name: Schema.String,
|
|
16
16
|
}) {}
|
|
17
17
|
|
|
18
|
-
describe('
|
|
18
|
+
describe('EchoObjectSchema class DSL', () => {
|
|
19
19
|
test('type is a valid schema', async () => {
|
|
20
20
|
expect(Schema.isSchema(Organization)).to.be.true;
|
|
21
21
|
});
|
|
@@ -7,11 +7,17 @@ import * as SchemaAST from 'effect/SchemaAST';
|
|
|
7
7
|
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import {
|
|
11
|
+
type TypeAnnotation,
|
|
12
|
+
TypeAnnotationId,
|
|
13
|
+
type TypeMeta,
|
|
14
|
+
TypenameSchema,
|
|
15
|
+
VersionSchema,
|
|
16
|
+
makeTypeJsonSchemaAnnotation,
|
|
17
|
+
} from '../annotations';
|
|
18
|
+
import { EntityKind, type HasId } from '../types';
|
|
12
19
|
|
|
13
20
|
import { type TypedObjectFields, type TypedObjectOptions, makeTypedEntityClass } from './common';
|
|
14
|
-
import { makeTypeJsonSchemaAnnotation } from './entity';
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
23
|
* Definition for an object type that can be stored in an ECHO database.
|
|
@@ -46,8 +52,8 @@ export const TypedObject = ({
|
|
|
46
52
|
version: versionParam,
|
|
47
53
|
disableValidation,
|
|
48
54
|
}: TypedObjectProps) => {
|
|
49
|
-
const typename =
|
|
50
|
-
const version =
|
|
55
|
+
const typename = TypenameSchema.make(typenameParam, { disableValidation });
|
|
56
|
+
const version = VersionSchema.make(versionParam, { disableValidation });
|
|
51
57
|
|
|
52
58
|
/**
|
|
53
59
|
* Return class definition factory.
|
|
@@ -7,29 +7,39 @@ import { inspect } from 'node:util';
|
|
|
7
7
|
import { describe, expect, test } from 'vitest';
|
|
8
8
|
|
|
9
9
|
import { registerSignalsRuntime } from '@dxos/echo-signals';
|
|
10
|
-
import type
|
|
11
|
-
import { objectData } from '@dxos/live-object';
|
|
10
|
+
import { type Live, objectData } from '@dxos/live-object';
|
|
12
11
|
import { isNode } from '@dxos/util';
|
|
13
12
|
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
13
|
+
import { TestSchema, updateCounter } from '../../testing';
|
|
14
|
+
import { createObject } from '../object';
|
|
15
|
+
import { ATTR_META } from '../types';
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { makeObject } from './make-object';
|
|
18
18
|
|
|
19
19
|
registerSignalsRuntime();
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
describe('proxy', () => {
|
|
22
|
+
test.skipIf(!isNode())('inspect', ({ expect }) => {
|
|
23
|
+
const obj = createObject(TestSchema.Message, { timestamp: new Date().toISOString() });
|
|
24
|
+
const str = inspect(obj, { colors: true });
|
|
25
|
+
expect(str).to.exist;
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const TEST_OBJECT: TestSchema.ExampleSchema = {
|
|
22
30
|
string: 'foo',
|
|
23
31
|
number: 42,
|
|
24
32
|
boolean: true,
|
|
25
33
|
null: null,
|
|
26
34
|
stringArray: ['1', '2', '3'],
|
|
27
|
-
|
|
35
|
+
nested: {
|
|
36
|
+
field: 'bar',
|
|
37
|
+
},
|
|
28
38
|
};
|
|
29
39
|
|
|
30
|
-
for (const schema of [undefined,
|
|
31
|
-
const createObject = (props: Partial<
|
|
32
|
-
return schema == null ? (
|
|
40
|
+
for (const schema of [undefined, TestSchema.ExampleSchema]) {
|
|
41
|
+
const createObject = (props: Partial<TestSchema.ExampleSchema> = {}): Live<TestSchema.ExampleSchema> => {
|
|
42
|
+
return schema == null ? (makeObject(props) as TestSchema.ExampleSchema) : makeObject(schema, props);
|
|
33
43
|
};
|
|
34
44
|
|
|
35
45
|
describe(`Non-echo specific proxy properties${schema == null ? '' : ' with schema'}`, () => {
|
|
@@ -51,10 +61,10 @@ for (const schema of [undefined, Testing.TestSchemaWithClass]) {
|
|
|
51
61
|
test('can assign class instances', () => {
|
|
52
62
|
const obj = createObject();
|
|
53
63
|
|
|
54
|
-
const classInstance = new
|
|
64
|
+
const classInstance = new TestSchema.TestClass();
|
|
55
65
|
obj.classInstance = classInstance;
|
|
56
66
|
expect(obj.classInstance!.field).to.eq('value');
|
|
57
|
-
expect(obj.classInstance instanceof
|
|
67
|
+
expect(obj.classInstance instanceof TestSchema.TestClass).to.eq(true);
|
|
58
68
|
expect(obj.classInstance === classInstance).to.be.true;
|
|
59
69
|
|
|
60
70
|
obj.classInstance!.field = 'baz';
|
|
@@ -63,7 +73,7 @@ for (const schema of [undefined, Testing.TestSchemaWithClass]) {
|
|
|
63
73
|
|
|
64
74
|
describe('class instance equality', () => {
|
|
65
75
|
test('toJSON', () => {
|
|
66
|
-
const original = { classInstance: new
|
|
76
|
+
const original = { classInstance: new TestSchema.TestClass() };
|
|
67
77
|
const reactive = createObject(original);
|
|
68
78
|
if (!schema) {
|
|
69
79
|
expect(JSON.stringify(reactive)).to.eq(JSON.stringify(original));
|
|
@@ -80,14 +90,14 @@ for (const schema of [undefined, Testing.TestSchemaWithClass]) {
|
|
|
80
90
|
});
|
|
81
91
|
|
|
82
92
|
test('chai deep equal works', () => {
|
|
83
|
-
const original = { classInstance: new
|
|
93
|
+
const original = { classInstance: new TestSchema.TestClass() };
|
|
84
94
|
const reactive = createObject(original);
|
|
85
95
|
expect(reactive).to.deep.eq(original);
|
|
86
96
|
expect(reactive).to.not.deep.eq({ ...original, number: 11 });
|
|
87
97
|
});
|
|
88
98
|
|
|
89
99
|
test('jest deep equal works', () => {
|
|
90
|
-
const original = { classInstance: new
|
|
100
|
+
const original = { classInstance: new TestSchema.TestClass() };
|
|
91
101
|
const reactive = createObject(original);
|
|
92
102
|
expect(reactive).toEqual(original);
|
|
93
103
|
expect(reactive).not.toEqual({ ...original, number: 11 });
|
|
@@ -96,7 +106,7 @@ for (const schema of [undefined, Testing.TestSchemaWithClass]) {
|
|
|
96
106
|
|
|
97
107
|
describe('signal updates', () => {
|
|
98
108
|
test('not in nested class instances', () => {
|
|
99
|
-
const obj = createObject({ classInstance: new
|
|
109
|
+
const obj = createObject({ classInstance: new TestSchema.TestClass() });
|
|
100
110
|
using updates = updateCounter(() => {
|
|
101
111
|
obj.classInstance!.field;
|
|
102
112
|
});
|
|
@@ -112,7 +122,7 @@ for (const schema of [undefined, Testing.TestSchemaWithClass]) {
|
|
|
112
122
|
describe('getters', () => {
|
|
113
123
|
test('add getter to object', () => {
|
|
114
124
|
let value = 'foo';
|
|
115
|
-
const obj =
|
|
125
|
+
const obj = makeObject({
|
|
116
126
|
get getter() {
|
|
117
127
|
return value;
|
|
118
128
|
},
|
|
@@ -124,11 +134,11 @@ describe('getters', () => {
|
|
|
124
134
|
});
|
|
125
135
|
|
|
126
136
|
test('signal updates', () => {
|
|
127
|
-
const innerObj =
|
|
137
|
+
const innerObj = makeObject({
|
|
128
138
|
string: 'bar',
|
|
129
139
|
});
|
|
130
140
|
|
|
131
|
-
const obj =
|
|
141
|
+
const obj = makeObject({
|
|
132
142
|
field: 1,
|
|
133
143
|
get getter() {
|
|
134
144
|
return innerObj.string;
|
|
@@ -150,7 +160,7 @@ describe('getters', () => {
|
|
|
150
160
|
|
|
151
161
|
test('getter for array', () => {
|
|
152
162
|
const value = [1];
|
|
153
|
-
const obj =
|
|
163
|
+
const obj = makeObject({
|
|
154
164
|
get getter() {
|
|
155
165
|
return value;
|
|
156
166
|
},
|
|
@@ -13,32 +13,37 @@ import {
|
|
|
13
13
|
isValidProxyTarget,
|
|
14
14
|
} from '@dxos/live-object';
|
|
15
15
|
|
|
16
|
-
import { getTypeAnnotation } from '../
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
16
|
+
import { getTypeAnnotation } from '../annotations';
|
|
17
|
+
import { Expando } from '../entities';
|
|
18
|
+
import { attachTypedJsonSerializer } from '../object';
|
|
19
|
+
import { type AnyProperties, KindId, MetaId, type ObjectMeta, ObjectMetaSchema } from '../types';
|
|
19
20
|
|
|
20
21
|
import { TypedReactiveHandler, prepareTypedTarget } from './typed-handler';
|
|
21
22
|
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
// TODO(burdon): Make internal
|
|
27
|
+
export type MakeObjectProps<T extends AnyProperties> = Omit<T, 'id' | KindId>;
|
|
28
|
+
|
|
22
29
|
/**
|
|
23
30
|
* Creates a reactive object from a plain Javascript object.
|
|
24
31
|
* Optionally provides a TS-effect schema.
|
|
25
|
-
*
|
|
26
|
-
* @depreacted Use `Obj.make`.
|
|
27
32
|
*/
|
|
33
|
+
// TODO(burdon): Make internal
|
|
28
34
|
// TODO(dmaretskyi): Deep mutability.
|
|
29
35
|
// TODO(dmaretskyi): Invert generics (generic over schema) to have better error messages.
|
|
30
36
|
// TODO(dmaretskyi): Could mutate original object making it unusable.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
<T extends
|
|
34
|
-
<T extends BaseObject>(
|
|
37
|
+
export const makeObject: {
|
|
38
|
+
<T extends AnyProperties>(obj: T): Live<T>;
|
|
39
|
+
<T extends AnyProperties>(
|
|
35
40
|
schema: Schema.Schema<T, any, never>,
|
|
36
|
-
obj: NoInfer<
|
|
41
|
+
obj: NoInfer<MakeObjectProps<T>>,
|
|
37
42
|
meta?: ObjectMeta,
|
|
38
43
|
): Live<T>;
|
|
39
|
-
} = <T extends
|
|
44
|
+
} = <T extends AnyProperties>(
|
|
40
45
|
objOrSchema: Schema.Schema<T, any> | T,
|
|
41
|
-
obj?:
|
|
46
|
+
obj?: MakeObjectProps<T>,
|
|
42
47
|
meta?: ObjectMeta,
|
|
43
48
|
): Live<T> => {
|
|
44
49
|
// TODO(dmaretskyi): Remove Expando special case.
|
|
@@ -51,7 +56,7 @@ export const live: {
|
|
|
51
56
|
}
|
|
52
57
|
};
|
|
53
58
|
|
|
54
|
-
const createReactiveObject = <T extends
|
|
59
|
+
const createReactiveObject = <T extends AnyProperties>(
|
|
55
60
|
obj: T,
|
|
56
61
|
meta?: ObjectMeta,
|
|
57
62
|
schema?: Schema.Schema<T>,
|
|
@@ -68,7 +73,7 @@ const createReactiveObject = <T extends BaseObject>(
|
|
|
68
73
|
setIdOnTarget(obj);
|
|
69
74
|
}
|
|
70
75
|
if (annotation) {
|
|
71
|
-
defineHiddenProperty(obj,
|
|
76
|
+
defineHiddenProperty(obj, KindId, annotation.kind);
|
|
72
77
|
}
|
|
73
78
|
initMeta(obj, meta);
|
|
74
79
|
prepareTypedTarget(obj, schema);
|
|
@@ -6,8 +6,9 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
7
|
import { describe, expect, test } from 'vitest';
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { createEchoSchema } from '../../testing';
|
|
10
|
+
import { PropertyMeta, getPropertyMetaAnnotation, getTypeAnnotation } from '../annotations';
|
|
11
|
+
import { TypedObject } from '../object';
|
|
11
12
|
|
|
12
13
|
// TODO(dmaretskyi): Comment.
|
|
13
14
|
class EmptySchemaType extends TypedObject({
|
|
@@ -95,7 +96,7 @@ describe('dynamic schema', () => {
|
|
|
95
96
|
test('updates typename', async ({ expect }) => {
|
|
96
97
|
// Create schema with some fields and annotations.
|
|
97
98
|
const registered = createEchoSchema(EmptySchemaType);
|
|
98
|
-
const originalVersion = registered.
|
|
99
|
+
const originalVersion = registered.persistentSchema.version;
|
|
99
100
|
registered.addFields({
|
|
100
101
|
name: Schema.String.pipe(PropertyMeta('test', { maxLength: 10 })),
|
|
101
102
|
age: Schema.Number,
|
|
@@ -111,7 +112,7 @@ describe('dynamic schema', () => {
|
|
|
111
112
|
expect(registered.jsonSchema.typename).toBe(newTypename1);
|
|
112
113
|
|
|
113
114
|
// Version preservation check.
|
|
114
|
-
expect(registered.
|
|
115
|
+
expect(registered.persistentSchema.version).toBe(originalVersion);
|
|
115
116
|
|
|
116
117
|
// Field preservation check.
|
|
117
118
|
const properties = registered.getProperties();
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { describe, expect, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { TestSchema } from '../../testing';
|
|
9
|
+
import { isInstanceOf } from '../annotations';
|
|
10
|
+
import { TypedObject, createObject } from '../object';
|
|
11
|
+
import { Ref } from '../ref';
|
|
12
|
+
import { foreignKey, getMeta, getSchema } from '../types';
|
|
10
13
|
|
|
11
|
-
import {
|
|
14
|
+
import { makeObject } from './make-object';
|
|
12
15
|
|
|
13
16
|
describe('complex schema validations', () => {
|
|
14
17
|
const setValue = (target: any, prop: string, value: any) => {
|
|
@@ -17,20 +20,20 @@ describe('complex schema validations', () => {
|
|
|
17
20
|
|
|
18
21
|
test('any', () => {
|
|
19
22
|
const schema = Schema.Struct({ field: Schema.Any });
|
|
20
|
-
const object =
|
|
23
|
+
const object = makeObject(schema, { field: { nested: { value: 100 } } });
|
|
21
24
|
expect(() => setValue(object, 'field', { any: 'value' })).not.to.throw();
|
|
22
25
|
});
|
|
23
26
|
|
|
24
27
|
test('meta', () => {
|
|
25
28
|
const source = 'test';
|
|
26
29
|
const schema = Schema.Struct({ field: Schema.Number });
|
|
27
|
-
const object =
|
|
30
|
+
const object = makeObject(schema, { field: 42 }, { keys: [foreignKey(source, '123')] });
|
|
28
31
|
expect(getMeta(object).keys).to.deep.eq([foreignKey(source, '123')]);
|
|
29
32
|
});
|
|
30
33
|
|
|
31
34
|
test('object', () => {
|
|
32
35
|
const schema = Schema.Struct({ field: Schema.optional(Schema.Object) });
|
|
33
|
-
const object =
|
|
36
|
+
const object = makeObject(schema, { field: { nested: { value: 100 } } });
|
|
34
37
|
expect(() => setValue(object, 'field', { any: 'value' })).not.to.throw();
|
|
35
38
|
});
|
|
36
39
|
|
|
@@ -38,15 +41,15 @@ describe('complex schema validations', () => {
|
|
|
38
41
|
class Foo extends TypedObject({ typename: 'example.com/type/Foo', version: '0.1.0' })({ field: Schema.String }) {}
|
|
39
42
|
class Bar extends TypedObject({ typename: 'example.com/type/Bar', version: '0.1.0' })({ fooRef: Ref(Foo) }) {}
|
|
40
43
|
const field = 'hello';
|
|
41
|
-
expect(() =>
|
|
42
|
-
expect(() =>
|
|
43
|
-
const bar =
|
|
44
|
+
expect(() => makeObject(Bar, { fooRef: { id: '1', field } as any })).to.throw();
|
|
45
|
+
expect(() => makeObject(Bar, { fooRef: undefined as any })).to.throw(); // Unresolved reference.
|
|
46
|
+
const bar = makeObject(Bar, { fooRef: Ref.make(makeObject(Foo, { field })) });
|
|
44
47
|
expect(bar.fooRef.target?.field).to.eq(field);
|
|
45
48
|
});
|
|
46
49
|
|
|
47
50
|
test('index signatures', () => {
|
|
48
51
|
const schema = Schema.Struct({}, { key: Schema.String, value: Schema.Number });
|
|
49
|
-
const object =
|
|
52
|
+
const object = makeObject(schema, { unknownField: 1 });
|
|
50
53
|
expect(() => setValue(object, 'field', '42')).to.throw();
|
|
51
54
|
expect(() => setValue(object, 'unknown_field', 42)).not.to.throw();
|
|
52
55
|
});
|
|
@@ -57,7 +60,7 @@ describe('complex schema validations', () => {
|
|
|
57
60
|
object: Schema.optional(Schema.suspend(() => Schema.Union(Schema.Null, Schema.Struct({ field: Schema.Number })))),
|
|
58
61
|
});
|
|
59
62
|
|
|
60
|
-
const object =
|
|
63
|
+
const object = makeObject(schema, { array: [1, 2, null], object: { field: 3 } });
|
|
61
64
|
expect(() => setValue(object, 'object', { field: 4 })).not.to.throw();
|
|
62
65
|
expect(() => setValue(object.object, 'field', 4)).not.to.throw();
|
|
63
66
|
expect(() => setValue(object.array, '0', 4)).not.to.throw();
|
|
@@ -65,38 +68,35 @@ describe('complex schema validations', () => {
|
|
|
65
68
|
});
|
|
66
69
|
|
|
67
70
|
test('nesting static objects with schema in the live object', () => {
|
|
68
|
-
const contact1 =
|
|
71
|
+
const contact1 = createObject(TestSchema.Person, {
|
|
69
72
|
name: 'Robert Smith',
|
|
70
73
|
email: 'robert@example.com',
|
|
71
74
|
} as any);
|
|
72
|
-
const contact2 =
|
|
75
|
+
const contact2 = createObject(TestSchema.Person, {
|
|
73
76
|
name: 'Katy Perry',
|
|
74
77
|
email: 'katy@example.com',
|
|
75
78
|
} as any);
|
|
76
79
|
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
expect(isInstanceOf(Testing.Person, contactBook.contacts[0])).to.eq(true);
|
|
82
|
-
expect(getSchema(contactBook.contacts[0])).to.eq(Testing.Person);
|
|
80
|
+
const network = makeObject({ contacts: [contact1] });
|
|
81
|
+
expect(isInstanceOf(TestSchema.Person, network.contacts[0])).to.eq(true);
|
|
82
|
+
expect(getSchema(network.contacts[0])).to.eq(TestSchema.Person);
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
expect(isInstanceOf(
|
|
86
|
-
expect(getSchema(
|
|
84
|
+
network.contacts.push(contact2);
|
|
85
|
+
expect(isInstanceOf(TestSchema.Person, network.contacts[1])).to.eq(true);
|
|
86
|
+
expect(getSchema(network.contacts[1])).to.eq(TestSchema.Person);
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
test('creating an object with data from another object', () => {
|
|
90
|
-
const contact =
|
|
90
|
+
const contact = makeObject(TestSchema.Person, {
|
|
91
91
|
name: 'Robert Smith',
|
|
92
92
|
email: 'robert@example.com',
|
|
93
93
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const data = live(TestSchema, {
|
|
94
|
+
|
|
95
|
+
const TempSchema = Schema.Struct({ value: Schema.Unknown });
|
|
96
|
+
const object = makeObject(TempSchema, {
|
|
98
97
|
value: contact,
|
|
99
98
|
});
|
|
100
|
-
|
|
99
|
+
|
|
100
|
+
expect((object.value as any).name).to.eq('Robert Smith');
|
|
101
101
|
});
|
|
102
102
|
});
|
|
@@ -20,8 +20,10 @@ import {
|
|
|
20
20
|
symbolIsProxy,
|
|
21
21
|
} from '@dxos/live-object';
|
|
22
22
|
|
|
23
|
-
import { getSchemaDXN } from '../
|
|
24
|
-
import {
|
|
23
|
+
import { getSchemaDXN } from '../annotations';
|
|
24
|
+
import { ObjectDeletedId } from '../entities';
|
|
25
|
+
import { SchemaValidator } from '../object';
|
|
26
|
+
import { SchemaId, TypeId } from '../types';
|
|
25
27
|
|
|
26
28
|
const symbolSignal = Symbol('signal');
|
|
27
29
|
const symbolPropertySignal = Symbol('property-signal');
|
|
@@ -68,7 +70,7 @@ export class TypedReactiveHandler implements ReactiveHandler<ProxyTarget> {
|
|
|
68
70
|
defineHiddenProperty(target, symbolPropertySignal, compositeRuntime.createSignal());
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
defineHiddenProperty(target,
|
|
73
|
+
defineHiddenProperty(target, ObjectDeletedId, false);
|
|
72
74
|
|
|
73
75
|
for (const key of Object.getOwnPropertyNames(target)) {
|
|
74
76
|
const descriptor = Object.getOwnPropertyDescriptor(target, key)!;
|
|
@@ -90,6 +92,7 @@ export class TypedReactiveHandler implements ReactiveHandler<ProxyTarget> {
|
|
|
90
92
|
|
|
91
93
|
get(target: ProxyTarget, prop: string | symbol, receiver: any): any {
|
|
92
94
|
switch (prop) {
|
|
95
|
+
// TODO(burdon): Remove?
|
|
93
96
|
case objectData: {
|
|
94
97
|
target[symbolSignal].notifyRead();
|
|
95
98
|
return toJSON(target);
|
|
@@ -170,6 +173,7 @@ export class TypedReactiveHandler implements ReactiveHandler<ProxyTarget> {
|
|
|
170
173
|
showHidden: false,
|
|
171
174
|
customInspect: false,
|
|
172
175
|
});
|
|
176
|
+
|
|
173
177
|
return `Typed ${inspected}`;
|
|
174
178
|
}
|
|
175
179
|
}
|
|
@@ -177,6 +181,7 @@ export class TypedReactiveHandler implements ReactiveHandler<ProxyTarget> {
|
|
|
177
181
|
/**
|
|
178
182
|
* @deprecated Use `Obj.toJSON` instead.
|
|
179
183
|
*/
|
|
184
|
+
// TODO(burdon): Remove?
|
|
180
185
|
const toJSON = (target: ProxyTarget): any => {
|
|
181
186
|
return { '@type': 'TypedReactiveObject', ...target };
|
|
182
187
|
};
|