hono-utils 0.3.2 → 0.3.3
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.cjs +8 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -2
- package/dist/index.d.ts +25 -2
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,7 @@ import { ContentfulStatusCode, SuccessStatusCode, ClientErrorStatusCode, StatusC
|
|
|
6
6
|
import z$1, { z, ZodObject } from 'zod';
|
|
7
7
|
import { Message, MessageBatch, Queue, Iso3166Alpha2Code, ContinentCode } from '@cloudflare/workers-types';
|
|
8
8
|
import * as hono_utils_types from 'hono/utils/types';
|
|
9
|
+
import { HTTPException } from 'hono/http-exception';
|
|
9
10
|
import { hc, ClientResponse } from 'hono/client';
|
|
10
11
|
|
|
11
12
|
type HonoLoggerVariables = {
|
|
@@ -283,7 +284,29 @@ declare const setResponseHandlers: (c: Context) => {
|
|
|
283
284
|
raw: <T extends {
|
|
284
285
|
status?: ContentfulStatusCode;
|
|
285
286
|
}>(data: T) => Response & hono.TypedResponse<hono_utils_types.JSONParsed<Omit<T, "status">, bigint | readonly bigint[]>, 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | -1, "json">;
|
|
286
|
-
success: <T extends object>(message: string, data
|
|
287
|
+
success: <T extends object>(message: string, data: T, status?: SuccessStatusCode) => Response & hono.TypedResponse<string | T extends bigint | readonly bigint[] ? never : { [K in keyof {
|
|
288
|
+
message: string;
|
|
289
|
+
data: T;
|
|
290
|
+
} as ({
|
|
291
|
+
message: string;
|
|
292
|
+
data: T;
|
|
293
|
+
}[K] extends infer T_1 ? T_1 extends {
|
|
294
|
+
message: string;
|
|
295
|
+
data: T;
|
|
296
|
+
}[K] ? T_1 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) extends true ? never : K]: boolean extends ({
|
|
297
|
+
message: string;
|
|
298
|
+
data: T;
|
|
299
|
+
}[K] extends infer T_2 ? T_2 extends {
|
|
300
|
+
message: string;
|
|
301
|
+
data: T;
|
|
302
|
+
}[K] ? T_2 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) ? hono_utils_types.JSONParsed<{
|
|
303
|
+
message: string;
|
|
304
|
+
data: T;
|
|
305
|
+
}[K], bigint | readonly bigint[]> | undefined : hono_utils_types.JSONParsed<{
|
|
306
|
+
message: string;
|
|
307
|
+
data: T;
|
|
308
|
+
}[K], bigint | readonly bigint[]>; }, 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | -1, "json">;
|
|
309
|
+
successNoContent: (message: string, status?: SuccessStatusCode) => Response & hono.TypedResponse<{
|
|
287
310
|
message: string;
|
|
288
311
|
}, 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | -1, "json">;
|
|
289
312
|
error: (message: string, status: ClientErrorStatusCode) => never;
|
|
@@ -459,7 +482,7 @@ declare namespace sha {
|
|
|
459
482
|
export { sha_generateSalt as generateSalt, sha_hash as hash };
|
|
460
483
|
}
|
|
461
484
|
|
|
462
|
-
declare const onError: <
|
|
485
|
+
declare const onError: <Environment extends Env>(parseError?: (err: Error | HTTPException, env: Environment["Bindings"], get: <K extends keyof Environment["Variables"]>(key: K) => Environment["Variables"][K]) => Promise<string>) => ErrorHandler<Environment>;
|
|
463
486
|
|
|
464
487
|
declare const onNotFound: NotFoundHandler;
|
|
465
488
|
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { ContentfulStatusCode, SuccessStatusCode, ClientErrorStatusCode, StatusC
|
|
|
6
6
|
import z$1, { z, ZodObject } from 'zod';
|
|
7
7
|
import { Message, MessageBatch, Queue, Iso3166Alpha2Code, ContinentCode } from '@cloudflare/workers-types';
|
|
8
8
|
import * as hono_utils_types from 'hono/utils/types';
|
|
9
|
+
import { HTTPException } from 'hono/http-exception';
|
|
9
10
|
import { hc, ClientResponse } from 'hono/client';
|
|
10
11
|
|
|
11
12
|
type HonoLoggerVariables = {
|
|
@@ -283,7 +284,29 @@ declare const setResponseHandlers: (c: Context) => {
|
|
|
283
284
|
raw: <T extends {
|
|
284
285
|
status?: ContentfulStatusCode;
|
|
285
286
|
}>(data: T) => Response & hono.TypedResponse<hono_utils_types.JSONParsed<Omit<T, "status">, bigint | readonly bigint[]>, 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | -1, "json">;
|
|
286
|
-
success: <T extends object>(message: string, data
|
|
287
|
+
success: <T extends object>(message: string, data: T, status?: SuccessStatusCode) => Response & hono.TypedResponse<string | T extends bigint | readonly bigint[] ? never : { [K in keyof {
|
|
288
|
+
message: string;
|
|
289
|
+
data: T;
|
|
290
|
+
} as ({
|
|
291
|
+
message: string;
|
|
292
|
+
data: T;
|
|
293
|
+
}[K] extends infer T_1 ? T_1 extends {
|
|
294
|
+
message: string;
|
|
295
|
+
data: T;
|
|
296
|
+
}[K] ? T_1 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) extends true ? never : K]: boolean extends ({
|
|
297
|
+
message: string;
|
|
298
|
+
data: T;
|
|
299
|
+
}[K] extends infer T_2 ? T_2 extends {
|
|
300
|
+
message: string;
|
|
301
|
+
data: T;
|
|
302
|
+
}[K] ? T_2 extends hono_utils_types.InvalidJSONValue ? true : false : never : never) ? hono_utils_types.JSONParsed<{
|
|
303
|
+
message: string;
|
|
304
|
+
data: T;
|
|
305
|
+
}[K], bigint | readonly bigint[]> | undefined : hono_utils_types.JSONParsed<{
|
|
306
|
+
message: string;
|
|
307
|
+
data: T;
|
|
308
|
+
}[K], bigint | readonly bigint[]>; }, 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | -1, "json">;
|
|
309
|
+
successNoContent: (message: string, status?: SuccessStatusCode) => Response & hono.TypedResponse<{
|
|
287
310
|
message: string;
|
|
288
311
|
}, 100 | 102 | 103 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | -1, "json">;
|
|
289
312
|
error: (message: string, status: ClientErrorStatusCode) => never;
|
|
@@ -459,7 +482,7 @@ declare namespace sha {
|
|
|
459
482
|
export { sha_generateSalt as generateSalt, sha_hash as hash };
|
|
460
483
|
}
|
|
461
484
|
|
|
462
|
-
declare const onError: <
|
|
485
|
+
declare const onError: <Environment extends Env>(parseError?: (err: Error | HTTPException, env: Environment["Bindings"], get: <K extends keyof Environment["Variables"]>(key: K) => Environment["Variables"][K]) => Promise<string>) => ErrorHandler<Environment>;
|
|
463
486
|
|
|
464
487
|
declare const onNotFound: NotFoundHandler;
|
|
465
488
|
|
package/dist/index.js
CHANGED
|
@@ -13925,17 +13925,17 @@ var queue = ({
|
|
|
13925
13925
|
import { createMiddleware as createMiddleware6 } from "hono/factory";
|
|
13926
13926
|
import { HTTPException as HTTPException3 } from "hono/http-exception";
|
|
13927
13927
|
var setResponseHandlers = (c) => {
|
|
13928
|
-
const method = c.req.method;
|
|
13929
13928
|
return {
|
|
13930
13929
|
raw: (data) => {
|
|
13931
13930
|
const { status, ...rest } = data;
|
|
13932
13931
|
return c.json(rest, status || 200);
|
|
13933
13932
|
},
|
|
13934
13933
|
success: (message, data, status) => {
|
|
13935
|
-
const statusCode = status ||
|
|
13936
|
-
|
|
13937
|
-
|
|
13938
|
-
|
|
13934
|
+
const statusCode = status || 200;
|
|
13935
|
+
return c.json({ message, data }, statusCode);
|
|
13936
|
+
},
|
|
13937
|
+
successNoContent: (message, status) => {
|
|
13938
|
+
const statusCode = status || 200;
|
|
13939
13939
|
return c.json({ message }, statusCode);
|
|
13940
13940
|
},
|
|
13941
13941
|
error: (message, status) => {
|
|
@@ -13953,7 +13953,9 @@ var setResponseHandlers = (c) => {
|
|
|
13953
13953
|
};
|
|
13954
13954
|
var response = createMiddleware6(async (c, next) => {
|
|
13955
13955
|
c.set("res", setResponseHandlers(c));
|
|
13956
|
-
|
|
13956
|
+
if (c.var.eventId) {
|
|
13957
|
+
c.header("x-event-id", c.var.eventId);
|
|
13958
|
+
}
|
|
13957
13959
|
await next();
|
|
13958
13960
|
});
|
|
13959
13961
|
|