stratal 0.0.24 → 0.0.25
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/cache/index.d.mts +1 -1
- package/dist/cache/index.mjs +2 -2
- package/dist/{command-CPhFHjG3.d.mts → command-4HnKnC-G.d.mts} +2 -2
- package/dist/{command-CPhFHjG3.d.mts.map → command-4HnKnC-G.d.mts.map} +1 -1
- package/dist/config/index.d.mts +1 -1
- package/dist/config/index.mjs +2 -2
- package/dist/{controller.decorator-C5UVeJS3.mjs → controller.decorator-DKeZ71aP.mjs} +3 -3
- package/dist/{controller.decorator-C5UVeJS3.mjs.map → controller.decorator-DKeZ71aP.mjs.map} +1 -1
- package/dist/cron/index.d.mts +1 -1
- package/dist/cron/index.mjs +1 -1
- package/dist/{cron.module-Bgzq5hiT.mjs → cron.module-DgxLe8Xy.mjs} +3 -3
- package/dist/{cron.module-Bgzq5hiT.mjs.map → cron.module-DgxLe8Xy.mjs.map} +1 -1
- package/dist/di/index.d.mts +1 -1
- package/dist/di/index.mjs +1 -1
- package/dist/{di-DseMn-z9.mjs → di-B0NXIdRF.mjs} +17 -1
- package/dist/di-B0NXIdRF.mjs.map +1 -0
- package/dist/email/index.d.mts +2 -2
- package/dist/email/index.mjs +3 -3
- package/dist/errors/index.d.mts +1 -1
- package/dist/errors/index.mjs +2 -2
- package/dist/{errors-mXYxG0XB.mjs → errors-EUtwVfNm.mjs} +3 -3
- package/dist/{errors-mXYxG0XB.mjs.map → errors-EUtwVfNm.mjs.map} +1 -1
- package/dist/events/index.d.mts +8 -0
- package/dist/events/index.d.mts.map +1 -1
- package/dist/events/index.mjs +1 -1
- package/dist/{events-BXJGZjpG.mjs → events-zbCMY_Gf.mjs} +5 -2
- package/dist/events-zbCMY_Gf.mjs.map +1 -0
- package/dist/{exception-context-kEoMFwze.mjs → exception-context-Bd5Hk2c_.mjs} +2 -2
- package/dist/{exception-context-kEoMFwze.mjs.map → exception-context-Bd5Hk2c_.mjs.map} +1 -1
- package/dist/{gateway-context-TMu_AlJt.mjs → gateway-context-I0tKgGfh.mjs} +4 -4
- package/dist/{gateway-context-TMu_AlJt.mjs.map → gateway-context-I0tKgGfh.mjs.map} +1 -1
- package/dist/guards/index.d.mts +1 -1
- package/dist/{hono-app-CvV3hOfT.mjs → hono-app-C7-1m9eK.mjs} +6 -6
- package/dist/{hono-app-CvV3hOfT.mjs.map → hono-app-C7-1m9eK.mjs.map} +1 -1
- package/dist/{http-method.decorator-ByWZb9DO.mjs → http-method.decorator-xCuGoZPC.mjs} +2 -2
- package/dist/{http-method.decorator-ByWZb9DO.mjs.map → http-method.decorator-xCuGoZPC.mjs.map} +1 -1
- package/dist/i18n/index.d.mts +1 -1
- package/dist/i18n/index.mjs +3 -3
- package/dist/{i18n.module-DRQAZoSZ.mjs → i18n.module-JOPUNpvi.mjs} +3 -3
- package/dist/{i18n.module-DRQAZoSZ.mjs.map → i18n.module-JOPUNpvi.mjs.map} +1 -1
- package/dist/{index-B5JBRcWD.d.mts → index-BPJSBHhq.d.mts} +2 -2
- package/dist/{index-B5JBRcWD.d.mts.map → index-BPJSBHhq.d.mts.map} +1 -1
- package/dist/{index-B_JoEl3V.d.mts → index-C_t8VVQD.d.mts} +12 -1
- package/dist/index-C_t8VVQD.d.mts.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/{lazy-module-loader-Ib383jH_.d.mts → lazy-module-loader-DZQxOgRZ.d.mts} +2 -2
- package/dist/{lazy-module-loader-Ib383jH_.d.mts.map → lazy-module-loader-DZQxOgRZ.d.mts.map} +1 -1
- package/dist/{locale-path.service-D-dHiIPc.mjs → locale-path.service-DzA01Kvc.mjs} +3 -3
- package/dist/{locale-path.service-D-dHiIPc.mjs.map → locale-path.service-DzA01Kvc.mjs.map} +1 -1
- package/dist/{locale-url.service-C2EWmGdq.mjs → locale-url.service-DwTXZid3.mjs} +2 -2
- package/dist/{locale-url.service-C2EWmGdq.mjs.map → locale-url.service-DwTXZid3.mjs.map} +1 -1
- package/dist/logger/index.mjs +1 -1
- package/dist/module/index.d.mts +2 -2
- package/dist/module/index.mjs +2 -2
- package/dist/{module-registry-Dm-pqHd3.mjs → module-registry-MfWmniZ7.mjs} +4 -4
- package/dist/{module-registry-Dm-pqHd3.mjs.map → module-registry-MfWmniZ7.mjs.map} +1 -1
- package/dist/openapi/index.d.mts +2 -2
- package/dist/openapi/index.mjs +1 -1
- package/dist/{openapi-CstuTM8S.mjs → openapi-BKDwQKh-.mjs} +3 -3
- package/dist/{openapi-CstuTM8S.mjs.map → openapi-BKDwQKh-.mjs.map} +1 -1
- package/dist/{openapi.service-YhTiJ1bO.d.mts → openapi.service-CM40bnBB.d.mts} +2 -2
- package/dist/{openapi.service-YhTiJ1bO.d.mts.map → openapi.service-CM40bnBB.d.mts.map} +1 -1
- package/dist/quarry/index.d.mts +3 -3
- package/dist/quarry/index.mjs +1 -1
- package/dist/quarry/runner.d.mts +6 -6
- package/dist/quarry/runner.mjs +5 -5
- package/dist/{quarry-registry-CXg0RFXq.d.mts → quarry-registry-CsStq0DB.d.mts} +3 -3
- package/dist/{quarry-registry-CXg0RFXq.d.mts.map → quarry-registry-CsStq0DB.d.mts.map} +1 -1
- package/dist/{quarry.module-BuRPGMDm.mjs → quarry.module-BOgcNJMU.mjs} +3 -3
- package/dist/{quarry.module-BuRPGMDm.mjs.map → quarry.module-BOgcNJMU.mjs.map} +1 -1
- package/dist/queue/index.d.mts +1 -1
- package/dist/queue/index.mjs +2 -2
- package/dist/{queue.module-nddvxzCB.mjs → queue.module-DSAH88gZ.mjs} +3 -3
- package/dist/{queue.module-nddvxzCB.mjs.map → queue.module-DSAH88gZ.mjs.map} +1 -1
- package/dist/{r2-storage.provider-DCxQt9dD.mjs → r2-storage.provider-BJ4j23W6.mjs} +2 -2
- package/dist/{r2-storage.provider-DCxQt9dD.mjs.map → r2-storage.provider-BJ4j23W6.mjs.map} +1 -1
- package/dist/{rate-limit.decorator-BPAie_p3.mjs → rate-limit.decorator-B35jBEVD.mjs} +2 -2
- package/dist/{rate-limit.decorator-BPAie_p3.mjs.map → rate-limit.decorator-B35jBEVD.mjs.map} +1 -1
- package/dist/rate-limiter/index.d.mts +1 -1
- package/dist/rate-limiter/index.mjs +3 -3
- package/dist/{route-registration.service-D6vSwiKP.mjs → route-registration.service-HN8WgIis.mjs} +9 -9
- package/dist/{route-registration.service-D6vSwiKP.mjs.map → route-registration.service-HN8WgIis.mjs.map} +1 -1
- package/dist/{route-registry-CYqLp2Nj.mjs → route-registry-CtW26Suv.mjs} +3 -3
- package/dist/{route-registry-CYqLp2Nj.mjs.map → route-registry-CtW26Suv.mjs.map} +1 -1
- package/dist/router/index.d.mts +1 -1
- package/dist/router/index.mjs +13 -13
- package/dist/{router-CWGBD-Bg.mjs → router-OCnf4VB6.mjs} +13 -13
- package/dist/{router-CWGBD-Bg.mjs.map → router-OCnf4VB6.mjs.map} +1 -1
- package/dist/{router-resolver-D4YlPNlm.mjs → router-resolver-CMNuw-s0.mjs} +2 -2
- package/dist/{router-resolver-D4YlPNlm.mjs.map → router-resolver-CMNuw-s0.mjs.map} +1 -1
- package/dist/seeder/index.d.mts +2 -2
- package/dist/seeder/index.mjs +3 -3
- package/dist/{seeder-7ubkms-Y.mjs → seeder-DI-rUoZx.mjs} +4 -4
- package/dist/{seeder-7ubkms-Y.mjs.map → seeder-DI-rUoZx.mjs.map} +1 -1
- package/dist/{seeder-registry-CyUmKsJq.mjs → seeder-registry-B5FwBeCU.mjs} +3 -3
- package/dist/{seeder-registry-CyUmKsJq.mjs.map → seeder-registry-B5FwBeCU.mjs.map} +1 -1
- package/dist/{seeder.module-CYYwk3Qk.mjs → seeder.module-DaY0RYoB.mjs} +2 -2
- package/dist/{seeder.module-CYYwk3Qk.mjs.map → seeder.module-DaY0RYoB.mjs.map} +1 -1
- package/dist/storage/index.d.mts +1 -1
- package/dist/storage/index.mjs +2 -2
- package/dist/storage/providers/index.mjs +1 -1
- package/dist/{storage-MDZypIE9.mjs → storage-BE6-kzaN.mjs} +7 -7
- package/dist/{storage-MDZypIE9.mjs.map → storage-BE6-kzaN.mjs.map} +1 -1
- package/dist/{storage.error-Dnib4VHc.mjs → storage.error-Dai3rShJ.mjs} +2 -2
- package/dist/{storage.error-Dnib4VHc.mjs.map → storage.error-Dai3rShJ.mjs.map} +1 -1
- package/dist/{stratal-DwDJPY9N.d.mts → stratal-Bmc6WT3k.d.mts} +2 -2
- package/dist/{stratal-DwDJPY9N.d.mts.map → stratal-Bmc6WT3k.d.mts.map} +1 -1
- package/dist/{stratal-DL9M38_s.mjs → stratal-DtAj21uF.mjs} +21 -20
- package/dist/stratal-DtAj21uF.mjs.map +1 -0
- package/dist/{uri-h7Q8Jug9.mjs → uri-h6ITRpqr.mjs} +3 -3
- package/dist/{uri-h7Q8Jug9.mjs.map → uri-h6ITRpqr.mjs.map} +1 -1
- package/dist/{versioning.service-C6aHky8-.mjs → versioning.service-B4rtmgMQ.mjs} +3 -3
- package/dist/{versioning.service-C6aHky8-.mjs.map → versioning.service-B4rtmgMQ.mjs.map} +1 -1
- package/dist/websocket/index.d.mts +1 -1
- package/dist/websocket/index.mjs +1 -1
- package/dist/workers/index.d.mts +1 -1
- package/dist/workers/index.mjs +2 -2
- package/package.json +1 -1
- package/dist/di-DseMn-z9.mjs.map +0 -1
- package/dist/events-BXJGZjpG.mjs.map +0 -1
- package/dist/index-B_JoEl3V.d.mts.map +0 -1
- package/dist/stratal-DL9M38_s.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.module-nddvxzCB.mjs","names":[],"sources":["../src/queue/queue.error.ts","../src/queue/queue-manager.ts","../src/queue/consumer-registry.ts","../src/queue/queue-sender.ts","../src/queue/queue-registry.ts","../src/queue/queue-store.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.module.ts"],"sourcesContent":["import { ApplicationError } from '../errors'\n\nexport class QueueError extends ApplicationError {}\n","import { inject } from '../di'\nimport { getContainer } from '../di/container-storage'\nimport { Transient } from '../di/decorators'\nimport { DI_TOKENS } from '../di/tokens'\nimport { LOGGER_TOKENS, type LoggerService } from '../logger'\nimport { type ConsumerRegistry } from './consumer-registry'\nimport type { FailedJob } from './failed-job'\nimport type { IQueueConsumer, QueueMessage } from './queue-consumer'\nimport { QueueError } from './queue.error'\nimport type { QueueModuleOptions } from './queue.module'\nimport type { QueueStore } from './queue-store'\nimport { QUEUE_TOKENS } from './queue.tokens'\n\nconst DEFAULT_MAX_RETRIES = 3\n\n@Transient(DI_TOKENS.Queue)\nexport class QueueManager {\n private readonly maxRetries: number\n\n constructor(\n @inject(DI_TOKENS.ConsumerRegistry) private readonly registry: ConsumerRegistry,\n @inject(LOGGER_TOKENS.LoggerService) private readonly logger: LoggerService,\n @inject(QUEUE_TOKENS.QueueStore) private readonly store: QueueStore,\n @inject(QUEUE_TOKENS.QueueModuleOptions) options: QueueModuleOptions,\n ) {\n this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES\n }\n\n async processBatch(queueName: string, batch: MessageBatch): Promise<void> {\n for (const message of batch.messages) {\n const queueMessage = message.body as QueueMessage\n const idempotencyKey = queueMessage.metadata?.idempotencyKey ?? queueMessage.id\n\n if (await this.store.isProcessed(idempotencyKey)) {\n message.ack()\n continue\n }\n\n // Resolve a fresh consumer instance per message from the active request\n // scope (handleQueue runs processBatch inside runInRequestScope), so\n // request-scoped consumer dependencies bind to this message's scope.\n const container = getContainer()\n const consumers = this.registry\n .getConsumerClasses(queueMessage.type)\n .map((ConsumerClass) => container.resolve<IQueueConsumer>(ConsumerClass))\n\n const results = await Promise.allSettled(\n consumers.map((consumer) => consumer.handle(queueMessage)),\n )\n\n let lastError: Error | undefined\n let failedConsumer: string | undefined\n\n for (let i = 0; i < results.length; i++) {\n const result = results[i]\n if (result.status === 'rejected') {\n const consumer = consumers[i]\n const errorInstance = result.reason instanceof Error\n ? result.reason\n : new Error(String(result.reason))\n\n this.logger.error('Queue message processing failed', errorInstance, {\n type: queueMessage.type,\n queue: queueName,\n messageId: queueMessage.id,\n idempotencyKey,\n })\n\n if (consumer.onError) {\n await consumer.onError(errorInstance, queueMessage)\n }\n\n lastError = errorInstance\n failedConsumer = consumer.constructor.name\n }\n }\n\n const failed = lastError !== undefined\n\n if (failed) {\n // `message.attempts` is 1-based (the first delivery is attempt 1), so a\n // message is only out of retries once it has been delivered more than\n // `maxRetries` times. `maxRetries: 3` therefore means 3 retries after the\n // initial delivery (4 total attempts). This must be <= the consumer's\n // `max_retries` in wrangler.jsonc, otherwise Cloudflare dead-letters the\n // message before this branch ever runs and it never reaches the store.\n if (message.attempts > this.maxRetries) {\n // A KV failure (or a message dispatched outside Stratal, with no\n // binding to retry through) while persisting the failed job must not\n // abort the rest of the batch — log and ack so the message isn't\n // redelivered forever.\n try {\n const binding = queueMessage.metadata?.binding\n if (!binding) {\n throw new QueueError(\n `Queue message ${queueMessage.id} has no binding metadata and cannot be recorded for retry. ` +\n `Messages must be dispatched through a Stratal queue sender (@InjectQueue).`,\n )\n }\n\n const failedJob: FailedJob = {\n id: queueMessage.id,\n queue: queueName,\n binding,\n type: queueMessage.type,\n message: queueMessage,\n error: {\n name: lastError!.name,\n message: lastError!.message,\n stack: lastError!.stack,\n },\n consumer: failedConsumer!,\n attempts: message.attempts,\n failedAt: new Date().toISOString(),\n }\n\n await this.store.storeFailedJob(failedJob)\n } catch (error) {\n this.logger.error(\n 'Failed to persist failed queue job',\n error instanceof Error ? error : new Error(String(error)),\n { queue: queueName, messageId: queueMessage.id, type: queueMessage.type },\n )\n }\n message.ack()\n } else {\n message.retry()\n }\n } else {\n await this.store.markProcessed(idempotencyKey)\n message.ack()\n }\n }\n }\n}\n","import { Singleton } from '../di/decorators'\nimport { DI_TOKENS } from '../di/tokens'\nimport type { Constructor } from '../types'\nimport type { IQueueConsumer } from './queue-consumer'\n\n/** A registered consumer class together with the message types it handles. */\nexport interface ConsumerRegistration {\n consumerClass: Constructor<IQueueConsumer>\n messageTypes: string[]\n}\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@Singleton(DI_TOKENS.ConsumerRegistry)\nexport class ConsumerRegistry {\n /** Map from message type to consumer classes handling that type */\n private classesByType = new Map<string, Constructor<IQueueConsumer>[]>()\n\n /** All registrations (for iteration / listing) */\n private registrations: ConsumerRegistration[] = []\n\n /** Registered consumer classes (dedupe) */\n private registeredClasses = new Set<Constructor<IQueueConsumer>>()\n\n /**\n * Register a queue consumer class.\n *\n * Indexes the class by each of its declared message types. A fresh instance\n * is resolved per message from the request-scoped container at dispatch time —\n * consumers are never held as long-lived singletons, so they may safely inject\n * request-scoped providers (`@InjectQueue`, i18n, auth context, …).\n *\n * @param consumerClass - Queue consumer class to register\n * @param messageTypes - Message types the consumer handles\n */\n register(consumerClass: Constructor<IQueueConsumer>, messageTypes: string[]): void {\n if (this.registeredClasses.has(consumerClass)) {\n return // Already registered\n }\n\n this.registeredClasses.add(consumerClass)\n this.registrations.push({ consumerClass, messageTypes })\n\n for (const messageType of messageTypes) {\n const existing = this.classesByType.get(messageType) ?? []\n existing.push(consumerClass)\n this.classesByType.set(messageType, existing)\n }\n }\n\n /**\n * Get all consumer classes that can handle a specific message type.\n *\n * Returns classes that either declare the message type explicitly or use the\n * `'*'` wildcard. Callers resolve a fresh instance per message from the\n * request-scoped container.\n *\n * @param messageType - The message type to find consumers for\n * @returns Array of consumer classes that can handle this message type\n */\n getConsumerClasses(messageType: string): Constructor<IQueueConsumer>[] {\n const exactMatch = this.classesByType.get(messageType) ?? []\n const wildcardMatch = this.classesByType.get('*') ?? []\n\n // Combine and dedupe\n return Array.from(new Set([...exactMatch, ...wildcardMatch]))\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.getConsumerClasses(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.classesByType.keys())\n }\n\n /**\n * Get all consumer registrations (class + message types) for listing.\n */\n getRegistrations(): readonly ConsumerRegistration[] {\n return this.registrations\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 binding.\n * Created by QueueRegistry for each registered binding.\n *\n * Automatically enriches messages with:\n * - `id`: UUID generated via crypto.randomUUID()\n * - `metadata.locale`: Current locale from I18n context\n * - `metadata.idempotencyKey`: Deterministic SHA-256 hash of type + payload (if not provided)\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 binding: 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)\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 metadata.idempotencyKey ??= await this.generateIdempotencyKey(message.type, message.payload);\n\n // Stamp the producer binding so a failed job can be retried to the right\n // Cloudflare binding. Consumers only see the queue *name*, which is not a\n // valid producer binding key.\n metadata.binding = this.binding\n\n const fullMessage: QueueMessage<T> = {\n id: crypto.randomUUID(),\n ...message,\n metadata,\n }\n\n await this.provider.send(this.binding, fullMessage)\n }\n\n private async generateIdempotencyKey(type: string, payload: unknown): Promise<string> {\n // Use a stable, key-sorted serialization: `JSON.stringify` preserves\n // insertion order, so two semantically identical payloads with differently\n // ordered keys would otherwise hash differently and defeat deduplication.\n const data = new TextEncoder().encode(stableStringify({ type, payload }))\n const hash = await crypto.subtle.digest('SHA-256', data)\n return `queue:${Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2, '0')).join('')}`\n }\n}\n\n/**\n * Deterministic JSON serialization: object keys are emitted in sorted order at\n * every level so the output depends only on the data, not on key insertion\n * order. Arrays keep their order (order is significant). Used to derive a stable\n * idempotency hash from a message's `type` + `payload`.\n */\nfunction stableStringify(value: unknown): string {\n if (value === null || typeof value !== 'object') {\n return JSON.stringify(value) ?? 'null'\n }\n if (Array.isArray(value)) {\n return `[${value.map(stableStringify).join(',')}]`\n }\n const entries = Object.keys(value as Record<string, unknown>)\n .sort()\n .map((key) => {\n const v = (value as Record<string, unknown>)[key]\n if (v === undefined) return undefined\n return `${JSON.stringify(key)}:${stableStringify(v)}`\n })\n .filter((entry): entry is string => entry !== undefined)\n return `{${entries.join(',')}}`\n}\n","import { inject } from '../di'\nimport { Request } 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 { type QueueProviderFactory } from './services'\n\n/**\n * Queue Registry\n *\n * Request-scoped factory service for creating QueueSender instances.\n * Caches senders per binding within the request scope.\n *\n * This service is used internally by QueueModule.registerQueue() to provide\n * IQueueSender instances for each registered binding.\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@Request(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 binding.\n *\n * Senders are cached per binding within the request scope.\n *\n * @param binding - The queue binding to get a sender for\n * @returns QueueSender bound to the specified binding\n */\n getQueue(binding: string): IQueueSender {\n let sender = this.senders.get(binding)\n\n if (!sender) {\n sender = new QueueSender(binding, this.provider, this.i18n)\n this.senders.set(binding, sender)\n }\n\n return sender\n }\n}\n","import { inject } from '../di';\nimport { Transient } from '../di/decorators';\nimport { CACHE_TOKENS } from '../cache/cache.tokens';\nimport type { TieredCacheService } from '../cache/services/tiered-cache.service';\nimport type { FailedJob, FailedJobMetadata } from './failed-job';\nimport type { QueueModuleOptions } from './queue.module';\nimport { QUEUE_TOKENS } from './queue.tokens';\n\nconst IDEM_PREFIX = 'queue:idem:'\nconst FAILED_PREFIX = 'queue:failed:'\nconst DEFAULT_IDEMPOTENCY_TTL = 86400\n\n/** Default KV binding name used for queue state when none is configured. */\nexport const DEFAULT_STORE_BINDING = 'CACHE'\n\n/**\n * Persists queue idempotency claims and failed jobs.\n *\n * Backed by {@link TieredCacheService} (isolate-local L1 + KV). The L1 is what\n * makes `markProcessed` → `isProcessed` reliable within an isolate: a claim\n * written on this isolate is read back from memory, so a message redelivered to\n * the same warm isolate is de-duplicated even inside KV's eventual-consistency\n * window. Idempotency markers are set-once, the pattern the L1 tier is designed\n * for. Cross-isolate duplicates still rely on KV (eventually consistent) —\n * delivery remains at-least-once with best-effort de-duplication, not\n * exactly-once.\n */\n@Transient(QUEUE_TOKENS.QueueStore)\nexport class QueueStore {\n private readonly cache: TieredCacheService\n private readonly idempotencyTtl: number\n\n constructor(\n @inject(CACHE_TOKENS.TieredCacheService) cache: TieredCacheService,\n @inject(QUEUE_TOKENS.QueueModuleOptions) options: QueueModuleOptions,\n ) {\n // Bind to the configured KV namespace via the tiered cache so the L1 lives\n // on its singleton (one per isolate) and persists across messages. The\n // binding is validated at module init (QueueModule.onInitialize);\n // `binding()` also throws if it is somehow absent here.\n this.cache = cache.binding(options.store?.binding ?? DEFAULT_STORE_BINDING)\n this.idempotencyTtl = options.idempotency?.ttl ?? DEFAULT_IDEMPOTENCY_TTL\n }\n\n async isProcessed(key: string): Promise<boolean> {\n return (await this.cache.get(`${IDEM_PREFIX}${key}`)) !== null\n }\n\n async markProcessed(key: string): Promise<void> {\n await this.cache.put(`${IDEM_PREFIX}${key}`, '1', {\n expirationTtl: this.idempotencyTtl,\n })\n }\n\n async storeFailedJob(job: FailedJob): Promise<void> {\n const metadata: FailedJobMetadata = {\n queue: job.queue,\n binding: job.binding,\n type: job.type,\n consumer: job.consumer,\n attempts: job.attempts,\n failedAt: job.failedAt,\n }\n\n await this.cache.put(`${FAILED_PREFIX}${job.id}`, JSON.stringify(job), {\n metadata,\n })\n }\n\n async getFailedJob(messageId: string): Promise<FailedJob | null> {\n return this.cache.get<FailedJob>(`${FAILED_PREFIX}${messageId}`, 'json')\n }\n\n async removeFailedJob(messageId: string): Promise<void> {\n await this.cache.delete(`${FAILED_PREFIX}${messageId}`)\n }\n\n async listFailedJobs(options?: {\n limit?: number\n cursor?: string\n }): Promise<{ keys: { id: string; metadata: FailedJobMetadata }[]; cursor?: string }> {\n const result = await this.cache.list<FailedJobMetadata>({\n prefix: FAILED_PREFIX,\n limit: options?.limit ?? 50,\n cursor: options?.cursor,\n })\n\n // Skip keys without metadata: a partially-written entry (or one written by\n // an older code path) is unusable for listing and must not crash the page.\n const keys = result.keys\n .filter((key): key is typeof key & { metadata: FailedJobMetadata } => key.metadata != null)\n .map((key) => ({\n id: key.name.slice(FAILED_PREFIX.length),\n metadata: key.metadata,\n }))\n\n return {\n keys,\n cursor: result.list_complete ? undefined : result.cursor,\n }\n }\n\n async purgeFailedJobs(): Promise<void> {\n let cursor: string | undefined\n\n do {\n const result = await this.cache.list({ prefix: FAILED_PREFIX, cursor })\n await Promise.all(result.keys.map((key) => this.cache.delete(key.name)))\n cursor = result.list_complete ? undefined : result.cursor\n } while (cursor)\n }\n\n /**\n * Delete failed jobs older than `retentionSeconds` (by their `failedAt`\n * timestamp). Returns the number removed. Backs the opt-in\n * {@link FailedJobCleanupJob} cron — failed jobs otherwise persist\n * indefinitely until retried or purged.\n */\n async purgeFailedJobsOlderThan(retentionSeconds: number): Promise<number> {\n const cutoff = Date.now() - retentionSeconds * 1000\n let cursor: string | undefined\n let removed = 0\n\n do {\n const result = await this.cache.list<FailedJobMetadata>({ prefix: FAILED_PREFIX, cursor })\n const expired = result.keys.filter((key) => {\n const failedAt = key.metadata?.failedAt\n return failedAt !== undefined && Date.parse(failedAt) < cutoff\n })\n await Promise.all(expired.map((key) => this.cache.delete(key.name)))\n removed += expired.length\n cursor = result.list_complete ? undefined : result.cursor\n } while (cursor)\n\n return removed\n }\n}\n","import { inject } from '../../di'\nimport { type StratalEnv } from '../../env'\nimport { Transient } from '../../di/decorators'\nimport { DI_TOKENS } from '../../di/tokens'\nimport { QueueError } from '../queue.error'\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 the binding directly on\n * the worker's `env`. Used in production environments where Cloudflare Workers\n * handle queue processing.\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 binding - Queue binding identifier (e.g., 'NOTIFICATIONS_QUEUE')\n * @param message - Complete message with id and payload\n * @throws {QueueError} If the binding is not configured on env\n */\n async send<T>(binding: string, message: QueueMessage<T>): Promise<void> {\n const queue = (this.env as unknown as Record<string, unknown>)[binding] as Queue | undefined\n\n if (!queue) {\n throw new QueueError(`Queue binding \"${binding}\" was not found in the environment`)\n }\n\n await queue.send(message)\n }\n}\n","import type { Container } from '../../di/container'\nimport { containerStorage } from '../../di/container-storage'\nimport { inject } from '../../di'\nimport { Transient } from '../../di/decorators'\nimport { DI_TOKENS } from '../../di/tokens'\nimport type { RouterContext } from '../../router/router-context'\nimport { type ConsumerRegistry } from '../consumer-registry'\nimport type { IQueueConsumer, 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@Transient()\nexport class SyncQueueProvider implements IQueueProvider {\n constructor(\n @inject(DI_TOKENS.ConsumerRegistry) private readonly registry: ConsumerRegistry,\n @inject(DI_TOKENS.Container) private readonly root: Container,\n ) {}\n\n /**\n * Process a message synchronously.\n *\n * Runs inside the active request scope when dispatch happens within one (an\n * HTTP request, or `runInScope` for queues/cron/commands). When dispatched\n * with no ambient scope — e.g. a service invoked directly in a test — it\n * establishes its own request scope (mirroring the production queue handler)\n * so consumers and their request-scoped dependencies resolve correctly.\n *\n * @param _binding - Queue binding (not used for routing, consumers match by message type)\n * @param message - Complete message with id and payload\n * @throws Re-throws any error from consumer.handle() after calling onError()\n */\n async send<T>(_binding: string, message: QueueMessage<T>): Promise<void> {\n const ambient = containerStorage.getStore()\n if (ambient) {\n await this.process(ambient, message)\n return\n }\n\n const locale = message.metadata?.locale ?? 'en'\n const context = {\n getLocale: () => locale,\n setLocale: () => { /* no-op */ },\n getContainer: () => containerStorage.getStore() ?? this.root,\n } as unknown as RouterContext\n\n await this.root.runInRequestScope(context, (container) => this.process(container, message))\n }\n\n /**\n * Resolve a fresh consumer per message from `container` (matched by type) and\n * invoke each sequentially, fail-fast on the first error after `onError`.\n */\n private async process<T>(container: Container, message: QueueMessage<T>): Promise<void> {\n const consumers = this.registry\n .getConsumerClasses(message.type)\n .map((ConsumerClass) => container.resolve<IQueueConsumer>(ConsumerClass))\n\n for (const consumer of consumers) {\n try {\n await consumer.handle(message)\n } catch (error) {\n const errorInstance = error instanceof Error ? error : 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 '../../di'\nimport type { Container } from '../../di/container'\nimport { type StratalEnv } from '../../env'\nimport { Transient } from '../../di/decorators'\nimport { DI_TOKENS } from '../../di/tokens'\nimport { type ConsumerRegistry } from '../consumer-registry'\nimport { QueueError } from '../queue.error'\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(DI_TOKENS.Container) private readonly container: Container,\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 {QueueError} 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, this.container)\n\n default:\n throw new QueueError(`Queue provider \"${String(providerType)}\" is not supported`)\n }\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 queue bindings (the binding IS the injection token)\n * QueueModule.registerQueue('NOTIFICATIONS_QUEUE')\n * QueueModule.registerQueue('BACKGROUND_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 { CacheModule } from '../cache';\nimport { DI_TOKENS } from '../di/tokens';\nimport { type StratalEnv } from '../env';\nimport { Module } from '../module';\nimport type {\n AsyncModuleOptions,\n DynamicModule,\n InjectionToken,\n ModuleContext,\n OnInitialize,\n} from '../module/types';\nimport { ConsumerRegistry } from './consumer-registry';\nimport type { QueueBinding } from './queue-binding';\nimport { QueueManager } from './queue-manager';\nimport { QueueRegistry } from './queue-registry';\nimport type { IQueueSender } from './queue-sender.interface';\nimport { QueueError } from './queue.error';\nimport { DEFAULT_STORE_BINDING, QueueStore } from './queue-store';\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 * KV binding for queue state (idempotency keys + failed jobs).\n * Defaults to the `CACHE` binding if omitted.\n */\n store?: {\n /**\n * KV namespace binding name.\n * @default CACHE\n */\n binding?: string\n }\n\n /**\n * Idempotency configuration.\n *\n * Delivery is **at-least-once with best-effort de-duplication**, not\n * exactly-once. Every dispatch carries an idempotency key (an explicit\n * `metadata.idempotencyKey`, otherwise a deterministic SHA-256 hash of `type`\n * + `payload`), and a message already recorded as processed is skipped. The\n * processed marker is written only after a handler succeeds, and KV `get`/`put`\n * are eventually consistent — so a message redelivered concurrently (or after\n * a crash before the marker was durable) can still run more than once. Make\n * handlers idempotent; don't rely on this as a hard exactly-once guarantee.\n * `ttl` bounds how long processed keys are remembered.\n */\n idempotency?: {\n /** TTL in seconds for processed idempotency keys. Default: 86400 (24h) */\n ttl?: number\n }\n\n /**\n * Failed-job configuration.\n *\n * Failed jobs persist indefinitely until retried or purged. To bound growth,\n * register the opt-in `FailedJobCleanupJob` cron in a module's `jobs` array;\n * it deletes failed jobs older than `retention`.\n */\n failedJobs?: {\n /**\n * Age in seconds beyond which `FailedJobCleanupJob` deletes a failed job.\n * Default: 604800 (7d). Has no effect unless the cron is registered.\n */\n retention?: number\n }\n\n /** Max retry attempts before storing as failed job. Default: 3 */\n maxRetries?: number\n}\n\n@Module({\n // QueueStore persists idempotency claims and failed jobs through CacheService\n // (isolate-local L1 + KV), so the cache must be available wherever queues are.\n imports: [CacheModule],\n providers: [\n { provide: DI_TOKENS.ConsumerRegistry, useClass: ConsumerRegistry },\n QueueManager,\n { provide: QUEUE_TOKENS.QueueProviderFactory, useClass: QueueProviderFactory },\n { provide: QUEUE_TOKENS.QueueRegistry, useClass: QueueRegistry },\n { provide: QUEUE_TOKENS.QueueStore, useClass: QueueStore },\n ],\n})\nexport class QueueModule implements OnInitialize {\n /**\n * Fail fast at boot if the configured KV store binding is missing, rather\n * than letting every queue invocation hard-fail lazily. The binding backs\n * idempotency claims and failed-job storage, so without it the queue\n * subsystem cannot function.\n */\n onInitialize({ container }: ModuleContext): void {\n const options = container.resolve<QueueModuleOptions>(QUEUE_TOKENS.QueueModuleOptions)\n\n // Only the `cloudflare` provider persists idempotency claims and failed jobs\n // to KV. The `sync` provider (dev/CLI) processes inline and never touches the\n // store, so it must not require the binding.\n if (options.provider !== 'cloudflare') return\n\n const binding = options.store?.binding ?? DEFAULT_STORE_BINDING\n const env = container.resolve<StratalEnv>(DI_TOKENS.CloudflareEnv)\n const kv = (env as unknown as Record<string, unknown>)[binding]\n\n if (!kv) {\n throw new QueueError(\n `Queue KV store binding \"${binding}\" was not found in the environment. ` +\n `The queue subsystem persists idempotency claims and failed jobs to KV. ` +\n `Add a kv_namespaces entry for \"${binding}\" in wrangler.jsonc, or set ` +\n `QueueModule.forRootAsync({ ..., store: { binding: 'YOUR_KV' } }) to point at an existing namespace.`,\n )\n }\n }\n\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 binding for injection.\n *\n * The binding name doubles as the DI injection token and the\n * `env`-lookup key. Binding names are typed against `StratalEnv`\n * (autocomplete works once an app augments `StratalEnv` with its\n * Cloudflare bindings).\n *\n * @param binding - Queue binding identifier (e.g. `NOTIFICATIONS_QUEUE`).\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 binding name\n * constructor(@InjectQueue('NOTIFICATIONS_QUEUE') private queue: IQueueSender) {}\n * ```\n */\n static registerQueue(binding: QueueBinding): DynamicModule {\n return {\n module: QueueModule,\n providers: [\n {\n provide: binding as InjectionToken<IQueueSender>,\n useFactory: (registry: QueueRegistry) => registry.getQueue(binding),\n inject: [QUEUE_TOKENS.QueueRegistry],\n },\n ],\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAEA,IAAa,aAAb,cAAgC,iBAAiB,CAAC;;;ACWlD,MAAM,sBAAsB;AAGrB,IAAA,eAAA,MAAM,aAAa;CAI+B;CACC;CACJ;CALpD;CAEA,YACE,UACA,QACA,OACA,SACA;EAJqD,KAAA,WAAA;EACC,KAAA,SAAA;EACJ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;;;;;;;;;;;;ACgF1D,IAAA,cAAA,eAAA,MAAM,YAAoC;;;;;;;CAO/C,aAAa,EAAE,aAAkC;EAC/C,MAAM,UAAU,UAAU,QAA4B,aAAa,kBAAkB;EAKrF,IAAI,QAAQ,aAAa,cAAc;EAEvC,MAAM,UAAU,QAAQ,OAAO,WAAA;EAI/B,IAAI,CAHQ,UAAU,QAAoB,UAAU,aACtC,EAAyC,UAGrD,MAAM,IAAI,WACR,2BAA2B,QAAQ,4IAEC,QAAQ,gIAE9C;CAEJ;;;;;;;;;;;;;;;;;;;CAoBA,OAAO,aAAa,SAAgE;EAClF,OAAO;GACL,QAAA;GACA,WAAW,CACT;IACE,SAAS,aAAa;IACtB,YAAY,QAAQ;IACpB,QAAQ,QAAQ;GAClB,CACF;EACF;CACF;;;;;;;;;;;;;;;;;;;;;CAsBA,OAAO,cAAc,SAAsC;EACzD,OAAO;GACL,QAAA;GACA,WAAW,CACT;IACE,SAAS;IACT,aAAa,aAA4B,SAAS,SAAS,OAAO;IAClE,QAAQ,CAAC,aAAa,aAAa;GACrC,CACF;EACF;CACF;AACF;yCAxGC,OAAO;CAGN,SAAS,CAAC,WAAW;CACrB,WAAW;EACT;GAAE,SAAS,UAAU;GAAkB,UAAU;EAAiB;EAClE;EACA;GAAE,SAAS,aAAa;GAAsB,UAAU;EAAqB;EAC7E;GAAE,SAAS,aAAa;GAAe,UAAU;EAAc;EAC/D;GAAE,SAAS,aAAa;GAAY,UAAU;EAAW;CAC3D;AACF,CAAC,CAAA,GAAA,WAAA"}
|
|
1
|
+
{"version":3,"file":"queue.module-DSAH88gZ.mjs","names":[],"sources":["../src/queue/queue.error.ts","../src/queue/queue-manager.ts","../src/queue/consumer-registry.ts","../src/queue/queue-sender.ts","../src/queue/queue-registry.ts","../src/queue/queue-store.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.module.ts"],"sourcesContent":["import { ApplicationError } from '../errors'\n\nexport class QueueError extends ApplicationError {}\n","import { inject } from '../di'\nimport { getContainer } from '../di/container-storage'\nimport { Transient } from '../di/decorators'\nimport { DI_TOKENS } from '../di/tokens'\nimport { LOGGER_TOKENS, type LoggerService } from '../logger'\nimport { type ConsumerRegistry } from './consumer-registry'\nimport type { FailedJob } from './failed-job'\nimport type { IQueueConsumer, QueueMessage } from './queue-consumer'\nimport { QueueError } from './queue.error'\nimport type { QueueModuleOptions } from './queue.module'\nimport type { QueueStore } from './queue-store'\nimport { QUEUE_TOKENS } from './queue.tokens'\n\nconst DEFAULT_MAX_RETRIES = 3\n\n@Transient(DI_TOKENS.Queue)\nexport class QueueManager {\n private readonly maxRetries: number\n\n constructor(\n @inject(DI_TOKENS.ConsumerRegistry) private readonly registry: ConsumerRegistry,\n @inject(LOGGER_TOKENS.LoggerService) private readonly logger: LoggerService,\n @inject(QUEUE_TOKENS.QueueStore) private readonly store: QueueStore,\n @inject(QUEUE_TOKENS.QueueModuleOptions) options: QueueModuleOptions,\n ) {\n this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES\n }\n\n async processBatch(queueName: string, batch: MessageBatch): Promise<void> {\n for (const message of batch.messages) {\n const queueMessage = message.body as QueueMessage\n const idempotencyKey = queueMessage.metadata?.idempotencyKey ?? queueMessage.id\n\n if (await this.store.isProcessed(idempotencyKey)) {\n message.ack()\n continue\n }\n\n // Resolve a fresh consumer instance per message from the active request\n // scope (handleQueue runs processBatch inside runInRequestScope), so\n // request-scoped consumer dependencies bind to this message's scope.\n const container = getContainer()\n const consumers = this.registry\n .getConsumerClasses(queueMessage.type)\n .map((ConsumerClass) => container.resolve<IQueueConsumer>(ConsumerClass))\n\n const results = await Promise.allSettled(\n consumers.map((consumer) => consumer.handle(queueMessage)),\n )\n\n let lastError: Error | undefined\n let failedConsumer: string | undefined\n\n for (let i = 0; i < results.length; i++) {\n const result = results[i]\n if (result.status === 'rejected') {\n const consumer = consumers[i]\n const errorInstance = result.reason instanceof Error\n ? result.reason\n : new Error(String(result.reason))\n\n this.logger.error('Queue message processing failed', errorInstance, {\n type: queueMessage.type,\n queue: queueName,\n messageId: queueMessage.id,\n idempotencyKey,\n })\n\n if (consumer.onError) {\n await consumer.onError(errorInstance, queueMessage)\n }\n\n lastError = errorInstance\n failedConsumer = consumer.constructor.name\n }\n }\n\n const failed = lastError !== undefined\n\n if (failed) {\n // `message.attempts` is 1-based (the first delivery is attempt 1), so a\n // message is only out of retries once it has been delivered more than\n // `maxRetries` times. `maxRetries: 3` therefore means 3 retries after the\n // initial delivery (4 total attempts). This must be <= the consumer's\n // `max_retries` in wrangler.jsonc, otherwise Cloudflare dead-letters the\n // message before this branch ever runs and it never reaches the store.\n if (message.attempts > this.maxRetries) {\n // A KV failure (or a message dispatched outside Stratal, with no\n // binding to retry through) while persisting the failed job must not\n // abort the rest of the batch — log and ack so the message isn't\n // redelivered forever.\n try {\n const binding = queueMessage.metadata?.binding\n if (!binding) {\n throw new QueueError(\n `Queue message ${queueMessage.id} has no binding metadata and cannot be recorded for retry. ` +\n `Messages must be dispatched through a Stratal queue sender (@InjectQueue).`,\n )\n }\n\n const failedJob: FailedJob = {\n id: queueMessage.id,\n queue: queueName,\n binding,\n type: queueMessage.type,\n message: queueMessage,\n error: {\n name: lastError!.name,\n message: lastError!.message,\n stack: lastError!.stack,\n },\n consumer: failedConsumer!,\n attempts: message.attempts,\n failedAt: new Date().toISOString(),\n }\n\n await this.store.storeFailedJob(failedJob)\n } catch (error) {\n this.logger.error(\n 'Failed to persist failed queue job',\n error instanceof Error ? error : new Error(String(error)),\n { queue: queueName, messageId: queueMessage.id, type: queueMessage.type },\n )\n }\n message.ack()\n } else {\n message.retry()\n }\n } else {\n await this.store.markProcessed(idempotencyKey)\n message.ack()\n }\n }\n }\n}\n","import { Singleton } from '../di/decorators'\nimport { DI_TOKENS } from '../di/tokens'\nimport type { Constructor } from '../types'\nimport type { IQueueConsumer } from './queue-consumer'\n\n/** A registered consumer class together with the message types it handles. */\nexport interface ConsumerRegistration {\n consumerClass: Constructor<IQueueConsumer>\n messageTypes: string[]\n}\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@Singleton(DI_TOKENS.ConsumerRegistry)\nexport class ConsumerRegistry {\n /** Map from message type to consumer classes handling that type */\n private classesByType = new Map<string, Constructor<IQueueConsumer>[]>()\n\n /** All registrations (for iteration / listing) */\n private registrations: ConsumerRegistration[] = []\n\n /** Registered consumer classes (dedupe) */\n private registeredClasses = new Set<Constructor<IQueueConsumer>>()\n\n /**\n * Register a queue consumer class.\n *\n * Indexes the class by each of its declared message types. A fresh instance\n * is resolved per message from the request-scoped container at dispatch time —\n * consumers are never held as long-lived singletons, so they may safely inject\n * request-scoped providers (`@InjectQueue`, i18n, auth context, …).\n *\n * @param consumerClass - Queue consumer class to register\n * @param messageTypes - Message types the consumer handles\n */\n register(consumerClass: Constructor<IQueueConsumer>, messageTypes: string[]): void {\n if (this.registeredClasses.has(consumerClass)) {\n return // Already registered\n }\n\n this.registeredClasses.add(consumerClass)\n this.registrations.push({ consumerClass, messageTypes })\n\n for (const messageType of messageTypes) {\n const existing = this.classesByType.get(messageType) ?? []\n existing.push(consumerClass)\n this.classesByType.set(messageType, existing)\n }\n }\n\n /**\n * Get all consumer classes that can handle a specific message type.\n *\n * Returns classes that either declare the message type explicitly or use the\n * `'*'` wildcard. Callers resolve a fresh instance per message from the\n * request-scoped container.\n *\n * @param messageType - The message type to find consumers for\n * @returns Array of consumer classes that can handle this message type\n */\n getConsumerClasses(messageType: string): Constructor<IQueueConsumer>[] {\n const exactMatch = this.classesByType.get(messageType) ?? []\n const wildcardMatch = this.classesByType.get('*') ?? []\n\n // Combine and dedupe\n return Array.from(new Set([...exactMatch, ...wildcardMatch]))\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.getConsumerClasses(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.classesByType.keys())\n }\n\n /**\n * Get all consumer registrations (class + message types) for listing.\n */\n getRegistrations(): readonly ConsumerRegistration[] {\n return this.registrations\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 binding.\n * Created by QueueRegistry for each registered binding.\n *\n * Automatically enriches messages with:\n * - `id`: UUID generated via crypto.randomUUID()\n * - `metadata.locale`: Current locale from I18n context\n * - `metadata.idempotencyKey`: Deterministic SHA-256 hash of type + payload (if not provided)\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 binding: 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)\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 metadata.idempotencyKey ??= await this.generateIdempotencyKey(message.type, message.payload);\n\n // Stamp the producer binding so a failed job can be retried to the right\n // Cloudflare binding. Consumers only see the queue *name*, which is not a\n // valid producer binding key.\n metadata.binding = this.binding\n\n const fullMessage: QueueMessage<T> = {\n id: crypto.randomUUID(),\n ...message,\n metadata,\n }\n\n await this.provider.send(this.binding, fullMessage)\n }\n\n private async generateIdempotencyKey(type: string, payload: unknown): Promise<string> {\n // Use a stable, key-sorted serialization: `JSON.stringify` preserves\n // insertion order, so two semantically identical payloads with differently\n // ordered keys would otherwise hash differently and defeat deduplication.\n const data = new TextEncoder().encode(stableStringify({ type, payload }))\n const hash = await crypto.subtle.digest('SHA-256', data)\n return `queue:${Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2, '0')).join('')}`\n }\n}\n\n/**\n * Deterministic JSON serialization: object keys are emitted in sorted order at\n * every level so the output depends only on the data, not on key insertion\n * order. Arrays keep their order (order is significant). Used to derive a stable\n * idempotency hash from a message's `type` + `payload`.\n */\nfunction stableStringify(value: unknown): string {\n if (value === null || typeof value !== 'object') {\n return JSON.stringify(value) ?? 'null'\n }\n if (Array.isArray(value)) {\n return `[${value.map(stableStringify).join(',')}]`\n }\n const entries = Object.keys(value as Record<string, unknown>)\n .sort()\n .map((key) => {\n const v = (value as Record<string, unknown>)[key]\n if (v === undefined) return undefined\n return `${JSON.stringify(key)}:${stableStringify(v)}`\n })\n .filter((entry): entry is string => entry !== undefined)\n return `{${entries.join(',')}}`\n}\n","import { inject } from '../di'\nimport { Request } 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 { type QueueProviderFactory } from './services'\n\n/**\n * Queue Registry\n *\n * Request-scoped factory service for creating QueueSender instances.\n * Caches senders per binding within the request scope.\n *\n * This service is used internally by QueueModule.registerQueue() to provide\n * IQueueSender instances for each registered binding.\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@Request(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 binding.\n *\n * Senders are cached per binding within the request scope.\n *\n * @param binding - The queue binding to get a sender for\n * @returns QueueSender bound to the specified binding\n */\n getQueue(binding: string): IQueueSender {\n let sender = this.senders.get(binding)\n\n if (!sender) {\n sender = new QueueSender(binding, this.provider, this.i18n)\n this.senders.set(binding, sender)\n }\n\n return sender\n }\n}\n","import { inject } from '../di';\nimport { Transient } from '../di/decorators';\nimport { CACHE_TOKENS } from '../cache/cache.tokens';\nimport type { TieredCacheService } from '../cache/services/tiered-cache.service';\nimport type { FailedJob, FailedJobMetadata } from './failed-job';\nimport type { QueueModuleOptions } from './queue.module';\nimport { QUEUE_TOKENS } from './queue.tokens';\n\nconst IDEM_PREFIX = 'queue:idem:'\nconst FAILED_PREFIX = 'queue:failed:'\nconst DEFAULT_IDEMPOTENCY_TTL = 86400\n\n/** Default KV binding name used for queue state when none is configured. */\nexport const DEFAULT_STORE_BINDING = 'CACHE'\n\n/**\n * Persists queue idempotency claims and failed jobs.\n *\n * Backed by {@link TieredCacheService} (isolate-local L1 + KV). The L1 is what\n * makes `markProcessed` → `isProcessed` reliable within an isolate: a claim\n * written on this isolate is read back from memory, so a message redelivered to\n * the same warm isolate is de-duplicated even inside KV's eventual-consistency\n * window. Idempotency markers are set-once, the pattern the L1 tier is designed\n * for. Cross-isolate duplicates still rely on KV (eventually consistent) —\n * delivery remains at-least-once with best-effort de-duplication, not\n * exactly-once.\n */\n@Transient(QUEUE_TOKENS.QueueStore)\nexport class QueueStore {\n private readonly cache: TieredCacheService\n private readonly idempotencyTtl: number\n\n constructor(\n @inject(CACHE_TOKENS.TieredCacheService) cache: TieredCacheService,\n @inject(QUEUE_TOKENS.QueueModuleOptions) options: QueueModuleOptions,\n ) {\n // Bind to the configured KV namespace via the tiered cache so the L1 lives\n // on its singleton (one per isolate) and persists across messages. The\n // binding is validated at module init (QueueModule.onInitialize);\n // `binding()` also throws if it is somehow absent here.\n this.cache = cache.binding(options.store?.binding ?? DEFAULT_STORE_BINDING)\n this.idempotencyTtl = options.idempotency?.ttl ?? DEFAULT_IDEMPOTENCY_TTL\n }\n\n async isProcessed(key: string): Promise<boolean> {\n return (await this.cache.get(`${IDEM_PREFIX}${key}`)) !== null\n }\n\n async markProcessed(key: string): Promise<void> {\n await this.cache.put(`${IDEM_PREFIX}${key}`, '1', {\n expirationTtl: this.idempotencyTtl,\n })\n }\n\n async storeFailedJob(job: FailedJob): Promise<void> {\n const metadata: FailedJobMetadata = {\n queue: job.queue,\n binding: job.binding,\n type: job.type,\n consumer: job.consumer,\n attempts: job.attempts,\n failedAt: job.failedAt,\n }\n\n await this.cache.put(`${FAILED_PREFIX}${job.id}`, JSON.stringify(job), {\n metadata,\n })\n }\n\n async getFailedJob(messageId: string): Promise<FailedJob | null> {\n return this.cache.get<FailedJob>(`${FAILED_PREFIX}${messageId}`, 'json')\n }\n\n async removeFailedJob(messageId: string): Promise<void> {\n await this.cache.delete(`${FAILED_PREFIX}${messageId}`)\n }\n\n async listFailedJobs(options?: {\n limit?: number\n cursor?: string\n }): Promise<{ keys: { id: string; metadata: FailedJobMetadata }[]; cursor?: string }> {\n const result = await this.cache.list<FailedJobMetadata>({\n prefix: FAILED_PREFIX,\n limit: options?.limit ?? 50,\n cursor: options?.cursor,\n })\n\n // Skip keys without metadata: a partially-written entry (or one written by\n // an older code path) is unusable for listing and must not crash the page.\n const keys = result.keys\n .filter((key): key is typeof key & { metadata: FailedJobMetadata } => key.metadata != null)\n .map((key) => ({\n id: key.name.slice(FAILED_PREFIX.length),\n metadata: key.metadata,\n }))\n\n return {\n keys,\n cursor: result.list_complete ? undefined : result.cursor,\n }\n }\n\n async purgeFailedJobs(): Promise<void> {\n let cursor: string | undefined\n\n do {\n const result = await this.cache.list({ prefix: FAILED_PREFIX, cursor })\n await Promise.all(result.keys.map((key) => this.cache.delete(key.name)))\n cursor = result.list_complete ? undefined : result.cursor\n } while (cursor)\n }\n\n /**\n * Delete failed jobs older than `retentionSeconds` (by their `failedAt`\n * timestamp). Returns the number removed. Backs the opt-in\n * {@link FailedJobCleanupJob} cron — failed jobs otherwise persist\n * indefinitely until retried or purged.\n */\n async purgeFailedJobsOlderThan(retentionSeconds: number): Promise<number> {\n const cutoff = Date.now() - retentionSeconds * 1000\n let cursor: string | undefined\n let removed = 0\n\n do {\n const result = await this.cache.list<FailedJobMetadata>({ prefix: FAILED_PREFIX, cursor })\n const expired = result.keys.filter((key) => {\n const failedAt = key.metadata?.failedAt\n return failedAt !== undefined && Date.parse(failedAt) < cutoff\n })\n await Promise.all(expired.map((key) => this.cache.delete(key.name)))\n removed += expired.length\n cursor = result.list_complete ? undefined : result.cursor\n } while (cursor)\n\n return removed\n }\n}\n","import { inject } from '../../di'\nimport { type StratalEnv } from '../../env'\nimport { Transient } from '../../di/decorators'\nimport { DI_TOKENS } from '../../di/tokens'\nimport { QueueError } from '../queue.error'\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 the binding directly on\n * the worker's `env`. Used in production environments where Cloudflare Workers\n * handle queue processing.\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 binding - Queue binding identifier (e.g., 'NOTIFICATIONS_QUEUE')\n * @param message - Complete message with id and payload\n * @throws {QueueError} If the binding is not configured on env\n */\n async send<T>(binding: string, message: QueueMessage<T>): Promise<void> {\n const queue = (this.env as unknown as Record<string, unknown>)[binding] as Queue | undefined\n\n if (!queue) {\n throw new QueueError(`Queue binding \"${binding}\" was not found in the environment`)\n }\n\n await queue.send(message)\n }\n}\n","import type { Container } from '../../di/container'\nimport { containerStorage } from '../../di/container-storage'\nimport { inject } from '../../di'\nimport { Transient } from '../../di/decorators'\nimport { DI_TOKENS } from '../../di/tokens'\nimport type { RouterContext } from '../../router/router-context'\nimport { type ConsumerRegistry } from '../consumer-registry'\nimport type { IQueueConsumer, 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@Transient()\nexport class SyncQueueProvider implements IQueueProvider {\n constructor(\n @inject(DI_TOKENS.ConsumerRegistry) private readonly registry: ConsumerRegistry,\n @inject(DI_TOKENS.Container) private readonly root: Container,\n ) {}\n\n /**\n * Process a message synchronously.\n *\n * Runs inside the active request scope when dispatch happens within one (an\n * HTTP request, or `runInScope` for queues/cron/commands). When dispatched\n * with no ambient scope — e.g. a service invoked directly in a test — it\n * establishes its own request scope (mirroring the production queue handler)\n * so consumers and their request-scoped dependencies resolve correctly.\n *\n * @param _binding - Queue binding (not used for routing, consumers match by message type)\n * @param message - Complete message with id and payload\n * @throws Re-throws any error from consumer.handle() after calling onError()\n */\n async send<T>(_binding: string, message: QueueMessage<T>): Promise<void> {\n const ambient = containerStorage.getStore()\n if (ambient) {\n await this.process(ambient, message)\n return\n }\n\n const locale = message.metadata?.locale ?? 'en'\n const context = {\n getLocale: () => locale,\n setLocale: () => { /* no-op */ },\n getContainer: () => containerStorage.getStore() ?? this.root,\n } as unknown as RouterContext\n\n await this.root.runInRequestScope(context, (container) => this.process(container, message))\n }\n\n /**\n * Resolve a fresh consumer per message from `container` (matched by type) and\n * invoke each sequentially, fail-fast on the first error after `onError`.\n */\n private async process<T>(container: Container, message: QueueMessage<T>): Promise<void> {\n const consumers = this.registry\n .getConsumerClasses(message.type)\n .map((ConsumerClass) => container.resolve<IQueueConsumer>(ConsumerClass))\n\n for (const consumer of consumers) {\n try {\n await consumer.handle(message)\n } catch (error) {\n const errorInstance = error instanceof Error ? error : 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 '../../di'\nimport type { Container } from '../../di/container'\nimport { type StratalEnv } from '../../env'\nimport { Transient } from '../../di/decorators'\nimport { DI_TOKENS } from '../../di/tokens'\nimport { type ConsumerRegistry } from '../consumer-registry'\nimport { QueueError } from '../queue.error'\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(DI_TOKENS.Container) private readonly container: Container,\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 {QueueError} 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, this.container)\n\n default:\n throw new QueueError(`Queue provider \"${String(providerType)}\" is not supported`)\n }\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 queue bindings (the binding IS the injection token)\n * QueueModule.registerQueue('NOTIFICATIONS_QUEUE')\n * QueueModule.registerQueue('BACKGROUND_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 { CacheModule } from '../cache';\nimport { DI_TOKENS } from '../di/tokens';\nimport { type StratalEnv } from '../env';\nimport { Module } from '../module';\nimport type {\n AsyncModuleOptions,\n DynamicModule,\n InjectionToken,\n ModuleContext,\n OnInitialize,\n} from '../module/types';\nimport { ConsumerRegistry } from './consumer-registry';\nimport type { QueueBinding } from './queue-binding';\nimport { QueueManager } from './queue-manager';\nimport { QueueRegistry } from './queue-registry';\nimport type { IQueueSender } from './queue-sender.interface';\nimport { QueueError } from './queue.error';\nimport { DEFAULT_STORE_BINDING, QueueStore } from './queue-store';\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 * KV binding for queue state (idempotency keys + failed jobs).\n * Defaults to the `CACHE` binding if omitted.\n */\n store?: {\n /**\n * KV namespace binding name.\n * @default CACHE\n */\n binding?: string\n }\n\n /**\n * Idempotency configuration.\n *\n * Delivery is **at-least-once with best-effort de-duplication**, not\n * exactly-once. Every dispatch carries an idempotency key (an explicit\n * `metadata.idempotencyKey`, otherwise a deterministic SHA-256 hash of `type`\n * + `payload`), and a message already recorded as processed is skipped. The\n * processed marker is written only after a handler succeeds, and KV `get`/`put`\n * are eventually consistent — so a message redelivered concurrently (or after\n * a crash before the marker was durable) can still run more than once. Make\n * handlers idempotent; don't rely on this as a hard exactly-once guarantee.\n * `ttl` bounds how long processed keys are remembered.\n */\n idempotency?: {\n /** TTL in seconds for processed idempotency keys. Default: 86400 (24h) */\n ttl?: number\n }\n\n /**\n * Failed-job configuration.\n *\n * Failed jobs persist indefinitely until retried or purged. To bound growth,\n * register the opt-in `FailedJobCleanupJob` cron in a module's `jobs` array;\n * it deletes failed jobs older than `retention`.\n */\n failedJobs?: {\n /**\n * Age in seconds beyond which `FailedJobCleanupJob` deletes a failed job.\n * Default: 604800 (7d). Has no effect unless the cron is registered.\n */\n retention?: number\n }\n\n /** Max retry attempts before storing as failed job. Default: 3 */\n maxRetries?: number\n}\n\n@Module({\n // QueueStore persists idempotency claims and failed jobs through CacheService\n // (isolate-local L1 + KV), so the cache must be available wherever queues are.\n imports: [CacheModule],\n providers: [\n { provide: DI_TOKENS.ConsumerRegistry, useClass: ConsumerRegistry },\n QueueManager,\n { provide: QUEUE_TOKENS.QueueProviderFactory, useClass: QueueProviderFactory },\n { provide: QUEUE_TOKENS.QueueRegistry, useClass: QueueRegistry },\n { provide: QUEUE_TOKENS.QueueStore, useClass: QueueStore },\n ],\n})\nexport class QueueModule implements OnInitialize {\n /**\n * Fail fast at boot if the configured KV store binding is missing, rather\n * than letting every queue invocation hard-fail lazily. The binding backs\n * idempotency claims and failed-job storage, so without it the queue\n * subsystem cannot function.\n */\n onInitialize({ container }: ModuleContext): void {\n const options = container.resolve<QueueModuleOptions>(QUEUE_TOKENS.QueueModuleOptions)\n\n // Only the `cloudflare` provider persists idempotency claims and failed jobs\n // to KV. The `sync` provider (dev/CLI) processes inline and never touches the\n // store, so it must not require the binding.\n if (options.provider !== 'cloudflare') return\n\n const binding = options.store?.binding ?? DEFAULT_STORE_BINDING\n const env = container.resolve<StratalEnv>(DI_TOKENS.CloudflareEnv)\n const kv = (env as unknown as Record<string, unknown>)[binding]\n\n if (!kv) {\n throw new QueueError(\n `Queue KV store binding \"${binding}\" was not found in the environment. ` +\n `The queue subsystem persists idempotency claims and failed jobs to KV. ` +\n `Add a kv_namespaces entry for \"${binding}\" in wrangler.jsonc, or set ` +\n `QueueModule.forRootAsync({ ..., store: { binding: 'YOUR_KV' } }) to point at an existing namespace.`,\n )\n }\n }\n\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 binding for injection.\n *\n * The binding name doubles as the DI injection token and the\n * `env`-lookup key. Binding names are typed against `StratalEnv`\n * (autocomplete works once an app augments `StratalEnv` with its\n * Cloudflare bindings).\n *\n * @param binding - Queue binding identifier (e.g. `NOTIFICATIONS_QUEUE`).\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 binding name\n * constructor(@InjectQueue('NOTIFICATIONS_QUEUE') private queue: IQueueSender) {}\n * ```\n */\n static registerQueue(binding: QueueBinding): DynamicModule {\n return {\n module: QueueModule,\n providers: [\n {\n provide: binding as InjectionToken<IQueueSender>,\n useFactory: (registry: QueueRegistry) => registry.getQueue(binding),\n inject: [QUEUE_TOKENS.QueueRegistry],\n },\n ],\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAEA,IAAa,aAAb,cAAgC,iBAAiB,CAAC;;;ACWlD,MAAM,sBAAsB;AAGrB,IAAA,eAAA,MAAM,aAAa;CAI+B;CACC;CACJ;CALpD;CAEA,YACE,UACA,QACA,OACA,SACA;EAJqD,KAAA,WAAA;EACC,KAAA,SAAA;EACJ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;;;;;;;;;;;;ACgF1D,IAAA,cAAA,eAAA,MAAM,YAAoC;;;;;;;CAO/C,aAAa,EAAE,aAAkC;EAC/C,MAAM,UAAU,UAAU,QAA4B,aAAa,kBAAkB;EAKrF,IAAI,QAAQ,aAAa,cAAc;EAEvC,MAAM,UAAU,QAAQ,OAAO,WAAA;EAI/B,IAAI,CAHQ,UAAU,QAAoB,UAAU,aACtC,EAAyC,UAGrD,MAAM,IAAI,WACR,2BAA2B,QAAQ,4IAEC,QAAQ,gIAE9C;CAEJ;;;;;;;;;;;;;;;;;;;CAoBA,OAAO,aAAa,SAAgE;EAClF,OAAO;GACL,QAAA;GACA,WAAW,CACT;IACE,SAAS,aAAa;IACtB,YAAY,QAAQ;IACpB,QAAQ,QAAQ;GAClB,CACF;EACF;CACF;;;;;;;;;;;;;;;;;;;;;CAsBA,OAAO,cAAc,SAAsC;EACzD,OAAO;GACL,QAAA;GACA,WAAW,CACT;IACE,SAAS;IACT,aAAa,aAA4B,SAAS,SAAS,OAAO;IAClE,QAAQ,CAAC,aAAa,aAAa;GACrC,CACF;EACF;CACF;AACF;yCAxGC,OAAO;CAGN,SAAS,CAAC,WAAW;CACrB,WAAW;EACT;GAAE,SAAS,UAAU;GAAkB,UAAU;EAAiB;EAClE;EACA;GAAE,SAAS,aAAa;GAAsB,UAAU;EAAqB;EAC7E;GAAE,SAAS,aAAa;GAAe,UAAU;EAAc;EAC/D;GAAE,SAAS,aAAa;GAAY,UAAU;EAAW;CAC3D;AACF,CAAC,CAAA,GAAA,WAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-BBjsoOtd.mjs";
|
|
2
|
-
import { t as StorageError } from "./storage.error-
|
|
2
|
+
import { t as StorageError } from "./storage.error-Dai3rShJ.mjs";
|
|
3
3
|
import { t as signUrl } from "./signed-url-DIU0sK_6.mjs";
|
|
4
4
|
//#region src/storage/providers/r2-storage.provider.ts
|
|
5
5
|
var r2_storage_provider_exports = /* @__PURE__ */ __exportAll({ R2StorageProvider: () => R2StorageProvider });
|
|
@@ -244,4 +244,4 @@ var R2StorageProvider = class {
|
|
|
244
244
|
//#endregion
|
|
245
245
|
export { r2_storage_provider_exports as n, R2StorageProvider as t };
|
|
246
246
|
|
|
247
|
-
//# sourceMappingURL=r2-storage.provider-
|
|
247
|
+
//# sourceMappingURL=r2-storage.provider-BJ4j23W6.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"r2-storage.provider-DCxQt9dD.mjs","names":[],"sources":["../src/storage/providers/r2-storage.provider.ts"],"sourcesContent":["import { type StratalEnv } from '../../env'\nimport { signUrl } from '../../router/signed-url'\nimport type { DownloadResult, PresignedUrlResult, UploadOptions, UploadResult } from '../contracts'\nimport { StorageError } from '../storage.error'\nimport type { StorageEntry, StorageRouteConfig } from '../types'\nimport type {\n CompletedPart,\n CompleteMultipartResult,\n CreateMultipartOptions,\n CreateMultipartResult,\n DeleteObjectsResult,\n HeadObjectResult,\n IMultipartProvider,\n ListMultipartUploadsResult,\n ListPartsResult,\n UploadPartResult,\n} from './multipart-provider.interface'\nimport type { StreamingBlobPayloadInputTypes } from './storage-provider.interface'\n\nconst MIN_PART_SIZE = 5 * 1024 * 1024 // 5MB\nconst MULTIPART_PREFIX = '__multipart/'\nconst PARTS_PREFIX = '__parts/'\n\n/**\n * R2 Storage Provider\n * Implements storage operations using native Cloudflare R2 bindings\n *\n * Implements IMultipartProvider for multipart upload support needed by TUS.\n * Tracks multipart upload metadata using companion R2 objects so that\n * listParts/listMultipartUploads work in all environments (local, test, prod).\n */\nexport class R2StorageProvider implements IMultipartProvider {\n private readonly routeBasePath: string\n\n constructor(\n private readonly config: StorageEntry,\n private readonly bucket: R2Bucket,\n private readonly env: StratalEnv,\n routeConfig?: StorageRouteConfig\n ) {\n this.routeBasePath = routeConfig?.basePath ?? '/storage'\n }\n\n async upload(\n body: StreamingBlobPayloadInputTypes,\n path: string,\n options: UploadOptions\n ): Promise<UploadResult> {\n const customMetadata: Record<string, string> = { ...options.metadata }\n if (options.tagging) {\n customMetadata['x-tags'] = options.tagging\n }\n\n await this.bucket.put(path, body as ReadableStream | ArrayBuffer | ArrayBufferView | string | Blob | null, {\n httpMetadata: {\n contentType: options.mimeType,\n },\n customMetadata,\n })\n\n return {\n path,\n disk: this.config.disk,\n fullPath: path,\n size: options.size,\n mimeType: options.mimeType ?? 'application/octet-stream',\n uploadedAt: new Date(),\n }\n }\n\n async download(path: string): Promise<DownloadResult> {\n const obj = await this.bucket.get(path)\n\n if (!obj) {\n throw new StorageError(`Storage object not found at path \"${path}\"`)\n }\n\n // R2ObjectBody has body, text(), arrayBuffer(), etc.\n const objBody = obj\n\n return {\n toStream: () => objBody.body as ReadableStream<Uint8Array>,\n contentType: obj.httpMetadata?.contentType ?? 'application/octet-stream',\n size: obj.size,\n metadata: obj.customMetadata,\n toString: () => objBody.text(),\n toArrayBuffer: () => objBody.bytes(),\n }\n }\n\n async delete(path: string): Promise<void> {\n await this.bucket.delete(path)\n }\n\n async exists(path: string): Promise<boolean> {\n const head = await this.bucket.head(path)\n return head !== null\n }\n\n async getPresignedUrl(\n path: string,\n method: 'GET' | 'PUT' | 'DELETE' | 'HEAD',\n expiresIn: number\n ): Promise<PresignedUrlResult> {\n const secret = this.env.APP_SECRET;\n if (!secret) {\n throw new StorageError('APP_SECRET is required for generating presigned URLs')\n }\n\n // Build a relative URL pointing to the StorageController route\n const routePath = `${this.routeBasePath}/${this.config.disk}/${path}`\n const urlWithMethod = `${routePath}?method=${method}`\n const url = await signUrl(urlWithMethod, secret, { expiresIn })\n\n return {\n url,\n expiresIn,\n expiresAt: new Date(Date.now() + expiresIn * 1000),\n method,\n }\n }\n\n async chunkedUpload(\n body: StreamingBlobPayloadInputTypes,\n path: string,\n options: Omit<UploadOptions, 'size'> & { size?: number }\n ): Promise<UploadResult> {\n const multipartUpload = await this.bucket.createMultipartUpload(path, {\n httpMetadata: {\n contentType: options.mimeType,\n },\n customMetadata: options.metadata,\n })\n\n const parts: R2UploadedPart[] = []\n\n try {\n if (body instanceof ReadableStream) {\n const reader = (body as ReadableStream<Uint8Array>).getReader()\n let buffer = new Uint8Array(0)\n let partNumber = 1\n\n while (true) {\n const { done, value } = await reader.read()\n\n if (value) {\n const newBuffer = new Uint8Array(buffer.length + value.length)\n newBuffer.set(buffer, 0)\n newBuffer.set(value, buffer.length)\n buffer = newBuffer\n }\n\n while (buffer.length >= MIN_PART_SIZE) {\n const partData = buffer.slice(0, MIN_PART_SIZE)\n buffer = buffer.slice(MIN_PART_SIZE)\n const part = await multipartUpload.uploadPart(partNumber, partData)\n parts.push(part)\n partNumber++\n }\n\n if (done) {\n // Upload remaining buffer as final part\n if (buffer.length > 0) {\n const part = await multipartUpload.uploadPart(partNumber, buffer)\n parts.push(part)\n }\n break\n }\n }\n } else if (body !== null && body !== undefined) {\n // Non-stream body: upload as single part\n const part = await multipartUpload.uploadPart(1, body as ArrayBuffer | ArrayBufferView | string | Blob)\n parts.push(part)\n }\n\n await multipartUpload.complete(parts)\n } catch (error) {\n await multipartUpload.abort()\n throw error\n }\n\n // Get actual size via head\n const headResult = await this.bucket.head(path)\n\n return {\n path,\n disk: this.config.disk,\n fullPath: path,\n size: headResult?.size ?? options.size ?? 0,\n mimeType: options.mimeType ?? 'application/octet-stream',\n uploadedAt: new Date(),\n }\n }\n\n // ============================================\n // IMultipartProvider - Multipart upload methods\n // ============================================\n\n getBucket(): string {\n return this.config.binding\n }\n\n async headObject(key: string): Promise<HeadObjectResult | null> {\n const obj = await this.bucket.head(key)\n if (!obj) {\n return null\n }\n return {\n size: obj.size,\n contentType: obj.httpMetadata?.contentType,\n metadata: obj.customMetadata,\n }\n }\n\n async deleteObjects(keys: string[]): Promise<DeleteObjectsResult> {\n if (keys.length === 0) {\n return { deleted: 0, errors: [] }\n }\n\n await this.bucket.delete(keys)\n\n return {\n deleted: keys.length,\n errors: [],\n }\n }\n\n async createMultipartUpload(\n key: string,\n options?: CreateMultipartOptions\n ): Promise<CreateMultipartResult> {\n const upload = await this.bucket.createMultipartUpload(key, {\n httpMetadata: {\n contentType: options?.contentType,\n cacheControl: options?.cacheControl,\n },\n customMetadata: options?.metadata,\n })\n\n // Track upload for listMultipartUploads\n await this.bucket.put(\n `${MULTIPART_PREFIX}${upload.uploadId}.json`,\n JSON.stringify({ key: upload.key, uploadId: upload.uploadId, initiated: new Date().toISOString() }),\n { httpMetadata: { contentType: 'application/json' } }\n )\n\n return {\n uploadId: upload.uploadId,\n key: upload.key,\n }\n }\n\n async uploadPart(\n key: string,\n uploadId: string,\n partNumber: number,\n body: Uint8Array\n ): Promise<UploadPartResult> {\n const upload = this.bucket.resumeMultipartUpload(key, uploadId)\n const part = await upload.uploadPart(partNumber, body)\n\n // Track part for listParts\n await this.bucket.put(\n `${PARTS_PREFIX}${uploadId}/${partNumber}`,\n JSON.stringify({ partNumber: part.partNumber, etag: part.etag, size: body.length }),\n { httpMetadata: { contentType: 'application/json' } }\n )\n\n return {\n etag: part.etag,\n partNumber: part.partNumber,\n }\n }\n\n async completeMultipartUpload(\n key: string,\n uploadId: string,\n parts: CompletedPart[]\n ): Promise<CompleteMultipartResult> {\n const upload = this.bucket.resumeMultipartUpload(key, uploadId)\n const result = await upload.complete(\n parts.map((p) => ({\n partNumber: p.partNumber,\n etag: p.etag,\n }))\n )\n\n await this.cleanupTrackingObjects(uploadId)\n\n return {\n key: result.key,\n }\n }\n\n async abortMultipartUpload(key: string, uploadId: string): Promise<void> {\n const upload = this.bucket.resumeMultipartUpload(key, uploadId)\n await upload.abort()\n\n await this.cleanupTrackingObjects(uploadId)\n }\n\n async listParts(\n _key: string,\n uploadId: string,\n partNumberMarker?: string\n ): Promise<ListPartsResult> {\n const prefix = `${PARTS_PREFIX}${uploadId}/`\n const listed = await this.bucket.list({\n prefix,\n cursor: partNumberMarker,\n })\n\n const parts = await Promise.all(\n listed.objects.map(async (obj) => {\n const data = await this.bucket.get(obj.key)\n if (!data) {\n return null\n }\n return JSON.parse(await data.text()) as { partNumber: number; etag: string; size: number }\n })\n )\n\n const validParts = parts\n .filter((p): p is NonNullable<typeof p> => p !== null)\n .sort((a, b) => a.partNumber - b.partNumber)\n\n return {\n parts: validParts,\n isTruncated: listed.truncated,\n nextPartNumberMarker: listed.truncated ? listed.cursor : undefined,\n }\n }\n\n async listMultipartUploads(\n keyMarker?: string,\n _uploadIdMarker?: string\n ): Promise<ListMultipartUploadsResult> {\n const listed = await this.bucket.list({\n prefix: MULTIPART_PREFIX,\n cursor: keyMarker,\n })\n\n const uploads = await Promise.all(\n listed.objects.map(async (obj) => {\n const data = await this.bucket.get(obj.key)\n if (!data) {\n return null\n }\n const parsed = JSON.parse(await data.text()) as { key: string; uploadId: string; initiated: string }\n return {\n key: parsed.key,\n uploadId: parsed.uploadId,\n initiated: new Date(parsed.initiated),\n }\n })\n )\n\n return {\n uploads: uploads.filter((u): u is NonNullable<typeof u> => u !== null),\n isTruncated: listed.truncated,\n nextKeyMarker: listed.truncated ? listed.cursor : undefined,\n nextUploadIdMarker: undefined,\n }\n }\n\n // ============================================\n // Private helpers\n // ============================================\n\n private async cleanupTrackingObjects(uploadId: string): Promise<void> {\n // Delete part tracking objects\n const partsPrefix = `${PARTS_PREFIX}${uploadId}/`\n let cursor: string | undefined\n const keysToDelete: string[] = []\n\n do {\n const listed = await this.bucket.list({ prefix: partsPrefix, cursor })\n for (const obj of listed.objects) {\n keysToDelete.push(obj.key)\n }\n cursor = listed.truncated ? listed.cursor : undefined\n } while (cursor)\n\n // Delete multipart tracking object\n keysToDelete.push(`${MULTIPART_PREFIX}${uploadId}.json`)\n\n if (keysToDelete.length > 0) {\n await this.bucket.delete(keysToDelete)\n }\n }\n}\n"],"mappings":";;;;;AAmBA,MAAM,gBAAgB,IAAI,OAAO;AACjC,MAAM,mBAAmB;AACzB,MAAM,eAAe;;;;;;;;;AAUrB,IAAa,oBAAb,MAA6D;CAIxC;CACA;CACA;CALnB;CAEA,YACE,QACA,QACA,KACA,aACA;EAJiB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,OAAO;IAET,MAAM,SAAS,KAAK,MAAM,MAAM,KAAK,KAAK,CAAC;IAC3C,OAAO;KACL,KAAK,OAAO;KACZ,UAAU,OAAO;KACjB,WAAW,IAAI,KAAK,OAAO,SAAS;IACtC;GACF,CAAC,CACH,GAGmB,QAAQ,MAAkC,MAAM,IAAI;GACrE,aAAa,OAAO;GACpB,eAAe,OAAO,YAAY,OAAO,SAAS,KAAA;GAClD,oBAAoB,KAAA;EACtB;CACF;CAMA,MAAc,uBAAuB,UAAiC;EAEpE,MAAM,cAAc,GAAG,eAAe,SAAS;EAC/C,IAAI;EACJ,MAAM,eAAyB,CAAC;EAEhC,GAAG;GACD,MAAM,SAAS,MAAM,KAAK,OAAO,KAAK;IAAE,QAAQ;IAAa;GAAO,CAAC;GACrE,KAAK,MAAM,OAAO,OAAO,SACvB,aAAa,KAAK,IAAI,GAAG;GAE3B,SAAS,OAAO,YAAY,OAAO,SAAS,KAAA;EAC9C,SAAS;EAGT,aAAa,KAAK,GAAG,mBAAmB,SAAS,MAAM;EAEvD,IAAI,aAAa,SAAS,GACxB,MAAM,KAAK,OAAO,OAAO,YAAY;CAEzC;AACF"}
|
|
1
|
+
{"version":3,"file":"r2-storage.provider-BJ4j23W6.mjs","names":[],"sources":["../src/storage/providers/r2-storage.provider.ts"],"sourcesContent":["import { type StratalEnv } from '../../env'\nimport { signUrl } from '../../router/signed-url'\nimport type { DownloadResult, PresignedUrlResult, UploadOptions, UploadResult } from '../contracts'\nimport { StorageError } from '../storage.error'\nimport type { StorageEntry, StorageRouteConfig } from '../types'\nimport type {\n CompletedPart,\n CompleteMultipartResult,\n CreateMultipartOptions,\n CreateMultipartResult,\n DeleteObjectsResult,\n HeadObjectResult,\n IMultipartProvider,\n ListMultipartUploadsResult,\n ListPartsResult,\n UploadPartResult,\n} from './multipart-provider.interface'\nimport type { StreamingBlobPayloadInputTypes } from './storage-provider.interface'\n\nconst MIN_PART_SIZE = 5 * 1024 * 1024 // 5MB\nconst MULTIPART_PREFIX = '__multipart/'\nconst PARTS_PREFIX = '__parts/'\n\n/**\n * R2 Storage Provider\n * Implements storage operations using native Cloudflare R2 bindings\n *\n * Implements IMultipartProvider for multipart upload support needed by TUS.\n * Tracks multipart upload metadata using companion R2 objects so that\n * listParts/listMultipartUploads work in all environments (local, test, prod).\n */\nexport class R2StorageProvider implements IMultipartProvider {\n private readonly routeBasePath: string\n\n constructor(\n private readonly config: StorageEntry,\n private readonly bucket: R2Bucket,\n private readonly env: StratalEnv,\n routeConfig?: StorageRouteConfig\n ) {\n this.routeBasePath = routeConfig?.basePath ?? '/storage'\n }\n\n async upload(\n body: StreamingBlobPayloadInputTypes,\n path: string,\n options: UploadOptions\n ): Promise<UploadResult> {\n const customMetadata: Record<string, string> = { ...options.metadata }\n if (options.tagging) {\n customMetadata['x-tags'] = options.tagging\n }\n\n await this.bucket.put(path, body as ReadableStream | ArrayBuffer | ArrayBufferView | string | Blob | null, {\n httpMetadata: {\n contentType: options.mimeType,\n },\n customMetadata,\n })\n\n return {\n path,\n disk: this.config.disk,\n fullPath: path,\n size: options.size,\n mimeType: options.mimeType ?? 'application/octet-stream',\n uploadedAt: new Date(),\n }\n }\n\n async download(path: string): Promise<DownloadResult> {\n const obj = await this.bucket.get(path)\n\n if (!obj) {\n throw new StorageError(`Storage object not found at path \"${path}\"`)\n }\n\n // R2ObjectBody has body, text(), arrayBuffer(), etc.\n const objBody = obj\n\n return {\n toStream: () => objBody.body as ReadableStream<Uint8Array>,\n contentType: obj.httpMetadata?.contentType ?? 'application/octet-stream',\n size: obj.size,\n metadata: obj.customMetadata,\n toString: () => objBody.text(),\n toArrayBuffer: () => objBody.bytes(),\n }\n }\n\n async delete(path: string): Promise<void> {\n await this.bucket.delete(path)\n }\n\n async exists(path: string): Promise<boolean> {\n const head = await this.bucket.head(path)\n return head !== null\n }\n\n async getPresignedUrl(\n path: string,\n method: 'GET' | 'PUT' | 'DELETE' | 'HEAD',\n expiresIn: number\n ): Promise<PresignedUrlResult> {\n const secret = this.env.APP_SECRET;\n if (!secret) {\n throw new StorageError('APP_SECRET is required for generating presigned URLs')\n }\n\n // Build a relative URL pointing to the StorageController route\n const routePath = `${this.routeBasePath}/${this.config.disk}/${path}`\n const urlWithMethod = `${routePath}?method=${method}`\n const url = await signUrl(urlWithMethod, secret, { expiresIn })\n\n return {\n url,\n expiresIn,\n expiresAt: new Date(Date.now() + expiresIn * 1000),\n method,\n }\n }\n\n async chunkedUpload(\n body: StreamingBlobPayloadInputTypes,\n path: string,\n options: Omit<UploadOptions, 'size'> & { size?: number }\n ): Promise<UploadResult> {\n const multipartUpload = await this.bucket.createMultipartUpload(path, {\n httpMetadata: {\n contentType: options.mimeType,\n },\n customMetadata: options.metadata,\n })\n\n const parts: R2UploadedPart[] = []\n\n try {\n if (body instanceof ReadableStream) {\n const reader = (body as ReadableStream<Uint8Array>).getReader()\n let buffer = new Uint8Array(0)\n let partNumber = 1\n\n while (true) {\n const { done, value } = await reader.read()\n\n if (value) {\n const newBuffer = new Uint8Array(buffer.length + value.length)\n newBuffer.set(buffer, 0)\n newBuffer.set(value, buffer.length)\n buffer = newBuffer\n }\n\n while (buffer.length >= MIN_PART_SIZE) {\n const partData = buffer.slice(0, MIN_PART_SIZE)\n buffer = buffer.slice(MIN_PART_SIZE)\n const part = await multipartUpload.uploadPart(partNumber, partData)\n parts.push(part)\n partNumber++\n }\n\n if (done) {\n // Upload remaining buffer as final part\n if (buffer.length > 0) {\n const part = await multipartUpload.uploadPart(partNumber, buffer)\n parts.push(part)\n }\n break\n }\n }\n } else if (body !== null && body !== undefined) {\n // Non-stream body: upload as single part\n const part = await multipartUpload.uploadPart(1, body as ArrayBuffer | ArrayBufferView | string | Blob)\n parts.push(part)\n }\n\n await multipartUpload.complete(parts)\n } catch (error) {\n await multipartUpload.abort()\n throw error\n }\n\n // Get actual size via head\n const headResult = await this.bucket.head(path)\n\n return {\n path,\n disk: this.config.disk,\n fullPath: path,\n size: headResult?.size ?? options.size ?? 0,\n mimeType: options.mimeType ?? 'application/octet-stream',\n uploadedAt: new Date(),\n }\n }\n\n // ============================================\n // IMultipartProvider - Multipart upload methods\n // ============================================\n\n getBucket(): string {\n return this.config.binding\n }\n\n async headObject(key: string): Promise<HeadObjectResult | null> {\n const obj = await this.bucket.head(key)\n if (!obj) {\n return null\n }\n return {\n size: obj.size,\n contentType: obj.httpMetadata?.contentType,\n metadata: obj.customMetadata,\n }\n }\n\n async deleteObjects(keys: string[]): Promise<DeleteObjectsResult> {\n if (keys.length === 0) {\n return { deleted: 0, errors: [] }\n }\n\n await this.bucket.delete(keys)\n\n return {\n deleted: keys.length,\n errors: [],\n }\n }\n\n async createMultipartUpload(\n key: string,\n options?: CreateMultipartOptions\n ): Promise<CreateMultipartResult> {\n const upload = await this.bucket.createMultipartUpload(key, {\n httpMetadata: {\n contentType: options?.contentType,\n cacheControl: options?.cacheControl,\n },\n customMetadata: options?.metadata,\n })\n\n // Track upload for listMultipartUploads\n await this.bucket.put(\n `${MULTIPART_PREFIX}${upload.uploadId}.json`,\n JSON.stringify({ key: upload.key, uploadId: upload.uploadId, initiated: new Date().toISOString() }),\n { httpMetadata: { contentType: 'application/json' } }\n )\n\n return {\n uploadId: upload.uploadId,\n key: upload.key,\n }\n }\n\n async uploadPart(\n key: string,\n uploadId: string,\n partNumber: number,\n body: Uint8Array\n ): Promise<UploadPartResult> {\n const upload = this.bucket.resumeMultipartUpload(key, uploadId)\n const part = await upload.uploadPart(partNumber, body)\n\n // Track part for listParts\n await this.bucket.put(\n `${PARTS_PREFIX}${uploadId}/${partNumber}`,\n JSON.stringify({ partNumber: part.partNumber, etag: part.etag, size: body.length }),\n { httpMetadata: { contentType: 'application/json' } }\n )\n\n return {\n etag: part.etag,\n partNumber: part.partNumber,\n }\n }\n\n async completeMultipartUpload(\n key: string,\n uploadId: string,\n parts: CompletedPart[]\n ): Promise<CompleteMultipartResult> {\n const upload = this.bucket.resumeMultipartUpload(key, uploadId)\n const result = await upload.complete(\n parts.map((p) => ({\n partNumber: p.partNumber,\n etag: p.etag,\n }))\n )\n\n await this.cleanupTrackingObjects(uploadId)\n\n return {\n key: result.key,\n }\n }\n\n async abortMultipartUpload(key: string, uploadId: string): Promise<void> {\n const upload = this.bucket.resumeMultipartUpload(key, uploadId)\n await upload.abort()\n\n await this.cleanupTrackingObjects(uploadId)\n }\n\n async listParts(\n _key: string,\n uploadId: string,\n partNumberMarker?: string\n ): Promise<ListPartsResult> {\n const prefix = `${PARTS_PREFIX}${uploadId}/`\n const listed = await this.bucket.list({\n prefix,\n cursor: partNumberMarker,\n })\n\n const parts = await Promise.all(\n listed.objects.map(async (obj) => {\n const data = await this.bucket.get(obj.key)\n if (!data) {\n return null\n }\n return JSON.parse(await data.text()) as { partNumber: number; etag: string; size: number }\n })\n )\n\n const validParts = parts\n .filter((p): p is NonNullable<typeof p> => p !== null)\n .sort((a, b) => a.partNumber - b.partNumber)\n\n return {\n parts: validParts,\n isTruncated: listed.truncated,\n nextPartNumberMarker: listed.truncated ? listed.cursor : undefined,\n }\n }\n\n async listMultipartUploads(\n keyMarker?: string,\n _uploadIdMarker?: string\n ): Promise<ListMultipartUploadsResult> {\n const listed = await this.bucket.list({\n prefix: MULTIPART_PREFIX,\n cursor: keyMarker,\n })\n\n const uploads = await Promise.all(\n listed.objects.map(async (obj) => {\n const data = await this.bucket.get(obj.key)\n if (!data) {\n return null\n }\n const parsed = JSON.parse(await data.text()) as { key: string; uploadId: string; initiated: string }\n return {\n key: parsed.key,\n uploadId: parsed.uploadId,\n initiated: new Date(parsed.initiated),\n }\n })\n )\n\n return {\n uploads: uploads.filter((u): u is NonNullable<typeof u> => u !== null),\n isTruncated: listed.truncated,\n nextKeyMarker: listed.truncated ? listed.cursor : undefined,\n nextUploadIdMarker: undefined,\n }\n }\n\n // ============================================\n // Private helpers\n // ============================================\n\n private async cleanupTrackingObjects(uploadId: string): Promise<void> {\n // Delete part tracking objects\n const partsPrefix = `${PARTS_PREFIX}${uploadId}/`\n let cursor: string | undefined\n const keysToDelete: string[] = []\n\n do {\n const listed = await this.bucket.list({ prefix: partsPrefix, cursor })\n for (const obj of listed.objects) {\n keysToDelete.push(obj.key)\n }\n cursor = listed.truncated ? listed.cursor : undefined\n } while (cursor)\n\n // Delete multipart tracking object\n keysToDelete.push(`${MULTIPART_PREFIX}${uploadId}.json`)\n\n if (keysToDelete.length > 0) {\n await this.bucket.delete(keysToDelete)\n }\n }\n}\n"],"mappings":";;;;;AAmBA,MAAM,gBAAgB,IAAI,OAAO;AACjC,MAAM,mBAAmB;AACzB,MAAM,eAAe;;;;;;;;;AAUrB,IAAa,oBAAb,MAA6D;CAIxC;CACA;CACA;CALnB;CAEA,YACE,QACA,QACA,KACA,aACA;EAJiB,KAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,MAAA;EAGjB,KAAK,gBAAgB,aAAa,YAAY;CAChD;CAEA,MAAM,OACJ,MACA,MACA,SACuB;EACvB,MAAM,iBAAyC,EAAE,GAAG,QAAQ,SAAS;EACrE,IAAI,QAAQ,SACV,eAAe,YAAY,QAAQ;EAGrC,MAAM,KAAK,OAAO,IAAI,MAAM,MAA+E;GACzG,cAAc,EACZ,aAAa,QAAQ,SACvB;GACA;EACF,CAAC;EAED,OAAO;GACL;GACA,MAAM,KAAK,OAAO;GAClB,UAAU;GACV,MAAM,QAAQ;GACd,UAAU,QAAQ,YAAY;GAC9B,4BAAY,IAAI,KAAK;EACvB;CACF;CAEA,MAAM,SAAS,MAAuC;EACpD,MAAM,MAAM,MAAM,KAAK,OAAO,IAAI,IAAI;EAEtC,IAAI,CAAC,KACH,MAAM,IAAI,aAAa,qCAAqC,KAAK,EAAE;EAIrE,MAAM,UAAU;EAEhB,OAAO;GACL,gBAAgB,QAAQ;GACxB,aAAa,IAAI,cAAc,eAAe;GAC9C,MAAM,IAAI;GACV,UAAU,IAAI;GACd,gBAAgB,QAAQ,KAAK;GAC7B,qBAAqB,QAAQ,MAAM;EACrC;CACF;CAEA,MAAM,OAAO,MAA6B;EACxC,M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prcID.mjs";
|
|
2
|
-
import { u as ROUTE_METADATA_KEYS } from "./exception-context-
|
|
2
|
+
import { u as ROUTE_METADATA_KEYS } from "./exception-context-Bd5Hk2c_.mjs";
|
|
3
3
|
//#region src/rate-limiter/decorators/rate-limit.decorator.ts
|
|
4
4
|
const KEY = ROUTE_METADATA_KEYS.RATE_LIMIT;
|
|
5
5
|
/**
|
|
@@ -47,4 +47,4 @@ function getRateLimits(target, propertyKey) {
|
|
|
47
47
|
//#endregion
|
|
48
48
|
export { getRateLimits as n, RateLimit as t };
|
|
49
49
|
|
|
50
|
-
//# sourceMappingURL=rate-limit.decorator-
|
|
50
|
+
//# sourceMappingURL=rate-limit.decorator-B35jBEVD.mjs.map
|
package/dist/{rate-limit.decorator-BPAie_p3.mjs.map → rate-limit.decorator-B35jBEVD.mjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit.decorator-
|
|
1
|
+
{"version":3,"file":"rate-limit.decorator-B35jBEVD.mjs","names":[],"sources":["../src/rate-limiter/decorators/rate-limit.decorator.ts"],"sourcesContent":["import { defineMetadata, getMetadata } from '../../di/metadata'\nimport { ROUTE_METADATA_KEYS } from '../../router/constants'\n\nconst KEY = ROUTE_METADATA_KEYS.RATE_LIMIT\n\n/**\n * Apply a named rate limiter to a controller class or a single route method.\n *\n * Stacks: multiple `@RateLimit` decorators on the same target push onto\n * the metadata array — every named limiter is enforced. Class-level limits\n * run before method-level limits in the resulting middleware chain.\n *\n * The named limiter must be registered separately via\n * `RateLimiterRegistry.for('name', resolver)` (typically inside a\n * module's `onInitialize` hook) and the user must import\n * `RateLimiterModule.forRoot({ store: ... })` in their AppModule.\n *\n * @example\n * ```typescript\n * @Controller('/api/v1/users')\n * @RateLimit('api')\n * export class UsersController {\n * @Get('/')\n * list(ctx: RouterContext) { ... }\n *\n * @Post('/')\n * @RateLimit('writes') // stacks with class-level 'api'\n * create(ctx: RouterContext) { ... }\n * }\n * ```\n */\nexport function RateLimit(name: string): ClassDecorator & MethodDecorator {\n return (target: object, propertyKey?: string | symbol) => {\n if (propertyKey === undefined) {\n const existing = getMetadata<string[]>(KEY, target) ?? []\n defineMetadata(KEY, [...existing, name], target)\n } else {\n const existing = getMetadata<string[]>(KEY, target, propertyKey as string) ?? []\n defineMetadata(KEY, [...existing, name], target, propertyKey as string)\n }\n }\n}\n\n/**\n * Read the rate-limit names attached to a class or method via `@RateLimit`.\n * Returns an empty array when no decorator was applied.\n *\n * @param target - For class metadata, pass the controller constructor.\n * For method metadata, pass `Controller.prototype` and the method name.\n */\nexport function getRateLimits(target: object, propertyKey?: string): string[] {\n const meta = propertyKey === undefined\n ? getMetadata<string[]>(KEY, target)\n : getMetadata<string[]>(KEY, target, propertyKey)\n return meta ?? []\n}\n"],"mappings":";;;AAGA,MAAM,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BhC,SAAgB,UAAU,MAAgD;CACxE,QAAQ,QAAgB,gBAAkC;EACxD,IAAI,gBAAgB,KAAA,GAElB,eAAe,KAAK,CAAC,GADJ,YAAsB,KAAK,MAAM,KAAK,CAAC,GACtB,IAAI,GAAG,MAAM;OAG/C,eAAe,KAAK,CAAC,GADJ,YAAsB,KAAK,QAAQ,WAAqB,KAAK,CAAC,GAC7C,IAAI,GAAG,QAAQ,WAAqB;CAE1E;AACF;;;;;;;;AASA,SAAgB,cAAc,QAAgB,aAAgC;CAI5E,QAHa,gBAAgB,KAAA,IACzB,YAAsB,KAAK,MAAM,IACjC,YAAsB,KAAK,QAAQ,WAAW,MACnC,CAAC;AAClB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dn as AsyncModuleOptions, Dr as ApplicationError, Fn as OnException, In as OnInitialize, Nn as ModuleContext, Y as Container, _n as Middleware, c as HttpException, d as ExceptionHandler, kn as DynamicModule, rt as RouterContext, vn as Next } from "../index-
|
|
1
|
+
import { Dn as AsyncModuleOptions, Dr as ApplicationError, Fn as OnException, In as OnInitialize, Nn as ModuleContext, Y as Container, _n as Middleware, c as HttpException, d as ExceptionHandler, kn as DynamicModule, rt as RouterContext, vn as Next } from "../index-C_t8VVQD.mjs";
|
|
2
2
|
import { t as Macroable } from "../index-0ItCjaqw.mjs";
|
|
3
3
|
import { t as StratalEnv } from "../env-ug22bJj7.mjs";
|
|
4
4
|
import { t as Constructor } from "../types-CmV_9xBD.mjs";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { d as inject, n as CONTAINER_TOKEN, r as DI_TOKENS, s as Singleton } from "../di-
|
|
1
|
+
import { d as inject, n as CONTAINER_TOKEN, r as DI_TOKENS, s as Singleton } from "../di-B0NXIdRF.mjs";
|
|
2
2
|
import { n as __decorateParam, t as __decorate } from "../decorate-CuAoSZvs.mjs";
|
|
3
3
|
import { t as Macroable } from "../macroable-cvDTFZ_A.mjs";
|
|
4
4
|
import { n as Module } from "../module.decorator-CYHY6pG5.mjs";
|
|
5
|
-
import { c as RATE_LIMITER_TOKENS, l as RateLimiterError, s as createThrottleMiddleware, u as TooManyRequestsError } from "../module-registry-
|
|
5
|
+
import { c as RATE_LIMITER_TOKENS, l as RateLimiterError, s as createThrottleMiddleware, u as TooManyRequestsError } from "../module-registry-MfWmniZ7.mjs";
|
|
6
6
|
import "../module/index.mjs";
|
|
7
7
|
import { CACHE_TOKENS, CacheModule } from "../cache/index.mjs";
|
|
8
|
-
import { n as getRateLimits, t as RateLimit } from "../rate-limit.decorator-
|
|
8
|
+
import { n as getRateLimits, t as RateLimit } from "../rate-limit.decorator-B35jBEVD.mjs";
|
|
9
9
|
//#region src/rate-limiter/limit.ts
|
|
10
10
|
/**
|
|
11
11
|
* A single rate limit window.
|
package/dist/{route-registration.service-D6vSwiKP.mjs → route-registration.service-HN8WgIis.mjs}
RENAMED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-BBjsoOtd.mjs";
|
|
2
|
-
import { d as inject, m as getMethodInjections, r as DI_TOKENS, s as Singleton, v as ROUTER_TOKENS } from "./di-
|
|
2
|
+
import { d as inject, m as getMethodInjections, r as DI_TOKENS, s as Singleton, v as ROUTER_TOKENS } from "./di-B0NXIdRF.mjs";
|
|
3
3
|
import { n as getMetadata, t as defineMetadata } from "./metadata-DzzprcID.mjs";
|
|
4
4
|
import { n as __decorateParam, t as __decorate } from "./decorate-CuAoSZvs.mjs";
|
|
5
5
|
import { LOGGER_TOKENS } from "./logger/index.mjs";
|
|
6
|
-
import { d as abort, u as HttpException } from "./errors-
|
|
7
|
-
import { a as RouterContext, c as METHOD_STATUS_CODES, d as SECURITY_SCHEMES, l as ROUTER_CONTEXT_KEYS, o as DEFAULT_CONTENT_TYPE, s as HTTP_METHODS, u as ROUTE_METADATA_KEYS } from "./exception-context-
|
|
8
|
-
import { o as RouterError, s as createThrottleMiddleware } from "./module-registry-
|
|
6
|
+
import { d as abort, u as HttpException } from "./errors-EUtwVfNm.mjs";
|
|
7
|
+
import { a as RouterContext, c as METHOD_STATUS_CODES, d as SECURITY_SCHEMES, l as ROUTER_CONTEXT_KEYS, o as DEFAULT_CONTENT_TYPE, s as HTTP_METHODS, u as ROUTE_METADATA_KEYS } from "./exception-context-Bd5Hk2c_.mjs";
|
|
8
|
+
import { o as RouterError, s as createThrottleMiddleware } from "./module-registry-MfWmniZ7.mjs";
|
|
9
9
|
import { i as zod_exports, r as z } from "./zod-eKqqhZ5_.mjs";
|
|
10
|
-
import { n as getControllerOptions, r as getControllerRoute } from "./controller.decorator-
|
|
11
|
-
import "./http-method.decorator-
|
|
10
|
+
import { n as getControllerOptions, r as getControllerRoute } from "./controller.decorator-DKeZ71aP.mjs";
|
|
11
|
+
import "./http-method.decorator-xCuGoZPC.mjs";
|
|
12
12
|
import { i as getMethodGuards, r as getControllerGuards, t as GuardExecutionService } from "./guards-DALPXy3_.mjs";
|
|
13
|
-
import { n as getRateLimits } from "./rate-limit.decorator-
|
|
14
|
-
import { a as getWsOnCloseMethod, o as getWsOnErrorMethod, s as getWsOnMessageMethod, t as GatewayContext, u as isGateway } from "./gateway-context-
|
|
13
|
+
import { n as getRateLimits } from "./rate-limit.decorator-B35jBEVD.mjs";
|
|
14
|
+
import { a as getWsOnCloseMethod, o as getWsOnErrorMethod, s as getWsOnMessageMethod, t as GatewayContext, u as isGateway } from "./gateway-context-I0tKgGfh.mjs";
|
|
15
15
|
import { o as toOpenAPIPath, r as generateConventionRouteName, s as toRoutingOpenAPIPath } from "./route-name-DGoBOfPg.mjs";
|
|
16
16
|
//#region src/router/errors/route-not-found.error.ts
|
|
17
17
|
var RouteNotFoundError = class extends HttpException {
|
|
@@ -915,4 +915,4 @@ RouteRegistrationService = __decorate([
|
|
|
915
915
|
//#endregion
|
|
916
916
|
export { ResponseValidationError as _, paginatedResponseSchema as a, uuidParamSchema as c, getRouteDecoratedMethods as d, getRouteMetadata as f, InvalidSignatureError as g, parseDomainPattern as h, errorResponseSchema as i, validationErrorResponseSchema as l, createDomainMiddleware as m, route_registration_service_exports as n, paginationQuerySchema as o, createMiddlewareChain as p, commonErrorSchemas as r, successMessageSchema as s, RouteRegistrationService as t, Route as u, SchemaValidationError as v, RouteNotFoundError as y };
|
|
917
917
|
|
|
918
|
-
//# sourceMappingURL=route-registration.service-
|
|
918
|
+
//# sourceMappingURL=route-registration.service-HN8WgIis.mjs.map
|