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