@dxos/echo 0.8.4-main.3c1ae3b → 0.8.4-main.3eb6e50203

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 (452) hide show
  1. package/README.md +1 -2
  2. package/dist/lib/neutral/Annotation.mjs +35 -0
  3. package/dist/lib/neutral/Database.mjs +45 -0
  4. package/dist/lib/neutral/Entity.mjs +51 -0
  5. package/dist/lib/{browser → neutral}/Err.mjs +4 -3
  6. package/dist/lib/{browser → neutral}/Filter.mjs +9 -8
  7. package/dist/lib/{browser → neutral}/Format.mjs +4 -5
  8. package/dist/lib/neutral/JsonSchema.mjs +19 -0
  9. package/dist/lib/{browser → neutral}/Key.mjs +2 -3
  10. package/dist/lib/{node-esm → neutral}/Obj.mjs +40 -19
  11. package/dist/lib/neutral/Order.mjs +12 -0
  12. package/dist/lib/neutral/Query.mjs +26 -0
  13. package/dist/lib/neutral/QueryResult.mjs +2 -0
  14. package/dist/lib/neutral/Ref.mjs +22 -0
  15. package/dist/lib/neutral/Relation.mjs +84 -0
  16. package/dist/lib/neutral/SchemaRegistry.mjs +2 -0
  17. package/dist/lib/neutral/Tag.mjs +25 -0
  18. package/dist/lib/neutral/Type.mjs +47 -0
  19. package/dist/lib/{browser/chunk-FGFQWIZE.mjs → neutral/chunk-4L6DOFXP.mjs} +1 -3
  20. package/dist/lib/neutral/chunk-4L6DOFXP.mjs.map +7 -0
  21. package/dist/lib/{browser/chunk-RP4JV7FD.mjs → neutral/chunk-7WE7SBA2.mjs} +4 -5
  22. package/dist/lib/neutral/chunk-7WE7SBA2.mjs.map +7 -0
  23. package/dist/lib/neutral/chunk-7YWDDFPH.mjs +251 -0
  24. package/dist/lib/neutral/chunk-7YWDDFPH.mjs.map +7 -0
  25. package/dist/lib/{browser/chunk-INHXFXY5.mjs → neutral/chunk-ANHVGJI4.mjs} +2 -3
  26. package/dist/lib/{node-esm/chunk-AJEMYSIR.mjs.map → neutral/chunk-ANHVGJI4.mjs.map} +1 -1
  27. package/dist/lib/neutral/chunk-B4FLOYG7.mjs +130 -0
  28. package/dist/lib/neutral/chunk-B4FLOYG7.mjs.map +7 -0
  29. package/dist/lib/{browser/chunk-O6FOICWT.mjs → neutral/chunk-EXAYCLIM.mjs} +8 -9
  30. package/dist/lib/neutral/chunk-EXAYCLIM.mjs.map +7 -0
  31. package/dist/lib/{browser/chunk-V7TON6BX.mjs → neutral/chunk-F6BTBXL7.mjs} +28 -8
  32. package/dist/lib/neutral/chunk-F6BTBXL7.mjs.map +7 -0
  33. package/dist/lib/neutral/chunk-HQXQWXLH.mjs +269 -0
  34. package/dist/lib/neutral/chunk-HQXQWXLH.mjs.map +7 -0
  35. package/dist/lib/{browser/chunk-CGS2ULMK.mjs → neutral/chunk-J5LGTIGS.mjs} +1 -2
  36. package/dist/lib/{node-esm/chunk-NHYOREKX.mjs → neutral/chunk-KB7RIVLK.mjs} +11 -6
  37. package/dist/lib/neutral/chunk-KB7RIVLK.mjs.map +7 -0
  38. package/dist/lib/neutral/chunk-MXQJZCPY.mjs +51 -0
  39. package/dist/lib/neutral/chunk-MXQJZCPY.mjs.map +7 -0
  40. package/dist/lib/{browser/chunk-3B2G6BW4.mjs → neutral/chunk-N2QNHMT5.mjs} +3 -4
  41. package/dist/lib/{browser/chunk-3B2G6BW4.mjs.map → neutral/chunk-N2QNHMT5.mjs.map} +1 -1
  42. package/dist/lib/{browser/chunk-JG4GH6LN.mjs → neutral/chunk-OMUPQMLR.mjs} +1 -3
  43. package/dist/lib/neutral/chunk-OMUPQMLR.mjs.map +7 -0
  44. package/dist/lib/{browser/chunk-AGOWBKY6.mjs → neutral/chunk-RCBBZLVM.mjs} +61 -13
  45. package/dist/lib/neutral/chunk-RCBBZLVM.mjs.map +7 -0
  46. package/dist/lib/{node-esm/chunk-6OTQZKHX.mjs → neutral/chunk-RIMHNJ3E.mjs} +30 -37
  47. package/dist/lib/neutral/chunk-RIMHNJ3E.mjs.map +7 -0
  48. package/dist/lib/{node-esm/chunk-BYL2NPEA.mjs → neutral/chunk-ROKO4RKJ.mjs} +9 -4
  49. package/dist/lib/{node-esm/chunk-BYL2NPEA.mjs.map → neutral/chunk-ROKO4RKJ.mjs.map} +3 -3
  50. package/dist/lib/{browser/chunk-ESLW4N7S.mjs → neutral/chunk-TMLVKIMX.mjs} +3 -4
  51. package/dist/lib/neutral/chunk-TMLVKIMX.mjs.map +7 -0
  52. package/dist/lib/{browser/chunk-P2B4BASR.mjs → neutral/chunk-UMECVTXM.mjs} +4 -5
  53. package/dist/lib/{node-esm/chunk-LDXRA5TC.mjs.map → neutral/chunk-UMECVTXM.mjs.map} +1 -1
  54. package/dist/lib/{browser/chunk-6XVZF5VJ.mjs → neutral/chunk-VJ2H5MOJ.mjs} +1991 -1010
  55. package/dist/lib/neutral/chunk-VJ2H5MOJ.mjs.map +7 -0
  56. package/dist/lib/{browser/chunk-5IN7XBIQ.mjs → neutral/chunk-VYEWMV5U.mjs} +3 -4
  57. package/dist/lib/{browser/chunk-5IN7XBIQ.mjs.map → neutral/chunk-VYEWMV5U.mjs.map} +1 -1
  58. package/dist/lib/{browser/chunk-MYCCGG2T.mjs → neutral/chunk-X2MPMYYN.mjs} +1 -3
  59. package/dist/lib/{browser/chunk-MYCCGG2T.mjs.map → neutral/chunk-X2MPMYYN.mjs.map} +1 -1
  60. package/dist/lib/{browser/chunk-ZIM3Y4ZK.mjs → neutral/chunk-XAJMXQ4H.mjs} +17 -12
  61. package/dist/lib/neutral/chunk-XAJMXQ4H.mjs.map +7 -0
  62. package/dist/lib/neutral/chunk-YPIP3WGI.mjs +97 -0
  63. package/dist/lib/neutral/chunk-YPIP3WGI.mjs.map +7 -0
  64. package/dist/lib/{browser → neutral}/index.mjs +27 -28
  65. package/dist/lib/{node-esm → neutral}/internal/index.mjs +141 -26
  66. package/dist/lib/neutral/meta.json +1 -0
  67. package/dist/lib/{browser → neutral}/testing/index.mjs +67 -61
  68. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  69. package/dist/types/src/Annotation.d.ts +23 -1
  70. package/dist/types/src/Annotation.d.ts.map +1 -1
  71. package/dist/types/src/Database.d.ts +90 -53
  72. package/dist/types/src/Database.d.ts.map +1 -1
  73. package/dist/types/src/Entity.d.ts +111 -5
  74. package/dist/types/src/Entity.d.ts.map +1 -1
  75. package/dist/types/src/Entity.test.d.ts +2 -0
  76. package/dist/types/src/Entity.test.d.ts.map +1 -0
  77. package/dist/types/src/Err.d.ts +55 -16
  78. package/dist/types/src/Err.d.ts.map +1 -1
  79. package/dist/types/src/Obj.d.ts +348 -76
  80. package/dist/types/src/Obj.d.ts.map +1 -1
  81. package/dist/types/src/Obj.test.d.ts +2 -0
  82. package/dist/types/src/Obj.test.d.ts.map +1 -0
  83. package/dist/types/src/Order.d.ts +5 -0
  84. package/dist/types/src/Order.d.ts.map +1 -1
  85. package/dist/types/src/Query.d.ts +21 -3
  86. package/dist/types/src/Query.d.ts.map +1 -1
  87. package/dist/types/src/QueryResult.d.ts +0 -4
  88. package/dist/types/src/QueryResult.d.ts.map +1 -1
  89. package/dist/types/src/Ref.d.ts +7 -7
  90. package/dist/types/src/Ref.d.ts.map +1 -1
  91. package/dist/types/src/Relation.d.ts +236 -19
  92. package/dist/types/src/Relation.d.ts.map +1 -1
  93. package/dist/types/src/Relation.test.d.ts +2 -0
  94. package/dist/types/src/Relation.test.d.ts.map +1 -0
  95. package/dist/types/src/SchemaRegistry.d.ts +11 -0
  96. package/dist/types/src/SchemaRegistry.d.ts.map +1 -1
  97. package/dist/types/src/Tag.d.ts +6 -6
  98. package/dist/types/src/Tag.d.ts.map +1 -1
  99. package/dist/types/src/Type.d.ts +213 -50
  100. package/dist/types/src/Type.d.ts.map +1 -1
  101. package/dist/types/src/Type.test.d.ts +2 -0
  102. package/dist/types/src/Type.test.d.ts.map +1 -0
  103. package/dist/types/src/hierarchy.test.d.ts +2 -0
  104. package/dist/types/src/hierarchy.test.d.ts.map +1 -0
  105. package/dist/types/src/internal/annotations/annotations.d.ts +24 -26
  106. package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -1
  107. package/dist/types/src/internal/annotations/util.d.ts +12 -0
  108. package/dist/types/src/internal/annotations/util.d.ts.map +1 -1
  109. package/dist/types/src/internal/api/annotations.d.ts +23 -0
  110. package/dist/types/src/internal/api/annotations.d.ts.map +1 -0
  111. package/dist/types/src/internal/api/entity.d.ts +13 -0
  112. package/dist/types/src/internal/api/entity.d.ts.map +1 -0
  113. package/dist/types/src/internal/api/index.d.ts +15 -0
  114. package/dist/types/src/internal/api/index.d.ts.map +1 -0
  115. package/dist/types/src/internal/api/meta.d.ts +42 -0
  116. package/dist/types/src/internal/api/meta.d.ts.map +1 -0
  117. package/dist/types/src/internal/api/sorting.d.ts +24 -0
  118. package/dist/types/src/internal/api/sorting.d.ts.map +1 -0
  119. package/dist/types/src/internal/api/version.d.ts +42 -0
  120. package/dist/types/src/internal/api/version.d.ts.map +1 -0
  121. package/dist/types/src/internal/entities/entity.d.ts +13 -3
  122. package/dist/types/src/internal/entities/entity.d.ts.map +1 -1
  123. package/dist/types/src/internal/entities/index.d.ts +1 -1
  124. package/dist/types/src/internal/entities/index.d.ts.map +1 -1
  125. package/dist/types/src/internal/entities/model.d.ts +17 -8
  126. package/dist/types/src/internal/entities/model.d.ts.map +1 -1
  127. package/dist/types/src/internal/entities/object.d.ts +8 -1
  128. package/dist/types/src/internal/entities/object.d.ts.map +1 -1
  129. package/dist/types/src/internal/entities/relation.d.ts +8 -1
  130. package/dist/types/src/internal/entities/relation.d.ts.map +1 -1
  131. package/dist/types/src/internal/formats/select.d.ts +2 -2
  132. package/dist/types/src/internal/formats/select.d.ts.map +1 -1
  133. package/dist/types/src/internal/index.d.ts +2 -1
  134. package/dist/types/src/internal/index.d.ts.map +1 -1
  135. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +1 -1
  136. package/dist/types/src/internal/json-schema/json-schema-type.d.ts +130 -29
  137. package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -1
  138. package/dist/types/src/internal/json-schema/json-schema.d.ts +2 -1
  139. package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -1
  140. package/dist/types/src/internal/object/clone.d.ts +8 -0
  141. package/dist/types/src/internal/object/clone.d.ts.map +1 -0
  142. package/dist/types/src/internal/object/create-object.d.ts +1 -1
  143. package/dist/types/src/internal/object/index.d.ts +3 -0
  144. package/dist/types/src/internal/object/index.d.ts.map +1 -1
  145. package/dist/types/src/internal/object/json-serializer.d.ts +13 -7
  146. package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -1
  147. package/dist/types/src/internal/object/schema-validator.d.ts +1 -14
  148. package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -1
  149. package/dist/types/src/internal/object/set-value.d.ts +7 -0
  150. package/dist/types/src/internal/object/set-value.d.ts.map +1 -0
  151. package/dist/types/src/internal/object/set-value.test.d.ts +2 -0
  152. package/dist/types/src/internal/object/set-value.test.d.ts.map +1 -0
  153. package/dist/types/src/internal/object/snapshot.d.ts +6 -0
  154. package/dist/types/src/internal/object/snapshot.d.ts.map +1 -0
  155. package/dist/types/src/internal/object/typed-object.d.ts +7 -13
  156. package/dist/types/src/internal/object/typed-object.d.ts.map +1 -1
  157. package/dist/types/src/internal/proxy/change-context.d.ts +55 -0
  158. package/dist/types/src/internal/proxy/change-context.d.ts.map +1 -0
  159. package/dist/types/src/internal/proxy/change.test.d.ts +2 -0
  160. package/dist/types/src/internal/proxy/change.test.d.ts.map +1 -0
  161. package/dist/types/src/internal/proxy/define-hidden-property.d.ts +5 -0
  162. package/dist/types/src/internal/proxy/define-hidden-property.d.ts.map +1 -0
  163. package/dist/types/src/internal/proxy/errors.d.ts +19 -0
  164. package/dist/types/src/internal/proxy/errors.d.ts.map +1 -0
  165. package/dist/types/src/internal/proxy/event-batch.d.ts +10 -0
  166. package/dist/types/src/internal/proxy/event-batch.d.ts.map +1 -0
  167. package/dist/types/src/internal/proxy/index.d.ts +11 -0
  168. package/dist/types/src/internal/proxy/index.d.ts.map +1 -1
  169. package/dist/types/src/internal/proxy/json-serializer.d.ts +6 -0
  170. package/dist/types/src/internal/proxy/json-serializer.d.ts.map +1 -0
  171. package/dist/types/src/internal/proxy/make-object.d.ts +2 -4
  172. package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -1
  173. package/dist/types/src/internal/proxy/ownership.d.ts +57 -0
  174. package/dist/types/src/internal/proxy/ownership.d.ts.map +1 -0
  175. package/dist/types/src/internal/proxy/proxy-types.d.ts +18 -0
  176. package/dist/types/src/internal/proxy/proxy-types.d.ts.map +1 -0
  177. package/dist/types/src/internal/proxy/proxy-utils.d.ts +47 -0
  178. package/dist/types/src/internal/proxy/proxy-utils.d.ts.map +1 -0
  179. package/dist/types/src/internal/proxy/reactive-array.d.ts +8 -0
  180. package/dist/types/src/internal/proxy/reactive-array.d.ts.map +1 -0
  181. package/dist/types/src/internal/proxy/reactive.d.ts +39 -0
  182. package/dist/types/src/internal/proxy/reactive.d.ts.map +1 -0
  183. package/dist/types/src/internal/proxy/schema-validator.d.ts +15 -0
  184. package/dist/types/src/internal/proxy/schema-validator.d.ts.map +1 -0
  185. package/dist/types/src/internal/proxy/symbols.d.ts +3 -0
  186. package/dist/types/src/internal/proxy/symbols.d.ts.map +1 -0
  187. package/dist/types/src/internal/proxy/typed-handler.d.ts +16 -12
  188. package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -1
  189. package/dist/types/src/internal/ref/ref-array.d.ts +4 -4
  190. package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -1
  191. package/dist/types/src/internal/ref/ref.d.ts +30 -8
  192. package/dist/types/src/internal/ref/ref.d.ts.map +1 -1
  193. package/dist/types/src/internal/schema/compose.d.ts +2 -1
  194. package/dist/types/src/internal/schema/compose.d.ts.map +1 -1
  195. package/dist/types/src/internal/schema/echo-schema.d.ts +16 -3
  196. package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -1
  197. package/dist/types/src/internal/schema/index.d.ts +0 -1
  198. package/dist/types/src/internal/schema/index.d.ts.map +1 -1
  199. package/dist/types/src/internal/schema/persistent-schema.d.ts +9 -7
  200. package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -1
  201. package/dist/types/src/internal/types/base.d.ts +5 -16
  202. package/dist/types/src/internal/types/base.d.ts.map +1 -1
  203. package/dist/types/src/internal/types/entity.d.ts +27 -2
  204. package/dist/types/src/internal/types/entity.d.ts.map +1 -1
  205. package/dist/types/src/internal/types/meta.d.ts +6 -14
  206. package/dist/types/src/internal/types/meta.d.ts.map +1 -1
  207. package/dist/types/src/internal/types/typename.d.ts +8 -0
  208. package/dist/types/src/internal/types/typename.d.ts.map +1 -1
  209. package/dist/types/src/testing/test-schema.d.ts +101 -205
  210. package/dist/types/src/testing/test-schema.d.ts.map +1 -1
  211. package/dist/types/src/testing/util.d.ts +6 -1
  212. package/dist/types/src/testing/util.d.ts.map +1 -1
  213. package/dist/types/tsconfig.tsbuildinfo +1 -1
  214. package/package.json +38 -115
  215. package/src/Annotation.ts +32 -4
  216. package/src/Database.ts +170 -125
  217. package/src/Entity.test.ts +22 -0
  218. package/src/Entity.ts +173 -7
  219. package/src/Err.ts +22 -2
  220. package/src/Obj.test.ts +442 -0
  221. package/src/Obj.ts +471 -254
  222. package/src/Order.ts +10 -0
  223. package/src/Query.test.ts +120 -1
  224. package/src/Query.ts +53 -8
  225. package/src/QueryResult.ts +1 -4
  226. package/src/Ref.ts +3 -3
  227. package/src/Relation.test.ts +82 -0
  228. package/src/Relation.ts +367 -28
  229. package/src/SchemaRegistry.ts +13 -0
  230. package/src/Tag.ts +1 -1
  231. package/src/Type.test.ts +52 -0
  232. package/src/Type.ts +322 -88
  233. package/src/hierarchy.test.ts +33 -0
  234. package/src/internal/README.md +31 -16
  235. package/src/internal/annotations/annotations.test.ts +6 -6
  236. package/src/internal/annotations/annotations.ts +48 -49
  237. package/src/internal/annotations/util.ts +13 -0
  238. package/src/internal/api/annotations.ts +60 -0
  239. package/src/internal/api/entity.ts +29 -0
  240. package/src/internal/api/index.ts +19 -0
  241. package/src/internal/api/meta.ts +88 -0
  242. package/src/internal/api/sorting.ts +53 -0
  243. package/src/internal/api/version.ts +96 -0
  244. package/src/internal/entities/entity.ts +36 -19
  245. package/src/internal/entities/index.ts +1 -1
  246. package/src/internal/entities/model.ts +21 -12
  247. package/src/internal/entities/object.ts +21 -8
  248. package/src/internal/entities/relation.ts +23 -7
  249. package/src/internal/formats/format.test.ts +1 -1
  250. package/src/internal/formats/select.ts +1 -1
  251. package/src/internal/formats/types.ts +1 -1
  252. package/src/internal/index.ts +2 -1
  253. package/src/internal/json-schema/json-schema-normalize.ts +4 -2
  254. package/src/internal/json-schema/json-schema-type.ts +30 -31
  255. package/src/internal/json-schema/json-schema.test.ts +17 -17
  256. package/src/internal/json-schema/json-schema.ts +14 -10
  257. package/src/internal/object/clone.ts +48 -0
  258. package/src/internal/object/create-object.ts +2 -2
  259. package/src/internal/object/index.ts +3 -0
  260. package/src/internal/object/inspect.ts +3 -3
  261. package/src/internal/object/json-serializer.test.ts +6 -2
  262. package/src/internal/object/json-serializer.ts +37 -70
  263. package/src/internal/object/schema-validator.test.ts +3 -7
  264. package/src/internal/object/schema-validator.ts +2 -240
  265. package/src/internal/object/set-value.test.ts +281 -0
  266. package/src/internal/object/set-value.ts +165 -0
  267. package/src/internal/object/snapshot.ts +93 -0
  268. package/src/internal/object/typed-object.test.ts +11 -11
  269. package/src/internal/object/typed-object.ts +8 -72
  270. package/src/internal/proxy/change-context.ts +138 -0
  271. package/src/internal/proxy/change.test.ts +519 -0
  272. package/src/internal/proxy/define-hidden-property.ts +14 -0
  273. package/src/internal/proxy/errors.ts +42 -0
  274. package/src/internal/proxy/event-batch.ts +44 -0
  275. package/src/internal/proxy/handler.test.ts +30 -80
  276. package/src/internal/proxy/index.ts +11 -0
  277. package/src/internal/proxy/json-serializer.ts +87 -0
  278. package/src/internal/proxy/make-object.ts +44 -51
  279. package/src/internal/proxy/ownership.ts +253 -0
  280. package/src/internal/proxy/proxy-types.ts +23 -0
  281. package/src/internal/proxy/proxy-utils.ts +150 -0
  282. package/src/internal/proxy/reactive-array.ts +71 -0
  283. package/src/internal/proxy/reactive.ts +69 -0
  284. package/src/internal/proxy/schema-validator.ts +244 -0
  285. package/src/internal/proxy/schema.test.ts +23 -15
  286. package/src/internal/proxy/symbols.ts +7 -0
  287. package/src/internal/proxy/typed-handler.test.ts +247 -35
  288. package/src/internal/proxy/typed-handler.ts +274 -57
  289. package/src/internal/proxy/typed-object.test.ts +37 -26
  290. package/src/internal/ref/ref-array.ts +4 -4
  291. package/src/internal/ref/ref.test.ts +1 -1
  292. package/src/internal/ref/ref.ts +88 -41
  293. package/src/internal/schema/compose.test.ts +3 -3
  294. package/src/internal/schema/compose.ts +13 -9
  295. package/src/internal/schema/echo-schema.ts +51 -12
  296. package/src/internal/schema/index.ts +0 -1
  297. package/src/internal/schema/persistent-schema.ts +5 -5
  298. package/src/internal/types/base.ts +6 -20
  299. package/src/internal/types/entity.ts +35 -4
  300. package/src/internal/types/meta.ts +13 -24
  301. package/src/internal/types/typename.ts +10 -0
  302. package/src/testing/api.test.ts +31 -5
  303. package/src/testing/test-schema.ts +44 -30
  304. package/src/testing/util.ts +22 -15
  305. package/dist/lib/browser/Annotation.mjs +0 -31
  306. package/dist/lib/browser/Database.mjs +0 -14
  307. package/dist/lib/browser/Entity.mjs +0 -20
  308. package/dist/lib/browser/JsonSchema.mjs +0 -18
  309. package/dist/lib/browser/Obj.mjs +0 -83
  310. package/dist/lib/browser/Order.mjs +0 -11
  311. package/dist/lib/browser/Query.mjs +0 -25
  312. package/dist/lib/browser/QueryResult.mjs +0 -3
  313. package/dist/lib/browser/Ref.mjs +0 -21
  314. package/dist/lib/browser/Relation.mjs +0 -33
  315. package/dist/lib/browser/SchemaRegistry.mjs +0 -3
  316. package/dist/lib/browser/Tag.mjs +0 -25
  317. package/dist/lib/browser/Type.mjs +0 -38
  318. package/dist/lib/browser/chunk-6XVZF5VJ.mjs.map +0 -7
  319. package/dist/lib/browser/chunk-AGOWBKY6.mjs.map +0 -7
  320. package/dist/lib/browser/chunk-BD6MRI4M.mjs +0 -113
  321. package/dist/lib/browser/chunk-BD6MRI4M.mjs.map +0 -7
  322. package/dist/lib/browser/chunk-DOPKE2FQ.mjs +0 -32
  323. package/dist/lib/browser/chunk-DOPKE2FQ.mjs.map +0 -7
  324. package/dist/lib/browser/chunk-ESLW4N7S.mjs.map +0 -7
  325. package/dist/lib/browser/chunk-F4YF6C3O.mjs +0 -363
  326. package/dist/lib/browser/chunk-F4YF6C3O.mjs.map +0 -7
  327. package/dist/lib/browser/chunk-FGFQWIZE.mjs.map +0 -7
  328. package/dist/lib/browser/chunk-INHXFXY5.mjs.map +0 -7
  329. package/dist/lib/browser/chunk-JG4GH6LN.mjs.map +0 -7
  330. package/dist/lib/browser/chunk-NFH3POTD.mjs +0 -37
  331. package/dist/lib/browser/chunk-NFH3POTD.mjs.map +0 -7
  332. package/dist/lib/browser/chunk-O6FOICWT.mjs.map +0 -7
  333. package/dist/lib/browser/chunk-P2B4BASR.mjs.map +0 -7
  334. package/dist/lib/browser/chunk-QHC3ZYNC.mjs +0 -152
  335. package/dist/lib/browser/chunk-QHC3ZYNC.mjs.map +0 -7
  336. package/dist/lib/browser/chunk-QU7PWSZD.mjs +0 -62
  337. package/dist/lib/browser/chunk-QU7PWSZD.mjs.map +0 -7
  338. package/dist/lib/browser/chunk-RP4JV7FD.mjs.map +0 -7
  339. package/dist/lib/browser/chunk-V7TON6BX.mjs.map +0 -7
  340. package/dist/lib/browser/chunk-WABSVOOX.mjs +0 -303
  341. package/dist/lib/browser/chunk-WABSVOOX.mjs.map +0 -7
  342. package/dist/lib/browser/chunk-XRHHSMHJ.mjs +0 -39
  343. package/dist/lib/browser/chunk-XRHHSMHJ.mjs.map +0 -7
  344. package/dist/lib/browser/chunk-ZIM3Y4ZK.mjs.map +0 -7
  345. package/dist/lib/browser/internal/index.mjs +0 -347
  346. package/dist/lib/browser/meta.json +0 -1
  347. package/dist/lib/browser/testing/index.mjs.map +0 -7
  348. package/dist/lib/node-esm/Annotation.mjs +0 -31
  349. package/dist/lib/node-esm/Annotation.mjs.map +0 -7
  350. package/dist/lib/node-esm/Database.mjs +0 -14
  351. package/dist/lib/node-esm/Database.mjs.map +0 -7
  352. package/dist/lib/node-esm/Entity.mjs +0 -20
  353. package/dist/lib/node-esm/Entity.mjs.map +0 -7
  354. package/dist/lib/node-esm/Err.mjs +0 -11
  355. package/dist/lib/node-esm/Err.mjs.map +0 -7
  356. package/dist/lib/node-esm/Filter.mjs +0 -60
  357. package/dist/lib/node-esm/Filter.mjs.map +0 -7
  358. package/dist/lib/node-esm/Format.mjs +0 -67
  359. package/dist/lib/node-esm/Format.mjs.map +0 -7
  360. package/dist/lib/node-esm/JsonSchema.mjs +0 -18
  361. package/dist/lib/node-esm/JsonSchema.mjs.map +0 -7
  362. package/dist/lib/node-esm/Key.mjs +0 -13
  363. package/dist/lib/node-esm/Key.mjs.map +0 -7
  364. package/dist/lib/node-esm/Obj.mjs.map +0 -7
  365. package/dist/lib/node-esm/Order.mjs +0 -11
  366. package/dist/lib/node-esm/Order.mjs.map +0 -7
  367. package/dist/lib/node-esm/Query.mjs +0 -25
  368. package/dist/lib/node-esm/Query.mjs.map +0 -7
  369. package/dist/lib/node-esm/QueryResult.mjs +0 -3
  370. package/dist/lib/node-esm/QueryResult.mjs.map +0 -7
  371. package/dist/lib/node-esm/Ref.mjs +0 -21
  372. package/dist/lib/node-esm/Ref.mjs.map +0 -7
  373. package/dist/lib/node-esm/Relation.mjs +0 -33
  374. package/dist/lib/node-esm/Relation.mjs.map +0 -7
  375. package/dist/lib/node-esm/SchemaRegistry.mjs +0 -3
  376. package/dist/lib/node-esm/SchemaRegistry.mjs.map +0 -7
  377. package/dist/lib/node-esm/Tag.mjs +0 -25
  378. package/dist/lib/node-esm/Tag.mjs.map +0 -7
  379. package/dist/lib/node-esm/Type.mjs +0 -38
  380. package/dist/lib/node-esm/Type.mjs.map +0 -7
  381. package/dist/lib/node-esm/chunk-5M5P2DCR.mjs +0 -32
  382. package/dist/lib/node-esm/chunk-5M5P2DCR.mjs.map +0 -7
  383. package/dist/lib/node-esm/chunk-6OTQZKHX.mjs.map +0 -7
  384. package/dist/lib/node-esm/chunk-76LEDWHO.mjs +0 -152
  385. package/dist/lib/node-esm/chunk-76LEDWHO.mjs.map +0 -7
  386. package/dist/lib/node-esm/chunk-AGHZH33D.mjs +0 -9
  387. package/dist/lib/node-esm/chunk-AGHZH33D.mjs.map +0 -7
  388. package/dist/lib/node-esm/chunk-AJEMYSIR.mjs +0 -22
  389. package/dist/lib/node-esm/chunk-BJACR7QG.mjs +0 -363
  390. package/dist/lib/node-esm/chunk-BJACR7QG.mjs.map +0 -7
  391. package/dist/lib/node-esm/chunk-CCMFPJUT.mjs +0 -74
  392. package/dist/lib/node-esm/chunk-CCMFPJUT.mjs.map +0 -7
  393. package/dist/lib/node-esm/chunk-D5BW7KHR.mjs +0 -39
  394. package/dist/lib/node-esm/chunk-D5BW7KHR.mjs.map +0 -7
  395. package/dist/lib/node-esm/chunk-DJX53IQ3.mjs +0 -2924
  396. package/dist/lib/node-esm/chunk-DJX53IQ3.mjs.map +0 -7
  397. package/dist/lib/node-esm/chunk-FWTPV5QD.mjs +0 -94
  398. package/dist/lib/node-esm/chunk-FWTPV5QD.mjs.map +0 -7
  399. package/dist/lib/node-esm/chunk-HLUDHPFO.mjs +0 -403
  400. package/dist/lib/node-esm/chunk-HLUDHPFO.mjs.map +0 -7
  401. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
  402. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
  403. package/dist/lib/node-esm/chunk-JYZSF62S.mjs +0 -113
  404. package/dist/lib/node-esm/chunk-JYZSF62S.mjs.map +0 -7
  405. package/dist/lib/node-esm/chunk-KUX5JEL2.mjs +0 -57
  406. package/dist/lib/node-esm/chunk-KUX5JEL2.mjs.map +0 -7
  407. package/dist/lib/node-esm/chunk-LDXRA5TC.mjs +0 -288
  408. package/dist/lib/node-esm/chunk-MOWUEW5P.mjs +0 -15
  409. package/dist/lib/node-esm/chunk-MOWUEW5P.mjs.map +0 -7
  410. package/dist/lib/node-esm/chunk-NHYOREKX.mjs.map +0 -7
  411. package/dist/lib/node-esm/chunk-QVZZHCDS.mjs +0 -9
  412. package/dist/lib/node-esm/chunk-QVZZHCDS.mjs.map +0 -7
  413. package/dist/lib/node-esm/chunk-W3OLV7MG.mjs +0 -41
  414. package/dist/lib/node-esm/chunk-W3OLV7MG.mjs.map +0 -7
  415. package/dist/lib/node-esm/chunk-W5AQXKVF.mjs +0 -38
  416. package/dist/lib/node-esm/chunk-W5AQXKVF.mjs.map +0 -7
  417. package/dist/lib/node-esm/chunk-YNBFXTDG.mjs +0 -24
  418. package/dist/lib/node-esm/chunk-YNBFXTDG.mjs.map +0 -7
  419. package/dist/lib/node-esm/chunk-Z53QIBP2.mjs +0 -151
  420. package/dist/lib/node-esm/chunk-Z53QIBP2.mjs.map +0 -7
  421. package/dist/lib/node-esm/index.mjs +0 -85
  422. package/dist/lib/node-esm/index.mjs.map +0 -7
  423. package/dist/lib/node-esm/internal/index.mjs.map +0 -7
  424. package/dist/lib/node-esm/meta.json +0 -1
  425. package/dist/lib/node-esm/testing/index.mjs +0 -360
  426. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  427. package/dist/types/src/internal/entities/expando.d.ts +0 -16
  428. package/dist/types/src/internal/entities/expando.d.ts.map +0 -1
  429. package/dist/types/src/internal/schema/snapshot.d.ts +0 -6
  430. package/dist/types/src/internal/schema/snapshot.d.ts.map +0 -1
  431. package/src/internal/entities/expando.ts +0 -23
  432. package/src/internal/schema/snapshot.ts +0 -25
  433. /package/dist/lib/{browser → neutral}/Annotation.mjs.map +0 -0
  434. /package/dist/lib/{browser → neutral}/Database.mjs.map +0 -0
  435. /package/dist/lib/{browser → neutral}/Entity.mjs.map +0 -0
  436. /package/dist/lib/{browser → neutral}/Err.mjs.map +0 -0
  437. /package/dist/lib/{browser → neutral}/Filter.mjs.map +0 -0
  438. /package/dist/lib/{browser → neutral}/Format.mjs.map +0 -0
  439. /package/dist/lib/{browser → neutral}/JsonSchema.mjs.map +0 -0
  440. /package/dist/lib/{browser → neutral}/Key.mjs.map +0 -0
  441. /package/dist/lib/{browser → neutral}/Obj.mjs.map +0 -0
  442. /package/dist/lib/{browser → neutral}/Order.mjs.map +0 -0
  443. /package/dist/lib/{browser → neutral}/Query.mjs.map +0 -0
  444. /package/dist/lib/{browser → neutral}/QueryResult.mjs.map +0 -0
  445. /package/dist/lib/{browser → neutral}/Ref.mjs.map +0 -0
  446. /package/dist/lib/{browser → neutral}/Relation.mjs.map +0 -0
  447. /package/dist/lib/{browser → neutral}/SchemaRegistry.mjs.map +0 -0
  448. /package/dist/lib/{browser → neutral}/Tag.mjs.map +0 -0
  449. /package/dist/lib/{browser → neutral}/Type.mjs.map +0 -0
  450. /package/dist/lib/{browser/chunk-CGS2ULMK.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
  451. /package/dist/lib/{browser → neutral}/index.mjs.map +0 -0
  452. /package/dist/lib/{browser → neutral}/internal/index.mjs.map +0 -0
@@ -3,19 +3,25 @@
3
3
  //
4
4
 
5
5
  import * as Effect from 'effect/Effect';
6
+ import * as Equal from 'effect/Equal';
7
+ import * as Hash from 'effect/Hash';
6
8
  import * as Option from 'effect/Option';
7
9
  import * as ParseResult from 'effect/ParseResult';
10
+ import * as Pipeable from 'effect/Pipeable';
8
11
  import * as Schema from 'effect/Schema';
9
12
  import * as SchemaAST from 'effect/SchemaAST';
13
+ import type * as Types from 'effect/Types';
10
14
 
11
- import { type EncodedReference, Reference } from '@dxos/echo-protocol';
12
- import { compositeRuntime } from '@dxos/echo-signals/runtime';
15
+ import { Event } from '@dxos/async';
16
+ import { type CustomInspectFunction, inspectCustom } from '@dxos/debug';
17
+ import { EncodedReference } from '@dxos/echo-protocol';
13
18
  import { assertArgument, invariant } from '@dxos/invariant';
14
19
  import { DXN, ObjectId } from '@dxos/keys';
15
20
 
21
+ import * as Database from '../../Database';
16
22
  import { ReferenceAnnotationId, getSchemaDXN, getTypeAnnotation, getTypeIdentifierAnnotation } from '../annotations';
17
23
  import { type JsonSchemaType } from '../json-schema';
18
- import type { AnyProperties, WithId } from '../types';
24
+ import type { AnyEntity, AnyProperties } from '../types';
19
25
 
20
26
  /**
21
27
  * The `$id` and `$ref` fields for an ECHO reference schema.
@@ -29,7 +35,7 @@ export const getSchemaReference = (property: JsonSchemaType): { typename: string
29
35
  }
30
36
  };
31
37
 
32
- export const createSchemaReference = (typename: string): JsonSchemaType => {
38
+ export const createSchemaReference = (typename: string): Types.DeepMutable<JsonSchemaType> => {
33
39
  return {
34
40
  $id: JSON_SCHEMA_ECHO_REF_ID,
35
41
  reference: {
@@ -70,7 +76,7 @@ export const RefTypeId: unique symbol = Symbol('@dxos/echo/internal/Ref');
70
76
  /**
71
77
  * Reference Schema.
72
78
  */
73
- export interface RefSchema<T extends WithId> extends Schema.SchemaClass<Ref<T>, EncodedReference> {}
79
+ export interface RefSchema<T extends AnyEntity> extends Schema.SchemaClass<Ref<T>, EncodedReference> {}
74
80
 
75
81
  /**
76
82
  * Type of the `Ref` function and extra methods attached to it.
@@ -101,8 +107,8 @@ export interface RefFn {
101
107
  /**
102
108
  * Constructs a reference that points to the given object.
103
109
  */
104
- // TODO(burdon): Narrow to Obj.Any?
105
- make: <T extends WithId>(object: T) => Ref<T>;
110
+ // TODO(burdon): Narrow to Obj.Unknown?
111
+ make: <T extends AnyEntity>(object: T) => Ref<T>;
106
112
 
107
113
  /**
108
114
  * Constructs a reference that points to the object specified by the provided DXN.
@@ -115,36 +121,33 @@ export interface RefFn {
115
121
  */
116
122
  export const Ref: RefFn = <S extends Schema.Schema.Any>(schema: S): RefSchema<Schema.Schema.Type<S>> => {
117
123
  assertArgument(Schema.isSchema(schema), 'schema', 'Must call with an instance of effect-schema');
118
-
119
124
  const annotation = getTypeAnnotation(schema);
120
125
  if (annotation == null) {
121
126
  throw new Error('Reference target must be an ECHO schema.');
122
127
  }
123
128
 
124
- return createEchoReferenceSchema(
125
- getTypeIdentifierAnnotation(schema),
126
- annotation.typename,
127
- annotation.version,
128
- getSchemaExpectedName(schema.ast),
129
- );
129
+ return createEchoReferenceSchema(getTypeIdentifierAnnotation(schema), annotation.typename, annotation.version);
130
130
  };
131
131
 
132
132
  /**
133
133
  * Represents materialized reference to a target.
134
134
  * This is the data type for the fields marked as ref.
135
135
  */
136
- export interface Ref<T> {
136
+ export interface Ref<T> extends Pipeable.Pipeable {
137
137
  /**
138
138
  * Target object DXN.
139
139
  */
140
140
  get dxn(): DXN;
141
141
 
142
+ /**
143
+ * Returns true if the reference has a target available (inlined or resolver set).
144
+ */
145
+ get isAvailable(): boolean;
146
+
142
147
  /**
143
148
  * @returns The reference target.
144
149
  * May return `undefined` if the object is not loaded in the working set.
145
150
  * Accessing this property, even if it returns `undefined` will trigger the object to be loaded to the working set.
146
- *
147
- * @reactive Supports signal subscriptions.
148
151
  */
149
152
  get target(): T | undefined;
150
153
 
@@ -158,6 +161,7 @@ export interface Ref<T> {
158
161
  /**
159
162
  * @returns Promise that will resolves with the target object or undefined if the object is not loaded locally.
160
163
  */
164
+
161
165
  tryLoad(): Promise<T | undefined>;
162
166
 
163
167
  /**
@@ -219,7 +223,7 @@ Ref.make = <T extends AnyProperties>(obj: T): Ref<T> => {
219
223
  // TODO(dmaretskyi): Extract to `getObjectDXN` function.
220
224
  const id = obj.id;
221
225
  invariant(ObjectId.isValid(id), 'Invalid object ID');
222
- const dxn = Reference.localObjectReference(id).toDXN();
226
+ const dxn = DXN.fromLocalObjectId(id);
223
227
  return new RefImpl(dxn, obj);
224
228
  };
225
229
 
@@ -244,7 +248,6 @@ export const createEchoReferenceSchema = (
244
248
  echoId: string | undefined,
245
249
  typename: string | undefined,
246
250
  version: string | undefined,
247
- schemaName?: string, // TODO(burdon): Not used.
248
251
  ): Schema.SchemaClass<Ref<any>, EncodedReference> => {
249
252
  if (!echoId && !typename) {
250
253
  throw new TypeError('Either echoId or typename must be provided.');
@@ -263,25 +266,39 @@ export const createEchoReferenceSchema = (
263
266
  [],
264
267
  {
265
268
  encode: () => {
266
- return (value) => {
267
- return Effect.succeed({
268
- '/': (value as Ref<any>).dxn.toString(),
269
+ return (value) =>
270
+ Effect.gen(function* () {
271
+ if (Ref.isRef(value)) {
272
+ return EncodedReference.fromDXN((value as Ref<any>).dxn);
273
+ } else if (EncodedReference.isEncodedReference(value)) {
274
+ return value;
275
+ }
276
+ throw new Error('Invalid reference');
269
277
  });
270
- };
271
278
  },
272
279
  decode: () => {
273
- return (value) => {
274
- // TODO(dmaretskyi): This branch seems to be taken by Schema.is
275
- if (Ref.isRef(value)) {
276
- return Effect.succeed(value);
277
- }
278
-
279
- if (typeof value !== 'object' || value == null || typeof (value as any)['/'] !== 'string') {
280
- return Effect.fail(new ParseResult.Unexpected(value, 'reference'));
281
- }
282
-
283
- return Effect.succeed(Ref.fromDXN(DXN.parse((value as any)['/'])));
284
- };
280
+ return (value) =>
281
+ Effect.gen(function* () {
282
+ const dbService = yield* Effect.serviceOption(Database.Service);
283
+
284
+ // TODO(dmaretskyi): This branch seems to be taken by Schema.is
285
+ if (Ref.isRef(value)) {
286
+ if (Option.isSome(dbService)) {
287
+ return dbService.value.db.makeRef(value.dxn);
288
+ } else {
289
+ return value;
290
+ }
291
+ }
292
+
293
+ if (!EncodedReference.isEncodedReference(value)) {
294
+ return yield* Effect.fail(new ParseResult.Unexpected(value, 'reference'));
295
+ }
296
+ if (Option.isSome(dbService)) {
297
+ return dbService.value.db.makeRef(EncodedReference.toDXN(value));
298
+ } else {
299
+ return Ref.fromDXN(EncodedReference.toDXN(value));
300
+ }
301
+ });
285
302
  },
286
303
  },
287
304
  {
@@ -331,7 +348,7 @@ export interface RefResolver {
331
348
  export class RefImpl<T> implements Ref<T> {
332
349
  #dxn: DXN;
333
350
  #resolver?: RefResolver = undefined;
334
- #signal = compositeRuntime.createSignal();
351
+ #resolved = new Event<void>();
335
352
 
336
353
  /**
337
354
  * Target is set when the reference is created from a specific object.
@@ -343,7 +360,7 @@ export class RefImpl<T> implements Ref<T> {
343
360
  * Callback to issue a reactive notification when object is resolved.
344
361
  */
345
362
  #resolverCallback = () => {
346
- this.#signal.notifyWrite();
363
+ this.#resolved.emit();
347
364
  };
348
365
 
349
366
  constructor(dxn: DXN, target?: T) {
@@ -358,11 +375,17 @@ export class RefImpl<T> implements Ref<T> {
358
375
  return this.#dxn;
359
376
  }
360
377
 
378
+ /**
379
+ * @inheritdoc
380
+ */
381
+ get isAvailable(): boolean {
382
+ return this.#target !== undefined || this.#resolver !== undefined;
383
+ }
384
+
361
385
  /**
362
386
  * @inheritdoc
363
387
  */
364
388
  get target(): T | undefined {
365
- this.#signal.notifyRead();
366
389
  if (this.#target) {
367
390
  return this.#target;
368
391
  }
@@ -390,6 +413,9 @@ export class RefImpl<T> implements Ref<T> {
390
413
  * @inheritdoc
391
414
  */
392
415
  async tryLoad(): Promise<T | undefined> {
416
+ if (this.#target) {
417
+ return this.#target;
418
+ }
393
419
  invariant(this.#resolver, 'Resolver is not set');
394
420
  return (await this.#resolver.resolve(this.#dxn)) as T | undefined;
395
421
  }
@@ -430,8 +456,27 @@ export class RefImpl<T> implements Ref<T> {
430
456
  return `Ref(${this.#dxn.toString()})`;
431
457
  }
432
458
 
459
+ [inspectCustom]: CustomInspectFunction = (depth, options, inspect) => {
460
+ return this.toString();
461
+ };
462
+
433
463
  [RefTypeId] = refVariance;
434
464
 
465
+ /**
466
+ * Effect Hash trait. Required for MutableHashMap-based caches (e.g., Atom.family)
467
+ * to deduplicate Ref instances that point to the same object.
468
+ * ECHO proxies return new RefImpl instances on every property access,
469
+ * so without this, each access would create a separate cache entry.
470
+ */
471
+ [Hash.symbol](): number {
472
+ return Hash.hash(this.#dxn.toString());
473
+ }
474
+
475
+ /** Effect Equal trait. See {@link Hash.symbol} for rationale. */
476
+ [Equal.symbol](that: Equal.Equal): boolean {
477
+ return that instanceof RefImpl && this.#dxn.toString() === that.dxn.toString();
478
+ }
479
+
435
480
  /**
436
481
  * Internal method to set the resolver.
437
482
  *
@@ -442,14 +487,16 @@ export class RefImpl<T> implements Ref<T> {
442
487
  }
443
488
 
444
489
  /**
445
- * Internal method to get the saved target.
446
- * Not the same as `target` which is resolved from the resolver.
447
- *
448
490
  * @internal
449
491
  */
450
492
  _getSavedTarget(): T | undefined {
451
493
  return this.#target;
452
494
  }
495
+
496
+ pipe() {
497
+ // eslint-disable-next-line prefer-rest-params
498
+ return Pipeable.pipeArguments(this, arguments);
499
+ }
453
500
  }
454
501
 
455
502
  /**
@@ -6,18 +6,18 @@ import * as Schema from 'effect/Schema';
6
6
  import { describe, test } from 'vitest';
7
7
 
8
8
  import { FieldPath } from '../annotations';
9
+ import { EchoObjectSchema } from '../entities';
9
10
  import { FormatAnnotation, TypeFormat } from '../formats';
10
11
  import { ECHO_ANNOTATIONS_NS_KEY, toJsonSchema } from '../json-schema';
11
- import { TypedObject } from '../object';
12
12
 
13
13
  import { composeSchema } from './compose';
14
14
 
15
15
  describe('schema composition', () => {
16
16
  test('schema composition', ({ expect }) => {
17
- class BaseType extends TypedObject({ typename: 'example.com/Person', version: '0.1.0' })({
17
+ const BaseType = Schema.Struct({
18
18
  name: Schema.String,
19
19
  email: Schema.String,
20
- }) {}
20
+ }).pipe(EchoObjectSchema({ typename: 'example.com/Person', version: '0.1.0' }));
21
21
 
22
22
  const OverlaySchema = Schema.Struct({
23
23
  email: Schema.String.pipe(FieldPath('$.email'), FormatAnnotation.set(TypeFormat.Email)),
@@ -2,19 +2,22 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import type * as Types from 'effect/Types';
6
+
5
7
  import { invariant } from '@dxos/invariant';
6
8
 
7
9
  import { type JsonSchemaType } from '../json-schema';
8
10
 
9
- import { getSnapshot } from './snapshot';
10
-
11
11
  /**
12
12
  * Creates a composite schema from the source and projection schemas.
13
13
  */
14
14
  // TODO(burdon): Use effect schema projections.
15
15
  // TODO(burdon): Can avoid having to call this every time we modify any property on the view?
16
- export const composeSchema = (source: JsonSchemaType, target: JsonSchemaType): JsonSchemaType => {
17
- const result: JsonSchemaType = getSnapshot(target);
16
+ export const composeSchema = (
17
+ source: Types.Mutable<JsonSchemaType>,
18
+ target: Types.Mutable<JsonSchemaType>,
19
+ ): Types.Mutable<JsonSchemaType> => {
20
+ const result = structuredClone(target);
18
21
  invariant('type' in result && result.type === 'object', 'source schema must be an object');
19
22
  invariant('type' in source && source.type === 'object', 'target schema must be an object');
20
23
 
@@ -22,12 +25,13 @@ export const composeSchema = (source: JsonSchemaType, target: JsonSchemaType): J
22
25
  const propSchema = source.properties![prop]; // TODO(dmaretskyi): Find by json-path instead.
23
26
  const annotations = (propSchema as JsonSchemaType)?.annotations?.meta;
24
27
  if (annotations) {
25
- (result.properties[prop] as JsonSchemaType).annotations ??= {};
26
- (result.properties[prop] as JsonSchemaType).annotations!.meta ??= {};
28
+ const resultProp = result.properties[prop] as Record<string, any>;
29
+ resultProp.annotations ??= {};
30
+ resultProp.annotations.meta ??= {};
27
31
  for (const key in annotations) {
28
- (result.properties[prop] as JsonSchemaType).annotations!.meta![key] ??= {};
29
- Object.assign((result.properties[prop] as JsonSchemaType).annotations!.meta![key], annotations[key], {
30
- ...(result.properties[prop] as JsonSchemaType).annotations!.meta![key],
32
+ resultProp.annotations.meta[key] ??= {};
33
+ Object.assign(resultProp.annotations.meta[key], annotations[key], {
34
+ ...resultProp.annotations.meta[key],
31
35
  });
32
36
  }
33
37
  }
@@ -8,9 +8,12 @@ import * as SchemaAST from 'effect/SchemaAST';
8
8
  import { invariant } from '@dxos/invariant';
9
9
  import { type ObjectId } from '@dxos/keys';
10
10
 
11
+ import type * as Type from '../../Type';
11
12
  import { type SchemaMeta, SchemaMetaSymbol, type TypeAnnotation, getTypeAnnotation } from '../annotations';
12
13
  import { type JsonSchemaType, toEffectSchema, toJsonSchema } from '../json-schema';
13
- import { type TypedObject, type TypedObjectPrototype } from '../object';
14
+ import { type TypedObject, type TypedObjectPrototype, getSnapshot } from '../object';
15
+ import { ChangeId } from '../proxy';
16
+ import { EntityKind, SchemaKindId } from '../types';
14
17
 
15
18
  import {
16
19
  addFieldsToSchema,
@@ -20,7 +23,6 @@ import {
20
23
  updateFieldsInSchema,
21
24
  } from './manipulation';
22
25
  import { PersistentSchema } from './persistent-schema';
23
- import { getSnapshot } from './snapshot';
24
26
 
25
27
  /**
26
28
  * Base schema type.
@@ -83,6 +85,10 @@ export class ImmutableSchema<A = any, I = any> implements BaseSchema<A, I> {
83
85
  // TypedObject
84
86
  //
85
87
 
88
+ get kind(): EntityKind {
89
+ return this._objectAnnotation.kind;
90
+ }
91
+
86
92
  get typename(): string {
87
93
  return this._objectAnnotation.typename;
88
94
  }
@@ -172,7 +178,7 @@ const schemaVariance = {
172
178
  *
173
179
  * @example
174
180
  * ```ts
175
- * export class TableType extends Schema.Struct({...}).pipe(Type.Obj({ typename: 'example.org/type/Table', version: '0.1.0' })){
181
+ * export class TableType extends Schema.Struct({...}).pipe(Type.object({ typename: 'example.org/type/Table', version: '0.1.0' })){
176
182
  * title: Schema.String,
177
183
  * schema: Schema.optional(ref(EchoSchema)),
178
184
  * props: Schema.mutable(S.Array(TablePropSchema)),
@@ -185,6 +191,12 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
185
191
  private _schema: Schema.Schema.AnyNoContext | undefined;
186
192
  private _isDirty = true;
187
193
 
194
+ /**
195
+ * Schema kind key that marks this as an ECHO schema.
196
+ * Makes EchoSchema satisfy the Type.Obj.Any type.
197
+ */
198
+ readonly [SchemaKindId]: EntityKind.Object = EntityKind.Object;
199
+
188
200
  constructor(private readonly _persistentSchema: PersistentSchema) {
189
201
  super();
190
202
  }
@@ -229,6 +241,11 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
229
241
  // BaseSchema
230
242
  //
231
243
 
244
+ public get kind(): EntityKind.Object {
245
+ // Dynamic schemas are always object schemas.
246
+ return EntityKind.Object;
247
+ }
248
+
232
249
  public get typename(): string {
233
250
  return this._persistentSchema.typename;
234
251
  }
@@ -249,7 +266,7 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
249
266
  }
250
267
 
251
268
  /**
252
- * @reactive
269
+ * Returns the JSON schema for the schema.
253
270
  */
254
271
  public get jsonSchema(): JsonSchemaType {
255
272
  return this._persistentSchema.jsonSchema;
@@ -288,8 +305,8 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
288
305
  /**
289
306
  * Reference to the underlying persistent schema object.
290
307
  */
291
- public get persistentSchema(): PersistentSchema {
292
- return this._persistentSchema;
308
+ public get persistentSchema(): Type.PersistentType {
309
+ return this._persistentSchema as Type.PersistentType;
293
310
  }
294
311
 
295
312
  public getProperties(): SchemaAST.PropertySignature[] {
@@ -309,8 +326,10 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
309
326
  */
310
327
  public updateTypename(typename: string): void {
311
328
  const updated = setTypenameInSchema(this._getSchema(), typename);
312
- this._persistentSchema.typename = typename;
313
- this._persistentSchema.jsonSchema = toJsonSchema(updated);
329
+ this._change((schema) => {
330
+ schema.typename = typename;
331
+ schema.jsonSchema = toJsonSchema(updated);
332
+ });
314
333
  }
315
334
 
316
335
  /**
@@ -318,7 +337,9 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
318
337
  */
319
338
  public addFields(fields: Schema.Struct.Fields): void {
320
339
  const extended = addFieldsToSchema(this._getSchema(), fields);
321
- this._persistentSchema.jsonSchema = toJsonSchema(extended);
340
+ this._change((schema) => {
341
+ schema.jsonSchema = toJsonSchema(extended);
342
+ });
322
343
  }
323
344
 
324
345
  /**
@@ -326,7 +347,9 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
326
347
  */
327
348
  public updateFields(fields: Schema.Struct.Fields): void {
328
349
  const updated = updateFieldsInSchema(this._getSchema(), fields);
329
- this._persistentSchema.jsonSchema = toJsonSchema(updated);
350
+ this._change((schema) => {
351
+ schema.jsonSchema = toJsonSchema(updated);
352
+ });
330
353
  }
331
354
 
332
355
  /**
@@ -334,7 +357,9 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
334
357
  */
335
358
  public updateFieldPropertyName({ before, after }: { before: PropertyKey; after: PropertyKey }): void {
336
359
  const renamed = updateFieldNameInSchema(this._getSchema(), { before, after });
337
- this._persistentSchema.jsonSchema = toJsonSchema(renamed);
360
+ this._change((schema) => {
361
+ schema.jsonSchema = toJsonSchema(renamed);
362
+ });
338
363
  }
339
364
 
340
365
  /**
@@ -342,7 +367,21 @@ export class EchoSchema<A = any, I = any> extends EchoSchemaConstructor() implem
342
367
  */
343
368
  public removeFields(fieldNames: string[]): void {
344
369
  const removed = removeFieldsFromSchema(this._getSchema(), fieldNames);
345
- this._persistentSchema.jsonSchema = toJsonSchema(removed);
370
+ this._change((schema) => {
371
+ schema.jsonSchema = toJsonSchema(removed);
372
+ });
373
+ }
374
+
375
+ /**
376
+ * Wrapper for Obj.change that handles the change context for the persistent schema.
377
+ */
378
+ private _change(callback: (schema: PersistentSchema) => void): void {
379
+ const changeFn = (this._persistentSchema as any)[ChangeId];
380
+ if (changeFn) {
381
+ changeFn(callback);
382
+ } else {
383
+ callback(this._persistentSchema);
384
+ }
346
385
  }
347
386
 
348
387
  //
@@ -5,4 +5,3 @@
5
5
  export * from './echo-schema';
6
6
  export * from './manipulation';
7
7
  export * from './persistent-schema';
8
- export * from './snapshot';
@@ -4,7 +4,7 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { TypenameSchema, VersionSchema } from '../annotations';
7
+ import { LabelAnnotation, TypenameSchema, VersionSchema } from '../annotations';
8
8
  import { EchoObjectSchema } from '../entities';
9
9
  import { JsonSchemaType } from '../json-schema';
10
10
 
@@ -12,7 +12,7 @@ import { JsonSchemaType } from '../json-schema';
12
12
  * Persistent representation of a schema.
13
13
  */
14
14
  // TODO(burdon): Move.
15
- const PersistentEchoSchema = Schema.Struct({
15
+ export const PersistentSchema = Schema.Struct({
16
16
  name: Schema.optional(Schema.String),
17
17
  typename: TypenameSchema,
18
18
  version: VersionSchema,
@@ -22,7 +22,7 @@ const PersistentEchoSchema = Schema.Struct({
22
22
  typename: 'dxos.org/type/Schema',
23
23
  version: '0.1.0',
24
24
  }),
25
+ LabelAnnotation.set(['name']),
25
26
  );
26
- export interface PersistentSchema extends Schema.Schema.Type<typeof PersistentEchoSchema> {}
27
- export interface PersistentSchemaEncoded extends Schema.Schema.Encoded<typeof PersistentEchoSchema> {}
28
- export const PersistentSchema: Schema.Schema<PersistentSchema, PersistentSchemaEncoded> = PersistentEchoSchema;
27
+
28
+ export interface PersistentSchema extends Schema.Schema.Type<typeof PersistentSchema> {}
@@ -9,20 +9,6 @@ import { type ObjectId } from '@dxos/keys';
9
9
 
10
10
  import { type ATTR_META, type ObjectMeta } from './meta';
11
11
 
12
- /**
13
- * Marker interface for object with an `id`.
14
- */
15
- export interface HasId {
16
- readonly id: ObjectId;
17
- }
18
-
19
- /**
20
- * Object that has an associated typename.
21
- * The typename is retrievable using {@link getTypename}.
22
- * The object can be used with {@link isInstanceOf} to check if it is an instance of a schema.
23
- */
24
- export type HasTypename = {};
25
-
26
12
  /**
27
13
  * Base type for all data objects (reactive, ECHO, and other raw objects).
28
14
  * NOTE: This describes the base type for all database objects.
@@ -33,19 +19,19 @@ export type HasTypename = {};
33
19
  export type AnyProperties = Record<string, any>;
34
20
 
35
21
  /**
36
- * Canonical type for all ECHO objects.
22
+ * Canonical type for all ECHO entities (objects and relations).
37
23
  */
38
- export interface AnyEchoObject extends HasId, HasTypename {}
39
-
40
- // TODO(dmaretskyi): Remove; this type effectively disables type safety due to `any`.
41
- export type WithId<T extends AnyProperties = AnyProperties> = T & HasId;
24
+ // TODO(wittjosiah): Remove. Prefer higher level types (e.g. Entity.Unknown).
25
+ export interface AnyEntity {
26
+ readonly id: ObjectId;
27
+ }
42
28
 
43
29
  export type ExcludeId<T extends AnyProperties> = Omit<T, 'id'>;
44
30
 
45
31
  export type PropertyKey<T extends AnyProperties> = Extract<keyof ExcludeId<T>, string>;
46
32
 
47
33
  // TODO(dmaretskyi): Remove. This should be using the symbol type.
48
- export type WithMeta = { [ATTR_META]?: ObjectMeta };
34
+ type WithMeta = { [ATTR_META]?: ObjectMeta };
49
35
 
50
36
  /**
51
37
  * The raw object should not include the ECHO id, but may include metadata.
@@ -4,10 +4,33 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
+ // NOTE: String literals are used instead of unique symbols for both KindId and SchemaKindId.
8
+ // Unique symbols cause TS4023 "cannot be named" errors when external packages
9
+ // try to export types that reference this key (e.g., `export const Graph = ...`).
10
+ // TypeScript cannot emit declaration files that reference unique symbols from
11
+ // external modules. Using a string literal allows the type to be inlined in
12
+ // declaration files, making the API portable across package boundaries.
13
+
14
+ /**
15
+ * String key used to identify the kind of an entity instance (object or relation).
16
+ */
17
+ export const KindId = '~@dxos/echo/Kind' as const;
18
+ export type KindId = typeof KindId;
19
+
20
+ /**
21
+ * String key used to identify the kind of a schema (object schema or relation schema).
22
+ * Parallels KindId which identifies instance kinds.
23
+ */
24
+ export const SchemaKindId = '~@dxos/echo/SchemaKind' as const;
25
+ export type SchemaKindId = typeof SchemaKindId;
26
+
7
27
  /**
8
- * Entity kind.
28
+ * String key used to brand snapshot types.
29
+ * Snapshots have SnapshotKindId instead of KindId, making them
30
+ * distinguishable from reactive objects at the type level.
9
31
  */
10
- const EntityKindId = Symbol.for('@dxos/echo/EntityKind');
32
+ export const SnapshotKindId = '~@dxos/echo/SnapshotKind' as const;
33
+ export type SnapshotKindId = typeof SnapshotKindId;
11
34
 
12
35
  /**
13
36
  * Kinds of entities stored in ECHO: objects and relations.
@@ -19,5 +42,13 @@ export enum EntityKind {
19
42
 
20
43
  export const EntityKindSchema = Schema.Enums(EntityKind);
21
44
 
22
- export const KindId: unique symbol = EntityKindId as any;
23
- export type KindId = typeof KindId;
45
+ /**
46
+ * Typename for generic object references (Type.Obj / Type.Ref(Type.Obj)).
47
+ * Used when referencing any object without a specific schema.
48
+ */
49
+ export const ANY_OBJECT_TYPENAME = 'dxos.org/schema/AnyObject';
50
+
51
+ /**
52
+ * Version for generic object references.
53
+ */
54
+ export const ANY_OBJECT_VERSION = '0.0.0';