@dxos/echo 0.8.4-main.69d29f4 → 0.8.4-main.6fa680abb7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/lib/{browser → neutral}/Annotation.mjs +9 -5
- package/dist/lib/neutral/Database.mjs +45 -0
- package/dist/lib/{browser → neutral}/Entity.mjs +19 -12
- package/dist/lib/{browser → neutral}/Err.mjs +4 -3
- package/dist/lib/neutral/Feed.mjs +46 -0
- package/dist/lib/{node-esm → neutral}/Filter.mjs +12 -10
- package/dist/lib/{browser → neutral}/Format.mjs +4 -5
- package/dist/lib/neutral/JsonSchema.mjs +19 -0
- package/dist/lib/{browser → neutral}/Key.mjs +2 -3
- package/dist/lib/{browser → neutral}/Obj.mjs +36 -17
- package/dist/lib/{browser → neutral}/Order.mjs +2 -3
- package/dist/lib/neutral/Query.mjs +35 -0
- package/dist/lib/neutral/QueryResult.mjs +2 -0
- package/dist/lib/neutral/Ref.mjs +24 -0
- package/dist/lib/{browser → neutral}/Relation.mjs +21 -13
- package/dist/lib/neutral/SchemaRegistry.mjs +2 -0
- package/dist/lib/neutral/Tag.mjs +28 -0
- package/dist/lib/neutral/Type.mjs +37 -0
- package/dist/lib/{browser/chunk-AFGYYVVQ.mjs → neutral/chunk-2FK7XCDV.mjs} +6 -7
- package/dist/lib/neutral/chunk-2FK7XCDV.mjs.map +7 -0
- package/dist/lib/neutral/chunk-2Z72D23W.mjs +787 -0
- package/dist/lib/neutral/chunk-2Z72D23W.mjs.map +7 -0
- package/dist/lib/neutral/chunk-35FDO7WH.mjs +396 -0
- package/dist/lib/neutral/chunk-35FDO7WH.mjs.map +7 -0
- package/dist/lib/neutral/chunk-4HWWKURH.mjs +34 -0
- package/dist/lib/neutral/chunk-4HWWKURH.mjs.map +7 -0
- package/dist/lib/{browser/chunk-73M2G455.mjs → neutral/chunk-7VLKWC6T.mjs} +33 -10
- package/dist/lib/neutral/chunk-7VLKWC6T.mjs.map +7 -0
- package/dist/lib/{browser/chunk-INHXFXY5.mjs → neutral/chunk-ANHVGJI4.mjs} +2 -3
- package/dist/lib/{node-esm/chunk-AJEMYSIR.mjs.map → neutral/chunk-ANHVGJI4.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-R3S54KRI.mjs → neutral/chunk-B5OXLWZL.mjs} +14 -15
- package/dist/lib/neutral/chunk-B5OXLWZL.mjs.map +7 -0
- package/dist/lib/{browser/chunk-TPIL3G6Y.mjs → neutral/chunk-BESZGRPL.mjs} +17 -6
- package/dist/lib/neutral/chunk-BESZGRPL.mjs.map +7 -0
- package/dist/lib/{browser/chunk-ZHXZGIXD.mjs → neutral/chunk-BNCCGLJN.mjs} +1 -3
- package/dist/lib/{browser/chunk-ZHXZGIXD.mjs.map → neutral/chunk-BNCCGLJN.mjs.map} +2 -2
- package/dist/lib/{browser/chunk-QIWDIPLR.mjs → neutral/chunk-EK7UOJ3R.mjs} +9 -5
- package/dist/lib/neutral/chunk-EK7UOJ3R.mjs.map +7 -0
- package/dist/lib/neutral/chunk-ETOQXZHC.mjs +130 -0
- package/dist/lib/neutral/chunk-ETOQXZHC.mjs.map +7 -0
- package/dist/lib/neutral/chunk-EV3A23AS.mjs +283 -0
- package/dist/lib/neutral/chunk-EV3A23AS.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-OZEDKT4R.mjs → neutral/chunk-FUGL645K.mjs} +135 -26
- package/dist/lib/neutral/chunk-FUGL645K.mjs.map +7 -0
- package/dist/lib/{browser/chunk-5RDNDPMX.mjs → neutral/chunk-FZO7LQO7.mjs} +3 -4
- package/dist/lib/neutral/chunk-FZO7LQO7.mjs.map +7 -0
- package/dist/lib/{browser/chunk-CGS2ULMK.mjs → neutral/chunk-J5LGTIGS.mjs} +1 -2
- package/dist/lib/neutral/chunk-LDHKQDXR.mjs +27 -0
- package/dist/lib/neutral/chunk-LDHKQDXR.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-5U5F4AWK.mjs → neutral/chunk-MFJPOZDU.mjs} +1579 -2717
- package/dist/lib/neutral/chunk-MFJPOZDU.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-NBWL7UCZ.mjs → neutral/chunk-OENWMTE6.mjs} +9 -4
- package/dist/lib/neutral/chunk-OENWMTE6.mjs.map +7 -0
- package/dist/lib/{browser/chunk-IXVWLTG7.mjs → neutral/chunk-OMUPQMLR.mjs} +1 -3
- package/dist/lib/{node-esm/chunk-UKGVOINP.mjs.map → neutral/chunk-OMUPQMLR.mjs.map} +1 -1
- package/dist/lib/{browser/chunk-2RMVRVOB.mjs → neutral/chunk-PH5RST5U.mjs} +73 -25
- package/dist/lib/neutral/chunk-PH5RST5U.mjs.map +7 -0
- package/dist/lib/neutral/chunk-PKD2L7XO.mjs +152 -0
- package/dist/lib/neutral/chunk-PKD2L7XO.mjs.map +7 -0
- package/dist/lib/{browser/chunk-L4RXUJHJ.mjs → neutral/chunk-QLALBCSA.mjs} +12 -58
- package/dist/lib/neutral/chunk-QLALBCSA.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QTUBE4DR.mjs +102 -0
- package/dist/lib/neutral/chunk-QTUBE4DR.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-YOLH5KS4.mjs → neutral/chunk-SEMVAGBM.mjs} +97 -25
- package/dist/lib/neutral/chunk-SEMVAGBM.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-YQ2NWGL5.mjs → neutral/chunk-UBEZSGXY.mjs} +15 -3
- package/dist/lib/neutral/chunk-UBEZSGXY.mjs.map +7 -0
- package/dist/lib/{browser/chunk-JMKVF2YQ.mjs → neutral/chunk-UI6MWK5W.mjs} +3 -4
- package/dist/lib/neutral/chunk-UI6MWK5W.mjs.map +7 -0
- package/dist/lib/{browser/chunk-YKTSSMDS.mjs → neutral/chunk-WYOKA6AE.mjs} +4 -6
- package/dist/lib/neutral/chunk-WYOKA6AE.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +97 -0
- package/dist/lib/{node-esm → neutral}/internal/index.mjs +53 -40
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/{node-esm → neutral}/testing/index.mjs +43 -37
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/Annotation.d.ts +23 -1
- package/dist/types/src/Annotation.d.ts.map +1 -1
- package/dist/types/src/Collection.d.ts +16 -0
- package/dist/types/src/Collection.d.ts.map +1 -0
- package/dist/types/src/Database.d.ts +78 -83
- package/dist/types/src/Database.d.ts.map +1 -1
- package/dist/types/src/Dataset.d.ts +18 -0
- package/dist/types/src/Dataset.d.ts.map +1 -0
- package/dist/types/src/Entity.d.ts +38 -12
- package/dist/types/src/Entity.d.ts.map +1 -1
- package/dist/types/src/Err.d.ts +43 -0
- package/dist/types/src/Err.d.ts.map +1 -1
- package/dist/types/src/Feed.d.ts +165 -0
- package/dist/types/src/Feed.d.ts.map +1 -0
- package/dist/types/src/Filter.d.ts +1 -1
- package/dist/types/src/Filter.d.ts.map +1 -1
- package/dist/types/src/Format.d.ts +3 -3
- package/dist/types/src/Format.d.ts.map +1 -1
- package/dist/types/src/Hypergraph.d.ts +2 -2
- package/dist/types/src/Hypergraph.d.ts.map +1 -1
- package/dist/types/src/JsonSchema.d.ts +11 -4
- package/dist/types/src/JsonSchema.d.ts.map +1 -1
- package/dist/types/src/Obj.d.ts +149 -36
- package/dist/types/src/Obj.d.ts.map +1 -1
- package/dist/types/src/Order.d.ts.map +1 -1
- package/dist/types/src/Query.d.ts +101 -14
- package/dist/types/src/Query.d.ts.map +1 -1
- package/dist/types/src/Ref.d.ts +58 -10
- package/dist/types/src/Ref.d.ts.map +1 -1
- package/dist/types/src/Relation.d.ts +73 -26
- package/dist/types/src/Relation.d.ts.map +1 -1
- package/dist/types/src/SchemaRegistry.d.ts +4 -4
- package/dist/types/src/SchemaRegistry.d.ts.map +1 -1
- package/dist/types/src/Tag.d.ts +4 -3
- package/dist/types/src/Tag.d.ts.map +1 -1
- package/dist/types/src/Type.d.ts +51 -180
- package/dist/types/src/Type.d.ts.map +1 -1
- package/dist/types/src/View.d.ts +68 -0
- package/dist/types/src/View.d.ts.map +1 -0
- package/dist/types/src/hierarchy.test.d.ts +2 -0
- package/dist/types/src/hierarchy.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/internal/{annotations → Annotation}/annotations.d.ts +68 -8
- package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/Annotation/annotations.test.d.ts.map +1 -0
- package/dist/types/src/internal/Annotation/index.d.ts +4 -0
- package/dist/types/src/internal/Annotation/index.d.ts.map +1 -0
- package/dist/types/src/internal/{api → Annotation}/sorting.d.ts +1 -1
- package/dist/types/src/internal/Annotation/sorting.d.ts.map +1 -0
- package/dist/types/src/internal/{annotations → Annotation}/util.d.ts +13 -1
- package/dist/types/src/internal/Annotation/util.d.ts.map +1 -0
- package/dist/types/src/internal/{api/entity.d.ts → Entity/api.d.ts} +2 -2
- package/dist/types/src/internal/Entity/api.d.ts.map +1 -0
- package/dist/types/src/internal/{entities → Entity}/entity.d.ts +3 -3
- package/dist/types/src/internal/Entity/entity.d.ts.map +1 -0
- package/dist/types/src/internal/{entities → Entity}/index.d.ts +2 -0
- package/dist/types/src/internal/Entity/index.d.ts.map +1 -0
- package/dist/types/src/internal/{entities → Entity}/model.d.ts +4 -26
- package/dist/types/src/internal/Entity/model.d.ts.map +1 -0
- package/dist/types/src/internal/{entities → Entity}/object.d.ts +2 -2
- package/dist/types/src/internal/Entity/object.d.ts.map +1 -0
- package/dist/types/src/internal/{entities → Entity}/relation.d.ts +3 -30
- package/dist/types/src/internal/Entity/relation.d.ts.map +1 -0
- package/dist/types/src/internal/Entity/util.d.ts.map +1 -0
- package/dist/types/src/internal/{api → Entity}/version.d.ts +1 -1
- package/dist/types/src/internal/Entity/version.d.ts.map +1 -0
- package/dist/types/src/internal/Format/date.d.ts.map +1 -0
- package/dist/types/src/internal/Format/date.test.d.ts.map +1 -0
- package/dist/types/src/internal/Format/format.d.ts.map +1 -0
- package/dist/types/src/internal/Format/format.test.d.ts.map +1 -0
- package/dist/types/src/internal/Format/index.d.ts.map +1 -0
- package/dist/types/src/internal/Format/number.d.ts.map +1 -0
- package/dist/types/src/internal/Format/object.d.ts.map +1 -0
- package/dist/types/src/internal/Format/select.d.ts.map +1 -0
- package/dist/types/src/internal/Format/string.d.ts.map +1 -0
- package/dist/types/src/internal/{formats → Format}/types.d.ts +1 -1
- package/dist/types/src/internal/Format/types.d.ts.map +1 -0
- package/dist/types/src/internal/{json-schema → JsonSchema}/annotations.d.ts +1 -1
- package/dist/types/src/internal/JsonSchema/annotations.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/effect-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/index.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts.map +1 -0
- package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema-type.d.ts +19 -19
- package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -0
- package/dist/types/src/internal/JsonSchema/json-schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/clone.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/common.d.ts.map +1 -0
- package/dist/types/src/internal/{object → Obj}/create-object.d.ts +2 -2
- package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/create-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/{object → Obj}/deleted.d.ts +1 -1
- package/dist/types/src/internal/Obj/deleted.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/ids.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/index.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/inspect.d.ts.map +1 -0
- package/dist/types/src/internal/{object → Obj}/json-serializer.d.ts +4 -4
- package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/json-serializer.test.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/schema-validator.d.ts +2 -0
- package/dist/types/src/internal/Obj/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/schema-validator.test.d.ts.map +1 -0
- package/dist/types/src/internal/{object → Obj}/set-value.d.ts +1 -1
- package/dist/types/src/internal/Obj/set-value.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/set-value.test.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/snapshot.d.ts.map +1 -0
- package/dist/types/src/internal/{object → Obj}/typed-object.d.ts +4 -4
- package/dist/types/src/internal/Obj/typed-object.d.ts.map +1 -0
- package/dist/types/src/internal/Obj/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/index.d.ts.map +1 -0
- package/dist/types/src/internal/{ref → Ref}/ref-array.d.ts +1 -1
- package/dist/types/src/internal/Ref/ref-array.d.ts.map +1 -0
- package/dist/types/src/internal/{ref → Ref}/ref.d.ts +16 -3
- package/dist/types/src/internal/Ref/ref.d.ts.map +1 -0
- package/dist/types/src/internal/Ref/ref.test.d.ts.map +1 -0
- package/dist/types/src/internal/{schema → Type}/compose.d.ts +1 -1
- package/dist/types/src/internal/Type/compose.d.ts.map +1 -0
- package/dist/types/src/internal/Type/compose.test.d.ts.map +1 -0
- package/dist/types/src/internal/{schema → Type}/echo-schema.d.ts +8 -7
- package/dist/types/src/internal/Type/echo-schema.d.ts.map +1 -0
- package/dist/types/src/internal/Type/index.d.ts.map +1 -0
- package/dist/types/src/internal/Type/manipulation.d.ts.map +1 -0
- package/dist/types/src/internal/{schema → Type}/persistent-schema.d.ts +2 -2
- package/dist/types/src/internal/Type/persistent-schema.d.ts.map +1 -0
- package/dist/types/src/internal/{api → common/api}/index.d.ts +0 -4
- package/dist/types/src/internal/common/api/index.d.ts.map +1 -0
- package/dist/types/src/internal/common/api/meta.d.ts.map +1 -0
- package/dist/types/src/internal/common/index.d.ts +4 -0
- package/dist/types/src/internal/common/index.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/change.test.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/errors.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/event-batch.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/index.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/json-serializer.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/ownership.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/proxy-types.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/reactive-array.d.ts.map +1 -0
- package/dist/types/src/internal/{proxy → common/proxy}/reactive.d.ts +1 -1
- package/dist/types/src/internal/common/proxy/reactive.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/schema.test.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -0
- package/dist/types/src/internal/{proxy → common/proxy}/typed-handler.d.ts +2 -1
- package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/typed-handler.test.d.ts.map +1 -0
- package/dist/types/src/internal/common/proxy/typed-object.test.d.ts.map +1 -0
- package/dist/types/src/internal/{types → common/types}/base.d.ts +1 -0
- package/dist/types/src/internal/common/types/base.d.ts.map +1 -0
- package/dist/types/src/internal/{types → common/types}/entity.d.ts +2 -2
- package/dist/types/src/internal/common/types/entity.d.ts.map +1 -0
- package/dist/types/src/internal/{types → common/types}/index.d.ts +1 -0
- package/dist/types/src/internal/common/types/index.d.ts.map +1 -0
- package/dist/types/src/internal/{types → common/types}/meta.d.ts +2 -1
- package/dist/types/src/internal/common/types/meta.d.ts.map +1 -0
- package/dist/types/src/internal/common/types/model-symbols.d.ts +54 -0
- package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -0
- package/dist/types/src/internal/{types → common/types}/typename.d.ts +8 -0
- package/dist/types/src/internal/common/types/typename.d.ts.map +1 -0
- package/dist/types/src/internal/{types → common/types}/version.d.ts +2 -2
- package/dist/types/src/internal/common/types/version.d.ts.map +1 -0
- package/dist/types/src/internal/index.d.ts +8 -10
- package/dist/types/src/internal/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +19 -18
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +39 -113
- package/src/Annotation.ts +31 -1
- package/src/Collection.ts +32 -0
- package/src/Database.ts +153 -172
- package/src/Dataset.ts +26 -0
- package/src/Entity.ts +71 -51
- package/src/Err.ts +22 -0
- package/src/Feed.ts +257 -0
- package/src/Filter.ts +19 -4
- package/src/Format.ts +3 -3
- package/src/Hypergraph.ts +2 -2
- package/src/JsonSchema.ts +14 -4
- package/src/Obj.test.ts +63 -2
- package/src/Obj.ts +274 -132
- package/src/Order.ts +3 -1
- package/src/Query.test.ts +181 -14
- package/src/Query.ts +249 -23
- package/src/Ref.ts +64 -11
- package/src/Relation.test.ts +8 -2
- package/src/Relation.ts +163 -129
- package/src/SchemaRegistry.ts +5 -4
- package/src/Tag.ts +6 -5
- package/src/Type.test.ts +10 -10
- package/src/Type.ts +70 -303
- package/src/View.ts +102 -0
- package/src/hierarchy.test.ts +33 -0
- package/src/index.ts +4 -0
- package/src/internal/{annotations → Annotation}/annotations.test.ts +6 -6
- package/src/internal/{annotations → Annotation}/annotations.ts +120 -9
- package/src/internal/{annotations → Annotation}/index.ts +1 -0
- package/src/internal/{api → Annotation}/sorting.ts +2 -3
- package/src/internal/{annotations → Annotation}/util.ts +14 -1
- package/src/internal/{api/entity.ts → Entity/api.ts} +4 -2
- package/src/internal/{entities → Entity}/entity.ts +6 -4
- package/src/internal/{entities → Entity}/index.ts +2 -0
- package/src/internal/{entities → Entity}/model.ts +17 -42
- package/src/internal/{entities → Entity}/object.ts +2 -2
- package/src/internal/{entities → Entity}/relation.ts +19 -36
- package/src/internal/{api → Entity}/version.ts +3 -2
- package/src/internal/{formats → Format}/date.test.ts +1 -1
- package/src/internal/{formats → Format}/format.test.ts +1 -1
- package/src/internal/{formats → Format}/types.ts +3 -3
- package/src/internal/{json-schema → JsonSchema}/annotations.ts +3 -3
- package/src/internal/{json-schema → JsonSchema}/json-schema-type.ts +4 -4
- package/src/internal/{json-schema → JsonSchema}/json-schema.test.ts +48 -48
- package/src/internal/{json-schema → JsonSchema}/json-schema.ts +6 -4
- package/src/internal/{object → Obj}/clone.ts +3 -3
- package/src/internal/{object → Obj}/common.ts +2 -2
- package/src/internal/{object → Obj}/create-object.test.ts +4 -4
- package/src/internal/{object → Obj}/create-object.ts +5 -5
- package/src/internal/{object → Obj}/deleted.ts +2 -2
- package/src/internal/{object → Obj}/inspect.ts +2 -2
- package/src/internal/{object → Obj}/json-serializer.test.ts +29 -6
- package/src/internal/{object → Obj}/json-serializer.ts +30 -14
- package/src/internal/{object → Obj}/schema-validator.ts +1 -1
- package/src/internal/{object → Obj}/set-value.ts +2 -2
- package/src/internal/Obj/snapshot.ts +105 -0
- package/src/internal/{object → Obj}/typed-object.test.ts +3 -3
- package/src/internal/{object → Obj}/typed-object.ts +4 -4
- package/src/internal/{ref → Ref}/ref-array.ts +1 -1
- package/src/internal/{ref → Ref}/ref.test.ts +4 -4
- package/src/internal/{ref → Ref}/ref.ts +27 -4
- package/src/internal/{schema → Type}/compose.test.ts +5 -5
- package/src/internal/{schema → Type}/compose.ts +1 -1
- package/src/internal/{schema → Type}/echo-schema.ts +11 -10
- package/src/internal/{schema → Type}/manipulation.ts +1 -1
- package/src/internal/{schema → Type}/persistent-schema.ts +10 -4
- package/src/internal/{README.md → common/README.md} +1 -1
- package/src/internal/{api → common/api}/index.ts +0 -4
- package/src/internal/common/index.ts +7 -0
- package/src/internal/{proxy → common/proxy}/change.test.ts +3 -3
- package/src/internal/{proxy → common/proxy}/handler.test.ts +2 -2
- package/src/internal/{proxy → common/proxy}/json-serializer.ts +6 -3
- package/src/internal/{proxy → common/proxy}/make-object.ts +13 -3
- package/src/internal/{proxy → common/proxy}/reactive.ts +1 -1
- package/src/internal/{proxy → common/proxy}/schema.test.ts +10 -10
- package/src/internal/{proxy → common/proxy}/typed-handler.test.ts +6 -6
- package/src/internal/{proxy → common/proxy}/typed-handler.ts +10 -3
- package/src/internal/{proxy → common/proxy}/typed-object.test.ts +4 -4
- package/src/internal/{types → common/types}/base.ts +1 -1
- package/src/internal/{types → common/types}/entity.ts +2 -2
- package/src/internal/{types → common/types}/index.ts +1 -0
- package/src/internal/{types → common/types}/meta.ts +4 -1
- package/src/internal/common/types/model-symbols.ts +69 -0
- package/src/internal/{types → common/types}/typename.ts +10 -0
- package/src/internal/{types → common/types}/version.ts +2 -3
- package/src/internal/index.ts +8 -31
- package/src/testing/api.test.ts +4 -4
- package/src/testing/test-schema.ts +20 -18
- package/dist/lib/browser/Database.mjs +0 -18
- package/dist/lib/browser/Filter.mjs +0 -62
- package/dist/lib/browser/JsonSchema.mjs +0 -20
- package/dist/lib/browser/Query.mjs +0 -27
- package/dist/lib/browser/QueryResult.mjs +0 -3
- package/dist/lib/browser/Ref.mjs +0 -23
- package/dist/lib/browser/SchemaRegistry.mjs +0 -3
- package/dist/lib/browser/Tag.mjs +0 -26
- package/dist/lib/browser/Type.mjs +0 -48
- package/dist/lib/browser/chunk-2RMVRVOB.mjs.map +0 -7
- package/dist/lib/browser/chunk-5RDNDPMX.mjs.map +0 -7
- package/dist/lib/browser/chunk-73M2G455.mjs.map +0 -7
- package/dist/lib/browser/chunk-7STIBCP7.mjs +0 -133
- package/dist/lib/browser/chunk-7STIBCP7.mjs.map +0 -7
- package/dist/lib/browser/chunk-AFGYYVVQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-BC6R4CAF.mjs +0 -24
- package/dist/lib/browser/chunk-BC6R4CAF.mjs.map +0 -7
- package/dist/lib/browser/chunk-BPYFLHWO.mjs +0 -158
- package/dist/lib/browser/chunk-BPYFLHWO.mjs.map +0 -7
- package/dist/lib/browser/chunk-CBPFF3ZO.mjs +0 -204
- package/dist/lib/browser/chunk-CBPFF3ZO.mjs.map +0 -7
- package/dist/lib/browser/chunk-CJ5YELTO.mjs +0 -39
- package/dist/lib/browser/chunk-CJ5YELTO.mjs.map +0 -7
- package/dist/lib/browser/chunk-FPOISFQK.mjs +0 -40
- package/dist/lib/browser/chunk-FPOISFQK.mjs.map +0 -7
- package/dist/lib/browser/chunk-INHXFXY5.mjs.map +0 -7
- package/dist/lib/browser/chunk-IXVWLTG7.mjs.map +0 -7
- package/dist/lib/browser/chunk-JMKVF2YQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-L4RXUJHJ.mjs.map +0 -7
- package/dist/lib/browser/chunk-MYCCGG2T.mjs +0 -15
- package/dist/lib/browser/chunk-MYCCGG2T.mjs.map +0 -7
- package/dist/lib/browser/chunk-PAM4KEXE.mjs +0 -3847
- package/dist/lib/browser/chunk-PAM4KEXE.mjs.map +0 -7
- package/dist/lib/browser/chunk-QIWDIPLR.mjs.map +0 -7
- package/dist/lib/browser/chunk-R3S54KRI.mjs.map +0 -7
- package/dist/lib/browser/chunk-RK4Z4JUZ.mjs +0 -283
- package/dist/lib/browser/chunk-RK4Z4JUZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-TPIL3G6Y.mjs.map +0 -7
- package/dist/lib/browser/chunk-YKTSSMDS.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -85
- package/dist/lib/browser/internal/index.mjs +0 -457
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs +0 -367
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/Annotation.mjs +0 -33
- package/dist/lib/node-esm/Annotation.mjs.map +0 -7
- package/dist/lib/node-esm/Database.mjs +0 -18
- package/dist/lib/node-esm/Database.mjs.map +0 -7
- package/dist/lib/node-esm/Entity.mjs +0 -52
- package/dist/lib/node-esm/Entity.mjs.map +0 -7
- package/dist/lib/node-esm/Err.mjs +0 -11
- package/dist/lib/node-esm/Err.mjs.map +0 -7
- package/dist/lib/node-esm/Format.mjs +0 -67
- package/dist/lib/node-esm/Format.mjs.map +0 -7
- package/dist/lib/node-esm/JsonSchema.mjs +0 -20
- package/dist/lib/node-esm/JsonSchema.mjs.map +0 -7
- package/dist/lib/node-esm/Key.mjs +0 -13
- package/dist/lib/node-esm/Key.mjs.map +0 -7
- package/dist/lib/node-esm/Obj.mjs +0 -91
- package/dist/lib/node-esm/Obj.mjs.map +0 -7
- package/dist/lib/node-esm/Order.mjs +0 -13
- package/dist/lib/node-esm/Order.mjs.map +0 -7
- package/dist/lib/node-esm/Query.mjs +0 -27
- package/dist/lib/node-esm/Query.mjs.map +0 -7
- package/dist/lib/node-esm/QueryResult.mjs +0 -3
- package/dist/lib/node-esm/QueryResult.mjs.map +0 -7
- package/dist/lib/node-esm/Ref.mjs +0 -23
- package/dist/lib/node-esm/Ref.mjs.map +0 -7
- package/dist/lib/node-esm/Relation.mjs +0 -85
- package/dist/lib/node-esm/Relation.mjs.map +0 -7
- package/dist/lib/node-esm/SchemaRegistry.mjs +0 -3
- package/dist/lib/node-esm/SchemaRegistry.mjs.map +0 -7
- package/dist/lib/node-esm/Tag.mjs +0 -26
- package/dist/lib/node-esm/Tag.mjs.map +0 -7
- package/dist/lib/node-esm/Type.mjs +0 -48
- package/dist/lib/node-esm/Type.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2RIFBW3A.mjs +0 -250
- package/dist/lib/node-esm/chunk-2RIFBW3A.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-5CB2ZW74.mjs +0 -57
- package/dist/lib/node-esm/chunk-5CB2ZW74.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-5U5F4AWK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AJEMYSIR.mjs +0 -22
- package/dist/lib/node-esm/chunk-BKYE5IW6.mjs +0 -158
- package/dist/lib/node-esm/chunk-BKYE5IW6.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BYOD7EVP.mjs +0 -98
- package/dist/lib/node-esm/chunk-BYOD7EVP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-FWTSPIFF.mjs +0 -133
- package/dist/lib/node-esm/chunk-FWTSPIFF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-K37NA7PO.mjs +0 -43
- package/dist/lib/node-esm/chunk-K37NA7PO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-LIXUCQJM.mjs +0 -41
- package/dist/lib/node-esm/chunk-LIXUCQJM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MOLNWFNL.mjs +0 -9
- package/dist/lib/node-esm/chunk-MOLNWFNL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MOWUEW5P.mjs +0 -15
- package/dist/lib/node-esm/chunk-MOWUEW5P.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NBWL7UCZ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OZEDKT4R.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-PW3VCWL5.mjs +0 -24
- package/dist/lib/node-esm/chunk-PW3VCWL5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-TSTKBFST.mjs +0 -403
- package/dist/lib/node-esm/chunk-TSTKBFST.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-UKGVOINP.mjs +0 -9
- package/dist/lib/node-esm/chunk-UV63HEHQ.mjs +0 -143
- package/dist/lib/node-esm/chunk-UV63HEHQ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-WXLVPCRJ.mjs +0 -288
- package/dist/lib/node-esm/chunk-WXLVPCRJ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-WZ6YBELW.mjs +0 -74
- package/dist/lib/node-esm/chunk-WZ6YBELW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XHJRMQZD.mjs +0 -69
- package/dist/lib/node-esm/chunk-XHJRMQZD.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YOLH5KS4.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YQ2NWGL5.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -85
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/internal/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/internal/annotations/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/annotations/annotations.test.d.ts.map +0 -1
- package/dist/types/src/internal/annotations/index.d.ts +0 -3
- package/dist/types/src/internal/annotations/index.d.ts.map +0 -1
- package/dist/types/src/internal/annotations/util.d.ts.map +0 -1
- package/dist/types/src/internal/api/annotations.d.ts +0 -23
- package/dist/types/src/internal/api/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/api/entity.d.ts.map +0 -1
- package/dist/types/src/internal/api/index.d.ts.map +0 -1
- package/dist/types/src/internal/api/meta.d.ts.map +0 -1
- package/dist/types/src/internal/api/sorting.d.ts.map +0 -1
- package/dist/types/src/internal/api/version.d.ts.map +0 -1
- package/dist/types/src/internal/entities/entity.d.ts.map +0 -1
- package/dist/types/src/internal/entities/index.d.ts.map +0 -1
- package/dist/types/src/internal/entities/model.d.ts.map +0 -1
- package/dist/types/src/internal/entities/object.d.ts.map +0 -1
- package/dist/types/src/internal/entities/relation.d.ts.map +0 -1
- package/dist/types/src/internal/entities/util.d.ts.map +0 -1
- package/dist/types/src/internal/formats/date.d.ts.map +0 -1
- package/dist/types/src/internal/formats/date.test.d.ts.map +0 -1
- package/dist/types/src/internal/formats/format.d.ts.map +0 -1
- package/dist/types/src/internal/formats/format.test.d.ts.map +0 -1
- package/dist/types/src/internal/formats/index.d.ts.map +0 -1
- package/dist/types/src/internal/formats/number.d.ts.map +0 -1
- package/dist/types/src/internal/formats/object.d.ts.map +0 -1
- package/dist/types/src/internal/formats/select.d.ts.map +0 -1
- package/dist/types/src/internal/formats/string.d.ts.map +0 -1
- package/dist/types/src/internal/formats/types.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/annotations.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/index.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/json-schema.d.ts.map +0 -1
- package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/clone.d.ts.map +0 -1
- package/dist/types/src/internal/object/common.d.ts.map +0 -1
- package/dist/types/src/internal/object/create-object.d.ts.map +0 -1
- package/dist/types/src/internal/object/create-object.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/deleted.d.ts.map +0 -1
- package/dist/types/src/internal/object/ids.d.ts.map +0 -1
- package/dist/types/src/internal/object/index.d.ts.map +0 -1
- package/dist/types/src/internal/object/inspect.d.ts.map +0 -1
- package/dist/types/src/internal/object/json-serializer.d.ts.map +0 -1
- package/dist/types/src/internal/object/json-serializer.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/schema-validator.d.ts +0 -2
- package/dist/types/src/internal/object/schema-validator.d.ts.map +0 -1
- package/dist/types/src/internal/object/schema-validator.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/set-value.d.ts.map +0 -1
- package/dist/types/src/internal/object/set-value.test.d.ts.map +0 -1
- package/dist/types/src/internal/object/snapshot.d.ts.map +0 -1
- package/dist/types/src/internal/object/typed-object.d.ts.map +0 -1
- package/dist/types/src/internal/object/typed-object.test.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/change-context.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/change.test.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/define-hidden-property.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/errors.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/event-batch.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/handler.test.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/index.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/json-serializer.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/make-object.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/ownership.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/proxy-types.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/proxy-utils.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/reactive-array.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/reactive.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/schema-validator.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/schema.test.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/symbols.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/typed-handler.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +0 -1
- package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +0 -1
- package/dist/types/src/internal/ref/index.d.ts.map +0 -1
- package/dist/types/src/internal/ref/ref-array.d.ts.map +0 -1
- package/dist/types/src/internal/ref/ref.d.ts.map +0 -1
- package/dist/types/src/internal/ref/ref.test.d.ts.map +0 -1
- package/dist/types/src/internal/schema/compose.d.ts.map +0 -1
- package/dist/types/src/internal/schema/compose.test.d.ts.map +0 -1
- package/dist/types/src/internal/schema/echo-schema.d.ts.map +0 -1
- package/dist/types/src/internal/schema/index.d.ts.map +0 -1
- package/dist/types/src/internal/schema/manipulation.d.ts.map +0 -1
- package/dist/types/src/internal/schema/persistent-schema.d.ts.map +0 -1
- package/dist/types/src/internal/types/base.d.ts.map +0 -1
- package/dist/types/src/internal/types/entity.d.ts.map +0 -1
- package/dist/types/src/internal/types/index.d.ts.map +0 -1
- package/dist/types/src/internal/types/meta.d.ts.map +0 -1
- package/dist/types/src/internal/types/typename.d.ts.map +0 -1
- package/dist/types/src/internal/types/version.d.ts.map +0 -1
- package/src/internal/api/annotations.ts +0 -60
- package/src/internal/object/snapshot.ts +0 -70
- /package/dist/lib/{browser → neutral}/Annotation.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Database.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Entity.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Err.mjs.map +0 -0
- /package/dist/lib/{browser/Filter.mjs.map → neutral/Feed.mjs.map} +0 -0
- /package/dist/lib/{node-esm → neutral}/Filter.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Format.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/JsonSchema.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Key.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Obj.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Order.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Query.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/QueryResult.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Ref.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Relation.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/SchemaRegistry.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Tag.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/Type.mjs.map +0 -0
- /package/dist/lib/{browser/chunk-CGS2ULMK.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/{browser → neutral}/index.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/internal/index.mjs.map +0 -0
- /package/dist/types/src/internal/{annotations → Annotation}/annotations.test.d.ts +0 -0
- /package/dist/types/src/internal/{entities → Entity}/util.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/date.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/date.test.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/format.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/format.test.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/index.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/number.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/object.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/select.d.ts +0 -0
- /package/dist/types/src/internal/{formats → Format}/string.d.ts +0 -0
- /package/dist/types/src/internal/{json-schema → JsonSchema}/effect-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{json-schema → JsonSchema}/index.d.ts +0 -0
- /package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema-normalize.d.ts +0 -0
- /package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema.d.ts +0 -0
- /package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/clone.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/common.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/create-object.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/ids.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/index.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/inspect.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/json-serializer.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/schema-validator.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/set-value.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/snapshot.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/typed-object.test.d.ts +0 -0
- /package/dist/types/src/internal/{ref → Ref}/index.d.ts +0 -0
- /package/dist/types/src/internal/{ref → Ref}/ref.test.d.ts +0 -0
- /package/dist/types/src/internal/{schema → Type}/compose.test.d.ts +0 -0
- /package/dist/types/src/internal/{schema → Type}/index.d.ts +0 -0
- /package/dist/types/src/internal/{schema → Type}/manipulation.d.ts +0 -0
- /package/dist/types/src/internal/{api → common/api}/meta.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/change-context.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/change.test.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/define-hidden-property.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/errors.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/event-batch.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/handler.test.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/index.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/json-serializer.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/make-object.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/ownership.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/proxy-types.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/proxy-utils.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/reactive-array.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/schema-validator.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/schema.test.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/symbols.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/typed-handler.test.d.ts +0 -0
- /package/dist/types/src/internal/{proxy → common/proxy}/typed-object.test.d.ts +0 -0
- /package/src/internal/{entities → Entity}/util.ts +0 -0
- /package/src/internal/{formats → Format}/date.ts +0 -0
- /package/src/internal/{formats → Format}/format.ts +0 -0
- /package/src/internal/{formats → Format}/index.ts +0 -0
- /package/src/internal/{formats → Format}/number.ts +0 -0
- /package/src/internal/{formats → Format}/object.ts +0 -0
- /package/src/internal/{formats → Format}/select.ts +0 -0
- /package/src/internal/{formats → Format}/string.ts +0 -0
- /package/src/internal/{json-schema → JsonSchema}/effect-schema.test.ts +0 -0
- /package/src/internal/{json-schema → JsonSchema}/index.ts +0 -0
- /package/src/internal/{json-schema → JsonSchema}/json-schema-normalize.ts +0 -0
- /package/src/internal/{object → Obj}/ids.ts +0 -0
- /package/src/internal/{object → Obj}/index.ts +0 -0
- /package/src/internal/{object → Obj}/schema-validator.test.ts +0 -0
- /package/src/internal/{object → Obj}/set-value.test.ts +0 -0
- /package/src/internal/{ref → Ref}/index.ts +0 -0
- /package/src/internal/{schema → Type}/index.ts +0 -0
- /package/src/internal/{api → common/api}/meta.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/change-context.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/define-hidden-property.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/errors.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/event-batch.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/index.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/ownership.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/proxy-types.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/proxy-utils.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/reactive-array.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/schema-validator.ts +0 -0
- /package/src/internal/{proxy → common/proxy}/symbols.ts +0 -0
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "./chunk-
|
|
2
|
+
JsonSchemaFields,
|
|
3
|
+
JsonSchemaType,
|
|
4
|
+
toEffectSchema,
|
|
5
|
+
toJsonSchema
|
|
6
|
+
} from "./chunk-2Z72D23W.mjs";
|
|
8
7
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
Ref,
|
|
9
|
+
refFromEncodedReference,
|
|
10
|
+
setRefResolver
|
|
11
|
+
} from "./chunk-35FDO7WH.mjs";
|
|
11
12
|
import {
|
|
13
|
+
ATTR_PARENT,
|
|
12
14
|
ATTR_TYPE,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ReferenceAnnotationId,
|
|
15
|
+
IconAnnotation,
|
|
16
|
+
LabelAnnotation,
|
|
17
|
+
ParentId,
|
|
17
18
|
SchemaId,
|
|
18
19
|
SchemaMetaSymbol,
|
|
19
20
|
TypeAnnotationId,
|
|
@@ -21,9 +22,8 @@ import {
|
|
|
21
22
|
TypeIdentifierAnnotationId,
|
|
22
23
|
TypenameSchema,
|
|
23
24
|
VersionSchema,
|
|
24
|
-
getDescriptionWithSchema,
|
|
25
25
|
getEntityKind,
|
|
26
|
-
|
|
26
|
+
getLabel,
|
|
27
27
|
getSchema,
|
|
28
28
|
getSchemaDXN,
|
|
29
29
|
getSchemaTypename,
|
|
@@ -31,26 +31,21 @@ import {
|
|
|
31
31
|
getTypeDXN,
|
|
32
32
|
getTypeIdentifierAnnotation,
|
|
33
33
|
getTypename,
|
|
34
|
-
setDescriptionWithSchema,
|
|
35
|
-
setLabelWithSchema,
|
|
36
34
|
setSchema,
|
|
37
35
|
setTypename
|
|
38
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-SEMVAGBM.mjs";
|
|
39
37
|
import {
|
|
40
|
-
ANY_OBJECT_TYPENAME,
|
|
41
|
-
ANY_OBJECT_VERSION,
|
|
42
38
|
EntityKind,
|
|
43
|
-
EntityKindSchema,
|
|
44
39
|
KindId,
|
|
45
40
|
SchemaKindId,
|
|
46
41
|
SnapshotKindId,
|
|
47
42
|
makeTypeJsonSchemaAnnotation
|
|
48
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-WYOKA6AE.mjs";
|
|
49
44
|
|
|
50
45
|
// src/internal/index.ts
|
|
51
|
-
import { JsonPath
|
|
46
|
+
import { JsonPath, JsonProp, getValue, splitJsonPath } from "@dxos/effect";
|
|
52
47
|
|
|
53
|
-
// src/internal/types/base.ts
|
|
48
|
+
// src/internal/common/types/base.ts
|
|
54
49
|
import * as Schema from "effect/Schema";
|
|
55
50
|
import * as SchemaAST from "effect/SchemaAST";
|
|
56
51
|
var RawObject = (schema) => {
|
|
@@ -59,14 +54,14 @@ var RawObject = (schema) => {
|
|
|
59
54
|
]));
|
|
60
55
|
};
|
|
61
56
|
|
|
62
|
-
// src/internal/types/meta.ts
|
|
57
|
+
// src/internal/common/types/meta.ts
|
|
63
58
|
import * as Schema2 from "effect/Schema";
|
|
64
59
|
import { ForeignKey } from "@dxos/echo-protocol";
|
|
65
60
|
import { invariant } from "@dxos/invariant";
|
|
66
61
|
import { intersection } from "@dxos/util";
|
|
67
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/types/meta.ts";
|
|
62
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/types/meta.ts";
|
|
68
63
|
var ATTR_META = "@meta";
|
|
69
|
-
var MetaId = Symbol.for("@dxos/echo/Meta");
|
|
64
|
+
var MetaId = /* @__PURE__ */ Symbol.for("@dxos/echo/Meta");
|
|
70
65
|
var ObjectMetaSchema = Schema2.Struct({
|
|
71
66
|
keys: Schema2.Array(ForeignKey),
|
|
72
67
|
/**
|
|
@@ -76,13 +71,14 @@ var ObjectMetaSchema = Schema2.Struct({
|
|
|
76
71
|
*/
|
|
77
72
|
// TODO(dmaretskyi): Has to be optional for compatibility with old data.
|
|
78
73
|
// Defaulting to an empty array is possible but requires a bit more work.
|
|
74
|
+
// TODO(dmaretskyi): In automerge this should be a map of { [tag]: boolean } for uniqueness and conflict resolution.
|
|
79
75
|
tags: Schema2.optional(Schema2.Array(Schema2.String))
|
|
80
76
|
});
|
|
81
77
|
var getMeta = (obj) => {
|
|
82
78
|
const metadata = obj[MetaId];
|
|
83
79
|
invariant(metadata, "ObjectMeta not found.", {
|
|
84
80
|
F: __dxlog_file,
|
|
85
|
-
L:
|
|
81
|
+
L: 55,
|
|
86
82
|
S: void 0,
|
|
87
83
|
A: [
|
|
88
84
|
"metadata",
|
|
@@ -98,2766 +94,1631 @@ var foreignKey = (source, id) => ({
|
|
|
98
94
|
var foreignKeyEquals = (a, b) => a.source === b.source && a.id === b.id;
|
|
99
95
|
var compareForeignKeys = (a, b) => intersection(getMeta(a).keys, getMeta(b).keys, foreignKeyEquals).length > 0;
|
|
100
96
|
|
|
101
|
-
// src/internal/types/
|
|
102
|
-
var
|
|
97
|
+
// src/internal/common/types/model-symbols.ts
|
|
98
|
+
var ATTR_SELF_DXN = "@dxn";
|
|
99
|
+
var SelfDXNId = /* @__PURE__ */ Symbol.for("@dxos/echo/DXN");
|
|
100
|
+
var ATTR_DELETED = "@deleted";
|
|
101
|
+
var ObjectDeletedId = /* @__PURE__ */ Symbol.for("@dxos/echo/Deleted");
|
|
102
|
+
var ObjectVersionId = /* @__PURE__ */ Symbol.for("@dxos/echo/Version");
|
|
103
|
+
var ObjectDatabaseId = /* @__PURE__ */ Symbol.for("@dxos/echo/Database");
|
|
104
|
+
var ATTR_RELATION_SOURCE = "@relationSource";
|
|
105
|
+
var RelationSourceId = /* @__PURE__ */ Symbol.for("@dxos/echo/RelationSource");
|
|
106
|
+
var RelationSourceDXNId = /* @__PURE__ */ Symbol.for("@dxos/echo/RelationSourceDXN");
|
|
107
|
+
var ATTR_RELATION_TARGET = "@relationTarget";
|
|
108
|
+
var RelationTargetId = /* @__PURE__ */ Symbol.for("@dxos/echo/RelationTarget");
|
|
109
|
+
var RelationTargetDXNId = /* @__PURE__ */ Symbol.for("@dxos/echo/RelationTargetDXN");
|
|
110
|
+
|
|
111
|
+
// src/internal/common/types/version.ts
|
|
112
|
+
var VersionTypeId = "~@dxos/echo/VersionTypeId";
|
|
103
113
|
|
|
104
|
-
// src/internal/
|
|
105
|
-
var
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return getLabelWithSchema(schema, entity);
|
|
114
|
+
// src/internal/Annotation/sorting.ts
|
|
115
|
+
var compare = (a, b) => {
|
|
116
|
+
if (a == null) {
|
|
117
|
+
return b == null ? 0 : 1;
|
|
109
118
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const schema = getSchema(entity);
|
|
113
|
-
if (schema != null) {
|
|
114
|
-
setLabelWithSchema(schema, entity, label);
|
|
119
|
+
if (b == null) {
|
|
120
|
+
return -1;
|
|
115
121
|
}
|
|
122
|
+
return a.localeCompare(b);
|
|
116
123
|
};
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
var sortByLabel = (a, b) => compare(getLabel(a), getLabel(b));
|
|
125
|
+
var sortByTypename = (a, b) => compare(getTypename(a), getTypename(b));
|
|
126
|
+
var sort = (...comparators) => {
|
|
127
|
+
return (a, b) => {
|
|
128
|
+
for (const comparator of comparators) {
|
|
129
|
+
const result = comparator(a, b);
|
|
130
|
+
if (result !== 0) {
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return 0;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// src/internal/common/api/meta.ts
|
|
139
|
+
import { assertArgument, invariant as invariant2 } from "@dxos/invariant";
|
|
140
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/api/meta.ts";
|
|
141
|
+
function getMetaChecked(entity) {
|
|
142
|
+
assertArgument(entity, "entity", "Should be an entity.");
|
|
143
|
+
const meta = getMeta(entity);
|
|
144
|
+
invariant2(meta != null, "Invalid entity.", {
|
|
145
|
+
F: __dxlog_file2,
|
|
146
|
+
L: 34,
|
|
147
|
+
S: this,
|
|
148
|
+
A: [
|
|
149
|
+
"meta != null",
|
|
150
|
+
"'Invalid entity.'"
|
|
151
|
+
]
|
|
152
|
+
});
|
|
153
|
+
return meta;
|
|
154
|
+
}
|
|
155
|
+
var getKeys = (entity, source) => {
|
|
156
|
+
assertArgument(entity, "entity", "Should be an entity.");
|
|
157
|
+
const meta = getMetaChecked(entity);
|
|
158
|
+
invariant2(meta != null, "Invalid entity.", {
|
|
159
|
+
F: __dxlog_file2,
|
|
160
|
+
L: 45,
|
|
161
|
+
S: void 0,
|
|
162
|
+
A: [
|
|
163
|
+
"meta != null",
|
|
164
|
+
"'Invalid entity.'"
|
|
165
|
+
]
|
|
166
|
+
});
|
|
167
|
+
return meta.keys.filter((key) => key.source === source);
|
|
168
|
+
};
|
|
169
|
+
var deleteKeys = (entity, source) => {
|
|
170
|
+
const meta = getMetaChecked(entity);
|
|
171
|
+
for (let i = 0; i < meta.keys.length; i++) {
|
|
172
|
+
if (meta.keys[i].source === source) {
|
|
173
|
+
meta.keys.splice(i, 1);
|
|
174
|
+
i--;
|
|
175
|
+
}
|
|
121
176
|
}
|
|
122
177
|
};
|
|
123
|
-
var
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
178
|
+
var addTag = (entity, tag) => {
|
|
179
|
+
const meta = getMetaChecked(entity);
|
|
180
|
+
meta.tags ??= [];
|
|
181
|
+
meta.tags.push(tag);
|
|
182
|
+
};
|
|
183
|
+
var removeTag = (entity, tag) => {
|
|
184
|
+
const meta = getMetaChecked(entity);
|
|
185
|
+
if (!meta.tags) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
for (let i = 0; i < meta.tags.length; i++) {
|
|
189
|
+
if (meta.tags[i] === tag) {
|
|
190
|
+
meta.tags.splice(i, 1);
|
|
191
|
+
i--;
|
|
192
|
+
}
|
|
127
193
|
}
|
|
128
194
|
};
|
|
129
195
|
|
|
130
|
-
// src/internal/
|
|
131
|
-
|
|
132
|
-
|
|
196
|
+
// src/internal/common/proxy/symbols.ts
|
|
197
|
+
var EventId = /* @__PURE__ */ Symbol.for("@dxos/live-object/EventId");
|
|
198
|
+
var ChangeId = /* @__PURE__ */ Symbol.for("@dxos/live-object/ChangeId");
|
|
133
199
|
|
|
134
|
-
// src/internal/
|
|
135
|
-
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// ? void | Simplify<Schema.TypeLiteral.Constructor<Fields, []>>
|
|
149
|
-
// : Simplify<Schema.TypeLiteral.Constructor<Fields, []>>,
|
|
150
|
-
// options?: MakeProps,
|
|
151
|
-
// ): Simplify<Schema.TypeLiteral.Type<Fields, []>> {
|
|
152
|
-
// const propsWithDefaults: any = _lazilyMergeDefaults(fields, { ...(props as any) });
|
|
153
|
-
// return _getDisableValidationMakeOption(options)
|
|
154
|
-
// ? propsWithDefaults
|
|
155
|
-
// : ParseResult.validateSync(this)(propsWithDefaults);
|
|
156
|
-
// }
|
|
157
|
-
static instanceOf(value2) {
|
|
158
|
-
return Schema3.is(this)(value2);
|
|
200
|
+
// src/internal/common/proxy/event-batch.ts
|
|
201
|
+
var eventBatchDepth = 0;
|
|
202
|
+
var pendingEventTargets = /* @__PURE__ */ new Set();
|
|
203
|
+
var batchEvents = (callback) => {
|
|
204
|
+
eventBatchDepth++;
|
|
205
|
+
try {
|
|
206
|
+
callback();
|
|
207
|
+
} finally {
|
|
208
|
+
eventBatchDepth--;
|
|
209
|
+
if (eventBatchDepth === 0) {
|
|
210
|
+
for (const target of pendingEventTargets) {
|
|
211
|
+
target[EventId]?.emit();
|
|
212
|
+
}
|
|
213
|
+
pendingEventTargets.clear();
|
|
159
214
|
}
|
|
160
|
-
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
var emitEvent = (target) => {
|
|
218
|
+
if (eventBatchDepth > 0) {
|
|
219
|
+
pendingEventTargets.add(target);
|
|
220
|
+
} else {
|
|
221
|
+
target[EventId]?.emit();
|
|
222
|
+
}
|
|
161
223
|
};
|
|
162
224
|
|
|
163
|
-
// src/internal/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
var RelationTargetId = Symbol.for("@dxos/echo/RelationTarget");
|
|
180
|
-
var RelationTargetDXNId = Symbol.for("@dxos/echo/RelationTargetDXN");
|
|
181
|
-
var EchoRelationSchema = ({ source, target, typename, version: version2 }) => {
|
|
182
|
-
assertArgument(Schema4.isSchema(source), "source");
|
|
183
|
-
assertArgument(Schema4.isSchema(target), "target");
|
|
184
|
-
const sourceDXN = getDXNForRelationSchemaRef(source);
|
|
185
|
-
const targetDXN = getDXNForRelationSchemaRef(target);
|
|
186
|
-
if (getEntityKind(source) !== EntityKind.Object) {
|
|
187
|
-
raise(new Error("Source schema must be an echo object schema."));
|
|
225
|
+
// src/internal/common/proxy/change-context.ts
|
|
226
|
+
var currentChangeContext = null;
|
|
227
|
+
var pendingNotificationKey = null;
|
|
228
|
+
var pendingOwnerNotifications = /* @__PURE__ */ new Set();
|
|
229
|
+
var enterChangeContext = (key) => {
|
|
230
|
+
currentChangeContext = key;
|
|
231
|
+
return () => {
|
|
232
|
+
currentChangeContext = null;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
var isInChangeContext = (key) => {
|
|
236
|
+
return currentChangeContext === key;
|
|
237
|
+
};
|
|
238
|
+
var queueNotification = (key) => {
|
|
239
|
+
if (currentChangeContext === key) {
|
|
240
|
+
pendingNotificationKey = key;
|
|
188
241
|
}
|
|
189
|
-
|
|
190
|
-
|
|
242
|
+
};
|
|
243
|
+
var queueOwnerNotification = (target) => {
|
|
244
|
+
if (currentChangeContext !== null && target !== currentChangeContext) {
|
|
245
|
+
pendingOwnerNotifications.add(target);
|
|
191
246
|
}
|
|
192
|
-
return (self) => {
|
|
193
|
-
invariant2(SchemaAST2.isTypeLiteral(self.ast), "Schema must be a TypeLiteral.", {
|
|
194
|
-
F: __dxlog_file2,
|
|
195
|
-
L: 127,
|
|
196
|
-
S: void 0,
|
|
197
|
-
A: [
|
|
198
|
-
"SchemaAST.isTypeLiteral(self.ast)",
|
|
199
|
-
"'Schema must be a TypeLiteral.'"
|
|
200
|
-
]
|
|
201
|
-
});
|
|
202
|
-
const fields = self.fields ?? {};
|
|
203
|
-
const schemaWithId = Schema4.extend(self, Schema4.Struct({
|
|
204
|
-
id: Schema4.String
|
|
205
|
-
}));
|
|
206
|
-
const ast = SchemaAST2.annotations(schemaWithId.ast, {
|
|
207
|
-
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
208
|
-
...self.ast.annotations,
|
|
209
|
-
[TypeAnnotationId]: {
|
|
210
|
-
kind: EntityKind.Relation,
|
|
211
|
-
typename,
|
|
212
|
-
version: version2,
|
|
213
|
-
sourceSchema: sourceDXN,
|
|
214
|
-
targetSchema: targetDXN
|
|
215
|
-
},
|
|
216
|
-
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
217
|
-
[SchemaAST2.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
218
|
-
kind: EntityKind.Relation,
|
|
219
|
-
typename,
|
|
220
|
-
version: version2,
|
|
221
|
-
relationSource: sourceDXN,
|
|
222
|
-
relationTarget: targetDXN
|
|
223
|
-
})
|
|
224
|
-
});
|
|
225
|
-
return makeEchoTypeSchema(fields, ast, typename, version2, EntityKind.Relation);
|
|
226
|
-
};
|
|
227
247
|
};
|
|
228
|
-
var
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
248
|
+
var hasPendingNotifications = (key) => {
|
|
249
|
+
return pendingNotificationKey === key;
|
|
250
|
+
};
|
|
251
|
+
var clearPendingNotifications = (key) => {
|
|
252
|
+
if (pendingNotificationKey === key) {
|
|
253
|
+
pendingNotificationKey = null;
|
|
233
254
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
255
|
+
};
|
|
256
|
+
var executeChange = (contextKey, eventTarget, proxy, callback) => {
|
|
257
|
+
const exitContext = enterChangeContext(contextKey);
|
|
258
|
+
try {
|
|
259
|
+
batchEvents(() => callback(proxy));
|
|
260
|
+
} finally {
|
|
261
|
+
exitContext();
|
|
262
|
+
if (hasPendingNotifications(contextKey)) {
|
|
263
|
+
clearPendingNotifications(contextKey);
|
|
264
|
+
eventTarget[EventId]?.emit();
|
|
265
|
+
}
|
|
266
|
+
for (const ownerTarget of pendingOwnerNotifications) {
|
|
267
|
+
ownerTarget[EventId]?.emit();
|
|
268
|
+
}
|
|
269
|
+
pendingOwnerNotifications.clear();
|
|
237
270
|
}
|
|
238
|
-
return DXN.fromTypename(typename).toString();
|
|
239
271
|
};
|
|
240
272
|
|
|
241
|
-
// src/internal/
|
|
242
|
-
var
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
var ObjectVersionId = Symbol.for("@dxos/echo/Version");
|
|
248
|
-
var ObjectDatabaseId = Symbol.for("@dxos/echo/Database");
|
|
249
|
-
function assertObjectModel(obj) {
|
|
250
|
-
invariant3(typeof obj === "object" && obj !== null, "Invalid object model: not an object", {
|
|
251
|
-
F: __dxlog_file3,
|
|
252
|
-
L: 119,
|
|
253
|
-
S: this,
|
|
254
|
-
A: [
|
|
255
|
-
"typeof obj === 'object' && obj !== null",
|
|
256
|
-
"'Invalid object model: not an object'"
|
|
257
|
-
]
|
|
258
|
-
});
|
|
259
|
-
assumeType(obj);
|
|
260
|
-
invariant3(ObjectId.isValid(obj.id), "Invalid object model: invalid id", {
|
|
261
|
-
F: __dxlog_file3,
|
|
262
|
-
L: 121,
|
|
263
|
-
S: this,
|
|
264
|
-
A: [
|
|
265
|
-
"ObjectId.isValid(obj.id)",
|
|
266
|
-
"'Invalid object model: invalid id'"
|
|
267
|
-
]
|
|
268
|
-
});
|
|
269
|
-
invariant3(obj[TypeId] === void 0 || obj[TypeId] instanceof DXN2, "Invalid object model: invalid type", {
|
|
270
|
-
F: __dxlog_file3,
|
|
271
|
-
L: 122,
|
|
272
|
-
S: this,
|
|
273
|
-
A: [
|
|
274
|
-
"obj[TypeId] === undefined || obj[TypeId] instanceof DXN",
|
|
275
|
-
"'Invalid object model: invalid type'"
|
|
276
|
-
]
|
|
277
|
-
});
|
|
278
|
-
invariant3(obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation, "Invalid object model: invalid entity kind", {
|
|
279
|
-
F: __dxlog_file3,
|
|
280
|
-
L: 123,
|
|
281
|
-
S: this,
|
|
282
|
-
A: [
|
|
283
|
-
"obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation",
|
|
284
|
-
"'Invalid object model: invalid entity kind'"
|
|
285
|
-
]
|
|
273
|
+
// src/internal/common/proxy/define-hidden-property.ts
|
|
274
|
+
var defineHiddenProperty = (object, key, value2) => {
|
|
275
|
+
Object.defineProperty(object, key, {
|
|
276
|
+
enumerable: false,
|
|
277
|
+
configurable: true,
|
|
278
|
+
value: value2
|
|
286
279
|
});
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// src/internal/common/proxy/errors.ts
|
|
283
|
+
var MutationOutsideChangeContextError = class extends Error {
|
|
284
|
+
constructor(operation, suggestion) {
|
|
285
|
+
super(`Cannot ${operation} outside of Obj.change(). Use Obj.change(obj, (mutableObj) => { ${suggestion} }) instead.`);
|
|
286
|
+
this.name = "MutationOutsideChangeContextError";
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
var createPropertySetError = (prop) => {
|
|
290
|
+
return new MutationOutsideChangeContextError(`modify object property "${String(prop)}"`, `mutableObj.${String(prop)} = value;`);
|
|
291
|
+
};
|
|
292
|
+
var createPropertyDeleteError = (prop) => {
|
|
293
|
+
return new MutationOutsideChangeContextError(`delete object property "${String(prop)}"`, `delete mutableObj.${String(prop)};`);
|
|
294
|
+
};
|
|
295
|
+
var createArrayMethodError = (method) => {
|
|
296
|
+
return new MutationOutsideChangeContextError(`call array.${method}()`, `mutableObj.array.${method}(...);`);
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/internal/common/proxy/json-serializer.ts
|
|
300
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
301
|
+
import { DXN } from "@dxos/keys";
|
|
302
|
+
import { deepMapValues } from "@dxos/util";
|
|
303
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/json-serializer.ts";
|
|
304
|
+
var attachTypedJsonSerializer = (obj) => {
|
|
305
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, "toJSON");
|
|
306
|
+
if (descriptor) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
Object.defineProperty(obj, "toJSON", {
|
|
310
|
+
value: typedJsonSerializer,
|
|
311
|
+
writable: false,
|
|
312
|
+
enumerable: false,
|
|
313
|
+
// Setting `configurable` to false breaks proxy invariants, should be fixable.
|
|
314
|
+
configurable: true
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
var typedJsonSerializer = function() {
|
|
318
|
+
const { id, ...rest } = this;
|
|
319
|
+
const result = {
|
|
320
|
+
id
|
|
321
|
+
};
|
|
322
|
+
if (this[TypeId]) {
|
|
323
|
+
result[ATTR_TYPE] = this[TypeId].toString();
|
|
324
|
+
}
|
|
325
|
+
if (this[MetaId]) {
|
|
326
|
+
result[ATTR_META] = serializeMeta(this[MetaId]);
|
|
327
|
+
}
|
|
328
|
+
if (this[SelfDXNId]) {
|
|
329
|
+
result[ATTR_SELF_DXN] = this[SelfDXNId].toString();
|
|
330
|
+
}
|
|
331
|
+
if (this[RelationSourceDXNId]) {
|
|
332
|
+
const sourceDXN = this[RelationSourceDXNId];
|
|
333
|
+
invariant3(sourceDXN instanceof DXN, void 0, {
|
|
307
334
|
F: __dxlog_file3,
|
|
308
|
-
L:
|
|
335
|
+
L: 64,
|
|
309
336
|
S: this,
|
|
310
337
|
A: [
|
|
311
|
-
"
|
|
312
|
-
"
|
|
338
|
+
"sourceDXN instanceof DXN",
|
|
339
|
+
""
|
|
313
340
|
]
|
|
314
341
|
});
|
|
315
|
-
|
|
342
|
+
result[ATTR_RELATION_SOURCE] = sourceDXN.toString();
|
|
343
|
+
}
|
|
344
|
+
if (this[RelationTargetDXNId]) {
|
|
345
|
+
const targetDXN = this[RelationTargetDXNId];
|
|
346
|
+
invariant3(targetDXN instanceof DXN, void 0, {
|
|
316
347
|
F: __dxlog_file3,
|
|
317
|
-
L:
|
|
348
|
+
L: 69,
|
|
318
349
|
S: this,
|
|
319
350
|
A: [
|
|
320
|
-
"
|
|
321
|
-
"
|
|
351
|
+
"targetDXN instanceof DXN",
|
|
352
|
+
""
|
|
322
353
|
]
|
|
323
354
|
});
|
|
355
|
+
result[ATTR_RELATION_TARGET] = targetDXN.toString();
|
|
324
356
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
// src/internal/entities/object.ts
|
|
328
|
-
import * as Schema5 from "effect/Schema";
|
|
329
|
-
import * as SchemaAST3 from "effect/SchemaAST";
|
|
330
|
-
import { invariant as invariant4 } from "@dxos/invariant";
|
|
331
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/entities/object.ts";
|
|
332
|
-
var EchoObjectSchema = ({ typename, version: version2 }) => {
|
|
333
|
-
return (self) => {
|
|
334
|
-
invariant4(typeof TypeAnnotationId === "symbol", "Sanity.", {
|
|
335
|
-
F: __dxlog_file4,
|
|
336
|
-
L: 37,
|
|
337
|
-
S: void 0,
|
|
338
|
-
A: [
|
|
339
|
-
"typeof TypeAnnotationId === 'symbol'",
|
|
340
|
-
"'Sanity.'"
|
|
341
|
-
]
|
|
342
|
-
});
|
|
343
|
-
invariant4(SchemaAST3.isTypeLiteral(self.ast), "Schema must be a TypeLiteral.", {
|
|
344
|
-
F: __dxlog_file4,
|
|
345
|
-
L: 38,
|
|
346
|
-
S: void 0,
|
|
347
|
-
A: [
|
|
348
|
-
"SchemaAST.isTypeLiteral(self.ast)",
|
|
349
|
-
"'Schema must be a TypeLiteral.'"
|
|
350
|
-
]
|
|
351
|
-
});
|
|
352
|
-
const fields = self.fields ?? {};
|
|
353
|
-
const schemaWithId = Schema5.extend(self, Schema5.Struct({
|
|
354
|
-
id: Schema5.String
|
|
355
|
-
}));
|
|
356
|
-
const ast = SchemaAST3.annotations(schemaWithId.ast, {
|
|
357
|
-
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
358
|
-
...self.ast.annotations,
|
|
359
|
-
[TypeAnnotationId]: {
|
|
360
|
-
kind: EntityKind.Object,
|
|
361
|
-
typename,
|
|
362
|
-
version: version2
|
|
363
|
-
},
|
|
364
|
-
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
365
|
-
[SchemaAST3.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
366
|
-
kind: EntityKind.Object,
|
|
367
|
-
typename,
|
|
368
|
-
version: version2
|
|
369
|
-
})
|
|
370
|
-
});
|
|
371
|
-
return makeEchoTypeSchema(fields, ast, typename, version2, EntityKind.Object);
|
|
372
|
-
};
|
|
357
|
+
Object.assign(result, serializeData(rest));
|
|
358
|
+
return result;
|
|
373
359
|
};
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/entities/util.ts";
|
|
381
|
-
var getObjectDXN = (object) => {
|
|
382
|
-
invariant5(!Schema6.isSchema(object), "schema not allowed in this function", {
|
|
383
|
-
F: __dxlog_file5,
|
|
384
|
-
L: 19,
|
|
385
|
-
S: void 0,
|
|
386
|
-
A: [
|
|
387
|
-
"!Schema.isSchema(object)",
|
|
388
|
-
"'schema not allowed in this function'"
|
|
389
|
-
]
|
|
360
|
+
var serializeData = (data) => {
|
|
361
|
+
return deepMapValues(data, (value2, recurse) => {
|
|
362
|
+
if (Ref.isRef(value2)) {
|
|
363
|
+
return value2.noInline().encode();
|
|
364
|
+
}
|
|
365
|
+
return recurse(value2);
|
|
390
366
|
});
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
367
|
+
};
|
|
368
|
+
var serializeMeta = (meta) => {
|
|
369
|
+
return deepMapValues(meta, (value2, recurse) => recurse(value2));
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
// src/internal/common/proxy/make-object.ts
|
|
373
|
+
import { ObjectId } from "@dxos/keys";
|
|
374
|
+
|
|
375
|
+
// src/internal/common/proxy/proxy-utils.ts
|
|
376
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
377
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/proxy-utils.ts";
|
|
378
|
+
var symbolIsProxy = /* @__PURE__ */ Symbol.for("@dxos/schema/Proxy");
|
|
379
|
+
var isProxy = (value2) => !!value2?.[symbolIsProxy];
|
|
380
|
+
var isValidProxyTarget = (value2) => {
|
|
381
|
+
if (value2 == null || value2[symbolIsProxy]) {
|
|
382
|
+
return false;
|
|
404
383
|
}
|
|
405
|
-
if (
|
|
406
|
-
|
|
384
|
+
if (Array.isArray(value2)) {
|
|
385
|
+
return true;
|
|
407
386
|
}
|
|
408
|
-
return
|
|
387
|
+
return typeof value2 === "object" && Object.getPrototypeOf(value2) === Object.prototype;
|
|
409
388
|
};
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
invariant6(dxn != null, "Invalid entity.", {
|
|
416
|
-
F: __dxlog_file6,
|
|
417
|
-
L: 18,
|
|
389
|
+
var getProxySlot = (proxy) => {
|
|
390
|
+
const value2 = proxy[symbolIsProxy];
|
|
391
|
+
invariant4(value2 instanceof ProxyHandlerSlot, void 0, {
|
|
392
|
+
F: __dxlog_file4,
|
|
393
|
+
L: 32,
|
|
418
394
|
S: void 0,
|
|
419
395
|
A: [
|
|
420
|
-
"
|
|
421
|
-
"
|
|
396
|
+
"value instanceof ProxyHandlerSlot",
|
|
397
|
+
""
|
|
422
398
|
]
|
|
423
399
|
});
|
|
424
|
-
return
|
|
425
|
-
};
|
|
426
|
-
var getDatabase = (entity) => {
|
|
427
|
-
assumeType3(entity);
|
|
428
|
-
return entity[ObjectDatabaseId];
|
|
400
|
+
return value2;
|
|
429
401
|
};
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
import { assertArgument as assertArgument3, invariant as invariant7 } from "@dxos/invariant";
|
|
433
|
-
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/api/meta.ts";
|
|
434
|
-
function getMetaChecked(entity) {
|
|
435
|
-
assertArgument3(entity, "entity", "Should be an entity.");
|
|
436
|
-
const meta = getMeta(entity);
|
|
437
|
-
invariant7(meta != null, "Invalid entity.", {
|
|
438
|
-
F: __dxlog_file7,
|
|
439
|
-
L: 34,
|
|
440
|
-
S: this,
|
|
441
|
-
A: [
|
|
442
|
-
"meta != null",
|
|
443
|
-
"'Invalid entity.'"
|
|
444
|
-
]
|
|
445
|
-
});
|
|
446
|
-
return meta;
|
|
447
|
-
}
|
|
448
|
-
var getKeys = (entity, source) => {
|
|
449
|
-
assertArgument3(entity, "entity", "Should be an entity.");
|
|
450
|
-
const meta = getMetaChecked(entity);
|
|
451
|
-
invariant7(meta != null, "Invalid entity.", {
|
|
452
|
-
F: __dxlog_file7,
|
|
453
|
-
L: 45,
|
|
454
|
-
S: void 0,
|
|
455
|
-
A: [
|
|
456
|
-
"meta != null",
|
|
457
|
-
"'Invalid entity.'"
|
|
458
|
-
]
|
|
459
|
-
});
|
|
460
|
-
return meta.keys.filter((key) => key.source === source);
|
|
402
|
+
var getProxyTarget = (proxy) => {
|
|
403
|
+
return getProxySlot(proxy).target;
|
|
461
404
|
};
|
|
462
|
-
var
|
|
463
|
-
|
|
464
|
-
for (let i = 0; i < meta.keys.length; i++) {
|
|
465
|
-
if (meta.keys[i].source === source) {
|
|
466
|
-
meta.keys.splice(i, 1);
|
|
467
|
-
i--;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
405
|
+
var getProxyHandler = (proxy) => {
|
|
406
|
+
return getProxySlot(proxy).handler;
|
|
470
407
|
};
|
|
471
|
-
var
|
|
472
|
-
|
|
473
|
-
meta.tags ??= [];
|
|
474
|
-
meta.tags.push(tag);
|
|
408
|
+
var dangerouslySetProxyId = (obj, id) => {
|
|
409
|
+
getProxySlot(obj).target.id = id;
|
|
475
410
|
};
|
|
476
|
-
var
|
|
477
|
-
const
|
|
478
|
-
if (
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
for (let i = 0; i < meta.tags.length; i++) {
|
|
482
|
-
if (meta.tags[i] === tag) {
|
|
483
|
-
meta.tags.splice(i, 1);
|
|
484
|
-
i--;
|
|
485
|
-
}
|
|
411
|
+
var createProxy = (target, handler) => {
|
|
412
|
+
const existingProxy = handler._proxyMap.get(target);
|
|
413
|
+
if (existingProxy) {
|
|
414
|
+
return existingProxy;
|
|
486
415
|
}
|
|
416
|
+
const proxy = new Proxy(target, new ProxyHandlerSlot(target, handler));
|
|
417
|
+
handler.init(target);
|
|
418
|
+
handler._proxyMap.set(target, proxy);
|
|
419
|
+
return proxy;
|
|
487
420
|
};
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
421
|
+
var ProxyHandlerSlot = class {
|
|
422
|
+
target;
|
|
423
|
+
_handler;
|
|
424
|
+
/**
|
|
425
|
+
* @param target Original object.
|
|
426
|
+
* @param _handler Handles intercepted operations.
|
|
427
|
+
*/
|
|
428
|
+
constructor(target, _handler) {
|
|
429
|
+
this.target = target;
|
|
430
|
+
this._handler = _handler;
|
|
496
431
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
432
|
+
get handler() {
|
|
433
|
+
invariant4(this._handler, void 0, {
|
|
434
|
+
F: __dxlog_file4,
|
|
435
|
+
L: 91,
|
|
436
|
+
S: this,
|
|
437
|
+
A: [
|
|
438
|
+
"this._handler",
|
|
439
|
+
""
|
|
440
|
+
]
|
|
441
|
+
});
|
|
442
|
+
return this._handler;
|
|
443
|
+
}
|
|
444
|
+
// TODO(burdon): Requires comment.
|
|
445
|
+
setHandler(handler) {
|
|
446
|
+
this._handler = handler;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Get value.
|
|
450
|
+
*/
|
|
451
|
+
get(target, prop, receiver) {
|
|
452
|
+
if (prop === symbolIsProxy) {
|
|
453
|
+
return this;
|
|
454
|
+
}
|
|
455
|
+
if (!this._handler || !this._handler.get) {
|
|
456
|
+
return Reflect.get(target, prop, receiver);
|
|
457
|
+
}
|
|
458
|
+
return this._handler.get(target, prop, receiver);
|
|
459
|
+
}
|
|
460
|
+
static {
|
|
461
|
+
const TRAPS = [
|
|
462
|
+
"apply",
|
|
463
|
+
"construct",
|
|
464
|
+
"defineProperty",
|
|
465
|
+
"deleteProperty",
|
|
466
|
+
"get",
|
|
467
|
+
"getOwnPropertyDescriptor",
|
|
468
|
+
"getPrototypeOf",
|
|
469
|
+
"has",
|
|
470
|
+
"isExtensible",
|
|
471
|
+
"ownKeys",
|
|
472
|
+
"preventExtensions",
|
|
473
|
+
"set",
|
|
474
|
+
"setPrototypeOf"
|
|
475
|
+
];
|
|
476
|
+
for (const trap of TRAPS) {
|
|
477
|
+
if (trap === "get") {
|
|
478
|
+
continue;
|
|
507
479
|
}
|
|
480
|
+
Object.defineProperty(this.prototype, trap, {
|
|
481
|
+
enumerable: false,
|
|
482
|
+
value: function(...args) {
|
|
483
|
+
if (!this._handler || !this._handler[trap]) {
|
|
484
|
+
return Reflect[trap](...args);
|
|
485
|
+
}
|
|
486
|
+
return this._handler[trap].apply(this._handler, args);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
508
489
|
}
|
|
509
|
-
|
|
510
|
-
};
|
|
490
|
+
}
|
|
511
491
|
};
|
|
512
492
|
|
|
513
|
-
// src/internal/
|
|
514
|
-
import
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
|
|
493
|
+
// src/internal/common/proxy/typed-handler.ts
|
|
494
|
+
import * as Schema4 from "effect/Schema";
|
|
495
|
+
import * as SchemaAST3 from "effect/SchemaAST";
|
|
496
|
+
import { Event } from "@dxos/async";
|
|
497
|
+
import { inspectCustom } from "@dxos/debug";
|
|
498
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
|
499
|
+
|
|
500
|
+
// src/internal/common/proxy/ownership.ts
|
|
501
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
502
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/ownership.ts";
|
|
503
|
+
var EchoOwner = /* @__PURE__ */ Symbol.for("@dxos/echo/Owner");
|
|
504
|
+
var getRawTarget = (value2) => {
|
|
505
|
+
return isProxy(value2) ? getProxyTarget(value2) : value2;
|
|
521
506
|
};
|
|
522
|
-
var
|
|
523
|
-
|
|
524
|
-
if (ver === void 0) {
|
|
525
|
-
return unversioned;
|
|
526
|
-
}
|
|
527
|
-
return ver;
|
|
507
|
+
var getOwner = (value2) => {
|
|
508
|
+
return value2?.[EchoOwner];
|
|
528
509
|
};
|
|
529
|
-
var
|
|
530
|
-
|
|
531
|
-
return !!ver.versioned;
|
|
510
|
+
var setMetaOwner = (metaTarget, parent) => {
|
|
511
|
+
defineHiddenProperty(metaTarget, EchoOwner, parent);
|
|
532
512
|
};
|
|
533
|
-
var
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
return "unversioned";
|
|
513
|
+
var setOwnerRecursive = (value2, owner, options = {}) => {
|
|
514
|
+
const { visited = /* @__PURE__ */ new Set(), depth = 0, allowedPreviousOwner } = options;
|
|
515
|
+
if (value2 == null || typeof value2 !== "object") {
|
|
516
|
+
return;
|
|
538
517
|
}
|
|
539
|
-
|
|
540
|
-
|
|
518
|
+
const actualValue = getRawTarget(value2);
|
|
519
|
+
if (visited.has(actualValue)) {
|
|
520
|
+
return;
|
|
541
521
|
}
|
|
542
|
-
|
|
543
|
-
|
|
522
|
+
visited.add(actualValue);
|
|
523
|
+
const existingOwner = getOwner(actualValue);
|
|
524
|
+
const isRootEchoObject = EventId in actualValue;
|
|
525
|
+
let newAllowedPreviousOwner = allowedPreviousOwner;
|
|
526
|
+
if (isRootEchoObject && depth === 0) {
|
|
527
|
+
newAllowedPreviousOwner = actualValue;
|
|
544
528
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
// src/internal/json-schema/annotations.ts
|
|
557
|
-
import * as SchemaAST4 from "effect/SchemaAST";
|
|
558
|
-
var CustomAnnotations = {
|
|
559
|
-
format: FormatAnnotationId,
|
|
560
|
-
currency: CurrencyAnnotationId
|
|
561
|
-
};
|
|
562
|
-
var DecodedAnnotations = {
|
|
563
|
-
title: SchemaAST4.TitleAnnotationId,
|
|
564
|
-
description: SchemaAST4.DescriptionAnnotationId
|
|
565
|
-
};
|
|
566
|
-
var EchoAnnotations = {
|
|
567
|
-
// TODO(dmaretskyi): `FieldLookupAnnotationId` might go here, but lets remove it entirely and use LabelAnnotation instead.
|
|
568
|
-
meta: PropertyMetaAnnotationId,
|
|
569
|
-
generator: GeneratorAnnotationId,
|
|
570
|
-
labelProp: LabelAnnotationId
|
|
571
|
-
};
|
|
572
|
-
|
|
573
|
-
// src/internal/json-schema/json-schema-type.ts
|
|
574
|
-
import * as Schema7 from "effect/Schema";
|
|
575
|
-
import { JsonPath } from "@dxos/effect";
|
|
576
|
-
var SimpleTypes = Schema7.Literal("array", "boolean", "integer", "null", "number", "object", "string");
|
|
577
|
-
var NonNegativeInteger = Schema7.Number.pipe(Schema7.greaterThanOrEqualTo(0));
|
|
578
|
-
var StringArray = Schema7.Array(Schema7.String);
|
|
579
|
-
var JsonSchemaOrBoolean = Schema7.Union(Schema7.suspend(() => JsonSchemaType), Schema7.Boolean);
|
|
580
|
-
var JsonSchemaEchoAnnotations = Schema7.Struct({
|
|
581
|
-
/**
|
|
582
|
-
* Label for this schema.
|
|
583
|
-
* Mapped from {@link LabelAnnotationId}.
|
|
584
|
-
*/
|
|
585
|
-
labelProp: Schema7.optional(Schema7.Union(JsonPath, Schema7.Array(JsonPath))),
|
|
586
|
-
/**
|
|
587
|
-
* Generator function for this schema.
|
|
588
|
-
* Mapped from {@link GeneratorAnnotationId}.
|
|
589
|
-
*/
|
|
590
|
-
generator: Schema7.optional(Schema7.Union(Schema7.String, Schema7.Tuple(Schema7.String, Schema7.Number))),
|
|
591
|
-
/**
|
|
592
|
-
* {@link PropertyMeta} annotations get serialized here.
|
|
593
|
-
*/
|
|
594
|
-
meta: Schema7.optional(Schema7.Record({
|
|
595
|
-
key: Schema7.String,
|
|
596
|
-
value: Schema7.Any
|
|
597
|
-
})),
|
|
598
|
-
/**
|
|
599
|
-
* @deprecated
|
|
600
|
-
*/
|
|
601
|
-
// TODO(dmaretskyi): We risk old schema not passing validation due to the extra fields. Remove when we are sure this is safe.
|
|
602
|
-
type: Schema7.optional(Schema7.Struct({
|
|
603
|
-
typename: Schema7.String,
|
|
604
|
-
version: Schema7.String,
|
|
605
|
-
// Not used.
|
|
606
|
-
schemaId: Schema7.optional(Schema7.String)
|
|
607
|
-
})),
|
|
608
|
-
/**
|
|
609
|
-
* @deprecated Superseded by `meta`.
|
|
610
|
-
*/
|
|
611
|
-
annotations: Schema7.optional(Schema7.Record({
|
|
612
|
-
key: Schema7.String,
|
|
613
|
-
value: Schema7.Any
|
|
614
|
-
}))
|
|
615
|
-
});
|
|
616
|
-
var _JsonSchemaType = Schema7.Struct({
|
|
617
|
-
/**
|
|
618
|
-
* Identifier for this schema.
|
|
619
|
-
* This schema might be referenced by $ref clause in other schemas.
|
|
620
|
-
*/
|
|
621
|
-
// TODO(dmaretskyi): Specify how the ids are generated.
|
|
622
|
-
// TODO(dmaretskyi): For type dxns, should this include the version?
|
|
623
|
-
$id: Schema7.optional(Schema7.String),
|
|
624
|
-
/**
|
|
625
|
-
* Schema of this schema.
|
|
626
|
-
* Set to "https://json-schema.org/draft-07/schema".
|
|
627
|
-
*/
|
|
628
|
-
$schema: Schema7.optional(Schema7.String),
|
|
629
|
-
/**
|
|
630
|
-
* Reference to another schema.
|
|
631
|
-
*/
|
|
632
|
-
$ref: Schema7.optional(Schema7.String),
|
|
633
|
-
/**
|
|
634
|
-
* Comments are ignored when interpreting the schema.
|
|
635
|
-
*/
|
|
636
|
-
$comment: Schema7.optional(Schema7.String),
|
|
637
|
-
/**
|
|
638
|
-
* Defines whether this schema is an object schema or a relation schema.
|
|
639
|
-
*/
|
|
640
|
-
entityKind: Schema7.optional(EntityKindSchema),
|
|
641
|
-
/**
|
|
642
|
-
* Typename of this schema.
|
|
643
|
-
* Only on schema representing an ECHO object.
|
|
644
|
-
*
|
|
645
|
-
* @example 'example.com/type/MyType'
|
|
646
|
-
*/
|
|
647
|
-
typename: Schema7.optional(Schema7.String),
|
|
648
|
-
/**
|
|
649
|
-
* Version of this schema.
|
|
650
|
-
* Custom dialect for ECHO.
|
|
651
|
-
*/
|
|
652
|
-
version: Schema7.optional(Schema7.String),
|
|
653
|
-
/**
|
|
654
|
-
* Target of this relation.
|
|
655
|
-
* Only for relation schemas.
|
|
656
|
-
* The referenced schema must be an object schema.
|
|
657
|
-
*/
|
|
658
|
-
relationTarget: Schema7.optional(Schema7.suspend(() => JsonSchemaType)),
|
|
659
|
-
/**
|
|
660
|
-
* Source of this relation.
|
|
661
|
-
* Only for relation schemas.
|
|
662
|
-
* The referenced schema must be an object schema.
|
|
663
|
-
*/
|
|
664
|
-
relationSource: Schema7.optional(Schema7.suspend(() => JsonSchemaType)),
|
|
665
|
-
/**
|
|
666
|
-
* Title of this schema.
|
|
667
|
-
*/
|
|
668
|
-
title: Schema7.optional(Schema7.String),
|
|
669
|
-
/**
|
|
670
|
-
* Description of this schema.
|
|
671
|
-
*/
|
|
672
|
-
description: Schema7.optional(Schema7.String),
|
|
673
|
-
/**
|
|
674
|
-
* Whether this schema is read-only.
|
|
675
|
-
*/
|
|
676
|
-
readOnly: Schema7.optional(Schema7.Boolean),
|
|
677
|
-
/**
|
|
678
|
-
* Whether this schema is write-only.
|
|
679
|
-
*/
|
|
680
|
-
writeOnly: Schema7.optional(Schema7.Boolean),
|
|
681
|
-
/**
|
|
682
|
-
* Examples of instances of this schema.
|
|
683
|
-
*/
|
|
684
|
-
examples: Schema7.optional(Schema7.Array(Schema7.Any)),
|
|
685
|
-
/**
|
|
686
|
-
* Default value for this schema.
|
|
687
|
-
*/
|
|
688
|
-
default: Schema7.optional(Schema7.Any),
|
|
689
|
-
/**
|
|
690
|
-
* This schema only matches values that are equal to this value.
|
|
691
|
-
*/
|
|
692
|
-
const: Schema7.optional(Schema7.Any),
|
|
693
|
-
/**
|
|
694
|
-
* This schema only matches one of the values in this array.
|
|
695
|
-
*/
|
|
696
|
-
enum: Schema7.optional(Schema7.Array(Schema7.Any)),
|
|
697
|
-
/**
|
|
698
|
-
* Base type of the schema.
|
|
699
|
-
*/
|
|
700
|
-
type: Schema7.optional(Schema7.Union(SimpleTypes, Schema7.Array(SimpleTypes))),
|
|
701
|
-
//
|
|
702
|
-
// Numbers.
|
|
703
|
-
//
|
|
704
|
-
multipleOf: Schema7.optional(Schema7.Number.pipe(Schema7.greaterThan(0))),
|
|
705
|
-
maximum: Schema7.optional(Schema7.Number),
|
|
706
|
-
exclusiveMaximum: Schema7.optional(Schema7.Number),
|
|
707
|
-
minimum: Schema7.optional(Schema7.Number),
|
|
708
|
-
exclusiveMinimum: Schema7.optional(Schema7.Number),
|
|
709
|
-
//
|
|
710
|
-
// Strings.
|
|
711
|
-
//
|
|
712
|
-
maxLength: Schema7.optional(NonNegativeInteger),
|
|
713
|
-
/**
|
|
714
|
-
* Regex pattern for strings.
|
|
715
|
-
*/
|
|
716
|
-
pattern: Schema7.optional(Schema7.String.pipe(FormatAnnotation.set(TypeFormat.Regex))),
|
|
717
|
-
/**
|
|
718
|
-
* Serialized from {@link FormatAnnotationId}.
|
|
719
|
-
*/
|
|
720
|
-
format: Schema7.optional(Schema7.String),
|
|
721
|
-
//
|
|
722
|
-
// Arrays
|
|
723
|
-
//
|
|
724
|
-
minLength: Schema7.optional(NonNegativeInteger),
|
|
725
|
-
items: Schema7.optional(Schema7.Union(Schema7.suspend(() => JsonSchemaType), Schema7.Array(Schema7.suspend(() => JsonSchemaType)))),
|
|
726
|
-
additionalItems: Schema7.optional(Schema7.Union(Schema7.suspend(() => JsonSchemaType), Schema7.Boolean)),
|
|
727
|
-
maxItems: Schema7.optional(NonNegativeInteger),
|
|
728
|
-
minItems: Schema7.optional(NonNegativeInteger),
|
|
729
|
-
uniqueItems: Schema7.optional(Schema7.Boolean),
|
|
730
|
-
contains: Schema7.optional(Schema7.suspend(() => JsonSchemaType)),
|
|
731
|
-
//
|
|
732
|
-
// Objects
|
|
733
|
-
//
|
|
734
|
-
maxProperties: Schema7.optional(NonNegativeInteger),
|
|
735
|
-
minProperties: Schema7.optional(NonNegativeInteger),
|
|
736
|
-
required: Schema7.optional(StringArray),
|
|
737
|
-
/**
|
|
738
|
-
* Non-standard JSON Schema extension.
|
|
739
|
-
* Defines the order of properties in the object.
|
|
740
|
-
* The unmentioned properties are placed at the end.
|
|
741
|
-
*
|
|
742
|
-
* Related: https://github.com/json-schema/json-schema/issues/119
|
|
743
|
-
*/
|
|
744
|
-
propertyOrder: Schema7.optional(StringArray),
|
|
745
|
-
additionalProperties: Schema7.optional(JsonSchemaOrBoolean),
|
|
746
|
-
properties: Schema7.optional(Schema7.Record({
|
|
747
|
-
key: Schema7.String,
|
|
748
|
-
value: Schema7.suspend(() => JsonSchemaType)
|
|
749
|
-
})),
|
|
750
|
-
patternProperties: Schema7.optional(Schema7.Record({
|
|
751
|
-
key: Schema7.String,
|
|
752
|
-
value: Schema7.suspend(() => JsonSchemaType)
|
|
753
|
-
})),
|
|
754
|
-
propertyNames: Schema7.optional(Schema7.suspend(() => JsonSchemaType)),
|
|
755
|
-
definitions: Schema7.optional(Schema7.Record({
|
|
756
|
-
key: Schema7.String,
|
|
757
|
-
value: Schema7.suspend(() => JsonSchemaType)
|
|
758
|
-
})),
|
|
759
|
-
dependencies: Schema7.optional(Schema7.Record({
|
|
760
|
-
key: Schema7.String,
|
|
761
|
-
value: Schema7.suspend(() => Schema7.Union(Schema7.String, StringArray, JsonSchemaType)).annotations({
|
|
762
|
-
identifier: "dependency",
|
|
763
|
-
description: "Dependency"
|
|
764
|
-
})
|
|
765
|
-
})),
|
|
766
|
-
contentMediaType: Schema7.optional(Schema7.String),
|
|
767
|
-
contentEncoding: Schema7.optional(Schema7.String),
|
|
768
|
-
if: Schema7.optional(Schema7.suspend(() => JsonSchemaType)),
|
|
769
|
-
then: Schema7.optional(Schema7.suspend(() => JsonSchemaType)),
|
|
770
|
-
else: Schema7.optional(Schema7.suspend(() => JsonSchemaType)),
|
|
771
|
-
allOf: Schema7.optional(Schema7.Array(Schema7.suspend(() => JsonSchemaType))),
|
|
772
|
-
anyOf: Schema7.optional(Schema7.Array(Schema7.suspend(() => JsonSchemaType))),
|
|
773
|
-
oneOf: Schema7.optional(Schema7.Array(Schema7.suspend(() => JsonSchemaType))),
|
|
774
|
-
not: Schema7.optional(Schema7.suspend(() => JsonSchemaType)),
|
|
775
|
-
$defs: Schema7.optional(Schema7.Record({
|
|
776
|
-
key: Schema7.String,
|
|
777
|
-
value: Schema7.suspend(() => JsonSchemaType)
|
|
778
|
-
})),
|
|
779
|
-
//
|
|
780
|
-
// ECHO extensions.
|
|
781
|
-
//
|
|
782
|
-
currency: Schema7.optional(Schema7.String),
|
|
783
|
-
reference: Schema7.optional(Schema7.Struct({
|
|
784
|
-
schema: Schema7.suspend(() => JsonSchemaType),
|
|
785
|
-
schemaVersion: Schema7.optional(Schema7.String),
|
|
786
|
-
schemaObject: Schema7.optional(Schema7.String)
|
|
787
|
-
})),
|
|
788
|
-
/**
|
|
789
|
-
* ECHO-specific annotations.
|
|
790
|
-
*/
|
|
791
|
-
// TODO(dmaretskyi): Since we are adding a lot of new extensions to the JSON Schema, it is safer to namespace them here.
|
|
792
|
-
annotations: Schema7.optional(JsonSchemaEchoAnnotations),
|
|
793
|
-
/**
|
|
794
|
-
* @deprecated Use `annotations` instead.
|
|
795
|
-
*/
|
|
796
|
-
echo: Schema7.optional(JsonSchemaEchoAnnotations)
|
|
797
|
-
}).annotations({
|
|
798
|
-
identifier: "jsonSchema",
|
|
799
|
-
description: "JSON Schema"
|
|
800
|
-
});
|
|
801
|
-
var JsonSchemaFields = Object.keys(_JsonSchemaType.fields);
|
|
802
|
-
var JsonSchemaType = _JsonSchemaType;
|
|
803
|
-
var getSchemaProperty = (schema, property) => {
|
|
804
|
-
return schema.properties?.[property];
|
|
805
|
-
};
|
|
806
|
-
var setSchemaProperty = (schema, property, value2) => {
|
|
807
|
-
schema.properties ??= {};
|
|
808
|
-
schema.properties[property] = value2;
|
|
809
|
-
return schema;
|
|
810
|
-
};
|
|
811
|
-
var ECHO_ANNOTATIONS_NS_DEPRECATED_KEY = "echo";
|
|
812
|
-
var ECHO_ANNOTATIONS_NS_KEY = "annotations";
|
|
813
|
-
var getNormalizedEchoAnnotations = (obj) => {
|
|
814
|
-
if (obj[ECHO_ANNOTATIONS_NS_KEY] != null && obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {
|
|
815
|
-
return normalizeEchoAnnotations({
|
|
816
|
-
...obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY],
|
|
817
|
-
...obj[ECHO_ANNOTATIONS_NS_KEY]
|
|
529
|
+
if (!isRootEchoObject) {
|
|
530
|
+
const ownershipAllowed = existingOwner == null || existingOwner === owner || existingOwner === newAllowedPreviousOwner;
|
|
531
|
+
invariant5(ownershipAllowed, "Cannot reassign ownership of a nested record to a different ECHO object. Use deep copy first.", {
|
|
532
|
+
F: __dxlog_file5,
|
|
533
|
+
L: 102,
|
|
534
|
+
S: void 0,
|
|
535
|
+
A: [
|
|
536
|
+
"ownershipAllowed",
|
|
537
|
+
"'Cannot reassign ownership of a nested record to a different ECHO object. Use deep copy first.'"
|
|
538
|
+
]
|
|
818
539
|
});
|
|
819
|
-
} else if (obj[ECHO_ANNOTATIONS_NS_KEY] != null) {
|
|
820
|
-
return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_KEY]);
|
|
821
|
-
} else if (obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY] != null) {
|
|
822
|
-
return normalizeEchoAnnotations(obj[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY]);
|
|
823
|
-
} else {
|
|
824
|
-
return void 0;
|
|
825
540
|
}
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
541
|
+
defineHiddenProperty(actualValue, EchoOwner, owner);
|
|
542
|
+
const recursiveOptions = {
|
|
543
|
+
visited,
|
|
544
|
+
depth: depth + 1,
|
|
545
|
+
allowedPreviousOwner: newAllowedPreviousOwner
|
|
546
|
+
};
|
|
547
|
+
if (Array.isArray(actualValue)) {
|
|
548
|
+
for (const item of actualValue) {
|
|
549
|
+
if (isValidProxyTarget(item) || isProxy(item)) {
|
|
550
|
+
setOwnerRecursive(item, owner, recursiveOptions);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
830
553
|
} else {
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
554
|
+
for (const key in actualValue) {
|
|
555
|
+
if (Object.prototype.hasOwnProperty.call(actualValue, key)) {
|
|
556
|
+
const nested = actualValue[key];
|
|
557
|
+
if (isValidProxyTarget(nested) || isProxy(nested)) {
|
|
558
|
+
setOwnerRecursive(nested, owner, recursiveOptions);
|
|
559
|
+
}
|
|
836
560
|
}
|
|
837
|
-
}
|
|
838
|
-
delete res.annotations;
|
|
839
|
-
return res;
|
|
561
|
+
}
|
|
840
562
|
}
|
|
841
563
|
};
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
const copy = structuredClone(schema);
|
|
846
|
-
go(copy);
|
|
847
|
-
return copy;
|
|
848
|
-
};
|
|
849
|
-
var go = (schema) => {
|
|
850
|
-
if (typeof schema !== "object" || schema === null) {
|
|
851
|
-
return;
|
|
564
|
+
var traverseObjectGraph = (value2, visitor, visited = /* @__PURE__ */ new Set()) => {
|
|
565
|
+
if (value2 == null || typeof value2 !== "object") {
|
|
566
|
+
return false;
|
|
852
567
|
}
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
} else if (schema.exclusiveMaximum === false) {
|
|
857
|
-
delete schema.exclusiveMaximum;
|
|
568
|
+
const actualValue = getRawTarget(value2);
|
|
569
|
+
if (visited.has(actualValue)) {
|
|
570
|
+
return false;
|
|
858
571
|
}
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
} else if (schema.exclusiveMinimum === false) {
|
|
863
|
-
delete schema.exclusiveMinimum;
|
|
572
|
+
visited.add(actualValue);
|
|
573
|
+
if (visitor(actualValue)) {
|
|
574
|
+
return true;
|
|
864
575
|
}
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
576
|
+
if (Array.isArray(actualValue)) {
|
|
577
|
+
for (const item of actualValue) {
|
|
578
|
+
if (traverseObjectGraph(item, visitor, visited)) {
|
|
579
|
+
return true;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
} else {
|
|
583
|
+
for (const key in actualValue) {
|
|
584
|
+
if (Object.prototype.hasOwnProperty.call(actualValue, key)) {
|
|
585
|
+
if (traverseObjectGraph(actualValue[key], visitor, visited)) {
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
868
589
|
}
|
|
869
590
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
go(schema.propertyNames);
|
|
878
|
-
}
|
|
879
|
-
if (schema.definitions) {
|
|
880
|
-
goOnRecord(schema.definitions);
|
|
881
|
-
}
|
|
882
|
-
if (schema.items) {
|
|
883
|
-
maybeGoOnArray(schema.items);
|
|
884
|
-
}
|
|
885
|
-
if (schema.additionalItems) {
|
|
886
|
-
maybeGoOnArray(schema.additionalItems);
|
|
887
|
-
}
|
|
888
|
-
if (schema.contains) {
|
|
889
|
-
go(schema.contains);
|
|
890
|
-
}
|
|
891
|
-
if (schema.if) {
|
|
892
|
-
go(schema.if);
|
|
893
|
-
}
|
|
894
|
-
if (schema.then) {
|
|
895
|
-
go(schema.then);
|
|
896
|
-
}
|
|
897
|
-
if (schema.else) {
|
|
898
|
-
go(schema.else);
|
|
899
|
-
}
|
|
900
|
-
if (schema.allOf) {
|
|
901
|
-
maybeGoOnArray(schema.allOf);
|
|
902
|
-
}
|
|
903
|
-
if (schema.anyOf) {
|
|
904
|
-
maybeGoOnArray(schema.anyOf);
|
|
905
|
-
}
|
|
906
|
-
if (schema.oneOf) {
|
|
907
|
-
maybeGoOnArray(schema.oneOf);
|
|
908
|
-
}
|
|
909
|
-
if (schema.not) {
|
|
910
|
-
go(schema.not);
|
|
591
|
+
return false;
|
|
592
|
+
};
|
|
593
|
+
var wouldCreateCycle = (targetRoot, value2) => traverseObjectGraph(value2, (v) => v === targetRoot);
|
|
594
|
+
var hasForeignOwner = (value2, target) => traverseObjectGraph(value2, (v) => {
|
|
595
|
+
const owner = getOwner(v);
|
|
596
|
+
if (owner != null && owner !== target) {
|
|
597
|
+
return true;
|
|
911
598
|
}
|
|
912
|
-
if (
|
|
913
|
-
|
|
599
|
+
if (EventId in v && v !== target) {
|
|
600
|
+
return true;
|
|
914
601
|
}
|
|
915
|
-
|
|
916
|
-
|
|
602
|
+
return false;
|
|
603
|
+
});
|
|
604
|
+
var MAX_OWNER_DEPTH = 100;
|
|
605
|
+
var getEchoRoot = (target, depth = 0) => {
|
|
606
|
+
invariant5(depth < MAX_OWNER_DEPTH, "Owner chain too deep - possible circular ownership", {
|
|
607
|
+
F: __dxlog_file5,
|
|
608
|
+
L: 221,
|
|
609
|
+
S: void 0,
|
|
610
|
+
A: [
|
|
611
|
+
"depth < MAX_OWNER_DEPTH",
|
|
612
|
+
"'Owner chain too deep - possible circular ownership'"
|
|
613
|
+
]
|
|
614
|
+
});
|
|
615
|
+
if (KindId in target) {
|
|
616
|
+
return target;
|
|
917
617
|
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
for (const item of value2) {
|
|
922
|
-
go(item);
|
|
923
|
-
}
|
|
924
|
-
} else if (typeof value2 === "object" && value2 !== null) {
|
|
925
|
-
go(value2);
|
|
618
|
+
const owner = getOwner(target);
|
|
619
|
+
if (owner) {
|
|
620
|
+
return getEchoRoot(owner, depth + 1);
|
|
926
621
|
}
|
|
622
|
+
return target;
|
|
927
623
|
};
|
|
928
|
-
var
|
|
929
|
-
|
|
930
|
-
|
|
624
|
+
var notifyOwnerChain = (target) => {
|
|
625
|
+
const owner = getOwner(target);
|
|
626
|
+
if (owner) {
|
|
627
|
+
queueOwnerNotification(getEchoRoot(owner));
|
|
628
|
+
notifyOwnerChain(owner);
|
|
931
629
|
}
|
|
932
630
|
};
|
|
933
631
|
|
|
934
|
-
// src/internal/
|
|
935
|
-
|
|
936
|
-
import * as Function from "effect/Function";
|
|
937
|
-
import * as JSONSchema from "effect/JSONSchema";
|
|
938
|
-
import * as Option2 from "effect/Option";
|
|
939
|
-
import * as Schema9 from "effect/Schema";
|
|
940
|
-
import * as SchemaAST6 from "effect/SchemaAST";
|
|
941
|
-
import { raise as raise2 } from "@dxos/debug";
|
|
942
|
-
import { mapAst } from "@dxos/effect";
|
|
943
|
-
import { assertArgument as assertArgument6, invariant as invariant9 } from "@dxos/invariant";
|
|
944
|
-
import { DXN as DXN5, ObjectId as ObjectId4 } from "@dxos/keys";
|
|
945
|
-
import { log } from "@dxos/log";
|
|
946
|
-
import { clearUndefined, orderKeys, removeProperties } from "@dxos/util";
|
|
632
|
+
// src/internal/common/proxy/proxy-types.ts
|
|
633
|
+
var objectData = /* @__PURE__ */ Symbol.for("@dxos/live-object/objectData");
|
|
947
634
|
|
|
948
|
-
// src/internal/
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
import { inspectCustom } from "@dxos/debug";
|
|
956
|
-
import { EncodedReference } from "@dxos/echo-protocol";
|
|
957
|
-
import { assertArgument as assertArgument5, invariant as invariant8 } from "@dxos/invariant";
|
|
958
|
-
import { DXN as DXN4, ObjectId as ObjectId3 } from "@dxos/keys";
|
|
959
|
-
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/ref/ref.ts";
|
|
960
|
-
var JSON_SCHEMA_ECHO_REF_ID = "/schemas/echo/ref";
|
|
961
|
-
var getSchemaReference = (property) => {
|
|
962
|
-
const { $id, reference: { schema: { $ref } = {} } = {} } = property;
|
|
963
|
-
if ($id === JSON_SCHEMA_ECHO_REF_ID && $ref) {
|
|
964
|
-
return {
|
|
965
|
-
typename: DXN4.parse($ref).typename
|
|
966
|
-
};
|
|
967
|
-
}
|
|
968
|
-
};
|
|
969
|
-
var createSchemaReference = (typename) => {
|
|
970
|
-
return {
|
|
971
|
-
$id: JSON_SCHEMA_ECHO_REF_ID,
|
|
972
|
-
reference: {
|
|
973
|
-
schema: {
|
|
974
|
-
$ref: DXN4.fromTypename(typename).toString()
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
};
|
|
978
|
-
};
|
|
979
|
-
var getReferenceAst = (ast) => {
|
|
980
|
-
if (ast._tag !== "Declaration" || !ast.annotations[ReferenceAnnotationId]) {
|
|
981
|
-
return void 0;
|
|
982
|
-
}
|
|
983
|
-
return {
|
|
984
|
-
typename: ast.annotations[ReferenceAnnotationId].typename,
|
|
985
|
-
version: ast.annotations[ReferenceAnnotationId].version
|
|
986
|
-
};
|
|
987
|
-
};
|
|
988
|
-
var RefTypeId = Symbol("@dxos/echo/internal/Ref");
|
|
989
|
-
var Ref = (schema) => {
|
|
990
|
-
assertArgument5(Schema8.isSchema(schema), "schema", "Must call with an instance of effect-schema");
|
|
991
|
-
const annotation = getTypeAnnotation(schema);
|
|
992
|
-
if (annotation == null) {
|
|
993
|
-
throw new Error("Reference target must be an ECHO schema.");
|
|
635
|
+
// src/internal/common/proxy/reactive-array.ts
|
|
636
|
+
var checkArrayMutationAllowed = (arr, method) => {
|
|
637
|
+
const target = isProxy(arr) ? getProxyTarget(arr) : arr;
|
|
638
|
+
const echoRoot = getEchoRoot(target);
|
|
639
|
+
const isInitialized = echoRoot[ChangeId] === true || EventId in echoRoot;
|
|
640
|
+
if (!isInitialized) {
|
|
641
|
+
return;
|
|
994
642
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
Ref.isRef = (obj) => {
|
|
998
|
-
return obj && typeof obj === "object" && RefTypeId in obj;
|
|
999
|
-
};
|
|
1000
|
-
Ref.hasObjectId = (id) => (ref) => ref.dxn.isLocalObjectId() && ref.dxn.parts[1] === id;
|
|
1001
|
-
Ref.isRefSchema = (schema) => {
|
|
1002
|
-
return Ref.isRefSchemaAST(schema.ast);
|
|
1003
|
-
};
|
|
1004
|
-
Ref.isRefSchemaAST = (ast) => {
|
|
1005
|
-
return SchemaAST5.getAnnotation(ast, ReferenceAnnotationId).pipe(Option.isSome);
|
|
1006
|
-
};
|
|
1007
|
-
Ref.make = (obj) => {
|
|
1008
|
-
if (typeof obj !== "object" || obj === null) {
|
|
1009
|
-
throw new TypeError("Expected: ECHO object.");
|
|
643
|
+
if (!isInChangeContext(echoRoot)) {
|
|
644
|
+
throw createArrayMethodError(method);
|
|
1010
645
|
}
|
|
1011
|
-
const id = obj.id;
|
|
1012
|
-
invariant8(ObjectId3.isValid(id), "Invalid object ID", {
|
|
1013
|
-
F: __dxlog_file8,
|
|
1014
|
-
L: 222,
|
|
1015
|
-
S: void 0,
|
|
1016
|
-
A: [
|
|
1017
|
-
"ObjectId.isValid(id)",
|
|
1018
|
-
"'Invalid object ID'"
|
|
1019
|
-
]
|
|
1020
|
-
});
|
|
1021
|
-
const dxn = DXN4.fromLocalObjectId(id);
|
|
1022
|
-
return new RefImpl(dxn, obj);
|
|
1023
646
|
};
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
};
|
|
1028
|
-
var createEchoReferenceSchema = (echoId, typename, version2) => {
|
|
1029
|
-
if (!echoId && !typename) {
|
|
1030
|
-
throw new TypeError("Either echoId or typename must be provided.");
|
|
647
|
+
var ReactiveArray = class extends Array {
|
|
648
|
+
static get [Symbol.species]() {
|
|
649
|
+
return Array;
|
|
1031
650
|
}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
const dbService = yield* Effect.serviceOption(Service);
|
|
1053
|
-
if (Ref.isRef(value2)) {
|
|
1054
|
-
if (Option.isSome(dbService)) {
|
|
1055
|
-
return dbService.value.db.makeRef(value2.dxn);
|
|
1056
|
-
} else {
|
|
1057
|
-
return value2;
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
if (!EncodedReference.isEncodedReference(value2)) {
|
|
1061
|
-
return yield* Effect.fail(new ParseResult.Unexpected(value2, "reference"));
|
|
1062
|
-
}
|
|
1063
|
-
if (Option.isSome(dbService)) {
|
|
1064
|
-
return dbService.value.db.makeRef(EncodedReference.toDXN(value2));
|
|
1065
|
-
} else {
|
|
1066
|
-
return Ref.fromDXN(EncodedReference.toDXN(value2));
|
|
651
|
+
static {
|
|
652
|
+
const BATCHED_METHODS = [
|
|
653
|
+
"push",
|
|
654
|
+
"pop",
|
|
655
|
+
"shift",
|
|
656
|
+
"unshift",
|
|
657
|
+
"splice",
|
|
658
|
+
"sort",
|
|
659
|
+
"reverse"
|
|
660
|
+
];
|
|
661
|
+
for (const method of BATCHED_METHODS) {
|
|
662
|
+
Object.defineProperty(this.prototype, method, {
|
|
663
|
+
enumerable: false,
|
|
664
|
+
value: function(...args) {
|
|
665
|
+
checkArrayMutationAllowed(this, method);
|
|
666
|
+
let result;
|
|
667
|
+
batchEvents(() => {
|
|
668
|
+
result = Array.prototype[method].apply(this, args);
|
|
669
|
+
});
|
|
670
|
+
return result;
|
|
1067
671
|
}
|
|
1068
672
|
});
|
|
1069
673
|
}
|
|
1070
|
-
}, {
|
|
1071
|
-
jsonSchema: {
|
|
1072
|
-
// TODO(dmaretskyi): We should remove `$id` and keep `$ref` with a fully qualified name.
|
|
1073
|
-
$id: JSON_SCHEMA_ECHO_REF_ID,
|
|
1074
|
-
$ref: JSON_SCHEMA_ECHO_REF_ID,
|
|
1075
|
-
reference: referenceInfo
|
|
1076
|
-
},
|
|
1077
|
-
[ReferenceAnnotationId]: {
|
|
1078
|
-
typename: typename ?? "",
|
|
1079
|
-
version: version2
|
|
1080
|
-
}
|
|
1081
|
-
});
|
|
1082
|
-
return refSchema;
|
|
1083
|
-
};
|
|
1084
|
-
var RefImpl = class _RefImpl {
|
|
1085
|
-
#dxn;
|
|
1086
|
-
#resolver = void 0;
|
|
1087
|
-
#resolved = new Event();
|
|
1088
|
-
/**
|
|
1089
|
-
* Target is set when the reference is created from a specific object.
|
|
1090
|
-
* In this case, the target might not be in the database.
|
|
1091
|
-
*/
|
|
1092
|
-
#target = void 0;
|
|
1093
|
-
/**
|
|
1094
|
-
* Callback to issue a reactive notification when object is resolved.
|
|
1095
|
-
*/
|
|
1096
|
-
#resolverCallback = () => {
|
|
1097
|
-
this.#resolved.emit();
|
|
1098
|
-
};
|
|
1099
|
-
constructor(dxn, target) {
|
|
1100
|
-
this.#dxn = dxn;
|
|
1101
|
-
this.#target = target;
|
|
1102
674
|
}
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
// src/internal/common/proxy/schema-validator.ts
|
|
678
|
+
import * as Schema3 from "effect/Schema";
|
|
679
|
+
import * as SchemaAST2 from "effect/SchemaAST";
|
|
680
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
681
|
+
import { log } from "@dxos/log";
|
|
682
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/schema-validator.ts";
|
|
683
|
+
var SchemaValidator = class {
|
|
1103
684
|
/**
|
|
1104
|
-
*
|
|
685
|
+
* Recursively check that schema specifies constructions we can handle.
|
|
686
|
+
* Validates there are no ambiguous discriminated union types.
|
|
1105
687
|
*/
|
|
1106
|
-
|
|
1107
|
-
|
|
688
|
+
static validateSchema(schema) {
|
|
689
|
+
const visitAll = (nodes) => nodes.forEach((node) => this.validateSchema(Schema3.make(node)));
|
|
690
|
+
if (SchemaAST2.isUnion(schema.ast)) {
|
|
691
|
+
const typeAstList = schema.ast.types.filter((type) => SchemaAST2.isTypeLiteral(type));
|
|
692
|
+
if (typeAstList.length > 1) {
|
|
693
|
+
getTypeDiscriminators(typeAstList);
|
|
694
|
+
}
|
|
695
|
+
visitAll(typeAstList);
|
|
696
|
+
} else if (SchemaAST2.isTupleType(schema.ast)) {
|
|
697
|
+
const positionalTypes = schema.ast.elements.map((t) => t.type);
|
|
698
|
+
const allTypes = positionalTypes.concat(schema.ast.rest.map((t) => t.type));
|
|
699
|
+
visitAll(allTypes);
|
|
700
|
+
} else if (SchemaAST2.isTypeLiteral(schema.ast)) {
|
|
701
|
+
visitAll(SchemaAST2.getPropertySignatures(schema.ast).map((p) => p.type));
|
|
702
|
+
}
|
|
1108
703
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
704
|
+
static hasTypeAnnotation(rootObjectSchema, property, annotation) {
|
|
705
|
+
try {
|
|
706
|
+
let type = this.getPropertySchema(rootObjectSchema, [
|
|
707
|
+
property
|
|
708
|
+
]);
|
|
709
|
+
if (SchemaAST2.isTupleType(type.ast)) {
|
|
710
|
+
type = this.getPropertySchema(rootObjectSchema, [
|
|
711
|
+
property,
|
|
712
|
+
"0"
|
|
713
|
+
]);
|
|
714
|
+
}
|
|
715
|
+
return type.ast.annotations[annotation] != null;
|
|
716
|
+
} catch {
|
|
717
|
+
return false;
|
|
718
|
+
}
|
|
1114
719
|
}
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
720
|
+
static getPropertySchema(rootObjectSchema, propertyPath, getProperty = () => null) {
|
|
721
|
+
let schema = rootObjectSchema;
|
|
722
|
+
for (let i = 0; i < propertyPath.length; i++) {
|
|
723
|
+
const propertyName = propertyPath[i];
|
|
724
|
+
const tupleAst = unwrapArray(schema.ast);
|
|
725
|
+
if (tupleAst != null) {
|
|
726
|
+
schema = getArrayElementSchema(tupleAst, propertyName);
|
|
727
|
+
} else {
|
|
728
|
+
const propertyType = getPropertyType(schema.ast, propertyName.toString(), (propertyName2) => getProperty([
|
|
729
|
+
...propertyPath.slice(0, i),
|
|
730
|
+
propertyName2
|
|
731
|
+
]));
|
|
732
|
+
if (propertyType == null) {
|
|
733
|
+
log.warn("unknown property", {
|
|
734
|
+
path: propertyPath,
|
|
735
|
+
property: propertyName
|
|
736
|
+
}, {
|
|
737
|
+
F: __dxlog_file6,
|
|
738
|
+
L: 71,
|
|
739
|
+
S: this,
|
|
740
|
+
C: (f, a) => f(...a)
|
|
741
|
+
});
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
schema = Schema3.make(propertyType).annotations(propertyType.annotations);
|
|
745
|
+
}
|
|
1121
746
|
}
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
747
|
+
return schema;
|
|
748
|
+
}
|
|
749
|
+
static getTargetPropertySchema(target, prop) {
|
|
750
|
+
const schema = target[SchemaId];
|
|
751
|
+
invariant6(schema, "target has no schema", {
|
|
752
|
+
F: __dxlog_file6,
|
|
753
|
+
L: 84,
|
|
1125
754
|
S: this,
|
|
1126
755
|
A: [
|
|
1127
|
-
"
|
|
1128
|
-
"'
|
|
756
|
+
"schema",
|
|
757
|
+
"'target has no schema'"
|
|
1129
758
|
]
|
|
1130
759
|
});
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
* @inheritdoc
|
|
1135
|
-
*/
|
|
1136
|
-
async load() {
|
|
1137
|
-
if (this.#target) {
|
|
1138
|
-
return this.#target;
|
|
760
|
+
const arrayAst = unwrapArray(schema.ast);
|
|
761
|
+
if (arrayAst != null) {
|
|
762
|
+
return getArrayElementSchema(arrayAst, prop);
|
|
1139
763
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
764
|
+
const propertyType = getPropertyType(schema.ast, prop.toString(), (prop2) => target[prop2]);
|
|
765
|
+
if (propertyType == null) {
|
|
766
|
+
return Schema3.Any;
|
|
767
|
+
}
|
|
768
|
+
invariant6(propertyType, `invalid property: ${prop.toString()}`, {
|
|
769
|
+
F: __dxlog_file6,
|
|
770
|
+
L: 95,
|
|
1143
771
|
S: this,
|
|
1144
772
|
A: [
|
|
1145
|
-
"
|
|
1146
|
-
"
|
|
773
|
+
"propertyType",
|
|
774
|
+
"`invalid property: ${prop.toString()}`"
|
|
1147
775
|
]
|
|
1148
776
|
});
|
|
1149
|
-
|
|
1150
|
-
if (obj == null) {
|
|
1151
|
-
throw new Error("Object not found");
|
|
1152
|
-
}
|
|
1153
|
-
return obj;
|
|
777
|
+
return Schema3.make(propertyType);
|
|
1154
778
|
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
F: __dxlog_file8,
|
|
1164
|
-
L: 416,
|
|
1165
|
-
S: this,
|
|
779
|
+
};
|
|
780
|
+
var getArrayElementSchema = (tupleAst, property) => {
|
|
781
|
+
const elementIndex = typeof property === "string" ? parseInt(property, 10) : Number.NaN;
|
|
782
|
+
if (Number.isNaN(elementIndex)) {
|
|
783
|
+
invariant6(property === "length", `invalid array property: ${String(property)}`, {
|
|
784
|
+
F: __dxlog_file6,
|
|
785
|
+
L: 111,
|
|
786
|
+
S: void 0,
|
|
1166
787
|
A: [
|
|
1167
|
-
"
|
|
1168
|
-
"
|
|
788
|
+
"property === 'length'",
|
|
789
|
+
"`invalid array property: ${String(property)}`"
|
|
1169
790
|
]
|
|
1170
791
|
});
|
|
1171
|
-
return
|
|
1172
|
-
}
|
|
1173
|
-
/**
|
|
1174
|
-
* Do not inline the target object in the reference.
|
|
1175
|
-
* Makes .target unavailable unless the reference is connected to a database context.
|
|
1176
|
-
* Clones the reference object.
|
|
1177
|
-
*/
|
|
1178
|
-
noInline() {
|
|
1179
|
-
const ref = new _RefImpl(this.#dxn, void 0);
|
|
1180
|
-
ref.#resolver = this.#resolver;
|
|
1181
|
-
return ref;
|
|
1182
|
-
}
|
|
1183
|
-
encode() {
|
|
1184
|
-
return {
|
|
1185
|
-
"/": this.#dxn.toString(),
|
|
1186
|
-
...this.#target ? {
|
|
1187
|
-
target: this.#target
|
|
1188
|
-
} : {}
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Serializes the reference to a JSON object.
|
|
1193
|
-
* The serialization format is compatible with the IPLD-style encoded references.
|
|
1194
|
-
* When a reference has a saved target (i.e. the target or object holding the reference is not in the database),
|
|
1195
|
-
* the target is included in the serialized object.
|
|
1196
|
-
*/
|
|
1197
|
-
toJSON() {
|
|
1198
|
-
return this.encode();
|
|
792
|
+
return Schema3.Number;
|
|
1199
793
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
}
|
|
1204
|
-
return `Ref(${this.#dxn.toString()})`;
|
|
794
|
+
if (elementIndex < tupleAst.elements.length) {
|
|
795
|
+
const elementType = tupleAst.elements[elementIndex].type;
|
|
796
|
+
return Schema3.make(elementType).annotations(elementType.annotations);
|
|
1205
797
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
798
|
+
const restType = tupleAst.rest;
|
|
799
|
+
return Schema3.make(restType[0].type).annotations(restType[0].annotations);
|
|
800
|
+
};
|
|
801
|
+
var flattenUnion = (typeAst) => SchemaAST2.isUnion(typeAst) ? typeAst.types.flatMap(flattenUnion) : [
|
|
802
|
+
typeAst
|
|
803
|
+
];
|
|
804
|
+
var getProperties = (typeAst, getTargetPropertyFn) => {
|
|
805
|
+
const astCandidates = flattenUnion(typeAst);
|
|
806
|
+
const typeAstList = astCandidates.filter((type) => SchemaAST2.isTypeLiteral(type));
|
|
807
|
+
if (typeAstList.length === 0) {
|
|
808
|
+
return [];
|
|
1217
809
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
*/
|
|
1221
|
-
_getSavedTarget() {
|
|
1222
|
-
return this.#target;
|
|
810
|
+
if (typeAstList.length === 1) {
|
|
811
|
+
return SchemaAST2.getPropertySignatures(typeAstList[0]);
|
|
1223
812
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
A: [
|
|
1231
|
-
"ref instanceof RefImpl",
|
|
1232
|
-
"'Ref is not an instance of RefImpl'"
|
|
1233
|
-
]
|
|
1234
|
-
});
|
|
1235
|
-
ref._setResolver(resolver);
|
|
1236
|
-
};
|
|
1237
|
-
var getRefSavedTarget = (ref) => {
|
|
1238
|
-
invariant8(ref instanceof RefImpl, "Ref is not an instance of RefImpl", {
|
|
1239
|
-
F: __dxlog_file8,
|
|
1240
|
-
L: 491,
|
|
813
|
+
const typeDiscriminators = getTypeDiscriminators(typeAstList);
|
|
814
|
+
const targetPropertyValue = getTargetPropertyFn(String(typeDiscriminators[0].name));
|
|
815
|
+
const typeIndex = typeDiscriminators.findIndex((p) => targetPropertyValue === p.type.literal);
|
|
816
|
+
invariant6(typeIndex !== -1, "discriminator field not set on target", {
|
|
817
|
+
F: __dxlog_file6,
|
|
818
|
+
L: 142,
|
|
1241
819
|
S: void 0,
|
|
1242
820
|
A: [
|
|
1243
|
-
"
|
|
1244
|
-
"'
|
|
821
|
+
"typeIndex !== -1",
|
|
822
|
+
"'discriminator field not set on target'"
|
|
1245
823
|
]
|
|
1246
824
|
});
|
|
1247
|
-
return
|
|
1248
|
-
};
|
|
1249
|
-
var refVariance = {
|
|
1250
|
-
_T: null
|
|
1251
|
-
};
|
|
1252
|
-
var refFromEncodedReference = (encodedReference, resolver) => {
|
|
1253
|
-
const dxn = DXN4.parse(encodedReference["/"]);
|
|
1254
|
-
const ref = new RefImpl(dxn);
|
|
1255
|
-
if (resolver) {
|
|
1256
|
-
setRefResolver(ref, resolver);
|
|
1257
|
-
}
|
|
1258
|
-
return ref;
|
|
1259
|
-
};
|
|
1260
|
-
var StaticRefResolver = class {
|
|
1261
|
-
objects = /* @__PURE__ */ new Map();
|
|
1262
|
-
schemas = /* @__PURE__ */ new Map();
|
|
1263
|
-
addObject(obj) {
|
|
1264
|
-
this.objects.set(obj.id, obj);
|
|
1265
|
-
return this;
|
|
1266
|
-
}
|
|
1267
|
-
addSchema(schema) {
|
|
1268
|
-
const dxn = getSchemaDXN(schema);
|
|
1269
|
-
invariant8(dxn, "Schema has no DXN", {
|
|
1270
|
-
F: __dxlog_file8,
|
|
1271
|
-
L: 523,
|
|
1272
|
-
S: this,
|
|
1273
|
-
A: [
|
|
1274
|
-
"dxn",
|
|
1275
|
-
"'Schema has no DXN'"
|
|
1276
|
-
]
|
|
1277
|
-
});
|
|
1278
|
-
this.schemas.set(dxn.toString(), schema);
|
|
1279
|
-
return this;
|
|
1280
|
-
}
|
|
1281
|
-
resolveSync(dxn, _load, _onLoad) {
|
|
1282
|
-
const id = dxn?.asEchoDXN()?.echoId;
|
|
1283
|
-
if (id == null) {
|
|
1284
|
-
return void 0;
|
|
1285
|
-
}
|
|
1286
|
-
return this.objects.get(id);
|
|
1287
|
-
}
|
|
1288
|
-
async resolve(dxn) {
|
|
1289
|
-
const id = dxn?.asEchoDXN()?.echoId;
|
|
1290
|
-
if (id == null) {
|
|
1291
|
-
return void 0;
|
|
1292
|
-
}
|
|
1293
|
-
return this.objects.get(id);
|
|
1294
|
-
}
|
|
1295
|
-
async resolveSchema(dxn) {
|
|
1296
|
-
return this.schemas.get(dxn.toString());
|
|
1297
|
-
}
|
|
825
|
+
return SchemaAST2.getPropertySignatures(typeAstList[typeIndex]);
|
|
1298
826
|
};
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
/**
|
|
1304
|
-
* @returns all resolved targets.
|
|
1305
|
-
*/
|
|
1306
|
-
targets: (refs) => {
|
|
1307
|
-
return refs.map((ref) => ref.target).filter(isNonNullable);
|
|
1308
|
-
},
|
|
1309
|
-
/**
|
|
1310
|
-
* Load all referenced objects.
|
|
1311
|
-
*/
|
|
1312
|
-
loadAll: (refs) => {
|
|
1313
|
-
return Promise.all(refs.map((ref) => ref.load()));
|
|
1314
|
-
},
|
|
1315
|
-
/**
|
|
1316
|
-
* Removes the ref with the given id.
|
|
1317
|
-
*/
|
|
1318
|
-
removeById: (refs, id) => {
|
|
1319
|
-
const index = refs.findIndex(Ref.hasObjectId(id));
|
|
1320
|
-
if (index >= 0) {
|
|
1321
|
-
refs.splice(index, 1);
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
});
|
|
1325
|
-
|
|
1326
|
-
// src/internal/json-schema/json-schema.ts
|
|
1327
|
-
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/json-schema/json-schema.ts";
|
|
1328
|
-
var PropType = /* @__PURE__ */ (function(PropType2) {
|
|
1329
|
-
PropType2[PropType2["NONE"] = 0] = "NONE";
|
|
1330
|
-
PropType2[PropType2["STRING"] = 1] = "STRING";
|
|
1331
|
-
PropType2[PropType2["NUMBER"] = 2] = "NUMBER";
|
|
1332
|
-
PropType2[PropType2["BOOLEAN"] = 3] = "BOOLEAN";
|
|
1333
|
-
PropType2[PropType2["DATE"] = 4] = "DATE";
|
|
1334
|
-
PropType2[PropType2["REF"] = 5] = "REF";
|
|
1335
|
-
PropType2[PropType2["RECORD"] = 6] = "RECORD";
|
|
1336
|
-
PropType2[PropType2["ENUM"] = 7] = "ENUM";
|
|
1337
|
-
return PropType2;
|
|
1338
|
-
})({});
|
|
1339
|
-
var toPropType = (type) => {
|
|
1340
|
-
switch (type) {
|
|
1341
|
-
case 1:
|
|
1342
|
-
return "string";
|
|
1343
|
-
case 2:
|
|
1344
|
-
return "number";
|
|
1345
|
-
case 3:
|
|
1346
|
-
return "boolean";
|
|
1347
|
-
case 4:
|
|
1348
|
-
return "date";
|
|
1349
|
-
case 5:
|
|
1350
|
-
return "ref";
|
|
1351
|
-
case 6:
|
|
1352
|
-
return "object";
|
|
1353
|
-
default:
|
|
1354
|
-
throw new Error(`Invalid type: ${type}`);
|
|
1355
|
-
}
|
|
1356
|
-
};
|
|
1357
|
-
var JSON_SCHEMA_URL = "http://json-schema.org/draft-07/schema#";
|
|
1358
|
-
var toJsonSchema = (schema, options = {}) => {
|
|
1359
|
-
assertArgument6(Schema9.isSchema(schema), "schema");
|
|
1360
|
-
let jsonSchema = _toJsonSchemaAST(schema.ast);
|
|
1361
|
-
if (options.strict) {
|
|
1362
|
-
jsonSchema = removeProperties(jsonSchema, (key, value2) => {
|
|
1363
|
-
if (key === "$id" && value2 === "/schemas/any") {
|
|
1364
|
-
return true;
|
|
1365
|
-
}
|
|
1366
|
-
if (key === "$ref" && value2 === "#/$defs/dependency") {
|
|
1367
|
-
return true;
|
|
1368
|
-
}
|
|
1369
|
-
if (key === "$ref" && value2 === "#/$defs/jsonSchema") {
|
|
1370
|
-
return true;
|
|
1371
|
-
}
|
|
1372
|
-
return false;
|
|
1373
|
-
});
|
|
827
|
+
var getPropertyType = (ast, propertyName, getTargetPropertyFn) => {
|
|
828
|
+
const anyOrObject = unwrapAst(ast, (candidate) => SchemaAST2.isAnyKeyword(candidate) || SchemaAST2.isObjectKeyword(candidate));
|
|
829
|
+
if (anyOrObject != null) {
|
|
830
|
+
return ast;
|
|
1374
831
|
}
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
var _toJsonSchemaAST = (ast) => {
|
|
1378
|
-
const withRefinements = withEchoRefinements(ast, "#");
|
|
1379
|
-
const jsonSchema = JSONSchema.fromAST(withRefinements, {
|
|
1380
|
-
definitions: {}
|
|
832
|
+
const typeOrDiscriminatedUnion = unwrapAst(ast, (t) => {
|
|
833
|
+
return SchemaAST2.isTypeLiteral(t) || SchemaAST2.isUnion(t) && t.types.some((t2) => SchemaAST2.isTypeLiteral(t2));
|
|
1381
834
|
});
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
var withEchoRefinements = (ast, path, suspendCache = /* @__PURE__ */ new Map()) => {
|
|
1385
|
-
if (path) {
|
|
1386
|
-
suspendCache.set(ast, path);
|
|
1387
|
-
}
|
|
1388
|
-
let recursiveResult;
|
|
1389
|
-
if (SchemaAST6.isSuspend(ast)) {
|
|
1390
|
-
const suspendedAst = ast.f();
|
|
1391
|
-
const cachedPath = suspendCache.get(suspendedAst);
|
|
1392
|
-
if (cachedPath) {
|
|
1393
|
-
recursiveResult = new SchemaAST6.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {
|
|
1394
|
-
[SchemaAST6.JSONSchemaAnnotationId]: {
|
|
1395
|
-
$ref: cachedPath
|
|
1396
|
-
}
|
|
1397
|
-
});
|
|
1398
|
-
} else {
|
|
1399
|
-
const jsonSchema = _toJsonSchemaAST(suspendedAst);
|
|
1400
|
-
recursiveResult = new SchemaAST6.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {
|
|
1401
|
-
[SchemaAST6.JSONSchemaAnnotationId]: jsonSchema
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
} else if (SchemaAST6.isTypeLiteral(ast)) {
|
|
1405
|
-
recursiveResult = mapAst(ast, (ast2, key) => withEchoRefinements(ast2, path && typeof key === "string" ? `${path}/${key}` : void 0, suspendCache));
|
|
1406
|
-
recursiveResult = addJsonSchemaFields(recursiveResult, {
|
|
1407
|
-
propertyOrder: [
|
|
1408
|
-
...ast.propertySignatures.map((p) => p.name)
|
|
1409
|
-
]
|
|
1410
|
-
});
|
|
1411
|
-
} else if (SchemaAST6.isUndefinedKeyword(ast)) {
|
|
1412
|
-
return ast;
|
|
1413
|
-
} else {
|
|
1414
|
-
recursiveResult = mapAst(ast, (ast2, key) => withEchoRefinements(ast2, path && (typeof key === "string" || typeof key === "number") ? `${path}/${key}` : void 0, suspendCache));
|
|
835
|
+
if (typeOrDiscriminatedUnion == null) {
|
|
836
|
+
return null;
|
|
1415
837
|
}
|
|
1416
|
-
const
|
|
1417
|
-
if (
|
|
1418
|
-
return
|
|
1419
|
-
} else {
|
|
1420
|
-
return addJsonSchemaFields(recursiveResult, annotationFields);
|
|
1421
|
-
}
|
|
1422
|
-
};
|
|
1423
|
-
var toEffectSchema = (root, _defs) => {
|
|
1424
|
-
const defs = root.$defs ? {
|
|
1425
|
-
..._defs,
|
|
1426
|
-
...root.$defs
|
|
1427
|
-
} : _defs ?? {};
|
|
1428
|
-
if ("type" in root && root.type === "object") {
|
|
1429
|
-
return objectToEffectSchema(root, defs);
|
|
1430
|
-
}
|
|
1431
|
-
let result = Schema9.Unknown;
|
|
1432
|
-
if ("$ref" in root) {
|
|
1433
|
-
switch (root.$ref) {
|
|
1434
|
-
case "/schemas/echo/ref": {
|
|
1435
|
-
result = refToEffectSchema(root);
|
|
1436
|
-
break;
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
} else if ("$id" in root) {
|
|
1440
|
-
switch (root.$id) {
|
|
1441
|
-
case "/schemas/any": {
|
|
1442
|
-
result = anyToEffectSchema(root);
|
|
1443
|
-
break;
|
|
1444
|
-
}
|
|
1445
|
-
case "/schemas/unknown": {
|
|
1446
|
-
result = Schema9.Unknown;
|
|
1447
|
-
break;
|
|
1448
|
-
}
|
|
1449
|
-
case "/schemas/{}":
|
|
1450
|
-
case "/schemas/object": {
|
|
1451
|
-
result = Schema9.Object;
|
|
1452
|
-
break;
|
|
1453
|
-
}
|
|
1454
|
-
// Custom ECHO object reference.
|
|
1455
|
-
case "/schemas/echo/ref": {
|
|
1456
|
-
result = refToEffectSchema(root);
|
|
1457
|
-
break;
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
} else if ("enum" in root) {
|
|
1461
|
-
result = Schema9.Union(...root.enum.map((e) => Schema9.Literal(e)));
|
|
1462
|
-
} else if ("oneOf" in root) {
|
|
1463
|
-
result = Schema9.Union(...root.oneOf.map((v) => toEffectSchema(v, defs)));
|
|
1464
|
-
} else if ("anyOf" in root) {
|
|
1465
|
-
result = Schema9.Union(...root.anyOf.map((v) => toEffectSchema(v, defs)));
|
|
1466
|
-
} else if ("allOf" in root) {
|
|
1467
|
-
if (root.allOf.length === 1) {
|
|
1468
|
-
result = toEffectSchema(root.allOf[0], defs);
|
|
1469
|
-
} else {
|
|
1470
|
-
log.warn("allOf with multiple schemas is not supported", void 0, {
|
|
1471
|
-
F: __dxlog_file9,
|
|
1472
|
-
L: 224,
|
|
1473
|
-
S: void 0,
|
|
1474
|
-
C: (f, a) => f(...a)
|
|
1475
|
-
});
|
|
1476
|
-
result = Schema9.Unknown;
|
|
1477
|
-
}
|
|
1478
|
-
} else if ("type" in root) {
|
|
1479
|
-
switch (root.type) {
|
|
1480
|
-
case "string": {
|
|
1481
|
-
result = Schema9.String;
|
|
1482
|
-
if (root.pattern) {
|
|
1483
|
-
result = result.pipe(Schema9.pattern(new RegExp(root.pattern)));
|
|
1484
|
-
}
|
|
1485
|
-
break;
|
|
1486
|
-
}
|
|
1487
|
-
case "number": {
|
|
1488
|
-
result = Schema9.Number;
|
|
1489
|
-
break;
|
|
1490
|
-
}
|
|
1491
|
-
case "integer": {
|
|
1492
|
-
result = Schema9.Number.pipe(Schema9.int());
|
|
1493
|
-
break;
|
|
1494
|
-
}
|
|
1495
|
-
case "boolean": {
|
|
1496
|
-
result = Schema9.Boolean;
|
|
1497
|
-
break;
|
|
1498
|
-
}
|
|
1499
|
-
case "array": {
|
|
1500
|
-
if (Array4.isArray(root.items)) {
|
|
1501
|
-
const [required, optional5] = Function.pipe(root.items, Array4.map((v) => toEffectSchema(v, defs)), Array4.splitAt(root.minItems ?? root.items.length));
|
|
1502
|
-
result = Schema9.Tuple(...required, ...optional5.map(Schema9.optionalElement));
|
|
1503
|
-
} else {
|
|
1504
|
-
invariant9(root.items, void 0, {
|
|
1505
|
-
F: __dxlog_file9,
|
|
1506
|
-
L: 257,
|
|
1507
|
-
S: void 0,
|
|
1508
|
-
A: [
|
|
1509
|
-
"root.items",
|
|
1510
|
-
""
|
|
1511
|
-
]
|
|
1512
|
-
});
|
|
1513
|
-
const items = root.items;
|
|
1514
|
-
result = Array4.isArray(items) ? Schema9.Tuple(...items.map((v) => toEffectSchema(v, defs))) : Schema9.Array(toEffectSchema(items, defs));
|
|
1515
|
-
}
|
|
1516
|
-
break;
|
|
1517
|
-
}
|
|
1518
|
-
case "null": {
|
|
1519
|
-
result = Schema9.Null;
|
|
1520
|
-
break;
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
} else if ("$ref" in root) {
|
|
1524
|
-
const refSegments = root.$ref.split("/");
|
|
1525
|
-
const jsonSchema = defs[refSegments[refSegments.length - 1]];
|
|
1526
|
-
invariant9(jsonSchema, `missing definition for ${root.$ref}`, {
|
|
1527
|
-
F: __dxlog_file9,
|
|
1528
|
-
L: 273,
|
|
1529
|
-
S: void 0,
|
|
1530
|
-
A: [
|
|
1531
|
-
"jsonSchema",
|
|
1532
|
-
"`missing definition for ${root.$ref}`"
|
|
1533
|
-
]
|
|
1534
|
-
});
|
|
1535
|
-
result = toEffectSchema(jsonSchema, defs).pipe(Schema9.annotations({
|
|
1536
|
-
identifier: refSegments[refSegments.length - 1]
|
|
1537
|
-
}));
|
|
838
|
+
const targetProperty = getProperties(typeOrDiscriminatedUnion, getTargetPropertyFn).find((p) => p.name === propertyName);
|
|
839
|
+
if (targetProperty != null) {
|
|
840
|
+
return unwrapAst(targetProperty.type);
|
|
1538
841
|
}
|
|
1539
|
-
const
|
|
1540
|
-
|
|
1541
|
-
|
|
842
|
+
const indexSignatureType = unwrapAst(ast, SchemaAST2.isTypeLiteral);
|
|
843
|
+
if (indexSignatureType && SchemaAST2.isTypeLiteral(indexSignatureType) && indexSignatureType.indexSignatures.length > 0) {
|
|
844
|
+
return unwrapAst(indexSignatureType.indexSignatures[0].type);
|
|
845
|
+
}
|
|
846
|
+
return null;
|
|
1542
847
|
};
|
|
1543
|
-
var
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
848
|
+
var getTypeDiscriminators = (typeAstList) => {
|
|
849
|
+
const discriminatorPropCandidates = typeAstList.flatMap(SchemaAST2.getPropertySignatures).filter((p) => SchemaAST2.isLiteral(p.type));
|
|
850
|
+
const propertyName = discriminatorPropCandidates[0].name;
|
|
851
|
+
const isValidDiscriminator = discriminatorPropCandidates.every((p) => p.name === propertyName && !p.isOptional);
|
|
852
|
+
const everyTypeHasDiscriminator = discriminatorPropCandidates.length === typeAstList.length;
|
|
853
|
+
const isDiscriminatedUnion = isValidDiscriminator && everyTypeHasDiscriminator;
|
|
854
|
+
invariant6(isDiscriminatedUnion, "type ambiguity: every type in a union must have a single unique-literal field", {
|
|
855
|
+
F: __dxlog_file6,
|
|
856
|
+
L: 193,
|
|
1547
857
|
S: void 0,
|
|
1548
858
|
A: [
|
|
1549
|
-
"
|
|
1550
|
-
"
|
|
859
|
+
"isDiscriminatedUnion",
|
|
860
|
+
"'type ambiguity: every type in a union must have a single unique-literal field'"
|
|
1551
861
|
]
|
|
1552
862
|
});
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
immutableIdField = toEffectSchema(value2, defs);
|
|
1561
|
-
} else {
|
|
1562
|
-
fields[key] = root.required?.includes(key) ? toEffectSchema(value2, defs) : Schema9.optional(toEffectSchema(value2, defs));
|
|
863
|
+
return discriminatorPropCandidates;
|
|
864
|
+
};
|
|
865
|
+
var unwrapAst = (rootAst, predicate) => {
|
|
866
|
+
let ast = rootAst;
|
|
867
|
+
while (ast != null) {
|
|
868
|
+
if (predicate?.(ast)) {
|
|
869
|
+
return ast;
|
|
1563
870
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
S: void 0,
|
|
1574
|
-
A: [
|
|
1575
|
-
"propertyList.length === 0",
|
|
1576
|
-
"'pattern properties mixed with regular properties are not supported'"
|
|
1577
|
-
]
|
|
1578
|
-
});
|
|
1579
|
-
invariant9(Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === "", "only one pattern property is supported", {
|
|
1580
|
-
F: __dxlog_file9,
|
|
1581
|
-
L: 315,
|
|
1582
|
-
S: void 0,
|
|
1583
|
-
A: [
|
|
1584
|
-
"Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === ''",
|
|
1585
|
-
"'only one pattern property is supported'"
|
|
1586
|
-
]
|
|
1587
|
-
});
|
|
1588
|
-
schema = Schema9.Record({
|
|
1589
|
-
key: Schema9.String,
|
|
1590
|
-
value: toEffectSchema(root.patternProperties[""], defs)
|
|
1591
|
-
});
|
|
1592
|
-
} else if (typeof root.additionalProperties !== "object") {
|
|
1593
|
-
schema = Schema9.Struct(fields);
|
|
1594
|
-
} else {
|
|
1595
|
-
const indexValue = toEffectSchema(root.additionalProperties, defs);
|
|
1596
|
-
if (propertyList.length > 0) {
|
|
1597
|
-
schema = Schema9.Struct(fields, {
|
|
1598
|
-
key: Schema9.String,
|
|
1599
|
-
value: indexValue
|
|
1600
|
-
});
|
|
871
|
+
if (SchemaAST2.isUnion(ast)) {
|
|
872
|
+
const next = ast.types.find((t) => predicate != null && predicate(t) || SchemaAST2.isSuspend(t));
|
|
873
|
+
if (next != null) {
|
|
874
|
+
ast = next;
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
if (SchemaAST2.isSuspend(ast)) {
|
|
879
|
+
ast = ast.f();
|
|
1601
880
|
} else {
|
|
1602
|
-
|
|
1603
|
-
key: Schema9.String,
|
|
1604
|
-
value: indexValue
|
|
1605
|
-
});
|
|
881
|
+
return predicate == null ? ast : null;
|
|
1606
882
|
}
|
|
1607
883
|
}
|
|
1608
|
-
|
|
1609
|
-
schema = Schema9.extend(schema, Schema9.Struct({
|
|
1610
|
-
id: immutableIdField
|
|
1611
|
-
}));
|
|
1612
|
-
}
|
|
1613
|
-
const annotations4 = jsonSchemaFieldsToAnnotations(root);
|
|
1614
|
-
return schema.annotations(annotations4);
|
|
1615
|
-
};
|
|
1616
|
-
var anyToEffectSchema = (root) => {
|
|
1617
|
-
const echoRefinement = root[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
|
|
1618
|
-
if (echoRefinement?.reference != null) {
|
|
1619
|
-
const echoId = root.$id.startsWith("dxn:echo:") ? root.$id : void 0;
|
|
1620
|
-
return createEchoReferenceSchema(echoId, echoRefinement.reference.typename, echoRefinement.reference.version);
|
|
1621
|
-
}
|
|
1622
|
-
return Schema9.Any;
|
|
884
|
+
return null;
|
|
1623
885
|
};
|
|
1624
|
-
var
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
if (typeof reference !== "object") {
|
|
1630
|
-
throw new Error("Invalid reference field in ref schema");
|
|
1631
|
-
}
|
|
1632
|
-
const targetSchemaDXN = DXN5.parse(reference.schema.$ref);
|
|
1633
|
-
invariant9(targetSchemaDXN.kind === DXN5.kind.TYPE, void 0, {
|
|
1634
|
-
F: __dxlog_file9,
|
|
1635
|
-
L: 368,
|
|
886
|
+
var unwrapArray = (ast) => unwrapAst(ast, SchemaAST2.isTupleType);
|
|
887
|
+
var checkIdNotPresentOnSchema = (schema) => {
|
|
888
|
+
invariant6(SchemaAST2.isTypeLiteral(schema.ast), void 0, {
|
|
889
|
+
F: __dxlog_file6,
|
|
890
|
+
L: 236,
|
|
1636
891
|
S: void 0,
|
|
1637
892
|
A: [
|
|
1638
|
-
"
|
|
893
|
+
"SchemaAST.isTypeLiteral(schema.ast)",
|
|
1639
894
|
""
|
|
1640
895
|
]
|
|
1641
896
|
});
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
const schemaFields = {};
|
|
1646
|
-
const echoAnnotations = {};
|
|
1647
|
-
for (const [key, annotationId] of Object.entries(EchoAnnotations)) {
|
|
1648
|
-
if (annotations4[annotationId] != null) {
|
|
1649
|
-
echoAnnotations[key] = annotations4[annotationId];
|
|
1650
|
-
}
|
|
897
|
+
const idProperty = SchemaAST2.getPropertySignatures(schema.ast).find((prop) => prop.name === "id");
|
|
898
|
+
if (idProperty != null) {
|
|
899
|
+
throw new Error('"id" property name is reserved');
|
|
1651
900
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
// src/internal/common/proxy/typed-handler.ts
|
|
904
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/typed-handler.ts";
|
|
905
|
+
var deepCopy = (value2, visited = /* @__PURE__ */ new Map()) => {
|
|
906
|
+
if (value2 == null || typeof value2 !== "object") {
|
|
907
|
+
return value2;
|
|
1654
908
|
}
|
|
1655
|
-
const
|
|
1656
|
-
if (
|
|
1657
|
-
|
|
1658
|
-
schemaFields[ECHO_ANNOTATIONS_NS_KEY].schemaId = echoIdentifier;
|
|
909
|
+
const actualValue = getRawTarget(value2);
|
|
910
|
+
if (visited.has(actualValue)) {
|
|
911
|
+
return visited.get(actualValue);
|
|
1659
912
|
}
|
|
1660
|
-
|
|
1661
|
-
const
|
|
1662
|
-
|
|
1663
|
-
|
|
913
|
+
if (actualValue instanceof ReactiveArray) {
|
|
914
|
+
const copy2 = new ReactiveArray();
|
|
915
|
+
visited.set(actualValue, copy2);
|
|
916
|
+
for (const item of actualValue) {
|
|
917
|
+
copy2.push(deepCopy(item, visited));
|
|
1664
918
|
}
|
|
919
|
+
copyHiddenProperties(actualValue, copy2);
|
|
920
|
+
return copy2;
|
|
1665
921
|
}
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
if (schema.$id && schema.$id.startsWith("dxn:echo:")) {
|
|
1670
|
-
return schema.$id;
|
|
1671
|
-
} else if (schema.$id && schema.$id.startsWith("dxn:type:") && schema?.echo?.type?.schemaId) {
|
|
1672
|
-
const id = schema?.echo?.type?.schemaId;
|
|
1673
|
-
if (ObjectId4.isValid(id)) {
|
|
1674
|
-
return DXN5.fromLocalObjectId(id).toString();
|
|
1675
|
-
}
|
|
922
|
+
const proto = Object.getPrototypeOf(actualValue);
|
|
923
|
+
if (proto !== Object.prototype && proto !== Array.prototype && proto !== null) {
|
|
924
|
+
return value2;
|
|
1676
925
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
// TODO(dmaretskyi): Decoding default.
|
|
1683
|
-
kind: schema.entityKind ? Schema9.decodeSync(EntityKindSchema)(schema.entityKind) : EntityKind.Object,
|
|
1684
|
-
typename: schema.typename,
|
|
1685
|
-
version: schema.version ?? "0.1.0"
|
|
1686
|
-
};
|
|
1687
|
-
if (annotation.kind === EntityKind.Relation) {
|
|
1688
|
-
const source = schema.relationSource?.$ref ?? raise2(new Error("Relation source not set"));
|
|
1689
|
-
const target = schema.relationTarget?.$ref ?? raise2(new Error("Relation target not set"));
|
|
1690
|
-
annotation.sourceSchema = DXN5.parse(source).toString();
|
|
1691
|
-
annotation.targetSchema = DXN5.parse(target).toString();
|
|
926
|
+
if (Array.isArray(actualValue)) {
|
|
927
|
+
const copy2 = new ReactiveArray();
|
|
928
|
+
visited.set(actualValue, copy2);
|
|
929
|
+
for (const item of actualValue) {
|
|
930
|
+
copy2.push(deepCopy(item, visited));
|
|
1692
931
|
}
|
|
1693
|
-
return
|
|
932
|
+
return copy2;
|
|
1694
933
|
}
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
version: schema.echo.type.version
|
|
1700
|
-
};
|
|
934
|
+
const copy = {};
|
|
935
|
+
visited.set(actualValue, copy);
|
|
936
|
+
for (const key of Object.keys(actualValue)) {
|
|
937
|
+
copy[key] = deepCopy(actualValue[key], visited);
|
|
1701
938
|
}
|
|
1702
|
-
|
|
939
|
+
copyHiddenProperties(actualValue, copy);
|
|
940
|
+
return copy;
|
|
1703
941
|
};
|
|
1704
|
-
var
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
if (echoAnnotations) {
|
|
1708
|
-
for (const [key, annotationId] of Object.entries(EchoAnnotations)) {
|
|
1709
|
-
if (echoAnnotations[key]) {
|
|
1710
|
-
annotations4[annotationId] = echoAnnotations[key];
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
942
|
+
var copyHiddenProperties = (source, target) => {
|
|
943
|
+
if (SchemaId in source) {
|
|
944
|
+
defineHiddenProperty(target, SchemaId, source[SchemaId]);
|
|
1713
945
|
}
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
if (typeAnnotation) {
|
|
1717
|
-
annotations4[TypeAnnotationId] = typeAnnotation;
|
|
1718
|
-
annotations4[SchemaAST6.JSONSchemaAnnotationId] = makeTypeJsonSchemaAnnotation({
|
|
1719
|
-
kind: typeAnnotation.kind,
|
|
1720
|
-
typename: typeAnnotation.typename,
|
|
1721
|
-
version: typeAnnotation.version,
|
|
1722
|
-
relationSource: typeAnnotation.sourceSchema,
|
|
1723
|
-
relationTarget: typeAnnotation.targetSchema
|
|
1724
|
-
});
|
|
946
|
+
if (TypeId in source) {
|
|
947
|
+
defineHiddenProperty(target, TypeId, source[TypeId]);
|
|
1725
948
|
}
|
|
1726
|
-
for (const [key, annotationId] of Object.entries({
|
|
1727
|
-
...CustomAnnotations,
|
|
1728
|
-
...DecodedAnnotations
|
|
1729
|
-
})) {
|
|
1730
|
-
if (key in schema) {
|
|
1731
|
-
annotations4[annotationId] = schema[key];
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
return clearUndefined(annotations4);
|
|
1735
|
-
};
|
|
1736
|
-
var makeAnnotatedRefinement = (ast, annotations4) => {
|
|
1737
|
-
return new SchemaAST6.Refinement(ast, () => Option2.none(), annotations4);
|
|
1738
|
-
};
|
|
1739
|
-
var addJsonSchemaFields = (ast, schema) => makeAnnotatedRefinement(ast, {
|
|
1740
|
-
[SchemaAST6.JSONSchemaAnnotationId]: schema
|
|
1741
|
-
});
|
|
1742
|
-
var normalizeJsonSchema = (jsonSchema) => {
|
|
1743
|
-
if (jsonSchema.properties && "id" in jsonSchema.properties) {
|
|
1744
|
-
jsonSchema.properties = orderKeys(jsonSchema.properties, [
|
|
1745
|
-
"id"
|
|
1746
|
-
]);
|
|
1747
|
-
}
|
|
1748
|
-
jsonSchema.$schema = JSON_SCHEMA_URL;
|
|
1749
|
-
jsonSchema = orderKeys(jsonSchema, [
|
|
1750
|
-
"$schema",
|
|
1751
|
-
"$id",
|
|
1752
|
-
"entityKind",
|
|
1753
|
-
"typename",
|
|
1754
|
-
"version",
|
|
1755
|
-
"relationTarget",
|
|
1756
|
-
"relationSource",
|
|
1757
|
-
"type",
|
|
1758
|
-
"enum",
|
|
1759
|
-
"properties",
|
|
1760
|
-
"required",
|
|
1761
|
-
"propertyOrder",
|
|
1762
|
-
"items",
|
|
1763
|
-
"additionalProperties",
|
|
1764
|
-
"anyOf",
|
|
1765
|
-
"oneOf"
|
|
1766
|
-
]);
|
|
1767
|
-
return jsonSchema;
|
|
1768
|
-
};
|
|
1769
|
-
|
|
1770
|
-
// src/internal/object/common.ts
|
|
1771
|
-
import * as Schema10 from "effect/Schema";
|
|
1772
|
-
var makeTypedEntityClass = (typename, version2, baseSchema) => {
|
|
1773
|
-
return class {
|
|
1774
|
-
// Implement TypedObject properties.
|
|
1775
|
-
static typename = typename;
|
|
1776
|
-
static version = version2;
|
|
1777
|
-
// Implement Schema.Schema properties.
|
|
1778
|
-
// TODO(burdon): Comment required.
|
|
1779
|
-
static [Schema10.TypeId] = schemaVariance;
|
|
1780
|
-
static ast = baseSchema.ast;
|
|
1781
|
-
static annotations = baseSchema.annotations.bind(baseSchema);
|
|
1782
|
-
static pipe = baseSchema.pipe.bind(baseSchema);
|
|
1783
|
-
// TODO(burdon): Comment required.
|
|
1784
|
-
static [Symbol.hasInstance](obj) {
|
|
1785
|
-
return obj != null && getTypename(obj) === typename;
|
|
1786
|
-
}
|
|
1787
|
-
// TODO(burdon): Throw APIError.
|
|
1788
|
-
constructor() {
|
|
1789
|
-
throw new Error("Use live(Typename, { ...fields }) to instantiate an object.");
|
|
1790
|
-
}
|
|
1791
|
-
};
|
|
1792
|
-
};
|
|
1793
|
-
var schemaVariance = {
|
|
1794
|
-
_A: (_) => _,
|
|
1795
|
-
_I: (_) => _,
|
|
1796
|
-
_R: (_) => _
|
|
1797
|
-
};
|
|
1798
|
-
|
|
1799
|
-
// src/internal/object/create-object.ts
|
|
1800
|
-
import { raise as raise4 } from "@dxos/debug";
|
|
1801
|
-
import { assertArgument as assertArgument8, failedInvariant } from "@dxos/invariant";
|
|
1802
|
-
import { ObjectId as ObjectId7 } from "@dxos/keys";
|
|
1803
|
-
|
|
1804
|
-
// src/internal/proxy/symbols.ts
|
|
1805
|
-
var EventId = Symbol.for("@dxos/live-object/EventId");
|
|
1806
|
-
var ChangeId = Symbol.for("@dxos/live-object/ChangeId");
|
|
1807
|
-
|
|
1808
|
-
// src/internal/proxy/event-batch.ts
|
|
1809
|
-
var eventBatchDepth = 0;
|
|
1810
|
-
var pendingEventTargets = /* @__PURE__ */ new Set();
|
|
1811
|
-
var batchEvents = (callback) => {
|
|
1812
|
-
eventBatchDepth++;
|
|
1813
|
-
try {
|
|
1814
|
-
callback();
|
|
1815
|
-
} finally {
|
|
1816
|
-
eventBatchDepth--;
|
|
1817
|
-
if (eventBatchDepth === 0) {
|
|
1818
|
-
for (const target of pendingEventTargets) {
|
|
1819
|
-
target[EventId]?.emit();
|
|
1820
|
-
}
|
|
1821
|
-
pendingEventTargets.clear();
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
};
|
|
1825
|
-
var emitEvent = (target) => {
|
|
1826
|
-
if (eventBatchDepth > 0) {
|
|
1827
|
-
pendingEventTargets.add(target);
|
|
1828
|
-
} else {
|
|
1829
|
-
target[EventId]?.emit();
|
|
1830
|
-
}
|
|
1831
|
-
};
|
|
1832
|
-
|
|
1833
|
-
// src/internal/proxy/change-context.ts
|
|
1834
|
-
var currentChangeContext = null;
|
|
1835
|
-
var pendingNotificationKey = null;
|
|
1836
|
-
var pendingOwnerNotifications = /* @__PURE__ */ new Set();
|
|
1837
|
-
var enterChangeContext = (key) => {
|
|
1838
|
-
currentChangeContext = key;
|
|
1839
|
-
return () => {
|
|
1840
|
-
currentChangeContext = null;
|
|
1841
|
-
};
|
|
1842
949
|
};
|
|
1843
|
-
var
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
pendingNotificationKey = key;
|
|
1849
|
-
}
|
|
1850
|
-
};
|
|
1851
|
-
var queueOwnerNotification = (target) => {
|
|
1852
|
-
if (currentChangeContext !== null && target !== currentChangeContext) {
|
|
1853
|
-
pendingOwnerNotifications.add(target);
|
|
1854
|
-
}
|
|
1855
|
-
};
|
|
1856
|
-
var hasPendingNotifications = (key) => {
|
|
1857
|
-
return pendingNotificationKey === key;
|
|
1858
|
-
};
|
|
1859
|
-
var clearPendingNotifications = (key) => {
|
|
1860
|
-
if (pendingNotificationKey === key) {
|
|
1861
|
-
pendingNotificationKey = null;
|
|
1862
|
-
}
|
|
1863
|
-
};
|
|
1864
|
-
var executeChange = (contextKey, eventTarget, proxy, callback) => {
|
|
1865
|
-
const exitContext = enterChangeContext(contextKey);
|
|
1866
|
-
try {
|
|
1867
|
-
batchEvents(() => callback(proxy));
|
|
1868
|
-
} finally {
|
|
1869
|
-
exitContext();
|
|
1870
|
-
if (hasPendingNotifications(contextKey)) {
|
|
1871
|
-
clearPendingNotifications(contextKey);
|
|
1872
|
-
eventTarget[EventId]?.emit();
|
|
1873
|
-
}
|
|
1874
|
-
for (const ownerTarget of pendingOwnerNotifications) {
|
|
1875
|
-
ownerTarget[EventId]?.emit();
|
|
1876
|
-
}
|
|
1877
|
-
pendingOwnerNotifications.clear();
|
|
1878
|
-
}
|
|
1879
|
-
};
|
|
1880
|
-
|
|
1881
|
-
// src/internal/proxy/define-hidden-property.ts
|
|
1882
|
-
var defineHiddenProperty = (object, key, value2) => {
|
|
1883
|
-
Object.defineProperty(object, key, {
|
|
1884
|
-
enumerable: false,
|
|
1885
|
-
configurable: true,
|
|
1886
|
-
value: value2
|
|
1887
|
-
});
|
|
1888
|
-
};
|
|
1889
|
-
|
|
1890
|
-
// src/internal/proxy/errors.ts
|
|
1891
|
-
var MutationOutsideChangeContextError = class extends Error {
|
|
1892
|
-
constructor(operation, suggestion) {
|
|
1893
|
-
super(`Cannot ${operation} outside of Obj.change(). Use Obj.change(obj, (mutableObj) => { ${suggestion} }) instead.`);
|
|
1894
|
-
this.name = "MutationOutsideChangeContextError";
|
|
1895
|
-
}
|
|
1896
|
-
};
|
|
1897
|
-
var createPropertySetError = (prop) => {
|
|
1898
|
-
return new MutationOutsideChangeContextError(`modify object property "${String(prop)}"`, `mutableObj.${String(prop)} = value;`);
|
|
1899
|
-
};
|
|
1900
|
-
var createPropertyDeleteError = (prop) => {
|
|
1901
|
-
return new MutationOutsideChangeContextError(`delete object property "${String(prop)}"`, `delete mutableObj.${String(prop)};`);
|
|
1902
|
-
};
|
|
1903
|
-
var createArrayMethodError = (method) => {
|
|
1904
|
-
return new MutationOutsideChangeContextError(`call array.${method}()`, `mutableObj.array.${method}(...);`);
|
|
1905
|
-
};
|
|
1906
|
-
|
|
1907
|
-
// src/internal/proxy/json-serializer.ts
|
|
1908
|
-
import { invariant as invariant10 } from "@dxos/invariant";
|
|
1909
|
-
import { DXN as DXN6 } from "@dxos/keys";
|
|
1910
|
-
import { deepMapValues } from "@dxos/util";
|
|
1911
|
-
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/proxy/json-serializer.ts";
|
|
1912
|
-
var attachTypedJsonSerializer = (obj) => {
|
|
1913
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, "toJSON");
|
|
1914
|
-
if (descriptor) {
|
|
1915
|
-
return;
|
|
1916
|
-
}
|
|
1917
|
-
Object.defineProperty(obj, "toJSON", {
|
|
1918
|
-
value: typedJsonSerializer,
|
|
1919
|
-
writable: false,
|
|
1920
|
-
enumerable: false,
|
|
1921
|
-
// Setting `configurable` to false breaks proxy invariants, should be fixable.
|
|
1922
|
-
configurable: true
|
|
1923
|
-
});
|
|
1924
|
-
};
|
|
1925
|
-
var typedJsonSerializer = function() {
|
|
1926
|
-
const { id, ...rest } = this;
|
|
1927
|
-
const result = {
|
|
1928
|
-
id
|
|
1929
|
-
};
|
|
1930
|
-
if (this[TypeId]) {
|
|
1931
|
-
result[ATTR_TYPE] = this[TypeId].toString();
|
|
1932
|
-
}
|
|
1933
|
-
if (this[MetaId]) {
|
|
1934
|
-
result[ATTR_META] = serializeMeta(this[MetaId]);
|
|
1935
|
-
}
|
|
1936
|
-
if (this[SelfDXNId]) {
|
|
1937
|
-
result[ATTR_SELF_DXN] = this[SelfDXNId].toString();
|
|
950
|
+
var TypedReactiveHandler = class _TypedReactiveHandler {
|
|
951
|
+
static instance = new _TypedReactiveHandler();
|
|
952
|
+
_proxyMap = /* @__PURE__ */ new WeakMap();
|
|
953
|
+
_inSet = false;
|
|
954
|
+
constructor() {
|
|
1938
955
|
}
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
L: 61,
|
|
956
|
+
init(target) {
|
|
957
|
+
invariant7(typeof target === "object" && target !== null, void 0, {
|
|
958
|
+
F: __dxlog_file7,
|
|
959
|
+
L: 147,
|
|
1944
960
|
S: this,
|
|
1945
961
|
A: [
|
|
1946
|
-
"
|
|
962
|
+
"typeof target === 'object' && target !== null",
|
|
1947
963
|
""
|
|
1948
964
|
]
|
|
1949
965
|
});
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
const targetDXN = this[RelationTargetDXNId];
|
|
1954
|
-
invariant10(targetDXN instanceof DXN6, void 0, {
|
|
1955
|
-
F: __dxlog_file10,
|
|
1956
|
-
L: 66,
|
|
966
|
+
invariant7(SchemaId in target, "Schema is not defined for the target", {
|
|
967
|
+
F: __dxlog_file7,
|
|
968
|
+
L: 148,
|
|
1957
969
|
S: this,
|
|
1958
970
|
A: [
|
|
1959
|
-
"
|
|
1960
|
-
""
|
|
971
|
+
"SchemaId in target",
|
|
972
|
+
"'Schema is not defined for the target'"
|
|
1961
973
|
]
|
|
1962
974
|
});
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
return result;
|
|
1967
|
-
};
|
|
1968
|
-
var serializeData = (data) => {
|
|
1969
|
-
return deepMapValues(data, (value2, recurse) => {
|
|
1970
|
-
if (Ref.isRef(value2)) {
|
|
1971
|
-
return value2.noInline().encode();
|
|
975
|
+
const hasOwner = !!getOwner(target);
|
|
976
|
+
if (!(EventId in target) && !hasOwner) {
|
|
977
|
+
defineHiddenProperty(target, EventId, new Event());
|
|
1972
978
|
}
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
};
|
|
1997
|
-
var getProxySlot = (proxy) => {
|
|
1998
|
-
const value2 = proxy[symbolIsProxy];
|
|
1999
|
-
invariant11(value2 instanceof ProxyHandlerSlot, void 0, {
|
|
2000
|
-
F: __dxlog_file11,
|
|
2001
|
-
L: 32,
|
|
2002
|
-
S: void 0,
|
|
2003
|
-
A: [
|
|
2004
|
-
"value instanceof ProxyHandlerSlot",
|
|
2005
|
-
""
|
|
2006
|
-
]
|
|
2007
|
-
});
|
|
2008
|
-
return value2;
|
|
2009
|
-
};
|
|
2010
|
-
var getProxyTarget = (proxy) => {
|
|
2011
|
-
return getProxySlot(proxy).target;
|
|
2012
|
-
};
|
|
2013
|
-
var getProxyHandler = (proxy) => {
|
|
2014
|
-
return getProxySlot(proxy).handler;
|
|
2015
|
-
};
|
|
2016
|
-
var dangerouslySetProxyId = (obj, id) => {
|
|
2017
|
-
getProxySlot(obj).target.id = id;
|
|
2018
|
-
};
|
|
2019
|
-
var createProxy = (target, handler) => {
|
|
2020
|
-
const existingProxy = handler._proxyMap.get(target);
|
|
2021
|
-
if (existingProxy) {
|
|
2022
|
-
return existingProxy;
|
|
2023
|
-
}
|
|
2024
|
-
const proxy = new Proxy(target, new ProxyHandlerSlot(target, handler));
|
|
2025
|
-
handler.init(target);
|
|
2026
|
-
handler._proxyMap.set(target, proxy);
|
|
2027
|
-
return proxy;
|
|
2028
|
-
};
|
|
2029
|
-
var ProxyHandlerSlot = class {
|
|
2030
|
-
target;
|
|
2031
|
-
_handler;
|
|
2032
|
-
/**
|
|
2033
|
-
* @param target Original object.
|
|
2034
|
-
* @param _handler Handles intercepted operations.
|
|
2035
|
-
*/
|
|
2036
|
-
constructor(target, _handler) {
|
|
2037
|
-
this.target = target;
|
|
2038
|
-
this._handler = _handler;
|
|
2039
|
-
}
|
|
2040
|
-
get handler() {
|
|
2041
|
-
invariant11(this._handler, void 0, {
|
|
2042
|
-
F: __dxlog_file11,
|
|
2043
|
-
L: 91,
|
|
2044
|
-
S: this,
|
|
2045
|
-
A: [
|
|
2046
|
-
"this._handler",
|
|
2047
|
-
""
|
|
2048
|
-
]
|
|
979
|
+
defineHiddenProperty(target, ObjectDeletedId, false);
|
|
980
|
+
if (!hasOwner && !(ChangeId in target)) {
|
|
981
|
+
defineHiddenProperty(target, ChangeId, true);
|
|
982
|
+
}
|
|
983
|
+
if (!hasOwner) {
|
|
984
|
+
for (const key in target) {
|
|
985
|
+
if (target[symbolIsProxy]) {
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
let value2 = target[key];
|
|
989
|
+
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
990
|
+
if (hasForeignOwner(value2, target)) {
|
|
991
|
+
value2 = deepCopy(value2);
|
|
992
|
+
target[key] = value2;
|
|
993
|
+
}
|
|
994
|
+
setOwnerRecursive(value2, target);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
Object.defineProperty(target, inspectCustom, {
|
|
999
|
+
enumerable: false,
|
|
1000
|
+
configurable: true,
|
|
1001
|
+
value: this._inspect.bind(target)
|
|
2049
1002
|
});
|
|
2050
|
-
return this._handler;
|
|
2051
|
-
}
|
|
2052
|
-
// TODO(burdon): Requires comment.
|
|
2053
|
-
setHandler(handler) {
|
|
2054
|
-
this._handler = handler;
|
|
2055
1003
|
}
|
|
2056
|
-
/**
|
|
2057
|
-
* Get value.
|
|
2058
|
-
*/
|
|
2059
1004
|
get(target, prop, receiver) {
|
|
2060
|
-
|
|
2061
|
-
|
|
1005
|
+
switch (prop) {
|
|
1006
|
+
// TODO(burdon): Remove?
|
|
1007
|
+
case objectData: {
|
|
1008
|
+
return toJSON(target);
|
|
1009
|
+
}
|
|
1010
|
+
case ChangeId: {
|
|
1011
|
+
if (target[ChangeId] !== true) {
|
|
1012
|
+
return void 0;
|
|
1013
|
+
}
|
|
1014
|
+
return (callback) => executeChange(target, target, receiver, callback);
|
|
1015
|
+
}
|
|
2062
1016
|
}
|
|
2063
|
-
if (
|
|
1017
|
+
if (Object.getOwnPropertyDescriptor(target, prop)?.get) {
|
|
2064
1018
|
return Reflect.get(target, prop, receiver);
|
|
2065
1019
|
}
|
|
2066
|
-
|
|
1020
|
+
const value2 = Reflect.get(target, prop, receiver);
|
|
1021
|
+
if (isValidProxyTarget(value2)) {
|
|
1022
|
+
return createProxy(value2, this);
|
|
1023
|
+
}
|
|
1024
|
+
return value2;
|
|
2067
1025
|
}
|
|
2068
|
-
|
|
2069
|
-
const
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
"
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
for (const trap of TRAPS) {
|
|
2085
|
-
if (trap === "get") {
|
|
2086
|
-
continue;
|
|
2087
|
-
}
|
|
2088
|
-
Object.defineProperty(this.prototype, trap, {
|
|
2089
|
-
enumerable: false,
|
|
2090
|
-
value: function(...args) {
|
|
2091
|
-
if (!this._handler || !this._handler[trap]) {
|
|
2092
|
-
return Reflect[trap](...args);
|
|
2093
|
-
}
|
|
2094
|
-
return this._handler[trap].apply(this._handler, args);
|
|
1026
|
+
set(target, prop, value2, receiver) {
|
|
1027
|
+
const echoRoot = getEchoRoot(target);
|
|
1028
|
+
const isInitialized = ChangeId in echoRoot || EventId in echoRoot;
|
|
1029
|
+
const isSymbolProp = typeof prop === "symbol";
|
|
1030
|
+
if (isInitialized && !isSymbolProp && !isInChangeContext(echoRoot)) {
|
|
1031
|
+
throw new Error(`Cannot modify object property "${String(prop)}" outside of Obj.change(). Use Obj.change(obj, (mutableObj) => { mutableObj.property = value; }) instead.`);
|
|
1032
|
+
}
|
|
1033
|
+
let result = false;
|
|
1034
|
+
this._inSet = true;
|
|
1035
|
+
try {
|
|
1036
|
+
batchEvents(() => {
|
|
1037
|
+
const { echoRoot: _, preparedValue } = this._prepareValueForAssignment(target, prop, value2);
|
|
1038
|
+
result = Reflect.set(target, prop, preparedValue, receiver);
|
|
1039
|
+
if (isInitialized) {
|
|
1040
|
+
queueNotification(echoRoot);
|
|
1041
|
+
notifyOwnerChain(target);
|
|
2095
1042
|
}
|
|
2096
1043
|
});
|
|
1044
|
+
} finally {
|
|
1045
|
+
this._inSet = false;
|
|
2097
1046
|
}
|
|
1047
|
+
return result;
|
|
2098
1048
|
}
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
// src/internal/proxy/typed-handler.ts
|
|
2102
|
-
import * as Schema12 from "effect/Schema";
|
|
2103
|
-
import * as SchemaAST8 from "effect/SchemaAST";
|
|
2104
|
-
import { Event as Event2 } from "@dxos/async";
|
|
2105
|
-
import { inspectCustom as inspectCustom2 } from "@dxos/debug";
|
|
2106
|
-
import { invariant as invariant14 } from "@dxos/invariant";
|
|
2107
|
-
|
|
2108
|
-
// src/internal/proxy/ownership.ts
|
|
2109
|
-
import { invariant as invariant12 } from "@dxos/invariant";
|
|
2110
|
-
var __dxlog_file12 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/proxy/ownership.ts";
|
|
2111
|
-
var EchoOwner = Symbol.for("@dxos/echo/Owner");
|
|
2112
|
-
var getRawTarget = (value2) => {
|
|
2113
|
-
return isProxy(value2) ? getProxyTarget(value2) : value2;
|
|
2114
|
-
};
|
|
2115
|
-
var getOwner = (value2) => {
|
|
2116
|
-
return value2?.[EchoOwner];
|
|
2117
|
-
};
|
|
2118
|
-
var setMetaOwner = (metaTarget, parent) => {
|
|
2119
|
-
defineHiddenProperty(metaTarget, EchoOwner, parent);
|
|
2120
|
-
};
|
|
2121
|
-
var setOwnerRecursive = (value2, owner, options = {}) => {
|
|
2122
|
-
const { visited = /* @__PURE__ */ new Set(), depth = 0, allowedPreviousOwner } = options;
|
|
2123
|
-
if (value2 == null || typeof value2 !== "object") {
|
|
2124
|
-
return;
|
|
2125
|
-
}
|
|
2126
|
-
const actualValue = getRawTarget(value2);
|
|
2127
|
-
if (visited.has(actualValue)) {
|
|
2128
|
-
return;
|
|
1049
|
+
ownKeys(target) {
|
|
1050
|
+
return Reflect.ownKeys(target);
|
|
2129
1051
|
}
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
1052
|
+
deleteProperty(target, property) {
|
|
1053
|
+
const echoRoot = getEchoRoot(target);
|
|
1054
|
+
const isInitialized = echoRoot[ChangeId] === true || EventId in echoRoot;
|
|
1055
|
+
const isSymbolProp = typeof property === "symbol";
|
|
1056
|
+
if (isInitialized && !isSymbolProp && !isInChangeContext(echoRoot)) {
|
|
1057
|
+
throw createPropertyDeleteError(property);
|
|
1058
|
+
}
|
|
1059
|
+
const result = Reflect.deleteProperty(target, property);
|
|
1060
|
+
if (isInitialized) {
|
|
1061
|
+
queueNotification(echoRoot);
|
|
1062
|
+
}
|
|
1063
|
+
return result;
|
|
2136
1064
|
}
|
|
2137
|
-
|
|
2138
|
-
const
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
1065
|
+
defineProperty(target, property, attributes) {
|
|
1066
|
+
const echoRoot = getEchoRoot(target);
|
|
1067
|
+
const isInitialized = ChangeId in echoRoot || EventId in echoRoot;
|
|
1068
|
+
const isSymbolProp = typeof property === "symbol";
|
|
1069
|
+
if (isInitialized && !isSymbolProp && !isInChangeContext(echoRoot)) {
|
|
1070
|
+
throw new Error(`Cannot modify object property "${String(property)}" outside of Obj.change(). Use Obj.change(obj, (mutableObj) => { mutableObj.property = value; }) instead.`);
|
|
1071
|
+
}
|
|
1072
|
+
const { echoRoot: _, preparedValue } = this._prepareValueForAssignment(target, property, attributes.value);
|
|
1073
|
+
const result = Reflect.defineProperty(target, property, {
|
|
1074
|
+
...attributes,
|
|
1075
|
+
value: preparedValue
|
|
2147
1076
|
});
|
|
1077
|
+
if (!this._inSet && isInitialized) {
|
|
1078
|
+
queueNotification(echoRoot);
|
|
1079
|
+
}
|
|
1080
|
+
return result;
|
|
2148
1081
|
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
1082
|
+
/**
|
|
1083
|
+
* Prepare a value for assignment to a typed object property.
|
|
1084
|
+
* Handles cycle detection, copy-on-assign, array conversion, validation, and ownership.
|
|
1085
|
+
*/
|
|
1086
|
+
_prepareValueForAssignment(target, prop, value2) {
|
|
1087
|
+
const echoRoot = getEchoRoot(target);
|
|
1088
|
+
if (prop === ParentId) {
|
|
1089
|
+
return {
|
|
1090
|
+
echoRoot,
|
|
1091
|
+
preparedValue: value2
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
1095
|
+
if (wouldCreateCycle(echoRoot, value2)) {
|
|
1096
|
+
throw new Error("Cannot create cycles in typed object graph. Consider using Ref for circular references.");
|
|
2159
1097
|
}
|
|
2160
1098
|
}
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
setOwnerRecursive(nested, owner, recursiveOptions);
|
|
2167
|
-
}
|
|
1099
|
+
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
1100
|
+
const actualValue = getRawTarget(value2);
|
|
1101
|
+
const isRootEchoObject = EventId in actualValue;
|
|
1102
|
+
if (isRootEchoObject) {
|
|
1103
|
+
throw new Error("Object references must be wrapped with `Ref.make`");
|
|
2168
1104
|
}
|
|
2169
1105
|
}
|
|
1106
|
+
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
1107
|
+
const actualValue = getRawTarget(value2);
|
|
1108
|
+
const existingOwner = getOwner(actualValue);
|
|
1109
|
+
if (existingOwner != null && existingOwner !== echoRoot) {
|
|
1110
|
+
value2 = deepCopy(value2);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (Array.isArray(value2) && !(value2 instanceof ReactiveArray)) {
|
|
1114
|
+
value2 = ReactiveArray.from(value2);
|
|
1115
|
+
}
|
|
1116
|
+
const validatedValue = this._validateValue(target, prop, value2);
|
|
1117
|
+
if (isValidProxyTarget(validatedValue) || isProxy(validatedValue)) {
|
|
1118
|
+
setOwnerRecursive(validatedValue, echoRoot);
|
|
1119
|
+
}
|
|
1120
|
+
return {
|
|
1121
|
+
echoRoot,
|
|
1122
|
+
preparedValue: validatedValue
|
|
1123
|
+
};
|
|
2170
1124
|
}
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
1125
|
+
_validateValue(target, prop, value2) {
|
|
1126
|
+
if (prop === ParentId) {
|
|
1127
|
+
return value2;
|
|
1128
|
+
}
|
|
1129
|
+
const schema = SchemaValidator.getTargetPropertySchema(target, prop);
|
|
1130
|
+
const _ = Schema4.asserts(schema)(value2);
|
|
1131
|
+
if (isValidProxyTarget(value2)) {
|
|
1132
|
+
setSchemaProperties(value2, schema);
|
|
1133
|
+
}
|
|
1134
|
+
return value2;
|
|
2179
1135
|
}
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
1136
|
+
_inspect(_, options, inspectFn) {
|
|
1137
|
+
const inspected = inspectFn(this, {
|
|
1138
|
+
...options,
|
|
1139
|
+
showHidden: false,
|
|
1140
|
+
customInspect: false
|
|
1141
|
+
});
|
|
1142
|
+
return `Typed ${inspected}`;
|
|
2183
1143
|
}
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
1144
|
+
};
|
|
1145
|
+
var toJSON = (target) => {
|
|
1146
|
+
return {
|
|
1147
|
+
"@type": "TypedReactiveObject",
|
|
1148
|
+
...target
|
|
1149
|
+
};
|
|
1150
|
+
};
|
|
1151
|
+
var setSchemaProperties = (obj, schema) => {
|
|
1152
|
+
const schemaType = getSchemaDXN(schema);
|
|
1153
|
+
if (schemaType != null) {
|
|
1154
|
+
defineHiddenProperty(obj, TypeId, schemaType);
|
|
1155
|
+
}
|
|
1156
|
+
defineHiddenProperty(obj, SchemaId, schema);
|
|
1157
|
+
for (const key in obj) {
|
|
1158
|
+
if (isValidProxyTarget(obj[key])) {
|
|
1159
|
+
const elementSchema = SchemaValidator.getTargetPropertySchema(obj, key);
|
|
1160
|
+
if (elementSchema != null) {
|
|
1161
|
+
setSchemaProperties(obj[key], elementSchema);
|
|
2196
1162
|
}
|
|
2197
1163
|
}
|
|
2198
1164
|
}
|
|
2199
|
-
return false;
|
|
2200
1165
|
};
|
|
2201
|
-
var
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
if (owner != null && owner !== target) {
|
|
2205
|
-
return true;
|
|
2206
|
-
}
|
|
2207
|
-
if (EventId in v && v !== target) {
|
|
2208
|
-
return true;
|
|
2209
|
-
}
|
|
2210
|
-
return false;
|
|
2211
|
-
});
|
|
2212
|
-
var MAX_OWNER_DEPTH = 100;
|
|
2213
|
-
var getEchoRoot = (target, depth = 0) => {
|
|
2214
|
-
invariant12(depth < MAX_OWNER_DEPTH, "Owner chain too deep - possible circular ownership", {
|
|
2215
|
-
F: __dxlog_file12,
|
|
2216
|
-
L: 221,
|
|
2217
|
-
S: void 0,
|
|
2218
|
-
A: [
|
|
2219
|
-
"depth < MAX_OWNER_DEPTH",
|
|
2220
|
-
"'Owner chain too deep - possible circular ownership'"
|
|
2221
|
-
]
|
|
2222
|
-
});
|
|
2223
|
-
if (KindId in target) {
|
|
2224
|
-
return target;
|
|
2225
|
-
}
|
|
2226
|
-
const owner = getOwner(target);
|
|
2227
|
-
if (owner) {
|
|
2228
|
-
return getEchoRoot(owner, depth + 1);
|
|
1166
|
+
var prepareTypedTarget = (target, schema) => {
|
|
1167
|
+
if (!SchemaAST3.isTypeLiteral(schema.ast)) {
|
|
1168
|
+
throw new Error("schema has to describe an object type");
|
|
2229
1169
|
}
|
|
2230
|
-
|
|
1170
|
+
SchemaValidator.validateSchema(schema);
|
|
1171
|
+
const _ = Schema4.asserts(schema)(target);
|
|
1172
|
+
makeArraysReactive(target);
|
|
1173
|
+
setSchemaProperties(target, schema);
|
|
2231
1174
|
};
|
|
2232
|
-
var
|
|
2233
|
-
const
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
1175
|
+
var makeArraysReactive = (target) => {
|
|
1176
|
+
for (const key in target) {
|
|
1177
|
+
if (target[symbolIsProxy]) {
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
if (Array.isArray(target[key])) {
|
|
1181
|
+
target[key] = ReactiveArray.from(target[key]);
|
|
1182
|
+
}
|
|
1183
|
+
if (typeof target[key] === "object") {
|
|
1184
|
+
makeArraysReactive(target[key]);
|
|
1185
|
+
}
|
|
2237
1186
|
}
|
|
2238
1187
|
};
|
|
2239
1188
|
|
|
2240
|
-
// src/internal/proxy/
|
|
2241
|
-
var
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
var
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
const isInitialized = echoRoot[ChangeId] === true || EventId in echoRoot;
|
|
2248
|
-
if (!isInitialized) {
|
|
2249
|
-
return;
|
|
1189
|
+
// src/internal/common/proxy/make-object.ts
|
|
1190
|
+
var makeObject = (schema, obj, meta) => {
|
|
1191
|
+
return createReactiveObject(Object.assign({}, obj), meta, schema);
|
|
1192
|
+
};
|
|
1193
|
+
var createReactiveObject = (obj, meta, schema) => {
|
|
1194
|
+
if (!isValidProxyTarget(obj)) {
|
|
1195
|
+
throw new Error("Value cannot be made into a reactive object.");
|
|
2250
1196
|
}
|
|
2251
|
-
if (!
|
|
2252
|
-
throw
|
|
1197
|
+
if (!schema) {
|
|
1198
|
+
throw new Error("Schema is required for reactive objects. Use Atom for untyped reactive state.");
|
|
2253
1199
|
}
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
return Array;
|
|
1200
|
+
const parent = obj[ParentId];
|
|
1201
|
+
if (parent !== void 0) {
|
|
1202
|
+
delete obj[ParentId];
|
|
2258
1203
|
}
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
result = Array.prototype[method].apply(this, args);
|
|
2277
|
-
});
|
|
2278
|
-
return result;
|
|
2279
|
-
}
|
|
2280
|
-
});
|
|
1204
|
+
const annotation = getTypeAnnotation(schema);
|
|
1205
|
+
if (annotation) {
|
|
1206
|
+
setIdOnTarget(obj);
|
|
1207
|
+
defineHiddenProperty(obj, KindId, annotation.kind);
|
|
1208
|
+
}
|
|
1209
|
+
initMeta(obj, meta);
|
|
1210
|
+
if (parent !== void 0) {
|
|
1211
|
+
defineHiddenProperty(obj, ParentId, parent);
|
|
1212
|
+
}
|
|
1213
|
+
prepareTypedTarget(obj, schema);
|
|
1214
|
+
attachTypedJsonSerializer(obj);
|
|
1215
|
+
const proxy = createProxy(obj, TypedReactiveHandler.instance);
|
|
1216
|
+
const metaProxy = obj[MetaId];
|
|
1217
|
+
if (metaProxy) {
|
|
1218
|
+
const metaTarget = getProxyTarget(metaProxy);
|
|
1219
|
+
if (metaTarget) {
|
|
1220
|
+
setMetaOwner(metaTarget, obj);
|
|
2281
1221
|
}
|
|
2282
1222
|
}
|
|
1223
|
+
return proxy;
|
|
2283
1224
|
};
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
import { invariant as invariant13 } from "@dxos/invariant";
|
|
2289
|
-
import { log as log2 } from "@dxos/log";
|
|
2290
|
-
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/proxy/schema-validator.ts";
|
|
2291
|
-
var SchemaValidator = class {
|
|
2292
|
-
/**
|
|
2293
|
-
* Recursively check that schema specifies constructions we can handle.
|
|
2294
|
-
* Validates there are no ambiguous discriminated union types.
|
|
2295
|
-
*/
|
|
2296
|
-
static validateSchema(schema) {
|
|
2297
|
-
const visitAll = (nodes) => nodes.forEach((node) => this.validateSchema(Schema11.make(node)));
|
|
2298
|
-
if (SchemaAST7.isUnion(schema.ast)) {
|
|
2299
|
-
const typeAstList = schema.ast.types.filter((type) => SchemaAST7.isTypeLiteral(type));
|
|
2300
|
-
if (typeAstList.length > 1) {
|
|
2301
|
-
getTypeDiscriminators(typeAstList);
|
|
2302
|
-
}
|
|
2303
|
-
visitAll(typeAstList);
|
|
2304
|
-
} else if (SchemaAST7.isTupleType(schema.ast)) {
|
|
2305
|
-
const positionalTypes = schema.ast.elements.map((t) => t.type);
|
|
2306
|
-
const allTypes = positionalTypes.concat(schema.ast.rest.map((t) => t.type));
|
|
2307
|
-
visitAll(allTypes);
|
|
2308
|
-
} else if (SchemaAST7.isTypeLiteral(schema.ast)) {
|
|
2309
|
-
visitAll(SchemaAST7.getPropertySignatures(schema.ast).map((p) => p.type));
|
|
1225
|
+
var setIdOnTarget = (target) => {
|
|
1226
|
+
if ("id" in target && target.id !== void 0 && target.id !== null) {
|
|
1227
|
+
if (!ObjectId.isValid(target.id)) {
|
|
1228
|
+
throw new Error("Invalid object id format.");
|
|
2310
1229
|
}
|
|
1230
|
+
} else {
|
|
1231
|
+
target.id = ObjectId.random();
|
|
2311
1232
|
}
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
return false;
|
|
2326
|
-
}
|
|
1233
|
+
};
|
|
1234
|
+
var initMeta = (obj, meta = {
|
|
1235
|
+
keys: []
|
|
1236
|
+
}) => {
|
|
1237
|
+
prepareTypedTarget(meta, ObjectMetaSchema);
|
|
1238
|
+
defineHiddenProperty(obj, MetaId, createProxy(meta, TypedReactiveHandler.instance));
|
|
1239
|
+
};
|
|
1240
|
+
|
|
1241
|
+
// src/internal/common/proxy/reactive.ts
|
|
1242
|
+
var subscribe = (obj, callback) => {
|
|
1243
|
+
const target = getProxyTarget(obj);
|
|
1244
|
+
if (target && EventId in target) {
|
|
1245
|
+
return target[EventId].on(callback);
|
|
2327
1246
|
}
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
...propertyPath.slice(0, i),
|
|
2338
|
-
propertyName2
|
|
2339
|
-
]));
|
|
2340
|
-
if (propertyType == null) {
|
|
2341
|
-
log2.warn("unknown property", {
|
|
2342
|
-
path: propertyPath,
|
|
2343
|
-
property: propertyName
|
|
2344
|
-
}, {
|
|
2345
|
-
F: __dxlog_file13,
|
|
2346
|
-
L: 71,
|
|
2347
|
-
S: this,
|
|
2348
|
-
C: (f, a) => f(...a)
|
|
2349
|
-
});
|
|
2350
|
-
continue;
|
|
2351
|
-
}
|
|
2352
|
-
schema = Schema11.make(propertyType).annotations(propertyType.annotations);
|
|
2353
|
-
}
|
|
2354
|
-
}
|
|
2355
|
-
return schema;
|
|
1247
|
+
return () => {
|
|
1248
|
+
};
|
|
1249
|
+
};
|
|
1250
|
+
var change = (obj, callback) => {
|
|
1251
|
+
const changeFn = obj[ChangeId];
|
|
1252
|
+
if (changeFn) {
|
|
1253
|
+
changeFn(callback);
|
|
1254
|
+
} else {
|
|
1255
|
+
callback(obj);
|
|
2356
1256
|
}
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
// src/internal/Entity/api.ts
|
|
1260
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
1261
|
+
import { assumeType as assumeType3 } from "@dxos/util";
|
|
1262
|
+
|
|
1263
|
+
// src/internal/Entity/model.ts
|
|
1264
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
1265
|
+
import { DXN as DXN2, ObjectId as ObjectId2 } from "@dxos/keys";
|
|
1266
|
+
import { assumeType } from "@dxos/util";
|
|
1267
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/model.ts";
|
|
1268
|
+
function assertObjectModel(obj) {
|
|
1269
|
+
invariant8(typeof obj === "object" && obj !== null, "Invalid object model: not an object", {
|
|
1270
|
+
F: __dxlog_file8,
|
|
1271
|
+
L: 94,
|
|
1272
|
+
S: this,
|
|
1273
|
+
A: [
|
|
1274
|
+
"typeof obj === 'object' && obj !== null",
|
|
1275
|
+
"'Invalid object model: not an object'"
|
|
1276
|
+
]
|
|
1277
|
+
});
|
|
1278
|
+
assumeType(obj);
|
|
1279
|
+
invariant8(ObjectId2.isValid(obj.id), "Invalid object model: invalid id", {
|
|
1280
|
+
F: __dxlog_file8,
|
|
1281
|
+
L: 96,
|
|
1282
|
+
S: this,
|
|
1283
|
+
A: [
|
|
1284
|
+
"ObjectId.isValid(obj.id)",
|
|
1285
|
+
"'Invalid object model: invalid id'"
|
|
1286
|
+
]
|
|
1287
|
+
});
|
|
1288
|
+
invariant8(obj[TypeId] === void 0 || obj[TypeId] instanceof DXN2, "Invalid object model: invalid type", {
|
|
1289
|
+
F: __dxlog_file8,
|
|
1290
|
+
L: 97,
|
|
1291
|
+
S: this,
|
|
1292
|
+
A: [
|
|
1293
|
+
"obj[TypeId] === undefined || obj[TypeId] instanceof DXN",
|
|
1294
|
+
"'Invalid object model: invalid type'"
|
|
1295
|
+
]
|
|
1296
|
+
});
|
|
1297
|
+
invariant8(obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation, "Invalid object model: invalid entity kind", {
|
|
1298
|
+
F: __dxlog_file8,
|
|
1299
|
+
L: 98,
|
|
1300
|
+
S: this,
|
|
1301
|
+
A: [
|
|
1302
|
+
"obj[KindId] === EntityKind.Object || obj[KindId] === EntityKind.Relation",
|
|
1303
|
+
"'Invalid object model: invalid entity kind'"
|
|
1304
|
+
]
|
|
1305
|
+
});
|
|
1306
|
+
if (obj[KindId] === EntityKind.Relation) {
|
|
1307
|
+
invariant8(obj[RelationSourceDXNId] instanceof DXN2, "Invalid object model: invalid relation source", {
|
|
1308
|
+
F: __dxlog_file8,
|
|
1309
|
+
L: 104,
|
|
1310
|
+
S: this,
|
|
1311
|
+
A: [
|
|
1312
|
+
"obj[RelationSourceDXNId] instanceof DXN",
|
|
1313
|
+
"'Invalid object model: invalid relation source'"
|
|
1314
|
+
]
|
|
1315
|
+
});
|
|
1316
|
+
invariant8(obj[RelationTargetDXNId] instanceof DXN2, "Invalid object model: invalid relation target", {
|
|
1317
|
+
F: __dxlog_file8,
|
|
1318
|
+
L: 105,
|
|
1319
|
+
S: this,
|
|
1320
|
+
A: [
|
|
1321
|
+
"obj[RelationTargetDXNId] instanceof DXN",
|
|
1322
|
+
"'Invalid object model: invalid relation target'"
|
|
1323
|
+
]
|
|
1324
|
+
});
|
|
1325
|
+
invariant8(!(obj[RelationSourceId] instanceof DXN2), "Invalid object model: source pointer is a DXN", {
|
|
1326
|
+
F: __dxlog_file8,
|
|
1327
|
+
L: 106,
|
|
2362
1328
|
S: this,
|
|
2363
1329
|
A: [
|
|
2364
|
-
"
|
|
2365
|
-
"'
|
|
1330
|
+
"!(obj[RelationSourceId] instanceof DXN)",
|
|
1331
|
+
"'Invalid object model: source pointer is a DXN'"
|
|
2366
1332
|
]
|
|
2367
1333
|
});
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
}
|
|
2372
|
-
const propertyType = getPropertyType(schema.ast, prop.toString(), (prop2) => target[prop2]);
|
|
2373
|
-
if (propertyType == null) {
|
|
2374
|
-
return Schema11.Any;
|
|
2375
|
-
}
|
|
2376
|
-
invariant13(propertyType, `invalid property: ${prop.toString()}`, {
|
|
2377
|
-
F: __dxlog_file13,
|
|
2378
|
-
L: 95,
|
|
1334
|
+
invariant8(!(obj[RelationTargetId] instanceof DXN2), "Invalid object model: target pointer is a DXN", {
|
|
1335
|
+
F: __dxlog_file8,
|
|
1336
|
+
L: 107,
|
|
2379
1337
|
S: this,
|
|
2380
1338
|
A: [
|
|
2381
|
-
"
|
|
2382
|
-
"
|
|
1339
|
+
"!(obj[RelationTargetId] instanceof DXN)",
|
|
1340
|
+
"'Invalid object model: target pointer is a DXN'"
|
|
2383
1341
|
]
|
|
2384
1342
|
});
|
|
2385
|
-
return Schema11.make(propertyType);
|
|
2386
1343
|
}
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
// src/internal/Entity/util.ts
|
|
1347
|
+
import * as Schema5 from "effect/Schema";
|
|
1348
|
+
import { assertArgument as assertArgument2, invariant as invariant9 } from "@dxos/invariant";
|
|
1349
|
+
import { DXN as DXN3, ObjectId as ObjectId3 } from "@dxos/keys";
|
|
1350
|
+
import { assumeType as assumeType2 } from "@dxos/util";
|
|
1351
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/util.ts";
|
|
1352
|
+
var getObjectDXN = (object) => {
|
|
1353
|
+
invariant9(!Schema5.isSchema(object), "schema not allowed in this function", {
|
|
1354
|
+
F: __dxlog_file9,
|
|
1355
|
+
L: 19,
|
|
1356
|
+
S: void 0,
|
|
1357
|
+
A: [
|
|
1358
|
+
"!Schema.isSchema(object)",
|
|
1359
|
+
"'schema not allowed in this function'"
|
|
1360
|
+
]
|
|
1361
|
+
});
|
|
1362
|
+
assertArgument2(typeof object === "object" && object != null, "object", "expected object");
|
|
1363
|
+
assumeType2(object);
|
|
1364
|
+
if (object[SelfDXNId]) {
|
|
1365
|
+
invariant9(object[SelfDXNId] instanceof DXN3, "Invalid object model: invalid self dxn", {
|
|
1366
|
+
F: __dxlog_file9,
|
|
1367
|
+
L: 24,
|
|
2394
1368
|
S: void 0,
|
|
2395
1369
|
A: [
|
|
2396
|
-
"
|
|
2397
|
-
"
|
|
1370
|
+
"object[SelfDXNId] instanceof DXN",
|
|
1371
|
+
"'Invalid object model: invalid self dxn'"
|
|
2398
1372
|
]
|
|
2399
1373
|
});
|
|
2400
|
-
return
|
|
1374
|
+
return object[SelfDXNId];
|
|
2401
1375
|
}
|
|
2402
|
-
if (
|
|
2403
|
-
|
|
2404
|
-
return Schema11.make(elementType).annotations(elementType.annotations);
|
|
1376
|
+
if (!ObjectId3.isValid(object.id)) {
|
|
1377
|
+
throw new TypeError("Object id is not valid.");
|
|
2405
1378
|
}
|
|
2406
|
-
|
|
2407
|
-
return Schema11.make(restType[0].type).annotations(restType[0].annotations);
|
|
1379
|
+
return DXN3.fromLocalObjectId(object.id);
|
|
2408
1380
|
};
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
var
|
|
2413
|
-
const
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
}
|
|
2418
|
-
if (typeAstList.length === 1) {
|
|
2419
|
-
return SchemaAST7.getPropertySignatures(typeAstList[0]);
|
|
2420
|
-
}
|
|
2421
|
-
const typeDiscriminators = getTypeDiscriminators(typeAstList);
|
|
2422
|
-
const targetPropertyValue = getTargetPropertyFn(String(typeDiscriminators[0].name));
|
|
2423
|
-
const typeIndex = typeDiscriminators.findIndex((p) => targetPropertyValue === p.type.literal);
|
|
2424
|
-
invariant13(typeIndex !== -1, "discriminator field not set on target", {
|
|
2425
|
-
F: __dxlog_file13,
|
|
2426
|
-
L: 142,
|
|
1381
|
+
|
|
1382
|
+
// src/internal/Entity/api.ts
|
|
1383
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/api.ts";
|
|
1384
|
+
var getDXN = (entity) => {
|
|
1385
|
+
const dxn = getObjectDXN(entity);
|
|
1386
|
+
invariant10(dxn != null, "Invalid entity.", {
|
|
1387
|
+
F: __dxlog_file10,
|
|
1388
|
+
L: 20,
|
|
2427
1389
|
S: void 0,
|
|
2428
1390
|
A: [
|
|
2429
|
-
"
|
|
2430
|
-
"'
|
|
1391
|
+
"dxn != null",
|
|
1392
|
+
"'Invalid entity.'"
|
|
2431
1393
|
]
|
|
2432
1394
|
});
|
|
2433
|
-
return
|
|
1395
|
+
return dxn;
|
|
2434
1396
|
};
|
|
2435
|
-
var
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
1397
|
+
var getDatabase = (entity) => {
|
|
1398
|
+
assumeType3(entity);
|
|
1399
|
+
return entity[ObjectDatabaseId];
|
|
1400
|
+
};
|
|
1401
|
+
|
|
1402
|
+
// src/internal/Entity/entity.ts
|
|
1403
|
+
import * as Schema6 from "effect/Schema";
|
|
1404
|
+
var makeEchoTypeSchema = (fields, ast, typename, version2, kind) => {
|
|
1405
|
+
return class EchoObjectSchemaClass extends Schema6.make(ast) {
|
|
1406
|
+
static typename = typename;
|
|
1407
|
+
static version = version2;
|
|
1408
|
+
static [SchemaKindId] = kind;
|
|
1409
|
+
static fields = fields;
|
|
1410
|
+
static annotations(annotations3) {
|
|
1411
|
+
const schema = Schema6.make(ast).annotations(annotations3);
|
|
1412
|
+
return makeEchoTypeSchema(fields, schema.ast, typename, version2, kind);
|
|
1413
|
+
}
|
|
1414
|
+
// static make(
|
|
1415
|
+
// props: RequiredKeys<Schema.TypeLiteral.Constructor<Fields, []>> extends never
|
|
1416
|
+
// ? void | Simplify<Schema.TypeLiteral.Constructor<Fields, []>>
|
|
1417
|
+
// : Simplify<Schema.TypeLiteral.Constructor<Fields, []>>,
|
|
1418
|
+
// options?: MakeProps,
|
|
1419
|
+
// ): Simplify<Schema.TypeLiteral.Type<Fields, []>> {
|
|
1420
|
+
// const propsWithDefaults: any = _lazilyMergeDefaults(fields, { ...(props as any) });
|
|
1421
|
+
// return _getDisableValidationMakeOption(options)
|
|
1422
|
+
// ? propsWithDefaults
|
|
1423
|
+
// : ParseResult.validateSync(this)(propsWithDefaults);
|
|
1424
|
+
// }
|
|
1425
|
+
static instanceOf(value2) {
|
|
1426
|
+
return Schema6.is(this)(value2);
|
|
1427
|
+
}
|
|
1428
|
+
};
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
// src/internal/Entity/object.ts
|
|
1432
|
+
import * as Schema7 from "effect/Schema";
|
|
1433
|
+
import * as SchemaAST4 from "effect/SchemaAST";
|
|
1434
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
1435
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/object.ts";
|
|
1436
|
+
var EchoObjectSchema = ({ typename, version: version2 }) => {
|
|
1437
|
+
return (self) => {
|
|
1438
|
+
invariant11(typeof TypeAnnotationId === "symbol", "Sanity.", {
|
|
1439
|
+
F: __dxlog_file11,
|
|
1440
|
+
L: 37,
|
|
1441
|
+
S: void 0,
|
|
1442
|
+
A: [
|
|
1443
|
+
"typeof TypeAnnotationId === 'symbol'",
|
|
1444
|
+
"'Sanity.'"
|
|
1445
|
+
]
|
|
1446
|
+
});
|
|
1447
|
+
invariant11(SchemaAST4.isTypeLiteral(self.ast), "Schema must be a TypeLiteral.", {
|
|
1448
|
+
F: __dxlog_file11,
|
|
1449
|
+
L: 38,
|
|
1450
|
+
S: void 0,
|
|
1451
|
+
A: [
|
|
1452
|
+
"SchemaAST.isTypeLiteral(self.ast)",
|
|
1453
|
+
"'Schema must be a TypeLiteral.'"
|
|
1454
|
+
]
|
|
1455
|
+
});
|
|
1456
|
+
const fields = self.fields ?? {};
|
|
1457
|
+
const schemaWithId = Schema7.extend(self, Schema7.Struct({
|
|
1458
|
+
id: Schema7.String
|
|
1459
|
+
}));
|
|
1460
|
+
const ast = SchemaAST4.annotations(schemaWithId.ast, {
|
|
1461
|
+
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
1462
|
+
...self.ast.annotations,
|
|
1463
|
+
[TypeAnnotationId]: {
|
|
1464
|
+
kind: EntityKind.Object,
|
|
1465
|
+
typename,
|
|
1466
|
+
version: version2
|
|
1467
|
+
},
|
|
1468
|
+
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
1469
|
+
[SchemaAST4.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
1470
|
+
kind: EntityKind.Object,
|
|
1471
|
+
typename,
|
|
1472
|
+
version: version2
|
|
1473
|
+
})
|
|
1474
|
+
});
|
|
1475
|
+
return makeEchoTypeSchema(fields, ast, typename, version2, EntityKind.Object);
|
|
1476
|
+
};
|
|
1477
|
+
};
|
|
1478
|
+
|
|
1479
|
+
// src/internal/Entity/relation.ts
|
|
1480
|
+
import * as Schema8 from "effect/Schema";
|
|
1481
|
+
import * as SchemaAST5 from "effect/SchemaAST";
|
|
1482
|
+
import { raise } from "@dxos/debug";
|
|
1483
|
+
import { assertArgument as assertArgument3, invariant as invariant12 } from "@dxos/invariant";
|
|
1484
|
+
import { DXN as DXN4 } from "@dxos/keys";
|
|
1485
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/relation.ts";
|
|
1486
|
+
var EchoRelationSchema = ({ source, target, typename, version: version2 }) => {
|
|
1487
|
+
assertArgument3(Schema8.isSchema(source), "source");
|
|
1488
|
+
assertArgument3(Schema8.isSchema(target), "target");
|
|
1489
|
+
const sourceDXN = getDXNForRelationSchemaRef(source);
|
|
1490
|
+
const targetDXN = getDXNForRelationSchemaRef(target);
|
|
1491
|
+
if (getEntityKind(source) !== EntityKind.Object) {
|
|
1492
|
+
raise(new Error("Source schema must be an echo object schema."));
|
|
2439
1493
|
}
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
});
|
|
2443
|
-
if (typeOrDiscriminatedUnion == null) {
|
|
2444
|
-
return null;
|
|
1494
|
+
if (getEntityKind(target) !== EntityKind.Object) {
|
|
1495
|
+
raise(new Error("Target schema must be an echo object schema."));
|
|
2445
1496
|
}
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
1497
|
+
return (self) => {
|
|
1498
|
+
invariant12(SchemaAST5.isTypeLiteral(self.ast), "Schema must be a TypeLiteral.", {
|
|
1499
|
+
F: __dxlog_file12,
|
|
1500
|
+
L: 110,
|
|
1501
|
+
S: void 0,
|
|
1502
|
+
A: [
|
|
1503
|
+
"SchemaAST.isTypeLiteral(self.ast)",
|
|
1504
|
+
"'Schema must be a TypeLiteral.'"
|
|
1505
|
+
]
|
|
1506
|
+
});
|
|
1507
|
+
const fields = self.fields ?? {};
|
|
1508
|
+
const schemaWithId = Schema8.extend(self, Schema8.Struct({
|
|
1509
|
+
id: Schema8.String
|
|
1510
|
+
}));
|
|
1511
|
+
const ast = SchemaAST5.annotations(schemaWithId.ast, {
|
|
1512
|
+
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
1513
|
+
...self.ast.annotations,
|
|
1514
|
+
[TypeAnnotationId]: {
|
|
1515
|
+
kind: EntityKind.Relation,
|
|
1516
|
+
typename,
|
|
1517
|
+
version: version2,
|
|
1518
|
+
sourceSchema: sourceDXN,
|
|
1519
|
+
targetSchema: targetDXN
|
|
1520
|
+
},
|
|
1521
|
+
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
1522
|
+
[SchemaAST5.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
1523
|
+
kind: EntityKind.Relation,
|
|
1524
|
+
typename,
|
|
1525
|
+
version: version2,
|
|
1526
|
+
relationSource: sourceDXN,
|
|
1527
|
+
relationTarget: targetDXN
|
|
1528
|
+
})
|
|
1529
|
+
});
|
|
1530
|
+
return makeEchoTypeSchema(fields, ast, typename, version2, EntityKind.Relation);
|
|
1531
|
+
};
|
|
1532
|
+
};
|
|
1533
|
+
var getDXNForRelationSchemaRef = (schema) => {
|
|
1534
|
+
assertArgument3(Schema8.isSchema(schema), "schema");
|
|
1535
|
+
const identifier = getTypeIdentifierAnnotation(schema);
|
|
1536
|
+
if (identifier) {
|
|
1537
|
+
return identifier;
|
|
2449
1538
|
}
|
|
2450
|
-
const
|
|
2451
|
-
if (
|
|
2452
|
-
|
|
1539
|
+
const typename = getSchemaTypename(schema);
|
|
1540
|
+
if (!typename) {
|
|
1541
|
+
throw new Error("Schema must have a typename");
|
|
2453
1542
|
}
|
|
2454
|
-
return
|
|
1543
|
+
return DXN4.fromTypename(typename).toString();
|
|
2455
1544
|
};
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
invariant13(isDiscriminatedUnion, "type ambiguity: every type in a union must have a single unique-literal field", {
|
|
2463
|
-
F: __dxlog_file13,
|
|
2464
|
-
L: 193,
|
|
2465
|
-
S: void 0,
|
|
2466
|
-
A: [
|
|
2467
|
-
"isDiscriminatedUnion",
|
|
2468
|
-
"'type ambiguity: every type in a union must have a single unique-literal field'"
|
|
2469
|
-
]
|
|
2470
|
-
});
|
|
2471
|
-
return discriminatorPropCandidates;
|
|
1545
|
+
|
|
1546
|
+
// src/internal/Entity/version.ts
|
|
1547
|
+
import { assertArgument as assertArgument4 } from "@dxos/invariant";
|
|
1548
|
+
var unversioned = {
|
|
1549
|
+
[VersionTypeId]: {},
|
|
1550
|
+
versioned: false
|
|
2472
1551
|
};
|
|
2473
|
-
var
|
|
2474
|
-
|
|
2475
|
-
while (ast != null) {
|
|
2476
|
-
if (predicate?.(ast)) {
|
|
2477
|
-
return ast;
|
|
2478
|
-
}
|
|
2479
|
-
if (SchemaAST7.isUnion(ast)) {
|
|
2480
|
-
const next = ast.types.find((t) => predicate != null && predicate(t) || SchemaAST7.isSuspend(t));
|
|
2481
|
-
if (next != null) {
|
|
2482
|
-
ast = next;
|
|
2483
|
-
continue;
|
|
2484
|
-
}
|
|
2485
|
-
}
|
|
2486
|
-
if (SchemaAST7.isSuspend(ast)) {
|
|
2487
|
-
ast = ast.f();
|
|
2488
|
-
} else {
|
|
2489
|
-
return predicate == null ? ast : null;
|
|
2490
|
-
}
|
|
2491
|
-
}
|
|
2492
|
-
return null;
|
|
1552
|
+
var isVersion = (entity) => {
|
|
1553
|
+
return entity != null && typeof entity === "object" && VersionTypeId in entity;
|
|
2493
1554
|
};
|
|
2494
|
-
var
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
L: 236,
|
|
2499
|
-
S: void 0,
|
|
2500
|
-
A: [
|
|
2501
|
-
"SchemaAST.isTypeLiteral(schema.ast)",
|
|
2502
|
-
""
|
|
2503
|
-
]
|
|
2504
|
-
});
|
|
2505
|
-
const idProperty = SchemaAST7.getPropertySignatures(schema.ast).find((prop) => prop.name === "id");
|
|
2506
|
-
if (idProperty != null) {
|
|
2507
|
-
throw new Error('"id" property name is reserved');
|
|
1555
|
+
var version = (entity) => {
|
|
1556
|
+
const ver = entity[ObjectVersionId];
|
|
1557
|
+
if (ver === void 0) {
|
|
1558
|
+
return unversioned;
|
|
2508
1559
|
}
|
|
1560
|
+
return ver;
|
|
2509
1561
|
};
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
return visited.get(actualValue);
|
|
2520
|
-
}
|
|
2521
|
-
if (actualValue instanceof ReactiveArray) {
|
|
2522
|
-
const copy2 = new ReactiveArray();
|
|
2523
|
-
visited.set(actualValue, copy2);
|
|
2524
|
-
for (const item of actualValue) {
|
|
2525
|
-
copy2.push(deepCopy(item, visited));
|
|
2526
|
-
}
|
|
2527
|
-
copyHiddenProperties(actualValue, copy2);
|
|
2528
|
-
return copy2;
|
|
2529
|
-
}
|
|
2530
|
-
const proto = Object.getPrototypeOf(actualValue);
|
|
2531
|
-
if (proto !== Object.prototype && proto !== Array.prototype && proto !== null) {
|
|
2532
|
-
return value2;
|
|
1562
|
+
var versionValid = (ver) => {
|
|
1563
|
+
assertArgument4(isVersion(ver), "version", "Invalid version object");
|
|
1564
|
+
return !!ver.versioned;
|
|
1565
|
+
};
|
|
1566
|
+
var compareVersions = (version1, version2) => {
|
|
1567
|
+
assertArgument4(isVersion(version1), "version1", "Invalid version object");
|
|
1568
|
+
assertArgument4(isVersion(version2), "version2", "Invalid version object");
|
|
1569
|
+
if (!versionValid(version1) || !versionValid(version2)) {
|
|
1570
|
+
return "unversioned";
|
|
2533
1571
|
}
|
|
2534
|
-
if (
|
|
2535
|
-
|
|
2536
|
-
visited.set(actualValue, copy2);
|
|
2537
|
-
for (const item of actualValue) {
|
|
2538
|
-
copy2.push(deepCopy(item, visited));
|
|
2539
|
-
}
|
|
2540
|
-
return copy2;
|
|
1572
|
+
if (version1.automergeHeads?.length !== version2.automergeHeads?.length) {
|
|
1573
|
+
return "different";
|
|
2541
1574
|
}
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
for (const key of Object.keys(actualValue)) {
|
|
2545
|
-
copy[key] = deepCopy(actualValue[key], visited);
|
|
1575
|
+
if (version1.automergeHeads?.some((head) => !version2.automergeHeads?.includes(head))) {
|
|
1576
|
+
return "different";
|
|
2546
1577
|
}
|
|
2547
|
-
|
|
1578
|
+
return "equal";
|
|
1579
|
+
};
|
|
1580
|
+
var encodeVersion = (ver) => {
|
|
1581
|
+
return JSON.stringify(ver);
|
|
1582
|
+
};
|
|
1583
|
+
var decodeVersion = (ver) => {
|
|
1584
|
+
const parsed = JSON.parse(ver);
|
|
1585
|
+
parsed[VersionTypeId] = {};
|
|
1586
|
+
return parsed;
|
|
1587
|
+
};
|
|
1588
|
+
|
|
1589
|
+
// src/internal/JsonSchema/json-schema-normalize.ts
|
|
1590
|
+
var normalizeSchema = (schema) => {
|
|
1591
|
+
const copy = structuredClone(schema);
|
|
1592
|
+
go(copy);
|
|
2548
1593
|
return copy;
|
|
2549
1594
|
};
|
|
2550
|
-
var
|
|
2551
|
-
if (
|
|
2552
|
-
|
|
1595
|
+
var go = (schema) => {
|
|
1596
|
+
if (typeof schema !== "object" || schema === null) {
|
|
1597
|
+
return;
|
|
2553
1598
|
}
|
|
2554
|
-
if (
|
|
2555
|
-
|
|
1599
|
+
if (schema.exclusiveMaximum === true) {
|
|
1600
|
+
schema.exclusiveMaximum = schema.maximum;
|
|
1601
|
+
delete schema.exclusiveMaximum;
|
|
1602
|
+
} else if (schema.exclusiveMaximum === false) {
|
|
1603
|
+
delete schema.exclusiveMaximum;
|
|
2556
1604
|
}
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
constructor() {
|
|
1605
|
+
if (schema.exclusiveMinimum === true) {
|
|
1606
|
+
schema.exclusiveMinimum = schema.minimum;
|
|
1607
|
+
delete schema.exclusiveMinimum;
|
|
1608
|
+
} else if (schema.exclusiveMinimum === false) {
|
|
1609
|
+
delete schema.exclusiveMinimum;
|
|
2563
1610
|
}
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
L: 147,
|
|
2568
|
-
S: this,
|
|
2569
|
-
A: [
|
|
2570
|
-
"typeof target === 'object' && target !== null",
|
|
2571
|
-
""
|
|
2572
|
-
]
|
|
2573
|
-
});
|
|
2574
|
-
invariant14(SchemaId in target, "Schema is not defined for the target", {
|
|
2575
|
-
F: __dxlog_file14,
|
|
2576
|
-
L: 148,
|
|
2577
|
-
S: this,
|
|
2578
|
-
A: [
|
|
2579
|
-
"SchemaId in target",
|
|
2580
|
-
"'Schema is not defined for the target'"
|
|
2581
|
-
]
|
|
2582
|
-
});
|
|
2583
|
-
const hasOwner = !!getOwner(target);
|
|
2584
|
-
if (!(EventId in target) && !hasOwner) {
|
|
2585
|
-
defineHiddenProperty(target, EventId, new Event2());
|
|
2586
|
-
}
|
|
2587
|
-
defineHiddenProperty(target, ObjectDeletedId, false);
|
|
2588
|
-
if (!hasOwner && !(ChangeId in target)) {
|
|
2589
|
-
defineHiddenProperty(target, ChangeId, true);
|
|
2590
|
-
}
|
|
2591
|
-
if (!hasOwner) {
|
|
2592
|
-
for (const key in target) {
|
|
2593
|
-
if (target[symbolIsProxy]) {
|
|
2594
|
-
continue;
|
|
2595
|
-
}
|
|
2596
|
-
let value2 = target[key];
|
|
2597
|
-
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
2598
|
-
if (hasForeignOwner(value2, target)) {
|
|
2599
|
-
value2 = deepCopy(value2);
|
|
2600
|
-
target[key] = value2;
|
|
2601
|
-
}
|
|
2602
|
-
setOwnerRecursive(value2, target);
|
|
2603
|
-
}
|
|
2604
|
-
}
|
|
1611
|
+
for (const key of Object.keys(schema)) {
|
|
1612
|
+
if (!JsonSchemaFields.includes(key)) {
|
|
1613
|
+
delete schema[key];
|
|
2605
1614
|
}
|
|
2606
|
-
Object.defineProperty(target, inspectCustom2, {
|
|
2607
|
-
enumerable: false,
|
|
2608
|
-
configurable: true,
|
|
2609
|
-
value: this._inspect.bind(target)
|
|
2610
|
-
});
|
|
2611
1615
|
}
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
// TODO(burdon): Remove?
|
|
2615
|
-
case objectData: {
|
|
2616
|
-
return toJSON(target);
|
|
2617
|
-
}
|
|
2618
|
-
case ChangeId: {
|
|
2619
|
-
if (target[ChangeId] !== true) {
|
|
2620
|
-
return void 0;
|
|
2621
|
-
}
|
|
2622
|
-
return (callback) => executeChange(target, target, receiver, callback);
|
|
2623
|
-
}
|
|
2624
|
-
}
|
|
2625
|
-
if (Object.getOwnPropertyDescriptor(target, prop)?.get) {
|
|
2626
|
-
return Reflect.get(target, prop, receiver);
|
|
2627
|
-
}
|
|
2628
|
-
const value2 = Reflect.get(target, prop, receiver);
|
|
2629
|
-
if (isValidProxyTarget(value2)) {
|
|
2630
|
-
return createProxy(value2, this);
|
|
2631
|
-
}
|
|
2632
|
-
return value2;
|
|
1616
|
+
if (schema.properties) {
|
|
1617
|
+
goOnRecord(schema.properties);
|
|
2633
1618
|
}
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
const isInitialized = ChangeId in echoRoot || EventId in echoRoot;
|
|
2637
|
-
const isSymbolProp = typeof prop === "symbol";
|
|
2638
|
-
if (isInitialized && !isSymbolProp && !isInChangeContext(echoRoot)) {
|
|
2639
|
-
throw new Error(`Cannot modify object property "${String(prop)}" outside of Obj.change(). Use Obj.change(obj, (mutableObj) => { mutableObj.property = value; }) instead.`);
|
|
2640
|
-
}
|
|
2641
|
-
let result = false;
|
|
2642
|
-
this._inSet = true;
|
|
2643
|
-
try {
|
|
2644
|
-
batchEvents(() => {
|
|
2645
|
-
const { echoRoot: _, preparedValue } = this._prepareValueForAssignment(target, prop, value2);
|
|
2646
|
-
result = Reflect.set(target, prop, preparedValue, receiver);
|
|
2647
|
-
if (isInitialized) {
|
|
2648
|
-
queueNotification(echoRoot);
|
|
2649
|
-
notifyOwnerChain(target);
|
|
2650
|
-
}
|
|
2651
|
-
});
|
|
2652
|
-
} finally {
|
|
2653
|
-
this._inSet = false;
|
|
2654
|
-
}
|
|
2655
|
-
return result;
|
|
1619
|
+
if (schema.patternProperties) {
|
|
1620
|
+
goOnRecord(schema.patternProperties);
|
|
2656
1621
|
}
|
|
2657
|
-
|
|
2658
|
-
|
|
1622
|
+
if (schema.propertyNames) {
|
|
1623
|
+
go(schema.propertyNames);
|
|
2659
1624
|
}
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
const isInitialized = echoRoot[ChangeId] === true || EventId in echoRoot;
|
|
2663
|
-
const isSymbolProp = typeof property === "symbol";
|
|
2664
|
-
if (isInitialized && !isSymbolProp && !isInChangeContext(echoRoot)) {
|
|
2665
|
-
throw createPropertyDeleteError(property);
|
|
2666
|
-
}
|
|
2667
|
-
const result = Reflect.deleteProperty(target, property);
|
|
2668
|
-
if (isInitialized) {
|
|
2669
|
-
queueNotification(echoRoot);
|
|
2670
|
-
}
|
|
2671
|
-
return result;
|
|
1625
|
+
if (schema.definitions) {
|
|
1626
|
+
goOnRecord(schema.definitions);
|
|
2672
1627
|
}
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
const isInitialized = ChangeId in echoRoot || EventId in echoRoot;
|
|
2676
|
-
const isSymbolProp = typeof property === "symbol";
|
|
2677
|
-
if (isInitialized && !isSymbolProp && !isInChangeContext(echoRoot)) {
|
|
2678
|
-
throw new Error(`Cannot modify object property "${String(property)}" outside of Obj.change(). Use Obj.change(obj, (mutableObj) => { mutableObj.property = value; }) instead.`);
|
|
2679
|
-
}
|
|
2680
|
-
const { echoRoot: _, preparedValue } = this._prepareValueForAssignment(target, property, attributes.value);
|
|
2681
|
-
const result = Reflect.defineProperty(target, property, {
|
|
2682
|
-
...attributes,
|
|
2683
|
-
value: preparedValue
|
|
2684
|
-
});
|
|
2685
|
-
if (!this._inSet && isInitialized) {
|
|
2686
|
-
queueNotification(echoRoot);
|
|
2687
|
-
}
|
|
2688
|
-
return result;
|
|
1628
|
+
if (schema.items) {
|
|
1629
|
+
maybeGoOnArray(schema.items);
|
|
2689
1630
|
}
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
* Handles cycle detection, copy-on-assign, array conversion, validation, and ownership.
|
|
2693
|
-
*/
|
|
2694
|
-
_prepareValueForAssignment(target, prop, value2) {
|
|
2695
|
-
const echoRoot = getEchoRoot(target);
|
|
2696
|
-
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
2697
|
-
if (wouldCreateCycle(echoRoot, value2)) {
|
|
2698
|
-
throw new Error("Cannot create cycles in typed object graph. Consider using Ref for circular references.");
|
|
2699
|
-
}
|
|
2700
|
-
}
|
|
2701
|
-
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
2702
|
-
const actualValue = getRawTarget(value2);
|
|
2703
|
-
const isRootEchoObject = EventId in actualValue;
|
|
2704
|
-
if (isRootEchoObject) {
|
|
2705
|
-
throw new Error("Object references must be wrapped with `Ref.make`");
|
|
2706
|
-
}
|
|
2707
|
-
}
|
|
2708
|
-
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
2709
|
-
const actualValue = getRawTarget(value2);
|
|
2710
|
-
const existingOwner = getOwner(actualValue);
|
|
2711
|
-
if (existingOwner != null && existingOwner !== echoRoot) {
|
|
2712
|
-
value2 = deepCopy(value2);
|
|
2713
|
-
}
|
|
2714
|
-
}
|
|
2715
|
-
if (Array.isArray(value2) && !(value2 instanceof ReactiveArray)) {
|
|
2716
|
-
value2 = ReactiveArray.from(value2);
|
|
2717
|
-
}
|
|
2718
|
-
const validatedValue = this._validateValue(target, prop, value2);
|
|
2719
|
-
if (isValidProxyTarget(validatedValue) || isProxy(validatedValue)) {
|
|
2720
|
-
setOwnerRecursive(validatedValue, echoRoot);
|
|
2721
|
-
}
|
|
2722
|
-
return {
|
|
2723
|
-
echoRoot,
|
|
2724
|
-
preparedValue: validatedValue
|
|
2725
|
-
};
|
|
1631
|
+
if (schema.additionalItems) {
|
|
1632
|
+
maybeGoOnArray(schema.additionalItems);
|
|
2726
1633
|
}
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
const _ = Schema12.asserts(schema)(value2);
|
|
2730
|
-
if (isValidProxyTarget(value2)) {
|
|
2731
|
-
setSchemaProperties(value2, schema);
|
|
2732
|
-
}
|
|
2733
|
-
return value2;
|
|
1634
|
+
if (schema.contains) {
|
|
1635
|
+
go(schema.contains);
|
|
2734
1636
|
}
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
...options,
|
|
2738
|
-
showHidden: false,
|
|
2739
|
-
customInspect: false
|
|
2740
|
-
});
|
|
2741
|
-
return `Typed ${inspected}`;
|
|
1637
|
+
if (schema.if) {
|
|
1638
|
+
go(schema.if);
|
|
2742
1639
|
}
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
return {
|
|
2746
|
-
"@type": "TypedReactiveObject",
|
|
2747
|
-
...target
|
|
2748
|
-
};
|
|
2749
|
-
};
|
|
2750
|
-
var setSchemaProperties = (obj, schema) => {
|
|
2751
|
-
const schemaType = getSchemaDXN(schema);
|
|
2752
|
-
if (schemaType != null) {
|
|
2753
|
-
defineHiddenProperty(obj, TypeId, schemaType);
|
|
1640
|
+
if (schema.then) {
|
|
1641
|
+
go(schema.then);
|
|
2754
1642
|
}
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
if (isValidProxyTarget(obj[key])) {
|
|
2758
|
-
const elementSchema = SchemaValidator.getTargetPropertySchema(obj, key);
|
|
2759
|
-
if (elementSchema != null) {
|
|
2760
|
-
setSchemaProperties(obj[key], elementSchema);
|
|
2761
|
-
}
|
|
2762
|
-
}
|
|
1643
|
+
if (schema.else) {
|
|
1644
|
+
go(schema.else);
|
|
2763
1645
|
}
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
if (!SchemaAST8.isTypeLiteral(schema.ast)) {
|
|
2767
|
-
throw new Error("schema has to describe an object type");
|
|
1646
|
+
if (schema.allOf) {
|
|
1647
|
+
maybeGoOnArray(schema.allOf);
|
|
2768
1648
|
}
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
makeArraysReactive(target);
|
|
2772
|
-
setSchemaProperties(target, schema);
|
|
2773
|
-
};
|
|
2774
|
-
var makeArraysReactive = (target) => {
|
|
2775
|
-
for (const key in target) {
|
|
2776
|
-
if (target[symbolIsProxy]) {
|
|
2777
|
-
continue;
|
|
2778
|
-
}
|
|
2779
|
-
if (Array.isArray(target[key])) {
|
|
2780
|
-
target[key] = ReactiveArray.from(target[key]);
|
|
2781
|
-
}
|
|
2782
|
-
if (typeof target[key] === "object") {
|
|
2783
|
-
makeArraysReactive(target[key]);
|
|
2784
|
-
}
|
|
1649
|
+
if (schema.anyOf) {
|
|
1650
|
+
maybeGoOnArray(schema.anyOf);
|
|
2785
1651
|
}
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
// src/internal/proxy/make-object.ts
|
|
2789
|
-
var makeObject = (schema, obj, meta) => {
|
|
2790
|
-
return createReactiveObject({
|
|
2791
|
-
...obj
|
|
2792
|
-
}, meta, schema);
|
|
2793
|
-
};
|
|
2794
|
-
var createReactiveObject = (obj, meta, schema) => {
|
|
2795
|
-
if (!isValidProxyTarget(obj)) {
|
|
2796
|
-
throw new Error("Value cannot be made into a reactive object.");
|
|
1652
|
+
if (schema.oneOf) {
|
|
1653
|
+
maybeGoOnArray(schema.oneOf);
|
|
2797
1654
|
}
|
|
2798
|
-
if (
|
|
2799
|
-
|
|
1655
|
+
if (schema.not) {
|
|
1656
|
+
go(schema.not);
|
|
2800
1657
|
}
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
setIdOnTarget(obj);
|
|
2804
|
-
defineHiddenProperty(obj, KindId, annotation.kind);
|
|
1658
|
+
if (schema.$defs) {
|
|
1659
|
+
goOnRecord(schema.$defs);
|
|
2805
1660
|
}
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
attachTypedJsonSerializer(obj);
|
|
2809
|
-
const proxy = createProxy(obj, TypedReactiveHandler.instance);
|
|
2810
|
-
const metaProxy = obj[MetaId];
|
|
2811
|
-
if (metaProxy) {
|
|
2812
|
-
const metaTarget = getProxyTarget(metaProxy);
|
|
2813
|
-
if (metaTarget) {
|
|
2814
|
-
setMetaOwner(metaTarget, obj);
|
|
2815
|
-
}
|
|
1661
|
+
if (schema.reference) {
|
|
1662
|
+
go(schema.reference.schema);
|
|
2816
1663
|
}
|
|
2817
|
-
return proxy;
|
|
2818
1664
|
};
|
|
2819
|
-
var
|
|
2820
|
-
if (
|
|
2821
|
-
|
|
2822
|
-
|
|
1665
|
+
var maybeGoOnArray = (value2) => {
|
|
1666
|
+
if (Array.isArray(value2)) {
|
|
1667
|
+
for (const item of value2) {
|
|
1668
|
+
go(item);
|
|
2823
1669
|
}
|
|
2824
|
-
} else {
|
|
2825
|
-
|
|
1670
|
+
} else if (typeof value2 === "object" && value2 !== null) {
|
|
1671
|
+
go(value2);
|
|
2826
1672
|
}
|
|
2827
1673
|
};
|
|
2828
|
-
var
|
|
2829
|
-
keys
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
defineHiddenProperty(obj, MetaId, createProxy(meta, TypedReactiveHandler.instance));
|
|
1674
|
+
var goOnRecord = (record) => {
|
|
1675
|
+
for (const key of Object.keys(record)) {
|
|
1676
|
+
go(record[key]);
|
|
1677
|
+
}
|
|
2833
1678
|
};
|
|
2834
1679
|
|
|
2835
|
-
// src/internal/
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
1680
|
+
// src/internal/Obj/common.ts
|
|
1681
|
+
import * as Schema9 from "effect/Schema";
|
|
1682
|
+
var makeTypedEntityClass = (typename, version2, baseSchema) => {
|
|
1683
|
+
return class {
|
|
1684
|
+
// Implement TypedObject properties.
|
|
1685
|
+
static typename = typename;
|
|
1686
|
+
static version = version2;
|
|
1687
|
+
// Implement Schema.Schema properties.
|
|
1688
|
+
// TODO(burdon): Comment required.
|
|
1689
|
+
static [Schema9.TypeId] = schemaVariance;
|
|
1690
|
+
static ast = baseSchema.ast;
|
|
1691
|
+
static annotations = baseSchema.annotations.bind(baseSchema);
|
|
1692
|
+
static pipe = baseSchema.pipe.bind(baseSchema);
|
|
1693
|
+
// TODO(burdon): Comment required.
|
|
1694
|
+
static [Symbol.hasInstance](obj) {
|
|
1695
|
+
return obj != null && getTypename(obj) === typename;
|
|
1696
|
+
}
|
|
1697
|
+
// TODO(burdon): Throw APIError.
|
|
1698
|
+
constructor() {
|
|
1699
|
+
throw new Error("Use live(Typename, { ...fields }) to instantiate an object.");
|
|
1700
|
+
}
|
|
2842
1701
|
};
|
|
2843
1702
|
};
|
|
2844
|
-
var
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
} else {
|
|
2849
|
-
callback(obj);
|
|
2850
|
-
}
|
|
1703
|
+
var schemaVariance = {
|
|
1704
|
+
_A: (_) => _,
|
|
1705
|
+
_I: (_) => _,
|
|
1706
|
+
_R: (_) => _
|
|
2851
1707
|
};
|
|
2852
1708
|
|
|
2853
|
-
// src/internal/object
|
|
2854
|
-
import {
|
|
1709
|
+
// src/internal/Obj/create-object.ts
|
|
1710
|
+
import { raise as raise3 } from "@dxos/debug";
|
|
1711
|
+
import { assertArgument as assertArgument6, failedInvariant } from "@dxos/invariant";
|
|
1712
|
+
import { ObjectId as ObjectId5 } from "@dxos/keys";
|
|
1713
|
+
|
|
1714
|
+
// src/internal/Obj/inspect.ts
|
|
1715
|
+
import { inspectCustom as inspectCustom2 } from "@dxos/debug";
|
|
2855
1716
|
var attachedTypedObjectInspector = (obj) => {
|
|
2856
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj,
|
|
1717
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, inspectCustom2);
|
|
2857
1718
|
if (descriptor) {
|
|
2858
1719
|
return;
|
|
2859
1720
|
}
|
|
2860
|
-
Object.defineProperty(obj,
|
|
1721
|
+
Object.defineProperty(obj, inspectCustom2, {
|
|
2861
1722
|
value: typedObjectInspectFunction,
|
|
2862
1723
|
writable: false,
|
|
2863
1724
|
enumerable: false,
|
|
@@ -2874,19 +1735,19 @@ var typedObjectInspectFunction = function(depth, options, inspect) {
|
|
|
2874
1735
|
}, options);
|
|
2875
1736
|
};
|
|
2876
1737
|
|
|
2877
|
-
// src/internal/
|
|
2878
|
-
import * as
|
|
2879
|
-
import { raise as
|
|
1738
|
+
// src/internal/Obj/json-serializer.ts
|
|
1739
|
+
import * as Schema10 from "effect/Schema";
|
|
1740
|
+
import { raise as raise2 } from "@dxos/debug";
|
|
2880
1741
|
import { ObjectStructure, isEncodedReference } from "@dxos/echo-protocol";
|
|
2881
|
-
import { assertArgument as
|
|
2882
|
-
import { DXN as
|
|
1742
|
+
import { assertArgument as assertArgument5, invariant as invariant13 } from "@dxos/invariant";
|
|
1743
|
+
import { DXN as DXN5, ObjectId as ObjectId4 } from "@dxos/keys";
|
|
2883
1744
|
import { assumeType as assumeType4, deepMapValues as deepMapValues2, visitValues } from "@dxos/util";
|
|
2884
|
-
var
|
|
1745
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Obj/json-serializer.ts";
|
|
2885
1746
|
var objectToJSON = (obj) => {
|
|
2886
1747
|
const typename = getTypeDXN(obj)?.toString();
|
|
2887
|
-
|
|
2888
|
-
F:
|
|
2889
|
-
L:
|
|
1748
|
+
invariant13(typename && typeof typename === "string", void 0, {
|
|
1749
|
+
F: __dxlog_file13,
|
|
1750
|
+
L: 64,
|
|
2890
1751
|
S: void 0,
|
|
2891
1752
|
A: [
|
|
2892
1753
|
"typename && typeof typename === 'string'",
|
|
@@ -2897,34 +1758,35 @@ var objectToJSON = (obj) => {
|
|
|
2897
1758
|
};
|
|
2898
1759
|
var objectFromJSON = async (jsonData, { refResolver, dxn } = {}) => {
|
|
2899
1760
|
assumeType4(jsonData);
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
const type =
|
|
1761
|
+
assertArgument5(typeof jsonData === "object" && jsonData !== null, "jsonData", "expect object");
|
|
1762
|
+
assertArgument5(typeof jsonData[ATTR_TYPE] === "string", "jsonData[ATTR_TYPE]", "expected object to have a type");
|
|
1763
|
+
assertArgument5(typeof jsonData.id === "string", "jsonData.id", "expected object to have an id");
|
|
1764
|
+
const type = DXN5.parse(jsonData[ATTR_TYPE]);
|
|
2904
1765
|
const schema = await refResolver?.resolveSchema(type);
|
|
2905
|
-
|
|
2906
|
-
F:
|
|
2907
|
-
L:
|
|
1766
|
+
invariant13(schema === void 0 || Schema10.isSchema(schema), void 0, {
|
|
1767
|
+
F: __dxlog_file13,
|
|
1768
|
+
L: 85,
|
|
2908
1769
|
S: void 0,
|
|
2909
1770
|
A: [
|
|
2910
1771
|
"schema === undefined || Schema.isSchema(schema)",
|
|
2911
1772
|
""
|
|
2912
1773
|
]
|
|
2913
1774
|
});
|
|
1775
|
+
const decodedInput = stripInternalJsonKeys(jsonData);
|
|
2914
1776
|
let obj;
|
|
2915
1777
|
if (schema != null) {
|
|
2916
|
-
obj = await schema.pipe(
|
|
1778
|
+
obj = await schema.pipe(Schema10.decodeUnknownPromise)(decodedInput);
|
|
2917
1779
|
if (refResolver) {
|
|
2918
1780
|
setRefResolverOnData(obj, refResolver);
|
|
2919
1781
|
}
|
|
2920
1782
|
} else {
|
|
2921
|
-
obj = decodeGeneric(
|
|
1783
|
+
obj = decodeGeneric(decodedInput, {
|
|
2922
1784
|
refResolver
|
|
2923
1785
|
});
|
|
2924
1786
|
}
|
|
2925
|
-
|
|
2926
|
-
F:
|
|
2927
|
-
L:
|
|
1787
|
+
invariant13(ObjectId4.isValid(obj.id), "Invalid object id", {
|
|
1788
|
+
F: __dxlog_file13,
|
|
1789
|
+
L: 98,
|
|
2928
1790
|
S: void 0,
|
|
2929
1791
|
A: [
|
|
2930
1792
|
"ObjectId.isValid(obj.id)",
|
|
@@ -2937,8 +1799,8 @@ var objectFromJSON = async (jsonData, { refResolver, dxn } = {}) => {
|
|
|
2937
1799
|
}
|
|
2938
1800
|
const isRelation = typeof jsonData[ATTR_RELATION_SOURCE] === "string" || typeof jsonData[ATTR_RELATION_TARGET] === "string";
|
|
2939
1801
|
if (isRelation) {
|
|
2940
|
-
const sourceDxn =
|
|
2941
|
-
const targetDxn =
|
|
1802
|
+
const sourceDxn = DXN5.parse(jsonData[ATTR_RELATION_SOURCE] ?? raise2(new TypeError("Missing relation source")));
|
|
1803
|
+
const targetDxn = DXN5.parse(jsonData[ATTR_RELATION_TARGET] ?? raise2(new TypeError("Missing relation target")));
|
|
2942
1804
|
const source = await refResolver?.resolve(sourceDxn);
|
|
2943
1805
|
const target = await refResolver?.resolve(targetDxn);
|
|
2944
1806
|
defineHiddenProperty(obj, KindId, EntityKind.Relation);
|
|
@@ -2950,10 +1812,10 @@ var objectFromJSON = async (jsonData, { refResolver, dxn } = {}) => {
|
|
|
2950
1812
|
defineHiddenProperty(obj, KindId, EntityKind.Object);
|
|
2951
1813
|
}
|
|
2952
1814
|
if (typeof jsonData[ATTR_META] === "object") {
|
|
2953
|
-
const meta = await ObjectMetaSchema.pipe(
|
|
2954
|
-
|
|
2955
|
-
F:
|
|
2956
|
-
L:
|
|
1815
|
+
const meta = await ObjectMetaSchema.pipe(Schema10.decodeUnknownPromise)(jsonData[ATTR_META]);
|
|
1816
|
+
invariant13(Array.isArray(meta.keys), void 0, {
|
|
1817
|
+
F: __dxlog_file13,
|
|
1818
|
+
L: 124,
|
|
2957
1819
|
S: void 0,
|
|
2958
1820
|
A: [
|
|
2959
1821
|
"Array.isArray(meta.keys)",
|
|
@@ -2966,58 +1828,63 @@ var objectFromJSON = async (jsonData, { refResolver, dxn } = {}) => {
|
|
|
2966
1828
|
keys: []
|
|
2967
1829
|
});
|
|
2968
1830
|
}
|
|
1831
|
+
if (jsonData[ATTR_PARENT]) {
|
|
1832
|
+
const parentDxn = DXN5.parse(jsonData[ATTR_PARENT]);
|
|
1833
|
+
const parent = await refResolver?.resolve(parentDxn);
|
|
1834
|
+
defineHiddenProperty(obj, ParentId, parent);
|
|
1835
|
+
}
|
|
2969
1836
|
if (dxn) {
|
|
2970
1837
|
defineHiddenProperty(obj, SelfDXNId, dxn);
|
|
2971
1838
|
}
|
|
2972
1839
|
assertObjectModel(obj);
|
|
2973
|
-
|
|
2974
|
-
F:
|
|
2975
|
-
L:
|
|
1840
|
+
invariant13(obj[ATTR_TYPE] === void 0, "Invalid object model", {
|
|
1841
|
+
F: __dxlog_file13,
|
|
1842
|
+
L: 143,
|
|
2976
1843
|
S: void 0,
|
|
2977
1844
|
A: [
|
|
2978
1845
|
"(obj as any)[ATTR_TYPE] === undefined",
|
|
2979
1846
|
"'Invalid object model'"
|
|
2980
1847
|
]
|
|
2981
1848
|
});
|
|
2982
|
-
|
|
2983
|
-
F:
|
|
2984
|
-
L:
|
|
1849
|
+
invariant13(obj[ATTR_META] === void 0, "Invalid object model", {
|
|
1850
|
+
F: __dxlog_file13,
|
|
1851
|
+
L: 144,
|
|
2985
1852
|
S: void 0,
|
|
2986
1853
|
A: [
|
|
2987
1854
|
"(obj as any)[ATTR_META] === undefined",
|
|
2988
1855
|
"'Invalid object model'"
|
|
2989
1856
|
]
|
|
2990
1857
|
});
|
|
2991
|
-
|
|
2992
|
-
F:
|
|
2993
|
-
L:
|
|
1858
|
+
invariant13(obj[ATTR_DELETED] === void 0, "Invalid object model", {
|
|
1859
|
+
F: __dxlog_file13,
|
|
1860
|
+
L: 145,
|
|
2994
1861
|
S: void 0,
|
|
2995
1862
|
A: [
|
|
2996
1863
|
"(obj as any)[ATTR_DELETED] === undefined",
|
|
2997
1864
|
"'Invalid object model'"
|
|
2998
1865
|
]
|
|
2999
1866
|
});
|
|
3000
|
-
|
|
3001
|
-
F:
|
|
3002
|
-
L:
|
|
1867
|
+
invariant13(obj[ATTR_SELF_DXN] === void 0, "Invalid object model", {
|
|
1868
|
+
F: __dxlog_file13,
|
|
1869
|
+
L: 146,
|
|
3003
1870
|
S: void 0,
|
|
3004
1871
|
A: [
|
|
3005
1872
|
"(obj as any)[ATTR_SELF_DXN] === undefined",
|
|
3006
1873
|
"'Invalid object model'"
|
|
3007
1874
|
]
|
|
3008
1875
|
});
|
|
3009
|
-
|
|
3010
|
-
F:
|
|
3011
|
-
L:
|
|
1876
|
+
invariant13(obj[ATTR_RELATION_SOURCE] === void 0, "Invalid object model", {
|
|
1877
|
+
F: __dxlog_file13,
|
|
1878
|
+
L: 147,
|
|
3012
1879
|
S: void 0,
|
|
3013
1880
|
A: [
|
|
3014
1881
|
"(obj as any)[ATTR_RELATION_SOURCE] === undefined",
|
|
3015
1882
|
"'Invalid object model'"
|
|
3016
1883
|
]
|
|
3017
1884
|
});
|
|
3018
|
-
|
|
3019
|
-
F:
|
|
3020
|
-
L:
|
|
1885
|
+
invariant13(obj[ATTR_RELATION_TARGET] === void 0, "Invalid object model", {
|
|
1886
|
+
F: __dxlog_file13,
|
|
1887
|
+
L: 148,
|
|
3021
1888
|
S: void 0,
|
|
3022
1889
|
A: [
|
|
3023
1890
|
"(obj as any)[ATTR_RELATION_TARGET] === undefined",
|
|
@@ -3027,7 +1894,7 @@ var objectFromJSON = async (jsonData, { refResolver, dxn } = {}) => {
|
|
|
3027
1894
|
return obj;
|
|
3028
1895
|
};
|
|
3029
1896
|
var decodeGeneric = (jsonData, options) => {
|
|
3030
|
-
const
|
|
1897
|
+
const props = stripInternalJsonKeys(jsonData);
|
|
3031
1898
|
return deepMapValues2(props, (value2, visitor) => {
|
|
3032
1899
|
if (isEncodedReference(value2)) {
|
|
3033
1900
|
return refFromEncodedReference(value2, options.refResolver);
|
|
@@ -3035,6 +1902,10 @@ var decodeGeneric = (jsonData, options) => {
|
|
|
3035
1902
|
return visitor(value2);
|
|
3036
1903
|
});
|
|
3037
1904
|
};
|
|
1905
|
+
var stripInternalJsonKeys = (jsonData) => {
|
|
1906
|
+
const { [ATTR_TYPE]: _type, [ATTR_META]: _meta, [ATTR_DELETED]: _deleted, [ATTR_SELF_DXN]: _selfDxn, [ATTR_RELATION_SOURCE]: _relationSource, [ATTR_RELATION_TARGET]: _relationTarget, ...props } = jsonData;
|
|
1907
|
+
return props;
|
|
1908
|
+
};
|
|
3038
1909
|
var setRefResolverOnData = (obj, refResolver) => {
|
|
3039
1910
|
const visitor = (value2) => {
|
|
3040
1911
|
if (Ref.isRef(value2)) {
|
|
@@ -3051,24 +1922,25 @@ var objectStructureToJson = (objectId, structure) => {
|
|
|
3051
1922
|
id: objectId,
|
|
3052
1923
|
[ATTR_TYPE]: ObjectStructure.getTypeReference(structure)?.["/"] ?? "",
|
|
3053
1924
|
[ATTR_DELETED]: ObjectStructure.isDeleted(structure),
|
|
1925
|
+
[ATTR_PARENT]: ObjectStructure.getParent(structure)?.["/"],
|
|
3054
1926
|
[ATTR_RELATION_SOURCE]: ObjectStructure.getRelationSource(structure)?.["/"],
|
|
3055
1927
|
[ATTR_RELATION_TARGET]: ObjectStructure.getRelationTarget(structure)?.["/"]
|
|
3056
1928
|
};
|
|
3057
1929
|
};
|
|
3058
1930
|
|
|
3059
|
-
// src/internal/
|
|
1931
|
+
// src/internal/Obj/create-object.ts
|
|
3060
1932
|
var createObject = (schema, props) => {
|
|
3061
1933
|
const annotation = getTypeAnnotation(schema);
|
|
3062
1934
|
if (!annotation) {
|
|
3063
1935
|
throw new Error("Schema is not an ECHO schema");
|
|
3064
1936
|
}
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
1937
|
+
assertArgument6(!("@type" in props), "data", "@type is not allowed");
|
|
1938
|
+
assertArgument6(!(RelationSourceDXNId in props), "data", "Relation source DXN is not allowed in the constructor");
|
|
1939
|
+
assertArgument6(!(RelationTargetDXNId in props), "data", "Relation target DXN is not allowed in the constructor");
|
|
1940
|
+
assertArgument6(RelationSourceId in props === RelationTargetId in props, "data", "Relation source and target must be provided together");
|
|
3069
1941
|
const obj = {
|
|
3070
1942
|
...props,
|
|
3071
|
-
id: props.id ??
|
|
1943
|
+
id: props.id ?? ObjectId5.random()
|
|
3072
1944
|
};
|
|
3073
1945
|
const kind = RelationSourceId in props ? EntityKind.Relation : EntityKind.Object;
|
|
3074
1946
|
defineHiddenProperty(obj, KindId, kind);
|
|
@@ -3080,8 +1952,8 @@ var createObject = (schema, props) => {
|
|
|
3080
1952
|
attachTypedJsonSerializer(obj);
|
|
3081
1953
|
attachedTypedObjectInspector(obj);
|
|
3082
1954
|
if (kind === EntityKind.Relation) {
|
|
3083
|
-
const sourceDXN = getObjectDXN(props[RelationSourceId]) ??
|
|
3084
|
-
const targetDXN = getObjectDXN(props[RelationTargetId]) ??
|
|
1955
|
+
const sourceDXN = getObjectDXN(props[RelationSourceId]) ?? raise3(new Error("Unresolved relation source"));
|
|
1956
|
+
const targetDXN = getObjectDXN(props[RelationTargetId]) ?? raise3(new Error("Unresolved relation target"));
|
|
3085
1957
|
defineHiddenProperty(obj, RelationSourceDXNId, sourceDXN);
|
|
3086
1958
|
defineHiddenProperty(obj, RelationTargetDXNId, targetDXN);
|
|
3087
1959
|
}
|
|
@@ -3089,7 +1961,7 @@ var createObject = (schema, props) => {
|
|
|
3089
1961
|
return obj;
|
|
3090
1962
|
};
|
|
3091
1963
|
|
|
3092
|
-
// src/internal/
|
|
1964
|
+
// src/internal/Obj/deleted.ts
|
|
3093
1965
|
var isDeleted = (obj) => {
|
|
3094
1966
|
if (obj[ObjectDeletedId] === void 0) {
|
|
3095
1967
|
return false;
|
|
@@ -3097,24 +1969,24 @@ var isDeleted = (obj) => {
|
|
|
3097
1969
|
return obj[ObjectDeletedId] ?? false;
|
|
3098
1970
|
};
|
|
3099
1971
|
|
|
3100
|
-
// src/internal/
|
|
3101
|
-
import { DXN as
|
|
3102
|
-
var createQueueDXN = (spaceId = SpaceId.random(), queueId =
|
|
1972
|
+
// src/internal/Obj/ids.ts
|
|
1973
|
+
import { DXN as DXN6, ObjectId as ObjectId6, QueueSubspaceTags, SpaceId } from "@dxos/keys";
|
|
1974
|
+
var createQueueDXN = (spaceId = SpaceId.random(), queueId = ObjectId6.random()) => new DXN6(DXN6.kind.QUEUE, [
|
|
3103
1975
|
QueueSubspaceTags.DATA,
|
|
3104
1976
|
spaceId,
|
|
3105
1977
|
queueId
|
|
3106
1978
|
]);
|
|
3107
1979
|
|
|
3108
|
-
// src/internal/
|
|
1980
|
+
// src/internal/Obj/set-value.ts
|
|
3109
1981
|
import * as Match from "effect/Match";
|
|
3110
|
-
import * as
|
|
3111
|
-
import * as
|
|
1982
|
+
import * as Option from "effect/Option";
|
|
1983
|
+
import * as SchemaAST6 from "effect/SchemaAST";
|
|
3112
1984
|
import { getArrayElementType, getBaseType, getProperties as getProperties2, isArrayType, isNestedType } from "@dxos/effect";
|
|
3113
|
-
import { invariant as
|
|
3114
|
-
var
|
|
1985
|
+
import { invariant as invariant14 } from "@dxos/invariant";
|
|
1986
|
+
var __dxlog_file14 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Obj/set-value.ts";
|
|
3115
1987
|
var setValue = (obj, path, value2) => {
|
|
3116
|
-
|
|
3117
|
-
F:
|
|
1988
|
+
invariant14(path.length > 0, "Path must not be empty", {
|
|
1989
|
+
F: __dxlog_file14,
|
|
3118
1990
|
L: 27,
|
|
3119
1991
|
S: void 0,
|
|
3120
1992
|
A: [
|
|
@@ -3123,8 +1995,8 @@ var setValue = (obj, path, value2) => {
|
|
|
3123
1995
|
]
|
|
3124
1996
|
});
|
|
3125
1997
|
const schema = getSchema(obj);
|
|
3126
|
-
|
|
3127
|
-
F:
|
|
1998
|
+
invariant14(schema != null, "Object must have a schema", {
|
|
1999
|
+
F: __dxlog_file14,
|
|
3128
2000
|
L: 30,
|
|
3129
2001
|
S: void 0,
|
|
3130
2002
|
A: [
|
|
@@ -3185,8 +2057,8 @@ var getDefaultValueForType = (ast) => {
|
|
|
3185
2057
|
if (!ast) {
|
|
3186
2058
|
return void 0;
|
|
3187
2059
|
}
|
|
3188
|
-
const defaultValue =
|
|
3189
|
-
if (
|
|
2060
|
+
const defaultValue = SchemaAST6.getDefaultAnnotation(ast);
|
|
2061
|
+
if (Option.isSome(defaultValue)) {
|
|
3190
2062
|
return defaultValue.value;
|
|
3191
2063
|
}
|
|
3192
2064
|
return Match.value(ast).pipe(Match.when({
|
|
@@ -3214,12 +2086,20 @@ var createObjectWithDefaults = (ast) => {
|
|
|
3214
2086
|
return obj;
|
|
3215
2087
|
};
|
|
3216
2088
|
|
|
3217
|
-
// src/internal/
|
|
2089
|
+
// src/internal/Obj/snapshot.ts
|
|
2090
|
+
import { assertArgument as assertArgument7 } from "@dxos/invariant";
|
|
3218
2091
|
import { deepMapValues as deepMapValues3 } from "@dxos/util";
|
|
3219
|
-
var copySymbolProperty = (source, target, symbol) => {
|
|
3220
|
-
|
|
2092
|
+
var copySymbolProperty = (source, target, symbol, transform) => {
|
|
2093
|
+
let value2;
|
|
2094
|
+
try {
|
|
2095
|
+
value2 = source[symbol];
|
|
2096
|
+
} catch {
|
|
2097
|
+
return;
|
|
2098
|
+
}
|
|
2099
|
+
if (value2 !== void 0) {
|
|
2100
|
+
const finalValue = transform ? transform(value2) : value2;
|
|
3221
2101
|
Object.defineProperty(target, symbol, {
|
|
3222
|
-
value:
|
|
2102
|
+
value: finalValue,
|
|
3223
2103
|
writable: false,
|
|
3224
2104
|
enumerable: false,
|
|
3225
2105
|
configurable: false
|
|
@@ -3227,6 +2107,7 @@ var copySymbolProperty = (source, target, symbol) => {
|
|
|
3227
2107
|
}
|
|
3228
2108
|
};
|
|
3229
2109
|
var getSnapshot = (obj) => {
|
|
2110
|
+
assertArgument7(typeof obj === "object" && obj !== null && KindId in obj, "obj", "must be an entity");
|
|
3230
2111
|
const snapshot = deepMapValues3(obj, (value2, recurse) => {
|
|
3231
2112
|
if (typeof value2 === "object" && value2 !== null && Object.getPrototypeOf(value2) !== Object.prototype && !Array.isArray(value2)) {
|
|
3232
2113
|
return value2;
|
|
@@ -3236,28 +2117,36 @@ var getSnapshot = (obj) => {
|
|
|
3236
2117
|
if (obj != null && typeof obj === "object" && KindId in obj) {
|
|
3237
2118
|
snapshot[SnapshotKindId] = obj[KindId];
|
|
3238
2119
|
}
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
2120
|
+
const source = obj;
|
|
2121
|
+
copySymbolProperty(source, snapshot, TypeId);
|
|
2122
|
+
copySymbolProperty(source, snapshot, SchemaId);
|
|
2123
|
+
copySymbolProperty(source, snapshot, SelfDXNId);
|
|
2124
|
+
copySymbolProperty(source, snapshot, ObjectDatabaseId);
|
|
2125
|
+
copySymbolProperty(source, snapshot, ObjectDeletedId);
|
|
2126
|
+
copySymbolProperty(source, snapshot, MetaId, (meta) => ({
|
|
2127
|
+
keys: [
|
|
2128
|
+
...meta?.keys ?? []
|
|
2129
|
+
],
|
|
2130
|
+
tags: [
|
|
2131
|
+
...meta?.tags ?? []
|
|
2132
|
+
]
|
|
2133
|
+
}));
|
|
2134
|
+
copySymbolProperty(source, snapshot, RelationSourceDXNId);
|
|
2135
|
+
copySymbolProperty(source, snapshot, RelationTargetDXNId);
|
|
2136
|
+
copySymbolProperty(source, snapshot, RelationSourceId);
|
|
2137
|
+
copySymbolProperty(source, snapshot, RelationTargetId);
|
|
3249
2138
|
return Object.freeze(snapshot);
|
|
3250
2139
|
};
|
|
3251
2140
|
|
|
3252
|
-
// src/internal/
|
|
3253
|
-
import { invariant as
|
|
2141
|
+
// src/internal/Obj/clone.ts
|
|
2142
|
+
import { invariant as invariant15 } from "@dxos/invariant";
|
|
3254
2143
|
import { deepMapValues as deepMapValues4 } from "@dxos/util";
|
|
3255
|
-
var
|
|
2144
|
+
var __dxlog_file15 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Obj/clone.ts";
|
|
3256
2145
|
var clone = (obj, opts) => {
|
|
3257
2146
|
const { id, ...data } = obj;
|
|
3258
2147
|
const schema = getSchema(obj);
|
|
3259
|
-
|
|
3260
|
-
F:
|
|
2148
|
+
invariant15(schema != null, "Object should have a schema", {
|
|
2149
|
+
F: __dxlog_file15,
|
|
3261
2150
|
L: 21,
|
|
3262
2151
|
S: void 0,
|
|
3263
2152
|
A: [
|
|
@@ -3289,25 +2178,25 @@ var clone = (obj, opts) => {
|
|
|
3289
2178
|
return makeObject(schema, props, meta);
|
|
3290
2179
|
};
|
|
3291
2180
|
|
|
3292
|
-
// src/internal/
|
|
3293
|
-
import * as
|
|
3294
|
-
import * as
|
|
3295
|
-
import { invariant as
|
|
2181
|
+
// src/internal/Type/echo-schema.ts
|
|
2182
|
+
import * as Schema13 from "effect/Schema";
|
|
2183
|
+
import * as SchemaAST8 from "effect/SchemaAST";
|
|
2184
|
+
import { invariant as invariant17 } from "@dxos/invariant";
|
|
3296
2185
|
|
|
3297
|
-
// src/internal/
|
|
3298
|
-
import * as
|
|
3299
|
-
import * as
|
|
3300
|
-
import { invariant as
|
|
3301
|
-
import { DXN as
|
|
3302
|
-
var
|
|
2186
|
+
// src/internal/Type/manipulation.ts
|
|
2187
|
+
import * as Schema11 from "effect/Schema";
|
|
2188
|
+
import * as SchemaAST7 from "effect/SchemaAST";
|
|
2189
|
+
import { invariant as invariant16 } from "@dxos/invariant";
|
|
2190
|
+
import { DXN as DXN7 } from "@dxos/keys";
|
|
2191
|
+
var __dxlog_file16 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Type/manipulation.ts";
|
|
3303
2192
|
var addFieldsToSchema = (schema, fields) => {
|
|
3304
|
-
const schemaExtension =
|
|
3305
|
-
return
|
|
2193
|
+
const schemaExtension = Schema11.partial(Schema11.Struct(fields));
|
|
2194
|
+
return Schema11.extend(schema, schemaExtension).annotations(schema.ast.annotations);
|
|
3306
2195
|
};
|
|
3307
2196
|
var updateFieldsInSchema = (schema, fields) => {
|
|
3308
2197
|
const ast = schema.ast;
|
|
3309
|
-
|
|
3310
|
-
F:
|
|
2198
|
+
invariant16(SchemaAST7.isTypeLiteral(ast), void 0, {
|
|
2199
|
+
F: __dxlog_file16,
|
|
3311
2200
|
L: 29,
|
|
3312
2201
|
S: void 0,
|
|
3313
2202
|
A: [
|
|
@@ -3318,7 +2207,7 @@ var updateFieldsInSchema = (schema, fields) => {
|
|
|
3318
2207
|
const updatedProperties = [
|
|
3319
2208
|
...ast.propertySignatures
|
|
3320
2209
|
];
|
|
3321
|
-
const propertiesToUpdate =
|
|
2210
|
+
const propertiesToUpdate = Schema11.partial(Schema11.Struct(fields)).ast.propertySignatures;
|
|
3322
2211
|
for (const property of propertiesToUpdate) {
|
|
3323
2212
|
const index = updatedProperties.findIndex((p) => p.name === property.name);
|
|
3324
2213
|
if (index !== -1) {
|
|
@@ -3327,15 +2216,15 @@ var updateFieldsInSchema = (schema, fields) => {
|
|
|
3327
2216
|
updatedProperties.push(property);
|
|
3328
2217
|
}
|
|
3329
2218
|
}
|
|
3330
|
-
return
|
|
2219
|
+
return Schema11.make(new SchemaAST7.TypeLiteral(updatedProperties, ast.indexSignatures, ast.annotations));
|
|
3331
2220
|
};
|
|
3332
2221
|
var removeFieldsFromSchema = (schema, fieldNames) => {
|
|
3333
|
-
return
|
|
2222
|
+
return Schema11.make(SchemaAST7.omit(schema.ast, fieldNames)).annotations(schema.ast.annotations);
|
|
3334
2223
|
};
|
|
3335
2224
|
var updateFieldNameInSchema = (schema, { before, after }) => {
|
|
3336
2225
|
const ast = schema.ast;
|
|
3337
|
-
|
|
3338
|
-
F:
|
|
2226
|
+
invariant16(SchemaAST7.isTypeLiteral(ast), void 0, {
|
|
2227
|
+
F: __dxlog_file16,
|
|
3339
2228
|
L: 57,
|
|
3340
2229
|
S: void 0,
|
|
3341
2230
|
A: [
|
|
@@ -3343,12 +2232,12 @@ var updateFieldNameInSchema = (schema, { before, after }) => {
|
|
|
3343
2232
|
""
|
|
3344
2233
|
]
|
|
3345
2234
|
});
|
|
3346
|
-
return
|
|
2235
|
+
return Schema11.make(new SchemaAST7.TypeLiteral(ast.propertySignatures.map((p) => p.name === before ? new SchemaAST7.PropertySignature(after, p.type, p.isOptional, p.isReadonly, p.annotations) : p), ast.indexSignatures, ast.annotations));
|
|
3347
2236
|
};
|
|
3348
2237
|
var setTypenameInSchema = (schema, typename) => {
|
|
3349
2238
|
const existingAnnotation = schema.ast.annotations[TypeAnnotationId];
|
|
3350
|
-
|
|
3351
|
-
F:
|
|
2239
|
+
invariant16(existingAnnotation, `Missing ${String(TypeAnnotationId)}`, {
|
|
2240
|
+
F: __dxlog_file16,
|
|
3352
2241
|
L: 77,
|
|
3353
2242
|
S: void 0,
|
|
3354
2243
|
A: [
|
|
@@ -3363,37 +2252,42 @@ var setTypenameInSchema = (schema, typename) => {
|
|
|
3363
2252
|
typename,
|
|
3364
2253
|
version: existingAnnotation.version
|
|
3365
2254
|
},
|
|
3366
|
-
[
|
|
3367
|
-
...schema.ast.annotations[
|
|
3368
|
-
$id: schema.ast.annotations[TypeIdentifierAnnotationId] ??
|
|
2255
|
+
[SchemaAST7.JSONSchemaAnnotationId]: {
|
|
2256
|
+
...schema.ast.annotations[SchemaAST7.JSONSchemaAnnotationId] ?? {},
|
|
2257
|
+
$id: schema.ast.annotations[TypeIdentifierAnnotationId] ?? DXN7.fromTypename(typename).toString(),
|
|
3369
2258
|
typename
|
|
3370
2259
|
}
|
|
3371
2260
|
});
|
|
3372
2261
|
};
|
|
3373
2262
|
|
|
3374
|
-
// src/internal/
|
|
3375
|
-
import * as
|
|
3376
|
-
var PersistentSchema =
|
|
3377
|
-
name:
|
|
2263
|
+
// src/internal/Type/persistent-schema.ts
|
|
2264
|
+
import * as Schema12 from "effect/Schema";
|
|
2265
|
+
var PersistentSchema = Schema12.Struct({
|
|
2266
|
+
name: Schema12.optional(Schema12.String),
|
|
3378
2267
|
typename: TypenameSchema,
|
|
3379
2268
|
version: VersionSchema,
|
|
3380
2269
|
jsonSchema: JsonSchemaType
|
|
3381
2270
|
}).pipe(EchoObjectSchema({
|
|
3382
|
-
typename: "dxos.
|
|
2271
|
+
typename: "org.dxos.type.schema",
|
|
3383
2272
|
version: "0.1.0"
|
|
2273
|
+
}), LabelAnnotation.set([
|
|
2274
|
+
"name"
|
|
2275
|
+
]), IconAnnotation.set({
|
|
2276
|
+
icon: "ph--brackets-curly--regular",
|
|
2277
|
+
hue: "blue"
|
|
3384
2278
|
}));
|
|
3385
2279
|
|
|
3386
|
-
// src/internal/
|
|
3387
|
-
var
|
|
2280
|
+
// src/internal/Type/echo-schema.ts
|
|
2281
|
+
var __dxlog_file17 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Type/echo-schema.ts";
|
|
3388
2282
|
var ImmutableSchema = class {
|
|
3389
2283
|
_schema;
|
|
3390
2284
|
_objectAnnotation;
|
|
3391
2285
|
constructor(_schema) {
|
|
3392
2286
|
this._schema = _schema;
|
|
3393
2287
|
this._objectAnnotation = getTypeAnnotation(this._schema);
|
|
3394
|
-
|
|
3395
|
-
F:
|
|
3396
|
-
L:
|
|
2288
|
+
invariant17(this._objectAnnotation, void 0, {
|
|
2289
|
+
F: __dxlog_file17,
|
|
2290
|
+
L: 49,
|
|
3397
2291
|
S: this,
|
|
3398
2292
|
A: [
|
|
3399
2293
|
"this._objectAnnotation",
|
|
@@ -3404,7 +2298,7 @@ var ImmutableSchema = class {
|
|
|
3404
2298
|
//
|
|
3405
2299
|
// Effect Schema (push to abstract base class).
|
|
3406
2300
|
//
|
|
3407
|
-
get [
|
|
2301
|
+
get [Schema13.TypeId]() {
|
|
3408
2302
|
return schemaVariance2;
|
|
3409
2303
|
}
|
|
3410
2304
|
get Type() {
|
|
@@ -3457,9 +2351,9 @@ var ImmutableSchema = class {
|
|
|
3457
2351
|
var EchoSchemaConstructor = () => {
|
|
3458
2352
|
return class {
|
|
3459
2353
|
static get _schema() {
|
|
3460
|
-
return
|
|
2354
|
+
return Schema13.Union(PersistentSchema, Schema13.instanceOf(EchoSchema)).annotations(PersistentSchema.ast.annotations);
|
|
3461
2355
|
}
|
|
3462
|
-
static [
|
|
2356
|
+
static [Schema13.TypeId] = schemaVariance2;
|
|
3463
2357
|
static get ast() {
|
|
3464
2358
|
const schema = this._schema;
|
|
3465
2359
|
return schema.ast;
|
|
@@ -3488,7 +2382,7 @@ var EchoSchema = class extends EchoSchemaConstructor() {
|
|
|
3488
2382
|
_isDirty = true;
|
|
3489
2383
|
/**
|
|
3490
2384
|
* Schema kind key that marks this as an ECHO schema.
|
|
3491
|
-
* Makes EchoSchema satisfy the Type.
|
|
2385
|
+
* Makes EchoSchema satisfy the Type.AnyObj type.
|
|
3492
2386
|
*/
|
|
3493
2387
|
[SchemaKindId] = EntityKind.Object;
|
|
3494
2388
|
constructor(_persistentSchema) {
|
|
@@ -3497,7 +2391,7 @@ var EchoSchema = class extends EchoSchemaConstructor() {
|
|
|
3497
2391
|
//
|
|
3498
2392
|
// Effect Schema (push to abstract base class).
|
|
3499
2393
|
//
|
|
3500
|
-
get [
|
|
2394
|
+
get [Schema13.TypeId]() {
|
|
3501
2395
|
return schemaVariance2;
|
|
3502
2396
|
}
|
|
3503
2397
|
get Type() {
|
|
@@ -3553,9 +2447,9 @@ var EchoSchema = class extends EchoSchemaConstructor() {
|
|
|
3553
2447
|
* Returns a mutable schema.
|
|
3554
2448
|
*/
|
|
3555
2449
|
get mutable() {
|
|
3556
|
-
|
|
3557
|
-
F:
|
|
3558
|
-
L:
|
|
2450
|
+
invariant17(!this.readonly, "Schema is not mutable", {
|
|
2451
|
+
F: __dxlog_file17,
|
|
2452
|
+
L: 279,
|
|
3559
2453
|
S: this,
|
|
3560
2454
|
A: [
|
|
3561
2455
|
"!this.readonly",
|
|
@@ -3594,9 +2488,9 @@ var EchoSchema = class extends EchoSchemaConstructor() {
|
|
|
3594
2488
|
}
|
|
3595
2489
|
getProperties() {
|
|
3596
2490
|
const ast = this._getSchema().ast;
|
|
3597
|
-
|
|
3598
|
-
F:
|
|
3599
|
-
L:
|
|
2491
|
+
invariant17(SchemaAST8.isTypeLiteral(ast), void 0, {
|
|
2492
|
+
F: __dxlog_file17,
|
|
2493
|
+
L: 314,
|
|
3600
2494
|
S: this,
|
|
3601
2495
|
A: [
|
|
3602
2496
|
"SchemaAST.isTypeLiteral(ast)",
|
|
@@ -3686,7 +2580,7 @@ var EchoSchema = class extends EchoSchemaConstructor() {
|
|
|
3686
2580
|
*/
|
|
3687
2581
|
_rebuild() {
|
|
3688
2582
|
if (this._isDirty || this._schema == null) {
|
|
3689
|
-
this._schema = toEffectSchema(getSnapshot(this._persistentSchema.jsonSchema)
|
|
2583
|
+
this._schema = toEffectSchema(getSnapshot(this._persistentSchema).jsonSchema);
|
|
3690
2584
|
this._isDirty = false;
|
|
3691
2585
|
}
|
|
3692
2586
|
}
|
|
@@ -3696,12 +2590,12 @@ var EchoSchema = class extends EchoSchemaConstructor() {
|
|
|
3696
2590
|
}
|
|
3697
2591
|
};
|
|
3698
2592
|
var unwrapOptionality = (property) => {
|
|
3699
|
-
if (!
|
|
2593
|
+
if (!SchemaAST8.isUnion(property.type)) {
|
|
3700
2594
|
return property;
|
|
3701
2595
|
}
|
|
3702
2596
|
return {
|
|
3703
2597
|
...property,
|
|
3704
|
-
type: property.type.types.find((type) => !
|
|
2598
|
+
type: property.type.types.find((type) => !SchemaAST8.isUndefinedKeyword(type))
|
|
3705
2599
|
};
|
|
3706
2600
|
};
|
|
3707
2601
|
|
|
@@ -3714,75 +2608,28 @@ export {
|
|
|
3714
2608
|
foreignKey,
|
|
3715
2609
|
foreignKeyEquals,
|
|
3716
2610
|
compareForeignKeys,
|
|
3717
|
-
VersionTypeId,
|
|
3718
|
-
getLabel,
|
|
3719
|
-
setLabel,
|
|
3720
|
-
getDescription,
|
|
3721
|
-
setDescription,
|
|
3722
|
-
makeEchoTypeSchema,
|
|
3723
|
-
ATTR_RELATION_SOURCE,
|
|
3724
|
-
RelationSourceId,
|
|
3725
|
-
RelationSourceDXNId,
|
|
3726
|
-
ATTR_RELATION_TARGET,
|
|
3727
|
-
RelationTargetId,
|
|
3728
|
-
RelationTargetDXNId,
|
|
3729
|
-
EchoRelationSchema,
|
|
3730
2611
|
ATTR_SELF_DXN,
|
|
3731
2612
|
SelfDXNId,
|
|
3732
2613
|
ATTR_DELETED,
|
|
3733
2614
|
ObjectDeletedId,
|
|
3734
2615
|
ObjectVersionId,
|
|
3735
2616
|
ObjectDatabaseId,
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
2617
|
+
ATTR_RELATION_SOURCE,
|
|
2618
|
+
RelationSourceId,
|
|
2619
|
+
RelationSourceDXNId,
|
|
2620
|
+
ATTR_RELATION_TARGET,
|
|
2621
|
+
RelationTargetId,
|
|
2622
|
+
RelationTargetDXNId,
|
|
2623
|
+
VersionTypeId,
|
|
2624
|
+
compare,
|
|
2625
|
+
sortByLabel,
|
|
2626
|
+
sortByTypename,
|
|
2627
|
+
sort,
|
|
3741
2628
|
getMetaChecked,
|
|
3742
2629
|
getKeys,
|
|
3743
2630
|
deleteKeys,
|
|
3744
2631
|
addTag,
|
|
3745
2632
|
removeTag,
|
|
3746
|
-
compare,
|
|
3747
|
-
sortByLabel,
|
|
3748
|
-
sortByTypename,
|
|
3749
|
-
sort,
|
|
3750
|
-
isVersion,
|
|
3751
|
-
version,
|
|
3752
|
-
versionValid,
|
|
3753
|
-
compareVersions,
|
|
3754
|
-
encodeVersion,
|
|
3755
|
-
decodeVersion,
|
|
3756
|
-
CustomAnnotations,
|
|
3757
|
-
DecodedAnnotations,
|
|
3758
|
-
EchoAnnotations,
|
|
3759
|
-
JsonSchemaEchoAnnotations,
|
|
3760
|
-
JsonSchemaFields,
|
|
3761
|
-
JsonSchemaType,
|
|
3762
|
-
getSchemaProperty,
|
|
3763
|
-
setSchemaProperty,
|
|
3764
|
-
ECHO_ANNOTATIONS_NS_DEPRECATED_KEY,
|
|
3765
|
-
ECHO_ANNOTATIONS_NS_KEY,
|
|
3766
|
-
getNormalizedEchoAnnotations,
|
|
3767
|
-
normalizeSchema,
|
|
3768
|
-
JSON_SCHEMA_ECHO_REF_ID,
|
|
3769
|
-
getSchemaReference,
|
|
3770
|
-
createSchemaReference,
|
|
3771
|
-
getReferenceAst,
|
|
3772
|
-
RefTypeId,
|
|
3773
|
-
Ref,
|
|
3774
|
-
createEchoReferenceSchema,
|
|
3775
|
-
RefImpl,
|
|
3776
|
-
setRefResolver,
|
|
3777
|
-
getRefSavedTarget,
|
|
3778
|
-
refFromEncodedReference,
|
|
3779
|
-
StaticRefResolver,
|
|
3780
|
-
RefArray,
|
|
3781
|
-
PropType,
|
|
3782
|
-
toPropType,
|
|
3783
|
-
toJsonSchema,
|
|
3784
|
-
toEffectSchema,
|
|
3785
|
-
makeTypedEntityClass,
|
|
3786
2633
|
EventId,
|
|
3787
2634
|
ChangeId,
|
|
3788
2635
|
batchEvents,
|
|
@@ -3820,6 +2667,21 @@ export {
|
|
|
3820
2667
|
makeObject,
|
|
3821
2668
|
subscribe,
|
|
3822
2669
|
change,
|
|
2670
|
+
assertObjectModel,
|
|
2671
|
+
getObjectDXN,
|
|
2672
|
+
getDXN,
|
|
2673
|
+
getDatabase,
|
|
2674
|
+
makeEchoTypeSchema,
|
|
2675
|
+
EchoObjectSchema,
|
|
2676
|
+
EchoRelationSchema,
|
|
2677
|
+
isVersion,
|
|
2678
|
+
version,
|
|
2679
|
+
versionValid,
|
|
2680
|
+
compareVersions,
|
|
2681
|
+
encodeVersion,
|
|
2682
|
+
decodeVersion,
|
|
2683
|
+
normalizeSchema,
|
|
2684
|
+
makeTypedEntityClass,
|
|
3823
2685
|
objectToJSON,
|
|
3824
2686
|
objectFromJSON,
|
|
3825
2687
|
setRefResolverOnData,
|
|
@@ -3839,9 +2701,9 @@ export {
|
|
|
3839
2701
|
ImmutableSchema,
|
|
3840
2702
|
isMutable,
|
|
3841
2703
|
EchoSchema,
|
|
3842
|
-
|
|
2704
|
+
JsonPath,
|
|
3843
2705
|
JsonProp,
|
|
3844
2706
|
getValue,
|
|
3845
2707
|
splitJsonPath
|
|
3846
2708
|
};
|
|
3847
|
-
//# sourceMappingURL=chunk-
|
|
2709
|
+
//# sourceMappingURL=chunk-MFJPOZDU.mjs.map
|