@dxos/echo 0.8.4-main.c85a9c8dae → 0.8.4-main.cb12b3f963

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