semola 0.5.3 → 0.6.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 (367) hide show
  1. package/README.md +18 -45
  2. package/dist/chunk-CKQMccvm.cjs +28 -0
  3. package/dist/lib/api/index.cjs +536 -4
  4. package/dist/lib/api/index.d.cts +270 -4
  5. package/dist/lib/api/index.d.mts +270 -4
  6. package/dist/lib/api/index.mjs +534 -2
  7. package/dist/lib/cache/index.cjs +47 -22
  8. package/dist/lib/cache/index.d.cts +14 -23
  9. package/dist/lib/cache/index.d.mts +14 -23
  10. package/dist/lib/cache/index.mjs +48 -25
  11. package/dist/lib/cron/index.cjs +734 -12
  12. package/dist/lib/cron/index.d.cts +145 -3
  13. package/dist/lib/cron/index.d.mts +145 -3
  14. package/dist/lib/cron/index.mjs +725 -3
  15. package/dist/lib/errors/index.d.cts +4 -4
  16. package/dist/lib/errors/index.d.mts +4 -4
  17. package/dist/lib/errors/index.mjs +0 -2
  18. package/dist/lib/i18n/index.d.cts +12 -4
  19. package/dist/lib/i18n/index.d.mts +12 -4
  20. package/dist/lib/i18n/index.mjs +0 -2
  21. package/dist/lib/logging/index.cjs +387 -17
  22. package/dist/lib/logging/index.d.cts +107 -6
  23. package/dist/lib/logging/index.d.mts +107 -6
  24. package/dist/lib/logging/index.mjs +373 -4
  25. package/dist/lib/orm/index.cjs +1641 -19
  26. package/dist/lib/orm/index.d.cts +402 -7
  27. package/dist/lib/orm/index.d.mts +402 -7
  28. package/dist/lib/orm/index.mjs +1630 -6
  29. package/dist/lib/policy/index.cjs +206 -20
  30. package/dist/lib/policy/index.d.cts +61 -5
  31. package/dist/lib/policy/index.d.mts +61 -5
  32. package/dist/lib/policy/index.mjs +187 -3
  33. package/dist/lib/prompts/index.cjs +374 -14
  34. package/dist/lib/prompts/index.d.cts +73 -29
  35. package/dist/lib/prompts/index.d.mts +73 -29
  36. package/dist/lib/prompts/index.mjs +361 -4
  37. package/dist/lib/pubsub/index.cjs +43 -19
  38. package/dist/lib/pubsub/index.d.cts +12 -22
  39. package/dist/lib/pubsub/index.d.mts +12 -22
  40. package/dist/lib/pubsub/index.mjs +44 -22
  41. package/dist/lib/queue/index.cjs +40 -10
  42. package/dist/lib/queue/index.d.cts +57 -8
  43. package/dist/lib/queue/index.d.mts +57 -8
  44. package/dist/lib/queue/index.mjs +39 -13
  45. package/dist/lib/workflow/index.cjs +285 -282
  46. package/dist/lib/workflow/index.d.cts +147 -4
  47. package/dist/lib/workflow/index.d.mts +147 -4
  48. package/dist/lib/workflow/index.mjs +278 -286
  49. package/package.json +11 -1
  50. package/dist/api/core/index.cjs +0 -206
  51. package/dist/api/core/index.d.cts +0 -21
  52. package/dist/api/core/index.d.cts.map +0 -1
  53. package/dist/api/core/index.d.mts +0 -21
  54. package/dist/api/core/index.d.mts.map +0 -1
  55. package/dist/api/core/index.mjs +0 -208
  56. package/dist/api/core/index.mjs.map +0 -1
  57. package/dist/api/core/types.d.cts +0 -107
  58. package/dist/api/core/types.d.cts.map +0 -1
  59. package/dist/api/core/types.d.mts +0 -107
  60. package/dist/api/core/types.d.mts.map +0 -1
  61. package/dist/api/middleware/index.cjs +0 -8
  62. package/dist/api/middleware/index.d.cts +0 -11
  63. package/dist/api/middleware/index.d.cts.map +0 -1
  64. package/dist/api/middleware/index.d.mts +0 -11
  65. package/dist/api/middleware/index.d.mts.map +0 -1
  66. package/dist/api/middleware/index.mjs +0 -10
  67. package/dist/api/middleware/index.mjs.map +0 -1
  68. package/dist/api/middleware/types.d.cts +0 -16
  69. package/dist/api/middleware/types.d.cts.map +0 -1
  70. package/dist/api/middleware/types.d.mts +0 -16
  71. package/dist/api/middleware/types.d.mts.map +0 -1
  72. package/dist/api/openapi/index.cjs +0 -254
  73. package/dist/api/openapi/index.mjs +0 -256
  74. package/dist/api/openapi/index.mjs.map +0 -1
  75. package/dist/api/openapi/types.d.cts +0 -60
  76. package/dist/api/openapi/types.d.cts.map +0 -1
  77. package/dist/api/openapi/types.d.mts +0 -60
  78. package/dist/api/openapi/types.d.mts.map +0 -1
  79. package/dist/api/validation/index.cjs +0 -64
  80. package/dist/api/validation/index.mjs +0 -61
  81. package/dist/api/validation/index.mjs.map +0 -1
  82. package/dist/cache/types.d.cts +0 -17
  83. package/dist/cache/types.d.cts.map +0 -1
  84. package/dist/cache/types.d.mts +0 -17
  85. package/dist/cache/types.d.mts.map +0 -1
  86. package/dist/cron/builder/index.cjs +0 -166
  87. package/dist/cron/builder/index.d.cts +0 -28
  88. package/dist/cron/builder/index.d.cts.map +0 -1
  89. package/dist/cron/builder/index.d.mts +0 -28
  90. package/dist/cron/builder/index.d.mts.map +0 -1
  91. package/dist/cron/builder/index.mjs +0 -163
  92. package/dist/cron/builder/index.mjs.map +0 -1
  93. package/dist/cron/builder/types.cjs +0 -27
  94. package/dist/cron/builder/types.d.cts +0 -79
  95. package/dist/cron/builder/types.d.cts.map +0 -1
  96. package/dist/cron/builder/types.d.mts +0 -79
  97. package/dist/cron/builder/types.d.mts.map +0 -1
  98. package/dist/cron/builder/types.mjs +0 -28
  99. package/dist/cron/builder/types.mjs.map +0 -1
  100. package/dist/cron/core/index.cjs +0 -308
  101. package/dist/cron/core/index.d.cts +0 -39
  102. package/dist/cron/core/index.d.cts.map +0 -1
  103. package/dist/cron/core/index.d.mts +0 -39
  104. package/dist/cron/core/index.d.mts.map +0 -1
  105. package/dist/cron/core/index.mjs +0 -310
  106. package/dist/cron/core/index.mjs.map +0 -1
  107. package/dist/cron/core/scanner.cjs +0 -237
  108. package/dist/cron/core/scanner.mjs +0 -238
  109. package/dist/cron/core/scanner.mjs.map +0 -1
  110. package/dist/cron/core/types.d.cts +0 -11
  111. package/dist/cron/core/types.d.cts.map +0 -1
  112. package/dist/cron/core/types.d.mts +0 -11
  113. package/dist/cron/core/types.d.mts.map +0 -1
  114. package/dist/errors/types.d.cts +0 -5
  115. package/dist/errors/types.d.cts.map +0 -1
  116. package/dist/errors/types.d.mts +0 -5
  117. package/dist/errors/types.d.mts.map +0 -1
  118. package/dist/i18n/types.d.cts +0 -13
  119. package/dist/i18n/types.d.cts.map +0 -1
  120. package/dist/i18n/types.d.mts +0 -13
  121. package/dist/i18n/types.d.mts.map +0 -1
  122. package/dist/lib/cache/index.d.cts.map +0 -1
  123. package/dist/lib/cache/index.d.mts.map +0 -1
  124. package/dist/lib/cache/index.mjs.map +0 -1
  125. package/dist/lib/errors/index.d.cts.map +0 -1
  126. package/dist/lib/errors/index.d.mts.map +0 -1
  127. package/dist/lib/errors/index.mjs.map +0 -1
  128. package/dist/lib/i18n/index.d.cts.map +0 -1
  129. package/dist/lib/i18n/index.d.mts.map +0 -1
  130. package/dist/lib/i18n/index.mjs.map +0 -1
  131. package/dist/lib/policy/index.d.cts.map +0 -1
  132. package/dist/lib/policy/index.d.mts.map +0 -1
  133. package/dist/lib/policy/index.mjs.map +0 -1
  134. package/dist/lib/prompts/index.d.cts.map +0 -1
  135. package/dist/lib/prompts/index.d.mts.map +0 -1
  136. package/dist/lib/prompts/index.mjs.map +0 -1
  137. package/dist/lib/pubsub/index.d.cts.map +0 -1
  138. package/dist/lib/pubsub/index.d.mts.map +0 -1
  139. package/dist/lib/pubsub/index.mjs.map +0 -1
  140. package/dist/lib/queue/index.d.cts.map +0 -1
  141. package/dist/lib/queue/index.d.mts.map +0 -1
  142. package/dist/lib/queue/index.mjs.map +0 -1
  143. package/dist/lib/workflow/index.d.cts.map +0 -1
  144. package/dist/lib/workflow/index.d.mts.map +0 -1
  145. package/dist/lib/workflow/index.mjs.map +0 -1
  146. package/dist/logging/core/index.cjs +0 -99
  147. package/dist/logging/core/index.d.cts +0 -26
  148. package/dist/logging/core/index.d.cts.map +0 -1
  149. package/dist/logging/core/index.d.mts +0 -26
  150. package/dist/logging/core/index.d.mts.map +0 -1
  151. package/dist/logging/core/index.mjs +0 -99
  152. package/dist/logging/core/index.mjs.map +0 -1
  153. package/dist/logging/core/types.cjs +0 -10
  154. package/dist/logging/core/types.d.cts +0 -22
  155. package/dist/logging/core/types.d.cts.map +0 -1
  156. package/dist/logging/core/types.d.mts +0 -22
  157. package/dist/logging/core/types.d.mts.map +0 -1
  158. package/dist/logging/core/types.mjs +0 -12
  159. package/dist/logging/core/types.mjs.map +0 -1
  160. package/dist/logging/formatter/index.cjs +0 -119
  161. package/dist/logging/formatter/index.d.cts +0 -27
  162. package/dist/logging/formatter/index.d.cts.map +0 -1
  163. package/dist/logging/formatter/index.d.mts +0 -27
  164. package/dist/logging/formatter/index.d.mts.map +0 -1
  165. package/dist/logging/formatter/index.mjs +0 -115
  166. package/dist/logging/formatter/index.mjs.map +0 -1
  167. package/dist/logging/formatter/types.d.cts +0 -5
  168. package/dist/logging/formatter/types.d.cts.map +0 -1
  169. package/dist/logging/formatter/types.d.mts +0 -5
  170. package/dist/logging/formatter/types.d.mts.map +0 -1
  171. package/dist/logging/provider/index.cjs +0 -165
  172. package/dist/logging/provider/index.d.cts +0 -28
  173. package/dist/logging/provider/index.d.cts.map +0 -1
  174. package/dist/logging/provider/index.d.mts +0 -28
  175. package/dist/logging/provider/index.d.mts.map +0 -1
  176. package/dist/logging/provider/index.mjs +0 -165
  177. package/dist/logging/provider/index.mjs.map +0 -1
  178. package/dist/logging/provider/types.d.cts +0 -23
  179. package/dist/logging/provider/types.d.cts.map +0 -1
  180. package/dist/logging/provider/types.d.mts +0 -23
  181. package/dist/logging/provider/types.d.mts.map +0 -1
  182. package/dist/node_modules/@standard-schema/spec/dist/index.d.cts +0 -80
  183. package/dist/node_modules/@standard-schema/spec/dist/index.d.cts.map +0 -1
  184. package/dist/node_modules/@standard-schema/spec/dist/index.d.mts +0 -80
  185. package/dist/node_modules/@standard-schema/spec/dist/index.d.mts.map +0 -1
  186. package/dist/orm/column.cjs +0 -137
  187. package/dist/orm/column.d.cts +0 -121
  188. package/dist/orm/column.d.cts.map +0 -1
  189. package/dist/orm/column.d.mts +0 -121
  190. package/dist/orm/column.d.mts.map +0 -1
  191. package/dist/orm/column.mjs +0 -132
  192. package/dist/orm/column.mjs.map +0 -1
  193. package/dist/orm/dialect/index.cjs +0 -14
  194. package/dist/orm/dialect/index.mjs +0 -16
  195. package/dist/orm/dialect/index.mjs.map +0 -1
  196. package/dist/orm/dialect/mysql.cjs +0 -31
  197. package/dist/orm/dialect/mysql.mjs +0 -33
  198. package/dist/orm/dialect/mysql.mjs.map +0 -1
  199. package/dist/orm/dialect/postgres.cjs +0 -23
  200. package/dist/orm/dialect/postgres.mjs +0 -25
  201. package/dist/orm/dialect/postgres.mjs.map +0 -1
  202. package/dist/orm/dialect/sqlite.cjs +0 -31
  203. package/dist/orm/dialect/sqlite.mjs +0 -33
  204. package/dist/orm/dialect/sqlite.mjs.map +0 -1
  205. package/dist/orm/dialect/utils.cjs +0 -8
  206. package/dist/orm/dialect/utils.mjs +0 -10
  207. package/dist/orm/dialect/utils.mjs.map +0 -1
  208. package/dist/orm/internal/table-columns.cjs +0 -31
  209. package/dist/orm/internal/table-columns.mjs +0 -32
  210. package/dist/orm/internal/table-columns.mjs.map +0 -1
  211. package/dist/orm/internal/table-lookup.cjs +0 -35
  212. package/dist/orm/internal/table-lookup.mjs +0 -35
  213. package/dist/orm/internal/table-lookup.mjs.map +0 -1
  214. package/dist/orm/internal/table-relations.cjs +0 -28
  215. package/dist/orm/internal/table-relations.mjs +0 -29
  216. package/dist/orm/internal/table-relations.mjs.map +0 -1
  217. package/dist/orm/migration/config.cjs +0 -7
  218. package/dist/orm/migration/config.d.cts +0 -7
  219. package/dist/orm/migration/config.d.cts.map +0 -1
  220. package/dist/orm/migration/config.d.mts +0 -7
  221. package/dist/orm/migration/config.d.mts.map +0 -1
  222. package/dist/orm/migration/config.mjs +0 -8
  223. package/dist/orm/migration/config.mjs.map +0 -1
  224. package/dist/orm/migration/types.d.cts +0 -20
  225. package/dist/orm/migration/types.d.cts.map +0 -1
  226. package/dist/orm/migration/types.d.mts +0 -20
  227. package/dist/orm/migration/types.d.mts.map +0 -1
  228. package/dist/orm/orm.cjs +0 -41
  229. package/dist/orm/orm.d.cts +0 -18
  230. package/dist/orm/orm.d.cts.map +0 -1
  231. package/dist/orm/orm.d.mts +0 -18
  232. package/dist/orm/orm.d.mts.map +0 -1
  233. package/dist/orm/orm.mjs +0 -43
  234. package/dist/orm/orm.mjs.map +0 -1
  235. package/dist/orm/relation.cjs +0 -18
  236. package/dist/orm/relation.d.cts +0 -8
  237. package/dist/orm/relation.d.cts.map +0 -1
  238. package/dist/orm/relation.d.mts +0 -8
  239. package/dist/orm/relation.d.mts.map +0 -1
  240. package/dist/orm/relation.mjs +0 -19
  241. package/dist/orm/relation.mjs.map +0 -1
  242. package/dist/orm/runtime/builders/mutations.cjs +0 -29
  243. package/dist/orm/runtime/builders/mutations.mjs +0 -28
  244. package/dist/orm/runtime/builders/mutations.mjs.map +0 -1
  245. package/dist/orm/runtime/builders/select.cjs +0 -18
  246. package/dist/orm/runtime/builders/select.mjs +0 -19
  247. package/dist/orm/runtime/builders/select.mjs.map +0 -1
  248. package/dist/orm/runtime/client.cjs +0 -90
  249. package/dist/orm/runtime/client.mjs +0 -92
  250. package/dist/orm/runtime/client.mjs.map +0 -1
  251. package/dist/orm/runtime/context.cjs +0 -49
  252. package/dist/orm/runtime/context.mjs +0 -51
  253. package/dist/orm/runtime/context.mjs.map +0 -1
  254. package/dist/orm/runtime/dialect/index.cjs +0 -11
  255. package/dist/orm/runtime/dialect/index.mjs +0 -13
  256. package/dist/orm/runtime/dialect/index.mjs.map +0 -1
  257. package/dist/orm/runtime/dialect/mysql.cjs +0 -95
  258. package/dist/orm/runtime/dialect/mysql.mjs +0 -97
  259. package/dist/orm/runtime/dialect/mysql.mjs.map +0 -1
  260. package/dist/orm/runtime/dialect/postgres.cjs +0 -51
  261. package/dist/orm/runtime/dialect/postgres.mjs +0 -53
  262. package/dist/orm/runtime/dialect/postgres.mjs.map +0 -1
  263. package/dist/orm/runtime/dialect/sqlite.cjs +0 -4
  264. package/dist/orm/runtime/dialect/sqlite.mjs +0 -7
  265. package/dist/orm/runtime/dialect/sqlite.mjs.map +0 -1
  266. package/dist/orm/runtime/errors.cjs +0 -19
  267. package/dist/orm/runtime/errors.mjs +0 -21
  268. package/dist/orm/runtime/errors.mjs.map +0 -1
  269. package/dist/orm/runtime/hydrate/many.cjs +0 -46
  270. package/dist/orm/runtime/hydrate/many.mjs +0 -48
  271. package/dist/orm/runtime/hydrate/many.mjs.map +0 -1
  272. package/dist/orm/runtime/hydrate/one.cjs +0 -38
  273. package/dist/orm/runtime/hydrate/one.mjs +0 -40
  274. package/dist/orm/runtime/hydrate/one.mjs.map +0 -1
  275. package/dist/orm/runtime/hydrate.cjs +0 -49
  276. package/dist/orm/runtime/hydrate.mjs +0 -51
  277. package/dist/orm/runtime/hydrate.mjs.map +0 -1
  278. package/dist/orm/runtime/rows.cjs +0 -30
  279. package/dist/orm/runtime/rows.mjs +0 -31
  280. package/dist/orm/runtime/rows.mjs.map +0 -1
  281. package/dist/orm/runtime/utils.cjs +0 -27
  282. package/dist/orm/runtime/utils.mjs +0 -27
  283. package/dist/orm/runtime/utils.mjs.map +0 -1
  284. package/dist/orm/sql/parse-array.cjs +0 -64
  285. package/dist/orm/sql/parse-array.mjs +0 -66
  286. package/dist/orm/sql/parse-array.mjs.map +0 -1
  287. package/dist/orm/sql/plan/select.cjs +0 -36
  288. package/dist/orm/sql/plan/select.mjs +0 -38
  289. package/dist/orm/sql/plan/select.mjs.map +0 -1
  290. package/dist/orm/sql/plan/where/operators.cjs +0 -95
  291. package/dist/orm/sql/plan/where/operators.mjs +0 -97
  292. package/dist/orm/sql/plan/where/operators.mjs.map +0 -1
  293. package/dist/orm/sql/plan/where.cjs +0 -59
  294. package/dist/orm/sql/plan/where.mjs +0 -61
  295. package/dist/orm/sql/plan/where.mjs.map +0 -1
  296. package/dist/orm/sql/serialize/clauses.cjs +0 -36
  297. package/dist/orm/sql/serialize/clauses.mjs +0 -37
  298. package/dist/orm/sql/serialize/clauses.mjs.map +0 -1
  299. package/dist/orm/sql/serialize/joins.cjs +0 -31
  300. package/dist/orm/sql/serialize/joins.mjs +0 -33
  301. package/dist/orm/sql/serialize/joins.mjs.map +0 -1
  302. package/dist/orm/sql/serialize/values.cjs +0 -30
  303. package/dist/orm/sql/serialize/values.mjs +0 -32
  304. package/dist/orm/sql/serialize/values.mjs.map +0 -1
  305. package/dist/orm/sql/serialize/where/predicate.cjs +0 -73
  306. package/dist/orm/sql/serialize/where/predicate.mjs +0 -75
  307. package/dist/orm/sql/serialize/where/predicate.mjs.map +0 -1
  308. package/dist/orm/sql/serialize/where/tree.cjs +0 -26
  309. package/dist/orm/sql/serialize/where/tree.mjs +0 -28
  310. package/dist/orm/sql/serialize/where/tree.mjs.map +0 -1
  311. package/dist/orm/sql/serialize/where.cjs +0 -10
  312. package/dist/orm/sql/serialize/where.mjs +0 -12
  313. package/dist/orm/sql/serialize/where.mjs.map +0 -1
  314. package/dist/orm/sql/serialize.cjs +0 -24
  315. package/dist/orm/sql/serialize.mjs +0 -25
  316. package/dist/orm/sql/serialize.mjs.map +0 -1
  317. package/dist/orm/table.cjs +0 -12
  318. package/dist/orm/table.d.cts +0 -12
  319. package/dist/orm/table.d.cts.map +0 -1
  320. package/dist/orm/table.d.mts +0 -12
  321. package/dist/orm/table.d.mts.map +0 -1
  322. package/dist/orm/table.mjs +0 -14
  323. package/dist/orm/table.mjs.map +0 -1
  324. package/dist/orm/types.d.cts +0 -183
  325. package/dist/orm/types.d.cts.map +0 -1
  326. package/dist/orm/types.d.mts +0 -183
  327. package/dist/orm/types.d.mts.map +0 -1
  328. package/dist/policy/helpers.cjs +0 -206
  329. package/dist/policy/helpers.d.cts +0 -50
  330. package/dist/policy/helpers.d.cts.map +0 -1
  331. package/dist/policy/helpers.d.mts +0 -50
  332. package/dist/policy/helpers.d.mts.map +0 -1
  333. package/dist/policy/helpers.mjs +0 -190
  334. package/dist/policy/helpers.mjs.map +0 -1
  335. package/dist/policy/types.d.cts +0 -16
  336. package/dist/policy/types.d.cts.map +0 -1
  337. package/dist/policy/types.d.mts +0 -16
  338. package/dist/policy/types.d.mts.map +0 -1
  339. package/dist/prompts/core/keys.cjs +0 -165
  340. package/dist/prompts/core/keys.mjs +0 -167
  341. package/dist/prompts/core/keys.mjs.map +0 -1
  342. package/dist/prompts/core/runtime.cjs +0 -104
  343. package/dist/prompts/core/runtime.mjs +0 -106
  344. package/dist/prompts/core/runtime.mjs.map +0 -1
  345. package/dist/prompts/core/session.cjs +0 -98
  346. package/dist/prompts/core/session.mjs +0 -100
  347. package/dist/prompts/core/session.mjs.map +0 -1
  348. package/dist/prompts/core/types.d.cts +0 -21
  349. package/dist/prompts/core/types.d.cts.map +0 -1
  350. package/dist/prompts/core/types.d.mts +0 -21
  351. package/dist/prompts/core/types.d.mts.map +0 -1
  352. package/dist/prompts/types.d.cts +0 -52
  353. package/dist/prompts/types.d.cts.map +0 -1
  354. package/dist/prompts/types.d.mts +0 -52
  355. package/dist/prompts/types.d.mts.map +0 -1
  356. package/dist/pubsub/types.d.cts +0 -10
  357. package/dist/pubsub/types.d.cts.map +0 -1
  358. package/dist/pubsub/types.d.mts +0 -10
  359. package/dist/pubsub/types.d.mts.map +0 -1
  360. package/dist/queue/types.d.cts +0 -47
  361. package/dist/queue/types.d.cts.map +0 -1
  362. package/dist/queue/types.d.mts +0 -47
  363. package/dist/queue/types.d.mts.map +0 -1
  364. package/dist/workflow/types.d.cts +0 -83
  365. package/dist/workflow/types.d.cts.map +0 -1
  366. package/dist/workflow/types.d.mts +0 -83
  367. package/dist/workflow/types.d.mts.map +0 -1
@@ -1,3 +1,535 @@
1
- import { Api } from "../../api/core/index.mjs";
2
- import { Middleware } from "../../api/middleware/index.mjs";
1
+ import { mightThrow } from "../errors/index.mjs";
2
+ //#region src/lib/api/openapi/index.ts
3
+ const toOpenAPISchema = (schema, io = "input") => ({ schema: schema["~standard"].jsonSchema[io]({ target: "draft-2020-12" }) });
4
+ const getSchemaDescription = (schema) => {
5
+ const metadata = schema["~standard"];
6
+ if (!metadata) return "";
7
+ if ("description" in metadata && typeof metadata.description === "string") return metadata.description;
8
+ return "";
9
+ };
10
+ const requestFields = [
11
+ "body",
12
+ "query",
13
+ "headers",
14
+ "cookies",
15
+ "params"
16
+ ];
17
+ const mergeRequestSchemas = (schemas) => {
18
+ const merged = {};
19
+ for (const schema of schemas) {
20
+ if (!schema) continue;
21
+ for (const field of requestFields) if (schema[field]) merged[field] = schema[field];
22
+ }
23
+ return merged;
24
+ };
25
+ const mergeResponseSchemas = (schemas) => {
26
+ const merged = {};
27
+ for (const schema of schemas) {
28
+ if (!schema) continue;
29
+ for (const status in schema) {
30
+ const statusCode = Number(status);
31
+ const responseSchema = schema[statusCode];
32
+ if (responseSchema) merged[statusCode] = responseSchema;
33
+ }
34
+ }
35
+ return Object.keys(merged).length > 0 ? merged : void 0;
36
+ };
37
+ const convertSchemaToOpenApi = async (schema, io = "input") => {
38
+ const result = toOpenAPISchema(schema, io);
39
+ const { schema: jsonSchema } = result;
40
+ const schemaId = jsonSchema.id;
41
+ if (schemaId && typeof schemaId === "string") {
42
+ const schemaWithoutId = { ...jsonSchema };
43
+ delete schemaWithoutId.id;
44
+ delete schemaWithoutId.$schema;
45
+ return {
46
+ schema: { $ref: `#/components/schemas/${schemaId}` },
47
+ components: { schemas: { [schemaId]: schemaWithoutId } }
48
+ };
49
+ }
50
+ if (jsonSchema.$schema) {
51
+ const schemaWithoutMeta = { ...jsonSchema };
52
+ delete schemaWithoutMeta.$schema;
53
+ return {
54
+ schema: schemaWithoutMeta,
55
+ components: void 0
56
+ };
57
+ }
58
+ return result;
59
+ };
60
+ const convertSchemaToInlineOpenApi = async (schema, io = "input") => {
61
+ const { schema: jsonSchema } = toOpenAPISchema(schema, io);
62
+ const cleanSchema = { ...jsonSchema };
63
+ delete cleanSchema.$schema;
64
+ delete cleanSchema.id;
65
+ return {
66
+ schema: cleanSchema,
67
+ components: void 0
68
+ };
69
+ };
70
+ const extractParametersFromSchema = async (schema, location) => {
71
+ const { schema: jsonSchema, components } = await convertSchemaToInlineOpenApi(schema);
72
+ if (jsonSchema.type !== "object") return {
73
+ parameters: [],
74
+ components
75
+ };
76
+ if (!jsonSchema.properties) return {
77
+ parameters: [],
78
+ components
79
+ };
80
+ const parameters = [];
81
+ const requiredFields = jsonSchema.required ?? [];
82
+ for (const name in jsonSchema.properties) {
83
+ const propertySchema = jsonSchema.properties[name];
84
+ const isRequired = requiredFields.includes(name);
85
+ parameters.push({
86
+ name,
87
+ in: location,
88
+ required: isRequired,
89
+ schema: propertySchema
90
+ });
91
+ }
92
+ return {
93
+ parameters,
94
+ components
95
+ };
96
+ };
97
+ const normalizePathForOpenAPI = (path) => {
98
+ return path.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g, "{$1}");
99
+ };
100
+ const extractPathParameters = (path) => {
101
+ const matches = path.match(/:([a-zA-Z_][a-zA-Z0-9_]*)/g);
102
+ if (!matches) return [];
103
+ return matches.map((match) => match.slice(1));
104
+ };
105
+ const paramSources = [
106
+ ["query", "query"],
107
+ ["headers", "header"],
108
+ ["cookies", "cookie"]
109
+ ];
110
+ const createParameters = async (request, path) => {
111
+ const parameters = [];
112
+ const allComponents = [];
113
+ for (const [field, location] of paramSources) if (request[field]) {
114
+ const { parameters: params, components } = await extractParametersFromSchema(request[field], location);
115
+ parameters.push(...params);
116
+ if (components) allComponents.push(components);
117
+ }
118
+ const pathParamNames = extractPathParameters(path);
119
+ if (pathParamNames.length > 0 && request.params) {
120
+ const { schema: jsonSchema, components } = await convertSchemaToInlineOpenApi(request.params);
121
+ if (components) allComponents.push(components);
122
+ if (jsonSchema.type === "object" && jsonSchema.properties) for (const name of pathParamNames) {
123
+ const propertySchema = jsonSchema.properties[name];
124
+ if (propertySchema) parameters.push({
125
+ name,
126
+ in: "path",
127
+ required: true,
128
+ schema: propertySchema
129
+ });
130
+ }
131
+ }
132
+ return {
133
+ parameters,
134
+ components: allComponents
135
+ };
136
+ };
137
+ const createRequestBody = async (bodySchema) => {
138
+ const { schema, components } = await convertSchemaToOpenApi(bodySchema);
139
+ return {
140
+ components,
141
+ requestBody: {
142
+ required: true,
143
+ content: { "application/json": { schema } }
144
+ }
145
+ };
146
+ };
147
+ const createResponses = async (response) => {
148
+ const responses = {};
149
+ const allComponents = [];
150
+ if (!response) return {
151
+ responses,
152
+ components: allComponents
153
+ };
154
+ for (const status in response) {
155
+ const statusCode = String(status);
156
+ const schema = response[Number(status)];
157
+ if (!schema) continue;
158
+ const description = getSchemaDescription(schema);
159
+ const { schema: jsonSchema, components } = await convertSchemaToOpenApi(schema, "output");
160
+ if (components) allComponents.push(components);
161
+ responses[statusCode] = {
162
+ description: description || `Response with status ${statusCode}`,
163
+ content: { "application/json": { schema: jsonSchema } }
164
+ };
165
+ }
166
+ return {
167
+ responses,
168
+ components: allComponents
169
+ };
170
+ };
171
+ const createOperation = async (route, globalMiddlewares, prefix) => {
172
+ const allMiddlewares = [...globalMiddlewares ?? [], ...route.middlewares ?? []];
173
+ const requestSchemas = [];
174
+ const responseSchemas = [];
175
+ for (const middleware of allMiddlewares) {
176
+ requestSchemas.push(middleware.options.request);
177
+ responseSchemas.push(middleware.options.response);
178
+ }
179
+ requestSchemas.push(route.request);
180
+ responseSchemas.push(route.response);
181
+ const mergedRequest = mergeRequestSchemas(requestSchemas);
182
+ const mergedResponse = mergeResponseSchemas(responseSchemas);
183
+ const { parameters, components: parameterComponents } = await createParameters(mergedRequest, prefix ? prefix + route.path : route.path);
184
+ const { responses, components: responseComponents } = await createResponses(mergedResponse);
185
+ const operation = { responses };
186
+ const allComponents = [];
187
+ allComponents.push(...responseComponents);
188
+ allComponents.push(...parameterComponents);
189
+ for (const field of [
190
+ "summary",
191
+ "description",
192
+ "operationId"
193
+ ]) if (route[field]) operation[field] = route[field];
194
+ if (route.tags && route.tags.length > 0) operation.tags = route.tags;
195
+ if (parameters.length > 0) operation.parameters = parameters;
196
+ const bodySchema = mergedRequest.body;
197
+ if (bodySchema) {
198
+ const { requestBody, components: bodyComponents } = await createRequestBody(bodySchema);
199
+ operation.requestBody = requestBody;
200
+ if (bodyComponents) allComponents.push(bodyComponents);
201
+ }
202
+ return {
203
+ operation,
204
+ components: allComponents
205
+ };
206
+ };
207
+ const componentKeys = [
208
+ "schemas",
209
+ "responses",
210
+ "parameters",
211
+ "requestBodies"
212
+ ];
213
+ const mergeComponents = (componentsArray) => {
214
+ const merged = {};
215
+ for (const components of componentsArray) {
216
+ if (!components) continue;
217
+ for (const key of componentKeys) if (components[key]) merged[key] = {
218
+ ...merged[key],
219
+ ...components[key]
220
+ };
221
+ }
222
+ return merged;
223
+ };
224
+ const generateOpenApiSpec = async (options) => {
225
+ const spec = {
226
+ openapi: "3.1.0",
227
+ info: {
228
+ title: options.title,
229
+ description: options.description,
230
+ version: options.version
231
+ },
232
+ paths: {}
233
+ };
234
+ if (options.servers && options.servers.length > 0) spec.servers = options.servers;
235
+ if (options.securitySchemes) spec.components = { securitySchemes: options.securitySchemes };
236
+ const allRouteComponents = [];
237
+ for (const route of options.routes) {
238
+ const openApiPath = normalizePathForOpenAPI(options.prefix ? options.prefix + route.path : route.path);
239
+ const method = route.method.toLowerCase();
240
+ if (!spec.paths[openApiPath]) spec.paths[openApiPath] = {};
241
+ const { operation, components } = await createOperation(route, options.globalMiddlewares ?? [], options.prefix);
242
+ spec.paths[openApiPath][method] = operation;
243
+ allRouteComponents.push(...components);
244
+ }
245
+ const mergedComponents = mergeComponents(allRouteComponents);
246
+ if (!spec.components) spec.components = {};
247
+ if (options.securitySchemes) spec.components.securitySchemes = options.securitySchemes;
248
+ for (const key of componentKeys) {
249
+ const value = mergedComponents[key];
250
+ if (value && Object.keys(value).length > 0) spec.components[key] = value;
251
+ }
252
+ return spec;
253
+ };
254
+ //#endregion
255
+ //#region src/lib/api/errors.ts
256
+ var ParseError = class extends Error {
257
+ constructor(message) {
258
+ super(message);
259
+ this.name = "ParseError";
260
+ }
261
+ };
262
+ var ValidationError = class extends Error {
263
+ constructor(message) {
264
+ super(message);
265
+ this.name = "ValidationError";
266
+ }
267
+ };
268
+ //#endregion
269
+ //#region src/lib/api/validation/index.ts
270
+ const validateSchema = async (schema, data) => {
271
+ const result = await schema["~standard"].validate(data);
272
+ if (!result.issues) return result.value;
273
+ throw new ValidationError(result.issues.map((issue) => {
274
+ let path = "unknown";
275
+ if (Array.isArray(issue.path)) path = issue.path.map(String).join(".");
276
+ return `${path}: ${issue.message ?? "validation failed"}`;
277
+ }).join(", "));
278
+ };
279
+ const validateBody = async (req, bodySchema, bodyCache) => {
280
+ if (!bodySchema) return true;
281
+ if (!(req.headers.get("content-type") ?? "").includes("application/json")) return;
282
+ if (bodyCache?.parsed) return validateSchema(bodySchema, bodyCache.value);
283
+ const [parseError, parsedBody] = await mightThrow(req.json());
284
+ if (parseError) throw new ParseError("Invalid JSON body");
285
+ if (bodyCache) {
286
+ bodyCache.parsed = true;
287
+ bodyCache.value = parsedBody;
288
+ }
289
+ return validateSchema(bodySchema, parsedBody);
290
+ };
291
+ const validateQuery = async (req, querySchema) => {
292
+ if (!querySchema) return true;
293
+ const qIndex = req.url.indexOf("?");
294
+ if (qIndex === -1) return validateSchema(querySchema, {});
295
+ const hashIndex = req.url.indexOf("#", qIndex + 1);
296
+ const queryString = hashIndex === -1 ? req.url.slice(qIndex + 1) : req.url.slice(qIndex + 1, hashIndex);
297
+ const searchParams = new URLSearchParams(queryString);
298
+ const queryParams = {};
299
+ for (const key of searchParams.keys()) {
300
+ const values = searchParams.getAll(key);
301
+ const [firstValue] = values;
302
+ if (values.length === 1) queryParams[key] = firstValue;
303
+ else queryParams[key] = values;
304
+ }
305
+ return validateSchema(querySchema, queryParams);
306
+ };
307
+ const validateHeaders = async (req, headersSchema) => {
308
+ if (!headersSchema) return true;
309
+ const headers = {};
310
+ req.headers.forEach((value, key) => {
311
+ headers[key] = value;
312
+ });
313
+ return validateSchema(headersSchema, headers);
314
+ };
315
+ const validateCookies = async (req, cookiesSchema) => {
316
+ if (!cookiesSchema) return true;
317
+ const cookieHeader = req.headers.get("cookie") ?? "";
318
+ const cookieMap = new Bun.CookieMap(cookieHeader);
319
+ return validateSchema(cookiesSchema, Object.fromEntries(cookieMap));
320
+ };
321
+ const validateParams = async (req, paramsSchema) => {
322
+ if (!paramsSchema) return true;
323
+ return validateSchema(paramsSchema, req.params);
324
+ };
325
+ //#endregion
326
+ //#region src/lib/api/core/index.ts
327
+ const defaultValidated = Object.freeze({
328
+ body: void 0,
329
+ query: void 0,
330
+ headers: void 0,
331
+ cookies: void 0,
332
+ params: void 0
333
+ });
334
+ const responseHelpers = {
335
+ json: (status, data) => Response.json(data, { status }),
336
+ text: (status, text) => new Response(text, { status }),
337
+ html: (status, html) => new Response(html, {
338
+ status,
339
+ headers: { "Content-Type": "text/html" }
340
+ }),
341
+ redirect: (status, url) => Response.redirect(url, status)
342
+ };
343
+ const noopGet = () => void 0;
344
+ const stripTrailingSlash = (path) => {
345
+ if (path !== "/" && path.endsWith("/")) return path.slice(0, -1);
346
+ return path;
347
+ };
348
+ const hasSchemas = (schema) => schema && (schema.body || schema.query || schema.headers || schema.cookies || schema.params);
349
+ const needsBodyCache = (schema) => schema?.body !== void 0;
350
+ const shouldCreateBodyCache = (hasMiddlewares, allMiddlewares, request) => {
351
+ if (needsBodyCache(request)) return true;
352
+ if (!hasMiddlewares) return false;
353
+ return allMiddlewares.some((mw) => needsBodyCache(mw.options.request));
354
+ };
355
+ const resolveValidation = (v) => {
356
+ if (v === void 0 || v === true) return {
357
+ input: true,
358
+ output: true
359
+ };
360
+ if (v === false) return {
361
+ input: false,
362
+ output: false
363
+ };
364
+ return {
365
+ input: v.input !== false,
366
+ output: v.output !== false
367
+ };
368
+ };
369
+ var Api = class {
370
+ options;
371
+ routes = [];
372
+ constructor(options = {}) {
373
+ this.options = options;
374
+ }
375
+ getFullPath(path) {
376
+ const normalizedPath = stripTrailingSlash(path) || "/";
377
+ if (!this.options.prefix) return normalizedPath;
378
+ const normalizedPrefix = stripTrailingSlash(this.options.prefix);
379
+ if (normalizedPrefix === "/") return normalizedPath;
380
+ if (normalizedPath === "/") return normalizedPrefix;
381
+ return normalizedPrefix + normalizedPath;
382
+ }
383
+ async validateRequestSchema(req, schema, bodyCache) {
384
+ if (!schema) return {
385
+ success: true,
386
+ data: {}
387
+ };
388
+ const v = {};
389
+ if (schema.body) {
390
+ const [err, val] = await mightThrow(validateBody(req, schema.body, bodyCache));
391
+ if (err) return {
392
+ success: false,
393
+ error: err
394
+ };
395
+ v.body = val;
396
+ }
397
+ if (schema.query) {
398
+ const [err, val] = await mightThrow(validateQuery(req, schema.query));
399
+ if (err) return {
400
+ success: false,
401
+ error: err
402
+ };
403
+ v.query = val;
404
+ }
405
+ if (schema.headers) {
406
+ const [err, val] = await mightThrow(validateHeaders(req, schema.headers));
407
+ if (err) return {
408
+ success: false,
409
+ error: err
410
+ };
411
+ v.headers = val;
412
+ }
413
+ if (schema.cookies) {
414
+ const [err, val] = await mightThrow(validateCookies(req, schema.cookies));
415
+ if (err) return {
416
+ success: false,
417
+ error: err
418
+ };
419
+ v.cookies = val;
420
+ }
421
+ if (schema.params) {
422
+ const [err, val] = await mightThrow(validateParams(req, schema.params));
423
+ if (err) return {
424
+ success: false,
425
+ error: err
426
+ };
427
+ v.params = val;
428
+ }
429
+ return {
430
+ success: true,
431
+ data: v
432
+ };
433
+ }
434
+ createContext(req, validated, extensions) {
435
+ return {
436
+ raw: req,
437
+ req: validated,
438
+ ...responseHelpers,
439
+ get: (key) => extensions[key]
440
+ };
441
+ }
442
+ async validateResponseBody(response, schema) {
443
+ if (!schema) return response;
444
+ const statusSchema = schema[response.status];
445
+ if (!statusSchema) return response;
446
+ if (!(response.headers.get("content-type") ?? "").includes("application/json")) return response;
447
+ const [parseError, body] = await mightThrow(response.clone().json());
448
+ if (parseError) return responseHelpers.json(400, { message: "Invalid response body" });
449
+ const [validationError] = await mightThrow(validateSchema(statusSchema, body));
450
+ if (validationError) return responseHelpers.json(400, { message: validationError.message });
451
+ return response;
452
+ }
453
+ buildBunRoutes() {
454
+ const bunRoutes = {};
455
+ const validationConfig = resolveValidation(this.options.validation);
456
+ for (const route of this.routes) {
457
+ const { path, method, handler, request, response, middlewares } = route;
458
+ const fullPath = this.getFullPath(path);
459
+ if (!bunRoutes[fullPath]) bunRoutes[fullPath] = {};
460
+ const allMiddlewares = [...this.options.middlewares ?? [], ...middlewares ?? []];
461
+ const hasMiddlewares = allMiddlewares.length > 0;
462
+ const hasRouteSchemas = hasSchemas(request);
463
+ const effectiveOutputValidation = validationConfig.output && !!response;
464
+ if (!hasMiddlewares && !(validationConfig.input && hasRouteSchemas) && !effectiveOutputValidation) bunRoutes[fullPath][method] = (req) => {
465
+ const context = Object.create(responseHelpers);
466
+ context.raw = req;
467
+ context.req = defaultValidated;
468
+ context.get = noopGet;
469
+ return handler(context);
470
+ };
471
+ else bunRoutes[fullPath][method] = async (req) => {
472
+ const extensions = {};
473
+ const bodyCache = validationConfig.input && shouldCreateBodyCache(hasMiddlewares, allMiddlewares, request) ? {
474
+ parsed: false,
475
+ value: void 0
476
+ } : void 0;
477
+ for (const mw of allMiddlewares) {
478
+ const { request: reqSchema, handler: mwHandler } = mw.options;
479
+ let validated = defaultValidated;
480
+ if (validationConfig.input && hasSchemas(reqSchema)) {
481
+ const result = await this.validateRequestSchema(req, reqSchema, bodyCache);
482
+ if (!result.success) return responseHelpers.json(400, { message: result.error?.message });
483
+ validated = result.data;
484
+ }
485
+ const mwResult = await mwHandler(this.createContext(req, validated, extensions));
486
+ if (mwResult instanceof Response) return mwResult;
487
+ if (mwResult) Object.assign(extensions, mwResult);
488
+ }
489
+ let routeValidated = defaultValidated;
490
+ if (validationConfig.input && hasRouteSchemas) {
491
+ const result = await this.validateRequestSchema(req, request, bodyCache);
492
+ if (!result.success) return responseHelpers.json(400, { message: result.error?.message });
493
+ routeValidated = result.data;
494
+ }
495
+ const handlerResponse = await handler(this.createContext(req, routeValidated, extensions));
496
+ if (effectiveOutputValidation) return this.validateResponseBody(handlerResponse, response);
497
+ return handlerResponse;
498
+ };
499
+ }
500
+ return bunRoutes;
501
+ }
502
+ defineRoute(config) {
503
+ this.routes.push(config);
504
+ }
505
+ getOpenApiSpec() {
506
+ return generateOpenApiSpec({
507
+ title: this.options.openapi?.title ?? "API",
508
+ description: this.options.openapi?.description,
509
+ version: this.options.openapi?.version ?? "1.0.0",
510
+ prefix: this.options.prefix,
511
+ servers: this.options.openapi?.servers,
512
+ securitySchemes: this.options.openapi?.securitySchemes,
513
+ routes: this.routes,
514
+ globalMiddlewares: this.options.middlewares
515
+ });
516
+ }
517
+ serve(port, callback) {
518
+ const bunRoutes = this.buildBunRoutes();
519
+ const server = Bun.serve({
520
+ port,
521
+ routes: bunRoutes,
522
+ fetch: () => new Response("Not found", { status: 404 })
523
+ });
524
+ if (callback) callback(server);
525
+ }
526
+ };
527
+ //#endregion
528
+ //#region src/lib/api/middleware/index.ts
529
+ var Middleware = class {
530
+ constructor(options) {
531
+ this.options = options;
532
+ }
533
+ };
534
+ //#endregion
3
535
  export { Api, Middleware };
@@ -1,5 +1,37 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_lib_errors_index = require("../errors/index.cjs");
3
+ //#region src/lib/cache/errors.ts
4
+ var CacheError = class extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "CacheError";
8
+ }
9
+ };
10
+ var InvalidTTLError = class extends Error {
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = "InvalidTTLError";
14
+ }
15
+ };
16
+ var NotFoundError = class extends Error {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = "NotFoundError";
20
+ }
21
+ };
22
+ var SerializationError = class extends Error {
23
+ constructor(message) {
24
+ super(message);
25
+ this.name = "SerializationError";
26
+ }
27
+ };
28
+ var DeserializationError = class extends Error {
29
+ constructor(message) {
30
+ super(message);
31
+ this.name = "DeserializationError";
32
+ }
33
+ };
34
+ //#endregion
3
35
  //#region src/lib/cache/index.ts
4
36
  var Cache = class {
5
37
  options;
@@ -11,41 +43,34 @@ var Cache = class {
11
43
  this.deserialize = options.deserializer ?? ((raw) => JSON.parse(raw));
12
44
  }
13
45
  async get(key) {
14
- if (!this.isEnabled) return this.fail("NotFoundError", `Key ${key} not found`);
46
+ if (!this.isEnabled) throw new NotFoundError(`Key ${key} not found`);
15
47
  const resolvedKey = this.resolveKey(key);
16
48
  const [error, value] = await require_lib_errors_index.mightThrow(this.options.redis.get(resolvedKey));
17
- if (error) return this.fail("CacheError", `Unable to get value for key ${key}`);
18
- if (value === null || value === void 0) return this.fail("NotFoundError", `Key ${key} not found`);
49
+ if (error) throw new CacheError(`Unable to get value for key ${key}`);
50
+ if (value === null || value === void 0) throw new NotFoundError(`Key ${key} not found`);
19
51
  const [deserializeErr, deserialized] = require_lib_errors_index.mightThrowSync(() => this.deserialize(value));
20
- if (deserializeErr) return this.fail("CacheError", `Unable to deserialize value for key ${key}`);
21
- return require_lib_errors_index.ok(deserialized);
52
+ if (deserializeErr) throw new DeserializationError(`Unable to deserialize value for key ${key}`);
53
+ return deserialized;
22
54
  }
23
55
  async set(key, value) {
24
- if (!this.isEnabled) return require_lib_errors_index.ok(value);
56
+ if (!this.isEnabled) return value;
25
57
  const [serializeErr, serialized] = require_lib_errors_index.mightThrowSync(() => this.serialize(value));
26
- if (serializeErr) return this.fail("CacheError", `Unable to serialize value for key ${key}`);
27
- if (serialized === null || serialized === void 0) return this.fail("CacheError", `Unable to serialize value for key ${key}`);
58
+ if (serializeErr) throw new SerializationError(`Unable to serialize value for key ${key}`);
59
+ if (serialized === null || serialized === void 0) throw new SerializationError(`Unable to serialize value for key ${key}`);
28
60
  const [ttlErr, ttl] = require_lib_errors_index.mightThrowSync(() => this.resolveTTL(key, value));
29
- if (ttlErr) return this.fail("InvalidTTLError", `Unable to resolve ttl for key ${key}`);
30
- if (!this.isTTLValid(ttl)) return this.fail("InvalidTTLError", `Unable to save records with ttl equal to ${ttl}`);
61
+ if (ttlErr) throw new InvalidTTLError(`Unable to resolve ttl for key ${key}`);
62
+ if (!this.isTTLValid(ttl)) throw new InvalidTTLError(`Unable to save records with ttl equal to ${ttl}`);
31
63
  const resolvedKey = this.resolveKey(key);
32
64
  const [setError] = await require_lib_errors_index.mightThrow(this.getSetPromise(resolvedKey, serialized, ttl));
33
- if (setError) return this.fail("CacheError", `Unable to set value for key ${key}`);
34
- return require_lib_errors_index.ok(value);
65
+ if (setError) throw new CacheError(`Unable to set value for key ${key}`);
66
+ return value;
35
67
  }
36
68
  async delete(key) {
37
- if (!this.isEnabled) return require_lib_errors_index.ok(0);
69
+ if (!this.isEnabled) return 0;
38
70
  const resolvedKey = this.resolveKey(key);
39
71
  const [error, data] = await require_lib_errors_index.mightThrow(this.options.redis.del(resolvedKey));
40
- if (error) return this.fail("CacheError", `Unable to delete key ${key}`);
41
- return require_lib_errors_index.ok(data);
42
- }
43
- fail(type, message) {
44
- this.options.onError?.({
45
- type,
46
- message
47
- });
48
- return require_lib_errors_index.err(type, message);
72
+ if (error) throw new CacheError(`Unable to delete key ${key}`);
73
+ return data;
49
74
  }
50
75
  get isEnabled() {
51
76
  return this.options.enabled !== false;
@@ -1,30 +1,22 @@
1
- import { CacheOptions } from "../../cache/types.cjs";
2
-
1
+ //#region src/lib/cache/types.d.ts
2
+ type CacheOptions<T> = {
3
+ redis: Bun.RedisClient;
4
+ ttl?: number | ((key: string, value: T) => number);
5
+ enabled?: boolean;
6
+ prefix?: string;
7
+ serializer?: (value: T) => string;
8
+ deserializer?: (raw: string) => T;
9
+ };
10
+ //#endregion
3
11
  //#region src/lib/cache/index.d.ts
4
12
  declare class Cache<T> {
5
13
  private options;
6
14
  private serialize;
7
15
  private deserialize;
8
16
  constructor(options: CacheOptions<T>);
9
- get(key: string): Promise<readonly [{
10
- readonly type: "NotFoundError";
11
- readonly message: string;
12
- }, null] | readonly [{
13
- readonly type: "CacheError";
14
- readonly message: string;
15
- }, null] | readonly [null, T]>;
16
- set(key: string, value: T): Promise<readonly [{
17
- readonly type: "CacheError";
18
- readonly message: string;
19
- }, null] | readonly [null, T] | readonly [{
20
- readonly type: "InvalidTTLError";
21
- readonly message: string;
22
- }, null]>;
23
- delete(key: string): Promise<readonly [null, number] | readonly [{
24
- readonly type: "CacheError";
25
- readonly message: string;
26
- }, null]>;
27
- private fail;
17
+ get(key: string): Promise<T>;
18
+ set(key: string, value: T): Promise<T>;
19
+ delete(key: string): Promise<number>;
28
20
  private get isEnabled();
29
21
  private resolveKey;
30
22
  private resolveTTL;
@@ -32,5 +24,4 @@ declare class Cache<T> {
32
24
  private isTTLValid;
33
25
  }
34
26
  //#endregion
35
- export { Cache };
36
- //# sourceMappingURL=index.d.cts.map
27
+ export { Cache };