@guren/server 2.9.0 → 2.10.1
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.
- package/dist/DocsViewerServiceProvider-qFCaeiUv.js +77 -0
- package/dist/Hash-CzrwKeDp.js +133 -0
- package/dist/HttpException-BkS3euNG.js +161 -0
- package/dist/Job-BVT813DO.js +441 -0
- package/dist/McpServiceProvider-BoAN-UcD.js +367 -0
- package/dist/MessageSigner-Bd25ZJAV.js +93 -0
- package/dist/Random-DbIJ22KQ.js +191 -0
- package/dist/address-D0Iq-XIH.js +20 -0
- package/dist/auth/index.js +2 -122
- package/dist/auth-C7sVmYgc.js +1954 -0
- package/dist/authorization/index.js +2 -38
- package/dist/authorization-Dbcuc5ZK.js +610 -0
- package/dist/broadcasting/index.js +2 -26
- package/dist/broadcasting-Dw-FhyjN.js +1055 -0
- package/dist/cache/index.js +2 -17
- package/dist/cache/types.d.ts +4 -4
- package/dist/cache-BYnZf2FR.js +812 -0
- package/dist/client-Dd7vLcqp.js +27 -0
- package/dist/console/Output.d.ts +18 -18
- package/dist/discovery/AutoDiscovery.d.ts +8 -0
- package/dist/encryption/index.js +5 -96
- package/dist/encryption-fOWQaKqX.js +250 -0
- package/dist/endpoint-D-20PiHY.js +46 -0
- package/dist/endpoint-D6GIqOpe.js +31 -0
- package/dist/errors-quJOkkCn.js +81 -0
- package/dist/events/index.js +2 -28
- package/dist/events-aIH_bWRx.js +410 -0
- package/dist/health/index.js +2 -24
- package/dist/health-VWdWXRwh.js +345 -0
- package/dist/hot-disposables-WsTX2ySN.js +281 -0
- package/dist/hot-reload/testing.d.ts +1 -1
- package/dist/http/Application.d.ts +0 -1
- package/dist/i18n/index.js +2 -30
- package/dist/i18n-mcWi7LCd.js +617 -0
- package/dist/index.js +7496 -7281
- package/dist/lambda/index.js +114 -71
- package/dist/logging/index.js +2 -24
- package/dist/logging-CPaRMuPP.js +518 -0
- package/dist/loopback-guard-D0Kc7-xc.js +224 -0
- package/dist/mail/index.js +2 -27
- package/dist/mail-DfEfSQEr.js +699 -0
- package/dist/mcp/index.js +2 -10
- package/dist/notifications/index.js +2 -33
- package/dist/notifications-BGqmUNZ8.js +759 -0
- package/dist/queue/index.js +3 -42
- package/dist/queue-CXrRK85G.js +948 -0
- package/dist/redis/index.js +672 -642
- package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
- package/dist/runtime/index.js +474 -604
- package/dist/scheduling/index.js +2 -29
- package/dist/scheduling-CPiEdtQd.js +839 -0
- package/dist/storage/index.js +2 -15
- package/dist/storage-tWHMv2H_.js +841 -0
- package/dist/support/expiry.js +69 -12
- package/dist/trim-slashes-ZJ_VsY5s.js +25 -0
- package/dist/vite/index.js +118 -181
- package/dist/vite/plugin.d.ts +1 -1
- package/dist/vite-dev-server-CpCUqmiC.js +131 -0
- package/package.json +6 -5
- package/dist/DocsViewerServiceProvider-RUYDFBMW.js +0 -75
- package/dist/McpServiceProvider-SL7DUZ4G.js +0 -8
- package/dist/chunk-2SC566CD.js +0 -376
- package/dist/chunk-2V3YID4H.js +0 -20
- package/dist/chunk-3KV5X2FL.js +0 -31
- package/dist/chunk-63SKW5PS.js +0 -457
- package/dist/chunk-6J6B5KOB.js +0 -425
- package/dist/chunk-A5JJ7XTH.js +0 -24
- package/dist/chunk-AZOYI43J.js +0 -18
- package/dist/chunk-B5E5VBDI.js +0 -115
- package/dist/chunk-DAQKYKLH.js +0 -182
- package/dist/chunk-DRNPVBAA.js +0 -1002
- package/dist/chunk-EI5GYMAT.js +0 -853
- package/dist/chunk-H3B23O6T.js +0 -271
- package/dist/chunk-HPET6XY5.js +0 -853
- package/dist/chunk-HR2KZ3WL.js +0 -616
- package/dist/chunk-IOTWFHZU.js +0 -558
- package/dist/chunk-K6CUBJX6.js +0 -642
- package/dist/chunk-KTNJG7R7.js +0 -911
- package/dist/chunk-LAJQCSSF.js +0 -355
- package/dist/chunk-LHR6OHI7.js +0 -189
- package/dist/chunk-N7PLD7MB.js +0 -729
- package/dist/chunk-O5XIXGYM.js +0 -274
- package/dist/chunk-Q2P6YLRR.js +0 -24
- package/dist/chunk-QQKTH5KX.js +0 -114
- package/dist/chunk-SFQP6O52.js +0 -126
- package/dist/chunk-SQR7277M.js +0 -911
- package/dist/chunk-T2FFUU6J.js +0 -484
- package/dist/chunk-TVV5YNEC.js +0 -1842
- package/dist/chunk-UY3AZSYL.js +0 -14
- package/dist/chunk-V4DNC2ER.js +0 -114
- package/dist/chunk-YSOJKAAU.js +0 -427
- package/dist/errors-PUNHAFL2.js +0 -34
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
//#region src/container/Container.ts
|
|
3
|
+
/**
|
|
4
|
+
* Dependency injection container with type-safe service resolution.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const container = new Container()
|
|
9
|
+
*
|
|
10
|
+
* // Register services
|
|
11
|
+
* container.singleton('events', (c) => new EventManager())
|
|
12
|
+
* container.instance('config', loadConfig())
|
|
13
|
+
*
|
|
14
|
+
* // Type-safe resolution (known bindings)
|
|
15
|
+
* const events = container.make('events') // EventManager
|
|
16
|
+
*
|
|
17
|
+
* // Generic resolution (custom bindings)
|
|
18
|
+
* const db = container.make<Database>('db')
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
var Container = class Container {
|
|
22
|
+
bindings = /* @__PURE__ */ new Map();
|
|
23
|
+
aliases = /* @__PURE__ */ new Map();
|
|
24
|
+
tags = /* @__PURE__ */ new Map();
|
|
25
|
+
contextualBindings = [];
|
|
26
|
+
resolvingStack = [];
|
|
27
|
+
scopedInstances = [];
|
|
28
|
+
fakes = /* @__PURE__ */ new Map();
|
|
29
|
+
/** @internal Used by ProviderManager to resolve deferred providers on demand */
|
|
30
|
+
deferredProviderLoader = null;
|
|
31
|
+
/**
|
|
32
|
+
* Bind a service to the container.
|
|
33
|
+
* Each resolution creates a new instance.
|
|
34
|
+
*/
|
|
35
|
+
bind(key, factory) {
|
|
36
|
+
this.bindings.set(key, {
|
|
37
|
+
factory,
|
|
38
|
+
singleton: false
|
|
39
|
+
});
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Bind a singleton service to the container.
|
|
44
|
+
* Only one instance is created and reused.
|
|
45
|
+
*/
|
|
46
|
+
singleton(key, factory) {
|
|
47
|
+
this.bindings.set(key, {
|
|
48
|
+
factory,
|
|
49
|
+
singleton: true
|
|
50
|
+
});
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Bind an existing instance to the container.
|
|
55
|
+
*/
|
|
56
|
+
instance(key, value) {
|
|
57
|
+
this.bindings.set(key, {
|
|
58
|
+
factory: () => value,
|
|
59
|
+
singleton: true,
|
|
60
|
+
instance: value
|
|
61
|
+
});
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
make(key) {
|
|
65
|
+
if (this.fakes.has(key)) return this.fakes.get(key);
|
|
66
|
+
const resolvedKey = this.resolveAlias(key);
|
|
67
|
+
if (resolvedKey !== key && this.fakes.has(resolvedKey)) return this.fakes.get(resolvedKey);
|
|
68
|
+
let binding = this.bindings.get(resolvedKey);
|
|
69
|
+
if (!binding && this.deferredProviderLoader) {
|
|
70
|
+
let resolved = false;
|
|
71
|
+
this.deferredProviderLoader(resolvedKey).then(() => {
|
|
72
|
+
resolved = true;
|
|
73
|
+
});
|
|
74
|
+
if (resolved) binding = this.bindings.get(resolvedKey);
|
|
75
|
+
}
|
|
76
|
+
if (!binding) throw new Error(`Service "${key}" not found in container`);
|
|
77
|
+
if (binding.singleton && binding.instance !== void 0) return binding.instance;
|
|
78
|
+
if (this.scopedInstances.length > 0) {
|
|
79
|
+
const currentScope = this.scopedInstances[this.scopedInstances.length - 1];
|
|
80
|
+
if (currentScope.has(resolvedKey)) return currentScope.get(resolvedKey);
|
|
81
|
+
}
|
|
82
|
+
const contextualFactory = this.findContextualBinding(resolvedKey);
|
|
83
|
+
this.resolvingStack.push(resolvedKey);
|
|
84
|
+
try {
|
|
85
|
+
const instance = (contextualFactory ?? binding.factory)(this);
|
|
86
|
+
if (binding.singleton) binding.instance = instance;
|
|
87
|
+
if (this.scopedInstances.length > 0 && !binding.singleton) this.scopedInstances[this.scopedInstances.length - 1].set(resolvedKey, instance);
|
|
88
|
+
return instance;
|
|
89
|
+
} finally {
|
|
90
|
+
this.resolvingStack.pop();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Resolve a service with additional parameters.
|
|
95
|
+
*/
|
|
96
|
+
makeWith(key, params) {
|
|
97
|
+
const resolvedKey = this.resolveAlias(key);
|
|
98
|
+
const binding = this.bindings.get(resolvedKey);
|
|
99
|
+
if (!binding) throw new Error(`Service "${key}" not found in container`);
|
|
100
|
+
const tempContainer = new Container();
|
|
101
|
+
for (const [k, v] of this.bindings) tempContainer.bindings.set(k, { ...v });
|
|
102
|
+
for (const [paramKey, paramValue] of Object.entries(params)) tempContainer.instance(paramKey, paramValue);
|
|
103
|
+
return binding.factory(tempContainer);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if a service is bound in the container.
|
|
107
|
+
*/
|
|
108
|
+
has(key) {
|
|
109
|
+
const resolvedKey = this.resolveAlias(key);
|
|
110
|
+
return this.bindings.has(resolvedKey);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create an alias for a service.
|
|
114
|
+
*/
|
|
115
|
+
alias(alias, key) {
|
|
116
|
+
if (alias === key) throw new Error("Alias cannot be the same as the key");
|
|
117
|
+
this.aliases.set(alias, key);
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Tag multiple services with a tag name.
|
|
122
|
+
*/
|
|
123
|
+
tag(keys, tagName) {
|
|
124
|
+
let taggedKeys = this.tags.get(tagName);
|
|
125
|
+
if (!taggedKeys) {
|
|
126
|
+
taggedKeys = /* @__PURE__ */ new Set();
|
|
127
|
+
this.tags.set(tagName, taggedKeys);
|
|
128
|
+
}
|
|
129
|
+
for (const key of keys) taggedKeys.add(key);
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Resolve all services with a given tag.
|
|
134
|
+
*/
|
|
135
|
+
tagged(tagName) {
|
|
136
|
+
const taggedKeys = this.tags.get(tagName);
|
|
137
|
+
if (!taggedKeys) return [];
|
|
138
|
+
return Array.from(taggedKeys).map((key) => this.make(key));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Define a contextual binding.
|
|
142
|
+
*/
|
|
143
|
+
when(concrete) {
|
|
144
|
+
return { needs: (abstract) => {
|
|
145
|
+
return { give: (factoryOrValue) => {
|
|
146
|
+
const factory = typeof factoryOrValue === "function" ? factoryOrValue : () => factoryOrValue;
|
|
147
|
+
this.contextualBindings.push({
|
|
148
|
+
concrete,
|
|
149
|
+
needs: abstract,
|
|
150
|
+
factory
|
|
151
|
+
});
|
|
152
|
+
} };
|
|
153
|
+
} };
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Run a callback within a scoped context.
|
|
157
|
+
* Services resolved within the scope are cached and released when the scope ends.
|
|
158
|
+
*/
|
|
159
|
+
scoped(callback) {
|
|
160
|
+
this.scopedInstances.push(/* @__PURE__ */ new Map());
|
|
161
|
+
try {
|
|
162
|
+
return callback();
|
|
163
|
+
} finally {
|
|
164
|
+
this.scopedInstances.pop();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Run an async callback within a scoped context.
|
|
169
|
+
*/
|
|
170
|
+
async scopedAsync(callback) {
|
|
171
|
+
this.scopedInstances.push(/* @__PURE__ */ new Map());
|
|
172
|
+
try {
|
|
173
|
+
return await callback();
|
|
174
|
+
} finally {
|
|
175
|
+
this.scopedInstances.pop();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
fake(key, instance) {
|
|
179
|
+
this.fakes.set(key, instance);
|
|
180
|
+
return { [Symbol.dispose]: () => {
|
|
181
|
+
this.fakes.delete(key);
|
|
182
|
+
} };
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Check if a service is currently faked.
|
|
186
|
+
*/
|
|
187
|
+
isFaked(key) {
|
|
188
|
+
return this.fakes.has(key);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Remove all fakes.
|
|
192
|
+
*/
|
|
193
|
+
clearFakes() {
|
|
194
|
+
this.fakes.clear();
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Flush all resolved singleton instances.
|
|
198
|
+
*/
|
|
199
|
+
flush() {
|
|
200
|
+
for (const binding of this.bindings.values()) binding.instance = void 0;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Remove a binding from the container.
|
|
204
|
+
*/
|
|
205
|
+
forget(key) {
|
|
206
|
+
const resolvedKey = this.resolveAlias(key);
|
|
207
|
+
this.bindings.delete(resolvedKey);
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Get all bound service keys.
|
|
212
|
+
*/
|
|
213
|
+
getBindings() {
|
|
214
|
+
return Array.from(this.bindings.keys());
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get all aliases.
|
|
218
|
+
*/
|
|
219
|
+
getAliases() {
|
|
220
|
+
const result = {};
|
|
221
|
+
for (const [alias, key] of this.aliases) result[alias] = key;
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Get all tags.
|
|
226
|
+
*/
|
|
227
|
+
getTags() {
|
|
228
|
+
const result = {};
|
|
229
|
+
for (const [tag, keys] of this.tags) result[tag] = Array.from(keys);
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
resolveAlias(key) {
|
|
233
|
+
let resolved = key;
|
|
234
|
+
const seen = /* @__PURE__ */ new Set();
|
|
235
|
+
while (this.aliases.has(resolved)) {
|
|
236
|
+
if (seen.has(resolved)) throw new Error(`Circular alias detected: ${key}`);
|
|
237
|
+
seen.add(resolved);
|
|
238
|
+
resolved = this.aliases.get(resolved);
|
|
239
|
+
}
|
|
240
|
+
return resolved;
|
|
241
|
+
}
|
|
242
|
+
findContextualBinding(needs) {
|
|
243
|
+
if (this.resolvingStack.length === 0) return null;
|
|
244
|
+
const currentConcrete = this.resolvingStack[this.resolvingStack.length - 1];
|
|
245
|
+
for (const binding of this.contextualBindings) if (binding.concrete === currentConcrete && binding.needs === needs) return binding.factory;
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Create a new container instance.
|
|
251
|
+
*/
|
|
252
|
+
function createContainer() {
|
|
253
|
+
return new Container();
|
|
254
|
+
}
|
|
255
|
+
let globalContainer = null;
|
|
256
|
+
function setContainer(container) {
|
|
257
|
+
globalContainer = container;
|
|
258
|
+
}
|
|
259
|
+
function getContainer() {
|
|
260
|
+
if (!globalContainer) throw new Error("Container not initialized. Call setContainer() first.");
|
|
261
|
+
return globalContainer;
|
|
262
|
+
}
|
|
263
|
+
function resolve(key) {
|
|
264
|
+
return getContainer().make(key);
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/queue/Job.ts
|
|
268
|
+
/**
|
|
269
|
+
* Global queue driver instance.
|
|
270
|
+
* Set via setQueueDriver() or QueueManager.
|
|
271
|
+
*/
|
|
272
|
+
let globalDriver = null;
|
|
273
|
+
/**
|
|
274
|
+
* Set the global queue driver.
|
|
275
|
+
*/
|
|
276
|
+
function setQueueDriver(driver) {
|
|
277
|
+
globalDriver = driver;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Get the global queue driver.
|
|
281
|
+
*/
|
|
282
|
+
function getQueueDriver() {
|
|
283
|
+
return globalDriver;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Generate a unique job ID.
|
|
287
|
+
*/
|
|
288
|
+
function generateJobId() {
|
|
289
|
+
return randomBytes(16).toString("hex");
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Base class for defining jobs.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```ts
|
|
296
|
+
* class SendWelcomeEmailJob extends Job<{ userId: string }> {
|
|
297
|
+
* static queue = 'emails'
|
|
298
|
+
* static maxAttempts = 5
|
|
299
|
+
*
|
|
300
|
+
* async handle({ userId }: { userId: string }): Promise<void> {
|
|
301
|
+
* const user = await User.find(userId)
|
|
302
|
+
* await mail.to(user.email).template(WelcomeEmail, user).send()
|
|
303
|
+
* }
|
|
304
|
+
*
|
|
305
|
+
* async failed({ userId }: { userId: string }, error: Error): Promise<void> {
|
|
306
|
+
* console.error(`Failed to send welcome email to user ${userId}:`, error)
|
|
307
|
+
* }
|
|
308
|
+
* }
|
|
309
|
+
*
|
|
310
|
+
* // Dispatch the job
|
|
311
|
+
* await SendWelcomeEmailJob.dispatch({ userId: '123' })
|
|
312
|
+
*
|
|
313
|
+
* // Dispatch with delay
|
|
314
|
+
* await SendWelcomeEmailJob.dispatchAfter(60000, { userId: '123' })
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
var Job = class {
|
|
318
|
+
/**
|
|
319
|
+
* Stable wire name for this job.
|
|
320
|
+
*
|
|
321
|
+
* Queued messages record this name, and the worker resolves the class back
|
|
322
|
+
* from it. When omitted the class name is used, which breaks if a bundler
|
|
323
|
+
* mangles identifiers or if the class is later renamed while messages are
|
|
324
|
+
* still in flight. Set it to pin the name across both.
|
|
325
|
+
*
|
|
326
|
+
* @default the class name
|
|
327
|
+
*/
|
|
328
|
+
static jobName;
|
|
329
|
+
/**
|
|
330
|
+
* The queue this job should be dispatched to.
|
|
331
|
+
* @default 'default'
|
|
332
|
+
*/
|
|
333
|
+
static queue = "default";
|
|
334
|
+
/**
|
|
335
|
+
* Maximum number of times the job should be attempted.
|
|
336
|
+
* @default 3
|
|
337
|
+
*/
|
|
338
|
+
static maxAttempts = 3;
|
|
339
|
+
/**
|
|
340
|
+
* Backoff strategy for retries.
|
|
341
|
+
* - 'exponential': 2^attempt * 1000ms (1s, 2s, 4s, 8s, ...)
|
|
342
|
+
* - 'linear': attempt * 1000ms (1s, 2s, 3s, 4s, ...)
|
|
343
|
+
* - number: fixed delay in milliseconds
|
|
344
|
+
* @default 'exponential'
|
|
345
|
+
*/
|
|
346
|
+
static backoff = "exponential";
|
|
347
|
+
make(key) {
|
|
348
|
+
return getContainer().make(key);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Dispatch the job to the queue.
|
|
352
|
+
*
|
|
353
|
+
* @param payload - Job payload data
|
|
354
|
+
* @param options - Optional dispatch options
|
|
355
|
+
*/
|
|
356
|
+
static async dispatch(payload, options = {}) {
|
|
357
|
+
const driver = globalDriver;
|
|
358
|
+
if (!driver) throw new Error("Queue driver not configured. Call setQueueDriver() first.");
|
|
359
|
+
const jobId = generateJobId();
|
|
360
|
+
const now = /* @__PURE__ */ new Date();
|
|
361
|
+
const delay = options.delay ?? 0;
|
|
362
|
+
const job = {
|
|
363
|
+
id: jobId,
|
|
364
|
+
name: resolveJobName(this),
|
|
365
|
+
payload,
|
|
366
|
+
queue: options.queue ?? this.queue,
|
|
367
|
+
attempts: 0,
|
|
368
|
+
maxAttempts: options.maxAttempts ?? this.maxAttempts,
|
|
369
|
+
availableAt: new Date(now.getTime() + delay),
|
|
370
|
+
createdAt: now,
|
|
371
|
+
reservedAt: null
|
|
372
|
+
};
|
|
373
|
+
await driver.push(job);
|
|
374
|
+
return jobId;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Dispatch the job after a delay.
|
|
378
|
+
*
|
|
379
|
+
* @param delayMs - Delay in milliseconds
|
|
380
|
+
* @param payload - Job payload data
|
|
381
|
+
* @param options - Optional dispatch options (delay is overridden)
|
|
382
|
+
*/
|
|
383
|
+
static async dispatchAfter(delayMs, payload, options = {}) {
|
|
384
|
+
return this.dispatch(payload, {
|
|
385
|
+
...options,
|
|
386
|
+
delay: delayMs
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Calculate the retry delay based on backoff strategy.
|
|
391
|
+
*/
|
|
392
|
+
static calculateRetryDelay(attempts) {
|
|
393
|
+
if (typeof this.backoff === "number") return this.backoff;
|
|
394
|
+
if (this.backoff === "linear") return attempts * 1e3;
|
|
395
|
+
return Math.pow(2, attempts) * 1e3;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Resolve the wire name a job is queued and looked up under.
|
|
400
|
+
*
|
|
401
|
+
* Prefers an explicit `jobName` over the class name so that renaming the class
|
|
402
|
+
* or bundling with identifier mangling does not orphan queued messages.
|
|
403
|
+
*
|
|
404
|
+
* Only an *own* `jobName` counts. Static members are inherited, so reading it
|
|
405
|
+
* off the prototype chain would make every subclass of a pinned job claim its
|
|
406
|
+
* parent's identity and overwrite it in the registry. A subclass that wants a
|
|
407
|
+
* pinned name declares its own.
|
|
408
|
+
*/
|
|
409
|
+
function resolveJobName(jobClass) {
|
|
410
|
+
return (Object.prototype.hasOwnProperty.call(jobClass, "jobName") ? jobClass.jobName : void 0) ?? jobClass.name;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Job registry for looking up job classes by name.
|
|
414
|
+
*/
|
|
415
|
+
const jobRegistry = /* @__PURE__ */ new Map();
|
|
416
|
+
/**
|
|
417
|
+
* Register a job class for the worker to use.
|
|
418
|
+
*/
|
|
419
|
+
function registerJob(jobClass) {
|
|
420
|
+
jobRegistry.set(resolveJobName(jobClass), jobClass);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Get a registered job class by name.
|
|
424
|
+
*/
|
|
425
|
+
function getJob(name) {
|
|
426
|
+
return jobRegistry.get(name);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Get all registered job classes.
|
|
430
|
+
*/
|
|
431
|
+
function getRegisteredJobs() {
|
|
432
|
+
return new Map(jobRegistry);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Clear all registered jobs (for testing).
|
|
436
|
+
*/
|
|
437
|
+
function clearJobRegistry() {
|
|
438
|
+
jobRegistry.clear();
|
|
439
|
+
}
|
|
440
|
+
//#endregion
|
|
441
|
+
export { getRegisteredJobs as a, setQueueDriver as c, getContainer as d, resolve as f, getQueueDriver as i, Container as l, clearJobRegistry as n, registerJob as o, setContainer as p, getJob as r, resolveJobName as s, Job as t, createContainer as u };
|