@dxos/echo 0.8.4-main.2e9d522 → 0.8.4-main.3c1ae3b

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 (478) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/browser/Annotation.mjs +31 -0
  3. package/dist/lib/browser/Annotation.mjs.map +7 -0
  4. package/dist/lib/browser/Database.mjs +14 -0
  5. package/dist/lib/browser/Database.mjs.map +7 -0
  6. package/dist/lib/browser/Entity.mjs +20 -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 +60 -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 +18 -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 +83 -0
  19. package/dist/lib/browser/Obj.mjs.map +7 -0
  20. package/dist/lib/browser/Order.mjs +11 -0
  21. package/dist/lib/browser/Order.mjs.map +7 -0
  22. package/dist/lib/browser/Query.mjs +25 -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 +21 -0
  27. package/dist/lib/browser/Ref.mjs.map +7 -0
  28. package/dist/lib/browser/Relation.mjs +33 -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 +25 -0
  33. package/dist/lib/browser/Tag.mjs.map +7 -0
  34. package/dist/lib/browser/Type.mjs +38 -0
  35. package/dist/lib/browser/Type.mjs.map +7 -0
  36. package/dist/lib/browser/chunk-3B2G6BW4.mjs +74 -0
  37. package/dist/lib/browser/chunk-3B2G6BW4.mjs.map +7 -0
  38. package/dist/lib/browser/chunk-5IN7XBIQ.mjs +24 -0
  39. package/dist/lib/browser/chunk-5IN7XBIQ.mjs.map +7 -0
  40. package/dist/lib/browser/chunk-6XVZF5VJ.mjs +2924 -0
  41. package/dist/lib/browser/chunk-6XVZF5VJ.mjs.map +7 -0
  42. package/dist/lib/browser/chunk-AGOWBKY6.mjs +94 -0
  43. package/dist/lib/browser/chunk-AGOWBKY6.mjs.map +7 -0
  44. package/dist/lib/browser/chunk-BD6MRI4M.mjs +113 -0
  45. package/dist/lib/browser/chunk-BD6MRI4M.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-DOPKE2FQ.mjs +32 -0
  49. package/dist/lib/browser/chunk-DOPKE2FQ.mjs.map +7 -0
  50. package/dist/lib/browser/chunk-ESLW4N7S.mjs +41 -0
  51. package/dist/lib/browser/chunk-ESLW4N7S.mjs.map +7 -0
  52. package/dist/lib/browser/chunk-F4YF6C3O.mjs +363 -0
  53. package/dist/lib/browser/chunk-F4YF6C3O.mjs.map +7 -0
  54. package/dist/lib/browser/chunk-FGFQWIZE.mjs +9 -0
  55. package/dist/lib/browser/chunk-FGFQWIZE.mjs.map +7 -0
  56. package/dist/lib/browser/chunk-INHXFXY5.mjs +22 -0
  57. package/dist/lib/browser/chunk-INHXFXY5.mjs.map +7 -0
  58. package/dist/lib/browser/chunk-JG4GH6LN.mjs +9 -0
  59. package/dist/lib/browser/chunk-JG4GH6LN.mjs.map +7 -0
  60. package/dist/lib/browser/chunk-MYCCGG2T.mjs +15 -0
  61. package/dist/lib/browser/chunk-MYCCGG2T.mjs.map +7 -0
  62. package/dist/lib/browser/chunk-NFH3POTD.mjs +37 -0
  63. package/dist/lib/browser/chunk-NFH3POTD.mjs.map +7 -0
  64. package/dist/lib/browser/chunk-O6FOICWT.mjs +57 -0
  65. package/dist/lib/browser/chunk-O6FOICWT.mjs.map +7 -0
  66. package/dist/lib/browser/chunk-P2B4BASR.mjs +288 -0
  67. package/dist/lib/browser/chunk-P2B4BASR.mjs.map +7 -0
  68. package/dist/lib/browser/chunk-QHC3ZYNC.mjs +152 -0
  69. package/dist/lib/browser/chunk-QHC3ZYNC.mjs.map +7 -0
  70. package/dist/lib/browser/chunk-QU7PWSZD.mjs +62 -0
  71. package/dist/lib/browser/chunk-QU7PWSZD.mjs.map +7 -0
  72. package/dist/lib/browser/chunk-RP4JV7FD.mjs +403 -0
  73. package/dist/lib/browser/chunk-RP4JV7FD.mjs.map +7 -0
  74. package/dist/lib/browser/chunk-V7TON6BX.mjs +151 -0
  75. package/dist/lib/browser/chunk-V7TON6BX.mjs.map +7 -0
  76. package/dist/lib/browser/chunk-WABSVOOX.mjs +303 -0
  77. package/dist/lib/browser/chunk-WABSVOOX.mjs.map +7 -0
  78. package/dist/lib/browser/chunk-XRHHSMHJ.mjs +39 -0
  79. package/dist/lib/browser/chunk-XRHHSMHJ.mjs.map +7 -0
  80. package/dist/lib/browser/chunk-ZIM3Y4ZK.mjs +38 -0
  81. package/dist/lib/browser/chunk-ZIM3Y4ZK.mjs.map +7 -0
  82. package/dist/lib/browser/index.mjs +72 -9
  83. package/dist/lib/browser/internal/index.mjs +347 -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 +322 -32
  87. package/dist/lib/browser/testing/index.mjs.map +4 -4
  88. package/dist/lib/node-esm/Annotation.mjs +31 -0
  89. package/dist/lib/node-esm/Annotation.mjs.map +7 -0
  90. package/dist/lib/node-esm/Database.mjs +14 -0
  91. package/dist/lib/node-esm/Database.mjs.map +7 -0
  92. package/dist/lib/node-esm/Entity.mjs +20 -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 +60 -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 +18 -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 +83 -0
  105. package/dist/lib/node-esm/Obj.mjs.map +7 -0
  106. package/dist/lib/node-esm/Order.mjs +11 -0
  107. package/dist/lib/node-esm/Order.mjs.map +7 -0
  108. package/dist/lib/node-esm/Query.mjs +25 -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 +21 -0
  113. package/dist/lib/node-esm/Ref.mjs.map +7 -0
  114. package/dist/lib/node-esm/Relation.mjs +33 -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 +25 -0
  119. package/dist/lib/node-esm/Tag.mjs.map +7 -0
  120. package/dist/lib/node-esm/Type.mjs +38 -0
  121. package/dist/lib/node-esm/Type.mjs.map +7 -0
  122. package/dist/lib/node-esm/chunk-5M5P2DCR.mjs +32 -0
  123. package/dist/lib/node-esm/chunk-5M5P2DCR.mjs.map +7 -0
  124. package/dist/lib/node-esm/chunk-6OTQZKHX.mjs +303 -0
  125. package/dist/lib/node-esm/chunk-6OTQZKHX.mjs.map +7 -0
  126. package/dist/lib/node-esm/chunk-76LEDWHO.mjs +152 -0
  127. package/dist/lib/node-esm/chunk-76LEDWHO.mjs.map +7 -0
  128. package/dist/lib/node-esm/chunk-AGHZH33D.mjs +9 -0
  129. package/dist/lib/node-esm/chunk-AGHZH33D.mjs.map +7 -0
  130. package/dist/lib/node-esm/chunk-AJEMYSIR.mjs +22 -0
  131. package/dist/lib/node-esm/chunk-AJEMYSIR.mjs.map +7 -0
  132. package/dist/lib/node-esm/chunk-BJACR7QG.mjs +363 -0
  133. package/dist/lib/node-esm/chunk-BJACR7QG.mjs.map +7 -0
  134. package/dist/lib/node-esm/chunk-BYL2NPEA.mjs +37 -0
  135. package/dist/lib/node-esm/chunk-BYL2NPEA.mjs.map +7 -0
  136. package/dist/lib/node-esm/chunk-CCMFPJUT.mjs +74 -0
  137. package/dist/lib/node-esm/chunk-CCMFPJUT.mjs.map +7 -0
  138. package/dist/lib/node-esm/chunk-D5BW7KHR.mjs +39 -0
  139. package/dist/lib/node-esm/chunk-D5BW7KHR.mjs.map +7 -0
  140. package/dist/lib/node-esm/chunk-DJX53IQ3.mjs +2924 -0
  141. package/dist/lib/node-esm/chunk-DJX53IQ3.mjs.map +7 -0
  142. package/dist/lib/node-esm/chunk-FWTPV5QD.mjs +94 -0
  143. package/dist/lib/node-esm/chunk-FWTPV5QD.mjs.map +7 -0
  144. package/dist/lib/node-esm/chunk-HLUDHPFO.mjs +403 -0
  145. package/dist/lib/node-esm/chunk-HLUDHPFO.mjs.map +7 -0
  146. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  147. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  148. package/dist/lib/node-esm/chunk-JYZSF62S.mjs +113 -0
  149. package/dist/lib/node-esm/chunk-JYZSF62S.mjs.map +7 -0
  150. package/dist/lib/node-esm/chunk-KUX5JEL2.mjs +57 -0
  151. package/dist/lib/node-esm/chunk-KUX5JEL2.mjs.map +7 -0
  152. package/dist/lib/node-esm/chunk-LDXRA5TC.mjs +288 -0
  153. package/dist/lib/node-esm/chunk-LDXRA5TC.mjs.map +7 -0
  154. package/dist/lib/node-esm/chunk-MOWUEW5P.mjs +15 -0
  155. package/dist/lib/node-esm/chunk-MOWUEW5P.mjs.map +7 -0
  156. package/dist/lib/node-esm/chunk-NHYOREKX.mjs +62 -0
  157. package/dist/lib/node-esm/chunk-NHYOREKX.mjs.map +7 -0
  158. package/dist/lib/node-esm/chunk-QVZZHCDS.mjs +9 -0
  159. package/dist/lib/node-esm/chunk-QVZZHCDS.mjs.map +7 -0
  160. package/dist/lib/node-esm/chunk-W3OLV7MG.mjs +41 -0
  161. package/dist/lib/node-esm/chunk-W3OLV7MG.mjs.map +7 -0
  162. package/dist/lib/node-esm/chunk-W5AQXKVF.mjs +38 -0
  163. package/dist/lib/node-esm/chunk-W5AQXKVF.mjs.map +7 -0
  164. package/dist/lib/node-esm/chunk-YNBFXTDG.mjs +24 -0
  165. package/dist/lib/node-esm/chunk-YNBFXTDG.mjs.map +7 -0
  166. package/dist/lib/node-esm/chunk-Z53QIBP2.mjs +151 -0
  167. package/dist/lib/node-esm/chunk-Z53QIBP2.mjs.map +7 -0
  168. package/dist/lib/node-esm/index.mjs +72 -9
  169. package/dist/lib/node-esm/internal/index.mjs +347 -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 +322 -32
  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 +179 -0
  177. package/dist/types/src/Database.d.ts.map +1 -0
  178. package/dist/types/src/Entity.d.ts +36 -0
  179. package/dist/types/src/Entity.d.ts.map +1 -0
  180. package/dist/types/src/Err.d.ts +68 -0
  181. package/dist/types/src/Err.d.ts.map +1 -0
  182. package/dist/types/src/Filter.d.ts +120 -0
  183. package/dist/types/src/Filter.d.ts.map +1 -0
  184. package/dist/types/src/Format.d.ts +4 -0
  185. package/dist/types/src/Format.d.ts.map +1 -0
  186. package/dist/types/src/Hypergraph.d.ts +60 -0
  187. package/dist/types/src/Hypergraph.d.ts.map +1 -0
  188. package/dist/types/src/JsonSchema.d.ts +9 -0
  189. package/dist/types/src/JsonSchema.d.ts.map +1 -0
  190. package/dist/types/src/Key.d.ts +1 -0
  191. package/dist/types/src/Key.d.ts.map +1 -1
  192. package/dist/types/src/Obj.d.ts +152 -35
  193. package/dist/types/src/Obj.d.ts.map +1 -1
  194. package/dist/types/src/Order.d.ts +11 -0
  195. package/dist/types/src/Order.d.ts.map +1 -0
  196. package/dist/types/src/Query.d.ts +107 -0
  197. package/dist/types/src/Query.d.ts.map +1 -0
  198. package/dist/types/src/Query.test.d.ts +2 -0
  199. package/dist/types/src/Query.test.d.ts.map +1 -0
  200. package/dist/types/src/QueryResult.d.ts +84 -0
  201. package/dist/types/src/QueryResult.d.ts.map +1 -0
  202. package/dist/types/src/Ref.d.ts +12 -10
  203. package/dist/types/src/Ref.d.ts.map +1 -1
  204. package/dist/types/src/Relation.d.ts +20 -14
  205. package/dist/types/src/Relation.d.ts.map +1 -1
  206. package/dist/types/src/SchemaRegistry.d.ts +73 -0
  207. package/dist/types/src/SchemaRegistry.d.ts.map +1 -0
  208. package/dist/types/src/Tag.d.ts +17 -0
  209. package/dist/types/src/Tag.d.ts.map +1 -0
  210. package/dist/types/src/Type.d.ts +39 -50
  211. package/dist/types/src/Type.d.ts.map +1 -1
  212. package/dist/types/src/index.d.ts +15 -3
  213. package/dist/types/src/index.d.ts.map +1 -1
  214. package/dist/types/src/internal/annotations/annotations.d.ts +179 -0
  215. package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -0
  216. package/dist/types/src/internal/annotations/annotations.test.d.ts +2 -0
  217. package/dist/types/src/internal/annotations/annotations.test.d.ts.map +1 -0
  218. package/dist/types/src/internal/annotations/index.d.ts +3 -0
  219. package/dist/types/src/internal/annotations/index.d.ts.map +1 -0
  220. package/dist/types/src/internal/annotations/util.d.ts +27 -0
  221. package/dist/types/src/internal/annotations/util.d.ts.map +1 -0
  222. package/dist/types/src/internal/entities/entity.d.ts +10 -0
  223. package/dist/types/src/internal/entities/entity.d.ts.map +1 -0
  224. package/dist/types/src/internal/entities/expando.d.ts +16 -0
  225. package/dist/types/src/internal/entities/expando.d.ts.map +1 -0
  226. package/dist/types/src/internal/entities/index.d.ts +6 -0
  227. package/dist/types/src/internal/entities/index.d.ts.map +1 -0
  228. package/dist/types/src/internal/entities/model.d.ts +70 -0
  229. package/dist/types/src/internal/entities/model.d.ts.map +1 -0
  230. package/dist/types/src/internal/entities/object.d.ts +11 -0
  231. package/dist/types/src/internal/entities/object.d.ts.map +1 -0
  232. package/dist/types/src/internal/entities/relation.d.ts +55 -0
  233. package/dist/types/src/internal/entities/relation.d.ts.map +1 -0
  234. package/dist/types/src/internal/entities/util.d.ts +2 -0
  235. package/dist/types/src/internal/entities/util.d.ts.map +1 -0
  236. package/dist/types/src/internal/formats/date.d.ts +63 -0
  237. package/dist/types/src/internal/formats/date.d.ts.map +1 -0
  238. package/dist/types/src/internal/formats/date.test.d.ts +2 -0
  239. package/dist/types/src/internal/formats/date.test.d.ts.map +1 -0
  240. package/dist/types/src/internal/formats/format.d.ts +32 -0
  241. package/dist/types/src/internal/formats/format.d.ts.map +1 -0
  242. package/dist/types/src/internal/formats/format.test.d.ts +2 -0
  243. package/dist/types/src/internal/formats/format.test.d.ts.map +1 -0
  244. package/dist/types/src/internal/formats/index.d.ts +8 -0
  245. package/dist/types/src/internal/formats/index.d.ts.map +1 -0
  246. package/dist/types/src/internal/formats/number.d.ts +31 -0
  247. package/dist/types/src/internal/formats/number.d.ts.map +1 -0
  248. package/dist/types/src/internal/formats/object.d.ts +35 -0
  249. package/dist/types/src/internal/formats/object.d.ts.map +1 -0
  250. package/dist/types/src/internal/formats/select.d.ts +13 -0
  251. package/dist/types/src/internal/formats/select.d.ts.map +1 -0
  252. package/dist/types/src/internal/formats/string.d.ts +42 -0
  253. package/dist/types/src/internal/formats/string.d.ts.map +1 -0
  254. package/dist/types/src/internal/formats/types.d.ts +72 -0
  255. package/dist/types/src/internal/formats/types.d.ts.map +1 -0
  256. package/dist/types/src/internal/index.d.ts +11 -0
  257. package/dist/types/src/internal/index.d.ts.map +1 -0
  258. package/dist/types/src/internal/json-schema/annotations.d.ts +19 -0
  259. package/dist/types/src/internal/json-schema/annotations.d.ts.map +1 -0
  260. package/dist/types/src/internal/json-schema/effect-schema.test.d.ts +2 -0
  261. package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +1 -0
  262. package/dist/types/src/internal/json-schema/index.d.ts +5 -0
  263. package/dist/types/src/internal/json-schema/index.d.ts.map +1 -0
  264. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts +7 -0
  265. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +1 -0
  266. package/dist/types/src/internal/json-schema/json-schema-type.d.ts +250 -0
  267. package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -0
  268. package/dist/types/src/internal/json-schema/json-schema.d.ts +29 -0
  269. package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -0
  270. package/dist/types/src/internal/json-schema/json-schema.test.d.ts +2 -0
  271. package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +1 -0
  272. package/dist/types/src/internal/object/common.d.ts +18 -0
  273. package/dist/types/src/internal/object/common.d.ts.map +1 -0
  274. package/dist/types/src/internal/object/create-object.d.ts +39 -0
  275. package/dist/types/src/internal/object/create-object.d.ts.map +1 -0
  276. package/dist/types/src/internal/object/create-object.test.d.ts +2 -0
  277. package/dist/types/src/internal/object/create-object.test.d.ts.map +1 -0
  278. package/dist/types/src/internal/object/deleted.d.ts +6 -0
  279. package/dist/types/src/internal/object/deleted.d.ts.map +1 -0
  280. package/dist/types/src/internal/object/ids.d.ts +6 -0
  281. package/dist/types/src/internal/object/ids.d.ts.map +1 -0
  282. package/dist/types/src/internal/object/index.d.ts +8 -0
  283. package/dist/types/src/internal/object/index.d.ts.map +1 -0
  284. package/dist/types/src/internal/object/inspect.d.ts +2 -0
  285. package/dist/types/src/internal/object/inspect.d.ts.map +1 -0
  286. package/dist/types/src/internal/object/json-serializer.d.ts +31 -0
  287. package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -0
  288. package/dist/types/src/internal/object/json-serializer.test.d.ts +2 -0
  289. package/dist/types/src/internal/object/json-serializer.test.d.ts.map +1 -0
  290. package/dist/types/src/internal/object/schema-validator.d.ts +15 -0
  291. package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -0
  292. package/dist/types/src/internal/object/schema-validator.test.d.ts +2 -0
  293. package/dist/types/src/internal/object/schema-validator.test.d.ts.map +1 -0
  294. package/dist/types/src/internal/object/typed-object.d.ts +31 -0
  295. package/dist/types/src/internal/object/typed-object.d.ts.map +1 -0
  296. package/dist/types/src/internal/object/typed-object.test.d.ts +2 -0
  297. package/dist/types/src/internal/object/typed-object.test.d.ts.map +1 -0
  298. package/dist/types/src/internal/proxy/handler.test.d.ts +2 -0
  299. package/dist/types/src/internal/proxy/handler.test.d.ts.map +1 -0
  300. package/dist/types/src/internal/proxy/index.d.ts +3 -0
  301. package/dist/types/src/internal/proxy/index.d.ts.map +1 -0
  302. package/dist/types/src/internal/proxy/make-object.d.ts +16 -0
  303. package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -0
  304. package/dist/types/src/internal/proxy/schema.test.d.ts +2 -0
  305. package/dist/types/src/internal/proxy/schema.test.d.ts.map +1 -0
  306. package/dist/types/src/internal/proxy/typed-handler.d.ts +44 -0
  307. package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -0
  308. package/dist/types/src/internal/proxy/typed-handler.test.d.ts +2 -0
  309. package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +1 -0
  310. package/dist/types/src/internal/proxy/typed-object.test.d.ts +2 -0
  311. package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +1 -0
  312. package/dist/types/src/internal/ref/index.d.ts +3 -0
  313. package/dist/types/src/internal/ref/index.d.ts.map +1 -0
  314. package/dist/types/src/internal/ref/ref-array.d.ts +21 -0
  315. package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -0
  316. package/dist/types/src/internal/ref/ref.d.ts +209 -0
  317. package/dist/types/src/internal/ref/ref.d.ts.map +1 -0
  318. package/dist/types/src/internal/ref/ref.test.d.ts +2 -0
  319. package/dist/types/src/internal/ref/ref.test.d.ts.map +1 -0
  320. package/dist/types/src/internal/schema/compose.d.ts +6 -0
  321. package/dist/types/src/internal/schema/compose.d.ts.map +1 -0
  322. package/dist/types/src/internal/schema/compose.test.d.ts +2 -0
  323. package/dist/types/src/internal/schema/compose.test.d.ts.map +1 -0
  324. package/dist/types/src/internal/schema/echo-schema.d.ts +168 -0
  325. package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -0
  326. package/dist/types/src/internal/schema/index.d.ts +5 -0
  327. package/dist/types/src/internal/schema/index.d.ts.map +1 -0
  328. package/dist/types/src/internal/schema/manipulation.d.ts +10 -0
  329. package/dist/types/src/internal/schema/manipulation.d.ts.map +1 -0
  330. package/dist/types/src/internal/schema/persistent-schema.d.ts +18 -0
  331. package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -0
  332. package/dist/types/src/internal/schema/snapshot.d.ts +6 -0
  333. package/dist/types/src/internal/schema/snapshot.d.ts.map +1 -0
  334. package/dist/types/src/internal/types/base.d.ts +37 -0
  335. package/dist/types/src/internal/types/base.d.ts.map +1 -0
  336. package/dist/types/src/internal/types/entity.d.ts +12 -0
  337. package/dist/types/src/internal/types/entity.d.ts.map +1 -0
  338. package/dist/types/src/internal/types/index.d.ts +6 -0
  339. package/dist/types/src/internal/types/index.d.ts.map +1 -0
  340. package/dist/types/src/internal/types/meta.d.ts +40 -0
  341. package/dist/types/src/internal/types/meta.d.ts.map +1 -0
  342. package/dist/types/src/internal/types/typename.d.ts +13 -0
  343. package/dist/types/src/internal/types/typename.d.ts.map +1 -0
  344. package/dist/types/src/internal/types/version.d.ts +15 -0
  345. package/dist/types/src/internal/types/version.d.ts.map +1 -0
  346. package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
  347. package/dist/types/src/testing/index.d.ts +3 -1
  348. package/dist/types/src/testing/index.d.ts.map +1 -1
  349. package/dist/types/src/testing/test-data.d.ts +18 -0
  350. package/dist/types/src/testing/test-data.d.ts.map +1 -0
  351. package/dist/types/src/testing/test-schema.d.ts +407 -0
  352. package/dist/types/src/testing/test-schema.d.ts.map +1 -0
  353. package/dist/types/src/testing/util.d.ts +16 -0
  354. package/dist/types/src/testing/util.d.ts.map +1 -0
  355. package/dist/types/tsconfig.tsbuildinfo +1 -1
  356. package/package.json +164 -33
  357. package/src/Annotation.ts +17 -0
  358. package/src/Database.ts +308 -0
  359. package/src/Entity.ts +51 -0
  360. package/src/Err.ts +18 -0
  361. package/src/Filter.ts +376 -0
  362. package/src/Format.ts +9 -0
  363. package/src/Hypergraph.ts +74 -0
  364. package/src/JsonSchema.ts +16 -0
  365. package/src/Key.ts +3 -0
  366. package/src/Obj.ts +407 -71
  367. package/src/Order.ts +34 -0
  368. package/src/Query.test.ts +346 -0
  369. package/src/Query.ts +279 -0
  370. package/src/QueryResult.ts +109 -0
  371. package/src/Ref.ts +25 -9
  372. package/src/Relation.ts +72 -46
  373. package/src/SchemaRegistry.ts +92 -0
  374. package/src/Tag.ts +40 -0
  375. package/src/Type.ts +98 -84
  376. package/src/index.ts +17 -4
  377. package/src/internal/README.md +87 -0
  378. package/src/internal/annotations/annotations.test.ts +96 -0
  379. package/src/internal/annotations/annotations.ts +488 -0
  380. package/src/internal/annotations/index.ts +6 -0
  381. package/src/internal/annotations/util.ts +72 -0
  382. package/src/internal/entities/entity.ts +109 -0
  383. package/src/internal/entities/expando.ts +23 -0
  384. package/src/internal/entities/index.ts +9 -0
  385. package/src/internal/entities/model.ts +129 -0
  386. package/src/internal/entities/object.ts +45 -0
  387. package/src/internal/entities/relation.ts +155 -0
  388. package/src/internal/entities/util.ts +33 -0
  389. package/src/internal/formats/date.test.ts +56 -0
  390. package/src/internal/formats/date.ts +217 -0
  391. package/src/internal/formats/format.test.ts +77 -0
  392. package/src/internal/formats/format.ts +54 -0
  393. package/src/internal/formats/index.ts +12 -0
  394. package/src/internal/formats/number.ts +89 -0
  395. package/src/internal/formats/object.ts +80 -0
  396. package/src/internal/formats/select.ts +18 -0
  397. package/src/internal/formats/string.ts +81 -0
  398. package/src/internal/formats/types.ts +186 -0
  399. package/src/internal/index.ts +38 -0
  400. package/src/internal/json-schema/annotations.ts +50 -0
  401. package/src/internal/json-schema/effect-schema.test.ts +143 -0
  402. package/src/internal/json-schema/index.ts +8 -0
  403. package/src/internal/json-schema/json-schema-normalize.ts +109 -0
  404. package/src/internal/json-schema/json-schema-type.ts +404 -0
  405. package/src/internal/json-schema/json-schema.test.ts +861 -0
  406. package/src/internal/json-schema/json-schema.ts +528 -0
  407. package/src/internal/object/common.ts +75 -0
  408. package/src/internal/object/create-object.test.ts +116 -0
  409. package/src/internal/object/create-object.ts +95 -0
  410. package/src/internal/object/deleted.ts +19 -0
  411. package/src/internal/object/ids.ts +12 -0
  412. package/src/internal/object/index.ts +11 -0
  413. package/src/internal/object/inspect.ts +46 -0
  414. package/src/internal/object/json-serializer.test.ts +94 -0
  415. package/src/internal/object/json-serializer.ts +230 -0
  416. package/src/internal/object/schema-validator.test.ts +186 -0
  417. package/src/internal/object/schema-validator.ts +244 -0
  418. package/src/internal/object/typed-object.test.ts +34 -0
  419. package/src/internal/object/typed-object.ts +94 -0
  420. package/src/internal/proxy/handler.test.ts +173 -0
  421. package/src/internal/proxy/index.ts +6 -0
  422. package/src/internal/proxy/make-object.ts +113 -0
  423. package/src/internal/proxy/schema.test.ts +137 -0
  424. package/src/internal/proxy/typed-handler.test.ts +102 -0
  425. package/src/internal/proxy/typed-handler.ts +233 -0
  426. package/src/internal/proxy/typed-object.test.ts +105 -0
  427. package/src/internal/ref/index.ts +6 -0
  428. package/src/internal/ref/ref-array.ts +39 -0
  429. package/src/internal/ref/ref.test.ts +101 -0
  430. package/src/internal/ref/ref.ts +525 -0
  431. package/src/internal/schema/compose.test.ts +42 -0
  432. package/src/internal/schema/compose.ts +37 -0
  433. package/src/internal/schema/echo-schema.ts +385 -0
  434. package/src/internal/schema/index.ts +8 -0
  435. package/src/internal/schema/manipulation.ts +92 -0
  436. package/src/internal/schema/persistent-schema.ts +28 -0
  437. package/src/internal/schema/snapshot.ts +25 -0
  438. package/src/internal/types/base.ts +57 -0
  439. package/src/internal/types/entity.ts +23 -0
  440. package/src/internal/types/index.ts +9 -0
  441. package/src/internal/types/meta.ts +76 -0
  442. package/src/internal/types/typename.ts +45 -0
  443. package/src/internal/types/version.ts +20 -0
  444. package/src/testing/api.test.ts +100 -0
  445. package/src/testing/index.ts +3 -1
  446. package/src/testing/test-data.ts +130 -0
  447. package/src/testing/test-schema.ts +224 -0
  448. package/src/testing/util.ts +78 -0
  449. package/dist/lib/browser/chunk-EUA7CM23.mjs +0 -619
  450. package/dist/lib/browser/chunk-EUA7CM23.mjs.map +0 -7
  451. package/dist/lib/node-esm/chunk-IV6BWGHK.mjs +0 -619
  452. package/dist/lib/node-esm/chunk-IV6BWGHK.mjs.map +0 -7
  453. package/dist/types/src/experimental/database.d.ts +0 -8
  454. package/dist/types/src/experimental/database.d.ts.map +0 -1
  455. package/dist/types/src/experimental/index.d.ts +0 -1
  456. package/dist/types/src/experimental/index.d.ts.map +0 -1
  457. package/dist/types/src/experimental/queue.d.ts +0 -8
  458. package/dist/types/src/experimental/queue.d.ts.map +0 -1
  459. package/dist/types/src/experimental/space.d.ts +0 -8
  460. package/dist/types/src/experimental/space.d.ts.map +0 -1
  461. package/dist/types/src/query/dsl.d.ts +0 -218
  462. package/dist/types/src/query/dsl.d.ts.map +0 -1
  463. package/dist/types/src/query/dsl.test.d.ts +0 -2
  464. package/dist/types/src/query/dsl.test.d.ts.map +0 -1
  465. package/dist/types/src/query/index.d.ts +0 -2
  466. package/dist/types/src/query/index.d.ts.map +0 -1
  467. package/dist/types/src/testing/types.d.ts +0 -113
  468. package/dist/types/src/testing/types.d.ts.map +0 -1
  469. package/src/experimental/database.ts +0 -11
  470. package/src/experimental/index.ts +0 -7
  471. package/src/experimental/queue.ts +0 -11
  472. package/src/experimental/space.ts +0 -11
  473. package/src/query/dsl.test.ts +0 -323
  474. package/src/query/dsl.ts +0 -646
  475. package/src/query/index.ts +0 -5
  476. package/src/test/api.test.ts +0 -173
  477. package/src/testing/types.ts +0 -91
  478. /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
@@ -0,0 +1,488 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Function from 'effect/Function';
6
+ import * as Option from 'effect/Option';
7
+ import * as Schema from 'effect/Schema';
8
+ import * as SchemaAST from 'effect/SchemaAST';
9
+
10
+ import { raise } from '@dxos/debug';
11
+ import { Reference } from '@dxos/echo-protocol';
12
+ import { type JsonPath, getField } from '@dxos/effect';
13
+ import { assertArgument, invariant } from '@dxos/invariant';
14
+ import { DXN } from '@dxos/keys';
15
+ import { type Primitive } from '@dxos/util';
16
+
17
+ import { type AnyProperties, EntityKind, TypeId, getSchema } from '../types';
18
+
19
+ import { createAnnotationHelper } from './util';
20
+
21
+ /**
22
+ * @internal
23
+ */
24
+ export const FIELD_PATH_ANNOTATION = 'path';
25
+
26
+ /**
27
+ * Sets the path for the field.
28
+ * @param path Data source path in the json path format. This is the field path in the source object.
29
+ */
30
+ // TODO(burdon): Field, vs. path vs. property.
31
+ export const FieldPath = (path: string) => PropertyMeta(FIELD_PATH_ANNOTATION, path);
32
+
33
+ //
34
+ // Type
35
+ //
36
+
37
+ /**
38
+ * ECHO identifier (for a stored schema).
39
+ * Must be a `dxn:echo:` URI.
40
+ */
41
+ export const TypeIdentifierAnnotationId = Symbol.for('@dxos/schema/annotation/TypeIdentifier');
42
+
43
+ export const getTypeIdentifierAnnotation = (schema: Schema.Schema.All) =>
44
+ Function.flow(
45
+ SchemaAST.getAnnotation<string>(TypeIdentifierAnnotationId),
46
+ Option.getOrElse(() => undefined),
47
+ )(schema.ast);
48
+
49
+ /**
50
+ * @returns DXN of the schema.
51
+ *
52
+ * For non-stored schema returns `dxn:type:`.
53
+ * For stored schema returns `dxn:echo:`.
54
+ */
55
+ export const getSchemaDXN = (schema: Schema.Schema.All): DXN | undefined => {
56
+ assertArgument(Schema.isSchema(schema), 'schema', 'invalid schema');
57
+ const id = getTypeIdentifierAnnotation(schema);
58
+ if (id) {
59
+ return DXN.parse(id);
60
+ }
61
+
62
+ // TODO(dmaretskyi): Add support for dynamic schema.
63
+ const objectAnnotation = getTypeAnnotation(schema);
64
+ if (!objectAnnotation) {
65
+ return undefined;
66
+ }
67
+
68
+ return DXN.fromTypenameAndVersion(objectAnnotation.typename, objectAnnotation.version);
69
+ };
70
+
71
+ /**
72
+ * Returns a reference that will be used to point to a schema.
73
+ * @deprecated Use {@link getSchemaDXN} instead.
74
+ */
75
+ export const getTypeReference = (schema: Schema.Schema.All | undefined): Reference | undefined => {
76
+ if (!schema) {
77
+ return undefined;
78
+ }
79
+
80
+ const schemaDXN = getSchemaDXN(schema);
81
+ if (!schemaDXN) {
82
+ return undefined;
83
+ }
84
+ return Reference.fromDXN(schemaDXN);
85
+ };
86
+
87
+ /**
88
+ * Returns a reference that will be used to point to a schema.
89
+ * @throws If it is not possible to reference this schema.
90
+ *
91
+ * @deprecated Use {@link getSchemaDXN} instead.
92
+ */
93
+ export const requireTypeReference = (schema: Schema.Schema.AnyNoContext): Reference => {
94
+ const typeReference = getTypeReference(schema);
95
+ if (typeReference == null) {
96
+ // TODO(burdon): Catalog user-facing errors (this is too verbose).
97
+ throw new Error('Schema must be defined via TypedObject.');
98
+ }
99
+
100
+ return typeReference;
101
+ };
102
+
103
+ /**
104
+ * @param input schema or a typename string
105
+ * @return type DXN
106
+ */
107
+ export const getTypeDXNFromSpecifier = (input: Schema.Schema.All | string): DXN => {
108
+ if (Schema.isSchema(input)) {
109
+ return getTypeReference(input)?.toDXN() ?? raise(new TypeError('Schema has no DXN'));
110
+ } else {
111
+ assertArgument(typeof input === 'string', 'input');
112
+ assertArgument(!input.startsWith('dxn:'), 'input');
113
+ return DXN.fromTypename(input);
114
+ }
115
+ };
116
+
117
+ //
118
+ // TypeAnnotation
119
+ //
120
+
121
+ /**
122
+ * Fully qualified globally unique typename.
123
+ * Example: `dxos.org/type/Message`
124
+ */
125
+ // TODO(burdon): Reconcile with short DXN format.
126
+ // TODO(burdon): Change "/type" => "/schema" throughout.
127
+ export const TypenameSchema = Schema.String.pipe(Schema.pattern(/^[a-zA-Z]\w+\.[a-zA-Z]\w{1,}\/[\w/_-]+$/)).annotations(
128
+ {
129
+ description: 'Fully qualified globally unique typename',
130
+ example: 'dxos.org/type/Message',
131
+ },
132
+ );
133
+
134
+ /**
135
+ * Semantic version format: `major.minor.patch`
136
+ * Example: `1.0.0`
137
+ */
138
+ export const VersionSchema = Schema.String.pipe(Schema.pattern(/^\d+.\d+.\d+$/)).annotations({
139
+ description: 'Semantic version format: `major.minor.patch`',
140
+ example: '1.0.0',
141
+ });
142
+
143
+ export const TypeMeta = Schema.Struct({
144
+ typename: TypenameSchema,
145
+ version: VersionSchema,
146
+ });
147
+
148
+ export interface TypeMeta extends Schema.Schema.Type<typeof TypeMeta> {}
149
+
150
+ /**
151
+ * Entity type.
152
+ */
153
+ export const TypeAnnotationId = Symbol.for('@dxos/schema/annotation/Type');
154
+
155
+ /**
156
+ * Payload stored under {@link TypeAnnotationId}.
157
+ */
158
+ export const TypeAnnotation = Schema.extend(
159
+ TypeMeta,
160
+ Schema.Struct({
161
+ kind: Schema.Enums(EntityKind),
162
+
163
+ /**
164
+ * If this is a relation, the schema of the source object.
165
+ * Must be present if entity kind is {@link EntityKind.Relation}.
166
+ */
167
+ sourceSchema: Schema.optional(DXN.Schema),
168
+
169
+ /**
170
+ * If this is a relation, the schema of the target object.
171
+ * Must be present if entity kind is {@link EntityKind.Relation}.
172
+ */
173
+ targetSchema: Schema.optional(DXN.Schema),
174
+ }),
175
+ );
176
+
177
+ export interface TypeAnnotation extends Schema.Schema.Type<typeof TypeAnnotation> {}
178
+
179
+ /**
180
+ * @returns {@link TypeAnnotation} from a schema.
181
+ * Schema must have been created with {@link TypedObject} or {@link TypedLink} or manually assigned an appropriate annotation.
182
+ */
183
+ export const getTypeAnnotation = (schema: Schema.Schema.All): TypeAnnotation | undefined => {
184
+ assertArgument(schema != null && schema.ast != null, 'schema', 'invalid schema');
185
+ return Function.flow(
186
+ SchemaAST.getAnnotation<TypeAnnotation>(TypeAnnotationId),
187
+ Option.getOrElse(() => undefined),
188
+ )(schema.ast);
189
+ };
190
+
191
+ /**
192
+ * @returns {@link EntityKind} from a schema.
193
+ */
194
+ export const getEntityKind = (schema: Schema.Schema.All): EntityKind | undefined => getTypeAnnotation(schema)?.kind;
195
+
196
+ /**
197
+ * @internal
198
+ * @returns Schema typename (without dxn: prefix or version number).
199
+ */
200
+ export const getSchemaTypename = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.typename;
201
+
202
+ /**
203
+ * @internal
204
+ * @returns Schema version in semver format.
205
+ */
206
+ export const getSchemaVersion = (schema: Schema.Schema.All): string | undefined => getTypeAnnotation(schema)?.version;
207
+
208
+ /**
209
+ * Gets the typename of the object without the version.
210
+ * Returns only the name portion, not the DXN.
211
+ * @example "example.org/type/Contact"
212
+ *
213
+ * @internal (use Obj.getTypename)
214
+ */
215
+ export const getTypename = (obj: AnyProperties): string | undefined => {
216
+ const schema = getSchema(obj);
217
+ if (schema != null) {
218
+ // Try to extract typename from DXN.
219
+ return getSchemaTypename(schema);
220
+ } else {
221
+ const type = getTypeDXN(obj);
222
+ return type?.asTypeDXN()?.type;
223
+ }
224
+ };
225
+
226
+ /**
227
+ * @internal (use Type.setTypename)
228
+ */
229
+ // TODO(dmaretskyi): Rename setTypeDXN.
230
+ export const setTypename = (obj: any, typename: DXN): void => {
231
+ invariant(typename instanceof DXN, 'Invalid type.');
232
+ Object.defineProperty(obj, TypeId, {
233
+ value: typename,
234
+ writable: false,
235
+ enumerable: false,
236
+ configurable: false,
237
+ });
238
+ };
239
+
240
+ /**
241
+ * @returns Object type as {@link DXN}.
242
+ * @returns undefined if the object doesn't have a type.
243
+ * @example `dxn:example.com/type/Person:1.0.0`
244
+ *
245
+ * @internal (use Obj.getTypeDXN)
246
+ */
247
+ // TODO(burdon): Narrow type.
248
+ export const getTypeDXN = (obj: AnyProperties): DXN | undefined => {
249
+ if (!obj) {
250
+ return undefined;
251
+ }
252
+
253
+ const type = (obj as any)[TypeId];
254
+ if (!type) {
255
+ return undefined;
256
+ }
257
+
258
+ invariant(type instanceof DXN, 'Invalid object.');
259
+ return type;
260
+ };
261
+
262
+ /**
263
+ * Checks if the object is an instance of the schema.
264
+ * Only typename is compared, the schema version is ignored.
265
+ *
266
+ * The following cases are considered to mean that the object is an instance of the schema:
267
+ * - Object was created with this exact schema.
268
+ * - Object was created with a different version of this schema.
269
+ * - Object was created with a different schema (maybe dynamic) that has the same typename.
270
+ */
271
+ // TODO(burdon): Can we use `Schema.is`?
272
+ export const isInstanceOf = <Schema extends Schema.Schema.AnyNoContext>(
273
+ schema: Schema,
274
+ object: any,
275
+ ): object is Schema.Schema.Type<Schema> => {
276
+ if (object == null) {
277
+ return false;
278
+ }
279
+
280
+ const schemaDXN = getSchemaDXN(schema);
281
+ if (!schemaDXN) {
282
+ throw new Error('Schema must have an object annotation.');
283
+ }
284
+
285
+ const type = getTypeDXN(object);
286
+ if (type && DXN.equals(type, schemaDXN)) {
287
+ return true;
288
+ }
289
+
290
+ const typename = getTypename(object);
291
+ if (!typename) {
292
+ return false;
293
+ }
294
+
295
+ const typeDXN = schemaDXN.asTypeDXN();
296
+ if (!typeDXN) {
297
+ return false;
298
+ }
299
+
300
+ return typeDXN.type === typename;
301
+ };
302
+
303
+ //
304
+ // PropertyMeta
305
+ //
306
+
307
+ /**
308
+ * PropertyMeta (metadata for dynamic schema properties).
309
+ * For user-defined annotations.
310
+ */
311
+ export const PropertyMetaAnnotationId = Symbol.for('@dxos/schema/annotation/PropertyMeta');
312
+
313
+ export type PropertyMetaValue = Primitive | Record<string, Primitive> | Primitive[];
314
+
315
+ export type PropertyMetaAnnotation = {
316
+ [name: string]: PropertyMetaValue;
317
+ };
318
+
319
+ // TODO(wittjosiah): Align with other annotations.
320
+ // TODO(wittjosiah): Why is this separate from FormatAnnotation?
321
+ export const PropertyMeta = (name: string, value: PropertyMetaValue) => {
322
+ return <A, I, R>(self: Schema.Schema<A, I, R>): Schema.Schema<A, I, R> => {
323
+ const existingMeta = self.ast.annotations[PropertyMetaAnnotationId] as PropertyMetaAnnotation;
324
+ return self.annotations({
325
+ [PropertyMetaAnnotationId]: {
326
+ ...existingMeta,
327
+ [name]: value,
328
+ },
329
+ });
330
+ };
331
+ };
332
+
333
+ export const getPropertyMetaAnnotation = <T>(prop: SchemaAST.PropertySignature, name: string) =>
334
+ Function.pipe(
335
+ SchemaAST.getAnnotation<PropertyMetaAnnotation>(PropertyMetaAnnotationId)(prop.type),
336
+ Option.map((meta) => meta[name] as T),
337
+ Option.getOrElse(() => undefined),
338
+ );
339
+
340
+ //
341
+ // Reference
342
+ //
343
+
344
+ /**
345
+ * Schema reference.
346
+ */
347
+ export const ReferenceAnnotationId = Symbol.for('@dxos/schema/annotation/Reference');
348
+
349
+ export type ReferenceAnnotationValue = TypeAnnotation;
350
+
351
+ export const getReferenceAnnotation = (schema: Schema.Schema.AnyNoContext) =>
352
+ Function.pipe(
353
+ SchemaAST.getAnnotation<ReferenceAnnotationValue>(ReferenceAnnotationId)(schema.ast),
354
+ Option.getOrElse(() => undefined),
355
+ );
356
+
357
+ /**
358
+ * SchemaMeta.
359
+ */
360
+ export const SchemaMetaSymbol = Symbol.for('@dxos/schema/SchemaMeta');
361
+ export type SchemaMeta = TypeMeta & { id: string };
362
+
363
+ /**
364
+ * Identifies a schema as a schema for a hidden system type.
365
+ */
366
+ export const SystemTypeAnnotationId = Symbol.for('@dxos/schema/annotation/SystemType');
367
+ export const SystemTypeAnnotation = createAnnotationHelper<boolean>(SystemTypeAnnotationId);
368
+
369
+ /**
370
+ * Identifies label property or JSON path expression.
371
+ * Either a string or an array of strings representing field accessors each matched in priority order.
372
+ */
373
+ export const LabelAnnotationId = Symbol.for('@dxos/schema/annotation/Label');
374
+ export const LabelAnnotation = createAnnotationHelper<string[]>(LabelAnnotationId);
375
+
376
+ /**
377
+ * Returns the label for a given object based on {@link LabelAnnotationId}.
378
+ */
379
+ // TODO(burdon): Convert to JsonPath?
380
+ export const getLabel = <S extends Schema.Schema.Any>(schema: S, object: Schema.Schema.Type<S>): string | undefined => {
381
+ const annotation = LabelAnnotation.get(schema).pipe(Option.getOrElse(() => ['name']));
382
+ for (const accessor of annotation) {
383
+ assertArgument(
384
+ typeof accessor === 'string',
385
+ 'accessor',
386
+ 'Label annotation must be a string or an array of strings',
387
+ );
388
+ const value = getField(object, accessor as JsonPath);
389
+ switch (typeof value) {
390
+ case 'string':
391
+ case 'number':
392
+ case 'boolean':
393
+ case 'bigint':
394
+ case 'symbol':
395
+ return value.toString();
396
+ case 'undefined':
397
+ case 'object':
398
+ case 'function':
399
+ continue;
400
+ }
401
+ }
402
+
403
+ return undefined;
404
+ };
405
+
406
+ /**
407
+ * Sets the label for a given object based on {@link LabelAnnotationId}.
408
+ */
409
+ export const setLabel = <S extends Schema.Schema.Any>(schema: S, object: Schema.Schema.Type<S>, label: string) => {
410
+ const annotation = LabelAnnotation.get(schema).pipe(
411
+ Option.map((field) => field[0]),
412
+ Option.getOrElse(() => 'name'),
413
+ );
414
+ object[annotation] = label;
415
+ };
416
+
417
+ /**
418
+ * Identifies description property or JSON path expression.
419
+ * A string representing field accessor.
420
+ */
421
+ export const DescriptionAnnotationId = Symbol.for('@dxos/schema/annotation/Description');
422
+ export const DescriptionAnnotation = createAnnotationHelper<string>(DescriptionAnnotationId);
423
+
424
+ /**
425
+ * Returns the label for a given object based on {@link LabelAnnotationId}.
426
+ */
427
+ // TODO(burdon): Convert to JsonPath?
428
+ export const getDescription = <S extends Schema.Schema.Any>(
429
+ schema: S,
430
+ object: Schema.Schema.Type<S>,
431
+ ): string | undefined => {
432
+ const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));
433
+ assertArgument(typeof accessor === 'string', 'accessor', 'Description annotation must be a string');
434
+ const value = getField(object, accessor as JsonPath);
435
+ switch (typeof value) {
436
+ case 'string':
437
+ case 'number':
438
+ case 'boolean':
439
+ case 'bigint':
440
+ case 'symbol':
441
+ return value.toString();
442
+ case 'undefined':
443
+ case 'object':
444
+ case 'function':
445
+ default:
446
+ return undefined;
447
+ }
448
+ };
449
+
450
+ /**
451
+ * Sets the description for a given object based on {@link DescriptionAnnotationId}.
452
+ */
453
+ export const setDescription = <S extends Schema.Schema.Any>(
454
+ schema: S,
455
+ object: Schema.Schema.Type<S>,
456
+ description: string,
457
+ ) => {
458
+ const accessor = DescriptionAnnotation.get(schema).pipe(Option.getOrElse(() => 'description'));
459
+ object[accessor] = description;
460
+ };
461
+
462
+ /**
463
+ * Identifies if a property should be included in a form or not.
464
+ * By default, all properties are included in forms, so this is opt-out.
465
+ */
466
+ // TODO(burdon): UI concern.
467
+ export const FormInputAnnotationId = Symbol.for('@dxos/schema/annotation/FormInput');
468
+ export const FormInputAnnotation = createAnnotationHelper<boolean>(FormInputAnnotationId);
469
+
470
+ /**
471
+ * Default field to be used on referenced schema to lookup the value.
472
+ */
473
+ export const FieldLookupAnnotationId = Symbol.for('@dxos/schema/annotation/FieldLookup');
474
+
475
+ /**
476
+ * Generate test data.
477
+ */
478
+ export const GeneratorAnnotationId = Symbol.for('@dxos/schema/annotation/Generator');
479
+
480
+ export type GeneratorAnnotationValue =
481
+ | string
482
+ | {
483
+ generator: string;
484
+ args?: any[];
485
+ probability?: number;
486
+ };
487
+
488
+ export const GeneratorAnnotation = createAnnotationHelper<GeneratorAnnotationValue>(GeneratorAnnotationId);
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './annotations';
6
+ export * from './util';
@@ -0,0 +1,72 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import type * as Option from 'effect/Option';
6
+ import type * as Schema from 'effect/Schema';
7
+ import * as SchemaAST from 'effect/SchemaAST';
8
+
9
+ import { assertArgument } from '@dxos/invariant';
10
+ import { DXN } from '@dxos/keys';
11
+
12
+ import { EntityKind } from '../types';
13
+
14
+ export interface AnnotationHelper<T> {
15
+ get: (schema: Schema.Schema.Any) => Option.Option<T>;
16
+ getFromAst: (ast: SchemaAST.AST) => Option.Option<T>;
17
+ set: (value: T) => <S extends Schema.Schema.Any>(schema: S) => S;
18
+ }
19
+
20
+ export const createAnnotationHelper = <T>(id: symbol): AnnotationHelper<T> => {
21
+ return {
22
+ get: (schema) => SchemaAST.getAnnotation(schema.ast, id),
23
+ getFromAst: (ast) => SchemaAST.getAnnotation(ast, id),
24
+ set:
25
+ (value) =>
26
+ <S extends Schema.Schema.Any>(schema: S) =>
27
+ schema.annotations({ [id]: value }) as S,
28
+ };
29
+ };
30
+
31
+ /**
32
+ * If property is optional returns the nested property, otherwise returns the property.
33
+ */
34
+ // TODO(wittjosiah): Is there a way to do this as a generic?
35
+ export const unwrapOptional = (property: SchemaAST.PropertySignature) => {
36
+ if (!property.isOptional || !SchemaAST.isUnion(property.type)) {
37
+ return property;
38
+ }
39
+
40
+ return property.type.types[0];
41
+ };
42
+
43
+ /**
44
+ * @see JSONSchemaAnnotationId
45
+ * @returns JSON-schema annotation so that the schema can be serialized with correct parameters.
46
+ */
47
+ // TODO(burdon): Required type.
48
+ export const makeTypeJsonSchemaAnnotation = (options: {
49
+ identifier?: string;
50
+ kind: EntityKind;
51
+ typename: string;
52
+ version: string;
53
+ relationSource?: string;
54
+ relationTarget?: string;
55
+ }) => {
56
+ assertArgument(!!options.relationSource === (options.kind === EntityKind.Relation), 'relationSource');
57
+ assertArgument(!!options.relationTarget === (options.kind === EntityKind.Relation), 'relationTarget');
58
+
59
+ const obj = {
60
+ // TODO(dmaretskyi): Should this include the version?
61
+ $id: options.identifier ?? DXN.fromTypename(options.typename).toString(),
62
+ entityKind: options.kind,
63
+ version: options.version,
64
+ typename: options.typename,
65
+ } as any;
66
+ if (options.kind === EntityKind.Relation) {
67
+ obj.relationSource = { $ref: options.relationSource };
68
+ obj.relationTarget = { $ref: options.relationTarget };
69
+ }
70
+
71
+ return obj;
72
+ };
@@ -0,0 +1,109 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+ import type * as SchemaAST from 'effect/SchemaAST';
7
+ import type * as Types from 'effect/Types';
8
+
9
+ import { type ToMutable } from '@dxos/util';
10
+
11
+ import { type TypeMeta } from '../annotations';
12
+ import { type HasId } from '../types';
13
+
14
+ // TODO(burdon): Define Schema type for `typename` and use consistently for all DXN-like properties.
15
+
16
+ // type RequiredKeys<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T];
17
+ export type EchoTypeSchemaProps<T, ExtraFields = {}> = Types.Simplify<HasId & ToMutable<T> & ExtraFields>;
18
+
19
+ // TODO(burdon): Rename EchoEntitySchema.
20
+ export interface EchoTypeSchema<Self extends Schema.Schema.Any, ExtraFields = {}>
21
+ extends TypeMeta,
22
+ Schema.AnnotableClass<
23
+ EchoTypeSchema<Self, ExtraFields>,
24
+ EchoTypeSchemaProps<Schema.Schema.Type<Self>, ExtraFields>,
25
+ EchoTypeSchemaProps<Schema.Schema.Encoded<Self>, ExtraFields>,
26
+ Schema.Schema.Context<Self>
27
+ > {
28
+ // make(
29
+ // props: RequiredKeys<Schema.TypeLiteral.Constructor<Fields, []>> extends never
30
+ // ? void | Simplify<Schema.TypeLiteral.Constructor<Fields, []>>
31
+ // : Simplify<Schema.TypeLiteral.Constructor<Fields, []>>,
32
+ // options?: MakeOptions,
33
+ // ): Simplify<Schema.TypeLiteral.Type<Fields, []>>;
34
+
35
+ instanceOf(value: unknown): boolean;
36
+ }
37
+
38
+ // type MakeOptions =
39
+ // | boolean
40
+ // | {
41
+ // readonly disableValidation?: boolean;
42
+ // };
43
+
44
+ // NOTE: Utils copied from Effect `Schema.ts`.
45
+ // const _ownKeys = (o: object): Array<PropertyKey> =>
46
+ // (Object.keys(o) as Array<PropertyKey>).concat(Object.getOwnPropertySymbols(o));
47
+
48
+ // const _lazilyMergeDefaults = (
49
+ // fields: Schema.Struct.Fields,
50
+ // out: Record<PropertyKey, unknown>,
51
+ // ): { [x: string | symbol]: unknown } => {
52
+ // const ownKeys = _ownKeys(fields);
53
+ // for (const key of ownKeys) {
54
+ // const field = fields[key];
55
+ // if (out[key] === undefined && Schema.isPropertySignature(field)) {
56
+ // const ast = field.ast;
57
+ // const defaultValue = ast._tag === 'PropertySignatureDeclaration' ? ast.defaultValue : ast.to.defaultValue;
58
+ // if (defaultValue !== undefined) {
59
+ // out[key] = defaultValue();
60
+ // }
61
+ // }
62
+ // }
63
+ // return out;
64
+ // };
65
+
66
+ // const _getDisableValidationMakeOption = (options: MakeOptions | undefined): boolean =>
67
+ // Predicate.isBoolean(options) ? options : options?.disableValidation ?? false;
68
+
69
+ /**
70
+ * @internal
71
+ */
72
+ export const makeEchoTypeSchema = <Self extends Schema.Schema.Any>(
73
+ // fields: Fields,
74
+ ast: SchemaAST.AST,
75
+ typename: string,
76
+ version: string,
77
+ ): EchoTypeSchema<Self> => {
78
+ return class EchoObjectSchemaClass extends Schema.make<
79
+ EchoTypeSchemaProps<Schema.Schema.Type<Self>>,
80
+ EchoTypeSchemaProps<Schema.Schema.Encoded<Self>>,
81
+ Schema.Schema.Context<Self>
82
+ >(ast) {
83
+ static readonly typename = typename;
84
+ static readonly version = version;
85
+
86
+ static override annotations(
87
+ annotations: Schema.Annotations.GenericSchema<EchoTypeSchemaProps<Schema.Schema.Type<Self>>>,
88
+ ): EchoTypeSchema<Self> {
89
+ const schema = Schema.make<EchoTypeSchemaProps<Schema.Schema.Type<Self>>>(ast).annotations(annotations);
90
+ return makeEchoTypeSchema<Self>(/* fields, */ schema.ast, typename, version);
91
+ }
92
+
93
+ // static make(
94
+ // props: RequiredKeys<Schema.TypeLiteral.Constructor<Fields, []>> extends never
95
+ // ? void | Simplify<Schema.TypeLiteral.Constructor<Fields, []>>
96
+ // : Simplify<Schema.TypeLiteral.Constructor<Fields, []>>,
97
+ // options?: MakeOptions,
98
+ // ): Simplify<Schema.TypeLiteral.Type<Fields, []>> {
99
+ // const propsWithDefaults: any = _lazilyMergeDefaults(fields, { ...(props as any) });
100
+ // return _getDisableValidationMakeOption(options)
101
+ // ? propsWithDefaults
102
+ // : ParseResult.validateSync(this)(propsWithDefaults);
103
+ // }
104
+
105
+ static instanceOf(value: unknown): boolean {
106
+ return Schema.is(this)(value);
107
+ }
108
+ };
109
+ };
@@ -0,0 +1,23 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { EchoObjectSchema } from './object';
8
+
9
+ export const EXPANDO_TYPENAME = 'dxos.org/type/Expando';
10
+
11
+ const ExpandoSchema = Schema.Struct({}, { key: Schema.String, value: Schema.Any }).pipe(
12
+ EchoObjectSchema({
13
+ typename: EXPANDO_TYPENAME,
14
+ version: '0.1.0',
15
+ }),
16
+ );
17
+
18
+ /**
19
+ * Expando object is an object with an arbitrary set of properties.
20
+ */
21
+ export interface Expando extends Schema.Schema.Type<typeof ExpandoSchema> {}
22
+ export interface ExpandoEncoded extends Schema.Schema.Encoded<typeof ExpandoSchema> {}
23
+ export const Expando: Schema.Schema<Expando, ExpandoEncoded> = ExpandoSchema;