@dxos/echo 0.8.4-main.d05539e30a → 0.8.4-main.d9fc60f731
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/README.md +4 -4
- package/dist/lib/neutral/Annotation.mjs +27 -6
- package/dist/lib/neutral/Database.mjs +6 -11
- package/dist/lib/neutral/Entity.mjs +25 -16
- package/dist/lib/neutral/Err.mjs +3 -3
- package/dist/lib/neutral/Feed.mjs +19 -17
- package/dist/lib/neutral/Filter.mjs +13 -13
- package/dist/lib/neutral/Format.mjs +23 -3
- package/dist/lib/neutral/JsonSchema.mjs +7 -8
- package/dist/lib/neutral/Key.mjs +9 -5
- package/dist/lib/neutral/Migration.mjs +11 -10
- package/dist/lib/neutral/Obj.mjs +21 -18
- package/dist/lib/neutral/Query.mjs +17 -17
- package/dist/lib/neutral/QueryResult.mjs +1 -1
- package/dist/lib/neutral/Ref.mjs +10 -11
- package/dist/lib/neutral/Registry.mjs +14 -0
- package/dist/lib/neutral/Relation.mjs +24 -23
- package/dist/lib/neutral/Scope.mjs +12 -0
- package/dist/lib/neutral/Tag.mjs +17 -14
- package/dist/lib/neutral/Type.mjs +52 -26
- package/dist/lib/neutral/chunk-3DKP2EIN.mjs +31 -0
- package/dist/lib/neutral/chunk-3DKP2EIN.mjs.map +7 -0
- package/dist/lib/neutral/chunk-4BB4MFCN.mjs +154 -0
- package/dist/lib/neutral/chunk-4BB4MFCN.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-PT37DG2F.mjs → chunk-4SFPZJVA.mjs} +82 -74
- package/dist/lib/neutral/chunk-4SFPZJVA.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-APHSOTIX.mjs → chunk-4Z6GET2X.mjs} +3 -3
- package/dist/lib/neutral/{chunk-APHSOTIX.mjs.map → chunk-4Z6GET2X.mjs.map} +2 -2
- package/dist/lib/neutral/{chunk-7RVZT53K.mjs → chunk-7LOUAPYZ.mjs} +9 -5
- package/dist/lib/neutral/chunk-7LOUAPYZ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-BMB7IHGB.mjs → chunk-7OAFN3OX.mjs} +70 -57
- package/dist/lib/neutral/chunk-7OAFN3OX.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-MLS7U7AT.mjs → chunk-7PRCIDHH.mjs} +41 -28
- package/dist/lib/neutral/chunk-7PRCIDHH.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-ZISMEVKD.mjs → chunk-BBFJWWAV.mjs} +6 -6
- package/dist/lib/neutral/chunk-BBFJWWAV.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-ZFACXBY6.mjs → chunk-BDQGMDIX.mjs} +30 -34
- package/dist/lib/neutral/chunk-BDQGMDIX.mjs.map +7 -0
- package/dist/lib/neutral/chunk-CGTI5MXO.mjs +36 -0
- package/dist/lib/neutral/chunk-CGTI5MXO.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-V72DY6LU.mjs → chunk-DKLUHO4T.mjs} +1 -1
- package/dist/lib/neutral/chunk-DKLUHO4T.mjs.map +7 -0
- package/dist/lib/neutral/chunk-DMN2CKPX.mjs +93 -0
- package/dist/lib/neutral/chunk-DMN2CKPX.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-QRZ2I3ZM.mjs → chunk-G6CFWUYH.mjs} +2 -2
- package/dist/lib/neutral/chunk-H26LSXVJ.mjs +653 -0
- package/dist/lib/neutral/chunk-H26LSXVJ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-N7VOEPSV.mjs → chunk-J3MNM65T.mjs} +9 -9
- package/dist/lib/neutral/chunk-J3MNM65T.mjs.map +7 -0
- package/dist/lib/neutral/chunk-JE7AOSWF.mjs +247 -0
- package/dist/lib/neutral/chunk-JE7AOSWF.mjs.map +7 -0
- package/dist/lib/neutral/chunk-LAF3LSWI.mjs +379 -0
- package/dist/lib/neutral/chunk-LAF3LSWI.mjs.map +7 -0
- package/dist/lib/neutral/chunk-LMNRFOVB.mjs +108 -0
- package/dist/lib/neutral/chunk-LMNRFOVB.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-N4B7FHQT.mjs → chunk-O6BH7EPN.mjs} +30 -3
- package/dist/lib/neutral/chunk-O6BH7EPN.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-Q7ZL2P5H.mjs → chunk-OIYW7R2G.mjs} +62 -46
- package/dist/lib/neutral/chunk-OIYW7R2G.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-G54OX4IX.mjs → chunk-OYUG4FHF.mjs} +527 -847
- package/dist/lib/neutral/chunk-OYUG4FHF.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-J54QMAKF.mjs → chunk-Q5FKCVBC.mjs} +64 -59
- package/dist/lib/neutral/chunk-Q5FKCVBC.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-FIWO2FZK.mjs → chunk-Q62IHV2N.mjs} +12 -7
- package/dist/lib/neutral/chunk-Q62IHV2N.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-SCPFDS2E.mjs → chunk-QVJDDG44.mjs} +65 -34
- package/dist/lib/neutral/chunk-QVJDDG44.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-TRPZU2HV.mjs → chunk-TFEWTY5A.mjs} +155 -129
- package/dist/lib/neutral/chunk-TFEWTY5A.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-44HT3MEC.mjs → chunk-VKWOFXT2.mjs} +22 -2
- package/dist/lib/neutral/{chunk-44HT3MEC.mjs.map → chunk-VKWOFXT2.mjs.map} +1 -1
- package/dist/lib/neutral/{chunk-APJKDGFL.mjs → chunk-ZACMEAYV.mjs} +24 -24
- package/dist/lib/neutral/chunk-ZACMEAYV.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +50 -40
- package/dist/lib/neutral/internal/index.mjs +125 -64
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/testing/index.mjs +88 -99
- package/dist/lib/neutral/testing/index.mjs.map +3 -3
- package/dist/types/src/Annotation.d.ts +108 -4
- package/dist/types/src/Annotation.d.ts.map +1 -1
- package/dist/types/src/Annotation.test.d.ts +2 -0
- package/dist/types/src/Annotation.test.d.ts.map +1 -0
- package/dist/types/src/Collection.d.ts +2 -3
- package/dist/types/src/Collection.d.ts.map +1 -1
- package/dist/types/src/Database.d.ts +50 -30
- package/dist/types/src/Database.d.ts.map +1 -1
- package/dist/types/src/Dataset.d.ts +16 -6
- package/dist/types/src/Dataset.d.ts.map +1 -1
- package/dist/types/src/Entity.d.ts +89 -19
- package/dist/types/src/Entity.d.ts.map +1 -1
- package/dist/types/src/Err.d.ts +9 -9
- package/dist/types/src/Err.d.ts.map +1 -1
- package/dist/types/src/Feed.d.ts +35 -12
- package/dist/types/src/Feed.d.ts.map +1 -1
- package/dist/types/src/Filter.d.ts +21 -8
- package/dist/types/src/Filter.d.ts.map +1 -1
- package/dist/types/src/Hypergraph.d.ts +13 -8
- package/dist/types/src/Hypergraph.d.ts.map +1 -1
- package/dist/types/src/Json.d.ts.map +1 -1
- package/dist/types/src/JsonSchema.d.ts +1 -1
- package/dist/types/src/JsonSchema.d.ts.map +1 -1
- package/dist/types/src/Key.d.ts +1 -1
- package/dist/types/src/Key.d.ts.map +1 -1
- package/dist/types/src/Migration.d.ts +15 -12
- package/dist/types/src/Migration.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +69 -40
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Query.d.ts +24 -10
- package/dist/types/src/Query.d.ts.map +1 -1
- package/dist/types/src/QueryResult.d.ts +9 -0
- package/dist/types/src/QueryResult.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +15 -8
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Registry.d.ts +131 -0
- package/dist/types/src/Registry.d.ts.map +1 -0
- package/dist/types/src/Relation.d.ts +55 -26
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Scope.d.ts +34 -0
- package/dist/types/src/Scope.d.ts.map +1 -0
- package/dist/types/src/StateMap.d.ts +32 -0
- package/dist/types/src/StateMap.d.ts.map +1 -0
- package/dist/types/src/StateMap.test.d.ts +2 -0
- package/dist/types/src/StateMap.test.d.ts.map +1 -0
- package/dist/types/src/Tag.d.ts +19 -3
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/TagIndex.d.ts +36 -0
- package/dist/types/src/TagIndex.d.ts.map +1 -0
- package/dist/types/src/TagIndex.test.d.ts +2 -0
- package/dist/types/src/TagIndex.test.d.ts.map +1 -0
- package/dist/types/src/Tagging.d.ts +31 -0
- package/dist/types/src/Tagging.d.ts.map +1 -0
- package/dist/types/src/Type.d.ts +356 -95
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/View.d.ts +1 -4
- package/dist/types/src/View.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/Annotation/annotations.d.ts +68 -36
- package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/dictionary.d.ts +24 -0
- package/dist/types/src/internal/Annotation/dictionary.d.ts.map +1 -0
- package/dist/types/src/internal/Annotation/entity-dictionary.d.ts +14 -0
- package/dist/types/src/internal/Annotation/entity-dictionary.d.ts.map +1 -0
- package/dist/types/src/internal/Annotation/index.d.ts +4 -2
- package/dist/types/src/internal/Annotation/index.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/util.d.ts +13 -4
- package/dist/types/src/internal/Annotation/util.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/api.d.ts +3 -3
- package/dist/types/src/internal/Entity/api.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/entity.d.ts +72 -8
- package/dist/types/src/internal/Entity/entity.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/guard.d.ts +10 -0
- package/dist/types/src/internal/Entity/guard.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/index.d.ts +2 -0
- package/dist/types/src/internal/Entity/index.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/model.d.ts +18 -17
- package/dist/types/src/internal/Entity/model.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/object.d.ts +3 -3
- package/dist/types/src/internal/Entity/object.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/relation.d.ts +30 -7
- package/dist/types/src/internal/Entity/relation.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/type-kind.d.ts +24 -0
- package/dist/types/src/internal/Entity/type-kind.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/type-uri.d.ts +25 -0
- package/dist/types/src/internal/Entity/type-uri.d.ts.map +1 -0
- package/dist/types/src/internal/Format/date.d.ts.map +1 -1
- package/dist/types/src/internal/Format/format.d.ts +3 -2
- package/dist/types/src/internal/Format/format.d.ts.map +1 -1
- package/dist/types/src/internal/Format/index.d.ts +2 -2
- package/dist/types/src/internal/Format/index.d.ts.map +1 -1
- package/dist/types/src/internal/Format/object.d.ts +3 -1
- package/dist/types/src/internal/Format/object.d.ts.map +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts +2 -1
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/clone.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/create-object.d.ts +11 -12
- package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/index.d.ts +0 -1
- package/dist/types/src/internal/Obj/index.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/json-serializer.d.ts +8 -8
- package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/snapshot.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/typed-object.d.ts +1 -1
- package/dist/types/src/internal/Query.d.ts.map +1 -1
- package/dist/types/src/internal/Ref/ref-array.d.ts +2 -2
- package/dist/types/src/internal/Ref/ref.d.ts +29 -19
- package/dist/types/src/internal/Ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/Type/index.d.ts +1 -2
- package/dist/types/src/internal/Type/index.d.ts.map +1 -1
- package/dist/types/src/internal/Type/manipulation.d.ts +0 -1
- package/dist/types/src/internal/Type/manipulation.d.ts.map +1 -1
- package/dist/types/src/internal/Type/type-schema.d.ts +52 -0
- package/dist/types/src/internal/Type/type-schema.d.ts.map +1 -0
- package/dist/types/src/internal/common/api/meta.d.ts +11 -8
- package/dist/types/src/internal/common/api/meta.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/make-object.d.ts +11 -5
- package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts +18 -2
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/base.d.ts +4 -4
- package/dist/types/src/internal/common/types/entity.d.ts +59 -2
- package/dist/types/src/internal/common/types/entity.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/index.d.ts +1 -1
- package/dist/types/src/internal/common/types/index.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/meta.d.ts +13 -7
- package/dist/types/src/internal/common/types/meta.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/model-symbols.d.ts +8 -4
- package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/typename.d.ts +7 -0
- package/dist/types/src/internal/common/types/typename.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/well-known-types.d.ts +11 -0
- package/dist/types/src/internal/common/types/well-known-types.d.ts.map +1 -0
- package/dist/types/src/internal/index.d.ts +1 -0
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +32 -38
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +5 -3
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -23
- package/src/Annotation.test.ts +439 -0
- package/src/Annotation.ts +151 -4
- package/src/Collection.ts +5 -9
- package/src/Database.ts +86 -61
- package/src/Dataset.ts +10 -2
- package/src/Entity.test.ts +116 -6
- package/src/Entity.ts +116 -23
- package/src/Err.ts +4 -4
- package/src/Feed.ts +57 -40
- package/src/Filter.ts +49 -27
- package/src/Hypergraph.ts +13 -8
- package/src/Json.test.ts +4 -4
- package/src/Json.ts +7 -6
- package/src/Key.ts +1 -1
- package/src/Migration.ts +27 -19
- package/src/Obj.test.ts +19 -8
- package/src/Obj.ts +131 -70
- package/src/Query.test.ts +147 -151
- package/src/Query.ts +133 -75
- package/src/QueryResult.ts +11 -0
- package/src/Ref.ts +21 -5
- package/src/Registry.ts +155 -0
- package/src/Relation.test.ts +10 -10
- package/src/Relation.ts +89 -52
- package/src/Scope.ts +50 -0
- package/src/StateMap.test.ts +56 -0
- package/src/StateMap.ts +99 -0
- package/src/Tag.md +88 -0
- package/src/Tag.ts +49 -6
- package/src/TagIndex.test.ts +57 -0
- package/src/TagIndex.ts +110 -0
- package/src/Tagging.ts +83 -0
- package/src/Type.test.ts +223 -18
- package/src/Type.ts +601 -131
- package/src/View.ts +10 -19
- package/src/index.ts +6 -4
- package/src/internal/Annotation/annotations.test.ts +31 -11
- package/src/internal/Annotation/annotations.ts +122 -103
- package/src/internal/Annotation/dictionary.ts +47 -0
- package/src/internal/Annotation/entity-dictionary.ts +40 -0
- package/src/internal/Annotation/index.ts +4 -2
- package/src/internal/Annotation/util.ts +17 -8
- package/src/internal/Entity/api.ts +7 -7
- package/src/internal/Entity/entity.ts +196 -47
- package/src/internal/Entity/guard.ts +26 -0
- package/src/internal/Entity/index.ts +2 -0
- package/src/internal/Entity/model.ts +35 -28
- package/src/internal/Entity/object.ts +21 -5
- package/src/internal/Entity/relation.ts +68 -34
- package/src/internal/Entity/type-kind.ts +75 -0
- package/src/internal/Entity/type-uri.ts +87 -0
- package/src/internal/Entity/util.ts +10 -9
- package/src/internal/Format/date.ts +0 -4
- package/src/internal/Format/format.test.ts +21 -0
- package/src/internal/Format/index.ts +2 -3
- package/src/internal/Format/object.ts +21 -4
- package/src/internal/Format/types.ts +1 -1
- package/src/internal/JsonSchema/annotations.ts +1 -1
- package/src/internal/JsonSchema/json-schema.test.ts +54 -140
- package/src/internal/JsonSchema/json-schema.ts +44 -30
- package/src/internal/Obj/clone.ts +9 -4
- package/src/internal/Obj/create-object.test.ts +12 -10
- package/src/internal/Obj/create-object.ts +67 -22
- package/src/internal/Obj/index.ts +0 -1
- package/src/internal/Obj/inspect.ts +4 -3
- package/src/internal/Obj/json-serializer.test.ts +100 -21
- package/src/internal/Obj/json-serializer.ts +93 -38
- package/src/internal/Obj/set-value.test.ts +7 -30
- package/src/internal/Obj/snapshot.ts +11 -4
- package/src/internal/Obj/typed-object.test.ts +9 -11
- package/src/internal/Obj/typed-object.ts +1 -1
- package/src/internal/Query.ts +14 -11
- package/src/internal/Ref/ref-array.ts +3 -3
- package/src/internal/Ref/ref.test.ts +17 -26
- package/src/internal/Ref/ref.ts +107 -59
- package/src/internal/Type/compose.test.ts +3 -1
- package/src/internal/Type/index.ts +1 -2
- package/src/internal/Type/manipulation.ts +0 -25
- package/src/internal/Type/type-schema.ts +60 -0
- package/src/internal/common/README.md +1 -1
- package/src/internal/common/api/meta.ts +16 -14
- package/src/internal/common/proxy/change.test.ts +35 -27
- package/src/internal/common/proxy/handler.test.ts +1 -1
- package/src/internal/common/proxy/json-serializer.ts +26 -16
- package/src/internal/common/proxy/make-object.ts +43 -20
- package/src/internal/common/proxy/ownership.ts +2 -2
- package/src/internal/common/proxy/schema.test.ts +48 -86
- package/src/internal/common/proxy/typed-handler.test.ts +12 -11
- package/src/internal/common/proxy/typed-handler.ts +71 -9
- package/src/internal/common/proxy/typed-object.test.ts +15 -27
- package/src/internal/common/types/base.ts +4 -4
- package/src/internal/common/types/entity.ts +80 -1
- package/src/internal/common/types/index.ts +6 -1
- package/src/internal/common/types/meta.ts +37 -14
- package/src/internal/common/types/model-symbols.ts +16 -4
- package/src/internal/common/types/typename.ts +39 -3
- package/src/internal/common/types/well-known-types.ts +15 -0
- package/src/internal/index.ts +5 -0
- package/src/testing/api.test.ts +15 -9
- package/src/testing/test-data.ts +24 -24
- package/src/testing/test-schema.ts +22 -58
- package/src/testing/util.ts +14 -11
- package/dist/lib/neutral/Extension.mjs +0 -18
- package/dist/lib/neutral/SchemaRegistry.mjs +0 -2
- package/dist/lib/neutral/chunk-5SL5LDLD.mjs +0 -47
- package/dist/lib/neutral/chunk-5SL5LDLD.mjs.map +0 -7
- package/dist/lib/neutral/chunk-7RVZT53K.mjs.map +0 -7
- package/dist/lib/neutral/chunk-APJKDGFL.mjs.map +0 -7
- package/dist/lib/neutral/chunk-BICZKPQG.mjs +0 -7
- package/dist/lib/neutral/chunk-BICZKPQG.mjs.map +0 -7
- package/dist/lib/neutral/chunk-BMB7IHGB.mjs.map +0 -7
- package/dist/lib/neutral/chunk-FIWO2FZK.mjs.map +0 -7
- package/dist/lib/neutral/chunk-G54OX4IX.mjs.map +0 -7
- package/dist/lib/neutral/chunk-GWFFC34K.mjs +0 -50
- package/dist/lib/neutral/chunk-GWFFC34K.mjs.map +0 -7
- package/dist/lib/neutral/chunk-I2DARWPX.mjs +0 -128
- package/dist/lib/neutral/chunk-I2DARWPX.mjs.map +0 -7
- package/dist/lib/neutral/chunk-J54QMAKF.mjs.map +0 -7
- package/dist/lib/neutral/chunk-MGSQGHOD.mjs +0 -206
- package/dist/lib/neutral/chunk-MGSQGHOD.mjs.map +0 -7
- package/dist/lib/neutral/chunk-MLS7U7AT.mjs.map +0 -7
- package/dist/lib/neutral/chunk-N4B7FHQT.mjs.map +0 -7
- package/dist/lib/neutral/chunk-N7VOEPSV.mjs.map +0 -7
- package/dist/lib/neutral/chunk-PSZBLH53.mjs +0 -81
- package/dist/lib/neutral/chunk-PSZBLH53.mjs.map +0 -7
- package/dist/lib/neutral/chunk-PT37DG2F.mjs.map +0 -7
- package/dist/lib/neutral/chunk-Q2KKKJSV.mjs +0 -56
- package/dist/lib/neutral/chunk-Q2KKKJSV.mjs.map +0 -7
- package/dist/lib/neutral/chunk-Q7ZL2P5H.mjs.map +0 -7
- package/dist/lib/neutral/chunk-SCPFDS2E.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TNBK56IN.mjs +0 -350
- package/dist/lib/neutral/chunk-TNBK56IN.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TRPZU2HV.mjs.map +0 -7
- package/dist/lib/neutral/chunk-V72DY6LU.mjs.map +0 -7
- package/dist/lib/neutral/chunk-ZFACXBY6.mjs.map +0 -7
- package/dist/lib/neutral/chunk-ZISMEVKD.mjs.map +0 -7
- package/dist/types/src/Extension.d.ts +0 -80
- package/dist/types/src/Extension.d.ts.map +0 -1
- package/dist/types/src/Extension.test.d.ts +0 -2
- package/dist/types/src/Extension.test.d.ts.map +0 -1
- package/dist/types/src/SchemaRegistry.d.ts +0 -84
- package/dist/types/src/SchemaRegistry.d.ts.map +0 -1
- package/dist/types/src/internal/Obj/ids.d.ts +0 -6
- package/dist/types/src/internal/Obj/ids.d.ts.map +0 -1
- package/dist/types/src/internal/Type/echo-schema.d.ts +0 -181
- package/dist/types/src/internal/Type/echo-schema.d.ts.map +0 -1
- package/dist/types/src/internal/Type/persistent-schema.d.ts +0 -20
- package/dist/types/src/internal/Type/persistent-schema.d.ts.map +0 -1
- package/src/Extension.test.ts +0 -235
- package/src/Extension.ts +0 -122
- package/src/SchemaRegistry.ts +0 -106
- package/src/internal/Obj/ids.ts +0 -12
- package/src/internal/Type/echo-schema.ts +0 -423
- package/src/internal/Type/persistent-schema.ts +0 -33
- /package/dist/lib/neutral/{Extension.mjs.map → Registry.mjs.map} +0 -0
- /package/dist/lib/neutral/{SchemaRegistry.mjs.map → Scope.mjs.map} +0 -0
- /package/dist/lib/neutral/{chunk-QRZ2I3ZM.mjs.map → chunk-G6CFWUYH.mjs.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.d9fc60f731",
|
|
4
4
|
"description": "ECHO API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -103,15 +103,20 @@
|
|
|
103
103
|
"types": "./dist/types/src/Ref.d.ts",
|
|
104
104
|
"default": "./dist/lib/neutral/Ref.mjs"
|
|
105
105
|
},
|
|
106
|
+
"./Registry": {
|
|
107
|
+
"source": "./src/Registry.ts",
|
|
108
|
+
"types": "./dist/types/src/Registry.d.ts",
|
|
109
|
+
"default": "./dist/lib/neutral/Registry.mjs"
|
|
110
|
+
},
|
|
106
111
|
"./Relation": {
|
|
107
112
|
"source": "./src/Relation.ts",
|
|
108
113
|
"types": "./dist/types/src/Relation.d.ts",
|
|
109
114
|
"default": "./dist/lib/neutral/Relation.mjs"
|
|
110
115
|
},
|
|
111
|
-
"./
|
|
112
|
-
"source": "./src/
|
|
113
|
-
"types": "./dist/types/src/
|
|
114
|
-
"default": "./dist/lib/neutral/
|
|
116
|
+
"./Scope": {
|
|
117
|
+
"source": "./src/Scope.ts",
|
|
118
|
+
"types": "./dist/types/src/Scope.d.ts",
|
|
119
|
+
"default": "./dist/lib/neutral/Scope.mjs"
|
|
115
120
|
},
|
|
116
121
|
"./Tag": {
|
|
117
122
|
"source": "./src/Tag.ts",
|
|
@@ -122,11 +127,6 @@
|
|
|
122
127
|
"source": "./src/Type.ts",
|
|
123
128
|
"types": "./dist/types/src/Type.d.ts",
|
|
124
129
|
"default": "./dist/lib/neutral/Type.mjs"
|
|
125
|
-
},
|
|
126
|
-
"./Extension": {
|
|
127
|
-
"source": "./src/Extension.ts",
|
|
128
|
-
"types": "./dist/types/src/Extension.d.ts",
|
|
129
|
-
"default": "./dist/lib/neutral/Extension.mjs"
|
|
130
130
|
}
|
|
131
131
|
},
|
|
132
132
|
"files": [
|
|
@@ -134,19 +134,17 @@
|
|
|
134
134
|
"src"
|
|
135
135
|
],
|
|
136
136
|
"dependencies": {
|
|
137
|
-
"effect": "3.
|
|
138
|
-
"@dxos/async": "0.8.4-main.
|
|
139
|
-
"@dxos/
|
|
140
|
-
"@dxos/echo-protocol": "0.8.4-main.
|
|
141
|
-
"@dxos/effect": "0.8.4-main.
|
|
142
|
-
"@dxos/
|
|
143
|
-
"@dxos/
|
|
144
|
-
"@dxos/keys": "0.8.4-main.
|
|
145
|
-
"@dxos/
|
|
146
|
-
"@dxos/node-std": "0.8.4-main.
|
|
147
|
-
"@dxos/
|
|
148
|
-
"@dxos/util": "0.8.4-main.d05539e30a",
|
|
149
|
-
"@dxos/errors": "0.8.4-main.d05539e30a"
|
|
137
|
+
"effect": "3.21.2",
|
|
138
|
+
"@dxos/async": "0.8.4-main.d9fc60f731",
|
|
139
|
+
"@dxos/debug": "0.8.4-main.d9fc60f731",
|
|
140
|
+
"@dxos/echo-protocol": "0.8.4-main.d9fc60f731",
|
|
141
|
+
"@dxos/effect": "0.8.4-main.d9fc60f731",
|
|
142
|
+
"@dxos/errors": "0.8.4-main.d9fc60f731",
|
|
143
|
+
"@dxos/log": "0.8.4-main.d9fc60f731",
|
|
144
|
+
"@dxos/keys": "0.8.4-main.d9fc60f731",
|
|
145
|
+
"@dxos/invariant": "0.8.4-main.d9fc60f731",
|
|
146
|
+
"@dxos/node-std": "0.8.4-main.d9fc60f731",
|
|
147
|
+
"@dxos/util": "0.8.4-main.d9fc60f731"
|
|
150
148
|
},
|
|
151
149
|
"publishConfig": {
|
|
152
150
|
"access": "public"
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Option from 'effect/Option';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
+
import { describe, test } from 'vitest';
|
|
9
|
+
|
|
10
|
+
import { DXN } from '@dxos/keys';
|
|
11
|
+
|
|
12
|
+
import * as Annotation from './Annotation';
|
|
13
|
+
import * as Obj from './Obj';
|
|
14
|
+
import * as Type from './Type';
|
|
15
|
+
|
|
16
|
+
describe('Annotation', () => {
|
|
17
|
+
describe('make', () => {
|
|
18
|
+
test('creates an annotation with a string schema', ({ expect }) => {
|
|
19
|
+
const ColorAnnotation = Annotation.make({
|
|
20
|
+
id: 'org.dxos.annotation.color',
|
|
21
|
+
schema: Schema.String,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
expect(ColorAnnotation.key).toBe('org.dxos.annotation.color');
|
|
25
|
+
expect(ColorAnnotation.schema).toBe(Schema.String);
|
|
26
|
+
expect(ColorAnnotation[Annotation.TypeId]).toBeDefined();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('creates an annotation with a number schema', ({ expect }) => {
|
|
30
|
+
const PriorityAnnotation = Annotation.make({
|
|
31
|
+
id: 'org.dxos.annotation.priority',
|
|
32
|
+
schema: Schema.Number,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect(PriorityAnnotation.key).toBe('org.dxos.annotation.priority');
|
|
36
|
+
expect(PriorityAnnotation.schema).toBe(Schema.Number);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('creates an annotation with a complex schema', ({ expect }) => {
|
|
40
|
+
const MetadataSchema = Schema.Struct({
|
|
41
|
+
author: Schema.String,
|
|
42
|
+
version: Schema.Number,
|
|
43
|
+
tags: Schema.Array(Schema.String),
|
|
44
|
+
});
|
|
45
|
+
const MetadataAnnotation = Annotation.make({
|
|
46
|
+
id: 'org.dxos.annotation.metadata',
|
|
47
|
+
schema: MetadataSchema,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(MetadataAnnotation.key).toBe('org.dxos.annotation.metadata');
|
|
51
|
+
expect(MetadataAnnotation.schema).toBe(MetadataSchema);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('getDictionary and setDictionary', () => {
|
|
56
|
+
test('set and get a string value', ({ expect }) => {
|
|
57
|
+
const ColorAnnotation = Annotation.make({
|
|
58
|
+
id: 'org.dxos.annotation.color',
|
|
59
|
+
schema: Schema.String,
|
|
60
|
+
});
|
|
61
|
+
const values: Annotation.Dictionary = {};
|
|
62
|
+
|
|
63
|
+
Annotation.setDictionary(values, ColorAnnotation, 'red');
|
|
64
|
+
const result = Annotation.getDictionary(values, ColorAnnotation);
|
|
65
|
+
|
|
66
|
+
expect(Option.isSome(result)).toBe(true);
|
|
67
|
+
expect(Option.getOrThrow(result)).toBe('red');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('set and get a number value', ({ expect }) => {
|
|
71
|
+
const PriorityAnnotation = Annotation.make({
|
|
72
|
+
id: 'org.dxos.annotation.priority',
|
|
73
|
+
schema: Schema.Number,
|
|
74
|
+
});
|
|
75
|
+
const values: Annotation.Dictionary = {};
|
|
76
|
+
|
|
77
|
+
Annotation.setDictionary(values, PriorityAnnotation, 42);
|
|
78
|
+
const result = Annotation.getDictionary(values, PriorityAnnotation);
|
|
79
|
+
|
|
80
|
+
expect(Option.isSome(result)).toBe(true);
|
|
81
|
+
expect(Option.getOrThrow(result)).toBe(42);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('set and get a boolean value', ({ expect }) => {
|
|
85
|
+
const EnabledAnnotation = Annotation.make({
|
|
86
|
+
id: 'org.dxos.annotation.enabled',
|
|
87
|
+
schema: Schema.Boolean,
|
|
88
|
+
});
|
|
89
|
+
const values: Annotation.Dictionary = {};
|
|
90
|
+
|
|
91
|
+
Annotation.setDictionary(values, EnabledAnnotation, true);
|
|
92
|
+
const result = Annotation.getDictionary(values, EnabledAnnotation);
|
|
93
|
+
|
|
94
|
+
expect(Option.isSome(result)).toBe(true);
|
|
95
|
+
expect(Option.getOrThrow(result)).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('set and get a complex object value', ({ expect }) => {
|
|
99
|
+
const ConfigSchema = Schema.Struct({
|
|
100
|
+
theme: Schema.String,
|
|
101
|
+
fontSize: Schema.Number,
|
|
102
|
+
darkMode: Schema.Boolean,
|
|
103
|
+
});
|
|
104
|
+
const ConfigAnnotation = Annotation.make({
|
|
105
|
+
id: 'org.dxos.annotation.config',
|
|
106
|
+
schema: ConfigSchema,
|
|
107
|
+
});
|
|
108
|
+
const values: Annotation.Dictionary = {};
|
|
109
|
+
|
|
110
|
+
const config = { theme: 'modern', fontSize: 14, darkMode: true };
|
|
111
|
+
Annotation.setDictionary(values, ConfigAnnotation, config);
|
|
112
|
+
const result = Annotation.getDictionary(values, ConfigAnnotation);
|
|
113
|
+
|
|
114
|
+
expect(Option.isSome(result)).toBe(true);
|
|
115
|
+
expect(Option.getOrThrow(result)).toEqual(config);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('set and get an array value', ({ expect }) => {
|
|
119
|
+
const TagsAnnotation = Annotation.make({
|
|
120
|
+
id: 'org.dxos.annotation.tags',
|
|
121
|
+
schema: Schema.Array(Schema.String),
|
|
122
|
+
});
|
|
123
|
+
const values: Annotation.Dictionary = {};
|
|
124
|
+
|
|
125
|
+
const tags = ['important', 'urgent', 'review'];
|
|
126
|
+
Annotation.setDictionary(values, TagsAnnotation, tags);
|
|
127
|
+
const result = Annotation.getDictionary(values, TagsAnnotation);
|
|
128
|
+
|
|
129
|
+
expect(Option.isSome(result)).toBe(true);
|
|
130
|
+
expect(Option.getOrThrow(result)).toEqual(tags);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('get returns None for missing annotation', ({ expect }) => {
|
|
134
|
+
const ColorAnnotation = Annotation.make({
|
|
135
|
+
id: 'org.dxos.annotation.color',
|
|
136
|
+
schema: Schema.String,
|
|
137
|
+
});
|
|
138
|
+
const values: Annotation.Dictionary = {};
|
|
139
|
+
|
|
140
|
+
const result = Annotation.getDictionary(values, ColorAnnotation);
|
|
141
|
+
|
|
142
|
+
expect(Option.isNone(result)).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('overwriting an annotation value', ({ expect }) => {
|
|
146
|
+
const ColorAnnotation = Annotation.make({
|
|
147
|
+
id: 'org.dxos.annotation.color',
|
|
148
|
+
schema: Schema.String,
|
|
149
|
+
});
|
|
150
|
+
const values: Annotation.Dictionary = {};
|
|
151
|
+
|
|
152
|
+
Annotation.setDictionary(values, ColorAnnotation, 'red');
|
|
153
|
+
Annotation.setDictionary(values, ColorAnnotation, 'blue');
|
|
154
|
+
const result = Annotation.getDictionary(values, ColorAnnotation);
|
|
155
|
+
|
|
156
|
+
expect(Option.isSome(result)).toBe(true);
|
|
157
|
+
expect(Option.getOrThrow(result)).toBe('blue');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('multiple annotations on the same dictionary', ({ expect }) => {
|
|
161
|
+
const ColorAnnotation = Annotation.make({
|
|
162
|
+
id: 'org.dxos.annotation.color',
|
|
163
|
+
schema: Schema.String,
|
|
164
|
+
});
|
|
165
|
+
const PriorityAnnotation = Annotation.make({
|
|
166
|
+
id: 'org.dxos.annotation.priority',
|
|
167
|
+
schema: Schema.Number,
|
|
168
|
+
});
|
|
169
|
+
const EnabledAnnotation = Annotation.make({
|
|
170
|
+
id: 'org.dxos.annotation.enabled',
|
|
171
|
+
schema: Schema.Boolean,
|
|
172
|
+
});
|
|
173
|
+
const values: Annotation.Dictionary = {};
|
|
174
|
+
|
|
175
|
+
Annotation.setDictionary(values, ColorAnnotation, 'green');
|
|
176
|
+
Annotation.setDictionary(values, PriorityAnnotation, 5);
|
|
177
|
+
Annotation.setDictionary(values, EnabledAnnotation, false);
|
|
178
|
+
|
|
179
|
+
expect(Option.getOrThrow(Annotation.getDictionary(values, ColorAnnotation))).toBe('green');
|
|
180
|
+
expect(Option.getOrThrow(Annotation.getDictionary(values, PriorityAnnotation))).toBe(5);
|
|
181
|
+
expect(Option.getOrThrow(Annotation.getDictionary(values, EnabledAnnotation))).toBe(false);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('curried forms', () => {
|
|
186
|
+
test('getDictionary curried form', ({ expect }) => {
|
|
187
|
+
const ColorAnnotation = Annotation.make({
|
|
188
|
+
id: 'org.dxos.annotation.color',
|
|
189
|
+
schema: Schema.String,
|
|
190
|
+
});
|
|
191
|
+
const values: Annotation.Dictionary = {};
|
|
192
|
+
Annotation.setDictionary(values, ColorAnnotation, 'purple');
|
|
193
|
+
|
|
194
|
+
const getColor = Annotation.getDictionary(ColorAnnotation);
|
|
195
|
+
const result = getColor(values);
|
|
196
|
+
|
|
197
|
+
expect(Option.isSome(result)).toBe(true);
|
|
198
|
+
expect(Option.getOrThrow(result)).toBe('purple');
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('setDictionary curried form', ({ expect }) => {
|
|
202
|
+
const ColorAnnotation = Annotation.make({
|
|
203
|
+
id: 'org.dxos.annotation.color',
|
|
204
|
+
schema: Schema.String,
|
|
205
|
+
});
|
|
206
|
+
const values: Annotation.Dictionary = {};
|
|
207
|
+
|
|
208
|
+
const setOrange = Annotation.setDictionary(ColorAnnotation, 'orange');
|
|
209
|
+
setOrange(values);
|
|
210
|
+
const result = Annotation.getDictionary(values, ColorAnnotation);
|
|
211
|
+
|
|
212
|
+
expect(Option.isSome(result)).toBe(true);
|
|
213
|
+
expect(Option.getOrThrow(result)).toBe('orange');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('curried forms work in pipelines', ({ expect }) => {
|
|
217
|
+
const ColorAnnotation = Annotation.make({
|
|
218
|
+
id: 'org.dxos.annotation.color',
|
|
219
|
+
schema: Schema.String,
|
|
220
|
+
});
|
|
221
|
+
const values: Annotation.Dictionary = {};
|
|
222
|
+
|
|
223
|
+
Annotation.setDictionary(ColorAnnotation, 'cyan')(values);
|
|
224
|
+
const result = Annotation.getDictionary(ColorAnnotation)(values);
|
|
225
|
+
|
|
226
|
+
expect(Option.isSome(result)).toBe(true);
|
|
227
|
+
expect(Option.getOrThrow(result)).toBe('cyan');
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
describe('Key', () => {
|
|
232
|
+
test('Key.make creates a branded key', ({ expect }) => {
|
|
233
|
+
const key = Annotation.Key.make('org.dxos.annotation.my-annotation');
|
|
234
|
+
|
|
235
|
+
expect(key).toBe('org.dxos.annotation.my-annotation');
|
|
236
|
+
expect(typeof key).toBe('string');
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe('Dictionary schema', () => {
|
|
241
|
+
test('Dictionary can be used as a schema', ({ expect }) => {
|
|
242
|
+
const PersonWithAnnotations = Schema.Struct({
|
|
243
|
+
name: Schema.String,
|
|
244
|
+
extensions: Annotation.Dictionary,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const person = Schema.decodeUnknownSync(PersonWithAnnotations)({
|
|
248
|
+
name: 'Alice',
|
|
249
|
+
extensions: {},
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
expect(person.name).toBe('Alice');
|
|
253
|
+
expect(person.extensions).toEqual({});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test('Dictionary schema accepts annotation data', ({ expect }) => {
|
|
257
|
+
const ColorAnnotation = Annotation.make({
|
|
258
|
+
id: 'org.dxos.annotation.color',
|
|
259
|
+
schema: Schema.String,
|
|
260
|
+
});
|
|
261
|
+
const values: Annotation.Dictionary = {};
|
|
262
|
+
Annotation.setDictionary(values, ColorAnnotation, 'red');
|
|
263
|
+
|
|
264
|
+
const PersonWithAnnotations = Schema.Struct({
|
|
265
|
+
name: Schema.String,
|
|
266
|
+
extensions: Annotation.Dictionary,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const person = Schema.decodeUnknownSync(PersonWithAnnotations)({
|
|
270
|
+
name: 'Bob',
|
|
271
|
+
extensions: values,
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
expect(person.name).toBe('Bob');
|
|
275
|
+
const color = Annotation.getDictionary(person.extensions, ColorAnnotation);
|
|
276
|
+
expect(Option.getOrThrow(color)).toBe('red');
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
describe('TypeId', () => {
|
|
281
|
+
test('TypeId is a unique symbol-like string', ({ expect }) => {
|
|
282
|
+
expect(Annotation.TypeId).toBe('~@dxos/echo/Annotation');
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('annotations have TypeId property', ({ expect }) => {
|
|
286
|
+
const ColorAnnotation = Annotation.make({
|
|
287
|
+
id: 'org.dxos.annotation.color',
|
|
288
|
+
schema: Schema.String,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
expect(Annotation.TypeId in ColorAnnotation).toBe(true);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
describe('schema', () => {
|
|
296
|
+
test('set and get on a struct schema', ({ expect }) => {
|
|
297
|
+
const ColorAnnotation = Annotation.make({
|
|
298
|
+
id: 'org.dxos.annotation.color',
|
|
299
|
+
schema: Schema.String,
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
const PersonSchema = Schema.Struct({
|
|
303
|
+
name: Schema.String,
|
|
304
|
+
}).pipe(ColorAnnotation.set('crimson'));
|
|
305
|
+
|
|
306
|
+
const result = ColorAnnotation.get(PersonSchema);
|
|
307
|
+
|
|
308
|
+
expect(Option.isSome(result)).toBe(true);
|
|
309
|
+
expect(Option.getOrThrow(result)).toBe('crimson');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test('get returns None when annotation is not on schema', ({ expect }) => {
|
|
313
|
+
const ColorAnnotation = Annotation.make({
|
|
314
|
+
id: 'org.dxos.annotation.color',
|
|
315
|
+
schema: Schema.String,
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const PersonSchema = Schema.Struct({
|
|
319
|
+
name: Schema.String,
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
expect(Option.isNone(ColorAnnotation.get(PersonSchema))).toBe(true);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test('set and get on a property schema', ({ expect }) => {
|
|
326
|
+
const ColorAnnotation = Annotation.make({
|
|
327
|
+
id: 'org.dxos.annotation.color',
|
|
328
|
+
schema: Schema.String,
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const PersonSchema = Schema.Struct({
|
|
332
|
+
name: Schema.String.pipe(ColorAnnotation.set('navy')),
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
const nameProperty = SchemaAST.getPropertySignatures(PersonSchema.ast).find((prop) => prop.name === 'name');
|
|
336
|
+
expect(nameProperty).toBeDefined();
|
|
337
|
+
|
|
338
|
+
const result = ColorAnnotation.getFromAst(nameProperty!.type);
|
|
339
|
+
|
|
340
|
+
expect(Option.isSome(result)).toBe(true);
|
|
341
|
+
expect(Option.getOrThrow(result)).toBe('navy');
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test('annotation survives Type.makeObject and is readable from Type.getSchema', ({ expect }) => {
|
|
345
|
+
const ColorAnnotation = Annotation.make({
|
|
346
|
+
id: 'org.dxos.annotation.color',
|
|
347
|
+
schema: Schema.String,
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
const TaggedPerson = Schema.Struct({
|
|
351
|
+
name: Schema.String,
|
|
352
|
+
})
|
|
353
|
+
.pipe(ColorAnnotation.set('teal'))
|
|
354
|
+
.pipe(Type.makeObject(DXN.make('com.example.type.taggedperson', '0.1.0')));
|
|
355
|
+
|
|
356
|
+
const schema = Type.getSchema(TaggedPerson);
|
|
357
|
+
const result = ColorAnnotation.get(schema);
|
|
358
|
+
|
|
359
|
+
expect(Option.isSome(result)).toBe(true);
|
|
360
|
+
expect(Option.getOrThrow(result)).toBe('teal');
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
describe('object', () => {
|
|
365
|
+
const ColorAnnotation = Annotation.make({
|
|
366
|
+
id: 'org.dxos.annotation.color',
|
|
367
|
+
schema: Schema.String,
|
|
368
|
+
});
|
|
369
|
+
const Person = Schema.Struct({
|
|
370
|
+
name: Schema.String,
|
|
371
|
+
})
|
|
372
|
+
.pipe(ColorAnnotation.set('schema-teal'))
|
|
373
|
+
.pipe(Type.makeObject(DXN.make('com.example.type.taggedperson', '0.1.0')));
|
|
374
|
+
|
|
375
|
+
test('set and get on Obj.make instance', ({ expect }) => {
|
|
376
|
+
const person = Obj.make(Person, { name: 'Alice' });
|
|
377
|
+
|
|
378
|
+
Obj.update(person, (person) => {
|
|
379
|
+
Annotation.set(person, ColorAnnotation, 'instance-red');
|
|
380
|
+
});
|
|
381
|
+
const result = Annotation.get(person, ColorAnnotation);
|
|
382
|
+
|
|
383
|
+
expect(Option.isSome(result)).toBe(true);
|
|
384
|
+
expect(Option.getOrThrow(result)).toBe('instance-red');
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
test('get returns None when instance has no annotation value', ({ expect }) => {
|
|
388
|
+
const person = Obj.make(Person, { name: 'Bob' });
|
|
389
|
+
|
|
390
|
+
expect(Option.isNone(Annotation.get(person, ColorAnnotation))).toBe(true);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
test('instance annotation is independent of schema default', ({ expect }) => {
|
|
394
|
+
const person = Obj.make(Person, { name: 'Carol' });
|
|
395
|
+
|
|
396
|
+
expect(Option.getOrThrow(ColorAnnotation.get(Type.getSchema(Person)))).toBe('schema-teal');
|
|
397
|
+
expect(Option.isNone(Annotation.get(person, ColorAnnotation))).toBe(true);
|
|
398
|
+
|
|
399
|
+
Obj.update(person, (person) => {
|
|
400
|
+
Annotation.set(person, ColorAnnotation, 'instance-blue');
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
expect(Option.getOrThrow(Annotation.get(person, ColorAnnotation))).toBe('instance-blue');
|
|
404
|
+
expect(Option.getOrThrow(ColorAnnotation.get(Type.getSchema(Person)))).toBe('schema-teal');
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test('set and get inside Obj.update', ({ expect }) => {
|
|
408
|
+
const person = Obj.make(Person, { name: 'Dana' });
|
|
409
|
+
|
|
410
|
+
Obj.update(person, (person) => {
|
|
411
|
+
Annotation.set(person, ColorAnnotation, 'updated');
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
expect(Option.getOrThrow(Annotation.get(person, ColorAnnotation))).toBe('updated');
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test('curried get and set on instances', ({ expect }) => {
|
|
418
|
+
const person = Obj.make(Person, { name: 'Eve' });
|
|
419
|
+
|
|
420
|
+
Obj.update(person, (person) => {
|
|
421
|
+
Annotation.set(ColorAnnotation, 'curried')(person);
|
|
422
|
+
});
|
|
423
|
+
const result = Annotation.get(ColorAnnotation)(person);
|
|
424
|
+
|
|
425
|
+
expect(Option.isSome(result)).toBe(true);
|
|
426
|
+
expect(Option.getOrThrow(result)).toBe('curried');
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
test('get reads annotation from a snapshot', ({ expect }) => {
|
|
430
|
+
const person = Obj.make(Person, { name: 'Frank' });
|
|
431
|
+
Obj.update(person, (person) => {
|
|
432
|
+
Annotation.set(person, ColorAnnotation, 'snapshot-color');
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
const snapshot = Obj.getSnapshot(person);
|
|
436
|
+
expect(Option.getOrThrow(Annotation.get(snapshot, ColorAnnotation))).toBe('snapshot-color');
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
});
|
package/src/Annotation.ts
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
export {
|
|
8
8
|
DescriptionAnnotation,
|
|
9
9
|
FormInputAnnotation,
|
|
10
|
+
FormInlineAnnotation,
|
|
10
11
|
GeneratorAnnotation,
|
|
11
12
|
LabelAnnotation,
|
|
12
13
|
ReferenceAnnotation,
|
|
13
|
-
|
|
14
|
+
HiddenAnnotation,
|
|
14
15
|
TypeAnnotation,
|
|
15
16
|
getDescriptionWithSchema,
|
|
16
17
|
getLabelWithSchema,
|
|
@@ -21,10 +22,68 @@ export {
|
|
|
21
22
|
IconFromRefAnnotation,
|
|
22
23
|
} from './internal/Annotation';
|
|
23
24
|
|
|
24
|
-
import
|
|
25
|
+
import * as Function from 'effect/Function';
|
|
26
|
+
import * as Option from 'effect/Option';
|
|
27
|
+
import * as Schema from 'effect/Schema';
|
|
28
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
29
|
+
import * as Types from 'effect/Types';
|
|
25
30
|
|
|
31
|
+
import * as Entity from './Entity';
|
|
26
32
|
import * as internalAnnotations from './internal/Annotation';
|
|
27
33
|
|
|
34
|
+
export const TypeId = '~@dxos/echo/Annotation' as const;
|
|
35
|
+
export type TypeId = typeof TypeId;
|
|
36
|
+
|
|
37
|
+
// TODO(dmaretskyi): Reconcile different get/set styles: mutate in-place, return.
|
|
38
|
+
// TODO(dmaretskyi): Reconcile Annotation methods vs static functions.
|
|
39
|
+
// TODO(dmaretskyi): Reconcile Annotation.Key vs DXN -- work-out approach to versioning.
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Annotation is a typed property that can be assigned to a schema or an entity instance.
|
|
43
|
+
*/
|
|
44
|
+
export interface Annotation<T> {
|
|
45
|
+
[TypeId]: {
|
|
46
|
+
_Type: T;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// TODO(dmaretskyi): Make this a DXN?
|
|
50
|
+
/**
|
|
51
|
+
* Unique fully-qualified identifier for the annotation.
|
|
52
|
+
* @example "org.dxos.annotation.color"
|
|
53
|
+
*/
|
|
54
|
+
readonly key: Key;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Schema of the annotation value.
|
|
58
|
+
*/
|
|
59
|
+
readonly schema: Schema.Schema<T, unknown, never>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get the annotation value from an Effect schema.
|
|
63
|
+
*
|
|
64
|
+
* Only accepts `Schema.Schema.Any` — to read an annotation off a `Type.Type`
|
|
65
|
+
* entity, unwrap it first with `Type.getSchema(entity)`. This keeps the
|
|
66
|
+
* annotation pipeline single-shaped and forces annotations to live on the
|
|
67
|
+
* source schema, not on the post-construction Type entity.
|
|
68
|
+
*/
|
|
69
|
+
get: (schema: Schema.Schema.Any) => Option.Option<T>;
|
|
70
|
+
/**
|
|
71
|
+
* Get the annotation value from the AST.
|
|
72
|
+
*/
|
|
73
|
+
getFromAst: (ast: SchemaAST.AST) => Option.Option<T>;
|
|
74
|
+
/**
|
|
75
|
+
* Set the annotation on an Effect schema.
|
|
76
|
+
*
|
|
77
|
+
* Only accepts `Schema.Schema.Any` — annotations must be applied to the
|
|
78
|
+
* source schema BEFORE wrapping it with `Type.makeObject` / `Type.makeRelation`.
|
|
79
|
+
* In a pipe, place every `Annotation.X.set(...)` before the `Type.make...` step.
|
|
80
|
+
*/
|
|
81
|
+
set: (value: T) => <S extends Schema.Schema.Any>(schema: S) => S;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const Key = internalAnnotations.Key;
|
|
85
|
+
export type Key = Schema.Schema.Type<typeof Key>;
|
|
86
|
+
|
|
28
87
|
interface MakeProps<T> {
|
|
29
88
|
id: string;
|
|
30
89
|
schema: Schema.Schema<T, any, never>;
|
|
@@ -45,5 +104,93 @@ interface MakeProps<T> {
|
|
|
45
104
|
* const schema = Schema.String.annotations(ColorAnnotation.set('red'));
|
|
46
105
|
* ```
|
|
47
106
|
*/
|
|
48
|
-
export const make: <T>(props: MakeProps<T>) =>
|
|
49
|
-
|
|
107
|
+
export const make: <T>(props: MakeProps<T>) => Annotation<T> = internalAnnotations.makeUserAnnotation;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get the value of an annotation from an entity instance or snapshot.
|
|
111
|
+
* For schema-level reads use the annotation instance method (e.g. `ColorAnnotation.get(schema)`).
|
|
112
|
+
* For getting an annotation value from a dictionary, use `getDictionary`.
|
|
113
|
+
*/
|
|
114
|
+
export const get: {
|
|
115
|
+
<T>(annotation: Annotation<T>): (target: Entity.Unknown | Entity.Snapshot) => Option.Option<T>;
|
|
116
|
+
<T>(target: Entity.Unknown | Entity.Snapshot, annotation: Annotation<T>): Option.Option<T>;
|
|
117
|
+
} = Function.dual<
|
|
118
|
+
<T>(annotation: Annotation<T>) => (target: Entity.Unknown | Entity.Snapshot) => Option.Option<T>,
|
|
119
|
+
<T>(target: Entity.Unknown | Entity.Snapshot, annotation: Annotation<T>) => Option.Option<T>
|
|
120
|
+
>(2, (target, annotation) => {
|
|
121
|
+
return internalAnnotations.get(target, annotation);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Set the value of an annotation on an entity instance.
|
|
126
|
+
* For schema-level writes use the annotation instance method (e.g. `ColorAnnotation.set('red')`).
|
|
127
|
+
* For setting an annotation value on a dictionary, use `setDictionary`.
|
|
128
|
+
*/
|
|
129
|
+
export const set: {
|
|
130
|
+
<T>(annotation: Annotation<T>, value: T): (target: Entity.Mutable<Entity.Unknown>) => void;
|
|
131
|
+
<T>(target: Entity.Mutable<Entity.Unknown>, annotation: Annotation<T>, value: T): void;
|
|
132
|
+
} = Function.dual<
|
|
133
|
+
<T>(annotation: Annotation<T>, value: T) => (target: Entity.Mutable<Entity.Unknown>) => void,
|
|
134
|
+
<T>(target: Entity.Mutable<Entity.Unknown>, annotation: Annotation<T>, value: T) => void
|
|
135
|
+
>(3, (target, annotation, value) => {
|
|
136
|
+
return internalAnnotations.set(target, annotation, value);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export const getFromAst: {
|
|
140
|
+
<T>(annotation: Annotation<T>): (ast: SchemaAST.AST) => Option.Option<T>;
|
|
141
|
+
<T>(ast: SchemaAST.AST, annotation: Annotation<T>): Option.Option<T>;
|
|
142
|
+
} = Function.dual<
|
|
143
|
+
<T>(annotation: Annotation<T>) => (ast: SchemaAST.AST) => Option.Option<T>,
|
|
144
|
+
<T>(ast: SchemaAST.AST, annotation: Annotation<T>) => Option.Option<T>
|
|
145
|
+
>(2, (ast, annotation) => {
|
|
146
|
+
return internalAnnotations.getFromAst(ast, annotation);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Set of annotation values.
|
|
151
|
+
*
|
|
152
|
+
* Can be used inside an object/relation schema:
|
|
153
|
+
*
|
|
154
|
+
* ```ts
|
|
155
|
+
* const Person = Schema.Struct({
|
|
156
|
+
* name: Schema.String,
|
|
157
|
+
* extensions: Annotation.Dictionary,
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export const Dictionary = internalAnnotations.Dictionary;
|
|
162
|
+
export interface Dictionary extends Schema.Schema.Type<typeof Dictionary> {}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get the value of an annotation from a Dictionary.
|
|
166
|
+
*/
|
|
167
|
+
export const getDictionary: {
|
|
168
|
+
<T>(annotation: Annotation<T>): (values: Dictionary) => Option.Option<T>;
|
|
169
|
+
<T>(values: Dictionary, annotation: Annotation<T>): Option.Option<T>;
|
|
170
|
+
} = Function.dual<
|
|
171
|
+
<T>(annotation: Annotation<T>) => (values: Dictionary) => Option.Option<T>,
|
|
172
|
+
<T>(values: Dictionary, annotation: Annotation<T>) => Option.Option<T>
|
|
173
|
+
>(2, (values, annotation) => {
|
|
174
|
+
return internalAnnotations.getDictionary(values, annotation);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Set the value of an annotation in a Dictionary.
|
|
179
|
+
*
|
|
180
|
+
* Can also be used within Obj.update callback:
|
|
181
|
+
*
|
|
182
|
+
* ```ts
|
|
183
|
+
* Obj.update(obj, (obj) => {
|
|
184
|
+
* Annotation.setDictionary(obj.annotations, ColorAnnotation, 'red');
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export const setDictionary: {
|
|
189
|
+
<T>(annotation: Annotation<T>, value: T): (values: Dictionary) => void;
|
|
190
|
+
<T>(values: Types.Mutable<Dictionary>, annotation: Annotation<T>, value: T): void;
|
|
191
|
+
} = Function.dual<
|
|
192
|
+
<T>(annotation: Annotation<T>, value: T) => (values: Dictionary) => void,
|
|
193
|
+
<T>(values: Types.Mutable<Dictionary>, annotation: Annotation<T>, value: T) => void
|
|
194
|
+
>(3, (values, annotation, value) => {
|
|
195
|
+
return internalAnnotations.setDictionary(values, annotation, value);
|
|
196
|
+
});
|