@dxos/echo 0.8.4-main.c85a9c8dae → 0.8.4-main.cb12b3f963
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/dist/lib/neutral/Annotation.mjs +3 -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 +21 -14
- package/dist/lib/neutral/Filter.mjs +21 -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 +7 -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-ALOGSVBP.mjs → chunk-3U5PIVPZ.mjs} +59 -4
- package/dist/lib/neutral/chunk-3U5PIVPZ.mjs.map +7 -0
- 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-5ELDDYWE.mjs → chunk-4VTRFJV3.mjs} +17 -19
- package/dist/lib/neutral/chunk-4VTRFJV3.mjs.map +7 -0
- package/dist/lib/neutral/chunk-5NR2KWDU.mjs +34 -0
- package/dist/lib/neutral/chunk-5NR2KWDU.mjs.map +7 -0
- package/dist/lib/neutral/chunk-62RJTYOZ.mjs +346 -0
- package/dist/lib/neutral/chunk-62RJTYOZ.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-OVUBTQLT.mjs → chunk-7OO5B5DD.mjs} +2 -2
- package/dist/lib/neutral/chunk-7OO5B5DD.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-ANHVGJI4.mjs → chunk-7RVZT53K.mjs} +1 -1
- package/dist/lib/neutral/{chunk-GAWKQ5DZ.mjs → chunk-AG7JS76F.mjs} +5 -5
- package/dist/lib/neutral/chunk-AG7JS76F.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-PP4DNUZU.mjs → chunk-AVPYX7FF.mjs} +1399 -2882
- package/dist/lib/neutral/chunk-AVPYX7FF.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-ZWKJ4LZJ.mjs → chunk-BCKTAKBX.mjs} +23 -51
- package/dist/lib/neutral/chunk-BCKTAKBX.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-F7KMHDPJ.mjs → chunk-GECFB2UL.mjs} +49 -31
- package/dist/lib/neutral/chunk-GECFB2UL.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-BRJSLACP.mjs → chunk-M7ET73JD.mjs} +71 -17
- package/dist/lib/neutral/chunk-M7ET73JD.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-KGV3QIRX.mjs → chunk-NCSIQP3L.mjs} +124 -17
- package/dist/lib/neutral/chunk-NCSIQP3L.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-QXF3LGN2.mjs → chunk-NGQNU3KX.mjs} +5 -3
- package/dist/lib/neutral/chunk-NGQNU3KX.mjs.map +7 -0
- package/dist/lib/neutral/chunk-PRCRETDK.mjs +36 -0
- package/dist/lib/neutral/chunk-PRCRETDK.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-AQP4QKYP.mjs → chunk-S4JXD2RO.mjs} +44 -9
- package/dist/lib/neutral/chunk-S4JXD2RO.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-W7OP5HGZ.mjs → chunk-SVEGO3DJ.mjs} +14 -10
- package/dist/lib/neutral/chunk-SVEGO3DJ.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-GFNCSK7F.mjs → chunk-TTUIJXGD.mjs} +54 -23
- package/dist/lib/neutral/chunk-TTUIJXGD.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-OMUPQMLR.mjs → chunk-V72DY6LU.mjs} +1 -1
- package/dist/lib/neutral/{chunk-T4MPQJ7X.mjs → chunk-WGMPVUUL.mjs} +6 -22
- package/dist/lib/neutral/chunk-WGMPVUUL.mjs.map +7 -0
- package/dist/lib/neutral/{chunk-O3TZFQCT.mjs → chunk-YDRLYZKW.mjs} +2 -2
- package/dist/lib/neutral/chunk-YDRLYZKW.mjs.map +7 -0
- package/dist/lib/neutral/chunk-Z25FPDXG.mjs +734 -0
- package/dist/lib/neutral/chunk-Z25FPDXG.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 +48 -38
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/testing/index.mjs +41 -35
- package/dist/lib/neutral/testing/index.mjs.map +2 -2
- 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 +15 -3
- 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 +40 -23
- package/dist/types/src/Feed.d.ts.map +1 -1
- package/dist/types/src/Filter.d.ts +33 -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 +6 -1
- 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 +57 -0
- package/dist/types/src/Migration.d.ts.map +1 -0
- package/dist/types/src/Obj.d.ts +45 -29
- 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 +11 -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 +24 -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 +2 -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/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 +3 -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.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 +24 -14
- package/src/Annotation.ts +5 -3
- package/src/Collection.ts +8 -1
- package/src/Database.ts +54 -17
- 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 +86 -36
- package/src/Filter.test.ts +90 -0
- package/src/Filter.ts +68 -3
- package/src/Format.ts +1 -1
- package/src/Hypergraph.ts +7 -2
- package/src/Json.test.ts +175 -0
- package/src/Json.ts +102 -0
- package/src/JsonSchema.ts +7 -5
- package/src/Migration.ts +94 -0
- package/src/Obj.test.ts +107 -15
- package/src/Obj.ts +166 -40
- package/src/Order.ts +2 -0
- package/src/Query.test.ts +221 -31
- package/src/Query.ts +50 -3
- package/src/Ref.ts +14 -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 +71 -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 +13 -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}/inspect.ts +2 -2
- package/src/internal/{object → Obj}/json-serializer.test.ts +8 -9
- package/src/internal/{object → Obj}/json-serializer.ts +36 -18
- 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 +137 -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 +1 -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 +0 -1
- 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.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}/ids.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/index.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/inspect.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/json-serializer.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/schema-validator.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/set-value.test.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/snapshot.d.ts +0 -0
- /package/dist/types/src/internal/{object → Obj}/typed-object.test.d.ts +0 -0
- /package/dist/types/src/internal/{ref → Ref}/index.d.ts +0 -0
- /package/dist/types/src/internal/{ref → Ref}/ref.test.d.ts +0 -0
- /package/dist/types/src/internal/{schema → Type}/compose.test.d.ts +0 -0
- /package/dist/types/src/internal/{schema → Type}/index.d.ts +0 -0
- /package/dist/types/src/internal/{schema → Type}/manipulation.d.ts +0 -0
- /package/dist/types/src/internal/{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}/ids.ts +0 -0
- /package/src/internal/{object → Obj}/index.ts +0 -0
- /package/src/internal/{object → Obj}/schema-validator.test.ts +0 -0
- /package/src/internal/{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-Z25FPDXG.mjs";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
Ref,
|
|
9
|
+
refFromEncodedReference,
|
|
10
|
+
setRefResolver
|
|
11
|
+
} from "./chunk-62RJTYOZ.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-GECFB2UL.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({
|
|
@@ -84,15 +76,7 @@ var ObjectMetaSchema = Schema2.Struct({
|
|
|
84
76
|
});
|
|
85
77
|
var getMeta = (obj) => {
|
|
86
78
|
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
|
-
});
|
|
79
|
+
invariant(metadata, "ObjectMeta not found.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 37, S: void 0, A: ["metadata", "'ObjectMeta not found.'"] });
|
|
96
80
|
return metadata;
|
|
97
81
|
};
|
|
98
82
|
var foreignKey = (source, id) => ({
|
|
@@ -102,365 +86,60 @@ var foreignKey = (source, id) => ({
|
|
|
102
86
|
var foreignKeyEquals = (a, b) => a.source === b.source && a.id === b.id;
|
|
103
87
|
var compareForeignKeys = (a, b) => intersection(getMeta(a).keys, getMeta(b).keys, foreignKeyEquals).length > 0;
|
|
104
88
|
|
|
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";
|
|
89
|
+
// src/internal/common/types/model-symbols.ts
|
|
247
90
|
var ATTR_SELF_DXN = "@dxn";
|
|
248
91
|
var SelfDXNId = /* @__PURE__ */ Symbol.for("@dxos/echo/DXN");
|
|
249
92
|
var ATTR_DELETED = "@deleted";
|
|
250
93
|
var ObjectDeletedId = /* @__PURE__ */ Symbol.for("@dxos/echo/Deleted");
|
|
251
94
|
var ObjectVersionId = /* @__PURE__ */ Symbol.for("@dxos/echo/Version");
|
|
252
95
|
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
|
-
}
|
|
96
|
+
var ATTR_RELATION_SOURCE = "@relationSource";
|
|
97
|
+
var RelationSourceId = /* @__PURE__ */ Symbol.for("@dxos/echo/RelationSource");
|
|
98
|
+
var RelationSourceDXNId = /* @__PURE__ */ Symbol.for("@dxos/echo/RelationSourceDXN");
|
|
99
|
+
var ATTR_RELATION_TARGET = "@relationTarget";
|
|
100
|
+
var RelationTargetId = /* @__PURE__ */ Symbol.for("@dxos/echo/RelationTarget");
|
|
101
|
+
var RelationTargetDXNId = /* @__PURE__ */ Symbol.for("@dxos/echo/RelationTargetDXN");
|
|
330
102
|
|
|
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
|
-
};
|
|
103
|
+
// src/internal/common/types/version.ts
|
|
104
|
+
var VersionTypeId = "~@dxos/echo/VersionTypeId";
|
|
378
105
|
|
|
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];
|
|
106
|
+
// src/internal/Annotation/sorting.ts
|
|
107
|
+
var compare = (a, b) => {
|
|
108
|
+
if (a == null) {
|
|
109
|
+
return b == null ? 0 : 1;
|
|
408
110
|
}
|
|
409
|
-
if (
|
|
410
|
-
|
|
111
|
+
if (b == null) {
|
|
112
|
+
return -1;
|
|
411
113
|
}
|
|
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;
|
|
114
|
+
return a.localeCompare(b);
|
|
429
115
|
};
|
|
430
|
-
var
|
|
431
|
-
|
|
432
|
-
|
|
116
|
+
var sortByLabel = (a, b) => compare(getLabel(a), getLabel(b));
|
|
117
|
+
var sortByTypename = (a, b) => compare(getTypename(a), getTypename(b));
|
|
118
|
+
var sort = (...comparators) => {
|
|
119
|
+
return (a, b) => {
|
|
120
|
+
for (const comparator of comparators) {
|
|
121
|
+
const result = comparator(a, b);
|
|
122
|
+
if (result !== 0) {
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return 0;
|
|
127
|
+
};
|
|
433
128
|
};
|
|
434
129
|
|
|
435
|
-
// src/internal/api/meta.ts
|
|
436
|
-
import { assertArgument
|
|
437
|
-
var
|
|
130
|
+
// src/internal/common/api/meta.ts
|
|
131
|
+
import { assertArgument, invariant as invariant2 } from "@dxos/invariant";
|
|
132
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/api/meta.ts";
|
|
438
133
|
function getMetaChecked(entity) {
|
|
439
|
-
|
|
134
|
+
assertArgument(entity, "entity", "Should be an entity.");
|
|
440
135
|
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
|
-
});
|
|
136
|
+
invariant2(meta != null, "Invalid entity.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 9, S: this, A: ["meta != null", "'Invalid entity.'"] });
|
|
450
137
|
return meta;
|
|
451
138
|
}
|
|
452
139
|
var getKeys = (entity, source) => {
|
|
453
|
-
|
|
140
|
+
assertArgument(entity, "entity", "Should be an entity.");
|
|
454
141
|
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
|
-
});
|
|
142
|
+
invariant2(meta != null, "Invalid entity.", { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 18, S: void 0, A: ["meta != null", "'Invalid entity.'"] });
|
|
464
143
|
return meta.keys.filter((key) => key.source === source);
|
|
465
144
|
};
|
|
466
145
|
var deleteKeys = (entity, source) => {
|
|
@@ -490,2413 +169,1307 @@ var removeTag = (entity, tag) => {
|
|
|
490
169
|
}
|
|
491
170
|
};
|
|
492
171
|
|
|
493
|
-
// src/internal/
|
|
494
|
-
var
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
if (result !== 0) {
|
|
510
|
-
return result;
|
|
172
|
+
// src/internal/common/proxy/symbols.ts
|
|
173
|
+
var EventId = /* @__PURE__ */ Symbol.for("@dxos/live-object/EventId");
|
|
174
|
+
var ChangeId = /* @__PURE__ */ Symbol.for("@dxos/live-object/ChangeId");
|
|
175
|
+
|
|
176
|
+
// src/internal/common/proxy/event-batch.ts
|
|
177
|
+
var eventBatchDepth = 0;
|
|
178
|
+
var pendingEventTargets = /* @__PURE__ */ new Set();
|
|
179
|
+
var batchEvents = (callback) => {
|
|
180
|
+
eventBatchDepth++;
|
|
181
|
+
try {
|
|
182
|
+
callback();
|
|
183
|
+
} finally {
|
|
184
|
+
eventBatchDepth--;
|
|
185
|
+
if (eventBatchDepth === 0) {
|
|
186
|
+
for (const target of pendingEventTargets) {
|
|
187
|
+
target[EventId]?.emit();
|
|
511
188
|
}
|
|
189
|
+
pendingEventTargets.clear();
|
|
512
190
|
}
|
|
513
|
-
|
|
514
|
-
};
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
// src/internal/api/version.ts
|
|
518
|
-
import { assertArgument as assertArgument4 } from "@dxos/invariant";
|
|
519
|
-
var unversioned = {
|
|
520
|
-
[VersionTypeId]: {},
|
|
521
|
-
versioned: false
|
|
522
|
-
};
|
|
523
|
-
var isVersion = (entity) => {
|
|
524
|
-
return entity != null && typeof entity === "object" && VersionTypeId in entity;
|
|
191
|
+
}
|
|
525
192
|
};
|
|
526
|
-
var
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
193
|
+
var emitEvent = (target) => {
|
|
194
|
+
if (eventBatchDepth > 0) {
|
|
195
|
+
pendingEventTargets.add(target);
|
|
196
|
+
} else {
|
|
197
|
+
target[EventId]?.emit();
|
|
530
198
|
}
|
|
531
|
-
return ver;
|
|
532
199
|
};
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
200
|
+
|
|
201
|
+
// src/internal/common/proxy/change-context.ts
|
|
202
|
+
var currentChangeContext = null;
|
|
203
|
+
var pendingNotificationKey = null;
|
|
204
|
+
var pendingOwnerNotifications = /* @__PURE__ */ new Set();
|
|
205
|
+
var enterChangeContext = (key) => {
|
|
206
|
+
currentChangeContext = key;
|
|
207
|
+
return () => {
|
|
208
|
+
currentChangeContext = null;
|
|
209
|
+
};
|
|
536
210
|
};
|
|
537
|
-
var
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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";
|
|
211
|
+
var isInChangeContext = (key) => {
|
|
212
|
+
return currentChangeContext === key;
|
|
213
|
+
};
|
|
214
|
+
var queueNotification = (key) => {
|
|
215
|
+
if (currentChangeContext === key) {
|
|
216
|
+
pendingNotificationKey = key;
|
|
548
217
|
}
|
|
549
|
-
return "equal";
|
|
550
218
|
};
|
|
551
|
-
var
|
|
552
|
-
|
|
219
|
+
var queueOwnerNotification = (target) => {
|
|
220
|
+
if (currentChangeContext !== null && target !== currentChangeContext) {
|
|
221
|
+
pendingOwnerNotifications.add(target);
|
|
222
|
+
}
|
|
553
223
|
};
|
|
554
|
-
var
|
|
555
|
-
|
|
556
|
-
parsed[VersionTypeId] = {};
|
|
557
|
-
return parsed;
|
|
224
|
+
var hasPendingNotifications = (key) => {
|
|
225
|
+
return pendingNotificationKey === key;
|
|
558
226
|
};
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
format: FormatAnnotationId,
|
|
564
|
-
currency: CurrencyAnnotationId
|
|
227
|
+
var clearPendingNotifications = (key) => {
|
|
228
|
+
if (pendingNotificationKey === key) {
|
|
229
|
+
pendingNotificationKey = null;
|
|
230
|
+
}
|
|
565
231
|
};
|
|
566
|
-
var
|
|
567
|
-
|
|
568
|
-
|
|
232
|
+
var executeChange = (contextKey, eventTarget, proxy, callback) => {
|
|
233
|
+
const exitContext = enterChangeContext(contextKey);
|
|
234
|
+
try {
|
|
235
|
+
batchEvents(() => callback(proxy));
|
|
236
|
+
} finally {
|
|
237
|
+
exitContext();
|
|
238
|
+
if (hasPendingNotifications(contextKey)) {
|
|
239
|
+
clearPendingNotifications(contextKey);
|
|
240
|
+
eventTarget[EventId]?.emit();
|
|
241
|
+
}
|
|
242
|
+
for (const ownerTarget of pendingOwnerNotifications) {
|
|
243
|
+
ownerTarget[EventId]?.emit();
|
|
244
|
+
}
|
|
245
|
+
pendingOwnerNotifications.clear();
|
|
246
|
+
}
|
|
569
247
|
};
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
248
|
+
|
|
249
|
+
// src/internal/common/proxy/define-hidden-property.ts
|
|
250
|
+
var defineHiddenProperty = (object, key, value2) => {
|
|
251
|
+
Object.defineProperty(object, key, {
|
|
252
|
+
enumerable: false,
|
|
253
|
+
configurable: true,
|
|
254
|
+
value: value2
|
|
255
|
+
});
|
|
575
256
|
};
|
|
576
257
|
|
|
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;
|
|
258
|
+
// src/internal/common/proxy/errors.ts
|
|
259
|
+
var MutationOutsideChangeContextError = class extends Error {
|
|
260
|
+
constructor(operation, suggestion) {
|
|
261
|
+
super(`Cannot ${operation} outside of Obj.update(). Use Obj.update(obj, (mutableObj) => { ${suggestion} }) instead.`);
|
|
262
|
+
this.name = "MutationOutsideChangeContextError";
|
|
829
263
|
}
|
|
830
264
|
};
|
|
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
|
-
}
|
|
265
|
+
var createPropertySetError = (prop) => {
|
|
266
|
+
return new MutationOutsideChangeContextError(`modify object property "${String(prop)}"`, `mutableObj.${String(prop)} = value;`);
|
|
845
267
|
};
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
var normalizeSchema = (schema) => {
|
|
849
|
-
const copy = structuredClone(schema);
|
|
850
|
-
go(copy);
|
|
851
|
-
return copy;
|
|
268
|
+
var createPropertyDeleteError = (prop) => {
|
|
269
|
+
return new MutationOutsideChangeContextError(`delete object property "${String(prop)}"`, `delete mutableObj.${String(prop)};`);
|
|
852
270
|
};
|
|
853
|
-
var
|
|
854
|
-
|
|
271
|
+
var createArrayMethodError = (method) => {
|
|
272
|
+
return new MutationOutsideChangeContextError(`call array.${method}()`, `mutableObj.array.${method}(...);`);
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// src/internal/common/proxy/json-serializer.ts
|
|
276
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
277
|
+
import { DXN } from "@dxos/keys";
|
|
278
|
+
import { deepMapValues } from "@dxos/util";
|
|
279
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/json-serializer.ts";
|
|
280
|
+
var attachTypedJsonSerializer = (obj) => {
|
|
281
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, "toJSON");
|
|
282
|
+
if (descriptor) {
|
|
855
283
|
return;
|
|
856
284
|
}
|
|
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);
|
|
285
|
+
Object.defineProperty(obj, "toJSON", {
|
|
286
|
+
value: typedJsonSerializer,
|
|
287
|
+
writable: false,
|
|
288
|
+
enumerable: false,
|
|
289
|
+
// Setting `configurable` to false breaks proxy invariants, should be fixable.
|
|
290
|
+
configurable: true
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
var typedJsonSerializer = function() {
|
|
294
|
+
const { id, ...rest } = this;
|
|
295
|
+
const result = {
|
|
296
|
+
id
|
|
297
|
+
};
|
|
298
|
+
if (this[TypeId]) {
|
|
299
|
+
result[ATTR_TYPE] = this[TypeId].toString();
|
|
882
300
|
}
|
|
883
|
-
if (
|
|
884
|
-
|
|
301
|
+
if (this[MetaId]) {
|
|
302
|
+
result[ATTR_META] = serializeMeta(this[MetaId]);
|
|
885
303
|
}
|
|
886
|
-
if (
|
|
887
|
-
|
|
304
|
+
if (this[SelfDXNId]) {
|
|
305
|
+
result[ATTR_SELF_DXN] = this[SelfDXNId].toString();
|
|
888
306
|
}
|
|
889
|
-
if (
|
|
890
|
-
|
|
307
|
+
if (this[RelationSourceDXNId]) {
|
|
308
|
+
const sourceDXN = this[RelationSourceDXNId];
|
|
309
|
+
invariant3(sourceDXN instanceof DXN, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 42, S: this, A: ["sourceDXN instanceof DXN", ""] });
|
|
310
|
+
result[ATTR_RELATION_SOURCE] = sourceDXN.toString();
|
|
891
311
|
}
|
|
892
|
-
if (
|
|
893
|
-
|
|
312
|
+
if (this[RelationTargetDXNId]) {
|
|
313
|
+
const targetDXN = this[RelationTargetDXNId];
|
|
314
|
+
invariant3(targetDXN instanceof DXN, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 47, S: this, A: ["targetDXN instanceof DXN", ""] });
|
|
315
|
+
result[ATTR_RELATION_TARGET] = targetDXN.toString();
|
|
894
316
|
}
|
|
895
|
-
|
|
896
|
-
|
|
317
|
+
Object.assign(result, serializeData(rest));
|
|
318
|
+
return result;
|
|
319
|
+
};
|
|
320
|
+
var serializeData = (data) => {
|
|
321
|
+
return deepMapValues(data, (value2, recurse) => {
|
|
322
|
+
if (Ref.isRef(value2)) {
|
|
323
|
+
return value2.noInline().encode();
|
|
324
|
+
}
|
|
325
|
+
return recurse(value2);
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
var serializeMeta = (meta) => {
|
|
329
|
+
return deepMapValues(meta, (value2, recurse) => recurse(value2));
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// src/internal/common/proxy/make-object.ts
|
|
333
|
+
import { ObjectId } from "@dxos/keys";
|
|
334
|
+
|
|
335
|
+
// src/internal/common/proxy/proxy-utils.ts
|
|
336
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
337
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/proxy-utils.ts";
|
|
338
|
+
var symbolIsProxy = /* @__PURE__ */ Symbol.for("@dxos/schema/Proxy");
|
|
339
|
+
var isProxy = (value2) => !!value2?.[symbolIsProxy];
|
|
340
|
+
var isValidProxyTarget = (value2) => {
|
|
341
|
+
if (value2 == null || value2[symbolIsProxy]) {
|
|
342
|
+
return false;
|
|
897
343
|
}
|
|
898
|
-
if (
|
|
899
|
-
|
|
344
|
+
if (Array.isArray(value2)) {
|
|
345
|
+
return true;
|
|
900
346
|
}
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
347
|
+
return typeof value2 === "object" && Object.getPrototypeOf(value2) === Object.prototype;
|
|
348
|
+
};
|
|
349
|
+
var getProxySlot = (proxy) => {
|
|
350
|
+
const value2 = proxy[symbolIsProxy];
|
|
351
|
+
invariant4(value2 instanceof ProxyHandlerSlot, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 22, S: void 0, A: ["value instanceof ProxyHandlerSlot", ""] });
|
|
352
|
+
return value2;
|
|
353
|
+
};
|
|
354
|
+
var getProxyTarget = (proxy) => {
|
|
355
|
+
return getProxySlot(proxy).target;
|
|
356
|
+
};
|
|
357
|
+
var getProxyHandler = (proxy) => {
|
|
358
|
+
return getProxySlot(proxy).handler;
|
|
359
|
+
};
|
|
360
|
+
var dangerouslySetProxyId = (obj, id) => {
|
|
361
|
+
getProxySlot(obj).target.id = id;
|
|
362
|
+
};
|
|
363
|
+
var createProxy = (target, handler) => {
|
|
364
|
+
const existingProxy = handler._proxyMap.get(target);
|
|
365
|
+
if (existingProxy) {
|
|
366
|
+
return existingProxy;
|
|
912
367
|
}
|
|
913
|
-
|
|
914
|
-
|
|
368
|
+
const proxy = new Proxy(target, new ProxyHandlerSlot(target, handler));
|
|
369
|
+
handler.init(target);
|
|
370
|
+
handler._proxyMap.set(target, proxy);
|
|
371
|
+
return proxy;
|
|
372
|
+
};
|
|
373
|
+
var ProxyHandlerSlot = class {
|
|
374
|
+
target;
|
|
375
|
+
_handler;
|
|
376
|
+
/**
|
|
377
|
+
* @param target Original object.
|
|
378
|
+
* @param _handler Handles intercepted operations.
|
|
379
|
+
*/
|
|
380
|
+
constructor(target, _handler) {
|
|
381
|
+
this.target = target;
|
|
382
|
+
this._handler = _handler;
|
|
915
383
|
}
|
|
916
|
-
|
|
917
|
-
|
|
384
|
+
get handler() {
|
|
385
|
+
invariant4(this._handler, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 71, S: this, A: ["this._handler", ""] });
|
|
386
|
+
return this._handler;
|
|
918
387
|
}
|
|
919
|
-
|
|
920
|
-
|
|
388
|
+
// TODO(burdon): Requires comment.
|
|
389
|
+
setHandler(handler) {
|
|
390
|
+
this._handler = handler;
|
|
921
391
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
392
|
+
/**
|
|
393
|
+
* Get value.
|
|
394
|
+
*/
|
|
395
|
+
get(target, prop, receiver) {
|
|
396
|
+
if (prop === symbolIsProxy) {
|
|
397
|
+
return this;
|
|
927
398
|
}
|
|
928
|
-
|
|
929
|
-
|
|
399
|
+
if (!this._handler || !this._handler.get) {
|
|
400
|
+
return Reflect.get(target, prop, receiver);
|
|
401
|
+
}
|
|
402
|
+
return this._handler.get(target, prop, receiver);
|
|
930
403
|
}
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
404
|
+
static {
|
|
405
|
+
const TRAPS = [
|
|
406
|
+
"apply",
|
|
407
|
+
"construct",
|
|
408
|
+
"defineProperty",
|
|
409
|
+
"deleteProperty",
|
|
410
|
+
"get",
|
|
411
|
+
"getOwnPropertyDescriptor",
|
|
412
|
+
"getPrototypeOf",
|
|
413
|
+
"has",
|
|
414
|
+
"isExtensible",
|
|
415
|
+
"ownKeys",
|
|
416
|
+
"preventExtensions",
|
|
417
|
+
"set",
|
|
418
|
+
"setPrototypeOf"
|
|
419
|
+
];
|
|
420
|
+
for (const trap of TRAPS) {
|
|
421
|
+
if (trap === "get") {
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
Object.defineProperty(this.prototype, trap, {
|
|
425
|
+
enumerable: false,
|
|
426
|
+
value: function(...args) {
|
|
427
|
+
if (!this._handler || !this._handler[trap]) {
|
|
428
|
+
return Reflect[trap](...args);
|
|
429
|
+
}
|
|
430
|
+
return this._handler[trap].apply(this._handler, args);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
}
|
|
935
434
|
}
|
|
936
435
|
};
|
|
937
436
|
|
|
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";
|
|
437
|
+
// src/internal/common/proxy/typed-handler.ts
|
|
438
|
+
import * as Schema4 from "effect/Schema";
|
|
439
|
+
import * as SchemaAST3 from "effect/SchemaAST";
|
|
961
440
|
import { Event } from "@dxos/async";
|
|
962
441
|
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
|
-
}
|
|
442
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
|
443
|
+
|
|
444
|
+
// src/internal/common/proxy/ownership.ts
|
|
445
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
446
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/ownership.ts";
|
|
447
|
+
var EchoOwner = /* @__PURE__ */ Symbol.for("@dxos/echo/Owner");
|
|
448
|
+
var getRawTarget = (value2) => {
|
|
449
|
+
return isProxy(value2) ? getProxyTarget(value2) : value2;
|
|
975
450
|
};
|
|
976
|
-
var
|
|
977
|
-
return
|
|
978
|
-
$id: JSON_SCHEMA_ECHO_REF_ID,
|
|
979
|
-
reference: {
|
|
980
|
-
schema: {
|
|
981
|
-
$ref: DXN4.fromTypename(typename).toString()
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
};
|
|
451
|
+
var getOwner = (value2) => {
|
|
452
|
+
return value2?.[EchoOwner];
|
|
985
453
|
};
|
|
986
|
-
var
|
|
987
|
-
|
|
988
|
-
return void 0;
|
|
989
|
-
}
|
|
990
|
-
return {
|
|
991
|
-
typename: ast.annotations[ReferenceAnnotationId].typename,
|
|
992
|
-
version: ast.annotations[ReferenceAnnotationId].version
|
|
993
|
-
};
|
|
454
|
+
var setMetaOwner = (metaTarget, parent) => {
|
|
455
|
+
defineHiddenProperty(metaTarget, EchoOwner, parent);
|
|
994
456
|
};
|
|
995
|
-
var
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
if (annotation == null) {
|
|
1000
|
-
throw new Error("Reference target must be an ECHO schema.");
|
|
457
|
+
var setOwnerRecursive = (value2, owner, options = {}) => {
|
|
458
|
+
const { visited = /* @__PURE__ */ new Set(), depth = 0, allowedPreviousOwner } = options;
|
|
459
|
+
if (value2 == null || typeof value2 !== "object") {
|
|
460
|
+
return;
|
|
1001
461
|
}
|
|
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.");
|
|
462
|
+
const actualValue = getRawTarget(value2);
|
|
463
|
+
if (visited.has(actualValue)) {
|
|
464
|
+
return;
|
|
1017
465
|
}
|
|
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.");
|
|
466
|
+
visited.add(actualValue);
|
|
467
|
+
const existingOwner = getOwner(actualValue);
|
|
468
|
+
const isRootEchoObject = EventId in actualValue;
|
|
469
|
+
let newAllowedPreviousOwner = allowedPreviousOwner;
|
|
470
|
+
if (isRootEchoObject && depth === 0) {
|
|
471
|
+
newAllowedPreviousOwner = actualValue;
|
|
1038
472
|
}
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
473
|
+
if (!isRootEchoObject) {
|
|
474
|
+
const ownershipAllowed = existingOwner == null || existingOwner === owner || existingOwner === newAllowedPreviousOwner;
|
|
475
|
+
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.'"] });
|
|
476
|
+
}
|
|
477
|
+
defineHiddenProperty(actualValue, EchoOwner, owner);
|
|
478
|
+
const recursiveOptions = {
|
|
479
|
+
visited,
|
|
480
|
+
depth: depth + 1,
|
|
481
|
+
allowedPreviousOwner: newAllowedPreviousOwner
|
|
1045
482
|
};
|
|
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
|
-
});
|
|
483
|
+
if (Array.isArray(actualValue)) {
|
|
484
|
+
for (const item of actualValue) {
|
|
485
|
+
if (isValidProxyTarget(item) || isProxy(item)) {
|
|
486
|
+
setOwnerRecursive(item, owner, recursiveOptions);
|
|
487
|
+
}
|
|
1076
488
|
}
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
typename: typename ?? "",
|
|
1086
|
-
version: version2
|
|
489
|
+
} else {
|
|
490
|
+
for (const key in actualValue) {
|
|
491
|
+
if (Object.prototype.hasOwnProperty.call(actualValue, key)) {
|
|
492
|
+
const nested = actualValue[key];
|
|
493
|
+
if (isValidProxyTarget(nested) || isProxy(nested)) {
|
|
494
|
+
setOwnerRecursive(nested, owner, recursiveOptions);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
1087
497
|
}
|
|
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
498
|
}
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
return this.#dxn;
|
|
499
|
+
};
|
|
500
|
+
var traverseObjectGraph = (value2, visitor, visited = /* @__PURE__ */ new Set()) => {
|
|
501
|
+
if (value2 == null || typeof value2 !== "object") {
|
|
502
|
+
return false;
|
|
1115
503
|
}
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
get isAvailable() {
|
|
1120
|
-
return this.#target !== void 0 || this.#resolver !== void 0;
|
|
504
|
+
const actualValue = getRawTarget(value2);
|
|
505
|
+
if (visited.has(actualValue)) {
|
|
506
|
+
return false;
|
|
1121
507
|
}
|
|
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);
|
|
508
|
+
visited.add(actualValue);
|
|
509
|
+
if (visitor(actualValue)) {
|
|
510
|
+
return true;
|
|
1139
511
|
}
|
|
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");
|
|
512
|
+
if (Array.isArray(actualValue)) {
|
|
513
|
+
for (const item of actualValue) {
|
|
514
|
+
if (traverseObjectGraph(item, visitor, visited)) {
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
1159
517
|
}
|
|
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()})`;
|
|
518
|
+
} else {
|
|
519
|
+
for (const key in actualValue) {
|
|
520
|
+
if (Object.prototype.hasOwnProperty.call(actualValue, key)) {
|
|
521
|
+
if (traverseObjectGraph(actualValue[key], visitor, visited)) {
|
|
522
|
+
return true;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
1210
525
|
}
|
|
1211
|
-
return `Ref(${this.#dxn.toString()})`;
|
|
1212
526
|
}
|
|
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());
|
|
527
|
+
return false;
|
|
528
|
+
};
|
|
529
|
+
var wouldCreateCycle = (targetRoot, value2) => traverseObjectGraph(value2, (v) => v === targetRoot);
|
|
530
|
+
var hasForeignOwner = (value2, target) => traverseObjectGraph(value2, (v) => {
|
|
531
|
+
const owner = getOwner(v);
|
|
532
|
+
if (owner != null && owner !== target) {
|
|
533
|
+
return true;
|
|
1225
534
|
}
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
return that instanceof _RefImpl && this.#dxn.toString() === that.dxn.toString();
|
|
535
|
+
if (EventId in v && v !== target) {
|
|
536
|
+
return true;
|
|
1229
537
|
}
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
}
|
|
1238
|
-
/**
|
|
1239
|
-
* @internal
|
|
1240
|
-
*/
|
|
1241
|
-
_getSavedTarget() {
|
|
1242
|
-
return this.#target;
|
|
538
|
+
return false;
|
|
539
|
+
});
|
|
540
|
+
var MAX_OWNER_DEPTH = 100;
|
|
541
|
+
var getEchoRoot = (target, depth = 0) => {
|
|
542
|
+
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'"] });
|
|
543
|
+
if (KindId in target) {
|
|
544
|
+
return target;
|
|
1243
545
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
546
|
+
const owner = getOwner(target);
|
|
547
|
+
if (owner) {
|
|
548
|
+
return getEchoRoot(owner, depth + 1);
|
|
1246
549
|
}
|
|
550
|
+
return target;
|
|
1247
551
|
};
|
|
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);
|
|
552
|
+
var notifyOwnerChain = (target) => {
|
|
553
|
+
const owner = getOwner(target);
|
|
554
|
+
if (owner) {
|
|
555
|
+
queueOwnerNotification(getEchoRoot(owner));
|
|
556
|
+
notifyOwnerChain(owner);
|
|
1280
557
|
}
|
|
1281
|
-
return ref;
|
|
1282
558
|
};
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
559
|
+
|
|
560
|
+
// src/internal/common/proxy/proxy-types.ts
|
|
561
|
+
var objectData = /* @__PURE__ */ Symbol.for("@dxos/live-object/objectData");
|
|
562
|
+
|
|
563
|
+
// src/internal/common/proxy/reactive-array.ts
|
|
564
|
+
var checkArrayMutationAllowed = (arr, method) => {
|
|
565
|
+
const target = isProxy(arr) ? getProxyTarget(arr) : arr;
|
|
566
|
+
const echoRoot = getEchoRoot(target);
|
|
567
|
+
const isInitialized = echoRoot[ChangeId] === true || EventId in echoRoot;
|
|
568
|
+
if (!isInitialized) {
|
|
569
|
+
return;
|
|
1289
570
|
}
|
|
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;
|
|
571
|
+
if (!isInChangeContext(echoRoot)) {
|
|
572
|
+
throw createArrayMethodError(method);
|
|
1303
573
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
}
|
|
1309
|
-
return this.objects.get(id);
|
|
574
|
+
};
|
|
575
|
+
var ReactiveArray = class extends Array {
|
|
576
|
+
static get [Symbol.species]() {
|
|
577
|
+
return Array;
|
|
1310
578
|
}
|
|
1311
|
-
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1314
|
-
|
|
579
|
+
static {
|
|
580
|
+
const BATCHED_METHODS = [
|
|
581
|
+
"push",
|
|
582
|
+
"pop",
|
|
583
|
+
"shift",
|
|
584
|
+
"unshift",
|
|
585
|
+
"splice",
|
|
586
|
+
"sort",
|
|
587
|
+
"reverse"
|
|
588
|
+
];
|
|
589
|
+
for (const method of BATCHED_METHODS) {
|
|
590
|
+
Object.defineProperty(this.prototype, method, {
|
|
591
|
+
enumerable: false,
|
|
592
|
+
value: function(...args) {
|
|
593
|
+
checkArrayMutationAllowed(this, method);
|
|
594
|
+
let result;
|
|
595
|
+
batchEvents(() => {
|
|
596
|
+
result = Array.prototype[method].apply(this, args);
|
|
597
|
+
});
|
|
598
|
+
return result;
|
|
599
|
+
}
|
|
600
|
+
});
|
|
1315
601
|
}
|
|
1316
|
-
return this.objects.get(id);
|
|
1317
|
-
}
|
|
1318
|
-
async resolveSchema(dxn) {
|
|
1319
|
-
return this.schemas.get(dxn.toString());
|
|
1320
602
|
}
|
|
1321
603
|
};
|
|
1322
604
|
|
|
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
|
-
},
|
|
605
|
+
// src/internal/common/proxy/schema-validator.ts
|
|
606
|
+
import * as Schema3 from "effect/Schema";
|
|
607
|
+
import * as SchemaAST2 from "effect/SchemaAST";
|
|
608
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
609
|
+
import { log } from "@dxos/log";
|
|
610
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/schema-validator.ts";
|
|
611
|
+
var SchemaValidator = class {
|
|
1338
612
|
/**
|
|
1339
|
-
*
|
|
613
|
+
* Recursively check that schema specifies constructions we can handle.
|
|
614
|
+
* Validates there are no ambiguous discriminated union types.
|
|
1340
615
|
*/
|
|
1341
|
-
|
|
1342
|
-
const
|
|
1343
|
-
if (
|
|
1344
|
-
|
|
616
|
+
static validateSchema(schema) {
|
|
617
|
+
const visitAll = (nodes) => nodes.forEach((node) => this.validateSchema(Schema3.make(node)));
|
|
618
|
+
if (SchemaAST2.isUnion(schema.ast)) {
|
|
619
|
+
const typeAstList = schema.ast.types.filter((type) => SchemaAST2.isTypeLiteral(type));
|
|
620
|
+
if (typeAstList.length > 1) {
|
|
621
|
+
getTypeDiscriminators(typeAstList);
|
|
622
|
+
}
|
|
623
|
+
visitAll(typeAstList);
|
|
624
|
+
} else if (SchemaAST2.isTupleType(schema.ast)) {
|
|
625
|
+
const positionalTypes = schema.ast.elements.map((t) => t.type);
|
|
626
|
+
const allTypes = positionalTypes.concat(schema.ast.rest.map((t) => t.type));
|
|
627
|
+
visitAll(allTypes);
|
|
628
|
+
} else if (SchemaAST2.isTypeLiteral(schema.ast)) {
|
|
629
|
+
visitAll(SchemaAST2.getPropertySignatures(schema.ast).map((p) => p.type));
|
|
1345
630
|
}
|
|
1346
631
|
}
|
|
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;
|
|
632
|
+
static hasTypeAnnotation(rootObjectSchema, property, annotation) {
|
|
633
|
+
try {
|
|
634
|
+
let type = this.getPropertySchema(rootObjectSchema, [
|
|
635
|
+
property
|
|
636
|
+
]);
|
|
637
|
+
if (SchemaAST2.isTupleType(type.ast)) {
|
|
638
|
+
type = this.getPropertySchema(rootObjectSchema, [
|
|
639
|
+
property,
|
|
640
|
+
"0"
|
|
641
|
+
]);
|
|
1394
642
|
}
|
|
643
|
+
return type.ast.annotations[annotation] != null;
|
|
644
|
+
} catch {
|
|
1395
645
|
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
646
|
}
|
|
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
647
|
}
|
|
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));
|
|
648
|
+
static getPropertySchema(rootObjectSchema, propertyPath, getProperty = () => null) {
|
|
649
|
+
let schema = rootObjectSchema;
|
|
650
|
+
for (let i = 0; i < propertyPath.length; i++) {
|
|
651
|
+
const propertyName = propertyPath[i];
|
|
652
|
+
const tupleAst = unwrapArray(schema.ast);
|
|
653
|
+
if (tupleAst != null) {
|
|
654
|
+
schema = getArrayElementSchema(tupleAst, propertyName);
|
|
655
|
+
} else {
|
|
656
|
+
const propertyType = getPropertyType(schema.ast, propertyName.toString(), (propertyName2) => getProperty([
|
|
657
|
+
...propertyPath.slice(0, i),
|
|
658
|
+
propertyName2
|
|
659
|
+
]));
|
|
660
|
+
if (propertyType == null) {
|
|
661
|
+
log.warn("unknown property", {
|
|
662
|
+
path: propertyPath,
|
|
663
|
+
property: propertyName
|
|
664
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 60, S: this });
|
|
665
|
+
continue;
|
|
1538
666
|
}
|
|
1539
|
-
|
|
1540
|
-
}
|
|
1541
|
-
case "null": {
|
|
1542
|
-
result = Schema9.Null;
|
|
1543
|
-
break;
|
|
667
|
+
schema = Schema3.make(propertyType).annotations(propertyType.annotations);
|
|
1544
668
|
}
|
|
1545
669
|
}
|
|
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
|
-
}));
|
|
670
|
+
return schema;
|
|
1561
671
|
}
|
|
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
|
-
});
|
|
672
|
+
static getTargetPropertySchema(target, prop) {
|
|
673
|
+
const schema = target[SchemaId];
|
|
674
|
+
invariant6(schema, "target has no schema", { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 73, S: this, A: ["schema", "'target has no schema'"] });
|
|
675
|
+
const arrayAst = unwrapArray(schema.ast);
|
|
676
|
+
if (arrayAst != null) {
|
|
677
|
+
return getArrayElementSchema(arrayAst, prop);
|
|
1629
678
|
}
|
|
679
|
+
const propertyType = getPropertyType(schema.ast, prop.toString(), (prop2) => target[prop2]);
|
|
680
|
+
if (propertyType == null) {
|
|
681
|
+
return Schema3.Any;
|
|
682
|
+
}
|
|
683
|
+
invariant6(propertyType, `invalid property: ${prop.toString()}`, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 82, S: this, A: ["propertyType", "`invalid property: ${prop.toString()}`"] });
|
|
684
|
+
return Schema3.make(propertyType);
|
|
1630
685
|
}
|
|
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
686
|
};
|
|
1667
|
-
var
|
|
1668
|
-
const
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
echoAnnotations[key] = annotations4[annotationId];
|
|
1673
|
-
}
|
|
687
|
+
var getArrayElementSchema = (tupleAst, property) => {
|
|
688
|
+
const elementIndex = typeof property === "string" ? parseInt(property, 10) : Number.NaN;
|
|
689
|
+
if (Number.isNaN(elementIndex)) {
|
|
690
|
+
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)}`"] });
|
|
691
|
+
return Schema3.Number;
|
|
1674
692
|
}
|
|
1675
|
-
if (
|
|
1676
|
-
|
|
693
|
+
if (elementIndex < tupleAst.elements.length) {
|
|
694
|
+
const elementType = tupleAst.elements[elementIndex].type;
|
|
695
|
+
return Schema3.make(elementType).annotations(elementType.annotations);
|
|
1677
696
|
}
|
|
1678
|
-
const
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
697
|
+
const restType = tupleAst.rest;
|
|
698
|
+
return Schema3.make(restType[0].type).annotations(restType[0].annotations);
|
|
699
|
+
};
|
|
700
|
+
var flattenUnion = (typeAst) => SchemaAST2.isUnion(typeAst) ? typeAst.types.flatMap(flattenUnion) : [
|
|
701
|
+
typeAst
|
|
702
|
+
];
|
|
703
|
+
var getProperties = (typeAst, getTargetPropertyFn) => {
|
|
704
|
+
const astCandidates = flattenUnion(typeAst);
|
|
705
|
+
const typeAstList = astCandidates.filter((type) => SchemaAST2.isTypeLiteral(type));
|
|
706
|
+
if (typeAstList.length === 0) {
|
|
707
|
+
return [];
|
|
1682
708
|
}
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
if (value2 != null) {
|
|
1686
|
-
schemaFields[key] = value2;
|
|
1687
|
-
}
|
|
709
|
+
if (typeAstList.length === 1) {
|
|
710
|
+
return SchemaAST2.getPropertySignatures(typeAstList[0]);
|
|
1688
711
|
}
|
|
1689
|
-
|
|
712
|
+
const typeDiscriminators = getTypeDiscriminators(typeAstList);
|
|
713
|
+
const targetPropertyValue = getTargetPropertyFn(String(typeDiscriminators[0].name));
|
|
714
|
+
const typeIndex = typeDiscriminators.findIndex((p) => targetPropertyValue === p.type.literal);
|
|
715
|
+
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'"] });
|
|
716
|
+
return SchemaAST2.getPropertySignatures(typeAstList[typeIndex]);
|
|
1690
717
|
};
|
|
1691
|
-
var
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
const id = schema?.echo?.type?.schemaId;
|
|
1696
|
-
if (ObjectId4.isValid(id)) {
|
|
1697
|
-
return DXN5.fromLocalObjectId(id).toString();
|
|
1698
|
-
}
|
|
718
|
+
var getPropertyType = (ast, propertyName, getTargetPropertyFn) => {
|
|
719
|
+
const anyOrObject = unwrapAst(ast, (candidate) => SchemaAST2.isAnyKeyword(candidate) || SchemaAST2.isObjectKeyword(candidate));
|
|
720
|
+
if (anyOrObject != null) {
|
|
721
|
+
return ast;
|
|
1699
722
|
}
|
|
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;
|
|
723
|
+
const typeOrDiscriminatedUnion = unwrapAst(ast, (t) => {
|
|
724
|
+
return SchemaAST2.isTypeLiteral(t) || SchemaAST2.isUnion(t) && t.types.some((t2) => SchemaAST2.isTypeLiteral(t2));
|
|
725
|
+
});
|
|
726
|
+
if (typeOrDiscriminatedUnion == null) {
|
|
727
|
+
return null;
|
|
1717
728
|
}
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
typename: schema.echo.type.typename,
|
|
1722
|
-
version: schema.echo.type.version
|
|
1723
|
-
};
|
|
729
|
+
const targetProperty = getProperties(typeOrDiscriminatedUnion, getTargetPropertyFn).find((p) => p.name === propertyName);
|
|
730
|
+
if (targetProperty != null) {
|
|
731
|
+
return unwrapAst(targetProperty.type);
|
|
1724
732
|
}
|
|
1725
|
-
|
|
733
|
+
const indexSignatureType = unwrapAst(ast, SchemaAST2.isTypeLiteral);
|
|
734
|
+
if (indexSignatureType && SchemaAST2.isTypeLiteral(indexSignatureType) && indexSignatureType.indexSignatures.length > 0) {
|
|
735
|
+
return unwrapAst(indexSignatureType.indexSignatures[0].type);
|
|
736
|
+
}
|
|
737
|
+
return null;
|
|
738
|
+
};
|
|
739
|
+
var getTypeDiscriminators = (typeAstList) => {
|
|
740
|
+
const discriminatorPropCandidates = typeAstList.flatMap(SchemaAST2.getPropertySignatures).filter((p) => SchemaAST2.isLiteral(p.type));
|
|
741
|
+
const propertyName = discriminatorPropCandidates[0].name;
|
|
742
|
+
const isValidDiscriminator = discriminatorPropCandidates.every((p) => p.name === propertyName && !p.isOptional);
|
|
743
|
+
const everyTypeHasDiscriminator = discriminatorPropCandidates.length === typeAstList.length;
|
|
744
|
+
const isDiscriminatedUnion = isValidDiscriminator && everyTypeHasDiscriminator;
|
|
745
|
+
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'"] });
|
|
746
|
+
return discriminatorPropCandidates;
|
|
1726
747
|
};
|
|
1727
|
-
var
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
748
|
+
var unwrapAst = (rootAst, predicate) => {
|
|
749
|
+
let ast = rootAst;
|
|
750
|
+
while (ast != null) {
|
|
751
|
+
if (predicate?.(ast)) {
|
|
752
|
+
return ast;
|
|
753
|
+
}
|
|
754
|
+
if (SchemaAST2.isUnion(ast)) {
|
|
755
|
+
const next = ast.types.find((t) => predicate != null && predicate(t) || SchemaAST2.isSuspend(t));
|
|
756
|
+
if (next != null) {
|
|
757
|
+
ast = next;
|
|
758
|
+
continue;
|
|
1734
759
|
}
|
|
1735
760
|
}
|
|
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];
|
|
761
|
+
if (SchemaAST2.isSuspend(ast)) {
|
|
762
|
+
ast = ast.f();
|
|
763
|
+
} else {
|
|
764
|
+
return predicate == null ? ast : null;
|
|
1757
765
|
}
|
|
1758
766
|
}
|
|
1759
|
-
return
|
|
1760
|
-
};
|
|
1761
|
-
var makeAnnotatedRefinement = (ast, annotations4) => {
|
|
1762
|
-
return new SchemaAST6.Refinement(ast, () => Option2.none(), annotations4);
|
|
767
|
+
return null;
|
|
1763
768
|
};
|
|
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;
|
|
769
|
+
var unwrapArray = (ast) => unwrapAst(ast, SchemaAST2.isTupleType);
|
|
770
|
+
var checkIdNotPresentOnSchema = (schema) => {
|
|
771
|
+
invariant6(SchemaAST2.isTypeLiteral(schema.ast), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 184, S: void 0, A: ["SchemaAST.isTypeLiteral(schema.ast)", ""] });
|
|
772
|
+
const idProperty = SchemaAST2.getPropertySignatures(schema.ast).find((prop) => prop.name === "id");
|
|
773
|
+
if (idProperty != null) {
|
|
774
|
+
throw new Error('"id" property name is reserved');
|
|
775
|
+
}
|
|
1793
776
|
};
|
|
1794
777
|
|
|
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);
|
|
778
|
+
// src/internal/common/proxy/typed-handler.ts
|
|
779
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/common/proxy/typed-handler.ts";
|
|
780
|
+
var deepCopy = (value2, visited = /* @__PURE__ */ new Map()) => {
|
|
781
|
+
if (value2 == null || typeof value2 !== "object") {
|
|
782
|
+
return value2;
|
|
1879
783
|
}
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
};
|
|
1884
|
-
var clearPendingNotifications = (key) => {
|
|
1885
|
-
if (pendingNotificationKey === key) {
|
|
1886
|
-
pendingNotificationKey = null;
|
|
784
|
+
const actualValue = getRawTarget(value2);
|
|
785
|
+
if (visited.has(actualValue)) {
|
|
786
|
+
return visited.get(actualValue);
|
|
1887
787
|
}
|
|
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();
|
|
788
|
+
if (actualValue instanceof ReactiveArray) {
|
|
789
|
+
const copy2 = new ReactiveArray();
|
|
790
|
+
visited.set(actualValue, copy2);
|
|
791
|
+
for (const item of actualValue) {
|
|
792
|
+
copy2.push(deepCopy(item, visited));
|
|
1901
793
|
}
|
|
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();
|
|
794
|
+
copyHiddenProperties(actualValue, copy2);
|
|
795
|
+
return copy2;
|
|
1976
796
|
}
|
|
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();
|
|
797
|
+
const proto = Object.getPrototypeOf(actualValue);
|
|
798
|
+
if (proto !== Object.prototype && proto !== Array.prototype && proto !== null) {
|
|
799
|
+
return value2;
|
|
1989
800
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
if (Ref.isRef(value2)) {
|
|
1996
|
-
return value2.noInline().encode();
|
|
801
|
+
if (Array.isArray(actualValue)) {
|
|
802
|
+
const copy2 = new ReactiveArray();
|
|
803
|
+
visited.set(actualValue, copy2);
|
|
804
|
+
for (const item of actualValue) {
|
|
805
|
+
copy2.push(deepCopy(item, visited));
|
|
1997
806
|
}
|
|
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;
|
|
807
|
+
return copy2;
|
|
2016
808
|
}
|
|
2017
|
-
|
|
2018
|
-
|
|
809
|
+
const copy = {};
|
|
810
|
+
visited.set(actualValue, copy);
|
|
811
|
+
for (const key of Object.keys(actualValue)) {
|
|
812
|
+
copy[key] = deepCopy(actualValue[key], visited);
|
|
2019
813
|
}
|
|
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;
|
|
814
|
+
copyHiddenProperties(actualValue, copy);
|
|
815
|
+
return copy;
|
|
2043
816
|
};
|
|
2044
|
-
var
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
817
|
+
var copyHiddenProperties = (source, target) => {
|
|
818
|
+
if (SchemaId in source) {
|
|
819
|
+
defineHiddenProperty(target, SchemaId, source[SchemaId]);
|
|
820
|
+
}
|
|
821
|
+
if (TypeId in source) {
|
|
822
|
+
defineHiddenProperty(target, TypeId, source[TypeId]);
|
|
2048
823
|
}
|
|
2049
|
-
const proxy = new Proxy(target, new ProxyHandlerSlot(target, handler));
|
|
2050
|
-
handler.init(target);
|
|
2051
|
-
handler._proxyMap.set(target, proxy);
|
|
2052
|
-
return proxy;
|
|
2053
824
|
};
|
|
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;
|
|
825
|
+
var TypedReactiveHandler = class _TypedReactiveHandler {
|
|
826
|
+
static instance = new _TypedReactiveHandler();
|
|
827
|
+
_proxyMap = /* @__PURE__ */ new WeakMap();
|
|
828
|
+
_inSet = false;
|
|
829
|
+
constructor() {
|
|
2064
830
|
}
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
831
|
+
init(target) {
|
|
832
|
+
invariant7(typeof target === "object" && target !== null, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 99, S: this, A: ["typeof target === 'object' && target !== null", ""] });
|
|
833
|
+
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'"] });
|
|
834
|
+
const hasOwner = !!getOwner(target);
|
|
835
|
+
if (!(EventId in target) && !hasOwner) {
|
|
836
|
+
defineHiddenProperty(target, EventId, new Event());
|
|
837
|
+
}
|
|
838
|
+
defineHiddenProperty(target, ObjectDeletedId, false);
|
|
839
|
+
if (!hasOwner && !(ChangeId in target)) {
|
|
840
|
+
defineHiddenProperty(target, ChangeId, true);
|
|
841
|
+
}
|
|
842
|
+
if (!hasOwner) {
|
|
843
|
+
for (const key in target) {
|
|
844
|
+
if (target[symbolIsProxy]) {
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
let value2 = target[key];
|
|
848
|
+
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
849
|
+
if (hasForeignOwner(value2, target)) {
|
|
850
|
+
value2 = deepCopy(value2);
|
|
851
|
+
target[key] = value2;
|
|
852
|
+
}
|
|
853
|
+
setOwnerRecursive(value2, target);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
Object.defineProperty(target, inspectCustom, {
|
|
858
|
+
enumerable: false,
|
|
859
|
+
configurable: true,
|
|
860
|
+
value: this._inspect.bind(target)
|
|
2074
861
|
});
|
|
2075
|
-
return this._handler;
|
|
2076
862
|
}
|
|
2077
|
-
// TODO(burdon): Requires comment.
|
|
2078
|
-
setHandler(handler) {
|
|
2079
|
-
this._handler = handler;
|
|
2080
|
-
}
|
|
2081
|
-
/**
|
|
2082
|
-
* Get value.
|
|
2083
|
-
*/
|
|
2084
863
|
get(target, prop, receiver) {
|
|
2085
|
-
|
|
2086
|
-
|
|
864
|
+
switch (prop) {
|
|
865
|
+
// TODO(burdon): Remove?
|
|
866
|
+
case objectData: {
|
|
867
|
+
return toJSON(target);
|
|
868
|
+
}
|
|
869
|
+
case ChangeId: {
|
|
870
|
+
if (target[ChangeId] !== true) {
|
|
871
|
+
return void 0;
|
|
872
|
+
}
|
|
873
|
+
return (callback) => executeChange(target, target, receiver, callback);
|
|
874
|
+
}
|
|
2087
875
|
}
|
|
2088
|
-
if (
|
|
876
|
+
if (Object.getOwnPropertyDescriptor(target, prop)?.get) {
|
|
2089
877
|
return Reflect.get(target, prop, receiver);
|
|
2090
878
|
}
|
|
2091
|
-
|
|
879
|
+
const value2 = Reflect.get(target, prop, receiver);
|
|
880
|
+
if (isValidProxyTarget(value2)) {
|
|
881
|
+
return createProxy(value2, this);
|
|
882
|
+
}
|
|
883
|
+
return value2;
|
|
2092
884
|
}
|
|
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);
|
|
885
|
+
set(target, prop, value2, receiver) {
|
|
886
|
+
const echoRoot = getEchoRoot(target);
|
|
887
|
+
const isInitialized = ChangeId in echoRoot || EventId in echoRoot;
|
|
888
|
+
const isSymbolProp = typeof prop === "symbol";
|
|
889
|
+
if (isInitialized && !isSymbolProp && !isInChangeContext(echoRoot)) {
|
|
890
|
+
throw new Error(`Cannot modify object property "${String(prop)}" outside of Obj.update(). Use Obj.update(obj, (mutableObj) => { mutableObj.property = value; }) instead.`);
|
|
891
|
+
}
|
|
892
|
+
let result = false;
|
|
893
|
+
this._inSet = true;
|
|
894
|
+
try {
|
|
895
|
+
batchEvents(() => {
|
|
896
|
+
const { echoRoot: _, preparedValue } = this._prepareValueForAssignment(target, prop, value2);
|
|
897
|
+
result = Reflect.set(target, prop, preparedValue, receiver);
|
|
898
|
+
if (isInitialized) {
|
|
899
|
+
queueNotification(echoRoot);
|
|
900
|
+
notifyOwnerChain(target);
|
|
2120
901
|
}
|
|
2121
902
|
});
|
|
903
|
+
} finally {
|
|
904
|
+
this._inSet = false;
|
|
2122
905
|
}
|
|
906
|
+
return result;
|
|
2123
907
|
}
|
|
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;
|
|
2154
|
-
}
|
|
2155
|
-
visited.add(actualValue);
|
|
2156
|
-
const existingOwner = getOwner(actualValue);
|
|
2157
|
-
const isRootEchoObject = EventId in actualValue;
|
|
2158
|
-
let newAllowedPreviousOwner = allowedPreviousOwner;
|
|
2159
|
-
if (isRootEchoObject && depth === 0) {
|
|
2160
|
-
newAllowedPreviousOwner = actualValue;
|
|
908
|
+
ownKeys(target) {
|
|
909
|
+
return Reflect.ownKeys(target);
|
|
2161
910
|
}
|
|
2162
|
-
|
|
2163
|
-
const
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
}
|
|
911
|
+
deleteProperty(target, property) {
|
|
912
|
+
const echoRoot = getEchoRoot(target);
|
|
913
|
+
const isInitialized = echoRoot[ChangeId] === true || EventId in echoRoot;
|
|
914
|
+
const isSymbolProp = typeof property === "symbol";
|
|
915
|
+
if (isInitialized && !isSymbolProp && !isInChangeContext(echoRoot)) {
|
|
916
|
+
throw createPropertyDeleteError(property);
|
|
917
|
+
}
|
|
918
|
+
const result = Reflect.deleteProperty(target, property);
|
|
919
|
+
if (isInitialized) {
|
|
920
|
+
queueNotification(echoRoot);
|
|
921
|
+
}
|
|
922
|
+
return result;
|
|
2173
923
|
}
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
924
|
+
defineProperty(target, property, attributes) {
|
|
925
|
+
const echoRoot = getEchoRoot(target);
|
|
926
|
+
const isInitialized = ChangeId in echoRoot || EventId in echoRoot;
|
|
927
|
+
const isSymbolProp = typeof property === "symbol";
|
|
928
|
+
if (isInitialized && !isSymbolProp && !isInChangeContext(echoRoot)) {
|
|
929
|
+
throw new Error(`Cannot modify object property "${String(property)}" outside of Obj.update(). Use Obj.update(obj, (mutableObj) => { mutableObj.property = value; }) instead.`);
|
|
930
|
+
}
|
|
931
|
+
const { echoRoot: _, preparedValue } = this._prepareValueForAssignment(target, property, attributes.value);
|
|
932
|
+
const result = Reflect.defineProperty(target, property, {
|
|
933
|
+
...attributes,
|
|
934
|
+
value: preparedValue
|
|
935
|
+
});
|
|
936
|
+
if (!this._inSet && isInitialized) {
|
|
937
|
+
queueNotification(echoRoot);
|
|
2185
938
|
}
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
939
|
+
return result;
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* Prepare a value for assignment to a typed object property.
|
|
943
|
+
* Handles cycle detection, copy-on-assign, array conversion, validation, and ownership.
|
|
944
|
+
*/
|
|
945
|
+
_prepareValueForAssignment(target, prop, value2) {
|
|
946
|
+
const echoRoot = getEchoRoot(target);
|
|
947
|
+
if (prop === ParentId) {
|
|
948
|
+
return {
|
|
949
|
+
echoRoot,
|
|
950
|
+
preparedValue: value2
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
954
|
+
if (wouldCreateCycle(echoRoot, value2)) {
|
|
955
|
+
throw new Error("Cannot create cycles in typed object graph. Consider using Ref for circular references.");
|
|
2193
956
|
}
|
|
2194
957
|
}
|
|
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;
|
|
958
|
+
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
959
|
+
const actualValue = getRawTarget(value2);
|
|
960
|
+
const isRootEchoObject = EventId in actualValue;
|
|
961
|
+
if (isRootEchoObject) {
|
|
962
|
+
throw new Error("Object references must be wrapped with `Ref.make`");
|
|
2213
963
|
}
|
|
2214
964
|
}
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
}
|
|
965
|
+
if (isValidProxyTarget(value2) || isProxy(value2)) {
|
|
966
|
+
const actualValue = getRawTarget(value2);
|
|
967
|
+
const existingOwner = getOwner(actualValue);
|
|
968
|
+
if (existingOwner != null && existingOwner !== echoRoot) {
|
|
969
|
+
value2 = deepCopy(value2);
|
|
2221
970
|
}
|
|
2222
971
|
}
|
|
972
|
+
if (Array.isArray(value2) && !(value2 instanceof ReactiveArray)) {
|
|
973
|
+
value2 = ReactiveArray.from(value2);
|
|
974
|
+
}
|
|
975
|
+
const validatedValue = this._validateValue(target, prop, value2);
|
|
976
|
+
if (isValidProxyTarget(validatedValue) || isProxy(validatedValue)) {
|
|
977
|
+
setOwnerRecursive(validatedValue, echoRoot);
|
|
978
|
+
}
|
|
979
|
+
return {
|
|
980
|
+
echoRoot,
|
|
981
|
+
preparedValue: validatedValue
|
|
982
|
+
};
|
|
2223
983
|
}
|
|
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;
|
|
984
|
+
_validateValue(target, prop, value2) {
|
|
985
|
+
if (prop === ParentId) {
|
|
986
|
+
return value2;
|
|
987
|
+
}
|
|
988
|
+
const schema = SchemaValidator.getTargetPropertySchema(target, prop);
|
|
989
|
+
const _ = Schema4.asserts(schema)(value2);
|
|
990
|
+
if (isValidProxyTarget(value2)) {
|
|
991
|
+
setSchemaProperties(value2, schema);
|
|
992
|
+
}
|
|
993
|
+
return value2;
|
|
2250
994
|
}
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
995
|
+
_inspect(_, options, inspectFn) {
|
|
996
|
+
const inspected = inspectFn(this, {
|
|
997
|
+
...options,
|
|
998
|
+
showHidden: false,
|
|
999
|
+
customInspect: false
|
|
1000
|
+
});
|
|
1001
|
+
return `Typed ${inspected}`;
|
|
2254
1002
|
}
|
|
2255
|
-
return target;
|
|
2256
1003
|
};
|
|
2257
|
-
var
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
}
|
|
1004
|
+
var toJSON = (target) => {
|
|
1005
|
+
return {
|
|
1006
|
+
"@type": "TypedReactiveObject",
|
|
1007
|
+
...target
|
|
1008
|
+
};
|
|
2263
1009
|
};
|
|
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;
|
|
1010
|
+
var setSchemaProperties = (obj, schema) => {
|
|
1011
|
+
const schemaType = getSchemaDXN(schema);
|
|
1012
|
+
if (schemaType != null) {
|
|
1013
|
+
defineHiddenProperty(obj, TypeId, schemaType);
|
|
2275
1014
|
}
|
|
2276
|
-
|
|
2277
|
-
|
|
1015
|
+
defineHiddenProperty(obj, SchemaId, schema);
|
|
1016
|
+
for (const key in obj) {
|
|
1017
|
+
if (isValidProxyTarget(obj[key])) {
|
|
1018
|
+
const elementSchema = SchemaValidator.getTargetPropertySchema(obj, key);
|
|
1019
|
+
if (elementSchema != null) {
|
|
1020
|
+
setSchemaProperties(obj[key], elementSchema);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
2278
1023
|
}
|
|
2279
1024
|
};
|
|
2280
|
-
var
|
|
2281
|
-
|
|
2282
|
-
|
|
1025
|
+
var prepareTypedTarget = (target, schema) => {
|
|
1026
|
+
if (!SchemaAST3.isTypeLiteral(schema.ast)) {
|
|
1027
|
+
throw new Error("schema has to describe an object type");
|
|
2283
1028
|
}
|
|
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
|
-
});
|
|
1029
|
+
SchemaValidator.validateSchema(schema);
|
|
1030
|
+
const _ = Schema4.asserts(schema)(target);
|
|
1031
|
+
makeArraysReactive(target);
|
|
1032
|
+
setSchemaProperties(target, schema);
|
|
1033
|
+
};
|
|
1034
|
+
var makeArraysReactive = (target) => {
|
|
1035
|
+
for (const key in target) {
|
|
1036
|
+
if (target[symbolIsProxy]) {
|
|
1037
|
+
continue;
|
|
1038
|
+
}
|
|
1039
|
+
if (Array.isArray(target[key])) {
|
|
1040
|
+
target[key] = ReactiveArray.from(target[key]);
|
|
1041
|
+
}
|
|
1042
|
+
if (typeof target[key] === "object") {
|
|
1043
|
+
makeArraysReactive(target[key]);
|
|
2306
1044
|
}
|
|
2307
1045
|
}
|
|
2308
1046
|
};
|
|
2309
1047
|
|
|
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
|
-
}
|
|
1048
|
+
// src/internal/common/proxy/make-object.ts
|
|
1049
|
+
var makeObject = (schema, obj, meta) => {
|
|
1050
|
+
return createReactiveObject(Object.assign({}, obj), meta, schema);
|
|
1051
|
+
};
|
|
1052
|
+
var createReactiveObject = (obj, meta, schema) => {
|
|
1053
|
+
if (!isValidProxyTarget(obj)) {
|
|
1054
|
+
throw new Error("Value cannot be made into a reactive object.");
|
|
2336
1055
|
}
|
|
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
|
-
}
|
|
1056
|
+
if (!schema) {
|
|
1057
|
+
throw new Error("Schema is required for reactive objects. Use Atom for untyped reactive state.");
|
|
2352
1058
|
}
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
const propertyType = getPropertyType(schema.ast, propertyName.toString(), (propertyName2) => getProperty([
|
|
2362
|
-
...propertyPath.slice(0, i),
|
|
2363
|
-
propertyName2
|
|
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;
|
|
1059
|
+
const parent = obj[ParentId];
|
|
1060
|
+
if (parent !== void 0) {
|
|
1061
|
+
delete obj[ParentId];
|
|
1062
|
+
}
|
|
1063
|
+
const annotation = getTypeAnnotation(schema);
|
|
1064
|
+
if (annotation) {
|
|
1065
|
+
setIdOnTarget(obj);
|
|
1066
|
+
defineHiddenProperty(obj, KindId, annotation.kind);
|
|
2381
1067
|
}
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
if (arrayAst != null) {
|
|
2395
|
-
return getArrayElementSchema(arrayAst, prop);
|
|
1068
|
+
initMeta(obj, meta);
|
|
1069
|
+
if (parent !== void 0) {
|
|
1070
|
+
defineHiddenProperty(obj, ParentId, parent);
|
|
1071
|
+
}
|
|
1072
|
+
prepareTypedTarget(obj, schema);
|
|
1073
|
+
attachTypedJsonSerializer(obj);
|
|
1074
|
+
const proxy = createProxy(obj, TypedReactiveHandler.instance);
|
|
1075
|
+
const metaProxy = obj[MetaId];
|
|
1076
|
+
if (metaProxy) {
|
|
1077
|
+
const metaTarget = getProxyTarget(metaProxy);
|
|
1078
|
+
if (metaTarget) {
|
|
1079
|
+
setMetaOwner(metaTarget, obj);
|
|
2396
1080
|
}
|
|
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
1081
|
}
|
|
1082
|
+
return proxy;
|
|
2412
1083
|
};
|
|
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);
|
|
1084
|
+
var setIdOnTarget = (target) => {
|
|
1085
|
+
if ("id" in target && target.id !== void 0 && target.id !== null) {
|
|
1086
|
+
if (!ObjectId.isValid(target.id)) {
|
|
1087
|
+
throw new Error("Invalid object id format.");
|
|
1088
|
+
}
|
|
1089
|
+
} else {
|
|
1090
|
+
target.id = ObjectId.random();
|
|
2430
1091
|
}
|
|
2431
|
-
const restType = tupleAst.rest;
|
|
2432
|
-
return Schema11.make(restType[0].type).annotations(restType[0].annotations);
|
|
2433
1092
|
};
|
|
2434
|
-
var
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
1093
|
+
var initMeta = (obj, meta = {
|
|
1094
|
+
keys: []
|
|
1095
|
+
}) => {
|
|
1096
|
+
prepareTypedTarget(meta, ObjectMetaSchema);
|
|
1097
|
+
defineHiddenProperty(obj, MetaId, createProxy(meta, TypedReactiveHandler.instance));
|
|
1098
|
+
};
|
|
1099
|
+
|
|
1100
|
+
// src/internal/common/proxy/reactive.ts
|
|
1101
|
+
var subscribe = (obj, callback) => {
|
|
1102
|
+
if (!isProxy(obj)) {
|
|
1103
|
+
return () => {
|
|
1104
|
+
};
|
|
2442
1105
|
}
|
|
2443
|
-
|
|
2444
|
-
|
|
1106
|
+
const target = getProxyTarget(obj);
|
|
1107
|
+
if (target && EventId in target) {
|
|
1108
|
+
return target[EventId].on(callback);
|
|
2445
1109
|
}
|
|
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]);
|
|
1110
|
+
return () => {
|
|
1111
|
+
};
|
|
2459
1112
|
};
|
|
2460
|
-
var
|
|
2461
|
-
const
|
|
2462
|
-
if (
|
|
2463
|
-
|
|
1113
|
+
var change = (obj, callback) => {
|
|
1114
|
+
const changeFn = obj[ChangeId];
|
|
1115
|
+
if (changeFn) {
|
|
1116
|
+
changeFn(callback);
|
|
1117
|
+
} else {
|
|
1118
|
+
callback(obj);
|
|
2464
1119
|
}
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
1120
|
+
};
|
|
1121
|
+
|
|
1122
|
+
// src/internal/Entity/api.ts
|
|
1123
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
1124
|
+
import { assumeType as assumeType3 } from "@dxos/util";
|
|
1125
|
+
|
|
1126
|
+
// src/internal/Entity/model.ts
|
|
1127
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
1128
|
+
import { DXN as DXN2, ObjectId as ObjectId2 } from "@dxos/keys";
|
|
1129
|
+
import { assumeType } from "@dxos/util";
|
|
1130
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/model.ts";
|
|
1131
|
+
function assertObjectModel(obj) {
|
|
1132
|
+
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'"] });
|
|
1133
|
+
assumeType(obj);
|
|
1134
|
+
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'"] });
|
|
1135
|
+
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'"] });
|
|
1136
|
+
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'"] });
|
|
1137
|
+
if (obj[KindId] === EntityKind.Relation) {
|
|
1138
|
+
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'"] });
|
|
1139
|
+
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'"] });
|
|
1140
|
+
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'"] });
|
|
1141
|
+
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
1142
|
}
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// src/internal/Entity/util.ts
|
|
1146
|
+
import * as Schema5 from "effect/Schema";
|
|
1147
|
+
import { assertArgument as assertArgument2, invariant as invariant9 } from "@dxos/invariant";
|
|
1148
|
+
import { DXN as DXN3, ObjectId as ObjectId3 } from "@dxos/keys";
|
|
1149
|
+
import { assumeType as assumeType2 } from "@dxos/util";
|
|
1150
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/util.ts";
|
|
1151
|
+
var getObjectDXN = (object) => {
|
|
1152
|
+
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'"] });
|
|
1153
|
+
assertArgument2(typeof object === "object" && object != null, "object", "expected object");
|
|
1154
|
+
assumeType2(object);
|
|
1155
|
+
if (object[SelfDXNId]) {
|
|
1156
|
+
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'"] });
|
|
1157
|
+
return object[SelfDXNId];
|
|
2474
1158
|
}
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
return unwrapAst(indexSignatureType.indexSignatures[0].type);
|
|
1159
|
+
if (!ObjectId3.isValid(object.id)) {
|
|
1160
|
+
throw new TypeError("Object id is not valid.");
|
|
2478
1161
|
}
|
|
2479
|
-
return
|
|
1162
|
+
return DXN3.fromLocalObjectId(object.id);
|
|
2480
1163
|
};
|
|
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;
|
|
1164
|
+
|
|
1165
|
+
// src/internal/Entity/api.ts
|
|
1166
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/api.ts";
|
|
1167
|
+
var getDXN = (entity) => {
|
|
1168
|
+
const dxn = getObjectDXN(entity);
|
|
1169
|
+
invariant10(dxn != null, "Invalid entity.", { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 13, S: void 0, A: ["dxn != null", "'Invalid entity.'"] });
|
|
1170
|
+
return dxn;
|
|
2497
1171
|
};
|
|
2498
|
-
var
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
1172
|
+
var getDatabase = (entity) => {
|
|
1173
|
+
assumeType3(entity);
|
|
1174
|
+
return entity[ObjectDatabaseId];
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
// src/internal/Entity/entity.ts
|
|
1178
|
+
import * as Schema6 from "effect/Schema";
|
|
1179
|
+
var makeEchoTypeSchema = (fields, ast, typename, version2, kind) => {
|
|
1180
|
+
return class EchoObjectSchemaClass extends Schema6.make(ast) {
|
|
1181
|
+
static typename = typename;
|
|
1182
|
+
static version = version2;
|
|
1183
|
+
static [SchemaKindId] = kind;
|
|
1184
|
+
static fields = fields;
|
|
1185
|
+
static annotations(annotations3) {
|
|
1186
|
+
const schema = Schema6.make(ast).annotations(annotations3);
|
|
1187
|
+
return makeEchoTypeSchema(fields, schema.ast, typename, version2, kind);
|
|
2510
1188
|
}
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
1189
|
+
// static make(
|
|
1190
|
+
// props: RequiredKeys<Schema.TypeLiteral.Constructor<Fields, []>> extends never
|
|
1191
|
+
// ? void | Simplify<Schema.TypeLiteral.Constructor<Fields, []>>
|
|
1192
|
+
// : Simplify<Schema.TypeLiteral.Constructor<Fields, []>>,
|
|
1193
|
+
// options?: MakeProps,
|
|
1194
|
+
// ): Simplify<Schema.TypeLiteral.Type<Fields, []>> {
|
|
1195
|
+
// const propsWithDefaults: any = _lazilyMergeDefaults(fields, { ...(props as any) });
|
|
1196
|
+
// return _getDisableValidationMakeOption(options)
|
|
1197
|
+
// ? propsWithDefaults
|
|
1198
|
+
// : ParseResult.validateSync(this)(propsWithDefaults);
|
|
1199
|
+
// }
|
|
1200
|
+
static instanceOf(value2) {
|
|
1201
|
+
return Schema6.is(this)(value2);
|
|
2515
1202
|
}
|
|
2516
|
-
}
|
|
2517
|
-
return null;
|
|
1203
|
+
};
|
|
2518
1204
|
};
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
]
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
1205
|
+
|
|
1206
|
+
// src/internal/Entity/object.ts
|
|
1207
|
+
import * as Schema7 from "effect/Schema";
|
|
1208
|
+
import * as SchemaAST4 from "effect/SchemaAST";
|
|
1209
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
1210
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/object.ts";
|
|
1211
|
+
var EchoObjectSchema = ({ typename, version: version2 }) => {
|
|
1212
|
+
return (self) => {
|
|
1213
|
+
invariant11(typeof TypeAnnotationId === "symbol", "Sanity.", { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 15, S: void 0, A: ["typeof TypeAnnotationId === 'symbol'", "'Sanity.'"] });
|
|
1214
|
+
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.'"] });
|
|
1215
|
+
const fields = self.fields ?? {};
|
|
1216
|
+
const schemaWithId = Schema7.extend(self, Schema7.Struct({
|
|
1217
|
+
id: Schema7.String
|
|
1218
|
+
}));
|
|
1219
|
+
const ast = SchemaAST4.annotations(schemaWithId.ast, {
|
|
1220
|
+
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
1221
|
+
...self.ast.annotations,
|
|
1222
|
+
[TypeAnnotationId]: {
|
|
1223
|
+
kind: EntityKind.Object,
|
|
1224
|
+
typename,
|
|
1225
|
+
version: version2
|
|
1226
|
+
},
|
|
1227
|
+
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
1228
|
+
[SchemaAST4.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
1229
|
+
kind: EntityKind.Object,
|
|
1230
|
+
typename,
|
|
1231
|
+
version: version2
|
|
1232
|
+
})
|
|
1233
|
+
});
|
|
1234
|
+
return makeEchoTypeSchema(fields, ast, typename, version2, EntityKind.Object);
|
|
1235
|
+
};
|
|
2534
1236
|
};
|
|
2535
1237
|
|
|
2536
|
-
// src/internal/
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
1238
|
+
// src/internal/Entity/relation.ts
|
|
1239
|
+
import * as Schema8 from "effect/Schema";
|
|
1240
|
+
import * as SchemaAST5 from "effect/SchemaAST";
|
|
1241
|
+
import { raise } from "@dxos/debug";
|
|
1242
|
+
import { assertArgument as assertArgument3, invariant as invariant12 } from "@dxos/invariant";
|
|
1243
|
+
import { DXN as DXN4 } from "@dxos/keys";
|
|
1244
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Entity/relation.ts";
|
|
1245
|
+
var EchoRelationSchema = ({ source, target, typename, version: version2 }) => {
|
|
1246
|
+
assertArgument3(Schema8.isSchema(source), "source");
|
|
1247
|
+
assertArgument3(Schema8.isSchema(target), "target");
|
|
1248
|
+
const sourceDXN = getDXNForRelationSchemaRef(source);
|
|
1249
|
+
const targetDXN = getDXNForRelationSchemaRef(target);
|
|
1250
|
+
if (getEntityKind(source) !== EntityKind.Object) {
|
|
1251
|
+
raise(new Error("Source schema must be an echo object schema."));
|
|
2545
1252
|
}
|
|
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;
|
|
1253
|
+
if (getEntityKind(target) !== EntityKind.Object) {
|
|
1254
|
+
raise(new Error("Target schema must be an echo object schema."));
|
|
2554
1255
|
}
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
1256
|
+
return (self) => {
|
|
1257
|
+
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.'"] });
|
|
1258
|
+
const fields = self.fields ?? {};
|
|
1259
|
+
const schemaWithId = Schema8.extend(self, Schema8.Struct({
|
|
1260
|
+
id: Schema8.String
|
|
1261
|
+
}));
|
|
1262
|
+
const ast = SchemaAST5.annotations(schemaWithId.ast, {
|
|
1263
|
+
// TODO(dmaretskyi): `extend` kills the annotations.
|
|
1264
|
+
...self.ast.annotations,
|
|
1265
|
+
[TypeAnnotationId]: {
|
|
1266
|
+
kind: EntityKind.Relation,
|
|
1267
|
+
typename,
|
|
1268
|
+
version: version2,
|
|
1269
|
+
sourceSchema: sourceDXN,
|
|
1270
|
+
targetSchema: targetDXN
|
|
1271
|
+
},
|
|
1272
|
+
// TODO(dmaretskyi): TypeIdentifierAnnotationId?
|
|
1273
|
+
[SchemaAST5.JSONSchemaAnnotationId]: makeTypeJsonSchemaAnnotation({
|
|
1274
|
+
kind: EntityKind.Relation,
|
|
1275
|
+
typename,
|
|
1276
|
+
version: version2,
|
|
1277
|
+
relationSource: sourceDXN,
|
|
1278
|
+
relationTarget: targetDXN
|
|
1279
|
+
})
|
|
1280
|
+
});
|
|
1281
|
+
return makeEchoTypeSchema(fields, ast, typename, version2, EntityKind.Relation);
|
|
1282
|
+
};
|
|
1283
|
+
};
|
|
1284
|
+
var getDXNForRelationSchemaRef = (schema) => {
|
|
1285
|
+
assertArgument3(Schema8.isSchema(schema), "schema");
|
|
1286
|
+
const identifier = getTypeIdentifierAnnotation(schema);
|
|
1287
|
+
if (identifier) {
|
|
1288
|
+
return identifier;
|
|
2558
1289
|
}
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
for (const item of actualValue) {
|
|
2563
|
-
copy2.push(deepCopy(item, visited));
|
|
2564
|
-
}
|
|
2565
|
-
return copy2;
|
|
1290
|
+
const typename = getSchemaTypename(schema);
|
|
1291
|
+
if (!typename) {
|
|
1292
|
+
throw new Error("Schema must have a typename");
|
|
2566
1293
|
}
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
1294
|
+
return DXN4.fromTypename(typename).toString();
|
|
1295
|
+
};
|
|
1296
|
+
|
|
1297
|
+
// src/internal/Entity/version.ts
|
|
1298
|
+
import { assertArgument as assertArgument4 } from "@dxos/invariant";
|
|
1299
|
+
var unversioned = {
|
|
1300
|
+
[VersionTypeId]: {},
|
|
1301
|
+
versioned: false
|
|
1302
|
+
};
|
|
1303
|
+
var isVersion = (entity) => {
|
|
1304
|
+
return entity != null && typeof entity === "object" && VersionTypeId in entity;
|
|
1305
|
+
};
|
|
1306
|
+
var version = (entity) => {
|
|
1307
|
+
const ver = entity[ObjectVersionId];
|
|
1308
|
+
if (ver === void 0) {
|
|
1309
|
+
return unversioned;
|
|
2571
1310
|
}
|
|
2572
|
-
|
|
2573
|
-
return copy;
|
|
1311
|
+
return ver;
|
|
2574
1312
|
};
|
|
2575
|
-
var
|
|
2576
|
-
|
|
2577
|
-
|
|
1313
|
+
var versionValid = (ver) => {
|
|
1314
|
+
assertArgument4(isVersion(ver), "version", "Invalid version object");
|
|
1315
|
+
return !!ver.versioned;
|
|
1316
|
+
};
|
|
1317
|
+
var compareVersions = (version1, version2) => {
|
|
1318
|
+
assertArgument4(isVersion(version1), "version1", "Invalid version object");
|
|
1319
|
+
assertArgument4(isVersion(version2), "version2", "Invalid version object");
|
|
1320
|
+
if (!versionValid(version1) || !versionValid(version2)) {
|
|
1321
|
+
return "unversioned";
|
|
2578
1322
|
}
|
|
2579
|
-
if (
|
|
2580
|
-
|
|
1323
|
+
if (version1.automergeHeads?.length !== version2.automergeHeads?.length) {
|
|
1324
|
+
return "different";
|
|
1325
|
+
}
|
|
1326
|
+
if (version1.automergeHeads?.some((head) => !version2.automergeHeads?.includes(head))) {
|
|
1327
|
+
return "different";
|
|
2581
1328
|
}
|
|
1329
|
+
return "equal";
|
|
2582
1330
|
};
|
|
2583
|
-
var
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
1331
|
+
var encodeVersion = (ver) => {
|
|
1332
|
+
return JSON.stringify(ver);
|
|
1333
|
+
};
|
|
1334
|
+
var decodeVersion = (ver) => {
|
|
1335
|
+
const parsed = JSON.parse(ver);
|
|
1336
|
+
parsed[VersionTypeId] = {};
|
|
1337
|
+
return parsed;
|
|
1338
|
+
};
|
|
1339
|
+
|
|
1340
|
+
// src/internal/JsonSchema/json-schema-normalize.ts
|
|
1341
|
+
var normalizeSchema = (schema) => {
|
|
1342
|
+
const copy = structuredClone(schema);
|
|
1343
|
+
go(copy);
|
|
1344
|
+
return copy;
|
|
1345
|
+
};
|
|
1346
|
+
var go = (schema) => {
|
|
1347
|
+
if (typeof schema !== "object" || schema === null) {
|
|
1348
|
+
return;
|
|
2588
1349
|
}
|
|
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
|
-
});
|
|
1350
|
+
if (schema.exclusiveMaximum === true) {
|
|
1351
|
+
schema.exclusiveMaximum = schema.maximum;
|
|
1352
|
+
delete schema.exclusiveMaximum;
|
|
1353
|
+
} else if (schema.exclusiveMaximum === false) {
|
|
1354
|
+
delete schema.exclusiveMaximum;
|
|
2636
1355
|
}
|
|
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;
|
|
1356
|
+
if (schema.exclusiveMinimum === true) {
|
|
1357
|
+
schema.exclusiveMinimum = schema.minimum;
|
|
1358
|
+
delete schema.exclusiveMinimum;
|
|
1359
|
+
} else if (schema.exclusiveMinimum === false) {
|
|
1360
|
+
delete schema.exclusiveMinimum;
|
|
2658
1361
|
}
|
|
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;
|
|
1362
|
+
for (const key of Object.keys(schema)) {
|
|
1363
|
+
if (!JsonSchemaFields.includes(key)) {
|
|
1364
|
+
delete schema[key];
|
|
2679
1365
|
}
|
|
2680
|
-
return result;
|
|
2681
|
-
}
|
|
2682
|
-
ownKeys(target) {
|
|
2683
|
-
return Reflect.ownKeys(target);
|
|
2684
1366
|
}
|
|
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;
|
|
1367
|
+
if (schema.properties) {
|
|
1368
|
+
goOnRecord(schema.properties);
|
|
2697
1369
|
}
|
|
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;
|
|
1370
|
+
if (schema.patternProperties) {
|
|
1371
|
+
goOnRecord(schema.patternProperties);
|
|
2714
1372
|
}
|
|
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
|
-
};
|
|
1373
|
+
if (schema.propertyNames) {
|
|
1374
|
+
go(schema.propertyNames);
|
|
2757
1375
|
}
|
|
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;
|
|
1376
|
+
if (schema.definitions) {
|
|
1377
|
+
goOnRecord(schema.definitions);
|
|
2768
1378
|
}
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
...options,
|
|
2772
|
-
showHidden: false,
|
|
2773
|
-
customInspect: false
|
|
2774
|
-
});
|
|
2775
|
-
return `Typed ${inspected}`;
|
|
1379
|
+
if (schema.items) {
|
|
1380
|
+
maybeGoOnArray(schema.items);
|
|
2776
1381
|
}
|
|
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);
|
|
1382
|
+
if (schema.additionalItems) {
|
|
1383
|
+
maybeGoOnArray(schema.additionalItems);
|
|
2788
1384
|
}
|
|
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
|
-
}
|
|
1385
|
+
if (schema.contains) {
|
|
1386
|
+
go(schema.contains);
|
|
2797
1387
|
}
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
if (!SchemaAST8.isTypeLiteral(schema.ast)) {
|
|
2801
|
-
throw new Error("schema has to describe an object type");
|
|
1388
|
+
if (schema.if) {
|
|
1389
|
+
go(schema.if);
|
|
2802
1390
|
}
|
|
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
|
-
}
|
|
1391
|
+
if (schema.then) {
|
|
1392
|
+
go(schema.then);
|
|
2819
1393
|
}
|
|
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.");
|
|
1394
|
+
if (schema.else) {
|
|
1395
|
+
go(schema.else);
|
|
2829
1396
|
}
|
|
2830
|
-
if (
|
|
2831
|
-
|
|
1397
|
+
if (schema.allOf) {
|
|
1398
|
+
maybeGoOnArray(schema.allOf);
|
|
2832
1399
|
}
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
delete obj[ParentId];
|
|
1400
|
+
if (schema.anyOf) {
|
|
1401
|
+
maybeGoOnArray(schema.anyOf);
|
|
2836
1402
|
}
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
setIdOnTarget(obj);
|
|
2840
|
-
defineHiddenProperty(obj, KindId, annotation.kind);
|
|
1403
|
+
if (schema.oneOf) {
|
|
1404
|
+
maybeGoOnArray(schema.oneOf);
|
|
2841
1405
|
}
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
defineHiddenProperty(obj, ParentId, parent);
|
|
1406
|
+
if (schema.not) {
|
|
1407
|
+
go(schema.not);
|
|
2845
1408
|
}
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
const metaTarget = getProxyTarget(metaProxy);
|
|
2852
|
-
if (metaTarget) {
|
|
2853
|
-
setMetaOwner(metaTarget, obj);
|
|
2854
|
-
}
|
|
1409
|
+
if (schema.$defs) {
|
|
1410
|
+
goOnRecord(schema.$defs);
|
|
1411
|
+
}
|
|
1412
|
+
if (schema.reference) {
|
|
1413
|
+
go(schema.reference.schema);
|
|
2855
1414
|
}
|
|
2856
|
-
return proxy;
|
|
2857
1415
|
};
|
|
2858
|
-
var
|
|
2859
|
-
if (
|
|
2860
|
-
|
|
2861
|
-
|
|
1416
|
+
var maybeGoOnArray = (value2) => {
|
|
1417
|
+
if (Array.isArray(value2)) {
|
|
1418
|
+
for (const item of value2) {
|
|
1419
|
+
go(item);
|
|
2862
1420
|
}
|
|
2863
|
-
} else {
|
|
2864
|
-
|
|
1421
|
+
} else if (typeof value2 === "object" && value2 !== null) {
|
|
1422
|
+
go(value2);
|
|
2865
1423
|
}
|
|
2866
1424
|
};
|
|
2867
|
-
var
|
|
2868
|
-
keys
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
defineHiddenProperty(obj, MetaId, createProxy(meta, TypedReactiveHandler.instance));
|
|
1425
|
+
var goOnRecord = (record) => {
|
|
1426
|
+
for (const key of Object.keys(record)) {
|
|
1427
|
+
go(record[key]);
|
|
1428
|
+
}
|
|
2872
1429
|
};
|
|
2873
1430
|
|
|
2874
|
-
// src/internal/
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
1431
|
+
// src/internal/Obj/common.ts
|
|
1432
|
+
import * as Schema9 from "effect/Schema";
|
|
1433
|
+
var makeTypedEntityClass = (typename, version2, baseSchema) => {
|
|
1434
|
+
return class {
|
|
1435
|
+
// Implement TypedObject properties.
|
|
1436
|
+
static typename = typename;
|
|
1437
|
+
static version = version2;
|
|
1438
|
+
// Implement Schema.Schema properties.
|
|
1439
|
+
// TODO(burdon): Comment required.
|
|
1440
|
+
static [Schema9.TypeId] = schemaVariance;
|
|
1441
|
+
static ast = baseSchema.ast;
|
|
1442
|
+
static annotations = baseSchema.annotations.bind(baseSchema);
|
|
1443
|
+
static pipe = baseSchema.pipe.bind(baseSchema);
|
|
1444
|
+
// TODO(burdon): Comment required.
|
|
1445
|
+
static [Symbol.hasInstance](obj) {
|
|
1446
|
+
return obj != null && getTypename(obj) === typename;
|
|
1447
|
+
}
|
|
1448
|
+
// TODO(burdon): Throw APIError.
|
|
1449
|
+
constructor() {
|
|
1450
|
+
throw new Error("Use live(Typename, { ...fields }) to instantiate an object.");
|
|
1451
|
+
}
|
|
2881
1452
|
};
|
|
2882
1453
|
};
|
|
2883
|
-
var
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
} else {
|
|
2888
|
-
callback(obj);
|
|
2889
|
-
}
|
|
1454
|
+
var schemaVariance = {
|
|
1455
|
+
_A: (_) => _,
|
|
1456
|
+
_I: (_) => _,
|
|
1457
|
+
_R: (_) => _
|
|
2890
1458
|
};
|
|
2891
1459
|
|
|
2892
|
-
// src/internal/object
|
|
2893
|
-
import {
|
|
1460
|
+
// src/internal/Obj/create-object.ts
|
|
1461
|
+
import { raise as raise3 } from "@dxos/debug";
|
|
1462
|
+
import { assertArgument as assertArgument6, failedInvariant } from "@dxos/invariant";
|
|
1463
|
+
import { ObjectId as ObjectId5 } from "@dxos/keys";
|
|
1464
|
+
|
|
1465
|
+
// src/internal/Obj/inspect.ts
|
|
1466
|
+
import { inspectCustom as inspectCustom2 } from "@dxos/debug";
|
|
2894
1467
|
var attachedTypedObjectInspector = (obj) => {
|
|
2895
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj,
|
|
1468
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, inspectCustom2);
|
|
2896
1469
|
if (descriptor) {
|
|
2897
1470
|
return;
|
|
2898
1471
|
}
|
|
2899
|
-
Object.defineProperty(obj,
|
|
1472
|
+
Object.defineProperty(obj, inspectCustom2, {
|
|
2900
1473
|
value: typedObjectInspectFunction,
|
|
2901
1474
|
writable: false,
|
|
2902
1475
|
enumerable: false,
|
|
@@ -2913,47 +1486,31 @@ var typedObjectInspectFunction = function(depth, options, inspect) {
|
|
|
2913
1486
|
}, options);
|
|
2914
1487
|
};
|
|
2915
1488
|
|
|
2916
|
-
// src/internal/
|
|
2917
|
-
import * as
|
|
2918
|
-
import { raise as
|
|
1489
|
+
// src/internal/Obj/json-serializer.ts
|
|
1490
|
+
import * as Schema10 from "effect/Schema";
|
|
1491
|
+
import { raise as raise2 } from "@dxos/debug";
|
|
2919
1492
|
import { ObjectStructure, isEncodedReference } from "@dxos/echo-protocol";
|
|
2920
|
-
import { assertArgument as
|
|
2921
|
-
import { DXN as
|
|
1493
|
+
import { assertArgument as assertArgument5, invariant as invariant13 } from "@dxos/invariant";
|
|
1494
|
+
import { DXN as DXN5, ObjectId as ObjectId4 } from "@dxos/keys";
|
|
2922
1495
|
import { assumeType as assumeType4, deepMapValues as deepMapValues2, visitValues } from "@dxos/util";
|
|
2923
|
-
var
|
|
1496
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Obj/json-serializer.ts";
|
|
2924
1497
|
var objectToJSON = (obj) => {
|
|
2925
1498
|
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
|
-
});
|
|
1499
|
+
invariant13(typename && typeof typename === "string", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 21, S: void 0, A: ["typename && typeof typename === 'string'", ""] });
|
|
2935
1500
|
return typedJsonSerializer.call(obj);
|
|
2936
1501
|
};
|
|
2937
|
-
var objectFromJSON = async (jsonData, { refResolver, dxn } = {}) => {
|
|
1502
|
+
var objectFromJSON = async (jsonData, { refResolver, dxn, database, parent } = {}) => {
|
|
2938
1503
|
assumeType4(jsonData);
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
const type =
|
|
1504
|
+
assertArgument5(typeof jsonData === "object" && jsonData !== null, "jsonData", "expect object");
|
|
1505
|
+
assertArgument5(typeof jsonData[ATTR_TYPE] === "string", "jsonData[ATTR_TYPE]", "expected object to have a type");
|
|
1506
|
+
assertArgument5(typeof jsonData.id === "string", "jsonData.id", "expected object to have an id");
|
|
1507
|
+
const type = DXN5.parse(jsonData[ATTR_TYPE]);
|
|
2943
1508
|
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
|
-
});
|
|
1509
|
+
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
1510
|
const decodedInput = stripInternalJsonKeys(jsonData);
|
|
2954
1511
|
let obj;
|
|
2955
1512
|
if (schema != null) {
|
|
2956
|
-
obj = await schema.pipe(
|
|
1513
|
+
obj = await schema.pipe(Schema10.decodeUnknownPromise)(decodedInput);
|
|
2957
1514
|
if (refResolver) {
|
|
2958
1515
|
setRefResolverOnData(obj, refResolver);
|
|
2959
1516
|
}
|
|
@@ -2962,23 +1519,15 @@ var objectFromJSON = async (jsonData, { refResolver, dxn } = {}) => {
|
|
|
2962
1519
|
refResolver
|
|
2963
1520
|
});
|
|
2964
1521
|
}
|
|
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
|
-
});
|
|
1522
|
+
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
1523
|
setTypename(obj, type);
|
|
2975
1524
|
if (schema) {
|
|
2976
1525
|
setSchema(obj, schema);
|
|
2977
1526
|
}
|
|
2978
1527
|
const isRelation = typeof jsonData[ATTR_RELATION_SOURCE] === "string" || typeof jsonData[ATTR_RELATION_TARGET] === "string";
|
|
2979
1528
|
if (isRelation) {
|
|
2980
|
-
const sourceDxn =
|
|
2981
|
-
const targetDxn =
|
|
1529
|
+
const sourceDxn = DXN5.parse(jsonData[ATTR_RELATION_SOURCE] ?? raise2(new TypeError("Missing relation source")));
|
|
1530
|
+
const targetDxn = DXN5.parse(jsonData[ATTR_RELATION_TARGET] ?? raise2(new TypeError("Missing relation target")));
|
|
2982
1531
|
const source = await refResolver?.resolve(sourceDxn);
|
|
2983
1532
|
const target = await refResolver?.resolve(targetDxn);
|
|
2984
1533
|
defineHiddenProperty(obj, KindId, EntityKind.Relation);
|
|
@@ -2990,16 +1539,8 @@ var objectFromJSON = async (jsonData, { refResolver, dxn } = {}) => {
|
|
|
2990
1539
|
defineHiddenProperty(obj, KindId, EntityKind.Object);
|
|
2991
1540
|
}
|
|
2992
1541
|
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
|
-
});
|
|
1542
|
+
const meta = await ObjectMetaSchema.pipe(Schema10.decodeUnknownPromise)(jsonData[ATTR_META]);
|
|
1543
|
+
invariant13(Array.isArray(meta.keys), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 75, S: void 0, A: ["Array.isArray(meta.keys)", ""] });
|
|
3003
1544
|
defineHiddenProperty(obj, MetaId, meta);
|
|
3004
1545
|
} else {
|
|
3005
1546
|
defineHiddenProperty(obj, MetaId, {
|
|
@@ -3007,68 +1548,25 @@ var objectFromJSON = async (jsonData, { refResolver, dxn } = {}) => {
|
|
|
3007
1548
|
});
|
|
3008
1549
|
}
|
|
3009
1550
|
if (jsonData[ATTR_PARENT]) {
|
|
3010
|
-
const parentDxn =
|
|
3011
|
-
const
|
|
1551
|
+
const parentDxn = DXN5.parse(jsonData[ATTR_PARENT]);
|
|
1552
|
+
const resolvedParent = await refResolver?.resolve(parentDxn);
|
|
1553
|
+
defineHiddenProperty(obj, ParentId, resolvedParent);
|
|
1554
|
+
} else if (parent) {
|
|
3012
1555
|
defineHiddenProperty(obj, ParentId, parent);
|
|
3013
1556
|
}
|
|
3014
1557
|
if (dxn) {
|
|
3015
1558
|
defineHiddenProperty(obj, SelfDXNId, dxn);
|
|
3016
1559
|
}
|
|
1560
|
+
if (database) {
|
|
1561
|
+
defineHiddenProperty(obj, ObjectDatabaseId, database);
|
|
1562
|
+
}
|
|
3017
1563
|
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
|
-
});
|
|
1564
|
+
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'"] });
|
|
1565
|
+
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'"] });
|
|
1566
|
+
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'"] });
|
|
1567
|
+
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'"] });
|
|
1568
|
+
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'"] });
|
|
1569
|
+
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
1570
|
return obj;
|
|
3073
1571
|
};
|
|
3074
1572
|
var decodeGeneric = (jsonData, options) => {
|
|
@@ -3106,19 +1604,19 @@ var objectStructureToJson = (objectId, structure) => {
|
|
|
3106
1604
|
};
|
|
3107
1605
|
};
|
|
3108
1606
|
|
|
3109
|
-
// src/internal/
|
|
1607
|
+
// src/internal/Obj/create-object.ts
|
|
3110
1608
|
var createObject = (schema, props) => {
|
|
3111
1609
|
const annotation = getTypeAnnotation(schema);
|
|
3112
1610
|
if (!annotation) {
|
|
3113
1611
|
throw new Error("Schema is not an ECHO schema");
|
|
3114
1612
|
}
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
1613
|
+
assertArgument6(!("@type" in props), "data", "@type is not allowed");
|
|
1614
|
+
assertArgument6(!(RelationSourceDXNId in props), "data", "Relation source DXN is not allowed in the constructor");
|
|
1615
|
+
assertArgument6(!(RelationTargetDXNId in props), "data", "Relation target DXN is not allowed in the constructor");
|
|
1616
|
+
assertArgument6(RelationSourceId in props === RelationTargetId in props, "data", "Relation source and target must be provided together");
|
|
3119
1617
|
const obj = {
|
|
3120
1618
|
...props,
|
|
3121
|
-
id: props.id ??
|
|
1619
|
+
id: props.id ?? ObjectId5.random()
|
|
3122
1620
|
};
|
|
3123
1621
|
const kind = RelationSourceId in props ? EntityKind.Relation : EntityKind.Object;
|
|
3124
1622
|
defineHiddenProperty(obj, KindId, kind);
|
|
@@ -3130,8 +1628,8 @@ var createObject = (schema, props) => {
|
|
|
3130
1628
|
attachTypedJsonSerializer(obj);
|
|
3131
1629
|
attachedTypedObjectInspector(obj);
|
|
3132
1630
|
if (kind === EntityKind.Relation) {
|
|
3133
|
-
const sourceDXN = getObjectDXN(props[RelationSourceId]) ??
|
|
3134
|
-
const targetDXN = getObjectDXN(props[RelationTargetId]) ??
|
|
1631
|
+
const sourceDXN = getObjectDXN(props[RelationSourceId]) ?? raise3(new Error("Unresolved relation source"));
|
|
1632
|
+
const targetDXN = getObjectDXN(props[RelationTargetId]) ?? raise3(new Error("Unresolved relation target"));
|
|
3135
1633
|
defineHiddenProperty(obj, RelationSourceDXNId, sourceDXN);
|
|
3136
1634
|
defineHiddenProperty(obj, RelationTargetDXNId, targetDXN);
|
|
3137
1635
|
}
|
|
@@ -3139,7 +1637,7 @@ var createObject = (schema, props) => {
|
|
|
3139
1637
|
return obj;
|
|
3140
1638
|
};
|
|
3141
1639
|
|
|
3142
|
-
// src/internal/
|
|
1640
|
+
// src/internal/Obj/deleted.ts
|
|
3143
1641
|
var isDeleted = (obj) => {
|
|
3144
1642
|
if (obj[ObjectDeletedId] === void 0) {
|
|
3145
1643
|
return false;
|
|
@@ -3147,41 +1645,25 @@ var isDeleted = (obj) => {
|
|
|
3147
1645
|
return obj[ObjectDeletedId] ?? false;
|
|
3148
1646
|
};
|
|
3149
1647
|
|
|
3150
|
-
// src/internal/
|
|
3151
|
-
import { DXN as
|
|
3152
|
-
var createQueueDXN = (spaceId = SpaceId.random(), queueId =
|
|
1648
|
+
// src/internal/Obj/ids.ts
|
|
1649
|
+
import { DXN as DXN6, ObjectId as ObjectId6, QueueSubspaceTags, SpaceId } from "@dxos/keys";
|
|
1650
|
+
var createQueueDXN = (spaceId = SpaceId.random(), queueId = ObjectId6.random()) => new DXN6(DXN6.kind.QUEUE, [
|
|
3153
1651
|
QueueSubspaceTags.DATA,
|
|
3154
1652
|
spaceId,
|
|
3155
1653
|
queueId
|
|
3156
1654
|
]);
|
|
3157
1655
|
|
|
3158
|
-
// src/internal/
|
|
1656
|
+
// src/internal/Obj/set-value.ts
|
|
3159
1657
|
import * as Match from "effect/Match";
|
|
3160
|
-
import * as
|
|
3161
|
-
import * as
|
|
1658
|
+
import * as Option from "effect/Option";
|
|
1659
|
+
import * as SchemaAST6 from "effect/SchemaAST";
|
|
3162
1660
|
import { getArrayElementType, getBaseType, getProperties as getProperties2, isArrayType, isNestedType } from "@dxos/effect";
|
|
3163
|
-
import { invariant as
|
|
3164
|
-
var
|
|
1661
|
+
import { invariant as invariant14 } from "@dxos/invariant";
|
|
1662
|
+
var __dxlog_file14 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Obj/set-value.ts";
|
|
3165
1663
|
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
|
-
});
|
|
1664
|
+
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
1665
|
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
|
-
});
|
|
1666
|
+
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
1667
|
let parent = obj;
|
|
3186
1668
|
let currentAST = schema.ast;
|
|
3187
1669
|
for (let i = 0; i < path.length - 1; i++) {
|
|
@@ -3235,8 +1717,8 @@ var getDefaultValueForType = (ast) => {
|
|
|
3235
1717
|
if (!ast) {
|
|
3236
1718
|
return void 0;
|
|
3237
1719
|
}
|
|
3238
|
-
const defaultValue =
|
|
3239
|
-
if (
|
|
1720
|
+
const defaultValue = SchemaAST6.getDefaultAnnotation(ast);
|
|
1721
|
+
if (Option.isSome(defaultValue)) {
|
|
3240
1722
|
return defaultValue.value;
|
|
3241
1723
|
}
|
|
3242
1724
|
return Match.value(ast).pipe(Match.when({
|
|
@@ -3264,19 +1746,19 @@ var createObjectWithDefaults = (ast) => {
|
|
|
3264
1746
|
return obj;
|
|
3265
1747
|
};
|
|
3266
1748
|
|
|
3267
|
-
// src/internal/
|
|
3268
|
-
import { assertArgument as
|
|
1749
|
+
// src/internal/Obj/snapshot.ts
|
|
1750
|
+
import { assertArgument as assertArgument7 } from "@dxos/invariant";
|
|
3269
1751
|
import { deepMapValues as deepMapValues3 } from "@dxos/util";
|
|
3270
|
-
var copySymbolProperty = (source, target,
|
|
1752
|
+
var copySymbolProperty = (source, target, symbol, transform) => {
|
|
3271
1753
|
let value2;
|
|
3272
1754
|
try {
|
|
3273
|
-
value2 = source[
|
|
1755
|
+
value2 = source[symbol];
|
|
3274
1756
|
} catch {
|
|
3275
1757
|
return;
|
|
3276
1758
|
}
|
|
3277
1759
|
if (value2 !== void 0) {
|
|
3278
1760
|
const finalValue = transform ? transform(value2) : value2;
|
|
3279
|
-
Object.defineProperty(target,
|
|
1761
|
+
Object.defineProperty(target, symbol, {
|
|
3280
1762
|
value: finalValue,
|
|
3281
1763
|
writable: false,
|
|
3282
1764
|
enumerable: false,
|
|
@@ -3285,7 +1767,7 @@ var copySymbolProperty = (source, target, symbol3, transform) => {
|
|
|
3285
1767
|
}
|
|
3286
1768
|
};
|
|
3287
1769
|
var getSnapshot = (obj) => {
|
|
3288
|
-
|
|
1770
|
+
assertArgument7(typeof obj === "object" && obj !== null && KindId in obj, "obj", "must be an entity");
|
|
3289
1771
|
const snapshot = deepMapValues3(obj, (value2, recurse) => {
|
|
3290
1772
|
if (typeof value2 === "object" && value2 !== null && Object.getPrototypeOf(value2) !== Object.prototype && !Array.isArray(value2)) {
|
|
3291
1773
|
return value2;
|
|
@@ -3316,22 +1798,14 @@ var getSnapshot = (obj) => {
|
|
|
3316
1798
|
return Object.freeze(snapshot);
|
|
3317
1799
|
};
|
|
3318
1800
|
|
|
3319
|
-
// src/internal/
|
|
3320
|
-
import { invariant as
|
|
1801
|
+
// src/internal/Obj/clone.ts
|
|
1802
|
+
import { invariant as invariant15 } from "@dxos/invariant";
|
|
3321
1803
|
import { deepMapValues as deepMapValues4 } from "@dxos/util";
|
|
3322
|
-
var
|
|
1804
|
+
var __dxlog_file15 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Obj/clone.ts";
|
|
3323
1805
|
var clone = (obj, opts) => {
|
|
3324
1806
|
const { id, ...data } = obj;
|
|
3325
1807
|
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
|
-
});
|
|
1808
|
+
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
1809
|
const props = deepMapValues4(data, (value2, recurse) => {
|
|
3336
1810
|
if (Ref.isRef(value2)) {
|
|
3337
1811
|
if (opts?.deep) {
|
|
@@ -3356,36 +1830,149 @@ var clone = (obj, opts) => {
|
|
|
3356
1830
|
return makeObject(schema, props, meta);
|
|
3357
1831
|
};
|
|
3358
1832
|
|
|
3359
|
-
// src/internal/
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
1833
|
+
// src/internal/Query.ts
|
|
1834
|
+
var prettyFilter = (filter) => {
|
|
1835
|
+
switch (filter.type) {
|
|
1836
|
+
case "object": {
|
|
1837
|
+
const parts = [];
|
|
1838
|
+
if (filter.typename !== null) {
|
|
1839
|
+
parts.push(String(filter.typename));
|
|
1840
|
+
}
|
|
1841
|
+
if (filter.id !== void 0 && filter.id.length > 0) {
|
|
1842
|
+
parts.push(`id: [${filter.id.join(", ")}]`);
|
|
1843
|
+
}
|
|
1844
|
+
const propEntries = Object.entries(filter.props);
|
|
1845
|
+
if (propEntries.length > 0) {
|
|
1846
|
+
const propsStr = propEntries.map(([k, v]) => `${k}: ${prettyFilter(v)}`).join(", ");
|
|
1847
|
+
parts.push(`{ ${propsStr} }`);
|
|
1848
|
+
}
|
|
1849
|
+
if (filter.foreignKeys !== void 0 && filter.foreignKeys.length > 0) {
|
|
1850
|
+
parts.push(`foreignKeys: [${filter.foreignKeys.map((fk) => JSON.stringify(fk)).join(", ")}]`);
|
|
1851
|
+
}
|
|
1852
|
+
return parts.length > 0 ? `Filter.type(${parts.join(", ")})` : "Filter.everything()";
|
|
1853
|
+
}
|
|
1854
|
+
case "compare":
|
|
1855
|
+
return `Filter.${filter.operator}(${JSON.stringify(filter.value)})`;
|
|
1856
|
+
case "in":
|
|
1857
|
+
return `Filter.in([${filter.values.map((v) => JSON.stringify(v)).join(", ")}])`;
|
|
1858
|
+
case "contains":
|
|
1859
|
+
return `Filter.contains(${JSON.stringify(filter.value)})`;
|
|
1860
|
+
case "tag":
|
|
1861
|
+
return `Filter.tag(${JSON.stringify(filter.tag)})`;
|
|
1862
|
+
case "range":
|
|
1863
|
+
return `Filter.range(${JSON.stringify(filter.from)}, ${JSON.stringify(filter.to)})`;
|
|
1864
|
+
case "text-search":
|
|
1865
|
+
return filter.searchKind ? `Filter.textSearch(${JSON.stringify(filter.text)}, ${JSON.stringify(filter.searchKind)})` : `Filter.textSearch(${JSON.stringify(filter.text)})`;
|
|
1866
|
+
case "timestamp":
|
|
1867
|
+
return `Filter.${filter.field}.${filter.operator}(${filter.value})`;
|
|
1868
|
+
case "child-of":
|
|
1869
|
+
return `Filter.childOf([${filter.parents.map((p) => JSON.stringify(p)).join(", ")}], { transitive: ${filter.transitive} })`;
|
|
1870
|
+
case "not":
|
|
1871
|
+
return `Filter.not(${prettyFilter(filter.filter)})`;
|
|
1872
|
+
case "and":
|
|
1873
|
+
return `Filter.and(${filter.filters.map(prettyFilter).join(", ")})`;
|
|
1874
|
+
case "or":
|
|
1875
|
+
return `Filter.or(${filter.filters.map(prettyFilter).join(", ")})`;
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1878
|
+
var prettyQuery = (query) => {
|
|
1879
|
+
switch (query.type) {
|
|
1880
|
+
case "select":
|
|
1881
|
+
return `Query.select(${prettyFilter(query.filter)})`;
|
|
1882
|
+
case "filter":
|
|
1883
|
+
return `${prettyQuery(query.selection)}.select(${prettyFilter(query.filter)})`;
|
|
1884
|
+
case "reference-traversal":
|
|
1885
|
+
return `${prettyQuery(query.anchor)}.reference(${JSON.stringify(query.property)})`;
|
|
1886
|
+
case "incoming-references": {
|
|
1887
|
+
const args = [];
|
|
1888
|
+
if (query.typename !== null) {
|
|
1889
|
+
args.push(String(query.typename));
|
|
1890
|
+
}
|
|
1891
|
+
if (query.property !== null) {
|
|
1892
|
+
args.push(JSON.stringify(query.property));
|
|
1893
|
+
}
|
|
1894
|
+
return `${prettyQuery(query.anchor)}.referencedBy(${args.join(", ")})`;
|
|
1895
|
+
}
|
|
1896
|
+
case "relation": {
|
|
1897
|
+
const method = query.direction === "outgoing" ? "sourceOf" : query.direction === "incoming" ? "targetOf" : "relationOf";
|
|
1898
|
+
const filterStr = query.filter !== void 0 ? prettyFilter(query.filter) : "";
|
|
1899
|
+
return `${prettyQuery(query.anchor)}.${method}(${filterStr})`;
|
|
1900
|
+
}
|
|
1901
|
+
case "relation-traversal":
|
|
1902
|
+
return `${prettyQuery(query.anchor)}.${query.direction}()`;
|
|
1903
|
+
case "hierarchy-traversal":
|
|
1904
|
+
return query.direction === "to-parent" ? `${prettyQuery(query.anchor)}.parent()` : `${prettyQuery(query.anchor)}.children()`;
|
|
1905
|
+
case "union":
|
|
1906
|
+
return `Query.all(${query.queries.map(prettyQuery).join(", ")})`;
|
|
1907
|
+
case "set-difference":
|
|
1908
|
+
return `Query.without(${prettyQuery(query.source)}, ${prettyQuery(query.exclude)})`;
|
|
1909
|
+
case "order": {
|
|
1910
|
+
const orders = query.order.map((o) => {
|
|
1911
|
+
if (o.kind === "natural") {
|
|
1912
|
+
return "Order.natural()";
|
|
1913
|
+
} else if (o.kind === "rank") {
|
|
1914
|
+
return `Order.rank(${JSON.stringify(o.direction)})`;
|
|
1915
|
+
} else {
|
|
1916
|
+
return `Order.property(${JSON.stringify(o.property)}, ${JSON.stringify(o.direction)})`;
|
|
1917
|
+
}
|
|
1918
|
+
});
|
|
1919
|
+
return `${prettyQuery(query.query)}.orderBy(${orders.join(", ")})`;
|
|
1920
|
+
}
|
|
1921
|
+
case "options": {
|
|
1922
|
+
const opts = query.options;
|
|
1923
|
+
const parts = [];
|
|
1924
|
+
if (opts.deleted !== void 0) {
|
|
1925
|
+
parts.push(`deleted: ${JSON.stringify(opts.deleted)}`);
|
|
1926
|
+
}
|
|
1927
|
+
if (opts.debugLabel !== void 0) {
|
|
1928
|
+
parts.push(`debugLabel: ${JSON.stringify(opts.debugLabel)}`);
|
|
1929
|
+
}
|
|
1930
|
+
return `${prettyQuery(query.query)}.options({ ${parts.join(", ")} })`;
|
|
1931
|
+
}
|
|
1932
|
+
case "from": {
|
|
1933
|
+
if (query.from._tag === "scope") {
|
|
1934
|
+
const scope = query.from.scope;
|
|
1935
|
+
const parts = [];
|
|
1936
|
+
if (scope.spaceIds !== void 0) {
|
|
1937
|
+
parts.push(`spaceIds: [${scope.spaceIds.map((s) => JSON.stringify(s)).join(", ")}]`);
|
|
1938
|
+
}
|
|
1939
|
+
if (scope.queues !== void 0) {
|
|
1940
|
+
parts.push(`queues: [${scope.queues.map(String).join(", ")}]`);
|
|
1941
|
+
}
|
|
1942
|
+
if (scope.allQueuesFromSpaces !== void 0) {
|
|
1943
|
+
parts.push(`allQueuesFromSpaces: ${scope.allQueuesFromSpaces}`);
|
|
1944
|
+
}
|
|
1945
|
+
return `${prettyQuery(query.query)}.from({ ${parts.join(", ")} })`;
|
|
1946
|
+
}
|
|
1947
|
+
return `${prettyQuery(query.query)}.from(${prettyQuery(query.from.query)})`;
|
|
1948
|
+
}
|
|
1949
|
+
case "limit":
|
|
1950
|
+
return `${prettyQuery(query.query)}.limit(${query.limit})`;
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
|
|
1954
|
+
// src/internal/Type/echo-schema.ts
|
|
1955
|
+
import * as Schema13 from "effect/Schema";
|
|
1956
|
+
import * as SchemaAST8 from "effect/SchemaAST";
|
|
1957
|
+
import { invariant as invariant17 } from "@dxos/invariant";
|
|
3363
1958
|
|
|
3364
|
-
// src/internal/
|
|
3365
|
-
import * as
|
|
3366
|
-
import * as
|
|
3367
|
-
import { invariant as
|
|
3368
|
-
import { DXN as
|
|
3369
|
-
var
|
|
1959
|
+
// src/internal/Type/manipulation.ts
|
|
1960
|
+
import * as Schema11 from "effect/Schema";
|
|
1961
|
+
import * as SchemaAST7 from "effect/SchemaAST";
|
|
1962
|
+
import { invariant as invariant16 } from "@dxos/invariant";
|
|
1963
|
+
import { DXN as DXN7 } from "@dxos/keys";
|
|
1964
|
+
var __dxlog_file16 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Type/manipulation.ts";
|
|
3370
1965
|
var addFieldsToSchema = (schema, fields) => {
|
|
3371
|
-
const schemaExtension =
|
|
3372
|
-
return
|
|
1966
|
+
const schemaExtension = Schema11.partial(Schema11.Struct(fields));
|
|
1967
|
+
return Schema11.extend(schema, schemaExtension).annotations(schema.ast.annotations);
|
|
3373
1968
|
};
|
|
3374
1969
|
var updateFieldsInSchema = (schema, fields) => {
|
|
3375
1970
|
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
|
-
});
|
|
1971
|
+
invariant16(SchemaAST7.isTypeLiteral(ast), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file16, L: 16, S: void 0, A: ["SchemaAST.isTypeLiteral(ast)", ""] });
|
|
3385
1972
|
const updatedProperties = [
|
|
3386
1973
|
...ast.propertySignatures
|
|
3387
1974
|
];
|
|
3388
|
-
const propertiesToUpdate =
|
|
1975
|
+
const propertiesToUpdate = Schema11.partial(Schema11.Struct(fields)).ast.propertySignatures;
|
|
3389
1976
|
for (const property of propertiesToUpdate) {
|
|
3390
1977
|
const index = updatedProperties.findIndex((p) => p.name === property.name);
|
|
3391
1978
|
if (index !== -1) {
|
|
@@ -3394,35 +1981,19 @@ var updateFieldsInSchema = (schema, fields) => {
|
|
|
3394
1981
|
updatedProperties.push(property);
|
|
3395
1982
|
}
|
|
3396
1983
|
}
|
|
3397
|
-
return
|
|
1984
|
+
return Schema11.make(new SchemaAST7.TypeLiteral(updatedProperties, ast.indexSignatures, ast.annotations));
|
|
3398
1985
|
};
|
|
3399
1986
|
var removeFieldsFromSchema = (schema, fieldNames) => {
|
|
3400
|
-
return
|
|
1987
|
+
return Schema11.make(SchemaAST7.omit(schema.ast, fieldNames)).annotations(schema.ast.annotations);
|
|
3401
1988
|
};
|
|
3402
1989
|
var updateFieldNameInSchema = (schema, { before, after }) => {
|
|
3403
1990
|
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));
|
|
1991
|
+
invariant16(SchemaAST7.isTypeLiteral(ast), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file16, L: 36, S: void 0, A: ["SchemaAST.isTypeLiteral(ast)", ""] });
|
|
1992
|
+
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
1993
|
};
|
|
3415
1994
|
var setTypenameInSchema = (schema, typename) => {
|
|
3416
1995
|
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
|
-
});
|
|
1996
|
+
invariant16(existingAnnotation, `Missing ${String(TypeAnnotationId)}`, { "~LogMeta": "~LogMeta", F: __dxlog_file16, L: 41, S: void 0, A: ["existingAnnotation", "`Missing ${String(TypeAnnotationId)}`"] });
|
|
3426
1997
|
return schema.annotations({
|
|
3427
1998
|
...schema.ast.annotations,
|
|
3428
1999
|
[TypeAnnotationId]: {
|
|
@@ -3430,53 +2001,45 @@ var setTypenameInSchema = (schema, typename) => {
|
|
|
3430
2001
|
typename,
|
|
3431
2002
|
version: existingAnnotation.version
|
|
3432
2003
|
},
|
|
3433
|
-
[
|
|
3434
|
-
...schema.ast.annotations[
|
|
3435
|
-
$id: schema.ast.annotations[TypeIdentifierAnnotationId] ??
|
|
2004
|
+
[SchemaAST7.JSONSchemaAnnotationId]: {
|
|
2005
|
+
...schema.ast.annotations[SchemaAST7.JSONSchemaAnnotationId] ?? {},
|
|
2006
|
+
$id: schema.ast.annotations[TypeIdentifierAnnotationId] ?? DXN7.fromTypename(typename).toString(),
|
|
3436
2007
|
typename
|
|
3437
2008
|
}
|
|
3438
2009
|
});
|
|
3439
2010
|
};
|
|
3440
2011
|
|
|
3441
|
-
// src/internal/
|
|
3442
|
-
import * as
|
|
3443
|
-
var PersistentSchema =
|
|
3444
|
-
name:
|
|
2012
|
+
// src/internal/Type/persistent-schema.ts
|
|
2013
|
+
import * as Schema12 from "effect/Schema";
|
|
2014
|
+
var PersistentSchema = Schema12.Struct({
|
|
2015
|
+
name: Schema12.optional(Schema12.String),
|
|
3445
2016
|
typename: TypenameSchema,
|
|
3446
2017
|
version: VersionSchema,
|
|
3447
2018
|
jsonSchema: JsonSchemaType
|
|
3448
2019
|
}).pipe(EchoObjectSchema({
|
|
3449
|
-
typename: "dxos.
|
|
2020
|
+
typename: "org.dxos.type.schema",
|
|
3450
2021
|
version: "0.1.0"
|
|
3451
2022
|
}), LabelAnnotation.set([
|
|
3452
2023
|
"name"
|
|
3453
2024
|
]), IconAnnotation.set({
|
|
3454
|
-
icon: "ph--
|
|
3455
|
-
hue: "
|
|
2025
|
+
icon: "ph--database--regular",
|
|
2026
|
+
hue: "green"
|
|
3456
2027
|
}));
|
|
3457
2028
|
|
|
3458
|
-
// src/internal/
|
|
3459
|
-
var
|
|
2029
|
+
// src/internal/Type/echo-schema.ts
|
|
2030
|
+
var __dxlog_file17 = "/__w/dxos/dxos/packages/core/echo/echo/src/internal/Type/echo-schema.ts";
|
|
3460
2031
|
var ImmutableSchema = class {
|
|
3461
2032
|
_schema;
|
|
3462
2033
|
_objectAnnotation;
|
|
3463
2034
|
constructor(_schema) {
|
|
3464
2035
|
this._schema = _schema;
|
|
3465
2036
|
this._objectAnnotation = getTypeAnnotation(this._schema);
|
|
3466
|
-
|
|
3467
|
-
F: __dxlog_file19,
|
|
3468
|
-
L: 49,
|
|
3469
|
-
S: this,
|
|
3470
|
-
A: [
|
|
3471
|
-
"this._objectAnnotation",
|
|
3472
|
-
""
|
|
3473
|
-
]
|
|
3474
|
-
});
|
|
2037
|
+
invariant17(this._objectAnnotation, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file17, L: 24, S: this, A: ["this._objectAnnotation", ""] });
|
|
3475
2038
|
}
|
|
3476
2039
|
//
|
|
3477
2040
|
// Effect Schema (push to abstract base class).
|
|
3478
2041
|
//
|
|
3479
|
-
get [
|
|
2042
|
+
get [Schema13.TypeId]() {
|
|
3480
2043
|
return schemaVariance2;
|
|
3481
2044
|
}
|
|
3482
2045
|
get Type() {
|
|
@@ -3529,9 +2092,9 @@ var ImmutableSchema = class {
|
|
|
3529
2092
|
var EchoSchemaConstructor = () => {
|
|
3530
2093
|
return class {
|
|
3531
2094
|
static get _schema() {
|
|
3532
|
-
return
|
|
2095
|
+
return Schema13.Union(PersistentSchema, Schema13.instanceOf(EchoSchema)).annotations(PersistentSchema.ast.annotations);
|
|
3533
2096
|
}
|
|
3534
|
-
static [
|
|
2097
|
+
static [Schema13.TypeId] = schemaVariance2;
|
|
3535
2098
|
static get ast() {
|
|
3536
2099
|
const schema = this._schema;
|
|
3537
2100
|
return schema.ast;
|
|
@@ -3569,7 +2132,7 @@ var EchoSchema = class extends EchoSchemaConstructor() {
|
|
|
3569
2132
|
//
|
|
3570
2133
|
// Effect Schema (push to abstract base class).
|
|
3571
2134
|
//
|
|
3572
|
-
get [
|
|
2135
|
+
get [Schema13.TypeId]() {
|
|
3573
2136
|
return schemaVariance2;
|
|
3574
2137
|
}
|
|
3575
2138
|
get Type() {
|
|
@@ -3625,15 +2188,7 @@ var EchoSchema = class extends EchoSchemaConstructor() {
|
|
|
3625
2188
|
* Returns a mutable schema.
|
|
3626
2189
|
*/
|
|
3627
2190
|
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
|
-
});
|
|
2191
|
+
invariant17(!this.readonly, "Schema is not mutable", { "~LogMeta": "~LogMeta", F: __dxlog_file17, L: 203, S: this, A: ["!this.readonly", "'Schema is not mutable'"] });
|
|
3637
2192
|
return this;
|
|
3638
2193
|
}
|
|
3639
2194
|
//
|
|
@@ -3666,15 +2221,7 @@ var EchoSchema = class extends EchoSchemaConstructor() {
|
|
|
3666
2221
|
}
|
|
3667
2222
|
getProperties() {
|
|
3668
2223
|
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
|
-
});
|
|
2224
|
+
invariant17(SchemaAST8.isTypeLiteral(ast), void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file17, L: 233, S: this, A: ["SchemaAST.isTypeLiteral(ast)", ""] });
|
|
3678
2225
|
return [
|
|
3679
2226
|
...ast.propertySignatures
|
|
3680
2227
|
].filter((p) => p.name !== "id").map(unwrapOptionality);
|
|
@@ -3734,7 +2281,7 @@ var EchoSchema = class extends EchoSchemaConstructor() {
|
|
|
3734
2281
|
});
|
|
3735
2282
|
}
|
|
3736
2283
|
/**
|
|
3737
|
-
* Wrapper for Obj.
|
|
2284
|
+
* Wrapper for Obj.update that handles the change context for the persistent schema.
|
|
3738
2285
|
*/
|
|
3739
2286
|
_change(callback) {
|
|
3740
2287
|
const changeFn = this._persistentSchema[ChangeId];
|
|
@@ -3768,12 +2315,12 @@ var EchoSchema = class extends EchoSchemaConstructor() {
|
|
|
3768
2315
|
}
|
|
3769
2316
|
};
|
|
3770
2317
|
var unwrapOptionality = (property) => {
|
|
3771
|
-
if (!
|
|
2318
|
+
if (!SchemaAST8.isUnion(property.type)) {
|
|
3772
2319
|
return property;
|
|
3773
2320
|
}
|
|
3774
2321
|
return {
|
|
3775
2322
|
...property,
|
|
3776
|
-
type: property.type.types.find((type) => !
|
|
2323
|
+
type: property.type.types.find((type) => !SchemaAST8.isUndefinedKeyword(type))
|
|
3777
2324
|
};
|
|
3778
2325
|
};
|
|
3779
2326
|
|
|
@@ -3786,75 +2333,28 @@ export {
|
|
|
3786
2333
|
foreignKey,
|
|
3787
2334
|
foreignKeyEquals,
|
|
3788
2335
|
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
2336
|
ATTR_SELF_DXN,
|
|
3803
2337
|
SelfDXNId,
|
|
3804
2338
|
ATTR_DELETED,
|
|
3805
2339
|
ObjectDeletedId,
|
|
3806
2340
|
ObjectVersionId,
|
|
3807
2341
|
ObjectDatabaseId,
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
2342
|
+
ATTR_RELATION_SOURCE,
|
|
2343
|
+
RelationSourceId,
|
|
2344
|
+
RelationSourceDXNId,
|
|
2345
|
+
ATTR_RELATION_TARGET,
|
|
2346
|
+
RelationTargetId,
|
|
2347
|
+
RelationTargetDXNId,
|
|
2348
|
+
VersionTypeId,
|
|
2349
|
+
compare,
|
|
2350
|
+
sortByLabel,
|
|
2351
|
+
sortByTypename,
|
|
2352
|
+
sort,
|
|
3813
2353
|
getMetaChecked,
|
|
3814
2354
|
getKeys,
|
|
3815
2355
|
deleteKeys,
|
|
3816
2356
|
addTag,
|
|
3817
2357
|
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
2358
|
EventId,
|
|
3859
2359
|
ChangeId,
|
|
3860
2360
|
batchEvents,
|
|
@@ -3892,6 +2392,21 @@ export {
|
|
|
3892
2392
|
makeObject,
|
|
3893
2393
|
subscribe,
|
|
3894
2394
|
change,
|
|
2395
|
+
assertObjectModel,
|
|
2396
|
+
getObjectDXN,
|
|
2397
|
+
getDXN,
|
|
2398
|
+
getDatabase,
|
|
2399
|
+
makeEchoTypeSchema,
|
|
2400
|
+
EchoObjectSchema,
|
|
2401
|
+
EchoRelationSchema,
|
|
2402
|
+
isVersion,
|
|
2403
|
+
version,
|
|
2404
|
+
versionValid,
|
|
2405
|
+
compareVersions,
|
|
2406
|
+
encodeVersion,
|
|
2407
|
+
decodeVersion,
|
|
2408
|
+
normalizeSchema,
|
|
2409
|
+
makeTypedEntityClass,
|
|
3895
2410
|
objectToJSON,
|
|
3896
2411
|
objectFromJSON,
|
|
3897
2412
|
setRefResolverOnData,
|
|
@@ -3902,6 +2417,8 @@ export {
|
|
|
3902
2417
|
setValue,
|
|
3903
2418
|
getSnapshot,
|
|
3904
2419
|
clone,
|
|
2420
|
+
prettyFilter,
|
|
2421
|
+
prettyQuery,
|
|
3905
2422
|
addFieldsToSchema,
|
|
3906
2423
|
updateFieldsInSchema,
|
|
3907
2424
|
removeFieldsFromSchema,
|
|
@@ -3911,9 +2428,9 @@ export {
|
|
|
3911
2428
|
ImmutableSchema,
|
|
3912
2429
|
isMutable,
|
|
3913
2430
|
EchoSchema,
|
|
3914
|
-
|
|
2431
|
+
JsonPath,
|
|
3915
2432
|
JsonProp,
|
|
3916
2433
|
getValue,
|
|
3917
2434
|
splitJsonPath
|
|
3918
2435
|
};
|
|
3919
|
-
//# sourceMappingURL=chunk-
|
|
2436
|
+
//# sourceMappingURL=chunk-AVPYX7FF.mjs.map
|