@venizia/ignis 0.0.5-2 → 0.0.5-20

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.
Files changed (146) hide show
  1. package/dist/base/applications/abstract.d.ts.map +1 -1
  2. package/dist/base/applications/abstract.js +1 -0
  3. package/dist/base/applications/abstract.js.map +1 -1
  4. package/dist/base/applications/base.d.ts.map +1 -1
  5. package/dist/base/applications/base.js +8 -1
  6. package/dist/base/applications/base.js.map +1 -1
  7. package/dist/base/applications/types.d.ts +10 -1
  8. package/dist/base/applications/types.d.ts.map +1 -1
  9. package/dist/base/controllers/abstract.d.ts +1 -0
  10. package/dist/base/controllers/abstract.d.ts.map +1 -1
  11. package/dist/base/controllers/abstract.js +12 -1
  12. package/dist/base/controllers/abstract.js.map +1 -1
  13. package/dist/base/controllers/common/types.d.ts +5 -1
  14. package/dist/base/controllers/common/types.d.ts.map +1 -1
  15. package/dist/base/controllers/factory/controller.d.ts +15 -6
  16. package/dist/base/controllers/factory/controller.d.ts.map +1 -1
  17. package/dist/base/controllers/factory/controller.js +46 -21
  18. package/dist/base/controllers/factory/controller.js.map +1 -1
  19. package/dist/base/datasources/base.d.ts.map +1 -1
  20. package/dist/base/datasources/base.js +10 -1
  21. package/dist/base/datasources/base.js.map +1 -1
  22. package/dist/base/metadata/index.d.ts +1 -0
  23. package/dist/base/metadata/index.d.ts.map +1 -1
  24. package/dist/base/metadata/index.js +1 -0
  25. package/dist/base/metadata/index.js.map +1 -1
  26. package/dist/base/metadata/request-context.d.ts +3 -0
  27. package/dist/base/metadata/request-context.d.ts.map +1 -0
  28. package/dist/base/metadata/request-context.js +9 -0
  29. package/dist/base/metadata/request-context.js.map +1 -0
  30. package/dist/base/metadata/routes.d.ts +30 -40
  31. package/dist/base/metadata/routes.d.ts.map +1 -1
  32. package/dist/base/metadata/routes.js +15 -5
  33. package/dist/base/metadata/routes.js.map +1 -1
  34. package/dist/base/middlewares/app-error.middleware.d.ts +1 -0
  35. package/dist/base/middlewares/app-error.middleware.d.ts.map +1 -1
  36. package/dist/base/middlewares/app-error.middleware.js +10 -8
  37. package/dist/base/middlewares/app-error.middleware.js.map +1 -1
  38. package/dist/base/middlewares/request-spy.middleware.d.ts.map +1 -1
  39. package/dist/base/middlewares/request-spy.middleware.js +12 -0
  40. package/dist/base/middlewares/request-spy.middleware.js.map +1 -1
  41. package/dist/base/mixins/component.mixin.d.ts.map +1 -1
  42. package/dist/base/mixins/controller.mixin.d.ts.map +1 -1
  43. package/dist/base/mixins/repository.mixin.d.ts.map +1 -1
  44. package/dist/base/mixins/service.mixin.d.ts.map +1 -1
  45. package/dist/base/models/enrichers/id.enricher.d.ts +15 -10
  46. package/dist/base/models/enrichers/id.enricher.d.ts.map +1 -1
  47. package/dist/base/models/enrichers/id.enricher.js +3 -3
  48. package/dist/base/models/enrichers/id.enricher.js.map +1 -1
  49. package/dist/base/models/enrichers/principal.enricher.d.ts +7 -9
  50. package/dist/base/models/enrichers/principal.enricher.d.ts.map +1 -1
  51. package/dist/base/models/enrichers/principal.enricher.js.map +1 -1
  52. package/dist/base/models/enrichers/user-audit.enricher.d.ts +3 -2
  53. package/dist/base/models/enrichers/user-audit.enricher.d.ts.map +1 -1
  54. package/dist/base/models/enrichers/user-audit.enricher.js +47 -11
  55. package/dist/base/models/enrichers/user-audit.enricher.js.map +1 -1
  56. package/dist/base/repositories/common/constants.d.ts +59 -0
  57. package/dist/base/repositories/common/constants.d.ts.map +1 -1
  58. package/dist/base/repositories/common/constants.js +51 -2
  59. package/dist/base/repositories/common/constants.js.map +1 -1
  60. package/dist/base/repositories/common/types.d.ts +482 -44
  61. package/dist/base/repositories/common/types.d.ts.map +1 -1
  62. package/dist/base/repositories/common/types.js +164 -17
  63. package/dist/base/repositories/common/types.js.map +1 -1
  64. package/dist/base/repositories/core/abstract.d.ts +450 -0
  65. package/dist/base/repositories/core/abstract.d.ts.map +1 -0
  66. package/dist/base/repositories/core/abstract.js +287 -0
  67. package/dist/base/repositories/core/abstract.js.map +1 -0
  68. package/dist/base/repositories/core/default-crud.d.ts +2 -2
  69. package/dist/base/repositories/core/default-crud.d.ts.map +1 -1
  70. package/dist/base/repositories/core/index.d.ts +1 -1
  71. package/dist/base/repositories/core/index.d.ts.map +1 -1
  72. package/dist/base/repositories/core/index.js +1 -1
  73. package/dist/base/repositories/core/index.js.map +1 -1
  74. package/dist/base/repositories/core/persistable.d.ts +91 -36
  75. package/dist/base/repositories/core/persistable.d.ts.map +1 -1
  76. package/dist/base/repositories/core/persistable.js +139 -37
  77. package/dist/base/repositories/core/persistable.js.map +1 -1
  78. package/dist/base/repositories/core/readable.d.ts +166 -62
  79. package/dist/base/repositories/core/readable.d.ts.map +1 -1
  80. package/dist/base/repositories/core/readable.js +185 -56
  81. package/dist/base/repositories/core/readable.js.map +1 -1
  82. package/dist/base/repositories/mixins/default-filter.d.ts +65 -0
  83. package/dist/base/repositories/mixins/default-filter.d.ts.map +1 -0
  84. package/dist/base/repositories/mixins/default-filter.js +97 -0
  85. package/dist/base/repositories/mixins/default-filter.js.map +1 -0
  86. package/dist/base/repositories/mixins/fields-visibility.d.ts +74 -0
  87. package/dist/base/repositories/mixins/fields-visibility.d.ts.map +1 -0
  88. package/dist/base/repositories/mixins/fields-visibility.js +129 -0
  89. package/dist/base/repositories/mixins/fields-visibility.js.map +1 -0
  90. package/dist/base/repositories/mixins/index.d.ts +3 -0
  91. package/dist/base/repositories/mixins/index.d.ts.map +1 -0
  92. package/dist/base/repositories/mixins/index.js +19 -0
  93. package/dist/base/repositories/mixins/index.js.map +1 -0
  94. package/dist/base/repositories/operators/filter.d.ts +146 -12
  95. package/dist/base/repositories/operators/filter.d.ts.map +1 -1
  96. package/dist/base/repositories/operators/filter.js +432 -112
  97. package/dist/base/repositories/operators/filter.js.map +1 -1
  98. package/dist/base/repositories/operators/query.d.ts +69 -0
  99. package/dist/base/repositories/operators/query.d.ts.map +1 -1
  100. package/dist/base/repositories/operators/query.js +190 -2
  101. package/dist/base/repositories/operators/query.js.map +1 -1
  102. package/dist/base/repositories/operators/relation.d.ts +33 -0
  103. package/dist/base/repositories/operators/relation.d.ts.map +1 -1
  104. package/dist/base/repositories/operators/relation.js +36 -0
  105. package/dist/base/repositories/operators/relation.js.map +1 -1
  106. package/dist/common/statuses.d.ts +26 -7
  107. package/dist/common/statuses.d.ts.map +1 -1
  108. package/dist/common/statuses.js +96 -9
  109. package/dist/common/statuses.js.map +1 -1
  110. package/dist/components/auth/authenticate/common/constants.d.ts +1 -0
  111. package/dist/components/auth/authenticate/common/constants.d.ts.map +1 -1
  112. package/dist/components/auth/authenticate/common/constants.js +1 -0
  113. package/dist/components/auth/authenticate/common/constants.js.map +1 -1
  114. package/dist/components/auth/authenticate/common/types.d.ts +7 -0
  115. package/dist/components/auth/authenticate/common/types.d.ts.map +1 -1
  116. package/dist/components/auth/authenticate/controllers/factory.d.ts +1 -0
  117. package/dist/components/auth/authenticate/controllers/factory.d.ts.map +1 -1
  118. package/dist/components/auth/authenticate/strategies/strategy-registry.d.ts.map +1 -1
  119. package/dist/components/auth/authenticate/strategies/strategy-registry.js +3 -0
  120. package/dist/components/auth/authenticate/strategies/strategy-registry.js.map +1 -1
  121. package/dist/components/auth/models/entities/user-role.model.d.ts +1 -1
  122. package/dist/components/auth/models/entities/user-role.model.d.ts.map +1 -1
  123. package/dist/components/auth/models/entities/user-role.model.js +1 -1
  124. package/dist/components/auth/models/entities/user-role.model.js.map +1 -1
  125. package/dist/components/health-check/controller.d.ts +4 -5
  126. package/dist/components/health-check/controller.d.ts.map +1 -1
  127. package/dist/components/health-check/controller.js +12 -12
  128. package/dist/components/health-check/controller.js.map +1 -1
  129. package/dist/components/static-asset/component.d.ts +0 -1
  130. package/dist/components/static-asset/component.d.ts.map +1 -1
  131. package/dist/components/static-asset/component.js +0 -2
  132. package/dist/components/static-asset/component.js.map +1 -1
  133. package/dist/components/static-asset/controller/factory.d.ts +1 -0
  134. package/dist/components/static-asset/controller/factory.d.ts.map +1 -1
  135. package/dist/components/static-asset/controller/factory.js +1 -1
  136. package/dist/components/static-asset/controller/factory.js.map +1 -1
  137. package/dist/components/static-asset/models/base.model.d.ts +10 -10
  138. package/dist/components/static-asset/models/base.model.js +1 -1
  139. package/dist/components/static-asset/models/base.model.js.map +1 -1
  140. package/dist/helpers/inversion/common/types.d.ts +35 -1
  141. package/dist/helpers/inversion/common/types.d.ts.map +1 -1
  142. package/package.json +4 -5
  143. package/dist/base/repositories/core/base.d.ts +0 -264
  144. package/dist/base/repositories/core/base.d.ts.map +0 -1
  145. package/dist/base/repositories/core/base.js +0 -197
  146. package/dist/base/repositories/core/base.js.map +0 -1
@@ -4,31 +4,197 @@ import { z } from '@hono/zod-openapi';
4
4
  import { TLogLevel, TNullable } from '@venizia/ignis-helpers';
5
5
  import { Column, SQL, createTableRelationsHelpers } from 'drizzle-orm';
6
6
  import { RelationTypes } from './constants';
7
+ /**
8
+ * Zod schema for pagination skip parameter.
9
+ * Specifies how many items to skip from the beginning of the result set.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * // Skip first 10 items
14
+ * const filter = { skip: 10, limit: 5 };
15
+ * ```
16
+ */
7
17
  export declare const SkipSchema: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
18
+ /** Type for pagination skip parameter. Inferred from {@link SkipSchema}. */
8
19
  export type TSkip = z.infer<typeof SkipSchema>;
20
+ /**
21
+ * Zod schema for pagination offset parameter.
22
+ * Alternative to skip - specifies the starting position in the result set.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // Start from the 20th item
27
+ * const filter = { offset: 20, limit: 10 };
28
+ * ```
29
+ */
9
30
  export declare const OffsetSchema: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
31
+ /** Type for pagination offset parameter. Inferred from {@link OffsetSchema}. */
10
32
  export type TOffset = z.infer<typeof OffsetSchema>;
33
+ /**
34
+ * Zod schema for pagination limit parameter.
35
+ * Specifies the maximum number of items to return in a query.
36
+ * Defaults to {@link DEFAULT_LIMIT} (10).
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Return at most 25 items
41
+ * const filter = { limit: 25 };
42
+ * ```
43
+ */
11
44
  export declare const LimitSchema: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
45
+ /** Type for pagination limit parameter. Inferred from {@link LimitSchema}. */
12
46
  export type TLimit = z.infer<typeof LimitSchema>;
47
+ /**
48
+ * Zod schema for query ordering/sorting.
49
+ * Supports sorting by regular columns and JSON/JSONB paths.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * // Sort by single column
54
+ * const filter = { order: ['createdAt DESC'] };
55
+ *
56
+ * // Sort by multiple columns
57
+ * const filter = { order: ['priority DESC', 'createdAt ASC'] };
58
+ *
59
+ * // Sort by JSON path
60
+ * const filter = { order: ['metadata.score DESC'] };
61
+ * ```
62
+ */
13
63
  export declare const OrderBySchema: z.ZodOptional<z.ZodArray<z.ZodString>>;
64
+ /** Type for ordering/sorting parameter. Inferred from {@link OrderBySchema}. */
14
65
  export type TOrderBy = z.infer<typeof OrderBySchema>;
66
+ /**
67
+ * Zod schema for query where conditions.
68
+ * Supports both object format and JSON string format (for URL query params).
69
+ *
70
+ * Features:
71
+ * - Field equality: `{ name: 'John' }`
72
+ * - Comparison operators: `{ age: { gte: 18 } }`
73
+ * - Logical AND: `{ and: [{ status: 'active' }, { role: 'admin' }] }`
74
+ * - Logical OR: `{ or: [{ status: 'active' }, { isPublished: true }] }`
75
+ * - JSON path queries: `{ 'metadata.score': { gt: 50 } }`
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * // Simple equality
80
+ * const where = { status: 'active' };
81
+ *
82
+ * // With operators
83
+ * const where = { age: { gte: 18, lt: 65 } };
84
+ *
85
+ * // Logical operations
86
+ * const where = { or: [{ role: 'admin' }, { role: 'moderator' }] };
87
+ * ```
88
+ */
15
89
  export declare const WhereSchema: z.ZodUnion<readonly [z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>, z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<any, string>>, z.ZodType<any, unknown, z.core.$ZodTypeInternals<any, unknown>>>]>;
90
+ /**
91
+ * Type for where clause conditions.
92
+ * Supports field-level conditions and logical AND/OR grouping.
93
+ *
94
+ * @template T - The entity type for type-safe field names
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // Type-safe where with entity
99
+ * const where: TWhere<User> = {
100
+ * email: 'john@example.com',
101
+ * and: [{ isActive: true }, { role: 'admin' }]
102
+ * };
103
+ * ```
104
+ */
16
105
  export type TWhere<T = any> = {
17
106
  [key in keyof T]?: any;
18
107
  } & {
19
108
  and?: TWhere<T>[];
20
109
  or?: TWhere<T>[];
21
110
  };
22
- export declare const FieldsSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
111
+ /**
112
+ * Zod schema for field/column selection.
113
+ * Supports two formats:
114
+ * - Array format: `['id', 'name', 'email']` - include only these fields
115
+ * - Object format: `{ id: true, name: true, password: false }` - include/exclude fields
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * // Array format - include only specified fields
120
+ * const filter = { fields: ['id', 'name', 'email'] };
121
+ *
122
+ * // Object format - include specific, exclude others
123
+ * const filter = { fields: { id: true, name: true, password: false } };
124
+ * ```
125
+ */
126
+ export declare const FieldsSchema: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodBoolean>, z.ZodArray<z.ZodString>]>>;
127
+ /**
128
+ * Type for field selection.
129
+ * Can be an object mapping field names to booleans, or an array of field names.
130
+ *
131
+ * @template T - The entity type for type-safe field names
132
+ */
23
133
  export type TFields<T = any> = Partial<{
24
134
  [K in keyof T]: boolean;
25
- }>;
135
+ }> | Array<keyof T>;
136
+ /**
137
+ * Zod schema for including related entities in queries.
138
+ * Allows eager loading of related data with optional nested filtering.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * // Simple inclusion
143
+ * const filter = { include: [{ relation: 'posts' }] };
144
+ *
145
+ * // With nested scope/filter
146
+ * const filter = {
147
+ * include: [{
148
+ * relation: 'posts',
149
+ * scope: { where: { isPublished: true }, limit: 5 }
150
+ * }]
151
+ * };
152
+ * ```
153
+ */
26
154
  export declare const InclusionSchema: any;
155
+ /**
156
+ * Type for a single relation inclusion configuration.
157
+ *
158
+ * @property relation - The name of the relation to include
159
+ * @property scope - Optional filter to apply to the related entities
160
+ */
27
161
  export type TInclusion = {
28
162
  relation: string;
29
163
  scope?: TFilter;
30
164
  };
165
+ /**
166
+ * Comprehensive Zod schema for repository query filtering.
167
+ * Combines where conditions, field selection, relation inclusion, pagination, and sorting.
168
+ * Supports both object format and JSON string format (for URL query params).
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * // Complete filter example
173
+ * const filter = {
174
+ * where: { status: 'active', role: { in: ['admin', 'moderator'] } },
175
+ * fields: ['id', 'name', 'email'],
176
+ * include: [{ relation: 'posts', scope: { limit: 5 } }],
177
+ * order: ['createdAt DESC'],
178
+ * limit: 20,
179
+ * skip: 0
180
+ * };
181
+ * ```
182
+ */
31
183
  export declare const FilterSchema: any;
184
+ /**
185
+ * Type for comprehensive filter configuration.
186
+ * Used across all repository query methods.
187
+ *
188
+ * @template T - The entity type for type-safe where conditions
189
+ *
190
+ * @property where - Query conditions for filtering results
191
+ * @property fields - Field selection (include/exclude columns)
192
+ * @property include - Related entities to eager load
193
+ * @property order - Sorting order for results
194
+ * @property limit - Maximum number of results to return
195
+ * @property offset - Number of results to skip (alternative to skip)
196
+ * @property skip - Number of results to skip
197
+ */
32
198
  export type TFilter<T = any> = {
33
199
  where?: TWhere<T>;
34
200
  fields?: TFields;
@@ -38,10 +204,57 @@ export type TFilter<T = any> = {
38
204
  offset?: number;
39
205
  skip?: number;
40
206
  };
207
+ /**
208
+ * Zod schema for count operation results.
209
+ * Returns the total number of matching records.
210
+ */
41
211
  export declare const CountSchema: z.ZodObject<{
42
212
  count: z.ZodDefault<z.ZodNumber>;
43
213
  }, z.core.$strip>;
214
+ /** Type for count operation results. Inferred from {@link CountSchema}. */
44
215
  export type TCount = z.infer<typeof CountSchema>;
216
+ /**
217
+ * Data range information for paginated queries.
218
+ * Follows HTTP Content-Range header standard format.
219
+ *
220
+ * @property start - The starting index (0-based, inclusive)
221
+ * @property end - The ending index (0-based, inclusive)
222
+ * @property total - The total number of records matching the query
223
+ * @property contentRange - Formatted Content-Range header string
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * // Query with limit: 10, skip: 20, total records: 100
228
+ * const range: TDataRange = {
229
+ * start: 20,
230
+ * end: 29,
231
+ * total: 100,
232
+ * contentRange: 'items 20-29/100'
233
+ * };
234
+ *
235
+ * // Use in HTTP response header
236
+ * res.setHeader('Content-Range', range.contentRange);
237
+ * ```
238
+ */
239
+ export type TDataRange = {
240
+ /** Starting index (0-based, inclusive) */
241
+ start: number;
242
+ /** Ending index (0-based, inclusive) */
243
+ end: number;
244
+ /** Total number of records matching the query */
245
+ total: number;
246
+ };
247
+ /**
248
+ * Options for Drizzle ORM query building.
249
+ * Internal type used by the FilterBuilder to construct Drizzle queries.
250
+ *
251
+ * @property limit - Maximum records to return
252
+ * @property offset - Records to skip
253
+ * @property orderBy - SQL order expressions
254
+ * @property where - SQL where condition
255
+ * @property with - Relation inclusion configuration
256
+ * @property columns - Column selection configuration
257
+ */
45
258
  export type TDrizzleQueryOptions = Partial<{
46
259
  limit: number;
47
260
  offset: number;
@@ -50,6 +263,25 @@ export type TDrizzleQueryOptions = Partial<{
50
263
  with: Record<string, true | TDrizzleQueryOptions>;
51
264
  columns: Record<string, boolean>;
52
265
  }>;
266
+ /**
267
+ * Configuration for entity relationships.
268
+ * Used to define one-to-one, one-to-many, and many-to-one relations.
269
+ *
270
+ * @property name - The relation name used in include queries
271
+ * @property type - The relation type ('one' or 'many')
272
+ * @property schema - The related entity's table schema
273
+ * @property metadata - Drizzle relation metadata (fields, references)
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * const postsRelation: TRelationConfig = {
278
+ * name: 'posts',
279
+ * type: RelationTypes.MANY,
280
+ * schema: PostSchema,
281
+ * metadata: { fields: [Post.schema.authorId], references: [User.schema.id] }
282
+ * };
283
+ * ```
284
+ */
53
285
  export type TRelationConfig = {
54
286
  name: string;
55
287
  } & ({
@@ -61,206 +293,412 @@ export type TRelationConfig = {
61
293
  schema: TTableSchemaWithId;
62
294
  metadata: Parameters<ReturnType<typeof createTableRelationsHelpers>[typeof RelationTypes.MANY]>[1];
63
295
  });
296
+ /**
297
+ * Configuration for repository operation logging.
298
+ *
299
+ * @property use - Whether to enable logging for this operation
300
+ * @property level - The log level to use (defaults to 'info')
301
+ */
64
302
  export type TRepositoryLogOptions = {
65
303
  use: boolean;
66
304
  level?: TLogLevel;
67
305
  };
68
- export type TTransactionOption = {
306
+ /**
307
+ * Interface for objects that can be associated with a database transaction.
308
+ */
309
+ export interface IWithTransaction {
310
+ /** The active transaction to use for this operation. */
69
311
  transaction?: ITransaction;
70
- };
71
- export interface IRepository<Schema extends TTableSchemaWithId = TTableSchemaWithId> {
312
+ }
313
+ /**
314
+ * Extended options for repository operations.
315
+ * Includes transaction support, logging configuration, and default filter bypass.
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * // Use with transaction
320
+ * const tx = await repository.beginTransaction();
321
+ * await repository.create({ data: user, options: { transaction: tx } });
322
+ * await tx.commit();
323
+ *
324
+ * // Enable logging for debugging
325
+ * await repository.find({ filter: {}, options: { log: { use: true, level: 'debug' } } });
326
+ *
327
+ * // Bypass default filter (e.g., soft delete)
328
+ * await repository.find({ filter: {}, options: { shouldSkipDefaultFilter: true } });
329
+ * ```
330
+ */
331
+ export interface IExtraOptions extends IWithTransaction {
332
+ /** Optional logging configuration for this operation. */
333
+ log?: TRepositoryLogOptions;
334
+ /**
335
+ * If true, bypass the default filter configured in model settings.
336
+ * Use this when you need to query all records regardless of default filter constraints.
337
+ *
338
+ * @example
339
+ * ```typescript
340
+ * // Bypass default filter: { where: { isDeleted: false } }
341
+ * repository.find({ filter: {}, options: { shouldSkipDefaultFilter: true } });
342
+ * ```
343
+ */
344
+ shouldSkipDefaultFilter?: boolean;
345
+ }
346
+ /**
347
+ * @deprecated Use {@link IExtraOptions} instead.
348
+ */
349
+ export type TTransactionOption = IExtraOptions;
350
+ /**
351
+ * Base repository interface.
352
+ * Defines the core properties and methods that all repositories must implement.
353
+ *
354
+ * @template EntitySchema - The Drizzle table schema type with an 'id' column
355
+ */
356
+ export interface IRepository<EntitySchema extends TTableSchemaWithId = TTableSchemaWithId> {
357
+ /** The data source providing database connectivity. */
72
358
  dataSource: IDataSource;
73
- entity: BaseEntity<Schema>;
74
- getEntity(): BaseEntity<Schema>;
75
- getEntitySchema(): Schema;
359
+ /** The entity/model instance associated with this repository. */
360
+ entity: BaseEntity<EntitySchema>;
361
+ /** Returns the entity instance. */
362
+ getEntity(): BaseEntity<EntitySchema>;
363
+ /** Returns the Drizzle table schema. */
364
+ getEntitySchema(): EntitySchema;
365
+ /** Returns the database connector from the data source. */
76
366
  getConnector(): IDataSource['connector'];
77
367
  }
78
- export interface IReadableRepository<Schema extends TTableSchemaWithId = TTableSchemaWithId, DataObject extends TTableObject<Schema> = TTableObject<Schema>, ExtraOptions extends TTransactionOption = TTransactionOption> extends IRepository<Schema> {
368
+ /**
369
+ * Interface for read-only repository operations.
370
+ * Provides methods for querying data without modification capabilities.
371
+ *
372
+ * @template EntitySchema - The Drizzle table schema type
373
+ * @template DataObject - The type of objects returned from queries
374
+ * @template ExtraOptions - Additional options type extending IExtraOptions
375
+ */
376
+ export interface IReadableRepository<EntitySchema extends TTableSchemaWithId = TTableSchemaWithId, DataObject extends TTableObject<EntitySchema> = TTableObject<EntitySchema>, ExtraOptions extends IExtraOptions = IExtraOptions> extends IRepository<EntitySchema> {
377
+ /**
378
+ * Builds Drizzle query options from a filter object.
379
+ * @param opts - Options containing the filter to convert
380
+ * @returns Drizzle-compatible query options
381
+ */
79
382
  buildQuery(opts: {
80
383
  filter: TFilter<DataObject>;
81
384
  }): TDrizzleQueryOptions;
385
+ /**
386
+ * Counts records matching the where condition.
387
+ * @param opts - Options containing where condition
388
+ * @returns Promise resolving to count result
389
+ */
82
390
  count(opts: {
83
391
  where: TWhere<DataObject>;
84
392
  options?: ExtraOptions;
85
393
  }): Promise<TCount>;
394
+ /**
395
+ * Checks if any records match the where condition.
396
+ * @param opts - Options containing where condition
397
+ * @returns Promise resolving to true if records exist
398
+ */
86
399
  existsWith(opts: {
87
400
  where: TWhere<DataObject>;
88
401
  options?: ExtraOptions;
89
402
  }): Promise<boolean>;
403
+ /**
404
+ * Finds all records matching the filter.
405
+ * @template R - Return type (defaults to DataObject)
406
+ * @param opts - Options containing filter and extra options with shouldQueryRange: true
407
+ * @returns Promise resolving to object with data array and range information
408
+ */
90
409
  find<R = DataObject>(opts: {
91
410
  filter: TFilter<DataObject>;
92
- options?: ExtraOptions;
411
+ options: ExtraOptions & {
412
+ shouldQueryRange: true;
413
+ };
414
+ }): Promise<{
415
+ data: Array<R>;
416
+ range: TDataRange;
417
+ }>;
418
+ /**
419
+ * Finds all records matching the filter.
420
+ * @template R - Return type (defaults to DataObject)
421
+ * @param opts - Options containing filter and extra options
422
+ * @returns Promise resolving to array of matching records
423
+ */
424
+ find<R = DataObject>(opts: {
425
+ filter: TFilter<DataObject>;
426
+ options?: ExtraOptions & {
427
+ shouldQueryRange?: false;
428
+ };
93
429
  }): Promise<Array<R>>;
430
+ /**
431
+ * Finds the first record matching the filter.
432
+ * @template R - Return type (defaults to DataObject)
433
+ * @param opts - Options containing filter and extra options
434
+ * @returns Promise resolving to the found record or null
435
+ */
94
436
  findOne<R = DataObject>(opts: {
95
437
  filter: TFilter<DataObject>;
96
438
  options?: ExtraOptions;
97
439
  }): Promise<TNullable<R>>;
440
+ /**
441
+ * Finds a record by its ID.
442
+ * @template R - Return type (defaults to DataObject)
443
+ * @param opts - Options containing id and optional filter (without where)
444
+ * @returns Promise resolving to the found record or null
445
+ */
98
446
  findById<R = DataObject>(opts: {
99
447
  id: IdType;
100
- filter?: Exclude<TFilter<DataObject>, 'where'>;
448
+ filter?: Omit<TFilter<DataObject>, 'where'>;
101
449
  options?: ExtraOptions;
102
450
  }): Promise<TNullable<R>>;
103
451
  }
104
- export interface IPersistableRepository<Schema extends TTableSchemaWithId = TTableSchemaWithId, DataObject extends TTableObject<Schema> = TTableObject<Schema>, PersistObject extends TTableInsert<Schema> = TTableInsert<Schema>, ExtraOptions extends TTransactionOption = TTransactionOption> extends IReadableRepository<Schema, DataObject, ExtraOptions> {
452
+ /**
453
+ * Interface for full CRUD repository operations.
454
+ * Extends IReadableRepository with create, update, and delete capabilities.
455
+ *
456
+ * @template EntitySchema - The Drizzle table schema type
457
+ * @template DataObject - The type of objects returned from queries
458
+ * @template PersistObject - The type for insert/update operations
459
+ * @template ExtraOptions - Additional options type extending IExtraOptions
460
+ */
461
+ export interface IPersistableRepository<EntitySchema extends TTableSchemaWithId = TTableSchemaWithId, DataObject extends TTableObject<EntitySchema> = TTableObject<EntitySchema>, PersistObject extends TTableInsert<EntitySchema> = TTableInsert<EntitySchema>, ExtraOptions extends IExtraOptions = IExtraOptions> extends IReadableRepository<EntitySchema, DataObject, ExtraOptions> {
462
+ /**
463
+ * Creates a single record.
464
+ * @param opts - Options with data and shouldReturn: false
465
+ * @returns Promise with count only (no data returned)
466
+ */
105
467
  create(opts: {
106
468
  data: PersistObject;
107
469
  options: ExtraOptions & {
108
470
  shouldReturn: false;
109
- log?: TRepositoryLogOptions;
110
471
  };
111
472
  }): Promise<TCount & {
112
- data: null;
473
+ data: undefined | null;
113
474
  }>;
114
- create<R = Schema['$inferSelect']>(opts: {
475
+ /**
476
+ * Creates a single record and returns it.
477
+ * @template R - Return type (defaults to DataObject)
478
+ * @param opts - Options with data to create
479
+ * @returns Promise with count and created record
480
+ */
481
+ create<R = DataObject>(opts: {
115
482
  data: PersistObject;
116
483
  options?: ExtraOptions & {
117
484
  shouldReturn?: true;
118
- log?: TRepositoryLogOptions;
119
485
  };
120
486
  }): Promise<TCount & {
121
487
  data: R;
122
488
  }>;
489
+ /**
490
+ * Creates multiple records in bulk.
491
+ * @param opts - Options with data array and shouldReturn: false
492
+ * @returns Promise with count only
493
+ */
123
494
  createAll(opts: {
124
495
  data: Array<PersistObject>;
125
496
  options: ExtraOptions & {
126
497
  shouldReturn: false;
127
- log?: TRepositoryLogOptions;
128
498
  };
129
499
  }): Promise<TCount & {
130
- data: null;
500
+ data: undefined | null;
131
501
  }>;
132
- createAll<R = Schema['$inferSelect']>(opts: {
502
+ /**
503
+ * Creates multiple records and returns them.
504
+ * @template R - Return type (defaults to DataObject)
505
+ * @param opts - Options with data array
506
+ * @returns Promise with count and created records
507
+ */
508
+ createAll<R = DataObject>(opts: {
133
509
  data: Array<PersistObject>;
134
510
  options?: ExtraOptions & {
135
511
  shouldReturn?: true;
136
- log?: TRepositoryLogOptions;
137
512
  };
138
513
  }): Promise<TCount & {
139
514
  data: Array<R>;
140
515
  }>;
516
+ /**
517
+ * Updates a record by its ID.
518
+ * @param opts - Options with id, partial data, and shouldReturn: false
519
+ * @returns Promise with count only
520
+ */
141
521
  updateById(opts: {
142
522
  id: IdType;
143
523
  data: Partial<PersistObject>;
144
524
  options: ExtraOptions & {
145
525
  shouldReturn: false;
146
- log?: TRepositoryLogOptions;
147
526
  };
148
527
  }): Promise<TCount & {
149
- data: null;
528
+ data: undefined | null;
150
529
  }>;
151
- updateById<R = Schema['$inferSelect']>(opts: {
530
+ /**
531
+ * Updates a record by its ID and returns it.
532
+ * @template R - Return type (defaults to DataObject)
533
+ * @param opts - Options with id and partial data
534
+ * @returns Promise with count and updated record
535
+ */
536
+ updateById<R = DataObject>(opts: {
152
537
  id: IdType;
153
538
  data: Partial<PersistObject>;
154
539
  options?: ExtraOptions & {
155
540
  shouldReturn?: true;
156
- log?: TRepositoryLogOptions;
157
541
  };
158
542
  }): Promise<TCount & {
159
543
  data: R;
160
544
  }>;
545
+ /**
546
+ * Updates all records matching the where condition.
547
+ * @param opts - Options with data, where, and shouldReturn: false
548
+ * @returns Promise with count only
549
+ */
161
550
  updateAll(opts: {
162
551
  data: Partial<PersistObject>;
163
552
  where: TWhere<DataObject>;
164
553
  options: ExtraOptions & {
165
554
  shouldReturn: false;
166
555
  force?: boolean;
167
- log?: TRepositoryLogOptions;
168
556
  };
169
557
  }): Promise<TCount & {
170
- data: null;
558
+ data: undefined | null;
171
559
  }>;
172
- updateAll<R = Schema['$inferSelect']>(opts: {
560
+ /**
561
+ * Updates all records matching the where condition and returns them.
562
+ * @template R - Return type (defaults to DataObject)
563
+ * @param opts - Options with data and where condition
564
+ * @returns Promise with count and updated records
565
+ */
566
+ updateAll<R = DataObject>(opts: {
173
567
  data: Partial<PersistObject>;
174
568
  where: TWhere<DataObject>;
175
569
  options?: ExtraOptions & {
176
570
  shouldReturn?: true;
177
571
  force?: boolean;
178
- log?: TRepositoryLogOptions;
179
572
  };
180
573
  }): Promise<TCount & {
181
574
  data: Array<R>;
182
575
  }>;
576
+ /**
577
+ * Alias for updateAll. Updates records matching the where condition.
578
+ * @param opts - Options with data, where, and shouldReturn: false
579
+ * @returns Promise with count only
580
+ */
183
581
  updateBy(opts: {
184
582
  data: Partial<PersistObject>;
185
583
  where: TWhere<DataObject>;
186
584
  options: ExtraOptions & {
187
585
  shouldReturn: false;
188
586
  force?: boolean;
189
- log?: TRepositoryLogOptions;
190
587
  };
191
588
  }): Promise<TCount & {
192
- data: null;
589
+ data: undefined | null;
193
590
  }>;
194
- updateBy<R = Schema['$inferSelect']>(opts: {
591
+ /**
592
+ * Alias for updateAll. Updates records and returns them.
593
+ * @template R - Return type (defaults to DataObject)
594
+ * @param opts - Options with data and where condition
595
+ * @returns Promise with count and updated records
596
+ */
597
+ updateBy<R = DataObject>(opts: {
195
598
  data: Partial<PersistObject>;
196
599
  where: TWhere<DataObject>;
197
600
  options?: ExtraOptions & {
198
601
  shouldReturn?: true;
199
602
  force?: boolean;
200
- log?: TRepositoryLogOptions;
201
603
  };
202
604
  }): Promise<TCount & {
203
605
  data: Array<R>;
204
606
  }>;
607
+ /**
608
+ * Deletes a record by its ID.
609
+ * @param opts - Options with id and shouldReturn: false
610
+ * @returns Promise with count only
611
+ */
205
612
  deleteById(opts: {
206
613
  id: IdType;
207
614
  options: ExtraOptions & {
208
615
  shouldReturn: false;
209
- log?: TRepositoryLogOptions;
210
616
  };
211
617
  }): Promise<TCount & {
212
- data: null;
618
+ data: undefined | null;
213
619
  }>;
214
- deleteById<R = Schema['$inferSelect']>(opts: {
620
+ /**
621
+ * Deletes a record by its ID and returns it.
622
+ * @template R - Return type (defaults to DataObject)
623
+ * @param opts - Options with id
624
+ * @returns Promise with count and deleted record
625
+ */
626
+ deleteById<R = DataObject>(opts: {
215
627
  id: IdType;
216
628
  options?: ExtraOptions & {
217
629
  shouldReturn?: true;
218
- log?: TRepositoryLogOptions;
219
630
  };
220
631
  }): Promise<TCount & {
221
632
  data: R;
222
633
  }>;
634
+ /**
635
+ * Deletes all records matching the where condition.
636
+ * @param opts - Options with where and shouldReturn: false
637
+ * @returns Promise with count only
638
+ */
223
639
  deleteAll(opts: {
224
640
  where?: TWhere<DataObject>;
225
641
  options: ExtraOptions & {
226
642
  shouldReturn: false;
227
643
  force?: boolean;
228
- log?: TRepositoryLogOptions;
229
644
  };
230
645
  }): Promise<TCount & {
231
- data: null;
646
+ data: undefined | null;
232
647
  }>;
233
- deleteAll<R = Schema['$inferSelect']>(opts: {
648
+ /**
649
+ * Deletes all records matching the where condition and returns them.
650
+ * @template R - Return type (defaults to DataObject)
651
+ * @param opts - Options with where condition
652
+ * @returns Promise with count and deleted records
653
+ */
654
+ deleteAll<R = DataObject>(opts: {
234
655
  where?: TWhere<DataObject>;
235
656
  options?: ExtraOptions & {
236
657
  shouldReturn?: true;
237
658
  force?: boolean;
238
- log?: TRepositoryLogOptions;
239
659
  };
240
660
  }): Promise<TCount & {
241
661
  data: Array<R>;
242
662
  }>;
663
+ /**
664
+ * Alias for deleteAll. Deletes records matching the where condition.
665
+ * @param opts - Options with where and shouldReturn: false
666
+ * @returns Promise with count only
667
+ */
243
668
  deleteBy(opts: {
244
669
  where?: TWhere<DataObject>;
245
670
  options: ExtraOptions & {
246
671
  shouldReturn: false;
247
672
  force?: boolean;
248
- log?: TRepositoryLogOptions;
249
673
  };
250
674
  }): Promise<TCount & {
251
- data: null;
675
+ data: undefined | null;
252
676
  }>;
253
- deleteBy<R = Schema['$inferSelect']>(opts: {
677
+ /**
678
+ * Alias for deleteAll. Deletes records and returns them.
679
+ * @template R - Return type (defaults to DataObject)
680
+ * @param opts - Options with where condition
681
+ * @returns Promise with count and deleted records
682
+ */
683
+ deleteBy<R = DataObject>(opts: {
254
684
  where?: TWhere<DataObject>;
255
685
  options?: ExtraOptions & {
256
686
  shouldReturn?: true;
257
687
  force?: boolean;
258
- log?: TRepositoryLogOptions;
259
688
  };
260
689
  }): Promise<TCount & {
261
690
  data: Array<R>;
262
691
  }>;
263
692
  }
693
+ /**
694
+ * Options passed to query operator handler functions.
695
+ * Used internally by {@link QueryOperators} to build SQL conditions.
696
+ *
697
+ * @template T - The type of the comparison value
698
+ *
699
+ * @property column - The Drizzle column to compare against
700
+ * @property value - The value to compare with
701
+ */
264
702
  export interface IQueryHandlerOptions<T = any> {
265
703
  column: Column;
266
704
  value: T;