@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,14 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
MSSQL,
|
|
4
|
+
Table
|
|
5
|
+
} from "../../chunk-pc66jgqv.js";
|
|
6
|
+
import"../../chunk-1a3wj3m1.js";
|
|
7
|
+
import"../../chunk-5qtpggzv.js";
|
|
8
|
+
import"../../chunk-yvyahr2h.js";
|
|
9
|
+
import"../../chunk-84mqvfsk.js";
|
|
10
|
+
import"../../chunk-vknq69e0.js";
|
|
11
|
+
export {
|
|
12
|
+
Table,
|
|
13
|
+
MSSQL
|
|
14
|
+
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { type Knex } from 'knex';
|
|
2
|
-
import { Repository } from '
|
|
3
|
-
import { TypedEventEmitter } from '
|
|
2
|
+
import { Repository } from '../../modules/repository/repository';
|
|
3
|
+
import { TypedEventEmitter } from '../../modules/typedEventEmitter/typedEventEmitter';
|
|
4
4
|
import type { MssqlEventMap } from './events/mssqlEventMap';
|
|
5
5
|
import { Table } from './table';
|
|
6
6
|
import type { MSSQLDatabaseOptions } from './types/mssqlDatabaseOption';
|
|
7
7
|
/**
|
|
8
8
|
* Manages the connection with an MSSQL database.
|
|
9
|
-
* The class extends {@link
|
|
9
|
+
* The class extends {@link TypedEventEmitter}<{@link MssqlEventMap}>.
|
|
10
10
|
*
|
|
11
|
-
* - Emits events
|
|
11
|
+
* - Emits events.
|
|
12
12
|
* - Automatically generates repositories and tables for CRUD operations.
|
|
13
13
|
* - Allows custom repository implementations per table.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
* ```
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
17
|
* const mssql = new MSSQL(options);
|
|
18
18
|
* await mssql.connect();
|
|
19
19
|
* const users = await mssql.getRepository('users').find();
|
|
@@ -30,29 +30,25 @@ export declare class MSSQL extends TypedEventEmitter<MssqlEventMap> {
|
|
|
30
30
|
private readonly _databaseName;
|
|
31
31
|
/**
|
|
32
32
|
* A map of tables in the database.
|
|
33
|
-
* @see {@link Table}
|
|
34
33
|
*/
|
|
35
34
|
private readonly _tables;
|
|
36
35
|
/**
|
|
37
36
|
* A map of repositories for each table.
|
|
38
|
-
* @see {@link Repository}
|
|
39
37
|
*/
|
|
40
38
|
private readonly _repositories;
|
|
41
39
|
/**
|
|
42
40
|
* The Knex instance for the database connection.
|
|
43
|
-
* @see {@link Knex}
|
|
44
|
-
* @see https://knexjs.org/
|
|
45
41
|
*/
|
|
46
42
|
private readonly _db;
|
|
47
43
|
/**
|
|
48
44
|
* Indicates whether to add basic event listeners for all tables.
|
|
49
|
-
* @
|
|
45
|
+
* @defaultValue false
|
|
50
46
|
*/
|
|
51
47
|
private readonly _isEventEnabled;
|
|
52
48
|
/**
|
|
53
49
|
* Create a new instance of `MSSQL` with the specified options.
|
|
50
|
+
*
|
|
54
51
|
* @param options - The configuration options for the MSSQL database connection.
|
|
55
|
-
* @see {@link MSSQLDatabaseOptions}
|
|
56
52
|
*/
|
|
57
53
|
constructor(options: MSSQLDatabaseOptions);
|
|
58
54
|
/**
|
|
@@ -61,27 +57,27 @@ export declare class MSSQL extends TypedEventEmitter<MssqlEventMap> {
|
|
|
61
57
|
* If the connection is successful, introspection is performed to retrieve information about tables, columns(fields), and primary keys.
|
|
62
58
|
* This information is used to create instances of {@link Table} and {@link Repository} for each table in the database.
|
|
63
59
|
*
|
|
64
|
-
* @throws ({@link
|
|
60
|
+
* @throws ({@link BaseError}) Thrown if an error occurs during the connection process.
|
|
65
61
|
*/
|
|
66
62
|
connect(): Promise<void>;
|
|
67
63
|
/**
|
|
68
64
|
* Closes the connection to the MSSQL database.
|
|
69
65
|
*
|
|
70
|
-
* @throws ({@link
|
|
71
|
-
* @throws ({@link
|
|
66
|
+
* @throws ({@link BaseError}) Thrown if the database is not connected.
|
|
67
|
+
* @throws ({@link BaseError}) Thrown if an error occurs during the disconnection process.
|
|
72
68
|
*/
|
|
73
69
|
disconnect(): Promise<void>;
|
|
74
70
|
/**
|
|
75
71
|
* Retrieves a repository for a specific table.
|
|
76
72
|
*
|
|
77
|
-
* @
|
|
78
|
-
* @
|
|
73
|
+
* @template TModel - The type of the model for the repository.
|
|
74
|
+
* @template TRepo - The repository to retrieve.
|
|
79
75
|
*
|
|
80
|
-
* @
|
|
81
|
-
* @
|
|
76
|
+
* @param tableName - The name of the table to retrieve the repository for.
|
|
77
|
+
* @param customRepository - Optional custom repository class to use for the table.
|
|
82
78
|
*
|
|
83
|
-
* @
|
|
84
|
-
* @
|
|
79
|
+
* @throws ({@link BaseError}) Thrown if the database is not connected.
|
|
80
|
+
* @throws ({@link BaseError}) Thrown if the specified table is not found.
|
|
85
81
|
*
|
|
86
82
|
* @returns The {@link Repository} for the specified table.
|
|
87
83
|
*/
|
|
@@ -92,11 +88,11 @@ export declare class MSSQL extends TypedEventEmitter<MssqlEventMap> {
|
|
|
92
88
|
*
|
|
93
89
|
* @param tableName - The name of the table to retrieve.
|
|
94
90
|
*
|
|
95
|
-
* @throws ({@link
|
|
96
|
-
* @throws ({@link
|
|
91
|
+
* @throws ({@link BaseError}) Thrown if the database is not connected.
|
|
92
|
+
* @throws ({@link BaseError}) Thrown if the specified table is not found.
|
|
97
93
|
*
|
|
98
94
|
* @returns The {@link Table} object for the specified table.
|
|
99
|
-
|
|
95
|
+
*/
|
|
100
96
|
getTable(tableName: string): Table;
|
|
101
97
|
/**
|
|
102
98
|
* Retrieves the name of the database.
|
|
@@ -125,7 +121,7 @@ export declare class MSSQL extends TypedEventEmitter<MssqlEventMap> {
|
|
|
125
121
|
/**
|
|
126
122
|
* Retrieves the Knex instance for the database connection.
|
|
127
123
|
*
|
|
128
|
-
* @throws ({@link
|
|
124
|
+
* @throws ({@link BaseError}) Thrown if the database is not connected.
|
|
129
125
|
*
|
|
130
126
|
* @returns The {@link Knex} instance for the database connection.
|
|
131
127
|
*/
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { TableEventMap } from '
|
|
2
|
-
import { TypedEventEmitter } from '
|
|
1
|
+
import type { TableEventMap } from '../../modules/database/events/tableEventMap';
|
|
2
|
+
import { TypedEventEmitter } from '../../modules/typedEventEmitter/typedEventEmitter';
|
|
3
3
|
/**
|
|
4
4
|
* Represents a database table and provides access to its metadata (name, fields, primary key).
|
|
5
|
+
* The class extends `TypedEventEmitter`<{@link TableEventMap}> to allow for event-driven programming.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
* - Used for query construction and event handling in the database layer.
|
|
7
|
+
* Can emit events for table operations (e.g., SELECTED, CREATED, UPDATED, DELETED). when is attach to {@link MSSQL} class.
|
|
8
8
|
*
|
|
9
9
|
* Example:
|
|
10
|
-
* ```
|
|
10
|
+
* ```ts
|
|
11
11
|
* const table = new Table('db', 'users', ['id', 'name'], ['id', 'NUMBER']);
|
|
12
|
-
* table.on('
|
|
12
|
+
* table.on('selected', data => console.log(data));
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export declare class Table extends TypedEventEmitter<TableEventMap> {
|
|
@@ -1,41 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Options to configure the MSSQL database connection.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```typescript
|
|
6
|
-
* const options: MSSQLDatabaseOptions = {
|
|
7
|
-
* databaseName: 'my_database',
|
|
8
|
-
* host: 'localhost',
|
|
9
|
-
* port: 1433,
|
|
10
|
-
* user: 'sa',
|
|
11
|
-
* password: 'Password123',
|
|
12
|
-
* encrypt: true,
|
|
13
|
-
* poolMin: 5,
|
|
14
|
-
* poolMax: 20,
|
|
15
|
-
* debug: true,
|
|
16
|
-
* pulse: true
|
|
17
|
-
* };
|
|
18
|
-
* ```
|
|
19
3
|
*/
|
|
20
4
|
export interface MSSQLDatabaseOptions {
|
|
21
5
|
/** The name of the database to connect to. */
|
|
22
|
-
databaseName: string;
|
|
6
|
+
readonly databaseName: string;
|
|
23
7
|
/** The host of the database server. */
|
|
24
|
-
host: string;
|
|
8
|
+
readonly host: string;
|
|
25
9
|
/** The port number for the database connection. */
|
|
26
|
-
port: number;
|
|
10
|
+
readonly port: number;
|
|
27
11
|
/** The username for authenticating with the database. */
|
|
28
|
-
user: string;
|
|
12
|
+
readonly user: string;
|
|
29
13
|
/** The password for authenticating with the database. */
|
|
30
|
-
password: string;
|
|
14
|
+
readonly password: string;
|
|
31
15
|
/**
|
|
32
16
|
* Whether to encrypt the database connection.
|
|
33
17
|
* When enabled, communication between the client and server will be encrypted,
|
|
34
|
-
* providing increased security but potentially slight performance impact.
|
|
35
18
|
*
|
|
36
19
|
* @defaultValue true
|
|
37
20
|
*/
|
|
38
|
-
encrypt?: boolean;
|
|
21
|
+
readonly encrypt?: boolean;
|
|
39
22
|
/**
|
|
40
23
|
* Minimum number of connections in the connection pool.
|
|
41
24
|
* This represents the minimum number of connections that will be maintained in the pool,
|
|
@@ -44,7 +27,7 @@ export interface MSSQLDatabaseOptions {
|
|
|
44
27
|
*
|
|
45
28
|
* @defaultValue 2
|
|
46
29
|
*/
|
|
47
|
-
poolMin?: number;
|
|
30
|
+
readonly poolMin?: number;
|
|
48
31
|
/**
|
|
49
32
|
* Maximum number of connections in the connection pool.
|
|
50
33
|
* This limits how many concurrent connections can be established to the database.
|
|
@@ -53,32 +36,28 @@ export interface MSSQLDatabaseOptions {
|
|
|
53
36
|
*
|
|
54
37
|
* @defaultValue 10
|
|
55
38
|
*/
|
|
56
|
-
poolMax?: number;
|
|
39
|
+
readonly poolMax?: number;
|
|
57
40
|
/**
|
|
58
41
|
* The timeout in milliseconds for acquiring a connection.
|
|
59
42
|
* If a connection cannot be acquired within this timeframe, an error will be thrown.
|
|
60
43
|
*
|
|
61
44
|
* @defaultValue 20000
|
|
62
45
|
*/
|
|
63
|
-
connectionTimeout?: number;
|
|
46
|
+
readonly connectionTimeout?: number;
|
|
64
47
|
/**
|
|
65
|
-
* If set to true,
|
|
66
|
-
*
|
|
67
|
-
* (select, create, update, delete) for all tables, allowing for easy monitoring
|
|
68
|
-
* and event-driven programming.
|
|
69
|
-
*
|
|
70
|
-
* [TODO] - Change this section when working on the AND-169 ticket.
|
|
48
|
+
* If set to true, emits events for database operations.
|
|
49
|
+
* (select, create, update, delete) for all tables.
|
|
71
50
|
*
|
|
72
51
|
* @defaultValue false
|
|
73
52
|
* @example
|
|
74
|
-
* ```
|
|
53
|
+
* ```ts
|
|
75
54
|
* const mssql = new MSSQL(options);
|
|
76
55
|
* await mssql.connect();
|
|
77
|
-
* //
|
|
78
|
-
* mssql.table('table_name').on(
|
|
79
|
-
*
|
|
56
|
+
* // selected, inserted, updated, deleted
|
|
57
|
+
* mssql.table('table_name').on('selected', (data: unknown) => {
|
|
58
|
+
* console.log(data); // data is the response from the query
|
|
80
59
|
* });
|
|
81
60
|
* ```
|
|
82
61
|
*/
|
|
83
|
-
isEventEnabled?: boolean;
|
|
62
|
+
readonly isEventEnabled?: boolean;
|
|
84
63
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface MssqlEventLog {
|
|
2
|
+
/** The name of the database where the query was executed. */
|
|
3
|
+
readonly database: string;
|
|
4
|
+
/** A list of tables affected by the query. */
|
|
5
|
+
readonly tables: string[];
|
|
6
|
+
/** A unique identifier for the executed query. */
|
|
7
|
+
readonly queryUuid: string;
|
|
8
|
+
/** The method used in the query (e.g., `SELECT`, `INSERT`, `UPDATE`, `DELETE`). */
|
|
9
|
+
readonly method: string;
|
|
10
|
+
/** The raw SQL query string. */
|
|
11
|
+
readonly sql: string;
|
|
12
|
+
/** The parameters or bindings used in the query. */
|
|
13
|
+
readonly bindings: unknown[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface QueryContext {
|
|
2
|
+
readonly method: string;
|
|
3
|
+
readonly options: Record<string, unknown>;
|
|
4
|
+
readonly timeout: number;
|
|
5
|
+
readonly cancelOnTimeout: boolean;
|
|
6
|
+
readonly bindings: unknown[];
|
|
7
|
+
readonly sql: string;
|
|
8
|
+
readonly queryContext: Record<string, unknown>;
|
|
9
|
+
readonly __knexUid: string;
|
|
10
|
+
readonly __knexQueryUid: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { TObject, TString } from '@sinclair/typebox';
|
|
2
|
+
import { Elysia, type SingletonBase } from 'elysia';
|
|
3
|
+
import type { MSSQL } from '../../../modules/database/mssql';
|
|
4
|
+
import type { CrudModelsType } from '../../../modules/elysia/crudSchema/types/crudModelsType';
|
|
5
|
+
import type { DynamicDbOptions } from '../../../modules/elysia/dbResolver/types/dynamicDbOptions';
|
|
6
|
+
import type { CrudOperationCountOptions } from './types/crudOperationCountOptions';
|
|
7
|
+
import type { CrudOperationDeleteOneOptions } from './types/crudOperationDeleteOneOptions';
|
|
8
|
+
import type { CrudOperationDeleteOptions } from './types/crudOperationDeleteOptions';
|
|
9
|
+
import type { CrudOperationFindOneOptions } from './types/crudOperationFindOneOptions';
|
|
10
|
+
import type { CrudOperationFindOptions } from './types/crudOperationFindOptions';
|
|
11
|
+
import type { CrudOperationInsertOptions } from './types/crudOperationInsertOptions';
|
|
12
|
+
import type { CrudOperationsOptions } from './types/crudOperationsOptions';
|
|
13
|
+
import type { CrudOperationUpdateOneOptions } from './types/crudOperationUpdateOneOptions';
|
|
14
|
+
import type { CrudOperationUpdateOptions } from './types/crudOperationUpdateOptions';
|
|
15
|
+
import type { CrudOptions } from './types/crudOptions';
|
|
16
|
+
export declare const crud: <const TDatabase extends DynamicDbOptions | string, const TTableName extends string, const TSourceSchema extends TObject, const TOperations extends CrudOperationsOptions = {
|
|
17
|
+
find: true;
|
|
18
|
+
findOne: true;
|
|
19
|
+
insert: true;
|
|
20
|
+
update: true;
|
|
21
|
+
updateOne: true;
|
|
22
|
+
delete: true;
|
|
23
|
+
deleteOne: true;
|
|
24
|
+
count: true;
|
|
25
|
+
}, const TSourceFindSchema extends TObject = TSourceSchema, const TSourceCountSchema extends TObject = TSourceSchema, const TSourceInsertSchema extends TObject = TSourceSchema, const TSourceUpdateSchema extends TObject = TSourceSchema, const TSourceDeleteSchema extends TObject = TSourceSchema, const TSourceResponseSchema extends TObject = TSourceSchema>({ database, tableName, schema, operations }: CrudOptions<TDatabase, TTableName, TSourceSchema, TOperations, TSourceFindSchema, TSourceCountSchema, TSourceInsertSchema, TSourceUpdateSchema, TSourceDeleteSchema, TSourceResponseSchema>) => Elysia<TTableName, {
|
|
26
|
+
decorator: SingletonBase["decorator"];
|
|
27
|
+
store: SingletonBase["store"];
|
|
28
|
+
derive: SingletonBase["derive"];
|
|
29
|
+
resolve: Record<TDatabase extends string ? "staticDB" : "dynamicDB", MSSQL>;
|
|
30
|
+
}, {
|
|
31
|
+
typebox: CrudModelsType<TTableName, {
|
|
32
|
+
find: TOperations["find"] extends true | CrudOperationFindOptions ? true : false;
|
|
33
|
+
findOne: TOperations["findOne"] extends true | CrudOperationFindOneOptions ? true : false;
|
|
34
|
+
insert: TOperations["insert"] extends true | CrudOperationInsertOptions ? true : false;
|
|
35
|
+
update: TOperations["update"] extends true | CrudOperationUpdateOptions ? true : false;
|
|
36
|
+
updateOne: TOperations["updateOne"] extends true | CrudOperationUpdateOneOptions ? true : false;
|
|
37
|
+
delete: TOperations["delete"] extends true | CrudOperationDeleteOptions ? true : false;
|
|
38
|
+
deleteOne: TOperations["deleteOne"] extends true | CrudOperationDeleteOneOptions ? true : false;
|
|
39
|
+
count: TOperations["count"] extends true | CrudOperationCountOptions ? true : false;
|
|
40
|
+
}, TSourceInsertSchema, TSourceFindSchema, TSourceCountSchema, TSourceUpdateSchema, TSourceDeleteSchema, TSourceResponseSchema> & {
|
|
41
|
+
ResolveDbHeader: TObject<{
|
|
42
|
+
"database-using": TString;
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
error: {};
|
|
46
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { crud } from './crud';
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
crudSchema
|
|
4
|
+
} from "../../../chunk-s07amdhx.js";
|
|
5
|
+
import"../../../chunk-f5z7x01b.js";
|
|
6
|
+
import {
|
|
7
|
+
dbResolver
|
|
8
|
+
} from "../../../chunk-v8v7982b.js";
|
|
9
|
+
import"../../../chunk-370444pc.js";
|
|
10
|
+
import"../../../chunk-cq973ydc.js";
|
|
11
|
+
import"../../../chunk-pc66jgqv.js";
|
|
12
|
+
import"../../../chunk-1a3wj3m1.js";
|
|
13
|
+
import"../../../chunk-5qtpggzv.js";
|
|
14
|
+
import"../../../chunk-yvyahr2h.js";
|
|
15
|
+
import"../../../chunk-84mqvfsk.js";
|
|
16
|
+
import"../../../chunk-vknq69e0.js";
|
|
17
|
+
|
|
18
|
+
// source/modules/elysia/crud/crud.ts
|
|
19
|
+
import { Elysia, t } from "elysia";
|
|
20
|
+
var _createDefaultOperationsWithHandlers = (tableName, database) => {
|
|
21
|
+
const _requiredHeaderDatabase = typeof database === "object" ? { headers: "dbSelectorHeader" } : {};
|
|
22
|
+
return {
|
|
23
|
+
insert: {
|
|
24
|
+
method: "POST",
|
|
25
|
+
path: "/",
|
|
26
|
+
hook: {
|
|
27
|
+
..._requiredHeaderDatabase,
|
|
28
|
+
body: `${tableName}Insert`,
|
|
29
|
+
response: `${tableName}Response200`
|
|
30
|
+
},
|
|
31
|
+
handler: async (ctx) => {
|
|
32
|
+
const db = ctx.dynamicDB || ctx.staticDB;
|
|
33
|
+
const body = ctx.body;
|
|
34
|
+
const selectedFields = body.queryOptions?.selectedFields ?? "*";
|
|
35
|
+
const data = await db.getRepository(tableName).insert(body.data, {
|
|
36
|
+
selectedFields,
|
|
37
|
+
throwIfNoResult: true
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
message: `Inserted record into ${tableName}`,
|
|
41
|
+
content: data
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
find: {
|
|
46
|
+
method: "POST",
|
|
47
|
+
path: "/search",
|
|
48
|
+
hook: {
|
|
49
|
+
..._requiredHeaderDatabase,
|
|
50
|
+
body: `${tableName}Find`,
|
|
51
|
+
response: `${tableName}Response200`
|
|
52
|
+
},
|
|
53
|
+
handler: async (ctx) => {
|
|
54
|
+
const db = ctx.dynamicDB || ctx.staticDB;
|
|
55
|
+
const body = ctx.body;
|
|
56
|
+
const data = await db.getRepository(tableName).find({
|
|
57
|
+
...body.queryOptions,
|
|
58
|
+
throwIfNoResult: true
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
message: `Found ${data.length} records for ${tableName}`,
|
|
62
|
+
content: data
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
findOne: {
|
|
67
|
+
method: "GET",
|
|
68
|
+
path: "/:id",
|
|
69
|
+
hook: {
|
|
70
|
+
..._requiredHeaderDatabase,
|
|
71
|
+
params: t.Object({
|
|
72
|
+
id: t.Union([
|
|
73
|
+
t.String({
|
|
74
|
+
format: "uuid"
|
|
75
|
+
}),
|
|
76
|
+
t.Number({
|
|
77
|
+
minimum: 1,
|
|
78
|
+
maximum: Number.MAX_SAFE_INTEGER
|
|
79
|
+
})
|
|
80
|
+
])
|
|
81
|
+
}),
|
|
82
|
+
response: `${tableName}Response200`
|
|
83
|
+
},
|
|
84
|
+
handler: async (ctx) => {
|
|
85
|
+
const db = ctx.dynamicDB || ctx.staticDB;
|
|
86
|
+
const { id } = ctx.params;
|
|
87
|
+
const [primaryKey] = db.getTable(tableName).primaryKey;
|
|
88
|
+
const data = await db.getRepository(tableName).find({
|
|
89
|
+
filters: {
|
|
90
|
+
[primaryKey]: id
|
|
91
|
+
},
|
|
92
|
+
throwIfNoResult: true
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
message: `Found record with id ${id} in ${tableName}`,
|
|
96
|
+
content: data
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
count: {
|
|
101
|
+
method: "POST",
|
|
102
|
+
path: "/count",
|
|
103
|
+
hook: {
|
|
104
|
+
..._requiredHeaderDatabase,
|
|
105
|
+
body: `${tableName}Count`,
|
|
106
|
+
response: `${tableName}CountResponse200`
|
|
107
|
+
},
|
|
108
|
+
handler: async (ctx) => {
|
|
109
|
+
const db = ctx.dynamicDB || ctx.staticDB;
|
|
110
|
+
const body = ctx.body;
|
|
111
|
+
const data = await db.getRepository(tableName).count({
|
|
112
|
+
...body.queryOptions,
|
|
113
|
+
throwIfNoResult: true
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
message: `Counted records in ${tableName}`,
|
|
117
|
+
content: data
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
update: {
|
|
122
|
+
method: "PATCH",
|
|
123
|
+
path: "/",
|
|
124
|
+
hook: {
|
|
125
|
+
..._requiredHeaderDatabase,
|
|
126
|
+
body: `${tableName}Update`,
|
|
127
|
+
response: `${tableName}Response200`
|
|
128
|
+
},
|
|
129
|
+
handler: async (ctx) => {
|
|
130
|
+
const db = ctx.dynamicDB || ctx.staticDB;
|
|
131
|
+
const body = ctx.body;
|
|
132
|
+
const data = await db.getRepository(tableName).update(body.data, {
|
|
133
|
+
filters: body.queryOptions.filters,
|
|
134
|
+
selectedFields: body.queryOptions.selectedFields ?? "*",
|
|
135
|
+
throwIfNoResult: true
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
message: data.length === 0 ? `No records updated in ${tableName}` : `Updated records in ${tableName}`,
|
|
139
|
+
content: data
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
updateOne: {
|
|
144
|
+
method: "PATCH",
|
|
145
|
+
path: "/:id",
|
|
146
|
+
hook: {
|
|
147
|
+
..._requiredHeaderDatabase,
|
|
148
|
+
params: t.Object({
|
|
149
|
+
id: t.Union([
|
|
150
|
+
t.String({
|
|
151
|
+
format: "uuid"
|
|
152
|
+
}),
|
|
153
|
+
t.Number({
|
|
154
|
+
minimum: 1,
|
|
155
|
+
maximum: Number.MAX_SAFE_INTEGER
|
|
156
|
+
})
|
|
157
|
+
])
|
|
158
|
+
}),
|
|
159
|
+
body: `${tableName}UpdateOne`,
|
|
160
|
+
response: `${tableName}Response200`
|
|
161
|
+
},
|
|
162
|
+
handler: async (ctx) => {
|
|
163
|
+
const db = ctx.dynamicDB || ctx.staticDB;
|
|
164
|
+
const { id } = ctx.params;
|
|
165
|
+
const body = ctx.body;
|
|
166
|
+
const [primaryKey] = db.getTable(tableName).primaryKey;
|
|
167
|
+
const data = await db.getRepository(tableName).update(body.data, {
|
|
168
|
+
selectedFields: "*",
|
|
169
|
+
filters: {
|
|
170
|
+
[primaryKey]: id
|
|
171
|
+
},
|
|
172
|
+
throwIfNoResult: true
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
message: `Updated record with id ${id} in ${tableName}`,
|
|
176
|
+
content: data
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
delete: {
|
|
181
|
+
method: "DELETE",
|
|
182
|
+
path: "/",
|
|
183
|
+
hook: {
|
|
184
|
+
..._requiredHeaderDatabase,
|
|
185
|
+
body: `${tableName}Delete`,
|
|
186
|
+
response: `${tableName}Response200`
|
|
187
|
+
},
|
|
188
|
+
handler: async (ctx) => {
|
|
189
|
+
const db = ctx.dynamicDB || ctx.staticDB;
|
|
190
|
+
const body = ctx.body;
|
|
191
|
+
const selectedFields = body.queryOptions?.selectedFields ?? "*";
|
|
192
|
+
const data = await db.getRepository(tableName).delete({
|
|
193
|
+
filters: body.queryOptions.filters,
|
|
194
|
+
selectedFields,
|
|
195
|
+
throwIfNoResult: true
|
|
196
|
+
});
|
|
197
|
+
return {
|
|
198
|
+
message: `Deleted records from ${tableName}`,
|
|
199
|
+
content: data
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
deleteOne: {
|
|
204
|
+
method: "DELETE",
|
|
205
|
+
path: "/:id",
|
|
206
|
+
hook: {
|
|
207
|
+
..._requiredHeaderDatabase,
|
|
208
|
+
params: t.Object({
|
|
209
|
+
id: t.Union([
|
|
210
|
+
t.String({
|
|
211
|
+
format: "uuid"
|
|
212
|
+
}),
|
|
213
|
+
t.Number({
|
|
214
|
+
minimum: 1,
|
|
215
|
+
maximum: Number.MAX_SAFE_INTEGER
|
|
216
|
+
})
|
|
217
|
+
])
|
|
218
|
+
}),
|
|
219
|
+
body: `${tableName}DeleteOne`,
|
|
220
|
+
response: `${tableName}Response200`
|
|
221
|
+
},
|
|
222
|
+
handler: async (ctx) => {
|
|
223
|
+
const db = ctx.dynamicDB || ctx.staticDB;
|
|
224
|
+
const { id } = ctx.params;
|
|
225
|
+
const body = ctx.body;
|
|
226
|
+
const selectedFields = body.queryOptions?.selectedFields ?? "*";
|
|
227
|
+
const data = await db.getRepository(tableName).delete({
|
|
228
|
+
filters: body.queryOptions.filters,
|
|
229
|
+
selectedFields,
|
|
230
|
+
throwIfNoResult: true
|
|
231
|
+
});
|
|
232
|
+
return {
|
|
233
|
+
message: `Deleted record with id ${id} from ${tableName}`,
|
|
234
|
+
content: data
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
var _addRoutesByOperations = (tableName, database, operations) => {
|
|
241
|
+
const app = new Elysia;
|
|
242
|
+
const _defaultOperations = _createDefaultOperationsWithHandlers(tableName, database);
|
|
243
|
+
for (const operationKey in operations) {
|
|
244
|
+
const operation = operations[operationKey];
|
|
245
|
+
const defaultOperation = _defaultOperations[operationKey];
|
|
246
|
+
if (!operation || !defaultOperation)
|
|
247
|
+
continue;
|
|
248
|
+
if (typeof operation === "boolean") {
|
|
249
|
+
app.route(defaultOperation.method, defaultOperation.path, (ctx) => defaultOperation.handler(ctx), defaultOperation.hook);
|
|
250
|
+
} else if (typeof operation === "object") {
|
|
251
|
+
const mergedOperation = {
|
|
252
|
+
...defaultOperation,
|
|
253
|
+
...operation
|
|
254
|
+
};
|
|
255
|
+
app.route(mergedOperation.method, mergedOperation.path, (ctx) => defaultOperation.handler(ctx), mergedOperation.hook);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return app;
|
|
259
|
+
};
|
|
260
|
+
var crud = ({
|
|
261
|
+
database,
|
|
262
|
+
tableName,
|
|
263
|
+
schema,
|
|
264
|
+
operations = {
|
|
265
|
+
find: true,
|
|
266
|
+
findOne: true,
|
|
267
|
+
insert: true,
|
|
268
|
+
update: true,
|
|
269
|
+
updateOne: true,
|
|
270
|
+
delete: true,
|
|
271
|
+
deleteOne: true,
|
|
272
|
+
count: true
|
|
273
|
+
}
|
|
274
|
+
}) => new Elysia({
|
|
275
|
+
name: `crudPlugin[${tableName}]`,
|
|
276
|
+
tags: [tableName]
|
|
277
|
+
}).use(dbResolver(database)).use(crudSchema({
|
|
278
|
+
sourceSchemaName: tableName,
|
|
279
|
+
sourceSchema: schema.sourceSchema,
|
|
280
|
+
sourceInsertSchema: schema.sourceInsertSchema || schema.sourceSchema,
|
|
281
|
+
sourceFindSchema: schema.sourceFindSchema || schema.sourceSchema,
|
|
282
|
+
sourceCountSchema: schema.sourceCountSchema || schema.sourceSchema,
|
|
283
|
+
sourceUpdateSchema: schema.sourceUpdateSchema || schema.sourceSchema,
|
|
284
|
+
sourceDeleteSchema: schema.sourceDeleteSchema || schema.sourceSchema,
|
|
285
|
+
sourceResponseSchema: schema.sourceResponseSchema || schema.sourceSchema,
|
|
286
|
+
operations: {
|
|
287
|
+
find: operations.find ? true : false,
|
|
288
|
+
findOne: operations.findOne ? true : false,
|
|
289
|
+
insert: operations.insert ? true : false,
|
|
290
|
+
update: operations.update ? true : false,
|
|
291
|
+
updateOne: operations.updateOne ? true : false,
|
|
292
|
+
delete: operations.delete ? true : false,
|
|
293
|
+
deleteOne: operations.deleteOne ? true : false,
|
|
294
|
+
count: operations.count ? true : false
|
|
295
|
+
}
|
|
296
|
+
})).use(_addRoutesByOperations(tableName, database, operations));
|
|
297
|
+
export {
|
|
298
|
+
crud
|
|
299
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BaseMacro, InputSchema, LocalHook, RouteSchema, SingletonBase } from 'elysia/types';
|
|
2
|
+
export interface CrudOperationBaseOptions {
|
|
3
|
+
readonly path?: string;
|
|
4
|
+
readonly method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
5
|
+
readonly hook?: LocalHook<InputSchema, RouteSchema, SingletonBase, Record<string, Error>, BaseMacro>;
|
|
6
|
+
}
|