@dxos/echo 0.8.4-main.67995b8 → 0.8.4-main.69d29f4

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