@kensio/yulin 1.21.6 → 1.21.8
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/README.md +22 -2
- package/dist/service/eventbridge/cfn/bus/sim-cfn-event-bus-creator.js +1 -0
- package/dist/service/eventbridge/cfn/bus/sim-cfn-event-bus-properties.d.ts +4 -0
- package/dist/service/eventbridge/cfn/bus/sim-cfn-event-bus-properties.js +26 -1
- package/dist/service/eventbridge/cfn/rule/sim-cfn-event-rule-creator.js +3 -1
- package/dist/service/eventbridge/cfn/rule/sim-cfn-event-rule-properties.d.ts +0 -7
- package/dist/service/eventbridge/cfn/rule/sim-cfn-event-rule-properties.js +0 -20
- package/dist/service/eventbridge/cfn/rule/sim-cfn-event-rule-unsimulated-properties.d.ts +13 -0
- package/dist/service/eventbridge/cfn/rule/sim-cfn-event-rule-unsimulated-properties.js +59 -0
- package/dist/service/eventbridge/cfn/sim-cfn-event-bridge-resource-error.d.ts +1 -1
- package/dist/service/eventbridge/cfn/sim-cfn-event-bridge-resource-error.js +1 -1
- package/dist/service/lambda/cfn/event-source-mapping/sim-cfn-lambda-event-source-mapping-properties.js +1 -1
- package/dist/service/lambda/cfn/event-source-mapping/sim-cfn-lambda-event-source-mapping-property-rules.d.ts +3 -2
- package/dist/service/lambda/cfn/event-source-mapping/sim-cfn-lambda-event-source-mapping-property-rules.js +25 -3
- package/dist/service/ses/command/authorize/sim-ses-authorizer.d.ts +9 -0
- package/dist/service/ses/command/authorize/sim-ses-authorizer.js +18 -2
- package/dist/service/ses/command/send/sim-ses-send-email.js +2 -1
- package/dist/service/sns/cfn/topic/sim-cfn-sns-topic-creator.js +1 -0
- package/dist/service/sns/cfn/topic/sim-cfn-sns-topic-properties.d.ts +9 -4
- package/dist/service/sns/cfn/topic/sim-cfn-sns-topic-properties.js +18 -6
- package/dist/service/sns/cfn/topic/sim-cfn-sns-topic-property-names.d.ts +10 -0
- package/dist/service/sns/cfn/topic/sim-cfn-sns-topic-property-names.js +16 -1
- package/dist/service/ssm/cfn/parameter/sim-cfn-ssm-parameter-creator.js +1 -1
- package/dist/service/ssm/cfn/parameter/sim-cfn-ssm-parameter-properties.d.ts +11 -6
- package/dist/service/ssm/cfn/parameter/sim-cfn-ssm-parameter-properties.js +18 -9
- package/docs/README.md +40 -4
- package/docs/ai-skill/README.md +57 -54
- package/docs/cli/README.md +84 -94
- package/docs/factories/README.md +42 -54
- package/docs/lint/README.md +41 -67
- package/docs/non-aws-dependencies/README.md +72 -168
- package/docs/sdk/README.md +109 -95
- package/docs/serve/README.md +192 -898
- package/docs/services/acm/README.md +24 -40
- package/docs/services/apigateway/README.md +52 -71
- package/docs/services/apigatewayv2/README.md +55 -74
- package/docs/services/athena/README.md +17 -26
- package/docs/services/backup/README.md +29 -39
- package/docs/services/bedrock/README.md +38 -52
- package/docs/services/cloudformation/README.md +43 -55
- package/docs/services/cloudfront/README.md +69 -95
- package/docs/services/cloudwatch/README.md +40 -54
- package/docs/services/cognito/README.md +30 -45
- package/docs/services/dynamodb/README.md +34 -51
- package/docs/services/ecr/README.md +36 -77
- package/docs/services/ecs/README.md +26 -46
- package/docs/services/elbv2/README.md +19 -29
- package/docs/services/eventbridge/README.md +24 -20
- package/docs/services/firehose/README.md +24 -32
- package/docs/services/glue/README.md +41 -78
- package/docs/services/iam/README.md +13 -15
- package/docs/services/kinesis/README.md +53 -93
- package/docs/services/kms/README.md +22 -32
- package/docs/services/lambda/README.md +60 -80
- package/docs/services/logs/README.md +41 -50
- package/docs/services/organizations/README.md +50 -85
- package/docs/services/personalize/README.md +28 -44
- package/docs/services/rekognition/README.md +26 -38
- package/docs/services/route53/README.md +17 -17
- package/docs/services/s3/README.md +47 -51
- package/docs/services/scheduler/README.md +41 -52
- package/docs/services/secretsmanager/README.md +27 -42
- package/docs/services/ses/README.md +24 -34
- package/docs/services/sns/README.md +31 -33
- package/docs/services/sqs/README.md +14 -14
- package/docs/services/ssm/README.md +19 -21
- package/docs/services/stepfunctions/README.md +18 -20
- package/docs/services/sts/README.md +32 -45
- package/docs/services/wafv2/README.md +12 -17
- package/docs/terraform/README.md +108 -126
- package/docs/testing/README.md +228 -0
- package/docs/time/README.md +87 -117
- package/llms.txt +2 -1
- package/package.json +1 -1
package/docs/time/README.md
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
# Simulated time
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
depends on time passing, such as a temporary session expiring, can be tested without waiting for it.
|
|
3
|
+
Each `SimAws` has its own clock. Yulin uses that clock for resource timestamps, expiry checks, and
|
|
4
|
+
scheduled work.
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
simulation running in the same test file, and any other code in the process all carry on unchanged.
|
|
6
|
+
## Isolate tests that control time
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
A shared [test suite environment](https://yulinsim.dev/testing/) also has one shared clock. Most
|
|
9
|
+
tests should use that environment without calling `freeze()`, `setTo(...)`, `advanceBy(...)`, or
|
|
10
|
+
`resume()`.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
Put tests that control simulated time in a separate test group. Give each of those tests its own
|
|
13
|
+
`SimAws` or `SimSdk`, along with the infrastructure it needs. A clock change then affects only that
|
|
14
|
+
test's environment. The rest of the suite can keep sharing one deployment and SDK interception.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
## Start at a known time
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Pass a clock to start somewhere specific. `SimFixedClock` is the usual choice, since it reports one
|
|
21
|
-
instant and stays there:
|
|
18
|
+
A new simulation follows the system clock by default. Pass a `SimFixedClock` when a test needs an
|
|
19
|
+
exact starting time:
|
|
22
20
|
|
|
23
21
|
```typescript sim-clock-freeze-and-advance
|
|
24
22
|
/**
|
|
@@ -47,41 +45,33 @@ console.log(simAws.now()); // 2026-07-26T11:30:00.000Z
|
|
|
47
45
|
simAws.clock().resume();
|
|
48
46
|
```
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
built on a `SimFixedClock` puts it back in running mode, and its time then moves whenever the clock
|
|
53
|
-
underneath moves. A fixed clock stays where it is. Leave the default real clock in place for a
|
|
54
|
-
simulation whose time should pass by itself.
|
|
48
|
+
`simAws.now()` returns the current simulated time. Services use the same value when they create
|
|
49
|
+
timestamps such as an IAM user's `CreateDate`.
|
|
55
50
|
|
|
56
|
-
|
|
51
|
+
The controllable clock sits on top of the clock passed to `SimAws`. Calling `resume()` makes time
|
|
52
|
+
follow that underlying clock again. A `SimFixedClock` never moves, so resuming it still reports a
|
|
53
|
+
fixed time. Keep the default system clock when resumed time should move normally.
|
|
57
54
|
|
|
58
|
-
|
|
55
|
+
## Frozen and running
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
- **Running**: simulated time tracks the clock underneath, offset from it. On the default real clock
|
|
64
|
-
time passes by itself. Use it to jump forward an hour and carry on.
|
|
57
|
+
Call `freeze()` to stop the clock at its current time. Both `setTo(...)` and `advanceBy(...)` also
|
|
58
|
+
leave the clock frozen at the resulting time. This keeps timestamps stable while the test makes its
|
|
59
|
+
assertions.
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
long the assertion takes. `resume()` is the way back to running, and it carries on from where the
|
|
69
|
-
clock stopped.
|
|
61
|
+
Call `resume()` to let the underlying clock move time again. Any offset remains in place. For
|
|
62
|
+
example, a simulation advanced by one hour continues to run one hour ahead of the system clock.
|
|
70
63
|
|
|
71
|
-
`simAws.clock().isFrozen`
|
|
64
|
+
Read `simAws.clock().isFrozen` to check the current mode.
|
|
72
65
|
|
|
73
66
|
## Advancing time
|
|
74
67
|
|
|
75
|
-
`advanceBy(...)`
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
passing only runs forwards. `setTo(...)` is the explicit way to move a clock back.
|
|
68
|
+
`advanceBy(...)` accepts days, hours, minutes, seconds, and milliseconds. The values are added
|
|
69
|
+
together. A number means milliseconds, so `advanceBy(3_600_000)` advances by one hour. Durations
|
|
70
|
+
must be zero or greater. Use `setTo(...)` to move to an earlier time.
|
|
79
71
|
|
|
80
|
-
Advancing
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
that work is itself due by the new time, and stays queued where it falls later. So a test can
|
|
84
|
-
advance and then assert, with no additional waiting:
|
|
72
|
+
Advancing the clock also runs scheduled work due within the interval. Yulin runs each task at its
|
|
73
|
+
due time and waits for the simulation to settle before returning. The test can assert on the result
|
|
74
|
+
immediately:
|
|
85
75
|
|
|
86
76
|
```typescript sim-clock-session-expiry
|
|
87
77
|
/**
|
|
@@ -138,31 +128,16 @@ try {
|
|
|
138
128
|
}
|
|
139
129
|
```
|
|
140
130
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
Delivery to a target is the exception, and deliberately so. An EventBridge rule or a Scheduler
|
|
145
|
-
schedule that cannot reach its target records the failure instead of throwing. Real AWS reports a
|
|
146
|
-
failed delivery to nobody, and one rejected delivery would otherwise fail an unrelated
|
|
147
|
-
`advanceBy(...)` elsewhere in the same test. Read the failures from `eventBridge().deliveryFailures`
|
|
148
|
-
and `scheduler().deliveryFailures`.
|
|
149
|
-
|
|
150
|
-
A Step Functions execution works the same way. A state that fails while the clock is being advanced
|
|
151
|
-
is recorded on the execution, and `DescribeExecution` reports it once the advance has returned.
|
|
131
|
+
If scheduled work throws, `advanceBy(...)` throws the same failure. The clock stops at the failed
|
|
132
|
+
task's due time, and later work remains queued.
|
|
152
133
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
falls due, a Step Functions execution moves on from a `Wait` state, and a Lambda event source
|
|
157
|
-
mapping polls again. Each of those runs at its own due instant inside the interval, in the order
|
|
158
|
-
they fall due.
|
|
134
|
+
EventBridge and EventBridge Scheduler delivery failures are recorded instead. Read them from
|
|
135
|
+
`eventBridge().deliveryFailures` or `scheduler().deliveryFailures`. Step Functions also records a
|
|
136
|
+
failed state on the execution for `DescribeExecution` to return.
|
|
159
137
|
|
|
160
|
-
##
|
|
138
|
+
## Read simulated time in a Lambda handler
|
|
161
139
|
|
|
162
|
-
|
|
163
|
-
the function code itself reads. `Date.now()` and `new Date()` inside a handler report simulated
|
|
164
|
-
time. Code stamping an expiry or building a date-partitioned key can be tested against a clock the
|
|
165
|
-
test controls:
|
|
140
|
+
Inside a simulated Lambda invocation, `Date.now()` and `new Date()` read the simulation's clock:
|
|
166
141
|
|
|
167
142
|
```typescript sim-clock-lambda-handler
|
|
168
143
|
/**
|
|
@@ -203,30 +178,22 @@ const second = await lambda.invoke(
|
|
|
203
178
|
console.log(Buffer.from(second.Payload!).toString()); // {"at":"2026-07-26T11:00:00.000Z"}
|
|
204
179
|
```
|
|
205
180
|
|
|
206
|
-
|
|
207
|
-
|
|
181
|
+
Zip code runs in a VM with a `Date` constructor connected to the simulation. An in-process handler
|
|
182
|
+
uses the same simulated time during its invocation. Code outside the invocation continues to read
|
|
183
|
+
the system clock, including code running concurrently in another simulation.
|
|
208
184
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
- **A real in-process handler function** is a closure over the module scope it was written in, and
|
|
212
|
-
reads the global `Date` like everything else in the test run. So the global is substituted for one
|
|
213
|
-
reporting the invocation's clock while an invocation is running, and the host clock otherwise,
|
|
214
|
-
tracked with `AsyncLocalStorage` so concurrent invocations of different simulations stay apart. It
|
|
215
|
-
is installed on the first in-process invocation and never removed, and with no invocation running
|
|
216
|
-
it behaves exactly as the host's own `Date` does.
|
|
185
|
+
Only calls that ask for the current time are changed. `new Date("2020-03-12")`, `Date.parse(...)`,
|
|
186
|
+
`Date.UTC(...)`, and `instanceof Date` keep their usual behaviour.
|
|
217
187
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
that waits for it to change never finishes. Call `resume()` before invoking if the code under test
|
|
223
|
-
polls the clock.
|
|
188
|
+
The global `setTimeout`, `clearTimeout`, `setInterval`, and `clearInterval` functions also use the
|
|
189
|
+
simulation's clock during an invocation. Start an invocation without awaiting it, advance the
|
|
190
|
+
clock past the timer delay, then await the invocation. Lambda's configured timeout and
|
|
191
|
+
`context.getRemainingTimeInMillis()` use the same clock.
|
|
224
192
|
|
|
225
193
|
### Where real AWS gets the time
|
|
226
194
|
|
|
227
|
-
Real Lambda has no current-time API.
|
|
228
|
-
|
|
229
|
-
Date()` is reading the machine clock. AWS does provide the time on the event:
|
|
195
|
+
Real Lambda has no current-time API. A production handler gets the current time from the machine
|
|
196
|
+
clock or from a timestamp in its event:
|
|
230
197
|
|
|
231
198
|
| Event source | Field |
|
|
232
199
|
| ------------------------- | ------------------------------------------------- |
|
|
@@ -236,49 +203,52 @@ Date()` is reading the machine clock. AWS does provide the time on the event:
|
|
|
236
203
|
| SNS | `Records[].Sns.Timestamp` |
|
|
237
204
|
| SQS | `Records[].attributes.SentTimestamp` |
|
|
238
205
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
An SQS event source mapping does the same. The `SentTimestamp` and
|
|
245
|
-
`ApproximateFirstReceiveTimestamp` attributes on a delivered record are simulated time, and a
|
|
246
|
-
handler reading the event's time reads the clock the test controls. See
|
|
247
|
-
[simulated Lambda](https://yulinsim.dev/services/lambda/#triggering-a-function-from-an-sqs-queue "Simulated Lambda event source mapping docs").
|
|
206
|
+
Yulin puts simulated time into the events it builds. Function URL events include
|
|
207
|
+
`requestContext.time` and `requestContext.timeEpoch`. SQS records include simulated
|
|
208
|
+
`SentTimestamp` and `ApproximateFirstReceiveTimestamp` values. The
|
|
209
|
+
[Lambda documentation](https://yulinsim.dev/services/lambda/#triggering-a-function-from-an-sqs-queue "Simulated Lambda event source mapping docs")
|
|
210
|
+
describes the event source mapping behaviour.
|
|
248
211
|
|
|
249
|
-
|
|
250
|
-
|
|
212
|
+
A handler can also accept a clock as a dependency. That approach works without Lambda-specific
|
|
213
|
+
clock handling.
|
|
251
214
|
|
|
252
215
|
## Time over HTTP
|
|
253
216
|
|
|
254
|
-
A simulation served
|
|
255
|
-
response
|
|
256
|
-
time. Advancing the clock changes what that header reports. A client talking to the simulation sees
|
|
257
|
-
the same "now" the simulation does, with no need to know it is talking to a simulator.
|
|
217
|
+
A simulation served through `serveSimAws` or `SimAwsHttp.fetch(...)` uses simulated time in each
|
|
218
|
+
response's `Date` header. Advancing the clock changes the header on later responses.
|
|
258
219
|
|
|
259
220
|
## Time and SDK interception
|
|
260
221
|
|
|
261
|
-
A `SimSdk`
|
|
262
|
-
|
|
222
|
+
A `SimSdk` exposes its simulation as `simSdk.simAws`. Advance its clock with
|
|
223
|
+
`await simSdk.simAws.clock().advanceBy({ hours: 1 })`.
|
|
224
|
+
|
|
225
|
+
## Uses of simulated time
|
|
226
|
+
|
|
227
|
+
Yulin uses the clock for:
|
|
228
|
+
|
|
229
|
+
- Resource timestamps and expiry checks
|
|
230
|
+
- EventBridge rules and EventBridge Scheduler schedules
|
|
231
|
+
- DynamoDB time to live and scheduled Secrets Manager deletion
|
|
232
|
+
- Step Functions `Wait` states
|
|
233
|
+
- Lambda event source polling and event timestamps
|
|
234
|
+
- `Date`, global timers, and invocation deadlines inside a simulated Lambda invocation
|
|
235
|
+
- HTTP response `Date` headers
|
|
263
236
|
|
|
264
237
|
## Limitations
|
|
265
238
|
|
|
266
|
-
-
|
|
267
|
-
[EventBridge
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
-
|
|
273
|
-
|
|
274
|
-
-
|
|
275
|
-
|
|
276
|
-
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
module scope read it when the test file imported the module, long before any invocation.
|
|
283
|
-
- Advancing time does not re-evaluate simulated state that was already computed, such as an ACM
|
|
284
|
-
certificate that has finished validating. It changes what is read from the clock next.
|
|
239
|
+
- Scheduled [EventBridge rules](https://yulinsim.dev/services/eventbridge/#rules-that-fire-on-a-schedule)
|
|
240
|
+
and [EventBridge Scheduler schedules](https://yulinsim.dev/services/scheduler/#firing-a-schedule)
|
|
241
|
+
run when `advanceBy(...)` or a forward `setTo(...)` reaches their due time. Elapsed system time
|
|
242
|
+
does not run them.
|
|
243
|
+
- Time control is available through `SimAws`. A standalone service such as `new SimS3()` uses the
|
|
244
|
+
system clock and has no clock controls.
|
|
245
|
+
- A `SimAws` created with a custom `background` scheduler cannot control time because the scheduler
|
|
246
|
+
owns its clock. Calling `simAws.clock()` throws `SimAwsTimeNotControllable`.
|
|
247
|
+
- JavaScript's `Date` and global timer functions use simulated time only during a simulated Lambda
|
|
248
|
+
invocation. Other application code continues to use system time.
|
|
249
|
+
- Lambda code imported from `node:timers` or `node:timers/promises` uses system time. The same is
|
|
250
|
+
true of `util.promisify(setTimeout)`.
|
|
251
|
+
- A module-level `Date.now()` runs when the module is imported, before the Lambda invocation begins.
|
|
252
|
+
It reads system time.
|
|
253
|
+
- Moving the clock does not recalculate state that has already been computed. For example, it does
|
|
254
|
+
not restart validation for an ACM certificate that is already issued.
|
package/llms.txt
CHANGED
|
@@ -47,7 +47,7 @@ The same pages are on the web at https://yulinsim.dev/ for whichever release is
|
|
|
47
47
|
- [STS](docs/services/sts/README.md): Simulated STS usage docs
|
|
48
48
|
- [WAFv2](docs/services/wafv2/README.md): Simulated WAFv2 usage docs
|
|
49
49
|
|
|
50
|
-
## Feature
|
|
50
|
+
## Feature guides
|
|
51
51
|
|
|
52
52
|
- [AI skill](docs/ai-skill/README.md): Yulin AI skill usage docs
|
|
53
53
|
- [The AWS CLI](docs/cli/README.md): The AWS CLI against simulated AWS usage docs
|
|
@@ -57,4 +57,5 @@ The same pages are on the web at https://yulinsim.dev/ for whichever release is
|
|
|
57
57
|
- [Non-AWS dependencies](docs/non-aws-dependencies/README.md): Dependencies Yulin does not simulate usage docs
|
|
58
58
|
- [Serving on localhost](docs/serve/README.md): Serving simulated AWS on localhost usage docs
|
|
59
59
|
- [Simulated time](docs/time/README.md): Simulated time usage docs
|
|
60
|
+
- [Test suite setup](docs/testing/README.md): Sharing one Yulin environment across a test suite
|
|
60
61
|
- [Terraform](docs/terraform/README.md): Deploying Terraform into simulated AWS usage docs
|
package/package.json
CHANGED