@guren/server 2.15.0 → 2.16.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 (296) hide show
  1. package/dist/{DocsViewerServiceProvider-qFCaeiUv.js → DocsViewerServiceProvider-D2cuVgtN.js} +7 -12
  2. package/dist/{Hash-C8aejmi8.js → Hash-D2DFd8xX.js} +7 -57
  3. package/dist/{HttpException-BkS3euNG.js → HttpException-BlQ2yEmT.js} +2 -79
  4. package/dist/{Job-BVT813DO.js → Job-DxQK8h3P.js} +24 -179
  5. package/dist/{McpServiceProvider-BawsYjgN.js → McpServiceProvider-nNcbCIQX.js} +11 -20
  6. package/dist/{Random-DbIJ22KQ.js → Random-S0OvCuR8.js} +9 -106
  7. package/dist/agent/AgentApprovalRequested.d.ts +11 -39
  8. package/dist/agent/approval.d.ts +76 -187
  9. package/dist/agent/audit-emitter.d.ts +16 -44
  10. package/dist/agent/audit.d.ts +20 -56
  11. package/dist/agent/derive.d.ts +32 -66
  12. package/dist/agent/dispatch.d.ts +38 -90
  13. package/dist/agent/events.d.ts +11 -19
  14. package/dist/agent/meta-tools.d.ts +18 -46
  15. package/dist/agent/public.d.ts +6 -25
  16. package/dist/agent/public.js +1 -1
  17. package/dist/agent/redact.d.ts +16 -38
  18. package/dist/agent/scopes.d.ts +23 -69
  19. package/dist/auth/AuthManager.d.ts +19 -40
  20. package/dist/auth/AuthenticatableModel.d.ts +2 -2
  21. package/dist/auth/SessionGuard.d.ts +0 -1
  22. package/dist/auth/TokenGuard.d.ts +6 -26
  23. package/dist/auth/api-token.d.ts +16 -148
  24. package/dist/auth/context.d.ts +5 -10
  25. package/dist/auth/email-verification.d.ts +29 -127
  26. package/dist/auth/index.js +1 -1
  27. package/dist/auth/oauth/index.d.ts +35 -57
  28. package/dist/auth/password/DefaultHasher.d.ts +5 -14
  29. package/dist/auth/password/PasswordHasher.d.ts +5 -13
  30. package/dist/auth/password/hash-format.d.ts +5 -13
  31. package/dist/auth/password-reset.d.ts +16 -42
  32. package/dist/auth/providers/ModelUserProvider.d.ts +3 -4
  33. package/dist/auth/providers/UserProvider.d.ts +4 -4
  34. package/dist/auth/signed-token.d.ts +18 -0
  35. package/dist/auth/types.d.ts +9 -32
  36. package/dist/auth/utils.d.ts +6 -27
  37. package/dist/{auth-DkYoAPVn.js → auth-CbdPH4Cd.js} +169 -502
  38. package/dist/authorization/Gate.d.ts +9 -145
  39. package/dist/authorization/Policy.d.ts +6 -53
  40. package/dist/authorization/index.js +1 -1
  41. package/dist/authorization/middleware.d.ts +16 -62
  42. package/dist/authorization/types.d.ts +8 -64
  43. package/dist/{authorization-CdfbCj8J.js → authorization-CdEWZZw3.js} +44 -309
  44. package/dist/broadcasting/BroadcastManager.d.ts +29 -149
  45. package/dist/broadcasting/channels/Channel.d.ts +1 -19
  46. package/dist/broadcasting/channels/PresenceChannel.d.ts +1 -55
  47. package/dist/broadcasting/channels/PrivateChannel.d.ts +1 -23
  48. package/dist/broadcasting/drivers/MemoryDriver.d.ts +18 -70
  49. package/dist/broadcasting/drivers/RedisDriver.d.ts +3 -80
  50. package/dist/broadcasting/drivers/index.d.ts +1 -1
  51. package/dist/broadcasting/index.d.ts +1 -1
  52. package/dist/broadcasting/index.js +1 -1
  53. package/dist/broadcasting/types.d.ts +7 -88
  54. package/dist/{broadcasting-BwodCA4q.js → broadcasting-B5RzB0A2.js} +87 -414
  55. package/dist/cache/CacheManager.d.ts +8 -62
  56. package/dist/cache/TaggedCache.d.ts +2 -35
  57. package/dist/cache/index.js +1 -1
  58. package/dist/cache/stores/FileStore.d.ts +2 -36
  59. package/dist/cache/stores/MemoryStore.d.ts +2 -26
  60. package/dist/cache/stores/RedisStore.d.ts +1 -29
  61. package/dist/cache/types.d.ts +21 -128
  62. package/dist/{cache-BYnZf2FR.js → cache-BOOIr324.js} +19 -198
  63. package/dist/client-C4TEr_Dd.js +9 -0
  64. package/dist/console/Command.d.ts +17 -126
  65. package/dist/console/ConsoleKernel.d.ts +2 -74
  66. package/dist/console/Input.d.ts +5 -113
  67. package/dist/console/Output.d.ts +3 -99
  68. package/dist/console/types.d.ts +3 -33
  69. package/dist/container/Container.d.ts +12 -103
  70. package/dist/container/ServiceProvider.d.ts +17 -61
  71. package/dist/container/bindings.d.ts +5 -26
  72. package/dist/container/defineModule.d.ts +16 -54
  73. package/dist/container/definePlugin.d.ts +12 -45
  74. package/dist/container/types.d.ts +2 -34
  75. package/dist/context-CXk_umpT.js +21 -0
  76. package/dist/database/Factory.d.ts +4 -57
  77. package/dist/database/Seeder.d.ts +8 -46
  78. package/dist/database/SeederRunner.d.ts +3 -33
  79. package/dist/database/types.d.ts +3 -24
  80. package/dist/discovery/AutoDiscovery.d.ts +10 -82
  81. package/dist/{dispatch-erOS9epZ.js → dispatch-BAwzftws.js} +32 -79
  82. package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +2 -5
  83. package/dist/docs-viewer/endpoint.d.ts +5 -11
  84. package/dist/encryption/Encrypter.d.ts +5 -71
  85. package/dist/encryption/Hash.d.ts +7 -57
  86. package/dist/encryption/Random.d.ts +6 -99
  87. package/dist/encryption/index.js +3 -3
  88. package/dist/encryption/types.d.ts +10 -72
  89. package/dist/{encryption-D99Vmls3.js → encryption-uwP3Di4D.js} +9 -78
  90. package/dist/{endpoint-D6GIqOpe.js → endpoint-BXipU2Jj.js} +6 -12
  91. package/dist/endpoint-Dsw3Acvq.js +26 -0
  92. package/dist/errors/ExceptionHandler.d.ts +3 -90
  93. package/dist/errors/HttpException.d.ts +2 -79
  94. package/dist/errors/debug-page.d.ts +3 -17
  95. package/dist/errors/error-page.d.ts +1 -0
  96. package/dist/errors/exceptions/AuthenticationException.d.ts +2 -24
  97. package/dist/errors/exceptions/AuthorizationException.d.ts +1 -24
  98. package/dist/errors/exceptions/MethodNotAllowedException.d.ts +1 -23
  99. package/dist/errors/exceptions/NotFoundHttpException.d.ts +1 -27
  100. package/dist/errors/exceptions/ValidationException.d.ts +2 -43
  101. package/dist/errors/types.d.ts +1 -25
  102. package/dist/{errors-BgeOl_DC.js → errors-JpkcCjjn.js} +3 -41
  103. package/dist/events/Event.d.ts +1 -28
  104. package/dist/events/EventManager.d.ts +5 -107
  105. package/dist/events/Listener.d.ts +7 -55
  106. package/dist/events/builtin.d.ts +0 -24
  107. package/dist/events/index.js +1 -1
  108. package/dist/events/types.d.ts +4 -22
  109. package/dist/{events-aIH_bWRx.js → events-DOmAHDeP.js} +11 -191
  110. package/dist/facades/index.d.ts +2 -14
  111. package/dist/health/HealthCheck.d.ts +0 -24
  112. package/dist/health/HealthManager.d.ts +0 -36
  113. package/dist/health/checks/CacheCheck.d.ts +2 -17
  114. package/dist/health/checks/CustomCheck.d.ts +0 -9
  115. package/dist/health/checks/DatabaseCheck.d.ts +2 -17
  116. package/dist/health/checks/MemoryCheck.d.ts +3 -12
  117. package/dist/health/checks/RedisCheck.d.ts +1 -13
  118. package/dist/health/checks/StorageCheck.d.ts +2 -17
  119. package/dist/health/index.js +1 -1
  120. package/dist/health/types.d.ts +4 -24
  121. package/dist/{health-VWdWXRwh.js → health-DQSvUplL.js} +1 -76
  122. package/dist/hot-disposables-B5BXqaIH.js +167 -0
  123. package/dist/hot-reload/hot-disposables.d.ts +22 -74
  124. package/dist/hot-reload/testing.d.ts +4 -9
  125. package/dist/http/Application.d.ts +62 -208
  126. package/dist/http/FormRequest.d.ts +4 -55
  127. package/dist/http/dev-assets.d.ts +13 -31
  128. package/dist/http/dev-banner.d.ts +2 -5
  129. package/dist/http/inertia-assets.d.ts +3 -6
  130. package/dist/http/middleware/capabilities.d.ts +27 -50
  131. package/dist/http/middleware/cors.d.ts +4 -29
  132. package/dist/http/middleware/csp.d.ts +2 -25
  133. package/dist/http/middleware/csrf.d.ts +20 -95
  134. package/dist/http/middleware/detect-locale.d.ts +7 -27
  135. package/dist/http/middleware/force-https.d.ts +6 -24
  136. package/dist/http/middleware/host-authorization.d.ts +2 -12
  137. package/dist/http/middleware/loopback-guard.d.ts +15 -33
  138. package/dist/http/middleware/rate-limit.d.ts +29 -126
  139. package/dist/http/middleware/redirect-safety.d.ts +2 -20
  140. package/dist/http/middleware/request-id.d.ts +1 -14
  141. package/dist/http/middleware/request-logging.d.ts +2 -13
  142. package/dist/http/middleware/response-headers.d.ts +5 -13
  143. package/dist/http/middleware/security-headers.d.ts +2 -16
  144. package/dist/http/middleware/session.d.ts +15 -34
  145. package/dist/http/middleware/validation-errors-cookie.d.ts +7 -18
  146. package/dist/http/middleware/validation.d.ts +8 -63
  147. package/dist/http/public-assets.d.ts +11 -7
  148. package/dist/http/request.d.ts +32 -118
  149. package/dist/http/resources/CursorPaginator.d.ts +5 -64
  150. package/dist/http/resources/Paginator.d.ts +7 -84
  151. package/dist/http/resources/Resource.d.ts +9 -65
  152. package/dist/http/resources/ResourceCollection.d.ts +5 -39
  153. package/dist/http/resources/types.d.ts +10 -30
  154. package/dist/http/static-documents.d.ts +10 -20
  155. package/dist/http/validation/Validator.d.ts +25 -85
  156. package/dist/http/validation/rules.d.ts +48 -147
  157. package/dist/http/validation/types.d.ts +16 -61
  158. package/dist/http/vite-assets.d.ts +5 -28
  159. package/dist/http/vite-dev-server.d.ts +6 -9
  160. package/dist/http/vite-manifest.d.ts +19 -33
  161. package/dist/i18n/I18nManager.d.ts +12 -78
  162. package/dist/i18n/Translator.d.ts +3 -54
  163. package/dist/i18n/index.js +1 -1
  164. package/dist/i18n/loaders/JsonLoader.d.ts +4 -31
  165. package/dist/i18n/loaders/MemoryLoader.d.ts +1 -21
  166. package/dist/i18n/pluralization.d.ts +4 -13
  167. package/dist/i18n/types.d.ts +17 -69
  168. package/dist/{i18n-mcWi7LCd.js → i18n-Cg1aajRP.js} +31 -225
  169. package/dist/index.d.ts +2 -1
  170. package/dist/index.js +714 -3011
  171. package/dist/internal/agent-preflight.d.ts +9 -21
  172. package/dist/internal/request.d.ts +6 -19
  173. package/dist/internal/request.js +1 -1
  174. package/dist/internal/route-path.d.ts +9 -21
  175. package/dist/internal/route-path.js +9 -21
  176. package/dist/internal/zod-compat.d.ts +55 -122
  177. package/dist/internal/zod-compat.js +39 -70
  178. package/dist/internal/zod-json-schema.d.ts +18 -54
  179. package/dist/internal/zod-json-schema.js +46 -123
  180. package/dist/jsx-runtime.d.ts +3 -8
  181. package/dist/lambda/index.d.ts +17 -79
  182. package/dist/lambda/index.js +11 -59
  183. package/dist/logging/LogManager.d.ts +1 -51
  184. package/dist/logging/Logger.d.ts +8 -47
  185. package/dist/logging/channels/ConsoleChannel.d.ts +1 -3
  186. package/dist/logging/channels/DailyFileChannel.d.ts +1 -3
  187. package/dist/logging/channels/FileChannel.d.ts +1 -3
  188. package/dist/logging/daily-file-path.d.ts +7 -16
  189. package/dist/logging/index.js +1 -1
  190. package/dist/logging/types.d.ts +13 -45
  191. package/dist/{logging-B-kngi3q.js → logging-zOY1XCtq.js} +52 -141
  192. package/dist/{loopback-guard-D0Kc7-xc.js → loopback-guard-DT9gHF0F.js} +41 -92
  193. package/dist/mail/Mail.d.ts +10 -106
  194. package/dist/mail/MailManager.d.ts +2 -60
  195. package/dist/mail/index.js +1 -1
  196. package/dist/mail/transports/LogTransport.d.ts +1 -4
  197. package/dist/mail/transports/MemoryTransport.d.ts +1 -63
  198. package/dist/mail/transports/ResendTransport.d.ts +1 -23
  199. package/dist/mail/transports/SmtpTransport.d.ts +1 -31
  200. package/dist/mail/types.d.ts +28 -150
  201. package/dist/{mail-DfEfSQEr.js → mail-76DWy9lj.js} +31 -289
  202. package/dist/mcp/McpServiceProvider.d.ts +4 -10
  203. package/dist/mcp/create-mcp-server.d.ts +25 -57
  204. package/dist/mcp/endpoint.d.ts +12 -36
  205. package/dist/mcp/index.js +1 -1
  206. package/dist/mvc/Controller.d.ts +46 -227
  207. package/dist/mvc/Router.d.ts +50 -129
  208. package/dist/mvc/inertia/InertiaEngine.d.ts +18 -48
  209. package/dist/mvc/inertia/shared.d.ts +6 -19
  210. package/dist/mvc/mount-route.d.ts +2 -6
  211. package/dist/mvc/view.d.ts +1 -2
  212. package/dist/notifications/Notification.d.ts +8 -75
  213. package/dist/notifications/NotificationManager.d.ts +15 -88
  214. package/dist/notifications/channels/DatabaseChannel.d.ts +1 -41
  215. package/dist/notifications/channels/MailChannel.d.ts +2 -31
  216. package/dist/notifications/channels/MemoryChannel.d.ts +2 -62
  217. package/dist/notifications/channels/SlackChannel.d.ts +3 -48
  218. package/dist/notifications/index.js +1 -1
  219. package/dist/notifications/notifiable-type.d.ts +3 -6
  220. package/dist/notifications/registry.d.ts +8 -27
  221. package/dist/notifications/types.d.ts +16 -53
  222. package/dist/{notifications-BGqmUNZ8.js → notifications-okWFs9ly.js} +37 -335
  223. package/dist/providers/AuthServiceProvider.d.ts +1 -3
  224. package/dist/providers/AuthorizationServiceProvider.d.ts +2 -3
  225. package/dist/providers/BroadcastServiceProvider.d.ts +1 -3
  226. package/dist/providers/CacheServiceProvider.d.ts +1 -3
  227. package/dist/providers/EncryptionServiceProvider.d.ts +1 -3
  228. package/dist/providers/ErrorServiceProvider.d.ts +1 -4
  229. package/dist/providers/EventServiceProvider.d.ts +1 -3
  230. package/dist/providers/HealthServiceProvider.d.ts +1 -3
  231. package/dist/providers/I18nServiceProvider.d.ts +6 -10
  232. package/dist/providers/InertiaServiceProvider.d.ts +1 -4
  233. package/dist/providers/LogServiceProvider.d.ts +1 -3
  234. package/dist/providers/MailServiceProvider.d.ts +1 -3
  235. package/dist/providers/NotificationServiceProvider.d.ts +1 -3
  236. package/dist/providers/OAuthServiceProvider.d.ts +1 -3
  237. package/dist/providers/QueueServiceProvider.d.ts +1 -3
  238. package/dist/providers/SchedulingServiceProvider.d.ts +1 -3
  239. package/dist/providers/StorageServiceProvider.d.ts +1 -3
  240. package/dist/queue/FailedJobReporter.d.ts +1 -24
  241. package/dist/queue/Job.d.ts +12 -99
  242. package/dist/queue/QueueManager.d.ts +6 -57
  243. package/dist/queue/Worker.d.ts +4 -65
  244. package/dist/queue/drivers/MemoryDriver.d.ts +3 -44
  245. package/dist/queue/drivers/RedisDriver.d.ts +7 -65
  246. package/dist/queue/drivers/SqsDriver.d.ts +6 -57
  247. package/dist/queue/drivers/SyncDriver.d.ts +10 -13
  248. package/dist/queue/index.js +2 -2
  249. package/dist/queue/types.d.ts +10 -92
  250. package/dist/{queue-CXrRK85G.js → queue-CcXCjuJI.js} +32 -260
  251. package/dist/redis/RedisApiTokenStore.d.ts +4 -56
  252. package/dist/redis/RedisEmailVerificationStore.d.ts +4 -37
  253. package/dist/redis/RedisOAuthStateStore.d.ts +2 -10
  254. package/dist/redis/RedisPasswordResetStore.d.ts +4 -37
  255. package/dist/redis/RedisRateLimitStore.d.ts +16 -49
  256. package/dist/redis/RedisSessionStore.d.ts +3 -44
  257. package/dist/redis/client.d.ts +2 -32
  258. package/dist/redis/index.js +47 -232
  259. package/dist/redis/redis-values.d.ts +6 -12
  260. package/dist/redis/scan-keys.d.ts +1 -4
  261. package/dist/request-CLOYytGP.js +68 -0
  262. package/dist/runtime/index.d.ts +2 -0
  263. package/dist/runtime/index.js +50 -92
  264. package/dist/scheduling/CronParser.d.ts +0 -29
  265. package/dist/scheduling/Schedule.d.ts +1 -153
  266. package/dist/scheduling/ScheduledTask.d.ts +0 -31
  267. package/dist/scheduling/Scheduler.d.ts +0 -70
  268. package/dist/scheduling/index.js +1 -1
  269. package/dist/scheduling/types.d.ts +4 -65
  270. package/dist/{scheduling-CPiEdtQd.js → scheduling-C6tcOtUl.js} +2 -287
  271. package/dist/storage/StorageManager.d.ts +0 -48
  272. package/dist/storage/drivers/LocalDriver.d.ts +1 -25
  273. package/dist/storage/drivers/MemoryDriver.d.ts +5 -35
  274. package/dist/storage/drivers/S3Driver.d.ts +6 -36
  275. package/dist/storage/drivers/s3-acl.d.ts +5 -10
  276. package/dist/storage/index.js +1 -1
  277. package/dist/storage/types.d.ts +27 -265
  278. package/dist/{storage-TLD9t0Q2.js → storage-BB59f07j.js} +17 -157
  279. package/dist/support/contained-path.d.ts +10 -20
  280. package/dist/support/error-polyfill.d.ts +4 -6
  281. package/dist/support/expiry.d.ts +17 -33
  282. package/dist/support/expiry.js +17 -33
  283. package/dist/support/import-map.d.ts +3 -7
  284. package/dist/support/inertia-defaults.d.ts +5 -10
  285. package/dist/support/redirect-target.d.ts +4 -6
  286. package/dist/support/stack-frames.d.ts +11 -50
  287. package/dist/support/trim-slashes.d.ts +4 -7
  288. package/dist/support/warn-once.d.ts +2 -6
  289. package/dist/{trim-slashes-ZJ_VsY5s.js → trim-slashes-BLY9hKAa.js} +4 -7
  290. package/dist/{vite-manifest-w_RSOvQW.js → vite-manifest-CTQp-SOo.js} +34 -58
  291. package/package.json +2 -2
  292. package/dist/client-Dd7vLcqp.js +0 -27
  293. package/dist/context-DoD0c7J_.js +0 -26
  294. package/dist/endpoint-D-20PiHY.js +0 -46
  295. package/dist/hot-disposables-WsTX2ySN.js +0 -281
  296. package/dist/request-CVQwpu2J.js +0 -129
@@ -1,39 +1,20 @@
1
- import { c as setQueueDriver, r as getJob } from "./Job-BVT813DO.js";
1
+ import { c as setQueueDriver, r as getJob } from "./Job-DxQK8h3P.js";
2
2
  //#region src/queue/drivers/MemoryDriver.ts
3
- /**
4
- * In-memory queue driver for development and testing.
5
- *
6
- * @example
7
- * ```ts
8
- * import { MemoryDriver, setQueueDriver } from '@guren/server/queue'
9
- *
10
- * const driver = new MemoryDriver()
11
- * setQueueDriver(driver)
12
- * ```
13
- */
3
+ /** In-memory queue driver for development and testing. */
14
4
  var MemoryDriver = class {
15
5
  jobs = /* @__PURE__ */ new Map();
16
6
  failedJobs = /* @__PURE__ */ new Map();
17
- /**
18
- * Push a job onto the queue.
19
- */
20
7
  async push(job) {
21
8
  this.jobs.set(job.id, { ...job });
22
9
  }
23
- /**
24
- * Pop the next available job from the queue.
25
- */
26
10
  async pop(queue) {
27
11
  const now = /* @__PURE__ */ new Date();
28
- for (const [id, job] of this.jobs) if (job.queue === queue && job.availableAt <= now && job.reservedAt === null) {
12
+ for (const [_id, job] of this.jobs) if (job.queue === queue && job.availableAt <= now && job.reservedAt === null) {
29
13
  job.reservedAt = now;
30
14
  return { ...job };
31
15
  }
32
16
  return null;
33
17
  }
34
- /**
35
- * Release a job back onto the queue.
36
- */
37
18
  async release(job, delayMs = 0) {
38
19
  const existing = this.jobs.get(job.id);
39
20
  if (existing) {
@@ -43,15 +24,9 @@ var MemoryDriver = class {
43
24
  if (job.lastError) existing.lastError = job.lastError;
44
25
  }
45
26
  }
46
- /**
47
- * Delete a job from the queue.
48
- */
49
27
  async delete(jobId) {
50
28
  this.jobs.delete(jobId);
51
29
  }
52
- /**
53
- * Mark a job as failed.
54
- */
55
30
  async fail(job, error) {
56
31
  const failedJob = {
57
32
  ...job,
@@ -62,25 +37,16 @@ var MemoryDriver = class {
62
37
  this.failedJobs.set(job.id, failedJob);
63
38
  this.jobs.delete(job.id);
64
39
  }
65
- /**
66
- * Get the number of jobs in a queue.
67
- */
68
40
  async size(queue) {
69
41
  let count = 0;
70
42
  for (const job of this.jobs.values()) if (job.queue === queue && job.reservedAt === null) count++;
71
43
  return count;
72
44
  }
73
- /**
74
- * Get failed jobs.
75
- */
76
45
  async getFailedJobs(queue) {
77
46
  const jobs = [];
78
47
  for (const job of this.failedJobs.values()) if (!queue || job.queue === queue) jobs.push({ ...job });
79
48
  return jobs.sort((a, b) => b.failedAt.getTime() - a.failedAt.getTime());
80
49
  }
81
- /**
82
- * Retry a failed job.
83
- */
84
50
  async retryFailedJob(jobId) {
85
51
  const failedJob = this.failedJobs.get(jobId);
86
52
  if (!failedJob) throw new Error(`Failed job not found: ${jobId}`);
@@ -98,22 +64,15 @@ var MemoryDriver = class {
98
64
  this.jobs.set(job.id, job);
99
65
  this.failedJobs.delete(jobId);
100
66
  }
101
- /**
102
- * Delete a failed job.
103
- */
104
67
  async deleteFailedJob(jobId) {
105
68
  this.failedJobs.delete(jobId);
106
69
  }
107
- /**
108
- * Clear all jobs (for testing).
109
- */
70
+ /** Testing only. */
110
71
  async clear() {
111
72
  this.jobs.clear();
112
73
  this.failedJobs.clear();
113
74
  }
114
- /**
115
- * Get all pending jobs (for testing/debugging).
116
- */
75
+ /** Testing/debugging only. */
117
76
  getPendingJobs(queue) {
118
77
  const jobs = [];
119
78
  for (const job of this.jobs.values()) if (!queue || job.queue === queue) jobs.push({ ...job });
@@ -123,18 +82,10 @@ var MemoryDriver = class {
123
82
  //#endregion
124
83
  //#region src/queue/drivers/SyncDriver.ts
125
84
  /**
126
- * Synchronous queue driver: jobs execute immediately in the dispatching
127
- * process, no worker required. This is the development default — dispatch
128
- * semantics stay identical to a real queue, but failures surface right away
129
- * and nothing needs a second process.
130
- *
131
- * @example
132
- * ```ts
133
- * const queue = createQueueManager({
134
- * default: 'sync',
135
- * drivers: { sync: () => new SyncDriver() },
136
- * })
137
- * ```
85
+ * Runs jobs inline in the dispatching process, no worker required: the
86
+ * development default. Dispatch semantics match a real queue but failures
87
+ * surface immediately, and retry backoff is not honored because nothing waits
88
+ * in a sync queue (`release()` re-runs the job at once whatever `delayMs`).
138
89
  */
139
90
  var SyncDriver = class {
140
91
  failedJobs = /* @__PURE__ */ new Map();
@@ -152,7 +103,12 @@ var SyncDriver = class {
152
103
  async pop() {
153
104
  return null;
154
105
  }
155
- async release(job) {
106
+ /**
107
+ * Re-run the job now, ignoring `delayMs`: honoring a backoff would block the
108
+ * releasing caller for the full delay, and a detached timer would move the
109
+ * failure off the call that surfaces it. A failure rethrows, as `push()` does.
110
+ */
111
+ async release(job, _delayMs) {
156
112
  await this.push(job);
157
113
  }
158
114
  async delete() {}
@@ -191,23 +147,10 @@ var SyncDriver = class {
191
147
  //#endregion
192
148
  //#region src/queue/drivers/RedisDriver.ts
193
149
  /**
194
- * Redis-backed queue driver for production.
195
- *
196
- * Uses the following Redis structures:
197
- * - `{prefix}{queue}:pending` - Sorted Set (score = availableAt timestamp)
198
- * - `{prefix}{queue}:reserved` - Sorted Set (score = timeout timestamp)
199
- * - `{prefix}{queue}:failed` - List of failed job IDs
200
- * - `{prefix}job:{id}` - Hash containing job data
201
- *
202
- * @example
203
- * ```ts
204
- * import { createRedisClient } from '@guren/server/redis'
205
- * import { RedisDriver, setQueueDriver } from '@guren/server/queue'
206
- *
207
- * const redis = createRedisClient({ url: process.env.REDIS_URL })
208
- * const driver = new RedisDriver(redis)
209
- * setQueueDriver(driver)
210
- * ```
150
+ * Redis-backed queue driver for production. Key layout:
151
+ * `{prefix}{queue}:pending` Sorted Set (score = availableAt),
152
+ * `{prefix}{queue}:reserved` Sorted Set (score = timeout),
153
+ * `{prefix}{queue}:failed` List of job IDs, `{prefix}job:{id}` Hash of job data.
211
154
  */
212
155
  var RedisDriver = class {
213
156
  redis;
@@ -230,9 +173,6 @@ var RedisDriver = class {
230
173
  jobKey(id) {
231
174
  return `${this.prefix}job:${id}`;
232
175
  }
233
- /**
234
- * Push a job onto the queue.
235
- */
236
176
  async push(job) {
237
177
  const jobData = {
238
178
  id: job.id,
@@ -249,9 +189,6 @@ var RedisDriver = class {
249
189
  pipeline.zadd(this.pendingKey(job.queue), job.availableAt.getTime(), job.id);
250
190
  await pipeline.exec();
251
191
  }
252
- /**
253
- * Pop the next available job from the queue.
254
- */
255
192
  async pop(queue) {
256
193
  const now = Date.now();
257
194
  await this.releaseTimedOutJobs(queue);
@@ -269,9 +206,6 @@ var RedisDriver = class {
269
206
  }
270
207
  return this.parseJobData(jobData);
271
208
  }
272
- /**
273
- * Release jobs that have exceeded visibility timeout.
274
- */
275
209
  async releaseTimedOutJobs(queue) {
276
210
  const now = Date.now();
277
211
  const timedOutIds = await this.redis.zrangebyscore(this.reservedKey(queue), "-inf", now);
@@ -280,9 +214,6 @@ var RedisDriver = class {
280
214
  await this.redis.hdel(this.jobKey(jobId), "reservedAt");
281
215
  }
282
216
  }
283
- /**
284
- * Release a job back onto the queue.
285
- */
286
217
  async release(job, delayMs = 0) {
287
218
  const availableAt = Date.now() + delayMs;
288
219
  await this.redis.zrem(this.reservedKey(job.queue), job.id);
@@ -295,9 +226,6 @@ var RedisDriver = class {
295
226
  await this.redis.hdel(this.jobKey(job.id), "reservedAt");
296
227
  await this.redis.zadd(this.pendingKey(job.queue), availableAt, job.id);
297
228
  }
298
- /**
299
- * Delete a job from the queue.
300
- */
301
229
  async delete(jobId) {
302
230
  const jobData = await this.redis.hgetall(this.jobKey(jobId));
303
231
  if (jobData && jobData.queue) {
@@ -308,9 +236,6 @@ var RedisDriver = class {
308
236
  await pipeline.exec();
309
237
  } else await this.redis.del(this.jobKey(jobId));
310
238
  }
311
- /**
312
- * Mark a job as failed.
313
- */
314
239
  async fail(job, error) {
315
240
  const failedData = {
316
241
  failedAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -323,15 +248,9 @@ var RedisDriver = class {
323
248
  pipeline.lpush(this.failedKey(job.queue), job.id);
324
249
  await pipeline.exec();
325
250
  }
326
- /**
327
- * Get the number of jobs in a queue.
328
- */
329
251
  async size(queue) {
330
252
  return this.redis.zcard(this.pendingKey(queue));
331
253
  }
332
- /**
333
- * Get failed jobs.
334
- */
335
254
  async getFailedJobs(queue) {
336
255
  const jobs = [];
337
256
  if (queue) jobs.push(...await this.getFailedJobsForQueue(queue));
@@ -368,9 +287,6 @@ var RedisDriver = class {
368
287
  }
369
288
  return jobs;
370
289
  }
371
- /**
372
- * Retry a failed job.
373
- */
374
290
  async retryFailedJob(jobId) {
375
291
  const jobData = await this.redis.hgetall(this.jobKey(jobId));
376
292
  if (!jobData || !jobData.queue) throw new Error(`Failed job not found: ${jobId}`);
@@ -385,17 +301,12 @@ var RedisDriver = class {
385
301
  await this.redis.hdel(this.jobKey(jobId), "reservedAt", "failedAt", "error", "stack", "lastError");
386
302
  await this.redis.zadd(this.pendingKey(queue), now.getTime(), jobId);
387
303
  }
388
- /**
389
- * Delete a failed job.
390
- */
391
304
  async deleteFailedJob(jobId) {
392
305
  const jobData = await this.redis.hgetall(this.jobKey(jobId));
393
306
  if (jobData && jobData.queue) await this.redis.lrem(this.failedKey(jobData.queue), 1, jobId);
394
307
  await this.redis.del(this.jobKey(jobId));
395
308
  }
396
- /**
397
- * Clear all jobs (for testing).
398
- */
309
+ /** Testing only. */
399
310
  async clear() {
400
311
  const pattern = this.prefix + "*";
401
312
  let cursor = "0";
@@ -407,9 +318,6 @@ var RedisDriver = class {
407
318
  } while (cursor !== "0");
408
319
  if (keys.length > 0) await this.redis.del(...keys);
409
320
  }
410
- /**
411
- * Parse job data from Redis hash.
412
- */
413
321
  parseJobData(data) {
414
322
  return {
415
323
  id: data.id,
@@ -427,19 +335,7 @@ var RedisDriver = class {
427
335
  };
428
336
  //#endregion
429
337
  //#region src/queue/drivers/SqsDriver.ts
430
- /**
431
- * Create an SqsAdapter from an @aws-sdk/client-sqs SQSClient.
432
- *
433
- * @example
434
- * ```ts
435
- * import { SQSClient } from '@aws-sdk/client-sqs'
436
- * import { createSqsAdapter, SqsDriver } from '@guren/server/queue'
437
- *
438
- * const client = new SQSClient({ region: 'ap-northeast-1' })
439
- * const adapter = createSqsAdapter(client)
440
- * const driver = new SqsDriver(adapter, { queueUrl: '...' })
441
- * ```
442
- */
338
+ /** Builds an SqsAdapter over an @aws-sdk/client-sqs SQSClient. */
443
339
  function createSqsAdapter(client) {
444
340
  return {
445
341
  async sendMessage(params) {
@@ -494,22 +390,7 @@ async function importSqs() {
494
390
  throw new Error(`Missing optional dependency "${SQS_MODULE}". Install @aws-sdk/client-sqs to use the SQS driver or createSqsAdapter.`);
495
391
  }
496
392
  }
497
- /**
498
- * AWS SQS queue driver for serverless deployments.
499
- *
500
- * @example
501
- * ```ts
502
- * import { SQSClient } from '@aws-sdk/client-sqs'
503
- * import { createSqsAdapter, SqsDriver, setQueueDriver } from '@guren/server/queue'
504
- *
505
- * const adapter = createSqsAdapter(new SQSClient({ region: 'ap-northeast-1' }))
506
- * const driver = new SqsDriver(adapter, { queueUrl: process.env.SQS_QUEUE_URL! })
507
- * setQueueDriver(driver)
508
- *
509
- * // Dispatch jobs as usual
510
- * await SendEmailJob.dispatch({ to: 'user@example.com' })
511
- * ```
512
- */
393
+ /** AWS SQS queue driver for serverless deployments. */
513
394
  var SqsDriver = class {
514
395
  adapter;
515
396
  options;
@@ -601,9 +482,6 @@ var SqsDriver = class {
601
482
  return this.options.queueUrls?.[queue] ?? this.options.queueUrl;
602
483
  }
603
484
  };
604
- /**
605
- * Deserialize a JSON string into a QueuedJob, restoring Date objects.
606
- */
607
485
  function deserializeJob(body) {
608
486
  const raw = JSON.parse(body);
609
487
  return {
@@ -616,26 +494,8 @@ function deserializeJob(body) {
616
494
  //#endregion
617
495
  //#region src/queue/Worker.ts
618
496
  /**
619
- * Queue worker that processes jobs.
620
- *
621
- * @example
622
- * ```ts
623
- * import { Worker, MemoryDriver, setQueueDriver } from '@guren/server/queue'
624
- *
625
- * const driver = new MemoryDriver()
626
- * setQueueDriver(driver)
627
- *
628
- * const worker = new Worker(driver, {
629
- * queues: ['default', 'emails'],
630
- * sleep: 1000,
631
- * })
632
- *
633
- * // Start processing
634
- * await worker.start()
635
- *
636
- * // Stop gracefully
637
- * await worker.stop()
638
- * ```
497
+ * Pulls jobs off a driver's queues in priority order and runs each under a
498
+ * timeout, retrying through `driver.release()`.
639
499
  */
640
500
  var Worker = class {
641
501
  driver;
@@ -660,9 +520,6 @@ var Worker = class {
660
520
  this.timeout = options.timeout ?? 6e4;
661
521
  this.stopWhenEmpty = options.stopWhenEmpty ?? false;
662
522
  }
663
- /**
664
- * Start the worker.
665
- */
666
523
  async start() {
667
524
  if (this.running) return;
668
525
  this.running = true;
@@ -683,29 +540,17 @@ var Worker = class {
683
540
  this.running = false;
684
541
  this.events.workerStopped?.();
685
542
  }
686
- /**
687
- * Stop the worker gracefully.
688
- */
689
543
  async stop() {
690
544
  this.shouldStop = true;
691
545
  const startWait = Date.now();
692
546
  while (this.running && this.currentJob && Date.now() - startWait < this.timeout) await this.sleepMs(100);
693
547
  }
694
- /**
695
- * Check if the worker is running.
696
- */
697
548
  isRunning() {
698
549
  return this.running;
699
550
  }
700
- /**
701
- * Get the number of processed jobs.
702
- */
703
551
  getProcessedJobsCount() {
704
552
  return this.processedJobs;
705
553
  }
706
- /**
707
- * Get the next available job from the queues.
708
- */
709
554
  async getNextJob() {
710
555
  for (const queue of this.queues) {
711
556
  const job = await this.driver.pop(queue);
@@ -713,9 +558,6 @@ var Worker = class {
713
558
  }
714
559
  return null;
715
560
  }
716
- /**
717
- * Process a single job.
718
- */
719
561
  async processJob(job) {
720
562
  this.currentJob = job;
721
563
  job.attempts++;
@@ -737,9 +579,6 @@ var Worker = class {
737
579
  this.currentJob = null;
738
580
  }
739
581
  }
740
- /**
741
- * Handle a failed job.
742
- */
743
582
  async handleFailedJob(job, error, JobClass) {
744
583
  const willRetry = job.attempts < job.maxAttempts;
745
584
  if (willRetry) {
@@ -767,9 +606,6 @@ var Worker = class {
767
606
  }));
768
607
  this.events.jobFailed?.(job, error, willRetry);
769
608
  }
770
- /**
771
- * Execute a function with a timeout.
772
- */
773
609
  async executeWithTimeout(fn, timeoutMs) {
774
610
  return new Promise((resolve, reject) => {
775
611
  const timer = setTimeout(() => {
@@ -784,16 +620,11 @@ var Worker = class {
784
620
  });
785
621
  });
786
622
  }
787
- /**
788
- * Sleep for a given number of milliseconds.
789
- */
790
623
  sleepMs(ms) {
791
624
  return new Promise((resolve) => setTimeout(resolve, ms));
792
625
  }
793
626
  };
794
- /**
795
- * Process a single job (for testing or one-off execution).
796
- */
627
+ /** Process one job without a running worker, for tests and one-off execution. */
797
628
  async function processJob(driver, queue = "default") {
798
629
  const worker = new Worker(driver, {
799
630
  queues: [queue],
@@ -805,9 +636,6 @@ async function processJob(driver, queue = "default") {
805
636
  }
806
637
  //#endregion
807
638
  //#region src/queue/FailedJobReporter.ts
808
- /**
809
- * Default handler that writes structured JSON to stderr.
810
- */
811
639
  function defaultLogHandler(info) {
812
640
  console.error(JSON.stringify({
813
641
  level: "error",
@@ -821,33 +649,16 @@ function defaultLogHandler(info) {
821
649
  failedAt: info.failedAt.toISOString()
822
650
  }));
823
651
  }
824
- /**
825
- * Configurable reporter for failed queue jobs.
826
- *
827
- * Registered by default in QueueServiceProvider to log failures.
828
- * Can be extended with custom handlers (e.g., Sentry, Slack notifications).
829
- *
830
- * @example
831
- * ```ts
832
- * const reporter = new FailedJobReporter()
833
- *
834
- * // Add a custom handler alongside the default logger
835
- * reporter.onFailure(async (info) => {
836
- * await sendToSentry(info.error)
837
- * })
838
- * ```
839
- */
652
+ /** Registered by default in QueueServiceProvider; extend with custom handlers. */
840
653
  var FailedJobReporter = class {
841
654
  handlers = [];
842
655
  constructor() {
843
656
  this.handlers.push(defaultLogHandler);
844
657
  }
845
- /** Add a custom handler for failed jobs. */
846
658
  onFailure(handler) {
847
659
  this.handlers.push(handler);
848
660
  return this;
849
661
  }
850
- /** Report a job failure to all registered handlers. */
851
662
  async report(info) {
852
663
  for (const handler of this.handlers) try {
853
664
  await handler(info);
@@ -857,29 +668,8 @@ var FailedJobReporter = class {
857
668
  //#endregion
858
669
  //#region src/queue/QueueManager.ts
859
670
  /**
860
- * Queue manager for handling multiple queue drivers.
861
- *
862
- * @example
863
- * ```ts
864
- * import { QueueManager, MemoryDriver, RedisDriver } from '@guren/server/queue'
865
- * import { createRedisClient } from '@guren/server/redis'
866
- *
867
- * const redis = createRedisClient({ url: process.env.REDIS_URL })
868
- *
869
- * const queueManager = new QueueManager({
870
- * default: 'redis',
871
- * drivers: {
872
- * memory: () => new MemoryDriver(),
873
- * redis: () => new RedisDriver(redis),
874
- * }
875
- * })
876
- *
877
- * // Use the default driver
878
- * const driver = queueManager.driver()
879
- *
880
- * // Use a specific driver
881
- * const memoryDriver = queueManager.driver('memory')
882
- * ```
671
+ * Resolves queue drivers by name from the configured factories; `driver()` with
672
+ * no name returns the default and publishes it as the global driver.
883
673
  */
884
674
  var QueueManager = class {
885
675
  defaultDriver;
@@ -889,10 +679,6 @@ var QueueManager = class {
889
679
  this.defaultDriver = config.default ?? "memory";
890
680
  if (config.drivers) for (const [name, factory] of Object.entries(config.drivers)) this.driverFactories.set(name, factory);
891
681
  }
892
- /**
893
- * Get a queue driver by name.
894
- * Returns the default driver if no name is specified.
895
- */
896
682
  driver(name) {
897
683
  const driverName = name ?? this.defaultDriver;
898
684
  const cached = this.resolvedDrivers.get(driverName);
@@ -904,43 +690,29 @@ var QueueManager = class {
904
690
  if (driverName === this.defaultDriver) setQueueDriver(driver);
905
691
  return driver;
906
692
  }
907
- /**
908
- * Register a custom driver factory.
909
- */
910
693
  registerDriver(name, factory) {
911
694
  this.driverFactories.set(name, factory);
912
695
  this.resolvedDrivers.delete(name);
913
696
  }
914
- /**
915
- * Check if a driver is registered.
916
- */
917
697
  hasDriver(name) {
918
698
  return this.driverFactories.has(name);
919
699
  }
920
- /**
921
- * Get the default driver name.
922
- */
923
700
  getDefaultDriverName() {
924
701
  return this.defaultDriver;
925
702
  }
926
- /**
927
- * Get all registered driver names.
928
- */
929
703
  getDriverNames() {
930
704
  return Array.from(this.driverFactories.keys());
931
705
  }
932
706
  /**
933
- * Set the default driver and update global driver.
707
+ * After this, `driver()` with no name, `getDefaultDriverName()`, and
708
+ * `Job.dispatch()` all use the new driver.
934
709
  */
935
710
  setDefaultDriver(name) {
936
711
  if (!this.driverFactories.has(name)) throw new Error(`Queue driver not found: ${name}`);
937
- const driver = this.driver(name);
938
- setQueueDriver(driver);
712
+ this.defaultDriver = name;
713
+ setQueueDriver(this.driver(name));
939
714
  }
940
715
  };
941
- /**
942
- * Create a queue manager with default configuration.
943
- */
944
716
  function createQueueManager(config) {
945
717
  return new QueueManager(config);
946
718
  }
@@ -1,78 +1,26 @@
1
1
  import type { Redis } from 'ioredis';
2
2
  import type { ApiToken, ApiTokenStore } from '../auth/api-token.js';
3
- /**
4
- * Options for RedisApiTokenStore.
5
- */
6
3
  export interface RedisApiTokenStoreOptions {
7
- /**
8
- * Key prefix for token keys.
9
- * @default 'apitoken:'
10
- */
4
+ /** @default 'apitoken:' */
11
5
  prefix?: string;
12
6
  }
13
7
  /**
14
- * Redis-backed API token store.
15
- *
16
- * Uses the following key structure:
17
- * - `apitoken:{id}` - Token data (hash)
18
- * - `apitoken:hash:{hashedToken}` - Maps hash to token ID
19
- * - `apitoken:user:{userId}` - Set of token IDs for a user
20
- *
21
- * @example
22
- * ```ts
23
- * import { createRedisClient } from '@guren/server/redis'
24
- *
25
- * const redis = createRedisClient({ url: process.env.REDIS_URL })
26
- * const store = new RedisApiTokenStore(redis)
27
- *
28
- * const { plainTextToken } = await createApiToken(store, {
29
- * name: 'API Token',
30
- * userId: user.id,
31
- * })
32
- * ```
8
+ * Key layout: `apitoken:{id}` Hash of token data, `apitoken:hash:{hashedToken}`
9
+ * hash → token ID, `apitoken:user:{userId}` Set of a user's token IDs.
33
10
  */
34
11
  export declare class RedisApiTokenStore implements ApiTokenStore {
35
12
  private readonly redis;
36
13
  private readonly prefix;
37
14
  constructor(redis: Redis, options?: RedisApiTokenStoreOptions);
38
- /**
39
- * Store a new API token.
40
- */
41
15
  store(token: ApiToken): Promise<void>;
42
- /**
43
- * Find a token by its hashed value.
44
- */
45
16
  findByHashedToken(hashedToken: string): Promise<ApiToken | null>;
46
- /**
47
- * Find all tokens for a user.
48
- */
49
17
  findByUserId(userId: string | number): Promise<ApiToken[]>;
50
- /**
51
- * Delete a token by its ID.
52
- */
53
18
  delete(id: string): Promise<void>;
54
- /**
55
- * Delete all tokens for a user.
56
- */
57
19
  deleteForUser(userId: string | number): Promise<void>;
58
- /**
59
- * Update the last used timestamp.
60
- */
61
20
  updateLastUsed(id: string, timestamp: Date): Promise<void>;
62
- /**
63
- * Find a token by its ID.
64
- */
65
21
  private findById;
66
- /**
67
- * Serialize a token for Redis storage.
68
- */
69
22
  private serializeToken;
70
- /**
71
- * Deserialize a token from Redis storage.
72
- */
73
23
  private deserializeToken;
74
- /**
75
- * Clear all tokens (for testing).
76
- */
24
+ /** Testing only. */
77
25
  clear(): Promise<void>;
78
26
  }