@kensio/yulin 1.14.0 → 1.14.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.
@@ -6,7 +6,8 @@ import type { SimLambdaEnvironment } from "../../environment/sim-lambda-environm
6
6
  *
7
7
  * The context provides the common globals a Node.js Lambda runtime offers,
8
8
  * including an AWS-like process.env holding the standard runtime variables
9
- * and any variables declared for the function. Everything else must be part
9
+ * and any variables declared for the function, and the writable standard
10
+ * streams function code writes its output to. Everything else must be part
10
11
  * of the deployed function code archive, as on real Lambda.
11
12
  *
12
13
  * Zip code needs nothing like the process.env and Date handling the
@@ -1 +1 @@
1
- {"version":3,"file":"sim-lambda-vm-context.d.ts","sourceRoot":"","sources":["../../../../../../src/service/lambda/function/code/vm/sim-lambda-vm-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EACL,KAAK,QAAQ,EAEd,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAExF;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,oBAAoB,EACjC,KAAK,GAAE,QAA6B,GACnC,EAAE,CAAC,OAAO,CAuBZ"}
1
+ {"version":3,"file":"sim-lambda-vm-context.d.ts","sourceRoot":"","sources":["../../../../../../src/service/lambda/function/code/vm/sim-lambda-vm-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EACL,KAAK,QAAQ,EAEd,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAGxF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,oBAAoB,EACjC,KAAK,GAAE,QAA6B,GACnC,EAAE,CAAC,OAAO,CAkCZ"}
@@ -1,12 +1,15 @@
1
+ import { Console } from "node:console";
1
2
  import vm from "node:vm";
2
3
  import { makeSimClockDate } from "../../../../../util/clock/sim-clock-date.js";
3
4
  import { SimRealClock, } from "../../../../../util/clock/sim-clock.js";
5
+ import { SimLambdaVmOutputStream } from "./sim-lambda-vm-output-stream.js";
4
6
  /**
5
7
  * Create the sandbox vm context that sim Lambda function code runs in.
6
8
  *
7
9
  * The context provides the common globals a Node.js Lambda runtime offers,
8
10
  * including an AWS-like process.env holding the standard runtime variables
9
- * and any variables declared for the function. Everything else must be part
11
+ * and any variables declared for the function, and the writable standard
12
+ * streams function code writes its output to. Everything else must be part
10
13
  * of the deployed function code archive, as on real Lambda.
11
14
  *
12
15
  * Zip code needs nothing like the process.env and Date handling the
@@ -15,11 +18,21 @@ import { SimRealClock, } from "../../../../../util/clock/sim-clock.js";
15
18
  * nothing outside the sandbox is touched to arrange that.
16
19
  */
17
20
  export function makeSimLambdaVmContext(environment, clock = new SimRealClock()) {
21
+ // Writable standard streams, as the real runtime provides. Code that builds
22
+ // its own console over them, as AWS Lambda Powertools' logger does, throws
23
+ // at module load without them.
24
+ const stdout = new SimLambdaVmOutputStream(() => process.stdout);
25
+ const stderr = new SimLambdaVmOutputStream(() => process.stderr);
18
26
  return vm.createContext({
19
- console,
27
+ // The sandbox's console is built over those streams, as the real
28
+ // runtime's is, so everything function code prints goes to one place
29
+ // whether it printed through the console or wrote to the stream itself.
30
+ console: new Console({ stdout, stderr }),
20
31
  Buffer,
21
32
  process: {
22
33
  env: environment.variables(),
34
+ stdout,
35
+ stderr,
23
36
  },
24
37
  // Function code asking JavaScript for the time gets the simulation's
25
38
  // time, so a frozen or advanced clock reaches the code under test.
@@ -1 +1 @@
1
- {"version":3,"file":"sim-lambda-vm-context.js","sourceRoot":"","sources":["../../../../../../src/service/lambda/function/code/vm/sim-lambda-vm-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAC/E,OAAO,EAEL,YAAY,GACb,MAAM,wCAAwC,CAAC;AAGhD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,sBAAsB,CACpC,WAAiC,EACjC,KAAK,GAAa,IAAI,YAAY,EAAE;IAEpC,OAAO,EAAE,CAAC,aAAa,CAAC;QACtB,OAAO;QACP,MAAM;QACN,OAAO,EAAE;YACP,GAAG,EAAE,WAAW,CAAC,SAAS,EAAE;SAC7B;QACD,qEAAqE;QACrE,mEAAmE;QACnE,IAAI,EAAE,gBAAgB,CAAC,KAAK,CAAC;QAC7B,UAAU;QACV,YAAY;QACZ,WAAW;QACX,aAAa;QACb,YAAY;QACZ,cAAc;QACd,WAAW;QACX,WAAW;QACX,GAAG;QACH,eAAe;QACf,eAAe;QACf,MAAM;KACP,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"sim-lambda-vm-context.js","sourceRoot":"","sources":["../../../../../../src/service/lambda/function/code/vm/sim-lambda-vm-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAC/E,OAAO,EAEL,YAAY,GACb,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAE3E;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,sBAAsB,CACpC,WAAiC,EACjC,KAAK,GAAa,IAAI,YAAY,EAAE;IAEpC,4EAA4E;IAC5E,2EAA2E;IAC3E,+BAA+B;IAC/B,MAAM,MAAM,GAAG,IAAI,uBAAuB,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACjE,MAAM,MAAM,GAAG,IAAI,uBAAuB,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjE,OAAO,EAAE,CAAC,aAAa,CAAC;QACtB,iEAAiE;QACjE,qEAAqE;QACrE,wEAAwE;QACxE,OAAO,EAAE,IAAI,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QACxC,MAAM;QACN,OAAO,EAAE;YACP,GAAG,EAAE,WAAW,CAAC,SAAS,EAAE;YAC5B,MAAM;YACN,MAAM;SACP;QACD,qEAAqE;QACrE,mEAAmE;QACnE,IAAI,EAAE,gBAAgB,CAAC,KAAK,CAAC;QAC7B,UAAU;QACV,YAAY;QACZ,WAAW;QACX,aAAa;QACb,YAAY;QACZ,cAAc;QACd,WAAW;QACX,WAAW;QACX,GAAG;QACH,eAAe;QACf,eAAe;QACf,MAAM;KACP,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { Writable } from "node:stream";
2
+ /**
3
+ * One of the standard output streams the sim Lambda vm sandbox gives function
4
+ * code as `process.stdout` and `process.stderr`.
5
+ *
6
+ * Real Lambda gives function code writable standard streams, and libraries
7
+ * build their own console over them rather than the global one, so that
8
+ * console patching cannot affect their output. AWS Lambda Powertools' logger
9
+ * does exactly that, at module scope:
10
+ *
11
+ * ```javascript
12
+ * new Console({ stdout: process.stdout, stderr: process.stderr })
13
+ * ```
14
+ *
15
+ * Without the streams that construction throws
16
+ * (`ERR_CONSOLE_WRITABLE_STREAM`) before the handler runs.
17
+ *
18
+ * What function code writes is forwarded to the matching host stream,
19
+ * standard output to standard output and standard error to standard error.
20
+ * The sandbox's own console is built over these streams too, so a handler's
21
+ * output arrives there whether it printed through the console or wrote to the
22
+ * stream itself, instead of one of the two disappearing. The host stream is
23
+ * read per write, so a test that starts capturing host output after the
24
+ * function has cold-started still sees what the handler writes.
25
+ */
26
+ export declare class SimLambdaVmOutputStream extends Writable {
27
+ private readonly hostStream;
28
+ constructor(hostStream: () => NodeJS.WritableStream);
29
+ /**
30
+ * The write is handed on and reported as done without waiting for the host
31
+ * stream, as Node.js's own console hands writes to process.stdout. Waiting
32
+ * would make a failed log write fail the code that logged: reporting the
33
+ * host's error here destroys this stream, and with nothing listening for
34
+ * its error the process goes down over a lost line. It would also mean a
35
+ * test capturing host output had to complete the write it captured, and the
36
+ * ordinary way to capture it does not.
37
+ */
38
+ _write(chunk: Buffer, _encoding: BufferEncoding, done: (error?: Error) => void): void;
39
+ }
40
+ //# sourceMappingURL=sim-lambda-vm-output-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sim-lambda-vm-output-stream.d.ts","sourceRoot":"","sources":["../../../../../../src/service/lambda/function/code/vm/sim-lambda-vm-output-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,uBAAwB,SAAQ,QAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAAvC,YAA6B,UAAU,EAAE,MAAM,MAAM,CAAC,cAAc,EAEnE;IAED;;;;;;;;OAQG;IACM,MAAM,CACb,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,cAAc,EACzB,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,GAC5B,IAAI,CAGN;CACF"}
@@ -0,0 +1,46 @@
1
+ import { Writable } from "node:stream";
2
+ /**
3
+ * One of the standard output streams the sim Lambda vm sandbox gives function
4
+ * code as `process.stdout` and `process.stderr`.
5
+ *
6
+ * Real Lambda gives function code writable standard streams, and libraries
7
+ * build their own console over them rather than the global one, so that
8
+ * console patching cannot affect their output. AWS Lambda Powertools' logger
9
+ * does exactly that, at module scope:
10
+ *
11
+ * ```javascript
12
+ * new Console({ stdout: process.stdout, stderr: process.stderr })
13
+ * ```
14
+ *
15
+ * Without the streams that construction throws
16
+ * (`ERR_CONSOLE_WRITABLE_STREAM`) before the handler runs.
17
+ *
18
+ * What function code writes is forwarded to the matching host stream,
19
+ * standard output to standard output and standard error to standard error.
20
+ * The sandbox's own console is built over these streams too, so a handler's
21
+ * output arrives there whether it printed through the console or wrote to the
22
+ * stream itself, instead of one of the two disappearing. The host stream is
23
+ * read per write, so a test that starts capturing host output after the
24
+ * function has cold-started still sees what the handler writes.
25
+ */
26
+ export class SimLambdaVmOutputStream extends Writable {
27
+ hostStream;
28
+ constructor(hostStream) {
29
+ super();
30
+ this.hostStream = hostStream;
31
+ }
32
+ /**
33
+ * The write is handed on and reported as done without waiting for the host
34
+ * stream, as Node.js's own console hands writes to process.stdout. Waiting
35
+ * would make a failed log write fail the code that logged: reporting the
36
+ * host's error here destroys this stream, and with nothing listening for
37
+ * its error the process goes down over a lost line. It would also mean a
38
+ * test capturing host output had to complete the write it captured, and the
39
+ * ordinary way to capture it does not.
40
+ */
41
+ _write(chunk, _encoding, done) {
42
+ this.hostStream().write(chunk);
43
+ done();
44
+ }
45
+ }
46
+ //# sourceMappingURL=sim-lambda-vm-output-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sim-lambda-vm-output-stream.js","sourceRoot":"","sources":["../../../../../../src/service/lambda/function/code/vm/sim-lambda-vm-output-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,uBAAwB,SAAQ,QAAQ;IACtB,UAAU;IAAvC,YAA6B,UAAuC;QAClE,KAAK,EAAE,CAAC;0BADmB,UAAU;IAEvC,CAAC;IAED;;;;;;;;OAQG;IACM,MAAM,CACb,KAAa,EACb,SAAyB,EACzB,IAA6B;QAE7B,IAAI,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,EAAE,CAAC;IACT,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kensio/yulin",
3
- "version": "1.14.0",
3
+ "version": "1.14.1",
4
4
  "description": "AWS system behaviour simulation for isolated unit testing",
5
5
  "repository": "https://github.com/KensioSoftware/yulin",
6
6
  "homepage": "https://yulinsim.dev/",
@@ -163,6 +163,8 @@
163
163
  "packageManager": "pnpm@11.17.0+sha512.cca3cea332ad254bb84145f966d19f4879615210346fc92c79a047f23a0d7b3cca3c3792f0076ba1f1831d277efbcf0a9119b31a9a60eca7fb3d6231f331ef72",
164
164
  "devDependencies": {
165
165
  "@aws-crypto/sha256-js": "^5.2.0",
166
+ "@aws-lambda-powertools/logger": "^2.34.0",
167
+ "@aws-lambda-powertools/metrics": "^2.34.0",
166
168
  "@aws-sdk/client-acm": "^3.1101.0",
167
169
  "@aws-sdk/client-apigatewayv2": "^3.1101.0",
168
170
  "@aws-sdk/client-cloudformation": "^3.1101.0",
@@ -204,6 +206,7 @@
204
206
  "aws-sdk-client-mock": "^4.1.0",
205
207
  "constructs": "^10.8.0",
206
208
  "conventional-changelog-conventionalcommits": "9.3.1",
209
+ "esbuild": "^0.28.2",
207
210
  "eslint": "^10.8.0",
208
211
  "eslint-plugin-jsdoc": "^63.3.2",
209
212
  "eslint-plugin-no-secrets": "^2.3.3",