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.
Files changed (53) hide show
  1. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forApiGateway/genLambdaEndpoint.forApiGateway.js +1 -1
  2. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.d.ts +14 -0
  3. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.js +20 -0
  4. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asCallerFault.js.map +1 -0
  5. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.d.ts +9 -0
  6. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.js +13 -0
  7. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsBatchResponse.js.map +1 -0
  8. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.d.ts +10 -0
  9. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.js +11 -0
  10. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/asSqsRecordIds.js.map +1 -0
  11. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.d.ts +9 -3
  12. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.js +35 -37
  13. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perBatch.js.map +1 -1
  14. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.d.ts +12 -6
  15. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js +54 -34
  16. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genLambdaEndpoint.forSqs.perRecord.js.map +1 -1
  17. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.d.ts +11 -7
  18. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.js +11 -7
  19. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/genSqsEndpointMiddlewares.js.map +1 -1
  20. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.d.ts +19 -0
  21. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.js +22 -0
  22. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsRetried.js.map +1 -0
  23. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.d.ts +11 -0
  24. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.js +13 -0
  25. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsIdsUnclaimable.js.map +1 -0
  26. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.d.ts +11 -0
  27. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.js +18 -0
  28. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/getAllSqsSuccessRefsMalformed.js.map +1 -0
  29. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.d.ts +8 -0
  30. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.js +14 -0
  31. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/isSqsSuccessRef.js.map +1 -0
  32. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.d.ts +15 -0
  33. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.js +22 -0
  34. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordInvalid.js.map +1 -0
  35. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.d.ts +27 -0
  36. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.js +33 -0
  37. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/logSqsRecordRefused.js.map +1 -0
  38. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.d.ts +6 -5
  39. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.js +6 -5
  40. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordValidated.js.map +1 -1
  41. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.d.ts +31 -0
  42. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.js +46 -0
  43. package/dist/domain.operations/genLambdaEndpoint/genLambdaEndpoint.forSqs/setSqsRecordsValidated.js.map +1 -0
  44. package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.d.ts +6 -1
  45. package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.js +6 -1
  46. package/dist/domain.operations/runLambdaEndpoint/error/isErrorLike.js.map +1 -1
  47. package/dist/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.d.ts +41 -0
  48. package/dist/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.js +116 -0
  49. package/dist/domain.operations/runLambdaEndpoint/serde/asErrorTypeOfErrorLike.js.map +1 -0
  50. package/dist/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.js +52 -17
  51. package/dist/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.js.map +1 -1
  52. package/package.json +6 -6
  53. package/readme.md +23 -4
@@ -2,6 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.asWireFunctionErrorPayload = void 0;
4
4
  const isErrorLike_1 = require("../error/isErrorLike");
5
+ const asErrorTypeOfErrorLike_1 = require("./asErrorTypeOfErrorLike");
6
+ /**
7
+ * .what = the message the aws node runtime writes when its own reads of a thrown value throw
8
+ * .why = `toRapidResponse`'s catch arm answers `errorType: 'handled'` with this fixed text and
9
+ * no trace (`aws-lambda-nodejs-runtime-interface-client`, `src/Errors.js`), so a local
10
+ * run shows the caller the same words the cloud does
11
+ */
12
+ const RUNTIME_HANDLED_MESSAGE = 'callback called with Error argument, but there was a problem while retrieving one or more of its message, name, and stack';
5
13
  /**
6
14
  * .what = casts a thrown handler fault into the envelope aws puts on the wire
7
15
  * .why = 🔴 **a THROW does not cross a wire; a payload does.** on the cloud locus
@@ -39,29 +47,56 @@ const isErrorLike_1 = require("../error/isErrorLike");
39
47
  */
40
48
  const asWireFunctionErrorPayload = (error) => {
41
49
  /**
42
- * .what = reads the error by duck-type, never by `instanceof Error`
43
- * .why = 🔴 `instanceof` fails CROSS-REALM, and this runs where two realms
44
- * meet: the local locus loads the handler through
45
- * `getOneHandlerFromServerlessYml`, and jest executes each module in
46
- * its own vm context.
47
- *
48
- * ⚠️ the miss is SILENT — it degrades the payload rather than throws:
49
- * `errorMessage` gains an `Error: ` prefix, `errorType` collapses to
50
- * `'Error'`, `stackTrace` is dropped. `getParsedResponse` hydrates from
51
- * `errorType`, so a cross-realm `ConstraintError` comes back generic — a
52
- * caller fault that no longer reads as one (`rule.forbid.failhide`).
50
+ * .what = labels the payload exactly as the aws node runtime labels it, read by duck-type
51
+ * .why = 🔴 the cloud wire is the truth this cast must reproduce. the runtime's
52
+ * `toRapidResponse` (`aws-lambda-nodejs-runtime-interface-client`,
53
+ * `src/Errors.js`) writes `errorType: error.name` for an error, and
54
+ * `errorType: typeof error` for any other thrown value. a read of
55
+ * `constructor.name` instead labels a helpful-errors `ConstraintError`
56
+ * (whose `.name` is the inherited `'Error'`) as a caller fault locally
57
+ * while the cloud labels it a server fault — a green local run over a
58
+ * red prod (sdk-aws-lambda#73). so a throw reads here exactly as it
59
+ * reads on the cloud, whatever its `.name`.
60
+ * .note = never `instanceof Error`: it fails across realms, and this runs where
61
+ * two meet (the local locus loads the handler through
62
+ * `getOneHandlerFromServerlessYml`; jest gives each module its own vm
63
+ * context). the reason lives at `isErrorLike`
64
+ * .note = the LABEL mirror is exact, the lossy parts included: `errorType`
65
+ * may be any `typeof` (`'object'`, `'symbol'`, …) or the runtime's own
66
+ * `'handled'` (a stackless native error), which carries the runtime's
67
+ * one fixed message and no trace. a thrown `null` or `undefined` never
68
+ * reaches `toRapidResponse`: the runtime's `CallbackContext.fail` swaps
69
+ * it for the string `'handled'` first, so the wire reads
70
+ * `errorType: 'string'`, `errorMessage: 'handled'` (measured by
71
+ * `blackbox/deployed.faultLabel.acceptance.test.ts`). and a
72
+ * thrown object with no message reads `errorMessage: '[object Object]'`,
73
+ * as the runtime's own `${error}` writes it. a local cast that read
74
+ * better than prod would hide what prod shows; to carry a cause, throw
75
+ * an `Error`. an error-like value that fails `_isError` keeps its
76
+ * message and stack here — the label, which decides the fault side,
77
+ * is the field held to the cloud's bytes
53
78
  */
54
- if (!(0, isErrorLike_1.isErrorLike)(error))
79
+ // the runtime's fail arm swaps a null or undefined rejection for the string 'handled'
80
+ const thrown = error === null || error === undefined ? 'handled' : error;
81
+ // the runtime's catch arm writes one fixed message and no trace, whatever was thrown
82
+ const errorType = (0, asErrorTypeOfErrorLike_1.asErrorTypeOfErrorLike)({ error: thrown });
83
+ if (errorType === 'handled')
84
+ return {
85
+ errorMessage: RUNTIME_HANDLED_MESSAGE,
86
+ errorType,
87
+ stackTrace: [],
88
+ };
89
+ if (!(0, isErrorLike_1.isErrorLike)(thrown))
55
90
  return {
56
- errorMessage: String(error),
57
- errorType: 'Error',
91
+ errorMessage: String(thrown),
92
+ errorType,
58
93
  stackTrace: [],
59
94
  };
60
95
  return {
61
- errorMessage: error.message,
62
- errorType: error.constructor?.name ?? 'Error',
96
+ errorMessage: thrown.message,
97
+ errorType,
63
98
  // `stack` is optional on a real Error
64
- stackTrace: typeof error.stack === 'string' ? error.stack.split('\n') : [],
99
+ stackTrace: typeof thrown.stack === 'string' ? thrown.stack.split('\n') : [],
65
100
  };
66
101
  };
67
102
  exports.asWireFunctionErrorPayload = asWireFunctionErrorPayload;
@@ -1 +1 @@
1
- {"version":3,"file":"asWireFunctionErrorPayload.js","sourceRoot":"","sources":["../../../../src/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACI,MAAM,0BAA0B,GAAG,CACxC,KAAc,EACqD,EAAE;IACrE;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,IAAA,yBAAW,EAAC,KAAK,CAAC;QACrB,OAAO;YACL,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC;YAC3B,SAAS,EAAE,OAAO;YAClB,UAAU,EAAE,EAAE;SACf,CAAC;IAEJ,OAAO;QACL,YAAY,EAAE,KAAK,CAAC,OAAO;QAC3B,SAAS,EAAE,KAAK,CAAC,WAAW,EAAE,IAAI,IAAI,OAAO;QAC7C,sCAAsC;QACtC,UAAU,EAAE,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;KAC3E,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,0BAA0B,8BA6BrC"}
1
+ {"version":3,"file":"asWireFunctionErrorPayload.js","sourceRoot":"","sources":["../../../../src/domain.operations/runLambdaEndpoint/serde/asWireFunctionErrorPayload.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AACnD,qEAAkE;AAElE;;;;;GAKG;AACH,MAAM,uBAAuB,GAC3B,2HAA2H,CAAC;AAE9H;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACI,MAAM,0BAA0B,GAAG,CACxC,KAAc,EACqD,EAAE;IACrE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,sFAAsF;IACtF,MAAM,MAAM,GAAG,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;IAEzE,qFAAqF;IACrF,MAAM,SAAS,GAAG,IAAA,+CAAsB,EAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5D,IAAI,SAAS,KAAK,SAAS;QACzB,OAAO;YACL,YAAY,EAAE,uBAAuB;YACrC,SAAS;YACT,UAAU,EAAE,EAAE;SACf,CAAC;IAEJ,IAAI,CAAC,IAAA,yBAAW,EAAC,MAAM,CAAC;QACtB,OAAO;YACL,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC;YAC5B,SAAS;YACT,UAAU,EAAE,EAAE;SACf,CAAC;IAEJ,OAAO;QACL,YAAY,EAAE,MAAM,CAAC,OAAO;QAC5B,SAAS;QACT,sCAAsC;QACtC,UAAU,EACR,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;KACnE,CAAC;AACJ,CAAC,CAAC;AA3DW,QAAA,0BAA0B,8BA2DrC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "sdk-aws-lambda",
3
3
  "author": "ehmpathy",
4
4
  "description": "a simple and opinionated sdk for aws lambda. define endpoints, ask endpoints, auto-propagate trace-ids.",
5
- "version": "0.7.2",
5
+ "version": "0.7.3",
6
6
  "repository": "ehmpathy/sdk-aws-lambda",
7
7
  "homepage": "https://github.com/ehmpathy/sdk-aws-lambda",
8
8
  "keywords": [
@@ -102,14 +102,14 @@
102
102
  "husky": "8.0.3",
103
103
  "iso-time": "1.11.7",
104
104
  "jest": "30.2.0",
105
- "rhachet": "1.49.2",
105
+ "rhachet": "1.50.1",
106
106
  "rhachet-brains-anthropic": "0.4.3",
107
107
  "rhachet-brains-fireworksai": "0.2.3",
108
- "rhachet-brains-openrouter": "0.1.3",
108
+ "rhachet-brains-openrouter": "0.1.4",
109
109
  "rhachet-brains-xai": "0.3.3",
110
- "rhachet-roles-bhrain": "0.39.3",
111
- "rhachet-roles-bhuild": "0.23.2",
112
- "rhachet-roles-ehmpathy": "1.39.5",
110
+ "rhachet-roles-bhrain": "0.42.3",
111
+ "rhachet-roles-bhuild": "0.23.3",
112
+ "rhachet-roles-ehmpathy": "1.40.0",
113
113
  "rhachet-roles-rhachet": "0.1.7",
114
114
  "test-fns": "1.15.8",
115
115
  "tsc-alias": "1.8.10",
package/readme.md CHANGED
@@ -152,10 +152,24 @@ export const handler = genLambdaEndpoint.forSqs.perBatch({
152
152
  });
153
153
  ```
154
154
 
155
- `perBatch` fails safe: any record not returned in `successes` is retried, and an answer the sdk
156
- cannot read retries the whole batch. its event source must declare
155
+ `perBatch` fails safe: any record neither returned in `successes` nor refused by the schema is
156
+ retried, and an answer the sdk cannot read retries the whole batch. its event source must declare
157
157
  `functionResponseTypes: ['ReportBatchItemFailures']`.
158
158
 
159
+ a caller fault is never retried. a message the schema refuses, or a `ConstraintError` (or
160
+ `BadRequestError`) a `perRecord` handler throws, logs `sqs.record.refused` at warn and is deleted,
161
+ with no dead-letter entry. to retry a fault, throw a `MalfunctionError`; every other throw redrives.
162
+
163
+ - `sqs.record.refused` carries the full message as delivered (`message`: body, attributes, queue
164
+ arn), so an operator can requeue it from the log. alarm on its volume: a schema bug of ours
165
+ deletes messages, and no dead-letter queue holds them
166
+ - `sqs.record.invalid` (error) marks a schema callback that threw a fault of ours; that record retries
167
+ - a `perBatch` handler throw redrives the whole batch, refused records too. to drop a record, return
168
+ it in `successes`, and log it yourself. when the schema refuses every record, the handler gets
169
+ `records: []`
170
+ - to test a refusal: the invoke succeeds with no answer, so assert the handler did not run and spy
171
+ `console.warn` for `sqs.record.refused`
172
+
159
173
  ⇒ zoom in: [records](./.agent/repo=.this/role=any/briefs/domain.terms/records.md)
160
174
 
161
175
  ## ask an endpoint
@@ -188,7 +202,7 @@ it resolves `{ status, headers, text, body }`. a 4xx throws a `ConstraintError`;
188
202
  `MalfunctionError` that carries the `correlationId`. your trail rides the request, so the endpoint's
189
203
  logs join yours.
190
204
 
191
- any other http client spreads the `x-trail-exid` header in to send the trail. the header also opts the
205
+ any other http caller spreads the `x-trail-exid` header in to send the trail. the header also opts the
192
206
  caller in to the contemp error body (`{ error: { class, … } }`); without it the endpoint answers the flat
193
207
  `{ errorMessage, errorType }`:
194
208
 
@@ -235,6 +249,11 @@ await expect(
235
249
 
236
250
  a malfunction throws on both. the util adds no `catch`.
237
251
 
252
+ `'local'` labels an escaped throw by its `.name`, as the aws runtime does. a `forAsk` or
253
+ `forApiGateway` endpoint answers a `ConstraintError` by class, so its caller reads a caller fault on
254
+ both loci. a raw handler's throw reads as its `.name` says: helpful-errors 1.7.3's `ConstraintError`
255
+ reads `'Error'`, so it arrives as a server fault, locally and on the cloud (cure: helpful-errors#47).
256
+
238
257
  the return is a union — `TOutput | Envelope` — so read either arm through a narrow:
239
258
 
240
259
  ```ts
@@ -370,7 +389,7 @@ schema: {
370
389
  a value that fails the domain object's own constructor **fails loud at the border** and never reaches
371
390
  `invoke` half-built.
372
391
 
373
- what a caller of your generated cross-service client sees is the **wire** shape —
392
+ what a caller of your generated cross-service sdk sees is the **wire** shape —
374
393
  `{ surfer: { uuid, name } }` — never the instance. the two differ by design: the wire is what
375
394
  crosses, the instance is what you hold once through.
376
395