@datrix/core 0.1.0

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.
@@ -0,0 +1,1935 @@
1
+ type QueryPrimitive = string | number | boolean | null | Date;
2
+ type ScalarValue = string | number | boolean | Date;
3
+ type QueryType = "select" | "insert" | "update" | "delete" | "count";
4
+ type ComparisonOperators<T = QueryPrimitive> = {
5
+ readonly $eq?: T;
6
+ readonly $ne?: T;
7
+ readonly $gt?: T extends number | Date ? T : never;
8
+ readonly $gte?: T extends number | Date ? T : never;
9
+ readonly $lt?: T extends number | Date ? T : never;
10
+ readonly $lte?: T extends number | Date ? T : never;
11
+ readonly $in?: readonly T[];
12
+ readonly $nin?: readonly T[];
13
+ readonly $like?: T extends string ? string : never;
14
+ readonly $ilike?: T extends string ? string : never;
15
+ readonly $startsWith?: T extends string ? string : never;
16
+ readonly $endsWith?: T extends string ? string : never;
17
+ readonly $contains?: T extends string ? string : never;
18
+ readonly $notContains?: T extends string ? string : never;
19
+ readonly $icontains?: T extends string ? string : never;
20
+ readonly $regex?: T extends string ? RegExp | string : never;
21
+ readonly $exists?: boolean;
22
+ readonly $null?: boolean;
23
+ readonly $notNull?: boolean;
24
+ };
25
+ type LogicalOperators<T extends DatrixEntry = DatrixRecord> = {
26
+ readonly $and?: WhereClause<T>[];
27
+ readonly $or?: WhereClause<T>[];
28
+ readonly $not?: WhereClause<T>;
29
+ };
30
+ type Writable<T> = {
31
+ -readonly [K in keyof T]: T[K];
32
+ };
33
+ type FallbackWhereClause = {
34
+ [key: string]: QueryPrimitive | ComparisonOperators | FallbackWhereClause | FallbackWhereClause[] | undefined;
35
+ $and?: FallbackWhereClause[];
36
+ $or?: FallbackWhereClause[];
37
+ $not?: FallbackWhereClause;
38
+ };
39
+ type TypedWhereClause<T extends DatrixEntry> = Writable<{
40
+ [K in keyof T]?: T[K] extends RelationInput<infer R extends DatrixEntry> ? WhereClause<R> : T[K] extends ScalarValue ? T[K] | ComparisonOperators<T[K]> : never;
41
+ }> & LogicalOperators<T>;
42
+ type WhereClause<T extends DatrixEntry = DatrixRecord> = DatrixRecord extends T ? FallbackWhereClause : TypedWhereClause<T>;
43
+ type SelectClause<T extends DatrixEntry = DatrixRecord> = (DatrixRecord extends T ? readonly string[] : readonly (keyof T)[]) | "*" | (DatrixRecord extends T ? string : keyof T);
44
+ type PopulateOptions<T extends DatrixEntry> = {
45
+ readonly select?: SelectClause<T> | undefined;
46
+ readonly where?: WhereClause<T> | undefined;
47
+ readonly populate?: PopulateClause<T> | undefined;
48
+ readonly limit?: number | undefined;
49
+ readonly offset?: number | undefined;
50
+ readonly orderBy?: QueryOrderBy | undefined;
51
+ };
52
+ type PopulateClause<T extends DatrixEntry = DatrixRecord> = boolean | "*" | "true" | (DatrixRecord extends T ? readonly string[] : readonly (keyof T)[]) | {
53
+ readonly [K in DatrixRecord extends T ? string : keyof T]?: PopulateOptions<T> | "*" | boolean;
54
+ };
55
+ type OrderDirection = "asc" | "desc";
56
+ type OrderByItem<T extends DatrixEntry> = {
57
+ readonly field: keyof T;
58
+ readonly direction: OrderDirection;
59
+ readonly nulls?: "first" | "last";
60
+ };
61
+ type FallbackOrderByItem = {
62
+ readonly field: string;
63
+ readonly direction: OrderDirection;
64
+ readonly nulls?: "first" | "last";
65
+ };
66
+ type QueryOrderBy<T extends DatrixEntry = DatrixRecord> = DatrixRecord extends T ? readonly FallbackOrderByItem[] : readonly OrderByItem<T>[];
67
+ type OrderByClause<T extends DatrixEntry = DatrixRecord> = DatrixRecord extends T ? readonly FallbackOrderByItem[] | Record<string, OrderDirection> | readonly string[] : QueryOrderBy<T> | Partial<Record<keyof T, OrderDirection>> | readonly (keyof T | `-${string & keyof T}`)[];
68
+ type QuerySelect<T extends DatrixEntry = DatrixRecord> = DatrixRecord extends T ? readonly string[] : readonly (keyof T)[];
69
+ type QueryPopulateOptions<T extends DatrixEntry> = {
70
+ readonly select: QuerySelect<T>;
71
+ readonly where?: WhereClause<T> | undefined;
72
+ readonly populate?: QueryPopulate<T> | undefined;
73
+ readonly limit?: number | undefined;
74
+ readonly offset?: number | undefined;
75
+ readonly orderBy?: QueryOrderBy | undefined;
76
+ };
77
+ type QueryPopulate<T extends DatrixEntry = DatrixRecord> = {
78
+ readonly [K in keyof T]?: T[K] extends RelationInput<infer R extends DatrixEntry> ? QueryPopulateOptions<R> : never;
79
+ };
80
+ type NormalizedNestedData<T extends DatrixEntry> = {
81
+ readonly data: Partial<T>;
82
+ readonly relations?: QueryRelations<T> | undefined;
83
+ };
84
+ type NormalizedRelationOperations<R extends DatrixEntry> = {
85
+ readonly connect?: readonly number[];
86
+ readonly disconnect?: readonly number[];
87
+ readonly set?: readonly number[];
88
+ readonly delete?: readonly number[];
89
+ readonly create?: readonly NormalizedNestedData<R>[];
90
+ readonly update?: readonly NormalizedRelationUpdate<R>[];
91
+ };
92
+ interface NormalizedRelationUpdate<T extends DatrixEntry> extends NormalizedNestedData<T> {
93
+ readonly where: {
94
+ readonly id: number;
95
+ };
96
+ }
97
+ type QueryRelations<T extends DatrixEntry> = {
98
+ readonly [K in keyof T]?: T[K] extends RelationInput<infer R extends DatrixEntry> ? NormalizedRelationOperations<R> : never;
99
+ };
100
+ interface QueryBase {
101
+ readonly table: string;
102
+ }
103
+ interface QuerySelectObject<T extends DatrixEntry> extends QueryBase {
104
+ readonly type: "select";
105
+ readonly select: QuerySelect<T>;
106
+ where?: WhereClause<T>;
107
+ readonly populate?: QueryPopulate<T> | undefined;
108
+ readonly orderBy?: QueryOrderBy | undefined;
109
+ readonly limit?: number | undefined;
110
+ readonly offset?: number | undefined;
111
+ readonly distinct?: boolean | undefined;
112
+ readonly groupBy?: readonly string[] | undefined;
113
+ readonly having?: WhereClause<T> | undefined;
114
+ }
115
+ interface QueryCountObject<T extends DatrixEntry> extends QueryBase {
116
+ readonly type: "count";
117
+ where?: WhereClause<T>;
118
+ readonly groupBy?: readonly string[];
119
+ readonly having?: WhereClause<T>;
120
+ }
121
+ interface QueryInsertObject<T extends DatrixEntry> extends QueryBase {
122
+ readonly type: "insert";
123
+ readonly data: readonly Partial<T>[];
124
+ readonly relations?: QueryRelations<T> | undefined;
125
+ readonly select?: QuerySelect<T> | undefined;
126
+ readonly populate?: QueryPopulate<T> | undefined;
127
+ }
128
+ interface QueryUpdateObject<T extends DatrixEntry> extends QueryBase {
129
+ readonly type: "update";
130
+ readonly data: Partial<T>;
131
+ where?: WhereClause<T>;
132
+ readonly relations?: QueryRelations<T> | undefined;
133
+ readonly select?: QuerySelect<T> | undefined;
134
+ readonly populate?: QueryPopulate<T> | undefined;
135
+ }
136
+ interface QueryDeleteObject<T extends DatrixEntry> extends QueryBase {
137
+ readonly type: "delete";
138
+ where: WhereClause<T>;
139
+ readonly select?: QuerySelect<T>;
140
+ readonly populate?: QueryPopulate<T>;
141
+ }
142
+ type QueryObject<T extends DatrixEntry = DatrixRecord> = QuerySelectObject<T> | QueryCountObject<T> | QueryInsertObject<T> | QueryUpdateObject<T> | QueryDeleteObject<T>;
143
+ type QueryObjectForType<T extends DatrixEntry, TType extends QueryType> = TType extends "select" ? QuerySelectObject<T> : TType extends "count" ? QueryCountObject<T> : TType extends "insert" ? QueryInsertObject<T> : TType extends "update" ? QueryUpdateObject<T> : TType extends "delete" ? QueryDeleteObject<T> : QueryObject<T>;
144
+
145
+ declare class DatrixError<TContext extends Record<string, unknown> = Record<string, unknown>> extends Error {
146
+ readonly code: string;
147
+ readonly timestamp: Date;
148
+ readonly operation?: string | undefined;
149
+ readonly context?: TContext | undefined;
150
+ readonly cause?: Error | undefined;
151
+ readonly suggestion?: string | undefined;
152
+ readonly expected?: string | undefined;
153
+ readonly received?: unknown;
154
+ readonly documentation?: string | undefined;
155
+ constructor(message: string, options: DatrixErrorOptions<TContext>);
156
+ toJSON(): SerializedDatrixError;
157
+ toDetailedMessage(): string;
158
+ static isDatrixError(error: unknown): error is DatrixError;
159
+ }
160
+ interface DatrixErrorOptions<TContext extends Record<string, unknown> = Record<string, unknown>> {
161
+ readonly code: string;
162
+ readonly operation?: string | undefined;
163
+ readonly context?: TContext | undefined;
164
+ readonly cause?: Error | undefined;
165
+ readonly suggestion?: string | undefined;
166
+ readonly expected?: string | undefined;
167
+ readonly received?: unknown | undefined;
168
+ readonly documentation?: string | undefined;
169
+ }
170
+ interface SerializedDatrixError {
171
+ readonly type: string;
172
+ readonly message: string;
173
+ readonly code: string;
174
+ readonly timestamp: string;
175
+ operation?: string;
176
+ context?: Record<string, unknown>;
177
+ suggestion?: string;
178
+ expected?: string;
179
+ received?: unknown;
180
+ documentation?: string;
181
+ cause?: {
182
+ readonly message: string;
183
+ readonly name: string;
184
+ };
185
+ }
186
+
187
+ type ParserType = "where" | "populate" | "fields" | "sort" | "pagination" | "query";
188
+ interface ErrorLocation {
189
+ readonly path: string;
190
+ readonly parts: readonly string[];
191
+ readonly queryParam?: string | undefined;
192
+ readonly index?: number | undefined;
193
+ readonly depth?: number | undefined;
194
+ }
195
+ interface BaseErrorContext {
196
+ readonly [key: string]: unknown;
197
+ }
198
+ interface WhereErrorContext extends BaseErrorContext {
199
+ readonly operator?: string;
200
+ readonly operatorPath?: string;
201
+ readonly validOperators?: readonly string[];
202
+ readonly arrayIndex?: number;
203
+ readonly previousOperator?: string;
204
+ readonly fieldValidationReason?: string;
205
+ }
206
+ interface PopulateErrorContext extends BaseErrorContext {
207
+ readonly relation?: string;
208
+ readonly relationPath?: string;
209
+ readonly currentDepth?: number;
210
+ readonly maxDepth?: number;
211
+ readonly nestedRelations?: readonly string[];
212
+ readonly fieldValidationReason?: string;
213
+ }
214
+ interface FieldsErrorContext extends BaseErrorContext {
215
+ readonly fieldName?: string;
216
+ readonly invalidFields?: readonly string[];
217
+ readonly validationReasons?: readonly string[];
218
+ readonly suspiciousParams?: readonly string[];
219
+ readonly fieldValidationReason?: string;
220
+ }
221
+ interface PaginationErrorContext extends BaseErrorContext {
222
+ readonly parameter?: "page" | "pageSize" | "limit" | "offset";
223
+ readonly minValue?: number;
224
+ readonly maxValue?: number;
225
+ }
226
+ interface SortErrorContext extends BaseErrorContext {
227
+ readonly sortField?: string;
228
+ readonly sortDirection?: string;
229
+ readonly invalidFields?: readonly string[];
230
+ readonly fieldValidationReason?: string;
231
+ }
232
+ type ParserErrorContext = WhereErrorContext | PopulateErrorContext | FieldsErrorContext | PaginationErrorContext | SortErrorContext | BaseErrorContext;
233
+ type ParserErrorCode = "INVALID_SYNTAX" | "INVALID_OPERATOR" | "INVALID_VALUE_TYPE" | "INVALID_VALUE_FORMAT" | "INVALID_FIELD_NAME" | "INVALID_PATH" | "MAX_DEPTH_EXCEEDED" | "MAX_LENGTH_EXCEEDED" | "MAX_SIZE_EXCEEDED" | "MIN_VALUE_VIOLATION" | "MAX_VALUE_VIOLATION" | "MISSING_REQUIRED" | "EMPTY_VALUE" | "ARRAY_INDEX_ERROR" | "CONSECUTIVE_INDEX_ERROR" | "UNKNOWN_PARAMETER" | "DUPLICATE_FIELD" | "INVALID_PAGINATION" | "PAGE_OUT_OF_RANGE" | "PARSER_INTERNAL_ERROR";
234
+ interface ParserErrorOptions {
235
+ readonly code: ParserErrorCode;
236
+ readonly parser: ParserType;
237
+ readonly location: ErrorLocation;
238
+ readonly context?: ParserErrorContext;
239
+ readonly suggestion?: string;
240
+ readonly received?: unknown;
241
+ readonly expected?: string;
242
+ }
243
+ interface SerializedParserError extends SerializedDatrixError {
244
+ readonly parser: ParserType;
245
+ readonly location: ErrorLocation;
246
+ }
247
+ declare class ParserError extends DatrixError<ParserErrorContext> {
248
+ readonly parser: ParserType;
249
+ readonly location: ErrorLocation;
250
+ constructor(message: string, options: ParserErrorOptions);
251
+ toJSON(): SerializedParserError;
252
+ toDetailedMessage(): string;
253
+ }
254
+ declare function buildErrorLocation(parts: string[], options?: {
255
+ queryParam?: string | undefined;
256
+ index?: number | undefined;
257
+ depth?: number | undefined;
258
+ }): ErrorLocation;
259
+
260
+ type RawQueryParams = Record<string, string | readonly string[] | undefined>;
261
+ interface ParsedQuery<T extends DatrixEntry = DatrixEntry> {
262
+ readonly select?: SelectClause<T>;
263
+ readonly where?: WhereClause<T>;
264
+ readonly populate?: PopulateClause<T>;
265
+ readonly orderBy?: OrderByClause<T>;
266
+ readonly page?: number;
267
+ readonly pageSize?: number;
268
+ }
269
+ interface ParserOptions {
270
+ readonly maxPageSize?: number;
271
+ readonly defaultPageSize?: number;
272
+ readonly maxPopulateDepth?: number;
273
+ readonly allowedOperators?: readonly string[];
274
+ readonly strictMode?: boolean;
275
+ }
276
+
277
+ declare const WHERE_OPERATORS: readonly ["$eq", "$ne", "$lt", "$lte", "$gt", "$gte", "$in", "$nin", "$contains", "$notContains", "$startsWith", "$endsWith", "$null", "$notNull", "$like", "$ilike", "$and", "$or", "$not"];
278
+ type WhereOperator = (typeof WHERE_OPERATORS)[number];
279
+ declare function isWhereOperator(value: string): value is WhereOperator;
280
+ interface PaginationParams {
281
+ readonly page?: number;
282
+ readonly pageSize?: number;
283
+ }
284
+ interface ParsedPagination {
285
+ readonly page: number;
286
+ readonly pageSize: number;
287
+ }
288
+ type SortParam = string | readonly string[];
289
+ type ParsedSort<T extends DatrixEntry = DatrixRecord> = readonly OrderByItem<T>[];
290
+
291
+ interface UploadFile {
292
+ readonly filename: string;
293
+ readonly originalName: string;
294
+ readonly mimetype: string;
295
+ readonly size: number;
296
+ readonly buffer: Uint8Array;
297
+ }
298
+ interface UploadResult {
299
+ readonly key: string;
300
+ readonly size: number;
301
+ readonly mimetype: string;
302
+ readonly uploadedAt: Date;
303
+ }
304
+ interface StorageProvider {
305
+ readonly name: string;
306
+ upload(file: UploadFile): Promise<UploadResult>;
307
+ delete(key: string): Promise<void>;
308
+ getUrl(key: string): string;
309
+ exists(key: string): Promise<boolean>;
310
+ }
311
+ interface MediaVariant {
312
+ readonly key: string;
313
+ readonly url: string;
314
+ readonly width: number;
315
+ readonly height: number;
316
+ readonly size: number;
317
+ readonly mimeType: string;
318
+ }
319
+ type MediaVariants<TResolutions extends string = string> = {
320
+ readonly [K in TResolutions]?: MediaVariant;
321
+ };
322
+ interface MediaEntry<TResolutions extends string = string> extends DatrixEntry {
323
+ readonly filename: string;
324
+ readonly originalName: string;
325
+ readonly mimeType: string;
326
+ readonly size: number;
327
+ readonly url: string;
328
+ readonly key: string;
329
+ readonly variants: MediaVariants<TResolutions> | null;
330
+ }
331
+ interface UploadConfig {
332
+ readonly provider: StorageProvider;
333
+ readonly modelName?: string;
334
+ readonly maxSize?: number;
335
+ readonly allowedMimeTypes?: readonly string[];
336
+ readonly permission?: SchemaPermission;
337
+ }
338
+ interface LocalProviderOptions {
339
+ readonly basePath: string;
340
+ readonly baseUrl: string;
341
+ readonly ensureDirectory?: boolean;
342
+ }
343
+ interface S3ProviderOptions {
344
+ readonly bucket: string;
345
+ readonly region: string;
346
+ readonly accessKeyId: string;
347
+ readonly secretAccessKey: string;
348
+ readonly endpoint?: string;
349
+ readonly pathPrefix?: string;
350
+ }
351
+ declare function generateUniqueFilename(originalFilename: string): string;
352
+ declare function getFileExtension(filename: string): string;
353
+ declare function sanitizeFilename(filename: string): string;
354
+ interface IUpload {
355
+ getSchemas(): Promise<SchemaDefinition[]> | SchemaDefinition[];
356
+ handleRequest(request: Request, datrix: unknown): Promise<Response>;
357
+ getModelName(): string;
358
+ injectUrls(data: unknown): Promise<unknown>;
359
+ getUrl(key: string): string;
360
+ readonly provider: StorageProvider;
361
+ }
362
+ declare function isStorageProvider(value: unknown): value is StorageProvider;
363
+
364
+ interface AuthenticatedUser<TRoles extends string = string, TUser extends DatrixEntry = DatrixEntry> extends DatrixEntry {
365
+ user: TUser;
366
+ email: string;
367
+ password: string;
368
+ passwordSalt: string;
369
+ role: TRoles;
370
+ }
371
+ interface AuthUser {
372
+ readonly id: number;
373
+ readonly email: string;
374
+ readonly role: string;
375
+ }
376
+ interface AuthContext {
377
+ readonly user: AuthUser | undefined;
378
+ readonly sessionId?: string;
379
+ readonly token?: string;
380
+ }
381
+ interface LoginResult {
382
+ readonly user: AuthUser;
383
+ readonly token?: string;
384
+ readonly sessionId?: string;
385
+ }
386
+ interface IAuthManager {
387
+ hashPassword(password: string): Promise<{
388
+ hash: string;
389
+ salt: string;
390
+ }>;
391
+ verifyPassword(password: string, hash: string, salt: string): Promise<boolean>;
392
+ login(user: AuthUser, options?: {
393
+ createToken?: boolean;
394
+ createSession?: boolean;
395
+ }): Promise<LoginResult>;
396
+ logout(sessionId: string): Promise<void>;
397
+ authenticate(request: Request): Promise<AuthContext | null>;
398
+ destroy(): Promise<void>;
399
+ }
400
+
401
+ type AdapterName = "postgres" | "mysql" | "mongodb" | "json";
402
+ type AdapterOperation = "connect" | "disconnect" | "query" | "transaction" | "populate" | "join" | "aggregation" | "migration" | "introspection" | "lock" | "read" | "write" | "validate";
403
+ type AdapterErrorCode = "ADAPTER_CONNECTION_ERROR" | "ADAPTER_QUERY_ERROR" | "ADAPTER_TRANSACTION_ERROR" | "ADAPTER_MIGRATION_ERROR" | "ADAPTER_INTROSPECTION_ERROR" | "ADAPTER_AGGREGATION_ERROR" | "ADAPTER_POPULATE_ERROR" | "ADAPTER_JOIN_ERROR" | "ADAPTER_LATERAL_JOIN_ERROR" | "ADAPTER_JSON_AGGREGATION_ERROR" | "ADAPTER_RESULT_PROCESSING_ERROR" | "ADAPTER_INVALID_POPULATE_OPTIONS" | "ADAPTER_MODEL_NOT_FOUND" | "ADAPTER_SCHEMA_NOT_FOUND" | "ADAPTER_RELATION_NOT_FOUND" | "ADAPTER_INVALID_RELATION" | "ADAPTER_TARGET_MODEL_NOT_FOUND" | "ADAPTER_JUNCTION_TABLE_NOT_FOUND" | "ADAPTER_MAX_DEPTH_EXCEEDED" | "ADAPTER_LOCK_TIMEOUT" | "ADAPTER_LOCK_ERROR" | "ADAPTER_FILE_READ_ERROR" | "ADAPTER_FILE_WRITE_ERROR" | "ADAPTER_FILE_NOT_FOUND" | "ADAPTER_INVALID_DATA" | "ADAPTER_QUERY_MISSING_DATA" | "ADAPTER_INVALID_WHERE_FIELD" | "ADAPTER_INVALID_RELATION_WHERE" | "ADAPTER_UNIQUE_CONSTRAINT" | "ADAPTER_FOREIGN_KEY_CONSTRAINT" | "ADAPTER_META_FIELD_EXISTS" | "ADAPTER_META_FIELD_NOT_FOUND";
404
+ interface AdapterErrorContext {
405
+ readonly table?: string;
406
+ readonly model?: string;
407
+ readonly field?: string;
408
+ readonly relationName?: string;
409
+ readonly targetModel?: string;
410
+ readonly junctionTable?: string;
411
+ readonly query?: Record<string, unknown>;
412
+ readonly sql?: string;
413
+ readonly params?: readonly unknown[];
414
+ readonly depth?: number;
415
+ readonly maxDepth?: number;
416
+ readonly relationPath?: string;
417
+ readonly file?: string;
418
+ readonly lockTimeout?: number;
419
+ readonly [key: string]: unknown;
420
+ }
421
+ interface DatrixAdapterErrorOptions {
422
+ readonly adapter: AdapterName;
423
+ readonly code: AdapterErrorCode;
424
+ readonly operation?: AdapterOperation | undefined;
425
+ readonly context?: AdapterErrorContext | undefined;
426
+ readonly cause?: Error | undefined;
427
+ readonly suggestion?: string | undefined;
428
+ readonly expected?: string | undefined;
429
+ readonly received?: unknown | undefined;
430
+ }
431
+ interface SerializedDatrixAdapterError extends SerializedDatrixError {
432
+ readonly adapter: AdapterName;
433
+ readonly adapterOperation?: AdapterOperation;
434
+ }
435
+ declare class DatrixAdapterError extends DatrixError<AdapterErrorContext> {
436
+ readonly adapter: AdapterName;
437
+ readonly adapterOperation?: AdapterOperation | undefined;
438
+ constructor(message: string, options: DatrixAdapterErrorOptions);
439
+ toJSON(): SerializedDatrixAdapterError;
440
+ toDetailedMessage(): string;
441
+ }
442
+
443
+ declare function truncateSqlForError(sql: string): string;
444
+ declare function throwNotConnected(params: {
445
+ adapter: AdapterName;
446
+ }): never;
447
+ declare function throwConnectionError(params: {
448
+ adapter: AdapterName;
449
+ message: string;
450
+ operation?: "connect" | "disconnect";
451
+ cause?: Error | undefined;
452
+ }): never;
453
+ declare function throwMigrationError(params: {
454
+ adapter: AdapterName;
455
+ message: string;
456
+ table?: string | undefined;
457
+ cause?: Error | undefined;
458
+ suggestion?: string | undefined;
459
+ }): never;
460
+ declare function throwIntrospectionError(params: {
461
+ adapter: AdapterName;
462
+ message: string;
463
+ table?: string | undefined;
464
+ cause?: Error | undefined;
465
+ }): never;
466
+ declare function throwQueryError(params: {
467
+ adapter: AdapterName;
468
+ message: string;
469
+ query?: QueryObject | undefined;
470
+ sql?: string | undefined;
471
+ cause?: Error | undefined;
472
+ suggestion?: string | undefined;
473
+ expected?: string | undefined;
474
+ received?: unknown;
475
+ }): never;
476
+ declare function throwQueryMissingData(params: {
477
+ adapter: AdapterName;
478
+ queryType: string;
479
+ table: string;
480
+ }): never;
481
+ declare function throwTransactionError(params: {
482
+ adapter: AdapterName;
483
+ message: string;
484
+ cause?: Error | undefined;
485
+ }): never;
486
+ declare function throwTransactionAlreadyCommitted(params: {
487
+ adapter: AdapterName;
488
+ }): never;
489
+ declare function throwTransactionAlreadyRolledBack(params: {
490
+ adapter: AdapterName;
491
+ }): never;
492
+ declare function throwTransactionSavepointNotSupported(params: {
493
+ adapter: AdapterName;
494
+ }): never;
495
+ declare function throwRawQueryNotSupported(params: {
496
+ adapter: AdapterName;
497
+ }): never;
498
+ declare function throwModelNotFound(params: {
499
+ adapter: AdapterName;
500
+ table: string;
501
+ }): never;
502
+ declare function throwSchemaNotFound(params: {
503
+ adapter: AdapterName;
504
+ modelName: string;
505
+ }): never;
506
+ declare function throwRelationNotFound(params: {
507
+ adapter: AdapterName;
508
+ relationName: string;
509
+ schemaName: string;
510
+ }): never;
511
+ declare function throwInvalidRelationType(params: {
512
+ adapter: AdapterName;
513
+ relationName: string;
514
+ fieldType: string;
515
+ schemaName: string;
516
+ }): never;
517
+ declare function throwTargetModelNotFound(params: {
518
+ adapter: AdapterName;
519
+ targetModel: string;
520
+ relationName: string;
521
+ schemaName: string;
522
+ }): never;
523
+ declare function throwJunctionTableNotFound(params: {
524
+ adapter: AdapterName;
525
+ junctionTable: string;
526
+ relationName: string;
527
+ schemaName: string;
528
+ }): never;
529
+ declare function throwMaxDepthExceeded(params: {
530
+ adapter: AdapterName;
531
+ currentDepth: number;
532
+ maxDepth: number;
533
+ relationPath: string;
534
+ }): never;
535
+ declare function throwPopulateQueryError<T extends DatrixEntry>(params: {
536
+ adapter: AdapterName;
537
+ query: QueryObject<T>;
538
+ sql: string;
539
+ cause: Error;
540
+ strategy?: string | undefined;
541
+ queryParams?: readonly unknown[] | undefined;
542
+ }): never;
543
+ declare function throwInvalidPopulateOptions(params: {
544
+ adapter: AdapterName;
545
+ relationName: string;
546
+ optionName: string;
547
+ optionValue: unknown;
548
+ }): never;
549
+ declare function throwJoinBuildError(params: {
550
+ adapter: AdapterName;
551
+ relationName: string;
552
+ relationKind: string;
553
+ cause?: Error | undefined;
554
+ }): never;
555
+ declare function throwLateralJoinError(params: {
556
+ adapter: AdapterName;
557
+ relationName: string;
558
+ cause?: Error | undefined;
559
+ }): never;
560
+ declare function throwJsonAggregationError(params: {
561
+ adapter: AdapterName;
562
+ relationName: string;
563
+ cause?: Error | undefined;
564
+ }): never;
565
+ declare function throwResultProcessingError(params: {
566
+ adapter: AdapterName;
567
+ operation: string;
568
+ cause?: Error | undefined;
569
+ }): never;
570
+ declare function throwMetaFieldAlreadyExists(params: {
571
+ adapter: AdapterName;
572
+ field: string;
573
+ table: string;
574
+ }): never;
575
+ declare function throwMetaFieldNotFound(params: {
576
+ adapter: AdapterName;
577
+ field: string;
578
+ table: string;
579
+ }): never;
580
+ declare function throwLockTimeout(params: {
581
+ adapter: AdapterName;
582
+ lockTimeout: number;
583
+ }): never;
584
+ declare function throwLockError(params: {
585
+ adapter: AdapterName;
586
+ cause?: Error | undefined;
587
+ }): never;
588
+ declare function throwFileReadError(params: {
589
+ adapter: AdapterName;
590
+ file: string;
591
+ cause?: Error | undefined;
592
+ }): never;
593
+ declare function throwFileWriteError(params: {
594
+ adapter: AdapterName;
595
+ file: string;
596
+ cause?: Error | undefined;
597
+ }): never;
598
+ declare function throwFileNotFound(params: {
599
+ adapter: AdapterName;
600
+ file: string;
601
+ }): never;
602
+ declare function throwUniqueConstraintField(params: {
603
+ adapter: AdapterName;
604
+ field: string;
605
+ value: unknown;
606
+ table: string;
607
+ }): never;
608
+ declare function throwUniqueConstraintIndex(params: {
609
+ adapter: AdapterName;
610
+ fields: readonly string[];
611
+ table: string;
612
+ }): never;
613
+ declare function throwForeignKeyConstraint(params: {
614
+ adapter: AdapterName;
615
+ foreignKey: string;
616
+ value: unknown;
617
+ targetModel: string;
618
+ table: string;
619
+ }): never;
620
+ declare function throwInvalidWhereField(params: {
621
+ adapter: AdapterName;
622
+ field: string;
623
+ schemaName: string;
624
+ availableFields: readonly string[];
625
+ }): never;
626
+ declare function throwInvalidRelationWhereSyntax(params: {
627
+ adapter: AdapterName;
628
+ relationName: string;
629
+ schemaName: string;
630
+ foreignKey: string;
631
+ }): never;
632
+
633
+ interface ExportMeta {
634
+ readonly version: number;
635
+ readonly exportedAt: string;
636
+ }
637
+ interface ExportWriter {
638
+ writeMeta(meta: ExportMeta): Promise<void>;
639
+ writeSchema(schema: SchemaDefinition): Promise<void>;
640
+ writeChunk(tableName: string, rows: Record<string, unknown>[]): Promise<void>;
641
+ finalize(): Promise<void>;
642
+ }
643
+ interface ImportReader {
644
+ readMeta(): Promise<ExportMeta>;
645
+ readSchemas(): AsyncIterable<SchemaDefinition>;
646
+ getTables(): Promise<readonly string[]>;
647
+ readChunks(tableName: string): AsyncIterable<Record<string, unknown>[]>;
648
+ }
649
+
650
+ interface QueryMetadata {
651
+ readonly rowCount?: number;
652
+ readonly affectedRows?: number;
653
+ readonly insertIds?: readonly number[];
654
+ readonly count?: number;
655
+ }
656
+ interface QueryResult<T = unknown> {
657
+ readonly rows: readonly T[];
658
+ readonly metadata: QueryMetadata;
659
+ }
660
+ interface QueryRunner {
661
+ executeQuery<TResult extends DatrixEntry>(query: QueryObject<TResult>): Promise<QueryResult<TResult>>;
662
+ executeRawQuery<TResult extends DatrixEntry>(sql: string, params: readonly unknown[]): Promise<QueryResult<TResult>>;
663
+ }
664
+ interface SchemaOperations {
665
+ createTable(schema: SchemaDefinition): Promise<void>;
666
+ dropTable(tableName: string): Promise<void>;
667
+ renameTable(from: string, to: string): Promise<void>;
668
+ alterTable(tableName: string, operations: readonly AlterOperation[]): Promise<void>;
669
+ addIndex(tableName: string, index: IndexDefinition): Promise<void>;
670
+ dropIndex(tableName: string, indexName: string): Promise<void>;
671
+ }
672
+ interface Transaction extends QueryRunner, SchemaOperations {
673
+ readonly id: string;
674
+ commit(): Promise<void>;
675
+ rollback(): Promise<void>;
676
+ savepoint(name: string): Promise<void>;
677
+ rollbackTo(name: string): Promise<void>;
678
+ release(name: string): Promise<void>;
679
+ }
680
+ type AlterOperation = {
681
+ readonly type: "addColumn";
682
+ readonly column: string;
683
+ readonly definition: FieldDefinition;
684
+ } | {
685
+ readonly type: "dropColumn";
686
+ readonly column: string;
687
+ } | {
688
+ readonly type: "modifyColumn";
689
+ readonly column: string;
690
+ readonly newDefinition: FieldDefinition;
691
+ } | {
692
+ readonly type: "renameColumn";
693
+ readonly from: string;
694
+ readonly to: string;
695
+ } | {
696
+ readonly type: "addMetaField";
697
+ readonly field: string;
698
+ readonly definition: FieldDefinition;
699
+ } | {
700
+ readonly type: "dropMetaField";
701
+ readonly field: string;
702
+ } | {
703
+ readonly type: "modifyMetaField";
704
+ readonly field: string;
705
+ readonly newDefinition: FieldDefinition;
706
+ };
707
+ type ConnectionState = "disconnected" | "connecting" | "connected" | "error";
708
+ interface DatabaseAdapter<TConfig = object> extends QueryRunner, SchemaOperations {
709
+ readonly name: string;
710
+ readonly config: TConfig;
711
+ connect(schemas: ISchemaRegistry): Promise<void>;
712
+ disconnect(): Promise<void>;
713
+ isConnected(): boolean;
714
+ getConnectionState(): ConnectionState;
715
+ beginTransaction(): Promise<Transaction>;
716
+ getTables(): Promise<readonly string[]>;
717
+ getTableSchema(tableName: string): Promise<SchemaDefinition | null>;
718
+ tableExists(tableName: string): Promise<boolean>;
719
+ exportData(writer: ExportWriter): Promise<void>;
720
+ importData(reader: ImportReader): Promise<void>;
721
+ }
722
+ declare function isDatabaseAdapter(value: unknown): value is DatabaseAdapter<unknown>;
723
+ type ParameterStyle = "numbered" | "question" | "named";
724
+ type SqlDialect = "postgres" | "mysql" | "sqlite";
725
+ interface QueryTranslator<T extends DatrixEntry = DatrixEntry> {
726
+ translate(query: QueryObject<T>): {
727
+ readonly sql: string;
728
+ readonly params: readonly unknown[];
729
+ };
730
+ translateWhere(where: WhereClause<T>, startIndex: number): {
731
+ readonly sql: string;
732
+ readonly params: readonly unknown[];
733
+ };
734
+ escapeIdentifier(identifier: string): string;
735
+ escapeValue(value: unknown): string;
736
+ getParameterPlaceholder(index: number): string;
737
+ }
738
+
739
+ interface DatrixConfig<TAdapter extends DatabaseAdapter = DatabaseAdapter> {
740
+ readonly adapter: TAdapter;
741
+ readonly schemas: readonly SchemaDefinition[];
742
+ readonly plugins?: readonly DatrixPlugin[];
743
+ readonly migration?: MigrationConfig;
744
+ readonly dev?: DevConfig;
745
+ }
746
+ interface MigrationConfig {
747
+ readonly auto?: boolean;
748
+ readonly directory?: string;
749
+ readonly modelName?: string;
750
+ }
751
+ interface DevConfig {
752
+ readonly logging?: boolean;
753
+ readonly validateQueries?: boolean;
754
+ readonly prettyErrors?: boolean;
755
+ }
756
+ type ConfigFileExport<T extends DatrixConfig = DatrixConfig> = T | {
757
+ default: T;
758
+ };
759
+ interface LoadConfigOptions {
760
+ readonly configPath?: string;
761
+ readonly environment?: "development" | "production" | "test";
762
+ readonly cwd?: string;
763
+ }
764
+ declare function isDatrixConfig(value: unknown): value is DatrixConfig;
765
+ declare function hasDefaultExport<T>(value: unknown): value is {
766
+ default: T;
767
+ };
768
+ declare const DEFAULT_MIGRATION_CONFIG: Required<MigrationConfig>;
769
+ declare const DEFAULT_DEV_CONFIG: Required<DevConfig>;
770
+
771
+ interface RawCrudOptions<T extends DatrixEntry = DatrixRecord> {
772
+ select?: SelectClause<T> | undefined;
773
+ populate?: PopulateClause<T> | undefined;
774
+ noReturning?: boolean;
775
+ action?: QueryAction;
776
+ }
777
+ interface RawFindManyOptions<T extends DatrixEntry = DatrixRecord> extends RawCrudOptions<T> {
778
+ orderBy?: OrderByClause<T> | undefined;
779
+ limit?: number | undefined;
780
+ offset?: number | undefined;
781
+ where?: WhereClause<T> | undefined;
782
+ }
783
+ type FallbackScalar = string | number | boolean | Date | null | undefined | object;
784
+ type FallbackInput = {
785
+ [key: string]: FallbackScalar | FallbackScalar[] | AnyRelationInput;
786
+ };
787
+ interface IRawCrud {
788
+ findOne<T extends DatrixEntry = DatrixRecord>(model: string, where: WhereClause<T>, options?: RawCrudOptions<T>): Promise<T | null>;
789
+ findById<T extends DatrixEntry = DatrixRecord>(model: string, id: number, options?: RawCrudOptions<T>): Promise<T | null>;
790
+ findMany<T extends DatrixEntry = DatrixRecord>(model: string, options?: RawFindManyOptions<T>): Promise<T[]>;
791
+ count<T extends DatrixEntry = DatrixRecord>(model: string, where?: WhereClause<T>): Promise<number>;
792
+ create<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, data: TInput, options?: RawCrudOptions<T>): Promise<T>;
793
+ createMany<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, data: TInput[], options?: RawCrudOptions<T>): Promise<T[]>;
794
+ update<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, id: number, data: TInput, options?: RawCrudOptions<T>): Promise<T>;
795
+ updateMany<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, where: WhereClause<T>, data: TInput, options?: RawCrudOptions<T>): Promise<T[]>;
796
+ delete<T extends DatrixEntry = DatrixRecord>(model: string, id: number, options?: RawCrudOptions<T>): Promise<T>;
797
+ deleteMany<T extends DatrixEntry = DatrixRecord>(model: string, where: WhereClause<T>, options?: RawCrudOptions<T>): Promise<T[]>;
798
+ }
799
+ interface IDatrix extends IRawCrud {
800
+ shutdown(): Promise<void>;
801
+ getConfig(): DatrixConfig;
802
+ getAdapter<T extends DatabaseAdapter = DatabaseAdapter>(): T;
803
+ getPlugins(): readonly DatrixPlugin[];
804
+ getPlugin<T extends DatrixPlugin = DatrixPlugin>(name: string): T | null;
805
+ hasPlugin(name: string): boolean;
806
+ getSchemas(): ISchemaRegistry;
807
+ getSchema(name: string): SchemaDefinition | undefined;
808
+ getMigrationConfig(): Required<MigrationConfig>;
809
+ getDevConfig(): Required<DevConfig>;
810
+ isInitialized(): boolean;
811
+ readonly raw: IRawCrud;
812
+ }
813
+
814
+ type QueryAction = "findOne" | "findMany" | "count" | "create" | "createMany" | "update" | "updateMany" | "delete" | "deleteMany";
815
+ interface QueryContext {
816
+ readonly action: QueryAction;
817
+ readonly datrix: IDatrix;
818
+ readonly metadata: Record<string, unknown>;
819
+ user?: AuthUser | undefined;
820
+ }
821
+
822
+ interface DatrixEntry {
823
+ readonly id: number;
824
+ createdAt: Date;
825
+ updatedAt: Date;
826
+ }
827
+ type FallbackValue = {
828
+ [key: string]: string | number | boolean | Date | null | FallbackValue | FallbackValue[];
829
+ };
830
+ type DatrixRecord = DatrixEntry & FallbackValue;
831
+
832
+ interface LifecycleHooks<T extends DatrixEntry = DatrixEntry> {
833
+ readonly beforeCreate?: (query: QueryInsertObject<T>, ctx: QueryContext) => Promise<QueryInsertObject<T>> | QueryInsertObject<T>;
834
+ readonly afterCreate?: (records: T[], ctx: QueryContext) => Promise<T[]> | T[];
835
+ readonly beforeUpdate?: (query: QueryUpdateObject<T>, ctx: QueryContext) => Promise<QueryUpdateObject<T>> | QueryUpdateObject<T>;
836
+ readonly afterUpdate?: (records: T[], ctx: QueryContext) => Promise<T[]> | T[];
837
+ readonly beforeDelete?: (query: QueryDeleteObject<T>, ctx: QueryContext) => Promise<QueryDeleteObject<T>> | QueryDeleteObject<T>;
838
+ readonly afterDelete?: (records: T[], ctx: QueryContext) => Promise<void> | void;
839
+ readonly beforeFind?: (query: QuerySelectObject<T>, ctx: QueryContext) => Promise<QuerySelectObject<T>> | QuerySelectObject<T>;
840
+ readonly afterFind?: (records: T[], ctx: QueryContext) => Promise<T[]> | T[];
841
+ }
842
+
843
+ declare const MAX_FIELD_NAME_LENGTH = 63;
844
+ declare const MAX_WHERE_VALUE_LENGTH = 10000;
845
+ declare const MAX_LOGICAL_NESTING_DEPTH = 10;
846
+ declare const MAX_ARRAY_INDEX = 1000;
847
+ declare const COMPARISON_OPERATORS: readonly ["$eq", "$ne", "$gt", "$gte", "$lt", "$lte"];
848
+ declare const STRING_OPERATORS: readonly ["$contains", "$notContains", "$startsWith", "$endsWith", "$like", "$ilike"];
849
+ declare const ARRAY_OPERATORS: readonly ["$in", "$nin"];
850
+ declare const NULL_OPERATORS: readonly ["$null", "$notNull"];
851
+ declare const LOGICAL_OPERATORS: readonly ["$and", "$or", "$not"];
852
+ declare const ALL_WHERE_OPERATORS: readonly ["$eq", "$ne", "$gt", "$gte", "$lt", "$lte", "$contains", "$notContains", "$startsWith", "$endsWith", "$like", "$ilike", "$in", "$nin", "$null", "$notNull", "$and", "$or", "$not"];
853
+ type OperatorValueType = "any" | "array" | "number" | "string" | "boolean" | "conditions";
854
+ declare const OPERATOR_VALUE_TYPES: Record<string, OperatorValueType>;
855
+ declare function isValidWhereOperator(operator: string): operator is (typeof ALL_WHERE_OPERATORS)[number];
856
+ declare function isLogicalOperator(operator: string): operator is (typeof LOGICAL_OPERATORS)[number];
857
+ declare function requiresArrayValue(operator: string): boolean;
858
+ declare function requiresConditions(operator: string): boolean;
859
+ declare function getOperatorValueType(operator: string): OperatorValueType | undefined;
860
+ declare const FORJA_META_MODEL = "_datrix";
861
+ declare const FORJA_META_KEY_PREFIX = "_schema_";
862
+ declare const FIELD_NAME_PATTERN: RegExp;
863
+ declare const CONTROL_CHARS_PATTERN: RegExp;
864
+ declare const RESERVED_FIELD_NAMES: readonly ["__proto__", "constructor", "prototype"];
865
+ type FieldInvalidReason = "EMPTY" | "TOO_LONG" | "RESERVED_FIELD" | "CONTROL_CHARS" | "INVALID_FORMAT";
866
+ type FieldValidationResult = {
867
+ valid: true;
868
+ } | {
869
+ valid: false;
870
+ reason: FieldInvalidReason;
871
+ detail?: string;
872
+ };
873
+ declare function validateFieldName(fieldName: string): FieldValidationResult;
874
+ declare function isValidFieldName(fieldName: string): boolean;
875
+
876
+ type MigrationStatus = "pending" | "running" | "completed" | "failed";
877
+ interface MigrationMetadata {
878
+ readonly name: string;
879
+ readonly version: string;
880
+ readonly timestamp: number;
881
+ readonly description?: string;
882
+ readonly author?: string;
883
+ }
884
+ interface MigrationContext {
885
+ readonly version: string;
886
+ readonly dryRun?: boolean;
887
+ }
888
+ type MigrationOperationType = "createTable" | "dropTable" | "alterTable" | "createIndex" | "dropIndex" | "renameTable" | "raw" | "dataTransfer";
889
+ interface BaseMigrationOperation {
890
+ readonly type: MigrationOperationType;
891
+ }
892
+ interface CreateTableOperation extends BaseMigrationOperation {
893
+ readonly type: "createTable";
894
+ readonly schema: SchemaDefinition;
895
+ }
896
+ interface DropTableOperation extends BaseMigrationOperation {
897
+ readonly type: "dropTable";
898
+ readonly tableName: string;
899
+ }
900
+ interface AlterTableOperation extends BaseMigrationOperation {
901
+ readonly type: "alterTable";
902
+ readonly tableName: string;
903
+ readonly operations: readonly AlterOperation[];
904
+ }
905
+ interface CreateIndexOperation extends BaseMigrationOperation {
906
+ readonly type: "createIndex";
907
+ readonly tableName: string;
908
+ readonly index: IndexDefinition;
909
+ }
910
+ interface DropIndexOperation extends BaseMigrationOperation {
911
+ readonly type: "dropIndex";
912
+ readonly tableName: string;
913
+ readonly indexName: string;
914
+ }
915
+ interface RenameTableOperation extends BaseMigrationOperation {
916
+ readonly type: "renameTable";
917
+ readonly from: string;
918
+ readonly to: string;
919
+ }
920
+ interface RawSQLOperation extends BaseMigrationOperation {
921
+ readonly type: "raw";
922
+ readonly sql: string;
923
+ readonly params?: readonly unknown[];
924
+ }
925
+ interface DataTransferOperation extends BaseMigrationOperation {
926
+ readonly type: "dataTransfer";
927
+ readonly description: string;
928
+ readonly execute: (runner: QueryRunner) => Promise<void>;
929
+ }
930
+ type MigrationOperation = CreateTableOperation | DropTableOperation | AlterTableOperation | CreateIndexOperation | DropIndexOperation | RenameTableOperation | RawSQLOperation | DataTransferOperation;
931
+ interface Migration {
932
+ readonly metadata: MigrationMetadata;
933
+ readonly operations: readonly MigrationOperation[];
934
+ }
935
+ type SchemaDiffType = "tableAdded" | "tableRemoved" | "tableRenamed" | "fieldAdded" | "fieldRemoved" | "fieldModified" | "fieldRenamed" | "indexAdded" | "indexRemoved";
936
+ interface BaseSchemaDiff {
937
+ readonly type: SchemaDiffType;
938
+ }
939
+ interface TableAddedDiff extends BaseSchemaDiff {
940
+ readonly type: "tableAdded";
941
+ readonly schema: SchemaDefinition;
942
+ }
943
+ interface TableRemovedDiff extends BaseSchemaDiff {
944
+ readonly type: "tableRemoved";
945
+ readonly tableName: string;
946
+ }
947
+ interface TableRenamedDiff extends BaseSchemaDiff {
948
+ readonly type: "tableRenamed";
949
+ readonly from: string;
950
+ readonly to: string;
951
+ }
952
+ interface FieldAddedDiff extends BaseSchemaDiff {
953
+ readonly type: "fieldAdded";
954
+ readonly tableName: string;
955
+ readonly fieldName: string;
956
+ readonly definition: FieldDefinition;
957
+ }
958
+ interface FieldRemovedDiff extends BaseSchemaDiff {
959
+ readonly type: "fieldRemoved";
960
+ readonly tableName: string;
961
+ readonly fieldName: string;
962
+ readonly definition: FieldDefinition;
963
+ }
964
+ interface FieldModifiedDiff extends BaseSchemaDiff {
965
+ readonly type: "fieldModified";
966
+ readonly tableName: string;
967
+ readonly fieldName: string;
968
+ readonly oldDefinition: FieldDefinition;
969
+ readonly newDefinition: FieldDefinition;
970
+ }
971
+ interface FieldRenamedDiff extends BaseSchemaDiff {
972
+ readonly type: "fieldRenamed";
973
+ readonly tableName: string;
974
+ readonly from: string;
975
+ readonly to: string;
976
+ }
977
+ interface IndexAddedDiff extends BaseSchemaDiff {
978
+ readonly type: "indexAdded";
979
+ readonly tableName: string;
980
+ readonly index: IndexDefinition;
981
+ }
982
+ interface IndexRemovedDiff extends BaseSchemaDiff {
983
+ readonly type: "indexRemoved";
984
+ readonly tableName: string;
985
+ readonly indexName: string;
986
+ }
987
+ type SchemaDiff = TableAddedDiff | TableRemovedDiff | TableRenamedDiff | FieldAddedDiff | FieldRemovedDiff | FieldModifiedDiff | FieldRenamedDiff | IndexAddedDiff | IndexRemovedDiff;
988
+ interface SchemaComparison {
989
+ readonly differences: readonly SchemaDiff[];
990
+ readonly hasChanges: boolean;
991
+ }
992
+ interface MigrationHistoryRecord {
993
+ readonly id: number;
994
+ readonly name: string;
995
+ readonly version: string;
996
+ readonly appliedAt: Date;
997
+ readonly executionTime: number;
998
+ readonly status: MigrationStatus;
999
+ readonly checksum?: string;
1000
+ readonly error?: string;
1001
+ }
1002
+ interface MigrationExecutionResult {
1003
+ readonly migration: Migration;
1004
+ readonly status: MigrationStatus;
1005
+ readonly executionTime: number;
1006
+ readonly error?: Error;
1007
+ readonly warnings?: readonly string[];
1008
+ }
1009
+ interface MigrationFilePlan {
1010
+ readonly migrations: readonly Migration[];
1011
+ readonly target?: string;
1012
+ }
1013
+ declare class MigrationSystemError extends Error {
1014
+ readonly code: "MIGRATION_ERROR" | "DIFF_ERROR" | "GENERATION_ERROR" | "VALIDATION_ERROR";
1015
+ readonly details?: unknown | undefined;
1016
+ constructor(message: string, code: "MIGRATION_ERROR" | "DIFF_ERROR" | "GENERATION_ERROR" | "VALIDATION_ERROR", details?: unknown | undefined);
1017
+ }
1018
+ interface SchemaDiffer {
1019
+ compare(oldSchema: Record<string, SchemaDefinition>, newSchema: Record<string, SchemaDefinition>): SchemaComparison;
1020
+ isFieldModified(oldField: FieldDefinition, newField: FieldDefinition): boolean;
1021
+ }
1022
+ interface MigrationGenerator {
1023
+ generate(differences: readonly SchemaDiff[], metadata: Omit<MigrationMetadata, "timestamp">): Migration;
1024
+ generateOperations(differences: readonly SchemaDiff[]): readonly MigrationOperation[];
1025
+ generateFile(migration: Migration): string;
1026
+ }
1027
+ interface MigrationRunner {
1028
+ getPending(): Promise<readonly Migration[]>;
1029
+ getApplied(): Promise<readonly MigrationHistoryRecord[]>;
1030
+ runPending(options?: {
1031
+ readonly target?: string;
1032
+ readonly dryRun?: boolean;
1033
+ }): Promise<readonly MigrationExecutionResult[]>;
1034
+ runOne(migration: Migration): Promise<MigrationExecutionResult>;
1035
+ getPlan(options?: {
1036
+ readonly target?: string;
1037
+ }): MigrationFilePlan;
1038
+ }
1039
+ interface MigrationHistory {
1040
+ initialize(): Promise<void>;
1041
+ record(migration: Migration, executionTime: number, status: MigrationStatus, error?: Error): Promise<void>;
1042
+ getAll(): Promise<readonly MigrationHistoryRecord[]>;
1043
+ getLast(): Promise<MigrationHistoryRecord | undefined>;
1044
+ isApplied(version: string): Promise<boolean>;
1045
+ calculateChecksum(migration: Migration): string;
1046
+ verifyChecksum(migration: Migration, record: MigrationHistoryRecord): boolean;
1047
+ }
1048
+
1049
+ interface IApiPlugin<TRole extends string = string> extends DatrixPlugin {
1050
+ readonly name: string;
1051
+ readonly version: string;
1052
+ readonly authManager?: IAuthManager | undefined;
1053
+ readonly upload?: IUpload | undefined;
1054
+ readonly user: AuthUser | null;
1055
+ readonly datrix: IDatrix;
1056
+ readonly authDefaultPermission: DefaultPermission<TRole> | undefined;
1057
+ readonly authDefaultRole: TRole | undefined;
1058
+ readonly excludeSchemas: readonly string[];
1059
+ isEnabled(): boolean;
1060
+ isAuthEnabled(): boolean;
1061
+ setUser(user: AuthUser | null): void;
1062
+ getAuthManager(): IAuthManager | undefined;
1063
+ handleRequest(request: Request, datrix: IDatrix): Promise<Response>;
1064
+ }
1065
+
1066
+ declare const DEFAULT_API_CONFIG: {
1067
+ readonly enabled: true;
1068
+ readonly prefix: "/api";
1069
+ readonly defaultPageSize: 25;
1070
+ readonly maxPageSize: 100;
1071
+ readonly maxPopulateDepth: 5;
1072
+ readonly autoRoutes: true;
1073
+ readonly excludeSchemas: readonly [];
1074
+ };
1075
+ declare const DEFAULT_API_AUTH_CONFIG: {
1076
+ readonly enabled: true;
1077
+ readonly userSchema: {
1078
+ readonly name: "user";
1079
+ readonly email: "email";
1080
+ };
1081
+ readonly jwt: {
1082
+ readonly expiresIn: "7d";
1083
+ readonly algorithm: "HS256";
1084
+ };
1085
+ readonly session: {
1086
+ readonly store: "memory";
1087
+ readonly maxAge: 86400;
1088
+ readonly checkPeriod: 3600;
1089
+ readonly prefix: "datrix:session:";
1090
+ };
1091
+ readonly password: {
1092
+ readonly iterations: 100000;
1093
+ readonly keyLength: 64;
1094
+ readonly minLength: 8;
1095
+ };
1096
+ readonly endpoints: {
1097
+ readonly login: "/auth/login";
1098
+ readonly register: "/auth/register";
1099
+ readonly logout: "/auth/logout";
1100
+ readonly me: "/auth/me";
1101
+ readonly disableRegister: false;
1102
+ };
1103
+ };
1104
+
1105
+ type ResponseData<T = unknown> = {
1106
+ data: T;
1107
+ meta: {
1108
+ total: number;
1109
+ page: number;
1110
+ pageSize: number;
1111
+ totalPages: number;
1112
+ };
1113
+ };
1114
+
1115
+ type PermissionAction = "create" | "read" | "update" | "delete";
1116
+ type FieldPermissionAction = "read" | "write";
1117
+ interface PermissionContext<TRecord extends DatrixEntry = DatrixEntry> {
1118
+ readonly user: AuthUser | undefined;
1119
+ readonly record?: TRecord;
1120
+ readonly input?: Partial<TRecord>;
1121
+ readonly action: PermissionAction;
1122
+ readonly id?: number | string | null;
1123
+ readonly datrix: unknown;
1124
+ }
1125
+ type PermissionFn<TRecord extends DatrixEntry = DatrixEntry> = (ctx: PermissionContext<TRecord>) => boolean | Promise<boolean>;
1126
+ type PermissionValue<TRoles extends string = string, TRecord extends DatrixEntry = DatrixEntry> = boolean | readonly TRoles[] | PermissionFn<TRecord> | readonly (TRoles | PermissionFn<TRecord>)[];
1127
+ interface SchemaPermission<TRoles extends string = string, TRecord extends DatrixEntry = DatrixEntry> {
1128
+ readonly create?: PermissionValue<TRoles, TRecord>;
1129
+ readonly read?: PermissionValue<TRoles, TRecord>;
1130
+ readonly update?: PermissionValue<TRoles, TRecord>;
1131
+ readonly delete?: PermissionValue<TRoles, TRecord>;
1132
+ }
1133
+ interface FieldPermission<TRoles extends string = string, TRecord extends DatrixEntry = DatrixEntry> {
1134
+ readonly read?: PermissionValue<TRoles, TRecord>;
1135
+ readonly write?: PermissionValue<TRoles, TRecord>;
1136
+ }
1137
+ interface DefaultPermission<TRoles extends string = string> {
1138
+ readonly create?: PermissionValue<TRoles>;
1139
+ readonly read?: PermissionValue<TRoles>;
1140
+ readonly update?: PermissionValue<TRoles>;
1141
+ readonly delete?: PermissionValue<TRoles>;
1142
+ }
1143
+ interface PermissionCheckResult {
1144
+ readonly allowed: boolean;
1145
+ readonly reason?: string | undefined;
1146
+ }
1147
+ interface FieldPermissionCheckResult {
1148
+ readonly allowed: boolean;
1149
+ readonly deniedFields?: readonly string[] | undefined;
1150
+ }
1151
+ declare function isPermissionFn<TRecord extends DatrixEntry = DatrixEntry>(value: unknown): value is PermissionFn<TRecord>;
1152
+
1153
+ declare const RESERVED_FIELDS: readonly ["id", "createdAt", "updatedAt"];
1154
+ type ReservedFieldName = (typeof RESERVED_FIELDS)[number];
1155
+
1156
+ type FieldType = "string" | "number" | "boolean" | "date" | "json" | "enum" | "array" | "relation" | "file";
1157
+ interface BaseFieldDefinition<TRoles extends string = string> {
1158
+ readonly required?: boolean;
1159
+ readonly default?: unknown;
1160
+ readonly description?: string;
1161
+ readonly hidden?: boolean;
1162
+ readonly permission?: FieldPermission<TRoles>;
1163
+ }
1164
+ interface StringField<TRoles extends string = string> extends BaseFieldDefinition<TRoles> {
1165
+ readonly type: "string";
1166
+ readonly minLength?: number;
1167
+ readonly maxLength?: number;
1168
+ readonly pattern?: RegExp;
1169
+ readonly unique?: boolean;
1170
+ readonly validator?: (value: string) => true | string;
1171
+ readonly errorMessage?: string;
1172
+ }
1173
+ interface ForeignKeyReference {
1174
+ readonly table: string;
1175
+ readonly column?: string;
1176
+ readonly onDelete?: "cascade" | "setNull" | "restrict" | undefined;
1177
+ readonly onUpdate?: "cascade" | "restrict" | undefined;
1178
+ }
1179
+ interface NumberField<TRoles extends string = string> extends BaseFieldDefinition<TRoles> {
1180
+ readonly type: "number";
1181
+ readonly min?: number;
1182
+ readonly max?: number;
1183
+ readonly integer?: boolean;
1184
+ readonly unique?: boolean;
1185
+ readonly autoIncrement?: boolean;
1186
+ readonly validator?: (value: number) => true | string;
1187
+ readonly references?: ForeignKeyReference;
1188
+ }
1189
+ interface BooleanField<TRoles extends string = string> extends BaseFieldDefinition<TRoles> {
1190
+ readonly type: "boolean";
1191
+ }
1192
+ interface DateField<TRoles extends string = string> extends BaseFieldDefinition<TRoles> {
1193
+ readonly type: "date";
1194
+ readonly min?: Date;
1195
+ readonly max?: Date;
1196
+ }
1197
+ interface JsonField<TRoles extends string = string> extends BaseFieldDefinition<TRoles> {
1198
+ readonly type: "json";
1199
+ readonly schema?: Record<string, unknown>;
1200
+ }
1201
+ interface EnumField<T extends readonly string[] = readonly string[], TRoles extends string = string> extends BaseFieldDefinition<TRoles> {
1202
+ readonly type: "enum";
1203
+ readonly values: T;
1204
+ }
1205
+ interface ArrayField<TRoles extends string = string> extends BaseFieldDefinition<TRoles> {
1206
+ readonly type: "array";
1207
+ readonly items: FieldDefinition<TRoles>;
1208
+ readonly minItems?: number;
1209
+ readonly maxItems?: number;
1210
+ readonly unique?: boolean;
1211
+ }
1212
+ type RelationKind = "hasOne" | "hasMany" | "belongsTo" | "manyToMany";
1213
+ interface FileFieldOptions {
1214
+ readonly allowedTypes?: readonly string[];
1215
+ readonly maxSize?: number;
1216
+ }
1217
+ interface RelationField<TRoles extends string = string> extends BaseFieldDefinition<TRoles> {
1218
+ readonly type: "relation";
1219
+ readonly model: string;
1220
+ readonly kind: RelationKind;
1221
+ readonly foreignKey?: string;
1222
+ readonly through?: string;
1223
+ readonly onDelete?: "cascade" | "setNull" | "restrict";
1224
+ readonly onUpdate?: "cascade" | "restrict";
1225
+ readonly fileOptions?: FileFieldOptions;
1226
+ }
1227
+ type RelationIdRef = number | {
1228
+ id: number;
1229
+ };
1230
+ type RelationIdRefs = RelationIdRef | RelationIdRef[];
1231
+ type RelationBelongsTo<T extends DatrixEntry> = RelationIdRef | null | {
1232
+ connect?: RelationIdRef;
1233
+ set?: RelationIdRef;
1234
+ disconnect?: true;
1235
+ create?: Partial<T>;
1236
+ update?: {
1237
+ where: {
1238
+ id: number;
1239
+ };
1240
+ data: Partial<T>;
1241
+ };
1242
+ delete?: RelationIdRef;
1243
+ };
1244
+ type RelationHasOne<T extends DatrixEntry> = RelationBelongsTo<T>;
1245
+ type RelationHasMany<T extends DatrixEntry> = RelationIdRefs | {
1246
+ connect?: RelationIdRefs;
1247
+ disconnect?: RelationIdRefs;
1248
+ set?: RelationIdRefs;
1249
+ create?: Partial<T> | Partial<T>[];
1250
+ update?: {
1251
+ where: {
1252
+ id: number;
1253
+ };
1254
+ data: Partial<T>;
1255
+ } | {
1256
+ where: {
1257
+ id: number;
1258
+ };
1259
+ data: Partial<T>;
1260
+ }[];
1261
+ delete?: RelationIdRefs;
1262
+ };
1263
+ type RelationManyToMany<T extends DatrixEntry> = RelationHasMany<T>;
1264
+ type RelationInput<T extends DatrixEntry> = RelationBelongsTo<T> | RelationHasMany<T>;
1265
+ type AnyRelationInput = RelationIdRefs | null | AnyRelationInputObject;
1266
+ type AnyRelationInputObject = {
1267
+ connect?: RelationIdRefs;
1268
+ disconnect?: RelationIdRefs | true;
1269
+ set?: RelationIdRefs;
1270
+ delete?: RelationIdRefs;
1271
+ create?: Record<string, unknown> | Record<string, unknown>[];
1272
+ update?: {
1273
+ where: {
1274
+ id: number;
1275
+ };
1276
+ data: Record<string, unknown>;
1277
+ } | {
1278
+ where: {
1279
+ id: number;
1280
+ };
1281
+ data: Record<string, unknown>;
1282
+ }[];
1283
+ };
1284
+ type NormalizedRelationId = {
1285
+ id: string | number;
1286
+ };
1287
+ declare function normalizeRelationId(ref: RelationIdRef): NormalizedRelationId;
1288
+ declare function normalizeRelationIds(refs: RelationIdRefs): NormalizedRelationId[];
1289
+ declare function isRelationIdRef(value: unknown): value is RelationIdRef;
1290
+ declare function isRelationIdRefs(value: unknown): value is RelationIdRefs;
1291
+ interface FileField<TRoles extends string = string> extends BaseFieldDefinition<TRoles> {
1292
+ readonly type: "file";
1293
+ readonly allowedTypes?: readonly string[];
1294
+ readonly maxSize?: number;
1295
+ readonly multiple?: boolean;
1296
+ }
1297
+ type FieldDefinition<TRoles extends string = string> = StringField<TRoles> | NumberField<TRoles> | BooleanField<TRoles> | DateField<TRoles> | JsonField<TRoles> | EnumField<readonly string[], TRoles> | ArrayField<TRoles> | RelationField<TRoles> | FileField<TRoles>;
1298
+ interface IndexDefinition {
1299
+ readonly name?: string;
1300
+ readonly fields: readonly string[];
1301
+ readonly unique?: boolean;
1302
+ readonly type?: "btree" | "hash" | "gist" | "gin";
1303
+ }
1304
+
1305
+ interface SchemaDefinition<TRoles extends string = string, TFields extends Record<string, FieldDefinition<TRoles>> = Record<string, FieldDefinition<TRoles>>> {
1306
+ readonly name: string;
1307
+ readonly fields: TFields;
1308
+ readonly indexes?: readonly IndexDefinition[];
1309
+ readonly hooks?: LifecycleHooks;
1310
+ readonly timestamps?: boolean;
1311
+ readonly softDelete?: boolean;
1312
+ readonly tableName?: string;
1313
+ readonly permission?: SchemaPermission<TRoles>;
1314
+ readonly _isJunctionTable?: boolean;
1315
+ }
1316
+ declare function defineSchema<const T extends SchemaDefinition>(schema: T): T;
1317
+ interface ISchemaRegistry {
1318
+ register(schema: SchemaDefinition): SchemaDefinition;
1319
+ get(name: string): SchemaDefinition | undefined;
1320
+ getWithTableName(modelName: string): {
1321
+ schema: SchemaDefinition;
1322
+ tableName: string;
1323
+ } | undefined;
1324
+ getByTableName(tableName: string): {
1325
+ schema: SchemaDefinition;
1326
+ tableName: string;
1327
+ } | undefined;
1328
+ has(name: string): boolean;
1329
+ getAll(): readonly SchemaDefinition[];
1330
+ getNames(): readonly string[];
1331
+ readonly size: number;
1332
+ findModelByTableName(tableName: string | null): string | null;
1333
+ getRelatedSchemas(schemaName: string): readonly string[];
1334
+ isLocked(): boolean;
1335
+ getCachedSelectFields<T extends DatrixEntry>(modelName: string): QuerySelect<T>;
1336
+ }
1337
+ interface FieldMetadata {
1338
+ readonly name: string;
1339
+ readonly type: FieldType;
1340
+ readonly required: boolean;
1341
+ readonly unique: boolean;
1342
+ readonly hasDefault: boolean;
1343
+ readonly isRelation: boolean;
1344
+ readonly isArray: boolean;
1345
+ }
1346
+ interface SchemaDefinitionValidationResult {
1347
+ readonly valid: boolean;
1348
+ readonly errors: readonly SchemaValidationError[];
1349
+ }
1350
+ interface SchemaValidationError {
1351
+ readonly field?: string;
1352
+ readonly message: string;
1353
+ readonly code: string;
1354
+ }
1355
+ declare function validateSchemaDefinition(schema: SchemaDefinition): SchemaDefinitionValidationResult;
1356
+ declare function sortSchemasByDependency(schemas: SchemaDefinition[]): SchemaDefinition[];
1357
+
1358
+ interface PluginContext {
1359
+ readonly adapter: DatabaseAdapter;
1360
+ readonly schemas: ISchemaRegistry;
1361
+ readonly config: DatrixConfig;
1362
+ }
1363
+ interface DatrixPlugin<TOptions = Record<string, unknown>> {
1364
+ readonly name: string;
1365
+ readonly version: string;
1366
+ readonly options: TOptions;
1367
+ init(context: PluginContext): Promise<void>;
1368
+ destroy(): Promise<void>;
1369
+ getSchemas?(): Promise<SchemaDefinition[]>;
1370
+ extendSchemas?(context: SchemaExtensionContext): Promise<SchemaExtension[]>;
1371
+ onSchemaLoad?(schemas: ISchemaRegistry): Promise<void>;
1372
+ onCreateQueryContext?(context: QueryContext): Promise<QueryContext>;
1373
+ onBeforeQuery?<T extends DatrixEntry>(query: QueryObject<T>, context: QueryContext): Promise<QueryObject<T>>;
1374
+ onAfterQuery?<TResult extends DatrixEntry>(result: TResult, context: QueryContext): Promise<TResult>;
1375
+ }
1376
+ declare class PluginError extends Error {
1377
+ readonly code: string;
1378
+ readonly pluginName: string | undefined;
1379
+ readonly details: unknown | undefined;
1380
+ constructor(message: string, options?: {
1381
+ code?: string;
1382
+ pluginName?: string;
1383
+ details?: unknown;
1384
+ });
1385
+ }
1386
+ declare function isDatrixPlugin(value: unknown): value is DatrixPlugin;
1387
+ type PluginFactory<TOptions = Record<string, unknown>> = (options: TOptions) => DatrixPlugin<TOptions>;
1388
+ declare class UploadError extends PluginError {
1389
+ constructor(message: string, details?: unknown);
1390
+ }
1391
+ declare class PluginRegistry {
1392
+ private readonly plugins;
1393
+ register(plugin: DatrixPlugin): void;
1394
+ get(name: string): DatrixPlugin | undefined;
1395
+ has(name: string): boolean;
1396
+ getAll(): readonly DatrixPlugin[];
1397
+ initAll(context: PluginContext): Promise<void>;
1398
+ destroyAll(): Promise<void>;
1399
+ }
1400
+ interface SchemaExtension {
1401
+ readonly targetSchema: string;
1402
+ readonly fields?: Record<string, FieldDefinition>;
1403
+ readonly removeFields?: readonly string[];
1404
+ readonly modifyFields?: Record<string, Partial<FieldDefinition>>;
1405
+ readonly indexes?: readonly IndexDefinition[];
1406
+ }
1407
+ type SchemaModifier = (schema: SchemaDefinition) => {
1408
+ readonly fields?: Record<string, FieldDefinition>;
1409
+ readonly indexes?: readonly IndexDefinition[];
1410
+ readonly removeFields?: readonly string[];
1411
+ readonly modifyFields?: Record<string, Partial<FieldDefinition>>;
1412
+ };
1413
+ interface SchemaPattern {
1414
+ readonly names?: readonly string[];
1415
+ readonly prefix?: string;
1416
+ readonly suffix?: string;
1417
+ readonly exclude?: readonly string[];
1418
+ readonly custom?: (schema: SchemaDefinition) => boolean;
1419
+ }
1420
+ interface SchemaExtensionContext {
1421
+ readonly schemas: ReadonlyArray<SchemaDefinition>;
1422
+ extendAll(modifier: SchemaModifier): SchemaExtension[];
1423
+ extendWhere(predicate: (schema: SchemaDefinition) => boolean, modifier: SchemaModifier): SchemaExtension[];
1424
+ extendByPattern(pattern: SchemaPattern, modifier: SchemaModifier): SchemaExtension[];
1425
+ }
1426
+
1427
+ declare class CLIError extends Error {
1428
+ readonly code: "INVALID_COMMAND" | "MISSING_ARGUMENT" | "FILE_ERROR" | "CONFIG_ERROR" | "EXECUTION_ERROR";
1429
+ readonly details?: unknown | undefined;
1430
+ constructor(message: string, code: "INVALID_COMMAND" | "MISSING_ARGUMENT" | "FILE_ERROR" | "CONFIG_ERROR" | "EXECUTION_ERROR", details?: unknown | undefined);
1431
+ }
1432
+ interface ParsedArgs {
1433
+ readonly command?: string | undefined;
1434
+ readonly subcommand?: string | undefined;
1435
+ readonly args: readonly string[];
1436
+ readonly options: Record<string, string | boolean>;
1437
+ }
1438
+ interface BaseCommandOptions {
1439
+ readonly config?: string | undefined;
1440
+ readonly verbose?: boolean | undefined;
1441
+ }
1442
+ interface MigrateCommandOptions extends BaseCommandOptions {
1443
+ readonly down?: boolean | undefined;
1444
+ readonly to?: string | undefined;
1445
+ readonly dryRun?: boolean | undefined;
1446
+ }
1447
+ interface GenerateCommandOptions extends BaseCommandOptions {
1448
+ readonly output?: string | undefined;
1449
+ }
1450
+ interface DevCommandOptions extends BaseCommandOptions {
1451
+ readonly watch?: boolean | undefined;
1452
+ }
1453
+
1454
+ interface SchemaRegistryConfig {
1455
+ readonly strict: boolean | undefined;
1456
+ readonly allowOverwrite: boolean | undefined;
1457
+ readonly validateRelations: boolean | undefined;
1458
+ }
1459
+ declare class SchemaRegistry implements ISchemaRegistry {
1460
+ private readonly schemas;
1461
+ private readonly config;
1462
+ private locked;
1463
+ private cache;
1464
+ constructor(config?: SchemaRegistryConfig);
1465
+ private invalidateCache;
1466
+ register(schema: SchemaDefinition): SchemaDefinition;
1467
+ registerMany(schemas: readonly SchemaDefinition[]): void;
1468
+ finalizeRegistry(): void;
1469
+ private sortByDependencies;
1470
+ get(name: string): SchemaDefinition | undefined;
1471
+ getWithTableName(modelName: string): {
1472
+ schema: SchemaDefinition;
1473
+ tableName: string;
1474
+ } | undefined;
1475
+ getByTableName(tableName: string): {
1476
+ schema: SchemaDefinition;
1477
+ tableName: string;
1478
+ } | undefined;
1479
+ has(name: string): boolean;
1480
+ getAll(): readonly SchemaDefinition[];
1481
+ getNames(): readonly string[];
1482
+ get size(): number;
1483
+ findModelByTableName(tableName: string | null): string | null;
1484
+ getSchemasWithRelations(): readonly SchemaDefinition[];
1485
+ getRelatedSchemas(schemaName: string): readonly string[];
1486
+ getReferencingSchemas(schemaName: string): readonly string[];
1487
+ findByFieldType(fieldType: string): readonly SchemaDefinition[];
1488
+ getCachedSelectFields<T extends DatrixEntry>(modelName: string): QuerySelect<T>;
1489
+ validateRelations(): void;
1490
+ clear(): void;
1491
+ remove(name: string): boolean;
1492
+ lock(): void;
1493
+ unlock(): void;
1494
+ isLocked(): boolean;
1495
+ private transformFileFields;
1496
+ private processRelations;
1497
+ private createJunctionTable;
1498
+ private getJunctionTableName;
1499
+ private pluralize;
1500
+ toJSON(): Record<string, SchemaDefinition>;
1501
+ fromJSON(data: Record<string, SchemaDefinition>): void;
1502
+ }
1503
+
1504
+ declare class Dispatcher {
1505
+ private readonly registry;
1506
+ private readonly datrix;
1507
+ constructor(registry: PluginRegistry, datrix: Datrix);
1508
+ buildQueryContext(action: QueryAction): Promise<QueryContext>;
1509
+ dispatchSchemaLoad(schemas: SchemaRegistry): Promise<void>;
1510
+ executeQuery<TResult extends DatrixEntry, R extends DatrixEntry = DatrixEntry>(action: QueryAction, schema: SchemaDefinition, query: QueryObject<TResult>, executor: (query: QueryObject<TResult>) => Promise<R>): Promise<R>;
1511
+ dispatchBeforeQuery<TResult extends DatrixEntry = DatrixRecord>(query: QueryObject<TResult>, schema: SchemaDefinition, context: QueryContext): Promise<QueryObject<TResult>>;
1512
+ dispatchAfterQuery<TResult extends DatrixEntry>(result: TResult, schema: SchemaDefinition, context: QueryContext): Promise<TResult>;
1513
+ private dispatchSchemaBeforeHook;
1514
+ private dispatchSchemaAfterHook;
1515
+ }
1516
+
1517
+ declare class CrudOperations implements IRawCrud {
1518
+ private readonly schemas;
1519
+ readonly getAdapter: () => DatabaseAdapter;
1520
+ private readonly getDispatcher;
1521
+ private readonly executor;
1522
+ constructor(schemas: ISchemaRegistry, getAdapter: () => DatabaseAdapter, getDispatcher?: (() => Dispatcher) | null);
1523
+ findOne<T extends DatrixEntry = DatrixEntry>(model: string, where: WhereClause<T>, options?: RawCrudOptions<T>): Promise<T | null>;
1524
+ findById<T extends DatrixEntry = DatrixRecord>(model: string, id: number, options?: RawCrudOptions<T>): Promise<T | null>;
1525
+ findMany<T extends DatrixEntry = DatrixRecord>(model: string, options?: RawFindManyOptions<T>): Promise<T[]>;
1526
+ count<T extends DatrixEntry = DatrixRecord>(model: string, where?: WhereClause<T>): Promise<number>;
1527
+ create<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, data: TInput, options?: RawCrudOptions<T>): Promise<T>;
1528
+ createMany<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, data: TInput[], options?: RawCrudOptions<T>): Promise<T[]>;
1529
+ update<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, id: number, data: TInput, options?: RawCrudOptions<T>): Promise<T>;
1530
+ updateMany<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, where: WhereClause<T>, data: TInput, options?: RawCrudOptions<T>): Promise<T[]>;
1531
+ delete<T extends DatrixEntry = DatrixRecord>(model: string, id: number, options?: RawCrudOptions<T>): Promise<T>;
1532
+ deleteMany<T extends DatrixEntry = DatrixRecord>(model: string, where: WhereClause<T>, options?: RawCrudOptions<T>): Promise<T[]>;
1533
+ }
1534
+
1535
+ type AmbiguousChangeType = "column_rename_or_replace" | "table_rename_or_replace" | "fk_column_drop" | "junction_table_drop" | "junction_table_rename_or_replace" | "relation_upgrade_single_to_many" | "relation_downgrade_many_to_single" | "fk_model_change" | "relation_direction_flip";
1536
+ type AmbiguousActionType = "rename" | "drop_and_add" | "confirm_drop" | "migrate_to_junction" | "migrate_first" | "fresh_start" | "keep_column" | "drop_and_recreate";
1537
+ interface AmbiguousChange {
1538
+ readonly id: string;
1539
+ readonly tableName: string;
1540
+ readonly type: AmbiguousChangeType;
1541
+ readonly removedName: string;
1542
+ readonly addedName: string;
1543
+ readonly removedDefinition?: FieldDefinition;
1544
+ readonly addedDefinition?: FieldDefinition;
1545
+ readonly possibleActions: readonly AmbiguousAction[];
1546
+ readonly warning?: string;
1547
+ readonly affectedRows?: number;
1548
+ resolved: boolean;
1549
+ resolvedAction?: AmbiguousAction;
1550
+ }
1551
+ interface AmbiguousAction {
1552
+ readonly type: AmbiguousActionType;
1553
+ readonly description: string;
1554
+ }
1555
+ interface MigrationPlan {
1556
+ readonly tablesToCreate: readonly SchemaDefinition[];
1557
+ readonly tablesToDrop: readonly string[];
1558
+ readonly tablesToAlter: readonly {
1559
+ readonly tableName: string;
1560
+ readonly changes: readonly SchemaDiff[];
1561
+ }[];
1562
+ readonly operations: readonly MigrationOperation[];
1563
+ readonly hasChanges: boolean;
1564
+ }
1565
+ declare class MigrationSession {
1566
+ private readonly datrix;
1567
+ private readonly adapter;
1568
+ private readonly differ;
1569
+ private readonly generator;
1570
+ private readonly history;
1571
+ private currentSchemas;
1572
+ private databaseSchemas;
1573
+ private differences;
1574
+ private _ambiguous;
1575
+ private initialized;
1576
+ constructor(datrix: IDatrix);
1577
+ initialize(): Promise<void>;
1578
+ private detectAmbiguousChanges;
1579
+ private detectRelationTypeChanges;
1580
+ private detectJunctionTableDrops;
1581
+ private detectJunctionTableRenames;
1582
+ private detectFkColumnChanges;
1583
+ private detectColumnRenames;
1584
+ private detectTableRenames;
1585
+ private detectFkModelChanges;
1586
+ private detectRelationDirectionFlips;
1587
+ private looksLikeJunctionTable;
1588
+ private isJunctionTableFor;
1589
+ private couldBeJunctionRename;
1590
+ private singularize;
1591
+ private pluralize;
1592
+ private couldBeRename;
1593
+ private couldBeTableRename;
1594
+ get tablesToCreate(): readonly SchemaDefinition[];
1595
+ get tablesToDrop(): readonly string[];
1596
+ get tablesToAlter(): readonly {
1597
+ tableName: string;
1598
+ changes: readonly SchemaDiff[];
1599
+ }[];
1600
+ get ambiguous(): readonly AmbiguousChange[];
1601
+ hasUnresolvedAmbiguous(): boolean;
1602
+ resolveAmbiguous(id: string, action: AmbiguousActionType): void;
1603
+ private applyResolution;
1604
+ private applyColumnRename;
1605
+ private applyTableRename;
1606
+ hasChanges(): boolean;
1607
+ getPlan(): MigrationPlan;
1608
+ apply(): Promise<readonly MigrationExecutionResult[]>;
1609
+ private injectDataTransferOperations;
1610
+ preview(): Promise<readonly MigrationOperation[]>;
1611
+ }
1612
+ declare function createMigrationSession(datrix: IDatrix): Promise<MigrationSession>;
1613
+
1614
+ interface DatrixInitOptions {
1615
+ readonly skipConnection?: boolean;
1616
+ readonly skipPlugins?: boolean;
1617
+ readonly skipSchemas?: boolean;
1618
+ }
1619
+ type ConfigFactory = () => DatrixConfig;
1620
+ declare class Datrix implements IDatrix {
1621
+ private config;
1622
+ private adapter;
1623
+ private pluginRegistry;
1624
+ private dispatcher;
1625
+ private _schemas;
1626
+ private initialized;
1627
+ private _crud;
1628
+ private _rawCrud;
1629
+ initializeWithConfig(config: DatrixConfig, options?: DatrixInitOptions): Promise<void>;
1630
+ shutdown(): Promise<void>;
1631
+ getConfig(): DatrixConfig;
1632
+ getAdapter<T extends DatabaseAdapter = DatabaseAdapter>(): T;
1633
+ getPlugins(): readonly DatrixPlugin[];
1634
+ getPlugin<T extends DatrixPlugin = DatrixPlugin>(name: string): T | null;
1635
+ hasPlugin(name: string): boolean;
1636
+ getDispatcher(): Dispatcher;
1637
+ getSchemas(): SchemaRegistry;
1638
+ getMigrationConfig(): Required<MigrationConfig>;
1639
+ getDevConfig(): Required<DevConfig>;
1640
+ isInitialized(): boolean;
1641
+ beginMigrate(): Promise<MigrationSession>;
1642
+ get crud(): CrudOperations;
1643
+ get raw(): CrudOperations;
1644
+ findOne<T extends DatrixEntry = DatrixRecord>(model: string, where: WhereClause<T>, options?: RawCrudOptions<T>): Promise<T | null>;
1645
+ findById<T extends DatrixEntry = DatrixRecord>(model: string, id: number, options?: RawCrudOptions<T>): Promise<T | null>;
1646
+ findMany<T extends DatrixEntry = DatrixRecord>(model: string, options?: RawFindManyOptions<T>): Promise<T[]>;
1647
+ count<T extends DatrixEntry = DatrixRecord>(model: string, where?: WhereClause<T>): Promise<number>;
1648
+ create<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, data: TInput, options?: RawCrudOptions<T>): Promise<T>;
1649
+ createMany<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, data: TInput[], options?: RawCrudOptions<T>): Promise<T[]>;
1650
+ update<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, id: number, data: TInput, options?: RawCrudOptions<T>): Promise<T>;
1651
+ updateMany<T extends DatrixEntry = DatrixRecord, TInput extends FallbackInput = FallbackInput>(model: string, where: WhereClause<T>, data: TInput, options?: RawCrudOptions<T>): Promise<T[]>;
1652
+ delete<T extends DatrixEntry = DatrixRecord>(model: string, id: number, options?: RawCrudOptions<T>): Promise<T>;
1653
+ deleteMany<T extends DatrixEntry = DatrixRecord>(model: string, where: WhereClause<T>, options?: RawCrudOptions<T>): Promise<T[]>;
1654
+ get schema(): SchemaRegistry;
1655
+ getSchema(name: string): SchemaDefinition<string, Record<string, FieldDefinition<string>>> | undefined;
1656
+ getAllSchemas(): readonly SchemaDefinition<string, Record<string, FieldDefinition<string>>>[];
1657
+ hasSchema(name: string): boolean;
1658
+ reset(): void;
1659
+ private ensureInitialized;
1660
+ private applySchemaExtensions;
1661
+ }
1662
+ declare function defineConfig(factory: ConfigFactory): () => Promise<Datrix>;
1663
+
1664
+ type AuthStrategy = "jwt" | "session" | "password" | "permission";
1665
+ type AuthErrorCode = "AUTH_INVALID_CREDENTIALS" | "AUTH_USER_NOT_FOUND" | "AUTH_USER_EXISTS" | "AUTH_WEAK_PASSWORD" | "AUTH_TOKEN_EXPIRED" | "AUTH_TOKEN_INVALID" | "AUTH_SESSION_NOT_FOUND" | "AUTH_SESSION_EXPIRED" | "AUTH_SESSION_INVALID" | "AUTH_UNAUTHORIZED" | "AUTH_FORBIDDEN" | "AUTH_CONFIG_INVALID" | "JWT_SIGN_ERROR" | "JWT_VERIFY_ERROR" | "JWT_DECODE_ERROR" | "JWT_EXPIRED" | "JWT_INVALID_FORMAT" | "JWT_INVALID_HEADER" | "JWT_INVALID_PAYLOAD" | "JWT_INVALID_SIGNATURE" | "JWT_INVALID_IAT" | "JWT_INVALID_ISSUER" | "JWT_INVALID_AUDIENCE" | "SESSION_CREATE_ERROR" | "SESSION_DELETE_ERROR" | "SESSION_NOT_CONFIGURED" | "PASSWORD_HASH_ERROR" | "PASSWORD_VERIFY_ERROR" | "PASSWORD_TOO_SHORT" | "PASSWORD_TOO_LONG" | "PERMISSION_DENIED";
1666
+ interface AuthErrorContext {
1667
+ readonly strategy?: AuthStrategy | undefined;
1668
+ readonly userId?: string | undefined;
1669
+ readonly role?: string | undefined;
1670
+ readonly sessionId?: string | undefined;
1671
+ readonly action?: string | undefined;
1672
+ readonly resource?: string | undefined;
1673
+ readonly field?: string | undefined;
1674
+ readonly exp?: number | undefined;
1675
+ readonly iat?: number | undefined;
1676
+ readonly now?: number | undefined;
1677
+ readonly minLength?: number | undefined;
1678
+ readonly maxLength?: number | undefined;
1679
+ readonly receivedType?: string | undefined;
1680
+ readonly expectedType?: string | undefined;
1681
+ readonly [key: string]: unknown;
1682
+ }
1683
+ interface DatrixAuthErrorOptions {
1684
+ readonly code: AuthErrorCode;
1685
+ readonly strategy?: AuthStrategy;
1686
+ readonly context?: AuthErrorContext | undefined;
1687
+ readonly cause?: Error | undefined;
1688
+ readonly suggestion?: string | undefined;
1689
+ readonly expected?: string | undefined;
1690
+ readonly received?: unknown | undefined;
1691
+ }
1692
+ interface SerializedDatrixAuthError extends SerializedDatrixError {
1693
+ readonly strategy?: AuthStrategy;
1694
+ }
1695
+ declare class DatrixAuthError extends DatrixError<AuthErrorContext> {
1696
+ readonly strategy?: AuthStrategy | undefined;
1697
+ constructor(message: string, options: DatrixAuthErrorOptions);
1698
+ toJSON(): SerializedDatrixAuthError;
1699
+ toDetailedMessage(): string;
1700
+ }
1701
+
1702
+ type ConfigErrorCode = "CONFIG_NOT_FOUND" | "CONFIG_INVALID_TYPE" | "CONFIG_REQUIRED_FIELD" | "CONFIG_INVALID_VALUE" | "CONFIG_EMPTY_VALUE" | "CONFIG_VALIDATION_FAILED" | "CONFIG_MULTIPLE_ERRORS";
1703
+ interface ConfigErrorContext {
1704
+ readonly field?: string;
1705
+ readonly validOptions?: readonly string[];
1706
+ readonly receivedType?: string;
1707
+ readonly expectedType?: string;
1708
+ readonly index?: number;
1709
+ readonly configPath?: string;
1710
+ readonly [key: string]: unknown;
1711
+ }
1712
+ interface DatrixConfigErrorOptions {
1713
+ readonly code: ConfigErrorCode;
1714
+ readonly field?: string | undefined;
1715
+ readonly context?: ConfigErrorContext | undefined;
1716
+ readonly cause?: Error | undefined;
1717
+ readonly suggestion?: string | undefined;
1718
+ readonly expected?: string | undefined;
1719
+ readonly received?: unknown | undefined;
1720
+ }
1721
+ interface SerializedDatrixConfigError extends SerializedDatrixError {
1722
+ readonly field?: string;
1723
+ }
1724
+ declare class DatrixConfigError extends DatrixError<ConfigErrorContext> {
1725
+ readonly field?: string | undefined;
1726
+ constructor(message: string, options: DatrixConfigErrorOptions);
1727
+ toJSON(): SerializedDatrixConfigError;
1728
+ toDetailedMessage(): string;
1729
+ }
1730
+ declare class DatrixConfigValidationError extends DatrixConfigError {
1731
+ readonly errors: readonly string[];
1732
+ constructor(errors: readonly string[], suggestion?: string);
1733
+ toDetailedMessage(): string;
1734
+ }
1735
+
1736
+ type CrudOperation = "findOne" | "findById" | "findMany" | "count" | "create" | "update" | "updateMany" | "delete" | "deleteMany";
1737
+ type CrudErrorCode = "QUERY_EXECUTION_FAILED" | "SCHEMA_NOT_FOUND" | "RECORD_NOT_FOUND" | "INVALID_POPULATE_VALUE" | "RESERVED_FIELD_WRITE" | "NOT_IMPLEMENTED" | "QUERY_FAILED";
1738
+ interface CrudErrorContext {
1739
+ readonly model?: string;
1740
+ readonly query?: Record<string, unknown>;
1741
+ readonly recordId?: string | number;
1742
+ readonly where?: Record<string, unknown>;
1743
+ readonly adapterError?: string;
1744
+ readonly [key: string]: unknown;
1745
+ }
1746
+ interface DatrixCrudErrorOptions {
1747
+ readonly code: CrudErrorCode;
1748
+ readonly operation: CrudOperation;
1749
+ readonly model: string;
1750
+ readonly context?: CrudErrorContext | undefined;
1751
+ readonly cause?: Error | undefined;
1752
+ readonly suggestion?: string | undefined;
1753
+ readonly expected?: string | undefined;
1754
+ readonly received?: unknown | undefined;
1755
+ }
1756
+ interface SerializedDatrixCrudError extends SerializedDatrixError {
1757
+ readonly operation: CrudOperation;
1758
+ readonly model: string;
1759
+ }
1760
+ declare class DatrixCrudError extends DatrixError<CrudErrorContext> {
1761
+ readonly operation: CrudOperation;
1762
+ readonly model: string;
1763
+ constructor(message: string, options: DatrixCrudErrorOptions);
1764
+ toJSON(): SerializedDatrixCrudError;
1765
+ toDetailedMessage(): string;
1766
+ }
1767
+
1768
+ type QueryBuilderComponent = "builder" | "where" | "select" | "populate" | "data" | "pagination";
1769
+ type QueryBuilderErrorCode = "INVALID_QUERY_TYPE" | "MISSING_TABLE" | "INVALID_FIELD" | "INVALID_OPERATOR" | "INVALID_VALUE" | "MAX_DEPTH_EXCEEDED" | "EMPTY_CLAUSE" | "DUPLICATE_FIELD" | "COERCION_FAILED" | "DELETE_WITHOUT_WHERE" | "MISSING_DATA" | "RELATION_IN_SELECT" | "SCHEMA_NOT_FOUND" | "UNKNOWN_FIELD";
1770
+ interface QueryBuilderErrorContext {
1771
+ readonly field?: string | undefined;
1772
+ readonly operator?: string | undefined;
1773
+ readonly value?: unknown | undefined;
1774
+ readonly availableFields?: readonly string[] | undefined;
1775
+ readonly validOperators?: readonly string[] | undefined;
1776
+ readonly depth?: number | undefined;
1777
+ readonly maxDepth?: number | undefined;
1778
+ readonly [key: string]: unknown;
1779
+ }
1780
+ interface DatrixQueryBuilderErrorOptions {
1781
+ readonly code: QueryBuilderErrorCode;
1782
+ readonly component: QueryBuilderComponent;
1783
+ readonly field?: string | undefined;
1784
+ readonly context?: QueryBuilderErrorContext | undefined;
1785
+ readonly cause?: Error | undefined;
1786
+ readonly suggestion?: string | undefined;
1787
+ readonly expected?: string | undefined;
1788
+ readonly received?: unknown | undefined;
1789
+ }
1790
+ interface SerializedDatrixQueryBuilderError extends SerializedDatrixError {
1791
+ readonly component: QueryBuilderComponent;
1792
+ readonly field?: string;
1793
+ }
1794
+ declare class DatrixQueryBuilderError extends DatrixError<QueryBuilderErrorContext> {
1795
+ readonly component: QueryBuilderComponent;
1796
+ readonly field?: string | undefined;
1797
+ constructor(message: string, options?: DatrixQueryBuilderErrorOptions | string);
1798
+ toJSON(): SerializedDatrixQueryBuilderError;
1799
+ toDetailedMessage(): string;
1800
+ }
1801
+
1802
+ type ValidationErrorCode = "REQUIRED" | "TYPE_MISMATCH" | "MIN_LENGTH" | "MAX_LENGTH" | "MIN_VALUE" | "MAX_VALUE" | "MIN_ITEMS" | "MAX_ITEMS" | "PATTERN" | "UNIQUE" | "INVALID_ENUM" | "INVALID_FORMAT" | "INVALID_DATE" | "CUSTOM" | "UNKNOWN";
1803
+ interface ValidationError {
1804
+ readonly field: string;
1805
+ readonly message: string;
1806
+ readonly code: ValidationErrorCode;
1807
+ readonly value?: unknown;
1808
+ readonly expected?: unknown;
1809
+ }
1810
+
1811
+ interface DatrixValidationErrorOptions extends Partial<DatrixErrorOptions> {
1812
+ readonly model: string;
1813
+ readonly errors: readonly ValidationError[];
1814
+ }
1815
+ interface SerializedDatrixValidationError extends SerializedDatrixError {
1816
+ readonly model: string;
1817
+ readonly errors: readonly ValidationError[];
1818
+ }
1819
+ declare class DatrixValidationError extends DatrixError {
1820
+ readonly model: string;
1821
+ readonly errors: readonly ValidationError[];
1822
+ constructor(message: string, options: DatrixValidationErrorOptions);
1823
+ toJSON(): SerializedDatrixValidationError;
1824
+ toDetailedMessage(): string;
1825
+ }
1826
+
1827
+ declare function validateQueryObject<T extends DatrixEntry>(query: unknown): void;
1828
+
1829
+ declare abstract class BasePlugin<TOptions = Record<string, unknown>> implements DatrixPlugin<TOptions> {
1830
+ abstract readonly name: string;
1831
+ abstract readonly version: string;
1832
+ readonly options: TOptions;
1833
+ protected context: PluginContext | undefined;
1834
+ constructor(options: TOptions);
1835
+ abstract init(context: PluginContext): Promise<void>;
1836
+ abstract destroy(): Promise<void>;
1837
+ getSchemas(): Promise<SchemaDefinition[]>;
1838
+ extendSchemas(_context: SchemaExtensionContext): Promise<SchemaExtension[]>;
1839
+ onSchemaLoad(_schemas: ISchemaRegistry): Promise<void>;
1840
+ onBeforeQuery<T extends DatrixEntry>(query: QueryObject<T>, _context: QueryContext): Promise<QueryObject<T>>;
1841
+ onAfterQuery<TResult extends DatrixEntry>(result: TResult, _context: QueryContext): Promise<TResult>;
1842
+ onCreateQueryContext(context: QueryContext): Promise<QueryContext>;
1843
+ protected validateOptions(validator: (options: unknown) => options is TOptions, errorMessage: string): TOptions;
1844
+ protected isInitialized(): this is this & {
1845
+ context: PluginContext;
1846
+ };
1847
+ protected getContext(): PluginContext;
1848
+ protected createError(message: string, code: string, details?: unknown): PluginError;
1849
+ }
1850
+
1851
+ declare const DEFAULT_MIGRATION_MODEL = "_datrix_migration";
1852
+ declare function getMigrationSchema(modelName?: string): {
1853
+ readonly name: string;
1854
+ readonly fields: {
1855
+ readonly name: {
1856
+ readonly type: "string";
1857
+ readonly required: true;
1858
+ readonly maxLength: 255;
1859
+ readonly description: "Migration name";
1860
+ };
1861
+ readonly version: {
1862
+ readonly type: "string";
1863
+ readonly required: true;
1864
+ readonly unique: true;
1865
+ readonly maxLength: 255;
1866
+ readonly description: "Migration version (timestamp-based)";
1867
+ };
1868
+ readonly executionTime: {
1869
+ readonly type: "number";
1870
+ readonly required: true;
1871
+ readonly min: 0;
1872
+ readonly description: "Execution time in milliseconds";
1873
+ };
1874
+ readonly status: {
1875
+ readonly type: "enum";
1876
+ readonly required: true;
1877
+ readonly values: readonly ["pending", "completed", "failed", "rolled_back"];
1878
+ readonly description: "Migration execution status";
1879
+ };
1880
+ readonly checksum: {
1881
+ readonly type: "string";
1882
+ readonly maxLength: 64;
1883
+ readonly description: "SHA-256 checksum of migration content";
1884
+ };
1885
+ readonly error: {
1886
+ readonly type: "string";
1887
+ readonly description: "Error message if migration failed";
1888
+ };
1889
+ readonly appliedAt: {
1890
+ readonly type: "date";
1891
+ readonly required: true;
1892
+ readonly description: "When the migration was applied";
1893
+ };
1894
+ };
1895
+ readonly indexes: readonly [{
1896
+ readonly fields: readonly ["version"];
1897
+ readonly unique: true;
1898
+ }, {
1899
+ readonly fields: readonly ["status"];
1900
+ }, {
1901
+ readonly fields: readonly ["appliedAt"];
1902
+ }];
1903
+ readonly permission: {
1904
+ readonly create: false;
1905
+ readonly read: false;
1906
+ readonly update: false;
1907
+ readonly delete: false;
1908
+ };
1909
+ };
1910
+ declare function getDatrixMetaSchema(): {
1911
+ readonly name: "_datrix";
1912
+ readonly tableName: "_datrix";
1913
+ readonly fields: {
1914
+ readonly key: {
1915
+ readonly type: "string";
1916
+ readonly required: true;
1917
+ readonly unique: true;
1918
+ readonly maxLength: 255;
1919
+ readonly description: "Table name";
1920
+ };
1921
+ readonly value: {
1922
+ readonly type: "string";
1923
+ readonly required: true;
1924
+ readonly description: "Datrix SchemaDefinition as JSON string";
1925
+ };
1926
+ };
1927
+ readonly permission: {
1928
+ readonly create: false;
1929
+ readonly read: false;
1930
+ readonly update: false;
1931
+ readonly delete: false;
1932
+ };
1933
+ };
1934
+
1935
+ export { ALL_WHERE_OPERATORS, ARRAY_OPERATORS, type AdapterErrorCode, type AdapterErrorContext, type AdapterName, type AdapterOperation, type AlterOperation, type AlterTableOperation, type AmbiguousAction, type AmbiguousActionType, type AmbiguousChange, type AmbiguousChangeType, type AnyRelationInput, type AnyRelationInputObject, type ArrayField, type AuthContext, type AuthErrorCode, type AuthErrorContext, type AuthStrategy, type AuthUser, type AuthenticatedUser, type BaseCommandOptions, type BaseErrorContext, type BaseMigrationOperation, BasePlugin, type BaseSchemaDiff, type BooleanField, CLIError, COMPARISON_OPERATORS, CONTROL_CHARS_PATTERN, type ComparisonOperators, type ConfigErrorCode, type ConfigErrorContext, type ConfigFactory, type ConfigFileExport, type ConnectionState, type CreateIndexOperation, type CreateTableOperation, type CrudErrorCode, type CrudErrorContext, type CrudOperation, DEFAULT_API_AUTH_CONFIG, DEFAULT_API_CONFIG, DEFAULT_DEV_CONFIG, DEFAULT_MIGRATION_CONFIG, DEFAULT_MIGRATION_MODEL, type DataTransferOperation, type DatabaseAdapter, type DateField, Datrix, DatrixAdapterError, type DatrixAdapterErrorOptions, DatrixAuthError, type DatrixAuthErrorOptions, type DatrixConfig, DatrixConfigError, type DatrixConfigErrorOptions, DatrixConfigValidationError, DatrixCrudError, type DatrixCrudErrorOptions, type DatrixEntry, DatrixError, type DatrixErrorOptions, type DatrixInitOptions, type DatrixPlugin, DatrixQueryBuilderError, type DatrixQueryBuilderErrorOptions, type DatrixRecord, DatrixValidationError, type DatrixValidationErrorOptions, type DefaultPermission, type DevCommandOptions, type DevConfig, type DropIndexOperation, type DropTableOperation, type EnumField, type ErrorLocation, type ExportMeta, type ExportWriter, FIELD_NAME_PATTERN, FORJA_META_KEY_PREFIX, FORJA_META_MODEL, type FallbackInput, type FallbackOrderByItem, type FallbackScalar, type FallbackValue, type FallbackWhereClause, type FieldAddedDiff, type FieldDefinition, type FieldInvalidReason, type FieldMetadata, type FieldModifiedDiff, type FieldPermission, type FieldPermissionAction, type FieldPermissionCheckResult, type FieldRemovedDiff, type FieldRenamedDiff, type FieldType, type FieldValidationResult, type FieldsErrorContext, type FileField, type FileFieldOptions, type ForeignKeyReference, type GenerateCommandOptions, type IApiPlugin, type IAuthManager, type IDatrix, type IRawCrud, type ISchemaRegistry, type IUpload, type ImportReader, type IndexAddedDiff, type IndexDefinition, type IndexRemovedDiff, type JsonField, LOGICAL_OPERATORS, type LifecycleHooks, type LoadConfigOptions, type LocalProviderOptions, type LogicalOperators, type LoginResult, MAX_ARRAY_INDEX, MAX_FIELD_NAME_LENGTH, MAX_LOGICAL_NESTING_DEPTH, MAX_WHERE_VALUE_LENGTH, type MediaEntry, type MediaVariant, type MediaVariants, type MigrateCommandOptions, type Migration, type MigrationConfig, type MigrationContext, type MigrationExecutionResult, type MigrationFilePlan, type MigrationGenerator, type MigrationHistory, type MigrationHistoryRecord, type MigrationMetadata, type MigrationOperation, type MigrationOperationType, type MigrationPlan, type MigrationRunner, MigrationSession, type MigrationStatus, MigrationSystemError, NULL_OPERATORS, type NormalizedNestedData, type NormalizedRelationId, type NormalizedRelationOperations, type NormalizedRelationUpdate, type NumberField, OPERATOR_VALUE_TYPES, type OperatorValueType, type OrderByClause, type OrderByItem, type OrderDirection, type PaginationErrorContext, type PaginationParams, type ParameterStyle, type ParsedArgs, type ParsedPagination, type ParsedQuery, type ParsedSort, ParserError, type ParserErrorCode, type ParserErrorContext, type ParserErrorOptions, type ParserOptions, type ParserType, type PermissionAction, type PermissionCheckResult, type PermissionContext, type PermissionFn, type PermissionValue, type PluginContext, PluginError, type PluginFactory, PluginRegistry, type PopulateClause, type PopulateErrorContext, type PopulateOptions, type QueryAction, type QueryBuilderComponent, type QueryBuilderErrorCode, type QueryBuilderErrorContext, type QueryContext, type QueryCountObject, type QueryDeleteObject, type QueryInsertObject, type QueryMetadata, type QueryObject, type QueryObjectForType, type QueryOrderBy, type QueryPopulate, type QueryPopulateOptions, type QueryPrimitive, type QueryRelations, type QueryResult, type QueryRunner, type QuerySelect, type QuerySelectObject, type QueryTranslator, type QueryType, type QueryUpdateObject, RESERVED_FIELDS, RESERVED_FIELD_NAMES, type RawCrudOptions, type RawFindManyOptions, type RawQueryParams, type RawSQLOperation, type RelationBelongsTo, type RelationField, type RelationHasMany, type RelationHasOne, type RelationIdRef, type RelationIdRefs, type RelationInput, type RelationKind, type RelationManyToMany, type RenameTableOperation, type ReservedFieldName, type ResponseData, type S3ProviderOptions, STRING_OPERATORS, type ScalarValue, type SchemaComparison, type SchemaDefinition, type SchemaDefinitionValidationResult, type SchemaDiff, type SchemaDiffType, type SchemaDiffer, type SchemaExtension, type SchemaExtensionContext, type SchemaModifier, type SchemaOperations, type SchemaPattern, type SchemaPermission, type SchemaValidationError, type SelectClause, type SerializedDatrixAdapterError, type SerializedDatrixAuthError, type SerializedDatrixConfigError, type SerializedDatrixCrudError, type SerializedDatrixError, type SerializedDatrixQueryBuilderError, type SerializedDatrixValidationError, type SerializedParserError, type SortErrorContext, type SortParam, type SqlDialect, type StorageProvider, type StringField, type TableAddedDiff, type TableRemovedDiff, type TableRenamedDiff, type Transaction, type UploadConfig, UploadError, type UploadFile, type UploadResult, WHERE_OPERATORS, type WhereClause, type WhereErrorContext, type WhereOperator, buildErrorLocation, createMigrationSession, defineConfig, defineSchema, generateUniqueFilename, getDatrixMetaSchema, getFileExtension, getMigrationSchema, getOperatorValueType, hasDefaultExport, isDatabaseAdapter, isDatrixConfig, isDatrixPlugin, isLogicalOperator, isPermissionFn, isRelationIdRef, isRelationIdRefs, isStorageProvider, isValidFieldName, isValidWhereOperator, isWhereOperator, normalizeRelationId, normalizeRelationIds, requiresArrayValue, requiresConditions, sanitizeFilename, sortSchemasByDependency, throwConnectionError, throwFileNotFound, throwFileReadError, throwFileWriteError, throwForeignKeyConstraint, throwIntrospectionError, throwInvalidPopulateOptions, throwInvalidRelationType, throwInvalidRelationWhereSyntax, throwInvalidWhereField, throwJoinBuildError, throwJsonAggregationError, throwJunctionTableNotFound, throwLateralJoinError, throwLockError, throwLockTimeout, throwMaxDepthExceeded, throwMetaFieldAlreadyExists, throwMetaFieldNotFound, throwMigrationError, throwModelNotFound, throwNotConnected, throwPopulateQueryError, throwQueryError, throwQueryMissingData, throwRawQueryNotSupported, throwRelationNotFound, throwResultProcessingError, throwSchemaNotFound, throwTargetModelNotFound, throwTransactionAlreadyCommitted, throwTransactionAlreadyRolledBack, throwTransactionError, throwTransactionSavepointNotSupported, throwUniqueConstraintField, throwUniqueConstraintIndex, truncateSqlForError, validateFieldName, validateQueryObject, validateSchemaDefinition };