semola 0.5.3 → 0.5.4

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