@dxos/echo 0.8.4-main.fd6878d → 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 (567) 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/Entity.mjs.map +7 -0
  7. package/dist/lib/neutral/Err.mjs +12 -0
  8. package/dist/lib/neutral/Err.mjs.map +7 -0
  9. package/dist/lib/neutral/Feed.mjs +54 -0
  10. package/dist/lib/neutral/Feed.mjs.map +7 -0
  11. package/dist/lib/neutral/Filter.mjs +70 -0
  12. package/dist/lib/neutral/Filter.mjs.map +7 -0
  13. package/dist/lib/neutral/Format.mjs +86 -0
  14. package/dist/lib/neutral/Format.mjs.map +7 -0
  15. package/dist/lib/neutral/JsonSchema.mjs +18 -0
  16. package/dist/lib/neutral/JsonSchema.mjs.map +7 -0
  17. package/dist/lib/neutral/Key.mjs +16 -0
  18. package/dist/lib/neutral/Key.mjs.map +7 -0
  19. package/dist/lib/neutral/Migration.mjs +18 -0
  20. package/dist/lib/neutral/Migration.mjs.map +7 -0
  21. package/dist/lib/neutral/Obj.mjs +122 -0
  22. package/dist/lib/neutral/Obj.mjs.map +7 -0
  23. package/dist/lib/neutral/Order.mjs +16 -0
  24. package/dist/lib/neutral/Order.mjs.map +7 -0
  25. package/dist/lib/neutral/Query.mjs +38 -0
  26. package/dist/lib/neutral/Query.mjs.map +7 -0
  27. package/dist/lib/neutral/QueryResult.mjs +2 -0
  28. package/dist/lib/neutral/QueryResult.mjs.map +7 -0
  29. package/dist/lib/neutral/Ref.mjs +25 -0
  30. package/dist/lib/neutral/Ref.mjs.map +7 -0
  31. package/dist/lib/neutral/Registry.mjs +14 -0
  32. package/dist/lib/neutral/Registry.mjs.map +7 -0
  33. package/dist/lib/neutral/Relation.mjs +97 -0
  34. package/dist/lib/neutral/Relation.mjs.map +7 -0
  35. package/dist/lib/neutral/Scope.mjs +12 -0
  36. package/dist/lib/neutral/Scope.mjs.map +7 -0
  37. package/dist/lib/neutral/Tag.mjs +32 -0
  38. package/dist/lib/neutral/Tag.mjs.map +7 -0
  39. package/dist/lib/neutral/Type.mjs +65 -0
  40. package/dist/lib/neutral/Type.mjs.map +7 -0
  41. package/dist/lib/neutral/chunk-35INCYOE.mjs +7 -0
  42. package/dist/lib/neutral/chunk-35INCYOE.mjs.map +7 -0
  43. package/dist/lib/neutral/chunk-3PBP4V4O.mjs +101 -0
  44. package/dist/lib/neutral/chunk-3PBP4V4O.mjs.map +7 -0
  45. package/dist/lib/neutral/chunk-4ZUHOTCG.mjs +184 -0
  46. package/dist/lib/neutral/chunk-4ZUHOTCG.mjs.map +7 -0
  47. package/dist/lib/neutral/chunk-5SMDBFVB.mjs +108 -0
  48. package/dist/lib/neutral/chunk-5SMDBFVB.mjs.map +7 -0
  49. package/dist/lib/neutral/chunk-5SUJPHAE.mjs +34 -0
  50. package/dist/lib/neutral/chunk-5SUJPHAE.mjs.map +7 -0
  51. package/dist/lib/neutral/chunk-6M2Z6WBH.mjs +93 -0
  52. package/dist/lib/neutral/chunk-6M2Z6WBH.mjs.map +7 -0
  53. package/dist/lib/neutral/chunk-6YDI3J37.mjs +346 -0
  54. package/dist/lib/neutral/chunk-6YDI3J37.mjs.map +7 -0
  55. package/dist/lib/neutral/chunk-7FPIAJIV.mjs +2279 -0
  56. package/dist/lib/neutral/chunk-7FPIAJIV.mjs.map +7 -0
  57. package/dist/lib/neutral/chunk-7LOUAPYZ.mjs +25 -0
  58. package/dist/lib/neutral/chunk-7LOUAPYZ.mjs.map +7 -0
  59. package/dist/lib/neutral/chunk-7PI7C4EF.mjs +747 -0
  60. package/dist/lib/neutral/chunk-7PI7C4EF.mjs.map +7 -0
  61. package/dist/lib/neutral/chunk-BBFJWWAV.mjs +51 -0
  62. package/dist/lib/neutral/chunk-BBFJWWAV.mjs.map +7 -0
  63. package/dist/lib/neutral/chunk-EVK6XBXO.mjs +56 -0
  64. package/dist/lib/neutral/chunk-EVK6XBXO.mjs.map +7 -0
  65. package/dist/lib/neutral/chunk-IGK6FN65.mjs +27 -0
  66. package/dist/lib/neutral/chunk-IGK6FN65.mjs.map +7 -0
  67. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  68. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  69. package/dist/lib/neutral/chunk-LWXVKPPW.mjs +281 -0
  70. package/dist/lib/neutral/chunk-LWXVKPPW.mjs.map +7 -0
  71. package/dist/lib/neutral/chunk-MZ7K3MLL.mjs +48 -0
  72. package/dist/lib/neutral/chunk-MZ7K3MLL.mjs.map +7 -0
  73. package/dist/lib/neutral/chunk-O6BH7EPN.mjs +94 -0
  74. package/dist/lib/neutral/chunk-O6BH7EPN.mjs.map +7 -0
  75. package/dist/lib/neutral/chunk-QQIYS74I.mjs +336 -0
  76. package/dist/lib/neutral/chunk-QQIYS74I.mjs.map +7 -0
  77. package/dist/lib/neutral/chunk-R5W6DXR4.mjs +678 -0
  78. package/dist/lib/neutral/chunk-R5W6DXR4.mjs.map +7 -0
  79. package/dist/lib/neutral/chunk-RIVWNMSF.mjs +41 -0
  80. package/dist/lib/neutral/chunk-RIVWNMSF.mjs.map +7 -0
  81. package/dist/lib/neutral/chunk-SBVFRTST.mjs +160 -0
  82. package/dist/lib/neutral/chunk-SBVFRTST.mjs.map +7 -0
  83. package/dist/lib/neutral/chunk-T6E37YIP.mjs +251 -0
  84. package/dist/lib/neutral/chunk-T6E37YIP.mjs.map +7 -0
  85. package/dist/lib/neutral/chunk-TFEWTY5A.mjs +428 -0
  86. package/dist/lib/neutral/chunk-TFEWTY5A.mjs.map +7 -0
  87. package/dist/lib/neutral/chunk-TYGKCRMK.mjs +437 -0
  88. package/dist/lib/neutral/chunk-TYGKCRMK.mjs.map +7 -0
  89. package/dist/lib/neutral/chunk-UUP46KUQ.mjs +205 -0
  90. package/dist/lib/neutral/chunk-UUP46KUQ.mjs.map +7 -0
  91. package/dist/lib/neutral/chunk-WISOH2XH.mjs +36 -0
  92. package/dist/lib/neutral/chunk-WISOH2XH.mjs.map +7 -0
  93. package/dist/lib/neutral/chunk-WTQJHC75.mjs +395 -0
  94. package/dist/lib/neutral/chunk-WTQJHC75.mjs.map +7 -0
  95. package/dist/lib/neutral/chunk-WU3GIANS.mjs +31 -0
  96. package/dist/lib/neutral/chunk-WU3GIANS.mjs.map +7 -0
  97. package/dist/lib/neutral/chunk-ZGNNFYHS.mjs +132 -0
  98. package/dist/lib/neutral/chunk-ZGNNFYHS.mjs.map +7 -0
  99. package/dist/lib/neutral/index.mjs +111 -0
  100. package/dist/lib/neutral/index.mjs.map +7 -0
  101. package/dist/lib/neutral/internal/index.mjs +539 -0
  102. package/dist/lib/neutral/internal/index.mjs.map +7 -0
  103. package/dist/lib/neutral/meta.json +1 -0
  104. package/dist/lib/neutral/testing/index.mjs +458 -0
  105. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  106. package/dist/types/src/Annotation.d.ts +128 -0
  107. package/dist/types/src/Annotation.d.ts.map +1 -0
  108. package/dist/types/src/Annotation.test.d.ts +2 -0
  109. package/dist/types/src/Annotation.test.d.ts.map +1 -0
  110. package/dist/types/src/Collection.d.ts +15 -0
  111. package/dist/types/src/Collection.d.ts.map +1 -0
  112. package/dist/types/src/Database.d.ts +208 -0
  113. package/dist/types/src/Database.d.ts.map +1 -0
  114. package/dist/types/src/Dataset.d.ts +29 -0
  115. package/dist/types/src/Dataset.d.ts.map +1 -0
  116. package/dist/types/src/Entity.d.ts +247 -0
  117. package/dist/types/src/Entity.d.ts.map +1 -0
  118. package/dist/types/src/Entity.test.d.ts +2 -0
  119. package/dist/types/src/Entity.test.d.ts.map +1 -0
  120. package/dist/types/src/Err.d.ts +107 -0
  121. package/dist/types/src/Err.d.ts.map +1 -0
  122. package/dist/types/src/Feed.d.ts +229 -0
  123. package/dist/types/src/Feed.d.ts.map +1 -0
  124. package/dist/types/src/Filter.d.ts +175 -0
  125. package/dist/types/src/Filter.d.ts.map +1 -0
  126. package/dist/types/src/Filter.test.d.ts +2 -0
  127. package/dist/types/src/Filter.test.d.ts.map +1 -0
  128. package/dist/types/src/Format.d.ts +2 -0
  129. package/dist/types/src/Format.d.ts.map +1 -0
  130. package/dist/types/src/Hypergraph.d.ts +70 -0
  131. package/dist/types/src/Hypergraph.d.ts.map +1 -0
  132. package/dist/types/src/Json.d.ts +33 -0
  133. package/dist/types/src/Json.d.ts.map +1 -0
  134. package/dist/types/src/Json.test.d.ts +2 -0
  135. package/dist/types/src/Json.test.d.ts.map +1 -0
  136. package/dist/types/src/JsonSchema.d.ts +16 -0
  137. package/dist/types/src/JsonSchema.d.ts.map +1 -0
  138. package/dist/types/src/Key.d.ts +2 -1
  139. package/dist/types/src/Key.d.ts.map +1 -1
  140. package/dist/types/src/Migration.d.ts +72 -0
  141. package/dist/types/src/Migration.d.ts.map +1 -0
  142. package/dist/types/src/Obj.d.ts +514 -53
  143. package/dist/types/src/Obj.d.ts.map +1 -1
  144. package/dist/types/src/Obj.test.d.ts +2 -0
  145. package/dist/types/src/Obj.test.d.ts.map +1 -0
  146. package/dist/types/src/Order.d.ts +26 -0
  147. package/dist/types/src/Order.d.ts.map +1 -0
  148. package/dist/types/src/Query.d.ts +231 -0
  149. package/dist/types/src/Query.d.ts.map +1 -0
  150. package/dist/types/src/Query.test.d.ts +2 -0
  151. package/dist/types/src/Query.test.d.ts.map +1 -0
  152. package/dist/types/src/QueryResult.d.ts +101 -0
  153. package/dist/types/src/QueryResult.d.ts.map +1 -0
  154. package/dist/types/src/Ref.d.ts +69 -11
  155. package/dist/types/src/Ref.d.ts.map +1 -1
  156. package/dist/types/src/Registry.d.ts +131 -0
  157. package/dist/types/src/Registry.d.ts.map +1 -0
  158. package/dist/types/src/Relation.d.ts +323 -24
  159. package/dist/types/src/Relation.d.ts.map +1 -1
  160. package/dist/types/src/Relation.test.d.ts +2 -0
  161. package/dist/types/src/Relation.test.d.ts.map +1 -0
  162. package/dist/types/src/Scope.d.ts +35 -0
  163. package/dist/types/src/Scope.d.ts.map +1 -0
  164. package/dist/types/src/Tag.d.ts +34 -0
  165. package/dist/types/src/Tag.d.ts.map +1 -0
  166. package/dist/types/src/Type.d.ts +397 -107
  167. package/dist/types/src/Type.d.ts.map +1 -1
  168. package/dist/types/src/Type.test.d.ts +2 -0
  169. package/dist/types/src/Type.test.d.ts.map +1 -0
  170. package/dist/types/src/View.d.ts +65 -0
  171. package/dist/types/src/View.d.ts.map +1 -0
  172. package/dist/types/src/exemplars.test.d.ts +2 -0
  173. package/dist/types/src/exemplars.test.d.ts.map +1 -0
  174. package/dist/types/src/hierarchy.test.d.ts +2 -0
  175. package/dist/types/src/hierarchy.test.d.ts.map +1 -0
  176. package/dist/types/src/index.d.ts +22 -3
  177. package/dist/types/src/index.d.ts.map +1 -1
  178. package/dist/types/src/internal/Annotation/annotations.d.ts +272 -0
  179. package/dist/types/src/internal/Annotation/annotations.d.ts.map +1 -0
  180. package/dist/types/src/internal/Annotation/annotations.test.d.ts +2 -0
  181. package/dist/types/src/internal/Annotation/annotations.test.d.ts.map +1 -0
  182. package/dist/types/src/internal/Annotation/dictionary.d.ts +24 -0
  183. package/dist/types/src/internal/Annotation/dictionary.d.ts.map +1 -0
  184. package/dist/types/src/internal/Annotation/entity-dictionary.d.ts +14 -0
  185. package/dist/types/src/internal/Annotation/entity-dictionary.d.ts.map +1 -0
  186. package/dist/types/src/internal/Annotation/index.d.ts +6 -0
  187. package/dist/types/src/internal/Annotation/index.d.ts.map +1 -0
  188. package/dist/types/src/internal/Annotation/sorting.d.ts +24 -0
  189. package/dist/types/src/internal/Annotation/sorting.d.ts.map +1 -0
  190. package/dist/types/src/internal/Annotation/util.d.ts +48 -0
  191. package/dist/types/src/internal/Annotation/util.d.ts.map +1 -0
  192. package/dist/types/src/internal/Entity/api.d.ts +27 -0
  193. package/dist/types/src/internal/Entity/api.d.ts.map +1 -0
  194. package/dist/types/src/internal/Entity/entity.d.ts +84 -0
  195. package/dist/types/src/internal/Entity/entity.d.ts.map +1 -0
  196. package/dist/types/src/internal/Entity/guard.d.ts +10 -0
  197. package/dist/types/src/internal/Entity/guard.d.ts.map +1 -0
  198. package/dist/types/src/internal/Entity/index.d.ts +10 -0
  199. package/dist/types/src/internal/Entity/index.d.ts.map +1 -0
  200. package/dist/types/src/internal/Entity/model.d.ts +59 -0
  201. package/dist/types/src/internal/Entity/model.d.ts.map +1 -0
  202. package/dist/types/src/internal/Entity/object.d.ts +18 -0
  203. package/dist/types/src/internal/Entity/object.d.ts.map +1 -0
  204. package/dist/types/src/internal/Entity/relation.d.ts +58 -0
  205. package/dist/types/src/internal/Entity/relation.d.ts.map +1 -0
  206. package/dist/types/src/internal/Entity/type-kind.d.ts +24 -0
  207. package/dist/types/src/internal/Entity/type-kind.d.ts.map +1 -0
  208. package/dist/types/src/internal/Entity/type-uri.d.ts +24 -0
  209. package/dist/types/src/internal/Entity/type-uri.d.ts.map +1 -0
  210. package/dist/types/src/internal/Entity/util.d.ts +2 -0
  211. package/dist/types/src/internal/Entity/util.d.ts.map +1 -0
  212. package/dist/types/src/internal/Entity/version.d.ts +42 -0
  213. package/dist/types/src/internal/Entity/version.d.ts.map +1 -0
  214. package/dist/types/src/internal/Format/date.d.ts +63 -0
  215. package/dist/types/src/internal/Format/date.d.ts.map +1 -0
  216. package/dist/types/src/internal/Format/date.test.d.ts +2 -0
  217. package/dist/types/src/internal/Format/date.test.d.ts.map +1 -0
  218. package/dist/types/src/internal/Format/format.d.ts +33 -0
  219. package/dist/types/src/internal/Format/format.d.ts.map +1 -0
  220. package/dist/types/src/internal/Format/format.test.d.ts +2 -0
  221. package/dist/types/src/internal/Format/format.test.d.ts.map +1 -0
  222. package/dist/types/src/internal/Format/index.d.ts +8 -0
  223. package/dist/types/src/internal/Format/index.d.ts.map +1 -0
  224. package/dist/types/src/internal/Format/number.d.ts +31 -0
  225. package/dist/types/src/internal/Format/number.d.ts.map +1 -0
  226. package/dist/types/src/internal/Format/object.d.ts +37 -0
  227. package/dist/types/src/internal/Format/object.d.ts.map +1 -0
  228. package/dist/types/src/internal/Format/select.d.ts +13 -0
  229. package/dist/types/src/internal/Format/select.d.ts.map +1 -0
  230. package/dist/types/src/internal/Format/string.d.ts +42 -0
  231. package/dist/types/src/internal/Format/string.d.ts.map +1 -0
  232. package/dist/types/src/internal/Format/types.d.ts +72 -0
  233. package/dist/types/src/internal/Format/types.d.ts.map +1 -0
  234. package/dist/types/src/internal/JsonSchema/annotations.d.ts +19 -0
  235. package/dist/types/src/internal/JsonSchema/annotations.d.ts.map +1 -0
  236. package/dist/types/src/internal/JsonSchema/effect-schema.test.d.ts +2 -0
  237. package/dist/types/src/internal/JsonSchema/effect-schema.test.d.ts.map +1 -0
  238. package/dist/types/src/internal/JsonSchema/index.d.ts +5 -0
  239. package/dist/types/src/internal/JsonSchema/index.d.ts.map +1 -0
  240. package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts +7 -0
  241. package/dist/types/src/internal/JsonSchema/json-schema-normalize.d.ts.map +1 -0
  242. package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts +351 -0
  243. package/dist/types/src/internal/JsonSchema/json-schema-type.d.ts.map +1 -0
  244. package/dist/types/src/internal/JsonSchema/json-schema.d.ts +31 -0
  245. package/dist/types/src/internal/JsonSchema/json-schema.d.ts.map +1 -0
  246. package/dist/types/src/internal/JsonSchema/json-schema.test.d.ts +2 -0
  247. package/dist/types/src/internal/JsonSchema/json-schema.test.d.ts.map +1 -0
  248. package/dist/types/src/internal/Obj/atoms.d.ts +38 -0
  249. package/dist/types/src/internal/Obj/atoms.d.ts.map +1 -0
  250. package/dist/types/src/internal/Obj/clone.d.ts +8 -0
  251. package/dist/types/src/internal/Obj/clone.d.ts.map +1 -0
  252. package/dist/types/src/internal/Obj/common.d.ts +18 -0
  253. package/dist/types/src/internal/Obj/common.d.ts.map +1 -0
  254. package/dist/types/src/internal/Obj/create-object.d.ts +39 -0
  255. package/dist/types/src/internal/Obj/create-object.d.ts.map +1 -0
  256. package/dist/types/src/internal/Obj/create-object.test.d.ts +2 -0
  257. package/dist/types/src/internal/Obj/create-object.test.d.ts.map +1 -0
  258. package/dist/types/src/internal/Obj/deleted.d.ts +6 -0
  259. package/dist/types/src/internal/Obj/deleted.d.ts.map +1 -0
  260. package/dist/types/src/internal/Obj/index.d.ts +11 -0
  261. package/dist/types/src/internal/Obj/index.d.ts.map +1 -0
  262. package/dist/types/src/internal/Obj/inspect.d.ts +2 -0
  263. package/dist/types/src/internal/Obj/inspect.d.ts.map +1 -0
  264. package/dist/types/src/internal/Obj/json-serializer.d.ts +45 -0
  265. package/dist/types/src/internal/Obj/json-serializer.d.ts.map +1 -0
  266. package/dist/types/src/internal/Obj/json-serializer.test.d.ts +2 -0
  267. package/dist/types/src/internal/Obj/json-serializer.test.d.ts.map +1 -0
  268. package/dist/types/src/internal/Obj/schema-validator.d.ts +2 -0
  269. package/dist/types/src/internal/Obj/schema-validator.d.ts.map +1 -0
  270. package/dist/types/src/internal/Obj/schema-validator.test.d.ts +2 -0
  271. package/dist/types/src/internal/Obj/schema-validator.test.d.ts.map +1 -0
  272. package/dist/types/src/internal/Obj/set-value.d.ts +7 -0
  273. package/dist/types/src/internal/Obj/set-value.d.ts.map +1 -0
  274. package/dist/types/src/internal/Obj/set-value.test.d.ts +2 -0
  275. package/dist/types/src/internal/Obj/set-value.test.d.ts.map +1 -0
  276. package/dist/types/src/internal/Obj/snapshot.d.ts +6 -0
  277. package/dist/types/src/internal/Obj/snapshot.d.ts.map +1 -0
  278. package/dist/types/src/internal/Obj/typed-object.d.ts +25 -0
  279. package/dist/types/src/internal/Obj/typed-object.d.ts.map +1 -0
  280. package/dist/types/src/internal/Obj/typed-object.test.d.ts +2 -0
  281. package/dist/types/src/internal/Obj/typed-object.test.d.ts.map +1 -0
  282. package/dist/types/src/internal/Query/index.d.ts +2 -0
  283. package/dist/types/src/internal/Query/index.d.ts.map +1 -0
  284. package/dist/types/src/internal/Query/pretty.d.ts +10 -0
  285. package/dist/types/src/internal/Query/pretty.d.ts.map +1 -0
  286. package/dist/types/src/internal/Ref/atoms.d.ts +10 -0
  287. package/dist/types/src/internal/Ref/atoms.d.ts.map +1 -0
  288. package/dist/types/src/internal/Ref/index.d.ts +3 -0
  289. package/dist/types/src/internal/Ref/index.d.ts.map +1 -0
  290. package/dist/types/src/internal/Ref/ref-array.d.ts +21 -0
  291. package/dist/types/src/internal/Ref/ref-array.d.ts.map +1 -0
  292. package/dist/types/src/internal/Ref/ref.d.ts +262 -0
  293. package/dist/types/src/internal/Ref/ref.d.ts.map +1 -0
  294. package/dist/types/src/internal/Ref/ref.test.d.ts +2 -0
  295. package/dist/types/src/internal/Ref/ref.test.d.ts.map +1 -0
  296. package/dist/types/src/internal/Ref/utils.d.ts +8 -0
  297. package/dist/types/src/internal/Ref/utils.d.ts.map +1 -0
  298. package/dist/types/src/internal/Type/compose.d.ts +7 -0
  299. package/dist/types/src/internal/Type/compose.d.ts.map +1 -0
  300. package/dist/types/src/internal/Type/compose.test.d.ts +2 -0
  301. package/dist/types/src/internal/Type/compose.test.d.ts.map +1 -0
  302. package/dist/types/src/internal/Type/index.d.ts +3 -0
  303. package/dist/types/src/internal/Type/index.d.ts.map +1 -0
  304. package/dist/types/src/internal/Type/manipulation.d.ts +9 -0
  305. package/dist/types/src/internal/Type/manipulation.d.ts.map +1 -0
  306. package/dist/types/src/internal/Type/type-schema.d.ts +52 -0
  307. package/dist/types/src/internal/Type/type-schema.d.ts.map +1 -0
  308. package/dist/types/src/internal/common/api/index.d.ts +11 -0
  309. package/dist/types/src/internal/common/api/index.d.ts.map +1 -0
  310. package/dist/types/src/internal/common/api/meta.d.ts +45 -0
  311. package/dist/types/src/internal/common/api/meta.d.ts.map +1 -0
  312. package/dist/types/src/internal/common/index.d.ts +4 -0
  313. package/dist/types/src/internal/common/index.d.ts.map +1 -0
  314. package/dist/types/src/internal/common/proxy/change-context.d.ts +55 -0
  315. package/dist/types/src/internal/common/proxy/change-context.d.ts.map +1 -0
  316. package/dist/types/src/internal/common/proxy/change.test.d.ts +2 -0
  317. package/dist/types/src/internal/common/proxy/change.test.d.ts.map +1 -0
  318. package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts +5 -0
  319. package/dist/types/src/internal/common/proxy/define-hidden-property.d.ts.map +1 -0
  320. package/dist/types/src/internal/common/proxy/errors.d.ts +19 -0
  321. package/dist/types/src/internal/common/proxy/errors.d.ts.map +1 -0
  322. package/dist/types/src/internal/common/proxy/event-batch.d.ts +10 -0
  323. package/dist/types/src/internal/common/proxy/event-batch.d.ts.map +1 -0
  324. package/dist/types/src/internal/common/proxy/handler.test.d.ts +2 -0
  325. package/dist/types/src/internal/common/proxy/handler.test.d.ts.map +1 -0
  326. package/dist/types/src/internal/common/proxy/index.d.ts +14 -0
  327. package/dist/types/src/internal/common/proxy/index.d.ts.map +1 -0
  328. package/dist/types/src/internal/common/proxy/json-serializer.d.ts +6 -0
  329. package/dist/types/src/internal/common/proxy/json-serializer.d.ts.map +1 -0
  330. package/dist/types/src/internal/common/proxy/make-object.d.ts +20 -0
  331. package/dist/types/src/internal/common/proxy/make-object.d.ts.map +1 -0
  332. package/dist/types/src/internal/common/proxy/ownership.d.ts +57 -0
  333. package/dist/types/src/internal/common/proxy/ownership.d.ts.map +1 -0
  334. package/dist/types/src/internal/common/proxy/proxy-types.d.ts +18 -0
  335. package/dist/types/src/internal/common/proxy/proxy-types.d.ts.map +1 -0
  336. package/dist/types/src/internal/common/proxy/proxy-utils.d.ts +47 -0
  337. package/dist/types/src/internal/common/proxy/proxy-utils.d.ts.map +1 -0
  338. package/dist/types/src/internal/common/proxy/reactive-array.d.ts +8 -0
  339. package/dist/types/src/internal/common/proxy/reactive-array.d.ts.map +1 -0
  340. package/dist/types/src/internal/common/proxy/reactive.d.ts +39 -0
  341. package/dist/types/src/internal/common/proxy/reactive.d.ts.map +1 -0
  342. package/dist/types/src/internal/common/proxy/reactive.test.d.ts +2 -0
  343. package/dist/types/src/internal/common/proxy/reactive.test.d.ts.map +1 -0
  344. package/dist/types/src/internal/common/proxy/schema-validator.d.ts +15 -0
  345. package/dist/types/src/internal/common/proxy/schema-validator.d.ts.map +1 -0
  346. package/dist/types/src/internal/common/proxy/schema.test.d.ts +2 -0
  347. package/dist/types/src/internal/common/proxy/schema.test.d.ts.map +1 -0
  348. package/dist/types/src/internal/common/proxy/symbols.d.ts +3 -0
  349. package/dist/types/src/internal/common/proxy/symbols.d.ts.map +1 -0
  350. package/dist/types/src/internal/common/proxy/typed-handler.d.ts +64 -0
  351. package/dist/types/src/internal/common/proxy/typed-handler.d.ts.map +1 -0
  352. package/dist/types/src/internal/common/proxy/typed-handler.test.d.ts +2 -0
  353. package/dist/types/src/internal/common/proxy/typed-handler.test.d.ts.map +1 -0
  354. package/dist/types/src/internal/common/proxy/typed-object.test.d.ts +2 -0
  355. package/dist/types/src/internal/common/proxy/typed-object.test.d.ts.map +1 -0
  356. package/dist/types/src/internal/common/types/base.d.ts +27 -0
  357. package/dist/types/src/internal/common/types/base.d.ts.map +1 -0
  358. package/dist/types/src/internal/common/types/entity.d.ts +94 -0
  359. package/dist/types/src/internal/common/types/entity.d.ts.map +1 -0
  360. package/dist/types/src/internal/common/types/index.d.ts +7 -0
  361. package/dist/types/src/internal/common/types/index.d.ts.map +1 -0
  362. package/dist/types/src/internal/common/types/meta.d.ts +54 -0
  363. package/dist/types/src/internal/common/types/meta.d.ts.map +1 -0
  364. package/dist/types/src/internal/common/types/model-symbols.d.ts +65 -0
  365. package/dist/types/src/internal/common/types/model-symbols.d.ts.map +1 -0
  366. package/dist/types/src/internal/common/types/typename.d.ts +28 -0
  367. package/dist/types/src/internal/common/types/typename.d.ts.map +1 -0
  368. package/dist/types/src/internal/common/types/version.d.ts +15 -0
  369. package/dist/types/src/internal/common/types/version.d.ts.map +1 -0
  370. package/dist/types/src/internal/common/types/well-known-types.d.ts +11 -0
  371. package/dist/types/src/internal/common/types/well-known-types.d.ts.map +1 -0
  372. package/dist/types/src/internal/index.d.ts +11 -0
  373. package/dist/types/src/internal/index.d.ts.map +1 -0
  374. package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
  375. package/dist/types/src/testing/index.d.ts +4 -1
  376. package/dist/types/src/testing/index.d.ts.map +1 -1
  377. package/dist/types/src/testing/registry.d.ts +9 -0
  378. package/dist/types/src/testing/registry.d.ts.map +1 -0
  379. package/dist/types/src/testing/test-data.d.ts +18 -0
  380. package/dist/types/src/testing/test-data.d.ts.map +1 -0
  381. package/dist/types/src/testing/test-schema.d.ts +298 -0
  382. package/dist/types/src/testing/test-schema.d.ts.map +1 -0
  383. package/dist/types/src/testing/util.d.ts +23 -0
  384. package/dist/types/src/testing/util.d.ts.map +1 -0
  385. package/dist/types/tsconfig.tsbuildinfo +1 -1
  386. package/package.json +122 -57
  387. package/src/Annotation.test.ts +439 -0
  388. package/src/Annotation.ts +202 -0
  389. package/src/Collection.ts +33 -0
  390. package/src/Database.ts +345 -0
  391. package/src/Dataset.ts +34 -0
  392. package/src/Entity.test.ts +132 -0
  393. package/src/Entity.ts +345 -0
  394. package/src/Err.ts +40 -0
  395. package/src/Feed.ts +352 -0
  396. package/src/Filter.test.ts +90 -0
  397. package/src/Filter.ts +484 -0
  398. package/src/Format.ts +5 -0
  399. package/src/Hypergraph.ts +84 -0
  400. package/src/Json.test.ts +175 -0
  401. package/src/Json.ts +103 -0
  402. package/src/JsonSchema.ts +26 -0
  403. package/src/Key.ts +4 -1
  404. package/src/Migration.ts +114 -0
  405. package/src/Obj.test.ts +641 -0
  406. package/src/Obj.ts +836 -105
  407. package/src/Order.ts +68 -0
  408. package/src/Query.test.ts +835 -0
  409. package/src/Query.ts +634 -0
  410. package/src/QueryResult.ts +132 -0
  411. package/src/Ref.ts +97 -10
  412. package/src/Registry.ts +155 -0
  413. package/src/Relation.test.ts +88 -0
  414. package/src/Relation.ts +508 -61
  415. package/src/Scope.ts +50 -0
  416. package/src/Tag.md +88 -0
  417. package/src/Tag.ts +84 -0
  418. package/src/Type.test.ts +257 -0
  419. package/src/Type.ts +643 -152
  420. package/src/View.ts +98 -0
  421. package/src/exemplars.test.ts +21 -0
  422. package/src/hierarchy.test.ts +33 -0
  423. package/src/index.ts +24 -4
  424. package/src/internal/Annotation/annotations.test.ts +165 -0
  425. package/src/internal/Annotation/annotations.ts +609 -0
  426. package/src/internal/Annotation/dictionary.ts +47 -0
  427. package/src/internal/Annotation/entity-dictionary.ts +74 -0
  428. package/src/internal/Annotation/index.ts +9 -0
  429. package/src/internal/Annotation/sorting.ts +51 -0
  430. package/src/internal/Annotation/util.ts +94 -0
  431. package/src/internal/Entity/api.ts +77 -0
  432. package/src/internal/Entity/entity.ts +277 -0
  433. package/src/internal/Entity/guard.ts +26 -0
  434. package/src/internal/Entity/index.ts +13 -0
  435. package/src/internal/Entity/model.ts +119 -0
  436. package/src/internal/Entity/object.ts +73 -0
  437. package/src/internal/Entity/relation.ts +188 -0
  438. package/src/internal/Entity/type-kind.ts +75 -0
  439. package/src/internal/Entity/type-uri.ts +92 -0
  440. package/src/internal/Entity/util.ts +33 -0
  441. package/src/internal/Entity/version.ts +96 -0
  442. package/src/internal/Format/date.test.ts +55 -0
  443. package/src/internal/Format/date.ts +213 -0
  444. package/src/internal/Format/format.test.ts +97 -0
  445. package/src/internal/Format/format.ts +54 -0
  446. package/src/internal/Format/index.ts +11 -0
  447. package/src/internal/Format/number.ts +89 -0
  448. package/src/internal/Format/object.ts +97 -0
  449. package/src/internal/Format/select.ts +18 -0
  450. package/src/internal/Format/string.ts +81 -0
  451. package/src/internal/Format/types.ts +186 -0
  452. package/src/internal/JsonSchema/annotations.ts +50 -0
  453. package/src/internal/JsonSchema/effect-schema.test.ts +143 -0
  454. package/src/internal/JsonSchema/index.ts +8 -0
  455. package/src/internal/JsonSchema/json-schema-normalize.ts +111 -0
  456. package/src/internal/JsonSchema/json-schema-type.ts +403 -0
  457. package/src/internal/JsonSchema/json-schema.test.ts +786 -0
  458. package/src/internal/JsonSchema/json-schema.ts +547 -0
  459. package/src/internal/Obj/atoms.ts +244 -0
  460. package/src/internal/Obj/clone.ts +53 -0
  461. package/src/internal/Obj/common.ts +75 -0
  462. package/src/internal/Obj/create-object.test.ts +116 -0
  463. package/src/internal/Obj/create-object.ts +140 -0
  464. package/src/internal/Obj/deleted.ts +19 -0
  465. package/src/internal/Obj/index.ts +14 -0
  466. package/src/internal/Obj/inspect.ts +48 -0
  467. package/src/internal/Obj/json-serializer.test.ts +199 -0
  468. package/src/internal/Obj/json-serializer.ts +278 -0
  469. package/src/internal/Obj/schema-validator.test.ts +182 -0
  470. package/src/internal/Obj/schema-validator.ts +6 -0
  471. package/src/internal/Obj/set-value.test.ts +258 -0
  472. package/src/internal/Obj/set-value.ts +158 -0
  473. package/src/internal/Obj/snapshot.ts +114 -0
  474. package/src/internal/Obj/typed-object.test.ts +32 -0
  475. package/src/internal/Obj/typed-object.ts +30 -0
  476. package/src/{query → internal/Query}/index.ts +1 -1
  477. package/src/internal/Query/pretty.ts +162 -0
  478. package/src/internal/Ref/atoms.ts +20 -0
  479. package/src/internal/Ref/index.ts +6 -0
  480. package/src/internal/Ref/ref-array.ts +38 -0
  481. package/src/internal/Ref/ref.test.ts +91 -0
  482. package/src/internal/Ref/ref.ts +650 -0
  483. package/src/internal/Ref/utils.ts +45 -0
  484. package/src/internal/Type/compose.test.ts +43 -0
  485. package/src/internal/Type/compose.ts +41 -0
  486. package/src/internal/Type/index.ts +6 -0
  487. package/src/internal/Type/manipulation.ts +67 -0
  488. package/src/internal/Type/type-schema.ts +60 -0
  489. package/src/internal/common/README.md +102 -0
  490. package/src/internal/common/api/index.ts +15 -0
  491. package/src/internal/common/api/meta.ts +90 -0
  492. package/src/internal/common/index.ts +7 -0
  493. package/src/internal/common/proxy/change-context.ts +138 -0
  494. package/src/internal/common/proxy/change.test.ts +527 -0
  495. package/src/internal/common/proxy/define-hidden-property.ts +14 -0
  496. package/src/internal/common/proxy/errors.ts +42 -0
  497. package/src/internal/common/proxy/event-batch.ts +44 -0
  498. package/src/internal/common/proxy/handler.test.ts +121 -0
  499. package/src/internal/common/proxy/index.ts +17 -0
  500. package/src/internal/common/proxy/json-serializer.ts +101 -0
  501. package/src/internal/common/proxy/make-object.ts +129 -0
  502. package/src/internal/common/proxy/ownership.ts +252 -0
  503. package/src/internal/common/proxy/proxy-types.ts +23 -0
  504. package/src/internal/common/proxy/proxy-utils.ts +150 -0
  505. package/src/internal/common/proxy/reactive-array.ts +71 -0
  506. package/src/internal/common/proxy/reactive.test.ts +54 -0
  507. package/src/internal/common/proxy/reactive.ts +77 -0
  508. package/src/internal/common/proxy/schema-validator.ts +244 -0
  509. package/src/internal/common/proxy/schema.test.ts +107 -0
  510. package/src/internal/common/proxy/symbols.ts +7 -0
  511. package/src/internal/common/proxy/typed-handler.test.ts +314 -0
  512. package/src/internal/common/proxy/typed-handler.ts +509 -0
  513. package/src/internal/common/proxy/typed-object.test.ts +103 -0
  514. package/src/internal/common/types/base.ts +43 -0
  515. package/src/internal/common/types/entity.ts +133 -0
  516. package/src/internal/common/types/index.ts +15 -0
  517. package/src/internal/common/types/meta.ts +109 -0
  518. package/src/internal/common/types/model-symbols.ts +89 -0
  519. package/src/internal/common/types/typename.ts +91 -0
  520. package/src/internal/common/types/version.ts +19 -0
  521. package/src/internal/common/types/well-known-types.ts +15 -0
  522. package/src/internal/index.ts +19 -0
  523. package/src/testing/api.test.ts +131 -0
  524. package/src/testing/index.ts +4 -1
  525. package/src/testing/registry.ts +44 -0
  526. package/src/testing/test-data.ts +189 -0
  527. package/src/testing/test-schema.ts +204 -0
  528. package/src/testing/util.ts +88 -0
  529. package/dist/lib/browser/chunk-NLPBTYZV.mjs +0 -647
  530. package/dist/lib/browser/chunk-NLPBTYZV.mjs.map +0 -7
  531. package/dist/lib/browser/index.mjs +0 -22
  532. package/dist/lib/browser/meta.json +0 -1
  533. package/dist/lib/browser/testing/index.mjs +0 -70
  534. package/dist/lib/browser/testing/index.mjs.map +0 -7
  535. package/dist/lib/node-esm/chunk-BQZZRMFX.mjs +0 -647
  536. package/dist/lib/node-esm/chunk-BQZZRMFX.mjs.map +0 -7
  537. package/dist/lib/node-esm/index.mjs +0 -22
  538. package/dist/lib/node-esm/meta.json +0 -1
  539. package/dist/lib/node-esm/testing/index.mjs +0 -70
  540. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  541. package/dist/types/src/experimental/database.d.ts +0 -8
  542. package/dist/types/src/experimental/database.d.ts.map +0 -1
  543. package/dist/types/src/experimental/index.d.ts +0 -1
  544. package/dist/types/src/experimental/index.d.ts.map +0 -1
  545. package/dist/types/src/experimental/queue.d.ts +0 -8
  546. package/dist/types/src/experimental/queue.d.ts.map +0 -1
  547. package/dist/types/src/experimental/space.d.ts +0 -8
  548. package/dist/types/src/experimental/space.d.ts.map +0 -1
  549. package/dist/types/src/query/dsl.d.ts +0 -218
  550. package/dist/types/src/query/dsl.d.ts.map +0 -1
  551. package/dist/types/src/query/dsl.test.d.ts +0 -2
  552. package/dist/types/src/query/dsl.test.d.ts.map +0 -1
  553. package/dist/types/src/query/index.d.ts +0 -2
  554. package/dist/types/src/query/index.d.ts.map +0 -1
  555. package/dist/types/src/testing/types.d.ts +0 -113
  556. package/dist/types/src/testing/types.d.ts.map +0 -1
  557. package/src/experimental/database.ts +0 -11
  558. package/src/experimental/index.ts +0 -7
  559. package/src/experimental/queue.ts +0 -11
  560. package/src/experimental/space.ts +0 -11
  561. package/src/query/dsl.test.ts +0 -324
  562. package/src/query/dsl.ts +0 -646
  563. package/src/test/api.test.ts +0 -173
  564. package/src/testing/types.ts +0 -91
  565. /package/dist/lib/{browser/index.mjs.map → neutral/Annotation.mjs.map} +0 -0
  566. /package/dist/lib/{node-esm/index.mjs.map → neutral/Database.mjs.map} +0 -0
  567. /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
package/src/Obj.ts CHANGED
@@ -2,196 +2,927 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ // @import-as-namespace
6
6
 
7
- import * as EchoSchema from '@dxos/echo-schema';
7
+ import * as Effect from 'effect/Effect';
8
+ import * as Equal from 'effect/Equal';
9
+ import * as Function from 'effect/Function';
10
+ import * as Option from 'effect/Option';
11
+ import * as Schema from 'effect/Schema';
12
+ import * as Utils from 'effect/Utils';
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 type * as LiveObject from '@dxos/live-object';
11
- import { live } from '@dxos/live-object';
12
- import { assumeType } from '@dxos/util';
17
+ import { EntityId, type URI } from '@dxos/keys';
18
+ import { assumeType, deepMapValues } from '@dxos/util';
13
19
 
14
- import type * as Ref from './Ref';
15
- import type * as Relation from './Relation';
16
- import type * as Type from './Type';
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';
28
+ import * as Type from './Type';
17
29
 
18
30
  /**
19
- * NOTE: Don't export: Obj.Any and Obj.Obj form the public API.
31
+ * Base type for all ECHO objects.
20
32
  */
21
- interface BaseObj extends EchoSchema.HasId, Type.OfKind<EchoSchema.EntityKind.Object> {}
33
+ interface BaseObj extends internal.AnyEntity, Entity.OfKind<typeof Entity.Kind.Object> {}
22
34
 
23
35
  /**
24
36
  * Object type with specific properties.
25
37
  */
26
- export type Obj<Props> = BaseObj & Props;
38
+ export type OfShape<Props> = BaseObj & Props;
27
39
 
28
40
  /**
29
- * Base type for all ECHO objects.
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)`.
47
+ */
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>;
86
+
87
+ /**
88
+ * Object with arbitrary properties.
89
+ *
90
+ * NOTE: Due to how TypeScript works, this type is not assignable to a specific schema type.
91
+ * In that case, use `Obj.instanceOf` to check if an object is of a specific type.
92
+ *
93
+ * Prefer using `Obj.Unknown` when you don't need to access arbitrary properties.
94
+ */
95
+ export interface Any extends BaseObj, internal.AnyProperties {}
96
+
97
+ /**
98
+ * Base type for snapshot objects (has SnapshotKindId instead of KindId).
99
+ */
100
+ interface BaseSnapshot extends internal.AnyEntity {
101
+ readonly [Entity.SnapshotKindId]: typeof Entity.Kind.Object;
102
+ readonly id: EntityId;
103
+ }
104
+
105
+ /**
106
+ * Immutable snapshot of an ECHO object.
107
+ * Branded with SnapshotKindId (not KindId).
108
+ * Property values are frozen at the time the snapshot was created.
109
+ * Returned by getSnapshot() and hooks like useObject().
110
+ *
111
+ * Snapshots are structurally identical to reactive objects but have a different brand,
112
+ * making them distinguishable at the TypeScript level. Neither is assignable to the other.
113
+ */
114
+ export type Snapshot<T extends Unknown = Unknown> = Omit<T, Entity.KindId> & BaseSnapshot;
115
+
116
+ /**
117
+ * JSON-encoded properties for objects.
30
118
  */
31
- export interface Any extends BaseObj {}
119
+ export interface BaseObjJson {
120
+ id: string;
121
+ }
32
122
 
33
- type Props<T = any> = { id?: EchoSchema.ObjectId } & Type.Properties<T>;
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 => ({
126
+ keys: [],
127
+ tags: [],
128
+ annotations: {},
129
+ });
34
130
 
35
- export type MakeProps<T extends Type.Obj.Any> = NoInfer<Props<Schema.Schema.Type<T>>>;
131
+ // TODO(burdon): Should we allow the caller to set the id?
132
+ /**
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>>);
36
154
 
37
155
  /**
38
- * Creates new object.
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)`).
160
+ * @param props - Object properties.
161
+ *
162
+ * Meta can be passed as a symbol in `props`.
163
+ *
164
+ * Example:
165
+ * ```ts
166
+ * const obj = Obj.make(Person, { [Obj.Meta]: { keys: [...] }, name: 'John' });
167
+ * ```
168
+ *
169
+ * Note: Only accepts object schemas / object-kind types, not relation schemas.
170
+ * Use `Relation.make` for relations.
39
171
  */
40
- // TODO(dmaretskyi): Move meta into props.
41
- export const make = <S extends Type.Obj.Any>(
42
- schema: S,
43
- props: MakeProps<S>,
44
- meta?: EchoSchema.ObjectMeta,
45
- ): 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);
46
178
  assertArgument(
47
- EchoSchema.getTypeAnnotation(schema)?.kind === EchoSchema.EntityKind.Object,
179
+ internal.getTypeAnnotation(schema)?.kind === Entity.Kind.Object,
180
+ 'schema',
48
181
  'Expected an object schema',
49
182
  );
50
183
 
51
- if (props[EchoSchema.MetaId] != null) {
52
- meta = props[EchoSchema.MetaId] as any;
53
- 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];
54
190
  }
55
191
 
56
- return live<Schema.Schema.Type<S>>(schema, props as any, meta);
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
+ }
201
+ }
202
+
203
+ return internal.makeObject(
204
+ schema,
205
+ filterUndefined,
206
+ {
207
+ ...defaultMeta(),
208
+ ...meta,
209
+ },
210
+ input,
211
+ );
212
+ }
213
+
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;
220
+ };
221
+
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;
57
225
  };
58
226
 
59
- export const isObject = (obj: unknown): obj is Any => {
60
- assumeType<EchoSchema.InternalObjectProps>(obj);
61
- return typeof obj === 'object' && obj !== null && obj[EchoSchema.EntityKindId] === EchoSchema.EntityKind.Object;
227
+ /**
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);
62
235
  };
63
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
+
64
248
  /**
65
- * Test if object or relation is an instance of a schema.
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`.
66
257
  * @example
67
258
  * ```ts
68
- * const john = Obj.make(Person, { name: 'John' });
69
- * 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).
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.
70
431
  *
432
+ * @example
433
+ * ```ts
434
+ * const john = Obj.make(Person, { name: 'John' });
71
435
  * const isPerson = Obj.instanceOf(Person);
72
- * if(isPerson(john)) {
436
+ * if (isPerson(john)) {
73
437
  * // john is Person
74
438
  * }
75
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.
76
443
  */
77
444
  export const instanceOf: {
78
- <S extends Type.Relation.Any | Type.Obj.Any>(schema: S): (value: unknown) => value is Schema.Schema.Type<S>;
79
- <S extends Type.Relation.Any | Type.Obj.Any>(schema: S, value: unknown): value is Schema.Schema.Type<S>;
80
- } = ((
81
- ...args: [schema: Type.Relation.Any | Type.Obj.Any, value: unknown] | [schema: Type.Relation.Any | Type.Obj.Any]
82
- ) => {
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]) => {
463
+ if (args.length === 1) {
464
+ return (entity: unknown) => internal.isInstanceOf(args[0], entity);
465
+ }
466
+
467
+ return internal.isInstanceOf(args[0], args[1]);
468
+ }) as any;
469
+
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
+
83
493
  if (args.length === 1) {
84
- return (obj: unknown) => EchoSchema.isInstanceOf(args[0], obj);
494
+ return (entity: unknown) => check(entity);
85
495
  }
86
496
 
87
- return EchoSchema.isInstanceOf(args[0], args[1]);
497
+ return check(args[1]);
88
498
  }) as any;
89
499
 
90
- export const getSchema = EchoSchema.getSchema;
500
+ export type { GetURIOptions } from './internal';
91
501
 
92
502
  // TODO(dmaretskyi): Allow returning undefined.
93
- export const getDXN = (obj: Any | Relation.Any): DXN => {
94
- assertArgument(!Schema.isSchema(obj), 'Object should not be a schema.');
95
- const dxn = EchoSchema.getObjectDXN(obj);
96
- invariant(dxn != null, 'Invalid object.');
97
- 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);
98
512
  };
99
513
 
100
514
  /**
101
515
  * @returns The DXN of the object's type.
102
- * @example dxn:example.com/type/Contact:1.0.0
516
+ * @example dxn:com.example.type.person:1.0.0
517
+ * @throws If the object is missing its type (corrupted object).
103
518
  */
104
- // TODO(burdon): Expando does not have a type.
105
- export const getTypeDXN = EchoSchema.getType;
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(...)`.
532
+ */
533
+ export const getType = (obj: Unknown | Snapshot): Type.AnyObj | undefined =>
534
+ internal.getType(obj) as Type.AnyObj | undefined;
106
535
 
107
536
  /**
108
537
  * @returns The typename of the object's type.
109
- * @example `example.com/type/Contact`
538
+ * Accepts both reactive objects and snapshots.
539
+ * @example `com.example.type.person`
110
540
  */
111
- export const getTypename = (obj: Any | Relation.Any): string | undefined => {
112
- const schema = getSchema(obj);
113
- if (schema == null) {
114
- // Try to extract typename from DXN.
115
- return EchoSchema.getType(obj)?.asTypeDXN()?.type;
116
- }
541
+ export const getTypename = (entity: Unknown | Snapshot): string | undefined => internal.getTypename(entity);
117
542
 
118
- return EchoSchema.getSchemaTypename(schema);
119
- };
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);
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;
120
580
 
581
+ // TODO(burdon): Narrow type.
121
582
  // TODO(dmaretskyi): Allow returning undefined.
122
- export const getMeta = (obj: Any | Relation.Any): EchoSchema.ObjectMeta => {
123
- const meta = EchoSchema.getMeta(obj);
124
- invariant(meta != null, 'Invalid object.');
125
- return meta;
126
- };
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
+ }
606
+
607
+ /**
608
+ * @returns Foreign keys for the object from the specified source.
609
+ * Accepts both reactive objects and snapshots.
610
+ */
611
+ export const getKeys: {
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!));
615
+
616
+ /**
617
+ * Delete all keys from the object for the specified source.
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);
127
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
+ */
128
647
  // TODO(dmaretskyi): Default to `false`.
129
- export const isDeleted = (obj: Any | Relation.Any): boolean => {
130
- const deleted = EchoSchema.isDeleted(obj);
131
- invariant(typeof deleted === 'boolean', 'Invalid object.');
132
- return deleted;
648
+ export const isDeleted = (entity: Unknown | Snapshot): boolean => objInternal.isDeleted(entity);
649
+
650
+ //
651
+ // Annotations
652
+ //
653
+
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);
663
+
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);
672
+
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;
133
722
  };
134
723
 
135
- // TODO(burdon): Rename "label"
136
- export const getLabel = (obj: Any | Relation.Any): string | undefined => {
137
- const schema = getSchema(obj);
138
- if (schema != null) {
139
- return EchoSchema.getLabel(schema, obj);
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;
736
+ };
737
+
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;
140
749
  }
750
+ if (typeof left !== 'object' || typeof right !== 'object') {
751
+ return Utils.structuralRegion(() => Equal.equals(left, right));
752
+ }
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
+ }
767
+ }
768
+ return true;
769
+ }
770
+ if (Array.isArray(left) || Array.isArray(right)) {
771
+ return false;
772
+ }
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
+ }
787
+ }
788
+ return true;
141
789
  };
142
790
 
143
- export const setLabel = (obj: Any | Relation.Any, label: string) => {
144
- const schema = getSchema(obj);
145
- if (schema != null) {
146
- EchoSchema.setLabel(schema, obj, label);
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) });
807
+ }
808
+ return recurse(nested);
809
+ });
810
+
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));
147
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;
148
852
  };
149
853
 
854
+ //
855
+ // JSON
856
+ //
857
+
150
858
  /**
151
859
  * JSON representation of an object.
152
860
  */
153
- export type JSON = EchoSchema.ObjectJSON;
861
+ export type JSON = internal.ObjectJSON;
154
862
 
155
863
  /**
156
864
  * Converts object to its JSON representation.
865
+ * Accepts both reactive objects and snapshots.
157
866
  *
158
867
  * The same algorithm is used when calling the standard `JSON.stringify(obj)` function.
159
868
  */
160
- // TODO(burdon): Base util type for Obj/Relation?
161
- export const toJSON = (obj: Any | Relation.Any): JSON => EchoSchema.objectToJSON(obj);
869
+ export const toJSON = (entity: Unknown | Snapshot): JSON => objInternal.objectToJSON(entity);
162
870
 
163
871
  /**
164
872
  * Creates an object from its json representation, performing schema validation.
165
873
  * References and schemas will be resolvable if the `refResolver` is provided.
166
874
  *
167
- * 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.
168
876
  *
169
877
  * @param options.refResolver - Resolver for references. Produces hydrated references that can be resolved.
170
- * @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.
171
880
  */
172
- export const fromJSON: (json: unknown, options?: { refResolver?: Ref.Resolver; dxn?: DXN }) => Promise<Any> =
173
- 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;
174
885
 
175
- export type CloneOptions = {
176
- /**
177
- * Retain the original object's ID.
178
- * @default false
179
- */
180
- retainId?: boolean;
181
- };
886
+ /**
887
+ * Comparator function type for sorting objects.
888
+ * Accepts both reactive objects and snapshots.
889
+ */
890
+ export type Comparator = internal.Comparator<Unknown | Snapshot>;
891
+
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;
895
+
896
+ //
897
+ // Version
898
+ //
899
+
900
+ export const VersionTypeId = internal.VersionTypeId;
901
+ export type VersionCompareResult = internal.VersionCompareResult;
182
902
 
183
903
  /**
184
- * Clones an object or relation.
185
- * This does not clone referenced objects, only the properties in the object.
186
- * @returns A new object with the same schema and properties.
904
+ * Represent object version.
905
+ * May be backed by Automerge.
906
+ * Objects with no history are not versioned.
187
907
  */
188
- export const clone = <T extends Any | Relation.Any>(obj: T, opts?: CloneOptions): T => {
189
- const { id, ...data } = obj;
190
- const schema = getSchema(obj);
191
- invariant(schema != null, 'Object should have a schema');
192
- const props: any = { ...data };
193
- if (opts?.retainId) {
194
- props.id = id;
195
- }
196
- return make(schema, props);
197
- };
908
+ export type Version = internal.EntityVersion;
909
+
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;
915
+
916
+ /**
917
+ * Returns the version of the object.
918
+ * Accepts both reactive objects and snapshots.
919
+ */
920
+ export const version = (entity: Unknown | Snapshot): Version => internal.version(entity);
921
+
922
+ //
923
+ // Atoms
924
+ //
925
+
926
+ export const atom = objInternal.makeAtom;
927
+ export const atomReactive = objInternal.makeWithReactive;
928
+ export const atomProperty = objInternal.makeProperty;