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