@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,861 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Option from 'effect/Option';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
+
import { describe, expect, test } from 'vitest';
|
|
9
|
+
|
|
10
|
+
import { type JsonProp, findAnnotation } from '@dxos/effect';
|
|
11
|
+
import { ObjectId } from '@dxos/keys';
|
|
12
|
+
import { log } from '@dxos/log';
|
|
13
|
+
|
|
14
|
+
import { TestSchema, prepareAstForCompare } from '../../testing';
|
|
15
|
+
import * as Type from '../../Type';
|
|
16
|
+
import {
|
|
17
|
+
FieldLookupAnnotationId,
|
|
18
|
+
GeneratorAnnotation,
|
|
19
|
+
LabelAnnotation,
|
|
20
|
+
PropertyMeta,
|
|
21
|
+
getTypeAnnotation,
|
|
22
|
+
getTypeIdentifierAnnotation,
|
|
23
|
+
} from '../annotations';
|
|
24
|
+
import { EchoObjectSchema } from '../entities';
|
|
25
|
+
import { Email, FormatAnnotation, TypeFormat } from '../formats';
|
|
26
|
+
import { JsonSchemaType, getNormalizedEchoAnnotations, getSchemaProperty, setSchemaProperty } from '../json-schema';
|
|
27
|
+
import { Ref, createSchemaReference, getReferenceAst, getSchemaReference } from '../ref';
|
|
28
|
+
import { PersistentSchema } from '../schema';
|
|
29
|
+
import { EntityKind } from '../types';
|
|
30
|
+
|
|
31
|
+
import { toEffectSchema, toJsonSchema } from './json-schema';
|
|
32
|
+
|
|
33
|
+
const EXAMPLE_NAMESPACE = '@example';
|
|
34
|
+
|
|
35
|
+
describe('effect-to-json', () => {
|
|
36
|
+
test('type annotation', () => {
|
|
37
|
+
const Test = Schema.Struct({ name: Schema.String }).pipe(
|
|
38
|
+
Type.object({
|
|
39
|
+
typename: 'example.com/type/Test',
|
|
40
|
+
version: '0.1.0',
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
const jsonSchema = toJsonSchema(Test);
|
|
44
|
+
expect((jsonSchema as any).$id).toEqual('dxn:type:example.com/type/Test');
|
|
45
|
+
expect((jsonSchema as any).version).toEqual('0.1.0');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('property meta annotation', () => {
|
|
49
|
+
const meta = { maxLength: 0 };
|
|
50
|
+
const Test = Schema.Struct({
|
|
51
|
+
name: Schema.String.pipe(PropertyMeta(EXAMPLE_NAMESPACE, meta)),
|
|
52
|
+
}).pipe(
|
|
53
|
+
Type.object({
|
|
54
|
+
typename: 'example.com/type/Test',
|
|
55
|
+
version: '0.1.0',
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
const jsonSchema = toJsonSchema(Test);
|
|
59
|
+
expect(getNormalizedEchoAnnotations(jsonSchema.properties!.name!)!.meta![EXAMPLE_NAMESPACE]).to.deep.eq(meta);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('reference annotation', () => {
|
|
63
|
+
const Nested = Schema.Struct({
|
|
64
|
+
name: Schema.String,
|
|
65
|
+
}).pipe(
|
|
66
|
+
Type.object({
|
|
67
|
+
typename: 'example.com/type/TestNested',
|
|
68
|
+
version: '0.1.0',
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
const Test = Schema.Struct({
|
|
72
|
+
name: Ref(Nested),
|
|
73
|
+
}).pipe(
|
|
74
|
+
Type.object({
|
|
75
|
+
typename: 'example.com/type/Test',
|
|
76
|
+
version: '0.1.0',
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
const jsonSchema = toJsonSchema(Test);
|
|
80
|
+
// log.info('schema', { jsonSchema });
|
|
81
|
+
const nested = jsonSchema.properties!.name;
|
|
82
|
+
expectReferenceAnnotation(nested);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// TODO(ZaymonFC): @dmaretskyi we still need to fix this.
|
|
86
|
+
// TODO(dmaretskyi): Remove FieldLookupAnnotationId.
|
|
87
|
+
test.skip('reference annotation with lookup property', () => {
|
|
88
|
+
const Nested = Schema.Struct({
|
|
89
|
+
name: Schema.String,
|
|
90
|
+
}).pipe(
|
|
91
|
+
Type.object({
|
|
92
|
+
typename: 'example.com/type/TestNested',
|
|
93
|
+
version: '0.1.0',
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
const Test = Schema.Struct({
|
|
97
|
+
name: Ref(Nested).annotations({ [FieldLookupAnnotationId]: 'name' }),
|
|
98
|
+
}).pipe(
|
|
99
|
+
Type.object({
|
|
100
|
+
typename: 'example.com/type/Test',
|
|
101
|
+
version: '0.1.0',
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
104
|
+
const jsonSchema = toJsonSchema(Test);
|
|
105
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
106
|
+
|
|
107
|
+
const annotation = findAnnotation<string>(effectSchema.ast, FieldLookupAnnotationId);
|
|
108
|
+
expect(annotation).to.not.toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('array of references', () => {
|
|
112
|
+
const Nested = Schema.Struct({
|
|
113
|
+
name: Schema.String,
|
|
114
|
+
}).pipe(
|
|
115
|
+
Type.object({
|
|
116
|
+
typename: 'example.com/type/TestNested',
|
|
117
|
+
version: '0.1.0',
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
const Test = Schema.Struct({
|
|
121
|
+
name: Schema.Array(Ref(Nested)),
|
|
122
|
+
}).pipe(
|
|
123
|
+
Type.object({
|
|
124
|
+
typename: 'example.com/type/Test',
|
|
125
|
+
version: '0.1.0',
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const jsonSchema = toJsonSchema(Test);
|
|
130
|
+
expectReferenceAnnotation((jsonSchema.properties!.name as any).items);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('optional references', () => {
|
|
134
|
+
const Nested = Schema.Struct({
|
|
135
|
+
name: Schema.String,
|
|
136
|
+
}).pipe(
|
|
137
|
+
Type.object({
|
|
138
|
+
typename: 'example.com/type/TestNested',
|
|
139
|
+
version: '0.1.0',
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
const Test = Schema.Struct({
|
|
143
|
+
name: Schema.optional(Ref(Nested)),
|
|
144
|
+
}).pipe(
|
|
145
|
+
Type.object({
|
|
146
|
+
typename: 'example.com/type/Test',
|
|
147
|
+
version: '0.1.0',
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
const jsonSchema = toJsonSchema(Test);
|
|
151
|
+
expectReferenceAnnotation(jsonSchema.properties!.name);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('regular objects are not annotated', () => {
|
|
155
|
+
const object = Schema.Struct({ name: Schema.Struct({ name: Schema.String }) });
|
|
156
|
+
const jsonSchema = toJsonSchema(object);
|
|
157
|
+
expect(getNormalizedEchoAnnotations(jsonSchema)).to.be.undefined;
|
|
158
|
+
expect(getNormalizedEchoAnnotations(jsonSchema.properties!.name!)).to.be.undefined;
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('annotations', () => {
|
|
162
|
+
const TempSchema = Schema.Struct({
|
|
163
|
+
name: Schema.String.annotations({ description: 'Person name', title: 'Name' }),
|
|
164
|
+
email: Schema.String.pipe(FormatAnnotation.set(TypeFormat.Email)).annotations({
|
|
165
|
+
description: 'Email address',
|
|
166
|
+
}),
|
|
167
|
+
}).pipe(
|
|
168
|
+
Type.object({
|
|
169
|
+
typename: 'example.com/type/Person',
|
|
170
|
+
version: '0.1.0',
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
const jsonSchema = toJsonSchema(TempSchema);
|
|
175
|
+
expect(jsonSchema).to.deep.eq({
|
|
176
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
177
|
+
$id: 'dxn:type:example.com/type/Person',
|
|
178
|
+
|
|
179
|
+
entityKind: EntityKind.Object,
|
|
180
|
+
typename: 'example.com/type/Person',
|
|
181
|
+
version: '0.1.0',
|
|
182
|
+
|
|
183
|
+
type: 'object',
|
|
184
|
+
required: ['name', 'email', 'id'],
|
|
185
|
+
properties: {
|
|
186
|
+
id: { type: 'string' },
|
|
187
|
+
name: { type: 'string', title: 'Name', description: 'Person name' },
|
|
188
|
+
email: {
|
|
189
|
+
type: 'string',
|
|
190
|
+
|
|
191
|
+
description: 'Email address',
|
|
192
|
+
format: 'email',
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
propertyOrder: ['name', 'email', 'id'],
|
|
196
|
+
additionalProperties: false,
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('handles suspend -- Contact schema serialization', () => {
|
|
201
|
+
const schema = toJsonSchema(TestSchema.Person);
|
|
202
|
+
expect(Object.keys(schema.properties!)).toEqual([
|
|
203
|
+
'id',
|
|
204
|
+
'name',
|
|
205
|
+
'username',
|
|
206
|
+
'email',
|
|
207
|
+
'age',
|
|
208
|
+
'tasks',
|
|
209
|
+
'employer',
|
|
210
|
+
'address',
|
|
211
|
+
'fields',
|
|
212
|
+
]);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('reference property by ref', () => {
|
|
216
|
+
const Organization = Schema.Struct({
|
|
217
|
+
field: Schema.String,
|
|
218
|
+
}).pipe(
|
|
219
|
+
Type.object({
|
|
220
|
+
typename: 'example.com/type/Organization',
|
|
221
|
+
version: '0.1.0',
|
|
222
|
+
}),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const Contact = Schema.Struct({
|
|
226
|
+
name: Schema.String,
|
|
227
|
+
organization: Ref(Organization).annotations({ description: 'Contact organization' }),
|
|
228
|
+
}).pipe(
|
|
229
|
+
Type.object({
|
|
230
|
+
typename: 'example.com/type/Person',
|
|
231
|
+
version: '0.1.0',
|
|
232
|
+
}),
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
// log.info('Contact', { ast: Contact.ast });
|
|
236
|
+
|
|
237
|
+
const jsonSchema = toJsonSchema(Contact);
|
|
238
|
+
expect(jsonSchema).toEqual({
|
|
239
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
240
|
+
$id: 'dxn:type:example.com/type/Person',
|
|
241
|
+
|
|
242
|
+
entityKind: EntityKind.Object,
|
|
243
|
+
typename: 'example.com/type/Person',
|
|
244
|
+
version: '0.1.0',
|
|
245
|
+
|
|
246
|
+
type: 'object',
|
|
247
|
+
additionalProperties: false,
|
|
248
|
+
|
|
249
|
+
properties: {
|
|
250
|
+
id: {
|
|
251
|
+
type: 'string',
|
|
252
|
+
},
|
|
253
|
+
name: {
|
|
254
|
+
type: 'string',
|
|
255
|
+
},
|
|
256
|
+
organization: {
|
|
257
|
+
allOf: [
|
|
258
|
+
{
|
|
259
|
+
$id: '/schemas/echo/ref',
|
|
260
|
+
$ref: '/schemas/echo/ref',
|
|
261
|
+
reference: {
|
|
262
|
+
schema: {
|
|
263
|
+
$ref: 'dxn:type:example.com/type/Organization',
|
|
264
|
+
},
|
|
265
|
+
schemaVersion: '0.1.0',
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
description: 'Contact organization',
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
required: ['name', 'organization', 'id'],
|
|
273
|
+
propertyOrder: ['name', 'organization', 'id'],
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test('add reference property', () => {
|
|
278
|
+
const Organization = Schema.Struct({
|
|
279
|
+
field: Schema.String,
|
|
280
|
+
}).pipe(
|
|
281
|
+
Type.object({
|
|
282
|
+
typename: 'example.com/type/Organization',
|
|
283
|
+
version: '0.1.0',
|
|
284
|
+
}),
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
const Contact = Schema.Struct({
|
|
288
|
+
name: Schema.String,
|
|
289
|
+
organization: Ref(Organization).annotations({ description: 'Contact organization' }),
|
|
290
|
+
}).pipe(
|
|
291
|
+
Type.object({
|
|
292
|
+
typename: 'example.com/type/Person',
|
|
293
|
+
version: '0.1.0',
|
|
294
|
+
}),
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
const jsonSchema = toJsonSchema(Contact);
|
|
298
|
+
setSchemaProperty(jsonSchema, 'organization' as JsonProp, createSchemaReference(Organization.typename));
|
|
299
|
+
const { typename } = getSchemaReference(getSchemaProperty(jsonSchema, 'organization' as JsonProp) ?? {}) ?? {};
|
|
300
|
+
expect(typename).to.eq(Organization.typename);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('serialize circular schema (PersistentSchema)', () => {
|
|
304
|
+
const jsonSchema = toJsonSchema(PersistentSchema);
|
|
305
|
+
expect(Object.keys(jsonSchema.properties!).length).toBeGreaterThan(0);
|
|
306
|
+
|
|
307
|
+
// TODO(dmaretskyi): Currently unable to deserialize.
|
|
308
|
+
// const effectSchema = toEffectSchema(jsonSchema);
|
|
309
|
+
log('schema', { jsonSchema });
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test('tuple schema with description', () => {
|
|
313
|
+
const schema = Schema.Struct({
|
|
314
|
+
args: Schema.Tuple(
|
|
315
|
+
Schema.String.annotations({ description: 'The source currency' }),
|
|
316
|
+
Schema.String.annotations({ description: 'The target currency' }),
|
|
317
|
+
),
|
|
318
|
+
});
|
|
319
|
+
const jsonSchema = toJsonSchema(schema);
|
|
320
|
+
log('schema', { jsonSchema });
|
|
321
|
+
|
|
322
|
+
(Schema.asserts(JsonSchemaType) as any)(jsonSchema);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test('reference with title annotation', () => {
|
|
326
|
+
const schema = Schema.Struct({
|
|
327
|
+
contact: Ref(TestSchema.Person).annotations({ title: 'Custom Title' }),
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// log.info('schema before', { ast: schema.ast });
|
|
331
|
+
|
|
332
|
+
const jsonSchema = toJsonSchema(schema);
|
|
333
|
+
// log.info('json schema', { jsonSchema });
|
|
334
|
+
|
|
335
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
336
|
+
// log.info('effect schema', { ast: effectSchema.ast });
|
|
337
|
+
|
|
338
|
+
expect(
|
|
339
|
+
effectSchema.pipe(
|
|
340
|
+
Schema.pluck('contact'),
|
|
341
|
+
Schema.typeSchema,
|
|
342
|
+
(s) => s.ast,
|
|
343
|
+
SchemaAST.getAnnotation(SchemaAST.TitleAnnotationId),
|
|
344
|
+
Option.getOrUndefined,
|
|
345
|
+
),
|
|
346
|
+
).to.eq('Custom Title');
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
test('relation schema', () => {
|
|
350
|
+
const schema = TestSchema.EmployedBy;
|
|
351
|
+
const jsonSchema = toJsonSchema(schema);
|
|
352
|
+
expect(jsonSchema).toEqual({
|
|
353
|
+
$id: 'dxn:type:example.com/type/EmployedBy',
|
|
354
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
355
|
+
entityKind: 'relation',
|
|
356
|
+
typename: 'example.com/type/EmployedBy',
|
|
357
|
+
version: '0.1.0',
|
|
358
|
+
relationSource: {
|
|
359
|
+
// TODO(dmaretskyi): Should those point to specific schema version?
|
|
360
|
+
$ref: 'dxn:type:example.com/type/Person',
|
|
361
|
+
},
|
|
362
|
+
relationTarget: {
|
|
363
|
+
// TODO(dmaretskyi): Should those point to specific schema version?
|
|
364
|
+
$ref: 'dxn:type:example.com/type/Organization',
|
|
365
|
+
},
|
|
366
|
+
type: 'object',
|
|
367
|
+
properties: {
|
|
368
|
+
id: {
|
|
369
|
+
type: 'string',
|
|
370
|
+
},
|
|
371
|
+
role: {
|
|
372
|
+
type: 'string',
|
|
373
|
+
},
|
|
374
|
+
since: {
|
|
375
|
+
type: 'string',
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
propertyOrder: ['role', 'since', 'id'],
|
|
379
|
+
required: ['role', 'id'],
|
|
380
|
+
additionalProperties: false,
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
test('label prop', () => {
|
|
385
|
+
const Organization = Schema.Struct({
|
|
386
|
+
id: ObjectId,
|
|
387
|
+
name: Schema.String,
|
|
388
|
+
}).pipe(
|
|
389
|
+
EchoObjectSchema({
|
|
390
|
+
typename: 'example.com/type/Organization',
|
|
391
|
+
version: '0.1.0',
|
|
392
|
+
}),
|
|
393
|
+
LabelAnnotation.set(['name']),
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
const jsonSchema = toJsonSchema(Organization);
|
|
397
|
+
expect(jsonSchema).toEqual({
|
|
398
|
+
$id: 'dxn:type:example.com/type/Organization',
|
|
399
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
400
|
+
typename: 'example.com/type/Organization',
|
|
401
|
+
version: '0.1.0',
|
|
402
|
+
entityKind: 'object',
|
|
403
|
+
type: 'object',
|
|
404
|
+
properties: {
|
|
405
|
+
id: {
|
|
406
|
+
type: 'string',
|
|
407
|
+
pattern: '^[0-7][0-9A-HJKMNP-TV-Z]{25}$',
|
|
408
|
+
description: 'A Universally Unique Lexicographically Sortable Identifier',
|
|
409
|
+
},
|
|
410
|
+
name: {
|
|
411
|
+
type: 'string',
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
annotations: {
|
|
415
|
+
labelProp: ['name'],
|
|
416
|
+
},
|
|
417
|
+
propertyOrder: ['id', 'name'],
|
|
418
|
+
required: ['id', 'name'],
|
|
419
|
+
additionalProperties: false,
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
test('object id with description', () => {
|
|
424
|
+
const schema = Schema.Struct({
|
|
425
|
+
id: ObjectId.annotations({ description: 'The id' }),
|
|
426
|
+
});
|
|
427
|
+
// log.info('schema', { schema: ObjectId.ast });
|
|
428
|
+
const jsonSchema = toJsonSchema(schema);
|
|
429
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
430
|
+
{
|
|
431
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
432
|
+
"additionalProperties": false,
|
|
433
|
+
"properties": {
|
|
434
|
+
"id": {
|
|
435
|
+
"description": "The id",
|
|
436
|
+
"pattern": "^[0-7][0-9A-HJKMNP-TV-Z]{25}$",
|
|
437
|
+
"type": "string",
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
"propertyOrder": [
|
|
441
|
+
"id",
|
|
442
|
+
],
|
|
443
|
+
"required": [
|
|
444
|
+
"id",
|
|
445
|
+
],
|
|
446
|
+
"type": "object",
|
|
447
|
+
}
|
|
448
|
+
`);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
test('email schema', () => {
|
|
452
|
+
const schema = Email;
|
|
453
|
+
const jsonSchema = toJsonSchema(schema);
|
|
454
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
455
|
+
{
|
|
456
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
457
|
+
"description": "Email address",
|
|
458
|
+
"format": "email",
|
|
459
|
+
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
|
|
460
|
+
"title": "Email",
|
|
461
|
+
"type": "string",
|
|
462
|
+
}
|
|
463
|
+
`);
|
|
464
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
465
|
+
expect(prepareAstForCompare(effectSchema.ast)).to.deep.eq(prepareAstForCompare(schema.ast));
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
const expectReferenceAnnotation = (object: JsonSchemaType) => {
|
|
469
|
+
expect(object.reference).to.deep.eq({
|
|
470
|
+
schema: {
|
|
471
|
+
$ref: 'dxn:type:example.com/type/TestNested',
|
|
472
|
+
},
|
|
473
|
+
schemaVersion: '0.1.0',
|
|
474
|
+
});
|
|
475
|
+
};
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
describe('json-to-effect', () => {
|
|
479
|
+
describe('field schema', () => {
|
|
480
|
+
test('email', () => {
|
|
481
|
+
const schema = Email;
|
|
482
|
+
expect(toJsonSchema(schema)).to.deep.eq({
|
|
483
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
484
|
+
type: 'string',
|
|
485
|
+
format: 'email',
|
|
486
|
+
title: 'Email',
|
|
487
|
+
description: 'Email address',
|
|
488
|
+
// TODO(dmaretskyi): omit pattern.
|
|
489
|
+
pattern: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
for (const partial of [false, true]) {
|
|
495
|
+
test(`deserialized equals original ${partial ? 'with partial' : ''}`, () => {
|
|
496
|
+
const Organization = Schema.Struct({
|
|
497
|
+
field: Schema.String,
|
|
498
|
+
}).pipe(
|
|
499
|
+
Type.object({
|
|
500
|
+
typename: 'example.com/type/Organization',
|
|
501
|
+
version: '0.1.0',
|
|
502
|
+
}),
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
const fields = {
|
|
506
|
+
string: Schema.String,
|
|
507
|
+
number: Schema.Number.pipe(PropertyMeta(EXAMPLE_NAMESPACE, { is_date: true })),
|
|
508
|
+
boolean: Schema.Boolean,
|
|
509
|
+
array: Schema.Array(Schema.String),
|
|
510
|
+
twoDArray: Schema.Array(Schema.Array(Schema.String)),
|
|
511
|
+
record: Schema.Record({ key: Schema.String, value: Schema.Number }),
|
|
512
|
+
object: Schema.Struct({ id: Schema.String, field: Ref(Organization) }),
|
|
513
|
+
echoObject: Ref(Organization),
|
|
514
|
+
echoObjectArray: Schema.Array(Ref(Organization)),
|
|
515
|
+
email: Schema.String.pipe(FormatAnnotation.set(TypeFormat.Email)),
|
|
516
|
+
null: Schema.Null,
|
|
517
|
+
} as const;
|
|
518
|
+
|
|
519
|
+
const Test = (partial ? Schema.partial(Schema.Struct(fields)) : Schema.Struct(fields)).pipe(
|
|
520
|
+
Type.object({
|
|
521
|
+
typename: 'example.com/type/Test',
|
|
522
|
+
version: '0.1.0',
|
|
523
|
+
}),
|
|
524
|
+
);
|
|
525
|
+
|
|
526
|
+
const jsonSchema = toJsonSchema(Test);
|
|
527
|
+
// log.info('schema', { jsonSchema });
|
|
528
|
+
|
|
529
|
+
const schema = toEffectSchema(jsonSchema);
|
|
530
|
+
|
|
531
|
+
expect(() => expect(schema.ast).to.deep.eq(Test.ast)).to.throw();
|
|
532
|
+
expect(() => expect(prepareAstForCompare(Test.ast)).to.deep.eq(Test.ast)).to.throw();
|
|
533
|
+
expect(() => expect(schema.ast).to.deep.eq(prepareAstForCompare(Test.ast))).to.throw();
|
|
534
|
+
// log.info('', { original: prepareAstForCompare(Schema.ast), deserialized: prepareAstForCompare(schema.ast) });
|
|
535
|
+
expect(prepareAstForCompare(schema.ast)).to.deep.eq(prepareAstForCompare(Test.ast));
|
|
536
|
+
|
|
537
|
+
// TODO(dmaretskyi): Fix.
|
|
538
|
+
// expect(
|
|
539
|
+
// SchemaAST.getPropertySignatures(schema.ast).find((prop) => prop.name === 'email')!.type.annotations[
|
|
540
|
+
// FormatAnnotationId
|
|
541
|
+
// ],
|
|
542
|
+
// ).toEqual('email');
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
test('legacy schema with dxn:type $id gets decoded', () => {
|
|
547
|
+
const jsonSchema: JsonSchemaType = {
|
|
548
|
+
$id: 'dxn:type:example.com/type/Project',
|
|
549
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
550
|
+
additionalProperties: false,
|
|
551
|
+
echo: {
|
|
552
|
+
type: {
|
|
553
|
+
schemaId: '01JERV1HQCQZDQ4NVCJ42QB38F',
|
|
554
|
+
typename: 'example.com/type/Project',
|
|
555
|
+
version: '0.1.0',
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
properties: {
|
|
559
|
+
description: {
|
|
560
|
+
type: 'string',
|
|
561
|
+
},
|
|
562
|
+
id: {
|
|
563
|
+
type: 'string',
|
|
564
|
+
},
|
|
565
|
+
name: {
|
|
566
|
+
echo: {
|
|
567
|
+
generator: 'commerce.productName',
|
|
568
|
+
},
|
|
569
|
+
type: 'string',
|
|
570
|
+
},
|
|
571
|
+
},
|
|
572
|
+
required: ['id'],
|
|
573
|
+
type: 'object',
|
|
574
|
+
version: '0.1.0',
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
const schema = toEffectSchema(jsonSchema);
|
|
578
|
+
expect(getTypeAnnotation(schema)).to.deep.eq({
|
|
579
|
+
kind: EntityKind.Object,
|
|
580
|
+
typename: 'example.com/type/Project',
|
|
581
|
+
version: '0.1.0',
|
|
582
|
+
});
|
|
583
|
+
expect(getTypeIdentifierAnnotation(schema)).to.deep.eq('dxn:echo:@:01JERV1HQCQZDQ4NVCJ42QB38F');
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
test('symbol annotations get compared', () => {
|
|
587
|
+
const schema1 = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Email));
|
|
588
|
+
const schema2 = Schema.String.pipe(FormatAnnotation.set(TypeFormat.Currency));
|
|
589
|
+
expect(prepareAstForCompare(schema1.ast)).not.to.deep.eq(prepareAstForCompare(schema2.ast));
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
test('description gets preserved', () => {
|
|
593
|
+
const schema = Schema.Struct({
|
|
594
|
+
name: Schema.String.annotations({ description: 'Name' }),
|
|
595
|
+
});
|
|
596
|
+
const jsonSchema = toJsonSchema(schema);
|
|
597
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
598
|
+
const jsonSchema2 = toJsonSchema(effectSchema);
|
|
599
|
+
expect(jsonSchema2.properties!.name.description).to.eq('Name');
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
test('relation schema roundtrip', () => {
|
|
603
|
+
const schema = TestSchema.HasManager;
|
|
604
|
+
const jsonSchema = toJsonSchema(schema);
|
|
605
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
606
|
+
expect(prepareAstForCompare(effectSchema.ast)).to.deep.eq(prepareAstForCompare(schema.ast));
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
test('generator annotation', () => {
|
|
610
|
+
const schema = Schema.Struct({
|
|
611
|
+
name: Schema.String.pipe(GeneratorAnnotation.set('commerce.productName')),
|
|
612
|
+
});
|
|
613
|
+
const jsonSchema = toJsonSchema(schema);
|
|
614
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
615
|
+
{
|
|
616
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
617
|
+
"additionalProperties": false,
|
|
618
|
+
"properties": {
|
|
619
|
+
"name": {
|
|
620
|
+
"annotations": {
|
|
621
|
+
"generator": "commerce.productName",
|
|
622
|
+
},
|
|
623
|
+
"type": "string",
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
"propertyOrder": [
|
|
627
|
+
"name",
|
|
628
|
+
],
|
|
629
|
+
"required": [
|
|
630
|
+
"name",
|
|
631
|
+
],
|
|
632
|
+
"type": "object",
|
|
633
|
+
}
|
|
634
|
+
`);
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
// test('generator annotation on object', () => {
|
|
638
|
+
// const schema = Schema.Struct({
|
|
639
|
+
// });
|
|
640
|
+
// const jsonSchema = toJsonSchema(schema);
|
|
641
|
+
// expect(jsonSchema).toMatchInlineSnapshot();
|
|
642
|
+
// });
|
|
643
|
+
|
|
644
|
+
test('default annotation ', () => {
|
|
645
|
+
const schema = Schema.Struct({
|
|
646
|
+
str: Schema.String.annotations({
|
|
647
|
+
default: 'foo',
|
|
648
|
+
}),
|
|
649
|
+
arr: Schema.Array(Schema.String).annotations({
|
|
650
|
+
default: [],
|
|
651
|
+
}),
|
|
652
|
+
obj: Schema.Struct({
|
|
653
|
+
foo: Schema.optional(Schema.String).annotations({
|
|
654
|
+
default: 'bar',
|
|
655
|
+
}),
|
|
656
|
+
}),
|
|
657
|
+
});
|
|
658
|
+
const jsonSchema = toJsonSchema(schema);
|
|
659
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
660
|
+
{
|
|
661
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
662
|
+
"additionalProperties": false,
|
|
663
|
+
"properties": {
|
|
664
|
+
"arr": {
|
|
665
|
+
"default": [],
|
|
666
|
+
"items": {
|
|
667
|
+
"type": "string",
|
|
668
|
+
},
|
|
669
|
+
"type": "array",
|
|
670
|
+
},
|
|
671
|
+
"obj": {
|
|
672
|
+
"additionalProperties": false,
|
|
673
|
+
"properties": {
|
|
674
|
+
"foo": {
|
|
675
|
+
"default": "bar",
|
|
676
|
+
"type": "string",
|
|
677
|
+
},
|
|
678
|
+
},
|
|
679
|
+
"propertyOrder": [
|
|
680
|
+
"foo",
|
|
681
|
+
],
|
|
682
|
+
"required": [],
|
|
683
|
+
"type": "object",
|
|
684
|
+
},
|
|
685
|
+
"str": {
|
|
686
|
+
"default": "foo",
|
|
687
|
+
"type": "string",
|
|
688
|
+
},
|
|
689
|
+
},
|
|
690
|
+
"propertyOrder": [
|
|
691
|
+
"str",
|
|
692
|
+
"arr",
|
|
693
|
+
"obj",
|
|
694
|
+
],
|
|
695
|
+
"required": [
|
|
696
|
+
"str",
|
|
697
|
+
"arr",
|
|
698
|
+
"obj",
|
|
699
|
+
],
|
|
700
|
+
"type": "object",
|
|
701
|
+
}
|
|
702
|
+
`);
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
test('schema with optional referece', () => {
|
|
706
|
+
const TempSchema = Schema.Struct({ contact: Schema.optional(Ref(TestSchema.Person)) });
|
|
707
|
+
const jsonSchema = toJsonSchema(TempSchema);
|
|
708
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
709
|
+
{
|
|
710
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
711
|
+
"additionalProperties": false,
|
|
712
|
+
"properties": {
|
|
713
|
+
"contact": {
|
|
714
|
+
"$id": "/schemas/echo/ref",
|
|
715
|
+
"$ref": "/schemas/echo/ref",
|
|
716
|
+
"reference": {
|
|
717
|
+
"schema": {
|
|
718
|
+
"$ref": "dxn:type:example.com/type/Person",
|
|
719
|
+
},
|
|
720
|
+
"schemaVersion": "0.1.0",
|
|
721
|
+
},
|
|
722
|
+
},
|
|
723
|
+
},
|
|
724
|
+
"propertyOrder": [
|
|
725
|
+
"contact",
|
|
726
|
+
],
|
|
727
|
+
"required": [],
|
|
728
|
+
"type": "object",
|
|
729
|
+
}
|
|
730
|
+
`);
|
|
731
|
+
|
|
732
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
733
|
+
expect(prepareAstForCompare(effectSchema.ast)).to.deep.eq(prepareAstForCompare(TempSchema.ast));
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
test('object nested inside another struct', () => {
|
|
737
|
+
const Contact = Schema.Struct({
|
|
738
|
+
name: Schema.String,
|
|
739
|
+
}).pipe(EchoObjectSchema({ typename: 'example.com/type/Person', version: '0.1.0' }));
|
|
740
|
+
const input = Schema.Struct({
|
|
741
|
+
contact: Contact,
|
|
742
|
+
});
|
|
743
|
+
const jsonSchema = toJsonSchema(input);
|
|
744
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
745
|
+
{
|
|
746
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
747
|
+
"additionalProperties": false,
|
|
748
|
+
"properties": {
|
|
749
|
+
"contact": {
|
|
750
|
+
"$id": "dxn:type:example.com/type/Person",
|
|
751
|
+
"additionalProperties": false,
|
|
752
|
+
"entityKind": "object",
|
|
753
|
+
"properties": {
|
|
754
|
+
"id": {
|
|
755
|
+
"type": "string",
|
|
756
|
+
},
|
|
757
|
+
"name": {
|
|
758
|
+
"type": "string",
|
|
759
|
+
},
|
|
760
|
+
},
|
|
761
|
+
"propertyOrder": [
|
|
762
|
+
"name",
|
|
763
|
+
"id",
|
|
764
|
+
],
|
|
765
|
+
"required": [
|
|
766
|
+
"name",
|
|
767
|
+
"id",
|
|
768
|
+
],
|
|
769
|
+
"type": "object",
|
|
770
|
+
"typename": "example.com/type/Person",
|
|
771
|
+
"version": "0.1.0",
|
|
772
|
+
},
|
|
773
|
+
},
|
|
774
|
+
"propertyOrder": [
|
|
775
|
+
"contact",
|
|
776
|
+
],
|
|
777
|
+
"required": [
|
|
778
|
+
"contact",
|
|
779
|
+
],
|
|
780
|
+
"type": "object",
|
|
781
|
+
}
|
|
782
|
+
`);
|
|
783
|
+
|
|
784
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
785
|
+
expect(prepareAstForCompare(effectSchema.ast)).to.deep.eq(prepareAstForCompare(input.ast));
|
|
786
|
+
});
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
describe('reference', () => {
|
|
790
|
+
test('reference annotation', () => {
|
|
791
|
+
const schema = Ref(TestSchema.Person);
|
|
792
|
+
const jsonSchema = toJsonSchema(schema);
|
|
793
|
+
expect(jsonSchema).toEqual({
|
|
794
|
+
$id: '/schemas/echo/ref',
|
|
795
|
+
$ref: '/schemas/echo/ref',
|
|
796
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
797
|
+
reference: {
|
|
798
|
+
schema: {
|
|
799
|
+
$ref: 'dxn:type:example.com/type/Person',
|
|
800
|
+
},
|
|
801
|
+
schemaVersion: '0.1.0',
|
|
802
|
+
},
|
|
803
|
+
});
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
test('title annotation', () => {
|
|
807
|
+
const schema = Ref(TestSchema.Person).annotations({ title: 'My custom title' });
|
|
808
|
+
const jsonSchema = toJsonSchema(schema);
|
|
809
|
+
expect(jsonSchema).toEqual({
|
|
810
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
811
|
+
allOf: [
|
|
812
|
+
{
|
|
813
|
+
$id: '/schemas/echo/ref',
|
|
814
|
+
$ref: '/schemas/echo/ref',
|
|
815
|
+
reference: {
|
|
816
|
+
schema: {
|
|
817
|
+
$ref: 'dxn:type:example.com/type/Person',
|
|
818
|
+
},
|
|
819
|
+
schemaVersion: '0.1.0',
|
|
820
|
+
},
|
|
821
|
+
},
|
|
822
|
+
],
|
|
823
|
+
title: 'My custom title',
|
|
824
|
+
});
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
test('description annotation', () => {
|
|
828
|
+
const schema = Ref(TestSchema.Person).annotations({ description: 'My custom description' });
|
|
829
|
+
const jsonSchema = toJsonSchema(schema);
|
|
830
|
+
expect(jsonSchema).toEqual({
|
|
831
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
832
|
+
allOf: [
|
|
833
|
+
{
|
|
834
|
+
$id: '/schemas/echo/ref',
|
|
835
|
+
$ref: '/schemas/echo/ref',
|
|
836
|
+
reference: {
|
|
837
|
+
schema: {
|
|
838
|
+
$ref: 'dxn:type:example.com/type/Person',
|
|
839
|
+
},
|
|
840
|
+
schemaVersion: '0.1.0',
|
|
841
|
+
},
|
|
842
|
+
},
|
|
843
|
+
],
|
|
844
|
+
description: 'My custom description',
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
const effectSchema = toEffectSchema(jsonSchema);
|
|
848
|
+
expect(prepareAstForCompare(effectSchema.ast)).to.deep.eq(prepareAstForCompare(schema.ast));
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
test('serialize and deserialize', () => {
|
|
852
|
+
const schema = Ref(TestSchema.Person);
|
|
853
|
+
const jsonSchema = toJsonSchema(schema);
|
|
854
|
+
const deserializedSchema = toEffectSchema(jsonSchema);
|
|
855
|
+
const refAst = getReferenceAst(deserializedSchema.ast);
|
|
856
|
+
expect(refAst).toEqual({
|
|
857
|
+
typename: TestSchema.Person.typename,
|
|
858
|
+
version: TestSchema.Person.version,
|
|
859
|
+
});
|
|
860
|
+
});
|
|
861
|
+
});
|