@dxos/echo 0.8.4-staging.ac66bdf99f → 0.9.0
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/LICENSE +102 -5
- package/README.md +7 -7
- package/dist/lib/neutral/Annotation.mjs +37 -6
- package/dist/lib/neutral/Database.mjs +6 -17
- package/dist/lib/neutral/Entity.mjs +31 -20
- package/dist/lib/neutral/Err.mjs +3 -3
- package/dist/lib/neutral/Feed.mjs +23 -19
- package/dist/lib/neutral/Filter.mjs +13 -15
- 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 +29 -20
- package/dist/lib/neutral/Order.mjs +7 -3
- package/dist/lib/neutral/Query.mjs +17 -17
- package/dist/lib/neutral/QueryResult.mjs +1 -1
- package/dist/lib/neutral/Ref.mjs +10 -9
- package/dist/lib/neutral/Registry.mjs +14 -0
- package/dist/lib/neutral/Relation.mjs +28 -25
- package/dist/lib/neutral/Scope.mjs +12 -0
- package/dist/lib/neutral/Tag.mjs +17 -14
- package/dist/lib/neutral/Type.mjs +54 -26
- package/dist/lib/neutral/{chunk-OMUPQMLR.mjs → chunk-35INCYOE.mjs} +1 -1
- package/dist/lib/neutral/chunk-35INCYOE.mjs.map +7 -0
- package/dist/lib/neutral/chunk-3PBP4V4O.mjs +101 -0
- package/dist/lib/neutral/chunk-3PBP4V4O.mjs.map +7 -0
- package/dist/lib/neutral/chunk-4ZUHOTCG.mjs +184 -0
- package/dist/lib/neutral/chunk-4ZUHOTCG.mjs.map +7 -0
- package/dist/lib/neutral/chunk-5SMDBFVB.mjs +108 -0
- package/dist/lib/neutral/chunk-5SMDBFVB.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-OS35K56T.mjs → chunk-5SUJPHAE.mjs} +3 -3
- package/dist/lib/neutral/{chunk-OS35K56T.mjs.map → chunk-5SUJPHAE.mjs.map} +2 -2
- package/dist/lib/neutral/{chunk-GZQTCRJB.mjs → chunk-6M2Z6WBH.mjs} +22 -2
- package/dist/lib/neutral/chunk-6M2Z6WBH.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-V36VO5SS.mjs → chunk-6YDI3J37.mjs} +32 -40
- package/dist/lib/neutral/chunk-6YDI3J37.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-MOR5ERFM.mjs → chunk-7FPIAJIV.mjs} +701 -1256
- package/dist/lib/neutral/chunk-7FPIAJIV.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-ANHVGJI4.mjs → chunk-7LOUAPYZ.mjs} +9 -5
- package/dist/lib/neutral/chunk-7LOUAPYZ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-JUXPFOEI.mjs → chunk-7PI7C4EF.mjs} +48 -88
- package/dist/lib/neutral/chunk-7PI7C4EF.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-UBEZSGXY.mjs → chunk-BBFJWWAV.mjs} +6 -6
- package/dist/lib/neutral/chunk-BBFJWWAV.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-UI6MWK5W.mjs → chunk-EVK6XBXO.mjs} +16 -2
- package/dist/lib/neutral/chunk-EVK6XBXO.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-7RO7CPBZ.mjs → chunk-IGK6FN65.mjs} +2 -2
- package/dist/lib/neutral/{chunk-HBUZJNZO.mjs → chunk-LWXVKPPW.mjs} +94 -99
- package/dist/lib/neutral/chunk-LWXVKPPW.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-BVOFLCVF.mjs → chunk-MZ7K3MLL.mjs} +9 -6
- package/dist/lib/neutral/chunk-MZ7K3MLL.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-TBKX6JQO.mjs → chunk-O6BH7EPN.mjs} +30 -3
- package/dist/lib/neutral/chunk-O6BH7EPN.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-EAMSSLZC.mjs → chunk-QQIYS74I.mjs} +83 -46
- package/dist/lib/neutral/chunk-QQIYS74I.mjs.map +7 -0
- package/dist/lib/neutral/chunk-R5W6DXR4.mjs +678 -0
- package/dist/lib/neutral/chunk-R5W6DXR4.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-WAK4DMFV.mjs → chunk-RIVWNMSF.mjs} +12 -7
- package/dist/lib/neutral/chunk-RIVWNMSF.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-T6W2LEZU.mjs → chunk-SBVFRTST.mjs} +73 -38
- package/dist/lib/neutral/chunk-SBVFRTST.mjs.map +7 -0
- package/dist/lib/neutral/chunk-T6E37YIP.mjs +251 -0
- package/dist/lib/neutral/chunk-T6E37YIP.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-DQYLD2RB.mjs → chunk-TFEWTY5A.mjs} +155 -129
- package/dist/lib/neutral/chunk-TFEWTY5A.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-B4BASU6W.mjs → chunk-TYGKCRMK.mjs} +85 -76
- package/dist/lib/neutral/chunk-TYGKCRMK.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-4OIBYSXE.mjs → chunk-UUP46KUQ.mjs} +78 -32
- package/dist/lib/neutral/chunk-UUP46KUQ.mjs.map +7 -0
- package/dist/lib/neutral/chunk-WISOH2XH.mjs +36 -0
- package/dist/lib/neutral/chunk-WISOH2XH.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-G3IQMKF7.mjs → chunk-WTQJHC75.mjs} +111 -112
- package/dist/lib/neutral/chunk-WTQJHC75.mjs.map +7 -0
- package/dist/lib/neutral/chunk-WU3GIANS.mjs +31 -0
- package/dist/lib/neutral/chunk-WU3GIANS.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-TU3GW67D.mjs → chunk-ZGNNFYHS.mjs} +40 -40
- package/dist/lib/neutral/chunk-ZGNNFYHS.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +47 -41
- package/dist/lib/neutral/internal/index.mjs +137 -72
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/testing/index.mjs +261 -178
- package/dist/lib/neutral/testing/index.mjs.map +4 -4
- 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 +56 -49
- 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 +101 -28
- package/dist/types/src/Entity.d.ts.map +1 -1
- package/dist/types/src/Err.d.ts +27 -27
- package/dist/types/src/Err.d.ts.map +1 -1
- package/dist/types/src/Feed.d.ts +66 -19
- package/dist/types/src/Feed.d.ts.map +1 -1
- package/dist/types/src/Filter.d.ts +38 -12
- package/dist/types/src/Filter.d.ts.map +1 -1
- package/dist/types/src/Format.d.ts +0 -2
- package/dist/types/src/Format.d.ts.map +1 -1
- package/dist/types/src/Hypergraph.d.ts +14 -9
- package/dist/types/src/Hypergraph.d.ts.map +1 -1
- package/dist/types/src/Json.d.ts +33 -0
- package/dist/types/src/Json.d.ts.map +1 -0
- package/dist/types/src/Json.test.d.ts +2 -0
- package/dist/types/src/Json.test.d.ts.map +1 -0
- package/dist/types/src/JsonSchema.d.ts +2 -2
- 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 +26 -11
- package/dist/types/src/Migration.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +104 -61
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Order.d.ts +10 -0
- package/dist/types/src/Order.d.ts.map +1 -1
- package/dist/types/src/Query.d.ts +34 -12
- package/dist/types/src/Query.d.ts.map +1 -1
- package/dist/types/src/QueryResult.d.ts +21 -0
- package/dist/types/src/QueryResult.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +15 -7
- 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 +73 -41
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Scope.d.ts +35 -0
- package/dist/types/src/Scope.d.ts.map +1 -0
- package/dist/types/src/Tag.d.ts +21 -5
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +362 -95
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/View.d.ts +9 -12
- package/dist/types/src/View.d.ts.map +1 -1
- package/dist/types/src/exemplars.test.d.ts +2 -0
- package/dist/types/src/exemplars.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/annotations.d.ts +79 -38
- 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/sorting.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/util.d.ts +14 -5
- package/dist/types/src/internal/Annotation/util.d.ts.map +1 -1
- package/dist/types/src/internal/Entity/api.d.ts +17 -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 +21 -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 +24 -0
- package/dist/types/src/internal/Entity/type-uri.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/version.d.ts.map +1 -1
- 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/number.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/Format/types.d.ts.map +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts.map +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts +34 -34
- package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -1
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts +3 -2
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/atoms.d.ts +38 -0
- package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/clone.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/common.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/create-object.d.ts +12 -12
- package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/deleted.d.ts.map +1 -1
- package/dist/types/src/internal/Obj/index.d.ts +1 -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/set-value.d.ts +1 -1
- package/dist/types/src/internal/Obj/set-value.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/index.d.ts +2 -0
- package/dist/types/src/internal/Query/index.d.ts.map +1 -0
- package/dist/types/src/internal/{Query.d.ts → Query/pretty.d.ts} +1 -1
- package/dist/types/src/internal/Query/pretty.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/atoms.d.ts +10 -0
- package/dist/types/src/internal/Ref/atoms.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/ref-array.d.ts +2 -2
- package/dist/types/src/internal/Ref/ref.d.ts +50 -19
- package/dist/types/src/internal/Ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/Ref/utils.d.ts +8 -0
- package/dist/types/src/internal/Ref/utils.d.ts.map +1 -0
- package/dist/types/src/internal/Type/compose.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 +14 -11
- package/dist/types/src/internal/common/api/meta.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/change-context.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/errors.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/errors.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/event-batch.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/ownership.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/reactive-array.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/reactive.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/reactive.d.ts.map +1 -1
- package/dist/types/src/internal/common/proxy/reactive.test.d.ts +2 -0
- package/dist/types/src/internal/common/proxy/reactive.test.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/schema-validator.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/base.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/entity.d.ts +62 -5
- 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 +33 -12
- package/dist/types/src/internal/common/types/meta.d.ts.map +1 -1
- package/dist/types/src/internal/common/types/model-symbols.d.ts +15 -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/version.d.ts +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 +2 -2
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/registry.d.ts +9 -0
- package/dist/types/src/testing/registry.d.ts.map +1 -0
- package/dist/types/src/testing/test-data.d.ts +8 -8
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +83 -89
- 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 +26 -24
- package/src/Annotation.test.ts +439 -0
- package/src/Annotation.ts +158 -4
- package/src/Collection.ts +5 -9
- package/src/Database.ts +93 -100
- package/src/Dataset.ts +10 -2
- package/src/Entity.test.ts +116 -6
- package/src/Entity.ts +134 -32
- package/src/Err.ts +4 -4
- package/src/Feed.ts +92 -44
- package/src/Filter.ts +70 -40
- package/src/Format.ts +0 -4
- package/src/Hypergraph.ts +14 -9
- package/src/Json.test.ts +175 -0
- package/src/Json.ts +103 -0
- package/src/Key.ts +1 -1
- package/src/Migration.ts +39 -19
- package/src/Obj.test.ts +122 -20
- package/src/Obj.ts +168 -91
- package/src/Order.ts +22 -0
- package/src/Query.test.ts +183 -154
- package/src/Query.ts +172 -85
- package/src/QueryResult.ts +26 -0
- package/src/Ref.ts +22 -4
- package/src/Registry.ts +155 -0
- package/src/Relation.test.ts +10 -10
- package/src/Relation.ts +116 -69
- package/src/Scope.ts +50 -0
- package/src/Tag.md +88 -0
- package/src/Tag.ts +49 -6
- package/src/Type.test.ts +223 -18
- package/src/Type.ts +609 -131
- package/src/View.ts +14 -23
- package/src/exemplars.test.ts +21 -0
- package/src/index.ts +4 -4
- package/src/internal/Annotation/annotations.test.ts +31 -11
- package/src/internal/Annotation/annotations.ts +143 -111
- package/src/internal/Annotation/dictionary.ts +47 -0
- package/src/internal/Annotation/entity-dictionary.ts +74 -0
- package/src/internal/Annotation/index.ts +4 -2
- package/src/internal/Annotation/util.ts +17 -8
- package/src/internal/Entity/api.ts +54 -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 +38 -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 +92 -0
- package/src/internal/Entity/util.ts +9 -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-type.ts +4 -4
- package/src/internal/JsonSchema/json-schema.test.ts +71 -145
- package/src/internal/JsonSchema/json-schema.ts +49 -35
- package/src/internal/Obj/atoms.ts +244 -0
- 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 +68 -22
- package/src/internal/Obj/index.ts +1 -1
- package/src/internal/Obj/inspect.ts +5 -3
- package/src/internal/Obj/json-serializer.test.ts +101 -22
- package/src/internal/Obj/json-serializer.ts +89 -33
- package/src/internal/Obj/set-value.test.ts +22 -45
- package/src/internal/Obj/set-value.ts +12 -19
- package/src/internal/Obj/snapshot.ts +13 -4
- package/src/internal/Obj/typed-object.test.ts +9 -11
- package/src/internal/Obj/typed-object.ts +1 -1
- package/src/internal/Query/index.ts +5 -0
- package/src/internal/{Query.ts → Query/pretty.ts} +40 -12
- package/src/internal/Ref/atoms.ts +20 -0
- package/src/internal/Ref/ref-array.ts +3 -3
- package/src/internal/Ref/ref.test.ts +18 -27
- package/src/internal/Ref/ref.ts +137 -59
- package/src/internal/Ref/utils.ts +45 -0
- 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 +2 -2
- package/src/internal/common/api/meta.ts +19 -17
- package/src/internal/common/proxy/change-context.ts +1 -1
- package/src/internal/common/proxy/change.test.ts +91 -83
- package/src/internal/common/proxy/errors.ts +2 -2
- package/src/internal/common/proxy/handler.test.ts +1 -1
- package/src/internal/common/proxy/json-serializer.ts +27 -16
- package/src/internal/common/proxy/make-object.ts +44 -20
- package/src/internal/common/proxy/ownership.ts +2 -2
- package/src/internal/common/proxy/reactive-array.ts +1 -1
- package/src/internal/common/proxy/reactive.test.ts +54 -0
- package/src/internal/common/proxy/reactive.ts +11 -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 +78 -16
- package/src/internal/common/proxy/typed-object.test.ts +16 -28
- 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 +62 -20
- package/src/internal/common/types/model-symbols.ts +24 -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 +6 -4
- package/src/testing/api.test.ts +15 -9
- package/src/testing/index.ts +1 -0
- package/src/testing/registry.ts +44 -0
- package/src/testing/test-data.ts +159 -99
- 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-2KHZ36F5.mjs +0 -361
- package/dist/lib/neutral/chunk-2KHZ36F5.mjs.map +0 -7
- package/dist/lib/neutral/chunk-4OIBYSXE.mjs.map +0 -7
- package/dist/lib/neutral/chunk-4P3IXBLT.mjs +0 -45
- package/dist/lib/neutral/chunk-4P3IXBLT.mjs.map +0 -7
- package/dist/lib/neutral/chunk-ANHVGJI4.mjs.map +0 -7
- package/dist/lib/neutral/chunk-B4BASU6W.mjs.map +0 -7
- package/dist/lib/neutral/chunk-BNCCGLJN.mjs +0 -7
- package/dist/lib/neutral/chunk-BNCCGLJN.mjs.map +0 -7
- package/dist/lib/neutral/chunk-BVOFLCVF.mjs.map +0 -7
- package/dist/lib/neutral/chunk-DQYLD2RB.mjs.map +0 -7
- package/dist/lib/neutral/chunk-EAMSSLZC.mjs.map +0 -7
- package/dist/lib/neutral/chunk-G3IQMKF7.mjs.map +0 -7
- package/dist/lib/neutral/chunk-GZQTCRJB.mjs.map +0 -7
- package/dist/lib/neutral/chunk-HBUZJNZO.mjs.map +0 -7
- package/dist/lib/neutral/chunk-JUXPFOEI.mjs.map +0 -7
- package/dist/lib/neutral/chunk-MOR5ERFM.mjs.map +0 -7
- package/dist/lib/neutral/chunk-OMUPQMLR.mjs.map +0 -7
- package/dist/lib/neutral/chunk-PHU22NLC.mjs +0 -136
- package/dist/lib/neutral/chunk-PHU22NLC.mjs.map +0 -7
- package/dist/lib/neutral/chunk-ROG4RXXL.mjs +0 -97
- package/dist/lib/neutral/chunk-ROG4RXXL.mjs.map +0 -7
- package/dist/lib/neutral/chunk-T6W2LEZU.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TBKX6JQO.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TU3GW67D.mjs.map +0 -7
- package/dist/lib/neutral/chunk-UBEZSGXY.mjs.map +0 -7
- package/dist/lib/neutral/chunk-UI6MWK5W.mjs.map +0 -7
- package/dist/lib/neutral/chunk-V36VO5SS.mjs.map +0 -7
- package/dist/lib/neutral/chunk-WAK4DMFV.mjs.map +0 -7
- package/dist/lib/neutral/chunk-YAHXAYOW.mjs +0 -56
- package/dist/lib/neutral/chunk-YAHXAYOW.mjs.map +0 -7
- package/dist/lib/neutral/chunk-YS6Q3XAD.mjs +0 -50
- package/dist/lib/neutral/chunk-YS6Q3XAD.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/Query.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-7RO7CPBZ.mjs.map → chunk-IGK6FN65.mjs.map} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/Hypergraph.ts", "../../../src/Json.ts", "../../../src/Collection.ts", "../../../src/View.ts", "../../../src/Dataset.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport { QueryAST } from '@dxos/echo-protocol';\nexport { DXN, EID, URI } from '@dxos/keys';\n\nexport * as Annotation from './Annotation';\nexport * as Database from './Database';\nexport * as Entity from './Entity';\n// TODO(burdon): Rename to Error (less problematic than Obj/Object).\nexport * as Err from './Err';\nexport * as Feed from './Feed';\nexport * as Filter from './Filter';\nexport * as Format from './Format';\nexport * as Hypergraph from './Hypergraph';\nexport * as Json from './Json';\nexport * as JsonSchema from './JsonSchema';\nexport * as Key from './Key';\nexport * as Migration from './Migration';\nexport * as Obj from './Obj';\nexport * as Order from './Order';\nexport * as Query from './Query';\nexport * as QueryResult from './QueryResult';\nexport * as Ref from './Ref';\nexport * as Registry from './Registry';\nexport * as Relation from './Relation';\nexport * as Scope from './Scope';\nexport * as Tag from './Tag';\nexport * as Type from './Type';\nexport * as Collection from './Collection';\nexport * as View from './View';\nexport * as Dataset from './Dataset';\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type URI } from '@dxos/keys';\n\nimport type * as Database from './Database';\nimport type * as Entity from './Entity';\nimport type * as internal from './internal';\nimport type * as Key from './Key';\nimport type * as Ref from './Ref';\nimport type * as Registry from './Registry';\n\n/**\n * Resolution context.\n * Affects how non-absolute DXNs are resolved.\n */\nexport interface RefResolutionContext {\n /**\n * Space that the resolution is happening from.\n */\n space?: Key.SpaceId;\n\n /**\n * Feed that the resolution is happening from.\n * This feed will be searched first, and then the space it belongs to.\n */\n feed?: URI.URI;\n}\n\nexport interface RefResolverOptions {\n /**\n * Resolution context.\n * Affects how non-absolute DXNs are resolved.\n */\n context?: RefResolutionContext;\n\n /**\n * Middleware to change the resolved object before returning it.\n * @deprecated On track to be removed.\n */\n middleware?: (obj: internal.AnyProperties) => internal.AnyProperties;\n}\n\n/**\n * Manages cross-space database interactions.\n */\nexport interface Hypergraph extends Database.Queryable {\n /**\n * In-process registry of keyed objects and static schema types.\n * Populated at startup via `registry.add(objects)` / `registry.add(schemas)`.\n * Queries that include no explicit from() clause will fan out to this registry automatically.\n */\n get registry(): Registry.Registry;\n\n /**\n * Query objects.\n */\n query: Database.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.Ref<T>;\n\n /**\n * @param hostDb Host database for reference resolution.\n * @param middleware Called with the loaded object. The caller may change the object.\n * @returns Result of `onLoad`.\n */\n // TODO(dmaretskyi): Restructure API: Remove middleware.\n createRefResolver(options: RefResolverOptions): Ref.Resolver;\n\n /**\n * Get a database by space ID.\n * @returns The database for the given space ID, or undefined if not found.\n */\n getDatabase(spaceId: Key.SpaceId): Database.Database | undefined;\n}\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport { EID } from '@dxos/keys';\n\nimport * as Database from './Database';\nimport * as Obj from './Obj';\n\n/**\n * `JSON.stringify` replacer signature.\n *\n * Defined here (rather than re-imported from a UI package) so other ECHO-aware utilities can\n * share a stable signature without creating a dependency edge into the UI tree.\n */\nexport type JsonReplacer = (key: string, value: any) => any;\n\nexport type CreateRefReplacerOptions = {\n db: Database.Database;\n /** How many ref hops to follow. `0` leaves all refs as-is. Default: `1`. */\n depth?: number;\n};\n\nconst isEncodedRef = (value: unknown): value is { '/': string } =>\n typeof value === 'object' &&\n value !== null &&\n Object.keys(value as object).length === 1 &&\n typeof (value as { '/': unknown })['/'] === 'string';\n\nconst toJson = (obj: Obj.Any): unknown => (typeof (obj as any).toJSON === 'function' ? (obj as any).toJSON() : obj);\n\n/**\n * Returns a {@link JsonReplacer} that inlines ECHO ref objects (`{ \"/\": \"echo:...\" }`) up to\n * `depth` ref hops. Beyond that depth refs are left in their encoded form.\n *\n * Implemented as a per-call `JSON.stringify` replacer (not a one-shot tree walk at root) so it\n * composes with wrappers like `safeStringify` that intercept the root call. JSON.stringify\n * already drives the recursion; we only need to (a) detect a ref at the current callback,\n * (b) resolve and return the target if hop budget remains, and (c) tag the returned object\n * with its hop count so children know how far in they are.\n *\n * The hop count is tracked per-object via a `WeakMap`: a ref-resolved target's children inherit\n * `parentHops + 1`; a regular intermediate object's children inherit `parentHops`. This makes the\n * budget count *ref hops*, not tree depth — a ref deep in a tree still resolves once when\n * `depth >= 1`.\n *\n * Note: ECHO objects' `toJSON` runs before the replacer is invoked, so by the time we see a\n * value refs are already encoded as `{ \"/\": \"dxn:...\" }`.\n */\nexport const createRefReplacer = ({ db, depth = 1 }: CreateRefReplacerOptions): JsonReplacer => {\n // Per-object hop count. Set when we return an object (via ref resolution or pass-through) so\n // the child callbacks (which carry that object as `this`) can read it.\n const hops = new WeakMap<object, number>();\n\n return function (this: any, key: string, value: any) {\n // Hop count for this call: hops at the parent, or 0 for the root.\n const parentHops = this && typeof this === 'object' ? (hops.get(this) ?? 0) : 0;\n if (isEncodedRef(value)) {\n if (parentHops >= depth) {\n return value;\n }\n\n // The `{ '/': string }` shape is shared with non-DXN IPLD-style refs (e.g. CIDs);\n // an unparseable string would otherwise crash the whole `JSON.stringify`.\n // Treat any parse miss as \"leave as-is\" rather than propagating.\n const dxnString = value['/'];\n if (!dxnString.startsWith('dxn:') && !dxnString.startsWith('echo:')) {\n return value;\n }\n\n let echoUri: string | undefined;\n try {\n const parsed = EID.tryParse(dxnString);\n echoUri = parsed ? EID.getEntityId(parsed) : undefined;\n } catch {\n return value;\n }\n\n if (!echoUri) {\n return value;\n }\n const target = db.getObjectById(echoUri);\n if (!target) {\n return value;\n }\n\n const encoded = toJson(target);\n if (encoded != null && typeof encoded === 'object') {\n // Children of the resolved target are one hop deeper.\n hops.set(encoded as object, parentHops + 1);\n }\n return encoded;\n }\n\n // Pass-through object: children inherit the parent's hop count (this branch doesn't burn\n // budget).\n if (value != null && typeof value === 'object') {\n hops.set(value, parentHops);\n }\n\n return value;\n };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { DXN } from '@dxos/keys';\n\nimport * as Annotation from './Annotation';\nimport * as internal from './internal';\nimport * as Obj from './Obj';\nimport * as Ref from './Ref';\nimport * as Type from './Type';\n\n/**\n * A an ordered set of objects.\n */\nexport const Collection = Schema.Struct({\n name: Schema.String.pipe(Schema.optional),\n objects: Schema.Array(Ref.Ref(Obj.Unknown)).pipe(internal.FormInputAnnotation.set(false)),\n}).pipe(\n Annotation.IconAnnotation.set({ icon: 'ph--folder--regular', hue: 'amber' }),\n Type.makeObject(DXN.make('org.dxos.type.collection', '0.1.0')),\n);\n\nexport type Collection = Type.InstanceType<typeof Collection>;\n\nexport const make = (props: Partial<Obj.MakeProps<typeof Collection>> = {}): Collection =>\n Obj.make(Collection, { objects: [], ...props });\n\nexport const isCollection: (value: unknown) => value is Collection = Obj.instanceOf(Collection);\n", "//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport { QueryAST } from '@dxos/echo-protocol';\nimport { SchemaEx } from '@dxos/effect';\nimport { DXN, PublicKey } from '@dxos/keys';\n\nimport * as Annotation from './Annotation';\nimport * as Filter from './Filter';\nimport * as internal from './internal';\nimport * as Obj from './Obj';\nimport * as Query from './Query';\nimport * as Type from './Type';\n\n/**\n * Stored field metadata (e.g., for UX).\n */\nexport const FieldSchema = Schema.Struct({\n id: Schema.String,\n path: SchemaEx.JsonPath,\n visible: Schema.optional(Schema.Boolean),\n\n // TODO(wittjosiah): Presentation-specific?\n referencePath: Schema.optional(SchemaEx.JsonPath),\n});\n\nexport type FieldType = Schema.Schema.Type<typeof FieldSchema>;\n\nexport const KeyValueProps = Schema.Record({ key: Schema.String, value: Schema.Any });\n\nexport const createFieldId = () => PublicKey.random().truncate();\n\nexport const Projection = Schema.Struct({\n /**\n * Optional schema override used to customize the underlying schema.\n */\n schema: internal.JsonSchemaType.pipe(Schema.optional),\n\n /**\n * UX metadata associated with displayed fields (in table, form, etc.)\n */\n // TODO(wittjosiah): Should this just be an array of SchemaEx.JsonPath?\n fields: Schema.Array(FieldSchema),\n\n /**\n * The id for the field used to pivot the view.\n * E.g., the field to use for kanban columns or the field to use for map coordinates.\n */\n pivotFieldId: Schema.String.pipe(Schema.optional),\n});\n\nexport type Projection = Schema.Schema.Type<typeof Projection>;\n\n/**\n * Views are generated or user-defined projections of a schema's properties.\n * They are used to configure the visual representation of the data.\n */\nconst ViewSchema = Schema.Struct({\n /**\n * Query used to retrieve data.\n * Can be a user-provided query grammar string or a query AST.\n */\n query: Schema.Struct({\n raw: Schema.optional(Schema.String),\n ast: QueryAST.Query,\n }),\n\n /**\n * Projection of the data returned from the query.\n */\n projection: Projection,\n}).pipe(\n internal.HiddenAnnotation.set(true),\n Annotation.IconAnnotation.set({ icon: 'ph--funnel--regular', hue: 'green' }),\n Type.makeObject(DXN.make('org.dxos.type.view', '0.1.0')),\n);\n\n// NOTE: Declared as a named interface and the `View` const is annotated `Type.Obj<View>` so\n// downstream consumers see a named `View` type instead of the inlined `QueryAST.Query` union.\n// Without the named interface, embedding `Type.getSchema(View.View)` in a downstream\n// `Schema.Struct` triggers TS2742 portability errors (e.g. plugin-kanban, plugin-table).\n// TODO(wittjosiah): Find a better solution that doesn't require manually keeping the interface in sync.\nexport interface View extends Type.InstanceType<typeof ViewSchema> {}\n\nexport const View: Type.Obj<View> = ViewSchema as any;\n\nexport const make = (props: Partial<Obj.MakeProps<typeof View>>): View => {\n return Obj.make(View, {\n query: { ast: Query.select(Filter.nothing()).ast },\n projection: { fields: [] },\n ...props,\n });\n};\n", "//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { pipe } from 'effect/Function';\nimport * as Predicate from 'effect/Predicate';\nimport * as Schema from 'effect/Schema';\n\nimport * as Collection from './Collection';\nimport * as Feed from './Feed';\nimport * as Obj from './Obj';\nimport * as Type from './Type';\nimport * as View from './View';\n\n/**\n * Abstract set of objects, represented by a view, feed, or collection.\n * Schema-level union of the underlying type entities (rebuilt via\n * `Type.getSchema`) so this can still be consumed by Schema-side APIs such\n * as `Filter.type(...)` on a union.\n */\nexport type Dataset = Feed.Feed | Collection.Collection | View.View;\nexport const Dataset = Schema.Union(\n Type.getSchema(Feed.Feed),\n Type.getSchema(Collection.Collection),\n Type.getSchema(View.View),\n);\n\nexport const isDataset: (value: unknown) => value is Dataset = pipe(\n Obj.instanceOf(Feed.Feed),\n Predicate.or(Obj.instanceOf(Collection.Collection)),\n Predicate.or(Obj.instanceOf(View.View)),\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAASA,YAAAA,iBAAgB;AACzB,SAASC,OAAAA,MAAKC,OAAAA,MAAKC,WAAW;;;ACL9B;;;ACAA;;;;AAIA,SAASC,WAAW;AAmBpB,IAAMC,eAAe,CAACC,UACpB,OAAOA,UAAU,YACjBA,UAAU,QACVC,OAAOC,KAAKF,KAAAA,EAAiBG,WAAW,KACxC,OAAQH,MAA2B,GAAA,MAAS;AAE9C,IAAMI,SAAS,CAACC,QAA2B,OAAQA,IAAYC,WAAW,aAAcD,IAAYC,OAAM,IAAKD;AAoBxG,IAAME,oBAAoB,CAAC,EAAEC,IAAIC,QAAQ,EAAC,MAA4B;AAG3E,QAAMC,OAAO,oBAAIC,QAAAA;AAEjB,SAAO,SAAqBC,KAAaZ,OAAU;AAEjD,UAAMa,aAAa,QAAQ,OAAO,SAAS,WAAYH,KAAKI,IAAI,IAAI,KAAK,IAAK;AAC9E,QAAIf,aAAaC,KAAAA,GAAQ;AACvB,UAAIa,cAAcJ,OAAO;AACvB,eAAOT;MACT;AAKA,YAAMe,YAAYf,MAAM,GAAA;AACxB,UAAI,CAACe,UAAUC,WAAW,MAAA,KAAW,CAACD,UAAUC,WAAW,OAAA,GAAU;AACnE,eAAOhB;MACT;AAEA,UAAIiB;AACJ,UAAI;AACF,cAAMC,SAASpB,IAAIqB,SAASJ,SAAAA;AAC5BE,kBAAUC,SAASpB,IAAIsB,YAAYF,M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AAQW,OAAcC;AAAI,CAAA;AAE5E,IAAMC,gBAAgB,MAAMC,UAAUC,OAAM,EAAGC,SAAQ;AAEvD,IAAMC,aAAoBnB,eAAO;;;;EAItCoB,QAAiBC,eAAeC,KAAYf,gBAAQ;;;;;EAMpDgB,QAAeC,cAAMzB,WAAAA;;;;;EAMrB0B,cAAqBvB,eAAOoB,KAAYf,gBAAQ;AAClD,CAAA;AAQA,IAAMmB,aAAoB1B,eAAO;;;;;EAK/B2B,OAAc3B,eAAO;IACnB4B,KAAYrB,iBAAgBL,cAAM;IAClC2B,KAAKC,SAASC;EAChB,CAAA;;;;EAKAC,YAAYb;AACd,CAAA,EAAGG,KACQW,iBAAiBC,IAAI,IAAA,GACnBC,eAAeD,IAAI;EAAEE,MAAM;EAAuBC,KAAK;AAAQ,CAAA,GACrEC,WAAWC,KAAIC,KAAK,sBAAsB,OAAA,CAAA,CAAA;AAU1C,IAAMC,OAAuBf;AAE7B,IAAMc,QAAO,CAACE,UAAAA;AACnB,SAAWF,KAAKC,MAAM;IACpBd,OAAO;MAAEE,KAAWc,OAAcC,QAAO,CAAA,EAAIf;IAAI;IACjDG,YAAY;MAAET,QAAQ,CAAA;IAAG;IACzB,GAAGmB;EACL,CAAA;AACF;;;ACjGA;;;;;AAMA,SAASG,YAAY;AACrB,YAAYC,eAAe;AAC3B,YAAYC,aAAY;AAejB,IAAMC,UAAiBC,cACvBC,UAAeC,IAAI,GACnBD,UAAqBE,UAAU,GAC/BF,UAAeG,IAAI,CAAA;AAGnB,IAAMC,YAAkDC,KACzDC,WAAgBL,IAAI,GACdM,aAAOD,WAAsBJ,UAAU,CAAA,GACvCK,aAAOD,WAAgBH,IAAI,CAAA,CAAA;",
|
|
6
|
+
"names": ["QueryAST", "DXN", "EID", "URI", "EID", "isEncodedRef", "value", "Object", "keys", "length", "toJson", "obj", "toJSON", "createRefReplacer", "db", "depth", "hops", "WeakMap", "key", "parentHops", "get", "dxnString", "startsWith", "echoUri", "parsed", "tryParse", "getEntityId", "undefined", "target", "getObjectById", "encoded", "set", "make", "Schema", "DXN", "Collection", "Struct", "name", "String", "pipe", "optional", "objects", "Array", "Ref", "Unknown", "FormInputAnnotation", "set", "IconAnnotation", "icon", "hue", "makeObject", "DXN", "make", "props", "isCollection", "instanceOf", "make", "Schema", "QueryAST", "SchemaEx", "DXN", "PublicKey", "FieldSchema", "Struct", "id", "String", "path", "SchemaEx", "JsonPath", "visible", "optional", "Boolean", "referencePath", "KeyValueProps", "Record", "key", "value", "Any", "createFieldId", "PublicKey", "random", "truncate", "Projection", "schema", "JsonSchemaType", "pipe", "fields", "Array", "pivotFieldId", "ViewSchema", "query", "raw", "ast", "QueryAST", "Query", "projection", "HiddenAnnotation", "set", "IconAnnotation", "icon", "hue", "makeObject", "DXN", "make", "View", "props", "select", "nothing", "pipe", "Predicate", "Schema", "Dataset", "Union", "getSchema", "Feed", "Collection", "View", "isDataset", "pipe", "instanceOf", "or"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
4
|
+
|
|
5
|
+
// src/Scope.ts
|
|
6
|
+
var Scope_exports = {};
|
|
7
|
+
__export(Scope_exports, {
|
|
8
|
+
feed: () => feed,
|
|
9
|
+
registry: () => registry,
|
|
10
|
+
space: () => space
|
|
11
|
+
});
|
|
12
|
+
var space = (options) => ({
|
|
13
|
+
_tag: "space",
|
|
14
|
+
...options?.id !== void 0 ? {
|
|
15
|
+
spaceId: options.id
|
|
16
|
+
} : {},
|
|
17
|
+
...options?.includeAllFeeds ? {
|
|
18
|
+
includeAllFeeds: true
|
|
19
|
+
} : {}
|
|
20
|
+
});
|
|
21
|
+
var registry = (location = "local") => ({
|
|
22
|
+
_tag: "registry",
|
|
23
|
+
location
|
|
24
|
+
});
|
|
25
|
+
var feed = (feedUri) => ({
|
|
26
|
+
_tag: "feed",
|
|
27
|
+
feedUri
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
space,
|
|
32
|
+
registry,
|
|
33
|
+
feed,
|
|
34
|
+
Scope_exports
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=chunk-WISOH2XH.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Scope.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { type QueryAST } from '@dxos/echo-protocol';\n\n/**\n * Scope targeting a space's automerge documents.\n *\n * With no `spaceId`, targets the owning space — i.e. the space of whichever database\n * executes the query — so callers can reference \"this space\" without looking up its id.\n *\n * @example\n * ```ts\n * db.query(Filter.type(Person).from(Scope.space())); // owning space\n * db.query(Filter.type(Person).from(Scope.space({ id: otherSpaceId }))); // a specific space\n * ```\n */\nexport const space = (options?: { id?: string; includeAllFeeds?: boolean }): QueryAST.SpaceScope => ({\n _tag: 'space',\n ...(options?.id !== undefined ? { spaceId: options.id } : {}),\n ...(options?.includeAllFeeds ? { includeAllFeeds: true } : {}),\n});\n\n/**\n * Scope targeting a code-shipped object/type registry.\n *\n * - `'local'` — the in-process registry attached to the hypergraph (default).\n * - `'remote'` — a remote registry service (not yet implemented).\n *\n * @example\n * ```ts\n * // Discover all types — persisted in the space and code-shipped in the registry.\n * db.query(Filter.type(Type.Type).from(Scope.space(), Scope.registry()));\n * ```\n */\nexport const registry = (location: 'local' | 'remote' = 'local'): QueryAST.RegistryScope => ({\n _tag: 'registry',\n location,\n});\n\n/**\n * Scope targeting a specific feed (by its underlying queue EID).\n */\nexport const feed = (feedUri: string): QueryAST.FeedScope => ({\n _tag: 'feed',\n feedUri,\n});\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA;;;;;;AAoBO,IAAMA,QAAQ,CAACC,aAA+E;EACnGC,MAAM;EACN,GAAID,SAASE,OAAOC,SAAY;IAAEC,SAASJ,QAAQE;EAAG,IAAI,CAAC;EAC3D,GAAIF,SAASK,kBAAkB;IAAEA,iBAAiB;EAAK,IAAI,CAAC;AAC9D;AAcO,IAAMC,WAAW,CAACC,WAA+B,aAAqC;EAC3FN,MAAM;EACNM;AACF;AAKO,IAAMC,OAAO,CAACC,aAAyC;EAC5DR,MAAM;EACNQ;AACF;",
|
|
6
|
+
"names": ["space", "options", "_tag", "id", "undefined", "spaceId", "includeAllFeeds", "registry", "location", "feed", "feedUri"]
|
|
7
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Service
|
|
3
|
-
} from "./chunk-PHU22NLC.mjs";
|
|
4
1
|
import {
|
|
5
2
|
ReferenceAnnotationId,
|
|
6
|
-
|
|
3
|
+
Service,
|
|
4
|
+
getSchemaURI,
|
|
7
5
|
getTypeAnnotation,
|
|
8
6
|
getTypeIdentifierAnnotation
|
|
9
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-R5W6DXR4.mjs";
|
|
8
|
+
import {
|
|
9
|
+
getStaticTypeSchema
|
|
10
|
+
} from "./chunk-O6BH7EPN.mjs";
|
|
10
11
|
|
|
11
12
|
// src/internal/Ref/ref.ts
|
|
12
13
|
import * as Effect from "effect/Effect";
|
|
@@ -21,15 +22,49 @@ import { Event } from "@dxos/async";
|
|
|
21
22
|
import { inspectCustom } from "@dxos/debug";
|
|
22
23
|
import { EncodedReference } from "@dxos/echo-protocol";
|
|
23
24
|
import { assertArgument, invariant } from "@dxos/invariant";
|
|
24
|
-
import { DXN,
|
|
25
|
+
import { DXN, EID, EntityId } from "@dxos/keys";
|
|
26
|
+
|
|
27
|
+
// src/internal/Ref/atoms.ts
|
|
28
|
+
import * as Atom from "@effect-atom/atom/Atom";
|
|
29
|
+
|
|
30
|
+
// src/internal/Ref/utils.ts
|
|
31
|
+
var loadRefTarget = (ref, get, onTargetAvailable) => {
|
|
32
|
+
const currentTarget = ref.target;
|
|
33
|
+
if (currentTarget) {
|
|
34
|
+
return onTargetAvailable(currentTarget);
|
|
35
|
+
}
|
|
36
|
+
const unsubscribe = ref.onResolved(() => {
|
|
37
|
+
const target = ref.target;
|
|
38
|
+
if (target) {
|
|
39
|
+
get.setSelf(onTargetAvailable(target));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
get.addFinalizer(unsubscribe);
|
|
43
|
+
void ref.load().then((loadedTarget) => {
|
|
44
|
+
get.setSelf(onTargetAvailable(loadedTarget));
|
|
45
|
+
}).catch(() => {
|
|
46
|
+
});
|
|
47
|
+
return void 0;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/internal/Ref/atoms.ts
|
|
51
|
+
var refSimpleFamily = Atom.family((ref) => {
|
|
52
|
+
return Atom.make((get) => {
|
|
53
|
+
return loadRefTarget(ref, get, (target) => target);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// src/internal/Ref/ref.ts
|
|
25
58
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Ref/ref.ts";
|
|
26
59
|
var JSON_SCHEMA_ECHO_REF_ID = "/schemas/echo/ref";
|
|
27
60
|
var getSchemaReference = (property) => {
|
|
28
61
|
const { $id, reference: { schema: { $ref } = {} } = {} } = property;
|
|
29
62
|
if ($id === JSON_SCHEMA_ECHO_REF_ID && $ref) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
63
|
+
const parsed = DXN.tryMake($ref);
|
|
64
|
+
const typename = parsed ? DXN.getName(parsed) : void 0;
|
|
65
|
+
return typename ? {
|
|
66
|
+
typename
|
|
67
|
+
} : void 0;
|
|
33
68
|
}
|
|
34
69
|
};
|
|
35
70
|
var createSchemaReference = (typename) => {
|
|
@@ -37,7 +72,7 @@ var createSchemaReference = (typename) => {
|
|
|
37
72
|
$id: JSON_SCHEMA_ECHO_REF_ID,
|
|
38
73
|
reference: {
|
|
39
74
|
schema: {
|
|
40
|
-
$ref: DXN.
|
|
75
|
+
$ref: DXN.make(typename)
|
|
41
76
|
}
|
|
42
77
|
}
|
|
43
78
|
};
|
|
@@ -52,7 +87,8 @@ var getReferenceAst = (ast) => {
|
|
|
52
87
|
};
|
|
53
88
|
};
|
|
54
89
|
var RefTypeId = /* @__PURE__ */ Symbol("@dxos/echo/internal/Ref");
|
|
55
|
-
var Ref = (
|
|
90
|
+
var Ref = (input) => {
|
|
91
|
+
const schema = getStaticTypeSchema(input) ?? input;
|
|
56
92
|
assertArgument(Schema.isSchema(schema), "schema", "Must call with an instance of effect-schema");
|
|
57
93
|
const annotation = getTypeAnnotation(schema);
|
|
58
94
|
if (annotation == null) {
|
|
@@ -63,7 +99,10 @@ var Ref = (schema) => {
|
|
|
63
99
|
Ref.isRef = (obj) => {
|
|
64
100
|
return obj && typeof obj === "object" && RefTypeId in obj;
|
|
65
101
|
};
|
|
66
|
-
Ref.
|
|
102
|
+
Ref.hasEntityId = (id) => (ref) => {
|
|
103
|
+
const uri = EID.tryParse(ref.uri);
|
|
104
|
+
return uri !== void 0 && EID.isLocal(uri) && EID.getEntityId(uri) === id;
|
|
105
|
+
};
|
|
67
106
|
Ref.isRefSchema = (schema) => {
|
|
68
107
|
return Ref.isRefSchemaAST(schema.ast);
|
|
69
108
|
};
|
|
@@ -75,30 +114,24 @@ Ref.make = (obj) => {
|
|
|
75
114
|
throw new TypeError("Expected: ECHO object.");
|
|
76
115
|
}
|
|
77
116
|
const id = obj.id;
|
|
78
|
-
invariant(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
S: void 0,
|
|
82
|
-
A: [
|
|
83
|
-
"ObjectId.isValid(id)",
|
|
84
|
-
"'Invalid object ID'"
|
|
85
|
-
]
|
|
117
|
+
invariant(EntityId.isValid(id), "Invalid object ID", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 86, S: void 0, A: ["EntityId.isValid(id)", "'Invalid object ID'"] });
|
|
118
|
+
const uri = EID.make({
|
|
119
|
+
entityId: id
|
|
86
120
|
});
|
|
87
|
-
|
|
88
|
-
return new RefImpl(dxn, obj);
|
|
121
|
+
return new RefImpl(uri, obj);
|
|
89
122
|
};
|
|
90
|
-
Ref.
|
|
91
|
-
assertArgument(
|
|
92
|
-
return new RefImpl(
|
|
123
|
+
Ref.fromURI = (uri) => {
|
|
124
|
+
assertArgument(typeof uri === "string", "uri", "Expected URI string");
|
|
125
|
+
return new RefImpl(uri);
|
|
93
126
|
};
|
|
94
|
-
var createEchoReferenceSchema = (
|
|
95
|
-
if (!
|
|
96
|
-
throw new TypeError("Either
|
|
127
|
+
var createEchoReferenceSchema = (echoUri, typename, version) => {
|
|
128
|
+
if (!echoUri && !typename) {
|
|
129
|
+
throw new TypeError("Either echoUri or typename must be provided.");
|
|
97
130
|
}
|
|
98
131
|
const referenceInfo = {
|
|
99
132
|
schema: {
|
|
100
133
|
// TODO(dmaretskyi): Include version?
|
|
101
|
-
$ref:
|
|
134
|
+
$ref: echoUri ?? DXN.make(typename)
|
|
102
135
|
},
|
|
103
136
|
schemaVersion: version
|
|
104
137
|
};
|
|
@@ -106,7 +139,7 @@ var createEchoReferenceSchema = (echoId, typename, version) => {
|
|
|
106
139
|
encode: () => {
|
|
107
140
|
return (value) => Effect.gen(function* () {
|
|
108
141
|
if (Ref.isRef(value)) {
|
|
109
|
-
return EncodedReference.
|
|
142
|
+
return EncodedReference.fromURI(value.uri);
|
|
110
143
|
} else if (EncodedReference.isEncodedReference(value)) {
|
|
111
144
|
return value;
|
|
112
145
|
}
|
|
@@ -118,7 +151,7 @@ var createEchoReferenceSchema = (echoId, typename, version) => {
|
|
|
118
151
|
const dbService = yield* Effect.serviceOption(Service);
|
|
119
152
|
if (Ref.isRef(value)) {
|
|
120
153
|
if (Option.isSome(dbService)) {
|
|
121
|
-
return dbService.value.db.makeRef(value.
|
|
154
|
+
return dbService.value.db.makeRef(value.uri);
|
|
122
155
|
} else {
|
|
123
156
|
return value;
|
|
124
157
|
}
|
|
@@ -127,9 +160,9 @@ var createEchoReferenceSchema = (echoId, typename, version) => {
|
|
|
127
160
|
return yield* Effect.fail(new ParseResult.Unexpected(value, "reference"));
|
|
128
161
|
}
|
|
129
162
|
if (Option.isSome(dbService)) {
|
|
130
|
-
return dbService.value.db.makeRef(EncodedReference.
|
|
163
|
+
return dbService.value.db.makeRef(EncodedReference.toURI(value));
|
|
131
164
|
} else {
|
|
132
|
-
return Ref.
|
|
165
|
+
return Ref.fromURI(EncodedReference.toURI(value));
|
|
133
166
|
}
|
|
134
167
|
});
|
|
135
168
|
}
|
|
@@ -148,7 +181,7 @@ var createEchoReferenceSchema = (echoId, typename, version) => {
|
|
|
148
181
|
return refSchema;
|
|
149
182
|
};
|
|
150
183
|
var RefImpl = class _RefImpl {
|
|
151
|
-
#
|
|
184
|
+
#uri;
|
|
152
185
|
#resolver = void 0;
|
|
153
186
|
#resolved = new Event();
|
|
154
187
|
/**
|
|
@@ -162,15 +195,15 @@ var RefImpl = class _RefImpl {
|
|
|
162
195
|
#resolverCallback = () => {
|
|
163
196
|
this.#resolved.emit();
|
|
164
197
|
};
|
|
165
|
-
constructor(
|
|
166
|
-
this.#
|
|
198
|
+
constructor(uri, target) {
|
|
199
|
+
this.#uri = uri;
|
|
167
200
|
this.#target = target;
|
|
168
201
|
}
|
|
169
202
|
/**
|
|
170
203
|
* @inheritdoc
|
|
171
204
|
*/
|
|
172
|
-
get
|
|
173
|
-
return this.#
|
|
205
|
+
get uri() {
|
|
206
|
+
return this.#uri;
|
|
174
207
|
}
|
|
175
208
|
/**
|
|
176
209
|
* @inheritdoc
|
|
@@ -185,16 +218,8 @@ var RefImpl = class _RefImpl {
|
|
|
185
218
|
if (this.#target) {
|
|
186
219
|
return this.#target;
|
|
187
220
|
}
|
|
188
|
-
invariant(this.#resolver, "Resolver is not set", {
|
|
189
|
-
|
|
190
|
-
L: 393,
|
|
191
|
-
S: this,
|
|
192
|
-
A: [
|
|
193
|
-
"this.#resolver",
|
|
194
|
-
"'Resolver is not set'"
|
|
195
|
-
]
|
|
196
|
-
});
|
|
197
|
-
return this.#resolver.resolveSync(this.#dxn, true, this.#resolverCallback);
|
|
221
|
+
invariant(this.#resolver, "Resolver is not set", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 193, S: this, A: ["this.#resolver", "'Resolver is not set'"] });
|
|
222
|
+
return this.#resolver.resolveSync(this.#uri, true, this.#resolverCallback);
|
|
198
223
|
}
|
|
199
224
|
/**
|
|
200
225
|
* @inheritdoc
|
|
@@ -203,16 +228,8 @@ var RefImpl = class _RefImpl {
|
|
|
203
228
|
if (this.#target) {
|
|
204
229
|
return this.#target;
|
|
205
230
|
}
|
|
206
|
-
invariant(this.#resolver, "Resolver is not set", {
|
|
207
|
-
|
|
208
|
-
L: 404,
|
|
209
|
-
S: this,
|
|
210
|
-
A: [
|
|
211
|
-
"this.#resolver",
|
|
212
|
-
"'Resolver is not set'"
|
|
213
|
-
]
|
|
214
|
-
});
|
|
215
|
-
const obj = await this.#resolver.resolve(this.#dxn);
|
|
231
|
+
invariant(this.#resolver, "Resolver is not set", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 202, S: this, A: ["this.#resolver", "'Resolver is not set'"] });
|
|
232
|
+
const obj = await this.#resolver.resolve(this.#uri);
|
|
216
233
|
if (obj == null) {
|
|
217
234
|
throw new Error("Object not found");
|
|
218
235
|
}
|
|
@@ -225,16 +242,14 @@ var RefImpl = class _RefImpl {
|
|
|
225
242
|
if (this.#target) {
|
|
226
243
|
return this.#target;
|
|
227
244
|
}
|
|
228
|
-
invariant(this.#resolver, "Resolver is not set", {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
});
|
|
237
|
-
return await this.#resolver.resolve(this.#dxn);
|
|
245
|
+
invariant(this.#resolver, "Resolver is not set", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 215, S: this, A: ["this.#resolver", "'Resolver is not set'"] });
|
|
246
|
+
return await this.#resolver.resolve(this.#uri);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* @inheritdoc
|
|
250
|
+
*/
|
|
251
|
+
onResolved(callback) {
|
|
252
|
+
return this.#resolved.on(callback);
|
|
238
253
|
}
|
|
239
254
|
/**
|
|
240
255
|
* Do not inline the target object in the reference.
|
|
@@ -242,13 +257,13 @@ var RefImpl = class _RefImpl {
|
|
|
242
257
|
* Clones the reference object.
|
|
243
258
|
*/
|
|
244
259
|
noInline() {
|
|
245
|
-
const ref = new _RefImpl(this.#
|
|
260
|
+
const ref = new _RefImpl(this.#uri, void 0);
|
|
246
261
|
ref.#resolver = this.#resolver;
|
|
247
262
|
return ref;
|
|
248
263
|
}
|
|
249
264
|
encode() {
|
|
250
265
|
return {
|
|
251
|
-
"/": this.#
|
|
266
|
+
"/": this.#uri,
|
|
252
267
|
...this.#target ? {
|
|
253
268
|
target: this.#target
|
|
254
269
|
} : {}
|
|
@@ -267,7 +282,7 @@ var RefImpl = class _RefImpl {
|
|
|
267
282
|
if (this.#target) {
|
|
268
283
|
return `Ref(${this.#target.toString()})`;
|
|
269
284
|
}
|
|
270
|
-
return `Ref(${this.#
|
|
285
|
+
return `Ref(${this.#uri.toString()})`;
|
|
271
286
|
}
|
|
272
287
|
[inspectCustom] = (depth, options, inspect) => {
|
|
273
288
|
return this.toString();
|
|
@@ -280,11 +295,14 @@ var RefImpl = class _RefImpl {
|
|
|
280
295
|
* so without this, each access would create a separate cache entry.
|
|
281
296
|
*/
|
|
282
297
|
[Hash.symbol]() {
|
|
283
|
-
return Hash.hash(this.#
|
|
298
|
+
return Hash.hash(this.#uri.toString());
|
|
284
299
|
}
|
|
285
300
|
/** Effect Equal trait. See {@link Hash.symbol} for rationale. */
|
|
286
301
|
[Equal.symbol](that) {
|
|
287
|
-
return that instanceof _RefImpl && this.#
|
|
302
|
+
return that instanceof _RefImpl && this.#uri === that.uri;
|
|
303
|
+
}
|
|
304
|
+
get atom() {
|
|
305
|
+
return refSimpleFamily(this);
|
|
288
306
|
}
|
|
289
307
|
/**
|
|
290
308
|
* Internal method to set the resolver.
|
|
@@ -305,35 +323,19 @@ var RefImpl = class _RefImpl {
|
|
|
305
323
|
}
|
|
306
324
|
};
|
|
307
325
|
var setRefResolver = (ref, resolver) => {
|
|
308
|
-
invariant(ref instanceof RefImpl, "Ref is not an instance of RefImpl", {
|
|
309
|
-
F: __dxlog_file,
|
|
310
|
-
L: 506,
|
|
311
|
-
S: void 0,
|
|
312
|
-
A: [
|
|
313
|
-
"ref instanceof RefImpl",
|
|
314
|
-
"'Ref is not an instance of RefImpl'"
|
|
315
|
-
]
|
|
316
|
-
});
|
|
326
|
+
invariant(ref instanceof RefImpl, "Ref is not an instance of RefImpl", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 292, S: void 0, A: ["ref instanceof RefImpl", "'Ref is not an instance of RefImpl'"] });
|
|
317
327
|
ref._setResolver(resolver);
|
|
318
328
|
};
|
|
319
329
|
var getRefSavedTarget = (ref) => {
|
|
320
|
-
invariant(ref instanceof RefImpl, "Ref is not an instance of RefImpl", {
|
|
321
|
-
F: __dxlog_file,
|
|
322
|
-
L: 514,
|
|
323
|
-
S: void 0,
|
|
324
|
-
A: [
|
|
325
|
-
"ref instanceof RefImpl",
|
|
326
|
-
"'Ref is not an instance of RefImpl'"
|
|
327
|
-
]
|
|
328
|
-
});
|
|
330
|
+
invariant(ref instanceof RefImpl, "Ref is not an instance of RefImpl", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 298, S: void 0, A: ["ref instanceof RefImpl", "'Ref is not an instance of RefImpl'"] });
|
|
329
331
|
return ref._getSavedTarget();
|
|
330
332
|
};
|
|
331
333
|
var refVariance = {
|
|
332
334
|
_T: null
|
|
333
335
|
};
|
|
334
336
|
var refFromEncodedReference = (encodedReference, resolver) => {
|
|
335
|
-
const
|
|
336
|
-
const ref = new RefImpl(
|
|
337
|
+
const uri = EncodedReference.toURI(encodedReference);
|
|
338
|
+
const ref = new RefImpl(uri);
|
|
337
339
|
if (resolver) {
|
|
338
340
|
setRefResolver(ref, resolver);
|
|
339
341
|
}
|
|
@@ -346,40 +348,37 @@ var StaticRefResolver = class {
|
|
|
346
348
|
this.objects.set(obj.id, obj);
|
|
347
349
|
return this;
|
|
348
350
|
}
|
|
349
|
-
addSchema(
|
|
350
|
-
const
|
|
351
|
-
invariant(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
A: [
|
|
356
|
-
"dxn",
|
|
357
|
-
"'Schema has no DXN'"
|
|
358
|
-
]
|
|
359
|
-
});
|
|
360
|
-
this.schemas.set(dxn.toString(), schema);
|
|
351
|
+
addSchema(input) {
|
|
352
|
+
const schema = getStaticTypeSchema(input);
|
|
353
|
+
invariant(schema, "Type entity is missing its source schema", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 323, S: this, A: ["schema", "'Type entity is missing its source schema'"] });
|
|
354
|
+
const uri = getSchemaURI(schema);
|
|
355
|
+
invariant(uri, "Schema has no URI", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 325, S: this, A: ["uri", "'Schema has no URI'"] });
|
|
356
|
+
this.schemas.set(uri, schema);
|
|
361
357
|
return this;
|
|
362
358
|
}
|
|
363
|
-
resolveSync(
|
|
364
|
-
const
|
|
359
|
+
resolveSync(uri, _load, _onLoad) {
|
|
360
|
+
const echoUri = EID.tryParse(uri);
|
|
361
|
+
const id = echoUri ? EID.getEntityId(echoUri) : void 0;
|
|
365
362
|
if (id == null) {
|
|
366
363
|
return void 0;
|
|
367
364
|
}
|
|
368
365
|
return this.objects.get(id);
|
|
369
366
|
}
|
|
370
|
-
async resolve(
|
|
371
|
-
const
|
|
367
|
+
async resolve(uri) {
|
|
368
|
+
const echoUri = EID.tryParse(uri);
|
|
369
|
+
const id = echoUri ? EID.getEntityId(echoUri) : void 0;
|
|
372
370
|
if (id == null) {
|
|
373
371
|
return void 0;
|
|
374
372
|
}
|
|
375
373
|
return this.objects.get(id);
|
|
376
374
|
}
|
|
377
|
-
async resolveSchema(
|
|
378
|
-
return this.schemas.get(
|
|
375
|
+
async resolveSchema(uri) {
|
|
376
|
+
return this.schemas.get(uri);
|
|
379
377
|
}
|
|
380
378
|
};
|
|
381
379
|
|
|
382
380
|
export {
|
|
381
|
+
loadRefTarget,
|
|
383
382
|
JSON_SCHEMA_ECHO_REF_ID,
|
|
384
383
|
getSchemaReference,
|
|
385
384
|
createSchemaReference,
|
|
@@ -393,4 +392,4 @@ export {
|
|
|
393
392
|
refFromEncodedReference,
|
|
394
393
|
StaticRefResolver
|
|
395
394
|
};
|
|
396
|
-
//# sourceMappingURL=chunk-
|
|
395
|
+
//# sourceMappingURL=chunk-WTQJHC75.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/internal/Ref/ref.ts", "../../../src/internal/Ref/atoms.ts", "../../../src/internal/Ref/utils.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\nimport * as Effect from 'effect/Effect';\nimport * as Equal from 'effect/Equal';\nimport * as Hash from 'effect/Hash';\nimport * as Option from 'effect/Option';\nimport * as ParseResult from 'effect/ParseResult';\nimport * as Pipeable from 'effect/Pipeable';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\nimport type * as Types from 'effect/Types';\n\nimport { Event } from '@dxos/async';\nimport { type CustomInspectFunction, inspectCustom } from '@dxos/debug';\nimport { EncodedReference } from '@dxos/echo-protocol';\nimport { assertArgument, invariant } from '@dxos/invariant';\nimport { DXN, EID, EntityId, type URI } from '@dxos/keys';\n\nimport * as Database from '../../Database';\nimport type * as Type from '../../Type';\nimport {\n ReferenceAnnotationId,\n getSchemaURI,\n getTypeAnnotation,\n getTypeIdentifierAnnotation,\n} from '../Annotation/annotations';\nimport { type AnyEntity, type AnyProperties, type UnknownTypeSchema, getStaticTypeSchema } from '../common/types';\nimport { type JsonSchemaType } from '../JsonSchema';\nimport * as RefAtoms from './atoms';\n\n/**\n * The `$id` and `$ref` fields for an ECHO reference schema.\n */\nexport const JSON_SCHEMA_ECHO_REF_ID = '/schemas/echo/ref';\n\nexport const getSchemaReference = (property: JsonSchemaType): { typename: string } | undefined => {\n const { $id, reference: { schema: { $ref } = {} } = {} } = property;\n if ($id === JSON_SCHEMA_ECHO_REF_ID && $ref) {\n const parsed = DXN.tryMake($ref);\n const typename = parsed ? DXN.getName(parsed) : undefined;\n return typename ? { typename } : undefined;\n }\n};\n\nexport const createSchemaReference = (typename: string): Types.DeepMutable<JsonSchemaType> => {\n return {\n $id: JSON_SCHEMA_ECHO_REF_ID,\n reference: {\n schema: {\n $ref: DXN.make(typename),\n },\n },\n };\n};\n\n/**\n * Runtime type-info for a reference extracted from effect AST.\n */\nexport type RefereneAST = {\n /**\n * Typename of linked schema.\n */\n typename: string;\n\n /**\n * Version of linked schema.\n */\n version: string;\n};\n\nexport const getReferenceAst = (ast: SchemaAST.AST): RefereneAST | undefined => {\n if (ast._tag !== 'Declaration' || !ast.annotations[ReferenceAnnotationId]) {\n return undefined;\n }\n return {\n typename: (ast.annotations[ReferenceAnnotationId] as any).typename,\n version: (ast.annotations[ReferenceAnnotationId] as any).version,\n };\n};\n\nexport const RefTypeId: unique symbol = Symbol('@dxos/echo/internal/Ref');\n\n/**\n * Reference Schema.\n */\nexport interface RefSchema<T extends AnyEntity> extends Schema.SchemaClass<Ref<T>, EncodedReference> {}\n\n/**\n * Type of the `Ref` function and extra methods attached to it.\n */\nexport interface RefFn {\n // A reference target is a `Type.AnyEntity` entity (the canonical Option B\n // input) or one of the well-known \"any object\" / \"any relation\" branded\n // schemas (`Obj.Unknown` / `Relation.Unknown`). Arbitrary raw schemas are\n // rejected.\n //\n // Referencing a type-kind entity (a meta-schema, e.g. `Type.Type`) yields a\n // reference to a stored schema record; its loaded target is any registered\n // entity (`Type.AnyEntity`), since a stored object/relation schema is itself a\n // `Type.Type` record. Referencing an object/relation type yields a reference\n // to an instance of that type.\n <S extends Type.AnyEntity | UnknownTypeSchema<any, any> = Type.AnyEntity>(\n schema: S,\n ): RefSchema<\n S extends Type.AnyType\n ? Type.AnyEntity\n : S extends Type.AnyObj | Type.AnyRelation\n ? Type.InstanceType<S>\n : S extends UnknownTypeSchema<infer A, any>\n ? A\n : never\n >;\n\n /**\n * @returns True if the object is a reference.\n */\n isRef: (obj: unknown) => obj is Ref<any>;\n\n /**\n * @returns True if the reference points to the given object id.\n */\n hasEntityId: (id: EntityId) => (ref: Ref<any>) => boolean;\n\n /**\n * @returns True if the schema is a reference schema.\n */\n isRefSchema: (schema: Schema.Schema<any, any>) => schema is RefSchema<any>;\n\n /**\n * @returns True if the schema AST is a reference schema.\n */\n isRefSchemaAST: (ast: SchemaAST.AST) => boolean;\n\n /**\n * Constructs a reference that points to the given object.\n */\n // TODO(burdon): Narrow to Obj.Unknown?\n make: <T extends AnyEntity>(object: T) => Ref<T>;\n\n /**\n * Constructs a reference that points to the object specified by the provided URI\n * (either an `echo:` EID for an object reference or a `dxn:` DXN for a type reference).\n */\n fromURI: (uri: URI.URI) => Ref<any>;\n}\n\n/**\n * Schema builder for references.\n */\nexport const Ref: RefFn = (input: any): RefSchema<any> => {\n // `Type.Type` entities carry their source schema on the hidden slot; the\n // branded `Obj.Unknown` / `Relation.Unknown` schemas are used directly.\n const schema = getStaticTypeSchema(input) ?? input;\n assertArgument(Schema.isSchema(schema), 'schema', 'Must call with an instance of effect-schema');\n const annotation = getTypeAnnotation(schema);\n if (annotation == null) {\n throw new Error('Reference target must be an ECHO schema.');\n }\n\n return createEchoReferenceSchema(getTypeIdentifierAnnotation(schema), annotation.typename, annotation.version);\n};\n\n/**\n * Represents materialized reference to a target.\n * This is the data type for the fields marked as ref.\n */\nexport interface Ref<T> extends Pipeable.Pipeable {\n /**\n * Target URI (either an `echo:` EID for an object reference or a `dxn:` DXN for a type reference).\n */\n get uri(): URI.URI;\n\n /**\n * Returns true if the reference has a target available (inlined or resolver set).\n */\n get isAvailable(): boolean;\n\n /**\n * @returns The reference target.\n * May return `undefined` if the object is not loaded in the working set.\n * Accessing this property, even if it returns `undefined` will trigger the object to be loaded to the working set.\n */\n get target(): T | undefined;\n\n /**\n * @returns Promise that will resolves with the target object.\n * Will load the object from disk if it is not present in the working set.\n * @throws If the object is not available locally.\n */\n load(): Promise<T>;\n\n /**\n * @returns Promise that will resolves with the target object or undefined if the object is not loaded locally.\n */\n\n tryLoad(): Promise<T | undefined>;\n\n /**\n * Subscribe to the ref's resolution event.\n * The callback fires when the target object becomes available in the working set\n * (e.g. when its document is loaded after sibling-client mutation).\n * Note: the resolver only schedules a notification when the target is requested\n * via {@link target} while it is not yet loaded.\n * @returns Function that unsubscribes the callback.\n */\n onResolved(callback: () => void): () => void;\n\n /**\n * Do not inline the target object in the reference.\n * Makes .target unavailable unless the reference is connected to a database context.\n *\n * When serialized with toJSON, the difference is between:\n * `{ \"/\": \"dxn:...\" }`\n * and\n * `{ \"/\": \"dxn:...\", \"target\": { ... } }`\n *\n * Clones the reference object.\n */\n noInline(): Ref<T>;\n\n /**\n * Read-only atom for the ref target.\n * Resolves once when the target loads; does NOT subscribe to target object mutations.\n * Use `Obj.atom(ref)` if you need reactive snapshots that update on every object mutation.\n */\n get atom(): Atom.Atom<T | undefined>;\n\n /**\n * Serializes the reference to a JSON object.\n * The serialization format is compatible with the IPLD-style encoded references.\n * When a reference has a saved target (i.e. the target or object holding the reference is not in the database),\n * the target is included in the serialized object.\n *\n * Examples:\n * `{ \"/\": \"dxn:...\" }`\n * `{ \"/\": \"dxn:...\", \"target\": { ... } }`\n */\n encode(): EncodedReference;\n\n [RefTypeId]: {\n _T: T;\n };\n}\n\nexport declare namespace Ref {\n /**\n * Target of the reference.\n */\n export type Target<R> = R extends Ref<infer U> ? U : never;\n}\n\nRef.isRef = (obj: any): obj is Ref<any> => {\n return obj && typeof obj === 'object' && RefTypeId in obj;\n};\n\nRef.hasEntityId = (id: EntityId) => (ref: Ref<any>) => {\n const uri = EID.tryParse(ref.uri);\n return uri !== undefined && EID.isLocal(uri) && EID.getEntityId(uri) === id;\n};\n\nRef.isRefSchema = (schema: Schema.Schema<any, any>): schema is RefSchema<any> => {\n return Ref.isRefSchemaAST(schema.ast);\n};\n\nRef.isRefSchemaAST = (ast: SchemaAST.AST): boolean => {\n return SchemaAST.getAnnotation(ast, ReferenceAnnotationId).pipe(Option.isSome);\n};\n\nRef.make = <T extends AnyProperties>(obj: T): Ref<T> => {\n if (typeof obj !== 'object' || obj === null) {\n throw new TypeError('Expected: ECHO object.');\n }\n\n // TODO(dmaretskyi): Extract to `getObjectEchoUri` function.\n const id = obj.id;\n invariant(EntityId.isValid(id), 'Invalid object ID');\n const uri = EID.make({ entityId: id });\n return new RefImpl(uri, obj);\n};\n\nRef.fromURI = (uri: URI.URI): Ref<any> => {\n assertArgument(typeof uri === 'string', 'uri', 'Expected URI string');\n return new RefImpl(uri);\n};\n\n/**\n * `reference` field on the schema object.\n */\nexport type JsonSchemaReferenceInfo = {\n schema: { $ref: string };\n schemaVersion?: string;\n};\n\n/**\n * @internal\n */\n// TODO(burdon): Move to json schema and make private?\nexport const createEchoReferenceSchema = (\n echoUri: string | undefined,\n typename: string | undefined,\n version: string | undefined,\n): Schema.SchemaClass<Ref<any>, EncodedReference> => {\n if (!echoUri && !typename) {\n throw new TypeError('Either echoUri or typename must be provided.');\n }\n\n const referenceInfo: JsonSchemaReferenceInfo = {\n schema: {\n // TODO(dmaretskyi): Include version?\n $ref: echoUri ?? DXN.make(typename!),\n },\n schemaVersion: version,\n };\n\n // TODO(dmaretskyi): Add name and description.\n const refSchema = Schema.declare<Ref<any>, EncodedReference, []>(\n [],\n {\n encode: () => {\n return (value) =>\n Effect.gen(function* () {\n if (Ref.isRef(value)) {\n return EncodedReference.fromURI((value as Ref<any>).uri);\n } else if (EncodedReference.isEncodedReference(value)) {\n return value;\n }\n throw new Error('Invalid reference');\n });\n },\n decode: () => {\n return (value) =>\n Effect.gen(function* () {\n const dbService = yield* Effect.serviceOption(Database.Service);\n\n // TODO(dmaretskyi): This branch seems to be taken by Schema.is\n if (Ref.isRef(value)) {\n if (Option.isSome(dbService)) {\n return dbService.value.db.makeRef(value.uri);\n } else {\n return value;\n }\n }\n\n if (!EncodedReference.isEncodedReference(value)) {\n return yield* Effect.fail(new ParseResult.Unexpected(value, 'reference'));\n }\n if (Option.isSome(dbService)) {\n return dbService.value.db.makeRef(EncodedReference.toURI(value));\n } else {\n return Ref.fromURI(EncodedReference.toURI(value));\n }\n });\n },\n },\n {\n jsonSchema: {\n // TODO(dmaretskyi): We should remove `$id` and keep `$ref` with a fully qualified name.\n $id: JSON_SCHEMA_ECHO_REF_ID,\n $ref: JSON_SCHEMA_ECHO_REF_ID,\n reference: referenceInfo,\n },\n [ReferenceAnnotationId]: {\n typename: typename ?? '',\n version,\n },\n },\n );\n\n return refSchema;\n};\n\nconst getSchemaExpectedName = (ast: SchemaAST.Annotated): string | undefined => {\n return SchemaAST.getIdentifierAnnotation(ast).pipe(\n Option.orElse(() => SchemaAST.getTitleAnnotation(ast)),\n Option.orElse(() => SchemaAST.getDescriptionAnnotation(ast)),\n Option.getOrElse(() => undefined),\n );\n};\n\nexport interface RefResolver {\n /**\n * Resolve ref synchronously from the objects in the working set.\n *\n * @param uri\n * @param load If true the resolver should attempt to load the object from disk.\n * @param onLoad Callback to call when the object is loaded.\n */\n resolveSync(uri: URI.URI, load: boolean, onLoad?: () => void): AnyProperties | undefined;\n\n /**\n * Resolver ref asynchronously.\n */\n resolve(uri: URI.URI): Promise<AnyProperties | undefined>;\n\n // TODO(dmaretskyi): Combine with `resolve`.\n resolveSchema(uri: URI.URI): Promise<Schema.Schema.AnyNoContext | undefined>;\n\n /**\n * Resolve the source `Type.AnyEntity` entity for a type URI. Used by\n * deserialization paths (`Obj.fromJSON`) to set the back-reference accessed\n * via `Obj.getType` / `Entity.getType`. Optional — resolvers that only\n * carry raw schemas may leave this unimplemented; the deserializer falls\n * back to leaving the type entity unset.\n */\n resolveType?(uri: URI.URI): Promise<unknown | undefined>;\n}\n\nexport class RefImpl<T> implements Ref<T> {\n #uri: URI.URI;\n #resolver?: RefResolver = undefined;\n #resolved = new Event<void>();\n\n /**\n * Target is set when the reference is created from a specific object.\n * In this case, the target might not be in the database.\n */\n #target: T | undefined = undefined;\n\n /**\n * Callback to issue a reactive notification when object is resolved.\n */\n #resolverCallback = () => {\n this.#resolved.emit();\n };\n\n constructor(uri: URI.URI, target?: T) {\n this.#uri = uri;\n this.#target = target;\n }\n\n /**\n * @inheritdoc\n */\n get uri(): URI.URI {\n return this.#uri;\n }\n\n /**\n * @inheritdoc\n */\n get isAvailable(): boolean {\n return this.#target !== undefined || this.#resolver !== undefined;\n }\n\n /**\n * @inheritdoc\n */\n get target(): T | undefined {\n if (this.#target) {\n return this.#target;\n }\n\n invariant(this.#resolver, 'Resolver is not set');\n return this.#resolver.resolveSync(this.#uri, true, this.#resolverCallback) as T | undefined;\n }\n\n /**\n * @inheritdoc\n */\n async load(): Promise<T> {\n if (this.#target) {\n return this.#target;\n }\n invariant(this.#resolver, 'Resolver is not set');\n const obj = await this.#resolver.resolve(this.#uri);\n if (obj == null) {\n throw new Error('Object not found');\n }\n return obj as T;\n }\n\n /**\n * @inheritdoc\n */\n async tryLoad(): Promise<T | undefined> {\n if (this.#target) {\n return this.#target;\n }\n invariant(this.#resolver, 'Resolver is not set');\n return (await this.#resolver.resolve(this.#uri)) as T | undefined;\n }\n\n /**\n * @inheritdoc\n */\n onResolved(callback: () => void): () => void {\n return this.#resolved.on(callback);\n }\n\n /**\n * Do not inline the target object in the reference.\n * Makes .target unavailable unless the reference is connected to a database context.\n * Clones the reference object.\n */\n noInline(): RefImpl<T> {\n const ref = new RefImpl<T>(this.#uri, undefined);\n ref.#resolver = this.#resolver;\n return ref;\n }\n\n encode(): EncodedReference {\n return {\n '/': this.#uri,\n ...(this.#target ? { target: this.#target } : {}),\n };\n }\n\n /**\n * Serializes the reference to a JSON object.\n * The serialization format is compatible with the IPLD-style encoded references.\n * When a reference has a saved target (i.e. the target or object holding the reference is not in the database),\n * the target is included in the serialized object.\n */\n toJSON(): EncodedReference {\n return this.encode();\n }\n\n toString(): string {\n if (this.#target) {\n return `Ref(${this.#target.toString()})`;\n }\n\n return `Ref(${this.#uri.toString()})`;\n }\n\n [inspectCustom]: CustomInspectFunction = (depth, options, inspect) => {\n return this.toString();\n };\n\n [RefTypeId] = refVariance;\n\n /**\n * Effect Hash trait. Required for MutableHashMap-based caches (e.g., Atom.family)\n * to deduplicate Ref instances that point to the same object.\n * ECHO proxies return new RefImpl instances on every property access,\n * so without this, each access would create a separate cache entry.\n */\n [Hash.symbol](): number {\n return Hash.hash(this.#uri.toString());\n }\n\n /** Effect Equal trait. See {@link Hash.symbol} for rationale. */\n [Equal.symbol](that: Equal.Equal): boolean {\n return that instanceof RefImpl && this.#uri === that.uri;\n }\n\n get atom(): Atom.Atom<T | undefined> {\n return RefAtoms.refSimpleFamily(this);\n }\n\n /**\n * Internal method to set the resolver.\n *\n * @internal\n */\n _setResolver(resolver: RefResolver): void {\n this.#resolver = resolver;\n }\n\n /**\n * @internal\n */\n _getSavedTarget(): T | undefined {\n return this.#target;\n }\n\n pipe() {\n // eslint-disable-next-line prefer-rest-params\n return Pipeable.pipeArguments(this, arguments);\n }\n}\n\n/**\n * Internal API for setting the reference resolver.\n */\nexport const setRefResolver = (ref: Ref<any>, resolver: RefResolver) => {\n invariant(ref instanceof RefImpl, 'Ref is not an instance of RefImpl');\n ref._setResolver(resolver);\n};\n\n/**\n * Internal API for getting the saved target on a reference.\n */\nexport const getRefSavedTarget = (ref: Ref<any>): AnyProperties | undefined => {\n invariant(ref instanceof RefImpl, 'Ref is not an instance of RefImpl');\n return ref._getSavedTarget();\n};\n\n// Used to validate reference target type.\nconst refVariance: Ref<any>[typeof RefTypeId] = {\n _T: null as any,\n};\n\nexport const refFromEncodedReference = (encodedReference: EncodedReference, resolver?: RefResolver): Ref<any> => {\n const uri = EncodedReference.toURI(encodedReference);\n const ref = new RefImpl(uri);\n\n // TODO(dmaretskyi): Handle inline target in the encoded reference.\n\n if (resolver) {\n setRefResolver(ref, resolver);\n }\n return ref;\n};\n\nexport class StaticRefResolver implements RefResolver {\n public objects = new Map<EntityId, AnyProperties>();\n public schemas = new Map<URI.URI, Schema.Schema.AnyNoContext>();\n\n addObject(obj: AnyProperties): this {\n this.objects.set(obj.id, obj);\n return this;\n }\n\n addSchema(input: Type.AnyEntity): this {\n const schema = getStaticTypeSchema(input);\n invariant(schema, 'Type entity is missing its source schema');\n const uri = getSchemaURI(schema);\n invariant(uri, 'Schema has no URI');\n this.schemas.set(uri, schema);\n return this;\n }\n\n resolveSync(uri: URI.URI, _load: boolean, _onLoad?: () => void): AnyProperties | undefined {\n const echoUri = EID.tryParse(uri);\n const id = echoUri ? EID.getEntityId(echoUri) : undefined;\n if (id == null) {\n return undefined;\n }\n\n return this.objects.get(id);\n }\n\n async resolve(uri: URI.URI): Promise<AnyProperties | undefined> {\n const echoUri = EID.tryParse(uri);\n const id = echoUri ? EID.getEntityId(echoUri) : undefined;\n if (id == null) {\n return undefined;\n }\n\n return this.objects.get(id);\n }\n\n async resolveSchema(uri: URI.URI): Promise<Schema.Schema.AnyNoContext | undefined> {\n return this.schemas.get(uri);\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Atom from '@effect-atom/atom/Atom';\n\nimport type { Ref } from './ref';\nimport { loadRefTarget } from './utils';\n\n/**\n * Atom family for ECHO refs.\n * Uses ref reference as key — same ref returns same atom.\n * This atom only updates once when the ref loads — it does not subscribe to target object changes.\n * Use `Obj.atom(ref)` if you need reactive snapshots of ECHO objects via a ref.\n */\nexport const refSimpleFamily = Atom.family(<T>(ref: Ref<T>): Atom.Atom<T | undefined> => {\n return Atom.make<T | undefined>((get) => {\n return loadRefTarget(ref, get, (target) => target);\n });\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport type * as Atom from '@effect-atom/atom/Atom';\n\nimport type { Ref } from './ref';\n\n/**\n * Internal helper for loading ref targets in atoms.\n * Handles the common pattern of checking for loaded target and triggering async load.\n */\nexport const loadRefTarget = <T, R>(\n ref: Ref<T>,\n get: Atom.Context,\n onTargetAvailable: (target: T) => R,\n): R | undefined => {\n // Accessing `ref.target` registers a resolution callback when the target is\n // not yet loaded, so resolution can be observed via `ref.onResolved` below.\n const currentTarget = ref.target;\n if (currentTarget) {\n return onTargetAvailable(currentTarget);\n }\n\n // Subscribe to the ref's resolution event in case the target loads later.\n const unsubscribe = ref.onResolved(() => {\n const target = ref.target;\n if (target) {\n get.setSelf(onTargetAvailable(target));\n }\n });\n get.addFinalizer(unsubscribe);\n\n // Also try async load (e.g. for objects that need disk loading).\n void ref\n .load()\n .then((loadedTarget) => {\n get.setSelf(onTargetAvailable(loadedTarget));\n })\n .catch(() => {\n // Loading failed; the resolution subscription above will pick up cross-client updates.\n });\n\n return undefined;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAKA,YAAYA,YAAY;AACxB,YAAYC,WAAW;AACvB,YAAYC,UAAU;AACtB,YAAYC,YAAY;AACxB,YAAYC,iBAAiB;AAC7B,YAAYC,cAAc;AAC1B,YAAYC,YAAY;AACxB,YAAYC,eAAe;AAG3B,SAASC,aAAa;AACtB,SAAqCC,qBAAqB;AAC1D,SAASC,wBAAwB;AACjC,SAASC,gBAAgBC,iBAAiB;AAC1C,SAASC,KAAKC,KAAKC,gBAA0B;;;ACf7C,YAAYC,UAAU;;;ACQf,IAAMC,gBAAgB,CAC3BC,KACAC,KACAC,sBAAAA;AAIA,QAAMC,gBAAgBH,IAAII;AAC1B,MAAID,eAAe;AACjB,WAAOD,kBAAkBC,aAAAA;EAC3B;AAGA,QAAME,cAAcL,IAAIM,WAAW,MAAA;AACjC,UAAMF,SAASJ,IAAII;AACnB,QAAIA,QAAQ;AACVH,UAAIM,QAAQL,kBAAkBE,MAAAA,CAAAA;IAChC;EACF,CAAA;AACAH,MAAIO,aAAaH,WAAAA;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AAA,KAAA,GAAA,MAAA,GAAA,CAAA,OAAA,qBAAA,EAAA,CAAA;AACb,SAAA,QAAA,IAAA,KAAA,MAAA;AAEAE,WAAAA;;cAEQC,KAAKC,OAAAA,SAAcC;AACzB,UAAIF,UAAY,IAAA,SAAA,GAAA;UACd,KAAO7B,UAAAA,IAAAA,YAAAA,OAAAA,IAAAA;AACT,QAAA,MAAA,MAAA;AAEA,aAAW;IACb;AAEA,WAAMgC,KAAQb,QAAkD,IAAA,EAAA;;QAE9D,QAAMU,KAAKC;AACX,UAAID,UAAY,IAAA,SAAA,GAAA;UACd,KAAO7B,UAAAA,IAAAA,YAAAA,OAAAA,IAAAA;AACT,QAAA,MAAA,MAAA;AAEA,aAAW;IACb;AAEA,WAAMiC,KAAAA,QAA0B,IAAmD,EAAA;;EAEnF,MAAA,cAAA,KAAA;AACF,WAAA,KAAA,QAAA,IAAA,GAAA;;;",
|
|
6
|
+
"names": ["Effect", "Equal", "Hash", "Option", "ParseResult", "Pipeable", "Schema", "SchemaAST", "Event", "inspectCustom", "EncodedReference", "assertArgument", "invariant", "DXN", "EID", "EntityId", "Atom", "loadRefTarget", "ref", "get", "onTargetAvailable", "currentTarget", "target", "unsubscribe", "onResolved", "setSelf", "addFinalizer", "load", "then", "loadedTarget", "catch", "undefined", "refSimpleFamily", "family", "ref", "make", "get", "loadRefTarget", "target", "reference", "$ref", "$id", "JSON_SCHEMA_ECHO_REF_ID", "parsed", "tryMake", "typename", "getName", "undefined", "schema", "version", "annotation", "getTypeAnnotation", "Error", "createEchoReferenceSchema", "isRef", "obj", "hasEntityId", "ref", "uri", "isRefSchema", "isRefSchemaAST", "ast", "make", "TypeError", "EID", "entityId", "id", "RefImpl", "fromURI", "referenceInfo", "schemaVersion", "Effect", "gen", "EncodedReference", "value", "Ref", "dbService", "Option", "isSome", "jsonSchema", "ReferenceAnnotationId", "getSchemaExpectedName", "undefined", "target", "invariant", "obj", "Error", "ref", "encode", "toString", "inspectCustom", "depth", "options", "inspect", "RefTypeId", "refVariance", "atom", "pipe", "_setResolver", "resolver", "_getSavedTarget", "uri", "schemas", "addObject", "objects", "set", "addSchema", "input", "schema", "getSchemaURI", "resolveSync", "id", "echoUri", "getEntityId", "resolve", "resolveSchema"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
4
|
+
|
|
5
|
+
// src/Registry.ts
|
|
6
|
+
var Registry_exports = {};
|
|
7
|
+
__export(Registry_exports, {
|
|
8
|
+
Service: () => Service,
|
|
9
|
+
TypeId: () => TypeId,
|
|
10
|
+
isRegistry: () => isRegistry,
|
|
11
|
+
runQuery: () => runQuery
|
|
12
|
+
});
|
|
13
|
+
import * as Context from "effect/Context";
|
|
14
|
+
import * as Effect from "effect/Effect";
|
|
15
|
+
var TypeId = /* @__PURE__ */ Symbol.for("@dxos/echo/Registry");
|
|
16
|
+
var isRegistry = (obj) => obj != null && typeof obj === "object" && TypeId in obj && obj[TypeId] === TypeId;
|
|
17
|
+
var Service = class extends Context.Tag("@dxos/echo/Registry/Service")() {
|
|
18
|
+
};
|
|
19
|
+
var runQuery = (queryOrFilter) => Effect.gen(function* () {
|
|
20
|
+
const registry = yield* Service;
|
|
21
|
+
return yield* Effect.promise(() => registry.query(queryOrFilter).run());
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
TypeId,
|
|
26
|
+
isRegistry,
|
|
27
|
+
Service,
|
|
28
|
+
runQuery,
|
|
29
|
+
Registry_exports
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=chunk-WU3GIANS.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Registry.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright 2026 DXOS.org\n\n// @import-as-namespace\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\n\nimport { type ReadOnlyEvent } from '@dxos/async';\n\nimport type * as Database from './Database';\nimport * as Entity from './Entity';\nimport type * as Filter from './Filter';\nimport type * as Query from './Query';\n\n/**\n * Identifier denoting an ECHO Registry.\n */\nexport const TypeId = Symbol.for('@dxos/echo/Registry');\nexport type TypeId = typeof TypeId;\n\n/**\n * Composable, in-memory registry of keyed ECHO entities.\n *\n * Entities are stored by id and queried via the standard ECHO Query API.\n * A registry may delegate to an optional upstream registry: results from the local\n * registry take precedence and upstream results fill in anything not found locally.\n *\n * Intended use cases include caches of schemas, operations, blueprints, routines, plugins,\n * etc., sourced from 3rd-party plugins, local code, or local space objects.\n *\n * Types (schema-definition entities produced by `Type.makeObject` / `Type.makeRelation`) are\n * stored the same way as any other entity — via `add()`. Use `list().filter(Type.isType)` to\n * retrieve them.\n *\n * Scope: a Registry is independent of any ECHO space or Hypergraph — it is a process-local,\n * in-memory cache. Wire one per space (e.g. as a Layer scoped to the space's Effect runtime)\n * or share a single instance across spaces depending on the use case.\n *\n * The concrete implementation (and the `makeRegistry` / `registryLayer` factories) lives in\n * `@dxos/echo-client`; this module declares only the interface so that the `@dxos/echo` API surface\n * stays free of query-matching dependencies.\n */\nexport interface Registry {\n readonly [TypeId]: TypeId;\n\n /**\n * Stable per-instance identifier. Used to key process-local resources (e.g. memoized\n * reactive atoms) to a specific registry instance, analogous to {@link Database.spaceId}.\n */\n readonly id: string;\n\n /**\n * Fires whenever local registry contents change (add, remove, or clear).\n */\n readonly changed: ReadOnlyEvent<void>;\n\n /**\n * All locally-stored entities.\n * Does not include upstream entities — use {@link list} for that.\n */\n readonly local: readonly Entity.Unknown[];\n\n /**\n * Add or replace one or more entities in the local registry.\n * Existing entries with the same id are replaced.\n * Also indexes type entities by DXN for fast lookup.\n */\n add(entities: readonly Entity.Unknown[]): void;\n\n /**\n * Remove an entity by id from the local registry.\n * @returns true if an entity was removed, false if it was not found.\n */\n remove(id: string): boolean;\n\n /**\n * Remove all locally-stored entities.\n * Does not affect the upstream registry.\n */\n clear(): void;\n\n /**\n * Get an entity by id.\n * Searches the local registry first, then falls back to the upstream registry.\n */\n get(id: string): Entity.Unknown | undefined;\n\n /**\n * Get an entity by one of its addressing URIs — a type entity by its typename DXN (or, when\n * persisted, its identifier EID), a keyed entity by its `dxn:<key>[:<version>]`. Accepts legacy\n * DXN forms (normalized internally). Searches the local registry first, then falls back to the\n * upstream registry. Narrow the result with `Type.isType` when a type entity is required.\n */\n getByURI(uri: string): Entity.Unknown | undefined;\n\n /**\n * List all entities.\n * Local entities take precedence over upstream entities with the same id.\n */\n list(): Entity.Unknown[];\n\n /**\n * Run an ECHO query against the registry's entities (implements {@link Database.Queryable}).\n *\n * Matching happens in-memory over {@link list}. Scope (`from`) clauses are unwrapped and\n * ignored — a direct registry query always targets the registry's own entities. The primary\n * way to query registry contents is still through the database (`db.query(...).from(Scope.registry())`),\n * which fans the database and registry together; this method is for querying a registry directly.\n *\n * Only locally-evaluable AST nodes are supported: `select`, `filter`, `limit`, `from`, `options`,\n * and boolean combinators. Server-side concerns (order, traversal, text/timestamp filters) throw.\n */\n query: Database.QueryFn;\n}\n\n/**\n * Type guard for {@link Registry}.\n */\nexport const isRegistry = (obj: unknown): obj is Registry =>\n obj != null && typeof obj === 'object' && TypeId in obj && (obj as { [TypeId]?: unknown })[TypeId] === TypeId;\n\n/**\n * Options for the registry factory (`makeRegistry` in `@dxos/echo-client`).\n */\nexport type Options = {\n /**\n * Optional upstream registry. Queries fall back to upstream when an entity\n * is not present in the local registry.\n */\n upstream?: Registry;\n\n /**\n * Initial set of entities to seed the local registry with.\n */\n initial?: readonly Entity.Unknown[];\n};\n\n/**\n * Effect Context tag for {@link Registry}.\n * Use this to inject a registry into Effect-based code.\n */\nexport class Service extends Context.Tag('@dxos/echo/Registry/Service')<Service, Registry>() {}\n\n/**\n * Executes a query against the registry and returns the results.\n * Analogous to {@link Database.query} `.run` for the in-process registry.\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 Effect.gen(function* () {\n const registry = yield* Service;\n return (yield* Effect.promise(() => registry.query(queryOrFilter as any).run())) as any;\n });\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA;;;;;;;AAIA,YAAYA,aAAa;AACzB,YAAYC,YAAY;AAYjB,IAAMC,SAASC,uBAAOC,IAAI,qBAAA;AAqG1B,IAAMC,aAAa,CAACC,QACzBA,OAAO,QAAQ,OAAOA,QAAQ,YAAYJ,UAAUI,OAAQA,IAA+BJ,MAAAA,MAAYA;AAsBlG,IAAMK,UAAN,cAA8BC,YAAI,6BAAA,EAAA,EAAA;AAAqD;AAMvF,IAAMC,WAGT,CAACC,kBACIC,WAAI,aAAA;AACT,QAAMC,WAAW,OAAOL;AACxB,SAAQ,OAAcM,eAAQ,MAAMD,SAASE,MAAMJ,aAAAA,EAAsBK,IAAG,CAAA;AAC9E,CAAA;",
|
|
6
|
+
"names": ["Context", "Effect", "TypeId", "Symbol", "for", "isRegistry", "obj", "Service", "Tag", "runQuery", "queryOrFilter", "gen", "registry", "promise", "query", "run"]
|
|
7
|
+
}
|