@drunkcod/express-kit 0.0.6 → 0.0.7

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/lib/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type express from 'express';
2
2
  export * from '@drunkcod/express-async';
3
- export * from './loggable';
4
- export declare function onceAsync<T>(fn: () => Promise<T>): () => Promise<T>;
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>;
5
7
  type ExpressServer = ReturnType<express.Application['listen']>;
6
8
  export declare function registerShutdown<Server extends ExpressServer = ExpressServer>(server: Server, shutdown?: () => Promise<void>): void;
package/lib/index.js CHANGED
@@ -1,24 +1,6 @@
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) {
1
+ export * from '@drunkcod/express-async';
2
+ export * from './loggable.js';
3
+ export function onceAsync(fn) {
22
4
  let p;
23
5
  return () => {
24
6
  if (p)
@@ -28,6 +10,19 @@ function onceAsync(fn) {
28
10
  return p;
29
11
  };
30
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
+ }
31
26
  const closeAsync = (server) => (new Promise((resolve, reject) => {
32
27
  server.close((err) => {
33
28
  if (err)
@@ -36,7 +31,7 @@ const closeAsync = (server) => (new Promise((resolve, reject) => {
36
31
  resolve();
37
32
  });
38
33
  }));
39
- function registerShutdown(server, shutdown) {
34
+ export function registerShutdown(server, shutdown) {
40
35
  const onShutdown = onceAsync(async () => {
41
36
  await closeAsync(server);
42
37
  if (shutdown)
package/lib/loggable.js CHANGED
@@ -1,9 +1,5 @@
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) {
1
+ import { hasOwn } from "@drunkcod/argis";
2
+ export function at(message) {
7
3
  const old = Error.stackTraceLimit;
8
4
  try {
9
5
  const r = { stack: '' };
@@ -25,13 +21,13 @@ function asLoggableCause(cause) {
25
21
  ? { message, stack, cause: asLoggableCause(innerCause), ...rest }
26
22
  : { message, stack, ...rest };
27
23
  }
28
- if ((0, argis_1.hasOwn)(cause, 'cause')) {
24
+ if (hasOwn(cause, 'cause')) {
29
25
  const { cause: innerCause, ...rest } = cause;
30
26
  return { ...rest, cause: asLoggableCause(innerCause) };
31
27
  }
32
28
  return { ...cause };
33
29
  }
34
- function asLoggableError(error) {
30
+ export function asLoggableError(error) {
35
31
  if (error instanceof Error)
36
32
  return asLoggableCause(error);
37
33
  const r = (error && typeof error === 'object') ? asLoggableCause(error) : { message: error };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@drunkcod/express-kit",
3
- "version": "0.0.6",
3
+ "type": "module",
4
+ "version": "0.0.7",
4
5
  "description": "Express4 utility things",
5
6
  "main": "lib/index.js",
6
7
  "types": "lib/index.d.ts",
@@ -10,28 +11,29 @@
10
11
  ],
11
12
  "scripts": {
12
13
  "clean": "rimraf lib",
13
- "compile": "npx tsc",
14
+ "compile": "tsc",
14
15
  "test": "jest",
15
- "build": "npm-run-all clean compile"
16
+ "build": "npm-run-all clean compile --silent"
16
17
  },
17
18
  "keywords": [
18
19
  "express"
19
20
  ],
20
- "author": "Tobbe Gyllebring",
21
+ "author": "Tobbe Gyllebring <tobbe@drunkcod.com>",
21
22
  "license": "MIT",
22
23
  "workspaces": [
23
24
  "express-async"
24
25
  ],
25
26
  "dependencies": {
26
- "@drunkcod/argis": "^0.0.4"
27
+ "@drunkcod/argis": "^0.0.4",
28
+ "@drunkcod/express-async": "^0.0.7"
27
29
  },
28
30
  "devDependencies": {
29
31
  "@jest/globals": "^29.7.0",
30
- "@types/node": "^22.5.4",
32
+ "@types/node": "^22.7.4",
31
33
  "jest": "^29.7.0",
32
34
  "npm-run-all": "^4.1.5",
33
35
  "rimraf": "^6.0.1",
34
36
  "ts-jest": "^29.2.5",
35
- "typescript": "^5.5.4"
37
+ "typescript": "^5.6.2"
36
38
  }
37
39
  }