@mrxsys/mrx-core 2.3.3-canary-20250514-a17e993

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 (99) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/LICENSE +21 -0
  3. package/README.md +20 -0
  4. package/dist/chunk-0pft81dh.js +2 -0
  5. package/dist/chunk-6sa6shm6.js +2 -0
  6. package/dist/chunk-7map0v4a.js +2 -0
  7. package/dist/chunk-dppgkz92.js +2 -0
  8. package/dist/chunk-kn1300vm.js +2 -0
  9. package/dist/chunk-nntk6mwx.js +2 -0
  10. package/dist/chunk-rr6e20n5.js +2 -0
  11. package/dist/chunk-s3xqwymw.js +2 -0
  12. package/dist/chunk-t411e41y.js +2 -0
  13. package/dist/chunk-wggj590m.js +2 -0
  14. package/dist/chunk-xcz2fxzt.js +2 -0
  15. package/dist/chunk-yeyzc9n2.js +2 -0
  16. package/dist/database/enums/databaseKeyError.d.ts +56 -0
  17. package/dist/database/enums/index.d.ts +2 -0
  18. package/dist/database/enums/index.js +2 -0
  19. package/dist/database/enums/mssqlErrorCode.d.ts +25 -0
  20. package/dist/database/events/index.d.ts +2 -0
  21. package/dist/database/events/index.js +2 -0
  22. package/dist/database/events/mssqlEvent.d.ts +3 -0
  23. package/dist/database/events/tableEvent.d.ts +6 -0
  24. package/dist/database/index.d.ts +5 -0
  25. package/dist/database/index.js +2 -0
  26. package/dist/database/mssql.d.ts +163 -0
  27. package/dist/database/table.d.ts +58 -0
  28. package/dist/database/types/index.d.ts +2 -0
  29. package/dist/database/types/index.js +1 -0
  30. package/dist/database/types/mssqlDatabaseOption.d.ts +92 -0
  31. package/dist/database/types/mssqlEventLog.d.ts +29 -0
  32. package/dist/elysia/advancedSearch.d.ts +460 -0
  33. package/dist/elysia/crud.d.ts +609 -0
  34. package/dist/elysia/dynamicDatabaseSelector.d.ts +352 -0
  35. package/dist/elysia/enums/elysiaKeyError.d.ts +16 -0
  36. package/dist/elysia/enums/httpStatusCode.d.ts +241 -0
  37. package/dist/elysia/enums/index.d.ts +2 -0
  38. package/dist/elysia/enums/index.js +2 -0
  39. package/dist/elysia/error.d.ts +50 -0
  40. package/dist/elysia/index.d.ts +7 -0
  41. package/dist/elysia/index.js +2 -0
  42. package/dist/elysia/jwt.d.ts +46 -0
  43. package/dist/elysia/microservice.d.ts +102 -0
  44. package/dist/elysia/ratelimit.d.ts +76 -0
  45. package/dist/elysia/schemas/index.d.ts +2 -0
  46. package/dist/elysia/schemas/index.js +2 -0
  47. package/dist/elysia/schemas/info.d.ts +9 -0
  48. package/dist/elysia/schemas/ping.d.ts +3 -0
  49. package/dist/elysia/types/crudOptions.d.ts +126 -0
  50. package/dist/elysia/types/crudRoutes.d.ts +2 -0
  51. package/dist/elysia/types/dynamicDatabaseSelectorPluginOptions.d.ts +30 -0
  52. package/dist/elysia/types/index.d.ts +5 -0
  53. package/dist/elysia/types/index.js +1 -0
  54. package/dist/elysia/types/jwtOptions.d.ts +92 -0
  55. package/dist/elysia/types/rateLimitOptions.d.ts +44 -0
  56. package/dist/error/coreError.d.ts +109 -0
  57. package/dist/error/index.d.ts +1 -0
  58. package/dist/error/index.js +2 -0
  59. package/dist/index.d.ts +18 -0
  60. package/dist/index.js +2 -0
  61. package/dist/mailer/enums/index.d.ts +1 -0
  62. package/dist/mailer/enums/index.js +2 -0
  63. package/dist/mailer/enums/mailerKeyError.d.ts +12 -0
  64. package/dist/mailer/index.d.ts +1 -0
  65. package/dist/mailer/index.js +2 -0
  66. package/dist/mailer/smtp.d.ts +62 -0
  67. package/dist/mailer/types/index.d.ts +3 -0
  68. package/dist/mailer/types/index.js +1 -0
  69. package/dist/mailer/types/smtpCredentials.d.ts +10 -0
  70. package/dist/mailer/types/smtpOptions.d.ts +26 -0
  71. package/dist/mailer/types/smtpPoolOptions.d.ts +7 -0
  72. package/dist/repository/index.d.ts +1 -0
  73. package/dist/repository/index.js +2 -0
  74. package/dist/repository/repository.d.ts +381 -0
  75. package/dist/repository/types/advancedSearch.d.ts +47 -0
  76. package/dist/repository/types/index.d.ts +8 -0
  77. package/dist/repository/types/index.js +1 -0
  78. package/dist/repository/types/orderBy.d.ts +21 -0
  79. package/dist/repository/types/queryOptions.d.ts +33 -0
  80. package/dist/repository/types/queryOptionsExtendPagination.d.ts +21 -0
  81. package/dist/repository/types/queryOptionsExtendStream.d.ts +16 -0
  82. package/dist/repository/types/selectedFields.d.ts +16 -0
  83. package/dist/repository/types/transaction.d.ts +10 -0
  84. package/dist/repository/types/whereClause.d.ts +15 -0
  85. package/dist/store/index.d.ts +1 -0
  86. package/dist/store/index.js +2 -0
  87. package/dist/store/redis.d.ts +6 -0
  88. package/dist/utils/enums/index.d.ts +1 -0
  89. package/dist/utils/enums/index.js +2 -0
  90. package/dist/utils/enums/utilKeyError.d.ts +8 -0
  91. package/dist/utils/env.d.ts +10 -0
  92. package/dist/utils/index.d.ts +3 -0
  93. package/dist/utils/index.js +2 -0
  94. package/dist/utils/isIsoDateString.d.ts +1 -0
  95. package/dist/utils/stream.d.ts +11 -0
  96. package/dist/utils/types/index.d.ts +1 -0
  97. package/dist/utils/types/index.js +1 -0
  98. package/dist/utils/types/streamWithAsyncIterable.d.ts +26 -0
  99. package/package.json +119 -0
@@ -0,0 +1,381 @@
1
+ import type { Knex } from 'knex';
2
+ import type { Table } from '../database/table';
3
+ import type { StreamWithAsyncIterable } from '../utils/types/streamWithAsyncIterable';
4
+ import type { AdvancedSearch } from './types/advancedSearch';
5
+ import type { QueryOptions } from './types/queryOptions';
6
+ import type { QueryOptionsExtendPagination } from './types/queryOptionsExtendPagination';
7
+ import type { QueryOptionsExtendStream } from './types/queryOptionsExtendStream';
8
+ import type { WhereClause } from './types/whereClause';
9
+ export type OperatorFn = (query: Knex.QueryBuilder, column: string, value: unknown) => Knex.QueryBuilder;
10
+ export declare const operators: Record<keyof WhereClause<unknown>, OperatorFn>;
11
+ /**
12
+ * Provides a type-safe, extensible interface for database operations (CRUD, search, streaming) on a table.
13
+ *
14
+ * - Wraps Knex.js for query building and execution.
15
+ * - Supports advanced search, pagination, field selection, and streaming.
16
+ * - Centralizes error handling for MSSQL.
17
+ *
18
+ * @template TModel - The data model type handled by the repository.
19
+ *
20
+ * Example:
21
+ * ```typescript
22
+ * const repo = new Repository<User>(knex, userTable);
23
+ * const users = await repo.find({ limit: 10 });
24
+ * ```
25
+ */
26
+ export declare class Repository<TModel = unknown> {
27
+ /**
28
+ * The Knex instance used for database operations.
29
+ */
30
+ protected readonly _knex: Knex;
31
+ /**
32
+ * The table associated with this repository.
33
+ * @see {@link Table}
34
+ */
35
+ protected readonly _table: Table;
36
+ /**
37
+ * Creates a new `Repository` instance with the specified Knex.js instance and table object.
38
+ *
39
+ * @param knex - The Knex.js instance used to interact with the database.
40
+ * @param table - The table object representing the database table to interact with.
41
+ */
42
+ constructor(knex: Knex, table: Table);
43
+ /**
44
+ * Finds records in the database based on the specified query options and returns a stream
45
+ * for async iteration. This method is particularly useful when working with large datasets
46
+ * that would be inefficient to load entirely into memory.
47
+ *
48
+ * The stream emits data events for each record and an end event when the stream is finished.
49
+ * It can be consumed using either async iteration or event listeners.
50
+ *
51
+ * @template KModel - The type of the object to retrieve.
52
+ * @param options - The query options to apply to the search. ({@link QueryOptionsExtendStream})
53
+ *
54
+ * @returns A stream with an async iterable interface for consuming the results. ({@link StreamWithAsyncIterable})
55
+ *
56
+ *
57
+ * ### Usage Examples:
58
+ * @example
59
+ * ```typescript
60
+ * // Basic usage with async iteration
61
+ * const stream = userRepository.findStream();
62
+ * for await (const user of stream) {
63
+ * console.log(user);
64
+ * }
65
+ *
66
+ * // With ordering and field selection
67
+ * const stream = userRepository.findStream({
68
+ * selectedFields: ['id', 'name', 'email'],
69
+ * orderBy: ['createdDate', 'desc']
70
+ * });
71
+ *
72
+ * // Using event listeners
73
+ * const stream = userRepository.findStream();
74
+ * stream.on('data', (user) => {
75
+ * console.log('User:', user);
76
+ * });
77
+ * stream.on('error', (error) => {
78
+ * console.error('Stream error:', error);
79
+ * });
80
+ * stream.on('end', () => {
81
+ * console.log('Stream completed');
82
+ * });
83
+ *
84
+ * // With transform function to process records
85
+ * const stream = userRepository.findStream({
86
+ * transform: (chunk, encoding, callback) => {
87
+ * // Transform the data
88
+ * const transformedData = { ...chunk, processed: true };
89
+ * callback(null, transformedData);
90
+ * }
91
+ * });
92
+ * ```
93
+ */
94
+ findStream<KModel extends TModel = NoInfer<TModel>>(options?: QueryOptionsExtendStream<KModel>): StreamWithAsyncIterable<KModel[]>;
95
+ /**
96
+ * Finds records in the database based on the specified query options and returns the results
97
+ * as an array. This method supports comprehensive filtering, pagination, field selection, and sorting
98
+ * to provide flexible data retrieval capabilities.
99
+ *
100
+ * @template KModel - The type of the object to retrieve.
101
+ * @param options - The query options to apply to the search. ({@link QueryOptionsExtendPagination})
102
+ *
103
+ * @throws ({@link CoreError}) Throws an error if no records are found and the `throwIfNoResult` option is enabled. ({@link databaseKeyError.mssqlNoResult})
104
+ * @throws ({@link CoreError}) Throws an error if an MSSQL-specific error occurs during the query execution. ({@link databaseKeyError})
105
+ *
106
+ * @returns An array of records matching the query options. ({@link KModel})
107
+ *
108
+ * ### Usage Examples:
109
+ * @example
110
+ * ```typescript
111
+ * // Basic usage with pagination
112
+ * const users = await userRepository.find({
113
+ * limit: 25,
114
+ * offset: 50 // Get users 51-75
115
+ * });
116
+ *
117
+ * // With field selection
118
+ * const userNames = await userRepository.find({
119
+ * selectedFields: ['id', 'firstName', 'lastName']
120
+ * });
121
+ *
122
+ * // With advanced filtering
123
+ * const activeAdmins = await userRepository.find({
124
+ * advancedSearch: {
125
+ * role: 'admin',
126
+ * status: { $eq: 'active' },
127
+ * lastLogin: { $gte: new Date('2023-01-01') }
128
+ * }
129
+ * });
130
+ *
131
+ * // With OR conditions
132
+ * const results = await userRepository.find({
133
+ * advancedSearch: [
134
+ * { department: 'engineering' },
135
+ * { department: 'design', role: 'lead' }
136
+ * ]
137
+ * });
138
+ *
139
+ * // With sorting
140
+ * const sortedUsers = await userRepository.find({
141
+ * orderBy: ['lastName', 'asc']
142
+ * });
143
+ *
144
+ * // Using a transaction
145
+ * await knex.transaction(async (trx) => {
146
+ * const users = await userRepository.find({
147
+ * advancedSearch: { department: 'finance' },
148
+ * transaction: trx
149
+ * });
150
+ * });
151
+ * ```
152
+ */
153
+ find<KModel extends TModel = NoInfer<TModel>>(options?: QueryOptionsExtendPagination<KModel>): Promise<KModel[]>;
154
+ /**
155
+ * Finds a single record in the database based on the specified query options and returns the result.
156
+ * This method supports comprehensive filtering, field selection, and sorting to provide flexible data retrieval capabilities.
157
+ *
158
+ * @template KModel - The type of the object to retrieve.
159
+ * @param options - The query options to apply to the search. ({@link QueryOptionsExtendPagination})
160
+ *
161
+ * @throws ({@link CoreError}) Throws an error if no records are found and the `throwIfNoResult` option is enabled. ({@link databaseKeyError.mssqlNoResult})
162
+ * @throws ({@link CoreError}) Throws an error if an MSSQL-specific error occurs during the query execution. ({@link databaseKeyError})
163
+ *
164
+ * @returns A single record matching the query options. ({@link KModel})
165
+ *
166
+ * ### Usage Examples:
167
+ * @example
168
+ * ```typescript
169
+ * // Basic usage
170
+ * const user = await userRepository.findOne({
171
+ * advancedSearch: { id: 1 }
172
+ * });
173
+ *
174
+ * // With field selection
175
+ * const user = await userRepository.findOne({
176
+ * selectedFields: ['id', 'firstName', 'lastName'],
177
+ * advancedSearch: { id: 1 }
178
+ * });
179
+ *
180
+ * // With advanced filtering
181
+ * const user = await userRepository.findOne({
182
+ * advancedSearch: {
183
+ * role: 'admin',
184
+ * status: { $eq: 'active' },
185
+ * }
186
+ * });
187
+ *
188
+ * // With sorting
189
+ * const user = await userRepository.findOne({
190
+ * orderBy: ['lastName', 'asc']
191
+ * });
192
+ *
193
+ * // Using a transaction
194
+ * await knex.transaction(async (trx) => {
195
+ * const user = await userRepository.findOne({
196
+ * advancedSearch: { department: 'finance' },
197
+ * transaction: trx
198
+ * });
199
+ * });
200
+ * ```
201
+ */
202
+ findOne<KModel extends TModel = NoInfer<TModel>>(options: Omit<QueryOptions<KModel>, 'advancedSearch'> & Required<Pick<QueryOptions<KModel>, 'advancedSearch'>>): Promise<KModel>;
203
+ /**
204
+ * Counts the number of records in the database based on the specified query options.
205
+ * This method supports advanced search capabilities to filter the records before counting.
206
+ *
207
+ * @template KModel - The type of the object to count.
208
+ * @param options - The query options to apply to the search. ({@link QueryOptions})
209
+ *
210
+ * @throws ({@link CoreError}) Throws an error if no records are found and the `throwIfNoResult` option is enabled. ({@link databaseKeyError.mssqlNoResult})
211
+ * @throws ({@link CoreError}) Throws an error if an MSSQL-specific error occurs during the query execution. ({@link databaseKeyError})
212
+ *
213
+ * @returns The count of records matching the query options.
214
+ *
215
+ * ### Usage Examples:
216
+ * @example
217
+ * ```typescript
218
+ * // Basic usage
219
+ * const userCount = await userRepository.count();
220
+ *
221
+ * // With advanced filtering
222
+ * const activeUserCount = await userRepository.count({
223
+ * advancedSearch: { status: 'active' }
224
+ * });
225
+ *
226
+ * // Using a transaction
227
+ * await knex.transaction(async (trx) => {
228
+ * const userCount = await userRepository.count({
229
+ * advancedSearch: { department: 'finance' },
230
+ * transaction: trx
231
+ * });
232
+ * });
233
+ * ```
234
+ */
235
+ count<KModel extends TModel = NoInfer<TModel>>(options?: Omit<QueryOptions<KModel>, 'selectedFields' | 'orderBy'>): Promise<number>;
236
+ /**
237
+ * Inserts new records into the database and returns the inserted records.
238
+ * This method supports bulk insertion of multiple records at once.
239
+ *
240
+ * @template KModel - The type of the object to insert.
241
+ * @param data - The data to insert. Can be a single object or an array of objects.
242
+ * @param options - The query options to apply to the insertion. ({@link QueryOptions})
243
+ *
244
+ * @throws ({@link CoreError}) Throws an error if an MSSQL-specific error occurs during the query execution. ({@link databaseKeyError})
245
+ *
246
+ * @returns An array of inserted records.
247
+ *
248
+ * ### Usage Examples:
249
+ * @example
250
+ * ```typescript
251
+ * // Basic usage
252
+ * const newUser = await userRepository.insert({ name: 'John Doe', email: 'john.doe@example.com' });
253
+ *
254
+ * // With bulk insertion
255
+ * const users = await userRepository.insert([
256
+ * { name: 'Jane Doe', email: 'jane.doe@example.com' },
257
+ * { name: 'John Smith', email: 'john.smith@example.com' }
258
+ * ]);
259
+ *
260
+ * // Using a transaction
261
+ * await knex.transaction(async (trx) => {
262
+ * const newUser = await userRepository.insert({ name: 'John Doe', email: 'john.doe@example.com' }, {
263
+ * transaction: trx
264
+ * });
265
+ * });
266
+ * ```
267
+ */
268
+ insert<KModel extends TModel = NoInfer<TModel>>(data: Partial<KModel> | Partial<KModel>[], options?: Omit<QueryOptions<KModel>, 'advancedSearch' | 'orderBy'>): Promise<KModel[]>;
269
+ /**
270
+ * Updates existing records in the database based on the specified query options and returns the updated records.
271
+ * This method supports advanced search capabilities to filter the records before updating.
272
+ *
273
+ * @template KModel - The type of the object to update.
274
+ * @param data - The data to update. Can be a single object or an array of objects.
275
+ * @param options - The query options to apply to the update. ({@link QueryOptions})
276
+ *
277
+ * @throws ({@link CoreError}) Throws an error if an MSSQL-specific error occurs during the query execution. ({@link databaseKeyError})
278
+ *
279
+ * @returns An array of updated records.
280
+ *
281
+ * ### Usage Examples:
282
+ * @example
283
+ * ```typescript
284
+ * // Basic usage
285
+ * const updatedUser = await userRepository.update({ name: 'John Doe' }, {
286
+ * advancedSearch: { id: 1 }
287
+ * });
288
+ *
289
+ * // With advanced filtering
290
+ * const updatedUsers = await userRepository.update({ status: 'inactive' }, {
291
+ * advancedSearch: { role: 'admin' }
292
+ * });
293
+ *
294
+ * // Using a transaction
295
+ * await knex.transaction(async (trx) => {
296
+ * const updatedUser = await userRepository.update({ name: 'John Doe' }, {
297
+ * advancedSearch: { id: 1 },
298
+ * transaction: trx
299
+ * });
300
+ * });
301
+ * ```
302
+ */
303
+ update<KModel extends TModel = NoInfer<TModel>>(data: Partial<KModel>, options: Omit<QueryOptions<KModel>, 'orderBy' | 'advancedSearch'> & Required<Pick<QueryOptions<KModel>, 'advancedSearch'>>): Promise<KModel[]>;
304
+ /**
305
+ * Deletes records from the database based on the specified query options and returns the deleted records.
306
+ * This method supports advanced search capabilities to filter the records before deletion.
307
+ *
308
+ * @template KModel - The type of the object to delete.
309
+ * @param options - The query options to apply to the deletion. ({@link QueryOptions})
310
+ *
311
+ * @throws ({@link CoreError}) Throws an error if an MSSQL-specific error occurs during the query execution. ({@link databaseKeyError})
312
+ *
313
+ * @returns An array of deleted records.
314
+ *
315
+ * ### Usage Examples:
316
+ * @example
317
+ * ```typescript
318
+ * // Basic usage
319
+ * const deletedUser = await userRepository.delete({
320
+ * advancedSearch: { id: 1 }
321
+ * });
322
+ *
323
+ * // With advanced filtering
324
+ * const deletedUsers = await userRepository.delete({
325
+ * advancedSearch: { status: 'inactive' }
326
+ * });
327
+ *
328
+ * // Using a transaction
329
+ * await knex.transaction(async (trx) => {
330
+ * const deletedUser = await userRepository.delete({
331
+ * advancedSearch: { id: 1 },
332
+ * transaction: trx
333
+ * });
334
+ * });
335
+ * ```
336
+ */
337
+ delete<KModel extends TModel = NoInfer<TModel>>(options: Omit<QueryOptions<KModel>, 'orderBy' | 'advancedSearch'> & Required<Pick<QueryOptions<KModel>, 'advancedSearch'>>): Promise<KModel[]>;
338
+ /**
339
+ * Applies advanced search criteria to a Knex.js query builder. This method supports complex queries
340
+ * using operators like `$eq`, `$neq`, `$lt`, `$lte`, `$gt`, `$gte`, `$in`, `$nin`, `$between`, `$nbetween`,
341
+ * `$like`, `$nlike`, and `$isNull`. It also supports basic string searches and field selection.
342
+ *
343
+ * @template KModel - The type of the object to search for.
344
+ * @param query - The Knex.js query builder to apply the search criteria to. ({@link Knex.QueryBuilder})
345
+ * @param search - The advanced search criteria to apply. Can be a single object or an array of objects. ({@link AdvancedSearch})
346
+ */
347
+ protected _applySearch<KModel>(query: Knex.QueryBuilder, search: AdvancedSearch<KModel> | AdvancedSearch<KModel>[]): void;
348
+ /**
349
+ * Handles errors that occur during query execution. This method centralizes error handling
350
+ * for MSSQL-specific errors and throws a {@link CoreError} with relevant information.
351
+ *
352
+ * @param error - The error object thrown by Knex.js.
353
+ * @param query - The Knex.js query builder that caused the error.
354
+ *
355
+ * @throws ({@link CoreError}) Throws an error if an MSSQL-specific error occurs during the query execution. ({@link databaseKeyError})
356
+ *
357
+ * @returns Never returns, always throws an error.
358
+ */
359
+ protected _handleError(error: unknown, query: Knex.QueryBuilder): never;
360
+ /**
361
+ * Determines if the provided data is a complex query (i.e., a WhereClause).
362
+ *
363
+ * @param data - The data to check.
364
+ * @returns True if the data is a WhereClause, false otherwise.
365
+ */
366
+ private _isComplexQuery;
367
+ /**
368
+ * Executes a Knex.js query and returns the result. This method provides centralized
369
+ * error handling and supports the option to throw an error if no records are found.
370
+ *
371
+ * @template KModel - The type of the records returned by the query.
372
+ * @param query - The Knex.js query builder to execute.
373
+ * @param throwIfNoResult - Whether to throw an error if no records are found.
374
+ *
375
+ * @throws ({@link CoreError}) Throws an error if no records are found and the `throwIfNoResult` option is enabled. ({@link databaseKeyError.mssqlNoResult})
376
+ * @throws ({@link CoreError}) Throws an error if an MSSQL-specific error occurs during the query execution. ({@link databaseKeyError})
377
+ *
378
+ * @returns An array of records returned by the query.
379
+ */
380
+ protected _executeQuery<KModel>(query: Knex.QueryBuilder, throwIfNoResult?: boolean): Promise<KModel[]>;
381
+ }
@@ -0,0 +1,47 @@
1
+ import type { WhereClause } from './whereClause';
2
+ import type { SelectedFields } from './selectedFields';
3
+ /**
4
+ * Defines an advanced search model using either plain partials of the model T or a {@link WhereClause} filter for more dynamic querying.
5
+ *
6
+ * @template TModel - The model type to be used for the advanced search.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * interface User {
11
+ * id: number;
12
+ * name: string;
13
+ * }
14
+ *
15
+ * interface Basket {
16
+ * id: number;
17
+ * userId: number;
18
+ * products: Product[];
19
+ * }
20
+ *
21
+ * const example1: AdvancedSearch<User> = {
22
+ * id: 1
23
+ * };
24
+ *
25
+ * const example2: AdvancedSearch<User> = {
26
+ * name: {
27
+ * $eq: 'John'
28
+ * }
29
+ * };
30
+ *
31
+ * const example3: AdvancedSearch<User> = {
32
+ * $q: 'John'
33
+ * };
34
+ *
35
+ * const example4: AdvancedSearch<User & Basket> = {
36
+ * 'basket.id': 1,
37
+ * };
38
+ * ```
39
+ */
40
+ export type AdvancedSearch<TModel> = {
41
+ $q?: string | number | {
42
+ selectedFields: SelectedFields<TModel>;
43
+ value: string | number;
44
+ };
45
+ } & {
46
+ [Key in keyof TModel]?: TModel[Key] | Partial<WhereClause<TModel[Key]>>;
47
+ };
@@ -0,0 +1,8 @@
1
+ export type * from './advancedSearch';
2
+ export type * from './orderBy';
3
+ export type * from './queryOptions';
4
+ export type * from './queryOptionsExtendPagination';
5
+ export type * from './queryOptionsExtendStream';
6
+ export type * from './selectedFields';
7
+ export type * from './transaction';
8
+ export type * from './whereClause';
@@ -0,0 +1 @@
1
+ // @bun
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Represents an ordering instruction for queries.
3
+ *
4
+ * This tuple specifies the field to order by and the direction of the ordering.
5
+ *
6
+ * @template TModel - The type of the object to order by.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * type User = {
11
+ * id: number;
12
+ * name: string;
13
+ * };
14
+ *
15
+ * const orderBy: OrderBy<User> = ['id', 'asc'];
16
+ * ```
17
+ */
18
+ export type OrderBy<TModel> = [
19
+ Extract<keyof TModel, string>,
20
+ 'asc' | 'desc'
21
+ ];
@@ -0,0 +1,33 @@
1
+ import type { AdvancedSearch } from './advancedSearch';
2
+ import type { OrderBy } from './orderBy';
3
+ import type { SelectedFields } from './selectedFields';
4
+ import type { Transaction } from './transaction';
5
+ /**
6
+ * This interface defines the basic options for a repository query.
7
+ *
8
+ * @template TModel - The type of the object to retrieve.
9
+ */
10
+ export interface QueryOptions<TModel> {
11
+ /**
12
+ * The advanced search options to apply to the query. Can be a single object or an array of objects.
13
+ * @see {@link AdvancedSearch}
14
+ */
15
+ advancedSearch?: AdvancedSearch<NoInfer<TModel>> | AdvancedSearch<NoInfer<TModel>>[];
16
+ /**
17
+ * The fields to select in the query. If not provided, all fields are selected. ({@link SelectedFields})
18
+ */
19
+ selectedFields?: SelectedFields<NoInfer<TModel>>;
20
+ /**
21
+ * Order the results by a specific column and direction. ({@link OrderBy})
22
+ */
23
+ orderBy?: OrderBy<NoInfer<TModel>>;
24
+ /**
25
+ * Whether to throw an error if the query does not return any result.
26
+ * @defaultValue false
27
+ */
28
+ throwIfNoResult?: boolean;
29
+ /**
30
+ * The transaction context for the query. ({@link Transaction})
31
+ */
32
+ transaction?: Transaction;
33
+ }
@@ -0,0 +1,21 @@
1
+ import type { QueryOptions } from './queryOptions';
2
+ /**
3
+ * Extends {@link QueryOptions} to add pagination capabilities for queries.
4
+ *
5
+ * @template TModel - The type of the object to retrieve.
6
+ *
7
+ * This interface allows specifying pagination options such as limit and offset
8
+ * in addition to the base query options.
9
+ */
10
+ export interface QueryOptionsExtendPagination<TModel> extends QueryOptions<TModel> {
11
+ /**
12
+ * The limit of the query
13
+ * @defaultValue 100
14
+ */
15
+ limit?: number;
16
+ /**
17
+ * The offset of the query
18
+ * @defaultValue 0
19
+ */
20
+ offset?: number;
21
+ }
@@ -0,0 +1,16 @@
1
+ import type { QueryOptions } from './queryOptions';
2
+ /**
3
+ * Interface Option query with stream option inherited from {@link QueryOptions}
4
+ *
5
+ * @template TModel - The type of the object to retrieve.
6
+ */
7
+ export interface QueryOptionsExtendStream<TModel> extends QueryOptions<TModel> {
8
+ /**
9
+ * Transform the chunk before emitting it.
10
+ *
11
+ * @param chunk - The chunk to transform.
12
+ * @param encoding - The encoding of the chunk.
13
+ * @param callback - The callback to call when the transformation is complete.
14
+ */
15
+ transform?: (chunk: NoInfer<TModel>, encoding: string, callback: (error?: Error | null, data?: NoInfer<TModel>) => void) => void;
16
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Defines which columns to select in a query using an array of keys from the model type.
3
+ *
4
+ * @template TModel - The type of the object to select fields from.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * interface User {
9
+ * id: number;
10
+ * name: string;
11
+ * }
12
+ *
13
+ * const selection: SelectedFields<User> = ['id', 'name'];
14
+ * ```
15
+ */
16
+ export type SelectedFields<TModel> = (keyof TModel extends string ? keyof TModel : never)[] | string[];
@@ -0,0 +1,10 @@
1
+ import type { Knex } from 'knex';
2
+ /**
3
+ * Represents a database transaction object provided by Knex.
4
+ *
5
+ * This type is used to perform a series of database operations as a single unit of work,
6
+ * ensuring that either all operations succeed or none are applied.
7
+ *
8
+ * @see {@link https://knexjs.org/ Knex documentation} for more details on transaction usage. ({@link Knex.Transaction})
9
+ */
10
+ export type Transaction = Knex.Transaction;
@@ -0,0 +1,15 @@
1
+ export interface WhereClause<TValue> {
2
+ $eq: TValue;
3
+ $neq: TValue;
4
+ $lt: TValue;
5
+ $lte: TValue;
6
+ $gt: TValue;
7
+ $gte: TValue;
8
+ $in: TValue[];
9
+ $nin: TValue[];
10
+ $between: [TValue, TValue];
11
+ $nbetween: [TValue, TValue];
12
+ $like: string;
13
+ $nlike: string;
14
+ $isNull: boolean;
15
+ }
@@ -0,0 +1 @@
1
+ export * from './redis';
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import"../chunk-rr6e20n5.js";import{Redis as i}from"ioredis";class t{_client;constructor(e){this._client=new i(e)}get client(){return this._client}}export{t as Redis};export{t as c};
@@ -0,0 +1,6 @@
1
+ import { Redis as IoRedis, type RedisOptions } from 'ioredis';
2
+ export declare class Redis {
3
+ private readonly _client;
4
+ constructor(options: RedisOptions);
5
+ get client(): IoRedis;
6
+ }
@@ -0,0 +1 @@
1
+ export * from './utilKeyError';
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{e}from"../../chunk-0pft81dh.js";import"../../chunk-rr6e20n5.js";export{e as utilKeyError};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Util error key is a list of errors in the util context.
3
+ * Each property represents a specific util error scenario.
4
+ */
5
+ export declare const utilKeyError: {
6
+ /** Error when the environment is invalid. */
7
+ readonly invalidEnvironment: "core.error.util.invalid_environment";
8
+ };
@@ -0,0 +1,10 @@
1
+ import type { TSchema } from '@sinclair/typebox';
2
+ /**
3
+ * Validates the environment variables based on the provided schema.
4
+ *
5
+ * @param schema - The schema to validate the environment variables against.
6
+ * @param env - The environment variables to validate. Defaults to `process.env`.
7
+ *
8
+ * @throws ({@link CoreError}): If the environment variables are invalid based on the schema. ({@link utilKeyError.invalidEnvironment})
9
+ */
10
+ export declare const validateEnv: (schema: TSchema, env?: Record<string, unknown>) => void;
@@ -0,0 +1,3 @@
1
+ export * from './env';
2
+ export * from './isIsoDateString';
3
+ export * from './stream';