@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
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Database.ts", "../../../src/internal/Entity/type-uri.ts", "../../../src/internal/Annotation/annotations.ts", "../../../src/internal/common/types/model-symbols.ts", "../../../src/internal/common/types/typename.ts", "../../../src/internal/Annotation/dictionary.ts", "../../../src/internal/Entity/api.ts", "../../../src/internal/Entity/model.ts", "../../../src/internal/Entity/util.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Effectable from 'effect/Effectable';\nimport * as Layer from 'effect/Layer';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\n\nimport { promiseWithCauseCapture } from '@dxos/effect';\nimport { invariant } from '@dxos/invariant';\nimport { type SpaceId, type URI } from '@dxos/keys';\n\nimport type * as Entity from './Entity';\nimport * as Err from './Err';\nimport type * as Filter from './Filter';\nimport type * as Hypergraph from './Hypergraph';\nimport { type AnyProperties, EntityKind, KindId } from './internal/common/types';\n// Deep import (not the `./internal/Entity` barrel) to avoid a cycle:\n// Database → internal/Entity → entity → JsonSchema → Ref → Database.\nimport { isInstanceOf } from './internal/Entity/type-uri';\nimport type { Ref } from './internal/Ref/ref';\nimport type * as Obj from './Obj';\nimport type * as Query from './Query';\nimport type * as QueryResult from './QueryResult';\nimport type * as Registry from './Registry';\nimport type * as Type from './Type';\n\n/**\n * `query` API function declaration.\n */\n// TODO(burdon): Reconcile Query and Filter (should only have one root type).\nexport interface QueryFn {\n <Q extends Query.Any>(query: Q): QueryResult.QueryResult<Query.Type<Q>>;\n <F extends Filter.Any>(filter: F): QueryResult.QueryResult<Filter.Type<F>>;\n}\n\n/**\n * Common interface for Database, Feed, and Hypergraph.\n */\nexport interface Queryable {\n query: QueryFn;\n}\n\nexport type GetObjectByIdOptions = {\n deleted?: boolean;\n};\n\nexport type ObjectPlacement = 'root-doc' | 'linked-doc';\n\nexport type AddOptions = {\n /**\n * Where to place the object in the Automerge document tree.\n * Root document is always loaded with the space.\n * Linked documents are loaded lazily.\n * Placing large number of objects in the root document may slow down the initial load.\n *\n * @default 'linked-doc'\n */\n placeIn?: ObjectPlacement;\n};\n\n/**\n * Rejects Type entities from {@link Database.add} at compile time via their `[KindId]` brand. Used\n * as `T & RejectTypeEntity<T>` to preserve inference of `T`. Bounding `add` on\n * `Obj.Unknown | Relation.Unknown` instead would reject broadly-typed instance adds (e.g.\n * `Entity.Any`, `Obj.OfShape<T>`), forcing casts repo-wide.\n */\nexport type RejectTypeEntity<T> = T extends { readonly [KindId]: EntityKind.Type }\n ? { __error: 'Type entities must be persisted via db.addType(), not db.add().' }\n : T;\n\nexport type FlushOptions = {\n /**\n * Write any pending changes to disk.\n * @default true\n */\n disk?: boolean;\n\n /**\n * Wait for pending index updates.\n * @default true\n */\n indexes?: boolean;\n\n /**\n * Flush pending updates to objects and queries.\n * @default false\n */\n updates?: boolean;\n};\n\n/**\n * Identifier denoting an ECHO Database.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Database');\nexport type TypeId = typeof TypeId;\n\n/**\n * ECHO Database interface.\n */\nexport interface Database extends Queryable {\n readonly [TypeId]: TypeId;\n\n get spaceId(): SpaceId;\n\n get graph(): Hypergraph.Hypergraph;\n\n /**\n * Registry for this database. Delegates type lookups to the shared hypergraph registry.\n * To persist a schema so it replicates to other clients, add the type entity with\n * {@link addType} (e.g. `await db.addType(Type.makeObjectFromJsonSchema(...))`).\n */\n readonly registry: Registry.Registry;\n\n toJSON(): object;\n\n /**\n * Return object by local ID.\n */\n getObjectById<T extends Obj.Unknown = Obj.OfShape<AnyProperties>>(\n id: string,\n opts?: GetObjectByIdOptions,\n ): T | undefined;\n\n /**\n * Query objects.\n */\n query: QueryFn;\n\n /**\n * Creates a reference to an existing object in the database.\n *\n * NOTE: The reference may be dangling if the object is not present in the database.\n * NOTE: Difference from `Ref.fromURI`\n * `Ref.fromURI(dxn)` returns an unhydrated reference. The `.load` and `.target` APIs will not work.\n * `db.makeRef(dxn)` is preferable in cases with access to the database.\n */\n makeRef<T extends Entity.Unknown = Entity.Unknown>(uri: URI.URI): Ref<T>;\n\n /**\n * Adds an object or relation to the database.\n *\n * Only Object and Relation entities are accepted. To persist a Type definition use\n * {@link addType} — passing a Type entity is rejected at compile time (and at runtime).\n */\n add<T extends Entity.Unknown = Entity.Unknown>(obj: T & RejectTypeEntity<T>, opts?: AddOptions): T;\n\n /**\n * Persists a Type definition (clones/forks the entity) so it replicates to other peers.\n *\n * Runs a conflict query first: if a type with the same typename + version already exists in\n * this space, the existing persisted entity is returned and no duplicate is created. This is\n * the only supported way to add Type entities — {@link add} rejects them.\n */\n addType<T extends Type.AnyEntity>(type: T): Promise<T>;\n\n /**\n * Removes object from the database.\n */\n // TODO(burdon): Return true if removed (currently throws if not present).\n remove(obj: Entity.Unknown): void;\n\n /**\n * Wait for all pending changes to be saved to disk.\n * Optionaly waits for changes to be propagated to indexes and event handlers.\n */\n flush(opts?: FlushOptions): Promise<void>;\n}\n\nexport const isDatabase = (obj: unknown): obj is Database => {\n return obj ? typeof obj === 'object' && TypeId in obj && obj[TypeId] === TypeId : false;\n};\n\nexport const Database: Schema.Schema<Database> = Schema.Any.pipe(Schema.filter((space) => isDatabase(space)));\n\n/**\n * Effect service tag for Database dependency injection.\n */\nexport class Service extends Context.Tag('@dxos/echo/Database/Service')<\n Service,\n {\n readonly db: Database;\n }\n>() {}\n\n/**\n * Layer that provides a Database service that throws when accessed.\n * Useful as a default layer when no database is available.\n */\nexport const notAvailable = Layer.succeed(Service, {\n get db(): Database {\n throw new Error('Database not available');\n },\n});\n\n/**\n * Creates a Database service instance from a Database.\n */\nexport const makeService = (db: Database): Context.Tag.Service<Service> => {\n return {\n get db() {\n return db;\n },\n };\n};\n\n/**\n * Creates a Layer that provides the Database service.\n */\nexport const layer = (db: Database): Layer.Layer<Service> => {\n return Layer.succeed(Service, makeService(db));\n};\n\n/**\n * Returns the space ID of the database.\n */\nexport const spaceId = Effect.gen(function* () {\n const { db } = yield* Service;\n return db.spaceId;\n});\n\n/**\n * Resolves an object by its DXN.\n */\nexport const resolve: {\n // No type check.\n (ref: URI.URI | Ref<any>): Effect.Effect<Entity.Unknown, never, Service>;\n // Check matches schema.\n <S extends Type.AnyEntity>(\n ref: URI.URI | Ref<any>,\n schema: S,\n ): Effect.Effect<Type.InstanceType<S>, Err.EntityNotFoundError, Service>;\n} = (<S extends Type.AnyEntity>(\n ref: URI.URI | Ref<any>,\n schema?: S,\n): Effect.Effect<Type.InstanceType<S>, Err.EntityNotFoundError, Service> =>\n Effect.gen(function* () {\n const { db } = yield* Service;\n const dxn = typeof ref === 'string' ? ref : ref.uri;\n const object = yield* promiseWithCauseCapture(() =>\n db.graph\n .createRefResolver({\n context: {\n space: db.spaceId,\n },\n })\n .resolve(dxn),\n );\n\n if (!object) {\n return yield* Effect.fail(new Err.EntityNotFoundError(dxn));\n }\n // `isInstanceOf` uses a conditional generic that TS can't resolve through\n // the local `S extends Type.AnyEntity` parameter — runtime accepts it fine.\n invariant(!schema || isInstanceOf(schema as any, object), 'Object type mismatch.');\n return object as any;\n }).pipe(Effect.withSpan('Database.resolve'))) as any;\n\n/**\n * Loads an object reference.\n */\nexport const load: <T>(ref: Ref<T>) => Effect.Effect<T, Err.EntityNotFoundError, never> = Effect.fn('Database.load')(\n function* (ref) {\n const object = yield* promiseWithCauseCapture(() => ref.tryLoad());\n if (!object) {\n return yield* Effect.fail(new Err.EntityNotFoundError(ref.uri));\n }\n return object;\n },\n);\n\n/**\n * Loads an object reference option.\n */\n// TODO(dmaretskyi): Do we need this -- you can just use `Effect.catchTag` in calling code instead.\nexport const loadOption: <T>(ref: Ref<T>) => Effect.Effect<Option.Option<T>, never, never> = Effect.fn(\n 'Database.loadOption',\n)(function* (ref) {\n const object = yield* load(ref).pipe(Effect.catchTag('EntityNotFoundError', () => Effect.succeed(undefined)));\n\n return Option.fromNullable(object);\n});\n\n/**\n * Adds an object or relation to the database.\n * @see {@link Database.add}\n */\nexport const add = <T extends Entity.Unknown>(obj: T & RejectTypeEntity<T>): Effect.Effect<T, never, Service> =>\n Service.pipe(Effect.map(({ db }) => db.add<T>(obj))).pipe(Effect.withSpan('Database.add'));\n\n/**\n * Persists a Type definition to the database.\n * @see {@link Database.addType}\n */\nexport const addType = <T extends Type.AnyEntity>(type: T): Effect.Effect<T, never, Service> =>\n Service.pipe(Effect.flatMap(({ db }) => promiseWithCauseCapture(() => db.addType(type)))).pipe(\n Effect.withSpan('Database.addType'),\n );\n\n/**\n * Removes an object from the database.\n * @see {@link Database.remove}\n */\nexport const remove = <T extends Entity.Unknown>(obj: T): Effect.Effect<void, never, Service> =>\n Service.pipe(Effect.map(({ db }) => db.remove(obj))).pipe(Effect.withSpan('Database.remove'));\n\n/**\n * Flushes pending changes to disk.\n * @see {@link Database.flush}\n */\nexport const flush = (opts?: FlushOptions) =>\n Service.pipe(Effect.flatMap(({ db }) => promiseWithCauseCapture(() => db.flush(opts)))).pipe(\n Effect.withSpan('Database.flush'),\n );\n\n/**\n * Creates a `QueryResult` object that can be subscribed to.\n */\nexport const query: {\n <Q extends Query.Any>(query: Q): QueryResult.QueryResultEffect<Query.Type<Q>, never, Service>;\n <F extends Filter.Any>(filter: F): QueryResult.QueryResultEffect<Filter.Type<F>, never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n Service.pipe(\n Effect.map(({ db }) => db.query(queryOrFilter as any) as QueryResult.QueryResult<any>),\n Effect.withSpan('Database.query'),\n makeQueryResultEffect,\n );\n\n/**\n * Executes the query once and returns the results.\n * @deprecated Use `yield* query(...).run` instead.\n */\nexport const runQuery: {\n <Q extends Query.Any>(query: Q): Effect.Effect<Query.Type<Q>[], never, Service>;\n <F extends Filter.Any>(filter: F): Effect.Effect<Filter.Type<F>[], never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n query(queryOrFilter as any).pipe(\n Effect.flatMap((queryResult) => promiseWithCauseCapture(() => queryResult.run())),\n Effect.withSpan('Database.runQuery'),\n );\n\n/**\n * Executes the query once and returns the first result as or None.\n * @deprecated Use `yield* query(...).first` instead.\n */\nexport const runQueryFirst: {\n <Q extends Query.Any>(query: Q): Effect.Effect<Option.Option<Query.Type<Q>>, never, Service>;\n <F extends Filter.Any>(filter: F): Effect.Effect<Option.Option<Filter.Type<F>>, never, Service>;\n} = (queryOrFilter: Query.Any | Filter.Any) =>\n query(queryOrFilter as any).pipe(\n Effect.flatMap((queryResult) =>\n promiseWithCauseCapture(async () => Option.fromNullable(await queryResult.firstOrUndefined())),\n ),\n Effect.withSpan('Database.runQueryFirst'),\n );\n\nconst makeQueryResultEffect = <T>(\n eff: Effect.Effect<QueryResult.QueryResult<T>, never, Service>,\n): QueryResult.QueryResultEffect<T, never, Service> => {\n return {\n run: Effect.flatMap(eff, (result) => promiseWithCauseCapture(() => result.run())),\n first: Effect.flatMap(eff, (result) =>\n promiseWithCauseCapture(async () => Option.fromNullable(await result.firstOrUndefined())),\n ),\n\n // Effect internals\n ...Effectable.CommitPrototype,\n commit() {\n return eff;\n },\n } as any;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { raise } from '@dxos/debug';\nimport { assertArgument } from '@dxos/invariant';\nimport { DXN, URI } from '@dxos/keys';\n\nimport { getSchemaURI, getTypename } from '../Annotation/annotations';\nimport { type AnyEntity, InstancePhantomId, KindId, TypeId, getStaticTypeSchema } from '../common/types';\nimport { getUri as getUriFromEntity } from './api';\n\n/**\n * @param input schema, `Type.Type` entity, or a typename string.\n * @return type identifier URI — see {@link getSchemaURI}. For a typename string,\n * always a DXN. For a `Type.Type` entity, the URI of the schema it declares,\n * symmetric with what `Obj.make(typeEntity, ...)` stamps on `system.type`: a\n * static declaration resolves to its typename DXN, a persisted entity to its\n * local `echo:/<objectId>`.\n */\nexport const getTypeURIFromSpecifier = (input: Schema.Schema.All | AnyEntity | string): URI.URI => {\n if (Schema.isSchema(input)) {\n return getSchemaURI(input) ?? raise(new TypeError('Schema has no URI'));\n }\n if (typeof input === 'object' && input !== null && KindId in input) {\n // `Type.Type` entity. Both in-memory and persisted forms expose the schema\n // they declare via `StaticTypeSchemaSlot`, whose URI is exactly what\n // `Obj.make` stamps on `system.type` — a static declaration carries\n // `TypeAnnotation` (→ typename DXN), a persisted entity's rebuilt schema\n // carries `TypeIdentifierAnnotation` (→ local `echo:/<objectId>`).\n const schema = getStaticTypeSchema(input);\n if (schema != null) {\n return getSchemaURI(schema) ?? raise(new TypeError('Type entity has no URI'));\n }\n return getUriFromEntity(input as AnyEntity);\n }\n assertArgument(typeof input === 'string', 'input');\n assertArgument(!input.startsWith('dxn:'), 'input');\n return DXN.make(input);\n};\n\n/**\n * Checks if the object is an instance of the schema.\n * Only typename is compared, the schema version is ignored.\n *\n * The following cases are considered to mean that the object is an instance of the schema:\n * - Object was created with this exact schema.\n * - Object was created with a different version of this schema.\n * - Object was created with a different schema (maybe dynamic) that has the same typename.\n */\n// TODO(burdon): Can we use `Schema.is`?\nexport const isInstanceOf = <S>(\n schemaOrType: S extends Schema.Schema.AnyNoContext ? S : Schema.Schema.AnyNoContext | AnyEntity,\n object: any,\n): object is S extends Schema.Schema.AnyNoContext\n ? Schema.Schema.Type<S>\n : S extends { readonly [InstancePhantomId]?: infer A }\n ? A\n : unknown => {\n if (object == null) {\n return false;\n }\n\n const schemaURI = getTypeURIFromSpecifier(schemaOrType);\n\n // `object` is arbitrary input — read TypeId directly (it may be missing on\n // non-entities) rather than via `getTypeURI` which asserts the URI is set.\n const type = (object as any)[TypeId];\n if (URI.isURI(type) && type === schemaURI) {\n return true;\n }\n\n const typename = getTypename(object);\n if (!typename) {\n return false;\n }\n\n if (!DXN.isDXN(schemaURI)) {\n // EID-based schema URI — no typename match possible.\n return false;\n }\n\n const parsed = DXN.tryMake(schemaURI);\n return parsed != null && DXN.getName(parsed) === typename;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { type JsonPath, getField } from '@dxos/effect';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, URI } from '@dxos/keys';\nimport { type Primitive } from '@dxos/util';\n\nimport type * as Annotation from '../../Annotation';\nimport { type Mutable } from '../common/proxy';\nimport { type AnyProperties, EntityKind, TypeId, getSchema } from '../common/types';\nimport { createAnnotationHelper } from './util';\n\nconst ANNOTATION_TYPE_ID: Annotation.TypeId = '~@dxos/echo/Annotation' as const;\n\n/**\n * @internal\n */\nexport const FIELD_PATH_ANNOTATION = 'path';\n\n/**\n * Sets the path for the field.\n * @param path Data source path in the json path format. This is the field path in the source object.\n */\n// TODO(burdon): Field, vs. path vs. property.\nexport const FieldPath = (path: string) => PropertyMeta(FIELD_PATH_ANNOTATION, path);\n\n//\n// Type\n//\n\n/**\n * ECHO identifier (for a stored schema).\n * Must be a `dxn:echo:` URI.\n */\nexport const TypeIdentifierAnnotationId = Symbol.for('@dxos/schema/annotation/TypeIdentifier');\n\nexport const getTypeIdentifierAnnotation = (schema: Schema.Schema.All) =>\n Function.flow(\n SchemaAST.getAnnotation<string>(TypeIdentifierAnnotationId),\n Option.getOrElse(() => undefined),\n )(schema.ast);\n\n/**\n * @returns The schema's type identifier URI — whichever URI fits.\n *\n * - Stored (dynamic) schemas: the schema-as-object's EID, so loaded objects ride\n * along with their schema as a strong dependency.\n * - Non-stored (static) schemas: the typename DXN built from `TypeAnnotation`.\n *\n * This URI is what gets written to an object's `system.type`; queries that filter by\n * type also use it (see `Filter.type` / `getTypeURIFromSpecifier`), so both sides\n * stay symmetric without per-schema branching.\n */\nexport const getSchemaURI = (schema: Schema.Schema.All): URI.URI | undefined => {\n assertArgument(Schema.isSchema(schema), 'schema', 'invalid schema');\n const id = getTypeIdentifierAnnotation(schema);\n if (id) {\n return URI.make(id);\n }\n const objectAnnotation = getTypeAnnotation(schema);\n if (objectAnnotation) {\n return DXN.make(objectAnnotation.typename, objectAnnotation.version);\n }\n return undefined;\n};\n\n//\n// TypeAnnotation\n//\n\n/**\n * Fully qualified globally unique typename.\n * Example: `org.dxos.type.message`\n */\n// TODO(wittjosiah): Factor out to DXN spec.\nexport const TypenameSchema = Schema.String.pipe(\n Schema.pattern(\n /^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)$/,\n ),\n).annotations({\n description: 'Fully qualified globally unique typename in reverse-DNS form.',\n example: 'org.dxos.type.message',\n});\n\n/**\n * Semantic version format: `major.minor.patch`\n * Example: `1.0.0`\n */\nexport const VersionSchema = Schema.String.pipe(Schema.pattern(/^\\d+.\\d+.\\d+$/)).annotations({\n description: 'Semantic version format: `major.minor.patch`',\n example: '1.0.0',\n});\n\nexport const TypeMeta = Schema.Struct({\n typename: TypenameSchema,\n version: VersionSchema,\n});\n\nexport interface TypeMeta extends Schema.Schema.Type<typeof TypeMeta> {}\n\n/**\n * Entity type.\n */\nexport const TypeAnnotationId = Symbol.for('@dxos/schema/annotation/Type');\n\n/**\n * Payload stored under {@link TypeAnnotationId}.\n */\nexport const TypeAnnotation = Schema.extend(\n TypeMeta,\n Schema.Struct({\n kind: Schema.Enums(EntityKind),\n\n /**\n * If this is a relation, the schema of the source object.\n * Must be present if entity kind is {@link EntityKind.Relation}.\n */\n sourceSchema: Schema.optional(DXN.Schema),\n\n /**\n * If this is a relation, the schema of the target object.\n * Must be present if entity kind is {@link EntityKind.Relation}.\n */\n targetSchema: Schema.optional(DXN.Schema),\n }),\n);\n\nexport interface TypeAnnotation extends Schema.Schema.Type<typeof TypeAnnotation> {}\n\n/**\n * @returns {@link TypeAnnotation} from a schema.\n * Schema must have been created with {@link TypedObject} or {@link TypedLink} or manually assigned an appropriate annotation.\n */\nexport const getTypeAnnotation = (schema: Schema.Schema.All): TypeAnnotation | undefined => {\n assertArgument(schema != null && schema.ast != null, 'schema', 'invalid schema');\n return Function.flow(\n SchemaAST.getAnnotation<TypeAnnotation>(TypeAnnotationId),\n Option.getOrElse(() => undefined),\n )(schema.ast);\n};\n\n/**\n * @returns {@link EntityKind} from a schema.\n */\nexport const getEntityKind = (schema: Schema.Schema.All): EntityKind | undefined => getTypeAnnotation(schema)?.kind;\n\n/**\n * @internal\n * @returns Schema typename (without dxn: prefix or version number).\n */\nexport const getSchemaTypename = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.typename;\n\n/**\n * @internal\n * @returns Schema version in semver format.\n */\nexport const getSchemaVersion = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.version;\n\n/**\n * Gets the typename of the object without the version.\n * Returns only the name portion, not the DXN.\n * @example \"org.example.type.contact\"\n *\n * @internal (use Obj.getTypename)\n */\nexport const getTypename = (obj: AnyProperties): string | undefined => {\n const schema = getSchema(obj);\n if (schema != null) {\n // Try to extract typename from DXN.\n return getSchemaTypename(schema);\n } else {\n // `obj` may be an arbitrary value (e.g. from `isInstanceOf`); read TypeId\n // directly so we return undefined for non-entities instead of throwing.\n const type = (obj as any)?.[TypeId];\n // Parse the URI string to extract typename.\n if (DXN.isDXN(type)) {\n const parsed = DXN.tryMake(type);\n return parsed && DXN.getName(parsed);\n }\n return undefined;\n }\n};\n\n/**\n * @internal (use Type.setTypename)\n */\n// TODO(dmaretskyi): Rename setTypeDXN.\nexport const setTypename = (obj: any, typename: URI.URI): void => {\n assertArgument(typeof typename === 'string', 'typename', 'Invalid type.');\n Object.defineProperty(obj, TypeId, {\n value: typename,\n writable: false,\n enumerable: false,\n configurable: false,\n });\n};\n\n/**\n * @returns Object type URI — either a typename {@link DXN} or an `echo:` reference to a stored Schema object.\n * @returns undefined if the object has no registered type URI (e.g. unresolved query result).\n * @example `dxn:com.example.type.person:1.0.0`\n * @example `echo:/01KKKG2FHWCMTR0BY00GJSVT1X` (stored schema)\n *\n * @internal (use Obj.getTypeURI)\n */\nexport const getTypeURI = (obj: AnyProperties): URI.URI | undefined => {\n if (obj == null) {\n return undefined;\n }\n const type = (obj as any)[TypeId];\n if (type == null) {\n return undefined;\n }\n invariant(URI.isURI(type), 'Invalid object.');\n return type;\n};\n\n//\n// PropertyMeta\n//\n\n/**\n * PropertyMeta (metadata for dynamic schema properties).\n * For user-defined annotations.\n */\nexport const PropertyMetaAnnotationId = Symbol.for('@dxos/schema/annotation/PropertyMeta');\n\nexport type PropertyMetaValue = Primitive | Record<string, Primitive> | Primitive[];\n\nexport type PropertyMetaAnnotation = {\n [name: string]: PropertyMetaValue;\n};\n\n// TODO(wittjosiah): Align with other annotations.\n// TODO(wittjosiah): Why is this separate from FormatAnnotation?\n/**\n * Apply property-level metadata to an Effect schema. Only accepts\n * `Schema.Schema.Any` — apply BEFORE wrapping the schema with\n * `Type.makeObject` / `Type.makeRelation`. To read property meta off a\n * `Type.Type` entity, unwrap it first with `Type.getSchema(entity)`.\n */\nexport const PropertyMeta = (name: string, value: PropertyMetaValue) => {\n return <A, I, R>(self: Schema.Schema<A, I, R>): Schema.Schema<A, I, R> => {\n const existingMeta = self.ast.annotations[PropertyMetaAnnotationId] as PropertyMetaAnnotation;\n return self.annotations({\n [PropertyMetaAnnotationId]: {\n ...existingMeta,\n [name]: value,\n },\n });\n };\n};\n\nexport const getPropertyMetaAnnotation = <T>(prop: SchemaAST.PropertySignature, name: string) =>\n Function.pipe(\n SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(prop.type),\n Option.map((meta) => meta[name] as T),\n Option.getOrElse(() => undefined),\n );\n\n//\n// Reference\n//\n\n/**\n * Schema reference.\n */\nexport const ReferenceAnnotationId = Symbol.for('@dxos/schema/annotation/Reference');\nexport type ReferenceAnnotationValue = TypeAnnotation;\nexport const ReferenceAnnotation = createAnnotationHelper<ReferenceAnnotationValue>(ReferenceAnnotationId);\n\n/**\n * SchemaMeta.\n */\nexport const SchemaMetaSymbol = Symbol.for('@dxos/schema/SchemaMeta');\nexport type SchemaMeta = TypeMeta & { id: string };\n\n/**\n * Identifies a schema as hidden from user-facing surfaces (like dotfiles — visible only via an advanced setting).\n */\nexport const HiddenAnnotationId = Symbol.for('@dxos/schema/annotation/Hidden');\nexport const HiddenAnnotation = createAnnotationHelper<boolean>(HiddenAnnotationId);\n\n/**\n * Identifies label property or JSON path expression.\n * Either a string or an array of strings representing field accessors each matched in priority order.\n */\nexport const LabelAnnotationId = Symbol.for('@dxos/schema/annotation/Label');\nexport const LabelAnnotation = createAnnotationHelper<string[]>(LabelAnnotationId);\n\n/**\n * Returns the label for a given object based on {@link LabelAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n * Skips empty strings and whitespace-only strings, continuing to the next field.\n */\n// TODO(burdon): Convert to JsonPath?\nexport const getLabelWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n): string | undefined => {\n const annotation = LabelAnnotation.get(schema).pipe(Option.getOrElse(() => ['name']));\n for (const accessor of annotation) {\n assertArgument(\n typeof accessor === 'string',\n 'accessor',\n 'Label annotation must be a string or an array of strings',\n );\n const value = getField(object, accessor as JsonPath);\n switch (typeof value) {\n case 'string': {\n const trimmed = value.trim();\n if (trimmed.length > 0) {\n return value;\n }\n continue;\n }\n case 'number':\n case 'boolean':\n case 'bigint':\n case 'symbol':\n return value.toString();\n case 'undefined':\n case 'object':\n case 'function':\n continue;\n }\n }\n\n return undefined;\n};\n\n/**\n * Sets the label for a given object based on {@link LabelAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\nexport const setLabelWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n label: string,\n) => {\n const annotation = LabelAnnotation.get(schema).pipe(\n Option.map((field) => field[0]),\n Option.getOrElse(() => 'name'),\n );\n object[annotation] = label;\n};\n\n/**\n * Identifies description property or JSON path expression.\n * A string representing field accessor.\n */\nexport const DescriptionAnnotationId = Symbol.for('@dxos/schema/annotation/Description');\nexport const DescriptionAnnotation = createAnnotationHelper<string>(DescriptionAnnotationId);\n\n/**\n * Returns the description for a given object based on {@link DescriptionAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\n// TODO(burdon): Convert to JsonPath?\nexport const getDescriptionWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n): string | undefined => {\n const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));\n assertArgument(typeof accessor === 'string', 'accessor', 'Description annotation must be a string');\n const value = getField(object, accessor as JsonPath);\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean':\n case 'bigint':\n case 'symbol':\n return value.toString();\n case 'undefined':\n case 'object':\n case 'function':\n default:\n return undefined;\n }\n};\n\n/**\n * Sets the description for a given object based on {@link DescriptionAnnotationId}.\n * Lower-level version that requires explicit schema parameter.\n */\nexport const setDescriptionWithSchema = <S extends Schema.Schema.Any>(\n schema: S,\n object: Schema.Schema.Type<S>,\n description: string,\n) => {\n const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));\n object[accessor] = description;\n};\n\n/**\n * Identifies if a property should be included in a form or not.\n * By default, all properties are included in forms, so this is opt-out.\n */\nexport const FormInputAnnotationId = Symbol.for('@dxos/schema/annotation/FormInput');\nexport const FormInputAnnotation = createAnnotationHelper<boolean>(FormInputAnnotationId);\n\n/**\n * When set on a `Ref` property, the form renders the referenced object's own\n * fields inline (a nested form bound to the target) instead of a picker.\n */\nexport const FormInlineAnnotationId = Symbol.for('@dxos/schema/annotation/FormInline');\nexport const FormInlineAnnotation = createAnnotationHelper<boolean>(FormInlineAnnotationId);\n\n/**\n * Default field to be used on referenced schema to lookup the value.\n */\nexport const FieldLookupAnnotationId = Symbol.for('@dxos/schema/annotation/FieldLookup');\n\n/**\n * Generate test data.\n */\nexport const GeneratorAnnotationId = Symbol.for('@dxos/schema/annotation/Generator');\n\nexport type GeneratorAnnotationValue =\n | string\n | {\n generator: string;\n args?: any[];\n probability?: number;\n };\n\nexport const GeneratorAnnotation = createAnnotationHelper<GeneratorAnnotationValue>(GeneratorAnnotationId);\n\ninterface MakeAnnoationsProps<T> {\n id: string;\n schema: Schema.Schema<T, any, never>;\n}\n\n// Annotation ids use the same NSID / reverse-DNS format as TypenameSchema —\n// dot-separated segments, middle segments may be hyphenated, final segment may be camelCase.\n// At least 3 segments are required (e.g. org.dxos.annotation.example).\nexport const makeUserAnnotation = <T>(props: MakeAnnoationsProps<T>): Annotation.Annotation<T> => {\n assertArgument(\n /^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){2,}(\\.[a-zA-Z]([a-zA-Z0-9]{0,62})?)?$/.test(\n props.id,\n ),\n 'id',\n 'Annotation id must be in the FQN format (org.dxos.annotation.example or org.dxos.space.rootCollection).',\n );\n\n const annotation: Annotation.Annotation<T> = {\n [ANNOTATION_TYPE_ID]: { _Type: {} as T },\n key: props.id as Annotation.Key,\n schema: props.schema,\n get: (schema) => getFromAst(schema.ast, annotation),\n getFromAst: (ast) => getFromAst(ast, annotation),\n set: (value) =>\n PropertyMeta(props.id, Schema.encodeSync(props.schema)(value)) as <S extends Schema.Schema.Any>(schema: S) => S,\n };\n\n return annotation;\n};\n\nconst IconAnnotationSchema = Schema.Struct({\n /**\n * Phosphor icon name (e.g., 'ph--user--regular', 'ph--cube--regular', 'ph--link--regular ', etc.)\n */\n icon: Schema.String.pipe(Schema.pattern(/^ph--[a-z-]+--[a-z]+$/)),\n\n /**\n * Color name.\n *\n * List of colors:\n * - 'red'\n * - 'orange'\n * - 'amber'\n * - 'yellow'\n * - 'lime'\n * - 'green'\n * - 'emerald'\n * - 'teal'\n * - 'cyan'\n * - 'violet'\n * - 'purple'\n * - 'fuchsia'\n * - 'pink'\n * - 'rose'\n */\n hue: Schema.optional(Schema.String),\n});\n\nexport interface IconAnnotation extends Schema.Schema.Type<typeof IconAnnotationSchema> {}\n\n/**\n * Icon to render in the UI.\n */\nexport const IconAnnotation = makeUserAnnotation<IconAnnotation>({\n id: 'org.dxos.annotation.icon',\n schema: IconAnnotationSchema,\n});\n\n/**\n * Indicates that this entity's icon should be resolved from a property whose value is a `Ref`\n * to another entity. Consumers (e.g. graph node builders) resolve the ref target and use that\n * target's schema `IconAnnotation` in place of the static one declared on this schema.\n *\n * Useful for wrapper schemas that delegate their visual identity to a referenced sub-entity\n * (e.g. a generic `Game` whose icon should come from its `variant` ref's typed state).\n */\nexport const IconFromRefAnnotation = makeUserAnnotation<string>({\n id: 'org.dxos.annotation.icon.from-ref',\n schema: Schema.String,\n});\n\n/**\n * Options for {@link getLabel}.\n */\nexport type GetLabelOptions = {\n /**\n * Strategy for deriving a label when the entity has no `LabelAnnotation` value.\n * - `'typename'`: use the entity's typename (e.g. `org.dxos.type.table`).\n * Useful for Card.Title chrome that must always display something, even\n * for unlabeled objects.\n */\n fallback?: 'typename';\n};\n\n/**\n * Get the label of an entity.\n * Accepts both reactive entities and snapshots.\n *\n * If `options.fallback === 'typename'` and no label is set, returns the\n * entity's typename instead.\n */\nexport const getLabel = (entity: AnyProperties, options?: GetLabelOptions): string | undefined => {\n const schema = getSchema(entity);\n const label = schema != null ? getLabelWithSchema(schema, entity) : undefined;\n if (label != null) {\n return label;\n }\n if (options?.fallback === 'typename') {\n return getTypename(entity);\n }\n return undefined;\n};\n\n/**\n * Set the label of an entity.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const setLabel = (entity: Mutable<AnyProperties>, label: string) => {\n const schema = getSchema(entity);\n if (schema != null) {\n setLabelWithSchema(schema, entity, label);\n }\n};\n\n/**\n * Get the description of an entity.\n * Accepts both reactive entities and snapshots.\n */\nexport const getDescription = (entity: AnyProperties): string | undefined => {\n const schema = getSchema(entity);\n if (schema != null) {\n return getDescriptionWithSchema(schema, entity);\n }\n};\n\n/**\n * Get the icon annotation for an entity, resolved via its type-level `IconAnnotation`.\n * Accepts both reactive entities and snapshots.\n *\n * Returns the full `{ icon, hue }` annotation so callers can use both the phosphor icon\n * name and the suggested colour. Callers wanting just the icon name typically write\n * `Obj.getIcon(obj)?.icon ?? 'ph--cube--regular'`.\n *\n * Note: this is the \"static\" icon from the object's own schema. It does not follow\n * `IconFromRefAnnotation` delegation — call sites needing that (e.g. app-graph node\n * builders) should resolve the ref themselves.\n */\nexport const getIcon = (entity: AnyProperties): IconAnnotation | undefined => {\n const schema = getSchema(entity);\n if (schema == null) {\n return undefined;\n }\n return Option.getOrUndefined(IconAnnotation.get(schema));\n};\n\n/**\n * Set the description of an entity.\n * Must be called within an Obj.update or Relation.update callback.\n */\nexport const setDescription = (entity: Mutable<AnyProperties>, description: string) => {\n const schema = getSchema(entity);\n if (schema != null) {\n setDescriptionWithSchema(schema, entity, description);\n }\n};\n\nexport { Dictionary, Key, getDictionary, setDictionary } from './dictionary';\n\nexport const getFromAst = <T>(ast: SchemaAST.AST, annotation: Annotation.Annotation<T>): Option.Option<T> => {\n return SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(ast).pipe(\n Option.flatMap((meta) => Option.fromNullable(meta[annotation.key])),\n Option.map(Schema.decodeUnknownSync(annotation.schema)),\n );\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// TODO(rename): These internal entity-wide symbols/types still use the `Object*` prefix but apply\n// to all entities (objects AND relations). Rename to `Entity*` in a follow-up pass (deferred from the\n// EchoURI→EID / ObjectId→EntityId / ObjectMeta→EntityMeta rename, which covered only public SDK API):\n// ObjectCore, ObjectInternals, ObjectVersion, ObjectVersionId, ObjectDeletedId, ObjectDatabaseId,\n// ObjectLoader, ObjectDocumentLoaded, ObjectUnavailable.\n// (ObjectMigration / ObjectMigrationContext intentionally excluded — object-only, not entity-wide.)\n\n/**\n * Internal symbol/string constants for the echo object model.\n * Defined in common/ so proxy/ can use them without importing from Entity/.\n * Entity/ re-exports these for external consumers.\n */\n\n/**\n * Property name for the object's own URI when serialized to JSON.\n */\nexport const ATTR_SELF_URI = '@uri';\n\n/**\n * @deprecated Legacy JSON property name accepted on read for backward compat.\n */\nexport const ATTR_SELF_URI_LEGACY = '@dxn';\n\n/**\n * Symbol carrying the object's own URI on live entities.\n */\nexport const SelfURIId = Symbol.for('@dxos/echo/URI');\n\n/**\n * Property name for deleted when object is serialized to JSON.\n */\nexport const ATTR_DELETED = '@deleted';\n\n/**\n * Deletion marker.\n */\nexport const ObjectDeletedId = Symbol.for('@dxos/echo/Deleted');\n\n/**\n * Object version accessor symbol.\n */\nexport const ObjectVersionId: unique symbol = Symbol.for('@dxos/echo/Version');\n\n/**\n * Object database accessor symbol.\n */\nexport const ObjectDatabaseId = Symbol.for('@dxos/echo/Database');\n\n/**\n * Property name for relation source when object is serialized to JSON.\n */\nexport const ATTR_RELATION_SOURCE = '@relationSource';\n\n/**\n * Used to access relation source ref on live ECHO objects.\n */\nexport const RelationSourceId: unique symbol = Symbol.for('@dxos/echo/RelationSource');\n\n/**\n * Used to access relation source DXN on live ECHO objects.\n */\nexport const RelationSourceDXNId: unique symbol = Symbol.for('@dxos/echo/RelationSourceDXN');\n\n/**\n * Property name for relation target when object is serialized to JSON.\n */\nexport const ATTR_RELATION_TARGET = '@relationTarget';\n\n/**\n * Used to access relation target ref on live ECHO objects.\n */\nexport const RelationTargetId: unique symbol = Symbol.for('@dxos/echo/RelationTarget');\n\n/**\n * Used to access relation target DXN on live ECHO objects.\n */\nexport const RelationTargetDXNId: unique symbol = Symbol.for('@dxos/echo/RelationTargetDXN');\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\n\n/**\n * Property name for typename when object is serialized to JSON.\n */\nexport const ATTR_TYPE = '@type';\n\n/**\n * DXN to the object type.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Type');\n\n/**\n * Reference to the object schema.\n */\nexport const SchemaId = Symbol.for('@dxos/echo/Schema');\n\n/**\n * Property name for parent when object is serialized to JSON.\n */\nexport const ATTR_PARENT = '@parent';\n\n/**\n * Reference to the object parent.\n */\nexport const ParentId = Symbol.for('@dxos/echo/Parent');\n\n/**\n * Reference to the object's type entity (`Type.Obj`, `Type.Relation`, or\n * `Type.Type`). Set at instance creation by `createObject` / `makeObject`\n * when the entity is known. Public read-back via `Obj.getType` / `Relation.getType`\n * / `Entity.getType`.\n */\nexport const TypeEntityId = Symbol.for('@dxos/echo/TypeEntity');\n\n/**\n * Returns the Effect Schema for the given object if one is defined.\n *\n * @internal\n * Internal callers needing schema-side validation read from `SchemaId`.\n * Public callers should use `Type.getSchema(Obj.getType(obj))` instead.\n */\n// TODO(dmaretskyi): For echo objects, this always returns the root schema.\nexport const getSchema = (obj: unknown | undefined): Schema.Schema.AnyNoContext | undefined => {\n if (obj) {\n return (obj as any)[SchemaId];\n }\n};\n\n/**\n * @internal\n */\nexport const setSchema = (obj: any, schema: Schema.Schema.AnyNoContext): void => {\n Object.defineProperty(obj, SchemaId, {\n value: schema,\n writable: false,\n enumerable: false,\n configurable: false,\n });\n};\n\n/**\n * Returns the type entity (`Type.AnyEntity`) for the given instance.\n * Set at instance creation; every entity has a type. Defensive: returns\n * undefined for null/undefined input so callers can safely probe arbitrary\n * values via this helper.\n *\n * @internal Re-exported via `Obj.getType` / `Relation.getType` / `Entity.getType`.\n */\nexport const getType = (obj: unknown): unknown => {\n if (obj == null) {\n return undefined;\n }\n return (obj as any)[TypeEntityId];\n};\n\n/**\n * @internal\n */\nexport const setType = (obj: any, type: unknown): void => {\n Object.defineProperty(obj, TypeEntityId, {\n value: type,\n writable: false,\n enumerable: false,\n configurable: true,\n });\n};\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Function from 'effect/Function';\nimport * as Option from 'effect/Option';\nimport * as Schema from 'effect/Schema';\nimport * as Types from 'effect/Types';\n\nimport type * as Annotation from '../../Annotation';\n\n/**\n * Unique identifier for an annotation.\n */\nexport const Key = Schema.String.pipe(Schema.brand('~@dxos/echo/AnnotationKey'));\nexport type Key = Schema.Schema.Type<typeof Key>;\n\n/**\n * Set of annotation values stored on entity meta or nested in schemas.\n */\nexport const Dictionary = Schema.Record({ key: Key, value: Schema.Unknown });\nexport interface Dictionary extends Schema.Schema.Type<typeof Dictionary> {}\n\n/**\n * Get the value of an annotation from a dictionary.\n */\nexport const getDictionary = <T>(\n values: Annotation.Dictionary,\n annotation: Annotation.Annotation<T>,\n): Option.Option<T> => {\n if (!(annotation.key in values)) {\n return Option.none();\n }\n\n return Function.pipe(values[annotation.key], Schema.decodeUnknownSync(annotation.schema), Option.some);\n};\n\n/**\n * Set the value of an annotation in a dictionary.\n */\nexport const setDictionary = <T>(\n values: Types.Mutable<Annotation.Dictionary>,\n annotation: Annotation.Annotation<T>,\n value: T,\n): void => {\n values[annotation.key] = Schema.encodeSync(annotation.schema)(value);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { type EID } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport type { AnyEntity } from '../common/types';\nimport { type InternalObjectProps, ObjectDatabaseId } from './model';\nimport { getObjectEchoUri } from './util';\n\n/**\n * Get the canonical EID of an entity.\n * Accepts both reactive entities and snapshots.\n */\nexport const getUri = (entity: AnyEntity): EID.EID => {\n const uri = getObjectEchoUri(entity);\n invariant(uri != null, 'Invalid entity.');\n return uri;\n};\n\n/**\n * Get the database the entity belongs to.\n * Accepts both reactive entities and snapshots.\n */\nexport const getDatabase = (entity: AnyEntity): any | undefined => {\n assumeType<InternalObjectProps>(entity);\n return entity[ObjectDatabaseId];\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Schema from 'effect/Schema';\n\nimport { type ForeignKey } from '@dxos/echo-protocol';\nimport { invariant } from '@dxos/invariant';\nimport { EID, EntityId, type URI } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport type * as Database from '../../Database';\nimport {\n type ATTR_PARENT,\n type ATTR_TYPE,\n ATTR_DELETED,\n ATTR_RELATION_SOURCE,\n ATTR_RELATION_TARGET,\n ATTR_SELF_URI,\n ATTR_SELF_URI_LEGACY,\n EntityKind,\n KindId,\n ObjectDatabaseId,\n ObjectDeletedId,\n ObjectVersionId,\n type ParentId,\n RelationSourceDXNId,\n RelationSourceId,\n RelationTargetDXNId,\n RelationTargetId,\n type SchemaId,\n SelfURIId,\n TypeId,\n type Version,\n} from '../common/types';\nimport { type ATTR_META, type MetaId, type EntityMeta } from '../common/types/meta';\n\nexport {\n ATTR_DELETED,\n ATTR_SELF_URI,\n ATTR_SELF_URI_LEGACY,\n ObjectDatabaseId,\n ObjectDeletedId,\n ObjectVersionId,\n SelfURIId,\n};\n\n/**\n * Internal runtime representation of an object.\n * The fields are accessed through getter functions.\n */\n// NOTE: Each symbol has a jsdoc describing its purpose.\nexport interface InternalObjectProps {\n readonly id: EntityId;\n readonly [SelfURIId]: EID.EID;\n readonly [KindId]: EntityKind;\n readonly [SchemaId]: Schema.Schema.AnyNoContext;\n readonly [TypeId]: URI.URI;\n readonly [MetaId]?: EntityMeta;\n [ParentId]?: InternalObjectProps;\n readonly [ObjectDatabaseId]?: Database.Database;\n readonly [ObjectDeletedId]?: boolean;\n readonly [ObjectVersionId]?: Version;\n readonly [RelationSourceDXNId]?: EID.EID;\n readonly [RelationTargetDXNId]?: EID.EID;\n readonly [RelationSourceId]?: InternalObjectProps;\n readonly [RelationTargetId]?: InternalObjectProps;\n}\n\n/**\n * Entity metadata.\n */\nexport interface EntityMetaJSON {\n keys: ForeignKey[];\n tags?: string[];\n key?: string;\n version?: string;\n}\n\n/**\n * JSON representation of an object or relation metadata.\n */\nexport interface ObjectJSON {\n id: EntityId;\n [ATTR_TYPE]?: URI.URI;\n [ATTR_SELF_URI]?: EID.EID;\n [ATTR_PARENT]?: EID.EID; // Encoded reference\n [ATTR_DELETED]?: boolean;\n [ATTR_META]?: EntityMetaJSON;\n [ATTR_RELATION_SOURCE]?: EID.EID;\n [ATTR_RELATION_TARGET]?: EID.EID;\n\n /**\n * Application-specific properties.\n */\n [key: string]: unknown;\n}\n\n/**\n * NOTE: Keep as `function` to avoid type inference issues.\n */\nexport function assertObjectModel(obj: unknown): asserts obj is InternalObjectProps {\n invariant(typeof obj === 'object' && obj !== null, 'Invalid object model: not an object');\n assumeType<InternalObjectProps>(obj);\n invariant(EntityId.isValid(obj.id), 'Invalid object model: invalid id');\n invariant(obj[TypeId] === undefined || typeof obj[TypeId] === 'string', 'Invalid object model: invalid type');\n invariant(\n obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation || obj[KindId] === EntityKind.Type,\n 'Invalid object model: invalid entity kind',\n );\n\n if (obj[KindId] === EntityKind.Relation) {\n invariant(EID.isEID(obj[RelationSourceDXNId]), 'Invalid object model: invalid relation source');\n invariant(EID.isEID(obj[RelationTargetDXNId]), 'Invalid object model: invalid relation target');\n invariant(!EID.isEID(obj[RelationSourceId]), 'Invalid object model: source pointer is a DXN');\n invariant(!EID.isEID(obj[RelationTargetId]), 'Invalid object model: target pointer is a DXN');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { EID, EntityId } from '@dxos/keys';\nimport { assumeType } from '@dxos/util';\n\nimport { type InternalObjectProps, SelfURIId } from './model';\n\n/**\n * Returns the EID of an object.\n * Normalizes any legacy `dxn:echo:` / `dxn:queue:` form stored in `SelfURIId`.\n *\n * @internal\n */\nexport const getObjectEchoUri = (object: any): EID.EID | undefined => {\n invariant(!Schema.isSchema(object), 'schema not allowed in this function');\n assertArgument(typeof object === 'object' && object != null, 'object', 'expected object');\n assumeType<InternalObjectProps>(object);\n\n if (object[SelfURIId]) {\n invariant(EID.isEID(object[SelfURIId]), 'Invalid object model: invalid self dxn');\n return EID.parse(object[SelfURIId]);\n }\n\n if (!EntityId.isValid(object.id)) {\n throw new TypeError('Object id is not valid.');\n }\n\n return EID.make({ entityId: object.id });\n};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EH,SAAA,qBAAA,MAAA;;;;;;;;AA4ES,IAAA,gBAAA,CAAA,kBAAA,MAAA,aAAA,EAAA,KAAA,eAAA,CAAA,gBAAA,wBAAA,YAAA,qBAAA,MAAA,YAAA,iBAAA,CAAA,CAAA,CAAA,GAAA,gBAAA,wBAAA,CAAA;4BACeU,CAAAA,QAAMC;SAC1BC;IAIA,KAAA,eAAmB,KAAA,CAAA,WAAA,wBAAA,MAAA,OAAA,IAAA,CAAA,CAAA;IACnB,OAAcC,eAAAA,KAAAA,CAAAA,WAAe,wBAAA,YAAA,qBAAA,MAAA,OAAA,iBAAA,CAAA,CAAA,CAAA;;OAEpBH;IACT,SAAA;AACF,aAAA;IACF;;;",
|
|
6
|
+
"names": ["TypeId", "Context", "Effect", "Effectable", "Layer", "Option", "Schema", "promiseWithCauseCapture", "invariant", "Schema", "raise", "assertArgument", "DXN", "URI", "Function", "Option", "Schema", "SchemaAST", "getField", "assertArgument", "invariant", "DXN", "URI", "ATTR_SELF_URI", "ATTR_SELF_URI_LEGACY", "SelfURIId", "Symbol", "for", "ATTR_DELETED", "ObjectDeletedId", "ObjectVersionId", "ObjectDatabaseId", "ATTR_RELATION_SOURCE", "RelationSourceId", "RelationSourceDXNId", "ATTR_RELATION_TARGET", "RelationTargetId", "RelationTargetDXNId", "ATTR_TYPE", "TypeId", "Symbol", "for", "SchemaId", "ATTR_PARENT", "ParentId", "TypeEntityId", "getSchema", "obj", "setSchema", "schema", "Object", "defineProperty", "value", "writable", "enumerable", "configurable", "getType", "undefined", "setType", "type", "Function", "Option", "Schema", "Key", "String", "pipe", "brand", "Dictionary", "Record", "key", "value", "Unknown", "getDictionary", "values", "annotation", "none", "decodeUnknownSync", "schema", "some", "setDictionary", "encodeSync", "ANNOTATION_TYPE_ID", "id", "getTypeIdentifierAnnotation", "URI", "objectAnnotation", "typename", "undefined", "example", "TypeMeta", "version", "VersionSchema", "Function", "getAnnotation", "schema", "getSchemaTypename", "DXN", "type", "parsed", "Object", "defineProperty", "obj", "TypeId", "writable", "enumerable", "configurable", "invariant", "existingMeta", "self", "annotations", "PropertyMetaAnnotationId", "value", "assertArgument", "getField", "object", "annotation", "label", "accessor", "description", "key", "get", "getFromAst", "ast", "set", "PropertyMeta", "Schema", "encodeSync", "IconAnnotationSchema", "getLabelWithSchema", "options", "setLabelWithSchema", "entity", "getDescriptionWithSchema", "Option", "setDescriptionWithSchema", "invariant", "assumeType", "invariant", "EID", "EntityId", "assumeType", "__dxlog_file", "ATTR_DELETED", "assumeType", "obj", "invariant", "EntityId", "isValid", "__dxlog_file", "TypeId", "KindId", "EntityKind", "Type", "EID", "isEID", "RelationSourceDXNId", "RelationTargetDXNId", "Schema", "assertArgument", "invariant", "EID", "EntityId", "assumeType", "__dxlog_file", "assertArgument", "object", "assumeType", "SelfURIId", "invariant", "EID", "EntityId", "isValid", "make", "__dxlog_file", "invariant", "uri", "entity", "ObjectDatabaseId", "assumeType", "getTypeURIFromSpecifier", "input", "isSchema", "getSchemaURI", "raise", "TypeError", "KindId", "schema", "getStaticTypeSchema", "getUriFromEntity", "assertArgument", "startsWith", "DXN", "make", "isInstanceOf", "schemaOrType", "object", "schemaURI", "type", "TypeId", "URI", "isURI", "typename", "getTypename", "isDXN", "parsed", "tryMake", "getName", "__dxlog_file", "obj", "TypeId", "Database", "Schema", "Any", "space", "isDatabase", "db", "spaceId", "dxn", "ref", "object", "promiseWithCauseCapture", "context", "resolve", "Effect", "pipe", "withSpan", "EntityNotFoundError", "uri", "Option", "eff", "result", "first", "CommitPrototype"]
|
|
7
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RefArray
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4Z6GET2X.mjs";
|
|
4
4
|
import {
|
|
5
5
|
Ref,
|
|
6
6
|
getSchemaReference
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-7OAFN3OX.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__export
|
|
10
10
|
} from "./chunk-J5LGTIGS.mjs";
|
|
@@ -14,8 +14,8 @@ var Ref_exports = {};
|
|
|
14
14
|
__export(Ref_exports, {
|
|
15
15
|
Array: () => Array,
|
|
16
16
|
Ref: () => Ref2,
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
fromURI: () => fromURI,
|
|
18
|
+
hasEntityId: () => hasEntityId,
|
|
19
19
|
isRef: () => isRef,
|
|
20
20
|
isRefType: () => isRefType,
|
|
21
21
|
make: () => make
|
|
@@ -26,8 +26,8 @@ var Ref2 = Ref;
|
|
|
26
26
|
var Array = RefArray;
|
|
27
27
|
var isRef = Ref.isRef;
|
|
28
28
|
var make = Ref.make;
|
|
29
|
-
var
|
|
30
|
-
var
|
|
29
|
+
var fromURI = (uri) => Ref.fromURI(uri);
|
|
30
|
+
var hasEntityId = Ref.hasEntityId;
|
|
31
31
|
var isRefType = (ast) => {
|
|
32
32
|
return SchemaAST.getAnnotation(ast, SchemaAST.JSONSchemaAnnotationId).pipe(Option.flatMap((jsonSchema) => "$id" in jsonSchema ? Option.some(jsonSchema) : Option.none()), Option.flatMap((jsonSchema) => {
|
|
33
33
|
const { typename } = getSchemaReference(jsonSchema) ?? {};
|
|
@@ -40,9 +40,9 @@ export {
|
|
|
40
40
|
Array,
|
|
41
41
|
isRef,
|
|
42
42
|
make,
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
fromURI,
|
|
44
|
+
hasEntityId,
|
|
45
45
|
isRefType,
|
|
46
46
|
Ref_exports
|
|
47
47
|
};
|
|
48
|
-
//# sourceMappingURL=chunk-
|
|
48
|
+
//# sourceMappingURL=chunk-J3MNM65T.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Ref.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Option from 'effect/Option';\nimport type * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { type URI } from '@dxos/keys';\n\nimport type * as Entity from './Entity';\nimport type * as internal from './internal';\nimport * as refInternal from './internal/Ref';\nimport type * as JsonSchema from './JsonSchema';\nimport type * as Obj from './Obj';\n// eslint-disable-next-line @dxos/rules/import-as-namespace\nimport type * as TypeNs from './Type';\n\n/**\n * Instance type for a reference.\n *\n * Reference can point to any object or relation.\n * References are lazy loaded.\n *\n * `ref.dxn` is the DXN of the referenced object.\n *\n * @example\n * ```ts\n * const taskRef: Ref<Task> = Ref.make(task);\n *\n * await taskRef.load(); // Returns Promise<Task>\n * yield* Database.load(taskRef); // Effectful version.\n *\n * database.makeRef(dxn); // Create a ref from a DXN.\n * ```\n */\nexport type Ref<T> = refInternal.Ref<T>;\nexport type Unknown = refInternal.Ref<Obj.Unknown>;\n\n/**\n * Factory function to create a Ref schema for the given target schema.\n * Use this in schema definitions to declare reference fields.\n *\n * @example\n * ```ts\n * const Task = Schema.Struct({\n * assignee: Ref.Ref(Person), // Creates a Ref schema\n * }).pipe(Type.makeObject(DXN.make('com.example.type.task', '0.1.0')));\n * ```\n */\nexport const Ref: {\n <S extends TypeNs.AnyObj | TypeNs.AnyRelation>(type: S): RefSchema<TypeNs.InstanceType<S> & Obj.Unknown>;\n\n // `Type.Type` entities (the meta-schema kind) can be referenced too — e.g. a\n // trigger that points to a stored function/workflow definition.\n <T extends TypeNs.Type<any>>(type: T): RefSchema<TypeNs.InstanceType<T>>;\n\n // Schema-side overload for the well-known \"any object\" / \"any relation\" schemas.\n // Other raw `Schema.Schema` values are intentionally rejected — callers should\n // pass a `Type.Type` entity instead.\n <S extends internal.UnknownTypeSchema<any, any>>(schema: S): RefSchema<Schema.Schema.Type<S> & Obj.Unknown>;\n} = refInternal.Ref as any;\n\nexport const Array = refInternal.RefArray;\n\n/**\n * TypeScript type for a Ref schema.\n * This is the type of the SCHEMA itself, not the runtime ref instance.\n * For the instance type, use `Ref.Ref<T>` from the Ref module.\n *\n * @example\n * ```ts\n * // Schema type annotation (rarely needed, usually inferred):\n * const refSchema: Ref.RefSchema<typeof Task> = Ref.Ref(Task);\n *\n * // Instance type annotation (use Ref.Ref instead):\n * const refInstance: Ref.Ref<Task> = Ref.make(task);\n * ```\n */\n// TODO(dmaretskyi): Investigate if we can remove this type.\n// Post DX-836 it will become just `Schema.Schema<Ref.Ref<T>>`.\n// NOTE: This could be Type.Ref<T> instead, but since it going to be removed, it's better to keep it here, self-contained.\nexport interface RefSchema<T extends Entity.Unknown> extends refInternal.RefSchema<T> {}\n\n/**\n * Extract reference target.\n */\nexport type Target<R extends Unknown> = R extends refInternal.Ref<infer T> ? T : never;\n\n/**\n * Reference resolver.\n */\nexport type Resolver = refInternal.RefResolver;\n\nexport const isRef: (value: unknown) => value is Unknown = refInternal.Ref.isRef;\n\nexport const make = refInternal.Ref.make;\n\n// TODO(dmaretskyi): Consider just allowing `make` to accept URI.\nexport const fromURI = (uri: URI.URI): refInternal.Ref<any> => refInternal.Ref.fromURI(uri);\n\nexport const hasEntityId = refInternal.Ref.hasEntityId;\n\n// TODO(wittjosiah): Factor out?\nexport const isRefType = (ast: SchemaAST.AST): boolean => {\n return SchemaAST.getAnnotation<JsonSchema.JsonSchema>(ast, SchemaAST.JSONSchemaAnnotationId).pipe(\n Option.flatMap((jsonSchema) => ('$id' in jsonSchema ? Option.some(jsonSchema) : Option.none())),\n Option.flatMap((jsonSchema) => {\n const { typename } = refInternal.getSchemaReference(jsonSchema) ?? {};\n return typename ? Option.some(true) : Option.some(false);\n }),\n Option.getOrElse(() => false),\n );\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAAA;;;aAAAA;EAAA;;;;;;AAMA,YAAYC,YAAY;AAExB,YAAYC,eAAe;AA4CpB,IAAMC,OAWGA;AAET,IAAMC,QAAoBC;AA+B1B,IAAMC,QAA0DH,IAAIG;AAEpE,IAAMC,OAAmBJ,IAAII;AAG7B,IAAMC,UAAU,CAACC,QAAmDN,IAAIK,QAAQC,GAAAA;AAEhF,IAAMC,cAA0BP,IAAIO;AAGpC,IAAMC,YAAY,CAACC,QAAAA;AACxB,SAAiBC,wBAAqCD,KAAeE,gCAAsB,EAAEC,KACpFC,eAAQ,CAACC,eAAgB,SAASA,aAAoBC,YAAKD,UAAAA,IAAqBE,YAAI,CAAA,GACpFH,eAAQ,CAACC,eAAAA;AACd,UAAM,EAAEG,SAAQ,IAAiBC,mBAAmBJ,UAAAA,KAAe,CAAC;AACpE,WAAOG,WAAkBF,YAAK,IAAA,IAAeA,YAAK,KAAA;EACpD,CAAA,GACOI,iBAAU,MAAM,KAAA,CAAA;AAE3B;",
|
|
6
|
+
"names": ["Ref", "Option", "SchemaAST", "Ref", "Array", "RefArray", "isRef", "make", "fromURI", "uri", "hasEntityId", "isRefType", "ast", "getAnnotation", "JSONSchemaAnnotationId", "pipe", "flatMap", "jsonSchema", "some", "none", "typename", "getSchemaReference", "getOrElse"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EchoObjectSchema,
|
|
3
|
+
EchoRelationSchema,
|
|
4
|
+
TypeSchema,
|
|
5
|
+
addFieldsToSchema,
|
|
6
|
+
change,
|
|
7
|
+
makeObject,
|
|
8
|
+
removeFieldsFromSchema,
|
|
9
|
+
updateFieldNameInSchema,
|
|
10
|
+
updateFieldsInSchema,
|
|
11
|
+
version
|
|
12
|
+
} from "./chunk-OYUG4FHF.mjs";
|
|
13
|
+
import {
|
|
14
|
+
toEffectSchema,
|
|
15
|
+
toJsonSchema
|
|
16
|
+
} from "./chunk-7PRCIDHH.mjs";
|
|
17
|
+
import {
|
|
18
|
+
getMetaChecked
|
|
19
|
+
} from "./chunk-4BB4MFCN.mjs";
|
|
20
|
+
import {
|
|
21
|
+
TypeIdentifierAnnotationId,
|
|
22
|
+
getDatabase,
|
|
23
|
+
getSchemaURI,
|
|
24
|
+
getTypeURIFromSpecifier
|
|
25
|
+
} from "./chunk-H26LSXVJ.mjs";
|
|
26
|
+
import {
|
|
27
|
+
EntityKind,
|
|
28
|
+
InstancePhantomId,
|
|
29
|
+
getEntityKindBrand,
|
|
30
|
+
getSchemaKind,
|
|
31
|
+
getStaticTypeSchema
|
|
32
|
+
} from "./chunk-O6BH7EPN.mjs";
|
|
33
|
+
import {
|
|
34
|
+
__export
|
|
35
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
36
|
+
|
|
37
|
+
// src/Type.ts
|
|
38
|
+
var Type_exports = {};
|
|
39
|
+
__export(Type_exports, {
|
|
40
|
+
InstancePhantomId: () => InstancePhantomId2,
|
|
41
|
+
Type: () => Type,
|
|
42
|
+
addFields: () => addFields,
|
|
43
|
+
assertObject: () => assertObject,
|
|
44
|
+
expectRelation: () => expectRelation,
|
|
45
|
+
expectTypeKind: () => expectTypeKind,
|
|
46
|
+
getDatabase: () => getDatabase2,
|
|
47
|
+
getMeta: () => getMeta,
|
|
48
|
+
getSchema: () => getSchema,
|
|
49
|
+
getTypename: () => getTypename,
|
|
50
|
+
getURI: () => getURI,
|
|
51
|
+
getVersion: () => getVersion,
|
|
52
|
+
isObject: () => isObject,
|
|
53
|
+
isRelation: () => isRelation,
|
|
54
|
+
isType: () => isType,
|
|
55
|
+
isTypeKind: () => isTypeKind,
|
|
56
|
+
makeObject: () => makeObject2,
|
|
57
|
+
makeObjectFromJsonSchema: () => makeObjectFromJsonSchema,
|
|
58
|
+
makeRelation: () => makeRelation,
|
|
59
|
+
makeRelationFromJsonSchema: () => makeRelationFromJsonSchema,
|
|
60
|
+
removeFields: () => removeFields,
|
|
61
|
+
update: () => update,
|
|
62
|
+
updateFieldPropertyName: () => updateFieldPropertyName,
|
|
63
|
+
updateFields: () => updateFields
|
|
64
|
+
});
|
|
65
|
+
import { raise } from "@dxos/debug";
|
|
66
|
+
import { assertArgument, invariant } from "@dxos/invariant";
|
|
67
|
+
import { EID } from "@dxos/keys";
|
|
68
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/Type.ts";
|
|
69
|
+
var makeObject2 = EchoObjectSchema;
|
|
70
|
+
var Type = TypeSchema;
|
|
71
|
+
var DRAFT_VERSION = "0.0.0";
|
|
72
|
+
var makeObjectFromJsonSchema = (props) => {
|
|
73
|
+
const { typename, version: version2, ...data } = props;
|
|
74
|
+
return makeObject(getStaticTypeSchema(TypeSchema), data, {
|
|
75
|
+
keys: [],
|
|
76
|
+
key: typename,
|
|
77
|
+
version: version2 ?? DRAFT_VERSION
|
|
78
|
+
}, TypeSchema);
|
|
79
|
+
};
|
|
80
|
+
var makeRelationFromJsonSchema = (props) => {
|
|
81
|
+
const { source, target, jsonSchema, typename, version: version2, ...rest } = props;
|
|
82
|
+
const sourceURI = getTypeURIFromSpecifier(source);
|
|
83
|
+
const targetURI = getTypeURIFromSpecifier(target);
|
|
84
|
+
const enrichedJsonSchema = {
|
|
85
|
+
...jsonSchema,
|
|
86
|
+
entityKind: EntityKind.Relation,
|
|
87
|
+
relationSource: {
|
|
88
|
+
$ref: sourceURI
|
|
89
|
+
},
|
|
90
|
+
relationTarget: {
|
|
91
|
+
$ref: targetURI
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return makeObject(getStaticTypeSchema(TypeSchema), {
|
|
95
|
+
...rest,
|
|
96
|
+
jsonSchema: enrichedJsonSchema
|
|
97
|
+
}, {
|
|
98
|
+
keys: [],
|
|
99
|
+
key: typename,
|
|
100
|
+
version: version2 ?? DRAFT_VERSION
|
|
101
|
+
}, TypeSchema);
|
|
102
|
+
};
|
|
103
|
+
var makeRelation = EchoRelationSchema;
|
|
104
|
+
var isObject = (entity) => {
|
|
105
|
+
return getSchemaKind(entity) === EntityKind.Object;
|
|
106
|
+
};
|
|
107
|
+
var isRelation = (entity) => {
|
|
108
|
+
return getSchemaKind(entity) === EntityKind.Relation;
|
|
109
|
+
};
|
|
110
|
+
var isTypeKind = (entity) => {
|
|
111
|
+
return getSchemaKind(entity) === EntityKind.Type;
|
|
112
|
+
};
|
|
113
|
+
var assertObject = (entity) => {
|
|
114
|
+
assertArgument(isObject(entity), "entity", "Expected an object-kind Type entity.");
|
|
115
|
+
return entity;
|
|
116
|
+
};
|
|
117
|
+
var expectRelation = (entity) => {
|
|
118
|
+
assertArgument(isRelation(entity), "entity", "Expected a relation-kind Type entity.");
|
|
119
|
+
return entity;
|
|
120
|
+
};
|
|
121
|
+
var expectTypeKind = (entity) => {
|
|
122
|
+
assertArgument(isTypeKind(entity), "entity", "Expected a type-kind Type entity.");
|
|
123
|
+
return entity;
|
|
124
|
+
};
|
|
125
|
+
var getURI = (input) => {
|
|
126
|
+
if (isType(input)) {
|
|
127
|
+
return getTypeURIFromSpecifier(input);
|
|
128
|
+
}
|
|
129
|
+
return getSchemaURI(getSchema(input)) ?? raise(new TypeError("Type entity has no URI"));
|
|
130
|
+
};
|
|
131
|
+
var getTypename = (input) => {
|
|
132
|
+
const meta = getMetaChecked(input);
|
|
133
|
+
let typename = meta.key;
|
|
134
|
+
if (typename == null) {
|
|
135
|
+
typename = input.jsonSchema?.typename;
|
|
136
|
+
}
|
|
137
|
+
typename ??= input.id;
|
|
138
|
+
typename = stripTypenamePrefix(typename);
|
|
139
|
+
invariant(typeof typename === "string" && typename.length > 0, "Invalid typename", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 205, S: void 0, A: ["typeof typename === 'string' && typename.length > 0", "'Invalid typename'"] });
|
|
140
|
+
return typename;
|
|
141
|
+
};
|
|
142
|
+
var getVersion = (input) => {
|
|
143
|
+
const meta = getMetaChecked(input);
|
|
144
|
+
const semver = meta.version ?? input.jsonSchema?.version ?? DRAFT_VERSION;
|
|
145
|
+
invariant(typeof semver === "string" && semver.match(/^\d+\.\d+\.\d+$/), "Invalid version", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 226, S: void 0, A: ["typeof semver === 'string' && semver.match(/^\\d+\\.\\d+\\.\\d+$/)", "'Invalid version'"] });
|
|
146
|
+
const heads = version(input).automergeHeads;
|
|
147
|
+
if (heads != null && heads.length > 0) {
|
|
148
|
+
return `${semver}-${[
|
|
149
|
+
...heads
|
|
150
|
+
].sort().join(".")}`;
|
|
151
|
+
}
|
|
152
|
+
return semver;
|
|
153
|
+
};
|
|
154
|
+
var stripTypenamePrefix = (value) => {
|
|
155
|
+
if (value.startsWith("dxn:")) {
|
|
156
|
+
return value.slice("dxn:".length);
|
|
157
|
+
}
|
|
158
|
+
if (value.startsWith("echo://")) {
|
|
159
|
+
return value.slice("echo://".length);
|
|
160
|
+
}
|
|
161
|
+
if (value.startsWith("echo:/")) {
|
|
162
|
+
return value.slice("echo:/".length);
|
|
163
|
+
}
|
|
164
|
+
return value;
|
|
165
|
+
};
|
|
166
|
+
var isType = (value) => getEntityKindBrand(value) === EntityKind.Type;
|
|
167
|
+
var getDatabase2 = (input) => getDatabase(input);
|
|
168
|
+
function getMeta(entity) {
|
|
169
|
+
assertArgument(isType(entity), "entity", "Expected a Type entity.");
|
|
170
|
+
return getMetaChecked(entity);
|
|
171
|
+
}
|
|
172
|
+
var InstancePhantomId2 = InstancePhantomId;
|
|
173
|
+
function getSchema(type) {
|
|
174
|
+
const staticSchema = getStaticTypeSchema(type);
|
|
175
|
+
if (staticSchema != null) {
|
|
176
|
+
return staticSchema;
|
|
177
|
+
}
|
|
178
|
+
assertArgument(isType(type), "type", "Expected a Type entity.");
|
|
179
|
+
const rebuilt = toEffectSchema(type.jsonSchema);
|
|
180
|
+
if (typeof type.id === "string") {
|
|
181
|
+
return rebuilt.annotations({
|
|
182
|
+
[TypeIdentifierAnnotationId]: EID.make({
|
|
183
|
+
entityId: type.id
|
|
184
|
+
})
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return rebuilt;
|
|
188
|
+
}
|
|
189
|
+
var update = (type, callback) => {
|
|
190
|
+
change(type, callback);
|
|
191
|
+
};
|
|
192
|
+
var addFields = (type, fields) => {
|
|
193
|
+
const extended = addFieldsToSchema(getSchema(type), fields);
|
|
194
|
+
update(type, (draft) => {
|
|
195
|
+
draft.jsonSchema = toJsonSchema(extended);
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
var updateFields = (type, fields) => {
|
|
199
|
+
const updated = updateFieldsInSchema(getSchema(type), fields);
|
|
200
|
+
update(type, (draft) => {
|
|
201
|
+
draft.jsonSchema = toJsonSchema(updated);
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
var updateFieldPropertyName = (type, { before, after }) => {
|
|
205
|
+
const renamed = updateFieldNameInSchema(getSchema(type), {
|
|
206
|
+
before,
|
|
207
|
+
after
|
|
208
|
+
});
|
|
209
|
+
update(type, (draft) => {
|
|
210
|
+
draft.jsonSchema = toJsonSchema(renamed);
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
var removeFields = (type, fieldNames) => {
|
|
214
|
+
const removed = removeFieldsFromSchema(getSchema(type), fieldNames);
|
|
215
|
+
update(type, (draft) => {
|
|
216
|
+
draft.jsonSchema = toJsonSchema(removed);
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export {
|
|
221
|
+
makeObject2 as makeObject,
|
|
222
|
+
Type,
|
|
223
|
+
makeObjectFromJsonSchema,
|
|
224
|
+
makeRelationFromJsonSchema,
|
|
225
|
+
makeRelation,
|
|
226
|
+
isObject,
|
|
227
|
+
isRelation,
|
|
228
|
+
isTypeKind,
|
|
229
|
+
assertObject,
|
|
230
|
+
expectRelation,
|
|
231
|
+
expectTypeKind,
|
|
232
|
+
getURI,
|
|
233
|
+
getTypename,
|
|
234
|
+
getVersion,
|
|
235
|
+
isType,
|
|
236
|
+
getDatabase2 as getDatabase,
|
|
237
|
+
getMeta,
|
|
238
|
+
InstancePhantomId2 as InstancePhantomId,
|
|
239
|
+
getSchema,
|
|
240
|
+
update,
|
|
241
|
+
addFields,
|
|
242
|
+
updateFields,
|
|
243
|
+
updateFieldPropertyName,
|
|
244
|
+
removeFields,
|
|
245
|
+
Type_exports
|
|
246
|
+
};
|
|
247
|
+
//# sourceMappingURL=chunk-JE7AOSWF.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Type.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\nimport type * as Types from 'effect/Types';\n\nimport { raise } from '@dxos/debug';\nimport { type EncodedReference } from '@dxos/echo-protocol';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, EID, type EntityId, type URI } from '@dxos/keys';\n\nimport type * as Database from './Database';\nimport type * as EntityModule from './Entity';\nimport * as internal from './internal';\nimport * as typeInternal from './internal/Type';\nimport type * as RelationModule from './Relation';\n\n//\n// Internal types (not exported)\n//\n\n/**\n * Structural base shared by the three sibling type-entity interfaces\n * ({@link Obj}, {@link Relation}, {@link Type}). NOT exported — callers\n * should constrain on {@link AnyEntity} when they want \"any of the three\"\n * and on the specific kind interface otherwise.\n */\ninterface BaseTypeEntity<A> {\n /**\n * Entity-kind brand of the type-entity value itself — always `EntityKind.Type`.\n * The kind of instance the type *describes* lives on `[SchemaKindId]`\n * (Object / Relation / Type). Lets `Obj.isObject` / `Relation.isRelation`\n * reject type entities by a single `[KindId]` check.\n */\n readonly [internal.KindId]: internal.EntityKind.Type;\n\n /**\n * Object id. Like all ECHO entities, type entities always carry an id —\n * stamped at construction for in-memory (static) declarations and assigned by\n * the database once persisted. The id does NOT determine the entity's URI:\n * static types resolve to their typename DXN, persisted types to `echo:/<id>`\n * (see `getTypeURIFromSpecifier`).\n */\n readonly id: EntityId;\n\n readonly name?: string;\n // NOTE: `typename` / `version` are intentionally NOT fields on any type-entity\n // interface. Both static and persisted entities carry them in `EntityMeta`\n // (`key` / `version`); read them via `Type.getTypename(self)` /\n // `Type.getVersion(self)` — never as a direct property.\n readonly jsonSchema: internal.JsonSchemaType;\n readonly [InstancePhantomId]?: A;\n}\n\n//\n// Obj — `Type.Type` value for an ECHO object schema.\n//\n\n/**\n * TypeScript type for an ECHO object type — a `Type.Type<A>` entity.\n *\n * `T` is the instance type produced by `Obj.make(Foo, props)`. `Fields` is\n * retained as a structural hint (the runtime value still carries `.fields`),\n * but consumers should derive instance/encoded types via `Type.InstanceType`.\n *\n * **Not a `Schema.Schema`.** `Foo.ast` / `Schema.Schema.Type<typeof Foo>` /\n * `Schema.extend(Foo)` no longer typecheck — extract the Effect Schema via\n * `Type.getSchema(Foo)` first, or derive instance types via\n * `Type.InstanceType<typeof Foo>`.\n *\n * @example\n * ```ts\n * const Person = Schema.Struct({\n * name: Schema.String,\n * }).pipe(Type.makeObject(DXN.make('com.example.type.person', '0.1.0')));\n *\n * type Person = Type.InstanceType<typeof Person>;\n * ```\n */\nexport interface Obj<T, Fields extends Schema.Struct.Fields = Schema.Struct.Fields> extends BaseTypeEntity<\n T & EntityModule.OfKind<typeof EntityModule.Kind.Object>\n> {\n /** Schema-kind brand (object). */\n readonly [internal.SchemaKindId]: internal.EntityKind.Object;\n\n /** Source Effect Schema — used internally by `Type.getSchema(self)`. */\n readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;\n\n /**\n * The fields defined in the original struct schema.\n * Allows accessing field definitions for introspection.\n */\n readonly fields: Fields;\n}\n\n/**\n * Type that represents any ECHO object type — a `Type.Type` entity branded\n * with the object entity kind, i.e. what `Type.makeObject(dxn)` produces.\n */\nexport type AnyObj = Obj<unknown>;\n\n/**\n * Factory function to create an ECHO object type.\n *\n * Returns a `Type.Type` entity — a live, in-memory `TypeSchema` instance,\n * NOT a `Schema.Schema`. Use `Type.InstanceType<typeof Foo>` for the instance\n * type and `Type.getSchema(Foo)` to obtain the underlying Effect Schema.\n *\n * The entity's id defaults to `EntityId.deterministic(typename, version)` so\n * constructing a type never reaches `crypto.getRandomValues()` — required for\n * Cloudflare workerd, which forbids RNG calls in global (module-evaluation)\n * scope. Pass `{ id }` to override (e.g. with `EntityId.random()` from a\n * request handler).\n *\n * @example\n * ```ts\n * const Person = Schema.Struct({\n * name: Schema.String,\n * }).pipe(Type.makeObject(DXN.make('com.example.type.person', '0.1.0')));\n * ```\n */\nexport const makeObject: {\n (\n dxn: DXN.DXN,\n options?: { id?: EntityId },\n ): <Self extends Schema.Schema.Any>(self: Self) => Obj<Schema.Schema.Type<Self>>;\n} = internal.EchoObjectSchema as any;\n\n//\n// Type — the ECHO entity that holds a schema and metadata.\n// Persisted via `db.addType()`; subscribed to via `Filter.type(Type.Type)`.\n//\n\n/**\n * ECHO meta-schema entity — stores `{ name?, typename, version, jsonSchema }`.\n * Type-kind sibling of `Type.makeObject(...)` / `Type.makeRelation(...)` outputs.\n * Stored types live under this entity; filter via `Filter.type(Type.Type)`.\n */\nexport const Type: Type<typeInternal.TypeSchema> = typeInternal.TypeSchema as any;\n\n/**\n * Default version stamped on draft (unnamed) types created via\n * {@link makeObjectFromJsonSchema} / {@link makeRelationFromJsonSchema} when\n * the caller does not supply one. Pure dynamic drafts surface as `'0.0.0'`\n * until they are persisted, at which point automerge-heads suffix the version.\n */\nconst DRAFT_VERSION = '0.0.0';\n\n/**\n * Common props shared by the type-kind factories. Typename and version are\n * optional — drafts omit typename and default version to {@link DRAFT_VERSION}.\n */\ntype MakeTypeProps = {\n jsonSchema: internal.JsonSchemaType;\n typename?: string;\n version?: string;\n name?: string;\n id?: EntityId;\n};\n\n/**\n * Construct a new object-kind type entity from raw metadata — for cases where\n * an Effect Schema isn't available (e.g. JSON-Schema arriving over the network\n * or from a UI editor). Parallel to {@link makeObject} but takes pre-built\n * `jsonSchema` instead of piping through an Effect schema.\n *\n * The returned entity is in-memory; persist it with `db.addType(entity)`.\n */\nexport const makeObjectFromJsonSchema = (props: MakeTypeProps): Type<typeInternal.TypeSchema> => {\n const { typename, version, ...data } = props;\n // `typename` / `version` are routed through `EntityMeta` (`key` / `version`)\n // — the canonical registry-provenance pair — not data fields. Drafts default\n // to `'0.0.0'`; the version is omitted from meta entirely when the caller\n // doesn't supply one so the proxy projection can apply its own default.\n return internal.makeObject(\n internal.getStaticTypeSchema(typeInternal.TypeSchema) as any,\n data as any,\n {\n keys: [],\n key: typename,\n version: version ?? DRAFT_VERSION,\n },\n typeInternal.TypeSchema,\n ) as unknown as Type<typeInternal.TypeSchema>;\n};\n\n/**\n * Construct a new relation-kind type entity from raw metadata. Parallel to\n * {@link makeRelation} but takes pre-built `jsonSchema` instead of piping\n * through an Effect schema. `source` / `target` accept either a static\n * `Type.Obj` entity or the well-known `Obj.Unknown` schema.\n *\n * The returned entity is in-memory; persist it with `db.addType(entity)`.\n */\nexport const makeRelationFromJsonSchema = (\n props: MakeTypeProps & {\n source: AnyObj | internal.UnknownTypeSchema<any, typeof EntityModule.Kind.Object>;\n target: AnyObj | internal.UnknownTypeSchema<any, typeof EntityModule.Kind.Object>;\n },\n): Type<typeInternal.TypeSchema> => {\n const { source, target, jsonSchema, typename, version, ...rest } = props;\n // Embed source/target DXNs + relation entity-kind into the jsonSchema so the\n // entity round-trips correctly through `toEffectSchema` / queries / refs.\n const sourceURI = internal.getTypeURIFromSpecifier(source);\n const targetURI = internal.getTypeURIFromSpecifier(target);\n const enrichedJsonSchema: internal.JsonSchemaType = {\n ...jsonSchema,\n entityKind: internal.EntityKind.Relation,\n relationSource: { $ref: sourceURI },\n relationTarget: { $ref: targetURI },\n };\n // `typename` / `version` route through `EntityMeta` (see\n // {@link makeObjectFromJsonSchema}); drafts default version to `'0.0.0'`.\n return internal.makeObject(\n internal.getStaticTypeSchema(typeInternal.TypeSchema) as any,\n { ...rest, jsonSchema: enrichedJsonSchema } as any,\n {\n keys: [],\n key: typename,\n version: version ?? DRAFT_VERSION,\n },\n typeInternal.TypeSchema,\n ) as unknown as Type<typeInternal.TypeSchema>;\n};\n\n/**\n * TypeScript type for an ECHO relation type — a `Type.Type<A>` entity.\n *\n * `T` is the instance-property type produced by `Relation.make(...)` (excluding\n * source/target endpoints). `Source` and `Target` are the endpoint types.\n *\n * **Not a `Schema.Schema`.** See {@link Obj}'s note.\n */\nexport interface Relation<\n T,\n Source,\n Target,\n Fields extends Schema.Struct.Fields = Schema.Struct.Fields,\n> extends BaseTypeEntity<\n RelationModule.Endpoints<Source, Target> & T & EntityModule.OfKind<typeof EntityModule.Kind.Relation>\n> {\n /** Schema-kind brand (relation). */\n readonly [internal.SchemaKindId]: internal.EntityKind.Relation;\n\n /** Source Effect Schema — used internally by `Type.getSchema(self)`. */\n readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;\n\n /**\n * The fields defined in the original struct schema.\n * Allows accessing field definitions for introspection.\n */\n readonly fields: Fields;\n}\n\n/**\n * Type that represents any ECHO relation type — a `Type.Type` entity branded\n * with the relation entity kind, i.e. what `Type.makeRelation(...)` produces.\n */\nexport type AnyRelation = Relation<unknown, unknown, unknown>;\n\n/**\n * Factory function to create an ECHO relation schema.\n * Adds relation metadata annotations to an Effect schema.\n *\n * @example\n * ```ts\n * const WorksFor = Schema.Struct({\n * role: Schema.String,\n * }).pipe(Type.makeRelation({\n * dxn: DXN.make('com.example.type.worksFor', '0.1.0'),\n * source: Person,\n * target: Company,\n * }));\n * ```\n */\nexport const makeRelation: {\n <SourceInstance, TargetInstance>(opts: {\n dxn: DXN.DXN;\n source: Obj<SourceInstance, any> | internal.UnknownTypeSchema<SourceInstance, typeof EntityModule.Kind.Object>;\n target: Obj<TargetInstance, any> | internal.UnknownTypeSchema<TargetInstance, typeof EntityModule.Kind.Object>;\n /**\n * Override the entity id. Defaults to `EntityId.deterministic(typename, version)`;\n * see `Type.makeObject` for the workerd motivation.\n */\n id?: EntityId;\n }): <Self extends Schema.Schema.Any>(\n self: Self,\n ) => Relation<\n Schema.Schema.Type<Self>,\n SourceInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>,\n TargetInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>\n >;\n} = internal.EchoRelationSchema as any;\n\n/**\n * Type that represents any ECHO type-kind entity — a `Type.Type` meta-schema\n * value (static `Type.Type` or a persisted draft from `db.addType(...)`).\n * Mirrors {@link AnyObj} / {@link AnyRelation} for the third sibling kind.\n */\nexport type AnyType = Type<unknown>;\n\n/**\n * Any ECHO type-entity — one of the three sibling kinds: object-kind, relation-kind,\n * or type-kind (the meta-schema). APIs that want \"any ECHO type\" use this union;\n * the underlying Effect Schema is retrieved via `Type.getSchema`.\n */\nexport type AnyEntity = AnyObj | AnyRelation | AnyType;\n\n/**\n * Type guard: narrows a `Type.AnyEntity` to an object-kind entity. Checks\n * ENTITIES, not instances — use `Obj.isObject` for instances. Raw\n * `Schema.Schema` values (including the branded `Obj.Unknown` companion)\n * are intentionally not accepted; inspect their `TypeAnnotation` directly.\n */\nexport const isObject = (entity: AnyEntity): entity is AnyObj => {\n return internal.getSchemaKind(entity) === internal.EntityKind.Object;\n};\n\n/**\n * Type guard: narrows a `Type.AnyEntity` to a relation-kind entity. Checks\n * ENTITIES, not instances — use `Relation.isRelation` for instances.\n */\nexport const isRelation = (entity: AnyEntity): entity is AnyRelation => {\n return internal.getSchemaKind(entity) === internal.EntityKind.Relation;\n};\n\n/**\n * Type guard: narrows a `Type.AnyEntity` to the type-kind meta-schema\n * (e.g. `Type.Type`). Mirrors {@link isObject} / {@link isRelation}.\n */\nexport const isTypeKind = (entity: AnyEntity): entity is Type => {\n return internal.getSchemaKind(entity) === internal.EntityKind.Type;\n};\n\n/**\n * Narrow a `Type.AnyEntity` (e.g. one returned from `schemaRegistry.query(...)`)\n * to `AnyObj`, throwing if it describes a relation or the type-kind\n * meta-schema. Use at call sites that need to pass the value to `Obj.make`,\n * `Filter.type`, or other object-only APIs.\n */\nexport const assertObject = (entity: AnyEntity): AnyObj => {\n assertArgument(isObject(entity), 'entity', 'Expected an object-kind Type entity.');\n return entity;\n};\n\n/** Narrow a `Type.AnyEntity` to `AnyRelation`, throwing otherwise. */\nexport const expectRelation = (entity: AnyEntity): AnyRelation => {\n assertArgument(isRelation(entity), 'entity', 'Expected a relation-kind Type entity.');\n return entity;\n};\n\n/** Narrow a `Type.AnyEntity` to the `Type.Type` meta-schema, throwing otherwise. */\nexport const expectTypeKind = (entity: AnyEntity): Type => {\n assertArgument(isTypeKind(entity), 'entity', 'Expected a type-kind Type entity.');\n return entity;\n};\n\n/**\n * Type that represents any Ref schema (with unknown target type).\n * This is a schema type, not an instance type.\n */\nexport type AnyRef = Schema.Schema<internal.Ref<any>, EncodedReference>;\n\n//\n// Schema utility functions\n//\n\n/**\n * Returns the URI identifying a type entity. Always defined.\n *\n * - Static `Type.Obj` / `Type.Relation` → typename DXN (e.g. `dxn:com.example.type.person:0.1.0`).\n * - Persisted `Type.Type` instance (has `id`) → local `EID` (`echo:/<objectId>`).\n * - In-memory `Type.Type` draft (has `id`, no typename) → local `EID`.\n *\n * Only accepts `Type.AnyEntity` entities. Raw `Schema.Schema` values and the\n * branded `Obj.Unknown` / `Relation.Unknown` schemas are intentionally not\n * supported — use `internal.getSchemaURI` or the schema's typename annotation\n * directly when working at the schema level.\n */\nexport const getURI = (input: AnyEntity): URI.URI => {\n // For Type entities, route through `getTypeURIFromSpecifier` (id → EID,\n // typename/version → DXN). For Obj/Relation entities, unwrap to the source\n // Effect Schema first and read its annotations.\n if (isType(input)) {\n return internal.getTypeURIFromSpecifier(input);\n }\n return internal.getSchemaURI(getSchema(input)) ?? raise(new TypeError('Type entity has no URI'));\n};\n\n/**\n * @returns The typename. Example: `com.example.type.person`.\n *\n * Persisted `Type.Type` entities carry typename in `EntityMeta.key` (the\n * canonical registry-provenance field); unnamed drafts fall back to the\n * entity's object id so the helper always returns a string. Any `dxn:` or\n * `echo:/` prefix is stripped — typename is a bare identifier, not a URI.\n */\n// TODO(wittjosiah): For in-database types this should return the object id once the registry\n// has more robust options for shadowing types (so callers can disambiguate db-stored copies).\nexport const getTypename = (input: AnyEntity): string => {\n // Both in-memory and in-database entities carry typename in `EntityMeta.key`\n // — the canonical registry-provenance field. In-memory entities attach meta\n // eagerly (see `makeEchoTypeSchema`), so a single meta-backed read covers\n // both forms.\n const meta = internal.getMetaChecked(input);\n let typename: string | undefined = meta.key as string | undefined;\n // `meta.key` is a denormalized copy of the typename. The authoritative source\n // for a type entity is its `jsonSchema.typename` (`getSchema` rebuilds the\n // Effect Schema from `jsonSchema`). A type loaded from a snapshot can arrive\n // with `meta.key` absent (the meta round-trip dropped the denormalized copy)\n // while `jsonSchema.typename` is always present — consult it before the\n // last-resort id fallback so callers never receive a bare object id where a\n // typename is expected (e.g. `Filter.typename`, which rejects non-typenames).\n if (typename == null) {\n typename = input.jsonSchema?.typename;\n }\n // Unnamed drafts (no meta.key, no jsonSchema typename) fall back to the id.\n typename ??= input.id as string;\n // Typename is a bare identifier — strip URI prefixes if a caller seeded\n // meta.key with one accidentally (or if a static entity carries a DXN-\n // style typename).\n typename = stripTypenamePrefix(typename);\n invariant(typeof typename === 'string' && typename.length > 0, 'Invalid typename');\n return typename;\n};\n\n/**\n * Gets the version.\n * @example 0.1.0\n * @example 0.1.0-<heads> (in-database, versioned by automerge heads)\n *\n * The registry-provenance semver lives in `EntityMeta.version`; unversioned\n * drafts default to {@link DRAFT_VERSION} (`'0.0.0'`). In-database entities are\n * additionally versioned by their automerge heads, which are exposed as the\n * semver pre-release tag (`<semver>-<heads>`). In-memory declarations have no\n * heads and surface the bare semver. Read the registry semver alone via\n * `Type.getMeta(input).version`.\n */\nexport const getVersion = (input: AnyEntity): string => {\n const meta = internal.getMetaChecked(input);\n // As with `getTypename`: `meta.version` is a denormalized copy; the\n // authoritative semver lives in `jsonSchema.version`. Prefer meta, fall back\n // to jsonSchema (always present on persisted types, survives serialization),\n // then to `DRAFT_VERSION` for unversioned drafts.\n const semver = (meta.version as string | undefined) ?? input.jsonSchema?.version ?? DRAFT_VERSION;\n invariant(typeof semver === 'string' && semver.match(/^\\d+\\.\\d+\\.\\d+$/), 'Invalid version');\n // In-database entities are versioned by their automerge heads; expose them as\n // the semver pre-release tag. In-memory drafts carry no heads → bare semver.\n const heads = internal.version(input).automergeHeads;\n if (heads != null && heads.length > 0) {\n return `${semver}-${[...heads].sort().join('.')}`;\n }\n return semver;\n};\n\n/**\n * Strip URI prefixes (`dxn:`, `echo:/`, `echo://`) from a typename string.\n * Typename is a bare identifier — callers reading from meta or from a\n * caller-supplied seed value shouldn't propagate URI prefixes downstream.\n */\nconst stripTypenamePrefix = (value: string): string => {\n if (value.startsWith('dxn:')) {\n return value.slice('dxn:'.length);\n }\n if (value.startsWith('echo://')) {\n return value.slice('echo://'.length);\n }\n if (value.startsWith('echo:/')) {\n return value.slice('echo:/'.length);\n }\n return value;\n};\n\n/**\n * Type predicate: true iff the value is any type-kind ECHO entity — a static\n * `Type.Obj` / `Type.Relation` produced by `Type.makeObject` / `Type.makeRelation`, a\n * static meta `Type.Type`, or a persisted `Type.Type` returned by the database.\n *\n * All three branches stamp `[KindId] = Type`, so this is a single brand check.\n * Use {@link isObject} / {@link isRelation} / {@link isTypeKind}\n * when you need to discriminate further; use {@link getDatabase} when you mean\n * \"is this a db-attached type\" (vs. an in-memory declaration).\n */\nexport const isType = (value: unknown): value is AnyEntity =>\n internal.getEntityKindBrand(value) === internal.EntityKind.Type;\n\n/**\n * Get the database the type entity belongs to, or `undefined` if it is an\n * in-memory declaration (`Type.makeObject` / `Type.makeRelation` result) not\n * yet attached to a database. Mirrors `Obj.getDatabase` / `Relation.getDatabase`.\n *\n * Database attachment is the canonical discriminator between in-memory and\n * in-database type entities — both are live reactive `TypeSchema` instances and\n * are otherwise indistinguishable.\n */\nexport const getDatabase = (input: AnyEntity): Database.Database | undefined => internal.getDatabase(input);\n\n/**\n * Mutable meta type returned by `Type.getMeta` inside a `Type.update` callback.\n * Mirrors `Obj.Meta` / `Relation.Meta` — `Type.Type` is an Entity like its\n * siblings, so its meta is the same `EntityMeta` record:\n * `{ keys, tags?, key?, version? }`.\n *\n * `key` / `version` here are the canonical registry-provenance pair\n * (typename + semver) on persisted Type.Type entities; they are absent on\n * unnamed drafts. Use {@link getTypename} / {@link getVersion} when you want\n * a non-`undefined` value with id / {@link DRAFT_VERSION} fallbacks.\n */\nexport type Meta = internal.Meta;\n\n/**\n * Deeply read-only version of {@link Meta}.\n * Prevents mutation at all nesting levels (e.g., `meta.keys.push()` is a TS error).\n */\nexport type ReadonlyMeta = internal.ReadonlyMeta;\n\n/**\n * Returns the entity's `EntityMeta`. Same semantics as `Obj.getMeta` /\n * `Relation.getMeta` — `Type.Type` is an Entity and carries the canonical\n * `EntityMeta` directly. Returns mutable meta when passed a mutable type\n * (inside a `Type.update` callback), read-only meta otherwise.\n *\n * For persisted Type entities, `meta.key` holds the typename and\n * `meta.version` holds the semver. Use {@link getTypename} / {@link getVersion}\n * if you want the helpers' id / {@link DRAFT_VERSION} fallbacks for drafts.\n *\n * Both persisted and in-memory type entities (`Type.makeObject` /\n * `Type.makeRelation` results) carry their `EntityMeta` via `[MetaId]`, so the\n * lookup is uniform.\n */\nexport function getMeta(entity: internal.Mutable<AnyEntity>): Meta;\nexport function getMeta(entity: Mutable): Meta;\nexport function getMeta(entity: AnyEntity): ReadonlyMeta;\nexport function getMeta(entity: AnyEntity | internal.Mutable<AnyEntity> | Mutable): ReadonlyMeta | Meta {\n // The `Mutable` overload accepts the narrowed view passed to `Type.update`\n // callbacks; at runtime that draft IS the underlying persisted Type entity,\n // so the same `MetaId` lookup works.\n assertArgument(isType(entity), 'entity', 'Expected a Type entity.');\n // Both persisted and in-memory type entities carry runtime `EntityMeta` via\n // `[MetaId]`, so the lookup is uniform.\n return internal.getMetaChecked(entity);\n}\n\n/**\n * String key used to phantom-carry the instance type produced by a `Type.Type`.\n * Used by `Type.InstanceType<typeof Foo>` to recover the schema instance type\n * since `Type.makeObject(dxn)` does not return a `Schema.Schema`.\n *\n * Re-exported from the internal types layer so both `Type.ts` and internal\n * helpers (`makeObject`, `createObject`) reference the same phantom key.\n */\nexport const InstancePhantomId = internal.InstancePhantomId;\nexport type InstancePhantomId = internal.InstancePhantomId;\n\n/**\n * Sibling of {@link Obj} / {@link Relation} for the third ECHO entity kind:\n * **type-kind** entities (meta-schemas). The singleton {@link Type} const is\n * the canonical example — it describes stored type definitions themselves.\n *\n * Not a `Schema.Schema`. Use `Type.getSchema(value)` to obtain the underlying\n * Effect Schema and `Type.update(value, draft => ...)` to mutate.\n *\n * `A` is the instance-type phantom — what `Obj.make(value, ...)` would produce.\n * Merged with the `Type` const value via TypeScript declaration merging.\n */\nexport interface Type<A = unknown> extends BaseTypeEntity<A & EntityModule.OfKind<typeof EntityModule.Kind.Type>> {\n /** Schema-kind brand (type — the meta-schema kind). */\n readonly [internal.SchemaKindId]: internal.EntityKind.Type;\n\n /** Source Effect Schema — used internally by `Type.getSchema(self)`. */\n readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;\n}\n\n/**\n * Instance type produced by a Type entity.\n *\n * Accepts ONLY {@link AnyEntity} inputs — `Type.Obj`, `Type.Relation`, or\n * `Type.Type`. Raw Effect `Schema.Schema` values are rejected: for those, use\n * `Schema.Schema.Type<typeof Foo>` directly. This separation keeps the type\n * system honest about which values represent ECHO entities versus plain\n * Effect schemas.\n *\n * Dispatches on the entity kind:\n * - `Relation<Props, S, T>` → `Endpoints<S,T> & Props & OfKind<Relation>`\n * - `Obj<A>` → `A & OfKind<Object>`\n * - `Type<A>` → `A & OfKind<Type>`\n */\nexport type InstanceType<T extends AnyEntity> =\n T extends Relation<infer Props, infer Source, infer Target, any>\n ? RelationModule.Endpoints<Source, Target> & Props & EntityModule.OfKind<typeof EntityModule.Kind.Relation>\n : T extends Obj<infer A, any>\n ? A & EntityModule.OfKind<typeof EntityModule.Kind.Object>\n : T extends Type<infer A>\n ? A & EntityModule.OfKind<typeof EntityModule.Kind.Type>\n : never;\n\n/**\n * Returns the Effect Schema for a type entity.\n *\n * - For static `Type.Obj` / `Type.Relation` entities the source Effect Schema is\n * read from a hidden slot — these overloads preserve the instance type.\n * - For `Type.Type` entities (the meta-schema kind) the schema is rebuilt from\n * `type.jsonSchema`; the instance type isn't statically knowable so the wide\n * `AnyEntity` overload widens to `Schema.Schema.AnyNoContext`.\n *\n * Always call this when you need to interact with the Effect Schema API\n * (e.g. before passing to Effect.Schema functions). For ECHO-side APIs\n * (`Obj.make`, `Filter.type`, `Ref`) pass the type entity directly.\n *\n * Only accepts `Type.AnyEntity` — raw `Schema.Schema` values can be used\n * directly without unwrapping.\n */\nexport function getSchema<T extends AnyObj>(type: T): Schema.Schema<InstanceType<T>>;\nexport function getSchema<T extends AnyRelation>(type: T): Schema.Schema<InstanceType<T>>;\nexport function getSchema(type: AnyEntity): Schema.Schema.AnyNoContext;\nexport function getSchema(type: AnyEntity): Schema.Schema.AnyNoContext {\n // Static `Type.Type` entities carry the source Effect Schema on a hidden\n // slot so we can return it without round-tripping through JsonSchema.\n const staticSchema = internal.getStaticTypeSchema(type);\n if (staticSchema != null) {\n return staticSchema;\n }\n assertArgument(isType(type), 'type', 'Expected a Type entity.');\n // Persisted `Type.Type` entity — build the Effect Schema from its stored\n // jsonSchema and re-attach the TypeIdentifierAnnotation so the rebuilt\n // schema's URI (via getSchemaURI) matches the entity's local EID.\n const rebuilt = internal.toEffectSchema(type.jsonSchema);\n if (typeof type.id === 'string') {\n return rebuilt.annotations({\n [internal.TypeIdentifierAnnotationId]: EID.make({ entityId: type.id }),\n });\n }\n return rebuilt;\n}\n\n/**\n * Mutable view of a `Type.Type` — the shape passed to the `Type.update` callback.\n * Outside `Type.update`, `Type.Type` fields are read-only (both at the type level\n * and at runtime — direct assignment throws). Use this to constrain mutation to\n * the change context, analogous to `Obj.update(obj, (draft) => ...)`.\n *\n * NOTE: `typename` and `version` are intentionally absent — they live in\n * `EntityMeta` (`key` / `version` — the canonical registry-provenance pair).\n * Read them via {@link getTypename} / {@link getVersion} / {@link getMeta};\n * `typename` is treated as immutable on persisted entities.\n *\n * Unlike `Obj.update` — whose mutable view is inferred as `Mutable<A>` over the\n * whole instance type because every data field is editable — a `Type.Type`\n * exposes only `name` and `jsonSchema` for mutation. The rest of its shape\n * (`id`, the `[KindId]` / `[SchemaKindId]` brands, and `typename` / `version`\n * in meta) is immutable, so this view is declared explicitly rather than\n * derived from `InstanceType<Type.Type>`.\n */\nexport interface Mutable {\n name?: string;\n // Deep-mutable within the change context — `Type.update`'s purpose is to allow\n // mutation, so the draft exposes `jsonSchema` as writable (the readonly\n // `JsonSchemaType` would force callers to cast).\n jsonSchema: Types.DeepMutable<internal.JsonSchemaType>;\n}\n\n/**\n * Perform mutations on a `Type.Type` within a change context.\n *\n * The callback receives a {@link Mutable} view of the type — direct mutation of\n * a `Type.Type` outside `Type.update` throws at runtime, mirroring `Obj.update`.\n * Delegates to the same automerge-transaction primitive `Obj.update(obj, cb)` uses.\n */\nexport const update = (type: AnyEntity, callback: (mutable: Mutable) => void): void => {\n // `Type.Type` is an ECHO object; the change machinery is the same as `Obj.update`.\n internal.change(type, callback as internal.ChangeCallback<AnyEntity>);\n};\n\n//\n// Field-level helpers for mutating persisted types.\n// These are thin wrappers over `Type.update` plus the JsonSchema manipulation\n// utilities. Callers pass a persisted `Type.Type` (e.g. one returned by\n// `db.addType(schemaEntity)`) and the helper drives the change context.\n//\n\n/**\n * Add fields to a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const addFields = (type: AnyEntity, fields: Schema.Struct.Fields): void => {\n const extended = typeInternal.addFieldsToSchema(getSchema(type), fields);\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(extended);\n });\n};\n\n/**\n * Replace existing fields on a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const updateFields = (type: AnyEntity, fields: Schema.Struct.Fields): void => {\n const updated = typeInternal.updateFieldsInSchema(getSchema(type), fields);\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(updated);\n });\n};\n\n/**\n * Rename a field on a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const updateFieldPropertyName = (\n type: Type,\n { before, after }: { before: PropertyKey; after: PropertyKey },\n): void => {\n const renamed = typeInternal.updateFieldNameInSchema(getSchema(type), { before, after });\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(renamed);\n });\n};\n\n/**\n * Remove fields from a persisted type's schema.\n * @throws if the type is not persisted.\n */\nexport const removeFields = (type: AnyEntity, fieldNames: string[]): void => {\n const removed = typeInternal.removeFieldsFromSchema(getSchema(type), fieldNames);\n update(type, (draft) => {\n draft.jsonSchema = internal.toJsonSchema(removed);\n });\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;2BAAAA;EAAA;;;;;qBAAAC;EAAA;;;;;;;;;oBAAAC;EAAA;;;;;;;;AASA,SAASC,aAAa;AAEtB,SAASC,gBAAgBC,iBAAiB;AAC1C,SAAcC,WAAoC;AA4FlD,IAAA,eAAA;AA4BA,IAAAC,cAAA;;;AAyCE,IAAA,2BAAA,CAAA,UAAA;AACA,QAAA,EAAA,UAAA,SAAAC,UAAA,GAAA,KAAA,IAAA;SAQSC,WAAAA,oBAAAA,UAAAA,GAAAA,MAAAA;IACLD,MAAAA,CAAAA;IAEFE,KAAAA;IAEF,SAAAF,YAAA;EAEF,GAAA,UAAA;;AAeE,IAAA,6BAAA,CAAA,UAAA;AACA,QAAA,EAAA,QAAA,QAAA,YAAA,UAAA,SAAAA,UAAA,GAAA,KAAA,IAAA;AAGA,QAAMG,YAA8C,wBAAA,MAAA;QAClD,YAAa,wBAAA,MAAA;QACbC,qBAAqBC;IACrBC,GAAAA;gBAAwBC,WAAAA;IAAU,gBAAA;MAClCC,MAAAA;;IAAkC,gBAAA;MACpC,MAAA;IACA;EACA;SAGyBL,WAAAA,oBAAAA,UAAAA,GAAAA;IACvB,GAAA;IACEM,YAAQ;;IAERT,MAAAA,CAAAA;IAEFE,KAAAA;IAEF,SAAAF,YAAA;EAqCF,GAAA,UAAA;;;AAwDE,IAAA,WAAA,CAAA,WAAA;AAEF,SAAA,cAAA,MAAA,MAAA,WAAA;;AAME,IAAA,aAAA,CAAA,WAAA;AAEF,SAAA,cAAA,MAAA,MAAA,WAAA;;AAME,IAAA,aAAA,C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CAAAA,MAAAA,EAAAA,QAAAA,MAAAA,MAAAA;QAAQC,UAAAA,wBAAAA,UAAAA,IAAAA,GAAAA;IAAM;IACtFC;;AAEA,SAAA,MAAA,CAAA,UAAA;AACA,UAAA,aAAA,aAAA,OAAA;EAEF,CAAA;;AAMSN,IAAM,eAACC,CAAAA,MAAAA,eAAAA;QACZA,UAAmBN,uBAAsBY,UAAAA,IAAAA,GAAAA,UAAAA;AAC3C,SAAA,MAAA,CAAA,UAAA;AACA,UAAA,aAAA,aAAA,OAAA;;;",
|
|
6
|
+
"names": ["InstancePhantomId", "getDatabase", "makeObject", "raise", "assertArgument", "invariant", "EID", "makeObject", "version", "typename", "typeInternal", "enrichedJsonSchema", "entityKind", "EntityKind", "relationSource", "sourceURI", "relationTarget", "keys", "entity", "getSchemaURI", "input", "heads", "join", "semver", "value", "startsWith", "getDatabase", "InstancePhantomId", "staticSchema", "assertArgument", "annotations", "internal", "TypeIdentifierAnnotationId", "entityId", "change", "callback", "type", "draft", "extended", "updated", "before", "after", "update", "removed"]
|
|
7
|
+
}
|