@geekmidas/constructs 10.0.0-alpha.41 → 10.0.0-alpha.43

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 (196) hide show
  1. package/dist/{Cron-CMEGfRs8.d.cts → Cron-DI3nKoic.d.cts} +3 -2
  2. package/dist/Cron-DI3nKoic.d.cts.map +1 -0
  3. package/dist/{Cron-D6X4-xjB.d.mts → Cron-uYAHPnp7.d.mts} +3 -2
  4. package/dist/Cron-uYAHPnp7.d.mts.map +1 -0
  5. package/dist/{CronBuilder-DB35T5dL.cjs → CronBuilder-BoHzlWU_.cjs} +8 -3
  6. package/dist/CronBuilder-BoHzlWU_.cjs.map +1 -0
  7. package/dist/{CronBuilder-Dv0IlZs0.mjs → CronBuilder-CCgt0wCE.mjs} +9 -4
  8. package/dist/CronBuilder-CCgt0wCE.mjs.map +1 -0
  9. package/dist/{CronBuilder-O_gvButp.d.mts → CronBuilder-DaSUm2Na.d.mts} +5 -4
  10. package/dist/CronBuilder-DaSUm2Na.d.mts.map +1 -0
  11. package/dist/{CronBuilder-CEK7aOqD.d.cts → CronBuilder-g1lZLWyG.d.cts} +5 -4
  12. package/dist/CronBuilder-g1lZLWyG.d.cts.map +1 -0
  13. package/dist/{Endpoint-CQAeh1Rh.mjs → Endpoint-BDgmfml0.mjs} +2 -2
  14. package/dist/{Endpoint-CQAeh1Rh.mjs.map → Endpoint-BDgmfml0.mjs.map} +1 -1
  15. package/dist/{Endpoint-Dp5AKIXl.d.cts → Endpoint-BkzU6nn1.d.cts} +5 -4
  16. package/dist/Endpoint-BkzU6nn1.d.cts.map +1 -0
  17. package/dist/{Endpoint-DtI7heFm.d.mts → Endpoint-BpboleFh.d.mts} +5 -4
  18. package/dist/Endpoint-BpboleFh.d.mts.map +1 -0
  19. package/dist/{Endpoint-D1L9qu5C.cjs → Endpoint-wSCHSnqb.cjs} +2 -2
  20. package/dist/{Endpoint-D1L9qu5C.cjs.map → Endpoint-wSCHSnqb.cjs.map} +1 -1
  21. package/dist/{EndpointFactory-FeFRmlDZ.d.cts → EndpointFactory-BZZOleQT.d.cts} +4 -4
  22. package/dist/{EndpointFactory-CgMDvERK.d.mts.map → EndpointFactory-BZZOleQT.d.cts.map} +1 -1
  23. package/dist/{EndpointFactory-BBdNeaGJ.mjs → EndpointFactory-C9G2pz86.mjs} +3 -3
  24. package/dist/{EndpointFactory-BBdNeaGJ.mjs.map → EndpointFactory-C9G2pz86.mjs.map} +1 -1
  25. package/dist/{EndpointFactory-CgMDvERK.d.mts → EndpointFactory-DnNlYflU.d.mts} +4 -4
  26. package/dist/{EndpointFactory-FeFRmlDZ.d.cts.map → EndpointFactory-DnNlYflU.d.mts.map} +1 -1
  27. package/dist/{EndpointFactory-BZOCOaK6.cjs → EndpointFactory-G1g1kiqC.cjs} +3 -3
  28. package/dist/{EndpointFactory-BZOCOaK6.cjs.map → EndpointFactory-G1g1kiqC.cjs.map} +1 -1
  29. package/dist/Function-DuqGcbOI.d.mts +76 -0
  30. package/dist/Function-DuqGcbOI.d.mts.map +1 -0
  31. package/dist/Function-Pu-1kKZz.d.cts +76 -0
  32. package/dist/Function-Pu-1kKZz.d.cts.map +1 -0
  33. package/dist/{HonoEndpointAdaptor-Cq99r9H7.cjs → HonoEndpointAdaptor-CBoSm3TM.cjs} +3 -3
  34. package/dist/{HonoEndpointAdaptor-Cq99r9H7.cjs.map → HonoEndpointAdaptor-CBoSm3TM.cjs.map} +1 -1
  35. package/dist/{HonoEndpointAdaptor-Aui-x9Lg.mjs → HonoEndpointAdaptor-DL_fCB9O.mjs} +3 -3
  36. package/dist/{HonoEndpointAdaptor-Aui-x9Lg.mjs.map → HonoEndpointAdaptor-DL_fCB9O.mjs.map} +1 -1
  37. package/dist/{Queue-Ckmudcm8.cjs → Queue-D5jcw0mu.cjs} +6 -2
  38. package/dist/Queue-D5jcw0mu.cjs.map +1 -0
  39. package/dist/{Queue-YmvN2vEP.d.mts → Queue-DlsHRzUp.d.mts} +22 -10
  40. package/dist/Queue-DlsHRzUp.d.mts.map +1 -0
  41. package/dist/{Queue-CpQIGB_2.d.cts → Queue-HPyi0e1i.d.cts} +22 -10
  42. package/dist/Queue-HPyi0e1i.d.cts.map +1 -0
  43. package/dist/{Queue-C1uDgjxt.mjs → Queue-hwPN-t31.mjs} +6 -2
  44. package/dist/Queue-hwPN-t31.mjs.map +1 -0
  45. package/dist/{QueueBuilder-CJNcv4dy.cjs → QueueBuilder-BFQn3OzZ.cjs} +27 -4
  46. package/dist/QueueBuilder-BFQn3OzZ.cjs.map +1 -0
  47. package/dist/{QueueBuilder-XuPKZwKH.mjs → QueueBuilder-DCuYdjMw.mjs} +28 -5
  48. package/dist/QueueBuilder-DCuYdjMw.mjs.map +1 -0
  49. package/dist/{QueueBuilder-XEnnOWGe.d.cts → QueueBuilder-OSi6LkV9.d.cts} +24 -11
  50. package/dist/QueueBuilder-OSi6LkV9.d.cts.map +1 -0
  51. package/dist/{QueueBuilder-CM0WUxfw.d.mts → QueueBuilder-QHsnVt1P.d.mts} +24 -11
  52. package/dist/QueueBuilder-QHsnVt1P.d.mts.map +1 -0
  53. package/dist/{Subscriber-B91YSkZt.d.cts → Subscriber-Bpp02cGr.d.cts} +20 -9
  54. package/dist/Subscriber-Bpp02cGr.d.cts.map +1 -0
  55. package/dist/{Subscriber-BjHYe5hK.d.mts → Subscriber-CtN9R48-.d.mts} +20 -9
  56. package/dist/Subscriber-CtN9R48-.d.mts.map +1 -0
  57. package/dist/{SubscriberBuilder-Duk028pD.cjs → SubscriberBuilder-C2PwqwIl.cjs} +31 -3
  58. package/dist/SubscriberBuilder-C2PwqwIl.cjs.map +1 -0
  59. package/dist/{SubscriberBuilder-BhMphk4z.d.mts → SubscriberBuilder-CuCMFpYW.d.mts} +23 -11
  60. package/dist/SubscriberBuilder-CuCMFpYW.d.mts.map +1 -0
  61. package/dist/{SubscriberBuilder-DzQUWE08.mjs → SubscriberBuilder-DMFk_Ap1.mjs} +32 -4
  62. package/dist/SubscriberBuilder-DMFk_Ap1.mjs.map +1 -0
  63. package/dist/{SubscriberBuilder-BSpQX1JT.d.cts → SubscriberBuilder-g3fAVWgs.d.cts} +23 -11
  64. package/dist/SubscriberBuilder-g3fAVWgs.d.cts.map +1 -0
  65. package/dist/adaptors/aws.cjs +20 -4
  66. package/dist/adaptors/aws.cjs.map +1 -1
  67. package/dist/adaptors/aws.d.cts +17 -13
  68. package/dist/adaptors/aws.d.cts.map +1 -1
  69. package/dist/adaptors/aws.d.mts +17 -13
  70. package/dist/adaptors/aws.d.mts.map +1 -1
  71. package/dist/adaptors/aws.mjs +20 -4
  72. package/dist/adaptors/aws.mjs.map +1 -1
  73. package/dist/adaptors/hono.cjs +1 -1
  74. package/dist/adaptors/hono.d.cts +1 -1
  75. package/dist/adaptors/hono.d.mts +1 -1
  76. package/dist/adaptors/hono.mjs +1 -1
  77. package/dist/adaptors/testing.cjs +170 -13
  78. package/dist/adaptors/testing.cjs.map +1 -1
  79. package/dist/adaptors/testing.d.cts +38 -21
  80. package/dist/adaptors/testing.d.cts.map +1 -1
  81. package/dist/adaptors/testing.d.mts +38 -21
  82. package/dist/adaptors/testing.d.mts.map +1 -1
  83. package/dist/adaptors/testing.mjs +170 -13
  84. package/dist/adaptors/testing.mjs.map +1 -1
  85. package/dist/{auth-CMwml9QN.d.mts → auth-3OAmK42n.d.cts} +4 -4
  86. package/dist/{auth-CMwml9QN.d.mts.map → auth-3OAmK42n.d.cts.map} +1 -1
  87. package/dist/{auth-rVRDjIw_.d.cts → auth-BWbiewHa.d.mts} +4 -4
  88. package/dist/{auth-rVRDjIw_.d.cts.map → auth-BWbiewHa.d.mts.map} +1 -1
  89. package/dist/auth.d.cts +1 -1
  90. package/dist/auth.d.mts +1 -1
  91. package/dist/{cache-C9a_hVCc.d.cts → cache-CXh6GIgb.d.mts} +3 -3
  92. package/dist/{cache-C9a_hVCc.d.cts.map → cache-CXh6GIgb.d.mts.map} +1 -1
  93. package/dist/{cache-CeTMI8LR.d.mts → cache-DnGDGly3.d.cts} +3 -3
  94. package/dist/{cache-CeTMI8LR.d.mts.map → cache-DnGDGly3.d.cts.map} +1 -1
  95. package/dist/cache.d.cts +1 -1
  96. package/dist/cache.d.mts +1 -1
  97. package/dist/{construct-interface-_3zgxzXl.d.mts → construct-interface-B1AfqRl4.d.cts} +25 -3
  98. package/dist/{construct-interface-_3zgxzXl.d.mts.map → construct-interface-B1AfqRl4.d.cts.map} +1 -1
  99. package/dist/{construct-interface-_xi4BPN8.d.cts → construct-interface-DluK3_da.d.mts} +25 -3
  100. package/dist/{construct-interface-_xi4BPN8.d.cts.map → construct-interface-DluK3_da.d.mts.map} +1 -1
  101. package/dist/construct-interface.cjs +26 -0
  102. package/dist/construct-interface.cjs.map +1 -1
  103. package/dist/construct-interface.d.cts +2 -2
  104. package/dist/construct-interface.d.mts +2 -2
  105. package/dist/construct-interface.mjs +26 -1
  106. package/dist/construct-interface.mjs.map +1 -1
  107. package/dist/credential.d.cts +1 -1
  108. package/dist/credential.d.mts +1 -1
  109. package/dist/crons/index.cjs +1 -1
  110. package/dist/crons/index.d.cts +2 -2
  111. package/dist/crons/index.d.mts +2 -2
  112. package/dist/crons/index.mjs +1 -1
  113. package/dist/database/kysely.d.cts +1 -1
  114. package/dist/database/kysely.d.mts +1 -1
  115. package/dist/email.d.cts +1 -1
  116. package/dist/email.d.mts +1 -1
  117. package/dist/endpoints/index.cjs +3 -3
  118. package/dist/endpoints/index.d.cts +2 -2
  119. package/dist/endpoints/index.d.mts +2 -2
  120. package/dist/endpoints/index.mjs +3 -3
  121. package/dist/{external-api-DS3mujT5.d.mts → external-api-CWY9orcO.d.mts} +2 -2
  122. package/dist/{external-api-DS3mujT5.d.mts.map → external-api-CWY9orcO.d.mts.map} +1 -1
  123. package/dist/{external-api-LBfE-q3g.d.cts → external-api-D-5WB-sr.d.cts} +2 -2
  124. package/dist/{external-api-LBfE-q3g.d.cts.map → external-api-D-5WB-sr.d.cts.map} +1 -1
  125. package/dist/external-api.d.cts +1 -1
  126. package/dist/external-api.d.mts +1 -1
  127. package/dist/file-server.d.cts +1 -1
  128. package/dist/file-server.d.mts +1 -1
  129. package/dist/functions/index.cjs +1 -1
  130. package/dist/functions/index.d.cts +2 -1
  131. package/dist/functions/index.d.mts +2 -1
  132. package/dist/functions/index.mjs +1 -1
  133. package/dist/{functions-ZH60FE7H.cjs → functions-CbP5ZKma.cjs} +15 -3
  134. package/dist/functions-CbP5ZKma.cjs.map +1 -0
  135. package/dist/{functions-DCIfCRR-.mjs → functions-Di6n5ltG.mjs} +16 -4
  136. package/dist/{functions-DCIfCRR-.mjs.map → functions-Di6n5ltG.mjs.map} +1 -1
  137. package/dist/{index-B0kxstwf.d.cts → index-BuzRvKOQ.d.cts} +9 -71
  138. package/dist/index-BuzRvKOQ.d.cts.map +1 -0
  139. package/dist/{index-CjVEjOw0.d.mts → index-CTkKOer4.d.mts} +9 -71
  140. package/dist/index-CTkKOer4.d.mts.map +1 -0
  141. package/dist/{kysely-BJ8IQ_1P.d.mts → kysely-Bqov3fwv.d.mts} +3 -3
  142. package/dist/{kysely-BJ8IQ_1P.d.mts.map → kysely-Bqov3fwv.d.mts.map} +1 -1
  143. package/dist/{kysely-DVF8wOT4.d.cts → kysely-DTnkZsub.d.cts} +3 -3
  144. package/dist/{kysely-DVF8wOT4.d.cts.map → kysely-DTnkZsub.d.cts.map} +1 -1
  145. package/dist/mobile-app.d.cts +1 -1
  146. package/dist/mobile-app.d.mts +1 -1
  147. package/dist/object-storage.d.cts +1 -1
  148. package/dist/object-storage.d.mts +1 -1
  149. package/dist/queue/index.cjs +2 -2
  150. package/dist/queue/index.d.cts +2 -2
  151. package/dist/queue/index.d.mts +2 -2
  152. package/dist/queue/index.mjs +2 -2
  153. package/dist/rest-api.cjs +1 -1
  154. package/dist/rest-api.d.cts +3 -3
  155. package/dist/rest-api.d.mts +3 -3
  156. package/dist/rest-api.mjs +1 -1
  157. package/dist/site.d.cts +1 -1
  158. package/dist/site.d.mts +1 -1
  159. package/dist/subscribers/index.cjs +1 -1
  160. package/dist/subscribers/index.d.cts +2 -2
  161. package/dist/subscribers/index.d.mts +2 -2
  162. package/dist/subscribers/index.mjs +1 -1
  163. package/dist/worker.cjs +26 -10
  164. package/dist/worker.cjs.map +1 -1
  165. package/dist/worker.d.cts +38 -22
  166. package/dist/worker.d.cts.map +1 -1
  167. package/dist/worker.d.mts +38 -22
  168. package/dist/worker.d.mts.map +1 -1
  169. package/dist/worker.mjs +26 -10
  170. package/dist/worker.mjs.map +1 -1
  171. package/package.json +31 -31
  172. package/dist/Cron-CMEGfRs8.d.cts.map +0 -1
  173. package/dist/Cron-D6X4-xjB.d.mts.map +0 -1
  174. package/dist/CronBuilder-CEK7aOqD.d.cts.map +0 -1
  175. package/dist/CronBuilder-DB35T5dL.cjs.map +0 -1
  176. package/dist/CronBuilder-Dv0IlZs0.mjs.map +0 -1
  177. package/dist/CronBuilder-O_gvButp.d.mts.map +0 -1
  178. package/dist/Endpoint-Dp5AKIXl.d.cts.map +0 -1
  179. package/dist/Endpoint-DtI7heFm.d.mts.map +0 -1
  180. package/dist/Queue-C1uDgjxt.mjs.map +0 -1
  181. package/dist/Queue-Ckmudcm8.cjs.map +0 -1
  182. package/dist/Queue-CpQIGB_2.d.cts.map +0 -1
  183. package/dist/Queue-YmvN2vEP.d.mts.map +0 -1
  184. package/dist/QueueBuilder-CJNcv4dy.cjs.map +0 -1
  185. package/dist/QueueBuilder-CM0WUxfw.d.mts.map +0 -1
  186. package/dist/QueueBuilder-XEnnOWGe.d.cts.map +0 -1
  187. package/dist/QueueBuilder-XuPKZwKH.mjs.map +0 -1
  188. package/dist/Subscriber-B91YSkZt.d.cts.map +0 -1
  189. package/dist/Subscriber-BjHYe5hK.d.mts.map +0 -1
  190. package/dist/SubscriberBuilder-BSpQX1JT.d.cts.map +0 -1
  191. package/dist/SubscriberBuilder-BhMphk4z.d.mts.map +0 -1
  192. package/dist/SubscriberBuilder-Duk028pD.cjs.map +0 -1
  193. package/dist/SubscriberBuilder-DzQUWE08.mjs.map +0 -1
  194. package/dist/functions-ZH60FE7H.cjs.map +0 -1
  195. package/dist/index-B0kxstwf.d.cts.map +0 -1
  196. package/dist/index-CjVEjOw0.d.mts.map +0 -1
package/dist/worker.d.cts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { t as StandardSchemaV1 } from "./index-CeEtxDmK.cjs";
2
2
  import { c as Topic, l as TopicEvents, u as TopicMessage } from "./Construct-BQALFCh2.cjs";
3
- import { a as FunctionHandler, r as Function, t as FunctionBuilder } from "./index-B0kxstwf.cjs";
4
- import { c as ServicesOf, i as Declarable, r as Consumable } from "./construct-interface-_xi4BPN8.cjs";
5
- import { i as ScheduleExpression } from "./Cron-CMEGfRs8.cjs";
6
- import { t as CronBuilder } from "./CronBuilder-CEK7aOqD.cjs";
7
- import { t as QueueBuilder } from "./QueueBuilder-XEnnOWGe.cjs";
8
- import { t as SubscriberBuilder } from "./SubscriberBuilder-BSpQX1JT.cjs";
3
+ import { i as FunctionHandler, n as Function } from "./Function-Pu-1kKZz.cjs";
4
+ import { c as ServicesOf, i as Declarable, r as Consumable } from "./construct-interface-B1AfqRl4.cjs";
5
+ import { t as FunctionBuilder } from "./index-BuzRvKOQ.cjs";
6
+ import { i as ScheduleExpression } from "./Cron-DI3nKoic.cjs";
7
+ import { t as CronBuilder } from "./CronBuilder-g1lZLWyG.cjs";
8
+ import { t as QueueBuilder } from "./QueueBuilder-OSi6LkV9.cjs";
9
+ import { t as SubscriberBuilder } from "./SubscriberBuilder-g3fAVWgs.cjs";
9
10
  import "./topic/index.cjs";
10
11
  import { EnvironmentParser } from "@geekmidas/envkit";
11
12
  import { Logger } from "@geekmidas/logger";
@@ -31,7 +32,7 @@ export interface WorkerConfig {
31
32
  */
32
33
  envParser?: EnvironmentParser<{}>;
33
34
  }
34
- export declare class Worker<TName extends string = string> implements Declarable<TName> {
35
+ export declare class Worker<TName extends string = string, TDatabase = undefined, TDatabaseServiceName extends string = string> implements Declarable<TName> {
35
36
  private readonly config;
36
37
  /** Internal: how `.calls()` carries edges into the copy it returns. */
37
38
  private readonly dependencies;
@@ -42,14 +43,18 @@ export declare class Worker<TName extends string = string> implements Declarable
42
43
  readonly envParser: EnvironmentParser<{}>;
43
44
  /**
44
45
  * Where this worker's schedules live, when it has crons and a server runs
45
- * them. `undefined` until `.database(…)` says.
46
+ * them — and the database everything built from it receives as `db`.
47
+ * `undefined` until `.database(…)` says.
46
48
  */
47
49
  readonly scheduleStore?: Consumable<string, unknown>;
48
50
  constructor(id: ConstructName<TName>, config?: WorkerConfig,
49
51
  /** Internal: how `.calls()` carries edges into the copy it returns. */
50
52
  dependencies?: readonly Dependency[], scheduleStore?: Consumable<string, unknown>);
51
53
  /**
52
- * The database this worker keeps its schedules in.
54
+ * The database this worker keeps its schedules in, and the one everything
55
+ * built from it — crons, queues, subscribers, functions — receives as `db`.
56
+ * One of them that works against another database names it with its own
57
+ * `.database(other)`, which replaces this one for that runnable alone.
53
58
  *
54
59
  * Only a server target uses it. On AWS a cron is an EventBridge rule
55
60
  * invoking a Lambda and nothing here is consulted — but a server has nothing
@@ -66,15 +71,19 @@ export declare class Worker<TName extends string = string> implements Declarable
66
71
  * @example
67
72
  * ```ts
68
73
  * export const jobs = new Worker('Jobs', { logger }).database(database);
74
+ *
75
+ * export const sweep = jobs
76
+ * .cron('rate(1 hour)')
77
+ * .handle(async ({ db }) => db.deleteFrom('sessions').execute());
69
78
  * ```
70
79
  */
71
- database<T, TDbName extends string>(source: Consumable<TDbName, T>): Worker<TName>;
80
+ database<T, TDbName extends string>(source: Consumable<TDbName, T>): Worker<TName, T, TDbName>;
72
81
  /**
73
82
  * A scheduled runnable.
74
83
  *
75
84
  * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`
76
85
  */
77
- cron(schedule: ScheduleExpression): CronBuilder<ComposableStandardSchema, Service[], Logger, undefined, undefined, string>;
86
+ cron(schedule: ScheduleExpression): CronBuilder<ComposableStandardSchema, Service[], Logger, undefined, TDatabase, TDatabaseServiceName>;
78
87
  /**
79
88
  * A queue and its one consumer, run by this worker.
80
89
  *
@@ -91,7 +100,7 @@ export declare class Worker<TName extends string = string> implements Declarable
91
100
  * .handle(async ({ messages, services }) => { … });
92
101
  * ```
93
102
  */
94
- queue<TQueueName extends string>(name: TQueueName): QueueBuilder<TQueueName, undefined, [], Logger>;
103
+ queue<TQueueName extends string>(name: TQueueName): QueueBuilder<TQueueName, undefined, [], Logger, TDatabase, TDatabaseServiceName>;
95
104
  /**
96
105
  * A runnable that consumes a topic.
97
106
  *
@@ -102,7 +111,7 @@ export declare class Worker<TName extends string = string> implements Declarable
102
111
  *
103
112
  * @example `worker.topic(users).subscribe(['user.created']).handle(…)`
104
113
  */
105
- topic<TTopicName extends string, TEvents extends TopicEvents>(topic: Topic<TTopicName, TEvents>): SubscriberBuilder<[], Logger, undefined, EventPublisher<TopicMessage<TEvents_1>>, []>;
114
+ topic<TTopicName extends string, TEvents extends TopicEvents>(topic: Topic<TTopicName, TEvents>): SubscriberBuilder<[], Logger, undefined, EventPublisher<TopicMessage<TEvents_1>>, [], TDatabase, TDatabaseServiceName>;
106
115
  /**
107
116
  * Everything below builds a function — the runnable with no schedule and no
108
117
  * topic, invoked by something else.
@@ -114,18 +123,18 @@ export declare class Worker<TName extends string = string> implements Declarable
114
123
  * makes a cron, a topic makes a subscriber, and anything else makes a
115
124
  * function.
116
125
  */
117
- input<T extends ComposableStandardSchema>(schema: T): FunctionBuilder<T, undefined, [], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
118
- output<T extends StandardSchemaV1>(schema: T): FunctionBuilder<ComposableStandardSchema, T, [], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
119
- timeout(ms: number): FunctionBuilder<ComposableStandardSchema, undefined, [], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
120
- memorySize(mb: number): FunctionBuilder<ComposableStandardSchema, undefined, [], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
121
- dependsOn<const T extends readonly Consumable[]>(constructs: T): FunctionBuilder<ComposableStandardSchema, undefined, [...ServicesOf<T>], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
122
- services<T extends Service[]>(services: T): FunctionBuilder<ComposableStandardSchema, undefined, [...T], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
126
+ input<T extends ComposableStandardSchema>(schema: T): FunctionBuilder<T, undefined, [], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
127
+ output<T extends StandardSchemaV1>(schema: T): FunctionBuilder<any, T, [], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
128
+ timeout(ms: number): FunctionBuilder<any, undefined, [], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
129
+ memorySize(mb: number): FunctionBuilder<any, undefined, [], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
130
+ dependsOn<const T extends readonly Consumable[]>(constructs: T): FunctionBuilder<any, undefined, [...ServicesOf<T>], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
131
+ services<T extends Service[]>(services: T): FunctionBuilder<any, undefined, [...T], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
123
132
  /**
124
133
  * A function with no input schema — the shortest runnable there is.
125
134
  *
126
135
  * @example `worker.handle(async ({ logger }) => { … })`
127
136
  */
128
- handle(...args: Parameters<ReturnType<Worker<TName>['schemalessFunction']>['handle']>): Function<ComposableStandardSchema, [], Logger, undefined, undefined, string, undefined, string, AuditableAction<string, unknown>, FunctionHandler<ComposableStandardSchema, [], Logger, undefined, undefined, undefined, AuditableAction<string, unknown>>>;
137
+ handle(...args: Parameters<ReturnType<Worker<TName, TDatabase, TDatabaseServiceName>['schemalessFunction']>['handle']>): Function<any, [], Logger, undefined, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>, FunctionHandler<any, [], Logger, undefined, TDatabase, undefined, AuditableAction<string, unknown>>>;
129
138
  /** The builder `handle` delegates to, named so its type can be referred to. */
130
139
  private schemalessFunction;
131
140
  /** The function builder the delegating methods above are built on. */
@@ -136,10 +145,17 @@ export declare class Worker<TName extends string = string> implements Declarable
136
145
  * Not `.dependsOn()`: this records the edge that derives the worker's
137
146
  * environment and its access, the same distinction `RestApi.calls()` draws.
138
147
  */
139
- calls(constructs: readonly Declarable[]): Worker<TName>;
148
+ calls(constructs: readonly Declarable[]): Worker<TName, TDatabase, TDatabaseServiceName>;
140
149
  /**
141
150
  * Stamps this worker's id onto a builder, so everything built from it says
142
- * which process runs it.
151
+ * which process runs it — and hands it the worker's database.
152
+ *
153
+ * The database goes through the builder's own `.database()` rather than
154
+ * being written into its fields, so the default is recorded exactly as an
155
+ * explicit one would be: the client the handler gets, and the edge the
156
+ * manifest reads. That is also what lets a later `.database(other)` replace
157
+ * it outright. The builder arrives already typed with this worker's
158
+ * database; this is the runtime half of that.
143
159
  */
144
160
  private own;
145
161
  declare(): Declaration[];
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.cts","names":["_$__topic0.TopicMessage","_$__construct_interface0.ServicesOf","_$__functions0.FunctionHandler","_$__functions0.Function"],"sources":["../src/worker.ts"],"mappings":";;;;;;;;;;;;;;;iBAkFiB;;;;;;;;;EAShB,SAAS;;;;;;;EAOT,YAAY;;qBAGA,OAAO,0CACR,WAAW;mBAkBJ;;mBAEA;WAlBT,IAAI;;WAGJ,QAAQ;;WAGR,WAAW;;;;;WAMX,gBAAgB;EAEzB,YACC,IAAI,cAAc,QACD,SAAQ,cAER;;EAAA,wBAAuB,cACxC,gBAAgB;;;;;;;;;;;;;;;;;;;;;EAkCjB,SAAS,GAAG,wBACX,QAAQ,WAAW,SAAS,KAC1B,OAAO;;;;;;EAcV,KAAK,UAAU,qBAAkB,YAAA,0BAAA,WAAA;;;;;;;;;;;;;;;;;EAoBjC,MAAM,2BAA2B,MAAM,aAAU,aAAA,2BAAA;;;;;;;;;;;EAcjD,MAAM,2BAA2B,gBAAgB,aAChD,OAAO,MAAM,YAAY,WAAQ,sBAAA,mBAAA,eAAAA,aAAA;;;;;;;;;;;;EAgBlC,MAAM,UAAU,0BAA0B,QAAQ,IAAC,gBAAA,kBAAA,8CAAA;EAInD,OAAO,UAAU,kBAAkB,QAAQ,IAAC,gBAAA,0BAAA,OAAA,8CAAA;EAI5C,QAAQ,aAAU,gBAAA,yCAAA,8CAAA;EAIlB,WAAW,aAAU,gBAAA,yCAAA,8CAAA;EAIrB,gBAAgB,mBAAmB,cAAc,YAAY,IAAC,gBAAA,yCAAAC,WAAA,KAAA,8CAAA;EAI9D,SAAS,UAAU,WAAW,UAAU,IAAC,gBAAA,yCAAA,IAAA,8CAAA;;;;;;EASzC,UACI,MAAM,WACR,WAAW,OAAO,2CAClBE,SAAA,8BAAA,yDAAA,kCAAAD,gBAAA,8BAAA,yCAAA;;UAMM;;cAKI;;;;;;;EAUZ,MAAM,qBAAqB,eAAe,OAAO;;;;;UAazC;EASR,WAAW"}
1
+ {"version":3,"file":"worker.d.cts","names":["_$__topic0.TopicMessage","_$__construct_interface0.ServicesOf","_$__functions0.FunctionHandler","_$__functions0.Function"],"sources":["../src/worker.ts"],"mappings":";;;;;;;;;;;;;;;;iBAkGiB;;;;;;;;;EAShB,SAAS;;;;;;;EAOT,YAAY;;qBAGA,OACZ,+BACA,uBACA,yDACY,WAAW;mBAmBL;;mBAEA;WAnBT,IAAI;;WAGJ,QAAQ;;WAGR,WAAW;;;;;;WAOX,gBAAgB;EAEzB,YACC,IAAI,cAAc,QACD,SAAQ,cAER;;EAAA,wBAAuB,cACxC,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyCjB,SAAS,GAAG,wBACX,QAAQ,WAAW,SAAS,KAC1B,OAAO,OAAO,GAAG;;;;;;EAcpB,KAAK,UAAU,qBAAkB,YAAA,0BAAA,WAAA,mBAAA,WAAA;;;;;;;;;;;;;;;;;EA6BjC,MAAM,2BAA2B,MAAM,aAAU,aAAA,2BAAA,QAAA,WAAA;;;;;;;;;;;EAuBjD,MAAM,2BAA2B,gBAAgB,aAChD,OAAO,MAAM,YAAY,WAAQ,sBAAA,mBAAA,eAAAA,aAAA,iBAAA,WAAA;;;;;;;;;;;;EA0BlC,MAAM,UAAU,0BAA0B,QAAQ,IAAC,gBAAA,kBAAA,2BAAA,WAAA,sBAAA;EAInD,OAAO,UAAU,kBAAkB,QAAQ,IAAC,qBAAA,OAAA,2BAAA,WAAA,sBAAA;EAI5C,QAAQ,aAAU,oCAAA,2BAAA,WAAA,sBAAA;EAIlB,WAAW,aAAU,oCAAA,2BAAA,WAAA,sBAAA;EAIrB,gBAAgB,mBAAmB,cAAc,YAAY,IAAC,oCAAAC,WAAA,KAAA,2BAAA,WAAA,sBAAA;EAI9D,SAAS,UAAU,WAAW,UAAU,IAAC,oCAAA,IAAA,2BAAA,WAAA,sBAAA;;;;;;EASzC,UACI,MAAM,WACR,WACC,OAAO,OAAO,WAAW,0DAE1BE,kBAAA,sCAAA,WAAA,sBAAA,kCAAAD,yBAAA,mBAAA,sBAAA;;UAMM;;cAKI;;;;;;;EAqBZ,MACC,qBAAqB,eACnB,OAAO,OAAO,WAAW;;;;;;;;;;;;UAoBpB;EAiBR,WAAW"}
package/dist/worker.d.mts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { t as StandardSchemaV1 } from "./index-CeEtxDmK.mjs";
2
2
  import { c as Topic, l as TopicEvents, u as TopicMessage } from "./Construct-QXnl3VqT.mjs";
3
- import { a as FunctionHandler, r as Function, t as FunctionBuilder } from "./index-CjVEjOw0.mjs";
4
- import { c as ServicesOf, i as Declarable, r as Consumable } from "./construct-interface-_3zgxzXl.mjs";
5
- import { i as ScheduleExpression } from "./Cron-D6X4-xjB.mjs";
6
- import { t as CronBuilder } from "./CronBuilder-O_gvButp.mjs";
7
- import { t as QueueBuilder } from "./QueueBuilder-CM0WUxfw.mjs";
8
- import { t as SubscriberBuilder } from "./SubscriberBuilder-BhMphk4z.mjs";
3
+ import { i as FunctionHandler, n as Function } from "./Function-DuqGcbOI.mjs";
4
+ import { c as ServicesOf, i as Declarable, r as Consumable } from "./construct-interface-DluK3_da.mjs";
5
+ import { t as FunctionBuilder } from "./index-CTkKOer4.mjs";
6
+ import { i as ScheduleExpression } from "./Cron-uYAHPnp7.mjs";
7
+ import { t as CronBuilder } from "./CronBuilder-DaSUm2Na.mjs";
8
+ import { t as QueueBuilder } from "./QueueBuilder-QHsnVt1P.mjs";
9
+ import { t as SubscriberBuilder } from "./SubscriberBuilder-CuCMFpYW.mjs";
9
10
  import "./topic/index.mjs";
10
11
  import { ConstructName, Declaration, Dependency } from "@geekmidas/manifest";
11
12
  import { EnvironmentParser } from "@geekmidas/envkit";
@@ -31,7 +32,7 @@ export interface WorkerConfig {
31
32
  */
32
33
  envParser?: EnvironmentParser<{}>;
33
34
  }
34
- export declare class Worker<TName extends string = string> implements Declarable<TName> {
35
+ export declare class Worker<TName extends string = string, TDatabase = undefined, TDatabaseServiceName extends string = string> implements Declarable<TName> {
35
36
  private readonly config;
36
37
  /** Internal: how `.calls()` carries edges into the copy it returns. */
37
38
  private readonly dependencies;
@@ -42,14 +43,18 @@ export declare class Worker<TName extends string = string> implements Declarable
42
43
  readonly envParser: EnvironmentParser<{}>;
43
44
  /**
44
45
  * Where this worker's schedules live, when it has crons and a server runs
45
- * them. `undefined` until `.database(…)` says.
46
+ * them — and the database everything built from it receives as `db`.
47
+ * `undefined` until `.database(…)` says.
46
48
  */
47
49
  readonly scheduleStore?: Consumable<string, unknown>;
48
50
  constructor(id: ConstructName<TName>, config?: WorkerConfig,
49
51
  /** Internal: how `.calls()` carries edges into the copy it returns. */
50
52
  dependencies?: readonly Dependency[], scheduleStore?: Consumable<string, unknown>);
51
53
  /**
52
- * The database this worker keeps its schedules in.
54
+ * The database this worker keeps its schedules in, and the one everything
55
+ * built from it — crons, queues, subscribers, functions — receives as `db`.
56
+ * One of them that works against another database names it with its own
57
+ * `.database(other)`, which replaces this one for that runnable alone.
53
58
  *
54
59
  * Only a server target uses it. On AWS a cron is an EventBridge rule
55
60
  * invoking a Lambda and nothing here is consulted — but a server has nothing
@@ -66,15 +71,19 @@ export declare class Worker<TName extends string = string> implements Declarable
66
71
  * @example
67
72
  * ```ts
68
73
  * export const jobs = new Worker('Jobs', { logger }).database(database);
74
+ *
75
+ * export const sweep = jobs
76
+ * .cron('rate(1 hour)')
77
+ * .handle(async ({ db }) => db.deleteFrom('sessions').execute());
69
78
  * ```
70
79
  */
71
- database<T, TDbName extends string>(source: Consumable<TDbName, T>): Worker<TName>;
80
+ database<T, TDbName extends string>(source: Consumable<TDbName, T>): Worker<TName, T, TDbName>;
72
81
  /**
73
82
  * A scheduled runnable.
74
83
  *
75
84
  * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`
76
85
  */
77
- cron(schedule: ScheduleExpression): CronBuilder<ComposableStandardSchema, Service[], Logger, undefined, undefined, string>;
86
+ cron(schedule: ScheduleExpression): CronBuilder<ComposableStandardSchema, Service[], Logger, undefined, TDatabase, TDatabaseServiceName>;
78
87
  /**
79
88
  * A queue and its one consumer, run by this worker.
80
89
  *
@@ -91,7 +100,7 @@ export declare class Worker<TName extends string = string> implements Declarable
91
100
  * .handle(async ({ messages, services }) => { … });
92
101
  * ```
93
102
  */
94
- queue<TQueueName extends string>(name: TQueueName): QueueBuilder<TQueueName, undefined, [], Logger>;
103
+ queue<TQueueName extends string>(name: TQueueName): QueueBuilder<TQueueName, undefined, [], Logger, TDatabase, TDatabaseServiceName>;
95
104
  /**
96
105
  * A runnable that consumes a topic.
97
106
  *
@@ -102,7 +111,7 @@ export declare class Worker<TName extends string = string> implements Declarable
102
111
  *
103
112
  * @example `worker.topic(users).subscribe(['user.created']).handle(…)`
104
113
  */
105
- topic<TTopicName extends string, TEvents extends TopicEvents>(topic: Topic<TTopicName, TEvents>): SubscriberBuilder<[], Logger, undefined, EventPublisher<TopicMessage<TEvents_1>>, []>;
114
+ topic<TTopicName extends string, TEvents extends TopicEvents>(topic: Topic<TTopicName, TEvents>): SubscriberBuilder<[], Logger, undefined, EventPublisher<TopicMessage<TEvents_1>>, [], TDatabase, TDatabaseServiceName>;
106
115
  /**
107
116
  * Everything below builds a function — the runnable with no schedule and no
108
117
  * topic, invoked by something else.
@@ -114,18 +123,18 @@ export declare class Worker<TName extends string = string> implements Declarable
114
123
  * makes a cron, a topic makes a subscriber, and anything else makes a
115
124
  * function.
116
125
  */
117
- input<T extends ComposableStandardSchema>(schema: T): FunctionBuilder<T, undefined, [], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
118
- output<T extends StandardSchemaV1>(schema: T): FunctionBuilder<ComposableStandardSchema, T, [], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
119
- timeout(ms: number): FunctionBuilder<ComposableStandardSchema, undefined, [], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
120
- memorySize(mb: number): FunctionBuilder<ComposableStandardSchema, undefined, [], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
121
- dependsOn<const T extends readonly Consumable[]>(constructs: T): FunctionBuilder<ComposableStandardSchema, undefined, [...ServicesOf<T>], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
122
- services<T extends Service[]>(services: T): FunctionBuilder<ComposableStandardSchema, undefined, [...T], Logger, undefined, string, undefined, string, AuditableAction<string, unknown>>;
126
+ input<T extends ComposableStandardSchema>(schema: T): FunctionBuilder<T, undefined, [], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
127
+ output<T extends StandardSchemaV1>(schema: T): FunctionBuilder<any, T, [], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
128
+ timeout(ms: number): FunctionBuilder<any, undefined, [], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
129
+ memorySize(mb: number): FunctionBuilder<any, undefined, [], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
130
+ dependsOn<const T extends readonly Consumable[]>(constructs: T): FunctionBuilder<any, undefined, [...ServicesOf<T>], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
131
+ services<T extends Service[]>(services: T): FunctionBuilder<any, undefined, [...T], Logger, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>>;
123
132
  /**
124
133
  * A function with no input schema — the shortest runnable there is.
125
134
  *
126
135
  * @example `worker.handle(async ({ logger }) => { … })`
127
136
  */
128
- handle(...args: Parameters<ReturnType<Worker<TName>['schemalessFunction']>['handle']>): Function<ComposableStandardSchema, [], Logger, undefined, undefined, string, undefined, string, AuditableAction<string, unknown>, FunctionHandler<ComposableStandardSchema, [], Logger, undefined, undefined, undefined, AuditableAction<string, unknown>>>;
137
+ handle(...args: Parameters<ReturnType<Worker<TName, TDatabase, TDatabaseServiceName>['schemalessFunction']>['handle']>): Function<any, [], Logger, undefined, undefined, string, TDatabase, TDatabaseServiceName, AuditableAction<string, unknown>, FunctionHandler<any, [], Logger, undefined, TDatabase, undefined, AuditableAction<string, unknown>>>;
129
138
  /** The builder `handle` delegates to, named so its type can be referred to. */
130
139
  private schemalessFunction;
131
140
  /** The function builder the delegating methods above are built on. */
@@ -136,10 +145,17 @@ export declare class Worker<TName extends string = string> implements Declarable
136
145
  * Not `.dependsOn()`: this records the edge that derives the worker's
137
146
  * environment and its access, the same distinction `RestApi.calls()` draws.
138
147
  */
139
- calls(constructs: readonly Declarable[]): Worker<TName>;
148
+ calls(constructs: readonly Declarable[]): Worker<TName, TDatabase, TDatabaseServiceName>;
140
149
  /**
141
150
  * Stamps this worker's id onto a builder, so everything built from it says
142
- * which process runs it.
151
+ * which process runs it — and hands it the worker's database.
152
+ *
153
+ * The database goes through the builder's own `.database()` rather than
154
+ * being written into its fields, so the default is recorded exactly as an
155
+ * explicit one would be: the client the handler gets, and the edge the
156
+ * manifest reads. That is also what lets a later `.database(other)` replace
157
+ * it outright. The builder arrives already typed with this worker's
158
+ * database; this is the runtime half of that.
143
159
  */
144
160
  private own;
145
161
  declare(): Declaration[];
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.mts","names":["_$__topic0.TopicMessage","_$__construct_interface0.ServicesOf","_$__functions0.FunctionHandler","_$__functions0.Function"],"sources":["../src/worker.ts"],"mappings":";;;;;;;;;;;;;;;iBAkFiB;;;;;;;;;EAShB,SAAS;;;;;;;EAOT,YAAY;;qBAGA,OAAO,0CACR,WAAW;mBAkBJ;;mBAEA;WAlBT,IAAI;;WAGJ,QAAQ;;WAGR,WAAW;;;;;WAMX,gBAAgB;EAEzB,YACC,IAAI,cAAc,QACD,SAAQ,cAER;;EAAA,wBAAuB,cACxC,gBAAgB;;;;;;;;;;;;;;;;;;;;;EAkCjB,SAAS,GAAG,wBACX,QAAQ,WAAW,SAAS,KAC1B,OAAO;;;;;;EAcV,KAAK,UAAU,qBAAkB,YAAA,0BAAA,WAAA;;;;;;;;;;;;;;;;;EAoBjC,MAAM,2BAA2B,MAAM,aAAU,aAAA,2BAAA;;;;;;;;;;;EAcjD,MAAM,2BAA2B,gBAAgB,aAChD,OAAO,MAAM,YAAY,WAAQ,sBAAA,mBAAA,eAAAA,aAAA;;;;;;;;;;;;EAgBlC,MAAM,UAAU,0BAA0B,QAAQ,IAAC,gBAAA,kBAAA,8CAAA;EAInD,OAAO,UAAU,kBAAkB,QAAQ,IAAC,gBAAA,0BAAA,OAAA,8CAAA;EAI5C,QAAQ,aAAU,gBAAA,yCAAA,8CAAA;EAIlB,WAAW,aAAU,gBAAA,yCAAA,8CAAA;EAIrB,gBAAgB,mBAAmB,cAAc,YAAY,IAAC,gBAAA,yCAAAC,WAAA,KAAA,8CAAA;EAI9D,SAAS,UAAU,WAAW,UAAU,IAAC,gBAAA,yCAAA,IAAA,8CAAA;;;;;;EASzC,UACI,MAAM,WACR,WAAW,OAAO,2CAClBE,SAAA,8BAAA,yDAAA,kCAAAD,gBAAA,8BAAA,yCAAA;;UAMM;;cAKI;;;;;;;EAUZ,MAAM,qBAAqB,eAAe,OAAO;;;;;UAazC;EASR,WAAW"}
1
+ {"version":3,"file":"worker.d.mts","names":["_$__topic0.TopicMessage","_$__construct_interface0.ServicesOf","_$__functions0.FunctionHandler","_$__functions0.Function"],"sources":["../src/worker.ts"],"mappings":";;;;;;;;;;;;;;;;iBAkGiB;;;;;;;;;EAShB,SAAS;;;;;;;EAOT,YAAY;;qBAGA,OACZ,+BACA,uBACA,yDACY,WAAW;mBAmBL;;mBAEA;WAnBT,IAAI;;WAGJ,QAAQ;;WAGR,WAAW;;;;;;WAOX,gBAAgB;EAEzB,YACC,IAAI,cAAc,QACD,SAAQ,cAER;;EAAA,wBAAuB,cACxC,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyCjB,SAAS,GAAG,wBACX,QAAQ,WAAW,SAAS,KAC1B,OAAO,OAAO,GAAG;;;;;;EAcpB,KAAK,UAAU,qBAAkB,YAAA,0BAAA,WAAA,mBAAA,WAAA;;;;;;;;;;;;;;;;;EA6BjC,MAAM,2BAA2B,MAAM,aAAU,aAAA,2BAAA,QAAA,WAAA;;;;;;;;;;;EAuBjD,MAAM,2BAA2B,gBAAgB,aAChD,OAAO,MAAM,YAAY,WAAQ,sBAAA,mBAAA,eAAAA,aAAA,iBAAA,WAAA;;;;;;;;;;;;EA0BlC,MAAM,UAAU,0BAA0B,QAAQ,IAAC,gBAAA,kBAAA,2BAAA,WAAA,sBAAA;EAInD,OAAO,UAAU,kBAAkB,QAAQ,IAAC,qBAAA,OAAA,2BAAA,WAAA,sBAAA;EAI5C,QAAQ,aAAU,oCAAA,2BAAA,WAAA,sBAAA;EAIlB,WAAW,aAAU,oCAAA,2BAAA,WAAA,sBAAA;EAIrB,gBAAgB,mBAAmB,cAAc,YAAY,IAAC,oCAAAC,WAAA,KAAA,2BAAA,WAAA,sBAAA;EAI9D,SAAS,UAAU,WAAW,UAAU,IAAC,oCAAA,IAAA,2BAAA,WAAA,sBAAA;;;;;;EASzC,UACI,MAAM,WACR,WACC,OAAO,OAAO,WAAW,0DAE1BE,kBAAA,sCAAA,WAAA,sBAAA,kCAAAD,yBAAA,mBAAA,sBAAA;;UAMM;;cAKI;;;;;;;EAqBZ,MACC,qBAAqB,eACnB,OAAO,OAAO,WAAW;;;;;;;;;;;;UAoBpB;EAiBR,WAAW"}
package/dist/worker.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import { edgeTo } from "./construct-interface.mjs";
2
- import { t as FunctionBuilder } from "./functions-DCIfCRR-.mjs";
2
+ import { t as FunctionBuilder } from "./functions-Di6n5ltG.mjs";
3
3
  import { n as envParserFor } from "./surfaceEnv-wMT5QzgZ.mjs";
4
- import { t as CronBuilder } from "./CronBuilder-Dv0IlZs0.mjs";
5
- import { t as QueueBuilder } from "./QueueBuilder-XuPKZwKH.mjs";
6
- import { t as SubscriberBuilder } from "./SubscriberBuilder-DzQUWE08.mjs";
4
+ import { t as CronBuilder } from "./CronBuilder-CCgt0wCE.mjs";
5
+ import { t as QueueBuilder } from "./QueueBuilder-DCuYdjMw.mjs";
6
+ import { t as SubscriberBuilder } from "./SubscriberBuilder-DMFk_Ap1.mjs";
7
7
  import { canonicalId } from "@geekmidas/manifest";
8
8
  import { DEFAULT_LOGGER } from "@geekmidas/logger/console";
9
9
  //#region src/worker.ts
@@ -17,7 +17,8 @@ var Worker = class Worker {
17
17
  envParser;
18
18
  /**
19
19
  * Where this worker's schedules live, when it has crons and a server runs
20
- * them. `undefined` until `.database(…)` says.
20
+ * them — and the database everything built from it receives as `db`.
21
+ * `undefined` until `.database(…)` says.
21
22
  */
22
23
  scheduleStore;
23
24
  constructor(id, config = {}, dependencies = [], scheduleStore) {
@@ -33,7 +34,10 @@ var Worker = class Worker {
33
34
  this.scheduleStore = scheduleStore;
34
35
  }
35
36
  /**
36
- * The database this worker keeps its schedules in.
37
+ * The database this worker keeps its schedules in, and the one everything
38
+ * built from it — crons, queues, subscribers, functions — receives as `db`.
39
+ * One of them that works against another database names it with its own
40
+ * `.database(other)`, which replaces this one for that runnable alone.
37
41
  *
38
42
  * Only a server target uses it. On AWS a cron is an EventBridge rule
39
43
  * invoking a Lambda and nothing here is consulted — but a server has nothing
@@ -50,6 +54,10 @@ var Worker = class Worker {
50
54
  * @example
51
55
  * ```ts
52
56
  * export const jobs = new Worker('Jobs', { logger }).database(database);
57
+ *
58
+ * export const sweep = jobs
59
+ * .cron('rate(1 hour)')
60
+ * .handle(async ({ db }) => db.deleteFrom('sessions').execute());
53
61
  * ```
54
62
  */
55
63
  database(source) {
@@ -151,12 +159,20 @@ var Worker = class Worker {
151
159
  }
152
160
  /**
153
161
  * Stamps this worker's id onto a builder, so everything built from it says
154
- * which process runs it.
162
+ * which process runs it — and hands it the worker's database.
163
+ *
164
+ * The database goes through the builder's own `.database()` rather than
165
+ * being written into its fields, so the default is recorded exactly as an
166
+ * explicit one would be: the client the handler gets, and the edge the
167
+ * manifest reads. That is also what lets a later `.database(other)` replace
168
+ * it outright. The builder arrives already typed with this worker's
169
+ * database; this is the runtime half of that.
155
170
  */
156
171
  own(builder) {
157
- builder._owner = this.id;
158
- builder._scheduleStore = this.scheduleStore;
159
- return builder;
172
+ const owned = this.scheduleStore ? builder.database(this.scheduleStore) : builder;
173
+ owned._owner = this.id;
174
+ owned._scheduleStore = this.scheduleStore;
175
+ return owned;
160
176
  }
161
177
  declare() {
162
178
  return [{
@@ -1 +1 @@
1
- {"version":3,"file":"worker.mjs","names":[],"sources":["../src/worker.ts"],"sourcesContent":["/**\n * A process with no port.\n *\n * `RestApi` is the process that answers HTTP. This is the one that does not —\n * the thing that runs a schedule, drains a queue, consumes a topic. Until it\n * existed, those had nowhere to say they belonged: a cron declared a schedule\n * and nothing else, and which container ran it was decided by the directory the\n * file sat in. A glob owned it.\n *\n * The cost of that shows up in the scaffolds. `gkm init --template worker` —\n * a project that is background jobs and nothing else — declared\n * `new RestApi('Api', { defaultAuthorizer: 'none', logger })`: an HTTP surface\n * with no HTTP on it, written because it was the only construct that made an\n * app exist and the only way to get a logger into the generated runtime.\n *\n * It takes no authorizer, and that is the tell that these are two constructs\n * rather than one with a flag: a `RestApi` needs one because an HTTP surface\n * can ship open by omission, and nothing reaches a worker from outside.\n *\n * ## Crons on a server target need a database\n *\n * A cron becomes an EventBridge rule on AWS and nothing here is consulted. A\n * server has nothing firing its crons but itself, and a process that schedules\n * in memory fires every job once per replica while reporting success — so the\n * schedule is kept in Postgres, and the worker says which one with\n * `.database(db)`.\n *\n * A worker with crons and no `.database(…)` schedules nothing on a server\n * target and says so at startup. That is a limitation of workers today rather\n * than a design: the store could be a cache, or something the target\n * provisions, and Postgres is what exists.\n *\n * It is not an app. A worker names the process that runs its crons and\n * subscribers, and that process is the app's server — the same one the\n * endpoints run in, minus the HTTP surface. Giving a worker a container of its\n * own made a second thing to build, deploy and keep alive for work that was\n * always going to run somewhere already. Declare as many as the shape of the\n * work wants: they are groupings, not deployments.\n *\n * @example\n * ```ts\n * // constructs/worker.ts\n * import { Worker } from '@geekmidas/constructs/worker';\n * import { logger } from './logger.js';\n *\n * export const worker = new Worker('Worker', { logger }).calls([database]);\n *\n * // crons/cleanup.ts\n * import { worker } from '@acme/constructs/worker.js';\n *\n * export const cleanup = worker\n * .cron('rate(1 day)')\n * .handle(async ({ logger }) => { … });\n * ```\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n} from '@geekmidas/manifest';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n\ttype Consumable,\n\ttype Declarable,\n\tedgeTo,\n} from './construct-interface';\nimport type { ScheduleExpression } from './crons/Cron';\nimport { CronBuilder } from './crons/CronBuilder';\nimport { envParserFor } from './endpoints/surfaceEnv';\nimport { FunctionBuilder } from './functions/FunctionBuilder';\nimport { QueueBuilder } from './queue/QueueBuilder';\nimport { SubscriberBuilder } from './subscribers/SubscriberBuilder';\nimport type { Topic, TopicEvents } from './topic/Topic';\n\nexport interface WorkerConfig {\n\t/**\n\t * The logger everything built from this worker runs with.\n\t *\n\t * The actual logger, not a path to one — the same reason `RestApi` takes\n\t * one. Every cron and subscriber in a scaffolded project used to open with\n\t * `import { logger } from '…/constructs/logger.js'`, which is the line this\n\t * removes.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The environment parser everything built from this worker runs with.\n\t *\n\t * Defaults to `process.env` merged with the credentials `gkm dev` injected,\n\t * which is what an application's own `config/env.ts` always was.\n\t */\n\tenvParser?: EnvironmentParser<{}>;\n}\n\nexport class Worker<TName extends string = string>\n\timplements Declarable<TName>\n{\n\treadonly id: TName;\n\n\t/** Always defined — the worker's own, or the console logger. */\n\treadonly logger: Logger;\n\n\t/** Always defined, and normally the default. */\n\treadonly envParser: EnvironmentParser<{}>;\n\n\t/**\n\t * Where this worker's schedules live, when it has crons and a server runs\n\t * them. `undefined` until `.database(…)` says.\n\t */\n\treadonly scheduleStore?: Consumable<string, unknown>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: WorkerConfig = {},\n\t\t/** Internal: how `.calls()` carries edges into the copy it returns. */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t\tscheduleStore?: Consumable<string, unknown>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.logger = config.logger ?? DEFAULT_LOGGER;\n\t\tthis.envParser = envParserFor(\n\t\t\tconfig.envParser\n\t\t\t\t? { id: canonical, envParser: config.envParser }\n\t\t\t\t: undefined,\n\t\t);\n\t\tthis.scheduleStore = scheduleStore;\n\t}\n\n\t/**\n\t * The database this worker keeps its schedules in.\n\t *\n\t * Only a server target uses it. On AWS a cron is an EventBridge rule\n\t * invoking a Lambda and nothing here is consulted — but a server has nothing\n\t * firing its crons except itself, and a process that schedules in memory\n\t * fires every job once per replica while reporting that all is well.\n\t *\n\t * So the store is declared rather than discovered. It could have been\n\t * inferred — from a database the app happens to declare, or from the events\n\t * backend when that backend is pg-boss — and both would work until an app\n\t * had two databases, or moved its events to SNS, at which point the\n\t * schedules would quietly move or stop. Naming it is one line and cannot\n\t * drift.\n\t *\n\t * @example\n\t * ```ts\n\t * export const jobs = new Worker('Jobs', { logger }).database(database);\n\t * ```\n\t */\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T>,\n\t): Worker<TName> {\n\t\treturn new Worker<TName>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, edgeTo(source)],\n\t\t\tsource as unknown as Consumable<string, unknown>,\n\t\t);\n\t}\n\n\t/**\n\t * A scheduled runnable.\n\t *\n\t * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`\n\t */\n\tcron(schedule: ScheduleExpression) {\n\t\treturn this.own(new CronBuilder().logger(this.logger)).schedule(schedule);\n\t}\n\n\t/**\n\t * A queue and its one consumer, run by this worker.\n\t *\n\t * One construct, because a queue has exactly one consumer: nothing else can\n\t * attach a second, or forget to attach the first. Producers send to it by\n\t * depending on it — `.dependsOn([emails])` makes `services.emails` the\n\t * publisher.\n\t *\n\t * @example\n\t * ```ts\n\t * export const emails = worker\n\t * .queue('Emails')\n\t * .message(z.object({ userId: z.uuid(), template: z.string() }))\n\t * .handle(async ({ messages, services }) => { … });\n\t * ```\n\t */\n\tqueue<TQueueName extends string>(name: TQueueName) {\n\t\treturn this.own(new QueueBuilder().logger(this.logger)).queue(name);\n\t}\n\n\t/**\n\t * A runnable that consumes a topic.\n\t *\n\t * Binding is not publishing: a consumer is handed the topic's event types\n\t * and no connection string it could publish with. A handler that emits\n\t * follow-up events depends on the topic it emits to —\n\t * `.dependsOn([orders])` — which is the only reason it would need one.\n\t *\n\t * @example `worker.topic(users).subscribe(['user.created']).handle(…)`\n\t */\n\ttopic<TTopicName extends string, TEvents extends TopicEvents>(\n\t\ttopic: Topic<TTopicName, TEvents>,\n\t) {\n\t\treturn this.own(new SubscriberBuilder().logger(this.logger)).topic(topic);\n\t}\n\n\t/**\n\t * Everything below builds a function — the runnable with no schedule and no\n\t * topic, invoked by something else.\n\t *\n\t * These sit on the worker rather than behind a `functions` namespace because\n\t * the namespace was a hop that said nothing: `worker.functions.input(…)`\n\t * names a collection to reach one member of it. What kind of runnable is\n\t * being built is decided by which of these is called first — a schedule\n\t * makes a cron, a topic makes a subscriber, and anything else makes a\n\t * function.\n\t */\n\tinput<T extends ComposableStandardSchema>(schema: T) {\n\t\treturn this.functions.input(schema);\n\t}\n\n\toutput<T extends StandardSchemaV1>(schema: T) {\n\t\treturn this.functions.output(schema);\n\t}\n\n\ttimeout(ms: number) {\n\t\treturn this.functions.timeout(ms);\n\t}\n\n\tmemorySize(mb: number) {\n\t\treturn this.functions.memorySize(mb);\n\t}\n\n\tdependsOn<const T extends readonly Consumable[]>(constructs: T) {\n\t\treturn this.functions.dependsOn(constructs);\n\t}\n\n\tservices<T extends Service[]>(services: T) {\n\t\treturn this.functions.services(services);\n\t}\n\n\t/**\n\t * A function with no input schema — the shortest runnable there is.\n\t *\n\t * @example `worker.handle(async ({ logger }) => { … })`\n\t */\n\thandle(\n\t\t...args: Parameters<\n\t\t\tReturnType<Worker<TName>['schemalessFunction']>['handle']\n\t\t>\n\t) {\n\t\treturn this.schemalessFunction().handle(...args);\n\t}\n\n\t/** The builder `handle` delegates to, named so its type can be referred to. */\n\tprivate schemalessFunction() {\n\t\treturn this.functions;\n\t}\n\n\t/** The function builder the delegating methods above are built on. */\n\tprivate get functions() {\n\t\treturn this.own(new FunctionBuilder().logger(this.logger));\n\t}\n\n\t/**\n\t * Resources and surfaces this worker calls.\n\t *\n\t * Not `.dependsOn()`: this records the edge that derives the worker's\n\t * environment and its access, the same distinction `RestApi.calls()` draws.\n\t */\n\tcalls(constructs: readonly Declarable[]): Worker<TName> {\n\t\treturn new Worker<TName>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, ...constructs.map(edgeTo)],\n\t\t\tthis.scheduleStore,\n\t\t);\n\t}\n\n\t/**\n\t * Stamps this worker's id onto a builder, so everything built from it says\n\t * which process runs it.\n\t */\n\tprivate own<T extends { _owner?: string; _scheduleStore?: unknown }>(\n\t\tbuilder: T,\n\t): T {\n\t\tbuilder._owner = this.id;\n\t\tbuilder._scheduleStore = this.scheduleStore;\n\n\t\treturn builder;\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'worker',\n\t\t\t\tid: this.id,\n\t\t\t\t...(this.dependencies.length\n\t\t\t\t\t? { dependencies: this.dependencies }\n\t\t\t\t\t: {}),\n\t\t\t\t// Nothing calls a worker, so it publishes no address.\n\t\t\t\tprovides: [],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;AAqGA,IAAa,SAAb,MAAa,OAEb;CAiBmB;CAEA;CAlBlB;;CAGA;;CAGA;;;;;CAMA;CAEA,YACC,IACA,SAAwC,CAAC,GAEzC,eAAuD,CAAC,GACxD,eACC;EAJgB,KAAA,SAAA;EAEA,KAAA,eAAA;EAGjB,MAAM,YAAY,YAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,SAAS,OAAO,UAAU;EAC/B,KAAK,YAAY,aAChB,OAAO,YACJ;GAAE,IAAI;GAAW,WAAW,OAAO;EAAU,IAC7C,KAAA,CACJ;EACA,KAAK,gBAAgB;CACtB;;;;;;;;;;;;;;;;;;;;;CAsBA,SACC,QACgB;EAChB,OAAO,IAAI,OACV,KAAK,IACL,KAAK,QACL,CAAC,GAAG,KAAK,cAAc,OAAO,MAAM,CAAC,GACrC,MACD;CACD;;;;;;CAOA,KAAK,UAA8B;EAClC,OAAO,KAAK,IAAI,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,QAAQ;CACzE;;;;;;;;;;;;;;;;;CAkBA,MAAiC,MAAkB;EAClD,OAAO,KAAK,IAAI,IAAI,aAAa,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,IAAI;CACnE;;;;;;;;;;;CAYA,MACC,OACC;EACD,OAAO,KAAK,IAAI,IAAI,kBAAkB,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,KAAK;CACzE;;;;;;;;;;;;CAaA,MAA0C,QAAW;EACpD,OAAO,KAAK,UAAU,MAAM,MAAM;CACnC;CAEA,OAAmC,QAAW;EAC7C,OAAO,KAAK,UAAU,OAAO,MAAM;CACpC;CAEA,QAAQ,IAAY;EACnB,OAAO,KAAK,UAAU,QAAQ,EAAE;CACjC;CAEA,WAAW,IAAY;EACtB,OAAO,KAAK,UAAU,WAAW,EAAE;CACpC;CAEA,UAAiD,YAAe;EAC/D,OAAO,KAAK,UAAU,UAAU,UAAU;CAC3C;CAEA,SAA8B,UAAa;EAC1C,OAAO,KAAK,UAAU,SAAS,QAAQ;CACxC;;;;;;CAOA,OACC,GAAG,MAGF;EACD,OAAO,KAAK,mBAAmB,CAAC,CAAC,OAAO,GAAG,IAAI;CAChD;;CAGA,qBAA6B;EAC5B,OAAO,KAAK;CACb;;CAGA,IAAY,YAAY;EACvB,OAAO,KAAK,IAAI,IAAI,gBAAgB,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC;CAC1D;;;;;;;CAQA,MAAM,YAAkD;EACvD,OAAO,IAAI,OACV,KAAK,IACL,KAAK,QACL,CAAC,GAAG,KAAK,cAAc,GAAG,WAAW,IAAI,MAAM,CAAC,GAChD,KAAK,aACN;CACD;;;;;CAMA,IACC,SACI;EACJ,QAAQ,SAAS,KAAK;EACtB,QAAQ,iBAAiB,KAAK;EAE9B,OAAO;CACR;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,GAAI,KAAK,aAAa,SACnB,EAAE,cAAc,KAAK,aAAa,IAClC,CAAC;GAEJ,UAAU,CAAC;EACZ,CACD;CACD;AACD"}
1
+ {"version":3,"file":"worker.mjs","names":[],"sources":["../src/worker.ts"],"sourcesContent":["/**\n * A process with no port.\n *\n * `RestApi` is the process that answers HTTP. This is the one that does not —\n * the thing that runs a schedule, drains a queue, consumes a topic. Until it\n * existed, those had nowhere to say they belonged: a cron declared a schedule\n * and nothing else, and which container ran it was decided by the directory the\n * file sat in. A glob owned it.\n *\n * The cost of that shows up in the scaffolds. `gkm init --template worker` —\n * a project that is background jobs and nothing else — declared\n * `new RestApi('Api', { defaultAuthorizer: 'none', logger })`: an HTTP surface\n * with no HTTP on it, written because it was the only construct that made an\n * app exist and the only way to get a logger into the generated runtime.\n *\n * It takes no authorizer, and that is the tell that these are two constructs\n * rather than one with a flag: a `RestApi` needs one because an HTTP surface\n * can ship open by omission, and nothing reaches a worker from outside.\n *\n * ## Crons on a server target need a database\n *\n * A cron becomes an EventBridge rule on AWS and nothing here is consulted. A\n * server has nothing firing its crons but itself, and a process that schedules\n * in memory fires every job once per replica while reporting success — so the\n * schedule is kept in Postgres, and the worker says which one with\n * `.database(db)`.\n *\n * A worker with crons and no `.database(…)` schedules nothing on a server\n * target and says so at startup. That is a limitation of workers today rather\n * than a design: the store could be a cache, or something the target\n * provisions, and Postgres is what exists.\n *\n * ## The database is everything's default\n *\n * The same `.database(db)` is the database every cron, queue, subscriber and\n * function built from the worker receives as `db`. The work a worker groups is\n * usually work against one database, and naming it per handler was a line\n * repeated in every file that could drift in any one of them. A runnable that\n * works against another names its own with `.database(other)`, which replaces\n * the worker's — client and manifest edge both — rather than adding to it.\n *\n * It is not an app. A worker names the process that runs its crons and\n * subscribers, and that process is the app's server — the same one the\n * endpoints run in, minus the HTTP surface. Giving a worker a container of its\n * own made a second thing to build, deploy and keep alive for work that was\n * always going to run somewhere already. Declare as many as the shape of the\n * work wants: they are groupings, not deployments.\n *\n * @example\n * ```ts\n * // constructs/worker.ts\n * import { Worker } from '@geekmidas/constructs/worker';\n * import { logger } from './logger.js';\n *\n * export const worker = new Worker('Worker', { logger }).database(database);\n *\n * // crons/cleanup.ts\n * import { worker } from '@acme/constructs/worker.js';\n *\n * export const cleanup = worker\n * .cron('rate(1 day)')\n * .handle(async ({ db, logger }) => { … });\n *\n * // queues/reports.ts — against another database than the worker's\n * export const reports = worker\n * .queue('Reports')\n * .database(analytics)\n * .message(z.object({ id: z.uuid() }))\n * .handle(async ({ messages, db }) => { … });\n * ```\n */\n\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport { DEFAULT_LOGGER } from '@geekmidas/logger/console';\nimport {\n\ttype ConstructName,\n\tcanonicalId,\n\ttype Declaration,\n\ttype Dependency,\n} from '@geekmidas/manifest';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n\ttype Consumable,\n\ttype Declarable,\n\tedgeTo,\n} from './construct-interface';\nimport type { ScheduleExpression } from './crons/Cron';\nimport { CronBuilder } from './crons/CronBuilder';\nimport { envParserFor } from './endpoints/surfaceEnv';\nimport { FunctionBuilder } from './functions/FunctionBuilder';\nimport { QueueBuilder } from './queue/QueueBuilder';\nimport { SubscriberBuilder } from './subscribers/SubscriberBuilder';\nimport type { Topic, TopicEvents } from './topic/Topic';\n\nexport interface WorkerConfig {\n\t/**\n\t * The logger everything built from this worker runs with.\n\t *\n\t * The actual logger, not a path to one — the same reason `RestApi` takes\n\t * one. Every cron and subscriber in a scaffolded project used to open with\n\t * `import { logger } from '…/constructs/logger.js'`, which is the line this\n\t * removes.\n\t */\n\tlogger?: Logger;\n\t/**\n\t * The environment parser everything built from this worker runs with.\n\t *\n\t * Defaults to `process.env` merged with the credentials `gkm dev` injected,\n\t * which is what an application's own `config/env.ts` always was.\n\t */\n\tenvParser?: EnvironmentParser<{}>;\n}\n\nexport class Worker<\n\tTName extends string = string,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> implements Declarable<TName>\n{\n\treadonly id: TName;\n\n\t/** Always defined — the worker's own, or the console logger. */\n\treadonly logger: Logger;\n\n\t/** Always defined, and normally the default. */\n\treadonly envParser: EnvironmentParser<{}>;\n\n\t/**\n\t * Where this worker's schedules live, when it has crons and a server runs\n\t * them — and the database everything built from it receives as `db`.\n\t * `undefined` until `.database(…)` says.\n\t */\n\treadonly scheduleStore?: Consumable<string, unknown>;\n\n\tconstructor(\n\t\tid: ConstructName<TName>,\n\t\tprivate readonly config: WorkerConfig = {},\n\t\t/** Internal: how `.calls()` carries edges into the copy it returns. */\n\t\tprivate readonly dependencies: readonly Dependency[] = [],\n\t\tscheduleStore?: Consumable<string, unknown>,\n\t) {\n\t\tconst canonical = canonicalId(id as string);\n\n\t\tthis.id = canonical as TName;\n\t\tthis.logger = config.logger ?? DEFAULT_LOGGER;\n\t\tthis.envParser = envParserFor(\n\t\t\tconfig.envParser\n\t\t\t\t? { id: canonical, envParser: config.envParser }\n\t\t\t\t: undefined,\n\t\t);\n\t\tthis.scheduleStore = scheduleStore;\n\t}\n\n\t/**\n\t * The database this worker keeps its schedules in, and the one everything\n\t * built from it — crons, queues, subscribers, functions — receives as `db`.\n\t * One of them that works against another database names it with its own\n\t * `.database(other)`, which replaces this one for that runnable alone.\n\t *\n\t * Only a server target uses it. On AWS a cron is an EventBridge rule\n\t * invoking a Lambda and nothing here is consulted — but a server has nothing\n\t * firing its crons except itself, and a process that schedules in memory\n\t * fires every job once per replica while reporting that all is well.\n\t *\n\t * So the store is declared rather than discovered. It could have been\n\t * inferred — from a database the app happens to declare, or from the events\n\t * backend when that backend is pg-boss — and both would work until an app\n\t * had two databases, or moved its events to SNS, at which point the\n\t * schedules would quietly move or stop. Naming it is one line and cannot\n\t * drift.\n\t *\n\t * @example\n\t * ```ts\n\t * export const jobs = new Worker('Jobs', { logger }).database(database);\n\t *\n\t * export const sweep = jobs\n\t * .cron('rate(1 hour)')\n\t * .handle(async ({ db }) => db.deleteFrom('sessions').execute());\n\t * ```\n\t */\n\tdatabase<T, TDbName extends string>(\n\t\tsource: Consumable<TDbName, T>,\n\t): Worker<TName, T, TDbName> {\n\t\treturn new Worker<TName, T, TDbName>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, edgeTo(source)],\n\t\t\tsource as unknown as Consumable<string, unknown>,\n\t\t);\n\t}\n\n\t/**\n\t * A scheduled runnable.\n\t *\n\t * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`\n\t */\n\tcron(schedule: ScheduleExpression) {\n\t\treturn this.own(\n\t\t\tnew CronBuilder<\n\t\t\t\tComposableStandardSchema,\n\t\t\t\tService[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).schedule(schedule);\n\t}\n\n\t/**\n\t * A queue and its one consumer, run by this worker.\n\t *\n\t * One construct, because a queue has exactly one consumer: nothing else can\n\t * attach a second, or forget to attach the first. Producers send to it by\n\t * depending on it — `.dependsOn([emails])` makes `services.emails` the\n\t * publisher.\n\t *\n\t * @example\n\t * ```ts\n\t * export const emails = worker\n\t * .queue('Emails')\n\t * .message(z.object({ userId: z.uuid(), template: z.string() }))\n\t * .handle(async ({ messages, services }) => { … });\n\t * ```\n\t */\n\tqueue<TQueueName extends string>(name: TQueueName) {\n\t\treturn this.own(\n\t\t\tnew QueueBuilder<\n\t\t\t\tstring,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).queue(name);\n\t}\n\n\t/**\n\t * A runnable that consumes a topic.\n\t *\n\t * Binding is not publishing: a consumer is handed the topic's event types\n\t * and no connection string it could publish with. A handler that emits\n\t * follow-up events depends on the topic it emits to —\n\t * `.dependsOn([orders])` — which is the only reason it would need one.\n\t *\n\t * @example `worker.topic(users).subscribe(['user.created']).handle(…)`\n\t */\n\ttopic<TTopicName extends string, TEvents extends TopicEvents>(\n\t\ttopic: Topic<TTopicName, TEvents>,\n\t) {\n\t\treturn this.own(\n\t\t\tnew SubscriberBuilder<\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t).topic(topic);\n\t}\n\n\t/**\n\t * Everything below builds a function — the runnable with no schedule and no\n\t * topic, invoked by something else.\n\t *\n\t * These sit on the worker rather than behind a `functions` namespace because\n\t * the namespace was a hop that said nothing: `worker.functions.input(…)`\n\t * names a collection to reach one member of it. What kind of runnable is\n\t * being built is decided by which of these is called first — a schedule\n\t * makes a cron, a topic makes a subscriber, and anything else makes a\n\t * function.\n\t */\n\tinput<T extends ComposableStandardSchema>(schema: T) {\n\t\treturn this.functions.input(schema);\n\t}\n\n\toutput<T extends StandardSchemaV1>(schema: T) {\n\t\treturn this.functions.output(schema);\n\t}\n\n\ttimeout(ms: number) {\n\t\treturn this.functions.timeout(ms);\n\t}\n\n\tmemorySize(mb: number) {\n\t\treturn this.functions.memorySize(mb);\n\t}\n\n\tdependsOn<const T extends readonly Consumable[]>(constructs: T) {\n\t\treturn this.functions.dependsOn(constructs);\n\t}\n\n\tservices<T extends Service[]>(services: T) {\n\t\treturn this.functions.services(services);\n\t}\n\n\t/**\n\t * A function with no input schema — the shortest runnable there is.\n\t *\n\t * @example `worker.handle(async ({ logger }) => { … })`\n\t */\n\thandle(\n\t\t...args: Parameters<\n\t\t\tReturnType<\n\t\t\t\tWorker<TName, TDatabase, TDatabaseServiceName>['schemalessFunction']\n\t\t\t>['handle']\n\t\t>\n\t) {\n\t\treturn this.schemalessFunction().handle(...args);\n\t}\n\n\t/** The builder `handle` delegates to, named so its type can be referred to. */\n\tprivate schemalessFunction() {\n\t\treturn this.functions;\n\t}\n\n\t/** The function builder the delegating methods above are built on. */\n\tprivate get functions() {\n\t\treturn this.own(\n\t\t\tnew FunctionBuilder<\n\t\t\t\tany,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\tLogger,\n\t\t\t\tundefined,\n\t\t\t\tstring,\n\t\t\t\tTDatabase,\n\t\t\t\tTDatabaseServiceName\n\t\t\t>().logger(this.logger),\n\t\t);\n\t}\n\n\t/**\n\t * Resources and surfaces this worker calls.\n\t *\n\t * Not `.dependsOn()`: this records the edge that derives the worker's\n\t * environment and its access, the same distinction `RestApi.calls()` draws.\n\t */\n\tcalls(\n\t\tconstructs: readonly Declarable[],\n\t): Worker<TName, TDatabase, TDatabaseServiceName> {\n\t\treturn new Worker<TName, TDatabase, TDatabaseServiceName>(\n\t\t\tthis.id as ConstructName<TName>,\n\t\t\tthis.config,\n\t\t\t[...this.dependencies, ...constructs.map(edgeTo)],\n\t\t\tthis.scheduleStore,\n\t\t);\n\t}\n\n\t/**\n\t * Stamps this worker's id onto a builder, so everything built from it says\n\t * which process runs it — and hands it the worker's database.\n\t *\n\t * The database goes through the builder's own `.database()` rather than\n\t * being written into its fields, so the default is recorded exactly as an\n\t * explicit one would be: the client the handler gets, and the edge the\n\t * manifest reads. That is also what lets a later `.database(other)` replace\n\t * it outright. The builder arrives already typed with this worker's\n\t * database; this is the runtime half of that.\n\t */\n\tprivate own<\n\t\tT extends {\n\t\t\t_owner?: string;\n\t\t\t_scheduleStore?: unknown;\n\t\t\tdatabase(source: Consumable<string, unknown>): unknown;\n\t\t},\n\t>(builder: T): T {\n\t\tconst owned = this.scheduleStore\n\t\t\t? (builder.database(this.scheduleStore) as T)\n\t\t\t: builder;\n\n\t\towned._owner = this.id;\n\t\towned._scheduleStore = this.scheduleStore;\n\n\t\treturn owned;\n\t}\n\n\tdeclare(): Declaration[] {\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: 'worker',\n\t\t\t\tid: this.id,\n\t\t\t\t...(this.dependencies.length\n\t\t\t\t\t? { dependencies: this.dependencies }\n\t\t\t\t\t: {}),\n\t\t\t\t// Nothing calls a worker, so it publishes no address.\n\t\t\t\tprovides: [],\n\t\t\t},\n\t\t];\n\t}\n}\n"],"mappings":";;;;;;;;;AAqHA,IAAa,SAAb,MAAa,OAKb;CAkBmB;CAEA;CAnBlB;;CAGA;;CAGA;;;;;;CAOA;CAEA,YACC,IACA,SAAwC,CAAC,GAEzC,eAAuD,CAAC,GACxD,eACC;EAJgB,KAAA,SAAA;EAEA,KAAA,eAAA;EAGjB,MAAM,YAAY,YAAY,EAAY;EAE1C,KAAK,KAAK;EACV,KAAK,SAAS,OAAO,UAAU;EAC/B,KAAK,YAAY,aAChB,OAAO,YACJ;GAAE,IAAI;GAAW,WAAW,OAAO;EAAU,IAC7C,KAAA,CACJ;EACA,KAAK,gBAAgB;CACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BA,SACC,QAC4B;EAC5B,OAAO,IAAI,OACV,KAAK,IACL,KAAK,QACL,CAAC,GAAG,KAAK,cAAc,OAAO,MAAM,CAAC,GACrC,MACD;CACD;;;;;;CAOA,KAAK,UAA8B;EAClC,OAAO,KAAK,IACX,IAAI,YAOF,CAAC,CAAC,OAAO,KAAK,MAAM,CACvB,CAAC,CAAC,SAAS,QAAQ;CACpB;;;;;;;;;;;;;;;;;CAkBA,MAAiC,MAAkB;EAClD,OAAO,KAAK,IACX,IAAI,aAOF,CAAC,CAAC,OAAO,KAAK,MAAM,CACvB,CAAC,CAAC,MAAM,IAAI;CACb;;;;;;;;;;;CAYA,MACC,OACC;EACD,OAAO,KAAK,IACX,IAAI,kBAQF,CAAC,CAAC,OAAO,KAAK,MAAM,CACvB,CAAC,CAAC,MAAM,KAAK;CACd;;;;;;;;;;;;CAaA,MAA0C,QAAW;EACpD,OAAO,KAAK,UAAU,MAAM,MAAM;CACnC;CAEA,OAAmC,QAAW;EAC7C,OAAO,KAAK,UAAU,OAAO,MAAM;CACpC;CAEA,QAAQ,IAAY;EACnB,OAAO,KAAK,UAAU,QAAQ,EAAE;CACjC;CAEA,WAAW,IAAY;EACtB,OAAO,KAAK,UAAU,WAAW,EAAE;CACpC;CAEA,UAAiD,YAAe;EAC/D,OAAO,KAAK,UAAU,UAAU,UAAU;CAC3C;CAEA,SAA8B,UAAa;EAC1C,OAAO,KAAK,UAAU,SAAS,QAAQ;CACxC;;;;;;CAOA,OACC,GAAG,MAKF;EACD,OAAO,KAAK,mBAAmB,CAAC,CAAC,OAAO,GAAG,IAAI;CAChD;;CAGA,qBAA6B;EAC5B,OAAO,KAAK;CACb;;CAGA,IAAY,YAAY;EACvB,OAAO,KAAK,IACX,IAAI,gBASF,CAAC,CAAC,OAAO,KAAK,MAAM,CACvB;CACD;;;;;;;CAQA,MACC,YACiD;EACjD,OAAO,IAAI,OACV,KAAK,IACL,KAAK,QACL,CAAC,GAAG,KAAK,cAAc,GAAG,WAAW,IAAI,MAAM,CAAC,GAChD,KAAK,aACN;CACD;;;;;;;;;;;;CAaA,IAME,SAAe;EAChB,MAAM,QAAQ,KAAK,gBACf,QAAQ,SAAS,KAAK,aAAa,IACpC;EAEH,MAAM,SAAS,KAAK;EACpB,MAAM,iBAAiB,KAAK;EAE5B,OAAO;CACR;CAEA,UAAyB;EACxB,OAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,GAAI,KAAK,aAAa,SACnB,EAAE,cAAc,KAAK,aAAa,IAClC,CAAC;GAEJ,UAAU,CAAC;EACZ,CACD;CACD;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/constructs",
3
- "version": "10.0.0-alpha.41",
3
+ "version": "10.0.0-alpha.43",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -265,13 +265,13 @@
265
265
  "lodash.uniqby": "~4.7.0",
266
266
  "openapi-types": "~12.1.3",
267
267
  "qs": "~6.16.0",
268
- "@geekmidas/envkit": "^10.0.0-alpha.41",
269
- "@geekmidas/errors": "^10.0.0-alpha.41",
270
- "@geekmidas/events": "^10.0.0-alpha.41",
271
- "@geekmidas/logger": "^10.0.0-alpha.41",
272
- "@geekmidas/schema": "^10.0.0-alpha.41",
273
- "@geekmidas/services": "^10.0.0-alpha.41",
274
- "@geekmidas/manifest": "^10.0.0-alpha.41"
268
+ "@geekmidas/envkit": "^10.0.0-alpha.43",
269
+ "@geekmidas/errors": "^10.0.0-alpha.43",
270
+ "@geekmidas/events": "^10.0.0-alpha.43",
271
+ "@geekmidas/logger": "^10.0.0-alpha.43",
272
+ "@geekmidas/manifest": "^10.0.0-alpha.43",
273
+ "@geekmidas/schema": "^10.0.0-alpha.43",
274
+ "@geekmidas/services": "^10.0.0-alpha.43"
275
275
  },
276
276
  "devDependencies": {
277
277
  "@better-auth/expo": "~1.7.6",
@@ -287,20 +287,20 @@
287
287
  "msw": "~2.15.0",
288
288
  "pg": "~8.23.0",
289
289
  "zod": "~4.6.5",
290
- "@geekmidas/audit": "^10.0.0-alpha.41",
291
- "@geekmidas/auth": "10.0.0-alpha.41",
292
- "@geekmidas/cache": "^10.0.0-alpha.41",
293
- "@geekmidas/db": "^10.0.0-alpha.41",
294
- "@geekmidas/emailkit": "^10.0.0-alpha.41",
295
- "@geekmidas/envkit": "^10.0.0-alpha.41",
296
- "@geekmidas/errors": "^10.0.0-alpha.41",
297
- "@geekmidas/events": "^10.0.0-alpha.41",
298
- "@geekmidas/logger": "^10.0.0-alpha.41",
299
- "@geekmidas/rate-limit": "^10.0.0-alpha.41",
300
- "@geekmidas/schema": "^10.0.0-alpha.41",
301
- "@geekmidas/services": "^10.0.0-alpha.41",
302
- "@geekmidas/telescope": "10.0.0-alpha.41",
303
- "@geekmidas/testkit": "^10.0.0-alpha.41"
290
+ "@geekmidas/audit": "^10.0.0-alpha.43",
291
+ "@geekmidas/auth": "10.0.0-alpha.43",
292
+ "@geekmidas/cache": "^10.0.0-alpha.43",
293
+ "@geekmidas/db": "^10.0.0-alpha.43",
294
+ "@geekmidas/emailkit": "^10.0.0-alpha.43",
295
+ "@geekmidas/envkit": "^10.0.0-alpha.43",
296
+ "@geekmidas/errors": "^10.0.0-alpha.43",
297
+ "@geekmidas/events": "^10.0.0-alpha.43",
298
+ "@geekmidas/logger": "^10.0.0-alpha.43",
299
+ "@geekmidas/rate-limit": "^10.0.0-alpha.43",
300
+ "@geekmidas/schema": "^10.0.0-alpha.43",
301
+ "@geekmidas/services": "^10.0.0-alpha.43",
302
+ "@geekmidas/telescope": "10.0.0-alpha.43",
303
+ "@geekmidas/testkit": "^10.0.0-alpha.43"
304
304
  },
305
305
  "peerDependencies": {
306
306
  "@middy/core": ">=7.9.2",
@@ -310,15 +310,15 @@
310
310
  "kysely": "~0.29.6",
311
311
  "msw": ">=2.15.0",
312
312
  "pg": ">=8.23.0",
313
- "@geekmidas/audit": "^10.0.0-alpha.41",
314
- "@geekmidas/auth": "10.0.0-alpha.41",
315
- "@geekmidas/cache": "^10.0.0-alpha.41",
316
- "@geekmidas/rate-limit": "^10.0.0-alpha.41",
317
- "@geekmidas/db": "^10.0.0-alpha.41",
318
- "@geekmidas/emailkit": "^10.0.0-alpha.41",
319
- "@geekmidas/storage": "^10.0.0-alpha.41",
320
- "@geekmidas/testkit": "^10.0.0-alpha.41",
321
- "@geekmidas/telescope": "10.0.0-alpha.41"
313
+ "@geekmidas/audit": "^10.0.0-alpha.43",
314
+ "@geekmidas/auth": "10.0.0-alpha.43",
315
+ "@geekmidas/cache": "^10.0.0-alpha.43",
316
+ "@geekmidas/db": "^10.0.0-alpha.43",
317
+ "@geekmidas/emailkit": "^10.0.0-alpha.43",
318
+ "@geekmidas/rate-limit": "^10.0.0-alpha.43",
319
+ "@geekmidas/storage": "^10.0.0-alpha.43",
320
+ "@geekmidas/telescope": "10.0.0-alpha.43",
321
+ "@geekmidas/testkit": "^10.0.0-alpha.43"
322
322
  },
323
323
  "peerDependenciesMeta": {
324
324
  "@geekmidas/audit": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"Cron-CMEGfRs8.d.cts","names":[],"sources":["../src/crons/Cron.ts"],"mappings":";;;;;;;;cAUa,KACZ,eAAe,kDACf,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,uBACA,sDACS,SACT,QACA,WACA,SACA,8BAGA,WACA,sBACA,kCACA,gBAAgB,QAAQ,WAAW,SAAS,WAAW;YA0B5C,YAAY;;;;;;;;;;;;EAbvB,gBAAgB;SAET,OAAO,WAAW,OAAO;EAQhC,YACC,IAAI,gBAAgB,QAAQ,WAAW,SAAS,WAAW,YAC3D,kBACU,YAAY,gCACtB,QAAQ,QACR,eAAe,WACf,WAAU,WACV,SAAS,SAET;;EAAA,SAAQ,cACR,qBACA,kBAAkB,QAAQ,sBAAsB,YAKhD;;;;;EAAA;MAkBG,YAAY;;KAKL;KAEP;KAUA;KAUA;KAUA;KAqBA;KAiBO,yBACH,cAAc,YAAY,WAAW,aAAa;KAE/C,qBAAqB,iBAAiB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Cron-D6X4-xjB.d.mts","names":[],"sources":["../src/crons/Cron.ts"],"mappings":";;;;;;;;cAUa,KACZ,eAAe,kDACf,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,uBACA,sDACS,SACT,QACA,WACA,SACA,8BAGA,WACA,sBACA,kCACA,gBAAgB,QAAQ,WAAW,SAAS,WAAW;YA0B5C,YAAY;;;;;;;;;;;;EAbvB,gBAAgB;SAET,OAAO,WAAW,OAAO;EAQhC,YACC,IAAI,gBAAgB,QAAQ,WAAW,SAAS,WAAW,YAC3D,kBACU,YAAY,gCACtB,QAAQ,QACR,eAAe,WACf,WAAU,WACV,SAAS,SAET;;EAAA,SAAQ,cACR,qBACA,kBAAkB,QAAQ,sBAAsB,YAKhD;;;;;EAAA;MAkBG,YAAY;;KAKL;KAEP;KAUA;KAUA;KAUA;KAqBA;KAiBO,yBACH,cAAc,YAAY,WAAW,aAAa;KAE/C,qBAAqB,iBAAiB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"CronBuilder-CEK7aOqD.d.cts","names":[],"sources":["../src/crons/CronBuilder.ts"],"mappings":";;;;;;;;;cAuBa,YACZ,eAAe,0BACf,kBAAkB,WAClB,gBAAgB,SAAS,QACzB,kBAAkB,0CAClB,uBACA,sDACS,gBACT,QACA,WACA,WACA,4BAGA,WACA;UAEQ;EAER;EAIS,WAAW;EAIpB,SACC,aAAa,qBACX,YACF,QACA,WACA,SACA,WACA,WACA;EAKQ,MAAM,UAAU,0BACxB,QAAQ,IACN,YACF,GACA,WACA,SACA,WACA,WACA;EAcQ,OAAO,UAAU,kBACzB,QAAQ,IACN,YACF,QACA,WACA,SACA,GACA,WACA;;;;;;;;;;;;EAyBQ,gBAAgB,mBAAmB,cAC3C,YAAY,IACV,YACF,YACI,cAAc,WAAW,KAC7B,SACA,WACA,WACA;EA2BQ,SAAS,UAAU,WAC3B,UAAU,IACR,YACF,YACI,cAAc,IAClB,SACA,WACA,WACA;EAiBQ,OAAO,UAAU,QACzB,QAAQ,IACN,YACF,QACA,WACA,GACA,WACA,WACA;;;;;;EAmBQ,MAAM,eAAe,iBAC7B,OAAO,QACP,OAAO,SAAS,QAAQ,oBAAoB,cAC1C,YACF,YACI,WAAW,oBACf,SACA,WACA,WACA;;;;;EAgBQ,SAAS,GAAG,sBACpB,QAAQ,WAAW,OAAO,KAAK,QAAQ,OAAO,KAC5C,YAAY,QAAQ,WAAW,SAAS,WAAW,GAAG;EAsBhD,OACR,IAAI,gBAAgB,QAAQ,WAAW,SAAS,WAAW,aACzD,KACF,QACA,WACA,SACA,WACA,WACA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"CronBuilder-DB35T5dL.cjs","names":["Function","FunctionBuilder","cloneWith","servicesOf","uniqBy","idsOf","serviceOf","isConsumable"],"sources":["../src/crons/Cron.ts","../src/crons/CronBuilder.ts"],"sourcesContent":["import type { AuditableAction } from '@geekmidas/audit';\nimport type { EventPublisher } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { ComposableStandardSchema } from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { ConstructType } from '../Construct';\nimport { Function, type FunctionHandler } from '../functions';\nimport type { TopicEvent } from '../publisher';\n\nexport class Cron<\n\tTInput extends ComposableStandardSchema | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> extends Function<\n\tTInput,\n\tTServices,\n\tTLogger,\n\tOutSchema,\n\tundefined,\n\tstring,\n\tTDatabase,\n\tTDatabaseServiceName,\n\tAuditableAction<string, unknown>,\n\tFunctionHandler<TInput, TServices, TLogger, OutSchema, TDatabase>\n> {\n\t/**\n\t * Where this cron's schedule lives when a server runs it.\n\t *\n\t * Carried from the worker that built it, which declared it once with\n\t * `.database(db)`. Unread on AWS, where the schedule is an EventBridge rule\n\t * and nothing in this process fires anything.\n\t *\n\t * A service rather than the construct, because what reads it is service\n\t * discovery in the generated server — which registers services, and failed\n\t * on the construct with `service.register is not a function`.\n\t */\n\tscheduleStore?: Service<string, unknown>;\n\n\tstatic isCron(obj: any): obj is Cron<any, any, any, any> {\n\t\treturn Boolean(\n\t\t\tobj &&\n\t\t\t\t(obj as Function).__IS_FUNCTION__ === true &&\n\t\t\t\tobj.type === ConstructType.Cron,\n\t\t);\n\t}\n\n\tconstructor(\n\t\tfn: FunctionHandler<TInput, TServices, TLogger, OutSchema, TDatabase>,\n\t\ttimeout?: number,\n\t\tprotected _schedule?: ScheduleExpression,\n\t\tinput?: TInput,\n\t\toutputSchema?: OutSchema,\n\t\tservices: TServices = [] as unknown as TServices,\n\t\tlogger?: TLogger,\n\t\t/** What it publishes once it has run, each to its own topic. */\n\t\tevents: TopicEvent[] = [],\n\t\tmemorySize?: number,\n\t\tdatabaseService?: Service<TDatabaseServiceName, TDatabase>,\n\t\t/**\n\t\t * The construct ids `.dependsOn()` named — last, so no existing positional\n\t\t * argument moves.\n\t\t */\n\t\tconstructs: string[] = [],\n\t) {\n\t\tsuper(\n\t\t\tfn,\n\t\t\ttimeout,\n\t\t\tConstructType.Cron,\n\t\t\tinput,\n\t\t\toutputSchema,\n\t\t\tservices,\n\t\t\tlogger,\n\t\t\tevents,\n\t\t\tmemorySize,\n\t\t\tundefined, // auditorStorageService\n\t\t\tdatabaseService,\n\t\t\tconstructs,\n\t\t);\n\t}\n\n\tget schedule(): ScheduleExpression | undefined {\n\t\treturn this._schedule;\n\t}\n}\n\nexport type RateExpression = `rate(${string})`;\n\ntype CronMinute =\n\t| '*'\n\t| number\n\t| `${number}`\n\t| `${number}-${number}`\n\t| `${number}/${number}`\n\t| `*/${number}`\n\t| `${number},${number}`\n\t| string; // Allow more complex patterns\n\ntype CronHour =\n\t| '*'\n\t| number\n\t| `${number}`\n\t| `${number}-${number}`\n\t| `${number}/${number}`\n\t| `*/${number}`\n\t| `${number},${number}`\n\t| string; // Allow more complex patterns\n\ntype CronDay =\n\t| '*'\n\t| number\n\t| `${number}`\n\t| `${number}-${number}`\n\t| `${number}/${number}`\n\t| `*/${number}`\n\t| `${number},${number}`\n\t| string; // Allow more complex patterns\n\ntype CronMonth =\n\t| '*'\n\t| number\n\t| `${number}`\n\t| `${number}-${number}`\n\t| `${number}/${number}`\n\t| `*/${number}`\n\t| 'JAN'\n\t| 'FEB'\n\t| 'MAR'\n\t| 'APR'\n\t| 'MAY'\n\t| 'JUN'\n\t| 'JUL'\n\t| 'AUG'\n\t| 'SEP'\n\t| 'OCT'\n\t| 'NOV'\n\t| 'DEC'\n\t| string; // Allow more complex patterns\n\ntype CronWeekday =\n\t| '*'\n\t| number\n\t| `${number}`\n\t| `${number}-${number}`\n\t| `${number}/${number}`\n\t| `*/${number}`\n\t| 'SUN'\n\t| 'MON'\n\t| 'TUE'\n\t| 'WED'\n\t| 'THU'\n\t| 'FRI'\n\t| 'SAT'\n\t| `${string}-${string}` // Allow patterns like MON-FRI\n\t| string; // Allow more complex patterns\n\nexport type CronExpression =\n\t`cron(${CronMinute} ${CronHour} ${CronDay} ${CronMonth} ${CronWeekday})`;\n\nexport type ScheduleExpression = RateExpression | CronExpression;\n","import type { Logger } from '@geekmidas/logger';\nimport type {\n\tComposableStandardSchema,\n\tInferStandardSchema,\n} from '@geekmidas/schema';\nimport type { Service } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport uniqBy from 'lodash.uniqby';\nimport { ConstructType } from '../Construct';\nimport { cloneWith } from '../clone';\nimport {\n\ttype Consumable,\n\tidsOf,\n\tisConsumable,\n\ttype ServicesOf,\n\tserviceOf,\n\tservicesOf,\n} from '../construct-interface';\nimport { FunctionBuilder, type FunctionHandler } from '../functions';\nimport type { EventFor } from '../publisher';\nimport type { Topic } from '../topic/Topic';\nimport { Cron, type ScheduleExpression } from './Cron';\n\nexport class CronBuilder<\n\tTInput extends ComposableStandardSchema,\n\tTServices extends Service[],\n\tTLogger extends Logger = Logger,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTDatabase = undefined,\n\tTDatabaseServiceName extends string = string,\n> extends FunctionBuilder<\n\tTInput,\n\tOutSchema,\n\tTServices,\n\tTLogger,\n\tundefined,\n\tstring,\n\tTDatabase,\n\tTDatabaseServiceName\n> {\n\tprivate _schedule?: ScheduleExpression;\n\n\tconstructor() {\n\t\tsuper(ConstructType.Cron);\n\t}\n\n\toverride memorySize(memorySize: number): this {\n\t\treturn cloneWith(this, { _memorySize: memorySize });\n\t}\n\n\tschedule(\n\t\t_expression: ScheduleExpression,\n\t): CronBuilder<\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn cloneWith(this, { _schedule: _expression });\n\t}\n\n\toverride input<T extends ComposableStandardSchema>(\n\t\tschema: T,\n\t): CronBuilder<\n\t\tT,\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn cloneWith(this, {\n\t\t\tinputSchema: schema as unknown as TInput,\n\t\t}) as unknown as CronBuilder<\n\t\t\tT,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t}\n\n\toverride output<T extends StandardSchemaV1>(\n\t\tschema: T,\n\t): CronBuilder<\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tT,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn cloneWith(this, {\n\t\t\toutputSchema: schema as unknown as OutSchema,\n\t\t}) as unknown as CronBuilder<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tT,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t}\n\n\t/**\n\t * Depend on constructs — a database, a bucket, a mail sender, a queue, a\n\t * topic.\n\t *\n\t * It records the edge and dissolves each construct's client into the\n\t * handler's service record under the construct's own id, so\n\t * `.dependsOn([uploads])` is what makes `services.uploads` exist and type.\n\t *\n\t * Constructs only. A `Service` does not match the shape, which is what keeps\n\t * env sniffing confined to `.services()` and the explicit lift.\n\t */\n\toverride dependsOn<const T extends readonly Consumable[]>(\n\t\tconstructs: T,\n\t): CronBuilder<\n\t\tTInput,\n\t\t[...TServices, ...ServicesOf<T>],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\t// Both halves of the edge, from one call and one clone: the services the\n\t\t// handler runs with, and the ids the manifest records. Recording them\n\t\t// separately is what let them drift apart.\n\t\t//\n\t\t// `servicesOf` is the half that validates, so it runs first — recording\n\t\t// ids ahead of it left a caught `NotAConstruct` with `undefined` already\n\t\t// on a `string[]`.\n\t\tconst services = servicesOf(constructs) as unknown as Service[];\n\n\t\treturn cloneWith(this, {\n\t\t\t_services: uniqBy(\n\t\t\t\t[...this._services, ...services],\n\t\t\t\t(s: Service) => s.serviceName,\n\t\t\t),\n\t\t\t_constructs: idsOf(constructs, this._constructs),\n\t\t}) as unknown as CronBuilder<\n\t\t\tTInput,\n\t\t\t[...TServices, ...ServicesOf<T>],\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t}\n\n\toverride services<T extends Service[]>(\n\t\tservices: T,\n\t): CronBuilder<\n\t\tTInput,\n\t\t[...TServices, ...T],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn cloneWith(this, {\n\t\t\t_services: uniqBy(\n\t\t\t\t[...this._services, ...services],\n\t\t\t\t(s) => s.serviceName,\n\t\t\t) as TServices,\n\t\t}) as unknown as CronBuilder<\n\t\t\tTInput,\n\t\t\t[...TServices, ...T],\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t}\n\n\toverride logger<T extends Logger>(\n\t\tlogger: T,\n\t): CronBuilder<\n\t\tTInput,\n\t\tTServices,\n\t\tT,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn cloneWith(this, {\n\t\t\t_logger: logger as unknown as TLogger,\n\t\t}) as unknown as CronBuilder<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tT,\n\t\t\tOutSchema,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t}\n\n\t/**\n\t * Publish `event` to `topic` each time the cron has run successfully —\n\t * repeatable, to as many topics as it names. The topic becomes a dependency\n\t * as with `.dependsOn([topic])`, so `services.<topic>` is there too.\n\t */\n\toverride event<TTopic extends Topic<any, any>>(\n\t\ttopic: TTopic,\n\t\tevent: EventFor<TTopic, InferStandardSchema<OutSchema>>,\n\t): CronBuilder<\n\t\tTInput,\n\t\t[...TServices, TTopic['service']],\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\treturn this.withEvent(topic, event as never) as unknown as CronBuilder<\n\t\t\tTInput,\n\t\t\t[...TServices, TTopic['service']],\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tTDatabase,\n\t\t\tTDatabaseServiceName\n\t\t>;\n\t}\n\n\t/**\n\t * Set the database service for this cron job.\n\t * The database will be available in the handler context as `db`.\n\t */\n\toverride database<T, TName extends string>(\n\t\tsource: Consumable<TName, T> | Service<TName, T>,\n\t): CronBuilder<TInput, TServices, TLogger, OutSchema, T, TName> {\n\t\tconst service = serviceOf(source);\n\n\t\treturn cloneWith(this, {\n\t\t\t_databaseService: service as unknown as Service<\n\t\t\t\tTDatabaseServiceName,\n\t\t\t\tTDatabase\n\t\t\t>,\n\t\t\t// The edge, as `.dependsOn()` records one — see EndpointFactory.\n\t\t\t...(isConsumable(source)\n\t\t\t\t? { _constructs: idsOf([source], this._constructs) }\n\t\t\t\t: {}),\n\t\t}) as unknown as CronBuilder<\n\t\t\tTInput,\n\t\t\tTServices,\n\t\t\tTLogger,\n\t\t\tOutSchema,\n\t\t\tT,\n\t\t\tTName\n\t\t>;\n\t}\n\n\toverride handle(\n\t\tfn: FunctionHandler<TInput, TServices, TLogger, OutSchema, TDatabase>,\n\t): Cron<\n\t\tTInput,\n\t\tTServices,\n\t\tTLogger,\n\t\tOutSchema,\n\t\tTDatabase,\n\t\tTDatabaseServiceName\n\t> {\n\t\tconst cron = new Cron(\n\t\t\tfn,\n\t\t\tthis._timeout,\n\t\t\tthis._schedule,\n\t\t\tthis.inputSchema,\n\t\t\tthis.outputSchema,\n\t\t\tthis._services,\n\t\t\tthis._logger,\n\t\t\tthis._events,\n\t\t\tthis._memorySize,\n\t\t\tthis._databaseService,\n\t\t\tthis._constructs,\n\t\t);\n\n\t\t// Which process runs it. Carried from the factory rather than inferred\n\t\t// from the directory the file happens to sit in.\n\t\tcron.owner = this._owner;\n\n\t\t// And where that process keeps the schedule, when a server is what runs\n\t\t// it. Declared once on the worker rather than repeated per cron.\n\t\tcron.scheduleStore = this._scheduleStore\n\t\t\t? serviceOf(this._scheduleStore as Consumable<string, unknown>)\n\t\t\t: undefined;\n\n\t\t// No reset. `.handle()` reads this builder and leaves it alone, so a\n\t\t// configured base — `const fn = f.logger(log).timeout(60_000)` — keeps\n\t\t// its configuration for every construct built from it. The reset that\n\t\t// used to be here wiped the base on first use, which made a base usable\n\t\t// exactly once, and quietly reverted the logger to the default.\n\n\t\treturn cron;\n\t}\n}\n"],"mappings":";;;;;;;AAUA,IAAa,OAAb,cAOUA,kBAAAA,SAWR;CAyBU;;;;;;;;;;;;CAbX;CAEA,OAAO,OAAO,KAA2C;EACxD,OAAO,QACN,OACE,IAAiB,oBAAoB,QACtC,IAAI,SAAA,6BACN;CACD;CAEA,YACC,IACA,SACA,WACA,OACA,cACA,WAAsB,CAAC,GACvB,QAEA,SAAuB,CAAC,GACxB,YACA,iBAKA,aAAuB,CAAC,GACvB;EACD,MACC,IACA,SAAA,+BAEA,OACA,cACA,UACA,QACA,QACA,YACA,KAAA,GACA,iBACA,UACD;EA5BU,KAAA,YAAA;CA6BX;CAEA,IAAI,WAA2C;EAC9C,OAAO,KAAK;CACb;AACD;;;AChEA,IAAa,cAAb,cAOUC,kBAAAA,gBASR;CACD;CAEA,cAAc;EACb,MAAA,6BAAwB;CACzB;CAEA,WAAoB,YAA0B;EAC7C,OAAOC,cAAAA,UAAU,MAAM,EAAE,aAAa,WAAW,CAAC;CACnD;CAEA,SACC,aAQC;EACD,OAAOA,cAAAA,UAAU,MAAM,EAAE,WAAW,YAAY,CAAC;CAClD;CAEA,MACC,QAQC;EACD,OAAOA,cAAAA,UAAU,MAAM,EACtB,aAAa,OACd,CAAC;CAQF;CAEA,OACC,QAQC;EACD,OAAOA,cAAAA,UAAU,MAAM,EACtB,cAAc,OACf,CAAC;CAQF;;;;;;;;;;;;CAaA,UACC,YAQC;EAQD,MAAM,WAAWC,4BAAAA,WAAW,UAAU;EAEtC,OAAOD,cAAAA,UAAU,MAAM;GACtB,YAAA,GAAWE,qBAAAA,QAAAA,CACV,CAAC,GAAG,KAAK,WAAW,GAAG,QAAQ,IAC9B,MAAe,EAAE,WACnB;GACA,aAAaC,4BAAAA,MAAM,YAAY,KAAK,WAAW;EAChD,CAAC;CAQF;CAEA,SACC,UAQC;EACD,OAAOH,cAAAA,UAAU,MAAM,EACtB,YAAA,GAAWE,qBAAAA,QAAAA,CACV,CAAC,GAAG,KAAK,WAAW,GAAG,QAAQ,IAC9B,MAAM,EAAE,WACV,EACD,CAAC;CAQF;CAEA,OACC,QAQC;EACD,OAAOF,cAAAA,UAAU,MAAM,EACtB,SAAS,OACV,CAAC;CAQF;;;;;;CAOA,MACC,OACA,OAQC;EACD,OAAO,KAAK,UAAU,OAAO,KAAc;CAQ5C;;;;;CAMA,SACC,QAC+D;EAC/D,MAAM,UAAUI,4BAAAA,UAAU,MAAM;EAEhC,OAAOJ,cAAAA,UAAU,MAAM;GACtB,kBAAkB;GAKlB,GAAIK,4BAAAA,aAAa,MAAM,IACpB,EAAE,aAAaF,4BAAAA,MAAM,CAAC,MAAM,GAAG,KAAK,WAAW,EAAE,IACjD,CAAC;EACL,CAAC;CAQF;CAEA,OACC,IAQC;EACD,MAAM,OAAO,IAAI,KAChB,IACA,KAAK,UACL,KAAK,WACL,KAAK,aACL,KAAK,cACL,KAAK,WACL,KAAK,SACL,KAAK,SACL,KAAK,aACL,KAAK,kBACL,KAAK,WACN;EAIA,KAAK,QAAQ,KAAK;EAIlB,KAAK,gBAAgB,KAAK,iBACvBC,4BAAAA,UAAU,KAAK,cAA6C,IAC5D,KAAA;EAQH,OAAO;CACR;AACD"}