@kalutskii/foundation 0.6.6 → 0.6.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/dist/index.d.ts +14 -1
- package/dist/index.js +13 -0
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
|
+
import { SQL } from 'drizzle-orm';
|
|
1
2
|
import { ErrorHandler, MiddlewareHandler, Context, TypedResponse } from 'hono';
|
|
2
3
|
import { Locale } from 'date-fns';
|
|
3
4
|
import { SymmetricAlgorithm } from 'hono/utils/jwt/jwa';
|
|
4
5
|
import z from 'zod';
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Builds a Drizzle SQL `where` condition from a plain object.
|
|
9
|
+
*
|
|
10
|
+
* Maps each `where` entry to `eq(table[key], value)` and combines them with `and`.
|
|
11
|
+
* Assumes that `where` was already validated and contains only existing table fields.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* await db.update(usersTable).set(values).where(sqlWhere(usersTable, { id: 1 })).returning();
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function sqlWhere(table: unknown, where: Record<string, unknown>): SQL;
|
|
18
|
+
|
|
6
19
|
/**
|
|
7
20
|
* Global error handler for Hono framework. Catches all exceptions thrown in route handlers and middlewares.
|
|
8
21
|
* Distinguishes between expected HTTPExceptions (mapped to their status codes) and unexpected errors (500).
|
|
@@ -321,4 +334,4 @@ declare const refinePagination: (options?: ZodPaginationOptions) => ZodPaginatio
|
|
|
321
334
|
*/
|
|
322
335
|
declare const asQuery: <T extends z.ZodTypeAny>(schema: T) => z.ZodPreprocess<T>;
|
|
323
336
|
|
|
324
|
-
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type Payload, type PayloadSchema, SUCCESS_STATUS_CODES, type Simplify, type SuccessStatusCode, ZodJWTService, type ZodPaginationOptions, asQuery, failure, fetchAndThrow, fetchSafely, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, log, measureExecutionTime, onHandlerError, refinePagination, respond, safeExecute, success, zodPaginationSchema, zodPaginationShape };
|
|
337
|
+
export { type APIContractData, type APIContractError, type APIContractResult, type APIError, type APISuccess, type AsQuery, type AtLeastOne, EXCEPTION_STATUS_CODES, type ExceptionStatusCode, type FetchResult, type JWTServiceOptions, type JWTSignOptions, type MeasuredExecution, type Payload, type PayloadSchema, SUCCESS_STATUS_CODES, type Simplify, type SuccessStatusCode, ZodJWTService, type ZodPaginationOptions, asQuery, failure, fetchAndThrow, fetchSafely, formatTime, generateRandomString, getColoredHTTPStatus, getFormattedDate, getFormattedTime, getUTCOffset, getZonedTime, honoLoggingHandler, log, measureExecutionTime, onHandlerError, refinePagination, respond, safeExecute, sqlWhere, success, zodPaginationSchema, zodPaginationShape };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// src/drizzle/drizzle.refiners.ts
|
|
2
|
+
import { and, eq } from "drizzle-orm";
|
|
3
|
+
var AT_LEAST_ONE_DEFINED_CONDITION_ERROR = "sqlWhere requires at least one defined condition.";
|
|
4
|
+
function sqlWhere(table, where) {
|
|
5
|
+
const columns = table;
|
|
6
|
+
const conditions = Object.entries(where).filter(([, value]) => value !== void 0).map(([key, value]) => eq(columns[key], value));
|
|
7
|
+
if (conditions.length === 0) {
|
|
8
|
+
throw new Error(AT_LEAST_ONE_DEFINED_CONDITION_ERROR);
|
|
9
|
+
}
|
|
10
|
+
return and(...conditions);
|
|
11
|
+
}
|
|
12
|
+
|
|
1
13
|
// src/hono/hono.execution.ts
|
|
2
14
|
import { HTTPException } from "hono/http-exception";
|
|
3
15
|
import { red as red2 } from "kleur/colors";
|
|
@@ -255,6 +267,7 @@ export {
|
|
|
255
267
|
refinePagination,
|
|
256
268
|
respond,
|
|
257
269
|
safeExecute,
|
|
270
|
+
sqlWhere,
|
|
258
271
|
success,
|
|
259
272
|
zodPaginationSchema,
|
|
260
273
|
zodPaginationShape
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kalutskii/foundation",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"description": "Typescript collection of most common utilities, schemas and functions among private projects.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"@hono/zod-validator": "^0.8.0",
|
|
30
30
|
"date-fns": "^4.1.0",
|
|
31
31
|
"date-fns-tz": "^3.2.0",
|
|
32
|
+
"drizzle-orm": "^1.0.0-beta.22",
|
|
32
33
|
"hono": "^4.12.18",
|
|
33
34
|
"kleur": "^4.1.5",
|
|
34
35
|
"typescript": "^5",
|