@dxos/echo 0.8.4-main.84f28bd → 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 +2 -3
- package/dist/lib/browser/Annotation.mjs +33 -0
- package/dist/lib/browser/Annotation.mjs.map +7 -0
- package/dist/lib/browser/Database.mjs +18 -0
- package/dist/lib/browser/Database.mjs.map +7 -0
- package/dist/lib/browser/Entity.mjs +52 -0
- package/dist/lib/browser/Entity.mjs.map +7 -0
- package/dist/lib/browser/Err.mjs +11 -0
- package/dist/lib/browser/Err.mjs.map +7 -0
- package/dist/lib/browser/Filter.mjs +62 -0
- package/dist/lib/browser/Filter.mjs.map +7 -0
- package/dist/lib/browser/Format.mjs +67 -0
- package/dist/lib/browser/Format.mjs.map +7 -0
- package/dist/lib/browser/JsonSchema.mjs +20 -0
- package/dist/lib/browser/JsonSchema.mjs.map +7 -0
- package/dist/lib/browser/Key.mjs +13 -0
- package/dist/lib/browser/Key.mjs.map +7 -0
- package/dist/lib/browser/Obj.mjs +91 -0
- package/dist/lib/browser/Obj.mjs.map +7 -0
- package/dist/lib/browser/Order.mjs +13 -0
- package/dist/lib/browser/Order.mjs.map +7 -0
- package/dist/lib/browser/Query.mjs +27 -0
- package/dist/lib/browser/Query.mjs.map +7 -0
- package/dist/lib/browser/QueryResult.mjs +3 -0
- package/dist/lib/browser/QueryResult.mjs.map +7 -0
- package/dist/lib/browser/Ref.mjs +23 -0
- package/dist/lib/browser/Ref.mjs.map +7 -0
- package/dist/lib/browser/Relation.mjs +85 -0
- package/dist/lib/browser/Relation.mjs.map +7 -0
- package/dist/lib/browser/SchemaRegistry.mjs +3 -0
- package/dist/lib/browser/SchemaRegistry.mjs.map +7 -0
- package/dist/lib/browser/Tag.mjs +26 -0
- package/dist/lib/browser/Tag.mjs.map +7 -0
- package/dist/lib/browser/Type.mjs +48 -0
- package/dist/lib/browser/Type.mjs.map +7 -0
- package/dist/lib/browser/chunk-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-BJPE6CIC.mjs +3847 -0
- 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 +72 -9
- package/dist/lib/browser/internal/index.mjs +457 -0
- package/dist/lib/browser/internal/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +332 -35
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/Annotation.mjs +33 -0
- package/dist/lib/node-esm/Annotation.mjs.map +7 -0
- package/dist/lib/node-esm/Database.mjs +18 -0
- package/dist/lib/node-esm/Database.mjs.map +7 -0
- package/dist/lib/node-esm/Entity.mjs +52 -0
- package/dist/lib/node-esm/Entity.mjs.map +7 -0
- package/dist/lib/node-esm/Err.mjs +11 -0
- package/dist/lib/node-esm/Err.mjs.map +7 -0
- package/dist/lib/node-esm/Filter.mjs +62 -0
- package/dist/lib/node-esm/Filter.mjs.map +7 -0
- package/dist/lib/node-esm/Format.mjs +67 -0
- package/dist/lib/node-esm/Format.mjs.map +7 -0
- package/dist/lib/node-esm/JsonSchema.mjs +20 -0
- package/dist/lib/node-esm/JsonSchema.mjs.map +7 -0
- package/dist/lib/node-esm/Key.mjs +13 -0
- package/dist/lib/node-esm/Key.mjs.map +7 -0
- package/dist/lib/node-esm/Obj.mjs +91 -0
- package/dist/lib/node-esm/Obj.mjs.map +7 -0
- package/dist/lib/node-esm/Order.mjs +13 -0
- package/dist/lib/node-esm/Order.mjs.map +7 -0
- package/dist/lib/node-esm/Query.mjs +27 -0
- package/dist/lib/node-esm/Query.mjs.map +7 -0
- package/dist/lib/node-esm/QueryResult.mjs +3 -0
- package/dist/lib/node-esm/QueryResult.mjs.map +7 -0
- package/dist/lib/node-esm/Ref.mjs +23 -0
- package/dist/lib/node-esm/Ref.mjs.map +7 -0
- package/dist/lib/node-esm/Relation.mjs +85 -0
- package/dist/lib/node-esm/Relation.mjs.map +7 -0
- package/dist/lib/node-esm/SchemaRegistry.mjs +3 -0
- package/dist/lib/node-esm/SchemaRegistry.mjs.map +7 -0
- package/dist/lib/node-esm/Tag.mjs +26 -0
- package/dist/lib/node-esm/Tag.mjs.map +7 -0
- package/dist/lib/node-esm/Type.mjs +48 -0
- package/dist/lib/node-esm/Type.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-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-LT3H4JOX.mjs +3847 -0
- 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 +72 -9
- package/dist/lib/node-esm/internal/index.mjs +457 -0
- package/dist/lib/node-esm/internal/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +332 -35
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/Annotation.d.ts +2 -0
- package/dist/types/src/Annotation.d.ts.map +1 -0
- package/dist/types/src/Database.d.ts +194 -0
- package/dist/types/src/Database.d.ts.map +1 -0
- package/dist/types/src/Entity.d.ts +142 -0
- package/dist/types/src/Entity.d.ts.map +1 -0
- package/dist/types/src/Entity.test.d.ts +2 -0
- package/dist/types/src/Entity.test.d.ts.map +1 -0
- package/dist/types/src/Err.d.ts +64 -0
- package/dist/types/src/Err.d.ts.map +1 -0
- package/dist/types/src/Filter.d.ts +120 -0
- package/dist/types/src/Filter.d.ts.map +1 -0
- package/dist/types/src/Format.d.ts +4 -0
- package/dist/types/src/Format.d.ts.map +1 -0
- package/dist/types/src/Hypergraph.d.ts +60 -0
- package/dist/types/src/Hypergraph.d.ts.map +1 -0
- package/dist/types/src/JsonSchema.d.ts +9 -0
- package/dist/types/src/JsonSchema.d.ts.map +1 -0
- package/dist/types/src/Key.d.ts +1 -0
- package/dist/types/src/Key.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +344 -34
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Obj.test.d.ts +2 -0
- package/dist/types/src/Obj.test.d.ts.map +1 -0
- package/dist/types/src/Order.d.ts +16 -0
- package/dist/types/src/Order.d.ts.map +1 -0
- package/dist/types/src/Query.d.ts +115 -0
- package/dist/types/src/Query.d.ts.map +1 -0
- package/dist/types/src/Query.test.d.ts +2 -0
- package/dist/types/src/Query.test.d.ts.map +1 -0
- package/dist/types/src/QueryResult.d.ts +80 -0
- package/dist/types/src/QueryResult.d.ts.map +1 -0
- package/dist/types/src/Ref.d.ts +13 -11
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +242 -19
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/Relation.test.d.ts +2 -0
- package/dist/types/src/Relation.test.d.ts.map +1 -0
- package/dist/types/src/SchemaRegistry.d.ts +84 -0
- package/dist/types/src/SchemaRegistry.d.ts.map +1 -0
- package/dist/types/src/Tag.d.ts +17 -0
- package/dist/types/src/Tag.d.ts.map +1 -0
- package/dist/types/src/Type.d.ts +225 -73
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/Type.test.d.ts +2 -0
- package/dist/types/src/Type.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +15 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/annotations/annotations.d.ts +170 -0
- package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/annotations.test.d.ts +2 -0
- package/dist/types/src/internal/annotations/annotations.test.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/index.d.ts +3 -0
- package/dist/types/src/internal/annotations/index.d.ts.map +1 -0
- package/dist/types/src/internal/annotations/util.d.ts +27 -0
- package/dist/types/src/internal/annotations/util.d.ts.map +1 -0
- package/dist/types/src/internal/api/annotations.d.ts +23 -0
- package/dist/types/src/internal/api/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/api/entity.d.ts +13 -0
- package/dist/types/src/internal/api/entity.d.ts.map +1 -0
- package/dist/types/src/internal/api/index.d.ts +15 -0
- package/dist/types/src/internal/api/index.d.ts.map +1 -0
- package/dist/types/src/internal/api/meta.d.ts +42 -0
- package/dist/types/src/internal/api/meta.d.ts.map +1 -0
- package/dist/types/src/internal/api/sorting.d.ts +24 -0
- package/dist/types/src/internal/api/sorting.d.ts.map +1 -0
- package/dist/types/src/internal/api/version.d.ts +42 -0
- package/dist/types/src/internal/api/version.d.ts.map +1 -0
- package/dist/types/src/internal/entities/entity.d.ts +20 -0
- package/dist/types/src/internal/entities/entity.d.ts.map +1 -0
- package/dist/types/src/internal/entities/index.d.ts +6 -0
- package/dist/types/src/internal/entities/index.d.ts.map +1 -0
- package/dist/types/src/internal/entities/model.d.ts +77 -0
- package/dist/types/src/internal/entities/model.d.ts.map +1 -0
- package/dist/types/src/internal/entities/object.d.ts +18 -0
- package/dist/types/src/internal/entities/object.d.ts.map +1 -0
- package/dist/types/src/internal/entities/relation.d.ts +62 -0
- package/dist/types/src/internal/entities/relation.d.ts.map +1 -0
- package/dist/types/src/internal/entities/util.d.ts +2 -0
- package/dist/types/src/internal/entities/util.d.ts.map +1 -0
- package/dist/types/src/internal/formats/date.d.ts +63 -0
- package/dist/types/src/internal/formats/date.d.ts.map +1 -0
- package/dist/types/src/internal/formats/date.test.d.ts +2 -0
- package/dist/types/src/internal/formats/date.test.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.d.ts +32 -0
- package/dist/types/src/internal/formats/format.d.ts.map +1 -0
- package/dist/types/src/internal/formats/format.test.d.ts +2 -0
- package/dist/types/src/internal/formats/format.test.d.ts.map +1 -0
- package/dist/types/src/internal/formats/index.d.ts +8 -0
- package/dist/types/src/internal/formats/index.d.ts.map +1 -0
- package/dist/types/src/internal/formats/number.d.ts +31 -0
- package/dist/types/src/internal/formats/number.d.ts.map +1 -0
- package/dist/types/src/internal/formats/object.d.ts +35 -0
- package/dist/types/src/internal/formats/object.d.ts.map +1 -0
- package/dist/types/src/internal/formats/select.d.ts +13 -0
- package/dist/types/src/internal/formats/select.d.ts.map +1 -0
- package/dist/types/src/internal/formats/string.d.ts +42 -0
- package/dist/types/src/internal/formats/string.d.ts.map +1 -0
- package/dist/types/src/internal/formats/types.d.ts +72 -0
- package/dist/types/src/internal/formats/types.d.ts.map +1 -0
- package/dist/types/src/internal/index.d.ts +12 -0
- package/dist/types/src/internal/index.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/annotations.d.ts +19 -0
- package/dist/types/src/internal/json-schema/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/effect-schema.test.d.ts +2 -0
- package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/index.d.ts +5 -0
- package/dist/types/src/internal/json-schema/index.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts +7 -0
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts +250 -0
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema.d.ts +29 -0
- package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -0
- package/dist/types/src/internal/json-schema/json-schema.test.d.ts +2 -0
- package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/clone.d.ts +8 -0
- package/dist/types/src/internal/object/clone.d.ts.map +1 -0
- package/dist/types/src/internal/object/common.d.ts +18 -0
- package/dist/types/src/internal/object/common.d.ts.map +1 -0
- package/dist/types/src/internal/object/create-object.d.ts +39 -0
- package/dist/types/src/internal/object/create-object.d.ts.map +1 -0
- package/dist/types/src/internal/object/create-object.test.d.ts +2 -0
- package/dist/types/src/internal/object/create-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/deleted.d.ts +6 -0
- package/dist/types/src/internal/object/deleted.d.ts.map +1 -0
- package/dist/types/src/internal/object/ids.d.ts +6 -0
- package/dist/types/src/internal/object/ids.d.ts.map +1 -0
- package/dist/types/src/internal/object/index.d.ts +11 -0
- package/dist/types/src/internal/object/index.d.ts.map +1 -0
- package/dist/types/src/internal/object/inspect.d.ts +2 -0
- package/dist/types/src/internal/object/inspect.d.ts.map +1 -0
- package/dist/types/src/internal/object/json-serializer.d.ts +37 -0
- package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/object/json-serializer.test.d.ts +2 -0
- package/dist/types/src/internal/object/json-serializer.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/schema-validator.d.ts +2 -0
- package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/object/schema-validator.test.d.ts +2 -0
- package/dist/types/src/internal/object/schema-validator.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/set-value.d.ts +7 -0
- package/dist/types/src/internal/object/set-value.d.ts.map +1 -0
- package/dist/types/src/internal/object/set-value.test.d.ts +2 -0
- package/dist/types/src/internal/object/set-value.test.d.ts.map +1 -0
- package/dist/types/src/internal/object/snapshot.d.ts +6 -0
- package/dist/types/src/internal/object/snapshot.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-object.d.ts +25 -0
- package/dist/types/src/internal/object/typed-object.d.ts.map +1 -0
- package/dist/types/src/internal/object/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/object/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/change-context.d.ts +55 -0
- package/dist/types/src/internal/proxy/change-context.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/change.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/change.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/define-hidden-property.d.ts +5 -0
- package/dist/types/src/internal/proxy/define-hidden-property.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/errors.d.ts +19 -0
- package/dist/types/src/internal/proxy/errors.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/event-batch.d.ts +10 -0
- package/dist/types/src/internal/proxy/event-batch.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/handler.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/index.d.ts +14 -0
- package/dist/types/src/internal/proxy/index.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/json-serializer.d.ts +6 -0
- package/dist/types/src/internal/proxy/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/make-object.d.ts +14 -0
- package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/ownership.d.ts +57 -0
- package/dist/types/src/internal/proxy/ownership.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/proxy-types.d.ts +18 -0
- package/dist/types/src/internal/proxy/proxy-types.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/proxy-utils.d.ts +47 -0
- package/dist/types/src/internal/proxy/proxy-utils.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/reactive-array.d.ts +8 -0
- package/dist/types/src/internal/proxy/reactive-array.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/reactive.d.ts +39 -0
- package/dist/types/src/internal/proxy/reactive.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/schema-validator.d.ts +15 -0
- package/dist/types/src/internal/proxy/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/schema.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/symbols.d.ts +3 -0
- package/dist/types/src/internal/proxy/symbols.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts +47 -0
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/typed-object.test.d.ts +2 -0
- package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/ref/index.d.ts +3 -0
- package/dist/types/src/internal/ref/index.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref-array.d.ts +21 -0
- package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref.d.ts +217 -0
- package/dist/types/src/internal/ref/ref.d.ts.map +1 -0
- package/dist/types/src/internal/ref/ref.test.d.ts +2 -0
- package/dist/types/src/internal/ref/ref.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/compose.d.ts +6 -0
- package/dist/types/src/internal/schema/compose.d.ts.map +1 -0
- package/dist/types/src/internal/schema/compose.test.d.ts +2 -0
- package/dist/types/src/internal/schema/compose.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts +180 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -0
- package/dist/types/src/internal/schema/index.d.ts +4 -0
- package/dist/types/src/internal/schema/index.d.ts.map +1 -0
- package/dist/types/src/internal/schema/manipulation.d.ts +10 -0
- package/dist/types/src/internal/schema/manipulation.d.ts.map +1 -0
- package/dist/types/src/internal/schema/persistent-schema.d.ts +20 -0
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -0
- package/dist/types/src/internal/types/base.d.ts +26 -0
- package/dist/types/src/internal/types/base.d.ts.map +1 -0
- package/dist/types/src/internal/types/entity.d.ts +37 -0
- package/dist/types/src/internal/types/entity.d.ts.map +1 -0
- package/dist/types/src/internal/types/index.d.ts +6 -0
- package/dist/types/src/internal/types/index.d.ts.map +1 -0
- package/dist/types/src/internal/types/meta.d.ts +32 -0
- package/dist/types/src/internal/types/meta.d.ts.map +1 -0
- package/dist/types/src/internal/types/typename.d.ts +13 -0
- package/dist/types/src/internal/types/typename.d.ts.map +1 -0
- package/dist/types/src/internal/types/version.d.ts +15 -0
- package/dist/types/src/internal/types/version.d.ts.map +1 -0
- package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +3 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +18 -0
- package/dist/types/src/testing/test-data.d.ts.map +1 -0
- package/dist/types/src/testing/test-schema.d.ts +303 -0
- package/dist/types/src/testing/test-schema.d.ts.map +1 -0
- package/dist/types/src/testing/util.d.ts +21 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +166 -33
- package/src/Annotation.ts +18 -0
- package/src/Database.ts +336 -0
- package/src/Entity.test.ts +22 -0
- package/src/Entity.ts +217 -0
- package/src/Err.ts +18 -0
- package/src/Filter.ts +376 -0
- package/src/Format.ts +9 -0
- package/src/Hypergraph.ts +74 -0
- package/src/JsonSchema.ts +16 -0
- package/src/Key.ts +3 -0
- package/src/Obj.test.ts +386 -0
- package/src/Obj.ts +509 -85
- package/src/Order.ts +44 -0
- package/src/Query.test.ts +465 -0
- package/src/Query.ts +296 -0
- package/src/QueryResult.ts +106 -0
- package/src/Ref.ts +25 -9
- package/src/Relation.test.ts +82 -0
- package/src/Relation.ts +414 -51
- package/src/SchemaRegistry.ts +105 -0
- package/src/Tag.ts +40 -0
- package/src/Type.test.ts +52 -0
- package/src/Type.ts +360 -112
- package/src/index.ts +17 -4
- package/src/internal/README.md +102 -0
- package/src/internal/annotations/annotations.test.ts +96 -0
- package/src/internal/annotations/annotations.ts +460 -0
- package/src/internal/annotations/index.ts +6 -0
- package/src/internal/annotations/util.ts +72 -0
- package/src/internal/api/annotations.ts +60 -0
- package/src/internal/api/entity.ts +29 -0
- package/src/internal/api/index.ts +19 -0
- package/src/internal/api/meta.ts +88 -0
- package/src/internal/api/sorting.ts +53 -0
- package/src/internal/api/version.ts +96 -0
- package/src/internal/entities/entity.ts +126 -0
- package/src/internal/entities/index.ts +9 -0
- package/src/internal/entities/model.ts +134 -0
- package/src/internal/entities/object.ts +60 -0
- package/src/internal/entities/relation.ts +173 -0
- package/src/internal/entities/util.ts +33 -0
- package/src/internal/formats/date.test.ts +56 -0
- package/src/internal/formats/date.ts +217 -0
- package/src/internal/formats/format.test.ts +77 -0
- package/src/internal/formats/format.ts +54 -0
- package/src/internal/formats/index.ts +12 -0
- package/src/internal/formats/number.ts +89 -0
- package/src/internal/formats/object.ts +80 -0
- package/src/internal/formats/select.ts +18 -0
- package/src/internal/formats/string.ts +81 -0
- package/src/internal/formats/types.ts +186 -0
- package/src/internal/index.ts +39 -0
- package/src/internal/json-schema/annotations.ts +50 -0
- package/src/internal/json-schema/effect-schema.test.ts +143 -0
- package/src/internal/json-schema/index.ts +8 -0
- package/src/internal/json-schema/json-schema-normalize.ts +109 -0
- package/src/internal/json-schema/json-schema-type.ts +404 -0
- package/src/internal/json-schema/json-schema.test.ts +861 -0
- package/src/internal/json-schema/json-schema.ts +528 -0
- package/src/internal/object/clone.ts +48 -0
- package/src/internal/object/common.ts +75 -0
- package/src/internal/object/create-object.test.ts +116 -0
- package/src/internal/object/create-object.ts +95 -0
- package/src/internal/object/deleted.ts +19 -0
- package/src/internal/object/ids.ts +12 -0
- package/src/internal/object/index.ts +14 -0
- package/src/internal/object/inspect.ts +46 -0
- package/src/internal/object/json-serializer.test.ts +97 -0
- package/src/internal/object/json-serializer.ts +188 -0
- package/src/internal/object/schema-validator.test.ts +186 -0
- package/src/internal/object/schema-validator.ts +6 -0
- package/src/internal/object/set-value.test.ts +281 -0
- package/src/internal/object/set-value.ts +165 -0
- package/src/internal/object/snapshot.ts +70 -0
- package/src/internal/object/typed-object.test.ts +34 -0
- package/src/internal/object/typed-object.ts +30 -0
- package/src/internal/proxy/change-context.ts +138 -0
- package/src/internal/proxy/change.test.ts +519 -0
- package/src/internal/proxy/define-hidden-property.ts +14 -0
- package/src/internal/proxy/errors.ts +42 -0
- package/src/internal/proxy/event-batch.ts +44 -0
- package/src/internal/proxy/handler.test.ts +123 -0
- package/src/internal/proxy/index.ts +17 -0
- package/src/internal/proxy/json-serializer.ts +87 -0
- package/src/internal/proxy/make-object.ts +96 -0
- package/src/internal/proxy/ownership.ts +253 -0
- package/src/internal/proxy/proxy-types.ts +23 -0
- package/src/internal/proxy/proxy-utils.ts +150 -0
- package/src/internal/proxy/reactive-array.ts +71 -0
- package/src/internal/proxy/reactive.ts +69 -0
- package/src/internal/proxy/schema-validator.ts +244 -0
- package/src/internal/proxy/schema.test.ts +145 -0
- package/src/internal/proxy/symbols.ts +7 -0
- package/src/internal/proxy/typed-handler.test.ts +318 -0
- package/src/internal/proxy/typed-handler.ts +442 -0
- package/src/internal/proxy/typed-object.test.ts +116 -0
- package/src/internal/ref/index.ts +6 -0
- package/src/internal/ref/ref-array.ts +39 -0
- package/src/internal/ref/ref.test.ts +101 -0
- package/src/internal/ref/ref.ts +548 -0
- package/src/internal/schema/compose.test.ts +42 -0
- package/src/internal/schema/compose.ts +36 -0
- package/src/internal/schema/echo-schema.ts +423 -0
- package/src/internal/schema/index.ts +7 -0
- package/src/internal/schema/manipulation.ts +92 -0
- package/src/internal/schema/persistent-schema.ts +27 -0
- package/src/internal/types/base.ts +43 -0
- package/src/internal/types/entity.ts +54 -0
- package/src/internal/types/index.ts +9 -0
- package/src/internal/types/meta.ts +66 -0
- package/src/internal/types/typename.ts +45 -0
- package/src/internal/types/version.ts +20 -0
- package/src/testing/api.test.ts +126 -0
- package/src/testing/index.ts +3 -1
- package/src/testing/test-data.ts +130 -0
- package/src/testing/test-schema.ts +238 -0
- package/src/testing/util.ts +85 -0
- package/dist/lib/browser/chunk-SVSJEELN.mjs +0 -619
- package/dist/lib/browser/chunk-SVSJEELN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-53HXWYR6.mjs +0 -619
- package/dist/lib/node-esm/chunk-53HXWYR6.mjs.map +0 -7
- package/dist/types/src/experimental/database.d.ts +0 -8
- package/dist/types/src/experimental/database.d.ts.map +0 -1
- package/dist/types/src/experimental/index.d.ts +0 -1
- package/dist/types/src/experimental/index.d.ts.map +0 -1
- package/dist/types/src/experimental/queue.d.ts +0 -8
- package/dist/types/src/experimental/queue.d.ts.map +0 -1
- package/dist/types/src/experimental/space.d.ts +0 -8
- package/dist/types/src/experimental/space.d.ts.map +0 -1
- package/dist/types/src/query/dsl.d.ts +0 -218
- package/dist/types/src/query/dsl.d.ts.map +0 -1
- package/dist/types/src/query/dsl.test.d.ts +0 -2
- package/dist/types/src/query/dsl.test.d.ts.map +0 -1
- package/dist/types/src/query/index.d.ts +0 -2
- package/dist/types/src/query/index.d.ts.map +0 -1
- package/dist/types/src/testing/types.d.ts +0 -113
- package/dist/types/src/testing/types.d.ts.map +0 -1
- package/src/experimental/database.ts +0 -11
- package/src/experimental/index.ts +0 -7
- package/src/experimental/queue.ts +0 -11
- package/src/experimental/space.ts +0 -11
- package/src/query/dsl.test.ts +0 -323
- package/src/query/dsl.ts +0 -646
- package/src/query/index.ts +0 -5
- package/src/test/api.test.ts +0 -173
- package/src/testing/types.ts +0 -91
- /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { getDeep } from '@dxos/util';
|
|
9
|
+
|
|
10
|
+
import { SchemaValidator } from './schema-validator';
|
|
11
|
+
|
|
12
|
+
describe('schema-validator', () => {
|
|
13
|
+
describe('validateSchema', () => {
|
|
14
|
+
test('throws on ambiguous discriminated type union', () => {
|
|
15
|
+
const TestSchema = Schema.Struct({
|
|
16
|
+
union: Schema.Union(Schema.Struct({ a: Schema.Number }), Schema.Struct({ b: Schema.String })),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(() => SchemaValidator.validateSchema(TestSchema)).to.throw();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('hasPropertyAnnotation', () => {
|
|
24
|
+
test('has annotation', () => {
|
|
25
|
+
const annotationId = Symbol('foo');
|
|
26
|
+
const annotationValue = 'bar';
|
|
27
|
+
const TestSchema: Schema.Schema.AnyNoContext = Schema.Struct({
|
|
28
|
+
name: Schema.String.annotations({ [annotationId]: annotationValue }),
|
|
29
|
+
parent: Schema.optional(Schema.suspend(() => TestSchema.annotations({ [annotationId]: annotationValue }))),
|
|
30
|
+
friends: Schema.suspend(() =>
|
|
31
|
+
Schema.mutable(Schema.Array(TestSchema.annotations({ [annotationId]: annotationValue }))),
|
|
32
|
+
),
|
|
33
|
+
});
|
|
34
|
+
expect(SchemaValidator.hasTypeAnnotation(TestSchema, 'name', annotationId)).to.be.true;
|
|
35
|
+
expect(SchemaValidator.hasTypeAnnotation(TestSchema, 'parent', annotationId)).to.be.true;
|
|
36
|
+
expect(SchemaValidator.hasTypeAnnotation(TestSchema, 'friends', annotationId)).to.be.true;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('no annotation', () => {
|
|
40
|
+
const annotationId = Symbol('foo');
|
|
41
|
+
const Person: Schema.Schema.AnyNoContext = Schema.Struct({
|
|
42
|
+
name: Schema.String,
|
|
43
|
+
parent: Schema.optional(Schema.suspend(() => Person)),
|
|
44
|
+
friends: Schema.suspend(() => Schema.mutable(Schema.Array(Person))),
|
|
45
|
+
});
|
|
46
|
+
expect(SchemaValidator.hasTypeAnnotation(Person, 'name', annotationId)).to.be.false;
|
|
47
|
+
expect(SchemaValidator.hasTypeAnnotation(Person, 'parent', annotationId)).to.be.false;
|
|
48
|
+
expect(SchemaValidator.hasTypeAnnotation(Person, 'friends', annotationId)).to.be.false;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('getPropertySchema', () => {
|
|
53
|
+
const validateValueToAssign = (args: {
|
|
54
|
+
schema: Schema.Schema.AnyNoContext;
|
|
55
|
+
target: any;
|
|
56
|
+
path: string[];
|
|
57
|
+
valueToAssign: any;
|
|
58
|
+
expectToThrow?: boolean;
|
|
59
|
+
}) => {
|
|
60
|
+
const expectation = expect(() => {
|
|
61
|
+
const nestedSchema = SchemaValidator.getPropertySchema(args.schema, args.path, (path) => {
|
|
62
|
+
return getDeep(args.target, path);
|
|
63
|
+
});
|
|
64
|
+
Schema.validateSync(nestedSchema)(args.valueToAssign);
|
|
65
|
+
});
|
|
66
|
+
if (args.expectToThrow) {
|
|
67
|
+
expectation.to.throw();
|
|
68
|
+
} else {
|
|
69
|
+
expectation.not.to.throw();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
test('basic', () => {
|
|
74
|
+
for (const value of [42, '42']) {
|
|
75
|
+
validateValueToAssign({
|
|
76
|
+
schema: Schema.Struct({ object: Schema.Struct({ field: Schema.Number }) }),
|
|
77
|
+
target: {},
|
|
78
|
+
path: ['object', 'field'],
|
|
79
|
+
valueToAssign: value,
|
|
80
|
+
expectToThrow: typeof value !== 'number',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('preserves annotations', () => {
|
|
86
|
+
const annotationId = Symbol('foo');
|
|
87
|
+
const annotationValue = 'bar';
|
|
88
|
+
const Person: Schema.Schema.AnyNoContext = Schema.Struct({
|
|
89
|
+
parent: Schema.optional(Schema.suspend(() => Person.annotations({ [annotationId]: annotationValue }))),
|
|
90
|
+
friends: Schema.suspend(() =>
|
|
91
|
+
Schema.mutable(Schema.Array(Person.annotations({ [annotationId]: annotationValue }))),
|
|
92
|
+
),
|
|
93
|
+
});
|
|
94
|
+
expect(SchemaValidator.getPropertySchema(Person, ['parent']).ast.annotations[annotationId]).to.eq(
|
|
95
|
+
annotationValue,
|
|
96
|
+
);
|
|
97
|
+
expect(SchemaValidator.getPropertySchema(Person, ['friends', '0']).ast.annotations[annotationId]).to.eq(
|
|
98
|
+
annotationValue,
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('discriminated union', () => {
|
|
103
|
+
const square = Schema.Struct({ type: Schema.Literal('square'), side: Schema.Number });
|
|
104
|
+
const circle = Schema.Struct({ type: Schema.Literal('circle'), radius: Schema.Number });
|
|
105
|
+
const shape = Schema.Union(square, circle);
|
|
106
|
+
validateValueToAssign({
|
|
107
|
+
schema: shape,
|
|
108
|
+
target: { type: 'square' },
|
|
109
|
+
path: ['side'],
|
|
110
|
+
valueToAssign: 1,
|
|
111
|
+
});
|
|
112
|
+
validateValueToAssign({
|
|
113
|
+
schema: shape,
|
|
114
|
+
target: { type: 'circle' },
|
|
115
|
+
path: ['side'],
|
|
116
|
+
valueToAssign: 1,
|
|
117
|
+
expectToThrow: true,
|
|
118
|
+
});
|
|
119
|
+
validateValueToAssign({
|
|
120
|
+
schema: shape,
|
|
121
|
+
target: { type: 'square' },
|
|
122
|
+
path: ['radius'],
|
|
123
|
+
valueToAssign: 1,
|
|
124
|
+
expectToThrow: true,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('any', () => {
|
|
129
|
+
validateValueToAssign({
|
|
130
|
+
schema: Schema.Any,
|
|
131
|
+
target: { field: { nested: { value: Schema.Number } } },
|
|
132
|
+
path: ['field', 'nested'],
|
|
133
|
+
valueToAssign: { any: 'value' },
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
test('index signatures', () => {
|
|
137
|
+
for (const value of [42, '42']) {
|
|
138
|
+
validateValueToAssign({
|
|
139
|
+
schema: Schema.Struct({ field: Schema.String }, { key: Schema.String, value: Schema.Number }),
|
|
140
|
+
target: {},
|
|
141
|
+
path: ['unknownField'],
|
|
142
|
+
valueToAssign: value,
|
|
143
|
+
expectToThrow: typeof value !== 'number',
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('index signature from optional record', () => {
|
|
149
|
+
for (const value of [42, '42']) {
|
|
150
|
+
validateValueToAssign({
|
|
151
|
+
schema: Schema.Struct({
|
|
152
|
+
field: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Number })),
|
|
153
|
+
}),
|
|
154
|
+
target: {},
|
|
155
|
+
path: ['field', 'unknownField'],
|
|
156
|
+
valueToAssign: value,
|
|
157
|
+
expectToThrow: typeof value !== 'number',
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('suspend', () => {
|
|
163
|
+
const schemaWithSuspend = Schema.Struct({
|
|
164
|
+
array: Schema.optional(Schema.suspend(() => Schema.Array(Schema.Union(Schema.Null, Schema.Number)))),
|
|
165
|
+
object: Schema.optional(
|
|
166
|
+
Schema.suspend(() => Schema.Union(Schema.Null, Schema.Struct({ field: Schema.Number }))),
|
|
167
|
+
),
|
|
168
|
+
});
|
|
169
|
+
const target: any = { array: [1, 2, null], object: { field: 3 } };
|
|
170
|
+
for (const value of [42, '42']) {
|
|
171
|
+
for (const path of [
|
|
172
|
+
['array', '0'],
|
|
173
|
+
['object', 'field'],
|
|
174
|
+
]) {
|
|
175
|
+
validateValueToAssign({
|
|
176
|
+
schema: schemaWithSuspend,
|
|
177
|
+
target,
|
|
178
|
+
path,
|
|
179
|
+
valueToAssign: value,
|
|
180
|
+
expectToThrow: typeof value !== 'number',
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 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 { TestSchema } from '../../testing';
|
|
10
|
+
import * as Type from '../../Type';
|
|
11
|
+
|
|
12
|
+
describe('Obj.setValue', () => {
|
|
13
|
+
test('sets simple nested object property', ({ expect }) => {
|
|
14
|
+
const person = Obj.make(TestSchema.Person, {
|
|
15
|
+
name: 'John',
|
|
16
|
+
username: 'john',
|
|
17
|
+
email: 'john@example.com',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
Obj.change(person, (p) => Obj.setValue(p, ['address', 'city'], 'NYC'));
|
|
21
|
+
|
|
22
|
+
expect(person.address).toBeDefined();
|
|
23
|
+
expect(person.address?.city).toBe('NYC');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('sets array element by initializing array', ({ expect }) => {
|
|
27
|
+
const person = Obj.make(TestSchema.Person, {
|
|
28
|
+
name: 'John',
|
|
29
|
+
username: 'john',
|
|
30
|
+
email: 'john@example.com',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
Obj.change(person, (p) => Obj.setValue(p, ['fields', 0, 'label'], 'Phone'));
|
|
34
|
+
|
|
35
|
+
expect(Array.isArray(person.fields)).toBe(true);
|
|
36
|
+
expect(person.fields?.[0].label).toBe('Phone');
|
|
37
|
+
// The 'value' field is required, so it should be initialized with default.
|
|
38
|
+
expect(person.fields?.[0].value).toBe('');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('sets deeply nested array in object', ({ expect }) => {
|
|
42
|
+
const person = Obj.make(TestSchema.Person, {
|
|
43
|
+
name: 'John',
|
|
44
|
+
username: 'john',
|
|
45
|
+
email: 'john@example.com',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
Obj.change(person, (p) => Obj.setValue(p, ['address', 'coordinates', 'lat'], 40.7128));
|
|
49
|
+
|
|
50
|
+
expect(person.address).toBeDefined();
|
|
51
|
+
expect(person.address?.coordinates).toBeDefined();
|
|
52
|
+
expect(person.address?.coordinates?.lat).toBe(40.7128);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('sets multiple nested array elements', ({ expect }) => {
|
|
56
|
+
const Item = Schema.Struct({
|
|
57
|
+
value: Schema.optional(Schema.Number),
|
|
58
|
+
}).pipe(Schema.mutable);
|
|
59
|
+
|
|
60
|
+
const Container = Schema.Struct({
|
|
61
|
+
name: Schema.String,
|
|
62
|
+
items: Schema.optional(Schema.mutable(Schema.Array(Item))),
|
|
63
|
+
}).pipe(
|
|
64
|
+
Type.object({
|
|
65
|
+
typename: 'test.com/Container',
|
|
66
|
+
version: '0.1.0',
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const container = Obj.make(Container, { name: 'box' });
|
|
71
|
+
|
|
72
|
+
Obj.change(container, (c) => {
|
|
73
|
+
Obj.setValue(c, ['items', 0, 'value'], 10);
|
|
74
|
+
Obj.setValue(c, ['items', 1, 'value'], 20);
|
|
75
|
+
Obj.setValue(c, ['items', 2, 'value'], 30);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(container.items).toHaveLength(3);
|
|
79
|
+
expect(container.items?.[0].value).toBe(10);
|
|
80
|
+
expect(container.items?.[1].value).toBe(20);
|
|
81
|
+
expect(container.items?.[2].value).toBe(30);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('handles optional fields', ({ expect }) => {
|
|
85
|
+
const person = Obj.make(TestSchema.Person, {
|
|
86
|
+
name: 'John',
|
|
87
|
+
username: 'john',
|
|
88
|
+
email: 'john@example.com',
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
Obj.change(person, (p) => Obj.setValue(p, ['age'], 25));
|
|
92
|
+
|
|
93
|
+
expect(person.age).toBe(25);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('handles nested optional objects', ({ expect }) => {
|
|
97
|
+
const person = Obj.make(TestSchema.Person, {
|
|
98
|
+
name: 'John',
|
|
99
|
+
username: 'john',
|
|
100
|
+
email: 'john@example.com',
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
Obj.change(person, (p) => Obj.setValue(p, ['address', 'city'], 'NYC'));
|
|
104
|
+
|
|
105
|
+
expect(person.address).toBeDefined();
|
|
106
|
+
expect(person.address?.city).toBe('NYC');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('returns the set value', ({ expect }) => {
|
|
110
|
+
const person = Obj.make(TestSchema.Person, {
|
|
111
|
+
name: 'John',
|
|
112
|
+
username: 'john',
|
|
113
|
+
email: 'john@example.com',
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
let result: any;
|
|
117
|
+
Obj.change(person, (p) => {
|
|
118
|
+
result = Obj.setValue(p, ['age'], 30);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
expect(result).toBe(30);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('overwrites existing values', ({ expect }) => {
|
|
125
|
+
const person = Obj.make(TestSchema.Person, {
|
|
126
|
+
name: 'John',
|
|
127
|
+
username: 'john',
|
|
128
|
+
email: 'john@example.com',
|
|
129
|
+
age: 25,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
Obj.change(person, (p) => Obj.setValue(p, ['age'], 30));
|
|
133
|
+
|
|
134
|
+
expect(person.age).toBe(30);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('sets nested value in existing object', ({ expect }) => {
|
|
138
|
+
const person = Obj.make(TestSchema.Person, {
|
|
139
|
+
name: 'John',
|
|
140
|
+
username: 'john',
|
|
141
|
+
email: 'john@example.com',
|
|
142
|
+
address: { city: 'Boston', state: 'MA', coordinates: {} },
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
Obj.change(person, (p) => Obj.setValue(p, ['address', 'city'], 'NYC'));
|
|
146
|
+
|
|
147
|
+
expect(person.address?.city).toBe('NYC');
|
|
148
|
+
expect(person.address?.state).toBe('MA');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('handles two-dimensional arrays', ({ expect }) => {
|
|
152
|
+
const Matrix = Schema.Struct({
|
|
153
|
+
values: Schema.optional(Schema.mutable(Schema.Array(Schema.mutable(Schema.Array(Schema.Number))))),
|
|
154
|
+
}).pipe(
|
|
155
|
+
Type.object({
|
|
156
|
+
typename: 'test.com/Matrix',
|
|
157
|
+
version: '0.1.0',
|
|
158
|
+
}),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const matrix = Obj.make(Matrix, {});
|
|
162
|
+
|
|
163
|
+
Obj.change(matrix, (m) => {
|
|
164
|
+
Obj.setValue(m, ['values', 0, 0], 1);
|
|
165
|
+
Obj.setValue(m, ['values', 0, 1], 2);
|
|
166
|
+
Obj.setValue(m, ['values', 1, 0], 3);
|
|
167
|
+
Obj.setValue(m, ['values', 1, 1], 4);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(matrix.values?.[0][0]).toBe(1);
|
|
171
|
+
expect(matrix.values?.[0][1]).toBe(2);
|
|
172
|
+
expect(matrix.values?.[1][0]).toBe(3);
|
|
173
|
+
expect(matrix.values?.[1][1]).toBe(4);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('throws error for empty path', ({ expect }) => {
|
|
177
|
+
const person = Obj.make(TestSchema.Person, {
|
|
178
|
+
name: 'John',
|
|
179
|
+
username: 'john',
|
|
180
|
+
email: 'john@example.com',
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
Obj.change(person, (p) => {
|
|
184
|
+
expect(() => Obj.setValue(p, [], 'value')).toThrow('Path must not be empty');
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('sets value with single-element path', ({ expect }) => {
|
|
189
|
+
const person = Obj.make(TestSchema.Person, {
|
|
190
|
+
name: 'John',
|
|
191
|
+
username: 'john',
|
|
192
|
+
email: 'john@example.com',
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
Obj.change(person, (p) => Obj.setValue(p, ['age'], 30));
|
|
196
|
+
|
|
197
|
+
expect(person.age).toBe(30);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('handles numeric keys as strings', ({ expect }) => {
|
|
201
|
+
const Item = Schema.Struct({
|
|
202
|
+
value: Schema.optional(Schema.Number),
|
|
203
|
+
}).pipe(Schema.mutable);
|
|
204
|
+
|
|
205
|
+
const Container = Schema.Struct({
|
|
206
|
+
name: Schema.String,
|
|
207
|
+
items: Schema.optional(Schema.mutable(Schema.Array(Item))),
|
|
208
|
+
}).pipe(
|
|
209
|
+
Type.object({
|
|
210
|
+
typename: 'test.com/Container',
|
|
211
|
+
version: '0.1.0',
|
|
212
|
+
}),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const container = Obj.make(Container, { name: 'box' });
|
|
216
|
+
|
|
217
|
+
// Using string '0' for array index.
|
|
218
|
+
Obj.change(container, (c) => Obj.setValue(c, ['items', '0', 'value'], 42));
|
|
219
|
+
|
|
220
|
+
expect(container.items?.[0].value).toBe(42);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('handles array with object with required field', ({ expect }) => {
|
|
224
|
+
// This test demonstrates the problematic scenario:
|
|
225
|
+
// An array containing objects that have required fields.
|
|
226
|
+
const Task = Schema.Struct({
|
|
227
|
+
id: Schema.String, // Required field.
|
|
228
|
+
title: Schema.optional(Schema.String),
|
|
229
|
+
completed: Schema.optional(Schema.Boolean),
|
|
230
|
+
}).pipe(Schema.mutable);
|
|
231
|
+
|
|
232
|
+
const TodoList = Schema.Struct({
|
|
233
|
+
name: Schema.String,
|
|
234
|
+
tasks: Schema.optional(Schema.mutable(Schema.Array(Task))),
|
|
235
|
+
}).pipe(
|
|
236
|
+
Type.object({
|
|
237
|
+
typename: 'test.com/TodoList',
|
|
238
|
+
version: '0.1.0',
|
|
239
|
+
}),
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const todoList = Obj.make(TodoList, { name: 'My Tasks' });
|
|
243
|
+
|
|
244
|
+
// This should work: setting a nested property on an array element.
|
|
245
|
+
// The required 'id' field should be initialized with a default value.
|
|
246
|
+
Obj.change(todoList, (t) => Obj.setValue(t, ['tasks', 0, 'title'], 'Buy groceries'));
|
|
247
|
+
|
|
248
|
+
expect(todoList.tasks?.[0].id).toBe(''); // Default value for required String
|
|
249
|
+
expect(todoList.tasks?.[0].title).toBe('Buy groceries');
|
|
250
|
+
expect(todoList.tasks?.[0].completed).toBeUndefined(); // Optional field not set
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test('initializes multiple required primitive fields with defaults', ({ expect }) => {
|
|
254
|
+
const Item = Schema.Struct({
|
|
255
|
+
id: Schema.String, // Required - should default to ""
|
|
256
|
+
count: Schema.Number, // Required - should default to 0
|
|
257
|
+
active: Schema.Boolean, // Required - should default to false
|
|
258
|
+
label: Schema.optional(Schema.String), // Optional - should not be initialized
|
|
259
|
+
}).pipe(Schema.mutable);
|
|
260
|
+
|
|
261
|
+
const Container = Schema.Struct({
|
|
262
|
+
name: Schema.String,
|
|
263
|
+
items: Schema.optional(Schema.mutable(Schema.Array(Item))),
|
|
264
|
+
}).pipe(
|
|
265
|
+
Type.object({
|
|
266
|
+
typename: 'test.com/Container',
|
|
267
|
+
version: '0.1.0',
|
|
268
|
+
}),
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
const container = Obj.make(Container, { name: 'box' });
|
|
272
|
+
|
|
273
|
+
Obj.change(container, (c) => Obj.setValue(c, ['items', 0, 'label'], 'First Item'));
|
|
274
|
+
|
|
275
|
+
// All required primitive fields should have default values.
|
|
276
|
+
expect(container.items?.[0].id).toBe('');
|
|
277
|
+
expect(container.items?.[0].count).toBe(0);
|
|
278
|
+
expect(container.items?.[0].active).toBe(false);
|
|
279
|
+
expect(container.items?.[0].label).toBe('First Item');
|
|
280
|
+
});
|
|
281
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Match from 'effect/Match';
|
|
6
|
+
import * as Option from 'effect/Option';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
type SchemaProperty,
|
|
11
|
+
getArrayElementType,
|
|
12
|
+
getBaseType,
|
|
13
|
+
getProperties,
|
|
14
|
+
isArrayType,
|
|
15
|
+
isNestedType,
|
|
16
|
+
} from '@dxos/effect';
|
|
17
|
+
import { invariant } from '@dxos/invariant';
|
|
18
|
+
|
|
19
|
+
import { type Mutable } from '../proxy';
|
|
20
|
+
import { getSchema } from '../types';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Set a deeply nested property on an object.
|
|
24
|
+
* Must be called within an Obj.change or Relation.change callback.
|
|
25
|
+
*/
|
|
26
|
+
export const setValue = (obj: Mutable<any>, path: readonly (string | number)[], value: any): void => {
|
|
27
|
+
invariant(path.length > 0, 'Path must not be empty');
|
|
28
|
+
|
|
29
|
+
const schema = getSchema(obj);
|
|
30
|
+
invariant(schema != null, 'Object must have a schema');
|
|
31
|
+
|
|
32
|
+
let parent = obj;
|
|
33
|
+
let currentAST: SchemaAST.AST | undefined = schema.ast;
|
|
34
|
+
|
|
35
|
+
// Navigate to the parent of the target property.
|
|
36
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
37
|
+
const part = path[i];
|
|
38
|
+
const key = typeof part === 'number' ? part : String(part);
|
|
39
|
+
if (parent[key] === undefined) {
|
|
40
|
+
const propertyAST = getPropertyAST(currentAST, String(part));
|
|
41
|
+
const shouldBeArray = propertyAST ? isArrayType(propertyAST) : false;
|
|
42
|
+
|
|
43
|
+
if (shouldBeArray) {
|
|
44
|
+
// Create array.
|
|
45
|
+
parent[key] = [];
|
|
46
|
+
} else {
|
|
47
|
+
// TODO(wittjosiah): Is there a better way to handle this than creating an object with defaults?
|
|
48
|
+
// Perhaps properties on objects should be optional by default?
|
|
49
|
+
// Create object with defaults for required fields.
|
|
50
|
+
const objWithDefaults = createObjectWithDefaults(propertyAST);
|
|
51
|
+
parent[key] = objWithDefaults;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
parent = parent[key];
|
|
56
|
+
currentAST = getPropertyAST(currentAST, String(part));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const finalKey = path[path.length - 1];
|
|
60
|
+
parent[finalKey] = value;
|
|
61
|
+
|
|
62
|
+
return value;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Helper to get the AST of a nested property.
|
|
67
|
+
* @param ast - Current schema AST.
|
|
68
|
+
* @param propertyName - Name of the property to get.
|
|
69
|
+
* @returns The AST of the nested property, or undefined if not found.
|
|
70
|
+
*/
|
|
71
|
+
const getPropertyAST = (ast: SchemaAST.AST | undefined, propertyName: string): SchemaAST.AST | undefined => {
|
|
72
|
+
if (!ast) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (isNestedType(ast)) {
|
|
77
|
+
const properties = getProperties(ast);
|
|
78
|
+
const property = properties.find((p) => p.name.toString() === propertyName);
|
|
79
|
+
if (property) {
|
|
80
|
+
return getBaseType(property).type;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (isArrayType(ast)) {
|
|
85
|
+
const elementType = getArrayElementType(ast);
|
|
86
|
+
return elementType;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return undefined;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get all required properties from a schema AST.
|
|
94
|
+
* A property is required if it's not optional.
|
|
95
|
+
*
|
|
96
|
+
* @param ast - Schema AST to inspect.
|
|
97
|
+
* @returns Array of required properties with their types.
|
|
98
|
+
*/
|
|
99
|
+
const getRequiredProperties = (ast: SchemaAST.AST | undefined): SchemaProperty[] => {
|
|
100
|
+
if (!ast) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Only objects/structs have properties with optional/required distinction.
|
|
105
|
+
if (!isNestedType(ast)) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const properties = getProperties(ast);
|
|
110
|
+
|
|
111
|
+
// Filter to only required properties (where isOptional === false).
|
|
112
|
+
return properties.filter((p) => !p.isOptional);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Get the default value for a primitive type.
|
|
117
|
+
* Returns undefined for non-primitive or unsupported types.
|
|
118
|
+
*
|
|
119
|
+
* @param ast - Type AST.
|
|
120
|
+
* @returns Default value for the type, or undefined.
|
|
121
|
+
*/
|
|
122
|
+
const getDefaultValueForType = (ast: SchemaAST.AST | undefined): any => {
|
|
123
|
+
if (!ast) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const defaultValue = SchemaAST.getDefaultAnnotation(ast);
|
|
128
|
+
if (Option.isSome(defaultValue)) {
|
|
129
|
+
return defaultValue.value;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return Match.value(ast).pipe(
|
|
133
|
+
Match.when({ _tag: 'StringKeyword' }, () => ''),
|
|
134
|
+
Match.when({ _tag: 'NumberKeyword' }, () => 0),
|
|
135
|
+
Match.when({ _tag: 'BooleanKeyword' }, () => false),
|
|
136
|
+
Match.orElse(() => undefined),
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Create an object with default values for all required properties.
|
|
142
|
+
* Handles primitive types (String, Number, Boolean) and recursively initializes required nested objects.
|
|
143
|
+
*
|
|
144
|
+
* @param ast - Schema AST describing the object structure.
|
|
145
|
+
* @returns Object with required fields populated with defaults.
|
|
146
|
+
*/
|
|
147
|
+
const createObjectWithDefaults = (ast: SchemaAST.AST | undefined): any => {
|
|
148
|
+
if (!ast) {
|
|
149
|
+
return {};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const requiredProps = getRequiredProperties(ast);
|
|
153
|
+
const obj: any = {};
|
|
154
|
+
|
|
155
|
+
for (const prop of requiredProps) {
|
|
156
|
+
const defaultValue = getDefaultValueForType(prop.type);
|
|
157
|
+
if (defaultValue !== undefined) {
|
|
158
|
+
obj[prop.name] = defaultValue;
|
|
159
|
+
} else if (isNestedType(prop.type)) {
|
|
160
|
+
obj[prop.name] = createObjectWithDefaults(prop.type);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return obj;
|
|
165
|
+
};
|