@mrxsys/mrx-core 2.11.0-2-and-276-20251029 → 2.11.0-2-and-277-20251030
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/dist/chunk-0d0zd2yg.js +8 -0
- package/dist/chunk-12qzn7jw.js +7 -0
- package/dist/chunk-441xs5k1.js +53 -0
- package/dist/chunk-4v86f7gp.js +59 -0
- package/dist/chunk-6w9ja96e.js +9 -0
- package/dist/chunk-7t524zqh.js +26 -0
- package/dist/chunk-8tffnbpn.js +7 -0
- package/dist/chunk-9cgzhc50.js +15 -0
- package/dist/chunk-9d3zvgp6.js +9 -0
- package/dist/chunk-9dzsj7f2.js +23 -0
- package/dist/chunk-9r5anep5.js +11 -0
- package/dist/chunk-afd82epa.js +201 -0
- package/dist/chunk-afyz8rg5.js +209 -0
- package/dist/chunk-dre2fgj0.js +7 -0
- package/dist/chunk-e30paw8a.js +101 -0
- package/dist/chunk-eeb7yskp.js +61 -0
- package/dist/chunk-fs3wm3p4.js +32 -0
- package/dist/chunk-grfyngq0.js +39 -0
- package/dist/chunk-gtn1kn0z.js +79 -0
- package/dist/chunk-jksb9ers.js +7 -0
- package/dist/chunk-m3grz32t.js +27 -0
- package/dist/chunk-mvrxngm7.js +41 -0
- package/dist/chunk-n0n14mf8.js +7 -0
- package/dist/chunk-p14h6jfs.js +365 -0
- package/dist/chunk-pjv1ekwr.js +284 -0
- package/dist/chunk-rz5p4j3p.js +13 -0
- package/dist/chunk-spnh9dzk.js +10 -0
- package/dist/chunk-sqts8vyk.js +60 -0
- package/dist/chunk-w7h898m3.js +14 -0
- package/dist/chunk-xhhj1gvj.js +9 -0
- package/dist/chunk-z0ct35ft.js +8 -0
- package/dist/errors/enums/index.js +7 -0
- package/dist/errors/index.js +12 -0
- package/dist/errors/utils/index.js +16 -0
- package/dist/errors/utils/is-nowarajs-error.ts.d.ts +2 -2
- package/dist/modules/data/enums/index.js +7 -0
- package/dist/modules/data/index.js +17 -0
- package/dist/modules/data/transformers/camel-case.d.ts +2 -2
- package/dist/modules/data/transformers/index.js +32 -0
- package/dist/modules/data/transformers/kebab-case.d.ts +2 -2
- package/dist/modules/data/transformers/pascal-case.d.ts +2 -2
- package/dist/modules/data/transformers/snake-case.d.ts +2 -2
- package/dist/modules/data/types/index.js +1 -0
- package/dist/modules/data/types/transform-object-keys.d.ts +4 -4
- package/dist/modules/database/enums/index.js +9 -0
- package/dist/modules/database/events/index.js +1 -0
- package/dist/modules/database/events/mssql-event-map.d.ts +1 -1
- package/dist/modules/database/events/table-event-map.d.ts +1 -1
- package/dist/modules/database/index.js +16 -0
- package/dist/modules/database/mssql.d.ts +2 -2
- package/dist/modules/database/table.d.ts +2 -2
- package/dist/modules/database/types/index.js +1 -0
- package/dist/modules/elysia/cache/cache.d.ts +1 -1
- package/dist/modules/elysia/cache/index.js +90 -0
- package/dist/modules/elysia/cache/types/index.js +1 -0
- package/dist/modules/elysia/crud/crud.d.ts +2 -2
- package/dist/modules/elysia/crud/enums/index.js +7 -0
- package/dist/modules/elysia/crud/index.js +153 -0
- package/dist/modules/elysia/crud/operations/count.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/delete.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/deleteOne.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/find.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/findOne.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/index.js +34 -0
- package/dist/modules/elysia/crud/operations/insert.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/update.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/updateOne.d.ts +3 -3
- package/dist/modules/elysia/crud/operations/utils/get-db-injection.d.ts +1 -1
- package/dist/modules/elysia/crud/types/crud-options.d.ts +1 -1
- package/dist/modules/elysia/crud/types/crud-schema-models-type.d.ts +9 -9
- package/dist/modules/elysia/crud/types/delete-schema.d.ts +2 -2
- package/dist/modules/elysia/crud/types/find-schema.d.ts +3 -3
- package/dist/modules/elysia/crud/types/index.js +1 -0
- package/dist/modules/elysia/crud/types/insert-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/types/properties-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/types/response-200-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/types/update-schema.d.ts +2 -2
- package/dist/modules/elysia/crud/utils/create-adaptive-where-clause-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-count-response-200-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-count-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-delete-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-filters-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-find-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-id-param-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-insert-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-order-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-properties-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-q-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-response-200-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-selected-fields-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-update-one-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/create-update-schema.d.ts +1 -1
- package/dist/modules/elysia/crud/utils/index.js +41 -0
- package/dist/modules/elysia/db-resolver/db-resolver.d.ts +2 -2
- package/dist/modules/elysia/db-resolver/enums/index.js +7 -0
- package/dist/modules/elysia/db-resolver/index.js +18 -0
- package/dist/modules/elysia/error/enums/index.js +7 -0
- package/dist/modules/elysia/error/error.d.ts +51 -0
- package/dist/modules/elysia/error/index.js +76 -0
- package/dist/modules/elysia/microservice/enums/index.js +7 -0
- package/dist/modules/elysia/microservice/index.js +100 -0
- package/dist/modules/elysia/rate-limit/enums/index.js +7 -0
- package/dist/modules/elysia/rate-limit/index.js +81 -0
- package/dist/modules/elysia/rate-limit/rate-limit.d.ts +1 -1
- package/dist/modules/elysia/rate-limit/types/index.js +1 -0
- package/dist/modules/jwt/enums/index.js +11 -0
- package/dist/modules/jwt/index.js +51 -0
- package/dist/modules/jwt/utils/index.js +9 -0
- package/dist/modules/kv-store/bun-redis/bun-redis-store.d.ts +1 -1
- package/dist/modules/kv-store/bun-redis/index.js +84 -0
- package/dist/modules/kv-store/enums/index.js +7 -0
- package/dist/modules/kv-store/ioredis/index.js +86 -0
- package/dist/modules/kv-store/ioredis/ioredis-store.d.ts +1 -1
- package/dist/modules/kv-store/memory/index.js +9 -0
- package/dist/modules/kv-store/memory/memory-store.d.ts +1 -1
- package/dist/modules/kv-store/types/index.js +1 -0
- package/dist/modules/logger/enums/index.js +7 -0
- package/dist/modules/logger/events/index.js +1 -0
- package/dist/modules/logger/events/logger-events.d.ts +1 -1
- package/dist/modules/logger/index.js +282 -0
- package/dist/modules/logger/logger.d.ts +1 -1
- package/dist/modules/logger/sinks/console-logger.d.ts +2 -2
- package/dist/modules/logger/sinks/devnull-logger.d.ts +1 -1
- package/dist/modules/logger/sinks/file-logger/file-logger.d.ts +2 -2
- package/dist/modules/logger/sinks/index.js +66 -0
- package/dist/modules/logger/types/index.js +1 -0
- package/dist/modules/logger/worker-logger.d.ts +1 -0
- package/dist/modules/mailer/enums/index.js +7 -0
- package/dist/modules/mailer/index.js +55 -0
- package/dist/modules/mailer/types/index.js +1 -0
- package/dist/modules/repository/index.js +12 -0
- package/dist/modules/repository/repository.d.ts +2 -2
- package/dist/modules/repository/types/index.js +1 -0
- package/dist/modules/repository/types/query-options.d.ts +1 -1
- package/dist/modules/singleton-manager/enums/index.js +7 -0
- package/dist/modules/singleton-manager/index.js +9 -0
- package/dist/modules/totp/enums/index.js +7 -0
- package/dist/modules/totp/index.js +104 -0
- package/dist/modules/totp/types/index.js +1 -0
- package/dist/modules/totp/utils/index.js +76 -0
- package/dist/modules/typed-event-emitter/index.js +7 -0
- package/dist/modules/typed-event-emitter/types/index.js +1 -0
- package/dist/shared/enums/index.js +7 -0
- package/dist/shared/types/index.js +1 -0
- package/dist/shared/utils/flatten.d.ts +1 -1
- package/dist/shared/utils/index.js +30 -0
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/modules/elysia/microservice/enums/microservice-success-keys.ts
|
|
3
|
+
var MICROSERVICE_SUCCESS_KEYS = {
|
|
4
|
+
PING_RESPONSE: "mrx-core.microservice.success.ping_response",
|
|
5
|
+
INFO_RETRIEVED: "mrx-core.microservice.success.info_retrieved"
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { MICROSERVICE_SUCCESS_KEYS };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/modules/jwt/enums/parse-human-time-to-seconds-error-keys.ts
|
|
3
|
+
var PARSE_HUMAN_TIME_TO_SECONDS_ERROR_KEYS = {
|
|
4
|
+
INVALID_TIME_EXPRESSION: "mrx-core.parse_human_time_to_seconds.error.invalid_time_expression"
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { PARSE_HUMAN_TIME_TO_SECONDS_ERROR_KEYS };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
SingletonManager
|
|
4
|
+
} from "./chunk-fs3wm3p4.js";
|
|
5
|
+
import {
|
|
6
|
+
DB_RESOLVER_ERROR_KEYS
|
|
7
|
+
} from "./chunk-8tffnbpn.js";
|
|
8
|
+
import {
|
|
9
|
+
MSSQL
|
|
10
|
+
} from "./chunk-afd82epa.js";
|
|
11
|
+
import {
|
|
12
|
+
BaseError
|
|
13
|
+
} from "./chunk-9cgzhc50.js";
|
|
14
|
+
|
|
15
|
+
// source/modules/elysia/db-resolver/db-resolver.ts
|
|
16
|
+
import { Elysia, t } from "elysia";
|
|
17
|
+
var dbResolver = (prefixDatabaseName = "") => new Elysia().model({
|
|
18
|
+
dbResolverHeader: t.Object({
|
|
19
|
+
"database-using": t.String()
|
|
20
|
+
})
|
|
21
|
+
}).macro({
|
|
22
|
+
injectDynamicDB(config) {
|
|
23
|
+
return {
|
|
24
|
+
headers: "dbResolverHeader",
|
|
25
|
+
async resolve({ headers }) {
|
|
26
|
+
const databaseName = headers["database-using"];
|
|
27
|
+
if (!SingletonManager.has(`${prefixDatabaseName}${databaseName}`)) {
|
|
28
|
+
SingletonManager.register(`${prefixDatabaseName}${databaseName}`, new MSSQL({
|
|
29
|
+
...config,
|
|
30
|
+
databaseName
|
|
31
|
+
}));
|
|
32
|
+
await SingletonManager.get(`${prefixDatabaseName}${databaseName}`).connect();
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
dynamicDB: SingletonManager.get(`${prefixDatabaseName}${databaseName}`)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
injectStaticDB(databaseName) {
|
|
41
|
+
return {
|
|
42
|
+
resolve() {
|
|
43
|
+
if (!SingletonManager.has(`${prefixDatabaseName}${databaseName}`))
|
|
44
|
+
throw new BaseError(DB_RESOLVER_ERROR_KEYS.DB_RESOLVER_STATIC_DB_NOT_FOUND, `${prefixDatabaseName}${databaseName}`);
|
|
45
|
+
return {
|
|
46
|
+
staticDB: SingletonManager.get(`${prefixDatabaseName}${databaseName}`)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export { dbResolver };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/modules/database/enums/database-error-keys.ts
|
|
3
|
+
var DATABASE_ERROR_KEYS = {
|
|
4
|
+
MSSQL_CONNECTION_ERROR: "mrx-core.mssql.error.database.connection_error",
|
|
5
|
+
MSSQL_DATABASE_ACCESS_DENIED: "mrx-core.mssql.error.database.access_denied",
|
|
6
|
+
MSSQL_DATABASE_AMBIGUOUS_COLUMN: "mrx-core.mssql.error.database.ambiguous_column",
|
|
7
|
+
MSSQL_DATABASE_AUTHORIZATION_FAILED: "mrx-core.mssql.error.database.authorization_failed",
|
|
8
|
+
MSSQL_DATABASE_COLUMN_NOT_FOUND: "mrx-core.mssql.error.database.column_not_found",
|
|
9
|
+
MSSQL_DATABASE_CONVERSION_FAILED: "mrx-core.mssql.error.database.conversion_failed",
|
|
10
|
+
MSSQL_DATABASE_DATA_TOO_LARGE: "mrx-core.mssql.error.database.data_too_large",
|
|
11
|
+
MSSQL_DATABASE_DEADLOCK_DETECTED: "mrx-core.mssql.error.database.deadlock_detected",
|
|
12
|
+
MSSQL_DATABASE_DUPLICATE_KEY: "mrx-core.mssql.error.database.duplicate_key",
|
|
13
|
+
MSSQL_DATABASE_FOREIGN_KEY_VIOLATION: "mrx-core.mssql.error.database.foreign_key_violation",
|
|
14
|
+
MSSQL_DATABASE_IDENTITY_INSERT_NOT_ALLOWED: "mrx-core.mssql.error.database.identity_insert_not_allowed",
|
|
15
|
+
MSSQL_DATABASE_INSUFFICIENT_MEMORY: "mrx-core.mssql.error.database.insufficient_memory",
|
|
16
|
+
MSSQL_DATABASE_INSUFFICIENT_STORAGE: "mrx-core.mssql.error.database.insufficient_storage",
|
|
17
|
+
MSSQL_DATABASE_PERMISSION_DENIED: "mrx-core.mssql.error.database.permission_denied",
|
|
18
|
+
MSSQL_DATABASE_QUERY_TIMEOUT: "mrx-core.mssql.error.database.query_timeout",
|
|
19
|
+
MSSQL_DATABASE_RESOURCE_LOCKED: "mrx-core.mssql.error.database.resource_locked",
|
|
20
|
+
MSSQL_DATABASE_SYNTAX_ERROR: "mrx-core.mssql.error.database.syntax_error",
|
|
21
|
+
MSSQL_DATABASE_TRANSACTION_ABORTED: "mrx-core.mssql.error.database.transaction_aborted",
|
|
22
|
+
MSSQL_DATABASE_TRANSACTION_LOG_FULL: "mrx-core.mssql.error.database.transaction_log_full",
|
|
23
|
+
MSSQL_DATABASE_UNIQUE_CONSTRAINT_VIOLATION: "mrx-core.mssql.error.database.unique_constraint_violation",
|
|
24
|
+
MSSQL_DATABASE_CANNOT_UPDATE_IDENTITY_COLUMN: "mrx-core.mssql.error.database.cannot_update_identity_column",
|
|
25
|
+
MSSQL_DISCONNECT_ERROR: "mrx-core.mssql.error.database.disconnect_error",
|
|
26
|
+
MSSQL_NO_RESULT: "mrx-core.mssql.error.database.no_result",
|
|
27
|
+
MSSQL_NOT_CONNECTED: "mrx-core.mssql.error.database.not_connected",
|
|
28
|
+
MSSQL_QUERY_ERROR: "mrx-core.mssql.error.database.query_error",
|
|
29
|
+
MSSQL_TABLE_NOT_FOUND: "mrx-core.mssql.error.database.table_not_found"
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// source/modules/database/enums/mssql-error-code.ts
|
|
33
|
+
var MSSQL_ERROR_CODE = {
|
|
34
|
+
0: DATABASE_ERROR_KEYS.MSSQL_QUERY_ERROR,
|
|
35
|
+
102: DATABASE_ERROR_KEYS.MSSQL_DATABASE_SYNTAX_ERROR,
|
|
36
|
+
1105: DATABASE_ERROR_KEYS.MSSQL_DATABASE_INSUFFICIENT_STORAGE,
|
|
37
|
+
1205: DATABASE_ERROR_KEYS.MSSQL_DATABASE_DEADLOCK_DETECTED,
|
|
38
|
+
1222: DATABASE_ERROR_KEYS.MSSQL_DATABASE_RESOURCE_LOCKED,
|
|
39
|
+
18452: DATABASE_ERROR_KEYS.MSSQL_DATABASE_AUTHORIZATION_FAILED,
|
|
40
|
+
18456: DATABASE_ERROR_KEYS.MSSQL_DATABASE_AUTHORIZATION_FAILED,
|
|
41
|
+
207: DATABASE_ERROR_KEYS.MSSQL_DATABASE_COLUMN_NOT_FOUND,
|
|
42
|
+
208: DATABASE_ERROR_KEYS.MSSQL_TABLE_NOT_FOUND,
|
|
43
|
+
209: DATABASE_ERROR_KEYS.MSSQL_DATABASE_AMBIGUOUS_COLUMN,
|
|
44
|
+
229: DATABASE_ERROR_KEYS.MSSQL_DATABASE_PERMISSION_DENIED,
|
|
45
|
+
2601: DATABASE_ERROR_KEYS.MSSQL_DATABASE_UNIQUE_CONSTRAINT_VIOLATION,
|
|
46
|
+
2627: DATABASE_ERROR_KEYS.MSSQL_DATABASE_DUPLICATE_KEY,
|
|
47
|
+
3928: DATABASE_ERROR_KEYS.MSSQL_DATABASE_TRANSACTION_ABORTED,
|
|
48
|
+
4060: DATABASE_ERROR_KEYS.MSSQL_DATABASE_ACCESS_DENIED,
|
|
49
|
+
544: DATABASE_ERROR_KEYS.MSSQL_DATABASE_IDENTITY_INSERT_NOT_ALLOWED,
|
|
50
|
+
547: DATABASE_ERROR_KEYS.MSSQL_DATABASE_FOREIGN_KEY_VIOLATION,
|
|
51
|
+
701: DATABASE_ERROR_KEYS.MSSQL_DATABASE_INSUFFICIENT_MEMORY,
|
|
52
|
+
8102: DATABASE_ERROR_KEYS.MSSQL_DATABASE_CANNOT_UPDATE_IDENTITY_COLUMN,
|
|
53
|
+
8152: DATABASE_ERROR_KEYS.MSSQL_DATABASE_DATA_TOO_LARGE,
|
|
54
|
+
8169: DATABASE_ERROR_KEYS.MSSQL_DATABASE_CONVERSION_FAILED,
|
|
55
|
+
8645: DATABASE_ERROR_KEYS.MSSQL_DATABASE_QUERY_TIMEOUT,
|
|
56
|
+
9002: DATABASE_ERROR_KEYS.MSSQL_DATABASE_TRANSACTION_LOG_FULL
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { DATABASE_ERROR_KEYS, MSSQL_ERROR_CODE };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/modules/mailer/enums/mailer-error-keys.ts
|
|
3
|
+
var MAILER_ERROR_KEYS = {
|
|
4
|
+
SMTP_ALREADY_CONNECTED: "mrx-core.mailer.error.smtp.already_connected",
|
|
5
|
+
SMTP_CONNECTION_ERROR: "mrx-core.mailer.error.smtp.connection_error",
|
|
6
|
+
SMTP_NOT_CONNECTED: "mrx-core.mailer.error.smtp.not_connected"
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { MAILER_ERROR_KEYS };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
HTTP_STATUS_CODES
|
|
4
|
+
} from "./chunk-sqts8vyk.js";
|
|
5
|
+
import {
|
|
6
|
+
BaseError
|
|
7
|
+
} from "./chunk-9cgzhc50.js";
|
|
8
|
+
|
|
9
|
+
// source/errors/http-error.ts
|
|
10
|
+
class HttpError extends BaseError {
|
|
11
|
+
httpStatusCode;
|
|
12
|
+
constructor(message, a, b) {
|
|
13
|
+
const isStatus = typeof a === "number" || typeof a === "string" && a in HTTP_STATUS_CODES;
|
|
14
|
+
const status = isStatus ? typeof a === "number" ? a : HTTP_STATUS_CODES[a] : HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR;
|
|
15
|
+
super(message, isStatus ? b : a);
|
|
16
|
+
this.httpStatusCode = status;
|
|
17
|
+
}
|
|
18
|
+
get isClientError() {
|
|
19
|
+
return this.httpStatusCode >= 400 && this.httpStatusCode < 500;
|
|
20
|
+
}
|
|
21
|
+
get isServerError() {
|
|
22
|
+
return this.httpStatusCode >= 500 && this.httpStatusCode < 600;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { HttpError };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/errors/base-error.ts
|
|
3
|
+
class BaseError extends Error {
|
|
4
|
+
cause;
|
|
5
|
+
date = new Date;
|
|
6
|
+
constructor(message, cause) {
|
|
7
|
+
super(message, { cause });
|
|
8
|
+
this.cause = cause;
|
|
9
|
+
this.name = new.target.name;
|
|
10
|
+
if (Error.captureStackTrace)
|
|
11
|
+
Error.captureStackTrace(this, new.target);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { BaseError };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/modules/jwt/enums/jwt-error-keys.ts
|
|
3
|
+
var JWT_ERROR_KEYS = {
|
|
4
|
+
JWT_EXPIRATION_PASSED: "mrx-core.jwt.error.expiration_passed",
|
|
5
|
+
JWT_SECRET_NOT_FOUND: "mrx-core.jwt.error.secret_not_found",
|
|
6
|
+
JWT_SIGN_ERROR: "mrx-core.jwt.error.sign_error"
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { JWT_ERROR_KEYS };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/shared/utils/flatten.ts
|
|
3
|
+
import { KindGuard } from "@sinclair/typebox";
|
|
4
|
+
import { t } from "elysia";
|
|
5
|
+
var _flattenInto = (type, result) => {
|
|
6
|
+
if (KindGuard.IsUnion(type))
|
|
7
|
+
for (const subType of type.anyOf)
|
|
8
|
+
_flattenInto(subType, result);
|
|
9
|
+
else
|
|
10
|
+
result.push(type);
|
|
11
|
+
};
|
|
12
|
+
var flatten = (type) => {
|
|
13
|
+
if (!KindGuard.IsUnion(type))
|
|
14
|
+
return type;
|
|
15
|
+
const isAlreadyFlat = type.anyOf.every((subType) => !KindGuard.IsUnion(subType));
|
|
16
|
+
if (isAlreadyFlat)
|
|
17
|
+
return type;
|
|
18
|
+
const result = [];
|
|
19
|
+
_flattenInto(type, result);
|
|
20
|
+
return t.Union(result);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { flatten };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// source/modules/totp/enums/totp-error-keys.ts
|
|
3
|
+
var TOTP_ERROR_KEYS = {
|
|
4
|
+
INVALID_ALGORITHM: "mrx-core.totp.error.invalid_algorithm",
|
|
5
|
+
INVALID_BASE32_CHARACTER: "mrx-core.totp.error.invalid_base32_character",
|
|
6
|
+
INVALID_OTP_AUTH_URI: "mrx-core.totp.error.invalid_otp_auth_uri",
|
|
7
|
+
INVALID_SECRET_LENGTH: "mrx-core.totp.error.invalid_secret_length",
|
|
8
|
+
MISSING_SECRET: "mrx-core.totp.error.missing_secret"
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { TOTP_ERROR_KEYS };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
Repository
|
|
4
|
+
} from "./chunk-afyz8rg5.js";
|
|
5
|
+
import {
|
|
6
|
+
TypedEventEmitter
|
|
7
|
+
} from "./chunk-mvrxngm7.js";
|
|
8
|
+
import {
|
|
9
|
+
DATABASE_ERROR_KEYS
|
|
10
|
+
} from "./chunk-4v86f7gp.js";
|
|
11
|
+
import {
|
|
12
|
+
BaseError
|
|
13
|
+
} from "./chunk-9cgzhc50.js";
|
|
14
|
+
|
|
15
|
+
// source/modules/database/table.ts
|
|
16
|
+
class Table extends TypedEventEmitter {
|
|
17
|
+
_databaseName;
|
|
18
|
+
_fields = [];
|
|
19
|
+
_name;
|
|
20
|
+
_primaryKey;
|
|
21
|
+
constructor(databaseName, tableName, fields, primaryKey) {
|
|
22
|
+
super();
|
|
23
|
+
this._databaseName = databaseName;
|
|
24
|
+
this._name = tableName;
|
|
25
|
+
this._fields = fields;
|
|
26
|
+
this._primaryKey = primaryKey;
|
|
27
|
+
}
|
|
28
|
+
get databaseName() {
|
|
29
|
+
return this._databaseName;
|
|
30
|
+
}
|
|
31
|
+
get name() {
|
|
32
|
+
return this._name;
|
|
33
|
+
}
|
|
34
|
+
get fields() {
|
|
35
|
+
return this._fields;
|
|
36
|
+
}
|
|
37
|
+
get primaryKey() {
|
|
38
|
+
return this._primaryKey;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// source/modules/database/mssql.ts
|
|
43
|
+
import knex from "knex";
|
|
44
|
+
class MSSQL extends TypedEventEmitter {
|
|
45
|
+
_isConnected = false;
|
|
46
|
+
_databaseName;
|
|
47
|
+
_tables = new Map;
|
|
48
|
+
_repositories = new Map;
|
|
49
|
+
_db;
|
|
50
|
+
_isEventEnabled;
|
|
51
|
+
constructor(options) {
|
|
52
|
+
super();
|
|
53
|
+
this._databaseName = options.databaseName;
|
|
54
|
+
this._isEventEnabled = options.isEventEnabled ?? false;
|
|
55
|
+
this._db = knex({
|
|
56
|
+
client: "mssql",
|
|
57
|
+
acquireConnectionTimeout: options.connectionTimeout ?? 20000,
|
|
58
|
+
compileSqlOnError: true,
|
|
59
|
+
connection: {
|
|
60
|
+
database: options.databaseName,
|
|
61
|
+
host: options.host,
|
|
62
|
+
port: options.port,
|
|
63
|
+
user: options.user,
|
|
64
|
+
password: options.password,
|
|
65
|
+
options: {
|
|
66
|
+
encrypt: options.encrypt ?? true
|
|
67
|
+
},
|
|
68
|
+
bigNumberStrings: false
|
|
69
|
+
},
|
|
70
|
+
pool: {
|
|
71
|
+
min: options.poolMin ?? 2,
|
|
72
|
+
max: options.poolMax ?? 10
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async connect() {
|
|
77
|
+
try {
|
|
78
|
+
await this._introspectDatabase();
|
|
79
|
+
this._isConnected = true;
|
|
80
|
+
if (this._isEventEnabled)
|
|
81
|
+
this._addEventKnex();
|
|
82
|
+
} catch (error) {
|
|
83
|
+
throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_CONNECTION_ERROR, {
|
|
84
|
+
databaseName: this._databaseName,
|
|
85
|
+
error
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async disconnect() {
|
|
90
|
+
if (!this._isConnected)
|
|
91
|
+
throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_NOT_CONNECTED, {
|
|
92
|
+
databaseName: this._databaseName
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
await this._db.destroy();
|
|
96
|
+
this._isConnected = false;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_DISCONNECT_ERROR, {
|
|
99
|
+
databaseName: this._databaseName,
|
|
100
|
+
error
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
getRepository(tableName, customRepository) {
|
|
105
|
+
if (!this._isConnected)
|
|
106
|
+
throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_NOT_CONNECTED, { databaseName: this._databaseName });
|
|
107
|
+
if (!this._tables.has(tableName))
|
|
108
|
+
throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_TABLE_NOT_FOUND, { table: tableName });
|
|
109
|
+
let repo = this._repositories.get(tableName);
|
|
110
|
+
if (customRepository) {
|
|
111
|
+
const table = this._tables.get(tableName);
|
|
112
|
+
if (repo && repo instanceof customRepository)
|
|
113
|
+
return repo;
|
|
114
|
+
repo = new customRepository(this._db, table);
|
|
115
|
+
this._repositories.set(tableName, repo);
|
|
116
|
+
return repo;
|
|
117
|
+
}
|
|
118
|
+
return this._repositories.get(tableName);
|
|
119
|
+
}
|
|
120
|
+
getTable(tableName) {
|
|
121
|
+
if (!this._isConnected)
|
|
122
|
+
throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_NOT_CONNECTED, { databaseName: this._databaseName });
|
|
123
|
+
if (!this._tables.has(tableName))
|
|
124
|
+
throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_TABLE_NOT_FOUND, { table: tableName });
|
|
125
|
+
return this._tables.get(tableName);
|
|
126
|
+
}
|
|
127
|
+
get databaseName() {
|
|
128
|
+
return this._databaseName;
|
|
129
|
+
}
|
|
130
|
+
get tables() {
|
|
131
|
+
return this._tables;
|
|
132
|
+
}
|
|
133
|
+
get repositories() {
|
|
134
|
+
return this._repositories;
|
|
135
|
+
}
|
|
136
|
+
get isConnected() {
|
|
137
|
+
return this._isConnected;
|
|
138
|
+
}
|
|
139
|
+
get db() {
|
|
140
|
+
if (!this._isConnected)
|
|
141
|
+
throw new BaseError(DATABASE_ERROR_KEYS.MSSQL_NOT_CONNECTED, { databaseName: this._databaseName });
|
|
142
|
+
return this._db;
|
|
143
|
+
}
|
|
144
|
+
async _introspectDatabase() {
|
|
145
|
+
const result = await this._db.from({ c: "information_schema.columns" }).select("c.table_name as tableName").select(this._db.raw("STRING_AGG(c.column_name, ',') AS fields")).select("pk.primaryKeyColumn as primaryKeyColumn").select("pk.primaryKeyType as primaryKeyType").leftJoin(this._db.from({ tc: "information_schema.table_constraints" }).join({ kcu: "information_schema.key_column_usage" }, "tc.constraint_name", "kcu.constraint_name").join({ col: "information_schema.columns" }, (builder) => {
|
|
146
|
+
builder.on("col.table_name", "=", "kcu.table_name").andOn("col.column_name", "=", "kcu.column_name");
|
|
147
|
+
}).where("tc.constraint_type", "PRIMARY KEY").groupBy("tc.table_name", "kcu.column_name", "col.data_type").select("tc.table_name as tableName").select("kcu.column_name as primaryKeyColumn").select("col.data_type as primaryKeyType").as("pk"), "c.table_name", "pk.tableName").groupBy("c.table_name", "pk.primaryKeyColumn", "pk.primaryKeyType");
|
|
148
|
+
const fieldsByTable = result.reduce((acc, { tableName, fields, primaryKeyColumn, primaryKeyType }) => {
|
|
149
|
+
const primaryKeyTypeTs = primaryKeyType === "int" ? "NUMBER" : "STRING";
|
|
150
|
+
acc.set(tableName, {
|
|
151
|
+
fields: fields.split(","),
|
|
152
|
+
primaryKey: [primaryKeyColumn, primaryKeyTypeTs]
|
|
153
|
+
});
|
|
154
|
+
return acc;
|
|
155
|
+
}, new Map);
|
|
156
|
+
fieldsByTable.forEach((desc, tableName) => {
|
|
157
|
+
const table = new Table(this._databaseName, tableName, desc.fields, desc.primaryKey);
|
|
158
|
+
this._tables.set(tableName, table);
|
|
159
|
+
this._repositories.set(tableName, new Repository(this._db, table));
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
_extractTablesFromSqlQuery(sql) {
|
|
163
|
+
const tableRegex = /(?:update|insert\s+into|delete\s+from|from|join|with)\s+\[?([^\]\s]+)\]?/gi;
|
|
164
|
+
const matches = [...sql.matchAll(tableRegex)].map((match) => match[1]);
|
|
165
|
+
return Array.from(new Set(matches));
|
|
166
|
+
}
|
|
167
|
+
_handleQueryResponse(response, queryContext) {
|
|
168
|
+
const tables = this._extractTablesFromSqlQuery(queryContext.sql);
|
|
169
|
+
const table = this._tables.get(tables[0]);
|
|
170
|
+
switch (queryContext.method) {
|
|
171
|
+
case "select":
|
|
172
|
+
table?.emit("selected", response, queryContext);
|
|
173
|
+
break;
|
|
174
|
+
case "insert":
|
|
175
|
+
table?.emit("inserted", response, queryContext);
|
|
176
|
+
break;
|
|
177
|
+
case "update":
|
|
178
|
+
table?.emit("updated", response, queryContext);
|
|
179
|
+
break;
|
|
180
|
+
case "del":
|
|
181
|
+
table?.emit("deleted", response, queryContext);
|
|
182
|
+
break;
|
|
183
|
+
default:
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
_addEventKnex() {
|
|
188
|
+
this._db.on("query", (queryContext) => {
|
|
189
|
+
this.emit("query", queryContext);
|
|
190
|
+
});
|
|
191
|
+
this._db.on("query-error", (error, queryContext) => {
|
|
192
|
+
this.emit("query:error", error, queryContext);
|
|
193
|
+
});
|
|
194
|
+
this._db.on("query-response", (response, queryContext) => {
|
|
195
|
+
this.emit("query:response", response, queryContext);
|
|
196
|
+
this._handleQueryResponse(response, queryContext);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export { Table, MSSQL };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
isDateString,
|
|
4
|
+
makeStreamAsyncIterable
|
|
5
|
+
} from "./chunk-grfyngq0.js";
|
|
6
|
+
import {
|
|
7
|
+
DATABASE_ERROR_KEYS,
|
|
8
|
+
MSSQL_ERROR_CODE
|
|
9
|
+
} from "./chunk-4v86f7gp.js";
|
|
10
|
+
import {
|
|
11
|
+
HttpError
|
|
12
|
+
} from "./chunk-7t524zqh.js";
|
|
13
|
+
|
|
14
|
+
// source/modules/repository/repository.ts
|
|
15
|
+
import { PassThrough } from "stream";
|
|
16
|
+
var _operators = {
|
|
17
|
+
$eq: (q, c, v) => q.where(c, v),
|
|
18
|
+
$neq: (q, c, v) => q.whereNot(c, v),
|
|
19
|
+
$lt: (q, c, v) => q.where(c, "<", v),
|
|
20
|
+
$lte: (q, c, v) => q.where(c, "<=", v),
|
|
21
|
+
$gt: (q, c, v) => q.where(c, ">", v),
|
|
22
|
+
$gte: (q, c, v) => q.where(c, ">=", v),
|
|
23
|
+
$in: (q, c, v) => q.whereIn(c, v),
|
|
24
|
+
$nin: (q, c, v) => q.whereNotIn(c, v),
|
|
25
|
+
$between: (q, c, v) => q.whereBetween(c, v),
|
|
26
|
+
$nbetween: (q, c, v) => q.whereNotBetween(c, v),
|
|
27
|
+
$like: (q, c, v) => {
|
|
28
|
+
const likeValue = `%${v}%`;
|
|
29
|
+
if (isDateString(v))
|
|
30
|
+
return q.whereRaw(`CONVERT(VARCHAR, ${c}, 23) LIKE ?`, [likeValue]);
|
|
31
|
+
return q.where(c, "LIKE", likeValue);
|
|
32
|
+
},
|
|
33
|
+
$nlike: (q, c, v) => {
|
|
34
|
+
const likeValue = `%${v}%`;
|
|
35
|
+
if (isDateString(v))
|
|
36
|
+
return q.whereRaw(`CONVERT(VARCHAR, ${c}, 23) NOT LIKE ?`, [likeValue]);
|
|
37
|
+
return q.whereRaw(`${c} NOT LIKE ?`, [likeValue]);
|
|
38
|
+
},
|
|
39
|
+
$isNull: (q, c, v) => v ? q.whereNull(c) : q.whereNotNull(c)
|
|
40
|
+
};
|
|
41
|
+
var _validOperatorKeys = new Set([
|
|
42
|
+
"$eq",
|
|
43
|
+
"$neq",
|
|
44
|
+
"$lt",
|
|
45
|
+
"$lte",
|
|
46
|
+
"$gt",
|
|
47
|
+
"$gte",
|
|
48
|
+
"$in",
|
|
49
|
+
"$nin",
|
|
50
|
+
"$between",
|
|
51
|
+
"$nbetween",
|
|
52
|
+
"$like",
|
|
53
|
+
"$nlike",
|
|
54
|
+
"$isNull"
|
|
55
|
+
]);
|
|
56
|
+
var _DEFAULT_LIMIT = 100;
|
|
57
|
+
var _DEFAULT_OFFSET = 0;
|
|
58
|
+
|
|
59
|
+
class Repository {
|
|
60
|
+
_knex;
|
|
61
|
+
_table;
|
|
62
|
+
constructor(knex, table) {
|
|
63
|
+
this._knex = knex;
|
|
64
|
+
this._table = table;
|
|
65
|
+
}
|
|
66
|
+
findStream(options) {
|
|
67
|
+
const query = this._knex(this._table.name);
|
|
68
|
+
this._applyQueryOptions(query, options);
|
|
69
|
+
const kStream = query.stream();
|
|
70
|
+
const passThrough = new PassThrough({
|
|
71
|
+
objectMode: true,
|
|
72
|
+
...options?.transform && { transform: options.transform }
|
|
73
|
+
});
|
|
74
|
+
const cleanup = () => {
|
|
75
|
+
if (!kStream.destroyed)
|
|
76
|
+
kStream.destroy();
|
|
77
|
+
if (!passThrough.destroyed)
|
|
78
|
+
passThrough.destroy();
|
|
79
|
+
};
|
|
80
|
+
kStream.on("error", (error) => {
|
|
81
|
+
const code = error?.number || 0;
|
|
82
|
+
passThrough.emit("error", new HttpError(MSSQL_ERROR_CODE[code] ?? DATABASE_ERROR_KEYS.MSSQL_QUERY_ERROR, {
|
|
83
|
+
query: query.toSQL().sql,
|
|
84
|
+
error
|
|
85
|
+
}));
|
|
86
|
+
});
|
|
87
|
+
passThrough.on("close", cleanup);
|
|
88
|
+
passThrough.on("error", cleanup);
|
|
89
|
+
kStream.pipe(passThrough);
|
|
90
|
+
return makeStreamAsyncIterable(passThrough);
|
|
91
|
+
}
|
|
92
|
+
async find(options) {
|
|
93
|
+
const query = this._knex(this._table.name);
|
|
94
|
+
this._applyQueryOptions(query, options);
|
|
95
|
+
const limit = options?.limit || _DEFAULT_LIMIT;
|
|
96
|
+
const offset = options?.offset || _DEFAULT_OFFSET;
|
|
97
|
+
query.limit(limit).offset(offset);
|
|
98
|
+
return this._executeQuery(query, options?.throwIfNoResult);
|
|
99
|
+
}
|
|
100
|
+
async count(options) {
|
|
101
|
+
const query = this._knex(this._table.name).count({ count: "*" });
|
|
102
|
+
this._applyFilter(query, options?.filters);
|
|
103
|
+
if (options?.transaction)
|
|
104
|
+
query.transacting(options.transaction);
|
|
105
|
+
return this._executeQuery(query, options?.throwIfNoResult).then((result) => result[0].count);
|
|
106
|
+
}
|
|
107
|
+
async insert(data, options) {
|
|
108
|
+
const query = this._knex(this._table.name).insert(data).returning(options?.selectedFields ?? "*");
|
|
109
|
+
if (options?.transaction)
|
|
110
|
+
query.transacting(options.transaction);
|
|
111
|
+
return this._executeQuery(query);
|
|
112
|
+
}
|
|
113
|
+
async update(data, options) {
|
|
114
|
+
const query = this._knex(this._table.name).update(data);
|
|
115
|
+
this._applyQueryOptions(query, options);
|
|
116
|
+
return this._executeQuery(query, options?.throwIfNoResult);
|
|
117
|
+
}
|
|
118
|
+
async delete(options) {
|
|
119
|
+
const query = this._knex(this._table.name).delete();
|
|
120
|
+
this._applyQueryOptions(query, options);
|
|
121
|
+
return this._executeQuery(query, options?.throwIfNoResult);
|
|
122
|
+
}
|
|
123
|
+
_applySelectedFields(query, selectedFields) {
|
|
124
|
+
const qMethod = query._method;
|
|
125
|
+
const sanitizedFields = selectedFields ? selectedFields === "*" ? "*" : Array.isArray(selectedFields) ? selectedFields.map((selectedField) => `${selectedField} as ${selectedField}`) : `${selectedFields} as ${selectedFields}` : "*";
|
|
126
|
+
if (qMethod === "del" || qMethod === "update" || qMethod === "insert")
|
|
127
|
+
query.returning(sanitizedFields, { includeTriggerModifications: true });
|
|
128
|
+
else
|
|
129
|
+
query.select(sanitizedFields);
|
|
130
|
+
}
|
|
131
|
+
_applyFilter(query, search) {
|
|
132
|
+
const processing = (query2, search2) => {
|
|
133
|
+
for (const key in search2) {
|
|
134
|
+
const prop = search2[key];
|
|
135
|
+
if (this._filterIsAdaptiveWhereClause(prop)) {
|
|
136
|
+
for (const operator in prop)
|
|
137
|
+
if (operator in _operators && prop[operator] !== undefined)
|
|
138
|
+
_operators[operator](query2, key, prop[operator]);
|
|
139
|
+
} else if (key === "$q" && prop !== null && (typeof prop === "string" || typeof prop === "number")) {
|
|
140
|
+
for (const field of this._table.fields)
|
|
141
|
+
if (prop)
|
|
142
|
+
query2.orWhere(field, "like", `%${prop}%`);
|
|
143
|
+
} else if (key === "$q" && prop !== null && typeof prop === "object" && "selectedFields" in prop && "value" in prop) {
|
|
144
|
+
const { selectedFields, value } = prop;
|
|
145
|
+
if (Array.isArray(selectedFields))
|
|
146
|
+
for (const field of selectedFields)
|
|
147
|
+
query2.orWhere(field, "like", `%${value}%`);
|
|
148
|
+
else
|
|
149
|
+
query2.orWhere(selectedFields, "like", `%${value}%`);
|
|
150
|
+
} else {
|
|
151
|
+
if (prop !== null && typeof prop === "object" && Object.keys(prop).length === 0)
|
|
152
|
+
continue;
|
|
153
|
+
if (prop !== undefined)
|
|
154
|
+
query2.where(key, prop);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
if (search && Array.isArray(search))
|
|
159
|
+
search.reduce((acc, item) => acc.orWhere((q) => this._applyFilter(q, item)), query);
|
|
160
|
+
else if (search)
|
|
161
|
+
processing(query, search);
|
|
162
|
+
}
|
|
163
|
+
_applyOrderBy(query, orderBy) {
|
|
164
|
+
const qMethod = query._method;
|
|
165
|
+
if (!(qMethod === "select"))
|
|
166
|
+
return;
|
|
167
|
+
if (!orderBy)
|
|
168
|
+
query.orderBy(`[${this._table.name}].${this._table.primaryKey[0]}`, "asc");
|
|
169
|
+
else if (Array.isArray(orderBy))
|
|
170
|
+
orderBy.forEach((item) => {
|
|
171
|
+
query.orderBy(`[${this._table.name}].${item.selectedField}`, item.direction);
|
|
172
|
+
});
|
|
173
|
+
else
|
|
174
|
+
query.orderBy(`[${this._table.name}].${orderBy.selectedField}`, orderBy.direction);
|
|
175
|
+
}
|
|
176
|
+
_applyQueryOptions(query, options) {
|
|
177
|
+
this._applyFilter(query, options?.filters);
|
|
178
|
+
this._applyOrderBy(query, options?.orderBy);
|
|
179
|
+
this._applySelectedFields(query, options?.selectedFields);
|
|
180
|
+
if (options?.transaction)
|
|
181
|
+
query.transacting(options.transaction);
|
|
182
|
+
}
|
|
183
|
+
_handleError(error, query) {
|
|
184
|
+
if (error instanceof HttpError)
|
|
185
|
+
throw error;
|
|
186
|
+
const code = error?.number || 0;
|
|
187
|
+
throw new HttpError(MSSQL_ERROR_CODE[code] ?? DATABASE_ERROR_KEYS.MSSQL_QUERY_ERROR, {
|
|
188
|
+
query: query.toSQL().sql,
|
|
189
|
+
error
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
_filterIsAdaptiveWhereClause(data) {
|
|
193
|
+
return Boolean(data && typeof data === "object" && !Array.isArray(data) && Object.keys(data).some((key) => _validOperatorKeys.has(key)));
|
|
194
|
+
}
|
|
195
|
+
async _executeQuery(query, throwIfNoResult = false) {
|
|
196
|
+
try {
|
|
197
|
+
const result = await query;
|
|
198
|
+
if (throwIfNoResult && result.length === 0)
|
|
199
|
+
throw new HttpError(typeof throwIfNoResult === "object" && throwIfNoResult.message ? throwIfNoResult.message : DATABASE_ERROR_KEYS.MSSQL_NO_RESULT, typeof throwIfNoResult === "object" && throwIfNoResult.httpStatusCode ? throwIfNoResult.httpStatusCode : 404, {
|
|
200
|
+
query: query.toSQL().sql
|
|
201
|
+
});
|
|
202
|
+
return result;
|
|
203
|
+
} catch (error) {
|
|
204
|
+
return this._handleError(error, query);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export { Repository };
|