lambder 12.0.1 → 13.0.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +7 -2
  3. package/dist/api/LambderApiAnswer.d.ts +7 -0
  4. package/dist/api/LambderApiEnvelope.js +4 -1
  5. package/dist/api/LambderApiRefusals.d.ts +22 -0
  6. package/dist/api/LambderApiRefusals.js +13 -0
  7. package/dist/build/generateApiFiles.d.ts +60 -0
  8. package/dist/build/generateApiFiles.js +85 -0
  9. package/dist/build.d.ts +4 -1
  10. package/dist/build.js +3 -1
  11. package/dist/core/Lambder.d.ts +32 -8
  12. package/dist/core/Lambder.js +135 -17
  13. package/dist/core/LambderCallSummary.d.ts +43 -0
  14. package/dist/core/LambderCallSummary.js +10 -0
  15. package/dist/core/LambderContext.d.ts +14 -1
  16. package/dist/core/LambderContext.js +19 -4
  17. package/dist/core/LambderCreateOptions.d.ts +50 -25
  18. package/dist/core/LambderCreateOptions.js +37 -18
  19. package/dist/core/LambderInvocationScope.d.ts +25 -0
  20. package/dist/core/LambderInvocationScope.js +21 -0
  21. package/dist/core/LambderResponse.d.ts +11 -0
  22. package/dist/core/LambderResponse.js +12 -0
  23. package/dist/core/LambderResponseBuilder.js +5 -1
  24. package/dist/index.d.ts +6 -4
  25. package/dist/index.js +1 -1
  26. package/dist/invoke/LambderLambdaEvent.d.ts +2 -0
  27. package/dist/invoke/LambderLambdaEvent.js +8 -2
  28. package/dist/mock/LambderMockApp.d.ts +8 -8
  29. package/dist/mock/LambderMockApp.js +14 -10
  30. package/dist/mock/LambderMockCreateOptions.d.ts +2 -3
  31. package/dist/session/LambderSessionManager.d.ts +46 -3
  32. package/dist/session/LambderSessionManager.js +62 -11
  33. package/dist/shared/LambderI18n.js +49 -4
  34. package/dist/shared/contracts/LambderRateLimiter.d.ts +2 -2
  35. package/dist/shared/contracts/LambderRateLimiter.js +2 -2
  36. package/dist/shared/util/LambderInvocationScope.d.ts +10 -0
  37. package/dist/shared/util/LambderInvocationScope.js +5 -0
  38. package/dist/shared/util/LambderNamedMaps.d.ts +22 -0
  39. package/dist/shared/util/LambderNamedMaps.js +19 -0
  40. package/dist/shared/wire/LambderCallOutcome.d.ts +27 -0
  41. package/dist/shared/wire/LambderCallOutcome.js +47 -0
  42. package/dist/shared/wire/LambderInvokeApiId.d.ts +10 -0
  43. package/dist/shared/wire/LambderInvokeApiId.js +10 -0
  44. package/dist/stores/LambderDdbRateLimiter.d.ts +24 -16
  45. package/dist/stores/LambderDdbRateLimiter.js +64 -45
  46. package/dist/stores/LambderMemoryRateLimiter.d.ts +9 -4
  47. package/dist/stores/LambderMemoryRateLimiter.js +20 -15
  48. package/dist/testing/LambderTestApp.d.ts +13 -4
  49. package/dist/testing/LambderTestApp.js +21 -5
  50. package/package.json +1 -1
@@ -9,6 +9,7 @@ import type { LambderRateLimiter } from "../shared/contracts/LambderRateLimiter.
9
9
  import type { LambderSessionStore } from "../shared/contracts/LambderSessionStore.js";
10
10
  import { LAMBDER_BACKEND_SWAP, LAMBDER_CRASH_WATCH } from "../shared/util/LambderTestingDoors.js";
11
11
  import type { LambderApiContractShape } from "../shared/wire/LambderApiContract.js";
12
+ import type { LambderCallSummary } from "../core/LambderCallSummary.js";
12
13
  import { LambderTestVisitor, type LambderTestVisitorArgs, type LambderTestVisitorOptions } from "./LambderTestVisitor.js";
13
14
  /**
14
15
  * What a test app may be told. Nothing is required: `lambderTestApp(lambder)`
@@ -100,6 +101,8 @@ export declare class LambderTestApp<TContract extends LambderApiContractShape =
100
101
  private visitorCount;
101
102
  private resetCount;
102
103
  private readonly crashList;
104
+ /** Every call summary the app wrote since the last reset; see callSummaries. */
105
+ private readonly callSummaryList;
103
106
  /**
104
107
  * The call a crash happened under. The app's 500 says nothing about the
105
108
  * crash, so the error travels beside the answer, and with concurrent
@@ -117,6 +120,12 @@ export declare class LambderTestApp<TContract extends LambderApiContractShape =
117
120
  * error an `event()` rejects with, which the test already holds.
118
121
  */
119
122
  get crashes(): readonly Error[];
123
+ /**
124
+ * The summary of every API call the app answered since the last reset,
125
+ * in order (see LambderCallSummary): what its callSummary option would
126
+ * have been handed, collected here instead of written to stdout.
127
+ */
128
+ get callSummaries(): readonly LambderCallSummary[];
120
129
  /** The session manager, for tests that inspect or manipulate sessions directly. Throws when the app has no sessions. */
121
130
  get sessionManager(): LambderSessionManager<TSessionData>;
122
131
  /**
@@ -159,10 +168,10 @@ export declare class LambderTestApp<TContract extends LambderApiContractShape =
159
168
  event(event: unknown, context?: Partial<Context>): Promise<unknown>;
160
169
  /**
161
170
  * Rewinds what accumulated: sessions, rate-limit counters and replay
162
- * records in the stores this test app made, the crashes it recorded, and
163
- * the cookies of every visitor it created (each empties its jar the next
164
- * time it is used). For a beforeEach. The app's own data (its database)
165
- * is the app's to rewind.
171
+ * records in the stores this test app made, the crashes and call
172
+ * summaries it recorded, and the cookies of every visitor it created
173
+ * (each empties its jar the next time it is used). For a beforeEach. The
174
+ * app's own data (its database) is the app's to rewind.
166
175
  */
167
176
  reset(): void;
168
177
  }
@@ -49,6 +49,8 @@ export class LambderTestApp {
49
49
  visitorCount = 0;
50
50
  resetCount = 0;
51
51
  crashList = [];
52
+ /** Every call summary the app wrote since the last reset; see callSummaries. */
53
+ callSummaryList = [];
52
54
  /**
53
55
  * The call a crash happened under. The app's 500 says nothing about the
54
56
  * crash, so the error travels beside the answer, and with concurrent
@@ -66,7 +68,12 @@ export class LambderTestApp {
66
68
  const sessionStore = options.session?.store ?? own(new LambderMemorySessionStore());
67
69
  const rateLimiter = options.rateLimits?.limiter ?? own(new LambderMemoryRateLimiter());
68
70
  const idempotencyStore = options.idempotency?.store ?? own(new LambderMemoryIdempotencyStore());
69
- const swap = lambder[LAMBDER_BACKEND_SWAP]({ sessionStore, rateLimiter, idempotencyStore, fileSource: options.files });
71
+ // The summaries are collected rather than written, so a suite's
72
+ // output stays its own and a test can read what a call recorded.
73
+ const swap = lambder[LAMBDER_BACKEND_SWAP]({
74
+ sessionStore, rateLimiter, idempotencyStore, fileSource: options.files,
75
+ callSummary: (summary) => { this.callSummaryList.push(summary); },
76
+ });
70
77
  if (options.files && !swap.files) {
71
78
  throw new Error("lambderTestApp: the files option was given, but the app was created without one, so nothing reads files to put a source under.");
72
79
  }
@@ -116,6 +123,14 @@ export class LambderTestApp {
116
123
  get crashes() {
117
124
  return this.crashList;
118
125
  }
126
+ /**
127
+ * The summary of every API call the app answered since the last reset,
128
+ * in order (see LambderCallSummary): what its callSummary option would
129
+ * have been handed, collected here instead of written to stdout.
130
+ */
131
+ get callSummaries() {
132
+ return this.callSummaryList;
133
+ }
119
134
  /** The session manager, for tests that inspect or manipulate sessions directly. Throws when the app has no sessions. */
120
135
  get sessionManager() {
121
136
  return this.lambder.getSessionManager();
@@ -178,15 +193,16 @@ export class LambderTestApp {
178
193
  }
179
194
  /**
180
195
  * Rewinds what accumulated: sessions, rate-limit counters and replay
181
- * records in the stores this test app made, the crashes it recorded, and
182
- * the cookies of every visitor it created (each empties its jar the next
183
- * time it is used). For a beforeEach. The app's own data (its database)
184
- * is the app's to rewind.
196
+ * records in the stores this test app made, the crashes and call
197
+ * summaries it recorded, and the cookies of every visitor it created
198
+ * (each empties its jar the next time it is used). For a beforeEach. The
199
+ * app's own data (its database) is the app's to rewind.
185
200
  */
186
201
  reset() {
187
202
  for (const store of this.ownStores)
188
203
  store.reset();
189
204
  this.crashList.length = 0;
205
+ this.callSummaryList.length = 0;
190
206
  this.resetCount += 1;
191
207
  }
192
208
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambder",
3
- "version": "12.0.1",
3
+ "version": "13.0.1",
4
4
  "sideEffects": false,
5
5
  "description": "Opinionated serverless web framework for TypeScript on AWS Lambda: type-safe APIs from Zod schemas, DynamoDB sessions, and declarative rate limits, authorization guards and idempotency.",
6
6
  "keywords": [