@dxos/echo 0.8.4-main.c1de068 → 0.8.4-main.c85a9c8dae

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