@geekmidas/constructs 9.4.0 → 9.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/{AWSScheduledFunction-DgQuL5kt.d.mts → AWSScheduledFunction--49dTSUQ.d.mts} +3 -3
  3. package/dist/{AWSScheduledFunction-DgQuL5kt.d.mts.map → AWSScheduledFunction--49dTSUQ.d.mts.map} +1 -1
  4. package/dist/{AWSScheduledFunction-DoDZR8E6.d.cts → AWSScheduledFunction-D0_HIJj8.d.cts} +2 -2
  5. package/dist/{AWSScheduledFunction-DoDZR8E6.d.cts.map → AWSScheduledFunction-D0_HIJj8.d.cts.map} +1 -1
  6. package/dist/{Construct-CgluLUuF.d.mts → Construct-qnOnQTcP.d.mts} +1 -1
  7. package/dist/{Construct-CgluLUuF.d.mts.map → Construct-qnOnQTcP.d.mts.map} +1 -1
  8. package/dist/{Endpoint-1u_i-nCT.d.cts → Endpoint-DIQblT3d.d.cts} +2 -2
  9. package/dist/Endpoint-DIQblT3d.d.cts.map +1 -0
  10. package/dist/{Endpoint-CypDvYJW.d.mts → Endpoint-ZtG0zVz1.d.mts} +4 -4
  11. package/dist/Endpoint-ZtG0zVz1.d.mts.map +1 -0
  12. package/dist/{HonoEndpointAdaptor-D_2UDPNs.cjs → HonoEndpointAdaptor-1aMXc8F3.cjs} +1 -1
  13. package/dist/{HonoEndpointAdaptor-D_2UDPNs.cjs.map → HonoEndpointAdaptor-1aMXc8F3.cjs.map} +1 -1
  14. package/dist/{HonoEndpointAdaptor-C-mPVfwk.mjs → HonoEndpointAdaptor-BcVAeMLW.mjs} +1 -1
  15. package/dist/{HonoEndpointAdaptor-C-mPVfwk.mjs.map → HonoEndpointAdaptor-BcVAeMLW.mjs.map} +1 -1
  16. package/dist/Queue-915lgS2D.mjs +62 -0
  17. package/dist/Queue-915lgS2D.mjs.map +1 -0
  18. package/dist/Queue-HbdYCQ-X.cjs +73 -0
  19. package/dist/Queue-HbdYCQ-X.cjs.map +1 -0
  20. package/dist/{Queue-Dhl8bc45.d.mts → Queue-I5NfFV0V.d.mts} +29 -4
  21. package/dist/{Queue-Bl87Atny.d.cts.map → Queue-I5NfFV0V.d.mts.map} +1 -1
  22. package/dist/{Queue-Bl87Atny.d.cts → Queue-XQNGO6_-.d.cts} +28 -3
  23. package/dist/{Queue-Dhl8bc45.d.mts.map → Queue-XQNGO6_-.d.cts.map} +1 -1
  24. package/dist/{Subscriber-panMf5vp.d.mts → Subscriber-Bjil86Ub.d.mts} +2 -2
  25. package/dist/{Subscriber-panMf5vp.d.mts.map → Subscriber-Bjil86Ub.d.mts.map} +1 -1
  26. package/dist/{Topic-DGtlTlu5.d.mts → Topic-D8-wkoh4.d.mts} +2 -2
  27. package/dist/{Topic-DGtlTlu5.d.mts.map → Topic-D8-wkoh4.d.mts.map} +1 -1
  28. package/dist/adaptors/aws.cjs +20 -8
  29. package/dist/adaptors/aws.cjs.map +1 -1
  30. package/dist/adaptors/aws.d.cts +8 -7
  31. package/dist/adaptors/aws.d.cts.map +1 -1
  32. package/dist/adaptors/aws.d.mts +12 -11
  33. package/dist/adaptors/aws.d.mts.map +1 -1
  34. package/dist/adaptors/aws.mjs +20 -8
  35. package/dist/adaptors/aws.mjs.map +1 -1
  36. package/dist/adaptors/hono.cjs +1 -1
  37. package/dist/adaptors/hono.d.cts +2 -2
  38. package/dist/adaptors/hono.d.mts +5 -5
  39. package/dist/adaptors/hono.mjs +1 -1
  40. package/dist/adaptors/testing.cjs +11 -3
  41. package/dist/adaptors/testing.cjs.map +1 -1
  42. package/dist/adaptors/testing.d.cts +10 -4
  43. package/dist/adaptors/testing.d.cts.map +1 -1
  44. package/dist/adaptors/testing.d.mts +14 -8
  45. package/dist/adaptors/testing.d.mts.map +1 -1
  46. package/dist/adaptors/testing.mjs +11 -3
  47. package/dist/adaptors/testing.mjs.map +1 -1
  48. package/dist/crons/index.d.cts +6 -6
  49. package/dist/crons/index.d.mts +3 -3
  50. package/dist/endpoints/index.d.cts +4 -4
  51. package/dist/endpoints/index.d.mts +5 -5
  52. package/dist/functions/index.d.cts +1 -1
  53. package/dist/functions/index.d.mts +2 -2
  54. package/dist/{index-BUNi5ldW.d.mts → index-CbhtERFB.d.mts} +2 -2
  55. package/dist/{index-BUNi5ldW.d.mts.map → index-CbhtERFB.d.mts.map} +1 -1
  56. package/dist/{index-zeG5G432.d.cts → index-XJKTxGx7.d.cts} +5 -5
  57. package/dist/{index-zeG5G432.d.cts.map → index-XJKTxGx7.d.cts.map} +1 -1
  58. package/dist/index.d.mts +3 -3
  59. package/dist/monitors/index.d.mts +1 -1
  60. package/dist/queue/index.cjs +4 -55
  61. package/dist/queue/index.cjs.map +1 -1
  62. package/dist/queue/index.d.cts +2 -2
  63. package/dist/queue/index.d.cts.map +1 -1
  64. package/dist/queue/index.d.mts +3 -3
  65. package/dist/queue/index.d.mts.map +1 -1
  66. package/dist/queue/index.mjs +4 -56
  67. package/dist/queue/index.mjs.map +1 -1
  68. package/dist/subscribers/index.d.cts +2 -2
  69. package/dist/subscribers/index.d.cts.map +1 -1
  70. package/dist/subscribers/index.d.mts +3 -3
  71. package/dist/{telemetry-Bp4DLvdQ.d.mts → telemetry-vq7C0ZBy.d.mts} +1 -1
  72. package/dist/{telemetry-Bp4DLvdQ.d.mts.map → telemetry-vq7C0ZBy.d.mts.map} +1 -1
  73. package/dist/topic/index.d.mts +2 -2
  74. package/dist/{types-j0ti0JTY.d.mts → types-X37z95fN.d.mts} +1 -1
  75. package/dist/{types-j0ti0JTY.d.mts.map → types-X37z95fN.d.mts.map} +1 -1
  76. package/dist/types.d.mts +1 -1
  77. package/package.json +22 -22
  78. package/src/queue/AWSLambdaQueueAdaptor.ts +33 -8
  79. package/src/queue/Queue.ts +35 -1
  80. package/src/queue/TestQueueAdaptor.ts +18 -4
  81. package/src/queue/__tests__/AWSLambdaQueueAdaptor.spec.ts +131 -0
  82. package/src/queue/__tests__/TestQueueAdaptor.spec.ts +58 -0
  83. package/src/queue/index.ts +3 -0
  84. package/dist/Endpoint-1u_i-nCT.d.cts.map +0 -1
  85. package/dist/Endpoint-CypDvYJW.d.mts.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import "../Construct-BEh2DSMe.cjs";
2
- import { Queue, QueueContext, QueueHandler, QueueMessage } from "../Queue-Bl87Atny.cjs";
2
+ import { Queue, QueueContext, QueueHandler, QueueMessage, QueueRecord, QueueResult, isQueueResult } from "../Queue-XQNGO6_-.cjs";
3
3
  import * as _geekmidas_logger8 from "@geekmidas/logger";
4
4
  import { Logger } from "@geekmidas/logger";
5
5
  import { Service } from "@geekmidas/services";
@@ -41,5 +41,5 @@ declare const q: QueueBuilder<string, undefined, [], _geekmidas_logger8.Logger>;
41
41
  //# sourceMappingURL=index.d.ts.map
42
42
 
43
43
  //#endregion
44
- export { Queue, QueueBuilder, QueueContext, QueueHandler, QueueMessage, q };
44
+ export { Queue, QueueBuilder, QueueContext, QueueHandler, QueueMessage, QueueRecord, QueueResult, isQueueResult, q };
45
45
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/queue/QueueBuilder.ts","../../src/queue/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AAaA;;AAEkB,cAFL,YAEK,CAAA,cAAA,MAAA,GAAA,MAAA,EAAA,iBAAA,gBAAA,GAAA,SAAA,GAAA,SAAA,EAAA,kBACC,OADD,EAAA,GAAA,EAAA,EAAA,gBAED,MAFC,GAEQ,MAFR,CAAA,CAAA;EAAgB,QACf,KAAA;EAAO,QACT,cAAA;EAAM,QAAG,QAAA;EAAM,QAYxB,UAAA;EAAC,QACQ,KAAA;EAAC,QAAE,SAAA;EAAQ,QAAE,OAAA;EAAS;EAAS,KAA5C,CAAA,UAAA,MAAA,CAAA,CAAA,IAAA,EADI,CACJ,CAAA,EAAA,YAAA,CAAa,CAAb,EAAgB,QAAhB,EA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ct-CgluLUuF.mjs";
2
- import { Queue, QueueContext, QueueHandler, QueueMessage } from "../Queue-Dhl8bc45.mjs";
1
+ import "../Construct-qnOnQTcP.mjs";
2
+ import { Queue, QueueContext, QueueHandler, QueueMessage, QueueRecord, QueueResult, isQueueResult } from "../Queue-I5NfFV0V.mjs";
3
3
  import { Service } from "@geekmidas/services";
4
4
  import { Logger as Logger$1 } from "@geekmidas/logger";
5
5
  import { StandardSchemaV1 } from "@standard-schema/spec";
@@ -40,5 +40,5 @@ declare const q: QueueBuilder<string, undefined, [], Logger>;
40
40
  //# sourceMappingURL=index.d.ts.map
41
41
 
42
42
  //#endregion
43
- export { Queue, QueueBuilder, QueueContext, QueueHandler, QueueMessage, q };
43
+ export { Queue, QueueBuilder, QueueContext, QueueHandler, QueueMessage, QueueRecord, QueueResult, isQueueResult, q };
44
44
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/queue/QueueBuilder.ts","../../src/queue/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAaA;;;AAGmB,cAHN,YAGM,CAAA,cAAA,MAAA,GAAA,MAAA,EAAA,iBADD,gBACC,GAAA,SAAA,GAAA,SAAA,EAAA,kBAAA,OAAA,EAAA,GAAA,EAAA,EAAA,gBACF,QADE,GACO,QADP,CAAA,CAAA;EAAO,QACT,KAAA;EAAM,QAAG,cAAA;EAAM,QAYxB,QAAA;EAAC,QACQ,UAAA;EAAC,QAAE,KAAA;EAAQ,QAAE,SAAA;EAAS,QAAE,OAAA;EAAO;EAAhC,KAuBI,CAAA,UAAA,MAAA,CAAA,CAAA,IAAA,EAxBZ,CAwBY,CAAA,EAvBhB,YAuBgB,CAvBH,CAuBG,EAvBA,QAuBA,EAvBU,SAuBV,EAvBqB,OAuBrB,CAAA;EAAO,OACf,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAC;EACS,SAAE,CAAA,SAAA,EAAA,MAAA,CAAA,E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AAA,MAAA,CAAA,CAAA,IAAA,EAxBZ,CAwBY,CAAA,EAvBhB,YAuBgB,CAvBH,CAuBG,EAvBA,QAuBA,EAvBU,SAuBV,EAvBqB,OAuBrB,CAAA;EAAO,OACf,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAC;EACS,SAAE,CAAA,SAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAAQ;EAAe,IAAK,CAAA,IAAA,CAAA,EAAA,OAAA,CAAA,EAAA,IAAA;EAAC,QAAG,CAAA,UAFpC,OAEoC,EAAA,CAAA,CAAA,QAAA,EAD5C,CAC4C,CAAA,EAApD,YAAoD,CAAvC,KAAuC,EAAhC,QAAgC,EAAA,CAAA,GAAlB,SAAkB,EAAA,GAAJ,CAAI,CAAA,EAAA,OAAA,CAAA;EAAO,MAA3D,CAAA,UAWc,QAXd,CAAA,CAAA,MAAA,EAYM,CAZN,CAAA,EAaA,YAbA,CAaa,KAbb,EAaoB,QAbpB,EAa8B,SAb9B,EAayC,CAbzC,CAAA;EAAY;EAWQ,OACd,CAAA,UAQS,gBART,CAAA,CAAA,MAAA,EASA,CATA,CAAA,EAUN,YAVM,CAUO,KAVP,EAUc,CAVd,EAUiB,SAVjB,EAU4B,OAV5B,CAAA;EAAC,MACM,CAAA,EAAA,EAgBX,YAhBW,CAgBE,WAhBF,CAgBc,QAhBd,CAAA,EAgByB,SAhBzB,EAgBoC,OAhBpC,CAAA,CAAA,EAiBb,KAjBa,CAiBP,KAjBO,EAiBA,WAjBA,CAiBY,QAjBZ,CAAA,EAiBuB,SAjBvB,EAiBkC,OAjBlC,CAAA;;;;;cCtDJ,GAAC,oCAAA"}
@@ -1,60 +1,8 @@
1
- import { Construct, ConstructType } from "../Construct-D5LZBFhb.mjs";
1
+ import "../Construct-D5LZBFhb.mjs";
2
2
  import { cloneWith } from "../clone-BWIwx6vL.mjs";
3
- import { ConsoleLogger, DEFAULT_LOGGER } from "@geekmidas/logger/console";
4
- import { environmentCase } from "@geekmidas/envkit";
5
- import { Publisher } from "@geekmidas/events";
3
+ import { Queue, isQueueResult } from "../Queue-915lgS2D.mjs";
4
+ import { DEFAULT_LOGGER } from "@geekmidas/logger/console";
6
5
 
7
- //#region src/queue/Queue.ts
8
- const DEFAULT_LOGGER$1 = new ConsoleLogger();
9
- /**
10
- * A queue worker — a point-to-point SQS-style queue and its single consumer.
11
- * Unlike a `Subscriber` (topic fan-out, filtered by `subscribedEvents`), a queue
12
- * drains every message of its one `message` type. Build one with `q` (see
13
- * `QueueBuilder`); `gkm build` discovers it into the manifest's `queues` field.
14
- *
15
- * The producer side is {@link Queue.publisher} — a ready-to-inject `Service`
16
- * that any endpoint/function drops into `.services([...])` to send messages.
17
- */
18
- var Queue = class extends Construct {
19
- __IS_QUEUE__ = true;
20
- static isQueue(obj) {
21
- return Boolean(obj && obj.__IS_QUEUE__ === true && obj.type === ConstructType.Queue);
22
- }
23
- constructor(name, handler, messageSchema, timeout = 3e4, services = [], logger = DEFAULT_LOGGER$1, batchSize, fifo) {
24
- super(ConstructType.Queue, logger, services, [], void 0, void 0, timeout);
25
- this.name = name;
26
- this.handler = handler;
27
- this.messageSchema = messageSchema;
28
- this.timeout = timeout;
29
- this.services = services;
30
- this.logger = logger;
31
- this.batchSize = batchSize;
32
- this.fifo = fifo;
33
- }
34
- /**
35
- * The producer side — a `Service` exposing an `EventPublisher` typed to this
36
- * queue's message. Inject it via `.services([queue.publisher])`; the handler
37
- * then calls `services.<name>Publisher.publish([{ type, payload }])`.
38
- *
39
- * It reads `<NAME>_PUBLISHER_CONNECTION_STRING` and builds the transport from
40
- * the URL protocol — `pgboss://` locally, `sqs://` deployed — so the same
41
- * code publishes to Postgres in dev and SQS in prod. Because it's a `Service`,
42
- * `Construct.getEnvironment()` sniffs it, so the env requirement flows into
43
- * the manifest and infra links exactly this queue with least privilege.
44
- */
45
- get publisher() {
46
- const envVar = `${environmentCase(this.name)}_PUBLISHER_CONNECTION_STRING`;
47
- return {
48
- serviceName: `${this.name}Publisher`,
49
- async register({ envParser }) {
50
- const { connectionString } = envParser.create((get) => ({ connectionString: get(envVar).string() })).parse();
51
- return Publisher.fromConnectionString(connectionString);
52
- }
53
- };
54
- }
55
- };
56
-
57
- //#endregion
58
6
  //#region src/queue/QueueBuilder.ts
59
7
  /**
60
8
  * Builds a {@link Queue} worker — `q.queue('orders').services([db]).message(schema).handle(fn)`.
@@ -108,5 +56,5 @@ var QueueBuilder = class {
108
56
  const q = new QueueBuilder();
109
57
 
110
58
  //#endregion
111
- export { Queue, QueueBuilder, q };
59
+ export { Queue, QueueBuilder, isQueueResult, q };
112
60
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["DEFAULT_LOGGER","obj: unknown","name: TName","handler: QueueHandler<TMessage, TServices, TLogger>","messageSchema: TMessage","timeout: number","services: TServices","logger: TLogger","batchSize?: number","fifo?: boolean","name: T","timeout: number","batchSize: number","services: T","logger: T","schema: T","fn: QueueHandler<NonNullable<TMessage>, TServices, TLogger>"],"sources":["../../src/queue/Queue.ts","../../src/queue/QueueBuilder.ts","../../src/queue/index.ts"],"sourcesContent":["import { environmentCase } from '@geekmidas/envkit';\nimport {\n\ttype EventPublisher,\n\ttype EventPublisherConnectionString,\n\ttype PublishableMessage,\n\tPublisher,\n} from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { ConsoleLogger } from '@geekmidas/logger/console';\nimport type { InferStandardSchema } from '@geekmidas/schema';\nimport type { Service, ServiceRecord } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { Construct, ConstructType } from '../Construct';\n\nconst DEFAULT_LOGGER = new ConsoleLogger() as unknown as Logger;\n\n/**\n * The wire message a queue carries: `{ type: <queue name>, payload: <message> }`.\n * The producer publishes this shape and the worker receives the `payload`s as\n * its `messages`. Typing `type` to the queue name keeps the publisher fully\n * typed and lets pg-boss (local) / SQS (deployed) route by name.\n */\nexport type QueueMessage<\n\tTName extends string,\n\tTMessage extends StandardSchemaV1,\n> = PublishableMessage<TName, InferStandardSchema<TMessage>>;\n\n/**\n * A queue worker — a point-to-point SQS-style queue and its single consumer.\n * Unlike a `Subscriber` (topic fan-out, filtered by `subscribedEvents`), a queue\n * drains every message of its one `message` type. Build one with `q` (see\n * `QueueBuilder`); `gkm build` discovers it into the manifest's `queues` field.\n *\n * The producer side is {@link Queue.publisher} — a ready-to-inject `Service`\n * that any endpoint/function drops into `.services([...])` to send messages.\n */\nexport class Queue<\n\tTName extends string = string,\n\tTMessage extends StandardSchemaV1 = StandardSchemaV1,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n> extends Construct<TLogger, string, undefined, undefined, TServices> {\n\t__IS_QUEUE__ = true;\n\n\tstatic isQueue(\n\t\tobj: unknown,\n\t): obj is Queue<string, StandardSchemaV1, Service[], Logger> {\n\t\treturn Boolean(\n\t\t\tobj &&\n\t\t\t\t(obj as { __IS_QUEUE__?: boolean }).__IS_QUEUE__ === true &&\n\t\t\t\t(obj as Construct).type === ConstructType.Queue,\n\t\t);\n\t}\n\n\tconstructor(\n\t\tpublic readonly name: TName,\n\t\tpublic readonly handler: QueueHandler<TMessage, TServices, TLogger>,\n\t\tpublic readonly messageSchema: TMessage,\n\t\tpublic override readonly timeout: number = 30000,\n\t\tpublic override readonly services: TServices = [] as unknown as TServices,\n\t\tpublic override readonly logger: TLogger = DEFAULT_LOGGER as TLogger,\n\t\t/** SQS event-source batch size (deployed). */\n\t\tpublic readonly batchSize?: number,\n\t\t/** Whether the queue is FIFO (deployed). */\n\t\tpublic readonly fifo?: boolean,\n\t) {\n\t\tsuper(\n\t\t\tConstructType.Queue,\n\t\t\tlogger,\n\t\t\tservices,\n\t\t\t[],\n\t\t\tundefined,\n\t\t\tundefined,\n\t\t\ttimeout,\n\t\t);\n\t}\n\n\t/**\n\t * The producer side — a `Service` exposing an `EventPublisher` typed to this\n\t * queue's message. Inject it via `.services([queue.publisher])`; the handler\n\t * then calls `services.<name>Publisher.publish([{ type, payload }])`.\n\t *\n\t * It reads `<NAME>_PUBLISHER_CONNECTION_STRING` and builds the transport from\n\t * the URL protocol — `pgboss://` locally, `sqs://` deployed — so the same\n\t * code publishes to Postgres in dev and SQS in prod. Because it's a `Service`,\n\t * `Construct.getEnvironment()` sniffs it, so the env requirement flows into\n\t * the manifest and infra links exactly this queue with least privilege.\n\t */\n\tget publisher(): Service<\n\t\t`${TName}Publisher`,\n\t\tEventPublisher<QueueMessage<TName, TMessage>>\n\t> {\n\t\tconst envVar = `${environmentCase(this.name)}_PUBLISHER_CONNECTION_STRING`;\n\t\treturn {\n\t\t\tserviceName: `${this.name}Publisher`,\n\t\t\tasync register({ envParser }) {\n\t\t\t\tconst { connectionString } = envParser\n\t\t\t\t\t.create((get) => ({\n\t\t\t\t\t\tconnectionString: get(envVar).string(),\n\t\t\t\t\t}))\n\t\t\t\t\t.parse();\n\n\t\t\t\treturn Publisher.fromConnectionString<QueueMessage<TName, TMessage>>(\n\t\t\t\t\tconnectionString as EventPublisherConnectionString,\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t}\n}\n\n/** The context a queue handler receives — a batch of typed messages. */\nexport type QueueContext<\n\tTMessage extends StandardSchemaV1,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n> = {\n\tmessages: InferStandardSchema<TMessage>[];\n\tservices: ServiceRecord<TServices>;\n\tlogger: TLogger;\n};\n\nexport type QueueHandler<\n\tTMessage extends StandardSchemaV1,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n> = (\n\tctx: QueueContext<TMessage, TServices, TLogger>,\n) => unknown | Promise<unknown>;\n","import type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { cloneWith } from '../clone';\nimport { Queue, type QueueHandler } from './Queue';\n\n/**\n * Builds a {@link Queue} worker — `q.queue('orders').services([db]).message(schema).handle(fn)`.\n * Services are an array (sniffed for required env vars); `message` is the typed\n * job payload; `handle` is the single consumer. The queue name is captured as a\n * literal so `queue.publisher` is typed to `{ type: '<name>', payload }`.\n */\nexport class QueueBuilder<\n\tTName extends string = string,\n\tTMessage extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n> {\n\tprivate _name?: string;\n\tprivate _messageSchema?: TMessage;\n\tprivate _timeout = 30000;\n\tprivate _batchSize?: number;\n\tprivate _fifo?: boolean;\n\tprivate _services: TServices = [] as Service[] as TServices;\n\tprivate _logger: TLogger = DEFAULT_LOGGER as TLogger;\n\n\t/** The queue name — drives the infra queue and its `<NAME>_*` env vars. */\n\tqueue<T extends string>(\n\t\tname: T,\n\t): QueueBuilder<T, TMessage, TServices, TLogger> {\n\t\treturn cloneWith(this, { _name: name }) as unknown as QueueBuilder<\n\t\t\tT,\n\t\t\tTMessage,\n\t\t\tTServices,\n\t\t\tTLogger\n\t\t>;\n\t}\n\n\ttimeout(timeout: number): this {\n\t\treturn cloneWith(this, { _timeout: timeout });\n\t}\n\n\t/** SQS event-source batch size (deployed). */\n\tbatchSize(batchSize: number): this {\n\t\treturn cloneWith(this, { _batchSize: batchSize });\n\t}\n\n\t/** Mark the queue as FIFO (deployed). */\n\tfifo(fifo = true): this {\n\t\treturn cloneWith(this, { _fifo: fifo });\n\t}\n\n\tservices<T extends Service[]>(\n\t\tservices: T,\n\t): QueueBuilder<TName, TMessage, [...TServices, ...T], TLogger> {\n\t\treturn cloneWith(this, {\n\t\t\t_services: [...this._services, ...services] as unknown as TServices,\n\t\t}) as unknown as QueueBuilder<\n\t\t\tTName,\n\t\t\tTMessage,\n\t\t\t[...TServices, ...T],\n\t\t\tTLogger\n\t\t>;\n\t}\n\n\tlogger<T extends Logger>(\n\t\tlogger: T,\n\t): QueueBuilder<TName, TMessage, TServices, T> {\n\t\treturn cloneWith(this, {\n\t\t\t_logger: logger as unknown as TLogger,\n\t\t}) as unknown as QueueBuilder<TName, TMessage, TServices, T>;\n\t}\n\n\t/** The typed message (job) payload the queue carries. */\n\tmessage<T extends StandardSchemaV1>(\n\t\tschema: T,\n\t): QueueBuilder<TName, T, TServices, TLogger> {\n\t\treturn cloneWith(this, {\n\t\t\t_messageSchema: schema as unknown as TMessage,\n\t\t}) as unknown as QueueBuilder<TName, T, TServices, TLogger>;\n\t}\n\n\thandle(\n\t\tfn: QueueHandler<NonNullable<TMessage>, TServices, TLogger>,\n\t): Queue<TName, NonNullable<TMessage>, TServices, TLogger> {\n\t\tif (!this._name) {\n\t\t\tthrow new Error(\n\t\t\t\t'Queue requires a name — call .queue(name) before .handle().',\n\t\t\t);\n\t\t}\n\t\tif (!this._messageSchema) {\n\t\t\tthrow new Error(\n\t\t\t\t'Queue requires a message schema — call .message(schema) before .handle().',\n\t\t\t);\n\t\t}\n\n\t\tconst queue = new Queue<TName, NonNullable<TMessage>, TServices, TLogger>(\n\t\t\tthis._name as TName,\n\t\t\tfn,\n\t\t\tthis._messageSchema as NonNullable<TMessage>,\n\t\t\tthis._timeout,\n\t\t\tthis._services,\n\t\t\tthis._logger,\n\t\t\tthis._batchSize,\n\t\t\tthis._fifo,\n\t\t);\n\n\t\t// No reset. `.handle()` reads this builder and leaves it alone, so a\n\t\t// configured base keeps its configuration for every construct built\n\t\t// from it. The reset that used to be here wiped the base on first use.\n\n\t\treturn queue;\n\t}\n}\n","export {\n\tQueue,\n\ttype QueueContext,\n\ttype QueueHandler,\n\ttype QueueMessage,\n} from './Queue';\n\nimport { QueueBuilder } from './QueueBuilder';\n\nexport { QueueBuilder } from './QueueBuilder';\n\nexport const q = new QueueBuilder();\n"],"mappings":";;;;;;;AAcA,MAAMA,mBAAiB,IAAI;;;;;;;;;;AAsB3B,IAAa,QAAb,cAKU,UAA4D;CACrE,eAAe;CAEf,OAAO,QACNC,KAC4D;AAC5D,SAAO,QACN,OACE,IAAmC,iBAAiB,QACpD,IAAkB,SAAS,cAAc,MA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OAChB,EAAC;CACF;CAED,OACCC,IAC0D;AAC1D,OAAK,KAAK,MACT,OAAM,IAAI,MACT;AAGF,OAAK,KAAK,eACT,OAAM,IAAI,MACT;EAIF,MAAM,QAAQ,IAAI,MACjB,KAAK,OACL,IACA,KAAK,gBACL,KAAK,UACL,KAAK,WACL,KAAK,SACL,KAAK,YACL,KAAK;AAON,SAAO;CACP;AACD;;;;ACvGD,MAAa,IAAI,IAAI"}
1
+ {"version":3,"file":"index.mjs","names":["name: T","timeout: number","batchSize: number","services: T","logger: T","schema: T","fn: QueueHandler<NonNullable<TMessage>, TServices, TLogger>"],"sources":["../../src/queue/QueueBuilder.ts","../../src/queue/index.ts"],"sourcesContent":["import type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { cloneWith } from '../clone';\nimport { Queue, type QueueHandler } from './Queue';\n\n/**\n * Builds a {@link Queue} worker — `q.queue('orders').services([db]).message(schema).handle(fn)`.\n * Services are an array (sniffed for required env vars); `message` is the typed\n * job payload; `handle` is the single consumer. The queue name is captured as a\n * literal so `queue.publisher` is typed to `{ type: '<name>', payload }`.\n */\nexport class QueueBuilder<\n\tTName extends string = string,\n\tTMessage extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n> {\n\tprivate _name?: string;\n\tprivate _messageSchema?: TMessage;\n\tprivate _timeout = 30000;\n\tprivate _batchSize?: number;\n\tprivate _fifo?: boolean;\n\tprivate _services: TServices = [] as Service[] as TServices;\n\tprivate _logger: TLogger = DEFAULT_LOGGER as TLogger;\n\n\t/** The queue name — drives the infra queue and its `<NAME>_*` env vars. */\n\tqueue<T extends string>(\n\t\tname: T,\n\t): QueueBuilder<T, TMessage, TServices, TLogger> {\n\t\treturn cloneWith(this, { _name: name }) as unknown as QueueBuilder<\n\t\t\tT,\n\t\t\tTMessage,\n\t\t\tTServices,\n\t\t\tTLogger\n\t\t>;\n\t}\n\n\ttimeout(timeout: number): this {\n\t\treturn cloneWith(this, { _timeout: timeout });\n\t}\n\n\t/** SQS event-source batch size (deployed). */\n\tbatchSize(batchSize: number): this {\n\t\treturn cloneWith(this, { _batchSize: batchSize });\n\t}\n\n\t/** Mark the queue as FIFO (deployed). */\n\tfifo(fifo = true): this {\n\t\treturn cloneWith(this, { _fifo: fifo });\n\t}\n\n\tservices<T extends Service[]>(\n\t\tservices: T,\n\t): QueueBuilder<TName, TMessage, [...TServices, ...T], TLogger> {\n\t\treturn cloneWith(this, {\n\t\t\t_services: [...this._services, ...services] as unknown as TServices,\n\t\t}) as unknown as QueueBuilder<\n\t\t\tTName,\n\t\t\tTMessage,\n\t\t\t[...TServices, ...T],\n\t\t\tTLogger\n\t\t>;\n\t}\n\n\tlogger<T extends Logger>(\n\t\tlogger: T,\n\t): QueueBuilder<TName, TMessage, TServices, T> {\n\t\treturn cloneWith(this, {\n\t\t\t_logger: logger as unknown as TLogger,\n\t\t}) as unknown as QueueBuilder<TName, TMessage, TServices, T>;\n\t}\n\n\t/** The typed message (job) payload the queue carries. */\n\tmessage<T extends StandardSchemaV1>(\n\t\tschema: T,\n\t): QueueBuilder<TName, T, TServices, TLogger> {\n\t\treturn cloneWith(this, {\n\t\t\t_messageSchema: schema as unknown as TMessage,\n\t\t}) as unknown as QueueBuilder<TName, T, TServices, TLogger>;\n\t}\n\n\thandle(\n\t\tfn: QueueHandler<NonNullable<TMessage>, TServices, TLogger>,\n\t): Queue<TName, NonNullable<TMessage>, TServices, TLogger> {\n\t\tif (!this._name) {\n\t\t\tthrow new Error(\n\t\t\t\t'Queue requires a name — call .queue(name) before .handle().',\n\t\t\t);\n\t\t}\n\t\tif (!this._messageSchema) {\n\t\t\tthrow new Error(\n\t\t\t\t'Queue requires a message schema — call .message(schema) before .handle().',\n\t\t\t);\n\t\t}\n\n\t\tconst queue = new Queue<TName, NonNullable<TMessage>, TServices, TLogger>(\n\t\t\tthis._name as TName,\n\t\t\tfn,\n\t\t\tthis._messageSchema as NonNullable<TMessage>,\n\t\t\tthis._timeout,\n\t\t\tthis._services,\n\t\t\tthis._logger,\n\t\t\tthis._batchSize,\n\t\t\tthis._fifo,\n\t\t);\n\n\t\t// No reset. `.handle()` reads this builder and leaves it alone, so a\n\t\t// configured base keeps its configuration for every construct built\n\t\t// from it. The reset that used to be here wiped the base on first use.\n\n\t\treturn queue;\n\t}\n}\n","export {\n\tisQueueResult,\n\tQueue,\n\ttype QueueContext,\n\ttype QueueHandler,\n\ttype QueueMessage,\n\ttype QueueRecord,\n\ttype QueueResult,\n} from './Queue';\n\nimport { QueueBuilder } from './QueueBuilder';\n\nexport { QueueBuilder } from './QueueBuilder';\n\nexport const q = new QueueBuilder();\n"],"mappings":";;;;;;;;;;;;AAaA,IAAa,eAAb,MAKE;CACD,AAAQ;CACR,AAAQ;CACR,AAAQ,WAAW;CACnB,AAAQ;CACR,AAAQ;CACR,AAAQ,YAAuB,CAAE;CACjC,AAAQ,UAAmB;;CAG3B,MACCA,MACgD;AAChD,SAAO,UAAU,MAAM,EAAE,OAAO,KAAM,EAAC;CAMvC;CAED,QAAQC,SAAuB;AAC9B,SAAO,UAAU,MAAM,EAAE,UAAU,QAAS,EAAC;CAC7C;;CAGD,UAAUC,WAAyB;AAClC,SAAO,UAAU,MAAM,EAAE,YAAY,UAAW,EAAC;CACjD;;CAGD,KAAK,OAAO,MAAY;AACvB,SAAO,UAAU,MAAM,EAAE,OAAO,KAAM,EAAC;CACvC;CAED,SACCC,UAC+D;AAC/D,SAAO,UAAU,MAAM,EACtB,WAAW,CAAC,GAAG,KAAK,WAAW,GAAG,QAAS,EAC3C,EAAC;CAMF;CAED,OACCC,QAC8C;AAC9C,SAAO,UAAU,MAAM,EACtB,SAAS,OACT,EAAC;CACF;;CAGD,QACCC,QAC6C;AAC7C,SAAO,UAAU,MAAM,EACtB,gBAAgB,OAChB,EAAC;CACF;CAED,OACCC,IAC0D;AAC1D,OAAK,KAAK,MACT,OAAM,IAAI,MACT;AAGF,OAAK,KAAK,eACT,OAAM,IAAI,MACT;EAIF,MAAM,QAAQ,IAAI,MACjB,KAAK,OACL,IACA,KAAK,gBACL,KAAK,UACL,KAAK,WACL,KAAK,SACL,KAAK,YACL,KAAK;AAON,SAAO;CACP;AACD;;;;ACpGD,MAAa,IAAI,IAAI"}
@@ -2,7 +2,7 @@ import "../Construct-BEh2DSMe.cjs";
2
2
  import { Subscriber, SubscriberHandler } from "../Subscriber-YwPpHrBc.cjs";
3
3
  import { Topic, TopicEvents, TopicMessage } from "../Topic-dIcPqSLa.cjs";
4
4
  import { EventPublisher, ExtractPublisherMessage } from "@geekmidas/events";
5
- import * as _geekmidas_logger10 from "@geekmidas/logger";
5
+ import * as _geekmidas_logger9 from "@geekmidas/logger";
6
6
  import { Logger } from "@geekmidas/logger";
7
7
  import { Service } from "@geekmidas/services";
8
8
  import { StandardSchemaV1 } from "@standard-schema/spec";
@@ -40,7 +40,7 @@ declare class SubscriberBuilder<TServices extends Service[] = [], TLogger extend
40
40
  //# sourceMappingURL=SubscriberBuilder.d.ts.map
41
41
  //#endregion
42
42
  //#region src/subscribers/index.d.ts
43
- declare const s: SubscriberBuilder<[], _geekmidas_logger10.Logger, undefined, undefined, string, []>;
43
+ declare const s: SubscriberBuilder<[], _geekmidas_logger9.Logger, undefined, undefined, string, []>;
44
44
  //# sourceMappingURL=index.d.ts.map
45
45
 
46
46
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/subscribers/SubscriberBuilder.ts","../../src/subscribers/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAYa,oCACM,gCACF,SAAS,0BACP,kEACM;;;;EAJZ,QAAA,SAAA;EAAiB,QAAA,OAAA;EAAA,QACX,UAAA;EAAO,QACT,UAAA;EAAM,WAAG,CAAA;EAAM;;;;;;;;;;;EAmCH,KAA3B,CAAA,cAAA,MAAA,EAAA,gBA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AA,GAsDK,uBAtDL,CAsD6B,eAtD7B,CAAA,CAAA,MAAA,CAAA,EAAA,GAAA,KAAA,EAAA,CAAA,KAAA,EAyDO,MAzDP,CAAA,EA0DE,iBA1DF,CA2DA,SA3DA,EA4DA,OA5DA,EA6DA,SA7DA,EA8DA,eA9DA,EA+DA,0BA/DA,EAgEA,MAhEA,SAAA,GAAA,EAAA,GAAA,CAAA,GAiEO,iBAjEP,EAAA,GAiE6B,MAjE7B,CAAA,GAAA,CAAA,GAkEO,iBAlEP,EAkE0B,MAlE1B,CAAA,CAAA;EAAe,MACf,CAAA,EAAA,EA0EI,iBA1EJ,CA2EC,eA3ED,EA4EC,iBA5ED,EA6EC,SA7ED,EA8EC,OA9ED,EA+EC,SA/ED,CAAA,CAAA,EAiFE,UAjFF,CAkFA,SAlFA,EAmFA,OAnFA,EAoFA,SApFA,EAqFA,eArFA,EAsFA,0BAtFA,EAuFA,iBAvFA,CAAA;;;;;cCvEW,GAAC,sBAA0B,mBAAA,CAA1B,MAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/subscribers/SubscriberBuilder.ts","../../src/subscribers/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAYa,oCACM,gCACF,SAAS,0BACP,kEACM;;;;EAJZ,QAAA,SAAA;EAAiB,QAAA,OAAA;EAAA,QACX,UAAA;EAAO,QACT,UAAA;EAAM,WAAG,CAAA;EAAM;;;;;;;;;;;EAmCH,KAA3B,CAAA,cAAA,MAAA,EAAA,gBAN2C,WAM3C,CAAA,CAAA,KAAA,EALO,KAKP,CALa,KAKb,EALoB,OAKpB,CAAA,CAAA,EAJE,iBAIF,CAHA,SAGA,EAFA,OAEA,EADA,SACA,EAAA,cAAA,CAAe,YAAf,CAA4B,OAA5B,CAAA,CAAA,EACA,0BADA,EAEA,iBAFA,CAAA;EAAc,OACd,CAAA,OAAA,EAAA,MAAA,CAAA,EAAA,IAAA;EAA0B,MAC1B,CAAA,UAkBgB,gBAlBhB,CA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A,CAAA,GAkEO,iBAlEP,EAkE0B,MAlE1B,CAAA,CAAA;EAAe,MACf,CAAA,EAAA,EA0EI,iBA1EJ,CA2EC,eA3ED,EA4EC,iBA5ED,EA6EC,SA7ED,EA8EC,OA9ED,EA+EC,SA/ED,CAAA,CAAA,EAiFE,UAjFF,CAkFA,SAlFA,EAmFA,OAnFA,EAoFA,SApFA,EAqFA,eArFA,EAsFA,0BAtFA,EAuFA,iBAvFA,CAAA;;;;;cCvEW,GAAC,sBAA0B,kBAAA,CAA1B,MAAA"}
@@ -1,6 +1,6 @@
1
- import "../Construct-CgluLUuF.mjs";
2
- import { Subscriber, SubscriberHandler } from "../Subscriber-panMf5vp.mjs";
3
- import { Topic, TopicEvents, TopicMessage } from "../Topic-DGtlTlu5.mjs";
1
+ import "../Construct-qnOnQTcP.mjs";
2
+ import { Subscriber, SubscriberHandler } from "../Subscriber-Bjil86Ub.mjs";
3
+ import { Topic, TopicEvents, TopicMessage } from "../Topic-D8-wkoh4.mjs";
4
4
  import { Service } from "@geekmidas/services";
5
5
  import { EventPublisher, ExtractPublisherMessage } from "@geekmidas/events";
6
6
  import { Logger as Logger$1 } from "@geekmidas/logger";
@@ -92,4 +92,4 @@ interface Telemetry {
92
92
  //# sourceMappingURL=telemetry.d.ts.map
93
93
  //#endregion
94
94
  export { Telemetry, TelemetryContext, TelemetryRequest, TelemetryResponse };
95
- //# sourceMappingURL=telemetry-Bp4DLvdQ.d.mts.map
95
+ //# sourceMappingURL=telemetry-vq7C0ZBy.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry-Bp4DLvdQ.d.mts","names":[],"sources":["../src/telemetry.ts"],"sourcesContent":[],"mappings":";;;;;;;AA6FmB,UAlFF,gBAAA,CAkFE;EAAgB;;;EAQgB,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;;;;;UAhFlC,gBAAA;;;;;;;;WASP;;;;;UAMO,iBAAA;;;;;;;;;;;;YAcN;;;;;;;;;;;;;;;;;;;;;;;;;;;UA4BM,SAAA;;;;;;;0BAOQ,mBAAmB;;;;;;;oBAQzB,4BAA4B;;;;;;;sBAQ1B,yBAAyB"}
1
+ {"version":3,"file":"telemetry-vq7C0ZBy.d.mts","names":[],"sources":["../src/telemetry.ts"],"sourcesContent":[],"mappings":";;;;;;;AA6FmB,UAlFF,gBAAA,CAkFE;EAAgB;;;EAQgB,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;;;;;UAhFlC,gBAAA;;;;;;;;WASP;;;;;UAMO,iBAAA;;;;;;;;;;;;YAcN;;;;;;;;;;;;;;;;;;;;;;;;;;;UA4BM,SAAA;;;;;;;0BAOQ,mBAAmB;;;;;;;oBAQzB,4BAA4B;;;;;;;sBAQ1B,yBAAyB"}
@@ -1,5 +1,5 @@
1
- import "../Construct-CgluLUuF.mjs";
2
- import { Topic, TopicEvents, TopicMessage } from "../Topic-DGtlTlu5.mjs";
1
+ import "../Construct-qnOnQTcP.mjs";
2
+ import { Topic, TopicEvents, TopicMessage } from "../Topic-D8-wkoh4.mjs";
3
3
  import { Logger } from "@geekmidas/logger";
4
4
 
5
5
  //#region src/topic/TopicBuilder.d.ts
@@ -6,4 +6,4 @@ type LowerHttpMethod<T extends HttpMethod> = Lowercase<T>;
6
6
 
7
7
  //#endregion
8
8
  export { HttpMethod, LowerHttpMethod, RemoveUndefined };
9
- //# sourceMappingURL=types-j0ti0JTY.d.mts.map
9
+ //# sourceMappingURL=types-X37z95fN.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types-j0ti0JTY.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";KAAY,6BAAA,MACC,CADD,IACM,CADS,CACP,CADO,CAAA,SAAA,SAAA,GAAA,KAAA,GACwB,CADxB,GAC4B,CAD5B,CAC8B,CAD9B,CAAA,EAAA;AACd,KAGD,UAAA,GAHC,KAAA,GAAA,MAAA,GAAA,KAAA,GAAA,OAAA,GAAA,QAAA,GAAA,SAAA;AAAK,KAWN,eAXM,CAAA,UAWoB,UAXpB,CAAA,GAWkC,SAXlC,CAW4C,CAX5C,CAAA"}
1
+ {"version":3,"file":"types-X37z95fN.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";KAAY,6BAAA,MACC,CADD,IACM,CADS,CACP,CADO,CAAA,SAAA,SAAA,GAAA,KAAA,GACwB,CADxB,GAC4B,CAD5B,CAC8B,CAD9B,CAAA,EAAA;AACd,KAGD,UAAA,GAHC,KAAA,GAAA,MAAA,GAAA,KAAA,GAAA,OAAA,GAAA,QAAA,GAAA,SAAA;AAAK,KAWN,eAXM,CAAA,UAWoB,UAXpB,CAAA,GAWkC,SAXlC,CAW4C,CAX5C,CAAA"}
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { HttpMethod, LowerHttpMethod, RemoveUndefined } from "./types-j0ti0JTY.mjs";
1
+ import { HttpMethod, LowerHttpMethod, RemoveUndefined } from "./types-X37z95fN.mjs";
2
2
  export { HttpMethod, LowerHttpMethod, RemoveUndefined };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/constructs",
3
- "version": "9.4.0",
3
+ "version": "9.5.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -152,33 +152,33 @@
152
152
  "pg": "~8.16.3",
153
153
  "msw": "~2.10.3",
154
154
  "zod": "~4.6.6",
155
- "@geekmidas/audit": "^9.4.0",
156
- "@geekmidas/cache": "^9.4.0",
157
- "@geekmidas/db": "^9.4.0",
158
- "@geekmidas/envkit": "^9.4.0",
159
- "@geekmidas/errors": "^9.4.0",
160
- "@geekmidas/events": "^9.4.0",
161
- "@geekmidas/logger": "^9.4.0",
162
- "@geekmidas/rate-limit": "^9.4.0",
163
- "@geekmidas/schema": "^9.4.0",
164
- "@geekmidas/services": "^9.4.0",
165
- "@geekmidas/testkit": "^9.4.0"
155
+ "@geekmidas/audit": "^9.5.0",
156
+ "@geekmidas/cache": "^9.5.0",
157
+ "@geekmidas/db": "^9.5.0",
158
+ "@geekmidas/envkit": "^9.5.0",
159
+ "@geekmidas/errors": "^9.5.0",
160
+ "@geekmidas/events": "^9.5.0",
161
+ "@geekmidas/logger": "^9.5.0",
162
+ "@geekmidas/rate-limit": "^9.5.0",
163
+ "@geekmidas/schema": "^9.5.0",
164
+ "@geekmidas/services": "^9.5.0",
165
+ "@geekmidas/testkit": "^9.5.0"
166
166
  },
167
167
  "peerDependencies": {
168
168
  "@middy/core": ">=6.3.1",
169
169
  "@types/aws-lambda": ">=8.10.92",
170
170
  "hono": ">=4.8.2",
171
171
  "msw": ">=2.0.0",
172
- "@geekmidas/audit": "^9.4.0",
173
- "@geekmidas/cache": "^9.4.0",
174
- "@geekmidas/db": "^9.4.0",
175
- "@geekmidas/envkit": "^9.4.0",
176
- "@geekmidas/errors": "^9.4.0",
177
- "@geekmidas/events": "^9.4.0",
178
- "@geekmidas/logger": "^9.4.0",
179
- "@geekmidas/rate-limit": "^9.4.0",
180
- "@geekmidas/schema": "^9.4.0",
181
- "@geekmidas/services": "^9.4.0"
172
+ "@geekmidas/audit": "^9.5.0",
173
+ "@geekmidas/cache": "^9.5.0",
174
+ "@geekmidas/db": "^9.5.0",
175
+ "@geekmidas/envkit": "^9.5.0",
176
+ "@geekmidas/errors": "^9.5.0",
177
+ "@geekmidas/events": "^9.5.0",
178
+ "@geekmidas/logger": "^9.5.0",
179
+ "@geekmidas/rate-limit": "^9.5.0",
180
+ "@geekmidas/schema": "^9.5.0",
181
+ "@geekmidas/services": "^9.5.0"
182
182
  },
183
183
  "peerDependenciesMeta": {
184
184
  "@geekmidas/audit": {
@@ -12,7 +12,7 @@ import type {
12
12
  SQSEvent,
13
13
  SQSRecord,
14
14
  } from 'aws-lambda';
15
- import type { Queue } from './Queue';
15
+ import { isQueueResult, type Queue, type QueueRecord } from './Queue';
16
16
 
17
17
  export type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<
18
18
  TEvent,
@@ -26,9 +26,10 @@ export type AWSLambdaHandler<TEvent = any, TResult = any> = Handler<
26
26
  * unwrapped to its `payload`, validated against the queue's `messageSchema`, and
27
27
  * the whole batch is handed to the handler as `messages`.
28
28
  *
29
- * Uses SQS partial-batch responses: a record that fails to parse, validate, or
30
- * (when the handler throws) process is returned in `batchItemFailures` so SQS
31
- * retries only those records.
29
+ * Uses SQS partial-batch responses: a record that fails to parse or validate
30
+ * is returned in `batchItemFailures`, so SQS retries only it. After that, the
31
+ * handler decides: returning a {@link QueueResult} retries only the records it
32
+ * names, and throwing retries every record in the batch.
32
33
  */
33
34
  export class AWSLambdaQueue<
34
35
  TName extends string = string,
@@ -100,7 +101,7 @@ export class AWSLambdaQueue<
100
101
  const schema = this.queue.messageSchema;
101
102
 
102
103
  const batchItemFailures: { itemIdentifier: string }[] = [];
103
- const messages: InferStandardSchema<TMessage>[] = [];
104
+ const records: QueueRecord<TMessage>[] = [];
104
105
 
105
106
  for (const record of event.Records) {
106
107
  try {
@@ -114,7 +115,10 @@ export class AWSLambdaQueue<
114
115
  batchItemFailures.push({ itemIdentifier: record.messageId });
115
116
  continue;
116
117
  }
117
- messages.push(validation.value as InferStandardSchema<TMessage>);
118
+ records.push({
119
+ id: record.messageId,
120
+ message: validation.value as InferStandardSchema<TMessage>,
121
+ });
118
122
  } catch (error) {
119
123
  logger.error(
120
124
  { error, messageId: record.messageId },
@@ -124,12 +128,33 @@ export class AWSLambdaQueue<
124
128
  }
125
129
  }
126
130
 
127
- if (messages.length === 0) {
131
+ if (records.length === 0) {
128
132
  return { batchItemFailures };
129
133
  }
130
134
 
131
135
  try {
132
- await this.queue.handler({ messages, services, logger });
136
+ const result = await this.queue.handler({
137
+ messages: records.map((r) => r.message),
138
+ records,
139
+ services,
140
+ logger,
141
+ });
142
+
143
+ if (isQueueResult(result)) {
144
+ const handed = new Set(records.map((r) => r.id));
145
+ const unknown = result.failed.filter((id) => !handed.has(id));
146
+ if (unknown.length > 0) {
147
+ logger.warn(
148
+ { unknown },
149
+ 'Queue handler reported records not in its batch',
150
+ );
151
+ }
152
+ for (const id of result.failed) {
153
+ if (handed.has(id)) {
154
+ batchItemFailures.push({ itemIdentifier: id });
155
+ }
156
+ }
157
+ }
133
158
  } catch (error) {
134
159
  logger.error(wrapError(error), 'Queue handler failed; retrying batch');
135
160
  // Handler processes the batch atomically — fail the whole batch so SQS
@@ -108,13 +108,47 @@ export class Queue<
108
108
  }
109
109
  }
110
110
 
111
- /** The context a queue handler receives — a batch of typed messages. */
111
+ /**
112
+ * One message in a batch, with the id its transport gave it: the SQS message id
113
+ * deployed, a generated id locally. The id is what a handler returns in
114
+ * {@link QueueResult} to have that message retried.
115
+ */
116
+ export type QueueRecord<TMessage extends StandardSchemaV1> = {
117
+ id: string;
118
+ message: InferStandardSchema<TMessage>;
119
+ };
120
+
121
+ /**
122
+ * What a handler returns to retry only part of a batch: the ids of the records
123
+ * that failed. The rest are acknowledged. Throwing instead retries the whole
124
+ * batch.
125
+ */
126
+ export type QueueResult = {
127
+ failed: readonly string[];
128
+ };
129
+
130
+ /** Whether a handler's return value reports failed records. */
131
+ export function isQueueResult(value: unknown): value is QueueResult {
132
+ return Boolean(
133
+ value &&
134
+ typeof value === 'object' &&
135
+ Array.isArray((value as { failed?: unknown }).failed),
136
+ );
137
+ }
138
+
139
+ /**
140
+ * The context a queue handler receives — a batch of typed messages.
141
+ *
142
+ * `messages` and `records` are the same batch in the same order; `records`
143
+ * carries each message's id, for a handler that reports failures per message.
144
+ */
112
145
  export type QueueContext<
113
146
  TMessage extends StandardSchemaV1,
114
147
  TServices extends Service[] = [],
115
148
  TLogger extends Logger = Logger,
116
149
  > = {
117
150
  messages: InferStandardSchema<TMessage>[];
151
+ records: QueueRecord<TMessage>[];
118
152
  services: ServiceRecord<TServices>;
119
153
  logger: TLogger;
120
154
  };
@@ -4,13 +4,16 @@ import type { InferStandardSchema } from '@geekmidas/schema';
4
4
  import type { Service, ServiceRecord } from '@geekmidas/services';
5
5
  import { runWithRequestContext, ServiceDiscovery } from '@geekmidas/services';
6
6
  import type { StandardSchemaV1 } from '@standard-schema/spec';
7
- import type { Queue } from './Queue';
7
+ import type { Queue, QueueRecord } from './Queue';
8
8
 
9
9
  /**
10
10
  * In-memory test driver for a {@link Queue} worker. Hand it a batch of messages
11
11
  * and it registers the queue's services, runs the handler in a request context,
12
12
  * and returns the handler result — no SQS/pg-boss required.
13
13
  *
14
+ * Pass `messages` and each gets the id `message-<index>`, or pass `records` to
15
+ * choose the ids, for a handler that reports failures by id.
16
+ *
14
17
  * @example
15
18
  * const adapter = new TestQueueAdaptor(ordersQueue);
16
19
  * await adapter.invoke({ messages: [{ orderId: '123' }] });
@@ -44,9 +47,18 @@ export class TestQueueAdaptor<
44
47
  const requestId = `test-${Date.now()}`;
45
48
  const startTime = Date.now();
46
49
 
50
+ const records: QueueRecord<TMessage>[] =
51
+ 'records' in request
52
+ ? request.records
53
+ : request.messages.map((message, index) => ({
54
+ id: `message-${index}`,
55
+ message,
56
+ }));
57
+
47
58
  return runWithRequestContext({ logger, requestId, startTime }, () =>
48
59
  this.queue.handler({
49
- messages: request.messages,
60
+ messages: records.map((r) => r.message),
61
+ records,
50
62
  services,
51
63
  logger,
52
64
  }),
@@ -57,7 +69,9 @@ export class TestQueueAdaptor<
57
69
  export type TestQueueRequest<
58
70
  TMessage extends StandardSchemaV1 = StandardSchemaV1,
59
71
  TServices extends Service[] = [],
60
- > = {
61
- messages: InferStandardSchema<TMessage>[];
72
+ > = (
73
+ | { messages: InferStandardSchema<TMessage>[] }
74
+ | { records: QueueRecord<TMessage>[] }
75
+ ) & {
62
76
  services?: ServiceRecord<TServices>;
63
77
  };
@@ -0,0 +1,131 @@
1
+ import { EnvironmentParser } from '@geekmidas/envkit';
2
+ import type { Context, SQSEvent } from 'aws-lambda';
3
+ import { describe, expect, it } from 'vitest';
4
+ import { z } from 'zod';
5
+ import { AWSLambdaQueue } from '../AWSLambdaQueueAdaptor';
6
+ import type { QueueContext } from '../Queue';
7
+ import { QueueBuilder } from '../QueueBuilder';
8
+
9
+ const schema = z.object({ orderId: z.string() });
10
+
11
+ type OrdersContext = QueueContext<typeof schema>;
12
+
13
+ const context = {
14
+ functionName: 'orders-worker',
15
+ awsRequestId: 'request-1',
16
+ } as Context;
17
+
18
+ /** An SQS event with one record per body, ids `message-<index>`. */
19
+ const createEvent = (bodies: unknown[]): SQSEvent =>
20
+ ({
21
+ Records: bodies.map((body, index) => ({
22
+ messageId: `message-${index}`,
23
+ body: typeof body === 'string' ? body : JSON.stringify(body),
24
+ })),
25
+ }) as SQSEvent;
26
+
27
+ /** A queue whose handler is `handle`, run through the Lambda adaptor. */
28
+ const runQueue = (
29
+ handle: (ctx: OrdersContext) => unknown,
30
+ bodies: unknown[],
31
+ ) => {
32
+ const queue = new QueueBuilder()
33
+ .queue('orders')
34
+ .message(schema)
35
+ .handle(handle);
36
+ const adaptor = new AWSLambdaQueue(new EnvironmentParser({}), queue);
37
+
38
+ return adaptor.handler(createEvent(bodies), context, () => {});
39
+ };
40
+
41
+ const ORDERS = [
42
+ { type: 'orders', payload: { orderId: 'a' } },
43
+ { type: 'orders', payload: { orderId: 'b' } },
44
+ { type: 'orders', payload: { orderId: 'c' } },
45
+ ];
46
+
47
+ describe('AWSLambdaQueue', () => {
48
+ it('hands the handler each record with its SQS message id', async () => {
49
+ const seen: OrdersContext['records'][] = [];
50
+
51
+ await runQueue(({ records }) => {
52
+ seen.push(records);
53
+ }, ORDERS);
54
+
55
+ expect(seen).toEqual([
56
+ [
57
+ { id: 'message-0', message: { orderId: 'a' } },
58
+ { id: 'message-1', message: { orderId: 'b' } },
59
+ { id: 'message-2', message: { orderId: 'c' } },
60
+ ],
61
+ ]);
62
+ });
63
+
64
+ it('acknowledges the whole batch when the handler returns nothing', async () => {
65
+ const response = await runQueue(() => {}, ORDERS);
66
+
67
+ expect(response).toEqual({ batchItemFailures: [] });
68
+ });
69
+
70
+ it('retries only the records the handler reports as failed', async () => {
71
+ const response = await runQueue(
72
+ ({ records }) => ({
73
+ failed: records
74
+ .filter((r) => r.message.orderId === 'b')
75
+ .map((r) => r.id),
76
+ }),
77
+ ORDERS,
78
+ );
79
+
80
+ expect(response).toEqual({
81
+ batchItemFailures: [{ itemIdentifier: 'message-1' }],
82
+ });
83
+ });
84
+
85
+ it('retries every record when the handler throws', async () => {
86
+ const response = await runQueue(() => {
87
+ throw new Error('downstream unavailable');
88
+ }, ORDERS);
89
+
90
+ expect(response).toEqual({
91
+ batchItemFailures: [
92
+ { itemIdentifier: 'message-0' },
93
+ { itemIdentifier: 'message-1' },
94
+ { itemIdentifier: 'message-2' },
95
+ ],
96
+ });
97
+ });
98
+
99
+ it('retries an invalid record alongside the ones the handler reports', async () => {
100
+ const response = await runQueue(
101
+ ({ records }) => ({ failed: [records[0]!.id] }),
102
+ [ORDERS[0], { type: 'orders', payload: { orderId: 42 } }],
103
+ );
104
+
105
+ expect(response).toEqual({
106
+ batchItemFailures: [
107
+ { itemIdentifier: 'message-1' },
108
+ { itemIdentifier: 'message-0' },
109
+ ],
110
+ });
111
+ });
112
+
113
+ it('ignores reported ids that are not in the batch', async () => {
114
+ const response = await runQueue(() => ({ failed: ['message-9'] }), ORDERS);
115
+
116
+ expect(response).toEqual({ batchItemFailures: [] });
117
+ });
118
+
119
+ it('takes a payload-only body as the message', async () => {
120
+ const seen: OrdersContext['messages'][] = [];
121
+
122
+ await runQueue(
123
+ ({ messages }) => {
124
+ seen.push(messages);
125
+ },
126
+ [{ orderId: 'raw' }],
127
+ );
128
+
129
+ expect(seen).toEqual([[{ orderId: 'raw' }]]);
130
+ });
131
+ });