sdk-aws-lambda 0.7.3 → 0.8.1
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/dist/domain.objects/LambdaEndpointRefusal.d.ts +25 -0
- package/dist/domain.objects/LambdaEndpointRefusal.js +19 -0
- package/dist/domain.objects/LambdaEndpointRefusal.js.map +1 -0
- package/dist/domain.objects/LambdaEndpointRefusedError.d.ts +25 -0
- package/dist/domain.objects/LambdaEndpointRefusedError.js +28 -0
- package/dist/domain.objects/LambdaEndpointRefusedError.js.map +1 -0
- package/dist/domain.objects/LambdaEventSchemaSource.d.ts +26 -0
- package/dist/domain.objects/LambdaEventSchemaSource.js +11 -0
- package/dist/domain.objects/LambdaEventSchemaSource.js.map +1 -0
- package/dist/domain.operations/asLambdaEventSchema/KinesisStreamEventDecoded.d.ts +13 -0
- package/dist/domain.operations/asLambdaEventSchema/KinesisStreamEventDecoded.js +3 -0
- package/dist/domain.operations/asLambdaEventSchema/KinesisStreamEventDecoded.js.map +1 -0
- package/dist/domain.operations/asLambdaEventSchema/SnsEventDecoded.d.ts +19 -0
- package/dist/domain.operations/asLambdaEventSchema/SnsEventDecoded.js +3 -0
- package/dist/domain.operations/asLambdaEventSchema/SnsEventDecoded.js.map +1 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventPayloadSchema.d.ts +37 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventPayloadSchema.js +57 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventPayloadSchema.js.map +1 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventSchema.d.ts +39 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventSchema.fromKinesis.d.ts +61 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventSchema.fromKinesis.js +89 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventSchema.fromKinesis.js.map +1 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventSchema.fromSns.d.ts +58 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventSchema.fromSns.js +81 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventSchema.fromSns.js.map +1 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventSchema.js +45 -0
- package/dist/domain.operations/asLambdaEventSchema/asLambdaEventSchema.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.d.ts +3 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.d.ts +11 -2
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.js +7 -2
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaApiGateway.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.d.ts +10 -0
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.js +17 -5
- package/dist/domain.operations/askLambdaEndpoint/askLambdaEndpoint.viaInvoke.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/cache/asAskLambdaCacheKeyOfRefusal.d.ts +17 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/asAskLambdaCacheKeyOfRefusal.js +22 -0
- package/dist/domain.operations/askLambdaEndpoint/cache/asAskLambdaCacheKeyOfRefusal.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.d.ts +2 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js +1 -0
- package/dist/domain.operations/askLambdaEndpoint/invoke/executeLambdaInvocation.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.d.ts +9 -5
- package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.js +27 -9
- package/dist/domain.operations/askLambdaEndpoint/serde/asErrorFromHttpResponse.js.map +1 -1
- package/dist/domain.operations/askLambdaEndpoint/serde/asLambdaEndpointRefusal.d.ts +15 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asLambdaEndpointRefusal.js +43 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/asLambdaEndpointRefusal.js.map +1 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getIsHttpThrottle.d.ts +11 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getIsHttpThrottle.js +15 -0
- package/dist/domain.operations/askLambdaEndpoint/serde/getIsHttpThrottle.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/genLambdaEndpoint.forAsk.d.ts +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/genLambdaEndpoint.forAsk.js +9 -2
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/genLambdaEndpoint.forAsk.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/middleware/genLambdaEventRefusedLogMiddleware.d.ts +25 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/middleware/genLambdaEventRefusedLogMiddleware.js +66 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/middleware/genLambdaEventRefusedLogMiddleware.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/middleware/getAllLambdaEventIds.d.ts +12 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/middleware/getAllLambdaEventIds.js +42 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/middleware/getAllLambdaEventIds.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/middleware/logLambdaEventRefused.d.ts +27 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/middleware/logLambdaEventRefused.js +103 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forAsk/middleware/logLambdaEventRefused.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.js +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/{genLambdaEndpoint.forSqs → middleware}/asCallerFault.d.ts +4 -3
- package/dist/domain.operations/genLambdaEndpoint/{genLambdaEndpoint.forSqs → middleware}/asCallerFault.js +5 -4
- package/dist/domain.operations/genLambdaEndpoint/middleware/asCallerFault.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/asLogMethodOfFailure.d.ts +17 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/asLogMethodOfFailure.js +26 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/asLogMethodOfFailure.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js +2 -2
- package/dist/domain.operations/genLambdaEndpoint/middleware/genInternalServiceErrorMiddleware.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.d.ts +15 -0
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js +34 -13
- package/dist/domain.operations/genLambdaEndpoint/middleware/genIoLoggerMiddleware.js.map +1 -1
- package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.js +1 -1
- package/dist/domain.operations/genServiceSdk/gen.file/asMechanismsFileSource.js.map +1 -1
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.d.ts +2 -0
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.js +8 -4
- package/dist/domain.operations/genServiceSdk/gen.mechanism/asMechanismFnSource.js.map +1 -1
- package/dist/domain.operations/lambdaEndpointWire/error/asErrorFromPeerRefusal.d.ts +22 -0
- package/dist/domain.operations/lambdaEndpointWire/error/asErrorFromPeerRefusal.js +34 -0
- package/dist/domain.operations/lambdaEndpointWire/error/asErrorFromPeerRefusal.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneLambdaEventSchemaSource.d.ts +15 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneLambdaEventSchemaSource.js +50 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/getOneLambdaEventSchemaSource.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/setLambdaEventSchemaSource.d.ts +27 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/setLambdaEventSchemaSource.js +31 -0
- package/dist/domain.operations/lambdaEndpointWire/frame/setLambdaEventSchemaSource.js.map +1 -0
- package/dist/domain.operations/lambdaEndpointWire/getParsedResponse.d.ts +15 -4
- package/dist/domain.operations/lambdaEndpointWire/getParsedResponse.js +32 -17
- package/dist/domain.operations/lambdaEndpointWire/getParsedResponse.js.map +1 -1
- package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.js +12 -0
- package/dist/domain.operations/runLambdaEndpoint/runLambdaEndpoint.onSerialized.js.map +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
- package/readme.md +115 -2
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.js.map +0 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = how a caller wants a peer endpoint's refusal thrown
|
|
3
|
+
* .why = a peer's refusal of a request this caller composed is this caller's malfunction, so the
|
|
4
|
+
* default throws `LambdaEndpointRefusedError`. a caller that forwards its own caller's
|
|
5
|
+
* input verbatim may name `ConstraintError` instead, which passes the fault on as its
|
|
6
|
+
* caller's to fix
|
|
7
|
+
*
|
|
8
|
+
* .note = a named value, never a boolean, so the call site states which class it gets
|
|
9
|
+
* (rule.require.explicit-optout)
|
|
10
|
+
* .note = `readonly`, since one default instance is shared by every call that omits the opt
|
|
11
|
+
*/
|
|
12
|
+
export interface LambdaEndpointRefusal {
|
|
13
|
+
readonly as: 'ConstraintError' | 'LambdaEndpointRefusedError';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* .what = the refusal stance of a caller that composed its request
|
|
17
|
+
* .why = the default of every ask road: a peer's refusal is this caller's own malfunction
|
|
18
|
+
*/
|
|
19
|
+
export declare const REFUSAL_DEFAULT: LambdaEndpointRefusal;
|
|
20
|
+
/**
|
|
21
|
+
* .what = the refusal stance of a caller that forwards its own caller's input verbatim
|
|
22
|
+
* .why = the opt-in of an ask road, and the fixed stance of `runLambdaEndpoint.onSerialized`,
|
|
23
|
+
* whose caller composed the event itself
|
|
24
|
+
*/
|
|
25
|
+
export declare const REFUSAL_PASSTHROUGH: LambdaEndpointRefusal;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REFUSAL_PASSTHROUGH = exports.REFUSAL_DEFAULT = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = the refusal stance of a caller that composed its request
|
|
6
|
+
* .why = the default of every ask road: a peer's refusal is this caller's own malfunction
|
|
7
|
+
*/
|
|
8
|
+
exports.REFUSAL_DEFAULT = {
|
|
9
|
+
as: 'LambdaEndpointRefusedError',
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* .what = the refusal stance of a caller that forwards its own caller's input verbatim
|
|
13
|
+
* .why = the opt-in of an ask road, and the fixed stance of `runLambdaEndpoint.onSerialized`,
|
|
14
|
+
* whose caller composed the event itself
|
|
15
|
+
*/
|
|
16
|
+
exports.REFUSAL_PASSTHROUGH = {
|
|
17
|
+
as: 'ConstraintError',
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=LambdaEndpointRefusal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LambdaEndpointRefusal.js","sourceRoot":"","sources":["../../src/domain.objects/LambdaEndpointRefusal.ts"],"names":[],"mappings":";;;AAeA;;;GAGG;AACU,QAAA,eAAe,GAA0B;IACpD,EAAE,EAAE,4BAA4B;CACjC,CAAC;AAEF;;;;GAIG;AACU,QAAA,mBAAmB,GAA0B;IACxD,EAAE,EAAE,iBAAiB;CACtB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MalfunctionError } from 'helpful-errors';
|
|
2
|
+
/**
|
|
3
|
+
* .what = the metadata a `LambdaEndpointRefusedError` carries
|
|
4
|
+
* .why = helpful-errors exports no name for its metadata shape, so it is read off the parent's
|
|
5
|
+
* own constructor rather than restated
|
|
6
|
+
*/
|
|
7
|
+
export type LambdaEndpointRefusedErrorMetadata = NonNullable<ConstructorParameters<typeof MalfunctionError>[1]>;
|
|
8
|
+
/**
|
|
9
|
+
* .what = a peer endpoint refused a request this caller composed
|
|
10
|
+
* .why = a peer's `ConstraintError` / `BadRequestError` names a fault in the request the PEER
|
|
11
|
+
* received — which this caller built. so it is this caller's malfunction, never a fault
|
|
12
|
+
* its own caller can fix. thrown as the caller's own `ConstraintError`, it became a 400 to
|
|
13
|
+
* an http caller and hid from every alarm (sdk-aws-lambda#77)
|
|
14
|
+
*
|
|
15
|
+
* .note = a `MalfunctionError`, so every consumer family treats it as a server fault: an
|
|
16
|
+
* api-gateway consumer answers 500, a direct-invoke consumer fails its invocation, and an
|
|
17
|
+
* sqs consumer redrives the message. `getIsConstraintError` reads it false
|
|
18
|
+
* .note = metadata is the road's own: the invoke road names the `endpoint`; the http road names
|
|
19
|
+
* the `url` and `status`. both carry `exid` and the peer's verdict as `errorType`
|
|
20
|
+
* .note = a consumer whose call forwards its own caller's input verbatim opts into the old class
|
|
21
|
+
* per call, via `refusal: { as: 'ConstraintError' }`
|
|
22
|
+
*/
|
|
23
|
+
export declare class LambdaEndpointRefusedError extends MalfunctionError {
|
|
24
|
+
constructor(message: string, metadata: LambdaEndpointRefusedErrorMetadata);
|
|
25
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LambdaEndpointRefusedError = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
/**
|
|
6
|
+
* .what = a peer endpoint refused a request this caller composed
|
|
7
|
+
* .why = a peer's `ConstraintError` / `BadRequestError` names a fault in the request the PEER
|
|
8
|
+
* received — which this caller built. so it is this caller's malfunction, never a fault
|
|
9
|
+
* its own caller can fix. thrown as the caller's own `ConstraintError`, it became a 400 to
|
|
10
|
+
* an http caller and hid from every alarm (sdk-aws-lambda#77)
|
|
11
|
+
*
|
|
12
|
+
* .note = a `MalfunctionError`, so every consumer family treats it as a server fault: an
|
|
13
|
+
* api-gateway consumer answers 500, a direct-invoke consumer fails its invocation, and an
|
|
14
|
+
* sqs consumer redrives the message. `getIsConstraintError` reads it false
|
|
15
|
+
* .note = metadata is the road's own: the invoke road names the `endpoint`; the http road names
|
|
16
|
+
* the `url` and `status`. both carry `exid` and the peer's verdict as `errorType`
|
|
17
|
+
* .note = a consumer whose call forwards its own caller's input verbatim opts into the old class
|
|
18
|
+
* per call, via `refusal: { as: 'ConstraintError' }`
|
|
19
|
+
*/
|
|
20
|
+
class LambdaEndpointRefusedError extends helpful_errors_1.MalfunctionError {
|
|
21
|
+
constructor(message, metadata) {
|
|
22
|
+
super(message, metadata);
|
|
23
|
+
// name the class, as aws labels an escaped throw by `.name`; helpful-errors sets no name
|
|
24
|
+
this.name = 'LambdaEndpointRefusedError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.LambdaEndpointRefusedError = LambdaEndpointRefusedError;
|
|
28
|
+
//# sourceMappingURL=LambdaEndpointRefusedError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LambdaEndpointRefusedError.js","sourceRoot":"","sources":["../../src/domain.objects/LambdaEndpointRefusedError.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAWlD;;;;;;;;;;;;;;GAcG;AACH,MAAa,0BAA2B,SAAQ,iCAAgB;IAC9D,YAAY,OAAe,EAAE,QAA4C;QACvE,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAEzB,yFAAyF;QACzF,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAPD,gEAOC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = the event sources an `asLambdaEventSchema.*` builder can declare, in one list
|
|
3
|
+
* .why = the builders stamp a name from it, the reader accepts only a name in it, and `forAsk`
|
|
4
|
+
* keys its per-source table by it — so a new source is one entry here, and every
|
|
5
|
+
* `Record<LambdaEventSchemaSourceName, …>` that lacks it fails to compile
|
|
6
|
+
*/
|
|
7
|
+
export declare const LAMBDA_EVENT_SCHEMA_SOURCE_NAMES: readonly ["sns", "kinesis"];
|
|
8
|
+
/**
|
|
9
|
+
* .what = the name of an event source an `asLambdaEventSchema.*` schema validates
|
|
10
|
+
*/
|
|
11
|
+
export type LambdaEventSchemaSourceName = (typeof LAMBDA_EVENT_SCHEMA_SOURCE_NAMES)[number];
|
|
12
|
+
/**
|
|
13
|
+
* .what = what a schema built by `asLambdaEventSchema.*` declares about itself
|
|
14
|
+
* .why = a refusal by an event-source schema owes a warn line (aws drops the event, so the log
|
|
15
|
+
* is its only trace), while every other `forAsk` caller keeps its debug-only log. this
|
|
16
|
+
* record is how `forAsk` tells the two apart
|
|
17
|
+
*
|
|
18
|
+
* .note = data only, never code: the mark may cross from another copy of this package
|
|
19
|
+
* (`Symbol.for`), and a name is checkable where a function is not. what `forAsk` does
|
|
20
|
+
* with a name (which ids to read, what became of the event) is `forAsk`'s own table
|
|
21
|
+
* .note = it lives here because two peers name it — the builders that stamp it and the
|
|
22
|
+
* endpoint that reads it (rule.prefer.most-common-denominator)
|
|
23
|
+
*/
|
|
24
|
+
export interface LambdaEventSchemaSource {
|
|
25
|
+
name: LambdaEventSchemaSourceName;
|
|
26
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LAMBDA_EVENT_SCHEMA_SOURCE_NAMES = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = the event sources an `asLambdaEventSchema.*` builder can declare, in one list
|
|
6
|
+
* .why = the builders stamp a name from it, the reader accepts only a name in it, and `forAsk`
|
|
7
|
+
* keys its per-source table by it — so a new source is one entry here, and every
|
|
8
|
+
* `Record<LambdaEventSchemaSourceName, …>` that lacks it fails to compile
|
|
9
|
+
*/
|
|
10
|
+
exports.LAMBDA_EVENT_SCHEMA_SOURCE_NAMES = ['sns', 'kinesis'];
|
|
11
|
+
//# sourceMappingURL=LambdaEventSchemaSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LambdaEventSchemaSource.js","sourceRoot":"","sources":["../../src/domain.objects/LambdaEventSchemaSource.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACU,QAAA,gCAAgC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAU,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { KinesisStreamEvent, KinesisStreamRecord, KinesisStreamRecordPayload } from 'aws-lambda';
|
|
2
|
+
/**
|
|
3
|
+
* .what = a kinesis event whose `Records[].kinesis.data` holds the decoded, validated payload
|
|
4
|
+
* .why = the handler face of `asLambdaEventSchema.fromKinesis({ payload })`. a consumer whose
|
|
5
|
+
* `invoke` is declared apart from the call site must be able to name it
|
|
6
|
+
*/
|
|
7
|
+
export type KinesisStreamEventDecoded<TPayload> = Omit<KinesisStreamEvent, 'Records'> & {
|
|
8
|
+
Records: Array<Omit<KinesisStreamRecord, 'kinesis'> & {
|
|
9
|
+
kinesis: Omit<KinesisStreamRecordPayload, 'data'> & {
|
|
10
|
+
data: TPayload;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KinesisStreamEventDecoded.js","sourceRoot":"","sources":["../../../src/domain.operations/asLambdaEventSchema/KinesisStreamEventDecoded.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SNSEvent, SNSEventRecord, SNSMessage } from 'aws-lambda';
|
|
2
|
+
/**
|
|
3
|
+
* .what = an sns event whose `Records[].Sns.Message` holds the decoded, validated payload
|
|
4
|
+
* .why = the handler face of `asLambdaEventSchema.fromSns({ payload })`. a consumer whose
|
|
5
|
+
* `invoke` is declared apart from the call site must be able to name it
|
|
6
|
+
*
|
|
7
|
+
* .note = `Subject` is `string | null | undefined`: sns sends `null` for a message published with
|
|
8
|
+
* no subject, and the schema accepts it, where `@types/aws-lambda` declares only
|
|
9
|
+
* `string | undefined`. this face is ours, so it states the runtime; a handler that tests
|
|
10
|
+
* `Subject === undefined` alone would miss the null
|
|
11
|
+
*/
|
|
12
|
+
export type SnsEventDecoded<TPayload> = Omit<SNSEvent, 'Records'> & {
|
|
13
|
+
Records: Array<Omit<SNSEventRecord, 'Sns'> & {
|
|
14
|
+
Sns: Omit<SNSMessage, 'Message' | 'Subject'> & {
|
|
15
|
+
Message: TPayload;
|
|
16
|
+
Subject?: string | null;
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnsEventDecoded.js","sourceRoot":"","sources":["../../../src/domain.operations/asLambdaEventSchema/SnsEventDecoded.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ZodType } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* .what = what `deserialize` means when a caller declares none
|
|
4
|
+
* .why payload = json is the common case; a text stream opts out by value,
|
|
5
|
+
* `deserialize: { payload: false }` — the same key and default `forSqs` ships
|
|
6
|
+
*
|
|
7
|
+
* .why a third declaration, where `forSqs` and `forApiGateway` each hold one = to import a
|
|
8
|
+
* peer family's default would bind this family to it. the three coincide, yet each is
|
|
9
|
+
* free to diverge (`rule.prefer.wet-over-dry`)
|
|
10
|
+
* .note = frozen, since every build shares this one reference
|
|
11
|
+
*/
|
|
12
|
+
export declare const DESERIALIZE_DEFAULT: Readonly<{
|
|
13
|
+
payload: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* .what = the schema of one message slot: the wire string, decoded, then met by `payload`
|
|
17
|
+
* .why = sns and kinesis differ only in how the wire string decodes to text (as-is vs base64),
|
|
18
|
+
* never in what happens after — so one transformer serves both
|
|
19
|
+
* (`rule.forbid.parallel-codepaths`)
|
|
20
|
+
*
|
|
21
|
+
* .note = the wire face (zod input) stays `string`, so introspection publishes the honest wire
|
|
22
|
+
* shape and `forAsk`'s handler accepts the aws-lambda type with no cast
|
|
23
|
+
*/
|
|
24
|
+
export declare const asLambdaEventPayloadSchema: (input: {
|
|
25
|
+
/**
|
|
26
|
+
* .note = input face `any`: zod's `.pipe()` demands the target accept the piped value, and the
|
|
27
|
+
* piped value is `string` (text) or `unknown` (parsed json), which no single declared
|
|
28
|
+
* input type covers. the payload schema itself judges the value at run time
|
|
29
|
+
*/
|
|
30
|
+
payload: ZodType<unknown, any>;
|
|
31
|
+
deserialize: {
|
|
32
|
+
payload: boolean;
|
|
33
|
+
};
|
|
34
|
+
decode: (input: {
|
|
35
|
+
wire: string;
|
|
36
|
+
}) => string;
|
|
37
|
+
}) => ZodType<unknown, string>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asLambdaEventPayloadSchema = exports.DESERIALIZE_DEFAULT = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const getParsedJson_1 = require("../lambdaEndpointWire/serde/getParsedJson");
|
|
6
|
+
/**
|
|
7
|
+
* .what = what `deserialize` means when a caller declares none
|
|
8
|
+
* .why payload = json is the common case; a text stream opts out by value,
|
|
9
|
+
* `deserialize: { payload: false }` — the same key and default `forSqs` ships
|
|
10
|
+
*
|
|
11
|
+
* .why a third declaration, where `forSqs` and `forApiGateway` each hold one = to import a
|
|
12
|
+
* peer family's default would bind this family to it. the three coincide, yet each is
|
|
13
|
+
* free to diverge (`rule.prefer.wet-over-dry`)
|
|
14
|
+
* .note = frozen, since every build shares this one reference
|
|
15
|
+
*/
|
|
16
|
+
exports.DESERIALIZE_DEFAULT = Object.freeze({ payload: true });
|
|
17
|
+
/**
|
|
18
|
+
* .what = the issue a message meets when the json step refuses it
|
|
19
|
+
* .why = the common cause is a text stream wired with the json default, so the issue names
|
|
20
|
+
* that fix (`rule.require.errors-name-the-fix`)
|
|
21
|
+
*/
|
|
22
|
+
const ISSUE_NOT_JSON = 'expected a json message; fix: for a text message (not json), set `deserialize: { payload: false }`';
|
|
23
|
+
/**
|
|
24
|
+
* .what = parses a json string, or records a custom issue at the field
|
|
25
|
+
* .why = a non-json message must be a refusal with a path, never a `JSON.parse` throw
|
|
26
|
+
* .note = the parse itself is `getParsedJson`, which allowlists `SyntaxError` and rethrows
|
|
27
|
+
* every other class
|
|
28
|
+
*/
|
|
29
|
+
const asJsonParsed = (input) => {
|
|
30
|
+
const parsed = (0, getParsedJson_1.getParsedJson)({ json: input.value });
|
|
31
|
+
if (parsed.success)
|
|
32
|
+
return parsed.data;
|
|
33
|
+
input.ctx.addIssue({ code: 'custom', message: ISSUE_NOT_JSON });
|
|
34
|
+
return zod_1.z.NEVER;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* .what = the schema of one message slot: the wire string, decoded, then met by `payload`
|
|
38
|
+
* .why = sns and kinesis differ only in how the wire string decodes to text (as-is vs base64),
|
|
39
|
+
* never in what happens after — so one transformer serves both
|
|
40
|
+
* (`rule.forbid.parallel-codepaths`)
|
|
41
|
+
*
|
|
42
|
+
* .note = the wire face (zod input) stays `string`, so introspection publishes the honest wire
|
|
43
|
+
* shape and `forAsk`'s handler accepts the aws-lambda type with no cast
|
|
44
|
+
*/
|
|
45
|
+
const asLambdaEventPayloadSchema = (input) => {
|
|
46
|
+
// decode the wire string to text, as the source delivers it
|
|
47
|
+
const text = zod_1.z.string().transform((wire) => input.decode({ wire }));
|
|
48
|
+
// a text payload meets the text as-is
|
|
49
|
+
if (!input.deserialize.payload)
|
|
50
|
+
return text.pipe(input.payload);
|
|
51
|
+
// a json payload meets the parsed text
|
|
52
|
+
return text
|
|
53
|
+
.transform((value, ctx) => asJsonParsed({ value, ctx }))
|
|
54
|
+
.pipe(input.payload);
|
|
55
|
+
};
|
|
56
|
+
exports.asLambdaEventPayloadSchema = asLambdaEventPayloadSchema;
|
|
57
|
+
//# sourceMappingURL=asLambdaEventPayloadSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asLambdaEventPayloadSchema.js","sourceRoot":"","sources":["../../../src/domain.operations/asLambdaEventSchema/asLambdaEventPayloadSchema.ts"],"names":[],"mappings":";;;AAAA,6BAAsC;AAEtC,6EAA0E;AAE1E;;;;;;;;;GASG;AACU,QAAA,mBAAmB,GAC9B,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAEnC;;;;GAIG;AACH,MAAM,cAAc,GAClB,oGAAoG,CAAC;AAEvG;;;;;GAKG;AACH,MAAM,YAAY,GAAG,CAAC,KAGrB,EAAW,EAAE;IACZ,MAAM,MAAM,GAAG,IAAA,6BAAa,EAAC,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACpD,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC;IACvC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;IAChE,OAAO,OAAC,CAAC,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,0BAA0B,GAAG,CAAC,KAS1C,EAA4B,EAAE;IAC7B,4DAA4D;IAC5D,MAAM,IAAI,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAEpE,sCAAsC;IACtC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAEhE,uCAAuC;IACvC,OAAO,IAAI;SACR,SAAS,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;SACvD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC,CAAC;AApBW,QAAA,0BAA0B,8BAoBrC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = the zod schema of the event an event source delivers, optionally with the schema of
|
|
3
|
+
* the payload inside it
|
|
4
|
+
* .why = the validate direction of the event-source axis. `asLambdaEvent.from$Source` builds an
|
|
5
|
+
* envelope; `asLambdaEventSchema.from$Source` validates one (`define.lambda-event-source`).
|
|
6
|
+
* it covers the sources whose payload no endpoint family already validates, so its list
|
|
7
|
+
* is a subset of `asLambdaEvent`'s, each absence on a stated axis below
|
|
8
|
+
*
|
|
9
|
+
* | source | the payload slot | decode before `payload` |
|
|
10
|
+
* |--------|------------------|-------------------------|
|
|
11
|
+
* | **sns** | `Records[].Sns.Message` | json parse (or none, under `deserialize: { payload: false }`) |
|
|
12
|
+
* | **kinesis** | `Records[].kinesis.data` | base64 → utf8, then json parse (or none) |
|
|
13
|
+
*
|
|
14
|
+
* ⚠️ **there is no `fromSqs`, deliberately.** `genLambdaEndpoint.forSqs.{perRecord,perBatch}`
|
|
15
|
+
* already validates each record's body against `schema.input.payload`, and answers per
|
|
16
|
+
* message: a refused message is acknowledged alone, never with its batch. use it for sqs
|
|
17
|
+
*
|
|
18
|
+
* ⚠️ **there is no `fromApiGateway`, on the same axis.** `genLambdaEndpoint.forApiGateway`
|
|
19
|
+
* validates the request through its own `schema.input` pair (`headers`, `payload`)
|
|
20
|
+
*
|
|
21
|
+
* ⚠️ **there is no `fromS3`, for want of a payload.** an s3 notice carries a reference (bucket,
|
|
22
|
+
* key), never content, so it has no payload slot to decode, and no evidenced consumer yet
|
|
23
|
+
*
|
|
24
|
+
* ⚠️ **one zod in the tree.** the envelope is built with this sdk's zod and pipes into your
|
|
25
|
+
* `payload` schema. a schema from another zod copy or major is a compile-time type error, as
|
|
26
|
+
* at `forAsk`'s `schema.input`; the cure is `pnpm.overrides.zod` to one version
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* genLambdaEndpoint.forAsk({
|
|
31
|
+
* schema: { input: asLambdaEventSchema.fromSns({ payload: schemaOfNotice }), output: z.void() },
|
|
32
|
+
* invoke: async ({ payload }) => handle(payload.Records[0]!.Sns.Message),
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const asLambdaEventSchema: {
|
|
37
|
+
fromKinesis: import("./asLambdaEventSchema.fromKinesis").FromKinesis;
|
|
38
|
+
fromSns: import("./asLambdaEventSchema.fromSns").FromSns;
|
|
39
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { KinesisStreamEvent } from 'aws-lambda';
|
|
2
|
+
import { type ZodType } from 'zod';
|
|
3
|
+
import type { KinesisStreamEventDecoded } from './KinesisStreamEventDecoded';
|
|
4
|
+
/**
|
|
5
|
+
* .what = the two call forms of `fromKinesis`, one per handler face
|
|
6
|
+
* .why = with no `payload`, the handler face IS the wire face (`KinesisStreamEvent`), and
|
|
7
|
+
* `data` stays the base64 string aws sent; with one, `data` holds the decoded payload
|
|
8
|
+
*/
|
|
9
|
+
export type FromKinesis = {
|
|
10
|
+
(): ZodType<KinesisStreamEvent, KinesisStreamEvent>;
|
|
11
|
+
<TPayload>(input: {
|
|
12
|
+
/**
|
|
13
|
+
* .what = the schema of `Records[].kinesis.data`, after base64 decode (and json parse)
|
|
14
|
+
*/
|
|
15
|
+
payload: ZodType<TPayload>;
|
|
16
|
+
/**
|
|
17
|
+
* .what = whether the decoded text is parsed as json before `payload` meets it
|
|
18
|
+
* .default = `{ payload: true }`; a text stream sets `{ payload: false }`
|
|
19
|
+
*/
|
|
20
|
+
deserialize?: {
|
|
21
|
+
payload: boolean;
|
|
22
|
+
};
|
|
23
|
+
}): ZodType<KinesisStreamEventDecoded<TPayload>, KinesisStreamEvent>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* .what = the zod schema of the event kinesis delivers to a lambda, optionally with the schema
|
|
27
|
+
* of each record's data
|
|
28
|
+
* .why = a kinesis handler wired via `genLambdaEndpoint.forAsk` gets a validated envelope and
|
|
29
|
+
* decoded, typed data, where it used to get a `Records`-array guard and a hand
|
|
30
|
+
* `Buffer.from(data, 'base64')`
|
|
31
|
+
*
|
|
32
|
+
* ⚠️ .note = one refused record refuses the WHOLE batch. under `forAsk` a refusal is a caller
|
|
33
|
+
* fault, so the invoke succeeds and kinesis advances past every record in the batch,
|
|
34
|
+
* good ones included (outside a tumble window, where a success with no `state` suspends
|
|
35
|
+
* the shard instead). for a stream of mixed quality, use the envelope-only form
|
|
36
|
+
* (`fromKinesis()`) and judge each record in the handler. `forAsk` logs a warn line
|
|
37
|
+
* with the refused batch's `eventID`s (the first 100, the count, and the last), so the
|
|
38
|
+
* range can be replayed
|
|
39
|
+
* .note = binary data (a KPL aggregate, cloudwatch-logs gzip) does not fit `payload`: the utf8
|
|
40
|
+
* decode never fails, so the bytes arrive as a mangled string. use the envelope-only
|
|
41
|
+
* form for a binary stream, and constrain a text schema's form (e.g. a regex)
|
|
42
|
+
* .note = two call forms, two contracts, by design: `fromKinesis()` makes no claim about the
|
|
43
|
+
* data, so it stays the base64 aws sent; `fromKinesis({ payload })` claims a shape, so
|
|
44
|
+
* the data is decoded and validated. an absent `input` is the envelope-only contract,
|
|
45
|
+
* not a skipped default — each form carries its own return type and its own tests
|
|
46
|
+
*
|
|
47
|
+
* .as = zod infers `looseObject` types with an index signature on input and output, which no
|
|
48
|
+
* aws-lambda interface carries, so neither face is assignable to `KinesisStreamEvent`
|
|
49
|
+
* structurally. the cast asserts the runtime shape the schema enforces
|
|
50
|
+
* .removal = drops when zod can infer a loose object without an index signature
|
|
51
|
+
* .note = the cast does not cut the tie to the aws type: the envelope-only schema `satisfies`
|
|
52
|
+
* `ZodType<KinesisStreamEvent, unknown>`, so a required key `@types/aws-lambda` adds, or
|
|
53
|
+
* one the schema drops, fails to compile
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* schema: { input: asLambdaEventSchema.fromKinesis({ payload: schemaOfClick }), output: z.void() },
|
|
58
|
+
* invoke: async ({ payload }) => handle(payload.Records.map((record) => record.kinesis.data)),
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const fromKinesis: FromKinesis;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromKinesis = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const setLambdaEventSchemaSource_1 = require("../lambdaEndpointWire/frame/setLambdaEventSchemaSource");
|
|
6
|
+
const asLambdaEventPayloadSchema_1 = require("./asLambdaEventPayloadSchema");
|
|
7
|
+
/**
|
|
8
|
+
* .what = decodes kinesis `data` from base64 to utf8 text
|
|
9
|
+
* .why = kinesis always delivers `data` base64-encoded; `payload` describes the text inside
|
|
10
|
+
* .note = node's base64 decode never throws; bad base64 yields text the next step refuses
|
|
11
|
+
*/
|
|
12
|
+
const asKinesisDataText = (input) => Buffer.from(input.wire, 'base64').toString('utf8');
|
|
13
|
+
/**
|
|
14
|
+
* .what = the schema of the kinesis envelope, with the data slot supplied
|
|
15
|
+
* .why = one envelope serves both call forms; only the data slot differs (the base64 string
|
|
16
|
+
* alone, or the decoded payload)
|
|
17
|
+
* .note = loose objects: a key aws adds later is kept, never stripped or refused (F4)
|
|
18
|
+
* ⚠️ .note = `Records` may be empty, unlike sns: aws's own kinesis sample handlers guard an empty
|
|
19
|
+
* batch, and a tumble window's final invoke may carry none. a refusal there would answer
|
|
20
|
+
* with no `state` and suspend the shard, so the schema accepts it. read
|
|
21
|
+
* `Records[0]` only after a length check
|
|
22
|
+
*/
|
|
23
|
+
const genSchemaOfKinesisEvent = (input) => zod_1.z.looseObject({
|
|
24
|
+
Records: zod_1.z.array(zod_1.z.looseObject({
|
|
25
|
+
kinesis: zod_1.z.looseObject({
|
|
26
|
+
kinesisSchemaVersion: zod_1.z.string(),
|
|
27
|
+
partitionKey: zod_1.z.string(),
|
|
28
|
+
sequenceNumber: zod_1.z.string(),
|
|
29
|
+
data: input.data,
|
|
30
|
+
approximateArrivalTimestamp: zod_1.z.number(),
|
|
31
|
+
}),
|
|
32
|
+
eventSource: zod_1.z.literal('aws:kinesis'),
|
|
33
|
+
eventVersion: zod_1.z.string(),
|
|
34
|
+
eventID: zod_1.z.string(),
|
|
35
|
+
eventName: zod_1.z.string(),
|
|
36
|
+
invokeIdentityArn: zod_1.z.string(),
|
|
37
|
+
awsRegion: zod_1.z.string(),
|
|
38
|
+
eventSourceARN: zod_1.z.string(),
|
|
39
|
+
})),
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* .what = the zod schema of the event kinesis delivers to a lambda, optionally with the schema
|
|
43
|
+
* of each record's data
|
|
44
|
+
* .why = a kinesis handler wired via `genLambdaEndpoint.forAsk` gets a validated envelope and
|
|
45
|
+
* decoded, typed data, where it used to get a `Records`-array guard and a hand
|
|
46
|
+
* `Buffer.from(data, 'base64')`
|
|
47
|
+
*
|
|
48
|
+
* ⚠️ .note = one refused record refuses the WHOLE batch. under `forAsk` a refusal is a caller
|
|
49
|
+
* fault, so the invoke succeeds and kinesis advances past every record in the batch,
|
|
50
|
+
* good ones included (outside a tumble window, where a success with no `state` suspends
|
|
51
|
+
* the shard instead). for a stream of mixed quality, use the envelope-only form
|
|
52
|
+
* (`fromKinesis()`) and judge each record in the handler. `forAsk` logs a warn line
|
|
53
|
+
* with the refused batch's `eventID`s (the first 100, the count, and the last), so the
|
|
54
|
+
* range can be replayed
|
|
55
|
+
* .note = binary data (a KPL aggregate, cloudwatch-logs gzip) does not fit `payload`: the utf8
|
|
56
|
+
* decode never fails, so the bytes arrive as a mangled string. use the envelope-only
|
|
57
|
+
* form for a binary stream, and constrain a text schema's form (e.g. a regex)
|
|
58
|
+
* .note = two call forms, two contracts, by design: `fromKinesis()` makes no claim about the
|
|
59
|
+
* data, so it stays the base64 aws sent; `fromKinesis({ payload })` claims a shape, so
|
|
60
|
+
* the data is decoded and validated. an absent `input` is the envelope-only contract,
|
|
61
|
+
* not a skipped default — each form carries its own return type and its own tests
|
|
62
|
+
*
|
|
63
|
+
* .as = zod infers `looseObject` types with an index signature on input and output, which no
|
|
64
|
+
* aws-lambda interface carries, so neither face is assignable to `KinesisStreamEvent`
|
|
65
|
+
* structurally. the cast asserts the runtime shape the schema enforces
|
|
66
|
+
* .removal = drops when zod can infer a loose object without an index signature
|
|
67
|
+
* .note = the cast does not cut the tie to the aws type: the envelope-only schema `satisfies`
|
|
68
|
+
* `ZodType<KinesisStreamEvent, unknown>`, so a required key `@types/aws-lambda` adds, or
|
|
69
|
+
* one the schema drops, fails to compile
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* schema: { input: asLambdaEventSchema.fromKinesis({ payload: schemaOfClick }), output: z.void() },
|
|
74
|
+
* invoke: async ({ payload }) => handle(payload.Records.map((record) => record.kinesis.data)),
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
exports.fromKinesis = ((input) => {
|
|
78
|
+
const schema = input
|
|
79
|
+
? genSchemaOfKinesisEvent({
|
|
80
|
+
data: (0, asLambdaEventPayloadSchema_1.asLambdaEventPayloadSchema)({
|
|
81
|
+
payload: input.payload,
|
|
82
|
+
deserialize: input.deserialize ?? asLambdaEventPayloadSchema_1.DESERIALIZE_DEFAULT,
|
|
83
|
+
decode: asKinesisDataText,
|
|
84
|
+
}),
|
|
85
|
+
})
|
|
86
|
+
: (genSchemaOfKinesisEvent({ data: zod_1.z.string() }));
|
|
87
|
+
return (0, setLambdaEventSchemaSource_1.setLambdaEventSchemaSource)({ schema, source: { name: 'kinesis' } });
|
|
88
|
+
});
|
|
89
|
+
//# sourceMappingURL=asLambdaEventSchema.fromKinesis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asLambdaEventSchema.fromKinesis.js","sourceRoot":"","sources":["../../../src/domain.operations/asLambdaEventSchema/asLambdaEventSchema.fromKinesis.ts"],"names":[],"mappings":";;;AACA,6BAAsC;AAEtC,uGAAoG;AACpG,6EAGsC;AAwBtC;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAuB,EAAU,EAAE,CAC5D,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAErD;;;;;;;;;GASG;AACH,MAAM,uBAAuB,GAAG,CAAW,KAE1C,EAAE,EAAE,CACH,OAAC,CAAC,WAAW,CAAC;IACZ,OAAO,EAAE,OAAC,CAAC,KAAK,CACd,OAAC,CAAC,WAAW,CAAC;QACZ,OAAO,EAAE,OAAC,CAAC,WAAW,CAAC;YACrB,oBAAoB,EAAE,OAAC,CAAC,MAAM,EAAE;YAChC,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE;YACxB,cAAc,EAAE,OAAC,CAAC,MAAM,EAAE;YAC1B,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,2BAA2B,EAAE,OAAC,CAAC,MAAM,EAAE;SACxC,CAAC;QACF,WAAW,EAAE,OAAC,CAAC,OAAO,CAAC,aAAa,CAAC;QACrC,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE;QACxB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;QACnB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;QACrB,iBAAiB,EAAE,OAAC,CAAC,MAAM,EAAE;QAC7B,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;QACrB,cAAc,EAAE,OAAC,CAAC,MAAM,EAAE;KAC3B,CAAC,CACH;CACF,CAAC,CAAC;AAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACU,QAAA,WAAW,GAAG,CAAC,CAAC,KAG5B,EAAW,EAAE;IACZ,MAAM,MAAM,GAAG,KAAK;QAClB,CAAC,CAAC,uBAAuB,CAAC;YACtB,IAAI,EAAE,IAAA,uDAA0B,EAAC;gBAC/B,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,gDAAmB;gBACrD,MAAM,EAAE,iBAAiB;aAC1B,CAAC;SACH,CAAC;QACJ,CAAC,CAAC,CAAC,uBAAuB,CAAC,EAAE,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,CAG5C,CAAC,CAAC;IACP,OAAO,IAAA,uDAA0B,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;AAC7E,CAAC,CAAgB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { SNSEvent } from 'aws-lambda';
|
|
2
|
+
import { type ZodType } from 'zod';
|
|
3
|
+
import type { SnsEventDecoded } from './SnsEventDecoded';
|
|
4
|
+
/**
|
|
5
|
+
* .what = the two call forms of `fromSns`, one per handler face
|
|
6
|
+
* .why = with no `payload`, the handler face IS the wire face (`SNSEvent`); with one, the
|
|
7
|
+
* message slot holds the decoded payload. a caller reads the face it asked for
|
|
8
|
+
* ⚠️ .note = the envelope-only face is typed `SNSEvent`, yet the schema passes three keys as aws
|
|
9
|
+
* sends them (`SnsEventKeysContested` below): `Subject` may be `null`, and
|
|
10
|
+
* `SigningCertUrl` / `UnsubscribeUrl` may be absent. test `Subject` with `== null`, never
|
|
11
|
+
* `=== undefined`, and do not read either url key unchecked
|
|
12
|
+
*/
|
|
13
|
+
export type FromSns = {
|
|
14
|
+
(): ZodType<SNSEvent, SNSEvent>;
|
|
15
|
+
<TPayload>(input: {
|
|
16
|
+
/**
|
|
17
|
+
* .what = the schema of `Records[].Sns.Message`, after it is decoded
|
|
18
|
+
*/
|
|
19
|
+
payload: ZodType<TPayload>;
|
|
20
|
+
/**
|
|
21
|
+
* .what = whether `Message` is parsed as json before `payload` meets it
|
|
22
|
+
* .default = `{ payload: true }`; a text message sets `{ payload: false }`
|
|
23
|
+
*/
|
|
24
|
+
deserialize?: {
|
|
25
|
+
payload: boolean;
|
|
26
|
+
};
|
|
27
|
+
}): ZodType<SnsEventDecoded<TPayload>, SNSEvent>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* .what = the zod schema of the event sns delivers to a lambda, optionally with the schema of
|
|
31
|
+
* the message inside it
|
|
32
|
+
* .why = an sns handler wired via `genLambdaEndpoint.forAsk` gets a validated envelope and a
|
|
33
|
+
* typed message, where it used to get `z.custom<SNSEvent>` and a hand `JSON.parse`
|
|
34
|
+
*
|
|
35
|
+
* .note = the wire face (zod input) is `SNSEvent`, so `forAsk` returns a handler typed on it
|
|
36
|
+
* .note = two call forms, two contracts, by design: `fromSns()` makes no claim about the
|
|
37
|
+
* message, so it stays the wire string; `fromSns({ payload })` claims a shape, so the
|
|
38
|
+
* message is decoded and validated. an absent `input` is the envelope-only contract, not
|
|
39
|
+
* a skipped default — each form carries its own return type and its own tests
|
|
40
|
+
* .note = a refusal is answered as a caller fault, so the invoke succeeds and lambda does not
|
|
41
|
+
* retry. `forAsk` logs a warn line with the message id, since the log is the only trace
|
|
42
|
+
*
|
|
43
|
+
* .as = zod infers `looseObject` types with an index signature on input and output, which no
|
|
44
|
+
* aws-lambda interface carries, so neither face is assignable to `SNSEvent` structurally.
|
|
45
|
+
* the cast asserts the runtime shape the schema enforces, which `@types/aws-lambda` names
|
|
46
|
+
* .removal = drops when zod can infer a loose object without an index signature
|
|
47
|
+
* .note = the cast does not cut the tie to the aws type: the envelope-only schema `satisfies`
|
|
48
|
+
* `ZodType<SnsEventKeysContested, unknown>`, so a required key `@types/aws-lambda` adds,
|
|
49
|
+
* or one the schema drops, fails to compile. the three contested keys (named on
|
|
50
|
+
* `SnsEventKeysContested`) are the one stated gap between the declared type and the runtime
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* schema: { input: asLambdaEventSchema.fromSns({ payload: schemaOfNotice }), output: z.void() },
|
|
55
|
+
* invoke: async ({ payload }) => handle(payload.Records[0]!.Sns.Message), // typed, validated
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const fromSns: FromSns;
|