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