time-machine-js-plugin-express 1.0.0 → 1.1.0
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/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +9 -3
- package/dist/index.mjs +7 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
1
2
|
import { TimeMachineMode } from 'time-machine-js';
|
|
2
3
|
import { Request, Response, NextFunction } from 'express';
|
|
3
4
|
|
|
5
|
+
declare const timeMachineStore: AsyncLocalStorage<{
|
|
6
|
+
targetTimestamp: number;
|
|
7
|
+
}>;
|
|
4
8
|
interface TimeMachineMiddlewareOptions {
|
|
5
9
|
/**
|
|
6
10
|
* Header name to look for to trigger time travel.
|
|
@@ -14,4 +18,4 @@ interface TimeMachineOptions {
|
|
|
14
18
|
declare function initTimeMachineFromEnv(config: TimeMachineOptions): void;
|
|
15
19
|
declare function timeMachineMiddleware(options?: TimeMachineMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => void;
|
|
16
20
|
|
|
17
|
-
export { type TimeMachineMiddlewareOptions, type TimeMachineOptions, initTimeMachineFromEnv, timeMachineMiddleware };
|
|
21
|
+
export { type TimeMachineMiddlewareOptions, type TimeMachineOptions, initTimeMachineFromEnv, timeMachineMiddleware, timeMachineStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
1
2
|
import { TimeMachineMode } from 'time-machine-js';
|
|
2
3
|
import { Request, Response, NextFunction } from 'express';
|
|
3
4
|
|
|
5
|
+
declare const timeMachineStore: AsyncLocalStorage<{
|
|
6
|
+
targetTimestamp: number;
|
|
7
|
+
}>;
|
|
4
8
|
interface TimeMachineMiddlewareOptions {
|
|
5
9
|
/**
|
|
6
10
|
* Header name to look for to trigger time travel.
|
|
@@ -14,4 +18,4 @@ interface TimeMachineOptions {
|
|
|
14
18
|
declare function initTimeMachineFromEnv(config: TimeMachineOptions): void;
|
|
15
19
|
declare function timeMachineMiddleware(options?: TimeMachineMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => void;
|
|
16
20
|
|
|
17
|
-
export { type TimeMachineMiddlewareOptions, type TimeMachineOptions, initTimeMachineFromEnv, timeMachineMiddleware };
|
|
21
|
+
export { type TimeMachineMiddlewareOptions, type TimeMachineOptions, initTimeMachineFromEnv, timeMachineMiddleware, timeMachineStore };
|
package/dist/index.js
CHANGED
|
@@ -21,10 +21,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
initTimeMachineFromEnv: () => initTimeMachineFromEnv,
|
|
24
|
-
timeMachineMiddleware: () => timeMachineMiddleware
|
|
24
|
+
timeMachineMiddleware: () => timeMachineMiddleware,
|
|
25
|
+
timeMachineStore: () => timeMachineStore
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_async_hooks = require("async_hooks");
|
|
27
29
|
var import_time_machine_js = require("time-machine-js");
|
|
30
|
+
var timeMachineStore = new import_async_hooks.AsyncLocalStorage();
|
|
28
31
|
var envTimeSet = false;
|
|
29
32
|
function initTimeMachineFromEnv(config) {
|
|
30
33
|
if (envTimeSet) return;
|
|
@@ -79,11 +82,14 @@ function timeMachineMiddleware(options = {}) {
|
|
|
79
82
|
};
|
|
80
83
|
res.on("finish", revertTime);
|
|
81
84
|
res.on("close", revertTime);
|
|
82
|
-
|
|
85
|
+
timeMachineStore.run({ targetTimestamp }, () => {
|
|
86
|
+
next();
|
|
87
|
+
});
|
|
83
88
|
};
|
|
84
89
|
}
|
|
85
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
86
91
|
0 && (module.exports = {
|
|
87
92
|
initTimeMachineFromEnv,
|
|
88
|
-
timeMachineMiddleware
|
|
93
|
+
timeMachineMiddleware,
|
|
94
|
+
timeMachineStore
|
|
89
95
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
2
3
|
import {
|
|
3
4
|
travel,
|
|
4
5
|
returnToPresent,
|
|
@@ -6,6 +7,7 @@ import {
|
|
|
6
7
|
getOffset,
|
|
7
8
|
isActive
|
|
8
9
|
} from "time-machine-js";
|
|
10
|
+
var timeMachineStore = new AsyncLocalStorage();
|
|
9
11
|
var envTimeSet = false;
|
|
10
12
|
function initTimeMachineFromEnv(config) {
|
|
11
13
|
if (envTimeSet) return;
|
|
@@ -60,10 +62,13 @@ function timeMachineMiddleware(options = {}) {
|
|
|
60
62
|
};
|
|
61
63
|
res.on("finish", revertTime);
|
|
62
64
|
res.on("close", revertTime);
|
|
63
|
-
|
|
65
|
+
timeMachineStore.run({ targetTimestamp }, () => {
|
|
66
|
+
next();
|
|
67
|
+
});
|
|
64
68
|
};
|
|
65
69
|
}
|
|
66
70
|
export {
|
|
67
71
|
initTimeMachineFromEnv,
|
|
68
|
-
timeMachineMiddleware
|
|
72
|
+
timeMachineMiddleware,
|
|
73
|
+
timeMachineStore
|
|
69
74
|
};
|