@dxos/echo 0.8.4-main.67995b8 → 0.8.4-main.69d29f4
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 +2 -3
- package/dist/lib/browser/Annotation.mjs +33 -0
- package/dist/lib/browser/Annotation.mjs.map +7 -0
- package/dist/lib/browser/Database.mjs +18 -0
- package/dist/lib/browser/Database.mjs.map +7 -0
- package/dist/lib/browser/Entity.mjs +52 -0
- package/dist/lib/browser/Entity.mjs.map +7 -0
- package/dist/lib/browser/Err.mjs +11 -0
- package/dist/lib/browser/Err.mjs.map +7 -0
- package/dist/lib/browser/Filter.mjs +62 -0
- package/dist/lib/browser/Filter.mjs.map +7 -0
- package/dist/lib/browser/Format.mjs +67 -0
- package/dist/lib/browser/Format.mjs.map +7 -0
- package/dist/lib/browser/JsonSchema.mjs +20 -0
- package/dist/lib/browser/JsonSchema.mjs.map +7 -0
- package/dist/lib/browser/Key.mjs +13 -0
- package/dist/lib/browser/Key.mjs.map +7 -0
- package/dist/lib/browser/Obj.mjs +91 -0
- package/dist/lib/browser/Obj.mjs.map +7 -0
- package/dist/lib/browser/Order.mjs +13 -0
- package/dist/lib/browser/Order.mjs.map +7 -0
- package/dist/lib/browser/Query.mjs +27 -0
- package/dist/lib/browser/Query.mjs.map +7 -0
- package/dist/lib/browser/QueryResult.mjs +3 -0
- package/dist/lib/browser/QueryResult.mjs.map +7 -0
- package/dist/lib/browser/Ref.mjs +23 -0
- package/dist/lib/browser/Ref.mjs.map +7 -0
- package/dist/lib/browser/Relation.mjs +85 -0
- package/dist/lib/browser/Relation.mjs.map +7 -0
- package/dist/lib/browser/SchemaRegistry.mjs +3 -0
- package/dist/lib/browser/SchemaRegistry.mjs.map +7 -0
- package/dist/lib/browser/Tag.mjs +26 -0
- package/dist/lib/browser/Tag.mjs.map +7 -0
- package/dist/lib/browser/Type.mjs +48 -0
- package/dist/lib/browser/Type.mjs.map +7 -0
- package/dist/lib/browser/chunk-2RMVRVOB.mjs +250 -0
- package/dist/lib/browser/chunk-2RMVRVOB.mjs.map +7 -0
- package/dist/lib/browser/chunk-5RDNDPMX.mjs +74 -0
- package/dist/lib/browser/chunk-5RDNDPMX.mjs.map +7 -0
- package/dist/lib/browser/chunk-73M2G455.mjs +98 -0
- package/dist/lib/browser/chunk-73M2G455.mjs.map +7 -0
- package/dist/lib/browser/chunk-7STIBCP7.mjs +133 -0
- package/dist/lib/browser/chunk-7STIBCP7.mjs.map +7 -0
- package/dist/lib/browser/chunk-AFGYYVVQ.mjs +57 -0
- package/dist/lib/browser/chunk-AFGYYVVQ.mjs.map +7 -0
- package/dist/lib/browser/chunk-BC6R4CAF.mjs +24 -0
- package/dist/lib/browser/chunk-BC6R4CAF.mjs.map +7 -0
- package/dist/lib/browser/chunk-BPYFLHWO.mjs +158 -0
- package/dist/lib/browser/chunk-BPYFLHWO.mjs.map +7 -0
- package/dist/lib/browser/chunk-CBPFF3ZO.mjs +204 -0
- package/dist/lib/browser/chunk-CBPFF3ZO.mjs.map +7 -0
- package/dist/lib/browser/chunk-CGS2ULMK.mjs +11 -0
- package/dist/lib/browser/chunk-CGS2ULMK.mjs.map +7 -0
- package/dist/lib/browser/chunk-CJ5YELTO.mjs +39 -0
- package/dist/lib/browser/chunk-CJ5YELTO.mjs.map +7 -0
- package/dist/lib/browser/chunk-FPOISFQK.mjs +40 -0
- package/dist/lib/browser/chunk-FPOISFQK.mjs.map +7 -0
- package/dist/lib/browser/chunk-INHXFXY5.mjs +22 -0
- package/dist/lib/browser/chunk-INHXFXY5.mjs.map +7 -0
- package/dist/lib/browser/chunk-IXVWLTG7.mjs +9 -0
- package/dist/lib/browser/chunk-IXVWLTG7.mjs.map +7 -0
- package/dist/lib/browser/chunk-JMKVF2YQ.mjs +43 -0
- package/dist/lib/browser/chunk-JMKVF2YQ.mjs.map +7 -0
- package/dist/lib/browser/chunk-L4RXUJHJ.mjs +143 -0
- package/dist/lib/browser/chunk-L4RXUJHJ.mjs.map +7 -0
- package/dist/lib/browser/chunk-MYCCGG2T.mjs +15 -0
- package/dist/lib/browser/chunk-MYCCGG2T.mjs.map +7 -0
- package/dist/lib/browser/chunk-PAM4KEXE.mjs +3847 -0
- package/dist/lib/browser/chunk-PAM4KEXE.mjs.map +7 -0
- package/dist/lib/browser/chunk-QIWDIPLR.mjs +41 -0
- package/dist/lib/browser/chunk-QIWDIPLR.mjs.map +7 -0
- package/dist/lib/browser/chunk-R3S54KRI.mjs +403 -0
- package/dist/lib/browser/chunk-R3S54KRI.mjs.map +7 -0
- package/dist/lib/browser/chunk-RK4Z4JUZ.mjs +283 -0
- package/dist/lib/browser/chunk-RK4Z4JUZ.mjs.map +7 -0
- package/dist/lib/browser/chunk-TPIL3G6Y.mjs +288 -0
- package/dist/lib/browser/chunk-TPIL3G6Y.mjs.map +7 -0
- package/dist/lib/browser/chunk-YKTSSMDS.mjs +69 -0
- package/dist/lib/browser/chunk-YKTSSMDS.mjs.map +7 -0
- package/dist/lib/browser/chunk-ZHXZGIXD.mjs +9 -0
- package/dist/lib/browser/chunk-ZHXZGIXD.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +72 -9
- package/dist/lib/browser/internal/index.mjs +457 -0
- package/dist/lib/browser/internal/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +332 -35
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/Annotation.mjs +33 -0
- package/dist/lib/node-esm/Annotation.mjs.map +7 -0
- package/dist/lib/node-esm/Database.mjs +18 -0
- package/dist/lib/node-esm/Database.mjs.map +7 -0
- package/dist/lib/node-esm/Entity.mjs +52 -0
- package/dist/lib/node-esm/Entity.mjs.map +7 -0
- package/dist/lib/node-esm/Err.mjs +11 -0
- package/dist/lib/node-esm/Err.mjs.map +7 -0
- package/dist/lib/node-esm/Filter.mjs +62 -0
- package/dist/lib/node-esm/Filter.mjs.map +7 -0
- package/dist/lib/node-esm/Format.mjs +67 -0
- package/dist/lib/node-esm/Format.mjs.map +7 -0
- package/dist/lib/node-esm/JsonSchema.mjs +20 -0
- package/dist/lib/node-esm/JsonSchema.mjs.map +7 -0
- package/dist/lib/node-esm/Key.mjs +13 -0
- package/dist/lib/node-esm/Key.mjs.map +7 -0
- package/dist/lib/node-esm/Obj.mjs +91 -0
- package/dist/lib/node-esm/Obj.mjs.map +7 -0
- package/dist/lib/node-esm/Order.mjs +13 -0
- package/dist/lib/node-esm/Order.mjs.map +7 -0
- package/dist/lib/node-esm/Query.mjs +27 -0
- package/dist/lib/node-esm/Query.mjs.map +7 -0
- package/dist/lib/node-esm/QueryResult.mjs +3 -0
- package/dist/lib/node-esm/QueryResult.mjs.map +7 -0
- package/dist/lib/node-esm/Ref.mjs +23 -0
- package/dist/lib/node-esm/Ref.mjs.map +7 -0
- package/dist/lib/node-esm/Relation.mjs +85 -0
- package/dist/lib/node-esm/Relation.mjs.map +7 -0
- package/dist/lib/node-esm/SchemaRegistry.mjs +3 -0
- package/dist/lib/node-esm/SchemaRegistry.mjs.map +7 -0
- package/dist/lib/node-esm/Tag.mjs +26 -0
- package/dist/lib/node-esm/Tag.mjs.map +7 -0
- package/dist/lib/node-esm/Type.mjs +48 -0
- package/dist/lib/node-esm/Type.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2RIFBW3A.mjs +250 -0
- package/dist/lib/node-esm/chunk-2RIFBW3A.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-5CB2ZW74.mjs +57 -0
- package/dist/lib/node-esm/chunk-5CB2ZW74.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-5U5F4AWK.mjs +3847 -0
- package/dist/lib/node-esm/chunk-5U5F4AWK.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-AJEMYSIR.mjs +22 -0
- package/dist/lib/node-esm/chunk-AJEMYSIR.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-BKYE5IW6.mjs +158 -0
- package/dist/lib/node-esm/chunk-BKYE5IW6.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-BYOD7EVP.mjs +98 -0
- package/dist/lib/node-esm/chunk-BYOD7EVP.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-FWTSPIFF.mjs +133 -0
- package/dist/lib/node-esm/chunk-FWTSPIFF.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-K37NA7PO.mjs +43 -0
- package/dist/lib/node-esm/chunk-K37NA7PO.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-LIXUCQJM.mjs +41 -0
- package/dist/lib/node-esm/chunk-LIXUCQJM.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-MOLNWFNL.mjs +9 -0
- package/dist/lib/node-esm/chunk-MOLNWFNL.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-MOWUEW5P.mjs +15 -0
- package/dist/lib/node-esm/chunk-MOWUEW5P.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NBWL7UCZ.mjs +40 -0
- package/dist/lib/node-esm/chunk-NBWL7UCZ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-OZEDKT4R.mjs +204 -0
- package/dist/lib/node-esm/chunk-OZEDKT4R.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-PW3VCWL5.mjs +24 -0
- package/dist/lib/node-esm/chunk-PW3VCWL5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-TSTKBFST.mjs +403 -0
- package/dist/lib/node-esm/chunk-TSTKBFST.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UKGVOINP.mjs +9 -0
- package/dist/lib/node-esm/chunk-UKGVOINP.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UV63HEHQ.mjs +143 -0
- package/dist/lib/node-esm/chunk-UV63HEHQ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-WXLVPCRJ.mjs +288 -0
- package/dist/lib/node-esm/chunk-WXLVPCRJ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-WZ6YBELW.mjs +74 -0
- package/dist/lib/node-esm/chunk-WZ6YBELW.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-XHJRMQZD.mjs +69 -0
- package/dist/lib/node-esm/chunk-XHJRMQZD.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YOLH5KS4.mjs +283 -0
- package/dist/lib/node-esm/chunk-YOLH5KS4.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YQ2NWGL5.mjs +39 -0
- package/dist/lib/node-esm/chunk-YQ2NWGL5.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +72 -9
- package/dist/lib/node-esm/internal/index.mjs +457 -0
- package/dist/lib/node-esm/internal/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +332 -35
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/Annotation.d.ts +2 -0
- package/dist/types/src/Annotation.d.ts.map +1 -0
- package/dist/types/src/Database.d.ts +194 -0
- package/dist/types/src/Database.d.ts.map +1 -0
- package/dist/types/src/Entity.d.ts +142 -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 +64 -0
- package/dist/types/src/Err.d.ts.map +1 -0
- package/dist/types/src/Filter.d.ts +120 -0
- package/dist/types/src/Filter.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 +60 -0
- package/dist/types/src/Hypergraph.d.ts.map +1 -0
- package/dist/types/src/JsonSchema.d.ts +9 -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/Obj.d.ts +344 -35
- 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 +115 -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 +13 -11
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +242 -19
- 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 +17 -0
- package/dist/types/src/Tag.d.ts.map +1 -0
- package/dist/types/src/Type.d.ts +225 -73
- 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/index.d.ts +15 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/annotations/annotations.d.ts +170 -0
- package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/annotations.test.d.ts +2 -0
- package/dist/types/src/internal/annotations/annotations.test.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/index.d.ts +3 -0
- package/dist/types/src/internal/annotations/index.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/util.d.ts +27 -0
- package/dist/types/src/internal/annotations/util.d.ts.map +1 -0
- package/dist/types/src/internal/api/annotations.d.ts +23 -0
- package/dist/types/src/internal/api/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/api/entity.d.ts +13 -0
- package/dist/types/src/internal/api/entity.d.ts.map +1 -0
- package/dist/types/src/internal/api/index.d.ts +15 -0
- package/dist/types/src/internal/api/index.d.ts.map +1 -0
- package/dist/types/src/internal/api/meta.d.ts +42 -0
- package/dist/types/src/internal/api/meta.d.ts.map +1 -0
- package/dist/types/src/internal/api/sorting.d.ts +24 -0
- package/dist/types/src/internal/api/sorting.d.ts.map +1 -0
- package/dist/types/src/internal/api/version.d.ts +42 -0
- package/dist/types/src/internal/api/version.d.ts.map +1 -0
- package/dist/types/src/internal/entities/entity.d.ts +20 -0
- package/dist/types/src/internal/entities/entity.d.ts.map +1 -0
- package/dist/types/src/internal/entities/index.d.ts +6 -0
- package/dist/types/src/internal/entities/index.d.ts.map +1 -0
- package/dist/types/src/internal/entities/model.d.ts +77 -0
- package/dist/types/src/internal/entities/model.d.ts.map +1 -0
- package/dist/types/src/internal/entities/object.d.ts +18 -0
- package/dist/types/src/internal/entities/object.d.ts.map +1 -0
- package/dist/types/src/internal/entities/relation.d.ts +62 -0
- package/dist/types/src/internal/entities/relation.d.ts.map +1 -0
- package/dist/types/src/internal/entities/util.d.ts +2 -0
- package/dist/types/src/internal/entities/util.d.ts.map +1 -0
- package/dist/types/src/internal/formats/date.d.ts +63 -0
- package/dist/types/src/internal/formats/date.d.ts.map +1 -0
- package/dist/types/src/internal/formats/date.test.d.ts +2 -0
- package/dist/types/src/internal/formats/date.test.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.d.ts +32 -0
- package/dist/types/src/internal/formats/format.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.test.d.ts +2 -0
- package/dist/types/src/internal/formats/format.test.d.ts.map +1 -0
- package/dist/types/src/internal/formats/index.d.ts +8 -0
- package/dist/types/src/internal/formats/index.d.ts.map +1 -0
- package/dist/types/src/internal/formats/number.d.ts +31 -0
- package/dist/types/src/internal/formats/number.d.ts.map +1 -0
- package/dist/types/src/internal/formats/object.d.ts +35 -0
- package/dist/types/src/internal/formats/object.d.ts.map +1 -0
- package/dist/types/src/internal/formats/select.d.ts +13 -0
- package/dist/types/src/internal/formats/select.d.ts.map +1 -0
- package/dist/types/src/internal/formats/string.d.ts +42 -0
- package/dist/types/src/internal/formats/string.d.ts.map +1 -0
- package/dist/types/src/internal/formats/types.d.ts +72 -0
- package/dist/types/src/internal/formats/types.d.ts.map +1 -0
- package/dist/types/src/internal/index.d.ts +12 -0
- package/dist/types/src/internal/index.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/annotations.d.ts +19 -0
- package/dist/types/src/internal/json-schema/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/effect-schema.test.d.ts +2 -0
- package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/index.d.ts +5 -0
- package/dist/types/src/internal/json-schema/index.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts +7 -0
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts +351 -0
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema.d.ts +30 -0
- package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema.test.d.ts +2 -0
- package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/clone.d.ts +8 -0
- package/dist/types/src/internal/object/clone.d.ts.map +1 -0
- package/dist/types/src/internal/object/common.d.ts +18 -0
- package/dist/types/src/internal/object/common.d.ts.map +1 -0
- package/dist/types/src/internal/object/create-object.d.ts +39 -0
- package/dist/types/src/internal/object/create-object.d.ts.map +1 -0
- package/dist/types/src/internal/object/create-object.test.d.ts +2 -0
- package/dist/types/src/internal/object/create-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/deleted.d.ts +6 -0
- package/dist/types/src/internal/object/deleted.d.ts.map +1 -0
- package/dist/types/src/internal/object/ids.d.ts +6 -0
- package/dist/types/src/internal/object/ids.d.ts.map +1 -0
- package/dist/types/src/internal/object/index.d.ts +11 -0
- package/dist/types/src/internal/object/index.d.ts.map +1 -0
- package/dist/types/src/internal/object/inspect.d.ts +2 -0
- package/dist/types/src/internal/object/inspect.d.ts.map +1 -0
- package/dist/types/src/internal/object/json-serializer.d.ts +37 -0
- package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/object/json-serializer.test.d.ts +2 -0
- package/dist/types/src/internal/object/json-serializer.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/schema-validator.d.ts +2 -0
- package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/object/schema-validator.test.d.ts +2 -0
- package/dist/types/src/internal/object/schema-validator.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/set-value.d.ts +7 -0
- package/dist/types/src/internal/object/set-value.d.ts.map +1 -0
- package/dist/types/src/internal/object/set-value.test.d.ts +2 -0
- package/dist/types/src/internal/object/set-value.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/snapshot.d.ts +6 -0
- package/dist/types/src/internal/object/snapshot.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-object.d.ts +25 -0
- package/dist/types/src/internal/object/typed-object.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/object/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/change-context.d.ts +55 -0
- package/dist/types/src/internal/proxy/change-context.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/change.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/change.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/define-hidden-property.d.ts +5 -0
- package/dist/types/src/internal/proxy/define-hidden-property.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/errors.d.ts +19 -0
- package/dist/types/src/internal/proxy/errors.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/event-batch.d.ts +10 -0
- package/dist/types/src/internal/proxy/event-batch.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/handler.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/index.d.ts +14 -0
- package/dist/types/src/internal/proxy/index.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/json-serializer.d.ts +6 -0
- package/dist/types/src/internal/proxy/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/make-object.d.ts +14 -0
- package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/ownership.d.ts +57 -0
- package/dist/types/src/internal/proxy/ownership.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/proxy-types.d.ts +18 -0
- package/dist/types/src/internal/proxy/proxy-types.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/proxy-utils.d.ts +47 -0
- package/dist/types/src/internal/proxy/proxy-utils.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/reactive-array.d.ts +8 -0
- package/dist/types/src/internal/proxy/reactive-array.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/reactive.d.ts +39 -0
- package/dist/types/src/internal/proxy/reactive.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/schema-validator.d.ts +15 -0
- package/dist/types/src/internal/proxy/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/schema.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/symbols.d.ts +3 -0
- package/dist/types/src/internal/proxy/symbols.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts +47 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/ref/index.d.ts +3 -0
- package/dist/types/src/internal/ref/index.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref-array.d.ts +21 -0
- package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref.d.ts +218 -0
- package/dist/types/src/internal/ref/ref.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref.test.d.ts +2 -0
- package/dist/types/src/internal/ref/ref.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/compose.d.ts +7 -0
- package/dist/types/src/internal/schema/compose.d.ts.map +1 -0
- package/dist/types/src/internal/schema/compose.test.d.ts +2 -0
- package/dist/types/src/internal/schema/compose.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts +180 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -0
- package/dist/types/src/internal/schema/index.d.ts +4 -0
- package/dist/types/src/internal/schema/index.d.ts.map +1 -0
- package/dist/types/src/internal/schema/manipulation.d.ts +10 -0
- package/dist/types/src/internal/schema/manipulation.d.ts.map +1 -0
- package/dist/types/src/internal/schema/persistent-schema.d.ts +20 -0
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -0
- package/dist/types/src/internal/types/base.d.ts +26 -0
- package/dist/types/src/internal/types/base.d.ts.map +1 -0
- package/dist/types/src/internal/types/entity.d.ts +37 -0
- package/dist/types/src/internal/types/entity.d.ts.map +1 -0
- package/dist/types/src/internal/types/index.d.ts +6 -0
- package/dist/types/src/internal/types/index.d.ts.map +1 -0
- package/dist/types/src/internal/types/meta.d.ts +32 -0
- package/dist/types/src/internal/types/meta.d.ts.map +1 -0
- package/dist/types/src/internal/types/typename.d.ts +13 -0
- package/dist/types/src/internal/types/typename.d.ts.map +1 -0
- package/dist/types/src/internal/types/version.d.ts +15 -0
- package/dist/types/src/internal/types/version.d.ts.map +1 -0
- package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +3 -1
- 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 +303 -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 +169 -42
- package/src/Annotation.ts +18 -0
- package/src/Database.ts +336 -0
- package/src/Entity.test.ts +22 -0
- package/src/Entity.ts +217 -0
- package/src/Err.ts +18 -0
- package/src/Filter.ts +376 -0
- package/src/Format.ts +9 -0
- package/src/Hypergraph.ts +74 -0
- package/src/JsonSchema.ts +16 -0
- package/src/Key.ts +3 -0
- package/src/Obj.test.ts +386 -0
- package/src/Obj.ts +508 -84
- package/src/Order.ts +44 -0
- package/src/Query.test.ts +465 -0
- package/src/Query.ts +296 -0
- package/src/QueryResult.ts +106 -0
- package/src/Ref.ts +25 -9
- package/src/Relation.test.ts +82 -0
- package/src/Relation.ts +414 -51
- package/src/SchemaRegistry.ts +105 -0
- package/src/Tag.ts +40 -0
- package/src/Type.test.ts +52 -0
- package/src/Type.ts +360 -112
- package/src/index.ts +17 -4
- package/src/internal/README.md +102 -0
- package/src/internal/annotations/annotations.test.ts +96 -0
- package/src/internal/annotations/annotations.ts +460 -0
- package/src/internal/annotations/index.ts +6 -0
- package/src/internal/annotations/util.ts +72 -0
- package/src/internal/api/annotations.ts +60 -0
- package/src/internal/api/entity.ts +29 -0
- package/src/internal/api/index.ts +19 -0
- package/src/internal/api/meta.ts +88 -0
- package/src/internal/api/sorting.ts +53 -0
- package/src/internal/api/version.ts +96 -0
- package/src/internal/entities/entity.ts +126 -0
- package/src/internal/entities/index.ts +9 -0
- package/src/internal/entities/model.ts +134 -0
- package/src/internal/entities/object.ts +58 -0
- package/src/internal/entities/relation.ts +171 -0
- package/src/internal/entities/util.ts +33 -0
- package/src/internal/formats/date.test.ts +56 -0
- package/src/internal/formats/date.ts +217 -0
- package/src/internal/formats/format.test.ts +77 -0
- package/src/internal/formats/format.ts +54 -0
- package/src/internal/formats/index.ts +12 -0
- package/src/internal/formats/number.ts +89 -0
- package/src/internal/formats/object.ts +80 -0
- package/src/internal/formats/select.ts +18 -0
- package/src/internal/formats/string.ts +81 -0
- package/src/internal/formats/types.ts +186 -0
- package/src/internal/index.ts +39 -0
- package/src/internal/json-schema/annotations.ts +50 -0
- package/src/internal/json-schema/effect-schema.test.ts +143 -0
- package/src/internal/json-schema/index.ts +8 -0
- package/src/internal/json-schema/json-schema-normalize.ts +111 -0
- package/src/internal/json-schema/json-schema-type.ts +403 -0
- package/src/internal/json-schema/json-schema.test.ts +861 -0
- package/src/internal/json-schema/json-schema.ts +532 -0
- package/src/internal/object/clone.ts +48 -0
- package/src/internal/object/common.ts +75 -0
- package/src/internal/object/create-object.test.ts +116 -0
- package/src/internal/object/create-object.ts +95 -0
- package/src/internal/object/deleted.ts +19 -0
- package/src/internal/object/ids.ts +12 -0
- package/src/internal/object/index.ts +14 -0
- package/src/internal/object/inspect.ts +46 -0
- package/src/internal/object/json-serializer.test.ts +98 -0
- package/src/internal/object/json-serializer.ts +188 -0
- package/src/internal/object/schema-validator.test.ts +182 -0
- package/src/internal/object/schema-validator.ts +6 -0
- package/src/internal/object/set-value.test.ts +281 -0
- package/src/internal/object/set-value.ts +165 -0
- package/src/internal/object/snapshot.ts +70 -0
- package/src/internal/object/typed-object.test.ts +34 -0
- package/src/internal/object/typed-object.ts +30 -0
- package/src/internal/proxy/change-context.ts +138 -0
- package/src/internal/proxy/change.test.ts +519 -0
- package/src/internal/proxy/define-hidden-property.ts +14 -0
- package/src/internal/proxy/errors.ts +42 -0
- package/src/internal/proxy/event-batch.ts +44 -0
- package/src/internal/proxy/handler.test.ts +123 -0
- package/src/internal/proxy/index.ts +17 -0
- package/src/internal/proxy/json-serializer.ts +87 -0
- package/src/internal/proxy/make-object.ts +96 -0
- package/src/internal/proxy/ownership.ts +253 -0
- package/src/internal/proxy/proxy-types.ts +23 -0
- package/src/internal/proxy/proxy-utils.ts +150 -0
- package/src/internal/proxy/reactive-array.ts +71 -0
- package/src/internal/proxy/reactive.ts +69 -0
- package/src/internal/proxy/schema-validator.ts +244 -0
- package/src/internal/proxy/schema.test.ts +145 -0
- package/src/internal/proxy/symbols.ts +7 -0
- package/src/internal/proxy/typed-handler.test.ts +314 -0
- package/src/internal/proxy/typed-handler.ts +442 -0
- package/src/internal/proxy/typed-object.test.ts +116 -0
- package/src/internal/ref/index.ts +6 -0
- package/src/internal/ref/ref-array.ts +39 -0
- package/src/internal/ref/ref.test.ts +101 -0
- package/src/internal/ref/ref.ts +549 -0
- package/src/internal/schema/compose.test.ts +42 -0
- package/src/internal/schema/compose.ts +41 -0
- package/src/internal/schema/echo-schema.ts +423 -0
- package/src/internal/schema/index.ts +7 -0
- package/src/internal/schema/manipulation.ts +92 -0
- package/src/internal/schema/persistent-schema.ts +27 -0
- package/src/internal/types/base.ts +43 -0
- package/src/internal/types/entity.ts +54 -0
- package/src/internal/types/index.ts +9 -0
- package/src/internal/types/meta.ts +65 -0
- package/src/internal/types/typename.ts +45 -0
- package/src/internal/types/version.ts +20 -0
- package/src/testing/api.test.ts +126 -0
- package/src/testing/index.ts +3 -1
- package/src/testing/test-data.ts +130 -0
- package/src/testing/test-schema.ts +238 -0
- package/src/testing/util.ts +85 -0
- package/dist/lib/browser/chunk-EUA7CM23.mjs +0 -619
- package/dist/lib/browser/chunk-EUA7CM23.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-IV6BWGHK.mjs +0 -619
- package/dist/lib/node-esm/chunk-IV6BWGHK.mjs.map +0 -7
- package/dist/types/src/experimental/database.d.ts +0 -8
- package/dist/types/src/experimental/database.d.ts.map +0 -1
- package/dist/types/src/experimental/index.d.ts +0 -1
- package/dist/types/src/experimental/index.d.ts.map +0 -1
- package/dist/types/src/experimental/queue.d.ts +0 -8
- package/dist/types/src/experimental/queue.d.ts.map +0 -1
- package/dist/types/src/experimental/space.d.ts +0 -8
- package/dist/types/src/experimental/space.d.ts.map +0 -1
- package/dist/types/src/query/dsl.d.ts +0 -218
- package/dist/types/src/query/dsl.d.ts.map +0 -1
- package/dist/types/src/query/dsl.test.d.ts +0 -2
- package/dist/types/src/query/dsl.test.d.ts.map +0 -1
- package/dist/types/src/query/index.d.ts +0 -2
- package/dist/types/src/query/index.d.ts.map +0 -1
- package/dist/types/src/testing/types.d.ts +0 -113
- package/dist/types/src/testing/types.d.ts.map +0 -1
- package/src/experimental/database.ts +0 -11
- package/src/experimental/index.ts +0 -7
- package/src/experimental/queue.ts +0 -11
- package/src/experimental/space.ts +0 -11
- package/src/query/dsl.test.ts +0 -323
- package/src/query/dsl.ts +0 -646
- package/src/query/index.ts +0 -5
- package/src/test/api.test.ts +0 -173
- package/src/testing/types.ts +0 -91
- /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Array from 'effect/Array';
|
|
6
|
+
import * as Function from 'effect/Function';
|
|
7
|
+
import * as JSONSchema from 'effect/JSONSchema';
|
|
8
|
+
import * as Option from 'effect/Option';
|
|
9
|
+
import * as Schema from 'effect/Schema';
|
|
10
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
11
|
+
import type * as Types from 'effect/Types';
|
|
12
|
+
|
|
13
|
+
import { raise } from '@dxos/debug';
|
|
14
|
+
import { mapAst } from '@dxos/effect';
|
|
15
|
+
import { assertArgument, invariant } from '@dxos/invariant';
|
|
16
|
+
import { DXN, ObjectId } from '@dxos/keys';
|
|
17
|
+
import { log } from '@dxos/log';
|
|
18
|
+
import { clearUndefined, orderKeys, removeProperties } from '@dxos/util';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
type TypeAnnotation,
|
|
22
|
+
TypeAnnotationId,
|
|
23
|
+
TypeIdentifierAnnotationId,
|
|
24
|
+
makeTypeJsonSchemaAnnotation,
|
|
25
|
+
} from '../annotations';
|
|
26
|
+
import { type JsonSchemaReferenceInfo, createEchoReferenceSchema } from '../ref';
|
|
27
|
+
import { ANY_OBJECT_TYPENAME, ANY_OBJECT_VERSION, EntityKind, EntityKindSchema } from '../types';
|
|
28
|
+
|
|
29
|
+
import { CustomAnnotations, DecodedAnnotations, EchoAnnotations } from './annotations';
|
|
30
|
+
import {
|
|
31
|
+
ECHO_ANNOTATIONS_NS_DEPRECATED_KEY,
|
|
32
|
+
ECHO_ANNOTATIONS_NS_KEY,
|
|
33
|
+
type JsonSchemaEchoAnnotations,
|
|
34
|
+
type JsonSchemaType,
|
|
35
|
+
getNormalizedEchoAnnotations,
|
|
36
|
+
} from './json-schema-type';
|
|
37
|
+
|
|
38
|
+
// TODO(burdon): Are these values stored (can they be changed?)
|
|
39
|
+
export enum PropType {
|
|
40
|
+
NONE = 0,
|
|
41
|
+
STRING = 1, // TODO(burdon): vs TEXT?
|
|
42
|
+
NUMBER = 2,
|
|
43
|
+
BOOLEAN = 3,
|
|
44
|
+
DATE = 4,
|
|
45
|
+
REF = 5,
|
|
46
|
+
RECORD = 6,
|
|
47
|
+
ENUM = 7,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// TODO(burdon): Reconcile with @dxos/schema.
|
|
51
|
+
export const toPropType = (type?: PropType): string => {
|
|
52
|
+
switch (type) {
|
|
53
|
+
case PropType.STRING:
|
|
54
|
+
return 'string';
|
|
55
|
+
case PropType.NUMBER:
|
|
56
|
+
return 'number';
|
|
57
|
+
case PropType.BOOLEAN:
|
|
58
|
+
return 'boolean';
|
|
59
|
+
case PropType.DATE:
|
|
60
|
+
return 'date';
|
|
61
|
+
case PropType.REF:
|
|
62
|
+
return 'ref';
|
|
63
|
+
case PropType.RECORD:
|
|
64
|
+
return 'object';
|
|
65
|
+
default:
|
|
66
|
+
throw new Error(`Invalid type: ${type}`);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const JSON_SCHEMA_URL = 'http://json-schema.org/draft-07/schema#';
|
|
71
|
+
|
|
72
|
+
export type JsonSchemaOptions = {
|
|
73
|
+
strict?: boolean;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Convert effect schema to JSON Schema.
|
|
78
|
+
* NOTE: This handles custom annotations.
|
|
79
|
+
* @param schema
|
|
80
|
+
*/
|
|
81
|
+
// TODO(burdon): Reconcile with possibly extending @effect/Schema/JSONSchema
|
|
82
|
+
// We add additional propertyOrder (but the object properties ARE ordered); and type "string" for literals.
|
|
83
|
+
// TODO(wittjosiah): This is mutable because its a pojo, perhaps should be left as readonly at type level though?
|
|
84
|
+
export const toJsonSchema = (
|
|
85
|
+
schema: Schema.Schema.All,
|
|
86
|
+
options: JsonSchemaOptions = {},
|
|
87
|
+
): Types.DeepMutable<JsonSchemaType> => {
|
|
88
|
+
assertArgument(Schema.isSchema(schema), 'schema');
|
|
89
|
+
let jsonSchema = _toJsonSchemaAST(schema.ast);
|
|
90
|
+
if (options.strict) {
|
|
91
|
+
// TOOD(burdon): Workaround to ensure JSON schema is valid (for agv parsing).
|
|
92
|
+
jsonSchema = removeProperties(jsonSchema, (key, value) => {
|
|
93
|
+
if (key === '$id' && value === '/schemas/any') {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (key === '$ref' && value === '#/$defs/dependency') {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
if (key === '$ref' && value === '#/$defs/jsonSchema') {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return false;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return jsonSchema;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const _toJsonSchemaAST = (ast: SchemaAST.AST): Types.DeepMutable<JsonSchemaType> => {
|
|
111
|
+
const withRefinements = withEchoRefinements(ast, '#');
|
|
112
|
+
const jsonSchema = JSONSchema.fromAST(withRefinements, {
|
|
113
|
+
definitions: {},
|
|
114
|
+
}) as Types.DeepMutable<JsonSchemaType>;
|
|
115
|
+
|
|
116
|
+
return normalizeJsonSchema(jsonSchema);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const withEchoRefinements = (
|
|
120
|
+
ast: SchemaAST.AST,
|
|
121
|
+
path: string | undefined,
|
|
122
|
+
suspendCache = new Map<SchemaAST.AST, string>(),
|
|
123
|
+
): SchemaAST.AST => {
|
|
124
|
+
if (path) {
|
|
125
|
+
suspendCache.set(ast, path);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let recursiveResult: SchemaAST.AST;
|
|
129
|
+
if (SchemaAST.isSuspend(ast)) {
|
|
130
|
+
// Precompute JSON schema for suspended AST since effect serializer does not support it.
|
|
131
|
+
const suspendedAst = ast.f();
|
|
132
|
+
const cachedPath = suspendCache.get(suspendedAst);
|
|
133
|
+
if (cachedPath) {
|
|
134
|
+
recursiveResult = new SchemaAST.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {
|
|
135
|
+
[SchemaAST.JSONSchemaAnnotationId]: {
|
|
136
|
+
$ref: cachedPath,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
const jsonSchema = _toJsonSchemaAST(suspendedAst);
|
|
141
|
+
recursiveResult = new SchemaAST.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {
|
|
142
|
+
[SchemaAST.JSONSchemaAnnotationId]: jsonSchema,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
} else if (SchemaAST.isTypeLiteral(ast)) {
|
|
146
|
+
// Add property order annotations
|
|
147
|
+
recursiveResult = mapAst(ast, (ast, key) =>
|
|
148
|
+
withEchoRefinements(ast, path && typeof key === 'string' ? `${path}/${key}` : undefined, suspendCache),
|
|
149
|
+
);
|
|
150
|
+
recursiveResult = addJsonSchemaFields(recursiveResult, {
|
|
151
|
+
propertyOrder: [...ast.propertySignatures.map((p) => p.name)] as string[],
|
|
152
|
+
});
|
|
153
|
+
} else if (SchemaAST.isUndefinedKeyword(ast)) {
|
|
154
|
+
// Ignore undefined keyword that appears in the optional fields.
|
|
155
|
+
return ast;
|
|
156
|
+
} else {
|
|
157
|
+
recursiveResult = mapAst(ast, (ast, key) =>
|
|
158
|
+
withEchoRefinements(
|
|
159
|
+
ast,
|
|
160
|
+
path && (typeof key === 'string' || typeof key === 'number') ? `${path}/${key}` : undefined,
|
|
161
|
+
suspendCache,
|
|
162
|
+
),
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const annotationFields = annotations_toJsonSchemaFields(ast.annotations);
|
|
167
|
+
if (Object.keys(annotationFields).length === 0) {
|
|
168
|
+
return recursiveResult;
|
|
169
|
+
} else {
|
|
170
|
+
return addJsonSchemaFields(recursiveResult, annotationFields);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Convert JSON schema to effect schema.
|
|
176
|
+
* @param root
|
|
177
|
+
* @param definitions
|
|
178
|
+
*/
|
|
179
|
+
export const toEffectSchema = (root: JsonSchemaType, _defs?: JsonSchemaType['$defs']): Schema.Schema.AnyNoContext => {
|
|
180
|
+
const defs = root.$defs ? { ..._defs, ...root.$defs } : (_defs ?? {});
|
|
181
|
+
if ('type' in root && root.type === 'object') {
|
|
182
|
+
return objectToEffectSchema(root, defs);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let result: Schema.Schema.AnyNoContext = Schema.Unknown;
|
|
186
|
+
if ('$ref' in root) {
|
|
187
|
+
switch (root.$ref) {
|
|
188
|
+
case '/schemas/echo/ref': {
|
|
189
|
+
result = refToEffectSchema(root);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
} else if ('$id' in root) {
|
|
194
|
+
switch (root.$id as string) {
|
|
195
|
+
case '/schemas/any': {
|
|
196
|
+
result = anyToEffectSchema(root as JSONSchema.JsonSchema7Any);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case '/schemas/unknown': {
|
|
200
|
+
result = Schema.Unknown;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
case '/schemas/{}':
|
|
204
|
+
case '/schemas/object': {
|
|
205
|
+
result = Schema.Object;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
// Custom ECHO object reference.
|
|
209
|
+
case '/schemas/echo/ref': {
|
|
210
|
+
result = refToEffectSchema(root);
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
} else if ('enum' in root) {
|
|
215
|
+
result = Schema.Union(...root.enum!.map((e) => Schema.Literal(e)));
|
|
216
|
+
} else if ('oneOf' in root) {
|
|
217
|
+
result = Schema.Union(...root.oneOf!.map((v) => toEffectSchema(v, defs)));
|
|
218
|
+
} else if ('anyOf' in root) {
|
|
219
|
+
result = Schema.Union(...root.anyOf!.map((v) => toEffectSchema(v, defs)));
|
|
220
|
+
} else if ('allOf' in root) {
|
|
221
|
+
if (root.allOf!.length === 1) {
|
|
222
|
+
result = toEffectSchema(root.allOf![0], defs);
|
|
223
|
+
} else {
|
|
224
|
+
log.warn('allOf with multiple schemas is not supported');
|
|
225
|
+
result = Schema.Unknown;
|
|
226
|
+
}
|
|
227
|
+
} else if ('type' in root) {
|
|
228
|
+
switch (root.type) {
|
|
229
|
+
case 'string': {
|
|
230
|
+
result = Schema.String;
|
|
231
|
+
if (root.pattern) {
|
|
232
|
+
result = result.pipe(Schema.pattern(new RegExp(root.pattern)));
|
|
233
|
+
}
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
case 'number': {
|
|
237
|
+
result = Schema.Number;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case 'integer': {
|
|
241
|
+
result = Schema.Number.pipe(Schema.int());
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
case 'boolean': {
|
|
245
|
+
result = Schema.Boolean;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
case 'array': {
|
|
249
|
+
if (Array.isArray(root.items)) {
|
|
250
|
+
const [required, optional] = Function.pipe(
|
|
251
|
+
root.items,
|
|
252
|
+
Array.map((v) => toEffectSchema(v as JsonSchemaType, defs)),
|
|
253
|
+
Array.splitAt(root.minItems ?? root.items.length),
|
|
254
|
+
);
|
|
255
|
+
result = Schema.Tuple(...required, ...optional.map(Schema.optionalElement));
|
|
256
|
+
} else {
|
|
257
|
+
invariant(root.items);
|
|
258
|
+
const items = root.items;
|
|
259
|
+
result = Array.isArray(items)
|
|
260
|
+
? Schema.Tuple(...items.map((v) => toEffectSchema(v as JsonSchemaType, defs)))
|
|
261
|
+
: Schema.Array(toEffectSchema(items as JsonSchemaType, defs));
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
case 'null': {
|
|
266
|
+
result = Schema.Null;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
} else if ('$ref' in root) {
|
|
271
|
+
const refSegments = root.$ref!.split('/');
|
|
272
|
+
const jsonSchema = defs[refSegments[refSegments.length - 1]];
|
|
273
|
+
invariant(jsonSchema, `missing definition for ${root.$ref}`);
|
|
274
|
+
result = toEffectSchema(jsonSchema, defs).pipe(
|
|
275
|
+
Schema.annotations({ identifier: refSegments[refSegments.length - 1] }),
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const annotations = jsonSchemaFieldsToAnnotations(root);
|
|
280
|
+
|
|
281
|
+
// log.info('toEffectSchema', { root, annotations });
|
|
282
|
+
result = result.annotations(annotations);
|
|
283
|
+
|
|
284
|
+
return result;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const objectToEffectSchema = (root: JsonSchemaType, defs: JsonSchemaType['$defs']): Schema.Schema.AnyNoContext => {
|
|
288
|
+
invariant('type' in root && root.type === 'object', `not an object: ${root}`);
|
|
289
|
+
|
|
290
|
+
const echoRefinement: JsonSchemaEchoAnnotations = (root as any)[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
|
|
291
|
+
const isEchoObject =
|
|
292
|
+
echoRefinement != null || ('$id' in root && typeof root.$id === 'string' && root.$id.startsWith('dxn:'));
|
|
293
|
+
|
|
294
|
+
let fields: Schema.Struct.Fields = {};
|
|
295
|
+
const propertyList = Object.entries(root.properties ?? {});
|
|
296
|
+
let immutableIdField: Schema.Schema.AnyNoContext | undefined;
|
|
297
|
+
for (const [key, value] of propertyList) {
|
|
298
|
+
if (isEchoObject && key === 'id') {
|
|
299
|
+
immutableIdField = toEffectSchema(value, defs);
|
|
300
|
+
} else {
|
|
301
|
+
// TODO(burdon): Mutable cast.
|
|
302
|
+
(fields as any)[key] = root.required?.includes(key)
|
|
303
|
+
? toEffectSchema(value, defs)
|
|
304
|
+
: Schema.optional(toEffectSchema(value, defs));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (root.propertyOrder) {
|
|
309
|
+
fields = orderKeys(fields, root.propertyOrder as any);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
let schema: Schema.Schema<any, any, unknown>;
|
|
313
|
+
if (root.patternProperties) {
|
|
314
|
+
invariant(propertyList.length === 0, 'pattern properties mixed with regular properties are not supported');
|
|
315
|
+
invariant(
|
|
316
|
+
Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === '',
|
|
317
|
+
'only one pattern property is supported',
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
schema = Schema.Record({ key: Schema.String, value: toEffectSchema(root.patternProperties[''], defs) });
|
|
321
|
+
} else if (typeof root.additionalProperties !== 'object') {
|
|
322
|
+
schema = Schema.Struct(fields);
|
|
323
|
+
} else {
|
|
324
|
+
const indexValue = toEffectSchema(root.additionalProperties, defs);
|
|
325
|
+
if (propertyList.length > 0) {
|
|
326
|
+
schema = Schema.Struct(fields, { key: Schema.String, value: indexValue });
|
|
327
|
+
} else {
|
|
328
|
+
schema = Schema.Record({ key: Schema.String, value: indexValue });
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (immutableIdField) {
|
|
333
|
+
schema = Schema.extend(schema, Schema.Struct({ id: immutableIdField }));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const annotations = jsonSchemaFieldsToAnnotations(root);
|
|
337
|
+
return schema.annotations(annotations) as any;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const anyToEffectSchema = (root: JSONSchema.JsonSchema7Any): Schema.Schema.AnyNoContext => {
|
|
341
|
+
const echoRefinement: JsonSchemaEchoAnnotations = (root as any)[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
|
|
342
|
+
// TODO(dmaretskyi): Is this branch still taken?
|
|
343
|
+
if ((echoRefinement as any)?.reference != null) {
|
|
344
|
+
const echoId = root.$id.startsWith('dxn:echo:') ? root.$id : undefined;
|
|
345
|
+
return createEchoReferenceSchema(
|
|
346
|
+
echoId,
|
|
347
|
+
(echoRefinement as any).reference.typename,
|
|
348
|
+
(echoRefinement as any).reference.version,
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return Schema.Any;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// TODO(dmaretskyi): Types.
|
|
356
|
+
const refToEffectSchema = (root: any): Schema.Schema.AnyNoContext => {
|
|
357
|
+
if (!('reference' in root)) {
|
|
358
|
+
// Fallback to generic object ref when no reference info is provided.
|
|
359
|
+
return createEchoReferenceSchema(undefined, ANY_OBJECT_TYPENAME, ANY_OBJECT_VERSION);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const reference: JsonSchemaReferenceInfo = root.reference;
|
|
363
|
+
if (typeof reference !== 'object') {
|
|
364
|
+
throw new Error('Invalid reference field in ref schema');
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const targetSchemaDXN = DXN.parse(reference.schema.$ref);
|
|
368
|
+
invariant(targetSchemaDXN.kind === DXN.kind.TYPE);
|
|
369
|
+
|
|
370
|
+
return createEchoReferenceSchema(
|
|
371
|
+
targetSchemaDXN.toString(),
|
|
372
|
+
targetSchemaDXN.kind === DXN.kind.TYPE ? targetSchemaDXN.parts[0] : undefined,
|
|
373
|
+
reference.schemaVersion,
|
|
374
|
+
);
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
//
|
|
378
|
+
// Annotations
|
|
379
|
+
//
|
|
380
|
+
|
|
381
|
+
const annotations_toJsonSchemaFields = (annotations: SchemaAST.Annotations): Record<symbol, any> => {
|
|
382
|
+
const schemaFields: Record<string, any> = {};
|
|
383
|
+
|
|
384
|
+
const echoAnnotations: Types.Mutable<JsonSchemaEchoAnnotations> = {};
|
|
385
|
+
for (const [key, annotationId] of Object.entries(EchoAnnotations)) {
|
|
386
|
+
if (annotations[annotationId] != null) {
|
|
387
|
+
echoAnnotations[key as keyof JsonSchemaEchoAnnotations] = annotations[annotationId] as any;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (Object.keys(echoAnnotations).length > 0) {
|
|
391
|
+
// TODO(dmaretskyi): use new namespace.
|
|
392
|
+
schemaFields[ECHO_ANNOTATIONS_NS_KEY] = echoAnnotations;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const echoIdentifier = annotations[TypeIdentifierAnnotationId];
|
|
396
|
+
if (echoIdentifier) {
|
|
397
|
+
schemaFields[ECHO_ANNOTATIONS_NS_KEY] ??= {};
|
|
398
|
+
schemaFields[ECHO_ANNOTATIONS_NS_KEY].schemaId = echoIdentifier;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// Custom (at end).
|
|
402
|
+
for (const [key, annotationId] of Object.entries(CustomAnnotations)) {
|
|
403
|
+
const value = annotations[annotationId];
|
|
404
|
+
if (value != null) {
|
|
405
|
+
schemaFields[key] = value;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return schemaFields;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
const decodeTypeIdentifierAnnotation = (schema: JsonSchemaType): string | undefined => {
|
|
413
|
+
// Limit to dxn:echo: URIs.
|
|
414
|
+
if (schema.$id && schema.$id.startsWith('dxn:echo:')) {
|
|
415
|
+
return schema.$id;
|
|
416
|
+
} else if (schema.$id && schema.$id.startsWith('dxn:type:') && schema?.echo?.type?.schemaId) {
|
|
417
|
+
const id = schema?.echo?.type?.schemaId;
|
|
418
|
+
if (ObjectId.isValid(id)) {
|
|
419
|
+
return DXN.fromLocalObjectId(id).toString();
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return undefined;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const decodeTypeAnnotation = (schema: JsonSchemaType): TypeAnnotation | undefined => {
|
|
426
|
+
if (schema.typename) {
|
|
427
|
+
const annotation: Types.Mutable<TypeAnnotation> = {
|
|
428
|
+
// TODO(dmaretskyi): Decoding default.
|
|
429
|
+
kind: schema.entityKind ? Schema.decodeSync(EntityKindSchema)(schema.entityKind) : EntityKind.Object,
|
|
430
|
+
typename: schema.typename,
|
|
431
|
+
version: schema.version ?? '0.1.0',
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
if (annotation.kind === EntityKind.Relation) {
|
|
435
|
+
const source = schema.relationSource?.$ref ?? raise(new Error('Relation source not set'));
|
|
436
|
+
const target = schema.relationTarget?.$ref ?? raise(new Error('Relation target not set'));
|
|
437
|
+
annotation.sourceSchema = DXN.parse(source).toString();
|
|
438
|
+
annotation.targetSchema = DXN.parse(target).toString();
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return annotation;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// Decode legacy schema.
|
|
445
|
+
if (!schema.typename && schema?.echo?.type) {
|
|
446
|
+
return {
|
|
447
|
+
kind: EntityKind.Object,
|
|
448
|
+
typename: schema.echo.type.typename,
|
|
449
|
+
version: schema.echo.type.version,
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return undefined;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const jsonSchemaFieldsToAnnotations = (schema: JsonSchemaType): SchemaAST.Annotations => {
|
|
457
|
+
const annotations: Types.Mutable<Schema.Annotations.Schema<any>> = {};
|
|
458
|
+
|
|
459
|
+
const echoAnnotations: JsonSchemaEchoAnnotations = getNormalizedEchoAnnotations(schema) ?? {};
|
|
460
|
+
if (echoAnnotations) {
|
|
461
|
+
for (const [key, annotationId] of Object.entries(EchoAnnotations)) {
|
|
462
|
+
if (echoAnnotations[key as keyof JsonSchemaEchoAnnotations]) {
|
|
463
|
+
annotations[annotationId] = echoAnnotations[key as keyof JsonSchemaEchoAnnotations];
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
annotations[TypeIdentifierAnnotationId] = decodeTypeIdentifierAnnotation(schema);
|
|
469
|
+
const typeAnnotation = decodeTypeAnnotation(schema);
|
|
470
|
+
if (typeAnnotation) {
|
|
471
|
+
annotations[TypeAnnotationId] = typeAnnotation;
|
|
472
|
+
annotations[SchemaAST.JSONSchemaAnnotationId] = makeTypeJsonSchemaAnnotation({
|
|
473
|
+
kind: typeAnnotation.kind,
|
|
474
|
+
typename: typeAnnotation.typename,
|
|
475
|
+
version: typeAnnotation.version,
|
|
476
|
+
relationSource: typeAnnotation.sourceSchema,
|
|
477
|
+
relationTarget: typeAnnotation.targetSchema,
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// Custom (at end).
|
|
482
|
+
for (const [key, annotationId] of Object.entries({ ...CustomAnnotations, ...DecodedAnnotations })) {
|
|
483
|
+
if (key in schema) {
|
|
484
|
+
annotations[annotationId] = (schema as any)[key];
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return clearUndefined(annotations);
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
const makeAnnotatedRefinement = (ast: SchemaAST.AST, annotations: SchemaAST.Annotations): SchemaAST.Refinement => {
|
|
492
|
+
return new SchemaAST.Refinement(ast, () => Option.none(), annotations);
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const addJsonSchemaFields = (ast: SchemaAST.AST, schema: JsonSchemaType): SchemaAST.AST =>
|
|
496
|
+
makeAnnotatedRefinement(ast, { [SchemaAST.JSONSchemaAnnotationId]: schema });
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Fixes field order.
|
|
500
|
+
* Sets `$schema` prop.
|
|
501
|
+
*/
|
|
502
|
+
const normalizeJsonSchema = (jsonSchema: Types.DeepMutable<JsonSchemaType>): Types.DeepMutable<JsonSchemaType> => {
|
|
503
|
+
if (jsonSchema.properties && 'id' in jsonSchema.properties) {
|
|
504
|
+
jsonSchema.properties = orderKeys(jsonSchema.properties, ['id']); // Put id first.
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// TODO(dmaretskyi): Makes sure undefined is not left on optional fields for the resulting object.
|
|
508
|
+
jsonSchema.$schema = JSON_SCHEMA_URL;
|
|
509
|
+
jsonSchema = orderKeys(jsonSchema, [
|
|
510
|
+
'$schema',
|
|
511
|
+
'$id',
|
|
512
|
+
|
|
513
|
+
'entityKind',
|
|
514
|
+
'typename',
|
|
515
|
+
'version',
|
|
516
|
+
'relationTarget',
|
|
517
|
+
'relationSource',
|
|
518
|
+
|
|
519
|
+
'type',
|
|
520
|
+
'enum',
|
|
521
|
+
|
|
522
|
+
'properties',
|
|
523
|
+
'required',
|
|
524
|
+
'propertyOrder', // Custom.
|
|
525
|
+
'items',
|
|
526
|
+
'additionalProperties',
|
|
527
|
+
|
|
528
|
+
'anyOf',
|
|
529
|
+
'oneOf',
|
|
530
|
+
]);
|
|
531
|
+
return jsonSchema;
|
|
532
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { invariant } from '@dxos/invariant';
|
|
6
|
+
import { deepMapValues } from '@dxos/util';
|
|
7
|
+
|
|
8
|
+
import type * as Obj from '../../Obj';
|
|
9
|
+
import { makeObject } from '../proxy';
|
|
10
|
+
import { Ref } from '../ref';
|
|
11
|
+
import { getMeta, getSchema } from '../types';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Clones an object or relation.
|
|
15
|
+
* This does not clone referenced objects, only the properties in the object.
|
|
16
|
+
* @returns A new object with the same schema and properties.
|
|
17
|
+
*/
|
|
18
|
+
export const clone = <T extends Obj.Any>(obj: T, opts?: Obj.CloneOptions): T => {
|
|
19
|
+
const { id, ...data } = obj;
|
|
20
|
+
const schema = getSchema(obj);
|
|
21
|
+
invariant(schema != null, 'Object should have a schema');
|
|
22
|
+
const props: any = deepMapValues(data, (value, recurse) => {
|
|
23
|
+
if (Ref.isRef(value)) {
|
|
24
|
+
if (opts?.deep) {
|
|
25
|
+
// TODO(dmaretskyi): Will break on circular references.
|
|
26
|
+
return Ref.make(clone(value.target!, opts));
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
return recurse(value);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (opts?.retainId) {
|
|
34
|
+
props.id = id;
|
|
35
|
+
}
|
|
36
|
+
const meta = deepMapValues(getMeta(obj), (value, recurse) => {
|
|
37
|
+
if (Ref.isRef(value)) {
|
|
38
|
+
if (opts?.deep) {
|
|
39
|
+
// TODO(dmaretskyi): Will break on circular references.
|
|
40
|
+
return Ref.make(clone(value.target!, opts));
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
return recurse(value);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return makeObject(schema, props, meta);
|
|
48
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { getTypename } from '../annotations';
|
|
8
|
+
import { type AnyProperties } from '../types';
|
|
9
|
+
|
|
10
|
+
// TODO(dmaretskyi): Rename to represent commonality between objects and relations (e.g. `entity`).
|
|
11
|
+
export type TypedObjectOptions = {
|
|
12
|
+
// TODO(burdon): Document.
|
|
13
|
+
partial?: true;
|
|
14
|
+
// TODO(burdon): Document.
|
|
15
|
+
record?: true;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
// TODO(burdon): Comment required.
|
|
22
|
+
// TODO(dmaretskyi): Rename to represent commonality between objects and relations (e.g. `entity`).
|
|
23
|
+
type SimplifiedSchemaFields<
|
|
24
|
+
SchemaFields extends Schema.Struct.Fields,
|
|
25
|
+
Options extends TypedObjectOptions,
|
|
26
|
+
> = Options['partial'] extends boolean
|
|
27
|
+
? Schema.SimplifyMutable<Partial<Schema.Struct.Type<SchemaFields>>>
|
|
28
|
+
: Schema.SimplifyMutable<Schema.Struct.Type<SchemaFields>>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
// TODO(burdon): Comment required.
|
|
34
|
+
// TODO(dmaretskyi): Rename to represent commonality between objects and relations (e.g. `entity`).
|
|
35
|
+
export type TypedObjectFields<
|
|
36
|
+
SchemaFields extends Schema.Struct.Fields,
|
|
37
|
+
Options extends TypedObjectOptions,
|
|
38
|
+
> = SimplifiedSchemaFields<SchemaFields, Options> & { id: string } & (Options['record'] extends boolean
|
|
39
|
+
? Schema.SimplifyMutable<Schema.IndexSignature.Type<Schema.IndexSignature.Records>>
|
|
40
|
+
: {});
|
|
41
|
+
|
|
42
|
+
export const makeTypedEntityClass = (
|
|
43
|
+
typename: string,
|
|
44
|
+
version: string,
|
|
45
|
+
baseSchema: Schema.Schema.AnyNoContext,
|
|
46
|
+
): Schema.SchemaClass<any> => {
|
|
47
|
+
return class {
|
|
48
|
+
// Implement TypedObject properties.
|
|
49
|
+
static readonly typename = typename;
|
|
50
|
+
static readonly version = version;
|
|
51
|
+
|
|
52
|
+
// Implement Schema.Schema properties.
|
|
53
|
+
// TODO(burdon): Comment required.
|
|
54
|
+
static readonly [Schema.TypeId] = schemaVariance;
|
|
55
|
+
static readonly ast = baseSchema.ast;
|
|
56
|
+
static readonly annotations = baseSchema.annotations.bind(baseSchema);
|
|
57
|
+
static readonly pipe = baseSchema.pipe.bind(baseSchema);
|
|
58
|
+
|
|
59
|
+
// TODO(burdon): Comment required.
|
|
60
|
+
static [Symbol.hasInstance](obj: AnyProperties) {
|
|
61
|
+
return obj != null && getTypename(obj) === typename;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// TODO(burdon): Throw APIError.
|
|
65
|
+
private constructor() {
|
|
66
|
+
throw new Error('Use live(Typename, { ...fields }) to instantiate an object.');
|
|
67
|
+
}
|
|
68
|
+
} as any;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const schemaVariance = {
|
|
72
|
+
_A: (_: any) => _,
|
|
73
|
+
_I: (_: any) => _,
|
|
74
|
+
_R: (_: never) => _,
|
|
75
|
+
};
|