crudora 0.1.0 → 0.2.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/LICENSE +21 -21
- package/README.md +554 -328
- package/dist/cli.js +62 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +1692 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +404 -0
- package/dist/index.d.ts +404 -10
- package/dist/index.js +1685 -16
- package/dist/index.js.map +1 -1
- package/dist/scripts/copy-assets.js +26 -47
- package/dist/scripts/postinstall.js +172 -136
- package/dist/templates/.env.example +13 -9
- package/dist/templates/drizzle.config.ts +10 -0
- package/dist/templates/schema.ts +23 -0
- package/package.json +109 -94
- package/scripts/copy-assets.js +26 -47
- package/scripts/postinstall.js +172 -136
- package/templates/.env.example +13 -9
- package/templates/drizzle.config.ts +10 -0
- package/templates/schema.ts +23 -0
- package/dist/core/crudora.d.ts +0 -24
- package/dist/core/crudora.d.ts.map +0 -1
- package/dist/core/crudora.js +0 -221
- package/dist/core/crudora.js.map +0 -1
- package/dist/core/crudoraServer.d.ts +0 -30
- package/dist/core/crudoraServer.d.ts.map +0 -1
- package/dist/core/crudoraServer.js +0 -83
- package/dist/core/crudoraServer.js.map +0 -1
- package/dist/core/model.d.ts +0 -39
- package/dist/core/model.d.ts.map +0 -1
- package/dist/core/model.js +0 -101
- package/dist/core/model.js.map +0 -1
- package/dist/core/repository.d.ts +0 -22
- package/dist/core/repository.d.ts.map +0 -1
- package/dist/core/repository.js +0 -149
- package/dist/core/repository.js.map +0 -1
- package/dist/core/schemaGenerator.d.ts +0 -6
- package/dist/core/schemaGenerator.d.ts.map +0 -1
- package/dist/core/schemaGenerator.js +0 -43
- package/dist/core/schemaGenerator.js.map +0 -1
- package/dist/decorators/model.d.ts +0 -9
- package/dist/decorators/model.d.ts.map +0 -1
- package/dist/decorators/model.js +0 -46
- package/dist/decorators/model.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/templates/schema.prisma +0 -22
- package/dist/types/model.type.d.ts +0 -13
- package/dist/types/model.type.d.ts.map +0 -1
- package/dist/types/model.type.js +0 -3
- package/dist/types/model.type.js.map +0 -1
- package/dist/utils/validation.d.ts +0 -7
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js +0 -35
- package/dist/utils/validation.js.map +0 -1
- package/templates/schema.prisma +0 -22
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,404 @@
|
|
|
1
|
-
import '
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Base class for all Crudora models. Extend this to define your table schema,
|
|
6
|
+
* configure lifecycle hooks, and control API behaviour via static properties.
|
|
7
|
+
*
|
|
8
|
+
* Use `@Field()` decorators on instance properties to describe columns.
|
|
9
|
+
* Use `@HasMany()`, `@HasOne()`, `@BelongsTo()`, `@BelongsToMany()` for relations.
|
|
10
|
+
*
|
|
11
|
+
* This is a plain class — **not** a decorator. Extend it:
|
|
12
|
+
* ```ts
|
|
13
|
+
* class User extends Model {
|
|
14
|
+
* static tableName = 'users';
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare abstract class Model {
|
|
19
|
+
static tableName?: string;
|
|
20
|
+
static primaryKey?: string;
|
|
21
|
+
static timestamps?: boolean;
|
|
22
|
+
static softDelete?: boolean;
|
|
23
|
+
static fillable?: string[];
|
|
24
|
+
static hidden?: string[];
|
|
25
|
+
static schema?: string;
|
|
26
|
+
static getTableName(): string;
|
|
27
|
+
static getPrimaryKey(): string;
|
|
28
|
+
static beforeCreate?(_data: any): Promise<any>;
|
|
29
|
+
static afterCreate?(_data: any, result: any): Promise<any>;
|
|
30
|
+
static afterCreateMany?(_records: any[]): Promise<any[]>;
|
|
31
|
+
static beforeUpdate?(_id: string, _data: any): Promise<any>;
|
|
32
|
+
static afterUpdate?(_id: string, _data: any, result: any): Promise<any>;
|
|
33
|
+
static beforeDelete?(_id: string): Promise<void>;
|
|
34
|
+
static afterDelete?(_id: string, result: any): Promise<any>;
|
|
35
|
+
static beforeFind?(options?: any): Promise<any>;
|
|
36
|
+
static afterFind?(results: any[]): Promise<any[]>;
|
|
37
|
+
beforeSave?(): Promise<void>;
|
|
38
|
+
afterSave?(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
type ModelConstructor<T extends Model = Model> = {
|
|
41
|
+
new (): T;
|
|
42
|
+
tableName?: string;
|
|
43
|
+
primaryKey?: string;
|
|
44
|
+
timestamps?: boolean;
|
|
45
|
+
softDelete?: boolean;
|
|
46
|
+
fillable?: string[];
|
|
47
|
+
hidden?: string[];
|
|
48
|
+
schema?: string;
|
|
49
|
+
getTableName(): string;
|
|
50
|
+
getPrimaryKey(): string;
|
|
51
|
+
beforeCreate?(data: any): Promise<any>;
|
|
52
|
+
afterCreate?(data: any, result: any): Promise<any>;
|
|
53
|
+
afterCreateMany?(records: any[]): Promise<any[]>;
|
|
54
|
+
beforeUpdate?(id: string, data: any): Promise<any>;
|
|
55
|
+
afterUpdate?(id: string, data: any, result: any): Promise<any>;
|
|
56
|
+
beforeDelete?(id: string): Promise<void>;
|
|
57
|
+
afterDelete?(id: string, result: any): Promise<any>;
|
|
58
|
+
beforeFind?(options?: any): Promise<any>;
|
|
59
|
+
afterFind?(results: any[]): Promise<any[]>;
|
|
60
|
+
} & typeof Model;
|
|
61
|
+
|
|
62
|
+
interface FindAllOptions {
|
|
63
|
+
skip?: number;
|
|
64
|
+
take?: number;
|
|
65
|
+
where?: Record<string, any>;
|
|
66
|
+
orderBy?: string | string[];
|
|
67
|
+
order?: 'asc' | 'desc' | Array<'asc' | 'desc'>;
|
|
68
|
+
select?: string[];
|
|
69
|
+
with?: string[];
|
|
70
|
+
withDeleted?: boolean;
|
|
71
|
+
/** When true, fields listed in `static hidden` are included in the result. */
|
|
72
|
+
includeHidden?: boolean;
|
|
73
|
+
}
|
|
74
|
+
interface FindByIdOptions {
|
|
75
|
+
select?: string[];
|
|
76
|
+
with?: string[];
|
|
77
|
+
withDeleted?: boolean;
|
|
78
|
+
/** When true, fields listed in `static hidden` are included in the result. */
|
|
79
|
+
includeHidden?: boolean;
|
|
80
|
+
}
|
|
81
|
+
interface CursorPaginationOptions {
|
|
82
|
+
take?: number;
|
|
83
|
+
cursor?: string | null;
|
|
84
|
+
cursorField?: string;
|
|
85
|
+
order?: 'asc' | 'desc';
|
|
86
|
+
where?: Record<string, any>;
|
|
87
|
+
select?: string[];
|
|
88
|
+
with?: string[];
|
|
89
|
+
withDeleted?: boolean;
|
|
90
|
+
/** When true, fields listed in `static hidden` are included in the result. */
|
|
91
|
+
includeHidden?: boolean;
|
|
92
|
+
}
|
|
93
|
+
interface CursorResult<T> {
|
|
94
|
+
data: T[];
|
|
95
|
+
nextCursor: string | null;
|
|
96
|
+
hasMore: boolean;
|
|
97
|
+
}
|
|
98
|
+
declare class NotFoundError extends Error {
|
|
99
|
+
readonly code = "NOT_FOUND";
|
|
100
|
+
constructor(message: string);
|
|
101
|
+
}
|
|
102
|
+
declare class Repository<T extends Model> {
|
|
103
|
+
private modelClass;
|
|
104
|
+
private db;
|
|
105
|
+
private table;
|
|
106
|
+
/** Shared registry — same Map instance as Crudora holds; populated lazily. */
|
|
107
|
+
private registry?;
|
|
108
|
+
constructor(modelClass: ModelConstructor<T>, db: any, table: any,
|
|
109
|
+
/** Shared registry — same Map instance as Crudora holds; populated lazily. */
|
|
110
|
+
registry?: Map<string, Repository<any>> | undefined);
|
|
111
|
+
/**
|
|
112
|
+
* Builds the Drizzle select-column object, merging hidden-field exclusion with
|
|
113
|
+
* an optional explicit field list. Returns `undefined` to select all columns.
|
|
114
|
+
*/
|
|
115
|
+
private buildSelectCols;
|
|
116
|
+
private buildWhere;
|
|
117
|
+
private softDeleteClause;
|
|
118
|
+
private combineWhere;
|
|
119
|
+
/**
|
|
120
|
+
* Batch-loads relations for a list of records. Uses the _in operator so the
|
|
121
|
+
* total number of DB round-trips equals the number of requested relations.
|
|
122
|
+
*/
|
|
123
|
+
private loadRelations;
|
|
124
|
+
create(data: Partial<T>): Promise<T>;
|
|
125
|
+
findById(id: string, opts?: FindByIdOptions): Promise<T | null>;
|
|
126
|
+
findAll(options?: FindAllOptions): Promise<T[]>;
|
|
127
|
+
/**
|
|
128
|
+
* Cursor-based pagination — more efficient than offset for large datasets.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* const page1 = await userRepo.findWithCursor({ take: 10 });
|
|
132
|
+
* const page2 = await userRepo.findWithCursor({ take: 10, cursor: page1.nextCursor });
|
|
133
|
+
*/
|
|
134
|
+
findWithCursor(options: CursorPaginationOptions): Promise<CursorResult<T>>;
|
|
135
|
+
update(id: string, data: Partial<T>): Promise<T>;
|
|
136
|
+
delete(id: string): Promise<T>;
|
|
137
|
+
hardDelete(id: string): Promise<T>;
|
|
138
|
+
restore(id: string): Promise<T>;
|
|
139
|
+
count(where?: any, withDeleted?: boolean): Promise<number>;
|
|
140
|
+
/** Returns the first record matching `where`, or null. Builds a direct LIMIT 1 query — does not delegate to findAll. */
|
|
141
|
+
findOne(where?: Record<string, any>, opts?: FindByIdOptions): Promise<T | null>;
|
|
142
|
+
/**
|
|
143
|
+
* Returns true if at least one record matches `where`.
|
|
144
|
+
* Uses SELECT pk LIMIT 1 — more efficient than COUNT(*) because the DB stops at the first match.
|
|
145
|
+
*/
|
|
146
|
+
exists(where?: Record<string, any>, withDeleted?: boolean): Promise<boolean>;
|
|
147
|
+
/**
|
|
148
|
+
* Inserts multiple records in a single INSERT statement.
|
|
149
|
+
* Calls `beforeCreate` for each row. Calls `afterCreateMany` once with all
|
|
150
|
+
* results — use this hook for batch-aware side effects (e.g. bulk notifications).
|
|
151
|
+
* Individual `afterCreate` is intentionally NOT called per row for performance.
|
|
152
|
+
*/
|
|
153
|
+
createMany(data: Partial<T>[]): Promise<T[]>;
|
|
154
|
+
/**
|
|
155
|
+
* Runs `fn` inside a database transaction. The callback receives a new
|
|
156
|
+
* Repository bound to the transaction connection.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* await userRepo.transaction(async (trx) => {
|
|
160
|
+
* await trx.create({ name: 'Alice' });
|
|
161
|
+
* await trx.update(id, { name: 'Bob' });
|
|
162
|
+
* });
|
|
163
|
+
*/
|
|
164
|
+
transaction<R>(fn: (trx: Repository<T>) => Promise<R>): Promise<R>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
type FieldType = 'string' | 'text' | 'integer' | 'number' | 'boolean' | 'date' | 'uuid' | 'decimal' | 'json' | 'enum' | 'bigint' | 'serial' | 'array';
|
|
168
|
+
interface FieldOptions {
|
|
169
|
+
type: FieldType;
|
|
170
|
+
required?: boolean;
|
|
171
|
+
unique?: boolean;
|
|
172
|
+
default?: any;
|
|
173
|
+
length?: number;
|
|
174
|
+
primary?: boolean;
|
|
175
|
+
nullable?: boolean;
|
|
176
|
+
precision?: number;
|
|
177
|
+
scale?: number;
|
|
178
|
+
/** Required when type is 'enum'. Lists the allowed values. */
|
|
179
|
+
enumValues?: string[];
|
|
180
|
+
}
|
|
181
|
+
interface ModelOptions {
|
|
182
|
+
tableName?: string;
|
|
183
|
+
timestamps?: boolean;
|
|
184
|
+
}
|
|
185
|
+
type Dialect = 'postgresql' | 'mysql';
|
|
186
|
+
type RelationType = 'hasOne' | 'hasMany' | 'belongsTo' | 'belongsToMany';
|
|
187
|
+
interface RelationDefinition {
|
|
188
|
+
type: RelationType;
|
|
189
|
+
/** Lazy model getter — avoids circular-import issues */
|
|
190
|
+
model: () => any;
|
|
191
|
+
/** The foreign-key column name */
|
|
192
|
+
foreignKey: string;
|
|
193
|
+
/**
|
|
194
|
+
* hasOne / hasMany: column on the owning (local) side. Defaults to the model's primary key.
|
|
195
|
+
* belongsTo : column on the related side (the "owner"). Defaults to the related model's primary key.
|
|
196
|
+
* belongsToMany: override for this model's local key (defaults to primary key).
|
|
197
|
+
*/
|
|
198
|
+
relatedKey?: string;
|
|
199
|
+
/** Lazy getter returning the pivot/junction model constructor. */
|
|
200
|
+
pivotModel?: () => any;
|
|
201
|
+
/** Column on the pivot table that points to the **related** model. */
|
|
202
|
+
pivotRelatedKey?: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
interface CrudoraLogger {
|
|
206
|
+
error(message: string, context?: Record<string, any>): void;
|
|
207
|
+
warn(message: string, context?: Record<string, any>): void;
|
|
208
|
+
info(message: string, context?: Record<string, any>): void;
|
|
209
|
+
debug(message: string, context?: Record<string, any>): void;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
declare class Crudora {
|
|
213
|
+
private db;
|
|
214
|
+
private dialect;
|
|
215
|
+
private logger;
|
|
216
|
+
private models;
|
|
217
|
+
private tables;
|
|
218
|
+
private repositories;
|
|
219
|
+
private customRoutes;
|
|
220
|
+
constructor(db: any, dialect: Dialect, logger?: CrudoraLogger);
|
|
221
|
+
registerModel(...modelClasses: ModelConstructor[]): this;
|
|
222
|
+
/**
|
|
223
|
+
* Register a model against a pre-built Drizzle table object (e.g. from `drizzle-kit introspect`).
|
|
224
|
+
* Skips `DrizzleTableBuilder` — useful when the database already exists and the schema
|
|
225
|
+
* was generated via introspection rather than Crudora decorators.
|
|
226
|
+
*
|
|
227
|
+
* Validation works if the model defines `@Field()` decorators matching the table columns.
|
|
228
|
+
* Without decorators, POST/PUT bodies pass through without Zod validation.
|
|
229
|
+
*/
|
|
230
|
+
registerTable<T extends Model>(modelClass: ModelConstructor<T>, table: any): this;
|
|
231
|
+
getRepository<T extends Model>(modelClass: ModelConstructor<T>): Repository<T>;
|
|
232
|
+
/**
|
|
233
|
+
* Returns the Drizzle table object for a registered model.
|
|
234
|
+
* Useful for raw queries that need access to columns excluded by `hidden`
|
|
235
|
+
* (e.g. fetching a password hash for authentication).
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* const usersTable = crudora.getTable(User);
|
|
239
|
+
* const [row] = await db.select().from(usersTable).where(eq(usersTable.email, email)).limit(1);
|
|
240
|
+
*/
|
|
241
|
+
getTable<T extends Model>(modelClass: ModelConstructor<T>): any;
|
|
242
|
+
generateDrizzleSchema(): string;
|
|
243
|
+
getValidationSchema<T extends Model>(modelClass: ModelConstructor<T>): z.ZodType<Partial<T>>;
|
|
244
|
+
getStrictValidationSchema<T extends Model>(modelClass: ModelConstructor<T>): z.ZodType<T>;
|
|
245
|
+
get(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
|
|
246
|
+
post(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
|
|
247
|
+
put(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
|
|
248
|
+
delete(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
|
|
249
|
+
patch(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
|
|
250
|
+
/** Runs `fn` inside a database transaction and returns its result. */
|
|
251
|
+
transaction<R>(fn: (db: any) => Promise<R>): Promise<R>;
|
|
252
|
+
generateRoutes(app: Express, basePath?: string): void;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
interface RateLimitConfig {
|
|
256
|
+
/** Sliding-window duration in milliseconds. Default: `60_000` (1 minute). */
|
|
257
|
+
windowMs?: number;
|
|
258
|
+
/** Maximum number of requests per key per window. Default: `100`. */
|
|
259
|
+
max?: number;
|
|
260
|
+
/** Message body returned with 429 responses. Default: `'Too many requests'`. */
|
|
261
|
+
message?: string;
|
|
262
|
+
/**
|
|
263
|
+
* Function that extracts the rate-limit key from a request.
|
|
264
|
+
* Default: `req.ip` (the direct connection IP, or `X-Forwarded-For` if `trust proxy` is set on Express).
|
|
265
|
+
*/
|
|
266
|
+
keyGenerator?: (req: any) => string;
|
|
267
|
+
}
|
|
268
|
+
interface CrudoraServerConfig {
|
|
269
|
+
port?: number;
|
|
270
|
+
/**
|
|
271
|
+
* CORS configuration.
|
|
272
|
+
* - `true` (default): allow all origins (`*`)
|
|
273
|
+
* - `false`: disable CORS headers entirely
|
|
274
|
+
* - `string`: allow a single specific origin, e.g. `'https://app.example.com'`
|
|
275
|
+
* - `string[]`: allow a list of origins; the request's Origin is reflected if it matches
|
|
276
|
+
*/
|
|
277
|
+
cors?: boolean | string | string[];
|
|
278
|
+
bodyParser?: boolean;
|
|
279
|
+
/**
|
|
280
|
+
* Maximum request body size accepted by the JSON and URL-encoded body parsers.
|
|
281
|
+
* Accepts a number (bytes) or a string with a unit suffix (`'100kb'`, `'5mb'`).
|
|
282
|
+
* Default: `'100kb'`.
|
|
283
|
+
*/
|
|
284
|
+
bodyParserLimit?: string | number;
|
|
285
|
+
db: any;
|
|
286
|
+
dialect: Dialect;
|
|
287
|
+
basePath?: string;
|
|
288
|
+
/**
|
|
289
|
+
* Logger for request errors and lifecycle events.
|
|
290
|
+
* - Omit (default): structured JSON written to console (compatible with log aggregators).
|
|
291
|
+
* - Pass a pino/winston instance or any object with `error`, `warn`, `info`, `debug` methods.
|
|
292
|
+
* - Pass `false` to disable all Crudora logging.
|
|
293
|
+
*/
|
|
294
|
+
logger?: CrudoraLogger | false;
|
|
295
|
+
/**
|
|
296
|
+
* Built-in sliding-window rate limiter applied to every route.
|
|
297
|
+
* - Omit / `undefined` (default): enabled with 100 requests per minute per IP.
|
|
298
|
+
* - Pass a `RateLimitConfig` object to customise the window, limit, or key function.
|
|
299
|
+
* - Pass `false` to disable rate limiting entirely (e.g. when using an external proxy-level limiter).
|
|
300
|
+
*/
|
|
301
|
+
rateLimit?: RateLimitConfig | false;
|
|
302
|
+
}
|
|
303
|
+
declare class CrudoraServer {
|
|
304
|
+
private app;
|
|
305
|
+
private crudora;
|
|
306
|
+
private config;
|
|
307
|
+
constructor(config: CrudoraServerConfig);
|
|
308
|
+
private setupMiddleware;
|
|
309
|
+
registerModel(...modelClasses: ModelConstructor[]): this;
|
|
310
|
+
registerTable<T extends Model>(modelClass: ModelConstructor<T>, table: any): this;
|
|
311
|
+
generateRoutes(): this;
|
|
312
|
+
use(middleware: any): this;
|
|
313
|
+
listen(callback?: () => void): void;
|
|
314
|
+
getApp(): Express;
|
|
315
|
+
getCrudora(): Crudora;
|
|
316
|
+
/**
|
|
317
|
+
* Returns the Drizzle table object for a registered model — delegates to `Crudora.getTable()`.
|
|
318
|
+
* Use this when you need raw DB access to columns excluded by `static hidden`
|
|
319
|
+
* (e.g. a login route that must read the password hash).
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* const usersTable = server.getTable(User);
|
|
323
|
+
* const [row] = await db.select().from(usersTable).where(eq(usersTable.email, email)).limit(1);
|
|
324
|
+
*/
|
|
325
|
+
getTable<T extends Model>(modelClass: ModelConstructor<T>): any;
|
|
326
|
+
get(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
|
|
327
|
+
post(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
|
|
328
|
+
put(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
|
|
329
|
+
delete(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
|
|
330
|
+
patch(path: string, ...handlers: Array<(req: any, res: any, next?: any) => void>): this;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
declare class SchemaGenerator {
|
|
334
|
+
static generateDrizzleSchema(models: ModelConstructor[], dialect: Dialect): string;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
declare class DrizzleTableBuilder {
|
|
338
|
+
static build(modelClass: ModelConstructor, dialect: Dialect): any;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
declare class ValidationGenerator {
|
|
342
|
+
static generateZodSchema<T extends Model>(modelClass: ModelConstructor<T>): z.ZodType<Partial<T>>;
|
|
343
|
+
static generateStrictZodSchema<T extends Model>(modelClass: ModelConstructor<T>): z.ZodType<any>;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
declare function Field(options: FieldOptions): (target: any, context: any) => void;
|
|
347
|
+
declare function getFieldMetadata(target: any): any;
|
|
348
|
+
/**
|
|
349
|
+
* Declares a one-to-many relation.
|
|
350
|
+
* @param model Lazy getter returning the related model constructor.
|
|
351
|
+
* @param foreignKey Column on the **related** table that references this model.
|
|
352
|
+
* @param localKey Column on **this** table (defaults to this model's primary key).
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* class User extends Model {
|
|
356
|
+
* @HasMany(() => Post, 'authorId')
|
|
357
|
+
* posts?: Post[];
|
|
358
|
+
* }
|
|
359
|
+
*/
|
|
360
|
+
declare function HasMany(model: () => any, foreignKey: string, localKey?: string): (target: any, propertyKey: string) => void;
|
|
361
|
+
/**
|
|
362
|
+
* Declares a one-to-one relation where the FK lives on the related table.
|
|
363
|
+
* @param model Lazy getter returning the related model constructor.
|
|
364
|
+
* @param foreignKey Column on the **related** table that references this model.
|
|
365
|
+
* @param localKey Column on **this** table (defaults to primary key).
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* class User extends Model {
|
|
369
|
+
* @HasOne(() => Profile, 'userId')
|
|
370
|
+
* profile?: Profile;
|
|
371
|
+
* }
|
|
372
|
+
*/
|
|
373
|
+
declare function HasOne(model: () => any, foreignKey: string, localKey?: string): (target: any, propertyKey: string) => void;
|
|
374
|
+
/**
|
|
375
|
+
* Declares a many-to-one (or one-to-one) relation where the FK lives on **this** table.
|
|
376
|
+
* @param model Lazy getter returning the related model constructor.
|
|
377
|
+
* @param foreignKey Column on **this** table that holds the FK value.
|
|
378
|
+
* @param ownerKey Column on the **related** table being pointed to (defaults to its primary key).
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* class Post extends Model {
|
|
382
|
+
* @BelongsTo(() => User, 'authorId')
|
|
383
|
+
* author?: User;
|
|
384
|
+
* }
|
|
385
|
+
*/
|
|
386
|
+
declare function BelongsTo(model: () => any, foreignKey: string, ownerKey?: string): (target: any, propertyKey: string) => void;
|
|
387
|
+
/**
|
|
388
|
+
* Declares a many-to-many relation through a pivot/junction model.
|
|
389
|
+
* @param model Lazy getter returning the **related** model constructor.
|
|
390
|
+
* @param pivotModel Lazy getter returning the **pivot** model constructor.
|
|
391
|
+
* @param pivotForeignKey Column on the pivot table that references **this** model.
|
|
392
|
+
* @param pivotRelatedKey Column on the pivot table that references the **related** model.
|
|
393
|
+
* @param localKey Override for this model's local key (defaults to primary key).
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* class User extends Model {
|
|
397
|
+
* @BelongsToMany(() => Role, () => UserRole, 'userId', 'roleId')
|
|
398
|
+
* roles?: Role[];
|
|
399
|
+
* }
|
|
400
|
+
*/
|
|
401
|
+
declare function BelongsToMany(model: () => any, pivotModel: () => any, pivotForeignKey: string, pivotRelatedKey: string, localKey?: string): (target: any, propertyKey: string) => void;
|
|
402
|
+
declare function getRelationMetadata(target: any): Record<string, RelationDefinition>;
|
|
403
|
+
|
|
404
|
+
export { BelongsTo, BelongsToMany, Crudora, type CrudoraLogger, CrudoraServer, type CrudoraServerConfig, type CursorPaginationOptions, type CursorResult, type Dialect, DrizzleTableBuilder, Field, type FieldOptions, type FieldType, type FindAllOptions, type FindByIdOptions, HasMany, HasOne, Model, type ModelConstructor, type ModelOptions, NotFoundError, type RateLimitConfig, type RelationDefinition, type RelationType, Repository, SchemaGenerator, ValidationGenerator, getFieldMetadata, getRelationMetadata };
|