sdk-aws-lambda 0.7.2 → 0.7.3
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.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.d.ts +14 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.js +20 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.d.ts +9 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.js +13 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.d.ts +10 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.js +11 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.d.ts +9 -3
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.js +35 -37
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.d.ts +12 -6
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js +54 -34
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.d.ts +11 -7
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.js +11 -7
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.d.ts +19 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.js +22 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.d.ts +11 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.js +13 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.d.ts +11 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.js +18 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.d.ts +8 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.js +14 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.d.ts +15 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.js +22 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.d.ts +27 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.js +33 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.js.map +1 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.d.ts +6 -5
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.js +6 -5
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.js.map +1 -1
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.d.ts +31 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.js +46 -0
- package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.js.map +1 -0
- package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.d.ts +6 -1
- package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.js +6 -1
- package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.js.map +1 -1
- package/dist/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.d.ts +41 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.js +116 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.js.map +1 -0
- package/dist/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.js +52 -17
- package/dist/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.js.map +1 -1
- package/package.json +6 -6
- package/readme.md +23 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAllSqsIdsUnclaimable.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,uBAAuB,GAAG,CAAC,KAGvC,EAAY,EAAE,CACb,KAAK,CAAC,SAAS;KACZ,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;KAC5B,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AANpC,QAAA,uBAAuB,2BAMa"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = the entries of a perBatch answer that carry no string `id`, each with its position
|
|
3
|
+
* .why = sqs can delete only by id, so an entry without one is no success at all. the position
|
|
4
|
+
* lets the refusal name exactly which entries the handler got wrong
|
|
5
|
+
*/
|
|
6
|
+
export declare const getAllSqsSuccessRefsMalformed: (input: {
|
|
7
|
+
successes: ReadonlyArray<unknown>;
|
|
8
|
+
}) => {
|
|
9
|
+
index: number;
|
|
10
|
+
got: string;
|
|
11
|
+
}[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllSqsSuccessRefsMalformed = void 0;
|
|
4
|
+
const isSqsSuccessRef_1 = require("./isSqsSuccessRef");
|
|
5
|
+
/**
|
|
6
|
+
* .what = the entries of a perBatch answer that carry no string `id`, each with its position
|
|
7
|
+
* .why = sqs can delete only by id, so an entry without one is no success at all. the position
|
|
8
|
+
* lets the refusal name exactly which entries the handler got wrong
|
|
9
|
+
*/
|
|
10
|
+
const getAllSqsSuccessRefsMalformed = (input) => input.successes
|
|
11
|
+
.map((success, index) => ({ index, success }))
|
|
12
|
+
.filter(({ success }) => !(0, isSqsSuccessRef_1.isSqsSuccessRef)(success))
|
|
13
|
+
.map(({ index, success }) => ({
|
|
14
|
+
index,
|
|
15
|
+
got: success === null ? 'null' : typeof success,
|
|
16
|
+
}));
|
|
17
|
+
exports.getAllSqsSuccessRefsMalformed = getAllSqsSuccessRefsMalformed;
|
|
18
|
+
//# sourceMappingURL=getAllSqsSuccessRefsMalformed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAllSqsSuccessRefsMalformed.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AAEpD;;;;GAIG;AACI,MAAM,6BAA6B,GAAG,CAAC,KAE7C,EAAoC,EAAE,CACrC,KAAK,CAAC,SAAS;KACZ,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;KAC7C,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,IAAA,iCAAe,EAAC,OAAO,CAAC,CAAC;KAClD,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5B,KAAK;IACL,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,OAAO;CAChD,CAAC,CAAC,CAAC;AATK,QAAA,6BAA6B,iCASlC"}
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = whether a value is one sqs can delete by: an object with a string `id`
|
|
3
|
+
* .why = a perBatch answer is read at runtime, so a js caller or an `any` site can hand over a
|
|
4
|
+
* bare id string, a `null`, or an object with no `id` — none of which names a message
|
|
5
|
+
*/
|
|
6
|
+
export declare const isSqsSuccessRef: (value: unknown) => value is {
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSqsSuccessRef = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = whether a value is one sqs can delete by: an object with a string `id`
|
|
6
|
+
* .why = a perBatch answer is read at runtime, so a js caller or an `any` site can hand over a
|
|
7
|
+
* bare id string, a `null`, or an object with no `id` — none of which names a message
|
|
8
|
+
*/
|
|
9
|
+
const isSqsSuccessRef = (value) => typeof value === 'object' &&
|
|
10
|
+
value !== null &&
|
|
11
|
+
'id' in value &&
|
|
12
|
+
typeof value.id === 'string';
|
|
13
|
+
exports.isSqsSuccessRef = isSqsSuccessRef;
|
|
14
|
+
//# sourceMappingURL=isSqsSuccessRef.js.map
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isSqsSuccessRef.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACI,MAAM,eAAe,GAAG,CAAC,KAAc,EAA2B,EAAE,CACzE,OAAO,KAAK,KAAK,QAAQ;IACzB,KAAK,KAAK,IAAI;IACd,IAAI,IAAI,KAAK;IACb,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,CAAC;AAJlB,QAAA,eAAe,mBAIG"}
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ContextLogTrail } from 'sdk-logs';
|
|
2
|
+
/**
|
|
3
|
+
* .what = records that one sqs record met a fault of ours in validation, and is retried
|
|
4
|
+
* .why = the record redrives, so without a loud line a schema defect hides behind retries. this
|
|
5
|
+
* names the message, the class, the cause, and the stack, so an on-call engineer can find it
|
|
6
|
+
*
|
|
7
|
+
* .note = error, not warn: the fault is ours — a schema whose own callback threw — never the
|
|
8
|
+
* producer's. the peer `logSqsRecordRefused` is the warn for a caller fault
|
|
9
|
+
*/
|
|
10
|
+
export declare const logSqsRecordInvalid: (input: {
|
|
11
|
+
id: string;
|
|
12
|
+
error: Error;
|
|
13
|
+
}, context: {
|
|
14
|
+
log: Pick<ContextLogTrail['log'], 'error'>;
|
|
15
|
+
}) => void;
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logSqsRecordInvalid = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = records that one sqs record met a fault of ours in validation, and is retried
|
|
6
|
+
* .why = the record redrives, so without a loud line a schema defect hides behind retries. this
|
|
7
|
+
* names the message, the class, the cause, and the stack, so an on-call engineer can find it
|
|
8
|
+
*
|
|
9
|
+
* .note = error, not warn: the fault is ours — a schema whose own callback threw — never the
|
|
10
|
+
* producer's. the peer `logSqsRecordRefused` is the warn for a caller fault
|
|
11
|
+
*/
|
|
12
|
+
const logSqsRecordInvalid = (input, context) => {
|
|
13
|
+
context.log.error('sqs.record.invalid', {
|
|
14
|
+
id: input.id,
|
|
15
|
+
class: input.error.constructor.name,
|
|
16
|
+
errorMessage: input.error.message,
|
|
17
|
+
stack: input.error.stack ?? null,
|
|
18
|
+
consequence: 'redriven — a fault of ours, so sqs redrives this record alone',
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.logSqsRecordInvalid = logSqsRecordInvalid;
|
|
22
|
+
//# sourceMappingURL=logSqsRecordInvalid.js.map
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logSqsRecordInvalid.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAAmC,EACnC,OAAuD,EACjD,EAAE;IACR,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,oBAAoB,EAAE;QACtC,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI;QACnC,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;QACjC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI;QAChC,WAAW,EACT,+DAA+D;KAClE,CAAC,CAAC;AACL,CAAC,CAAC;AAZW,QAAA,mBAAmB,uBAY9B"}
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SQSRecord } from 'aws-lambda';
|
|
2
|
+
import type { ContextLogTrail } from 'sdk-logs';
|
|
3
|
+
/**
|
|
4
|
+
* .what = records that one sqs message was refused as a caller fault, and acknowledged
|
|
5
|
+
* .why = an acknowledged message is deleted from the queue, so this line is the one durable trace
|
|
6
|
+
* of it. it names the message, the class, and the cause, so an operator can find the
|
|
7
|
+
* producer at fault, and it carries the full message as it arrived, so an operator can
|
|
8
|
+
* requeue it from the log alone
|
|
9
|
+
*
|
|
10
|
+
* .note = `message` is the untouched `SQSRecord` aws handed over (`record._.raw`), never the
|
|
11
|
+
* decoded record: validation writes parsed values back into the decoded record, so only
|
|
12
|
+
* the raw one still holds the wire body and the typed `messageAttributes` a requeue needs.
|
|
13
|
+
* its `attributes` carry the fifo `MessageGroupId` and `MessageDeduplicationId`, and its
|
|
14
|
+
* `eventSourceARN` names the queue to requeue into
|
|
15
|
+
* .note = `class` reads `constructor.name`, the in-process class, and differs from the wire's
|
|
16
|
+
* `errorType` (`.name`) on purpose: an operator searches for the class the author threw,
|
|
17
|
+
* and helpful-errors 1.7.3 leaves `.name` at `'Error'` for every refusal. the wire must
|
|
18
|
+
* match the aws runtime; this line must name the cause. neither should copy the other
|
|
19
|
+
* .note = warn, not error: the lambda ran as intended and the producer is at fault, so the invoke
|
|
20
|
+
* is a success, exactly as `simple-lambda-handlers`' `badRequestErrorMiddleware` treated it
|
|
21
|
+
*/
|
|
22
|
+
export declare const logSqsRecordRefused: (input: {
|
|
23
|
+
message: SQSRecord;
|
|
24
|
+
error: Error;
|
|
25
|
+
}, context: {
|
|
26
|
+
log: Pick<ContextLogTrail['log'], 'warn'>;
|
|
27
|
+
}) => void;
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logSqsRecordRefused = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = records that one sqs message was refused as a caller fault, and acknowledged
|
|
6
|
+
* .why = an acknowledged message is deleted from the queue, so this line is the one durable trace
|
|
7
|
+
* of it. it names the message, the class, and the cause, so an operator can find the
|
|
8
|
+
* producer at fault, and it carries the full message as it arrived, so an operator can
|
|
9
|
+
* requeue it from the log alone
|
|
10
|
+
*
|
|
11
|
+
* .note = `message` is the untouched `SQSRecord` aws handed over (`record._.raw`), never the
|
|
12
|
+
* decoded record: validation writes parsed values back into the decoded record, so only
|
|
13
|
+
* the raw one still holds the wire body and the typed `messageAttributes` a requeue needs.
|
|
14
|
+
* its `attributes` carry the fifo `MessageGroupId` and `MessageDeduplicationId`, and its
|
|
15
|
+
* `eventSourceARN` names the queue to requeue into
|
|
16
|
+
* .note = `class` reads `constructor.name`, the in-process class, and differs from the wire's
|
|
17
|
+
* `errorType` (`.name`) on purpose: an operator searches for the class the author threw,
|
|
18
|
+
* and helpful-errors 1.7.3 leaves `.name` at `'Error'` for every refusal. the wire must
|
|
19
|
+
* match the aws runtime; this line must name the cause. neither should copy the other
|
|
20
|
+
* .note = warn, not error: the lambda ran as intended and the producer is at fault, so the invoke
|
|
21
|
+
* is a success, exactly as `simple-lambda-handlers`' `badRequestErrorMiddleware` treated it
|
|
22
|
+
*/
|
|
23
|
+
const logSqsRecordRefused = (input, context) => {
|
|
24
|
+
context.log.warn('sqs.record.refused', {
|
|
25
|
+
id: input.message.messageId,
|
|
26
|
+
class: input.error.constructor.name,
|
|
27
|
+
errorMessage: input.error.message,
|
|
28
|
+
consequence: 'deleted only if this invoke succeeds; redriven if it fails',
|
|
29
|
+
message: input.message,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
exports.logSqsRecordRefused = logSqsRecordRefused;
|
|
33
|
+
//# sourceMappingURL=logSqsRecordRefused.js.map
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logSqsRecordRefused.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACI,MAAM,mBAAmB,GAAG,CACjC,KAA2C,EAC3C,OAAsD,EAChD,EAAE;IACR,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,oBAAoB,EAAE;QACrC,EAAE,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS;QAC3B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI;QACnC,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;QACjC,WAAW,EAAE,4DAA4D;QACzE,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC,CAAC;AACL,CAAC,CAAC;AAXW,QAAA,mBAAmB,uBAW9B"}
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.d.ts
CHANGED
|
@@ -9,15 +9,16 @@ import type { SqsHeadersDeclared, SqsHeadersMerged, SqsRecordDecoded } from './S
|
|
|
9
9
|
* the record stale, silently (`domain.terms/headers.md`)
|
|
10
10
|
*
|
|
11
11
|
* .why one transformer for both variants = they differ in what they do with a failure, never in
|
|
12
|
-
* what counts as one.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* what counts as one. a refusal is a caller fault, so each variant acknowledges it:
|
|
13
|
+
* `perRecord` catches it around the whole serve and returns; `perBatch` catches it per
|
|
14
|
+
* record and leaves that id out of `batchItemFailures`. a second implementation would let
|
|
15
|
+
* the two definitions of valid drift
|
|
15
16
|
* (`rule.forbid.parallel-codepaths`)
|
|
16
17
|
*
|
|
17
18
|
* .why it throws rather than returns a result = the validation error carries the zod issue
|
|
18
19
|
* summary, and a `{ ok, error }` return would make every caller restate the throw.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
20
|
+
* each caller catches it at its own boundary — the serve for `perRecord`, the record for
|
|
21
|
+
* `perBatch` — which is where the disposition belongs
|
|
21
22
|
*
|
|
22
23
|
* .defect = LIVE, NOT FIXED — `getValidationError`'s strict-headers hint names api gateway, and
|
|
23
24
|
* one of its four clauses is false here: "api gateway injects keys you did not declare".
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.js
CHANGED
|
@@ -11,15 +11,16 @@ const getValidatedInput_1 = require("../middleware/getValidatedInput");
|
|
|
11
11
|
* the record stale, silently (`domain.terms/headers.md`)
|
|
12
12
|
*
|
|
13
13
|
* .why one transformer for both variants = they differ in what they do with a failure, never in
|
|
14
|
-
* what counts as one.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* what counts as one. a refusal is a caller fault, so each variant acknowledges it:
|
|
15
|
+
* `perRecord` catches it around the whole serve and returns; `perBatch` catches it per
|
|
16
|
+
* record and leaves that id out of `batchItemFailures`. a second implementation would let
|
|
17
|
+
* the two definitions of valid drift
|
|
17
18
|
* (`rule.forbid.parallel-codepaths`)
|
|
18
19
|
*
|
|
19
20
|
* .why it throws rather than returns a result = the validation error carries the zod issue
|
|
20
21
|
* summary, and a `{ ok, error }` return would make every caller restate the throw.
|
|
21
|
-
*
|
|
22
|
-
*
|
|
22
|
+
* each caller catches it at its own boundary — the serve for `perRecord`, the record for
|
|
23
|
+
* `perBatch` — which is where the disposition belongs
|
|
23
24
|
*
|
|
24
25
|
* .defect = LIVE, NOT FIXED — `getValidationError`'s strict-headers hint names api gateway, and
|
|
25
26
|
* one of its four clauses is false here: "api gateway injects keys you did not declare".
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setSqsRecordValidated.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.ts"],"names":[],"mappings":";;;AAEA,uEAAoE;AAOpE
|
|
1
|
+
{"version":3,"file":"setSqsRecordValidated.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.ts"],"names":[],"mappings":";;;AAEA,uEAAoE;AAOpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACI,MAAM,qBAAqB,GAAG,CAGnC,KAGD,EAGE,EAAE;IACH,MAAM,UAAU,GAAG,IAAA,qCAAiB,EAAC;QACnC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE;KACxE,CAAC,CAAC;IAEH;;;OAGG;IAEH;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,MAAM,CAAC,OAAO,GAAG,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;IAE1E;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IAE1C;;;;;;OAMG;IACH,OAAO,KAAK,CAAC,MAGX,CAAC;AACL,CAAC,CAAC;AAtDW,QAAA,qBAAqB,yBAsDhC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ContextLogTrail } from 'sdk-logs';
|
|
2
|
+
import type { ZodSchema } from 'zod';
|
|
3
|
+
import type { SqsHeadersDeclared, SqsHeadersMerged, SqsRecordDecoded } from './SqsEventDecoded';
|
|
4
|
+
/**
|
|
5
|
+
* .what = validates each record of a batch, and sorts the ones that fail by whose fault it is
|
|
6
|
+
* .why = `perBatch` decides per record, so a refusal must be read where its id is in hand:
|
|
7
|
+
* - a caller fault is acknowledged — logged, and named in `idsRefused` so it stays out of
|
|
8
|
+
* `batchItemFailures` and sqs deletes it once (`invariant.constraint-errors-never-redrive-sqs`)
|
|
9
|
+
* - a server fault (a schema whose own callback throws) is logged loud and named in neither
|
|
10
|
+
* list, so that record alone is retried — one defect of ours never redrives the healthy
|
|
11
|
+
* records beside it
|
|
12
|
+
* - a throw that is not an `Error` carries no verdict on any record, so it escapes and the
|
|
13
|
+
* whole batch redrives
|
|
14
|
+
*
|
|
15
|
+
* .note = deliberate mutation — the two accumulators fill in one pass and are returned
|
|
16
|
+
*/
|
|
17
|
+
export declare const setSqsRecordsValidated: <THeaders extends SqsHeadersDeclared, TPayload>(input: {
|
|
18
|
+
records: SqsRecordDecoded[];
|
|
19
|
+
schema: ZodSchema<{
|
|
20
|
+
headers?: THeaders;
|
|
21
|
+
payload: TPayload;
|
|
22
|
+
}>;
|
|
23
|
+
}, context: {
|
|
24
|
+
log: Pick<ContextLogTrail['log'], 'warn' | 'error'>;
|
|
25
|
+
}) => {
|
|
26
|
+
recordsValidated: SqsRecordDecoded<{
|
|
27
|
+
headers: SqsHeadersMerged<THeaders>;
|
|
28
|
+
payload: TPayload;
|
|
29
|
+
}>[];
|
|
30
|
+
idsRefused: Set<string>;
|
|
31
|
+
};
|
package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setSqsRecordsValidated = void 0;
|
|
4
|
+
const asCallerFault_1 = require("./asCallerFault");
|
|
5
|
+
const logSqsRecordInvalid_1 = require("./logSqsRecordInvalid");
|
|
6
|
+
const logSqsRecordRefused_1 = require("./logSqsRecordRefused");
|
|
7
|
+
const setSqsRecordValidated_1 = require("./setSqsRecordValidated");
|
|
8
|
+
/**
|
|
9
|
+
* .what = validates each record of a batch, and sorts the ones that fail by whose fault it is
|
|
10
|
+
* .why = `perBatch` decides per record, so a refusal must be read where its id is in hand:
|
|
11
|
+
* - a caller fault is acknowledged — logged, and named in `idsRefused` so it stays out of
|
|
12
|
+
* `batchItemFailures` and sqs deletes it once (`invariant.constraint-errors-never-redrive-sqs`)
|
|
13
|
+
* - a server fault (a schema whose own callback throws) is logged loud and named in neither
|
|
14
|
+
* list, so that record alone is retried — one defect of ours never redrives the healthy
|
|
15
|
+
* records beside it
|
|
16
|
+
* - a throw that is not an `Error` carries no verdict on any record, so it escapes and the
|
|
17
|
+
* whole batch redrives
|
|
18
|
+
*
|
|
19
|
+
* .note = deliberate mutation — the two accumulators fill in one pass and are returned
|
|
20
|
+
*/
|
|
21
|
+
const setSqsRecordsValidated = (input, context) => {
|
|
22
|
+
const recordsValidated = [];
|
|
23
|
+
const idsRefused = new Set();
|
|
24
|
+
for (const record of input.records) {
|
|
25
|
+
try {
|
|
26
|
+
recordsValidated.push((0, setSqsRecordValidated_1.setSqsRecordValidated)({ record, schema: input.schema }));
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
// a caller fault: acknowledge it, by id
|
|
30
|
+
const callerFault = (0, asCallerFault_1.asCallerFault)({ error });
|
|
31
|
+
if (callerFault) {
|
|
32
|
+
(0, logSqsRecordRefused_1.logSqsRecordRefused)({ message: record._.raw, error: callerFault }, context);
|
|
33
|
+
idsRefused.add(record.id);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
// a non-error throw is no verdict on this record; it escapes, and the batch redrives
|
|
37
|
+
if (!(error instanceof Error))
|
|
38
|
+
throw error;
|
|
39
|
+
// a server fault: logged loud; its omission from both lists IS its redrive, never a swallow
|
|
40
|
+
(0, logSqsRecordInvalid_1.logSqsRecordInvalid)({ id: record.id, error }, context);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { recordsValidated, idsRefused };
|
|
44
|
+
};
|
|
45
|
+
exports.setSqsRecordsValidated = setSqsRecordsValidated;
|
|
46
|
+
//# sourceMappingURL=setSqsRecordsValidated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setSqsRecordsValidated.js","sourceRoot":"","sources":["../../../../src/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.ts"],"names":[],"mappings":";;;AAGA,mDAAgD;AAChD,+DAA4D;AAC5D,+DAA4D;AAM5D,mEAAgE;AAEhE;;;;;;;;;;;;GAYG;AACI,MAAM,sBAAsB,GAAG,CAIpC,KAGC,EACD,OAAgE,EAOhE,EAAE;IACF,MAAM,gBAAgB,GAGf,EAAE,CAAC;IACV,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IAErC,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,gBAAgB,CAAC,IAAI,CACnB,IAAA,6CAAqB,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CACxD,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,wCAAwC;YACxC,MAAM,WAAW,GAAG,IAAA,6BAAa,EAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YAC7C,IAAI,WAAW,EAAE,CAAC;gBAChB,IAAA,yCAAmB,EACjB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,EAC7C,OAAO,CACR,CAAC;gBACF,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAC1B,SAAS;YACX,CAAC;YAED,qFAAqF;YACrF,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;gBAAE,MAAM,KAAK,CAAC;YAE3C,4FAA4F;YAC5F,IAAA,yCAAmB,EAAC,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAED,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,CAAC;AAC1C,CAAC,CAAC;AAhDW,QAAA,sBAAsB,0BAgDjC"}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* | site | what it wanted |
|
|
16
16
|
* |---|---|
|
|
17
|
-
* | `runLambdaEndpoint.onSerialized.ts` (`asWireFunctionErrorPayload`) | `message` · `stack` · `
|
|
17
|
+
* | `runLambdaEndpoint.onSerialized.ts` (`asWireFunctionErrorPayload`) | `message` · `stack` · `name` |
|
|
18
18
|
* | `serde/asWireStripped.ts` | the whole `Error`, to hang as a `cause` |
|
|
19
19
|
* | `local/getOneHandlerFromServerlessYml.ts` | `message`, to branch on a text match |
|
|
20
20
|
*
|
|
@@ -46,5 +46,10 @@
|
|
|
46
46
|
* optional on a real `Error` and absent on a plain thrown object; `.name` is
|
|
47
47
|
* present on a bare `{ name }` bag. `.message` as a string is the one field
|
|
48
48
|
* every `Error` carries and few impostors do.
|
|
49
|
+
*
|
|
50
|
+
* .note = this is the COARSE narrow, for a site that reads fields. the wire LABEL
|
|
51
|
+
* follows a stricter rule — the aws runtime's `_isError` trio — which lives in
|
|
52
|
+
* `serde/asErrorTypeOfErrorLike.ts`. the two answer different questions, so
|
|
53
|
+
* neither replaces the other.
|
|
49
54
|
*/
|
|
50
55
|
export declare const isErrorLike: (value: unknown) => value is Error;
|
|
@@ -17,7 +17,7 @@ exports.isErrorLike = void 0;
|
|
|
17
17
|
*
|
|
18
18
|
* | site | what it wanted |
|
|
19
19
|
* |---|---|
|
|
20
|
-
* | `runLambdaEndpoint.onSerialized.ts` (`asWireFunctionErrorPayload`) | `message` · `stack` · `
|
|
20
|
+
* | `runLambdaEndpoint.onSerialized.ts` (`asWireFunctionErrorPayload`) | `message` · `stack` · `name` |
|
|
21
21
|
* | `serde/asWireStripped.ts` | the whole `Error`, to hang as a `cause` |
|
|
22
22
|
* | `local/getOneHandlerFromServerlessYml.ts` | `message`, to branch on a text match |
|
|
23
23
|
*
|
|
@@ -49,6 +49,11 @@ exports.isErrorLike = void 0;
|
|
|
49
49
|
* optional on a real `Error` and absent on a plain thrown object; `.name` is
|
|
50
50
|
* present on a bare `{ name }` bag. `.message` as a string is the one field
|
|
51
51
|
* every `Error` carries and few impostors do.
|
|
52
|
+
*
|
|
53
|
+
* .note = this is the COARSE narrow, for a site that reads fields. the wire LABEL
|
|
54
|
+
* follows a stricter rule — the aws runtime's `_isError` trio — which lives in
|
|
55
|
+
* `serde/asErrorTypeOfErrorLike.ts`. the two answer different questions, so
|
|
56
|
+
* neither replaces the other.
|
|
52
57
|
*/
|
|
53
58
|
const isErrorLike = (value) => typeof value?.message === 'string';
|
|
54
59
|
exports.isErrorLike = isErrorLike;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isErrorLike.js","sourceRoot":"","sources":["../../../../src/domain.operations/runLambdaEndpoint/error/isErrorLike.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"isErrorLike.js","sourceRoot":"","sources":["../../../../src/domain.operations/runLambdaEndpoint/error/isErrorLike.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACI,MAAM,WAAW,GAAG,CAAC,KAAc,EAAkB,EAAE,CAC5D,OAAQ,KAA+B,EAAE,OAAO,KAAK,QAAQ,CAAC;AADnD,QAAA,WAAW,eACwC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* .what = the wire label of any thrown value, as the aws node runtime writes it
|
|
3
|
+
* .why = a local run must label a throw exactly as the cloud does, or a caller fault flips side
|
|
4
|
+
* between loci. the source is `toRapidResponse` in
|
|
5
|
+
* `aws-lambda-nodejs-runtime-interface-client`, `src/Errors.js`:
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* try {
|
|
9
|
+
* if (util.types.isNativeError(error) || _isError(error))
|
|
10
|
+
* return { errorType: error.name?.replaceAll('\x7F', '%7F'), ...,
|
|
11
|
+
* trace: error.stack.replaceAll('\x7F', '%7F').split('\n') };
|
|
12
|
+
* return { errorType: typeof error, errorMessage: error.toString(), trace: [] };
|
|
13
|
+
* } catch (_err) { return { errorType: 'handled', ... }; }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* `_isError` asks for a truthy `name`, `message`, and `stack`, each a string
|
|
17
|
+
*
|
|
18
|
+
* .note = read from `aws/aws-lambda-nodejs-runtime-interface-client` `main`, `src/Errors.js`, on
|
|
19
|
+
* 2026-10-22. `blackbox/deployed.faultLabel.acceptance.test.ts` compares it to the
|
|
20
|
+
* deployed runtime, one fault kind per branch, so a label rule change upstream turns that
|
|
21
|
+
* suite red. a branch no kind there reaches is still caught only by a re-read of the file
|
|
22
|
+
*
|
|
23
|
+
* .note = a thrown `null` or `undefined` never reaches `toRapidResponse` on the cloud: the
|
|
24
|
+
* runtime's `CallbackContext.fail` swaps it for the string `'handled'` first. this
|
|
25
|
+
* mirrors `toRapidResponse` alone; `asWireFunctionErrorPayload` makes that swap ahead of it
|
|
26
|
+
*
|
|
27
|
+
* .note = each branch the runtime reaches via its `catch` is computed here up front, so this
|
|
28
|
+
* holds no catch of its own: an error-shaped value whose `stack`, or a present `name` or
|
|
29
|
+
* `message`, is not a string makes the runtime's `.replaceAll` throw; a `null`, an
|
|
30
|
+
* `undefined`, a value with no `toString`, or one whose `toString` (or its getter)
|
|
31
|
+
* throws makes `error.toString()` throw. each of those reads `'handled'`
|
|
32
|
+
* .note = one divergence, by type: a native error whose `.name` was set nullish gets no
|
|
33
|
+
* `errorType` on the cloud; this answers `'undefined'`, since a label is a string
|
|
34
|
+
* .note = two predicates, two questions. `isErrorLike` is the COARSE narrow: "can I read
|
|
35
|
+
* `.message` and `.stack` off this?". this is the runtime's LABEL rule: "what does the
|
|
36
|
+
* cloud call it?". a site that reads fields reaches for `isErrorLike`; a site that must
|
|
37
|
+
* match the wire label reaches for this
|
|
38
|
+
*/
|
|
39
|
+
export declare const asErrorTypeOfErrorLike: (input: {
|
|
40
|
+
error: unknown;
|
|
41
|
+
}) => string;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asErrorTypeOfErrorLike = void 0;
|
|
4
|
+
const node_util_1 = require("node:util");
|
|
5
|
+
/**
|
|
6
|
+
* .what = the wire label of any thrown value, as the aws node runtime writes it
|
|
7
|
+
* .why = a local run must label a throw exactly as the cloud does, or a caller fault flips side
|
|
8
|
+
* between loci. the source is `toRapidResponse` in
|
|
9
|
+
* `aws-lambda-nodejs-runtime-interface-client`, `src/Errors.js`:
|
|
10
|
+
*
|
|
11
|
+
* ```js
|
|
12
|
+
* try {
|
|
13
|
+
* if (util.types.isNativeError(error) || _isError(error))
|
|
14
|
+
* return { errorType: error.name?.replaceAll('\x7F', '%7F'), ...,
|
|
15
|
+
* trace: error.stack.replaceAll('\x7F', '%7F').split('\n') };
|
|
16
|
+
* return { errorType: typeof error, errorMessage: error.toString(), trace: [] };
|
|
17
|
+
* } catch (_err) { return { errorType: 'handled', ... }; }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* `_isError` asks for a truthy `name`, `message`, and `stack`, each a string
|
|
21
|
+
*
|
|
22
|
+
* .note = read from `aws/aws-lambda-nodejs-runtime-interface-client` `main`, `src/Errors.js`, on
|
|
23
|
+
* 2026-10-22. `blackbox/deployed.faultLabel.acceptance.test.ts` compares it to the
|
|
24
|
+
* deployed runtime, one fault kind per branch, so a label rule change upstream turns that
|
|
25
|
+
* suite red. a branch no kind there reaches is still caught only by a re-read of the file
|
|
26
|
+
*
|
|
27
|
+
* .note = a thrown `null` or `undefined` never reaches `toRapidResponse` on the cloud: the
|
|
28
|
+
* runtime's `CallbackContext.fail` swaps it for the string `'handled'` first. this
|
|
29
|
+
* mirrors `toRapidResponse` alone; `asWireFunctionErrorPayload` makes that swap ahead of it
|
|
30
|
+
*
|
|
31
|
+
* .note = each branch the runtime reaches via its `catch` is computed here up front, so this
|
|
32
|
+
* holds no catch of its own: an error-shaped value whose `stack`, or a present `name` or
|
|
33
|
+
* `message`, is not a string makes the runtime's `.replaceAll` throw; a `null`, an
|
|
34
|
+
* `undefined`, a value with no `toString`, or one whose `toString` (or its getter)
|
|
35
|
+
* throws makes `error.toString()` throw. each of those reads `'handled'`
|
|
36
|
+
* .note = one divergence, by type: a native error whose `.name` was set nullish gets no
|
|
37
|
+
* `errorType` on the cloud; this answers `'undefined'`, since a label is a string
|
|
38
|
+
* .note = two predicates, two questions. `isErrorLike` is the COARSE narrow: "can I read
|
|
39
|
+
* `.message` and `.stack` off this?". this is the runtime's LABEL rule: "what does the
|
|
40
|
+
* cloud call it?". a site that reads fields reaches for `isErrorLike`; a site that must
|
|
41
|
+
* match the wire label reaches for this
|
|
42
|
+
*/
|
|
43
|
+
const asErrorTypeOfErrorLike = (input) => {
|
|
44
|
+
const error = input.error;
|
|
45
|
+
// the runtime's error arm: a native error, or a value its `_isError` accepts
|
|
46
|
+
if (node_util_1.types.isNativeError(error) || isRuntimeErrorShape(error))
|
|
47
|
+
return asErrorTypeOfErrorShaped({ error });
|
|
48
|
+
// the runtime's other arm calls `error.toString()`; where that throws, it answers 'handled'
|
|
49
|
+
if (!isToStringCallable({ value: error }))
|
|
50
|
+
return 'handled';
|
|
51
|
+
return typeof error;
|
|
52
|
+
};
|
|
53
|
+
exports.asErrorTypeOfErrorLike = asErrorTypeOfErrorLike;
|
|
54
|
+
/**
|
|
55
|
+
* .what = the runtime's `_isError`: a truthy `name`, `message`, and `stack`, each a string
|
|
56
|
+
* .why = the empty string is falsy, so `{ name: 'X', message: '', stack: 's' }` fails it
|
|
57
|
+
* .note = `_isError` asks no `typeof` of the value, so a named function with a string
|
|
58
|
+
* `message` and `stack` passes it too, and the cloud labels it by its `.name`
|
|
59
|
+
*/
|
|
60
|
+
const isRuntimeErrorShape = (value) => (typeof value === 'object' || typeof value === 'function') &&
|
|
61
|
+
value !== null &&
|
|
62
|
+
'name' in value &&
|
|
63
|
+
'message' in value &&
|
|
64
|
+
'stack' in value &&
|
|
65
|
+
typeof value.name === 'string' &&
|
|
66
|
+
typeof value.message === 'string' &&
|
|
67
|
+
typeof value.stack === 'string' &&
|
|
68
|
+
value.name !== '' &&
|
|
69
|
+
value.message !== '' &&
|
|
70
|
+
value.stack !== '';
|
|
71
|
+
/**
|
|
72
|
+
* .what = the label of a value the runtime treats as an error: its `.name`, or 'handled' where
|
|
73
|
+
* the runtime's own reads would throw
|
|
74
|
+
*/
|
|
75
|
+
const asErrorTypeOfErrorShaped = (input) => {
|
|
76
|
+
// a native error or a `_isError` value; each read may be absent on either
|
|
77
|
+
const name = Reflect.get(input.error, 'name');
|
|
78
|
+
const message = Reflect.get(input.error, 'message');
|
|
79
|
+
const stack = Reflect.get(input.error, 'stack');
|
|
80
|
+
// `error.stack.replaceAll(...)` throws on a stack that is not a string
|
|
81
|
+
if (typeof stack !== 'string')
|
|
82
|
+
return 'handled';
|
|
83
|
+
// `?.replaceAll(...)` throws on a present name or message that is not a string
|
|
84
|
+
const isStringOrNullish = (value) => value === null || value === undefined || typeof value === 'string';
|
|
85
|
+
if (!isStringOrNullish(name) || !isStringOrNullish(message))
|
|
86
|
+
return 'handled';
|
|
87
|
+
// the runtime escapes DEL, so a label that holds one reads the same on both loci
|
|
88
|
+
return typeof name === 'string'
|
|
89
|
+
? name.split('\x7F').join('%7F')
|
|
90
|
+
: 'undefined';
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* .what = whether `value.toString()` runs, as the runtime's non-error arm calls it
|
|
94
|
+
* .why = the runtime answers 'handled' wherever that call throws: an absent `toString` (a null
|
|
95
|
+
* prototype), one that throws, or a getter that throws. only a call tells all three apart,
|
|
96
|
+
* so the probe calls it rather than read the property
|
|
97
|
+
* .note = the catch IS the mirror of the runtime's own `catch`, never a hidden fault: whatever
|
|
98
|
+
* the call throws, the cloud reads 'handled', and so does this. a `toString` with side
|
|
99
|
+
* effects runs once here and once more where the payload writes the message
|
|
100
|
+
*/
|
|
101
|
+
const isToStringCallable = (input) => {
|
|
102
|
+
if (input.value === null || input.value === undefined)
|
|
103
|
+
return false;
|
|
104
|
+
try {
|
|
105
|
+
// a primitive boxes to its prototype's `toString`, so `Object()` reads it the same way
|
|
106
|
+
const toStringFound = Reflect.get(Object(input.value), 'toString');
|
|
107
|
+
if (typeof toStringFound !== 'function')
|
|
108
|
+
return false;
|
|
109
|
+
Reflect.apply(toStringFound, input.value, []);
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=asErrorTypeOfErrorLike.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asErrorTypeOfErrorLike.js","sourceRoot":"","sources":["../../../../src/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.ts"],"names":[],"mappings":";;;AAAA,yCAAkC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACI,MAAM,sBAAsB,GAAG,CAAC,KAAyB,EAAU,EAAE;IAC1E,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAE1B,6EAA6E;IAC7E,IAAI,iBAAK,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,mBAAmB,CAAC,KAAK,CAAC;QAC1D,OAAO,wBAAwB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAE7C,4FAA4F;IAC5F,IAAI,CAAC,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5D,OAAO,OAAO,KAAK,CAAC;AACtB,CAAC,CAAC;AAVW,QAAA,sBAAsB,0BAUjC;AAEF;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAAmB,EAAE,CAC9D,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC;IAC1D,KAAK,KAAK,IAAI;IACd,MAAM,IAAI,KAAK;IACf,SAAS,IAAI,KAAK;IAClB,OAAO,IAAI,KAAK;IAChB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;IACjC,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;IAC/B,KAAK,CAAC,IAAI,KAAK,EAAE;IACjB,KAAK,CAAC,OAAO,KAAK,EAAE;IACpB,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC;AAErB;;;GAGG;AACH,MAAM,wBAAwB,GAAG,CAAC,KAAwB,EAAU,EAAE;IACpE,0EAA0E;IAC1E,MAAM,IAAI,GAAY,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACvD,MAAM,OAAO,GAAY,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAY,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAEzD,uEAAuE;IACvE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAEhD,+EAA+E;IAC/E,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAW,EAAE,CACpD,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;IACrE,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAE9E,iFAAiF;IACjF,OAAO,OAAO,IAAI,KAAK,QAAQ;QAC7B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;QAChC,CAAC,CAAC,WAAW,CAAC;AAClB,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,kBAAkB,GAAG,CAAC,KAAyB,EAAW,EAAE;IAChE,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACpE,IAAI,CAAC;QACH,uFAAuF;QACvF,MAAM,aAAa,GAAY,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,CAAC;QAC5E,IAAI,OAAO,aAAa,KAAK,UAAU;YAAE,OAAO,KAAK,CAAC;QACtD,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC"}
|