@dxos/echo 0.8.4-main.ef1bc66f44 → 0.8.4-main.effb148878
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 +9 -9
- package/dist/lib/neutral/Annotation.mjs +7 -3
- package/dist/lib/neutral/Database.mjs +8 -4
- package/dist/lib/neutral/Entity.mjs +35 -18
- package/dist/lib/neutral/Err.mjs +3 -1
- package/dist/lib/neutral/Extension.mjs +18 -0
- package/dist/lib/neutral/Extension.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 +25 -12
- package/dist/lib/neutral/Format.mjs +23 -3
- package/dist/lib/neutral/JsonSchema.mjs +9 -9
- package/dist/lib/neutral/Key.mjs +7 -3
- package/dist/lib/neutral/Migration.mjs +18 -0
- package/dist/lib/neutral/Migration.mjs.map +7 -0
- package/dist/lib/neutral/Obj.mjs +41 -23
- package/dist/lib/neutral/Order.mjs +1 -1
- package/dist/lib/neutral/Query.mjs +21 -9
- package/dist/lib/neutral/QueryResult.mjs +1 -1
- package/dist/lib/neutral/Ref.mjs +13 -9
- package/dist/lib/neutral/Relation.mjs +34 -23
- package/dist/lib/neutral/SchemaRegistry.mjs +1 -1
- package/dist/lib/neutral/Tag.mjs +14 -10
- package/dist/lib/neutral/Type.mjs +52 -36
- package/dist/lib/neutral/{chunk-K5K3Z62A.mjs → chunk-4SYHDOQA.mjs} +14 -6
- package/dist/lib/neutral/chunk-4SYHDOQA.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-XAJMXQ4H.mjs → chunk-4U7OD55H.mjs} +6 -2
- package/dist/lib/neutral/chunk-4U7OD55H.mjs.map +7 -0
- package/dist/lib/neutral/chunk-52NG2XEE.mjs +34 -0
- package/dist/lib/neutral/chunk-52NG2XEE.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-KB7RIVLK.mjs → chunk-A5HDDVKS.mjs} +33 -6
- package/dist/lib/neutral/chunk-A5HDDVKS.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-DLPC7DHQ.mjs → chunk-EZ4XJFHJ.mjs} +9 -11
- package/dist/lib/neutral/chunk-EZ4XJFHJ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-ZAHWXGK4.mjs → chunk-F625JEZB.mjs} +97 -19
- package/dist/lib/neutral/chunk-F625JEZB.mjs.map +7 -0
- package/dist/lib/neutral/chunk-FFCN66OF.mjs +420 -0
- package/dist/lib/neutral/chunk-FFCN66OF.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-RPB6V4BE.mjs → chunk-GOHDOJE3.mjs} +16 -3
- package/dist/lib/neutral/chunk-GOHDOJE3.mjs.map +7 -0
- package/dist/lib/neutral/chunk-GWFFC34K.mjs +50 -0
- package/dist/lib/neutral/chunk-GWFFC34K.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J7QWJQQV.mjs +318 -0
- package/dist/lib/neutral/chunk-J7QWJQQV.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-QARLJVDB.mjs → chunk-JTHNDGAR.mjs} +8 -4
- package/dist/lib/neutral/chunk-JTHNDGAR.mjs.map +7 -0
- package/dist/lib/neutral/chunk-K5RH2PBH.mjs +361 -0
- package/dist/lib/neutral/chunk-K5RH2PBH.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-RIMHNJ3E.mjs → chunk-KHRAQDYX.mjs} +138 -91
- package/dist/lib/neutral/chunk-KHRAQDYX.mjs.map +7 -0
- package/dist/lib/neutral/chunk-L65CW5EI.mjs +156 -0
- package/dist/lib/neutral/chunk-L65CW5EI.mjs.map +7 -0
- package/dist/lib/neutral/chunk-LNZIPZX6.mjs +2186 -0
- package/dist/lib/neutral/chunk-LNZIPZX6.mjs.map +7 -0
- package/dist/lib/neutral/chunk-MPXUNTME.mjs +41 -0
- package/dist/lib/neutral/chunk-MPXUNTME.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-7WE7SBA2.mjs → chunk-O2EOH7XQ.mjs} +152 -134
- package/dist/lib/neutral/chunk-O2EOH7XQ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-MTEHHY62.mjs → chunk-Q7ID37KF.mjs} +121 -94
- package/dist/lib/neutral/chunk-Q7ID37KF.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QLYEQ5VA.mjs +205 -0
- package/dist/lib/neutral/chunk-QLYEQ5VA.mjs.map +7 -0
- package/dist/lib/neutral/chunk-SSDGRJ3A.mjs +747 -0
- package/dist/lib/neutral/chunk-SSDGRJ3A.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-ROKO4RKJ.mjs → chunk-TTCSATUD.mjs} +2 -2
- package/dist/lib/neutral/chunk-TTCSATUD.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-ANHVGJI4.mjs → chunk-UEFRFUYC.mjs} +8 -4
- package/dist/lib/neutral/chunk-UEFRFUYC.mjs.map +7 -0
- package/dist/lib/neutral/chunk-UN7K472Q.mjs +132 -0
- package/dist/lib/neutral/chunk-UN7K472Q.mjs.map +7 -0
- package/dist/lib/neutral/chunk-UQAMAXDU.mjs +243 -0
- package/dist/lib/neutral/chunk-UQAMAXDU.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-4L6DOFXP.mjs → chunk-V5NE2X7Y.mjs} +1 -1
- package/dist/lib/neutral/chunk-V5NE2X7Y.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-OMUPQMLR.mjs → chunk-V72DY6LU.mjs} +1 -1
- package/dist/lib/neutral/chunk-ZII2BGPM.mjs +269 -0
- package/dist/lib/neutral/chunk-ZII2BGPM.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-N2QNHMT5.mjs → chunk-ZM7VFIS2.mjs} +22 -2
- package/dist/lib/neutral/chunk-ZM7VFIS2.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +56 -29
- package/dist/lib/neutral/internal/index.mjs +128 -77
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/testing/index.mjs +226 -174
- package/dist/lib/neutral/testing/index.mjs.map +3 -3
- package/dist/types/src/Annotation.d.ts +3 -3
- package/dist/types/src/Annotation.d.ts.map +1 -1
- 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 +27 -42
- package/dist/types/src/Database.d.ts.map +1 -1
- 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 +123 -29
- package/dist/types/src/Entity.d.ts.map +1 -1
- package/dist/types/src/Err.d.ts +56 -13
- package/dist/types/src/Err.d.ts.map +1 -1
- package/dist/types/src/Extension.d.ts +80 -0
- package/dist/types/src/Extension.d.ts.map +1 -0
- package/dist/types/src/Extension.test.d.ts +2 -0
- package/dist/types/src/Extension.test.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 +74 -11
- package/dist/types/src/Filter.d.ts.map +1 -1
- 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 +3 -3
- package/dist/types/src/Format.d.ts.map +1 -1
- package/dist/types/src/Hypergraph.d.ts +15 -10
- 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 +11 -4
- 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 +72 -0
- package/dist/types/src/Migration.d.ts.map +1 -0
- package/dist/types/src/Obj.d.ts +201 -77
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Order.d.ts.map +1 -1
- package/dist/types/src/Query.d.ts +117 -17
- package/dist/types/src/Query.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +66 -10
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +127 -54
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/SchemaRegistry.d.ts +12 -13
- package/dist/types/src/SchemaRegistry.d.ts.map +1 -1
- package/dist/types/src/Tag.d.ts +4 -3
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +337 -218
- package/dist/types/src/Type.d.ts.map +1 -1
- 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/index.d.ts +8 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/{annotations → Annotation}/annotations.d.ts +98 -24
- package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/Annotation/annotations.test.d.ts.map +1 -0
- package/dist/types/src/internal/Annotation/index.d.ts +4 -0
- package/dist/types/src/internal/Annotation/index.d.ts.map +1 -0
- package/dist/types/src/internal/{api → Annotation}/sorting.d.ts +1 -1
- package/dist/types/src/internal/Annotation/sorting.d.ts.map +1 -0
- package/dist/types/src/internal/{annotations → Annotation}/util.d.ts +15 -6
- package/dist/types/src/internal/Annotation/util.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/api.d.ts +13 -0
- package/dist/types/src/internal/Entity/api.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/entity.d.ts +67 -0
- package/dist/types/src/internal/Entity/entity.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 +57 -0
- package/dist/types/src/internal/Entity/model.d.ts.map +1 -0
- package/dist/types/src/internal/{entities → Entity}/object.d.ts +3 -3
- package/dist/types/src/internal/Entity/object.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/relation.d.ts +51 -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 +25 -0
- package/dist/types/src/internal/Entity/type-uri.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/util.d.ts.map +1 -0
- package/dist/types/src/internal/{api → Entity}/version.d.ts +1 -1
- package/dist/types/src/internal/Entity/version.d.ts.map +1 -0
- package/dist/types/src/internal/Format/date.d.ts.map +1 -0
- package/dist/types/src/internal/Format/date.test.d.ts.map +1 -0
- package/dist/types/src/internal/{formats → Format}/format.d.ts +2 -1
- package/dist/types/src/internal/Format/format.d.ts.map +1 -0
- package/dist/types/src/internal/Format/format.test.d.ts.map +1 -0
- package/dist/types/src/internal/{formats → Format}/index.d.ts +2 -2
- package/dist/types/src/internal/Format/index.d.ts.map +1 -0
- package/dist/types/src/internal/Format/number.d.ts.map +1 -0
- package/dist/types/src/internal/Format/object.d.ts.map +1 -0
- package/dist/types/src/internal/Format/select.d.ts.map +1 -0
- package/dist/types/src/internal/Format/string.d.ts.map +1 -0
- package/dist/types/src/internal/{formats → Format}/types.d.ts +1 -1
- package/dist/types/src/internal/Format/types.d.ts.map +1 -0
- package/dist/types/src/internal/{json-schema → JsonSchema}/annotations.d.ts +1 -1
- package/dist/types/src/internal/JsonSchema/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/effect-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/index.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts.map +1 -0
- package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema-type.d.ts +37 -37
- package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -0
- package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema.d.ts +3 -2
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/json-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/clone.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/common.d.ts.map +1 -0
- package/dist/types/src/internal/{object → Obj}/create-object.d.ts +10 -12
- package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/create-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/{object → Obj}/deleted.d.ts +1 -1
- package/dist/types/src/internal/Obj/deleted.d.ts.map +1 -0
- package/dist/types/src/internal/{object → Obj}/index.d.ts +0 -1
- package/dist/types/src/internal/Obj/index.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/inspect.d.ts.map +1 -0
- package/dist/types/src/internal/{object → Obj}/json-serializer.d.ts +16 -8
- package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -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.map +1 -0
- package/dist/types/src/internal/{object → Obj}/set-value.d.ts +2 -2
- package/dist/types/src/internal/Obj/set-value.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/set-value.test.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/snapshot.d.ts.map +1 -0
- package/dist/types/src/internal/{object → Obj}/typed-object.d.ts +5 -5
- package/dist/types/src/internal/Obj/typed-object.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/Query.d.ts +10 -0
- package/dist/types/src/internal/Query.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/index.d.ts.map +1 -0
- package/dist/types/src/internal/{ref → Ref}/ref-array.d.ts +1 -1
- package/dist/types/src/internal/Ref/ref-array.d.ts.map +1 -0
- package/dist/types/src/internal/{ref → Ref}/ref.d.ts +42 -19
- package/dist/types/src/internal/Ref/ref.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/ref.test.d.ts.map +1 -0
- package/dist/types/src/internal/{schema → Type}/compose.d.ts +1 -1
- package/dist/types/src/internal/Type/compose.d.ts.map +1 -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/{schema → Type}/manipulation.d.ts +0 -1
- 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/{api → common/api}/index.d.ts +0 -4
- package/dist/types/src/internal/common/api/index.d.ts.map +1 -0
- package/dist/types/src/internal/{api → common/api}/meta.d.ts +3 -3
- 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/{proxy → common/proxy}/change-context.d.ts +1 -1
- 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.map +1 -0
- package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts.map +1 -0
- package/dist/types/src/internal/{proxy → common/proxy}/errors.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/errors.d.ts.map +1 -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.map +1 -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.map +1 -0
- package/dist/types/src/internal/common/proxy/make-object.d.ts +19 -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.map +1 -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.map +1 -0
- package/dist/types/src/internal/{proxy → common/proxy}/reactive-array.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/reactive-array.d.ts.map +1 -0
- package/dist/types/src/internal/{proxy → common/proxy}/reactive.d.ts +2 -2
- package/dist/types/src/internal/{proxy → 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 -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.map +1 -0
- package/dist/types/src/internal/{proxy → common/proxy}/typed-handler.d.ts +18 -2
- 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.map +1 -0
- package/dist/types/src/internal/common/proxy/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/{types → common/types}/base.d.ts +1 -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/{types → common/types}/index.d.ts +1 -0
- package/dist/types/src/internal/common/types/index.d.ts.map +1 -0
- package/dist/types/src/internal/{types → common/types}/meta.d.ts +12 -1
- package/dist/types/src/internal/common/types/meta.d.ts.map +1 -0
- package/dist/types/src/internal/common/types/model-symbols.d.ts +58 -0
- package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -0
- package/dist/types/src/internal/{types → common/types}/typename.d.ts +7 -0
- package/dist/types/src/internal/common/types/typename.d.ts.map +1 -0
- package/dist/types/src/internal/{types → common/types}/version.d.ts +2 -2
- package/dist/types/src/internal/common/types/version.d.ts.map +1 -0
- package/dist/types/src/internal/index.d.ts +9 -10
- package/dist/types/src/internal/index.d.ts.map +1 -1
- 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 +77 -82
- 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 +30 -15
- package/src/Annotation.ts +7 -3
- package/src/Collection.ts +36 -0
- package/src/Database.ts +80 -77
- package/src/Dataset.ts +34 -0
- package/src/Entity.test.ts +116 -6
- package/src/Entity.ts +181 -66
- package/src/Err.ts +25 -3
- package/src/Extension.test.ts +235 -0
- package/src/Extension.ts +122 -0
- package/src/Feed.ts +356 -0
- package/src/Filter.test.ts +90 -0
- package/src/Filter.ts +152 -21
- package/src/Format.ts +3 -3
- package/src/Hypergraph.ts +16 -11
- package/src/Json.test.ts +175 -0
- package/src/Json.ts +103 -0
- package/src/JsonSchema.ts +14 -4
- package/src/Key.ts +1 -1
- package/src/Migration.ts +114 -0
- package/src/Obj.test.ts +158 -20
- package/src/Obj.ts +451 -183
- package/src/Order.ts +3 -1
- package/src/Query.test.ts +446 -89
- package/src/Query.ts +300 -35
- package/src/Ref.ts +83 -12
- package/src/Relation.test.ts +16 -10
- package/src/Relation.ts +236 -165
- package/src/SchemaRegistry.ts +13 -17
- package/src/Tag.ts +9 -9
- package/src/Type.test.ts +169 -24
- package/src/Type.ts +561 -354
- package/src/View.ts +101 -0
- package/src/exemplars.test.ts +21 -0
- package/src/index.ts +9 -2
- package/src/internal/Annotation/annotations.test.ts +165 -0
- package/src/internal/{annotations → Annotation}/annotations.ts +181 -101
- package/src/internal/{annotations → Annotation}/index.ts +1 -0
- package/src/internal/{api → Annotation}/sorting.ts +2 -4
- package/src/internal/{annotations → Annotation}/util.ts +17 -9
- package/src/internal/{api/entity.ts → Entity/api.ts} +9 -8
- package/src/internal/Entity/entity.ts +246 -0
- package/src/internal/{entities → Entity}/index.ts +4 -0
- package/src/internal/{entities → Entity}/model.ts +42 -60
- package/src/internal/{entities → Entity}/object.ts +13 -6
- package/src/internal/Entity/relation.ts +179 -0
- package/src/internal/Entity/type-kind.ts +67 -0
- package/src/internal/Entity/type-uri.ts +87 -0
- package/src/internal/Entity/util.ts +34 -0
- package/src/internal/{api → Entity}/version.ts +2 -2
- package/src/internal/{formats → Format}/date.test.ts +1 -2
- package/src/internal/{formats → Format}/date.ts +0 -4
- package/src/internal/{formats → Format}/format.test.ts +1 -2
- package/src/internal/{formats → Format}/index.ts +2 -3
- package/src/internal/{formats → Format}/types.ts +2 -2
- package/src/internal/{json-schema → JsonSchema}/annotations.ts +3 -3
- package/src/internal/{json-schema → JsonSchema}/json-schema-type.ts +4 -4
- package/src/internal/{json-schema → JsonSchema}/json-schema.test.ts +64 -151
- package/src/internal/{json-schema → JsonSchema}/json-schema.ts +47 -28
- package/src/internal/{object → Obj}/clone.ts +10 -6
- package/src/internal/{object → Obj}/common.ts +2 -2
- package/src/internal/{object → Obj}/create-object.test.ts +13 -14
- package/src/internal/Obj/create-object.ts +135 -0
- package/src/internal/{object → Obj}/deleted.ts +2 -2
- package/src/internal/{object → Obj}/index.ts +0 -1
- package/src/internal/{object → Obj}/inspect.ts +3 -3
- package/src/internal/Obj/json-serializer.test.ts +185 -0
- package/src/internal/{object → Obj}/json-serializer.ts +108 -45
- package/src/internal/{object → Obj}/schema-validator.ts +1 -1
- package/src/internal/{object → Obj}/set-value.test.ts +31 -54
- package/src/internal/{object → Obj}/set-value.ts +3 -3
- package/src/internal/{object → Obj}/snapshot.ts +41 -23
- package/src/internal/Obj/typed-object.test.ts +32 -0
- package/src/internal/{object → Obj}/typed-object.ts +5 -5
- package/src/internal/Query.ts +156 -0
- package/src/internal/{ref → Ref}/ref-array.ts +1 -2
- package/src/internal/{ref → Ref}/ref.test.ts +16 -26
- package/src/internal/{ref → Ref}/ref.ts +117 -57
- package/src/internal/{schema → Type}/compose.test.ts +6 -5
- package/src/internal/{schema → Type}/compose.ts +1 -1
- package/src/internal/Type/index.ts +6 -0
- package/src/internal/{schema → Type}/manipulation.ts +0 -25
- package/src/internal/Type/type-schema.ts +60 -0
- package/src/internal/{README.md → common/README.md} +2 -2
- package/src/internal/{api → common/api}/index.ts +0 -4
- package/src/internal/{api → common/api}/meta.ts +3 -3
- package/src/internal/common/index.ts +7 -0
- package/src/internal/{proxy → common/proxy}/change-context.ts +1 -1
- package/src/internal/{proxy → common/proxy}/change.test.ts +97 -97
- package/src/internal/{proxy → common/proxy}/errors.ts +2 -2
- package/src/internal/{proxy → common/proxy}/handler.test.ts +2 -4
- package/src/internal/{proxy → common/proxy}/json-serializer.ts +20 -14
- package/src/internal/{proxy → common/proxy}/make-object.ts +37 -15
- package/src/internal/{proxy → common/proxy}/ownership.ts +0 -1
- package/src/internal/{proxy → common/proxy}/reactive-array.ts +1 -1
- package/src/internal/common/proxy/reactive.test.ts +54 -0
- package/src/internal/{proxy → common/proxy}/reactive.ts +12 -4
- package/src/internal/common/proxy/schema.test.ts +107 -0
- package/src/internal/{proxy → common/proxy}/typed-handler.test.ts +15 -15
- package/src/internal/{proxy → common/proxy}/typed-handler.ts +75 -18
- package/src/internal/{proxy → common/proxy}/typed-object.test.ts +17 -30
- package/src/internal/{types → common/types}/base.ts +1 -1
- package/src/internal/common/types/entity.ts +133 -0
- package/src/internal/{types → common/types}/index.ts +1 -0
- package/src/internal/{types → common/types}/meta.ts +15 -1
- package/src/internal/common/types/model-symbols.ts +74 -0
- package/src/internal/common/types/typename.ts +91 -0
- package/src/internal/{types → common/types}/version.ts +2 -3
- package/src/internal/index.ts +9 -31
- package/src/testing/api.test.ts +15 -12
- package/src/testing/test-data.ts +158 -99
- package/src/testing/test-schema.ts +33 -67
- package/src/testing/util.ts +14 -11
- package/dist/lib/neutral/chunk-2AF5GMG6.mjs +0 -171
- package/dist/lib/neutral/chunk-2AF5GMG6.mjs.map +0 -7
- package/dist/lib/neutral/chunk-4L6DOFXP.mjs.map +0 -7
- package/dist/lib/neutral/chunk-7WE7SBA2.mjs.map +0 -7
- package/dist/lib/neutral/chunk-ANHVGJI4.mjs.map +0 -7
- package/dist/lib/neutral/chunk-DLPC7DHQ.mjs.map +0 -7
- package/dist/lib/neutral/chunk-EBUAT5ID.mjs +0 -229
- package/dist/lib/neutral/chunk-EBUAT5ID.mjs.map +0 -7
- package/dist/lib/neutral/chunk-K5K3Z62A.mjs.map +0 -7
- package/dist/lib/neutral/chunk-KB7RIVLK.mjs.map +0 -7
- package/dist/lib/neutral/chunk-LKFNEFHF.mjs +0 -130
- package/dist/lib/neutral/chunk-LKFNEFHF.mjs.map +0 -7
- package/dist/lib/neutral/chunk-MTEHHY62.mjs.map +0 -7
- package/dist/lib/neutral/chunk-N2QNHMT5.mjs.map +0 -7
- package/dist/lib/neutral/chunk-QARLJVDB.mjs.map +0 -7
- package/dist/lib/neutral/chunk-RIMHNJ3E.mjs.map +0 -7
- package/dist/lib/neutral/chunk-ROKO4RKJ.mjs.map +0 -7
- package/dist/lib/neutral/chunk-RPB6V4BE.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TLGNKUUG.mjs +0 -3905
- package/dist/lib/neutral/chunk-TLGNKUUG.mjs.map +0 -7
- package/dist/lib/neutral/chunk-TQT6WTIJ.mjs +0 -142
- package/dist/lib/neutral/chunk-TQT6WTIJ.mjs.map +0 -7
- package/dist/lib/neutral/chunk-VUQGRDRI.mjs +0 -97
- package/dist/lib/neutral/chunk-VUQGRDRI.mjs.map +0 -7
- package/dist/lib/neutral/chunk-X2MPMYYN.mjs +0 -13
- package/dist/lib/neutral/chunk-X2MPMYYN.mjs.map +0 -7
- package/dist/lib/neutral/chunk-XAJMXQ4H.mjs.map +0 -7
- package/dist/lib/neutral/chunk-ZAHWXGK4.mjs.map +0 -7
- package/dist/types/src/internal/annotations/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/annotations/annotations.test.d.ts.map +0 -1
- package/dist/types/src/internal/annotations/index.d.ts +0 -3
- package/dist/types/src/internal/annotations/index.d.ts.map +0 -1
- package/dist/types/src/internal/annotations/util.d.ts.map +0 -1
- package/dist/types/src/internal/api/annotations.d.ts +0 -23
- package/dist/types/src/internal/api/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/api/entity.d.ts +0 -13
- package/dist/types/src/internal/api/entity.d.ts.map +0 -1
- package/dist/types/src/internal/api/index.d.ts.map +0 -1
- package/dist/types/src/internal/api/meta.d.ts.map +0 -1
- package/dist/types/src/internal/api/sorting.d.ts.map +0 -1
- package/dist/types/src/internal/api/version.d.ts.map +0 -1
- package/dist/types/src/internal/entities/entity.d.ts +0 -20
- package/dist/types/src/internal/entities/entity.d.ts.map +0 -1
- package/dist/types/src/internal/entities/index.d.ts +0 -6
- package/dist/types/src/internal/entities/index.d.ts.map +0 -1
- package/dist/types/src/internal/entities/model.d.ts +0 -79
- package/dist/types/src/internal/entities/model.d.ts.map +0 -1
- package/dist/types/src/internal/entities/object.d.ts.map +0 -1
- package/dist/types/src/internal/entities/relation.d.ts +0 -62
- package/dist/types/src/internal/entities/relation.d.ts.map +0 -1
- package/dist/types/src/internal/entities/util.d.ts.map +0 -1
- package/dist/types/src/internal/formats/date.d.ts.map +0 -1
- package/dist/types/src/internal/formats/date.test.d.ts.map +0 -1
- package/dist/types/src/internal/formats/format.d.ts.map +0 -1
- package/dist/types/src/internal/formats/format.test.d.ts.map +0 -1
- package/dist/types/src/internal/formats/index.d.ts.map +0 -1
- package/dist/types/src/internal/formats/number.d.ts.map +0 -1
- package/dist/types/src/internal/formats/object.d.ts.map +0 -1
- package/dist/types/src/internal/formats/select.d.ts.map +0 -1
- package/dist/types/src/internal/formats/string.d.ts.map +0 -1
- package/dist/types/src/internal/formats/types.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/index.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/json-schema.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/clone.d.ts.map +0 -1
- package/dist/types/src/internal/object/common.d.ts.map +0 -1
- package/dist/types/src/internal/object/create-object.d.ts.map +0 -1
- package/dist/types/src/internal/object/create-object.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/deleted.d.ts.map +0 -1
- package/dist/types/src/internal/object/ids.d.ts +0 -6
- package/dist/types/src/internal/object/ids.d.ts.map +0 -1
- package/dist/types/src/internal/object/index.d.ts.map +0 -1
- package/dist/types/src/internal/object/inspect.d.ts.map +0 -1
- package/dist/types/src/internal/object/json-serializer.d.ts.map +0 -1
- package/dist/types/src/internal/object/json-serializer.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/schema-validator.d.ts +0 -2
- package/dist/types/src/internal/object/schema-validator.d.ts.map +0 -1
- package/dist/types/src/internal/object/schema-validator.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/set-value.d.ts.map +0 -1
- package/dist/types/src/internal/object/set-value.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/snapshot.d.ts.map +0 -1
- package/dist/types/src/internal/object/typed-object.d.ts.map +0 -1
- package/dist/types/src/internal/object/typed-object.test.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/change-context.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/change.test.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/define-hidden-property.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/errors.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/event-batch.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/handler.test.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/index.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/json-serializer.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/make-object.d.ts +0 -14
- package/dist/types/src/internal/proxy/make-object.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/ownership.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/proxy-types.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/proxy-utils.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/reactive-array.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/schema-validator.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/symbols.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +0 -1
- package/dist/types/src/internal/ref/index.d.ts.map +0 -1
- package/dist/types/src/internal/ref/ref-array.d.ts.map +0 -1
- package/dist/types/src/internal/ref/ref.d.ts.map +0 -1
- package/dist/types/src/internal/ref/ref.test.d.ts.map +0 -1
- package/dist/types/src/internal/schema/compose.d.ts.map +0 -1
- package/dist/types/src/internal/schema/compose.test.d.ts.map +0 -1
- package/dist/types/src/internal/schema/echo-schema.d.ts +0 -181
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +0 -1
- package/dist/types/src/internal/schema/index.d.ts +0 -4
- package/dist/types/src/internal/schema/index.d.ts.map +0 -1
- package/dist/types/src/internal/schema/manipulation.d.ts.map +0 -1
- package/dist/types/src/internal/schema/persistent-schema.d.ts +0 -20
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +0 -1
- package/dist/types/src/internal/types/base.d.ts.map +0 -1
- package/dist/types/src/internal/types/entity.d.ts +0 -37
- package/dist/types/src/internal/types/entity.d.ts.map +0 -1
- package/dist/types/src/internal/types/index.d.ts.map +0 -1
- package/dist/types/src/internal/types/meta.d.ts.map +0 -1
- package/dist/types/src/internal/types/typename.d.ts.map +0 -1
- package/dist/types/src/internal/types/version.d.ts.map +0 -1
- package/src/internal/annotations/annotations.test.ts +0 -96
- package/src/internal/api/annotations.ts +0 -60
- package/src/internal/entities/entity.ts +0 -126
- package/src/internal/entities/relation.ts +0 -171
- package/src/internal/entities/util.ts +0 -33
- package/src/internal/object/create-object.ts +0 -95
- package/src/internal/object/ids.ts +0 -12
- package/src/internal/object/json-serializer.test.ts +0 -98
- package/src/internal/object/typed-object.test.ts +0 -34
- package/src/internal/proxy/schema.test.ts +0 -145
- package/src/internal/schema/echo-schema.ts +0 -424
- package/src/internal/schema/index.ts +0 -7
- package/src/internal/schema/persistent-schema.ts +0 -28
- package/src/internal/types/entity.ts +0 -54
- package/src/internal/types/typename.ts +0 -55
- /package/dist/lib/neutral/{chunk-OMUPQMLR.mjs.map → chunk-V72DY6LU.mjs.map} +0 -0
- /package/dist/types/src/internal/{annotations → Annotation}/annotations.test.d.ts +0 -0
- /package/dist/types/src/internal/{entities → Entity}/util.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/date.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/date.test.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/format.test.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/number.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/object.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/select.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/string.d.ts +0 -0
- /package/dist/types/src/internal/{json-schema → JsonSchema}/effect-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{json-schema → JsonSchema}/index.d.ts +0 -0
- /package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema-normalize.d.ts +0 -0
- /package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/clone.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/common.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/create-object.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/inspect.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/json-serializer.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/schema-validator.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/set-value.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/snapshot.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/typed-object.test.d.ts +0 -0
- /package/dist/types/src/internal/{ref → Ref}/index.d.ts +0 -0
- /package/dist/types/src/internal/{ref → Ref}/ref.test.d.ts +0 -0
- /package/dist/types/src/internal/{schema → Type}/compose.test.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/change.test.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/define-hidden-property.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/event-batch.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/handler.test.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/index.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/json-serializer.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/ownership.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/proxy-types.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/proxy-utils.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/schema-validator.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/symbols.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/typed-handler.test.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/typed-object.test.d.ts +0 -0
- /package/src/internal/{formats → Format}/format.ts +0 -0
- /package/src/internal/{formats → Format}/number.ts +0 -0
- /package/src/internal/{formats → Format}/object.ts +0 -0
- /package/src/internal/{formats → Format}/select.ts +0 -0
- /package/src/internal/{formats → Format}/string.ts +0 -0
- /package/src/internal/{json-schema → JsonSchema}/effect-schema.test.ts +0 -0
- /package/src/internal/{json-schema → JsonSchema}/index.ts +0 -0
- /package/src/internal/{json-schema → JsonSchema}/json-schema-normalize.ts +0 -0
- /package/src/internal/{object → Obj}/schema-validator.test.ts +0 -0
- /package/src/internal/{ref → Ref}/index.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/define-hidden-property.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/event-batch.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/index.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/proxy-types.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/proxy-utils.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/schema-validator.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/symbols.ts +0 -0
package/src/Type.ts
CHANGED
|
@@ -2,160 +2,93 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
5
7
|
import * as Schema from 'effect/Schema';
|
|
8
|
+
import type * as Types from 'effect/Types';
|
|
6
9
|
|
|
10
|
+
import { raise } from '@dxos/debug';
|
|
7
11
|
import { type EncodedReference } from '@dxos/echo-protocol';
|
|
8
12
|
import { invariant } from '@dxos/invariant';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import type * as
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type ATTR_RELATION_SOURCE,
|
|
17
|
-
type ATTR_RELATION_TARGET,
|
|
18
|
-
type AnyEntity,
|
|
19
|
-
type AnyProperties,
|
|
20
|
-
EchoObjectSchema,
|
|
21
|
-
EchoRelationSchema,
|
|
22
|
-
type EchoRelationSchemaOptions,
|
|
23
|
-
EchoSchema,
|
|
24
|
-
EntityKind,
|
|
25
|
-
PersistentSchema,
|
|
26
|
-
Ref as Ref$,
|
|
27
|
-
type RefFn,
|
|
28
|
-
type RefSchema,
|
|
29
|
-
SchemaKindId,
|
|
30
|
-
type TypeAnnotation,
|
|
31
|
-
type TypeMeta,
|
|
32
|
-
getSchemaDXN,
|
|
33
|
-
getSchemaTypename,
|
|
34
|
-
getSchemaVersion,
|
|
35
|
-
getTypeAnnotation,
|
|
36
|
-
isMutable as isMutable$,
|
|
37
|
-
toEffectSchema,
|
|
38
|
-
toJsonSchema,
|
|
39
|
-
} from './internal';
|
|
40
|
-
import type * as Relation$ from './Relation';
|
|
41
|
-
|
|
42
|
-
// TODO(burdon): Remove toEffectSchema, toJsonSchema (moved to JsonSchema export).
|
|
43
|
-
export { toEffectSchema, toJsonSchema };
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Returns all properties of an object or relation except for the id and kind.
|
|
47
|
-
*/
|
|
48
|
-
export type Properties<T = any> = Omit<T, 'id' | Entity$.KindId | Relation$.Source | Relation$.Target>;
|
|
13
|
+
import { DXN, EchoURI, type ObjectId, type URI } from '@dxos/keys';
|
|
14
|
+
|
|
15
|
+
import type * as Database from './Database';
|
|
16
|
+
import type * as EntityModule from './Entity';
|
|
17
|
+
import * as internal from './internal';
|
|
18
|
+
import * as typeInternal from './internal/Type';
|
|
19
|
+
import type * as RelationModule from './Relation';
|
|
49
20
|
|
|
50
21
|
//
|
|
51
22
|
// Internal types (not exported)
|
|
52
23
|
//
|
|
53
24
|
|
|
54
25
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
readonly [SchemaKindId]: K;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* JSON-encoded properties for objects.
|
|
26
|
+
* Structural base shared by the three sibling type-entity interfaces
|
|
27
|
+
* ({@link Obj}, {@link Relation}, {@link Type}). NOT exported — callers
|
|
28
|
+
* should constrain on {@link AnyEntity} when they want "any of the three"
|
|
29
|
+
* and on the specific kind interface otherwise.
|
|
64
30
|
*/
|
|
65
|
-
interface
|
|
66
|
-
|
|
67
|
-
|
|
31
|
+
interface BaseTypeEntity<A> {
|
|
32
|
+
/**
|
|
33
|
+
* Entity-kind brand of the type-entity value itself — always `EntityKind.Type`.
|
|
34
|
+
* The kind of instance the type *describes* lives on `[SchemaKindId]`
|
|
35
|
+
* (Object / Relation / Type). Lets `Obj.isObject` / `Relation.isRelation`
|
|
36
|
+
* reject type entities by a single `[KindId]` check.
|
|
37
|
+
*/
|
|
38
|
+
readonly [internal.KindId]: internal.EntityKind.Type;
|
|
68
39
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Object id. Like all ECHO entities, type entities always carry an id —
|
|
42
|
+
* stamped at construction for in-memory (static) declarations and assigned by
|
|
43
|
+
* the database once persisted. The id does NOT determine the entity's URI:
|
|
44
|
+
* static types resolve to their typename DXN, persisted types to `echo:/<id>`
|
|
45
|
+
* (see `getTypeURIFromSpecifier`).
|
|
46
|
+
*/
|
|
47
|
+
readonly id: ObjectId;
|
|
48
|
+
|
|
49
|
+
readonly name?: string;
|
|
50
|
+
// NOTE: `typename` / `version` are intentionally NOT fields on any type-entity
|
|
51
|
+
// interface. Both static and persisted entities carry them in `ObjectMeta`
|
|
52
|
+
// (`key` / `version`); read them via `Type.getTypename(self)` /
|
|
53
|
+
// `Type.getVersion(self)` — never as a direct property.
|
|
54
|
+
readonly jsonSchema: internal.JsonSchemaType;
|
|
55
|
+
readonly [InstancePhantomId]?: A;
|
|
76
56
|
}
|
|
77
57
|
|
|
78
58
|
//
|
|
79
|
-
// Obj
|
|
59
|
+
// Obj — `Type.Type` value for an ECHO object schema.
|
|
80
60
|
//
|
|
81
61
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// assignable with specific object types (e.g., Type.Obj can be assigned to/from Meeting.Meeting).
|
|
85
|
-
// This is needed because operation schemas erase type information.
|
|
86
|
-
// TODO(wittjosiah): Consider alternatives to the `any` intersection hack:
|
|
87
|
-
// - Generic operation schemas that preserve input type in output
|
|
88
|
-
// - Branded types that specific schemas also carry
|
|
89
|
-
// - Accept the limitation and require explicit type narrowing at call sites
|
|
90
|
-
type ObjSchemaType = Schema.Schema<
|
|
91
|
-
any & AnyEntity & Entity$.OfKind<typeof Entity$.Kind.Object> & AnyProperties,
|
|
92
|
-
{ id: string } & AnyProperties
|
|
93
|
-
> &
|
|
94
|
-
EchoSchemaKind<EntityKind.Object> &
|
|
95
|
-
TypeMeta;
|
|
96
|
-
|
|
97
|
-
// Internal schema definition.
|
|
98
|
-
// NOTE: The EchoObjectSchema annotation is required for Type.Ref(Type.Obj) to work.
|
|
99
|
-
// The typename/version only satisfy ECHO schema machinery for reference targets.
|
|
100
|
-
const ObjSchema = Schema.Struct({
|
|
101
|
-
id: Schema.String,
|
|
102
|
-
}).pipe(
|
|
103
|
-
Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),
|
|
104
|
-
EchoObjectSchema({ typename: ANY_OBJECT_TYPENAME, version: ANY_OBJECT_VERSION }),
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Runtime Effect schema for any ECHO object.
|
|
109
|
-
* Use for validation, parsing, or as a reference target for collections.
|
|
110
|
-
*
|
|
111
|
-
* NOTE: `Schema.is(Type.Obj)` does STRUCTURAL validation only (checks for `id` field).
|
|
112
|
-
* Use `Obj.isObject()` for proper ECHO instance type guards that check the KindId brand.
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```ts
|
|
116
|
-
* // Structural type guard (accepts any object with id field)
|
|
117
|
-
* if (Schema.is(Type.Obj)(unknownValue)) { ... }
|
|
62
|
+
/**
|
|
63
|
+
* TypeScript type for an ECHO object type — a `Type.Type<A>` entity.
|
|
118
64
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
65
|
+
* `T` is the instance type produced by `Obj.make(Foo, props)`. `Fields` is
|
|
66
|
+
* retained as a structural hint (the runtime value still carries `.fields`),
|
|
67
|
+
* but consumers should derive instance/encoded types via `Type.InstanceType`.
|
|
121
68
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
// TODO(wittjosiah): Investigate if Schema.filter can validate KindId on ECHO instances.
|
|
129
|
-
// Effect Schema normalizes proxy objects to plain objects before calling filter predicates.
|
|
130
|
-
// Possible approaches: custom Schema.declare, AST manipulation, or upstream contribution.
|
|
131
|
-
export const Obj: ObjSchemaType = Object.assign(ObjSchema, {
|
|
132
|
-
[SchemaKindId]: (ObjSchema as any)[SchemaKindId],
|
|
133
|
-
}) as unknown as ObjSchemaType;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* TypeScript type for an ECHO object schema.
|
|
137
|
-
* `T` is the instance type produced by the schema.
|
|
138
|
-
* `Fields` is the optional struct fields type for introspection.
|
|
69
|
+
* **Not a `Schema.Schema`.** `Foo.ast` / `Schema.Schema.Type<typeof Foo>` /
|
|
70
|
+
* `Schema.extend(Foo)` no longer typecheck — extract the Effect Schema via
|
|
71
|
+
* `Type.getSchema(Foo)` first, or derive instance types via
|
|
72
|
+
* `Type.InstanceType<typeof Foo>`.
|
|
139
73
|
*
|
|
140
74
|
* @example
|
|
141
75
|
* ```ts
|
|
142
|
-
* const
|
|
76
|
+
* const Person = Schema.Struct({
|
|
143
77
|
* name: Schema.String,
|
|
144
|
-
* }).pipe(Type.
|
|
78
|
+
* }).pipe(Type.makeObject(DXN.make('com.example.type.person', '0.1.0')));
|
|
145
79
|
*
|
|
146
|
-
*
|
|
147
|
-
* Object.keys(PersonSchema.fields); // ['name']
|
|
80
|
+
* type Person = Type.InstanceType<typeof Person>;
|
|
148
81
|
* ```
|
|
149
82
|
*/
|
|
150
|
-
export interface Obj<T
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
83
|
+
export interface Obj<T, Fields extends Schema.Struct.Fields = Schema.Struct.Fields> extends BaseTypeEntity<
|
|
84
|
+
T & EntityModule.OfKind<typeof EntityModule.Kind.Object>
|
|
85
|
+
> {
|
|
86
|
+
/** Schema-kind brand (object). */
|
|
87
|
+
readonly [internal.SchemaKindId]: internal.EntityKind.Object;
|
|
88
|
+
|
|
89
|
+
/** Source Effect Schema — used internally by `Type.getSchema(self)`. */
|
|
90
|
+
readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;
|
|
91
|
+
|
|
159
92
|
/**
|
|
160
93
|
* The fields defined in the original struct schema.
|
|
161
94
|
* Allows accessing field definitions for introspection.
|
|
@@ -164,116 +97,148 @@ export interface Obj<T = any, Fields extends Schema.Struct.Fields = Schema.Struc
|
|
|
164
97
|
}
|
|
165
98
|
|
|
166
99
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* NOTE: Does not include the brand symbol to avoid TS4053 declaration portability issues.
|
|
170
|
-
* Use Type.isObjectSchema() for runtime type guards.
|
|
100
|
+
* Type that represents any ECHO object type — a `Type.Type` entity branded
|
|
101
|
+
* with the object entity kind, i.e. what `Type.makeObject(dxn)` produces.
|
|
171
102
|
*/
|
|
172
|
-
type
|
|
173
|
-
readonly typename: string;
|
|
174
|
-
readonly version: string;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
export namespace Obj {
|
|
178
|
-
/**
|
|
179
|
-
* Type that represents any ECHO object schema.
|
|
180
|
-
* Accepts both static schemas (Type.object()) and mutable schemas (EchoSchema).
|
|
181
|
-
*/
|
|
182
|
-
export type Any = ObjectSchemaBase;
|
|
183
|
-
}
|
|
103
|
+
export type AnyObj = Obj<unknown>;
|
|
184
104
|
|
|
185
105
|
/**
|
|
186
|
-
* Factory function to create an ECHO object
|
|
187
|
-
*
|
|
106
|
+
* Factory function to create an ECHO object type.
|
|
107
|
+
*
|
|
108
|
+
* Returns a `Type.Type` entity — a live, in-memory `TypeSchema` instance,
|
|
109
|
+
* NOT a `Schema.Schema`. Use `Type.InstanceType<typeof Foo>` for the instance
|
|
110
|
+
* type and `Type.getSchema(Foo)` to obtain the underlying Effect Schema.
|
|
188
111
|
*
|
|
189
112
|
* @example
|
|
190
113
|
* ```ts
|
|
191
114
|
* const Person = Schema.Struct({
|
|
192
115
|
* name: Schema.String,
|
|
193
|
-
* }).pipe(Type.
|
|
116
|
+
* }).pipe(Type.makeObject(DXN.make('com.example.type.person', '0.1.0')));
|
|
194
117
|
* ```
|
|
195
118
|
*/
|
|
196
|
-
export const
|
|
197
|
-
(
|
|
198
|
-
} = EchoObjectSchema as any;
|
|
119
|
+
export const makeObject: {
|
|
120
|
+
(dxn: DXN.DXN): <Self extends Schema.Schema.Any>(self: Self) => Obj<Schema.Schema.Type<Self>>;
|
|
121
|
+
} = internal.EchoObjectSchema as any;
|
|
199
122
|
|
|
200
123
|
//
|
|
201
|
-
//
|
|
124
|
+
// Type — the ECHO entity that holds a schema and metadata.
|
|
125
|
+
// Persisted via `db.add()`; subscribed to via `Filter.type(Type.Type)`.
|
|
202
126
|
//
|
|
203
127
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
128
|
+
/**
|
|
129
|
+
* ECHO meta-schema entity — stores `{ name?, typename, version, jsonSchema }`.
|
|
130
|
+
* Type-kind sibling of `Type.makeObject(...)` / `Type.makeRelation(...)` outputs.
|
|
131
|
+
* Stored types live under this entity; filter via `Filter.type(Type.Type)`.
|
|
132
|
+
*/
|
|
133
|
+
export const Type: Type<typeInternal.TypeSchema> = typeInternal.TypeSchema as any;
|
|
207
134
|
|
|
208
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Default version stamped on draft (unnamed) types created via
|
|
137
|
+
* {@link makeObjectFromJsonSchema} / {@link makeRelationFromJsonSchema} when
|
|
138
|
+
* the caller does not supply one. Pure dynamic drafts surface as `'0.0.0'`
|
|
139
|
+
* until they are persisted, at which point automerge-heads suffix the version.
|
|
140
|
+
*/
|
|
141
|
+
const DRAFT_VERSION = '0.0.0';
|
|
209
142
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Common props shared by the type-kind factories. Typename and version are
|
|
145
|
+
* optional — drafts omit typename and default version to {@link DRAFT_VERSION}.
|
|
146
|
+
*/
|
|
147
|
+
type MakeTypeProps = {
|
|
148
|
+
jsonSchema: internal.JsonSchemaType;
|
|
149
|
+
typename?: string;
|
|
150
|
+
version?: string;
|
|
151
|
+
name?: string;
|
|
152
|
+
id?: ObjectId;
|
|
153
|
+
};
|
|
213
154
|
|
|
214
|
-
|
|
215
|
-
type
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
EchoSchemaKind<EntityKind.Relation> &
|
|
220
|
-
TypeMeta;
|
|
221
|
-
|
|
222
|
-
// Internal schema definition.
|
|
223
|
-
// NOTE: The EchoRelationSchema annotation is required for Type.Ref(Type.Relation) to work.
|
|
224
|
-
// The typename/version/source/target only satisfy ECHO schema machinery for reference targets.
|
|
225
|
-
const RelationSchema = Schema.Struct({
|
|
226
|
-
id: Schema.String,
|
|
227
|
-
}).pipe(
|
|
228
|
-
Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),
|
|
229
|
-
EchoRelationSchema({
|
|
230
|
-
typename: 'dxos.org/schema/AnyRelation',
|
|
231
|
-
version: '0.0.0',
|
|
232
|
-
source: ObjSchema,
|
|
233
|
-
target: ObjSchema,
|
|
234
|
-
}),
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Runtime Effect schema for any ECHO relation.
|
|
239
|
-
* Use for validation, parsing, or as a reference target for collections.
|
|
240
|
-
* A relation has `id`, source, and target fields plus any additional properties.
|
|
241
|
-
*
|
|
242
|
-
* NOTE: `Schema.is(Type.Relation)` does STRUCTURAL validation only (checks for `id` field).
|
|
243
|
-
* Use `Relation.isRelation()` for proper ECHO instance type guards that check the KindId brand.
|
|
155
|
+
/**
|
|
156
|
+
* Construct a new object-kind type entity from raw metadata — for cases where
|
|
157
|
+
* an Effect Schema isn't available (e.g. JSON-Schema arriving over the network
|
|
158
|
+
* or from a UI editor). Parallel to {@link makeObject} but takes pre-built
|
|
159
|
+
* `jsonSchema` instead of piping through an Effect schema.
|
|
244
160
|
*
|
|
245
|
-
*
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
161
|
+
* The returned entity is in-memory; persist it with `db.add(entity)`.
|
|
162
|
+
*/
|
|
163
|
+
export const makeObjectFromJsonSchema = (props: MakeTypeProps): Type<typeInternal.TypeSchema> => {
|
|
164
|
+
const { typename, version, ...data } = props;
|
|
165
|
+
// `typename` / `version` are routed through `ObjectMeta` (`key` / `version`)
|
|
166
|
+
// — the canonical registry-provenance pair — not data fields. Drafts default
|
|
167
|
+
// to `'0.0.0'`; the version is omitted from meta entirely when the caller
|
|
168
|
+
// doesn't supply one so the proxy projection can apply its own default.
|
|
169
|
+
return internal.makeObject(
|
|
170
|
+
internal.getStaticTypeSchema(typeInternal.TypeSchema) as any,
|
|
171
|
+
data as any,
|
|
172
|
+
{
|
|
173
|
+
keys: [],
|
|
174
|
+
key: typename,
|
|
175
|
+
version: version ?? DRAFT_VERSION,
|
|
176
|
+
},
|
|
177
|
+
typeInternal.TypeSchema,
|
|
178
|
+
) as unknown as Type<typeInternal.TypeSchema>;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Construct a new relation-kind type entity from raw metadata. Parallel to
|
|
183
|
+
* {@link makeRelation} but takes pre-built `jsonSchema` instead of piping
|
|
184
|
+
* through an Effect schema. `source` / `target` accept either a static
|
|
185
|
+
* `Type.Obj` entity or the well-known `Obj.Unknown` schema.
|
|
249
186
|
*
|
|
250
|
-
*
|
|
251
|
-
* if (Relation.isRelation(unknownValue)) { ... }
|
|
252
|
-
* ```
|
|
187
|
+
* The returned entity is in-memory; persist it with `db.add(entity)`.
|
|
253
188
|
*/
|
|
254
|
-
export const
|
|
255
|
-
|
|
256
|
-
|
|
189
|
+
export const makeRelationFromJsonSchema = (
|
|
190
|
+
props: MakeTypeProps & {
|
|
191
|
+
source: AnyObj | internal.UnknownTypeSchema<any, typeof EntityModule.Kind.Object>;
|
|
192
|
+
target: AnyObj | internal.UnknownTypeSchema<any, typeof EntityModule.Kind.Object>;
|
|
193
|
+
},
|
|
194
|
+
): Type<typeInternal.TypeSchema> => {
|
|
195
|
+
const { source, target, jsonSchema, typename, version, ...rest } = props;
|
|
196
|
+
// Embed source/target DXNs + relation entity-kind into the jsonSchema so the
|
|
197
|
+
// entity round-trips correctly through `toEffectSchema` / queries / refs.
|
|
198
|
+
const sourceURI = internal.getTypeURIFromSpecifier(source);
|
|
199
|
+
const targetURI = internal.getTypeURIFromSpecifier(target);
|
|
200
|
+
const enrichedJsonSchema: internal.JsonSchemaType = {
|
|
201
|
+
...jsonSchema,
|
|
202
|
+
entityKind: internal.EntityKind.Relation,
|
|
203
|
+
relationSource: { $ref: sourceURI },
|
|
204
|
+
relationTarget: { $ref: targetURI },
|
|
205
|
+
};
|
|
206
|
+
// `typename` / `version` route through `ObjectMeta` (see
|
|
207
|
+
// {@link makeObjectFromJsonSchema}); drafts default version to `'0.0.0'`.
|
|
208
|
+
return internal.makeObject(
|
|
209
|
+
internal.getStaticTypeSchema(typeInternal.TypeSchema) as any,
|
|
210
|
+
{ ...rest, jsonSchema: enrichedJsonSchema } as any,
|
|
211
|
+
{
|
|
212
|
+
keys: [],
|
|
213
|
+
key: typename,
|
|
214
|
+
version: version ?? DRAFT_VERSION,
|
|
215
|
+
},
|
|
216
|
+
typeInternal.TypeSchema,
|
|
217
|
+
) as unknown as Type<typeInternal.TypeSchema>;
|
|
218
|
+
};
|
|
257
219
|
|
|
258
220
|
/**
|
|
259
|
-
* TypeScript type for an ECHO relation
|
|
260
|
-
*
|
|
261
|
-
* `
|
|
262
|
-
* `
|
|
221
|
+
* TypeScript type for an ECHO relation type — a `Type.Type<A>` entity.
|
|
222
|
+
*
|
|
223
|
+
* `T` is the instance-property type produced by `Relation.make(...)` (excluding
|
|
224
|
+
* source/target endpoints). `Source` and `Target` are the endpoint types.
|
|
225
|
+
*
|
|
226
|
+
* **Not a `Schema.Schema`.** See {@link Obj}'s note.
|
|
263
227
|
*/
|
|
264
228
|
export interface Relation<
|
|
265
|
-
T
|
|
266
|
-
Source
|
|
267
|
-
Target
|
|
229
|
+
T,
|
|
230
|
+
Source,
|
|
231
|
+
Target,
|
|
268
232
|
Fields extends Schema.Struct.Fields = Schema.Struct.Fields,
|
|
269
|
-
> extends
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
233
|
+
> extends BaseTypeEntity<
|
|
234
|
+
RelationModule.Endpoints<Source, Target> & T & EntityModule.OfKind<typeof EntityModule.Kind.Relation>
|
|
235
|
+
> {
|
|
236
|
+
/** Schema-kind brand (relation). */
|
|
237
|
+
readonly [internal.SchemaKindId]: internal.EntityKind.Relation;
|
|
238
|
+
|
|
239
|
+
/** Source Effect Schema — used internally by `Type.getSchema(self)`. */
|
|
240
|
+
readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;
|
|
241
|
+
|
|
277
242
|
/**
|
|
278
243
|
* The fields defined in the original struct schema.
|
|
279
244
|
* Allows accessing field definitions for introspection.
|
|
@@ -282,38 +247,10 @@ export interface Relation<
|
|
|
282
247
|
}
|
|
283
248
|
|
|
284
249
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
* NOTE: Does not include the brand symbol to avoid TS4053 declaration portability issues.
|
|
288
|
-
* Use Type.isRelationSchema() for runtime type guards.
|
|
250
|
+
* Type that represents any ECHO relation type — a `Type.Type` entity branded
|
|
251
|
+
* with the relation entity kind, i.e. what `Type.makeRelation(...)` produces.
|
|
289
252
|
*/
|
|
290
|
-
type
|
|
291
|
-
readonly typename: string;
|
|
292
|
-
readonly version: string;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
export namespace Relation {
|
|
296
|
-
/**
|
|
297
|
-
* Type that represents any ECHO relation schema.
|
|
298
|
-
* Accepts static schemas (Type.relation()).
|
|
299
|
-
*/
|
|
300
|
-
export type Any = RelationSchemaBase;
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Get relation source type.
|
|
304
|
-
*/
|
|
305
|
-
export type Source<A> = A extends Relation.Endpoints<infer S, infer _T> ? S : never;
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Get relation target type.
|
|
309
|
-
*/
|
|
310
|
-
export type Target<A> = A extends Relation.Endpoints<infer _S, infer T> ? T : never;
|
|
311
|
-
|
|
312
|
-
export type Endpoints<Source, Target> = {
|
|
313
|
-
[Relation$.Source]: Source;
|
|
314
|
-
[Relation$.Target]: Target;
|
|
315
|
-
};
|
|
316
|
-
}
|
|
253
|
+
export type AnyRelation = Relation<unknown, unknown, unknown>;
|
|
317
254
|
|
|
318
255
|
/**
|
|
319
256
|
* Factory function to create an ECHO relation schema.
|
|
@@ -323,170 +260,440 @@ export namespace Relation {
|
|
|
323
260
|
* ```ts
|
|
324
261
|
* const WorksFor = Schema.Struct({
|
|
325
262
|
* role: Schema.String,
|
|
326
|
-
* }).pipe(Type.
|
|
327
|
-
*
|
|
328
|
-
* version: '0.1.0',
|
|
263
|
+
* }).pipe(Type.makeRelation({
|
|
264
|
+
* dxn: DXN.make('com.example.type.worksFor', '0.1.0'),
|
|
329
265
|
* source: Person,
|
|
330
266
|
* target: Company,
|
|
331
267
|
* }));
|
|
332
268
|
* ```
|
|
333
269
|
*/
|
|
334
|
-
export const
|
|
335
|
-
<
|
|
336
|
-
|
|
337
|
-
|
|
270
|
+
export const makeRelation: {
|
|
271
|
+
<SourceInstance, TargetInstance>(opts: {
|
|
272
|
+
dxn: DXN.DXN;
|
|
273
|
+
source: Obj<SourceInstance, any> | internal.UnknownTypeSchema<SourceInstance, typeof EntityModule.Kind.Object>;
|
|
274
|
+
target: Obj<TargetInstance, any> | internal.UnknownTypeSchema<TargetInstance, typeof EntityModule.Kind.Object>;
|
|
275
|
+
}): <Self extends Schema.Schema.Any>(
|
|
338
276
|
self: Self,
|
|
339
|
-
) => Relation<
|
|
340
|
-
|
|
277
|
+
) => Relation<
|
|
278
|
+
Schema.Schema.Type<Self>,
|
|
279
|
+
SourceInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>,
|
|
280
|
+
TargetInstance & EntityModule.OfKind<typeof EntityModule.Kind.Object>
|
|
281
|
+
>;
|
|
282
|
+
} = internal.EchoRelationSchema as any;
|
|
341
283
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
284
|
+
/**
|
|
285
|
+
* Type that represents any ECHO type-kind entity — a `Type.Type` meta-schema
|
|
286
|
+
* value (static `Type.Type` or a persisted draft from `db.add(...)`).
|
|
287
|
+
* Mirrors {@link AnyObj} / {@link AnyRelation} for the third sibling kind.
|
|
288
|
+
*/
|
|
289
|
+
export type AnyType = Type<unknown>;
|
|
345
290
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
* ```ts
|
|
353
|
-
* if (Schema.is(Type.Entity.Any)(unknownValue)) {
|
|
354
|
-
* // unknownValue is an ECHO entity
|
|
355
|
-
* }
|
|
356
|
-
* ```
|
|
357
|
-
*/
|
|
358
|
-
export const Any: Schema.Schema<
|
|
359
|
-
{ id: ObjectId } & Record<string, unknown>,
|
|
360
|
-
{ id: string } & Record<string, unknown>
|
|
361
|
-
> = Schema.Union(Obj, Relation);
|
|
291
|
+
/**
|
|
292
|
+
* Any ECHO type-entity — one of the three sibling kinds: object-kind, relation-kind,
|
|
293
|
+
* or type-kind (the meta-schema). APIs that want "any ECHO type" use this union;
|
|
294
|
+
* the underlying Effect Schema is retrieved via `Type.getSchema`.
|
|
295
|
+
*/
|
|
296
|
+
export type AnyEntity = AnyObj | AnyRelation | AnyType;
|
|
362
297
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
298
|
+
/**
|
|
299
|
+
* Type guard: narrows a `Type.AnyEntity` to an object-kind entity. Checks
|
|
300
|
+
* ENTITIES, not instances — use `Obj.isObject` for instances. Raw
|
|
301
|
+
* `Schema.Schema` values (including the branded `Obj.Unknown` companion)
|
|
302
|
+
* are intentionally not accepted; inspect their `TypeAnnotation` directly.
|
|
303
|
+
*/
|
|
304
|
+
export const isObject = (entity: AnyEntity): entity is AnyObj => {
|
|
305
|
+
return internal.getSchemaKind(entity) === internal.EntityKind.Object;
|
|
306
|
+
};
|
|
369
307
|
|
|
370
308
|
/**
|
|
371
|
-
* Type guard
|
|
372
|
-
*
|
|
309
|
+
* Type guard: narrows a `Type.AnyEntity` to a relation-kind entity. Checks
|
|
310
|
+
* ENTITIES, not instances — use `Relation.isRelation` for instances.
|
|
373
311
|
*/
|
|
374
|
-
export const
|
|
375
|
-
return (
|
|
312
|
+
export const isRelation = (entity: AnyEntity): entity is AnyRelation => {
|
|
313
|
+
return internal.getSchemaKind(entity) === internal.EntityKind.Relation;
|
|
376
314
|
};
|
|
377
315
|
|
|
378
316
|
/**
|
|
379
|
-
* Type guard
|
|
380
|
-
*
|
|
317
|
+
* Type guard: narrows a `Type.AnyEntity` to the type-kind meta-schema
|
|
318
|
+
* (e.g. `Type.Type`). Mirrors {@link isObject} / {@link isRelation}.
|
|
381
319
|
*/
|
|
382
|
-
export const
|
|
383
|
-
return (
|
|
320
|
+
export const isTypeKindSchema = (entity: AnyEntity): entity is Type => {
|
|
321
|
+
return internal.getSchemaKind(entity) === internal.EntityKind.Type;
|
|
384
322
|
};
|
|
385
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Narrow a `Type.AnyEntity` (e.g. one returned from `schemaRegistry.query(...)`)
|
|
326
|
+
* to `AnyObj`, throwing if it describes a relation or the type-kind
|
|
327
|
+
* meta-schema. Use at call sites that need to pass the value to `Obj.make`,
|
|
328
|
+
* `Filter.type`, or other object-only APIs.
|
|
329
|
+
*/
|
|
330
|
+
export const assertObject = (entity: AnyEntity): AnyObj => {
|
|
331
|
+
invariant(isObject(entity), 'Expected an object-kind Type entity.');
|
|
332
|
+
return entity;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
/** Narrow a `Type.AnyEntity` to `AnyRelation`, throwing otherwise. */
|
|
336
|
+
export const expectRelation = (entity: AnyEntity): AnyRelation => {
|
|
337
|
+
invariant(isRelation(entity), 'Expected a relation-kind Type entity.');
|
|
338
|
+
return entity;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
/** Narrow a `Type.AnyEntity` to the `Type.Type` meta-schema, throwing otherwise. */
|
|
342
|
+
export const expectTypeKind = (entity: AnyEntity): Type => {
|
|
343
|
+
invariant(isTypeKindSchema(entity), 'Expected a type-kind Type entity.');
|
|
344
|
+
return entity;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Type that represents any Ref schema (with unknown target type).
|
|
349
|
+
* This is a schema type, not an instance type.
|
|
350
|
+
*/
|
|
351
|
+
export type AnyRef = Schema.Schema<internal.Ref<any>, EncodedReference>;
|
|
352
|
+
|
|
386
353
|
//
|
|
387
|
-
//
|
|
388
|
-
//
|
|
389
|
-
// NOTE: `Type.Ref` vs `Ref.Ref`:
|
|
390
|
-
// - `Type.Ref<T>` is the SCHEMA type - a schema that produces `Ref.Ref<T>` instances.
|
|
391
|
-
// - `Ref.Ref<T>` is the INSTANCE type - the actual runtime ref object.
|
|
392
|
-
//
|
|
393
|
-
// Example:
|
|
394
|
-
// const taskRef: Ref.Ref<Task> = Ref.make(task); // Instance
|
|
395
|
-
// const schema: Type.Ref<Task> = Type.Ref(Task); // Schema
|
|
354
|
+
// Schema utility functions
|
|
396
355
|
//
|
|
397
356
|
|
|
398
357
|
/**
|
|
399
|
-
*
|
|
358
|
+
* Returns the URI identifying a type entity. Always defined.
|
|
359
|
+
*
|
|
360
|
+
* - Static `Type.Obj` / `Type.Relation` → typename DXN (e.g. `dxn:com.example.type.person:0.1.0`).
|
|
361
|
+
* - Persisted `Type.Type` instance (has `id`) → local `EchoURI` (`echo:/<objectId>`).
|
|
362
|
+
* - In-memory `Type.Type` draft (has `id`, no typename) → local `EchoURI`.
|
|
400
363
|
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
364
|
+
* Only accepts `Type.AnyEntity` entities. Raw `Schema.Schema` values and the
|
|
365
|
+
* branded `Obj.Unknown` / `Relation.Unknown` schemas are intentionally not
|
|
366
|
+
* supported — use `internal.getSchemaURI` or the schema's typename annotation
|
|
367
|
+
* directly when working at the schema level.
|
|
403
368
|
*/
|
|
404
|
-
export
|
|
369
|
+
export const getURI = (input: AnyEntity): URI.URI => {
|
|
370
|
+
// For Type entities, route through `getTypeURIFromSpecifier` (id → EchoURI,
|
|
371
|
+
// typename/version → DXN). For Obj/Relation entities, unwrap to the source
|
|
372
|
+
// Effect Schema first and read its annotations.
|
|
373
|
+
if (isType(input)) {
|
|
374
|
+
return internal.getTypeURIFromSpecifier(input);
|
|
375
|
+
}
|
|
376
|
+
return internal.getSchemaURI(getSchema(input)) ?? raise(new TypeError('Type entity has no URI'));
|
|
377
|
+
};
|
|
405
378
|
|
|
406
379
|
/**
|
|
407
|
-
*
|
|
408
|
-
* Use this in schema definitions to declare reference fields.
|
|
380
|
+
* @returns The typename. Example: `com.example.type.person`.
|
|
409
381
|
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
* }).pipe(Type.object({ typename: 'Task', version: '0.1.0' }));
|
|
415
|
-
* ```
|
|
382
|
+
* Persisted `Type.Type` entities carry typename in `ObjectMeta.key` (the
|
|
383
|
+
* canonical registry-provenance field); unnamed drafts fall back to the
|
|
384
|
+
* entity's object id so the helper always returns a string. Any `dxn:` or
|
|
385
|
+
* `echo:/` prefix is stripped — typename is a bare identifier, not a URI.
|
|
416
386
|
*/
|
|
417
|
-
|
|
387
|
+
// TODO(wittjosiah): For in-database types this should return the object id once the registry
|
|
388
|
+
// has more robust options for shadowing types (so callers can disambiguate db-stored copies).
|
|
389
|
+
export const getTypename = (input: AnyEntity): string => {
|
|
390
|
+
// Both in-memory and in-database entities carry typename in `ObjectMeta.key`
|
|
391
|
+
// — the canonical registry-provenance field. In-memory entities attach meta
|
|
392
|
+
// eagerly (see `makeEchoTypeSchema`), so a single meta-backed read covers
|
|
393
|
+
// both forms. Unnamed drafts fall back to the entity id.
|
|
394
|
+
const meta = internal.getMetaChecked(input);
|
|
395
|
+
let typename: string = (meta.key as string | undefined) ?? (input.id as string);
|
|
396
|
+
// Typename is a bare identifier — strip URI prefixes if a caller seeded
|
|
397
|
+
// meta.key with one accidentally (or if a static entity carries a DXN-
|
|
398
|
+
// style typename).
|
|
399
|
+
typename = stripTypenamePrefix(typename);
|
|
400
|
+
invariant(typeof typename === 'string' && typename.length > 0, 'Invalid typename');
|
|
401
|
+
return typename;
|
|
402
|
+
};
|
|
418
403
|
|
|
419
404
|
/**
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
405
|
+
* Gets the version.
|
|
406
|
+
* @example 0.1.0
|
|
407
|
+
* @example 0.1.0-<heads> (in-database, versioned by automerge heads)
|
|
423
408
|
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
409
|
+
* The registry-provenance semver lives in `ObjectMeta.version`; unversioned
|
|
410
|
+
* drafts default to {@link DRAFT_VERSION} (`'0.0.0'`). In-database entities are
|
|
411
|
+
* additionally versioned by their automerge heads, which are exposed as the
|
|
412
|
+
* semver pre-release tag (`<semver>-<heads>`). In-memory declarations have no
|
|
413
|
+
* heads and surface the bare semver. Read the registry semver alone via
|
|
414
|
+
* `Type.getMeta(input).version`.
|
|
415
|
+
*/
|
|
416
|
+
export const getVersion = (input: AnyEntity): string => {
|
|
417
|
+
const meta = internal.getMetaChecked(input);
|
|
418
|
+
const semver = (meta.version as string | undefined) ?? DRAFT_VERSION;
|
|
419
|
+
invariant(typeof semver === 'string' && semver.match(/^\d+\.\d+\.\d+$/), 'Invalid version');
|
|
420
|
+
// In-database entities are versioned by their automerge heads; expose them as
|
|
421
|
+
// the semver pre-release tag. In-memory drafts carry no heads → bare semver.
|
|
422
|
+
const heads = internal.version(input).automergeHeads;
|
|
423
|
+
if (heads != null && heads.length > 0) {
|
|
424
|
+
return `${semver}-${[...heads].sort().join('.')}`;
|
|
425
|
+
}
|
|
426
|
+
return semver;
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Strip URI prefixes (`dxn:`, `echo:/`, `echo://`) from a typename string.
|
|
431
|
+
* Typename is a bare identifier — callers reading from meta or from a
|
|
432
|
+
* caller-supplied seed value shouldn't propagate URI prefixes downstream.
|
|
433
|
+
*/
|
|
434
|
+
const stripTypenamePrefix = (value: string): string => {
|
|
435
|
+
if (value.startsWith('dxn:')) {
|
|
436
|
+
return value.slice('dxn:'.length);
|
|
437
|
+
}
|
|
438
|
+
if (value.startsWith('echo://')) {
|
|
439
|
+
return value.slice('echo://'.length);
|
|
440
|
+
}
|
|
441
|
+
if (value.startsWith('echo:/')) {
|
|
442
|
+
return value.slice('echo:/'.length);
|
|
443
|
+
}
|
|
444
|
+
return value;
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Type predicate: true iff the value is any type-kind ECHO entity — a static
|
|
449
|
+
* `Type.Obj` / `Type.Relation` produced by `Type.makeObject` / `Type.makeRelation`, a
|
|
450
|
+
* static meta `Type.Type`, or a persisted `Type.Type` returned by the database.
|
|
428
451
|
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
452
|
+
* All three branches stamp `[KindId] = Type`, so this is a single brand check.
|
|
453
|
+
* Use {@link isObject} / {@link isRelation} / {@link isTypeKindSchema}
|
|
454
|
+
* when you need to discriminate further; use {@link getDatabase} when you mean
|
|
455
|
+
* "is this a db-attached type" (vs. an in-memory declaration).
|
|
432
456
|
*/
|
|
433
|
-
export
|
|
457
|
+
export const isType = (value: unknown): value is AnyEntity =>
|
|
458
|
+
internal.getEntityKindBrand(value) === internal.EntityKind.Type;
|
|
434
459
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
460
|
+
/**
|
|
461
|
+
* Get the database the type entity belongs to, or `undefined` if it is an
|
|
462
|
+
* in-memory declaration (`Type.makeObject` / `Type.makeRelation` result) not
|
|
463
|
+
* yet attached to a database. Mirrors `Obj.getDatabase` / `Relation.getDatabase`.
|
|
464
|
+
*
|
|
465
|
+
* Database attachment is the canonical discriminator between in-memory and
|
|
466
|
+
* in-database type entities — both are live reactive `TypeSchema` instances and
|
|
467
|
+
* are otherwise indistinguishable.
|
|
468
|
+
*/
|
|
469
|
+
export const getDatabase = (input: AnyEntity): Database.Database | undefined => internal.getDatabase(input);
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Mutable meta type returned by `Type.getMeta` inside a `Type.update` callback.
|
|
473
|
+
* Mirrors `Obj.Meta` / `Relation.Meta` — `Type.Type` is an Entity like its
|
|
474
|
+
* siblings, so its meta is the same `ObjectMeta` record:
|
|
475
|
+
* `{ keys, tags?, key?, version? }`.
|
|
476
|
+
*
|
|
477
|
+
* `key` / `version` here are the canonical registry-provenance pair
|
|
478
|
+
* (typename + semver) on persisted Type.Type entities; they are absent on
|
|
479
|
+
* unnamed drafts. Use {@link getTypename} / {@link getVersion} when you want
|
|
480
|
+
* a non-`undefined` value with id / {@link DRAFT_VERSION} fallbacks.
|
|
481
|
+
*/
|
|
482
|
+
export type Meta = internal.Meta;
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Deeply read-only version of {@link Meta}.
|
|
486
|
+
* Prevents mutation at all nesting levels (e.g., `meta.keys.push()` is a TS error).
|
|
487
|
+
*/
|
|
488
|
+
export type ReadonlyMeta = internal.ReadonlyMeta;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Returns the entity's `ObjectMeta`. Same semantics as `Obj.getMeta` /
|
|
492
|
+
* `Relation.getMeta` — `Type.Type` is an Entity and carries the canonical
|
|
493
|
+
* `ObjectMeta` directly. Returns mutable meta when passed a mutable type
|
|
494
|
+
* (inside a `Type.update` callback), read-only meta otherwise.
|
|
495
|
+
*
|
|
496
|
+
* For persisted Type entities, `meta.key` holds the typename and
|
|
497
|
+
* `meta.version` holds the semver. Use {@link getTypename} / {@link getVersion}
|
|
498
|
+
* if you want the helpers' id / {@link DRAFT_VERSION} fallbacks for drafts.
|
|
499
|
+
*
|
|
500
|
+
* Both persisted and in-memory type entities (`Type.makeObject` /
|
|
501
|
+
* `Type.makeRelation` results) carry their `ObjectMeta` via `[MetaId]`, so the
|
|
502
|
+
* lookup is uniform.
|
|
503
|
+
*/
|
|
504
|
+
export function getMeta(entity: internal.Mutable<AnyEntity>): Meta;
|
|
505
|
+
export function getMeta(entity: Mutable): Meta;
|
|
506
|
+
export function getMeta(entity: AnyEntity): ReadonlyMeta;
|
|
507
|
+
export function getMeta(entity: AnyEntity | internal.Mutable<AnyEntity> | Mutable): ReadonlyMeta | Meta {
|
|
508
|
+
// The `Mutable` overload accepts the narrowed view passed to `Type.update`
|
|
509
|
+
// callbacks; at runtime that draft IS the underlying persisted Type entity,
|
|
510
|
+
// so the same `MetaId` lookup works.
|
|
511
|
+
invariant(isType(entity), 'Expected a Type entity.');
|
|
512
|
+
// Both persisted and in-memory type entities carry runtime `ObjectMeta` via
|
|
513
|
+
// `[MetaId]`, so the lookup is uniform.
|
|
514
|
+
return internal.getMetaChecked(entity);
|
|
441
515
|
}
|
|
442
516
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
517
|
+
/**
|
|
518
|
+
* String key used to phantom-carry the instance type produced by a `Type.Type`.
|
|
519
|
+
* Used by `Type.InstanceType<typeof Foo>` to recover the schema instance type
|
|
520
|
+
* since `Type.makeObject(dxn)` does not return a `Schema.Schema`.
|
|
521
|
+
*
|
|
522
|
+
* Re-exported from the internal types layer so both `Type.ts` and internal
|
|
523
|
+
* helpers (`makeObject`, `createObject`) reference the same phantom key.
|
|
524
|
+
*/
|
|
525
|
+
export const InstancePhantomId = internal.InstancePhantomId;
|
|
526
|
+
export type InstancePhantomId = internal.InstancePhantomId;
|
|
446
527
|
|
|
447
528
|
/**
|
|
448
|
-
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
529
|
+
* Sibling of {@link Obj} / {@link Relation} for the third ECHO entity kind:
|
|
530
|
+
* **type-kind** entities (meta-schemas). The singleton {@link Type} const is
|
|
531
|
+
* the canonical example — it describes stored type definitions themselves.
|
|
532
|
+
*
|
|
533
|
+
* Not a `Schema.Schema`. Use `Type.getSchema(value)` to obtain the underlying
|
|
534
|
+
* Effect Schema and `Type.update(value, draft => ...)` to mutate.
|
|
535
|
+
*
|
|
536
|
+
* `A` is the instance-type phantom — what `Obj.make(value, ...)` would produce.
|
|
537
|
+
* Merged with the `Type` const value via TypeScript declaration merging.
|
|
452
538
|
*/
|
|
453
|
-
export
|
|
454
|
-
|
|
455
|
-
|
|
539
|
+
export interface Type<A = unknown> extends BaseTypeEntity<A & EntityModule.OfKind<typeof EntityModule.Kind.Type>> {
|
|
540
|
+
/** Schema-kind brand (type — the meta-schema kind). */
|
|
541
|
+
readonly [internal.SchemaKindId]: internal.EntityKind.Type;
|
|
542
|
+
|
|
543
|
+
/** Source Effect Schema — used internally by `Type.getSchema(self)`. */
|
|
544
|
+
readonly [internal.StaticTypeSchemaSlot]: Schema.Schema.AnyNoContext;
|
|
545
|
+
}
|
|
456
546
|
|
|
457
547
|
/**
|
|
458
|
-
*
|
|
459
|
-
*
|
|
548
|
+
* Instance type produced by a Type entity.
|
|
549
|
+
*
|
|
550
|
+
* Accepts ONLY {@link AnyEntity} inputs — `Type.Obj`, `Type.Relation`, or
|
|
551
|
+
* `Type.Type`. Raw Effect `Schema.Schema` values are rejected: for those, use
|
|
552
|
+
* `Schema.Schema.Type<typeof Foo>` directly. This separation keeps the type
|
|
553
|
+
* system honest about which values represent ECHO entities versus plain
|
|
554
|
+
* Effect schemas.
|
|
555
|
+
*
|
|
556
|
+
* Dispatches on the entity kind:
|
|
557
|
+
* - `Relation<Props, S, T>` → `Endpoints<S,T> & Props & OfKind<Relation>`
|
|
558
|
+
* - `Obj<A>` → `A & OfKind<Object>`
|
|
559
|
+
* - `Type<A>` → `A & OfKind<Type>`
|
|
460
560
|
*/
|
|
461
|
-
export
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
561
|
+
export type InstanceType<T extends AnyEntity> =
|
|
562
|
+
T extends Relation<infer Props, infer Source, infer Target, any>
|
|
563
|
+
? RelationModule.Endpoints<Source, Target> & Props & EntityModule.OfKind<typeof EntityModule.Kind.Relation>
|
|
564
|
+
: T extends Obj<infer A, any>
|
|
565
|
+
? A & EntityModule.OfKind<typeof EntityModule.Kind.Object>
|
|
566
|
+
: T extends Type<infer A>
|
|
567
|
+
? A & EntityModule.OfKind<typeof EntityModule.Kind.Type>
|
|
568
|
+
: never;
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Returns the Effect Schema for a type entity.
|
|
572
|
+
*
|
|
573
|
+
* - For static `Type.Obj` / `Type.Relation` entities the source Effect Schema is
|
|
574
|
+
* read from a hidden slot — these overloads preserve the instance type.
|
|
575
|
+
* - For `Type.Type` entities (the meta-schema kind) the schema is rebuilt from
|
|
576
|
+
* `type.jsonSchema`; the instance type isn't statically knowable so the wide
|
|
577
|
+
* `AnyEntity` overload widens to `Schema.Schema.AnyNoContext`.
|
|
578
|
+
*
|
|
579
|
+
* Always call this when you need to interact with the Effect Schema API
|
|
580
|
+
* (e.g. before passing to Effect.Schema functions). For ECHO-side APIs
|
|
581
|
+
* (`Obj.make`, `Filter.type`, `Ref`) pass the type entity directly.
|
|
582
|
+
*
|
|
583
|
+
* Only accepts `Type.AnyEntity` — raw `Schema.Schema` values can be used
|
|
584
|
+
* directly without unwrapping.
|
|
585
|
+
*/
|
|
586
|
+
export function getSchema<T extends AnyObj>(type: T): Schema.Schema<InstanceType<T>>;
|
|
587
|
+
export function getSchema<T extends AnyRelation>(type: T): Schema.Schema<InstanceType<T>>;
|
|
588
|
+
export function getSchema(type: AnyEntity): Schema.Schema.AnyNoContext;
|
|
589
|
+
export function getSchema(type: AnyEntity): Schema.Schema.AnyNoContext {
|
|
590
|
+
// Static `Type.Type` entities carry the source Effect Schema on a hidden
|
|
591
|
+
// slot so we can return it without round-tripping through JsonSchema.
|
|
592
|
+
const staticSchema = internal.getStaticTypeSchema(type);
|
|
593
|
+
if (staticSchema != null) {
|
|
594
|
+
return staticSchema;
|
|
595
|
+
}
|
|
596
|
+
invariant(isType(type), 'Expected a Type entity.');
|
|
597
|
+
// Persisted `Type.Type` entity — build the Effect Schema from its stored
|
|
598
|
+
// jsonSchema and re-attach the TypeIdentifierAnnotation so the rebuilt
|
|
599
|
+
// schema's URI (via getSchemaURI) matches the entity's local EchoURI.
|
|
600
|
+
const rebuilt = internal.toEffectSchema(type.jsonSchema);
|
|
601
|
+
if (typeof type.id === 'string') {
|
|
602
|
+
return rebuilt.annotations({
|
|
603
|
+
[internal.TypeIdentifierAnnotationId]: EchoURI.make({ objectId: type.id }),
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
return rebuilt;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Mutable view of a `Type.Type` — the shape passed to the `Type.update` callback.
|
|
611
|
+
* Outside `Type.update`, `Type.Type` fields are read-only (both at the type level
|
|
612
|
+
* and at runtime — direct assignment throws). Use this to constrain mutation to
|
|
613
|
+
* the change context, analogous to `Obj.update(obj, (draft) => ...)`.
|
|
614
|
+
*
|
|
615
|
+
* NOTE: `typename` and `version` are intentionally absent — they live in
|
|
616
|
+
* `ObjectMeta` (`key` / `version` — the canonical registry-provenance pair).
|
|
617
|
+
* Read them via {@link getTypename} / {@link getVersion} / {@link getMeta};
|
|
618
|
+
* `typename` is treated as immutable on persisted entities.
|
|
619
|
+
*
|
|
620
|
+
* Unlike `Obj.update` — whose mutable view is inferred as `Mutable<A>` over the
|
|
621
|
+
* whole instance type because every data field is editable — a `Type.Type`
|
|
622
|
+
* exposes only `name` and `jsonSchema` for mutation. The rest of its shape
|
|
623
|
+
* (`id`, the `[KindId]` / `[SchemaKindId]` brands, and `typename` / `version`
|
|
624
|
+
* in meta) is immutable, so this view is declared explicitly rather than
|
|
625
|
+
* derived from `InstanceType<Type.Type>`.
|
|
626
|
+
*/
|
|
627
|
+
export interface Mutable {
|
|
628
|
+
name?: string;
|
|
629
|
+
// Deep-mutable within the change context — `Type.update`'s purpose is to allow
|
|
630
|
+
// mutation, so the draft exposes `jsonSchema` as writable (the readonly
|
|
631
|
+
// `JsonSchemaType` would force callers to cast).
|
|
632
|
+
jsonSchema: Types.DeepMutable<internal.JsonSchemaType>;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Perform mutations on a `Type.Type` within a change context.
|
|
637
|
+
*
|
|
638
|
+
* The callback receives a {@link Mutable} view of the type — direct mutation of
|
|
639
|
+
* a `Type.Type` outside `Type.update` throws at runtime, mirroring `Obj.update`.
|
|
640
|
+
* Delegates to the same automerge-transaction primitive `Obj.update(obj, cb)` uses.
|
|
641
|
+
*/
|
|
642
|
+
export const update = (type: AnyEntity, callback: (mutable: Mutable) => void): void => {
|
|
643
|
+
// `Type.Type` is an ECHO object; the change machinery is the same as `Obj.update`.
|
|
644
|
+
internal.change(type, callback as internal.ChangeCallback<AnyEntity>);
|
|
465
645
|
};
|
|
466
646
|
|
|
647
|
+
//
|
|
648
|
+
// Field-level helpers for mutating persisted types.
|
|
649
|
+
// These are thin wrappers over `Type.update` plus the JsonSchema manipulation
|
|
650
|
+
// utilities. Callers pass a persisted `Type.Type` (e.g. one returned by
|
|
651
|
+
// `DatabaseSchemaRegistry.register`) and the helper drives the change context.
|
|
652
|
+
//
|
|
653
|
+
|
|
467
654
|
/**
|
|
468
|
-
*
|
|
469
|
-
* @
|
|
655
|
+
* Add fields to a persisted type's schema.
|
|
656
|
+
* @throws if the type is not persisted.
|
|
470
657
|
*/
|
|
471
|
-
export const
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
658
|
+
export const addFields = (type: AnyEntity, fields: Schema.Struct.Fields): void => {
|
|
659
|
+
const extended = typeInternal.addFieldsToSchema(getSchema(type), fields);
|
|
660
|
+
update(type, (draft) => {
|
|
661
|
+
draft.jsonSchema = internal.toJsonSchema(extended);
|
|
662
|
+
});
|
|
475
663
|
};
|
|
476
664
|
|
|
477
665
|
/**
|
|
478
|
-
*
|
|
666
|
+
* Replace existing fields on a persisted type's schema.
|
|
667
|
+
* @throws if the type is not persisted.
|
|
479
668
|
*/
|
|
480
|
-
export const
|
|
669
|
+
export const updateFields = (type: AnyEntity, fields: Schema.Struct.Fields): void => {
|
|
670
|
+
const updated = typeInternal.updateFieldsInSchema(getSchema(type), fields);
|
|
671
|
+
update(type, (draft) => {
|
|
672
|
+
draft.jsonSchema = internal.toJsonSchema(updated);
|
|
673
|
+
});
|
|
674
|
+
};
|
|
481
675
|
|
|
482
676
|
/**
|
|
483
|
-
*
|
|
677
|
+
* Rename a field on a persisted type's schema.
|
|
678
|
+
* @throws if the type is not persisted.
|
|
484
679
|
*/
|
|
485
|
-
export
|
|
680
|
+
export const updateFieldPropertyName = (
|
|
681
|
+
type: Type,
|
|
682
|
+
{ before, after }: { before: PropertyKey; after: PropertyKey },
|
|
683
|
+
): void => {
|
|
684
|
+
const renamed = typeInternal.updateFieldNameInSchema(getSchema(type), { before, after });
|
|
685
|
+
update(type, (draft) => {
|
|
686
|
+
draft.jsonSchema = internal.toJsonSchema(renamed);
|
|
687
|
+
});
|
|
688
|
+
};
|
|
486
689
|
|
|
487
690
|
/**
|
|
488
|
-
*
|
|
691
|
+
* Remove fields from a persisted type's schema.
|
|
692
|
+
* @throws if the type is not persisted.
|
|
489
693
|
*/
|
|
490
|
-
export const
|
|
491
|
-
|
|
694
|
+
export const removeFields = (type: AnyEntity, fieldNames: string[]): void => {
|
|
695
|
+
const removed = typeInternal.removeFieldsFromSchema(getSchema(type), fieldNames);
|
|
696
|
+
update(type, (draft) => {
|
|
697
|
+
draft.jsonSchema = internal.toJsonSchema(removed);
|
|
698
|
+
});
|
|
492
699
|
};
|