@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
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Service
|
|
3
|
-
} from "./chunk-I2DARWPX.mjs";
|
|
4
1
|
import {
|
|
5
2
|
ReferenceAnnotationId,
|
|
6
|
-
|
|
3
|
+
Service,
|
|
4
|
+
getSchemaURI,
|
|
7
5
|
getTypeAnnotation,
|
|
8
6
|
getTypeIdentifierAnnotation
|
|
9
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-H26LSXVJ.mjs";
|
|
8
|
+
import {
|
|
9
|
+
getStaticTypeSchema
|
|
10
|
+
} from "./chunk-O6BH7EPN.mjs";
|
|
10
11
|
|
|
11
12
|
// src/internal/Ref/ref.ts
|
|
12
13
|
import * as Effect from "effect/Effect";
|
|
@@ -21,15 +22,17 @@ import { Event } from "@dxos/async";
|
|
|
21
22
|
import { inspectCustom } from "@dxos/debug";
|
|
22
23
|
import { EncodedReference } from "@dxos/echo-protocol";
|
|
23
24
|
import { assertArgument, invariant } from "@dxos/invariant";
|
|
24
|
-
import { DXN,
|
|
25
|
+
import { DXN, EID, EntityId } from "@dxos/keys";
|
|
25
26
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Ref/ref.ts";
|
|
26
27
|
var JSON_SCHEMA_ECHO_REF_ID = "/schemas/echo/ref";
|
|
27
28
|
var getSchemaReference = (property) => {
|
|
28
29
|
const { $id, reference: { schema: { $ref } = {} } = {} } = property;
|
|
29
30
|
if ($id === JSON_SCHEMA_ECHO_REF_ID && $ref) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const parsed = DXN.tryMake($ref);
|
|
32
|
+
const typename = parsed ? DXN.getName(parsed) : void 0;
|
|
33
|
+
return typename ? {
|
|
34
|
+
typename
|
|
35
|
+
} : void 0;
|
|
33
36
|
}
|
|
34
37
|
};
|
|
35
38
|
var createSchemaReference = (typename) => {
|
|
@@ -37,7 +40,7 @@ var createSchemaReference = (typename) => {
|
|
|
37
40
|
$id: JSON_SCHEMA_ECHO_REF_ID,
|
|
38
41
|
reference: {
|
|
39
42
|
schema: {
|
|
40
|
-
$ref: DXN.
|
|
43
|
+
$ref: DXN.make(typename)
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
};
|
|
@@ -52,7 +55,8 @@ var getReferenceAst = (ast) => {
|
|
|
52
55
|
};
|
|
53
56
|
};
|
|
54
57
|
var RefTypeId = /* @__PURE__ */ Symbol("@dxos/echo/internal/Ref");
|
|
55
|
-
var Ref = (
|
|
58
|
+
var Ref = (input) => {
|
|
59
|
+
const schema = getStaticTypeSchema(input) ?? input;
|
|
56
60
|
assertArgument(Schema.isSchema(schema), "schema", "Must call with an instance of effect-schema");
|
|
57
61
|
const annotation = getTypeAnnotation(schema);
|
|
58
62
|
if (annotation == null) {
|
|
@@ -63,7 +67,10 @@ var Ref = (schema) => {
|
|
|
63
67
|
Ref.isRef = (obj) => {
|
|
64
68
|
return obj && typeof obj === "object" && RefTypeId in obj;
|
|
65
69
|
};
|
|
66
|
-
Ref.
|
|
70
|
+
Ref.hasEntityId = (id) => (ref) => {
|
|
71
|
+
const uri = EID.tryParse(ref.uri);
|
|
72
|
+
return uri !== void 0 && EID.isLocal(uri) && EID.getEntityId(uri) === id;
|
|
73
|
+
};
|
|
67
74
|
Ref.isRefSchema = (schema) => {
|
|
68
75
|
return Ref.isRefSchemaAST(schema.ast);
|
|
69
76
|
};
|
|
@@ -75,22 +82,24 @@ Ref.make = (obj) => {
|
|
|
75
82
|
throw new TypeError("Expected: ECHO object.");
|
|
76
83
|
}
|
|
77
84
|
const id = obj.id;
|
|
78
|
-
invariant(
|
|
79
|
-
const
|
|
80
|
-
|
|
85
|
+
invariant(EntityId.isValid(id), "Invalid object ID", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 85, S: void 0, A: ["EntityId.isValid(id)", "'Invalid object ID'"] });
|
|
86
|
+
const uri = EID.make({
|
|
87
|
+
entityId: id
|
|
88
|
+
});
|
|
89
|
+
return new RefImpl(uri, obj);
|
|
81
90
|
};
|
|
82
|
-
Ref.
|
|
83
|
-
assertArgument(
|
|
84
|
-
return new RefImpl(
|
|
91
|
+
Ref.fromURI = (uri) => {
|
|
92
|
+
assertArgument(typeof uri === "string", "uri", "Expected URI string");
|
|
93
|
+
return new RefImpl(uri);
|
|
85
94
|
};
|
|
86
|
-
var createEchoReferenceSchema = (
|
|
87
|
-
if (!
|
|
88
|
-
throw new TypeError("Either
|
|
95
|
+
var createEchoReferenceSchema = (echoUri, typename, version) => {
|
|
96
|
+
if (!echoUri && !typename) {
|
|
97
|
+
throw new TypeError("Either echoUri or typename must be provided.");
|
|
89
98
|
}
|
|
90
99
|
const referenceInfo = {
|
|
91
100
|
schema: {
|
|
92
101
|
// TODO(dmaretskyi): Include version?
|
|
93
|
-
$ref:
|
|
102
|
+
$ref: echoUri ?? DXN.make(typename)
|
|
94
103
|
},
|
|
95
104
|
schemaVersion: version
|
|
96
105
|
};
|
|
@@ -98,7 +107,7 @@ var createEchoReferenceSchema = (echoId, typename, version) => {
|
|
|
98
107
|
encode: () => {
|
|
99
108
|
return (value) => Effect.gen(function* () {
|
|
100
109
|
if (Ref.isRef(value)) {
|
|
101
|
-
return EncodedReference.
|
|
110
|
+
return EncodedReference.fromURI(value.uri);
|
|
102
111
|
} else if (EncodedReference.isEncodedReference(value)) {
|
|
103
112
|
return value;
|
|
104
113
|
}
|
|
@@ -110,7 +119,7 @@ var createEchoReferenceSchema = (echoId, typename, version) => {
|
|
|
110
119
|
const dbService = yield* Effect.serviceOption(Service);
|
|
111
120
|
if (Ref.isRef(value)) {
|
|
112
121
|
if (Option.isSome(dbService)) {
|
|
113
|
-
return dbService.value.db.makeRef(value.
|
|
122
|
+
return dbService.value.db.makeRef(value.uri);
|
|
114
123
|
} else {
|
|
115
124
|
return value;
|
|
116
125
|
}
|
|
@@ -119,9 +128,9 @@ var createEchoReferenceSchema = (echoId, typename, version) => {
|
|
|
119
128
|
return yield* Effect.fail(new ParseResult.Unexpected(value, "reference"));
|
|
120
129
|
}
|
|
121
130
|
if (Option.isSome(dbService)) {
|
|
122
|
-
return dbService.value.db.makeRef(EncodedReference.
|
|
131
|
+
return dbService.value.db.makeRef(EncodedReference.toURI(value));
|
|
123
132
|
} else {
|
|
124
|
-
return Ref.
|
|
133
|
+
return Ref.fromURI(EncodedReference.toURI(value));
|
|
125
134
|
}
|
|
126
135
|
});
|
|
127
136
|
}
|
|
@@ -140,7 +149,7 @@ var createEchoReferenceSchema = (echoId, typename, version) => {
|
|
|
140
149
|
return refSchema;
|
|
141
150
|
};
|
|
142
151
|
var RefImpl = class _RefImpl {
|
|
143
|
-
#
|
|
152
|
+
#uri;
|
|
144
153
|
#resolver = void 0;
|
|
145
154
|
#resolved = new Event();
|
|
146
155
|
/**
|
|
@@ -154,15 +163,15 @@ var RefImpl = class _RefImpl {
|
|
|
154
163
|
#resolverCallback = () => {
|
|
155
164
|
this.#resolved.emit();
|
|
156
165
|
};
|
|
157
|
-
constructor(
|
|
158
|
-
this.#
|
|
166
|
+
constructor(uri, target) {
|
|
167
|
+
this.#uri = uri;
|
|
159
168
|
this.#target = target;
|
|
160
169
|
}
|
|
161
170
|
/**
|
|
162
171
|
* @inheritdoc
|
|
163
172
|
*/
|
|
164
|
-
get
|
|
165
|
-
return this.#
|
|
173
|
+
get uri() {
|
|
174
|
+
return this.#uri;
|
|
166
175
|
}
|
|
167
176
|
/**
|
|
168
177
|
* @inheritdoc
|
|
@@ -177,8 +186,8 @@ var RefImpl = class _RefImpl {
|
|
|
177
186
|
if (this.#target) {
|
|
178
187
|
return this.#target;
|
|
179
188
|
}
|
|
180
|
-
invariant(this.#resolver, "Resolver is not set", { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
181
|
-
return this.#resolver.resolveSync(this.#
|
|
189
|
+
invariant(this.#resolver, "Resolver is not set", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 192, S: this, A: ["this.#resolver", "'Resolver is not set'"] });
|
|
190
|
+
return this.#resolver.resolveSync(this.#uri, true, this.#resolverCallback);
|
|
182
191
|
}
|
|
183
192
|
/**
|
|
184
193
|
* @inheritdoc
|
|
@@ -187,8 +196,8 @@ var RefImpl = class _RefImpl {
|
|
|
187
196
|
if (this.#target) {
|
|
188
197
|
return this.#target;
|
|
189
198
|
}
|
|
190
|
-
invariant(this.#resolver, "Resolver is not set", { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
191
|
-
const obj = await this.#resolver.resolve(this.#
|
|
199
|
+
invariant(this.#resolver, "Resolver is not set", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 201, S: this, A: ["this.#resolver", "'Resolver is not set'"] });
|
|
200
|
+
const obj = await this.#resolver.resolve(this.#uri);
|
|
192
201
|
if (obj == null) {
|
|
193
202
|
throw new Error("Object not found");
|
|
194
203
|
}
|
|
@@ -201,8 +210,8 @@ var RefImpl = class _RefImpl {
|
|
|
201
210
|
if (this.#target) {
|
|
202
211
|
return this.#target;
|
|
203
212
|
}
|
|
204
|
-
invariant(this.#resolver, "Resolver is not set", { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
205
|
-
return await this.#resolver.resolve(this.#
|
|
213
|
+
invariant(this.#resolver, "Resolver is not set", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 214, S: this, A: ["this.#resolver", "'Resolver is not set'"] });
|
|
214
|
+
return await this.#resolver.resolve(this.#uri);
|
|
206
215
|
}
|
|
207
216
|
/**
|
|
208
217
|
* @inheritdoc
|
|
@@ -216,13 +225,13 @@ var RefImpl = class _RefImpl {
|
|
|
216
225
|
* Clones the reference object.
|
|
217
226
|
*/
|
|
218
227
|
noInline() {
|
|
219
|
-
const ref = new _RefImpl(this.#
|
|
228
|
+
const ref = new _RefImpl(this.#uri, void 0);
|
|
220
229
|
ref.#resolver = this.#resolver;
|
|
221
230
|
return ref;
|
|
222
231
|
}
|
|
223
232
|
encode() {
|
|
224
233
|
return {
|
|
225
|
-
"/": this.#
|
|
234
|
+
"/": this.#uri,
|
|
226
235
|
...this.#target ? {
|
|
227
236
|
target: this.#target
|
|
228
237
|
} : {}
|
|
@@ -241,7 +250,7 @@ var RefImpl = class _RefImpl {
|
|
|
241
250
|
if (this.#target) {
|
|
242
251
|
return `Ref(${this.#target.toString()})`;
|
|
243
252
|
}
|
|
244
|
-
return `Ref(${this.#
|
|
253
|
+
return `Ref(${this.#uri.toString()})`;
|
|
245
254
|
}
|
|
246
255
|
[inspectCustom] = (depth, options, inspect) => {
|
|
247
256
|
return this.toString();
|
|
@@ -254,11 +263,11 @@ var RefImpl = class _RefImpl {
|
|
|
254
263
|
* so without this, each access would create a separate cache entry.
|
|
255
264
|
*/
|
|
256
265
|
[Hash.symbol]() {
|
|
257
|
-
return Hash.hash(this.#
|
|
266
|
+
return Hash.hash(this.#uri.toString());
|
|
258
267
|
}
|
|
259
268
|
/** Effect Equal trait. See {@link Hash.symbol} for rationale. */
|
|
260
269
|
[Equal.symbol](that) {
|
|
261
|
-
return that instanceof _RefImpl && this.#
|
|
270
|
+
return that instanceof _RefImpl && this.#uri === that.uri;
|
|
262
271
|
}
|
|
263
272
|
/**
|
|
264
273
|
* Internal method to set the resolver.
|
|
@@ -279,19 +288,19 @@ var RefImpl = class _RefImpl {
|
|
|
279
288
|
}
|
|
280
289
|
};
|
|
281
290
|
var setRefResolver = (ref, resolver) => {
|
|
282
|
-
invariant(ref instanceof RefImpl, "Ref is not an instance of RefImpl", { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
291
|
+
invariant(ref instanceof RefImpl, "Ref is not an instance of RefImpl", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 288, S: void 0, A: ["ref instanceof RefImpl", "'Ref is not an instance of RefImpl'"] });
|
|
283
292
|
ref._setResolver(resolver);
|
|
284
293
|
};
|
|
285
294
|
var getRefSavedTarget = (ref) => {
|
|
286
|
-
invariant(ref instanceof RefImpl, "Ref is not an instance of RefImpl", { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
295
|
+
invariant(ref instanceof RefImpl, "Ref is not an instance of RefImpl", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 294, S: void 0, A: ["ref instanceof RefImpl", "'Ref is not an instance of RefImpl'"] });
|
|
287
296
|
return ref._getSavedTarget();
|
|
288
297
|
};
|
|
289
298
|
var refVariance = {
|
|
290
299
|
_T: null
|
|
291
300
|
};
|
|
292
301
|
var refFromEncodedReference = (encodedReference, resolver) => {
|
|
293
|
-
const
|
|
294
|
-
const ref = new RefImpl(
|
|
302
|
+
const uri = EncodedReference.toURI(encodedReference);
|
|
303
|
+
const ref = new RefImpl(uri);
|
|
295
304
|
if (resolver) {
|
|
296
305
|
setRefResolver(ref, resolver);
|
|
297
306
|
}
|
|
@@ -304,28 +313,32 @@ var StaticRefResolver = class {
|
|
|
304
313
|
this.objects.set(obj.id, obj);
|
|
305
314
|
return this;
|
|
306
315
|
}
|
|
307
|
-
addSchema(
|
|
308
|
-
const
|
|
309
|
-
invariant(
|
|
310
|
-
|
|
316
|
+
addSchema(input) {
|
|
317
|
+
const schema = getStaticTypeSchema(input);
|
|
318
|
+
invariant(schema, "Type entity is missing its source schema", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 319, S: this, A: ["schema", "'Type entity is missing its source schema'"] });
|
|
319
|
+
const uri = getSchemaURI(schema);
|
|
320
|
+
invariant(uri, "Schema has no URI", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 321, S: this, A: ["uri", "'Schema has no URI'"] });
|
|
321
|
+
this.schemas.set(uri, schema);
|
|
311
322
|
return this;
|
|
312
323
|
}
|
|
313
|
-
resolveSync(
|
|
314
|
-
const
|
|
324
|
+
resolveSync(uri, _load, _onLoad) {
|
|
325
|
+
const echoUri = EID.tryParse(uri);
|
|
326
|
+
const id = echoUri ? EID.getEntityId(echoUri) : void 0;
|
|
315
327
|
if (id == null) {
|
|
316
328
|
return void 0;
|
|
317
329
|
}
|
|
318
330
|
return this.objects.get(id);
|
|
319
331
|
}
|
|
320
|
-
async resolve(
|
|
321
|
-
const
|
|
332
|
+
async resolve(uri) {
|
|
333
|
+
const echoUri = EID.tryParse(uri);
|
|
334
|
+
const id = echoUri ? EID.getEntityId(echoUri) : void 0;
|
|
322
335
|
if (id == null) {
|
|
323
336
|
return void 0;
|
|
324
337
|
}
|
|
325
338
|
return this.objects.get(id);
|
|
326
339
|
}
|
|
327
|
-
async resolveSchema(
|
|
328
|
-
return this.schemas.get(
|
|
340
|
+
async resolveSchema(uri) {
|
|
341
|
+
return this.schemas.get(uri);
|
|
329
342
|
}
|
|
330
343
|
};
|
|
331
344
|
|
|
@@ -343,4 +356,4 @@ export {
|
|
|
343
356
|
refFromEncodedReference,
|
|
344
357
|
StaticRefResolver
|
|
345
358
|
};
|
|
346
|
-
//# sourceMappingURL=chunk-
|
|
359
|
+
//# sourceMappingURL=chunk-7OAFN3OX.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/internal/Ref/ref.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\nimport * as Equal from 'effect/Equal';\nimport * as Hash from 'effect/Hash';\nimport * as Option from 'effect/Option';\nimport * as ParseResult from 'effect/ParseResult';\nimport * as Pipeable from 'effect/Pipeable';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\nimport type * as Types from 'effect/Types';\n\nimport { Event } from '@dxos/async';\nimport { type CustomInspectFunction, inspectCustom } from '@dxos/debug';\nimport { EncodedReference } from '@dxos/echo-protocol';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, EID, EntityId, type URI } from '@dxos/keys';\n\nimport * as Database from '../../Database';\nimport type * as Type from '../../Type';\nimport {\n ReferenceAnnotationId,\n getSchemaURI,\n getTypeAnnotation,\n getTypeIdentifierAnnotation,\n} from '../Annotation/annotations';\nimport { type AnyEntity, type AnyProperties, type UnknownTypeSchema, getStaticTypeSchema } from '../common/types';\nimport { type JsonSchemaType } from '../JsonSchema';\n\n/**\n * The `$id` and `$ref` fields for an ECHO reference schema.\n */\nexport const JSON_SCHEMA_ECHO_REF_ID = '/schemas/echo/ref';\n\nexport const getSchemaReference = (property: JsonSchemaType): { typename: string } | undefined => {\n const { $id, reference: { schema: { $ref } = {} } = {} } = property;\n if ($id === JSON_SCHEMA_ECHO_REF_ID && $ref) {\n const parsed = DXN.tryMake($ref);\n const typename = parsed ? DXN.getName(parsed) : undefined;\n return typename ? { typename } : undefined;\n }\n};\n\nexport const createSchemaReference = (typename: string): Types.DeepMutable<JsonSchemaType> => {\n return {\n $id: JSON_SCHEMA_ECHO_REF_ID,\n reference: {\n schema: {\n $ref: DXN.make(typename),\n },\n },\n };\n};\n\n/**\n * Runtime type-info for a reference extracted from effect AST.\n */\nexport type RefereneAST = {\n /**\n * Typename of linked schema.\n */\n typename: string;\n\n /**\n * Version of linked schema.\n */\n version: string;\n};\n\nexport const getReferenceAst = (ast: SchemaAST.AST): RefereneAST | undefined => {\n if (ast._tag !== 'Declaration' || !ast.annotations[ReferenceAnnotationId]) {\n return undefined;\n }\n return {\n typename: (ast.annotations[ReferenceAnnotationId] as any).typename,\n version: (ast.annotations[ReferenceAnnotationId] as any).version,\n };\n};\n\nexport const RefTypeId: unique symbol = Symbol('@dxos/echo/internal/Ref');\n\n/**\n * Reference Schema.\n */\nexport interface RefSchema<T extends AnyEntity> extends Schema.SchemaClass<Ref<T>, EncodedReference> {}\n\n/**\n * Type of the `Ref` function and extra methods attached to it.\n */\nexport interface RefFn {\n // A reference target is a `Type.AnyEntity` entity (the canonical Option B\n // input) or one of the well-known \"any object\" / \"any relation\" branded\n // schemas (`Obj.Unknown` / `Relation.Unknown`). Arbitrary raw schemas are\n // rejected.\n //\n // Referencing a type-kind entity (a meta-schema, e.g. `Type.Type`) yields a\n // reference to a stored schema record; its loaded target is any registered\n // entity (`Type.AnyEntity`), since a stored object/relation schema is itself a\n // `Type.Type` record. Referencing an object/relation type yields a reference\n // to an instance of that type.\n <S extends Type.AnyEntity | UnknownTypeSchema<any, any> = Type.AnyEntity>(\n schema: S,\n ): RefSchema<\n S extends Type.AnyType\n ? Type.AnyEntity\n : S extends Type.AnyObj | Type.AnyRelation\n ? Type.InstanceType<S>\n : S extends UnknownTypeSchema<infer A, any>\n ? A\n : never\n >;\n\n /**\n * @returns True if the object is a reference.\n */\n isRef: (obj: unknown) => obj is Ref<any>;\n\n /**\n * @returns True if the reference points to the given object id.\n */\n hasEntityId: (id: EntityId) => (ref: Ref<any>) => boolean;\n\n /**\n * @returns True if the schema is a reference schema.\n */\n isRefSchema: (schema: Schema.Schema<any, any>) => schema is RefSchema<any>;\n\n /**\n * @returns True if the schema AST is a reference schema.\n */\n isRefSchemaAST: (ast: SchemaAST.AST) => boolean;\n\n /**\n * Constructs a reference that points to the given object.\n */\n // TODO(burdon): Narrow to Obj.Unknown?\n make: <T extends AnyEntity>(object: T) => Ref<T>;\n\n /**\n * Constructs a reference that points to the object specified by the provided URI\n * (either an `echo:` EID for an object reference or a `dxn:` DXN for a type reference).\n */\n fromURI: (uri: URI.URI) => Ref<any>;\n}\n\n/**\n * Schema builder for references.\n */\nexport const Ref: RefFn = (input: any): RefSchema<any> => {\n // `Type.Type` entities carry their source schema on the hidden slot; the\n // branded `Obj.Unknown` / `Relation.Unknown` schemas are used directly.\n const schema = getStaticTypeSchema(input) ?? input;\n assertArgument(Schema.isSchema(schema), 'schema', 'Must call with an instance of effect-schema');\n const annotation = getTypeAnnotation(schema);\n if (annotation == null) {\n throw new Error('Reference target must be an ECHO schema.');\n }\n\n return createEchoReferenceSchema(getTypeIdentifierAnnotation(schema), annotation.typename, annotation.version);\n};\n\n/**\n * Represents materialized reference to a target.\n * This is the data type for the fields marked as ref.\n */\nexport interface Ref<T> extends Pipeable.Pipeable {\n /**\n * Target URI (either an `echo:` EID for an object reference or a `dxn:` DXN for a type reference).\n */\n get uri(): URI.URI;\n\n /**\n * Returns true if the reference has a target available (inlined or resolver set).\n */\n get isAvailable(): boolean;\n\n /**\n * @returns The reference target.\n * May return `undefined` if the object is not loaded in the working set.\n * Accessing this property, even if it returns `undefined` will trigger the object to be loaded to the working set.\n */\n get target(): T | undefined;\n\n /**\n * @returns Promise that will resolves with the target object.\n * Will load the object from disk if it is not present in the working set.\n * @throws If the object is not available locally.\n */\n load(): Promise<T>;\n\n /**\n * @returns Promise that will resolves with the target object or undefined if the object is not loaded locally.\n */\n\n tryLoad(): Promise<T | undefined>;\n\n /**\n * Subscribe to the ref's resolution event.\n * The callback fires when the target object becomes available in the working set\n * (e.g. when its document is loaded after sibling-client mutation).\n * Note: the resolver only schedules a notification when the target is requested\n * via {@link target} while it is not yet loaded.\n * @returns Function that unsubscribes the callback.\n */\n onResolved(callback: () => void): () => void;\n\n /**\n * Do not inline the target object in the reference.\n * Makes .target unavailable unless the reference is connected to a database context.\n *\n * When serialized with toJSON, the difference is between:\n * `{ \"/\": \"dxn:...\" }`\n * and\n * `{ \"/\": \"dxn:...\", \"target\": { ... } }`\n *\n * Clones the reference object.\n */\n noInline(): Ref<T>;\n\n /**\n * Serializes the reference to a JSON object.\n * The serialization format is compatible with the IPLD-style encoded references.\n * When a reference has a saved target (i.e. the target or object holding the reference is not in the database),\n * the target is included in the serialized object.\n *\n * Examples:\n * `{ \"/\": \"dxn:...\" }`\n * `{ \"/\": \"dxn:...\", \"target\": { ... } }`\n */\n encode(): EncodedReference;\n\n [RefTypeId]: {\n _T: T;\n };\n}\n\nexport declare namespace Ref {\n /**\n * Target of the reference.\n */\n export type Target<R> = R extends Ref<infer U> ? U : never;\n}\n\nRef.isRef = (obj: any): obj is Ref<any> => {\n return obj && typeof obj === 'object' && RefTypeId in obj;\n};\n\nRef.hasEntityId = (id: EntityId) => (ref: Ref<any>) => {\n const uri = EID.tryParse(ref.uri);\n return uri !== undefined && EID.isLocal(uri) && EID.getEntityId(uri) === id;\n};\n\nRef.isRefSchema = (schema: Schema.Schema<any, any>): schema is RefSchema<any> => {\n return Ref.isRefSchemaAST(schema.ast);\n};\n\nRef.isRefSchemaAST = (ast: SchemaAST.AST): boolean => {\n return SchemaAST.getAnnotation(ast, ReferenceAnnotationId).pipe(Option.isSome);\n};\n\nRef.make = <T extends AnyProperties>(obj: T): Ref<T> => {\n if (typeof obj !== 'object' || obj === null) {\n throw new TypeError('Expected: ECHO object.');\n }\n\n // TODO(dmaretskyi): Extract to `getObjectEchoUri` function.\n const id = obj.id;\n invariant(EntityId.isValid(id), 'Invalid object ID');\n const uri = EID.make({ entityId: id });\n return new RefImpl(uri, obj);\n};\n\nRef.fromURI = (uri: URI.URI): Ref<any> => {\n assertArgument(typeof uri === 'string', 'uri', 'Expected URI string');\n return new RefImpl(uri);\n};\n\n/**\n * `reference` field on the schema object.\n */\nexport type JsonSchemaReferenceInfo = {\n schema: { $ref: string };\n schemaVersion?: string;\n};\n\n/**\n * @internal\n */\n// TODO(burdon): Move to json schema and make private?\nexport const createEchoReferenceSchema = (\n echoUri: string | undefined,\n typename: string | undefined,\n version: string | undefined,\n): Schema.SchemaClass<Ref<any>, EncodedReference> => {\n if (!echoUri && !typename) {\n throw new TypeError('Either echoUri or typename must be provided.');\n }\n\n const referenceInfo: JsonSchemaReferenceInfo = {\n schema: {\n // TODO(dmaretskyi): Include version?\n $ref: echoUri ?? DXN.make(typename!),\n },\n schemaVersion: version,\n };\n\n // TODO(dmaretskyi): Add name and description.\n const refSchema = Schema.declare<Ref<any>, EncodedReference, []>(\n [],\n {\n encode: () => {\n return (value) =>\n Effect.gen(function* () {\n if (Ref.isRef(value)) {\n return EncodedReference.fromURI((value as Ref<any>).uri);\n } else if (EncodedReference.isEncodedReference(value)) {\n return value;\n }\n throw new Error('Invalid reference');\n });\n },\n decode: () => {\n return (value) =>\n Effect.gen(function* () {\n const dbService = yield* Effect.serviceOption(Database.Service);\n\n // TODO(dmaretskyi): This branch seems to be taken by Schema.is\n if (Ref.isRef(value)) {\n if (Option.isSome(dbService)) {\n return dbService.value.db.makeRef(value.uri);\n } else {\n return value;\n }\n }\n\n if (!EncodedReference.isEncodedReference(value)) {\n return yield* Effect.fail(new ParseResult.Unexpected(value, 'reference'));\n }\n if (Option.isSome(dbService)) {\n return dbService.value.db.makeRef(EncodedReference.toURI(value));\n } else {\n return Ref.fromURI(EncodedReference.toURI(value));\n }\n });\n },\n },\n {\n jsonSchema: {\n // TODO(dmaretskyi): We should remove `$id` and keep `$ref` with a fully qualified name.\n $id: JSON_SCHEMA_ECHO_REF_ID,\n $ref: JSON_SCHEMA_ECHO_REF_ID,\n reference: referenceInfo,\n },\n [ReferenceAnnotationId]: {\n typename: typename ?? '',\n version,\n },\n },\n );\n\n return refSchema;\n};\n\nconst getSchemaExpectedName = (ast: SchemaAST.Annotated): string | undefined => {\n return SchemaAST.getIdentifierAnnotation(ast).pipe(\n Option.orElse(() => SchemaAST.getTitleAnnotation(ast)),\n Option.orElse(() => SchemaAST.getDescriptionAnnotation(ast)),\n Option.getOrElse(() => undefined),\n );\n};\n\nexport interface RefResolver {\n /**\n * Resolve ref synchronously from the objects in the working set.\n *\n * @param uri\n * @param load If true the resolver should attempt to load the object from disk.\n * @param onLoad Callback to call when the object is loaded.\n */\n resolveSync(uri: URI.URI, load: boolean, onLoad?: () => void): AnyProperties | undefined;\n\n /**\n * Resolver ref asynchronously.\n */\n resolve(uri: URI.URI): Promise<AnyProperties | undefined>;\n\n // TODO(dmaretskyi): Combine with `resolve`.\n resolveSchema(uri: URI.URI): Promise<Schema.Schema.AnyNoContext | undefined>;\n\n /**\n * Resolve the source `Type.AnyEntity` entity for a type URI. Used by\n * deserialization paths (`Obj.fromJSON`) to set the back-reference accessed\n * via `Obj.getType` / `Entity.getType`. Optional — resolvers that only\n * carry raw schemas may leave this unimplemented; the deserializer falls\n * back to leaving the type entity unset.\n */\n resolveType?(uri: URI.URI): Promise<unknown | undefined>;\n}\n\nexport class RefImpl<T> implements Ref<T> {\n #uri: URI.URI;\n #resolver?: RefResolver = undefined;\n #resolved = new Event<void>();\n\n /**\n * Target is set when the reference is created from a specific object.\n * In this case, the target might not be in the database.\n */\n #target: T | undefined = undefined;\n\n /**\n * Callback to issue a reactive notification when object is resolved.\n */\n #resolverCallback = () => {\n this.#resolved.emit();\n };\n\n constructor(uri: URI.URI, target?: T) {\n this.#uri = uri;\n this.#target = target;\n }\n\n /**\n * @inheritdoc\n */\n get uri(): URI.URI {\n return this.#uri;\n }\n\n /**\n * @inheritdoc\n */\n get isAvailable(): boolean {\n return this.#target !== undefined || this.#resolver !== undefined;\n }\n\n /**\n * @inheritdoc\n */\n get target(): T | undefined {\n if (this.#target) {\n return this.#target;\n }\n\n invariant(this.#resolver, 'Resolver is not set');\n return this.#resolver.resolveSync(this.#uri, true, this.#resolverCallback) as T | undefined;\n }\n\n /**\n * @inheritdoc\n */\n async load(): Promise<T> {\n if (this.#target) {\n return this.#target;\n }\n invariant(this.#resolver, 'Resolver is not set');\n const obj = await this.#resolver.resolve(this.#uri);\n if (obj == null) {\n throw new Error('Object not found');\n }\n return obj as T;\n }\n\n /**\n * @inheritdoc\n */\n async tryLoad(): Promise<T | undefined> {\n if (this.#target) {\n return this.#target;\n }\n invariant(this.#resolver, 'Resolver is not set');\n return (await this.#resolver.resolve(this.#uri)) as T | undefined;\n }\n\n /**\n * @inheritdoc\n */\n onResolved(callback: () => void): () => void {\n return this.#resolved.on(callback);\n }\n\n /**\n * Do not inline the target object in the reference.\n * Makes .target unavailable unless the reference is connected to a database context.\n * Clones the reference object.\n */\n noInline(): RefImpl<T> {\n const ref = new RefImpl<T>(this.#uri, undefined);\n ref.#resolver = this.#resolver;\n return ref;\n }\n\n encode(): EncodedReference {\n return {\n '/': this.#uri,\n ...(this.#target ? { target: this.#target } : {}),\n };\n }\n\n /**\n * Serializes the reference to a JSON object.\n * The serialization format is compatible with the IPLD-style encoded references.\n * When a reference has a saved target (i.e. the target or object holding the reference is not in the database),\n * the target is included in the serialized object.\n */\n toJSON(): EncodedReference {\n return this.encode();\n }\n\n toString(): string {\n if (this.#target) {\n return `Ref(${this.#target.toString()})`;\n }\n\n return `Ref(${this.#uri.toString()})`;\n }\n\n [inspectCustom]: CustomInspectFunction = (depth, options, inspect) => {\n return this.toString();\n };\n\n [RefTypeId] = refVariance;\n\n /**\n * Effect Hash trait. Required for MutableHashMap-based caches (e.g., Atom.family)\n * to deduplicate Ref instances that point to the same object.\n * ECHO proxies return new RefImpl instances on every property access,\n * so without this, each access would create a separate cache entry.\n */\n [Hash.symbol](): number {\n return Hash.hash(this.#uri.toString());\n }\n\n /** Effect Equal trait. See {@link Hash.symbol} for rationale. */\n [Equal.symbol](that: Equal.Equal): boolean {\n return that instanceof RefImpl && this.#uri === that.uri;\n }\n\n /**\n * Internal method to set the resolver.\n *\n * @internal\n */\n _setResolver(resolver: RefResolver): void {\n this.#resolver = resolver;\n }\n\n /**\n * @internal\n */\n _getSavedTarget(): T | undefined {\n return this.#target;\n }\n\n pipe() {\n // eslint-disable-next-line prefer-rest-params\n return Pipeable.pipeArguments(this, arguments);\n }\n}\n\n/**\n * Internal API for setting the reference resolver.\n */\nexport const setRefResolver = (ref: Ref<any>, resolver: RefResolver) => {\n invariant(ref instanceof RefImpl, 'Ref is not an instance of RefImpl');\n ref._setResolver(resolver);\n};\n\n/**\n * Internal API for getting the saved target on a reference.\n */\nexport const getRefSavedTarget = (ref: Ref<any>): AnyProperties | undefined => {\n invariant(ref instanceof RefImpl, 'Ref is not an instance of RefImpl');\n return ref._getSavedTarget();\n};\n\n// Used to validate reference target type.\nconst refVariance: Ref<any>[typeof RefTypeId] = {\n _T: null as any,\n};\n\nexport const refFromEncodedReference = (encodedReference: EncodedReference, resolver?: RefResolver): Ref<any> => {\n const uri = EncodedReference.toURI(encodedReference);\n const ref = new RefImpl(uri);\n\n // TODO(dmaretskyi): Handle inline target in the encoded reference.\n\n if (resolver) {\n setRefResolver(ref, resolver);\n }\n return ref;\n};\n\nexport class StaticRefResolver implements RefResolver {\n public objects = new Map<EntityId, AnyProperties>();\n public schemas = new Map<URI.URI, Schema.Schema.AnyNoContext>();\n\n addObject(obj: AnyProperties): this {\n this.objects.set(obj.id, obj);\n return this;\n }\n\n addSchema(input: Type.AnyEntity): this {\n const schema = getStaticTypeSchema(input);\n invariant(schema, 'Type entity is missing its source schema');\n const uri = getSchemaURI(schema);\n invariant(uri, 'Schema has no URI');\n this.schemas.set(uri, schema);\n return this;\n }\n\n resolveSync(uri: URI.URI, _load: boolean, _onLoad?: () => void): AnyProperties | undefined {\n const echoUri = EID.tryParse(uri);\n const id = echoUri ? EID.getEntityId(echoUri) : undefined;\n if (id == null) {\n return undefined;\n }\n\n return this.objects.get(id);\n }\n\n async resolve(uri: URI.URI): Promise<AnyProperties | undefined> {\n const echoUri = EID.tryParse(uri);\n const id = echoUri ? EID.getEntityId(echoUri) : undefined;\n if (id == null) {\n return undefined;\n }\n\n return this.objects.get(id);\n }\n\n async resolveSchema(uri: URI.URI): Promise<Schema.Schema.AnyNoContext | undefined> {\n return this.schemas.get(uri);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAIA,YAAYA,YAAY;AACxB,YAAYC,WAAW;AACvB,YAAYC,UAAU;AACtB,YAAYC,YAAY;AACxB,YAAYC,iBAAiB;AAC7B,YAAYC,cAAc;AAC1B,YAAYC,YAAY;AACxB,YAAYC,eAAe;AAG3B,SAASC,aAAa;AACtB,SAAqCC,qBAAqB;AAC1D,SAASC,wBAAwB;AACjC,SAASC,gBAAgBC,iBAAiB;AAC1C,SAASC,KAAKC,KAAKC,gBAA0B;AAa7C,IAAA,eAAA;AAMQ,IAAOC,0BAAuBC;AACpC,IAAIC,qBAAQC,CAAAA,aAA2BF;QACrC,EAAA,KAAMG,WAAaC,EAAAA,QAAQJ,EAAAA,KAAAA,IAAAA,CAAAA,EAAAA,IAAAA,CAAAA,EAAAA,IAAAA;MAC3B,QAAMK,2BAAwBC,MAAQH;AACtC,UAAA,SAAOE,IAAW,QAAA,IAAA;UAAEA,WAAAA,SAAAA,IAAAA,QAAAA,MAAAA,IAAAA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AAExB,QAAA,MAAA,iBAAA,MAAA,gBAAA;AAEA,QAAIF,MAAAA,IAAU,QAAA,GAAA;AAEd,MAAA,UAAA;AACA,mBAAOX,KAAAA,QAAAA;EACP;AAEF,SAAO;;AAEEc,IAAAA,oBAAAA,MAAyD;EAEhEC,UAAUjB,oBAAkB,IAAQ;YAC7BkB,oBAAAA,IAAQC;YACb,KAAW;AACb,SAAA,QAAA,IAAA,IAAA,IAAA,GAAA;AAEAC,WAAUC;;YAERtB,OAAUuB;AACV,UAAMP,SAAMQ,oBAAaD,KAAAA;AACzBvB,cAAUgB,QAAK,4CAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,KAAA,GAAA,MAAA,GAAA,CAAA,UAAA,4CAAA,EAAA,CAAA;AACf,UAAKC,MAAO,aAAUM,MAAAA;AACtB,cAAO,KAAI,qBAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,KAAA,GAAA,MAAA,GAAA,CAAA,OAAA,qBAAA,EAAA,CAAA;AACb,SAAA,QAAA,IAAA,KAAA,MAAA;AAEAE,WAAAA;;cAEQC,KAAKC,OAAAA,SAAcC;AACzB,UAAIF,UAAY,IAAA,SAAA,GAAA;UACd,KAAO5B,UAAAA,IAAAA,YAAAA,OAAAA,IAAAA;AACT,QAAA,MAAA,MAAA;AAEA,aAAW;IACb;AAEA,WAAM+B,KAAQb,QAAkD,IAAA,EAAA;;QAE9D,QAAMU,KAAKC;AACX,UAAID,UAAY,IAAA,SAAA,GAAA;UACd,KAAO5B,UAAAA,IAAAA,YAAAA,OAAAA,IAAAA;AACT,QAAA,MAAA,MAAA;AAEA,aAAW;IACb;AAEA,WAAMgC,KAAAA,QAA0B,IAAmD,EAAA;;EAEnF,MAAA,cAAA,KAAA;AACF,WAAA,KAAA,QAAA,IAAA,GAAA;;;",
|
|
6
|
+
"names": ["Effect", "Equal", "Hash", "Option", "ParseResult", "Pipeable", "Schema", "SchemaAST", "Event", "inspectCustom", "EncodedReference", "assertArgument", "invariant", "DXN", "EID", "EntityId", "reference", "$ref", "$id", "JSON_SCHEMA_ECHO_REF_ID", "parsed", "tryMake", "typename", "getName", "undefined", "schema", "version", "annotation", "getTypeAnnotation", "Error", "createEchoReferenceSchema", "isRef", "obj", "hasEntityId", "ref", "uri", "isRefSchema", "isRefSchemaAST", "ast", "make", "TypeError", "EID", "entityId", "id", "RefImpl", "fromURI", "referenceInfo", "schemaVersion", "Effect", "gen", "EncodedReference", "value", "Ref", "dbService", "Option", "isSome", "jsonSchema", "ReferenceAnnotationId", "getSchemaExpectedName", "undefined", "target", "invariant", "obj", "Error", "ref", "encode", "toString", "inspectCustom", "depth", "options", "inspect", "RefTypeId", "refVariance", "pipe", "_setResolver", "resolver", "_getSavedTarget", "uri", "schemas", "addObject", "objects", "set", "addSchema", "input", "schema", "getSchemaURI", "resolveSync", "id", "echoUri", "getEntityId", "resolve", "resolveSchema"]
|
|
7
|
+
}
|
|
@@ -3,24 +3,25 @@ import {
|
|
|
3
3
|
FormatAnnotation,
|
|
4
4
|
FormatAnnotationId,
|
|
5
5
|
TypeFormat
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TFEWTY5A.mjs";
|
|
7
7
|
import {
|
|
8
8
|
createEchoReferenceSchema
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-7OAFN3OX.mjs";
|
|
10
10
|
import {
|
|
11
11
|
GeneratorAnnotationId,
|
|
12
12
|
LabelAnnotationId,
|
|
13
13
|
PropertyMetaAnnotationId,
|
|
14
14
|
TypeAnnotationId,
|
|
15
15
|
TypeIdentifierAnnotationId
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-H26LSXVJ.mjs";
|
|
17
17
|
import {
|
|
18
18
|
ANY_OBJECT_TYPENAME,
|
|
19
19
|
ANY_OBJECT_VERSION,
|
|
20
20
|
EntityKind,
|
|
21
21
|
EntityKindSchema,
|
|
22
|
+
getStaticTypeSchema,
|
|
22
23
|
makeTypeJsonSchemaAnnotation
|
|
23
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-O6BH7EPN.mjs";
|
|
24
25
|
|
|
25
26
|
// src/internal/JsonSchema/annotations.ts
|
|
26
27
|
import * as SchemaAST from "effect/SchemaAST";
|
|
@@ -319,7 +320,7 @@ import * as SchemaAST2 from "effect/SchemaAST";
|
|
|
319
320
|
import { raise } from "@dxos/debug";
|
|
320
321
|
import { mapAst } from "@dxos/effect";
|
|
321
322
|
import { assertArgument, invariant } from "@dxos/invariant";
|
|
322
|
-
import { DXN,
|
|
323
|
+
import { DXN, EID, EntityId } from "@dxos/keys";
|
|
323
324
|
import { log } from "@dxos/log";
|
|
324
325
|
import { clearUndefined, orderKeys, removeProperties } from "@dxos/util";
|
|
325
326
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/JsonSchema/json-schema.ts";
|
|
@@ -354,6 +355,15 @@ var toPropType = (type) => {
|
|
|
354
355
|
};
|
|
355
356
|
var JSON_SCHEMA_URL = "http://json-schema.org/draft-07/schema#";
|
|
356
357
|
var toJsonSchema = (schema, options = {}) => {
|
|
358
|
+
const slot = getStaticTypeSchema(schema);
|
|
359
|
+
if (slot != null) {
|
|
360
|
+
schema = slot;
|
|
361
|
+
} else if (!Schema2.isSchema(schema)) {
|
|
362
|
+
const entityJsonSchema = schema.jsonSchema;
|
|
363
|
+
if (entityJsonSchema != null) {
|
|
364
|
+
return entityJsonSchema;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
357
367
|
assertArgument(Schema2.isSchema(schema), "schema");
|
|
358
368
|
let jsonSchema = _toJsonSchemaAST(schema.ast);
|
|
359
369
|
if (options.strict) {
|
|
@@ -465,7 +475,7 @@ var toEffectSchema = (root, _defs) => {
|
|
|
465
475
|
if (root.allOf.length === 1) {
|
|
466
476
|
result = toEffectSchema(root.allOf[0], defs);
|
|
467
477
|
} else {
|
|
468
|
-
log.warn("allOf with multiple schemas is not supported", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
478
|
+
log.warn("allOf with multiple schemas is not supported", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 197, S: void 0 });
|
|
469
479
|
result = Schema2.Unknown;
|
|
470
480
|
}
|
|
471
481
|
} else if ("type" in root) {
|
|
@@ -494,7 +504,7 @@ var toEffectSchema = (root, _defs) => {
|
|
|
494
504
|
const [required, optional3] = Function.pipe(root.items, Array2.map((v) => toEffectSchema(v, defs)), Array2.splitAt(root.minItems ?? root.items.length));
|
|
495
505
|
result = Schema2.Tuple(...required, ...optional3.map(Schema2.optionalElement));
|
|
496
506
|
} else {
|
|
497
|
-
invariant(root.items, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
507
|
+
invariant(root.items, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 231, S: void 0, A: ["root.items", ""] });
|
|
498
508
|
const items = root.items;
|
|
499
509
|
result = Array2.isArray(items) ? Schema2.Tuple(...items.map((v) => toEffectSchema(v, defs))) : Schema2.Array(toEffectSchema(items, defs));
|
|
500
510
|
}
|
|
@@ -508,7 +518,7 @@ var toEffectSchema = (root, _defs) => {
|
|
|
508
518
|
} else if ("$ref" in root) {
|
|
509
519
|
const refSegments = root.$ref.split("/");
|
|
510
520
|
const jsonSchema = defs[refSegments[refSegments.length - 1]];
|
|
511
|
-
invariant(jsonSchema, `missing definition for ${root.$ref}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
521
|
+
invariant(jsonSchema, `missing definition for ${root.$ref}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 246, S: void 0, A: ["jsonSchema", "`missing definition for ${root.$ref}`"] });
|
|
512
522
|
result = toEffectSchema(jsonSchema, defs).pipe(Schema2.annotations({
|
|
513
523
|
identifier: refSegments[refSegments.length - 1]
|
|
514
524
|
}));
|
|
@@ -518,7 +528,7 @@ var toEffectSchema = (root, _defs) => {
|
|
|
518
528
|
return result;
|
|
519
529
|
};
|
|
520
530
|
var objectToEffectSchema = (root, defs) => {
|
|
521
|
-
invariant("type" in root && root.type === "object", `not an object: ${root}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
531
|
+
invariant("type" in root && root.type === "object", `not an object: ${root}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 257, S: void 0, A: ["'type' in root && root.type === 'object'", "`not an object: ${root}`"] });
|
|
522
532
|
const echoRefinement = root[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
|
|
523
533
|
const isEchoObject = echoRefinement != null || "$id" in root && typeof root.$id === "string" && root.$id.startsWith("dxn:");
|
|
524
534
|
let fields = {};
|
|
@@ -536,8 +546,8 @@ var objectToEffectSchema = (root, defs) => {
|
|
|
536
546
|
}
|
|
537
547
|
let schema;
|
|
538
548
|
if (root.patternProperties) {
|
|
539
|
-
invariant(propertyList.length === 0, "pattern properties mixed with regular properties are not supported", { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
540
|
-
invariant(Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === "", "only one pattern property is supported", { "~LogMeta": "~LogMeta", F: __dxlog_file, L:
|
|
549
|
+
invariant(propertyList.length === 0, "pattern properties mixed with regular properties are not supported", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 276, S: void 0, A: ["propertyList.length === 0", "'pattern properties mixed with regular properties are not supported'"] });
|
|
550
|
+
invariant(Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === "", "only one pattern property is supported", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 277, S: void 0, A: ["Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === ''", "'only one pattern property is supported'"] });
|
|
541
551
|
schema = Schema2.Record({
|
|
542
552
|
key: Schema2.String,
|
|
543
553
|
value: toEffectSchema(root.patternProperties[""], defs)
|
|
@@ -569,8 +579,8 @@ var objectToEffectSchema = (root, defs) => {
|
|
|
569
579
|
var anyToEffectSchema = (root) => {
|
|
570
580
|
const echoRefinement = root[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
|
|
571
581
|
if (echoRefinement?.reference != null) {
|
|
572
|
-
const
|
|
573
|
-
return createEchoReferenceSchema(
|
|
582
|
+
const echoUri = root.$id.startsWith("echo:") || root.$id.startsWith("dxn:echo:") ? root.$id : void 0;
|
|
583
|
+
return createEchoReferenceSchema(echoUri, echoRefinement.reference.typename, echoRefinement.reference.version);
|
|
574
584
|
}
|
|
575
585
|
return Schema2.Any;
|
|
576
586
|
};
|
|
@@ -582,9 +592,10 @@ var refToEffectSchema = (root) => {
|
|
|
582
592
|
if (typeof reference !== "object") {
|
|
583
593
|
throw new Error("Invalid reference field in ref schema");
|
|
584
594
|
}
|
|
585
|
-
const
|
|
586
|
-
|
|
587
|
-
|
|
595
|
+
const ref = reference.schema.$ref;
|
|
596
|
+
const targetSchemaDXN = DXN.tryMake(ref);
|
|
597
|
+
invariant(targetSchemaDXN, `Expected a type DXN, got: ${ref}`, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 327, S: void 0, A: ["targetSchemaDXN", "`Expected a type DXN, got: ${ref}`"] });
|
|
598
|
+
return createEchoReferenceSchema(ref, DXN.getName(targetSchemaDXN), reference.schemaVersion);
|
|
588
599
|
};
|
|
589
600
|
var annotations_toJsonSchemaFields = (annotations2) => {
|
|
590
601
|
const schemaFields = {};
|
|
@@ -599,8 +610,7 @@ var annotations_toJsonSchemaFields = (annotations2) => {
|
|
|
599
610
|
}
|
|
600
611
|
const echoIdentifier = annotations2[TypeIdentifierAnnotationId];
|
|
601
612
|
if (echoIdentifier) {
|
|
602
|
-
schemaFields
|
|
603
|
-
schemaFields[ECHO_ANNOTATIONS_NS_KEY].schemaId = echoIdentifier;
|
|
613
|
+
schemaFields.$id = echoIdentifier;
|
|
604
614
|
}
|
|
605
615
|
for (const [key, annotationId] of Object.entries(CustomAnnotations)) {
|
|
606
616
|
const value = annotations2[annotationId];
|
|
@@ -611,13 +621,14 @@ var annotations_toJsonSchemaFields = (annotations2) => {
|
|
|
611
621
|
return schemaFields;
|
|
612
622
|
};
|
|
613
623
|
var decodeTypeIdentifierAnnotation = (schema) => {
|
|
614
|
-
if (schema.$id && schema.$id.startsWith("dxn:echo:")) {
|
|
624
|
+
if (schema.$id && (schema.$id.startsWith("echo:") || schema.$id.startsWith("dxn:echo:"))) {
|
|
615
625
|
return schema.$id;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
626
|
+
}
|
|
627
|
+
const legacySchemaId = schema.echo?.type?.schemaId;
|
|
628
|
+
if (legacySchemaId) {
|
|
629
|
+
return EntityId.isValid(legacySchemaId) ? EID.make({
|
|
630
|
+
entityId: legacySchemaId
|
|
631
|
+
}) : legacySchemaId;
|
|
621
632
|
}
|
|
622
633
|
return void 0;
|
|
623
634
|
};
|
|
@@ -632,8 +643,8 @@ var decodeTypeAnnotation = (schema) => {
|
|
|
632
643
|
if (annotation.kind === EntityKind.Relation) {
|
|
633
644
|
const source = schema.relationSource?.$ref ?? raise(new Error("Relation source not set"));
|
|
634
645
|
const target = schema.relationTarget?.$ref ?? raise(new Error("Relation target not set"));
|
|
635
|
-
annotation.sourceSchema = DXN.
|
|
636
|
-
annotation.targetSchema = DXN.
|
|
646
|
+
annotation.sourceSchema = DXN.tryMake(source) ?? raise(new Error(`Invalid relation source: ${source}`));
|
|
647
|
+
annotation.targetSchema = DXN.tryMake(target) ?? raise(new Error(`Invalid relation target: ${target}`));
|
|
637
648
|
}
|
|
638
649
|
return annotation;
|
|
639
650
|
}
|
|
@@ -662,7 +673,9 @@ var jsonSchemaFieldsToAnnotations = (schema) => {
|
|
|
662
673
|
if (typeAnnotation) {
|
|
663
674
|
annotations2[TypeAnnotationId] = typeAnnotation;
|
|
664
675
|
annotations2[SchemaAST2.JSONSchemaAnnotationId] = makeTypeJsonSchemaAnnotation({
|
|
665
|
-
|
|
676
|
+
// $id is the typename DXN — the schema's type identity. The storage EID (if any)
|
|
677
|
+
// is preserved separately on TypeIdentifierAnnotation / echo.schemaId.
|
|
678
|
+
identifier: DXN.make(typeAnnotation.typename, typeAnnotation.version),
|
|
666
679
|
kind: typeAnnotation.kind,
|
|
667
680
|
typename: typeAnnotation.typename,
|
|
668
681
|
version: typeAnnotation.version,
|
|
@@ -731,4 +744,4 @@ export {
|
|
|
731
744
|
toJsonSchema,
|
|
732
745
|
toEffectSchema
|
|
733
746
|
};
|
|
734
|
-
//# sourceMappingURL=chunk-
|
|
747
|
+
//# sourceMappingURL=chunk-7PRCIDHH.mjs.map
|