@dxos/echo 0.8.4-main.70d3990 → 0.8.4-main.74a063c4e0

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