@dxos/echo 0.8.4-main.7ace549 → 0.8.4-main.937b3ca
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 +1 -2
- 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-22JMFST2.mjs +24 -0
- package/dist/lib/browser/chunk-22JMFST2.mjs.map +7 -0
- package/dist/lib/browser/chunk-2SBB7OWV.mjs +250 -0
- package/dist/lib/browser/chunk-2SBB7OWV.mjs.map +7 -0
- package/dist/lib/browser/chunk-6L5HHUVU.mjs +158 -0
- package/dist/lib/browser/chunk-6L5HHUVU.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-7GH6RXJ3.mjs → chunk-BJPE6CIC.mjs} +1999 -1835
- package/dist/lib/browser/chunk-BJPE6CIC.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-FRDT7RA4.mjs +403 -0
- package/dist/lib/browser/chunk-FRDT7RA4.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-KQQGVHFN.mjs +143 -0
- package/dist/lib/browser/chunk-KQQGVHFN.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-NOPVNWPT.mjs +204 -0
- package/dist/lib/browser/chunk-NOPVNWPT.mjs.map +7 -0
- package/dist/lib/browser/chunk-PQZW3S6L.mjs +74 -0
- package/dist/lib/browser/chunk-PQZW3S6L.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-U2J7TA7K.mjs +57 -0
- package/dist/lib/browser/chunk-U2J7TA7K.mjs.map +7 -0
- package/dist/lib/browser/chunk-W5D2GWAW.mjs +98 -0
- package/dist/lib/browser/chunk-W5D2GWAW.mjs.map +7 -0
- package/dist/lib/browser/chunk-XDIUHAAX.mjs +41 -0
- package/dist/lib/browser/chunk-XDIUHAAX.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-ZAGAOZVY.mjs +288 -0
- package/dist/lib/browser/chunk-ZAGAOZVY.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 +65 -25
- package/dist/lib/browser/internal/index.mjs +213 -92
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +80 -41
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- 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-4PNXQA64.mjs +250 -0
- package/dist/lib/node-esm/chunk-4PNXQA64.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-5OBN7GZW.mjs +158 -0
- package/dist/lib/node-esm/chunk-5OBN7GZW.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-ANLVLWME.mjs +98 -0
- package/dist/lib/node-esm/chunk-ANLVLWME.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-DMR7OAFK.mjs +57 -0
- package/dist/lib/node-esm/chunk-DMR7OAFK.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-ILMLLM4R.mjs +204 -0
- package/dist/lib/node-esm/chunk-ILMLLM4R.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-M4B6BMD2.mjs → chunk-LT3H4JOX.mjs} +1999 -1835
- package/dist/lib/node-esm/chunk-LT3H4JOX.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-NRN3ZW2T.mjs +143 -0
- package/dist/lib/node-esm/chunk-NRN3ZW2T.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QLI2EIJ2.mjs +41 -0
- package/dist/lib/node-esm/chunk-QLI2EIJ2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QYR67VBV.mjs +288 -0
- package/dist/lib/node-esm/chunk-QYR67VBV.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-W6QIEBTQ.mjs +403 -0
- package/dist/lib/node-esm/chunk-W6QIEBTQ.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-Y75VU7LB.mjs +74 -0
- package/dist/lib/node-esm/chunk-Y75VU7LB.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/chunk-ZBB67AKD.mjs +24 -0
- package/dist/lib/node-esm/chunk-ZBB67AKD.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +65 -25
- package/dist/lib/node-esm/internal/index.mjs +213 -92
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +80 -41
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/Annotation.d.ts +1 -1
- package/dist/types/src/Annotation.d.ts.map +1 -1
- package/dist/types/src/Database.d.ts +117 -60
- package/dist/types/src/Database.d.ts.map +1 -1
- package/dist/types/src/Entity.d.ts +111 -5
- package/dist/types/src/Entity.d.ts.map +1 -1
- 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/{errors.d.ts → Err.d.ts} +13 -17
- 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.map +1 -1
- package/dist/types/src/Hypergraph.d.ts +60 -0
- package/dist/types/src/Hypergraph.d.ts.map +1 -0
- package/dist/types/src/Obj.d.ts +268 -76
- 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/query.d.ts → Query.d.ts} +53 -50
- 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 +9 -7
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +235 -18
- 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 +6 -6
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +213 -50
- 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 +8 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/annotations/annotations.d.ts +23 -27
- package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -1
- package/dist/types/src/internal/annotations/util.d.ts +1 -0
- package/dist/types/src/internal/annotations/util.d.ts.map +1 -1
- 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 +13 -3
- package/dist/types/src/internal/entities/entity.d.ts.map +1 -1
- package/dist/types/src/internal/entities/index.d.ts +1 -1
- package/dist/types/src/internal/entities/index.d.ts.map +1 -1
- package/dist/types/src/internal/entities/model.d.ts +14 -7
- package/dist/types/src/internal/entities/model.d.ts.map +1 -1
- package/dist/types/src/internal/entities/object.d.ts +8 -1
- package/dist/types/src/internal/entities/object.d.ts.map +1 -1
- package/dist/types/src/internal/entities/relation.d.ts +8 -1
- package/dist/types/src/internal/entities/relation.d.ts.map +1 -1
- package/dist/types/src/internal/formats/format.d.ts +4 -4
- package/dist/types/src/internal/formats/format.d.ts.map +1 -1
- package/dist/types/src/internal/formats/select.d.ts +5 -3
- package/dist/types/src/internal/formats/select.d.ts.map +1 -1
- package/dist/types/src/internal/formats/string.d.ts +4 -0
- package/dist/types/src/internal/formats/string.d.ts.map +1 -1
- package/dist/types/src/internal/formats/types.d.ts +6 -2
- package/dist/types/src/internal/formats/types.d.ts.map +1 -1
- package/dist/types/src/internal/index.d.ts +2 -1
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -1
- 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/create-object.d.ts +1 -1
- package/dist/types/src/internal/object/index.d.ts +3 -0
- package/dist/types/src/internal/object/index.d.ts.map +1 -1
- package/dist/types/src/internal/object/json-serializer.d.ts +13 -7
- package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -1
- package/dist/types/src/internal/object/schema-validator.d.ts +1 -14
- package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -1
- 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 +7 -13
- package/dist/types/src/internal/object/typed-object.d.ts.map +1 -1
- 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/index.d.ts +11 -0
- package/dist/types/src/internal/proxy/index.d.ts.map +1 -1
- 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 +2 -4
- package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -1
- 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/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 +14 -11
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -1
- package/dist/types/src/internal/ref/ref-array.d.ts +4 -4
- package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -1
- package/dist/types/src/internal/ref/ref.d.ts +14 -6
- package/dist/types/src/internal/ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/schema/compose.d.ts.map +1 -1
- package/dist/types/src/internal/schema/echo-schema.d.ts +15 -3
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -1
- package/dist/types/src/internal/schema/index.d.ts +0 -2
- package/dist/types/src/internal/schema/index.d.ts.map +1 -1
- package/dist/types/src/internal/schema/persistent-schema.d.ts +9 -7
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -1
- package/dist/types/src/internal/types/base.d.ts +5 -16
- package/dist/types/src/internal/types/base.d.ts.map +1 -1
- package/dist/types/src/internal/types/entity.d.ts +27 -2
- package/dist/types/src/internal/types/entity.d.ts.map +1 -1
- package/dist/types/src/internal/types/meta.d.ts +1 -9
- package/dist/types/src/internal/types/meta.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +141 -175
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +6 -1
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +130 -23
- package/src/Annotation.ts +5 -4
- package/src/Database.ts +229 -82
- package/src/Entity.test.ts +22 -0
- package/src/Entity.ts +173 -7
- package/src/{errors.ts → Err.ts} +2 -2
- package/src/Filter.ts +376 -0
- package/src/Format.ts +0 -2
- package/src/Hypergraph.ts +74 -0
- package/src/Obj.test.ts +386 -0
- package/src/Obj.ts +338 -250
- package/src/{query/order.ts → Order.ts} +19 -9
- package/src/{query/query.test.ts → Query.test.ts} +180 -49
- package/src/{query/query.ts → Query.ts} +115 -122
- package/src/QueryResult.ts +106 -0
- package/src/Ref.ts +20 -3
- package/src/Relation.test.ts +82 -0
- package/src/Relation.ts +364 -27
- package/src/SchemaRegistry.ts +105 -0
- package/src/Tag.ts +1 -1
- package/src/Type.test.ts +52 -0
- package/src/Type.ts +322 -88
- package/src/index.ts +9 -5
- package/src/internal/README.md +36 -17
- package/src/internal/annotations/annotations.test.ts +6 -6
- package/src/internal/annotations/annotations.ts +73 -76
- package/src/internal/annotations/util.ts +2 -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 +36 -19
- package/src/internal/entities/index.ts +1 -1
- package/src/internal/entities/model.ts +17 -12
- package/src/internal/entities/object.ts +20 -5
- package/src/internal/entities/relation.ts +22 -4
- package/src/internal/formats/format.ts +7 -8
- package/src/internal/formats/object.ts +2 -2
- package/src/internal/formats/select.ts +5 -3
- package/src/internal/formats/string.ts +5 -0
- package/src/internal/formats/types.ts +9 -3
- package/src/internal/index.ts +2 -1
- package/src/internal/json-schema/json-schema-type.ts +1 -1
- package/src/internal/json-schema/json-schema.test.ts +19 -17
- package/src/internal/json-schema/json-schema.ts +4 -4
- package/src/internal/object/clone.ts +48 -0
- package/src/internal/object/create-object.ts +2 -2
- package/src/internal/object/index.ts +3 -0
- package/src/internal/object/inspect.ts +3 -3
- package/src/internal/object/json-serializer.test.ts +4 -1
- package/src/internal/object/json-serializer.ts +28 -70
- package/src/internal/object/schema-validator.ts +2 -238
- 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 +11 -11
- package/src/internal/object/typed-object.ts +8 -72
- 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 +30 -80
- package/src/internal/proxy/index.ts +11 -0
- package/src/internal/proxy/json-serializer.ts +87 -0
- package/src/internal/proxy/make-object.ts +33 -50
- 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 +23 -15
- package/src/internal/proxy/symbols.ts +7 -0
- package/src/internal/proxy/typed-handler.test.ts +251 -35
- package/src/internal/proxy/typed-handler.ts +265 -56
- package/src/internal/proxy/typed-object.test.ts +26 -15
- package/src/internal/ref/ref-array.ts +4 -4
- package/src/internal/ref/ref.ts +62 -39
- package/src/internal/schema/compose.test.ts +3 -3
- package/src/internal/schema/compose.ts +1 -2
- package/src/internal/schema/echo-schema.ts +49 -11
- package/src/internal/schema/index.ts +0 -2
- package/src/internal/schema/persistent-schema.ts +3 -4
- package/src/internal/types/base.ts +6 -21
- package/src/internal/types/entity.ts +35 -4
- package/src/internal/types/meta.ts +1 -11
- package/src/testing/api.test.ts +31 -5
- package/src/testing/test-schema.ts +55 -30
- package/src/testing/util.ts +22 -15
- package/dist/lib/browser/chunk-7GH6RXJ3.mjs.map +0 -7
- package/dist/lib/browser/chunk-E4UTVJNF.mjs +0 -1111
- package/dist/lib/browser/chunk-E4UTVJNF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-JE5RXM2I.mjs +0 -1111
- package/dist/lib/node-esm/chunk-JE5RXM2I.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-M4B6BMD2.mjs.map +0 -7
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/internal/entities/expando.d.ts +0 -16
- package/dist/types/src/internal/entities/expando.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/query/filter.d.ts +0 -167
- package/dist/types/src/query/filter.d.ts.map +0 -1
- package/dist/types/src/query/index.d.ts +0 -5
- package/dist/types/src/query/index.d.ts.map +0 -1
- package/dist/types/src/query/order.d.ts +0 -12
- package/dist/types/src/query/order.d.ts.map +0 -1
- 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/query/testing.d.ts +0 -51
- package/dist/types/src/query/testing.d.ts.map +0 -1
- package/dist/types/src/query/types.d.ts +0 -17
- package/dist/types/src/query/types.d.ts.map +0 -1
- package/dist/types/src/query/util.d.ts +0 -8
- package/dist/types/src/query/util.d.ts.map +0 -1
- package/src/internal/entities/expando.ts +0 -23
- package/src/internal/schema/runtime-schema-registry.ts +0 -78
- package/src/internal/schema/snapshot.ts +0 -25
- package/src/query/filter.ts +0 -455
- package/src/query/index.ts +0 -9
- package/src/query/testing.ts +0 -64
- package/src/query/types.ts +0 -23
- package/src/query/util.ts +0 -25
package/src/Relation.ts
CHANGED
|
@@ -2,61 +2,110 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import * as Schema from 'effect/Schema';
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
7
|
import { raise } from '@dxos/debug';
|
|
8
|
+
import type { ForeignKey } from '@dxos/echo-protocol';
|
|
9
|
+
import { createJsonPath, getValue as getValue$ } from '@dxos/effect';
|
|
8
10
|
import { assertArgument, invariant } from '@dxos/invariant';
|
|
9
11
|
import { DXN, type ObjectId } from '@dxos/keys';
|
|
10
|
-
import { type Live } from '@dxos/live-object';
|
|
11
12
|
import { assumeType } from '@dxos/util';
|
|
12
13
|
|
|
14
|
+
import type * as Database from './Database';
|
|
13
15
|
import * as Entity from './Entity';
|
|
14
16
|
import {
|
|
17
|
+
type ObjectJSON as APIJSON,
|
|
15
18
|
ATTR_RELATION_SOURCE,
|
|
16
19
|
ATTR_RELATION_TARGET,
|
|
17
|
-
type
|
|
20
|
+
type AnyEntity,
|
|
21
|
+
type Comparator as ApiComparator,
|
|
22
|
+
type Meta as ApiMeta,
|
|
23
|
+
type ReadonlyMeta as ApiReadonlyMeta,
|
|
24
|
+
type EntityVersion as ApiVersion,
|
|
25
|
+
type ChangeCallback,
|
|
18
26
|
EntityKind,
|
|
19
27
|
type InternalObjectProps,
|
|
28
|
+
type KindId,
|
|
20
29
|
MetaId,
|
|
30
|
+
type Mutable,
|
|
21
31
|
type ObjectMeta,
|
|
22
32
|
RelationSourceDXNId,
|
|
23
33
|
RelationSourceId,
|
|
24
34
|
RelationTargetDXNId,
|
|
25
35
|
RelationTargetId,
|
|
36
|
+
SnapshotKindId,
|
|
37
|
+
VersionTypeId,
|
|
38
|
+
addTag as addTag$,
|
|
39
|
+
change as change$,
|
|
40
|
+
deleteKeys as deleteKeys$,
|
|
41
|
+
getDXN as getDXN$,
|
|
42
|
+
getDatabase as getDatabase$,
|
|
43
|
+
getDescription as getDescription$,
|
|
44
|
+
getKeys as getKeys$,
|
|
45
|
+
getLabel as getLabel$,
|
|
46
|
+
getMetaChecked as getMeta$,
|
|
26
47
|
getObjectDXN,
|
|
48
|
+
getSchema as getSchema$,
|
|
49
|
+
getSnapshot as getSnapshot$,
|
|
27
50
|
getTypeAnnotation,
|
|
51
|
+
getTypeDXN as getTypeDXN$,
|
|
52
|
+
getTypename as getTypename$,
|
|
53
|
+
isDeleted as isDeleted$,
|
|
54
|
+
isVersion,
|
|
28
55
|
makeObject,
|
|
56
|
+
removeTag as removeTag$,
|
|
57
|
+
setDescription as setDescription$,
|
|
58
|
+
setLabel as setLabel$,
|
|
59
|
+
setValue as setValue$,
|
|
60
|
+
sort as sort$,
|
|
61
|
+
sortByLabel as sortByLabel$,
|
|
62
|
+
sortByTypename as sortByTypename$,
|
|
63
|
+
subscribe as subscribe$,
|
|
64
|
+
objectToJSON as toJSON$,
|
|
65
|
+
version as version$,
|
|
29
66
|
} from './internal';
|
|
30
|
-
import * as Obj from './Obj';
|
|
31
|
-
import * as Type from './Type';
|
|
67
|
+
import type * as Obj from './Obj';
|
|
68
|
+
import type * as Type from './Type';
|
|
32
69
|
|
|
33
70
|
/**
|
|
34
71
|
* Base type for all ECHO relations.
|
|
35
72
|
* @private
|
|
36
73
|
*/
|
|
37
74
|
interface BaseRelation<Source, Target>
|
|
38
|
-
extends
|
|
75
|
+
extends AnyEntity,
|
|
39
76
|
Type.Relation.Endpoints<Source, Target>,
|
|
40
77
|
Entity.OfKind<EntityKind.Relation> {}
|
|
41
78
|
|
|
42
79
|
/**
|
|
43
|
-
*
|
|
80
|
+
* Relation with no known properties beyond id, kind, source, and target.
|
|
81
|
+
* Use this when the relation's schema/properties are not known.
|
|
82
|
+
*
|
|
83
|
+
* NOTE: This is a TypeScript type only, not a schema.
|
|
84
|
+
* To validate that a value is an ECHO relation, use `Relation.isRelation`.
|
|
44
85
|
*/
|
|
45
|
-
export interface
|
|
46
|
-
|
|
47
|
-
export const Any = Schema.Struct({}).pipe(
|
|
48
|
-
Type.Relation({
|
|
49
|
-
typename: 'dxos.org/type/Any',
|
|
50
|
-
version: '0.1.0',
|
|
51
|
-
source: Obj.Any,
|
|
52
|
-
target: Obj.Any,
|
|
53
|
-
}),
|
|
54
|
-
);
|
|
86
|
+
export interface Unknown extends BaseRelation<Obj.Unknown, Obj.Unknown> {}
|
|
55
87
|
|
|
56
88
|
/**
|
|
57
89
|
* Relation type with specific source and target types.
|
|
58
90
|
*/
|
|
59
|
-
export type Relation<Source extends Obj.
|
|
91
|
+
export type Relation<Source extends Obj.Unknown, Target extends Obj.Unknown, Props> = BaseRelation<Source, Target> &
|
|
92
|
+
Props;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Base type for snapshot relations (has SnapshotKindId instead of KindId).
|
|
96
|
+
*/
|
|
97
|
+
interface BaseRelationSnapshot<Source, Target> extends AnyEntity, Type.Relation.Endpoints<Source, Target> {
|
|
98
|
+
readonly [SnapshotKindId]: EntityKind.Relation;
|
|
99
|
+
readonly id: ObjectId;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Immutable snapshot of an ECHO relation.
|
|
104
|
+
* Branded with SnapshotKindId (not KindId).
|
|
105
|
+
* Property values are frozen at the time the snapshot was created.
|
|
106
|
+
* Returned by getSnapshot() and hooks.
|
|
107
|
+
*/
|
|
108
|
+
export type Snapshot<T extends Unknown = Unknown> = Omit<T, KindId> & BaseRelationSnapshot<Obj.Unknown, Obj.Unknown>;
|
|
60
109
|
|
|
61
110
|
export const Source: unique symbol = RelationSourceId as any;
|
|
62
111
|
export type Source = typeof Source;
|
|
@@ -64,13 +113,22 @@ export type Source = typeof Source;
|
|
|
64
113
|
export const Target: unique symbol = RelationTargetId as any;
|
|
65
114
|
export type Target = typeof Target;
|
|
66
115
|
|
|
67
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Internal props type for relation instance creation.
|
|
118
|
+
*/
|
|
119
|
+
type RelationMakeProps<T extends Unknown> = {
|
|
68
120
|
id?: ObjectId;
|
|
69
121
|
[MetaId]?: ObjectMeta;
|
|
70
122
|
[Source]: T[Source];
|
|
71
123
|
[Target]: T[Target];
|
|
72
124
|
} & Type.Properties<T>;
|
|
73
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Props type for relation creation with a given schema.
|
|
128
|
+
* Takes a schema type (created with Type.Relation) and extracts the props type.
|
|
129
|
+
*/
|
|
130
|
+
export type MakeProps<S extends Type.Relation.Any> = RelationMakeProps<Schema.Schema.Type<S>>;
|
|
131
|
+
|
|
74
132
|
/**
|
|
75
133
|
* Creates new relation.
|
|
76
134
|
* @param schema - Relation schema.
|
|
@@ -82,9 +140,9 @@ type MakeProps<T extends Any> = {
|
|
|
82
140
|
// TODO(dmaretskyi): Move meta into props.
|
|
83
141
|
export const make = <S extends Type.Relation.Any>(
|
|
84
142
|
schema: S,
|
|
85
|
-
props: NoInfer<
|
|
143
|
+
props: NoInfer<RelationMakeProps<Schema.Schema.Type<S>>>,
|
|
86
144
|
meta?: ObjectMeta,
|
|
87
|
-
):
|
|
145
|
+
): Schema.Schema.Type<S> & Entity.OfKind<typeof Entity.Kind.Relation> => {
|
|
88
146
|
assertArgument(getTypeAnnotation(schema)?.kind === EntityKind.Relation, 'schema', 'Expected a relation schema');
|
|
89
147
|
|
|
90
148
|
if (props[MetaId] != null) {
|
|
@@ -101,7 +159,11 @@ export const make = <S extends Type.Relation.Any>(
|
|
|
101
159
|
return makeObject<Schema.Schema.Type<S>>(schema, props as any, meta);
|
|
102
160
|
};
|
|
103
161
|
|
|
104
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Type guard for relations.
|
|
164
|
+
* Returns true for both reactive relations and relation snapshots.
|
|
165
|
+
*/
|
|
166
|
+
export const isRelation = (value: unknown): value is Unknown => {
|
|
105
167
|
if (typeof value !== 'object' || value === null) {
|
|
106
168
|
return false;
|
|
107
169
|
}
|
|
@@ -109,15 +171,17 @@ export const isRelation = (value: unknown): value is Any => {
|
|
|
109
171
|
return true;
|
|
110
172
|
}
|
|
111
173
|
|
|
112
|
-
|
|
174
|
+
// Check for reactive relation (KindId) or snapshot (SnapshotKindId).
|
|
175
|
+
const kind = (value as any)[Entity.KindId] ?? (value as any)[SnapshotKindId];
|
|
113
176
|
return kind === EntityKind.Relation;
|
|
114
177
|
};
|
|
115
178
|
|
|
116
179
|
/**
|
|
117
180
|
* @returns Relation source DXN.
|
|
181
|
+
* Accepts both reactive relations and snapshots.
|
|
118
182
|
* @throws If the object is not a relation.
|
|
119
183
|
*/
|
|
120
|
-
export const getSourceDXN = (value:
|
|
184
|
+
export const getSourceDXN = (value: Unknown | Snapshot): DXN => {
|
|
121
185
|
assertArgument(isRelation(value), 'Expected a relation');
|
|
122
186
|
assumeType<InternalObjectProps>(value);
|
|
123
187
|
const dxn = (value as InternalObjectProps)[RelationSourceDXNId];
|
|
@@ -127,9 +191,10 @@ export const getSourceDXN = (value: Any): DXN => {
|
|
|
127
191
|
|
|
128
192
|
/**
|
|
129
193
|
* @returns Relation target DXN.
|
|
194
|
+
* Accepts both reactive relations and snapshots.
|
|
130
195
|
* @throws If the object is not a relation.
|
|
131
196
|
*/
|
|
132
|
-
export const getTargetDXN = (value:
|
|
197
|
+
export const getTargetDXN = (value: Unknown | Snapshot): DXN => {
|
|
133
198
|
assertArgument(isRelation(value), 'Expected a relation');
|
|
134
199
|
assumeType<InternalObjectProps>(value);
|
|
135
200
|
const dxn = (value as InternalObjectProps)[RelationTargetDXNId];
|
|
@@ -139,9 +204,10 @@ export const getTargetDXN = (value: Any): DXN => {
|
|
|
139
204
|
|
|
140
205
|
/**
|
|
141
206
|
* @returns Relation source.
|
|
207
|
+
* Accepts both reactive relations and snapshots.
|
|
142
208
|
* @throws If the object is not a relation.
|
|
143
209
|
*/
|
|
144
|
-
export const getSource = <T extends
|
|
210
|
+
export const getSource = <T extends Unknown | Snapshot>(relation: T): Type.Relation.Source<T> => {
|
|
145
211
|
assertArgument(isRelation(relation), 'Expected a relation');
|
|
146
212
|
assumeType<InternalObjectProps>(relation);
|
|
147
213
|
const obj = (relation as InternalObjectProps)[RelationSourceId];
|
|
@@ -151,12 +217,283 @@ export const getSource = <T extends Any>(relation: T): Type.Relation.Source<T> =
|
|
|
151
217
|
|
|
152
218
|
/**
|
|
153
219
|
* @returns Relation target.
|
|
220
|
+
* Accepts both reactive relations and snapshots.
|
|
154
221
|
* @throws If the object is not a relation.
|
|
155
222
|
*/
|
|
156
|
-
export const getTarget = <T extends
|
|
223
|
+
export const getTarget = <T extends Unknown | Snapshot>(relation: T): Type.Relation.Target<T> => {
|
|
157
224
|
assertArgument(isRelation(relation), 'Expected a relation');
|
|
158
225
|
assumeType<InternalObjectProps>(relation);
|
|
159
226
|
const obj = (relation as InternalObjectProps)[RelationTargetId];
|
|
160
227
|
invariant(obj !== undefined, `Invalid target: ${relation.id}`);
|
|
161
228
|
return obj as Type.Relation.Target<T>;
|
|
162
229
|
};
|
|
230
|
+
|
|
231
|
+
//
|
|
232
|
+
// Change
|
|
233
|
+
//
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Makes all properties mutable recursively.
|
|
237
|
+
* Used to provide a mutable view of a relation within `Relation.change`.
|
|
238
|
+
*/
|
|
239
|
+
export type { Mutable };
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Perform mutations on an echo relation within a controlled context.
|
|
243
|
+
*
|
|
244
|
+
* All mutations within the callback are batched and trigger a single notification
|
|
245
|
+
* when the callback completes. Direct mutations outside of `Relation.change` will throw
|
|
246
|
+
* an error for echo relations.
|
|
247
|
+
*
|
|
248
|
+
* @param relation - The echo relation to mutate. Use `Obj.change` for objects.
|
|
249
|
+
* @param callback - The callback that performs mutations on the relation.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* const worksFor = Relation.make(EmployedBy, {
|
|
254
|
+
* [Relation.Source]: person,
|
|
255
|
+
* [Relation.Target]: company,
|
|
256
|
+
* role: 'Engineer',
|
|
257
|
+
* });
|
|
258
|
+
*
|
|
259
|
+
* // Mutate within Relation.change
|
|
260
|
+
* Relation.change(worksFor, (r) => {
|
|
261
|
+
* r.role = 'Senior Engineer';
|
|
262
|
+
* });
|
|
263
|
+
* ```
|
|
264
|
+
*
|
|
265
|
+
* Note: Only accepts relations. Use `Obj.change` for objects.
|
|
266
|
+
*/
|
|
267
|
+
export const change = <T extends Unknown>(relation: T, callback: ChangeCallback<T>): void => {
|
|
268
|
+
change$(relation, callback);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
//
|
|
272
|
+
// Snapshot
|
|
273
|
+
//
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Returns an immutable snapshot of a relation.
|
|
277
|
+
* The snapshot is branded with SnapshotKindId instead of KindId,
|
|
278
|
+
* making it distinguishable from the reactive relation at the type level.
|
|
279
|
+
*/
|
|
280
|
+
export const getSnapshot: <T extends Unknown>(rel: T) => Snapshot<T> = getSnapshot$ as any;
|
|
281
|
+
|
|
282
|
+
//
|
|
283
|
+
// Subscribe
|
|
284
|
+
//
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Subscribe to relation updates.
|
|
288
|
+
* The callback is called synchronously when the relation is modified.
|
|
289
|
+
* Only accepts reactive relations (not snapshots).
|
|
290
|
+
* @returns Unsubscribe function.
|
|
291
|
+
*/
|
|
292
|
+
export const subscribe = (rel: Unknown, callback: () => void): (() => void) => {
|
|
293
|
+
return subscribe$(rel, callback);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
//
|
|
297
|
+
// Property Access
|
|
298
|
+
//
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Get a deeply nested property from a relation.
|
|
302
|
+
* Accepts both reactive relations and snapshots.
|
|
303
|
+
*/
|
|
304
|
+
export const getValue = (rel: Unknown | Snapshot, path: readonly (string | number)[]): any => {
|
|
305
|
+
return getValue$(rel, createJsonPath(path));
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Set a deeply nested property on a relation.
|
|
310
|
+
* Must be called within a `Relation.change` callback.
|
|
311
|
+
*
|
|
312
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
313
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
314
|
+
*/
|
|
315
|
+
export const setValue: (rel: Mutable<Unknown>, path: readonly (string | number)[], value: any) => void =
|
|
316
|
+
setValue$ as any;
|
|
317
|
+
|
|
318
|
+
//
|
|
319
|
+
// Type
|
|
320
|
+
//
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Get the DXN of the relation.
|
|
324
|
+
* Accepts both reactive relations and snapshots.
|
|
325
|
+
*/
|
|
326
|
+
export const getDXN = (entity: Unknown | Snapshot): DXN => getDXN$(entity);
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* @returns The DXN of the relation's type.
|
|
330
|
+
*/
|
|
331
|
+
export const getTypeDXN = getTypeDXN$;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Get the schema of the relation.
|
|
335
|
+
* Returns the branded ECHO schema used to create the relation.
|
|
336
|
+
*/
|
|
337
|
+
export const getSchema: (rel: unknown | undefined) => Type.Entity.Any | undefined = getSchema$ as any;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* @returns The typename of the relation's type.
|
|
341
|
+
* Accepts both reactive relations and snapshots.
|
|
342
|
+
*/
|
|
343
|
+
export const getTypename = (entity: Unknown | Snapshot): string | undefined => getTypename$(entity);
|
|
344
|
+
|
|
345
|
+
//
|
|
346
|
+
// Database
|
|
347
|
+
//
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Get the database the relation belongs to.
|
|
351
|
+
* Accepts both reactive relations and snapshots.
|
|
352
|
+
*/
|
|
353
|
+
export const getDatabase = (entity: Unknown | Snapshot): Database.Database | undefined => getDatabase$(entity);
|
|
354
|
+
|
|
355
|
+
//
|
|
356
|
+
// Meta
|
|
357
|
+
//
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Deeply read-only version of ObjectMeta.
|
|
361
|
+
*/
|
|
362
|
+
export type ReadonlyMeta = ApiReadonlyMeta;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Mutable meta type returned by `Relation.getMeta` inside a `Relation.change` callback.
|
|
366
|
+
*/
|
|
367
|
+
export type Meta = ApiMeta;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Get the metadata for a relation.
|
|
371
|
+
* Returns mutable meta when passed a mutable relation (inside `Relation.change` callback).
|
|
372
|
+
* Returns read-only meta when passed a regular relation or snapshot.
|
|
373
|
+
*/
|
|
374
|
+
// TODO(wittjosiah): When passed a Snapshot, should return a snapshot of meta, not the live meta proxy.
|
|
375
|
+
export function getMeta(entity: Mutable<Unknown>): ObjectMeta;
|
|
376
|
+
export function getMeta(entity: Unknown | Snapshot): ReadonlyMeta;
|
|
377
|
+
export function getMeta(entity: Unknown | Snapshot | Mutable<Unknown>): ObjectMeta | ReadonlyMeta {
|
|
378
|
+
return getMeta$(entity);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* @returns Foreign keys for the relation from the specified source.
|
|
383
|
+
* Accepts both reactive relations and snapshots.
|
|
384
|
+
*/
|
|
385
|
+
export const getKeys = (entity: Unknown | Snapshot, source: string): ForeignKey[] => getKeys$(entity, source);
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Delete all keys from the relation for the specified source.
|
|
389
|
+
* Must be called within a `Relation.change` callback.
|
|
390
|
+
*
|
|
391
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
392
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
393
|
+
*/
|
|
394
|
+
export const deleteKeys = (entity: Mutable<Unknown>, source: string): void => deleteKeys$(entity, source);
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Add a tag to the relation.
|
|
398
|
+
* Must be called within a `Relation.change` callback.
|
|
399
|
+
*
|
|
400
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
401
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
402
|
+
*/
|
|
403
|
+
export const addTag = (entity: Mutable<Unknown>, tag: string): void => addTag$(entity, tag);
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Remove a tag from the relation.
|
|
407
|
+
* Must be called within a `Relation.change` callback.
|
|
408
|
+
*
|
|
409
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
410
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
411
|
+
*/
|
|
412
|
+
export const removeTag = (entity: Mutable<Unknown>, tag: string): void => removeTag$(entity, tag);
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Check if the relation is deleted.
|
|
416
|
+
* Accepts both reactive relations and snapshots.
|
|
417
|
+
*/
|
|
418
|
+
export const isDeleted = (entity: Unknown | Snapshot): boolean => isDeleted$(entity);
|
|
419
|
+
|
|
420
|
+
//
|
|
421
|
+
// Annotations
|
|
422
|
+
//
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Get the label of the relation.
|
|
426
|
+
* Accepts both reactive relations and snapshots.
|
|
427
|
+
*/
|
|
428
|
+
export const getLabel = (entity: Unknown | Snapshot): string | undefined => getLabel$(entity);
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Set the label of the relation.
|
|
432
|
+
* Must be called within a `Relation.change` callback.
|
|
433
|
+
*
|
|
434
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
435
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
436
|
+
*/
|
|
437
|
+
export const setLabel = (entity: Mutable<Unknown>, label: string): void => setLabel$(entity, label);
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Get the description of the relation.
|
|
441
|
+
* Accepts both reactive relations and snapshots.
|
|
442
|
+
*/
|
|
443
|
+
export const getDescription = (entity: Unknown | Snapshot): string | undefined => getDescription$(entity);
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Set the description of the relation.
|
|
447
|
+
* Must be called within a `Relation.change` callback.
|
|
448
|
+
*
|
|
449
|
+
* NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
|
|
450
|
+
* parameters, so there is no compile-time error. Enforcement is runtime-only.
|
|
451
|
+
*/
|
|
452
|
+
export const setDescription = (entity: Mutable<Unknown>, description: string): void =>
|
|
453
|
+
setDescription$(entity, description);
|
|
454
|
+
|
|
455
|
+
//
|
|
456
|
+
// JSON
|
|
457
|
+
//
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* JSON representation of a relation.
|
|
461
|
+
*/
|
|
462
|
+
export type JSON = APIJSON;
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Converts relation to its JSON representation.
|
|
466
|
+
* Accepts both reactive relations and snapshots.
|
|
467
|
+
*/
|
|
468
|
+
export const toJSON = (entity: Unknown | Snapshot): JSON => toJSON$(entity);
|
|
469
|
+
|
|
470
|
+
//
|
|
471
|
+
// Sorting
|
|
472
|
+
//
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Comparator function type for sorting relations.
|
|
476
|
+
* Accepts both reactive relations and snapshots.
|
|
477
|
+
*/
|
|
478
|
+
export type Comparator = ApiComparator<Unknown | Snapshot>;
|
|
479
|
+
|
|
480
|
+
export const sortByLabel: Comparator = sortByLabel$ as Comparator;
|
|
481
|
+
export const sortByTypename: Comparator = sortByTypename$ as Comparator;
|
|
482
|
+
export const sort = (...comparators: Comparator[]): Comparator => sort$(...comparators) as Comparator;
|
|
483
|
+
|
|
484
|
+
//
|
|
485
|
+
// Version
|
|
486
|
+
//
|
|
487
|
+
|
|
488
|
+
export { VersionTypeId, isVersion };
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Represent relation version.
|
|
492
|
+
*/
|
|
493
|
+
export type Version = ApiVersion;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Returns the version of the relation.
|
|
497
|
+
* Accepts both reactive relations and snapshots.
|
|
498
|
+
*/
|
|
499
|
+
export const version = (entity: Unknown | Snapshot): Version => version$(entity);
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type * as Types from 'effect/Types';
|
|
6
|
+
|
|
7
|
+
import type * as JsonSchema from './JsonSchema';
|
|
8
|
+
import type * as Key from './Key';
|
|
9
|
+
import type * as QueryResult from './QueryResult';
|
|
10
|
+
import type * as Type from './Type';
|
|
11
|
+
|
|
12
|
+
// TODO(wittjosiah): Replace w/ Query.Query.
|
|
13
|
+
export type Query = {
|
|
14
|
+
/**
|
|
15
|
+
* Filter by schema ID.
|
|
16
|
+
* Schema id is a DXN with `echo` or `type` kind.
|
|
17
|
+
*/
|
|
18
|
+
id?: string | string[];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Id of the backing ECHO object.
|
|
22
|
+
*/
|
|
23
|
+
backingObjectId?: Key.ObjectId | Key.ObjectId[];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* One or more typenames to filter by.
|
|
27
|
+
*/
|
|
28
|
+
typename?: string | string[];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* [Semver Range](https://docs.npmjs.com/cli/v6/using-npm/semver#ranges) for the schema version.
|
|
32
|
+
*/
|
|
33
|
+
version?: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Where to look for the schema.
|
|
37
|
+
*
|
|
38
|
+
* Database schema are stored in the database of the current space.
|
|
39
|
+
* Runtime schema are registered in the runtime.
|
|
40
|
+
*
|
|
41
|
+
* @default ['database']
|
|
42
|
+
*/
|
|
43
|
+
location?: ('database' | 'runtime')[];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Include system schemas.
|
|
47
|
+
* @default false
|
|
48
|
+
*
|
|
49
|
+
* The system schema include but are not limited to:
|
|
50
|
+
* - dxos.org/type/Schema
|
|
51
|
+
*/
|
|
52
|
+
includeSystem?: boolean;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Input for schema registration.
|
|
57
|
+
* The typename, version and schema mutability metadata is read from the schema annotations.
|
|
58
|
+
*
|
|
59
|
+
* Accepts:
|
|
60
|
+
* - Branded ECHO schemas created with Type.Obj() or Type.Relation()
|
|
61
|
+
* - JSON schema with typename and version
|
|
62
|
+
*/
|
|
63
|
+
export type RegisterSchemaInput =
|
|
64
|
+
| Type.Entity.Any
|
|
65
|
+
| {
|
|
66
|
+
typename: string;
|
|
67
|
+
version: string;
|
|
68
|
+
jsonSchema: JsonSchema.JsonSchema;
|
|
69
|
+
/**
|
|
70
|
+
* Display name of the schema.
|
|
71
|
+
*/
|
|
72
|
+
name?: string;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type ExtractQueryResult<Query> = Query extends { location: ('database' | 'runtime')[] }
|
|
76
|
+
? Type.Entity.Any
|
|
77
|
+
: Type.RuntimeType;
|
|
78
|
+
|
|
79
|
+
export interface SchemaRegistry {
|
|
80
|
+
/**
|
|
81
|
+
* Checks if the provided schema is registered.
|
|
82
|
+
*/
|
|
83
|
+
// TODO(burdon): Type?
|
|
84
|
+
hasSchema(schema: Type.Entity.Any): boolean;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Registers the provided schema.
|
|
88
|
+
*
|
|
89
|
+
* @returns Mutable runtime instances of schemas that were registered.
|
|
90
|
+
*
|
|
91
|
+
* The behavior of this method depends on the state of the database.
|
|
92
|
+
* The general principle is that the schema will be upserted into the space.
|
|
93
|
+
* If an equivalent schema with the same name and version already exists, the method does nothing.
|
|
94
|
+
* If a different schema with the same name and version exists, the method throws an error.
|
|
95
|
+
* If no schema with the same name and version exists, a new schema will be inserted based on semantic versioning rules.
|
|
96
|
+
*/
|
|
97
|
+
register(input: RegisterSchemaInput[]): Promise<Type.RuntimeType[]>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
*
|
|
101
|
+
*/
|
|
102
|
+
query<Q extends Types.NoExcessProperties<Query, Q>>(
|
|
103
|
+
query?: Q & Query,
|
|
104
|
+
): QueryResult.QueryResult<ExtractQueryResult<Q>>;
|
|
105
|
+
}
|
package/src/Tag.ts
CHANGED
package/src/Type.test.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import * as Obj from './Obj';
|
|
9
|
+
import * as Relation from './Relation';
|
|
10
|
+
import { TestSchema } from './testing';
|
|
11
|
+
import * as Type from './Type';
|
|
12
|
+
|
|
13
|
+
describe('Type', () => {
|
|
14
|
+
describe('Type.Obj', () => {
|
|
15
|
+
test('has SchemaKindId for schema type checking', ({ expect }) => {
|
|
16
|
+
// Type.isObjectSchema uses SchemaKindId to check if a schema is an object schema.
|
|
17
|
+
expect(Type.isObjectSchema(Type.Obj)).toBe(true);
|
|
18
|
+
expect(Type.isObjectSchema(TestSchema.Person)).toBe(true);
|
|
19
|
+
expect(Type.isObjectSchema(Type.Relation)).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('Schema.is validates structural compatibility only', ({ expect }) => {
|
|
23
|
+
// Schema.is does structural validation (has id field).
|
|
24
|
+
// It accepts both ECHO objects and plain objects with compatible structure.
|
|
25
|
+
expect(Schema.is(Type.Obj)({ id: 'plain-object' })).toBe(true);
|
|
26
|
+
const obj = Obj.make(TestSchema.Person, { name: 'Test' });
|
|
27
|
+
expect(Schema.is(Type.Obj)(obj)).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('Type.Relation', () => {
|
|
32
|
+
test('has SchemaKindId for schema type checking', ({ expect }) => {
|
|
33
|
+
// Type.isRelationSchema uses SchemaKindId to check if a schema is a relation schema.
|
|
34
|
+
expect(Type.isRelationSchema(Type.Relation)).toBe(true);
|
|
35
|
+
expect(Type.isRelationSchema(TestSchema.HasManager)).toBe(true);
|
|
36
|
+
expect(Type.isRelationSchema(Type.Obj)).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('Schema.is validates structural compatibility only', ({ expect }) => {
|
|
40
|
+
// Schema.is does structural validation (has id field).
|
|
41
|
+
// It accepts both ECHO relations and plain objects with compatible structure.
|
|
42
|
+
expect(Schema.is(Type.Relation)({ id: 'plain-object' })).toBe(true);
|
|
43
|
+
const obj1 = Obj.make(TestSchema.Person, { name: 'Alice' });
|
|
44
|
+
const obj2 = Obj.make(TestSchema.Person, { name: 'Bob' });
|
|
45
|
+
const rel = Relation.make(TestSchema.HasManager, {
|
|
46
|
+
[Relation.Source]: obj1,
|
|
47
|
+
[Relation.Target]: obj2,
|
|
48
|
+
});
|
|
49
|
+
expect(Schema.is(Type.Relation)(rel)).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|