@dxos/echo 0.8.4-main.3a94e84 → 0.8.4-main.3c1ae3b
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 -1
- package/dist/lib/browser/Annotation.mjs +31 -0
- package/dist/lib/browser/Annotation.mjs.map +7 -0
- package/dist/lib/browser/Database.mjs +14 -0
- package/dist/lib/browser/Database.mjs.map +7 -0
- package/dist/lib/browser/Entity.mjs +20 -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 +60 -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 +18 -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 +83 -0
- package/dist/lib/browser/Obj.mjs.map +7 -0
- package/dist/lib/browser/Order.mjs +11 -0
- package/dist/lib/browser/Order.mjs.map +7 -0
- package/dist/lib/browser/Query.mjs +25 -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 +21 -0
- package/dist/lib/browser/Ref.mjs.map +7 -0
- package/dist/lib/browser/Relation.mjs +33 -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 +25 -0
- package/dist/lib/browser/Tag.mjs.map +7 -0
- package/dist/lib/browser/Type.mjs +38 -0
- package/dist/lib/browser/Type.mjs.map +7 -0
- package/dist/lib/browser/chunk-3B2G6BW4.mjs +74 -0
- package/dist/lib/browser/chunk-3B2G6BW4.mjs.map +7 -0
- package/dist/lib/browser/chunk-5IN7XBIQ.mjs +24 -0
- package/dist/lib/browser/chunk-5IN7XBIQ.mjs.map +7 -0
- package/dist/lib/browser/chunk-6XVZF5VJ.mjs +2924 -0
- package/dist/lib/browser/chunk-6XVZF5VJ.mjs.map +7 -0
- package/dist/lib/browser/chunk-AGOWBKY6.mjs +94 -0
- package/dist/lib/browser/chunk-AGOWBKY6.mjs.map +7 -0
- package/dist/lib/browser/chunk-BD6MRI4M.mjs +113 -0
- package/dist/lib/browser/chunk-BD6MRI4M.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-DOPKE2FQ.mjs +32 -0
- package/dist/lib/browser/chunk-DOPKE2FQ.mjs.map +7 -0
- package/dist/lib/browser/chunk-ESLW4N7S.mjs +41 -0
- package/dist/lib/browser/chunk-ESLW4N7S.mjs.map +7 -0
- package/dist/lib/browser/chunk-F4YF6C3O.mjs +363 -0
- package/dist/lib/browser/chunk-F4YF6C3O.mjs.map +7 -0
- package/dist/lib/browser/chunk-FGFQWIZE.mjs +9 -0
- package/dist/lib/browser/chunk-FGFQWIZE.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-JG4GH6LN.mjs +9 -0
- package/dist/lib/browser/chunk-JG4GH6LN.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-NFH3POTD.mjs +37 -0
- package/dist/lib/browser/chunk-NFH3POTD.mjs.map +7 -0
- package/dist/lib/browser/chunk-O6FOICWT.mjs +57 -0
- package/dist/lib/browser/chunk-O6FOICWT.mjs.map +7 -0
- package/dist/lib/browser/chunk-P2B4BASR.mjs +288 -0
- package/dist/lib/browser/chunk-P2B4BASR.mjs.map +7 -0
- package/dist/lib/browser/chunk-QHC3ZYNC.mjs +152 -0
- package/dist/lib/browser/chunk-QHC3ZYNC.mjs.map +7 -0
- package/dist/lib/browser/chunk-QU7PWSZD.mjs +62 -0
- package/dist/lib/browser/chunk-QU7PWSZD.mjs.map +7 -0
- package/dist/lib/browser/chunk-RP4JV7FD.mjs +403 -0
- package/dist/lib/browser/chunk-RP4JV7FD.mjs.map +7 -0
- package/dist/lib/browser/chunk-V7TON6BX.mjs +151 -0
- package/dist/lib/browser/chunk-V7TON6BX.mjs.map +7 -0
- package/dist/lib/browser/chunk-WABSVOOX.mjs +303 -0
- package/dist/lib/browser/chunk-WABSVOOX.mjs.map +7 -0
- package/dist/lib/browser/chunk-XRHHSMHJ.mjs +39 -0
- package/dist/lib/browser/chunk-XRHHSMHJ.mjs.map +7 -0
- package/dist/lib/browser/chunk-ZIM3Y4ZK.mjs +38 -0
- package/dist/lib/browser/chunk-ZIM3Y4ZK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +72 -9
- package/dist/lib/browser/internal/index.mjs +347 -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 +322 -32
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/Annotation.mjs +31 -0
- package/dist/lib/node-esm/Annotation.mjs.map +7 -0
- package/dist/lib/node-esm/Database.mjs +14 -0
- package/dist/lib/node-esm/Database.mjs.map +7 -0
- package/dist/lib/node-esm/Entity.mjs +20 -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 +60 -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 +18 -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 +83 -0
- package/dist/lib/node-esm/Obj.mjs.map +7 -0
- package/dist/lib/node-esm/Order.mjs +11 -0
- package/dist/lib/node-esm/Order.mjs.map +7 -0
- package/dist/lib/node-esm/Query.mjs +25 -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 +21 -0
- package/dist/lib/node-esm/Ref.mjs.map +7 -0
- package/dist/lib/node-esm/Relation.mjs +33 -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 +25 -0
- package/dist/lib/node-esm/Tag.mjs.map +7 -0
- package/dist/lib/node-esm/Type.mjs +38 -0
- package/dist/lib/node-esm/Type.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-5M5P2DCR.mjs +32 -0
- package/dist/lib/node-esm/chunk-5M5P2DCR.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-6OTQZKHX.mjs +303 -0
- package/dist/lib/node-esm/chunk-6OTQZKHX.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-76LEDWHO.mjs +152 -0
- package/dist/lib/node-esm/chunk-76LEDWHO.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-AGHZH33D.mjs +9 -0
- package/dist/lib/node-esm/chunk-AGHZH33D.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-BJACR7QG.mjs +363 -0
- package/dist/lib/node-esm/chunk-BJACR7QG.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-BYL2NPEA.mjs +37 -0
- package/dist/lib/node-esm/chunk-BYL2NPEA.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CCMFPJUT.mjs +74 -0
- package/dist/lib/node-esm/chunk-CCMFPJUT.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-D5BW7KHR.mjs +39 -0
- package/dist/lib/node-esm/chunk-D5BW7KHR.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-DJX53IQ3.mjs +2924 -0
- package/dist/lib/node-esm/chunk-DJX53IQ3.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-FWTPV5QD.mjs +94 -0
- package/dist/lib/node-esm/chunk-FWTPV5QD.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HLUDHPFO.mjs +403 -0
- package/dist/lib/node-esm/chunk-HLUDHPFO.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-JYZSF62S.mjs +113 -0
- package/dist/lib/node-esm/chunk-JYZSF62S.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-KUX5JEL2.mjs +57 -0
- package/dist/lib/node-esm/chunk-KUX5JEL2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-LDXRA5TC.mjs +288 -0
- package/dist/lib/node-esm/chunk-LDXRA5TC.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-NHYOREKX.mjs +62 -0
- package/dist/lib/node-esm/chunk-NHYOREKX.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QVZZHCDS.mjs +9 -0
- package/dist/lib/node-esm/chunk-QVZZHCDS.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-W3OLV7MG.mjs +41 -0
- package/dist/lib/node-esm/chunk-W3OLV7MG.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-W5AQXKVF.mjs +38 -0
- package/dist/lib/node-esm/chunk-W5AQXKVF.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YNBFXTDG.mjs +24 -0
- package/dist/lib/node-esm/chunk-YNBFXTDG.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-Z53QIBP2.mjs +151 -0
- package/dist/lib/node-esm/chunk-Z53QIBP2.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +72 -9
- package/dist/lib/node-esm/internal/index.mjs +347 -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 +322 -32
- 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 +179 -0
- package/dist/types/src/Database.d.ts.map +1 -0
- package/dist/types/src/Entity.d.ts +36 -0
- package/dist/types/src/Entity.d.ts.map +1 -0
- package/dist/types/src/Err.d.ts +68 -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 +152 -35
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Order.d.ts +11 -0
- package/dist/types/src/Order.d.ts.map +1 -0
- package/dist/types/src/Query.d.ts +107 -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 +84 -0
- package/dist/types/src/QueryResult.d.ts.map +1 -0
- package/dist/types/src/Ref.d.ts +12 -10
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +20 -14
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/SchemaRegistry.d.ts +73 -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 +39 -50
- package/dist/types/src/Type.d.ts.map +1 -1
- 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 +179 -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/entities/entity.d.ts +10 -0
- package/dist/types/src/internal/entities/entity.d.ts.map +1 -0
- package/dist/types/src/internal/entities/expando.d.ts +16 -0
- package/dist/types/src/internal/entities/expando.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 +70 -0
- package/dist/types/src/internal/entities/model.d.ts.map +1 -0
- package/dist/types/src/internal/entities/object.d.ts +11 -0
- package/dist/types/src/internal/entities/object.d.ts.map +1 -0
- package/dist/types/src/internal/entities/relation.d.ts +55 -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 +11 -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/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 +8 -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 +31 -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 +15 -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/typed-object.d.ts +31 -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/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 +3 -0
- package/dist/types/src/internal/proxy/index.d.ts.map +1 -0
- package/dist/types/src/internal/proxy/make-object.d.ts +16 -0
- package/dist/types/src/internal/proxy/make-object.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/typed-handler.d.ts +44 -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 +209 -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 +168 -0
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -0
- package/dist/types/src/internal/schema/index.d.ts +5 -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 +18 -0
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -0
- package/dist/types/src/internal/schema/snapshot.d.ts +6 -0
- package/dist/types/src/internal/schema/snapshot.d.ts.map +1 -0
- package/dist/types/src/internal/types/base.d.ts +37 -0
- package/dist/types/src/internal/types/base.d.ts.map +1 -0
- package/dist/types/src/internal/types/entity.d.ts +12 -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 +40 -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 +407 -0
- package/dist/types/src/testing/test-schema.d.ts.map +1 -0
- package/dist/types/src/testing/util.d.ts +16 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +164 -33
- package/src/Annotation.ts +17 -0
- package/src/Database.ts +308 -0
- package/src/Entity.ts +51 -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.ts +407 -71
- package/src/Order.ts +34 -0
- package/src/Query.test.ts +346 -0
- package/src/Query.ts +279 -0
- package/src/QueryResult.ts +109 -0
- package/src/Ref.ts +25 -9
- package/src/Relation.ts +72 -46
- package/src/SchemaRegistry.ts +92 -0
- package/src/Tag.ts +40 -0
- package/src/Type.ts +98 -84
- package/src/index.ts +17 -4
- package/src/internal/README.md +87 -0
- package/src/internal/annotations/annotations.test.ts +96 -0
- package/src/internal/annotations/annotations.ts +488 -0
- package/src/internal/annotations/index.ts +6 -0
- package/src/internal/annotations/util.ts +72 -0
- package/src/internal/entities/entity.ts +109 -0
- package/src/internal/entities/expando.ts +23 -0
- package/src/internal/entities/index.ts +9 -0
- package/src/internal/entities/model.ts +129 -0
- package/src/internal/entities/object.ts +45 -0
- package/src/internal/entities/relation.ts +155 -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 +38 -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/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 +11 -0
- package/src/internal/object/inspect.ts +46 -0
- package/src/internal/object/json-serializer.test.ts +94 -0
- package/src/internal/object/json-serializer.ts +230 -0
- package/src/internal/object/schema-validator.test.ts +186 -0
- package/src/internal/object/schema-validator.ts +244 -0
- package/src/internal/object/typed-object.test.ts +34 -0
- package/src/internal/object/typed-object.ts +94 -0
- package/src/internal/proxy/handler.test.ts +173 -0
- package/src/internal/proxy/index.ts +6 -0
- package/src/internal/proxy/make-object.ts +113 -0
- package/src/internal/proxy/schema.test.ts +137 -0
- package/src/internal/proxy/typed-handler.test.ts +102 -0
- package/src/internal/proxy/typed-handler.ts +233 -0
- package/src/internal/proxy/typed-object.test.ts +105 -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 +525 -0
- package/src/internal/schema/compose.test.ts +42 -0
- package/src/internal/schema/compose.ts +37 -0
- package/src/internal/schema/echo-schema.ts +385 -0
- package/src/internal/schema/index.ts +8 -0
- package/src/internal/schema/manipulation.ts +92 -0
- package/src/internal/schema/persistent-schema.ts +28 -0
- package/src/internal/schema/snapshot.ts +25 -0
- package/src/internal/types/base.ts +57 -0
- package/src/internal/types/entity.ts +23 -0
- package/src/internal/types/index.ts +9 -0
- package/src/internal/types/meta.ts +76 -0
- package/src/internal/types/typename.ts +45 -0
- package/src/internal/types/version.ts +20 -0
- package/src/testing/api.test.ts +100 -0
- package/src/testing/index.ts +3 -1
- package/src/testing/test-data.ts +130 -0
- package/src/testing/test-schema.ts +224 -0
- package/src/testing/util.ts +78 -0
- package/dist/lib/browser/chunk-EUA7CM23.mjs +0 -619
- package/dist/lib/browser/chunk-EUA7CM23.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-IV6BWGHK.mjs +0 -619
- package/dist/lib/node-esm/chunk-IV6BWGHK.mjs.map +0 -7
- package/dist/types/src/experimental/database.d.ts +0 -8
- package/dist/types/src/experimental/database.d.ts.map +0 -1
- package/dist/types/src/experimental/index.d.ts +0 -1
- package/dist/types/src/experimental/index.d.ts.map +0 -1
- package/dist/types/src/experimental/queue.d.ts +0 -8
- package/dist/types/src/experimental/queue.d.ts.map +0 -1
- package/dist/types/src/experimental/space.d.ts +0 -8
- package/dist/types/src/experimental/space.d.ts.map +0 -1
- package/dist/types/src/query/dsl.d.ts +0 -218
- package/dist/types/src/query/dsl.d.ts.map +0 -1
- package/dist/types/src/query/dsl.test.d.ts +0 -2
- package/dist/types/src/query/dsl.test.d.ts.map +0 -1
- package/dist/types/src/query/index.d.ts +0 -2
- package/dist/types/src/query/index.d.ts.map +0 -1
- package/dist/types/src/testing/types.d.ts +0 -113
- package/dist/types/src/testing/types.d.ts.map +0 -1
- package/src/experimental/database.ts +0 -11
- package/src/experimental/index.ts +0 -7
- package/src/experimental/queue.ts +0 -11
- package/src/experimental/space.ts +0 -11
- package/src/query/dsl.test.ts +0 -323
- package/src/query/dsl.ts +0 -646
- package/src/query/index.ts +0 -5
- package/src/test/api.test.ts +0 -173
- package/src/testing/types.ts +0 -91
- /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { getDeep } from '@dxos/util';
|
|
9
|
+
|
|
10
|
+
import { SchemaValidator } from './schema-validator';
|
|
11
|
+
|
|
12
|
+
describe('schema-validator', () => {
|
|
13
|
+
describe('validateSchema', () => {
|
|
14
|
+
test('throws on ambiguous discriminated type union', () => {
|
|
15
|
+
const TestSchema = Schema.Struct({
|
|
16
|
+
union: Schema.Union(Schema.Struct({ a: Schema.Number }), Schema.Struct({ b: Schema.String })),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(() => SchemaValidator.validateSchema(TestSchema)).to.throw();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('hasPropertyAnnotation', () => {
|
|
24
|
+
test('has annotation', () => {
|
|
25
|
+
const annotationId = Symbol('foo');
|
|
26
|
+
const annotationValue = 'bar';
|
|
27
|
+
const TestSchema: Schema.Schema.AnyNoContext = Schema.Struct({
|
|
28
|
+
name: Schema.String.annotations({ [annotationId]: annotationValue }),
|
|
29
|
+
parent: Schema.optional(Schema.suspend(() => TestSchema.annotations({ [annotationId]: annotationValue }))),
|
|
30
|
+
friends: Schema.suspend(() =>
|
|
31
|
+
Schema.mutable(Schema.Array(TestSchema.annotations({ [annotationId]: annotationValue }))),
|
|
32
|
+
),
|
|
33
|
+
});
|
|
34
|
+
expect(SchemaValidator.hasTypeAnnotation(TestSchema, 'name', annotationId)).to.be.true;
|
|
35
|
+
expect(SchemaValidator.hasTypeAnnotation(TestSchema, 'parent', annotationId)).to.be.true;
|
|
36
|
+
expect(SchemaValidator.hasTypeAnnotation(TestSchema, 'friends', annotationId)).to.be.true;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('no annotation', () => {
|
|
40
|
+
const annotationId = Symbol('foo');
|
|
41
|
+
const Person: Schema.Schema.AnyNoContext = Schema.Struct({
|
|
42
|
+
name: Schema.String,
|
|
43
|
+
parent: Schema.optional(Schema.suspend(() => Person)),
|
|
44
|
+
friends: Schema.suspend(() => Schema.mutable(Schema.Array(Person))),
|
|
45
|
+
});
|
|
46
|
+
expect(SchemaValidator.hasTypeAnnotation(Person, 'name', annotationId)).to.be.false;
|
|
47
|
+
expect(SchemaValidator.hasTypeAnnotation(Person, 'parent', annotationId)).to.be.false;
|
|
48
|
+
expect(SchemaValidator.hasTypeAnnotation(Person, 'friends', annotationId)).to.be.false;
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('getPropertySchema', () => {
|
|
53
|
+
const validateValueToAssign = (args: {
|
|
54
|
+
schema: Schema.Schema.AnyNoContext;
|
|
55
|
+
target: any;
|
|
56
|
+
path: string[];
|
|
57
|
+
valueToAssign: any;
|
|
58
|
+
expectToThrow?: boolean;
|
|
59
|
+
}) => {
|
|
60
|
+
const expectation = expect(() => {
|
|
61
|
+
const nestedSchema = SchemaValidator.getPropertySchema(args.schema, args.path, (path) => {
|
|
62
|
+
return getDeep(args.target, path);
|
|
63
|
+
});
|
|
64
|
+
Schema.validateSync(nestedSchema)(args.valueToAssign);
|
|
65
|
+
});
|
|
66
|
+
if (args.expectToThrow) {
|
|
67
|
+
expectation.to.throw();
|
|
68
|
+
} else {
|
|
69
|
+
expectation.not.to.throw();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
test('basic', () => {
|
|
74
|
+
for (const value of [42, '42']) {
|
|
75
|
+
validateValueToAssign({
|
|
76
|
+
schema: Schema.Struct({ object: Schema.Struct({ field: Schema.Number }) }),
|
|
77
|
+
target: {},
|
|
78
|
+
path: ['object', 'field'],
|
|
79
|
+
valueToAssign: value,
|
|
80
|
+
expectToThrow: typeof value !== 'number',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('preserves annotations', () => {
|
|
86
|
+
const annotationId = Symbol('foo');
|
|
87
|
+
const annotationValue = 'bar';
|
|
88
|
+
const Person: Schema.Schema.AnyNoContext = Schema.Struct({
|
|
89
|
+
parent: Schema.optional(Schema.suspend(() => Person.annotations({ [annotationId]: annotationValue }))),
|
|
90
|
+
friends: Schema.suspend(() =>
|
|
91
|
+
Schema.mutable(Schema.Array(Person.annotations({ [annotationId]: annotationValue }))),
|
|
92
|
+
),
|
|
93
|
+
});
|
|
94
|
+
expect(SchemaValidator.getPropertySchema(Person, ['parent']).ast.annotations[annotationId]).to.eq(
|
|
95
|
+
annotationValue,
|
|
96
|
+
);
|
|
97
|
+
expect(SchemaValidator.getPropertySchema(Person, ['friends', '0']).ast.annotations[annotationId]).to.eq(
|
|
98
|
+
annotationValue,
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('discriminated union', () => {
|
|
103
|
+
const square = Schema.Struct({ type: Schema.Literal('square'), side: Schema.Number });
|
|
104
|
+
const circle = Schema.Struct({ type: Schema.Literal('circle'), radius: Schema.Number });
|
|
105
|
+
const shape = Schema.Union(square, circle);
|
|
106
|
+
validateValueToAssign({
|
|
107
|
+
schema: shape,
|
|
108
|
+
target: { type: 'square' },
|
|
109
|
+
path: ['side'],
|
|
110
|
+
valueToAssign: 1,
|
|
111
|
+
});
|
|
112
|
+
validateValueToAssign({
|
|
113
|
+
schema: shape,
|
|
114
|
+
target: { type: 'circle' },
|
|
115
|
+
path: ['side'],
|
|
116
|
+
valueToAssign: 1,
|
|
117
|
+
expectToThrow: true,
|
|
118
|
+
});
|
|
119
|
+
validateValueToAssign({
|
|
120
|
+
schema: shape,
|
|
121
|
+
target: { type: 'square' },
|
|
122
|
+
path: ['radius'],
|
|
123
|
+
valueToAssign: 1,
|
|
124
|
+
expectToThrow: true,
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('any', () => {
|
|
129
|
+
validateValueToAssign({
|
|
130
|
+
schema: Schema.Any,
|
|
131
|
+
target: { field: { nested: { value: Schema.Number } } },
|
|
132
|
+
path: ['field', 'nested'],
|
|
133
|
+
valueToAssign: { any: 'value' },
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
test('index signatures', () => {
|
|
137
|
+
for (const value of [42, '42']) {
|
|
138
|
+
validateValueToAssign({
|
|
139
|
+
schema: Schema.Struct({ field: Schema.String }, { key: Schema.String, value: Schema.Number }),
|
|
140
|
+
target: {},
|
|
141
|
+
path: ['unknownField'],
|
|
142
|
+
valueToAssign: value,
|
|
143
|
+
expectToThrow: typeof value !== 'number',
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('index signature from optional record', () => {
|
|
149
|
+
for (const value of [42, '42']) {
|
|
150
|
+
validateValueToAssign({
|
|
151
|
+
schema: Schema.Struct({
|
|
152
|
+
field: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Number })),
|
|
153
|
+
}),
|
|
154
|
+
target: {},
|
|
155
|
+
path: ['field', 'unknownField'],
|
|
156
|
+
valueToAssign: value,
|
|
157
|
+
expectToThrow: typeof value !== 'number',
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('suspend', () => {
|
|
163
|
+
const schemaWithSuspend = Schema.Struct({
|
|
164
|
+
array: Schema.optional(Schema.suspend(() => Schema.Array(Schema.Union(Schema.Null, Schema.Number)))),
|
|
165
|
+
object: Schema.optional(
|
|
166
|
+
Schema.suspend(() => Schema.Union(Schema.Null, Schema.Struct({ field: Schema.Number }))),
|
|
167
|
+
),
|
|
168
|
+
});
|
|
169
|
+
const target: any = { array: [1, 2, null], object: { field: 3 } };
|
|
170
|
+
for (const value of [42, '42']) {
|
|
171
|
+
for (const path of [
|
|
172
|
+
['array', '0'],
|
|
173
|
+
['object', 'field'],
|
|
174
|
+
]) {
|
|
175
|
+
validateValueToAssign({
|
|
176
|
+
schema: schemaWithSuspend,
|
|
177
|
+
target,
|
|
178
|
+
path,
|
|
179
|
+
valueToAssign: value,
|
|
180
|
+
expectToThrow: typeof value !== 'number',
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
import { log } from '@dxos/log';
|
|
10
|
+
|
|
11
|
+
import { SchemaId } from '../types';
|
|
12
|
+
|
|
13
|
+
// TODO(burdon): Reconcile with @dxos/effect visit().
|
|
14
|
+
|
|
15
|
+
export class SchemaValidator {
|
|
16
|
+
/**
|
|
17
|
+
* Recursively check that schema specifies constructions we can handle.
|
|
18
|
+
* Validates there are no ambiguous discriminated union types.
|
|
19
|
+
*/
|
|
20
|
+
public static validateSchema(schema: Schema.Schema.AnyNoContext): void {
|
|
21
|
+
const visitAll = (nodes: SchemaAST.AST[]) => nodes.forEach((node) => this.validateSchema(Schema.make(node)));
|
|
22
|
+
if (SchemaAST.isUnion(schema.ast)) {
|
|
23
|
+
const typeAstList = schema.ast.types.filter((type) => SchemaAST.isTypeLiteral(type)) as SchemaAST.TypeLiteral[];
|
|
24
|
+
// Check we can handle a discriminated union.
|
|
25
|
+
if (typeAstList.length > 1) {
|
|
26
|
+
getTypeDiscriminators(typeAstList);
|
|
27
|
+
}
|
|
28
|
+
visitAll(typeAstList);
|
|
29
|
+
} else if (SchemaAST.isTupleType(schema.ast)) {
|
|
30
|
+
const positionalTypes = schema.ast.elements.map((t) => t.type);
|
|
31
|
+
const allTypes = positionalTypes.concat(schema.ast.rest.map((t) => t.type));
|
|
32
|
+
visitAll(allTypes);
|
|
33
|
+
} else if (SchemaAST.isTypeLiteral(schema.ast)) {
|
|
34
|
+
visitAll(SchemaAST.getPropertySignatures(schema.ast).map((p) => p.type));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public static hasTypeAnnotation(
|
|
39
|
+
rootObjectSchema: Schema.Schema.AnyNoContext,
|
|
40
|
+
property: string,
|
|
41
|
+
annotation: symbol,
|
|
42
|
+
): boolean {
|
|
43
|
+
try {
|
|
44
|
+
let type = this.getPropertySchema(rootObjectSchema, [property]);
|
|
45
|
+
if (SchemaAST.isTupleType(type.ast)) {
|
|
46
|
+
type = this.getPropertySchema(rootObjectSchema, [property, '0']);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return type.ast.annotations[annotation] != null;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public static getPropertySchema(
|
|
56
|
+
rootObjectSchema: Schema.Schema.AnyNoContext,
|
|
57
|
+
propertyPath: KeyPath,
|
|
58
|
+
getProperty: (path: KeyPath) => any = () => null,
|
|
59
|
+
): Schema.Schema.AnyNoContext {
|
|
60
|
+
let schema: Schema.Schema.AnyNoContext = rootObjectSchema;
|
|
61
|
+
for (let i = 0; i < propertyPath.length; i++) {
|
|
62
|
+
const propertyName = propertyPath[i];
|
|
63
|
+
const tupleAst = unwrapArray(schema.ast);
|
|
64
|
+
if (tupleAst != null) {
|
|
65
|
+
schema = getArrayElementSchema(tupleAst, propertyName);
|
|
66
|
+
} else {
|
|
67
|
+
const propertyType = getPropertyType(schema.ast, propertyName.toString(), (propertyName) =>
|
|
68
|
+
getProperty([...propertyPath.slice(0, i), propertyName]),
|
|
69
|
+
);
|
|
70
|
+
if (propertyType == null) {
|
|
71
|
+
log.warn('unknown property', { path: propertyPath, property: propertyName });
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
schema = Schema.make(propertyType).annotations(propertyType.annotations);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return schema;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public static getTargetPropertySchema(target: any, prop: string | symbol): Schema.Schema.AnyNoContext {
|
|
83
|
+
const schema: Schema.Schema.AnyNoContext | undefined = (target as any)[SchemaId];
|
|
84
|
+
invariant(schema, 'target has no schema');
|
|
85
|
+
const arrayAst = unwrapArray(schema.ast);
|
|
86
|
+
if (arrayAst != null) {
|
|
87
|
+
return getArrayElementSchema(arrayAst, prop);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const propertyType = getPropertyType(schema.ast, prop.toString(), (prop) => target[prop]);
|
|
91
|
+
if (propertyType == null) {
|
|
92
|
+
return Schema.Any; // TODO(burdon): HACK.
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
invariant(propertyType, `invalid property: ${prop.toString()}`);
|
|
96
|
+
return Schema.make(propertyType);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Tuple AST is used both for:
|
|
102
|
+
* fixed-length tuples ([string, number]) in which case AST will be { elements: [Schema.String, Schema.Number] }
|
|
103
|
+
* variable-length arrays (Array<string | number>) in which case AST will be { rest: [Schema.Union(Schema.String, Schema.Number)] }
|
|
104
|
+
*/
|
|
105
|
+
const getArrayElementSchema = (
|
|
106
|
+
tupleAst: SchemaAST.TupleType,
|
|
107
|
+
property: string | symbol | number,
|
|
108
|
+
): Schema.Schema.AnyNoContext => {
|
|
109
|
+
const elementIndex = typeof property === 'string' ? parseInt(property, 10) : Number.NaN;
|
|
110
|
+
if (Number.isNaN(elementIndex)) {
|
|
111
|
+
invariant(property === 'length', `invalid array property: ${String(property)}`);
|
|
112
|
+
return Schema.Number;
|
|
113
|
+
}
|
|
114
|
+
if (elementIndex < tupleAst.elements.length) {
|
|
115
|
+
const elementType = tupleAst.elements[elementIndex].type;
|
|
116
|
+
return Schema.make(elementType).annotations(elementType.annotations);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const restType = tupleAst.rest;
|
|
120
|
+
return Schema.make(restType[0].type).annotations(restType[0].annotations);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const flattenUnion = (typeAst: SchemaAST.AST): SchemaAST.AST[] =>
|
|
124
|
+
SchemaAST.isUnion(typeAst) ? typeAst.types.flatMap(flattenUnion) : [typeAst];
|
|
125
|
+
|
|
126
|
+
const getProperties = (
|
|
127
|
+
typeAst: SchemaAST.AST,
|
|
128
|
+
getTargetPropertyFn: (propertyName: string) => any,
|
|
129
|
+
): SchemaAST.PropertySignature[] => {
|
|
130
|
+
const astCandidates = flattenUnion(typeAst);
|
|
131
|
+
const typeAstList = astCandidates.filter((type) => SchemaAST.isTypeLiteral(type)) as SchemaAST.TypeLiteral[];
|
|
132
|
+
if (typeAstList.length === 0) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
if (typeAstList.length === 1) {
|
|
136
|
+
return SchemaAST.getPropertySignatures(typeAstList[0]);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const typeDiscriminators = getTypeDiscriminators(typeAstList);
|
|
140
|
+
const targetPropertyValue = getTargetPropertyFn(String(typeDiscriminators[0].name));
|
|
141
|
+
const typeIndex = typeDiscriminators.findIndex((p) => targetPropertyValue === (p.type as SchemaAST.Literal).literal);
|
|
142
|
+
invariant(typeIndex !== -1, 'discriminator field not set on target');
|
|
143
|
+
return SchemaAST.getPropertySignatures(typeAstList[typeIndex]);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const getPropertyType = (
|
|
147
|
+
ast: SchemaAST.AST,
|
|
148
|
+
propertyName: string,
|
|
149
|
+
getTargetPropertyFn: (propertyName: string) => any,
|
|
150
|
+
): SchemaAST.AST | null => {
|
|
151
|
+
const anyOrObject = unwrapAst(
|
|
152
|
+
ast,
|
|
153
|
+
(candidate) => SchemaAST.isAnyKeyword(candidate) || SchemaAST.isObjectKeyword(candidate),
|
|
154
|
+
);
|
|
155
|
+
if (anyOrObject != null) {
|
|
156
|
+
return ast;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const typeOrDiscriminatedUnion = unwrapAst(ast, (t) => {
|
|
160
|
+
return SchemaAST.isTypeLiteral(t) || (SchemaAST.isUnion(t) && t.types.some((t) => SchemaAST.isTypeLiteral(t)));
|
|
161
|
+
});
|
|
162
|
+
if (typeOrDiscriminatedUnion == null) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const targetProperty = getProperties(typeOrDiscriminatedUnion, getTargetPropertyFn).find(
|
|
167
|
+
(p) => p.name === propertyName,
|
|
168
|
+
);
|
|
169
|
+
if (targetProperty != null) {
|
|
170
|
+
return unwrapAst(targetProperty.type);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const indexSignatureType = unwrapAst(ast, SchemaAST.isTypeLiteral);
|
|
174
|
+
if (
|
|
175
|
+
indexSignatureType &&
|
|
176
|
+
SchemaAST.isTypeLiteral(indexSignatureType) &&
|
|
177
|
+
indexSignatureType.indexSignatures.length > 0
|
|
178
|
+
) {
|
|
179
|
+
return unwrapAst(indexSignatureType.indexSignatures[0].type);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return null;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const getTypeDiscriminators = (typeAstList: SchemaAST.TypeLiteral[]): SchemaAST.PropertySignature[] => {
|
|
186
|
+
const discriminatorPropCandidates = typeAstList
|
|
187
|
+
.flatMap(SchemaAST.getPropertySignatures)
|
|
188
|
+
.filter((p) => SchemaAST.isLiteral(p.type));
|
|
189
|
+
const propertyName = discriminatorPropCandidates[0].name;
|
|
190
|
+
const isValidDiscriminator = discriminatorPropCandidates.every((p) => p.name === propertyName && !p.isOptional);
|
|
191
|
+
const everyTypeHasDiscriminator = discriminatorPropCandidates.length === typeAstList.length;
|
|
192
|
+
const isDiscriminatedUnion = isValidDiscriminator && everyTypeHasDiscriminator;
|
|
193
|
+
invariant(isDiscriminatedUnion, 'type ambiguity: every type in a union must have a single unique-literal field');
|
|
194
|
+
return discriminatorPropCandidates;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Used to check that rootAst is for a type matching the provided predicate.
|
|
199
|
+
* That's not always straightforward because types of optionality and recursive types.
|
|
200
|
+
* const Task = Schema.Struct({
|
|
201
|
+
* ...,
|
|
202
|
+
* previous?: Schema.optional(Schema.suspend(() => Task)),
|
|
203
|
+
* });
|
|
204
|
+
* Here the AST for `previous` field is going to be Union(Suspend(Type), Undefined).
|
|
205
|
+
* SchemaAST.isTypeLiteral(field) will return false, but unwrapAst(field, (ast) => SchemaAST.isTypeLiteral(ast))
|
|
206
|
+
* will return true.
|
|
207
|
+
*/
|
|
208
|
+
const unwrapAst = (rootAst: SchemaAST.AST, predicate?: (ast: SchemaAST.AST) => boolean): SchemaAST.AST | null => {
|
|
209
|
+
let ast: SchemaAST.AST | undefined = rootAst;
|
|
210
|
+
while (ast != null) {
|
|
211
|
+
if (predicate?.(ast)) {
|
|
212
|
+
return ast;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (SchemaAST.isUnion(ast)) {
|
|
216
|
+
const next: any = ast.types.find((t) => (predicate != null && predicate(t)) || SchemaAST.isSuspend(t));
|
|
217
|
+
if (next != null) {
|
|
218
|
+
ast = next;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (SchemaAST.isSuspend(ast)) {
|
|
224
|
+
ast = ast.f();
|
|
225
|
+
} else {
|
|
226
|
+
return predicate == null ? ast : null;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return null;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const unwrapArray = (ast: SchemaAST.AST) => unwrapAst(ast, SchemaAST.isTupleType) as SchemaAST.TupleType | null;
|
|
234
|
+
|
|
235
|
+
export const checkIdNotPresentOnSchema = (schema: Schema.Schema<any, any, any>) => {
|
|
236
|
+
invariant(SchemaAST.isTypeLiteral(schema.ast));
|
|
237
|
+
const idProperty = SchemaAST.getPropertySignatures(schema.ast).find((prop) => prop.name === 'id');
|
|
238
|
+
if (idProperty != null) {
|
|
239
|
+
throw new Error('"id" property name is reserved');
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// TODO(burdon): Reconcile with JsonPath.
|
|
244
|
+
type KeyPath = readonly (string | number)[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
import { describe, expect, test } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { TypedObject } from './typed-object';
|
|
10
|
+
|
|
11
|
+
class Organization extends TypedObject({
|
|
12
|
+
typename: 'example.com/type/Organization',
|
|
13
|
+
version: '0.1.0',
|
|
14
|
+
})({
|
|
15
|
+
name: Schema.String,
|
|
16
|
+
}) {}
|
|
17
|
+
|
|
18
|
+
describe('EchoObjectSchema class DSL', () => {
|
|
19
|
+
test('type is a valid schema', async () => {
|
|
20
|
+
expect(Schema.isSchema(Organization)).to.be.true;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('static typename accessor', async () => {
|
|
24
|
+
expect(Organization.typename).to.eq('example.com/type/Organization');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('expect constructor to throw', async () => {
|
|
28
|
+
expect(() => new Organization()).to.throw();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('expect schema', async () => {
|
|
32
|
+
expect(SchemaAST.isTypeLiteral(Organization.ast)).to.be.true;
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
|
+
|
|
8
|
+
import { invariant } from '@dxos/invariant';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
type TypeAnnotation,
|
|
12
|
+
TypeAnnotationId,
|
|
13
|
+
type TypeMeta,
|
|
14
|
+
TypenameSchema,
|
|
15
|
+
VersionSchema,
|
|
16
|
+
makeTypeJsonSchemaAnnotation,
|
|
17
|
+
} from '../annotations';
|
|
18
|
+
import { EntityKind, type HasId } from '../types';
|
|
19
|
+
|
|
20
|
+
import { type TypedObjectFields, type TypedObjectOptions, makeTypedEntityClass } from './common';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Definition for an object type that can be stored in an ECHO database.
|
|
24
|
+
* Implements effect schema to define object properties.
|
|
25
|
+
* Has a typename and version.
|
|
26
|
+
*
|
|
27
|
+
* In contrast to {@link EchoSchema} this definition is not recorded in the database.
|
|
28
|
+
*/
|
|
29
|
+
export interface TypedObject<A = any, I = any> extends TypeMeta, Schema.Schema<A, I> {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Typed object that could be used as a prototype in class definitions.
|
|
33
|
+
* This is an internal API type.
|
|
34
|
+
* Use {@link TypedObject} for the common use-cases.
|
|
35
|
+
*/
|
|
36
|
+
export interface TypedObjectPrototype<A = any, I = any> extends TypedObject<A, I> {
|
|
37
|
+
/** Type constructor. */
|
|
38
|
+
new (): HasId & A;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type TypedObjectProps = TypeMeta & {
|
|
42
|
+
// TODO(dmaretskyi): Remove after all legacy types has been removed.
|
|
43
|
+
disableValidation?: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Base class factory for typed objects.
|
|
48
|
+
* @deprecated Use Function.pipe(Type.Obj) instead.
|
|
49
|
+
*/
|
|
50
|
+
export const TypedObject = ({
|
|
51
|
+
typename: typenameParam,
|
|
52
|
+
version: versionParam,
|
|
53
|
+
disableValidation,
|
|
54
|
+
}: TypedObjectProps) => {
|
|
55
|
+
const typename = TypenameSchema.make(typenameParam, { disableValidation });
|
|
56
|
+
const version = VersionSchema.make(versionParam, { disableValidation });
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Return class definition factory.
|
|
60
|
+
*/
|
|
61
|
+
return <SchemaFields extends Schema.Struct.Fields, Options extends TypedObjectOptions>(
|
|
62
|
+
fields: SchemaFields,
|
|
63
|
+
options?: Options,
|
|
64
|
+
): TypedObjectPrototype<TypedObjectFields<SchemaFields, Options>, Schema.Struct.Encoded<SchemaFields>> => {
|
|
65
|
+
// Create schema from fields.
|
|
66
|
+
const schema: Schema.Schema.All = options?.record
|
|
67
|
+
? Schema.Struct(fields, { key: Schema.String, value: Schema.Any })
|
|
68
|
+
: Schema.Struct(fields);
|
|
69
|
+
|
|
70
|
+
// Set ECHO object id property.
|
|
71
|
+
const typeSchema = Schema.extend(
|
|
72
|
+
Schema.mutable(options?.partial ? Schema.partial(schema) : schema),
|
|
73
|
+
Schema.Struct({ id: Schema.String }),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// Set ECHO annotations.
|
|
77
|
+
invariant(typeof EntityKind.Object === 'string');
|
|
78
|
+
const annotatedSchema = typeSchema.annotations({
|
|
79
|
+
[TypeAnnotationId]: { kind: EntityKind.Object, typename, version } satisfies TypeAnnotation,
|
|
80
|
+
[SchemaAST.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
81
|
+
kind: EntityKind.Object,
|
|
82
|
+
typename,
|
|
83
|
+
version,
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Return class definition.
|
|
89
|
+
* NOTE: Actual reactive ECHO objects must be created via the `live(Type)` function.
|
|
90
|
+
*/
|
|
91
|
+
// TODO(burdon): This is missing fields required by TypedObject (e.g., Type, Encoded, Context)?
|
|
92
|
+
return class TypedObject extends makeTypedEntityClass(typename, version, annotatedSchema as any) {} as any;
|
|
93
|
+
};
|
|
94
|
+
};
|