@bgord/bun 0.4.0 → 0.5.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.
Files changed (77) hide show
  1. package/dist/api-key-shield.d.ts +14 -13
  2. package/dist/api-key-shield.d.ts.map +1 -0
  3. package/dist/api-key-shield.js +19 -0
  4. package/dist/api-key-shield.js.map +1 -0
  5. package/dist/api-version.d.ts +6 -5
  6. package/dist/api-version.d.ts.map +1 -0
  7. package/dist/api-version.js +12 -0
  8. package/dist/api-version.js.map +1 -0
  9. package/dist/auth-shield.d.ts +30 -29
  10. package/dist/auth-shield.d.ts.map +1 -0
  11. package/dist/auth-shield.js +90 -0
  12. package/dist/auth-shield.js.map +1 -0
  13. package/dist/cache-response.d.ts +13 -12
  14. package/dist/cache-response.d.ts.map +1 -0
  15. package/dist/cache-response.js +29 -0
  16. package/dist/cache-response.js.map +1 -0
  17. package/dist/cache-static-files.d.ts +9 -8
  18. package/dist/cache-static-files.d.ts.map +1 -0
  19. package/dist/cache-static-files.js +25 -0
  20. package/dist/cache-static-files.js.map +1 -0
  21. package/dist/context.d.ts +10 -9
  22. package/dist/context.d.ts.map +1 -0
  23. package/dist/context.js +11 -0
  24. package/dist/context.js.map +1 -0
  25. package/dist/download-file.d.ts +12 -12
  26. package/dist/download-file.d.ts.map +1 -0
  27. package/dist/download-file.js +11 -0
  28. package/dist/download-file.js.map +1 -0
  29. package/dist/etag-extractor.d.ts +16 -15
  30. package/dist/etag-extractor.d.ts.map +1 -0
  31. package/dist/etag-extractor.js +33 -0
  32. package/dist/etag-extractor.js.map +1 -0
  33. package/dist/file-uploader.d.ts +13 -12
  34. package/dist/file-uploader.d.ts.map +1 -0
  35. package/dist/file-uploader.js +35 -0
  36. package/dist/file-uploader.js.map +1 -0
  37. package/dist/graceful-shutdown.d.ts +7 -6
  38. package/dist/graceful-shutdown.d.ts.map +1 -0
  39. package/dist/graceful-shutdown.js +32 -0
  40. package/dist/graceful-shutdown.js.map +1 -0
  41. package/dist/healthcheck.d.ts +21 -20
  42. package/dist/healthcheck.d.ts.map +1 -0
  43. package/dist/healthcheck.js +31 -0
  44. package/dist/healthcheck.js.map +1 -0
  45. package/dist/http-logger.d.ts +7 -7
  46. package/dist/http-logger.d.ts.map +1 -0
  47. package/dist/http-logger.js +88 -0
  48. package/dist/http-logger.js.map +1 -0
  49. package/dist/i18n.d.ts +27 -26
  50. package/dist/i18n.d.ts.map +1 -0
  51. package/dist/i18n.js +50 -0
  52. package/dist/i18n.js.map +1 -0
  53. package/dist/image-processor.d.ts +5 -4
  54. package/dist/image-processor.d.ts.map +1 -0
  55. package/dist/image-processor.js +5 -0
  56. package/dist/image-processor.js.map +1 -0
  57. package/dist/index.d.ts +18 -17
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +18 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/rate-limit-shield.d.ts +9 -8
  62. package/dist/rate-limit-shield.d.ts.map +1 -0
  63. package/dist/rate-limit-shield.js +18 -0
  64. package/dist/rate-limit-shield.js.map +1 -0
  65. package/dist/setup.d.ts +8 -7
  66. package/dist/setup.d.ts.map +1 -0
  67. package/dist/setup.js +34 -0
  68. package/dist/setup.js.map +1 -0
  69. package/dist/time-zone-offset.d.ts +15 -14
  70. package/dist/time-zone-offset.d.ts.map +1 -0
  71. package/dist/time-zone-offset.js +22 -0
  72. package/dist/time-zone-offset.js.map +1 -0
  73. package/dist/tsconfig.tsbuildinfo +1 -0
  74. package/package.json +10 -16
  75. package/src/http-logger.ts +1 -1
  76. package/src/i18n.ts +2 -1
  77. package/src/setup.ts +2 -1
@@ -1,13 +1,14 @@
1
- import * as bg from "@bgord/node";
2
- import { HTTPException } from "hono/http-exception";
3
- declare type ApiKeyShieldConfigType = {
4
- API_KEY: bg.Schema.ApiKeyType;
5
- };
6
- export declare const AccessDeniedApiKeyError: HTTPException;
7
- export declare class ApiKeyShield {
8
- private readonly config;
9
- static readonly HEADER_NAME = "bgord-api-key";
10
- constructor(config: ApiKeyShieldConfigType);
11
- verify: import("hono").MiddlewareHandler<any, string, {}>;
12
- }
13
- export {};
1
+ import * as bg from "@bgord/node";
2
+ import { HTTPException } from "hono/http-exception";
3
+ type ApiKeyShieldConfigType = {
4
+ API_KEY: bg.Schema.ApiKeyType;
5
+ };
6
+ export declare const AccessDeniedApiKeyError: HTTPException;
7
+ export declare class ApiKeyShield {
8
+ private readonly config;
9
+ static readonly HEADER_NAME = "bgord-api-key";
10
+ constructor(config: ApiKeyShieldConfigType);
11
+ verify: import("hono").MiddlewareHandler<any, string, {}>;
12
+ }
13
+ export {};
14
+ //# sourceMappingURL=api-key-shield.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-key-shield.d.ts","sourceRoot":"","sources":["../src/api-key-shield.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,KAAK,sBAAsB,GAAG;IAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAA;CAAE,CAAC;AAEhE,eAAO,MAAM,uBAAuB,eAElC,CAAC;AAEH,qBAAa,YAAY;IAGX,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,MAAM,CAAC,QAAQ,CAAC,WAAW,mBAAmB;gBAEjB,MAAM,EAAE,sBAAsB;IAE3D,MAAM,oDAMH;CACJ"}
@@ -0,0 +1,19 @@
1
+ import { createMiddleware } from "hono/factory";
2
+ import { HTTPException } from "hono/http-exception";
3
+ export const AccessDeniedApiKeyError = new HTTPException(403, {
4
+ message: "access_denied_api_key",
5
+ });
6
+ export class ApiKeyShield {
7
+ config;
8
+ static HEADER_NAME = "bgord-api-key";
9
+ constructor(config) {
10
+ this.config = config;
11
+ }
12
+ verify = createMiddleware(async (c, next) => {
13
+ if (c.req.header(ApiKeyShield.HEADER_NAME) === this.config.API_KEY) {
14
+ return next();
15
+ }
16
+ throw AccessDeniedApiKeyError;
17
+ });
18
+ }
19
+ //# sourceMappingURL=api-key-shield.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-key-shield.js","sourceRoot":"","sources":["../src/api-key-shield.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,aAAa,CAAC,GAAG,EAAE;IAC5D,OAAO,EAAE,uBAAuB;CACjC,CAAC,CAAC;AAEH,MAAM,OAAO,YAAY;IAGM;IAF7B,MAAM,CAAU,WAAW,GAAG,eAAe,CAAC;IAE9C,YAA6B,MAA8B;QAA9B,WAAM,GAAN,MAAM,CAAwB;IAAG,CAAC;IAE/D,MAAM,GAAG,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QAC1C,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACnE,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAED,MAAM,uBAAuB,CAAC;IAChC,CAAC,CAAC,CAAC"}
@@ -1,5 +1,6 @@
1
- export declare class ApiVersion {
2
- static HEADER_NAME: string;
3
- static DEFAULT_API_VERSION: string;
4
- static attach: import("hono").MiddlewareHandler<any, string, {}>;
5
- }
1
+ export declare class ApiVersion {
2
+ static HEADER_NAME: string;
3
+ static DEFAULT_API_VERSION: string;
4
+ static attach: import("hono").MiddlewareHandler<any, string, {}>;
5
+ }
6
+ //# sourceMappingURL=api-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-version.d.ts","sourceRoot":"","sources":["../src/api-version.ts"],"names":[],"mappings":"AAGA,qBAAa,UAAU;IACrB,MAAM,CAAC,WAAW,SAAiB;IAEnC,MAAM,CAAC,mBAAmB,SAAa;IAEvC,MAAM,CAAC,MAAM,oDAMV;CACJ"}
@@ -0,0 +1,12 @@
1
+ import * as bg from "@bgord/node";
2
+ import { createMiddleware } from "hono/factory";
3
+ export class ApiVersion {
4
+ static HEADER_NAME = "api-version";
5
+ static DEFAULT_API_VERSION = "unknown";
6
+ static attach = createMiddleware(async (c, next) => {
7
+ const build = await bg.BuildInfoRepository.extract();
8
+ c.res.headers.set(ApiVersion.HEADER_NAME, build.BUILD_VERSION ?? ApiVersion.DEFAULT_API_VERSION);
9
+ await next();
10
+ });
11
+ }
12
+ //# sourceMappingURL=api-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-version.js","sourceRoot":"","sources":["../src/api-version.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,OAAO,UAAU;IACrB,MAAM,CAAC,WAAW,GAAG,aAAa,CAAC;IAEnC,MAAM,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAEvC,MAAM,CAAC,MAAM,GAAG,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QACjD,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;QAErD,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC,aAAa,IAAI,UAAU,CAAC,mBAAmB,CAAC,CAAC;QAEjG,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC,CAAC"}
@@ -1,29 +1,30 @@
1
- import * as bgn from "@bgord/node";
2
- import hono from "hono";
3
- import { HTTPException } from "hono/http-exception";
4
- import { Lucia } from "lucia";
5
- declare type AuthShieldConfigType<T> = {
6
- Username: typeof bgn.Username;
7
- Password: typeof bgn.Password;
8
- HashedPassword: typeof bgn.HashedPassword;
9
- lucia: Lucia;
10
- findUniqueUserOrThrow: (username: bgn.Username) => Promise<T>;
11
- };
12
- export declare const AccessDeniedAuthShieldError: HTTPException;
13
- export declare class AuthShield<T extends {
14
- password: bgn.PasswordType;
15
- id: bgn.IdType;
16
- }> {
17
- private readonly config;
18
- constructor(overrides: Omit<AuthShieldConfigType<T>, "Username" | "Password" | "HashedPassword"> & {
19
- Username?: typeof bgn.Username;
20
- Password?: typeof bgn.Password;
21
- HashedPassword?: typeof bgn.HashedPassword;
22
- });
23
- verify: hono.MiddlewareHandler<any, any, {}>;
24
- reverse: hono.MiddlewareHandler<any, any, {}>;
25
- detach: hono.MiddlewareHandler<any, any, {}>;
26
- build: hono.MiddlewareHandler<any, any, {}>;
27
- attach: hono.MiddlewareHandler<any, any, {}>;
28
- }
29
- export {};
1
+ import * as bgn from "@bgord/node";
2
+ import hono from "hono";
3
+ import { HTTPException } from "hono/http-exception";
4
+ import { Lucia } from "lucia";
5
+ type AuthShieldConfigType<T> = {
6
+ Username: typeof bgn.Username;
7
+ Password: typeof bgn.Password;
8
+ HashedPassword: typeof bgn.HashedPassword;
9
+ lucia: Lucia;
10
+ findUniqueUserOrThrow: (username: bgn.Username) => Promise<T>;
11
+ };
12
+ export declare const AccessDeniedAuthShieldError: HTTPException;
13
+ export declare class AuthShield<T extends {
14
+ password: bgn.PasswordType;
15
+ id: bgn.IdType;
16
+ }> {
17
+ private readonly config;
18
+ constructor(overrides: Omit<AuthShieldConfigType<T>, "Username" | "Password" | "HashedPassword"> & {
19
+ Username?: typeof bgn.Username;
20
+ Password?: typeof bgn.Password;
21
+ HashedPassword?: typeof bgn.HashedPassword;
22
+ });
23
+ verify: hono.MiddlewareHandler<any, any, {}>;
24
+ reverse: hono.MiddlewareHandler<any, any, {}>;
25
+ detach: hono.MiddlewareHandler<any, any, {}>;
26
+ build: hono.MiddlewareHandler<any, any, {}>;
27
+ attach: hono.MiddlewareHandler<any, any, {}>;
28
+ }
29
+ export {};
30
+ //# sourceMappingURL=auth-shield.d.ts.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+ import * as bgn from "@bgord/node";
2
+ import { createMiddleware } from "hono/factory";
3
+ import { HTTPException } from "hono/http-exception";
4
+ class SessionId {
5
+ value;
6
+ constructor(cookie, lucia) {
7
+ this.value = lucia.readSessionCookie(cookie ?? "");
8
+ }
9
+ get() {
10
+ return this.value;
11
+ }
12
+ }
13
+ export const AccessDeniedAuthShieldError = new HTTPException(403, {
14
+ message: "access_denied_auth_shield",
15
+ });
16
+ export class AuthShield {
17
+ config;
18
+ constructor(overrides) {
19
+ const config = {
20
+ Username: overrides.Username ?? bgn.Username,
21
+ Password: overrides.Password ?? bgn.Password,
22
+ HashedPassword: overrides.HashedPassword ?? bgn.HashedPassword,
23
+ lucia: overrides.lucia,
24
+ findUniqueUserOrThrow: overrides.findUniqueUserOrThrow,
25
+ };
26
+ this.config = config;
27
+ }
28
+ verify = createMiddleware(async (c, next) => {
29
+ const user = c.get("user");
30
+ if (!user) {
31
+ throw AccessDeniedAuthShieldError;
32
+ }
33
+ return next();
34
+ });
35
+ reverse = createMiddleware(async (c, next) => {
36
+ const user = c.get("user");
37
+ if (user) {
38
+ throw AccessDeniedAuthShieldError;
39
+ }
40
+ return next();
41
+ });
42
+ detach = createMiddleware(async (c, next) => {
43
+ const cookie = c.req.header("cookie");
44
+ const sessionId = new SessionId(cookie, this.config.lucia).get();
45
+ if (!sessionId)
46
+ return next();
47
+ await this.config.lucia.invalidateSession(sessionId);
48
+ return next();
49
+ });
50
+ build = createMiddleware(async (c, next) => {
51
+ const cookie = c.req.header("cookie");
52
+ const sessionId = new SessionId(cookie, this.config.lucia).get();
53
+ if (!sessionId) {
54
+ c.set("user", null);
55
+ c.set("session", null);
56
+ return next();
57
+ }
58
+ const { session, user } = await this.config.lucia.validateSession(sessionId);
59
+ if (!session) {
60
+ c.res.headers.set("Set-Cookie", this.config.lucia.createBlankSessionCookie().serialize());
61
+ c.set("user", null);
62
+ c.set("session", null);
63
+ return next();
64
+ }
65
+ if (session.fresh) {
66
+ c.res.headers.set("Set-Cookie", this.config.lucia.createSessionCookie(session.id).serialize());
67
+ }
68
+ c.set("user", user);
69
+ c.set("session", session);
70
+ return next();
71
+ });
72
+ attach = createMiddleware(async (c, next) => {
73
+ try {
74
+ const body = await c.req.raw.clone().formData();
75
+ const username = new this.config.Username(body.get("username"));
76
+ const password = new this.config.Password(body.get("password"));
77
+ const user = await this.config.findUniqueUserOrThrow(username);
78
+ const hashedPassword = await this.config.HashedPassword.fromHash(user.password);
79
+ await hashedPassword.matchesOrThrow(password);
80
+ const session = await this.config.lucia.createSession(user.id, {});
81
+ const sessionCookie = this.config.lucia.createSessionCookie(session.id);
82
+ c.res.headers.set("Set-Cookie", sessionCookie.serialize());
83
+ return next();
84
+ }
85
+ catch (error) {
86
+ throw AccessDeniedAuthShieldError;
87
+ }
88
+ });
89
+ }
90
+ //# sourceMappingURL=auth-shield.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-shield.js","sourceRoot":"","sources":["../src/auth-shield.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,MAAM,SAAS;IACL,KAAK,CAAgB;IAE7B,YAAY,MAA0B,EAAE,KAAY;QAClD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,iBAAiB,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,GAAG;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AAUD,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,aAAa,CAAC,GAAG,EAAE;IAChE,OAAO,EAAE,2BAA2B;CACrC,CAAC,CAAC;AAEH,MAAM,OAAO,UAAU;IACJ,MAAM,CAA0B;IAEjD,YACE,SAIC;QAED,MAAM,MAAM,GAAG;YACb,QAAQ,EAAE,SAAS,CAAC,QAAQ,IAA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AE,CAAC;YACf,MAAM,2BAA2B,CAAC;QACpC,CAAC;IACH,CAAC,CAAC,CAAC;CACJ"}
@@ -1,12 +1,13 @@
1
- import NodeCache from "node-cache";
2
- export declare enum CacheHitEnum {
3
- hit = "hit",
4
- miss = "miss"
5
- }
6
- export declare class CacheResponse {
7
- private readonly cache;
8
- static readonly CACHE_HIT_HEADER = "Cache-Hit";
9
- constructor(cache: NodeCache);
10
- handle: import("hono").MiddlewareHandler<any, string, {}>;
11
- clear: import("hono").MiddlewareHandler<any, string, {}>;
12
- }
1
+ import NodeCache from "node-cache";
2
+ export declare enum CacheHitEnum {
3
+ hit = "hit",
4
+ miss = "miss"
5
+ }
6
+ export declare class CacheResponse {
7
+ private readonly cache;
8
+ static readonly CACHE_HIT_HEADER = "Cache-Hit";
9
+ constructor(cache: NodeCache);
10
+ handle: import("hono").MiddlewareHandler<any, string, {}>;
11
+ clear: import("hono").MiddlewareHandler<any, string, {}>;
12
+ }
13
+ //# sourceMappingURL=cache-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-response.d.ts","sourceRoot":"","sources":["../src/cache-response.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,oBAAY,YAAY;IACtB,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AAED,qBAAa,aAAa;IAGZ,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,eAAe;gBAElB,KAAK,EAAE,SAAS;IAE7C,MAAM,oDAaH;IAEH,KAAK,oDAIF;CACJ"}
@@ -0,0 +1,29 @@
1
+ import { createMiddleware } from "hono/factory";
2
+ import _ from "lodash";
3
+ export var CacheHitEnum;
4
+ (function (CacheHitEnum) {
5
+ CacheHitEnum["hit"] = "hit";
6
+ CacheHitEnum["miss"] = "miss";
7
+ })(CacheHitEnum || (CacheHitEnum = {}));
8
+ export class CacheResponse {
9
+ cache;
10
+ static CACHE_HIT_HEADER = "Cache-Hit";
11
+ constructor(cache) {
12
+ this.cache = cache;
13
+ }
14
+ handle = createMiddleware(async (c, next) => {
15
+ const url = _.escape(c.req.url);
16
+ if (this.cache.has(url)) {
17
+ c.res.headers.set(CacheResponse.CACHE_HIT_HEADER, CacheHitEnum.hit);
18
+ // @ts-ignore
19
+ return c.json(this.cache.get(url));
20
+ }
21
+ c.res.headers.set(CacheResponse.CACHE_HIT_HEADER, CacheHitEnum.miss);
22
+ return next();
23
+ });
24
+ clear = createMiddleware(async (_c, next) => {
25
+ this.cache.flushAll();
26
+ return next();
27
+ });
28
+ }
29
+ //# sourceMappingURL=cache-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-response.js","sourceRoot":"","sources":["../src/cache-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,CAAC,MAAM,QAAQ,CAAC;AAGvB,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,2BAAW,CAAA;IACX,6BAAa,CAAA;AACf,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AAED,MAAM,OAAO,aAAa;IAGK;IAF7B,MAAM,CAAU,gBAAgB,GAAG,WAAW,CAAC;IAE/C,YAA6B,KAAgB;QAAhB,UAAK,GAAL,KAAK,CAAW;IAAG,CAAC;IAEjD,MAAM,GAAG,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QAC1C,MAAM,GAAG,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEhC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,gBAAgB,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;YAEpE,aAAa;YACb,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC;QAED,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,gBAAgB,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;QAErE,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,KAAK,GAAG,gBAAgB,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE;QAC1C,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAEtB,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC,CAAC"}
@@ -1,8 +1,9 @@
1
- export declare enum CacheStaticFilesStrategy {
2
- never = "never",
3
- always = "always",
4
- five_minutes = "five_minutes"
5
- }
6
- export declare class CacheStaticFiles {
7
- static handle(strategy: CacheStaticFilesStrategy): import("hono").MiddlewareHandler<any, string, {}>;
8
- }
1
+ export declare enum CacheStaticFilesStrategy {
2
+ never = "never",
3
+ always = "always",
4
+ five_minutes = "five_minutes"
5
+ }
6
+ export declare class CacheStaticFiles {
7
+ static handle(strategy: CacheStaticFilesStrategy): import("hono").MiddlewareHandler<any, string, {}>;
8
+ }
9
+ //# sourceMappingURL=cache-static-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-static-files.d.ts","sourceRoot":"","sources":["../src/cache-static-files.ts"],"names":[],"mappings":"AAGA,oBAAY,wBAAwB;IAClC,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,YAAY,iBAAiB;CAC9B;AAED,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,wBAAwB;CAcjD"}
@@ -0,0 +1,25 @@
1
+ import * as bg from "@bgord/node";
2
+ import { createMiddleware } from "hono/factory";
3
+ export var CacheStaticFilesStrategy;
4
+ (function (CacheStaticFilesStrategy) {
5
+ CacheStaticFilesStrategy["never"] = "never";
6
+ CacheStaticFilesStrategy["always"] = "always";
7
+ CacheStaticFilesStrategy["five_minutes"] = "five_minutes";
8
+ })(CacheStaticFilesStrategy || (CacheStaticFilesStrategy = {}));
9
+ export class CacheStaticFiles {
10
+ static handle(strategy) {
11
+ return createMiddleware(async (c, next) => {
12
+ if (strategy === CacheStaticFilesStrategy.never) {
13
+ c.res.headers.set("cache-control", "private, no-cache, no-store, must-revalidate");
14
+ }
15
+ if (strategy === CacheStaticFilesStrategy.always) {
16
+ c.res.headers.set("cache-control", `public, max-age=${bg.Time.Days(365).seconds}, immutable`);
17
+ }
18
+ if (strategy === CacheStaticFilesStrategy.five_minutes) {
19
+ c.res.headers.set("cache-control", `public, max-age=${bg.Time.Minutes(5).seconds}`);
20
+ }
21
+ return next();
22
+ });
23
+ }
24
+ }
25
+ //# sourceMappingURL=cache-static-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache-static-files.js","sourceRoot":"","sources":["../src/cache-static-files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,CAAN,IAAY,wBAIX;AAJD,WAAY,wBAAwB;IAClC,2CAAe,CAAA;IACf,6CAAiB,CAAA;IACjB,yDAA6B,CAAA;AAC/B,CAAC,EAJW,wBAAwB,KAAxB,wBAAwB,QAInC;AAED,MAAM,OAAO,gBAAgB;IAC3B,MAAM,CAAC,MAAM,CAAC,QAAkC;QAC9C,OAAO,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;YACxC,IAAI,QAAQ,KAAK,wBAAwB,CAAC,KAAK,EAAE,CAAC;gBAChD,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,8CAA8C,CAAC,CAAC;YACrF,CAAC;YACD,IAAI,QAAQ,KAAK,wBAAwB,CAAC,MAAM,EAAE,CAAC;gBACjD,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,mBAAmB,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,aAAa,CAAC,CAAC;YAChG,CAAC;YACD,IAAI,QAAQ,KAAK,wBAAwB,CAAC,YAAY,EAAE,CAAC;gBACvD,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,mBAAmB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACtF,CAAC;YACD,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
package/dist/context.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import * as bg from "@bgord/node";
2
- import { TimeZoneOffsetVariables } from "./time-zone-offset";
3
- export declare type ContextVariables = {
4
- context: bg.ContextType;
5
- requestId: string;
6
- } & TimeZoneOffsetVariables;
7
- export declare class Context {
8
- static attach: import("hono").MiddlewareHandler<any, string, {}>;
9
- }
1
+ import * as bg from "@bgord/node";
2
+ import { TimeZoneOffsetVariables } from "./time-zone-offset";
3
+ export type ContextVariables = {
4
+ context: bg.ContextType;
5
+ requestId: string;
6
+ } & TimeZoneOffsetVariables;
7
+ export declare class Context {
8
+ static attach: import("hono").MiddlewareHandler<any, string, {}>;
9
+ }
10
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,uBAAuB,CAAC;AAE5B,qBAAa,OAAO;IAClB,MAAM,CAAC,MAAM,oDAOV;CACJ"}
@@ -0,0 +1,11 @@
1
+ import { createMiddleware } from "hono/factory";
2
+ export class Context {
3
+ static attach = createMiddleware(async (c, next) => {
4
+ c.set("context", {
5
+ requestId: c.get("requestId"),
6
+ timeZoneOffset: c.get("timeZoneOffset"),
7
+ });
8
+ await next();
9
+ });
10
+ }
11
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAShD,MAAM,OAAO,OAAO;IAClB,MAAM,CAAC,MAAM,GAAG,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QACjD,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE;YACf,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAgC;YAC5D,cAAc,EAAE,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC;SACxC,CAAC,CAAC;QAEH,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC,CAAC"}
@@ -1,12 +1,12 @@
1
- /// <reference types="node" />
2
- import type { PathLike } from "node:fs";
3
- import * as bgn from "@bgord/node";
4
- export declare type DownloadFileConfigType = {
5
- filename: PathLike;
6
- mime: bgn.Mime;
7
- };
8
- export declare class DownloadFile {
9
- static attach(config: DownloadFileConfigType): {
10
- headers: Headers;
11
- };
12
- }
1
+ import type { PathLike } from "node:fs";
2
+ import * as bgn from "@bgord/node";
3
+ export type DownloadFileConfigType = {
4
+ filename: PathLike;
5
+ mime: bgn.Mime;
6
+ };
7
+ export declare class DownloadFile {
8
+ static attach(config: DownloadFileConfigType): {
9
+ headers: import("undici-types").Headers;
10
+ };
11
+ }
12
+ //# sourceMappingURL=download-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download-file.d.ts","sourceRoot":"","sources":["../src/download-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC,MAAM,MAAM,sBAAsB,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAA;CAAE,CAAC;AAE5E,qBAAa,YAAY;IACvB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB;;;CAQ7C"}
@@ -0,0 +1,11 @@
1
+ export class DownloadFile {
2
+ static attach(config) {
3
+ return {
4
+ headers: new Headers({
5
+ "Content-Disposition": `attachment; filename="${config.filename}"`,
6
+ "Content-Type": config.mime.raw,
7
+ }),
8
+ };
9
+ }
10
+ }
11
+ //# sourceMappingURL=download-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download-file.js","sourceRoot":"","sources":["../src/download-file.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,MAAM,CAAC,MAA8B;QAC1C,OAAO;YACL,OAAO,EAAE,IAAI,OAAO,CAAC;gBACnB,qBAAqB,EAAE,yBAAyB,MAAM,CAAC,QAAQ,GAAG;gBAClE,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG;aAChC,CAAC;SACH,CAAC;IACJ,CAAC;CACF"}
@@ -1,15 +1,16 @@
1
- import * as bg from "@bgord/node";
2
- export declare type EtagVariables = {
3
- ETag: bg.ETag | null;
4
- WeakETag: bg.WeakETag | null;
5
- };
6
- export declare class ETagExtractor {
7
- static attach: import("hono").MiddlewareHandler<{
8
- Variables: EtagVariables;
9
- }, string, {}>;
10
- }
11
- export declare class WeakETagExtractor {
12
- static attach: import("hono").MiddlewareHandler<{
13
- Variables: EtagVariables;
14
- }, string, {}>;
15
- }
1
+ import * as bg from "@bgord/node";
2
+ export type EtagVariables = {
3
+ ETag: bg.ETag | null;
4
+ WeakETag: bg.WeakETag | null;
5
+ };
6
+ export declare class ETagExtractor {
7
+ static attach: import("hono").MiddlewareHandler<{
8
+ Variables: EtagVariables;
9
+ }, string, {}>;
10
+ }
11
+ export declare class WeakETagExtractor {
12
+ static attach: import("hono").MiddlewareHandler<{
13
+ Variables: EtagVariables;
14
+ }, string, {}>;
15
+ }
16
+ //# sourceMappingURL=etag-extractor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"etag-extractor.d.ts","sourceRoot":"","sources":["../src/etag-extractor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAGlC,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,EAAE,CAAC,QAAQ,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,qBAAa,aAAa;IACxB,MAAM,CAAC,MAAM;mBAAiC,aAAa;mBAWxD;CACJ;AAED,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,MAAM;mBAAiC,aAAa;mBAWxD;CACJ"}
@@ -0,0 +1,33 @@
1
+ import * as bg from "@bgord/node";
2
+ import { createMiddleware } from "hono/factory";
3
+ export class ETagExtractor {
4
+ static attach = createMiddleware(async (c, next) => {
5
+ try {
6
+ const header = String(c.req.header(bg.ETag.IF_MATCH_HEADER_NAME));
7
+ if (!header || header === "undefined")
8
+ c.set("ETag", null);
9
+ else
10
+ c.set("ETag", bg.ETag.fromHeader(header));
11
+ }
12
+ catch (error) {
13
+ c.set("ETag", null);
14
+ }
15
+ await next();
16
+ });
17
+ }
18
+ export class WeakETagExtractor {
19
+ static attach = createMiddleware(async (c, next) => {
20
+ try {
21
+ const header = String(c.req.header(bg.WeakETag.IF_MATCH_HEADER_NAME));
22
+ if (!header || header === "undefined")
23
+ c.set("WeakETag", null);
24
+ else
25
+ c.set("WeakETag", bg.WeakETag.fromHeader(header));
26
+ }
27
+ catch (error) {
28
+ c.set("WeakETag", null);
29
+ }
30
+ await next();
31
+ });
32
+ }
33
+ //# sourceMappingURL=etag-extractor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"etag-extractor.js","sourceRoot":"","sources":["../src/etag-extractor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAOhD,MAAM,OAAO,aAAa;IACxB,MAAM,CAAC,MAAM,GAAG,gBAAgB,CAA+B,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QAC/E,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;YAElE,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,WAAW;gBAAE,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;;gBACtD,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACtB,CAAC;QAED,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC,CAAC;;AAGL,MAAM,OAAO,iBAAiB;IAC5B,MAAM,CAAC,MAAM,GAAG,gBAAgB,CAA+B,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;QAC/E,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,CAAC;YAEtE,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,WAAW;gBAAE,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;;gBAC1D,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC1B,CAAC;QAED,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC,CAAC"}
@@ -1,12 +1,13 @@
1
- import * as bgn from "@bgord/node";
2
- import { HTTPException } from "hono/http-exception";
3
- export declare const InvalidFileMimeTypeError: HTTPException;
4
- export declare const FileTooBigError: HTTPException;
5
- declare type FileUploaderConfigType = {
6
- mimeTypes: string[];
7
- maxFilesSize: bgn.SizeValueType;
8
- };
9
- export declare class FileUploader {
10
- static validate(config: FileUploaderConfigType): import("hono").MiddlewareHandler<any, string, {}>[];
11
- }
12
- export {};
1
+ import * as bgn from "@bgord/node";
2
+ import { HTTPException } from "hono/http-exception";
3
+ export declare const InvalidFileMimeTypeError: HTTPException;
4
+ export declare const FileTooBigError: HTTPException;
5
+ type FileUploaderConfigType = {
6
+ mimeTypes: string[];
7
+ maxFilesSize: bgn.SizeValueType;
8
+ };
9
+ export declare class FileUploader {
10
+ static validate(config: FileUploaderConfigType): import("hono").MiddlewareHandler<any, string, {}>[];
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=file-uploader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-uploader.d.ts","sourceRoot":"","sources":["../src/file-uploader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAGnC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,eAAO,MAAM,wBAAwB,eAEnC,CAAC;AAEH,eAAO,MAAM,eAAe,eAE1B,CAAC;AAEH,KAAK,sBAAsB,GAAG;IAC5B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC,aAAa,CAAC;CACjC,CAAC;AAEF,qBAAa,YAAY;IACvB,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,sBAAsB;CA4B/C"}
@@ -0,0 +1,35 @@
1
+ import * as bgn from "@bgord/node";
2
+ import { bodyLimit } from "hono/body-limit";
3
+ import { createMiddleware } from "hono/factory";
4
+ import { HTTPException } from "hono/http-exception";
5
+ export const InvalidFileMimeTypeError = new HTTPException(400, {
6
+ message: "invalid_file_mime_type_error",
7
+ });
8
+ export const FileTooBigError = new HTTPException(400, {
9
+ message: "file_too_big_error",
10
+ });
11
+ export class FileUploader {
12
+ static validate(config) {
13
+ return [
14
+ bodyLimit({
15
+ maxSize: config.maxFilesSize,
16
+ onError: () => {
17
+ throw FileTooBigError;
18
+ },
19
+ }),
20
+ createMiddleware(async (c, next) => {
21
+ const body = await c.req.raw.clone().formData();
22
+ const file = body.get("file");
23
+ if (!(file instanceof File)) {
24
+ throw InvalidFileMimeTypeError;
25
+ }
26
+ const contentType = new bgn.Mime(file.type);
27
+ const accepted = config.mimeTypes.some((acceptedMimeType) => new bgn.Mime(acceptedMimeType).isSatisfiedBy(contentType));
28
+ if (!accepted)
29
+ throw InvalidFileMimeTypeError;
30
+ return next();
31
+ }),
32
+ ];
33
+ }
34
+ }
35
+ //# sourceMappingURL=file-uploader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-uploader.js","sourceRoot":"","sources":["../src/file-uploader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,aAAa,CAAC,GAAG,EAAE;IAC7D,OAAO,EAAE,8BAA8B;CACxC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,aAAa,CAAC,GAAG,EAAE;IACpD,OAAO,EAAE,oBAAoB;CAC9B,CAAC,CAAC;AAOH,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,QAAQ,CAAC,MAA8B;QAC5C,OAAO;YACL,SAAS,CAAC;gBACR,OAAO,EAAE,MAAM,CAAC,YAAY;gBAC5B,OAAO,EAAE,GAAG,EAAE;oBACZ,MAAM,eAAe,CAAC;gBACxB,CAAC;aACF,CAAC;YAEF,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE;gBACjC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,CAAC;gBAEhD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBAE9B,IAAI,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC,EAAE,CAAC;oBAC5B,MAAM,wBAAwB,CAAC;gBACjC,CAAC;gBAED,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC5C,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,EAAE,CAC1D,IAAI,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,CAC1D,CAAC;gBAEF,IAAI,CAAC,QAAQ;oBAAE,MAAM,wBAAwB,CAAC;gBAC9C,OAAO,IAAI,EAAE,CAAC;YAChB,CAAC,CAAC;SACH,CAAC;IACJ,CAAC;CACF"}
@@ -1,6 +1,7 @@
1
- declare type ServerType = ReturnType<typeof Bun.serve>;
2
- export declare class GracefulShutdown {
3
- private static shutdown;
4
- static applyTo(server: ServerType, callback?: () => any): void;
5
- }
6
- export {};
1
+ type ServerType = ReturnType<typeof Bun.serve>;
2
+ export declare class GracefulShutdown {
3
+ private static shutdown;
4
+ static applyTo(server: ServerType, callback?: () => any): void;
5
+ }
6
+ export {};
7
+ //# sourceMappingURL=graceful-shutdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graceful-shutdown.d.ts","sourceRoot":"","sources":["../src/graceful-shutdown.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;AAE/C,qBAAa,gBAAgB;mBACN,QAAQ;IAO7B,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAE,MAAM,GAAa;CA0BjE"}