@dxos/echo 0.8.4-main.5ea62a8 → 0.8.4-main.66e292d

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 (328) hide show
  1. package/dist/lib/browser/chunk-7GH6RXJ3.mjs +3683 -0
  2. package/dist/lib/browser/chunk-7GH6RXJ3.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-E4UTVJNF.mjs +1111 -0
  4. package/dist/lib/browser/chunk-E4UTVJNF.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +24 -1
  6. package/dist/lib/browser/internal/index.mjs +336 -0
  7. package/dist/lib/browser/internal/index.mjs.map +7 -0
  8. package/dist/lib/browser/meta.json +1 -1
  9. package/dist/lib/browser/testing/index.mjs +289 -31
  10. package/dist/lib/browser/testing/index.mjs.map +4 -4
  11. package/dist/lib/node-esm/chunk-JE5RXM2I.mjs +1111 -0
  12. package/dist/lib/node-esm/chunk-JE5RXM2I.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-M4B6BMD2.mjs +3683 -0
  14. package/dist/lib/node-esm/chunk-M4B6BMD2.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +24 -1
  16. package/dist/lib/node-esm/internal/index.mjs +336 -0
  17. package/dist/lib/node-esm/internal/index.mjs.map +7 -0
  18. package/dist/lib/node-esm/meta.json +1 -1
  19. package/dist/lib/node-esm/testing/index.mjs +289 -31
  20. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  21. package/dist/types/src/Annotation.d.ts +2 -0
  22. package/dist/types/src/Annotation.d.ts.map +1 -0
  23. package/dist/types/src/Database.d.ts +137 -0
  24. package/dist/types/src/Database.d.ts.map +1 -0
  25. package/dist/types/src/Entity.d.ts +36 -0
  26. package/dist/types/src/Entity.d.ts.map +1 -0
  27. package/dist/types/src/Format.d.ts +4 -0
  28. package/dist/types/src/Format.d.ts.map +1 -0
  29. package/dist/types/src/JsonSchema.d.ts +9 -0
  30. package/dist/types/src/JsonSchema.d.ts.map +1 -0
  31. package/dist/types/src/Key.d.ts +1 -0
  32. package/dist/types/src/Key.d.ts.map +1 -1
  33. package/dist/types/src/Obj.d.ts +121 -50
  34. package/dist/types/src/Obj.d.ts.map +1 -1
  35. package/dist/types/src/Ref.d.ts +10 -10
  36. package/dist/types/src/Ref.d.ts.map +1 -1
  37. package/dist/types/src/Relation.d.ts +18 -14
  38. package/dist/types/src/Relation.d.ts.map +1 -1
  39. package/dist/types/src/Tag.d.ts +17 -0
  40. package/dist/types/src/Tag.d.ts.map +1 -0
  41. package/dist/types/src/Type.d.ts +39 -50
  42. package/dist/types/src/Type.d.ts.map +1 -1
  43. package/dist/types/src/errors.d.ts +68 -0
  44. package/dist/types/src/errors.d.ts.map +1 -0
  45. package/dist/types/src/index.d.ts +9 -3
  46. package/dist/types/src/index.d.ts.map +1 -1
  47. package/dist/types/src/internal/annotations/annotations.d.ts +174 -0
  48. package/dist/types/src/internal/annotations/annotations.d.ts.map +1 -0
  49. package/dist/types/src/internal/annotations/annotations.test.d.ts +2 -0
  50. package/dist/types/src/internal/annotations/annotations.test.d.ts.map +1 -0
  51. package/dist/types/src/internal/annotations/index.d.ts +3 -0
  52. package/dist/types/src/internal/annotations/index.d.ts.map +1 -0
  53. package/dist/types/src/internal/annotations/util.d.ts +26 -0
  54. package/dist/types/src/internal/annotations/util.d.ts.map +1 -0
  55. package/dist/types/src/internal/entities/entity.d.ts +10 -0
  56. package/dist/types/src/internal/entities/entity.d.ts.map +1 -0
  57. package/dist/types/src/internal/entities/expando.d.ts +16 -0
  58. package/dist/types/src/internal/entities/expando.d.ts.map +1 -0
  59. package/dist/types/src/internal/entities/index.d.ts +6 -0
  60. package/dist/types/src/internal/entities/index.d.ts.map +1 -0
  61. package/dist/types/src/internal/entities/model.d.ts +70 -0
  62. package/dist/types/src/internal/entities/model.d.ts.map +1 -0
  63. package/dist/types/src/internal/entities/object.d.ts +11 -0
  64. package/dist/types/src/internal/entities/object.d.ts.map +1 -0
  65. package/dist/types/src/internal/entities/relation.d.ts +55 -0
  66. package/dist/types/src/internal/entities/relation.d.ts.map +1 -0
  67. package/dist/types/src/internal/entities/util.d.ts +2 -0
  68. package/dist/types/src/internal/entities/util.d.ts.map +1 -0
  69. package/dist/types/src/internal/formats/date.d.ts +63 -0
  70. package/dist/types/src/internal/formats/date.d.ts.map +1 -0
  71. package/dist/types/src/internal/formats/date.test.d.ts +2 -0
  72. package/dist/types/src/internal/formats/date.test.d.ts.map +1 -0
  73. package/dist/types/src/internal/formats/format.d.ts +32 -0
  74. package/dist/types/src/internal/formats/format.d.ts.map +1 -0
  75. package/dist/types/src/internal/formats/format.test.d.ts +2 -0
  76. package/dist/types/src/internal/formats/format.test.d.ts.map +1 -0
  77. package/dist/types/src/internal/formats/index.d.ts +8 -0
  78. package/dist/types/src/internal/formats/index.d.ts.map +1 -0
  79. package/dist/types/src/internal/formats/number.d.ts +31 -0
  80. package/dist/types/src/internal/formats/number.d.ts.map +1 -0
  81. package/dist/types/src/internal/formats/object.d.ts +35 -0
  82. package/dist/types/src/internal/formats/object.d.ts.map +1 -0
  83. package/dist/types/src/internal/formats/select.d.ts +11 -0
  84. package/dist/types/src/internal/formats/select.d.ts.map +1 -0
  85. package/dist/types/src/internal/formats/string.d.ts +38 -0
  86. package/dist/types/src/internal/formats/string.d.ts.map +1 -0
  87. package/dist/types/src/internal/formats/types.d.ts +68 -0
  88. package/dist/types/src/internal/formats/types.d.ts.map +1 -0
  89. package/dist/types/src/internal/index.d.ts +11 -0
  90. package/dist/types/src/internal/index.d.ts.map +1 -0
  91. package/dist/types/src/internal/json-schema/annotations.d.ts +19 -0
  92. package/dist/types/src/internal/json-schema/annotations.d.ts.map +1 -0
  93. package/dist/types/src/internal/json-schema/effect-schema.test.d.ts +2 -0
  94. package/dist/types/src/internal/json-schema/effect-schema.test.d.ts.map +1 -0
  95. package/dist/types/src/internal/json-schema/index.d.ts +5 -0
  96. package/dist/types/src/internal/json-schema/index.d.ts.map +1 -0
  97. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts +7 -0
  98. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +1 -0
  99. package/dist/types/src/internal/json-schema/json-schema-type.d.ts +250 -0
  100. package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -0
  101. package/dist/types/src/internal/json-schema/json-schema.d.ts +29 -0
  102. package/dist/types/src/internal/json-schema/json-schema.d.ts.map +1 -0
  103. package/dist/types/src/internal/json-schema/json-schema.test.d.ts +2 -0
  104. package/dist/types/src/internal/json-schema/json-schema.test.d.ts.map +1 -0
  105. package/dist/types/src/internal/object/common.d.ts +18 -0
  106. package/dist/types/src/internal/object/common.d.ts.map +1 -0
  107. package/dist/types/src/internal/object/create-object.d.ts +39 -0
  108. package/dist/types/src/internal/object/create-object.d.ts.map +1 -0
  109. package/dist/types/src/internal/object/create-object.test.d.ts +2 -0
  110. package/dist/types/src/internal/object/create-object.test.d.ts.map +1 -0
  111. package/dist/types/src/internal/object/deleted.d.ts +6 -0
  112. package/dist/types/src/internal/object/deleted.d.ts.map +1 -0
  113. package/dist/types/src/internal/object/ids.d.ts +6 -0
  114. package/dist/types/src/internal/object/ids.d.ts.map +1 -0
  115. package/dist/types/src/internal/object/index.d.ts +8 -0
  116. package/dist/types/src/internal/object/index.d.ts.map +1 -0
  117. package/dist/types/src/internal/object/inspect.d.ts +2 -0
  118. package/dist/types/src/internal/object/inspect.d.ts.map +1 -0
  119. package/dist/types/src/internal/object/json-serializer.d.ts +31 -0
  120. package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -0
  121. package/dist/types/src/internal/object/json-serializer.test.d.ts +2 -0
  122. package/dist/types/src/internal/object/json-serializer.test.d.ts.map +1 -0
  123. package/dist/types/src/internal/object/schema-validator.d.ts +15 -0
  124. package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -0
  125. package/dist/types/src/internal/object/schema-validator.test.d.ts +2 -0
  126. package/dist/types/src/internal/object/schema-validator.test.d.ts.map +1 -0
  127. package/dist/types/src/internal/object/typed-object.d.ts +31 -0
  128. package/dist/types/src/internal/object/typed-object.d.ts.map +1 -0
  129. package/dist/types/src/internal/object/typed-object.test.d.ts +2 -0
  130. package/dist/types/src/internal/object/typed-object.test.d.ts.map +1 -0
  131. package/dist/types/src/internal/proxy/handler.test.d.ts +2 -0
  132. package/dist/types/src/internal/proxy/handler.test.d.ts.map +1 -0
  133. package/dist/types/src/internal/proxy/index.d.ts +3 -0
  134. package/dist/types/src/internal/proxy/index.d.ts.map +1 -0
  135. package/dist/types/src/internal/proxy/make-object.d.ts +16 -0
  136. package/dist/types/src/internal/proxy/make-object.d.ts.map +1 -0
  137. package/dist/types/src/internal/proxy/schema.test.d.ts +2 -0
  138. package/dist/types/src/internal/proxy/schema.test.d.ts.map +1 -0
  139. package/dist/types/src/internal/proxy/typed-handler.d.ts +44 -0
  140. package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -0
  141. package/dist/types/src/internal/proxy/typed-handler.test.d.ts +2 -0
  142. package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +1 -0
  143. package/dist/types/src/internal/proxy/typed-object.test.d.ts +2 -0
  144. package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +1 -0
  145. package/dist/types/src/internal/ref/index.d.ts +3 -0
  146. package/dist/types/src/internal/ref/index.d.ts.map +1 -0
  147. package/dist/types/src/internal/ref/ref-array.d.ts +21 -0
  148. package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -0
  149. package/dist/types/src/internal/ref/ref.d.ts +209 -0
  150. package/dist/types/src/internal/ref/ref.d.ts.map +1 -0
  151. package/dist/types/src/internal/ref/ref.test.d.ts +2 -0
  152. package/dist/types/src/internal/ref/ref.test.d.ts.map +1 -0
  153. package/dist/types/src/internal/schema/compose.d.ts +6 -0
  154. package/dist/types/src/internal/schema/compose.d.ts.map +1 -0
  155. package/dist/types/src/internal/schema/compose.test.d.ts +2 -0
  156. package/dist/types/src/internal/schema/compose.test.d.ts.map +1 -0
  157. package/dist/types/src/internal/schema/echo-schema.d.ts +168 -0
  158. package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -0
  159. package/dist/types/src/internal/schema/index.d.ts +6 -0
  160. package/dist/types/src/internal/schema/index.d.ts.map +1 -0
  161. package/dist/types/src/internal/schema/manipulation.d.ts +10 -0
  162. package/dist/types/src/internal/schema/manipulation.d.ts.map +1 -0
  163. package/dist/types/src/internal/schema/persistent-schema.d.ts +18 -0
  164. package/dist/types/src/internal/schema/persistent-schema.d.ts.map +1 -0
  165. package/dist/types/src/internal/schema/runtime-schema-registry.d.ts +18 -0
  166. package/dist/types/src/internal/schema/runtime-schema-registry.d.ts.map +1 -0
  167. package/dist/types/src/internal/schema/snapshot.d.ts +6 -0
  168. package/dist/types/src/internal/schema/snapshot.d.ts.map +1 -0
  169. package/dist/types/src/internal/types/base.d.ts +37 -0
  170. package/dist/types/src/internal/types/base.d.ts.map +1 -0
  171. package/dist/types/src/internal/types/entity.d.ts +12 -0
  172. package/dist/types/src/internal/types/entity.d.ts.map +1 -0
  173. package/dist/types/src/internal/types/index.d.ts +6 -0
  174. package/dist/types/src/internal/types/index.d.ts.map +1 -0
  175. package/dist/types/src/internal/types/meta.d.ts +40 -0
  176. package/dist/types/src/internal/types/meta.d.ts.map +1 -0
  177. package/dist/types/src/internal/types/typename.d.ts +13 -0
  178. package/dist/types/src/internal/types/typename.d.ts.map +1 -0
  179. package/dist/types/src/internal/types/version.d.ts +15 -0
  180. package/dist/types/src/internal/types/version.d.ts.map +1 -0
  181. package/dist/types/src/query/filter.d.ts +167 -0
  182. package/dist/types/src/query/filter.d.ts.map +1 -0
  183. package/dist/types/src/query/index.d.ts +4 -1
  184. package/dist/types/src/query/index.d.ts.map +1 -1
  185. package/dist/types/src/query/order.d.ts +12 -0
  186. package/dist/types/src/query/order.d.ts.map +1 -0
  187. package/dist/types/src/query/query.d.ts +112 -0
  188. package/dist/types/src/query/query.d.ts.map +1 -0
  189. package/dist/types/src/query/query.test.d.ts +2 -0
  190. package/dist/types/src/query/query.test.d.ts.map +1 -0
  191. package/dist/types/src/query/testing.d.ts +51 -0
  192. package/dist/types/src/query/testing.d.ts.map +1 -0
  193. package/dist/types/src/query/types.d.ts +17 -0
  194. package/dist/types/src/query/types.d.ts.map +1 -0
  195. package/dist/types/src/query/util.d.ts +8 -0
  196. package/dist/types/src/query/util.d.ts.map +1 -0
  197. package/dist/types/src/{test → testing}/api.test.d.ts.map +1 -1
  198. package/dist/types/src/testing/index.d.ts +3 -1
  199. package/dist/types/src/testing/index.d.ts.map +1 -1
  200. package/dist/types/src/testing/test-data.d.ts +18 -0
  201. package/dist/types/src/testing/test-data.d.ts.map +1 -0
  202. package/dist/types/src/testing/test-schema.d.ts +337 -0
  203. package/dist/types/src/testing/test-schema.d.ts.map +1 -0
  204. package/dist/types/src/testing/util.d.ts +16 -0
  205. package/dist/types/src/testing/util.d.ts.map +1 -0
  206. package/dist/types/tsconfig.tsbuildinfo +1 -1
  207. package/package.json +49 -29
  208. package/src/Annotation.ts +17 -0
  209. package/src/Database.ts +189 -0
  210. package/src/Entity.ts +51 -0
  211. package/src/Format.ts +11 -0
  212. package/src/JsonSchema.ts +16 -0
  213. package/src/Key.ts +3 -0
  214. package/src/Obj.ts +353 -107
  215. package/src/Ref.ts +9 -10
  216. package/src/Relation.ts +68 -43
  217. package/src/Tag.ts +40 -0
  218. package/src/Type.ts +97 -85
  219. package/src/errors.ts +18 -0
  220. package/src/index.ts +13 -4
  221. package/src/internal/README.md +83 -0
  222. package/src/internal/annotations/annotations.test.ts +96 -0
  223. package/src/internal/annotations/annotations.ts +463 -0
  224. package/src/internal/annotations/index.ts +6 -0
  225. package/src/internal/annotations/util.ts +70 -0
  226. package/src/internal/entities/entity.ts +109 -0
  227. package/src/internal/entities/expando.ts +23 -0
  228. package/src/internal/entities/index.ts +9 -0
  229. package/src/internal/entities/model.ts +129 -0
  230. package/src/internal/entities/object.ts +45 -0
  231. package/src/internal/entities/relation.ts +155 -0
  232. package/src/internal/entities/util.ts +33 -0
  233. package/src/internal/formats/date.test.ts +56 -0
  234. package/src/internal/formats/date.ts +217 -0
  235. package/src/internal/formats/format.test.ts +77 -0
  236. package/src/internal/formats/format.ts +55 -0
  237. package/src/internal/formats/index.ts +12 -0
  238. package/src/internal/formats/number.ts +89 -0
  239. package/src/internal/formats/object.ts +80 -0
  240. package/src/internal/formats/select.ts +16 -0
  241. package/src/internal/formats/string.ts +76 -0
  242. package/src/internal/formats/types.ts +180 -0
  243. package/src/internal/index.ts +38 -0
  244. package/src/internal/json-schema/annotations.ts +50 -0
  245. package/src/internal/json-schema/effect-schema.test.ts +143 -0
  246. package/src/internal/json-schema/index.ts +8 -0
  247. package/src/internal/json-schema/json-schema-normalize.ts +109 -0
  248. package/src/internal/json-schema/json-schema-type.ts +404 -0
  249. package/src/internal/json-schema/json-schema.test.ts +859 -0
  250. package/src/internal/json-schema/json-schema.ts +528 -0
  251. package/src/internal/object/common.ts +75 -0
  252. package/src/internal/object/create-object.test.ts +116 -0
  253. package/src/internal/object/create-object.ts +95 -0
  254. package/src/internal/object/deleted.ts +19 -0
  255. package/src/internal/object/ids.ts +12 -0
  256. package/src/internal/object/index.ts +11 -0
  257. package/src/internal/object/inspect.ts +46 -0
  258. package/src/internal/object/json-serializer.test.ts +94 -0
  259. package/src/internal/object/json-serializer.ts +230 -0
  260. package/src/internal/object/schema-validator.test.ts +186 -0
  261. package/src/internal/object/schema-validator.ts +242 -0
  262. package/src/internal/object/typed-object.test.ts +34 -0
  263. package/src/internal/object/typed-object.ts +94 -0
  264. package/src/internal/proxy/handler.test.ts +173 -0
  265. package/src/internal/proxy/index.ts +6 -0
  266. package/src/internal/proxy/make-object.ts +113 -0
  267. package/src/internal/proxy/schema.test.ts +137 -0
  268. package/src/internal/proxy/typed-handler.test.ts +102 -0
  269. package/src/internal/proxy/typed-handler.ts +233 -0
  270. package/src/internal/proxy/typed-object.test.ts +105 -0
  271. package/src/internal/ref/index.ts +6 -0
  272. package/src/internal/ref/ref-array.ts +39 -0
  273. package/src/internal/ref/ref.test.ts +101 -0
  274. package/src/internal/ref/ref.ts +525 -0
  275. package/src/internal/schema/compose.test.ts +42 -0
  276. package/src/internal/schema/compose.ts +37 -0
  277. package/src/internal/schema/echo-schema.ts +385 -0
  278. package/src/internal/schema/index.ts +9 -0
  279. package/src/internal/schema/manipulation.ts +92 -0
  280. package/src/internal/schema/persistent-schema.ts +28 -0
  281. package/src/internal/schema/runtime-schema-registry.ts +78 -0
  282. package/src/internal/schema/snapshot.ts +25 -0
  283. package/src/internal/types/base.ts +58 -0
  284. package/src/internal/types/entity.ts +23 -0
  285. package/src/internal/types/index.ts +9 -0
  286. package/src/internal/types/meta.ts +76 -0
  287. package/src/internal/types/typename.ts +45 -0
  288. package/src/internal/types/version.ts +20 -0
  289. package/src/query/filter.ts +455 -0
  290. package/src/query/index.ts +5 -1
  291. package/src/query/order.ts +34 -0
  292. package/src/query/query.test.ts +334 -0
  293. package/src/query/query.ts +303 -0
  294. package/src/query/testing.ts +64 -0
  295. package/src/query/types.ts +23 -0
  296. package/src/query/util.ts +25 -0
  297. package/src/testing/api.test.ts +100 -0
  298. package/src/testing/index.ts +3 -1
  299. package/src/testing/test-data.ts +130 -0
  300. package/src/testing/test-schema.ts +213 -0
  301. package/src/testing/util.ts +78 -0
  302. package/dist/lib/browser/chunk-2KNTYMIW.mjs +0 -697
  303. package/dist/lib/browser/chunk-2KNTYMIW.mjs.map +0 -7
  304. package/dist/lib/node-esm/chunk-EXNNC62J.mjs +0 -697
  305. package/dist/lib/node-esm/chunk-EXNNC62J.mjs.map +0 -7
  306. package/dist/types/src/experimental/database.d.ts +0 -8
  307. package/dist/types/src/experimental/database.d.ts.map +0 -1
  308. package/dist/types/src/experimental/index.d.ts +0 -1
  309. package/dist/types/src/experimental/index.d.ts.map +0 -1
  310. package/dist/types/src/experimental/queue.d.ts +0 -8
  311. package/dist/types/src/experimental/queue.d.ts.map +0 -1
  312. package/dist/types/src/experimental/space.d.ts +0 -8
  313. package/dist/types/src/experimental/space.d.ts.map +0 -1
  314. package/dist/types/src/query/dsl.d.ts +0 -218
  315. package/dist/types/src/query/dsl.d.ts.map +0 -1
  316. package/dist/types/src/query/dsl.test.d.ts +0 -2
  317. package/dist/types/src/query/dsl.test.d.ts.map +0 -1
  318. package/dist/types/src/testing/types.d.ts +0 -113
  319. package/dist/types/src/testing/types.d.ts.map +0 -1
  320. package/src/experimental/database.ts +0 -11
  321. package/src/experimental/index.ts +0 -7
  322. package/src/experimental/queue.ts +0 -11
  323. package/src/experimental/space.ts +0 -11
  324. package/src/query/dsl.test.ts +0 -324
  325. package/src/query/dsl.ts +0 -646
  326. package/src/test/api.test.ts +0 -173
  327. package/src/testing/types.ts +0 -91
  328. /package/dist/types/src/{test → testing}/api.test.d.ts +0 -0
@@ -0,0 +1,180 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Function from 'effect/Function';
6
+ import type * as JSONSchema from 'effect/JSONSchema';
7
+ import * as Option from 'effect/Option';
8
+ import * as SchemaAST from 'effect/SchemaAST';
9
+
10
+ import { createAnnotationHelper } from '../annotations';
11
+ import { type JsonSchemaType } from '../json-schema';
12
+
13
+ // TODO(burdon): Rename PropertyType.
14
+ export type ScalarType =
15
+ | JSONSchema.JsonSchema7Object
16
+ | JSONSchema.JsonSchema7String
17
+ | JSONSchema.JsonSchema7Number
18
+ | JSONSchema.JsonSchema7Boolean
19
+ | JSONSchema.JsonSchema7Ref;
20
+
21
+ // TODO(burdon): Rename ValueType and change to disciminated union.
22
+ // export type ValueType = 'array' | 'object' | 'string' | 'number' | 'boolean' | 'ref';
23
+ export enum TypeEnum {
24
+ Array = 'array', // TODO(burdon): Remove?
25
+ Object = 'object',
26
+ String = 'string',
27
+ Number = 'number',
28
+ Boolean = 'boolean',
29
+ Ref = 'ref',
30
+ }
31
+
32
+ // TODO(burdon): Ref?
33
+ export const getTypeEnum = (property: JsonSchemaType): TypeEnum | undefined => {
34
+ switch (property.type) {
35
+ case 'array':
36
+ return TypeEnum.Array;
37
+ case 'object':
38
+ return TypeEnum.Object;
39
+ case 'string':
40
+ return TypeEnum.String;
41
+ case 'number':
42
+ return TypeEnum.Number;
43
+ case 'boolean':
44
+ return TypeEnum.Boolean;
45
+ default:
46
+ return undefined;
47
+ }
48
+ };
49
+
50
+ /**
51
+ * https://json-schema.org/understanding-json-schema/reference/schema
52
+ * https://json-schema.org/understanding-json-schema/reference/string#built-in-formats
53
+ */
54
+ export const FormatAnnotationId = Symbol.for('@dxos/schema/annotation/Format');
55
+
56
+ export const FormatAnnotation = createAnnotationHelper<TypeFormat>(FormatAnnotationId);
57
+
58
+ export const getFormatAnnotation = (node: SchemaAST.AST): TypeFormat | undefined =>
59
+ Function.pipe(SchemaAST.getAnnotation<TypeFormat>(FormatAnnotationId)(node), Option.getOrUndefined);
60
+
61
+ // TODO(burdon): Rename Format; Change to discriminated union?
62
+ export enum TypeFormat {
63
+ None = 'none',
64
+
65
+ //
66
+ // Scalar
67
+ //
68
+
69
+ String = 'string',
70
+ Number = 'number',
71
+ Boolean = 'boolean',
72
+ Ref = 'ref',
73
+
74
+ //
75
+ // { type: 'string' }
76
+ //
77
+
78
+ DID = 'did', // Users, etc.
79
+ DXN = 'dxn',
80
+ Email = 'email',
81
+ Formula = 'formula', // Spreadsheet formula.
82
+ Hostname = 'hostname',
83
+ JSON = 'json',
84
+ Markdown = 'markdown',
85
+ Regex = 'regex',
86
+ SingleSelect = 'single-select',
87
+ MultiSelect = 'multi-select',
88
+ URL = 'url',
89
+ UUID = 'uuid',
90
+
91
+ //
92
+ // { type: 'number' }
93
+ //
94
+
95
+ Currency = 'currency',
96
+ Integer = 'integer',
97
+ Percent = 'percent',
98
+ Timestamp = 'timestamp',
99
+
100
+ //
101
+ // { type: 'date' }
102
+ //
103
+
104
+ DateTime = 'date-time',
105
+ Date = 'date',
106
+ Time = 'time',
107
+ Duration = 'duration',
108
+
109
+ //
110
+ // { type: 'object' }
111
+ //
112
+
113
+ GeoPoint = 'lnglat',
114
+ }
115
+
116
+ export const FormatEnums = Object.values(TypeFormat).sort();
117
+
118
+ export const PropertyKind = {
119
+ type: TypeEnum,
120
+ format: TypeFormat,
121
+ };
122
+
123
+ /**
124
+ * Default formats
125
+ */
126
+ export const typeToFormat: Partial<Record<TypeEnum, TypeFormat>> = {
127
+ [TypeEnum.String]: TypeFormat.String,
128
+ [TypeEnum.Number]: TypeFormat.Number,
129
+ [TypeEnum.Boolean]: TypeFormat.Boolean,
130
+ };
131
+
132
+ /**
133
+ * Map of format to type.
134
+ */
135
+ export const formatToType: Record<TypeFormat, TypeEnum> = {
136
+ [TypeFormat.None]: undefined as any,
137
+ [TypeFormat.String]: TypeEnum.String,
138
+ [TypeFormat.Number]: TypeEnum.Number,
139
+ [TypeFormat.Boolean]: TypeEnum.Boolean,
140
+ [TypeFormat.Ref]: TypeEnum.Ref,
141
+
142
+ // Strings
143
+ [TypeFormat.DID]: TypeEnum.String,
144
+ [TypeFormat.DXN]: TypeEnum.String,
145
+ [TypeFormat.Email]: TypeEnum.String,
146
+ [TypeFormat.Formula]: TypeEnum.String,
147
+ [TypeFormat.Hostname]: TypeEnum.String,
148
+ [TypeFormat.JSON]: TypeEnum.String,
149
+ [TypeFormat.Markdown]: TypeEnum.String,
150
+ [TypeFormat.Regex]: TypeEnum.String,
151
+ [TypeFormat.URL]: TypeEnum.String,
152
+ [TypeFormat.UUID]: TypeEnum.String,
153
+ [TypeFormat.SingleSelect]: TypeEnum.String,
154
+ [TypeFormat.MultiSelect]: TypeEnum.Object,
155
+
156
+ // Dates
157
+ [TypeFormat.Date]: TypeEnum.String,
158
+ [TypeFormat.DateTime]: TypeEnum.String,
159
+ [TypeFormat.Duration]: TypeEnum.String,
160
+ [TypeFormat.Time]: TypeEnum.String,
161
+
162
+ // Numbers
163
+ [TypeFormat.Currency]: TypeEnum.Number,
164
+ [TypeFormat.Integer]: TypeEnum.Number,
165
+ [TypeFormat.Percent]: TypeEnum.Number,
166
+ [TypeFormat.Timestamp]: TypeEnum.Number,
167
+
168
+ // Objects
169
+ [TypeFormat.GeoPoint]: TypeEnum.Array,
170
+ };
171
+
172
+ /**
173
+ * Allowed value options for select.
174
+ */
175
+ export const OptionsAnnotationId = Symbol.for('@dxos/schema/annotation/Options');
176
+
177
+ export const getOptionsAnnotation = (node: SchemaAST.AST): OptionsAnnotationType[] | undefined =>
178
+ Function.pipe(SchemaAST.getAnnotation<OptionsAnnotationType[]>(OptionsAnnotationId)(node), Option.getOrUndefined);
179
+
180
+ export type OptionsAnnotationType = string | number;
@@ -0,0 +1,38 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ // TODO(burdon): Import directly (not part of ECHO API).
6
+ export { JsonPath, JsonProp, getValue, setValue, splitJsonPath } from '@dxos/effect';
7
+
8
+ export * from './annotations';
9
+ export * from './entities';
10
+ export * from './formats';
11
+ export * from './json-schema';
12
+ export * from './ref';
13
+ export * from './types';
14
+
15
+ // TODO(wittjosiah): Required to ensure types are portable (need to export all types required for downstream inference).
16
+ export * from './object';
17
+ export * from './proxy';
18
+ export * from './schema';
19
+
20
+ // export {
21
+ // createObject,
22
+ // createQueueDXN,
23
+ // isDeleted,
24
+ // objectFromJSON,
25
+ // objectToJSON,
26
+ // setRefResolverOnData,
27
+ // SchemaValidator,
28
+ // TypedObject,
29
+ // } from './object';
30
+ // export { makeObject } from './proxy';
31
+ // export {
32
+ // type BaseSchema,
33
+ // EchoSchema,
34
+ // ImmutableSchema,
35
+ // RuntimeSchemaRegistry,
36
+ // PersistentSchema,
37
+ // isMutable,
38
+ // } from './schema';
@@ -0,0 +1,50 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as SchemaAST from 'effect/SchemaAST';
6
+
7
+ import { GeneratorAnnotationId, LabelAnnotationId, PropertyMetaAnnotationId } from '../annotations';
8
+ import { CurrencyAnnotationId, FormatAnnotationId } from '../formats';
9
+ import { type JsonSchemaEchoAnnotations, type JsonSchemaType } from '../json-schema';
10
+
11
+ //
12
+ // This file configures annotations for JSON encoding/decoding.
13
+ //
14
+
15
+ // Go on the root level.
16
+ type RootJsonSchemaProperty = keyof JsonSchemaType;
17
+
18
+ // Go on the namespaced `annotations` property.
19
+ type NamespacedJsonSchemaProperty = keyof JsonSchemaEchoAnnotations;
20
+
21
+ /**
22
+ * List of annotations for JSON encoding/decoding.
23
+ * Omits default effect-schema annotations since they are encoded with default serializer.
24
+ */
25
+ // TODO(burdon): Reconcile with `EchoAnnotations`.
26
+ export const CustomAnnotations: Partial<Record<RootJsonSchemaProperty, symbol>> = {
27
+ format: FormatAnnotationId,
28
+ currency: CurrencyAnnotationId,
29
+ };
30
+
31
+ /**
32
+ * List of annotations for JSON decoding only.
33
+ * Includes default effect annotations.
34
+ */
35
+ export const DecodedAnnotations: Partial<Record<RootJsonSchemaProperty, symbol>> = {
36
+ title: SchemaAST.TitleAnnotationId,
37
+ description: SchemaAST.DescriptionAnnotationId,
38
+ };
39
+
40
+ /**
41
+ * Annotations that go into ECHO namespace in json-schema.
42
+ */
43
+ // TODO(dmaretskyi): Consider removing ECHO namespace and putting them at the top level.
44
+ // TODO(dmaretskyi): Move to format.ts when circular imports are solved
45
+ export const EchoAnnotations: Partial<Record<NamespacedJsonSchemaProperty, symbol>> = {
46
+ // TODO(dmaretskyi): `FieldLookupAnnotationId` might go here, but lets remove it entirely and use LabelAnnotation instead.
47
+ meta: PropertyMetaAnnotationId,
48
+ generator: GeneratorAnnotationId,
49
+ labelProp: LabelAnnotationId,
50
+ };
@@ -0,0 +1,143 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as JSONSchema from 'effect/JSONSchema';
6
+ import * as Option from 'effect/Option';
7
+ import * as Schema from 'effect/Schema';
8
+ import * as SchemaAST from 'effect/SchemaAST';
9
+ import { expect, test } from 'vitest';
10
+
11
+ import { log } from '@dxos/log';
12
+
13
+ test('json-schema annotations for filter refinement get combined', () => {
14
+ const type = Schema.Number.annotations({
15
+ jsonSchema: { foo: 'foo' },
16
+ }).pipe(Schema.filter(() => true, { jsonSchema: { bar: 'bar' } }));
17
+
18
+ const jsonSchema = JSONSchema.make(type);
19
+ expect(jsonSchema).toEqual({
20
+ $schema: 'http://json-schema.org/draft-07/schema#',
21
+ foo: 'foo',
22
+ bar: 'bar',
23
+ type: 'number',
24
+ });
25
+ });
26
+
27
+ test('json-schema annotations on types do not override the default serialization', () => {
28
+ const type = Schema.Number.annotations({
29
+ jsonSchema: { foo: 'foo' },
30
+ });
31
+
32
+ const jsonSchema = JSONSchema.make(type);
33
+ expect(jsonSchema).toEqual({
34
+ $schema: 'http://json-schema.org/draft-07/schema#',
35
+ foo: 'foo',
36
+ type: 'number',
37
+ });
38
+ });
39
+
40
+ // pass
41
+ test('number with title and description annotations', () => {
42
+ const number = Schema.Number.annotations({
43
+ title: 'My Title',
44
+ description: 'My Description',
45
+ });
46
+
47
+ expect(JSONSchema.make(number)).toEqual({
48
+ $schema: 'http://json-schema.org/draft-07/schema#',
49
+ type: 'number',
50
+ title: 'My Title',
51
+ description: 'My Description',
52
+ });
53
+ });
54
+
55
+ // pass
56
+ test('date with title and description annotations', () => {
57
+ const date = Schema.Date.annotations({
58
+ title: 'My Title',
59
+ description: 'My Description',
60
+ });
61
+
62
+ expect(JSONSchema.make(date)).toEqual({
63
+ $schema: 'http://json-schema.org/draft-07/schema#',
64
+ $defs: {
65
+ DateFromString: {
66
+ description: 'a string to be decoded into a Date',
67
+ type: 'string',
68
+ },
69
+ },
70
+ $ref: '#/$defs/DateFromString',
71
+ });
72
+ });
73
+
74
+ // fail
75
+ test('declare', () => {
76
+ class MyType {}
77
+ const type = Schema.declare<MyType>((x) => x instanceof MyType, {
78
+ jsonSchema: {
79
+ type: 'my-type',
80
+ },
81
+ });
82
+
83
+ expect(JSONSchema.make(type)).toEqual({
84
+ $schema: 'http://json-schema.org/draft-07/schema#',
85
+ type: 'my-type',
86
+ });
87
+
88
+ expect(type.pipe(Schema.is)(new MyType())).toBe(true);
89
+ expect(type.pipe(Schema.is)({})).toBe(false);
90
+
91
+ const withAnnotations = type.annotations({
92
+ title: 'My Title',
93
+ description: 'My Description',
94
+ });
95
+
96
+ expect(JSONSchema.make(withAnnotations)).toEqual({
97
+ $schema: 'http://json-schema.org/draft-07/schema#',
98
+ type: 'my-type',
99
+ title: 'My Title',
100
+ description: 'My Description',
101
+ });
102
+ });
103
+
104
+ // pass
105
+ test('declare with refinement', () => {
106
+ class MyType {}
107
+ const type = Schema.declare<MyType>((x) => x instanceof MyType, {
108
+ jsonSchema: {
109
+ type: 'my-type',
110
+ },
111
+ }).pipe(Schema.filter(() => true, { jsonSchema: {} }));
112
+
113
+ const named = type.annotations({
114
+ title: 'My Title',
115
+ description: 'My Description',
116
+ });
117
+
118
+ expect(JSONSchema.make(named)).toEqual({
119
+ $schema: 'http://json-schema.org/draft-07/schema#',
120
+ type: 'my-type',
121
+ title: 'My Title',
122
+ description: 'My Description',
123
+ });
124
+ });
125
+
126
+ test("default title annotations don't get serialized", () => {
127
+ const schema = Schema.String;
128
+
129
+ expect(SchemaAST.getTitleAnnotation(schema.ast).pipe(Option.getOrUndefined)).toEqual('string');
130
+ expect(SchemaAST.getDescriptionAnnotation(schema.ast).pipe(Option.getOrUndefined)).toEqual('a string');
131
+
132
+ expect(JSONSchema.make(schema)).toEqual({
133
+ $schema: 'http://json-schema.org/draft-07/schema#',
134
+ type: 'string',
135
+ });
136
+ });
137
+
138
+ test.skip('ast comparison', () => {
139
+ log.info('ast', {
140
+ default: Schema.String.ast,
141
+ annotated: Schema.String.annotations({ title: 'Custom title', description: 'Custom description' }).ast,
142
+ });
143
+ });
@@ -0,0 +1,8 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './annotations';
6
+ export * from './json-schema-normalize';
7
+ export * from './json-schema-type';
8
+ export * from './json-schema';
@@ -0,0 +1,109 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { JsonSchemaFields, type JsonSchemaType } from './json-schema-type';
6
+
7
+ /**
8
+ * Normalize schema to to draft-07 format.
9
+ * Note: the input type does not necessarily match the {@link JsonSchemaType} type.
10
+ */
11
+ export const normalizeSchema = (schema: JsonSchemaType): JsonSchemaType => {
12
+ const copy = structuredClone(schema);
13
+ go(copy);
14
+ return copy;
15
+ };
16
+
17
+ const go = (schema: JsonSchemaType) => {
18
+ if (typeof schema !== 'object' || schema === null) {
19
+ return;
20
+ }
21
+
22
+ if ((schema as any).exclusiveMaximum === true) {
23
+ schema.exclusiveMaximum = schema.maximum;
24
+ delete (schema as any).exclusiveMaximum;
25
+ } else if ((schema as any).exclusiveMaximum === false) {
26
+ delete (schema as any).exclusiveMaximum;
27
+ }
28
+
29
+ if ((schema as any).exclusiveMinimum === true) {
30
+ schema.exclusiveMinimum = schema.minimum;
31
+ delete (schema as any).exclusiveMinimum;
32
+ } else if ((schema as any).exclusiveMinimum === false) {
33
+ delete (schema as any).exclusiveMinimum;
34
+ }
35
+
36
+ // Delete all properties that are not in the JsonSchemaFields.
37
+ for (const key of Object.keys(schema)) {
38
+ if (!JsonSchemaFields.includes(key)) {
39
+ delete (schema as any)[key];
40
+ }
41
+ }
42
+
43
+ // Recursively normalize the schema.
44
+ // Recursively normalize the schema.
45
+ if (schema.properties) {
46
+ goOnRecord(schema.properties);
47
+ }
48
+ if (schema.patternProperties) {
49
+ goOnRecord(schema.patternProperties);
50
+ }
51
+ if (schema.propertyNames) {
52
+ go(schema.propertyNames);
53
+ }
54
+ if (schema.definitions) {
55
+ goOnRecord(schema.definitions);
56
+ }
57
+ if (schema.items) {
58
+ maybeGoOnArray(schema.items);
59
+ }
60
+ if (schema.additionalItems) {
61
+ maybeGoOnArray(schema.additionalItems);
62
+ }
63
+ if (schema.contains) {
64
+ go(schema.contains);
65
+ }
66
+ if (schema.if) {
67
+ go(schema.if);
68
+ }
69
+ if (schema.then) {
70
+ go(schema.then);
71
+ }
72
+ if (schema.else) {
73
+ go(schema.else);
74
+ }
75
+ if (schema.allOf) {
76
+ maybeGoOnArray(schema.allOf);
77
+ }
78
+ if (schema.anyOf) {
79
+ maybeGoOnArray(schema.anyOf);
80
+ }
81
+ if (schema.oneOf) {
82
+ maybeGoOnArray(schema.oneOf);
83
+ }
84
+ if (schema.not) {
85
+ go(schema.not);
86
+ }
87
+ if (schema.$defs) {
88
+ goOnRecord(schema.$defs);
89
+ }
90
+ if (schema.reference) {
91
+ go(schema.reference.schema);
92
+ }
93
+ };
94
+
95
+ const maybeGoOnArray = (value: any) => {
96
+ if (Array.isArray(value)) {
97
+ for (const item of value) {
98
+ go(item);
99
+ }
100
+ } else if (typeof value === 'object' && value !== null) {
101
+ go(value);
102
+ }
103
+ };
104
+
105
+ const goOnRecord = (record: Record<string, any>) => {
106
+ for (const key of Object.keys(record)) {
107
+ go(record[key]);
108
+ }
109
+ };