@dxos/echo 0.8.4-main.3c1ae3b → 0.8.4-main.3eb6e50203

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