@dxos/echo 0.8.4-main.548089c → 0.8.4-main.59c2e9b
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/Database.mjs +18 -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 +68 -18
- package/dist/lib/browser/internal/index.mjs +245 -124
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +298 -198
- 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 +68 -18
- package/dist/lib/node-esm/internal/index.mjs +245 -124
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +298 -198
- 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/{errors.d.ts → Err.d.ts} +19 -19
- 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 +300 -99
- 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 -22
- 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 +7 -7
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +225 -72
- 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 +14 -5
- 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.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/format.d.ts +4 -2
- 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 +13 -9
- package/dist/types/src/internal/formats/types.d.ts.map +1 -1
- package/dist/types/src/internal/index.d.ts +7 -10
- package/dist/types/src/internal/index.d.ts.map +1 -1
- 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.map +1 -0
- package/dist/types/src/internal/json-schema/index.d.ts +2 -0
- package/dist/types/src/internal/json-schema/index.d.ts.map +1 -1
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -1
- package/dist/types/src/internal/{json → json-schema}/json-schema.d.ts +2 -1
- 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.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.map +1 -1
- package/dist/types/src/internal/object/{create.d.ts → create-object.d.ts} +9 -10
- 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 +2 -2
- package/dist/types/src/internal/object/deleted.d.ts.map +1 -1
- package/dist/types/src/internal/object/ids.d.ts.map +1 -1
- package/dist/types/src/internal/object/index.d.ts +6 -11
- package/dist/types/src/internal/object/index.d.ts.map +1 -1
- package/dist/types/src/internal/object/json-serializer.d.ts +14 -9
- 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 +8 -14
- 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 +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/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 +15 -12
- 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 +27 -16
- package/dist/types/src/internal/ref/ref.d.ts.map +1 -1
- package/dist/types/src/internal/schema/compose.d.ts.map +1 -0
- package/dist/types/src/internal/schema/compose.test.d.ts.map +1 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts +24 -12
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -1
- package/dist/types/src/internal/schema/index.d.ts +1 -4
- package/dist/types/src/internal/schema/index.d.ts.map +1 -1
- 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 +5 -2
- package/dist/types/src/internal/types/index.d.ts.map +1 -1
- package/dist/types/src/internal/{object → types}/meta.d.ts +12 -11
- 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/{object → types}/version.d.ts +3 -2
- 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 -3
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +18 -0
- package/dist/types/src/testing/test-data.d.ts.map +1 -0
- package/dist/types/src/testing/test-schema.d.ts +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 +160 -45
- 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/{errors.ts → Err.ts} +2 -2
- 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 +447 -292
- 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 +26 -9
- package/src/Relation.test.ts +82 -0
- package/src/Relation.ts +411 -60
- package/src/SchemaRegistry.ts +105 -0
- package/src/Tag.ts +3 -2
- package/src/Type.test.ts +52 -0
- package/src/Type.ts +361 -114
- package/src/index.ts +15 -6
- package/src/internal/README.md +100 -0
- package/src/internal/{ast → annotations}/annotations.test.ts +18 -20
- 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 +1 -1
- package/src/internal/formats/date.ts +5 -5
- package/src/internal/formats/format.test.ts +5 -5
- package/src/internal/formats/format.ts +8 -6
- package/src/internal/formats/number.ts +5 -5
- package/src/internal/formats/object.ts +4 -4
- package/src/internal/formats/select.ts +5 -3
- package/src/internal/formats/string.ts +14 -9
- package/src/internal/formats/types.ts +53 -42
- package/src/internal/index.ts +30 -13
- package/src/internal/{json → json-schema}/annotations.ts +1 -1
- package/src/internal/json-schema/index.ts +2 -0
- package/src/internal/json-schema/json-schema-type.ts +5 -4
- package/src/internal/{json → json-schema}/json-schema.test.ts +67 -55
- package/src/internal/{json → json-schema}/json-schema.ts +17 -8
- package/src/internal/object/clone.ts +48 -0
- package/src/internal/object/common.ts +3 -4
- package/src/internal/object/{create.test.ts → create-object.test.ts} +30 -32
- package/src/internal/object/{create.ts → create-object.ts} +35 -36
- package/src/internal/object/deleted.ts +6 -6
- package/src/internal/object/ids.ts +1 -1
- package/src/internal/object/index.ts +6 -11
- package/src/internal/object/inspect.ts +5 -7
- package/src/internal/object/json-serializer.test.ts +35 -37
- package/src/internal/object/json-serializer.ts +65 -102
- package/src/internal/object/schema-validator.ts +2 -237
- 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 -66
- 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 +51 -91
- 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 +27 -18
- package/src/internal/proxy/symbols.ts +7 -0
- package/src/internal/proxy/typed-handler.test.ts +264 -48
- package/src/internal/proxy/typed-handler.ts +275 -61
- package/src/internal/proxy/typed-object.test.ts +42 -26
- package/src/internal/ref/ref-array.ts +4 -4
- package/src/internal/ref/ref.test.ts +8 -7
- package/src/internal/ref/ref.ts +81 -54
- package/src/internal/{projection → schema}/compose.test.ts +8 -9
- package/src/internal/{projection → schema}/compose.ts +1 -1
- package/src/internal/schema/echo-schema.ts +73 -33
- package/src/internal/schema/index.ts +1 -4
- package/src/internal/schema/manipulation.ts +1 -1
- 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 +5 -2
- package/src/internal/{object → types}/meta.ts +22 -17
- 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 -3
- 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-3FCPYTWA.mjs +0 -585
- package/dist/lib/browser/chunk-3FCPYTWA.mjs.map +0 -7
- package/dist/lib/browser/chunk-5BNXQE6S.mjs +0 -3727
- package/dist/lib/browser/chunk-5BNXQE6S.mjs.map +0 -7
- package/dist/lib/browser/chunk-U43CXUCL.mjs +0 -410
- package/dist/lib/browser/chunk-U43CXUCL.mjs.map +0 -7
- package/dist/lib/browser/query/index.mjs +0 -13
- package/dist/lib/node-esm/chunk-3FGSPSYN.mjs +0 -3727
- package/dist/lib/node-esm/chunk-3FGSPSYN.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-C7LTTWRL.mjs +0 -585
- package/dist/lib/node-esm/chunk-C7LTTWRL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OHJ5WBB6.mjs +0 -410
- package/dist/lib/node-esm/chunk-OHJ5WBB6.mjs.map +0 -7
- package/dist/lib/node-esm/query/index.mjs +0 -13
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotation-helper.d.ts +0 -8
- package/dist/types/src/internal/ast/annotation-helper.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotations.d.ts +0 -131
- package/dist/types/src/internal/ast/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/ast/annotations.test.d.ts.map +0 -1
- package/dist/types/src/internal/ast/entity-kind.d.ts +0 -10
- package/dist/types/src/internal/ast/entity-kind.d.ts.map +0 -1
- package/dist/types/src/internal/ast/index.d.ts +0 -5
- package/dist/types/src/internal/ast/index.d.ts.map +0 -1
- package/dist/types/src/internal/ast/types.d.ts +0 -6
- package/dist/types/src/internal/ast/types.d.ts.map +0 -1
- package/dist/types/src/internal/json/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/json/effect-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/json/index.d.ts +0 -2
- package/dist/types/src/internal/json/index.d.ts.map +0 -1
- package/dist/types/src/internal/json/json-schema.d.ts.map +0 -1
- package/dist/types/src/internal/json/json-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/accessors.d.ts +0 -37
- package/dist/types/src/internal/object/accessors.d.ts.map +0 -1
- package/dist/types/src/internal/object/create.d.ts.map +0 -1
- package/dist/types/src/internal/object/create.test.d.ts +0 -2
- package/dist/types/src/internal/object/create.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/entity.d.ts +0 -33
- package/dist/types/src/internal/object/entity.d.ts.map +0 -1
- package/dist/types/src/internal/object/expando.d.ts +0 -14
- package/dist/types/src/internal/object/expando.d.ts.map +0 -1
- package/dist/types/src/internal/object/meta.d.ts.map +0 -1
- package/dist/types/src/internal/object/model.d.ts +0 -117
- package/dist/types/src/internal/object/model.d.ts.map +0 -1
- package/dist/types/src/internal/object/relation.d.ts +0 -17
- package/dist/types/src/internal/object/relation.d.ts.map +0 -1
- package/dist/types/src/internal/object/typename.d.ts +0 -15
- package/dist/types/src/internal/object/typename.d.ts.map +0 -1
- package/dist/types/src/internal/object/version.d.ts.map +0 -1
- package/dist/types/src/internal/projection/compose.d.ts.map +0 -1
- package/dist/types/src/internal/projection/compose.test.d.ts.map +0 -1
- package/dist/types/src/internal/projection/index.d.ts +0 -2
- package/dist/types/src/internal/projection/index.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/reactive-object.d.ts +0 -15
- package/dist/types/src/internal/proxy/reactive-object.d.ts.map +0 -1
- package/dist/types/src/internal/query/index.d.ts +0 -2
- package/dist/types/src/internal/query/index.d.ts.map +0 -1
- package/dist/types/src/internal/query/query.d.ts +0 -17
- package/dist/types/src/internal/query/query.d.ts.map +0 -1
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts +0 -18
- package/dist/types/src/internal/schema/runtime-schema-registry.d.ts.map +0 -1
- package/dist/types/src/internal/schema/snapshot.d.ts +0 -6
- package/dist/types/src/internal/schema/snapshot.d.ts.map +0 -1
- package/dist/types/src/internal/schema/stored-schema.d.ts +0 -13
- package/dist/types/src/internal/schema/stored-schema.d.ts.map +0 -1
- package/dist/types/src/internal/testing/index.d.ts +0 -3
- package/dist/types/src/internal/testing/index.d.ts.map +0 -1
- package/dist/types/src/internal/testing/types.d.ts +0 -381
- package/dist/types/src/internal/testing/types.d.ts.map +0 -1
- package/dist/types/src/internal/testing/utils.d.ts +0 -10
- package/dist/types/src/internal/testing/utils.d.ts.map +0 -1
- package/dist/types/src/internal/types/types.d.ts +0 -79
- package/dist/types/src/internal/types/types.d.ts.map +0 -1
- package/dist/types/src/internal/types/types.test.d.ts +0 -2
- package/dist/types/src/internal/types/types.test.d.ts.map +0 -1
- package/dist/types/src/internal/types/util.d.ts +0 -5
- package/dist/types/src/internal/types/util.d.ts.map +0 -1
- package/dist/types/src/query/index.d.ts +0 -2
- package/dist/types/src/query/index.d.ts.map +0 -1
- package/dist/types/src/query/query.d.ts +0 -248
- package/dist/types/src/query/query.d.ts.map +0 -1
- package/dist/types/src/query/query.test.d.ts +0 -2
- package/dist/types/src/query/query.test.d.ts.map +0 -1
- package/dist/types/src/testing/echo-schema.d.ts +0 -7
- package/dist/types/src/testing/echo-schema.d.ts.map +0 -1
- package/dist/types/src/testing/types.d.ts +0 -228
- package/dist/types/src/testing/types.d.ts.map +0 -1
- package/src/internal/ast/annotation-helper.ts +0 -22
- package/src/internal/ast/annotations.ts +0 -226
- package/src/internal/ast/entity-kind.ts +0 -15
- package/src/internal/ast/index.ts +0 -8
- package/src/internal/ast/types.ts +0 -17
- package/src/internal/json/index.ts +0 -5
- package/src/internal/object/accessors.ts +0 -153
- package/src/internal/object/entity.ts +0 -248
- package/src/internal/object/expando.ts +0 -21
- package/src/internal/object/model.ts +0 -170
- package/src/internal/object/relation.ts +0 -24
- package/src/internal/object/typename.ts +0 -61
- package/src/internal/object/version.ts +0 -22
- package/src/internal/projection/index.ts +0 -5
- package/src/internal/proxy/reactive-object.ts +0 -108
- package/src/internal/query/index.ts +0 -5
- package/src/internal/query/query.ts +0 -23
- package/src/internal/schema/runtime-schema-registry.ts +0 -78
- package/src/internal/schema/snapshot.ts +0 -25
- package/src/internal/schema/stored-schema.ts +0 -26
- package/src/internal/testing/index.ts +0 -6
- package/src/internal/testing/types.ts +0 -144
- package/src/internal/testing/utils.ts +0 -54
- package/src/internal/types/types.test.ts +0 -48
- package/src/internal/types/types.ts +0 -176
- package/src/internal/types/util.ts +0 -9
- package/src/query/index.ts +0 -6
- package/src/query/query.test.ts +0 -401
- package/src/query/query.ts +0 -789
- package/src/test/api.test.ts +0 -180
- package/src/testing/echo-schema.ts +0 -39
- package/src/testing/types.ts +0 -108
- /package/dist/lib/browser/{query/index.mjs.map → Annotation.mjs.map} +0 -0
- /package/dist/lib/{node-esm/query/index.mjs.map → browser/Database.mjs.map} +0 -0
- /package/dist/types/src/internal/{ast → annotations}/annotations.test.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/annotations.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/effect-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{json → json-schema}/json-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{projection → schema}/compose.d.ts +0 -0
- /package/dist/types/src/internal/{projection → schema}/compose.test.d.ts +0 -0
- /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
- /package/src/internal/{json → json-schema}/effect-schema.test.ts +0 -0
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { deepMapValues } from '@dxos/util';
|
|
6
|
+
|
|
7
|
+
import { RelationSourceDXNId, RelationSourceId, RelationTargetDXNId, RelationTargetId } from '../entities/relation';
|
|
8
|
+
import { KindId, SnapshotKindId } from '../types/entity';
|
|
9
|
+
import { MetaId } from '../types/meta';
|
|
10
|
+
import { SchemaId, TypeId } from '../types/typename';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copy a Symbol-keyed property from source to target if it exists.
|
|
14
|
+
*/
|
|
15
|
+
const copySymbolProperty = (source: any, target: any, symbol: symbol): void => {
|
|
16
|
+
if (symbol in source) {
|
|
17
|
+
Object.defineProperty(target, symbol, {
|
|
18
|
+
value: source[symbol],
|
|
19
|
+
writable: false,
|
|
20
|
+
enumerable: false,
|
|
21
|
+
configurable: false,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns an immutable snapshot of the reactive object.
|
|
28
|
+
* The snapshot is branded with SnapshotKindId (not KindId).
|
|
29
|
+
*/
|
|
30
|
+
export const getSnapshot = <T extends object>(obj: T): T => {
|
|
31
|
+
const snapshot = deepMapValues(obj, (value, recurse) => {
|
|
32
|
+
// Do not recurse on references (but do recurse on arrays).
|
|
33
|
+
if (
|
|
34
|
+
typeof value === 'object' &&
|
|
35
|
+
value !== null &&
|
|
36
|
+
Object.getPrototypeOf(value) !== Object.prototype &&
|
|
37
|
+
!Array.isArray(value)
|
|
38
|
+
) {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return recurse(value);
|
|
43
|
+
}) as any;
|
|
44
|
+
|
|
45
|
+
// Add SnapshotKindId brand based on original KindId.
|
|
46
|
+
if (obj != null && typeof obj === 'object' && KindId in obj) {
|
|
47
|
+
snapshot[SnapshotKindId] = (obj as any)[KindId];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Preserve Symbol-keyed properties that are important for type introspection.
|
|
51
|
+
// These are not copied by deepMapValues since Object.keys() doesn't include symbols.
|
|
52
|
+
if (obj != null && typeof obj === 'object') {
|
|
53
|
+
const source = obj as any;
|
|
54
|
+
|
|
55
|
+
// Type introspection symbols.
|
|
56
|
+
copySymbolProperty(source, snapshot, TypeId);
|
|
57
|
+
copySymbolProperty(source, snapshot, SchemaId);
|
|
58
|
+
|
|
59
|
+
// Metadata symbol.
|
|
60
|
+
copySymbolProperty(source, snapshot, MetaId);
|
|
61
|
+
|
|
62
|
+
// Relation endpoint symbols.
|
|
63
|
+
copySymbolProperty(source, snapshot, RelationSourceDXNId);
|
|
64
|
+
copySymbolProperty(source, snapshot, RelationTargetDXNId);
|
|
65
|
+
copySymbolProperty(source, snapshot, RelationSourceId);
|
|
66
|
+
copySymbolProperty(source, snapshot, RelationTargetId);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return Object.freeze(snapshot) as T;
|
|
70
|
+
};
|
|
@@ -6,16 +6,20 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
7
|
import { describe, expect, test } from 'vitest';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { EchoObjectSchema } from '../entities';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
typename: 'example.com/type/Organization',
|
|
13
|
-
version: '0.1.0',
|
|
14
|
-
})({
|
|
11
|
+
const Organization = Schema.Struct({
|
|
15
12
|
name: Schema.String,
|
|
16
|
-
})
|
|
13
|
+
}).pipe(
|
|
14
|
+
EchoObjectSchema({
|
|
15
|
+
typename: 'example.com/type/Organization',
|
|
16
|
+
version: '0.1.0',
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
interface Organization extends Schema.Schema.Type<typeof Organization> {}
|
|
21
|
+
|
|
22
|
+
describe('EchoObjectSchema DSL', () => {
|
|
19
23
|
test('type is a valid schema', async () => {
|
|
20
24
|
expect(Schema.isSchema(Organization)).to.be.true;
|
|
21
25
|
});
|
|
@@ -24,10 +28,6 @@ describe('EchoObject class DSL', () => {
|
|
|
24
28
|
expect(Organization.typename).to.eq('example.com/type/Organization');
|
|
25
29
|
});
|
|
26
30
|
|
|
27
|
-
test('expect constructor to throw', async () => {
|
|
28
|
-
expect(() => new Organization()).to.throw();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
31
|
test('expect schema', async () => {
|
|
32
32
|
expect(SchemaAST.isTypeLiteral(Organization.ast)).to.be.true;
|
|
33
33
|
});
|
|
@@ -2,16 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import * as Schema from 'effect/Schema';
|
|
6
|
-
import * as SchemaAST from 'effect/SchemaAST';
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
7
6
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import { EntityKind, SchemaVersion, type TypeAnnotation, TypeAnnotationId, type TypeMeta, Typename } from '../ast';
|
|
11
|
-
import { type HasId } from '../types';
|
|
12
|
-
|
|
13
|
-
import { type TypedObjectFields, type TypedObjectOptions, makeTypedEntityClass } from './common';
|
|
14
|
-
import { makeTypeJsonSchemaAnnotation } from './entity';
|
|
7
|
+
import { type TypeMeta } from '../annotations';
|
|
8
|
+
import { type AnyEntity } from '../types';
|
|
15
9
|
|
|
16
10
|
/**
|
|
17
11
|
* Definition for an object type that can be stored in an ECHO database.
|
|
@@ -19,70 +13,18 @@ import { makeTypeJsonSchemaAnnotation } from './entity';
|
|
|
19
13
|
* Has a typename and version.
|
|
20
14
|
*
|
|
21
15
|
* In contrast to {@link EchoSchema} this definition is not recorded in the database.
|
|
16
|
+
*
|
|
17
|
+
* @deprecated Use `Type.Obj.Any` from `@dxos/echo` instead.
|
|
22
18
|
*/
|
|
23
19
|
export interface TypedObject<A = any, I = any> extends TypeMeta, Schema.Schema<A, I> {}
|
|
24
20
|
|
|
25
21
|
/**
|
|
26
22
|
* Typed object that could be used as a prototype in class definitions.
|
|
27
23
|
* This is an internal API type.
|
|
28
|
-
*
|
|
24
|
+
*
|
|
25
|
+
* @deprecated Use `Type.Obj.Any` from `@dxos/echo` instead.
|
|
29
26
|
*/
|
|
30
27
|
export interface TypedObjectPrototype<A = any, I = any> extends TypedObject<A, I> {
|
|
31
28
|
/** Type constructor. */
|
|
32
|
-
new ():
|
|
29
|
+
new (): AnyEntity & A;
|
|
33
30
|
}
|
|
34
|
-
|
|
35
|
-
export type TypedObjectProps = TypeMeta & {
|
|
36
|
-
// TODO(dmaretskyi): Remove after all legacy types has been removed.
|
|
37
|
-
disableValidation?: boolean;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Base class factory for typed objects.
|
|
42
|
-
* @deprecated Use Function.pipe(Type.Obj) instead.
|
|
43
|
-
*/
|
|
44
|
-
export const TypedObject = ({
|
|
45
|
-
typename: typenameParam,
|
|
46
|
-
version: versionParam,
|
|
47
|
-
disableValidation,
|
|
48
|
-
}: TypedObjectProps) => {
|
|
49
|
-
const typename = Typename.make(typenameParam, { disableValidation });
|
|
50
|
-
const version = SchemaVersion.make(versionParam, { disableValidation });
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Return class definition factory.
|
|
54
|
-
*/
|
|
55
|
-
return <SchemaFields extends Schema.Struct.Fields, Options extends TypedObjectOptions>(
|
|
56
|
-
fields: SchemaFields,
|
|
57
|
-
options?: Options,
|
|
58
|
-
): TypedObjectPrototype<TypedObjectFields<SchemaFields, Options>, Schema.Struct.Encoded<SchemaFields>> => {
|
|
59
|
-
// Create schema from fields.
|
|
60
|
-
const schema: Schema.Schema.All = options?.record
|
|
61
|
-
? Schema.Struct(fields, { key: Schema.String, value: Schema.Any })
|
|
62
|
-
: Schema.Struct(fields);
|
|
63
|
-
|
|
64
|
-
// Set ECHO object id property.
|
|
65
|
-
const typeSchema = Schema.extend(
|
|
66
|
-
Schema.mutable(options?.partial ? Schema.partial(schema) : schema),
|
|
67
|
-
Schema.Struct({ id: Schema.String }),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
// Set ECHO annotations.
|
|
71
|
-
invariant(typeof EntityKind.Object === 'string');
|
|
72
|
-
const annotatedSchema = typeSchema.annotations({
|
|
73
|
-
[TypeAnnotationId]: { kind: EntityKind.Object, typename, version } satisfies TypeAnnotation,
|
|
74
|
-
[SchemaAST.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
75
|
-
kind: EntityKind.Object,
|
|
76
|
-
typename,
|
|
77
|
-
version,
|
|
78
|
-
}),
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Return class definition.
|
|
83
|
-
* NOTE: Actual reactive ECHO objects must be created via the `live(Type)` function.
|
|
84
|
-
*/
|
|
85
|
-
// TODO(burdon): This is missing fields required by TypedObject (e.g., Type, Encoded, Context)?
|
|
86
|
-
return class TypedObject extends makeTypedEntityClass(typename, version, annotatedSchema as any) {} as any;
|
|
87
|
-
};
|
|
88
|
-
};
|