@geekmidas/constructs 10.0.0-alpha.155 → 10.0.0-alpha.157
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 +24 -0
- package/dist/{Construct-DySlwh8o.d.mts → Construct-BMk_CRSD.d.mts} +2 -2
- package/dist/{Construct-DySlwh8o.d.mts.map → Construct-BMk_CRSD.d.mts.map} +1 -1
- package/dist/{Cron-D8mB_cPX.d.mts → Cron-D6Y7BBt3.d.mts} +5 -5
- package/dist/{Cron-D8mB_cPX.d.mts.map → Cron-D6Y7BBt3.d.mts.map} +1 -1
- package/dist/{CronBuilder-Cmajva3g.d.mts → CronBuilder-4BZhkChG.d.mts} +5 -5
- package/dist/{CronBuilder-Cmajva3g.d.mts.map → CronBuilder-4BZhkChG.d.mts.map} +1 -1
- package/dist/{Endpoint-BbHh3Qoc.d.mts → Endpoint-BUoDD96P.d.mts} +5 -5
- package/dist/{Endpoint-BbHh3Qoc.d.mts.map → Endpoint-BUoDD96P.d.mts.map} +1 -1
- package/dist/{EndpointFactory-qcLzi4f-.d.mts → EndpointFactory-BbVOeryo.d.mts} +5 -5
- package/dist/{EndpointFactory-qcLzi4f-.d.mts.map → EndpointFactory-BbVOeryo.d.mts.map} +1 -1
- package/dist/{Function-DfMzTGS4.d.mts → Function-BKReud5p.d.mts} +3 -3
- package/dist/{Function-DfMzTGS4.d.mts.map → Function-BKReud5p.d.mts.map} +1 -1
- package/dist/{HonoEndpointAdaptor-DR3j7S35.mjs → HonoEndpointAdaptor-2xHA3bvn.mjs} +5 -4
- package/dist/HonoEndpointAdaptor-2xHA3bvn.mjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-BXBdb2Bt.cjs → HonoEndpointAdaptor-CZ1TooUu.cjs} +6 -5
- package/dist/HonoEndpointAdaptor-CZ1TooUu.cjs.map +1 -0
- package/dist/{ObjectSubscriberBuilder-Cv8C7yS1.d.mts → ObjectSubscriberBuilder-DfzXQEKW.d.mts} +4 -4
- package/dist/{ObjectSubscriberBuilder-Cv8C7yS1.d.mts.map → ObjectSubscriberBuilder-DfzXQEKW.d.mts.map} +1 -1
- package/dist/ObjectSubscriberBuilder-LWkey_oq.d.cts.map +1 -1
- package/dist/{ProcessorBuilder-CwfP-M33.d.mts → ProcessorBuilder-D4oYvZeG.d.mts} +2 -2
- package/dist/{ProcessorBuilder-CwfP-M33.d.mts.map → ProcessorBuilder-D4oYvZeG.d.mts.map} +1 -1
- package/dist/{Queue-BnK3UH8r.d.mts → Queue-B8HGg439.d.mts} +3 -3
- package/dist/{Queue-BnK3UH8r.d.mts.map → Queue-B8HGg439.d.mts.map} +1 -1
- package/dist/{QueueBuilder-DmwFtLzQ.d.mts → QueueBuilder-CVS_qPuo.d.mts} +2 -2
- package/dist/{QueueBuilder-DmwFtLzQ.d.mts.map → QueueBuilder-CVS_qPuo.d.mts.map} +1 -1
- package/dist/{Subscriber-CW_Dl-YR.d.mts → Subscriber-CtQXhcL7.d.mts} +3 -3
- package/dist/{Subscriber-CW_Dl-YR.d.mts.map → Subscriber-CtQXhcL7.d.mts.map} +1 -1
- package/dist/{SubscriberBuilder-BL_GTcwh.mjs → SubscriberBuilder-CpFhShTJ.mjs} +3 -2
- package/dist/SubscriberBuilder-CpFhShTJ.mjs.map +1 -0
- package/dist/{SubscriberBuilder-CWzKwX1p.cjs → SubscriberBuilder-DJEvNRdD.cjs} +3 -2
- package/dist/SubscriberBuilder-DJEvNRdD.cjs.map +1 -0
- package/dist/adaptors/aws.cjs +18 -13
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/aws.d.cts.map +1 -1
- package/dist/adaptors/aws.d.mts +6 -6
- package/dist/adaptors/aws.d.mts.map +1 -1
- package/dist/adaptors/aws.mjs +17 -12
- package/dist/adaptors/aws.mjs.map +1 -1
- package/dist/adaptors/awsWebsocket.cjs +354 -0
- package/dist/adaptors/awsWebsocket.cjs.map +1 -0
- package/dist/adaptors/awsWebsocket.d.cts +156 -0
- package/dist/adaptors/awsWebsocket.d.cts.map +1 -0
- package/dist/adaptors/awsWebsocket.d.mts +156 -0
- package/dist/adaptors/awsWebsocket.d.mts.map +1 -0
- package/dist/adaptors/awsWebsocket.mjs +347 -0
- package/dist/adaptors/awsWebsocket.mjs.map +1 -0
- package/dist/adaptors/hono.cjs +1 -1
- package/dist/adaptors/hono.d.mts +2 -2
- package/dist/adaptors/hono.mjs +1 -1
- package/dist/adaptors/testing.cjs +19 -9
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/testing.d.cts +1 -1
- package/dist/adaptors/testing.d.cts.map +1 -1
- package/dist/adaptors/testing.d.mts +9 -9
- package/dist/adaptors/testing.d.mts.map +1 -1
- package/dist/adaptors/testing.mjs +17 -7
- package/dist/adaptors/testing.mjs.map +1 -1
- package/dist/auth-BqWz2JxC.d.cts.map +1 -1
- package/dist/auth-DnB9H9KL.d.mts.map +1 -1
- package/dist/auth.cjs +7 -21
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.mjs +6 -20
- package/dist/auth.mjs.map +1 -1
- package/dist/{cache-e3tfMQ9g.d.mts → cache-CCHcO9Oo.d.mts} +2 -2
- package/dist/cache-CCHcO9Oo.d.mts.map +1 -0
- package/dist/cache-CQjMNPrC.d.cts.map +1 -1
- package/dist/cache.cjs +3 -19
- package/dist/cache.cjs.map +1 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cache.mjs +2 -18
- package/dist/cache.mjs.map +1 -1
- package/dist/crons/index.cjs +2 -1
- package/dist/crons/index.cjs.map +1 -1
- package/dist/crons/index.d.cts.map +1 -1
- package/dist/crons/index.d.mts +2 -2
- package/dist/crons/index.d.mts.map +1 -1
- package/dist/crons/index.mjs +2 -1
- package/dist/crons/index.mjs.map +1 -1
- package/dist/database/kysely.d.mts +1 -1
- package/dist/email.cjs +4 -16
- package/dist/email.cjs.map +1 -1
- package/dist/email.d.cts.map +1 -1
- package/dist/email.d.mts.map +1 -1
- package/dist/email.mjs +2 -14
- package/dist/email.mjs.map +1 -1
- package/dist/endpoints/index.cjs +1 -1
- package/dist/endpoints/index.d.cts +1 -1
- package/dist/endpoints/index.d.cts.map +1 -1
- package/dist/endpoints/index.d.mts +4 -4
- package/dist/endpoints/index.d.mts.map +1 -1
- package/dist/endpoints/index.mjs +1 -1
- package/dist/file-server.d.mts +1 -1
- package/dist/functions/index.d.mts +2 -2
- package/dist/{inbox-CjxpLVkH.d.mts → inbox-YOdxlyfj.d.mts} +2 -2
- package/dist/{inbox-CjxpLVkH.d.mts.map → inbox-YOdxlyfj.d.mts.map} +1 -1
- package/dist/inbox.d.mts +1 -1
- package/dist/{index-DCkDQkwj.d.mts → index-BoQ3-M-K.d.mts} +4 -4
- package/dist/{index-DCkDQkwj.d.mts.map → index-BoQ3-M-K.d.mts.map} +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/{kysely-DE4kADWD.d.mts → kysely-De5rAC-E.d.mts} +2 -2
- package/dist/{kysely-DE4kADWD.d.mts.map → kysely-De5rAC-E.d.mts.map} +1 -1
- package/dist/optionalPeers-D7Wt6dnF.mjs +140 -0
- package/dist/optionalPeers-D7Wt6dnF.mjs.map +1 -0
- package/dist/optionalPeers-DuNQXXe1.cjs +223 -0
- package/dist/optionalPeers-DuNQXXe1.cjs.map +1 -0
- package/dist/origins-BjxYht13.cjs +96 -0
- package/dist/origins-BjxYht13.cjs.map +1 -0
- package/dist/origins-Boc9qbo-.mjs +73 -0
- package/dist/origins-Boc9qbo-.mjs.map +1 -0
- package/dist/privateAddress-Bg5fUsbp.mjs +21 -0
- package/dist/privateAddress-Bg5fUsbp.mjs.map +1 -0
- package/dist/privateAddress-CqGyuFHn.cjs +26 -0
- package/dist/privateAddress-CqGyuFHn.cjs.map +1 -0
- package/dist/processors/index.d.mts +1 -1
- package/dist/queue/index.d.mts +2 -2
- package/dist/{readRequestBody-BTIl3k-D.mjs → readRequestBody-BmKnPl0a.mjs} +26 -4
- package/dist/readRequestBody-BmKnPl0a.mjs.map +1 -0
- package/dist/{readRequestBody-Dej_L3c4.cjs → readRequestBody-CN9GVdeE.cjs} +26 -4
- package/dist/readRequestBody-CN9GVdeE.cjs.map +1 -0
- package/dist/{requestLogger-BZcXwdBs.cjs → requestLogger-CnoYd-Ah.cjs} +4 -63
- package/dist/requestLogger-CnoYd-Ah.cjs.map +1 -0
- package/dist/{requestLogger-pA4gi3E1.mjs → requestLogger-D2JS7pPM.mjs} +3 -56
- package/dist/requestLogger-D2JS7pPM.mjs.map +1 -0
- package/dist/rest-api.d.mts +2 -2
- package/dist/{runSubscriber-DyHWp_Lf.mjs → runSubscriber-HEqXkin1.mjs} +3 -2
- package/dist/runSubscriber-HEqXkin1.mjs.map +1 -0
- package/dist/{runSubscriber-CC_2C9F2.cjs → runSubscriber-sVJfLA0-.cjs} +3 -2
- package/dist/runSubscriber-sVJfLA0-.cjs.map +1 -0
- package/dist/subscribers/index.cjs +6 -6
- package/dist/subscribers/index.cjs.map +1 -1
- package/dist/subscribers/index.d.cts +1 -1
- package/dist/subscribers/index.d.mts +3 -3
- package/dist/subscribers/index.mjs +3 -3
- package/dist/subscribers/index.mjs.map +1 -1
- package/dist/topic/index.d.mts +1 -1
- package/dist/{websocket-api-Dn_3Y2fI.mjs → websocket-api-Bg9SowJ5.mjs} +452 -44
- package/dist/websocket-api-Bg9SowJ5.mjs.map +1 -0
- package/dist/{websocket-api-DSWDhZph.d.mts → websocket-api-CPEzJyDt.d.mts} +501 -208
- package/dist/websocket-api-CPEzJyDt.d.mts.map +1 -0
- package/dist/{websocket-api-CLnV_7CB.d.cts → websocket-api-DkF8Hva-.d.cts} +501 -208
- package/dist/websocket-api-DkF8Hva-.d.cts.map +1 -0
- package/dist/{websocket-api-9bXfgrqd.cjs → websocket-api-czxhekGG.cjs} +493 -43
- package/dist/websocket-api-czxhekGG.cjs.map +1 -0
- package/dist/websocket-api.cjs +11 -1
- package/dist/websocket-api.d.cts +2 -2
- package/dist/websocket-api.d.mts +2 -2
- package/dist/websocket-api.mjs +3 -2
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.mts +9 -9
- package/dist/worker.mjs +1 -1
- package/package.json +57 -31
- package/dist/HonoEndpointAdaptor-BXBdb2Bt.cjs.map +0 -1
- package/dist/HonoEndpointAdaptor-DR3j7S35.mjs.map +0 -1
- package/dist/SubscriberBuilder-BL_GTcwh.mjs.map +0 -1
- package/dist/SubscriberBuilder-CWzKwX1p.cjs.map +0 -1
- package/dist/cache-e3tfMQ9g.d.mts.map +0 -1
- package/dist/readRequestBody-BTIl3k-D.mjs.map +0 -1
- package/dist/readRequestBody-Dej_L3c4.cjs.map +0 -1
- package/dist/requestLogger-BZcXwdBs.cjs.map +0 -1
- package/dist/requestLogger-pA4gi3E1.mjs.map +0 -1
- package/dist/runSubscriber-CC_2C9F2.cjs.map +0 -1
- package/dist/runSubscriber-DyHWp_Lf.mjs.map +0 -1
- package/dist/websocket-api-9bXfgrqd.cjs.map +0 -1
- package/dist/websocket-api-CLnV_7CB.d.cts.map +0 -1
- package/dist/websocket-api-DSWDhZph.d.mts.map +0 -1
- package/dist/websocket-api-Dn_3Y2fI.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-BoQ3-M-K.d.mts","names":[],"sources":["../src/functions/BaseFunctionBuilder.ts","../src/functions/FunctionBuilder.ts"],"mappings":";;;;;;;;;uBAsBsB,oBACrB,eAAe,0BACf,kBAAkB,0CAClB,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,sBAAsB,sCACtB,kDACA,uBACA;EAoFmB,MAAI;YAlFb,cAAc;YACd,eAAe;YACf;EAEH,WAAW;;;;;;;;;EASX;EACA,SAAS;;;;;;;EAQT;;;;;;;;EASA;;EAGA,SAAS;YACN,kBAAkB,QAAQ,0BAA0B;YACpD,mBAAmB,QAAQ,sBAAsB;;YAEjD;SAEH,mBAAmB,aAAa,KAAK;SAM/B,8BACZ,UAAU,sCACT,eAAe,QAAQ,IAAI,QAAQ,8BAA8B;EAkCnE,YAAmB,OAAI;WAEd,SAAS,UAAU,WAAW,UAAU;WAExC,OAAO,UAAU,QAAQ,QAAQ;EAE1C,QAAQ;WAIC,OAAO,UAAU,kBAAkB,QAAQ;WAE3C,MAAM,UAAU,0BAA0B,QAAQ;;;;;;;YAQjD,UACT,OAAO,iBACP,OAAO,SAAS;EAcjB,QAAQ,UAAU,cAAc,sBAC/B,SAAS,QAAQ,OAAO,KACtB,oBACF,QACA,WACA,WACA,SACA,GACA,OACA,WACA;;;;;EAuBD,SAAS,GAAG,sBACX,QAAQ,WAAW,OAAO,KAAK,QAAQ,OAAO,KAC5C,oBACF,QACA,WACA,WACA,SACA,eACA,0BACA,GACA;;;;cCzKW,gBACZ,eAAe,0BACf,kBAAkB,0CAClB,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,sBAAsB,sCACtB,kDACA,uBACA,8CACA,qBAAqB,mCAAmC,0CAI/C,oBACT,QACA,WACA,WACA,SACA,eACA,0BACA,WACA;EAI4B,MAAI;YAFtB;EAEV,YAA4B,OAAI;EAIvB,QAAQ;EAIjB,WAAW;EAIX,OAAO,UAAU,kBAChB,QAAQ,IACN,gBACF,QACA,GACA,WACA,SACA,eACA,0BACA,WACA,sBACA;EAiBD,MAAM,UAAU,0BACf,QAAQ,IACN,gBACF,GACA,WACA,WACA,SACA,eACA,0BACA,WACA,sBACA;;;;;;;;;;;;EA4BD,gBAAgB,mBAAmB,cAClC,YAAY,IACV,gBACF,QACA,eACI,cAAc,WAAW,KAC7B,SACA,eACA,0BACA,WACA,sBACA;EA8BD,SAAS,UAAU,WAClB,UAAU,IACR,gBACF,QACA,eACI,cAAc,IAClB,SACA,eACA,0BACA,WACA,sBACA;EAoBD,OAAO,UAAU,QAChB,QAAQ,IACN,gBACF,QACA,WACA,WACA,GACA,eACA,0BACA,WACA,sBACA;;;;;;;EAuBD,MAAM,eAAe,iBACpB,OAAO,QACP,OAAO,SAAS,QAAQ,oBAAoB,cAC1C,gBACF,QACA,eACI,WAAW,oBACf,SACA,eACA,0BACA,WACA,sBACA;EAeQ,QAAQ,UAAU,cAAc,sBACxC,SAAS,QAAQ,OAAO,KACtB,gBACF,QACA,WACA,WACA,SACA,GACA,OACA,WACA,sBACA;;;;;EAwBD,QAAQ,UAAU,qCAAqC,gBACtD,QACA,WACA,WACA,SACA,eACA,0BACA,WACA,sBACA;;;;;EAmBQ,SAAS,GAAG,sBACpB,QAAQ,WAAW,OAAO,KAAK,QAAQ,OAAO,KAC5C,gBACF,QACA,WACA,WACA,SACA,eACA,0BACA,GACA,OACA;EAkCD,OACC,IAAI,gBACH,QACA,WACA,SACA,WACA,WACA,eACA,gBAEC,SACF,QACA,WACA,SACA,WACA,eACA,0BACA,WACA,sBACA,cACA,gBACC,QACA,WACA,SACA,WACA,WACA,eACA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as snifferContext, n as ConstructType, r as sniffService, t as Construct } from "./Construct-
|
|
1
|
+
import { i as snifferContext, n as ConstructType, r as sniffService, t as Construct } from "./Construct-BMk_CRSD.mjs";
|
|
2
2
|
import { n as LowerHttpMethod, r as RemoveUndefined, t as HttpMethod } from "./types-DMuSQeLL.mjs";
|
|
3
3
|
import { i as TelemetryResponse, n as TelemetryContext, r as TelemetryRequest, t as Telemetry } from "./lambdaTelemetry-8vnmVZQ5.mjs";
|
|
4
4
|
import { a as Stages, i as SeedContext, n as DeployedStage, o as TestStage, r as LocalStage, t as AnyStage } from "./stages-DaTaoQei.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as Construct } from "./construct-interface-CSA9VeWM.mjs";
|
|
2
|
-
import { t as Cache } from "./cache-
|
|
2
|
+
import { t as Cache } from "./cache-CCHcO9Oo.mjs";
|
|
3
3
|
import { ConstructName, Declaration, PostgresVersion } from "@geekmidas/manifest";
|
|
4
4
|
import { Service } from "@geekmidas/services";
|
|
5
5
|
import { Kysely, KyselyConfig } from "kysely";
|
|
@@ -213,4 +213,4 @@ declare class KyselyDatabase<DB = unknown, TName extends string = string> implem
|
|
|
213
213
|
type ReadOnlyDatabase<DB, TName extends string> = Omit<KyselyDatabase<DB, TName>, 'reader' | 'cache' | 'schema'>;
|
|
214
214
|
//#endregion
|
|
215
215
|
export { closeDatabasePools as a, ReadOnlyDatabase as i, KyselyDatabaseOptions as n, PostgresRuntime as r, KyselyDatabase as t };
|
|
216
|
-
//# sourceMappingURL=kysely-
|
|
216
|
+
//# sourceMappingURL=kysely-De5rAC-E.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kysely-
|
|
1
|
+
{"version":3,"file":"kysely-De5rAC-E.d.mts","names":[],"sources":["../src/database/pool.ts","../src/database/kysely.ts"],"mappings":";;;;;;;;;;;iBAwGsB,sBAAsB;;;;;;;;;;;;UChElC,kCAAkC,KAAK;;;;;;;;EAQhD;;;;;;;;EAQA;;;;;;;;;;EAUA;;;;;;;;EAQA;;;;;;;KAQW;;;;;;;;;;;EAYT,UAAU;EACV;;;;;;;;;;;;;;;;;EAkBA;EACA;;;;;;KAOS,wBAAwB,4BAA4B;;UAGtD;EACT;EACA;EACA;;;;;;;;;cAUY,eAAe,cAAc,0CAC9B,UAAU,OAAO,OAAO;mBAiBjB;WAfT,IAAI;WACJ,SAAS,QAAQ,aAAa,QAAQ,OAAO;;;;;mBAMrC;mBACA;mBACA;mBACA;mBACA;EAEjB,YACC,IAAI,cAAc,QACD,UAAS,uBAC1B,cAAc;EA2Bf,WAAW;;;;;;;;;;;;;EAyDX,UAAU,iBAAiB,OAAO;;;;;;;;;;;;;;;;;;EAyBlC,MAAM,2BAA2B,cAChC,KAAI,cAAc,SAClB;IAAW;MACT,MAAM;;;;;;;;;EAeT,OAAO,UAAU,wBAChB,IAAI,cAAc,UAClB,UAAS,wBACP,eAAe,UAAU;;;;;;;;;;;;;MAoBxB,SAAS,WAAW,aAAa,eAAe,OAAO;;;;;;;;;MAgBvD,gBAAgB,KAAK;UAiBX;;;;;;;;;;;;;;;;;;;KAuCH,iBAAiB,IAAI,wBAAwB,KACxD,eAAe,IAAI"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
//#region src/optionalPeers.ts
|
|
2
|
+
/**
|
|
3
|
+
* The optional peers a construct needs only for a feature it opted into.
|
|
4
|
+
*
|
|
5
|
+
* `@geekmidas/audit`, `@geekmidas/rate-limit`, `@geekmidas/db`,
|
|
6
|
+
* `@geekmidas/cache`, `@geekmidas/emailkit`, `@geekmidas/storage`, `hono`,
|
|
7
|
+
* `ws`, `ioredis` and `better-auth` are optional peers of this package: an app
|
|
8
|
+
* that audits nothing, limits nothing, sends no mail and serves no WebSocket
|
|
9
|
+
* need not install them. Entries that every app loads (`./endpoints`,
|
|
10
|
+
* `./crons`, `./worker`, `./testing`, the CLI's discovery) used to import them
|
|
11
|
+
* at the top, so loading any of them needed them all — and a production bundle
|
|
12
|
+
* of an app without them failed to build. They are loaded here instead, when
|
|
13
|
+
* the construct that uses one runs, which is also when the app declaring that
|
|
14
|
+
* construct has installed it.
|
|
15
|
+
*
|
|
16
|
+
* The `try` around each `import()` is load-bearing beyond the error it names:
|
|
17
|
+
* a bundler leaves an import it cannot resolve to run time when the import is
|
|
18
|
+
* guarded, and fails the build when it is not. `scripts/check-optional-peers.mjs`
|
|
19
|
+
* holds every entry to that: an optional peer is reached from its own adaptor
|
|
20
|
+
* subpath, or through a guarded `import()` like these.
|
|
21
|
+
*/
|
|
22
|
+
/** A construct uses a feature whose optional peer is not installed. */
|
|
23
|
+
var OptionalPeerMissing = class extends Error {
|
|
24
|
+
packageName;
|
|
25
|
+
feature;
|
|
26
|
+
constructor(packageName, feature, cause) {
|
|
27
|
+
super(`${feature} needs '${packageName}', which could not be loaded. Add it to the dependencies of the app that declares it.`, { cause });
|
|
28
|
+
this.packageName = packageName;
|
|
29
|
+
this.feature = feature;
|
|
30
|
+
this.name = "OptionalPeerMissing";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/** `@geekmidas/audit`, for an endpoint, function or cron with an auditor. */
|
|
34
|
+
async function loadAudit() {
|
|
35
|
+
try {
|
|
36
|
+
return await import("@geekmidas/audit");
|
|
37
|
+
} catch (cause) {
|
|
38
|
+
throw new OptionalPeerMissing("@geekmidas/audit", "An auditor", cause);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** `@geekmidas/audit/kysely`, for audits written in the handler's transaction. */
|
|
42
|
+
async function loadAuditKysely() {
|
|
43
|
+
try {
|
|
44
|
+
return await import("@geekmidas/audit/kysely");
|
|
45
|
+
} catch (cause) {
|
|
46
|
+
throw new OptionalPeerMissing("@geekmidas/audit", "An auditor that stores in the database", cause);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** `@geekmidas/rate-limit`, for an endpoint with a rate limit. */
|
|
50
|
+
async function loadRateLimit() {
|
|
51
|
+
try {
|
|
52
|
+
return await import("@geekmidas/rate-limit");
|
|
53
|
+
} catch (cause) {
|
|
54
|
+
throw new OptionalPeerMissing("@geekmidas/rate-limit", "An endpoint with a rate limit", cause);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** `@geekmidas/db/rls`, for an endpoint with row-level security. */
|
|
58
|
+
async function loadRls() {
|
|
59
|
+
try {
|
|
60
|
+
return await import("@geekmidas/db/rls");
|
|
61
|
+
} catch (cause) {
|
|
62
|
+
throw new OptionalPeerMissing("@geekmidas/db", "An endpoint with row-level security", cause);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** `@geekmidas/cache`, for a `Cache` construct's client. */
|
|
66
|
+
async function loadCache() {
|
|
67
|
+
try {
|
|
68
|
+
return await import("@geekmidas/cache");
|
|
69
|
+
} catch (cause) {
|
|
70
|
+
throw new OptionalPeerMissing("@geekmidas/cache", "A Cache", cause);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** `@geekmidas/emailkit`, for an `Email` construct's client. */
|
|
74
|
+
async function loadEmailkit() {
|
|
75
|
+
try {
|
|
76
|
+
return await import("@geekmidas/emailkit");
|
|
77
|
+
} catch (cause) {
|
|
78
|
+
throw new OptionalPeerMissing("@geekmidas/emailkit", "An Email", cause);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** `@geekmidas/storage/events`, for a subscriber to a bucket's objects. */
|
|
82
|
+
async function loadStorageEvents() {
|
|
83
|
+
try {
|
|
84
|
+
return await import("@geekmidas/storage/events");
|
|
85
|
+
} catch (cause) {
|
|
86
|
+
throw new OptionalPeerMissing("@geekmidas/storage", "A subscriber to a bucket's objects", cause);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** `hono`, for a surface that serves HTTP itself. */
|
|
90
|
+
async function loadHono(feature) {
|
|
91
|
+
try {
|
|
92
|
+
return await import("hono");
|
|
93
|
+
} catch (cause) {
|
|
94
|
+
throw new OptionalPeerMissing("hono", feature, cause);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** `hono/cors`, beside {@link loadHono}. */
|
|
98
|
+
async function loadHonoCors(feature) {
|
|
99
|
+
try {
|
|
100
|
+
return await import("hono/cors");
|
|
101
|
+
} catch (cause) {
|
|
102
|
+
throw new OptionalPeerMissing("hono", feature, cause);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** `ws`, for a `WebSocketApi`'s server. */
|
|
106
|
+
async function loadWs() {
|
|
107
|
+
try {
|
|
108
|
+
return await import("ws");
|
|
109
|
+
} catch (cause) {
|
|
110
|
+
throw new OptionalPeerMissing("ws", "A WebSocketApi", cause);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** `ioredis`, for a `WebSocketApi` that fans out through Redis. */
|
|
114
|
+
async function loadIoredis() {
|
|
115
|
+
try {
|
|
116
|
+
return await import("ioredis");
|
|
117
|
+
} catch (cause) {
|
|
118
|
+
throw new OptionalPeerMissing("ioredis", "A WebSocketApi with a redis:// transport", cause);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** `better-auth`, for an `Auth` construct's server. */
|
|
122
|
+
async function loadBetterAuth() {
|
|
123
|
+
try {
|
|
124
|
+
return await import("better-auth");
|
|
125
|
+
} catch (cause) {
|
|
126
|
+
throw new OptionalPeerMissing("better-auth", "An Auth", cause);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** `better-auth/db/migration`, for migrating an `Auth` construct's tables. */
|
|
130
|
+
async function loadBetterAuthMigration() {
|
|
131
|
+
try {
|
|
132
|
+
return await import("better-auth/db/migration");
|
|
133
|
+
} catch (cause) {
|
|
134
|
+
throw new OptionalPeerMissing("better-auth", "An Auth", cause);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
export { loadBetterAuthMigration as a, loadHono as c, loadRateLimit as d, loadRls as f, loadBetterAuth as i, loadHonoCors as l, loadWs as m, loadAudit as n, loadCache as o, loadStorageEvents as p, loadAuditKysely as r, loadEmailkit as s, OptionalPeerMissing as t, loadIoredis as u };
|
|
139
|
+
|
|
140
|
+
//# sourceMappingURL=optionalPeers-D7Wt6dnF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optionalPeers-D7Wt6dnF.mjs","names":[],"sources":["../src/optionalPeers.ts"],"sourcesContent":["/**\n * The optional peers a construct needs only for a feature it opted into.\n *\n * `@geekmidas/audit`, `@geekmidas/rate-limit`, `@geekmidas/db`,\n * `@geekmidas/cache`, `@geekmidas/emailkit`, `@geekmidas/storage`, `hono`,\n * `ws`, `ioredis` and `better-auth` are optional peers of this package: an app\n * that audits nothing, limits nothing, sends no mail and serves no WebSocket\n * need not install them. Entries that every app loads (`./endpoints`,\n * `./crons`, `./worker`, `./testing`, the CLI's discovery) used to import them\n * at the top, so loading any of them needed them all — and a production bundle\n * of an app without them failed to build. They are loaded here instead, when\n * the construct that uses one runs, which is also when the app declaring that\n * construct has installed it.\n *\n * The `try` around each `import()` is load-bearing beyond the error it names:\n * a bundler leaves an import it cannot resolve to run time when the import is\n * guarded, and fails the build when it is not. `scripts/check-optional-peers.mjs`\n * holds every entry to that: an optional peer is reached from its own adaptor\n * subpath, or through a guarded `import()` like these.\n */\n\n/** A construct uses a feature whose optional peer is not installed. */\nexport class OptionalPeerMissing extends Error {\n\tconstructor(\n\t\treadonly packageName: string,\n\t\treadonly feature: string,\n\t\tcause: unknown,\n\t) {\n\t\tsuper(\n\t\t\t`${feature} needs '${packageName}', which could not be loaded. ` +\n\t\t\t\t`Add it to the dependencies of the app that declares it.`,\n\t\t\t{ cause },\n\t\t);\n\t\tthis.name = 'OptionalPeerMissing';\n\t}\n}\n\n/** `@geekmidas/audit`, for an endpoint, function or cron with an auditor. */\nexport async function loadAudit(): Promise<typeof import('@geekmidas/audit')> {\n\ttry {\n\t\treturn await import('@geekmidas/audit');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('@geekmidas/audit', 'An auditor', cause);\n\t}\n}\n\n/** `@geekmidas/audit/kysely`, for audits written in the handler's transaction. */\nexport async function loadAuditKysely(): Promise<\n\ttypeof import('@geekmidas/audit/kysely')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/audit/kysely');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/audit',\n\t\t\t'An auditor that stores in the database',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/rate-limit`, for an endpoint with a rate limit. */\nexport async function loadRateLimit(): Promise<\n\ttypeof import('@geekmidas/rate-limit')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/rate-limit');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/rate-limit',\n\t\t\t'An endpoint with a rate limit',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/db/rls`, for an endpoint with row-level security. */\nexport async function loadRls(): Promise<typeof import('@geekmidas/db/rls')> {\n\ttry {\n\t\treturn await import('@geekmidas/db/rls');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/db',\n\t\t\t'An endpoint with row-level security',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/cache`, for a `Cache` construct's client. */\nexport async function loadCache(): Promise<typeof import('@geekmidas/cache')> {\n\ttry {\n\t\treturn await import('@geekmidas/cache');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('@geekmidas/cache', 'A Cache', cause);\n\t}\n}\n\n/** `@geekmidas/emailkit`, for an `Email` construct's client. */\nexport async function loadEmailkit(): Promise<\n\ttypeof import('@geekmidas/emailkit')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/emailkit');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('@geekmidas/emailkit', 'An Email', cause);\n\t}\n}\n\n/** `@geekmidas/emailkit/autoSubmitted`, for a subscriber to an `Inbox`. */\nexport async function loadAutoSubmitted(): Promise<\n\ttypeof import('@geekmidas/emailkit/autoSubmitted')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/emailkit/autoSubmitted');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/emailkit',\n\t\t\t'A subscriber to an Inbox',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/storage/events`, for a subscriber to a bucket's objects. */\nexport async function loadStorageEvents(): Promise<\n\ttypeof import('@geekmidas/storage/events')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/storage/events');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/storage',\n\t\t\t\"A subscriber to a bucket's objects\",\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `hono`, for a surface that serves HTTP itself. */\nexport async function loadHono(\n\tfeature: string,\n): Promise<typeof import('hono')> {\n\ttry {\n\t\treturn await import('hono');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('hono', feature, cause);\n\t}\n}\n\n/** `hono/cors`, beside {@link loadHono}. */\nexport async function loadHonoCors(\n\tfeature: string,\n): Promise<typeof import('hono/cors')> {\n\ttry {\n\t\treturn await import('hono/cors');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('hono', feature, cause);\n\t}\n}\n\n/** `ws`, for a `WebSocketApi`'s server. */\nexport async function loadWs(): Promise<typeof import('ws')> {\n\ttry {\n\t\treturn await import('ws');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('ws', 'A WebSocketApi', cause);\n\t}\n}\n\n/** `ioredis`, for a `WebSocketApi` that fans out through Redis. */\nexport async function loadIoredis(): Promise<typeof import('ioredis')> {\n\ttry {\n\t\treturn await import('ioredis');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'ioredis',\n\t\t\t'A WebSocketApi with a redis:// transport',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `better-auth`, for an `Auth` construct's server. */\nexport async function loadBetterAuth(): Promise<typeof import('better-auth')> {\n\ttry {\n\t\treturn await import('better-auth');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('better-auth', 'An Auth', cause);\n\t}\n}\n\n/** `better-auth/db/migration`, for migrating an `Auth` construct's tables. */\nexport async function loadBetterAuthMigration(): Promise<\n\ttypeof import('better-auth/db/migration')\n> {\n\ttry {\n\t\treturn await import('better-auth/db/migration');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('better-auth', 'An Auth', cause);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,sBAAb,cAAyC,MAAM;CAEpC;CACA;CAFV,YACC,aACA,SACA,OACC;EACD,MACC,GAAG,QAAQ,UAAU,YAAY,wFAEjC,EAAE,MAAM,CACT;EARS,KAAA,cAAA;EACA,KAAA,UAAA;EAQT,KAAK,OAAO;CACb;AACD;;AAGA,eAAsB,YAAwD;CAC7E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,oBAAoB,cAAc,KAAK;CACtE;AACD;;AAGA,eAAsB,kBAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,oBACA,0CACA,KACD;CACD;AACD;;AAGA,eAAsB,gBAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,yBACA,iCACA,KACD;CACD;AACD;;AAGA,eAAsB,UAAuD;CAC5E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,iBACA,uCACA,KACD;CACD;AACD;;AAGA,eAAsB,YAAwD;CAC7E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,oBAAoB,WAAW,KAAK;CACnE;AACD;;AAGA,eAAsB,eAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,uBAAuB,YAAY,KAAK;CACvE;AACD;;AAkBA,eAAsB,oBAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,sBACA,sCACA,KACD;CACD;AACD;;AAGA,eAAsB,SACrB,SACiC;CACjC,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,QAAQ,SAAS,KAAK;CACrD;AACD;;AAGA,eAAsB,aACrB,SACsC;CACtC,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,QAAQ,SAAS,KAAK;CACrD;AACD;;AAGA,eAAsB,SAAuC;CAC5D,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,MAAM,kBAAkB,KAAK;CAC5D;AACD;;AAGA,eAAsB,cAAiD;CACtE,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,WACA,4CACA,KACD;CACD;AACD;;AAGA,eAAsB,iBAAwD;CAC7E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,eAAe,WAAW,KAAK;CAC9D;AACD;;AAGA,eAAsB,0BAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,eAAe,WAAW,KAAK;CAC9D;AACD"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
//#region src/optionalPeers.ts
|
|
2
|
+
/**
|
|
3
|
+
* The optional peers a construct needs only for a feature it opted into.
|
|
4
|
+
*
|
|
5
|
+
* `@geekmidas/audit`, `@geekmidas/rate-limit`, `@geekmidas/db`,
|
|
6
|
+
* `@geekmidas/cache`, `@geekmidas/emailkit`, `@geekmidas/storage`, `hono`,
|
|
7
|
+
* `ws`, `ioredis` and `better-auth` are optional peers of this package: an app
|
|
8
|
+
* that audits nothing, limits nothing, sends no mail and serves no WebSocket
|
|
9
|
+
* need not install them. Entries that every app loads (`./endpoints`,
|
|
10
|
+
* `./crons`, `./worker`, `./testing`, the CLI's discovery) used to import them
|
|
11
|
+
* at the top, so loading any of them needed them all — and a production bundle
|
|
12
|
+
* of an app without them failed to build. They are loaded here instead, when
|
|
13
|
+
* the construct that uses one runs, which is also when the app declaring that
|
|
14
|
+
* construct has installed it.
|
|
15
|
+
*
|
|
16
|
+
* The `try` around each `import()` is load-bearing beyond the error it names:
|
|
17
|
+
* a bundler leaves an import it cannot resolve to run time when the import is
|
|
18
|
+
* guarded, and fails the build when it is not. `scripts/check-optional-peers.mjs`
|
|
19
|
+
* holds every entry to that: an optional peer is reached from its own adaptor
|
|
20
|
+
* subpath, or through a guarded `import()` like these.
|
|
21
|
+
*/
|
|
22
|
+
/** A construct uses a feature whose optional peer is not installed. */
|
|
23
|
+
var OptionalPeerMissing = class extends Error {
|
|
24
|
+
packageName;
|
|
25
|
+
feature;
|
|
26
|
+
constructor(packageName, feature, cause) {
|
|
27
|
+
super(`${feature} needs '${packageName}', which could not be loaded. Add it to the dependencies of the app that declares it.`, { cause });
|
|
28
|
+
this.packageName = packageName;
|
|
29
|
+
this.feature = feature;
|
|
30
|
+
this.name = "OptionalPeerMissing";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/** `@geekmidas/audit`, for an endpoint, function or cron with an auditor. */
|
|
34
|
+
async function loadAudit() {
|
|
35
|
+
try {
|
|
36
|
+
return await import("@geekmidas/audit");
|
|
37
|
+
} catch (cause) {
|
|
38
|
+
throw new OptionalPeerMissing("@geekmidas/audit", "An auditor", cause);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** `@geekmidas/audit/kysely`, for audits written in the handler's transaction. */
|
|
42
|
+
async function loadAuditKysely() {
|
|
43
|
+
try {
|
|
44
|
+
return await import("@geekmidas/audit/kysely");
|
|
45
|
+
} catch (cause) {
|
|
46
|
+
throw new OptionalPeerMissing("@geekmidas/audit", "An auditor that stores in the database", cause);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** `@geekmidas/rate-limit`, for an endpoint with a rate limit. */
|
|
50
|
+
async function loadRateLimit() {
|
|
51
|
+
try {
|
|
52
|
+
return await import("@geekmidas/rate-limit");
|
|
53
|
+
} catch (cause) {
|
|
54
|
+
throw new OptionalPeerMissing("@geekmidas/rate-limit", "An endpoint with a rate limit", cause);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** `@geekmidas/db/rls`, for an endpoint with row-level security. */
|
|
58
|
+
async function loadRls() {
|
|
59
|
+
try {
|
|
60
|
+
return await import("@geekmidas/db/rls");
|
|
61
|
+
} catch (cause) {
|
|
62
|
+
throw new OptionalPeerMissing("@geekmidas/db", "An endpoint with row-level security", cause);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** `@geekmidas/cache`, for a `Cache` construct's client. */
|
|
66
|
+
async function loadCache() {
|
|
67
|
+
try {
|
|
68
|
+
return await import("@geekmidas/cache");
|
|
69
|
+
} catch (cause) {
|
|
70
|
+
throw new OptionalPeerMissing("@geekmidas/cache", "A Cache", cause);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** `@geekmidas/emailkit`, for an `Email` construct's client. */
|
|
74
|
+
async function loadEmailkit() {
|
|
75
|
+
try {
|
|
76
|
+
return await import("@geekmidas/emailkit");
|
|
77
|
+
} catch (cause) {
|
|
78
|
+
throw new OptionalPeerMissing("@geekmidas/emailkit", "An Email", cause);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** `@geekmidas/storage/events`, for a subscriber to a bucket's objects. */
|
|
82
|
+
async function loadStorageEvents() {
|
|
83
|
+
try {
|
|
84
|
+
return await import("@geekmidas/storage/events");
|
|
85
|
+
} catch (cause) {
|
|
86
|
+
throw new OptionalPeerMissing("@geekmidas/storage", "A subscriber to a bucket's objects", cause);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** `hono`, for a surface that serves HTTP itself. */
|
|
90
|
+
async function loadHono(feature) {
|
|
91
|
+
try {
|
|
92
|
+
return await import("hono");
|
|
93
|
+
} catch (cause) {
|
|
94
|
+
throw new OptionalPeerMissing("hono", feature, cause);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** `hono/cors`, beside {@link loadHono}. */
|
|
98
|
+
async function loadHonoCors(feature) {
|
|
99
|
+
try {
|
|
100
|
+
return await import("hono/cors");
|
|
101
|
+
} catch (cause) {
|
|
102
|
+
throw new OptionalPeerMissing("hono", feature, cause);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** `ws`, for a `WebSocketApi`'s server. */
|
|
106
|
+
async function loadWs() {
|
|
107
|
+
try {
|
|
108
|
+
return await import("ws");
|
|
109
|
+
} catch (cause) {
|
|
110
|
+
throw new OptionalPeerMissing("ws", "A WebSocketApi", cause);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** `ioredis`, for a `WebSocketApi` that fans out through Redis. */
|
|
114
|
+
async function loadIoredis() {
|
|
115
|
+
try {
|
|
116
|
+
return await import("ioredis");
|
|
117
|
+
} catch (cause) {
|
|
118
|
+
throw new OptionalPeerMissing("ioredis", "A WebSocketApi with a redis:// transport", cause);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** `better-auth`, for an `Auth` construct's server. */
|
|
122
|
+
async function loadBetterAuth() {
|
|
123
|
+
try {
|
|
124
|
+
return await import("better-auth");
|
|
125
|
+
} catch (cause) {
|
|
126
|
+
throw new OptionalPeerMissing("better-auth", "An Auth", cause);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** `better-auth/db/migration`, for migrating an `Auth` construct's tables. */
|
|
130
|
+
async function loadBetterAuthMigration() {
|
|
131
|
+
try {
|
|
132
|
+
return await import("better-auth/db/migration");
|
|
133
|
+
} catch (cause) {
|
|
134
|
+
throw new OptionalPeerMissing("better-auth", "An Auth", cause);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
Object.defineProperty(exports, "OptionalPeerMissing", {
|
|
139
|
+
enumerable: true,
|
|
140
|
+
get: function() {
|
|
141
|
+
return OptionalPeerMissing;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
Object.defineProperty(exports, "loadAudit", {
|
|
145
|
+
enumerable: true,
|
|
146
|
+
get: function() {
|
|
147
|
+
return loadAudit;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
Object.defineProperty(exports, "loadAuditKysely", {
|
|
151
|
+
enumerable: true,
|
|
152
|
+
get: function() {
|
|
153
|
+
return loadAuditKysely;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
Object.defineProperty(exports, "loadBetterAuth", {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
get: function() {
|
|
159
|
+
return loadBetterAuth;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
Object.defineProperty(exports, "loadBetterAuthMigration", {
|
|
163
|
+
enumerable: true,
|
|
164
|
+
get: function() {
|
|
165
|
+
return loadBetterAuthMigration;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(exports, "loadCache", {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
get: function() {
|
|
171
|
+
return loadCache;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
Object.defineProperty(exports, "loadEmailkit", {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: function() {
|
|
177
|
+
return loadEmailkit;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
Object.defineProperty(exports, "loadHono", {
|
|
181
|
+
enumerable: true,
|
|
182
|
+
get: function() {
|
|
183
|
+
return loadHono;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(exports, "loadHonoCors", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function() {
|
|
189
|
+
return loadHonoCors;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(exports, "loadIoredis", {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function() {
|
|
195
|
+
return loadIoredis;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
Object.defineProperty(exports, "loadRateLimit", {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
get: function() {
|
|
201
|
+
return loadRateLimit;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(exports, "loadRls", {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
get: function() {
|
|
207
|
+
return loadRls;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
Object.defineProperty(exports, "loadStorageEvents", {
|
|
211
|
+
enumerable: true,
|
|
212
|
+
get: function() {
|
|
213
|
+
return loadStorageEvents;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(exports, "loadWs", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
get: function() {
|
|
219
|
+
return loadWs;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
//# sourceMappingURL=optionalPeers-DuNQXXe1.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optionalPeers-DuNQXXe1.cjs","names":[],"sources":["../src/optionalPeers.ts"],"sourcesContent":["/**\n * The optional peers a construct needs only for a feature it opted into.\n *\n * `@geekmidas/audit`, `@geekmidas/rate-limit`, `@geekmidas/db`,\n * `@geekmidas/cache`, `@geekmidas/emailkit`, `@geekmidas/storage`, `hono`,\n * `ws`, `ioredis` and `better-auth` are optional peers of this package: an app\n * that audits nothing, limits nothing, sends no mail and serves no WebSocket\n * need not install them. Entries that every app loads (`./endpoints`,\n * `./crons`, `./worker`, `./testing`, the CLI's discovery) used to import them\n * at the top, so loading any of them needed them all — and a production bundle\n * of an app without them failed to build. They are loaded here instead, when\n * the construct that uses one runs, which is also when the app declaring that\n * construct has installed it.\n *\n * The `try` around each `import()` is load-bearing beyond the error it names:\n * a bundler leaves an import it cannot resolve to run time when the import is\n * guarded, and fails the build when it is not. `scripts/check-optional-peers.mjs`\n * holds every entry to that: an optional peer is reached from its own adaptor\n * subpath, or through a guarded `import()` like these.\n */\n\n/** A construct uses a feature whose optional peer is not installed. */\nexport class OptionalPeerMissing extends Error {\n\tconstructor(\n\t\treadonly packageName: string,\n\t\treadonly feature: string,\n\t\tcause: unknown,\n\t) {\n\t\tsuper(\n\t\t\t`${feature} needs '${packageName}', which could not be loaded. ` +\n\t\t\t\t`Add it to the dependencies of the app that declares it.`,\n\t\t\t{ cause },\n\t\t);\n\t\tthis.name = 'OptionalPeerMissing';\n\t}\n}\n\n/** `@geekmidas/audit`, for an endpoint, function or cron with an auditor. */\nexport async function loadAudit(): Promise<typeof import('@geekmidas/audit')> {\n\ttry {\n\t\treturn await import('@geekmidas/audit');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('@geekmidas/audit', 'An auditor', cause);\n\t}\n}\n\n/** `@geekmidas/audit/kysely`, for audits written in the handler's transaction. */\nexport async function loadAuditKysely(): Promise<\n\ttypeof import('@geekmidas/audit/kysely')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/audit/kysely');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/audit',\n\t\t\t'An auditor that stores in the database',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/rate-limit`, for an endpoint with a rate limit. */\nexport async function loadRateLimit(): Promise<\n\ttypeof import('@geekmidas/rate-limit')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/rate-limit');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/rate-limit',\n\t\t\t'An endpoint with a rate limit',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/db/rls`, for an endpoint with row-level security. */\nexport async function loadRls(): Promise<typeof import('@geekmidas/db/rls')> {\n\ttry {\n\t\treturn await import('@geekmidas/db/rls');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/db',\n\t\t\t'An endpoint with row-level security',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/cache`, for a `Cache` construct's client. */\nexport async function loadCache(): Promise<typeof import('@geekmidas/cache')> {\n\ttry {\n\t\treturn await import('@geekmidas/cache');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('@geekmidas/cache', 'A Cache', cause);\n\t}\n}\n\n/** `@geekmidas/emailkit`, for an `Email` construct's client. */\nexport async function loadEmailkit(): Promise<\n\ttypeof import('@geekmidas/emailkit')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/emailkit');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('@geekmidas/emailkit', 'An Email', cause);\n\t}\n}\n\n/** `@geekmidas/emailkit/autoSubmitted`, for a subscriber to an `Inbox`. */\nexport async function loadAutoSubmitted(): Promise<\n\ttypeof import('@geekmidas/emailkit/autoSubmitted')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/emailkit/autoSubmitted');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/emailkit',\n\t\t\t'A subscriber to an Inbox',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `@geekmidas/storage/events`, for a subscriber to a bucket's objects. */\nexport async function loadStorageEvents(): Promise<\n\ttypeof import('@geekmidas/storage/events')\n> {\n\ttry {\n\t\treturn await import('@geekmidas/storage/events');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'@geekmidas/storage',\n\t\t\t\"A subscriber to a bucket's objects\",\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `hono`, for a surface that serves HTTP itself. */\nexport async function loadHono(\n\tfeature: string,\n): Promise<typeof import('hono')> {\n\ttry {\n\t\treturn await import('hono');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('hono', feature, cause);\n\t}\n}\n\n/** `hono/cors`, beside {@link loadHono}. */\nexport async function loadHonoCors(\n\tfeature: string,\n): Promise<typeof import('hono/cors')> {\n\ttry {\n\t\treturn await import('hono/cors');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('hono', feature, cause);\n\t}\n}\n\n/** `ws`, for a `WebSocketApi`'s server. */\nexport async function loadWs(): Promise<typeof import('ws')> {\n\ttry {\n\t\treturn await import('ws');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('ws', 'A WebSocketApi', cause);\n\t}\n}\n\n/** `ioredis`, for a `WebSocketApi` that fans out through Redis. */\nexport async function loadIoredis(): Promise<typeof import('ioredis')> {\n\ttry {\n\t\treturn await import('ioredis');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing(\n\t\t\t'ioredis',\n\t\t\t'A WebSocketApi with a redis:// transport',\n\t\t\tcause,\n\t\t);\n\t}\n}\n\n/** `better-auth`, for an `Auth` construct's server. */\nexport async function loadBetterAuth(): Promise<typeof import('better-auth')> {\n\ttry {\n\t\treturn await import('better-auth');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('better-auth', 'An Auth', cause);\n\t}\n}\n\n/** `better-auth/db/migration`, for migrating an `Auth` construct's tables. */\nexport async function loadBetterAuthMigration(): Promise<\n\ttypeof import('better-auth/db/migration')\n> {\n\ttry {\n\t\treturn await import('better-auth/db/migration');\n\t} catch (cause) {\n\t\tthrow new OptionalPeerMissing('better-auth', 'An Auth', cause);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,sBAAb,cAAyC,MAAM;CAEpC;CACA;CAFV,YACC,aACA,SACA,OACC;EACD,MACC,GAAG,QAAQ,UAAU,YAAY,wFAEjC,EAAE,MAAM,CACT;EARS,KAAA,cAAA;EACA,KAAA,UAAA;EAQT,KAAK,OAAO;CACb;AACD;;AAGA,eAAsB,YAAwD;CAC7E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,oBAAoB,cAAc,KAAK;CACtE;AACD;;AAGA,eAAsB,kBAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,oBACA,0CACA,KACD;CACD;AACD;;AAGA,eAAsB,gBAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,yBACA,iCACA,KACD;CACD;AACD;;AAGA,eAAsB,UAAuD;CAC5E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,iBACA,uCACA,KACD;CACD;AACD;;AAGA,eAAsB,YAAwD;CAC7E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,oBAAoB,WAAW,KAAK;CACnE;AACD;;AAGA,eAAsB,eAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,uBAAuB,YAAY,KAAK;CACvE;AACD;;AAkBA,eAAsB,oBAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,sBACA,sCACA,KACD;CACD;AACD;;AAGA,eAAsB,SACrB,SACiC;CACjC,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,QAAQ,SAAS,KAAK;CACrD;AACD;;AAGA,eAAsB,aACrB,SACsC;CACtC,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,QAAQ,SAAS,KAAK;CACrD;AACD;;AAGA,eAAsB,SAAuC;CAC5D,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,MAAM,kBAAkB,KAAK;CAC5D;AACD;;AAGA,eAAsB,cAAiD;CACtE,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBACT,WACA,4CACA,KACD;CACD;AACD;;AAGA,eAAsB,iBAAwD;CAC7E,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,eAAe,WAAW,KAAK;CAC9D;AACD;;AAGA,eAAsB,0BAEpB;CACD,IAAI;EACH,OAAO,MAAM,OAAO;CACrB,SAAS,OAAO;EACf,MAAM,IAAI,oBAAoB,eAAe,WAAW,KAAK;CAC9D;AACD"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
2
|
+
//#region src/websocket/drivers.ts
|
|
3
|
+
/**
|
|
4
|
+
* WebSocket sink drivers, keyed by publisher-string scheme.
|
|
5
|
+
*
|
|
6
|
+
* The shape `@geekmidas/events` and `Encryption` use, for the same reason: a
|
|
7
|
+
* surface's `<ID>_PUBLISHER_CONNECTION_STRING` names where its sockets are, and
|
|
8
|
+
* the scheme picks what reaches them. `redis://` and `memory://` are the
|
|
9
|
+
* process transport, built in. Any other scheme is a driver the entry point
|
|
10
|
+
* registers — `apigateway:` on an AWS build, from
|
|
11
|
+
* `@geekmidas/constructs/aws-websocket` — so a process that never publishes
|
|
12
|
+
* to API Gateway never imports its SDK.
|
|
13
|
+
*
|
|
14
|
+
* Registration is an explicit call rather than an import side effect, because
|
|
15
|
+
* a side-effecting module is exactly what a bundler is entitled to drop.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The registry lives on `globalThis`, so one registration is seen by every
|
|
19
|
+
* copy of this module — the ESM and the CJS build of one install.
|
|
20
|
+
*/
|
|
21
|
+
const REGISTRY = Symbol.for("@geekmidas/constructs/websocket-sinks");
|
|
22
|
+
function drivers() {
|
|
23
|
+
const global = globalThis;
|
|
24
|
+
global[REGISTRY] ??= /* @__PURE__ */ new Map();
|
|
25
|
+
return global[REGISTRY];
|
|
26
|
+
}
|
|
27
|
+
/** Make a sink available for its scheme. Idempotent. */
|
|
28
|
+
function registerWebSocketSinkDriver(driver) {
|
|
29
|
+
drivers().set(driver.scheme, driver);
|
|
30
|
+
}
|
|
31
|
+
/** The driver registered for a publisher string's scheme, if any. */
|
|
32
|
+
function webSocketSinkDriverFor(connectionString) {
|
|
33
|
+
return drivers().get(schemeOf(connectionString));
|
|
34
|
+
}
|
|
35
|
+
/** `apigateway:` from `apigateway://…`. */
|
|
36
|
+
function schemeOf(connectionString) {
|
|
37
|
+
const separator = connectionString.indexOf(":");
|
|
38
|
+
return separator === -1 ? connectionString : connectionString.slice(0, separator + 1);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A surface's publisher string names a scheme this process registered no
|
|
42
|
+
* sink for — `apigateway:` in an entry not built for AWS.
|
|
43
|
+
*/
|
|
44
|
+
var UnregisteredWebSocketScheme = class extends Error {
|
|
45
|
+
surface;
|
|
46
|
+
scheme;
|
|
47
|
+
constructor(surface, scheme) {
|
|
48
|
+
super(`${surface}'s publisher string is a '${scheme}' URL, and this build registered no sink for it. ` + (scheme === _geekmidas_manifest.API_GATEWAY_WEBSOCKET_SCHEME ? "An API Gateway surface is an AWS target's: build for it (gkm build --provider aws), which registers the API Gateway sink and needs @aws-sdk/client-apigatewaymanagementapi, @aws-sdk/client-dynamodb and electrodb installed." : "Register its driver with registerWebSocketSinkDriver before the first publish."));
|
|
49
|
+
this.surface = surface;
|
|
50
|
+
this.scheme = scheme;
|
|
51
|
+
this.name = "UnregisteredWebSocketScheme";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/websocket/origins.ts
|
|
56
|
+
/**
|
|
57
|
+
* The origins a client of the surface's own address sends: the `https://`
|
|
58
|
+
* one a native socket derives from `wss://`, and the address's own.
|
|
59
|
+
*
|
|
60
|
+
* Shared by every adaptor that checks a handshake's `Origin` — the Node
|
|
61
|
+
* server and the API Gateway `$connect` handler — so the two trust the same
|
|
62
|
+
* origins for the same address.
|
|
63
|
+
*/
|
|
64
|
+
function ownOrigins(url) {
|
|
65
|
+
if (!url || !URL.canParse(url)) return [];
|
|
66
|
+
const own = new URL(url);
|
|
67
|
+
const web = new URL(url.replace(/^ws(s?):/i, "http$1:"));
|
|
68
|
+
return [.../* @__PURE__ */ new Set([`${own.protocol}//${own.host}`, web.origin])];
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
Object.defineProperty(exports, "UnregisteredWebSocketScheme", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function() {
|
|
74
|
+
return UnregisteredWebSocketScheme;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(exports, "ownOrigins", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function() {
|
|
80
|
+
return ownOrigins;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, "registerWebSocketSinkDriver", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function() {
|
|
86
|
+
return registerWebSocketSinkDriver;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(exports, "webSocketSinkDriverFor", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function() {
|
|
92
|
+
return webSocketSinkDriverFor;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=origins-BjxYht13.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"origins-BjxYht13.cjs","names":["API_GATEWAY_WEBSOCKET_SCHEME"],"sources":["../src/websocket/drivers.ts","../src/websocket/origins.ts"],"sourcesContent":["/**\n * WebSocket sink drivers, keyed by publisher-string scheme.\n *\n * The shape `@geekmidas/events` and `Encryption` use, for the same reason: a\n * surface's `<ID>_PUBLISHER_CONNECTION_STRING` names where its sockets are, and\n * the scheme picks what reaches them. `redis://` and `memory://` are the\n * process transport, built in. Any other scheme is a driver the entry point\n * registers — `apigateway:` on an AWS build, from\n * `@geekmidas/constructs/aws-websocket` — so a process that never publishes\n * to API Gateway never imports its SDK.\n *\n * Registration is an explicit call rather than an import side effect, because\n * a side-effecting module is exactly what a bundler is entitled to drop.\n */\n\nimport { API_GATEWAY_WEBSOCKET_SCHEME } from '@geekmidas/manifest';\nimport type { WebSocketSink } from './publisher';\n\n/** What reaches a surface's sockets for one publisher-string scheme. */\nexport interface WebSocketSinkDriver {\n\t/** The scheme it handles, with its colon: `'apigateway:'`. */\n\treadonly scheme: string;\n\t/** The sink for a publisher string of that scheme. */\n\tsink(connectionString: string): WebSocketSink;\n}\n\n/**\n * The registry lives on `globalThis`, so one registration is seen by every\n * copy of this module — the ESM and the CJS build of one install.\n */\nconst REGISTRY = Symbol.for('@geekmidas/constructs/websocket-sinks');\n\nfunction drivers(): Map<string, WebSocketSinkDriver> {\n\tconst global = globalThis as {\n\t\t[REGISTRY]?: Map<string, WebSocketSinkDriver>;\n\t};\n\tglobal[REGISTRY] ??= new Map();\n\treturn global[REGISTRY];\n}\n\n/** Make a sink available for its scheme. Idempotent. */\nexport function registerWebSocketSinkDriver(driver: WebSocketSinkDriver): void {\n\tdrivers().set(driver.scheme, driver);\n}\n\n/** The driver registered for a publisher string's scheme, if any. */\nexport function webSocketSinkDriverFor(\n\tconnectionString: string,\n): WebSocketSinkDriver | undefined {\n\treturn drivers().get(schemeOf(connectionString));\n}\n\n/** `apigateway:` from `apigateway://…`. */\nexport function schemeOf(connectionString: string): string {\n\tconst separator = connectionString.indexOf(':');\n\treturn separator === -1\n\t\t? connectionString\n\t\t: connectionString.slice(0, separator + 1);\n}\n\n/**\n * A surface's publisher string names a scheme this process registered no\n * sink for — `apigateway:` in an entry not built for AWS.\n */\nexport class UnregisteredWebSocketScheme extends Error {\n\tconstructor(\n\t\treadonly surface: string,\n\t\treadonly scheme: string,\n\t) {\n\t\tsuper(\n\t\t\t`${surface}'s publisher string is a '${scheme}' URL, and this build registered no sink for it. ` +\n\t\t\t\t(scheme === API_GATEWAY_WEBSOCKET_SCHEME\n\t\t\t\t\t? \"An API Gateway surface is an AWS target's: build for it (gkm build --provider aws), which registers the API Gateway sink and needs @aws-sdk/client-apigatewaymanagementapi, @aws-sdk/client-dynamodb and electrodb installed.\"\n\t\t\t\t\t: 'Register its driver with registerWebSocketSinkDriver before the first publish.'),\n\t\t);\n\t\tthis.name = 'UnregisteredWebSocketScheme';\n\t}\n}\n","/**\n * The origins a client of the surface's own address sends: the `https://`\n * one a native socket derives from `wss://`, and the address's own.\n *\n * Shared by every adaptor that checks a handshake's `Origin` — the Node\n * server and the API Gateway `$connect` handler — so the two trust the same\n * origins for the same address.\n */\nexport function ownOrigins(url: string | undefined): string[] {\n\tif (!url || !URL.canParse(url)) return [];\n\tconst own = new URL(url);\n\tconst web = new URL(url.replace(/^ws(s?):/i, 'http$1:'));\n\treturn [...new Set([`${own.protocol}//${own.host}`, web.origin])];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,WAAW,OAAO,IAAI,uCAAuC;AAEnE,SAAS,UAA4C;CACpD,MAAM,SAAS;CAGf,OAAO,8BAAc,IAAI,IAAI;CAC7B,OAAO,OAAO;AACf;;AAGA,SAAgB,4BAA4B,QAAmC;CAC9E,QAAQ,CAAC,CAAC,IAAI,OAAO,QAAQ,MAAM;AACpC;;AAGA,SAAgB,uBACf,kBACkC;CAClC,OAAO,QAAQ,CAAC,CAAC,IAAI,SAAS,gBAAgB,CAAC;AAChD;;AAGA,SAAgB,SAAS,kBAAkC;CAC1D,MAAM,YAAY,iBAAiB,QAAQ,GAAG;CAC9C,OAAO,cAAc,KAClB,mBACA,iBAAiB,MAAM,GAAG,YAAY,CAAC;AAC3C;;;;;AAMA,IAAa,8BAAb,cAAiD,MAAM;CAE5C;CACA;CAFV,YACC,SACA,QACC;EACD,MACC,GAAG,QAAQ,4BAA4B,OAAO,sDAC5C,WAAWA,oBAAAA,+BACT,kOACA,iFACL;EARS,KAAA,UAAA;EACA,KAAA,SAAA;EAQT,KAAK,OAAO;CACb;AACD;;;;;;;;;;;ACrEA,SAAgB,WAAW,KAAmC;CAC7D,IAAI,CAAC,OAAO,CAAC,IAAI,SAAS,GAAG,GAAG,OAAO,CAAC;CACxC,MAAM,MAAM,IAAI,IAAI,GAAG;CACvB,MAAM,MAAM,IAAI,IAAI,IAAI,QAAQ,aAAa,SAAS,CAAC;CACvD,OAAO,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,IAAI,SAAS,IAAI,IAAI,QAAQ,IAAI,MAAM,CAAC,CAAC;AACjE"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { API_GATEWAY_WEBSOCKET_SCHEME } from "@geekmidas/manifest";
|
|
2
|
+
//#region src/websocket/drivers.ts
|
|
3
|
+
/**
|
|
4
|
+
* WebSocket sink drivers, keyed by publisher-string scheme.
|
|
5
|
+
*
|
|
6
|
+
* The shape `@geekmidas/events` and `Encryption` use, for the same reason: a
|
|
7
|
+
* surface's `<ID>_PUBLISHER_CONNECTION_STRING` names where its sockets are, and
|
|
8
|
+
* the scheme picks what reaches them. `redis://` and `memory://` are the
|
|
9
|
+
* process transport, built in. Any other scheme is a driver the entry point
|
|
10
|
+
* registers — `apigateway:` on an AWS build, from
|
|
11
|
+
* `@geekmidas/constructs/aws-websocket` — so a process that never publishes
|
|
12
|
+
* to API Gateway never imports its SDK.
|
|
13
|
+
*
|
|
14
|
+
* Registration is an explicit call rather than an import side effect, because
|
|
15
|
+
* a side-effecting module is exactly what a bundler is entitled to drop.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The registry lives on `globalThis`, so one registration is seen by every
|
|
19
|
+
* copy of this module — the ESM and the CJS build of one install.
|
|
20
|
+
*/
|
|
21
|
+
const REGISTRY = Symbol.for("@geekmidas/constructs/websocket-sinks");
|
|
22
|
+
function drivers() {
|
|
23
|
+
const global = globalThis;
|
|
24
|
+
global[REGISTRY] ??= /* @__PURE__ */ new Map();
|
|
25
|
+
return global[REGISTRY];
|
|
26
|
+
}
|
|
27
|
+
/** Make a sink available for its scheme. Idempotent. */
|
|
28
|
+
function registerWebSocketSinkDriver(driver) {
|
|
29
|
+
drivers().set(driver.scheme, driver);
|
|
30
|
+
}
|
|
31
|
+
/** The driver registered for a publisher string's scheme, if any. */
|
|
32
|
+
function webSocketSinkDriverFor(connectionString) {
|
|
33
|
+
return drivers().get(schemeOf(connectionString));
|
|
34
|
+
}
|
|
35
|
+
/** `apigateway:` from `apigateway://…`. */
|
|
36
|
+
function schemeOf(connectionString) {
|
|
37
|
+
const separator = connectionString.indexOf(":");
|
|
38
|
+
return separator === -1 ? connectionString : connectionString.slice(0, separator + 1);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A surface's publisher string names a scheme this process registered no
|
|
42
|
+
* sink for — `apigateway:` in an entry not built for AWS.
|
|
43
|
+
*/
|
|
44
|
+
var UnregisteredWebSocketScheme = class extends Error {
|
|
45
|
+
surface;
|
|
46
|
+
scheme;
|
|
47
|
+
constructor(surface, scheme) {
|
|
48
|
+
super(`${surface}'s publisher string is a '${scheme}' URL, and this build registered no sink for it. ` + (scheme === API_GATEWAY_WEBSOCKET_SCHEME ? "An API Gateway surface is an AWS target's: build for it (gkm build --provider aws), which registers the API Gateway sink and needs @aws-sdk/client-apigatewaymanagementapi, @aws-sdk/client-dynamodb and electrodb installed." : "Register its driver with registerWebSocketSinkDriver before the first publish."));
|
|
49
|
+
this.surface = surface;
|
|
50
|
+
this.scheme = scheme;
|
|
51
|
+
this.name = "UnregisteredWebSocketScheme";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/websocket/origins.ts
|
|
56
|
+
/**
|
|
57
|
+
* The origins a client of the surface's own address sends: the `https://`
|
|
58
|
+
* one a native socket derives from `wss://`, and the address's own.
|
|
59
|
+
*
|
|
60
|
+
* Shared by every adaptor that checks a handshake's `Origin` — the Node
|
|
61
|
+
* server and the API Gateway `$connect` handler — so the two trust the same
|
|
62
|
+
* origins for the same address.
|
|
63
|
+
*/
|
|
64
|
+
function ownOrigins(url) {
|
|
65
|
+
if (!url || !URL.canParse(url)) return [];
|
|
66
|
+
const own = new URL(url);
|
|
67
|
+
const web = new URL(url.replace(/^ws(s?):/i, "http$1:"));
|
|
68
|
+
return [.../* @__PURE__ */ new Set([`${own.protocol}//${own.host}`, web.origin])];
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { webSocketSinkDriverFor as i, UnregisteredWebSocketScheme as n, registerWebSocketSinkDriver as r, ownOrigins as t };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=origins-Boc9qbo-.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"origins-Boc9qbo-.mjs","names":[],"sources":["../src/websocket/drivers.ts","../src/websocket/origins.ts"],"sourcesContent":["/**\n * WebSocket sink drivers, keyed by publisher-string scheme.\n *\n * The shape `@geekmidas/events` and `Encryption` use, for the same reason: a\n * surface's `<ID>_PUBLISHER_CONNECTION_STRING` names where its sockets are, and\n * the scheme picks what reaches them. `redis://` and `memory://` are the\n * process transport, built in. Any other scheme is a driver the entry point\n * registers — `apigateway:` on an AWS build, from\n * `@geekmidas/constructs/aws-websocket` — so a process that never publishes\n * to API Gateway never imports its SDK.\n *\n * Registration is an explicit call rather than an import side effect, because\n * a side-effecting module is exactly what a bundler is entitled to drop.\n */\n\nimport { API_GATEWAY_WEBSOCKET_SCHEME } from '@geekmidas/manifest';\nimport type { WebSocketSink } from './publisher';\n\n/** What reaches a surface's sockets for one publisher-string scheme. */\nexport interface WebSocketSinkDriver {\n\t/** The scheme it handles, with its colon: `'apigateway:'`. */\n\treadonly scheme: string;\n\t/** The sink for a publisher string of that scheme. */\n\tsink(connectionString: string): WebSocketSink;\n}\n\n/**\n * The registry lives on `globalThis`, so one registration is seen by every\n * copy of this module — the ESM and the CJS build of one install.\n */\nconst REGISTRY = Symbol.for('@geekmidas/constructs/websocket-sinks');\n\nfunction drivers(): Map<string, WebSocketSinkDriver> {\n\tconst global = globalThis as {\n\t\t[REGISTRY]?: Map<string, WebSocketSinkDriver>;\n\t};\n\tglobal[REGISTRY] ??= new Map();\n\treturn global[REGISTRY];\n}\n\n/** Make a sink available for its scheme. Idempotent. */\nexport function registerWebSocketSinkDriver(driver: WebSocketSinkDriver): void {\n\tdrivers().set(driver.scheme, driver);\n}\n\n/** The driver registered for a publisher string's scheme, if any. */\nexport function webSocketSinkDriverFor(\n\tconnectionString: string,\n): WebSocketSinkDriver | undefined {\n\treturn drivers().get(schemeOf(connectionString));\n}\n\n/** `apigateway:` from `apigateway://…`. */\nexport function schemeOf(connectionString: string): string {\n\tconst separator = connectionString.indexOf(':');\n\treturn separator === -1\n\t\t? connectionString\n\t\t: connectionString.slice(0, separator + 1);\n}\n\n/**\n * A surface's publisher string names a scheme this process registered no\n * sink for — `apigateway:` in an entry not built for AWS.\n */\nexport class UnregisteredWebSocketScheme extends Error {\n\tconstructor(\n\t\treadonly surface: string,\n\t\treadonly scheme: string,\n\t) {\n\t\tsuper(\n\t\t\t`${surface}'s publisher string is a '${scheme}' URL, and this build registered no sink for it. ` +\n\t\t\t\t(scheme === API_GATEWAY_WEBSOCKET_SCHEME\n\t\t\t\t\t? \"An API Gateway surface is an AWS target's: build for it (gkm build --provider aws), which registers the API Gateway sink and needs @aws-sdk/client-apigatewaymanagementapi, @aws-sdk/client-dynamodb and electrodb installed.\"\n\t\t\t\t\t: 'Register its driver with registerWebSocketSinkDriver before the first publish.'),\n\t\t);\n\t\tthis.name = 'UnregisteredWebSocketScheme';\n\t}\n}\n","/**\n * The origins a client of the surface's own address sends: the `https://`\n * one a native socket derives from `wss://`, and the address's own.\n *\n * Shared by every adaptor that checks a handshake's `Origin` — the Node\n * server and the API Gateway `$connect` handler — so the two trust the same\n * origins for the same address.\n */\nexport function ownOrigins(url: string | undefined): string[] {\n\tif (!url || !URL.canParse(url)) return [];\n\tconst own = new URL(url);\n\tconst web = new URL(url.replace(/^ws(s?):/i, 'http$1:'));\n\treturn [...new Set([`${own.protocol}//${own.host}`, web.origin])];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,WAAW,OAAO,IAAI,uCAAuC;AAEnE,SAAS,UAA4C;CACpD,MAAM,SAAS;CAGf,OAAO,8BAAc,IAAI,IAAI;CAC7B,OAAO,OAAO;AACf;;AAGA,SAAgB,4BAA4B,QAAmC;CAC9E,QAAQ,CAAC,CAAC,IAAI,OAAO,QAAQ,MAAM;AACpC;;AAGA,SAAgB,uBACf,kBACkC;CAClC,OAAO,QAAQ,CAAC,CAAC,IAAI,SAAS,gBAAgB,CAAC;AAChD;;AAGA,SAAgB,SAAS,kBAAkC;CAC1D,MAAM,YAAY,iBAAiB,QAAQ,GAAG;CAC9C,OAAO,cAAc,KAClB,mBACA,iBAAiB,MAAM,GAAG,YAAY,CAAC;AAC3C;;;;;AAMA,IAAa,8BAAb,cAAiD,MAAM;CAE5C;CACA;CAFV,YACC,SACA,QACC;EACD,MACC,GAAG,QAAQ,4BAA4B,OAAO,sDAC5C,WAAW,+BACT,kOACA,iFACL;EARS,KAAA,UAAA;EACA,KAAA,SAAA;EAQT,KAAK,OAAO;CACb;AACD;;;;;;;;;;;ACrEA,SAAgB,WAAW,KAAmC;CAC7D,IAAI,CAAC,OAAO,CAAC,IAAI,SAAS,GAAG,GAAG,OAAO,CAAC;CACxC,MAAM,MAAM,IAAI,IAAI,GAAG;CACvB,MAAM,MAAM,IAAI,IAAI,IAAI,QAAQ,aAAa,SAAS,CAAC;CACvD,OAAO,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,IAAI,SAAS,IAAI,IAAI,QAAQ,IAAI,MAAM,CAAC,CAAC;AACjE"}
|