zeed 1.3.0 → 1.4.0

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 (575) hide show
  1. package/AGENTS.md +50 -211
  2. package/README.md +16 -0
  3. package/dist/_experiments/bitcask.cjs +243 -1
  4. package/dist/_experiments/bitcask.cjs.map +1 -1
  5. package/dist/_experiments/bitcask.mjs +230 -1
  6. package/dist/_experiments/bitcask.mjs.map +1 -1
  7. package/dist/bin-BAoS4qtm.mjs +593 -0
  8. package/dist/{bin-SPdenYkw.mjs.map → bin-BAoS4qtm.mjs.map} +1 -1
  9. package/dist/bin-Ddaz2lxM.cjs +862 -0
  10. package/dist/{bin-Ce3i6ABn.cjs.map → bin-Ddaz2lxM.cjs.map} +1 -1
  11. package/dist/browser/base64.cjs +14 -1
  12. package/dist/browser/base64.cjs.map +1 -1
  13. package/dist/browser/base64.mjs +12 -1
  14. package/dist/browser/base64.mjs.map +1 -1
  15. package/dist/browser/gravatar.cjs +186 -1
  16. package/dist/browser/gravatar.cjs.map +1 -1
  17. package/dist/browser/gravatar.mjs +184 -1
  18. package/dist/browser/gravatar.mjs.map +1 -1
  19. package/dist/browser/index.cjs +14 -1
  20. package/dist/browser/index.mjs +8 -1
  21. package/dist/browser/localstorage.cjs +46 -1
  22. package/dist/browser/localstorage.cjs.map +1 -1
  23. package/dist/browser/localstorage.mjs +45 -1
  24. package/dist/browser/localstorage.mjs.map +1 -1
  25. package/dist/browser/log/index.cjs +8 -1
  26. package/dist/browser/log/index.mjs +5 -1
  27. package/dist/browser/log/log-browser-factory.cjs +65 -1
  28. package/dist/browser/log/log-browser-factory.cjs.map +1 -1
  29. package/dist/browser/log/log-browser-factory.mjs +64 -1
  30. package/dist/browser/log/log-browser-factory.mjs.map +1 -1
  31. package/dist/browser/log/log-browser.cjs +72 -1
  32. package/dist/browser/log/log-browser.cjs.map +1 -1
  33. package/dist/browser/log/log-browser.mjs +71 -1
  34. package/dist/browser/log/log-browser.mjs.map +1 -1
  35. package/dist/browser/log/log-colors.cjs +11 -1
  36. package/dist/browser/log/log-colors.cjs.map +1 -1
  37. package/dist/browser/log/log-colors.mjs +9 -1
  38. package/dist/browser/log/log-colors.mjs.map +1 -1
  39. package/dist/browser/log/log-context-browser.cjs +25 -1
  40. package/dist/browser/log/log-context-browser.cjs.map +1 -1
  41. package/dist/browser/log/log-context-browser.mjs +23 -1
  42. package/dist/browser/log/log-context-browser.mjs.map +1 -1
  43. package/dist/chunk-DQk6qfdC.mjs +18 -0
  44. package/dist/chunk-uaV2rQ02.cjs +53 -0
  45. package/dist/common/assert.cjs +22 -1
  46. package/dist/common/assert.cjs.map +1 -1
  47. package/dist/common/assert.mjs +19 -1
  48. package/dist/common/assert.mjs.map +1 -1
  49. package/dist/common/bin/index.cjs +106 -1
  50. package/dist/common/bin/index.cjs.map +1 -1
  51. package/dist/common/bin/index.mjs +98 -1
  52. package/dist/common/bin/index.mjs.map +1 -1
  53. package/dist/common/bin/lib0/binary.cjs +146 -1
  54. package/dist/common/bin/lib0/binary.cjs.map +1 -1
  55. package/dist/common/bin/lib0/binary.mjs +80 -1
  56. package/dist/common/bin/lib0/binary.mjs.map +1 -1
  57. package/dist/common/bin/lib0/buffer.cjs +42 -1
  58. package/dist/common/bin/lib0/buffer.cjs.map +1 -1
  59. package/dist/common/bin/lib0/buffer.mjs +38 -1
  60. package/dist/common/bin/lib0/buffer.mjs.map +1 -1
  61. package/dist/common/bin/lib0/create.cjs +24 -1
  62. package/dist/common/bin/lib0/create.cjs.map +1 -1
  63. package/dist/common/bin/lib0/create.mjs +21 -1
  64. package/dist/common/bin/lib0/create.mjs.map +1 -1
  65. package/dist/common/bin/lib0/decoding.cjs +325 -1
  66. package/dist/common/bin/lib0/decoding.cjs.map +1 -1
  67. package/dist/common/bin/lib0/decoding.mjs +298 -1
  68. package/dist/common/bin/lib0/decoding.mjs.map +1 -1
  69. package/dist/common/bin/lib0/encoding.cjs +404 -1
  70. package/dist/common/bin/lib0/encoding.cjs.map +1 -1
  71. package/dist/common/bin/lib0/encoding.mjs +377 -1
  72. package/dist/common/bin/lib0/encoding.mjs.map +1 -1
  73. package/dist/common/bin/lib0/string.cjs +81 -1
  74. package/dist/common/bin/lib0/string.cjs.map +1 -1
  75. package/dist/common/bin/lib0/string.mjs +71 -1
  76. package/dist/common/bin/lib0/string.mjs.map +1 -1
  77. package/dist/common/crypto/aes-sealed.cjs +34 -1
  78. package/dist/common/crypto/aes-sealed.cjs.map +1 -1
  79. package/dist/common/crypto/aes-sealed.mjs +32 -1
  80. package/dist/common/crypto/aes-sealed.mjs.map +1 -1
  81. package/dist/common/crypto/crypto.cjs +91 -1
  82. package/dist/common/crypto/crypto.cjs.map +1 -1
  83. package/dist/common/crypto/crypto.mjs +80 -1
  84. package/dist/common/crypto/crypto.mjs.map +1 -1
  85. package/dist/common/crypto/index.cjs +23 -1
  86. package/dist/common/crypto/index.mjs +5 -1
  87. package/dist/common/crypto/xaes.cjs +128 -1
  88. package/dist/common/crypto/xaes.cjs.map +1 -1
  89. package/dist/common/crypto/xaes.mjs +123 -1
  90. package/dist/common/crypto/xaes.mjs.map +1 -1
  91. package/dist/common/csv.cjs +49 -4
  92. package/dist/common/csv.cjs.map +1 -1
  93. package/dist/common/csv.mjs +46 -4
  94. package/dist/common/csv.mjs.map +1 -1
  95. package/dist/common/data/array.cjs +299 -1
  96. package/dist/common/data/array.cjs.map +1 -1
  97. package/dist/common/data/array.mjs +274 -1
  98. package/dist/common/data/array.mjs.map +1 -1
  99. package/dist/common/data/basex-secure.cjs +30 -1
  100. package/dist/common/data/basex-secure.mjs +3 -1
  101. package/dist/common/data/basex.cjs +163 -1
  102. package/dist/common/data/basex.cjs.map +1 -1
  103. package/dist/common/data/basex.mjs +152 -1
  104. package/dist/common/data/basex.mjs.map +1 -1
  105. package/dist/common/data/bin-types.mjs +1 -1
  106. package/dist/common/data/bin.cjs +21 -1
  107. package/dist/common/data/bin.mjs +3 -1
  108. package/dist/common/data/camelcase.cjs +27 -1
  109. package/dist/common/data/camelcase.cjs.map +1 -1
  110. package/dist/common/data/camelcase.mjs +22 -1
  111. package/dist/common/data/camelcase.mjs.map +1 -1
  112. package/dist/common/data/convert.cjs +104 -1
  113. package/dist/common/data/convert.cjs.map +1 -1
  114. package/dist/common/data/convert.mjs +88 -1
  115. package/dist/common/data/convert.mjs.map +1 -1
  116. package/dist/common/data/datauri.cjs +32 -1
  117. package/dist/common/data/datauri.cjs.map +1 -1
  118. package/dist/common/data/datauri.mjs +27 -1
  119. package/dist/common/data/datauri.mjs.map +1 -1
  120. package/dist/common/data/day-legacy.cjs +148 -1
  121. package/dist/common/data/day-legacy.cjs.map +1 -1
  122. package/dist/common/data/day-legacy.mjs +143 -1
  123. package/dist/common/data/day-legacy.mjs.map +1 -1
  124. package/dist/common/data/day.cjs +335 -1
  125. package/dist/common/data/day.cjs.map +1 -1
  126. package/dist/common/data/day.mjs +305 -1
  127. package/dist/common/data/day.mjs.map +1 -1
  128. package/dist/common/data/decimal.cjs +28 -1
  129. package/dist/common/data/decimal.cjs.map +1 -1
  130. package/dist/common/data/decimal.mjs +23 -1
  131. package/dist/common/data/decimal.mjs.map +1 -1
  132. package/dist/common/data/deep.cjs +57 -1
  133. package/dist/common/data/deep.cjs.map +1 -1
  134. package/dist/common/data/deep.mjs +54 -1
  135. package/dist/common/data/deep.mjs.map +1 -1
  136. package/dist/common/data/diff.cjs +62 -1
  137. package/dist/common/data/diff.cjs.map +1 -1
  138. package/dist/common/data/diff.mjs +60 -1
  139. package/dist/common/data/diff.mjs.map +1 -1
  140. package/dist/common/data/distributed.cjs +24 -1
  141. package/dist/common/data/distributed.cjs.map +1 -1
  142. package/dist/common/data/distributed.mjs +22 -1
  143. package/dist/common/data/distributed.mjs.map +1 -1
  144. package/dist/common/data/format.cjs +63 -1
  145. package/dist/common/data/format.cjs.map +1 -1
  146. package/dist/common/data/format.mjs +59 -1
  147. package/dist/common/data/format.mjs.map +1 -1
  148. package/dist/common/data/html.cjs +13 -1
  149. package/dist/common/data/html.cjs.map +1 -1
  150. package/dist/common/data/html.mjs +10 -1
  151. package/dist/common/data/html.mjs.map +1 -1
  152. package/dist/common/data/index.cjs +296 -1
  153. package/dist/common/data/index.mjs +37 -1
  154. package/dist/common/data/is.cjs +106 -1
  155. package/dist/common/data/is.cjs.map +1 -1
  156. package/dist/common/data/is.mjs +85 -1
  157. package/dist/common/data/is.mjs.map +1 -1
  158. package/dist/common/data/json.cjs +70 -1
  159. package/dist/common/data/json.cjs.map +1 -1
  160. package/dist/common/data/json.mjs +65 -1
  161. package/dist/common/data/json.mjs.map +1 -1
  162. package/dist/common/data/list.cjs +32 -1
  163. package/dist/common/data/list.cjs.map +1 -1
  164. package/dist/common/data/list.mjs +27 -1
  165. package/dist/common/data/list.mjs.map +1 -1
  166. package/dist/common/data/lru.mjs +1 -1
  167. package/dist/common/data/math.cjs +79 -1
  168. package/dist/common/data/math.cjs.map +1 -1
  169. package/dist/common/data/math.mjs +65 -1
  170. package/dist/common/data/math.mjs.map +1 -1
  171. package/dist/common/data/message.cjs +30 -1
  172. package/dist/common/data/message.cjs.map +1 -1
  173. package/dist/common/data/message.mjs +28 -1
  174. package/dist/common/data/message.mjs.map +1 -1
  175. package/dist/common/data/object-changes.cjs +66 -1
  176. package/dist/common/data/object-changes.cjs.map +1 -1
  177. package/dist/common/data/object-changes.mjs +63 -1
  178. package/dist/common/data/object-changes.mjs.map +1 -1
  179. package/dist/common/data/object.cjs +112 -1
  180. package/dist/common/data/object.cjs.map +1 -1
  181. package/dist/common/data/object.mjs +104 -1
  182. package/dist/common/data/object.mjs.map +1 -1
  183. package/dist/common/data/orderby.cjs +42 -1
  184. package/dist/common/data/orderby.cjs.map +1 -1
  185. package/dist/common/data/orderby.mjs +37 -1
  186. package/dist/common/data/orderby.mjs.map +1 -1
  187. package/dist/common/data/path.cjs +26 -1
  188. package/dist/common/data/path.cjs.map +1 -1
  189. package/dist/common/data/path.mjs +25 -1
  190. package/dist/common/data/path.mjs.map +1 -1
  191. package/dist/common/data/regexp.cjs +12 -1
  192. package/dist/common/data/regexp.cjs.map +1 -1
  193. package/dist/common/data/regexp.mjs +10 -1
  194. package/dist/common/data/regexp.mjs.map +1 -1
  195. package/dist/common/data/rounding.cjs +107 -1
  196. package/dist/common/data/rounding.cjs.map +1 -1
  197. package/dist/common/data/rounding.mjs +95 -1
  198. package/dist/common/data/rounding.mjs.map +1 -1
  199. package/dist/common/data/signal.cjs +39 -1
  200. package/dist/common/data/signal.cjs.map +1 -1
  201. package/dist/common/data/signal.mjs +38 -1
  202. package/dist/common/data/signal.mjs.map +1 -1
  203. package/dist/common/data/sortable.cjs +35 -1
  204. package/dist/common/data/sortable.cjs.map +1 -1
  205. package/dist/common/data/sortable.mjs +31 -1
  206. package/dist/common/data/sortable.mjs.map +1 -1
  207. package/dist/common/data/sorted.cjs +54 -1
  208. package/dist/common/data/sorted.cjs.map +1 -1
  209. package/dist/common/data/sorted.mjs +53 -1
  210. package/dist/common/data/sorted.mjs.map +1 -1
  211. package/dist/common/data/string-deburr.cjs +240 -1
  212. package/dist/common/data/string-deburr.cjs.map +1 -1
  213. package/dist/common/data/string-deburr.mjs +238 -1
  214. package/dist/common/data/string-deburr.mjs.map +1 -1
  215. package/dist/common/data/string-hash-fnv.cjs +69 -1
  216. package/dist/common/data/string-hash-fnv.cjs.map +1 -1
  217. package/dist/common/data/string-hash-fnv.mjs +67 -1
  218. package/dist/common/data/string-hash-fnv.mjs.map +1 -1
  219. package/dist/common/data/string-hash-pool.cjs +28 -1
  220. package/dist/common/data/string-hash-pool.cjs.map +1 -1
  221. package/dist/common/data/string-hash-pool.mjs +27 -1
  222. package/dist/common/data/string-hash-pool.mjs.map +1 -1
  223. package/dist/common/data/url.cjs +98 -2
  224. package/dist/common/data/url.cjs.map +1 -1
  225. package/dist/common/data/url.mjs +91 -2
  226. package/dist/common/data/url.mjs.map +1 -1
  227. package/dist/common/data/utils.cjs +118 -1
  228. package/dist/common/data/utils.cjs.map +1 -1
  229. package/dist/common/data/utils.mjs +107 -1
  230. package/dist/common/data/utils.mjs.map +1 -1
  231. package/dist/common/data/wordlist.cjs +531 -1
  232. package/dist/common/data/wordlist.cjs.map +1 -1
  233. package/dist/common/data/wordlist.mjs +529 -1
  234. package/dist/common/data/wordlist.mjs.map +1 -1
  235. package/dist/common/data/xrx.cjs +96 -1
  236. package/dist/common/data/xrx.cjs.map +1 -1
  237. package/dist/common/data/xrx.mjs +92 -1
  238. package/dist/common/data/xrx.mjs.map +1 -1
  239. package/dist/common/dispose-defer.cjs +133 -1
  240. package/dist/common/dispose-defer.cjs.map +1 -1
  241. package/dist/common/dispose-defer.mjs +130 -1
  242. package/dist/common/dispose-defer.mjs.map +1 -1
  243. package/dist/common/dispose-types.mjs +1 -1
  244. package/dist/common/dispose-utils.cjs +113 -1
  245. package/dist/common/dispose-utils.cjs.map +1 -1
  246. package/dist/common/dispose-utils.mjs +106 -1
  247. package/dist/common/dispose-utils.mjs.map +1 -1
  248. package/dist/common/exec/index.cjs +24 -1
  249. package/dist/common/exec/index.d.cts +1 -1
  250. package/dist/common/exec/index.d.mts +1 -1
  251. package/dist/common/exec/index.mjs +8 -1
  252. package/dist/common/exec/mutex.cjs +44 -1
  253. package/dist/common/exec/mutex.cjs.map +1 -1
  254. package/dist/common/exec/mutex.mjs +42 -1
  255. package/dist/common/exec/mutex.mjs.map +1 -1
  256. package/dist/common/exec/pool.cjs +181 -1
  257. package/dist/common/exec/pool.cjs.map +1 -1
  258. package/dist/common/exec/pool.d.cts +1 -1
  259. package/dist/common/exec/pool.d.mts +1 -1
  260. package/dist/common/exec/pool.mjs +180 -1
  261. package/dist/common/exec/pool.mjs.map +1 -1
  262. package/dist/common/exec/progress.cjs +149 -1
  263. package/dist/common/exec/progress.cjs.map +1 -1
  264. package/dist/common/exec/progress.d.cts +1 -1
  265. package/dist/common/exec/progress.d.mts +1 -1
  266. package/dist/common/exec/progress.mjs +148 -1
  267. package/dist/common/exec/progress.mjs.map +1 -1
  268. package/dist/common/exec/promise.cjs +113 -1
  269. package/dist/common/exec/promise.cjs.map +1 -1
  270. package/dist/common/exec/promise.mjs +103 -1
  271. package/dist/common/exec/promise.mjs.map +1 -1
  272. package/dist/common/exec/queue.cjs +125 -1
  273. package/dist/common/exec/queue.cjs.map +1 -1
  274. package/dist/common/exec/queue.d.cts +1 -1
  275. package/dist/common/exec/queue.d.mts +1 -1
  276. package/dist/common/exec/queue.mjs +124 -1
  277. package/dist/common/exec/queue.mjs.map +1 -1
  278. package/dist/common/exec/throttle-debounce.cjs +114 -1
  279. package/dist/common/exec/throttle-debounce.cjs.map +1 -1
  280. package/dist/common/exec/throttle-debounce.mjs +112 -1
  281. package/dist/common/exec/throttle-debounce.mjs.map +1 -1
  282. package/dist/common/global.cjs +22 -1
  283. package/dist/common/global.cjs.map +1 -1
  284. package/dist/common/global.mjs +19 -1
  285. package/dist/common/global.mjs.map +1 -1
  286. package/dist/common/index.cjs +559 -1
  287. package/dist/common/index.d.cts +1 -1
  288. package/dist/common/index.d.mts +1 -1
  289. package/dist/common/index.mjs +89 -1
  290. package/dist/common/localhost.cjs +16 -1
  291. package/dist/common/localhost.cjs.map +1 -1
  292. package/dist/common/localhost.mjs +14 -1
  293. package/dist/common/localhost.mjs.map +1 -1
  294. package/dist/common/log/index.cjs +34 -1
  295. package/dist/common/log/index.mjs +11 -1
  296. package/dist/common/log/log-base.cjs +40 -1
  297. package/dist/common/log/log-base.cjs.map +1 -1
  298. package/dist/common/log/log-base.mjs +31 -1
  299. package/dist/common/log/log-base.mjs.map +1 -1
  300. package/dist/common/log/log-colors.cjs +92 -1
  301. package/dist/common/log/log-colors.cjs.map +1 -1
  302. package/dist/common/log/log-colors.mjs +90 -1
  303. package/dist/common/log/log-colors.mjs.map +1 -1
  304. package/dist/common/log/log-config.cjs +15 -1
  305. package/dist/common/log/log-config.cjs.map +1 -1
  306. package/dist/common/log/log-config.mjs +14 -1
  307. package/dist/common/log/log-config.mjs.map +1 -1
  308. package/dist/common/log/log-console-capture.cjs +33 -1
  309. package/dist/common/log/log-console-capture.cjs.map +1 -1
  310. package/dist/common/log/log-console-capture.mjs +32 -1
  311. package/dist/common/log/log-console-capture.mjs.map +1 -1
  312. package/dist/common/log/log-console-original.cjs +27 -1
  313. package/dist/common/log/log-console-original.cjs.map +1 -1
  314. package/dist/common/log/log-console-original.mjs +26 -1
  315. package/dist/common/log/log-console-original.mjs.map +1 -1
  316. package/dist/common/log/log-console.cjs +39 -1
  317. package/dist/common/log/log-console.cjs.map +1 -1
  318. package/dist/common/log/log-console.mjs +38 -1
  319. package/dist/common/log/log-console.mjs.map +1 -1
  320. package/dist/common/log/log-context.cjs +109 -1
  321. package/dist/common/log/log-context.cjs.map +1 -1
  322. package/dist/common/log/log-context.mjs +108 -1
  323. package/dist/common/log/log-context.mjs.map +1 -1
  324. package/dist/common/log/log-filter.cjs +80 -1
  325. package/dist/common/log/log-filter.cjs.map +1 -1
  326. package/dist/common/log/log-filter.mjs +75 -1
  327. package/dist/common/log/log-filter.mjs.map +1 -1
  328. package/dist/common/log/log-memory.cjs +45 -1
  329. package/dist/common/log/log-memory.cjs.map +1 -1
  330. package/dist/common/log/log-memory.mjs +43 -1
  331. package/dist/common/log/log-memory.mjs.map +1 -1
  332. package/dist/common/log/log-noop.cjs +17 -1
  333. package/dist/common/log/log-noop.cjs.map +1 -1
  334. package/dist/common/log/log-noop.mjs +15 -1
  335. package/dist/common/log/log-noop.mjs.map +1 -1
  336. package/dist/common/log/log.cjs +46 -1
  337. package/dist/common/log/log.cjs.map +1 -1
  338. package/dist/common/log/log.mjs +43 -1
  339. package/dist/common/log/log.mjs.map +1 -1
  340. package/dist/common/msg/channel-debug.cjs +17 -1
  341. package/dist/common/msg/channel-debug.cjs.map +1 -1
  342. package/dist/common/msg/channel-debug.d.cts +1 -1
  343. package/dist/common/msg/channel-debug.d.mts +1 -1
  344. package/dist/common/msg/channel-debug.mjs +16 -1
  345. package/dist/common/msg/channel-debug.mjs.map +1 -1
  346. package/dist/common/msg/channel-local.cjs +28 -1
  347. package/dist/common/msg/channel-local.cjs.map +1 -1
  348. package/dist/common/msg/channel-local.d.cts +1 -1
  349. package/dist/common/msg/channel-local.d.mts +1 -1
  350. package/dist/common/msg/channel-local.mjs +26 -1
  351. package/dist/common/msg/channel-local.mjs.map +1 -1
  352. package/dist/common/msg/channel-resilient.cjs +63 -1
  353. package/dist/common/msg/channel-resilient.cjs.map +1 -1
  354. package/dist/common/msg/channel-resilient.d.cts +1 -1
  355. package/dist/common/msg/channel-resilient.d.mts +1 -1
  356. package/dist/common/msg/channel-resilient.mjs +62 -1
  357. package/dist/common/msg/channel-resilient.mjs.map +1 -1
  358. package/dist/common/msg/channel-wkwebview.cjs +35 -1
  359. package/dist/common/msg/channel-wkwebview.cjs.map +1 -1
  360. package/dist/common/msg/channel-wkwebview.d.cts +2 -1
  361. package/dist/common/msg/channel-wkwebview.d.mts +2 -1
  362. package/dist/common/msg/channel-wkwebview.mjs +34 -1
  363. package/dist/common/msg/channel-wkwebview.mjs.map +1 -1
  364. package/dist/common/msg/channel.cjs +23 -1
  365. package/dist/common/msg/channel.cjs.map +1 -1
  366. package/dist/common/msg/channel.d.cts +1 -1
  367. package/dist/common/msg/channel.d.mts +1 -1
  368. package/dist/common/msg/channel.mjs +22 -1
  369. package/dist/common/msg/channel.mjs.map +1 -1
  370. package/dist/common/msg/emitter.cjs +141 -1
  371. package/dist/common/msg/emitter.cjs.map +1 -1
  372. package/dist/common/msg/emitter.d.cts +1 -1
  373. package/dist/common/msg/emitter.d.mts +1 -1
  374. package/dist/common/msg/emitter.mjs +139 -1
  375. package/dist/common/msg/emitter.mjs.map +1 -1
  376. package/dist/common/msg/encoder.cjs +38 -1
  377. package/dist/common/msg/encoder.cjs.map +1 -1
  378. package/dist/common/msg/encoder.mjs +35 -1
  379. package/dist/common/msg/encoder.mjs.map +1 -1
  380. package/dist/common/msg/index.cjs +28 -1
  381. package/dist/common/msg/index.d.cts +1 -1
  382. package/dist/common/msg/index.d.mts +1 -1
  383. package/dist/common/msg/index.mjs +11 -1
  384. package/dist/common/msg/messages.cjs +135 -1
  385. package/dist/common/msg/messages.cjs.map +1 -1
  386. package/dist/common/msg/messages.d.cts +1 -1
  387. package/dist/common/msg/messages.d.mts +1 -1
  388. package/dist/common/msg/messages.mjs +133 -1
  389. package/dist/common/msg/messages.mjs.map +1 -1
  390. package/dist/common/msg/pipe.mjs +1 -1
  391. package/dist/common/msg/pubsub.cjs +78 -1
  392. package/dist/common/msg/pubsub.cjs.map +1 -1
  393. package/dist/common/msg/pubsub.d.cts +1 -1
  394. package/dist/common/msg/pubsub.d.mts +1 -1
  395. package/dist/common/msg/pubsub.mjs +76 -1
  396. package/dist/common/msg/pubsub.mjs.map +1 -1
  397. package/dist/common/msg/rpc.cjs +142 -1
  398. package/dist/common/msg/rpc.cjs.map +1 -1
  399. package/dist/common/msg/rpc.mjs +139 -1
  400. package/dist/common/msg/rpc.mjs.map +1 -1
  401. package/dist/common/network.cjs +129 -1
  402. package/dist/common/network.cjs.map +1 -1
  403. package/dist/common/network.mjs +122 -1
  404. package/dist/common/network.mjs.map +1 -1
  405. package/dist/common/platform.cjs +92 -1
  406. package/dist/common/platform.cjs.map +1 -1
  407. package/dist/common/platform.mjs +84 -1
  408. package/dist/common/platform.mjs.map +1 -1
  409. package/dist/common/schema/_sandbox/sandbox-inherit.mjs +1 -1
  410. package/dist/common/schema/_sandbox/sandbox.mjs +1 -1
  411. package/dist/common/schema/_sandbox/sandbox.xspec.mjs +1 -1
  412. package/dist/common/schema/export-json-schema.cjs +54 -1
  413. package/dist/common/schema/export-json-schema.cjs.map +1 -1
  414. package/dist/common/schema/export-json-schema.mjs +52 -1
  415. package/dist/common/schema/export-json-schema.mjs.map +1 -1
  416. package/dist/common/schema/export-swift.cjs +30 -2
  417. package/dist/common/schema/export-swift.cjs.map +1 -1
  418. package/dist/common/schema/export-swift.mjs +29 -2
  419. package/dist/common/schema/export-swift.mjs.map +1 -1
  420. package/dist/common/schema/export-typescript.cjs +20 -2
  421. package/dist/common/schema/export-typescript.cjs.map +1 -1
  422. package/dist/common/schema/export-typescript.mjs +19 -2
  423. package/dist/common/schema/export-typescript.mjs.map +1 -1
  424. package/dist/common/schema/index.cjs +55 -1
  425. package/dist/common/schema/index.mjs +12 -1
  426. package/dist/common/schema/parse-args.cjs +62 -2
  427. package/dist/common/schema/parse-args.cjs.map +1 -1
  428. package/dist/common/schema/parse-args.mjs +60 -2
  429. package/dist/common/schema/parse-args.mjs.map +1 -1
  430. package/dist/common/schema/parse-env.cjs +48 -3
  431. package/dist/common/schema/parse-env.cjs.map +1 -1
  432. package/dist/common/schema/parse-env.mjs +46 -3
  433. package/dist/common/schema/parse-env.mjs.map +1 -1
  434. package/dist/common/schema/parse-object.cjs +122 -1
  435. package/dist/common/schema/parse-object.cjs.map +1 -1
  436. package/dist/common/schema/parse-object.mjs +119 -1
  437. package/dist/common/schema/parse-object.mjs.map +1 -1
  438. package/dist/common/schema/schema-standard.mjs +1 -1
  439. package/dist/common/schema/schema.cjs +423 -1
  440. package/dist/common/schema/schema.cjs.map +1 -1
  441. package/dist/common/schema/schema.mjs +404 -1
  442. package/dist/common/schema/schema.mjs.map +1 -1
  443. package/dist/common/schema/serialize.cjs +109 -1
  444. package/dist/common/schema/serialize.cjs.map +1 -1
  445. package/dist/common/schema/serialize.mjs +107 -1
  446. package/dist/common/schema/serialize.mjs.map +1 -1
  447. package/dist/common/schema/type-test.mjs +1 -1
  448. package/dist/common/schema/utils.cjs +25 -1
  449. package/dist/common/schema/utils.cjs.map +1 -1
  450. package/dist/common/schema/utils.mjs +19 -1
  451. package/dist/common/schema/utils.mjs.map +1 -1
  452. package/dist/common/schema/z-collection.cjs +51 -1
  453. package/dist/common/schema/z-collection.mjs +27 -1
  454. package/dist/common/schema/z.cjs +9 -1
  455. package/dist/common/schema/z.mjs +3 -1
  456. package/dist/common/storage/index.cjs +4 -1
  457. package/dist/common/storage/index.mjs +3 -1
  458. package/dist/common/storage/memstorage.cjs +26 -1
  459. package/dist/common/storage/memstorage.cjs.map +1 -1
  460. package/dist/common/storage/memstorage.mjs +25 -1
  461. package/dist/common/storage/memstorage.mjs.map +1 -1
  462. package/dist/common/test.cjs +14 -1
  463. package/dist/common/test.cjs.map +1 -1
  464. package/dist/common/test.mjs +13 -1
  465. package/dist/common/test.mjs.map +1 -1
  466. package/dist/common/time.cjs +220 -1
  467. package/dist/common/time.cjs.map +1 -1
  468. package/dist/common/time.mjs +194 -1
  469. package/dist/common/time.mjs.map +1 -1
  470. package/dist/common/timeout.cjs +27 -1
  471. package/dist/common/timeout.cjs.map +1 -1
  472. package/dist/common/timeout.mjs +25 -1
  473. package/dist/common/timeout.mjs.map +1 -1
  474. package/dist/common/types.mjs +1 -1
  475. package/dist/common/utils.cjs +7 -1
  476. package/dist/common/utils.cjs.map +1 -1
  477. package/dist/common/utils.mjs +5 -1
  478. package/dist/common/utils.mjs.map +1 -1
  479. package/dist/common/uuid.cjs +307 -1
  480. package/dist/common/uuid.cjs.map +1 -1
  481. package/dist/common/uuid.mjs +284 -1
  482. package/dist/common/uuid.mjs.map +1 -1
  483. package/dist/{index-DHXVOH8h.d.cts → index-CFkMqHvX.d.cts} +1 -2
  484. package/dist/{index-DMaPyx9O.d.mts → index-C_3Y_s6f.d.mts} +1 -2
  485. package/dist/index.all.cjs +641 -1
  486. package/dist/index.all.d.cts +1 -1
  487. package/dist/index.all.d.mts +1 -1
  488. package/dist/index.all.mjs +113 -1
  489. package/dist/index.browser.cjs +576 -1
  490. package/dist/index.browser.d.cts +1 -1
  491. package/dist/index.browser.d.mts +1 -1
  492. package/dist/index.browser.mjs +98 -1
  493. package/dist/index.jsr.cjs +57 -1
  494. package/dist/index.jsr.mjs +6 -1
  495. package/dist/index.node.cjs +628 -1
  496. package/dist/index.node.d.cts +1 -1
  497. package/dist/index.node.d.mts +1 -1
  498. package/dist/index.node.mjs +106 -1
  499. package/dist/node/args.cjs +56 -1
  500. package/dist/node/args.cjs.map +1 -1
  501. package/dist/node/args.mjs +53 -1
  502. package/dist/node/args.mjs.map +1 -1
  503. package/dist/node/clipboard.cjs +18 -1
  504. package/dist/node/clipboard.cjs.map +1 -1
  505. package/dist/node/clipboard.mjs +16 -1
  506. package/dist/node/clipboard.mjs.map +1 -1
  507. package/dist/node/crypto.cjs +28 -1
  508. package/dist/node/crypto.cjs.map +1 -1
  509. package/dist/node/crypto.mjs +24 -1
  510. package/dist/node/crypto.mjs.map +1 -1
  511. package/dist/node/env.cjs +100 -4
  512. package/dist/node/env.cjs.map +1 -1
  513. package/dist/node/env.mjs +90 -4
  514. package/dist/node/env.mjs.map +1 -1
  515. package/dist/node/files-async.cjs +66 -1
  516. package/dist/node/files-async.cjs.map +1 -1
  517. package/dist/node/files-async.mjs +60 -1
  518. package/dist/node/files-async.mjs.map +1 -1
  519. package/dist/node/files.cjs +52 -1
  520. package/dist/node/files.cjs.map +1 -1
  521. package/dist/node/files.mjs +46 -1
  522. package/dist/node/files.mjs.map +1 -1
  523. package/dist/node/filestorage.cjs +100 -1
  524. package/dist/node/filestorage.cjs.map +1 -1
  525. package/dist/node/filestorage.mjs +97 -1
  526. package/dist/node/filestorage.mjs.map +1 -1
  527. package/dist/node/fs.cjs +119 -1
  528. package/dist/node/fs.cjs.map +1 -1
  529. package/dist/node/fs.mjs +101 -1
  530. package/dist/node/fs.mjs.map +1 -1
  531. package/dist/node/glob.cjs +75 -1
  532. package/dist/node/glob.cjs.map +1 -1
  533. package/dist/node/glob.mjs +73 -1
  534. package/dist/node/glob.mjs.map +1 -1
  535. package/dist/node/index.cjs +66 -1
  536. package/dist/node/index.mjs +16 -1
  537. package/dist/node/log/index.cjs +20 -1
  538. package/dist/node/log/index.mjs +7 -1
  539. package/dist/node/log/log-context-node.cjs +39 -1
  540. package/dist/node/log/log-context-node.cjs.map +1 -1
  541. package/dist/node/log/log-context-node.mjs +35 -1
  542. package/dist/node/log/log-context-node.mjs.map +1 -1
  543. package/dist/node/log/log-file-rotation.cjs +71 -1
  544. package/dist/node/log/log-file-rotation.cjs.map +1 -1
  545. package/dist/node/log/log-file-rotation.mjs +68 -1
  546. package/dist/node/log/log-file-rotation.mjs.map +1 -1
  547. package/dist/node/log/log-file.cjs +57 -1
  548. package/dist/node/log/log-file.cjs.map +1 -1
  549. package/dist/node/log/log-file.mjs +54 -1
  550. package/dist/node/log/log-file.mjs.map +1 -1
  551. package/dist/node/log/log-node.cjs +162 -1
  552. package/dist/node/log/log-node.cjs.map +1 -1
  553. package/dist/node/log/log-node.mjs +155 -1
  554. package/dist/node/log/log-node.mjs.map +1 -1
  555. package/dist/node/log/log-rotation.cjs +543 -3
  556. package/dist/node/log/log-rotation.cjs.map +1 -1
  557. package/dist/node/log/log-rotation.mjs +538 -3
  558. package/dist/node/log/log-rotation.mjs.map +1 -1
  559. package/dist/node/log/log-util.cjs +69 -3
  560. package/dist/node/log/log-util.cjs.map +1 -1
  561. package/dist/node/log/log-util.mjs +63 -3
  562. package/dist/node/log/log-util.mjs.map +1 -1
  563. package/dist/node/open-browser.cjs +20 -1
  564. package/dist/node/open-browser.cjs.map +1 -1
  565. package/dist/node/open-browser.mjs +18 -1
  566. package/dist/node/open-browser.mjs.map +1 -1
  567. package/package.json +15 -15
  568. package/src/common/schema/README.md +247 -66
  569. package/src/eslint-defaults.js +4 -0
  570. package/src/index.spec.ts +6 -6
  571. package/dist/bin-Ce3i6ABn.cjs +0 -3
  572. package/dist/bin-SPdenYkw.mjs +0 -3
  573. package/dist/chunk-0Lt9GpW0.mjs +0 -1
  574. package/dist/chunk-D-qHiVGv.cjs +0 -1
  575. package/src/common/schema/README-SCHEMA.md +0 -0
@@ -1,2 +1,405 @@
1
- import{isArray as e,isBoolean as t,isFunction as n,isInteger as r,isNumber as i,isObject as a,isString as o}from"../data/is.mjs";var s=class e{type;_default;_optional;_meta;_check;_object;_type;_union;_enumValues;_args;_ret;_info;constructor(e,t={}){this.type=e,Object.assign(this,t)}get"~standard"(){return{version:1,vendor:`zeed`,validate:e=>this.validate(e),types:{input:void 0,output:void 0}}}validate(e){if(e==null)return this._optional?{value:void 0}:this._default===void 0?{issues:[{message:`Required value is missing`,path:[]}]}:{value:n(this._default)?this._default(this):this._default};if(this.type===`literal`&&this._default!==e)return{issues:[{message:`Expected literal value ${this._default}, got ${e}`,path:[]}]};if(this._enumValues&&Array.isArray(this._enumValues)&&!this._enumValues.includes(e))return{issues:[{message:`Expected one of [${this._enumValues.join(`, `)}], got ${e}`,path:[]}]};if(this._union&&Array.isArray(this._union)){for(let t of this._union){let n=t.validate(e);if(!n.issues)return n}return{issues:[{message:`Value does not match any union variant`,path:[]}]}}if(this.type===`array`||this.type===`tuple`){if(!Array.isArray(e))return{issues:[{message:`Expected array, got ${typeof e}`,path:[]}]};if(this.type===`tuple`&&this._type){let t=this._type;if(e.length!==t.length)return{issues:[{message:`Expected tuple of length ${t.length}, got ${e.length}`,path:[]}]};let n=[];for(let r=0;r<t.length;r++){let i=t[r].validate(e[r]);if(i.issues)for(let e of i.issues)n.push({message:e.message,path:[r,...e.path||[]]})}if(n.length>0)return{issues:n}}else if(this._type){let t=this._type,n=[];for(let r=0;r<e.length;r++){let i=t.validate(e[r]);if(i.issues)for(let e of i.issues)n.push({message:e.message,path:[r,...e.path||[]]})}if(n.length>0)return{issues:n}}}if(this._object){if(!a(e))return{issues:[{message:`Expected object, got ${typeof e}`,path:[]}]};let t=[],n=e;for(let e in this._object){let r=this._object[e],i=n[e],a=r.validate(i);if(a.issues)for(let n of a.issues)t.push({message:n.message,path:[e,...n.path||[]]})}return t.length>0?{issues:t}:{value:e,issues:void 0}}if(this.type===`record`&&this._type){if(!a(e))return{issues:[{message:`Expected object, got ${typeof e}`,path:[]}]};let t=this._type,n=[],r=e;for(let e in r){let i=t.validate(r[e]);if(i.issues)for(let t of i.issues)n.push({message:t.message,path:[e,...t.path||[]]})}if(n.length>0)return{issues:n}}return this._check&&!this._check(e)?{issues:[{message:`Expected ${this.type}, got ${typeof e}`,path:[]}]}:{value:e}}_cloneWithProps(t={}){let n=new e(this.type);for(let e of[`_default`,`_optional`,`_meta`,`_check`,`_object`,`_type`,`_union`,`_enumValues`,`_args`,`_ret`,`_info`])this[e]!==void 0&&(n[e]=this[e]);return Object.assign(n,t),n}static _copyTypeProperties(e,t){for(let n of[`_check`,`_default`,`_meta`,`_object`,`_type`,`_enumValues`])e[n]!==void 0&&(t[n]=e[n])}optional(){return this._cloneWithProps({_optional:!0})}default(e){return this._cloneWithProps({_default:e})}meta(e){return this._cloneWithProps({_meta:e})}describe(e){let t=this._meta||{};return t.desc=e,this._cloneWithProps({_meta:t})}extend(e){if(!this._object)throw Error(`extend() can only be used on object schemas`);return _({...this._object,...e})}pick(e){if(!this._object)throw Error(`pick() can only be used on object schemas`);let t={};for(let n of Object.keys(e))n in this._object&&(t[n]=this._object[n]);return _(t)}omit(e){if(!this._object)throw Error(`omit() can only be used on object schemas`);let t={...this._object};for(let n of Object.keys(e))delete t[n];return _(t)}_transformObjectProperties(e,t){if(!this._object)throw Error(`This operation can only be used on object schemas`);let n={},r=this._object;for(let[i,a]of Object.entries(r))n[i]=e(i,a,!t||i in t);return _(n)}partial(t){if(!this._object)throw Error(`partial() can only be used on object schemas`);return this._transformObjectProperties((t,n,r)=>r?e._cloneTypeWithOptional(n,!0):n,t)}required(t){if(!this._object)throw Error(`required() can only be used on object schemas`);return this._transformObjectProperties((t,n,r)=>r?e._cloneTypeWithOptional(n,!1):n,t)}static _cloneTypeWithOptional(t,n){let r=new e(t.type);return e._copyTypeProperties(t,r),r._optional=n,r}};function c(){return new s(`string`,{_check:o})}function l(){return new s(`number`,{_check:i})}function u(){return new s(`int`,{_check:r})}function d(){return new s(`boolean`,{_check:t})}function f(){return new s(`none`,{_check:e=>e==null,_optional:!0})}function p(){return new s(`any`,{_check:e=>e!=null})}const m=l,h=l,g=l;function _(e){return new s(`object`,{_check:a,_object:e})}function v(e){return new s(`record`,{_check:a,_type:e})}function y(e){return new s(`union`,{_check:t=>e.some(e=>e._check?.(t)??!1),_union:e})}function b(e){return new s(`literal`,{_check:t=>t===e,_default:e})}function x(e){return new s(`string`,{_check:t=>typeof t==`string`&&e.includes(t),_enumValues:e})}function S(e){return new s(`tuple`,{_check:t=>Array.isArray(t)&&t.length===e.length&&e.every((e,n)=>e._check?.(t[n])??!1),_type:e})}function C(t){return new s(`array`,{_check:e,_type:t})}function w(e,t){return new s(`function`,{_check:n,_args:e,_ret:t})}function T(e,t){return new s(`rpc`,{_check:n,_info:e,_ret:t??f()})}export{s as Type,p as any,C as array,d as boolean,h as double,m as float,w as func,u as int,b as literal,f as none,l as number,_ as object,g as real,v as record,T as rpc,c as string,x as stringLiterals,S as tuple,y as union};
1
+ import { isArray, isBoolean, isFunction, isInteger, isNumber, isObject, isString } from "../data/is.mjs";
2
+
3
+ //#region src/common/schema/schema.ts
4
+ /**
5
+ * Core Type class for schema validation and type inference
6
+ * Implements StandardSchemaV1 for cross-library compatibility
7
+ */
8
+ var Type = class Type {
9
+ type;
10
+ _default;
11
+ _optional;
12
+ _meta;
13
+ _check;
14
+ _object;
15
+ _type;
16
+ _union;
17
+ _enumValues;
18
+ _args;
19
+ _ret;
20
+ _info;
21
+ constructor(name, options = {}) {
22
+ this.type = name;
23
+ Object.assign(this, options);
24
+ }
25
+ /**
26
+ * Standard Schema V1 compliance property
27
+ * Provides a standard interface for validation and type inference
28
+ */
29
+ get "~standard"() {
30
+ return {
31
+ version: 1,
32
+ vendor: "zeed",
33
+ validate: (value) => {
34
+ return this.validate(value);
35
+ },
36
+ types: {
37
+ input: void 0,
38
+ output: void 0
39
+ }
40
+ };
41
+ }
42
+ /**
43
+ * Validation method for standard-schema compliance
44
+ */
45
+ validate(value) {
46
+ if (value == null) {
47
+ if (this._optional) return { value: void 0 };
48
+ if (this._default !== void 0) return { value: isFunction(this._default) ? this._default(this) : this._default };
49
+ return { issues: [{
50
+ message: `Required value is missing`,
51
+ path: []
52
+ }] };
53
+ }
54
+ if (this.type === "literal" && this._default !== value) return { issues: [{
55
+ message: `Expected literal value ${this._default}, got ${value}`,
56
+ path: []
57
+ }] };
58
+ if (this._enumValues && Array.isArray(this._enumValues)) {
59
+ if (!this._enumValues.includes(value)) return { issues: [{
60
+ message: `Expected one of [${this._enumValues.join(", ")}], got ${value}`,
61
+ path: []
62
+ }] };
63
+ }
64
+ if (this._union && Array.isArray(this._union)) {
65
+ for (const option of this._union) {
66
+ const result = option.validate(value);
67
+ if (!result.issues) return result;
68
+ }
69
+ return { issues: [{
70
+ message: `Value does not match any union variant`,
71
+ path: []
72
+ }] };
73
+ }
74
+ if (this.type === "array" || this.type === "tuple") {
75
+ if (!Array.isArray(value)) return { issues: [{
76
+ message: `Expected array, got ${typeof value}`,
77
+ path: []
78
+ }] };
79
+ if (this.type === "tuple" && this._type) {
80
+ const items = this._type;
81
+ if (value.length !== items.length) return { issues: [{
82
+ message: `Expected tuple of length ${items.length}, got ${value.length}`,
83
+ path: []
84
+ }] };
85
+ const issues = [];
86
+ for (let i = 0; i < items.length; i++) {
87
+ const itemResult = items[i].validate(value[i]);
88
+ if (itemResult.issues) for (const issue of itemResult.issues) issues.push({
89
+ message: issue.message,
90
+ path: [i, ...issue.path || []]
91
+ });
92
+ }
93
+ if (issues.length > 0) return { issues };
94
+ } else if (this._type) {
95
+ const itemType = this._type;
96
+ const issues = [];
97
+ for (let i = 0; i < value.length; i++) {
98
+ const itemResult = itemType.validate(value[i]);
99
+ if (itemResult.issues) for (const issue of itemResult.issues) issues.push({
100
+ message: issue.message,
101
+ path: [i, ...issue.path || []]
102
+ });
103
+ }
104
+ if (issues.length > 0) return { issues };
105
+ }
106
+ }
107
+ if (this._object) {
108
+ if (!isObject(value)) return { issues: [{
109
+ message: `Expected object, got ${typeof value}`,
110
+ path: []
111
+ }] };
112
+ const issues = [];
113
+ const obj = value;
114
+ for (const key in this._object) {
115
+ const propSchema = this._object[key];
116
+ const propValue = obj[key];
117
+ const propResult = propSchema.validate(propValue);
118
+ if (propResult.issues) for (const issue of propResult.issues) issues.push({
119
+ message: issue.message,
120
+ path: [key, ...issue.path || []]
121
+ });
122
+ }
123
+ if (issues.length > 0) return { issues };
124
+ return {
125
+ value,
126
+ issues: void 0
127
+ };
128
+ }
129
+ if (this.type === "record" && this._type) {
130
+ if (!isObject(value)) return { issues: [{
131
+ message: `Expected object, got ${typeof value}`,
132
+ path: []
133
+ }] };
134
+ const valueType = this._type;
135
+ const issues = [];
136
+ const obj = value;
137
+ for (const key in obj) {
138
+ const propResult = valueType.validate(obj[key]);
139
+ if (propResult.issues) for (const issue of propResult.issues) issues.push({
140
+ message: issue.message,
141
+ path: [key, ...issue.path || []]
142
+ });
143
+ }
144
+ if (issues.length > 0) return { issues };
145
+ }
146
+ if (this._check && !this._check(value)) return { issues: [{
147
+ message: `Expected ${this.type}, got ${typeof value}`,
148
+ path: []
149
+ }] };
150
+ return { value };
151
+ }
152
+ /**
153
+ * Creates a copy of the type with new properties merged
154
+ */
155
+ _cloneWithProps(newProps = {}) {
156
+ const cloned = new Type(this.type);
157
+ for (const prop of [
158
+ "_default",
159
+ "_optional",
160
+ "_meta",
161
+ "_check",
162
+ "_object",
163
+ "_type",
164
+ "_union",
165
+ "_enumValues",
166
+ "_args",
167
+ "_ret",
168
+ "_info"
169
+ ]) if (this[prop] !== void 0) cloned[prop] = this[prop];
170
+ Object.assign(cloned, newProps);
171
+ return cloned;
172
+ }
173
+ /**
174
+ * Helper to copy type properties when creating new type instances
175
+ */
176
+ static _copyTypeProperties(source, target) {
177
+ for (const prop of [
178
+ "_check",
179
+ "_default",
180
+ "_meta",
181
+ "_object",
182
+ "_type",
183
+ "_enumValues"
184
+ ]) if (source[prop] !== void 0) target[prop] = source[prop];
185
+ }
186
+ /**
187
+ * Marks the type as optional, meaning it can be undefined
188
+ * This is useful for properties that are not required.
189
+ */
190
+ optional() {
191
+ return this._cloneWithProps({ _optional: true });
192
+ }
193
+ /**
194
+ * Sets a default value for the type, which will be used if the value is not provided
195
+ * The default value can be a function that receives the schema as argument, or a static value.
196
+ */
197
+ default(value) {
198
+ return this._cloneWithProps({ _default: value });
199
+ }
200
+ /**
201
+ * Props / Metadata for the type, like description or other properties
202
+ */
203
+ meta(meta) {
204
+ return this._cloneWithProps({ _meta: meta });
205
+ }
206
+ /**
207
+ * Sets the `desc` property for the type, which is a human-readable description
208
+ */
209
+ describe(msg) {
210
+ const meta = this._meta || {};
211
+ meta.desc = msg;
212
+ return this._cloneWithProps({ _meta: meta });
213
+ }
214
+ /**
215
+ * Extends the type with an object, merging the properties
216
+ */
217
+ extend(obj) {
218
+ if (!this._object) throw new Error("extend() can only be used on object schemas");
219
+ return object({
220
+ ...this._object,
221
+ ...obj
222
+ });
223
+ }
224
+ /**
225
+ * Picks certain keys from an object schema
226
+ */
227
+ pick(keys) {
228
+ if (!this._object) throw new Error("pick() can only be used on object schemas");
229
+ const pickedObj = {};
230
+ for (const key of Object.keys(keys)) if (key in this._object) pickedObj[key] = this._object[key];
231
+ return object(pickedObj);
232
+ }
233
+ /**
234
+ * Omits certain keys from an object schema
235
+ */
236
+ omit(keys) {
237
+ if (!this._object) throw new Error("omit() can only be used on object schemas");
238
+ const omittedObj = { ...this._object };
239
+ for (const key of Object.keys(keys)) delete omittedObj[key];
240
+ return object(omittedObj);
241
+ }
242
+ /**
243
+ * Helper method to modify object properties with a transformation function
244
+ */
245
+ _transformObjectProperties(transform, keys) {
246
+ if (!this._object) throw new Error("This operation can only be used on object schemas");
247
+ const transformedObj = {};
248
+ const originalObj = this._object;
249
+ for (const [key, typeInstance] of Object.entries(originalObj)) transformedObj[key] = transform(key, typeInstance, !keys || key in keys);
250
+ return object(transformedObj);
251
+ }
252
+ partial(keys) {
253
+ if (!this._object) throw new Error("partial() can only be used on object schemas");
254
+ return this._transformObjectProperties((key, type, shouldTransform) => {
255
+ if (!shouldTransform) return type;
256
+ return Type._cloneTypeWithOptional(type, true);
257
+ }, keys);
258
+ }
259
+ required(keys) {
260
+ if (!this._object) throw new Error("required() can only be used on object schemas");
261
+ return this._transformObjectProperties((key, type, shouldTransform) => {
262
+ if (!shouldTransform) return type;
263
+ return Type._cloneTypeWithOptional(type, false);
264
+ }, keys);
265
+ }
266
+ /**
267
+ * Helper method to clone a type with optional flag
268
+ */
269
+ static _cloneTypeWithOptional(originalType, optional) {
270
+ const newType = new Type(originalType.type);
271
+ Type._copyTypeProperties(originalType, newType);
272
+ newType._optional = optional;
273
+ return newType;
274
+ }
275
+ };
276
+ /**
277
+ * Creates a string type validator
278
+ */
279
+ function string() {
280
+ return new Type("string", { _check: isString });
281
+ }
282
+ /**
283
+ * Creates a number type validator
284
+ */
285
+ function number() {
286
+ return new Type("number", { _check: isNumber });
287
+ }
288
+ /**
289
+ * Creates an integer type validator
290
+ */
291
+ function int() {
292
+ return new Type("int", { _check: isInteger });
293
+ }
294
+ /**
295
+ * Creates a boolean type validator
296
+ */
297
+ function boolean() {
298
+ return new Type("boolean", { _check: isBoolean });
299
+ }
300
+ /**
301
+ * Creates a none type validator (undefined | null)
302
+ * Like undefined | null in TS and nil in Swift
303
+ */
304
+ function none() {
305
+ return new Type("none", {
306
+ _check: (v) => v == null,
307
+ _optional: true
308
+ });
309
+ }
310
+ /**
311
+ * Creates an any type validator that accepts any non-null value
312
+ */
313
+ function any() {
314
+ return new Type("any", { _check: (v) => v != null });
315
+ }
316
+ const float = number;
317
+ const double = number;
318
+ const real = number;
319
+ /**
320
+ * Creates an object type validator with specified properties
321
+ */
322
+ function object(tobj) {
323
+ return new Type("object", {
324
+ _check: isObject,
325
+ _object: tobj
326
+ });
327
+ }
328
+ /**
329
+ * Creates a record type validator (object with string keys and uniform value type)
330
+ */
331
+ function record(valueType) {
332
+ return new Type("record", {
333
+ _check: isObject,
334
+ _type: valueType
335
+ });
336
+ }
337
+ /**
338
+ * Creates a union type validator (like `string | number | boolean`)
339
+ */
340
+ function union(options) {
341
+ return new Type("union", {
342
+ _check: (v) => options.some((option) => option._check?.(v) ?? false),
343
+ _union: options
344
+ });
345
+ }
346
+ /**
347
+ * Creates a literal value validator
348
+ */
349
+ function literal(value) {
350
+ return new Type("literal", {
351
+ _check: (v) => v === value,
352
+ _default: value
353
+ });
354
+ }
355
+ /**
356
+ * Creates a string literal union validator (like `"a" | "b" | "c"`)
357
+ */
358
+ function stringLiterals(values) {
359
+ return new Type("string", {
360
+ _check: (v) => typeof v === "string" && values.includes(v),
361
+ _enumValues: values
362
+ });
363
+ }
364
+ /**
365
+ * Creates a tuple type validator with fixed length and types e.g. [string, number, boolean]
366
+ */
367
+ function tuple(items) {
368
+ return new Type("tuple", {
369
+ _check: (v) => Array.isArray(v) && v.length === items.length && items.every((item, i) => item._check?.(v[i]) ?? false),
370
+ _type: items
371
+ });
372
+ }
373
+ /**
374
+ * Creates an array type validator for a specific item type
375
+ */
376
+ function array(itemType) {
377
+ return new Type("array", {
378
+ _check: isArray,
379
+ _type: itemType
380
+ });
381
+ }
382
+ /**
383
+ * Creates a regular function type validator
384
+ */
385
+ function func(args, ret) {
386
+ return new Type("function", {
387
+ _check: isFunction,
388
+ _args: args,
389
+ _ret: ret
390
+ });
391
+ }
392
+ /**
393
+ * Creates an RPC function type validator that takes one argument and returns a promise
394
+ */
395
+ function rpc(info, ret) {
396
+ return new Type("rpc", {
397
+ _check: isFunction,
398
+ _info: info,
399
+ _ret: ret ?? none()
400
+ });
401
+ }
402
+
403
+ //#endregion
404
+ export { Type, any, array, boolean, double, float, func, int, literal, none, number, object, real, record, rpc, string, stringLiterals, tuple, union };
2
405
  //# sourceMappingURL=schema.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.mjs","names":[],"sources":["../../../src/common/schema/schema.ts"],"sourcesContent":["// With many, many inspiration from https://github.com/badrap/valita MIT License as of 2024-09-10\n\nimport type { StandardSchemaV1 } from './schema-standard'\nimport { isArray, isBoolean, isFunction, isInteger, isNumber, isObject, isString } from '../data/is'\n\n/**\n * Metadata interface for type descriptions and additional properties\n */\nexport interface TypeMeta {\n desc?: string\n}\n\n/**\n * Core Type class for schema validation and type inference\n * Implements StandardSchemaV1 for cross-library compatibility\n */\nexport class Type<T = unknown> {\n readonly type: string\n\n _default?: any\n _optional?: boolean\n _meta?: TypeMeta\n _check?: (obj: any) => boolean\n _object?: any\n _type?: any\n _union?: any\n _enumValues?: any\n _args?: any\n _ret?: any\n _info?: any\n\n // [key: `_${string}`]: any // Allow only optional dynamic properties starting with an underscore\n\n constructor(name: string, options: Partial<Type<T>> = {}) {\n this.type = name\n Object.assign(this, options)\n }\n\n /**\n * Standard Schema V1 compliance property\n * Provides a standard interface for validation and type inference\n */\n get '~standard'(): any {\n return {\n version: 1,\n vendor: 'zeed',\n validate: (value: unknown): StandardSchemaV1.Result<T> => {\n return this.validate(value)\n },\n types: {\n input: undefined as any as T,\n output: undefined as any as T,\n },\n }\n }\n\n /**\n * Validation method for standard-schema compliance\n */\n validate(value: any): any {\n // const messages: Array<{ path: string, message: string, type: string, valid: boolean }> = []\n\n // Handle null/undefined cases\n if (value == null) {\n if (this._optional) {\n return { value: undefined as any as T }\n }\n if (this._default !== undefined) {\n const defaultValue = isFunction(this._default) ? this._default(this) : this._default\n return { value: defaultValue }\n }\n return {\n issues: [{\n message: `Required value is missing`,\n path: [],\n }],\n }\n }\n\n // Handle literal types\n if (this.type === 'literal' && this._default !== value) {\n return {\n issues: [{\n message: `Expected literal value ${this._default}, got ${value}`,\n path: [],\n }],\n }\n }\n\n // Handle string literals (enums)\n if (this._enumValues && Array.isArray(this._enumValues)) {\n if (!this._enumValues.includes(value)) {\n return {\n issues: [{\n message: `Expected one of [${this._enumValues.join(', ')}], got ${value}`,\n path: [],\n }],\n }\n }\n }\n\n // Handle union types\n if (this._union && Array.isArray(this._union)) {\n for (const option of this._union) {\n const result = (option as Type<any>).validate(value)\n if (!result.issues) {\n return result\n }\n }\n return {\n issues: [{\n message: `Value does not match any union variant`,\n path: [],\n }],\n }\n }\n\n // Handle array types\n if (this.type === 'array' || this.type === 'tuple') {\n if (!Array.isArray(value)) {\n return {\n issues: [{\n message: `Expected array, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n if (this.type === 'tuple' && this._type) {\n const items = this._type as Type<any>[]\n if (value.length !== items.length) {\n return {\n issues: [{\n message: `Expected tuple of length ${items.length}, got ${value.length}`,\n path: [],\n }],\n }\n }\n\n const issues: StandardSchemaV1.Issue[] = []\n for (let i = 0; i < items.length; i++) {\n const itemResult = items[i].validate(value[i])\n if (itemResult.issues) {\n for (const issue of itemResult.issues) {\n issues.push({\n message: issue.message,\n path: [i, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n else if (this._type) {\n // Regular array with item type\n const itemType = this._type as Type<any>\n const issues: StandardSchemaV1.Issue[] = []\n\n for (let i = 0; i < value.length; i++) {\n const itemResult = itemType.validate(value[i])\n if (itemResult.issues) {\n for (const issue of itemResult.issues) {\n issues.push({\n message: issue.message,\n path: [i, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n }\n\n // Handle object types\n if (this._object) {\n if (!isObject(value)) {\n return {\n issues: [{\n message: `Expected object, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n const issues: StandardSchemaV1.Issue[] = []\n const obj = value as Record<string, any>\n\n for (const key in this._object) {\n const propSchema = this._object[key] as Type<any>\n const propValue = obj[key]\n const propResult = propSchema.validate(propValue)\n\n if (propResult.issues) {\n for (const issue of propResult.issues) {\n issues.push({\n message: issue.message,\n path: [key, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n\n return { value: value as T, issues: undefined }\n }\n\n // Handle record types\n if (this.type === 'record' && this._type) {\n if (!isObject(value)) {\n return {\n issues: [{\n message: `Expected object, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n const valueType = this._type as Type<any>\n const issues: StandardSchemaV1.Issue[] = []\n const obj = value as Record<string, any>\n\n for (const key in obj) {\n const propResult = valueType.validate(obj[key])\n if (propResult.issues) {\n for (const issue of propResult.issues) {\n issues.push({\n message: issue.message,\n path: [key, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n\n // Check primitive types\n if (this._check && !this._check(value)) {\n return {\n issues: [{\n message: `Expected ${this.type}, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n // Success - return the value\n return { value: value as T }\n }\n\n /**\n * Creates a copy of the type with new properties merged\n */\n private _cloneWithProps<U = T>(newProps: Partial<Type<any>> = {}): Type<U> {\n const cloned = new Type<U>(this.type)\n // Copy all existing properties\n const propertiesToCopy = ['_default', '_optional', '_meta', '_check', '_object', '_type', '_union', '_enumValues', '_args', '_ret', '_info']\n for (const prop of propertiesToCopy) {\n if ((this as any)[prop] !== undefined) {\n (cloned as any)[prop] = (this as any)[prop]\n }\n }\n // Apply new properties\n Object.assign(cloned, newProps)\n return cloned\n }\n\n /**\n * Helper to copy type properties when creating new type instances\n */\n private static _copyTypeProperties(source: Type<any>, target: Type<any>): void {\n const properties = ['_check', '_default', '_meta', '_object', '_type', '_enumValues']\n for (const prop of properties) {\n if ((source as any)[prop] !== undefined) {\n (target as any)[prop] = (source as any)[prop]\n }\n }\n }\n\n /**\n * Marks the type as optional, meaning it can be undefined\n * This is useful for properties that are not required.\n */\n optional(): Type<T | undefined> {\n return this._cloneWithProps<T | undefined>({ _optional: true })\n }\n\n /**\n * Sets a default value for the type, which will be used if the value is not provided\n * The default value can be a function that receives the schema as argument, or a static value.\n */\n default(value: T | ((schema?: this) => T)): Type<T> {\n return this._cloneWithProps<T>({ _default: value })\n }\n\n /**\n * Props / Metadata for the type, like description or other properties\n */\n meta(meta: TypeMeta): Type<T> {\n return this._cloneWithProps<T>({ _meta: meta })\n }\n\n /**\n * Sets the `desc` property for the type, which is a human-readable description\n */\n describe(msg: string): Type<T> {\n const meta = this._meta || {}\n meta.desc = msg\n return this._cloneWithProps<T>({ _meta: meta })\n }\n\n /**\n * Extends the type with an object, merging the properties\n */\n extend<O>(obj: O): Type<T & TypeObject<O>> {\n if (!this._object) {\n throw new Error('extend() can only be used on object schemas')\n }\n const newObj = { ...this._object, ...obj }\n return object(newObj) as any\n }\n\n /**\n * Picks certain keys from an object schema\n */\n pick<K extends keyof T>(keys: Record<K, true>): Type<Pick<T, K>> {\n if (!this._object) {\n throw new Error('pick() can only be used on object schemas')\n }\n const pickedObj: any = {}\n for (const key of Object.keys(keys)) {\n if (key in this._object) {\n pickedObj[key] = (this._object as any)[key]\n }\n }\n return object(pickedObj) as any\n }\n\n /**\n * Omits certain keys from an object schema\n */\n omit<K extends keyof T>(keys: Record<K, true>): Type<Omit<T, K>> {\n if (!this._object) {\n throw new Error('omit() can only be used on object schemas')\n }\n const omittedObj: any = { ...this._object }\n for (const key of Object.keys(keys)) {\n delete omittedObj[key]\n }\n return object(omittedObj) as any\n }\n\n /**\n * Helper method to modify object properties with a transformation function\n */\n private _transformObjectProperties(\n transform: (key: string, type: Type<any>, shouldTransform: boolean) => Type<any>,\n keys?: Record<string, true>,\n ): any {\n if (!this._object) {\n throw new Error('This operation can only be used on object schemas')\n }\n\n const transformedObj: any = {}\n const originalObj = this._object as any\n\n for (const [key, typeInstance] of Object.entries(originalObj)) {\n const shouldTransform = !keys || key in keys\n transformedObj[key] = transform(key, typeInstance as Type<any>, shouldTransform)\n }\n\n return object(transformedObj)\n }\n\n /**\n * Makes some or all properties of an object schema optional\n */\n partial(): Type<Partial<T>>\n partial<K extends keyof T>(keys: Record<K, true>): Type<Partial<Pick<T, K>> & Omit<T, K>>\n partial<K extends keyof T>(keys?: Record<K, true>): Type<Partial<T> | (Partial<Pick<T, K>> & Omit<T, K>)> {\n if (!this._object) {\n throw new Error('partial() can only be used on object schemas')\n }\n return this._transformObjectProperties((key, type, shouldTransform) => {\n if (!shouldTransform)\n return type\n return Type._cloneTypeWithOptional(type, true)\n }, keys)\n }\n\n /**\n * Makes some or all properties of an object schema required\n */\n required(): Type<Required<T>>\n required<K extends keyof T>(keys: Record<K, true>): Type<Required<Pick<T, K>> & Omit<T, K>>\n required<K extends keyof T>(keys?: Record<K, true>): Type<Required<T> | (Required<Pick<T, K>> & Omit<T, K>)> {\n if (!this._object) {\n throw new Error('required() can only be used on object schemas')\n }\n return this._transformObjectProperties((key, type, shouldTransform) => {\n if (!shouldTransform)\n return type\n return Type._cloneTypeWithOptional(type, false)\n }, keys)\n }\n\n /**\n * Helper method to clone a type with optional flag\n */\n private static _cloneTypeWithOptional(originalType: Type<any>, optional: boolean): Type<any> {\n const newType = new Type(originalType.type)\n Type._copyTypeProperties(originalType, newType)\n newType._optional = optional\n return newType\n }\n}\n\n/**\n * Type inference utility for extracting the TypeScript type from a schema Type\n */\nexport type Infer<T> = T extends Type<infer TT> ? TT : never\n\n// =============================================================================\n// Primitive Types\n// =============================================================================\n\n/**\n * Creates a string type validator\n */\nexport function string(): Type<string> {\n return new Type('string', {\n _check: isString,\n })\n}\n\n/**\n * Creates a number type validator\n */\nexport function number(): Type<number> {\n return new Type('number', {\n _check: isNumber,\n })\n}\n\n/**\n * Creates an integer type validator\n */\nexport function int(): Type<number> {\n return new Type('int', {\n _check: isInteger,\n })\n}\n\n/**\n * Creates a boolean type validator\n */\nexport function boolean(): Type<boolean> {\n return new Type('boolean', {\n _check: isBoolean,\n })\n}\n\n/**\n * Creates a none type validator (undefined | null)\n * Like undefined | null in TS and nil in Swift\n */\nexport function none(): Type<undefined> {\n return new Type('none', {\n _check: (v: any) => v == null,\n _optional: true,\n })\n}\n\n/**\n * Creates an any type validator that accepts any non-null value\n */\nexport function any<T = any>(): Type<T> {\n return new Type('any', {\n _check: (v: any) => v != null,\n })\n}\n\n// Aliases for number types\nexport const float = number\nexport const double = number\nexport const real = number\n\n// =============================================================================\n// Object Types\n// =============================================================================\n\n/**\n * Utility type to make object properties optional if their value type includes undefined.\n * @category Schema\n */\nexport type TypeObjectFixOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]?: T[K] & {}\n} & {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K] & {}\n}\n\n/**\n * Utility type for pretty-printing object types\n */\ntype TypeObjectPretty<V> = Extract<{ [K in keyof V]: V[K] }, unknown>\n\n/**\n * Main object type utility\n */\ntype TypeObject<T> = TypeObjectPretty<TypeObjectFixOptional<{\n [K in keyof T]: Infer<T[K]>\n}>>\n\n/**\n * Creates an object type validator with specified properties\n */\nexport function object<T>(tobj: T): Type<TypeObject<T>> {\n return new Type('object', {\n _check: isObject,\n _object: tobj,\n })\n}\n\n/**\n * Creates a record type validator (object with string keys and uniform value type)\n */\nexport function record<T extends Type>(valueType: T): Type<Record<string, Infer<T>>> {\n return new Type('record', {\n _check: isObject,\n _type: valueType,\n })\n}\n\n// =============================================================================\n// Union Types\n// =============================================================================\n\n/**\n * Utility type for union of types.\n * @category Schema\n */\nexport type TypeUnion<T extends Type<any>[]> = {\n [K in keyof T]: T[K] extends Type<infer U> ? U : never\n}[number]\n\n/**\n * Creates a union type validator (like `string | number | boolean`)\n */\nexport function union<T extends Type<any>[]>(options: T): Type<TypeUnion<T>> {\n return new Type('union', {\n _check: (v: any) => options.some(option => option._check?.(v) ?? false),\n _union: options,\n })\n}\n\n// =============================================================================\n// Literal Types\n// =============================================================================\n\n/**\n * Utility type for literal types.\n * @category Schema\n */\nexport type TypeLiterals = string | number | bigint | boolean\n\n/**\n * Creates a literal value validator\n */\nexport function literal<T extends TypeLiterals>(value: T): Type<T> {\n return new Type('literal', {\n _check: (v: any) => v === value,\n _default: value,\n })\n}\n\n/**\n * Creates a string literal union validator (like `\"a\" | \"b\" | \"c\"`)\n */\nexport function stringLiterals<const T extends readonly string[]>(values: T): Type<T[number]> {\n return new Type('string', {\n _check: (v: any) => typeof v === 'string' && (values as readonly string[]).includes(v),\n _enumValues: values,\n })\n}\n\n// =============================================================================\n// Collection Types\n// =============================================================================\n\n/**\n * Utility type for tuple types.\n * @category Schema\n */\nexport type TypeTuple<T extends readonly Type[]> = {\n -readonly [K in keyof T]: T[K] extends Type<infer U> ? U : never\n}\n\n/**\n * Output type for TypeArray.\n * @category Schema\n */\nexport type TypeArrayOutput<Head extends Type[], Rest extends Type | undefined> = [\n ...TypeTuple<Head>,\n ...(Rest extends Type ? Infer<Rest>[] : []),\n]\n\n/**\n * Utility type for array types.\n * @category Schema\n */\nexport type TypeArray<Head extends Type[] = Type[], Rest extends Type | undefined = Type | undefined> = Type<TypeArrayOutput<Head, Rest>>\n\n/**\n * Creates a tuple type validator with fixed length and types e.g. [string, number, boolean]\n */\nexport function tuple<const T extends readonly Type[]>(items: T): Type<TypeTuple<T>> {\n return new Type('tuple', {\n _check: (v: any) => Array.isArray(v) && v.length === items.length && items.every((item, i) => (item as Type)._check?.(v[i]) ?? false),\n _type: items,\n })\n}\n\n/**\n * Creates an array type validator for a specific item type\n */\nexport function array<T>(itemType: Type<T>): Type<T[]> {\n return new Type('array', {\n _check: isArray,\n _type: itemType,\n })\n}\n\n// =============================================================================\n// Function Types\n// =============================================================================\n\n/**\n * Creates a regular function type validator\n */\nexport function func<\n TypeFuncArgs extends [Type<unknown>, ...Type<any>[]] | [],\n TypeFuncRet = Type,\n T = (...args: TypeTuple<TypeFuncArgs>) => Infer<TypeFuncRet>,\n>(args: TypeFuncArgs, ret: TypeFuncRet): Type<T> {\n return new Type('function', {\n _check: isFunction,\n _args: args,\n _ret: ret,\n })\n}\n\n/**\n * Creates an RPC function type validator that takes one argument and returns a promise\n */\nexport function rpc<\n TypeRpcInfo extends Type<unknown> | undefined = undefined,\n TypeRpcRet extends Type<unknown> = Type<void>,\n T = TypeRpcInfo extends undefined\n ? () => Infer<TypeRpcRet>\n : (info: Infer<TypeRpcInfo>) => Infer<TypeRpcRet> | Promise<Infer<TypeRpcRet>>,\n>(info?: TypeRpcInfo, ret?: TypeRpcRet): Type<T> {\n return new Type('rpc', {\n _check: isFunction,\n _info: info,\n _ret: ret ?? none(),\n })\n}\n"],"mappings":"iIAgBA,IAAa,EAAb,MAAa,CAAkB,CAC7B,KAEA,SACA,UACA,MACA,OACA,QACA,MACA,OACA,YACA,MACA,KACA,MAIA,YAAY,EAAc,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vB,OAAS,GAAW,EAAQ,KAAK,GAAU,EAAO,SAAS,EAAE,EAAI,GAAM,CACvE,OAAQ,EACT,CAAC,CAgBJ,SAAgB,EAAgC,EAAmB,CACjE,OAAO,IAAI,EAAK,UAAW,CACzB,OAAS,GAAW,IAAM,EAC1B,SAAU,EACX,CAAC,CAMJ,SAAgB,EAAkD,EAA4B,CAC5F,OAAO,IAAI,EAAK,SAAU,CACxB,OAAS,GAAW,OAAO,GAAM,UAAa,EAA6B,SAAS,EAAE,CACtF,YAAa,EACd,CAAC,CAiCJ,SAAgB,EAAuC,EAA8B,CACnF,OAAO,IAAI,EAAK,QAAS,CACvB,OAAS,GAAW,MAAM,QAAQ,EAAE,EAAI,EAAE,SAAW,EAAM,QAAU,EAAM,OAAO,EAAM,IAAO,EAAc,SAAS,EAAE,GAAG,EAAI,GAAM,CACrI,MAAO,EACR,CAAC,CAMJ,SAAgB,EAAS,EAA8B,CACrD,OAAO,IAAI,EAAK,QAAS,CACvB,OAAQ,EACR,MAAO,EACR,CAAC,CAUJ,SAAgB,EAId,EAAoB,EAA2B,CAC/C,OAAO,IAAI,EAAK,WAAY,CAC1B,OAAQ,EACR,MAAO,EACP,KAAM,EACP,CAAC,CAMJ,SAAgB,EAMd,EAAoB,EAA2B,CAC/C,OAAO,IAAI,EAAK,MAAO,CACrB,OAAQ,EACR,MAAO,EACP,KAAM,GAAO,GAAM,CACpB,CAAC"}
1
+ {"version":3,"file":"schema.mjs","names":[],"sources":["../../../src/common/schema/schema.ts"],"sourcesContent":["// With many, many inspiration from https://github.com/badrap/valita MIT License as of 2024-09-10\n\nimport type { StandardSchemaV1 } from './schema-standard'\nimport { isArray, isBoolean, isFunction, isInteger, isNumber, isObject, isString } from '../data/is'\n\n/**\n * Metadata interface for type descriptions and additional properties\n */\nexport interface TypeMeta {\n desc?: string\n}\n\n/**\n * Core Type class for schema validation and type inference\n * Implements StandardSchemaV1 for cross-library compatibility\n */\nexport class Type<T = unknown> {\n readonly type: string\n\n _default?: any\n _optional?: boolean\n _meta?: TypeMeta\n _check?: (obj: any) => boolean\n _object?: any\n _type?: any\n _union?: any\n _enumValues?: any\n _args?: any\n _ret?: any\n _info?: any\n\n // [key: `_${string}`]: any // Allow only optional dynamic properties starting with an underscore\n\n constructor(name: string, options: Partial<Type<T>> = {}) {\n this.type = name\n Object.assign(this, options)\n }\n\n /**\n * Standard Schema V1 compliance property\n * Provides a standard interface for validation and type inference\n */\n get '~standard'(): any {\n return {\n version: 1,\n vendor: 'zeed',\n validate: (value: unknown): StandardSchemaV1.Result<T> => {\n return this.validate(value)\n },\n types: {\n input: undefined as any as T,\n output: undefined as any as T,\n },\n }\n }\n\n /**\n * Validation method for standard-schema compliance\n */\n validate(value: any): any {\n // const messages: Array<{ path: string, message: string, type: string, valid: boolean }> = []\n\n // Handle null/undefined cases\n if (value == null) {\n if (this._optional) {\n return { value: undefined as any as T }\n }\n if (this._default !== undefined) {\n const defaultValue = isFunction(this._default) ? this._default(this) : this._default\n return { value: defaultValue }\n }\n return {\n issues: [{\n message: `Required value is missing`,\n path: [],\n }],\n }\n }\n\n // Handle literal types\n if (this.type === 'literal' && this._default !== value) {\n return {\n issues: [{\n message: `Expected literal value ${this._default}, got ${value}`,\n path: [],\n }],\n }\n }\n\n // Handle string literals (enums)\n if (this._enumValues && Array.isArray(this._enumValues)) {\n if (!this._enumValues.includes(value)) {\n return {\n issues: [{\n message: `Expected one of [${this._enumValues.join(', ')}], got ${value}`,\n path: [],\n }],\n }\n }\n }\n\n // Handle union types\n if (this._union && Array.isArray(this._union)) {\n for (const option of this._union) {\n const result = (option as Type<any>).validate(value)\n if (!result.issues) {\n return result\n }\n }\n return {\n issues: [{\n message: `Value does not match any union variant`,\n path: [],\n }],\n }\n }\n\n // Handle array types\n if (this.type === 'array' || this.type === 'tuple') {\n if (!Array.isArray(value)) {\n return {\n issues: [{\n message: `Expected array, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n if (this.type === 'tuple' && this._type) {\n const items = this._type as Type<any>[]\n if (value.length !== items.length) {\n return {\n issues: [{\n message: `Expected tuple of length ${items.length}, got ${value.length}`,\n path: [],\n }],\n }\n }\n\n const issues: StandardSchemaV1.Issue[] = []\n for (let i = 0; i < items.length; i++) {\n const itemResult = items[i].validate(value[i])\n if (itemResult.issues) {\n for (const issue of itemResult.issues) {\n issues.push({\n message: issue.message,\n path: [i, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n else if (this._type) {\n // Regular array with item type\n const itemType = this._type as Type<any>\n const issues: StandardSchemaV1.Issue[] = []\n\n for (let i = 0; i < value.length; i++) {\n const itemResult = itemType.validate(value[i])\n if (itemResult.issues) {\n for (const issue of itemResult.issues) {\n issues.push({\n message: issue.message,\n path: [i, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n }\n\n // Handle object types\n if (this._object) {\n if (!isObject(value)) {\n return {\n issues: [{\n message: `Expected object, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n const issues: StandardSchemaV1.Issue[] = []\n const obj = value as Record<string, any>\n\n for (const key in this._object) {\n const propSchema = this._object[key] as Type<any>\n const propValue = obj[key]\n const propResult = propSchema.validate(propValue)\n\n if (propResult.issues) {\n for (const issue of propResult.issues) {\n issues.push({\n message: issue.message,\n path: [key, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n\n return { value: value as T, issues: undefined }\n }\n\n // Handle record types\n if (this.type === 'record' && this._type) {\n if (!isObject(value)) {\n return {\n issues: [{\n message: `Expected object, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n const valueType = this._type as Type<any>\n const issues: StandardSchemaV1.Issue[] = []\n const obj = value as Record<string, any>\n\n for (const key in obj) {\n const propResult = valueType.validate(obj[key])\n if (propResult.issues) {\n for (const issue of propResult.issues) {\n issues.push({\n message: issue.message,\n path: [key, ...(issue.path || [])],\n })\n }\n }\n }\n\n if (issues.length > 0) {\n return { issues }\n }\n }\n\n // Check primitive types\n if (this._check && !this._check(value)) {\n return {\n issues: [{\n message: `Expected ${this.type}, got ${typeof value}`,\n path: [],\n }],\n }\n }\n\n // Success - return the value\n return { value: value as T }\n }\n\n /**\n * Creates a copy of the type with new properties merged\n */\n private _cloneWithProps<U = T>(newProps: Partial<Type<any>> = {}): Type<U> {\n const cloned = new Type<U>(this.type)\n // Copy all existing properties\n const propertiesToCopy = ['_default', '_optional', '_meta', '_check', '_object', '_type', '_union', '_enumValues', '_args', '_ret', '_info']\n for (const prop of propertiesToCopy) {\n if ((this as any)[prop] !== undefined) {\n (cloned as any)[prop] = (this as any)[prop]\n }\n }\n // Apply new properties\n Object.assign(cloned, newProps)\n return cloned\n }\n\n /**\n * Helper to copy type properties when creating new type instances\n */\n private static _copyTypeProperties(source: Type<any>, target: Type<any>): void {\n const properties = ['_check', '_default', '_meta', '_object', '_type', '_enumValues']\n for (const prop of properties) {\n if ((source as any)[prop] !== undefined) {\n (target as any)[prop] = (source as any)[prop]\n }\n }\n }\n\n /**\n * Marks the type as optional, meaning it can be undefined\n * This is useful for properties that are not required.\n */\n optional(): Type<T | undefined> {\n return this._cloneWithProps<T | undefined>({ _optional: true })\n }\n\n /**\n * Sets a default value for the type, which will be used if the value is not provided\n * The default value can be a function that receives the schema as argument, or a static value.\n */\n default(value: T | ((schema?: this) => T)): Type<T> {\n return this._cloneWithProps<T>({ _default: value })\n }\n\n /**\n * Props / Metadata for the type, like description or other properties\n */\n meta(meta: TypeMeta): Type<T> {\n return this._cloneWithProps<T>({ _meta: meta })\n }\n\n /**\n * Sets the `desc` property for the type, which is a human-readable description\n */\n describe(msg: string): Type<T> {\n const meta = this._meta || {}\n meta.desc = msg\n return this._cloneWithProps<T>({ _meta: meta })\n }\n\n /**\n * Extends the type with an object, merging the properties\n */\n extend<O>(obj: O): Type<T & TypeObject<O>> {\n if (!this._object) {\n throw new Error('extend() can only be used on object schemas')\n }\n const newObj = { ...this._object, ...obj }\n return object(newObj) as any\n }\n\n /**\n * Picks certain keys from an object schema\n */\n pick<K extends keyof T>(keys: Record<K, true>): Type<Pick<T, K>> {\n if (!this._object) {\n throw new Error('pick() can only be used on object schemas')\n }\n const pickedObj: any = {}\n for (const key of Object.keys(keys)) {\n if (key in this._object) {\n pickedObj[key] = (this._object as any)[key]\n }\n }\n return object(pickedObj) as any\n }\n\n /**\n * Omits certain keys from an object schema\n */\n omit<K extends keyof T>(keys: Record<K, true>): Type<Omit<T, K>> {\n if (!this._object) {\n throw new Error('omit() can only be used on object schemas')\n }\n const omittedObj: any = { ...this._object }\n for (const key of Object.keys(keys)) {\n delete omittedObj[key]\n }\n return object(omittedObj) as any\n }\n\n /**\n * Helper method to modify object properties with a transformation function\n */\n private _transformObjectProperties(\n transform: (key: string, type: Type<any>, shouldTransform: boolean) => Type<any>,\n keys?: Record<string, true>,\n ): any {\n if (!this._object) {\n throw new Error('This operation can only be used on object schemas')\n }\n\n const transformedObj: any = {}\n const originalObj = this._object as any\n\n for (const [key, typeInstance] of Object.entries(originalObj)) {\n const shouldTransform = !keys || key in keys\n transformedObj[key] = transform(key, typeInstance as Type<any>, shouldTransform)\n }\n\n return object(transformedObj)\n }\n\n /**\n * Makes some or all properties of an object schema optional\n */\n partial(): Type<Partial<T>>\n partial<K extends keyof T>(keys: Record<K, true>): Type<Partial<Pick<T, K>> & Omit<T, K>>\n partial<K extends keyof T>(keys?: Record<K, true>): Type<Partial<T> | (Partial<Pick<T, K>> & Omit<T, K>)> {\n if (!this._object) {\n throw new Error('partial() can only be used on object schemas')\n }\n return this._transformObjectProperties((key, type, shouldTransform) => {\n if (!shouldTransform)\n return type\n return Type._cloneTypeWithOptional(type, true)\n }, keys)\n }\n\n /**\n * Makes some or all properties of an object schema required\n */\n required(): Type<Required<T>>\n required<K extends keyof T>(keys: Record<K, true>): Type<Required<Pick<T, K>> & Omit<T, K>>\n required<K extends keyof T>(keys?: Record<K, true>): Type<Required<T> | (Required<Pick<T, K>> & Omit<T, K>)> {\n if (!this._object) {\n throw new Error('required() can only be used on object schemas')\n }\n return this._transformObjectProperties((key, type, shouldTransform) => {\n if (!shouldTransform)\n return type\n return Type._cloneTypeWithOptional(type, false)\n }, keys)\n }\n\n /**\n * Helper method to clone a type with optional flag\n */\n private static _cloneTypeWithOptional(originalType: Type<any>, optional: boolean): Type<any> {\n const newType = new Type(originalType.type)\n Type._copyTypeProperties(originalType, newType)\n newType._optional = optional\n return newType\n }\n}\n\n/**\n * Type inference utility for extracting the TypeScript type from a schema Type\n */\nexport type Infer<T> = T extends Type<infer TT> ? TT : never\n\n// =============================================================================\n// Primitive Types\n// =============================================================================\n\n/**\n * Creates a string type validator\n */\nexport function string(): Type<string> {\n return new Type('string', {\n _check: isString,\n })\n}\n\n/**\n * Creates a number type validator\n */\nexport function number(): Type<number> {\n return new Type('number', {\n _check: isNumber,\n })\n}\n\n/**\n * Creates an integer type validator\n */\nexport function int(): Type<number> {\n return new Type('int', {\n _check: isInteger,\n })\n}\n\n/**\n * Creates a boolean type validator\n */\nexport function boolean(): Type<boolean> {\n return new Type('boolean', {\n _check: isBoolean,\n })\n}\n\n/**\n * Creates a none type validator (undefined | null)\n * Like undefined | null in TS and nil in Swift\n */\nexport function none(): Type<undefined> {\n return new Type('none', {\n _check: (v: any) => v == null,\n _optional: true,\n })\n}\n\n/**\n * Creates an any type validator that accepts any non-null value\n */\nexport function any<T = any>(): Type<T> {\n return new Type('any', {\n _check: (v: any) => v != null,\n })\n}\n\n// Aliases for number types\nexport const float = number\nexport const double = number\nexport const real = number\n\n// =============================================================================\n// Object Types\n// =============================================================================\n\n/**\n * Utility type to make object properties optional if their value type includes undefined.\n * @category Schema\n */\nexport type TypeObjectFixOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]?: T[K] & {}\n} & {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K] & {}\n}\n\n/**\n * Utility type for pretty-printing object types\n */\ntype TypeObjectPretty<V> = Extract<{ [K in keyof V]: V[K] }, unknown>\n\n/**\n * Main object type utility\n */\ntype TypeObject<T> = TypeObjectPretty<TypeObjectFixOptional<{\n [K in keyof T]: Infer<T[K]>\n}>>\n\n/**\n * Creates an object type validator with specified properties\n */\nexport function object<T>(tobj: T): Type<TypeObject<T>> {\n return new Type('object', {\n _check: isObject,\n _object: tobj,\n })\n}\n\n/**\n * Creates a record type validator (object with string keys and uniform value type)\n */\nexport function record<T extends Type>(valueType: T): Type<Record<string, Infer<T>>> {\n return new Type('record', {\n _check: isObject,\n _type: valueType,\n })\n}\n\n// =============================================================================\n// Union Types\n// =============================================================================\n\n/**\n * Utility type for union of types.\n * @category Schema\n */\nexport type TypeUnion<T extends Type<any>[]> = {\n [K in keyof T]: T[K] extends Type<infer U> ? U : never\n}[number]\n\n/**\n * Creates a union type validator (like `string | number | boolean`)\n */\nexport function union<T extends Type<any>[]>(options: T): Type<TypeUnion<T>> {\n return new Type('union', {\n _check: (v: any) => options.some(option => option._check?.(v) ?? false),\n _union: options,\n })\n}\n\n// =============================================================================\n// Literal Types\n// =============================================================================\n\n/**\n * Utility type for literal types.\n * @category Schema\n */\nexport type TypeLiterals = string | number | bigint | boolean\n\n/**\n * Creates a literal value validator\n */\nexport function literal<T extends TypeLiterals>(value: T): Type<T> {\n return new Type('literal', {\n _check: (v: any) => v === value,\n _default: value,\n })\n}\n\n/**\n * Creates a string literal union validator (like `\"a\" | \"b\" | \"c\"`)\n */\nexport function stringLiterals<const T extends readonly string[]>(values: T): Type<T[number]> {\n return new Type('string', {\n _check: (v: any) => typeof v === 'string' && (values as readonly string[]).includes(v),\n _enumValues: values,\n })\n}\n\n// =============================================================================\n// Collection Types\n// =============================================================================\n\n/**\n * Utility type for tuple types.\n * @category Schema\n */\nexport type TypeTuple<T extends readonly Type[]> = {\n -readonly [K in keyof T]: T[K] extends Type<infer U> ? U : never\n}\n\n/**\n * Output type for TypeArray.\n * @category Schema\n */\nexport type TypeArrayOutput<Head extends Type[], Rest extends Type | undefined> = [\n ...TypeTuple<Head>,\n ...(Rest extends Type ? Infer<Rest>[] : []),\n]\n\n/**\n * Utility type for array types.\n * @category Schema\n */\nexport type TypeArray<Head extends Type[] = Type[], Rest extends Type | undefined = Type | undefined> = Type<TypeArrayOutput<Head, Rest>>\n\n/**\n * Creates a tuple type validator with fixed length and types e.g. [string, number, boolean]\n */\nexport function tuple<const T extends readonly Type[]>(items: T): Type<TypeTuple<T>> {\n return new Type('tuple', {\n _check: (v: any) => Array.isArray(v) && v.length === items.length && items.every((item, i) => (item as Type)._check?.(v[i]) ?? false),\n _type: items,\n })\n}\n\n/**\n * Creates an array type validator for a specific item type\n */\nexport function array<T>(itemType: Type<T>): Type<T[]> {\n return new Type('array', {\n _check: isArray,\n _type: itemType,\n })\n}\n\n// =============================================================================\n// Function Types\n// =============================================================================\n\n/**\n * Creates a regular function type validator\n */\nexport function func<\n TypeFuncArgs extends [Type<unknown>, ...Type<any>[]] | [],\n TypeFuncRet = Type,\n T = (...args: TypeTuple<TypeFuncArgs>) => Infer<TypeFuncRet>,\n>(args: TypeFuncArgs, ret: TypeFuncRet): Type<T> {\n return new Type('function', {\n _check: isFunction,\n _args: args,\n _ret: ret,\n })\n}\n\n/**\n * Creates an RPC function type validator that takes one argument and returns a promise\n */\nexport function rpc<\n TypeRpcInfo extends Type<unknown> | undefined = undefined,\n TypeRpcRet extends Type<unknown> = Type<void>,\n T = TypeRpcInfo extends undefined\n ? () => Infer<TypeRpcRet>\n : (info: Infer<TypeRpcInfo>) => Infer<TypeRpcRet> | Promise<Infer<TypeRpcRet>>,\n>(info?: TypeRpcInfo, ret?: TypeRpcRet): Type<T> {\n return new Type('rpc', {\n _check: isFunction,\n _info: info,\n _ret: ret ?? none(),\n })\n}\n"],"mappings":";;;;;;;AAgBA,IAAa,OAAb,MAAa,KAAkB;CAC7B,AAAS;CAET;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAIA,YAAY,MAAc,UAA4B,EAAE,EAAE;AACxD,OAAK,OAAO;AACZ,S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B,CAAC"}
@@ -1,2 +1,110 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../data/is.cjs`),t=require(`./schema.cjs`);function n(t){let r={type:t.type};if(t._optional!==void 0&&(r.optional=t._optional),t._meta!==void 0&&(r.meta=t._meta),t._default!==void 0&&!e.isFunction(t._default)&&(r.default=t._default),t._object!==void 0){r.object={};for(let[e,i]of Object.entries(t._object))r.object[e]=n(i)}return t._type!==void 0&&(e.isArray(t._type)?r.tupleTypes=t._type.map(e=>n(e)):r.itemType=n(t._type)),t._union!==void 0&&(r.union=t._union.map(e=>n(e))),t._enumValues!==void 0&&(r.enumValues=t._enumValues),t._args!==void 0&&(r.args=t._args.map(e=>n(e))),t._ret!==void 0&&(r.ret=n(t._ret)),t._info!==void 0&&(r.info=n(t._info)),t.type===`literal`&&t._default!==void 0&&(r.literalValue=t._default),r}function r(e){let n;switch(e.type){case`string`:n=e.enumValues?t.stringLiterals(e.enumValues):t.string();break;case`number`:n=t.number();break;case`int`:n=t.int();break;case`boolean`:n=t.boolean();break;case`none`:n=t.none();break;case`any`:n=t.any();break;case`object`:if(e.object){let i={};for(let[t,n]of Object.entries(e.object))i[t]=r(n);n=t.object(i)}else n=t.object({});break;case`record`:n=e.itemType?t.record(r(e.itemType)):t.record(t.any());break;case`array`:n=e.itemType?t.array(r(e.itemType)):t.array(t.any());break;case`tuple`:n=e.tupleTypes?t.tuple(e.tupleTypes.map(e=>r(e))):t.tuple([]);break;case`union`:n=e.union?t.union(e.union.map(e=>r(e))):t.union([]);break;case`literal`:n=e.literalValue===void 0?t.any():t.literal(e.literalValue);break;case`function`:n=e.args&&e.ret?t.func(e.args.map(e=>r(e)),r(e.ret)):t.func([],t.any());break;case`rpc`:n=e.info&&e.ret?t.rpc(r(e.info),r(e.ret)):e.ret?t.rpc(void 0,r(e.ret)):t.rpc();break;default:n=t.any();break}return e.optional&&(n=n.optional()),e.default!==void 0&&(n=n.default(e.default)),e.meta&&(n=n.meta(e.meta)),n}exports.deserializeSchema=r,exports.serializeSchema=n;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_common_data_is = require('../data/is.cjs');
3
+ const require_common_schema_schema = require('./schema.cjs');
4
+
5
+ //#region src/common/schema/serialize.ts
6
+ /**
7
+ * Serializes a schema Type to a plain JSON object.
8
+ * Functions in _check and _default will not be serialized.
9
+ *
10
+ * @param schema - The schema Type to serialize
11
+ * @returns A plain JSON object representing the schema
12
+ */
13
+ function serializeSchema(schema) {
14
+ const result = { type: schema.type };
15
+ if (schema._optional !== void 0) result.optional = schema._optional;
16
+ if (schema._meta !== void 0) result.meta = schema._meta;
17
+ if (schema._default !== void 0 && !require_common_data_is.isFunction(schema._default)) result.default = schema._default;
18
+ if (schema._object !== void 0) {
19
+ result.object = {};
20
+ for (const [key, value] of Object.entries(schema._object)) result.object[key] = serializeSchema(value);
21
+ }
22
+ if (schema._type !== void 0) if (require_common_data_is.isArray(schema._type)) result.tupleTypes = schema._type.map((t) => serializeSchema(t));
23
+ else result.itemType = serializeSchema(schema._type);
24
+ if (schema._union !== void 0) result.union = schema._union.map((t) => serializeSchema(t));
25
+ if (schema._enumValues !== void 0) result.enumValues = schema._enumValues;
26
+ if (schema._args !== void 0) result.args = schema._args.map((t) => serializeSchema(t));
27
+ if (schema._ret !== void 0) result.ret = serializeSchema(schema._ret);
28
+ if (schema._info !== void 0) result.info = serializeSchema(schema._info);
29
+ if (schema.type === "literal" && schema._default !== void 0) result.literalValue = schema._default;
30
+ return result;
31
+ }
32
+ /**
33
+ * Deserializes a plain JSON object back to a schema Type.
34
+ * Note: Custom _check functions cannot be restored and will use default validators.
35
+ *
36
+ * @param serialized - The serialized schema object
37
+ * @returns A reconstructed Type instance
38
+ */
39
+ function deserializeSchema(serialized) {
40
+ let schema;
41
+ switch (serialized.type) {
42
+ case "string":
43
+ if (serialized.enumValues) schema = require_common_schema_schema.stringLiterals(serialized.enumValues);
44
+ else schema = require_common_schema_schema.string();
45
+ break;
46
+ case "number":
47
+ schema = require_common_schema_schema.number();
48
+ break;
49
+ case "int":
50
+ schema = require_common_schema_schema.int();
51
+ break;
52
+ case "boolean":
53
+ schema = require_common_schema_schema.boolean();
54
+ break;
55
+ case "none":
56
+ schema = require_common_schema_schema.none();
57
+ break;
58
+ case "any":
59
+ schema = require_common_schema_schema.any();
60
+ break;
61
+ case "object":
62
+ if (serialized.object) {
63
+ const obj = {};
64
+ for (const [key, value] of Object.entries(serialized.object)) obj[key] = deserializeSchema(value);
65
+ schema = require_common_schema_schema.object(obj);
66
+ } else schema = require_common_schema_schema.object({});
67
+ break;
68
+ case "record":
69
+ if (serialized.itemType) schema = require_common_schema_schema.record(deserializeSchema(serialized.itemType));
70
+ else schema = require_common_schema_schema.record(require_common_schema_schema.any());
71
+ break;
72
+ case "array":
73
+ if (serialized.itemType) schema = require_common_schema_schema.array(deserializeSchema(serialized.itemType));
74
+ else schema = require_common_schema_schema.array(require_common_schema_schema.any());
75
+ break;
76
+ case "tuple":
77
+ if (serialized.tupleTypes) schema = require_common_schema_schema.tuple(serialized.tupleTypes.map((t) => deserializeSchema(t)));
78
+ else schema = require_common_schema_schema.tuple([]);
79
+ break;
80
+ case "union":
81
+ if (serialized.union) schema = require_common_schema_schema.union(serialized.union.map((t) => deserializeSchema(t)));
82
+ else schema = require_common_schema_schema.union([]);
83
+ break;
84
+ case "literal":
85
+ if (serialized.literalValue !== void 0) schema = require_common_schema_schema.literal(serialized.literalValue);
86
+ else schema = require_common_schema_schema.any();
87
+ break;
88
+ case "function":
89
+ if (serialized.args && serialized.ret) schema = require_common_schema_schema.func(serialized.args.map((t) => deserializeSchema(t)), deserializeSchema(serialized.ret));
90
+ else schema = require_common_schema_schema.func([], require_common_schema_schema.any());
91
+ break;
92
+ case "rpc":
93
+ if (serialized.info && serialized.ret) schema = require_common_schema_schema.rpc(deserializeSchema(serialized.info), deserializeSchema(serialized.ret));
94
+ else if (serialized.ret) schema = require_common_schema_schema.rpc(void 0, deserializeSchema(serialized.ret));
95
+ else schema = require_common_schema_schema.rpc();
96
+ break;
97
+ default:
98
+ schema = require_common_schema_schema.any();
99
+ break;
100
+ }
101
+ if (serialized.optional) schema = schema.optional();
102
+ if (serialized.default !== void 0) schema = schema.default(serialized.default);
103
+ if (serialized.meta) schema = schema.meta(serialized.meta);
104
+ return schema;
105
+ }
106
+
107
+ //#endregion
108
+ exports.deserializeSchema = deserializeSchema;
109
+ exports.serializeSchema = serializeSchema;
2
110
  //# sourceMappingURL=serialize.cjs.map