@geekmidas/constructs 10.0.0-alpha.0 → 10.0.0-alpha.10

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 (218) hide show
  1. package/README.md +1 -0
  2. package/dist/{Construct-HmWM6YYu.mjs → Construct-BD5neF7w.mjs} +15 -2
  3. package/dist/Construct-BD5neF7w.mjs.map +1 -0
  4. package/dist/{Construct-WhCXIOPV.d.cts → Construct-C0ijr2qp.d.cts} +14 -1
  5. package/dist/Construct-C0ijr2qp.d.cts.map +1 -0
  6. package/dist/{Construct-B-xc0SE9.d.mts → Construct-Ct8nalEi.d.mts} +14 -1
  7. package/dist/Construct-Ct8nalEi.d.mts.map +1 -0
  8. package/dist/{Construct-roId57cU.cjs → Construct-CyS3RpTL.cjs} +14 -1
  9. package/dist/Construct-CyS3RpTL.cjs.map +1 -0
  10. package/dist/Cron-DmQ8vQ4b.d.cts +39 -0
  11. package/dist/Cron-DmQ8vQ4b.d.cts.map +1 -0
  12. package/dist/Cron-dh4rUgib.d.mts +39 -0
  13. package/dist/Cron-dh4rUgib.d.mts.map +1 -0
  14. package/dist/CronBuilder-BquXDbDI.d.cts +44 -0
  15. package/dist/CronBuilder-BquXDbDI.d.cts.map +1 -0
  16. package/dist/CronBuilder-CGgY2080.d.mts +44 -0
  17. package/dist/CronBuilder-CGgY2080.d.mts.map +1 -0
  18. package/dist/CronBuilder-CYKT5RiO.mjs +93 -0
  19. package/dist/CronBuilder-CYKT5RiO.mjs.map +1 -0
  20. package/dist/CronBuilder-Da0C0edR.cjs +105 -0
  21. package/dist/CronBuilder-Da0C0edR.cjs.map +1 -0
  22. package/dist/{Endpoint-ROcXU-eH.d.mts → Endpoint-BjWKinFA.d.mts} +2 -2
  23. package/dist/{Endpoint-ROcXU-eH.d.mts.map → Endpoint-BjWKinFA.d.mts.map} +1 -1
  24. package/dist/{Endpoint-BGwpNEX4.mjs → Endpoint-DCQPMdUX.mjs} +3 -3
  25. package/dist/{Endpoint-BGwpNEX4.mjs.map → Endpoint-DCQPMdUX.mjs.map} +1 -1
  26. package/dist/{Endpoint-BBkV6l0k.cjs → Endpoint-DcWXE-SZ.cjs} +3 -3
  27. package/dist/{Endpoint-BBkV6l0k.cjs.map → Endpoint-DcWXE-SZ.cjs.map} +1 -1
  28. package/dist/{Endpoint-BnxZqIX-.d.cts → Endpoint-dav89W6-.d.cts} +2 -2
  29. package/dist/{Endpoint-BnxZqIX-.d.cts.map → Endpoint-dav89W6-.d.cts.map} +1 -1
  30. package/dist/{EndpointFactory-DYoGLaIT.cjs → EndpointFactory-CdWB7wPw.cjs} +7 -5
  31. package/dist/EndpointFactory-CdWB7wPw.cjs.map +1 -0
  32. package/dist/{EndpointFactory-Di0X9AWp.mjs → EndpointFactory-CjV8F_lJ.mjs} +7 -5
  33. package/dist/EndpointFactory-CjV8F_lJ.mjs.map +1 -0
  34. package/dist/{HonoEndpointAdaptor-wMsCyMgt.cjs → HonoEndpointAdaptor-DtL9j19R.cjs} +5 -6
  35. package/dist/{HonoEndpointAdaptor-wMsCyMgt.cjs.map → HonoEndpointAdaptor-DtL9j19R.cjs.map} +1 -1
  36. package/dist/{HonoEndpointAdaptor-DFKIIG2o.mjs → HonoEndpointAdaptor-P1ahhZHu.mjs} +4 -5
  37. package/dist/{HonoEndpointAdaptor-DFKIIG2o.mjs.map → HonoEndpointAdaptor-P1ahhZHu.mjs.map} +1 -1
  38. package/dist/{Queue-D6WeziRD.d.cts → Queue-D7ZuwBhy.d.cts} +2 -2
  39. package/dist/{Queue-D6WeziRD.d.cts.map → Queue-D7ZuwBhy.d.cts.map} +1 -1
  40. package/dist/{Queue-DpUeqdC8.d.mts → Queue-gVGfi2Yk.d.mts} +2 -2
  41. package/dist/{Queue-DpUeqdC8.d.mts.map → Queue-gVGfi2Yk.d.mts.map} +1 -1
  42. package/dist/{Subscriber-4rBJgDKI.d.mts → Subscriber-2mEi0ImH.d.cts} +3 -3
  43. package/dist/{Subscriber-4rBJgDKI.d.mts.map → Subscriber-2mEi0ImH.d.cts.map} +1 -1
  44. package/dist/{Subscriber-DVQowdyj.d.cts → Subscriber-xTJ9ayPN.d.mts} +3 -3
  45. package/dist/{Subscriber-DVQowdyj.d.cts.map → Subscriber-xTJ9ayPN.d.mts.map} +1 -1
  46. package/dist/SubscriberBuilder-4OPehf2R.cjs +120 -0
  47. package/dist/SubscriberBuilder-4OPehf2R.cjs.map +1 -0
  48. package/dist/SubscriberBuilder-BjkbeT9l.mjs +108 -0
  49. package/dist/SubscriberBuilder-BjkbeT9l.mjs.map +1 -0
  50. package/dist/SubscriberBuilder-Dptmo-1A.d.mts +62 -0
  51. package/dist/SubscriberBuilder-Dptmo-1A.d.mts.map +1 -0
  52. package/dist/SubscriberBuilder-waNhzjSM.d.cts +62 -0
  53. package/dist/SubscriberBuilder-waNhzjSM.d.cts.map +1 -0
  54. package/dist/{Topic-Ohx9dvWr.d.cts → Topic-19QeHBIR.d.cts} +2 -2
  55. package/dist/{Topic-Ohx9dvWr.d.cts.map → Topic-19QeHBIR.d.cts.map} +1 -1
  56. package/dist/{Topic-cmy2jOUy.d.mts → Topic-DuFeqkBh.d.mts} +2 -2
  57. package/dist/{Topic-cmy2jOUy.d.mts.map → Topic-DuFeqkBh.d.mts.map} +1 -1
  58. package/dist/adaptors/aws.cjs +243 -10
  59. package/dist/adaptors/aws.cjs.map +1 -1
  60. package/dist/adaptors/aws.d.cts +99 -10
  61. package/dist/adaptors/aws.d.cts.map +1 -1
  62. package/dist/adaptors/aws.d.mts +99 -10
  63. package/dist/adaptors/aws.d.mts.map +1 -1
  64. package/dist/adaptors/aws.mjs +240 -7
  65. package/dist/adaptors/aws.mjs.map +1 -1
  66. package/dist/adaptors/hono.cjs +6 -7
  67. package/dist/adaptors/hono.d.cts +6 -6
  68. package/dist/adaptors/hono.d.cts.map +1 -1
  69. package/dist/adaptors/hono.d.mts +6 -6
  70. package/dist/adaptors/hono.d.mts.map +1 -1
  71. package/dist/adaptors/hono.mjs +6 -7
  72. package/dist/adaptors/testing.cjs +9 -10
  73. package/dist/adaptors/testing.cjs.map +1 -1
  74. package/dist/adaptors/testing.d.cts +6 -6
  75. package/dist/adaptors/testing.d.mts +6 -6
  76. package/dist/adaptors/testing.mjs +6 -7
  77. package/dist/adaptors/testing.mjs.map +1 -1
  78. package/dist/auth.cjs +2 -2
  79. package/dist/auth.cjs.map +1 -1
  80. package/dist/auth.d.cts +10 -10
  81. package/dist/auth.d.cts.map +1 -1
  82. package/dist/auth.d.mts +10 -10
  83. package/dist/auth.d.mts.map +1 -1
  84. package/dist/auth.mjs +2 -2
  85. package/dist/auth.mjs.map +1 -1
  86. package/dist/{cache-CdQ7OLpR.d.cts → cache-BrRz3fEB.d.mts} +3 -3
  87. package/dist/{cache-CdQ7OLpR.d.cts.map → cache-BrRz3fEB.d.mts.map} +1 -1
  88. package/dist/{cache-DYoJFcfd.d.mts → cache-BtZY_tHe.d.cts} +3 -3
  89. package/dist/{cache-DYoJFcfd.d.mts.map → cache-BtZY_tHe.d.cts.map} +1 -1
  90. package/dist/cache.d.cts +2 -2
  91. package/dist/cache.d.mts +2 -2
  92. package/dist/{construct-interface-BqwRNYA2.d.mts → construct-interface-D9d4Gm4p.d.cts} +2 -2
  93. package/dist/{construct-interface-BqwRNYA2.d.mts.map → construct-interface-D9d4Gm4p.d.cts.map} +1 -1
  94. package/dist/{construct-interface-D2nNkHUN.d.cts → construct-interface-g5GM5pwR.d.mts} +2 -2
  95. package/dist/{construct-interface-D2nNkHUN.d.cts.map → construct-interface-g5GM5pwR.d.mts.map} +1 -1
  96. package/dist/construct-interface.d.cts +1 -1
  97. package/dist/construct-interface.d.mts +1 -1
  98. package/dist/credential.d.cts +1 -1
  99. package/dist/credential.d.mts +1 -1
  100. package/dist/crons/index.cjs +68 -86
  101. package/dist/crons/index.cjs.map +1 -1
  102. package/dist/crons/index.d.cts +36 -48
  103. package/dist/crons/index.d.cts.map +1 -1
  104. package/dist/crons/index.d.mts +36 -48
  105. package/dist/crons/index.d.mts.map +1 -1
  106. package/dist/crons/index.mjs +65 -82
  107. package/dist/crons/index.mjs.map +1 -1
  108. package/dist/database/kysely.d.cts +2 -2
  109. package/dist/database/kysely.d.mts +2 -2
  110. package/dist/email.d.cts +1 -1
  111. package/dist/email.d.mts +1 -1
  112. package/dist/endpoints/index.cjs +6 -7
  113. package/dist/endpoints/index.d.cts +5 -5
  114. package/dist/endpoints/index.d.mts +5 -5
  115. package/dist/endpoints/index.mjs +5 -6
  116. package/dist/file-server.d.cts +1 -1
  117. package/dist/file-server.d.mts +1 -1
  118. package/dist/functions/index.cjs +3 -4
  119. package/dist/functions/index.d.cts +4 -4
  120. package/dist/functions/index.d.mts +4 -4
  121. package/dist/functions/index.mjs +3 -3
  122. package/dist/{functions-CvT_q7Y4.mjs → functions-14lpEFL4.mjs} +22 -9
  123. package/dist/functions-14lpEFL4.mjs.map +1 -0
  124. package/dist/{functions-DukjG8ov.cjs → functions-i_la-N5r.cjs} +21 -14
  125. package/dist/functions-i_la-N5r.cjs.map +1 -0
  126. package/dist/{index-7OcOWe75.d.cts → index-Bd5FqCoe.d.cts} +5 -5
  127. package/dist/{index-7OcOWe75.d.cts.map → index-Bd5FqCoe.d.cts.map} +1 -1
  128. package/dist/index-BknhM6Ux.d.mts +31 -0
  129. package/dist/index-BknhM6Ux.d.mts.map +1 -0
  130. package/dist/index-CBSfrowv.d.cts +31 -0
  131. package/dist/index-CBSfrowv.d.cts.map +1 -0
  132. package/dist/{index-Dadljnh_.d.cts → index-D24Xm79M.d.cts} +19 -11
  133. package/dist/index-D24Xm79M.d.cts.map +1 -0
  134. package/dist/{index-CPeqtKgq.d.mts → index-_ajboYxK.d.mts} +26 -17
  135. package/dist/index-_ajboYxK.d.mts.map +1 -0
  136. package/dist/{index-Bt-F7u8L.d.mts → index-lAO9egTb.d.mts} +5 -5
  137. package/dist/{index-Bt-F7u8L.d.mts.map → index-lAO9egTb.d.mts.map} +1 -1
  138. package/dist/index.cjs +1 -1
  139. package/dist/index.d.cts +1 -1
  140. package/dist/index.d.mts +1 -1
  141. package/dist/index.mjs +1 -1
  142. package/dist/{lazyAccessors-DM6HcXQk.mjs → lazyAccessors-BoJN3SMd.mjs} +41 -2
  143. package/dist/lazyAccessors-BoJN3SMd.mjs.map +1 -0
  144. package/dist/{lazyAccessors-DrJj8NpA.cjs → lazyAccessors-e3j2oE2m.cjs} +52 -1
  145. package/dist/lazyAccessors-e3j2oE2m.cjs.map +1 -0
  146. package/dist/object-storage.d.cts +1 -1
  147. package/dist/object-storage.d.mts +1 -1
  148. package/dist/{processAudits-Bc8rz6Ev.cjs → processAudits-CGqttuXm.cjs} +1 -1
  149. package/dist/{processAudits-Bc8rz6Ev.cjs.map → processAudits-CGqttuXm.cjs.map} +1 -1
  150. package/dist/{processAudits-D89tICM4.mjs → processAudits-Dmts9H_b.mjs} +1 -1
  151. package/dist/{processAudits-D89tICM4.mjs.map → processAudits-Dmts9H_b.mjs.map} +1 -1
  152. package/dist/queue/index.cjs +1 -1
  153. package/dist/queue/index.d.cts +5 -5
  154. package/dist/queue/index.d.mts +5 -5
  155. package/dist/queue/index.mjs +1 -1
  156. package/dist/rest-api.cjs +6 -8
  157. package/dist/rest-api.cjs.map +1 -1
  158. package/dist/rest-api.d.cts +16 -24
  159. package/dist/rest-api.d.cts.map +1 -1
  160. package/dist/rest-api.d.mts +16 -24
  161. package/dist/rest-api.d.mts.map +1 -1
  162. package/dist/rest-api.mjs +6 -8
  163. package/dist/rest-api.mjs.map +1 -1
  164. package/dist/site.cjs +2 -2
  165. package/dist/site.cjs.map +1 -1
  166. package/dist/site.d.cts +9 -16
  167. package/dist/site.d.cts.map +1 -1
  168. package/dist/site.d.mts +9 -16
  169. package/dist/site.d.mts.map +1 -1
  170. package/dist/site.mjs +2 -2
  171. package/dist/site.mjs.map +1 -1
  172. package/dist/subscribers/index.cjs +6 -108
  173. package/dist/subscribers/index.d.cts +6 -63
  174. package/dist/subscribers/index.d.mts +6 -63
  175. package/dist/subscribers/index.mjs +5 -105
  176. package/dist/topic/index.cjs +1 -1
  177. package/dist/topic/index.d.cts +4 -32
  178. package/dist/topic/index.d.mts +4 -32
  179. package/dist/topic/index.mjs +1 -1
  180. package/dist/worker.cjs +166 -0
  181. package/dist/worker.cjs.map +1 -0
  182. package/dist/worker.d.cts +146 -0
  183. package/dist/worker.d.cts.map +1 -0
  184. package/dist/worker.d.mts +145 -0
  185. package/dist/worker.d.mts.map +1 -0
  186. package/dist/worker.mjs +165 -0
  187. package/dist/worker.mjs.map +1 -0
  188. package/package.json +58 -66
  189. package/dist/AWSScheduledFunction-BvFvBsBN.d.cts +0 -122
  190. package/dist/AWSScheduledFunction-BvFvBsBN.d.cts.map +0 -1
  191. package/dist/AWSScheduledFunction-CVccZO-L.d.mts +0 -122
  192. package/dist/AWSScheduledFunction-CVccZO-L.d.mts.map +0 -1
  193. package/dist/AWSScheduledFunction-Db1lttJH.mjs +0 -243
  194. package/dist/AWSScheduledFunction-Db1lttJH.mjs.map +0 -1
  195. package/dist/AWSScheduledFunction-qu4ieRZR.cjs +0 -255
  196. package/dist/AWSScheduledFunction-qu4ieRZR.cjs.map +0 -1
  197. package/dist/Construct-B-xc0SE9.d.mts.map +0 -1
  198. package/dist/Construct-HmWM6YYu.mjs.map +0 -1
  199. package/dist/Construct-WhCXIOPV.d.cts.map +0 -1
  200. package/dist/Construct-roId57cU.cjs.map +0 -1
  201. package/dist/EndpointFactory-DYoGLaIT.cjs.map +0 -1
  202. package/dist/EndpointFactory-Di0X9AWp.mjs.map +0 -1
  203. package/dist/functions-CvT_q7Y4.mjs.map +0 -1
  204. package/dist/functions-DukjG8ov.cjs.map +0 -1
  205. package/dist/index-CPeqtKgq.d.mts.map +0 -1
  206. package/dist/index-Dadljnh_.d.cts.map +0 -1
  207. package/dist/lazyAccessors-DM6HcXQk.mjs.map +0 -1
  208. package/dist/lazyAccessors-DrJj8NpA.cjs.map +0 -1
  209. package/dist/publisher-CGEo8UKD.mjs +0 -41
  210. package/dist/publisher-CGEo8UKD.mjs.map +0 -1
  211. package/dist/publisher-CqGsXB2X.cjs +0 -53
  212. package/dist/publisher-CqGsXB2X.cjs.map +0 -1
  213. package/dist/subscribers/index.cjs.map +0 -1
  214. package/dist/subscribers/index.d.cts.map +0 -1
  215. package/dist/subscribers/index.d.mts.map +0 -1
  216. package/dist/subscribers/index.mjs.map +0 -1
  217. package/dist/topic/index.d.cts.map +0 -1
  218. package/dist/topic/index.d.mts.map +0 -1
@@ -1,32 +1,4 @@
1
- import "../Construct-B-xc0SE9.mjs";
2
- import { Topic, TopicEvents, TopicMessage } from "../Topic-cmy2jOUy.mjs";
3
- import { Logger } from "@geekmidas/logger";
4
-
5
- //#region src/topic/TopicBuilder.d.ts
6
-
7
- /**
8
- * Builds a {@link Topic} — `t.topic('users').events({ 'user.created': schema, … })`.
9
- * The event map is the topic's contract: it types the derived `topic.publisher`
10
- * and the subscribers that bind via `s.topic(topic)`.
11
- */
12
- declare class TopicBuilder<TName extends string = string, TEvents extends TopicEvents = TopicEvents> {
13
- private _name?;
14
- private _logger;
15
- /** The topic name — drives the infra topic and its `<NAME>_*` env vars. */
16
- topic<T extends string>(name: T): TopicBuilder<T, TEvents>;
17
- logger(logger: Logger): this;
18
- /**
19
- * The event contract — a map of event type → payload schema. Building the
20
- * topic requires this; it's what types the publisher and subscribers.
21
- */
22
- events<T extends TopicEvents>(events: T): Topic<TName, T>;
23
- }
24
- //# sourceMappingURL=TopicBuilder.d.ts.map
25
- //#endregion
26
- //#region src/topic/index.d.ts
27
- declare const t: TopicBuilder<string, TopicEvents>;
28
- //# sourceMappingURL=index.d.ts.map
29
-
30
- //#endregion
31
- export { Topic, TopicBuilder, TopicEvents, TopicMessage, t };
32
- //# sourceMappingURL=index.d.mts.map
1
+ import "../Construct-Ct8nalEi.mjs";
2
+ import { Topic, TopicEvents, TopicMessage } from "../Topic-DuFeqkBh.mjs";
3
+ import { TopicBuilder, t } from "../index-BknhM6Ux.mjs";
4
+ export { Topic, TopicBuilder, TopicEvents, TopicMessage, t };
@@ -1,4 +1,4 @@
1
- import { Construct, ConstructType } from "../Construct-HmWM6YYu.mjs";
1
+ import { Construct, ConstructType } from "../Construct-BD5neF7w.mjs";
2
2
  import { cloneWith } from "../clone-DblgEZZa.mjs";
3
3
  import { canonicalId, provideKey, serviceKey } from "@geekmidas/manifest";
4
4
  import { DEFAULT_LOGGER } from "@geekmidas/logger/console";
@@ -0,0 +1,166 @@
1
+ const require_chunk = require('./chunk-DWy1uDak.cjs');
2
+ const require_construct_interface = require('./construct-interface-BfjcOD_E.cjs');
3
+ require('./Construct-CyS3RpTL.cjs');
4
+ const require_functions = require('./functions-i_la-N5r.cjs');
5
+ require('./clone-Dy0cR2SZ.cjs');
6
+ const require_surfaceEnv = require('./surfaceEnv-BFXEms2f.cjs');
7
+ const require_CronBuilder = require('./CronBuilder-Da0C0edR.cjs');
8
+ const require_SubscriberBuilder = require('./SubscriberBuilder-4OPehf2R.cjs');
9
+ const __geekmidas_manifest = require_chunk.__toESM(require("@geekmidas/manifest"));
10
+ const __geekmidas_logger_console = require_chunk.__toESM(require("@geekmidas/logger/console"));
11
+
12
+ //#region src/worker.ts
13
+ var Worker = class Worker {
14
+ id;
15
+ /** Always defined — the worker's own, or the console logger. */
16
+ logger;
17
+ /** Always defined, and normally the default. */
18
+ envParser;
19
+ /**
20
+ * Where this worker's schedules live, when it has crons and a server runs
21
+ * them. `undefined` until `.database(…)` says.
22
+ */
23
+ scheduleStore;
24
+ constructor(id, config = {}, dependencies = [], scheduleStore) {
25
+ this.config = config;
26
+ this.dependencies = dependencies;
27
+ const canonical = (0, __geekmidas_manifest.canonicalId)(id);
28
+ this.id = canonical;
29
+ this.logger = config.logger ?? __geekmidas_logger_console.DEFAULT_LOGGER;
30
+ this.envParser = require_surfaceEnv.envParserFor(config.envParser ? {
31
+ id: canonical,
32
+ envParser: config.envParser
33
+ } : void 0);
34
+ this.scheduleStore = scheduleStore;
35
+ }
36
+ /**
37
+ * The database this worker keeps its schedules in.
38
+ *
39
+ * Only a server target uses it. On AWS a cron is an EventBridge rule
40
+ * invoking a Lambda and nothing here is consulted — but a server has nothing
41
+ * firing its crons except itself, and a process that schedules in memory
42
+ * fires every job once per replica while reporting that all is well.
43
+ *
44
+ * So the store is declared rather than discovered. It could have been
45
+ * inferred — from a database the app happens to declare, or from the events
46
+ * backend when that backend is pg-boss — and both would work until an app
47
+ * had two databases, or moved its events to SNS, at which point the
48
+ * schedules would quietly move or stop. Naming it is one line and cannot
49
+ * drift.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * export const jobs = new Worker('Jobs', { logger }).database(database);
54
+ * ```
55
+ */
56
+ database(source) {
57
+ return new Worker(this.id, this.config, [...this.dependencies, require_construct_interface.edgeTo(source)], source);
58
+ }
59
+ /**
60
+ * A scheduled runnable.
61
+ *
62
+ * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`
63
+ */
64
+ cron(schedule) {
65
+ return this.own(new require_CronBuilder.CronBuilder().logger(this.logger)).schedule(schedule);
66
+ }
67
+ /**
68
+ * A runnable that consumes a topic.
69
+ *
70
+ * Binding is not publishing: a consumer is handed the topic's event types
71
+ * and no connection string it could publish with. Chain `.publishes(…)` when
72
+ * the handler emits follow-up events, which is the only reason it would need
73
+ * one.
74
+ *
75
+ * @example `worker.topic(users).subscribe(['user.created']).handle(…)`
76
+ */
77
+ topic(topic) {
78
+ return this.own(new require_SubscriberBuilder.SubscriberBuilder().logger(this.logger)).topic(topic);
79
+ }
80
+ /**
81
+ * A runnable that consumes events typed from a publisher service.
82
+ *
83
+ * The older of the two ways to bind a subscriber, kept for a project whose
84
+ * events come from a hand-written publisher rather than a `Topic`
85
+ * construct. `topic()` is the one to reach for: it types the events the same
86
+ * way and hands the consumer no connection string it could publish with.
87
+ */
88
+ publisher(service) {
89
+ return this.own(new require_SubscriberBuilder.SubscriberBuilder().logger(this.logger)).publisher(service);
90
+ }
91
+ /**
92
+ * Everything below builds a function — the runnable with no schedule and no
93
+ * topic, invoked by something else.
94
+ *
95
+ * These sit on the worker rather than behind a `functions` namespace because
96
+ * the namespace was a hop that said nothing: `worker.functions.input(…)`
97
+ * names a collection to reach one member of it. What kind of runnable is
98
+ * being built is decided by which of these is called first — a schedule
99
+ * makes a cron, a topic makes a subscriber, and anything else makes a
100
+ * function.
101
+ */
102
+ input(schema) {
103
+ return this.functions.input(schema);
104
+ }
105
+ output(schema) {
106
+ return this.functions.output(schema);
107
+ }
108
+ timeout(ms) {
109
+ return this.functions.timeout(ms);
110
+ }
111
+ memorySize(mb) {
112
+ return this.functions.memorySize(mb);
113
+ }
114
+ dependsOn(constructs) {
115
+ return this.functions.dependsOn(constructs);
116
+ }
117
+ services(services) {
118
+ return this.functions.services(services);
119
+ }
120
+ /**
121
+ * A function with no input schema — the shortest runnable there is.
122
+ *
123
+ * @example `worker.handle(async ({ logger }) => { … })`
124
+ */
125
+ handle(...args) {
126
+ return this.schemalessFunction().handle(...args);
127
+ }
128
+ /** The builder `handle` delegates to, named so its type can be referred to. */
129
+ schemalessFunction() {
130
+ return this.functions;
131
+ }
132
+ /** The function builder the delegating methods above are built on. */
133
+ get functions() {
134
+ return this.own(new require_functions.FunctionBuilder().logger(this.logger));
135
+ }
136
+ /**
137
+ * Resources and surfaces this worker calls.
138
+ *
139
+ * Not `.dependsOn()`: this records the edge that derives the worker's
140
+ * environment and its access, the same distinction `RestApi.calls()` draws.
141
+ */
142
+ calls(constructs) {
143
+ return new Worker(this.id, this.config, [...this.dependencies, ...constructs.map(require_construct_interface.edgeTo)], this.scheduleStore);
144
+ }
145
+ /**
146
+ * Stamps this worker's id onto a builder, so everything built from it says
147
+ * which process runs it.
148
+ */
149
+ own(builder) {
150
+ builder._owner = this.id;
151
+ builder._scheduleStore = this.scheduleStore;
152
+ return builder;
153
+ }
154
+ declare() {
155
+ return [{
156
+ kind: "worker",
157
+ id: this.id,
158
+ ...this.dependencies.length ? { dependencies: this.dependencies } : {},
159
+ provides: []
160
+ }];
161
+ }
162
+ };
163
+
164
+ //#endregion
165
+ exports.Worker = Worker;
166
+ //# sourceMappingURL=worker.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.cjs","names":["id: ConstructName<TName>","config: WorkerConfig","dependencies: readonly Dependency[]","scheduleStore?: Consumable<string, unknown>","DEFAULT_LOGGER","source: Consumable<TDbName, T>","schedule: ScheduleExpression","CronBuilder","topic: Topic<TTopicName, TEvents>","SubscriberBuilder","service: Service<TPubName, T> | Consumable<TPubName, T>","schema: T","ms: number","mb: number","constructs: T","services: T","FunctionBuilder","constructs: readonly Declarable[]","edgeTo","builder: T"],"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 { 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 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. Chain `.publishes(…)` when\n\t * the handler emits follow-up events, which is the only reason it would need\n\t * 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 * A runnable that consumes events typed from a publisher service.\n\t *\n\t * The older of the two ways to bind a subscriber, kept for a project whose\n\t * events come from a hand-written publisher rather than a `Topic`\n\t * construct. `topic()` is the one to reach for: it types the events the same\n\t * way and hands the consumer no connection string it could publish with.\n\t */\n\tpublisher<T extends EventPublisher<any>, TPubName extends string>(\n\t\tservice: Service<TPubName, T> | Consumable<TPubName, T>,\n\t) {\n\t\treturn this.own(new SubscriberBuilder().logger(this.logger)).publisher(\n\t\t\tservice as never,\n\t\t);\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":";;;;;;;;;;;;AAoGA,IAAa,SAAb,MAAa,OAEb;CACC,AAAS;;CAGT,AAAS;;CAGT,AAAS;;;;;CAMT,AAAS;CAET,YACCA,IACiBC,SAAuB,CAAE,GAEzBC,eAAsC,CAAE,GACzDC,eACC;EAJgB;EAEA;EAGjB,MAAM,YAAY,sCAAY,GAAa;AAE3C,OAAK,KAAK;AACV,OAAK,SAAS,OAAO,UAAUC;AAC/B,OAAK,YAAY,gCAChB,OAAO,YACJ;GAAE,IAAI;GAAW,WAAW,OAAO;EAAW,WAEjD;AACD,OAAK,gBAAgB;CACrB;;;;;;;;;;;;;;;;;;;;;CAsBD,SACCC,QACgB;AAChB,SAAO,IAAI,OACV,KAAK,IACL,KAAK,QACL,CAAC,GAAG,KAAK,cAAc,mCAAO,OAAO,AAAC,GACtC;CAED;;;;;;CAOD,KAAKC,UAA8B;AAClC,SAAO,KAAK,IAAI,IAAIC,kCAAc,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,SAAS;CACzE;;;;;;;;;;;CAYD,MACCC,OACC;AACD,SAAO,KAAK,IAAI,IAAIC,8CAAoB,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,MAAM;CACzE;;;;;;;;;CAUD,UACCC,SACC;AACD,SAAO,KAAK,IAAI,IAAID,8CAAoB,OAAO,KAAK,OAAO,CAAC,CAAC,UAC5D,QACA;CACD;;;;;;;;;;;;CAaD,MAA0CE,QAAW;AACpD,SAAO,KAAK,UAAU,MAAM,OAAO;CACnC;CAED,OAAmCA,QAAW;AAC7C,SAAO,KAAK,UAAU,OAAO,OAAO;CACpC;CAED,QAAQC,IAAY;AACnB,SAAO,KAAK,UAAU,QAAQ,GAAG;CACjC;CAED,WAAWC,IAAY;AACtB,SAAO,KAAK,UAAU,WAAW,GAAG;CACpC;CAED,UAAiDC,YAAe;AAC/D,SAAO,KAAK,UAAU,UAAU,WAAW;CAC3C;CAED,SAA8BC,UAAa;AAC1C,SAAO,KAAK,UAAU,SAAS,SAAS;CACxC;;;;;;CAOD,OACC,GAAG,MAGF;AACD,SAAO,KAAK,oBAAoB,CAAC,OAAO,GAAG,KAAK;CAChD;;CAGD,AAAQ,qBAAqB;AAC5B,SAAO,KAAK;CACZ;;CAGD,IAAY,YAAY;AACvB,SAAO,KAAK,IAAI,IAAIC,oCAAkB,OAAO,KAAK,OAAO,CAAC;CAC1D;;;;;;;CAQD,MAAMC,YAAkD;AACvD,SAAO,IAAI,OACV,KAAK,IACL,KAAK,QACL,CAAC,GAAG,KAAK,cAAc,GAAG,WAAW,IAAIC,mCAAO,AAAC,GACjD,KAAK;CAEN;;;;;CAMD,AAAQ,IACPC,SACI;AACJ,UAAQ,SAAS,KAAK;AACtB,UAAQ,iBAAiB,KAAK;AAE9B,SAAO;CACP;CAED,UAAyB;AACxB,SAAO,CACN;GACC,MAAM;GACN,IAAI,KAAK;GACT,GAAI,KAAK,aAAa,SACnB,EAAE,cAAc,KAAK,aAAc,IACnC,CAAE;GAEL,UAAU,CAAE;EACZ,CACD;CACD;AACD"}
@@ -0,0 +1,146 @@
1
+ import "./Construct-C0ijr2qp.cjs";
2
+ import { Function, FunctionBuilder, FunctionHandler } from "./index-D24Xm79M.cjs";
3
+ import { Consumable, Declarable, ServicesOf } from "./construct-interface-D9d4Gm4p.cjs";
4
+ import { ScheduleExpression } from "./Cron-DmQ8vQ4b.cjs";
5
+ import "./Subscriber-2mEi0ImH.cjs";
6
+ import { CronBuilder } from "./CronBuilder-BquXDbDI.cjs";
7
+ import { Topic, TopicEvents, TopicMessage } from "./Topic-19QeHBIR.cjs";
8
+ import { SubscriberBuilder } from "./SubscriberBuilder-waNhzjSM.cjs";
9
+ import "./index-CBSfrowv.cjs";
10
+ import { EnvironmentParser } from "@geekmidas/envkit";
11
+ import { EventPublisher } from "@geekmidas/events";
12
+ import { Logger } from "@geekmidas/logger";
13
+ import { ComposableStandardSchema } from "@geekmidas/schema";
14
+ import { Service } from "@geekmidas/services";
15
+ import { StandardSchemaV1 } from "@standard-schema/spec";
16
+ import * as _geekmidas_audit13 from "@geekmidas/audit";
17
+ import { ConstructName, Declaration, Dependency } from "@geekmidas/manifest";
18
+
19
+ //#region src/worker.d.ts
20
+
21
+ interface WorkerConfig {
22
+ /**
23
+ * The logger everything built from this worker runs with.
24
+ *
25
+ * The actual logger, not a path to one — the same reason `RestApi` takes
26
+ * one. Every cron and subscriber in a scaffolded project used to open with
27
+ * `import { logger } from '…/constructs/logger.js'`, which is the line this
28
+ * removes.
29
+ */
30
+ logger?: Logger;
31
+ /**
32
+ * The environment parser everything built from this worker runs with.
33
+ *
34
+ * Defaults to `process.env` merged with the credentials `gkm dev` injected,
35
+ * which is what an application's own `config/env.ts` always was.
36
+ */
37
+ envParser?: EnvironmentParser<{}>;
38
+ }
39
+ declare class Worker<TName extends string = string> implements Declarable<TName> {
40
+ private readonly config;
41
+ /** Internal: how `.calls()` carries edges into the copy it returns. */
42
+ private readonly dependencies;
43
+ readonly id: TName;
44
+ /** Always defined — the worker's own, or the console logger. */
45
+ readonly logger: Logger;
46
+ /** Always defined, and normally the default. */
47
+ readonly envParser: EnvironmentParser<{}>;
48
+ /**
49
+ * Where this worker's schedules live, when it has crons and a server runs
50
+ * them. `undefined` until `.database(…)` says.
51
+ */
52
+ readonly scheduleStore?: Consumable<string, unknown>;
53
+ constructor(id: ConstructName<TName>, config?: WorkerConfig, /** Internal: how `.calls()` carries edges into the copy it returns. */
54
+ dependencies?: readonly Dependency[], scheduleStore?: Consumable<string, unknown>);
55
+ /**
56
+ * The database this worker keeps its schedules in.
57
+ *
58
+ * Only a server target uses it. On AWS a cron is an EventBridge rule
59
+ * invoking a Lambda and nothing here is consulted — but a server has nothing
60
+ * firing its crons except itself, and a process that schedules in memory
61
+ * fires every job once per replica while reporting that all is well.
62
+ *
63
+ * So the store is declared rather than discovered. It could have been
64
+ * inferred — from a database the app happens to declare, or from the events
65
+ * backend when that backend is pg-boss — and both would work until an app
66
+ * had two databases, or moved its events to SNS, at which point the
67
+ * schedules would quietly move or stop. Naming it is one line and cannot
68
+ * drift.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * export const jobs = new Worker('Jobs', { logger }).database(database);
73
+ * ```
74
+ */
75
+ database<T, TDbName extends string>(source: Consumable<TDbName, T>): Worker<TName>;
76
+ /**
77
+ * A scheduled runnable.
78
+ *
79
+ * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`
80
+ */
81
+ cron(schedule: ScheduleExpression): CronBuilder<ComposableStandardSchema, Service<string, unknown>[], Logger, undefined, undefined, string, undefined, string>;
82
+ /**
83
+ * A runnable that consumes a topic.
84
+ *
85
+ * Binding is not publishing: a consumer is handed the topic's event types
86
+ * and no connection string it could publish with. Chain `.publishes(…)` when
87
+ * the handler emits follow-up events, which is the only reason it would need
88
+ * one.
89
+ *
90
+ * @example `worker.topic(users).subscribe(['user.created']).handle(…)`
91
+ */
92
+ topic<TTopicName extends string, TEvents extends TopicEvents>(topic: Topic<TTopicName, TEvents>): SubscriberBuilder<[], Logger, undefined, EventPublisher<TopicMessage<TEvents>>, string, []>;
93
+ /**
94
+ * A runnable that consumes events typed from a publisher service.
95
+ *
96
+ * The older of the two ways to bind a subscriber, kept for a project whose
97
+ * events come from a hand-written publisher rather than a `Topic`
98
+ * construct. `topic()` is the one to reach for: it types the events the same
99
+ * way and hands the consumer no connection string it could publish with.
100
+ */
101
+ publisher<T extends EventPublisher<any>, TPubName extends string>(service: Service<TPubName, T> | Consumable<TPubName, T>): SubscriberBuilder<[], Logger, undefined, EventPublisher<any>, string, []>;
102
+ /**
103
+ * Everything below builds a function — the runnable with no schedule and no
104
+ * topic, invoked by something else.
105
+ *
106
+ * These sit on the worker rather than behind a `functions` namespace because
107
+ * the namespace was a hop that said nothing: `worker.functions.input(…)`
108
+ * names a collection to reach one member of it. What kind of runnable is
109
+ * being built is decided by which of these is called first — a schedule
110
+ * makes a cron, a topic makes a subscriber, and anything else makes a
111
+ * function.
112
+ */
113
+ input<T extends ComposableStandardSchema>(schema: T): FunctionBuilder<T, undefined, [], Logger, undefined, string, undefined, string, undefined, string, _geekmidas_audit13.AuditableAction<string, unknown>>;
114
+ output<T extends StandardSchemaV1>(schema: T): FunctionBuilder<ComposableStandardSchema, T, [], Logger, undefined, string, undefined, string, undefined, string, _geekmidas_audit13.AuditableAction<string, unknown>>;
115
+ timeout(ms: number): FunctionBuilder<ComposableStandardSchema, undefined, [], Logger, undefined, string, undefined, string, undefined, string, _geekmidas_audit13.AuditableAction<string, unknown>>;
116
+ memorySize(mb: number): FunctionBuilder<ComposableStandardSchema, undefined, [], Logger, undefined, string, undefined, string, undefined, string, _geekmidas_audit13.AuditableAction<string, unknown>>;
117
+ dependsOn<const T extends readonly Consumable[]>(constructs: T): FunctionBuilder<ComposableStandardSchema, undefined, [...ServicesOf<T>], Logger, undefined, string, undefined, string, undefined, string, _geekmidas_audit13.AuditableAction<string, unknown>>;
118
+ services<T extends Service[]>(services: T): FunctionBuilder<ComposableStandardSchema, undefined, [...T], Logger, undefined, string, undefined, string, undefined, string, _geekmidas_audit13.AuditableAction<string, unknown>>;
119
+ /**
120
+ * A function with no input schema — the shortest runnable there is.
121
+ *
122
+ * @example `worker.handle(async ({ logger }) => { … })`
123
+ */
124
+ handle(...args: Parameters<ReturnType<Worker<TName>['schemalessFunction']>['handle']>): Function<ComposableStandardSchema, [], Logger, undefined, undefined, string, undefined, string, undefined, string, _geekmidas_audit13.AuditableAction<string, unknown>, FunctionHandler<ComposableStandardSchema, [], Logger, undefined, undefined, undefined, _geekmidas_audit13.AuditableAction<string, unknown>>>;
125
+ /** The builder `handle` delegates to, named so its type can be referred to. */
126
+ private schemalessFunction;
127
+ /** The function builder the delegating methods above are built on. */
128
+ private get functions();
129
+ /**
130
+ * Resources and surfaces this worker calls.
131
+ *
132
+ * Not `.dependsOn()`: this records the edge that derives the worker's
133
+ * environment and its access, the same distinction `RestApi.calls()` draws.
134
+ */
135
+ calls(constructs: readonly Declarable[]): Worker<TName>;
136
+ /**
137
+ * Stamps this worker's id onto a builder, so everything built from it says
138
+ * which process runs it.
139
+ */
140
+ private own;
141
+ declare(): Declaration[];
142
+ }
143
+ //# sourceMappingURL=worker.d.ts.map
144
+ //#endregion
145
+ export { Worker, WorkerConfig };
146
+ //# sourceMappingURL=worker.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.cts","names":[],"sources":["../src/worker.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;;AA2NoD,UA1InC,YAAA,CA0ImC;EAAA;;;;;;;;EAIP,MAAA,CAAA,EArInC,MAqImC;EAAA;;;;;;EAQvB,SAAA,CAAA,EAtIT,iBAsIS,CAAA,CAAA,CAAA,CAAA;;AAIc,cAvIvB,MAuIuB,CAAA,cAAA,MAAA,GAAA,MAAA,CAAA,YAtIxB,UAsIwB,CAtIb,KAsIa,CAAA,CAAA;EAAU,iBAAgB,MAAA;EAAC;EAAA,iBAAA,YAAA;EAAA,SAAA,EAAA,EApIjD,KAoIiD;EAAA;EAAA,SAAA,MAAA,EAjI7C,MAiI6C;EAAA;EAAA,SAI3C,SAAA,EAlIC,iBAkID,CAAA,CAAA,CAAA,CAAA;EAAO;;;;EAAe,SAAA,aAAA,CAAA,EA5HhB,UA4HgB,CAAA,MAAA,EAAA,OAAA,CAAA;EAAA,WAAA,CAAA,EAAA,EAzHpC,aAyHoC,CAzHtB,KAyHsB,CAAA,EAAA,MAAA,CAAA,EAxHf,YAwHe,EAAA;EAWhB,YAAZ,CAAA,EAAA,SAjI4B,UAiI5B,EAAA,EAAA,aAAA,CAAA,EAhII,UAgIJ,CAAA,MAAA,EAAA,OAAA,CAAA;EAAM;;;;;;;;;;;;;;;AArJE;;;;;8CAwDZ,WAAW,SAAS,KAC1B,OAAO;;;;;;iBAcK,qBAAkB,YAAA,0BAAA,4BAAA;;;;;;;;;;;mDAcgB,oBACzC,MAAM,YAAY,WAAQ,sBAAA,mBAAA,eAAA,aAAA;;;;;;;;;sBAad,uDACV,QAAQ,UAAU,KAAK,WAAW,UAAU,KAAE,sBAAA,mBAAA;;;;;;;;;;;;kBAkBxC,kCAAkC,IAAC,gBAAA,kBAAA,iEAAA,kBAAA,CAAA;mBAIlC,0BAA0B,IAAC,gBAAA,0BAAA,OAAA,iEAAA,kBAAA,CAAA;uBAI1B,gBAAA,yCAAA,iEAAA,kBAAA,CAAA;0BAIG,gBAAA,yCAAA,iEAAA,kBAAA,CAAA;qCAIc,0BAA0B,IAAC,gBAAA,yCAAA,WAAA,KAAA,iEAAA,kBAAA,CAAA;qBAI3C,qBAAqB,IAAC,gBAAA,yCAAA,IAAA,iEAAA,kBAAA,CAAA;;;;;;kBAU/B,WACR,WAAW,OAAO,2CAClB,SAAA,8BAAA,4EAAA,kBAAA,CAAA,kCAAA,gBAAA,8BAAA,yCAAA,kBAAA,CAAA;;;;;;;;;;;6BAqByB,eAAe,OAAO;;;;;;aAsBtC"}
@@ -0,0 +1,145 @@
1
+ import "./Construct-Ct8nalEi.mjs";
2
+ import { Function, FunctionBuilder, FunctionHandler } from "./index-_ajboYxK.mjs";
3
+ import { Consumable, Declarable, ServicesOf } from "./construct-interface-g5GM5pwR.mjs";
4
+ import { ScheduleExpression } from "./Cron-dh4rUgib.mjs";
5
+ import "./Subscriber-xTJ9ayPN.mjs";
6
+ import { CronBuilder } from "./CronBuilder-CGgY2080.mjs";
7
+ import { Topic, TopicEvents, TopicMessage } from "./Topic-DuFeqkBh.mjs";
8
+ import { SubscriberBuilder } from "./SubscriberBuilder-Dptmo-1A.mjs";
9
+ import "./index-BknhM6Ux.mjs";
10
+ import { ConstructName, Declaration, Dependency } from "@geekmidas/manifest";
11
+ import { EnvironmentParser } from "@geekmidas/envkit";
12
+ import { Service } from "@geekmidas/services";
13
+ import { EventPublisher } from "@geekmidas/events";
14
+ import { Logger } from "@geekmidas/logger";
15
+ import { ComposableStandardSchema } from "@geekmidas/schema";
16
+ import { StandardSchemaV1 } from "@standard-schema/spec";
17
+
18
+ //#region src/worker.d.ts
19
+
20
+ interface WorkerConfig {
21
+ /**
22
+ * The logger everything built from this worker runs with.
23
+ *
24
+ * The actual logger, not a path to one — the same reason `RestApi` takes
25
+ * one. Every cron and subscriber in a scaffolded project used to open with
26
+ * `import { logger } from '…/constructs/logger.js'`, which is the line this
27
+ * removes.
28
+ */
29
+ logger?: Logger;
30
+ /**
31
+ * The environment parser everything built from this worker runs with.
32
+ *
33
+ * Defaults to `process.env` merged with the credentials `gkm dev` injected,
34
+ * which is what an application's own `config/env.ts` always was.
35
+ */
36
+ envParser?: EnvironmentParser<{}>;
37
+ }
38
+ declare class Worker<TName extends string = string> implements Declarable<TName> {
39
+ private readonly config;
40
+ /** Internal: how `.calls()` carries edges into the copy it returns. */
41
+ private readonly dependencies;
42
+ readonly id: TName;
43
+ /** Always defined — the worker's own, or the console logger. */
44
+ readonly logger: Logger;
45
+ /** Always defined, and normally the default. */
46
+ readonly envParser: EnvironmentParser<{}>;
47
+ /**
48
+ * Where this worker's schedules live, when it has crons and a server runs
49
+ * them. `undefined` until `.database(…)` says.
50
+ */
51
+ readonly scheduleStore?: Consumable<string, unknown>;
52
+ constructor(id: ConstructName<TName>, config?: WorkerConfig, /** Internal: how `.calls()` carries edges into the copy it returns. */
53
+ dependencies?: readonly Dependency[], scheduleStore?: Consumable<string, unknown>);
54
+ /**
55
+ * The database this worker keeps its schedules in.
56
+ *
57
+ * Only a server target uses it. On AWS a cron is an EventBridge rule
58
+ * invoking a Lambda and nothing here is consulted — but a server has nothing
59
+ * firing its crons except itself, and a process that schedules in memory
60
+ * fires every job once per replica while reporting that all is well.
61
+ *
62
+ * So the store is declared rather than discovered. It could have been
63
+ * inferred — from a database the app happens to declare, or from the events
64
+ * backend when that backend is pg-boss — and both would work until an app
65
+ * had two databases, or moved its events to SNS, at which point the
66
+ * schedules would quietly move or stop. Naming it is one line and cannot
67
+ * drift.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * export const jobs = new Worker('Jobs', { logger }).database(database);
72
+ * ```
73
+ */
74
+ database<T, TDbName extends string>(source: Consumable<TDbName, T>): Worker<TName>;
75
+ /**
76
+ * A scheduled runnable.
77
+ *
78
+ * @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`
79
+ */
80
+ cron(schedule: ScheduleExpression): CronBuilder<ComposableStandardSchema, Service<string, unknown>[], Logger, undefined, undefined, string, undefined, string>;
81
+ /**
82
+ * A runnable that consumes a topic.
83
+ *
84
+ * Binding is not publishing: a consumer is handed the topic's event types
85
+ * and no connection string it could publish with. Chain `.publishes(…)` when
86
+ * the handler emits follow-up events, which is the only reason it would need
87
+ * one.
88
+ *
89
+ * @example `worker.topic(users).subscribe(['user.created']).handle(…)`
90
+ */
91
+ topic<TTopicName extends string, TEvents extends TopicEvents>(topic: Topic<TTopicName, TEvents>): SubscriberBuilder<[], Logger, undefined, EventPublisher<TopicMessage<TEvents_1>>, string, []>;
92
+ /**
93
+ * A runnable that consumes events typed from a publisher service.
94
+ *
95
+ * The older of the two ways to bind a subscriber, kept for a project whose
96
+ * events come from a hand-written publisher rather than a `Topic`
97
+ * construct. `topic()` is the one to reach for: it types the events the same
98
+ * way and hands the consumer no connection string it could publish with.
99
+ */
100
+ publisher<T extends EventPublisher<any>, TPubName extends string>(service: Service<TPubName, T> | Consumable<TPubName, T>): SubscriberBuilder<[], Logger, undefined, EventPublisher<any>, string, []>;
101
+ /**
102
+ * Everything below builds a function — the runnable with no schedule and no
103
+ * topic, invoked by something else.
104
+ *
105
+ * These sit on the worker rather than behind a `functions` namespace because
106
+ * the namespace was a hop that said nothing: `worker.functions.input(…)`
107
+ * names a collection to reach one member of it. What kind of runnable is
108
+ * being built is decided by which of these is called first — a schedule
109
+ * makes a cron, a topic makes a subscriber, and anything else makes a
110
+ * function.
111
+ */
112
+ input<T extends ComposableStandardSchema>(schema: T): FunctionBuilder<T, undefined, [], Logger, undefined, string, undefined, string, undefined, string, AuditableAction<string, unknown>>;
113
+ output<T extends StandardSchemaV1>(schema: T): FunctionBuilder<ComposableStandardSchema, T, [], Logger, undefined, string, undefined, string, undefined, string, AuditableAction<string, unknown>>;
114
+ timeout(ms: number): FunctionBuilder<ComposableStandardSchema, undefined, [], Logger, undefined, string, undefined, string, undefined, string, AuditableAction<string, unknown>>;
115
+ memorySize(mb: number): FunctionBuilder<ComposableStandardSchema, undefined, [], Logger, undefined, string, undefined, string, undefined, string, AuditableAction<string, unknown>>;
116
+ dependsOn<const T extends readonly Consumable[]>(constructs: T): FunctionBuilder<ComposableStandardSchema, undefined, [...ServicesOf<T>], Logger, undefined, string, undefined, string, undefined, string, AuditableAction<string, unknown>>;
117
+ services<T extends Service[]>(services: T): FunctionBuilder<ComposableStandardSchema, undefined, [...T], Logger, undefined, string, undefined, string, undefined, string, AuditableAction<string, unknown>>;
118
+ /**
119
+ * A function with no input schema — the shortest runnable there is.
120
+ *
121
+ * @example `worker.handle(async ({ logger }) => { … })`
122
+ */
123
+ handle(...args: Parameters<ReturnType<Worker<TName>['schemalessFunction']>['handle']>): Function<ComposableStandardSchema, [], Logger, undefined, undefined, string, undefined, string, undefined, string, AuditableAction<string, unknown>, FunctionHandler<ComposableStandardSchema, [], Logger, undefined, undefined, undefined, AuditableAction<string, unknown>>>;
124
+ /** The builder `handle` delegates to, named so its type can be referred to. */
125
+ private schemalessFunction;
126
+ /** The function builder the delegating methods above are built on. */
127
+ private get functions();
128
+ /**
129
+ * Resources and surfaces this worker calls.
130
+ *
131
+ * Not `.dependsOn()`: this records the edge that derives the worker's
132
+ * environment and its access, the same distinction `RestApi.calls()` draws.
133
+ */
134
+ calls(constructs: readonly Declarable[]): Worker<TName>;
135
+ /**
136
+ * Stamps this worker's id onto a builder, so everything built from it says
137
+ * which process runs it.
138
+ */
139
+ private own;
140
+ declare(): Declaration[];
141
+ }
142
+ //# sourceMappingURL=worker.d.ts.map
143
+ //#endregion
144
+ export { Worker, WorkerConfig };
145
+ //# sourceMappingURL=worker.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.mts","names":[],"sources":["../src/worker.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;AA2NoD,UA1InC,YAAA,CA0ImC;EAAA;;;;;;;;EAIP,MAI1B,CAAA,EAzIT,MAyIS;EAAA;;;;;;EAIG,SAAA,CAAA,EAtIT,iBAsIS,CAAA,CAAA,CAAA,CAAA;;AAIwC,cAvIjD,MAuIiD,CAAA,cAAA,MAAA,GAAA,MAAA,CAAA,YAtIlD,UAsIkD,CAtIvC,KAsIuC,CAAA,CAAA;EAAC,iBAAA,MAAA;EAAA;EAAA,iBAAA,YAAA;EAAA,SAAA,EAAA,EApIjD,KAoIiD;EAAA;EAAA,SAAA,MAAA,EAjI7C,MAiI6C;EAAA;EAIpC,SAAc,SAAA,EAlIpB,iBAkIoB,CAAA,CAAA,CAAA,CAAA;EAAC;;;;EAAA,SAAA,aAAA,CAAA,EA5HhB,UA4HgB,CAAA,MAAA,EAAA,OAAA,CAAA;EAAA,WAWrB,CAAA,EAAA,EApIf,aAoIe,CApID,KAoIC,CAAA,EAAA,MAAA,CAAA,EAnIM,YAmIN,EAAK;EAAN,YAAjB,CAAA,EAAA,SAjIuC,UAiIvC,EAAA,EAAA,aAAA,CAAA,EAhIe,UAgIf,CAAA,MAAA,EAAA,OAAA,CAAA;EAAU;;;;;;;;;;;;;;AArJS;;;;;;8CAwDZ,WAAW,SAAS,KAC1B,OAAO;;;;;;iBAcK,qBAAkB,YAAA,0BAAA,4BAAA;;;;;;;;;;;mDAcgB,oBACzC,MAAM,YAAY,WAAQ,sBAAA,mBAAA,eAAA,aAAA;;;;;;;;;sBAad,uDACV,QAAQ,UAAU,KAAK,WAAW,UAAU,KAAE,sBAAA,mBAAA;;;;;;;;;;;;kBAkBxC,kCAAkC,IAAC,gBAAA,kBAAA,iEAAA;mBAIlC,0BAA0B,IAAC,gBAAA,0BAAA,OAAA,iEAAA;uBAI1B,gBAAA,yCAAA,iEAAA;0BAIG,gBAAA,yCAAA,iEAAA;qCAIc,0BAA0B,IAAC,gBAAA,yCAAA,WAAA,KAAA,iEAAA;qBAI3C,qBAAqB,IAAC,gBAAA,yCAAA,IAAA,iEAAA;;;;;;kBAU/B,WACR,WAAW,OAAO,2CAClB,SAAA,8BAAA,4EAAA,kCAAA,gBAAA,8BAAA,yCAAA;;;;;;;;;;;6BAqByB,eAAe,OAAO;;;;;;aAsBtC"}