@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,2924 @@
|
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
import {
|
|
3
|
+
CurrencyAnnotationId,
|
|
4
|
+
FormatAnnotation,
|
|
5
|
+
FormatAnnotationId,
|
|
6
|
+
TypeFormat
|
|
7
|
+
} from "./chunk-RP4JV7FD.mjs";
|
|
8
|
+
import {
|
|
9
|
+
ATTR_TYPE,
|
|
10
|
+
GeneratorAnnotationId,
|
|
11
|
+
LabelAnnotationId,
|
|
12
|
+
PropertyMetaAnnotationId,
|
|
13
|
+
ReferenceAnnotationId,
|
|
14
|
+
SchemaId,
|
|
15
|
+
SchemaMetaSymbol,
|
|
16
|
+
TypeAnnotationId,
|
|
17
|
+
TypeId,
|
|
18
|
+
TypeIdentifierAnnotationId,
|
|
19
|
+
TypenameSchema,
|
|
20
|
+
VersionSchema,
|
|
21
|
+
getEntityKind,
|
|
22
|
+
getSchemaDXN,
|
|
23
|
+
getSchemaTypename,
|
|
24
|
+
getTypeAnnotation,
|
|
25
|
+
getTypeDXN,
|
|
26
|
+
getTypeIdentifierAnnotation,
|
|
27
|
+
getTypename,
|
|
28
|
+
setSchema,
|
|
29
|
+
setTypename
|
|
30
|
+
} from "./chunk-WABSVOOX.mjs";
|
|
31
|
+
import {
|
|
32
|
+
EntityKind,
|
|
33
|
+
EntityKindSchema,
|
|
34
|
+
KindId,
|
|
35
|
+
makeTypeJsonSchemaAnnotation
|
|
36
|
+
} from "./chunk-QU7PWSZD.mjs";
|
|
37
|
+
|
|
38
|
+
// src/internal/index.ts
|
|
39
|
+
import { JsonPath as JsonPath2, JsonProp, getValue, setValue, splitJsonPath } from "@dxos/effect";
|
|
40
|
+
|
|
41
|
+
// src/internal/types/base.ts
|
|
42
|
+
import * as Schema from "effect/Schema";
|
|
43
|
+
import * as SchemaAST from "effect/SchemaAST";
|
|
44
|
+
var RawObject = (schema) => {
|
|
45
|
+
return Schema.make(SchemaAST.omit(schema.ast, [
|
|
46
|
+
"id"
|
|
47
|
+
]));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/internal/types/meta.ts
|
|
51
|
+
import * as Schema2 from "effect/Schema";
|
|
52
|
+
import { ForeignKey } from "@dxos/echo-protocol";
|
|
53
|
+
import { invariant } from "@dxos/invariant";
|
|
54
|
+
import { intersection } from "@dxos/util";
|
|
55
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/types/meta.ts";
|
|
56
|
+
var ATTR_META = "@meta";
|
|
57
|
+
var MetaId = Symbol.for("@dxos/echo/Meta");
|
|
58
|
+
var ObjectMetaSchema = Schema2.mutable(Schema2.Struct({
|
|
59
|
+
keys: Schema2.mutable(Schema2.Array(ForeignKey)),
|
|
60
|
+
/**
|
|
61
|
+
* A set of tags.
|
|
62
|
+
* Tags are arbitrary application-defined strings.
|
|
63
|
+
* ECHO makes no assumptions about the tag structure.
|
|
64
|
+
*/
|
|
65
|
+
// TODO(dmaretskyi): Has to be optional for compatibility with old data.
|
|
66
|
+
// Defaulting to an empty array is possible but requires a bit more work.
|
|
67
|
+
tags: Schema2.optional(Schema2.mutable(Schema2.Array(Schema2.String)))
|
|
68
|
+
}));
|
|
69
|
+
var getMeta = (obj) => {
|
|
70
|
+
const metadata = obj[MetaId];
|
|
71
|
+
invariant(metadata, "ObjectMeta not found.", {
|
|
72
|
+
F: __dxlog_file,
|
|
73
|
+
L: 53,
|
|
74
|
+
S: void 0,
|
|
75
|
+
A: [
|
|
76
|
+
"metadata",
|
|
77
|
+
"'ObjectMeta not found.'"
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
return metadata;
|
|
81
|
+
};
|
|
82
|
+
var splitMeta = (object) => {
|
|
83
|
+
const meta = object[ATTR_META];
|
|
84
|
+
delete object[ATTR_META];
|
|
85
|
+
return {
|
|
86
|
+
meta,
|
|
87
|
+
object
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
var foreignKey = (source, id) => ({
|
|
91
|
+
source,
|
|
92
|
+
id
|
|
93
|
+
});
|
|
94
|
+
var foreignKeyEquals = (a, b) => a.source === b.source && a.id === b.id;
|
|
95
|
+
var compareForeignKeys = (a, b) => intersection(getMeta(a).keys, getMeta(b).keys, foreignKeyEquals).length > 0;
|
|
96
|
+
|
|
97
|
+
// src/internal/types/version.ts
|
|
98
|
+
var VersionTypeId = Symbol.for("@dxos/echo/VersionTypeId");
|
|
99
|
+
|
|
100
|
+
// src/internal/entities/expando.ts
|
|
101
|
+
import * as Schema5 from "effect/Schema";
|
|
102
|
+
|
|
103
|
+
// src/internal/entities/object.ts
|
|
104
|
+
import * as Schema4 from "effect/Schema";
|
|
105
|
+
import * as SchemaAST2 from "effect/SchemaAST";
|
|
106
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
107
|
+
|
|
108
|
+
// src/internal/entities/entity.ts
|
|
109
|
+
import * as Schema3 from "effect/Schema";
|
|
110
|
+
var makeEchoTypeSchema = (ast, typename, version) => {
|
|
111
|
+
return class EchoObjectSchemaClass extends Schema3.make(ast) {
|
|
112
|
+
static typename = typename;
|
|
113
|
+
static version = version;
|
|
114
|
+
static annotations(annotations4) {
|
|
115
|
+
const schema = Schema3.make(ast).annotations(annotations4);
|
|
116
|
+
return makeEchoTypeSchema(
|
|
117
|
+
/* fields, */
|
|
118
|
+
schema.ast,
|
|
119
|
+
typename,
|
|
120
|
+
version
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
// static make(
|
|
124
|
+
// props: RequiredKeys<Schema.TypeLiteral.Constructor<Fields, []>> extends never
|
|
125
|
+
// ? void | Simplify<Schema.TypeLiteral.Constructor<Fields, []>>
|
|
126
|
+
// : Simplify<Schema.TypeLiteral.Constructor<Fields, []>>,
|
|
127
|
+
// options?: MakeOptions,
|
|
128
|
+
// ): Simplify<Schema.TypeLiteral.Type<Fields, []>> {
|
|
129
|
+
// const propsWithDefaults: any = _lazilyMergeDefaults(fields, { ...(props as any) });
|
|
130
|
+
// return _getDisableValidationMakeOption(options)
|
|
131
|
+
// ? propsWithDefaults
|
|
132
|
+
// : ParseResult.validateSync(this)(propsWithDefaults);
|
|
133
|
+
// }
|
|
134
|
+
static instanceOf(value) {
|
|
135
|
+
return Schema3.is(this)(value);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// src/internal/entities/object.ts
|
|
141
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/entities/object.ts";
|
|
142
|
+
var EchoObjectSchema = ({ typename, version }) => {
|
|
143
|
+
return (self) => {
|
|
144
|
+
invariant2(typeof TypeAnnotationId === "symbol", "Sanity.", {
|
|
145
|
+
F: __dxlog_file2,
|
|
146
|
+
L: 25,
|
|
147
|
+
S: void 0,
|
|
148
|
+
A: [
|
|
149
|
+
"typeof TypeAnnotationId === 'symbol'",
|
|
150
|
+
"'Sanity.'"
|
|
151
|
+
]
|
|
152
|
+
});
|
|
153
|
+
invariant2(SchemaAST2.isTypeLiteral(self.ast), "Schema must be a TypeLiteral.", {
|
|
154
|
+
F: __dxlog_file2,
|
|
155
|
+
L: 26,
|
|
156
|
+
S: void 0,
|
|
157
|
+
A: [
|
|
158
|
+
"SchemaAST.isTypeLiteral(self.ast)",
|
|
159
|
+
"'Schema must be a TypeLiteral.'"
|
|
160
|
+
]
|
|
161
|
+
});
|
|
162
|
+
const schemaWithId = Schema4.extend(Schema4.mutable(self), Schema4.Struct({
|
|
163
|
+
id: Schema4.String
|
|
164
|
+
}));
|
|
165
|
+
const ast = SchemaAST2.annotations(schemaWithId.ast, {
|
|
166
|
+
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
167
|
+
...self.ast.annotations,
|
|
168
|
+
[TypeAnnotationId]: {
|
|
169
|
+
kind: EntityKind.Object,
|
|
170
|
+
typename,
|
|
171
|
+
version
|
|
172
|
+
},
|
|
173
|
+
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
174
|
+
[SchemaAST2.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
175
|
+
kind: EntityKind.Object,
|
|
176
|
+
typename,
|
|
177
|
+
version
|
|
178
|
+
})
|
|
179
|
+
});
|
|
180
|
+
return makeEchoTypeSchema(
|
|
181
|
+
/* self.fields, */
|
|
182
|
+
ast,
|
|
183
|
+
typename,
|
|
184
|
+
version
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// src/internal/entities/expando.ts
|
|
190
|
+
var EXPANDO_TYPENAME = "dxos.org/type/Expando";
|
|
191
|
+
var ExpandoSchema = Schema5.Struct({}, {
|
|
192
|
+
key: Schema5.String,
|
|
193
|
+
value: Schema5.Any
|
|
194
|
+
}).pipe(EchoObjectSchema({
|
|
195
|
+
typename: EXPANDO_TYPENAME,
|
|
196
|
+
version: "0.1.0"
|
|
197
|
+
}));
|
|
198
|
+
var Expando = ExpandoSchema;
|
|
199
|
+
|
|
200
|
+
// src/internal/entities/model.ts
|
|
201
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
202
|
+
import { DXN as DXN2, ObjectId } from "@dxos/keys";
|
|
203
|
+
import { assumeType } from "@dxos/util";
|
|
204
|
+
|
|
205
|
+
// src/internal/entities/relation.ts
|
|
206
|
+
import * as Schema6 from "effect/Schema";
|
|
207
|
+
import * as SchemaAST3 from "effect/SchemaAST";
|
|
208
|
+
import { raise } from "@dxos/debug";
|
|
209
|
+
import { assertArgument, invariant as invariant3 } from "@dxos/invariant";
|
|
210
|
+
import { DXN } from "@dxos/keys";
|
|
211
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/entities/relation.ts";
|
|
212
|
+
var ATTR_RELATION_SOURCE = "@relationSource";
|
|
213
|
+
var RelationSourceId = Symbol.for("@dxos/echo/RelationSource");
|
|
214
|
+
var RelationSourceDXNId = Symbol.for("@dxos/echo/RelationSourceDXN");
|
|
215
|
+
var ATTR_RELATION_TARGET = "@relationTarget";
|
|
216
|
+
var RelationTargetId = Symbol.for("@dxos/echo/RelationTarget");
|
|
217
|
+
var RelationTargetDXNId = Symbol.for("@dxos/echo/RelationTargetDXN");
|
|
218
|
+
var EchoRelationSchema = ({ source, target, typename, version }) => {
|
|
219
|
+
assertArgument(Schema6.isSchema(source), "source");
|
|
220
|
+
assertArgument(Schema6.isSchema(target), "target");
|
|
221
|
+
const sourceDXN = getDXNForRelationSchemaRef(source);
|
|
222
|
+
const targetDXN = getDXNForRelationSchemaRef(target);
|
|
223
|
+
if (getEntityKind(source) !== EntityKind.Object) {
|
|
224
|
+
raise(new Error("Source schema must be an echo object schema."));
|
|
225
|
+
}
|
|
226
|
+
if (getEntityKind(target) !== EntityKind.Object) {
|
|
227
|
+
raise(new Error("Target schema must be an echo object schema."));
|
|
228
|
+
}
|
|
229
|
+
return (self) => {
|
|
230
|
+
invariant3(SchemaAST3.isTypeLiteral(self.ast), "Schema must be a TypeLiteral.", {
|
|
231
|
+
F: __dxlog_file3,
|
|
232
|
+
L: 112,
|
|
233
|
+
S: void 0,
|
|
234
|
+
A: [
|
|
235
|
+
"SchemaAST.isTypeLiteral(self.ast)",
|
|
236
|
+
"'Schema must be a TypeLiteral.'"
|
|
237
|
+
]
|
|
238
|
+
});
|
|
239
|
+
const schemaWithId = Schema6.extend(Schema6.mutable(self), Schema6.Struct({
|
|
240
|
+
id: Schema6.String
|
|
241
|
+
}));
|
|
242
|
+
const ast = SchemaAST3.annotations(schemaWithId.ast, {
|
|
243
|
+
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
244
|
+
...self.ast.annotations,
|
|
245
|
+
[TypeAnnotationId]: {
|
|
246
|
+
kind: EntityKind.Relation,
|
|
247
|
+
typename,
|
|
248
|
+
version,
|
|
249
|
+
sourceSchema: sourceDXN,
|
|
250
|
+
targetSchema: targetDXN
|
|
251
|
+
},
|
|
252
|
+
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
253
|
+
[SchemaAST3.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
254
|
+
kind: EntityKind.Relation,
|
|
255
|
+
typename,
|
|
256
|
+
version,
|
|
257
|
+
relationSource: sourceDXN,
|
|
258
|
+
relationTarget: targetDXN
|
|
259
|
+
})
|
|
260
|
+
});
|
|
261
|
+
return makeEchoTypeSchema(
|
|
262
|
+
/* self.fields, */
|
|
263
|
+
ast,
|
|
264
|
+
typename,
|
|
265
|
+
version
|
|
266
|
+
);
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
var getDXNForRelationSchemaRef = (schema) => {
|
|
270
|
+
assertArgument(Schema6.isSchema(schema), "schema");
|
|
271
|
+
const identifier = getTypeIdentifierAnnotation(schema);
|
|
272
|
+
if (identifier) {
|
|
273
|
+
return identifier;
|
|
274
|
+
}
|
|
275
|
+
const typename = getSchemaTypename(schema);
|
|
276
|
+
if (!typename) {
|
|
277
|
+
throw new Error("Schema must have a typename");
|
|
278
|
+
}
|
|
279
|
+
return DXN.fromTypename(typename).toString();
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// src/internal/entities/model.ts
|
|
283
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/entities/model.ts";
|
|
284
|
+
var ATTR_SELF_DXN = "@dxn";
|
|
285
|
+
var SelfDXNId = Symbol.for("@dxos/echo/DXN");
|
|
286
|
+
var ATTR_DELETED = "@deleted";
|
|
287
|
+
var ObjectDeletedId = Symbol.for("@dxos/echo/Deleted");
|
|
288
|
+
var ObjectVersionId = Symbol.for("@dxos/echo/Version");
|
|
289
|
+
function assertObjectModel(obj) {
|
|
290
|
+
invariant4(typeof obj === "object" && obj !== null, "Invalid object model: not an object", {
|
|
291
|
+
F: __dxlog_file4,
|
|
292
|
+
L: 114,
|
|
293
|
+
S: this,
|
|
294
|
+
A: [
|
|
295
|
+
"typeof obj === 'object' && obj !== null",
|
|
296
|
+
"'Invalid object model: not an object'"
|
|
297
|
+
]
|
|
298
|
+
});
|
|
299
|
+
assumeType(obj);
|
|
300
|
+
invariant4(ObjectId.isValid(obj.id), "Invalid object model: invalid id", {
|
|
301
|
+
F: __dxlog_file4,
|
|
302
|
+
L: 116,
|
|
303
|
+
S: this,
|
|
304
|
+
A: [
|
|
305
|
+
"ObjectId.isValid(obj.id)",
|
|
306
|
+
"'Invalid object model: invalid id'"
|
|
307
|
+
]
|
|
308
|
+
});
|
|
309
|
+
invariant4(obj[TypeId] === void 0 || obj[TypeId] instanceof DXN2, "Invalid object model: invalid type", {
|
|
310
|
+
F: __dxlog_file4,
|
|
311
|
+
L: 117,
|
|
312
|
+
S: this,
|
|
313
|
+
A: [
|
|
314
|
+
"obj[TypeId] === undefined || obj[TypeId] instanceof DXN",
|
|
315
|
+
"'Invalid object model: invalid type'"
|
|
316
|
+
]
|
|
317
|
+
});
|
|
318
|
+
invariant4(obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation, "Invalid object model: invalid entity kind", {
|
|
319
|
+
F: __dxlog_file4,
|
|
320
|
+
L: 118,
|
|
321
|
+
S: this,
|
|
322
|
+
A: [
|
|
323
|
+
"obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation",
|
|
324
|
+
"'Invalid object model: invalid entity kind'"
|
|
325
|
+
]
|
|
326
|
+
});
|
|
327
|
+
if (obj[KindId] === EntityKind.Relation) {
|
|
328
|
+
invariant4(obj[RelationSourceDXNId] instanceof DXN2, "Invalid object model: invalid relation source", {
|
|
329
|
+
F: __dxlog_file4,
|
|
330
|
+
L: 124,
|
|
331
|
+
S: this,
|
|
332
|
+
A: [
|
|
333
|
+
"obj[RelationSourceDXNId] instanceof DXN",
|
|
334
|
+
"'Invalid object model: invalid relation source'"
|
|
335
|
+
]
|
|
336
|
+
});
|
|
337
|
+
invariant4(obj[RelationTargetDXNId] instanceof DXN2, "Invalid object model: invalid relation target", {
|
|
338
|
+
F: __dxlog_file4,
|
|
339
|
+
L: 125,
|
|
340
|
+
S: this,
|
|
341
|
+
A: [
|
|
342
|
+
"obj[RelationTargetDXNId] instanceof DXN",
|
|
343
|
+
"'Invalid object model: invalid relation target'"
|
|
344
|
+
]
|
|
345
|
+
});
|
|
346
|
+
invariant4(!(obj[RelationSourceId] instanceof DXN2), "Invalid object model: source pointer is a DXN", {
|
|
347
|
+
F: __dxlog_file4,
|
|
348
|
+
L: 126,
|
|
349
|
+
S: this,
|
|
350
|
+
A: [
|
|
351
|
+
"!(obj[RelationSourceId] instanceof DXN)",
|
|
352
|
+
"'Invalid object model: source pointer is a DXN'"
|
|
353
|
+
]
|
|
354
|
+
});
|
|
355
|
+
invariant4(!(obj[RelationTargetId] instanceof DXN2), "Invalid object model: target pointer is a DXN", {
|
|
356
|
+
F: __dxlog_file4,
|
|
357
|
+
L: 127,
|
|
358
|
+
S: this,
|
|
359
|
+
A: [
|
|
360
|
+
"!(obj[RelationTargetId] instanceof DXN)",
|
|
361
|
+
"'Invalid object model: target pointer is a DXN'"
|
|
362
|
+
]
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/internal/entities/util.ts
|
|
368
|
+
import * as Schema7 from "effect/Schema";
|
|
369
|
+
import { assertArgument as assertArgument2, invariant as invariant5 } from "@dxos/invariant";
|
|
370
|
+
import { DXN as DXN3, ObjectId as ObjectId2 } from "@dxos/keys";
|
|
371
|
+
import { assumeType as assumeType2 } from "@dxos/util";
|
|
372
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/entities/util.ts";
|
|
373
|
+
var getObjectDXN = (object) => {
|
|
374
|
+
invariant5(!Schema7.isSchema(object), "schema not allowed in this function", {
|
|
375
|
+
F: __dxlog_file5,
|
|
376
|
+
L: 19,
|
|
377
|
+
S: void 0,
|
|
378
|
+
A: [
|
|
379
|
+
"!Schema.isSchema(object)",
|
|
380
|
+
"'schema not allowed in this function'"
|
|
381
|
+
]
|
|
382
|
+
});
|
|
383
|
+
assertArgument2(typeof object === "object" && object != null, "object", "expected object");
|
|
384
|
+
assumeType2(object);
|
|
385
|
+
if (object[SelfDXNId]) {
|
|
386
|
+
invariant5(object[SelfDXNId] instanceof DXN3, "Invalid object model: invalid self dxn", {
|
|
387
|
+
F: __dxlog_file5,
|
|
388
|
+
L: 24,
|
|
389
|
+
S: void 0,
|
|
390
|
+
A: [
|
|
391
|
+
"object[SelfDXNId] instanceof DXN",
|
|
392
|
+
"'Invalid object model: invalid self dxn'"
|
|
393
|
+
]
|
|
394
|
+
});
|
|
395
|
+
return object[SelfDXNId];
|
|
396
|
+
}
|
|
397
|
+
if (!ObjectId2.isValid(object.id)) {
|
|
398
|
+
throw new TypeError("Object id is not valid.");
|
|
399
|
+
}
|
|
400
|
+
return DXN3.fromLocalObjectId(object.id);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
// src/internal/json-schema/annotations.ts
|
|
404
|
+
import * as SchemaAST4 from "effect/SchemaAST";
|
|
405
|
+
var CustomAnnotations = {
|
|
406
|
+
format: FormatAnnotationId,
|
|
407
|
+
currency: CurrencyAnnotationId
|
|
408
|
+
};
|
|
409
|
+
var DecodedAnnotations = {
|
|
410
|
+
title: SchemaAST4.TitleAnnotationId,
|
|
411
|
+
description: SchemaAST4.DescriptionAnnotationId
|
|
412
|
+
};
|
|
413
|
+
var EchoAnnotations = {
|
|
414
|
+
// TODO(dmaretskyi): `FieldLookupAnnotationId` might go here, but lets remove it entirely and use LabelAnnotation instead.
|
|
415
|
+
meta: PropertyMetaAnnotationId,
|
|
416
|
+
generator: GeneratorAnnotationId,
|
|
417
|
+
labelProp: LabelAnnotationId
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
// src/internal/json-schema/json-schema-type.ts
|
|
421
|
+
import * as Schema8 from "effect/Schema";
|
|
422
|
+
import { JsonPath } from "@dxos/effect";
|
|
423
|
+
var SimpleTypes = Schema8.Literal("array", "boolean", "integer", "null", "number", "object", "string");
|
|
424
|
+
var NonNegativeInteger = Schema8.Number.pipe(Schema8.greaterThanOrEqualTo(0));
|
|
425
|
+
var StringArray = Schema8.Array(Schema8.String).pipe(Schema8.mutable);
|
|
426
|
+
var JsonSchemaOrBoolean = Schema8.Union(Schema8.suspend(() => JsonSchemaType), Schema8.Boolean);
|
|
427
|
+
var JsonSchemaEchoAnnotations = Schema8.Struct({
|
|
428
|
+
/**
|
|
429
|
+
* Label for this schema.
|
|
430
|
+
* Mapped from {@link LabelAnnotationId}.
|
|
431
|
+
*/
|
|
432
|
+
labelProp: Schema8.optional(Schema8.Union(JsonPath, Schema8.Array(JsonPath))),
|
|
433
|
+
/**
|
|
434
|
+
* Generator function for this schema.
|
|
435
|
+
* Mapped from {@link GeneratorAnnotationId}.
|
|
436
|
+
*/
|
|
437
|
+
generator: Schema8.optional(Schema8.Union(Schema8.String, Schema8.Tuple(Schema8.String, Schema8.Number))),
|
|
438
|
+
/**
|
|
439
|
+
* {@link PropertyMeta} annotations get serialized here.
|
|
440
|
+
*/
|
|
441
|
+
meta: Schema8.optional(Schema8.Record({
|
|
442
|
+
key: Schema8.String,
|
|
443
|
+
value: Schema8.Any
|
|
444
|
+
}).pipe(Schema8.mutable)),
|
|
445
|
+
/**
|
|
446
|
+
* @deprecated
|
|
447
|
+
*/
|
|
448
|
+
// TODO(dmaretskyi): We risk old schema not passing validation due to the extra fields. Remove when we are sure this is safe.
|
|
449
|
+
type: Schema8.optional(Schema8.Struct({
|
|
450
|
+
typename: Schema8.String,
|
|
451
|
+
version: Schema8.String,
|
|
452
|
+
// Not used.
|
|
453
|
+
schemaId: Schema8.optional(Schema8.String)
|
|
454
|
+
}).pipe(Schema8.mutable)),
|
|
455
|
+
/**
|
|
456
|
+
* @deprecated Superseded by `meta`.
|
|
457
|
+
*/
|
|
458
|
+
annotations: Schema8.optional(Schema8.Record({
|
|
459
|
+
key: Schema8.String,
|
|
460
|
+
value: Schema8.Any
|
|
461
|
+
}).pipe(Schema8.mutable))
|
|
462
|
+
}).pipe(Schema8.mutable);
|
|
463
|
+
var _JsonSchemaType = Schema8.Struct({
|
|
464
|
+
/**
|
|
465
|
+
* Identifier for this schema.
|
|
466
|
+
* This schema might be referenced by $ref clause in other schemas.
|
|
467
|
+
*/
|
|
468
|
+
// TODO(dmaretskyi): Specify how the ids are generated.
|
|
469
|
+
// TODO(dmaretskyi): For type dxns, should this include the version?
|
|
470
|
+
$id: Schema8.optional(Schema8.String),
|
|
471
|
+
/**
|
|
472
|
+
* Schema of this schema.
|
|
473
|
+
* Set to "https://json-schema.org/draft-07/schema".
|
|
474
|
+
*/
|
|
475
|
+
$schema: Schema8.optional(Schema8.String),
|
|
476
|
+
/**
|
|
477
|
+
* Reference to another schema.
|
|
478
|
+
*/
|
|
479
|
+
$ref: Schema8.optional(Schema8.String),
|
|
480
|
+
/**
|
|
481
|
+
* Comments are ignored when interpreting the schema.
|
|
482
|
+
*/
|
|
483
|
+
$comment: Schema8.optional(Schema8.String),
|
|
484
|
+
/**
|
|
485
|
+
* Defines whether this schema is an object schema or a relation schema.
|
|
486
|
+
*/
|
|
487
|
+
entityKind: Schema8.optional(EntityKindSchema),
|
|
488
|
+
/**
|
|
489
|
+
* Typename of this schema.
|
|
490
|
+
* Only on schema representing an ECHO object.
|
|
491
|
+
*
|
|
492
|
+
* @example 'example.com/type/MyType'
|
|
493
|
+
*/
|
|
494
|
+
typename: Schema8.optional(Schema8.String),
|
|
495
|
+
/**
|
|
496
|
+
* Version of this schema.
|
|
497
|
+
* Custom dialect for ECHO.
|
|
498
|
+
*/
|
|
499
|
+
version: Schema8.optional(Schema8.String),
|
|
500
|
+
/**
|
|
501
|
+
* Target of this relation.
|
|
502
|
+
* Only for relation schemas.
|
|
503
|
+
* The referenced schema must be an object schema.
|
|
504
|
+
*/
|
|
505
|
+
relationTarget: Schema8.optional(Schema8.suspend(() => JsonSchemaType)),
|
|
506
|
+
/**
|
|
507
|
+
* Source of this relation.
|
|
508
|
+
* Only for relation schemas.
|
|
509
|
+
* The referenced schema must be an object schema.
|
|
510
|
+
*/
|
|
511
|
+
relationSource: Schema8.optional(Schema8.suspend(() => JsonSchemaType)),
|
|
512
|
+
/**
|
|
513
|
+
* Title of this schema.
|
|
514
|
+
*/
|
|
515
|
+
title: Schema8.optional(Schema8.String),
|
|
516
|
+
/**
|
|
517
|
+
* Description of this schema.
|
|
518
|
+
*/
|
|
519
|
+
description: Schema8.optional(Schema8.String),
|
|
520
|
+
/**
|
|
521
|
+
* Whether this schema is read-only.
|
|
522
|
+
*/
|
|
523
|
+
readOnly: Schema8.optional(Schema8.Boolean),
|
|
524
|
+
/**
|
|
525
|
+
* Whether this schema is write-only.
|
|
526
|
+
*/
|
|
527
|
+
writeOnly: Schema8.optional(Schema8.Boolean),
|
|
528
|
+
/**
|
|
529
|
+
* Examples of instances of this schema.
|
|
530
|
+
*/
|
|
531
|
+
examples: Schema8.optional(Schema8.Array(Schema8.Any)),
|
|
532
|
+
/**
|
|
533
|
+
* Default value for this schema.
|
|
534
|
+
*/
|
|
535
|
+
default: Schema8.optional(Schema8.Any),
|
|
536
|
+
/**
|
|
537
|
+
* This schema only matches values that are equal to this value.
|
|
538
|
+
*/
|
|
539
|
+
const: Schema8.optional(Schema8.Any),
|
|
540
|
+
/**
|
|
541
|
+
* This schema only matches one of the values in this array.
|
|
542
|
+
*/
|
|
543
|
+
enum: Schema8.optional(Schema8.Array(Schema8.Any)),
|
|
544
|
+
/**
|
|
545
|
+
* Base type of the schema.
|
|
546
|
+
*/
|
|
547
|
+
type: Schema8.optional(Schema8.Union(SimpleTypes, Schema8.Array(SimpleTypes))),
|
|
548
|
+
//
|
|
549
|
+
// Numbers.
|
|
550
|
+
//
|
|
551
|
+
multipleOf: Schema8.optional(Schema8.Number.pipe(Schema8.greaterThan(0))),
|
|
552
|
+
maximum: Schema8.optional(Schema8.Number),
|
|
553
|
+
exclusiveMaximum: Schema8.optional(Schema8.Number),
|
|
554
|
+
minimum: Schema8.optional(Schema8.Number),
|
|
555
|
+
exclusiveMinimum: Schema8.optional(Schema8.Number),
|
|
556
|
+
//
|
|
557
|
+
// Strings.
|
|
558
|
+
//
|
|
559
|
+
maxLength: Schema8.optional(NonNegativeInteger),
|
|
560
|
+
/**
|
|
561
|
+
* Regex pattern for strings.
|
|
562
|
+
*/
|
|
563
|
+
pattern: Schema8.optional(Schema8.String.pipe(FormatAnnotation.set(TypeFormat.Regex))),
|
|
564
|
+
/**
|
|
565
|
+
* Serialized from {@link FormatAnnotationId}.
|
|
566
|
+
*/
|
|
567
|
+
format: Schema8.optional(Schema8.String),
|
|
568
|
+
//
|
|
569
|
+
// Arrays
|
|
570
|
+
//
|
|
571
|
+
minLength: Schema8.optional(NonNegativeInteger),
|
|
572
|
+
items: Schema8.optional(Schema8.Union(Schema8.suspend(() => JsonSchemaType), Schema8.Array(Schema8.suspend(() => JsonSchemaType)))),
|
|
573
|
+
additionalItems: Schema8.optional(Schema8.Union(Schema8.suspend(() => JsonSchemaType), Schema8.Boolean)),
|
|
574
|
+
maxItems: Schema8.optional(NonNegativeInteger),
|
|
575
|
+
minItems: Schema8.optional(NonNegativeInteger),
|
|
576
|
+
uniqueItems: Schema8.optional(Schema8.Boolean),
|
|
577
|
+
contains: Schema8.optional(Schema8.suspend(() => JsonSchemaType)),
|
|
578
|
+
//
|
|
579
|
+
// Objects
|
|
580
|
+
//
|
|
581
|
+
maxProperties: Schema8.optional(NonNegativeInteger),
|
|
582
|
+
minProperties: Schema8.optional(NonNegativeInteger),
|
|
583
|
+
required: Schema8.optional(StringArray),
|
|
584
|
+
/**
|
|
585
|
+
* Non-standard JSON Schema extension.
|
|
586
|
+
* Defines the order of properties in the object.
|
|
587
|
+
* The unmentioned properties are placed at the end.
|
|
588
|
+
*
|
|
589
|
+
* Related: https://github.com/json-schema/json-schema/issues/119
|
|
590
|
+
*/
|
|
591
|
+
propertyOrder: Schema8.optional(StringArray),
|
|
592
|
+
additionalProperties: Schema8.optional(JsonSchemaOrBoolean),
|
|
593
|
+
properties: Schema8.optional(Schema8.Record({
|
|
594
|
+
key: Schema8.String,
|
|
595
|
+
value: Schema8.suspend(() => JsonSchemaType)
|
|
596
|
+
}).pipe(Schema8.mutable)),
|
|
597
|
+
patternProperties: Schema8.optional(Schema8.Record({
|
|
598
|
+
key: Schema8.String,
|
|
599
|
+
value: Schema8.suspend(() => JsonSchemaType)
|
|
600
|
+
}).pipe(Schema8.mutable)),
|
|
601
|
+
propertyNames: Schema8.optional(Schema8.suspend(() => JsonSchemaType)),
|
|
602
|
+
definitions: Schema8.optional(Schema8.mutable(Schema8.Record({
|
|
603
|
+
key: Schema8.String,
|
|
604
|
+
value: Schema8.suspend(() => JsonSchemaType)
|
|
605
|
+
}))),
|
|
606
|
+
dependencies: Schema8.optional(Schema8.Record({
|
|
607
|
+
key: Schema8.String,
|
|
608
|
+
value: Schema8.suspend(() => Schema8.Union(Schema8.String, StringArray, JsonSchemaType)).annotations({
|
|
609
|
+
identifier: "dependency",
|
|
610
|
+
description: "Dependency"
|
|
611
|
+
})
|
|
612
|
+
})),
|
|
613
|
+
contentMediaType: Schema8.optional(Schema8.String),
|
|
614
|
+
contentEncoding: Schema8.optional(Schema8.String),
|
|
615
|
+
if: Schema8.optional(Schema8.suspend(() => JsonSchemaType)),
|
|
616
|
+
then: Schema8.optional(Schema8.suspend(() => JsonSchemaType)),
|
|
617
|
+
else: Schema8.optional(Schema8.suspend(() => JsonSchemaType)),
|
|
618
|
+
allOf: Schema8.optional(Schema8.Array(Schema8.suspend(() => JsonSchemaType))),
|
|
619
|
+
anyOf: Schema8.optional(Schema8.Array(Schema8.suspend(() => JsonSchemaType))),
|
|
620
|
+
oneOf: Schema8.optional(Schema8.Array(Schema8.suspend(() => JsonSchemaType))),
|
|
621
|
+
not: Schema8.optional(Schema8.suspend(() => JsonSchemaType)),
|
|
622
|
+
$defs: Schema8.optional(Schema8.mutable(Schema8.Record({
|
|
623
|
+
key: Schema8.String,
|
|
624
|
+
value: Schema8.suspend(() => JsonSchemaType)
|
|
625
|
+
}))),
|
|
626
|
+
//
|
|
627
|
+
// ECHO extensions.
|
|
628
|
+
//
|
|
629
|
+
currency: Schema8.optional(Schema8.String),
|
|
630
|
+
reference: Schema8.optional(Schema8.mutable(Schema8.Struct({
|
|
631
|
+
schema: Schema8.suspend(() => JsonSchemaType),
|
|
632
|
+
schemaVersion: Schema8.optional(Schema8.String),
|
|
633
|
+
schemaObject: Schema8.optional(Schema8.String)
|
|
634
|
+
}))),
|
|
635
|
+
/**
|
|
636
|
+
* ECHO-specific annotations.
|
|
637
|
+
*/
|
|
638
|
+
// TODO(dmaretskyi): Since we are adding a lot of new extensions to the JSON Schema, it is safer to namespace them here.
|
|
639
|
+
annotations: Schema8.optional(Schema8.mutable(JsonSchemaEchoAnnotations)),
|
|
640
|
+
/**
|
|
641
|
+
* @deprecated Use `annotations` instead.
|
|
642
|
+
*/
|
|
643
|
+
echo: Schema8.optional(Schema8.mutable(JsonSchemaEchoAnnotations))
|
|
644
|
+
}).annotations({
|
|
645
|
+
identifier: "jsonSchema",
|
|
646
|
+
description: "JSON Schema"
|
|
647
|
+
});
|
|
648
|
+
var JsonSchemaFields = Object.keys(_JsonSchemaType.fields);
|
|
649
|
+
var JsonSchemaType = _JsonSchemaType.pipe(Schema8.mutable);
|
|
650
|
+
var getSchemaProperty = (schema, property) => {
|
|
651
|
+
return schema.properties?.[property];
|
|
652
|
+
};
|
|
653
|
+
var setSchemaProperty = (schema, property, value) => {
|
|
654
|
+
schema.properties ??= {};
|
|
655
|
+
schema.properties[property] = value;
|
|
656
|
+
return schema;
|
|
657
|
+
};
|
|
658
|
+
var ECHO_ANNOTATIONS_NS_DEPRECATED_KEY = "echo";
|
|
659
|
+
var ECHO_ANNOTATIONS_NS_KEY = "annotations";
|
|
660
|
+
var getNormalizedEchoAnnotations = (obj) => {
|
|
661
|
+
if (obj[ECHO_ANNOTATIONS_NS_KEY] != null && obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {
|
|
662
|
+
return normalizeEchoAnnotations({
|
|
663
|
+
...obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY],
|
|
664
|
+
...obj[ECHO_ANNOTATIONS_NS_KEY]
|
|
665
|
+
});
|
|
666
|
+
} else if (obj[ECHO_ANNOTATIONS_NS_KEY] != null) {
|
|
667
|
+
return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_KEY]);
|
|
668
|
+
} else if (obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {
|
|
669
|
+
return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY]);
|
|
670
|
+
} else {
|
|
671
|
+
return void 0;
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
var normalizeEchoAnnotations = (obj) => {
|
|
675
|
+
if (!obj.annotations) {
|
|
676
|
+
return obj;
|
|
677
|
+
} else {
|
|
678
|
+
const res = {
|
|
679
|
+
...obj,
|
|
680
|
+
meta: {
|
|
681
|
+
...obj.annotations,
|
|
682
|
+
...obj.meta ?? {}
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
delete res.annotations;
|
|
686
|
+
return res;
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
// src/internal/json-schema/json-schema-normalize.ts
|
|
691
|
+
var normalizeSchema = (schema) => {
|
|
692
|
+
const copy = structuredClone(schema);
|
|
693
|
+
go(copy);
|
|
694
|
+
return copy;
|
|
695
|
+
};
|
|
696
|
+
var go = (schema) => {
|
|
697
|
+
if (typeof schema !== "object" || schema === null) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
if (schema.exclusiveMaximum === true) {
|
|
701
|
+
schema.exclusiveMaximum = schema.maximum;
|
|
702
|
+
delete schema.exclusiveMaximum;
|
|
703
|
+
} else if (schema.exclusiveMaximum === false) {
|
|
704
|
+
delete schema.exclusiveMaximum;
|
|
705
|
+
}
|
|
706
|
+
if (schema.exclusiveMinimum === true) {
|
|
707
|
+
schema.exclusiveMinimum = schema.minimum;
|
|
708
|
+
delete schema.exclusiveMinimum;
|
|
709
|
+
} else if (schema.exclusiveMinimum === false) {
|
|
710
|
+
delete schema.exclusiveMinimum;
|
|
711
|
+
}
|
|
712
|
+
for (const key of Object.keys(schema)) {
|
|
713
|
+
if (!JsonSchemaFields.includes(key)) {
|
|
714
|
+
delete schema[key];
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
if (schema.properties) {
|
|
718
|
+
goOnRecord(schema.properties);
|
|
719
|
+
}
|
|
720
|
+
if (schema.patternProperties) {
|
|
721
|
+
goOnRecord(schema.patternProperties);
|
|
722
|
+
}
|
|
723
|
+
if (schema.propertyNames) {
|
|
724
|
+
go(schema.propertyNames);
|
|
725
|
+
}
|
|
726
|
+
if (schema.definitions) {
|
|
727
|
+
goOnRecord(schema.definitions);
|
|
728
|
+
}
|
|
729
|
+
if (schema.items) {
|
|
730
|
+
maybeGoOnArray(schema.items);
|
|
731
|
+
}
|
|
732
|
+
if (schema.additionalItems) {
|
|
733
|
+
maybeGoOnArray(schema.additionalItems);
|
|
734
|
+
}
|
|
735
|
+
if (schema.contains) {
|
|
736
|
+
go(schema.contains);
|
|
737
|
+
}
|
|
738
|
+
if (schema.if) {
|
|
739
|
+
go(schema.if);
|
|
740
|
+
}
|
|
741
|
+
if (schema.then) {
|
|
742
|
+
go(schema.then);
|
|
743
|
+
}
|
|
744
|
+
if (schema.else) {
|
|
745
|
+
go(schema.else);
|
|
746
|
+
}
|
|
747
|
+
if (schema.allOf) {
|
|
748
|
+
maybeGoOnArray(schema.allOf);
|
|
749
|
+
}
|
|
750
|
+
if (schema.anyOf) {
|
|
751
|
+
maybeGoOnArray(schema.anyOf);
|
|
752
|
+
}
|
|
753
|
+
if (schema.oneOf) {
|
|
754
|
+
maybeGoOnArray(schema.oneOf);
|
|
755
|
+
}
|
|
756
|
+
if (schema.not) {
|
|
757
|
+
go(schema.not);
|
|
758
|
+
}
|
|
759
|
+
if (schema.$defs) {
|
|
760
|
+
goOnRecord(schema.$defs);
|
|
761
|
+
}
|
|
762
|
+
if (schema.reference) {
|
|
763
|
+
go(schema.reference.schema);
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
var maybeGoOnArray = (value) => {
|
|
767
|
+
if (Array.isArray(value)) {
|
|
768
|
+
for (const item of value) {
|
|
769
|
+
go(item);
|
|
770
|
+
}
|
|
771
|
+
} else if (typeof value === "object" && value !== null) {
|
|
772
|
+
go(value);
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
var goOnRecord = (record) => {
|
|
776
|
+
for (const key of Object.keys(record)) {
|
|
777
|
+
go(record[key]);
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
// src/internal/json-schema/json-schema.ts
|
|
782
|
+
import * as Array4 from "effect/Array";
|
|
783
|
+
import * as Function from "effect/Function";
|
|
784
|
+
import * as JSONSchema from "effect/JSONSchema";
|
|
785
|
+
import * as Option2 from "effect/Option";
|
|
786
|
+
import * as Schema10 from "effect/Schema";
|
|
787
|
+
import * as SchemaAST6 from "effect/SchemaAST";
|
|
788
|
+
import { raise as raise2 } from "@dxos/debug";
|
|
789
|
+
import { mapAst } from "@dxos/effect";
|
|
790
|
+
import { assertArgument as assertArgument4, invariant as invariant7 } from "@dxos/invariant";
|
|
791
|
+
import { DXN as DXN5, ObjectId as ObjectId4 } from "@dxos/keys";
|
|
792
|
+
import { log } from "@dxos/log";
|
|
793
|
+
import { clearUndefined, orderKeys, removeProperties } from "@dxos/util";
|
|
794
|
+
|
|
795
|
+
// src/internal/ref/ref.ts
|
|
796
|
+
import * as Effect from "effect/Effect";
|
|
797
|
+
import * as Option from "effect/Option";
|
|
798
|
+
import * as ParseResult from "effect/ParseResult";
|
|
799
|
+
import * as Schema9 from "effect/Schema";
|
|
800
|
+
import * as SchemaAST5 from "effect/SchemaAST";
|
|
801
|
+
import { Reference } from "@dxos/echo-protocol";
|
|
802
|
+
import { compositeRuntime } from "@dxos/echo-signals/runtime";
|
|
803
|
+
import { assertArgument as assertArgument3, invariant as invariant6 } from "@dxos/invariant";
|
|
804
|
+
import { DXN as DXN4, ObjectId as ObjectId3 } from "@dxos/keys";
|
|
805
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/ref/ref.ts";
|
|
806
|
+
var JSON_SCHEMA_ECHO_REF_ID = "/schemas/echo/ref";
|
|
807
|
+
var getSchemaReference = (property) => {
|
|
808
|
+
const { $id, reference: { schema: { $ref } = {} } = {} } = property;
|
|
809
|
+
if ($id === JSON_SCHEMA_ECHO_REF_ID && $ref) {
|
|
810
|
+
return {
|
|
811
|
+
typename: DXN4.parse($ref).typename
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
var createSchemaReference = (typename) => {
|
|
816
|
+
return {
|
|
817
|
+
$id: JSON_SCHEMA_ECHO_REF_ID,
|
|
818
|
+
reference: {
|
|
819
|
+
schema: {
|
|
820
|
+
$ref: DXN4.fromTypename(typename).toString()
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
};
|
|
825
|
+
var getReferenceAst = (ast) => {
|
|
826
|
+
if (ast._tag !== "Declaration" || !ast.annotations[ReferenceAnnotationId]) {
|
|
827
|
+
return void 0;
|
|
828
|
+
}
|
|
829
|
+
return {
|
|
830
|
+
typename: ast.annotations[ReferenceAnnotationId].typename,
|
|
831
|
+
version: ast.annotations[ReferenceAnnotationId].version
|
|
832
|
+
};
|
|
833
|
+
};
|
|
834
|
+
var RefTypeId = Symbol("@dxos/echo/internal/Ref");
|
|
835
|
+
var Ref = (schema) => {
|
|
836
|
+
assertArgument3(Schema9.isSchema(schema), "schema", "Must call with an instance of effect-schema");
|
|
837
|
+
const annotation = getTypeAnnotation(schema);
|
|
838
|
+
if (annotation == null) {
|
|
839
|
+
throw new Error("Reference target must be an ECHO schema.");
|
|
840
|
+
}
|
|
841
|
+
return createEchoReferenceSchema(getTypeIdentifierAnnotation(schema), annotation.typename, annotation.version, getSchemaExpectedName(schema.ast));
|
|
842
|
+
};
|
|
843
|
+
Ref.isRef = (obj) => {
|
|
844
|
+
return obj && typeof obj === "object" && RefTypeId in obj;
|
|
845
|
+
};
|
|
846
|
+
Ref.hasObjectId = (id) => (ref) => ref.dxn.isLocalObjectId() && ref.dxn.parts[1] === id;
|
|
847
|
+
Ref.isRefSchema = (schema) => {
|
|
848
|
+
return Ref.isRefSchemaAST(schema.ast);
|
|
849
|
+
};
|
|
850
|
+
Ref.isRefSchemaAST = (ast) => {
|
|
851
|
+
return SchemaAST5.getAnnotation(ast, ReferenceAnnotationId).pipe(Option.isSome);
|
|
852
|
+
};
|
|
853
|
+
Ref.make = (obj) => {
|
|
854
|
+
if (typeof obj !== "object" || obj === null) {
|
|
855
|
+
throw new TypeError("Expected: ECHO object.");
|
|
856
|
+
}
|
|
857
|
+
const id = obj.id;
|
|
858
|
+
invariant6(ObjectId3.isValid(id), "Invalid object ID", {
|
|
859
|
+
F: __dxlog_file6,
|
|
860
|
+
L: 221,
|
|
861
|
+
S: void 0,
|
|
862
|
+
A: [
|
|
863
|
+
"ObjectId.isValid(id)",
|
|
864
|
+
"'Invalid object ID'"
|
|
865
|
+
]
|
|
866
|
+
});
|
|
867
|
+
const dxn = Reference.localObjectReference(id).toDXN();
|
|
868
|
+
return new RefImpl(dxn, obj);
|
|
869
|
+
};
|
|
870
|
+
Ref.fromDXN = (dxn) => {
|
|
871
|
+
assertArgument3(dxn instanceof DXN4, "dxn", "Expected DXN");
|
|
872
|
+
return new RefImpl(dxn);
|
|
873
|
+
};
|
|
874
|
+
var createEchoReferenceSchema = (echoId, typename, version, schemaName) => {
|
|
875
|
+
if (!echoId && !typename) {
|
|
876
|
+
throw new TypeError("Either echoId or typename must be provided.");
|
|
877
|
+
}
|
|
878
|
+
const referenceInfo = {
|
|
879
|
+
schema: {
|
|
880
|
+
// TODO(dmaretskyi): Include version?
|
|
881
|
+
$ref: echoId ?? DXN4.fromTypename(typename).toString()
|
|
882
|
+
},
|
|
883
|
+
schemaVersion: version
|
|
884
|
+
};
|
|
885
|
+
const refSchema = Schema9.declare([], {
|
|
886
|
+
encode: () => {
|
|
887
|
+
return (value) => {
|
|
888
|
+
return Effect.succeed({
|
|
889
|
+
"/": value.dxn.toString()
|
|
890
|
+
});
|
|
891
|
+
};
|
|
892
|
+
},
|
|
893
|
+
decode: () => {
|
|
894
|
+
return (value) => {
|
|
895
|
+
if (Ref.isRef(value)) {
|
|
896
|
+
return Effect.succeed(value);
|
|
897
|
+
}
|
|
898
|
+
if (typeof value !== "object" || value == null || typeof value["/"] !== "string") {
|
|
899
|
+
return Effect.fail(new ParseResult.Unexpected(value, "reference"));
|
|
900
|
+
}
|
|
901
|
+
return Effect.succeed(Ref.fromDXN(DXN4.parse(value["/"])));
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
}, {
|
|
905
|
+
jsonSchema: {
|
|
906
|
+
// TODO(dmaretskyi): We should remove `$id` and keep `$ref` with a fully qualified name.
|
|
907
|
+
$id: JSON_SCHEMA_ECHO_REF_ID,
|
|
908
|
+
$ref: JSON_SCHEMA_ECHO_REF_ID,
|
|
909
|
+
reference: referenceInfo
|
|
910
|
+
},
|
|
911
|
+
[ReferenceAnnotationId]: {
|
|
912
|
+
typename: typename ?? "",
|
|
913
|
+
version
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
return refSchema;
|
|
917
|
+
};
|
|
918
|
+
var getSchemaExpectedName = (ast) => {
|
|
919
|
+
return SchemaAST5.getIdentifierAnnotation(ast).pipe(Option.orElse(() => SchemaAST5.getTitleAnnotation(ast)), Option.orElse(() => SchemaAST5.getDescriptionAnnotation(ast)), Option.getOrElse(() => void 0));
|
|
920
|
+
};
|
|
921
|
+
var RefImpl = class _RefImpl {
|
|
922
|
+
#dxn;
|
|
923
|
+
#resolver = void 0;
|
|
924
|
+
#signal = compositeRuntime.createSignal();
|
|
925
|
+
/**
|
|
926
|
+
* Target is set when the reference is created from a specific object.
|
|
927
|
+
* In this case, the target might not be in the database.
|
|
928
|
+
*/
|
|
929
|
+
#target = void 0;
|
|
930
|
+
/**
|
|
931
|
+
* Callback to issue a reactive notification when object is resolved.
|
|
932
|
+
*/
|
|
933
|
+
#resolverCallback = () => {
|
|
934
|
+
this.#signal.notifyWrite();
|
|
935
|
+
};
|
|
936
|
+
constructor(dxn, target) {
|
|
937
|
+
this.#dxn = dxn;
|
|
938
|
+
this.#target = target;
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* @inheritdoc
|
|
942
|
+
*/
|
|
943
|
+
get dxn() {
|
|
944
|
+
return this.#dxn;
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* @inheritdoc
|
|
948
|
+
*/
|
|
949
|
+
get target() {
|
|
950
|
+
this.#signal.notifyRead();
|
|
951
|
+
if (this.#target) {
|
|
952
|
+
return this.#target;
|
|
953
|
+
}
|
|
954
|
+
invariant6(this.#resolver, "Resolver is not set", {
|
|
955
|
+
F: __dxlog_file6,
|
|
956
|
+
L: 370,
|
|
957
|
+
S: this,
|
|
958
|
+
A: [
|
|
959
|
+
"this.#resolver",
|
|
960
|
+
"'Resolver is not set'"
|
|
961
|
+
]
|
|
962
|
+
});
|
|
963
|
+
return this.#resolver.resolveSync(this.#dxn, true, this.#resolverCallback);
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* @inheritdoc
|
|
967
|
+
*/
|
|
968
|
+
async load() {
|
|
969
|
+
if (this.#target) {
|
|
970
|
+
return this.#target;
|
|
971
|
+
}
|
|
972
|
+
invariant6(this.#resolver, "Resolver is not set", {
|
|
973
|
+
F: __dxlog_file6,
|
|
974
|
+
L: 381,
|
|
975
|
+
S: this,
|
|
976
|
+
A: [
|
|
977
|
+
"this.#resolver",
|
|
978
|
+
"'Resolver is not set'"
|
|
979
|
+
]
|
|
980
|
+
});
|
|
981
|
+
const obj = await this.#resolver.resolve(this.#dxn);
|
|
982
|
+
if (obj == null) {
|
|
983
|
+
throw new Error("Object not found");
|
|
984
|
+
}
|
|
985
|
+
return obj;
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* @inheritdoc
|
|
989
|
+
*/
|
|
990
|
+
async tryLoad() {
|
|
991
|
+
invariant6(this.#resolver, "Resolver is not set", {
|
|
992
|
+
F: __dxlog_file6,
|
|
993
|
+
L: 393,
|
|
994
|
+
S: this,
|
|
995
|
+
A: [
|
|
996
|
+
"this.#resolver",
|
|
997
|
+
"'Resolver is not set'"
|
|
998
|
+
]
|
|
999
|
+
});
|
|
1000
|
+
return await this.#resolver.resolve(this.#dxn);
|
|
1001
|
+
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Do not inline the target object in the reference.
|
|
1004
|
+
* Makes .target unavailable unless the reference is connected to a database context.
|
|
1005
|
+
* Clones the reference object.
|
|
1006
|
+
*/
|
|
1007
|
+
noInline() {
|
|
1008
|
+
const ref = new _RefImpl(this.#dxn, void 0);
|
|
1009
|
+
ref.#resolver = this.#resolver;
|
|
1010
|
+
return ref;
|
|
1011
|
+
}
|
|
1012
|
+
encode() {
|
|
1013
|
+
return {
|
|
1014
|
+
"/": this.#dxn.toString(),
|
|
1015
|
+
...this.#target ? {
|
|
1016
|
+
target: this.#target
|
|
1017
|
+
} : {}
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Serializes the reference to a JSON object.
|
|
1022
|
+
* The serialization format is compatible with the IPLD-style encoded references.
|
|
1023
|
+
* When a reference has a saved target (i.e. the target or object holding the reference is not in the database),
|
|
1024
|
+
* the target is included in the serialized object.
|
|
1025
|
+
*/
|
|
1026
|
+
toJSON() {
|
|
1027
|
+
return this.encode();
|
|
1028
|
+
}
|
|
1029
|
+
toString() {
|
|
1030
|
+
if (this.#target) {
|
|
1031
|
+
return `Ref(${this.#target.toString()})`;
|
|
1032
|
+
}
|
|
1033
|
+
return `Ref(${this.#dxn.toString()})`;
|
|
1034
|
+
}
|
|
1035
|
+
[RefTypeId] = refVariance;
|
|
1036
|
+
/**
|
|
1037
|
+
* Internal method to set the resolver.
|
|
1038
|
+
*
|
|
1039
|
+
* @internal
|
|
1040
|
+
*/
|
|
1041
|
+
_setResolver(resolver) {
|
|
1042
|
+
this.#resolver = resolver;
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Internal method to get the saved target.
|
|
1046
|
+
* Not the same as `target` which is resolved from the resolver.
|
|
1047
|
+
*
|
|
1048
|
+
* @internal
|
|
1049
|
+
*/
|
|
1050
|
+
_getSavedTarget() {
|
|
1051
|
+
return this.#target;
|
|
1052
|
+
}
|
|
1053
|
+
};
|
|
1054
|
+
var setRefResolver = (ref, resolver) => {
|
|
1055
|
+
invariant6(ref instanceof RefImpl, "Ref is not an instance of RefImpl", {
|
|
1056
|
+
F: __dxlog_file6,
|
|
1057
|
+
L: 459,
|
|
1058
|
+
S: void 0,
|
|
1059
|
+
A: [
|
|
1060
|
+
"ref instanceof RefImpl",
|
|
1061
|
+
"'Ref is not an instance of RefImpl'"
|
|
1062
|
+
]
|
|
1063
|
+
});
|
|
1064
|
+
ref._setResolver(resolver);
|
|
1065
|
+
};
|
|
1066
|
+
var getRefSavedTarget = (ref) => {
|
|
1067
|
+
invariant6(ref instanceof RefImpl, "Ref is not an instance of RefImpl", {
|
|
1068
|
+
F: __dxlog_file6,
|
|
1069
|
+
L: 467,
|
|
1070
|
+
S: void 0,
|
|
1071
|
+
A: [
|
|
1072
|
+
"ref instanceof RefImpl",
|
|
1073
|
+
"'Ref is not an instance of RefImpl'"
|
|
1074
|
+
]
|
|
1075
|
+
});
|
|
1076
|
+
return ref._getSavedTarget();
|
|
1077
|
+
};
|
|
1078
|
+
var refVariance = {
|
|
1079
|
+
_T: null
|
|
1080
|
+
};
|
|
1081
|
+
var refFromEncodedReference = (encodedReference, resolver) => {
|
|
1082
|
+
const dxn = DXN4.parse(encodedReference["/"]);
|
|
1083
|
+
const ref = new RefImpl(dxn);
|
|
1084
|
+
if (resolver) {
|
|
1085
|
+
setRefResolver(ref, resolver);
|
|
1086
|
+
}
|
|
1087
|
+
return ref;
|
|
1088
|
+
};
|
|
1089
|
+
var StaticRefResolver = class {
|
|
1090
|
+
objects = /* @__PURE__ */ new Map();
|
|
1091
|
+
schemas = /* @__PURE__ */ new Map();
|
|
1092
|
+
addObject(obj) {
|
|
1093
|
+
this.objects.set(obj.id, obj);
|
|
1094
|
+
return this;
|
|
1095
|
+
}
|
|
1096
|
+
addSchema(schema) {
|
|
1097
|
+
const dxn = getSchemaDXN(schema);
|
|
1098
|
+
invariant6(dxn, "Schema has no DXN", {
|
|
1099
|
+
F: __dxlog_file6,
|
|
1100
|
+
L: 499,
|
|
1101
|
+
S: this,
|
|
1102
|
+
A: [
|
|
1103
|
+
"dxn",
|
|
1104
|
+
"'Schema has no DXN'"
|
|
1105
|
+
]
|
|
1106
|
+
});
|
|
1107
|
+
this.schemas.set(dxn.toString(), schema);
|
|
1108
|
+
return this;
|
|
1109
|
+
}
|
|
1110
|
+
resolveSync(dxn, _load, _onLoad) {
|
|
1111
|
+
const id = dxn?.asEchoDXN()?.echoId;
|
|
1112
|
+
if (id == null) {
|
|
1113
|
+
return void 0;
|
|
1114
|
+
}
|
|
1115
|
+
return this.objects.get(id);
|
|
1116
|
+
}
|
|
1117
|
+
async resolve(dxn) {
|
|
1118
|
+
const id = dxn?.asEchoDXN()?.echoId;
|
|
1119
|
+
if (id == null) {
|
|
1120
|
+
return void 0;
|
|
1121
|
+
}
|
|
1122
|
+
return this.objects.get(id);
|
|
1123
|
+
}
|
|
1124
|
+
async resolveSchema(dxn) {
|
|
1125
|
+
return this.schemas.get(dxn.toString());
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
|
|
1129
|
+
// src/internal/ref/ref-array.ts
|
|
1130
|
+
import { isNonNullable } from "@dxos/util";
|
|
1131
|
+
var RefArray = Object.freeze({
|
|
1132
|
+
/**
|
|
1133
|
+
* @returns all resolved targets.
|
|
1134
|
+
*/
|
|
1135
|
+
targets: (refs) => {
|
|
1136
|
+
return refs.map((ref) => ref.target).filter(isNonNullable);
|
|
1137
|
+
},
|
|
1138
|
+
/**
|
|
1139
|
+
* Load all referenced objects.
|
|
1140
|
+
*/
|
|
1141
|
+
loadAll: (refs) => {
|
|
1142
|
+
return Promise.all(refs.map((ref) => ref.load()));
|
|
1143
|
+
},
|
|
1144
|
+
/**
|
|
1145
|
+
* Removes the ref with the given id.
|
|
1146
|
+
*/
|
|
1147
|
+
removeById: (refs, id) => {
|
|
1148
|
+
const index = refs.findIndex(Ref.hasObjectId(id));
|
|
1149
|
+
if (index >= 0) {
|
|
1150
|
+
refs.splice(index, 1);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
// src/internal/json-schema/json-schema.ts
|
|
1156
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/json-schema/json-schema.ts";
|
|
1157
|
+
var PropType = /* @__PURE__ */ (function(PropType2) {
|
|
1158
|
+
PropType2[PropType2["NONE"] = 0] = "NONE";
|
|
1159
|
+
PropType2[PropType2["STRING"] = 1] = "STRING";
|
|
1160
|
+
PropType2[PropType2["NUMBER"] = 2] = "NUMBER";
|
|
1161
|
+
PropType2[PropType2["BOOLEAN"] = 3] = "BOOLEAN";
|
|
1162
|
+
PropType2[PropType2["DATE"] = 4] = "DATE";
|
|
1163
|
+
PropType2[PropType2["REF"] = 5] = "REF";
|
|
1164
|
+
PropType2[PropType2["RECORD"] = 6] = "RECORD";
|
|
1165
|
+
PropType2[PropType2["ENUM"] = 7] = "ENUM";
|
|
1166
|
+
return PropType2;
|
|
1167
|
+
})({});
|
|
1168
|
+
var toPropType = (type) => {
|
|
1169
|
+
switch (type) {
|
|
1170
|
+
case 1:
|
|
1171
|
+
return "string";
|
|
1172
|
+
case 2:
|
|
1173
|
+
return "number";
|
|
1174
|
+
case 3:
|
|
1175
|
+
return "boolean";
|
|
1176
|
+
case 4:
|
|
1177
|
+
return "date";
|
|
1178
|
+
case 5:
|
|
1179
|
+
return "ref";
|
|
1180
|
+
case 6:
|
|
1181
|
+
return "object";
|
|
1182
|
+
default:
|
|
1183
|
+
throw new Error(`Invalid type: ${type}`);
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
var JSON_SCHEMA_URL = "http://json-schema.org/draft-07/schema#";
|
|
1187
|
+
var toJsonSchema = (schema, options = {}) => {
|
|
1188
|
+
assertArgument4(Schema10.isSchema(schema), "schema");
|
|
1189
|
+
let jsonSchema = _toJsonSchemaAST(schema.ast);
|
|
1190
|
+
if (options.strict) {
|
|
1191
|
+
jsonSchema = removeProperties(jsonSchema, (key, value) => {
|
|
1192
|
+
if (key === "$id" && value === "/schemas/any") {
|
|
1193
|
+
return true;
|
|
1194
|
+
}
|
|
1195
|
+
if (key === "$ref" && value === "#/$defs/dependency") {
|
|
1196
|
+
return true;
|
|
1197
|
+
}
|
|
1198
|
+
if (key === "$ref" && value === "#/$defs/jsonSchema") {
|
|
1199
|
+
return true;
|
|
1200
|
+
}
|
|
1201
|
+
return false;
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
return jsonSchema;
|
|
1205
|
+
};
|
|
1206
|
+
var _toJsonSchemaAST = (ast) => {
|
|
1207
|
+
const withRefinements = withEchoRefinements(ast, "#");
|
|
1208
|
+
const jsonSchema = JSONSchema.fromAST(withRefinements, {
|
|
1209
|
+
definitions: {}
|
|
1210
|
+
});
|
|
1211
|
+
return normalizeJsonSchema(jsonSchema);
|
|
1212
|
+
};
|
|
1213
|
+
var withEchoRefinements = (ast, path, suspendCache = /* @__PURE__ */ new Map()) => {
|
|
1214
|
+
if (path) {
|
|
1215
|
+
suspendCache.set(ast, path);
|
|
1216
|
+
}
|
|
1217
|
+
let recursiveResult;
|
|
1218
|
+
if (SchemaAST6.isSuspend(ast)) {
|
|
1219
|
+
const suspendedAst = ast.f();
|
|
1220
|
+
const cachedPath = suspendCache.get(suspendedAst);
|
|
1221
|
+
if (cachedPath) {
|
|
1222
|
+
recursiveResult = new SchemaAST6.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {
|
|
1223
|
+
[SchemaAST6.JSONSchemaAnnotationId]: {
|
|
1224
|
+
$ref: cachedPath
|
|
1225
|
+
}
|
|
1226
|
+
});
|
|
1227
|
+
} else {
|
|
1228
|
+
const jsonSchema = _toJsonSchemaAST(suspendedAst);
|
|
1229
|
+
recursiveResult = new SchemaAST6.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {
|
|
1230
|
+
[SchemaAST6.JSONSchemaAnnotationId]: jsonSchema
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
} else if (SchemaAST6.isTypeLiteral(ast)) {
|
|
1234
|
+
recursiveResult = mapAst(ast, (ast2, key) => withEchoRefinements(ast2, path && typeof key === "string" ? `${path}/${key}` : void 0, suspendCache));
|
|
1235
|
+
recursiveResult = addJsonSchemaFields(recursiveResult, {
|
|
1236
|
+
propertyOrder: [
|
|
1237
|
+
...ast.propertySignatures.map((p) => p.name)
|
|
1238
|
+
]
|
|
1239
|
+
});
|
|
1240
|
+
} else if (SchemaAST6.isUndefinedKeyword(ast)) {
|
|
1241
|
+
return ast;
|
|
1242
|
+
} else {
|
|
1243
|
+
recursiveResult = mapAst(ast, (ast2, key) => withEchoRefinements(ast2, path && (typeof key === "string" || typeof key === "number") ? `${path}/${key}` : void 0, suspendCache));
|
|
1244
|
+
}
|
|
1245
|
+
const annotationFields = annotations_toJsonSchemaFields(ast.annotations);
|
|
1246
|
+
if (Object.keys(annotationFields).length === 0) {
|
|
1247
|
+
return recursiveResult;
|
|
1248
|
+
} else {
|
|
1249
|
+
return addJsonSchemaFields(recursiveResult, annotationFields);
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
var toEffectSchema = (root, _defs) => {
|
|
1253
|
+
const defs = root.$defs ? {
|
|
1254
|
+
..._defs,
|
|
1255
|
+
...root.$defs
|
|
1256
|
+
} : _defs ?? {};
|
|
1257
|
+
if ("type" in root && root.type === "object") {
|
|
1258
|
+
return objectToEffectSchema(root, defs);
|
|
1259
|
+
}
|
|
1260
|
+
let result = Schema10.Unknown;
|
|
1261
|
+
if ("$ref" in root) {
|
|
1262
|
+
switch (root.$ref) {
|
|
1263
|
+
case "/schemas/echo/ref": {
|
|
1264
|
+
result = refToEffectSchema(root);
|
|
1265
|
+
break;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
} else if ("$id" in root) {
|
|
1269
|
+
switch (root.$id) {
|
|
1270
|
+
case "/schemas/any": {
|
|
1271
|
+
result = anyToEffectSchema(root);
|
|
1272
|
+
break;
|
|
1273
|
+
}
|
|
1274
|
+
case "/schemas/unknown": {
|
|
1275
|
+
result = Schema10.Unknown;
|
|
1276
|
+
break;
|
|
1277
|
+
}
|
|
1278
|
+
case "/schemas/{}":
|
|
1279
|
+
case "/schemas/object": {
|
|
1280
|
+
result = Schema10.Object;
|
|
1281
|
+
break;
|
|
1282
|
+
}
|
|
1283
|
+
// Custom ECHO object reference.
|
|
1284
|
+
case "/schemas/echo/ref": {
|
|
1285
|
+
result = refToEffectSchema(root);
|
|
1286
|
+
break;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
} else if ("enum" in root) {
|
|
1290
|
+
result = Schema10.Union(...root.enum.map((e) => Schema10.Literal(e)));
|
|
1291
|
+
} else if ("oneOf" in root) {
|
|
1292
|
+
result = Schema10.Union(...root.oneOf.map((v) => toEffectSchema(v, defs)));
|
|
1293
|
+
} else if ("anyOf" in root) {
|
|
1294
|
+
result = Schema10.Union(...root.anyOf.map((v) => toEffectSchema(v, defs)));
|
|
1295
|
+
} else if ("allOf" in root) {
|
|
1296
|
+
if (root.allOf.length === 1) {
|
|
1297
|
+
result = toEffectSchema(root.allOf[0], defs);
|
|
1298
|
+
} else {
|
|
1299
|
+
log.warn("allOf with multiple schemas is not supported", void 0, {
|
|
1300
|
+
F: __dxlog_file7,
|
|
1301
|
+
L: 221,
|
|
1302
|
+
S: void 0,
|
|
1303
|
+
C: (f, a) => f(...a)
|
|
1304
|
+
});
|
|
1305
|
+
result = Schema10.Unknown;
|
|
1306
|
+
}
|
|
1307
|
+
} else if ("type" in root) {
|
|
1308
|
+
switch (root.type) {
|
|
1309
|
+
case "string": {
|
|
1310
|
+
result = Schema10.String;
|
|
1311
|
+
if (root.pattern) {
|
|
1312
|
+
result = result.pipe(Schema10.pattern(new RegExp(root.pattern)));
|
|
1313
|
+
}
|
|
1314
|
+
break;
|
|
1315
|
+
}
|
|
1316
|
+
case "number": {
|
|
1317
|
+
result = Schema10.Number;
|
|
1318
|
+
break;
|
|
1319
|
+
}
|
|
1320
|
+
case "integer": {
|
|
1321
|
+
result = Schema10.Number.pipe(Schema10.int());
|
|
1322
|
+
break;
|
|
1323
|
+
}
|
|
1324
|
+
case "boolean": {
|
|
1325
|
+
result = Schema10.Boolean;
|
|
1326
|
+
break;
|
|
1327
|
+
}
|
|
1328
|
+
case "array": {
|
|
1329
|
+
if (Array4.isArray(root.items)) {
|
|
1330
|
+
const [required, optional5] = Function.pipe(root.items, Array4.map((v) => toEffectSchema(v, defs)), Array4.splitAt(root.minItems ?? root.items.length));
|
|
1331
|
+
result = Schema10.Tuple(...required, ...optional5.map(Schema10.optionalElement));
|
|
1332
|
+
} else {
|
|
1333
|
+
invariant7(root.items, void 0, {
|
|
1334
|
+
F: __dxlog_file7,
|
|
1335
|
+
L: 254,
|
|
1336
|
+
S: void 0,
|
|
1337
|
+
A: [
|
|
1338
|
+
"root.items",
|
|
1339
|
+
""
|
|
1340
|
+
]
|
|
1341
|
+
});
|
|
1342
|
+
const items = root.items;
|
|
1343
|
+
result = Array4.isArray(items) ? Schema10.Tuple(...items.map((v) => toEffectSchema(v, defs))) : Schema10.Array(toEffectSchema(items, defs));
|
|
1344
|
+
}
|
|
1345
|
+
break;
|
|
1346
|
+
}
|
|
1347
|
+
case "null": {
|
|
1348
|
+
result = Schema10.Null;
|
|
1349
|
+
break;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
} else if ("$ref" in root) {
|
|
1353
|
+
const refSegments = root.$ref.split("/");
|
|
1354
|
+
const jsonSchema = defs[refSegments[refSegments.length - 1]];
|
|
1355
|
+
invariant7(jsonSchema, `missing definition for ${root.$ref}`, {
|
|
1356
|
+
F: __dxlog_file7,
|
|
1357
|
+
L: 270,
|
|
1358
|
+
S: void 0,
|
|
1359
|
+
A: [
|
|
1360
|
+
"jsonSchema",
|
|
1361
|
+
"`missing definition for ${root.$ref}`"
|
|
1362
|
+
]
|
|
1363
|
+
});
|
|
1364
|
+
result = toEffectSchema(jsonSchema, defs).pipe(Schema10.annotations({
|
|
1365
|
+
identifier: refSegments[refSegments.length - 1]
|
|
1366
|
+
}));
|
|
1367
|
+
}
|
|
1368
|
+
const annotations4 = jsonSchemaFieldsToAnnotations(root);
|
|
1369
|
+
result = result.annotations(annotations4);
|
|
1370
|
+
return result;
|
|
1371
|
+
};
|
|
1372
|
+
var objectToEffectSchema = (root, defs) => {
|
|
1373
|
+
invariant7("type" in root && root.type === "object", `not an object: ${root}`, {
|
|
1374
|
+
F: __dxlog_file7,
|
|
1375
|
+
L: 285,
|
|
1376
|
+
S: void 0,
|
|
1377
|
+
A: [
|
|
1378
|
+
"'type' in root && root.type === 'object'",
|
|
1379
|
+
"`not an object: ${root}`"
|
|
1380
|
+
]
|
|
1381
|
+
});
|
|
1382
|
+
const echoRefinement = root[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
|
|
1383
|
+
const isEchoObject = echoRefinement != null || "$id" in root && typeof root.$id === "string" && root.$id.startsWith("dxn:");
|
|
1384
|
+
let fields = {};
|
|
1385
|
+
const propertyList = Object.entries(root.properties ?? {});
|
|
1386
|
+
let immutableIdField;
|
|
1387
|
+
for (const [key, value] of propertyList) {
|
|
1388
|
+
if (isEchoObject && key === "id") {
|
|
1389
|
+
immutableIdField = toEffectSchema(value, defs);
|
|
1390
|
+
} else {
|
|
1391
|
+
fields[key] = root.required?.includes(key) ? toEffectSchema(value, defs) : Schema10.optional(toEffectSchema(value, defs));
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
if (root.propertyOrder) {
|
|
1395
|
+
fields = orderKeys(fields, root.propertyOrder);
|
|
1396
|
+
}
|
|
1397
|
+
let schema;
|
|
1398
|
+
if (root.patternProperties) {
|
|
1399
|
+
invariant7(propertyList.length === 0, "pattern properties mixed with regular properties are not supported", {
|
|
1400
|
+
F: __dxlog_file7,
|
|
1401
|
+
L: 311,
|
|
1402
|
+
S: void 0,
|
|
1403
|
+
A: [
|
|
1404
|
+
"propertyList.length === 0",
|
|
1405
|
+
"'pattern properties mixed with regular properties are not supported'"
|
|
1406
|
+
]
|
|
1407
|
+
});
|
|
1408
|
+
invariant7(Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === "", "only one pattern property is supported", {
|
|
1409
|
+
F: __dxlog_file7,
|
|
1410
|
+
L: 312,
|
|
1411
|
+
S: void 0,
|
|
1412
|
+
A: [
|
|
1413
|
+
"Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === ''",
|
|
1414
|
+
"'only one pattern property is supported'"
|
|
1415
|
+
]
|
|
1416
|
+
});
|
|
1417
|
+
schema = Schema10.Record({
|
|
1418
|
+
key: Schema10.String,
|
|
1419
|
+
value: toEffectSchema(root.patternProperties[""], defs)
|
|
1420
|
+
});
|
|
1421
|
+
} else if (typeof root.additionalProperties !== "object") {
|
|
1422
|
+
schema = Schema10.Struct(fields);
|
|
1423
|
+
} else {
|
|
1424
|
+
const indexValue = toEffectSchema(root.additionalProperties, defs);
|
|
1425
|
+
if (propertyList.length > 0) {
|
|
1426
|
+
schema = Schema10.Struct(fields, {
|
|
1427
|
+
key: Schema10.String,
|
|
1428
|
+
value: indexValue
|
|
1429
|
+
});
|
|
1430
|
+
} else {
|
|
1431
|
+
schema = Schema10.Record({
|
|
1432
|
+
key: Schema10.String,
|
|
1433
|
+
value: indexValue
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
if (immutableIdField) {
|
|
1438
|
+
schema = Schema10.extend(Schema10.mutable(schema), Schema10.Struct({
|
|
1439
|
+
id: immutableIdField
|
|
1440
|
+
}));
|
|
1441
|
+
}
|
|
1442
|
+
const annotations4 = jsonSchemaFieldsToAnnotations(root);
|
|
1443
|
+
return schema.annotations(annotations4);
|
|
1444
|
+
};
|
|
1445
|
+
var anyToEffectSchema = (root) => {
|
|
1446
|
+
const echoRefinement = root[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
|
|
1447
|
+
if (echoRefinement?.reference != null) {
|
|
1448
|
+
const echoId = root.$id.startsWith("dxn:echo:") ? root.$id : void 0;
|
|
1449
|
+
return createEchoReferenceSchema(echoId, echoRefinement.reference.typename, echoRefinement.reference.version);
|
|
1450
|
+
}
|
|
1451
|
+
return Schema10.Any;
|
|
1452
|
+
};
|
|
1453
|
+
var refToEffectSchema = (root) => {
|
|
1454
|
+
if (!("reference" in root)) {
|
|
1455
|
+
return Ref(Expando);
|
|
1456
|
+
}
|
|
1457
|
+
const reference = root.reference;
|
|
1458
|
+
if (typeof reference !== "object") {
|
|
1459
|
+
throw new Error("Invalid reference field in ref schema");
|
|
1460
|
+
}
|
|
1461
|
+
const targetSchemaDXN = DXN5.parse(reference.schema.$ref);
|
|
1462
|
+
invariant7(targetSchemaDXN.kind === DXN5.kind.TYPE, void 0, {
|
|
1463
|
+
F: __dxlog_file7,
|
|
1464
|
+
L: 364,
|
|
1465
|
+
S: void 0,
|
|
1466
|
+
A: [
|
|
1467
|
+
"targetSchemaDXN.kind === DXN.kind.TYPE",
|
|
1468
|
+
""
|
|
1469
|
+
]
|
|
1470
|
+
});
|
|
1471
|
+
return createEchoReferenceSchema(targetSchemaDXN.toString(), targetSchemaDXN.kind === DXN5.kind.TYPE ? targetSchemaDXN.parts[0] : void 0, reference.schemaVersion);
|
|
1472
|
+
};
|
|
1473
|
+
var annotations_toJsonSchemaFields = (annotations4) => {
|
|
1474
|
+
const schemaFields = {};
|
|
1475
|
+
const echoAnnotations = {};
|
|
1476
|
+
for (const [key, annotationId] of Object.entries(EchoAnnotations)) {
|
|
1477
|
+
if (annotations4[annotationId] != null) {
|
|
1478
|
+
echoAnnotations[key] = annotations4[annotationId];
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
if (Object.keys(echoAnnotations).length > 0) {
|
|
1482
|
+
schemaFields[ECHO_ANNOTATIONS_NS_KEY] = echoAnnotations;
|
|
1483
|
+
}
|
|
1484
|
+
const echoIdentifier = annotations4[TypeIdentifierAnnotationId];
|
|
1485
|
+
if (echoIdentifier) {
|
|
1486
|
+
schemaFields[ECHO_ANNOTATIONS_NS_KEY] ??= {};
|
|
1487
|
+
schemaFields[ECHO_ANNOTATIONS_NS_KEY].schemaId = echoIdentifier;
|
|
1488
|
+
}
|
|
1489
|
+
for (const [key, annotationId] of Object.entries(CustomAnnotations)) {
|
|
1490
|
+
const value = annotations4[annotationId];
|
|
1491
|
+
if (value != null) {
|
|
1492
|
+
schemaFields[key] = value;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
return schemaFields;
|
|
1496
|
+
};
|
|
1497
|
+
var decodeTypeIdentifierAnnotation = (schema) => {
|
|
1498
|
+
if (schema.$id && schema.$id.startsWith("dxn:echo:")) {
|
|
1499
|
+
return schema.$id;
|
|
1500
|
+
} else if (schema.$id && schema.$id.startsWith("dxn:type:") && schema?.echo?.type?.schemaId) {
|
|
1501
|
+
const id = schema?.echo?.type?.schemaId;
|
|
1502
|
+
if (ObjectId4.isValid(id)) {
|
|
1503
|
+
return DXN5.fromLocalObjectId(id).toString();
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
return void 0;
|
|
1507
|
+
};
|
|
1508
|
+
var decodeTypeAnnotation = (schema) => {
|
|
1509
|
+
if (schema.typename) {
|
|
1510
|
+
const annotation = {
|
|
1511
|
+
// TODO(dmaretskyi): Decoding default.
|
|
1512
|
+
kind: schema.entityKind ? Schema10.decodeSync(EntityKindSchema)(schema.entityKind) : EntityKind.Object,
|
|
1513
|
+
typename: schema.typename,
|
|
1514
|
+
version: schema.version ?? "0.1.0"
|
|
1515
|
+
};
|
|
1516
|
+
if (annotation.kind === EntityKind.Relation) {
|
|
1517
|
+
const source = schema.relationSource?.$ref ?? raise2(new Error("Relation source not set"));
|
|
1518
|
+
const target = schema.relationTarget?.$ref ?? raise2(new Error("Relation target not set"));
|
|
1519
|
+
annotation.sourceSchema = DXN5.parse(source).toString();
|
|
1520
|
+
annotation.targetSchema = DXN5.parse(target).toString();
|
|
1521
|
+
}
|
|
1522
|
+
return annotation;
|
|
1523
|
+
}
|
|
1524
|
+
if (!schema.typename && schema?.echo?.type) {
|
|
1525
|
+
return {
|
|
1526
|
+
kind: EntityKind.Object,
|
|
1527
|
+
typename: schema.echo.type.typename,
|
|
1528
|
+
version: schema.echo.type.version
|
|
1529
|
+
};
|
|
1530
|
+
}
|
|
1531
|
+
return void 0;
|
|
1532
|
+
};
|
|
1533
|
+
var jsonSchemaFieldsToAnnotations = (schema) => {
|
|
1534
|
+
const annotations4 = {};
|
|
1535
|
+
const echoAnnotations = getNormalizedEchoAnnotations(schema) ?? {};
|
|
1536
|
+
if (echoAnnotations) {
|
|
1537
|
+
for (const [key, annotationId] of Object.entries(EchoAnnotations)) {
|
|
1538
|
+
if (echoAnnotations[key]) {
|
|
1539
|
+
annotations4[annotationId] = echoAnnotations[key];
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
annotations4[TypeIdentifierAnnotationId] = decodeTypeIdentifierAnnotation(schema);
|
|
1544
|
+
const typeAnnotation = decodeTypeAnnotation(schema);
|
|
1545
|
+
if (typeAnnotation) {
|
|
1546
|
+
annotations4[TypeAnnotationId] = typeAnnotation;
|
|
1547
|
+
annotations4[SchemaAST6.JSONSchemaAnnotationId] = makeTypeJsonSchemaAnnotation({
|
|
1548
|
+
kind: typeAnnotation.kind,
|
|
1549
|
+
typename: typeAnnotation.typename,
|
|
1550
|
+
version: typeAnnotation.version,
|
|
1551
|
+
relationSource: typeAnnotation.sourceSchema,
|
|
1552
|
+
relationTarget: typeAnnotation.targetSchema
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
for (const [key, annotationId] of Object.entries({
|
|
1556
|
+
...CustomAnnotations,
|
|
1557
|
+
...DecodedAnnotations
|
|
1558
|
+
})) {
|
|
1559
|
+
if (key in schema) {
|
|
1560
|
+
annotations4[annotationId] = schema[key];
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
return clearUndefined(annotations4);
|
|
1564
|
+
};
|
|
1565
|
+
var makeAnnotatedRefinement = (ast, annotations4) => {
|
|
1566
|
+
return new SchemaAST6.Refinement(ast, () => Option2.none(), annotations4);
|
|
1567
|
+
};
|
|
1568
|
+
var addJsonSchemaFields = (ast, schema) => makeAnnotatedRefinement(ast, {
|
|
1569
|
+
[SchemaAST6.JSONSchemaAnnotationId]: schema
|
|
1570
|
+
});
|
|
1571
|
+
var normalizeJsonSchema = (jsonSchema) => {
|
|
1572
|
+
if (jsonSchema.properties && "id" in jsonSchema.properties) {
|
|
1573
|
+
jsonSchema.properties = orderKeys(jsonSchema.properties, [
|
|
1574
|
+
"id"
|
|
1575
|
+
]);
|
|
1576
|
+
}
|
|
1577
|
+
jsonSchema.$schema = JSON_SCHEMA_URL;
|
|
1578
|
+
jsonSchema = orderKeys(jsonSchema, [
|
|
1579
|
+
"$schema",
|
|
1580
|
+
"$id",
|
|
1581
|
+
"entityKind",
|
|
1582
|
+
"typename",
|
|
1583
|
+
"version",
|
|
1584
|
+
"relationTarget",
|
|
1585
|
+
"relationSource",
|
|
1586
|
+
"type",
|
|
1587
|
+
"enum",
|
|
1588
|
+
"properties",
|
|
1589
|
+
"required",
|
|
1590
|
+
"propertyOrder",
|
|
1591
|
+
"items",
|
|
1592
|
+
"additionalProperties",
|
|
1593
|
+
"anyOf",
|
|
1594
|
+
"oneOf"
|
|
1595
|
+
]);
|
|
1596
|
+
return jsonSchema;
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
// src/internal/object/common.ts
|
|
1600
|
+
import * as Schema11 from "effect/Schema";
|
|
1601
|
+
var makeTypedEntityClass = (typename, version, baseSchema) => {
|
|
1602
|
+
return class {
|
|
1603
|
+
// Implement TypedObject properties.
|
|
1604
|
+
static typename = typename;
|
|
1605
|
+
static version = version;
|
|
1606
|
+
// Implement Schema.Schema properties.
|
|
1607
|
+
// TODO(burdon): Comment required.
|
|
1608
|
+
static [Schema11.TypeId] = schemaVariance;
|
|
1609
|
+
static ast = baseSchema.ast;
|
|
1610
|
+
static annotations = baseSchema.annotations.bind(baseSchema);
|
|
1611
|
+
static pipe = baseSchema.pipe.bind(baseSchema);
|
|
1612
|
+
// TODO(burdon): Comment required.
|
|
1613
|
+
static [Symbol.hasInstance](obj) {
|
|
1614
|
+
return obj != null && getTypename(obj) === typename;
|
|
1615
|
+
}
|
|
1616
|
+
// TODO(burdon): Throw APIError.
|
|
1617
|
+
constructor() {
|
|
1618
|
+
throw new Error("Use live(Typename, { ...fields }) to instantiate an object.");
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
};
|
|
1622
|
+
var schemaVariance = {
|
|
1623
|
+
_A: (_) => _,
|
|
1624
|
+
_I: (_) => _,
|
|
1625
|
+
_R: (_) => _
|
|
1626
|
+
};
|
|
1627
|
+
|
|
1628
|
+
// src/internal/object/create-object.ts
|
|
1629
|
+
import { raise as raise4 } from "@dxos/debug";
|
|
1630
|
+
import { assertArgument as assertArgument6, failedInvariant } from "@dxos/invariant";
|
|
1631
|
+
import { ObjectId as ObjectId6 } from "@dxos/keys";
|
|
1632
|
+
import { defineHiddenProperty as defineHiddenProperty2 } from "@dxos/live-object";
|
|
1633
|
+
|
|
1634
|
+
// src/internal/object/inspect.ts
|
|
1635
|
+
import { inspectCustom } from "@dxos/debug";
|
|
1636
|
+
var attachedTypedObjectInspector = (obj) => {
|
|
1637
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, inspectCustom);
|
|
1638
|
+
if (descriptor) {
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
Object.defineProperty(obj, inspectCustom, {
|
|
1642
|
+
value: typedObjectInspectFunction,
|
|
1643
|
+
writable: false,
|
|
1644
|
+
enumerable: false,
|
|
1645
|
+
configurable: true
|
|
1646
|
+
});
|
|
1647
|
+
};
|
|
1648
|
+
var typedObjectInspectFunction = function(depth, options, inspect) {
|
|
1649
|
+
const { id, ...props } = this;
|
|
1650
|
+
return inspect({
|
|
1651
|
+
id,
|
|
1652
|
+
[ATTR_TYPE]: getTypeDXN(this),
|
|
1653
|
+
...props,
|
|
1654
|
+
[ATTR_META]: this[MetaId]
|
|
1655
|
+
}, options);
|
|
1656
|
+
};
|
|
1657
|
+
|
|
1658
|
+
// src/internal/object/json-serializer.ts
|
|
1659
|
+
import * as Schema12 from "effect/Schema";
|
|
1660
|
+
import { raise as raise3 } from "@dxos/debug";
|
|
1661
|
+
import { isEncodedReference } from "@dxos/echo-protocol";
|
|
1662
|
+
import { assertArgument as assertArgument5, invariant as invariant8 } from "@dxos/invariant";
|
|
1663
|
+
import { DXN as DXN6, ObjectId as ObjectId5 } from "@dxos/keys";
|
|
1664
|
+
import { defineHiddenProperty } from "@dxos/live-object";
|
|
1665
|
+
import { assumeType as assumeType3, deepMapValues, visitValues } from "@dxos/util";
|
|
1666
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/object/json-serializer.ts";
|
|
1667
|
+
var objectToJSON = (obj) => {
|
|
1668
|
+
const typename = getTypeDXN(obj)?.toString();
|
|
1669
|
+
invariant8(typename && typeof typename === "string", void 0, {
|
|
1670
|
+
F: __dxlog_file8,
|
|
1671
|
+
L: 59,
|
|
1672
|
+
S: void 0,
|
|
1673
|
+
A: [
|
|
1674
|
+
"typename && typeof typename === 'string'",
|
|
1675
|
+
""
|
|
1676
|
+
]
|
|
1677
|
+
});
|
|
1678
|
+
return typedJsonSerializer.call(obj);
|
|
1679
|
+
};
|
|
1680
|
+
var objectFromJSON = async (jsonData, { refResolver, dxn } = {}) => {
|
|
1681
|
+
assumeType3(jsonData);
|
|
1682
|
+
assertArgument5(typeof jsonData === "object" && jsonData !== null, "jsonData", "expect object");
|
|
1683
|
+
assertArgument5(typeof jsonData[ATTR_TYPE] === "string", "jsonData[ATTR_TYPE]", "expected object to have a type");
|
|
1684
|
+
assertArgument5(typeof jsonData.id === "string", "jsonData.id", "expected object to have an id");
|
|
1685
|
+
const type = DXN6.parse(jsonData[ATTR_TYPE]);
|
|
1686
|
+
const schema = await refResolver?.resolveSchema(type);
|
|
1687
|
+
invariant8(schema === void 0 || Schema12.isSchema(schema), void 0, {
|
|
1688
|
+
F: __dxlog_file8,
|
|
1689
|
+
L: 80,
|
|
1690
|
+
S: void 0,
|
|
1691
|
+
A: [
|
|
1692
|
+
"schema === undefined || Schema.isSchema(schema)",
|
|
1693
|
+
""
|
|
1694
|
+
]
|
|
1695
|
+
});
|
|
1696
|
+
let obj;
|
|
1697
|
+
if (schema != null) {
|
|
1698
|
+
obj = await schema.pipe(Schema12.decodeUnknownPromise)(jsonData);
|
|
1699
|
+
if (refResolver) {
|
|
1700
|
+
setRefResolverOnData(obj, refResolver);
|
|
1701
|
+
}
|
|
1702
|
+
} else {
|
|
1703
|
+
obj = decodeGeneric(jsonData, {
|
|
1704
|
+
refResolver
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
invariant8(ObjectId5.isValid(obj.id), "Invalid object id", {
|
|
1708
|
+
F: __dxlog_file8,
|
|
1709
|
+
L: 92,
|
|
1710
|
+
S: void 0,
|
|
1711
|
+
A: [
|
|
1712
|
+
"ObjectId.isValid(obj.id)",
|
|
1713
|
+
"'Invalid object id'"
|
|
1714
|
+
]
|
|
1715
|
+
});
|
|
1716
|
+
setTypename(obj, type);
|
|
1717
|
+
if (schema) {
|
|
1718
|
+
setSchema(obj, schema);
|
|
1719
|
+
}
|
|
1720
|
+
const isRelation = typeof jsonData[ATTR_RELATION_SOURCE] === "string" || typeof jsonData[ATTR_RELATION_TARGET] === "string";
|
|
1721
|
+
if (isRelation) {
|
|
1722
|
+
const sourceDxn = DXN6.parse(jsonData[ATTR_RELATION_SOURCE] ?? raise3(new TypeError("Missing relation source")));
|
|
1723
|
+
const targetDxn = DXN6.parse(jsonData[ATTR_RELATION_TARGET] ?? raise3(new TypeError("Missing relation target")));
|
|
1724
|
+
const source = await refResolver?.resolve(sourceDxn);
|
|
1725
|
+
const target = await refResolver?.resolve(targetDxn);
|
|
1726
|
+
defineHiddenProperty(obj, KindId, EntityKind.Relation);
|
|
1727
|
+
defineHiddenProperty(obj, RelationSourceDXNId, sourceDxn);
|
|
1728
|
+
defineHiddenProperty(obj, RelationTargetDXNId, targetDxn);
|
|
1729
|
+
defineHiddenProperty(obj, RelationSourceId, source);
|
|
1730
|
+
defineHiddenProperty(obj, RelationTargetId, target);
|
|
1731
|
+
} else {
|
|
1732
|
+
defineHiddenProperty(obj, KindId, EntityKind.Object);
|
|
1733
|
+
}
|
|
1734
|
+
if (typeof jsonData[ATTR_META] === "object") {
|
|
1735
|
+
const meta = await ObjectMetaSchema.pipe(Schema12.decodeUnknownPromise)(jsonData[ATTR_META]);
|
|
1736
|
+
invariant8(Array.isArray(meta.keys), void 0, {
|
|
1737
|
+
F: __dxlog_file8,
|
|
1738
|
+
L: 118,
|
|
1739
|
+
S: void 0,
|
|
1740
|
+
A: [
|
|
1741
|
+
"Array.isArray(meta.keys)",
|
|
1742
|
+
""
|
|
1743
|
+
]
|
|
1744
|
+
});
|
|
1745
|
+
defineHiddenProperty(obj, MetaId, meta);
|
|
1746
|
+
}
|
|
1747
|
+
if (dxn) {
|
|
1748
|
+
defineHiddenProperty(obj, SelfDXNId, dxn);
|
|
1749
|
+
}
|
|
1750
|
+
assertObjectModel(obj);
|
|
1751
|
+
invariant8(obj[ATTR_TYPE] === void 0, "Invalid object model", {
|
|
1752
|
+
F: __dxlog_file8,
|
|
1753
|
+
L: 127,
|
|
1754
|
+
S: void 0,
|
|
1755
|
+
A: [
|
|
1756
|
+
"(obj as any)[ATTR_TYPE] === undefined",
|
|
1757
|
+
"'Invalid object model'"
|
|
1758
|
+
]
|
|
1759
|
+
});
|
|
1760
|
+
invariant8(obj[ATTR_META] === void 0, "Invalid object model", {
|
|
1761
|
+
F: __dxlog_file8,
|
|
1762
|
+
L: 128,
|
|
1763
|
+
S: void 0,
|
|
1764
|
+
A: [
|
|
1765
|
+
"(obj as any)[ATTR_META] === undefined",
|
|
1766
|
+
"'Invalid object model'"
|
|
1767
|
+
]
|
|
1768
|
+
});
|
|
1769
|
+
invariant8(obj[ATTR_DELETED] === void 0, "Invalid object model", {
|
|
1770
|
+
F: __dxlog_file8,
|
|
1771
|
+
L: 129,
|
|
1772
|
+
S: void 0,
|
|
1773
|
+
A: [
|
|
1774
|
+
"(obj as any)[ATTR_DELETED] === undefined",
|
|
1775
|
+
"'Invalid object model'"
|
|
1776
|
+
]
|
|
1777
|
+
});
|
|
1778
|
+
invariant8(obj[ATTR_SELF_DXN] === void 0, "Invalid object model", {
|
|
1779
|
+
F: __dxlog_file8,
|
|
1780
|
+
L: 130,
|
|
1781
|
+
S: void 0,
|
|
1782
|
+
A: [
|
|
1783
|
+
"(obj as any)[ATTR_SELF_DXN] === undefined",
|
|
1784
|
+
"'Invalid object model'"
|
|
1785
|
+
]
|
|
1786
|
+
});
|
|
1787
|
+
invariant8(obj[ATTR_RELATION_SOURCE] === void 0, "Invalid object model", {
|
|
1788
|
+
F: __dxlog_file8,
|
|
1789
|
+
L: 131,
|
|
1790
|
+
S: void 0,
|
|
1791
|
+
A: [
|
|
1792
|
+
"(obj as any)[ATTR_RELATION_SOURCE] === undefined",
|
|
1793
|
+
"'Invalid object model'"
|
|
1794
|
+
]
|
|
1795
|
+
});
|
|
1796
|
+
invariant8(obj[ATTR_RELATION_TARGET] === void 0, "Invalid object model", {
|
|
1797
|
+
F: __dxlog_file8,
|
|
1798
|
+
L: 132,
|
|
1799
|
+
S: void 0,
|
|
1800
|
+
A: [
|
|
1801
|
+
"(obj as any)[ATTR_RELATION_TARGET] === undefined",
|
|
1802
|
+
"'Invalid object model'"
|
|
1803
|
+
]
|
|
1804
|
+
});
|
|
1805
|
+
return obj;
|
|
1806
|
+
};
|
|
1807
|
+
var decodeGeneric = (jsonData, options) => {
|
|
1808
|
+
const { [ATTR_TYPE]: _type, [ATTR_META]: _meta, [ATTR_DELETED]: _deleted, [ATTR_SELF_DXN]: _selfDxn, [ATTR_RELATION_SOURCE]: _relationSource, [ATTR_RELATION_TARGET]: _relationTarget, ...props } = jsonData;
|
|
1809
|
+
return deepMapValues(props, (value, visitor) => {
|
|
1810
|
+
if (isEncodedReference(value)) {
|
|
1811
|
+
return refFromEncodedReference(value, options.refResolver);
|
|
1812
|
+
}
|
|
1813
|
+
return visitor(value);
|
|
1814
|
+
});
|
|
1815
|
+
};
|
|
1816
|
+
var setRefResolverOnData = (obj, refResolver) => {
|
|
1817
|
+
const visitor = (value) => {
|
|
1818
|
+
if (Ref.isRef(value)) {
|
|
1819
|
+
setRefResolver(value, refResolver);
|
|
1820
|
+
} else {
|
|
1821
|
+
visitValues(value, visitor);
|
|
1822
|
+
}
|
|
1823
|
+
};
|
|
1824
|
+
visitor(obj);
|
|
1825
|
+
};
|
|
1826
|
+
var attachTypedJsonSerializer = (obj) => {
|
|
1827
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, "toJSON");
|
|
1828
|
+
if (descriptor) {
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
Object.defineProperty(obj, "toJSON", {
|
|
1832
|
+
value: typedJsonSerializer,
|
|
1833
|
+
writable: false,
|
|
1834
|
+
enumerable: false,
|
|
1835
|
+
// Setting `configurable` to false breaks proxy invariants, should be fixable.
|
|
1836
|
+
configurable: true
|
|
1837
|
+
});
|
|
1838
|
+
};
|
|
1839
|
+
var typedJsonSerializer = function() {
|
|
1840
|
+
const { id, ...rest } = this;
|
|
1841
|
+
const result = {
|
|
1842
|
+
id
|
|
1843
|
+
};
|
|
1844
|
+
if (this[TypeId]) {
|
|
1845
|
+
result[ATTR_TYPE] = this[TypeId].toString();
|
|
1846
|
+
}
|
|
1847
|
+
if (this[MetaId]) {
|
|
1848
|
+
result[ATTR_META] = serializeMeta(this[MetaId]);
|
|
1849
|
+
}
|
|
1850
|
+
if (this[SelfDXNId]) {
|
|
1851
|
+
result[ATTR_SELF_DXN] = this[SelfDXNId].toString();
|
|
1852
|
+
}
|
|
1853
|
+
if (this[RelationSourceDXNId]) {
|
|
1854
|
+
const sourceDXN = this[RelationSourceDXNId];
|
|
1855
|
+
invariant8(sourceDXN instanceof DXN6, void 0, {
|
|
1856
|
+
F: __dxlog_file8,
|
|
1857
|
+
L: 204,
|
|
1858
|
+
S: this,
|
|
1859
|
+
A: [
|
|
1860
|
+
"sourceDXN instanceof DXN",
|
|
1861
|
+
""
|
|
1862
|
+
]
|
|
1863
|
+
});
|
|
1864
|
+
result[ATTR_RELATION_SOURCE] = sourceDXN.toString();
|
|
1865
|
+
}
|
|
1866
|
+
if (this[RelationTargetDXNId]) {
|
|
1867
|
+
const targetDXN = this[RelationTargetDXNId];
|
|
1868
|
+
invariant8(targetDXN instanceof DXN6, void 0, {
|
|
1869
|
+
F: __dxlog_file8,
|
|
1870
|
+
L: 209,
|
|
1871
|
+
S: this,
|
|
1872
|
+
A: [
|
|
1873
|
+
"targetDXN instanceof DXN",
|
|
1874
|
+
""
|
|
1875
|
+
]
|
|
1876
|
+
});
|
|
1877
|
+
result[ATTR_RELATION_TARGET] = targetDXN.toString();
|
|
1878
|
+
}
|
|
1879
|
+
Object.assign(result, serializeData(rest));
|
|
1880
|
+
return result;
|
|
1881
|
+
};
|
|
1882
|
+
var serializeData = (data) => {
|
|
1883
|
+
return deepMapValues(data, (value, recurse) => {
|
|
1884
|
+
if (Ref.isRef(value)) {
|
|
1885
|
+
return value.noInline().encode();
|
|
1886
|
+
}
|
|
1887
|
+
return recurse(value);
|
|
1888
|
+
});
|
|
1889
|
+
};
|
|
1890
|
+
var serializeMeta = (meta) => {
|
|
1891
|
+
return deepMapValues(meta, (value, recurse) => recurse(value));
|
|
1892
|
+
};
|
|
1893
|
+
|
|
1894
|
+
// src/internal/object/create-object.ts
|
|
1895
|
+
var createObject = (schema, props) => {
|
|
1896
|
+
const annotation = getTypeAnnotation(schema);
|
|
1897
|
+
if (!annotation) {
|
|
1898
|
+
throw new Error("Schema is not an ECHO schema");
|
|
1899
|
+
}
|
|
1900
|
+
assertArgument6(!("@type" in props), "data", "@type is not allowed");
|
|
1901
|
+
assertArgument6(!(RelationSourceDXNId in props), "data", "Relation source DXN is not allowed in the constructor");
|
|
1902
|
+
assertArgument6(!(RelationTargetDXNId in props), "data", "Relation target DXN is not allowed in the constructor");
|
|
1903
|
+
assertArgument6(RelationSourceId in props === RelationTargetId in props, "data", "Relation source and target must be provided together");
|
|
1904
|
+
const obj = {
|
|
1905
|
+
...props,
|
|
1906
|
+
id: props.id ?? ObjectId6.random()
|
|
1907
|
+
};
|
|
1908
|
+
const kind = RelationSourceId in props ? EntityKind.Relation : EntityKind.Object;
|
|
1909
|
+
defineHiddenProperty2(obj, KindId, kind);
|
|
1910
|
+
defineHiddenProperty2(obj, MetaId, {
|
|
1911
|
+
keys: []
|
|
1912
|
+
});
|
|
1913
|
+
setSchema(obj, schema);
|
|
1914
|
+
setTypename(obj, getSchemaDXN(schema) ?? failedInvariant("Missing schema DXN"));
|
|
1915
|
+
attachTypedJsonSerializer(obj);
|
|
1916
|
+
attachedTypedObjectInspector(obj);
|
|
1917
|
+
if (kind === EntityKind.Relation) {
|
|
1918
|
+
const sourceDXN = getObjectDXN(props[RelationSourceId]) ?? raise4(new Error("Unresolved relation source"));
|
|
1919
|
+
const targetDXN = getObjectDXN(props[RelationTargetId]) ?? raise4(new Error("Unresolved relation target"));
|
|
1920
|
+
defineHiddenProperty2(obj, RelationSourceDXNId, sourceDXN);
|
|
1921
|
+
defineHiddenProperty2(obj, RelationTargetDXNId, targetDXN);
|
|
1922
|
+
}
|
|
1923
|
+
assertObjectModel(obj);
|
|
1924
|
+
return obj;
|
|
1925
|
+
};
|
|
1926
|
+
|
|
1927
|
+
// src/internal/object/deleted.ts
|
|
1928
|
+
var isDeleted = (obj) => {
|
|
1929
|
+
if (obj[ObjectDeletedId] === void 0) {
|
|
1930
|
+
return false;
|
|
1931
|
+
}
|
|
1932
|
+
return obj[ObjectDeletedId] ?? false;
|
|
1933
|
+
};
|
|
1934
|
+
|
|
1935
|
+
// src/internal/object/ids.ts
|
|
1936
|
+
import { DXN as DXN7, ObjectId as ObjectId7, QueueSubspaceTags, SpaceId } from "@dxos/keys";
|
|
1937
|
+
var createQueueDXN = (spaceId = SpaceId.random(), queueId = ObjectId7.random()) => new DXN7(DXN7.kind.QUEUE, [
|
|
1938
|
+
QueueSubspaceTags.DATA,
|
|
1939
|
+
spaceId,
|
|
1940
|
+
queueId
|
|
1941
|
+
]);
|
|
1942
|
+
|
|
1943
|
+
// src/internal/object/schema-validator.ts
|
|
1944
|
+
import * as Schema13 from "effect/Schema";
|
|
1945
|
+
import * as SchemaAST7 from "effect/SchemaAST";
|
|
1946
|
+
import { invariant as invariant9 } from "@dxos/invariant";
|
|
1947
|
+
import { log as log2 } from "@dxos/log";
|
|
1948
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/object/schema-validator.ts";
|
|
1949
|
+
var SchemaValidator = class {
|
|
1950
|
+
/**
|
|
1951
|
+
* Recursively check that schema specifies constructions we can handle.
|
|
1952
|
+
* Validates there are no ambiguous discriminated union types.
|
|
1953
|
+
*/
|
|
1954
|
+
static validateSchema(schema) {
|
|
1955
|
+
const visitAll = (nodes) => nodes.forEach((node) => this.validateSchema(Schema13.make(node)));
|
|
1956
|
+
if (SchemaAST7.isUnion(schema.ast)) {
|
|
1957
|
+
const typeAstList = schema.ast.types.filter((type) => SchemaAST7.isTypeLiteral(type));
|
|
1958
|
+
if (typeAstList.length > 1) {
|
|
1959
|
+
getTypeDiscriminators(typeAstList);
|
|
1960
|
+
}
|
|
1961
|
+
visitAll(typeAstList);
|
|
1962
|
+
} else if (SchemaAST7.isTupleType(schema.ast)) {
|
|
1963
|
+
const positionalTypes = schema.ast.elements.map((t) => t.type);
|
|
1964
|
+
const allTypes = positionalTypes.concat(schema.ast.rest.map((t) => t.type));
|
|
1965
|
+
visitAll(allTypes);
|
|
1966
|
+
} else if (SchemaAST7.isTypeLiteral(schema.ast)) {
|
|
1967
|
+
visitAll(SchemaAST7.getPropertySignatures(schema.ast).map((p) => p.type));
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
static hasTypeAnnotation(rootObjectSchema, property, annotation) {
|
|
1971
|
+
try {
|
|
1972
|
+
let type = this.getPropertySchema(rootObjectSchema, [
|
|
1973
|
+
property
|
|
1974
|
+
]);
|
|
1975
|
+
if (SchemaAST7.isTupleType(type.ast)) {
|
|
1976
|
+
type = this.getPropertySchema(rootObjectSchema, [
|
|
1977
|
+
property,
|
|
1978
|
+
"0"
|
|
1979
|
+
]);
|
|
1980
|
+
}
|
|
1981
|
+
return type.ast.annotations[annotation] != null;
|
|
1982
|
+
} catch {
|
|
1983
|
+
return false;
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
static getPropertySchema(rootObjectSchema, propertyPath, getProperty = () => null) {
|
|
1987
|
+
let schema = rootObjectSchema;
|
|
1988
|
+
for (let i = 0; i < propertyPath.length; i++) {
|
|
1989
|
+
const propertyName = propertyPath[i];
|
|
1990
|
+
const tupleAst = unwrapArray(schema.ast);
|
|
1991
|
+
if (tupleAst != null) {
|
|
1992
|
+
schema = getArrayElementSchema(tupleAst, propertyName);
|
|
1993
|
+
} else {
|
|
1994
|
+
const propertyType = getPropertyType(schema.ast, propertyName.toString(), (propertyName2) => getProperty([
|
|
1995
|
+
...propertyPath.slice(0, i),
|
|
1996
|
+
propertyName2
|
|
1997
|
+
]));
|
|
1998
|
+
if (propertyType == null) {
|
|
1999
|
+
log2.warn("unknown property", {
|
|
2000
|
+
path: propertyPath,
|
|
2001
|
+
property: propertyName
|
|
2002
|
+
}, {
|
|
2003
|
+
F: __dxlog_file9,
|
|
2004
|
+
L: 71,
|
|
2005
|
+
S: this,
|
|
2006
|
+
C: (f, a) => f(...a)
|
|
2007
|
+
});
|
|
2008
|
+
continue;
|
|
2009
|
+
}
|
|
2010
|
+
schema = Schema13.make(propertyType).annotations(propertyType.annotations);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
return schema;
|
|
2014
|
+
}
|
|
2015
|
+
static getTargetPropertySchema(target, prop) {
|
|
2016
|
+
const schema = target[SchemaId];
|
|
2017
|
+
invariant9(schema, "target has no schema", {
|
|
2018
|
+
F: __dxlog_file9,
|
|
2019
|
+
L: 84,
|
|
2020
|
+
S: this,
|
|
2021
|
+
A: [
|
|
2022
|
+
"schema",
|
|
2023
|
+
"'target has no schema'"
|
|
2024
|
+
]
|
|
2025
|
+
});
|
|
2026
|
+
const arrayAst = unwrapArray(schema.ast);
|
|
2027
|
+
if (arrayAst != null) {
|
|
2028
|
+
return getArrayElementSchema(arrayAst, prop);
|
|
2029
|
+
}
|
|
2030
|
+
const propertyType = getPropertyType(schema.ast, prop.toString(), (prop2) => target[prop2]);
|
|
2031
|
+
if (propertyType == null) {
|
|
2032
|
+
return Schema13.Any;
|
|
2033
|
+
}
|
|
2034
|
+
invariant9(propertyType, `invalid property: ${prop.toString()}`, {
|
|
2035
|
+
F: __dxlog_file9,
|
|
2036
|
+
L: 95,
|
|
2037
|
+
S: this,
|
|
2038
|
+
A: [
|
|
2039
|
+
"propertyType",
|
|
2040
|
+
"`invalid property: ${prop.toString()}`"
|
|
2041
|
+
]
|
|
2042
|
+
});
|
|
2043
|
+
return Schema13.make(propertyType);
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
2046
|
+
var getArrayElementSchema = (tupleAst, property) => {
|
|
2047
|
+
const elementIndex = typeof property === "string" ? parseInt(property, 10) : Number.NaN;
|
|
2048
|
+
if (Number.isNaN(elementIndex)) {
|
|
2049
|
+
invariant9(property === "length", `invalid array property: ${String(property)}`, {
|
|
2050
|
+
F: __dxlog_file9,
|
|
2051
|
+
L: 111,
|
|
2052
|
+
S: void 0,
|
|
2053
|
+
A: [
|
|
2054
|
+
"property === 'length'",
|
|
2055
|
+
"`invalid array property: ${String(property)}`"
|
|
2056
|
+
]
|
|
2057
|
+
});
|
|
2058
|
+
return Schema13.Number;
|
|
2059
|
+
}
|
|
2060
|
+
if (elementIndex < tupleAst.elements.length) {
|
|
2061
|
+
const elementType = tupleAst.elements[elementIndex].type;
|
|
2062
|
+
return Schema13.make(elementType).annotations(elementType.annotations);
|
|
2063
|
+
}
|
|
2064
|
+
const restType = tupleAst.rest;
|
|
2065
|
+
return Schema13.make(restType[0].type).annotations(restType[0].annotations);
|
|
2066
|
+
};
|
|
2067
|
+
var flattenUnion = (typeAst) => SchemaAST7.isUnion(typeAst) ? typeAst.types.flatMap(flattenUnion) : [
|
|
2068
|
+
typeAst
|
|
2069
|
+
];
|
|
2070
|
+
var getProperties = (typeAst, getTargetPropertyFn) => {
|
|
2071
|
+
const astCandidates = flattenUnion(typeAst);
|
|
2072
|
+
const typeAstList = astCandidates.filter((type) => SchemaAST7.isTypeLiteral(type));
|
|
2073
|
+
if (typeAstList.length === 0) {
|
|
2074
|
+
return [];
|
|
2075
|
+
}
|
|
2076
|
+
if (typeAstList.length === 1) {
|
|
2077
|
+
return SchemaAST7.getPropertySignatures(typeAstList[0]);
|
|
2078
|
+
}
|
|
2079
|
+
const typeDiscriminators = getTypeDiscriminators(typeAstList);
|
|
2080
|
+
const targetPropertyValue = getTargetPropertyFn(String(typeDiscriminators[0].name));
|
|
2081
|
+
const typeIndex = typeDiscriminators.findIndex((p) => targetPropertyValue === p.type.literal);
|
|
2082
|
+
invariant9(typeIndex !== -1, "discriminator field not set on target", {
|
|
2083
|
+
F: __dxlog_file9,
|
|
2084
|
+
L: 142,
|
|
2085
|
+
S: void 0,
|
|
2086
|
+
A: [
|
|
2087
|
+
"typeIndex !== -1",
|
|
2088
|
+
"'discriminator field not set on target'"
|
|
2089
|
+
]
|
|
2090
|
+
});
|
|
2091
|
+
return SchemaAST7.getPropertySignatures(typeAstList[typeIndex]);
|
|
2092
|
+
};
|
|
2093
|
+
var getPropertyType = (ast, propertyName, getTargetPropertyFn) => {
|
|
2094
|
+
const anyOrObject = unwrapAst(ast, (candidate) => SchemaAST7.isAnyKeyword(candidate) || SchemaAST7.isObjectKeyword(candidate));
|
|
2095
|
+
if (anyOrObject != null) {
|
|
2096
|
+
return ast;
|
|
2097
|
+
}
|
|
2098
|
+
const typeOrDiscriminatedUnion = unwrapAst(ast, (t) => {
|
|
2099
|
+
return SchemaAST7.isTypeLiteral(t) || SchemaAST7.isUnion(t) && t.types.some((t2) => SchemaAST7.isTypeLiteral(t2));
|
|
2100
|
+
});
|
|
2101
|
+
if (typeOrDiscriminatedUnion == null) {
|
|
2102
|
+
return null;
|
|
2103
|
+
}
|
|
2104
|
+
const targetProperty = getProperties(typeOrDiscriminatedUnion, getTargetPropertyFn).find((p) => p.name === propertyName);
|
|
2105
|
+
if (targetProperty != null) {
|
|
2106
|
+
return unwrapAst(targetProperty.type);
|
|
2107
|
+
}
|
|
2108
|
+
const indexSignatureType = unwrapAst(ast, SchemaAST7.isTypeLiteral);
|
|
2109
|
+
if (indexSignatureType && SchemaAST7.isTypeLiteral(indexSignatureType) && indexSignatureType.indexSignatures.length > 0) {
|
|
2110
|
+
return unwrapAst(indexSignatureType.indexSignatures[0].type);
|
|
2111
|
+
}
|
|
2112
|
+
return null;
|
|
2113
|
+
};
|
|
2114
|
+
var getTypeDiscriminators = (typeAstList) => {
|
|
2115
|
+
const discriminatorPropCandidates = typeAstList.flatMap(SchemaAST7.getPropertySignatures).filter((p) => SchemaAST7.isLiteral(p.type));
|
|
2116
|
+
const propertyName = discriminatorPropCandidates[0].name;
|
|
2117
|
+
const isValidDiscriminator = discriminatorPropCandidates.every((p) => p.name === propertyName && !p.isOptional);
|
|
2118
|
+
const everyTypeHasDiscriminator = discriminatorPropCandidates.length === typeAstList.length;
|
|
2119
|
+
const isDiscriminatedUnion = isValidDiscriminator && everyTypeHasDiscriminator;
|
|
2120
|
+
invariant9(isDiscriminatedUnion, "type ambiguity: every type in a union must have a single unique-literal field", {
|
|
2121
|
+
F: __dxlog_file9,
|
|
2122
|
+
L: 193,
|
|
2123
|
+
S: void 0,
|
|
2124
|
+
A: [
|
|
2125
|
+
"isDiscriminatedUnion",
|
|
2126
|
+
"'type ambiguity: every type in a union must have a single unique-literal field'"
|
|
2127
|
+
]
|
|
2128
|
+
});
|
|
2129
|
+
return discriminatorPropCandidates;
|
|
2130
|
+
};
|
|
2131
|
+
var unwrapAst = (rootAst, predicate) => {
|
|
2132
|
+
let ast = rootAst;
|
|
2133
|
+
while (ast != null) {
|
|
2134
|
+
if (predicate?.(ast)) {
|
|
2135
|
+
return ast;
|
|
2136
|
+
}
|
|
2137
|
+
if (SchemaAST7.isUnion(ast)) {
|
|
2138
|
+
const next = ast.types.find((t) => predicate != null && predicate(t) || SchemaAST7.isSuspend(t));
|
|
2139
|
+
if (next != null) {
|
|
2140
|
+
ast = next;
|
|
2141
|
+
continue;
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
if (SchemaAST7.isSuspend(ast)) {
|
|
2145
|
+
ast = ast.f();
|
|
2146
|
+
} else {
|
|
2147
|
+
return predicate == null ? ast : null;
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
return null;
|
|
2151
|
+
};
|
|
2152
|
+
var unwrapArray = (ast) => unwrapAst(ast, SchemaAST7.isTupleType);
|
|
2153
|
+
var checkIdNotPresentOnSchema = (schema) => {
|
|
2154
|
+
invariant9(SchemaAST7.isTypeLiteral(schema.ast), void 0, {
|
|
2155
|
+
F: __dxlog_file9,
|
|
2156
|
+
L: 236,
|
|
2157
|
+
S: void 0,
|
|
2158
|
+
A: [
|
|
2159
|
+
"SchemaAST.isTypeLiteral(schema.ast)",
|
|
2160
|
+
""
|
|
2161
|
+
]
|
|
2162
|
+
});
|
|
2163
|
+
const idProperty = SchemaAST7.getPropertySignatures(schema.ast).find((prop) => prop.name === "id");
|
|
2164
|
+
if (idProperty != null) {
|
|
2165
|
+
throw new Error('"id" property name is reserved');
|
|
2166
|
+
}
|
|
2167
|
+
};
|
|
2168
|
+
|
|
2169
|
+
// src/internal/object/typed-object.ts
|
|
2170
|
+
import * as Schema14 from "effect/Schema";
|
|
2171
|
+
import * as SchemaAST8 from "effect/SchemaAST";
|
|
2172
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2173
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/object/typed-object.ts";
|
|
2174
|
+
var TypedObject = ({ typename: typenameParam, version: versionParam, disableValidation }) => {
|
|
2175
|
+
const typename = TypenameSchema.make(typenameParam, {
|
|
2176
|
+
disableValidation
|
|
2177
|
+
});
|
|
2178
|
+
const version = VersionSchema.make(versionParam, {
|
|
2179
|
+
disableValidation
|
|
2180
|
+
});
|
|
2181
|
+
return (fields, options) => {
|
|
2182
|
+
const schema = options?.record ? Schema14.Struct(fields, {
|
|
2183
|
+
key: Schema14.String,
|
|
2184
|
+
value: Schema14.Any
|
|
2185
|
+
}) : Schema14.Struct(fields);
|
|
2186
|
+
const typeSchema = Schema14.extend(Schema14.mutable(options?.partial ? Schema14.partial(schema) : schema), Schema14.Struct({
|
|
2187
|
+
id: Schema14.String
|
|
2188
|
+
}));
|
|
2189
|
+
invariant10(typeof EntityKind.Object === "string", void 0, {
|
|
2190
|
+
F: __dxlog_file10,
|
|
2191
|
+
L: 77,
|
|
2192
|
+
S: void 0,
|
|
2193
|
+
A: [
|
|
2194
|
+
"typeof EntityKind.Object === 'string'",
|
|
2195
|
+
""
|
|
2196
|
+
]
|
|
2197
|
+
});
|
|
2198
|
+
const annotatedSchema = typeSchema.annotations({
|
|
2199
|
+
[TypeAnnotationId]: {
|
|
2200
|
+
kind: EntityKind.Object,
|
|
2201
|
+
typename,
|
|
2202
|
+
version
|
|
2203
|
+
},
|
|
2204
|
+
[SchemaAST8.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
2205
|
+
kind: EntityKind.Object,
|
|
2206
|
+
typename,
|
|
2207
|
+
version
|
|
2208
|
+
})
|
|
2209
|
+
});
|
|
2210
|
+
return class TypedObject extends makeTypedEntityClass(typename, version, annotatedSchema) {
|
|
2211
|
+
};
|
|
2212
|
+
};
|
|
2213
|
+
};
|
|
2214
|
+
|
|
2215
|
+
// src/internal/proxy/make-object.ts
|
|
2216
|
+
import { ObjectId as ObjectId8 } from "@dxos/keys";
|
|
2217
|
+
import { UntypedReactiveHandler, createProxy as createProxy2, defineHiddenProperty as defineHiddenProperty4, isValidProxyTarget as isValidProxyTarget2 } from "@dxos/live-object";
|
|
2218
|
+
|
|
2219
|
+
// src/internal/proxy/typed-handler.ts
|
|
2220
|
+
import * as Schema15 from "effect/Schema";
|
|
2221
|
+
import * as SchemaAST9 from "effect/SchemaAST";
|
|
2222
|
+
import { inspectCustom as inspectCustom2 } from "@dxos/debug";
|
|
2223
|
+
import { compositeRuntime as compositeRuntime2 } from "@dxos/echo-signals/runtime";
|
|
2224
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
2225
|
+
import { ReactiveArray, createProxy, defineHiddenProperty as defineHiddenProperty3, isValidProxyTarget, objectData, symbolIsProxy } from "@dxos/live-object";
|
|
2226
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/proxy/typed-handler.ts";
|
|
2227
|
+
var symbolSignal = Symbol("signal");
|
|
2228
|
+
var symbolPropertySignal = Symbol("property-signal");
|
|
2229
|
+
var TypedReactiveHandler = class _TypedReactiveHandler {
|
|
2230
|
+
static instance = new _TypedReactiveHandler();
|
|
2231
|
+
_proxyMap = /* @__PURE__ */ new WeakMap();
|
|
2232
|
+
constructor() {
|
|
2233
|
+
}
|
|
2234
|
+
init(target) {
|
|
2235
|
+
invariant11(typeof target === "object" && target !== null, void 0, {
|
|
2236
|
+
F: __dxlog_file11,
|
|
2237
|
+
L: 65,
|
|
2238
|
+
S: this,
|
|
2239
|
+
A: [
|
|
2240
|
+
"typeof target === 'object' && target !== null",
|
|
2241
|
+
""
|
|
2242
|
+
]
|
|
2243
|
+
});
|
|
2244
|
+
invariant11(SchemaId in target, "Schema is not defined for the target", {
|
|
2245
|
+
F: __dxlog_file11,
|
|
2246
|
+
L: 66,
|
|
2247
|
+
S: this,
|
|
2248
|
+
A: [
|
|
2249
|
+
"SchemaId in target",
|
|
2250
|
+
"'Schema is not defined for the target'"
|
|
2251
|
+
]
|
|
2252
|
+
});
|
|
2253
|
+
if (!(symbolSignal in target)) {
|
|
2254
|
+
defineHiddenProperty3(target, symbolSignal, compositeRuntime2.createSignal());
|
|
2255
|
+
defineHiddenProperty3(target, symbolPropertySignal, compositeRuntime2.createSignal());
|
|
2256
|
+
}
|
|
2257
|
+
defineHiddenProperty3(target, ObjectDeletedId, false);
|
|
2258
|
+
for (const key of Object.getOwnPropertyNames(target)) {
|
|
2259
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
2260
|
+
if (descriptor.get) {
|
|
2261
|
+
continue;
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
Object.defineProperty(target, inspectCustom2, {
|
|
2265
|
+
enumerable: false,
|
|
2266
|
+
configurable: true,
|
|
2267
|
+
value: this._inspect.bind(target)
|
|
2268
|
+
});
|
|
2269
|
+
}
|
|
2270
|
+
get(target, prop, receiver) {
|
|
2271
|
+
switch (prop) {
|
|
2272
|
+
// TODO(burdon): Remove?
|
|
2273
|
+
case objectData: {
|
|
2274
|
+
target[symbolSignal].notifyRead();
|
|
2275
|
+
return toJSON(target);
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
if (Object.getOwnPropertyDescriptor(target, prop)?.get) {
|
|
2279
|
+
target[symbolPropertySignal].notifyRead();
|
|
2280
|
+
return Reflect.get(target, prop, receiver);
|
|
2281
|
+
}
|
|
2282
|
+
target[symbolSignal].notifyRead();
|
|
2283
|
+
target[symbolPropertySignal].notifyRead();
|
|
2284
|
+
const value = Reflect.get(target, prop, receiver);
|
|
2285
|
+
if (isValidProxyTarget(value)) {
|
|
2286
|
+
return createProxy(value, this);
|
|
2287
|
+
}
|
|
2288
|
+
return value;
|
|
2289
|
+
}
|
|
2290
|
+
set(target, prop, value, receiver) {
|
|
2291
|
+
if (Array.isArray(value)) {
|
|
2292
|
+
value = ReactiveArray.from(value);
|
|
2293
|
+
}
|
|
2294
|
+
let result = false;
|
|
2295
|
+
compositeRuntime2.batch(() => {
|
|
2296
|
+
const validatedValue = this._validateValue(target, prop, value);
|
|
2297
|
+
result = Reflect.set(target, prop, validatedValue, receiver);
|
|
2298
|
+
target[symbolSignal].notifyWrite();
|
|
2299
|
+
});
|
|
2300
|
+
return result;
|
|
2301
|
+
}
|
|
2302
|
+
ownKeys(target) {
|
|
2303
|
+
target[symbolSignal].notifyRead();
|
|
2304
|
+
target[symbolPropertySignal].notifyRead();
|
|
2305
|
+
return Reflect.ownKeys(target);
|
|
2306
|
+
}
|
|
2307
|
+
defineProperty(target, property, attributes) {
|
|
2308
|
+
const validatedValue = this._validateValue(target, property, attributes.value);
|
|
2309
|
+
const result = Reflect.defineProperty(target, property, {
|
|
2310
|
+
...attributes,
|
|
2311
|
+
value: validatedValue
|
|
2312
|
+
});
|
|
2313
|
+
target[symbolPropertySignal].notifyWrite();
|
|
2314
|
+
return result;
|
|
2315
|
+
}
|
|
2316
|
+
_validateValue(target, prop, value) {
|
|
2317
|
+
const schema = SchemaValidator.getTargetPropertySchema(target, prop);
|
|
2318
|
+
const _ = Schema15.asserts(schema)(value);
|
|
2319
|
+
if (Array.isArray(value)) {
|
|
2320
|
+
value = new ReactiveArray(...value);
|
|
2321
|
+
}
|
|
2322
|
+
if (isValidProxyTarget(value)) {
|
|
2323
|
+
setSchemaProperties(value, schema);
|
|
2324
|
+
}
|
|
2325
|
+
return value;
|
|
2326
|
+
}
|
|
2327
|
+
_inspect(_, options, inspectFn) {
|
|
2328
|
+
const inspected = inspectFn(this, {
|
|
2329
|
+
...options,
|
|
2330
|
+
showHidden: false,
|
|
2331
|
+
customInspect: false
|
|
2332
|
+
});
|
|
2333
|
+
return `Typed ${inspected}`;
|
|
2334
|
+
}
|
|
2335
|
+
};
|
|
2336
|
+
var toJSON = (target) => {
|
|
2337
|
+
return {
|
|
2338
|
+
"@type": "TypedReactiveObject",
|
|
2339
|
+
...target
|
|
2340
|
+
};
|
|
2341
|
+
};
|
|
2342
|
+
var setSchemaProperties = (obj, schema) => {
|
|
2343
|
+
const schemaType = getSchemaDXN(schema);
|
|
2344
|
+
if (schemaType != null) {
|
|
2345
|
+
defineHiddenProperty3(obj, TypeId, schemaType);
|
|
2346
|
+
}
|
|
2347
|
+
defineHiddenProperty3(obj, SchemaId, schema);
|
|
2348
|
+
for (const key in obj) {
|
|
2349
|
+
if (isValidProxyTarget(obj[key])) {
|
|
2350
|
+
const elementSchema = SchemaValidator.getTargetPropertySchema(obj, key);
|
|
2351
|
+
if (elementSchema != null) {
|
|
2352
|
+
setSchemaProperties(obj[key], elementSchema);
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
};
|
|
2357
|
+
var prepareTypedTarget = (target, schema) => {
|
|
2358
|
+
if (!SchemaAST9.isTypeLiteral(schema.ast)) {
|
|
2359
|
+
throw new Error("schema has to describe an object type");
|
|
2360
|
+
}
|
|
2361
|
+
SchemaValidator.validateSchema(schema);
|
|
2362
|
+
const _ = Schema15.asserts(schema)(target);
|
|
2363
|
+
makeArraysReactive(target);
|
|
2364
|
+
setSchemaProperties(target, schema);
|
|
2365
|
+
};
|
|
2366
|
+
var makeArraysReactive = (target) => {
|
|
2367
|
+
for (const key in target) {
|
|
2368
|
+
if (target[symbolIsProxy]) {
|
|
2369
|
+
continue;
|
|
2370
|
+
}
|
|
2371
|
+
if (Array.isArray(target[key])) {
|
|
2372
|
+
target[key] = ReactiveArray.from(target[key]);
|
|
2373
|
+
}
|
|
2374
|
+
if (typeof target[key] === "object") {
|
|
2375
|
+
makeArraysReactive(target[key]);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
};
|
|
2379
|
+
|
|
2380
|
+
// src/internal/proxy/make-object.ts
|
|
2381
|
+
var makeObject = (objOrSchema, obj, meta) => {
|
|
2382
|
+
if (obj && objOrSchema !== Expando) {
|
|
2383
|
+
return createReactiveObject({
|
|
2384
|
+
...obj
|
|
2385
|
+
}, meta, objOrSchema);
|
|
2386
|
+
} else if (obj && objOrSchema === Expando) {
|
|
2387
|
+
return createReactiveObject({
|
|
2388
|
+
...obj
|
|
2389
|
+
}, meta, void 0, {
|
|
2390
|
+
expando: true
|
|
2391
|
+
});
|
|
2392
|
+
} else {
|
|
2393
|
+
return createReactiveObject(objOrSchema, meta);
|
|
2394
|
+
}
|
|
2395
|
+
};
|
|
2396
|
+
var createReactiveObject = (obj, meta, schema, options) => {
|
|
2397
|
+
if (!isValidProxyTarget2(obj)) {
|
|
2398
|
+
throw new Error("Value cannot be made into a reactive object.");
|
|
2399
|
+
}
|
|
2400
|
+
if (schema) {
|
|
2401
|
+
const annotation = getTypeAnnotation(schema);
|
|
2402
|
+
const shouldGenerateId = options?.expando || !!annotation;
|
|
2403
|
+
if (shouldGenerateId) {
|
|
2404
|
+
setIdOnTarget(obj);
|
|
2405
|
+
}
|
|
2406
|
+
if (annotation) {
|
|
2407
|
+
defineHiddenProperty4(obj, KindId, annotation.kind);
|
|
2408
|
+
}
|
|
2409
|
+
initMeta(obj, meta);
|
|
2410
|
+
prepareTypedTarget(obj, schema);
|
|
2411
|
+
attachTypedJsonSerializer(obj);
|
|
2412
|
+
return createProxy2(obj, TypedReactiveHandler.instance);
|
|
2413
|
+
} else {
|
|
2414
|
+
if (options?.expando) {
|
|
2415
|
+
setIdOnTarget(obj);
|
|
2416
|
+
}
|
|
2417
|
+
initMeta(obj, meta);
|
|
2418
|
+
return createProxy2(obj, UntypedReactiveHandler.instance);
|
|
2419
|
+
}
|
|
2420
|
+
};
|
|
2421
|
+
var setIdOnTarget = (target) => {
|
|
2422
|
+
if ("id" in target && target.id !== void 0 && target.id !== null) {
|
|
2423
|
+
if (!ObjectId8.isValid(target.id)) {
|
|
2424
|
+
throw new Error("Invalid object id format.");
|
|
2425
|
+
}
|
|
2426
|
+
} else {
|
|
2427
|
+
target.id = ObjectId8.random();
|
|
2428
|
+
}
|
|
2429
|
+
};
|
|
2430
|
+
var initMeta = (obj, meta = {
|
|
2431
|
+
keys: []
|
|
2432
|
+
}) => {
|
|
2433
|
+
prepareTypedTarget(meta, ObjectMetaSchema);
|
|
2434
|
+
defineHiddenProperty4(obj, MetaId, createProxy2(meta, TypedReactiveHandler.instance));
|
|
2435
|
+
};
|
|
2436
|
+
|
|
2437
|
+
// src/internal/schema/echo-schema.ts
|
|
2438
|
+
import * as Schema18 from "effect/Schema";
|
|
2439
|
+
import * as SchemaAST11 from "effect/SchemaAST";
|
|
2440
|
+
import { invariant as invariant13 } from "@dxos/invariant";
|
|
2441
|
+
|
|
2442
|
+
// src/internal/schema/manipulation.ts
|
|
2443
|
+
import * as Schema16 from "effect/Schema";
|
|
2444
|
+
import * as SchemaAST10 from "effect/SchemaAST";
|
|
2445
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
2446
|
+
import { DXN as DXN8 } from "@dxos/keys";
|
|
2447
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/schema/manipulation.ts";
|
|
2448
|
+
var addFieldsToSchema = (schema, fields) => {
|
|
2449
|
+
const schemaExtension = Schema16.partial(Schema16.Struct(fields));
|
|
2450
|
+
return Schema16.extend(schema, schemaExtension).annotations(schema.ast.annotations);
|
|
2451
|
+
};
|
|
2452
|
+
var updateFieldsInSchema = (schema, fields) => {
|
|
2453
|
+
const ast = schema.ast;
|
|
2454
|
+
invariant12(SchemaAST10.isTypeLiteral(ast), void 0, {
|
|
2455
|
+
F: __dxlog_file12,
|
|
2456
|
+
L: 29,
|
|
2457
|
+
S: void 0,
|
|
2458
|
+
A: [
|
|
2459
|
+
"SchemaAST.isTypeLiteral(ast)",
|
|
2460
|
+
""
|
|
2461
|
+
]
|
|
2462
|
+
});
|
|
2463
|
+
const updatedProperties = [
|
|
2464
|
+
...ast.propertySignatures
|
|
2465
|
+
];
|
|
2466
|
+
const propertiesToUpdate = Schema16.partial(Schema16.Struct(fields)).ast.propertySignatures;
|
|
2467
|
+
for (const property of propertiesToUpdate) {
|
|
2468
|
+
const index = updatedProperties.findIndex((p) => p.name === property.name);
|
|
2469
|
+
if (index !== -1) {
|
|
2470
|
+
updatedProperties[index] = property;
|
|
2471
|
+
} else {
|
|
2472
|
+
updatedProperties.push(property);
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
return Schema16.make(new SchemaAST10.TypeLiteral(updatedProperties, ast.indexSignatures, ast.annotations));
|
|
2476
|
+
};
|
|
2477
|
+
var removeFieldsFromSchema = (schema, fieldNames) => {
|
|
2478
|
+
return Schema16.make(SchemaAST10.omit(schema.ast, fieldNames)).annotations(schema.ast.annotations);
|
|
2479
|
+
};
|
|
2480
|
+
var updateFieldNameInSchema = (schema, { before, after }) => {
|
|
2481
|
+
const ast = schema.ast;
|
|
2482
|
+
invariant12(SchemaAST10.isTypeLiteral(ast), void 0, {
|
|
2483
|
+
F: __dxlog_file12,
|
|
2484
|
+
L: 57,
|
|
2485
|
+
S: void 0,
|
|
2486
|
+
A: [
|
|
2487
|
+
"SchemaAST.isTypeLiteral(ast)",
|
|
2488
|
+
""
|
|
2489
|
+
]
|
|
2490
|
+
});
|
|
2491
|
+
return Schema16.make(new SchemaAST10.TypeLiteral(ast.propertySignatures.map((p) => p.name === before ? new SchemaAST10.PropertySignature(after, p.type, p.isOptional, p.isReadonly, p.annotations) : p), ast.indexSignatures, ast.annotations));
|
|
2492
|
+
};
|
|
2493
|
+
var setTypenameInSchema = (schema, typename) => {
|
|
2494
|
+
const existingAnnotation = schema.ast.annotations[TypeAnnotationId];
|
|
2495
|
+
invariant12(existingAnnotation, `Missing ${String(TypeAnnotationId)}`, {
|
|
2496
|
+
F: __dxlog_file12,
|
|
2497
|
+
L: 77,
|
|
2498
|
+
S: void 0,
|
|
2499
|
+
A: [
|
|
2500
|
+
"existingAnnotation",
|
|
2501
|
+
"`Missing ${String(TypeAnnotationId)}`"
|
|
2502
|
+
]
|
|
2503
|
+
});
|
|
2504
|
+
return schema.annotations({
|
|
2505
|
+
...schema.ast.annotations,
|
|
2506
|
+
[TypeAnnotationId]: {
|
|
2507
|
+
kind: existingAnnotation.kind,
|
|
2508
|
+
typename,
|
|
2509
|
+
version: existingAnnotation.version
|
|
2510
|
+
},
|
|
2511
|
+
[SchemaAST10.JSONSchemaAnnotationId]: {
|
|
2512
|
+
...schema.ast.annotations[SchemaAST10.JSONSchemaAnnotationId] ?? {},
|
|
2513
|
+
$id: schema.ast.annotations[TypeIdentifierAnnotationId] ?? DXN8.fromTypename(typename).toString(),
|
|
2514
|
+
typename
|
|
2515
|
+
}
|
|
2516
|
+
});
|
|
2517
|
+
};
|
|
2518
|
+
|
|
2519
|
+
// src/internal/schema/persistent-schema.ts
|
|
2520
|
+
import * as Schema17 from "effect/Schema";
|
|
2521
|
+
var PersistentEchoSchema = Schema17.Struct({
|
|
2522
|
+
name: Schema17.optional(Schema17.String),
|
|
2523
|
+
typename: TypenameSchema,
|
|
2524
|
+
version: VersionSchema,
|
|
2525
|
+
jsonSchema: JsonSchemaType
|
|
2526
|
+
}).pipe(EchoObjectSchema({
|
|
2527
|
+
typename: "dxos.org/type/Schema",
|
|
2528
|
+
version: "0.1.0"
|
|
2529
|
+
}));
|
|
2530
|
+
var PersistentSchema = PersistentEchoSchema;
|
|
2531
|
+
|
|
2532
|
+
// src/internal/schema/snapshot.ts
|
|
2533
|
+
var getSnapshot = (object) => {
|
|
2534
|
+
if (typeof object !== "object") {
|
|
2535
|
+
return object;
|
|
2536
|
+
}
|
|
2537
|
+
if (Array.isArray(object)) {
|
|
2538
|
+
return object.map(getSnapshot);
|
|
2539
|
+
}
|
|
2540
|
+
const result = {};
|
|
2541
|
+
for (const key in object) {
|
|
2542
|
+
result[key] = getSnapshot(object[key]);
|
|
2543
|
+
}
|
|
2544
|
+
return result;
|
|
2545
|
+
};
|
|
2546
|
+
|
|
2547
|
+
// src/internal/schema/echo-schema.ts
|
|
2548
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/schema/echo-schema.ts";
|
|
2549
|
+
var ImmutableSchema = class {
|
|
2550
|
+
_schema;
|
|
2551
|
+
_objectAnnotation;
|
|
2552
|
+
constructor(_schema) {
|
|
2553
|
+
this._schema = _schema;
|
|
2554
|
+
this._objectAnnotation = getTypeAnnotation(this._schema);
|
|
2555
|
+
invariant13(this._objectAnnotation, void 0, {
|
|
2556
|
+
F: __dxlog_file13,
|
|
2557
|
+
L: 47,
|
|
2558
|
+
S: this,
|
|
2559
|
+
A: [
|
|
2560
|
+
"this._objectAnnotation",
|
|
2561
|
+
""
|
|
2562
|
+
]
|
|
2563
|
+
});
|
|
2564
|
+
}
|
|
2565
|
+
//
|
|
2566
|
+
// Effect Schema (push to abstract base class).
|
|
2567
|
+
//
|
|
2568
|
+
get [Schema18.TypeId]() {
|
|
2569
|
+
return schemaVariance2;
|
|
2570
|
+
}
|
|
2571
|
+
get Type() {
|
|
2572
|
+
return this._schema.Type;
|
|
2573
|
+
}
|
|
2574
|
+
get Encoded() {
|
|
2575
|
+
return this._schema.Encoded;
|
|
2576
|
+
}
|
|
2577
|
+
get Context() {
|
|
2578
|
+
return this._schema.Context;
|
|
2579
|
+
}
|
|
2580
|
+
get ast() {
|
|
2581
|
+
return this._schema.ast;
|
|
2582
|
+
}
|
|
2583
|
+
get annotations() {
|
|
2584
|
+
return this._schema.annotations;
|
|
2585
|
+
}
|
|
2586
|
+
get pipe() {
|
|
2587
|
+
return this._schema.pipe;
|
|
2588
|
+
}
|
|
2589
|
+
//
|
|
2590
|
+
// TypedObject
|
|
2591
|
+
//
|
|
2592
|
+
get typename() {
|
|
2593
|
+
return this._objectAnnotation.typename;
|
|
2594
|
+
}
|
|
2595
|
+
get version() {
|
|
2596
|
+
return this._objectAnnotation.version;
|
|
2597
|
+
}
|
|
2598
|
+
//
|
|
2599
|
+
// BaseSchema
|
|
2600
|
+
//
|
|
2601
|
+
get readonly() {
|
|
2602
|
+
return true;
|
|
2603
|
+
}
|
|
2604
|
+
get snapshot() {
|
|
2605
|
+
return this._schema;
|
|
2606
|
+
}
|
|
2607
|
+
// TODO(burdon): Change from getter since this is expensive.
|
|
2608
|
+
get jsonSchema() {
|
|
2609
|
+
return toJsonSchema(this._schema);
|
|
2610
|
+
}
|
|
2611
|
+
get mutable() {
|
|
2612
|
+
throw new Error("Schema is readonly.");
|
|
2613
|
+
}
|
|
2614
|
+
};
|
|
2615
|
+
var EchoSchemaConstructor = () => {
|
|
2616
|
+
return class {
|
|
2617
|
+
static get _schema() {
|
|
2618
|
+
return Schema18.Union(PersistentSchema, Schema18.instanceOf(EchoSchema)).annotations(PersistentSchema.ast.annotations);
|
|
2619
|
+
}
|
|
2620
|
+
static [Schema18.TypeId] = schemaVariance2;
|
|
2621
|
+
static get ast() {
|
|
2622
|
+
const schema = this._schema;
|
|
2623
|
+
return schema.ast;
|
|
2624
|
+
}
|
|
2625
|
+
static get annotations() {
|
|
2626
|
+
const schema = this._schema;
|
|
2627
|
+
return schema.annotations.bind(schema);
|
|
2628
|
+
}
|
|
2629
|
+
static get pipe() {
|
|
2630
|
+
const schema = this._schema;
|
|
2631
|
+
return schema.pipe.bind(schema);
|
|
2632
|
+
}
|
|
2633
|
+
};
|
|
2634
|
+
};
|
|
2635
|
+
var isMutable = (schema) => {
|
|
2636
|
+
return schema instanceof EchoSchema;
|
|
2637
|
+
};
|
|
2638
|
+
var schemaVariance2 = {
|
|
2639
|
+
_A: (_) => _,
|
|
2640
|
+
_I: (_) => _,
|
|
2641
|
+
_R: (_) => _
|
|
2642
|
+
};
|
|
2643
|
+
var EchoSchema = class extends EchoSchemaConstructor() {
|
|
2644
|
+
_persistentSchema;
|
|
2645
|
+
_schema;
|
|
2646
|
+
_isDirty = true;
|
|
2647
|
+
constructor(_persistentSchema) {
|
|
2648
|
+
super(), this._persistentSchema = _persistentSchema;
|
|
2649
|
+
}
|
|
2650
|
+
//
|
|
2651
|
+
// Effect Schema (push to abstract base class).
|
|
2652
|
+
//
|
|
2653
|
+
get [Schema18.TypeId]() {
|
|
2654
|
+
return schemaVariance2;
|
|
2655
|
+
}
|
|
2656
|
+
get Type() {
|
|
2657
|
+
return this._persistentSchema;
|
|
2658
|
+
}
|
|
2659
|
+
get Encoded() {
|
|
2660
|
+
return this._persistentSchema;
|
|
2661
|
+
}
|
|
2662
|
+
get Context() {
|
|
2663
|
+
const schema = this._getSchema();
|
|
2664
|
+
return schema.Context;
|
|
2665
|
+
}
|
|
2666
|
+
get ast() {
|
|
2667
|
+
const schema = this._getSchema();
|
|
2668
|
+
return schema.ast;
|
|
2669
|
+
}
|
|
2670
|
+
get annotations() {
|
|
2671
|
+
const schema = this._getSchema();
|
|
2672
|
+
return schema.annotations.bind(schema);
|
|
2673
|
+
}
|
|
2674
|
+
get pipe() {
|
|
2675
|
+
const schema = this._getSchema();
|
|
2676
|
+
return schema.pipe.bind(schema);
|
|
2677
|
+
}
|
|
2678
|
+
//
|
|
2679
|
+
// BaseSchema
|
|
2680
|
+
//
|
|
2681
|
+
get typename() {
|
|
2682
|
+
return this._persistentSchema.typename;
|
|
2683
|
+
}
|
|
2684
|
+
get version() {
|
|
2685
|
+
return this._persistentSchema.version;
|
|
2686
|
+
}
|
|
2687
|
+
get readonly() {
|
|
2688
|
+
return false;
|
|
2689
|
+
}
|
|
2690
|
+
/**
|
|
2691
|
+
* Returns an immutable schema snapshot of the current state of the schema.
|
|
2692
|
+
*/
|
|
2693
|
+
get snapshot() {
|
|
2694
|
+
return this._getSchema();
|
|
2695
|
+
}
|
|
2696
|
+
/**
|
|
2697
|
+
* @reactive
|
|
2698
|
+
*/
|
|
2699
|
+
get jsonSchema() {
|
|
2700
|
+
return this._persistentSchema.jsonSchema;
|
|
2701
|
+
}
|
|
2702
|
+
/**
|
|
2703
|
+
* Returns a mutable schema.
|
|
2704
|
+
*/
|
|
2705
|
+
get mutable() {
|
|
2706
|
+
invariant13(!this.readonly, "Schema is not mutable", {
|
|
2707
|
+
F: __dxlog_file13,
|
|
2708
|
+
L: 262,
|
|
2709
|
+
S: this,
|
|
2710
|
+
A: [
|
|
2711
|
+
"!this.readonly",
|
|
2712
|
+
"'Schema is not mutable'"
|
|
2713
|
+
]
|
|
2714
|
+
});
|
|
2715
|
+
return this;
|
|
2716
|
+
}
|
|
2717
|
+
//
|
|
2718
|
+
// Mutable Schema
|
|
2719
|
+
//
|
|
2720
|
+
/**
|
|
2721
|
+
* Id of the ECHO object containing the schema.
|
|
2722
|
+
*/
|
|
2723
|
+
get id() {
|
|
2724
|
+
return this._persistentSchema.id;
|
|
2725
|
+
}
|
|
2726
|
+
/**
|
|
2727
|
+
* Short name of the schema.
|
|
2728
|
+
*/
|
|
2729
|
+
get name() {
|
|
2730
|
+
return this._persistentSchema.name;
|
|
2731
|
+
}
|
|
2732
|
+
get [SchemaMetaSymbol]() {
|
|
2733
|
+
return {
|
|
2734
|
+
id: this.id,
|
|
2735
|
+
typename: this.typename,
|
|
2736
|
+
version: this._persistentSchema.version
|
|
2737
|
+
};
|
|
2738
|
+
}
|
|
2739
|
+
/**
|
|
2740
|
+
* Reference to the underlying persistent schema object.
|
|
2741
|
+
*/
|
|
2742
|
+
get persistentSchema() {
|
|
2743
|
+
return this._persistentSchema;
|
|
2744
|
+
}
|
|
2745
|
+
getProperties() {
|
|
2746
|
+
const ast = this._getSchema().ast;
|
|
2747
|
+
invariant13(SchemaAST11.isTypeLiteral(ast), void 0, {
|
|
2748
|
+
F: __dxlog_file13,
|
|
2749
|
+
L: 297,
|
|
2750
|
+
S: this,
|
|
2751
|
+
A: [
|
|
2752
|
+
"SchemaAST.isTypeLiteral(ast)",
|
|
2753
|
+
""
|
|
2754
|
+
]
|
|
2755
|
+
});
|
|
2756
|
+
return [
|
|
2757
|
+
...ast.propertySignatures
|
|
2758
|
+
].filter((p) => p.name !== "id").map(unwrapOptionality);
|
|
2759
|
+
}
|
|
2760
|
+
//
|
|
2761
|
+
// Mutation methods.
|
|
2762
|
+
// TODO(burdon): Create separate interface for dynamic schema.
|
|
2763
|
+
// TODO(burdon): Deprecate direct manipulation? Use JSONSchema directly.
|
|
2764
|
+
//
|
|
2765
|
+
/**
|
|
2766
|
+
* @throws Error if the schema is readonly.
|
|
2767
|
+
*/
|
|
2768
|
+
updateTypename(typename) {
|
|
2769
|
+
const updated = setTypenameInSchema(this._getSchema(), typename);
|
|
2770
|
+
this._persistentSchema.typename = typename;
|
|
2771
|
+
this._persistentSchema.jsonSchema = toJsonSchema(updated);
|
|
2772
|
+
}
|
|
2773
|
+
/**
|
|
2774
|
+
* @throws Error if the schema is readonly.
|
|
2775
|
+
*/
|
|
2776
|
+
addFields(fields) {
|
|
2777
|
+
const extended = addFieldsToSchema(this._getSchema(), fields);
|
|
2778
|
+
this._persistentSchema.jsonSchema = toJsonSchema(extended);
|
|
2779
|
+
}
|
|
2780
|
+
/**
|
|
2781
|
+
* @throws Error if the schema is readonly.
|
|
2782
|
+
*/
|
|
2783
|
+
updateFields(fields) {
|
|
2784
|
+
const updated = updateFieldsInSchema(this._getSchema(), fields);
|
|
2785
|
+
this._persistentSchema.jsonSchema = toJsonSchema(updated);
|
|
2786
|
+
}
|
|
2787
|
+
/**
|
|
2788
|
+
* @throws Error if the schema is readonly.
|
|
2789
|
+
*/
|
|
2790
|
+
updateFieldPropertyName({ before, after }) {
|
|
2791
|
+
const renamed = updateFieldNameInSchema(this._getSchema(), {
|
|
2792
|
+
before,
|
|
2793
|
+
after
|
|
2794
|
+
});
|
|
2795
|
+
this._persistentSchema.jsonSchema = toJsonSchema(renamed);
|
|
2796
|
+
}
|
|
2797
|
+
/**
|
|
2798
|
+
* @throws Error if the schema is readonly.
|
|
2799
|
+
*/
|
|
2800
|
+
removeFields(fieldNames) {
|
|
2801
|
+
const removed = removeFieldsFromSchema(this._getSchema(), fieldNames);
|
|
2802
|
+
this._persistentSchema.jsonSchema = toJsonSchema(removed);
|
|
2803
|
+
}
|
|
2804
|
+
//
|
|
2805
|
+
// Internals
|
|
2806
|
+
//
|
|
2807
|
+
/**
|
|
2808
|
+
* Called by DatabaseSchemaRegistry on update.
|
|
2809
|
+
*/
|
|
2810
|
+
_invalidate() {
|
|
2811
|
+
this._isDirty = true;
|
|
2812
|
+
}
|
|
2813
|
+
/**
|
|
2814
|
+
* Rebuilds this schema if it is dirty.
|
|
2815
|
+
*/
|
|
2816
|
+
_rebuild() {
|
|
2817
|
+
if (this._isDirty || this._schema == null) {
|
|
2818
|
+
this._schema = toEffectSchema(getSnapshot(this._persistentSchema.jsonSchema));
|
|
2819
|
+
this._isDirty = false;
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
_getSchema() {
|
|
2823
|
+
this._rebuild();
|
|
2824
|
+
return this._schema;
|
|
2825
|
+
}
|
|
2826
|
+
};
|
|
2827
|
+
var unwrapOptionality = (property) => {
|
|
2828
|
+
if (!SchemaAST11.isUnion(property.type)) {
|
|
2829
|
+
return property;
|
|
2830
|
+
}
|
|
2831
|
+
return {
|
|
2832
|
+
...property,
|
|
2833
|
+
type: property.type.types.find((type) => !SchemaAST11.isUndefinedKeyword(type))
|
|
2834
|
+
};
|
|
2835
|
+
};
|
|
2836
|
+
|
|
2837
|
+
export {
|
|
2838
|
+
RawObject,
|
|
2839
|
+
ATTR_META,
|
|
2840
|
+
MetaId,
|
|
2841
|
+
ObjectMetaSchema,
|
|
2842
|
+
getMeta,
|
|
2843
|
+
splitMeta,
|
|
2844
|
+
foreignKey,
|
|
2845
|
+
foreignKeyEquals,
|
|
2846
|
+
compareForeignKeys,
|
|
2847
|
+
VersionTypeId,
|
|
2848
|
+
EchoObjectSchema,
|
|
2849
|
+
EXPANDO_TYPENAME,
|
|
2850
|
+
Expando,
|
|
2851
|
+
ATTR_RELATION_SOURCE,
|
|
2852
|
+
RelationSourceId,
|
|
2853
|
+
RelationSourceDXNId,
|
|
2854
|
+
ATTR_RELATION_TARGET,
|
|
2855
|
+
RelationTargetId,
|
|
2856
|
+
RelationTargetDXNId,
|
|
2857
|
+
EchoRelationSchema,
|
|
2858
|
+
ATTR_SELF_DXN,
|
|
2859
|
+
SelfDXNId,
|
|
2860
|
+
ATTR_DELETED,
|
|
2861
|
+
ObjectDeletedId,
|
|
2862
|
+
ObjectVersionId,
|
|
2863
|
+
assertObjectModel,
|
|
2864
|
+
getObjectDXN,
|
|
2865
|
+
CustomAnnotations,
|
|
2866
|
+
DecodedAnnotations,
|
|
2867
|
+
EchoAnnotations,
|
|
2868
|
+
JsonSchemaEchoAnnotations,
|
|
2869
|
+
JsonSchemaFields,
|
|
2870
|
+
JsonSchemaType,
|
|
2871
|
+
getSchemaProperty,
|
|
2872
|
+
setSchemaProperty,
|
|
2873
|
+
ECHO_ANNOTATIONS_NS_DEPRECATED_KEY,
|
|
2874
|
+
ECHO_ANNOTATIONS_NS_KEY,
|
|
2875
|
+
getNormalizedEchoAnnotations,
|
|
2876
|
+
normalizeSchema,
|
|
2877
|
+
JSON_SCHEMA_ECHO_REF_ID,
|
|
2878
|
+
getSchemaReference,
|
|
2879
|
+
createSchemaReference,
|
|
2880
|
+
getReferenceAst,
|
|
2881
|
+
RefTypeId,
|
|
2882
|
+
Ref,
|
|
2883
|
+
createEchoReferenceSchema,
|
|
2884
|
+
RefImpl,
|
|
2885
|
+
setRefResolver,
|
|
2886
|
+
getRefSavedTarget,
|
|
2887
|
+
refFromEncodedReference,
|
|
2888
|
+
StaticRefResolver,
|
|
2889
|
+
RefArray,
|
|
2890
|
+
PropType,
|
|
2891
|
+
toPropType,
|
|
2892
|
+
toJsonSchema,
|
|
2893
|
+
toEffectSchema,
|
|
2894
|
+
makeTypedEntityClass,
|
|
2895
|
+
objectToJSON,
|
|
2896
|
+
objectFromJSON,
|
|
2897
|
+
setRefResolverOnData,
|
|
2898
|
+
attachTypedJsonSerializer,
|
|
2899
|
+
createObject,
|
|
2900
|
+
isDeleted,
|
|
2901
|
+
createQueueDXN,
|
|
2902
|
+
SchemaValidator,
|
|
2903
|
+
checkIdNotPresentOnSchema,
|
|
2904
|
+
TypedObject,
|
|
2905
|
+
TypedReactiveHandler,
|
|
2906
|
+
prepareTypedTarget,
|
|
2907
|
+
makeObject,
|
|
2908
|
+
addFieldsToSchema,
|
|
2909
|
+
updateFieldsInSchema,
|
|
2910
|
+
removeFieldsFromSchema,
|
|
2911
|
+
updateFieldNameInSchema,
|
|
2912
|
+
setTypenameInSchema,
|
|
2913
|
+
PersistentSchema,
|
|
2914
|
+
getSnapshot,
|
|
2915
|
+
ImmutableSchema,
|
|
2916
|
+
isMutable,
|
|
2917
|
+
EchoSchema,
|
|
2918
|
+
JsonPath2 as JsonPath,
|
|
2919
|
+
JsonProp,
|
|
2920
|
+
getValue,
|
|
2921
|
+
setValue,
|
|
2922
|
+
splitJsonPath
|
|
2923
|
+
};
|
|
2924
|
+
//# sourceMappingURL=chunk-6XVZF5VJ.mjs.map
|