@mrxsys/mrx-core 2.4.0 → 2.5.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.
- package/CHANGELOG.md +318 -33
- package/README.md +3 -3
- package/dist/chunk-1a3wj3m1.js +272 -0
- package/dist/chunk-370444pc.js +43 -0
- package/dist/chunk-5qtpggzv.js +38 -0
- package/dist/chunk-84mqvfsk.js +69 -0
- package/dist/chunk-cq973ydc.js +82 -0
- package/dist/chunk-f5z7x01b.js +352 -0
- package/dist/chunk-pc66jgqv.js +220 -0
- package/dist/chunk-s07amdhx.js +77 -0
- package/dist/chunk-v8v7982b.js +58 -0
- package/dist/chunk-vknq69e0.js +23 -0
- package/dist/chunk-yvyahr2h.js +40 -0
- package/dist/errors/baseError.d.ts +9 -0
- package/dist/errors/enums/httpErrorStatusCodes.d.ts +42 -0
- package/dist/errors/httpError.d.ts +14 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +11 -0
- package/dist/errors/types/baseErrorOptions.d.ts +15 -0
- package/dist/errors/types/httpErrorOptions.d.ts +13 -0
- package/dist/errors/types/index.d.ts +2 -0
- package/dist/modules/data/data.d.ts +115 -0
- package/dist/modules/data/enums/dataErrorKeys.d.ts +3 -0
- package/dist/modules/data/index.d.ts +1 -0
- package/dist/modules/data/index.js +16 -0
- package/dist/modules/data/transformers/camelCase.d.ts +25 -0
- package/dist/modules/data/transformers/index.d.ts +4 -0
- package/dist/modules/data/transformers/index.js +32 -0
- package/dist/modules/data/transformers/kebabCase.d.ts +25 -0
- package/dist/modules/data/transformers/pascalCase.d.ts +25 -0
- package/dist/modules/data/transformers/snakeCase.d.ts +25 -0
- package/dist/modules/data/types/camelCase.d.ts +1 -0
- package/dist/modules/data/types/caseTransformer.d.ts +13 -0
- package/dist/modules/data/types/index.d.ts +10 -0
- package/dist/modules/data/types/kebabCase.d.ts +1 -0
- package/dist/modules/data/types/pascalCase.d.ts +2 -0
- package/dist/modules/data/types/snakeCase.d.ts +1 -0
- package/dist/modules/data/types/transformKeysCamelCase.d.ts +4 -0
- package/dist/modules/data/types/transformKeysKebabCase.d.ts +4 -0
- package/dist/modules/data/types/transformKeysPascalCase.d.ts +4 -0
- package/dist/modules/data/types/transformKeysSnakeCase.d.ts +4 -0
- package/dist/modules/data/types/transformObjectKeys.d.ts +9 -0
- package/dist/modules/database/enums/databaseErrorKeys.d.ts +28 -0
- package/dist/modules/database/enums/mssqlErrorCode.d.ts +25 -0
- package/dist/modules/database/events/index.d.ts +2 -0
- package/dist/modules/database/events/mssqlEventMap.d.ts +6 -0
- package/dist/modules/database/events/tableEventMap.d.ts +7 -0
- package/dist/modules/database/index.d.ts +2 -0
- package/dist/modules/database/index.js +14 -0
- package/dist/{database → modules/database}/mssql.d.ts +21 -25
- package/dist/{database → modules/database}/table.d.ts +6 -6
- package/dist/modules/database/types/index.d.ts +3 -0
- package/dist/{database → modules/database}/types/mssqlDatabaseOption.d.ts +16 -37
- package/dist/modules/database/types/mssqlEventLog.d.ts +14 -0
- package/dist/modules/database/types/queryContext.d.ts +11 -0
- package/dist/modules/elysia/crud/crud.d.ts +46 -0
- package/dist/modules/elysia/crud/index.d.ts +1 -0
- package/dist/modules/elysia/crud/index.js +299 -0
- package/dist/modules/elysia/crud/types/crudOperationBaseOptions.d.ts +6 -0
- package/dist/modules/elysia/crud/types/crudOperationCountOptions.d.ts +2 -0
- package/dist/modules/elysia/crud/types/crudOperationDeleteOneOptions.d.ts +2 -0
- package/dist/modules/elysia/crud/types/crudOperationDeleteOptions.d.ts +2 -0
- package/dist/modules/elysia/crud/types/crudOperationFindOneOptions.d.ts +2 -0
- package/dist/modules/elysia/crud/types/crudOperationFindOptions.d.ts +2 -0
- package/dist/modules/elysia/crud/types/crudOperationInsertOptions.d.ts +2 -0
- package/dist/modules/elysia/crud/types/crudOperationUpdateOneOptions.d.ts +2 -0
- package/dist/modules/elysia/crud/types/crudOperationUpdateOptions.d.ts +2 -0
- package/dist/modules/elysia/crud/types/crudOperationsOptions.d.ts +18 -0
- package/dist/modules/elysia/crud/types/crudOptions.d.ts +23 -0
- package/dist/modules/elysia/crud/types/index.d.ts +11 -0
- package/dist/modules/elysia/crudSchema/crudSchema.d.ts +18 -0
- package/dist/modules/elysia/crudSchema/index.d.ts +1 -0
- package/dist/modules/elysia/crudSchema/index.js +10 -0
- package/dist/modules/elysia/crudSchema/types/adaptiveWhereClauseSchema.d.ts +31 -0
- package/dist/modules/elysia/crudSchema/types/crudModelsType.d.ts +14 -0
- package/dist/modules/elysia/crudSchema/types/crudSchemaOperations.d.ts +10 -0
- package/dist/modules/elysia/crudSchema/types/crudSchemaOptions.d.ts +13 -0
- package/dist/modules/elysia/crudSchema/types/index.d.ts +8 -0
- package/dist/modules/elysia/crudSchema/types/orderSchema.d.ts +11 -0
- package/dist/modules/elysia/crudSchema/types/qSchema.d.ts +15 -0
- package/dist/modules/elysia/crudSchema/types/queryOptionsBuilderOptions.d.ts +11 -0
- package/dist/modules/elysia/crudSchema/types/selectedFieldSchema.d.ts +6 -0
- package/dist/modules/elysia/crudSchema/utils/createAdaptiveWhereClauseSchema.d.ts +17 -0
- package/dist/modules/elysia/crudSchema/utils/createCountResponse200Schema.d.ts +11 -0
- package/dist/modules/elysia/crudSchema/utils/createCountSchema.d.ts +16 -0
- package/dist/modules/elysia/crudSchema/utils/createDeleteSchema.d.ts +18 -0
- package/dist/modules/elysia/crudSchema/utils/createFiltersSchema.d.ts +17 -0
- package/dist/modules/elysia/crudSchema/utils/createFindSchema.d.ts +22 -0
- package/dist/modules/elysia/crudSchema/utils/createIdParamSchema.d.ts +4 -0
- package/dist/modules/elysia/crudSchema/utils/createInsertSchema.d.ts +8 -0
- package/dist/modules/elysia/crudSchema/utils/createOrderSchema.d.ts +12 -0
- package/dist/modules/elysia/crudSchema/utils/createPropertiesSchema.d.ts +12 -0
- package/dist/modules/elysia/crudSchema/utils/createQSchema.d.ts +12 -0
- package/dist/modules/elysia/crudSchema/utils/createResponse200Schema.d.ts +5 -0
- package/dist/modules/elysia/crudSchema/utils/createSelectedFieldsSchema.d.ts +12 -0
- package/dist/modules/elysia/crudSchema/utils/createUpdateOneSchema.d.ts +4 -0
- package/dist/modules/elysia/crudSchema/utils/createUpdateSchema.d.ts +10 -0
- package/dist/modules/elysia/crudSchema/utils/index.d.ts +15 -0
- package/dist/modules/elysia/crudSchema/utils/index.js +37 -0
- package/dist/modules/elysia/crudSchema/utils/isDateFromElysiaTypeBox.d.ts +2 -0
- package/dist/modules/elysia/dbResolver/dbResolver.d.ts +17 -0
- package/dist/modules/elysia/dbResolver/enums/dbResolverErrorKeys.d.ts +3 -0
- package/dist/modules/elysia/dbResolver/index.d.ts +1 -0
- package/dist/modules/elysia/dbResolver/index.js +14 -0
- package/dist/modules/elysia/dbResolver/types/dynamicDbOptions.d.ts +7 -0
- package/dist/modules/elysia/dbResolver/types/index.d.ts +1 -0
- package/dist/modules/elysia/error/error.d.ts +34 -0
- package/dist/modules/elysia/error/index.d.ts +1 -0
- package/dist/modules/elysia/error/index.js +58 -0
- package/dist/modules/elysia/jwt/enums/jwtErrorKeys.d.ts +4 -0
- package/dist/modules/elysia/jwt/index.d.ts +1 -0
- package/dist/modules/elysia/jwt/index.js +81 -0
- package/dist/modules/elysia/jwt/jwt.d.ts +119 -0
- package/dist/modules/elysia/jwt/types/index.d.ts +1 -0
- package/dist/modules/elysia/jwt/types/jwtOptions.d.ts +98 -0
- package/dist/modules/elysia/microservice/index.d.ts +1 -0
- package/dist/modules/elysia/microservice/index.js +96 -0
- package/dist/{elysia → modules/elysia/microservice}/microservice.d.ts +1 -1
- package/dist/modules/elysia/ratelimit/enums/ratelimitErrorKeys.d.ts +3 -0
- package/dist/modules/elysia/ratelimit/index.d.ts +1 -0
- package/dist/modules/elysia/ratelimit/index.js +55 -0
- package/dist/{elysia → modules/elysia/ratelimit}/ratelimit.d.ts +3 -13
- package/dist/modules/elysia/ratelimit/types/index.d.ts +1 -0
- package/dist/{elysia → modules/elysia/ratelimit}/types/rateLimitOptions.d.ts +6 -16
- package/dist/modules/logger/enums/loggerErrorKeys.d.ts +6 -0
- package/dist/modules/logger/events/index.d.ts +1 -0
- package/dist/modules/logger/events/loggerEvents.d.ts +11 -0
- package/dist/modules/logger/index.d.ts +1 -0
- package/dist/modules/logger/index.js +139 -0
- package/dist/modules/logger/logger.d.ts +189 -0
- package/dist/{logger → modules/logger}/strategies/consoleLogger.d.ts +4 -4
- package/dist/{logger → modules/logger}/strategies/fileLogger.d.ts +4 -4
- package/dist/modules/logger/strategies/index.d.ts +2 -0
- package/dist/modules/logger/strategies/index.js +44 -0
- package/dist/modules/logger/types/index.d.ts +6 -0
- package/dist/modules/logger/types/index.js +1 -0
- package/dist/{logger → modules/logger}/types/logStreamChunk.d.ts +4 -4
- package/dist/{logger → modules/logger}/types/loggerStrategy.d.ts +1 -1
- package/dist/modules/mailer/enums/mailerErrorKeys.d.ts +5 -0
- package/dist/modules/mailer/index.d.ts +1 -0
- package/dist/modules/mailer/index.js +64 -0
- package/dist/{mailer → modules/mailer}/smtp.d.ts +6 -6
- package/dist/modules/mailer/types/index.d.ts +3 -0
- package/dist/modules/mailer/types/index.js +1 -0
- package/dist/{mailer → modules/mailer}/types/smtpCredentials.d.ts +2 -2
- package/dist/{mailer → modules/mailer}/types/smtpOptions.d.ts +5 -5
- package/dist/{mailer → modules/mailer}/types/smtpPoolOptions.d.ts +1 -1
- package/dist/modules/repository/index.d.ts +1 -0
- package/dist/modules/repository/index.js +10 -0
- package/dist/modules/repository/repository.d.ts +421 -0
- package/dist/modules/repository/types/adaptiveWhereClause.d.ts +30 -0
- package/dist/modules/repository/types/filter.d.ts +43 -0
- package/dist/modules/repository/types/index.d.ts +8 -0
- package/dist/modules/repository/types/index.js +1 -0
- package/dist/modules/repository/types/orderByItem.d.ts +42 -0
- package/dist/modules/repository/types/queryOptions.d.ts +36 -0
- package/dist/{repository → modules/repository}/types/queryOptionsExtendPagination.d.ts +2 -2
- package/dist/{repository → modules/repository}/types/queryOptionsExtendStream.d.ts +1 -1
- package/dist/modules/repository/types/selectedFields.d.ts +37 -0
- package/dist/modules/singletonManager/enums/singletonManagerErrorKeys.d.ts +4 -0
- package/dist/modules/singletonManager/index.d.ts +1 -0
- package/dist/modules/singletonManager/index.js +8 -0
- package/dist/modules/singletonManager/singletonManager.d.ts +75 -0
- package/dist/modules/typedEventEmitter/index.d.ts +1 -0
- package/dist/modules/typedEventEmitter/index.js +7 -0
- package/dist/{typedEventEmitter → modules/typedEventEmitter}/typedEventEmitter.d.ts +33 -11
- package/dist/modules/typedEventEmitter/types/index.d.ts +1 -0
- package/dist/modules/typedEventEmitter/types/index.js +1 -0
- package/dist/utils/enums/utilsErrorKeys.d.ts +3 -0
- package/dist/utils/env.d.ts +1 -1
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +32 -1
- package/dist/utils/isDateString.d.ts +16 -0
- package/dist/utils/stream.d.ts +12 -1
- package/dist/utils/types/index.d.ts +1 -1
- package/dist/utils/types/streamWithAsyncIterable.d.ts +12 -5
- package/package.json +128 -128
- package/dist/chunk-1c7w5cx7.js +0 -3
- package/dist/chunk-40pg2cqx.js +0 -2
- package/dist/chunk-4v4tp5qj.js +0 -2
- package/dist/chunk-4w7nd4nw.js +0 -2
- package/dist/chunk-5nvsx7md.js +0 -2
- package/dist/chunk-89mnpfvy.js +0 -2
- package/dist/chunk-91srr77d.js +0 -2
- package/dist/chunk-9hj714bv.js +0 -2
- package/dist/chunk-9rss6865.js +0 -2
- package/dist/chunk-df9xr1f5.js +0 -2
- package/dist/chunk-dq00mfya.js +0 -2
- package/dist/chunk-fnb68m68.js +0 -2
- package/dist/chunk-g6a16nyh.js +0 -2
- package/dist/chunk-gtgpa8nc.js +0 -2
- package/dist/chunk-gxjax5n3.js +0 -2
- package/dist/chunk-h9er1sh5.js +0 -2
- package/dist/chunk-mwpajm9x.js +0 -2
- package/dist/chunk-n5w9cwwg.js +0 -2
- package/dist/chunk-pt7wrvtr.js +0 -2
- package/dist/chunk-qndyhwdn.js +0 -2
- package/dist/chunk-v5dfx8mh.js +0 -2
- package/dist/chunk-wgq0yyqw.js +0 -2
- package/dist/chunk-wtfcgg9s.js +0 -2
- package/dist/chunk-z00b1r18.js +0 -2
- package/dist/data/data.d.ts +0 -99
- package/dist/data/enums/dataErrorKeys.d.ts +0 -7
- package/dist/data/enums/index.d.ts +0 -1
- package/dist/data/enums/index.js +0 -2
- package/dist/data/index.d.ts +0 -1
- package/dist/data/index.js +0 -2
- package/dist/data/transformers/camelCase.d.ts +0 -25
- package/dist/data/transformers/index.d.ts +0 -4
- package/dist/data/transformers/index.js +0 -2
- package/dist/data/transformers/kebabCase.d.ts +0 -25
- package/dist/data/transformers/pascalCase.d.ts +0 -25
- package/dist/data/transformers/snakeCase.d.ts +0 -25
- package/dist/data/types/index.d.ts +0 -1
- package/dist/data/types/keyTransformer.d.ts +0 -11
- package/dist/database/enums/databaseErrorKeys.d.ts +0 -52
- package/dist/database/enums/index.d.ts +0 -2
- package/dist/database/enums/index.js +0 -2
- package/dist/database/enums/mssqlErrorCode.d.ts +0 -25
- package/dist/database/events/index.d.ts +0 -2
- package/dist/database/events/mssqlEventMap.d.ts +0 -6
- package/dist/database/events/tableEventMap.d.ts +0 -7
- package/dist/database/index.d.ts +0 -2
- package/dist/database/index.js +0 -2
- package/dist/database/types/index.d.ts +0 -3
- package/dist/database/types/mssqlEventLog.d.ts +0 -29
- package/dist/database/types/queryContext.d.ts +0 -11
- package/dist/elysia/advancedSearch.d.ts +0 -460
- package/dist/elysia/crud.d.ts +0 -609
- package/dist/elysia/dynamicDatabaseSelector.d.ts +0 -352
- package/dist/elysia/enums/elysiaErrorKeys.d.ts +0 -12
- package/dist/elysia/enums/httpStatusCode.d.ts +0 -241
- package/dist/elysia/enums/index.d.ts +0 -2
- package/dist/elysia/enums/index.js +0 -2
- package/dist/elysia/error.d.ts +0 -46
- package/dist/elysia/index.d.ts +0 -7
- package/dist/elysia/index.js +0 -2
- package/dist/elysia/jwt.d.ts +0 -46
- package/dist/elysia/schemas/index.d.ts +0 -2
- package/dist/elysia/schemas/index.js +0 -2
- package/dist/elysia/types/crudOptions.d.ts +0 -126
- package/dist/elysia/types/crudRoutes.d.ts +0 -2
- package/dist/elysia/types/dynamicDatabaseSelectorPluginOptions.d.ts +0 -30
- package/dist/elysia/types/index.d.ts +0 -5
- package/dist/elysia/types/jwtOptions.d.ts +0 -92
- package/dist/error/coreError.d.ts +0 -89
- package/dist/error/index.d.ts +0 -1
- package/dist/error/index.js +0 -2
- package/dist/error/types/coreErrorOptions.d.ts +0 -21
- package/dist/error/types/index.d.ts +0 -1
- package/dist/index.d.ts +0 -68
- package/dist/index.js +0 -2
- package/dist/logger/enums/index.d.ts +0 -1
- package/dist/logger/enums/index.js +0 -2
- package/dist/logger/enums/loggerErrorKeys.d.ts +0 -6
- package/dist/logger/events/index.d.ts +0 -1
- package/dist/logger/events/loggerEvents.d.ts +0 -4
- package/dist/logger/index.d.ts +0 -1
- package/dist/logger/index.js +0 -2
- package/dist/logger/logger.d.ts +0 -173
- package/dist/logger/strategies/index.d.ts +0 -2
- package/dist/logger/strategies/index.js +0 -2
- package/dist/logger/types/index.d.ts +0 -6
- package/dist/mailer/enums/index.d.ts +0 -1
- package/dist/mailer/enums/index.js +0 -2
- package/dist/mailer/enums/mailerErrorKeys.d.ts +0 -8
- package/dist/mailer/index.d.ts +0 -1
- package/dist/mailer/index.js +0 -2
- package/dist/mailer/types/index.d.ts +0 -3
- package/dist/repository/index.d.ts +0 -1
- package/dist/repository/index.js +0 -2
- package/dist/repository/repository.d.ts +0 -378
- package/dist/repository/types/advancedSearch.d.ts +0 -47
- package/dist/repository/types/index.d.ts +0 -8
- package/dist/repository/types/orderBy.d.ts +0 -21
- package/dist/repository/types/queryOptions.d.ts +0 -33
- package/dist/repository/types/selectedFields.d.ts +0 -16
- package/dist/repository/types/whereClause.d.ts +0 -15
- package/dist/singletonManager/enums/index.d.ts +0 -1
- package/dist/singletonManager/enums/index.js +0 -2
- package/dist/singletonManager/enums/singletonManagerErrorKeys.d.ts +0 -7
- package/dist/singletonManager/index.d.ts +0 -1
- package/dist/singletonManager/index.js +0 -2
- package/dist/singletonManager/singletonManager.d.ts +0 -112
- package/dist/store/index.d.ts +0 -1
- package/dist/store/index.js +0 -2
- package/dist/store/redis.d.ts +0 -6
- package/dist/typedEventEmitter/index.d.ts +0 -1
- package/dist/typedEventEmitter/index.js +0 -2
- package/dist/typedEventEmitter/types/index.d.ts +0 -1
- package/dist/utils/enums/index.d.ts +0 -1
- package/dist/utils/enums/index.js +0 -2
- package/dist/utils/enums/utilErrorKeys.d.ts +0 -4
- package/dist/utils/isIsoDateString.d.ts +0 -1
- /package/dist/{data → errors}/types/index.js +0 -0
- /package/dist/{database/events → modules/data/types}/index.js +0 -0
- /package/dist/{database/types → modules/database/events}/index.js +0 -0
- /package/dist/{elysia → modules/database}/types/index.js +0 -0
- /package/dist/{error → modules/elysia/crud}/types/index.js +0 -0
- /package/dist/{logger/events → modules/elysia/crudSchema/types}/index.js +0 -0
- /package/dist/{logger → modules/elysia/dbResolver}/types/index.js +0 -0
- /package/dist/{mailer → modules/elysia/jwt}/types/index.js +0 -0
- /package/dist/{elysia → modules/elysia/microservice}/schemas/info.d.ts +0 -0
- /package/dist/{elysia → modules/elysia/microservice}/schemas/ping.d.ts +0 -0
- /package/dist/{repository → modules/elysia/ratelimit}/types/index.js +0 -0
- /package/dist/{typedEventEmitter/types → modules/logger/events}/index.js +0 -0
- /package/dist/{logger → modules/logger}/types/bodiesIntersection.d.ts +0 -0
- /package/dist/{logger → modules/logger}/types/logLevels.d.ts +0 -0
- /package/dist/{logger → modules/logger}/types/strategyBody.d.ts +0 -0
- /package/dist/{logger → modules/logger}/types/strategyMap.d.ts +0 -0
- /package/dist/{repository → modules/repository}/types/transaction.d.ts +0 -0
- /package/dist/{typedEventEmitter → modules/typedEventEmitter}/types/eventMap.d.ts +0 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import type { Table } from '../../modules/database/table';
|
|
3
|
+
import type { StreamWithAsyncIterable } from '../../utils/types/streamWithAsyncIterable';
|
|
4
|
+
import type { Filter } from './types/filter';
|
|
5
|
+
import type { OrderByItem } from './types/orderByItem';
|
|
6
|
+
import type { QueryOptions } from './types/queryOptions';
|
|
7
|
+
import type { QueryOptionsExtendPagination } from './types/queryOptionsExtendPagination';
|
|
8
|
+
import type { QueryOptionsExtendStream } from './types/queryOptionsExtendStream';
|
|
9
|
+
/**
|
|
10
|
+
* Repository allowing interaction with a database table using Knex.js fully typed.
|
|
11
|
+
*
|
|
12
|
+
* @template TModel - The data model type handled by the repository.
|
|
13
|
+
*
|
|
14
|
+
* Example:
|
|
15
|
+
* ```ts
|
|
16
|
+
* const repo = new Repository<User>(knex, userTable);
|
|
17
|
+
* const users = await repo.find({ limit: 10 });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class Repository<TModel = unknown> {
|
|
21
|
+
/**
|
|
22
|
+
* The Knex instance used for database operations.
|
|
23
|
+
*/
|
|
24
|
+
protected readonly _knex: Knex;
|
|
25
|
+
/**
|
|
26
|
+
* The table associated with this repository.
|
|
27
|
+
*/
|
|
28
|
+
protected readonly _table: Table;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new `Repository` instance with the specified Knex.js instance and table object.
|
|
31
|
+
*
|
|
32
|
+
* @param knex - The Knex.js instance used to interact with the database.
|
|
33
|
+
* @param table - The table object representing the database table to interact with.
|
|
34
|
+
*/
|
|
35
|
+
constructor(knex: Knex, table: Table);
|
|
36
|
+
/**
|
|
37
|
+
* Finds records in the database based on the specified query options and returns a stream
|
|
38
|
+
* for async iteration. This method is particularly useful when working with large datasets
|
|
39
|
+
* that would be inefficient to load entirely into memory.
|
|
40
|
+
*
|
|
41
|
+
* The stream emits data events for each record and an end event when the stream is finished.
|
|
42
|
+
* It can be consumed using either async iteration or event listeners.
|
|
43
|
+
*
|
|
44
|
+
* @template KModel - The type of the object to retrieve.
|
|
45
|
+
*
|
|
46
|
+
* @param options - The query options to apply to the search.
|
|
47
|
+
*
|
|
48
|
+
* @returns A stream with an async iterable interface for consuming the results.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* Basic usage with async iteration
|
|
52
|
+
* ```ts
|
|
53
|
+
* const stream = userRepository.findStream();
|
|
54
|
+
* for await (const user of stream) {
|
|
55
|
+
* console.log(user);
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
* @example
|
|
59
|
+
* With single field selection
|
|
60
|
+
* ```ts
|
|
61
|
+
* const stream = userRepository.findStream({
|
|
62
|
+
* selectedFields: 'name'
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
* @example
|
|
66
|
+
* With multiple fields selection
|
|
67
|
+
* ```ts
|
|
68
|
+
* const stream = userRepository.findStream({
|
|
69
|
+
* selectedFields: ['id', 'name', 'email']
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
* @example
|
|
73
|
+
* With single order by field
|
|
74
|
+
* ```ts
|
|
75
|
+
* const stream = userRepository.findStream({
|
|
76
|
+
* orderBy: {
|
|
77
|
+
* selectedField: 'createdAt',
|
|
78
|
+
* direction: 'desc'
|
|
79
|
+
* }
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
* @example
|
|
83
|
+
* With multiple order by fields
|
|
84
|
+
* ```ts
|
|
85
|
+
* const stream = userRepository.findStream({
|
|
86
|
+
* orderBy: [
|
|
87
|
+
* { selectedField: 'createdAt', direction: 'desc' },
|
|
88
|
+
* { selectedField: 'name', direction: 'asc' }
|
|
89
|
+
* ]
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
* @example
|
|
93
|
+
* With filtering
|
|
94
|
+
* ```ts
|
|
95
|
+
* const stream = userRepository.findStream({
|
|
96
|
+
* filters: {
|
|
97
|
+
* isActive: false
|
|
98
|
+
* }
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
* @example
|
|
102
|
+
* Using event listeners
|
|
103
|
+
* ```ts
|
|
104
|
+
* const stream = userRepository.findStream();
|
|
105
|
+
* stream.on('data', (user) => {
|
|
106
|
+
* console.log('User:', user);
|
|
107
|
+
* });
|
|
108
|
+
* stream.on('error', (error) => {
|
|
109
|
+
* console.error('Stream error:', error);
|
|
110
|
+
* });
|
|
111
|
+
* stream.on('end', () => {
|
|
112
|
+
* console.log('Stream completed');
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
* @example
|
|
116
|
+
* With transform function to process records
|
|
117
|
+
* ```ts
|
|
118
|
+
* const stream = userRepository.findStream({
|
|
119
|
+
* transform: (chunk, encoding, callback) => {
|
|
120
|
+
* // Transform the data
|
|
121
|
+
* const transformedData = { ...chunk, processed: true };
|
|
122
|
+
* callback(null, transformedData);
|
|
123
|
+
* }
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
findStream<KModel extends TModel = NoInfer<TModel>>(options?: QueryOptionsExtendStream<KModel>): StreamWithAsyncIterable<KModel>;
|
|
128
|
+
/**
|
|
129
|
+
* Finds records in the database based on the specified query options and returns the results
|
|
130
|
+
* as an array. This method supports comprehensive filtering, pagination, field selection, and sorting
|
|
131
|
+
* to provide flexible data retrieval capabilities.
|
|
132
|
+
*
|
|
133
|
+
* @template KModel - The type of the object to retrieve.
|
|
134
|
+
*
|
|
135
|
+
* @param options - The query options to apply to the search.
|
|
136
|
+
*
|
|
137
|
+
* @throws ({@link HttpError}) - Throws an error if no records are found if the {@link QueryOptions.throwIfNoResult} option is enabled.
|
|
138
|
+
* @throws ({@link HttpError}) - Throws an error if an MSSQL-specific error occurs during the query execution.
|
|
139
|
+
*
|
|
140
|
+
* @returns An array of records matching the query options.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* Basic usage with pagination
|
|
144
|
+
* ```ts
|
|
145
|
+
* const users = await userRepository.find({
|
|
146
|
+
* limit: 25,
|
|
147
|
+
* offset: 50 // Get users 51-75
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
150
|
+
* @example
|
|
151
|
+
* With field selection
|
|
152
|
+
* ```ts
|
|
153
|
+
* const userNames = await userRepository.find({
|
|
154
|
+
* selectedFields: ['id', 'firstName', 'lastName']
|
|
155
|
+
* });
|
|
156
|
+
* ```
|
|
157
|
+
* @example
|
|
158
|
+
* With filtering
|
|
159
|
+
* ```ts
|
|
160
|
+
* const activeAdmins = await userRepository.find({
|
|
161
|
+
* filters: {
|
|
162
|
+
* isActive: { $eq: true }
|
|
163
|
+
* }
|
|
164
|
+
* });
|
|
165
|
+
* ```
|
|
166
|
+
* @example
|
|
167
|
+
* With OR conditions
|
|
168
|
+
* ```ts
|
|
169
|
+
* const results = await userRepository.find({
|
|
170
|
+
* filters: [
|
|
171
|
+
* { department: 'engineering' },
|
|
172
|
+
* { department: 'design', role: 'lead' }
|
|
173
|
+
* ]
|
|
174
|
+
* });
|
|
175
|
+
* ```
|
|
176
|
+
* @example
|
|
177
|
+
* With sorting
|
|
178
|
+
* ```ts
|
|
179
|
+
* const sortedUsers = await userRepository.find({
|
|
180
|
+
* orderBy: ['lastName', 'asc']
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
* @example
|
|
184
|
+
* Using a transaction
|
|
185
|
+
* ```ts
|
|
186
|
+
* await knex.transaction(async (trx) => {
|
|
187
|
+
* const users = await userRepository.find({
|
|
188
|
+
* filters: { department: 'finance' },
|
|
189
|
+
* transaction: trx
|
|
190
|
+
* });
|
|
191
|
+
* });
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
find<KModel extends TModel = NoInfer<TModel>>(options?: QueryOptionsExtendPagination<KModel>): Promise<KModel[]>;
|
|
195
|
+
/**
|
|
196
|
+
* Counts the number of records in the database based on the specified query options.
|
|
197
|
+
* This method supports advanced filtering capabilities to count records that match specific criteria.
|
|
198
|
+
*
|
|
199
|
+
* @template KModel - The type of the object to count.
|
|
200
|
+
*
|
|
201
|
+
* @param options - The query options to apply to the search.
|
|
202
|
+
*
|
|
203
|
+
* @throws ({@link HttpError}) - Throws an error if no records are found if the {@link QueryOptions.throwIfNoResult} option is enabled.
|
|
204
|
+
* @throws ({@link HttpError}) - Throws an error if an MSSQL-specific error occurs during the query execution.
|
|
205
|
+
*
|
|
206
|
+
* @returns The count of records matching the query options.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* Basic usage
|
|
210
|
+
* ```ts
|
|
211
|
+
* const userCount = await userRepository.count();
|
|
212
|
+
* ```
|
|
213
|
+
* @example
|
|
214
|
+
* With filtering
|
|
215
|
+
* ```ts
|
|
216
|
+
* const activeUserCount = await userRepository.count({
|
|
217
|
+
* filters: { isActive: true }
|
|
218
|
+
* });
|
|
219
|
+
* ```
|
|
220
|
+
* @example
|
|
221
|
+
* Using a transaction
|
|
222
|
+
* ```ts
|
|
223
|
+
* await knex.transaction(async (trx) => {
|
|
224
|
+
* const userCount = await userRepository.count({
|
|
225
|
+
* filters: { department: 'finance' },
|
|
226
|
+
* transaction: trx
|
|
227
|
+
* });
|
|
228
|
+
* });
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
count<KModel extends TModel = NoInfer<TModel>>(options?: Omit<QueryOptions<KModel>, 'selectedFields' | 'orderBy'>): Promise<number>;
|
|
232
|
+
/**
|
|
233
|
+
* Inserts new records into the database and returns the inserted records.
|
|
234
|
+
* This method supports bulk insertion of multiple records at once.
|
|
235
|
+
*
|
|
236
|
+
* @template KModel - The type of the object to insert.
|
|
237
|
+
*
|
|
238
|
+
* @param data - The data to insert. Can be a single object or an array of objects.
|
|
239
|
+
* @param options - The query options to apply to the insertion.
|
|
240
|
+
*
|
|
241
|
+
* @throws ({@link HttpError}) - Throws an error if an MSSQL-specific error occurs during the query execution.
|
|
242
|
+
*
|
|
243
|
+
* @returns An array of inserted records.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* Basic usage
|
|
247
|
+
* ```ts
|
|
248
|
+
* const newUser = await userRepository.insert({ name: 'John Doe', email: 'john.doe@example.com' });
|
|
249
|
+
* ```
|
|
250
|
+
* @example
|
|
251
|
+
* With bulk insertion
|
|
252
|
+
* ```ts
|
|
253
|
+
* const users = await userRepository.insert([
|
|
254
|
+
* { name: 'Jane Doe', email: 'jane.doe@example.com' },
|
|
255
|
+
* { name: 'John Smith', email: 'john.smith@example.com' }
|
|
256
|
+
* ]);
|
|
257
|
+
* ```
|
|
258
|
+
* @example
|
|
259
|
+
* Using a transaction
|
|
260
|
+
* ```ts
|
|
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>, 'filters' | '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 filtering capabilities to update records that match specific criteria.
|
|
272
|
+
*
|
|
273
|
+
* @template KModel - The type of the object to update.
|
|
274
|
+
*
|
|
275
|
+
* @param data - The data to update. Can be a single object or an array of objects.
|
|
276
|
+
* @param options - The query options to apply to the update.
|
|
277
|
+
*
|
|
278
|
+
* @throws ({@link HttpError}) - Throws an error if an MSSQL-specific error occurs during the query execution.
|
|
279
|
+
*
|
|
280
|
+
* @returns An array of updated records.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* Basic usage
|
|
284
|
+
* ```ts
|
|
285
|
+
* const updatedUser = await userRepository.update({ name: 'John Doe' }, {
|
|
286
|
+
* filters: { id: 1 }
|
|
287
|
+
* });
|
|
288
|
+
* ```
|
|
289
|
+
* @example
|
|
290
|
+
* With filtering
|
|
291
|
+
* ```ts
|
|
292
|
+
* const updatedUsers = await userRepository.update({ status: 'inactive' }, {
|
|
293
|
+
* filters: { role: 'admin' }
|
|
294
|
+
* });
|
|
295
|
+
* ```
|
|
296
|
+
* @example
|
|
297
|
+
* Using a transaction
|
|
298
|
+
* ```ts
|
|
299
|
+
* await knex.transaction(async (trx) => {
|
|
300
|
+
* const updatedUser = await userRepository.update({ name: 'John Doe' }, {
|
|
301
|
+
* filters: { id: 1 },
|
|
302
|
+
* transaction: trx
|
|
303
|
+
* });
|
|
304
|
+
* });
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
update<KModel extends TModel = NoInfer<TModel>>(data: Partial<KModel>, options: Omit<QueryOptions<KModel>, 'orderBy' | 'filters'> & Required<Pick<QueryOptions<KModel>, 'filters'>>): Promise<KModel[]>;
|
|
308
|
+
/**
|
|
309
|
+
* Deletes records from the database based on the specified query options and returns the deleted records.
|
|
310
|
+
* This method supports advanced filtering capabilities to filter the records before deletion.
|
|
311
|
+
*
|
|
312
|
+
* @template KModel - The type of the object to delete.
|
|
313
|
+
*
|
|
314
|
+
* @param options - The query options to apply to the deletion.
|
|
315
|
+
*
|
|
316
|
+
* @throws ({@link HttpError}) - Throws an error if an MSSQL-specific error occurs during the query execution.
|
|
317
|
+
*
|
|
318
|
+
* @returns An array of deleted records.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* Basic usage
|
|
322
|
+
* ```ts
|
|
323
|
+
* const deletedUser = await userRepository.delete({
|
|
324
|
+
* filters: { id: 1 }
|
|
325
|
+
* });
|
|
326
|
+
* ```
|
|
327
|
+
* @example
|
|
328
|
+
* With filtering
|
|
329
|
+
* ```ts
|
|
330
|
+
* const deletedUsers = await userRepository.delete({
|
|
331
|
+
* filters: { status: 'inactive' }
|
|
332
|
+
* });
|
|
333
|
+
* ```
|
|
334
|
+
* @example
|
|
335
|
+
* Using a transaction
|
|
336
|
+
* ```ts
|
|
337
|
+
* await knex.transaction(async (trx) => {
|
|
338
|
+
* const deletedUser = await userRepository.delete({
|
|
339
|
+
* filters: { id: 1 },
|
|
340
|
+
* transaction: trx
|
|
341
|
+
* });
|
|
342
|
+
* });
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
delete<KModel extends TModel = NoInfer<TModel>>(options: Omit<QueryOptions<KModel>, 'orderBy' | 'filters'> & Required<Pick<QueryOptions<KModel>, 'filters'>>): Promise<KModel[]>;
|
|
346
|
+
/**
|
|
347
|
+
* Applies selected fields to a Knex.js query builder. This method supports both single and multiple field selections.
|
|
348
|
+
* It is used to specify which fields should be returned in the query results.
|
|
349
|
+
*
|
|
350
|
+
* @template KModel - The type of the object for query options.
|
|
351
|
+
*
|
|
352
|
+
* @param query - The Knex.js query builder to apply the selected fields to.
|
|
353
|
+
* @param selectedFields - The fields to select. Can be a single field or an array of fields.
|
|
354
|
+
*/
|
|
355
|
+
protected _applySelectedFields<KModel>(query: Knex.QueryBuilder, selectedFields: QueryOptions<KModel>['selectedFields'] | undefined): void;
|
|
356
|
+
/**
|
|
357
|
+
* Applies filter criteria to a Knex.js query builder. This method supports complex queries
|
|
358
|
+
* using operators like `$eq`, `$neq`, `$lt`, `$lte`, `$gt`, `$gte`, `$in`, `$nin`, `$between`, `$nbetween`,
|
|
359
|
+
* `$like`, `$nlike`, and `$isNull`. It also supports basic string searches and field selection.
|
|
360
|
+
*
|
|
361
|
+
* @template KModel - The type of the object to search for.
|
|
362
|
+
*
|
|
363
|
+
* @param query - The Knex.js query builder to apply the search criteria to.
|
|
364
|
+
* @param search - The advanced search criteria to apply. Can be a single object or an array of objects.
|
|
365
|
+
*/
|
|
366
|
+
protected _applyFilter<KModel>(query: Knex.QueryBuilder, search: Filter<KModel> | Filter<KModel>[] | undefined): void;
|
|
367
|
+
/**
|
|
368
|
+
* Applies order by criteria to a Knex.js query builder. This method supports both single and multiple order by items.
|
|
369
|
+
* It is used to specify the sorting order of the query results.
|
|
370
|
+
*
|
|
371
|
+
* @template KModel - The type of the object for query options.
|
|
372
|
+
*
|
|
373
|
+
* @param query - The Knex.js query builder to apply the order by criteria to.
|
|
374
|
+
* @param orderBy - The order by criteria. Can be a single item or an array of items.
|
|
375
|
+
*/
|
|
376
|
+
protected _applyOrderBy<KModel>(query: Knex.QueryBuilder, orderBy: OrderByItem<KModel> | OrderByItem<KModel>[] | undefined): void;
|
|
377
|
+
/**
|
|
378
|
+
* Applies query options such as filters, orderBy, and transaction to a Knex.js query builder.
|
|
379
|
+
*
|
|
380
|
+
* @template KModel - The type of the object for query options.
|
|
381
|
+
*
|
|
382
|
+
* @param query - The Knex.js query builder to apply the options to.
|
|
383
|
+
* @param options - The query options to apply.
|
|
384
|
+
*/
|
|
385
|
+
protected _applyQueryOptions<KModel>(query: Knex.QueryBuilder, options?: Omit<QueryOptions<KModel>, 'throwIfNoResult'>): void;
|
|
386
|
+
/**
|
|
387
|
+
* Handles errors that occur during query execution. This method centralizes error handling
|
|
388
|
+
* for MSSQL-specific errors and throws a {@link HttpError} with relevant information.
|
|
389
|
+
*
|
|
390
|
+
* @param error - The error object thrown by Knex.js.
|
|
391
|
+
* @param query - The Knex.js query builder that caused the error.
|
|
392
|
+
*
|
|
393
|
+
* @throws ({@link HttpError}) - Throws an error if an MSSQL-specific error occurs during the query execution.
|
|
394
|
+
*
|
|
395
|
+
* @returns Never returns, always throws an error.
|
|
396
|
+
*/
|
|
397
|
+
protected _handleError(error: unknown, query: Knex.QueryBuilder): never;
|
|
398
|
+
/**
|
|
399
|
+
* Determines if the provided data is a complex query (i.e., a WhereClause).
|
|
400
|
+
*
|
|
401
|
+
* @param data - The data to check.
|
|
402
|
+
*
|
|
403
|
+
* @returns True if the data is a WhereClause, false otherwise.
|
|
404
|
+
*/
|
|
405
|
+
private _filterIsAdaptiveWhereClause;
|
|
406
|
+
/**
|
|
407
|
+
* Executes a Knex.js query and returns the result. This method provides centralized
|
|
408
|
+
* error handling and supports the option to throw an error if no records are found.
|
|
409
|
+
*
|
|
410
|
+
* @template KModel - The type of the records returned by the query.
|
|
411
|
+
*
|
|
412
|
+
* @param query - The Knex.js query builder to execute.
|
|
413
|
+
* @param throwIfNoResult - Whether to throw an error if no records are found.
|
|
414
|
+
*
|
|
415
|
+
* @throws ({@link HttpError}) - Throws an error if no records are found if the {@link QueryOptions.throwIfNoResult} option is enabled.
|
|
416
|
+
* @throws ({@link HttpError}) - Throws an error if an MSSQL-specific error occurs during the query execution.
|
|
417
|
+
*
|
|
418
|
+
* @returns An array of records returned by the query.
|
|
419
|
+
*/
|
|
420
|
+
protected _executeQuery<KModel>(query: Knex.QueryBuilder, throwIfNoResult?: QueryOptions<KModel>['throwIfNoResult']): Promise<KModel[]>;
|
|
421
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type AdaptiveWhereClause<TValue> = TValue extends string ? {
|
|
2
|
+
$eq?: TValue;
|
|
3
|
+
$neq?: TValue;
|
|
4
|
+
$isNull?: boolean;
|
|
5
|
+
} & {
|
|
6
|
+
$in?: TValue[];
|
|
7
|
+
$nin?: TValue[];
|
|
8
|
+
$like?: string;
|
|
9
|
+
$nlike?: string;
|
|
10
|
+
} : TValue extends number | Date | bigint ? {
|
|
11
|
+
$eq?: TValue;
|
|
12
|
+
$neq?: TValue;
|
|
13
|
+
$isNull?: boolean;
|
|
14
|
+
} & {
|
|
15
|
+
$in?: TValue[];
|
|
16
|
+
$nin?: TValue[];
|
|
17
|
+
$like?: string;
|
|
18
|
+
$nlike?: string;
|
|
19
|
+
} & {
|
|
20
|
+
$lt?: TValue;
|
|
21
|
+
$lte?: TValue;
|
|
22
|
+
$gt?: TValue;
|
|
23
|
+
$gte?: TValue;
|
|
24
|
+
$between?: [TValue, TValue];
|
|
25
|
+
$nbetween?: [TValue, TValue];
|
|
26
|
+
} : {
|
|
27
|
+
$eq?: boolean;
|
|
28
|
+
$neq?: boolean;
|
|
29
|
+
$isNull?: boolean;
|
|
30
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AdaptiveWhereClause } from './adaptiveWhereClause';
|
|
2
|
+
import type { SelectedFields } from './selectedFields';
|
|
3
|
+
/**
|
|
4
|
+
* Defines an filter model using either plain partials of the model TModel or a {@link AdaptiveWhereClause} filter for more dynamic querying.
|
|
5
|
+
*
|
|
6
|
+
* @template TModel - The model type to be used for the filter.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
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: Filter<User> = {
|
|
22
|
+
* id: 1
|
|
23
|
+
* };
|
|
24
|
+
*
|
|
25
|
+
* const example2: Filter<User> = {
|
|
26
|
+
* name: {
|
|
27
|
+
* $eq: 'John'
|
|
28
|
+
* }
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* const example3: Filter<User> = {
|
|
32
|
+
* $q: 'John'
|
|
33
|
+
* };
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export type Filter<TModel> = {
|
|
37
|
+
$q?: string | number | {
|
|
38
|
+
selectedFields: SelectedFields<TModel>;
|
|
39
|
+
value: string | number;
|
|
40
|
+
};
|
|
41
|
+
} & {
|
|
42
|
+
[Key in keyof TModel]?: TModel[Key] | Partial<AdaptiveWhereClause<TModel[Key]>>;
|
|
43
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { AdaptiveWhereClause } from './adaptiveWhereClause';
|
|
2
|
+
export type { Filter } from './filter';
|
|
3
|
+
export type { OrderByItem } from './orderByItem';
|
|
4
|
+
export type { QueryOptions } from './queryOptions';
|
|
5
|
+
export type { QueryOptionsExtendPagination } from './queryOptionsExtendPagination';
|
|
6
|
+
export type { QueryOptionsExtendStream } from './queryOptionsExtendStream';
|
|
7
|
+
export type { SelectedFields } from './selectedFields';
|
|
8
|
+
export type { Transaction } from './transaction';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// @bun
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an ordering instruction for queries.
|
|
3
|
+
*
|
|
4
|
+
* This interface 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
|
+
* Define a model
|
|
10
|
+
* ```ts
|
|
11
|
+
* interface User {
|
|
12
|
+
* id: number;
|
|
13
|
+
* name: string;
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
* @example
|
|
17
|
+
* Order by a single field ascending
|
|
18
|
+
* ```ts
|
|
19
|
+
* const orderBy1: OrderByItem<User> = {
|
|
20
|
+
* selectedField: 'id',
|
|
21
|
+
* direction: 'asc'
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
* @example
|
|
25
|
+
* Order by a single field descending
|
|
26
|
+
* ```ts
|
|
27
|
+
* const orderBy2: OrderByItem<User> = {
|
|
28
|
+
* selectedField: 'name',
|
|
29
|
+
* direction: 'desc'
|
|
30
|
+
* };
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export interface OrderByItem<TModel> {
|
|
34
|
+
/**
|
|
35
|
+
* The field to order by. Must be a key of the model or a string.
|
|
36
|
+
*/
|
|
37
|
+
selectedField: (keyof TModel extends string ? keyof TModel : string);
|
|
38
|
+
/**
|
|
39
|
+
* The direction of the ordering: 'asc' for ascending, 'desc' for descending.
|
|
40
|
+
*/
|
|
41
|
+
direction: 'asc' | 'desc';
|
|
42
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Filter } from './filter';
|
|
2
|
+
import type { OrderByItem } from './orderByItem';
|
|
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 fields to select in the query. If not provided, all fields are selected. ({@link SelectedFields})
|
|
13
|
+
*
|
|
14
|
+
* @defaultValue If not provided, all fields are selected.
|
|
15
|
+
*/
|
|
16
|
+
readonly selectedFields?: SelectedFields<NoInfer<TModel>>;
|
|
17
|
+
/**
|
|
18
|
+
* The filters options to apply to the query. Can be a single object or an array of objects.
|
|
19
|
+
* @see {@link Filter}
|
|
20
|
+
*/
|
|
21
|
+
readonly filters?: Filter<NoInfer<TModel>> | Filter<NoInfer<TModel>>[];
|
|
22
|
+
/**
|
|
23
|
+
* Order the results by a specific column and direction. ({@link OrderByItem})
|
|
24
|
+
* @defaultValue If not provided, the primary key of the model is used in ascending order.
|
|
25
|
+
*/
|
|
26
|
+
readonly orderBy?: OrderByItem<NoInfer<TModel>> | OrderByItem<NoInfer<TModel>>[];
|
|
27
|
+
/**
|
|
28
|
+
* Whether to throw an error if the query does not return any result.
|
|
29
|
+
* @defaultValue false
|
|
30
|
+
*/
|
|
31
|
+
readonly throwIfNoResult?: boolean | string;
|
|
32
|
+
/**
|
|
33
|
+
* The transaction context for the query. ({@link Transaction})
|
|
34
|
+
*/
|
|
35
|
+
readonly transaction?: Transaction;
|
|
36
|
+
}
|
|
@@ -12,10 +12,10 @@ export interface QueryOptionsExtendPagination<TModel> extends QueryOptions<TMode
|
|
|
12
12
|
* The limit of the query
|
|
13
13
|
* @defaultValue 100
|
|
14
14
|
*/
|
|
15
|
-
limit?: number;
|
|
15
|
+
readonly limit?: number;
|
|
16
16
|
/**
|
|
17
17
|
* The offset of the query
|
|
18
18
|
* @defaultValue 0
|
|
19
19
|
*/
|
|
20
|
-
offset?: number;
|
|
20
|
+
readonly offset?: number;
|
|
21
21
|
}
|
|
@@ -12,5 +12,5 @@ export interface QueryOptionsExtendStream<TModel> extends QueryOptions<TModel> {
|
|
|
12
12
|
* @param encoding - The encoding of the chunk.
|
|
13
13
|
* @param callback - The callback to call when the transformation is complete.
|
|
14
14
|
*/
|
|
15
|
-
transform?: (chunk: NoInfer<TModel>, encoding: string, callback: (error?: Error | null, data?: NoInfer<TModel>) => void) => void;
|
|
15
|
+
readonly transform?: (chunk: NoInfer<TModel>, encoding: string, callback: (error?: Error | null, data?: NoInfer<TModel>) => void) => void;
|
|
16
16
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Specifies the fields to select in a query for a given model type.
|
|
3
|
+
*
|
|
4
|
+
* This type allows you to define which columns should be included in the query result.
|
|
5
|
+
* You can provide a single field name or an array of field names, using either keys from the model type or arbitrary strings.
|
|
6
|
+
*
|
|
7
|
+
* @template TModel - The type of the object to select fields from.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* - If you use keys from the model type, TypeScript will provide type safety.
|
|
11
|
+
* - You may also use string values for dynamic or computed fields.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* Define a model
|
|
15
|
+
* ```ts
|
|
16
|
+
* interface User {
|
|
17
|
+
* id: number;
|
|
18
|
+
* name: string;
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
* @example
|
|
22
|
+
* Select specific fields using model keys
|
|
23
|
+
* ```ts
|
|
24
|
+
* const selection1: SelectedFields<User> = ['id', 'name'];
|
|
25
|
+
* ```
|
|
26
|
+
* @example
|
|
27
|
+
* Select a single field
|
|
28
|
+
* ```ts
|
|
29
|
+
* const selection2: SelectedFields<User> = 'id';
|
|
30
|
+
* ```
|
|
31
|
+
* @example
|
|
32
|
+
* Select fields using arbitrary strings (e.g., computed columns)
|
|
33
|
+
* ```ts
|
|
34
|
+
* const selection3: SelectedFields<User> = ['id', 'fullName'];
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export type SelectedFields<TModel> = (keyof TModel extends string ? keyof TModel : string) | '*' | (keyof TModel extends string ? keyof TModel : string)[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SingletonManager } from './singletonManager';
|