@dxos/echo 0.8.4-main.c1de068 → 0.8.4-main.c4373fc

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 (315) hide show
  1. package/README.md +1 -1
  2. package/dist/lib/browser/chunk-MWLA34S5.mjs +3843 -0
  3. package/dist/lib/browser/chunk-MWLA34S5.mjs.map +7 -0
  4. package/dist/lib/browser/chunk-OAZJQHVO.mjs +453 -0
  5. package/dist/lib/browser/chunk-OAZJQHVO.mjs.map +7 -0
  6. package/dist/lib/browser/chunk-ORIE2FMS.mjs +514 -0
  7. package/dist/lib/browser/chunk-ORIE2FMS.mjs.map +7 -0
  8. package/dist/lib/browser/index.mjs +26 -5
  9. package/dist/lib/browser/internal/index.mjs +326 -0
  10. package/dist/lib/browser/internal/index.mjs.map +7 -0
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/query/index.mjs +23 -0
  13. package/dist/lib/browser/query/index.mjs.map +7 -0
  14. package/dist/lib/browser/testing/index.mjs +260 -32
  15. package/dist/lib/browser/testing/index.mjs.map +4 -4
  16. package/dist/lib/node-esm/chunk-AXWVDOP7.mjs +453 -0
  17. package/dist/lib/node-esm/chunk-AXWVDOP7.mjs.map +7 -0
  18. package/dist/lib/node-esm/chunk-L4PBAJDP.mjs +514 -0
  19. package/dist/lib/node-esm/chunk-L4PBAJDP.mjs.map +7 -0
  20. package/dist/lib/node-esm/chunk-YTNLFBIK.mjs +3843 -0
  21. package/dist/lib/node-esm/chunk-YTNLFBIK.mjs.map +7 -0
  22. package/dist/lib/node-esm/index.mjs +26 -5
  23. package/dist/lib/node-esm/internal/index.mjs +326 -0
  24. package/dist/lib/node-esm/internal/index.mjs.map +7 -0
  25. package/dist/lib/node-esm/meta.json +1 -1
  26. package/dist/lib/node-esm/query/index.mjs +23 -0
  27. package/dist/lib/node-esm/query/index.mjs.map +7 -0
  28. package/dist/lib/node-esm/testing/index.mjs +260 -32
  29. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  30. package/dist/types/src/Obj.d.ts +111 -17
  31. package/dist/types/src/Obj.d.ts.map +1 -1
  32. package/dist/types/src/Ref.d.ts +1 -1
  33. package/dist/types/src/Ref.d.ts.map +1 -1
  34. package/dist/types/src/Relation.d.ts +11 -8
  35. package/dist/types/src/Relation.d.ts.map +1 -1
  36. package/dist/types/src/Type.d.ts +17 -18
  37. package/dist/types/src/Type.d.ts.map +1 -1
  38. package/dist/types/src/errors.d.ts +72 -0
  39. package/dist/types/src/errors.d.ts.map +1 -0
  40. package/dist/types/src/index.d.ts +3 -1
  41. package/dist/types/src/index.d.ts.map +1 -1
  42. package/dist/types/src/internal/ast/annotation-helper.d.ts +8 -0
  43. package/dist/types/src/internal/ast/annotation-helper.d.ts.map +1 -0
  44. package/dist/types/src/internal/ast/annotations.d.ts +119 -0
  45. package/dist/types/src/internal/ast/annotations.d.ts.map +1 -0
  46. package/dist/types/src/internal/ast/annotations.test.d.ts +2 -0
  47. package/dist/types/src/internal/ast/annotations.test.d.ts.map +1 -0
  48. package/dist/types/src/internal/ast/entity-kind.d.ts +10 -0
  49. package/dist/types/src/internal/ast/entity-kind.d.ts.map +1 -0
  50. package/dist/types/src/internal/ast/index.d.ts +5 -0
  51. package/dist/types/src/internal/ast/index.d.ts.map +1 -0
  52. package/dist/types/src/internal/ast/types.d.ts +6 -0
  53. package/dist/types/src/internal/ast/types.d.ts.map +1 -0
  54. package/dist/types/src/internal/formats/date.d.ts +63 -0
  55. package/dist/types/src/internal/formats/date.d.ts.map +1 -0
  56. package/dist/types/src/internal/formats/date.test.d.ts +2 -0
  57. package/dist/types/src/internal/formats/date.test.d.ts.map +1 -0
  58. package/dist/types/src/internal/formats/format.d.ts +30 -0
  59. package/dist/types/src/internal/formats/format.d.ts.map +1 -0
  60. package/dist/types/src/internal/formats/format.test.d.ts +2 -0
  61. package/dist/types/src/internal/formats/format.test.d.ts.map +1 -0
  62. package/dist/types/src/internal/formats/index.d.ts +8 -0
  63. package/dist/types/src/internal/formats/index.d.ts.map +1 -0
  64. package/dist/types/src/internal/formats/number.d.ts +31 -0
  65. package/dist/types/src/internal/formats/number.d.ts.map +1 -0
  66. package/dist/types/src/internal/formats/object.d.ts +35 -0
  67. package/dist/types/src/internal/formats/object.d.ts.map +1 -0
  68. package/dist/types/src/internal/formats/select.d.ts +11 -0
  69. package/dist/types/src/internal/formats/select.d.ts.map +1 -0
  70. package/dist/types/src/internal/formats/string.d.ts +38 -0
  71. package/dist/types/src/internal/formats/string.d.ts.map +1 -0
  72. package/dist/types/src/internal/formats/types.d.ts +68 -0
  73. package/dist/types/src/internal/formats/types.d.ts.map +1 -0
  74. package/dist/types/src/internal/index.d.ts +15 -0
  75. package/dist/types/src/internal/index.d.ts.map +1 -0
  76. package/dist/types/src/internal/json/annotations.d.ts +19 -0
  77. package/dist/types/src/internal/json/annotations.d.ts.map +1 -0
  78. package/dist/types/src/internal/json/effect-schema.test.d.ts +2 -0
  79. package/dist/types/src/internal/json/effect-schema.test.d.ts.map +1 -0
  80. package/dist/types/src/internal/json/index.d.ts +2 -0
  81. package/dist/types/src/internal/json/index.d.ts.map +1 -0
  82. package/dist/types/src/internal/json/json-schema.d.ts +32 -0
  83. package/dist/types/src/internal/json/json-schema.d.ts.map +1 -0
  84. package/dist/types/src/internal/json/json-schema.test.d.ts +2 -0
  85. package/dist/types/src/internal/json/json-schema.test.d.ts.map +1 -0
  86. package/dist/types/src/internal/json-schema/index.d.ts +3 -0
  87. package/dist/types/src/internal/json-schema/index.d.ts.map +1 -0
  88. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts +7 -0
  89. package/dist/types/src/internal/json-schema/json-schema-normalize.d.ts.map +1 -0
  90. package/dist/types/src/internal/json-schema/json-schema-type.d.ts +250 -0
  91. package/dist/types/src/internal/json-schema/json-schema-type.d.ts.map +1 -0
  92. package/dist/types/src/internal/object/accessors.d.ts +29 -0
  93. package/dist/types/src/internal/object/accessors.d.ts.map +1 -0
  94. package/dist/types/src/internal/object/common.d.ts +18 -0
  95. package/dist/types/src/internal/object/common.d.ts.map +1 -0
  96. package/dist/types/src/internal/object/create.d.ts +40 -0
  97. package/dist/types/src/internal/object/create.d.ts.map +1 -0
  98. package/dist/types/src/internal/object/create.test.d.ts +2 -0
  99. package/dist/types/src/internal/object/create.test.d.ts.map +1 -0
  100. package/dist/types/src/internal/object/deleted.d.ts +6 -0
  101. package/dist/types/src/internal/object/deleted.d.ts.map +1 -0
  102. package/dist/types/src/internal/object/entity.d.ts +22 -0
  103. package/dist/types/src/internal/object/entity.d.ts.map +1 -0
  104. package/dist/types/src/internal/object/expando.d.ts +14 -0
  105. package/dist/types/src/internal/object/expando.d.ts.map +1 -0
  106. package/dist/types/src/internal/object/ids.d.ts +6 -0
  107. package/dist/types/src/internal/object/ids.d.ts.map +1 -0
  108. package/dist/types/src/internal/object/index.d.ts +17 -0
  109. package/dist/types/src/internal/object/index.d.ts.map +1 -0
  110. package/dist/types/src/internal/object/inspect.d.ts +2 -0
  111. package/dist/types/src/internal/object/inspect.d.ts.map +1 -0
  112. package/dist/types/src/internal/object/json-serializer.d.ts +32 -0
  113. package/dist/types/src/internal/object/json-serializer.d.ts.map +1 -0
  114. package/dist/types/src/internal/object/json-serializer.test.d.ts +2 -0
  115. package/dist/types/src/internal/object/json-serializer.test.d.ts.map +1 -0
  116. package/dist/types/src/internal/object/meta.d.ts +31 -0
  117. package/dist/types/src/internal/object/meta.d.ts.map +1 -0
  118. package/dist/types/src/internal/object/model.d.ts +117 -0
  119. package/dist/types/src/internal/object/model.d.ts.map +1 -0
  120. package/dist/types/src/internal/object/relation.d.ts +17 -0
  121. package/dist/types/src/internal/object/relation.d.ts.map +1 -0
  122. package/dist/types/src/internal/object/schema-validator.d.ts +15 -0
  123. package/dist/types/src/internal/object/schema-validator.d.ts.map +1 -0
  124. package/dist/types/src/internal/object/schema-validator.test.d.ts +2 -0
  125. package/dist/types/src/internal/object/schema-validator.test.d.ts.map +1 -0
  126. package/dist/types/src/internal/object/typed-object.d.ts +31 -0
  127. package/dist/types/src/internal/object/typed-object.d.ts.map +1 -0
  128. package/dist/types/src/internal/object/typed-object.test.d.ts +2 -0
  129. package/dist/types/src/internal/object/typed-object.test.d.ts.map +1 -0
  130. package/dist/types/src/internal/object/typed-relation.d.ts +32 -0
  131. package/dist/types/src/internal/object/typed-relation.d.ts.map +1 -0
  132. package/dist/types/src/internal/object/typename.d.ts +15 -0
  133. package/dist/types/src/internal/object/typename.d.ts.map +1 -0
  134. package/dist/types/src/internal/object/version.d.ts +14 -0
  135. package/dist/types/src/internal/object/version.d.ts.map +1 -0
  136. package/dist/types/src/internal/projection/compose.d.ts +6 -0
  137. package/dist/types/src/internal/projection/compose.d.ts.map +1 -0
  138. package/dist/types/src/internal/projection/compose.test.d.ts +2 -0
  139. package/dist/types/src/internal/projection/compose.test.d.ts.map +1 -0
  140. package/dist/types/src/internal/projection/index.d.ts +2 -0
  141. package/dist/types/src/internal/projection/index.d.ts.map +1 -0
  142. package/dist/types/src/internal/proxy/handler.test.d.ts +2 -0
  143. package/dist/types/src/internal/proxy/handler.test.d.ts.map +1 -0
  144. package/dist/types/src/internal/proxy/reactive-object.d.ts +15 -0
  145. package/dist/types/src/internal/proxy/reactive-object.d.ts.map +1 -0
  146. package/dist/types/src/internal/proxy/schema.test.d.ts +2 -0
  147. package/dist/types/src/internal/proxy/schema.test.d.ts.map +1 -0
  148. package/dist/types/src/internal/proxy/typed-handler.d.ts +44 -0
  149. package/dist/types/src/internal/proxy/typed-handler.d.ts.map +1 -0
  150. package/dist/types/src/internal/proxy/typed-handler.test.d.ts +2 -0
  151. package/dist/types/src/internal/proxy/typed-handler.test.d.ts.map +1 -0
  152. package/dist/types/src/internal/proxy/typed-object.test.d.ts +2 -0
  153. package/dist/types/src/internal/proxy/typed-object.test.d.ts.map +1 -0
  154. package/dist/types/src/internal/query/index.d.ts +2 -0
  155. package/dist/types/src/internal/query/index.d.ts.map +1 -0
  156. package/dist/types/src/internal/query/query.d.ts +17 -0
  157. package/dist/types/src/internal/query/query.d.ts.map +1 -0
  158. package/dist/types/src/internal/ref/index.d.ts +3 -0
  159. package/dist/types/src/internal/ref/index.d.ts.map +1 -0
  160. package/dist/types/src/internal/ref/ref-array.d.ts +21 -0
  161. package/dist/types/src/internal/ref/ref-array.d.ts.map +1 -0
  162. package/dist/types/src/internal/ref/ref.d.ts +206 -0
  163. package/dist/types/src/internal/ref/ref.d.ts.map +1 -0
  164. package/dist/types/src/internal/ref/ref.test.d.ts +2 -0
  165. package/dist/types/src/internal/ref/ref.test.d.ts.map +1 -0
  166. package/dist/types/src/internal/schema/echo-schema.d.ts +168 -0
  167. package/dist/types/src/internal/schema/echo-schema.d.ts.map +1 -0
  168. package/dist/types/src/internal/schema/index.d.ts +7 -0
  169. package/dist/types/src/internal/schema/index.d.ts.map +1 -0
  170. package/dist/types/src/internal/schema/manipulation.d.ts +10 -0
  171. package/dist/types/src/internal/schema/manipulation.d.ts.map +1 -0
  172. package/dist/types/src/internal/schema/runtime-schema-registry.d.ts +18 -0
  173. package/dist/types/src/internal/schema/runtime-schema-registry.d.ts.map +1 -0
  174. package/dist/types/src/internal/schema/snapshot.d.ts +6 -0
  175. package/dist/types/src/internal/schema/snapshot.d.ts.map +1 -0
  176. package/dist/types/src/internal/schema/stored-schema.d.ts +13 -0
  177. package/dist/types/src/internal/schema/stored-schema.d.ts.map +1 -0
  178. package/dist/types/src/internal/testing/index.d.ts +3 -0
  179. package/dist/types/src/internal/testing/index.d.ts.map +1 -0
  180. package/dist/types/src/internal/testing/types.d.ts +455 -0
  181. package/dist/types/src/internal/testing/types.d.ts.map +1 -0
  182. package/dist/types/src/internal/testing/utils.d.ts +10 -0
  183. package/dist/types/src/internal/testing/utils.d.ts.map +1 -0
  184. package/dist/types/src/internal/types/index.d.ts +3 -0
  185. package/dist/types/src/internal/types/index.d.ts.map +1 -0
  186. package/dist/types/src/internal/types/types.d.ts +79 -0
  187. package/dist/types/src/internal/types/types.d.ts.map +1 -0
  188. package/dist/types/src/internal/types/types.test.d.ts +2 -0
  189. package/dist/types/src/internal/types/types.test.d.ts.map +1 -0
  190. package/dist/types/src/internal/types/util.d.ts +5 -0
  191. package/dist/types/src/internal/types/util.d.ts.map +1 -0
  192. package/dist/types/src/query/index.d.ts +2 -1
  193. package/dist/types/src/query/index.d.ts.map +1 -1
  194. package/dist/types/src/query/{dsl.d.ts → query.d.ts} +44 -15
  195. package/dist/types/src/query/query.d.ts.map +1 -0
  196. package/dist/types/src/query/query.test.d.ts +2 -0
  197. package/dist/types/src/query/query.test.d.ts.map +1 -0
  198. package/dist/types/src/query/tag.d.ts +18 -0
  199. package/dist/types/src/query/tag.d.ts.map +1 -0
  200. package/dist/types/src/testing/echo-schema.d.ts +7 -0
  201. package/dist/types/src/testing/echo-schema.d.ts.map +1 -0
  202. package/dist/types/src/testing/index.d.ts +2 -0
  203. package/dist/types/src/testing/index.d.ts.map +1 -1
  204. package/dist/types/src/testing/types.d.ts +18 -18
  205. package/dist/types/src/testing/types.d.ts.map +1 -1
  206. package/dist/types/tsconfig.tsbuildinfo +1 -1
  207. package/package.json +34 -16
  208. package/src/Obj.ts +250 -27
  209. package/src/Ref.ts +1 -2
  210. package/src/Relation.ts +25 -13
  211. package/src/Type.ts +32 -31
  212. package/src/errors.ts +18 -0
  213. package/src/index.ts +4 -1
  214. package/src/internal/ast/annotation-helper.ts +22 -0
  215. package/src/internal/ast/annotations.test.ts +98 -0
  216. package/src/internal/ast/annotations.ts +212 -0
  217. package/src/internal/ast/entity-kind.ts +15 -0
  218. package/src/internal/ast/index.ts +8 -0
  219. package/src/internal/ast/types.ts +17 -0
  220. package/src/internal/formats/date.test.ts +56 -0
  221. package/src/internal/formats/date.ts +217 -0
  222. package/src/internal/formats/format.test.ts +77 -0
  223. package/src/internal/formats/format.ts +52 -0
  224. package/src/internal/formats/index.ts +12 -0
  225. package/src/internal/formats/number.ts +89 -0
  226. package/src/internal/formats/object.ts +80 -0
  227. package/src/internal/formats/select.ts +16 -0
  228. package/src/internal/formats/string.ts +76 -0
  229. package/src/internal/formats/types.ts +175 -0
  230. package/src/internal/index.ts +22 -0
  231. package/src/internal/json/annotations.ts +50 -0
  232. package/src/internal/json/effect-schema.test.ts +143 -0
  233. package/src/internal/json/index.ts +5 -0
  234. package/src/internal/json/json-schema.test.ts +726 -0
  235. package/src/internal/json/json-schema.ts +548 -0
  236. package/src/internal/json-schema/index.ts +6 -0
  237. package/src/internal/json-schema/json-schema-normalize.ts +109 -0
  238. package/src/internal/json-schema/json-schema-type.ts +403 -0
  239. package/src/internal/object/accessors.ts +115 -0
  240. package/src/internal/object/common.ts +76 -0
  241. package/src/internal/object/create.test.ts +118 -0
  242. package/src/internal/object/create.ts +96 -0
  243. package/src/internal/object/deleted.ts +19 -0
  244. package/src/internal/object/entity.ts +204 -0
  245. package/src/internal/object/expando.ts +21 -0
  246. package/src/internal/object/ids.ts +12 -0
  247. package/src/internal/object/index.ts +20 -0
  248. package/src/internal/object/inspect.ts +48 -0
  249. package/src/internal/object/json-serializer.test.ts +99 -0
  250. package/src/internal/object/json-serializer.ts +225 -0
  251. package/src/internal/object/meta.ts +62 -0
  252. package/src/internal/object/model.ts +170 -0
  253. package/src/internal/object/relation.ts +24 -0
  254. package/src/internal/object/schema-validator.test.ts +186 -0
  255. package/src/internal/object/schema-validator.ts +241 -0
  256. package/src/internal/object/typed-object.test.ts +34 -0
  257. package/src/internal/object/typed-object.ts +81 -0
  258. package/src/internal/object/typed-relation.ts +85 -0
  259. package/src/internal/object/typename.ts +61 -0
  260. package/src/internal/object/version.ts +22 -0
  261. package/src/internal/projection/compose.test.ts +43 -0
  262. package/src/internal/projection/compose.ts +36 -0
  263. package/src/internal/projection/index.ts +5 -0
  264. package/src/internal/proxy/handler.test.ts +163 -0
  265. package/src/internal/proxy/reactive-object.ts +108 -0
  266. package/src/internal/proxy/schema.test.ts +136 -0
  267. package/src/internal/proxy/typed-handler.test.ts +102 -0
  268. package/src/internal/proxy/typed-handler.ts +228 -0
  269. package/src/internal/proxy/typed-object.test.ts +100 -0
  270. package/src/internal/query/index.ts +5 -0
  271. package/src/internal/query/query.ts +23 -0
  272. package/src/internal/ref/index.ts +6 -0
  273. package/src/internal/ref/ref-array.ts +39 -0
  274. package/src/internal/ref/ref.test.ts +100 -0
  275. package/src/internal/ref/ref.ts +521 -0
  276. package/src/internal/schema/echo-schema.ts +383 -0
  277. package/src/internal/schema/index.ts +10 -0
  278. package/src/internal/schema/manipulation.ts +86 -0
  279. package/src/internal/schema/runtime-schema-registry.ts +78 -0
  280. package/src/internal/schema/snapshot.ts +25 -0
  281. package/src/internal/schema/stored-schema.ts +26 -0
  282. package/src/internal/testing/index.ts +6 -0
  283. package/src/internal/testing/types.ts +211 -0
  284. package/src/internal/testing/utils.ts +54 -0
  285. package/src/internal/types/index.ts +6 -0
  286. package/src/internal/types/types.test.ts +48 -0
  287. package/src/internal/types/types.ts +176 -0
  288. package/src/internal/types/util.ts +9 -0
  289. package/src/query/index.ts +2 -1
  290. package/src/query/{dsl.test.ts → query.test.ts} +41 -2
  291. package/src/query/{dsl.ts → query.ts} +170 -32
  292. package/src/query/tag.ts +35 -0
  293. package/src/test/api.test.ts +17 -10
  294. package/src/testing/echo-schema.ts +39 -0
  295. package/src/testing/index.ts +2 -0
  296. package/src/testing/types.ts +1 -1
  297. package/dist/lib/browser/chunk-EUA7CM23.mjs +0 -619
  298. package/dist/lib/browser/chunk-EUA7CM23.mjs.map +0 -7
  299. package/dist/lib/node-esm/chunk-IV6BWGHK.mjs +0 -619
  300. package/dist/lib/node-esm/chunk-IV6BWGHK.mjs.map +0 -7
  301. package/dist/types/src/experimental/database.d.ts +0 -8
  302. package/dist/types/src/experimental/database.d.ts.map +0 -1
  303. package/dist/types/src/experimental/index.d.ts +0 -1
  304. package/dist/types/src/experimental/index.d.ts.map +0 -1
  305. package/dist/types/src/experimental/queue.d.ts +0 -8
  306. package/dist/types/src/experimental/queue.d.ts.map +0 -1
  307. package/dist/types/src/experimental/space.d.ts +0 -8
  308. package/dist/types/src/experimental/space.d.ts.map +0 -1
  309. package/dist/types/src/query/dsl.d.ts.map +0 -1
  310. package/dist/types/src/query/dsl.test.d.ts +0 -2
  311. package/dist/types/src/query/dsl.test.d.ts.map +0 -1
  312. package/src/experimental/database.ts +0 -11
  313. package/src/experimental/index.ts +0 -7
  314. package/src/experimental/queue.ts +0 -11
  315. package/src/experimental/space.ts +0 -11
@@ -0,0 +1,217 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+ import * as SchemaAST from 'effect/SchemaAST';
7
+
8
+ import { FormatAnnotation, FormatEnum } from './types';
9
+
10
+ /**
11
+ * Datetime values should be stored as ISO strings or unix numbers (ms) in UTC.
12
+ *
13
+ * NOTE: HyperFormula uses Excel's time format (null date 1900/01/01)
14
+ * It can be configured to use a different parser via `parseDateTime`.
15
+ * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#date-and-time-handling
16
+ * https://github.com/handsontable/hyperformula/blob/master/src/DateTimeHelper.ts
17
+ */
18
+
19
+ // TODO(burdon): Annotations not present in JSON.
20
+ // TODO(burdon): Timezone.
21
+ // TODO(burdon): Format for timestamp (Unix UTC or ISO 8601)?
22
+ // TODO(burdon): Refs
23
+ // - https://www.npmjs.com/package/numfmt
24
+ // - https://date-fns.org/docs/Getting-Started
25
+ // - https://github.com/date-fns/tz
26
+
27
+ /**
28
+ * Simple date compatible with HF.
29
+ */
30
+ export const SimpleDate = Schema.Struct({
31
+ year: Schema.Number.pipe(Schema.between(1900, 9999)),
32
+ month: Schema.Number.pipe(Schema.between(1, 12)),
33
+ day: Schema.Number.pipe(Schema.between(1, 31)),
34
+ });
35
+
36
+ export type SimpleDate = Schema.Schema.Type<typeof SimpleDate>;
37
+
38
+ export const toSimpleDate = (date: Date): SimpleDate => ({
39
+ year: date.getUTCFullYear(),
40
+ month: date.getUTCMonth() + 1,
41
+ day: date.getUTCDate(),
42
+ });
43
+
44
+ /**
45
+ * Simple time compatible with HF.
46
+ */
47
+ export const SimpleTime = Schema.Struct({
48
+ hours: Schema.Number.pipe(Schema.between(0, 23)),
49
+ minutes: Schema.Number.pipe(Schema.between(0, 59)),
50
+ seconds: Schema.Number.pipe(Schema.between(0, 59)),
51
+ });
52
+
53
+ export type SimpleTime = Schema.Schema.Type<typeof SimpleTime>;
54
+
55
+ export const toSimpleTime = (date: Date): SimpleTime => ({
56
+ hours: date.getUTCHours(),
57
+ minutes: date.getUTCSeconds(),
58
+ seconds: date.getUTCSeconds(),
59
+ });
60
+
61
+ /**
62
+ * Simple date-time compatible with HF.
63
+ */
64
+ export const SimpleDateTime = Schema.extend(SimpleDate, SimpleTime);
65
+
66
+ export type SimpleDateTime = Schema.Schema.Type<typeof SimpleDateTime>;
67
+
68
+ export const toSimpleDateTime = (date: Date): SimpleDateTime => ({
69
+ ...toSimpleDate(date),
70
+ ...toSimpleTime(date),
71
+ });
72
+
73
+ /**
74
+ * https://effect.website/docs/guides/schema/transformations#date-transformations
75
+ */
76
+
77
+ // TODO(burdon): Consider if transformations should be supported with Automerge.
78
+
79
+ /**
80
+ * Format: 2018-11-13
81
+ */
82
+ export const DateOnly = /* Schema.transformOrFail(Schema.String, SimpleDate, {
83
+ strict: true,
84
+ decode: (str, _, ast) => {
85
+ if (!isValidDateFormat(str)) {
86
+ return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected YYYY-MM-DD format'));
87
+ }
88
+ if (!isValidDate(str)) {
89
+ return ParseResult.fail(new ParseResult.Type(ast, str, 'Invalid date'));
90
+ }
91
+
92
+ const [year, month, day] = str.split('-').map(Number);
93
+ return ParseResult.succeed({ year, month, day });
94
+ },
95
+ encode: (date) => {
96
+ return ParseResult.succeed(
97
+ [
98
+ date.year.toString().padStart(4, '0'),
99
+ date.month.toString().padStart(2, '0'),
100
+ date.day.toString().padStart(2, '0'),
101
+ ].join('-'),
102
+ );
103
+ },
104
+ }) */ Schema.String.pipe(
105
+ FormatAnnotation.set(FormatEnum.Date),
106
+ Schema.annotations({
107
+ title: 'Date',
108
+ description: 'Valid date in ISO format',
109
+ }),
110
+ );
111
+
112
+ /**
113
+ * Format: 20:20:39+00:00
114
+ */
115
+ export const TimeOnly = /* Schema.transformOrFail(Schema.String, SimpleTime, {
116
+ strict: true,
117
+ decode: (str, _, ast) => {
118
+ if (!isValidTimeFormat(str)) {
119
+ return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected HH:mm:ss format'));
120
+ }
121
+
122
+ const [hours, minutes, seconds] = str.split(':').map(Number);
123
+ return ParseResult.succeed({ hours, minutes, seconds });
124
+ },
125
+ encode: (time) => {
126
+ return ParseResult.succeed(
127
+ [
128
+ time.hours.toString().padStart(2, '0'),
129
+ time.minutes.toString().padStart(2, '0'),
130
+ time.seconds.toString().padStart(2, '0'),
131
+ ].join(':'),
132
+ );
133
+ },
134
+ }) */ Schema.String.pipe(
135
+ FormatAnnotation.set(FormatEnum.Time),
136
+ Schema.annotations({
137
+ title: 'Time',
138
+ description: 'Valid time in ISO format',
139
+ }),
140
+ );
141
+
142
+ /**
143
+ * Format: 2018-11-13T20:20:39+00:00
144
+ */
145
+ export const DateTime = /* Schema.transformOrFail(Schema.String, SimpleDateTime, {
146
+ strict: false,
147
+ decode: (str, _, ast) => {
148
+ const [date, time] = str.split('T');
149
+ if (!isValidDateFormat(date)) {
150
+ return ParseResult.fail(new ParseResult.Type(ast, date, 'Expected YYYY-MM-DD format'));
151
+ }
152
+ if (!isValidDate(date)) {
153
+ return ParseResult.fail(new ParseResult.Type(ast, date, 'Invalid date'));
154
+ }
155
+ if (!isValidTimeFormat(time)) {
156
+ return ParseResult.fail(new ParseResult.Type(ast, str, 'Expected HH:mm:ss format'));
157
+ }
158
+
159
+ const [year, month, day] = date.split('-').map(Number);
160
+ const [hours, minutes, seconds] = time.split(':').map(Number);
161
+ return ParseResult.succeed({ year, month, day, hours, minutes, seconds });
162
+ },
163
+ encode: (datetime) => {
164
+ return ParseResult.succeed(
165
+ [
166
+ [
167
+ datetime.year.toString().padStart(4, '0'),
168
+ datetime.month.toString().padStart(2, '0'),
169
+ datetime.day.toString().padStart(2, '0'),
170
+ ].join('-'),
171
+ [
172
+ datetime.hours.toString().padStart(2, '0'),
173
+ datetime.minutes.toString().padStart(2, '0'),
174
+ datetime.seconds.toString().padStart(2, '0'),
175
+ ].join(':'),
176
+ ].join('T'),
177
+ );
178
+ },
179
+ }) */ Schema.String.pipe(
180
+ FormatAnnotation.set(FormatEnum.DateTime),
181
+ Schema.annotations({
182
+ title: 'DateTime',
183
+ description: 'Valid date and time in ISO format',
184
+ }),
185
+ );
186
+
187
+ /**
188
+ * https://datatracker.ietf.org/doc/html/rfc3339#appendix-A
189
+ */
190
+ // TODO(burdon): Define duration type.
191
+ export const Duration = Schema.String.pipe(
192
+ FormatAnnotation.set(FormatEnum.Duration),
193
+ Schema.annotations({
194
+ title: 'Duration',
195
+ description: 'Duration in ISO 8601 format',
196
+ [SchemaAST.ExamplesAnnotationId]: ['1h', '3D'],
197
+ }),
198
+ );
199
+
200
+ //
201
+ // Utils
202
+ //
203
+
204
+ // YYYY-MM-DD
205
+ const DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/;
206
+
207
+ const _isValidDateFormat = (str: string) => DATE_REGEX.test(str);
208
+
209
+ const _isValidDate = (str: string) => {
210
+ const date = new Date(str);
211
+ return !isNaN(date.getTime()) && date.toISOString().startsWith(str);
212
+ };
213
+
214
+ // HH:mm:ss
215
+ const TIME_REGEX = /^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$/;
216
+
217
+ const _isValidTimeFormat = (str: string) => TIME_REGEX.test(str);
@@ -0,0 +1,77 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+ import { describe, test } from 'vitest';
7
+
8
+ import { toJsonSchema } from '../json';
9
+
10
+ import { Format } from './format';
11
+ import { FormatEnum, TypeEnum, getTypeEnum } from './types';
12
+
13
+ describe('formats', () => {
14
+ test('annotations', ({ expect }) => {
15
+ const TestSchema = Schema.Struct({
16
+ name: Schema.String,
17
+ email: Schema.optional(Format.Email),
18
+ salary: Schema.optional(Format.Currency({ decimals: 2, code: 'usd' })),
19
+ website: Schema.optional(Format.URL),
20
+ birthday: Schema.optional(Format.Date),
21
+ started: Schema.optional(Format.DateTime),
22
+ active: Schema.optional(Schema.Boolean),
23
+ }).pipe(Schema.mutable);
24
+
25
+ type TestType = Schema.Schema.Type<typeof TestSchema>;
26
+
27
+ const jsonSchema = toJsonSchema(TestSchema);
28
+
29
+ const data: TestType = {
30
+ name: 'Alice',
31
+ email: 'alice@example.com',
32
+ birthday: '1999-06-11',
33
+ };
34
+
35
+ const validate = Schema.validateSync(TestSchema);
36
+ validate(data);
37
+
38
+ {
39
+ const prop = jsonSchema.properties!['active' as const];
40
+ expect(getTypeEnum(prop)).to.eq(TypeEnum.Boolean);
41
+ expect(prop).includes({
42
+ type: TypeEnum.Boolean,
43
+ });
44
+ }
45
+
46
+ {
47
+ const prop = jsonSchema.properties!['email' as const];
48
+ expect(getTypeEnum(prop)).to.eq(TypeEnum.String);
49
+ expect(prop).includes({
50
+ type: TypeEnum.String,
51
+ format: FormatEnum.Email,
52
+ title: 'Email',
53
+ });
54
+ }
55
+
56
+ {
57
+ const prop = jsonSchema.properties!['salary' as const];
58
+ expect(getTypeEnum(prop)).to.eq(TypeEnum.Number);
59
+ expect(prop).includes({
60
+ type: TypeEnum.Number,
61
+ format: FormatEnum.Currency,
62
+ title: 'Currency',
63
+ multipleOf: 0.01,
64
+ currency: 'USD',
65
+ });
66
+ }
67
+
68
+ {
69
+ const prop = jsonSchema.properties!['birthday' as const];
70
+ expect(getTypeEnum(prop)).to.eq(TypeEnum.String);
71
+ expect(prop).includes({
72
+ type: TypeEnum.String,
73
+ format: FormatEnum.Date,
74
+ });
75
+ }
76
+ });
77
+ });
@@ -0,0 +1,52 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import * as Keys from '@dxos/keys';
8
+
9
+ import * as DateUtil from './date';
10
+ import * as NumberUtil from './number';
11
+ import * as ObjectUtil from './object';
12
+ import * as StringUtil from './string';
13
+
14
+ // TODO(burdon): Consider factoring out to separate `@dxos/json-schema`
15
+ // TODO(burdon): Media encoding.
16
+ // - https://json-schema.org/understanding-json-schema/reference/non_json_data
17
+
18
+ /**
19
+ * Formats.
20
+ * https://json-schema.org/understanding-json-schema/reference/string#built-in-formats
21
+ * NOTE: A JSON Schema validator will ignore any format type that it does not understand.
22
+ */
23
+ // TODO(burdon): Add fields for `examples`, `message`, etc.
24
+ export namespace Format {
25
+ // Strings
26
+ export const DXN = Keys.DXN.Schema;
27
+ export const Email = StringUtil.Email;
28
+ export const Formula = StringUtil.Formula;
29
+ export const Hostname = StringUtil.Hostname;
30
+ export const JSON = StringUtil.JSON;
31
+ export const Markdown = StringUtil.Markdown;
32
+ export const Regex = StringUtil.Regex;
33
+ export const URL = StringUtil.URL;
34
+ export const UUID = Schema.UUID;
35
+
36
+ // Numbers
37
+ // TODO(burdon): BigInt.
38
+ export const Currency = NumberUtil.Currency;
39
+ export const Integer = NumberUtil.Integer;
40
+ export const Percent = NumberUtil.Percent;
41
+ export const Timestamp = NumberUtil.Timestamp;
42
+
43
+ // Dates and times
44
+ export const DateTime = DateUtil.DateTime;
45
+ export const Date = DateUtil.DateOnly;
46
+ export const Time = DateUtil.TimeOnly;
47
+ export const Duration = DateUtil.Duration;
48
+
49
+ // Objects
50
+ export const GeoPoint = ObjectUtil.GeoPoint;
51
+ export type GeoPoint = ObjectUtil.GeoPoint;
52
+ }
@@ -0,0 +1,12 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export type { SimpleDate, SimpleDateTime, SimpleTime } from './date';
6
+ export { CurrencyAnnotationId, DecimalPrecision, Currency } from './number';
7
+ export { GeoPoint, GeoLocation } from './object';
8
+
9
+ export * from './format';
10
+ export * from './select';
11
+ export * from './string';
12
+ export * from './types';
@@ -0,0 +1,89 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { FormatAnnotation, FormatEnum } from './types';
8
+
9
+ const encodeMultipleOf = (divisor: number) => 1 / Math.pow(10, divisor);
10
+
11
+ const encodeMultiple =
12
+ <A extends number>(divisor?: number) =>
13
+ <I, R>(self: Schema.Schema<A, I, R>) =>
14
+ divisor === undefined || divisor === 0 ? self : self.pipe(Schema.multipleOf(encodeMultipleOf(divisor)));
15
+
16
+ /**
17
+ * Convert number of digits to multipleOf annotation.
18
+ */
19
+ export const DecimalPrecision = Schema.transform(Schema.Number, Schema.Number, {
20
+ strict: true,
21
+ encode: (value) => encodeMultipleOf(value),
22
+ decode: (value) => Math.log10(1 / value),
23
+ }).annotations({
24
+ title: 'Number of digits',
25
+ });
26
+
27
+ export const CurrencyAnnotationId = Symbol.for('@dxos/schema/annotation/Currency');
28
+
29
+ export type CurrencyAnnotation = {
30
+ decimals?: number;
31
+ code?: string;
32
+ };
33
+
34
+ /**
35
+ * ISO 4217 currency code.
36
+ */
37
+ export const Currency = ({ decimals, code }: CurrencyAnnotation = { decimals: 2 }) =>
38
+ Schema.Number.pipe(
39
+ encodeMultiple(decimals),
40
+ FormatAnnotation.set(FormatEnum.Currency),
41
+ Schema.annotations({
42
+ title: 'Currency',
43
+ description: 'Currency value',
44
+ ...(code ? { [CurrencyAnnotationId]: code.toUpperCase() } : {}),
45
+ }),
46
+ );
47
+
48
+ export type PercentAnnotation = {
49
+ decimals?: number;
50
+ };
51
+
52
+ /**
53
+ * Integer.
54
+ */
55
+ export const Integer = () =>
56
+ Schema.Number.pipe(
57
+ Schema.int(),
58
+ FormatAnnotation.set(FormatEnum.Integer),
59
+ Schema.annotations({
60
+ title: 'Integer',
61
+ description: 'Integer value',
62
+ }),
63
+ );
64
+
65
+ /**
66
+ * Percent.
67
+ */
68
+ // TODO(burdon): Define min/max (e.g., 0, 1).
69
+ export const Percent = ({ decimals }: PercentAnnotation = { decimals: 2 }) =>
70
+ Schema.Number.pipe(
71
+ encodeMultiple(decimals),
72
+ FormatAnnotation.set(FormatEnum.Percent),
73
+ Schema.annotations({
74
+ title: 'Percent',
75
+ description: 'Percentage value',
76
+ }),
77
+ );
78
+
79
+ /**
80
+ * Unix timestamp.
81
+ * https://en.wikipedia.org/wiki/Unix_time
82
+ */
83
+ export const Timestamp = Schema.Number.pipe(
84
+ FormatAnnotation.set(FormatEnum.Timestamp),
85
+ Schema.annotations({
86
+ title: 'Timestamp',
87
+ description: 'Unix timestamp',
88
+ }),
89
+ );
@@ -0,0 +1,80 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { clamp } from '@dxos/util';
8
+
9
+ import { FormatAnnotation, FormatEnum } from './types';
10
+
11
+ /**
12
+ * GeoJSON Format
13
+ * https://datatracker.ietf.org/doc/html/rfc7946
14
+ * https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1
15
+ * https://en.wikipedia.org/wiki/Geographic_coordinate_system
16
+ * https://geojson.org
17
+ * {
18
+ * "type": "Point",
19
+ * "coordinates": [0, 51.47] // [longitude, latitude]
20
+ * }
21
+ * Note: optional third element for altitude.
22
+ */
23
+ export const GeoPoint = Schema.Tuple(
24
+ Schema.Number.pipe(Schema.annotations({ title: 'Longitude' }), Schema.clamp(-180, 180), Schema.multipleOf(0.00001)),
25
+ Schema.Number.pipe(Schema.annotations({ title: 'Latitude' }), Schema.clamp(-90, 90), Schema.multipleOf(0.00001)),
26
+ Schema.optionalElement(Schema.Number).annotations({
27
+ title: 'Height ASL (m)',
28
+ }),
29
+ ).pipe(
30
+ FormatAnnotation.set(FormatEnum.GeoPoint),
31
+ Schema.annotations({
32
+ title: 'GeoPoint',
33
+ description: 'GeoJSON Position',
34
+ }),
35
+ );
36
+
37
+ export type GeoPoint = Schema.Schema.Type<typeof GeoPoint>;
38
+
39
+ export type GeoLocation = {
40
+ longitude: number;
41
+ latitude: number;
42
+ height?: number;
43
+ };
44
+
45
+ /**
46
+ * Geolocation utilities for working with GeoPoint format.
47
+ */
48
+ export namespace GeoLocation {
49
+ /**
50
+ * Convert latitude and longitude to GeoPoint (GeoJSON format [longitude, latitude, height?]).
51
+ * Clamps values to valid ranges: latitude [-90, 90], longitude [-180, 180].
52
+ */
53
+ export const toGeoPoint = ({ longitude, latitude, height }: GeoLocation): GeoPoint => {
54
+ // TODO(ZaymonFC): Use schema validation instead of doing this manually.
55
+ const clampedLongitude = clamp(longitude, -180, 180);
56
+ const clampedLatitude = clamp(latitude, -90, 90);
57
+ return height !== undefined ? [clampedLongitude, clampedLatitude, height] : [clampedLongitude, clampedLatitude];
58
+ };
59
+
60
+ /**
61
+ * Extract latitude and longitude from GeoPoint (GeoJSON format [longitude, latitude, height?]).
62
+ */
63
+ export const fromGeoPoint = (geoPoint: GeoPoint | undefined): GeoLocation => {
64
+ if (!geoPoint) {
65
+ return { longitude: 0, latitude: 0 };
66
+ }
67
+
68
+ const result: GeoLocation = {
69
+ longitude: geoPoint[0],
70
+ latitude: geoPoint[1],
71
+ };
72
+
73
+ // Add height if defined.
74
+ if (geoPoint[2] !== undefined) {
75
+ result.height = geoPoint[2];
76
+ }
77
+
78
+ return result;
79
+ };
80
+ }
@@ -0,0 +1,16 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ /** Schema for a single select option. Used to define choices in a {single|multi}-select field. */
8
+ export const SelectOptionSchema = Schema.Struct({
9
+ /** Stable identifier for the option. */
10
+ id: Schema.NonEmptyString,
11
+ title: Schema.String,
12
+ /** Color palette used for visual styling. */
13
+ color: Schema.String,
14
+ }).pipe(Schema.mutable);
15
+
16
+ export type SelectOption = Schema.Schema.Type<typeof SelectOptionSchema>;
@@ -0,0 +1,76 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+ import * as SchemaAST from 'effect/SchemaAST';
7
+
8
+ import { FormatAnnotation, FormatEnum } from './types';
9
+
10
+ /**
11
+ * Email address (RFC 5321)
12
+ * https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.2
13
+ */
14
+ export const Email = Schema.String.pipe(
15
+ Schema.pattern(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/),
16
+ FormatAnnotation.set(FormatEnum.Email),
17
+ Schema.annotations({
18
+ title: 'Email',
19
+ description: 'Email address',
20
+ }),
21
+ );
22
+
23
+ /**
24
+ *
25
+ */
26
+ // TODO(burdon): Implement.
27
+ export const Formula = Schema.String.pipe(FormatAnnotation.set(FormatEnum.Formula));
28
+
29
+ /**
30
+ *
31
+ */
32
+ // TODO(burdon): Implement.
33
+ export const Hostname = Schema.String.pipe(FormatAnnotation.set(FormatEnum.Hostname));
34
+
35
+ /**
36
+ *
37
+ */
38
+ // TODO(burdon): Implement.
39
+ export const JSON = Schema.String.pipe(FormatAnnotation.set(FormatEnum.JSON));
40
+
41
+ /**
42
+ *
43
+ */
44
+ // TODO(burdon): Implement.
45
+ export const Markdown = Schema.String.pipe(FormatAnnotation.set(FormatEnum.Markdown));
46
+
47
+ /**
48
+ * Regex
49
+ * https://json-schema.org/understanding-json-schema/reference/regular_expressions
50
+ * https://ecma-international.org/publications-and-standards/standards/ecma-262
51
+ */
52
+ // TODO(burdon): Implement.
53
+ export const Regex = Schema.String.pipe(FormatAnnotation.set(FormatEnum.Regex));
54
+
55
+ /**
56
+ * https://datatracker.ietf.org/doc/html/rfc3986#section-1.1.3
57
+ */
58
+ export const URL = Schema.String.pipe(
59
+ Schema.pattern(/^(\w+?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/i),
60
+ FormatAnnotation.set(FormatEnum.URL),
61
+ Schema.annotations({
62
+ title: 'URL',
63
+ description: 'URL',
64
+ }),
65
+ );
66
+
67
+ /**
68
+ * UUID (RFC 4122)
69
+ * https://datatracker.ietf.org/doc/html/rfc4122
70
+ */
71
+ export const UUID = Schema.UUID.pipe(
72
+ FormatAnnotation.set(FormatEnum.UUID),
73
+ Schema.annotations({
74
+ [SchemaAST.ExamplesAnnotationId]: ['3e4666bf-d5e5-4aa7-b8ce-cefe41c7568a'],
75
+ }),
76
+ );