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,310 +0,0 @@
1
- import { i as Transient, l as DI_TOKENS, n as __decorateParam, r as __decorateMetadata, t as __decorate } from "./decorate-D5j-d9_z.mjs";
2
- import { n as CommandError, r as COMMAND_INTERNALS } from "./command-BvCOD6df.mjs";
3
- import { inject } from "tsyringe";
4
- //#region src/quarry/command-internals.ts
5
- /** @internal Set the flat input values before calling handle() */
6
- function setCommandInputs(command, values) {
7
- command[COMMAND_INTERNALS].inputs = { ...values };
8
- }
9
- /** @internal Set the Quarry reference for this.call() support */
10
- function setCommandQuarry(command, quarry) {
11
- command[COMMAND_INTERNALS].quarry = quarry;
12
- }
13
- /** @internal Collect the result after handle() completes */
14
- function getCommandResult(command) {
15
- const internals = command[COMMAND_INTERNALS];
16
- return {
17
- exitCode: internals.exitCode,
18
- output: [...internals.output],
19
- errors: [...internals.errors]
20
- };
21
- }
22
- //#endregion
23
- //#region src/quarry/errors/command-not-found.error.ts
24
- /**
25
- * Thrown when a command is not found in the Quarry registry.
26
- */
27
- var CommandNotFoundError = class extends Error {
28
- constructor(name) {
29
- super(`Command "${name}" is not registered.`);
30
- this.name = "CommandNotFoundError";
31
- }
32
- };
33
- //#endregion
34
- //#region src/quarry/signature-parser.ts
35
- /**
36
- * Parse a Laravel-style command signature string.
37
- *
38
- * Signature syntax:
39
- * command-name {arg} ... — flat command
40
- * group subcommand {arg} ... — subcommand hierarchy (space-separated)
41
- * namespace:command {arg} ... — namespaced flat command (colon-separated)
42
- * {--flag} {--name=} {--name=default} {--name=*} {--A|name} {--name= : desc}
43
- *
44
- * Pure function, zero dependencies, edge-compatible.
45
- */
46
- function parseSignature(signature) {
47
- const tokens = extractTokens(signature);
48
- const name = extractCommandName(signature);
49
- const args = [];
50
- const options = [];
51
- for (const token of tokens) {
52
- const inner = token.slice(1, -1).trim();
53
- if (inner.startsWith("--")) options.push(parseOption(inner));
54
- else args.push(parseArgument(inner));
55
- }
56
- return {
57
- name,
58
- arguments: args,
59
- options
60
- };
61
- }
62
- function extractCommandName(signature) {
63
- const match = /^[\w:.-]+(?:\s+[\w:.-]+)*/.exec(signature);
64
- if (!match) throw new CommandError(`Invalid signature: cannot extract command name from "${signature}"`);
65
- return match[0];
66
- }
67
- function extractTokens(signature) {
68
- const tokens = [];
69
- const regex = /\{[^}]+\}/g;
70
- let match;
71
- while ((match = regex.exec(signature)) !== null) tokens.push(match[0]);
72
- return tokens;
73
- }
74
- function parseArgument(inner) {
75
- const { value, description } = splitDescription(inner);
76
- if (value.endsWith("*")) return {
77
- name: value.slice(0, -1).trim(),
78
- required: true,
79
- isArray: true,
80
- description
81
- };
82
- const eqIdx = value.indexOf("=");
83
- if (eqIdx !== -1) return {
84
- name: value.slice(0, eqIdx).trim(),
85
- required: false,
86
- default: value.slice(eqIdx + 1).trim(),
87
- isArray: false,
88
- description
89
- };
90
- if (value.endsWith("?")) return {
91
- name: value.slice(0, -1).trim(),
92
- required: false,
93
- isArray: false,
94
- description
95
- };
96
- return {
97
- name: value.trim(),
98
- required: true,
99
- isArray: false,
100
- description
101
- };
102
- }
103
- function parseOption(inner) {
104
- const { value, description } = splitDescription(inner.slice(2));
105
- let alias;
106
- let optBody = value;
107
- const pipeIdx = optBody.indexOf("|");
108
- if (pipeIdx !== -1) {
109
- alias = optBody.slice(0, pipeIdx).trim();
110
- optBody = optBody.slice(pipeIdx + 1).trim();
111
- }
112
- if (optBody.endsWith("=*")) return {
113
- name: optBody.slice(0, -2).trim(),
114
- alias,
115
- isFlag: false,
116
- isArray: true,
117
- description
118
- };
119
- const eqIdx = optBody.indexOf("=");
120
- if (eqIdx !== -1) {
121
- const name = optBody.slice(0, eqIdx).trim();
122
- const defaultValue = optBody.slice(eqIdx + 1).trim();
123
- return {
124
- name,
125
- alias,
126
- isFlag: false,
127
- isArray: false,
128
- default: defaultValue || void 0,
129
- description
130
- };
131
- }
132
- return {
133
- name: optBody.trim(),
134
- alias,
135
- isFlag: true,
136
- isArray: false,
137
- description
138
- };
139
- }
140
- function splitDescription(value) {
141
- const colonIdx = value.indexOf(" : ");
142
- if (colonIdx === -1) return { value };
143
- return {
144
- value: value.slice(0, colonIdx).trim(),
145
- description: value.slice(colonIdx + 3).trim()
146
- };
147
- }
148
- //#endregion
149
- //#region src/quarry/quarry-registry.ts
150
- let QuarryRegistry = class QuarryRegistry {
151
- commands = /* @__PURE__ */ new Map();
152
- signatures = /* @__PURE__ */ new Map();
153
- aliases = /* @__PURE__ */ new Map();
154
- constructor(container) {
155
- this.container = container;
156
- }
157
- /**
158
- * Execute a command by name with optional flat input.
159
- * A fresh command instance is resolved from the container per invocation.
160
- */
161
- async call(name, input) {
162
- const resolvedName = this.resolveName(name);
163
- const CommandClass = this.commands.get(resolvedName);
164
- if (!CommandClass) throw new CommandNotFoundError(name);
165
- const signature = this.signatures.get(resolvedName);
166
- const mergedInput = this.applyDefaults(input ?? {}, signature);
167
- for (const arg of signature.arguments) if (arg.required && (mergedInput[arg.name] === void 0 || mergedInput[arg.name] === null)) throw new CommandError(`Missing required argument: ${arg.name}`);
168
- let command;
169
- try {
170
- command = this.container.resolve(CommandClass);
171
- setCommandQuarry(command, this);
172
- setCommandInputs(command, mergedInput);
173
- const exitCode = await command.handle();
174
- const result = getCommandResult(command);
175
- if (typeof exitCode === "number") return {
176
- ...result,
177
- exitCode
178
- };
179
- return result;
180
- } catch (error) {
181
- if (error instanceof CommandError) {
182
- if (command) {
183
- const result = getCommandResult(command);
184
- return {
185
- exitCode: result.exitCode === 0 ? 1 : result.exitCode,
186
- output: result.output,
187
- errors: [...result.errors, error.message]
188
- };
189
- }
190
- return {
191
- exitCode: 1,
192
- output: [],
193
- errors: [error.message]
194
- };
195
- }
196
- const errorMessage = this.handleError(error);
197
- if (command) {
198
- const result = getCommandResult(command);
199
- return {
200
- exitCode: result.exitCode === 0 ? 1 : result.exitCode,
201
- output: result.output,
202
- errors: [...result.errors, errorMessage]
203
- };
204
- }
205
- return {
206
- exitCode: 1,
207
- output: [],
208
- errors: [errorMessage]
209
- };
210
- }
211
- }
212
- /**
213
- * Check if a command exists by name or alias.
214
- */
215
- has(name) {
216
- const resolved = this.resolveName(name);
217
- return this.commands.has(resolved);
218
- }
219
- /**
220
- * Get a command constructor by name or alias.
221
- */
222
- get(name) {
223
- const resolved = this.resolveName(name);
224
- return this.commands.get(resolved);
225
- }
226
- /**
227
- * Get all registered command constructors.
228
- */
229
- all() {
230
- return new Map(this.commands);
231
- }
232
- /**
233
- * List all commands with their descriptions and aliases.
234
- */
235
- list() {
236
- const result = [];
237
- for (const [name, CommandClass] of this.commands) {
238
- const staticCommand = CommandClass;
239
- const commandAliases = [];
240
- for (const [alias, target] of this.aliases) if (target === name) commandAliases.push(alias);
241
- result.push({
242
- name,
243
- description: staticCommand.description,
244
- aliases: commandAliases
245
- });
246
- }
247
- return result.sort((a, b) => a.name.localeCompare(b.name));
248
- }
249
- /**
250
- * Generate a compact listing of all commands with visual hierarchy and colors.
251
- */
252
- async listUsage(options) {
253
- const commands = this.list();
254
- const { generateListing } = await import("./usage-generator-C9hWziY4.mjs").then((n) => n.n);
255
- return generateListing(commands, this.signatures, options);
256
- }
257
- /**
258
- * Get auto-generated usage text for a command.
259
- */
260
- async usage(name) {
261
- const resolvedName = this.resolveName(name);
262
- const CommandClass = this.commands.get(resolvedName);
263
- if (!CommandClass) throw new CommandNotFoundError(name);
264
- const signature = this.signatures.get(resolvedName);
265
- const staticCommand = CommandClass;
266
- const { generateUsage } = await import("./usage-generator-C9hWziY4.mjs").then((n) => n.n);
267
- return generateUsage(signature, staticCommand.description);
268
- }
269
- /**
270
- * Register a command constructor with the registry.
271
- * @internal Called by Application during bootstrap.
272
- */
273
- register(commandClass) {
274
- const staticCommand = commandClass;
275
- if (!staticCommand.command) throw new CommandError(`Command class ${commandClass.name} is missing static "command" signature`);
276
- const signature = parseSignature(staticCommand.command);
277
- const name = signature.name;
278
- if (this.commands.has(name) || this.aliases.has(name)) throw new CommandError(`Duplicate command name: "${name}" is already registered`);
279
- if (staticCommand.aliases) {
280
- for (const alias of staticCommand.aliases) if (this.commands.has(alias) || this.aliases.has(alias)) throw new CommandError(`Duplicate alias: "${alias}" conflicts with an existing command or alias`);
281
- }
282
- this.commands.set(name, commandClass);
283
- this.signatures.set(name, signature);
284
- if (staticCommand.aliases) for (const alias of staticCommand.aliases) this.aliases.set(alias, name);
285
- }
286
- handleError(error) {
287
- return this.container.resolve(DI_TOKENS.ErrorHandler).handle(error).message;
288
- }
289
- resolveName(name) {
290
- return this.aliases.get(name) ?? name;
291
- }
292
- applyDefaults(input, signature) {
293
- const result = { ...input };
294
- for (const arg of signature.arguments) if (result[arg.name] === void 0 && arg.default !== void 0) result[arg.name] = arg.default;
295
- for (const opt of signature.options) if (result[opt.name] === void 0) {
296
- if (opt.default !== void 0) result[opt.name] = opt.default;
297
- else if (opt.isFlag) result[opt.name] = false;
298
- }
299
- return result;
300
- }
301
- };
302
- QuarryRegistry = __decorate([
303
- Transient(DI_TOKENS.Quarry),
304
- __decorateParam(0, inject(DI_TOKENS.Container)),
305
- __decorateMetadata("design:paramtypes", [Object])
306
- ], QuarryRegistry);
307
- //#endregion
308
- export { parseSignature as n, CommandNotFoundError as r, QuarryRegistry as t };
309
-
310
- //# sourceMappingURL=quarry-registry-DCwqVcRp.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"quarry-registry-DCwqVcRp.mjs","names":[],"sources":["../src/quarry/command-internals.ts","../src/quarry/errors/command-not-found.error.ts","../src/quarry/signature-parser.ts","../src/quarry/quarry-registry.ts"],"sourcesContent":["import type { Command } from './command'\nimport { COMMAND_INTERNALS } from './constants'\nimport type { CommandInput, CommandInternals, CommandResult } from './types'\n\n/** @internal Set the flat input values before calling handle() */\nexport function setCommandInputs(command: Command, values: CommandInput): void {\n command[COMMAND_INTERNALS].inputs = { ...values }\n}\n\n/** @internal Set the Quarry reference for this.call() support */\nexport function setCommandQuarry(\n command: Command,\n quarry: { call(name: string, input?: CommandInput): Promise<CommandResult> },\n): void {\n command[COMMAND_INTERNALS].quarry = quarry\n}\n\n/** @internal Collect the result after handle() completes */\nexport function getCommandResult(command: Command): CommandResult {\n const internals: CommandInternals = command[COMMAND_INTERNALS]\n return {\n exitCode: internals.exitCode,\n output: [...internals.output],\n errors: [...internals.errors],\n }\n}\n\n/** @internal Reset state between invocations */\nexport function resetCommandState(command: Command): void {\n const internals: CommandInternals = command[COMMAND_INTERNALS]\n internals.inputs = {}\n internals.output = []\n internals.errors = []\n internals.exitCode = 0\n}\n","/**\n * Thrown when a command is not found in the Quarry registry.\n */\nexport class CommandNotFoundError extends Error {\n constructor(name: string) {\n super(`Command \"${name}\" is not registered.`)\n this.name = 'CommandNotFoundError'\n }\n}\n","import { CommandError } from './errors/command.error'\nimport type { ParsedArgument, ParsedOption, ParsedSignature } from './types'\n\n/**\n * Parse a Laravel-style command signature string.\n *\n * Signature syntax:\n * command-name {arg} ... — flat command\n * group subcommand {arg} ... — subcommand hierarchy (space-separated)\n * namespace:command {arg} ... — namespaced flat command (colon-separated)\n * {--flag} {--name=} {--name=default} {--name=*} {--A|name} {--name= : desc}\n *\n * Pure function, zero dependencies, edge-compatible.\n */\nexport function parseSignature(signature: string): ParsedSignature {\n const tokens = extractTokens(signature)\n const name = extractCommandName(signature)\n const args: ParsedArgument[] = []\n const options: ParsedOption[] = []\n\n for (const token of tokens) {\n const inner = token.slice(1, -1).trim() // strip { }\n\n if (inner.startsWith('--')) {\n options.push(parseOption(inner))\n } else {\n args.push(parseArgument(inner))\n }\n }\n\n return { name, arguments: args, options }\n}\n\nfunction extractCommandName(signature: string): string {\n const match = /^[\\w:.-]+(?:\\s+[\\w:.-]+)*/.exec(signature)\n if (!match) {\n throw new CommandError(`Invalid signature: cannot extract command name from \"${signature}\"`)\n }\n return match[0]\n}\n\nfunction extractTokens(signature: string): string[] {\n const tokens: string[] = []\n const regex = /\\{[^}]+\\}/g\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(signature)) !== null) {\n tokens.push(match[0])\n }\n\n return tokens\n}\n\nfunction parseArgument(inner: string): ParsedArgument {\n const { value, description } = splitDescription(inner)\n\n // {name*} — array/variadic argument\n if (value.endsWith('*')) {\n return {\n name: value.slice(0, -1).trim(),\n required: true,\n isArray: true,\n description,\n }\n }\n\n // {name=default} — argument with default value\n const eqIdx = value.indexOf('=')\n if (eqIdx !== -1) {\n return {\n name: value.slice(0, eqIdx).trim(),\n required: false,\n default: value.slice(eqIdx + 1).trim(),\n isArray: false,\n description,\n }\n }\n\n // {name?} — optional argument\n if (value.endsWith('?')) {\n return {\n name: value.slice(0, -1).trim(),\n required: false,\n isArray: false,\n description,\n }\n }\n\n // {name} — required argument\n return {\n name: value.trim(),\n required: true,\n isArray: false,\n description,\n }\n}\n\nfunction parseOption(inner: string): ParsedOption {\n // Remove leading --\n const withoutDashes = inner.slice(2)\n const { value, description } = splitDescription(withoutDashes)\n\n // Check for alias: {--A|name...}\n let alias: string | undefined\n let optBody = value\n\n const pipeIdx = optBody.indexOf('|')\n if (pipeIdx !== -1) {\n alias = optBody.slice(0, pipeIdx).trim()\n optBody = optBody.slice(pipeIdx + 1).trim()\n }\n\n // {--name=*} — array option\n if (optBody.endsWith('=*')) {\n return {\n name: optBody.slice(0, -2).trim(),\n alias,\n isFlag: false,\n isArray: true,\n description,\n }\n }\n\n // {--name=default} — option with default value\n const eqIdx = optBody.indexOf('=')\n if (eqIdx !== -1) {\n const name = optBody.slice(0, eqIdx).trim()\n const defaultValue = optBody.slice(eqIdx + 1).trim()\n\n return {\n name,\n alias,\n isFlag: false,\n isArray: false,\n default: defaultValue || undefined,\n description,\n }\n }\n\n // {--flag} — boolean flag\n return {\n name: optBody.trim(),\n alias,\n isFlag: true,\n isArray: false,\n description,\n }\n}\n\nfunction splitDescription(value: string): { value: string; description?: string } {\n const colonIdx = value.indexOf(' : ')\n if (colonIdx === -1) {\n return { value }\n }\n\n return {\n value: value.slice(0, colonIdx).trim(),\n description: value.slice(colonIdx + 3).trim(),\n }\n}\n","import { inject } from 'tsyringe'\nimport type { Container } from '../di/container'\nimport { Transient } from '../di/decorators'\nimport { DI_TOKENS } from '../di/tokens'\nimport type { GlobalErrorHandler } from '../errors/global-error-handler'\nimport type { Constructor } from '../types'\nimport { Command } from './command'\nimport { getCommandResult, setCommandInputs, setCommandQuarry } from './command-internals'\nimport { CommandNotFoundError } from './errors/command-not-found.error'\nimport { CommandError } from './errors/command.error'\nimport { parseSignature } from './signature-parser'\nimport type { CommandInput, CommandResult, ParsedSignature, Quarry } from './types'\n\n/**\n * QuarryRegistry — edge-compatible programmatic API for running commands.\n *\n * Registered as a singleton via DI_TOKENS.Quarry.\n * Commands are auto-discovered from module providers and registered at bootstrap.\n * Command constructors are stored at bootstrap; fresh instances are resolved per `call()`.\n *\n * Users should inject and type as `Quarry` (the interface), which only exposes `call()`.\n */\n@Transient(DI_TOKENS.Quarry)\nexport class QuarryRegistry implements Quarry {\n private commands = new Map<string, Constructor<Command>>()\n private signatures = new Map<string, ParsedSignature>()\n private aliases = new Map<string, string>()\n\n constructor(@inject(DI_TOKENS.Container) private readonly container: Container) { }\n\n /**\n * Execute a command by name with optional flat input.\n * A fresh command instance is resolved from the container per invocation.\n */\n async call(name: string, input?: CommandInput): Promise<CommandResult> {\n const resolvedName = this.resolveName(name)\n const CommandClass = this.commands.get(resolvedName)\n\n if (!CommandClass) {\n throw new CommandNotFoundError(name)\n }\n\n const signature = this.signatures.get(resolvedName)!\n const mergedInput = this.applyDefaults(input ?? {}, signature)\n\n // Validate required arguments\n for (const arg of signature.arguments) {\n if (arg.required && (mergedInput[arg.name] === undefined || mergedInput[arg.name] === null)) {\n throw new CommandError(`Missing required argument: ${arg.name}`)\n }\n }\n\n let command: Command | undefined\n\n try {\n // Resolve a fresh instance per invocation to avoid shared mutable state\n command = this.container.resolve<Command>(CommandClass)\n\n setCommandQuarry(command, this)\n setCommandInputs(command, mergedInput)\n\n const exitCode = await command.handle()\n const result = getCommandResult(command)\n\n if (typeof exitCode === 'number') {\n return { ...result, exitCode }\n }\n\n return result\n } catch (error) {\n if (error instanceof CommandError) {\n if (command) {\n const result = getCommandResult(command)\n return {\n exitCode: result.exitCode === 0 ? 1 : result.exitCode,\n output: result.output,\n errors: [...result.errors, error.message],\n }\n }\n return { exitCode: 1, output: [], errors: [error.message] }\n }\n\n const errorMessage = this.handleError(error)\n\n if (command) {\n const result = getCommandResult(command)\n return {\n exitCode: result.exitCode === 0 ? 1 : result.exitCode,\n output: result.output,\n errors: [...result.errors, errorMessage],\n }\n }\n return { exitCode: 1, output: [], errors: [errorMessage] }\n }\n }\n\n /**\n * Check if a command exists by name or alias.\n */\n has(name: string): boolean {\n const resolved = this.resolveName(name)\n return this.commands.has(resolved)\n }\n\n /**\n * Get a command constructor by name or alias.\n */\n get(name: string): Constructor<Command> | undefined {\n const resolved = this.resolveName(name)\n return this.commands.get(resolved)\n }\n\n /**\n * Get all registered command constructors.\n */\n all(): Map<string, Constructor<Command>> {\n return new Map(this.commands)\n }\n\n /**\n * List all commands with their descriptions and aliases.\n */\n list(): { name: string; description?: string; aliases: string[] }[] {\n const result: { name: string; description?: string; aliases: string[] }[] = []\n\n for (const [name, CommandClass] of this.commands) {\n const staticCommand = CommandClass as unknown as typeof Command\n const commandAliases: string[] = []\n\n for (const [alias, target] of this.aliases) {\n if (target === name) {\n commandAliases.push(alias)\n }\n }\n\n result.push({\n name,\n description: staticCommand.description,\n aliases: commandAliases,\n })\n }\n\n return result.sort((a, b) => a.name.localeCompare(b.name))\n }\n\n /**\n * Generate a compact listing of all commands with visual hierarchy and colors.\n */\n async listUsage(options?: { binaryName?: string; binaryLabel?: string; binaryVersion?: string }): Promise<string> {\n const commands = this.list()\n\n // Dynamic import to keep usage-generator tree-shakeable\n const { generateListing } = await import('./usage-generator')\n return generateListing(commands, this.signatures, options)\n }\n\n /**\n * Get auto-generated usage text for a command.\n */\n async usage(name: string): Promise<string> {\n const resolvedName = this.resolveName(name)\n const CommandClass = this.commands.get(resolvedName)\n\n if (!CommandClass) {\n throw new CommandNotFoundError(name)\n }\n\n const signature = this.signatures.get(resolvedName)!\n const staticCommand = CommandClass as unknown as typeof Command\n\n // Dynamic import to keep usage-generator tree-shakeable\n const { generateUsage } = await import('./usage-generator')\n return generateUsage(signature, staticCommand.description)\n }\n\n /**\n * Register a command constructor with the registry.\n * @internal Called by Application during bootstrap.\n */\n register(commandClass: Constructor<Command>): void {\n const staticCommand = commandClass as unknown as typeof Command\n\n if (!staticCommand.command) {\n throw new CommandError(`Command class ${commandClass.name} is missing static \"command\" signature`)\n }\n\n const signature = parseSignature(staticCommand.command)\n const name = signature.name\n\n if (this.commands.has(name) || this.aliases.has(name)) {\n throw new CommandError(`Duplicate command name: \"${name}\" is already registered`)\n }\n\n // Validate all aliases before any mutation\n if (staticCommand.aliases) {\n for (const alias of staticCommand.aliases) {\n if (this.commands.has(alias) || this.aliases.has(alias)) {\n throw new CommandError(`Duplicate alias: \"${alias}\" conflicts with an existing command or alias`)\n }\n }\n }\n\n // All checks passed — safe to mutate\n this.commands.set(name, commandClass)\n this.signatures.set(name, signature)\n\n if (staticCommand.aliases) {\n for (const alias of staticCommand.aliases) {\n this.aliases.set(alias, name)\n }\n }\n }\n\n private handleError(error: unknown): string {\n const errorHandler = this.container.resolve<GlobalErrorHandler>(DI_TOKENS.ErrorHandler)\n const response = errorHandler.handle(error)\n return response.message\n }\n\n private resolveName(name: string): string {\n return this.aliases.get(name) ?? name\n }\n\n private applyDefaults(input: CommandInput, signature: ParsedSignature): CommandInput {\n const result = { ...input }\n\n // Apply argument defaults\n for (const arg of signature.arguments) {\n if (result[arg.name] === undefined && arg.default !== undefined) {\n result[arg.name] = arg.default\n }\n }\n\n // Apply option defaults\n for (const opt of signature.options) {\n if (result[opt.name] === undefined) {\n if (opt.default !== undefined) {\n result[opt.name] = opt.default\n } else if (opt.isFlag) {\n result[opt.name] = false\n }\n }\n }\n\n return result\n }\n}\n"],"mappings":";;;;;AAKA,SAAgB,iBAAiB,SAAkB,QAA4B;AAC7E,SAAQ,mBAAmB,SAAS,EAAE,GAAG,QAAQ;;;AAInD,SAAgB,iBACd,SACA,QACM;AACN,SAAQ,mBAAmB,SAAS;;;AAItC,SAAgB,iBAAiB,SAAiC;CAChE,MAAM,YAA8B,QAAQ;AAC5C,QAAO;EACL,UAAU,UAAU;EACpB,QAAQ,CAAC,GAAG,UAAU,OAAO;EAC7B,QAAQ,CAAC,GAA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,UAAU,UAAU,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"queue.module-BZvmeAMj.mjs","names":[],"sources":["../src/queue/consumer-registry.ts","../src/queue/queue-sender.ts","../src/queue/queue.tokens.ts","../src/queue/errors/queue-binding-not-found.error.ts","../src/queue/errors/queue-provider-not-supported.error.ts","../src/queue/providers/cloudflare-queue.provider.ts","../src/queue/providers/sync-queue.provider.ts","../src/queue/services/queue-provider-factory.ts","../src/queue/queue-registry.ts","../src/queue/queue.module.ts"],"sourcesContent":["import { Transient } from '../di/decorators'\nimport { DI_TOKENS } from '../di/tokens'\nimport type { IQueueConsumer } from './queue-consumer'\n\n/**\n * Consumer Registry\n *\n * Singleton service that holds all registered queue consumers indexed by message type.\n * Consumers declare the message types they handle, and this registry routes messages\n * to the appropriate consumers based on their types.\n *\n * **Message-Type Routing:**\n * - Consumers declare `messageTypes` array (e.g., `['email.send', 'email.batch.send']`)\n * - When a message arrives, consumers matching the message type are invoked\n * - A consumer can handle messages from ANY queue (routing is by type, not queue)\n * - Use `'*'` as a wildcard to handle all message types\n *\n * @example Consumer registration\n * ```typescript\n * // In consumer.ts\n * @Transient()\n * export class EmailConsumer implements IQueueConsumer {\n * readonly messageTypes = ['email.send', 'email.batch.send']\n * // ...\n * }\n *\n * // In module.ts\n * @Module({\n * consumers: [EmailConsumer]\n * })\n *\n * // Application auto-registers via ConsumerRegistry\n * this.consumerRegistry.register(consumer)\n * ```\n */\n@Transient(DI_TOKENS.ConsumerRegistry)\nexport class ConsumerRegistry {\n /** Map from message type to consumers handling that type */\n private consumersByType = new Map<string, IQueueConsumer[]>()\n\n /** Set of all registered consumers (for iteration) */\n private allConsumers = new Set<IQueueConsumer>()\n\n /**\n * Register a queue consumer\n *\n * Indexes the consumer by each of its declared message types.\n *\n * @param consumer - Queue consumer to register\n */\n register(consumer: IQueueConsumer): void {\n if (this.allConsumers.has(consumer)) {\n return // Already registered\n }\n\n this.allConsumers.add(consumer)\n\n for (const messageType of consumer.messageTypes) {\n const existing = this.consumersByType.get(messageType) ?? []\n existing.push(consumer)\n this.consumersByType.set(messageType, existing)\n }\n }\n\n /**\n * Get all consumers that can handle a specific message type\n *\n * Returns consumers that either:\n * - Explicitly declare the message type\n * - Use '*' wildcard to handle all types\n *\n * @param messageType - The message type to find consumers for\n * @returns Array of consumers that can handle this message type\n */\n getConsumers(messageType: string): IQueueConsumer[] {\n const exactMatch = this.consumersByType.get(messageType) ?? []\n const wildcardMatch = this.consumersByType.get('*') ?? []\n\n // Combine and dedupe\n const combined = new Set([...exactMatch, ...wildcardMatch])\n return Array.from(combined)\n }\n\n /**\n * Check if any consumers can handle a message type\n *\n * @param messageType - The message type to check\n * @returns true if at least one consumer can handle this type\n */\n hasConsumers(messageType: string): boolean {\n return this.getConsumers(messageType).length > 0\n }\n\n /**\n * Get all registered message types\n *\n * @returns Array of message types with registered consumers\n */\n getMessageTypes(): string[] {\n return Array.from(this.consumersByType.keys())\n }\n\n /**\n * Get all registered consumers\n *\n * @returns Array of all registered consumers\n */\n getAllConsumers(): IQueueConsumer[] {\n return Array.from(this.allConsumers)\n }\n}\n","import type { II18nService } from '../i18n/i18n.types'\nimport type { IQueueProvider } from './providers'\nimport type { QueueMessage } from './queue-consumer'\nimport type { DispatchMessage, IQueueSender } from './queue-sender.interface'\n\n/**\n * Queue Sender\n *\n * Implementation of IQueueSender bound to a specific queue name.\n * Created by QueueRegistry for each registered queue.\n *\n * Automatically enriches messages with:\n * - `id`: UUID generated via crypto.randomUUID()\n * - `timestamp`: Current time in milliseconds\n * - `metadata.locale`: Current locale from I18n context\n *\n * @example\n * ```typescript\n * // Created by QueueRegistry, not directly instantiated\n * const sender = registry.getQueue('notifications-queue')\n *\n * await sender.dispatch({\n * type: 'email.send',\n * payload: { to: 'user@example.com', subject: 'Hello' }\n * })\n * ```\n */\nexport class QueueSender implements IQueueSender {\n constructor(\n private readonly queueName: string,\n private readonly provider: IQueueProvider,\n private readonly i18n: II18nService\n ) {}\n\n /**\n * Dispatch a message to this queue.\n *\n * @param message - Message to dispatch (without id/timestamp)\n */\n async dispatch<T>(message: DispatchMessage<T>): Promise<void> {\n const metadata = { ...message.metadata }\n\n if (!metadata.locale) {\n const locale = this.i18n.getLocale()\n if (locale) {\n metadata.locale = locale\n }\n }\n\n const fullMessage: QueueMessage<T> = {\n id: crypto.randomUUID(),\n timestamp: Date.now(),\n ...message,\n metadata: Object.keys(metadata).length > 0 ? metadata : undefined\n }\n\n await this.provider.send(this.queueName, fullMessage)\n }\n}\n","export const QUEUE_TOKENS = {\n QueueProviderFactory: Symbol.for('stratal:queue:provider:factory'),\n QueueRegistry: Symbol.for('stratal:queue:registry'),\n QueueModuleOptions: Symbol.for('stratal:queue:options'),\n} as const\n\nexport type QueueToken = (typeof QUEUE_TOKENS)[keyof typeof QUEUE_TOKENS]\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * QueueBindingNotFoundError\n *\n * Thrown when attempting to access a Cloudflare Queue binding that hasn't been configured.\n * This typically indicates that the queue binding is missing from wrangler.jsonc\n * or the environment variables are not properly set.\n */\nexport class QueueBindingNotFoundError extends ApplicationError {\n constructor(queueName: string, bindingName: string) {\n super(\n 'errors.queueBindingNotFound',\n ERROR_CODES.SYSTEM.QUEUE_BINDING_NOT_FOUND,\n { queueName, bindingName }\n )\n }\n}\n","import { ApplicationError, ERROR_CODES } from '../../errors'\n\n/**\n * QueueProviderNotSupportedError\n *\n * Thrown when attempting to use a queue provider that is not supported.\n * Valid providers are: 'cloudflare', 'sync'\n *\n * This typically indicates an invalid QUEUE_PROVIDER environment variable.\n */\nexport class QueueProviderNotSupportedError extends ApplicationError {\n constructor(provider: string) {\n super(\n 'errors.queueProviderNotSupported',\n ERROR_CODES.SYSTEM.QUEUE_PROVIDER_NOT_SUPPORTED,\n { provider }\n )\n }\n}\n","import { inject } from 'tsyringe'\nimport { type StratalEnv } from '../../env'\nimport { Transient } from '../../di/decorators'\nimport { DI_TOKENS } from '../../di/tokens'\nimport { QueueBindingNotFoundError } from '../errors'\nimport type { QueueMessage } from '../queue-consumer'\nimport type { IQueueProvider } from './queue-provider.interface'\n\n/**\n * Cloudflare Queue Provider\n *\n * Sends messages to Cloudflare Queues by resolving bindings from the environment.\n * Used in production environments where Cloudflare Workers handle queue processing.\n *\n * **Binding Resolution:**\n * Queue names are converted to binding names:\n * - `notifications-queue` → `NOTIFICATIONS_QUEUE`\n *\n * @example\n * ```typescript\n * const provider = new CloudflareQueueProvider(env)\n * await provider.send('notifications-queue', message)\n * ```\n */\n@Transient()\nexport class CloudflareQueueProvider implements IQueueProvider {\n constructor(\n @inject(DI_TOKENS.CloudflareEnv) private readonly env: StratalEnv\n ) { }\n\n /**\n * Send a message to a Cloudflare Queue\n *\n * @param queueName - Queue name (e.g., 'notifications-queue')\n * @param message - Complete message with id, timestamp, and payload\n * @throws {QueueBindingNotFoundError} If queue binding is not configured\n */\n async send<T>(queueName: string, message: QueueMessage<T>): Promise<void> {\n const queue = this.getQueue(queueName)\n await queue.send(message)\n }\n\n /**\n * Resolve queue binding from Cloudflare environment\n *\n * Converts kebab-case queue name to UPPER_SNAKE_CASE binding name.\n *\n * @param queueName - Queue name (e.g., 'notifications-queue')\n * @returns Cloudflare Queue binding\n * @throws {QueueBindingNotFoundError} If binding not found in env\n */\n private getQueue(queueName: string): Queue {\n const bindingName = queueName.toUpperCase().replace(/-/g, '_')\n const queue = (this.env as unknown as Record<string, unknown>)[bindingName] as Queue | undefined\n\n if (!queue) {\n throw new QueueBindingNotFoundError(queueName, bindingName)\n }\n\n return queue\n }\n}\n","import { inject } from 'tsyringe'\nimport { Transient } from '../../di/decorators'\nimport { DI_TOKENS } from '../../di/tokens'\nimport { ConsumerRegistry } from '../consumer-registry'\nimport type { QueueMessage } from '../queue-consumer'\nimport type { IQueueProvider } from './queue-provider.interface'\n\n/**\n * Sync Queue Provider\n *\n * Processes messages immediately by finding matching consumers and calling\n * their handle() method directly. Used for testing and development where\n * real queue infrastructure is not available.\n *\n * **Behavior:**\n * - Messages are processed synchronously when send() is called\n * - Matching consumers are found via ConsumerRegistry by message type\n * - All matching consumers are called sequentially\n * - Errors are re-thrown after onError() is called (fail-fast for testing)\n *\n * **Consumer Matching:**\n * - Consumers are matched by message type, not queue name\n * - Wildcard ('*') matches all message types\n *\n * @example Testing with sync provider\n * ```typescript\n * const provider = new SyncQueueProvider(registry)\n * await provider.send('notifications-queue', {\n * id: '123',\n * timestamp: Date.now(),\n * type: 'email.send',\n * payload: { to: 'test@example.com' }\n * })\n * // Consumer's handle() is called immediately!\n * ```\n */\n@Transient()\nexport class SyncQueueProvider implements IQueueProvider {\n constructor(\n @inject(DI_TOKENS.ConsumerRegistry) private readonly registry: ConsumerRegistry\n ) {}\n\n /**\n * Process a message synchronously\n *\n * Finds all matching consumers by message type and calls their handle() method.\n * If any consumer throws, onError() is called and the error is re-thrown.\n *\n * @param _queueName - Queue name (not used for routing, consumers match by message type)\n * @param message - Complete message with id, timestamp, and payload\n * @throws Re-throws any error from consumer.handle() after calling onError()\n */\n async send<T>(_queueName: string, message: QueueMessage<T>): Promise<void> {\n // Consumers are matched by message type, not queue name\n const consumers = this.registry.getConsumers(message.type)\n\n // Process synchronously - call each matching consumer\n for (const consumer of consumers) {\n try {\n await consumer.handle(message)\n } catch (error) {\n const errorInstance = error instanceof Error\n ? error\n : new Error(String(error))\n\n // Call onError hook if defined\n if (consumer.onError) {\n await consumer.onError(errorInstance, message)\n }\n\n // Re-throw for fail-fast behavior in tests\n throw errorInstance\n }\n }\n }\n}\n","import { inject } from 'tsyringe'\nimport { type StratalEnv } from '../../env'\nimport { Transient } from '../../di/decorators'\nimport { DI_TOKENS } from '../../di/tokens'\nimport { ConsumerRegistry } from '../consumer-registry'\nimport { QueueProviderNotSupportedError } from '../errors'\nimport { CloudflareQueueProvider, SyncQueueProvider, type IQueueProvider } from '../providers'\nimport type { QueueModuleOptions } from '../queue.module'\nimport { QUEUE_TOKENS } from '../queue.tokens'\n\n/**\n * Queue Provider Factory\n *\n * Creates the appropriate queue provider based on configuration provided\n * via QueueModule.forRootAsync().\n *\n * **Provider Selection:**\n * - `cloudflare`: Production provider using Cloudflare Queue bindings\n * - `sync`: Testing provider that processes messages immediately\n *\n * @example\n * ```typescript\n * // Configuration via QueueModule.forRootAsync()\n * QueueModule.forRootAsync({\n * inject: [CONFIG_TOKENS.ConfigService],\n * useFactory: (config) => ({ provider: config.get('queue').provider })\n * })\n *\n * // Factory usage (internal)\n * const factory = container.resolve(QueueProviderFactory)\n * const provider = factory.create()\n * ```\n */\n@Transient(QUEUE_TOKENS.QueueProviderFactory)\nexport class QueueProviderFactory {\n constructor(\n @inject(DI_TOKENS.CloudflareEnv) private readonly env: StratalEnv,\n @inject(DI_TOKENS.ConsumerRegistry) private readonly registry: ConsumerRegistry,\n @inject(QUEUE_TOKENS.QueueModuleOptions, { isOptional: true }) private readonly options?: QueueModuleOptions,\n ) { }\n\n /**\n * Create a queue provider based on module configuration\n *\n * @returns Queue provider instance\n * @throws {QueueProviderNotSupportedError} If provider type is not supported\n */\n create(): IQueueProvider {\n const providerType = this.options?.provider ?? 'cloudflare'\n\n switch (providerType) {\n case 'cloudflare':\n return new CloudflareQueueProvider(this.env)\n\n case 'sync':\n return new SyncQueueProvider(this.registry)\n\n default:\n throw new QueueProviderNotSupportedError(providerType)\n }\n }\n}\n","import { inject } from 'tsyringe'\nimport { Transient } from '../di/decorators'\nimport { I18N_TOKENS } from '../i18n/i18n.tokens'\nimport type { II18nService } from '../i18n/i18n.types'\nimport type { IQueueProvider } from './providers'\nimport type { IQueueSender } from './queue-sender.interface'\nimport { QueueSender } from './queue-sender'\nimport { QUEUE_TOKENS } from './queue.tokens'\nimport { QueueProviderFactory } from './services'\n\n/**\n * Queue Registry\n *\n * Request-scoped factory service for creating QueueSender instances.\n * Caches senders per queue name within the request scope.\n *\n * This service is used internally by QueueModule.registerQueue() to provide\n * IQueueSender instances for each registered queue.\n *\n * **Why request-scoped?**\n * - Needs access to I18nService for locale-aware message metadata\n * - Provider is created once per request for consistency\n * - Queue senders are cached per request to avoid recreating them\n *\n * @example\n * ```typescript\n * // Used internally by QueueModule.registerQueue()\n * QueueModule.registerQueue('notifications-queue')\n *\n * // The module creates a factory provider:\n * {\n * provide: 'notifications-queue',\n * useFactory: (registry: QueueRegistry) => registry.getQueue('notifications-queue'),\n * inject: [QUEUE_TOKENS.QueueRegistry],\n * }\n * ```\n */\n@Transient(QUEUE_TOKENS.QueueRegistry)\nexport class QueueRegistry {\n private readonly provider: IQueueProvider\n private readonly senders = new Map<string, IQueueSender>()\n\n constructor(\n @inject(QUEUE_TOKENS.QueueProviderFactory) providerFactory: QueueProviderFactory,\n @inject(I18N_TOKENS.I18nService) private readonly i18n: II18nService\n ) {\n this.provider = providerFactory.create()\n }\n\n /**\n * Get or create a QueueSender for the specified queue name.\n *\n * Senders are cached per queue name within the request scope.\n *\n * @param queueName - The queue name to get a sender for\n * @returns QueueSender bound to the specified queue\n */\n getQueue(queueName: string): IQueueSender {\n let sender = this.senders.get(queueName)\n\n if (!sender) {\n sender = new QueueSender(queueName, this.provider, this.i18n)\n this.senders.set(queueName, sender)\n }\n\n return sender\n }\n}\n","/**\n * Queue Module\n *\n * Provides declarative queue infrastructure with provider abstraction.\n *\n * **Usage:**\n * ```typescript\n * // 1. Configure provider (once, in app root)\n * QueueModule.forRootAsync({\n * inject: [CONFIG_TOKENS.ConfigService],\n * useFactory: (config) => ({ provider: config.get('queue').provider })\n * })\n *\n * // 2. Register queues (queue name IS the injection token)\n * QueueModule.registerQueue('notifications-queue')\n * QueueModule.registerQueue('batch-notifications-queue')\n *\n * // 3. Inject and use\n * constructor(@InjectQueue('notifications-queue') private queue: IQueueSender) {}\n * await this.queue.dispatch({ type: 'email.send', payload: {...} })\n * ```\n *\n * **Providers:**\n * - `cloudflare`: Production provider using Cloudflare Queue bindings\n * - `sync`: Testing provider that processes messages immediately\n */\n\nimport { DI_TOKENS } from '../di/tokens'\nimport { Scope } from '../di/types'\nimport { Module } from '../module'\nimport type { AsyncModuleOptions, DynamicModule, InjectionToken } from '../module/types'\nimport { ConsumerRegistry } from './consumer-registry'\nimport type { QueueName } from './queue-name'\nimport { QueueRegistry } from './queue-registry'\nimport type { IQueueSender } from './queue-sender.interface'\nimport { QUEUE_TOKENS } from './queue.tokens'\nimport { QueueProviderFactory } from './services'\n\n/**\n * Queue module configuration options\n */\nexport interface QueueModuleOptions {\n /**\n * Queue provider type\n * - 'cloudflare': Production provider using Cloudflare Queue bindings\n * - 'sync': Testing provider that processes messages immediately\n */\n provider: 'cloudflare' | 'sync'\n}\n\n@Module({\n providers: [\n { provide: DI_TOKENS.ConsumerRegistry, useClass: ConsumerRegistry, scope: Scope.Singleton },\n { provide: QUEUE_TOKENS.QueueProviderFactory, useClass: QueueProviderFactory, scope: Scope.Singleton },\n { provide: QUEUE_TOKENS.QueueRegistry, useClass: QueueRegistry },\n ],\n})\nexport class QueueModule {\n /**\n * Configure queue infrastructure with async factory.\n *\n * Use when provider configuration depends on other services like ConfigService.\n *\n * @param options - Async configuration with factory and inject tokens\n * @returns Dynamic module with queue infrastructure\n *\n * @example\n * ```typescript\n * QueueModule.forRootAsync({\n * inject: [CONFIG_TOKENS.ConfigService],\n * useFactory: (config: IConfigService) => ({\n * provider: config.get('queue').provider\n * })\n * })\n * ```\n */\n static forRootAsync(options: AsyncModuleOptions<QueueModuleOptions>): DynamicModule {\n return {\n module: QueueModule,\n providers: [\n {\n provide: QUEUE_TOKENS.QueueModuleOptions,\n useFactory: options.useFactory,\n inject: options.inject,\n },\n ],\n }\n }\n\n /**\n * Register a queue for injection.\n *\n * The queue name serves as both the identifier and the DI injection token.\n * Queue names are typed via module augmentation of QueueNames interface.\n *\n * @param name - Queue name (typed with autocomplete if QueueNames is augmented)\n * @returns Dynamic module that provides the queue sender\n *\n * @example\n * ```typescript\n * // In AppModule imports\n * QueueModule.registerQueue('notifications-queue')\n *\n * // Then inject using the queue name\n * constructor(@InjectQueue('notifications-queue') private queue: IQueueSender) {}\n * ```\n */\n static registerQueue(name: QueueName): DynamicModule {\n return {\n module: QueueModule,\n providers: [\n {\n provide: name as InjectionToken<IQueueSender>,\n useFactory: (registry: QueueRegistry) => registry.getQueue(name),\n inject: [QUEUE_TOKENS.QueueRegistry],\n },\n ],\n }\n }\n}\n"],"mappings":";;;;;AAoCO,IAAA,mBAAA,MAAM,iBAAiB;;CAE5B,kCAA0B,IAAI,KAA+B;;CAG7D,+BAAuB,IAAI,KAAqB;;;;;;;;CAShD,SAAS,UAAgC;AACvC,MAAI,KAAK,aAAa,IAAI,SAAS,CACjC;AAGF,OAAK,aAAa,IAAI,SAAS;AAE/B,OAAK,MAAM,eAAe,SAAS,cAAc;GAC/C,MAAM,WAAW,KAAK,gBAAgB,IAAI,YAAY,IAAI,EAAE;AAC5D,YAAS,KAAK,SAAS;AACvB,QAAK,gBAAgB,IAAI,aAAa,SAAS;;;;;;;;;;;;;CAcnD,aAAa,aAAuC;EAClD,MAAM,aAAa,KAAK,gBAAgB,IAAI,YAAY,IAAI,EAAE;EAC9D,MAAM,gBAAgB,KAAK,gBAAgB,IAAI,IAAI,IAAI,EAAE;EAGzD,MAAM,WAAW,IAAI,IAAI,CAAC,GAAG,YAAY,GAAG,cAAc,CAAC;AAC3D,SAAO,MAAM,KAAK,SAAS;;;;;;;;CAS7B,aAAa,aAA8B;AACzC,SAAO,KAAK,aAAa,YAAY,CAAC,SAAS;;;;;;;CAQjD,kBAA4B;AAC1B,SAAO,MAAM,KAAK,KAAK,gBAAgB,MAAM,CAAC;;;;;;;CAQhD,kBAAoC;AAClC,SAAO,MAAM,KAAK,KAAK,aAAa;;;+BAzEvC,UAAU,UAAU,iBAAiB,CAAA,EAAA,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;ACRtC,IAAa,cAAb,MAAiD;CAC/C,YACE,WACA,UACA,MACA;AAHiB,OAAA,YAAA;AACA,OAAA,WAAA;AACA,OAAA,OAAA;;;;;;;CAQnB,MAAM,SAAY,SAA4C;EAC5D,MAAM,WAAW,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CAAA;oBACzC,OAAO,YAAY,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACa7B,IAAA,cAAA,eAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;CAmBvB,OAAO,aAAa,SAAgE;AAClF,SAAO;GACL,QAAA;GACA,WAAW,CACT;IACE,SAAS,aAAa;IACtB,YAAY,QAAQ;IACpB,QAAQ,QAAQ;IACjB,CACF;GACF;;;;;;;;;;;;;;;;;;;;CAqBH,OAAO,cAAc,MAAgC;AACnD,SAAO;GACL,QAAA;GACA,WAAW,CACT;IACE,SAAS;IACT,aAAa,aAA4B,SAAS,SAAS,KAAK;IAChE,QAAQ,CAAC,aAAa,cAAc;IACrC,CACF;GACF;;;yCAnEJ,OAAO,EACN,WAAW;CACT;EAAE,SAAS,UAAU;EAAkB,UAAU;EAAkB,OAAO,MAAM;EAAW;CAC3F;EAAE,SAAS,aAAa;EAAsB,UAAU;EAAsB,OAAO,MAAM;EAAW;CACtG;EAAE,SAAS,aAAa;EAAe,UAAU;EAAe;CACjE,EACF,CAAC,CAAA,EAAA,YAAA"}
@@ -1,264 +0,0 @@
1
- import { n as RequestContainerNotInitializedError } from "./errors-CtCi1wn6.mjs";
2
- import { stream, streamSSE, streamText } from "hono/streaming";
3
- //#region src/router/constants.ts
4
- /**
5
- * Type-safe context keys for Hono router variables
6
- * Using symbols to avoid string collisions
7
- */
8
- const ROUTER_CONTEXT_KEYS = {
9
- REQUEST_CONTAINER: "requestContainer",
10
- LOCALE: "locale"
11
- };
12
- /**
13
- * Metadata keys for storing route and controller configuration
14
- * Using symbols to avoid collisions with other decorators
15
- */
16
- const ROUTE_METADATA_KEYS = {
17
- CONTROLLER_ROUTE: Symbol.for("stratal:controller:route"),
18
- CONTROLLER_OPTIONS: Symbol.for("stratal:controller:options"),
19
- CONTROLLER_MIDDLEWARES: Symbol.for("stratal:controller:middlewares"),
20
- ROUTE_CONFIG: Symbol.for("stratal:route:config"),
21
- DECORATED_METHODS: Symbol.for("stratal:decorated:methods"),
22
- HTTP_ROUTE_CONFIG: Symbol.for("stratal:http-route:config"),
23
- HTTP_DECORATED_METHODS: Symbol.for("stratal:http-decorated:methods"),
24
- AUTH_GUARD: Symbol.for("stratal:auth:guard"),
25
- GATEWAY_MARKER: Symbol.for("stratal:gateway:marker"),
26
- WS_ON_MESSAGE: Symbol.for("stratal:ws:on-message"),
27
- WS_ON_CLOSE: Symbol.for("stratal:ws:on-close"),
28
- WS_ON_ERROR: Symbol.for("stratal:ws:on-error")
29
- };
30
- /**
31
- * Security scheme identifiers for OpenAPI
32
- * These reference the security scheme definitions in security.schemas.ts
33
- */
34
- const SECURITY_SCHEMES = {
35
- BEARER_AUTH: "bearerAuth",
36
- API_KEY: "apiKey",
37
- SESSION_COOKIE: "sessionCookie"
38
- };
39
- /**
40
- * HTTP method mapping for RESTful controller methods
41
- * Maps controller method names to HTTP verbs and path patterns
42
- */
43
- const HTTP_METHODS = {
44
- index: {
45
- method: "get",
46
- path: ""
47
- },
48
- show: {
49
- method: "get",
50
- path: "/:id"
51
- },
52
- create: {
53
- method: "post",
54
- path: ""
55
- },
56
- update: {
57
- method: "put",
58
- path: "/:id"
59
- },
60
- patch: {
61
- method: "patch",
62
- path: "/:id"
63
- },
64
- destroy: {
65
- method: "delete",
66
- path: "/:id"
67
- }
68
- };
69
- /**
70
- * Default success status codes for RESTful controller methods
71
- * Used by @Route() decorator to auto-derive response status
72
- */
73
- const METHOD_STATUS_CODES = {
74
- index: 200,
75
- show: 200,
76
- create: 201,
77
- update: 200,
78
- patch: 200,
79
- destroy: 200
80
- };
81
- /**
82
- * Sentinel symbol to opt a controller out of versioning.
83
- * When used as the version, no prefix is applied even when defaultVersion is set.
84
- */
85
- const VERSION_NEUTRAL = Symbol.for("stratal:version:neutral");
86
- /**
87
- * Default content type for request bodies and responses
88
- */
89
- const DEFAULT_CONTENT_TYPE = "application/json";
90
- //#endregion
91
- //#region src/router/router-context.ts
92
- /**
93
- * Router context wrapper with helper methods
94
- *
95
- * Provides convenient access to Hono's context and common request/response operations.
96
- * The native Hono context is available via the `c` property for advanced use cases.
97
- *
98
- * @example
99
- * ```typescript
100
- * async index(ctx: RouterContext): Promise<Response> {
101
- * // Use helper methods
102
- * const users = await this.service.findAll()
103
- * return ctx.json(users)
104
- * }
105
- *
106
- * async show(ctx: RouterContext): Promise<Response> {
107
- * // Access route params
108
- * const id = ctx.param('id')
109
- * const user = await this.service.findById(id)
110
- * return ctx.json(user)
111
- * }
112
- *
113
- * async create(ctx: RouterContext): Promise<Response> {
114
- * // Parse request body
115
- * const body = await ctx.body<CreateUserInput>()
116
- * const user = await this.service.create(body)
117
- * return ctx.json(user, 201)
118
- * }
119
- * ```
120
- */
121
- var RouterContext = class {
122
- /**
123
- * Native Hono context
124
- * Access for advanced use cases not covered by helper methods
125
- */
126
- constructor(c) {
127
- this.c = c;
128
- }
129
- /**
130
- * Get request-scoped DI container
131
- * Contains request-specific services and context (AuthContext)
132
- *
133
- * @throws Error if container not initialized
134
- */
135
- getContainer() {
136
- const container = this.c.get(ROUTER_CONTEXT_KEYS.REQUEST_CONTAINER);
137
- if (!container) throw new RequestContainerNotInitializedError();
138
- return container;
139
- }
140
- /**
141
- * Set locale for the current request
142
- * Locale is determined by X-Locale header or defaults to config
143
- *
144
- * @param locale - Locale code (e.g., 'en', 'fr')
145
- */
146
- setLocale(locale) {
147
- this.c.set(ROUTER_CONTEXT_KEYS.LOCALE, locale);
148
- }
149
- /**
150
- * Get locale for the current request
151
- *
152
- * @returns Current locale code
153
- */
154
- getLocale() {
155
- return this.c.get(ROUTER_CONTEXT_KEYS.LOCALE) || "en";
156
- }
157
- /**
158
- * Return JSON response
159
- *
160
- * @param data - Data to serialize as JSON
161
- * @param status - HTTP status code (default: 200)
162
- */
163
- json(data, status) {
164
- return this.c.json(data, status);
165
- }
166
- /**
167
- * Get route parameter value
168
- *
169
- * @param key - Parameter name (e.g., 'id' for /users/:id)
170
- */
171
- param(key) {
172
- return this.c.req.valid("param")[key];
173
- }
174
- /**
175
- * Get query parameter value
176
- *
177
- * @param key - Query parameter name
178
- */
179
- query(key) {
180
- const validated = this.c.req.valid("query");
181
- return key ? validated[key] : validated;
182
- }
183
- /**
184
- * Get request header value
185
- *
186
- * @param name - Header name (case-insensitive)
187
- */
188
- header(name) {
189
- return this.c.req.header(name);
190
- }
191
- /**
192
- * Get validated request body from OpenAPI route
193
- * Returns pre-validated data that has passed schema validation
194
- *
195
- * @returns Validated JSON body
196
- */
197
- body() {
198
- return this.c.req.valid("json");
199
- }
200
- /**
201
- * Return text response
202
- *
203
- * @param text - Text content
204
- * @param status - HTTP status code (default: 200)
205
- */
206
- text(text, status) {
207
- return this.c.text(text, status);
208
- }
209
- /**
210
- * Return HTML response
211
- *
212
- * @param html - HTML content
213
- * @param status - HTTP status code (default: 200)
214
- */
215
- html(html, status) {
216
- return this.c.html(html, status);
217
- }
218
- /**
219
- * Redirect to another URL
220
- *
221
- * @param url - Target URL
222
- * @param status - HTTP status code (default: 302)
223
- */
224
- redirect(url, status) {
225
- return this.c.redirect(url, status);
226
- }
227
- /**
228
- * Return a streaming response (binary/generic)
229
- *
230
- * @param callback - Async function that writes to the stream
231
- * @param onError - Optional error handler called if an error occurs during streaming
232
- */
233
- stream(callback, onError) {
234
- return stream(this.c, callback, onError);
235
- }
236
- /**
237
- * Return a streaming text response
238
- *
239
- * Automatically sets `Content-Encoding: Identity` for Cloudflare Workers compatibility.
240
- *
241
- * @param callback - Async function that writes text to the stream
242
- * @param onError - Optional error handler called if an error occurs during streaming
243
- */
244
- streamText(callback, onError) {
245
- this.c.header("Content-Encoding", "Identity");
246
- return streamText(this.c, callback, onError);
247
- }
248
- /**
249
- * Return a Server-Sent Events (SSE) streaming response
250
- *
251
- * Automatically sets `Content-Encoding: Identity` for Cloudflare Workers compatibility.
252
- *
253
- * @param callback - Async function that writes SSE events to the stream
254
- * @param onError - Optional error handler called if an error occurs during streaming
255
- */
256
- streamSSE(callback, onError) {
257
- this.c.header("Content-Encoding", "Identity");
258
- return streamSSE(this.c, callback, onError);
259
- }
260
- };
261
- //#endregion
262
- export { ROUTER_CONTEXT_KEYS as a, VERSION_NEUTRAL as c, METHOD_STATUS_CODES as i, DEFAULT_CONTENT_TYPE as n, ROUTE_METADATA_KEYS as o, HTTP_METHODS as r, SECURITY_SCHEMES as s, RouterContext as t };
263
-
264
- //# sourceMappingURL=router-context-BEJe9HEB.mjs.map