@dxos/echo 0.8.4-main.fffef41 → 0.8.4-staging.ac66bdf99f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/dist/lib/neutral/Annotation.mjs +37 -0
- package/dist/lib/neutral/Database.mjs +49 -0
- package/dist/lib/neutral/Entity.mjs +61 -0
- package/dist/lib/neutral/Err.mjs +12 -0
- package/dist/lib/neutral/Extension.mjs +18 -0
- package/dist/lib/neutral/Feed.mjs +50 -0
- package/dist/lib/neutral/Filter.mjs +72 -0
- package/dist/lib/neutral/Filter.mjs.map +7 -0
- package/dist/lib/neutral/Format.mjs +66 -0
- package/dist/lib/neutral/Format.mjs.map +7 -0
- package/dist/lib/neutral/JsonSchema.mjs +19 -0
- package/dist/lib/neutral/JsonSchema.mjs.map +7 -0
- package/dist/lib/neutral/Key.mjs +12 -0
- package/dist/lib/neutral/Key.mjs.map +7 -0
- package/dist/lib/neutral/Migration.mjs +17 -0
- package/dist/lib/neutral/Migration.mjs.map +7 -0
- package/dist/lib/neutral/Obj.mjs +113 -0
- package/dist/lib/neutral/Obj.mjs.map +7 -0
- package/dist/lib/neutral/Order.mjs +12 -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 +24 -0
- package/dist/lib/neutral/Ref.mjs.map +7 -0
- package/dist/lib/neutral/Relation.mjs +94 -0
- package/dist/lib/neutral/Relation.mjs.map +7 -0
- package/dist/lib/neutral/SchemaRegistry.mjs +2 -0
- package/dist/lib/neutral/SchemaRegistry.mjs.map +7 -0
- package/dist/lib/neutral/Tag.mjs +29 -0
- package/dist/lib/neutral/Tag.mjs.map +7 -0
- package/dist/lib/neutral/Type.mjs +37 -0
- package/dist/lib/neutral/Type.mjs.map +7 -0
- package/dist/lib/neutral/chunk-2KHZ36F5.mjs +361 -0
- package/dist/lib/neutral/chunk-2KHZ36F5.mjs.map +7 -0
- package/dist/lib/neutral/chunk-4OIBYSXE.mjs +159 -0
- package/dist/lib/neutral/chunk-4OIBYSXE.mjs.map +7 -0
- package/dist/lib/neutral/chunk-4P3IXBLT.mjs +45 -0
- package/dist/lib/neutral/chunk-4P3IXBLT.mjs.map +7 -0
- package/dist/lib/neutral/chunk-7RO7CPBZ.mjs +27 -0
- package/dist/lib/neutral/chunk-7RO7CPBZ.mjs.map +7 -0
- package/dist/lib/neutral/chunk-ANHVGJI4.mjs +21 -0
- package/dist/lib/neutral/chunk-ANHVGJI4.mjs.map +7 -0
- package/dist/lib/neutral/chunk-B4BASU6W.mjs +428 -0
- package/dist/lib/neutral/chunk-B4BASU6W.mjs.map +7 -0
- package/dist/lib/neutral/chunk-BNCCGLJN.mjs +7 -0
- package/dist/lib/neutral/chunk-BNCCGLJN.mjs.map +7 -0
- package/dist/lib/neutral/chunk-BVOFLCVF.mjs +45 -0
- package/dist/lib/neutral/chunk-BVOFLCVF.mjs.map +7 -0
- package/dist/lib/neutral/chunk-DQYLD2RB.mjs +402 -0
- package/dist/lib/neutral/chunk-DQYLD2RB.mjs.map +7 -0
- package/dist/lib/neutral/chunk-EAMSSLZC.mjs +299 -0
- package/dist/lib/neutral/chunk-EAMSSLZC.mjs.map +7 -0
- package/dist/lib/neutral/chunk-G3IQMKF7.mjs +396 -0
- package/dist/lib/neutral/chunk-G3IQMKF7.mjs.map +7 -0
- package/dist/lib/neutral/chunk-GZQTCRJB.mjs +73 -0
- package/dist/lib/neutral/chunk-GZQTCRJB.mjs.map +7 -0
- package/dist/lib/neutral/chunk-HBUZJNZO.mjs +286 -0
- package/dist/lib/neutral/chunk-HBUZJNZO.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-JUXPFOEI.mjs +787 -0
- package/dist/lib/neutral/chunk-JUXPFOEI.mjs.map +7 -0
- package/dist/lib/neutral/chunk-MOR5ERFM.mjs +2834 -0
- package/dist/lib/neutral/chunk-MOR5ERFM.mjs.map +7 -0
- package/dist/lib/neutral/chunk-OMUPQMLR.mjs +7 -0
- package/dist/lib/neutral/chunk-OMUPQMLR.mjs.map +7 -0
- package/dist/lib/neutral/chunk-OS35K56T.mjs +34 -0
- package/dist/lib/neutral/chunk-OS35K56T.mjs.map +7 -0
- package/dist/lib/neutral/chunk-PHU22NLC.mjs +136 -0
- package/dist/lib/neutral/chunk-PHU22NLC.mjs.map +7 -0
- package/dist/lib/neutral/chunk-ROG4RXXL.mjs +97 -0
- package/dist/lib/neutral/chunk-ROG4RXXL.mjs.map +7 -0
- package/dist/lib/neutral/chunk-T6W2LEZU.mjs +125 -0
- package/dist/lib/neutral/chunk-T6W2LEZU.mjs.map +7 -0
- package/dist/lib/neutral/chunk-TBKX6JQO.mjs +67 -0
- package/dist/lib/neutral/chunk-TBKX6JQO.mjs.map +7 -0
- package/dist/lib/neutral/chunk-TU3GW67D.mjs +132 -0
- package/dist/lib/neutral/chunk-TU3GW67D.mjs.map +7 -0
- package/dist/lib/neutral/chunk-UBEZSGXY.mjs +51 -0
- package/dist/lib/neutral/chunk-UBEZSGXY.mjs.map +7 -0
- package/dist/lib/neutral/chunk-UI6MWK5W.mjs +42 -0
- package/dist/lib/neutral/chunk-UI6MWK5W.mjs.map +7 -0
- package/dist/lib/neutral/chunk-V36VO5SS.mjs +354 -0
- package/dist/lib/neutral/chunk-V36VO5SS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-WAK4DMFV.mjs +36 -0
- package/dist/lib/neutral/chunk-WAK4DMFV.mjs.map +7 -0
- package/dist/lib/neutral/chunk-YAHXAYOW.mjs +56 -0
- package/dist/lib/neutral/chunk-YAHXAYOW.mjs.map +7 -0
- package/dist/lib/neutral/chunk-YS6Q3XAD.mjs +50 -0
- package/dist/lib/neutral/chunk-YS6Q3XAD.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +105 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/{node-esm → neutral}/internal/index.mjs +290 -152
- 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 +375 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/Annotation.d.ts +24 -0
- package/dist/types/src/Annotation.d.ts.map +1 -0
- package/dist/types/src/Collection.d.ts +16 -0
- package/dist/types/src/Collection.d.ts.map +1 -0
- package/dist/types/src/Database.d.ts +201 -0
- package/dist/types/src/Database.d.ts.map +1 -0
- package/dist/types/src/Dataset.d.ts +19 -0
- package/dist/types/src/Dataset.d.ts.map +1 -0
- package/dist/types/src/Entity.d.ts +174 -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/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 +182 -0
- package/dist/types/src/Feed.d.ts.map +1 -0
- package/dist/types/src/Filter.d.ts +149 -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 +4 -0
- package/dist/types/src/Format.d.ts.map +1 -0
- package/dist/types/src/Hypergraph.d.ts +65 -0
- package/dist/types/src/Hypergraph.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 +1 -0
- package/dist/types/src/Key.d.ts.map +1 -1
- package/dist/types/src/Migration.d.ts +57 -0
- package/dist/types/src/Migration.d.ts.map +1 -0
- package/dist/types/src/Obj.d.ts +434 -104
- 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 +16 -0
- package/dist/types/src/Order.d.ts.map +1 -0
- package/dist/types/src/Query.d.ts +209 -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 +80 -0
- package/dist/types/src/QueryResult.d.ts.map +1 -0
- package/dist/types/src/Ref.d.ts +61 -11
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +287 -21
- 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/SchemaRegistry.d.ts +84 -0
- package/dist/types/src/SchemaRegistry.d.ts.map +1 -0
- package/dist/types/src/Tag.d.ts +8 -7
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +123 -99
- 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 +68 -0
- package/dist/types/src/View.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 +20 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/Annotation/annotations.d.ts +231 -0
- 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/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 +39 -0
- 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 +20 -0
- package/dist/types/src/internal/Entity/entity.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/index.d.ts +8 -0
- package/dist/types/src/internal/Entity/index.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/model.d.ts +55 -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 +35 -0
- package/dist/types/src/internal/Entity/relation.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.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 +4 -2
- 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/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/{formats → Format}/select.d.ts +6 -4
- package/dist/types/src/internal/Format/select.d.ts.map +1 -0
- package/dist/types/src/internal/{formats → Format}/string.d.ts +4 -0
- package/dist/types/src/internal/Format/string.d.ts.map +1 -0
- package/dist/types/src/internal/{formats → Format}/types.d.ts +14 -10
- package/dist/types/src/internal/Format/types.d.ts.map +1 -0
- package/dist/types/src/internal/{json → 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 +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.map +1 -0
- package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema-type.d.ts +131 -30
- package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -0
- package/dist/types/src/internal/{json → JsonSchema}/json-schema.d.ts +4 -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 +8 -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/create.d.ts → Obj/create-object.d.ts} +10 -11
- 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/ids.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.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.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/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.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 +4 -4
- package/dist/types/src/internal/Ref/ref-array.d.ts.map +1 -0
- package/dist/types/src/internal/{ref → Ref}/ref.d.ts +44 -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/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.map +1 -0
- package/dist/types/src/internal/{schema → Type}/echo-schema.d.ts +27 -14
- package/dist/types/src/internal/Type/echo-schema.d.ts.map +1 -0
- package/dist/types/src/internal/Type/index.d.ts +4 -0
- package/dist/types/src/internal/Type/index.d.ts.map +1 -0
- package/dist/types/src/internal/Type/manipulation.d.ts.map +1 -0
- package/dist/types/src/internal/Type/persistent-schema.d.ts +20 -0
- package/dist/types/src/internal/Type/persistent-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 +42 -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.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 +14 -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/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 +3 -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 +16 -12
- 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/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 +37 -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/{object → common/types}/meta.d.ts +18 -16
- package/dist/types/src/internal/common/types/meta.d.ts.map +1 -0
- package/dist/types/src/internal/common/types/model-symbols.d.ts +54 -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 +21 -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/index.d.ts +10 -14
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +3 -3
- package/dist/types/src/testing/index.d.ts.map +1 -1
- 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 +304 -0
- package/dist/types/src/testing/test-schema.d.ts.map +1 -0
- package/dist/types/src/testing/util.d.ts +21 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +116 -65
- package/src/Annotation.ts +48 -0
- package/src/Collection.ts +37 -0
- package/src/Database.ts +352 -0
- package/src/Dataset.ts +26 -0
- package/src/Entity.test.ts +22 -0
- package/src/Entity.ts +243 -0
- package/src/Err.ts +40 -0
- package/src/Extension.test.ts +235 -0
- package/src/Extension.ts +122 -0
- package/src/Feed.ts +304 -0
- package/src/Filter.test.ts +90 -0
- package/src/Filter.ts +454 -0
- package/src/Format.ts +9 -0
- package/src/Hypergraph.ts +79 -0
- package/src/JsonSchema.ts +26 -0
- package/src/Key.ts +3 -0
- package/src/Migration.ts +94 -0
- package/src/Obj.test.ts +539 -0
- package/src/Obj.ts +697 -277
- package/src/Order.ts +46 -0
- package/src/Query.test.ts +806 -0
- package/src/Query.ts +547 -0
- package/src/QueryResult.ts +106 -0
- package/src/Ref.ts +79 -9
- package/src/Relation.test.ts +88 -0
- package/src/Relation.ts +449 -60
- package/src/SchemaRegistry.ts +106 -0
- package/src/Tag.ts +7 -5
- package/src/Type.test.ts +52 -0
- package/src/Type.ts +167 -153
- package/src/View.ts +107 -0
- package/src/hierarchy.test.ts +33 -0
- package/src/index.ts +22 -6
- package/src/internal/Annotation/annotations.test.ts +145 -0
- package/src/internal/Annotation/annotations.ts +577 -0
- package/src/internal/Annotation/index.ts +7 -0
- package/src/internal/Annotation/sorting.ts +51 -0
- package/src/internal/Annotation/util.ts +85 -0
- package/src/internal/Entity/api.ts +30 -0
- package/src/internal/Entity/entity.ts +128 -0
- package/src/internal/Entity/index.ts +11 -0
- package/src/internal/Entity/model.ts +109 -0
- package/src/internal/Entity/object.ts +57 -0
- package/src/internal/Entity/relation.ts +154 -0
- package/src/internal/Entity/util.ts +33 -0
- package/src/internal/Entity/version.ts +96 -0
- package/src/internal/{formats → Format}/date.test.ts +1 -2
- package/src/internal/{formats → Format}/date.ts +5 -5
- package/src/internal/{formats → Format}/format.test.ts +6 -7
- package/src/internal/{formats → Format}/format.ts +8 -6
- package/src/internal/{formats → Format}/number.ts +5 -5
- package/src/internal/{formats → Format}/object.ts +4 -4
- package/src/internal/{formats → Format}/select.ts +6 -4
- package/src/internal/{formats → Format}/string.ts +14 -9
- package/src/internal/{formats → Format}/types.ts +54 -43
- package/src/internal/{json → JsonSchema}/annotations.ts +3 -3
- package/src/internal/{json-schema → JsonSchema}/index.ts +2 -0
- package/src/internal/{json-schema → JsonSchema}/json-schema-normalize.ts +4 -2
- package/src/internal/{json-schema → JsonSchema}/json-schema-type.ts +36 -36
- package/src/internal/{json → JsonSchema}/json-schema.test.ts +106 -95
- package/src/internal/{json → JsonSchema}/json-schema.ts +29 -15
- package/src/internal/Obj/clone.ts +48 -0
- package/src/internal/{object → Obj}/common.ts +3 -4
- package/src/internal/{object/create.test.ts → Obj/create-object.test.ts} +32 -36
- package/src/internal/{object/create.ts → Obj/create-object.ts} +35 -37
- package/src/internal/Obj/deleted.ts +19 -0
- package/src/internal/{object → Obj}/ids.ts +1 -1
- package/src/internal/Obj/index.ts +14 -0
- package/src/internal/{object → Obj}/inspect.ts +5 -7
- package/src/internal/Obj/json-serializer.test.ts +120 -0
- package/src/internal/{object → Obj}/json-serializer.ts +106 -109
- package/src/internal/{object → Obj}/schema-validator.test.ts +3 -7
- package/src/internal/Obj/schema-validator.ts +6 -0
- package/src/internal/Obj/set-value.test.ts +281 -0
- package/src/internal/Obj/set-value.ts +165 -0
- package/src/internal/Obj/snapshot.ts +105 -0
- package/src/internal/{object → Obj}/typed-object.test.ts +12 -12
- package/src/internal/Obj/typed-object.ts +30 -0
- package/src/internal/Query.ts +134 -0
- package/src/internal/{ref → Ref}/ref-array.ts +4 -5
- package/src/internal/{ref → Ref}/ref.test.ts +11 -11
- package/src/internal/{ref → Ref}/ref.ts +108 -57
- package/src/internal/{projection → Type}/compose.test.ts +8 -10
- package/src/internal/{projection → Type}/compose.ts +14 -9
- package/src/internal/{schema → Type}/echo-schema.ts +74 -34
- package/src/internal/Type/index.ts +7 -0
- package/src/internal/{schema → Type}/manipulation.ts +1 -1
- package/src/internal/Type/persistent-schema.ts +33 -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 +88 -0
- package/src/internal/{testing → common}/index.ts +2 -1
- package/src/internal/common/proxy/change-context.ts +138 -0
- package/src/internal/common/proxy/change.test.ts +519 -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 +90 -0
- package/src/internal/common/proxy/make-object.ts +105 -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.ts +68 -0
- package/src/internal/{object → common/proxy}/schema-validator.ts +6 -3
- package/src/internal/{proxy → common/proxy}/schema.test.ts +31 -22
- package/src/internal/common/proxy/symbols.ts +7 -0
- package/src/internal/common/proxy/typed-handler.test.ts +313 -0
- package/src/internal/common/proxy/typed-handler.ts +447 -0
- package/src/internal/common/proxy/typed-object.test.ts +115 -0
- package/src/internal/common/types/base.ts +43 -0
- package/src/internal/common/types/entity.ts +54 -0
- package/src/internal/common/types/index.ts +10 -0
- package/src/internal/common/types/meta.ts +67 -0
- package/src/internal/common/types/model-symbols.ts +69 -0
- package/src/internal/common/types/typename.ts +55 -0
- package/src/internal/common/types/version.ts +19 -0
- package/src/internal/index.ts +12 -17
- package/src/testing/api.test.ts +125 -0
- package/src/testing/index.ts +3 -3
- package/src/testing/test-data.ts +129 -0
- package/src/testing/test-schema.ts +240 -0
- package/src/testing/util.ts +85 -0
- package/dist/lib/browser/chunk-BIDAASFK.mjs +0 -3727
- package/dist/lib/browser/chunk-BIDAASFK.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZDLCWGEW.mjs +0 -410
- package/dist/lib/browser/chunk-ZDLCWGEW.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZFRJKT4A.mjs +0 -585
- package/dist/lib/browser/chunk-ZFRJKT4A.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -35
- package/dist/lib/browser/internal/index.mjs +0 -336
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/query/index.mjs +0 -13
- package/dist/lib/browser/testing/index.mjs +0 -267
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3SVRRCUU.mjs +0 -3727
- package/dist/lib/node-esm/chunk-3SVRRCUU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CGDHRZWH.mjs +0 -585
- package/dist/lib/node-esm/chunk-CGDHRZWH.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HWS6VBQC.mjs +0 -410
- package/dist/lib/node-esm/chunk-HWS6VBQC.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -35
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/query/index.mjs +0 -13
- package/dist/lib/node-esm/testing/index.mjs +0 -267
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/errors.d.ts +0 -68
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotation-helper.d.ts +0 -8
- package/dist/types/src/internal/ast/annotation-helper.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotations.d.ts +0 -131
- package/dist/types/src/internal/ast/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotations.test.d.ts.map +0 -1
- package/dist/types/src/internal/ast/entity-kind.d.ts +0 -10
- package/dist/types/src/internal/ast/entity-kind.d.ts.map +0 -1
- package/dist/types/src/internal/ast/index.d.ts +0 -5
- package/dist/types/src/internal/ast/index.d.ts.map +0 -1
- package/dist/types/src/internal/ast/types.d.ts +0 -6
- package/dist/types/src/internal/ast/types.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/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/json/effect-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/json/index.d.ts +0 -2
- package/dist/types/src/internal/json/index.d.ts.map +0 -1
- package/dist/types/src/internal/json/json-schema.d.ts.map +0 -1
- package/dist/types/src/internal/json/json-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/index.d.ts +0 -3
- 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/object/accessors.d.ts +0 -37
- package/dist/types/src/internal/object/accessors.d.ts.map +0 -1
- package/dist/types/src/internal/object/common.d.ts.map +0 -1
- package/dist/types/src/internal/object/create.d.ts.map +0 -1
- package/dist/types/src/internal/object/create.test.d.ts +0 -2
- package/dist/types/src/internal/object/create.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/deleted.d.ts +0 -6
- package/dist/types/src/internal/object/deleted.d.ts.map +0 -1
- package/dist/types/src/internal/object/entity.d.ts +0 -33
- package/dist/types/src/internal/object/entity.d.ts.map +0 -1
- package/dist/types/src/internal/object/expando.d.ts +0 -14
- package/dist/types/src/internal/object/expando.d.ts.map +0 -1
- package/dist/types/src/internal/object/ids.d.ts.map +0 -1
- package/dist/types/src/internal/object/index.d.ts +0 -16
- 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 +0 -32
- 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/meta.d.ts.map +0 -1
- package/dist/types/src/internal/object/model.d.ts +0 -117
- package/dist/types/src/internal/object/model.d.ts.map +0 -1
- package/dist/types/src/internal/object/relation.d.ts +0 -17
- package/dist/types/src/internal/object/relation.d.ts.map +0 -1
- 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/typed-object.d.ts +0 -31
- 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/object/typename.d.ts +0 -15
- package/dist/types/src/internal/object/typename.d.ts.map +0 -1
- package/dist/types/src/internal/object/version.d.ts +0 -14
- package/dist/types/src/internal/object/version.d.ts.map +0 -1
- package/dist/types/src/internal/projection/compose.d.ts +0 -6
- package/dist/types/src/internal/projection/compose.d.ts.map +0 -1
- package/dist/types/src/internal/projection/compose.test.d.ts.map +0 -1
- package/dist/types/src/internal/projection/index.d.ts +0 -2
- package/dist/types/src/internal/projection/index.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/handler.test.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/reactive-object.d.ts +0 -15
- package/dist/types/src/internal/proxy/reactive-object.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/schema.test.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/query/index.d.ts +0 -2
- package/dist/types/src/internal/query/index.d.ts.map +0 -1
- package/dist/types/src/internal/query/query.d.ts +0 -17
- package/dist/types/src/internal/query/query.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/echo-schema.d.ts.map +0 -1
- package/dist/types/src/internal/schema/index.d.ts +0 -7
- 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/runtime-schema-registry.d.ts +0 -18
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts.map +0 -1
- package/dist/types/src/internal/schema/snapshot.d.ts +0 -6
- package/dist/types/src/internal/schema/snapshot.d.ts.map +0 -1
- package/dist/types/src/internal/schema/stored-schema.d.ts +0 -13
- package/dist/types/src/internal/schema/stored-schema.d.ts.map +0 -1
- package/dist/types/src/internal/testing/index.d.ts +0 -3
- package/dist/types/src/internal/testing/index.d.ts.map +0 -1
- package/dist/types/src/internal/testing/types.d.ts +0 -381
- package/dist/types/src/internal/testing/types.d.ts.map +0 -1
- package/dist/types/src/internal/testing/utils.d.ts +0 -10
- package/dist/types/src/internal/testing/utils.d.ts.map +0 -1
- package/dist/types/src/internal/types/index.d.ts +0 -3
- package/dist/types/src/internal/types/index.d.ts.map +0 -1
- package/dist/types/src/internal/types/types.d.ts +0 -79
- package/dist/types/src/internal/types/types.d.ts.map +0 -1
- package/dist/types/src/internal/types/types.test.d.ts +0 -2
- package/dist/types/src/internal/types/types.test.d.ts.map +0 -1
- package/dist/types/src/internal/types/util.d.ts +0 -5
- package/dist/types/src/internal/types/util.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/query/query.d.ts +0 -248
- package/dist/types/src/query/query.d.ts.map +0 -1
- package/dist/types/src/query/query.test.d.ts +0 -2
- package/dist/types/src/query/query.test.d.ts.map +0 -1
- package/dist/types/src/testing/echo-schema.d.ts +0 -7
- package/dist/types/src/testing/echo-schema.d.ts.map +0 -1
- package/dist/types/src/testing/types.d.ts +0 -228
- package/dist/types/src/testing/types.d.ts.map +0 -1
- package/src/errors.ts +0 -18
- package/src/internal/ast/annotation-helper.ts +0 -22
- package/src/internal/ast/annotations.test.ts +0 -98
- package/src/internal/ast/annotations.ts +0 -226
- package/src/internal/ast/entity-kind.ts +0 -15
- package/src/internal/ast/index.ts +0 -8
- package/src/internal/ast/types.ts +0 -17
- package/src/internal/json/index.ts +0 -5
- package/src/internal/object/accessors.ts +0 -153
- package/src/internal/object/deleted.ts +0 -19
- package/src/internal/object/entity.ts +0 -248
- package/src/internal/object/expando.ts +0 -21
- package/src/internal/object/index.ts +0 -19
- package/src/internal/object/json-serializer.test.ts +0 -99
- package/src/internal/object/meta.ts +0 -61
- package/src/internal/object/model.ts +0 -170
- package/src/internal/object/relation.ts +0 -24
- package/src/internal/object/typed-object.ts +0 -88
- package/src/internal/object/typename.ts +0 -61
- package/src/internal/object/version.ts +0 -22
- package/src/internal/projection/index.ts +0 -5
- package/src/internal/proxy/handler.test.ts +0 -163
- package/src/internal/proxy/reactive-object.ts +0 -108
- package/src/internal/proxy/typed-handler.test.ts +0 -102
- package/src/internal/proxy/typed-handler.ts +0 -228
- package/src/internal/proxy/typed-object.test.ts +0 -100
- package/src/internal/query/index.ts +0 -5
- package/src/internal/query/query.ts +0 -23
- package/src/internal/schema/index.ts +0 -10
- package/src/internal/schema/runtime-schema-registry.ts +0 -78
- package/src/internal/schema/snapshot.ts +0 -25
- package/src/internal/schema/stored-schema.ts +0 -26
- package/src/internal/testing/types.ts +0 -144
- package/src/internal/testing/utils.ts +0 -54
- package/src/internal/types/index.ts +0 -6
- package/src/internal/types/types.test.ts +0 -48
- package/src/internal/types/types.ts +0 -176
- package/src/internal/types/util.ts +0 -9
- package/src/query/index.ts +0 -6
- package/src/query/query.test.ts +0 -401
- package/src/query/query.ts +0 -789
- package/src/test/api.test.ts +0 -180
- package/src/testing/echo-schema.ts +0 -39
- package/src/testing/types.ts +0 -108
- /package/dist/lib/{browser/index.mjs.map → neutral/Annotation.mjs.map} +0 -0
- /package/dist/lib/{browser/internal/index.mjs.map → neutral/Database.mjs.map} +0 -0
- /package/dist/lib/{browser/query/index.mjs.map → neutral/Entity.mjs.map} +0 -0
- /package/dist/lib/{node-esm/index.mjs.map → neutral/Err.mjs.map} +0 -0
- /package/dist/lib/{node-esm/internal/index.mjs.map → neutral/Extension.mjs.map} +0 -0
- /package/dist/lib/{node-esm/query/index.mjs.map → neutral/Feed.mjs.map} +0 -0
- /package/dist/types/src/internal/{ast → Annotation}/annotations.test.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}/index.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/{json → JsonSchema}/effect-schema.test.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 → JsonSchema}/json-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/common.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/ids.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}/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/{projection → Type}/compose.test.d.ts +0 -0
- /package/dist/types/src/internal/{schema → Type}/manipulation.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/handler.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → 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}/typed-handler.test.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/typed-object.test.d.ts +0 -0
- /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
- /package/src/internal/{formats → Format}/index.ts +0 -0
- /package/src/internal/{json → JsonSchema}/effect-schema.test.ts +0 -0
- /package/src/internal/{ref → Ref}/index.ts +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type * as Option from 'effect/Option';
|
|
6
|
+
import type * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
+
|
|
9
|
+
import { assertArgument } from '@dxos/invariant';
|
|
10
|
+
import { DXN } from '@dxos/keys';
|
|
11
|
+
|
|
12
|
+
import { EntityKind } from '../common/types';
|
|
13
|
+
|
|
14
|
+
export interface AnnotationHelper<T> {
|
|
15
|
+
/**
|
|
16
|
+
* Get the annotation value from the schema.
|
|
17
|
+
*/
|
|
18
|
+
get: (schema: Schema.Schema.Any) => Option.Option<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Get the annotation value from the AST.
|
|
21
|
+
*/
|
|
22
|
+
getFromAst: (ast: SchemaAST.AST) => Option.Option<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Set the annotation value on the schema.
|
|
25
|
+
*/
|
|
26
|
+
set: (value: T) => <S extends Schema.Schema.Any>(schema: S) => S;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Note: only for system annotations.
|
|
31
|
+
*/
|
|
32
|
+
// TODO(dmaretskyi): Rename to createSystemAnnotationHelper.
|
|
33
|
+
export const createAnnotationHelper = <T>(id: symbol): AnnotationHelper<T> => {
|
|
34
|
+
return {
|
|
35
|
+
get: (schema) => SchemaAST.getAnnotation(schema.ast, id),
|
|
36
|
+
getFromAst: (ast) => SchemaAST.getAnnotation(ast, id),
|
|
37
|
+
set:
|
|
38
|
+
(value) =>
|
|
39
|
+
<S extends Schema.Schema.Any>(schema: S) =>
|
|
40
|
+
schema.annotations({ [id]: value }) as S,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* If property is optional returns the nested property, otherwise returns the property.
|
|
46
|
+
*/
|
|
47
|
+
// TODO(wittjosiah): Is there a way to do this as a generic?
|
|
48
|
+
export const unwrapOptional = (property: SchemaAST.PropertySignature) => {
|
|
49
|
+
if (!property.isOptional || !SchemaAST.isUnion(property.type)) {
|
|
50
|
+
return property;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return property.type.types[0];
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @see JSONSchemaAnnotationId
|
|
58
|
+
* @returns JSON-schema annotation so that the schema can be serialized with correct parameters.
|
|
59
|
+
*/
|
|
60
|
+
// TODO(burdon): Required type.
|
|
61
|
+
export const makeTypeJsonSchemaAnnotation = (options: {
|
|
62
|
+
identifier?: string;
|
|
63
|
+
kind: EntityKind;
|
|
64
|
+
typename: string;
|
|
65
|
+
version: string;
|
|
66
|
+
relationSource?: string;
|
|
67
|
+
relationTarget?: string;
|
|
68
|
+
}) => {
|
|
69
|
+
assertArgument(!!options.relationSource === (options.kind === EntityKind.Relation), 'relationSource');
|
|
70
|
+
assertArgument(!!options.relationTarget === (options.kind === EntityKind.Relation), 'relationTarget');
|
|
71
|
+
|
|
72
|
+
const obj = {
|
|
73
|
+
// TODO(dmaretskyi): Should this include the version?
|
|
74
|
+
$id: options.identifier ?? DXN.fromTypename(options.typename).toString(),
|
|
75
|
+
entityKind: options.kind,
|
|
76
|
+
version: options.version,
|
|
77
|
+
typename: options.typename,
|
|
78
|
+
} as any;
|
|
79
|
+
if (options.kind === EntityKind.Relation) {
|
|
80
|
+
obj.relationSource = { $ref: options.relationSource };
|
|
81
|
+
obj.relationTarget = { $ref: options.relationTarget };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return obj;
|
|
85
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { invariant } from '@dxos/invariant';
|
|
6
|
+
import { type DXN } from '@dxos/keys';
|
|
7
|
+
import { assumeType } from '@dxos/util';
|
|
8
|
+
|
|
9
|
+
import type { AnyEntity } from '../common/types';
|
|
10
|
+
import { type InternalObjectProps, ObjectDatabaseId } from './model';
|
|
11
|
+
import { getObjectDXN } from './util';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Get the DXN of an entity.
|
|
15
|
+
* Accepts both reactive entities and snapshots.
|
|
16
|
+
*/
|
|
17
|
+
export const getDXN = (entity: AnyEntity): DXN => {
|
|
18
|
+
const dxn = getObjectDXN(entity);
|
|
19
|
+
invariant(dxn != null, 'Invalid entity.');
|
|
20
|
+
return dxn;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get the database the entity belongs to.
|
|
25
|
+
* Accepts both reactive entities and snapshots.
|
|
26
|
+
*/
|
|
27
|
+
export const getDatabase = (entity: AnyEntity): any | undefined => {
|
|
28
|
+
assumeType<InternalObjectProps>(entity);
|
|
29
|
+
return entity[ObjectDatabaseId];
|
|
30
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import type * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
import type * as Types from 'effect/Types';
|
|
8
|
+
|
|
9
|
+
import { type ToMutable } from '@dxos/util';
|
|
10
|
+
|
|
11
|
+
import { type TypeMeta } from '../Annotation';
|
|
12
|
+
import { type AnyEntity, type EntityKind, SchemaKindId } from '../common/types';
|
|
13
|
+
|
|
14
|
+
// TODO(burdon): Define Schema type for `typename` and use consistently for all DXN-like properties.
|
|
15
|
+
|
|
16
|
+
// type RequiredKeys<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T];
|
|
17
|
+
export type EchoTypeSchemaProps<T, ExtraFields = {}> = Types.Simplify<AnyEntity & ToMutable<T> & ExtraFields>;
|
|
18
|
+
|
|
19
|
+
// TODO(burdon): Rename EchoEntitySchema.
|
|
20
|
+
export interface EchoTypeSchema<
|
|
21
|
+
Self extends Schema.Schema.Any,
|
|
22
|
+
ExtraFields = {},
|
|
23
|
+
K extends EntityKind = EntityKind,
|
|
24
|
+
Fields extends Schema.Struct.Fields = Schema.Struct.Fields,
|
|
25
|
+
>
|
|
26
|
+
extends
|
|
27
|
+
TypeMeta,
|
|
28
|
+
Schema.AnnotableClass<
|
|
29
|
+
EchoTypeSchema<Self, ExtraFields, K, Fields>,
|
|
30
|
+
EchoTypeSchemaProps<Schema.Schema.Type<Self>, ExtraFields>,
|
|
31
|
+
EchoTypeSchemaProps<Schema.Schema.Encoded<Self>, ExtraFields>,
|
|
32
|
+
Schema.Schema.Context<Self>
|
|
33
|
+
> {
|
|
34
|
+
/**
|
|
35
|
+
* Schema kind key that marks this as an ECHO schema and indicates its kind.
|
|
36
|
+
* Makes EchoTypeSchema satisfy the Type.AnyObj or Type.Relation.Any type.
|
|
37
|
+
*/
|
|
38
|
+
readonly [SchemaKindId]: K;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The fields defined in the original struct schema.
|
|
42
|
+
* Allows accessing field definitions for introspection.
|
|
43
|
+
*/
|
|
44
|
+
readonly fields: Fields;
|
|
45
|
+
|
|
46
|
+
instanceOf(value: unknown): boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// type MakeProps =
|
|
50
|
+
// | boolean
|
|
51
|
+
// | {
|
|
52
|
+
// readonly disableValidation?: boolean;
|
|
53
|
+
// };
|
|
54
|
+
|
|
55
|
+
// NOTE: Utils copied from Effect `Schema.ts`.
|
|
56
|
+
// const _ownKeys = (o: object): Array<PropertyKey> =>
|
|
57
|
+
// (Object.keys(o) as Array<PropertyKey>).concat(Object.getOwnPropertySymbols(o));
|
|
58
|
+
|
|
59
|
+
// const _lazilyMergeDefaults = (
|
|
60
|
+
// fields: Schema.Struct.Fields,
|
|
61
|
+
// out: Record<PropertyKey, unknown>,
|
|
62
|
+
// ): { [x: string | symbol]: unknown } => {
|
|
63
|
+
// const ownKeys = _ownKeys(fields);
|
|
64
|
+
// for (const key of ownKeys) {
|
|
65
|
+
// const field = fields[key];
|
|
66
|
+
// if (out[key] === undefined && Schema.isPropertySignature(field)) {
|
|
67
|
+
// const ast = field.ast;
|
|
68
|
+
// const defaultValue = ast._tag === 'PropertySignatureDeclaration' ? ast.defaultValue : ast.to.defaultValue;
|
|
69
|
+
// if (defaultValue !== undefined) {
|
|
70
|
+
// out[key] = defaultValue();
|
|
71
|
+
// }
|
|
72
|
+
// }
|
|
73
|
+
// }
|
|
74
|
+
// return out;
|
|
75
|
+
// };
|
|
76
|
+
|
|
77
|
+
// const _getDisableValidationMakeOption = (options: MakeProps | undefined): boolean =>
|
|
78
|
+
// Predicate.isBoolean(options) ? options : options?.disableValidation ?? false;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export const makeEchoTypeSchema = <
|
|
84
|
+
Self extends Schema.Schema.Any,
|
|
85
|
+
K extends EntityKind = EntityKind,
|
|
86
|
+
// TODO(wittjosiah): Can this be inferred from the schema?
|
|
87
|
+
Fields extends Schema.Struct.Fields = Schema.Struct.Fields,
|
|
88
|
+
>(
|
|
89
|
+
fields: Fields,
|
|
90
|
+
ast: SchemaAST.AST,
|
|
91
|
+
typename: string,
|
|
92
|
+
version: string,
|
|
93
|
+
kind: K,
|
|
94
|
+
): EchoTypeSchema<Self, {}, K, Fields> => {
|
|
95
|
+
return class EchoObjectSchemaClass extends Schema.make<
|
|
96
|
+
EchoTypeSchemaProps<Schema.Schema.Type<Self>>,
|
|
97
|
+
EchoTypeSchemaProps<Schema.Schema.Encoded<Self>>,
|
|
98
|
+
Schema.Schema.Context<Self>
|
|
99
|
+
>(ast) {
|
|
100
|
+
static readonly typename = typename;
|
|
101
|
+
static readonly version = version;
|
|
102
|
+
static readonly [SchemaKindId] = kind;
|
|
103
|
+
static readonly fields = fields;
|
|
104
|
+
|
|
105
|
+
static override annotations(
|
|
106
|
+
annotations: Schema.Annotations.GenericSchema<EchoTypeSchemaProps<Schema.Schema.Type<Self>>>,
|
|
107
|
+
): EchoTypeSchema<Self, {}, K, Fields> {
|
|
108
|
+
const schema = Schema.make<EchoTypeSchemaProps<Schema.Schema.Type<Self>>>(ast).annotations(annotations);
|
|
109
|
+
return makeEchoTypeSchema<Self, K, Fields>(fields, schema.ast, typename, version, kind);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// static make(
|
|
113
|
+
// props: RequiredKeys<Schema.TypeLiteral.Constructor<Fields, []>> extends never
|
|
114
|
+
// ? void | Simplify<Schema.TypeLiteral.Constructor<Fields, []>>
|
|
115
|
+
// : Simplify<Schema.TypeLiteral.Constructor<Fields, []>>,
|
|
116
|
+
// options?: MakeProps,
|
|
117
|
+
// ): Simplify<Schema.TypeLiteral.Type<Fields, []>> {
|
|
118
|
+
// const propsWithDefaults: any = _lazilyMergeDefaults(fields, { ...(props as any) });
|
|
119
|
+
// return _getDisableValidationMakeOption(options)
|
|
120
|
+
// ? propsWithDefaults
|
|
121
|
+
// : ParseResult.validateSync(this)(propsWithDefaults);
|
|
122
|
+
// }
|
|
123
|
+
|
|
124
|
+
static instanceOf(value: unknown): boolean {
|
|
125
|
+
return Schema.is(this)(value);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { type ForeignKey } from '@dxos/echo-protocol';
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { DXN, ObjectId } from '@dxos/keys';
|
|
10
|
+
import { assumeType } from '@dxos/util';
|
|
11
|
+
|
|
12
|
+
import type * as Database from '../../Database';
|
|
13
|
+
import {
|
|
14
|
+
type ATTR_META,
|
|
15
|
+
type ATTR_PARENT,
|
|
16
|
+
type ATTR_TYPE,
|
|
17
|
+
ATTR_DELETED,
|
|
18
|
+
ATTR_RELATION_SOURCE,
|
|
19
|
+
ATTR_RELATION_TARGET,
|
|
20
|
+
ATTR_SELF_DXN,
|
|
21
|
+
EntityKind,
|
|
22
|
+
KindId,
|
|
23
|
+
type MetaId,
|
|
24
|
+
ObjectDatabaseId,
|
|
25
|
+
ObjectDeletedId,
|
|
26
|
+
type ObjectMeta,
|
|
27
|
+
ObjectVersionId,
|
|
28
|
+
type ParentId,
|
|
29
|
+
RelationSourceDXNId,
|
|
30
|
+
RelationSourceId,
|
|
31
|
+
RelationTargetDXNId,
|
|
32
|
+
RelationTargetId,
|
|
33
|
+
type SchemaId,
|
|
34
|
+
SelfDXNId,
|
|
35
|
+
TypeId,
|
|
36
|
+
type Version,
|
|
37
|
+
} from '../common/types';
|
|
38
|
+
|
|
39
|
+
export { ATTR_DELETED, ATTR_SELF_DXN, ObjectDatabaseId, ObjectDeletedId, ObjectVersionId, SelfDXNId };
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Internal runtime representation of an object.
|
|
43
|
+
* The fields are accessed through getter functions.
|
|
44
|
+
*/
|
|
45
|
+
// NOTE: Each symbol has a jsdoc describing its purpose.
|
|
46
|
+
export interface InternalObjectProps {
|
|
47
|
+
readonly id: ObjectId;
|
|
48
|
+
readonly [SelfDXNId]: DXN;
|
|
49
|
+
readonly [KindId]: EntityKind;
|
|
50
|
+
readonly [SchemaId]: Schema.Schema.AnyNoContext;
|
|
51
|
+
readonly [TypeId]: DXN;
|
|
52
|
+
readonly [MetaId]?: ObjectMeta;
|
|
53
|
+
[ParentId]?: InternalObjectProps;
|
|
54
|
+
readonly [ObjectDatabaseId]?: Database.Database;
|
|
55
|
+
readonly [ObjectDeletedId]?: boolean;
|
|
56
|
+
readonly [ObjectVersionId]?: Version;
|
|
57
|
+
readonly [RelationSourceDXNId]?: DXN;
|
|
58
|
+
readonly [RelationTargetDXNId]?: DXN;
|
|
59
|
+
readonly [RelationSourceId]?: InternalObjectProps;
|
|
60
|
+
readonly [RelationTargetId]?: InternalObjectProps;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Entity metadata.
|
|
65
|
+
*/
|
|
66
|
+
export interface ObjectMetaJSON {
|
|
67
|
+
keys: ForeignKey[];
|
|
68
|
+
tags?: string[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* JSON representation of an object or relation metadata.
|
|
73
|
+
*/
|
|
74
|
+
export interface ObjectJSON {
|
|
75
|
+
id: string;
|
|
76
|
+
[ATTR_TYPE]: DXN.String;
|
|
77
|
+
[ATTR_SELF_DXN]?: DXN.String;
|
|
78
|
+
[ATTR_PARENT]?: string; // Encoded reference
|
|
79
|
+
[ATTR_DELETED]?: boolean;
|
|
80
|
+
[ATTR_META]?: ObjectMetaJSON;
|
|
81
|
+
[ATTR_RELATION_SOURCE]?: DXN.String;
|
|
82
|
+
[ATTR_RELATION_TARGET]?: DXN.String;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Application-specific properties.
|
|
86
|
+
*/
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* NOTE: Keep as `function` to avoid type inference issues.
|
|
92
|
+
*/
|
|
93
|
+
export function assertObjectModel(obj: unknown): asserts obj is InternalObjectProps {
|
|
94
|
+
invariant(typeof obj === 'object' && obj !== null, 'Invalid object model: not an object');
|
|
95
|
+
assumeType<InternalObjectProps>(obj);
|
|
96
|
+
invariant(ObjectId.isValid(obj.id), 'Invalid object model: invalid id');
|
|
97
|
+
invariant(obj[TypeId] === undefined || obj[TypeId] instanceof DXN, 'Invalid object model: invalid type');
|
|
98
|
+
invariant(
|
|
99
|
+
obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation,
|
|
100
|
+
'Invalid object model: invalid entity kind',
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (obj[KindId] === EntityKind.Relation) {
|
|
104
|
+
invariant(obj[RelationSourceDXNId] instanceof DXN, 'Invalid object model: invalid relation source');
|
|
105
|
+
invariant(obj[RelationTargetDXNId] instanceof DXN, 'Invalid object model: invalid relation target');
|
|
106
|
+
invariant(!(obj[RelationSourceId] instanceof DXN), 'Invalid object model: source pointer is a DXN');
|
|
107
|
+
invariant(!(obj[RelationTargetId] instanceof DXN), 'Invalid object model: target pointer is a DXN');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
|
|
10
|
+
import { type TypeAnnotation, TypeAnnotationId, type TypeMeta, makeTypeJsonSchemaAnnotation } from '../Annotation';
|
|
11
|
+
import { EntityKind } from '../common/types';
|
|
12
|
+
import { type EchoTypeSchema, makeEchoTypeSchema } from './entity';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Object schema type with kind marker.
|
|
16
|
+
*/
|
|
17
|
+
export type EchoObjectSchema<
|
|
18
|
+
Self extends Schema.Schema.Any,
|
|
19
|
+
Fields extends Schema.Struct.Fields = Schema.Struct.Fields,
|
|
20
|
+
> = EchoTypeSchema<Self, {}, EntityKind.Object, Fields>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Schema for Obj entity types.
|
|
24
|
+
* Pipeable function to add ECHO object annotations to a schema.
|
|
25
|
+
*/
|
|
26
|
+
export const EchoObjectSchema: {
|
|
27
|
+
(
|
|
28
|
+
meta: TypeMeta,
|
|
29
|
+
): <Self extends Schema.Schema.Any, Fields extends Schema.Struct.Fields = Schema.Struct.Fields>(
|
|
30
|
+
self: Self & { fields?: Fields },
|
|
31
|
+
) => EchoObjectSchema<Self, Fields>;
|
|
32
|
+
} = ({ typename, version }) => {
|
|
33
|
+
return <Self extends Schema.Schema.Any, Fields extends Schema.Struct.Fields = Schema.Struct.Fields>(
|
|
34
|
+
self: Self & { fields?: Fields },
|
|
35
|
+
): EchoObjectSchema<Self, Fields> => {
|
|
36
|
+
invariant(typeof TypeAnnotationId === 'symbol', 'Sanity.');
|
|
37
|
+
invariant(SchemaAST.isTypeLiteral(self.ast), 'Schema must be a TypeLiteral.');
|
|
38
|
+
|
|
39
|
+
// Extract fields from the schema if available (Struct schemas have .fields).
|
|
40
|
+
const fields = ((self as any).fields ?? {}) as Fields;
|
|
41
|
+
|
|
42
|
+
const schemaWithId = Schema.extend(self, Schema.Struct({ id: Schema.String }));
|
|
43
|
+
const ast = SchemaAST.annotations(schemaWithId.ast, {
|
|
44
|
+
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
45
|
+
...self.ast.annotations,
|
|
46
|
+
[TypeAnnotationId]: { kind: EntityKind.Object, typename, version } satisfies TypeAnnotation,
|
|
47
|
+
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
48
|
+
[SchemaAST.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
49
|
+
kind: EntityKind.Object,
|
|
50
|
+
typename,
|
|
51
|
+
version,
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return makeEchoTypeSchema<Self, EntityKind.Object, Fields>(fields, ast, typename, version, EntityKind.Object);
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
|
|
8
|
+
import { raise } from '@dxos/debug';
|
|
9
|
+
import { assertArgument, invariant } from '@dxos/invariant';
|
|
10
|
+
import { DXN } from '@dxos/keys';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
type TypeAnnotation,
|
|
14
|
+
TypeAnnotationId,
|
|
15
|
+
type TypeMeta,
|
|
16
|
+
getEntityKind,
|
|
17
|
+
getSchemaTypename,
|
|
18
|
+
getTypeIdentifierAnnotation,
|
|
19
|
+
makeTypeJsonSchemaAnnotation,
|
|
20
|
+
} from '../Annotation';
|
|
21
|
+
import {
|
|
22
|
+
ATTR_RELATION_SOURCE,
|
|
23
|
+
ATTR_RELATION_TARGET,
|
|
24
|
+
EntityKind,
|
|
25
|
+
RelationSourceDXNId,
|
|
26
|
+
RelationSourceId,
|
|
27
|
+
RelationTargetDXNId,
|
|
28
|
+
RelationTargetId,
|
|
29
|
+
} from '../common/types';
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
ATTR_RELATION_SOURCE,
|
|
33
|
+
ATTR_RELATION_TARGET,
|
|
34
|
+
RelationSourceDXNId,
|
|
35
|
+
RelationSourceId,
|
|
36
|
+
RelationTargetDXNId,
|
|
37
|
+
RelationTargetId,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
import { type EchoTypeSchema, makeEchoTypeSchema } from './entity';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Source and target props on relations.
|
|
44
|
+
*/
|
|
45
|
+
// TODO(burdon): any?
|
|
46
|
+
export type RelationSourceTargetRefs<Source = any, Target = any> = {
|
|
47
|
+
/**
|
|
48
|
+
* Source ECHO live object.
|
|
49
|
+
*/
|
|
50
|
+
[RelationSourceId]: Source;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Target ECHO live object.
|
|
54
|
+
*/
|
|
55
|
+
[RelationTargetId]: Target;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type RelationSource<R> = R extends RelationSourceTargetRefs<infer Source, infer _Target> ? Source : never;
|
|
59
|
+
export type RelationTarget<R> = R extends RelationSourceTargetRefs<infer _Source, infer Target> ? Target : never;
|
|
60
|
+
|
|
61
|
+
export type EchoRelationSchemaOptions<
|
|
62
|
+
TSource extends Schema.Schema.AnyNoContext,
|
|
63
|
+
TTarget extends Schema.Schema.AnyNoContext,
|
|
64
|
+
> = TypeMeta & {
|
|
65
|
+
source: TSource;
|
|
66
|
+
target: TTarget;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Relation schema type with kind marker.
|
|
71
|
+
*/
|
|
72
|
+
export type EchoRelationSchema<
|
|
73
|
+
Self extends Schema.Schema.Any,
|
|
74
|
+
Source extends Schema.Schema.AnyNoContext,
|
|
75
|
+
Target extends Schema.Schema.AnyNoContext,
|
|
76
|
+
Fields extends Schema.Struct.Fields = Schema.Struct.Fields,
|
|
77
|
+
> = EchoTypeSchema<
|
|
78
|
+
Self,
|
|
79
|
+
RelationSourceTargetRefs<Schema.Schema.Type<Source>, Schema.Schema.Type<Target>>,
|
|
80
|
+
EntityKind.Relation,
|
|
81
|
+
Fields
|
|
82
|
+
>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Schema for Relation entity types.
|
|
86
|
+
*/
|
|
87
|
+
export const EchoRelationSchema = <
|
|
88
|
+
Source extends Schema.Schema.AnyNoContext,
|
|
89
|
+
Target extends Schema.Schema.AnyNoContext,
|
|
90
|
+
>({
|
|
91
|
+
source,
|
|
92
|
+
target,
|
|
93
|
+
typename,
|
|
94
|
+
version,
|
|
95
|
+
}: EchoRelationSchemaOptions<Source, Target>) => {
|
|
96
|
+
assertArgument(Schema.isSchema(source), 'source');
|
|
97
|
+
assertArgument(Schema.isSchema(target), 'target');
|
|
98
|
+
const sourceDXN = getDXNForRelationSchemaRef(source);
|
|
99
|
+
const targetDXN = getDXNForRelationSchemaRef(target);
|
|
100
|
+
if (getEntityKind(source) !== EntityKind.Object) {
|
|
101
|
+
raise(new Error('Source schema must be an echo object schema.'));
|
|
102
|
+
}
|
|
103
|
+
if (getEntityKind(target) !== EntityKind.Object) {
|
|
104
|
+
raise(new Error('Target schema must be an echo object schema.'));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return <Self extends Schema.Schema.Any, Fields extends Schema.Struct.Fields = Schema.Struct.Fields>(
|
|
108
|
+
self: Self & { fields?: Fields },
|
|
109
|
+
): EchoRelationSchema<Self, Source, Target, Fields> => {
|
|
110
|
+
invariant(SchemaAST.isTypeLiteral(self.ast), 'Schema must be a TypeLiteral.');
|
|
111
|
+
|
|
112
|
+
// Extract fields from the schema if available (Struct schemas have .fields).
|
|
113
|
+
const fields = ((self as any).fields ?? {}) as Fields;
|
|
114
|
+
|
|
115
|
+
const schemaWithId = Schema.extend(self, Schema.Struct({ id: Schema.String }));
|
|
116
|
+
const ast = SchemaAST.annotations(schemaWithId.ast, {
|
|
117
|
+
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
118
|
+
...self.ast.annotations,
|
|
119
|
+
[TypeAnnotationId]: {
|
|
120
|
+
kind: EntityKind.Relation,
|
|
121
|
+
typename,
|
|
122
|
+
version,
|
|
123
|
+
sourceSchema: sourceDXN,
|
|
124
|
+
targetSchema: targetDXN,
|
|
125
|
+
} satisfies TypeAnnotation,
|
|
126
|
+
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
127
|
+
|
|
128
|
+
[SchemaAST.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
129
|
+
kind: EntityKind.Relation,
|
|
130
|
+
typename,
|
|
131
|
+
version,
|
|
132
|
+
relationSource: sourceDXN,
|
|
133
|
+
relationTarget: targetDXN,
|
|
134
|
+
}),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
return makeEchoTypeSchema<Self, EntityKind.Relation, Fields>(fields, ast, typename, version, EntityKind.Relation);
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const getDXNForRelationSchemaRef = (schema: Schema.Schema.Any): string => {
|
|
142
|
+
assertArgument(Schema.isSchema(schema), 'schema');
|
|
143
|
+
const identifier = getTypeIdentifierAnnotation(schema);
|
|
144
|
+
if (identifier) {
|
|
145
|
+
return identifier;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const typename = getSchemaTypename(schema);
|
|
149
|
+
if (!typename) {
|
|
150
|
+
throw new Error('Schema must have a typename');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return DXN.fromTypename(typename).toString();
|
|
154
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { assertArgument, invariant } from '@dxos/invariant';
|
|
8
|
+
import { DXN, ObjectId } from '@dxos/keys';
|
|
9
|
+
import { assumeType } from '@dxos/util';
|
|
10
|
+
|
|
11
|
+
import { type InternalObjectProps, SelfDXNId } from './model';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns a DXN for an object or schema.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export const getObjectDXN = (object: any): DXN | undefined => {
|
|
19
|
+
invariant(!Schema.isSchema(object), 'schema not allowed in this function');
|
|
20
|
+
assertArgument(typeof object === 'object' && object != null, 'object', 'expected object');
|
|
21
|
+
assumeType<InternalObjectProps>(object);
|
|
22
|
+
|
|
23
|
+
if (object[SelfDXNId]) {
|
|
24
|
+
invariant(object[SelfDXNId] instanceof DXN, 'Invalid object model: invalid self dxn');
|
|
25
|
+
return object[SelfDXNId];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!ObjectId.isValid(object.id)) {
|
|
29
|
+
throw new TypeError('Object id is not valid.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return DXN.fromLocalObjectId(object.id);
|
|
33
|
+
};
|