@dxos/echo 0.8.4-main.7ace549 → 0.8.4-main.8360d9e660

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