@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
@@ -0,0 +1,528 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Array from 'effect/Array';
6
+ import * as Function from 'effect/Function';
7
+ import * as JSONSchema from 'effect/JSONSchema';
8
+ import * as Option from 'effect/Option';
9
+ import * as Schema from 'effect/Schema';
10
+ import * as SchemaAST from 'effect/SchemaAST';
11
+ import type * as Types from 'effect/Types';
12
+
13
+ import { raise } from '@dxos/debug';
14
+ import { mapAst } from '@dxos/effect';
15
+ import { assertArgument, invariant } from '@dxos/invariant';
16
+ import { DXN, ObjectId } from '@dxos/keys';
17
+ import { log } from '@dxos/log';
18
+ import { clearUndefined, orderKeys, removeProperties } from '@dxos/util';
19
+
20
+ import {
21
+ type TypeAnnotation,
22
+ TypeAnnotationId,
23
+ TypeIdentifierAnnotationId,
24
+ makeTypeJsonSchemaAnnotation,
25
+ } from '../annotations';
26
+ import { type JsonSchemaReferenceInfo, createEchoReferenceSchema } from '../ref';
27
+ import { ANY_OBJECT_TYPENAME, ANY_OBJECT_VERSION, EntityKind, EntityKindSchema } from '../types';
28
+
29
+ import { CustomAnnotations, DecodedAnnotations, EchoAnnotations } from './annotations';
30
+ import {
31
+ ECHO_ANNOTATIONS_NS_DEPRECATED_KEY,
32
+ ECHO_ANNOTATIONS_NS_KEY,
33
+ type JsonSchemaEchoAnnotations,
34
+ type JsonSchemaType,
35
+ getNormalizedEchoAnnotations,
36
+ } from './json-schema-type';
37
+
38
+ // TODO(burdon): Are these values stored (can they be changed?)
39
+ export enum PropType {
40
+ NONE = 0,
41
+ STRING = 1, // TODO(burdon): vs TEXT?
42
+ NUMBER = 2,
43
+ BOOLEAN = 3,
44
+ DATE = 4,
45
+ REF = 5,
46
+ RECORD = 6,
47
+ ENUM = 7,
48
+ }
49
+
50
+ // TODO(burdon): Reconcile with @dxos/schema.
51
+ export const toPropType = (type?: PropType): string => {
52
+ switch (type) {
53
+ case PropType.STRING:
54
+ return 'string';
55
+ case PropType.NUMBER:
56
+ return 'number';
57
+ case PropType.BOOLEAN:
58
+ return 'boolean';
59
+ case PropType.DATE:
60
+ return 'date';
61
+ case PropType.REF:
62
+ return 'ref';
63
+ case PropType.RECORD:
64
+ return 'object';
65
+ default:
66
+ throw new Error(`Invalid type: ${type}`);
67
+ }
68
+ };
69
+
70
+ const JSON_SCHEMA_URL = 'http://json-schema.org/draft-07/schema#';
71
+
72
+ export type JsonSchemaOptions = {
73
+ strict?: boolean;
74
+ };
75
+
76
+ /**
77
+ * Convert effect schema to JSON Schema.
78
+ * NOTE: This handles custom annotations.
79
+ * @param schema
80
+ */
81
+ // TODO(burdon): Reconcile with possibly extending @effect/Schema/JSONSchema
82
+ // We add additional propertyOrder (but the object properties ARE ordered); and type "string" for literals.
83
+ export const toJsonSchema = (schema: Schema.Schema.All, options: JsonSchemaOptions = {}): JsonSchemaType => {
84
+ assertArgument(Schema.isSchema(schema), 'schema');
85
+ let jsonSchema = _toJsonSchemaAST(schema.ast);
86
+ if (options.strict) {
87
+ // TOOD(burdon): Workaround to ensure JSON schema is valid (for agv parsing).
88
+ jsonSchema = removeProperties(jsonSchema, (key, value) => {
89
+ if (key === '$id' && value === '/schemas/any') {
90
+ return true;
91
+ }
92
+ if (key === '$ref' && value === '#/$defs/dependency') {
93
+ return true;
94
+ }
95
+ if (key === '$ref' && value === '#/$defs/jsonSchema') {
96
+ return true;
97
+ }
98
+
99
+ return false;
100
+ });
101
+ }
102
+
103
+ return jsonSchema;
104
+ };
105
+
106
+ const _toJsonSchemaAST = (ast: SchemaAST.AST): JsonSchemaType => {
107
+ const withRefinements = withEchoRefinements(ast, '#');
108
+ const jsonSchema = JSONSchema.fromAST(withRefinements, {
109
+ definitions: {},
110
+ }) as JsonSchemaType;
111
+
112
+ return normalizeJsonSchema(jsonSchema);
113
+ };
114
+
115
+ const withEchoRefinements = (
116
+ ast: SchemaAST.AST,
117
+ path: string | undefined,
118
+ suspendCache = new Map<SchemaAST.AST, string>(),
119
+ ): SchemaAST.AST => {
120
+ if (path) {
121
+ suspendCache.set(ast, path);
122
+ }
123
+
124
+ let recursiveResult: SchemaAST.AST;
125
+ if (SchemaAST.isSuspend(ast)) {
126
+ // Precompute JSON schema for suspended AST since effect serializer does not support it.
127
+ const suspendedAst = ast.f();
128
+ const cachedPath = suspendCache.get(suspendedAst);
129
+ if (cachedPath) {
130
+ recursiveResult = new SchemaAST.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {
131
+ [SchemaAST.JSONSchemaAnnotationId]: {
132
+ $ref: cachedPath,
133
+ },
134
+ });
135
+ } else {
136
+ const jsonSchema = _toJsonSchemaAST(suspendedAst);
137
+ recursiveResult = new SchemaAST.Suspend(() => withEchoRefinements(suspendedAst, path, suspendCache), {
138
+ [SchemaAST.JSONSchemaAnnotationId]: jsonSchema,
139
+ });
140
+ }
141
+ } else if (SchemaAST.isTypeLiteral(ast)) {
142
+ // Add property order annotations
143
+ recursiveResult = mapAst(ast, (ast, key) =>
144
+ withEchoRefinements(ast, path && typeof key === 'string' ? `${path}/${key}` : undefined, suspendCache),
145
+ );
146
+ recursiveResult = addJsonSchemaFields(recursiveResult, {
147
+ propertyOrder: [...ast.propertySignatures.map((p) => p.name)] as string[],
148
+ });
149
+ } else if (SchemaAST.isUndefinedKeyword(ast)) {
150
+ // Ignore undefined keyword that appears in the optional fields.
151
+ return ast;
152
+ } else {
153
+ recursiveResult = mapAst(ast, (ast, key) =>
154
+ withEchoRefinements(
155
+ ast,
156
+ path && (typeof key === 'string' || typeof key === 'number') ? `${path}/${key}` : undefined,
157
+ suspendCache,
158
+ ),
159
+ );
160
+ }
161
+
162
+ const annotationFields = annotations_toJsonSchemaFields(ast.annotations);
163
+ if (Object.keys(annotationFields).length === 0) {
164
+ return recursiveResult;
165
+ } else {
166
+ return addJsonSchemaFields(recursiveResult, annotationFields);
167
+ }
168
+ };
169
+
170
+ /**
171
+ * Convert JSON schema to effect schema.
172
+ * @param root
173
+ * @param definitions
174
+ */
175
+ export const toEffectSchema = (root: JsonSchemaType, _defs?: JsonSchemaType['$defs']): Schema.Schema.AnyNoContext => {
176
+ const defs = root.$defs ? { ..._defs, ...root.$defs } : (_defs ?? {});
177
+ if ('type' in root && root.type === 'object') {
178
+ return objectToEffectSchema(root, defs);
179
+ }
180
+
181
+ let result: Schema.Schema.AnyNoContext = Schema.Unknown;
182
+ if ('$ref' in root) {
183
+ switch (root.$ref) {
184
+ case '/schemas/echo/ref': {
185
+ result = refToEffectSchema(root);
186
+ break;
187
+ }
188
+ }
189
+ } else if ('$id' in root) {
190
+ switch (root.$id as string) {
191
+ case '/schemas/any': {
192
+ result = anyToEffectSchema(root as JSONSchema.JsonSchema7Any);
193
+ break;
194
+ }
195
+ case '/schemas/unknown': {
196
+ result = Schema.Unknown;
197
+ break;
198
+ }
199
+ case '/schemas/{}':
200
+ case '/schemas/object': {
201
+ result = Schema.Object;
202
+ break;
203
+ }
204
+ // Custom ECHO object reference.
205
+ case '/schemas/echo/ref': {
206
+ result = refToEffectSchema(root);
207
+ break;
208
+ }
209
+ }
210
+ } else if ('enum' in root) {
211
+ result = Schema.Union(...root.enum!.map((e) => Schema.Literal(e)));
212
+ } else if ('oneOf' in root) {
213
+ result = Schema.Union(...root.oneOf!.map((v) => toEffectSchema(v, defs)));
214
+ } else if ('anyOf' in root) {
215
+ result = Schema.Union(...root.anyOf!.map((v) => toEffectSchema(v, defs)));
216
+ } else if ('allOf' in root) {
217
+ if (root.allOf!.length === 1) {
218
+ result = toEffectSchema(root.allOf![0], defs);
219
+ } else {
220
+ log.warn('allOf with multiple schemas is not supported');
221
+ result = Schema.Unknown;
222
+ }
223
+ } else if ('type' in root) {
224
+ switch (root.type) {
225
+ case 'string': {
226
+ result = Schema.String;
227
+ if (root.pattern) {
228
+ result = result.pipe(Schema.pattern(new RegExp(root.pattern)));
229
+ }
230
+ break;
231
+ }
232
+ case 'number': {
233
+ result = Schema.Number;
234
+ break;
235
+ }
236
+ case 'integer': {
237
+ result = Schema.Number.pipe(Schema.int());
238
+ break;
239
+ }
240
+ case 'boolean': {
241
+ result = Schema.Boolean;
242
+ break;
243
+ }
244
+ case 'array': {
245
+ if (Array.isArray(root.items)) {
246
+ const [required, optional] = Function.pipe(
247
+ root.items,
248
+ Array.map((v) => toEffectSchema(v as JsonSchemaType, defs)),
249
+ Array.splitAt(root.minItems ?? root.items.length),
250
+ );
251
+ result = Schema.Tuple(...required, ...optional.map(Schema.optionalElement));
252
+ } else {
253
+ invariant(root.items);
254
+ const items = root.items;
255
+ result = Array.isArray(items)
256
+ ? Schema.Tuple(...items.map((v) => toEffectSchema(v as JsonSchemaType, defs)))
257
+ : Schema.Array(toEffectSchema(items as JsonSchemaType, defs));
258
+ }
259
+ break;
260
+ }
261
+ case 'null': {
262
+ result = Schema.Null;
263
+ break;
264
+ }
265
+ }
266
+ } else if ('$ref' in root) {
267
+ const refSegments = root.$ref!.split('/');
268
+ const jsonSchema = defs[refSegments[refSegments.length - 1]];
269
+ invariant(jsonSchema, `missing definition for ${root.$ref}`);
270
+ result = toEffectSchema(jsonSchema, defs).pipe(
271
+ Schema.annotations({ identifier: refSegments[refSegments.length - 1] }),
272
+ );
273
+ }
274
+
275
+ const annotations = jsonSchemaFieldsToAnnotations(root);
276
+
277
+ // log.info('toEffectSchema', { root, annotations });
278
+ result = result.annotations(annotations);
279
+
280
+ return result;
281
+ };
282
+
283
+ const objectToEffectSchema = (root: JsonSchemaType, defs: JsonSchemaType['$defs']): Schema.Schema.AnyNoContext => {
284
+ invariant('type' in root && root.type === 'object', `not an object: ${root}`);
285
+
286
+ const echoRefinement: JsonSchemaEchoAnnotations = (root as any)[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
287
+ const isEchoObject =
288
+ echoRefinement != null || ('$id' in root && typeof root.$id === 'string' && root.$id.startsWith('dxn:'));
289
+
290
+ let fields: Schema.Struct.Fields = {};
291
+ const propertyList = Object.entries(root.properties ?? {});
292
+ let immutableIdField: Schema.Schema.AnyNoContext | undefined;
293
+ for (const [key, value] of propertyList) {
294
+ if (isEchoObject && key === 'id') {
295
+ immutableIdField = toEffectSchema(value, defs);
296
+ } else {
297
+ // TODO(burdon): Mutable cast.
298
+ (fields as any)[key] = root.required?.includes(key)
299
+ ? toEffectSchema(value, defs)
300
+ : Schema.optional(toEffectSchema(value, defs));
301
+ }
302
+ }
303
+
304
+ if (root.propertyOrder) {
305
+ fields = orderKeys(fields, root.propertyOrder as any);
306
+ }
307
+
308
+ let schema: Schema.Schema<any, any, unknown>;
309
+ if (root.patternProperties) {
310
+ invariant(propertyList.length === 0, 'pattern properties mixed with regular properties are not supported');
311
+ invariant(
312
+ Object.keys(root.patternProperties).length === 1 && Object.keys(root.patternProperties)[0] === '',
313
+ 'only one pattern property is supported',
314
+ );
315
+
316
+ schema = Schema.Record({ key: Schema.String, value: toEffectSchema(root.patternProperties[''], defs) });
317
+ } else if (typeof root.additionalProperties !== 'object') {
318
+ schema = Schema.Struct(fields);
319
+ } else {
320
+ const indexValue = toEffectSchema(root.additionalProperties, defs);
321
+ if (propertyList.length > 0) {
322
+ schema = Schema.Struct(fields, { key: Schema.String, value: indexValue });
323
+ } else {
324
+ schema = Schema.Record({ key: Schema.String, value: indexValue });
325
+ }
326
+ }
327
+
328
+ if (immutableIdField) {
329
+ schema = Schema.extend(Schema.mutable(schema), Schema.Struct({ id: immutableIdField }));
330
+ }
331
+
332
+ const annotations = jsonSchemaFieldsToAnnotations(root);
333
+ return schema.annotations(annotations) as any;
334
+ };
335
+
336
+ const anyToEffectSchema = (root: JSONSchema.JsonSchema7Any): Schema.Schema.AnyNoContext => {
337
+ const echoRefinement: JsonSchemaEchoAnnotations = (root as any)[ECHO_ANNOTATIONS_NS_DEPRECATED_KEY];
338
+ // TODO(dmaretskyi): Is this branch still taken?
339
+ if ((echoRefinement as any)?.reference != null) {
340
+ const echoId = root.$id.startsWith('dxn:echo:') ? root.$id : undefined;
341
+ return createEchoReferenceSchema(
342
+ echoId,
343
+ (echoRefinement as any).reference.typename,
344
+ (echoRefinement as any).reference.version,
345
+ );
346
+ }
347
+
348
+ return Schema.Any;
349
+ };
350
+
351
+ // TODO(dmaretskyi): Types.
352
+ const refToEffectSchema = (root: any): Schema.Schema.AnyNoContext => {
353
+ if (!('reference' in root)) {
354
+ // Fallback to generic object ref when no reference info is provided.
355
+ return createEchoReferenceSchema(undefined, ANY_OBJECT_TYPENAME, ANY_OBJECT_VERSION);
356
+ }
357
+
358
+ const reference: JsonSchemaReferenceInfo = root.reference;
359
+ if (typeof reference !== 'object') {
360
+ throw new Error('Invalid reference field in ref schema');
361
+ }
362
+
363
+ const targetSchemaDXN = DXN.parse(reference.schema.$ref);
364
+ invariant(targetSchemaDXN.kind === DXN.kind.TYPE);
365
+
366
+ return createEchoReferenceSchema(
367
+ targetSchemaDXN.toString(),
368
+ targetSchemaDXN.kind === DXN.kind.TYPE ? targetSchemaDXN.parts[0] : undefined,
369
+ reference.schemaVersion,
370
+ );
371
+ };
372
+
373
+ //
374
+ // Annotations
375
+ //
376
+
377
+ const annotations_toJsonSchemaFields = (annotations: SchemaAST.Annotations): Record<symbol, any> => {
378
+ const schemaFields: Record<string, any> = {};
379
+
380
+ const echoAnnotations: JsonSchemaEchoAnnotations = {};
381
+ for (const [key, annotationId] of Object.entries(EchoAnnotations)) {
382
+ if (annotations[annotationId] != null) {
383
+ echoAnnotations[key as keyof JsonSchemaEchoAnnotations] = annotations[annotationId] as any;
384
+ }
385
+ }
386
+ if (Object.keys(echoAnnotations).length > 0) {
387
+ // TODO(dmaretskyi): use new namespace.
388
+ schemaFields[ECHO_ANNOTATIONS_NS_KEY] = echoAnnotations;
389
+ }
390
+
391
+ const echoIdentifier = annotations[TypeIdentifierAnnotationId];
392
+ if (echoIdentifier) {
393
+ schemaFields[ECHO_ANNOTATIONS_NS_KEY] ??= {};
394
+ schemaFields[ECHO_ANNOTATIONS_NS_KEY].schemaId = echoIdentifier;
395
+ }
396
+
397
+ // Custom (at end).
398
+ for (const [key, annotationId] of Object.entries(CustomAnnotations)) {
399
+ const value = annotations[annotationId];
400
+ if (value != null) {
401
+ schemaFields[key] = value;
402
+ }
403
+ }
404
+
405
+ return schemaFields;
406
+ };
407
+
408
+ const decodeTypeIdentifierAnnotation = (schema: JsonSchemaType): string | undefined => {
409
+ // Limit to dxn:echo: URIs.
410
+ if (schema.$id && schema.$id.startsWith('dxn:echo:')) {
411
+ return schema.$id;
412
+ } else if (schema.$id && schema.$id.startsWith('dxn:type:') && schema?.echo?.type?.schemaId) {
413
+ const id = schema?.echo?.type?.schemaId;
414
+ if (ObjectId.isValid(id)) {
415
+ return DXN.fromLocalObjectId(id).toString();
416
+ }
417
+ }
418
+ return undefined;
419
+ };
420
+
421
+ const decodeTypeAnnotation = (schema: JsonSchemaType): TypeAnnotation | undefined => {
422
+ if (schema.typename) {
423
+ const annotation: Types.Mutable<TypeAnnotation> = {
424
+ // TODO(dmaretskyi): Decoding default.
425
+ kind: schema.entityKind ? Schema.decodeSync(EntityKindSchema)(schema.entityKind) : EntityKind.Object,
426
+ typename: schema.typename,
427
+ version: schema.version ?? '0.1.0',
428
+ };
429
+
430
+ if (annotation.kind === EntityKind.Relation) {
431
+ const source = schema.relationSource?.$ref ?? raise(new Error('Relation source not set'));
432
+ const target = schema.relationTarget?.$ref ?? raise(new Error('Relation target not set'));
433
+ annotation.sourceSchema = DXN.parse(source).toString();
434
+ annotation.targetSchema = DXN.parse(target).toString();
435
+ }
436
+
437
+ return annotation;
438
+ }
439
+
440
+ // Decode legacy schema.
441
+ if (!schema.typename && schema?.echo?.type) {
442
+ return {
443
+ kind: EntityKind.Object,
444
+ typename: schema.echo.type.typename,
445
+ version: schema.echo.type.version,
446
+ };
447
+ }
448
+
449
+ return undefined;
450
+ };
451
+
452
+ const jsonSchemaFieldsToAnnotations = (schema: JsonSchemaType): SchemaAST.Annotations => {
453
+ const annotations: Types.Mutable<Schema.Annotations.Schema<any>> = {};
454
+
455
+ const echoAnnotations: JsonSchemaEchoAnnotations = getNormalizedEchoAnnotations(schema) ?? {};
456
+ if (echoAnnotations) {
457
+ for (const [key, annotationId] of Object.entries(EchoAnnotations)) {
458
+ if (echoAnnotations[key as keyof JsonSchemaEchoAnnotations]) {
459
+ annotations[annotationId] = echoAnnotations[key as keyof JsonSchemaEchoAnnotations];
460
+ }
461
+ }
462
+ }
463
+
464
+ annotations[TypeIdentifierAnnotationId] = decodeTypeIdentifierAnnotation(schema);
465
+ const typeAnnotation = decodeTypeAnnotation(schema);
466
+ if (typeAnnotation) {
467
+ annotations[TypeAnnotationId] = typeAnnotation;
468
+ annotations[SchemaAST.JSONSchemaAnnotationId] = makeTypeJsonSchemaAnnotation({
469
+ kind: typeAnnotation.kind,
470
+ typename: typeAnnotation.typename,
471
+ version: typeAnnotation.version,
472
+ relationSource: typeAnnotation.sourceSchema,
473
+ relationTarget: typeAnnotation.targetSchema,
474
+ });
475
+ }
476
+
477
+ // Custom (at end).
478
+ for (const [key, annotationId] of Object.entries({ ...CustomAnnotations, ...DecodedAnnotations })) {
479
+ if (key in schema) {
480
+ annotations[annotationId] = (schema as any)[key];
481
+ }
482
+ }
483
+
484
+ return clearUndefined(annotations);
485
+ };
486
+
487
+ const makeAnnotatedRefinement = (ast: SchemaAST.AST, annotations: SchemaAST.Annotations): SchemaAST.Refinement => {
488
+ return new SchemaAST.Refinement(ast, () => Option.none(), annotations);
489
+ };
490
+
491
+ const addJsonSchemaFields = (ast: SchemaAST.AST, schema: JsonSchemaType): SchemaAST.AST =>
492
+ makeAnnotatedRefinement(ast, { [SchemaAST.JSONSchemaAnnotationId]: schema });
493
+
494
+ /**
495
+ * Fixes field order.
496
+ * Sets `$schema` prop.
497
+ */
498
+ const normalizeJsonSchema = (jsonSchema: JsonSchemaType): JsonSchemaType => {
499
+ if (jsonSchema.properties && 'id' in jsonSchema.properties) {
500
+ jsonSchema.properties = orderKeys(jsonSchema.properties, ['id']); // Put id first.
501
+ }
502
+
503
+ // TODO(dmaretskyi): Makes sure undefined is not left on optional fields for the resulting object.
504
+ jsonSchema.$schema = JSON_SCHEMA_URL;
505
+ jsonSchema = orderKeys(jsonSchema, [
506
+ '$schema',
507
+ '$id',
508
+
509
+ 'entityKind',
510
+ 'typename',
511
+ 'version',
512
+ 'relationTarget',
513
+ 'relationSource',
514
+
515
+ 'type',
516
+ 'enum',
517
+
518
+ 'properties',
519
+ 'required',
520
+ 'propertyOrder', // Custom.
521
+ 'items',
522
+ 'additionalProperties',
523
+
524
+ 'anyOf',
525
+ 'oneOf',
526
+ ]);
527
+ return jsonSchema;
528
+ };
@@ -0,0 +1,48 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { invariant } from '@dxos/invariant';
6
+ import { deepMapValues } from '@dxos/util';
7
+
8
+ import type * as Obj from '../../Obj';
9
+ import { makeObject } from '../proxy';
10
+ import { Ref } from '../ref';
11
+ import { getMeta, getSchema } from '../types';
12
+
13
+ /**
14
+ * Clones an object or relation.
15
+ * This does not clone referenced objects, only the properties in the object.
16
+ * @returns A new object with the same schema and properties.
17
+ */
18
+ export const clone = <T extends Obj.Any>(obj: T, opts?: Obj.CloneOptions): T => {
19
+ const { id, ...data } = obj;
20
+ const schema = getSchema(obj);
21
+ invariant(schema != null, 'Object should have a schema');
22
+ const props: any = deepMapValues(data, (value, recurse) => {
23
+ if (Ref.isRef(value)) {
24
+ if (opts?.deep) {
25
+ // TODO(dmaretskyi): Will break on circular references.
26
+ return Ref.make(clone(value.target!, opts));
27
+ }
28
+ return value;
29
+ }
30
+ return recurse(value);
31
+ });
32
+
33
+ if (opts?.retainId) {
34
+ props.id = id;
35
+ }
36
+ const meta = deepMapValues(getMeta(obj), (value, recurse) => {
37
+ if (Ref.isRef(value)) {
38
+ if (opts?.deep) {
39
+ // TODO(dmaretskyi): Will break on circular references.
40
+ return Ref.make(clone(value.target!, opts));
41
+ }
42
+ return value;
43
+ }
44
+ return recurse(value);
45
+ });
46
+
47
+ return makeObject(schema, props, meta);
48
+ };
@@ -0,0 +1,75 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { getTypename } from '../annotations';
8
+ import { type AnyProperties } from '../types';
9
+
10
+ // TODO(dmaretskyi): Rename to represent commonality between objects and relations (e.g. `entity`).
11
+ export type TypedObjectOptions = {
12
+ // TODO(burdon): Document.
13
+ partial?: true;
14
+ // TODO(burdon): Document.
15
+ record?: true;
16
+ };
17
+
18
+ /**
19
+ *
20
+ */
21
+ // TODO(burdon): Comment required.
22
+ // TODO(dmaretskyi): Rename to represent commonality between objects and relations (e.g. `entity`).
23
+ type SimplifiedSchemaFields<
24
+ SchemaFields extends Schema.Struct.Fields,
25
+ Options extends TypedObjectOptions,
26
+ > = Options['partial'] extends boolean
27
+ ? Schema.SimplifyMutable<Partial<Schema.Struct.Type<SchemaFields>>>
28
+ : Schema.SimplifyMutable<Schema.Struct.Type<SchemaFields>>;
29
+
30
+ /**
31
+ *
32
+ */
33
+ // TODO(burdon): Comment required.
34
+ // TODO(dmaretskyi): Rename to represent commonality between objects and relations (e.g. `entity`).
35
+ export type TypedObjectFields<
36
+ SchemaFields extends Schema.Struct.Fields,
37
+ Options extends TypedObjectOptions,
38
+ > = SimplifiedSchemaFields<SchemaFields, Options> & { id: string } & (Options['record'] extends boolean
39
+ ? Schema.SimplifyMutable<Schema.IndexSignature.Type<Schema.IndexSignature.Records>>
40
+ : {});
41
+
42
+ export const makeTypedEntityClass = (
43
+ typename: string,
44
+ version: string,
45
+ baseSchema: Schema.Schema.AnyNoContext,
46
+ ): Schema.SchemaClass<any> => {
47
+ return class {
48
+ // Implement TypedObject properties.
49
+ static readonly typename = typename;
50
+ static readonly version = version;
51
+
52
+ // Implement Schema.Schema properties.
53
+ // TODO(burdon): Comment required.
54
+ static readonly [Schema.TypeId] = schemaVariance;
55
+ static readonly ast = baseSchema.ast;
56
+ static readonly annotations = baseSchema.annotations.bind(baseSchema);
57
+ static readonly pipe = baseSchema.pipe.bind(baseSchema);
58
+
59
+ // TODO(burdon): Comment required.
60
+ static [Symbol.hasInstance](obj: AnyProperties) {
61
+ return obj != null && getTypename(obj) === typename;
62
+ }
63
+
64
+ // TODO(burdon): Throw APIError.
65
+ private constructor() {
66
+ throw new Error('Use live(Typename, { ...fields }) to instantiate an object.');
67
+ }
68
+ } as any;
69
+ };
70
+
71
+ const schemaVariance = {
72
+ _A: (_: any) => _,
73
+ _I: (_: any) => _,
74
+ _R: (_: never) => _,
75
+ };