hono-crud 0.2.0 → 0.3.1
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/CHANGELOG.md +4 -0
- package/dist/adapters/drizzle/index.d.ts +255 -175
- package/dist/adapters/drizzle/index.js +164 -162
- package/dist/adapters/memory/index.d.ts +82 -39
- package/dist/adapters/memory/index.js +5 -2
- package/dist/adapters/prisma/index.d.ts +107 -155
- package/dist/adapters/prisma/index.js +382 -366
- package/dist/auth/index.d.ts +478 -0
- package/dist/auth/index.js +4 -0
- package/dist/bulk-patch-C1j76FUv.d.ts +141 -0
- package/dist/cache/index.d.ts +425 -0
- package/dist/cache/index.js +5 -0
- package/dist/chunk-6LS3LNIH.js +158 -0
- package/dist/chunk-CNE7UR5E.js +175 -0
- package/dist/chunk-FST5S5UY.js +304 -0
- package/dist/chunk-IPGNLIJV.js +199 -0
- package/dist/chunk-MANRQHEB.js +330 -0
- package/dist/{chunk-JEXEFNN2.js → chunk-NTQNZZSH.js} +128 -1030
- package/dist/{chunk-27JQOBXW.js → chunk-OKVSQZMU.js} +673 -225
- package/dist/chunk-SCC4CBTS.js +142 -0
- package/dist/chunk-U3SUUXJK.js +770 -0
- package/dist/chunk-WOFE46VS.js +1214 -0
- package/dist/chunk-XYVTFG7O.js +947 -0
- package/dist/chunk-YJMGFVHZ.js +220 -0
- package/dist/chunk-ZCHXXN7T.js +44 -0
- package/dist/{import-Cm5-75Os.d.ts → import-C4cjkYZ1.d.ts} +23 -1304
- package/dist/{index-CH2mY76l.d.ts → index-BVaCSKwG.d.ts} +2 -1
- package/dist/index-Dm8-ODYA.d.ts +420 -0
- package/dist/index.d.ts +1456 -3877
- package/dist/index.js +1023 -3629
- package/dist/logging/index.d.ts +299 -0
- package/dist/logging/index.js +5 -0
- package/dist/memory-B_NZbOQP.d.ts +462 -0
- package/dist/rate-limit/index.d.ts +6 -0
- package/dist/rate-limit/index.js +5 -0
- package/dist/route-BCROG0Mx.d.ts +64 -0
- package/dist/storage/index.d.ts +368 -0
- package/dist/storage/index.js +5 -0
- package/dist/types-B8CWg4nO.d.ts +327 -0
- package/dist/types-Bc7ebF5x.d.ts +236 -0
- package/dist/types-CwJSGrCj.d.ts +982 -0
- package/dist/types-DlIkjpdK.d.ts +139 -0
- package/dist/ui-CNJUoCg1.d.ts +148 -0
- package/dist/ui.d.ts +2 -0
- package/dist/ui.js +1 -0
- package/dist/versioning-4Pn5V1ed.d.ts +291 -0
- package/package.json +25 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
10
10
|
%b
|
|
11
11
|
%b
|
|
12
12
|
%b
|
|
13
|
+
%b
|
|
14
|
+
%b
|
|
13
15
|
## [0.1.0] - 2025-01-29
|
|
14
16
|
|
|
15
17
|
### Added
|
|
@@ -36,3 +38,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
36
38
|
[0.1.3]: https://github.com/ksh-us/hono-crud/compare/v0.1.2...v0.1.3
|
|
37
39
|
[0.1.4]: https://github.com/kshdotdev/hono-crud/compare/v0.1.3...v0.1.4
|
|
38
40
|
[0.2.0]: https://github.com/kshdotdev/hono-crud/compare/v0.1.4...v0.2.0
|
|
41
|
+
[0.3.0]: https://github.com/kshdotdev/hono-crud/compare/v0.2.0...v0.3.0
|
|
42
|
+
[0.3.1]: https://github.com/kshdotdev/hono-crud/compare/v0.3.0...v0.3.1
|
|
@@ -1,187 +1,56 @@
|
|
|
1
|
+
import { Table, SQL, Column } from 'drizzle-orm';
|
|
2
|
+
import { M as MetaInput, I as IncludeOptions, F as FilterCondition, g as RelationConfig, h as NestedUpdateInput, i as NestedWriteResult, L as ListFilters, P as PaginatedResult, j as AggregateOptions, k as AggregateResult, S as SearchOptions, l as SearchResult } from '../../types-CwJSGrCj.js';
|
|
1
3
|
import { Env } from 'hono';
|
|
4
|
+
import { C as CreateEndpoint, M as ModelObject, R as ReadEndpoint, U as UpdateEndpoint, D as DeleteEndpoint, L as ListEndpoint, a as RestoreEndpoint, B as BatchCreateEndpoint, b as BatchDeleteEndpoint, c as BatchRestoreEndpoint, d as BatchUpdateEndpoint, e as BatchUpdateItem, A as AggregateEndpoint, f as BatchUpsertEndpoint, g as UpsertEndpoint, E as ExportEndpoint, I as ImportEndpoint, S as SearchEndpoint, V as VersionCompareEndpoint, h as VersionHistoryEndpoint, i as VersionReadEndpoint, j as VersionRollbackEndpoint } from '../../import-C4cjkYZ1.js';
|
|
5
|
+
import { A as AdapterBundle } from '../../index-BVaCSKwG.js';
|
|
2
6
|
import { z } from 'zod';
|
|
3
|
-
import { Table, Column } from 'drizzle-orm';
|
|
4
|
-
import { M as MetaInput, e as AggregateEndpoint, h as AggregateOptions, i as AggregateResult, B as BatchCreateEndpoint, c as ModelObject, o as BatchDeleteEndpoint, q as BatchRestoreEndpoint, s as BatchUpdateEndpoint, t as BatchUpdateItem, v as BatchUpsertEndpoint, G as CreateEndpoint, aA as RelationConfig, az as ReadEndpoint, aa as IncludeOptions, aP as UpdateEndpoint, ap as NestedUpdateInput, ar as NestedWriteResult, P as DeleteEndpoint, ae as ListEndpoint, ag as ListFilters, ax as PaginatedResult, aE as RestoreEndpoint, aR as UpsertEndpoint, R as ExportEndpoint, a3 as ImportEndpoint, aI as SearchEndpoint, aJ as SearchOptions, aK as SearchResult, aU as VersionCompareEndpoint, aV as VersionHistoryEndpoint, aY as VersionReadEndpoint, aZ as VersionRollbackEndpoint } from '../../import-Cm5-75Os.js';
|
|
5
|
-
import { A as AdapterBundle } from '../../index-CH2mY76l.js';
|
|
6
|
-
import 'hono/utils/http-status';
|
|
7
7
|
import '@hono/zod-openapi';
|
|
8
|
+
import '../../route-BCROG0Mx.js';
|
|
9
|
+
import 'hono/utils/http-status';
|
|
10
|
+
import '../../versioning-4Pn5V1ed.js';
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
13
|
+
* Internal query builder interface used for type-safe method calls.
|
|
14
|
+
* All Drizzle query builders satisfy this interface at runtime.
|
|
15
|
+
*/
|
|
16
|
+
interface QueryBuilder extends PromiseLike<unknown[]> {
|
|
17
|
+
where(condition: unknown): QueryBuilder;
|
|
18
|
+
limit(n: number): QueryBuilder;
|
|
19
|
+
offset(n: number): QueryBuilder;
|
|
20
|
+
orderBy(...columns: unknown[]): QueryBuilder;
|
|
21
|
+
set(data: Record<string, unknown>): QueryBuilder;
|
|
22
|
+
values(data: Record<string, unknown> | Record<string, unknown>[]): QueryBuilder;
|
|
23
|
+
returning(): QueryBuilder;
|
|
24
|
+
onConflictDoUpdate(config: {
|
|
25
|
+
target: unknown[];
|
|
26
|
+
set: Record<string, unknown>;
|
|
27
|
+
where?: unknown;
|
|
28
|
+
}): QueryBuilder;
|
|
29
|
+
onConflictDoNothing(config?: {
|
|
30
|
+
target?: unknown[];
|
|
31
|
+
}): QueryBuilder;
|
|
32
|
+
onDuplicateKeyUpdate(config: {
|
|
33
|
+
set: Record<string, unknown>;
|
|
34
|
+
}): QueryBuilder;
|
|
35
|
+
}
|
|
34
36
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
+
* Internal database interface used for type-safe method calls.
|
|
38
|
+
* All Drizzle databases (PostgreSQL, MySQL, SQLite) satisfy this interface at runtime.
|
|
37
39
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
columns: Record<string, any>;
|
|
40
|
+
interface Database {
|
|
41
|
+
select(fields?: Record<string, unknown>): {
|
|
42
|
+
from(table: Table): QueryBuilder;
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
* @param table - Drizzle table definition
|
|
49
|
-
* @param refine - Optional refinements for specific columns
|
|
50
|
-
* @returns Zod schema for the table's select type
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```ts
|
|
54
|
-
* import { users } from './schema';
|
|
55
|
-
* import { createSelectSchema } from 'hono-crud/adapters/drizzle';
|
|
56
|
-
*
|
|
57
|
-
* const UserSchema = createSelectSchema(users);
|
|
58
|
-
* type User = z.infer<typeof UserSchema>;
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
declare function createSelectSchema<T extends DrizzleTable>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
62
|
-
/**
|
|
63
|
-
* Re-export createInsertSchema from drizzle-zod.
|
|
64
|
-
* Creates a Zod schema for INSERT queries (columns with defaults become optional).
|
|
65
|
-
*
|
|
66
|
-
* @param table - Drizzle table definition
|
|
67
|
-
* @param refine - Optional refinements for specific columns
|
|
68
|
-
* @returns Zod schema for the table's insert type
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* import { users } from './schema';
|
|
73
|
-
* import { createInsertSchema } from 'hono-crud/adapters/drizzle';
|
|
74
|
-
*
|
|
75
|
-
* const CreateUserSchema = createInsertSchema(users);
|
|
76
|
-
* type CreateUser = z.infer<typeof CreateUserSchema>;
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
declare function createInsertSchema<T extends DrizzleTable>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
80
|
-
/**
|
|
81
|
-
* Re-export createUpdateSchema from drizzle-zod (if available).
|
|
82
|
-
* Creates a Zod schema for UPDATE queries (all columns become optional).
|
|
83
|
-
*
|
|
84
|
-
* Note: createUpdateSchema may not be available in older versions of drizzle-zod.
|
|
85
|
-
* Use createInsertSchema(table).partial() as an alternative.
|
|
86
|
-
*
|
|
87
|
-
* @param table - Drizzle table definition
|
|
88
|
-
* @param refine - Optional refinements for specific columns
|
|
89
|
-
* @returns Zod schema for the table's update type
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* ```ts
|
|
93
|
-
* import { users } from './schema';
|
|
94
|
-
* import { createUpdateSchema } from 'hono-crud/adapters/drizzle';
|
|
95
|
-
*
|
|
96
|
-
* const UpdateUserSchema = createUpdateSchema(users);
|
|
97
|
-
* type UpdateUser = z.infer<typeof UpdateUserSchema>;
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
declare function createUpdateSchema<T extends DrizzleTable>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
101
|
-
/**
|
|
102
|
-
* Result of createDrizzleSchemas helper.
|
|
103
|
-
*/
|
|
104
|
-
interface DrizzleSchemas {
|
|
105
|
-
/** Schema for SELECT queries (full record) */
|
|
106
|
-
select: z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
107
|
-
/** Schema for INSERT queries (required fields only) */
|
|
108
|
-
insert: z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
109
|
-
/** Schema for UPDATE queries (all fields optional) */
|
|
110
|
-
update: z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
44
|
+
insert(table: Table): QueryBuilder;
|
|
45
|
+
update(table: Table): QueryBuilder;
|
|
46
|
+
delete(table: Table): QueryBuilder;
|
|
47
|
+
transaction<T>(fn: (tx: Database) => Promise<T>): Promise<T>;
|
|
111
48
|
}
|
|
112
49
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* This is a convenience helper that generates:
|
|
116
|
-
* - `select`: Full record schema for reading data
|
|
117
|
-
* - `insert`: Schema for creating new records (with date coercion for JSON input)
|
|
118
|
-
* - `update`: Partial schema for updating records (with date coercion for JSON input)
|
|
119
|
-
*
|
|
120
|
-
* Date coercion is automatically applied to timestamp/date columns, allowing
|
|
121
|
-
* both Date objects and ISO 8601 date strings as input values.
|
|
122
|
-
*
|
|
123
|
-
* @param table - Drizzle table definition
|
|
124
|
-
* @param options - Optional configuration
|
|
125
|
-
* @param options.insertRefine - Refinements for insert schema
|
|
126
|
-
* @param options.selectRefine - Refinements for select schema
|
|
127
|
-
* @param options.updateRefine - Refinements for update schema
|
|
128
|
-
* @param options.coerceDates - Whether to coerce date strings to Date objects (default: true)
|
|
129
|
-
* @returns Object containing select, insert, and update schemas
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```ts
|
|
133
|
-
* import { pgTable, text, uuid } from 'drizzle-orm/pg-core';
|
|
134
|
-
* import { createDrizzleSchemas, defineModel, defineMeta } from 'hono-crud/adapters/drizzle';
|
|
135
|
-
* import { z } from 'zod';
|
|
136
|
-
*
|
|
137
|
-
* const users = pgTable('users', {
|
|
138
|
-
* id: uuid('id').primaryKey().defaultRandom(),
|
|
139
|
-
* name: text('name').notNull(),
|
|
140
|
-
* email: text('email').notNull().unique(),
|
|
141
|
-
* });
|
|
142
|
-
*
|
|
143
|
-
* // Generate schemas from table
|
|
144
|
-
* const schemas = createDrizzleSchemas(users, {
|
|
145
|
-
* insertRefine: {
|
|
146
|
-
* email: z.string().email(), // Add email validation
|
|
147
|
-
* },
|
|
148
|
-
* });
|
|
149
|
-
*
|
|
150
|
-
* // Use with hono-crud model
|
|
151
|
-
* const UserModel = defineModel({
|
|
152
|
-
* tableName: 'users',
|
|
153
|
-
* schema: schemas.select,
|
|
154
|
-
* primaryKeys: ['id'],
|
|
155
|
-
* table: users,
|
|
156
|
-
* });
|
|
157
|
-
* ```
|
|
50
|
+
* Casts a database to the internal Database interface for method calls.
|
|
51
|
+
* This is safe because all Drizzle databases have these methods at runtime.
|
|
158
52
|
*/
|
|
159
|
-
declare function
|
|
160
|
-
insertRefine?: Record<string, z.ZodTypeAny>;
|
|
161
|
-
selectRefine?: Record<string, z.ZodTypeAny>;
|
|
162
|
-
updateRefine?: Record<string, z.ZodTypeAny>;
|
|
163
|
-
/** Whether to coerce date strings to Date objects. Default: true */
|
|
164
|
-
coerceDates?: boolean;
|
|
165
|
-
}): DrizzleSchemas;
|
|
166
|
-
/**
|
|
167
|
-
* Async version of createDrizzleSchemas that handles lazy loading.
|
|
168
|
-
* Use this if you're not sure drizzle-zod is already loaded.
|
|
169
|
-
*
|
|
170
|
-
* @param table - Drizzle table definition
|
|
171
|
-
* @param options - Optional configuration
|
|
172
|
-
* @returns Promise resolving to schemas object
|
|
173
|
-
*/
|
|
174
|
-
declare function createDrizzleSchemasAsync<T extends DrizzleTable>(table: T, options?: {
|
|
175
|
-
insertRefine?: Record<string, z.ZodTypeAny>;
|
|
176
|
-
selectRefine?: Record<string, z.ZodTypeAny>;
|
|
177
|
-
updateRefine?: Record<string, z.ZodTypeAny>;
|
|
178
|
-
}): Promise<DrizzleSchemas>;
|
|
179
|
-
/**
|
|
180
|
-
* Checks if drizzle-zod is available.
|
|
181
|
-
* @returns true if drizzle-zod can be imported
|
|
182
|
-
*/
|
|
183
|
-
declare function isDrizzleZodAvailable(): boolean;
|
|
184
|
-
|
|
53
|
+
declare function cast<T>(instance: T): Database;
|
|
185
54
|
/**
|
|
186
55
|
* Base constraint for Drizzle database types.
|
|
187
56
|
* Your database type must have select, insert, update, delete, and transaction methods.
|
|
@@ -243,6 +112,39 @@ type DrizzleEnv<DB = DrizzleDatabaseConstraint> = {
|
|
|
243
112
|
db: DB;
|
|
244
113
|
};
|
|
245
114
|
};
|
|
115
|
+
/**
|
|
116
|
+
* Gets the Drizzle table from the model.
|
|
117
|
+
*/
|
|
118
|
+
declare function getTable<M extends MetaInput>(meta: M): Table;
|
|
119
|
+
/**
|
|
120
|
+
* Gets a column from the table with proper type safety.
|
|
121
|
+
* Uses drizzle-orm's getTableColumns for type-safe column access.
|
|
122
|
+
*
|
|
123
|
+
* @param table - The Drizzle table
|
|
124
|
+
* @param field - The field/column name
|
|
125
|
+
* @returns The column
|
|
126
|
+
* @throws Error if the column is not found in the table
|
|
127
|
+
*/
|
|
128
|
+
declare function getColumn(table: Table, field: string): Column;
|
|
129
|
+
/**
|
|
130
|
+
* Loads related records for a given item using Drizzle queries.
|
|
131
|
+
*/
|
|
132
|
+
declare function loadDrizzleRelation<T extends Record<string, unknown>>(db: DrizzleDatabase, item: T, relationName: string, relationConfig: RelationConfig<Table>): Promise<T>;
|
|
133
|
+
/**
|
|
134
|
+
* Loads all requested relations for an item.
|
|
135
|
+
* Note: For multiple items, use `batchLoadDrizzleRelations` to avoid N+1 queries.
|
|
136
|
+
*/
|
|
137
|
+
declare function loadDrizzleRelations<T extends Record<string, unknown>, M extends MetaInput>(db: DrizzleDatabase, item: T, meta: M, includeOptions?: IncludeOptions): Promise<T>;
|
|
138
|
+
/**
|
|
139
|
+
* Batch loads relations for multiple items to avoid N+1 queries.
|
|
140
|
+
* Instead of N queries per relation, this uses 1 query per relation using inArray().
|
|
141
|
+
*/
|
|
142
|
+
declare function batchLoadDrizzleRelations<T extends Record<string, unknown>, M extends MetaInput>(db: DrizzleDatabase, items: T[], meta: M, includeOptions?: IncludeOptions): Promise<T[]>;
|
|
143
|
+
/**
|
|
144
|
+
* Builds a where condition from filter conditions.
|
|
145
|
+
*/
|
|
146
|
+
declare function buildWhereCondition(table: Table, filter: FilterCondition): SQL | undefined;
|
|
147
|
+
|
|
246
148
|
/**
|
|
247
149
|
* Drizzle Create endpoint.
|
|
248
150
|
* Works with any Drizzle dialect (PostgreSQL, MySQL, SQLite).
|
|
@@ -461,6 +363,7 @@ declare abstract class DrizzleRestoreEndpoint<E extends Env = Env, M extends Met
|
|
|
461
363
|
*/
|
|
462
364
|
handle(): Promise<Response>;
|
|
463
365
|
}
|
|
366
|
+
|
|
464
367
|
/**
|
|
465
368
|
* Drizzle Batch Create endpoint.
|
|
466
369
|
* Works with any Drizzle dialect (PostgreSQL, MySQL, SQLite).
|
|
@@ -527,6 +430,7 @@ declare abstract class DrizzleBatchRestoreEndpoint<E extends Env = Env, M extend
|
|
|
527
430
|
notFound: string[];
|
|
528
431
|
}>;
|
|
529
432
|
}
|
|
433
|
+
|
|
530
434
|
/**
|
|
531
435
|
* Drizzle Upsert endpoint.
|
|
532
436
|
* Creates a record if it doesn't exist, updates it if it does.
|
|
@@ -733,6 +637,7 @@ declare abstract class DrizzleImportEndpoint<E extends Env = Env, M extends Meta
|
|
|
733
637
|
*/
|
|
734
638
|
update(existing: ModelObject<M['model']>, data: Partial<ModelObject<M['model']>>): Promise<ModelObject<M['model']>>;
|
|
735
639
|
}
|
|
640
|
+
|
|
736
641
|
/**
|
|
737
642
|
* Return type of createDrizzleCrud factory function.
|
|
738
643
|
* Provides type-safe base classes for all CRUD operations.
|
|
@@ -779,7 +684,6 @@ interface DrizzleCrudClasses<M extends MetaInput> {
|
|
|
779
684
|
* ```
|
|
780
685
|
*/
|
|
781
686
|
declare function createDrizzleCrud<M extends MetaInput>(db: DrizzleDatabaseConstraint, meta: M): DrizzleCrudClasses<M>;
|
|
782
|
-
|
|
783
687
|
/**
|
|
784
688
|
* Drizzle adapter bundle for use with defineEndpoints.
|
|
785
689
|
*
|
|
@@ -806,4 +710,180 @@ declare function createDrizzleCrud<M extends MetaInput>(db: DrizzleDatabaseConst
|
|
|
806
710
|
*/
|
|
807
711
|
declare const DrizzleAdapters: AdapterBundle;
|
|
808
712
|
|
|
809
|
-
|
|
713
|
+
/**
|
|
714
|
+
* Drizzle-Zod schema utilities.
|
|
715
|
+
*
|
|
716
|
+
* This module provides helpers for generating Zod schemas from Drizzle tables
|
|
717
|
+
* using drizzle-zod. This allows automatic schema generation for CRUD operations.
|
|
718
|
+
*
|
|
719
|
+
* Note: drizzle-zod is an optional peer dependency. These utilities will only
|
|
720
|
+
* work if drizzle-zod is installed.
|
|
721
|
+
*
|
|
722
|
+
* @example
|
|
723
|
+
* ```ts
|
|
724
|
+
* import { pgTable, text, timestamp, uuid } from 'drizzle-orm/pg-core';
|
|
725
|
+
* import { createDrizzleSchemas } from 'hono-crud/adapters/drizzle';
|
|
726
|
+
*
|
|
727
|
+
* const users = pgTable('users', {
|
|
728
|
+
* id: uuid('id').primaryKey().defaultRandom(),
|
|
729
|
+
* name: text('name').notNull(),
|
|
730
|
+
* email: text('email').notNull().unique(),
|
|
731
|
+
* createdAt: timestamp('created_at').defaultNow(),
|
|
732
|
+
* });
|
|
733
|
+
*
|
|
734
|
+
* const { select: UserSchema, insert: CreateUserSchema } = createDrizzleSchemas(users);
|
|
735
|
+
* ```
|
|
736
|
+
*/
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Duck-typed interface for Drizzle tables.
|
|
740
|
+
* This allows compatibility across different drizzle-orm versions and package installations.
|
|
741
|
+
*/
|
|
742
|
+
type DrizzleTable = {
|
|
743
|
+
_: {
|
|
744
|
+
name: string;
|
|
745
|
+
columns: Record<string, any>;
|
|
746
|
+
};
|
|
747
|
+
};
|
|
748
|
+
/**
|
|
749
|
+
* Re-export createSelectSchema from drizzle-zod.
|
|
750
|
+
* Creates a Zod schema for SELECT queries (all columns as required/optional based on table definition).
|
|
751
|
+
*
|
|
752
|
+
* @param table - Drizzle table definition
|
|
753
|
+
* @param refine - Optional refinements for specific columns
|
|
754
|
+
* @returns Zod schema for the table's select type
|
|
755
|
+
*
|
|
756
|
+
* @example
|
|
757
|
+
* ```ts
|
|
758
|
+
* import { users } from './schema';
|
|
759
|
+
* import { createSelectSchema } from 'hono-crud/adapters/drizzle';
|
|
760
|
+
*
|
|
761
|
+
* const UserSchema = createSelectSchema(users);
|
|
762
|
+
* type User = z.infer<typeof UserSchema>;
|
|
763
|
+
* ```
|
|
764
|
+
*/
|
|
765
|
+
declare function createSelectSchema<T extends DrizzleTable>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
766
|
+
/**
|
|
767
|
+
* Re-export createInsertSchema from drizzle-zod.
|
|
768
|
+
* Creates a Zod schema for INSERT queries (columns with defaults become optional).
|
|
769
|
+
*
|
|
770
|
+
* @param table - Drizzle table definition
|
|
771
|
+
* @param refine - Optional refinements for specific columns
|
|
772
|
+
* @returns Zod schema for the table's insert type
|
|
773
|
+
*
|
|
774
|
+
* @example
|
|
775
|
+
* ```ts
|
|
776
|
+
* import { users } from './schema';
|
|
777
|
+
* import { createInsertSchema } from 'hono-crud/adapters/drizzle';
|
|
778
|
+
*
|
|
779
|
+
* const CreateUserSchema = createInsertSchema(users);
|
|
780
|
+
* type CreateUser = z.infer<typeof CreateUserSchema>;
|
|
781
|
+
* ```
|
|
782
|
+
*/
|
|
783
|
+
declare function createInsertSchema<T extends DrizzleTable>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
784
|
+
/**
|
|
785
|
+
* Re-export createUpdateSchema from drizzle-zod (if available).
|
|
786
|
+
* Creates a Zod schema for UPDATE queries (all columns become optional).
|
|
787
|
+
*
|
|
788
|
+
* Note: createUpdateSchema may not be available in older versions of drizzle-zod.
|
|
789
|
+
* Use createInsertSchema(table).partial() as an alternative.
|
|
790
|
+
*
|
|
791
|
+
* @param table - Drizzle table definition
|
|
792
|
+
* @param refine - Optional refinements for specific columns
|
|
793
|
+
* @returns Zod schema for the table's update type
|
|
794
|
+
*
|
|
795
|
+
* @example
|
|
796
|
+
* ```ts
|
|
797
|
+
* import { users } from './schema';
|
|
798
|
+
* import { createUpdateSchema } from 'hono-crud/adapters/drizzle';
|
|
799
|
+
*
|
|
800
|
+
* const UpdateUserSchema = createUpdateSchema(users);
|
|
801
|
+
* type UpdateUser = z.infer<typeof UpdateUserSchema>;
|
|
802
|
+
* ```
|
|
803
|
+
*/
|
|
804
|
+
declare function createUpdateSchema<T extends DrizzleTable>(table: T, refine?: Record<string, z.ZodTypeAny>): z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
805
|
+
/**
|
|
806
|
+
* Result of createDrizzleSchemas helper.
|
|
807
|
+
*/
|
|
808
|
+
interface DrizzleSchemas {
|
|
809
|
+
/** Schema for SELECT queries (full record) */
|
|
810
|
+
select: z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
811
|
+
/** Schema for INSERT queries (required fields only) */
|
|
812
|
+
insert: z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
813
|
+
/** Schema for UPDATE queries (all fields optional) */
|
|
814
|
+
update: z.ZodObject<Record<string, z.ZodTypeAny>>;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Creates all three common schemas (select, insert, update) for a Drizzle table.
|
|
818
|
+
*
|
|
819
|
+
* This is a convenience helper that generates:
|
|
820
|
+
* - `select`: Full record schema for reading data
|
|
821
|
+
* - `insert`: Schema for creating new records (with date coercion for JSON input)
|
|
822
|
+
* - `update`: Partial schema for updating records (with date coercion for JSON input)
|
|
823
|
+
*
|
|
824
|
+
* Date coercion is automatically applied to timestamp/date columns, allowing
|
|
825
|
+
* both Date objects and ISO 8601 date strings as input values.
|
|
826
|
+
*
|
|
827
|
+
* @param table - Drizzle table definition
|
|
828
|
+
* @param options - Optional configuration
|
|
829
|
+
* @param options.insertRefine - Refinements for insert schema
|
|
830
|
+
* @param options.selectRefine - Refinements for select schema
|
|
831
|
+
* @param options.updateRefine - Refinements for update schema
|
|
832
|
+
* @param options.coerceDates - Whether to coerce date strings to Date objects (default: true)
|
|
833
|
+
* @returns Object containing select, insert, and update schemas
|
|
834
|
+
*
|
|
835
|
+
* @example
|
|
836
|
+
* ```ts
|
|
837
|
+
* import { pgTable, text, uuid } from 'drizzle-orm/pg-core';
|
|
838
|
+
* import { createDrizzleSchemas, defineModel, defineMeta } from 'hono-crud/adapters/drizzle';
|
|
839
|
+
* import { z } from 'zod';
|
|
840
|
+
*
|
|
841
|
+
* const users = pgTable('users', {
|
|
842
|
+
* id: uuid('id').primaryKey().defaultRandom(),
|
|
843
|
+
* name: text('name').notNull(),
|
|
844
|
+
* email: text('email').notNull().unique(),
|
|
845
|
+
* });
|
|
846
|
+
*
|
|
847
|
+
* // Generate schemas from table
|
|
848
|
+
* const schemas = createDrizzleSchemas(users, {
|
|
849
|
+
* insertRefine: {
|
|
850
|
+
* email: z.string().email(), // Add email validation
|
|
851
|
+
* },
|
|
852
|
+
* });
|
|
853
|
+
*
|
|
854
|
+
* // Use with hono-crud model
|
|
855
|
+
* const UserModel = defineModel({
|
|
856
|
+
* tableName: 'users',
|
|
857
|
+
* schema: schemas.select,
|
|
858
|
+
* primaryKeys: ['id'],
|
|
859
|
+
* table: users,
|
|
860
|
+
* });
|
|
861
|
+
* ```
|
|
862
|
+
*/
|
|
863
|
+
declare function createDrizzleSchemas<T extends DrizzleTable>(table: T, options?: {
|
|
864
|
+
insertRefine?: Record<string, z.ZodTypeAny>;
|
|
865
|
+
selectRefine?: Record<string, z.ZodTypeAny>;
|
|
866
|
+
updateRefine?: Record<string, z.ZodTypeAny>;
|
|
867
|
+
/** Whether to coerce date strings to Date objects. Default: true */
|
|
868
|
+
coerceDates?: boolean;
|
|
869
|
+
}): DrizzleSchemas;
|
|
870
|
+
/**
|
|
871
|
+
* Async version of createDrizzleSchemas that handles lazy loading.
|
|
872
|
+
* Use this if you're not sure drizzle-zod is already loaded.
|
|
873
|
+
*
|
|
874
|
+
* @param table - Drizzle table definition
|
|
875
|
+
* @param options - Optional configuration
|
|
876
|
+
* @returns Promise resolving to schemas object
|
|
877
|
+
*/
|
|
878
|
+
declare function createDrizzleSchemasAsync<T extends DrizzleTable>(table: T, options?: {
|
|
879
|
+
insertRefine?: Record<string, z.ZodTypeAny>;
|
|
880
|
+
selectRefine?: Record<string, z.ZodTypeAny>;
|
|
881
|
+
updateRefine?: Record<string, z.ZodTypeAny>;
|
|
882
|
+
}): Promise<DrizzleSchemas>;
|
|
883
|
+
/**
|
|
884
|
+
* Checks if drizzle-zod is available.
|
|
885
|
+
* @returns true if drizzle-zod can be imported
|
|
886
|
+
*/
|
|
887
|
+
declare function isDrizzleZodAvailable(): boolean;
|
|
888
|
+
|
|
889
|
+
export { type Database, DrizzleAdapters, DrizzleAggregateEndpoint, DrizzleBatchCreateEndpoint, DrizzleBatchDeleteEndpoint, DrizzleBatchRestoreEndpoint, DrizzleBatchUpdateEndpoint, DrizzleBatchUpsertEndpoint, DrizzleCreateEndpoint, type DrizzleCrudClasses, type DrizzleDB, type DrizzleDatabase, type DrizzleDatabaseConstraint, DrizzleDeleteEndpoint, type DrizzleEnv, DrizzleExportEndpoint, DrizzleImportEndpoint, DrizzleListEndpoint, DrizzleReadEndpoint, DrizzleRestoreEndpoint, type DrizzleSchemas, DrizzleSearchEndpoint, DrizzleUpdateEndpoint, DrizzleUpsertEndpoint, DrizzleVersionCompareEndpoint, DrizzleVersionHistoryEndpoint, DrizzleVersionReadEndpoint, DrizzleVersionRollbackEndpoint, type QueryBuilder, batchLoadDrizzleRelations, buildWhereCondition, cast, createDrizzleCrud, createDrizzleSchemas, createDrizzleSchemasAsync, createInsertSchema, createSelectSchema, createUpdateSchema, getColumn, getTable, isDrizzleZodAvailable, loadDrizzleRelation, loadDrizzleRelations };
|