@dxos/echo 0.8.4-main.5ad4a44 → 0.8.4-main.66e292d
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-MWLA34S5.mjs → chunk-7GH6RXJ3.mjs} +2513 -2673
- 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 +21 -19
- package/dist/lib/browser/internal/index.mjs +55 -45
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +247 -217
- 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-YTNLFBIK.mjs → chunk-M4B6BMD2.mjs} +2513 -2673
- package/dist/lib/node-esm/chunk-M4B6BMD2.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +21 -19
- package/dist/lib/node-esm/internal/index.mjs +55 -45
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +247 -217
- 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 +85 -62
- 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 +17 -0
- package/dist/types/src/Tag.d.ts.map +1 -0
- package/dist/types/src/Type.d.ts +39 -49
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +14 -18
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +7 -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 -5
- 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} +9 -10
- 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 -12
- 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/manipulation.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 -1
- 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 -144
- 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/test-schema.d.ts +337 -0
- 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 +260 -147
- package/src/Ref.ts +9 -9
- package/src/Relation.ts +58 -44
- package/src/Tag.ts +40 -0
- package/src/Type.ts +96 -83
- package/src/index.ts +10 -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/entities/model.ts +129 -0
- 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 +230 -97
- package/src/internal/{json → json-schema}/json-schema.ts +67 -87
- package/src/internal/object/common.ts +3 -4
- package/src/internal/object/{create.test.ts → create-object.test.ts} +31 -33
- package/src/internal/object/{create.ts → create-object.ts} +34 -35
- package/src/internal/object/deleted.ts +6 -6
- package/src/internal/object/ids.ts +1 -1
- package/src/internal/object/index.ts +3 -12
- 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 +17 -4
- 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 +11 -6
- package/src/internal/proxy/typed-object.test.ts +17 -12
- package/src/internal/ref/ref.test.ts +9 -8
- 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 +7 -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 -18
- 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 +188 -216
- package/src/query/query.ts +24 -505
- 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-MWLA34S5.mjs.map +0 -7
- package/dist/lib/browser/chunk-OAZJQHVO.mjs +0 -453
- package/dist/lib/browser/chunk-OAZJQHVO.mjs.map +0 -7
- package/dist/lib/browser/chunk-ORIE2FMS.mjs +0 -514
- package/dist/lib/browser/chunk-ORIE2FMS.mjs.map +0 -7
- package/dist/lib/browser/query/index.mjs +0 -23
- package/dist/lib/browser/query/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AXWVDOP7.mjs +0 -453
- package/dist/lib/node-esm/chunk-AXWVDOP7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-L4PBAJDP.mjs +0 -514
- package/dist/lib/node-esm/chunk-L4PBAJDP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YTNLFBIK.mjs.map +0 -7
- package/dist/lib/node-esm/query/index.mjs +0 -23
- 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 -119
- 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 -29
- 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 -22
- 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/typed-relation.d.ts +0 -32
- package/dist/types/src/internal/object/typed-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 -455
- 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/query/tag.d.ts +0 -18
- package/dist/types/src/query/tag.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 +0 -113
- 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 -212
- 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 -115
- package/src/internal/object/entity.ts +0 -204
- package/src/internal/object/model.ts +0 -170
- package/src/internal/object/relation.ts +0 -24
- package/src/internal/object/typed-relation.ts +0 -85
- 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 -211
- 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/query/tag.ts +0 -35
- package/src/test/api.test.ts +0 -180
- package/src/testing/echo-schema.ts +0 -39
- package/src/testing/types.ts +0 -91
- /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
|
@@ -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.Contact, contactBook.contacts[0])).to.eq(true);
|
|
82
|
-
expect(getSchema(contactBook.contacts[0])).to.eq(Testing.Contact);
|
|
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);
|
|
@@ -165,18 +168,20 @@ export class TypedReactiveHandler implements ReactiveHandler<ProxyTarget> {
|
|
|
165
168
|
options: InspectOptionsStylized,
|
|
166
169
|
inspectFn: (value: any, options?: InspectOptionsStylized) => string,
|
|
167
170
|
): string {
|
|
168
|
-
|
|
171
|
+
const inspected = inspectFn(this, {
|
|
169
172
|
...options,
|
|
170
|
-
compact: true,
|
|
171
173
|
showHidden: false,
|
|
172
174
|
customInspect: false,
|
|
173
|
-
})
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return `Typed ${inspected}`;
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
|
|
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
|
};
|
|
@@ -5,14 +5,16 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { describe, expect, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { EchoObjectSchema } from '../entities';
|
|
9
|
+
import { TypedObject } from '../object';
|
|
10
|
+
import { getSchema } from '../types';
|
|
9
11
|
|
|
10
|
-
import {
|
|
12
|
+
import { makeObject } from './make-object';
|
|
11
13
|
|
|
12
14
|
const Organization = Schema.Struct({
|
|
13
15
|
name: Schema.String,
|
|
14
16
|
}).pipe(
|
|
15
|
-
|
|
17
|
+
EchoObjectSchema({
|
|
16
18
|
typename: 'example.com/type/Organization',
|
|
17
19
|
version: '0.1.0',
|
|
18
20
|
}),
|
|
@@ -24,11 +26,14 @@ const Contact = Schema.Struct(
|
|
|
24
26
|
{
|
|
25
27
|
name: Schema.String,
|
|
26
28
|
},
|
|
27
|
-
{
|
|
29
|
+
{
|
|
30
|
+
key: Schema.String,
|
|
31
|
+
value: Schema.Any,
|
|
32
|
+
},
|
|
28
33
|
).pipe(
|
|
29
34
|
Schema.partial,
|
|
30
|
-
|
|
31
|
-
typename: 'example.com/type/
|
|
35
|
+
EchoObjectSchema({
|
|
36
|
+
typename: 'example.com/type/Person',
|
|
32
37
|
version: '0.1.0',
|
|
33
38
|
}),
|
|
34
39
|
);
|
|
@@ -37,15 +42,15 @@ interface Contact extends Schema.Schema.Type<typeof Contact> {}
|
|
|
37
42
|
|
|
38
43
|
const TEST_ORG: Omit<Organization, 'id'> = { name: 'Test' };
|
|
39
44
|
|
|
40
|
-
describe('
|
|
45
|
+
describe('EchoObjectSchema class DSL', () => {
|
|
41
46
|
test('can get object schema', async () => {
|
|
42
|
-
const obj =
|
|
47
|
+
const obj = makeObject(Organization, TEST_ORG);
|
|
43
48
|
expect(getSchema(obj)).to.deep.eq(Organization);
|
|
44
49
|
});
|
|
45
50
|
|
|
46
51
|
describe('class options', () => {
|
|
47
52
|
test('can assign undefined to partial fields', async () => {
|
|
48
|
-
const person =
|
|
53
|
+
const person = makeObject(Contact, { name: 'John' });
|
|
49
54
|
person.name = undefined;
|
|
50
55
|
person.recordField = 'hello';
|
|
51
56
|
expect(person.name).to.be.undefined;
|
|
@@ -65,13 +70,13 @@ describe('EchoObject class DSL', () => {
|
|
|
65
70
|
);
|
|
66
71
|
|
|
67
72
|
{
|
|
68
|
-
const object =
|
|
73
|
+
const object = makeObject(schema, {});
|
|
69
74
|
(object.meta ??= {}).test = 100;
|
|
70
75
|
expect(object.meta.test).to.eq(100);
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
{
|
|
74
|
-
const object =
|
|
79
|
+
const object = makeObject(schema, {});
|
|
75
80
|
object.meta = { test: { value: 300 } };
|
|
76
81
|
expect(object.meta.test.value).to.eq(300);
|
|
77
82
|
}
|
|
@@ -92,7 +97,7 @@ describe('EchoObject class DSL', () => {
|
|
|
92
97
|
meta: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
|
|
93
98
|
}) {}
|
|
94
99
|
|
|
95
|
-
const object =
|
|
100
|
+
const object = makeObject(Test2, {});
|
|
96
101
|
(object.meta ??= {}).test = 100;
|
|
97
102
|
expect(object.meta.test).to.eq(100);
|
|
98
103
|
}
|
|
@@ -7,14 +7,15 @@ import { describe, expect, test } from 'vitest';
|
|
|
7
7
|
|
|
8
8
|
import { DXN, ObjectId } from '@dxos/keys';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { EchoObjectSchema, getObjectDXN } from '../entities';
|
|
11
|
+
import { createObject } from '../object';
|
|
11
12
|
|
|
12
13
|
import { Ref, getReferenceAst } from './ref';
|
|
13
14
|
|
|
14
15
|
const Task = Schema.Struct({
|
|
15
16
|
title: Schema.optional(Schema.String),
|
|
16
17
|
}).pipe(
|
|
17
|
-
|
|
18
|
+
EchoObjectSchema({
|
|
18
19
|
typename: 'example.com/type/Task',
|
|
19
20
|
version: '0.1.0',
|
|
20
21
|
}),
|
|
@@ -27,8 +28,8 @@ const Contact = Schema.Struct({
|
|
|
27
28
|
email: Schema.optional(Schema.String),
|
|
28
29
|
tasks: Schema.mutable(Schema.Array(Ref(Task))),
|
|
29
30
|
}).pipe(
|
|
30
|
-
|
|
31
|
-
typename: 'example.com/type/
|
|
31
|
+
EchoObjectSchema({
|
|
32
|
+
typename: 'example.com/type/Person',
|
|
32
33
|
version: '0.1.0',
|
|
33
34
|
}),
|
|
34
35
|
);
|
|
@@ -49,8 +50,8 @@ describe('Ref', () => {
|
|
|
49
50
|
|
|
50
51
|
// TODO(dmaretskyi): Figure out how to expose this in the API.
|
|
51
52
|
test.skip('encode with inlined target', () => {
|
|
52
|
-
const task =
|
|
53
|
-
const contact =
|
|
53
|
+
const task = createObject(Task, { title: 'Fix bugs' });
|
|
54
|
+
const contact = createObject(Contact, { name: 'John Doe', tasks: [Ref.make(task)] });
|
|
54
55
|
|
|
55
56
|
const json = JSON.parse(JSON.stringify(contact));
|
|
56
57
|
expect(json).toEqual({
|
|
@@ -70,8 +71,8 @@ describe('Ref', () => {
|
|
|
70
71
|
});
|
|
71
72
|
|
|
72
73
|
test('encode without inlining target', () => {
|
|
73
|
-
const task =
|
|
74
|
-
const contact =
|
|
74
|
+
const task = createObject(Task, { title: 'Fix bugs' });
|
|
75
|
+
const contact = createObject(Contact, { name: 'John Doe', tasks: [Ref.make(task).noInline()] });
|
|
75
76
|
|
|
76
77
|
const json = JSON.parse(JSON.stringify(contact));
|
|
77
78
|
expect(json).toEqual({
|
package/src/internal/ref/ref.ts
CHANGED
|
@@ -13,16 +13,15 @@ import { compositeRuntime } from '@dxos/echo-signals/runtime';
|
|
|
13
13
|
import { assertArgument, invariant } from '@dxos/invariant';
|
|
14
14
|
import { DXN, ObjectId } from '@dxos/keys';
|
|
15
15
|
|
|
16
|
-
import { ReferenceAnnotationId, getSchemaDXN, getTypeAnnotation, getTypeIdentifierAnnotation } from '../
|
|
16
|
+
import { ReferenceAnnotationId, getSchemaDXN, getTypeAnnotation, getTypeIdentifierAnnotation } from '../annotations';
|
|
17
17
|
import { type JsonSchemaType } from '../json-schema';
|
|
18
|
-
import type {
|
|
18
|
+
import type { AnyProperties, WithId } from '../types';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* The `$id` and `$ref` fields for an ECHO reference schema.
|
|
22
22
|
*/
|
|
23
23
|
export const JSON_SCHEMA_ECHO_REF_ID = '/schemas/echo/ref';
|
|
24
24
|
|
|
25
|
-
// TODO(burdon): Define return type.
|
|
26
25
|
export const getSchemaReference = (property: JsonSchemaType): { typename: string } | undefined => {
|
|
27
26
|
const { $id, reference: { schema: { $ref } = {} } = {} } = property;
|
|
28
27
|
if ($id === JSON_SCHEMA_ECHO_REF_ID && $ref) {
|
|
@@ -71,16 +70,18 @@ export const RefTypeId: unique symbol = Symbol('@dxos/echo/internal/Ref');
|
|
|
71
70
|
/**
|
|
72
71
|
* Reference Schema.
|
|
73
72
|
*/
|
|
74
|
-
export interface
|
|
73
|
+
export interface RefSchema<T extends WithId> extends Schema.SchemaClass<Ref<T>, EncodedReference> {}
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Type of the `Ref` function and extra methods attached to it.
|
|
77
|
+
*/
|
|
77
78
|
export interface RefFn {
|
|
78
|
-
<S extends Schema.Schema.Any>(schema: S):
|
|
79
|
+
<S extends Schema.Schema.Any>(schema: S): RefSchema<Schema.Schema.Type<S>>;
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
82
|
* @returns True if the object is a reference.
|
|
82
83
|
*/
|
|
83
|
-
isRef: (obj:
|
|
84
|
+
isRef: (obj: unknown) => obj is Ref<any>;
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
87
|
* @returns True if the reference points to the given object id.
|
|
@@ -90,7 +91,7 @@ export interface RefFn {
|
|
|
90
91
|
/**
|
|
91
92
|
* @returns True if the schema is a reference schema.
|
|
92
93
|
*/
|
|
93
|
-
isRefSchema: (schema: Schema.Schema<any, any>) => schema is
|
|
94
|
+
isRefSchema: (schema: Schema.Schema<any, any>) => schema is RefSchema<any>;
|
|
94
95
|
|
|
95
96
|
/**
|
|
96
97
|
* @returns True if the schema AST is a reference schema.
|
|
@@ -100,7 +101,7 @@ export interface RefFn {
|
|
|
100
101
|
/**
|
|
101
102
|
* Constructs a reference that points to the given object.
|
|
102
103
|
*/
|
|
103
|
-
// TODO(burdon):
|
|
104
|
+
// TODO(burdon): Narrow to Obj.Any?
|
|
104
105
|
make: <T extends WithId>(object: T) => Ref<T>;
|
|
105
106
|
|
|
106
107
|
/**
|
|
@@ -108,10 +109,11 @@ export interface RefFn {
|
|
|
108
109
|
*/
|
|
109
110
|
fromDXN: (dxn: DXN) => Ref<any>;
|
|
110
111
|
}
|
|
112
|
+
|
|
111
113
|
/**
|
|
112
114
|
* Schema builder for references.
|
|
113
115
|
*/
|
|
114
|
-
export const Ref: RefFn = <S extends Schema.Schema.Any>(schema: S):
|
|
116
|
+
export const Ref: RefFn = <S extends Schema.Schema.Any>(schema: S): RefSchema<Schema.Schema.Type<S>> => {
|
|
115
117
|
assertArgument(Schema.isSchema(schema), 'schema', 'Must call with an instance of effect-schema');
|
|
116
118
|
|
|
117
119
|
const annotation = getTypeAnnotation(schema);
|
|
@@ -201,7 +203,7 @@ Ref.isRef = (obj: any): obj is Ref<any> => {
|
|
|
201
203
|
|
|
202
204
|
Ref.hasObjectId = (id: ObjectId) => (ref: Ref<any>) => ref.dxn.isLocalObjectId() && ref.dxn.parts[1] === id;
|
|
203
205
|
|
|
204
|
-
Ref.isRefSchema = (schema: Schema.Schema<any, any>): schema is
|
|
206
|
+
Ref.isRefSchema = (schema: Schema.Schema<any, any>): schema is RefSchema<any> => {
|
|
205
207
|
return Ref.isRefSchemaAST(schema.ast);
|
|
206
208
|
};
|
|
207
209
|
|
|
@@ -209,7 +211,7 @@ Ref.isRefSchemaAST = (ast: SchemaAST.AST): boolean => {
|
|
|
209
211
|
return SchemaAST.getAnnotation(ast, ReferenceAnnotationId).pipe(Option.isSome);
|
|
210
212
|
};
|
|
211
213
|
|
|
212
|
-
Ref.make = <T extends
|
|
214
|
+
Ref.make = <T extends AnyProperties>(obj: T): Ref<T> => {
|
|
213
215
|
if (typeof obj !== 'object' || obj === null) {
|
|
214
216
|
throw new TypeError('Expected: ECHO object.');
|
|
215
217
|
}
|
|
@@ -242,7 +244,7 @@ export const createEchoReferenceSchema = (
|
|
|
242
244
|
echoId: string | undefined,
|
|
243
245
|
typename: string | undefined,
|
|
244
246
|
version: string | undefined,
|
|
245
|
-
schemaName?: string,
|
|
247
|
+
schemaName?: string, // TODO(burdon): Not used.
|
|
246
248
|
): Schema.SchemaClass<Ref<any>, EncodedReference> => {
|
|
247
249
|
if (!echoId && !typename) {
|
|
248
250
|
throw new TypeError('Either echoId or typename must be provided.');
|
|
@@ -315,12 +317,12 @@ export interface RefResolver {
|
|
|
315
317
|
* @param load If true the resolver should attempt to load the object from disk.
|
|
316
318
|
* @param onLoad Callback to call when the object is loaded.
|
|
317
319
|
*/
|
|
318
|
-
resolveSync(dxn: DXN, load: boolean, onLoad?: () => void):
|
|
320
|
+
resolveSync(dxn: DXN, load: boolean, onLoad?: () => void): AnyProperties | undefined;
|
|
319
321
|
|
|
320
322
|
/**
|
|
321
323
|
* Resolver ref asynchronously.
|
|
322
324
|
*/
|
|
323
|
-
resolve(dxn: DXN): Promise<
|
|
325
|
+
resolve(dxn: DXN): Promise<AnyProperties | undefined>;
|
|
324
326
|
|
|
325
327
|
// TODO(dmaretskyi): Combine with `resolve`.
|
|
326
328
|
resolveSchema(dxn: DXN): Promise<Schema.Schema.AnyNoContext | undefined>;
|
|
@@ -432,6 +434,7 @@ export class RefImpl<T> implements Ref<T> {
|
|
|
432
434
|
|
|
433
435
|
/**
|
|
434
436
|
* Internal method to set the resolver.
|
|
437
|
+
*
|
|
435
438
|
* @internal
|
|
436
439
|
*/
|
|
437
440
|
_setResolver(resolver: RefResolver): void {
|
|
@@ -441,6 +444,7 @@ export class RefImpl<T> implements Ref<T> {
|
|
|
441
444
|
/**
|
|
442
445
|
* Internal method to get the saved target.
|
|
443
446
|
* Not the same as `target` which is resolved from the resolver.
|
|
447
|
+
*
|
|
444
448
|
* @internal
|
|
445
449
|
*/
|
|
446
450
|
_getSavedTarget(): T | undefined {
|
|
@@ -459,7 +463,7 @@ export const setRefResolver = (ref: Ref<any>, resolver: RefResolver) => {
|
|
|
459
463
|
/**
|
|
460
464
|
* Internal API for getting the saved target on a reference.
|
|
461
465
|
*/
|
|
462
|
-
export const getRefSavedTarget = (ref: Ref<any>):
|
|
466
|
+
export const getRefSavedTarget = (ref: Ref<any>): AnyProperties | undefined => {
|
|
463
467
|
invariant(ref instanceof RefImpl, 'Ref is not an instance of RefImpl');
|
|
464
468
|
return ref._getSavedTarget();
|
|
465
469
|
};
|
|
@@ -482,10 +486,10 @@ export const refFromEncodedReference = (encodedReference: EncodedReference, reso
|
|
|
482
486
|
};
|
|
483
487
|
|
|
484
488
|
export class StaticRefResolver implements RefResolver {
|
|
485
|
-
public objects = new Map<ObjectId,
|
|
489
|
+
public objects = new Map<ObjectId, AnyProperties>();
|
|
486
490
|
public schemas = new Map<DXN.String, Schema.Schema.AnyNoContext>();
|
|
487
491
|
|
|
488
|
-
addObject(obj:
|
|
492
|
+
addObject(obj: AnyProperties): this {
|
|
489
493
|
this.objects.set(obj.id, obj);
|
|
490
494
|
return this;
|
|
491
495
|
}
|
|
@@ -497,7 +501,7 @@ export class StaticRefResolver implements RefResolver {
|
|
|
497
501
|
return this;
|
|
498
502
|
}
|
|
499
503
|
|
|
500
|
-
resolveSync(dxn: DXN, _load: boolean, _onLoad?: () => void):
|
|
504
|
+
resolveSync(dxn: DXN, _load: boolean, _onLoad?: () => void): AnyProperties | undefined {
|
|
501
505
|
const id = dxn?.asEchoDXN()?.echoId;
|
|
502
506
|
if (id == null) {
|
|
503
507
|
return undefined;
|
|
@@ -506,7 +510,7 @@ export class StaticRefResolver implements RefResolver {
|
|
|
506
510
|
return this.objects.get(id);
|
|
507
511
|
}
|
|
508
512
|
|
|
509
|
-
async resolve(dxn: DXN): Promise<
|
|
513
|
+
async resolve(dxn: DXN): Promise<AnyProperties | undefined> {
|
|
510
514
|
const id = dxn?.asEchoDXN()?.echoId;
|
|
511
515
|
if (id == null) {
|
|
512
516
|
return undefined;
|
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { describe, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import { FieldPath } from '../
|
|
9
|
-
import { FormatAnnotation,
|
|
10
|
-
import { toJsonSchema } from '../json';
|
|
11
|
-
import { ECHO_ANNOTATIONS_NS_KEY } from '../json-schema';
|
|
8
|
+
import { FieldPath } from '../annotations';
|
|
9
|
+
import { FormatAnnotation, TypeFormat } from '../formats';
|
|
10
|
+
import { ECHO_ANNOTATIONS_NS_KEY, toJsonSchema } from '../json-schema';
|
|
12
11
|
import { TypedObject } from '../object';
|
|
13
12
|
|
|
14
13
|
import { composeSchema } from './compose';
|
|
@@ -21,7 +20,7 @@ describe('schema composition', () => {
|
|
|
21
20
|
}) {}
|
|
22
21
|
|
|
23
22
|
const OverlaySchema = Schema.Struct({
|
|
24
|
-
email: Schema.String.pipe(FieldPath('$.email'), FormatAnnotation.set(
|
|
23
|
+
email: Schema.String.pipe(FieldPath('$.email'), FormatAnnotation.set(TypeFormat.Email)),
|
|
25
24
|
});
|
|
26
25
|
|
|
27
26
|
const baseSchema = toJsonSchema(BaseType);
|
|
@@ -30,7 +29,7 @@ describe('schema composition', () => {
|
|
|
30
29
|
expect(composedSchema.properties).to.deep.eq({
|
|
31
30
|
email: {
|
|
32
31
|
type: 'string',
|
|
33
|
-
format:
|
|
32
|
+
format: TypeFormat.Email,
|
|
34
33
|
// TODO(dmaretskyi): Should use the new field.
|
|
35
34
|
[ECHO_ANNOTATIONS_NS_KEY]: {
|
|
36
35
|
meta: {
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { invariant } from '@dxos/invariant';
|
|
6
6
|
|
|
7
7
|
import { type JsonSchemaType } from '../json-schema';
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
import { getSnapshot } from './snapshot';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Creates a composite schema from the source and projection schemas.
|