@dxos/echo 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8
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 +10 -11
- package/dist/lib/neutral/Annotation.mjs +68 -0
- package/dist/lib/neutral/Database.mjs +38 -0
- package/dist/lib/neutral/Entity.mjs +72 -0
- package/dist/lib/neutral/Entity.mjs.map +7 -0
- package/dist/lib/neutral/Err.mjs +12 -0
- package/dist/lib/neutral/Err.mjs.map +7 -0
- package/dist/lib/neutral/Feed.mjs +54 -0
- package/dist/lib/neutral/Feed.mjs.map +7 -0
- package/dist/lib/neutral/Filter.mjs +70 -0
- package/dist/lib/neutral/Filter.mjs.map +7 -0
- package/dist/lib/neutral/Format.mjs +86 -0
- package/dist/lib/neutral/Format.mjs.map +7 -0
- package/dist/lib/neutral/JsonSchema.mjs +18 -0
- package/dist/lib/neutral/JsonSchema.mjs.map +7 -0
- package/dist/lib/neutral/Key.mjs +16 -0
- package/dist/lib/neutral/Key.mjs.map +7 -0
- package/dist/lib/neutral/Migration.mjs +18 -0
- package/dist/lib/neutral/Migration.mjs.map +7 -0
- package/dist/lib/neutral/Obj.mjs +122 -0
- package/dist/lib/neutral/Obj.mjs.map +7 -0
- package/dist/lib/neutral/Order.mjs +16 -0
- package/dist/lib/neutral/Order.mjs.map +7 -0
- package/dist/lib/neutral/Query.mjs +38 -0
- package/dist/lib/neutral/Query.mjs.map +7 -0
- package/dist/lib/neutral/QueryResult.mjs +2 -0
- package/dist/lib/neutral/QueryResult.mjs.map +7 -0
- package/dist/lib/neutral/Ref.mjs +25 -0
- package/dist/lib/neutral/Ref.mjs.map +7 -0
- package/dist/lib/neutral/Registry.mjs +14 -0
- package/dist/lib/neutral/Registry.mjs.map +7 -0
- package/dist/lib/neutral/Relation.mjs +97 -0
- package/dist/lib/neutral/Relation.mjs.map +7 -0
- package/dist/lib/neutral/Scope.mjs +12 -0
- package/dist/lib/neutral/Scope.mjs.map +7 -0
- package/dist/lib/neutral/Tag.mjs +32 -0
- package/dist/lib/neutral/Tag.mjs.map +7 -0
- package/dist/lib/neutral/Type.mjs +65 -0
- package/dist/lib/neutral/Type.mjs.map +7 -0
- package/dist/lib/neutral/chunk-35INCYOE.mjs +7 -0
- 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-5SUJPHAE.mjs +34 -0
- package/dist/lib/neutral/chunk-5SUJPHAE.mjs.map +7 -0
- package/dist/lib/neutral/chunk-6M2Z6WBH.mjs +93 -0
- package/dist/lib/neutral/chunk-6M2Z6WBH.mjs.map +7 -0
- package/dist/lib/neutral/chunk-6YDI3J37.mjs +346 -0
- package/dist/lib/neutral/chunk-6YDI3J37.mjs.map +7 -0
- package/dist/lib/neutral/chunk-7FPIAJIV.mjs +2279 -0
- package/dist/lib/neutral/chunk-7FPIAJIV.mjs.map +7 -0
- package/dist/lib/neutral/chunk-7LOUAPYZ.mjs +25 -0
- package/dist/lib/neutral/chunk-7LOUAPYZ.mjs.map +7 -0
- package/dist/lib/neutral/chunk-7PI7C4EF.mjs +747 -0
- package/dist/lib/neutral/chunk-7PI7C4EF.mjs.map +7 -0
- package/dist/lib/neutral/chunk-BBFJWWAV.mjs +51 -0
- package/dist/lib/neutral/chunk-BBFJWWAV.mjs.map +7 -0
- package/dist/lib/neutral/chunk-EVK6XBXO.mjs +56 -0
- package/dist/lib/neutral/chunk-EVK6XBXO.mjs.map +7 -0
- package/dist/lib/neutral/chunk-IGK6FN65.mjs +27 -0
- package/dist/lib/neutral/chunk-IGK6FN65.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-LWXVKPPW.mjs +281 -0
- package/dist/lib/neutral/chunk-LWXVKPPW.mjs.map +7 -0
- package/dist/lib/neutral/chunk-MZ7K3MLL.mjs +48 -0
- package/dist/lib/neutral/chunk-MZ7K3MLL.mjs.map +7 -0
- package/dist/lib/neutral/chunk-O6BH7EPN.mjs +94 -0
- package/dist/lib/neutral/chunk-O6BH7EPN.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QQIYS74I.mjs +336 -0
- 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-RIVWNMSF.mjs +41 -0
- package/dist/lib/neutral/chunk-RIVWNMSF.mjs.map +7 -0
- package/dist/lib/neutral/chunk-SBVFRTST.mjs +160 -0
- 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-TFEWTY5A.mjs +428 -0
- package/dist/lib/neutral/chunk-TFEWTY5A.mjs.map +7 -0
- package/dist/lib/neutral/chunk-TYGKCRMK.mjs +437 -0
- package/dist/lib/neutral/chunk-TYGKCRMK.mjs.map +7 -0
- package/dist/lib/neutral/chunk-UUP46KUQ.mjs +205 -0
- 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-WTQJHC75.mjs +395 -0
- 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-ZGNNFYHS.mjs +132 -0
- package/dist/lib/neutral/chunk-ZGNNFYHS.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +111 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/internal/index.mjs +539 -0
- package/dist/lib/neutral/internal/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/testing/index.mjs +458 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/Annotation.d.ts +128 -0
- package/dist/types/src/Annotation.d.ts.map +1 -0
- 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 +15 -0
- package/dist/types/src/Collection.d.ts.map +1 -0
- package/dist/types/src/Database.d.ts +208 -0
- package/dist/types/src/Database.d.ts.map +1 -0
- package/dist/types/src/Dataset.d.ts +29 -0
- package/dist/types/src/Dataset.d.ts.map +1 -0
- package/dist/types/src/Entity.d.ts +247 -0
- package/dist/types/src/Entity.d.ts.map +1 -0
- package/dist/types/src/Entity.test.d.ts +2 -0
- package/dist/types/src/Entity.test.d.ts.map +1 -0
- package/dist/types/src/Err.d.ts +107 -0
- package/dist/types/src/Err.d.ts.map +1 -0
- package/dist/types/src/Feed.d.ts +229 -0
- package/dist/types/src/Feed.d.ts.map +1 -0
- package/dist/types/src/Filter.d.ts +175 -0
- package/dist/types/src/Filter.d.ts.map +1 -0
- package/dist/types/src/Filter.test.d.ts +2 -0
- package/dist/types/src/Filter.test.d.ts.map +1 -0
- package/dist/types/src/Format.d.ts +2 -0
- package/dist/types/src/Format.d.ts.map +1 -0
- package/dist/types/src/Hypergraph.d.ts +70 -0
- package/dist/types/src/Hypergraph.d.ts.map +1 -0
- 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 +16 -0
- package/dist/types/src/JsonSchema.d.ts.map +1 -0
- package/dist/types/src/Key.d.ts +2 -1
- package/dist/types/src/Key.d.ts.map +1 -1
- package/dist/types/src/Migration.d.ts +72 -0
- package/dist/types/src/Migration.d.ts.map +1 -0
- package/dist/types/src/Obj.d.ts +514 -53
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Obj.test.d.ts +2 -0
- package/dist/types/src/Obj.test.d.ts.map +1 -0
- package/dist/types/src/Order.d.ts +26 -0
- package/dist/types/src/Order.d.ts.map +1 -0
- package/dist/types/src/Query.d.ts +231 -0
- package/dist/types/src/Query.d.ts.map +1 -0
- package/dist/types/src/Query.test.d.ts +2 -0
- package/dist/types/src/Query.test.d.ts.map +1 -0
- package/dist/types/src/QueryResult.d.ts +101 -0
- package/dist/types/src/QueryResult.d.ts.map +1 -0
- package/dist/types/src/Ref.d.ts +69 -11
- 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 +323 -24
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Relation.test.d.ts +2 -0
- package/dist/types/src/Relation.test.d.ts.map +1 -0
- 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 +34 -0
- package/dist/types/src/Tag.d.ts.map +1 -0
- package/dist/types/src/Type.d.ts +397 -107
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/Type.test.d.ts +2 -0
- package/dist/types/src/Type.test.d.ts.map +1 -0
- package/dist/types/src/View.d.ts +65 -0
- package/dist/types/src/View.d.ts.map +1 -0
- 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/hierarchy.test.d.ts +2 -0
- package/dist/types/src/hierarchy.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +22 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/annotations.d.ts +272 -0
- package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/Annotation/annotations.test.d.ts +2 -0
- package/dist/types/src/internal/Annotation/annotations.test.d.ts.map +1 -0
- 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 +6 -0
- package/dist/types/src/internal/Annotation/index.d.ts.map +1 -0
- package/dist/types/src/internal/Annotation/sorting.d.ts +24 -0
- package/dist/types/src/internal/Annotation/sorting.d.ts.map +1 -0
- package/dist/types/src/internal/Annotation/util.d.ts +48 -0
- package/dist/types/src/internal/Annotation/util.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/api.d.ts +27 -0
- package/dist/types/src/internal/Entity/api.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/entity.d.ts +84 -0
- package/dist/types/src/internal/Entity/entity.d.ts.map +1 -0
- 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 +10 -0
- package/dist/types/src/internal/Entity/index.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/model.d.ts +59 -0
- package/dist/types/src/internal/Entity/model.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/object.d.ts +18 -0
- package/dist/types/src/internal/Entity/object.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/relation.d.ts +58 -0
- package/dist/types/src/internal/Entity/relation.d.ts.map +1 -0
- 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/util.d.ts +2 -0
- package/dist/types/src/internal/Entity/util.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/version.d.ts +42 -0
- package/dist/types/src/internal/Entity/version.d.ts.map +1 -0
- package/dist/types/src/internal/Format/date.d.ts +63 -0
- package/dist/types/src/internal/Format/date.d.ts.map +1 -0
- package/dist/types/src/internal/Format/date.test.d.ts +2 -0
- package/dist/types/src/internal/Format/date.test.d.ts.map +1 -0
- package/dist/types/src/internal/Format/format.d.ts +33 -0
- package/dist/types/src/internal/Format/format.d.ts.map +1 -0
- package/dist/types/src/internal/Format/format.test.d.ts +2 -0
- package/dist/types/src/internal/Format/format.test.d.ts.map +1 -0
- package/dist/types/src/internal/Format/index.d.ts +8 -0
- package/dist/types/src/internal/Format/index.d.ts.map +1 -0
- package/dist/types/src/internal/Format/number.d.ts +31 -0
- package/dist/types/src/internal/Format/number.d.ts.map +1 -0
- package/dist/types/src/internal/Format/object.d.ts +37 -0
- package/dist/types/src/internal/Format/object.d.ts.map +1 -0
- package/dist/types/src/internal/Format/select.d.ts +13 -0
- package/dist/types/src/internal/Format/select.d.ts.map +1 -0
- package/dist/types/src/internal/Format/string.d.ts +42 -0
- package/dist/types/src/internal/Format/string.d.ts.map +1 -0
- package/dist/types/src/internal/Format/types.d.ts +72 -0
- package/dist/types/src/internal/Format/types.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/annotations.d.ts +19 -0
- package/dist/types/src/internal/JsonSchema/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/effect-schema.test.d.ts +2 -0
- package/dist/types/src/internal/JsonSchema/effect-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/index.d.ts +5 -0
- package/dist/types/src/internal/JsonSchema/index.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts +7 -0
- package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts +351 -0
- package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts +31 -0
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/json-schema.test.d.ts +2 -0
- package/dist/types/src/internal/JsonSchema/json-schema.test.d.ts.map +1 -0
- 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 +8 -0
- package/dist/types/src/internal/Obj/clone.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/common.d.ts +18 -0
- package/dist/types/src/internal/Obj/common.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/create-object.d.ts +39 -0
- package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/create-object.test.d.ts +2 -0
- package/dist/types/src/internal/Obj/create-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/deleted.d.ts +6 -0
- package/dist/types/src/internal/Obj/deleted.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/index.d.ts +11 -0
- package/dist/types/src/internal/Obj/index.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/inspect.d.ts +2 -0
- package/dist/types/src/internal/Obj/inspect.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/json-serializer.d.ts +45 -0
- package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/json-serializer.test.d.ts +2 -0
- package/dist/types/src/internal/Obj/json-serializer.test.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/schema-validator.d.ts +2 -0
- package/dist/types/src/internal/Obj/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/schema-validator.test.d.ts +2 -0
- package/dist/types/src/internal/Obj/schema-validator.test.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/set-value.d.ts +7 -0
- package/dist/types/src/internal/Obj/set-value.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/set-value.test.d.ts +2 -0
- package/dist/types/src/internal/Obj/set-value.test.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/snapshot.d.ts +6 -0
- package/dist/types/src/internal/Obj/snapshot.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/typed-object.d.ts +25 -0
- package/dist/types/src/internal/Obj/typed-object.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/Obj/typed-object.test.d.ts.map +1 -0
- 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/pretty.d.ts +10 -0
- 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/index.d.ts +3 -0
- package/dist/types/src/internal/Ref/index.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/ref-array.d.ts +21 -0
- package/dist/types/src/internal/Ref/ref-array.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/ref.d.ts +262 -0
- package/dist/types/src/internal/Ref/ref.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/ref.test.d.ts +2 -0
- package/dist/types/src/internal/Ref/ref.test.d.ts.map +1 -0
- 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 +7 -0
- package/dist/types/src/internal/Type/compose.d.ts.map +1 -0
- package/dist/types/src/internal/Type/compose.test.d.ts +2 -0
- package/dist/types/src/internal/Type/compose.test.d.ts.map +1 -0
- package/dist/types/src/internal/Type/index.d.ts +3 -0
- package/dist/types/src/internal/Type/index.d.ts.map +1 -0
- package/dist/types/src/internal/Type/manipulation.d.ts +9 -0
- package/dist/types/src/internal/Type/manipulation.d.ts.map +1 -0
- 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/index.d.ts +11 -0
- package/dist/types/src/internal/common/api/index.d.ts.map +1 -0
- package/dist/types/src/internal/common/api/meta.d.ts +45 -0
- package/dist/types/src/internal/common/api/meta.d.ts.map +1 -0
- package/dist/types/src/internal/common/index.d.ts +4 -0
- package/dist/types/src/internal/common/index.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/change-context.d.ts +55 -0
- package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/change.test.d.ts +2 -0
- package/dist/types/src/internal/common/proxy/change.test.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts +5 -0
- package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/errors.d.ts +19 -0
- package/dist/types/src/internal/common/proxy/errors.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/event-batch.d.ts +10 -0
- package/dist/types/src/internal/common/proxy/event-batch.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/handler.test.d.ts +2 -0
- package/dist/types/src/internal/common/proxy/handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/index.d.ts +14 -0
- package/dist/types/src/internal/common/proxy/index.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/json-serializer.d.ts +6 -0
- package/dist/types/src/internal/common/proxy/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/make-object.d.ts +20 -0
- package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/ownership.d.ts +57 -0
- package/dist/types/src/internal/common/proxy/ownership.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/proxy-types.d.ts +18 -0
- package/dist/types/src/internal/common/proxy/proxy-types.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/proxy-utils.d.ts +47 -0
- package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/reactive-array.d.ts +8 -0
- package/dist/types/src/internal/common/proxy/reactive-array.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/reactive.d.ts +39 -0
- package/dist/types/src/internal/common/proxy/reactive.d.ts.map +1 -0
- 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 +15 -0
- package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/schema.test.d.ts +2 -0
- package/dist/types/src/internal/common/proxy/schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/symbols.d.ts +3 -0
- package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts +64 -0
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/typed-handler.test.d.ts +2 -0
- package/dist/types/src/internal/common/proxy/typed-handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/common/proxy/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/common/types/base.d.ts +27 -0
- package/dist/types/src/internal/common/types/base.d.ts.map +1 -0
- package/dist/types/src/internal/common/types/entity.d.ts +94 -0
- package/dist/types/src/internal/common/types/entity.d.ts.map +1 -0
- package/dist/types/src/internal/common/types/index.d.ts +7 -0
- package/dist/types/src/internal/common/types/index.d.ts.map +1 -0
- package/dist/types/src/internal/common/types/meta.d.ts +54 -0
- package/dist/types/src/internal/common/types/meta.d.ts.map +1 -0
- package/dist/types/src/internal/common/types/model-symbols.d.ts +65 -0
- package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -0
- package/dist/types/src/internal/common/types/typename.d.ts +28 -0
- package/dist/types/src/internal/common/types/typename.d.ts.map +1 -0
- package/dist/types/src/internal/common/types/version.d.ts +15 -0
- package/dist/types/src/internal/common/types/version.d.ts.map +1 -0
- 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 +11 -0
- package/dist/types/src/internal/index.d.ts.map +1 -0
- package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +4 -1
- 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 +18 -0
- package/dist/types/src/testing/test-data.d.ts.map +1 -0
- package/dist/types/src/testing/test-schema.d.ts +298 -0
- package/dist/types/src/testing/test-schema.d.ts.map +1 -0
- package/dist/types/src/testing/util.d.ts +23 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +122 -57
- package/src/Annotation.test.ts +439 -0
- package/src/Annotation.ts +202 -0
- package/src/Collection.ts +33 -0
- package/src/Database.ts +345 -0
- package/src/Dataset.ts +34 -0
- package/src/Entity.test.ts +132 -0
- package/src/Entity.ts +345 -0
- package/src/Err.ts +40 -0
- package/src/Feed.ts +352 -0
- package/src/Filter.test.ts +90 -0
- package/src/Filter.ts +484 -0
- package/src/Format.ts +5 -0
- package/src/Hypergraph.ts +84 -0
- package/src/Json.test.ts +175 -0
- package/src/Json.ts +103 -0
- package/src/JsonSchema.ts +26 -0
- package/src/Key.ts +4 -1
- package/src/Migration.ts +114 -0
- package/src/Obj.test.ts +641 -0
- package/src/Obj.ts +836 -105
- package/src/Order.ts +68 -0
- package/src/Query.test.ts +835 -0
- package/src/Query.ts +634 -0
- package/src/QueryResult.ts +132 -0
- package/src/Ref.ts +97 -10
- package/src/Registry.ts +155 -0
- package/src/Relation.test.ts +88 -0
- package/src/Relation.ts +508 -61
- package/src/Scope.ts +50 -0
- package/src/Tag.md +88 -0
- package/src/Tag.ts +84 -0
- package/src/Type.test.ts +257 -0
- package/src/Type.ts +643 -152
- package/src/View.ts +98 -0
- package/src/exemplars.test.ts +21 -0
- package/src/hierarchy.test.ts +33 -0
- package/src/index.ts +24 -4
- package/src/internal/Annotation/annotations.test.ts +165 -0
- package/src/internal/Annotation/annotations.ts +609 -0
- package/src/internal/Annotation/dictionary.ts +47 -0
- package/src/internal/Annotation/entity-dictionary.ts +74 -0
- package/src/internal/Annotation/index.ts +9 -0
- package/src/internal/Annotation/sorting.ts +51 -0
- package/src/internal/Annotation/util.ts +94 -0
- package/src/internal/Entity/api.ts +77 -0
- package/src/internal/Entity/entity.ts +277 -0
- package/src/internal/Entity/guard.ts +26 -0
- package/src/internal/Entity/index.ts +13 -0
- package/src/internal/Entity/model.ts +119 -0
- package/src/internal/Entity/object.ts +73 -0
- package/src/internal/Entity/relation.ts +188 -0
- package/src/internal/Entity/type-kind.ts +75 -0
- package/src/internal/Entity/type-uri.ts +92 -0
- package/src/internal/Entity/util.ts +33 -0
- package/src/internal/Entity/version.ts +96 -0
- package/src/internal/Format/date.test.ts +55 -0
- package/src/internal/Format/date.ts +213 -0
- package/src/internal/Format/format.test.ts +97 -0
- package/src/internal/Format/format.ts +54 -0
- package/src/internal/Format/index.ts +11 -0
- package/src/internal/Format/number.ts +89 -0
- package/src/internal/Format/object.ts +97 -0
- package/src/internal/Format/select.ts +18 -0
- package/src/internal/Format/string.ts +81 -0
- package/src/internal/Format/types.ts +186 -0
- package/src/internal/JsonSchema/annotations.ts +50 -0
- package/src/internal/JsonSchema/effect-schema.test.ts +143 -0
- package/src/internal/JsonSchema/index.ts +8 -0
- package/src/internal/JsonSchema/json-schema-normalize.ts +111 -0
- package/src/internal/JsonSchema/json-schema-type.ts +403 -0
- package/src/internal/JsonSchema/json-schema.test.ts +786 -0
- package/src/internal/JsonSchema/json-schema.ts +547 -0
- package/src/internal/Obj/atoms.ts +244 -0
- package/src/internal/Obj/clone.ts +53 -0
- package/src/internal/Obj/common.ts +75 -0
- package/src/internal/Obj/create-object.test.ts +116 -0
- package/src/internal/Obj/create-object.ts +140 -0
- package/src/internal/Obj/deleted.ts +19 -0
- package/src/internal/Obj/index.ts +14 -0
- package/src/internal/Obj/inspect.ts +48 -0
- package/src/internal/Obj/json-serializer.test.ts +199 -0
- package/src/internal/Obj/json-serializer.ts +278 -0
- package/src/internal/Obj/schema-validator.test.ts +182 -0
- package/src/internal/Obj/schema-validator.ts +6 -0
- package/src/internal/Obj/set-value.test.ts +258 -0
- package/src/internal/Obj/set-value.ts +158 -0
- package/src/internal/Obj/snapshot.ts +114 -0
- package/src/internal/Obj/typed-object.test.ts +32 -0
- package/src/internal/Obj/typed-object.ts +30 -0
- package/src/{query → internal/Query}/index.ts +1 -1
- package/src/internal/Query/pretty.ts +162 -0
- package/src/internal/Ref/atoms.ts +20 -0
- package/src/internal/Ref/index.ts +6 -0
- package/src/internal/Ref/ref-array.ts +38 -0
- package/src/internal/Ref/ref.test.ts +91 -0
- package/src/internal/Ref/ref.ts +650 -0
- package/src/internal/Ref/utils.ts +45 -0
- package/src/internal/Type/compose.test.ts +43 -0
- package/src/internal/Type/compose.ts +41 -0
- package/src/internal/Type/index.ts +6 -0
- package/src/internal/Type/manipulation.ts +67 -0
- package/src/internal/Type/type-schema.ts +60 -0
- package/src/internal/common/README.md +102 -0
- package/src/internal/common/api/index.ts +15 -0
- package/src/internal/common/api/meta.ts +90 -0
- package/src/internal/common/index.ts +7 -0
- package/src/internal/common/proxy/change-context.ts +138 -0
- package/src/internal/common/proxy/change.test.ts +527 -0
- package/src/internal/common/proxy/define-hidden-property.ts +14 -0
- package/src/internal/common/proxy/errors.ts +42 -0
- package/src/internal/common/proxy/event-batch.ts +44 -0
- package/src/internal/common/proxy/handler.test.ts +121 -0
- package/src/internal/common/proxy/index.ts +17 -0
- package/src/internal/common/proxy/json-serializer.ts +101 -0
- package/src/internal/common/proxy/make-object.ts +129 -0
- package/src/internal/common/proxy/ownership.ts +252 -0
- package/src/internal/common/proxy/proxy-types.ts +23 -0
- package/src/internal/common/proxy/proxy-utils.ts +150 -0
- package/src/internal/common/proxy/reactive-array.ts +71 -0
- package/src/internal/common/proxy/reactive.test.ts +54 -0
- package/src/internal/common/proxy/reactive.ts +77 -0
- package/src/internal/common/proxy/schema-validator.ts +244 -0
- package/src/internal/common/proxy/schema.test.ts +107 -0
- package/src/internal/common/proxy/symbols.ts +7 -0
- package/src/internal/common/proxy/typed-handler.test.ts +314 -0
- package/src/internal/common/proxy/typed-handler.ts +509 -0
- package/src/internal/common/proxy/typed-object.test.ts +103 -0
- package/src/internal/common/types/base.ts +43 -0
- package/src/internal/common/types/entity.ts +133 -0
- package/src/internal/common/types/index.ts +15 -0
- package/src/internal/common/types/meta.ts +109 -0
- package/src/internal/common/types/model-symbols.ts +89 -0
- package/src/internal/common/types/typename.ts +91 -0
- package/src/internal/common/types/version.ts +19 -0
- package/src/internal/common/types/well-known-types.ts +15 -0
- package/src/internal/index.ts +19 -0
- package/src/testing/api.test.ts +131 -0
- package/src/testing/index.ts +4 -1
- package/src/testing/registry.ts +44 -0
- package/src/testing/test-data.ts +189 -0
- package/src/testing/test-schema.ts +204 -0
- package/src/testing/util.ts +88 -0
- package/dist/lib/browser/chunk-NLPBTYZV.mjs +0 -647
- package/dist/lib/browser/chunk-NLPBTYZV.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -22
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs +0 -70
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BQZZRMFX.mjs +0 -647
- package/dist/lib/node-esm/chunk-BQZZRMFX.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -22
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -70
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/experimental/database.d.ts +0 -8
- package/dist/types/src/experimental/database.d.ts.map +0 -1
- package/dist/types/src/experimental/index.d.ts +0 -1
- package/dist/types/src/experimental/index.d.ts.map +0 -1
- package/dist/types/src/experimental/queue.d.ts +0 -8
- package/dist/types/src/experimental/queue.d.ts.map +0 -1
- package/dist/types/src/experimental/space.d.ts +0 -8
- package/dist/types/src/experimental/space.d.ts.map +0 -1
- package/dist/types/src/query/dsl.d.ts +0 -218
- package/dist/types/src/query/dsl.d.ts.map +0 -1
- package/dist/types/src/query/dsl.test.d.ts +0 -2
- package/dist/types/src/query/dsl.test.d.ts.map +0 -1
- package/dist/types/src/query/index.d.ts +0 -2
- package/dist/types/src/query/index.d.ts.map +0 -1
- package/dist/types/src/testing/types.d.ts +0 -113
- package/dist/types/src/testing/types.d.ts.map +0 -1
- package/src/experimental/database.ts +0 -11
- package/src/experimental/index.ts +0 -7
- package/src/experimental/queue.ts +0 -11
- package/src/experimental/space.ts +0 -11
- package/src/query/dsl.test.ts +0 -324
- package/src/query/dsl.ts +0 -646
- package/src/test/api.test.ts +0 -173
- package/src/testing/types.ts +0 -91
- /package/dist/lib/{browser/index.mjs.map → neutral/Annotation.mjs.map} +0 -0
- /package/dist/lib/{node-esm/index.mjs.map → neutral/Database.mjs.map} +0 -0
- /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Function from 'effect/Function';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
9
|
+
|
|
10
|
+
import { SchemaEx } from '@dxos/effect';
|
|
11
|
+
import { assertArgument, invariant } from '@dxos/invariant';
|
|
12
|
+
import { DXN, URI } from '@dxos/keys';
|
|
13
|
+
import { type Primitive } from '@dxos/util';
|
|
14
|
+
|
|
15
|
+
import type * as Annotation from '../../Annotation';
|
|
16
|
+
import { type Mutable } from '../common/proxy';
|
|
17
|
+
import { type AnyProperties, EntityKind, TypeId, getSchema } from '../common/types';
|
|
18
|
+
import { createAnnotationHelper } from './util';
|
|
19
|
+
|
|
20
|
+
const ANNOTATION_TYPE_ID: Annotation.TypeId = '~@dxos/echo/Annotation' as const;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export const FIELD_PATH_ANNOTATION = 'path';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Sets the path for the field.
|
|
29
|
+
* @param path Data source path in the json path format. This is the field path in the source object.
|
|
30
|
+
*/
|
|
31
|
+
// TODO(burdon): Field, vs. path vs. property.
|
|
32
|
+
export const FieldPath = (path: string) => PropertyMeta(FIELD_PATH_ANNOTATION, path);
|
|
33
|
+
|
|
34
|
+
//
|
|
35
|
+
// Type
|
|
36
|
+
//
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* ECHO identifier (for a stored schema).
|
|
40
|
+
* Must be an `echo:` URI.
|
|
41
|
+
*/
|
|
42
|
+
export const TypeIdentifierAnnotationId = Symbol.for('@dxos/schema/annotation/TypeIdentifier');
|
|
43
|
+
|
|
44
|
+
export const getTypeIdentifierAnnotation = (schema: Schema.Schema.All) =>
|
|
45
|
+
Function.flow(
|
|
46
|
+
SchemaAST.getAnnotation<string>(TypeIdentifierAnnotationId),
|
|
47
|
+
Option.getOrElse(() => undefined),
|
|
48
|
+
)(schema.ast);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @returns The schema's type identifier URI — whichever URI fits.
|
|
52
|
+
*
|
|
53
|
+
* - Stored (dynamic) schemas: the schema-as-object's EID, so loaded objects ride
|
|
54
|
+
* along with their schema as a strong dependency.
|
|
55
|
+
* - Non-stored (static) schemas: the typename DXN built from `TypeAnnotation`.
|
|
56
|
+
*
|
|
57
|
+
* This URI is what gets written to an object's `system.type`; queries that filter by
|
|
58
|
+
* type also use it (see `Filter.type` / `getTypeURIFromSpecifier`), so both sides
|
|
59
|
+
* stay symmetric without per-schema branching.
|
|
60
|
+
*/
|
|
61
|
+
export const getSchemaURI = (schema: Schema.Schema.All): URI.URI | undefined => {
|
|
62
|
+
assertArgument(Schema.isSchema(schema), 'schema', 'invalid schema');
|
|
63
|
+
const id = getTypeIdentifierAnnotation(schema);
|
|
64
|
+
if (id) {
|
|
65
|
+
return URI.make(id);
|
|
66
|
+
}
|
|
67
|
+
const objectAnnotation = getTypeAnnotation(schema);
|
|
68
|
+
if (objectAnnotation) {
|
|
69
|
+
return DXN.make(objectAnnotation.typename, objectAnnotation.version);
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//
|
|
75
|
+
// TypeAnnotation
|
|
76
|
+
//
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Fully qualified globally unique typename.
|
|
80
|
+
* Example: `org.dxos.type.message`
|
|
81
|
+
*/
|
|
82
|
+
// TODO(wittjosiah): Factor out to DXN spec.
|
|
83
|
+
export const TypenameSchema = Schema.String.pipe(
|
|
84
|
+
Schema.pattern(
|
|
85
|
+
/^[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})?)$/,
|
|
86
|
+
),
|
|
87
|
+
).annotations({
|
|
88
|
+
description: 'Fully qualified globally unique typename in reverse-DNS form.',
|
|
89
|
+
example: 'org.dxos.type.message',
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Semantic version format: `major.minor.patch`
|
|
94
|
+
* Example: `1.0.0`
|
|
95
|
+
*/
|
|
96
|
+
export const VersionSchema = Schema.String.pipe(Schema.pattern(/^\d+.\d+.\d+$/)).annotations({
|
|
97
|
+
description: 'Semantic version format: `major.minor.patch`',
|
|
98
|
+
example: '1.0.0',
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export const TypeMeta = Schema.Struct({
|
|
102
|
+
typename: TypenameSchema,
|
|
103
|
+
version: VersionSchema,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
export interface TypeMeta extends Schema.Schema.Type<typeof TypeMeta> {}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Entity type.
|
|
110
|
+
*/
|
|
111
|
+
export const TypeAnnotationId = Symbol.for('@dxos/schema/annotation/Type');
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Payload stored under {@link TypeAnnotationId}.
|
|
115
|
+
*/
|
|
116
|
+
export const TypeAnnotation = Schema.extend(
|
|
117
|
+
TypeMeta,
|
|
118
|
+
Schema.Struct({
|
|
119
|
+
kind: Schema.Enums(EntityKind),
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* If this is a relation, the schema of the source object.
|
|
123
|
+
* Must be present if entity kind is {@link EntityKind.Relation}.
|
|
124
|
+
*/
|
|
125
|
+
sourceSchema: Schema.optional(DXN.Schema),
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* If this is a relation, the schema of the target object.
|
|
129
|
+
* Must be present if entity kind is {@link EntityKind.Relation}.
|
|
130
|
+
*/
|
|
131
|
+
targetSchema: Schema.optional(DXN.Schema),
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
export interface TypeAnnotation extends Schema.Schema.Type<typeof TypeAnnotation> {}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @returns {@link TypeAnnotation} from a schema.
|
|
139
|
+
* Schema must have been created with {@link TypedObject} or {@link TypedLink} or manually assigned an appropriate annotation.
|
|
140
|
+
*/
|
|
141
|
+
export const getTypeAnnotation = (schema: Schema.Schema.All): TypeAnnotation | undefined => {
|
|
142
|
+
assertArgument(schema != null && schema.ast != null, 'schema', 'invalid schema');
|
|
143
|
+
return Function.flow(
|
|
144
|
+
SchemaAST.getAnnotation<TypeAnnotation>(TypeAnnotationId),
|
|
145
|
+
Option.getOrElse(() => undefined),
|
|
146
|
+
)(schema.ast);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @returns {@link EntityKind} from a schema.
|
|
151
|
+
*/
|
|
152
|
+
export const getEntityKind = (schema: Schema.Schema.All): EntityKind | undefined => getTypeAnnotation(schema)?.kind;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @internal
|
|
156
|
+
* @returns Schema typename (without dxn: prefix or version number).
|
|
157
|
+
*/
|
|
158
|
+
export const getSchemaTypename = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.typename;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @internal
|
|
162
|
+
* @returns Schema version in semver format.
|
|
163
|
+
*/
|
|
164
|
+
export const getSchemaVersion = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.version;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Gets the typename of the object without the version.
|
|
168
|
+
* Returns only the name portion, not the DXN.
|
|
169
|
+
* @example "org.example.type.contact"
|
|
170
|
+
*
|
|
171
|
+
* @internal (use Obj.getTypename)
|
|
172
|
+
*/
|
|
173
|
+
export const getTypename = (obj: AnyProperties): string | undefined => {
|
|
174
|
+
const schema = getSchema(obj);
|
|
175
|
+
if (schema != null) {
|
|
176
|
+
// Try to extract typename from DXN.
|
|
177
|
+
return getSchemaTypename(schema);
|
|
178
|
+
} else {
|
|
179
|
+
// `obj` may be an arbitrary value (e.g. from `isInstanceOf`); read TypeId
|
|
180
|
+
// directly so we return undefined for non-entities instead of throwing.
|
|
181
|
+
const type = (obj as any)?.[TypeId];
|
|
182
|
+
// Parse the URI string to extract typename.
|
|
183
|
+
if (DXN.isDXN(type)) {
|
|
184
|
+
const parsed = DXN.tryMake(type);
|
|
185
|
+
return parsed && DXN.getName(parsed);
|
|
186
|
+
}
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @internal (use Type.setTypename)
|
|
193
|
+
*/
|
|
194
|
+
// TODO(dmaretskyi): Rename setTypeDXN.
|
|
195
|
+
export const setTypename = (obj: any, typename: URI.URI): void => {
|
|
196
|
+
assertArgument(typeof typename === 'string', 'typename', 'Invalid type.');
|
|
197
|
+
Object.defineProperty(obj, TypeId, {
|
|
198
|
+
value: typename,
|
|
199
|
+
writable: false,
|
|
200
|
+
enumerable: false,
|
|
201
|
+
configurable: false,
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @returns Object type URI — either a typename {@link DXN} or an `echo:` reference to a stored Schema object.
|
|
207
|
+
* @returns undefined if the object has no registered type URI (e.g. unresolved query result).
|
|
208
|
+
* @example `dxn:com.example.type.person:1.0.0`
|
|
209
|
+
* @example `echo:/01KKKG2FHWCMTR0BY00GJSVT1X` (stored schema)
|
|
210
|
+
*
|
|
211
|
+
* @internal (use Obj.getTypeURI)
|
|
212
|
+
*/
|
|
213
|
+
export const getTypeURI = (obj: AnyProperties): URI.URI | undefined => {
|
|
214
|
+
if (obj == null) {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
const type = (obj as any)[TypeId];
|
|
218
|
+
if (type == null) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
invariant(URI.isURI(type), 'Invalid object.');
|
|
222
|
+
return type;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
//
|
|
226
|
+
// PropertyMeta
|
|
227
|
+
//
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* PropertyMeta (metadata for dynamic schema properties).
|
|
231
|
+
* For user-defined annotations.
|
|
232
|
+
*/
|
|
233
|
+
export const PropertyMetaAnnotationId = Symbol.for('@dxos/schema/annotation/PropertyMeta');
|
|
234
|
+
|
|
235
|
+
export type PropertyMetaValue = Primitive | Record<string, Primitive> | Primitive[];
|
|
236
|
+
|
|
237
|
+
export type PropertyMetaAnnotation = {
|
|
238
|
+
[name: string]: PropertyMetaValue;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// TODO(wittjosiah): Align with other annotations.
|
|
242
|
+
// TODO(wittjosiah): Why is this separate from FormatAnnotation?
|
|
243
|
+
/**
|
|
244
|
+
* Apply property-level metadata to an Effect schema. Only accepts
|
|
245
|
+
* `Schema.Schema.Any` — apply BEFORE wrapping the schema with
|
|
246
|
+
* `Type.makeObject` / `Type.makeRelation`. To read property meta off a
|
|
247
|
+
* `Type.Type` entity, unwrap it first with `Type.getSchema(entity)`.
|
|
248
|
+
*/
|
|
249
|
+
export const PropertyMeta = (name: string, value: PropertyMetaValue) => {
|
|
250
|
+
return <A, I, R>(self: Schema.Schema<A, I, R>): Schema.Schema<A, I, R> => {
|
|
251
|
+
const existingMeta = self.ast.annotations[PropertyMetaAnnotationId] as PropertyMetaAnnotation;
|
|
252
|
+
return self.annotations({
|
|
253
|
+
[PropertyMetaAnnotationId]: {
|
|
254
|
+
...existingMeta,
|
|
255
|
+
[name]: value,
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
export const getPropertyMetaAnnotation = <T>(prop: SchemaAST.PropertySignature, name: string) =>
|
|
262
|
+
Function.pipe(
|
|
263
|
+
SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(prop.type),
|
|
264
|
+
Option.map((meta) => meta[name] as T),
|
|
265
|
+
Option.getOrElse(() => undefined),
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
//
|
|
269
|
+
// Reference
|
|
270
|
+
//
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Schema reference.
|
|
274
|
+
*/
|
|
275
|
+
export const ReferenceAnnotationId = Symbol.for('@dxos/schema/annotation/Reference');
|
|
276
|
+
export type ReferenceAnnotationValue = TypeAnnotation;
|
|
277
|
+
export const ReferenceAnnotation = createAnnotationHelper<ReferenceAnnotationValue>(ReferenceAnnotationId);
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* SchemaMeta.
|
|
281
|
+
*/
|
|
282
|
+
export const SchemaMetaSymbol = Symbol.for('@dxos/schema/SchemaMeta');
|
|
283
|
+
export type SchemaMeta = TypeMeta & { id: string };
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Identifies a schema as hidden from user-facing surfaces (like dotfiles — visible only via an advanced setting).
|
|
287
|
+
*/
|
|
288
|
+
export const HiddenAnnotationId = Symbol.for('@dxos/schema/annotation/Hidden');
|
|
289
|
+
export const HiddenAnnotation = createAnnotationHelper<boolean>(HiddenAnnotationId);
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Identifies label property or JSON path expression.
|
|
293
|
+
* Either a string or an array of strings representing field accessors each matched in priority order.
|
|
294
|
+
*/
|
|
295
|
+
export const LabelAnnotationId = Symbol.for('@dxos/schema/annotation/Label');
|
|
296
|
+
export const LabelAnnotation = createAnnotationHelper<string[]>(LabelAnnotationId);
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Returns the label for a given object based on {@link LabelAnnotationId}.
|
|
300
|
+
* Lower-level version that requires explicit schema parameter.
|
|
301
|
+
* Skips empty strings and whitespace-only strings, continuing to the next field.
|
|
302
|
+
*/
|
|
303
|
+
// TODO(burdon): Convert to SchemaEx.JsonPath?
|
|
304
|
+
export const getLabelWithSchema = <S extends Schema.Schema.Any>(
|
|
305
|
+
schema: S,
|
|
306
|
+
object: Schema.Schema.Type<S>,
|
|
307
|
+
): string | undefined => {
|
|
308
|
+
const annotation = LabelAnnotation.get(schema).pipe(Option.getOrElse(() => ['name']));
|
|
309
|
+
for (const accessor of annotation) {
|
|
310
|
+
assertArgument(
|
|
311
|
+
typeof accessor === 'string',
|
|
312
|
+
'accessor',
|
|
313
|
+
'Label annotation must be a string or an array of strings',
|
|
314
|
+
);
|
|
315
|
+
const value = SchemaEx.getField(object, accessor as SchemaEx.JsonPath);
|
|
316
|
+
switch (typeof value) {
|
|
317
|
+
case 'string': {
|
|
318
|
+
const trimmed = value.trim();
|
|
319
|
+
if (trimmed.length > 0) {
|
|
320
|
+
return value;
|
|
321
|
+
}
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
case 'number':
|
|
325
|
+
case 'boolean':
|
|
326
|
+
case 'bigint':
|
|
327
|
+
case 'symbol':
|
|
328
|
+
return value.toString();
|
|
329
|
+
case 'undefined':
|
|
330
|
+
case 'object':
|
|
331
|
+
case 'function':
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return undefined;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Sets the label for a given object based on {@link LabelAnnotationId}.
|
|
341
|
+
* Lower-level version that requires explicit schema parameter.
|
|
342
|
+
*/
|
|
343
|
+
export const setLabelWithSchema = <S extends Schema.Schema.Any>(
|
|
344
|
+
schema: S,
|
|
345
|
+
object: Schema.Schema.Type<S>,
|
|
346
|
+
label: string,
|
|
347
|
+
) => {
|
|
348
|
+
const annotation = LabelAnnotation.get(schema).pipe(
|
|
349
|
+
Option.map((field) => field[0]),
|
|
350
|
+
Option.getOrElse(() => 'name'),
|
|
351
|
+
);
|
|
352
|
+
object[annotation] = label;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Identifies description property or JSON path expression.
|
|
357
|
+
* A string representing field accessor.
|
|
358
|
+
*/
|
|
359
|
+
export const DescriptionAnnotationId = Symbol.for('@dxos/schema/annotation/Description');
|
|
360
|
+
export const DescriptionAnnotation = createAnnotationHelper<string>(DescriptionAnnotationId);
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Returns the description for a given object based on {@link DescriptionAnnotationId}.
|
|
364
|
+
* Lower-level version that requires explicit schema parameter.
|
|
365
|
+
*/
|
|
366
|
+
// TODO(burdon): Convert to SchemaEx.JsonPath?
|
|
367
|
+
export const getDescriptionWithSchema = <S extends Schema.Schema.Any>(
|
|
368
|
+
schema: S,
|
|
369
|
+
object: Schema.Schema.Type<S>,
|
|
370
|
+
): string | undefined => {
|
|
371
|
+
const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));
|
|
372
|
+
assertArgument(typeof accessor === 'string', 'accessor', 'Description annotation must be a string');
|
|
373
|
+
const value = SchemaEx.getField(object, accessor as SchemaEx.JsonPath);
|
|
374
|
+
switch (typeof value) {
|
|
375
|
+
case 'string':
|
|
376
|
+
case 'number':
|
|
377
|
+
case 'boolean':
|
|
378
|
+
case 'bigint':
|
|
379
|
+
case 'symbol':
|
|
380
|
+
return value.toString();
|
|
381
|
+
case 'undefined':
|
|
382
|
+
case 'object':
|
|
383
|
+
case 'function':
|
|
384
|
+
default:
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Sets the description for a given object based on {@link DescriptionAnnotationId}.
|
|
391
|
+
* Lower-level version that requires explicit schema parameter.
|
|
392
|
+
*/
|
|
393
|
+
export const setDescriptionWithSchema = <S extends Schema.Schema.Any>(
|
|
394
|
+
schema: S,
|
|
395
|
+
object: Schema.Schema.Type<S>,
|
|
396
|
+
description: string,
|
|
397
|
+
) => {
|
|
398
|
+
const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));
|
|
399
|
+
object[accessor] = description;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Identifies if a property should be included in a form or not.
|
|
404
|
+
* By default, all properties are included in forms, so this is opt-out.
|
|
405
|
+
*/
|
|
406
|
+
export const FormInputAnnotationId = Symbol.for('@dxos/schema/annotation/FormInput');
|
|
407
|
+
export const FormInputAnnotation = createAnnotationHelper<boolean>(FormInputAnnotationId);
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* When set on a `Ref` property, the form renders the referenced object's own
|
|
411
|
+
* fields inline (a nested form bound to the target) instead of a picker.
|
|
412
|
+
*/
|
|
413
|
+
export const FormInlineAnnotationId = Symbol.for('@dxos/schema/annotation/FormInline');
|
|
414
|
+
export const FormInlineAnnotation = createAnnotationHelper<boolean>(FormInlineAnnotationId);
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Default field to be used on referenced schema to lookup the value.
|
|
418
|
+
*/
|
|
419
|
+
export const FieldLookupAnnotationId = Symbol.for('@dxos/schema/annotation/FieldLookup');
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Generate test data.
|
|
423
|
+
*/
|
|
424
|
+
export const GeneratorAnnotationId = Symbol.for('@dxos/schema/annotation/Generator');
|
|
425
|
+
|
|
426
|
+
export type GeneratorAnnotationValue =
|
|
427
|
+
| string
|
|
428
|
+
| {
|
|
429
|
+
generator: string;
|
|
430
|
+
args?: any[];
|
|
431
|
+
probability?: number;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
export const GeneratorAnnotation = createAnnotationHelper<GeneratorAnnotationValue>(GeneratorAnnotationId);
|
|
435
|
+
|
|
436
|
+
interface MakeAnnoationsProps<T> {
|
|
437
|
+
id: string;
|
|
438
|
+
schema: Schema.Schema<T, any, never>;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Annotation ids use the same NSID / reverse-DNS format as TypenameSchema —
|
|
442
|
+
// dot-separated segments, middle segments may be hyphenated, final segment may be camelCase.
|
|
443
|
+
// At least 3 segments are required (e.g. org.dxos.annotation.example).
|
|
444
|
+
export const makeUserAnnotation = <T>(props: MakeAnnoationsProps<T>): Annotation.Annotation<T> => {
|
|
445
|
+
assertArgument(
|
|
446
|
+
/^[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(
|
|
447
|
+
props.id,
|
|
448
|
+
),
|
|
449
|
+
'id',
|
|
450
|
+
'Annotation id must be in the FQN format (org.dxos.annotation.example or org.dxos.space.rootCollection).',
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
const annotation: Annotation.Annotation<T> = {
|
|
454
|
+
[ANNOTATION_TYPE_ID]: { _Type: {} as T },
|
|
455
|
+
key: props.id as Annotation.Key,
|
|
456
|
+
schema: props.schema,
|
|
457
|
+
get: (schema) => getFromAst(schema.ast, annotation),
|
|
458
|
+
getFromAst: (ast) => getFromAst(ast, annotation),
|
|
459
|
+
set: (value) =>
|
|
460
|
+
PropertyMeta(props.id, Schema.encodeSync(props.schema)(value)) as <S extends Schema.Schema.Any>(schema: S) => S,
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
return annotation;
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
const IconAnnotationSchema = Schema.Struct({
|
|
467
|
+
/**
|
|
468
|
+
* Phosphor icon name (e.g., 'ph--user--regular', 'ph--cube--regular', 'ph--link--regular ', etc.)
|
|
469
|
+
*/
|
|
470
|
+
icon: Schema.String.pipe(Schema.pattern(/^ph--[a-z-]+--[a-z]+$/)),
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Color name.
|
|
474
|
+
*
|
|
475
|
+
* List of colors:
|
|
476
|
+
* - 'red'
|
|
477
|
+
* - 'orange'
|
|
478
|
+
* - 'amber'
|
|
479
|
+
* - 'yellow'
|
|
480
|
+
* - 'lime'
|
|
481
|
+
* - 'green'
|
|
482
|
+
* - 'emerald'
|
|
483
|
+
* - 'teal'
|
|
484
|
+
* - 'cyan'
|
|
485
|
+
* - 'violet'
|
|
486
|
+
* - 'purple'
|
|
487
|
+
* - 'fuchsia'
|
|
488
|
+
* - 'pink'
|
|
489
|
+
* - 'rose'
|
|
490
|
+
*/
|
|
491
|
+
hue: Schema.optional(Schema.String),
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
export interface IconAnnotation extends Schema.Schema.Type<typeof IconAnnotationSchema> {}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Icon to render in the UI.
|
|
498
|
+
*/
|
|
499
|
+
export const IconAnnotation = makeUserAnnotation<IconAnnotation>({
|
|
500
|
+
id: 'org.dxos.annotation.icon',
|
|
501
|
+
schema: IconAnnotationSchema,
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Indicates that this entity's icon should be resolved from a property whose value is a `Ref`
|
|
506
|
+
* to another entity. Consumers (e.g. graph node builders) resolve the ref target and use that
|
|
507
|
+
* target's schema `IconAnnotation` in place of the static one declared on this schema.
|
|
508
|
+
*
|
|
509
|
+
* Useful for wrapper schemas that delegate their visual identity to a referenced sub-entity
|
|
510
|
+
* (e.g. a generic `Game` whose icon should come from its `variant` ref's typed state).
|
|
511
|
+
*/
|
|
512
|
+
export const IconFromRefAnnotation = makeUserAnnotation<string>({
|
|
513
|
+
id: 'org.dxos.annotation.icon.from-ref',
|
|
514
|
+
schema: Schema.String,
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Options for {@link getLabel}.
|
|
519
|
+
*/
|
|
520
|
+
export type GetLabelOptions = {
|
|
521
|
+
/**
|
|
522
|
+
* Strategy for deriving a label when the entity has no `LabelAnnotation` value.
|
|
523
|
+
* - `'typename'`: use the entity's typename (e.g. `org.dxos.type.table`).
|
|
524
|
+
* Useful for Card.Title chrome that must always display something, even
|
|
525
|
+
* for unlabeled objects.
|
|
526
|
+
*/
|
|
527
|
+
fallback?: 'typename';
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Get the label of an entity.
|
|
532
|
+
* Accepts both reactive entities and snapshots.
|
|
533
|
+
*
|
|
534
|
+
* If `options.fallback === 'typename'` and no label is set, returns the
|
|
535
|
+
* entity's typename instead.
|
|
536
|
+
*/
|
|
537
|
+
export const getLabel = (entity: AnyProperties, options?: GetLabelOptions): string | undefined => {
|
|
538
|
+
const schema = getSchema(entity);
|
|
539
|
+
const label = schema != null ? getLabelWithSchema(schema, entity) : undefined;
|
|
540
|
+
if (label != null) {
|
|
541
|
+
return label;
|
|
542
|
+
}
|
|
543
|
+
if (options?.fallback === 'typename') {
|
|
544
|
+
return getTypename(entity);
|
|
545
|
+
}
|
|
546
|
+
return undefined;
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Set the label of an entity.
|
|
551
|
+
* Must be called within an Obj.update or Relation.update callback.
|
|
552
|
+
*/
|
|
553
|
+
export const setLabel = (entity: Mutable<AnyProperties>, label: string) => {
|
|
554
|
+
const schema = getSchema(entity);
|
|
555
|
+
if (schema != null) {
|
|
556
|
+
setLabelWithSchema(schema, entity, label);
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Get the description of an entity.
|
|
562
|
+
* Accepts both reactive entities and snapshots.
|
|
563
|
+
*/
|
|
564
|
+
export const getDescription = (entity: AnyProperties): string | undefined => {
|
|
565
|
+
const schema = getSchema(entity);
|
|
566
|
+
if (schema != null) {
|
|
567
|
+
return getDescriptionWithSchema(schema, entity);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Get the icon annotation for an entity, resolved via its type-level `IconAnnotation`.
|
|
573
|
+
* Accepts both reactive entities and snapshots.
|
|
574
|
+
*
|
|
575
|
+
* Returns the full `{ icon, hue }` annotation so callers can use both the phosphor icon
|
|
576
|
+
* name and the suggested colour. Callers wanting just the icon name typically write
|
|
577
|
+
* `Obj.getIcon(obj)?.icon ?? 'ph--cube--regular'`.
|
|
578
|
+
*
|
|
579
|
+
* Note: this is the "static" icon from the object's own schema. It does not follow
|
|
580
|
+
* `IconFromRefAnnotation` delegation — call sites needing that (e.g. app-graph node
|
|
581
|
+
* builders) should resolve the ref themselves.
|
|
582
|
+
*/
|
|
583
|
+
export const getIcon = (entity: AnyProperties): IconAnnotation | undefined => {
|
|
584
|
+
const schema = getSchema(entity);
|
|
585
|
+
if (schema == null) {
|
|
586
|
+
return undefined;
|
|
587
|
+
}
|
|
588
|
+
return Option.getOrUndefined(IconAnnotation.get(schema));
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Set the description of an entity.
|
|
593
|
+
* Must be called within an Obj.update or Relation.update callback.
|
|
594
|
+
*/
|
|
595
|
+
export const setDescription = (entity: Mutable<AnyProperties>, description: string) => {
|
|
596
|
+
const schema = getSchema(entity);
|
|
597
|
+
if (schema != null) {
|
|
598
|
+
setDescriptionWithSchema(schema, entity, description);
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
export { Dictionary, Key, getDictionary, setDictionary } from './dictionary';
|
|
603
|
+
|
|
604
|
+
export const getFromAst = <T>(ast: SchemaAST.AST, annotation: Annotation.Annotation<T>): Option.Option<T> => {
|
|
605
|
+
return SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(ast).pipe(
|
|
606
|
+
Option.flatMap((meta) => Option.fromNullable(meta[annotation.key])),
|
|
607
|
+
Option.map(Schema.decodeUnknownSync(annotation.schema)),
|
|
608
|
+
);
|
|
609
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Function from 'effect/Function';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
import * as Types from 'effect/Types';
|
|
9
|
+
|
|
10
|
+
import type * as Annotation from '../../Annotation';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Unique identifier for an annotation.
|
|
14
|
+
*/
|
|
15
|
+
export const Key = Schema.String.pipe(Schema.brand('~@dxos/echo/AnnotationKey'));
|
|
16
|
+
export type Key = Schema.Schema.Type<typeof Key>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Set of annotation values stored on entity meta or nested in schemas.
|
|
20
|
+
*/
|
|
21
|
+
export const Dictionary = Schema.Record({ key: Key, value: Schema.Unknown });
|
|
22
|
+
export interface Dictionary extends Schema.Schema.Type<typeof Dictionary> {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get the value of an annotation from a dictionary.
|
|
26
|
+
*/
|
|
27
|
+
export const getDictionary = <T>(
|
|
28
|
+
values: Annotation.Dictionary,
|
|
29
|
+
annotation: Annotation.Annotation<T>,
|
|
30
|
+
): Option.Option<T> => {
|
|
31
|
+
if (!(annotation.key in values)) {
|
|
32
|
+
return Option.none();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return Function.pipe(values[annotation.key], Schema.decodeUnknownSync(annotation.schema), Option.some);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Set the value of an annotation in a dictionary.
|
|
40
|
+
*/
|
|
41
|
+
export const setDictionary = <T>(
|
|
42
|
+
values: Types.Mutable<Annotation.Dictionary>,
|
|
43
|
+
annotation: Annotation.Annotation<T>,
|
|
44
|
+
value: T,
|
|
45
|
+
): void => {
|
|
46
|
+
values[annotation.key] = Schema.encodeSync(annotation.schema)(value);
|
|
47
|
+
};
|