stratal 0.0.16 → 0.0.18

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 (181) hide show
  1. package/README.md +4 -0
  2. package/dist/bin/cloudflare-workers-loader.mjs +33 -1
  3. package/dist/bin/cloudflare-workers-loader.mjs.map +1 -1
  4. package/dist/bin/quarry.mjs +183 -55
  5. package/dist/bin/quarry.mjs.map +1 -1
  6. package/dist/cache/index.d.mts +2 -2
  7. package/dist/cache/index.d.mts.map +1 -1
  8. package/dist/cache/index.mjs +3 -11
  9. package/dist/cache/index.mjs.map +1 -1
  10. package/dist/{colors-DJaRDXoS.mjs → colors-BTAnQRGU.mjs} +1 -1
  11. package/dist/{colors-DJaRDXoS.mjs.map → colors-BTAnQRGU.mjs.map} +1 -1
  12. package/dist/{command-B-QH-Vu3.d.mts → command-B1YuV-UZ.d.mts} +2 -2
  13. package/dist/{command-B-QH-Vu3.d.mts.map → command-B1YuV-UZ.d.mts.map} +1 -1
  14. package/dist/{command-BvCOD6df.mjs → command-DjGqCYHv.mjs} +7 -4
  15. package/dist/command-DjGqCYHv.mjs.map +1 -0
  16. package/dist/config/index.d.mts +2 -2
  17. package/dist/config/index.mjs +12 -20
  18. package/dist/config/index.mjs.map +1 -1
  19. package/dist/consumer-registry-BkuHXR_u.d.mts +142 -0
  20. package/dist/consumer-registry-BkuHXR_u.d.mts.map +1 -0
  21. package/dist/cron/index.d.mts +3 -116
  22. package/dist/cron/index.d.mts.map +1 -1
  23. package/dist/cron/index.mjs +1 -4
  24. package/dist/{cron-manager-DR7fiG6o.mjs → cron-manager-1KnZvojs.mjs} +3 -3
  25. package/dist/{cron-manager-DR7fiG6o.mjs.map → cron-manager-1KnZvojs.mjs.map} +1 -1
  26. package/dist/cron-manager-BnEZquBL.d.mts +117 -0
  27. package/dist/cron-manager-BnEZquBL.d.mts.map +1 -0
  28. package/dist/di/index.d.mts +2 -2
  29. package/dist/di/index.mjs +3 -4
  30. package/dist/email/index.d.mts +3 -3
  31. package/dist/email/index.mjs +8 -17
  32. package/dist/email/index.mjs.map +1 -1
  33. package/dist/{en-DaewN8hc.mjs → en-3QnZwP-u.mjs} +10 -1
  34. package/dist/en-3QnZwP-u.mjs.map +1 -0
  35. package/dist/errors/index.d.mts +2 -2
  36. package/dist/errors/index.mjs +2 -4
  37. package/dist/errors--RBIvDXr.mjs +1560 -0
  38. package/dist/errors--RBIvDXr.mjs.map +1 -0
  39. package/dist/{errors-H3TZnVeX.mjs → errors-B7hCnXgB.mjs} +2 -2
  40. package/dist/{errors-H3TZnVeX.mjs.map → errors-B7hCnXgB.mjs.map} +1 -1
  41. package/dist/events/index.d.mts +2 -2
  42. package/dist/events/index.mjs +1 -3
  43. package/dist/{events-CXl-o1Ad.mjs → events-UTJliZhl.mjs} +2 -3
  44. package/dist/{events-CXl-o1Ad.mjs.map → events-UTJliZhl.mjs.map} +1 -1
  45. package/dist/{gateway-context-BkZ4UKaX.mjs → gateway-context-BdBFoQd8.mjs} +66 -10
  46. package/dist/gateway-context-BdBFoQd8.mjs.map +1 -0
  47. package/dist/guards/index.d.mts +3 -3
  48. package/dist/guards/index.d.mts.map +1 -1
  49. package/dist/guards/index.mjs +1 -1
  50. package/dist/{guards-DUk_Kzst.mjs → guards-MtDgcHnF.mjs} +1 -1
  51. package/dist/{guards-DUk_Kzst.mjs.map → guards-MtDgcHnF.mjs.map} +1 -1
  52. package/dist/i18n/index.d.mts +3 -3
  53. package/dist/i18n/index.mjs +3 -16
  54. package/dist/i18n/messages/en/index.d.mts +1 -1
  55. package/dist/i18n/messages/en/index.mjs +1 -1
  56. package/dist/i18n/utils/index.d.mts +30 -0
  57. package/dist/i18n/utils/index.d.mts.map +1 -0
  58. package/dist/i18n/utils/index.mjs +2 -0
  59. package/dist/i18n/validation/index.d.mts +1 -1
  60. package/dist/i18n/validation/index.mjs +1 -1
  61. package/dist/i18n.module-BpLLLCTg.mjs +2462 -0
  62. package/dist/i18n.module-BpLLLCTg.mjs.map +1 -0
  63. package/dist/{index-D_w_Rmtd.d.mts → index-BDh9J2KD.d.mts} +10 -1
  64. package/dist/{index-D_w_Rmtd.d.mts.map → index-BDh9J2KD.d.mts.map} +1 -1
  65. package/dist/{index-Dp6A5ywM.d.mts → index-BR23zDMy.d.mts} +1 -1
  66. package/dist/{index-Dp6A5ywM.d.mts.map → index-BR23zDMy.d.mts.map} +1 -1
  67. package/dist/index-BrmS34sa.d.mts +4287 -0
  68. package/dist/index-BrmS34sa.d.mts.map +1 -0
  69. package/dist/{index-D9iYu2Yc.d.mts → index-DPxmo6AY.d.mts} +5 -144
  70. package/dist/index-DPxmo6AY.d.mts.map +1 -0
  71. package/dist/{index-DVhdhLvE.d.mts → index-Dfpd_ypO.d.mts} +38 -9
  72. package/dist/index-Dfpd_ypO.d.mts.map +1 -0
  73. package/dist/index.d.mts +4 -3
  74. package/dist/index.d.mts.map +1 -1
  75. package/dist/index.mjs +1 -20
  76. package/dist/{is-command-BfCgWAcQ.mjs → is-command-PvULqiTa.mjs} +2 -2
  77. package/dist/{is-command-BfCgWAcQ.mjs.map → is-command-PvULqiTa.mjs.map} +1 -1
  78. package/dist/{is-seeder-CebjZCDn.mjs → is-seeder-BN9Ej1r7.mjs} +1 -1
  79. package/dist/{is-seeder-CebjZCDn.mjs.map → is-seeder-BN9Ej1r7.mjs.map} +1 -1
  80. package/dist/logger/index.d.mts +1 -1
  81. package/dist/logger/index.mjs +1 -2
  82. package/dist/{logger-BR1-s1Um.mjs → logger-c0ftIK4G.mjs} +170 -4
  83. package/dist/logger-c0ftIK4G.mjs.map +1 -0
  84. package/dist/module/index.d.mts +3 -119
  85. package/dist/module/index.d.mts.map +1 -1
  86. package/dist/module/index.mjs +1 -11
  87. package/dist/module-C3YZ-kZN.mjs +719 -0
  88. package/dist/module-C3YZ-kZN.mjs.map +1 -0
  89. package/dist/openapi/index.d.mts +54 -54
  90. package/dist/openapi/index.d.mts.map +1 -1
  91. package/dist/openapi/index.mjs +3 -16
  92. package/dist/openapi-tools.service-B77QXD56.mjs +197 -0
  93. package/dist/openapi-tools.service-B77QXD56.mjs.map +1 -0
  94. package/dist/openapi.service-6yj0BUY4.d.mts +50 -0
  95. package/dist/openapi.service-6yj0BUY4.d.mts.map +1 -0
  96. package/dist/quarry/index.d.mts +124 -29
  97. package/dist/quarry/index.d.mts.map +1 -1
  98. package/dist/quarry/index.mjs +5 -7
  99. package/dist/quarry-registry-CQCIlYTO.mjs +686 -0
  100. package/dist/quarry-registry-CQCIlYTO.mjs.map +1 -0
  101. package/dist/queue/index.d.mts +2 -1
  102. package/dist/queue/index.mjs +3 -14
  103. package/dist/queue/index.mjs.map +1 -1
  104. package/dist/{queue.module-BZvmeAMj.mjs → queue.module-DIjD6nr-.mjs} +39 -42
  105. package/dist/queue.module-DIjD6nr-.mjs.map +1 -0
  106. package/dist/{resend.provider-BCCACQAU.mjs → resend.provider-Bvw36rQy.mjs} +1 -4
  107. package/dist/{resend.provider-BCCACQAU.mjs.map → resend.provider-Bvw36rQy.mjs.map} +1 -1
  108. package/dist/router/index.d.mts +2 -2
  109. package/dist/router/index.mjs +5 -16
  110. package/dist/{s3-storage.provider-BLlzQYiJ.mjs → s3-storage.provider-BAhHDMI3.mjs} +16 -9
  111. package/dist/s3-storage.provider-BAhHDMI3.mjs.map +1 -0
  112. package/dist/seeder/index.d.mts +3 -4
  113. package/dist/seeder/index.d.mts.map +1 -1
  114. package/dist/seeder/index.mjs +2 -7
  115. package/dist/{seeder-Cupi5jl-.mjs → seeder-D7VXULXB.mjs} +20 -17
  116. package/dist/seeder-D7VXULXB.mjs.map +1 -0
  117. package/dist/setup-BRIN-iYT.mjs +37 -0
  118. package/dist/setup-BRIN-iYT.mjs.map +1 -0
  119. package/dist/{smtp.provider-B8XtOcHU.mjs → smtp.provider-CAwpvzvD.mjs} +1 -4
  120. package/dist/{smtp.provider-B8XtOcHU.mjs.map → smtp.provider-CAwpvzvD.mjs.map} +1 -1
  121. package/dist/storage/index.d.mts +2 -195
  122. package/dist/storage/index.d.mts.map +1 -1
  123. package/dist/storage/index.mjs +2 -14
  124. package/dist/storage/providers/index.d.mts +273 -0
  125. package/dist/storage/providers/index.d.mts.map +1 -0
  126. package/dist/storage/providers/index.mjs +2 -0
  127. package/dist/{storage-By_ow2o_.mjs → storage-CJ-QOwNv.mjs} +8 -9
  128. package/dist/storage-CJ-QOwNv.mjs.map +1 -0
  129. package/dist/storage-provider.interface-YRtyYBxV.d.mts +203 -0
  130. package/dist/storage-provider.interface-YRtyYBxV.d.mts.map +1 -0
  131. package/dist/stratal-B7G4i9-N.mjs +502 -0
  132. package/dist/stratal-B7G4i9-N.mjs.map +1 -0
  133. package/dist/{types-DahElfUw.d.mts → types-CN0zONAZ.d.mts} +2 -2
  134. package/dist/types-CN0zONAZ.d.mts.map +1 -0
  135. package/dist/{usage-generator-C9hWziY4.mjs → usage-generator-Cl1HPlUp.mjs} +2 -2
  136. package/dist/{usage-generator-C9hWziY4.mjs.map → usage-generator-Cl1HPlUp.mjs.map} +1 -1
  137. package/dist/{validation-Bh875Lyg.mjs → validation-B4bePOa_.mjs} +5 -5
  138. package/dist/{validation-Bh875Lyg.mjs.map → validation-B4bePOa_.mjs.map} +1 -1
  139. package/dist/websocket/index.d.mts +2 -2
  140. package/dist/websocket/index.d.mts.map +1 -1
  141. package/dist/websocket/index.mjs +1 -5
  142. package/dist/workers/index.d.mts +1 -1
  143. package/dist/workers/index.d.mts.map +1 -1
  144. package/dist/workers/index.mjs +2 -20
  145. package/dist/workers/index.mjs.map +1 -1
  146. package/package.json +39 -31
  147. package/dist/application-zG8b-pol.d.mts +0 -116
  148. package/dist/application-zG8b-pol.d.mts.map +0 -1
  149. package/dist/command-BvCOD6df.mjs.map +0 -1
  150. package/dist/decorate-D5j-d9_z.mjs +0 -171
  151. package/dist/decorate-D5j-d9_z.mjs.map +0 -1
  152. package/dist/en-DaewN8hc.mjs.map +0 -1
  153. package/dist/errors-CtCi1wn6.mjs +0 -707
  154. package/dist/errors-CtCi1wn6.mjs.map +0 -1
  155. package/dist/gateway-context-BkZ4UKaX.mjs.map +0 -1
  156. package/dist/i18n.module-W8OJxg3d.mjs +0 -1791
  157. package/dist/i18n.module-W8OJxg3d.mjs.map +0 -1
  158. package/dist/index-BJWm863C.d.mts +0 -2616
  159. package/dist/index-BJWm863C.d.mts.map +0 -1
  160. package/dist/index-D9iYu2Yc.d.mts.map +0 -1
  161. package/dist/index-DVhdhLvE.d.mts.map +0 -1
  162. package/dist/logger-BR1-s1Um.mjs.map +0 -1
  163. package/dist/middleware/index.d.mts +0 -2
  164. package/dist/middleware/index.mjs +0 -6
  165. package/dist/middleware-C0Ebzswy.mjs +0 -362
  166. package/dist/middleware-C0Ebzswy.mjs.map +0 -1
  167. package/dist/module-BgdxxzBe.mjs +0 -370
  168. package/dist/module-BgdxxzBe.mjs.map +0 -1
  169. package/dist/quarry-registry-DCwqVcRp.mjs +0 -310
  170. package/dist/quarry-registry-DCwqVcRp.mjs.map +0 -1
  171. package/dist/queue.module-BZvmeAMj.mjs.map +0 -1
  172. package/dist/router-context-BEJe9HEB.mjs +0 -264
  173. package/dist/router-context-BEJe9HEB.mjs.map +0 -1
  174. package/dist/s3-storage.provider-BLlzQYiJ.mjs.map +0 -1
  175. package/dist/seeder-Cupi5jl-.mjs.map +0 -1
  176. package/dist/storage-By_ow2o_.mjs.map +0 -1
  177. package/dist/stratal-CE0iTz4f.mjs +0 -305
  178. package/dist/stratal-CE0iTz4f.mjs.map +0 -1
  179. package/dist/types-CLhOhYsQ.d.mts +0 -64
  180. package/dist/types-CLhOhYsQ.d.mts.map +0 -1
  181. package/dist/types-DahElfUw.d.mts.map +0 -1
@@ -1,4 +1,4 @@
1
- import { a as green, n as cyan, o as red, r as dim, s as yellow, t as bold } from "./colors-DJaRDXoS.mjs";
1
+ import { a as green, n as cyan, o as red, r as dim, s as yellow, t as bold } from "./colors-BTAnQRGU.mjs";
2
2
  import "reflect-metadata";
3
3
  //#region src/quarry/constants.ts
4
4
  /**
@@ -13,7 +13,7 @@ const COMMAND_INTERNALS = Symbol.for("stratal:command:internals");
13
13
  *
14
14
  * Quarry catches this in `call()` and puts the message into `CommandResult.errors`.
15
15
  * Does NOT extend `ApplicationError` (which requires i18n keys + error codes).
16
- * Not routed through GlobalErrorHandler.
16
+ * Not routed through ExceptionHandler.
17
17
  */
18
18
  var CommandError = class extends Error {
19
19
  constructor(message) {
@@ -184,10 +184,13 @@ var Command = class {
184
184
  async call(name, input) {
185
185
  const internals = this[COMMAND_INTERNALS];
186
186
  if (!internals.quarry) throw new CommandError("Cannot call commands: Quarry reference not set");
187
- return internals.quarry.call(name, input);
187
+ const result = await internals.quarry.call(name, input);
188
+ internals.output.push(...result.output);
189
+ internals.errors.push(...result.errors);
190
+ return result;
188
191
  }
189
192
  };
190
193
  //#endregion
191
194
  export { CommandError as n, COMMAND_INTERNALS as r, Command as t };
192
195
 
193
- //# sourceMappingURL=command-BvCOD6df.mjs.map
196
+ //# sourceMappingURL=command-DjGqCYHv.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-DjGqCYHv.mjs","names":[],"sources":["../src/quarry/constants.ts","../src/quarry/errors/command.error.ts","../src/quarry/command.ts"],"sourcesContent":["/**\n * Symbol key for storing internal mutable state on Command instances.\n * Keeps internal state hidden from user-facing autocomplete.\n */\nexport const COMMAND_INTERNALS = Symbol.for('stratal:command:internals')\n","/**\n * User-facing command error with a plain English message.\n *\n * Quarry catches this in `call()` and puts the message into `CommandResult.errors`.\n * Does NOT extend `ApplicationError` (which requires i18n keys + error codes).\n * Not routed through ExceptionHandler.\n */\nexport class CommandError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'CommandError'\n }\n}\n","import 'reflect-metadata'\n\nimport { bold, cyan, dim, green, red, yellow } from './colors'\nimport { COMMAND_INTERNALS } from './constants'\nimport { CommandError } from './errors/command.error'\nimport type { CommandInput, CommandInternals, CommandResult } from './types'\n\n/**\n * Abstract base class for Quarry commands.\n *\n * Subclasses define a static `command` signature string and implement `handle()`.\n *\n * @example\n * ```typescript\n * export class GreetCommand extends Command {\n * static command = 'greet {name : The name to greet} {--loud}'\n * static description = 'Greet someone'\n *\n * async handle(): Promise<void> {\n * const name = this.string('name')\n * const loud = this.boolean('loud')\n * this.info(loud ? `HELLO, ${name.toUpperCase()}!` : `Hello, ${name}!`)\n * }\n * }\n * ```\n */\nexport abstract class Command {\n /**\n * Laravel-style command signature string.\n *\n * **Command names:**\n * - `'greet'` — flat command (`quarry greet`)\n * - `'task add'` — subcommand hierarchy via spaces (`quarry task add`)\n * - `'task:add'` — namespaced flat command via colons (`quarry task:add`)\n *\n * **Arguments:**\n * - `{name}` — required argument\n * - `{name?}` — optional argument\n * - `{name=default}` — argument with default value\n * - `{name*}` — array/variadic argument\n * - `{name : description}` — argument with description\n *\n * **Options:**\n * - `{--flag}` — boolean flag\n * - `{--name=}` — option that accepts a value\n * - `{--name=default}` — option with default value\n * - `{--name=*}` — array option (multiple values)\n * - `{--A|name}` — option with single-char alias\n * - `{--name= : description}` — option with description\n *\n * @example\n * ```typescript\n * // Namespaced flat command: `quarry users:create ...`\n * static command = 'users:create {email : The user email} {--A|admin} {--R|role= : Assign a role}'\n *\n * // Subcommand hierarchy: `quarry users create ...`\n * static command = 'users create {email : The user email} {--A|admin} {--R|role= : Assign a role}'\n * ```\n */\n static command: string\n /** Human-readable description */\n static description?: string\n /** Alternative command names */\n static aliases?: string[];\n\n [COMMAND_INTERNALS]: CommandInternals\n\n constructor() {\n this[COMMAND_INTERNALS] = {\n inputs: {},\n output: [],\n errors: [],\n exitCode: 0,\n quarry: null,\n }\n }\n\n /**\n * Implement this method with the command's logic.\n * Return a number to set the exit code, or void for exit code 0.\n */\n // eslint-disable-next-line @typescript-eslint/no-invalid-void-type\n abstract handle(): number | void | Promise<number | void>\n\n // ── Input Accessors ──────────────────────────────────────────────\n\n /**\n * Get an input value with generic type.\n */\n input<T>(name: string): T {\n return this[COMMAND_INTERNALS].inputs[name] as T\n }\n\n /**\n * Get a string input. Throws CommandError if present but not a string.\n */\n string(name: string): string {\n const value = this[COMMAND_INTERNALS].inputs[name]\n if (value === undefined || value === null) {\n return ''\n }\n if (typeof value !== 'string') {\n throw new CommandError(`Input \"${name}\" expected a string, got ${typeof value}`)\n }\n return value\n }\n\n /**\n * Get a boolean input. Throws CommandError if present but not a boolean.\n */\n boolean(name: string): boolean {\n const value = this[COMMAND_INTERNALS].inputs[name]\n if (value === undefined || value === null) {\n return false\n }\n if (typeof value !== 'boolean') {\n throw new CommandError(`Input \"${name}\" expected a boolean, got ${typeof value}`)\n }\n return value\n }\n\n /**\n * Get a number input. Coerces strings to numbers. Throws CommandError on NaN.\n */\n number(name: string): number {\n const value = this[COMMAND_INTERNALS].inputs[name]\n if (value === undefined || value === null) {\n return 0\n }\n const num = typeof value === 'string' ? Number(value) : value\n if (typeof num !== 'number' || Number.isNaN(num)) {\n throw new CommandError(`Input \"${name}\" expected a number, got ${typeof value}`)\n }\n return num\n }\n\n /**\n * Get an array input. Throws CommandError if present but not an array.\n */\n array(name: string): string[] {\n const value = this[COMMAND_INTERNALS].inputs[name]\n if (value === undefined || value === null) {\n return []\n }\n if (!Array.isArray(value)) {\n throw new CommandError(`Input \"${name}\" expected an array, got ${typeof value}`)\n }\n return value as string[]\n }\n\n // ── Output Helpers ───────────────────────────────────────────────\n\n /** Write an informational message to output */\n info(message: string): void {\n this[COMMAND_INTERNALS].output.push(cyan(message))\n }\n\n /** Write a success message to output */\n success(message: string): void {\n this[COMMAND_INTERNALS].output.push(`${green(bold('✔'))} ${green(message)}`)\n }\n\n /** Write a warning message to output */\n warn(message: string): void {\n this[COMMAND_INTERNALS].output.push(`${yellow(bold('⚠'))} ${yellow(message)}`)\n }\n\n /** Write an error message to errors */\n error(message: string): void {\n this[COMMAND_INTERNALS].errors.push(red(message))\n }\n\n /** Write a plain line to output */\n line(message?: string): void {\n this[COMMAND_INTERNALS].output.push(message ?? '')\n }\n\n /** Write an empty line to output */\n newLine(): void {\n this[COMMAND_INTERNALS].output.push('')\n }\n\n /** Write a comment-style line to output */\n comment(message: string): void {\n this[COMMAND_INTERNALS].output.push(dim(`// ${message}`))\n }\n\n /** Write a formatted table to output */\n table(headers: string[], rows: string[][]): void {\n const colWidths = headers.map((h, i) => {\n const maxRow = rows.reduce((max, row) => Math.max(max, (row[i] ?? '').length), 0)\n return Math.max(h.length, maxRow)\n })\n\n const formatRow = (cells: string[]) =>\n cells.map((cell, i) => cell.padEnd(colWidths[i])).join(' ')\n\n this[COMMAND_INTERNALS].output.push(bold(formatRow(headers)))\n this[COMMAND_INTERNALS].output.push(dim(colWidths.map((w) => '-'.repeat(w)).join(' ')))\n for (const row of rows) {\n this[COMMAND_INTERNALS].output.push(formatRow(row))\n }\n }\n\n /** Write an error message and set exit code */\n fail(message: string, exitCode = 1): void {\n this[COMMAND_INTERNALS].errors.push(`${red(bold('✖'))} ${red(message)}`)\n this[COMMAND_INTERNALS].exitCode = exitCode\n }\n\n // ── Command Calling ──────────────────────────────────────────────\n\n /**\n * Call another command from within this command.\n * Delegates to Quarry.call() via internal reference.\n */\n async call(name: string, input?: CommandInput): Promise<CommandResult> {\n const internals = this[COMMAND_INTERNALS]\n if (!internals.quarry) {\n throw new CommandError('Cannot call commands: Quarry reference not set')\n }\n const result = await internals.quarry.call(name, input)\n\n // Forward child output/errors into parent (like Clipanion context switches)\n internals.output.push(...result.output)\n internals.errors.push(...result.errors)\n\n return result\n }\n}\n"],"mappings":";;;;;;;AAIA,MAAa,oBAAoB,OAAO,IAAI,4BAA4B;;;;;;;;;;ACGxE,IAAa,eAAb,cAAkC,MAAM;CACtC,YAAY,SAAiB;AAC3B,QAAM,QAAQ;AACd,OAAK,OAAO;;;;;;;;;;;;;;;;;;;;;;;;ACgBhB,IAAsB,UAAtB,MAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC5B,OAAO;;CAEP,OAAO;;CAEP,OAAO;CAEP,CAAC;CAED,cAAc;AACZ,OAAK,qBAAqB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AAC,UAAU,OACb,OAAM,IAAI,aAAa,iDAAiD;EAE1E,MAAM,SAAS,MAAM,UAAU,OAAO,KAAK,MAAM,MAAM;AAGvD,YAAU,OAAO,KAAK,GAAG,OAAO,OAAO;AACvC,YAAU,OAAO,KAAK,GAAG,OAAO,OAAO;AAEvC,SAAO"}
@@ -1,5 +1,5 @@
1
- import { dt as OnInitialize, it as DynamicModule, lt as ModuleContext, ot as FactoryProvider } from "../index-BJWm863C.mjs";
2
- import { o as z } from "../index-DVhdhLvE.mjs";
1
+ import { Sn as OnInitialize, gn as FactoryProvider, mn as DynamicModule, yn as ModuleContext } from "../index-BrmS34sa.mjs";
2
+ import { o as z } from "../index-Dfpd_ypO.mjs";
3
3
  import { InjectionToken } from "tsyringe";
4
4
 
5
5
  //#region src/config/config.tokens.d.ts
@@ -1,17 +1,18 @@
1
- import { S as ApplicationError, b as ERROR_CODES, s as Scope } from "../errors-CtCi1wn6.mjs";
2
- import { i as Transient, l as DI_TOKENS, t as __decorate } from "../decorate-D5j-d9_z.mjs";
3
- import "../logger-BR1-s1Um.mjs";
4
- import { r as Module } from "../module-BgdxxzBe.mjs";
5
- import "../events-CXl-o1Ad.mjs";
6
- import "../colors-DJaRDXoS.mjs";
7
- import "../command-BvCOD6df.mjs";
8
- import "../is-command-BfCgWAcQ.mjs";
9
- import "../is-seeder-CebjZCDn.mjs";
10
- import "../middleware-C0Ebzswy.mjs";
11
- import "../router-context-BEJe9HEB.mjs";
1
+ import { A as Scope, H as ApplicationError, k as ERROR_CODES } from "../errors--RBIvDXr.mjs";
2
+ import { a as __decorate, f as DI_TOKENS, p as Transient } from "../logger-c0ftIK4G.mjs";
3
+ import { S as Module } from "../module-C3YZ-kZN.mjs";
12
4
  //#region src/config/config.tokens.ts
13
5
  const CONFIG_TOKENS = { ConfigService: Symbol.for("stratal:config:service") };
14
6
  //#endregion
7
+ //#region src/config/config.types.ts
8
+ var ConfigValidationError = class extends Error {
9
+ constructor(message, errors) {
10
+ super(message);
11
+ this.errors = errors;
12
+ this.name = "ConfigValidationError";
13
+ }
14
+ };
15
+ //#endregion
15
16
  //#region src/config/errors/config-module-not-initialized.error.ts
16
17
  /**
17
18
  * Error thrown when ConfigModule's onInitialize runs but forRoot() was never called.
@@ -38,15 +39,6 @@ var ConfigNotInitializedError = class extends ApplicationError {
38
39
  }
39
40
  };
40
41
  //#endregion
41
- //#region src/config/config.types.ts
42
- var ConfigValidationError = class extends Error {
43
- constructor(message, errors) {
44
- super(message);
45
- this.errors = errors;
46
- this.name = "ConfigValidationError";
47
- }
48
- };
49
- //#endregion
50
42
  //#region src/config/services/config.service.ts
51
43
  let ConfigService = class ConfigService {
52
44
  originalConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/config/config.tokens.ts","../../src/config/errors/config-module-not-initialized.error.ts","../../src/config/errors/config-not-initialized.error.ts","../../src/config/config.types.ts","../../src/config/services/config.service.ts","../../src/config/config.module.ts","../../src/config/register-as.ts"],"sourcesContent":["export const CONFIG_TOKENS = {\n\tConfigService: Symbol.for('stratal:config:service'),\n} as const\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * Error thrown when ConfigModule's onInitialize runs but forRoot() was never called.\n *\n * This means the module was imported without calling ConfigModule.forRoot({ load: [...] }).\n */\nexport class ConfigModuleNotInitializedError extends ApplicationError {\n constructor() {\n super(\n 'errors.configModuleNotInitialized',\n ERROR_CODES.SYSTEM.CONFIG_MODULE_NOT_INITIALIZED\n )\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\n/**\n * ConfigNotInitializedError\n *\n * Thrown when attempting to access ConfigService before it has been initialized.\n * This typically indicates that ConfigModule's onInitialize hook hasn't run yet,\n * or the module wasn't registered properly.\n */\nexport class ConfigNotInitializedError extends ApplicationError {\n constructor() {\n super(\n 'errors.configNotInitialized',\n ERROR_CODES.SYSTEM.CONFIG_NOT_INITIALIZED\n )\n }\n}\n","import type { z } from '../i18n/validation'\n\nexport class ConfigValidationError extends Error {\n constructor(\n message: string,\n public readonly errors: z.ZodError\n ) {\n super(message)\n this.name = 'ConfigValidationError'\n }\n}\n\n/**\n * Configuration that can be augmented by applications\n * Apps should augment this interface with their AppConfig type using module augmentation\n *\n * @example\n * ```typescript\n * // In your app (e.g., apps/backend/src/config/types.ts)\n * declare module 'stratal' {\n * interface ModuleConfig {\n * database: { url: string; maxConnections: number }\n * email: { provider: string; from: { name: string; email: string } }\n * }\n * }\n * ```\n */\nexport interface ModuleConfig { }\n\n/**\n * Generate all valid dot-notation paths from a config object type\n * @example ConfigPath<{ database: { url: string } }> = 'database' | 'database.url'\n */\nexport type ConfigPath<T> = {\n [K in keyof T & string]: T[K] extends Record<string, unknown>\n ? K | `${K}.${ConfigPath<T[K]>}`\n : K\n}[keyof T & string]\n\n/**\n * Get the value type at a dot-notation path\n * @example ConfigPathValue<{ database: { url: string } }, 'database.url'> = string\n */\nexport type ConfigPathValue<T, P extends string> = P extends `${infer K}.${infer Rest}`\n ? K extends keyof T\n ? T[K] extends Record<string, unknown>\n ? ConfigPathValue<T[K], Rest>\n : never\n : never\n : P extends keyof T\n ? T[P]\n : never\n\n/**\n * ConfigService interface with dot notation support\n */\nexport interface IConfigService<T extends object = ModuleConfig> {\n /**\n * Initialize the config service with validated configuration\n * Should be called once during application startup\n */\n initialize(config: T): void\n\n /**\n * Get config value using dot notation\n * @example config.get('database.url')\n */\n get<P extends ConfigPath<T>>(path: P): ConfigPathValue<T, P>\n\n /**\n * Set config value at runtime (for runtime overrides)\n * @example config.set('email.from.name', 'Custom Name')\n */\n set<P extends ConfigPath<T>>(path: P, value: ConfigPathValue<T, P>): void\n\n /**\n * Reset config to original value\n * @param path - Optional path to reset (resets entire config if omitted)\n */\n reset(path?: ConfigPath<T>): void\n\n /**\n * Get entire config object\n */\n all(): Readonly<T>\n\n /**\n * Check if a config path exists\n */\n has(path: ConfigPath<T>): boolean\n}\n","import { Transient } from '../../di/decorators'\nimport { CONFIG_TOKENS } from '../config.tokens'\nimport type { ConfigPath, ConfigPathValue, IConfigService, ModuleConfig } from '../config.types'\nimport { ConfigNotInitializedError } from '../errors'\n\n/**\n * ConfigService with dot notation support for get/set operations\n *\n * Supports runtime overrides via set() - useful for request-specific config overrides.\n * Use reset() to restore original values.\n *\n * @example\n * ```typescript\n * // Get with dot notation\n * const url = config.get('database.url')\n * const fromName = config.get('email.from.name')\n *\n * // Set at runtime (e.g., in middleware for runtime override)\n * config.set('email.from.name', 'Custom Name')\n *\n * // Reset to original\n * config.reset('email.from.name') // reset specific path\n * config.reset() // reset entire config\n * ```\n */\n@Transient(CONFIG_TOKENS.ConfigService)\nexport class ConfigService<T extends object = ModuleConfig> implements IConfigService<T> {\n private originalConfig: T | undefined\n private currentConfig: T | undefined\n\n /**\n * Initialize the config service with validated configuration\n * Called by ConfigModule during initialization\n */\n initialize(config: T): void {\n this.originalConfig = this.deepClone(config)\n this.currentConfig = this.deepClone(config)\n }\n\n /**\n * Get config value using dot notation\n * @example config.get('database.url')\n */\n get<P extends ConfigPath<T>>(path: P): ConfigPathValue<T, P> {\n this.ensureInitialized()\n return this.getByPath(this.currentConfig, path) as ConfigPathValue<T, P>\n }\n\n /**\n * Set config value at runtime (for runtime overrides)\n * @example config.set('email.from.name', 'Custom Name')\n */\n set<P extends ConfigPath<T>>(path: P, value: ConfigPathValue<T, P>): void {\n this.ensureInitialized()\n this.setByPath(this.currentConfig, path, value)\n }\n\n /**\n * Reset config to original value\n * @param path - Optional path to reset (resets entire config if omitted)\n */\n reset(path?: ConfigPath<T>): void {\n this.ensureInitialized()\n if (path) {\n const originalValue = this.getByPath(this.originalConfig, path)\n this.setByPath(this.currentConfig, path, this.deepClone(originalValue))\n } else {\n this.currentConfig = this.deepClone(this.originalConfig)\n }\n }\n\n /**\n * Get entire config object\n */\n all(): Readonly<T> {\n this.ensureInitialized()\n return this.currentConfig as Readonly<T>\n }\n\n /**\n * Check if a config path exists\n */\n has(path: ConfigPath<T>): boolean {\n this.ensureInitialized()\n return this.getByPath(this.currentConfig, path) !== undefined\n }\n\n private getByPath(obj: unknown, path: string): unknown {\n const keys = path.split('.')\n let current = obj\n for (const key of keys) {\n if (this.isDangerousKey(key)) return undefined\n if (current === null || current === undefined) return undefined\n current = (current as Record<string, unknown>)[key]\n }\n return current\n }\n\n private setByPath(obj: unknown, path: string, value: unknown): void {\n const keys = path.split('.')\n if (keys.some((key) => this.isDangerousKey(key))) return\n let current = obj as Record<string, unknown>\n for (let i = 0; i < keys.length - 1; i++) {\n const key = keys[i]\n if (!Object.hasOwn(current, key) || typeof current[key] !== 'object' || current[key] === null) {\n Object.defineProperty(current, key, {\n value: {},\n writable: true,\n enumerable: true,\n configurable: true,\n })\n }\n current = current[key] as Record<string, unknown>\n }\n Object.defineProperty(current, keys[keys.length - 1], {\n value,\n writable: true,\n enumerable: true,\n configurable: true,\n })\n }\n\n private isDangerousKey(key: string): boolean {\n return key === '__proto__' || key === 'constructor' || key === 'prototype'\n }\n\n private ensureInitialized(): void {\n if (!this.currentConfig) {\n throw new ConfigNotInitializedError()\n }\n }\n\n private deepClone<V>(obj: V): V {\n if (obj === null || typeof obj !== 'object') {\n return obj\n }\n return JSON.parse(JSON.stringify(obj)) as V\n }\n}\n","import type { z } from '../i18n/validation'\nimport { ConfigModuleNotInitializedError } from './errors'\nimport { DI_TOKENS } from '../di/tokens'\nimport { Scope } from '../di/types'\nimport { Module } from '../module'\nimport type { DynamicModule, ModuleContext, OnInitialize, Provider } from '../module/types'\nimport { CONFIG_TOKENS } from './config.tokens'\nimport { ConfigValidationError, ModuleConfig } from './config.types'\nimport type { ConfigNamespace } from './register-as'\nimport { ConfigService } from './services/config.service'\n\n/**\n * Any config namespace - uses structural typing for flexibility\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyConfigNamespace = ConfigNamespace<string, any, object>\n\n/**\n * Options for ConfigModule.forRoot\n */\nexport interface ConfigModuleOptions {\n /**\n * Array of config namespaces created via registerAs()\n */\n load: AnyConfigNamespace[]\n\n /**\n * Optional Zod schema for validating the merged config\n * Validates the entire config object after all namespaces are merged\n */\n validateSchema?: z.ZodType<object>\n}\n\n// Store options for use in onInitialize\nlet moduleOptions: ConfigModuleOptions | null = null\n\n/**\n * ConfigModule\n *\n * Provides configuration management with namespace support.\n * Uses registerAs() to create typed config namespaces that can be injected.\n *\n * @example\n * ```typescript\n * // Define config namespaces\n * const databaseConfig = registerAs('database', (env) => ({\n * url: env.DATABASE_URL,\n * maxConnections: 10\n * }))\n *\n * const emailConfig = registerAs('email', (env) => ({\n * provider: env.EMAIL_PROVIDER,\n * from: { name: 'App', email: 'noreply@example.com' }\n * }))\n *\n * // Register in module\n * @Module({\n * imports: [\n * ConfigModule.forRoot({\n * load: [databaseConfig, emailConfig],\n * validateSchema: AppConfigSchema\n * })\n * ]\n * })\n * export class AppModule {}\n *\n * // Inject config\n * constructor(\n * @inject(CONFIG_TOKENS.ConfigService) private config: IConfigService,\n * @inject(databaseConfig.KEY) private dbConfig: DatabaseConfig\n * ) {\n * // Use dot notation\n * const url = this.config.get('database.url')\n *\n * // Or inject namespace directly\n * const url = this.dbConfig.url\n * }\n * ```\n */\n@Module({\n providers: [\n // Register the main ConfigService as Singleton so initialization persists\n {\n provide: CONFIG_TOKENS.ConfigService,\n useClass: ConfigService,\n scope: Scope.Singleton,\n },\n ],\n})\nexport class ConfigModule implements OnInitialize {\n /**\n * Configure ConfigModule with namespace loaders\n *\n * @param options - Configuration options\n * @returns Dynamic module with config infrastructure\n */\n static forRoot(options: ConfigModuleOptions): DynamicModule {\n moduleOptions = options\n\n const providers: Provider[] = []\n\n // Register each namespace config using asProvider()\n for (const namespace of options.load) {\n providers.push(namespace.asProvider())\n }\n\n return {\n module: ConfigModule,\n providers,\n }\n }\n\n /**\n * Initialize config service with merged namespaces\n * Called after all providers are registered\n */\n onInitialize(context: ModuleContext): void {\n if (!moduleOptions) {\n throw new ConfigModuleNotInitializedError()\n }\n\n const env = context.container.resolve<unknown>(DI_TOKENS.CloudflareEnv)\n const configService = context.container.resolve<ConfigService>(CONFIG_TOKENS.ConfigService)\n\n // Build merged config from all namespaces\n const mergedConfig: Record<string, unknown> = {}\n\n for (const namespace of moduleOptions.load) {\n mergedConfig[namespace.namespace] = namespace.factory(env)\n }\n\n // Validate if schema provided\n if (moduleOptions.validateSchema) {\n const result = moduleOptions.validateSchema.safeParse(mergedConfig)\n if (!result.success) {\n throw new ConfigValidationError(\n 'Configuration validation failed',\n result.error\n )\n }\n }\n\n // Initialize ConfigService with merged config\n configService.initialize(mergedConfig as ModuleConfig)\n\n context.logger.debug('ConfigModule initialized', {\n namespaces: moduleOptions.load.map((n) => n.namespace),\n })\n }\n}\n","import type { InjectionToken } from 'tsyringe'\nimport { DI_TOKENS } from '../di/tokens'\nimport type { FactoryProvider } from '../module/types'\n\n/**\n * Configuration namespace registration result\n */\nexport interface ConfigNamespace<TKey extends string, TEnv, TConfig extends object> {\n /** Auto-derived injection token (e.g., 'database' -> Symbol('stratal:config:database')) */\n readonly KEY: InjectionToken<TConfig>\n /** The namespace key */\n readonly namespace: TKey\n /** The factory function that receives env and returns config */\n readonly factory: (env: TEnv) => TConfig\n /**\n * Returns a provider configuration for use in module registration\n * Automatically injects DI_TOKENS.CloudflareEnv\n */\n asProvider(): FactoryProvider<TConfig>\n}\n\n/**\n * Create a namespaced configuration factory\n * Similar to NestJS registerAs\n *\n * @param namespace - Configuration namespace (e.g., 'database', 'email')\n * @param factory - Factory function receiving env and returning config object\n * @returns ConfigNamespace with token, factory, and asProvider() method\n *\n * @example\n * ```typescript\n * // apps/backend/src/config/database.config.ts\n * export const databaseConfig = registerAs('database', (env: Env) => ({\n * url: env.DATABASE_URL,\n * maxConnections: parseInt(env.DATABASE_MAX_CONNECTIONS || '10'),\n * }))\n *\n * // Auto-generates: databaseConfig.KEY = Symbol('stratal:config:database')\n *\n * // Usage in module:\n * // Option 1: Manual provider\n * {\n * provide: databaseConfig.KEY,\n * useFactory: databaseConfig.factory,\n * inject: [DI_TOKENS.CloudflareEnv]\n * }\n *\n * // Option 2: asProvider() helper\n * databaseConfig.asProvider()\n * // Returns: { provide: databaseConfig.KEY, useFactory: ..., inject: [DI_TOKENS.CloudflareEnv] }\n * ```\n */\nexport function registerAs<TKey extends string, TEnv, TConfig extends object>(\n namespace: TKey,\n factory: (env: TEnv) => TConfig\n): ConfigNamespace<TKey, TEnv, TConfig> {\n const KEY = Symbol.for(`stratal:config:${namespace}`) as InjectionToken<TConfig>\n\n return {\n KEY,\n namespace,\n factory,\n asProvider(): FactoryProvider<TConfig> {\n return {\n provide: KEY,\n useFactory: factory,\n inject: [DI_TOKENS.CloudflareEnv],\n }\n },\n }\n}\n\n/**\n * Helper to derive config type from registerAs result\n *\n * @example\n * ```typescript\n * const databaseConfig = registerAs('database', (env) => ({ url: env.DATABASE_URL }))\n * type DatabaseConfig = InferConfigType<typeof databaseConfig>\n * // { url: string }\n * ```\n */\nexport type InferConfigType<T> = T extends ConfigNamespace<string, unknown, infer C> ? C : never\n"],"mappings":";;;;;;;;;;;;AAAA,MAAa,gBAAgB,EAC5B,eAAe,OAAO,IAAI,yBAAyB,EACnD;;;;;;;;ACKD,IAAa,kCAAb,cAAqD,iBAAiB;CACpE,cAAc;AACZ,QACE,qCACA,YAAY,OAAO,8BACpB;;;;;;;;;;;;ACFL,IAAa,4BAAb,cAA+C,iBAAiB;CAC9D,cAAc;AACZ,QACE,+BACA,YAAY,OAAO,uBACpB;;;;;ACbL,IAAa,wBAAb,cAA2C,MAAM;CAC/C,YACE,SACA,QACA;AACA,QAAM,QAAQ;AAFE,OAAA,SAAA;AAGhB,OAAK,OAAO;;;;;ACkBT,IAAA,gBAAA,MAAM,cAA4E;CACvF;CACA;;;;;CAMA,WAAW,QAAiB;AAC1B,OAAK,iBAAiB,KAAK,UAAU,OAAO;AAC5C,OAAK,gBAAgB,KAAK,UAAU,OAAO;;;;;;CAO7C,IAA6B,MAAgC;AAC3D,OAAK,mBAAmB;AACxB,SAAO,K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ACF,CAAC,CAAA,EAAA,aAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpCF,SAAgB,WACd,WACA,SACsC;CACtC,MAAM,MAAM,OAAO,IAAI,kBAAkB,YAAY;AAErD,QAAO;EACL;EACA;EACA;EACA,aAAuC;AACrC,UAAO;IACL,SAAS;IACT,YAAY;IACZ,QAAQ,CAAC,UAAU,cAAc;IAClC;;EAEJ"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/config/config.tokens.ts","../../src/config/config.types.ts","../../src/config/errors/config-module-not-initialized.error.ts","../../src/config/errors/config-not-initialized.error.ts","../../src/config/services/config.service.ts","../../src/config/config.module.ts","../../src/config/register-as.ts"],"sourcesContent":["export const CONFIG_TOKENS = {\n\tConfigService: Symbol.for('stratal:config:service'),\n} as const\n","import type { z } from '../i18n/validation'\n\nexport class ConfigValidationError extends Error {\n constructor(\n message: string,\n public readonly errors: z.ZodError\n ) {\n super(message)\n this.name = 'ConfigValidationError'\n }\n}\n\n/**\n * Configuration that can be augmented by applications\n * Apps should augment this interface with their AppConfig type using module augmentation\n *\n * @example\n * ```typescript\n * // In your app (e.g., apps/backend/src/config/types.ts)\n * declare module 'stratal' {\n * interface ModuleConfig {\n * database: { url: string; maxConnections: number }\n * email: { provider: string; from: { name: string; email: string } }\n * }\n * }\n * ```\n */\nexport interface ModuleConfig { }\n\n/**\n * Generate all valid dot-notation paths from a config object type\n * @example ConfigPath<{ database: { url: string } }> = 'database' | 'database.url'\n */\nexport type ConfigPath<T> = {\n [K in keyof T & string]: T[K] extends Record<string, unknown>\n ? K | `${K}.${ConfigPath<T[K]>}`\n : K\n}[keyof T & string]\n\n/**\n * Get the value type at a dot-notation path\n * @example ConfigPathValue<{ database: { url: string } }, 'database.url'> = string\n */\nexport type ConfigPathValue<T, P extends string> = P extends `${infer K}.${infer Rest}`\n ? K extends keyof T\n ? T[K] extends Record<string, unknown>\n ? ConfigPathValue<T[K], Rest>\n : never\n : never\n : P extends keyof T\n ? T[P]\n : never\n\n/**\n * ConfigService interface with dot notation support\n */\nexport interface IConfigService<T extends object = ModuleConfig> {\n /**\n * Initialize the config service with validated configuration\n * Should be called once during application startup\n */\n initialize(config: T): void\n\n /**\n * Get config value using dot notation\n * @example config.get('database.url')\n */\n get<P extends ConfigPath<T>>(path: P): ConfigPathValue<T, P>\n\n /**\n * Set config value at runtime (for runtime overrides)\n * @example config.set('email.from.name', 'Custom Name')\n */\n set<P extends ConfigPath<T>>(path: P, value: ConfigPathValue<T, P>): void\n\n /**\n * Reset config to original value\n * @param path - Optional path to reset (resets entire config if omitted)\n */\n reset(path?: ConfigPath<T>): void\n\n /**\n * Get entire config object\n */\n all(): Readonly<T>\n\n /**\n * Check if a config path exists\n */\n has(path: ConfigPath<T>): boolean\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * Error thrown when ConfigModule's onInitialize runs but forRoot() was never called.\n *\n * This means the module was imported without calling ConfigModule.forRoot({ load: [...] }).\n */\nexport class ConfigModuleNotInitializedError extends ApplicationError {\n constructor() {\n super(\n 'errors.configModuleNotInitialized',\n ERROR_CODES.SYSTEM.CONFIG_MODULE_NOT_INITIALIZED\n )\n }\n}\n","import { ERROR_CODES } from '../../errors'\nimport { ApplicationError } from '../../errors'\n\n/**\n * ConfigNotInitializedError\n *\n * Thrown when attempting to access ConfigService before it has been initialized.\n * This typically indicates that ConfigModule's onInitialize hook hasn't run yet,\n * or the module wasn't registered properly.\n */\nexport class ConfigNotInitializedError extends ApplicationError {\n constructor() {\n super(\n 'errors.configNotInitialized',\n ERROR_CODES.SYSTEM.CONFIG_NOT_INITIALIZED\n )\n }\n}\n","import { Transient } from '../../di/decorators'\nimport { CONFIG_TOKENS } from '../config.tokens'\nimport type { ConfigPath, ConfigPathValue, IConfigService, ModuleConfig } from '../config.types'\nimport { ConfigNotInitializedError } from '../errors'\n\n/**\n * ConfigService with dot notation support for get/set operations\n *\n * Supports runtime overrides via set() - useful for request-specific config overrides.\n * Use reset() to restore original values.\n *\n * @example\n * ```typescript\n * // Get with dot notation\n * const url = config.get('database.url')\n * const fromName = config.get('email.from.name')\n *\n * // Set at runtime (e.g., in middleware for runtime override)\n * config.set('email.from.name', 'Custom Name')\n *\n * // Reset to original\n * config.reset('email.from.name') // reset specific path\n * config.reset() // reset entire config\n * ```\n */\n@Transient(CONFIG_TOKENS.ConfigService)\nexport class ConfigService<T extends object = ModuleConfig> implements IConfigService<T> {\n private originalConfig: T | undefined\n private currentConfig: T | undefined\n\n /**\n * Initialize the config service with validated configuration\n * Called by ConfigModule during initialization\n */\n initialize(config: T): void {\n this.originalConfig = this.deepClone(config)\n this.currentConfig = this.deepClone(config)\n }\n\n /**\n * Get config value using dot notation\n * @example config.get('database.url')\n */\n get<P extends ConfigPath<T>>(path: P): ConfigPathValue<T, P> {\n this.ensureInitialized()\n return this.getByPath(this.currentConfig, path) as ConfigPathValue<T, P>\n }\n\n /**\n * Set config value at runtime (for runtime overrides)\n * @example config.set('email.from.name', 'Custom Name')\n */\n set<P extends ConfigPath<T>>(path: P, value: ConfigPathValue<T, P>): void {\n this.ensureInitialized()\n this.setByPath(this.currentConfig, path, value)\n }\n\n /**\n * Reset config to original value\n * @param path - Optional path to reset (resets entire config if omitted)\n */\n reset(path?: ConfigPath<T>): void {\n this.ensureInitialized()\n if (path) {\n const originalValue = this.getByPath(this.originalConfig, path)\n this.setByPath(this.currentConfig, path, this.deepClone(originalValue))\n } else {\n this.currentConfig = this.deepClone(this.originalConfig)\n }\n }\n\n /**\n * Get entire config object\n */\n all(): Readonly<T> {\n this.ensureInitialized()\n return this.currentConfig as Readonly<T>\n }\n\n /**\n * Check if a config path exists\n */\n has(path: ConfigPath<T>): boolean {\n this.ensureInitialized()\n return this.getByPath(this.currentConfig, path) !== undefined\n }\n\n private getByPath(obj: unknown, path: string): unknown {\n const keys = path.split('.')\n let current = obj\n for (const key of keys) {\n if (this.isDangerousKey(key)) return undefined\n if (current === null || current === undefined) return undefined\n current = (current as Record<string, unknown>)[key]\n }\n return current\n }\n\n private setByPath(obj: unknown, path: string, value: unknown): void {\n const keys = path.split('.')\n if (keys.some((key) => this.isDangerousKey(key))) return\n let current = obj as Record<string, unknown>\n for (let i = 0; i < keys.length - 1; i++) {\n const key = keys[i]\n if (!Object.hasOwn(current, key) || typeof current[key] !== 'object' || current[key] === null) {\n Object.defineProperty(current, key, {\n value: {},\n writable: true,\n enumerable: true,\n configurable: true,\n })\n }\n current = current[key] as Record<string, unknown>\n }\n Object.defineProperty(current, keys[keys.length - 1], {\n value,\n writable: true,\n enumerable: true,\n configurable: true,\n })\n }\n\n private isDangerousKey(key: string): boolean {\n return key === '__proto__' || key === 'constructor' || key === 'prototype'\n }\n\n private ensureInitialized(): void {\n if (!this.currentConfig) {\n throw new ConfigNotInitializedError()\n }\n }\n\n private deepClone<V>(obj: V): V {\n if (obj === null || typeof obj !== 'object') {\n return obj\n }\n return JSON.parse(JSON.stringify(obj)) as V\n }\n}\n","import { DI_TOKENS } from '../di/tokens'\nimport { Scope } from '../di/types'\nimport type { z } from '../i18n/validation'\nimport { Module } from '../module'\nimport type { DynamicModule, ModuleContext, OnInitialize, Provider } from '../module/types'\nimport { CONFIG_TOKENS } from './config.tokens'\nimport { ConfigValidationError, type ModuleConfig } from './config.types'\nimport { ConfigModuleNotInitializedError } from './errors'\nimport type { ConfigNamespace } from './register-as'\nimport { ConfigService } from './services/config.service'\n\n/**\n * Any config namespace - uses structural typing for flexibility\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyConfigNamespace = ConfigNamespace<string, any, object>\n\n/**\n * Options for ConfigModule.forRoot\n */\nexport interface ConfigModuleOptions {\n /**\n * Array of config namespaces created via registerAs()\n */\n load: AnyConfigNamespace[]\n\n /**\n * Optional Zod schema for validating the merged config\n * Validates the entire config object after all namespaces are merged\n */\n validateSchema?: z.ZodType<object>\n}\n\n// Store options for use in onInitialize\nlet moduleOptions: ConfigModuleOptions | null = null\n\n/**\n * ConfigModule\n *\n * Provides configuration management with namespace support.\n * Uses registerAs() to create typed config namespaces that can be injected.\n *\n * @example\n * ```typescript\n * // Define config namespaces\n * const databaseConfig = registerAs('database', (env) => ({\n * url: env.DATABASE_URL,\n * maxConnections: 10\n * }))\n *\n * const emailConfig = registerAs('email', (env) => ({\n * provider: env.EMAIL_PROVIDER,\n * from: { name: 'App', email: 'noreply@example.com' }\n * }))\n *\n * // Register in module\n * @Module({\n * imports: [\n * ConfigModule.forRoot({\n * load: [databaseConfig, emailConfig],\n * validateSchema: AppConfigSchema\n * })\n * ]\n * })\n * export class AppModule {}\n *\n * // Inject config\n * constructor(\n * @inject(CONFIG_TOKENS.ConfigService) private config: IConfigService,\n * @inject(databaseConfig.KEY) private dbConfig: DatabaseConfig\n * ) {\n * // Use dot notation\n * const url = this.config.get('database.url')\n *\n * // Or inject namespace directly\n * const url = this.dbConfig.url\n * }\n * ```\n */\n@Module({\n providers: [\n // Register the main ConfigService as Singleton so initialization persists\n {\n provide: CONFIG_TOKENS.ConfigService,\n useClass: ConfigService,\n scope: Scope.Singleton,\n },\n ],\n})\nexport class ConfigModule implements OnInitialize {\n /**\n * Configure ConfigModule with namespace loaders\n *\n * @param options - Configuration options\n * @returns Dynamic module with config infrastructure\n */\n static forRoot(options: ConfigModuleOptions): DynamicModule {\n moduleOptions = options\n\n const providers: Provider[] = []\n\n // Register each namespace config using asProvider()\n for (const namespace of options.load) {\n providers.push(namespace.asProvider())\n }\n\n return {\n module: ConfigModule,\n providers,\n }\n }\n\n /**\n * Initialize config service with merged namespaces\n * Called after all providers are registered\n */\n onInitialize(context: ModuleContext): void {\n if (!moduleOptions) {\n throw new ConfigModuleNotInitializedError()\n }\n\n const env = context.container.resolve<unknown>(DI_TOKENS.CloudflareEnv)\n const configService = context.container.resolve<ConfigService>(CONFIG_TOKENS.ConfigService)\n\n // Build merged config from all namespaces\n const mergedConfig: Record<string, unknown> = {}\n\n for (const namespace of moduleOptions.load) {\n mergedConfig[namespace.namespace] = namespace.factory(env)\n }\n\n // Validate if schema provided\n if (moduleOptions.validateSchema) {\n const result = moduleOptions.validateSchema.safeParse(mergedConfig)\n if (!result.success) {\n throw new ConfigValidationError(\n 'Configuration validation failed',\n result.error\n )\n }\n }\n\n // Initialize ConfigService with merged config\n configService.initialize(mergedConfig as ModuleConfig)\n\n context.logger.debug('ConfigModule initialized', {\n namespaces: moduleOptions.load.map((n) => n.namespace),\n })\n }\n}\n","import type { InjectionToken } from 'tsyringe'\nimport { DI_TOKENS } from '../di/tokens'\nimport type { FactoryProvider } from '../module/types'\n\n/**\n * Configuration namespace registration result\n */\nexport interface ConfigNamespace<TKey extends string, TEnv, TConfig extends object> {\n /** Auto-derived injection token (e.g., 'database' -> Symbol('stratal:config:database')) */\n readonly KEY: InjectionToken<TConfig>\n /** The namespace key */\n readonly namespace: TKey\n /** The factory function that receives env and returns config */\n readonly factory: (env: TEnv) => TConfig\n /**\n * Returns a provider configuration for use in module registration\n * Automatically injects DI_TOKENS.CloudflareEnv\n */\n asProvider(): FactoryProvider<TConfig>\n}\n\n/**\n * Create a namespaced configuration factory\n * Similar to NestJS registerAs\n *\n * @param namespace - Configuration namespace (e.g., 'database', 'email')\n * @param factory - Factory function receiving env and returning config object\n * @returns ConfigNamespace with token, factory, and asProvider() method\n *\n * @example\n * ```typescript\n * // apps/backend/src/config/database.config.ts\n * export const databaseConfig = registerAs('database', (env: Env) => ({\n * url: env.DATABASE_URL,\n * maxConnections: parseInt(env.DATABASE_MAX_CONNECTIONS || '10'),\n * }))\n *\n * // Auto-generates: databaseConfig.KEY = Symbol('stratal:config:database')\n *\n * // Usage in module:\n * // Option 1: Manual provider\n * {\n * provide: databaseConfig.KEY,\n * useFactory: databaseConfig.factory,\n * inject: [DI_TOKENS.CloudflareEnv]\n * }\n *\n * // Option 2: asProvider() helper\n * databaseConfig.asProvider()\n * // Returns: { provide: databaseConfig.KEY, useFactory: ..., inject: [DI_TOKENS.CloudflareEnv] }\n * ```\n */\nexport function registerAs<TKey extends string, TEnv, TConfig extends object>(\n namespace: TKey,\n factory: (env: TEnv) => TConfig\n): ConfigNamespace<TKey, TEnv, TConfig> {\n const KEY = Symbol.for(`stratal:config:${namespace}`) as InjectionToken<TConfig>\n\n return {\n KEY,\n namespace,\n factory,\n asProvider(): FactoryProvider<TConfig> {\n return {\n provide: KEY,\n useFactory: factory,\n inject: [DI_TOKENS.CloudflareEnv],\n }\n },\n }\n}\n\n/**\n * Helper to derive config type from registerAs result\n *\n * @example\n * ```typescript\n * const databaseConfig = registerAs('database', (env) => ({ url: env.DATABASE_URL }))\n * type DatabaseConfig = InferConfigType<typeof databaseConfig>\n * // { url: string }\n * ```\n */\nexport type InferConfigType<T> = T extends ConfigNamespace<string, unknown, infer C> ? C : never\n"],"mappings":";;;;AAAA,MAAa,gBAAgB,EAC5B,eAAe,OAAO,IAAI,yBAAyB,EACnD;;;ACAD,IAAa,wBAAb,cAA2C,MAAM;CAC/C,YACE,SACA,QACA;AACA,QAAM,QAAQ;AAFE,OAAA,SAAA;AAGhB,OAAK,OAAO;;;;;;;;;;ACDhB,IAAa,kCAAb,cAAqD,iBAAiB;CACpE,cAAc;AACZ,QACE,qCACA,YAAY,OAAO,8BACpB;;;;;;;;;;;;ACFL,IAAa,4BAAb,cAA+C,iBAAiB;CAC9D,cAAc;AACZ,QACE,+BACA,YAAY,OAAO,uBACpB;;;;;ACWE,IAAA,gBAAA,MAAM,cAA4E;CACvF;CACA;;;;;CAMA,WAAW,QAAiB;AAC1B,OAAK,iBAAiB,KAAK,UAAU,OAAO;AAC5C,OAAK,gBAAgB,KAAK,UAAU,OAAO;;;;;;CAO7C,IAA6B,MAAgC;AAC3D,OAAK,mBAAmB;AACxB,SAAO,KAAK,UAAU,KAAK,eAAe,KAAK;;;;;;CAOjD,IAA6B,MAAS,OAAoC;AACxE,OAAK,mBAAmB;AACxB,OAAK,UAAU,KAAK,eAAe,MAAM,MAAM;;;;;;CAOjD,MAAM,MAA4B;AAChC,OAAK,mBAAmB;AACxB,MAAI,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C,UAAO;IACL,SAAS;IACT,YAAY;IACZ,QAAQ,CAAC,UAAU,cAAc;IAClC;;EAEJ"}
@@ -0,0 +1,142 @@
1
+ //#region src/queue/queue-consumer.d.ts
2
+ /**
3
+ * Queue message structure
4
+ *
5
+ * All messages dispatched to queues follow this structure.
6
+ * The `id` and `timestamp` are auto-generated by QueueSender.
7
+ */
8
+ interface QueueMessage<T = unknown> {
9
+ /** Unique message identifier (UUID) */
10
+ id: string;
11
+ /** Timestamp when message was dispatched (milliseconds since epoch) */
12
+ timestamp: number;
13
+ /** Message type for routing to consumers */
14
+ type: string;
15
+ /** Message payload */
16
+ payload: T;
17
+ /** Optional metadata including locale for i18n */
18
+ metadata?: {
19
+ locale?: string;
20
+ [key: string]: unknown;
21
+ };
22
+ }
23
+ /**
24
+ * Queue consumer interface
25
+ *
26
+ * Consumers handle messages based on their `messageTypes` declaration.
27
+ * A consumer receives messages of the declared types from ANY queue.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * @Transient()
32
+ * export class EmailConsumer implements IQueueConsumer<SendEmailInput> {
33
+ * readonly messageTypes = ['email.send', 'email.batch.send']
34
+ *
35
+ * async handle(message: QueueMessage<SendEmailInput>): Promise<void> {
36
+ * // Process email...
37
+ * }
38
+ * }
39
+ * ```
40
+ */
41
+ interface IQueueConsumer<T = unknown> {
42
+ /**
43
+ * Message types this consumer handles.
44
+ *
45
+ * The consumer receives messages matching these types from ANY queue.
46
+ * Use '*' to match all message types (wildcard consumer).
47
+ */
48
+ readonly messageTypes: string[];
49
+ /**
50
+ * Handle an incoming message
51
+ *
52
+ * @param message - The queue message to process
53
+ */
54
+ handle(message: QueueMessage<T>): Promise<void>;
55
+ /**
56
+ * Optional error handler for failed message processing
57
+ *
58
+ * @param error - The error that occurred
59
+ * @param message - The message that failed to process
60
+ */
61
+ onError?(error: Error, message: QueueMessage<T>): Promise<void>;
62
+ }
63
+ //#endregion
64
+ //#region src/queue/consumer-registry.d.ts
65
+ /**
66
+ * Consumer Registry
67
+ *
68
+ * Singleton service that holds all registered queue consumers indexed by message type.
69
+ * Consumers declare the message types they handle, and this registry routes messages
70
+ * to the appropriate consumers based on their types.
71
+ *
72
+ * **Message-Type Routing:**
73
+ * - Consumers declare `messageTypes` array (e.g., `['email.send', 'email.batch.send']`)
74
+ * - When a message arrives, consumers matching the message type are invoked
75
+ * - A consumer can handle messages from ANY queue (routing is by type, not queue)
76
+ * - Use `'*'` as a wildcard to handle all message types
77
+ *
78
+ * @example Consumer registration
79
+ * ```typescript
80
+ * // In consumer.ts
81
+ * @Transient()
82
+ * export class EmailConsumer implements IQueueConsumer {
83
+ * readonly messageTypes = ['email.send', 'email.batch.send']
84
+ * // ...
85
+ * }
86
+ *
87
+ * // In module.ts
88
+ * @Module({
89
+ * consumers: [EmailConsumer]
90
+ * })
91
+ *
92
+ * // Application auto-registers via ConsumerRegistry
93
+ * this.consumerRegistry.register(consumer)
94
+ * ```
95
+ */
96
+ declare class ConsumerRegistry {
97
+ /** Map from message type to consumers handling that type */
98
+ private consumersByType;
99
+ /** Set of all registered consumers (for iteration) */
100
+ private allConsumers;
101
+ /**
102
+ * Register a queue consumer
103
+ *
104
+ * Indexes the consumer by each of its declared message types.
105
+ *
106
+ * @param consumer - Queue consumer to register
107
+ */
108
+ register(consumer: IQueueConsumer): void;
109
+ /**
110
+ * Get all consumers that can handle a specific message type
111
+ *
112
+ * Returns consumers that either:
113
+ * - Explicitly declare the message type
114
+ * - Use '*' wildcard to handle all types
115
+ *
116
+ * @param messageType - The message type to find consumers for
117
+ * @returns Array of consumers that can handle this message type
118
+ */
119
+ getConsumers(messageType: string): IQueueConsumer[];
120
+ /**
121
+ * Check if any consumers can handle a message type
122
+ *
123
+ * @param messageType - The message type to check
124
+ * @returns true if at least one consumer can handle this type
125
+ */
126
+ hasConsumers(messageType: string): boolean;
127
+ /**
128
+ * Get all registered message types
129
+ *
130
+ * @returns Array of message types with registered consumers
131
+ */
132
+ getMessageTypes(): string[];
133
+ /**
134
+ * Get all registered consumers
135
+ *
136
+ * @returns Array of all registered consumers
137
+ */
138
+ getAllConsumers(): IQueueConsumer[];
139
+ }
140
+ //#endregion
141
+ export { IQueueConsumer as n, QueueMessage as r, ConsumerRegistry as t };
142
+ //# sourceMappingURL=consumer-registry-BkuHXR_u.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumer-registry-BkuHXR_u.d.mts","names":[],"sources":["../src/queue/queue-consumer.ts","../src/queue/consumer-registry.ts"],"mappings":";;AAMA;;;;;UAAiB,YAAA;EAIf;EAFA,EAAA;EAMA;EAJA,SAAA;EAMA;EAJA,IAAA;EAMG;EAJH,OAAA,EAAS,CAAA;EAIK;EAFd,QAAA;IACE,MAAA;IAAA,CACC,GAAA;EAAA;AAAA;;;;;;;;;;;;;;;;;;;UAsBY,cAAA;EAsBQ;;;;;;EAAA,SAfd,YAAA;ECXE;;;;;EDkBX,MAAA,CAAO,OAAA,EAAS,YAAA,CAAa,CAAA,IAAK,OAAA;ECqDD;;;;;;ED7CjC,OAAA,EAAS,KAAA,EAAO,KAAA,EAAO,OAAA,EAAS,YAAA,CAAa,CAAA,IAAK,OAAA;AAAA;;;AAxDpD;;;;;;;;;;;;;;;AAkCA;;;;;;;;;;;;;;;;AAlCA,cC8Ba,gBAAA;EDkBJ;EAAA,QChBC,eAAA;EDwBR;EAAA,QCrBQ,YAAA;EDqBC;;;;;;;ECZT,QAAA,CAAS,QAAA,EAAU,cAAA;;;AAfrB;;;;;;;;EAuCE,YAAA,CAAa,WAAA,WAAsB,cAAA;EAjC3B;;;;;;EAgDR,YAAA,CAAa,WAAA;EAAb;;;;;EASA,eAAA,CAAA;EASiC;;;;;EAAjC,eAAA,CAAA,GAAmB,cAAA;AAAA"}
@@ -1,119 +1,6 @@
1
- import { s as ApplicationError } from "../index-BJWm863C.mjs";
2
- //#region src/cron/cron-job.d.ts
3
- /**
4
- * Interface for cron jobs that can be registered by modules
5
- *
6
- * Cron jobs are executed when Cloudflare triggers match their schedule.
7
- * Jobs are registered via the module's getCronJobs() method.
8
- *
9
- * @example
10
- * ```typescript
11
- * @Transient()
12
- * export class DataCleanupJob implements CronJob {
13
- * readonly schedule = '0 2 * * *' // Daily at 2 AM UTC
14
- *
15
- * constructor(
16
- * @inject(LOGGER_TOKENS.LoggerService) private logger: LoggerService,
17
- * ) {}
18
- *
19
- * async execute(controller: ScheduledController): Promise<void> {
20
- * this.logger.info('Running data cleanup')
21
- * await this.cleanupExpiredData()
22
- * }
23
- *
24
- * async onError(error: Error): Promise<void> {
25
- * this.logger.error('Data cleanup failed', { error: error.message })
26
- * }
27
- * }
28
- * ```
29
- */
30
- interface CronJob {
31
- /**
32
- * Cron expression that triggers this job
33
- *
34
- * Must match a cron trigger defined in wrangler.jsonc
35
- * @example '0 2 * * *' // Daily at 2 AM UTC
36
- * @example '* /15 * * * *' // Every 15 minutes
37
- */
38
- readonly schedule: string;
39
- /**
40
- * Execute the cron job
41
- *
42
- * @param controller - Cloudflare ScheduledController with scheduledTime and cron
43
- * @throws ApplicationError for expected errors
44
- */
45
- execute(controller: ScheduledController): Promise<void>;
46
- /**
47
- * Optional error handler for job execution failures
48
- *
49
- * If not provided, errors are logged via GlobalErrorHandler
50
- *
51
- * @param error - Error that occurred during execution
52
- * @param controller - Cloudflare ScheduledController
53
- */
54
- onError?(error: Error, controller: ScheduledController): Promise<void>;
55
- }
56
- //#endregion
57
- //#region src/cron/cron-manager.d.ts
58
- /**
59
- * Manages cron job registration and execution
60
- *
61
- * CronManager is a singleton service that:
62
- * - Registers cron jobs from modules
63
- * - Routes scheduled events to matching jobs
64
- * - Handles errors during job execution
65
- *
66
- * Jobs are grouped by their cron expression, allowing multiple jobs
67
- * to run on the same schedule.
68
- */
69
- declare class CronManager {
70
- /**
71
- * Map of cron expressions to jobs
72
- * Key: Cron expression (e.g., '0 2 * * *')
73
- * Value: Array of jobs matching that expression
74
- */
75
- private jobs;
76
- /**
77
- * Register a cron job
78
- *
79
- * Jobs with the same schedule are grouped together and executed
80
- * sequentially when the trigger fires.
81
- *
82
- * @param job - CronJob instance to register
83
- */
84
- registerJob(job: CronJob): void;
85
- /**
86
- * Execute all jobs matching the triggered cron expression
87
- *
88
- * Jobs are executed sequentially. If a job fails:
89
- * - Its onError() hook is called (if defined)
90
- * - Execution continues with the next job
91
- * - Errors are collected and logged
92
- *
93
- * @param controller - Cloudflare ScheduledController
94
- */
95
- executeScheduled(controller: ScheduledController): Promise<void>;
96
- /**
97
- * Get all registered jobs for a specific cron expression
98
- *
99
- * @param schedule - Cron expression
100
- * @returns Array of jobs for that schedule, or empty array if none
101
- */
102
- getJobsForSchedule(schedule: string): CronJob[];
103
- /**
104
- * Get all registered cron expressions
105
- *
106
- * @returns Array of unique cron expressions
107
- */
108
- getAllSchedules(): string[];
109
- /**
110
- * Get total number of registered jobs across all schedules
111
- *
112
- * @returns Total job count
113
- */
114
- getTotalJobCount(): number;
115
- }
116
- //#endregion
1
+ import { d as ApplicationError } from "../index-BrmS34sa.mjs";
2
+ import { n as CronJob, t as CronManager } from "../cron-manager-BnEZquBL.mjs";
3
+
117
4
  //#region src/cron/errors/cron-execution.error.d.ts
118
5
  /**
119
6
  * Error thrown when one or more cron jobs fail execution
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/cron/cron-job.ts","../../src/cron/cron-manager.ts","../../src/cron/errors/cron-execution.error.ts"],"mappings":";;;;;;AA2BA;;;;;;;;;;;;;;;;;;;;;;;UAAiB,OAAA;;;ACZjB;;;;;WDoBU,QAAA;EC6D6B;;;;;;EDrDtC,OAAA,CAAQ,UAAA,EAAY,mBAAA,GAAsB,OAAA;ECKpC;;;;;;;;EDKN,OAAA,EAAS,KAAA,EAAO,KAAA,EAAO,UAAA,EAAY,mBAAA,GAAsB,OAAA;AAAA;;;;;;AA1B1D;;;;;;;;cCXa,WAAA;EDqCoD;;;;;EAAA,QC/BxD,IAAA;ED+BR;;;;;;;;ECrBA,WAAA,CAAY,GAAA,EAAK,OAAA;;;AAjBlB;;;;;;;;EAiCO,gBAAA,CAAiB,UAAA,EAAY,mBAAA,GAAsB,OAAA;EA1BjD;;;;;;EA0ER,kBAAA,CAAmB,QAAA,WAAmB,OAAA;EAhDmB;;;;;EAyDzD,eAAA,CAAA;EASgB;;;;;EAAhB,gBAAA,CAAA;AAAA;;;;;;ADvFD;;cEnBa,kBAAA,SAA2B,gBAAA;cAEtC,QAAA,UACA,eAAA,UACA,QAAA;AAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/cron/errors/cron-execution.error.ts"],"mappings":";;;;;;;AAQA;;cAAa,kBAAA,SAA2B,gBAAA;cAEtC,QAAA,UACA,eAAA,UACA,QAAA;AAAA"}
@@ -1,5 +1,2 @@
1
- import "../errors-CtCi1wn6.mjs";
2
- import "../decorate-D5j-d9_z.mjs";
3
- import "../logger-BR1-s1Um.mjs";
4
- import { n as CronExecutionError, t as CronManager } from "../cron-manager-DR7fiG6o.mjs";
1
+ import { n as CronExecutionError, t as CronManager } from "../cron-manager-1KnZvojs.mjs";
5
2
  export { CronExecutionError, CronManager };
@@ -1,5 +1,5 @@
1
- import { S as ApplicationError, b as ERROR_CODES } from "./errors-CtCi1wn6.mjs";
2
- import { i as Transient, t as __decorate } from "./decorate-D5j-d9_z.mjs";
1
+ import { H as ApplicationError, k as ERROR_CODES } from "./errors--RBIvDXr.mjs";
2
+ import { a as __decorate, p as Transient } from "./logger-c0ftIK4G.mjs";
3
3
  //#region src/cron/errors/cron-execution.error.ts
4
4
  /**
5
5
  * Error thrown when one or more cron jobs fail execution
@@ -104,4 +104,4 @@ CronManager = __decorate([Transient()], CronManager);
104
104
  //#endregion
105
105
  export { CronExecutionError as n, CronManager as t };
106
106
 
107
- //# sourceMappingURL=cron-manager-DR7fiG6o.mjs.map
107
+ //# sourceMappingURL=cron-manager-1KnZvojs.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cron-manager-DR7fiG6o.mjs","names":[],"sources":["../src/cron/errors/cron-execution.error.ts","../src/cron/cron-manager.ts"],"sourcesContent":["import { ApplicationError } from '../../errors'\nimport { ERROR_CODES } from '../../errors'\n\n/**\n * Error thrown when one or more cron jobs fail execution\n *\n * This error aggregates failures from multiple jobs that share the same schedule.\n */\nexport class CronExecutionError extends ApplicationError {\n\tconstructor(\n\t\tschedule: string,\n\t\tfailedJobsCount: number,\n\t\tjobNames: string\n\t) {\n\t\tsuper(\n\t\t\t'errors.cronExecutionFailed',\n\t\t\tERROR_CODES.SYSTEM.CRON_EXECUTION_FAILED,\n\t\t\t{\n\t\t\t\tschedule,\n\t\t\t\tcount: failedJobsCount,\n\t\t\t\tjobs: jobNames\n\t\t\t}\n\t\t)\n\t}\n}\n","import { Transient } from '../di/decorators'\nimport type { CronJob } from './cron-job'\nimport { CronExecutionError } from './errors/cron-execution.error'\n\n/**\n * Manages cron job registration and execution\n *\n * CronManager is a singleton service that:\n * - Registers cron jobs from modules\n * - Routes scheduled events to matching jobs\n * - Handles errors during job execution\n *\n * Jobs are grouped by their cron expression, allowing multiple jobs\n * to run on the same schedule.\n */\n@Transient()\nexport class CronManager {\n\t/**\n\t * Map of cron expressions to jobs\n\t * Key: Cron expression (e.g., '0 2 * * *')\n\t * Value: Array of jobs matching that expression\n\t */\n\tprivate jobs = new Map<string, CronJob[]>()\n\n\t/**\n\t * Register a cron job\n\t *\n\t * Jobs with the same schedule are grouped together and executed\n\t * sequentially when the trigger fires.\n\t *\n\t * @param job - CronJob instance to register\n\t */\n\tregisterJob(job: CronJob): void {\n\t\tconst existing = this.jobs.get(job.schedule) ?? []\n\t\texisting.push(job)\n\t\tthis.jobs.set(job.schedule, existing)\n\t}\n\n\t/**\n\t * Execute all jobs matching the triggered cron expression\n\t *\n\t * Jobs are executed sequentially. If a job fails:\n\t * - Its onError() hook is called (if defined)\n\t * - Execution continues with the next job\n\t * - Errors are collected and logged\n\t *\n\t * @param controller - Cloudflare ScheduledController\n\t */\n\tasync executeScheduled(controller: ScheduledController): Promise<void> {\n\t\tconst { cron } = controller\n\t\tconst matchingJobs = this.jobs.get(cron) ?? []\n\n\t\tif (matchingJobs.length === 0) {\n\t\t\treturn\n\t\t}\n\n\t\tconst errors: { job: string; error: Error }[] = []\n\n\t\tfor (const job of matchingJobs) {\n\t\t\tconst jobName = job.constructor.name\n\n\t\t\ttry {\n\t\t\t\tawait job.execute(controller)\n\t\t\t} catch (error) {\n\t\t\t\tconst err = error as Error\n\t\t\t\terrors.push({ job: jobName, error: err })\n\n\t\t\t\t// Call job's error handler if defined\n\t\t\t\tif (job.onError) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait job.onError(err, controller)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// If onError() itself fails, we just continue\n\t\t\t\t\t\t// The error will be logged by GlobalErrorHandler\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// If any jobs failed, throw an aggregate error\n\t\t// This ensures the error is logged by GlobalErrorHandler\n\t\tif (errors.length > 0) {\n\t\t\tconst jobNames = errors\n\t\t\t\t.map(({ job, error }) => `${job}: ${error.message}`)\n\t\t\t\t.join('; ')\n\n\t\t\tthrow new CronExecutionError(cron, errors.length, jobNames)\n\t\t}\n\t}\n\n\t/**\n\t * Get all registered jobs for a specific cron expression\n\t *\n\t * @param schedule - Cron expression\n\t * @returns Array of jobs for that schedule, or empty array if none\n\t */\n\tgetJobsForSchedule(schedule: string): CronJob[] {\n\t\treturn this.jobs.get(schedule) ?? []\n\t}\n\n\t/**\n\t * Get all registered cron expressions\n\t *\n\t * @returns Array of unique cron expressions\n\t */\n\tgetAllSchedules(): string[] {\n\t\treturn Array.from(this.jobs.keys())\n\t}\n\n\t/**\n\t * Get total number of registered jobs across all schedules\n\t *\n\t * @returns Total job count\n\t */\n\tgetTotalJobCount(): number {\n\t\tlet count = 0\n\t\tfor (const jobs of this.jobs.values()) {\n\t\t\tcount += jobs.length\n\t\t}\n\t\treturn count\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,IAAa,q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AO;;;0BAxGR,WAAW,CAAA,EAAA,YAAA"}
1
+ {"version":3,"file":"cron-manager-1KnZvojs.mjs","names":[],"sources":["../src/cron/errors/cron-execution.error.ts","../src/cron/cron-manager.ts"],"sourcesContent":["import { ApplicationError } from '../../errors'\nimport { ERROR_CODES } from '../../errors'\n\n/**\n * Error thrown when one or more cron jobs fail execution\n *\n * This error aggregates failures from multiple jobs that share the same schedule.\n */\nexport class CronExecutionError extends ApplicationError {\n\tconstructor(\n\t\tschedule: string,\n\t\tfailedJobsCount: number,\n\t\tjobNames: string\n\t) {\n\t\tsuper(\n\t\t\t'errors.cronExecutionFailed',\n\t\t\tERROR_CODES.SYSTEM.CRON_EXECUTION_FAILED,\n\t\t\t{\n\t\t\t\tschedule,\n\t\t\t\tcount: failedJobsCount,\n\t\t\t\tjobs: jobNames\n\t\t\t}\n\t\t)\n\t}\n}\n","import { Transient } from '../di/decorators'\nimport type { CronJob } from './cron-job'\nimport { CronExecutionError } from './errors/cron-execution.error'\n\n/**\n * Manages cron job registration and execution\n *\n * CronManager is a singleton service that:\n * - Registers cron jobs from modules\n * - Routes scheduled events to matching jobs\n * - Handles errors during job execution\n *\n * Jobs are grouped by their cron expression, allowing multiple jobs\n * to run on the same schedule.\n */\n@Transient()\nexport class CronManager {\n\t/**\n\t * Map of cron expressions to jobs\n\t * Key: Cron expression (e.g., '0 2 * * *')\n\t * Value: Array of jobs matching that expression\n\t */\n\tprivate jobs = new Map<string, CronJob[]>()\n\n\t/**\n\t * Register a cron job\n\t *\n\t * Jobs with the same schedule are grouped together and executed\n\t * sequentially when the trigger fires.\n\t *\n\t * @param job - CronJob instance to register\n\t */\n\tregisterJob(job: CronJob): void {\n\t\tconst existing = this.jobs.get(job.schedule) ?? []\n\t\texisting.push(job)\n\t\tthis.jobs.set(job.schedule, existing)\n\t}\n\n\t/**\n\t * Execute all jobs matching the triggered cron expression\n\t *\n\t * Jobs are executed sequentially. If a job fails:\n\t * - Its onError() hook is called (if defined)\n\t * - Execution continues with the next job\n\t * - Errors are collected and logged\n\t *\n\t * @param controller - Cloudflare ScheduledController\n\t */\n\tasync executeScheduled(controller: ScheduledController): Promise<void> {\n\t\tconst { cron } = controller\n\t\tconst matchingJobs = this.jobs.get(cron) ?? []\n\n\t\tif (matchingJobs.length === 0) {\n\t\t\treturn\n\t\t}\n\n\t\tconst errors: { job: string; error: Error }[] = []\n\n\t\tfor (const job of matchingJobs) {\n\t\t\tconst jobName = job.constructor.name\n\n\t\t\ttry {\n\t\t\t\tawait job.execute(controller)\n\t\t\t} catch (error) {\n\t\t\t\tconst err = error as Error\n\t\t\t\terrors.push({ job: jobName, error: err })\n\n\t\t\t\t// Call job's error handler if defined\n\t\t\t\tif (job.onError) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait job.onError(err, controller)\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// If onError() itself fails, we just continue\n\t\t\t\t\t\t// The error will be logged by ExceptionHandler\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// If any jobs failed, throw an aggregate error\n\t\t// This ensures the error is logged by ExceptionHandler\n\t\tif (errors.length > 0) {\n\t\t\tconst jobNames = errors\n\t\t\t\t.map(({ job, error }) => `${job}: ${error.message}`)\n\t\t\t\t.join('; ')\n\n\t\t\tthrow new CronExecutionError(cron, errors.length, jobNames)\n\t\t}\n\t}\n\n\t/**\n\t * Get all registered jobs for a specific cron expression\n\t *\n\t * @param schedule - Cron expression\n\t * @returns Array of jobs for that schedule, or empty array if none\n\t */\n\tgetJobsForSchedule(schedule: string): CronJob[] {\n\t\treturn this.jobs.get(schedule) ?? []\n\t}\n\n\t/**\n\t * Get all registered cron expressions\n\t *\n\t * @returns Array of unique cron expressions\n\t */\n\tgetAllSchedules(): string[] {\n\t\treturn Array.from(this.jobs.keys())\n\t}\n\n\t/**\n\t * Get total number of registered jobs across all schedules\n\t *\n\t * @returns Total job count\n\t */\n\tgetTotalJobCount(): number {\n\t\tlet count = 0\n\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CAQpC,mBAA2B;EAC1B,IAAI,QAAQ;AACZ,OAAK,MAAM,QAAQ,KAAK,KAAK,QAAQ,CACpC,UAAS,KAAK;AAEf,SAAO;;;0BAxGR,WAAW,CAAA,EAAA,YAAA"}
@@ -0,0 +1,117 @@
1
+ //#region src/cron/cron-job.d.ts
2
+ /**
3
+ * Interface for cron jobs that can be registered by modules
4
+ *
5
+ * Cron jobs are executed when Cloudflare triggers match their schedule.
6
+ * Jobs are registered via the module's getCronJobs() method.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * @Transient()
11
+ * export class DataCleanupJob implements CronJob {
12
+ * readonly schedule = '0 2 * * *' // Daily at 2 AM UTC
13
+ *
14
+ * constructor(
15
+ * @inject(LOGGER_TOKENS.LoggerService) private logger: LoggerService,
16
+ * ) {}
17
+ *
18
+ * async execute(controller: ScheduledController): Promise<void> {
19
+ * this.logger.info('Running data cleanup')
20
+ * await this.cleanupExpiredData()
21
+ * }
22
+ *
23
+ * async onError(error: Error): Promise<void> {
24
+ * this.logger.error('Data cleanup failed', { error: error.message })
25
+ * }
26
+ * }
27
+ * ```
28
+ */
29
+ interface CronJob {
30
+ /**
31
+ * Cron expression that triggers this job
32
+ *
33
+ * Must match a cron trigger defined in wrangler.jsonc
34
+ * @example '0 2 * * *' // Daily at 2 AM UTC
35
+ * @example '* /15 * * * *' // Every 15 minutes
36
+ */
37
+ readonly schedule: string;
38
+ /**
39
+ * Execute the cron job
40
+ *
41
+ * @param controller - Cloudflare ScheduledController with scheduledTime and cron
42
+ * @throws ApplicationError for expected errors
43
+ */
44
+ execute(controller: ScheduledController): Promise<void>;
45
+ /**
46
+ * Optional error handler for job execution failures
47
+ *
48
+ * If not provided, errors are logged via ExceptionHandler
49
+ *
50
+ * @param error - Error that occurred during execution
51
+ * @param controller - Cloudflare ScheduledController
52
+ */
53
+ onError?(error: Error, controller: ScheduledController): Promise<void>;
54
+ }
55
+ //#endregion
56
+ //#region src/cron/cron-manager.d.ts
57
+ /**
58
+ * Manages cron job registration and execution
59
+ *
60
+ * CronManager is a singleton service that:
61
+ * - Registers cron jobs from modules
62
+ * - Routes scheduled events to matching jobs
63
+ * - Handles errors during job execution
64
+ *
65
+ * Jobs are grouped by their cron expression, allowing multiple jobs
66
+ * to run on the same schedule.
67
+ */
68
+ declare class CronManager {
69
+ /**
70
+ * Map of cron expressions to jobs
71
+ * Key: Cron expression (e.g., '0 2 * * *')
72
+ * Value: Array of jobs matching that expression
73
+ */
74
+ private jobs;
75
+ /**
76
+ * Register a cron job
77
+ *
78
+ * Jobs with the same schedule are grouped together and executed
79
+ * sequentially when the trigger fires.
80
+ *
81
+ * @param job - CronJob instance to register
82
+ */
83
+ registerJob(job: CronJob): void;
84
+ /**
85
+ * Execute all jobs matching the triggered cron expression
86
+ *
87
+ * Jobs are executed sequentially. If a job fails:
88
+ * - Its onError() hook is called (if defined)
89
+ * - Execution continues with the next job
90
+ * - Errors are collected and logged
91
+ *
92
+ * @param controller - Cloudflare ScheduledController
93
+ */
94
+ executeScheduled(controller: ScheduledController): Promise<void>;
95
+ /**
96
+ * Get all registered jobs for a specific cron expression
97
+ *
98
+ * @param schedule - Cron expression
99
+ * @returns Array of jobs for that schedule, or empty array if none
100
+ */
101
+ getJobsForSchedule(schedule: string): CronJob[];
102
+ /**
103
+ * Get all registered cron expressions
104
+ *
105
+ * @returns Array of unique cron expressions
106
+ */
107
+ getAllSchedules(): string[];
108
+ /**
109
+ * Get total number of registered jobs across all schedules
110
+ *
111
+ * @returns Total job count
112
+ */
113
+ getTotalJobCount(): number;
114
+ }
115
+ //#endregion
116
+ export { CronJob as n, CronManager as t };
117
+ //# sourceMappingURL=cron-manager-BnEZquBL.d.mts.map