@dxos/echo 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8

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 (731) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +10 -11
  3. package/dist/lib/neutral/Annotation.mjs +68 -0
  4. package/dist/lib/neutral/Database.mjs +38 -0
  5. package/dist/lib/neutral/Entity.mjs +72 -0
  6. package/dist/lib/neutral/Err.mjs +12 -0
  7. package/dist/lib/neutral/Feed.mjs +54 -0
  8. package/dist/lib/neutral/Filter.mjs +70 -0
  9. package/dist/lib/neutral/Format.mjs +86 -0
  10. package/dist/lib/neutral/Format.mjs.map +7 -0
  11. package/dist/lib/neutral/JsonSchema.mjs +18 -0
  12. package/dist/lib/neutral/JsonSchema.mjs.map +7 -0
  13. package/dist/lib/neutral/Key.mjs +16 -0
  14. package/dist/lib/neutral/Key.mjs.map +7 -0
  15. package/dist/lib/neutral/Migration.mjs +18 -0
  16. package/dist/lib/neutral/Migration.mjs.map +7 -0
  17. package/dist/lib/neutral/Obj.mjs +122 -0
  18. package/dist/lib/neutral/Obj.mjs.map +7 -0
  19. package/dist/lib/neutral/Order.mjs +16 -0
  20. package/dist/lib/neutral/Order.mjs.map +7 -0
  21. package/dist/lib/neutral/Query.mjs +38 -0
  22. package/dist/lib/neutral/Query.mjs.map +7 -0
  23. package/dist/lib/neutral/QueryResult.mjs +2 -0
  24. package/dist/lib/neutral/QueryResult.mjs.map +7 -0
  25. package/dist/lib/neutral/Ref.mjs +25 -0
  26. package/dist/lib/neutral/Ref.mjs.map +7 -0
  27. package/dist/lib/neutral/Registry.mjs +14 -0
  28. package/dist/lib/neutral/Registry.mjs.map +7 -0
  29. package/dist/lib/neutral/Relation.mjs +97 -0
  30. package/dist/lib/neutral/Relation.mjs.map +7 -0
  31. package/dist/lib/neutral/Scope.mjs +12 -0
  32. package/dist/lib/neutral/Scope.mjs.map +7 -0
  33. package/dist/lib/neutral/Tag.mjs +32 -0
  34. package/dist/lib/neutral/Tag.mjs.map +7 -0
  35. package/dist/lib/neutral/Type.mjs +65 -0
  36. package/dist/lib/neutral/Type.mjs.map +7 -0
  37. package/dist/lib/neutral/chunk-35INCYOE.mjs +7 -0
  38. package/dist/lib/neutral/chunk-35INCYOE.mjs.map +7 -0
  39. package/dist/lib/neutral/chunk-3PBP4V4O.mjs +101 -0
  40. package/dist/lib/neutral/chunk-3PBP4V4O.mjs.map +7 -0
  41. package/dist/lib/neutral/chunk-4ZUHOTCG.mjs +184 -0
  42. package/dist/lib/neutral/chunk-4ZUHOTCG.mjs.map +7 -0
  43. package/dist/lib/neutral/chunk-5SMDBFVB.mjs +108 -0
  44. package/dist/lib/neutral/chunk-5SMDBFVB.mjs.map +7 -0
  45. package/dist/lib/neutral/chunk-5SUJPHAE.mjs +34 -0
  46. package/dist/lib/neutral/chunk-5SUJPHAE.mjs.map +7 -0
  47. package/dist/lib/neutral/chunk-6M2Z6WBH.mjs +93 -0
  48. package/dist/lib/neutral/chunk-6M2Z6WBH.mjs.map +7 -0
  49. package/dist/lib/neutral/chunk-6YDI3J37.mjs +346 -0
  50. package/dist/lib/neutral/chunk-6YDI3J37.mjs.map +7 -0
  51. package/dist/lib/neutral/chunk-7FPIAJIV.mjs +2279 -0
  52. package/dist/lib/neutral/chunk-7FPIAJIV.mjs.map +7 -0
  53. package/dist/lib/neutral/chunk-7LOUAPYZ.mjs +25 -0
  54. package/dist/lib/neutral/chunk-7LOUAPYZ.mjs.map +7 -0
  55. package/dist/lib/neutral/chunk-7PI7C4EF.mjs +747 -0
  56. package/dist/lib/neutral/chunk-7PI7C4EF.mjs.map +7 -0
  57. package/dist/lib/neutral/chunk-BBFJWWAV.mjs +51 -0
  58. package/dist/lib/neutral/chunk-BBFJWWAV.mjs.map +7 -0
  59. package/dist/lib/neutral/chunk-EVK6XBXO.mjs +56 -0
  60. package/dist/lib/neutral/chunk-EVK6XBXO.mjs.map +7 -0
  61. package/dist/lib/neutral/chunk-IGK6FN65.mjs +27 -0
  62. package/dist/lib/neutral/chunk-IGK6FN65.mjs.map +7 -0
  63. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  64. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  65. package/dist/lib/neutral/chunk-LWXVKPPW.mjs +281 -0
  66. package/dist/lib/neutral/chunk-LWXVKPPW.mjs.map +7 -0
  67. package/dist/lib/neutral/chunk-MZ7K3MLL.mjs +48 -0
  68. package/dist/lib/neutral/chunk-MZ7K3MLL.mjs.map +7 -0
  69. package/dist/lib/neutral/chunk-O6BH7EPN.mjs +94 -0
  70. package/dist/lib/neutral/chunk-O6BH7EPN.mjs.map +7 -0
  71. package/dist/lib/neutral/chunk-QQIYS74I.mjs +336 -0
  72. package/dist/lib/neutral/chunk-QQIYS74I.mjs.map +7 -0
  73. package/dist/lib/neutral/chunk-R5W6DXR4.mjs +678 -0
  74. package/dist/lib/neutral/chunk-R5W6DXR4.mjs.map +7 -0
  75. package/dist/lib/neutral/chunk-RIVWNMSF.mjs +41 -0
  76. package/dist/lib/neutral/chunk-RIVWNMSF.mjs.map +7 -0
  77. package/dist/lib/neutral/chunk-SBVFRTST.mjs +160 -0
  78. package/dist/lib/neutral/chunk-SBVFRTST.mjs.map +7 -0
  79. package/dist/lib/neutral/chunk-T6E37YIP.mjs +251 -0
  80. package/dist/lib/neutral/chunk-T6E37YIP.mjs.map +7 -0
  81. package/dist/lib/neutral/chunk-TFEWTY5A.mjs +428 -0
  82. package/dist/lib/neutral/chunk-TFEWTY5A.mjs.map +7 -0
  83. package/dist/lib/neutral/chunk-TYGKCRMK.mjs +437 -0
  84. package/dist/lib/neutral/chunk-TYGKCRMK.mjs.map +7 -0
  85. package/dist/lib/neutral/chunk-UUP46KUQ.mjs +205 -0
  86. package/dist/lib/neutral/chunk-UUP46KUQ.mjs.map +7 -0
  87. package/dist/lib/neutral/chunk-WISOH2XH.mjs +36 -0
  88. package/dist/lib/neutral/chunk-WISOH2XH.mjs.map +7 -0
  89. package/dist/lib/neutral/chunk-WTQJHC75.mjs +395 -0
  90. package/dist/lib/neutral/chunk-WTQJHC75.mjs.map +7 -0
  91. package/dist/lib/neutral/chunk-WU3GIANS.mjs +31 -0
  92. package/dist/lib/neutral/chunk-WU3GIANS.mjs.map +7 -0
  93. package/dist/lib/neutral/chunk-ZGNNFYHS.mjs +132 -0
  94. package/dist/lib/neutral/chunk-ZGNNFYHS.mjs.map +7 -0
  95. package/dist/lib/neutral/index.mjs +111 -0
  96. package/dist/lib/neutral/index.mjs.map +7 -0
  97. package/dist/lib/neutral/internal/index.mjs +539 -0
  98. package/dist/lib/neutral/internal/index.mjs.map +7 -0
  99. package/dist/lib/neutral/meta.json +1 -0
  100. package/dist/lib/neutral/testing/index.mjs +458 -0
  101. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  102. package/dist/types/src/Annotation.d.ts +128 -0
  103. package/dist/types/src/Annotation.d.ts.map +1 -0
  104. package/dist/types/src/Annotation.test.d.ts +2 -0
  105. package/dist/types/src/Annotation.test.d.ts.map +1 -0
  106. package/dist/types/src/Collection.d.ts +15 -0
  107. package/dist/types/src/Collection.d.ts.map +1 -0
  108. package/dist/types/src/Database.d.ts +208 -0
  109. package/dist/types/src/Database.d.ts.map +1 -0
  110. package/dist/types/src/Dataset.d.ts +29 -0
  111. package/dist/types/src/Dataset.d.ts.map +1 -0
  112. package/dist/types/src/Entity.d.ts +247 -0
  113. package/dist/types/src/Entity.d.ts.map +1 -0
  114. package/dist/types/src/Entity.test.d.ts +2 -0
  115. package/dist/types/src/Entity.test.d.ts.map +1 -0
  116. package/dist/types/src/Err.d.ts +107 -0
  117. package/dist/types/src/Err.d.ts.map +1 -0
  118. package/dist/types/src/Feed.d.ts +229 -0
  119. package/dist/types/src/Feed.d.ts.map +1 -0
  120. package/dist/types/src/Filter.d.ts +175 -0
  121. package/dist/types/src/Filter.d.ts.map +1 -0
  122. package/dist/types/src/Filter.test.d.ts +2 -0
  123. package/dist/types/src/Filter.test.d.ts.map +1 -0
  124. package/dist/types/src/Format.d.ts +2 -0
  125. package/dist/types/src/Format.d.ts.map +1 -0
  126. package/dist/types/src/Hypergraph.d.ts +70 -0
  127. package/dist/types/src/Hypergraph.d.ts.map +1 -0
  128. package/dist/types/src/Json.d.ts +33 -0
  129. package/dist/types/src/Json.d.ts.map +1 -0
  130. package/dist/types/src/Json.test.d.ts +2 -0
  131. package/dist/types/src/Json.test.d.ts.map +1 -0
  132. package/dist/types/src/JsonSchema.d.ts +16 -0
  133. package/dist/types/src/JsonSchema.d.ts.map +1 -0
  134. package/dist/types/src/Key.d.ts +2 -1
  135. package/dist/types/src/Key.d.ts.map +1 -1
  136. package/dist/types/src/Migration.d.ts +72 -0
  137. package/dist/types/src/Migration.d.ts.map +1 -0
  138. package/dist/types/src/Obj.d.ts +483 -110
  139. package/dist/types/src/Obj.d.ts.map +1 -1
  140. package/dist/types/src/Obj.test.d.ts +2 -0
  141. package/dist/types/src/Obj.test.d.ts.map +1 -0
  142. package/dist/types/src/Order.d.ts +26 -0
  143. package/dist/types/src/Order.d.ts.map +1 -0
  144. package/dist/types/src/Query.d.ts +231 -0
  145. package/dist/types/src/Query.d.ts.map +1 -0
  146. package/dist/types/src/Query.test.d.ts +2 -0
  147. package/dist/types/src/Query.test.d.ts.map +1 -0
  148. package/dist/types/src/QueryResult.d.ts +101 -0
  149. package/dist/types/src/QueryResult.d.ts.map +1 -0
  150. package/dist/types/src/Ref.d.ts +69 -11
  151. package/dist/types/src/Ref.d.ts.map +1 -1
  152. package/dist/types/src/Registry.d.ts +131 -0
  153. package/dist/types/src/Registry.d.ts.map +1 -0
  154. package/dist/types/src/Relation.d.ts +321 -23
  155. package/dist/types/src/Relation.d.ts.map +1 -1
  156. package/dist/types/src/Relation.test.d.ts +2 -0
  157. package/dist/types/src/Relation.test.d.ts.map +1 -0
  158. package/dist/types/src/Scope.d.ts +35 -0
  159. package/dist/types/src/Scope.d.ts.map +1 -0
  160. package/dist/types/src/Tag.d.ts +26 -9
  161. package/dist/types/src/Tag.d.ts.map +1 -1
  162. package/dist/types/src/Type.d.ts +397 -106
  163. package/dist/types/src/Type.d.ts.map +1 -1
  164. package/dist/types/src/Type.test.d.ts +2 -0
  165. package/dist/types/src/Type.test.d.ts.map +1 -0
  166. package/dist/types/src/View.d.ts +65 -0
  167. package/dist/types/src/View.d.ts.map +1 -0
  168. package/dist/types/src/exemplars.test.d.ts +2 -0
  169. package/dist/types/src/exemplars.test.d.ts.map +1 -0
  170. package/dist/types/src/hierarchy.test.d.ts +2 -0
  171. package/dist/types/src/hierarchy.test.d.ts.map +1 -0
  172. package/dist/types/src/index.d.ts +21 -5
  173. package/dist/types/src/index.d.ts.map +1 -1
  174. package/dist/types/src/internal/Annotation/annotations.d.ts +272 -0
  175. package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -0
  176. package/dist/types/src/internal/Annotation/annotations.test.d.ts.map +1 -0
  177. package/dist/types/src/internal/Annotation/dictionary.d.ts +24 -0
  178. package/dist/types/src/internal/Annotation/dictionary.d.ts.map +1 -0
  179. package/dist/types/src/internal/Annotation/entity-dictionary.d.ts +14 -0
  180. package/dist/types/src/internal/Annotation/entity-dictionary.d.ts.map +1 -0
  181. package/dist/types/src/internal/Annotation/index.d.ts +6 -0
  182. package/dist/types/src/internal/Annotation/index.d.ts.map +1 -0
  183. package/dist/types/src/internal/Annotation/sorting.d.ts +24 -0
  184. package/dist/types/src/internal/Annotation/sorting.d.ts.map +1 -0
  185. package/dist/types/src/internal/Annotation/util.d.ts +48 -0
  186. package/dist/types/src/internal/Annotation/util.d.ts.map +1 -0
  187. package/dist/types/src/internal/Entity/api.d.ts +27 -0
  188. package/dist/types/src/internal/Entity/api.d.ts.map +1 -0
  189. package/dist/types/src/internal/Entity/entity.d.ts +84 -0
  190. package/dist/types/src/internal/Entity/entity.d.ts.map +1 -0
  191. package/dist/types/src/internal/Entity/guard.d.ts +10 -0
  192. package/dist/types/src/internal/Entity/guard.d.ts.map +1 -0
  193. package/dist/types/src/internal/Entity/index.d.ts +10 -0
  194. package/dist/types/src/internal/Entity/index.d.ts.map +1 -0
  195. package/dist/types/src/internal/Entity/model.d.ts +59 -0
  196. package/dist/types/src/internal/Entity/model.d.ts.map +1 -0
  197. package/dist/types/src/internal/Entity/object.d.ts +18 -0
  198. package/dist/types/src/internal/Entity/object.d.ts.map +1 -0
  199. package/dist/types/src/internal/Entity/relation.d.ts +58 -0
  200. package/dist/types/src/internal/Entity/relation.d.ts.map +1 -0
  201. package/dist/types/src/internal/Entity/type-kind.d.ts +24 -0
  202. package/dist/types/src/internal/Entity/type-kind.d.ts.map +1 -0
  203. package/dist/types/src/internal/Entity/type-uri.d.ts +24 -0
  204. package/dist/types/src/internal/Entity/type-uri.d.ts.map +1 -0
  205. package/dist/types/src/internal/Entity/util.d.ts +2 -0
  206. package/dist/types/src/internal/Entity/util.d.ts.map +1 -0
  207. package/dist/types/src/internal/Entity/version.d.ts +42 -0
  208. package/dist/types/src/internal/Entity/version.d.ts.map +1 -0
  209. package/dist/types/src/internal/Format/date.d.ts.map +1 -0
  210. package/dist/types/src/internal/Format/date.test.d.ts.map +1 -0
  211. package/dist/types/src/internal/{formats → Format}/format.d.ts +7 -4
  212. package/dist/types/src/internal/Format/format.d.ts.map +1 -0
  213. package/dist/types/src/internal/Format/format.test.d.ts.map +1 -0
  214. package/dist/types/src/internal/{formats → Format}/index.d.ts +2 -2
  215. package/dist/types/src/internal/Format/index.d.ts.map +1 -0
  216. package/dist/types/src/internal/Format/number.d.ts.map +1 -0
  217. package/dist/types/src/internal/{formats → Format}/object.d.ts +3 -1
  218. package/dist/types/src/internal/Format/object.d.ts.map +1 -0
  219. package/dist/types/src/internal/{formats → Format}/select.d.ts +6 -4
  220. package/dist/types/src/internal/Format/select.d.ts.map +1 -0
  221. package/dist/types/src/internal/{formats → Format}/string.d.ts +4 -0
  222. package/dist/types/src/internal/Format/string.d.ts.map +1 -0
  223. package/dist/types/src/internal/{formats → Format}/types.d.ts +14 -10
  224. package/dist/types/src/internal/Format/types.d.ts.map +1 -0
  225. package/dist/types/src/internal/{json → JsonSchema}/annotations.d.ts +1 -1
  226. package/dist/types/src/internal/JsonSchema/annotations.d.ts.map +1 -0
  227. package/dist/types/src/internal/JsonSchema/effect-schema.test.d.ts.map +1 -0
  228. package/dist/types/src/internal/JsonSchema/index.d.ts +5 -0
  229. package/dist/types/src/internal/JsonSchema/index.d.ts.map +1 -0
  230. package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts.map +1 -0
  231. package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema-type.d.ts +136 -35
  232. package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -0
  233. package/dist/types/src/internal/{json → JsonSchema}/json-schema.d.ts +6 -3
  234. package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -0
  235. package/dist/types/src/internal/JsonSchema/json-schema.test.d.ts.map +1 -0
  236. package/dist/types/src/internal/Obj/atoms.d.ts +38 -0
  237. package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -0
  238. package/dist/types/src/internal/Obj/clone.d.ts +8 -0
  239. package/dist/types/src/internal/Obj/clone.d.ts.map +1 -0
  240. package/dist/types/src/internal/Obj/common.d.ts.map +1 -0
  241. package/dist/types/src/internal/{object/create.d.ts → Obj/create-object.d.ts} +15 -16
  242. package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -0
  243. package/dist/types/src/internal/Obj/create-object.test.d.ts +2 -0
  244. package/dist/types/src/internal/Obj/create-object.test.d.ts.map +1 -0
  245. package/dist/types/src/internal/Obj/deleted.d.ts +6 -0
  246. package/dist/types/src/internal/Obj/deleted.d.ts.map +1 -0
  247. package/dist/types/src/internal/Obj/index.d.ts +11 -0
  248. package/dist/types/src/internal/Obj/index.d.ts.map +1 -0
  249. package/dist/types/src/internal/Obj/inspect.d.ts.map +1 -0
  250. package/dist/types/src/internal/Obj/json-serializer.d.ts +45 -0
  251. package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -0
  252. package/dist/types/src/internal/Obj/json-serializer.test.d.ts.map +1 -0
  253. package/dist/types/src/internal/Obj/schema-validator.d.ts +2 -0
  254. package/dist/types/src/internal/Obj/schema-validator.d.ts.map +1 -0
  255. package/dist/types/src/internal/Obj/schema-validator.test.d.ts.map +1 -0
  256. package/dist/types/src/internal/Obj/set-value.d.ts +7 -0
  257. package/dist/types/src/internal/Obj/set-value.d.ts.map +1 -0
  258. package/dist/types/src/internal/Obj/set-value.test.d.ts +2 -0
  259. package/dist/types/src/internal/Obj/set-value.test.d.ts.map +1 -0
  260. package/dist/types/src/internal/Obj/snapshot.d.ts +6 -0
  261. package/dist/types/src/internal/Obj/snapshot.d.ts.map +1 -0
  262. package/dist/types/src/internal/Obj/typed-object.d.ts +25 -0
  263. package/dist/types/src/internal/Obj/typed-object.d.ts.map +1 -0
  264. package/dist/types/src/internal/Obj/typed-object.test.d.ts.map +1 -0
  265. package/dist/types/src/internal/Query/index.d.ts +2 -0
  266. package/dist/types/src/internal/Query/index.d.ts.map +1 -0
  267. package/dist/types/src/internal/Query/pretty.d.ts +10 -0
  268. package/dist/types/src/internal/Query/pretty.d.ts.map +1 -0
  269. package/dist/types/src/internal/Ref/atoms.d.ts +10 -0
  270. package/dist/types/src/internal/Ref/atoms.d.ts.map +1 -0
  271. package/dist/types/src/internal/Ref/index.d.ts.map +1 -0
  272. package/dist/types/src/internal/Ref/ref-array.d.ts +21 -0
  273. package/dist/types/src/internal/Ref/ref-array.d.ts.map +1 -0
  274. package/dist/types/src/internal/{ref → Ref}/ref.d.ts +88 -32
  275. package/dist/types/src/internal/Ref/ref.d.ts.map +1 -0
  276. package/dist/types/src/internal/Ref/ref.test.d.ts.map +1 -0
  277. package/dist/types/src/internal/Ref/utils.d.ts +8 -0
  278. package/dist/types/src/internal/Ref/utils.d.ts.map +1 -0
  279. package/dist/types/src/internal/Type/compose.d.ts +7 -0
  280. package/dist/types/src/internal/Type/compose.d.ts.map +1 -0
  281. package/dist/types/src/internal/Type/compose.test.d.ts.map +1 -0
  282. package/dist/types/src/internal/Type/index.d.ts +3 -0
  283. package/dist/types/src/internal/Type/index.d.ts.map +1 -0
  284. package/dist/types/src/internal/{schema → Type}/manipulation.d.ts +0 -1
  285. package/dist/types/src/internal/Type/manipulation.d.ts.map +1 -0
  286. package/dist/types/src/internal/Type/type-schema.d.ts +52 -0
  287. package/dist/types/src/internal/Type/type-schema.d.ts.map +1 -0
  288. package/dist/types/src/internal/common/api/index.d.ts +11 -0
  289. package/dist/types/src/internal/common/api/index.d.ts.map +1 -0
  290. package/dist/types/src/internal/common/api/meta.d.ts +45 -0
  291. package/dist/types/src/internal/common/api/meta.d.ts.map +1 -0
  292. package/dist/types/src/internal/common/index.d.ts +4 -0
  293. package/dist/types/src/internal/common/index.d.ts.map +1 -0
  294. package/dist/types/src/internal/common/proxy/change-context.d.ts +55 -0
  295. package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -0
  296. package/dist/types/src/internal/common/proxy/change.test.d.ts +2 -0
  297. package/dist/types/src/internal/common/proxy/change.test.d.ts.map +1 -0
  298. package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts +5 -0
  299. package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts.map +1 -0
  300. package/dist/types/src/internal/common/proxy/errors.d.ts +19 -0
  301. package/dist/types/src/internal/common/proxy/errors.d.ts.map +1 -0
  302. package/dist/types/src/internal/common/proxy/event-batch.d.ts +10 -0
  303. package/dist/types/src/internal/common/proxy/event-batch.d.ts.map +1 -0
  304. package/dist/types/src/internal/common/proxy/handler.test.d.ts.map +1 -0
  305. package/dist/types/src/internal/common/proxy/index.d.ts +14 -0
  306. package/dist/types/src/internal/common/proxy/index.d.ts.map +1 -0
  307. package/dist/types/src/internal/common/proxy/json-serializer.d.ts +6 -0
  308. package/dist/types/src/internal/common/proxy/json-serializer.d.ts.map +1 -0
  309. package/dist/types/src/internal/common/proxy/make-object.d.ts +20 -0
  310. package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -0
  311. package/dist/types/src/internal/common/proxy/ownership.d.ts +57 -0
  312. package/dist/types/src/internal/common/proxy/ownership.d.ts.map +1 -0
  313. package/dist/types/src/internal/common/proxy/proxy-types.d.ts +18 -0
  314. package/dist/types/src/internal/common/proxy/proxy-types.d.ts.map +1 -0
  315. package/dist/types/src/internal/common/proxy/proxy-utils.d.ts +47 -0
  316. package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -0
  317. package/dist/types/src/internal/common/proxy/reactive-array.d.ts +8 -0
  318. package/dist/types/src/internal/common/proxy/reactive-array.d.ts.map +1 -0
  319. package/dist/types/src/internal/common/proxy/reactive.d.ts +39 -0
  320. package/dist/types/src/internal/common/proxy/reactive.d.ts.map +1 -0
  321. package/dist/types/src/internal/common/proxy/reactive.test.d.ts +2 -0
  322. package/dist/types/src/internal/common/proxy/reactive.test.d.ts.map +1 -0
  323. package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -0
  324. package/dist/types/src/internal/common/proxy/schema.test.d.ts.map +1 -0
  325. package/dist/types/src/internal/common/proxy/symbols.d.ts +3 -0
  326. package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -0
  327. package/dist/types/src/internal/common/proxy/typed-handler.d.ts +64 -0
  328. package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -0
  329. package/dist/types/src/internal/common/proxy/typed-handler.test.d.ts.map +1 -0
  330. package/dist/types/src/internal/common/proxy/typed-object.test.d.ts.map +1 -0
  331. package/dist/types/src/internal/common/types/base.d.ts +27 -0
  332. package/dist/types/src/internal/common/types/base.d.ts.map +1 -0
  333. package/dist/types/src/internal/common/types/entity.d.ts +94 -0
  334. package/dist/types/src/internal/common/types/entity.d.ts.map +1 -0
  335. package/dist/types/src/internal/common/types/index.d.ts +7 -0
  336. package/dist/types/src/internal/common/types/index.d.ts.map +1 -0
  337. package/dist/types/src/internal/common/types/meta.d.ts +54 -0
  338. package/dist/types/src/internal/common/types/meta.d.ts.map +1 -0
  339. package/dist/types/src/internal/common/types/model-symbols.d.ts +65 -0
  340. package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -0
  341. package/dist/types/src/internal/common/types/typename.d.ts +28 -0
  342. package/dist/types/src/internal/common/types/typename.d.ts.map +1 -0
  343. package/dist/types/src/internal/common/types/version.d.ts +15 -0
  344. package/dist/types/src/internal/common/types/version.d.ts.map +1 -0
  345. package/dist/types/src/internal/common/types/well-known-types.d.ts +11 -0
  346. package/dist/types/src/internal/common/types/well-known-types.d.ts.map +1 -0
  347. package/dist/types/src/internal/index.d.ts +10 -14
  348. package/dist/types/src/internal/index.d.ts.map +1 -1
  349. package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
  350. package/dist/types/src/testing/index.d.ts +4 -3
  351. package/dist/types/src/testing/index.d.ts.map +1 -1
  352. package/dist/types/src/testing/registry.d.ts +9 -0
  353. package/dist/types/src/testing/registry.d.ts.map +1 -0
  354. package/dist/types/src/testing/test-data.d.ts +18 -0
  355. package/dist/types/src/testing/test-data.d.ts.map +1 -0
  356. package/dist/types/src/testing/test-schema.d.ts +298 -0
  357. package/dist/types/src/testing/test-schema.d.ts.map +1 -0
  358. package/dist/types/src/testing/util.d.ts +23 -0
  359. package/dist/types/src/testing/util.d.ts.map +1 -0
  360. package/dist/types/tsconfig.tsbuildinfo +1 -1
  361. package/package.json +119 -66
  362. package/src/Annotation.test.ts +439 -0
  363. package/src/Annotation.ts +202 -0
  364. package/src/Collection.ts +33 -0
  365. package/src/Database.ts +345 -0
  366. package/src/Dataset.ts +34 -0
  367. package/src/Entity.test.ts +132 -0
  368. package/src/Entity.ts +345 -0
  369. package/src/Err.ts +40 -0
  370. package/src/Feed.ts +352 -0
  371. package/src/Filter.test.ts +90 -0
  372. package/src/Filter.ts +484 -0
  373. package/src/Format.ts +5 -0
  374. package/src/Hypergraph.ts +84 -0
  375. package/src/Json.test.ts +175 -0
  376. package/src/Json.ts +103 -0
  377. package/src/JsonSchema.ts +26 -0
  378. package/src/Key.ts +4 -1
  379. package/src/Migration.ts +114 -0
  380. package/src/Obj.test.ts +641 -0
  381. package/src/Obj.ts +778 -281
  382. package/src/Order.ts +68 -0
  383. package/src/Query.test.ts +835 -0
  384. package/src/Query.ts +634 -0
  385. package/src/QueryResult.ts +132 -0
  386. package/src/Ref.ts +98 -10
  387. package/src/Registry.ts +155 -0
  388. package/src/Relation.test.ts +88 -0
  389. package/src/Relation.ts +503 -67
  390. package/src/Scope.ts +50 -0
  391. package/src/Tag.md +88 -0
  392. package/src/Tag.ts +53 -8
  393. package/src/Type.test.ts +257 -0
  394. package/src/Type.ts +643 -151
  395. package/src/View.ts +98 -0
  396. package/src/exemplars.test.ts +21 -0
  397. package/src/hierarchy.test.ts +33 -0
  398. package/src/index.ts +22 -6
  399. package/src/internal/Annotation/annotations.test.ts +165 -0
  400. package/src/internal/Annotation/annotations.ts +609 -0
  401. package/src/internal/Annotation/dictionary.ts +47 -0
  402. package/src/internal/Annotation/entity-dictionary.ts +74 -0
  403. package/src/internal/Annotation/index.ts +9 -0
  404. package/src/internal/Annotation/sorting.ts +51 -0
  405. package/src/internal/Annotation/util.ts +94 -0
  406. package/src/internal/Entity/api.ts +77 -0
  407. package/src/internal/Entity/entity.ts +277 -0
  408. package/src/internal/Entity/guard.ts +26 -0
  409. package/src/internal/Entity/index.ts +13 -0
  410. package/src/internal/Entity/model.ts +119 -0
  411. package/src/internal/Entity/object.ts +73 -0
  412. package/src/internal/Entity/relation.ts +188 -0
  413. package/src/internal/Entity/type-kind.ts +75 -0
  414. package/src/internal/Entity/type-uri.ts +92 -0
  415. package/src/internal/Entity/util.ts +33 -0
  416. package/src/internal/Entity/version.ts +96 -0
  417. package/src/internal/{formats → Format}/date.test.ts +1 -2
  418. package/src/internal/{formats → Format}/date.ts +5 -9
  419. package/src/internal/{formats → Format}/format.test.ts +27 -7
  420. package/src/internal/{formats → Format}/format.ts +8 -6
  421. package/src/internal/{formats → Format}/index.ts +2 -3
  422. package/src/internal/{formats → Format}/number.ts +5 -5
  423. package/src/internal/{formats → Format}/object.ts +23 -6
  424. package/src/internal/{formats → Format}/select.ts +6 -4
  425. package/src/internal/{formats → Format}/string.ts +14 -9
  426. package/src/internal/{formats → Format}/types.ts +54 -43
  427. package/src/internal/{json → JsonSchema}/annotations.ts +3 -3
  428. package/src/internal/{json-schema → JsonSchema}/index.ts +2 -0
  429. package/src/internal/{json-schema → JsonSchema}/json-schema-normalize.ts +4 -2
  430. package/src/internal/{json-schema → JsonSchema}/json-schema-type.ts +39 -39
  431. package/src/internal/{json → JsonSchema}/json-schema.test.ts +119 -182
  432. package/src/internal/{json → JsonSchema}/json-schema.ts +70 -42
  433. package/src/internal/Obj/atoms.ts +244 -0
  434. package/src/internal/Obj/clone.ts +53 -0
  435. package/src/internal/{object → Obj}/common.ts +3 -4
  436. package/src/internal/Obj/create-object.test.ts +116 -0
  437. package/src/internal/Obj/create-object.ts +140 -0
  438. package/src/internal/Obj/deleted.ts +19 -0
  439. package/src/internal/Obj/index.ts +14 -0
  440. package/src/internal/{object → Obj}/inspect.ts +7 -7
  441. package/src/internal/Obj/json-serializer.test.ts +199 -0
  442. package/src/internal/Obj/json-serializer.ts +278 -0
  443. package/src/internal/{object → Obj}/schema-validator.test.ts +3 -7
  444. package/src/internal/Obj/schema-validator.ts +6 -0
  445. package/src/internal/Obj/set-value.test.ts +258 -0
  446. package/src/internal/Obj/set-value.ts +158 -0
  447. package/src/internal/Obj/snapshot.ts +114 -0
  448. package/src/internal/Obj/typed-object.test.ts +32 -0
  449. package/src/internal/Obj/typed-object.ts +30 -0
  450. package/src/internal/{json → Query}/index.ts +1 -1
  451. package/src/internal/Query/pretty.ts +162 -0
  452. package/src/internal/Ref/atoms.ts +20 -0
  453. package/src/internal/{ref → Ref}/ref-array.ts +6 -7
  454. package/src/internal/Ref/ref.test.ts +91 -0
  455. package/src/internal/{ref → Ref}/ref.ts +230 -101
  456. package/src/internal/Ref/utils.ts +45 -0
  457. package/src/internal/{projection → Type}/compose.test.ts +9 -9
  458. package/src/internal/{projection → Type}/compose.ts +14 -9
  459. package/src/internal/Type/index.ts +6 -0
  460. package/src/internal/{schema → Type}/manipulation.ts +0 -25
  461. package/src/internal/Type/type-schema.ts +60 -0
  462. package/src/internal/common/README.md +102 -0
  463. package/src/internal/common/api/index.ts +15 -0
  464. package/src/internal/common/api/meta.ts +90 -0
  465. package/src/internal/{testing → common}/index.ts +2 -1
  466. package/src/internal/common/proxy/change-context.ts +138 -0
  467. package/src/internal/common/proxy/change.test.ts +527 -0
  468. package/src/internal/common/proxy/define-hidden-property.ts +14 -0
  469. package/src/internal/common/proxy/errors.ts +42 -0
  470. package/src/internal/common/proxy/event-batch.ts +44 -0
  471. package/src/internal/common/proxy/handler.test.ts +121 -0
  472. package/src/internal/common/proxy/index.ts +17 -0
  473. package/src/internal/common/proxy/json-serializer.ts +101 -0
  474. package/src/internal/common/proxy/make-object.ts +129 -0
  475. package/src/internal/common/proxy/ownership.ts +252 -0
  476. package/src/internal/common/proxy/proxy-types.ts +23 -0
  477. package/src/internal/common/proxy/proxy-utils.ts +150 -0
  478. package/src/internal/common/proxy/reactive-array.ts +71 -0
  479. package/src/internal/common/proxy/reactive.test.ts +54 -0
  480. package/src/internal/common/proxy/reactive.ts +77 -0
  481. package/src/internal/{object → common/proxy}/schema-validator.ts +6 -3
  482. package/src/internal/common/proxy/schema.test.ts +107 -0
  483. package/src/internal/common/proxy/symbols.ts +7 -0
  484. package/src/internal/common/proxy/typed-handler.test.ts +314 -0
  485. package/src/internal/common/proxy/typed-handler.ts +509 -0
  486. package/src/internal/common/proxy/typed-object.test.ts +103 -0
  487. package/src/internal/common/types/base.ts +43 -0
  488. package/src/internal/common/types/entity.ts +133 -0
  489. package/src/internal/common/types/index.ts +15 -0
  490. package/src/internal/common/types/meta.ts +109 -0
  491. package/src/internal/common/types/model-symbols.ts +89 -0
  492. package/src/internal/common/types/typename.ts +91 -0
  493. package/src/internal/common/types/version.ts +19 -0
  494. package/src/internal/common/types/well-known-types.ts +15 -0
  495. package/src/internal/index.ts +14 -17
  496. package/src/testing/api.test.ts +131 -0
  497. package/src/testing/index.ts +4 -3
  498. package/src/testing/registry.ts +44 -0
  499. package/src/testing/test-data.ts +189 -0
  500. package/src/testing/test-schema.ts +204 -0
  501. package/src/testing/util.ts +88 -0
  502. package/dist/lib/browser/chunk-BIDAASFK.mjs +0 -3727
  503. package/dist/lib/browser/chunk-BIDAASFK.mjs.map +0 -7
  504. package/dist/lib/browser/chunk-ZDLCWGEW.mjs +0 -410
  505. package/dist/lib/browser/chunk-ZDLCWGEW.mjs.map +0 -7
  506. package/dist/lib/browser/chunk-ZFRJKT4A.mjs +0 -585
  507. package/dist/lib/browser/chunk-ZFRJKT4A.mjs.map +0 -7
  508. package/dist/lib/browser/index.mjs +0 -35
  509. package/dist/lib/browser/internal/index.mjs +0 -336
  510. package/dist/lib/browser/meta.json +0 -1
  511. package/dist/lib/browser/query/index.mjs +0 -13
  512. package/dist/lib/browser/testing/index.mjs +0 -267
  513. package/dist/lib/browser/testing/index.mjs.map +0 -7
  514. package/dist/lib/node-esm/chunk-3SVRRCUU.mjs +0 -3727
  515. package/dist/lib/node-esm/chunk-3SVRRCUU.mjs.map +0 -7
  516. package/dist/lib/node-esm/chunk-CGDHRZWH.mjs +0 -585
  517. package/dist/lib/node-esm/chunk-CGDHRZWH.mjs.map +0 -7
  518. package/dist/lib/node-esm/chunk-HWS6VBQC.mjs +0 -410
  519. package/dist/lib/node-esm/chunk-HWS6VBQC.mjs.map +0 -7
  520. package/dist/lib/node-esm/index.mjs +0 -35
  521. package/dist/lib/node-esm/internal/index.mjs +0 -336
  522. package/dist/lib/node-esm/meta.json +0 -1
  523. package/dist/lib/node-esm/query/index.mjs +0 -13
  524. package/dist/lib/node-esm/testing/index.mjs +0 -267
  525. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  526. package/dist/types/src/errors.d.ts +0 -68
  527. package/dist/types/src/errors.d.ts.map +0 -1
  528. package/dist/types/src/internal/ast/annotation-helper.d.ts +0 -8
  529. package/dist/types/src/internal/ast/annotation-helper.d.ts.map +0 -1
  530. package/dist/types/src/internal/ast/annotations.d.ts +0 -131
  531. package/dist/types/src/internal/ast/annotations.d.ts.map +0 -1
  532. package/dist/types/src/internal/ast/annotations.test.d.ts.map +0 -1
  533. package/dist/types/src/internal/ast/entity-kind.d.ts +0 -10
  534. package/dist/types/src/internal/ast/entity-kind.d.ts.map +0 -1
  535. package/dist/types/src/internal/ast/index.d.ts +0 -5
  536. package/dist/types/src/internal/ast/index.d.ts.map +0 -1
  537. package/dist/types/src/internal/ast/types.d.ts +0 -6
  538. package/dist/types/src/internal/ast/types.d.ts.map +0 -1
  539. package/dist/types/src/internal/formats/date.d.ts.map +0 -1
  540. package/dist/types/src/internal/formats/date.test.d.ts.map +0 -1
  541. package/dist/types/src/internal/formats/format.d.ts.map +0 -1
  542. package/dist/types/src/internal/formats/format.test.d.ts.map +0 -1
  543. package/dist/types/src/internal/formats/index.d.ts.map +0 -1
  544. package/dist/types/src/internal/formats/number.d.ts.map +0 -1
  545. package/dist/types/src/internal/formats/object.d.ts.map +0 -1
  546. package/dist/types/src/internal/formats/select.d.ts.map +0 -1
  547. package/dist/types/src/internal/formats/string.d.ts.map +0 -1
  548. package/dist/types/src/internal/formats/types.d.ts.map +0 -1
  549. package/dist/types/src/internal/json/annotations.d.ts.map +0 -1
  550. package/dist/types/src/internal/json/effect-schema.test.d.ts.map +0 -1
  551. package/dist/types/src/internal/json/index.d.ts +0 -2
  552. package/dist/types/src/internal/json/index.d.ts.map +0 -1
  553. package/dist/types/src/internal/json/json-schema.d.ts.map +0 -1
  554. package/dist/types/src/internal/json/json-schema.test.d.ts.map +0 -1
  555. package/dist/types/src/internal/json-schema/index.d.ts +0 -3
  556. package/dist/types/src/internal/json-schema/index.d.ts.map +0 -1
  557. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +0 -1
  558. package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +0 -1
  559. package/dist/types/src/internal/object/accessors.d.ts +0 -37
  560. package/dist/types/src/internal/object/accessors.d.ts.map +0 -1
  561. package/dist/types/src/internal/object/common.d.ts.map +0 -1
  562. package/dist/types/src/internal/object/create.d.ts.map +0 -1
  563. package/dist/types/src/internal/object/create.test.d.ts +0 -2
  564. package/dist/types/src/internal/object/create.test.d.ts.map +0 -1
  565. package/dist/types/src/internal/object/deleted.d.ts +0 -6
  566. package/dist/types/src/internal/object/deleted.d.ts.map +0 -1
  567. package/dist/types/src/internal/object/entity.d.ts +0 -33
  568. package/dist/types/src/internal/object/entity.d.ts.map +0 -1
  569. package/dist/types/src/internal/object/expando.d.ts +0 -14
  570. package/dist/types/src/internal/object/expando.d.ts.map +0 -1
  571. package/dist/types/src/internal/object/ids.d.ts +0 -6
  572. package/dist/types/src/internal/object/ids.d.ts.map +0 -1
  573. package/dist/types/src/internal/object/index.d.ts +0 -16
  574. package/dist/types/src/internal/object/index.d.ts.map +0 -1
  575. package/dist/types/src/internal/object/inspect.d.ts.map +0 -1
  576. package/dist/types/src/internal/object/json-serializer.d.ts +0 -32
  577. package/dist/types/src/internal/object/json-serializer.d.ts.map +0 -1
  578. package/dist/types/src/internal/object/json-serializer.test.d.ts.map +0 -1
  579. package/dist/types/src/internal/object/meta.d.ts +0 -31
  580. package/dist/types/src/internal/object/meta.d.ts.map +0 -1
  581. package/dist/types/src/internal/object/model.d.ts +0 -117
  582. package/dist/types/src/internal/object/model.d.ts.map +0 -1
  583. package/dist/types/src/internal/object/relation.d.ts +0 -17
  584. package/dist/types/src/internal/object/relation.d.ts.map +0 -1
  585. package/dist/types/src/internal/object/schema-validator.d.ts.map +0 -1
  586. package/dist/types/src/internal/object/schema-validator.test.d.ts.map +0 -1
  587. package/dist/types/src/internal/object/typed-object.d.ts +0 -31
  588. package/dist/types/src/internal/object/typed-object.d.ts.map +0 -1
  589. package/dist/types/src/internal/object/typed-object.test.d.ts.map +0 -1
  590. package/dist/types/src/internal/object/typename.d.ts +0 -15
  591. package/dist/types/src/internal/object/typename.d.ts.map +0 -1
  592. package/dist/types/src/internal/object/version.d.ts +0 -14
  593. package/dist/types/src/internal/object/version.d.ts.map +0 -1
  594. package/dist/types/src/internal/projection/compose.d.ts +0 -6
  595. package/dist/types/src/internal/projection/compose.d.ts.map +0 -1
  596. package/dist/types/src/internal/projection/compose.test.d.ts.map +0 -1
  597. package/dist/types/src/internal/projection/index.d.ts +0 -2
  598. package/dist/types/src/internal/projection/index.d.ts.map +0 -1
  599. package/dist/types/src/internal/proxy/handler.test.d.ts.map +0 -1
  600. package/dist/types/src/internal/proxy/reactive-object.d.ts +0 -15
  601. package/dist/types/src/internal/proxy/reactive-object.d.ts.map +0 -1
  602. package/dist/types/src/internal/proxy/schema.test.d.ts.map +0 -1
  603. package/dist/types/src/internal/proxy/typed-handler.d.ts +0 -44
  604. package/dist/types/src/internal/proxy/typed-handler.d.ts.map +0 -1
  605. package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +0 -1
  606. package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +0 -1
  607. package/dist/types/src/internal/query/index.d.ts +0 -2
  608. package/dist/types/src/internal/query/index.d.ts.map +0 -1
  609. package/dist/types/src/internal/query/query.d.ts +0 -17
  610. package/dist/types/src/internal/query/query.d.ts.map +0 -1
  611. package/dist/types/src/internal/ref/index.d.ts.map +0 -1
  612. package/dist/types/src/internal/ref/ref-array.d.ts +0 -21
  613. package/dist/types/src/internal/ref/ref-array.d.ts.map +0 -1
  614. package/dist/types/src/internal/ref/ref.d.ts.map +0 -1
  615. package/dist/types/src/internal/ref/ref.test.d.ts.map +0 -1
  616. package/dist/types/src/internal/schema/echo-schema.d.ts +0 -168
  617. package/dist/types/src/internal/schema/echo-schema.d.ts.map +0 -1
  618. package/dist/types/src/internal/schema/index.d.ts +0 -7
  619. package/dist/types/src/internal/schema/index.d.ts.map +0 -1
  620. package/dist/types/src/internal/schema/manipulation.d.ts.map +0 -1
  621. package/dist/types/src/internal/schema/runtime-schema-registry.d.ts +0 -18
  622. package/dist/types/src/internal/schema/runtime-schema-registry.d.ts.map +0 -1
  623. package/dist/types/src/internal/schema/snapshot.d.ts +0 -6
  624. package/dist/types/src/internal/schema/snapshot.d.ts.map +0 -1
  625. package/dist/types/src/internal/schema/stored-schema.d.ts +0 -13
  626. package/dist/types/src/internal/schema/stored-schema.d.ts.map +0 -1
  627. package/dist/types/src/internal/testing/index.d.ts +0 -3
  628. package/dist/types/src/internal/testing/index.d.ts.map +0 -1
  629. package/dist/types/src/internal/testing/types.d.ts +0 -381
  630. package/dist/types/src/internal/testing/types.d.ts.map +0 -1
  631. package/dist/types/src/internal/testing/utils.d.ts +0 -10
  632. package/dist/types/src/internal/testing/utils.d.ts.map +0 -1
  633. package/dist/types/src/internal/types/index.d.ts +0 -3
  634. package/dist/types/src/internal/types/index.d.ts.map +0 -1
  635. package/dist/types/src/internal/types/types.d.ts +0 -79
  636. package/dist/types/src/internal/types/types.d.ts.map +0 -1
  637. package/dist/types/src/internal/types/types.test.d.ts +0 -2
  638. package/dist/types/src/internal/types/types.test.d.ts.map +0 -1
  639. package/dist/types/src/internal/types/util.d.ts +0 -5
  640. package/dist/types/src/internal/types/util.d.ts.map +0 -1
  641. package/dist/types/src/query/index.d.ts +0 -2
  642. package/dist/types/src/query/index.d.ts.map +0 -1
  643. package/dist/types/src/query/query.d.ts +0 -248
  644. package/dist/types/src/query/query.d.ts.map +0 -1
  645. package/dist/types/src/query/query.test.d.ts +0 -2
  646. package/dist/types/src/query/query.test.d.ts.map +0 -1
  647. package/dist/types/src/testing/echo-schema.d.ts +0 -7
  648. package/dist/types/src/testing/echo-schema.d.ts.map +0 -1
  649. package/dist/types/src/testing/types.d.ts +0 -228
  650. package/dist/types/src/testing/types.d.ts.map +0 -1
  651. package/src/errors.ts +0 -18
  652. package/src/internal/ast/annotation-helper.ts +0 -22
  653. package/src/internal/ast/annotations.test.ts +0 -98
  654. package/src/internal/ast/annotations.ts +0 -226
  655. package/src/internal/ast/entity-kind.ts +0 -15
  656. package/src/internal/ast/index.ts +0 -8
  657. package/src/internal/ast/types.ts +0 -17
  658. package/src/internal/object/accessors.ts +0 -153
  659. package/src/internal/object/create.test.ts +0 -118
  660. package/src/internal/object/create.ts +0 -96
  661. package/src/internal/object/deleted.ts +0 -19
  662. package/src/internal/object/entity.ts +0 -248
  663. package/src/internal/object/expando.ts +0 -21
  664. package/src/internal/object/ids.ts +0 -12
  665. package/src/internal/object/index.ts +0 -19
  666. package/src/internal/object/json-serializer.test.ts +0 -99
  667. package/src/internal/object/json-serializer.ts +0 -225
  668. package/src/internal/object/meta.ts +0 -61
  669. package/src/internal/object/model.ts +0 -170
  670. package/src/internal/object/relation.ts +0 -24
  671. package/src/internal/object/typed-object.test.ts +0 -34
  672. package/src/internal/object/typed-object.ts +0 -88
  673. package/src/internal/object/typename.ts +0 -61
  674. package/src/internal/object/version.ts +0 -22
  675. package/src/internal/projection/index.ts +0 -5
  676. package/src/internal/proxy/handler.test.ts +0 -163
  677. package/src/internal/proxy/reactive-object.ts +0 -108
  678. package/src/internal/proxy/schema.test.ts +0 -136
  679. package/src/internal/proxy/typed-handler.test.ts +0 -102
  680. package/src/internal/proxy/typed-handler.ts +0 -228
  681. package/src/internal/proxy/typed-object.test.ts +0 -100
  682. package/src/internal/query/index.ts +0 -5
  683. package/src/internal/query/query.ts +0 -23
  684. package/src/internal/ref/ref.test.ts +0 -100
  685. package/src/internal/schema/echo-schema.ts +0 -383
  686. package/src/internal/schema/index.ts +0 -10
  687. package/src/internal/schema/runtime-schema-registry.ts +0 -78
  688. package/src/internal/schema/snapshot.ts +0 -25
  689. package/src/internal/schema/stored-schema.ts +0 -26
  690. package/src/internal/testing/types.ts +0 -144
  691. package/src/internal/testing/utils.ts +0 -54
  692. package/src/internal/types/index.ts +0 -6
  693. package/src/internal/types/types.test.ts +0 -48
  694. package/src/internal/types/types.ts +0 -176
  695. package/src/internal/types/util.ts +0 -9
  696. package/src/query/index.ts +0 -6
  697. package/src/query/query.test.ts +0 -401
  698. package/src/query/query.ts +0 -789
  699. package/src/test/api.test.ts +0 -180
  700. package/src/testing/echo-schema.ts +0 -39
  701. package/src/testing/types.ts +0 -108
  702. /package/dist/lib/{browser/index.mjs.map → neutral/Annotation.mjs.map} +0 -0
  703. /package/dist/lib/{browser/internal/index.mjs.map → neutral/Database.mjs.map} +0 -0
  704. /package/dist/lib/{browser/query/index.mjs.map → neutral/Entity.mjs.map} +0 -0
  705. /package/dist/lib/{node-esm/index.mjs.map → neutral/Err.mjs.map} +0 -0
  706. /package/dist/lib/{node-esm/internal/index.mjs.map → neutral/Feed.mjs.map} +0 -0
  707. /package/dist/lib/{node-esm/query/index.mjs.map → neutral/Filter.mjs.map} +0 -0
  708. /package/dist/types/src/internal/{ast → Annotation}/annotations.test.d.ts +0 -0
  709. /package/dist/types/src/internal/{formats → Format}/date.d.ts +0 -0
  710. /package/dist/types/src/internal/{formats → Format}/date.test.d.ts +0 -0
  711. /package/dist/types/src/internal/{formats → Format}/format.test.d.ts +0 -0
  712. /package/dist/types/src/internal/{formats → Format}/number.d.ts +0 -0
  713. /package/dist/types/src/internal/{json → JsonSchema}/effect-schema.test.d.ts +0 -0
  714. /package/dist/types/src/internal/{json-schema → JsonSchema}/json-schema-normalize.d.ts +0 -0
  715. /package/dist/types/src/internal/{json → JsonSchema}/json-schema.test.d.ts +0 -0
  716. /package/dist/types/src/internal/{object → Obj}/common.d.ts +0 -0
  717. /package/dist/types/src/internal/{object → Obj}/inspect.d.ts +0 -0
  718. /package/dist/types/src/internal/{object → Obj}/json-serializer.test.d.ts +0 -0
  719. /package/dist/types/src/internal/{object → Obj}/schema-validator.test.d.ts +0 -0
  720. /package/dist/types/src/internal/{object → Obj}/typed-object.test.d.ts +0 -0
  721. /package/dist/types/src/internal/{ref → Ref}/index.d.ts +0 -0
  722. /package/dist/types/src/internal/{ref → Ref}/ref.test.d.ts +0 -0
  723. /package/dist/types/src/internal/{projection → Type}/compose.test.d.ts +0 -0
  724. /package/dist/types/src/internal/{proxy → common/proxy}/handler.test.d.ts +0 -0
  725. /package/dist/types/src/internal/{object → common/proxy}/schema-validator.d.ts +0 -0
  726. /package/dist/types/src/internal/{proxy → common/proxy}/schema.test.d.ts +0 -0
  727. /package/dist/types/src/internal/{proxy → common/proxy}/typed-handler.test.d.ts +0 -0
  728. /package/dist/types/src/internal/{proxy → common/proxy}/typed-object.test.d.ts +0 -0
  729. /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
  730. /package/src/internal/{json → JsonSchema}/effect-schema.test.ts +0 -0
  731. /package/src/internal/{ref → Ref}/index.ts +0 -0
package/src/Obj.ts CHANGED
@@ -2,70 +2,162 @@
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
 
14
+ import type { ForeignKey } from '@dxos/echo-protocol';
15
+ import { SchemaEx } from '@dxos/effect';
8
16
  import { assertArgument, invariant } from '@dxos/invariant';
9
- import { type DXN } from '@dxos/keys';
10
- import * as LiveObject from '@dxos/live-object';
17
+ import { EntityId, type URI } from '@dxos/keys';
11
18
  import { assumeType, deepMapValues } from '@dxos/util';
12
19
 
13
- import { live } from './internal';
14
- import * as EchoSchema from './internal';
15
- import type * as Ref from './Ref';
16
- import type * as Relation from './Relation';
20
+ import type * as Database from './Database';
21
+ import * as Entity from './Entity';
22
+ import * as Err from './Err';
23
+ import * as internal from './internal';
24
+ import { getProxyTarget, isProxy } from './internal/common/proxy/proxy-utils';
25
+ import * as objInternal from './internal/Obj';
26
+ import * as Ref from './Ref';
27
+ import type * as Tag from './Tag';
17
28
  import * as Type from './Type';
18
29
 
19
30
  /**
20
- * NOTE: Don't export: Obj.Any and Obj.Obj form the public API.
31
+ * Base type for all ECHO objects.
21
32
  */
22
- interface BaseObj extends EchoSchema.HasId, Type.OfKind<EchoSchema.EntityKind.Object> {}
33
+ interface BaseObj extends internal.AnyEntity, Entity.OfKind<typeof Entity.Kind.Object> {}
23
34
 
24
35
  /**
25
36
  * Object type with specific properties.
26
37
  */
27
- export type Obj<Props> = BaseObj & Props;
38
+ export type OfShape<Props> = BaseObj & Props;
28
39
 
29
40
  /**
30
- * Base type for all ECHO objects.
31
- * This type does not define any properties.
41
+ * Object with no known properties beyond id and kind.
42
+ * Use this when the object's schema/properties are not known.
43
+ * For objects with arbitrary properties, use `Obj.AnyProps`.
44
+ *
45
+ * NOTE: This is a TypeScript type only, not a schema.
46
+ * To validate that a value is an ECHO object, use `Schema.is(Type.Obj)`.
32
47
  */
33
- export interface Any extends BaseObj {}
48
+ export interface Unknown extends BaseObj {}
49
+
50
+ /**
51
+ * Runtime Effect schema for any ECHO object.
52
+ * Use for validation, parsing, or as a reference target for collections.
53
+ *
54
+ * NOTE: `Schema.is(Type.Obj)` does STRUCTURAL validation only (checks for `id` field).
55
+ * Use `Obj.isObject()` for proper ECHO instance type guards that check the KindId brand.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * // Structural type guard (accepts any object with id field)
60
+ * if (Schema.is(Type.Obj)(unknownValue)) { ... }
61
+ *
62
+ * // ECHO instance type guard (checks KindId brand)
63
+ * if (Obj.isObject(unknownValue)) { ... }
64
+ *
65
+ * // Reference to any object type
66
+ * const Collection = Schema.Struct({
67
+ * objects: Schema.Array(Ref.Ref(Obj.Unknown)),
68
+ * }).pipe(Type.makeObject(DXN.make('com.example.type.collection', '0.1.0')));
69
+ * ```
70
+ */
71
+ // TODO(wittjosiah): Investigate if Schema.filter can validate KindId on ECHO instances.
72
+ // Effect Schema normalizes proxy objects to plain objects before calling filter predicates.
73
+ // Possible approaches: custom Schema.declare, AST manipulation, or upstream contribution.
74
+ export const Unknown: internal.UnknownTypeSchema<Unknown, typeof Entity.Kind.Object> = Schema.Struct({
75
+ id: Schema.String,
76
+ }).pipe(
77
+ Schema.extend(Schema.Record({ key: Schema.String, value: Schema.Unknown })),
78
+ Schema.annotations({
79
+ [internal.TypeAnnotationId]: {
80
+ kind: Entity.Kind.Object,
81
+ typename: internal.ANY_OBJECT_TYPENAME,
82
+ version: internal.ANY_OBJECT_VERSION,
83
+ },
84
+ }),
85
+ ) as unknown as internal.UnknownTypeSchema<Unknown, typeof Entity.Kind.Object>;
34
86
 
35
87
  /**
36
88
  * Object with arbitrary properties.
37
89
  *
38
- * 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.
39
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.
40
94
  */
41
- export interface AnyProps extends BaseObj {
42
- [key: string]: any;
43
- }
44
-
45
- export const Any = Schema.Struct({}).pipe(
46
- Type.Obj({
47
- typename: 'dxos.org/types/Any',
48
- version: '0.1.0',
49
- }),
50
- );
95
+ export interface Any extends BaseObj, internal.AnyProperties {}
51
96
 
52
- type Props<T = any> = { id?: EchoSchema.ObjectId } & Type.Properties<T>;
97
+ /**
98
+ * Base type for snapshot objects (has SnapshotKindId instead of KindId).
99
+ */
100
+ interface BaseSnapshot extends internal.AnyEntity {
101
+ readonly [Entity.SnapshotKindId]: typeof Entity.Kind.Object;
102
+ readonly id: EntityId;
103
+ }
53
104
 
54
- export type MakeProps<T extends Type.Obj.Any> = NoInfer<Props<Schema.Schema.Type<T>>> & {
55
- [Meta]?: Partial<EchoSchema.ObjectMeta>;
56
- };
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;
57
115
 
58
- export const Meta: unique symbol = EchoSchema.MetaId as any;
116
+ /**
117
+ * JSON-encoded properties for objects.
118
+ */
119
+ export interface BaseObjJson {
120
+ id: string;
121
+ }
59
122
 
60
- const DEFAULT_META: EchoSchema.ObjectMeta = {
123
+ // Factory (not a shared const): each object must get its own `keys`/`tags`/`annotations` containers,
124
+ // otherwise mutating one object's meta would leak into every other object via the shared references.
125
+ const defaultMeta = (): internal.EntityMeta => ({
61
126
  keys: [],
62
- };
127
+ tags: [],
128
+ annotations: {},
129
+ });
63
130
 
131
+ // TODO(burdon): Should we allow the caller to set the id?
64
132
  /**
65
- * Creates new object.
66
- * @param schema - Object schema.
133
+ * Props type for object creation with a given type. Accepts a `Type.AnyObj`
134
+ * entity and derives the instance shape via `Type.InstanceType`. Relation-kind
135
+ * entities are rejected at the type level — use `Relation.MakeProps` for those.
136
+ *
137
+ * When the schema is the unconstrained `Type.AnyObj` (`Obj<unknown>` — e.g. a
138
+ * dynamic type from `schemaRegistry.register`), the instance shape is not
139
+ * statically known, so data props widen to `Record<string, unknown>` and the
140
+ * caller can pass arbitrary fields without a cast.
141
+ */
142
+ export type MakeProps<S extends Type.AnyObj> = {
143
+ id?: EntityId;
144
+ [Meta]?: Partial<internal.EntityMeta>;
145
+ [Parent]?: Unknown;
146
+ // When the resolved instance has no known data keys, widen to a permissive
147
+ // record (the `Obj<unknown>` case); otherwise use the precise property shape.
148
+ // `[keyof …] extends [never]` is wrapped in tuples so the check is
149
+ // non-distributive — a `never` instance type (e.g. when narrowing collapses
150
+ // the schema) stays a single branch instead of distributing to `never`.
151
+ } & ([keyof Entity.Properties<Type.InstanceType<S>>] extends [never]
152
+ ? Record<string, unknown>
153
+ : Entity.Properties<Type.InstanceType<S>>);
154
+
155
+ /**
156
+ * Creates a new echo object of the given schema or `Type.Type`.
157
+ *
158
+ * @param typeOrSchema - A static object schema (`Type.makeObject(...)`) or a
159
+ * `Type.Type` entity (e.g. one returned by `db.addType(schemaEntity)`).
67
160
  * @param props - Object properties.
68
- * @param meta - Object metadata (deprecated) -- pass with Obj.Meta.
69
161
  *
70
162
  * Meta can be passed as a symbol in `props`.
71
163
  *
@@ -73,359 +165,764 @@ const DEFAULT_META: EchoSchema.ObjectMeta = {
73
165
  * ```ts
74
166
  * const obj = Obj.make(Person, { [Obj.Meta]: { keys: [...] }, name: 'John' });
75
167
  * ```
168
+ *
169
+ * Note: Only accepts object schemas / object-kind types, not relation schemas.
170
+ * Use `Relation.make` for relations.
76
171
  */
77
- export const make = <S extends Type.Obj.Any>(
78
- schema: S,
79
- props: MakeProps<S>,
80
- meta?: Partial<EchoSchema.ObjectMeta>,
81
- ): LiveObject.Live<Schema.Schema.Type<S>> => {
172
+ export function make<T extends Type.AnyObj>(type: T, props: NoInfer<MakeProps<T>>): OfShape<Type.InstanceType<T>>;
173
+ export function make(input: Type.AnyObj, props: any): OfShape<any> {
174
+ // `Type.Type` entities aren't `Schema.Schema` themselves; derive the Effect
175
+ // Schema via `Type.getSchema(...)`. Pass the entity through to `makeObject`
176
+ // so subsequent schema mutations (`Type.addFields`, etc.) propagate.
177
+ const schema = Type.getSchema(input);
82
178
  assertArgument(
83
- EchoSchema.getTypeAnnotation(schema)?.kind === EchoSchema.EntityKind.Object,
179
+ internal.getTypeAnnotation(schema)?.kind === Entity.Kind.Object,
84
180
  'schema',
85
181
  'Expected an object schema',
86
182
  );
87
183
 
88
- if (props[EchoSchema.MetaId] != null) {
89
- // Set default fields on meta on creation.
90
- meta = { ...structuredClone(DEFAULT_META), ...props[EchoSchema.MetaId] };
91
- delete props[EchoSchema.MetaId];
184
+ let meta: internal.EntityMeta | undefined = undefined;
185
+
186
+ // Set default fields on meta on creation.
187
+ if (props[internal.MetaId] != null) {
188
+ meta = { ...defaultMeta(), ...props[internal.MetaId] };
189
+ delete props[internal.MetaId];
190
+ }
191
+
192
+ // Filter undefined values (Object.entries only returns string-keyed properties).
193
+ const filterUndefined: any = Object.fromEntries(Object.entries(props).filter(([_, v]) => v !== undefined));
194
+
195
+ // Copy symbol properties (like ParentId) that Object.entries doesn't include.
196
+ for (const sym of Object.getOwnPropertySymbols(props)) {
197
+ const value = (props as any)[sym];
198
+ if (value !== undefined) {
199
+ filterUndefined[sym] = value;
200
+ }
92
201
  }
93
202
 
94
- const filterUndefined = Object.fromEntries(Object.entries(props).filter(([_, v]) => v !== undefined));
203
+ return internal.makeObject(
204
+ schema,
205
+ filterUndefined,
206
+ {
207
+ ...defaultMeta(),
208
+ ...meta,
209
+ },
210
+ input,
211
+ );
212
+ }
95
213
 
96
- return live<Schema.Schema.Type<S>>(schema, filterUndefined as any, { keys: [], ...meta });
214
+ /**
215
+ * Determine if object is an ECHO object.
216
+ */
217
+ export const isObject = (obj: unknown): obj is Unknown => {
218
+ assumeType<internal.InternalObjectProps>(obj);
219
+ return typeof obj === 'object' && obj !== null && obj[Entity.KindId] === Entity.Kind.Object;
97
220
  };
98
221
 
99
- export const isObject = (obj: unknown): obj is Any => {
100
- assumeType<EchoSchema.InternalObjectProps>(obj);
101
- return typeof obj === 'object' && obj !== null && obj[EchoSchema.EntityKindId] === EchoSchema.EntityKind.Object;
222
+ export const isSnapshot = (obj: unknown): obj is Snapshot => {
223
+ assumeType<internal.InternalObjectProps>(obj);
224
+ return typeof obj === 'object' && obj !== null && (obj as any)[Entity.SnapshotKindId] === Entity.Kind.Object;
102
225
  };
103
226
 
104
227
  /**
105
- * Test if object or relation is an instance of a schema.
228
+ * Subscribe to object updates.
229
+ * The callback is called synchronously when the object is modified.
230
+ * Only accepts reactive objects (not snapshots).
231
+ * @returns Unsubscribe function.
232
+ */
233
+ export const subscribe = (obj: Unknown, callback: () => void): (() => void) => {
234
+ return internal.subscribe(obj, callback);
235
+ };
236
+
237
+ //
238
+ // Snapshot
239
+ //
240
+
241
+ /**
242
+ * Returns an immutable snapshot of an object.
243
+ * The snapshot is branded with SnapshotKindId instead of KindId,
244
+ * making it distinguishable from the reactive object at the type level.
245
+ */
246
+ export const getSnapshot: <T extends Unknown>(obj: T) => Snapshot<T> = objInternal.getSnapshot as any;
247
+
248
+ /**
249
+ * Returns the reactive version of an object from the database, given its snapshot.
250
+ * Inverse of `Obj.getSnapshot`.
251
+ *
252
+ * Uses `Obj.getDatabase` internally to get the database from the snapshot,
253
+ * then resolves the reactive object by ID.
254
+ *
255
+ * @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).
256
+ * @returns Effect that succeeds with the reactive object, or fails with `GetReactiveError`.
106
257
  * @example
107
258
  * ```ts
108
- * const john = Obj.make(Person, { name: 'John' });
109
- * const johnIsPerson = Obj.instanceOf(Person)(john);
259
+ * const snapshot = Obj.getSnapshot(obj);
260
+ * const reactive = Obj.getReactive(snapshot).pipe(
261
+ * Effect.runSync
262
+ * );
263
+ * ```
264
+ */
265
+ export const getReactive = <T extends Unknown>(snapshot: Snapshot<T>): Effect.Effect<T, Err.GetReactiveError> =>
266
+ Effect.gen(function* () {
267
+ const db = internal.getDatabase(snapshot);
268
+ if (!db) {
269
+ return yield* Effect.fail(new Err.GetReactiveError({ reason: 'no-database', snapshotId: snapshot.id }));
270
+ }
271
+ const obj = db.getObjectById(snapshot.id);
272
+ if (!obj) {
273
+ return yield* Effect.fail(new Err.GetReactiveError({ reason: 'object-not-found', snapshotId: snapshot.id }));
274
+ }
275
+ return obj as T;
276
+ });
277
+
278
+ /**
279
+ * Like `Obj.getReactive` but returns `Option.none()` instead of failing when the object
280
+ * cannot be resolved (no database, object not found).
110
281
  *
282
+ * @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).
283
+ * @returns Effect that succeeds with `Option.some(reactive)` or `Option.none()`.
284
+ */
285
+ export const getReactiveOption = <T extends Unknown>(snapshot: Snapshot<T>): Effect.Effect<Option.Option<T>, never> =>
286
+ getReactive(snapshot).pipe(
287
+ Effect.map(Option.some),
288
+ Effect.catchAll(() => Effect.succeed(Option.none())),
289
+ );
290
+
291
+ /**
292
+ * Synchronous version of `Obj.getReactive`. Returns the reactive object or throws
293
+ * `GetReactiveError` when the object cannot be resolved (no database, object not found).
294
+ *
295
+ * @param snapshot - A snapshot of the object (from `Obj.getSnapshot`).
296
+ * @returns The reactive object.
297
+ * @throws {Err.GetReactiveError} When the object cannot be resolved.
298
+ */
299
+ export const getReactiveOrThrow = <T extends Unknown>(snapshot: Snapshot<T>): T =>
300
+ Effect.runSync(getReactive(snapshot));
301
+
302
+ export type CloneOptions = {
303
+ /**
304
+ * Retain the original object's ID.
305
+ * @default false
306
+ */
307
+ retainId?: boolean;
308
+
309
+ /**
310
+ * Recursively clone referenced objects.
311
+ * @default false
312
+ */
313
+ deep?: boolean;
314
+ };
315
+
316
+ /**
317
+ * Clones an object or relation.
318
+ * This does not clone referenced objects, only the properties in the object.
319
+ * @returns A new object with the same schema and properties.
320
+ */
321
+ export const clone: <T extends Unknown>(obj: T, opts?: CloneOptions) => T = objInternal.clone;
322
+
323
+ //
324
+ // Change
325
+ //
326
+
327
+ /**
328
+ * Makes all properties mutable recursively.
329
+ * Used to provide a mutable view of an object within `Obj.update`.
330
+ */
331
+ export type Mutable<T> = internal.Mutable<T>;
332
+
333
+ /**
334
+ * Perform mutations on an echo object within a controlled context.
335
+ *
336
+ * All mutations within the callback are batched and trigger a single notification
337
+ * when the callback completes. Direct mutations outside of `Obj.update` will throw
338
+ * an error for echo objects.
339
+ *
340
+ * This function also works with nested objects within echo objects (e.g., Template structs)
341
+ * that are reactive at runtime.
342
+ *
343
+ * @param obj - The echo object to mutate. Use `Relation.update` for relations.
344
+ * @param callback - The callback that performs mutations on the object.
345
+ *
346
+ * @example
347
+ * ```ts
348
+ * const person = Obj.make(Person, { name: 'John', age: 25 });
349
+ *
350
+ * // Mutate within Obj.update
351
+ * Obj.update(person, (obj) => {
352
+ * obj.name = 'Jane';
353
+ * obj.age = 30;
354
+ * });
355
+ * // ONE notification fires here
356
+ *
357
+ * // Direct mutation throws
358
+ * person.name = 'Bob'; // Error: Cannot modify outside Obj.update()
359
+ * ```
360
+ *
361
+ * Note: Only accepts objects. Use `Relation.update` for relations.
362
+ */
363
+ export const update = <T extends Unknown>(obj: T, callback: internal.ChangeCallback<T>): void => {
364
+ internal.change(obj, callback);
365
+ };
366
+
367
+ /**
368
+ * Get a deeply nested property from an object.
369
+ *
370
+ * Similar to lodash.get and getDeep from @dxos/util.
371
+ * This is the complementary function to setValue.
372
+ * Accepts both reactive objects and snapshots.
373
+ *
374
+ * @param obj - The ECHO object to get the property from.
375
+ * @param path - Path to the property (array of keys).
376
+ * @returns The value at the path, or undefined if not found.
377
+ *
378
+ * @example
379
+ * ```ts
380
+ * const person = Obj.make(Person, {
381
+ * name: 'John',
382
+ * addresses: [{ street: '123 Main St' }]
383
+ * });
384
+ *
385
+ * Obj.getValue(person, ['addresses', 0, 'street']); // '123 Main St'
386
+ * Obj.getValue(person, ['addresses', 1, 'street']); // undefined
387
+ * ```
388
+ */
389
+ export const getValue = (obj: Unknown | Snapshot, path: readonly (string | number)[]): any => {
390
+ return SchemaEx.getValue(obj, SchemaEx.createJsonPath(path));
391
+ };
392
+
393
+ /**
394
+ * Set a deeply nested property on an object, using the object's schema to determine
395
+ * whether to initialize nested data as an empty object or array.
396
+ *
397
+ * Similar to lodash.set and setDeep from @dxos/util, but schema-aware.
398
+ * Must be called within an `Obj.update` callback.
399
+ *
400
+ * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
401
+ * parameters, so there is no compile-time error. Enforcement is runtime-only.
402
+ *
403
+ * @param obj - The mutable ECHO object to set the property on.
404
+ * @param path - Path to the property (array of keys).
405
+ * @param value - Value to set.
406
+ * @returns The value that was set.
407
+ *
408
+ * @example
409
+ * ```ts
410
+ * const person = Obj.make(Person, { name: 'John' });
411
+ * // Person schema has: addresses: Schema.Array(Address)
412
+ * Obj.update(person, (obj) => {
413
+ * Obj.setValue(obj, ['addresses', 0, 'street'], '123 Main St');
414
+ * });
415
+ * // Creates: person.addresses = [{ street: '123 Main St' }]
416
+ * ```
417
+ */
418
+ // TODO(wittjosiah): Compute possible path values + type value based on generic object type.
419
+ export const setValue: (obj: Mutable<Unknown>, path: readonly (string | number)[], value: any) => void =
420
+ objInternal.setValue as any;
421
+
422
+ //
423
+ // Type
424
+ //
425
+
426
+ export const ID = EntityId;
427
+ export type ID = EntityId;
428
+
429
+ /**
430
+ * Test if an object is an instance of a given object type.
431
+ *
432
+ * @example
433
+ * ```ts
434
+ * const john = Obj.make(Person, { name: 'John' });
111
435
  * const isPerson = Obj.instanceOf(Person);
112
436
  * if (isPerson(john)) {
113
437
  * // john is Person
114
438
  * }
115
439
  * ```
440
+ *
441
+ * Only accepts `Type.AnyObj` — use `Relation.instanceOf` for relations and
442
+ * `Type.isType(value)` to test for `Type.Type` meta-schema entities.
116
443
  */
117
444
  export const instanceOf: {
118
- <S extends Type.Relation.Any | Type.Obj.Any>(schema: S): (value: unknown) => value is Schema.Schema.Type<S>;
119
- <S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is Schema.Schema.Type<S>;
120
- } = ((
121
- ...args: [schema: Type.Relation.Any | Type.Obj.Any, value: unknown] | [schema: Type.Relation.Any | Type.Obj.Any]
122
- ) => {
445
+ // Reject `Type.Type` at the type level those are meta-schema entities, not
446
+ // object instances. Use `Type.isType(value)` instead.
447
+ <T extends Type.Type>(
448
+ type: T,
449
+ _hint?: never,
450
+ // eslint-disable-next-line @typescript-eslint/unified-signatures
451
+ ..._error: ['ERROR: Obj.instanceOf does not accept Type.Type; use Type.isType(value) instead']
452
+ ): never;
453
+ // Reject relation types — use `Relation.instanceOf` instead.
454
+ <R extends Type.AnyRelation>(
455
+ type: R,
456
+ _hint?: never,
457
+ // eslint-disable-next-line @typescript-eslint/unified-signatures
458
+ ..._error: ['ERROR: Obj.instanceOf does not accept relation types; use Relation.instanceOf instead']
459
+ ): never;
460
+ <S extends Type.AnyObj>(schema: S): (value: unknown) => value is Type.InstanceType<S>;
461
+ <S extends Type.AnyObj>(schema: S, value: unknown): value is Type.InstanceType<S>;
462
+ } = ((...args: [schema: Type.AnyEntity, value?: unknown]) => {
123
463
  if (args.length === 1) {
124
- return (obj: unknown) => EchoSchema.isInstanceOf(args[0], obj);
464
+ return (entity: unknown) => internal.isInstanceOf(args[0], entity);
125
465
  }
126
466
 
127
- return EchoSchema.isInstanceOf(args[0], args[1]);
467
+ return internal.isInstanceOf(args[0], args[1]);
128
468
  }) as any;
129
469
 
130
- export const getSchema = EchoSchema.getSchema;
470
+ /**
471
+ * Test if a snapshot is an instance of a schema.
472
+ * Mirrors `instanceOf` but only accepts values branded with SnapshotKindId.
473
+ * Use when the value is known to be a snapshot (e.g. from `getSnapshot` or `useObject`).
474
+ *
475
+ * @example
476
+ * ```ts
477
+ * const snapshot = Obj.getSnapshot(person);
478
+ * if (Obj.snapshotOf(Person, snapshot)) {
479
+ * // snapshot is Obj.Snapshot<Person>
480
+ * }
481
+ * ```
482
+ */
483
+ export const snapshotOf: {
484
+ <S extends Type.AnyObj>(schema: S): (value: unknown) => value is Snapshot<Type.InstanceType<S>>;
485
+ <S extends Type.AnyObj>(schema: S, value: unknown): value is Snapshot<Type.InstanceType<S>>;
486
+ } = ((...args: [schema: Type.AnyObj, value: unknown] | [schema: Type.AnyObj]) => {
487
+ const check = (entity: unknown) =>
488
+ entity != null &&
489
+ typeof entity === 'object' &&
490
+ Entity.SnapshotKindId in entity &&
491
+ internal.isInstanceOf(args[0], entity);
492
+
493
+ if (args.length === 1) {
494
+ return (entity: unknown) => check(entity);
495
+ }
496
+
497
+ return check(args[1]);
498
+ }) as any;
499
+
500
+ export type { GetURIOptions } from './internal';
131
501
 
132
502
  // TODO(dmaretskyi): Allow returning undefined.
133
- export const getDXN = (obj: Any | Relation.Any): DXN => {
134
- assertArgument(!Schema.isSchema(obj), 'obj', 'Object should not be a schema.');
135
- const dxn = EchoSchema.getObjectDXN(obj);
136
- invariant(dxn != null, 'Invalid object.');
137
- return dxn;
503
+ /**
504
+ * Get the URI of the object.
505
+ * Accepts both reactive objects and snapshots.
506
+ *
507
+ * @param options.prefer - Controls the URI form (see {@link GetURIOptions}).
508
+ */
509
+ export const getURI = (entity: Unknown | Snapshot, options?: internal.GetURIOptions): URI.URI => {
510
+ assertArgument(!Schema.isSchema(entity), 'obj', 'Object should not be a schema.');
511
+ return internal.getUri(entity, options);
138
512
  };
139
513
 
140
514
  /**
141
515
  * @returns The DXN of the object's type.
142
- * @example dxn:example.com/type/Person:1.0.0
516
+ * @example dxn:com.example.type.person:1.0.0
517
+ * @throws If the object is missing its type (corrupted object).
518
+ */
519
+ export const getTypeURI = (obj: Unknown | Snapshot): URI.URI => {
520
+ const type = internal.getTypeURI(obj);
521
+ invariant(type != null, 'Corrupted object: missing type.');
522
+ return type;
523
+ };
524
+
525
+ /**
526
+ * Get the type entity (`Type.AnyObj`) the object was created from.
527
+ *
528
+ * Returns `undefined` when the object's type isn't registered in this runtime
529
+ * (e.g. a freshly deserialized snapshot whose type entity hasn't been wired
530
+ * up yet, or an object loaded from storage before its schema is known). To
531
+ * get the Effect Schema from the returned entity, use `Type.getSchema(...)`.
143
532
  */
144
- // TODO(burdon): Expando does not have a type.
145
- export const getTypeDXN = EchoSchema.getType;
533
+ export const getType = (obj: Unknown | Snapshot): Type.AnyObj | undefined =>
534
+ internal.getType(obj) as Type.AnyObj | undefined;
146
535
 
147
536
  /**
148
537
  * @returns The typename of the object's type.
149
- * @example `example.com/type/Person`
538
+ * Accepts both reactive objects and snapshots.
539
+ * @example `com.example.type.person`
150
540
  */
151
- export const getTypename = (obj: Any | Relation.Any): string | undefined => {
152
- const schema = getSchema(obj);
153
- if (schema == null) {
154
- // Try to extract typename from DXN.
155
- return EchoSchema.getType(obj)?.asTypeDXN()?.type;
156
- }
541
+ export const getTypename = (entity: Unknown | Snapshot): string | undefined => internal.getTypename(entity);
157
542
 
158
- return EchoSchema.getSchemaTypename(schema);
159
- };
543
+ //
544
+ // Database
545
+ //
546
+
547
+ /**
548
+ * Get the database the object belongs to.
549
+ * Accepts both reactive objects and snapshots.
550
+ *
551
+ * @idiom org.dxos.echo.objGetDatabase
552
+ * applies: Reaching an object's database — to query, add, or remove — when the surrounding Space is not otherwise needed
553
+ * instead-of: `getSpace(obj)?.db` (resolving the whole Space just to read its `.db`)
554
+ * uses: {@link getDatabase}
555
+ */
556
+ export const getDatabase = (entity: Entity.Unknown | Entity.Snapshot): Database.Database | undefined =>
557
+ internal.getDatabase(entity);
160
558
 
559
+ //
560
+ // Meta
561
+ //
562
+
563
+ /**
564
+ * Property that accesses metadata for an entity.
565
+ *
566
+ * Alias for `Entity.Meta`.
567
+ */
568
+ export const Meta = internal.MetaId;
569
+
570
+ /**
571
+ * Deeply read-only version of EntityMeta.
572
+ * Prevents mutation at all nesting levels (e.g., `meta.keys.push()` is a TypeScript error).
573
+ */
574
+ export type ReadonlyMeta = internal.ReadonlyMeta;
575
+
576
+ /**
577
+ * Mutable meta type returned by `Obj.getMeta` inside an `Obj.update` callback.
578
+ */
579
+ export type Meta = internal.Meta;
580
+
581
+ // TODO(burdon): Narrow type.
161
582
  // TODO(dmaretskyi): Allow returning undefined.
162
- export const getMeta = (obj: Any | Relation.Any): EchoSchema.ObjectMeta => {
163
- const meta = EchoSchema.getMeta(obj);
164
- invariant(meta != null, 'Invalid object.');
165
- return meta;
166
- };
583
+ /**
584
+ * Get the metadata for an object.
585
+ * Returns mutable meta when passed a mutable object (inside `Obj.update` callback).
586
+ * Returns read-only meta when passed a regular object or snapshot.
587
+ *
588
+ * @example
589
+ * ```ts
590
+ * // Read-only access outside change callback
591
+ * const meta = Obj.getMeta(person); // ReadonlyMeta
592
+ *
593
+ * // Mutable access inside change callback
594
+ * Obj.update(person, (obj) => {
595
+ * const meta = Obj.getMeta(obj); // EntityMeta (mutable)
596
+ * meta.tags.push(Ref.make(tag)); // tags are refs to Tag objects
597
+ * });
598
+ * ```
599
+ */
600
+ // TODO(wittjosiah): When passed a Snapshot, should return a snapshot of meta, not the live meta proxy.
601
+ export function getMeta(entity: Mutable<Unknown>): Meta;
602
+ export function getMeta(entity: Unknown | Snapshot): ReadonlyMeta;
603
+ export function getMeta(entity: Unknown | Snapshot | Mutable<Unknown>): Meta | ReadonlyMeta {
604
+ return internal.getMetaChecked(entity);
605
+ }
167
606
 
168
607
  /**
169
608
  * @returns Foreign keys for the object from the specified source.
609
+ * Accepts both reactive objects and snapshots.
170
610
  */
171
611
  export const getKeys: {
172
- (obj: Any | Relation.Any, source: string): EchoSchema.ForeignKey[];
173
- (source: string): (obj: Any | Relation.Any) => EchoSchema.ForeignKey[];
174
- } = Function.dual(2, (obj: Any | Relation.Any, source?: string): EchoSchema.ForeignKey[] => {
175
- const meta = EchoSchema.getMeta(obj);
176
- invariant(meta != null, 'Invalid object.');
177
- return meta.keys.filter((key) => key.source === source);
178
- });
612
+ (entity: Unknown | Snapshot, source: string): ForeignKey[];
613
+ (source: string): (entity: Unknown | Snapshot) => ForeignKey[];
614
+ } = Function.dual(2, (entity: Unknown | Snapshot, source?: string): ForeignKey[] => internal.getKeys(entity, source!));
179
615
 
180
616
  /**
181
617
  * Delete all keys from the object for the specified source.
182
- * @param obj
183
- * @param source
184
- */
185
- export const deleteKeys = (obj: Any | Relation.Any, source: string) => {
186
- const meta = EchoSchema.getMeta(obj);
187
- for (let i = 0; i < meta.keys.length; i++) {
188
- if (meta.keys[i].source === source) {
189
- meta.keys.splice(i, 1);
190
- i--;
191
- }
192
- }
193
- };
618
+ * Must be called within an `Obj.update` callback.
619
+ *
620
+ * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
621
+ * parameters, so there is no compile-time error. Enforcement is runtime-only.
622
+ */
623
+ export const deleteKeys = (entity: Mutable<Unknown>, source: string): void => internal.deleteKeys(entity, source);
624
+
625
+ /**
626
+ * Add a tag to the object.
627
+ * Must be called within an `Obj.update` callback.
628
+ *
629
+ * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
630
+ * parameters, so there is no compile-time error. Enforcement is runtime-only.
631
+ */
632
+ export const addTag = (entity: Mutable<Unknown>, tag: Ref.Ref<Tag.Tag>): void => internal.addTag(entity, tag);
194
633
 
634
+ /**
635
+ * Remove a tag from the object.
636
+ * Must be called within an `Obj.update` callback.
637
+ *
638
+ * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
639
+ * parameters, so there is no compile-time error. Enforcement is runtime-only.
640
+ */
641
+ export const removeTag = (entity: Mutable<Unknown>, tag: Ref.Ref<Tag.Tag>): void => internal.removeTag(entity, tag);
642
+
643
+ /**
644
+ * Check if the object is deleted.
645
+ * Accepts both reactive objects and snapshots.
646
+ */
195
647
  // TODO(dmaretskyi): Default to `false`.
196
- export const isDeleted = (obj: Any | Relation.Any): boolean => {
197
- const deleted = EchoSchema.isDeleted(obj);
198
- invariant(typeof deleted === 'boolean', 'Invalid object.');
199
- return deleted;
200
- };
648
+ export const isDeleted = (entity: Unknown | Snapshot): boolean => objInternal.isDeleted(entity);
201
649
 
202
- export const getLabel = (obj: Any | Relation.Any): string | undefined => {
203
- const schema = getSchema(obj);
204
- if (schema != null) {
205
- return EchoSchema.getLabel(schema, obj);
206
- }
207
- };
650
+ //
651
+ // Annotations
652
+ //
208
653
 
209
- export const setLabel = (obj: Any | Relation.Any, label: string) => {
210
- const schema = getSchema(obj);
211
- if (schema != null) {
212
- EchoSchema.setLabel(schema, obj, label);
213
- }
214
- };
654
+ /**
655
+ * Get the label of the object.
656
+ * Accepts both reactive objects and snapshots.
657
+ *
658
+ * @param options.fallback `'typename'` returns the object's typename when no
659
+ * label is set (e.g. `org.dxos.type.table`).
660
+ */
661
+ export const getLabel = (entity: Unknown | Snapshot, options?: internal.GetLabelOptions): string | undefined =>
662
+ internal.getLabel(entity, options);
215
663
 
216
- export const getDescription = (obj: Any | Relation.Any): string | undefined => {
217
- const schema = getSchema(obj);
218
- if (schema != null) {
219
- return EchoSchema.getDescription(schema, obj);
220
- }
221
- };
664
+ /**
665
+ * Set the label of the object.
666
+ * Must be called within an `Obj.update` callback.
667
+ *
668
+ * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
669
+ * parameters, so there is no compile-time error. Enforcement is runtime-only.
670
+ */
671
+ export const setLabel = (entity: Mutable<Unknown>, label: string): void => internal.setLabel(entity, label);
222
672
 
223
- export const setDescription = (obj: Any | Relation.Any, description: string) => {
224
- const schema = getSchema(obj);
225
- if (schema != null) {
226
- EchoSchema.setDescription(schema, obj, description);
227
- }
673
+ /**
674
+ * Get the description of the object.
675
+ * Accepts both reactive objects and snapshots.
676
+ */
677
+ export const getDescription = (entity: Unknown | Snapshot): string | undefined => internal.getDescription(entity);
678
+
679
+ /**
680
+ * Get the icon annotation for the object (or any entity), resolved via its type-level
681
+ * `IconAnnotation`. Accepts both reactive entities and snapshots, and either Objects or
682
+ * Relations — the underlying schema-based lookup works for both.
683
+ *
684
+ * Returns the full `{ icon, hue }` annotation; callers wanting just the icon name typically
685
+ * write `Obj.getIcon(obj)?.icon ?? 'ph--cube--regular'`.
686
+ */
687
+ export const getIcon = (entity: Entity.Unknown | Entity.Snapshot): internal.IconAnnotation | undefined =>
688
+ internal.getIcon(entity);
689
+
690
+ /**
691
+ * Set the description of the object.
692
+ * Must be called within an `Obj.update` callback.
693
+ *
694
+ * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
695
+ * parameters, so there is no compile-time error. Enforcement is runtime-only.
696
+ */
697
+ export const setDescription = (entity: Mutable<Unknown>, description: string): void =>
698
+ internal.setDescription(entity, description);
699
+
700
+ /**
701
+ * Symbol to set parent when creating objects with `Obj.make`.
702
+ * @example
703
+ * ```ts
704
+ * Obj.make(TestSchema.Person, {
705
+ * [Obj.Parent]: parentObject,
706
+ * name: 'John',
707
+ * })
708
+ * ```
709
+ */
710
+ export const Parent: unique symbol = internal.ParentId as any;
711
+
712
+ /**
713
+ * Get the parent of an object.
714
+ * The parent is always loaded together with the object.
715
+ * Only objects are allowed to have a parent
716
+ * @returns The parent object, or undefined if the object has no parent.
717
+ */
718
+ export const getParent = (entity: Unknown | Snapshot): Unknown | undefined => {
719
+ assertArgument(isObject(entity) || isSnapshot(entity), 'Expected an object');
720
+ assumeType<internal.InternalObjectProps>(entity);
721
+ return entity[internal.ParentId] as Unknown | undefined;
228
722
  };
229
723
 
230
- export const addTag = (obj: Any | Relation.Any, tag: string) => {
231
- const meta = getMeta(obj);
232
- meta.tags ??= [];
233
- meta.tags.push(tag);
724
+ /**
725
+ * Sets the parent of an object.
726
+ * If a parent (or any transitive parent) is deleted, the object will be deleted.
727
+ * Only objects are allowed to have a parent.
728
+ */
729
+ export const setParent = (entity: Unknown, parent: Any | undefined) => {
730
+ assertArgument(isObject(entity), 'Expected an object');
731
+ assertArgument(parent === undefined || isObject(parent), 'Expected an object');
732
+ assumeType<internal.InternalObjectProps>(entity);
733
+ assumeType<internal.InternalObjectProps | undefined>(parent);
734
+ entity[internal.ParentId] = parent;
735
+ return entity;
234
736
  };
235
737
 
236
- export const removeTag = (obj: Any | Relation.Any, tag: string) => {
237
- const meta = getMeta(obj);
238
- if (!meta.tags) {
239
- return;
738
+ interface UpdateFromOptions<T> {
739
+ exclude?: (keyof T)[];
740
+ include?: (keyof T)[];
741
+ }
742
+
743
+ const valuesEqual = (left: unknown, right: unknown): boolean => {
744
+ if (left === right) {
745
+ return true;
746
+ }
747
+ if (left === null || right === null) {
748
+ return left === right;
749
+ }
750
+ if (typeof left !== 'object' || typeof right !== 'object') {
751
+ return Utils.structuralRegion(() => Equal.equals(left, right));
240
752
  }
241
- for (let i = 0; i < meta.tags.length; i++) {
242
- if (meta.tags[i] === tag) {
243
- meta.tags.splice(i, 1);
244
- i--;
753
+ if (Ref.isRef(left) && Ref.isRef(right)) {
754
+ return left.uri === right.uri;
755
+ }
756
+ if (Ref.isRef(left) || Ref.isRef(right)) {
757
+ return false;
758
+ }
759
+ if (Array.isArray(left) && Array.isArray(right)) {
760
+ if (left.length !== right.length) {
761
+ return false;
762
+ }
763
+ for (let index = 0; index < left.length; index++) {
764
+ if (!valuesEqual(left[index], right[index])) {
765
+ return false;
766
+ }
245
767
  }
768
+ return true;
246
769
  }
247
- };
248
-
249
- const compare = (a?: string, b?: string) => {
250
- if (a == null) {
251
- return b == null ? 0 : 1;
770
+ if (Array.isArray(left) || Array.isArray(right)) {
771
+ return false;
252
772
  }
253
-
254
- if (b == null) {
255
- return -1;
773
+ const leftRecord = left as Record<string, unknown>;
774
+ const rightRecord = right as Record<string, unknown>;
775
+ const keys = new Set([
776
+ ...Object.keys(leftRecord).filter((key) => key !== 'id'),
777
+ ...Object.keys(rightRecord).filter((key) => key !== 'id'),
778
+ ]);
779
+ for (const key of keys) {
780
+ const leftHas = Object.hasOwn(leftRecord, key);
781
+ const rightHas = Object.hasOwn(rightRecord, key);
782
+ const leftValue = leftHas ? leftRecord[key] : undefined;
783
+ const rightValue = rightHas ? rightRecord[key] : undefined;
784
+ if (!valuesEqual(leftValue, rightValue)) {
785
+ return false;
786
+ }
256
787
  }
257
-
258
- return a.localeCompare(b);
788
+ return true;
259
789
  };
260
790
 
261
- export type Comparator = (a: Any, b: Any) => number;
262
-
263
- export const sortByLabel: Comparator = (a: Any, b: Any) => compare(getLabel(a), getLabel(b));
264
- export const sortByTypename: Comparator = (a: Any, b: Any) => compare(getTypename(a), getTypename(b));
265
- export const sort = (...comparators: Comparator[]): Comparator => {
266
- return (a: Any, b: Any) => {
267
- for (const comparator of comparators) {
268
- const result = comparator(a, b);
269
- if (result !== 0) {
270
- return result;
271
- }
791
+ /**
792
+ * Breaks reactive proxies on assigned values so echo-db assignment accepts nested structs (same idea as link assignment).
793
+ */
794
+ const prepareAssignValue = (value: unknown): unknown =>
795
+ deepMapValues(value, (nested, recurse) => {
796
+ if (nested === null || typeof nested !== 'object') {
797
+ return nested;
798
+ }
799
+ if (Ref.isRef(nested)) {
800
+ return nested;
801
+ }
802
+ if (Array.isArray(nested)) {
803
+ return recurse(nested);
804
+ }
805
+ if (isProxy(nested)) {
806
+ return recurse({ ...getProxyTarget(nested) });
272
807
  }
808
+ return recurse(nested);
809
+ });
273
810
 
274
- return 0;
275
- };
811
+ /**
812
+ * For each key present on `source` (except `id`), assigns `target[key]` when the current value differs.
813
+ * References are compared by target DXN; other values use Effect `Equal.equals` inside a structural region,
814
+ * with recursive comparison for arrays and plain object-shaped property bags (excluding `id`).
815
+ *
816
+ * Must be called within an `Obj.update` callback.
817
+ *
818
+ * @returns Whether any property was updated.
819
+ */
820
+ export const updateFrom = <T extends Unknown>(
821
+ target: Mutable<T>,
822
+ source: T,
823
+ options?: UpdateFromOptions<T>,
824
+ ): boolean => {
825
+ assertArgument(isObject(target), 'Expected an echo object target.');
826
+ assertArgument(isObject(source), 'Expected an echo object source.');
827
+ let keys = Object.keys(source as Record<string, unknown>).filter((key) => key !== 'id');
828
+ if (options?.include !== undefined) {
829
+ const include = new Set(options.include.map((key) => String(key)));
830
+ keys = keys.filter((key) => include.has(key));
831
+ }
832
+ if (options?.exclude !== undefined) {
833
+ const exclude = new Set(options.exclude.map((key) => String(key)));
834
+ keys = keys.filter((key) => !exclude.has(key));
835
+ }
836
+ let updated = false;
837
+ const sourceRecord = source as Record<string, unknown>;
838
+ const targetRecord = target as Record<string, unknown>;
839
+ for (const key of keys) {
840
+ if (!Object.hasOwn(sourceRecord, key)) {
841
+ continue;
842
+ }
843
+ const nextValue = sourceRecord[key];
844
+ const prevValue = Object.hasOwn(targetRecord, key) ? targetRecord[key] : undefined;
845
+ if (valuesEqual(prevValue, nextValue)) {
846
+ continue;
847
+ }
848
+ targetRecord[key] = prepareAssignValue(nextValue) as never;
849
+ updated = true;
850
+ }
851
+ return updated;
276
852
  };
277
853
 
854
+ //
855
+ // JSON
856
+ //
857
+
278
858
  /**
279
859
  * JSON representation of an object.
280
860
  */
281
- export type JSON = EchoSchema.ObjectJSON;
861
+ export type JSON = internal.ObjectJSON;
282
862
 
283
863
  /**
284
864
  * Converts object to its JSON representation.
865
+ * Accepts both reactive objects and snapshots.
285
866
  *
286
867
  * The same algorithm is used when calling the standard `JSON.stringify(obj)` function.
287
868
  */
288
- // TODO(burdon): Base util type for Obj/Relation?
289
- export const toJSON = (obj: Any | Relation.Any): JSON => EchoSchema.objectToJSON(obj);
869
+ export const toJSON = (entity: Unknown | Snapshot): JSON => objInternal.objectToJSON(entity);
290
870
 
291
871
  /**
292
872
  * Creates an object from its json representation, performing schema validation.
293
873
  * References and schemas will be resolvable if the `refResolver` is provided.
294
874
  *
295
- * The function need to be async to support resolving the schema as well as the relation endpoints.
875
+ * The function must be async to support resolving the schema as well as the relation endpoints.
296
876
  *
297
877
  * @param options.refResolver - Resolver for references. Produces hydrated references that can be resolved.
298
- * @param options.dxn - Override object DXN. Changes the result of `Obj.getDXN`.
878
+ * @param options.uri - Override object URI. Changes the result of `Obj.getURI`.
879
+ * @param options.database - Database to associate with the object.
299
880
  */
300
- export const fromJSON: (json: unknown, options?: { refResolver?: Ref.Resolver; dxn?: DXN }) => Promise<Any> =
301
- EchoSchema.objectFromJSON as any;
881
+ export const fromJSON: (
882
+ json: unknown,
883
+ options?: { refResolver?: Ref.Resolver; uri?: URI.URI; database?: Database.Database; parent?: Unknown },
884
+ ) => Promise<Unknown> = objInternal.objectFromJSON as any;
302
885
 
303
886
  /**
304
- * Returns an immutable snapshot of an object.
887
+ * Comparator function type for sorting objects.
888
+ * Accepts both reactive objects and snapshots.
305
889
  */
306
- export const getSnapshot: <T extends Any>(obj: Obj<T>) => T = LiveObject.getSnapshot;
890
+ export type Comparator = internal.Comparator<Unknown | Snapshot>;
307
891
 
308
- export type CloneOptions = {
309
- /**
310
- * Retain the original object's ID.
311
- * @default false
312
- */
313
- retainId?: boolean;
314
- };
892
+ export const sortByLabel: Comparator = internal.sortByLabel as Comparator;
893
+ export const sortByTypename: Comparator = internal.sortByTypename as Comparator;
894
+ export const sort = (...comparators: Comparator[]): Comparator => internal.sort(...comparators) as Comparator;
315
895
 
316
- /**
317
- * Clones an object or relation.
318
- * This does not clone referenced objects, only the properties in the object.
319
- * @returns A new object with the same schema and properties.
320
- */
321
- export const clone = <T extends Any | Relation.Any>(obj: T, opts?: CloneOptions): T => {
322
- const { id, ...data } = obj;
323
- const schema = getSchema(obj);
324
- invariant(schema != null, 'Object should have a schema');
325
- const props: any = deepMapValues(data, (value, recurse) => {
326
- if (EchoSchema.Ref.isRef(value)) {
327
- return value;
328
- }
329
- return recurse(value);
330
- });
331
- if (opts?.retainId) {
332
- props.id = id;
333
- }
334
- const meta = getMeta(obj);
335
- props[EchoSchema.MetaId] = deepMapValues(meta, (value, recurse) => {
336
- if (EchoSchema.Ref.isRef(value)) {
337
- return value;
338
- }
339
- return recurse(value);
340
- });
341
- return make(schema, props);
342
- };
896
+ //
897
+ // Version
898
+ //
343
899
 
344
- export const VersionTypeId = EchoSchema.VersionTypeId;
345
- export type VersionType = typeof VersionTypeId;
900
+ export const VersionTypeId = internal.VersionTypeId;
901
+ export type VersionCompareResult = internal.VersionCompareResult;
346
902
 
347
903
  /**
348
904
  * Represent object version.
349
905
  * May be backed by Automerge.
350
906
  * Objects with no history are not versioned.
351
907
  */
352
- export interface Version {
353
- [VersionTypeId]: {};
908
+ export type Version = internal.EntityVersion;
354
909
 
355
- /**
356
- * Whether the object is versioned.
357
- */
358
- versioned: boolean;
359
-
360
- /**
361
- * Automerge heads.
362
- */
363
- automergeHeads?: string[];
364
- }
365
-
366
- const unversioned: Version = {
367
- [VersionTypeId]: {},
368
- versioned: false,
369
- };
370
-
371
- /**
372
- * Checks that `obj` is a version object.
373
- */
374
- export const isVersion = (obj: unknown): obj is Version => {
375
- return obj != null && typeof obj === 'object' && VersionTypeId in obj;
376
- };
910
+ export const isVersion = internal.isVersion;
911
+ export const versionValid = internal.versionValid;
912
+ export const compareVersions = internal.compareVersions;
913
+ export const encodeVersion = internal.encodeVersion;
914
+ export const decodeVersion = internal.decodeVersion;
377
915
 
378
916
  /**
379
917
  * Returns the version of the object.
918
+ * Accepts both reactive objects and snapshots.
380
919
  */
381
- export const version = (obj: Any | Relation.Any): Version => {
382
- const version = (obj as any)[EchoSchema.ObjectVersionId];
383
- if (version === undefined) {
384
- return unversioned;
385
- }
386
- return version;
387
- };
388
-
389
- /**
390
- * Checks that `version` is a valid version object.
391
- */
392
- export const versionValid = (version: Version): boolean => {
393
- assertArgument(isVersion(version), 'version', 'Invalid version object');
394
- return !!version.versioned;
395
- };
396
-
397
- export type VersionCompareResult = 'unversioned' | 'equal' | 'different';
398
-
399
- /**
400
- * Compares two versions.
401
- * @param version1
402
- * @param version2
403
- * @returns 'unversioned' if either object is unversioned, 'equal' if the versions are equal, 'different' if the versions are different.
404
- */
405
- export const compareVersions = (version1: Version, version2: Version): VersionCompareResult => {
406
- assertArgument(isVersion(version1), 'version1', 'Invalid version object');
407
- assertArgument(isVersion(version2), 'version2', 'Invalid version object');
408
-
409
- if (!versionValid(version1) || !versionValid(version2)) {
410
- return 'unversioned';
411
- }
412
-
413
- if (version1.automergeHeads?.length !== version2.automergeHeads?.length) {
414
- return 'different';
415
- }
416
- if (version1.automergeHeads?.some((head) => !version2.automergeHeads?.includes(head))) {
417
- return 'different';
418
- }
419
-
420
- return 'equal';
421
- };
920
+ export const version = (entity: Unknown | Snapshot): Version => internal.version(entity);
422
921
 
423
- export const encodeVersion = (version: Version): string => {
424
- return JSON.stringify(version);
425
- };
922
+ //
923
+ // Atoms
924
+ //
426
925
 
427
- export const decodeVersion = (version: string): Version => {
428
- const parsed = JSON.parse(version);
429
- parsed[VersionTypeId] = {};
430
- return parsed;
431
- };
926
+ export const atom = objInternal.makeAtom;
927
+ export const atomReactive = objInternal.makeWithReactive;
928
+ export const atomProperty = objInternal.makeProperty;