@dxos/echo 0.8.4-main.ef1bc66f44 → 0.8.4-main.f466a3d56e

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 (565) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +5 -5
  3. package/dist/lib/neutral/Annotation.mjs +7 -3
  4. package/dist/lib/neutral/Database.mjs +8 -4
  5. package/dist/lib/neutral/Entity.mjs +24 -14
  6. package/dist/lib/neutral/Err.mjs +3 -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 +52 -0
  10. package/dist/lib/neutral/Feed.mjs.map +7 -0
  11. package/dist/lib/neutral/Filter.mjs +23 -10
  12. package/dist/lib/neutral/Format.mjs +3 -3
  13. package/dist/lib/neutral/JsonSchema.mjs +9 -9
  14. package/dist/lib/neutral/Key.mjs +1 -1
  15. package/dist/lib/neutral/Migration.mjs +17 -0
  16. package/dist/lib/neutral/Migration.mjs.map +7 -0
  17. package/dist/lib/neutral/Obj.mjs +34 -17
  18. package/dist/lib/neutral/Order.mjs +1 -1
  19. package/dist/lib/neutral/Query.mjs +21 -9
  20. package/dist/lib/neutral/QueryResult.mjs +1 -1
  21. package/dist/lib/neutral/Ref.mjs +11 -7
  22. package/dist/lib/neutral/Relation.mjs +23 -13
  23. package/dist/lib/neutral/SchemaRegistry.mjs +1 -1
  24. package/dist/lib/neutral/Tag.mjs +14 -10
  25. package/dist/lib/neutral/Type.mjs +13 -23
  26. package/dist/lib/neutral/{chunk-N2QNHMT5.mjs → chunk-44HT3MEC.mjs} +2 -2
  27. package/dist/lib/neutral/{chunk-N2QNHMT5.mjs.map → chunk-44HT3MEC.mjs.map} +1 -1
  28. package/dist/lib/neutral/{chunk-XAJMXQ4H.mjs → chunk-5SL5LDLD.mjs} +6 -2
  29. package/dist/lib/neutral/chunk-5SL5LDLD.mjs.map +7 -0
  30. package/dist/lib/neutral/{chunk-ANHVGJI4.mjs → chunk-7RVZT53K.mjs} +1 -1
  31. package/dist/lib/neutral/chunk-APHSOTIX.mjs +34 -0
  32. package/dist/lib/neutral/chunk-APHSOTIX.mjs.map +7 -0
  33. package/dist/lib/neutral/{chunk-ZAHWXGK4.mjs → chunk-APJKDGFL.mjs} +85 -7
  34. package/dist/lib/neutral/chunk-APJKDGFL.mjs.map +7 -0
  35. package/dist/lib/neutral/{chunk-4L6DOFXP.mjs → chunk-BICZKPQG.mjs} +1 -1
  36. package/dist/lib/neutral/{chunk-4L6DOFXP.mjs.map → chunk-BICZKPQG.mjs.map} +1 -1
  37. package/dist/lib/neutral/chunk-BMB7IHGB.mjs +346 -0
  38. package/dist/lib/neutral/chunk-BMB7IHGB.mjs.map +7 -0
  39. package/dist/lib/neutral/chunk-FIWO2FZK.mjs +36 -0
  40. package/dist/lib/neutral/chunk-FIWO2FZK.mjs.map +7 -0
  41. package/dist/lib/neutral/chunk-G54OX4IX.mjs +2452 -0
  42. package/dist/lib/neutral/chunk-G54OX4IX.mjs.map +7 -0
  43. package/dist/lib/neutral/chunk-GWFFC34K.mjs +50 -0
  44. package/dist/lib/neutral/chunk-GWFFC34K.mjs.map +7 -0
  45. package/dist/lib/neutral/{chunk-LKFNEFHF.mjs → chunk-I2DARWPX.mjs} +18 -20
  46. package/dist/lib/neutral/chunk-I2DARWPX.mjs.map +7 -0
  47. package/dist/lib/neutral/chunk-J54QMAKF.mjs +421 -0
  48. package/dist/lib/neutral/chunk-J54QMAKF.mjs.map +7 -0
  49. package/dist/lib/neutral/chunk-MGSQGHOD.mjs +206 -0
  50. package/dist/lib/neutral/chunk-MGSQGHOD.mjs.map +7 -0
  51. package/dist/lib/neutral/chunk-MLS7U7AT.mjs +734 -0
  52. package/dist/lib/neutral/chunk-MLS7U7AT.mjs.map +7 -0
  53. package/dist/lib/neutral/{chunk-KB7RIVLK.mjs → chunk-N4B7FHQT.mjs} +4 -4
  54. package/dist/lib/neutral/{chunk-KB7RIVLK.mjs.map → chunk-N4B7FHQT.mjs.map} +2 -2
  55. package/dist/lib/neutral/{chunk-K5K3Z62A.mjs → chunk-N7VOEPSV.mjs} +11 -3
  56. package/dist/lib/neutral/chunk-N7VOEPSV.mjs.map +7 -0
  57. package/dist/lib/neutral/chunk-PSZBLH53.mjs +81 -0
  58. package/dist/lib/neutral/chunk-PSZBLH53.mjs.map +7 -0
  59. package/dist/lib/neutral/{chunk-MTEHHY62.mjs → chunk-PT37DG2F.mjs} +77 -58
  60. package/dist/lib/neutral/chunk-PT37DG2F.mjs.map +7 -0
  61. package/dist/lib/neutral/{chunk-DLPC7DHQ.mjs → chunk-Q2KKKJSV.mjs} +5 -5
  62. package/dist/lib/neutral/chunk-Q2KKKJSV.mjs.map +7 -0
  63. package/dist/lib/neutral/chunk-Q7ZL2P5H.mjs +320 -0
  64. package/dist/lib/neutral/chunk-Q7ZL2P5H.mjs.map +7 -0
  65. package/dist/lib/neutral/{chunk-QARLJVDB.mjs → chunk-QRZ2I3ZM.mjs} +8 -4
  66. package/dist/lib/neutral/chunk-QRZ2I3ZM.mjs.map +7 -0
  67. package/dist/lib/neutral/{chunk-VUQGRDRI.mjs → chunk-SCPFDS2E.mjs} +40 -12
  68. package/dist/lib/neutral/chunk-SCPFDS2E.mjs.map +7 -0
  69. package/dist/lib/neutral/{chunk-RIMHNJ3E.mjs → chunk-TNBK56IN.mjs} +98 -44
  70. package/dist/lib/neutral/chunk-TNBK56IN.mjs.map +7 -0
  71. package/dist/lib/neutral/{chunk-7WE7SBA2.mjs → chunk-TRPZU2HV.mjs} +13 -13
  72. package/dist/lib/neutral/chunk-TRPZU2HV.mjs.map +7 -0
  73. package/dist/lib/neutral/{chunk-ROKO4RKJ.mjs → chunk-TTCSATUD.mjs} +2 -2
  74. package/dist/lib/neutral/chunk-TTCSATUD.mjs.map +7 -0
  75. package/dist/lib/neutral/{chunk-OMUPQMLR.mjs → chunk-V72DY6LU.mjs} +1 -1
  76. package/dist/lib/neutral/chunk-ZFACXBY6.mjs +136 -0
  77. package/dist/lib/neutral/chunk-ZFACXBY6.mjs.map +7 -0
  78. package/dist/lib/neutral/{chunk-RPB6V4BE.mjs → chunk-ZISMEVKD.mjs} +14 -1
  79. package/dist/lib/neutral/chunk-ZISMEVKD.mjs.map +7 -0
  80. package/dist/lib/neutral/index.mjs +51 -28
  81. package/dist/lib/neutral/internal/index.mjs +52 -38
  82. package/dist/lib/neutral/meta.json +1 -1
  83. package/dist/lib/neutral/testing/index.mjs +199 -136
  84. package/dist/lib/neutral/testing/index.mjs.map +3 -3
  85. package/dist/types/src/Annotation.d.ts +3 -3
  86. package/dist/types/src/Annotation.d.ts.map +1 -1
  87. package/dist/types/src/Collection.d.ts +16 -0
  88. package/dist/types/src/Collection.d.ts.map +1 -0
  89. package/dist/types/src/Database.d.ts +21 -36
  90. package/dist/types/src/Database.d.ts.map +1 -1
  91. package/dist/types/src/Dataset.d.ts +19 -0
  92. package/dist/types/src/Dataset.d.ts.map +1 -0
  93. package/dist/types/src/Entity.d.ts +54 -22
  94. package/dist/types/src/Entity.d.ts.map +1 -1
  95. package/dist/types/src/Err.d.ts +55 -12
  96. package/dist/types/src/Err.d.ts.map +1 -1
  97. package/dist/types/src/Extension.d.ts +80 -0
  98. package/dist/types/src/Extension.d.ts.map +1 -0
  99. package/dist/types/src/Extension.test.d.ts +2 -0
  100. package/dist/types/src/Extension.test.d.ts.map +1 -0
  101. package/dist/types/src/Feed.d.ts +206 -0
  102. package/dist/types/src/Feed.d.ts.map +1 -0
  103. package/dist/types/src/Filter.d.ts +55 -5
  104. package/dist/types/src/Filter.d.ts.map +1 -1
  105. package/dist/types/src/Filter.test.d.ts +2 -0
  106. package/dist/types/src/Filter.test.d.ts.map +1 -0
  107. package/dist/types/src/Format.d.ts +3 -3
  108. package/dist/types/src/Format.d.ts.map +1 -1
  109. package/dist/types/src/Hypergraph.d.ts +11 -6
  110. package/dist/types/src/Hypergraph.d.ts.map +1 -1
  111. package/dist/types/src/Json.d.ts +33 -0
  112. package/dist/types/src/Json.d.ts.map +1 -0
  113. package/dist/types/src/Json.test.d.ts +2 -0
  114. package/dist/types/src/Json.test.d.ts.map +1 -0
  115. package/dist/types/src/JsonSchema.d.ts +11 -4
  116. package/dist/types/src/JsonSchema.d.ts.map +1 -1
  117. package/dist/types/src/Migration.d.ts +69 -0
  118. package/dist/types/src/Migration.d.ts.map +1 -0
  119. package/dist/types/src/Obj.d.ts +163 -59
  120. package/dist/types/src/Obj.d.ts.map +1 -1
  121. package/dist/types/src/Order.d.ts.map +1 -1
  122. package/dist/types/src/Query.d.ts +105 -17
  123. package/dist/types/src/Query.d.ts.map +1 -1
  124. package/dist/types/src/Ref.d.ts +59 -10
  125. package/dist/types/src/Ref.d.ts.map +1 -1
  126. package/dist/types/src/Relation.d.ts +86 -40
  127. package/dist/types/src/Relation.d.ts.map +1 -1
  128. package/dist/types/src/SchemaRegistry.d.ts +4 -4
  129. package/dist/types/src/SchemaRegistry.d.ts.map +1 -1
  130. package/dist/types/src/Tag.d.ts +2 -1
  131. package/dist/types/src/Tag.d.ts.map +1 -1
  132. package/dist/types/src/Type.d.ts +51 -180
  133. package/dist/types/src/Type.d.ts.map +1 -1
  134. package/dist/types/src/View.d.ts +68 -0
  135. package/dist/types/src/View.d.ts.map +1 -0
  136. package/dist/types/src/exemplars.test.d.ts +2 -0
  137. package/dist/types/src/exemplars.test.d.ts.map +1 -0
  138. package/dist/types/src/index.d.ts +7 -0
  139. package/dist/types/src/index.d.ts.map +1 -1
  140. package/dist/types/src/internal/{annotations → Annotation}/annotations.d.ts +65 -2
  141. package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -0
  142. package/dist/types/src/internal/Annotation/annotations.test.d.ts.map +1 -0
  143. package/dist/types/src/internal/Annotation/index.d.ts +4 -0
  144. package/dist/types/src/internal/Annotation/index.d.ts.map +1 -0
  145. package/dist/types/src/internal/{api → Annotation}/sorting.d.ts +1 -1
  146. package/dist/types/src/internal/Annotation/sorting.d.ts.map +1 -0
  147. package/dist/types/src/internal/{annotations → Annotation}/util.d.ts +2 -2
  148. package/dist/types/src/internal/Annotation/util.d.ts.map +1 -0
  149. package/dist/types/src/internal/{api/entity.d.ts → Entity/api.d.ts} +2 -2
  150. package/dist/types/src/internal/Entity/api.d.ts.map +1 -0
  151. package/dist/types/src/internal/{entities → Entity}/entity.d.ts +3 -3
  152. package/dist/types/src/internal/Entity/entity.d.ts.map +1 -0
  153. package/dist/types/src/internal/{entities → Entity}/index.d.ts +2 -0
  154. package/dist/types/src/internal/Entity/index.d.ts.map +1 -0
  155. package/dist/types/src/internal/{entities → Entity}/model.d.ts +4 -26
  156. package/dist/types/src/internal/Entity/model.d.ts.map +1 -0
  157. package/dist/types/src/internal/{entities → Entity}/object.d.ts +2 -2
  158. package/dist/types/src/internal/Entity/object.d.ts.map +1 -0
  159. package/dist/types/src/internal/{entities → Entity}/relation.d.ts +3 -30
  160. package/dist/types/src/internal/Entity/relation.d.ts.map +1 -0
  161. package/dist/types/src/internal/Entity/util.d.ts.map +1 -0
  162. package/dist/types/src/internal/{api → Entity}/version.d.ts +1 -1
  163. package/dist/types/src/internal/Entity/version.d.ts.map +1 -0
  164. package/dist/types/src/internal/Format/date.d.ts.map +1 -0
  165. package/dist/types/src/internal/Format/date.test.d.ts.map +1 -0
  166. package/dist/types/src/internal/Format/format.d.ts.map +1 -0
  167. package/dist/types/src/internal/Format/format.test.d.ts.map +1 -0
  168. package/dist/types/src/internal/Format/index.d.ts.map +1 -0
  169. package/dist/types/src/internal/Format/number.d.ts.map +1 -0
  170. package/dist/types/src/internal/Format/object.d.ts.map +1 -0
  171. package/dist/types/src/internal/Format/select.d.ts.map +1 -0
  172. package/dist/types/src/internal/Format/string.d.ts.map +1 -0
  173. package/dist/types/src/internal/{formats → Format}/types.d.ts +1 -1
  174. package/dist/types/src/internal/Format/types.d.ts.map +1 -0
  175. package/dist/types/src/internal/{json-schema → JsonSchema}/annotations.d.ts +1 -1
  176. package/dist/types/src/internal/JsonSchema/annotations.d.ts.map +1 -0
  177. package/dist/types/src/internal/JsonSchema/effect-schema.test.d.ts.map +1 -0
  178. package/dist/types/src/internal/JsonSchema/index.d.ts.map +1 -0
  179. package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts.map +1 -0
  180. package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema-type.d.ts +37 -37
  181. package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -0
  182. package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema.d.ts +1 -1
  183. package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -0
  184. package/dist/types/src/internal/JsonSchema/json-schema.test.d.ts.map +1 -0
  185. package/dist/types/src/internal/Obj/clone.d.ts.map +1 -0
  186. package/dist/types/src/internal/Obj/common.d.ts.map +1 -0
  187. package/dist/types/src/internal/{object → Obj}/create-object.d.ts +2 -2
  188. package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -0
  189. package/dist/types/src/internal/Obj/create-object.test.d.ts.map +1 -0
  190. package/dist/types/src/internal/{object → Obj}/deleted.d.ts +1 -1
  191. package/dist/types/src/internal/Obj/deleted.d.ts.map +1 -0
  192. package/dist/types/src/internal/{object → Obj}/ids.d.ts +1 -1
  193. package/dist/types/src/internal/Obj/ids.d.ts.map +1 -0
  194. package/dist/types/src/internal/Obj/index.d.ts.map +1 -0
  195. package/dist/types/src/internal/Obj/inspect.d.ts.map +1 -0
  196. package/dist/types/src/internal/{object → Obj}/json-serializer.d.ts +13 -5
  197. package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -0
  198. package/dist/types/src/internal/Obj/json-serializer.test.d.ts.map +1 -0
  199. package/dist/types/src/internal/Obj/schema-validator.d.ts +2 -0
  200. package/dist/types/src/internal/Obj/schema-validator.d.ts.map +1 -0
  201. package/dist/types/src/internal/Obj/schema-validator.test.d.ts.map +1 -0
  202. package/dist/types/src/internal/{object → Obj}/set-value.d.ts +2 -2
  203. package/dist/types/src/internal/Obj/set-value.d.ts.map +1 -0
  204. package/dist/types/src/internal/Obj/set-value.test.d.ts.map +1 -0
  205. package/dist/types/src/internal/Obj/snapshot.d.ts.map +1 -0
  206. package/dist/types/src/internal/{object → Obj}/typed-object.d.ts +4 -4
  207. package/dist/types/src/internal/Obj/typed-object.d.ts.map +1 -0
  208. package/dist/types/src/internal/Obj/typed-object.test.d.ts.map +1 -0
  209. package/dist/types/src/internal/Query.d.ts +10 -0
  210. package/dist/types/src/internal/Query.d.ts.map +1 -0
  211. package/dist/types/src/internal/Ref/index.d.ts.map +1 -0
  212. package/dist/types/src/internal/{ref → Ref}/ref-array.d.ts +1 -1
  213. package/dist/types/src/internal/Ref/ref-array.d.ts.map +1 -0
  214. package/dist/types/src/internal/{ref → Ref}/ref.d.ts +15 -2
  215. package/dist/types/src/internal/Ref/ref.d.ts.map +1 -0
  216. package/dist/types/src/internal/Ref/ref.test.d.ts.map +1 -0
  217. package/dist/types/src/internal/{schema → Type}/compose.d.ts +1 -1
  218. package/dist/types/src/internal/Type/compose.d.ts.map +1 -0
  219. package/dist/types/src/internal/Type/compose.test.d.ts.map +1 -0
  220. package/dist/types/src/internal/{schema → Type}/echo-schema.d.ts +7 -7
  221. package/dist/types/src/internal/Type/echo-schema.d.ts.map +1 -0
  222. package/dist/types/src/internal/Type/index.d.ts.map +1 -0
  223. package/dist/types/src/internal/Type/manipulation.d.ts.map +1 -0
  224. package/dist/types/src/internal/{schema → Type}/persistent-schema.d.ts +2 -2
  225. package/dist/types/src/internal/Type/persistent-schema.d.ts.map +1 -0
  226. package/dist/types/src/internal/{api → common/api}/index.d.ts +0 -4
  227. package/dist/types/src/internal/common/api/index.d.ts.map +1 -0
  228. package/dist/types/src/internal/{api → common/api}/meta.d.ts +3 -3
  229. package/dist/types/src/internal/common/api/meta.d.ts.map +1 -0
  230. package/dist/types/src/internal/common/index.d.ts +4 -0
  231. package/dist/types/src/internal/common/index.d.ts.map +1 -0
  232. package/dist/types/src/internal/{proxy → common/proxy}/change-context.d.ts +1 -1
  233. package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -0
  234. package/dist/types/src/internal/common/proxy/change.test.d.ts.map +1 -0
  235. package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts.map +1 -0
  236. package/dist/types/src/internal/{proxy → common/proxy}/errors.d.ts +1 -1
  237. package/dist/types/src/internal/common/proxy/errors.d.ts.map +1 -0
  238. package/dist/types/src/internal/common/proxy/event-batch.d.ts.map +1 -0
  239. package/dist/types/src/internal/common/proxy/handler.test.d.ts.map +1 -0
  240. package/dist/types/src/internal/common/proxy/index.d.ts.map +1 -0
  241. package/dist/types/src/internal/common/proxy/json-serializer.d.ts.map +1 -0
  242. package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -0
  243. package/dist/types/src/internal/common/proxy/ownership.d.ts.map +1 -0
  244. package/dist/types/src/internal/common/proxy/proxy-types.d.ts.map +1 -0
  245. package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -0
  246. package/dist/types/src/internal/{proxy → common/proxy}/reactive-array.d.ts +1 -1
  247. package/dist/types/src/internal/common/proxy/reactive-array.d.ts.map +1 -0
  248. package/dist/types/src/internal/{proxy → common/proxy}/reactive.d.ts +2 -2
  249. package/dist/types/src/internal/{proxy → common/proxy}/reactive.d.ts.map +1 -1
  250. package/dist/types/src/internal/common/proxy/reactive.test.d.ts +2 -0
  251. package/dist/types/src/internal/common/proxy/reactive.test.d.ts.map +1 -0
  252. package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -0
  253. package/dist/types/src/internal/common/proxy/schema.test.d.ts.map +1 -0
  254. package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -0
  255. package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -0
  256. package/dist/types/src/internal/common/proxy/typed-handler.test.d.ts.map +1 -0
  257. package/dist/types/src/internal/common/proxy/typed-object.test.d.ts.map +1 -0
  258. package/dist/types/src/internal/{types → common/types}/base.d.ts +1 -0
  259. package/dist/types/src/internal/common/types/base.d.ts.map +1 -0
  260. package/dist/types/src/internal/{types → common/types}/entity.d.ts +5 -5
  261. package/dist/types/src/internal/common/types/entity.d.ts.map +1 -0
  262. package/dist/types/src/internal/{types → common/types}/index.d.ts +1 -0
  263. package/dist/types/src/internal/common/types/index.d.ts.map +1 -0
  264. package/dist/types/src/internal/{types → common/types}/meta.d.ts +12 -1
  265. package/dist/types/src/internal/common/types/meta.d.ts.map +1 -0
  266. package/dist/types/src/internal/common/types/model-symbols.d.ts +54 -0
  267. package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -0
  268. package/dist/types/src/internal/common/types/typename.d.ts.map +1 -0
  269. package/dist/types/src/internal/{types → common/types}/version.d.ts +2 -2
  270. package/dist/types/src/internal/common/types/version.d.ts.map +1 -0
  271. package/dist/types/src/internal/index.d.ts +9 -10
  272. package/dist/types/src/internal/index.d.ts.map +1 -1
  273. package/dist/types/src/testing/test-data.d.ts +8 -8
  274. package/dist/types/src/testing/test-data.d.ts.map +1 -1
  275. package/dist/types/src/testing/test-schema.d.ts +47 -46
  276. package/dist/types/src/testing/test-schema.d.ts.map +1 -1
  277. package/dist/types/src/testing/util.d.ts.map +1 -1
  278. package/dist/types/tsconfig.tsbuildinfo +1 -1
  279. package/package.json +30 -15
  280. package/src/Annotation.ts +7 -3
  281. package/src/Collection.ts +37 -0
  282. package/src/Database.ts +64 -65
  283. package/src/Dataset.ts +26 -0
  284. package/src/Entity.ts +87 -61
  285. package/src/Err.ts +22 -0
  286. package/src/Extension.test.ts +235 -0
  287. package/src/Extension.ts +122 -0
  288. package/src/Feed.ts +335 -0
  289. package/src/Filter.test.ts +90 -0
  290. package/src/Filter.ts +116 -7
  291. package/src/Format.ts +3 -3
  292. package/src/Hypergraph.ts +12 -7
  293. package/src/Json.test.ts +175 -0
  294. package/src/Json.ts +102 -0
  295. package/src/JsonSchema.ts +14 -4
  296. package/src/Migration.ts +106 -0
  297. package/src/Obj.test.ts +142 -15
  298. package/src/Obj.ts +382 -161
  299. package/src/Order.ts +3 -1
  300. package/src/Query.test.ts +372 -15
  301. package/src/Query.ts +274 -26
  302. package/src/Ref.ts +66 -11
  303. package/src/Relation.test.ts +8 -2
  304. package/src/Relation.ts +183 -147
  305. package/src/SchemaRegistry.ts +5 -4
  306. package/src/Tag.ts +6 -5
  307. package/src/Type.test.ts +10 -10
  308. package/src/Type.ts +70 -303
  309. package/src/View.ts +107 -0
  310. package/src/exemplars.test.ts +21 -0
  311. package/src/index.ts +8 -0
  312. package/src/internal/{annotations → Annotation}/annotations.test.ts +56 -7
  313. package/src/internal/{annotations → Annotation}/annotations.ts +122 -19
  314. package/src/internal/{annotations → Annotation}/index.ts +1 -0
  315. package/src/internal/{api → Annotation}/sorting.ts +2 -4
  316. package/src/internal/{annotations → Annotation}/util.ts +1 -1
  317. package/src/internal/{api/entity.ts → Entity/api.ts} +3 -2
  318. package/src/internal/{entities → Entity}/entity.ts +6 -4
  319. package/src/internal/{entities → Entity}/index.ts +2 -0
  320. package/src/internal/{entities → Entity}/model.ts +15 -42
  321. package/src/internal/{entities → Entity}/object.ts +2 -3
  322. package/src/internal/{entities → Entity}/relation.ts +19 -36
  323. package/src/internal/{api → Entity}/version.ts +2 -2
  324. package/src/internal/{formats → Format}/date.test.ts +1 -2
  325. package/src/internal/{formats → Format}/format.test.ts +1 -2
  326. package/src/internal/{formats → Format}/types.ts +2 -2
  327. package/src/internal/{json-schema → JsonSchema}/annotations.ts +3 -3
  328. package/src/internal/{json-schema → JsonSchema}/json-schema-type.ts +4 -4
  329. package/src/internal/{json-schema → JsonSchema}/json-schema.test.ts +48 -49
  330. package/src/internal/{json-schema → JsonSchema}/json-schema.ts +6 -5
  331. package/src/internal/{object → Obj}/clone.ts +3 -3
  332. package/src/internal/{object → Obj}/common.ts +2 -2
  333. package/src/internal/{object → Obj}/create-object.test.ts +5 -7
  334. package/src/internal/{object → Obj}/create-object.ts +5 -6
  335. package/src/internal/{object → Obj}/deleted.ts +2 -2
  336. package/src/internal/{object → Obj}/ids.ts +1 -1
  337. package/src/internal/{object → Obj}/inspect.ts +2 -2
  338. package/src/internal/{object → Obj}/json-serializer.test.ts +31 -9
  339. package/src/internal/{object → Obj}/json-serializer.ts +60 -35
  340. package/src/internal/{object → Obj}/schema-validator.ts +1 -1
  341. package/src/internal/{object → Obj}/set-value.test.ts +24 -24
  342. package/src/internal/{object → Obj}/set-value.ts +3 -3
  343. package/src/internal/{object → Obj}/snapshot.ts +35 -23
  344. package/src/internal/{object → Obj}/typed-object.test.ts +3 -3
  345. package/src/internal/{object → Obj}/typed-object.ts +4 -4
  346. package/src/internal/Query.ts +156 -0
  347. package/src/internal/{ref → Ref}/ref-array.ts +1 -2
  348. package/src/internal/{ref → Ref}/ref.test.ts +4 -5
  349. package/src/internal/{ref → Ref}/ref.ts +20 -3
  350. package/src/internal/{schema → Type}/compose.test.ts +5 -6
  351. package/src/internal/{schema → Type}/compose.ts +1 -1
  352. package/src/internal/{schema → Type}/echo-schema.ts +9 -10
  353. package/src/internal/{schema → Type}/manipulation.ts +1 -1
  354. package/src/internal/{schema → Type}/persistent-schema.ts +9 -4
  355. package/src/internal/{README.md → common/README.md} +2 -2
  356. package/src/internal/{api → common/api}/index.ts +0 -4
  357. package/src/internal/{api → common/api}/meta.ts +3 -3
  358. package/src/internal/common/index.ts +7 -0
  359. package/src/internal/{proxy → common/proxy}/change-context.ts +1 -1
  360. package/src/internal/{proxy → common/proxy}/change.test.ts +97 -97
  361. package/src/internal/{proxy → common/proxy}/errors.ts +2 -2
  362. package/src/internal/{proxy → common/proxy}/handler.test.ts +2 -4
  363. package/src/internal/{proxy → common/proxy}/json-serializer.ts +6 -3
  364. package/src/internal/{proxy → common/proxy}/make-object.ts +1 -2
  365. package/src/internal/{proxy → common/proxy}/ownership.ts +0 -1
  366. package/src/internal/{proxy → common/proxy}/reactive-array.ts +1 -1
  367. package/src/internal/common/proxy/reactive.test.ts +54 -0
  368. package/src/internal/{proxy → common/proxy}/reactive.ts +12 -4
  369. package/src/internal/{proxy → common/proxy}/schema.test.ts +10 -10
  370. package/src/internal/{proxy → common/proxy}/typed-handler.test.ts +6 -7
  371. package/src/internal/{proxy → common/proxy}/typed-handler.ts +10 -13
  372. package/src/internal/{proxy → common/proxy}/typed-object.test.ts +5 -6
  373. package/src/internal/{types → common/types}/base.ts +1 -1
  374. package/src/internal/{types → common/types}/entity.ts +2 -2
  375. package/src/internal/{types → common/types}/index.ts +1 -0
  376. package/src/internal/{types → common/types}/meta.ts +15 -1
  377. package/src/internal/common/types/model-symbols.ts +69 -0
  378. package/src/internal/{types → common/types}/version.ts +2 -3
  379. package/src/internal/index.ts +9 -31
  380. package/src/testing/api.test.ts +4 -5
  381. package/src/testing/test-data.ts +157 -98
  382. package/src/testing/test-schema.ts +20 -18
  383. package/dist/lib/neutral/chunk-2AF5GMG6.mjs +0 -171
  384. package/dist/lib/neutral/chunk-2AF5GMG6.mjs.map +0 -7
  385. package/dist/lib/neutral/chunk-7WE7SBA2.mjs.map +0 -7
  386. package/dist/lib/neutral/chunk-DLPC7DHQ.mjs.map +0 -7
  387. package/dist/lib/neutral/chunk-EBUAT5ID.mjs +0 -229
  388. package/dist/lib/neutral/chunk-EBUAT5ID.mjs.map +0 -7
  389. package/dist/lib/neutral/chunk-K5K3Z62A.mjs.map +0 -7
  390. package/dist/lib/neutral/chunk-LKFNEFHF.mjs.map +0 -7
  391. package/dist/lib/neutral/chunk-MTEHHY62.mjs.map +0 -7
  392. package/dist/lib/neutral/chunk-QARLJVDB.mjs.map +0 -7
  393. package/dist/lib/neutral/chunk-RIMHNJ3E.mjs.map +0 -7
  394. package/dist/lib/neutral/chunk-ROKO4RKJ.mjs.map +0 -7
  395. package/dist/lib/neutral/chunk-RPB6V4BE.mjs.map +0 -7
  396. package/dist/lib/neutral/chunk-TLGNKUUG.mjs +0 -3905
  397. package/dist/lib/neutral/chunk-TLGNKUUG.mjs.map +0 -7
  398. package/dist/lib/neutral/chunk-TQT6WTIJ.mjs +0 -142
  399. package/dist/lib/neutral/chunk-TQT6WTIJ.mjs.map +0 -7
  400. package/dist/lib/neutral/chunk-VUQGRDRI.mjs.map +0 -7
  401. package/dist/lib/neutral/chunk-X2MPMYYN.mjs +0 -13
  402. package/dist/lib/neutral/chunk-X2MPMYYN.mjs.map +0 -7
  403. package/dist/lib/neutral/chunk-XAJMXQ4H.mjs.map +0 -7
  404. package/dist/lib/neutral/chunk-ZAHWXGK4.mjs.map +0 -7
  405. package/dist/types/src/internal/annotations/annotations.d.ts.map +0 -1
  406. package/dist/types/src/internal/annotations/annotations.test.d.ts.map +0 -1
  407. package/dist/types/src/internal/annotations/index.d.ts +0 -3
  408. package/dist/types/src/internal/annotations/index.d.ts.map +0 -1
  409. package/dist/types/src/internal/annotations/util.d.ts.map +0 -1
  410. package/dist/types/src/internal/api/annotations.d.ts +0 -23
  411. package/dist/types/src/internal/api/annotations.d.ts.map +0 -1
  412. package/dist/types/src/internal/api/entity.d.ts.map +0 -1
  413. package/dist/types/src/internal/api/index.d.ts.map +0 -1
  414. package/dist/types/src/internal/api/meta.d.ts.map +0 -1
  415. package/dist/types/src/internal/api/sorting.d.ts.map +0 -1
  416. package/dist/types/src/internal/api/version.d.ts.map +0 -1
  417. package/dist/types/src/internal/entities/entity.d.ts.map +0 -1
  418. package/dist/types/src/internal/entities/index.d.ts.map +0 -1
  419. package/dist/types/src/internal/entities/model.d.ts.map +0 -1
  420. package/dist/types/src/internal/entities/object.d.ts.map +0 -1
  421. package/dist/types/src/internal/entities/relation.d.ts.map +0 -1
  422. package/dist/types/src/internal/entities/util.d.ts.map +0 -1
  423. package/dist/types/src/internal/formats/date.d.ts.map +0 -1
  424. package/dist/types/src/internal/formats/date.test.d.ts.map +0 -1
  425. package/dist/types/src/internal/formats/format.d.ts.map +0 -1
  426. package/dist/types/src/internal/formats/format.test.d.ts.map +0 -1
  427. package/dist/types/src/internal/formats/index.d.ts.map +0 -1
  428. package/dist/types/src/internal/formats/number.d.ts.map +0 -1
  429. package/dist/types/src/internal/formats/object.d.ts.map +0 -1
  430. package/dist/types/src/internal/formats/select.d.ts.map +0 -1
  431. package/dist/types/src/internal/formats/string.d.ts.map +0 -1
  432. package/dist/types/src/internal/formats/types.d.ts.map +0 -1
  433. package/dist/types/src/internal/json-schema/annotations.d.ts.map +0 -1
  434. package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +0 -1
  435. package/dist/types/src/internal/json-schema/index.d.ts.map +0 -1
  436. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +0 -1
  437. package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +0 -1
  438. package/dist/types/src/internal/json-schema/json-schema.d.ts.map +0 -1
  439. package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +0 -1
  440. package/dist/types/src/internal/object/clone.d.ts.map +0 -1
  441. package/dist/types/src/internal/object/common.d.ts.map +0 -1
  442. package/dist/types/src/internal/object/create-object.d.ts.map +0 -1
  443. package/dist/types/src/internal/object/create-object.test.d.ts.map +0 -1
  444. package/dist/types/src/internal/object/deleted.d.ts.map +0 -1
  445. package/dist/types/src/internal/object/ids.d.ts.map +0 -1
  446. package/dist/types/src/internal/object/index.d.ts.map +0 -1
  447. package/dist/types/src/internal/object/inspect.d.ts.map +0 -1
  448. package/dist/types/src/internal/object/json-serializer.d.ts.map +0 -1
  449. package/dist/types/src/internal/object/json-serializer.test.d.ts.map +0 -1
  450. package/dist/types/src/internal/object/schema-validator.d.ts +0 -2
  451. package/dist/types/src/internal/object/schema-validator.d.ts.map +0 -1
  452. package/dist/types/src/internal/object/schema-validator.test.d.ts.map +0 -1
  453. package/dist/types/src/internal/object/set-value.d.ts.map +0 -1
  454. package/dist/types/src/internal/object/set-value.test.d.ts.map +0 -1
  455. package/dist/types/src/internal/object/snapshot.d.ts.map +0 -1
  456. package/dist/types/src/internal/object/typed-object.d.ts.map +0 -1
  457. package/dist/types/src/internal/object/typed-object.test.d.ts.map +0 -1
  458. package/dist/types/src/internal/proxy/change-context.d.ts.map +0 -1
  459. package/dist/types/src/internal/proxy/change.test.d.ts.map +0 -1
  460. package/dist/types/src/internal/proxy/define-hidden-property.d.ts.map +0 -1
  461. package/dist/types/src/internal/proxy/errors.d.ts.map +0 -1
  462. package/dist/types/src/internal/proxy/event-batch.d.ts.map +0 -1
  463. package/dist/types/src/internal/proxy/handler.test.d.ts.map +0 -1
  464. package/dist/types/src/internal/proxy/index.d.ts.map +0 -1
  465. package/dist/types/src/internal/proxy/json-serializer.d.ts.map +0 -1
  466. package/dist/types/src/internal/proxy/make-object.d.ts.map +0 -1
  467. package/dist/types/src/internal/proxy/ownership.d.ts.map +0 -1
  468. package/dist/types/src/internal/proxy/proxy-types.d.ts.map +0 -1
  469. package/dist/types/src/internal/proxy/proxy-utils.d.ts.map +0 -1
  470. package/dist/types/src/internal/proxy/reactive-array.d.ts.map +0 -1
  471. package/dist/types/src/internal/proxy/schema-validator.d.ts.map +0 -1
  472. package/dist/types/src/internal/proxy/schema.test.d.ts.map +0 -1
  473. package/dist/types/src/internal/proxy/symbols.d.ts.map +0 -1
  474. package/dist/types/src/internal/proxy/typed-handler.d.ts.map +0 -1
  475. package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +0 -1
  476. package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +0 -1
  477. package/dist/types/src/internal/ref/index.d.ts.map +0 -1
  478. package/dist/types/src/internal/ref/ref-array.d.ts.map +0 -1
  479. package/dist/types/src/internal/ref/ref.d.ts.map +0 -1
  480. package/dist/types/src/internal/ref/ref.test.d.ts.map +0 -1
  481. package/dist/types/src/internal/schema/compose.d.ts.map +0 -1
  482. package/dist/types/src/internal/schema/compose.test.d.ts.map +0 -1
  483. package/dist/types/src/internal/schema/echo-schema.d.ts.map +0 -1
  484. package/dist/types/src/internal/schema/index.d.ts.map +0 -1
  485. package/dist/types/src/internal/schema/manipulation.d.ts.map +0 -1
  486. package/dist/types/src/internal/schema/persistent-schema.d.ts.map +0 -1
  487. package/dist/types/src/internal/types/base.d.ts.map +0 -1
  488. package/dist/types/src/internal/types/entity.d.ts.map +0 -1
  489. package/dist/types/src/internal/types/index.d.ts.map +0 -1
  490. package/dist/types/src/internal/types/meta.d.ts.map +0 -1
  491. package/dist/types/src/internal/types/typename.d.ts.map +0 -1
  492. package/dist/types/src/internal/types/version.d.ts.map +0 -1
  493. package/src/internal/api/annotations.ts +0 -60
  494. /package/dist/lib/neutral/{chunk-ANHVGJI4.mjs.map → chunk-7RVZT53K.mjs.map} +0 -0
  495. /package/dist/lib/neutral/{chunk-OMUPQMLR.mjs.map → chunk-V72DY6LU.mjs.map} +0 -0
  496. /package/dist/types/src/internal/{annotations → Annotation}/annotations.test.d.ts +0 -0
  497. /package/dist/types/src/internal/{entities → Entity}/util.d.ts +0 -0
  498. /package/dist/types/src/internal/{formats → Format}/date.d.ts +0 -0
  499. /package/dist/types/src/internal/{formats → Format}/date.test.d.ts +0 -0
  500. /package/dist/types/src/internal/{formats → Format}/format.d.ts +0 -0
  501. /package/dist/types/src/internal/{formats → Format}/format.test.d.ts +0 -0
  502. /package/dist/types/src/internal/{formats → Format}/index.d.ts +0 -0
  503. /package/dist/types/src/internal/{formats → Format}/number.d.ts +0 -0
  504. /package/dist/types/src/internal/{formats → Format}/object.d.ts +0 -0
  505. /package/dist/types/src/internal/{formats → Format}/select.d.ts +0 -0
  506. /package/dist/types/src/internal/{formats → Format}/string.d.ts +0 -0
  507. /package/dist/types/src/internal/{json-schema → JsonSchema}/effect-schema.test.d.ts +0 -0
  508. /package/dist/types/src/internal/{json-schema → JsonSchema}/index.d.ts +0 -0
  509. /package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema-normalize.d.ts +0 -0
  510. /package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema.test.d.ts +0 -0
  511. /package/dist/types/src/internal/{object → Obj}/clone.d.ts +0 -0
  512. /package/dist/types/src/internal/{object → Obj}/common.d.ts +0 -0
  513. /package/dist/types/src/internal/{object → Obj}/create-object.test.d.ts +0 -0
  514. /package/dist/types/src/internal/{object → Obj}/index.d.ts +0 -0
  515. /package/dist/types/src/internal/{object → Obj}/inspect.d.ts +0 -0
  516. /package/dist/types/src/internal/{object → Obj}/json-serializer.test.d.ts +0 -0
  517. /package/dist/types/src/internal/{object → Obj}/schema-validator.test.d.ts +0 -0
  518. /package/dist/types/src/internal/{object → Obj}/set-value.test.d.ts +0 -0
  519. /package/dist/types/src/internal/{object → Obj}/snapshot.d.ts +0 -0
  520. /package/dist/types/src/internal/{object → Obj}/typed-object.test.d.ts +0 -0
  521. /package/dist/types/src/internal/{ref → Ref}/index.d.ts +0 -0
  522. /package/dist/types/src/internal/{ref → Ref}/ref.test.d.ts +0 -0
  523. /package/dist/types/src/internal/{schema → Type}/compose.test.d.ts +0 -0
  524. /package/dist/types/src/internal/{schema → Type}/index.d.ts +0 -0
  525. /package/dist/types/src/internal/{schema → Type}/manipulation.d.ts +0 -0
  526. /package/dist/types/src/internal/{proxy → common/proxy}/change.test.d.ts +0 -0
  527. /package/dist/types/src/internal/{proxy → common/proxy}/define-hidden-property.d.ts +0 -0
  528. /package/dist/types/src/internal/{proxy → common/proxy}/event-batch.d.ts +0 -0
  529. /package/dist/types/src/internal/{proxy → common/proxy}/handler.test.d.ts +0 -0
  530. /package/dist/types/src/internal/{proxy → common/proxy}/index.d.ts +0 -0
  531. /package/dist/types/src/internal/{proxy → common/proxy}/json-serializer.d.ts +0 -0
  532. /package/dist/types/src/internal/{proxy → common/proxy}/make-object.d.ts +0 -0
  533. /package/dist/types/src/internal/{proxy → common/proxy}/ownership.d.ts +0 -0
  534. /package/dist/types/src/internal/{proxy → common/proxy}/proxy-types.d.ts +0 -0
  535. /package/dist/types/src/internal/{proxy → common/proxy}/proxy-utils.d.ts +0 -0
  536. /package/dist/types/src/internal/{proxy → common/proxy}/schema-validator.d.ts +0 -0
  537. /package/dist/types/src/internal/{proxy → common/proxy}/schema.test.d.ts +0 -0
  538. /package/dist/types/src/internal/{proxy → common/proxy}/symbols.d.ts +0 -0
  539. /package/dist/types/src/internal/{proxy → common/proxy}/typed-handler.d.ts +0 -0
  540. /package/dist/types/src/internal/{proxy → common/proxy}/typed-handler.test.d.ts +0 -0
  541. /package/dist/types/src/internal/{proxy → common/proxy}/typed-object.test.d.ts +0 -0
  542. /package/dist/types/src/internal/{types → common/types}/typename.d.ts +0 -0
  543. /package/src/internal/{entities → Entity}/util.ts +0 -0
  544. /package/src/internal/{formats → Format}/date.ts +0 -0
  545. /package/src/internal/{formats → Format}/format.ts +0 -0
  546. /package/src/internal/{formats → Format}/index.ts +0 -0
  547. /package/src/internal/{formats → Format}/number.ts +0 -0
  548. /package/src/internal/{formats → Format}/object.ts +0 -0
  549. /package/src/internal/{formats → Format}/select.ts +0 -0
  550. /package/src/internal/{formats → Format}/string.ts +0 -0
  551. /package/src/internal/{json-schema → JsonSchema}/effect-schema.test.ts +0 -0
  552. /package/src/internal/{json-schema → JsonSchema}/index.ts +0 -0
  553. /package/src/internal/{json-schema → JsonSchema}/json-schema-normalize.ts +0 -0
  554. /package/src/internal/{object → Obj}/index.ts +0 -0
  555. /package/src/internal/{object → Obj}/schema-validator.test.ts +0 -0
  556. /package/src/internal/{ref → Ref}/index.ts +0 -0
  557. /package/src/internal/{schema → Type}/index.ts +0 -0
  558. /package/src/internal/{proxy → common/proxy}/define-hidden-property.ts +0 -0
  559. /package/src/internal/{proxy → common/proxy}/event-batch.ts +0 -0
  560. /package/src/internal/{proxy → common/proxy}/index.ts +0 -0
  561. /package/src/internal/{proxy → common/proxy}/proxy-types.ts +0 -0
  562. /package/src/internal/{proxy → common/proxy}/proxy-utils.ts +0 -0
  563. /package/src/internal/{proxy → common/proxy}/schema-validator.ts +0 -0
  564. /package/src/internal/{proxy → common/proxy}/symbols.ts +0 -0
  565. /package/src/internal/{types → common/types}/typename.ts +0 -0
package/src/Obj.ts CHANGED
@@ -2,83 +2,39 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ // @import-as-namespace
6
+
7
+ import * as Effect from 'effect/Effect';
8
+ import * as Equal from 'effect/Equal';
5
9
  import * as Function from 'effect/Function';
10
+ import * as Option from 'effect/Option';
6
11
  import * as Schema from 'effect/Schema';
12
+ import * as Utils from 'effect/Utils';
7
13
 
8
14
  import type { ForeignKey } from '@dxos/echo-protocol';
9
- import { createJsonPath, getValue as getValue$ } from '@dxos/effect';
10
- import { assertArgument } from '@dxos/invariant';
15
+ import { createJsonPath } from '@dxos/effect';
16
+ import { assertArgument, invariant } from '@dxos/invariant';
11
17
  import { type DXN, ObjectId } from '@dxos/keys';
12
- import { assumeType } from '@dxos/util';
18
+ import { assumeType, deepMapValues } from '@dxos/util';
13
19
 
14
20
  import type * as Database from './Database';
15
21
  import * as Entity from './Entity';
16
- import {
17
- type ObjectJSON as APIJSON,
18
- type AnyEntity,
19
- type AnyProperties,
20
- type Comparator as ApiComparator,
21
- type Meta as ApiMeta,
22
- type ReadonlyMeta as ApiReadonlyMeta,
23
- type EntityVersion as ApiVersion,
24
- type ChangeCallback,
25
- type InternalObjectProps,
26
- type KindId,
27
- MetaId,
28
- type Mutable,
29
- type ObjectMeta,
30
- // TODO(dmaretskyi): Export ParentId?
31
- ParentId,
32
- type SnapshotKindId,
33
- type VersionCompareResult,
34
- VersionTypeId,
35
- addTag as addTag$,
36
- change as change$,
37
- clone as clone$,
38
- compareVersions,
39
- decodeVersion,
40
- deleteKeys as deleteKeys$,
41
- encodeVersion,
42
- getDXN as getDXN$,
43
- getDatabase as getDatabase$,
44
- getDescription as getDescription$,
45
- getKeys as getKeys$,
46
- getLabel as getLabel$,
47
- getMetaChecked as getMeta$,
48
- getSchema as getSchema$,
49
- getSnapshot as getSnapshot$,
50
- getTypeAnnotation,
51
- getTypeDXN as getTypeDXN$,
52
- getTypename as getTypename$,
53
- isDeleted as isDeleted$,
54
- isInstanceOf,
55
- isVersion,
56
- makeObject,
57
- objectFromJSON,
58
- removeTag as removeTag$,
59
- setDescription as setDescription$,
60
- setLabel as setLabel$,
61
- setValue as setValue$,
62
- sort as sort$,
63
- sortByLabel as sortByLabel$,
64
- sortByTypename as sortByTypename$,
65
- subscribe as subscribe$,
66
- objectToJSON as toJSON$,
67
- version as version$,
68
- versionValid,
69
- } from './internal';
70
- import type * as Ref from './Ref';
22
+ import * as Err from './Err';
23
+ import * as internal from './internal';
24
+ import { getProxyTarget, isProxy } from './internal/common/proxy/proxy-utils';
25
+ import * as objInternal from './internal/Obj';
26
+ import * as Ref from './Ref';
71
27
  import type * as Type from './Type';
72
28
 
73
29
  /**
74
30
  * Base type for all ECHO objects.
75
31
  */
76
- interface BaseObj extends AnyEntity, Entity.OfKind<typeof Entity.Kind.Object> {}
32
+ interface BaseObj extends internal.AnyEntity, Entity.OfKind<typeof Entity.Kind.Object> {}
77
33
 
78
34
  /**
79
35
  * Object type with specific properties.
80
36
  */
81
- export type Obj<Props> = BaseObj & Props;
37
+ export type OfShape<Props> = BaseObj & Props;
82
38
 
83
39
  /**
84
40
  * Object with no known properties beyond id and kind.
@@ -90,6 +46,44 @@ export type Obj<Props> = BaseObj & Props;
90
46
  */
91
47
  export interface Unknown extends BaseObj {}
92
48
 
49
+ /**
50
+ * Runtime Effect schema for any ECHO object.
51
+ * Use for validation, parsing, or as a reference target for collections.
52
+ *
53
+ * NOTE: `Schema.is(Type.Obj)` does STRUCTURAL validation only (checks for `id` field).
54
+ * Use `Obj.isObject()` for proper ECHO instance type guards that check the KindId brand.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * // Structural type guard (accepts any object with id field)
59
+ * if (Schema.is(Type.Obj)(unknownValue)) { ... }
60
+ *
61
+ * // ECHO instance type guard (checks KindId brand)
62
+ * if (Obj.isObject(unknownValue)) { ... }
63
+ *
64
+ * // Reference to any object type
65
+ * const Collection = Schema.Struct({
66
+ * objects: Schema.Array(Ref.Ref(Obj.Unknown)),
67
+ * }).pipe(Type.object({ typename: 'Collection', version: '0.1.0' }));
68
+ * ```
69
+ */
70
+ // TODO(wittjosiah): Investigate if Schema.filter can validate KindId on ECHO instances.
71
+ // Effect Schema normalizes proxy objects to plain objects before calling filter predicates.
72
+ // Possible approaches: custom Schema.declare, AST manipulation, or upstream contribution.
73
+ export const Unknown: Type.Obj<Unknown> = Schema.Struct({
74
+ id: Schema.String,
75
+ }).pipe(
76
+ Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),
77
+ // TODO(dmaretskyi): Clean this up.
78
+ // NOTE: The EchoObjectSchema annotation is required for Ref.Ref(Obj.Unknown) to work.
79
+ // The typename/version only satisfy ECHO schema machinery for reference targets.
80
+ internal.EchoObjectSchema({ typename: internal.ANY_OBJECT_TYPENAME, version: internal.ANY_OBJECT_VERSION }),
81
+ (schema) =>
82
+ Object.assign(schema, {
83
+ [internal.SchemaKindId]: (schema as any)[internal.SchemaKindId],
84
+ }) as unknown as Type.Obj<Unknown>,
85
+ );
86
+
93
87
  /**
94
88
  * Object with arbitrary properties.
95
89
  *
@@ -98,13 +92,13 @@ export interface Unknown extends BaseObj {}
98
92
  *
99
93
  * Prefer using `Obj.Unknown` when you don't need to access arbitrary properties.
100
94
  */
101
- export interface Any extends BaseObj, AnyProperties {}
95
+ export interface Any extends BaseObj, internal.AnyProperties {}
102
96
 
103
97
  /**
104
98
  * Base type for snapshot objects (has SnapshotKindId instead of KindId).
105
99
  */
106
- interface BaseSnapshot extends AnyEntity {
107
- readonly [SnapshotKindId]: typeof Entity.Kind.Object;
100
+ interface BaseSnapshot extends internal.AnyEntity {
101
+ readonly [Entity.SnapshotKindId]: typeof Entity.Kind.Object;
108
102
  readonly id: ObjectId;
109
103
  }
110
104
 
@@ -117,16 +111,23 @@ interface BaseSnapshot extends AnyEntity {
117
111
  * Snapshots are structurally identical to reactive objects but have a different brand,
118
112
  * making them distinguishable at the TypeScript level. Neither is assignable to the other.
119
113
  */
120
- export type Snapshot<T extends Unknown = Unknown> = Omit<T, KindId> & BaseSnapshot;
114
+ export type Snapshot<T extends Unknown = Unknown> = Omit<T, Entity.KindId> & BaseSnapshot;
121
115
 
122
- const defaultMeta: ObjectMeta = {
116
+ /**
117
+ * JSON-encoded properties for objects.
118
+ */
119
+ export interface BaseObjJson {
120
+ id: string;
121
+ }
122
+
123
+ const defaultMeta: internal.ObjectMeta = {
123
124
  keys: [],
124
125
  };
125
126
 
126
- type Props<T = any> = {
127
+ type MakePropsInternal<T extends Unknown> = {
127
128
  id?: ObjectId;
128
- [Meta]?: Partial<ObjectMeta>;
129
- } & Type.Properties<T>;
129
+ [Meta]?: Partial<internal.ObjectMeta>;
130
+ } & Entity.Properties<T>;
130
131
 
131
132
  // TODO(burdon): Should we allow the caller to set the id?
132
133
  /**
@@ -134,9 +135,9 @@ type Props<T = any> = {
134
135
  */
135
136
  export type MakeProps<S extends Schema.Schema.AnyNoContext> = {
136
137
  id?: ObjectId;
137
- [Meta]?: Partial<ObjectMeta>;
138
+ [Meta]?: Partial<internal.ObjectMeta>;
138
139
  [Parent]?: Unknown;
139
- } & NoInfer<Props<Schema.Schema.Type<S>>>;
140
+ } & MakePropsInternal<Schema.Schema.Type<S>>;
140
141
 
141
142
  /**
142
143
  * Creates a new echo object of the given schema.
@@ -153,23 +154,22 @@ export type MakeProps<S extends Schema.Schema.AnyNoContext> = {
153
154
  *
154
155
  * Note: Only accepts object schemas, not relation schemas. Use `Relation.make` for relations.
155
156
  */
156
- export const make: {
157
- <S extends Type.Obj.Any>(schema: S, props: MakeProps<S>): Obj<Schema.Schema.Type<S>>;
158
- /**
159
- * @deprecated Pass meta as in the example: `Obj.make(Person, { [Obj.Meta]: { keys: [...] }, name: 'John' })`.
160
- */
161
- <S extends Type.Obj.Any>(schema: S, props: MakeProps<S>, meta: Partial<ObjectMeta>): Obj<Schema.Schema.Type<S>>;
162
- } = <S extends Type.Obj.Any>(
157
+ export const make = <S extends Type.AnyObj>(
163
158
  schema: S,
164
- props: MakeProps<S>,
165
- meta?: Partial<ObjectMeta>,
166
- ): Obj<Schema.Schema.Type<S>> => {
167
- assertArgument(getTypeAnnotation(schema)?.kind === Entity.Kind.Object, 'schema', 'Expected an object schema');
159
+ props: NoInfer<MakeProps<S>>,
160
+ ): OfShape<Schema.Schema.Type<S>> => {
161
+ assertArgument(
162
+ internal.getTypeAnnotation(schema)?.kind === Entity.Kind.Object,
163
+ 'schema',
164
+ 'Expected an object schema',
165
+ );
166
+
167
+ let meta: internal.ObjectMeta | undefined = undefined;
168
168
 
169
169
  // Set default fields on meta on creation.
170
- if (props[MetaId] != null) {
171
- meta = { ...structuredClone(defaultMeta), ...props[MetaId] };
172
- delete props[MetaId];
170
+ if (props[internal.MetaId] != null) {
171
+ meta = { ...structuredClone(defaultMeta), ...props[internal.MetaId] };
172
+ delete props[internal.MetaId];
173
173
  }
174
174
 
175
175
  // Filter undefined values (Object.entries only returns string-keyed properties).
@@ -183,7 +183,7 @@ export const make: {
183
183
  }
184
184
  }
185
185
 
186
- return makeObject<Schema.Schema.Type<S>>(schema, filterUndefined as any, {
186
+ return internal.makeObject<Schema.Schema.Type<S>>(schema, filterUndefined as any, {
187
187
  ...defaultMeta,
188
188
  ...meta,
189
189
  });
@@ -193,10 +193,15 @@ export const make: {
193
193
  * Determine if object is an ECHO object.
194
194
  */
195
195
  export const isObject = (obj: unknown): obj is Unknown => {
196
- assumeType<InternalObjectProps>(obj);
196
+ assumeType<internal.InternalObjectProps>(obj);
197
197
  return typeof obj === 'object' && obj !== null && obj[Entity.KindId] === Entity.Kind.Object;
198
198
  };
199
199
 
200
+ export const isSnapshot = (obj: unknown): obj is Snapshot => {
201
+ assumeType<internal.InternalObjectProps>(obj);
202
+ return typeof obj === 'object' && obj !== null && (obj as any)[Entity.SnapshotKindId] === Entity.Kind.Object;
203
+ };
204
+
200
205
  /**
201
206
  * Subscribe to object updates.
202
207
  * The callback is called synchronously when the object is modified.
@@ -204,7 +209,7 @@ export const isObject = (obj: unknown): obj is Unknown => {
204
209
  * @returns Unsubscribe function.
205
210
  */
206
211
  export const subscribe = (obj: Unknown, callback: () => void): (() => void) => {
207
- return subscribe$(obj, callback);
212
+ return internal.subscribe(obj, callback);
208
213
  };
209
214
 
210
215
  //
@@ -216,7 +221,61 @@ export const subscribe = (obj: Unknown, callback: () => void): (() => void) => {
216
221
  * The snapshot is branded with SnapshotKindId instead of KindId,
217
222
  * making it distinguishable from the reactive object at the type level.
218
223
  */
219
- export const getSnapshot: <T extends Unknown>(obj: T) => Snapshot<T> = getSnapshot$ as any;
224
+ export const getSnapshot: <T extends Unknown>(obj: T) => Snapshot<T> = objInternal.getSnapshot as any;
225
+
226
+ /**
227
+ * Returns the reactive version of an object from the database, given its snapshot.
228
+ * Inverse of `Obj.getSnapshot`.
229
+ *
230
+ * Uses `Obj.getDatabase` internally to get the database from the snapshot,
231
+ * then resolves the reactive object by ID.
232
+ *
233
+ * @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).
234
+ * @returns Effect that succeeds with the reactive object, or fails with `GetReactiveError`.
235
+ * @example
236
+ * ```ts
237
+ * const snapshot = Obj.getSnapshot(obj);
238
+ * const reactive = Obj.getReactive(snapshot).pipe(
239
+ * Effect.runSync
240
+ * );
241
+ * ```
242
+ */
243
+ export const getReactive = <T extends Unknown>(snapshot: Snapshot<T>): Effect.Effect<T, Err.GetReactiveError> =>
244
+ Effect.gen(function* () {
245
+ const db = internal.getDatabase(snapshot);
246
+ if (!db) {
247
+ return yield* Effect.fail(new Err.GetReactiveError({ reason: 'no-database', snapshotId: snapshot.id }));
248
+ }
249
+ const obj = db.getObjectById(snapshot.id);
250
+ if (!obj) {
251
+ return yield* Effect.fail(new Err.GetReactiveError({ reason: 'object-not-found', snapshotId: snapshot.id }));
252
+ }
253
+ return obj as T;
254
+ });
255
+
256
+ /**
257
+ * Like `Obj.getReactive` but returns `Option.none()` instead of failing when the object
258
+ * cannot be resolved (no database, object not found).
259
+ *
260
+ * @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).
261
+ * @returns Effect that succeeds with `Option.some(reactive)` or `Option.none()`.
262
+ */
263
+ export const getReactiveOption = <T extends Unknown>(snapshot: Snapshot<T>): Effect.Effect<Option.Option<T>, never> =>
264
+ getReactive(snapshot).pipe(
265
+ Effect.map(Option.some),
266
+ Effect.catchAll(() => Effect.succeed(Option.none())),
267
+ );
268
+
269
+ /**
270
+ * Synchronous version of `Obj.getReactive`. Returns the reactive object or throws
271
+ * `GetReactiveError` when the object cannot be resolved (no database, object not found).
272
+ *
273
+ * @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).
274
+ * @returns The reactive object.
275
+ * @throws {Err.GetReactiveError} When the object cannot be resolved.
276
+ */
277
+ export const getReactiveOrThrow = <T extends Unknown>(snapshot: Snapshot<T>): T =>
278
+ Effect.runSync(getReactive(snapshot));
220
279
 
221
280
  export type CloneOptions = {
222
281
  /**
@@ -237,7 +296,7 @@ export type CloneOptions = {
237
296
  * This does not clone referenced objects, only the properties in the object.
238
297
  * @returns A new object with the same schema and properties.
239
298
  */
240
- export const clone: <T extends Unknown>(obj: T, opts?: CloneOptions) => T = clone$;
299
+ export const clone: <T extends Unknown>(obj: T, opts?: CloneOptions) => T = objInternal.clone;
241
300
 
242
301
  //
243
302
  // Change
@@ -245,42 +304,42 @@ export const clone: <T extends Unknown>(obj: T, opts?: CloneOptions) => T = clon
245
304
 
246
305
  /**
247
306
  * Makes all properties mutable recursively.
248
- * Used to provide a mutable view of an object within `Obj.change`.
307
+ * Used to provide a mutable view of an object within `Obj.update`.
249
308
  */
250
- export type { Mutable };
309
+ export type Mutable<T> = internal.Mutable<T>;
251
310
 
252
311
  /**
253
312
  * Perform mutations on an echo object within a controlled context.
254
313
  *
255
314
  * All mutations within the callback are batched and trigger a single notification
256
- * when the callback completes. Direct mutations outside of `Obj.change` will throw
315
+ * when the callback completes. Direct mutations outside of `Obj.update` will throw
257
316
  * an error for echo objects.
258
317
  *
259
318
  * This function also works with nested objects within echo objects (e.g., Template structs)
260
319
  * that are reactive at runtime.
261
320
  *
262
- * @param obj - The echo object to mutate. Use `Relation.change` for relations.
321
+ * @param obj - The echo object to mutate. Use `Relation.update` for relations.
263
322
  * @param callback - The callback that performs mutations on the object.
264
323
  *
265
324
  * @example
266
325
  * ```ts
267
326
  * const person = Obj.make(Person, { name: 'John', age: 25 });
268
327
  *
269
- * // Mutate within Obj.change
270
- * Obj.change(person, (p) => {
271
- * p.name = 'Jane';
272
- * p.age = 30;
328
+ * // Mutate within Obj.update
329
+ * Obj.update(person, (obj) => {
330
+ * obj.name = 'Jane';
331
+ * obj.age = 30;
273
332
  * });
274
333
  * // ONE notification fires here
275
334
  *
276
335
  * // Direct mutation throws
277
- * person.name = 'Bob'; // Error: Cannot modify outside Obj.change()
336
+ * person.name = 'Bob'; // Error: Cannot modify outside Obj.update()
278
337
  * ```
279
338
  *
280
- * Note: Only accepts objects. Use `Relation.change` for relations.
339
+ * Note: Only accepts objects. Use `Relation.update` for relations.
281
340
  */
282
- export const change = <T extends Unknown>(obj: T, callback: ChangeCallback<T>): void => {
283
- change$(obj, callback);
341
+ export const update = <T extends Unknown>(obj: T, callback: internal.ChangeCallback<T>): void => {
342
+ internal.change(obj, callback);
284
343
  };
285
344
 
286
345
  /**
@@ -306,7 +365,7 @@ export const change = <T extends Unknown>(obj: T, callback: ChangeCallback<T>):
306
365
  * ```
307
366
  */
308
367
  export const getValue = (obj: Unknown | Snapshot, path: readonly (string | number)[]): any => {
309
- return getValue$(obj, createJsonPath(path));
368
+ return internal.getValue(obj, createJsonPath(path));
310
369
  };
311
370
 
312
371
  /**
@@ -314,7 +373,7 @@ export const getValue = (obj: Unknown | Snapshot, path: readonly (string | numbe
314
373
  * whether to initialize nested data as an empty object or array.
315
374
  *
316
375
  * Similar to lodash.set and setDeep from @dxos/util, but schema-aware.
317
- * Must be called within an `Obj.change` callback.
376
+ * Must be called within an `Obj.update` callback.
318
377
  *
319
378
  * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
320
379
  * parameters, so there is no compile-time error. Enforcement is runtime-only.
@@ -328,15 +387,15 @@ export const getValue = (obj: Unknown | Snapshot, path: readonly (string | numbe
328
387
  * ```ts
329
388
  * const person = Obj.make(Person, { name: 'John' });
330
389
  * // Person schema has: addresses: Schema.Array(Address)
331
- * Obj.change(person, (p) => {
332
- * Obj.setValue(p, ['addresses', 0, 'street'], '123 Main St');
390
+ * Obj.update(person, (obj) => {
391
+ * Obj.setValue(obj, ['addresses', 0, 'street'], '123 Main St');
333
392
  * });
334
393
  * // Creates: person.addresses = [{ street: '123 Main St' }]
335
394
  * ```
336
395
  */
337
396
  // TODO(wittjosiah): Compute possible path values + type value based on generic object type.
338
397
  export const setValue: (obj: Mutable<Unknown>, path: readonly (string | number)[], value: any) => void =
339
- setValue$ as any;
398
+ objInternal.setValue as any;
340
399
 
341
400
  //
342
401
  // Type
@@ -358,14 +417,44 @@ export type ID = ObjectId;
358
417
  * ```
359
418
  */
360
419
  export const instanceOf: {
361
- <S extends Type.Entity.Any>(schema: S): (value: unknown) => value is Schema.Schema.Type<S>;
362
- <S extends Type.Entity.Any>(schema: S, value: unknown): value is Schema.Schema.Type<S>;
363
- } = ((...args: [schema: Type.Entity.Any, value: unknown] | [schema: Type.Entity.Any]) => {
420
+ <S extends Type.AnyEntity>(schema: S): (value: unknown) => value is Schema.Schema.Type<S>;
421
+ <S extends Type.AnyEntity>(schema: S, value: unknown): value is Schema.Schema.Type<S>;
422
+ } = ((...args: [schema: Type.AnyEntity, value: unknown] | [schema: Type.AnyEntity]) => {
423
+ if (args.length === 1) {
424
+ return (entity: unknown) => internal.isInstanceOf(args[0], entity);
425
+ }
426
+
427
+ return internal.isInstanceOf(args[0], args[1]);
428
+ }) as any;
429
+
430
+ /**
431
+ * Test if a snapshot is an instance of a schema.
432
+ * Mirrors `instanceOf` but only accepts values branded with SnapshotKindId.
433
+ * Use when the value is known to be a snapshot (e.g. from `getSnapshot` or `useObject`).
434
+ *
435
+ * @example
436
+ * ```ts
437
+ * const snapshot = Obj.getSnapshot(person);
438
+ * if (Obj.snapshotOf(Person, snapshot)) {
439
+ * // snapshot is Obj.Snapshot<Person>
440
+ * }
441
+ * ```
442
+ */
443
+ export const snapshotOf: {
444
+ <S extends Type.AnyEntity>(schema: S): (value: unknown) => value is Snapshot<Schema.Schema.Type<S>>;
445
+ <S extends Type.AnyEntity>(schema: S, value: unknown): value is Snapshot<Schema.Schema.Type<S>>;
446
+ } = ((...args: [schema: Type.AnyEntity, value: unknown] | [schema: Type.AnyEntity]) => {
447
+ const check = (entity: unknown) =>
448
+ entity != null &&
449
+ typeof entity === 'object' &&
450
+ Entity.SnapshotKindId in entity &&
451
+ internal.isInstanceOf(args[0], entity);
452
+
364
453
  if (args.length === 1) {
365
- return (entity: unknown) => isInstanceOf(args[0], entity);
454
+ return (entity: unknown) => check(entity);
366
455
  }
367
456
 
368
- return isInstanceOf(args[0], args[1]);
457
+ return check(args[1]);
369
458
  }) as any;
370
459
 
371
460
  // TODO(dmaretskyi): Allow returning undefined.
@@ -375,29 +464,32 @@ export const instanceOf: {
375
464
  */
376
465
  export const getDXN = (entity: Unknown | Snapshot): DXN => {
377
466
  assertArgument(!Schema.isSchema(entity), 'obj', 'Object should not be a schema.');
378
- return getDXN$(entity);
467
+ return internal.getDXN(entity);
379
468
  };
380
469
 
381
470
  /**
382
471
  * @returns The DXN of the object's type.
383
- * @example dxn:example.com/type/Person:1.0.0
472
+ * @example dxn:com.example.type.person:1.0.0
473
+ * @throws If the object is missing its type (corrupted object).
384
474
  */
385
- // TODO(wittjosiah): Narrow types.
386
- export const getTypeDXN: (obj: unknown | undefined) => DXN | undefined = getTypeDXN$ as any;
475
+ export const getTypeDXN = (obj: Unknown | Snapshot): DXN => {
476
+ const type = internal.getTypeDXN(obj);
477
+ invariant(type != null, 'Corrupted object: missing type.');
478
+ return type;
479
+ };
387
480
 
388
481
  /**
389
482
  * Get the schema of the object.
390
483
  * Returns the branded ECHO schema used to create the object.
391
484
  */
392
- // TODO(wittjosiah): Narrow types.
393
- export const getSchema: (obj: unknown | undefined) => Type.Entity.Any | undefined = getSchema$ as any;
485
+ export const getSchema: (obj: Unknown | Snapshot) => Type.AnyEntity | undefined = internal.getSchema as any;
394
486
 
395
487
  /**
396
488
  * @returns The typename of the object's type.
397
489
  * Accepts both reactive objects and snapshots.
398
- * @example `example.com/type/Person`
490
+ * @example `com.example.type.person`
399
491
  */
400
- export const getTypename = (entity: Unknown | Snapshot): string | undefined => getTypename$(entity);
492
+ export const getTypename = (entity: Unknown | Snapshot): string | undefined => internal.getTypename(entity);
401
493
 
402
494
  //
403
495
  // Database
@@ -408,30 +500,35 @@ export const getTypename = (entity: Unknown | Snapshot): string | undefined => g
408
500
  * Accepts both reactive objects and snapshots.
409
501
  */
410
502
  export const getDatabase = (entity: Entity.Unknown | Entity.Snapshot): Database.Database | undefined =>
411
- getDatabase$(entity);
503
+ internal.getDatabase(entity);
412
504
 
413
505
  //
414
506
  // Meta
415
507
  //
416
508
 
417
- export const Meta: unique symbol = MetaId as any;
509
+ /**
510
+ * Property that accesses metadata for an entity.
511
+ *
512
+ * Alias for `Entity.Meta`.
513
+ */
514
+ export const Meta = internal.MetaId;
418
515
 
419
516
  /**
420
517
  * Deeply read-only version of ObjectMeta.
421
518
  * Prevents mutation at all nesting levels (e.g., `meta.keys.push()` is a TypeScript error).
422
519
  */
423
- export type ReadonlyMeta = ApiReadonlyMeta;
520
+ export type ReadonlyMeta = internal.ReadonlyMeta;
424
521
 
425
522
  /**
426
- * Mutable meta type returned by `Obj.getMeta` inside an `Obj.change` callback.
523
+ * Mutable meta type returned by `Obj.getMeta` inside an `Obj.update` callback.
427
524
  */
428
- export type Meta = ApiMeta;
525
+ export type Meta = internal.Meta;
429
526
 
430
527
  // TODO(burdon): Narrow type.
431
528
  // TODO(dmaretskyi): Allow returning undefined.
432
529
  /**
433
530
  * Get the metadata for an object.
434
- * Returns mutable meta when passed a mutable object (inside `Obj.change` callback).
531
+ * Returns mutable meta when passed a mutable object (inside `Obj.update` callback).
435
532
  * Returns read-only meta when passed a regular object or snapshot.
436
533
  *
437
534
  * @example
@@ -440,8 +537,8 @@ export type Meta = ApiMeta;
440
537
  * const meta = Obj.getMeta(person); // ReadonlyMeta
441
538
  *
442
539
  * // Mutable access inside change callback
443
- * Obj.change(person, (p) => {
444
- * const meta = Obj.getMeta(p); // ObjectMeta (mutable)
540
+ * Obj.update(person, (obj) => {
541
+ * const meta = Obj.getMeta(obj); // ObjectMeta (mutable)
445
542
  * meta.tags ??= [];
446
543
  * meta.tags.push('important');
447
544
  * });
@@ -451,7 +548,7 @@ export type Meta = ApiMeta;
451
548
  export function getMeta(entity: Mutable<Unknown>): Meta;
452
549
  export function getMeta(entity: Unknown | Snapshot): ReadonlyMeta;
453
550
  export function getMeta(entity: Unknown | Snapshot | Mutable<Unknown>): Meta | ReadonlyMeta {
454
- return getMeta$(entity);
551
+ return internal.getMetaChecked(entity);
455
552
  }
456
553
 
457
554
  /**
@@ -461,41 +558,41 @@ export function getMeta(entity: Unknown | Snapshot | Mutable<Unknown>): Meta | R
461
558
  export const getKeys: {
462
559
  (entity: Unknown | Snapshot, source: string): ForeignKey[];
463
560
  (source: string): (entity: Unknown | Snapshot) => ForeignKey[];
464
- } = Function.dual(2, (entity: Unknown | Snapshot, source?: string): ForeignKey[] => getKeys$(entity, source!));
561
+ } = Function.dual(2, (entity: Unknown | Snapshot, source?: string): ForeignKey[] => internal.getKeys(entity, source!));
465
562
 
466
563
  /**
467
564
  * Delete all keys from the object for the specified source.
468
- * Must be called within an `Obj.change` callback.
565
+ * Must be called within an `Obj.update` callback.
469
566
  *
470
567
  * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
471
568
  * parameters, so there is no compile-time error. Enforcement is runtime-only.
472
569
  */
473
- export const deleteKeys = (entity: Mutable<Unknown>, source: string): void => deleteKeys$(entity, source);
570
+ export const deleteKeys = (entity: Mutable<Unknown>, source: string): void => internal.deleteKeys(entity, source);
474
571
 
475
572
  /**
476
573
  * Add a tag to the object.
477
- * Must be called within an `Obj.change` callback.
574
+ * Must be called within an `Obj.update` callback.
478
575
  *
479
576
  * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
480
577
  * parameters, so there is no compile-time error. Enforcement is runtime-only.
481
578
  */
482
- export const addTag = (entity: Mutable<Unknown>, tag: string): void => addTag$(entity, tag);
579
+ export const addTag = (entity: Mutable<Unknown>, tag: string): void => internal.addTag(entity, tag);
483
580
 
484
581
  /**
485
582
  * Remove a tag from the object.
486
- * Must be called within an `Obj.change` callback.
583
+ * Must be called within an `Obj.update` callback.
487
584
  *
488
585
  * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
489
586
  * parameters, so there is no compile-time error. Enforcement is runtime-only.
490
587
  */
491
- export const removeTag = (entity: Mutable<Unknown>, tag: string): void => removeTag$(entity, tag);
588
+ export const removeTag = (entity: Mutable<Unknown>, tag: string): void => internal.removeTag(entity, tag);
492
589
 
493
590
  /**
494
591
  * Check if the object is deleted.
495
592
  * Accepts both reactive objects and snapshots.
496
593
  */
497
594
  // TODO(dmaretskyi): Default to `false`.
498
- export const isDeleted = (entity: Unknown | Snapshot): boolean => isDeleted$(entity);
595
+ export const isDeleted = (entity: Unknown | Snapshot): boolean => objInternal.isDeleted(entity);
499
596
 
500
597
  //
501
598
  // Annotations
@@ -505,32 +602,32 @@ export const isDeleted = (entity: Unknown | Snapshot): boolean => isDeleted$(ent
505
602
  * Get the label of the object.
506
603
  * Accepts both reactive objects and snapshots.
507
604
  */
508
- export const getLabel = (entity: Unknown | Snapshot): string | undefined => getLabel$(entity);
605
+ export const getLabel = (entity: Unknown | Snapshot): string | undefined => internal.getLabel(entity);
509
606
 
510
607
  /**
511
608
  * Set the label of the object.
512
- * Must be called within an `Obj.change` callback.
609
+ * Must be called within an `Obj.update` callback.
513
610
  *
514
611
  * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
515
612
  * parameters, so there is no compile-time error. Enforcement is runtime-only.
516
613
  */
517
- export const setLabel = (entity: Mutable<Unknown>, label: string): void => setLabel$(entity, label);
614
+ export const setLabel = (entity: Mutable<Unknown>, label: string): void => internal.setLabel(entity, label);
518
615
 
519
616
  /**
520
617
  * Get the description of the object.
521
618
  * Accepts both reactive objects and snapshots.
522
619
  */
523
- export const getDescription = (entity: Unknown | Snapshot): string | undefined => getDescription$(entity);
620
+ export const getDescription = (entity: Unknown | Snapshot): string | undefined => internal.getDescription(entity);
524
621
 
525
622
  /**
526
623
  * Set the description of the object.
527
- * Must be called within an `Obj.change` callback.
624
+ * Must be called within an `Obj.update` callback.
528
625
  *
529
626
  * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
530
627
  * parameters, so there is no compile-time error. Enforcement is runtime-only.
531
628
  */
532
629
  export const setDescription = (entity: Mutable<Unknown>, description: string): void =>
533
- setDescription$(entity, description);
630
+ internal.setDescription(entity, description);
534
631
 
535
632
  /**
536
633
  * Symbol to set parent when creating objects with `Obj.make`.
@@ -542,7 +639,7 @@ export const setDescription = (entity: Mutable<Unknown>, description: string): v
542
639
  * })
543
640
  * ```
544
641
  */
545
- export const Parent: unique symbol = ParentId as any;
642
+ export const Parent: unique symbol = internal.ParentId as any;
546
643
 
547
644
  /**
548
645
  * Get the parent of an object.
@@ -552,8 +649,8 @@ export const Parent: unique symbol = ParentId as any;
552
649
  */
553
650
  export const getParent = (entity: Unknown | Snapshot): Unknown | undefined => {
554
651
  assertArgument(isObject(entity), 'Expected an object');
555
- assumeType<InternalObjectProps>(entity);
556
- return entity[ParentId] as Unknown | undefined;
652
+ assumeType<internal.InternalObjectProps>(entity);
653
+ return entity[internal.ParentId] as Unknown | undefined;
557
654
  };
558
655
 
559
656
  /**
@@ -564,9 +661,126 @@ export const getParent = (entity: Unknown | Snapshot): Unknown | undefined => {
564
661
  export const setParent = (entity: Unknown, parent: Any | undefined) => {
565
662
  assertArgument(isObject(entity), 'Expected an object');
566
663
  assertArgument(parent === undefined || isObject(parent), 'Expected an object');
567
- assumeType<InternalObjectProps>(entity);
568
- assumeType<InternalObjectProps | undefined>(parent);
569
- entity[ParentId] = parent;
664
+ assumeType<internal.InternalObjectProps>(entity);
665
+ assumeType<internal.InternalObjectProps | undefined>(parent);
666
+ entity[internal.ParentId] = parent;
667
+ return entity;
668
+ };
669
+
670
+ interface UpdateFromOptions<T> {
671
+ exclude?: (keyof T)[];
672
+ include?: (keyof T)[];
673
+ }
674
+
675
+ const valuesEqual = (left: unknown, right: unknown): boolean => {
676
+ if (left === right) {
677
+ return true;
678
+ }
679
+ if (left === null || right === null) {
680
+ return left === right;
681
+ }
682
+ if (typeof left !== 'object' || typeof right !== 'object') {
683
+ return Utils.structuralRegion(() => Equal.equals(left, right));
684
+ }
685
+ if (Ref.isRef(left) && Ref.isRef(right)) {
686
+ return left.dxn.toString() === right.dxn.toString();
687
+ }
688
+ if (Ref.isRef(left) || Ref.isRef(right)) {
689
+ return false;
690
+ }
691
+ if (Array.isArray(left) && Array.isArray(right)) {
692
+ if (left.length !== right.length) {
693
+ return false;
694
+ }
695
+ for (let index = 0; index < left.length; index++) {
696
+ if (!valuesEqual(left[index], right[index])) {
697
+ return false;
698
+ }
699
+ }
700
+ return true;
701
+ }
702
+ if (Array.isArray(left) || Array.isArray(right)) {
703
+ return false;
704
+ }
705
+ const leftRecord = left as Record<string, unknown>;
706
+ const rightRecord = right as Record<string, unknown>;
707
+ const keys = new Set([
708
+ ...Object.keys(leftRecord).filter((key) => key !== 'id'),
709
+ ...Object.keys(rightRecord).filter((key) => key !== 'id'),
710
+ ]);
711
+ for (const key of keys) {
712
+ const leftHas = Object.hasOwn(leftRecord, key);
713
+ const rightHas = Object.hasOwn(rightRecord, key);
714
+ const leftValue = leftHas ? leftRecord[key] : undefined;
715
+ const rightValue = rightHas ? rightRecord[key] : undefined;
716
+ if (!valuesEqual(leftValue, rightValue)) {
717
+ return false;
718
+ }
719
+ }
720
+ return true;
721
+ };
722
+
723
+ /**
724
+ * Breaks reactive proxies on assigned values so echo-db assignment accepts nested structs (same idea as link assignment).
725
+ */
726
+ const prepareAssignValue = (value: unknown): unknown =>
727
+ deepMapValues(value, (nested, recurse) => {
728
+ if (nested === null || typeof nested !== 'object') {
729
+ return nested;
730
+ }
731
+ if (Ref.isRef(nested)) {
732
+ return nested;
733
+ }
734
+ if (Array.isArray(nested)) {
735
+ return recurse(nested);
736
+ }
737
+ if (isProxy(nested)) {
738
+ return recurse({ ...getProxyTarget(nested) });
739
+ }
740
+ return recurse(nested);
741
+ });
742
+
743
+ /**
744
+ * For each key present on `source` (except `id`), assigns `target[key]` when the current value differs.
745
+ * References are compared by target DXN; other values use Effect `Equal.equals` inside a structural region,
746
+ * with recursive comparison for arrays and plain object-shaped property bags (excluding `id`).
747
+ *
748
+ * Must be called within an `Obj.update` callback.
749
+ *
750
+ * @returns Whether any property was updated.
751
+ */
752
+ export const updateFrom = <T extends Unknown>(
753
+ target: Mutable<T>,
754
+ source: T,
755
+ options?: UpdateFromOptions<T>,
756
+ ): boolean => {
757
+ assertArgument(isObject(target), 'Expected an echo object target.');
758
+ assertArgument(isObject(source), 'Expected an echo object source.');
759
+ let keys = Object.keys(source as Record<string, unknown>).filter((key) => key !== 'id');
760
+ if (options?.include !== undefined) {
761
+ const include = new Set(options.include.map((key) => String(key)));
762
+ keys = keys.filter((key) => include.has(key));
763
+ }
764
+ if (options?.exclude !== undefined) {
765
+ const exclude = new Set(options.exclude.map((key) => String(key)));
766
+ keys = keys.filter((key) => !exclude.has(key));
767
+ }
768
+ let updated = false;
769
+ const sourceRecord = source as Record<string, unknown>;
770
+ const targetRecord = target as Record<string, unknown>;
771
+ for (const key of keys) {
772
+ if (!Object.hasOwn(sourceRecord, key)) {
773
+ continue;
774
+ }
775
+ const nextValue = sourceRecord[key];
776
+ const prevValue = Object.hasOwn(targetRecord, key) ? targetRecord[key] : undefined;
777
+ if (valuesEqual(prevValue, nextValue)) {
778
+ continue;
779
+ }
780
+ targetRecord[key] = prepareAssignValue(nextValue) as never;
781
+ updated = true;
782
+ }
783
+ return updated;
570
784
  };
571
785
 
572
786
  //
@@ -576,7 +790,7 @@ export const setParent = (entity: Unknown, parent: Any | undefined) => {
576
790
  /**
577
791
  * JSON representation of an object.
578
792
  */
579
- export type JSON = APIJSON;
793
+ export type JSON = internal.ObjectJSON;
580
794
 
581
795
  /**
582
796
  * Converts object to its JSON representation.
@@ -584,7 +798,7 @@ export type JSON = APIJSON;
584
798
  *
585
799
  * The same algorithm is used when calling the standard `JSON.stringify(obj)` function.
586
800
  */
587
- export const toJSON = (entity: Unknown | Snapshot): JSON => toJSON$(entity);
801
+ export const toJSON = (entity: Unknown | Snapshot): JSON => objInternal.objectToJSON(entity);
588
802
 
589
803
  /**
590
804
  * Creates an object from its json representation, performing schema validation.
@@ -594,38 +808,45 @@ export const toJSON = (entity: Unknown | Snapshot): JSON => toJSON$(entity);
594
808
  *
595
809
  * @param options.refResolver - Resolver for references. Produces hydrated references that can be resolved.
596
810
  * @param options.dxn - Override object DXN. Changes the result of `Obj.getDXN`.
811
+ * @param options.database - Database to associate with the object.
597
812
  */
598
- export const fromJSON: (json: unknown, options?: { refResolver?: Ref.Resolver; dxn?: DXN }) => Promise<Unknown> =
599
- objectFromJSON as any;
813
+ export const fromJSON: (
814
+ json: unknown,
815
+ options?: { refResolver?: Ref.Resolver; dxn?: DXN; database?: Database.Database; parent?: Unknown },
816
+ ) => Promise<Unknown> = objInternal.objectFromJSON as any;
600
817
 
601
818
  /**
602
819
  * Comparator function type for sorting objects.
603
820
  * Accepts both reactive objects and snapshots.
604
821
  */
605
- export type Comparator = ApiComparator<Unknown | Snapshot>;
822
+ export type Comparator = internal.Comparator<Unknown | Snapshot>;
606
823
 
607
- export const sortByLabel: Comparator = sortByLabel$ as Comparator;
608
- export const sortByTypename: Comparator = sortByTypename$ as Comparator;
609
- export const sort = (...comparators: Comparator[]): Comparator => sort$(...comparators) as Comparator;
824
+ export const sortByLabel: Comparator = internal.sortByLabel as Comparator;
825
+ export const sortByTypename: Comparator = internal.sortByTypename as Comparator;
826
+ export const sort = (...comparators: Comparator[]): Comparator => internal.sort(...comparators) as Comparator;
610
827
 
611
828
  //
612
829
  // Version
613
830
  //
614
831
 
615
- export { VersionTypeId };
616
- export type { VersionCompareResult };
832
+ export const VersionTypeId = internal.VersionTypeId;
833
+ export type VersionCompareResult = internal.VersionCompareResult;
617
834
 
618
835
  /**
619
836
  * Represent object version.
620
837
  * May be backed by Automerge.
621
838
  * Objects with no history are not versioned.
622
839
  */
623
- export type Version = ApiVersion;
840
+ export type Version = internal.EntityVersion;
624
841
 
625
- export { isVersion, versionValid, compareVersions, encodeVersion, decodeVersion };
842
+ export const isVersion = internal.isVersion;
843
+ export const versionValid = internal.versionValid;
844
+ export const compareVersions = internal.compareVersions;
845
+ export const encodeVersion = internal.encodeVersion;
846
+ export const decodeVersion = internal.decodeVersion;
626
847
 
627
848
  /**
628
849
  * Returns the version of the object.
629
850
  * Accepts both reactive objects and snapshots.
630
851
  */
631
- export const version = (entity: Unknown | Snapshot): Version => version$(entity);
852
+ export const version = (entity: Unknown | Snapshot): Version => internal.version(entity);