@kalutskii/foundation 0.3.0 → 0.3.2
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.d.ts +2 -16
- package/dist/index.js +0 -22
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ErrorHandler, MiddlewareHandler, Context, TypedResponse
|
|
1
|
+
import { ErrorHandler, MiddlewareHandler, Context, TypedResponse } from 'hono';
|
|
2
2
|
import z$1, { z, ZodNumber } from 'zod';
|
|
3
3
|
import { Locale } from 'date-fns';
|
|
4
4
|
import { SymmetricAlgorithm } from 'hono/utils/jwt/jwa';
|
|
@@ -87,20 +87,6 @@ declare function respond<T extends object = Record<string, never>, S extends Suc
|
|
|
87
87
|
data?: T;
|
|
88
88
|
}): Response & TypedResponse<APISuccess<SerializeDates<T>> | APIError, S, 'json'>;
|
|
89
89
|
|
|
90
|
-
/** The subset of Hono validation targets supported for payload extraction. */
|
|
91
|
-
type PayloadTarget = Extract<keyof ValidationTargets, 'json' | 'query' | 'param'>;
|
|
92
|
-
/** Raw payload readers for each supported target, keyed by {@link PayloadTarget}. */
|
|
93
|
-
declare const requestReaders: {
|
|
94
|
-
json: (c: Context) => Promise<unknown>;
|
|
95
|
-
query: (c: Context) => unknown;
|
|
96
|
-
param: (c: Context) => unknown;
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Reads the raw payload from the request and validates it against the provided Zod schema.
|
|
100
|
-
* Throws an `HTTPException(400)` when validation fails or when the payload cannot be read.
|
|
101
|
-
*/
|
|
102
|
-
declare function requirePayload<TSchema extends z.ZodTypeAny>(c: Context, target: PayloadTarget, schema: TSchema): Promise<z.infer<TSchema>>;
|
|
103
|
-
|
|
104
90
|
/**
|
|
105
91
|
* Returns the current time in the specified timezone.
|
|
106
92
|
* Example: getZonedTime({ tz: 'America/New_York' }) = new Date('2026-03-15T12:00:00Z')
|
|
@@ -200,4 +186,4 @@ declare class ZodJWTService<TSchema extends z$1.ZodObject<z$1.ZodRawShape>> {
|
|
|
200
186
|
verifyOrThrow(token: string, secret: string): Promise<z$1.infer<TSchema>>;
|
|
201
187
|
}
|
|
202
188
|
|
|
203
|
-
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type JWTServiceOptions, type JWTSignOptions, SUCCESS_STATUS_CODES, type SerializeDates, type SuccessStatusCode, ZodJWTService, asQueryBoolean, asQueryNumber, failure, fetchAndThrow, fetchSafely, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, log, onHandlerError,
|
|
189
|
+
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type JWTServiceOptions, type JWTSignOptions, SUCCESS_STATUS_CODES, type SerializeDates, type SuccessStatusCode, ZodJWTService, asQueryBoolean, asQueryNumber, failure, fetchAndThrow, fetchSafely, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, log, onHandlerError, respond, safeExecute, success };
|
package/dist/index.js
CHANGED
|
@@ -130,9 +130,6 @@ function respond(c, options) {
|
|
|
130
130
|
return c.json(success({ status: options.status, data: options.data ?? {} }), options.status);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
// src/hono/hono.validation.ts
|
|
134
|
-
import { HTTPException as HTTPException2 } from "hono/http-exception";
|
|
135
|
-
|
|
136
133
|
// src/utilities/execution.utilities.ts
|
|
137
134
|
async function safeExecute(fn, onError) {
|
|
138
135
|
try {
|
|
@@ -144,23 +141,6 @@ async function safeExecute(fn, onError) {
|
|
|
144
141
|
}
|
|
145
142
|
}
|
|
146
143
|
|
|
147
|
-
// src/hono/hono.validation.ts
|
|
148
|
-
var FALLBACK_ERROR_MESSAGE = "Failed to decode request payload, please ensure it is correctly formatted.";
|
|
149
|
-
var requestReaders = {
|
|
150
|
-
json: async (c) => safeExecute(() => c.req.json(), () => {
|
|
151
|
-
throw new HTTPException2(400, { message: FALLBACK_ERROR_MESSAGE });
|
|
152
|
-
}),
|
|
153
|
-
query: (c) => c.req.query(),
|
|
154
|
-
param: (c) => c.req.param()
|
|
155
|
-
};
|
|
156
|
-
async function requirePayload(c, target, schema) {
|
|
157
|
-
const rawPayload = await requestReaders[target](c);
|
|
158
|
-
const parsedPayload = await schema.safeParseAsync(rawPayload);
|
|
159
|
-
if (parsedPayload.success)
|
|
160
|
-
return parsedPayload.data;
|
|
161
|
-
throw new HTTPException2(400, { message: parsedPayload.error.message });
|
|
162
|
-
}
|
|
163
|
-
|
|
164
144
|
// src/utilities/serialization.utilities.ts
|
|
165
145
|
import { z } from "zod";
|
|
166
146
|
var asQueryNumber = (schema) => z.preprocess((v) => typeof v === "string" ? Number(v) : v, schema);
|
|
@@ -237,8 +217,6 @@ export {
|
|
|
237
217
|
honoLoggingHandler,
|
|
238
218
|
log,
|
|
239
219
|
onHandlerError,
|
|
240
|
-
requestReaders,
|
|
241
|
-
requirePayload,
|
|
242
220
|
respond,
|
|
243
221
|
safeExecute,
|
|
244
222
|
success
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kalutskii/foundation",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Typescript collection of most common utilities, schemas and functions among private projects.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"peerDependencies": {
|
|
28
|
+
"@hono/zod-validator": "^0.8.0",
|
|
28
29
|
"date-fns": "^4.1.0",
|
|
29
30
|
"date-fns-tz": "^3.2.0",
|
|
30
31
|
"hono": "^4.12.18",
|