@geekmidas/constructs 9.3.0 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/dist/{AWSScheduledFunction-CU7mMGFA.mjs → AWSScheduledFunction-BXmRm9W6.mjs} +4 -3
- package/dist/{AWSScheduledFunction-CU7mMGFA.mjs.map → AWSScheduledFunction-BXmRm9W6.mjs.map} +1 -1
- package/dist/{AWSScheduledFunction-CKhVurOa.cjs → AWSScheduledFunction-C-JBSNak.cjs} +6 -5
- package/dist/{AWSScheduledFunction-CKhVurOa.cjs.map → AWSScheduledFunction-C-JBSNak.cjs.map} +1 -1
- package/dist/{AWSScheduledFunction-Dg6TPIxn.d.mts → AWSScheduledFunction-DgQuL5kt.d.mts} +8 -2
- package/dist/AWSScheduledFunction-DgQuL5kt.d.mts.map +1 -0
- package/dist/{AWSScheduledFunction-DAGP_vz5.d.cts → AWSScheduledFunction-DoDZR8E6.d.cts} +8 -2
- package/dist/AWSScheduledFunction-DoDZR8E6.d.cts.map +1 -0
- package/dist/{Construct-D_3yZ9m5.d.cts → Construct-BEh2DSMe.d.cts} +7 -13
- package/dist/Construct-BEh2DSMe.d.cts.map +1 -0
- package/dist/{Construct-D09WUUOf.cjs → Construct-Cf_0pAvo.cjs} +2 -10
- package/dist/Construct-Cf_0pAvo.cjs.map +1 -0
- package/dist/{Construct-DsqpiAym.d.mts → Construct-CgluLUuF.d.mts} +7 -13
- package/dist/Construct-CgluLUuF.d.mts.map +1 -0
- package/dist/{Construct-D0uZvbr3.mjs → Construct-D5LZBFhb.mjs} +3 -11
- package/dist/Construct-D5LZBFhb.mjs.map +1 -0
- package/dist/{Endpoint-CxBdXNZm.d.cts → Endpoint-1u_i-nCT.d.cts} +2 -2
- package/dist/{Endpoint-CxBdXNZm.d.cts.map → Endpoint-1u_i-nCT.d.cts.map} +1 -1
- package/dist/{Endpoint-DEydLuBs.d.mts → Endpoint-CypDvYJW.d.mts} +3 -3
- package/dist/Endpoint-CypDvYJW.d.mts.map +1 -0
- package/dist/{HonoEndpointAdaptor-CJfFQ5KR.mjs → HonoEndpointAdaptor-C-mPVfwk.mjs} +11 -18
- package/dist/HonoEndpointAdaptor-C-mPVfwk.mjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-DCD0rhFg.cjs → HonoEndpointAdaptor-D_2UDPNs.cjs} +12 -19
- package/dist/HonoEndpointAdaptor-D_2UDPNs.cjs.map +1 -0
- package/dist/{Queue-Brw--scg.d.cts → Queue-Bl87Atny.d.cts} +2 -2
- package/dist/{Queue-Brw--scg.d.cts.map → Queue-Bl87Atny.d.cts.map} +1 -1
- package/dist/{Queue-D5z1bwFu.d.mts → Queue-Dhl8bc45.d.mts} +2 -2
- package/dist/{Queue-D5z1bwFu.d.mts.map → Queue-Dhl8bc45.d.mts.map} +1 -1
- package/dist/{Subscriber-DvKSp0N4.d.cts → Subscriber-YwPpHrBc.d.cts} +2 -2
- package/dist/{Subscriber-DvKSp0N4.d.cts.map → Subscriber-YwPpHrBc.d.cts.map} +1 -1
- package/dist/{Subscriber-CJ22tp8r.d.mts → Subscriber-panMf5vp.d.mts} +2 -2
- package/dist/{Subscriber-CJ22tp8r.d.mts.map → Subscriber-panMf5vp.d.mts.map} +1 -1
- package/dist/{Topic-BMfrIFdX.d.cts → Topic-DGtlTlu5.d.mts} +3 -3
- package/dist/{Topic-B-fxOsR2.d.mts.map → Topic-DGtlTlu5.d.mts.map} +1 -1
- package/dist/{Topic-B-fxOsR2.d.mts → Topic-dIcPqSLa.d.cts} +3 -3
- package/dist/{Topic-BMfrIFdX.d.cts.map → Topic-dIcPqSLa.d.cts.map} +1 -1
- package/dist/adaptors/aws.cjs +9 -14
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/aws.d.cts +6 -6
- package/dist/adaptors/aws.d.cts.map +1 -1
- package/dist/adaptors/aws.d.mts +8 -8
- package/dist/adaptors/aws.d.mts.map +1 -1
- package/dist/adaptors/aws.mjs +9 -14
- package/dist/adaptors/aws.mjs.map +1 -1
- package/dist/adaptors/hono.cjs +7 -7
- package/dist/adaptors/hono.d.cts +3 -3
- package/dist/adaptors/hono.d.cts.map +1 -1
- package/dist/adaptors/hono.d.mts +4 -4
- package/dist/adaptors/hono.d.mts.map +1 -1
- package/dist/adaptors/hono.mjs +7 -7
- package/dist/adaptors/testing.cjs +22 -29
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/testing.d.cts +5 -5
- package/dist/adaptors/testing.d.cts.map +1 -1
- package/dist/adaptors/testing.d.mts +6 -6
- package/dist/adaptors/testing.d.mts.map +1 -1
- package/dist/adaptors/testing.mjs +22 -29
- package/dist/adaptors/testing.mjs.map +1 -1
- package/dist/{clone-I_WIpiFf.cjs → clone-BQnYiRgm.cjs} +1 -1
- package/dist/{clone-I_WIpiFf.cjs.map → clone-BQnYiRgm.cjs.map} +1 -1
- package/dist/{clone-pdXxc0t3.mjs → clone-BWIwx6vL.mjs} +1 -1
- package/dist/{clone-pdXxc0t3.mjs.map → clone-BWIwx6vL.mjs.map} +1 -1
- package/dist/crons/index.cjs +27 -6
- package/dist/crons/index.cjs.map +1 -1
- package/dist/crons/index.d.cts +17 -7
- package/dist/crons/index.d.cts.map +1 -1
- package/dist/crons/index.d.mts +13 -3
- package/dist/crons/index.d.mts.map +1 -1
- package/dist/crons/index.mjs +27 -6
- package/dist/crons/index.mjs.map +1 -1
- package/dist/endpoints/index.cjs +7 -32
- package/dist/endpoints/index.cjs.map +1 -1
- package/dist/endpoints/index.d.cts +6 -14
- package/dist/endpoints/index.d.cts.map +1 -1
- package/dist/endpoints/index.d.mts +5 -13
- package/dist/endpoints/index.d.mts.map +1 -1
- package/dist/endpoints/index.mjs +7 -32
- package/dist/endpoints/index.mjs.map +1 -1
- package/dist/functions/index.cjs +3 -3
- package/dist/functions/index.d.cts +2 -2
- package/dist/functions/index.d.mts +2 -2
- package/dist/functions/index.mjs +3 -3
- package/dist/{functions-DhkDodl0.mjs → functions-CNJbRq0O.mjs} +4 -89
- package/dist/functions-CNJbRq0O.mjs.map +1 -0
- package/dist/{functions-B3OFv3QV.cjs → functions-DzjxHo1V.cjs} +3 -100
- package/dist/functions-DzjxHo1V.cjs.map +1 -0
- package/dist/{index-B8LNLQXD.d.mts → index-BUNi5ldW.d.mts} +2 -8
- package/dist/index-BUNi5ldW.d.mts.map +1 -0
- package/dist/{index-CeoLMr7c.d.cts → index-zeG5G432.d.cts} +6 -12
- package/dist/index-zeG5G432.d.cts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/{lazyAccessors-C1n1QfEj.cjs → lazyAccessors-BZJl6bx_.cjs} +3 -3
- package/dist/{lazyAccessors-C1n1QfEj.cjs.map → lazyAccessors-BZJl6bx_.cjs.map} +1 -1
- package/dist/{lazyAccessors-fFIQrblM.mjs → lazyAccessors-BjAZqRqK.mjs} +3 -3
- package/dist/{lazyAccessors-fFIQrblM.mjs.map → lazyAccessors-BjAZqRqK.mjs.map} +1 -1
- package/dist/monitor-D3uHJ8DU.cjs +67 -0
- package/dist/monitor-D3uHJ8DU.cjs.map +1 -0
- package/dist/monitor-Dt7fiasS.mjs +61 -0
- package/dist/monitor-Dt7fiasS.mjs.map +1 -0
- package/dist/monitors/index.cjs +2 -2
- package/dist/monitors/index.cjs.map +1 -1
- package/dist/monitors/index.d.cts +2 -2
- package/dist/monitors/index.d.cts.map +1 -1
- package/dist/monitors/index.d.mts +2 -2
- package/dist/monitors/index.mjs +2 -2
- package/dist/monitors/index.mjs.map +1 -1
- package/dist/{processAudits-CwyaaSQc.mjs → processAudits-BEiSkgH3.mjs} +1 -1
- package/dist/{processAudits-CwyaaSQc.mjs.map → processAudits-BEiSkgH3.mjs.map} +1 -1
- package/dist/{processAudits-94Ar_EJF.cjs → processAudits-Cd912Eck.cjs} +2 -2
- package/dist/{processAudits-94Ar_EJF.cjs.map → processAudits-Cd912Eck.cjs.map} +1 -1
- package/dist/{publisher-BZgcrVPy.cjs → publisher-B6Wu-JNv.cjs} +1 -1
- package/dist/{publisher-BZgcrVPy.cjs.map → publisher-B6Wu-JNv.cjs.map} +1 -1
- package/dist/{publisher-CnpeMv-r.mjs → publisher-Cs7WcvJl.mjs} +1 -1
- package/dist/{publisher-CnpeMv-r.mjs.map → publisher-Cs7WcvJl.mjs.map} +1 -1
- package/dist/queue/index.cjs +2 -2
- package/dist/queue/index.d.cts +2 -2
- package/dist/queue/index.d.mts +2 -2
- package/dist/queue/index.mjs +2 -2
- package/dist/subscribers/index.cjs +2 -2
- package/dist/subscribers/index.d.cts +5 -5
- package/dist/subscribers/index.d.cts.map +1 -1
- package/dist/subscribers/index.d.mts +3 -3
- package/dist/subscribers/index.mjs +2 -2
- package/dist/{telemetry-C--EgYVr.d.mts → telemetry-Bp4DLvdQ.d.mts} +1 -1
- package/dist/{telemetry-C--EgYVr.d.mts.map → telemetry-Bp4DLvdQ.d.mts.map} +1 -1
- package/dist/topic/index.cjs +2 -2
- package/dist/topic/index.d.cts +2 -2
- package/dist/topic/index.d.mts +2 -2
- package/dist/topic/index.mjs +2 -2
- package/dist/{types-DNngH0fX.d.mts → types-j0ti0JTY.d.mts} +1 -1
- package/dist/{types-DNngH0fX.d.mts.map → types-j0ti0JTY.d.mts.map} +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +22 -22
- package/src/Construct.ts +2 -13
- package/src/__tests__/uptime.spec.ts +340 -0
- package/src/crons/Cron.ts +10 -0
- package/src/crons/CronBuilder.ts +15 -1
- package/src/endpoints/AmazonApiGatewayEndpointAdaptor.ts +2 -23
- package/src/endpoints/EndpointBuilder.ts +1 -4
- package/src/endpoints/EndpointFactory.ts +0 -31
- package/src/endpoints/HonoEndpointAdaptor.ts +1 -16
- package/src/endpoints/TestEndpointAdaptor.ts +4 -20
- package/src/functions/BaseFunctionBuilder.ts +0 -10
- package/src/functions/FunctionBuilder.ts +0 -2
- package/src/monitor.ts +14 -55
- package/src/monitors/heartbeat.ts +4 -2
- package/dist/AWSScheduledFunction-DAGP_vz5.d.cts.map +0 -1
- package/dist/AWSScheduledFunction-Dg6TPIxn.d.mts.map +0 -1
- package/dist/Construct-D09WUUOf.cjs.map +0 -1
- package/dist/Construct-D0uZvbr3.mjs.map +0 -1
- package/dist/Construct-D_3yZ9m5.d.cts.map +0 -1
- package/dist/Construct-DsqpiAym.d.mts.map +0 -1
- package/dist/Endpoint-DEydLuBs.d.mts.map +0 -1
- package/dist/HonoEndpointAdaptor-CJfFQ5KR.mjs.map +0 -1
- package/dist/HonoEndpointAdaptor-DCD0rhFg.cjs.map +0 -1
- package/dist/functions-B3OFv3QV.cjs.map +0 -1
- package/dist/functions-DhkDodl0.mjs.map +0 -1
- package/dist/index-B8LNLQXD.d.mts.map +0 -1
- package/dist/index-CeoLMr7c.d.cts.map +0 -1
- package/src/__tests__/monitor.spec.ts +0 -696
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-
|
|
1
|
+
{"version":3,"file":"telemetry-Bp4DLvdQ.d.mts","names":[],"sources":["../src/telemetry.ts"],"sourcesContent":[],"mappings":";;;;;;;AA6FmB,UAlFF,gBAAA,CAkFE;EAAgB;;;EAQgB,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;;;;;UAhFlC,gBAAA;;;;;;;;WASP;;;;;UAMO,iBAAA;;;;;;;;;;;;YAcN;;;;;;;;;;;;;;;;;;;;;;;;;;;UA4BM,SAAA;;;;;;;0BAOQ,mBAAmB;;;;;;;oBAQzB,4BAA4B;;;;;;;sBAQ1B,yBAAyB"}
|
package/dist/topic/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_Construct = require('../Construct-
|
|
2
|
-
const require_clone = require('../clone-
|
|
1
|
+
const require_Construct = require('../Construct-Cf_0pAvo.cjs');
|
|
2
|
+
const require_clone = require('../clone-BQnYiRgm.cjs');
|
|
3
3
|
const __geekmidas_logger_console = require_Construct.__toESM(require("@geekmidas/logger/console"));
|
|
4
4
|
const __geekmidas_envkit = require_Construct.__toESM(require("@geekmidas/envkit"));
|
|
5
5
|
const __geekmidas_events = require_Construct.__toESM(require("@geekmidas/events"));
|
package/dist/topic/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../Construct-
|
|
2
|
-
import { Topic, TopicEvents, TopicMessage } from "../Topic-
|
|
1
|
+
import "../Construct-BEh2DSMe.cjs";
|
|
2
|
+
import { Topic, TopicEvents, TopicMessage } from "../Topic-dIcPqSLa.cjs";
|
|
3
3
|
import { Logger } from "@geekmidas/logger";
|
|
4
4
|
|
|
5
5
|
//#region src/topic/TopicBuilder.d.ts
|
package/dist/topic/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../Construct-
|
|
2
|
-
import { Topic, TopicEvents, TopicMessage } from "../Topic-
|
|
1
|
+
import "../Construct-CgluLUuF.mjs";
|
|
2
|
+
import { Topic, TopicEvents, TopicMessage } from "../Topic-DGtlTlu5.mjs";
|
|
3
3
|
import { Logger } from "@geekmidas/logger";
|
|
4
4
|
|
|
5
5
|
//#region src/topic/TopicBuilder.d.ts
|
package/dist/topic/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Construct, ConstructType } from "../Construct-
|
|
2
|
-
import { cloneWith } from "../clone-
|
|
1
|
+
import { Construct, ConstructType } from "../Construct-D5LZBFhb.mjs";
|
|
2
|
+
import { cloneWith } from "../clone-BWIwx6vL.mjs";
|
|
3
3
|
import { ConsoleLogger, DEFAULT_LOGGER } from "@geekmidas/logger/console";
|
|
4
4
|
import { environmentCase } from "@geekmidas/envkit";
|
|
5
5
|
import { Publisher } from "@geekmidas/events";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-j0ti0JTY.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";KAAY,6BAAA,MACC,CADD,IACM,CADS,CACP,CADO,CAAA,SAAA,SAAA,GAAA,KAAA,GACwB,CADxB,GAC4B,CAD5B,CAC8B,CAD9B,CAAA,EAAA;AACd,KAGD,UAAA,GAHC,KAAA,GAAA,MAAA,GAAA,KAAA,GAAA,OAAA,GAAA,QAAA,GAAA,SAAA;AAAK,KAWN,eAXM,CAAA,UAWoB,UAXpB,CAAA,GAWkC,SAXlC,CAW4C,CAX5C,CAAA"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { HttpMethod, LowerHttpMethod, RemoveUndefined } from "./types-
|
|
1
|
+
import { HttpMethod, LowerHttpMethod, RemoveUndefined } from "./types-j0ti0JTY.mjs";
|
|
2
2
|
export { HttpMethod, LowerHttpMethod, RemoveUndefined };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/constructs",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -152,33 +152,33 @@
|
|
|
152
152
|
"pg": "~8.16.3",
|
|
153
153
|
"msw": "~2.10.3",
|
|
154
154
|
"zod": "~4.6.6",
|
|
155
|
-
"@geekmidas/audit": "^9.
|
|
156
|
-
"@geekmidas/cache": "^9.
|
|
157
|
-
"@geekmidas/db": "^9.
|
|
158
|
-
"@geekmidas/envkit": "^9.
|
|
159
|
-
"@geekmidas/errors": "^9.
|
|
160
|
-
"@geekmidas/events": "^9.
|
|
161
|
-
"@geekmidas/logger": "^9.
|
|
162
|
-
"@geekmidas/rate-limit": "^9.
|
|
163
|
-
"@geekmidas/schema": "^9.
|
|
164
|
-
"@geekmidas/services": "^9.
|
|
165
|
-
"@geekmidas/testkit": "^9.
|
|
155
|
+
"@geekmidas/audit": "^9.4.0",
|
|
156
|
+
"@geekmidas/cache": "^9.4.0",
|
|
157
|
+
"@geekmidas/db": "^9.4.0",
|
|
158
|
+
"@geekmidas/envkit": "^9.4.0",
|
|
159
|
+
"@geekmidas/errors": "^9.4.0",
|
|
160
|
+
"@geekmidas/events": "^9.4.0",
|
|
161
|
+
"@geekmidas/logger": "^9.4.0",
|
|
162
|
+
"@geekmidas/rate-limit": "^9.4.0",
|
|
163
|
+
"@geekmidas/schema": "^9.4.0",
|
|
164
|
+
"@geekmidas/services": "^9.4.0",
|
|
165
|
+
"@geekmidas/testkit": "^9.4.0"
|
|
166
166
|
},
|
|
167
167
|
"peerDependencies": {
|
|
168
168
|
"@middy/core": ">=6.3.1",
|
|
169
169
|
"@types/aws-lambda": ">=8.10.92",
|
|
170
170
|
"hono": ">=4.8.2",
|
|
171
171
|
"msw": ">=2.0.0",
|
|
172
|
-
"@geekmidas/audit": "^9.
|
|
173
|
-
"@geekmidas/cache": "^9.
|
|
174
|
-
"@geekmidas/db": "^9.
|
|
175
|
-
"@geekmidas/envkit": "^9.
|
|
176
|
-
"@geekmidas/errors": "^9.
|
|
177
|
-
"@geekmidas/events": "^9.
|
|
178
|
-
"@geekmidas/logger": "^9.
|
|
179
|
-
"@geekmidas/rate-limit": "^9.
|
|
180
|
-
"@geekmidas/schema": "^9.
|
|
181
|
-
"@geekmidas/services": "^9.
|
|
172
|
+
"@geekmidas/audit": "^9.4.0",
|
|
173
|
+
"@geekmidas/cache": "^9.4.0",
|
|
174
|
+
"@geekmidas/db": "^9.4.0",
|
|
175
|
+
"@geekmidas/envkit": "^9.4.0",
|
|
176
|
+
"@geekmidas/errors": "^9.4.0",
|
|
177
|
+
"@geekmidas/events": "^9.4.0",
|
|
178
|
+
"@geekmidas/logger": "^9.4.0",
|
|
179
|
+
"@geekmidas/rate-limit": "^9.4.0",
|
|
180
|
+
"@geekmidas/schema": "^9.4.0",
|
|
181
|
+
"@geekmidas/services": "^9.4.0"
|
|
182
182
|
},
|
|
183
183
|
"peerDependenciesMeta": {
|
|
184
184
|
"@geekmidas/audit": {
|
package/src/Construct.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { Logger } from '@geekmidas/logger';
|
|
|
9
9
|
import type { Service, ServiceContext } from '@geekmidas/services';
|
|
10
10
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
11
11
|
import compact from 'lodash.compact';
|
|
12
|
-
import type {
|
|
12
|
+
import type { MonitorService } from './monitor';
|
|
13
13
|
|
|
14
14
|
// Cache for service environment variables to handle singleton services
|
|
15
15
|
// Stores both the full list and the optional subset so the same sniff result
|
|
@@ -61,7 +61,7 @@ export abstract class Construct<
|
|
|
61
61
|
/** Database service for this construct (used by Endpoint for RLS/audit context) */
|
|
62
62
|
public databaseService?: Service<TDatabaseServiceName, TDatabase>;
|
|
63
63
|
|
|
64
|
-
/** Monitors told about each run
|
|
64
|
+
/** Monitors told about each run: a cron's `.uptime()`, if it has one. */
|
|
65
65
|
public monitors: MonitorService[] = [];
|
|
66
66
|
|
|
67
67
|
constructor(
|
|
@@ -80,17 +80,6 @@ export abstract class Construct<
|
|
|
80
80
|
>,
|
|
81
81
|
) {}
|
|
82
82
|
|
|
83
|
-
/**
|
|
84
|
-
* This construct's monitors as the build manifest records them, or nothing
|
|
85
|
-
* when it has none.
|
|
86
|
-
*/
|
|
87
|
-
getMonitoring(): MonitorInfo[] | undefined {
|
|
88
|
-
if (!this.monitors.length) return undefined;
|
|
89
|
-
return this.monitors.map(
|
|
90
|
-
(monitor) => monitor.monitor ?? { type: monitor.serviceName },
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
83
|
/**
|
|
95
84
|
* Returns an array of environment variable names required by this construct's services.
|
|
96
85
|
* This is determined by running a "sniffer" EnvironmentParser through each service's
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { EnvironmentParser } from '@geekmidas/envkit';
|
|
2
|
+
import { ServiceDiscovery } from '@geekmidas/services';
|
|
3
|
+
import { createMockContext } from '@geekmidas/testkit/aws';
|
|
4
|
+
import { HttpResponse, http } from 'msw';
|
|
5
|
+
import { setupServer } from 'msw/node';
|
|
6
|
+
import {
|
|
7
|
+
afterAll,
|
|
8
|
+
afterEach,
|
|
9
|
+
beforeAll,
|
|
10
|
+
beforeEach,
|
|
11
|
+
describe,
|
|
12
|
+
expect,
|
|
13
|
+
it,
|
|
14
|
+
vi,
|
|
15
|
+
} from 'vitest';
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { AWSScheduledFunction } from '../crons/AWSScheduledFunction';
|
|
18
|
+
import { CronBuilder } from '../crons/CronBuilder';
|
|
19
|
+
import { EndpointFactory } from '../endpoints/EndpointFactory';
|
|
20
|
+
import { FunctionBuilder } from '../functions/FunctionBuilder';
|
|
21
|
+
import { TestFunctionAdaptor } from '../functions/TestFunctionAdaptor';
|
|
22
|
+
import type { ConstructMonitor, MonitorService } from '../monitor';
|
|
23
|
+
import { heartbeat } from '../monitors';
|
|
24
|
+
|
|
25
|
+
const HEARTBEAT = 'https://heartbeat.test/api/v1/heartbeat/abc';
|
|
26
|
+
|
|
27
|
+
/** Every heartbeat request MSW saw, as `path`. */
|
|
28
|
+
const pings: string[] = [];
|
|
29
|
+
|
|
30
|
+
const server = setupServer(
|
|
31
|
+
http.get('https://heartbeat.test/*', ({ request }) => {
|
|
32
|
+
pings.push(new URL(request.url).pathname.replace('/api/v1/heartbeat', ''));
|
|
33
|
+
return new HttpResponse(null, { status: 200 });
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
/** A monitor that writes down what it was told, in order. */
|
|
38
|
+
function recorder(serviceName = 'recorder') {
|
|
39
|
+
const calls: string[] = [];
|
|
40
|
+
const service = {
|
|
41
|
+
serviceName,
|
|
42
|
+
async register(): Promise<ConstructMonitor<string>> {
|
|
43
|
+
return {
|
|
44
|
+
async start() {
|
|
45
|
+
calls.push('start');
|
|
46
|
+
return 'run-1';
|
|
47
|
+
},
|
|
48
|
+
async success({ run }) {
|
|
49
|
+
calls.push(`success:${run}`);
|
|
50
|
+
},
|
|
51
|
+
async failure({ run, error }) {
|
|
52
|
+
calls.push(`failure:${run}:${(error as Error).message}`);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
} satisfies MonitorService;
|
|
57
|
+
|
|
58
|
+
return { calls, service };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const throwing = {
|
|
62
|
+
serviceName: 'throwing',
|
|
63
|
+
async register(): Promise<ConstructMonitor> {
|
|
64
|
+
return {
|
|
65
|
+
async start() {
|
|
66
|
+
throw new Error('start failed');
|
|
67
|
+
},
|
|
68
|
+
async success() {
|
|
69
|
+
throw new Error('success failed');
|
|
70
|
+
},
|
|
71
|
+
async failure() {
|
|
72
|
+
throw new Error('failure failed');
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
} satisfies MonitorService;
|
|
77
|
+
|
|
78
|
+
function discovery(env: Record<string, string> = {}) {
|
|
79
|
+
return ServiceDiscovery.getInstance(new EnvironmentParser(env));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
|
|
83
|
+
afterAll(() => server.close());
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
// Services are cached by name, so each test starts from its own env.
|
|
86
|
+
ServiceDiscovery.reset();
|
|
87
|
+
pings.length = 0;
|
|
88
|
+
});
|
|
89
|
+
afterEach(() => server.resetHandlers());
|
|
90
|
+
|
|
91
|
+
const cron = (monitor: MonitorService) =>
|
|
92
|
+
new CronBuilder()
|
|
93
|
+
.input(z.object({}))
|
|
94
|
+
.schedule('cron(0 0 * * *)')
|
|
95
|
+
.uptime(monitor);
|
|
96
|
+
|
|
97
|
+
describe('cron.uptime() with a heartbeat', () => {
|
|
98
|
+
it('pings the URL when a run succeeds', async () => {
|
|
99
|
+
await new TestFunctionAdaptor(
|
|
100
|
+
cron(heartbeat.betterStack()).handle(async () => ({ ok: true })),
|
|
101
|
+
discovery({ HEARTBEAT_URL: HEARTBEAT }),
|
|
102
|
+
).invoke({ input: {}, services: {} });
|
|
103
|
+
|
|
104
|
+
expect(pings).toEqual(['/abc']);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('pings the failure URL and rethrows when a run fails', async () => {
|
|
108
|
+
await expect(
|
|
109
|
+
new TestFunctionAdaptor(
|
|
110
|
+
cron(heartbeat.betterStack()).handle(async () => {
|
|
111
|
+
throw new Error('boom');
|
|
112
|
+
}),
|
|
113
|
+
discovery({ HEARTBEAT_URL: HEARTBEAT }),
|
|
114
|
+
).invoke({ input: {}, services: {} }),
|
|
115
|
+
).rejects.toThrow('boom');
|
|
116
|
+
|
|
117
|
+
expect(pings).toEqual(['/abc/fail']);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('pings start before success for providers that take one', async () => {
|
|
121
|
+
await new TestFunctionAdaptor(
|
|
122
|
+
cron(heartbeat.healthchecks()).handle(async () => ({})),
|
|
123
|
+
discovery({ HEARTBEAT_URL: HEARTBEAT }),
|
|
124
|
+
).invoke({ input: {}, services: {} });
|
|
125
|
+
|
|
126
|
+
expect(pings).toEqual(['/abc/start', '/abc']);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('skips the heartbeat but still runs when its env var is missing', async () => {
|
|
130
|
+
const output = await new TestFunctionAdaptor(
|
|
131
|
+
cron(heartbeat.betterStack())
|
|
132
|
+
.output(z.object({ ok: z.boolean() }))
|
|
133
|
+
.handle(async () => ({ ok: true })),
|
|
134
|
+
discovery(),
|
|
135
|
+
).invoke({ input: {}, services: {} });
|
|
136
|
+
|
|
137
|
+
expect(output).toEqual({ ok: true });
|
|
138
|
+
expect(pings).toEqual([]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('reads the env var it was given', async () => {
|
|
142
|
+
await new TestFunctionAdaptor(
|
|
143
|
+
cron(heartbeat.betterStack('NIGHTLY_HEARTBEAT_URL')).handle(
|
|
144
|
+
async () => ({}),
|
|
145
|
+
),
|
|
146
|
+
discovery({ NIGHTLY_HEARTBEAT_URL: `${HEARTBEAT}/nightly` }),
|
|
147
|
+
).invoke({ input: {}, services: {} });
|
|
148
|
+
|
|
149
|
+
expect(pings).toEqual(['/abc/nightly']);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('does not fail the run when the provider is down', async () => {
|
|
153
|
+
server.use(
|
|
154
|
+
http.get('https://heartbeat.test/*', () =>
|
|
155
|
+
HttpResponse.json({ error: 'down' }, { status: 503 }),
|
|
156
|
+
),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const output = await new TestFunctionAdaptor(
|
|
160
|
+
cron(heartbeat.betterStack())
|
|
161
|
+
.output(z.object({ ok: z.boolean() }))
|
|
162
|
+
.handle(async () => ({ ok: true })),
|
|
163
|
+
discovery({ HEARTBEAT_URL: HEARTBEAT }),
|
|
164
|
+
).invoke({ input: {}, services: {} });
|
|
165
|
+
|
|
166
|
+
expect(output).toEqual({ ok: true });
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('declares its env var as required', async () => {
|
|
170
|
+
const environment = await cron(
|
|
171
|
+
heartbeat.betterStack('NIGHTLY_HEARTBEAT_URL'),
|
|
172
|
+
)
|
|
173
|
+
.handle(async () => ({}))
|
|
174
|
+
.getEnvironment({ markOptional: true });
|
|
175
|
+
|
|
176
|
+
expect(environment).toContain('NIGHTLY_HEARTBEAT_URL');
|
|
177
|
+
expect(environment).not.toContain('NIGHTLY_HEARTBEAT_URL?');
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe('cron.uptime()', () => {
|
|
182
|
+
it('reports start, then success with what start returned', async () => {
|
|
183
|
+
const { calls, service } = recorder();
|
|
184
|
+
|
|
185
|
+
await new TestFunctionAdaptor(
|
|
186
|
+
cron(service).handle(async () => ({})),
|
|
187
|
+
discovery(),
|
|
188
|
+
).invoke({ input: {}, services: {} });
|
|
189
|
+
|
|
190
|
+
expect(calls).toEqual(['start', 'success:run-1']);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('ignores a monitor that throws', async () => {
|
|
194
|
+
const output = await new TestFunctionAdaptor(
|
|
195
|
+
cron(throwing)
|
|
196
|
+
.output(z.object({ ok: z.boolean() }))
|
|
197
|
+
.handle(async () => ({ ok: true })),
|
|
198
|
+
discovery(),
|
|
199
|
+
).invoke({ input: {}, services: {} });
|
|
200
|
+
|
|
201
|
+
expect(output).toEqual({ ok: true });
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('replaces the monitor when called again', () => {
|
|
205
|
+
const first = recorder('first');
|
|
206
|
+
const second = recorder('second');
|
|
207
|
+
|
|
208
|
+
const nightly = cron(first.service)
|
|
209
|
+
.uptime(second.service)
|
|
210
|
+
.handle(async () => ({}));
|
|
211
|
+
|
|
212
|
+
expect(nightly.monitors.map((m) => m.serviceName)).toEqual(['second']);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('is inherited from a shared base', () => {
|
|
216
|
+
const shared = recorder('shared');
|
|
217
|
+
const base = new CronBuilder().uptime(shared.service);
|
|
218
|
+
|
|
219
|
+
const nightly = base.schedule('cron(0 0 * * *)').handle(async () => ({}));
|
|
220
|
+
const hourly = base.schedule('cron(0 * * * *)').handle(async () => ({}));
|
|
221
|
+
|
|
222
|
+
expect(nightly.monitors.map((m) => m.serviceName)).toEqual(['shared']);
|
|
223
|
+
expect(hourly.monitors.map((m) => m.serviceName)).toEqual(['shared']);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('is not available on functions or endpoints', () => {
|
|
227
|
+
// @ts-expect-error uptime is for crons only
|
|
228
|
+
expect(new FunctionBuilder().uptime).toBeUndefined();
|
|
229
|
+
// @ts-expect-error monitor() is removed
|
|
230
|
+
expect(new FunctionBuilder().monitor).toBeUndefined();
|
|
231
|
+
// @ts-expect-error monitor() is removed
|
|
232
|
+
expect(new EndpointFactory().monitor).toBeUndefined();
|
|
233
|
+
// @ts-expect-error monitor() is removed
|
|
234
|
+
expect(new EndpointFactory().get('/x').monitor).toBeUndefined();
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe('cron.uptime() in the AWS Lambda handler', () => {
|
|
239
|
+
const invoke = (construct: any, env = { HEARTBEAT_URL: HEARTBEAT }) =>
|
|
240
|
+
new AWSScheduledFunction(new EnvironmentParser(env), construct).handler(
|
|
241
|
+
{},
|
|
242
|
+
createMockContext(),
|
|
243
|
+
vi.fn(),
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
it('sends the success ping', async () => {
|
|
247
|
+
await invoke(cron(heartbeat.betterStack()).handle(async () => ({})));
|
|
248
|
+
expect(pings).toEqual(['/abc']);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('sends the failure ping', async () => {
|
|
252
|
+
await expect(
|
|
253
|
+
invoke(
|
|
254
|
+
cron(heartbeat.betterStack()).handle(async () => {
|
|
255
|
+
throw new Error('boom');
|
|
256
|
+
}),
|
|
257
|
+
),
|
|
258
|
+
).rejects.toThrow();
|
|
259
|
+
expect(pings).toEqual(['/abc/fail']);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('reports the original error, not the wrapped one', async () => {
|
|
263
|
+
const { calls, service } = recorder();
|
|
264
|
+
discovery();
|
|
265
|
+
|
|
266
|
+
await expect(
|
|
267
|
+
invoke(
|
|
268
|
+
cron(service).handle(async () => {
|
|
269
|
+
throw new Error('boom');
|
|
270
|
+
}),
|
|
271
|
+
),
|
|
272
|
+
).rejects.toThrow();
|
|
273
|
+
expect(calls).toEqual(['start', 'failure:run-1:boom']);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('sends the start ping first, for Healthchecks.io', async () => {
|
|
277
|
+
await invoke(cron(heartbeat.healthchecks()).handle(async () => ({})));
|
|
278
|
+
expect(pings).toEqual(['/abc/start', '/abc']);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('sends one ping per run, from a shared base', async () => {
|
|
282
|
+
const base = new CronBuilder().uptime(heartbeat.betterStack());
|
|
283
|
+
|
|
284
|
+
await invoke(base.schedule('cron(0 0 * * *)').handle(async () => ({})));
|
|
285
|
+
await invoke(base.schedule('cron(0 * * * *)').handle(async () => ({})));
|
|
286
|
+
|
|
287
|
+
expect(pings).toEqual(['/abc', '/abc']);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe('getUptime', () => {
|
|
292
|
+
it('records the monitor for the manifest', () => {
|
|
293
|
+
expect(
|
|
294
|
+
cron(heartbeat.betterStack('MONITORING_URL'))
|
|
295
|
+
.handle(async () => ({}))
|
|
296
|
+
.getUptime(),
|
|
297
|
+
).toEqual({
|
|
298
|
+
type: 'heartbeat',
|
|
299
|
+
provider: 'betterStack',
|
|
300
|
+
env: 'MONITORING_URL',
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('records a custom heartbeat without a provider, on its default env var', () => {
|
|
305
|
+
expect(
|
|
306
|
+
cron(heartbeat())
|
|
307
|
+
.handle(async () => ({}))
|
|
308
|
+
.getUptime(),
|
|
309
|
+
).toEqual({
|
|
310
|
+
type: 'heartbeat',
|
|
311
|
+
env: 'HEARTBEAT_URL',
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('records a hand-written monitor by its service name', () => {
|
|
316
|
+
const custom = {
|
|
317
|
+
serviceName: 'custom',
|
|
318
|
+
async register() {
|
|
319
|
+
return { async success() {}, async failure() {} };
|
|
320
|
+
},
|
|
321
|
+
} satisfies MonitorService;
|
|
322
|
+
|
|
323
|
+
expect(
|
|
324
|
+
cron(custom)
|
|
325
|
+
.handle(async () => ({}))
|
|
326
|
+
.getUptime(),
|
|
327
|
+
).toEqual({
|
|
328
|
+
type: 'custom',
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it('records nothing for a cron without one', () => {
|
|
333
|
+
expect(
|
|
334
|
+
new CronBuilder()
|
|
335
|
+
.schedule('cron(0 0 * * *)')
|
|
336
|
+
.handle(async () => ({}))
|
|
337
|
+
.getUptime(),
|
|
338
|
+
).toBeUndefined();
|
|
339
|
+
});
|
|
340
|
+
});
|
package/src/crons/Cron.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
|
7
7
|
|
|
8
8
|
import { ConstructType } from '../Construct';
|
|
9
9
|
import { Function, type FunctionHandler } from '../functions';
|
|
10
|
+
import type { MonitorInfo } from '../monitor';
|
|
10
11
|
|
|
11
12
|
export class Cron<
|
|
12
13
|
TInput extends ComposableStandardSchema | undefined = undefined,
|
|
@@ -71,6 +72,15 @@ export class Cron<
|
|
|
71
72
|
get schedule(): ScheduleExpression | undefined {
|
|
72
73
|
return this._schedule;
|
|
73
74
|
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The monitor set with `.uptime()` as the build manifest records it, or
|
|
78
|
+
* nothing when the cron has none.
|
|
79
|
+
*/
|
|
80
|
+
getUptime(): MonitorInfo | undefined {
|
|
81
|
+
const [uptime] = this.monitors;
|
|
82
|
+
return uptime && (uptime.monitor ?? { type: uptime.serviceName });
|
|
83
|
+
}
|
|
74
84
|
}
|
|
75
85
|
|
|
76
86
|
// ---- Cron expression types ------------------------------------------------
|
package/src/crons/CronBuilder.ts
CHANGED
|
@@ -7,6 +7,7 @@ import uniqBy from 'lodash.uniqby';
|
|
|
7
7
|
import { ConstructType } from '../Construct';
|
|
8
8
|
import { cloneWith } from '../clone';
|
|
9
9
|
import { FunctionBuilder, type FunctionHandler } from '../functions';
|
|
10
|
+
import type { MonitorService } from '../monitor';
|
|
10
11
|
import { Cron, type CronExpression, type ScheduleExpression } from './Cron';
|
|
11
12
|
|
|
12
13
|
export class CronBuilder<
|
|
@@ -31,6 +32,7 @@ export class CronBuilder<
|
|
|
31
32
|
TDatabaseServiceName
|
|
32
33
|
> {
|
|
33
34
|
private _schedule?: ScheduleExpression;
|
|
35
|
+
private _uptime?: MonitorService;
|
|
34
36
|
|
|
35
37
|
constructor() {
|
|
36
38
|
super(ConstructType.Cron);
|
|
@@ -61,6 +63,18 @@ export class CronBuilder<
|
|
|
61
63
|
});
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Report each run to an uptime monitor, so a cron that stops running is
|
|
68
|
+
* noticed: `heartbeat.betterStack()` pings on success and reports a
|
|
69
|
+
* failure. Calling it again replaces the monitor.
|
|
70
|
+
*
|
|
71
|
+
* `gkm build` records it in the manifest with the schedule's period, the
|
|
72
|
+
* longest gap between runs, so infrastructure can create the heartbeat.
|
|
73
|
+
*/
|
|
74
|
+
uptime(monitor: MonitorService): this {
|
|
75
|
+
return cloneWith(this, { _uptime: monitor });
|
|
76
|
+
}
|
|
77
|
+
|
|
64
78
|
override input<T extends ComposableStandardSchema>(
|
|
65
79
|
schema: T,
|
|
66
80
|
): CronBuilder<
|
|
@@ -260,7 +274,7 @@ export class CronBuilder<
|
|
|
260
274
|
// configured base keeps its configuration for every construct built
|
|
261
275
|
// from it. The reset that used to be here wiped the base on first use.
|
|
262
276
|
|
|
263
|
-
cron.monitors = this.
|
|
277
|
+
cron.monitors = this._uptime ? [this._uptime] : [];
|
|
264
278
|
|
|
265
279
|
return cron;
|
|
266
280
|
}
|
|
@@ -37,7 +37,6 @@ import {
|
|
|
37
37
|
ServiceDiscovery,
|
|
38
38
|
type ServiceRecord,
|
|
39
39
|
} from '@geekmidas/services';
|
|
40
|
-
import { startMonitors } from '../monitor';
|
|
41
40
|
import { publishConstructEvents } from '../publisher';
|
|
42
41
|
import type { MappedAudit } from './audit';
|
|
43
42
|
import type { CookieFn, HeaderFn } from './Endpoint';
|
|
@@ -134,8 +133,6 @@ export abstract class AmazonApiGatewayEndpoint<
|
|
|
134
133
|
'Error processing request',
|
|
135
134
|
);
|
|
136
135
|
const wrappedError = wrapError(req.error);
|
|
137
|
-
// Kept for the monitors, which only see the response otherwise.
|
|
138
|
-
(req.event as any).__error = req.error;
|
|
139
136
|
|
|
140
137
|
// Set the response with the proper status code from the HttpError
|
|
141
138
|
req.response = {
|
|
@@ -595,26 +592,8 @@ export abstract class AmazonApiGatewayEndpoint<
|
|
|
595
592
|
|
|
596
593
|
// Cast event to any since Middy middlewares enrich the event with
|
|
597
594
|
// services, logger, session, etc. during the middleware chain execution
|
|
598
|
-
return runWithRequestContext(
|
|
599
|
-
|
|
600
|
-
async () => {
|
|
601
|
-
const monitor = await startMonitors(
|
|
602
|
-
this.endpoint,
|
|
603
|
-
ServiceDiscovery.getInstance(this.envParser),
|
|
604
|
-
logger,
|
|
605
|
-
);
|
|
606
|
-
const response = await chain(
|
|
607
|
-
event as unknown as Parameters<typeof chain>[0],
|
|
608
|
-
context,
|
|
609
|
-
);
|
|
610
|
-
// Awaited: Lambda freezes the process once the response is
|
|
611
|
-
// returned, so an unawaited ping may never be sent.
|
|
612
|
-
await monitor.settle(
|
|
613
|
-
(response as any)?.statusCode ?? 200,
|
|
614
|
-
(event as any).__error,
|
|
615
|
-
);
|
|
616
|
-
return response;
|
|
617
|
-
},
|
|
595
|
+
return runWithRequestContext({ logger, requestId, startTime }, () =>
|
|
596
|
+
chain(event as unknown as Parameters<typeof chain>[0], context),
|
|
618
597
|
);
|
|
619
598
|
};
|
|
620
599
|
|
|
@@ -715,7 +715,7 @@ export class EndpointBuilder<
|
|
|
715
715
|
}
|
|
716
716
|
}
|
|
717
717
|
|
|
718
|
-
|
|
718
|
+
return new Endpoint({
|
|
719
719
|
fn,
|
|
720
720
|
method: this.method,
|
|
721
721
|
route: this.route,
|
|
@@ -742,8 +742,5 @@ export class EndpointBuilder<
|
|
|
742
742
|
rlsBypass: this._rlsBypass,
|
|
743
743
|
responseType: this._responseType,
|
|
744
744
|
});
|
|
745
|
-
endpoint.monitors = this._monitors;
|
|
746
|
-
|
|
747
|
-
return endpoint;
|
|
748
745
|
}
|
|
749
746
|
}
|