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

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