@drunkcod/express-kit 0.0.7 → 0.0.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/package.json +7 -5
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -42
- package/lib/loggable.d.ts +0 -2
- package/lib/loggable.js +0 -36
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drunkcod/express-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"description": "Express4 utility things",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"clean": "rimraf lib",
|
|
14
14
|
"compile": "tsc",
|
|
15
|
-
"test": "jest",
|
|
15
|
+
"test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest",
|
|
16
|
+
"test:all": "npm-run-all \"test --workspaces --include-workspace-root\" --silent",
|
|
16
17
|
"build": "npm-run-all clean compile --silent"
|
|
17
18
|
},
|
|
18
19
|
"keywords": [
|
|
@@ -24,16 +25,17 @@
|
|
|
24
25
|
"express-async"
|
|
25
26
|
],
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@drunkcod/argis": "^0.0.
|
|
28
|
+
"@drunkcod/argis": "^0.0.5",
|
|
28
29
|
"@drunkcod/express-async": "^0.0.7"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
32
|
+
"@drunkcod/ts-jest-esm": "^0.0.1",
|
|
31
33
|
"@jest/globals": "^29.7.0",
|
|
32
|
-
"@types/node": "^22.
|
|
34
|
+
"@types/node": "^22.8.1",
|
|
33
35
|
"jest": "^29.7.0",
|
|
34
36
|
"npm-run-all": "^4.1.5",
|
|
35
37
|
"rimraf": "^6.0.1",
|
|
36
38
|
"ts-jest": "^29.2.5",
|
|
37
|
-
"typescript": "^5.6.
|
|
39
|
+
"typescript": "^5.6.3"
|
|
38
40
|
}
|
|
39
41
|
}
|
package/lib/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type express from 'express';
|
|
2
|
-
export * from '@drunkcod/express-async';
|
|
3
|
-
export * from './loggable.js';
|
|
4
|
-
type AsyncFn<T> = () => Promise<T>;
|
|
5
|
-
export declare function onceAsync<T>(fn: AsyncFn<T>): AsyncFn<T>;
|
|
6
|
-
export declare function mergeCallsAsync<T>(fn: AsyncFn<T>): AsyncFn<T>;
|
|
7
|
-
type ExpressServer = ReturnType<express.Application['listen']>;
|
|
8
|
-
export declare function registerShutdown<Server extends ExpressServer = ExpressServer>(server: Server, shutdown?: () => Promise<void>): void;
|
package/lib/index.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export * from '@drunkcod/express-async';
|
|
2
|
-
export * from './loggable.js';
|
|
3
|
-
export function onceAsync(fn) {
|
|
4
|
-
let p;
|
|
5
|
-
return () => {
|
|
6
|
-
if (p)
|
|
7
|
-
return p;
|
|
8
|
-
p = fn();
|
|
9
|
-
fn = () => p;
|
|
10
|
-
return p;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export function mergeCallsAsync(fn) {
|
|
14
|
-
let p;
|
|
15
|
-
return async () => {
|
|
16
|
-
if (!p)
|
|
17
|
-
p = fn();
|
|
18
|
-
try {
|
|
19
|
-
return await p;
|
|
20
|
-
}
|
|
21
|
-
finally {
|
|
22
|
-
p = null;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
const closeAsync = (server) => (new Promise((resolve, reject) => {
|
|
27
|
-
server.close((err) => {
|
|
28
|
-
if (err)
|
|
29
|
-
reject(err);
|
|
30
|
-
else
|
|
31
|
-
resolve();
|
|
32
|
-
});
|
|
33
|
-
}));
|
|
34
|
-
export function registerShutdown(server, shutdown) {
|
|
35
|
-
const onShutdown = onceAsync(async () => {
|
|
36
|
-
await closeAsync(server);
|
|
37
|
-
if (shutdown)
|
|
38
|
-
await shutdown();
|
|
39
|
-
});
|
|
40
|
-
process.on('SIGINT', onShutdown);
|
|
41
|
-
process.on('SIGTERM', onShutdown);
|
|
42
|
-
}
|
package/lib/loggable.d.ts
DELETED
package/lib/loggable.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { hasOwn } from "@drunkcod/argis";
|
|
2
|
-
export function at(message) {
|
|
3
|
-
const old = Error.stackTraceLimit;
|
|
4
|
-
try {
|
|
5
|
-
const r = { stack: '' };
|
|
6
|
-
Error.stackTraceLimit = 1;
|
|
7
|
-
Error.captureStackTrace(r, at);
|
|
8
|
-
message = message ? `${message} ` : '';
|
|
9
|
-
return message + r.stack.substring(10);
|
|
10
|
-
}
|
|
11
|
-
finally {
|
|
12
|
-
Error.stackTraceLimit = old;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function asLoggableCause(cause) {
|
|
16
|
-
if (cause == null || typeof cause !== 'object')
|
|
17
|
-
return cause;
|
|
18
|
-
if (cause instanceof Error) {
|
|
19
|
-
const { message, stack, cause: innerCause, ...rest } = cause;
|
|
20
|
-
return innerCause
|
|
21
|
-
? { message, stack, cause: asLoggableCause(innerCause), ...rest }
|
|
22
|
-
: { message, stack, ...rest };
|
|
23
|
-
}
|
|
24
|
-
if (hasOwn(cause, 'cause')) {
|
|
25
|
-
const { cause: innerCause, ...rest } = cause;
|
|
26
|
-
return { ...rest, cause: asLoggableCause(innerCause) };
|
|
27
|
-
}
|
|
28
|
-
return { ...cause };
|
|
29
|
-
}
|
|
30
|
-
export function asLoggableError(error) {
|
|
31
|
-
if (error instanceof Error)
|
|
32
|
-
return asLoggableCause(error);
|
|
33
|
-
const r = (error && typeof error === 'object') ? asLoggableCause(error) : { message: error };
|
|
34
|
-
Error.captureStackTrace(r, asLoggableError);
|
|
35
|
-
return Object.defineProperty(r, 'stack', { enumerable: true });
|
|
36
|
-
}
|