@geekmidas/constructs 10.0.0-alpha.37 → 10.0.0-alpha.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -155
- package/dist/{Construct-Detz65RA.mjs → Construct-BO1X-kt9.mjs} +3 -6
- package/dist/Construct-BO1X-kt9.mjs.map +1 -0
- package/dist/Construct-BQALFCh2.d.cts +230 -0
- package/dist/Construct-BQALFCh2.d.cts.map +1 -0
- package/dist/{Construct-yG9Sw-5p.cjs → Construct-DmvXceVY.cjs} +3 -6
- package/dist/Construct-DmvXceVY.cjs.map +1 -0
- package/dist/Construct-QXnl3VqT.d.mts +230 -0
- package/dist/Construct-QXnl3VqT.d.mts.map +1 -0
- package/dist/{Cron-CA2oa2nC.d.cts → Cron-CMEGfRs8.d.cts} +7 -5
- package/dist/Cron-CMEGfRs8.d.cts.map +1 -0
- package/dist/{Cron-B_iuyNxr.d.mts → Cron-D6X4-xjB.d.mts} +7 -5
- package/dist/Cron-D6X4-xjB.d.mts.map +1 -0
- package/dist/{CronBuilder-B_KqaodP.d.cts → CronBuilder-CEK7aOqD.d.cts} +21 -16
- package/dist/CronBuilder-CEK7aOqD.d.cts.map +1 -0
- package/dist/{CronBuilder-BbnT7tqo.cjs → CronBuilder-DB35T5dL.cjs} +13 -11
- package/dist/CronBuilder-DB35T5dL.cjs.map +1 -0
- package/dist/{CronBuilder-BRkzUOAs.mjs → CronBuilder-Dv0IlZs0.mjs} +14 -12
- package/dist/CronBuilder-Dv0IlZs0.mjs.map +1 -0
- package/dist/{CronBuilder-BIKCLWu7.d.mts → CronBuilder-O_gvButp.d.mts} +21 -16
- package/dist/CronBuilder-O_gvButp.d.mts.map +1 -0
- package/dist/{Endpoint-DO332Dnm.mjs → Endpoint-CQAeh1Rh.mjs} +5 -5
- package/dist/Endpoint-CQAeh1Rh.mjs.map +1 -0
- package/dist/{Endpoint-QKuFg5gs.cjs → Endpoint-D1L9qu5C.cjs} +5 -5
- package/dist/Endpoint-D1L9qu5C.cjs.map +1 -0
- package/dist/{Endpoint-1-XYQSx0.d.cts → Endpoint-Dp5AKIXl.d.cts} +10 -13
- package/dist/Endpoint-Dp5AKIXl.d.cts.map +1 -0
- package/dist/{Endpoint-GFIxYb9L.d.mts → Endpoint-DtI7heFm.d.mts} +10 -13
- package/dist/Endpoint-DtI7heFm.d.mts.map +1 -0
- package/dist/{EndpointFactory-B9HAjDAP.mjs → EndpointFactory-BBdNeaGJ.mjs} +23 -52
- package/dist/EndpointFactory-BBdNeaGJ.mjs.map +1 -0
- package/dist/{EndpointFactory-BmO0WnXE.cjs → EndpointFactory-BZOCOaK6.cjs} +22 -51
- package/dist/EndpointFactory-BZOCOaK6.cjs.map +1 -0
- package/dist/{EndpointFactory-BCZdh_u3.d.mts → EndpointFactory-CgMDvERK.d.mts} +58 -48
- package/dist/EndpointFactory-CgMDvERK.d.mts.map +1 -0
- package/dist/{EndpointFactory-BnK_YkW1.d.cts → EndpointFactory-FeFRmlDZ.d.cts} +58 -48
- package/dist/EndpointFactory-FeFRmlDZ.d.cts.map +1 -0
- package/dist/{HonoEndpointAdaptor-CiqAZ5Mt.mjs → HonoEndpointAdaptor-Aui-x9Lg.mjs} +4 -3
- package/dist/HonoEndpointAdaptor-Aui-x9Lg.mjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-DoEQdC3r.cjs → HonoEndpointAdaptor-Cq99r9H7.cjs} +5 -4
- package/dist/HonoEndpointAdaptor-Cq99r9H7.cjs.map +1 -0
- package/dist/{Queue-DpKTLl6E.mjs → Queue-C1uDgjxt.mjs} +29 -48
- package/dist/Queue-C1uDgjxt.mjs.map +1 -0
- package/dist/{Queue-B7yRXQmL.cjs → Queue-Ckmudcm8.cjs} +29 -48
- package/dist/Queue-Ckmudcm8.cjs.map +1 -0
- package/dist/{Queue-Bhzi2WQC.d.cts → Queue-CpQIGB_2.d.cts} +22 -33
- package/dist/Queue-CpQIGB_2.d.cts.map +1 -0
- package/dist/{Queue-BoUA-e83.d.mts → Queue-YmvN2vEP.d.mts} +21 -32
- package/dist/Queue-YmvN2vEP.d.mts.map +1 -0
- package/dist/QueueBuilder-CJNcv4dy.cjs +112 -0
- package/dist/QueueBuilder-CJNcv4dy.cjs.map +1 -0
- package/dist/QueueBuilder-CM0WUxfw.d.mts +62 -0
- package/dist/QueueBuilder-CM0WUxfw.d.mts.map +1 -0
- package/dist/QueueBuilder-XEnnOWGe.d.cts +62 -0
- package/dist/QueueBuilder-XEnnOWGe.d.cts.map +1 -0
- package/dist/QueueBuilder-XuPKZwKH.mjs +95 -0
- package/dist/QueueBuilder-XuPKZwKH.mjs.map +1 -0
- package/dist/{Subscriber-DQCaiOXF.d.cts → Subscriber-B91YSkZt.d.cts} +12 -13
- package/dist/Subscriber-B91YSkZt.d.cts.map +1 -0
- package/dist/{Subscriber-CIO3pwji.d.mts → Subscriber-BjHYe5hK.d.mts} +11 -12
- package/dist/Subscriber-BjHYe5hK.d.mts.map +1 -0
- package/dist/{SubscriberBuilder-CjDGSTZc.d.cts → SubscriberBuilder-BSpQX1JT.d.cts} +19 -23
- package/dist/SubscriberBuilder-BSpQX1JT.d.cts.map +1 -0
- package/dist/{SubscriberBuilder-C2FRfd26.d.mts → SubscriberBuilder-BhMphk4z.d.mts} +18 -22
- package/dist/SubscriberBuilder-BhMphk4z.d.mts.map +1 -0
- package/dist/{SubscriberBuilder-C2bCOuPT.cjs → SubscriberBuilder-Duk028pD.cjs} +11 -19
- package/dist/SubscriberBuilder-Duk028pD.cjs.map +1 -0
- package/dist/{SubscriberBuilder-B4YRTBng.mjs → SubscriberBuilder-DzQUWE08.mjs} +11 -19
- package/dist/SubscriberBuilder-DzQUWE08.mjs.map +1 -0
- package/dist/{Topic-D5rlM9wS.cjs → Topic-BBVXC3H4.cjs} +46 -51
- package/dist/Topic-BBVXC3H4.cjs.map +1 -0
- package/dist/Topic-DOw051ch.mjs +98 -0
- package/dist/Topic-DOw051ch.mjs.map +1 -0
- package/dist/adaptors/aws.cjs +5 -5
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/aws.d.cts +26 -26
- package/dist/adaptors/aws.d.cts.map +1 -1
- package/dist/adaptors/aws.d.mts +25 -25
- package/dist/adaptors/aws.d.mts.map +1 -1
- package/dist/adaptors/aws.mjs +5 -5
- package/dist/adaptors/aws.mjs.map +1 -1
- package/dist/adaptors/hono.cjs +1 -1
- package/dist/adaptors/hono.d.cts +4 -5
- package/dist/adaptors/hono.d.cts.map +1 -1
- package/dist/adaptors/hono.d.mts +4 -5
- package/dist/adaptors/hono.d.mts.map +1 -1
- package/dist/adaptors/hono.mjs +1 -1
- package/dist/adaptors/testing.cjs +59 -23
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/testing.d.cts +40 -28
- package/dist/adaptors/testing.d.cts.map +1 -1
- package/dist/adaptors/testing.d.mts +40 -28
- package/dist/adaptors/testing.d.mts.map +1 -1
- package/dist/adaptors/testing.mjs +59 -23
- package/dist/adaptors/testing.mjs.map +1 -1
- package/dist/{auth-c6nWnvD8.d.cts → auth-CMwml9QN.d.mts} +4 -4
- package/dist/{auth-c6nWnvD8.d.cts.map → auth-CMwml9QN.d.mts.map} +1 -1
- package/dist/{auth-pS_U1H_X.d.mts → auth-rVRDjIw_.d.cts} +4 -4
- package/dist/{auth-pS_U1H_X.d.mts.map → auth-rVRDjIw_.d.cts.map} +1 -1
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.mts +1 -1
- package/dist/{cache-B2s0b-ss.d.mts → cache-C9a_hVCc.d.cts} +3 -3
- package/dist/{cache-B2s0b-ss.d.mts.map → cache-C9a_hVCc.d.cts.map} +1 -1
- package/dist/{cache-CYe2Kzjc.d.cts → cache-CeTMI8LR.d.mts} +3 -3
- package/dist/{cache-CYe2Kzjc.d.cts.map → cache-CeTMI8LR.d.mts.map} +1 -1
- package/dist/cache.d.cts +1 -1
- package/dist/cache.d.mts +1 -1
- package/dist/{construct-interface-D2gesxos.d.mts → construct-interface-_3zgxzXl.d.mts} +11 -20
- package/dist/{construct-interface-D2gesxos.d.mts.map → construct-interface-_3zgxzXl.d.mts.map} +1 -1
- package/dist/{construct-interface-DPusCUSQ.d.cts → construct-interface-_xi4BPN8.d.cts} +11 -20
- package/dist/{construct-interface-DPusCUSQ.d.cts.map → construct-interface-_xi4BPN8.d.cts.map} +1 -1
- package/dist/construct-interface.cjs +4 -33
- package/dist/construct-interface.cjs.map +1 -1
- package/dist/construct-interface.d.cts +2 -2
- package/dist/construct-interface.d.mts +2 -2
- package/dist/construct-interface.mjs +5 -32
- package/dist/construct-interface.mjs.map +1 -1
- package/dist/credential.cjs +22 -9
- package/dist/credential.cjs.map +1 -1
- package/dist/credential.d.cts +12 -2
- package/dist/credential.d.cts.map +1 -1
- package/dist/credential.d.mts +12 -2
- package/dist/credential.d.mts.map +1 -1
- package/dist/credential.mjs +22 -10
- package/dist/credential.mjs.map +1 -1
- package/dist/crons/index.cjs +1 -1
- package/dist/crons/index.d.cts +2 -2
- package/dist/crons/index.d.mts +2 -2
- package/dist/crons/index.mjs +1 -1
- package/dist/database/kysely.d.cts +1 -1
- package/dist/database/kysely.d.mts +1 -1
- package/dist/email.d.cts +1 -1
- package/dist/email.d.mts +1 -1
- package/dist/endpoints/index.cjs +5 -4
- package/dist/endpoints/index.d.cts +4 -13
- package/dist/endpoints/index.d.cts.map +1 -1
- package/dist/endpoints/index.d.mts +4 -13
- package/dist/endpoints/index.d.mts.map +1 -1
- package/dist/endpoints/index.mjs +4 -3
- package/dist/external-api-DS3mujT5.d.mts +86 -0
- package/dist/external-api-DS3mujT5.d.mts.map +1 -0
- package/dist/external-api-LBfE-q3g.d.cts +86 -0
- package/dist/external-api-LBfE-q3g.d.cts.map +1 -0
- package/dist/external-api.cjs +124 -0
- package/dist/external-api.cjs.map +1 -0
- package/dist/external-api.d.cts +2 -0
- package/dist/external-api.d.mts +2 -0
- package/dist/external-api.mjs +121 -0
- package/dist/external-api.mjs.map +1 -0
- package/dist/file-server.d.cts +1 -1
- package/dist/file-server.d.mts +1 -1
- package/dist/functions/index.cjs +1 -1
- package/dist/functions/index.d.cts +1 -1
- package/dist/functions/index.d.mts +1 -1
- package/dist/functions/index.mjs +1 -1
- package/dist/{functions-DlFm8HmH.mjs → functions-DCIfCRR-.mjs} +94 -23
- package/dist/functions-DCIfCRR-.mjs.map +1 -0
- package/dist/{functions-DKN6aQWJ.cjs → functions-ZH60FE7H.cjs} +99 -19
- package/dist/functions-ZH60FE7H.cjs.map +1 -0
- package/dist/{index-BI23K3wy.d.cts → index-B0kxstwf.d.cts} +36 -24
- package/dist/index-B0kxstwf.d.cts.map +1 -0
- package/dist/{index-yb3fXNyH.d.mts → index-CjVEjOw0.d.mts} +36 -24
- package/dist/index-CjVEjOw0.d.mts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{kysely-CEVXacPN.d.cts → kysely-BJ8IQ_1P.d.mts} +4 -4
- package/dist/{kysely-CEVXacPN.d.cts.map → kysely-BJ8IQ_1P.d.mts.map} +1 -1
- package/dist/{kysely-mcTdPNhl.d.mts → kysely-DVF8wOT4.d.cts} +4 -4
- package/dist/{kysely-mcTdPNhl.d.mts.map → kysely-DVF8wOT4.d.cts.map} +1 -1
- package/dist/{lazyAccessors-BHtcqgz2.mjs → lazyAccessors-CFanua0O.mjs} +2 -39
- package/dist/lazyAccessors-CFanua0O.mjs.map +1 -0
- package/dist/{lazyAccessors-Dx9NLwJZ.cjs → lazyAccessors-hJKGv8Ay.cjs} +1 -50
- package/dist/lazyAccessors-hJKGv8Ay.cjs.map +1 -0
- package/dist/mobile-app.d.cts +1 -1
- package/dist/mobile-app.d.mts +1 -1
- package/dist/object-storage.d.cts +1 -1
- package/dist/object-storage.d.mts +1 -1
- package/dist/processAudits-BpRlPQMW.mjs.map +1 -1
- package/dist/processAudits-D_2W5x8k.cjs.map +1 -1
- package/dist/queue/index.cjs +4 -78
- package/dist/queue/index.d.cts +3 -53
- package/dist/queue/index.d.mts +3 -53
- package/dist/queue/index.mjs +3 -77
- package/dist/rest-api.cjs +2 -4
- package/dist/rest-api.cjs.map +1 -1
- package/dist/rest-api.d.cts +4 -5
- package/dist/rest-api.d.cts.map +1 -1
- package/dist/rest-api.d.mts +4 -5
- package/dist/rest-api.d.mts.map +1 -1
- package/dist/rest-api.mjs +2 -4
- package/dist/rest-api.mjs.map +1 -1
- package/dist/site.d.cts +1 -1
- package/dist/site.d.mts +1 -1
- package/dist/subscribers/index.cjs +1 -1
- package/dist/subscribers/index.d.cts +2 -2
- package/dist/subscribers/index.d.mts +2 -2
- package/dist/subscribers/index.mjs +1 -1
- package/dist/topic/index.cjs +1 -36
- package/dist/topic/index.d.cts +2 -3
- package/dist/topic/index.d.mts +2 -3
- package/dist/topic/index.mjs +2 -35
- package/dist/worker.cjs +26 -17
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.d.cts +37 -29
- package/dist/worker.d.cts.map +1 -1
- package/dist/worker.d.mts +37 -29
- package/dist/worker.d.mts.map +1 -1
- package/dist/worker.mjs +26 -17
- package/dist/worker.mjs.map +1 -1
- package/package.json +41 -31
- package/dist/Construct-DTqYvkPG.d.cts +0 -115
- package/dist/Construct-DTqYvkPG.d.cts.map +0 -1
- package/dist/Construct-Detz65RA.mjs.map +0 -1
- package/dist/Construct-pVadmURD.d.mts +0 -115
- package/dist/Construct-pVadmURD.d.mts.map +0 -1
- package/dist/Construct-yG9Sw-5p.cjs.map +0 -1
- package/dist/Cron-B_iuyNxr.d.mts.map +0 -1
- package/dist/Cron-CA2oa2nC.d.cts.map +0 -1
- package/dist/CronBuilder-BIKCLWu7.d.mts.map +0 -1
- package/dist/CronBuilder-BRkzUOAs.mjs.map +0 -1
- package/dist/CronBuilder-B_KqaodP.d.cts.map +0 -1
- package/dist/CronBuilder-BbnT7tqo.cjs.map +0 -1
- package/dist/Endpoint-1-XYQSx0.d.cts.map +0 -1
- package/dist/Endpoint-DO332Dnm.mjs.map +0 -1
- package/dist/Endpoint-GFIxYb9L.d.mts.map +0 -1
- package/dist/Endpoint-QKuFg5gs.cjs.map +0 -1
- package/dist/EndpointFactory-B9HAjDAP.mjs.map +0 -1
- package/dist/EndpointFactory-BCZdh_u3.d.mts.map +0 -1
- package/dist/EndpointFactory-BmO0WnXE.cjs.map +0 -1
- package/dist/EndpointFactory-BnK_YkW1.d.cts.map +0 -1
- package/dist/HonoEndpointAdaptor-CiqAZ5Mt.mjs.map +0 -1
- package/dist/HonoEndpointAdaptor-DoEQdC3r.cjs.map +0 -1
- package/dist/Queue-B7yRXQmL.cjs.map +0 -1
- package/dist/Queue-Bhzi2WQC.d.cts.map +0 -1
- package/dist/Queue-BoUA-e83.d.mts.map +0 -1
- package/dist/Queue-DpKTLl6E.mjs.map +0 -1
- package/dist/Subscriber-CIO3pwji.d.mts.map +0 -1
- package/dist/Subscriber-DQCaiOXF.d.cts.map +0 -1
- package/dist/SubscriberBuilder-B4YRTBng.mjs.map +0 -1
- package/dist/SubscriberBuilder-C2FRfd26.d.mts.map +0 -1
- package/dist/SubscriberBuilder-C2bCOuPT.cjs.map +0 -1
- package/dist/SubscriberBuilder-CjDGSTZc.d.cts.map +0 -1
- package/dist/Topic-Ct3Le8Wt.mjs +0 -103
- package/dist/Topic-Ct3Le8Wt.mjs.map +0 -1
- package/dist/Topic-D5rlM9wS.cjs.map +0 -1
- package/dist/Topic-D6blllEn.d.cts +0 -89
- package/dist/Topic-D6blllEn.d.cts.map +0 -1
- package/dist/Topic-DVvheJ_-.d.mts +0 -89
- package/dist/Topic-DVvheJ_-.d.mts.map +0 -1
- package/dist/functions-DKN6aQWJ.cjs.map +0 -1
- package/dist/functions-DlFm8HmH.mjs.map +0 -1
- package/dist/index-BI23K3wy.d.cts.map +0 -1
- package/dist/index-fnpjXiA-.d.mts +0 -26
- package/dist/index-fnpjXiA-.d.mts.map +0 -1
- package/dist/index-tE_119SX.d.cts +0 -26
- package/dist/index-tE_119SX.d.cts.map +0 -1
- package/dist/index-yb3fXNyH.d.mts.map +0 -1
- package/dist/lazyAccessors-BHtcqgz2.mjs.map +0 -1
- package/dist/lazyAccessors-Dx9NLwJZ.cjs.map +0 -1
- package/dist/queue/index.cjs.map +0 -1
- package/dist/queue/index.d.cts.map +0 -1
- package/dist/queue/index.d.mts.map +0 -1
- package/dist/queue/index.mjs.map +0 -1
- package/dist/topic/index.cjs.map +0 -1
- package/dist/topic/index.mjs.map +0 -1
package/dist/worker.d.mts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { t as StandardSchemaV1 } from "./index-CeEtxDmK.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { i as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { t as
|
|
8
|
-
import "./
|
|
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";
|
|
9
|
+
import "./topic/index.mjs";
|
|
9
10
|
import { ConstructName, Declaration, Dependency } from "@geekmidas/manifest";
|
|
10
11
|
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
11
|
-
import { EventPublisher } from "@geekmidas/events";
|
|
12
12
|
import { Service } from "@geekmidas/services";
|
|
13
13
|
import { Logger } from "@geekmidas/logger";
|
|
14
14
|
import { ComposableStandardSchema } from "@geekmidas/schema";
|
|
@@ -74,27 +74,35 @@ export declare class Worker<TName extends string = string> implements Declarable
|
|
|
74
74
|
*
|
|
75
75
|
* @example `worker.cron('rate(1 day)').handle(async ({ logger }) => { … })`
|
|
76
76
|
*/
|
|
77
|
-
cron(schedule: ScheduleExpression): CronBuilder<ComposableStandardSchema, Service[], Logger, undefined, undefined, string
|
|
77
|
+
cron(schedule: ScheduleExpression): CronBuilder<ComposableStandardSchema, Service[], Logger, undefined, undefined, string>;
|
|
78
78
|
/**
|
|
79
|
-
* A
|
|
79
|
+
* A queue and its one consumer, run by this worker.
|
|
80
80
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
81
|
+
* One construct, because a queue has exactly one consumer: nothing else can
|
|
82
|
+
* attach a second, or forget to attach the first. Producers send to it by
|
|
83
|
+
* depending on it — `.dependsOn([emails])` makes `services.emails` the
|
|
84
|
+
* publisher.
|
|
85
85
|
*
|
|
86
|
-
* @example
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* export const emails = worker
|
|
89
|
+
* .queue('Emails')
|
|
90
|
+
* .message(z.object({ userId: z.uuid(), template: z.string() }))
|
|
91
|
+
* .handle(async ({ messages, services }) => { … });
|
|
92
|
+
* ```
|
|
87
93
|
*/
|
|
88
|
-
|
|
94
|
+
queue<TQueueName extends string>(name: TQueueName): QueueBuilder<TQueueName, undefined, [], Logger>;
|
|
89
95
|
/**
|
|
90
|
-
* A runnable that consumes
|
|
96
|
+
* A runnable that consumes a topic.
|
|
91
97
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
98
|
+
* Binding is not publishing: a consumer is handed the topic's event types
|
|
99
|
+
* and no connection string it could publish with. A handler that emits
|
|
100
|
+
* follow-up events depends on the topic it emits to —
|
|
101
|
+
* `.dependsOn([orders])` — which is the only reason it would need one.
|
|
102
|
+
*
|
|
103
|
+
* @example `worker.topic(users).subscribe(['user.created']).handle(…)`
|
|
96
104
|
*/
|
|
97
|
-
|
|
105
|
+
topic<TTopicName extends string, TEvents extends TopicEvents>(topic: Topic<TTopicName, TEvents>): SubscriberBuilder<[], Logger, undefined, EventPublisher<TopicMessage<TEvents_1>>, []>;
|
|
98
106
|
/**
|
|
99
107
|
* Everything below builds a function — the runnable with no schedule and no
|
|
100
108
|
* topic, invoked by something else.
|
|
@@ -106,18 +114,18 @@ export declare class Worker<TName extends string = string> implements Declarable
|
|
|
106
114
|
* makes a cron, a topic makes a subscriber, and anything else makes a
|
|
107
115
|
* function.
|
|
108
116
|
*/
|
|
109
|
-
input<T extends ComposableStandardSchema>(schema: T): FunctionBuilder<T, undefined, [], Logger, undefined, string, undefined, string,
|
|
110
|
-
output<T extends StandardSchemaV1>(schema: T): FunctionBuilder<ComposableStandardSchema, T, [], Logger, undefined, string, undefined, string,
|
|
111
|
-
timeout(ms: number): FunctionBuilder<ComposableStandardSchema, undefined, [], Logger, undefined, string, undefined, string,
|
|
112
|
-
memorySize(mb: number): FunctionBuilder<ComposableStandardSchema, undefined, [], Logger, undefined, string, undefined, string,
|
|
113
|
-
dependsOn<const T extends readonly Consumable[]>(constructs: T): FunctionBuilder<ComposableStandardSchema, undefined, [...ServicesOf<T>], Logger, undefined, string, undefined, string,
|
|
114
|
-
services<T extends Service[]>(services: T): FunctionBuilder<ComposableStandardSchema, undefined, [...T], Logger, undefined, string, undefined, string,
|
|
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>>;
|
|
115
123
|
/**
|
|
116
124
|
* A function with no input schema — the shortest runnable there is.
|
|
117
125
|
*
|
|
118
126
|
* @example `worker.handle(async ({ logger }) => { … })`
|
|
119
127
|
*/
|
|
120
|
-
handle(...args: Parameters<ReturnType<Worker<TName>['schemalessFunction']>['handle']>): Function<ComposableStandardSchema, [], Logger, undefined, undefined, string, undefined, string,
|
|
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>>>;
|
|
121
129
|
/** The builder `handle` delegates to, named so its type can be referred to. */
|
|
122
130
|
private schemalessFunction;
|
|
123
131
|
/** The function builder the delegating methods above are built on. */
|
package/dist/worker.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.mts","names":["_$__topic0.TopicMessage","_$__construct_interface0.ServicesOf","_$__functions0.FunctionHandler","_$__functions0.Function"],"sources":["../src/worker.ts"],"mappings":";;;;;;;;;;;;;;;
|
|
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"}
|
package/dist/worker.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { edgeTo } from "./construct-interface.mjs";
|
|
2
|
-
import { t as FunctionBuilder } from "./functions-
|
|
2
|
+
import { t as FunctionBuilder } from "./functions-DCIfCRR-.mjs";
|
|
3
3
|
import { n as envParserFor } from "./surfaceEnv-wMT5QzgZ.mjs";
|
|
4
|
-
import { t as CronBuilder } from "./CronBuilder-
|
|
5
|
-
import { t as
|
|
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";
|
|
6
7
|
import { canonicalId } from "@geekmidas/manifest";
|
|
7
8
|
import { DEFAULT_LOGGER } from "@geekmidas/logger/console";
|
|
8
9
|
//#region src/worker.ts
|
|
@@ -63,12 +64,31 @@ var Worker = class Worker {
|
|
|
63
64
|
return this.own(new CronBuilder().logger(this.logger)).schedule(schedule);
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
67
|
+
* A queue and its one consumer, run by this worker.
|
|
68
|
+
*
|
|
69
|
+
* One construct, because a queue has exactly one consumer: nothing else can
|
|
70
|
+
* attach a second, or forget to attach the first. Producers send to it by
|
|
71
|
+
* depending on it — `.dependsOn([emails])` makes `services.emails` the
|
|
72
|
+
* publisher.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* export const emails = worker
|
|
77
|
+
* .queue('Emails')
|
|
78
|
+
* .message(z.object({ userId: z.uuid(), template: z.string() }))
|
|
79
|
+
* .handle(async ({ messages, services }) => { … });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
queue(name) {
|
|
83
|
+
return this.own(new QueueBuilder().logger(this.logger)).queue(name);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
66
86
|
* A runnable that consumes a topic.
|
|
67
87
|
*
|
|
68
88
|
* Binding is not publishing: a consumer is handed the topic's event types
|
|
69
|
-
* and no connection string it could publish with.
|
|
70
|
-
*
|
|
71
|
-
* one.
|
|
89
|
+
* and no connection string it could publish with. A handler that emits
|
|
90
|
+
* follow-up events depends on the topic it emits to —
|
|
91
|
+
* `.dependsOn([orders])` — which is the only reason it would need one.
|
|
72
92
|
*
|
|
73
93
|
* @example `worker.topic(users).subscribe(['user.created']).handle(…)`
|
|
74
94
|
*/
|
|
@@ -76,17 +96,6 @@ var Worker = class Worker {
|
|
|
76
96
|
return this.own(new SubscriberBuilder().logger(this.logger)).topic(topic);
|
|
77
97
|
}
|
|
78
98
|
/**
|
|
79
|
-
* A runnable that consumes events typed from a publisher service.
|
|
80
|
-
*
|
|
81
|
-
* The older of the two ways to bind a subscriber, kept for a project whose
|
|
82
|
-
* events come from a hand-written publisher rather than a `Topic`
|
|
83
|
-
* construct. `topic()` is the one to reach for: it types the events the same
|
|
84
|
-
* way and hands the consumer no connection string it could publish with.
|
|
85
|
-
*/
|
|
86
|
-
publisher(service) {
|
|
87
|
-
return this.own(new SubscriberBuilder().logger(this.logger)).publisher(service);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
99
|
* Everything below builds a function — the runnable with no schedule and no
|
|
91
100
|
* topic, invoked by something else.
|
|
92
101
|
*
|
package/dist/worker.mjs.map
CHANGED
|
@@ -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 { 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;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;;;;;;;;;;;CAYA,MACC,OACC;EACD,OAAO,KAAK,IAAI,IAAI,kBAAkB,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,KAAK;CACzE;;;;;;;;;CAUA,UACC,SACC;EACD,OAAO,KAAK,IAAI,IAAI,kBAAkB,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,UAC5D,OACD;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,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 * 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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/constructs",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-alpha.39",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -174,6 +174,16 @@
|
|
|
174
174
|
"default": "./dist/credential.cjs"
|
|
175
175
|
}
|
|
176
176
|
},
|
|
177
|
+
"./external-api": {
|
|
178
|
+
"import": {
|
|
179
|
+
"types": "./dist/external-api.d.mts",
|
|
180
|
+
"default": "./dist/external-api.mjs"
|
|
181
|
+
},
|
|
182
|
+
"require": {
|
|
183
|
+
"types": "./dist/external-api.d.cts",
|
|
184
|
+
"default": "./dist/external-api.cjs"
|
|
185
|
+
}
|
|
186
|
+
},
|
|
177
187
|
"./auth": {
|
|
178
188
|
"import": {
|
|
179
189
|
"types": "./dist/auth.d.mts",
|
|
@@ -255,13 +265,13 @@
|
|
|
255
265
|
"lodash.uniqby": "~4.7.0",
|
|
256
266
|
"openapi-types": "~12.1.3",
|
|
257
267
|
"qs": "~6.16.0",
|
|
258
|
-
"@geekmidas/envkit": "^10.0.0-alpha.
|
|
259
|
-
"@geekmidas/errors": "^10.0.0-alpha.
|
|
260
|
-
"@geekmidas/events": "^10.0.0-alpha.
|
|
261
|
-
"@geekmidas/logger": "^10.0.0-alpha.
|
|
262
|
-
"@geekmidas/manifest": "^10.0.0-alpha.
|
|
263
|
-
"@geekmidas/schema": "^10.0.0-alpha.
|
|
264
|
-
"@geekmidas/services": "^10.0.0-alpha.
|
|
268
|
+
"@geekmidas/envkit": "^10.0.0-alpha.39",
|
|
269
|
+
"@geekmidas/errors": "^10.0.0-alpha.39",
|
|
270
|
+
"@geekmidas/events": "^10.0.0-alpha.39",
|
|
271
|
+
"@geekmidas/logger": "^10.0.0-alpha.39",
|
|
272
|
+
"@geekmidas/manifest": "^10.0.0-alpha.39",
|
|
273
|
+
"@geekmidas/schema": "^10.0.0-alpha.39",
|
|
274
|
+
"@geekmidas/services": "^10.0.0-alpha.39"
|
|
265
275
|
},
|
|
266
276
|
"devDependencies": {
|
|
267
277
|
"@better-auth/expo": "~1.7.6",
|
|
@@ -277,20 +287,20 @@
|
|
|
277
287
|
"msw": "~2.15.0",
|
|
278
288
|
"pg": "~8.23.0",
|
|
279
289
|
"zod": "~4.6.5",
|
|
280
|
-
"@geekmidas/audit": "^10.0.0-alpha.
|
|
281
|
-
"@geekmidas/auth": "10.0.0-alpha.
|
|
282
|
-
"@geekmidas/cache": "^10.0.0-alpha.
|
|
283
|
-
"@geekmidas/db": "^10.0.0-alpha.
|
|
284
|
-
"@geekmidas/emailkit": "^10.0.0-alpha.
|
|
285
|
-
"@geekmidas/envkit": "^10.0.0-alpha.
|
|
286
|
-
"@geekmidas/errors": "^10.0.0-alpha.
|
|
287
|
-
"@geekmidas/events": "^10.0.0-alpha.
|
|
288
|
-
"@geekmidas/logger": "^10.0.0-alpha.
|
|
289
|
-
"@geekmidas/rate-limit": "^10.0.0-alpha.
|
|
290
|
-
"@geekmidas/schema": "^10.0.0-alpha.
|
|
291
|
-
"@geekmidas/services": "^10.0.0-alpha.
|
|
292
|
-
"@geekmidas/telescope": "10.0.0-alpha.
|
|
293
|
-
"@geekmidas/testkit": "^10.0.0-alpha.
|
|
290
|
+
"@geekmidas/audit": "^10.0.0-alpha.39",
|
|
291
|
+
"@geekmidas/auth": "10.0.0-alpha.39",
|
|
292
|
+
"@geekmidas/cache": "^10.0.0-alpha.39",
|
|
293
|
+
"@geekmidas/db": "^10.0.0-alpha.39",
|
|
294
|
+
"@geekmidas/emailkit": "^10.0.0-alpha.39",
|
|
295
|
+
"@geekmidas/envkit": "^10.0.0-alpha.39",
|
|
296
|
+
"@geekmidas/errors": "^10.0.0-alpha.39",
|
|
297
|
+
"@geekmidas/events": "^10.0.0-alpha.39",
|
|
298
|
+
"@geekmidas/logger": "^10.0.0-alpha.39",
|
|
299
|
+
"@geekmidas/rate-limit": "^10.0.0-alpha.39",
|
|
300
|
+
"@geekmidas/schema": "^10.0.0-alpha.39",
|
|
301
|
+
"@geekmidas/services": "^10.0.0-alpha.39",
|
|
302
|
+
"@geekmidas/telescope": "10.0.0-alpha.39",
|
|
303
|
+
"@geekmidas/testkit": "^10.0.0-alpha.39"
|
|
294
304
|
},
|
|
295
305
|
"peerDependencies": {
|
|
296
306
|
"@middy/core": ">=7.9.2",
|
|
@@ -300,15 +310,15 @@
|
|
|
300
310
|
"kysely": "~0.29.6",
|
|
301
311
|
"msw": ">=2.15.0",
|
|
302
312
|
"pg": ">=8.23.0",
|
|
303
|
-
"@geekmidas/audit": "^10.0.0-alpha.
|
|
304
|
-
"@geekmidas/auth": "10.0.0-alpha.
|
|
305
|
-
"@geekmidas/cache": "^10.0.0-alpha.
|
|
306
|
-
"@geekmidas/db": "^10.0.0-alpha.
|
|
307
|
-
"@geekmidas/emailkit": "^10.0.0-alpha.
|
|
308
|
-
"@geekmidas/rate-limit": "^10.0.0-alpha.
|
|
309
|
-
"@geekmidas/storage": "^10.0.0-alpha.
|
|
310
|
-
"@geekmidas/telescope": "10.0.0-alpha.
|
|
311
|
-
"@geekmidas/testkit": "^10.0.0-alpha.
|
|
313
|
+
"@geekmidas/audit": "^10.0.0-alpha.39",
|
|
314
|
+
"@geekmidas/auth": "10.0.0-alpha.39",
|
|
315
|
+
"@geekmidas/cache": "^10.0.0-alpha.39",
|
|
316
|
+
"@geekmidas/db": "^10.0.0-alpha.39",
|
|
317
|
+
"@geekmidas/emailkit": "^10.0.0-alpha.39",
|
|
318
|
+
"@geekmidas/rate-limit": "^10.0.0-alpha.39",
|
|
319
|
+
"@geekmidas/storage": "^10.0.0-alpha.39",
|
|
320
|
+
"@geekmidas/telescope": "10.0.0-alpha.39",
|
|
321
|
+
"@geekmidas/testkit": "^10.0.0-alpha.39"
|
|
312
322
|
},
|
|
313
323
|
"peerDependenciesMeta": {
|
|
314
324
|
"@geekmidas/audit": {
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { t as StandardSchemaV1 } from "./index-CeEtxDmK.cjs";
|
|
2
|
-
import { EventPublisher, MappedEvent } from "@geekmidas/events";
|
|
3
|
-
import { Logger } from "@geekmidas/logger";
|
|
4
|
-
import { Service, ServiceContext } from "@geekmidas/services";
|
|
5
|
-
import { AuditStorage } from "@geekmidas/audit";
|
|
6
|
-
import { SniffResult } from "@geekmidas/envkit/sniffer";
|
|
7
|
-
//#region src/Construct.d.ts
|
|
8
|
-
/**
|
|
9
|
-
* Noop context for environment sniffing.
|
|
10
|
-
* Used when calling service.register() to detect env vars without a real request.
|
|
11
|
-
* Returns dummy values since services should only use context in instance methods,
|
|
12
|
-
* not during registration.
|
|
13
|
-
*/
|
|
14
|
-
declare const snifferContext: ServiceContext;
|
|
15
|
-
declare abstract class Construct<TLogger extends Logger = Logger, TServiceName extends string = string, T extends EventPublisher<any> | undefined = undefined, OutSchema extends StandardSchemaV1 | undefined = undefined, TServices extends Service[] = [], TAuditStorageServiceName extends string = string, TAuditStorage extends AuditStorage | undefined = undefined, TDatabaseServiceName extends string = string, TDatabase = unknown> {
|
|
16
|
-
readonly type: ConstructType;
|
|
17
|
-
readonly logger: TLogger;
|
|
18
|
-
readonly services: TServices;
|
|
19
|
-
readonly events: MappedEvent<T, any>[];
|
|
20
|
-
readonly publisherService?: Service<TServiceName, T>;
|
|
21
|
-
outputSchema?: OutSchema | undefined;
|
|
22
|
-
readonly timeout?: number | undefined;
|
|
23
|
-
readonly memorySize?: number | undefined;
|
|
24
|
-
readonly auditorStorageService?: Service<TAuditStorageServiceName, TAuditStorage>;
|
|
25
|
-
/**
|
|
26
|
-
* The constructs this one declared an edge to, by id.
|
|
27
|
-
*
|
|
28
|
-
* What the manifest records. `services` is the same information in the
|
|
29
|
-
* form a handler runs with — clients, keyed by name — and an id cannot be
|
|
30
|
-
* recovered from one of those reliably, so both are kept.
|
|
31
|
-
*
|
|
32
|
-
* Last in the list because every other parameter is positional and already
|
|
33
|
-
* spoken for; a new one anywhere else silently rebinds existing callers.
|
|
34
|
-
*/
|
|
35
|
-
readonly constructs: string[];
|
|
36
|
-
/** Database service for this construct (used by Endpoint for RLS/audit context) */
|
|
37
|
-
databaseService?: Service<TDatabaseServiceName, TDatabase>;
|
|
38
|
-
/**
|
|
39
|
-
* The deploy unit that runs this, by construct id.
|
|
40
|
-
*
|
|
41
|
-
* What an endpoint's `surface` is to it, and for the same reason: something
|
|
42
|
-
* has to say which process a runnable belongs to, and until this existed the
|
|
43
|
-
* only thing that said so was the directory its file sat in. Set by the
|
|
44
|
-
* factory it was built from — `worker.crons`, `api.get(…)` — so it is
|
|
45
|
-
* carried rather than configured.
|
|
46
|
-
*
|
|
47
|
-
* Undefined for a construct built from a free-standing builder, which is
|
|
48
|
-
* still how `c`, `s` and `f` work.
|
|
49
|
-
*/
|
|
50
|
-
owner?: string;
|
|
51
|
-
constructor(type: ConstructType, logger: TLogger, services: TServices, events?: MappedEvent<T, any>[], publisherService?: Service<TServiceName, T>, outputSchema?: OutSchema | undefined, timeout?: number | undefined, memorySize?: number | undefined, auditorStorageService?: Service<TAuditStorageServiceName, TAuditStorage>,
|
|
52
|
-
/**
|
|
53
|
-
* The constructs this one declared an edge to, by id.
|
|
54
|
-
*
|
|
55
|
-
* What the manifest records. `services` is the same information in the
|
|
56
|
-
* form a handler runs with — clients, keyed by name — and an id cannot be
|
|
57
|
-
* recovered from one of those reliably, so both are kept.
|
|
58
|
-
*
|
|
59
|
-
* Last in the list because every other parameter is positional and already
|
|
60
|
-
* spoken for; a new one anywhere else silently rebinds existing callers.
|
|
61
|
-
*/
|
|
62
|
-
constructs?: string[]);
|
|
63
|
-
/**
|
|
64
|
-
* Returns an array of environment variable names required by this construct's services.
|
|
65
|
-
* This is determined by running a "sniffer" EnvironmentParser through each service's
|
|
66
|
-
* register method to track which environment variables are accessed.
|
|
67
|
-
*
|
|
68
|
-
* Results are cached per service class to handle singleton patterns where
|
|
69
|
-
* subsequent register() calls may short-circuit and not access env vars.
|
|
70
|
-
*
|
|
71
|
-
* @param markOptional - When true, optional vars (those accessed via `.optional()` or
|
|
72
|
-
* `.default()`) are suffixed with `?` in the returned array (e.g. `'PORT?'`).
|
|
73
|
-
* @returns Promise that resolves to array of environment variable names, sorted alphabetically
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```typescript
|
|
77
|
-
* const endpoint = e
|
|
78
|
-
* .services([databaseService, authService])
|
|
79
|
-
* .get('/users')
|
|
80
|
-
* .handle(async () => []);
|
|
81
|
-
*
|
|
82
|
-
* await endpoint.getEnvironment(); // ['AUTH_SECRET', 'DATABASE_URL']
|
|
83
|
-
* await endpoint.getEnvironment({ markOptional: true }); // ['AUTH_SECRET', 'DATABASE_URL', 'PORT?']
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
getEnvironment(opts?: {
|
|
87
|
-
markOptional?: boolean;
|
|
88
|
-
}): Promise<string[]>;
|
|
89
|
-
}
|
|
90
|
-
declare enum ConstructType {
|
|
91
|
-
Cron = "dev.geekmidas.function.cron",
|
|
92
|
-
Endpoint = "dev.geekmidas.function.endpoint",
|
|
93
|
-
Function = "dev.geekmidas.function.function",
|
|
94
|
-
Subscriber = "dev.geekmidas.function.subscriber",
|
|
95
|
-
Queue = "dev.geekmidas.function.queue",
|
|
96
|
-
Topic = "dev.geekmidas.resource.topic"
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Utility to test sniffing a service for environment variables.
|
|
100
|
-
* Useful for debugging services that throw errors during sniffing.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* import { sniffService } from '@geekmidas/constructs';
|
|
105
|
-
* import { authService } from './services/AuthService';
|
|
106
|
-
*
|
|
107
|
-
* const result = await sniffService(authService);
|
|
108
|
-
* console.log('Env vars:', result.envVars);
|
|
109
|
-
* console.log('Error:', result.error);
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
declare function sniffService(service: Service): Promise<SniffResult>;
|
|
113
|
-
//#endregion
|
|
114
|
-
export { snifferContext as i, ConstructType as n, sniffService as r, Construct as t };
|
|
115
|
-
//# sourceMappingURL=Construct-DTqYvkPG.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Construct-DTqYvkPG.d.cts","names":[],"sources":["../src/Construct.ts"],"mappings":";;;;;;;;;;;;;cA0BM,gBAAgB;uBAsBA,UACrB,gBAAgB,SAAS,QACzB,sCACA,UAAU,6CACV,kBAAkB,0CAClB,kBAAkB,gBAClB,kDACA,sBAAsB,sCACtB,8CACA;WAoBiB,MAAM;WACN,QAAQ;WACR,UAAU;WACV,QAAQ,YAAY;WACpB,mBAAmB,QAAQ,cAAc;EAClD,eAAe;WACN;WACA;WACA,wBAAwB,QACvC,0BACA;;;;;;;;;;;WAYe;;EAvCV,kBAAkB,QAAQ,sBAAsB;;;;;;;;;;;;;EAchD;EAEP,YACiB,MAAM,eACN,QAAQ,SACR,UAAU,WACV,SAAQ,YAAY,WACpB,mBAAmB,QAAQ,cAAc,IAClD,eAAe,uBACN,8BACA,iCACA,wBAAwB,QACvC,0BACA,gBAYe;;;;;;;;;;;EAAA;;;;;;;;;;;;;;;;;;;;;;;;EA0BX,eACL;IAAQ;MACN;;aAiEQ;EACX;EACA;EACA;EACA;EACA;EACA;;;;;;;;;;;;;;;;iBAiBqB,aAAa,SAAS,UAAU,QAAQ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Construct-Detz65RA.mjs","names":["compact"],"sources":["../../../node_modules/.pnpm/lodash.compact@3.0.1/node_modules/lodash.compact/index.js","../src/Construct.ts"],"sourcesContent":["/**\n * lodash 3.0.1 (Custom Build) <https://lodash.com/>\n * Build: `lodash modularize exports=\"npm\" -o ./`\n * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>\n * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\n * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n * Available under MIT license <https://lodash.com/license>\n */\n\n/**\n * Creates an array with all falsey values removed. The values `false`, `null`,\n * `0`, `\"\"`, `undefined`, and `NaN` are falsey.\n *\n * @static\n * @memberOf _\n * @category Array\n * @param {Array} array The array to compact.\n * @returns {Array} Returns the new array of filtered values.\n * @example\n *\n * _.compact([0, 1, false, 2, '', 3]);\n * // => [1, 2, 3]\n */\nfunction compact(array) {\n var index = -1,\n length = array ? array.length : 0,\n resIndex = 0,\n result = [];\n\n while (++index < length) {\n var value = array[index];\n if (value) {\n result[resIndex++] = value;\n }\n }\n return result;\n}\n\nmodule.exports = compact;\n","import type { AuditStorage } from '@geekmidas/audit';\nimport {\n\tSnifferEnvironmentParser,\n\ttype SniffResult,\n\tsniffWithFireAndForget,\n} from '@geekmidas/envkit/sniffer';\nimport type { EventPublisher, MappedEvent } from '@geekmidas/events';\nimport type { Logger } from '@geekmidas/logger';\nimport type { Service, ServiceContext } from '@geekmidas/services';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport compact from 'lodash.compact';\n\n// Cache for service environment variables to handle singleton services\n// Stores both the full list and the optional subset so the same sniff result\n// can satisfy both getEnvironment() and getEnvironment({ markOptional: true }).\nconst serviceEnvCache = new Map<\n\tService,\n\t{ envVars: string[]; optionalEnvVars: string[] }\n>();\n\n/**\n * Noop context for environment sniffing.\n * Used when calling service.register() to detect env vars without a real request.\n * Returns dummy values since services should only use context in instance methods,\n * not during registration.\n */\nconst snifferContext: ServiceContext = {\n\tgetLogger() {\n\t\t// Return a noop logger for sniffing - services shouldn't log during registration\n\t\treturn {\n\t\t\tdebug: () => {},\n\t\t\tinfo: () => {},\n\t\t\twarn: () => {},\n\t\t\terror: () => {},\n\t\t\tchild: () => snifferContext.getLogger(),\n\t\t} as unknown as Logger;\n\t},\n\tgetRequestId() {\n\t\treturn 'sniffer-context';\n\t},\n\tgetRequestStartTime() {\n\t\treturn Date.now();\n\t},\n\thasContext() {\n\t\treturn false;\n\t},\n};\n\nexport abstract class Construct<\n\tTLogger extends Logger = Logger,\n\tTServiceName extends string = string,\n\tT extends EventPublisher<any> | undefined = undefined,\n\tOutSchema extends StandardSchemaV1 | undefined = undefined,\n\tTServices extends Service[] = [],\n\tTAuditStorageServiceName extends string = string,\n\tTAuditStorage extends AuditStorage | undefined = undefined,\n\tTDatabaseServiceName extends string = string,\n\tTDatabase = unknown,\n> {\n\t/** Database service for this construct (used by Endpoint for RLS/audit context) */\n\tpublic databaseService?: Service<TDatabaseServiceName, TDatabase>;\n\n\t/**\n\t * The deploy unit that runs this, by construct id.\n\t *\n\t * What an endpoint's `surface` is to it, and for the same reason: something\n\t * has to say which process a runnable belongs to, and until this existed the\n\t * only thing that said so was the directory its file sat in. Set by the\n\t * factory it was built from — `worker.crons`, `api.get(…)` — so it is\n\t * carried rather than configured.\n\t *\n\t * Undefined for a construct built from a free-standing builder, which is\n\t * still how `c`, `s` and `f` work.\n\t */\n\tpublic owner?: string;\n\n\tconstructor(\n\t\tpublic readonly type: ConstructType,\n\t\tpublic readonly logger: TLogger,\n\t\tpublic readonly services: TServices,\n\t\tpublic readonly events: MappedEvent<T, any>[] = [],\n\t\tpublic readonly publisherService?: Service<TServiceName, T>,\n\t\tpublic outputSchema?: OutSchema,\n\t\tpublic readonly timeout?: number,\n\t\tpublic readonly memorySize?: number,\n\t\tpublic readonly auditorStorageService?: Service<\n\t\t\tTAuditStorageServiceName,\n\t\t\tTAuditStorage\n\t\t>,\n\t\t/**\n\t\t * The constructs this one declared an edge to, by id.\n\t\t *\n\t\t * What the manifest records. `services` is the same information in the\n\t\t * form a handler runs with — clients, keyed by name — and an id cannot be\n\t\t * recovered from one of those reliably, so both are kept.\n\t\t *\n\t\t * Last in the list because every other parameter is positional and already\n\t\t * spoken for; a new one anywhere else silently rebinds existing callers.\n\t\t */\n\t\tpublic readonly constructs: string[] = [],\n\t) {}\n\n\t/**\n\t * Returns an array of environment variable names required by this construct's services.\n\t * This is determined by running a \"sniffer\" EnvironmentParser through each service's\n\t * register method to track which environment variables are accessed.\n\t *\n\t * Results are cached per service class to handle singleton patterns where\n\t * subsequent register() calls may short-circuit and not access env vars.\n\t *\n\t * @param markOptional - When true, optional vars (those accessed via `.optional()` or\n\t * `.default()`) are suffixed with `?` in the returned array (e.g. `'PORT?'`).\n\t * @returns Promise that resolves to array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const endpoint = e\n\t * .services([databaseService, authService])\n\t * .get('/users')\n\t * .handle(async () => []);\n\t *\n\t * await endpoint.getEnvironment(); // ['AUTH_SECRET', 'DATABASE_URL']\n\t * await endpoint.getEnvironment({ markOptional: true }); // ['AUTH_SECRET', 'DATABASE_URL', 'PORT?']\n\t * ```\n\t */\n\tasync getEnvironment(\n\t\topts: { markOptional?: boolean } = {},\n\t): Promise<string[]> {\n\t\tconst { markOptional = false } = opts;\n\t\tconst envVars = new Set<string>();\n\t\tconst optionalVars = new Set<string>();\n\t\tconst services: Service[] = compact([\n\t\t\t...this.services,\n\t\t\tthis.publisherService,\n\t\t\tthis.publisherService,\n\t\t\tthis.auditorStorageService,\n\t\t\tthis.databaseService,\n\t\t]);\n\n\t\ttry {\n\t\t\tfor (const service of services) {\n\t\t\t\t// Check cache first - handles singleton services that short-circuit\n\t\t\t\tif (serviceEnvCache.has(service)) {\n\t\t\t\t\tconst cached = serviceEnvCache.get(service)!;\n\t\t\t\t\tcached.envVars.forEach((v) => envVars.add(v));\n\t\t\t\t\tcached.optionalEnvVars.forEach((v) => optionalVars.add(v));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Use sniffService to properly handle all error scenarios\n\t\t\t\tconst result = await sniffService(service);\n\n\t\t\t\t// Log any issues for debugging\n\t\t\t\tif (result.error) {\n\t\t\t\t\tthis.logger.warn(\n\t\t\t\t\t\t{ error: result.error.message, service: service.serviceName },\n\t\t\t\t\t\t'Service threw error during env sniffing (env vars still captured)',\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (result.unhandledRejections.length > 0) {\n\t\t\t\t\tthis.logger.warn(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\terrors: result.unhandledRejections.map((e) => e.message),\n\t\t\t\t\t\t\tservice: service.serviceName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t'Fire-and-forget rejections during env sniffing (suppressed)',\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Cache and collect env vars (both required and optional)\n\t\t\t\tserviceEnvCache.set(service, {\n\t\t\t\t\tenvVars: result.envVars,\n\t\t\t\t\toptionalEnvVars: result.optionalEnvVars,\n\t\t\t\t});\n\t\t\t\tresult.envVars.forEach((v) => envVars.add(v));\n\t\t\t\tresult.optionalEnvVars.forEach((v) => optionalVars.add(v));\n\t\t\t}\n\n\t\t\tconst sorted = Array.from(envVars).sort();\n\t\t\tif (!markOptional || optionalVars.size === 0) return sorted;\n\t\t\treturn sorted.map((v) => (optionalVars.has(v) ? `${v}?` : v));\n\t\t} catch (error) {\n\t\t\tthis.logger.error(\n\t\t\t\t{ error },\n\t\t\t\t'Error determining environment variables for construct',\n\t\t\t);\n\n\t\t\treturn [];\n\t\t}\n\t}\n}\n\nexport enum ConstructType {\n\tCron = 'dev.geekmidas.function.cron',\n\tEndpoint = 'dev.geekmidas.function.endpoint',\n\tFunction = 'dev.geekmidas.function.function',\n\tSubscriber = 'dev.geekmidas.function.subscriber',\n\tQueue = 'dev.geekmidas.function.queue',\n\tTopic = 'dev.geekmidas.resource.topic',\n}\n\n/**\n * Utility to test sniffing a service for environment variables.\n * Useful for debugging services that throw errors during sniffing.\n *\n * @example\n * ```typescript\n * import { sniffService } from '@geekmidas/constructs';\n * import { authService } from './services/AuthService';\n *\n * const result = await sniffService(authService);\n * console.log('Env vars:', result.envVars);\n * console.log('Error:', result.error);\n * ```\n */\nexport async function sniffService(service: Service): Promise<SniffResult> {\n\tconst sniffer = new SnifferEnvironmentParser();\n\n\treturn sniffWithFireAndForget(sniffer, () =>\n\t\tservice.register({\n\t\t\tenvParser: sniffer as any,\n\t\t\tcontext: snifferContext,\n\t\t}),\n\t);\n}\n\n// Export for testing\nexport { snifferContext };\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuBA,SAAS,QAAQ,OAAO;EACtB,IAAI,QAAQ,IACR,SAAS,QAAQ,MAAM,SAAS,GAChC,WAAW,GACX,SAAS,CAAC;EAEd,OAAO,EAAE,QAAQ,QAAQ;GACvB,IAAI,QAAQ,MAAM;GAClB,IAAI,OACF,OAAO,cAAc;EAEzB;EACA,OAAO;CACT;CAEA,OAAO,UAAU;;ACvBjB,MAAM,kCAAkB,IAAI,IAG1B;;;;;;;AAQF,MAAM,iBAAiC;CACtC,YAAY;EAEX,OAAO;GACN,aAAa,CAAC;GACd,YAAY,CAAC;GACb,YAAY,CAAC;GACb,aAAa,CAAC;GACd,aAAa,eAAe,UAAU;EACvC;CACD;CACA,eAAe;EACd,OAAO;CACR;CACA,sBAAsB;EACrB,OAAO,KAAK,IAAI;CACjB;CACA,aAAa;EACZ,OAAO;CACR;AACD;AAEA,IAAsB,YAAtB,MAUE;CAmBgB;CACA;CACA;CACA;CACA;CACT;CACS;CACA;CACA;CAcA;;CAvCjB;;;;;;;;;;;;;CAcA;CAEA,YACC,MACA,QACA,UACA,SAAgD,CAAC,GACjD,kBACA,cACA,SACA,YACA,uBAcA,aAAuC,CAAC,GACvC;EAvBe,KAAA,OAAA;EACA,KAAA,SAAA;EACA,KAAA,WAAA;EACA,KAAA,SAAA;EACA,KAAA,mBAAA;EACT,KAAA,eAAA;EACS,KAAA,UAAA;EACA,KAAA,aAAA;EACA,KAAA,wBAAA;EAcA,KAAA,aAAA;CACd;;;;;;;;;;;;;;;;;;;;;;;;CAyBH,MAAM,eACL,OAAmC,CAAC,GAChB;EACpB,MAAM,EAAE,eAAe,UAAU;EACjC,MAAM,0BAAU,IAAI,IAAY;EAChC,MAAM,+BAAe,IAAI,IAAY;EACrC,MAAM,YAAA,GAAsBA,sBAAAA,QAAAA,CAAQ;GACnC,GAAG,KAAK;GACR,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;EACN,CAAC;EAED,IAAI;GACH,KAAK,MAAM,WAAW,UAAU;IAE/B,IAAI,gBAAgB,IAAI,OAAO,GAAG;KACjC,MAAM,SAAS,gBAAgB,IAAI,OAAO;KAC1C,OAAO,QAAQ,SAAS,MAAM,QAAQ,IAAI,CAAC,CAAC;KAC5C,OAAO,gBAAgB,SAAS,MAAM,aAAa,IAAI,CAAC,CAAC;KACzD;IACD;IAGA,MAAM,SAAS,MAAM,aAAa,OAAO;IAGzC,IAAI,OAAO,OACV,KAAK,OAAO,KACX;KAAE,OAAO,OAAO,MAAM;KAAS,SAAS,QAAQ;IAAY,GAC5D,mEACD;IAED,IAAI,OAAO,oBAAoB,SAAS,GACvC,KAAK,OAAO,KACX;KACC,QAAQ,OAAO,oBAAoB,KAAK,MAAM,EAAE,OAAO;KACvD,SAAS,QAAQ;IAClB,GACA,6DACD;IAID,gBAAgB,IAAI,SAAS;KAC5B,SAAS,OAAO;KAChB,iBAAiB,OAAO;IACzB,CAAC;IACD,OAAO,QAAQ,SAAS,MAAM,QAAQ,IAAI,CAAC,CAAC;IAC5C,OAAO,gBAAgB,SAAS,MAAM,aAAa,IAAI,CAAC,CAAC;GAC1D;GAEA,MAAM,SAAS,MAAM,KAAK,OAAO,CAAC,CAAC,KAAK;GACxC,IAAI,CAAC,gBAAgB,aAAa,SAAS,GAAG,OAAO;GACrD,OAAO,OAAO,KAAK,MAAO,aAAa,IAAI,CAAC,IAAI,GAAG,EAAE,KAAK,CAAE;EAC7D,SAAS,OAAO;GACf,KAAK,OAAO,MACX,EAAE,MAAM,GACR,uDACD;GAEA,OAAO,CAAC;EACT;CACD;AACD;AAEA,IAAY,gBAAL,yBAAA,eAAA;CACN,cAAA,UAAA;CACA,cAAA,cAAA;CACA,cAAA,cAAA;CACA,cAAA,gBAAA;CACA,cAAA,WAAA;CACA,cAAA,WAAA;;AACD,EAAA,CAAA,CAAA;;;;;;;;;;;;;;;AAgBA,eAAsB,aAAa,SAAwC;CAC1E,MAAM,UAAU,IAAI,yBAAyB;CAE7C,OAAO,uBAAuB,eAC7B,QAAQ,SAAS;EAChB,WAAW;EACX,SAAS;CACV,CAAC,CACF;AACD"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { t as StandardSchemaV1 } from "./index-CeEtxDmK.mjs";
|
|
2
|
-
import { SniffResult } from "@geekmidas/envkit/sniffer";
|
|
3
|
-
import { EventPublisher, MappedEvent } from "@geekmidas/events";
|
|
4
|
-
import { Service, ServiceContext } from "@geekmidas/services";
|
|
5
|
-
import { AuditStorage } from "@geekmidas/audit";
|
|
6
|
-
import { Logger } from "@geekmidas/logger";
|
|
7
|
-
//#region src/Construct.d.ts
|
|
8
|
-
/**
|
|
9
|
-
* Noop context for environment sniffing.
|
|
10
|
-
* Used when calling service.register() to detect env vars without a real request.
|
|
11
|
-
* Returns dummy values since services should only use context in instance methods,
|
|
12
|
-
* not during registration.
|
|
13
|
-
*/
|
|
14
|
-
declare const snifferContext: ServiceContext;
|
|
15
|
-
declare abstract class Construct<TLogger extends Logger = Logger, TServiceName extends string = string, T extends EventPublisher<any> | undefined = undefined, OutSchema extends StandardSchemaV1 | undefined = undefined, TServices extends Service[] = [], TAuditStorageServiceName extends string = string, TAuditStorage extends AuditStorage | undefined = undefined, TDatabaseServiceName extends string = string, TDatabase = unknown> {
|
|
16
|
-
readonly type: ConstructType;
|
|
17
|
-
readonly logger: TLogger;
|
|
18
|
-
readonly services: TServices;
|
|
19
|
-
readonly events: MappedEvent<T, any>[];
|
|
20
|
-
readonly publisherService?: Service<TServiceName, T>;
|
|
21
|
-
outputSchema?: OutSchema | undefined;
|
|
22
|
-
readonly timeout?: number | undefined;
|
|
23
|
-
readonly memorySize?: number | undefined;
|
|
24
|
-
readonly auditorStorageService?: Service<TAuditStorageServiceName, TAuditStorage>;
|
|
25
|
-
/**
|
|
26
|
-
* The constructs this one declared an edge to, by id.
|
|
27
|
-
*
|
|
28
|
-
* What the manifest records. `services` is the same information in the
|
|
29
|
-
* form a handler runs with — clients, keyed by name — and an id cannot be
|
|
30
|
-
* recovered from one of those reliably, so both are kept.
|
|
31
|
-
*
|
|
32
|
-
* Last in the list because every other parameter is positional and already
|
|
33
|
-
* spoken for; a new one anywhere else silently rebinds existing callers.
|
|
34
|
-
*/
|
|
35
|
-
readonly constructs: string[];
|
|
36
|
-
/** Database service for this construct (used by Endpoint for RLS/audit context) */
|
|
37
|
-
databaseService?: Service<TDatabaseServiceName, TDatabase>;
|
|
38
|
-
/**
|
|
39
|
-
* The deploy unit that runs this, by construct id.
|
|
40
|
-
*
|
|
41
|
-
* What an endpoint's `surface` is to it, and for the same reason: something
|
|
42
|
-
* has to say which process a runnable belongs to, and until this existed the
|
|
43
|
-
* only thing that said so was the directory its file sat in. Set by the
|
|
44
|
-
* factory it was built from — `worker.crons`, `api.get(…)` — so it is
|
|
45
|
-
* carried rather than configured.
|
|
46
|
-
*
|
|
47
|
-
* Undefined for a construct built from a free-standing builder, which is
|
|
48
|
-
* still how `c`, `s` and `f` work.
|
|
49
|
-
*/
|
|
50
|
-
owner?: string;
|
|
51
|
-
constructor(type: ConstructType, logger: TLogger, services: TServices, events?: MappedEvent<T, any>[], publisherService?: Service<TServiceName, T>, outputSchema?: OutSchema | undefined, timeout?: number | undefined, memorySize?: number | undefined, auditorStorageService?: Service<TAuditStorageServiceName, TAuditStorage>,
|
|
52
|
-
/**
|
|
53
|
-
* The constructs this one declared an edge to, by id.
|
|
54
|
-
*
|
|
55
|
-
* What the manifest records. `services` is the same information in the
|
|
56
|
-
* form a handler runs with — clients, keyed by name — and an id cannot be
|
|
57
|
-
* recovered from one of those reliably, so both are kept.
|
|
58
|
-
*
|
|
59
|
-
* Last in the list because every other parameter is positional and already
|
|
60
|
-
* spoken for; a new one anywhere else silently rebinds existing callers.
|
|
61
|
-
*/
|
|
62
|
-
constructs?: string[]);
|
|
63
|
-
/**
|
|
64
|
-
* Returns an array of environment variable names required by this construct's services.
|
|
65
|
-
* This is determined by running a "sniffer" EnvironmentParser through each service's
|
|
66
|
-
* register method to track which environment variables are accessed.
|
|
67
|
-
*
|
|
68
|
-
* Results are cached per service class to handle singleton patterns where
|
|
69
|
-
* subsequent register() calls may short-circuit and not access env vars.
|
|
70
|
-
*
|
|
71
|
-
* @param markOptional - When true, optional vars (those accessed via `.optional()` or
|
|
72
|
-
* `.default()`) are suffixed with `?` in the returned array (e.g. `'PORT?'`).
|
|
73
|
-
* @returns Promise that resolves to array of environment variable names, sorted alphabetically
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```typescript
|
|
77
|
-
* const endpoint = e
|
|
78
|
-
* .services([databaseService, authService])
|
|
79
|
-
* .get('/users')
|
|
80
|
-
* .handle(async () => []);
|
|
81
|
-
*
|
|
82
|
-
* await endpoint.getEnvironment(); // ['AUTH_SECRET', 'DATABASE_URL']
|
|
83
|
-
* await endpoint.getEnvironment({ markOptional: true }); // ['AUTH_SECRET', 'DATABASE_URL', 'PORT?']
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
getEnvironment(opts?: {
|
|
87
|
-
markOptional?: boolean;
|
|
88
|
-
}): Promise<string[]>;
|
|
89
|
-
}
|
|
90
|
-
declare enum ConstructType {
|
|
91
|
-
Cron = "dev.geekmidas.function.cron",
|
|
92
|
-
Endpoint = "dev.geekmidas.function.endpoint",
|
|
93
|
-
Function = "dev.geekmidas.function.function",
|
|
94
|
-
Subscriber = "dev.geekmidas.function.subscriber",
|
|
95
|
-
Queue = "dev.geekmidas.function.queue",
|
|
96
|
-
Topic = "dev.geekmidas.resource.topic"
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Utility to test sniffing a service for environment variables.
|
|
100
|
-
* Useful for debugging services that throw errors during sniffing.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* import { sniffService } from '@geekmidas/constructs';
|
|
105
|
-
* import { authService } from './services/AuthService';
|
|
106
|
-
*
|
|
107
|
-
* const result = await sniffService(authService);
|
|
108
|
-
* console.log('Env vars:', result.envVars);
|
|
109
|
-
* console.log('Error:', result.error);
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
declare function sniffService(service: Service): Promise<SniffResult>;
|
|
113
|
-
//#endregion
|
|
114
|
-
export { snifferContext as i, ConstructType as n, sniffService as r, Construct as t };
|
|
115
|
-
//# sourceMappingURL=Construct-pVadmURD.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Construct-pVadmURD.d.mts","names":[],"sources":["../src/Construct.ts"],"mappings":";;;;;;;;;;;;;cA0BM,gBAAgB;uBAsBA,UACrB,gBAAgB,SAAS,QACzB,sCACA,UAAU,6CACV,kBAAkB,0CAClB,kBAAkB,gBAClB,kDACA,sBAAsB,sCACtB,8CACA;WAoBiB,MAAM;WACN,QAAQ;WACR,UAAU;WACV,QAAQ,YAAY;WACpB,mBAAmB,QAAQ,cAAc;EAClD,eAAe;WACN;WACA;WACA,wBAAwB,QACvC,0BACA;;;;;;;;;;;WAYe;;EAvCV,kBAAkB,QAAQ,sBAAsB;;;;;;;;;;;;;EAchD;EAEP,YACiB,MAAM,eACN,QAAQ,SACR,UAAU,WACV,SAAQ,YAAY,WACpB,mBAAmB,QAAQ,cAAc,IAClD,eAAe,uBACN,8BACA,iCACA,wBAAwB,QACvC,0BACA,gBAYe;;;;;;;;;;;EAAA;;;;;;;;;;;;;;;;;;;;;;;;EA0BX,eACL;IAAQ;MACN;;aAiEQ;EACX;EACA;EACA;EACA;EACA;EACA;;;;;;;;;;;;;;;;iBAiBqB,aAAa,SAAS,UAAU,QAAQ"}
|