@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
|
@@ -7,7 +7,6 @@ import type * as Schema from 'effect/Schema';
|
|
|
7
7
|
import { raise } from '@dxos/debug';
|
|
8
8
|
import { assertArgument, failedInvariant } from '@dxos/invariant';
|
|
9
9
|
import { ObjectId } from '@dxos/keys';
|
|
10
|
-
import { defineHiddenProperty } from '@dxos/live-object';
|
|
11
10
|
|
|
12
11
|
import { getSchemaDXN, getTypeAnnotation, setTypename } from '../annotations';
|
|
13
12
|
import {
|
|
@@ -18,6 +17,7 @@ import {
|
|
|
18
17
|
assertObjectModel,
|
|
19
18
|
getObjectDXN,
|
|
20
19
|
} from '../entities';
|
|
20
|
+
import { defineHiddenProperty } from '../proxy';
|
|
21
21
|
import { EntityKind, KindId, MetaId, setSchema } from '../types';
|
|
22
22
|
|
|
23
23
|
import { attachedTypedObjectInspector } from './inspect';
|
|
@@ -41,7 +41,7 @@ export type CreateObjectProps<T> = T extends { id: string } ? Omit<T, 'id' | Kin
|
|
|
41
41
|
* const Contact = Schema.Struct({
|
|
42
42
|
* name: Schema.String,
|
|
43
43
|
* email: Schema.String,
|
|
44
|
-
* }).pipe(Type.
|
|
44
|
+
* }).pipe(Type.object({
|
|
45
45
|
* typename: 'example.com/type/Person',
|
|
46
46
|
* version: '0.1.0',
|
|
47
47
|
* }))
|
|
@@ -7,7 +7,7 @@ import type { InspectOptionsStylized, inspect as inspectFn } from 'node:util';
|
|
|
7
7
|
import { type CustomInspectFunction, inspectCustom } from '@dxos/debug';
|
|
8
8
|
|
|
9
9
|
import { getTypeDXN } from '../annotations';
|
|
10
|
-
import { ATTR_META, ATTR_TYPE, type
|
|
10
|
+
import { ATTR_META, ATTR_TYPE, type AnyEntity, MetaId } from '../types';
|
|
11
11
|
|
|
12
12
|
/*
|
|
13
13
|
* @internal
|
|
@@ -27,8 +27,8 @@ export const attachedTypedObjectInspector = (obj: any) => {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
// NOTE: KEEP as function.
|
|
30
|
-
const typedObjectInspectFunction: CustomInspectFunction<
|
|
31
|
-
this:
|
|
30
|
+
const typedObjectInspectFunction: CustomInspectFunction<AnyEntity> = function (
|
|
31
|
+
this: AnyEntity,
|
|
32
32
|
depth: number,
|
|
33
33
|
options: InspectOptionsStylized,
|
|
34
34
|
inspect: typeof inspectFn,
|
|
@@ -6,6 +6,7 @@ import { describe, expect, test } from 'vitest';
|
|
|
6
6
|
|
|
7
7
|
import { DXN } from '@dxos/keys';
|
|
8
8
|
|
|
9
|
+
import * as Obj from '../../Obj';
|
|
9
10
|
import { TestSchema } from '../../testing';
|
|
10
11
|
import { getSchemaDXN, getSchemaTypename, getTypeDXN, getTypename } from '../annotations';
|
|
11
12
|
import { RelationSourceId, RelationTargetId, getObjectDXN } from '../entities';
|
|
@@ -19,7 +20,9 @@ import { objectFromJSON, objectToJSON } from './json-serializer';
|
|
|
19
20
|
describe('Object JSON serializer', () => {
|
|
20
21
|
test('should serialize and deserialize object', async () => {
|
|
21
22
|
const contact = makeObject(TestSchema.Person, { name: 'Alice' });
|
|
22
|
-
|
|
23
|
+
Obj.change(contact, (c) => {
|
|
24
|
+
getMeta(c).keys.push({ id: '12345', source: 'example.com' });
|
|
25
|
+
});
|
|
23
26
|
|
|
24
27
|
const task = createObject(TestSchema.Task, {
|
|
25
28
|
title: 'Fix the tests',
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
7
|
import { raise } from '@dxos/debug';
|
|
8
|
-
import { type EncodedReference,
|
|
8
|
+
import { type EncodedReference, ObjectStructure, isEncodedReference } from '@dxos/echo-protocol';
|
|
9
9
|
import { assertArgument, invariant } from '@dxos/invariant';
|
|
10
10
|
import { DXN, ObjectId } from '@dxos/keys';
|
|
11
|
-
import { defineHiddenProperty } from '@dxos/live-object';
|
|
12
11
|
import { assumeType, deepMapValues, visitValues } from '@dxos/util';
|
|
13
12
|
|
|
13
|
+
import type * as Obj from '../../Obj';
|
|
14
14
|
import { getTypeDXN, setTypename } from '../annotations';
|
|
15
15
|
import {
|
|
16
16
|
ATTR_DELETED,
|
|
@@ -25,19 +25,22 @@ import {
|
|
|
25
25
|
SelfDXNId,
|
|
26
26
|
assertObjectModel,
|
|
27
27
|
} from '../entities';
|
|
28
|
+
import { attachTypedJsonSerializer, defineHiddenProperty, typedJsonSerializer } from '../proxy';
|
|
28
29
|
import { Ref, type RefResolver, refFromEncodedReference, setRefResolver } from '../ref';
|
|
29
30
|
import {
|
|
30
31
|
ATTR_META,
|
|
31
32
|
ATTR_TYPE,
|
|
32
|
-
type
|
|
33
|
+
type AnyEntity,
|
|
33
34
|
EntityKind,
|
|
34
35
|
KindId,
|
|
35
36
|
MetaId,
|
|
36
37
|
ObjectMetaSchema,
|
|
37
|
-
TypeId,
|
|
38
38
|
setSchema,
|
|
39
39
|
} from '../types';
|
|
40
40
|
|
|
41
|
+
// Re-export for backward compatibility.
|
|
42
|
+
export { attachTypedJsonSerializer };
|
|
43
|
+
|
|
41
44
|
type DeepReplaceRef<T> =
|
|
42
45
|
T extends Ref<any>
|
|
43
46
|
? EncodedReference
|
|
@@ -54,7 +57,7 @@ type SerializedObject<T extends { id: string }> = {
|
|
|
54
57
|
/**
|
|
55
58
|
* Converts object to it's JSON representation.
|
|
56
59
|
*/
|
|
57
|
-
export const objectToJSON = <T extends
|
|
60
|
+
export const objectToJSON = <T extends AnyEntity>(obj: T): SerializedObject<T> => {
|
|
58
61
|
const typename = getTypeDXN(obj)?.toString();
|
|
59
62
|
invariant(typename && typeof typename === 'string');
|
|
60
63
|
return typedJsonSerializer.call(obj);
|
|
@@ -69,7 +72,7 @@ export const objectToJSON = <T extends AnyEchoObject>(obj: T): SerializedObject<
|
|
|
69
72
|
export const objectFromJSON = async (
|
|
70
73
|
jsonData: unknown,
|
|
71
74
|
{ refResolver, dxn }: { refResolver?: RefResolver; dxn?: DXN } = {},
|
|
72
|
-
): Promise<
|
|
75
|
+
): Promise<AnyEntity> => {
|
|
73
76
|
assumeType<ObjectJSON>(jsonData);
|
|
74
77
|
assertArgument(typeof jsonData === 'object' && jsonData !== null, 'jsonData', 'expect object');
|
|
75
78
|
assertArgument(typeof jsonData[ATTR_TYPE] === 'string', 'jsonData[ATTR_TYPE]', 'expected object to have a type');
|
|
@@ -101,8 +104,8 @@ export const objectFromJSON = async (
|
|
|
101
104
|
const sourceDxn: DXN = DXN.parse(jsonData[ATTR_RELATION_SOURCE] ?? raise(new TypeError('Missing relation source')));
|
|
102
105
|
const targetDxn: DXN = DXN.parse(jsonData[ATTR_RELATION_TARGET] ?? raise(new TypeError('Missing relation target')));
|
|
103
106
|
|
|
104
|
-
const source = (await refResolver?.resolve(sourceDxn)) as
|
|
105
|
-
const target = (await refResolver?.resolve(targetDxn)) as
|
|
107
|
+
const source = (await refResolver?.resolve(sourceDxn)) as AnyEntity | undefined;
|
|
108
|
+
const target = (await refResolver?.resolve(targetDxn)) as AnyEntity | undefined;
|
|
106
109
|
|
|
107
110
|
defineHiddenProperty(obj, KindId, EntityKind.Relation);
|
|
108
111
|
defineHiddenProperty(obj, RelationSourceDXNId, sourceDxn);
|
|
@@ -117,6 +120,10 @@ export const objectFromJSON = async (
|
|
|
117
120
|
const meta = await ObjectMetaSchema.pipe(Schema.decodeUnknownPromise)(jsonData[ATTR_META]);
|
|
118
121
|
invariant(Array.isArray(meta.keys));
|
|
119
122
|
defineHiddenProperty(obj, MetaId, meta);
|
|
123
|
+
} else {
|
|
124
|
+
defineHiddenProperty(obj, MetaId, {
|
|
125
|
+
keys: [],
|
|
126
|
+
});
|
|
120
127
|
}
|
|
121
128
|
|
|
122
129
|
if (dxn) {
|
|
@@ -153,7 +160,7 @@ const decodeGeneric = (jsonData: unknown, options: { refResolver?: RefResolver }
|
|
|
153
160
|
});
|
|
154
161
|
};
|
|
155
162
|
|
|
156
|
-
export const setRefResolverOnData = (obj:
|
|
163
|
+
export const setRefResolverOnData = (obj: AnyEntity, refResolver: RefResolver) => {
|
|
157
164
|
const visitor = (value: unknown) => {
|
|
158
165
|
if (Ref.isRef(value)) {
|
|
159
166
|
setRefResolver(value, refResolver);
|
|
@@ -165,66 +172,17 @@ export const setRefResolverOnData = (obj: AnyEchoObject, refResolver: RefResolve
|
|
|
165
172
|
visitor(obj);
|
|
166
173
|
};
|
|
167
174
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
// NOTE: KEEP as function.
|
|
184
|
-
const typedJsonSerializer = function (this: any) {
|
|
185
|
-
const { id, ...rest } = this;
|
|
186
|
-
const result: any = {
|
|
187
|
-
id,
|
|
175
|
+
/**
|
|
176
|
+
* Convert ObjectStructure to JSON data for indexing.
|
|
177
|
+
* Different from {@link objectToJSON} as it takes the internal {@link ObjectStructure} representation directly
|
|
178
|
+
*/
|
|
179
|
+
export const objectStructureToJson = (objectId: string, structure: ObjectStructure): Obj.JSON => {
|
|
180
|
+
return {
|
|
181
|
+
...structure.data,
|
|
182
|
+
id: objectId,
|
|
183
|
+
[ATTR_TYPE]: (ObjectStructure.getTypeReference(structure)?.['/'] ?? '') as DXN.String,
|
|
184
|
+
[ATTR_DELETED]: ObjectStructure.isDeleted(structure),
|
|
185
|
+
[ATTR_RELATION_SOURCE]: ObjectStructure.getRelationSource(structure)?.['/'] as DXN.String | undefined,
|
|
186
|
+
[ATTR_RELATION_TARGET]: ObjectStructure.getRelationTarget(structure)?.['/'] as DXN.String | undefined,
|
|
188
187
|
};
|
|
189
|
-
|
|
190
|
-
if (this[TypeId]) {
|
|
191
|
-
result[ATTR_TYPE] = this[TypeId].toString();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (this[MetaId]) {
|
|
195
|
-
result[ATTR_META] = serializeMeta(this[MetaId]);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (this[SelfDXNId]) {
|
|
199
|
-
result[ATTR_SELF_DXN] = this[SelfDXNId].toString();
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (this[RelationSourceDXNId]) {
|
|
203
|
-
const sourceDXN = this[RelationSourceDXNId];
|
|
204
|
-
invariant(sourceDXN instanceof DXN);
|
|
205
|
-
result[ATTR_RELATION_SOURCE] = sourceDXN.toString();
|
|
206
|
-
}
|
|
207
|
-
if (this[RelationTargetDXNId]) {
|
|
208
|
-
const targetDXN = this[RelationTargetDXNId];
|
|
209
|
-
invariant(targetDXN instanceof DXN);
|
|
210
|
-
result[ATTR_RELATION_TARGET] = targetDXN.toString();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
Object.assign(result, serializeData(rest));
|
|
214
|
-
return result;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const serializeData = (data: unknown) => {
|
|
218
|
-
return deepMapValues(data, (value, recurse) => {
|
|
219
|
-
if (Ref.isRef(value)) {
|
|
220
|
-
// TODO(dmaretskyi): Should this be configurable?
|
|
221
|
-
return value.noInline().encode();
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return recurse(value);
|
|
225
|
-
});
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
const serializeMeta = (meta: ObjectMeta) => {
|
|
229
|
-
return deepMapValues(meta, (value, recurse) => recurse(value));
|
|
230
188
|
};
|
|
@@ -2,241 +2,5 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { invariant } from '@dxos/invariant';
|
|
9
|
-
|
|
10
|
-
import { SchemaId } from '../types';
|
|
11
|
-
|
|
12
|
-
// TODO(burdon): Reconcile with @dxos/effect visit().
|
|
13
|
-
|
|
14
|
-
export class SchemaValidator {
|
|
15
|
-
/**
|
|
16
|
-
* Recursively check that schema specifies constructions we can handle.
|
|
17
|
-
* Validates there are no ambiguous discriminated union types.
|
|
18
|
-
*/
|
|
19
|
-
public static validateSchema(schema: Schema.Schema.AnyNoContext): void {
|
|
20
|
-
const visitAll = (nodes: SchemaAST.AST[]) => nodes.forEach((node) => this.validateSchema(Schema.make(node)));
|
|
21
|
-
if (SchemaAST.isUnion(schema.ast)) {
|
|
22
|
-
const typeAstList = schema.ast.types.filter((type) => SchemaAST.isTypeLiteral(type)) as SchemaAST.TypeLiteral[];
|
|
23
|
-
// Check we can handle a discriminated union.
|
|
24
|
-
if (typeAstList.length > 1) {
|
|
25
|
-
getTypeDiscriminators(typeAstList);
|
|
26
|
-
}
|
|
27
|
-
visitAll(typeAstList);
|
|
28
|
-
} else if (SchemaAST.isTupleType(schema.ast)) {
|
|
29
|
-
const positionalTypes = schema.ast.elements.map((t) => t.type);
|
|
30
|
-
const allTypes = positionalTypes.concat(schema.ast.rest.map((t) => t.type));
|
|
31
|
-
visitAll(allTypes);
|
|
32
|
-
} else if (SchemaAST.isTypeLiteral(schema.ast)) {
|
|
33
|
-
visitAll(SchemaAST.getPropertySignatures(schema.ast).map((p) => p.type));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public static hasTypeAnnotation(
|
|
38
|
-
rootObjectSchema: Schema.Schema.AnyNoContext,
|
|
39
|
-
property: string,
|
|
40
|
-
annotation: symbol,
|
|
41
|
-
): boolean {
|
|
42
|
-
try {
|
|
43
|
-
let type = this.getPropertySchema(rootObjectSchema, [property]);
|
|
44
|
-
if (SchemaAST.isTupleType(type.ast)) {
|
|
45
|
-
type = this.getPropertySchema(rootObjectSchema, [property, '0']);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return type.ast.annotations[annotation] != null;
|
|
49
|
-
} catch {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public static getPropertySchema(
|
|
55
|
-
rootObjectSchema: Schema.Schema.AnyNoContext,
|
|
56
|
-
propertyPath: KeyPath,
|
|
57
|
-
getProperty: (path: KeyPath) => any = () => null,
|
|
58
|
-
): Schema.Schema.AnyNoContext {
|
|
59
|
-
let schema: Schema.Schema.AnyNoContext = rootObjectSchema;
|
|
60
|
-
for (let i = 0; i < propertyPath.length; i++) {
|
|
61
|
-
const propertyName = propertyPath[i];
|
|
62
|
-
const tupleAst = unwrapArray(schema.ast);
|
|
63
|
-
if (tupleAst != null) {
|
|
64
|
-
schema = getArrayElementSchema(tupleAst, propertyName);
|
|
65
|
-
} else {
|
|
66
|
-
const propertyType = getPropertyType(schema.ast, propertyName.toString(), (propertyName) =>
|
|
67
|
-
getProperty([...propertyPath.slice(0, i), propertyName]),
|
|
68
|
-
);
|
|
69
|
-
if (propertyType == null) {
|
|
70
|
-
throw new TypeError(`unknown property: ${String(propertyName)} on object. Path: ${propertyPath}`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
schema = Schema.make(propertyType).annotations(propertyType.annotations);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return schema;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public static getTargetPropertySchema(target: any, prop: string | symbol): Schema.Schema.AnyNoContext {
|
|
81
|
-
const schema: Schema.Schema.AnyNoContext | undefined = (target as any)[SchemaId];
|
|
82
|
-
invariant(schema, 'target has no schema');
|
|
83
|
-
const arrayAst = unwrapArray(schema.ast);
|
|
84
|
-
if (arrayAst != null) {
|
|
85
|
-
return getArrayElementSchema(arrayAst, prop);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const propertyType = getPropertyType(schema.ast, prop.toString(), (prop) => target[prop]);
|
|
89
|
-
if (propertyType == null) {
|
|
90
|
-
return Schema.Any; // TODO(burdon): HACK.
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
invariant(propertyType, `invalid property: ${prop.toString()}`);
|
|
94
|
-
return Schema.make(propertyType);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Tuple AST is used both for:
|
|
100
|
-
* fixed-length tuples ([string, number]) in which case AST will be { elements: [Schema.String, Schema.Number] }
|
|
101
|
-
* variable-length arrays (Array<string | number>) in which case AST will be { rest: [Schema.Union(Schema.String, Schema.Number)] }
|
|
102
|
-
*/
|
|
103
|
-
const getArrayElementSchema = (
|
|
104
|
-
tupleAst: SchemaAST.TupleType,
|
|
105
|
-
property: string | symbol | number,
|
|
106
|
-
): Schema.Schema.AnyNoContext => {
|
|
107
|
-
const elementIndex = typeof property === 'string' ? parseInt(property, 10) : Number.NaN;
|
|
108
|
-
if (Number.isNaN(elementIndex)) {
|
|
109
|
-
invariant(property === 'length', `invalid array property: ${String(property)}`);
|
|
110
|
-
return Schema.Number;
|
|
111
|
-
}
|
|
112
|
-
if (elementIndex < tupleAst.elements.length) {
|
|
113
|
-
const elementType = tupleAst.elements[elementIndex].type;
|
|
114
|
-
return Schema.make(elementType).annotations(elementType.annotations);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const restType = tupleAst.rest;
|
|
118
|
-
return Schema.make(restType[0].type).annotations(restType[0].annotations);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const flattenUnion = (typeAst: SchemaAST.AST): SchemaAST.AST[] =>
|
|
122
|
-
SchemaAST.isUnion(typeAst) ? typeAst.types.flatMap(flattenUnion) : [typeAst];
|
|
123
|
-
|
|
124
|
-
const getProperties = (
|
|
125
|
-
typeAst: SchemaAST.AST,
|
|
126
|
-
getTargetPropertyFn: (propertyName: string) => any,
|
|
127
|
-
): SchemaAST.PropertySignature[] => {
|
|
128
|
-
const astCandidates = flattenUnion(typeAst);
|
|
129
|
-
const typeAstList = astCandidates.filter((type) => SchemaAST.isTypeLiteral(type)) as SchemaAST.TypeLiteral[];
|
|
130
|
-
if (typeAstList.length === 0) {
|
|
131
|
-
return [];
|
|
132
|
-
}
|
|
133
|
-
if (typeAstList.length === 1) {
|
|
134
|
-
return SchemaAST.getPropertySignatures(typeAstList[0]);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const typeDiscriminators = getTypeDiscriminators(typeAstList);
|
|
138
|
-
const targetPropertyValue = getTargetPropertyFn(String(typeDiscriminators[0].name));
|
|
139
|
-
const typeIndex = typeDiscriminators.findIndex((p) => targetPropertyValue === (p.type as SchemaAST.Literal).literal);
|
|
140
|
-
invariant(typeIndex !== -1, 'discriminator field not set on target');
|
|
141
|
-
return SchemaAST.getPropertySignatures(typeAstList[typeIndex]);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const getPropertyType = (
|
|
145
|
-
ast: SchemaAST.AST,
|
|
146
|
-
propertyName: string,
|
|
147
|
-
getTargetPropertyFn: (propertyName: string) => any,
|
|
148
|
-
): SchemaAST.AST | null => {
|
|
149
|
-
const anyOrObject = unwrapAst(
|
|
150
|
-
ast,
|
|
151
|
-
(candidate) => SchemaAST.isAnyKeyword(candidate) || SchemaAST.isObjectKeyword(candidate),
|
|
152
|
-
);
|
|
153
|
-
if (anyOrObject != null) {
|
|
154
|
-
return ast;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const typeOrDiscriminatedUnion = unwrapAst(ast, (t) => {
|
|
158
|
-
return SchemaAST.isTypeLiteral(t) || (SchemaAST.isUnion(t) && t.types.some((t) => SchemaAST.isTypeLiteral(t)));
|
|
159
|
-
});
|
|
160
|
-
if (typeOrDiscriminatedUnion == null) {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const targetProperty = getProperties(typeOrDiscriminatedUnion, getTargetPropertyFn).find(
|
|
165
|
-
(p) => p.name === propertyName,
|
|
166
|
-
);
|
|
167
|
-
if (targetProperty != null) {
|
|
168
|
-
return unwrapAst(targetProperty.type);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const indexSignatureType = unwrapAst(ast, SchemaAST.isTypeLiteral);
|
|
172
|
-
if (
|
|
173
|
-
indexSignatureType &&
|
|
174
|
-
SchemaAST.isTypeLiteral(indexSignatureType) &&
|
|
175
|
-
indexSignatureType.indexSignatures.length > 0
|
|
176
|
-
) {
|
|
177
|
-
return unwrapAst(indexSignatureType.indexSignatures[0].type);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return null;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const getTypeDiscriminators = (typeAstList: SchemaAST.TypeLiteral[]): SchemaAST.PropertySignature[] => {
|
|
184
|
-
const discriminatorPropCandidates = typeAstList
|
|
185
|
-
.flatMap(SchemaAST.getPropertySignatures)
|
|
186
|
-
.filter((p) => SchemaAST.isLiteral(p.type));
|
|
187
|
-
const propertyName = discriminatorPropCandidates[0].name;
|
|
188
|
-
const isValidDiscriminator = discriminatorPropCandidates.every((p) => p.name === propertyName && !p.isOptional);
|
|
189
|
-
const everyTypeHasDiscriminator = discriminatorPropCandidates.length === typeAstList.length;
|
|
190
|
-
const isDiscriminatedUnion = isValidDiscriminator && everyTypeHasDiscriminator;
|
|
191
|
-
invariant(isDiscriminatedUnion, 'type ambiguity: every type in a union must have a single unique-literal field');
|
|
192
|
-
return discriminatorPropCandidates;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Used to check that rootAst is for a type matching the provided predicate.
|
|
197
|
-
* That's not always straightforward because types of optionality and recursive types.
|
|
198
|
-
* const Task = Schema.Struct({
|
|
199
|
-
* ...,
|
|
200
|
-
* previous?: Schema.optional(Schema.suspend(() => Task)),
|
|
201
|
-
* });
|
|
202
|
-
* Here the AST for `previous` field is going to be Union(Suspend(Type), Undefined).
|
|
203
|
-
* SchemaAST.isTypeLiteral(field) will return false, but unwrapAst(field, (ast) => SchemaAST.isTypeLiteral(ast))
|
|
204
|
-
* will return true.
|
|
205
|
-
*/
|
|
206
|
-
const unwrapAst = (rootAst: SchemaAST.AST, predicate?: (ast: SchemaAST.AST) => boolean): SchemaAST.AST | null => {
|
|
207
|
-
let ast: SchemaAST.AST | undefined = rootAst;
|
|
208
|
-
while (ast != null) {
|
|
209
|
-
if (predicate?.(ast)) {
|
|
210
|
-
return ast;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (SchemaAST.isUnion(ast)) {
|
|
214
|
-
const next: any = ast.types.find((t) => (predicate != null && predicate(t)) || SchemaAST.isSuspend(t));
|
|
215
|
-
if (next != null) {
|
|
216
|
-
ast = next;
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (SchemaAST.isSuspend(ast)) {
|
|
222
|
-
ast = ast.f();
|
|
223
|
-
} else {
|
|
224
|
-
return predicate == null ? ast : null;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return null;
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const unwrapArray = (ast: SchemaAST.AST) => unwrapAst(ast, SchemaAST.isTupleType) as SchemaAST.TupleType | null;
|
|
232
|
-
|
|
233
|
-
export const checkIdNotPresentOnSchema = (schema: Schema.Schema<any, any, any>) => {
|
|
234
|
-
invariant(SchemaAST.isTypeLiteral(schema.ast));
|
|
235
|
-
const idProperty = SchemaAST.getPropertySignatures(schema.ast).find((prop) => prop.name === 'id');
|
|
236
|
-
if (idProperty != null) {
|
|
237
|
-
throw new Error('"id" property name is reserved');
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
// TODO(burdon): Reconcile with JsonPath.
|
|
242
|
-
type KeyPath = readonly (string | number)[];
|
|
5
|
+
// Re-export from proxy for backward compatibility.
|
|
6
|
+
export { SchemaValidator, checkIdNotPresentOnSchema } from '../proxy';
|