@dxos/echo 0.8.4-main.84f28bd → 0.8.4-main.937b3ca

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 (553) hide show
  1. package/README.md +2 -3
  2. package/dist/lib/browser/Annotation.mjs +33 -0
  3. package/dist/lib/browser/Annotation.mjs.map +7 -0
  4. package/dist/lib/browser/Database.mjs +18 -0
  5. package/dist/lib/browser/Database.mjs.map +7 -0
  6. package/dist/lib/browser/Entity.mjs +52 -0
  7. package/dist/lib/browser/Entity.mjs.map +7 -0
  8. package/dist/lib/browser/Err.mjs +11 -0
  9. package/dist/lib/browser/Err.mjs.map +7 -0
  10. package/dist/lib/browser/Filter.mjs +62 -0
  11. package/dist/lib/browser/Filter.mjs.map +7 -0
  12. package/dist/lib/browser/Format.mjs +67 -0
  13. package/dist/lib/browser/Format.mjs.map +7 -0
  14. package/dist/lib/browser/JsonSchema.mjs +20 -0
  15. package/dist/lib/browser/JsonSchema.mjs.map +7 -0
  16. package/dist/lib/browser/Key.mjs +13 -0
  17. package/dist/lib/browser/Key.mjs.map +7 -0
  18. package/dist/lib/browser/Obj.mjs +91 -0
  19. package/dist/lib/browser/Obj.mjs.map +7 -0
  20. package/dist/lib/browser/Order.mjs +13 -0
  21. package/dist/lib/browser/Order.mjs.map +7 -0
  22. package/dist/lib/browser/Query.mjs +27 -0
  23. package/dist/lib/browser/Query.mjs.map +7 -0
  24. package/dist/lib/browser/QueryResult.mjs +3 -0
  25. package/dist/lib/browser/QueryResult.mjs.map +7 -0
  26. package/dist/lib/browser/Ref.mjs +23 -0
  27. package/dist/lib/browser/Ref.mjs.map +7 -0
  28. package/dist/lib/browser/Relation.mjs +85 -0
  29. package/dist/lib/browser/Relation.mjs.map +7 -0
  30. package/dist/lib/browser/SchemaRegistry.mjs +3 -0
  31. package/dist/lib/browser/SchemaRegistry.mjs.map +7 -0
  32. package/dist/lib/browser/Tag.mjs +26 -0
  33. package/dist/lib/browser/Tag.mjs.map +7 -0
  34. package/dist/lib/browser/Type.mjs +48 -0
  35. package/dist/lib/browser/Type.mjs.map +7 -0
  36. package/dist/lib/browser/chunk-22JMFST2.mjs +24 -0
  37. package/dist/lib/browser/chunk-22JMFST2.mjs.map +7 -0
  38. package/dist/lib/browser/chunk-2SBB7OWV.mjs +250 -0
  39. package/dist/lib/browser/chunk-2SBB7OWV.mjs.map +7 -0
  40. package/dist/lib/browser/chunk-6L5HHUVU.mjs +158 -0
  41. package/dist/lib/browser/chunk-6L5HHUVU.mjs.map +7 -0
  42. package/dist/lib/browser/chunk-7STIBCP7.mjs +133 -0
  43. package/dist/lib/browser/chunk-7STIBCP7.mjs.map +7 -0
  44. package/dist/lib/browser/chunk-BJPE6CIC.mjs +3847 -0
  45. package/dist/lib/browser/chunk-BJPE6CIC.mjs.map +7 -0
  46. package/dist/lib/browser/chunk-CGS2ULMK.mjs +11 -0
  47. package/dist/lib/browser/chunk-CGS2ULMK.mjs.map +7 -0
  48. package/dist/lib/browser/chunk-CJ5YELTO.mjs +39 -0
  49. package/dist/lib/browser/chunk-CJ5YELTO.mjs.map +7 -0
  50. package/dist/lib/browser/chunk-FPOISFQK.mjs +40 -0
  51. package/dist/lib/browser/chunk-FPOISFQK.mjs.map +7 -0
  52. package/dist/lib/browser/chunk-FRDT7RA4.mjs +403 -0
  53. package/dist/lib/browser/chunk-FRDT7RA4.mjs.map +7 -0
  54. package/dist/lib/browser/chunk-INHXFXY5.mjs +22 -0
  55. package/dist/lib/browser/chunk-INHXFXY5.mjs.map +7 -0
  56. package/dist/lib/browser/chunk-IXVWLTG7.mjs +9 -0
  57. package/dist/lib/browser/chunk-IXVWLTG7.mjs.map +7 -0
  58. package/dist/lib/browser/chunk-JMKVF2YQ.mjs +43 -0
  59. package/dist/lib/browser/chunk-JMKVF2YQ.mjs.map +7 -0
  60. package/dist/lib/browser/chunk-KQQGVHFN.mjs +143 -0
  61. package/dist/lib/browser/chunk-KQQGVHFN.mjs.map +7 -0
  62. package/dist/lib/browser/chunk-MYCCGG2T.mjs +15 -0
  63. package/dist/lib/browser/chunk-MYCCGG2T.mjs.map +7 -0
  64. package/dist/lib/browser/chunk-NOPVNWPT.mjs +204 -0
  65. package/dist/lib/browser/chunk-NOPVNWPT.mjs.map +7 -0
  66. package/dist/lib/browser/chunk-PQZW3S6L.mjs +74 -0
  67. package/dist/lib/browser/chunk-PQZW3S6L.mjs.map +7 -0
  68. package/dist/lib/browser/chunk-RK4Z4JUZ.mjs +283 -0
  69. package/dist/lib/browser/chunk-RK4Z4JUZ.mjs.map +7 -0
  70. package/dist/lib/browser/chunk-U2J7TA7K.mjs +57 -0
  71. package/dist/lib/browser/chunk-U2J7TA7K.mjs.map +7 -0
  72. package/dist/lib/browser/chunk-W5D2GWAW.mjs +98 -0
  73. package/dist/lib/browser/chunk-W5D2GWAW.mjs.map +7 -0
  74. package/dist/lib/browser/chunk-XDIUHAAX.mjs +41 -0
  75. package/dist/lib/browser/chunk-XDIUHAAX.mjs.map +7 -0
  76. package/dist/lib/browser/chunk-YKTSSMDS.mjs +69 -0
  77. package/dist/lib/browser/chunk-YKTSSMDS.mjs.map +7 -0
  78. package/dist/lib/browser/chunk-ZAGAOZVY.mjs +288 -0
  79. package/dist/lib/browser/chunk-ZAGAOZVY.mjs.map +7 -0
  80. package/dist/lib/browser/chunk-ZHXZGIXD.mjs +9 -0
  81. package/dist/lib/browser/chunk-ZHXZGIXD.mjs.map +7 -0
  82. package/dist/lib/browser/index.mjs +72 -9
  83. package/dist/lib/browser/internal/index.mjs +457 -0
  84. package/dist/lib/browser/internal/index.mjs.map +7 -0
  85. package/dist/lib/browser/meta.json +1 -1
  86. package/dist/lib/browser/testing/index.mjs +332 -35
  87. package/dist/lib/browser/testing/index.mjs.map +4 -4
  88. package/dist/lib/node-esm/Annotation.mjs +33 -0
  89. package/dist/lib/node-esm/Annotation.mjs.map +7 -0
  90. package/dist/lib/node-esm/Database.mjs +18 -0
  91. package/dist/lib/node-esm/Database.mjs.map +7 -0
  92. package/dist/lib/node-esm/Entity.mjs +52 -0
  93. package/dist/lib/node-esm/Entity.mjs.map +7 -0
  94. package/dist/lib/node-esm/Err.mjs +11 -0
  95. package/dist/lib/node-esm/Err.mjs.map +7 -0
  96. package/dist/lib/node-esm/Filter.mjs +62 -0
  97. package/dist/lib/node-esm/Filter.mjs.map +7 -0
  98. package/dist/lib/node-esm/Format.mjs +67 -0
  99. package/dist/lib/node-esm/Format.mjs.map +7 -0
  100. package/dist/lib/node-esm/JsonSchema.mjs +20 -0
  101. package/dist/lib/node-esm/JsonSchema.mjs.map +7 -0
  102. package/dist/lib/node-esm/Key.mjs +13 -0
  103. package/dist/lib/node-esm/Key.mjs.map +7 -0
  104. package/dist/lib/node-esm/Obj.mjs +91 -0
  105. package/dist/lib/node-esm/Obj.mjs.map +7 -0
  106. package/dist/lib/node-esm/Order.mjs +13 -0
  107. package/dist/lib/node-esm/Order.mjs.map +7 -0
  108. package/dist/lib/node-esm/Query.mjs +27 -0
  109. package/dist/lib/node-esm/Query.mjs.map +7 -0
  110. package/dist/lib/node-esm/QueryResult.mjs +3 -0
  111. package/dist/lib/node-esm/QueryResult.mjs.map +7 -0
  112. package/dist/lib/node-esm/Ref.mjs +23 -0
  113. package/dist/lib/node-esm/Ref.mjs.map +7 -0
  114. package/dist/lib/node-esm/Relation.mjs +85 -0
  115. package/dist/lib/node-esm/Relation.mjs.map +7 -0
  116. package/dist/lib/node-esm/SchemaRegistry.mjs +3 -0
  117. package/dist/lib/node-esm/SchemaRegistry.mjs.map +7 -0
  118. package/dist/lib/node-esm/Tag.mjs +26 -0
  119. package/dist/lib/node-esm/Tag.mjs.map +7 -0
  120. package/dist/lib/node-esm/Type.mjs +48 -0
  121. package/dist/lib/node-esm/Type.mjs.map +7 -0
  122. package/dist/lib/node-esm/chunk-4PNXQA64.mjs +250 -0
  123. package/dist/lib/node-esm/chunk-4PNXQA64.mjs.map +7 -0
  124. package/dist/lib/node-esm/chunk-5OBN7GZW.mjs +158 -0
  125. package/dist/lib/node-esm/chunk-5OBN7GZW.mjs.map +7 -0
  126. package/dist/lib/node-esm/chunk-AJEMYSIR.mjs +22 -0
  127. package/dist/lib/node-esm/chunk-AJEMYSIR.mjs.map +7 -0
  128. package/dist/lib/node-esm/chunk-ANLVLWME.mjs +98 -0
  129. package/dist/lib/node-esm/chunk-ANLVLWME.mjs.map +7 -0
  130. package/dist/lib/node-esm/chunk-DMR7OAFK.mjs +57 -0
  131. package/dist/lib/node-esm/chunk-DMR7OAFK.mjs.map +7 -0
  132. package/dist/lib/node-esm/chunk-FWTSPIFF.mjs +133 -0
  133. package/dist/lib/node-esm/chunk-FWTSPIFF.mjs.map +7 -0
  134. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  135. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  136. package/dist/lib/node-esm/chunk-ILMLLM4R.mjs +204 -0
  137. package/dist/lib/node-esm/chunk-ILMLLM4R.mjs.map +7 -0
  138. package/dist/lib/node-esm/chunk-K37NA7PO.mjs +43 -0
  139. package/dist/lib/node-esm/chunk-K37NA7PO.mjs.map +7 -0
  140. package/dist/lib/node-esm/chunk-LT3H4JOX.mjs +3847 -0
  141. package/dist/lib/node-esm/chunk-LT3H4JOX.mjs.map +7 -0
  142. package/dist/lib/node-esm/chunk-MOLNWFNL.mjs +9 -0
  143. package/dist/lib/node-esm/chunk-MOLNWFNL.mjs.map +7 -0
  144. package/dist/lib/node-esm/chunk-MOWUEW5P.mjs +15 -0
  145. package/dist/lib/node-esm/chunk-MOWUEW5P.mjs.map +7 -0
  146. package/dist/lib/node-esm/chunk-NBWL7UCZ.mjs +40 -0
  147. package/dist/lib/node-esm/chunk-NBWL7UCZ.mjs.map +7 -0
  148. package/dist/lib/node-esm/chunk-NRN3ZW2T.mjs +143 -0
  149. package/dist/lib/node-esm/chunk-NRN3ZW2T.mjs.map +7 -0
  150. package/dist/lib/node-esm/chunk-QLI2EIJ2.mjs +41 -0
  151. package/dist/lib/node-esm/chunk-QLI2EIJ2.mjs.map +7 -0
  152. package/dist/lib/node-esm/chunk-QYR67VBV.mjs +288 -0
  153. package/dist/lib/node-esm/chunk-QYR67VBV.mjs.map +7 -0
  154. package/dist/lib/node-esm/chunk-UKGVOINP.mjs +9 -0
  155. package/dist/lib/node-esm/chunk-UKGVOINP.mjs.map +7 -0
  156. package/dist/lib/node-esm/chunk-W6QIEBTQ.mjs +403 -0
  157. package/dist/lib/node-esm/chunk-W6QIEBTQ.mjs.map +7 -0
  158. package/dist/lib/node-esm/chunk-XHJRMQZD.mjs +69 -0
  159. package/dist/lib/node-esm/chunk-XHJRMQZD.mjs.map +7 -0
  160. package/dist/lib/node-esm/chunk-Y75VU7LB.mjs +74 -0
  161. package/dist/lib/node-esm/chunk-Y75VU7LB.mjs.map +7 -0
  162. package/dist/lib/node-esm/chunk-YOLH5KS4.mjs +283 -0
  163. package/dist/lib/node-esm/chunk-YOLH5KS4.mjs.map +7 -0
  164. package/dist/lib/node-esm/chunk-YQ2NWGL5.mjs +39 -0
  165. package/dist/lib/node-esm/chunk-YQ2NWGL5.mjs.map +7 -0
  166. package/dist/lib/node-esm/chunk-ZBB67AKD.mjs +24 -0
  167. package/dist/lib/node-esm/chunk-ZBB67AKD.mjs.map +7 -0
  168. package/dist/lib/node-esm/index.mjs +72 -9
  169. package/dist/lib/node-esm/internal/index.mjs +457 -0
  170. package/dist/lib/node-esm/internal/index.mjs.map +7 -0
  171. package/dist/lib/node-esm/meta.json +1 -1
  172. package/dist/lib/node-esm/testing/index.mjs +332 -35
  173. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  174. package/dist/types/src/Annotation.d.ts +2 -0
  175. package/dist/types/src/Annotation.d.ts.map +1 -0
  176. package/dist/types/src/Database.d.ts +194 -0
  177. package/dist/types/src/Database.d.ts.map +1 -0
  178. package/dist/types/src/Entity.d.ts +142 -0
  179. package/dist/types/src/Entity.d.ts.map +1 -0
  180. package/dist/types/src/Entity.test.d.ts +2 -0
  181. package/dist/types/src/Entity.test.d.ts.map +1 -0
  182. package/dist/types/src/Err.d.ts +64 -0
  183. package/dist/types/src/Err.d.ts.map +1 -0
  184. package/dist/types/src/Filter.d.ts +120 -0
  185. package/dist/types/src/Filter.d.ts.map +1 -0
  186. package/dist/types/src/Format.d.ts +4 -0
  187. package/dist/types/src/Format.d.ts.map +1 -0
  188. package/dist/types/src/Hypergraph.d.ts +60 -0
  189. package/dist/types/src/Hypergraph.d.ts.map +1 -0
  190. package/dist/types/src/JsonSchema.d.ts +9 -0
  191. package/dist/types/src/JsonSchema.d.ts.map +1 -0
  192. package/dist/types/src/Key.d.ts +1 -0
  193. package/dist/types/src/Key.d.ts.map +1 -1
  194. package/dist/types/src/Obj.d.ts +344 -34
  195. package/dist/types/src/Obj.d.ts.map +1 -1
  196. package/dist/types/src/Obj.test.d.ts +2 -0
  197. package/dist/types/src/Obj.test.d.ts.map +1 -0
  198. package/dist/types/src/Order.d.ts +16 -0
  199. package/dist/types/src/Order.d.ts.map +1 -0
  200. package/dist/types/src/Query.d.ts +115 -0
  201. package/dist/types/src/Query.d.ts.map +1 -0
  202. package/dist/types/src/Query.test.d.ts +2 -0
  203. package/dist/types/src/Query.test.d.ts.map +1 -0
  204. package/dist/types/src/QueryResult.d.ts +80 -0
  205. package/dist/types/src/QueryResult.d.ts.map +1 -0
  206. package/dist/types/src/Ref.d.ts +13 -11
  207. package/dist/types/src/Ref.d.ts.map +1 -1
  208. package/dist/types/src/Relation.d.ts +242 -19
  209. package/dist/types/src/Relation.d.ts.map +1 -1
  210. package/dist/types/src/Relation.test.d.ts +2 -0
  211. package/dist/types/src/Relation.test.d.ts.map +1 -0
  212. package/dist/types/src/SchemaRegistry.d.ts +84 -0
  213. package/dist/types/src/SchemaRegistry.d.ts.map +1 -0
  214. package/dist/types/src/Tag.d.ts +17 -0
  215. package/dist/types/src/Tag.d.ts.map +1 -0
  216. package/dist/types/src/Type.d.ts +225 -73
  217. package/dist/types/src/Type.d.ts.map +1 -1
  218. package/dist/types/src/Type.test.d.ts +2 -0
  219. package/dist/types/src/Type.test.d.ts.map +1 -0
  220. package/dist/types/src/index.d.ts +15 -3
  221. package/dist/types/src/index.d.ts.map +1 -1
  222. package/dist/types/src/internal/annotations/annotations.d.ts +170 -0
  223. package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -0
  224. package/dist/types/src/internal/annotations/annotations.test.d.ts +2 -0
  225. package/dist/types/src/internal/annotations/annotations.test.d.ts.map +1 -0
  226. package/dist/types/src/internal/annotations/index.d.ts +3 -0
  227. package/dist/types/src/internal/annotations/index.d.ts.map +1 -0
  228. package/dist/types/src/internal/annotations/util.d.ts +27 -0
  229. package/dist/types/src/internal/annotations/util.d.ts.map +1 -0
  230. package/dist/types/src/internal/api/annotations.d.ts +23 -0
  231. package/dist/types/src/internal/api/annotations.d.ts.map +1 -0
  232. package/dist/types/src/internal/api/entity.d.ts +13 -0
  233. package/dist/types/src/internal/api/entity.d.ts.map +1 -0
  234. package/dist/types/src/internal/api/index.d.ts +15 -0
  235. package/dist/types/src/internal/api/index.d.ts.map +1 -0
  236. package/dist/types/src/internal/api/meta.d.ts +42 -0
  237. package/dist/types/src/internal/api/meta.d.ts.map +1 -0
  238. package/dist/types/src/internal/api/sorting.d.ts +24 -0
  239. package/dist/types/src/internal/api/sorting.d.ts.map +1 -0
  240. package/dist/types/src/internal/api/version.d.ts +42 -0
  241. package/dist/types/src/internal/api/version.d.ts.map +1 -0
  242. package/dist/types/src/internal/entities/entity.d.ts +20 -0
  243. package/dist/types/src/internal/entities/entity.d.ts.map +1 -0
  244. package/dist/types/src/internal/entities/index.d.ts +6 -0
  245. package/dist/types/src/internal/entities/index.d.ts.map +1 -0
  246. package/dist/types/src/internal/entities/model.d.ts +77 -0
  247. package/dist/types/src/internal/entities/model.d.ts.map +1 -0
  248. package/dist/types/src/internal/entities/object.d.ts +18 -0
  249. package/dist/types/src/internal/entities/object.d.ts.map +1 -0
  250. package/dist/types/src/internal/entities/relation.d.ts +62 -0
  251. package/dist/types/src/internal/entities/relation.d.ts.map +1 -0
  252. package/dist/types/src/internal/entities/util.d.ts +2 -0
  253. package/dist/types/src/internal/entities/util.d.ts.map +1 -0
  254. package/dist/types/src/internal/formats/date.d.ts +63 -0
  255. package/dist/types/src/internal/formats/date.d.ts.map +1 -0
  256. package/dist/types/src/internal/formats/date.test.d.ts +2 -0
  257. package/dist/types/src/internal/formats/date.test.d.ts.map +1 -0
  258. package/dist/types/src/internal/formats/format.d.ts +32 -0
  259. package/dist/types/src/internal/formats/format.d.ts.map +1 -0
  260. package/dist/types/src/internal/formats/format.test.d.ts +2 -0
  261. package/dist/types/src/internal/formats/format.test.d.ts.map +1 -0
  262. package/dist/types/src/internal/formats/index.d.ts +8 -0
  263. package/dist/types/src/internal/formats/index.d.ts.map +1 -0
  264. package/dist/types/src/internal/formats/number.d.ts +31 -0
  265. package/dist/types/src/internal/formats/number.d.ts.map +1 -0
  266. package/dist/types/src/internal/formats/object.d.ts +35 -0
  267. package/dist/types/src/internal/formats/object.d.ts.map +1 -0
  268. package/dist/types/src/internal/formats/select.d.ts +13 -0
  269. package/dist/types/src/internal/formats/select.d.ts.map +1 -0
  270. package/dist/types/src/internal/formats/string.d.ts +42 -0
  271. package/dist/types/src/internal/formats/string.d.ts.map +1 -0
  272. package/dist/types/src/internal/formats/types.d.ts +72 -0
  273. package/dist/types/src/internal/formats/types.d.ts.map +1 -0
  274. package/dist/types/src/internal/index.d.ts +12 -0
  275. package/dist/types/src/internal/index.d.ts.map +1 -0
  276. package/dist/types/src/internal/json-schema/annotations.d.ts +19 -0
  277. package/dist/types/src/internal/json-schema/annotations.d.ts.map +1 -0
  278. package/dist/types/src/internal/json-schema/effect-schema.test.d.ts +2 -0
  279. package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +1 -0
  280. package/dist/types/src/internal/json-schema/index.d.ts +5 -0
  281. package/dist/types/src/internal/json-schema/index.d.ts.map +1 -0
  282. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts +7 -0
  283. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +1 -0
  284. package/dist/types/src/internal/json-schema/json-schema-type.d.ts +250 -0
  285. package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -0
  286. package/dist/types/src/internal/json-schema/json-schema.d.ts +29 -0
  287. package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -0
  288. package/dist/types/src/internal/json-schema/json-schema.test.d.ts +2 -0
  289. package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +1 -0
  290. package/dist/types/src/internal/object/clone.d.ts +8 -0
  291. package/dist/types/src/internal/object/clone.d.ts.map +1 -0
  292. package/dist/types/src/internal/object/common.d.ts +18 -0
  293. package/dist/types/src/internal/object/common.d.ts.map +1 -0
  294. package/dist/types/src/internal/object/create-object.d.ts +39 -0
  295. package/dist/types/src/internal/object/create-object.d.ts.map +1 -0
  296. package/dist/types/src/internal/object/create-object.test.d.ts +2 -0
  297. package/dist/types/src/internal/object/create-object.test.d.ts.map +1 -0
  298. package/dist/types/src/internal/object/deleted.d.ts +6 -0
  299. package/dist/types/src/internal/object/deleted.d.ts.map +1 -0
  300. package/dist/types/src/internal/object/ids.d.ts +6 -0
  301. package/dist/types/src/internal/object/ids.d.ts.map +1 -0
  302. package/dist/types/src/internal/object/index.d.ts +11 -0
  303. package/dist/types/src/internal/object/index.d.ts.map +1 -0
  304. package/dist/types/src/internal/object/inspect.d.ts +2 -0
  305. package/dist/types/src/internal/object/inspect.d.ts.map +1 -0
  306. package/dist/types/src/internal/object/json-serializer.d.ts +37 -0
  307. package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -0
  308. package/dist/types/src/internal/object/json-serializer.test.d.ts +2 -0
  309. package/dist/types/src/internal/object/json-serializer.test.d.ts.map +1 -0
  310. package/dist/types/src/internal/object/schema-validator.d.ts +2 -0
  311. package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -0
  312. package/dist/types/src/internal/object/schema-validator.test.d.ts +2 -0
  313. package/dist/types/src/internal/object/schema-validator.test.d.ts.map +1 -0
  314. package/dist/types/src/internal/object/set-value.d.ts +7 -0
  315. package/dist/types/src/internal/object/set-value.d.ts.map +1 -0
  316. package/dist/types/src/internal/object/set-value.test.d.ts +2 -0
  317. package/dist/types/src/internal/object/set-value.test.d.ts.map +1 -0
  318. package/dist/types/src/internal/object/snapshot.d.ts +6 -0
  319. package/dist/types/src/internal/object/snapshot.d.ts.map +1 -0
  320. package/dist/types/src/internal/object/typed-object.d.ts +25 -0
  321. package/dist/types/src/internal/object/typed-object.d.ts.map +1 -0
  322. package/dist/types/src/internal/object/typed-object.test.d.ts +2 -0
  323. package/dist/types/src/internal/object/typed-object.test.d.ts.map +1 -0
  324. package/dist/types/src/internal/proxy/change-context.d.ts +55 -0
  325. package/dist/types/src/internal/proxy/change-context.d.ts.map +1 -0
  326. package/dist/types/src/internal/proxy/change.test.d.ts +2 -0
  327. package/dist/types/src/internal/proxy/change.test.d.ts.map +1 -0
  328. package/dist/types/src/internal/proxy/define-hidden-property.d.ts +5 -0
  329. package/dist/types/src/internal/proxy/define-hidden-property.d.ts.map +1 -0
  330. package/dist/types/src/internal/proxy/errors.d.ts +19 -0
  331. package/dist/types/src/internal/proxy/errors.d.ts.map +1 -0
  332. package/dist/types/src/internal/proxy/event-batch.d.ts +10 -0
  333. package/dist/types/src/internal/proxy/event-batch.d.ts.map +1 -0
  334. package/dist/types/src/internal/proxy/handler.test.d.ts +2 -0
  335. package/dist/types/src/internal/proxy/handler.test.d.ts.map +1 -0
  336. package/dist/types/src/internal/proxy/index.d.ts +14 -0
  337. package/dist/types/src/internal/proxy/index.d.ts.map +1 -0
  338. package/dist/types/src/internal/proxy/json-serializer.d.ts +6 -0
  339. package/dist/types/src/internal/proxy/json-serializer.d.ts.map +1 -0
  340. package/dist/types/src/internal/proxy/make-object.d.ts +14 -0
  341. package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -0
  342. package/dist/types/src/internal/proxy/ownership.d.ts +57 -0
  343. package/dist/types/src/internal/proxy/ownership.d.ts.map +1 -0
  344. package/dist/types/src/internal/proxy/proxy-types.d.ts +18 -0
  345. package/dist/types/src/internal/proxy/proxy-types.d.ts.map +1 -0
  346. package/dist/types/src/internal/proxy/proxy-utils.d.ts +47 -0
  347. package/dist/types/src/internal/proxy/proxy-utils.d.ts.map +1 -0
  348. package/dist/types/src/internal/proxy/reactive-array.d.ts +8 -0
  349. package/dist/types/src/internal/proxy/reactive-array.d.ts.map +1 -0
  350. package/dist/types/src/internal/proxy/reactive.d.ts +39 -0
  351. package/dist/types/src/internal/proxy/reactive.d.ts.map +1 -0
  352. package/dist/types/src/internal/proxy/schema-validator.d.ts +15 -0
  353. package/dist/types/src/internal/proxy/schema-validator.d.ts.map +1 -0
  354. package/dist/types/src/internal/proxy/schema.test.d.ts +2 -0
  355. package/dist/types/src/internal/proxy/schema.test.d.ts.map +1 -0
  356. package/dist/types/src/internal/proxy/symbols.d.ts +3 -0
  357. package/dist/types/src/internal/proxy/symbols.d.ts.map +1 -0
  358. package/dist/types/src/internal/proxy/typed-handler.d.ts +47 -0
  359. package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -0
  360. package/dist/types/src/internal/proxy/typed-handler.test.d.ts +2 -0
  361. package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +1 -0
  362. package/dist/types/src/internal/proxy/typed-object.test.d.ts +2 -0
  363. package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +1 -0
  364. package/dist/types/src/internal/ref/index.d.ts +3 -0
  365. package/dist/types/src/internal/ref/index.d.ts.map +1 -0
  366. package/dist/types/src/internal/ref/ref-array.d.ts +21 -0
  367. package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -0
  368. package/dist/types/src/internal/ref/ref.d.ts +217 -0
  369. package/dist/types/src/internal/ref/ref.d.ts.map +1 -0
  370. package/dist/types/src/internal/ref/ref.test.d.ts +2 -0
  371. package/dist/types/src/internal/ref/ref.test.d.ts.map +1 -0
  372. package/dist/types/src/internal/schema/compose.d.ts +6 -0
  373. package/dist/types/src/internal/schema/compose.d.ts.map +1 -0
  374. package/dist/types/src/internal/schema/compose.test.d.ts +2 -0
  375. package/dist/types/src/internal/schema/compose.test.d.ts.map +1 -0
  376. package/dist/types/src/internal/schema/echo-schema.d.ts +180 -0
  377. package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -0
  378. package/dist/types/src/internal/schema/index.d.ts +4 -0
  379. package/dist/types/src/internal/schema/index.d.ts.map +1 -0
  380. package/dist/types/src/internal/schema/manipulation.d.ts +10 -0
  381. package/dist/types/src/internal/schema/manipulation.d.ts.map +1 -0
  382. package/dist/types/src/internal/schema/persistent-schema.d.ts +20 -0
  383. package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -0
  384. package/dist/types/src/internal/types/base.d.ts +26 -0
  385. package/dist/types/src/internal/types/base.d.ts.map +1 -0
  386. package/dist/types/src/internal/types/entity.d.ts +37 -0
  387. package/dist/types/src/internal/types/entity.d.ts.map +1 -0
  388. package/dist/types/src/internal/types/index.d.ts +6 -0
  389. package/dist/types/src/internal/types/index.d.ts.map +1 -0
  390. package/dist/types/src/internal/types/meta.d.ts +32 -0
  391. package/dist/types/src/internal/types/meta.d.ts.map +1 -0
  392. package/dist/types/src/internal/types/typename.d.ts +13 -0
  393. package/dist/types/src/internal/types/typename.d.ts.map +1 -0
  394. package/dist/types/src/internal/types/version.d.ts +15 -0
  395. package/dist/types/src/internal/types/version.d.ts.map +1 -0
  396. package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
  397. package/dist/types/src/testing/index.d.ts +3 -1
  398. package/dist/types/src/testing/index.d.ts.map +1 -1
  399. package/dist/types/src/testing/test-data.d.ts +18 -0
  400. package/dist/types/src/testing/test-data.d.ts.map +1 -0
  401. package/dist/types/src/testing/test-schema.d.ts +303 -0
  402. package/dist/types/src/testing/test-schema.d.ts.map +1 -0
  403. package/dist/types/src/testing/util.d.ts +21 -0
  404. package/dist/types/src/testing/util.d.ts.map +1 -0
  405. package/dist/types/tsconfig.tsbuildinfo +1 -1
  406. package/package.json +166 -33
  407. package/src/Annotation.ts +18 -0
  408. package/src/Database.ts +336 -0
  409. package/src/Entity.test.ts +22 -0
  410. package/src/Entity.ts +217 -0
  411. package/src/Err.ts +18 -0
  412. package/src/Filter.ts +376 -0
  413. package/src/Format.ts +9 -0
  414. package/src/Hypergraph.ts +74 -0
  415. package/src/JsonSchema.ts +16 -0
  416. package/src/Key.ts +3 -0
  417. package/src/Obj.test.ts +386 -0
  418. package/src/Obj.ts +509 -85
  419. package/src/Order.ts +44 -0
  420. package/src/Query.test.ts +465 -0
  421. package/src/Query.ts +296 -0
  422. package/src/QueryResult.ts +106 -0
  423. package/src/Ref.ts +25 -9
  424. package/src/Relation.test.ts +82 -0
  425. package/src/Relation.ts +414 -51
  426. package/src/SchemaRegistry.ts +105 -0
  427. package/src/Tag.ts +40 -0
  428. package/src/Type.test.ts +52 -0
  429. package/src/Type.ts +360 -112
  430. package/src/index.ts +17 -4
  431. package/src/internal/README.md +102 -0
  432. package/src/internal/annotations/annotations.test.ts +96 -0
  433. package/src/internal/annotations/annotations.ts +460 -0
  434. package/src/internal/annotations/index.ts +6 -0
  435. package/src/internal/annotations/util.ts +72 -0
  436. package/src/internal/api/annotations.ts +60 -0
  437. package/src/internal/api/entity.ts +29 -0
  438. package/src/internal/api/index.ts +19 -0
  439. package/src/internal/api/meta.ts +88 -0
  440. package/src/internal/api/sorting.ts +53 -0
  441. package/src/internal/api/version.ts +96 -0
  442. package/src/internal/entities/entity.ts +126 -0
  443. package/src/internal/entities/index.ts +9 -0
  444. package/src/internal/entities/model.ts +134 -0
  445. package/src/internal/entities/object.ts +60 -0
  446. package/src/internal/entities/relation.ts +173 -0
  447. package/src/internal/entities/util.ts +33 -0
  448. package/src/internal/formats/date.test.ts +56 -0
  449. package/src/internal/formats/date.ts +217 -0
  450. package/src/internal/formats/format.test.ts +77 -0
  451. package/src/internal/formats/format.ts +54 -0
  452. package/src/internal/formats/index.ts +12 -0
  453. package/src/internal/formats/number.ts +89 -0
  454. package/src/internal/formats/object.ts +80 -0
  455. package/src/internal/formats/select.ts +18 -0
  456. package/src/internal/formats/string.ts +81 -0
  457. package/src/internal/formats/types.ts +186 -0
  458. package/src/internal/index.ts +39 -0
  459. package/src/internal/json-schema/annotations.ts +50 -0
  460. package/src/internal/json-schema/effect-schema.test.ts +143 -0
  461. package/src/internal/json-schema/index.ts +8 -0
  462. package/src/internal/json-schema/json-schema-normalize.ts +109 -0
  463. package/src/internal/json-schema/json-schema-type.ts +404 -0
  464. package/src/internal/json-schema/json-schema.test.ts +861 -0
  465. package/src/internal/json-schema/json-schema.ts +528 -0
  466. package/src/internal/object/clone.ts +48 -0
  467. package/src/internal/object/common.ts +75 -0
  468. package/src/internal/object/create-object.test.ts +116 -0
  469. package/src/internal/object/create-object.ts +95 -0
  470. package/src/internal/object/deleted.ts +19 -0
  471. package/src/internal/object/ids.ts +12 -0
  472. package/src/internal/object/index.ts +14 -0
  473. package/src/internal/object/inspect.ts +46 -0
  474. package/src/internal/object/json-serializer.test.ts +97 -0
  475. package/src/internal/object/json-serializer.ts +188 -0
  476. package/src/internal/object/schema-validator.test.ts +186 -0
  477. package/src/internal/object/schema-validator.ts +6 -0
  478. package/src/internal/object/set-value.test.ts +281 -0
  479. package/src/internal/object/set-value.ts +165 -0
  480. package/src/internal/object/snapshot.ts +70 -0
  481. package/src/internal/object/typed-object.test.ts +34 -0
  482. package/src/internal/object/typed-object.ts +30 -0
  483. package/src/internal/proxy/change-context.ts +138 -0
  484. package/src/internal/proxy/change.test.ts +519 -0
  485. package/src/internal/proxy/define-hidden-property.ts +14 -0
  486. package/src/internal/proxy/errors.ts +42 -0
  487. package/src/internal/proxy/event-batch.ts +44 -0
  488. package/src/internal/proxy/handler.test.ts +123 -0
  489. package/src/internal/proxy/index.ts +17 -0
  490. package/src/internal/proxy/json-serializer.ts +87 -0
  491. package/src/internal/proxy/make-object.ts +96 -0
  492. package/src/internal/proxy/ownership.ts +253 -0
  493. package/src/internal/proxy/proxy-types.ts +23 -0
  494. package/src/internal/proxy/proxy-utils.ts +150 -0
  495. package/src/internal/proxy/reactive-array.ts +71 -0
  496. package/src/internal/proxy/reactive.ts +69 -0
  497. package/src/internal/proxy/schema-validator.ts +244 -0
  498. package/src/internal/proxy/schema.test.ts +145 -0
  499. package/src/internal/proxy/symbols.ts +7 -0
  500. package/src/internal/proxy/typed-handler.test.ts +318 -0
  501. package/src/internal/proxy/typed-handler.ts +442 -0
  502. package/src/internal/proxy/typed-object.test.ts +116 -0
  503. package/src/internal/ref/index.ts +6 -0
  504. package/src/internal/ref/ref-array.ts +39 -0
  505. package/src/internal/ref/ref.test.ts +101 -0
  506. package/src/internal/ref/ref.ts +548 -0
  507. package/src/internal/schema/compose.test.ts +42 -0
  508. package/src/internal/schema/compose.ts +36 -0
  509. package/src/internal/schema/echo-schema.ts +423 -0
  510. package/src/internal/schema/index.ts +7 -0
  511. package/src/internal/schema/manipulation.ts +92 -0
  512. package/src/internal/schema/persistent-schema.ts +27 -0
  513. package/src/internal/types/base.ts +43 -0
  514. package/src/internal/types/entity.ts +54 -0
  515. package/src/internal/types/index.ts +9 -0
  516. package/src/internal/types/meta.ts +66 -0
  517. package/src/internal/types/typename.ts +45 -0
  518. package/src/internal/types/version.ts +20 -0
  519. package/src/testing/api.test.ts +126 -0
  520. package/src/testing/index.ts +3 -1
  521. package/src/testing/test-data.ts +130 -0
  522. package/src/testing/test-schema.ts +238 -0
  523. package/src/testing/util.ts +85 -0
  524. package/dist/lib/browser/chunk-SVSJEELN.mjs +0 -619
  525. package/dist/lib/browser/chunk-SVSJEELN.mjs.map +0 -7
  526. package/dist/lib/node-esm/chunk-53HXWYR6.mjs +0 -619
  527. package/dist/lib/node-esm/chunk-53HXWYR6.mjs.map +0 -7
  528. package/dist/types/src/experimental/database.d.ts +0 -8
  529. package/dist/types/src/experimental/database.d.ts.map +0 -1
  530. package/dist/types/src/experimental/index.d.ts +0 -1
  531. package/dist/types/src/experimental/index.d.ts.map +0 -1
  532. package/dist/types/src/experimental/queue.d.ts +0 -8
  533. package/dist/types/src/experimental/queue.d.ts.map +0 -1
  534. package/dist/types/src/experimental/space.d.ts +0 -8
  535. package/dist/types/src/experimental/space.d.ts.map +0 -1
  536. package/dist/types/src/query/dsl.d.ts +0 -218
  537. package/dist/types/src/query/dsl.d.ts.map +0 -1
  538. package/dist/types/src/query/dsl.test.d.ts +0 -2
  539. package/dist/types/src/query/dsl.test.d.ts.map +0 -1
  540. package/dist/types/src/query/index.d.ts +0 -2
  541. package/dist/types/src/query/index.d.ts.map +0 -1
  542. package/dist/types/src/testing/types.d.ts +0 -113
  543. package/dist/types/src/testing/types.d.ts.map +0 -1
  544. package/src/experimental/database.ts +0 -11
  545. package/src/experimental/index.ts +0 -7
  546. package/src/experimental/queue.ts +0 -11
  547. package/src/experimental/space.ts +0 -11
  548. package/src/query/dsl.test.ts +0 -323
  549. package/src/query/dsl.ts +0 -646
  550. package/src/query/index.ts +0 -5
  551. package/src/test/api.test.ts +0 -173
  552. package/src/testing/types.ts +0 -91
  553. /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
package/src/Relation.ts CHANGED
@@ -2,47 +2,133 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type Schema } from 'effect';
5
+ import type * as Schema from 'effect/Schema';
6
6
 
7
7
  import { raise } from '@dxos/debug';
8
- import * as EchoSchema from '@dxos/echo-schema';
8
+ import type { ForeignKey } from '@dxos/echo-protocol';
9
+ import { createJsonPath, getValue as getValue$ } from '@dxos/effect';
9
10
  import { assertArgument, invariant } from '@dxos/invariant';
10
- import { DXN } from '@dxos/keys';
11
- import { type Live, live } from '@dxos/live-object';
11
+ import { DXN, type ObjectId } from '@dxos/keys';
12
12
  import { assumeType } from '@dxos/util';
13
13
 
14
+ import type * as Database from './Database';
15
+ import * as Entity from './Entity';
16
+ import {
17
+ type ObjectJSON as APIJSON,
18
+ ATTR_RELATION_SOURCE,
19
+ ATTR_RELATION_TARGET,
20
+ type AnyEntity,
21
+ type Comparator as ApiComparator,
22
+ type Meta as ApiMeta,
23
+ type ReadonlyMeta as ApiReadonlyMeta,
24
+ type EntityVersion as ApiVersion,
25
+ type ChangeCallback,
26
+ EntityKind,
27
+ type InternalObjectProps,
28
+ type KindId,
29
+ MetaId,
30
+ type Mutable,
31
+ type ObjectMeta,
32
+ RelationSourceDXNId,
33
+ RelationSourceId,
34
+ RelationTargetDXNId,
35
+ RelationTargetId,
36
+ SnapshotKindId,
37
+ VersionTypeId,
38
+ addTag as addTag$,
39
+ change as change$,
40
+ deleteKeys as deleteKeys$,
41
+ getDXN as getDXN$,
42
+ getDatabase as getDatabase$,
43
+ getDescription as getDescription$,
44
+ getKeys as getKeys$,
45
+ getLabel as getLabel$,
46
+ getMetaChecked as getMeta$,
47
+ getObjectDXN,
48
+ getSchema as getSchema$,
49
+ getSnapshot as getSnapshot$,
50
+ getTypeAnnotation,
51
+ getTypeDXN as getTypeDXN$,
52
+ getTypename as getTypename$,
53
+ isDeleted as isDeleted$,
54
+ isVersion,
55
+ makeObject,
56
+ removeTag as removeTag$,
57
+ setDescription as setDescription$,
58
+ setLabel as setLabel$,
59
+ setValue as setValue$,
60
+ sort as sort$,
61
+ sortByLabel as sortByLabel$,
62
+ sortByTypename as sortByTypename$,
63
+ subscribe as subscribe$,
64
+ objectToJSON as toJSON$,
65
+ version as version$,
66
+ } from './internal';
14
67
  import type * as Obj from './Obj';
15
68
  import type * as Type from './Type';
16
69
 
17
- // NOTE: Don't export: Relation.Relation and Relation.Any form the public API.
18
- interface RelationBase<Source, Target>
19
- extends Type.Relation.Endpoints<Source, Target>,
20
- Type.OfKind<EchoSchema.EntityKind.Relation> {
21
- readonly id: EchoSchema.ObjectId;
22
- }
70
+ /**
71
+ * Base type for all ECHO relations.
72
+ * @private
73
+ */
74
+ interface BaseRelation<Source, Target>
75
+ extends AnyEntity,
76
+ Type.Relation.Endpoints<Source, Target>,
77
+ Entity.OfKind<EntityKind.Relation> {}
23
78
 
24
79
  /**
25
- * Relation type with specific properties.
80
+ * Relation with no known properties beyond id, kind, source, and target.
81
+ * Use this when the relation's schema/properties are not known.
82
+ *
83
+ * NOTE: This is a TypeScript type only, not a schema.
84
+ * To validate that a value is an ECHO relation, use `Relation.isRelation`.
26
85
  */
27
- export type Relation<Source extends Obj.Any, Target extends Obj.Any, Props> = RelationBase<Source, Target> & Props;
86
+ export interface Unknown extends BaseRelation<Obj.Unknown, Obj.Unknown> {}
28
87
 
29
88
  /**
30
- * Base type for all ECHO relations.
89
+ * Relation type with specific source and target types.
31
90
  */
32
- export interface Any extends RelationBase<Obj.Any, Obj.Any> {}
91
+ export type Relation<Source extends Obj.Unknown, Target extends Obj.Unknown, Props> = BaseRelation<Source, Target> &
92
+ Props;
33
93
 
34
- // TODO(dmaretskyi): Has to be `unique symbol`.
35
- export const Source: unique symbol = EchoSchema.RelationSourceId as any;
94
+ /**
95
+ * Base type for snapshot relations (has SnapshotKindId instead of KindId).
96
+ */
97
+ interface BaseRelationSnapshot<Source, Target> extends AnyEntity, Type.Relation.Endpoints<Source, Target> {
98
+ readonly [SnapshotKindId]: EntityKind.Relation;
99
+ readonly id: ObjectId;
100
+ }
101
+
102
+ /**
103
+ * Immutable snapshot of an ECHO relation.
104
+ * Branded with SnapshotKindId (not KindId).
105
+ * Property values are frozen at the time the snapshot was created.
106
+ * Returned by getSnapshot() and hooks.
107
+ */
108
+ export type Snapshot<T extends Unknown = Unknown> = Omit<T, KindId> & BaseRelationSnapshot<Obj.Unknown, Obj.Unknown>;
109
+
110
+ export const Source: unique symbol = RelationSourceId as any;
36
111
  export type Source = typeof Source;
37
- export const Target: unique symbol = EchoSchema.RelationTargetId as any;
112
+
113
+ export const Target: unique symbol = RelationTargetId as any;
38
114
  export type Target = typeof Target;
39
115
 
40
- type MakeProps<T extends Any> = {
41
- id?: EchoSchema.ObjectId;
116
+ /**
117
+ * Internal props type for relation instance creation.
118
+ */
119
+ type RelationMakeProps<T extends Unknown> = {
120
+ id?: ObjectId;
121
+ [MetaId]?: ObjectMeta;
42
122
  [Source]: T[Source];
43
123
  [Target]: T[Target];
44
124
  } & Type.Properties<T>;
45
125
 
126
+ /**
127
+ * Props type for relation creation with a given schema.
128
+ * Takes a schema type (created with Type.Relation) and extracts the props type.
129
+ */
130
+ export type MakeProps<S extends Type.Relation.Any> = RelationMakeProps<Schema.Schema.Type<S>>;
131
+
46
132
  /**
47
133
  * Creates new relation.
48
134
  * @param schema - Relation schema.
@@ -54,83 +140,360 @@ type MakeProps<T extends Any> = {
54
140
  // TODO(dmaretskyi): Move meta into props.
55
141
  export const make = <S extends Type.Relation.Any>(
56
142
  schema: S,
57
- props: NoInfer<MakeProps<Schema.Schema.Type<S>>>,
58
- meta?: EchoSchema.ObjectMeta,
59
- ): Live<Schema.Schema.Type<S> & Type.OfKind<EchoSchema.EntityKind.Relation>> => {
60
- assertArgument(
61
- EchoSchema.getTypeAnnotation(schema)?.kind === EchoSchema.EntityKind.Relation,
62
- 'Expected a relation schema',
63
- );
64
-
65
- if (props[EchoSchema.MetaId] != null) {
66
- meta = props[EchoSchema.MetaId] as any;
67
- delete props[EchoSchema.MetaId];
143
+ props: NoInfer<RelationMakeProps<Schema.Schema.Type<S>>>,
144
+ meta?: ObjectMeta,
145
+ ): Schema.Schema.Type<S> & Entity.OfKind<typeof Entity.Kind.Relation> => {
146
+ assertArgument(getTypeAnnotation(schema)?.kind === EntityKind.Relation, 'schema', 'Expected a relation schema');
147
+
148
+ if (props[MetaId] != null) {
149
+ meta = props[MetaId] as any;
150
+ delete props[MetaId];
68
151
  }
69
152
 
70
- const sourceDXN = EchoSchema.getObjectDXN(props[Source]) ?? raise(new Error('Unresolved relation source'));
71
- const targetDXN = EchoSchema.getObjectDXN(props[Target]) ?? raise(new Error('Unresolved relation target'));
72
- (props as any)[EchoSchema.RelationSourceDXNId] = sourceDXN;
73
- (props as any)[EchoSchema.RelationTargetDXNId] = targetDXN;
153
+ const sourceDXN = getObjectDXN(props[Source]) ?? raise(new Error('Unresolved relation source'));
154
+ const targetDXN = getObjectDXN(props[Target]) ?? raise(new Error('Unresolved relation target'));
74
155
 
75
- return live<Schema.Schema.Type<S>>(schema, props as any, meta);
156
+ (props as any)[RelationSourceDXNId] = sourceDXN;
157
+ (props as any)[RelationTargetDXNId] = targetDXN;
158
+
159
+ return makeObject<Schema.Schema.Type<S>>(schema, props as any, meta);
76
160
  };
77
161
 
78
- export const isRelation = (value: unknown): value is Any => {
162
+ /**
163
+ * Type guard for relations.
164
+ * Returns true for both reactive relations and relation snapshots.
165
+ */
166
+ export const isRelation = (value: unknown): value is Unknown => {
79
167
  if (typeof value !== 'object' || value === null) {
80
168
  return false;
81
169
  }
82
- if (EchoSchema.ATTR_RELATION_SOURCE in value || EchoSchema.ATTR_RELATION_TARGET in value) {
170
+ if (ATTR_RELATION_SOURCE in value || ATTR_RELATION_TARGET in value) {
83
171
  return true;
84
172
  }
85
173
 
86
- const kind = (value as any)[EchoSchema.EntityKindId];
87
- return kind === EchoSchema.EntityKind.Relation;
174
+ // Check for reactive relation (KindId) or snapshot (SnapshotKindId).
175
+ const kind = (value as any)[Entity.KindId] ?? (value as any)[SnapshotKindId];
176
+ return kind === EntityKind.Relation;
88
177
  };
89
178
 
90
179
  /**
91
180
  * @returns Relation source DXN.
181
+ * Accepts both reactive relations and snapshots.
92
182
  * @throws If the object is not a relation.
93
183
  */
94
- export const getSourceDXN = (value: Any): DXN => {
184
+ export const getSourceDXN = (value: Unknown | Snapshot): DXN => {
95
185
  assertArgument(isRelation(value), 'Expected a relation');
96
- assumeType<EchoSchema.InternalObjectProps>(value);
97
- const dxn = (value as EchoSchema.InternalObjectProps)[EchoSchema.RelationSourceDXNId];
186
+ assumeType<InternalObjectProps>(value);
187
+ const dxn = (value as InternalObjectProps)[RelationSourceDXNId];
98
188
  invariant(dxn instanceof DXN);
99
189
  return dxn;
100
190
  };
101
191
 
102
192
  /**
103
193
  * @returns Relation target DXN.
194
+ * Accepts both reactive relations and snapshots.
104
195
  * @throws If the object is not a relation.
105
196
  */
106
- export const getTargetDXN = (value: Any): DXN => {
197
+ export const getTargetDXN = (value: Unknown | Snapshot): DXN => {
107
198
  assertArgument(isRelation(value), 'Expected a relation');
108
- assumeType<EchoSchema.InternalObjectProps>(value);
109
- const dxn = (value as EchoSchema.InternalObjectProps)[EchoSchema.RelationTargetDXNId];
199
+ assumeType<InternalObjectProps>(value);
200
+ const dxn = (value as InternalObjectProps)[RelationTargetDXNId];
110
201
  invariant(dxn instanceof DXN);
111
202
  return dxn;
112
203
  };
113
204
 
114
205
  /**
115
206
  * @returns Relation source.
207
+ * Accepts both reactive relations and snapshots.
116
208
  * @throws If the object is not a relation.
117
209
  */
118
- export const getSource = <T extends Any>(relation: T): Type.Relation.Source<T> => {
210
+ export const getSource = <T extends Unknown | Snapshot>(relation: T): Type.Relation.Source<T> => {
119
211
  assertArgument(isRelation(relation), 'Expected a relation');
120
- assumeType<EchoSchema.InternalObjectProps>(relation);
121
- const obj = (relation as EchoSchema.InternalObjectProps)[EchoSchema.RelationSourceId];
212
+ assumeType<InternalObjectProps>(relation);
213
+ const obj = (relation as InternalObjectProps)[RelationSourceId];
122
214
  invariant(obj !== undefined, `Invalid source: ${relation.id}`);
123
215
  return obj as Type.Relation.Source<T>;
124
216
  };
125
217
 
126
218
  /**
127
219
  * @returns Relation target.
220
+ * Accepts both reactive relations and snapshots.
128
221
  * @throws If the object is not a relation.
129
222
  */
130
- export const getTarget = <T extends Any>(relation: T): Type.Relation.Target<T> => {
223
+ export const getTarget = <T extends Unknown | Snapshot>(relation: T): Type.Relation.Target<T> => {
131
224
  assertArgument(isRelation(relation), 'Expected a relation');
132
- assumeType<EchoSchema.InternalObjectProps>(relation);
133
- const obj = (relation as EchoSchema.InternalObjectProps)[EchoSchema.RelationTargetId];
225
+ assumeType<InternalObjectProps>(relation);
226
+ const obj = (relation as InternalObjectProps)[RelationTargetId];
134
227
  invariant(obj !== undefined, `Invalid target: ${relation.id}`);
135
228
  return obj as Type.Relation.Target<T>;
136
229
  };
230
+
231
+ //
232
+ // Change
233
+ //
234
+
235
+ /**
236
+ * Makes all properties mutable recursively.
237
+ * Used to provide a mutable view of a relation within `Relation.change`.
238
+ */
239
+ export type { Mutable };
240
+
241
+ /**
242
+ * Perform mutations on an echo relation within a controlled context.
243
+ *
244
+ * All mutations within the callback are batched and trigger a single notification
245
+ * when the callback completes. Direct mutations outside of `Relation.change` will throw
246
+ * an error for echo relations.
247
+ *
248
+ * @param relation - The echo relation to mutate. Use `Obj.change` for objects.
249
+ * @param callback - The callback that performs mutations on the relation.
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * const worksFor = Relation.make(EmployedBy, {
254
+ * [Relation.Source]: person,
255
+ * [Relation.Target]: company,
256
+ * role: 'Engineer',
257
+ * });
258
+ *
259
+ * // Mutate within Relation.change
260
+ * Relation.change(worksFor, (r) => {
261
+ * r.role = 'Senior Engineer';
262
+ * });
263
+ * ```
264
+ *
265
+ * Note: Only accepts relations. Use `Obj.change` for objects.
266
+ */
267
+ export const change = <T extends Unknown>(relation: T, callback: ChangeCallback<T>): void => {
268
+ change$(relation, callback);
269
+ };
270
+
271
+ //
272
+ // Snapshot
273
+ //
274
+
275
+ /**
276
+ * Returns an immutable snapshot of a relation.
277
+ * The snapshot is branded with SnapshotKindId instead of KindId,
278
+ * making it distinguishable from the reactive relation at the type level.
279
+ */
280
+ export const getSnapshot: <T extends Unknown>(rel: T) => Snapshot<T> = getSnapshot$ as any;
281
+
282
+ //
283
+ // Subscribe
284
+ //
285
+
286
+ /**
287
+ * Subscribe to relation updates.
288
+ * The callback is called synchronously when the relation is modified.
289
+ * Only accepts reactive relations (not snapshots).
290
+ * @returns Unsubscribe function.
291
+ */
292
+ export const subscribe = (rel: Unknown, callback: () => void): (() => void) => {
293
+ return subscribe$(rel, callback);
294
+ };
295
+
296
+ //
297
+ // Property Access
298
+ //
299
+
300
+ /**
301
+ * Get a deeply nested property from a relation.
302
+ * Accepts both reactive relations and snapshots.
303
+ */
304
+ export const getValue = (rel: Unknown | Snapshot, path: readonly (string | number)[]): any => {
305
+ return getValue$(rel, createJsonPath(path));
306
+ };
307
+
308
+ /**
309
+ * Set a deeply nested property on a relation.
310
+ * Must be called within a `Relation.change` callback.
311
+ *
312
+ * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
313
+ * parameters, so there is no compile-time error. Enforcement is runtime-only.
314
+ */
315
+ export const setValue: (rel: Mutable<Unknown>, path: readonly (string | number)[], value: any) => void =
316
+ setValue$ as any;
317
+
318
+ //
319
+ // Type
320
+ //
321
+
322
+ /**
323
+ * Get the DXN of the relation.
324
+ * Accepts both reactive relations and snapshots.
325
+ */
326
+ export const getDXN = (entity: Unknown | Snapshot): DXN => getDXN$(entity);
327
+
328
+ /**
329
+ * @returns The DXN of the relation's type.
330
+ */
331
+ export const getTypeDXN = getTypeDXN$;
332
+
333
+ /**
334
+ * Get the schema of the relation.
335
+ * Returns the branded ECHO schema used to create the relation.
336
+ */
337
+ export const getSchema: (rel: unknown | undefined) => Type.Entity.Any | undefined = getSchema$ as any;
338
+
339
+ /**
340
+ * @returns The typename of the relation's type.
341
+ * Accepts both reactive relations and snapshots.
342
+ */
343
+ export const getTypename = (entity: Unknown | Snapshot): string | undefined => getTypename$(entity);
344
+
345
+ //
346
+ // Database
347
+ //
348
+
349
+ /**
350
+ * Get the database the relation belongs to.
351
+ * Accepts both reactive relations and snapshots.
352
+ */
353
+ export const getDatabase = (entity: Unknown | Snapshot): Database.Database | undefined => getDatabase$(entity);
354
+
355
+ //
356
+ // Meta
357
+ //
358
+
359
+ /**
360
+ * Deeply read-only version of ObjectMeta.
361
+ */
362
+ export type ReadonlyMeta = ApiReadonlyMeta;
363
+
364
+ /**
365
+ * Mutable meta type returned by `Relation.getMeta` inside a `Relation.change` callback.
366
+ */
367
+ export type Meta = ApiMeta;
368
+
369
+ /**
370
+ * Get the metadata for a relation.
371
+ * Returns mutable meta when passed a mutable relation (inside `Relation.change` callback).
372
+ * Returns read-only meta when passed a regular relation or snapshot.
373
+ */
374
+ // TODO(wittjosiah): When passed a Snapshot, should return a snapshot of meta, not the live meta proxy.
375
+ export function getMeta(entity: Mutable<Unknown>): ObjectMeta;
376
+ export function getMeta(entity: Unknown | Snapshot): ReadonlyMeta;
377
+ export function getMeta(entity: Unknown | Snapshot | Mutable<Unknown>): ObjectMeta | ReadonlyMeta {
378
+ return getMeta$(entity);
379
+ }
380
+
381
+ /**
382
+ * @returns Foreign keys for the relation from the specified source.
383
+ * Accepts both reactive relations and snapshots.
384
+ */
385
+ export const getKeys = (entity: Unknown | Snapshot, source: string): ForeignKey[] => getKeys$(entity, source);
386
+
387
+ /**
388
+ * Delete all keys from the relation for the specified source.
389
+ * Must be called within a `Relation.change` callback.
390
+ *
391
+ * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
392
+ * parameters, so there is no compile-time error. Enforcement is runtime-only.
393
+ */
394
+ export const deleteKeys = (entity: Mutable<Unknown>, source: string): void => deleteKeys$(entity, source);
395
+
396
+ /**
397
+ * Add a tag to the relation.
398
+ * Must be called within a `Relation.change` 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
+ export const addTag = (entity: Mutable<Unknown>, tag: string): void => addTag$(entity, tag);
404
+
405
+ /**
406
+ * Remove a tag from the relation.
407
+ * Must be called within a `Relation.change` callback.
408
+ *
409
+ * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
410
+ * parameters, so there is no compile-time error. Enforcement is runtime-only.
411
+ */
412
+ export const removeTag = (entity: Mutable<Unknown>, tag: string): void => removeTag$(entity, tag);
413
+
414
+ /**
415
+ * Check if the relation is deleted.
416
+ * Accepts both reactive relations and snapshots.
417
+ */
418
+ export const isDeleted = (entity: Unknown | Snapshot): boolean => isDeleted$(entity);
419
+
420
+ //
421
+ // Annotations
422
+ //
423
+
424
+ /**
425
+ * Get the label of the relation.
426
+ * Accepts both reactive relations and snapshots.
427
+ */
428
+ export const getLabel = (entity: Unknown | Snapshot): string | undefined => getLabel$(entity);
429
+
430
+ /**
431
+ * Set the label of the relation.
432
+ * Must be called within a `Relation.change` callback.
433
+ *
434
+ * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
435
+ * parameters, so there is no compile-time error. Enforcement is runtime-only.
436
+ */
437
+ export const setLabel = (entity: Mutable<Unknown>, label: string): void => setLabel$(entity, label);
438
+
439
+ /**
440
+ * Get the description of the relation.
441
+ * Accepts both reactive relations and snapshots.
442
+ */
443
+ export const getDescription = (entity: Unknown | Snapshot): string | undefined => getDescription$(entity);
444
+
445
+ /**
446
+ * Set the description of the relation.
447
+ * Must be called within a `Relation.change` callback.
448
+ *
449
+ * NOTE: TypeScript's structural typing allows readonly objects to be passed to `Mutable<T>`
450
+ * parameters, so there is no compile-time error. Enforcement is runtime-only.
451
+ */
452
+ export const setDescription = (entity: Mutable<Unknown>, description: string): void =>
453
+ setDescription$(entity, description);
454
+
455
+ //
456
+ // JSON
457
+ //
458
+
459
+ /**
460
+ * JSON representation of a relation.
461
+ */
462
+ export type JSON = APIJSON;
463
+
464
+ /**
465
+ * Converts relation to its JSON representation.
466
+ * Accepts both reactive relations and snapshots.
467
+ */
468
+ export const toJSON = (entity: Unknown | Snapshot): JSON => toJSON$(entity);
469
+
470
+ //
471
+ // Sorting
472
+ //
473
+
474
+ /**
475
+ * Comparator function type for sorting relations.
476
+ * Accepts both reactive relations and snapshots.
477
+ */
478
+ export type Comparator = ApiComparator<Unknown | Snapshot>;
479
+
480
+ export const sortByLabel: Comparator = sortByLabel$ as Comparator;
481
+ export const sortByTypename: Comparator = sortByTypename$ as Comparator;
482
+ export const sort = (...comparators: Comparator[]): Comparator => sort$(...comparators) as Comparator;
483
+
484
+ //
485
+ // Version
486
+ //
487
+
488
+ export { VersionTypeId, isVersion };
489
+
490
+ /**
491
+ * Represent relation version.
492
+ */
493
+ export type Version = ApiVersion;
494
+
495
+ /**
496
+ * Returns the version of the relation.
497
+ * Accepts both reactive relations and snapshots.
498
+ */
499
+ export const version = (entity: Unknown | Snapshot): Version => version$(entity);
@@ -0,0 +1,105 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import type * as Types from 'effect/Types';
6
+
7
+ import type * as JsonSchema from './JsonSchema';
8
+ import type * as Key from './Key';
9
+ import type * as QueryResult from './QueryResult';
10
+ import type * as Type from './Type';
11
+
12
+ // TODO(wittjosiah): Replace w/ Query.Query.
13
+ export type Query = {
14
+ /**
15
+ * Filter by schema ID.
16
+ * Schema id is a DXN with `echo` or `type` kind.
17
+ */
18
+ id?: string | string[];
19
+
20
+ /**
21
+ * Id of the backing ECHO object.
22
+ */
23
+ backingObjectId?: Key.ObjectId | Key.ObjectId[];
24
+
25
+ /**
26
+ * One or more typenames to filter by.
27
+ */
28
+ typename?: string | string[];
29
+
30
+ /**
31
+ * [Semver Range](https://docs.npmjs.com/cli/v6/using-npm/semver#ranges) for the schema version.
32
+ */
33
+ version?: string;
34
+
35
+ /**
36
+ * Where to look for the schema.
37
+ *
38
+ * Database schema are stored in the database of the current space.
39
+ * Runtime schema are registered in the runtime.
40
+ *
41
+ * @default ['database']
42
+ */
43
+ location?: ('database' | 'runtime')[];
44
+
45
+ /**
46
+ * Include system schemas.
47
+ * @default false
48
+ *
49
+ * The system schema include but are not limited to:
50
+ * - dxos.org/type/Schema
51
+ */
52
+ includeSystem?: boolean;
53
+ };
54
+
55
+ /**
56
+ * Input for schema registration.
57
+ * The typename, version and schema mutability metadata is read from the schema annotations.
58
+ *
59
+ * Accepts:
60
+ * - Branded ECHO schemas created with Type.Obj() or Type.Relation()
61
+ * - JSON schema with typename and version
62
+ */
63
+ export type RegisterSchemaInput =
64
+ | Type.Entity.Any
65
+ | {
66
+ typename: string;
67
+ version: string;
68
+ jsonSchema: JsonSchema.JsonSchema;
69
+ /**
70
+ * Display name of the schema.
71
+ */
72
+ name?: string;
73
+ };
74
+
75
+ export type ExtractQueryResult<Query> = Query extends { location: ('database' | 'runtime')[] }
76
+ ? Type.Entity.Any
77
+ : Type.RuntimeType;
78
+
79
+ export interface SchemaRegistry {
80
+ /**
81
+ * Checks if the provided schema is registered.
82
+ */
83
+ // TODO(burdon): Type?
84
+ hasSchema(schema: Type.Entity.Any): boolean;
85
+
86
+ /**
87
+ * Registers the provided schema.
88
+ *
89
+ * @returns Mutable runtime instances of schemas that were registered.
90
+ *
91
+ * The behavior of this method depends on the state of the database.
92
+ * The general principle is that the schema will be upserted into the space.
93
+ * If an equivalent schema with the same name and version already exists, the method does nothing.
94
+ * If a different schema with the same name and version exists, the method throws an error.
95
+ * If no schema with the same name and version exists, a new schema will be inserted based on semantic versioning rules.
96
+ */
97
+ register(input: RegisterSchemaInput[]): Promise<Type.RuntimeType[]>;
98
+
99
+ /**
100
+ *
101
+ */
102
+ query<Q extends Types.NoExcessProperties<Query, Q>>(
103
+ query?: Q & Query,
104
+ ): QueryResult.QueryResult<ExtractQueryResult<Q>>;
105
+ }
package/src/Tag.ts ADDED
@@ -0,0 +1,40 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { LabelAnnotation, SystemTypeAnnotation } from './internal';
8
+ import * as Obj from './Obj';
9
+ import * as Type from './Type';
10
+
11
+ export const Tag = Schema.Struct({
12
+ label: Schema.String,
13
+ hue: Schema.optional(Schema.String), // TODO(burdon): Color name?
14
+ }).pipe(
15
+ Type.object({
16
+ typename: 'dxos.org/type/Tag',
17
+ version: '0.1.0',
18
+ }),
19
+ LabelAnnotation.set(['label']),
20
+ SystemTypeAnnotation.set(true),
21
+ );
22
+
23
+ export type Tag = Schema.Schema.Type<typeof Tag>;
24
+
25
+ export const make = (props: Obj.MakeProps<typeof Tag>) => Obj.make(Tag, props);
26
+
27
+ // TODO(burdon): Rename Map.
28
+ export type Map = Record<string, Tag>;
29
+
30
+ export const sortTags = ({ label: a }: Tag, { label: b }: Tag) => a.localeCompare(b);
31
+
32
+ export const createTagList = (tags: Map): Tag[] =>
33
+ Object.entries(tags)
34
+ .map(([id, tag]) => ({ ...tag, id }))
35
+ .sort(sortTags);
36
+
37
+ export const findTagByLabel = (tags: Map | undefined, name: string): Tag | undefined => {
38
+ const entry = Object.entries(tags ?? {}).find(([_, tag]) => tag.label.toLowerCase() === name.toLowerCase());
39
+ return entry ? { ...entry[1], id: entry[0] } : undefined;
40
+ };