@diia-inhouse/db 10.8.12 → 12.3.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.
Files changed (118) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +27 -0
  2. package/dist/cli/cleanupExpiredData.js +83 -136
  3. package/dist/cli/index.d.ts +1 -0
  4. package/dist/cli/index.js +85 -100
  5. package/dist/cli/runMigration.js +64 -105
  6. package/dist/cli/syncIndexes.js +38 -77
  7. package/dist/index.d.ts +28 -0
  8. package/dist/index.js +23 -22
  9. package/dist/interfaces/database.d.ts +10 -0
  10. package/dist/interfaces/dbConfig.d.ts +37 -0
  11. package/dist/interfaces/dbConfig.js +8 -9
  12. package/dist/interfaces/errors.d.ts +43 -0
  13. package/dist/interfaces/errors.js +42 -50
  14. package/dist/interfaces/index.d.ts +15 -0
  15. package/dist/interfaces/index.js +11 -25
  16. package/dist/interfaces/metrics.d.ts +22 -0
  17. package/dist/interfaces/metrics.js +38 -19
  18. package/dist/interfaces/migrateMongoConfig.d.ts +17 -0
  19. package/dist/interfaces/models/counter.d.ts +8 -0
  20. package/dist/interfaces/models/encryptedStorage.d.ts +9 -0
  21. package/dist/interfaces/mongoStatus.d.ts +16 -0
  22. package/dist/interfaces/mongoStatus.js +11 -12
  23. package/dist/mongo.d.ts +12 -0
  24. package/dist/mongo.js +71 -89
  25. package/dist/postgres.d.ts +4 -0
  26. package/dist/postgres.js +5 -19
  27. package/dist/postgresUtils.d.ts +8 -0
  28. package/dist/postgresUtils.js +14 -18
  29. package/dist/schemas/counter.d.ts +7 -0
  30. package/dist/schemas/counter.js +19 -14
  31. package/dist/schemas/encryptedStorage.d.ts +7 -0
  32. package/dist/schemas/encryptedStorage.js +17 -15
  33. package/dist/schemas/index.d.ts +3 -0
  34. package/dist/schemas/index.js +4 -20
  35. package/dist/schemas/statusHistoryItem.d.ts +7 -0
  36. package/dist/schemas/statusHistoryItem.js +16 -10
  37. package/dist/services/counter.d.ts +19 -0
  38. package/dist/services/counter.js +70 -72
  39. package/dist/services/database.d.ts +50 -0
  40. package/dist/services/database.js +255 -281
  41. package/dist/services/encryptedStorage.d.ts +73 -0
  42. package/dist/services/encryptedStorage.js +178 -214
  43. package/dist/services/index.d.ts +4 -0
  44. package/dist/services/index.js +5 -21
  45. package/dist/services/postgresDatabase.d.ts +12 -0
  46. package/dist/services/postgresDatabase.js +20 -25
  47. package/dist/tables/counter.d.ts +4 -0
  48. package/dist/tables/counter.js +11 -12
  49. package/dist/tables/encryptedStorage.d.ts +4 -0
  50. package/dist/tables/encryptedStorage.js +12 -13
  51. package/dist/tables/index.d.ts +9 -0
  52. package/dist/tables/index.js +3 -19
  53. package/package.json +47 -48
  54. package/dist/cli/cleanupExpiredData.js.map +0 -1
  55. package/dist/cli/index.js.map +0 -1
  56. package/dist/cli/runMigration.js.map +0 -1
  57. package/dist/cli/syncIndexes.js.map +0 -1
  58. package/dist/index.js.map +0 -1
  59. package/dist/interfaces/database.js +0 -3
  60. package/dist/interfaces/database.js.map +0 -1
  61. package/dist/interfaces/dbConfig.js.map +0 -1
  62. package/dist/interfaces/errors.js.map +0 -1
  63. package/dist/interfaces/index.js.map +0 -1
  64. package/dist/interfaces/metrics.js.map +0 -1
  65. package/dist/interfaces/migrateMongoConfig.js +0 -3
  66. package/dist/interfaces/migrateMongoConfig.js.map +0 -1
  67. package/dist/interfaces/models/counter.js +0 -3
  68. package/dist/interfaces/models/counter.js.map +0 -1
  69. package/dist/interfaces/models/encryptedStorage.js +0 -3
  70. package/dist/interfaces/models/encryptedStorage.js.map +0 -1
  71. package/dist/interfaces/models/index.js +0 -19
  72. package/dist/interfaces/models/index.js.map +0 -1
  73. package/dist/interfaces/mongoStatus.js.map +0 -1
  74. package/dist/mongo.js.map +0 -1
  75. package/dist/postgres.js.map +0 -1
  76. package/dist/postgresUtils.js.map +0 -1
  77. package/dist/schemas/counter.js.map +0 -1
  78. package/dist/schemas/encryptedStorage.js.map +0 -1
  79. package/dist/schemas/index.js.map +0 -1
  80. package/dist/schemas/statusHistoryItem.js.map +0 -1
  81. package/dist/services/counter.js.map +0 -1
  82. package/dist/services/database.js.map +0 -1
  83. package/dist/services/encryptedStorage.js.map +0 -1
  84. package/dist/services/index.js.map +0 -1
  85. package/dist/services/postgresDatabase.js.map +0 -1
  86. package/dist/tables/counter.js.map +0 -1
  87. package/dist/tables/encryptedStorage.js.map +0 -1
  88. package/dist/tables/index.js.map +0 -1
  89. package/dist/types/cli/cleanupExpiredData.d.ts +0 -11
  90. package/dist/types/cli/index.d.ts +0 -2
  91. package/dist/types/cli/runMigration.d.ts +0 -11
  92. package/dist/types/cli/syncIndexes.d.ts +0 -7
  93. package/dist/types/index.d.ts +0 -5
  94. package/dist/types/interfaces/database.d.ts +0 -8
  95. package/dist/types/interfaces/dbConfig.d.ts +0 -33
  96. package/dist/types/interfaces/errors.d.ts +0 -40
  97. package/dist/types/interfaces/index.d.ts +0 -8
  98. package/dist/types/interfaces/metrics.d.ts +0 -20
  99. package/dist/types/interfaces/migrateMongoConfig.d.ts +0 -13
  100. package/dist/types/interfaces/models/counter.d.ts +0 -5
  101. package/dist/types/interfaces/models/encryptedStorage.d.ts +0 -6
  102. package/dist/types/interfaces/models/index.d.ts +0 -2
  103. package/dist/types/interfaces/mongoStatus.d.ts +0 -12
  104. package/dist/types/mongo.d.ts +0 -9
  105. package/dist/types/postgres.d.ts +0 -2
  106. package/dist/types/postgresUtils.d.ts +0 -26
  107. package/dist/types/schemas/counter.d.ts +0 -12
  108. package/dist/types/schemas/encryptedStorage.d.ts +0 -12
  109. package/dist/types/schemas/index.d.ts +0 -3
  110. package/dist/types/schemas/statusHistoryItem.d.ts +0 -3
  111. package/dist/types/services/counter.d.ts +0 -15
  112. package/dist/types/services/database.d.ts +0 -43
  113. package/dist/types/services/encryptedStorage.d.ts +0 -69
  114. package/dist/types/services/index.d.ts +0 -4
  115. package/dist/types/services/postgresDatabase.d.ts +0 -8
  116. package/dist/types/tables/counter.d.ts +0 -94
  117. package/dist/types/tables/encryptedStorage.d.ts +0 -111
  118. package/dist/types/tables/index.d.ts +0 -2
@@ -1,78 +1,39 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import recursiveRead from "recursive-readdir";
4
+ //#region src/cli/syncIndexes.ts
5
+ var SyncIndexesCommand = class {
6
+ logger;
7
+ constructor(logger) {
8
+ this.logger = logger;
9
+ }
10
+ async run(modelsDir) {
11
+ const modelsPath = `./dist/${modelsDir}`;
12
+ if (!existsSync(modelsPath)) throw new Error(`Models dir is absent: ${modelsPath}`);
13
+ const t0 = Date.now();
14
+ this.logger.info("Start syncing indexes");
15
+ const files = await recursiveRead(modelsPath, [
16
+ "*.map",
17
+ "index.js",
18
+ "schemas",
19
+ "*.types.js"
20
+ ]);
21
+ const tasks = [];
22
+ for (const fileName of files) {
23
+ const modelModule = await import(path.resolve(fileName));
24
+ if (modelModule.skipSyncIndexes) continue;
25
+ const task = modelModule.default;
26
+ tasks.push(this.syncModel(task));
27
+ }
28
+ await Promise.all(tasks);
29
+ this.logger.info(`Ended syncing indexes in ${Date.now() - t0} ms`);
30
+ }
31
+ async syncModel(model) {
32
+ const t0 = Date.now();
33
+ this.logger.info(`Start syncing indexes for the ${model.modelName} collection`);
34
+ await model.syncIndexes();
35
+ this.logger.info(`Ended syncing indexes for the ${model.modelName} collection in ${Date.now() - t0} ms`);
36
+ }
37
37
  };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.SyncIndexesCommand = void 0;
40
- const node_fs_1 = require("node:fs");
41
- const node_path_1 = __importDefault(require("node:path"));
42
- const recursive_readdir_1 = __importDefault(require("recursive-readdir"));
43
- class SyncIndexesCommand {
44
- logger;
45
- constructor(logger) {
46
- this.logger = logger;
47
- }
48
- async run(modelsDir) {
49
- const modelsPath = `./dist/${modelsDir}`;
50
- // eslint-disable-next-line security/detect-non-literal-fs-filename
51
- const isExistsSync = (0, node_fs_1.existsSync)(modelsPath); // nosemgrep: eslint.detect-non-literal-fs-filename
52
- if (!isExistsSync) {
53
- throw new Error(`Models dir is absent: ${modelsPath}`);
54
- }
55
- const t0 = Date.now();
56
- this.logger.info('Start syncing indexes');
57
- const files = await (0, recursive_readdir_1.default)(modelsPath, ['*.map', 'index.js', 'schemas', '*.types.js']);
58
- const tasks = [];
59
- for (const fileName of files) {
60
- const modelModule = await Promise.resolve(`${node_path_1.default.resolve(fileName)}`).then(s => __importStar(require(s)));
61
- if (modelModule.skipSyncIndexes) {
62
- continue;
63
- }
64
- const task = modelModule.default;
65
- tasks.push(this.syncModel(task));
66
- }
67
- await Promise.all(tasks);
68
- this.logger.info(`Ended syncing indexes in ${Date.now() - t0} ms`);
69
- }
70
- async syncModel(model) {
71
- const t0 = Date.now();
72
- this.logger.info(`Start syncing indexes for the ${model.modelName} collection`);
73
- await model.syncIndexes();
74
- this.logger.info(`Ended syncing indexes for the ${model.modelName} collection in ${Date.now() - t0} ms`);
75
- }
76
- }
77
- exports.SyncIndexesCommand = SyncIndexesCommand;
78
- //# sourceMappingURL=syncIndexes.js.map
38
+ //#endregion
39
+ export { SyncIndexesCommand };
@@ -0,0 +1,28 @@
1
+ import { counter } from "./tables/counter.js";
2
+ import { encryptedStorage } from "./tables/encryptedStorage.js";
3
+ import { DatabaseAdapter, DatabaseAdapterType, DerivedRepository, PostgresDatabase } from "./interfaces/database.js";
4
+ import { AppDb, AppDbConfig, DbType, PostgresDbConfig, ReplicaSetNodeConfig } from "./interfaces/dbConfig.js";
5
+ import { MongoDBErrorCode, PostgresErrorCode } from "./interfaces/errors.js";
6
+ import { MigrateMongoConfig } from "./interfaces/migrateMongoConfig.js";
7
+ import { DbConnectionStatus, DbStatusByType, MongoDbStatus } from "./interfaces/mongoStatus.js";
8
+ import { DbOpLog, DbOpLogEntry, MongodbOperationResult, MongodbOperationsLabelsMap, mongodbOperationsAllowedFields, mongodbOperationsDefaultBuckets } from "./interfaces/metrics.js";
9
+ import { Counter } from "./interfaces/models/counter.js";
10
+ import { EncryptedStorage } from "./interfaces/models/encryptedStorage.js";
11
+ import { models, mongoose } from "./interfaces/index.js";
12
+ import { DatabaseService } from "./services/database.js";
13
+ import { PostgresDatabaseService } from "./services/postgresDatabase.js";
14
+ import { EncryptedStorageService } from "./services/encryptedStorage.js";
15
+ import { CounterService } from "./services/counter.js";
16
+ import { MongoHelper } from "./mongo.js";
17
+ import { counterSchema } from "./schemas/counter.js";
18
+ import { encryptedStorageSchema } from "./schemas/encryptedStorage.js";
19
+ import { createStatusHistoryItemSchema } from "./schemas/statusHistoryItem.js";
20
+ import { expiringTimestamp, timestamps } from "./postgresUtils.js";
21
+ export * from "mongoose";
22
+
23
+ //#region src/index.d.ts
24
+ declare namespace index_d_exports {
25
+ export { AppDb, AppDbConfig, Counter, CounterService, DatabaseAdapter, DatabaseAdapterType, DatabaseService, DbConnectionStatus, DbOpLog, DbOpLogEntry, DbStatusByType, DbType, DerivedRepository, EncryptedStorage, EncryptedStorageService, MigrateMongoConfig, MongoDBErrorCode, MongoDbStatus, MongoHelper, MongodbOperationResult, MongodbOperationsLabelsMap, PostgresDatabase, PostgresDatabaseService, PostgresDbConfig, PostgresErrorCode, ReplicaSetNodeConfig, counter, counterSchema, createStatusHistoryItemSchema, encryptedStorage, encryptedStorageSchema, expiringTimestamp, models, mongodbOperationsAllowedFields, mongodbOperationsDefaultBuckets, mongoose, timestamps };
26
+ }
27
+ //#endregion
28
+ export { AppDb, AppDbConfig, Counter, CounterService, DatabaseAdapter, DatabaseAdapterType, DatabaseService, DbConnectionStatus, DbOpLog, DbOpLogEntry, DbStatusByType, DbType, DerivedRepository, EncryptedStorage, EncryptedStorageService, MigrateMongoConfig, MongoDBErrorCode, MongoDbStatus, MongoHelper, MongodbOperationResult, MongodbOperationsLabelsMap, PostgresDatabase, PostgresDatabaseService, PostgresDbConfig, PostgresErrorCode, ReplicaSetNodeConfig, counter, counterSchema, createStatusHistoryItemSchema, encryptedStorage, encryptedStorageSchema, expiringTimestamp, models, mongodbOperationsAllowedFields, mongodbOperationsDefaultBuckets, mongoose, timestamps };
package/dist/index.js CHANGED
@@ -1,22 +1,23 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./interfaces"), exports);
18
- __exportStar(require("./services"), exports);
19
- __exportStar(require("./mongo"), exports);
20
- __exportStar(require("./schemas"), exports);
21
- __exportStar(require("./postgres"), exports);
22
- //# sourceMappingURL=index.js.map
1
+ import "./_virtual/_rolldown/runtime.js";
2
+ import { DbType } from "./interfaces/dbConfig.js";
3
+ import { MongoDBErrorCode, PostgresErrorCode } from "./interfaces/errors.js";
4
+ import { DbConnectionStatus } from "./interfaces/mongoStatus.js";
5
+ import { MongodbOperationResult, mongodbOperationsAllowedFields, mongodbOperationsDefaultBuckets } from "./interfaces/metrics.js";
6
+ import { models, mongoose } from "./interfaces/index.js";
7
+ import { DatabaseService } from "./services/database.js";
8
+ import { PostgresDatabaseService } from "./services/postgresDatabase.js";
9
+ import { expiringTimestamp, timestamps } from "./postgresUtils.js";
10
+ import { encryptedStorage } from "./tables/encryptedStorage.js";
11
+ import { EncryptedStorageService } from "./services/encryptedStorage.js";
12
+ import { counter } from "./tables/counter.js";
13
+ import { CounterService } from "./services/counter.js";
14
+ import "./services/index.js";
15
+ import { MongoHelper } from "./mongo.js";
16
+ import { counterSchema } from "./schemas/counter.js";
17
+ import { encryptedStorageSchema } from "./schemas/encryptedStorage.js";
18
+ import { createStatusHistoryItemSchema } from "./schemas/statusHistoryItem.js";
19
+ import "./schemas/index.js";
20
+ import "./postgres.js";
21
+ export * from "mongoose";
22
+ //#endregion
23
+ export { CounterService, DatabaseService, DbConnectionStatus, DbType, EncryptedStorageService, MongoDBErrorCode, MongoHelper, MongodbOperationResult, PostgresDatabaseService, PostgresErrorCode, counter, counterSchema, createStatusHistoryItemSchema, encryptedStorage, encryptedStorageSchema, expiringTimestamp, models, mongodbOperationsAllowedFields, mongodbOperationsDefaultBuckets, mongoose, timestamps };
@@ -0,0 +1,10 @@
1
+ import { index_d_exports } from "../tables/index.js";
2
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
3
+
4
+ //#region src/interfaces/database.d.ts
5
+ type DatabaseAdapterType = "mongo" | "postgres";
6
+ type DerivedRepository<TRepository> = { [K in keyof TRepository]: TRepository[K] extends ((...args: any[]) => any) ? TRepository[K] : never };
7
+ type PostgresDatabase = NodePgDatabase<typeof index_d_exports>;
8
+ type DatabaseAdapter<T extends DatabaseAdapterType, Repositories extends Record<DatabaseAdapterType, unknown>> = Repositories[T];
9
+ //#endregion
10
+ export { DatabaseAdapter, DatabaseAdapterType, DerivedRepository, PostgresDatabase };
@@ -0,0 +1,37 @@
1
+ import mongoose, { mongo } from "mongoose";
2
+
3
+ //#region src/interfaces/dbConfig.d.ts
4
+ interface ReplicaSetNodeConfig {
5
+ replicaHost: string;
6
+ }
7
+ declare enum DbType {
8
+ Main = "main",
9
+ Cache = "cache"
10
+ }
11
+ interface AppDbConfig {
12
+ isEnabled?: boolean;
13
+ user?: string;
14
+ password?: string;
15
+ database: string;
16
+ authSource?: string;
17
+ host?: string;
18
+ port?: number;
19
+ replicaSet?: string;
20
+ replicaSetNodes?: ReplicaSetNodeConfig[];
21
+ readPreference?: string;
22
+ authMechanism?: mongo.AuthMechanism;
23
+ metrics: {
24
+ enabled: boolean;
25
+ buckets?: number[];
26
+ };
27
+ }
28
+ interface PostgresDbConfig {
29
+ url: string;
30
+ }
31
+ interface AppDb {
32
+ connection: mongoose.Connection;
33
+ connectionString: string;
34
+ connectionOptions: mongoose.ConnectOptions;
35
+ }
36
+ //#endregion
37
+ export { AppDb, AppDbConfig, DbType, PostgresDbConfig, ReplicaSetNodeConfig };
@@ -1,9 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DbType = void 0;
4
- var DbType;
5
- (function (DbType) {
6
- DbType["Main"] = "main";
7
- DbType["Cache"] = "cache";
8
- })(DbType || (exports.DbType = DbType = {}));
9
- //# sourceMappingURL=dbConfig.js.map
1
+ //#region src/interfaces/dbConfig.ts
2
+ let DbType = /* @__PURE__ */ function(DbType) {
3
+ DbType["Main"] = "main";
4
+ DbType["Cache"] = "cache";
5
+ return DbType;
6
+ }({});
7
+ //#endregion
8
+ export { DbType };
@@ -0,0 +1,43 @@
1
+ //#region src/interfaces/errors.d.ts
2
+ declare enum MongoDBErrorCode {
3
+ AlreadyInitialized = 23,
4
+ AuthenticationFailed = 18,
5
+ BadValue = 2,
6
+ CannotMutateObject = 10,
7
+ CannotReuseObject = 19,
8
+ CollectionDoesNotExist = 26,
9
+ DuplicateKey = 11e3,
10
+ EmptyArrayOperation = 21,
11
+ FailedToParse = 9,
12
+ GraphContainsCycle = 5,
13
+ HostNotFound = 7,
14
+ HostUnreachable = 6,
15
+ IllegalOperation = 20,
16
+ IndexNotFound = 27,
17
+ InternalError = 1,
18
+ InvalidBson = 22,
19
+ InvalidLength = 16,
20
+ InvalidPath = 30,
21
+ LockTimeout = 24,
22
+ MaxTimeMSExpired = 50,
23
+ NonExistentPath = 29,
24
+ NoSuchKey = 4,
25
+ Overflow = 15,
26
+ PathNotViable = 28,
27
+ ProtocolError = 17,
28
+ QueryCommandNotFound = 59,
29
+ QueryNotTailable = 13051,
30
+ RemoteValidationError = 25,
31
+ TypeMismatch = 14,
32
+ Unauthorized = 13,
33
+ UnknownError = 8,
34
+ UnsupportedFormat = 12,
35
+ UserNotFound = 11,
36
+ WriteConcernError = 64,
37
+ WriteConflict = 112
38
+ }
39
+ declare const PostgresErrorCode: {
40
+ readonly InvalidCredentials: "28P01";
41
+ };
42
+ //#endregion
43
+ export { MongoDBErrorCode, PostgresErrorCode };
@@ -1,50 +1,42 @@
1
- "use strict";
2
- /*
3
- Full list of mongo errors:
4
- https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.yml
5
- https://github.com/mongodb/mongo-c-driver/blob/master/src/libmongoc/src/mongoc/mongoc-error.h
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.PostgresErrorCode = exports.MongoDBErrorCode = void 0;
9
- var MongoDBErrorCode;
10
- (function (MongoDBErrorCode) {
11
- MongoDBErrorCode[MongoDBErrorCode["AlreadyInitialized"] = 23] = "AlreadyInitialized";
12
- MongoDBErrorCode[MongoDBErrorCode["AuthenticationFailed"] = 18] = "AuthenticationFailed";
13
- MongoDBErrorCode[MongoDBErrorCode["BadValue"] = 2] = "BadValue";
14
- MongoDBErrorCode[MongoDBErrorCode["CannotMutateObject"] = 10] = "CannotMutateObject";
15
- MongoDBErrorCode[MongoDBErrorCode["CannotReuseObject"] = 19] = "CannotReuseObject";
16
- MongoDBErrorCode[MongoDBErrorCode["CollectionDoesNotExist"] = 26] = "CollectionDoesNotExist";
17
- MongoDBErrorCode[MongoDBErrorCode["DuplicateKey"] = 11000] = "DuplicateKey";
18
- MongoDBErrorCode[MongoDBErrorCode["EmptyArrayOperation"] = 21] = "EmptyArrayOperation";
19
- MongoDBErrorCode[MongoDBErrorCode["FailedToParse"] = 9] = "FailedToParse";
20
- MongoDBErrorCode[MongoDBErrorCode["GraphContainsCycle"] = 5] = "GraphContainsCycle";
21
- MongoDBErrorCode[MongoDBErrorCode["HostNotFound"] = 7] = "HostNotFound";
22
- MongoDBErrorCode[MongoDBErrorCode["HostUnreachable"] = 6] = "HostUnreachable";
23
- MongoDBErrorCode[MongoDBErrorCode["IllegalOperation"] = 20] = "IllegalOperation";
24
- MongoDBErrorCode[MongoDBErrorCode["IndexNotFound"] = 27] = "IndexNotFound";
25
- MongoDBErrorCode[MongoDBErrorCode["InternalError"] = 1] = "InternalError";
26
- MongoDBErrorCode[MongoDBErrorCode["InvalidBson"] = 22] = "InvalidBson";
27
- MongoDBErrorCode[MongoDBErrorCode["InvalidLength"] = 16] = "InvalidLength";
28
- MongoDBErrorCode[MongoDBErrorCode["InvalidPath"] = 30] = "InvalidPath";
29
- MongoDBErrorCode[MongoDBErrorCode["LockTimeout"] = 24] = "LockTimeout";
30
- MongoDBErrorCode[MongoDBErrorCode["MaxTimeMSExpired"] = 50] = "MaxTimeMSExpired";
31
- MongoDBErrorCode[MongoDBErrorCode["NonExistentPath"] = 29] = "NonExistentPath";
32
- MongoDBErrorCode[MongoDBErrorCode["NoSuchKey"] = 4] = "NoSuchKey";
33
- MongoDBErrorCode[MongoDBErrorCode["Overflow"] = 15] = "Overflow";
34
- MongoDBErrorCode[MongoDBErrorCode["PathNotViable"] = 28] = "PathNotViable";
35
- MongoDBErrorCode[MongoDBErrorCode["ProtocolError"] = 17] = "ProtocolError";
36
- MongoDBErrorCode[MongoDBErrorCode["QueryCommandNotFound"] = 59] = "QueryCommandNotFound";
37
- MongoDBErrorCode[MongoDBErrorCode["QueryNotTailable"] = 13051] = "QueryNotTailable";
38
- MongoDBErrorCode[MongoDBErrorCode["RemoteValidationError"] = 25] = "RemoteValidationError";
39
- MongoDBErrorCode[MongoDBErrorCode["TypeMismatch"] = 14] = "TypeMismatch";
40
- MongoDBErrorCode[MongoDBErrorCode["Unauthorized"] = 13] = "Unauthorized";
41
- MongoDBErrorCode[MongoDBErrorCode["UnknownError"] = 8] = "UnknownError";
42
- MongoDBErrorCode[MongoDBErrorCode["UnsupportedFormat"] = 12] = "UnsupportedFormat";
43
- MongoDBErrorCode[MongoDBErrorCode["UserNotFound"] = 11] = "UserNotFound";
44
- MongoDBErrorCode[MongoDBErrorCode["WriteConcernError"] = 64] = "WriteConcernError";
45
- MongoDBErrorCode[MongoDBErrorCode["WriteConflict"] = 112] = "WriteConflict";
46
- })(MongoDBErrorCode || (exports.MongoDBErrorCode = MongoDBErrorCode = {}));
47
- exports.PostgresErrorCode = {
48
- InvalidCredentials: '28P01',
49
- };
50
- //# sourceMappingURL=errors.js.map
1
+ //#region src/interfaces/errors.ts
2
+ let MongoDBErrorCode = /* @__PURE__ */ function(MongoDBErrorCode) {
3
+ MongoDBErrorCode[MongoDBErrorCode["AlreadyInitialized"] = 23] = "AlreadyInitialized";
4
+ MongoDBErrorCode[MongoDBErrorCode["AuthenticationFailed"] = 18] = "AuthenticationFailed";
5
+ MongoDBErrorCode[MongoDBErrorCode["BadValue"] = 2] = "BadValue";
6
+ MongoDBErrorCode[MongoDBErrorCode["CannotMutateObject"] = 10] = "CannotMutateObject";
7
+ MongoDBErrorCode[MongoDBErrorCode["CannotReuseObject"] = 19] = "CannotReuseObject";
8
+ MongoDBErrorCode[MongoDBErrorCode["CollectionDoesNotExist"] = 26] = "CollectionDoesNotExist";
9
+ MongoDBErrorCode[MongoDBErrorCode["DuplicateKey"] = 11e3] = "DuplicateKey";
10
+ MongoDBErrorCode[MongoDBErrorCode["EmptyArrayOperation"] = 21] = "EmptyArrayOperation";
11
+ MongoDBErrorCode[MongoDBErrorCode["FailedToParse"] = 9] = "FailedToParse";
12
+ MongoDBErrorCode[MongoDBErrorCode["GraphContainsCycle"] = 5] = "GraphContainsCycle";
13
+ MongoDBErrorCode[MongoDBErrorCode["HostNotFound"] = 7] = "HostNotFound";
14
+ MongoDBErrorCode[MongoDBErrorCode["HostUnreachable"] = 6] = "HostUnreachable";
15
+ MongoDBErrorCode[MongoDBErrorCode["IllegalOperation"] = 20] = "IllegalOperation";
16
+ MongoDBErrorCode[MongoDBErrorCode["IndexNotFound"] = 27] = "IndexNotFound";
17
+ MongoDBErrorCode[MongoDBErrorCode["InternalError"] = 1] = "InternalError";
18
+ MongoDBErrorCode[MongoDBErrorCode["InvalidBson"] = 22] = "InvalidBson";
19
+ MongoDBErrorCode[MongoDBErrorCode["InvalidLength"] = 16] = "InvalidLength";
20
+ MongoDBErrorCode[MongoDBErrorCode["InvalidPath"] = 30] = "InvalidPath";
21
+ MongoDBErrorCode[MongoDBErrorCode["LockTimeout"] = 24] = "LockTimeout";
22
+ MongoDBErrorCode[MongoDBErrorCode["MaxTimeMSExpired"] = 50] = "MaxTimeMSExpired";
23
+ MongoDBErrorCode[MongoDBErrorCode["NonExistentPath"] = 29] = "NonExistentPath";
24
+ MongoDBErrorCode[MongoDBErrorCode["NoSuchKey"] = 4] = "NoSuchKey";
25
+ MongoDBErrorCode[MongoDBErrorCode["Overflow"] = 15] = "Overflow";
26
+ MongoDBErrorCode[MongoDBErrorCode["PathNotViable"] = 28] = "PathNotViable";
27
+ MongoDBErrorCode[MongoDBErrorCode["ProtocolError"] = 17] = "ProtocolError";
28
+ MongoDBErrorCode[MongoDBErrorCode["QueryCommandNotFound"] = 59] = "QueryCommandNotFound";
29
+ MongoDBErrorCode[MongoDBErrorCode["QueryNotTailable"] = 13051] = "QueryNotTailable";
30
+ MongoDBErrorCode[MongoDBErrorCode["RemoteValidationError"] = 25] = "RemoteValidationError";
31
+ MongoDBErrorCode[MongoDBErrorCode["TypeMismatch"] = 14] = "TypeMismatch";
32
+ MongoDBErrorCode[MongoDBErrorCode["Unauthorized"] = 13] = "Unauthorized";
33
+ MongoDBErrorCode[MongoDBErrorCode["UnknownError"] = 8] = "UnknownError";
34
+ MongoDBErrorCode[MongoDBErrorCode["UnsupportedFormat"] = 12] = "UnsupportedFormat";
35
+ MongoDBErrorCode[MongoDBErrorCode["UserNotFound"] = 11] = "UserNotFound";
36
+ MongoDBErrorCode[MongoDBErrorCode["WriteConcernError"] = 64] = "WriteConcernError";
37
+ MongoDBErrorCode[MongoDBErrorCode["WriteConflict"] = 112] = "WriteConflict";
38
+ return MongoDBErrorCode;
39
+ }({});
40
+ const PostgresErrorCode = { InvalidCredentials: "28P01" };
41
+ //#endregion
42
+ export { MongoDBErrorCode, PostgresErrorCode };
@@ -0,0 +1,15 @@
1
+ import { DatabaseAdapter, DatabaseAdapterType, DerivedRepository, PostgresDatabase } from "./database.js";
2
+ import { AppDb, AppDbConfig, DbType, PostgresDbConfig, ReplicaSetNodeConfig } from "./dbConfig.js";
3
+ import { MongoDBErrorCode, PostgresErrorCode } from "./errors.js";
4
+ import { MigrateMongoConfig } from "./migrateMongoConfig.js";
5
+ import { DbConnectionStatus, DbStatusByType, MongoDbStatus } from "./mongoStatus.js";
6
+ import { DbOpLog, DbOpLogEntry, MongodbOperationResult, MongodbOperationsLabelsMap, mongodbOperationsAllowedFields, mongodbOperationsDefaultBuckets } from "./metrics.js";
7
+ import { Counter } from "./models/counter.js";
8
+ import { EncryptedStorage } from "./models/encryptedStorage.js";
9
+ import mongoose$1, { Models } from "mongoose";
10
+ export * from "mongoose";
11
+
12
+ //#region src/interfaces/index.d.ts
13
+ declare const models: Models;
14
+ //#endregion
15
+ export { models, mongoose$1 as mongoose };
@@ -1,25 +1,11 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("mongoose"), exports);
18
- __exportStar(require("./database"), exports);
19
- __exportStar(require("./dbConfig"), exports);
20
- __exportStar(require("./errors"), exports);
21
- __exportStar(require("./migrateMongoConfig"), exports);
22
- __exportStar(require("./mongoStatus"), exports);
23
- __exportStar(require("./metrics"), exports);
24
- __exportStar(require("./models"), exports);
25
- //# sourceMappingURL=index.js.map
1
+ import "../_virtual/_rolldown/runtime.js";
2
+ import "./dbConfig.js";
3
+ import "./errors.js";
4
+ import "./mongoStatus.js";
5
+ import "./metrics.js";
6
+ import mongoose$1 from "mongoose";
7
+ export * from "mongoose";
8
+ //#region src/interfaces/index.ts
9
+ const models = mongoose$1.models;
10
+ //#endregion
11
+ export { models, mongoose$1 as mongoose };
@@ -0,0 +1,22 @@
1
+ //#region src/interfaces/metrics.d.ts
2
+ declare enum MongodbOperationResult {
3
+ Successful = "successful",
4
+ Failed = "failed"
5
+ }
6
+ interface DbOpLogEntry {
7
+ database: string;
8
+ collection?: string;
9
+ opType: string;
10
+ }
11
+ type DbOpLog = Record<string, DbOpLogEntry>;
12
+ declare class MongodbOperationsLabelsMapConcrete {
13
+ operation: string;
14
+ status: MongodbOperationResult;
15
+ database: string;
16
+ collection: string;
17
+ }
18
+ type MongodbOperationsLabelsMap = MongodbOperationsLabelsMapConcrete;
19
+ declare const mongodbOperationsAllowedFields: (keyof MongodbOperationsLabelsMap)[];
20
+ declare const mongodbOperationsDefaultBuckets: number[];
21
+ //#endregion
22
+ export { DbOpLog, DbOpLogEntry, MongodbOperationResult, MongodbOperationsLabelsMap, mongodbOperationsAllowedFields, mongodbOperationsDefaultBuckets };
@@ -1,20 +1,39 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mongodbOperationsDefaultBuckets = exports.mongodbOperationsAllowedFields = exports.MongodbOperationResult = void 0;
4
- var MongodbOperationResult;
5
- (function (MongodbOperationResult) {
6
- MongodbOperationResult["Successful"] = "successful";
7
- MongodbOperationResult["Failed"] = "failed";
8
- })(MongodbOperationResult || (exports.MongodbOperationResult = MongodbOperationResult = {}));
9
- class MongodbOperationsLabelsMapConcrete {
10
- operation = '';
11
- status = MongodbOperationResult.Successful;
12
- database = '';
13
- collection = '';
14
- }
15
- exports.mongodbOperationsAllowedFields = Object.keys(new MongodbOperationsLabelsMapConcrete());
16
- // From 1ms up to 30s
17
- exports.mongodbOperationsDefaultBuckets = [
18
- 0.001, 0.003, 0.005, 0.01, 0.015, 0.03, 0.05, 0.07, 0.09, 0.1, 0.15, 0.3, 0.5, 0.7, 0.9, 1, 5, 10, 15, 20, 25, 30,
1
+ //#region src/interfaces/metrics.ts
2
+ let MongodbOperationResult = /* @__PURE__ */ function(MongodbOperationResult) {
3
+ MongodbOperationResult["Successful"] = "successful";
4
+ MongodbOperationResult["Failed"] = "failed";
5
+ return MongodbOperationResult;
6
+ }({});
7
+ var MongodbOperationsLabelsMapConcrete = class {
8
+ operation = "";
9
+ status = "successful";
10
+ database = "";
11
+ collection = "";
12
+ };
13
+ const mongodbOperationsAllowedFields = Object.keys(new MongodbOperationsLabelsMapConcrete());
14
+ const mongodbOperationsDefaultBuckets = [
15
+ .001,
16
+ .003,
17
+ .005,
18
+ .01,
19
+ .015,
20
+ .03,
21
+ .05,
22
+ .07,
23
+ .09,
24
+ .1,
25
+ .15,
26
+ .3,
27
+ .5,
28
+ .7,
29
+ .9,
30
+ 1,
31
+ 5,
32
+ 10,
33
+ 15,
34
+ 20,
35
+ 25,
36
+ 30
19
37
  ];
20
- //# sourceMappingURL=metrics.js.map
38
+ //#endregion
39
+ export { MongodbOperationResult, mongodbOperationsAllowedFields, mongodbOperationsDefaultBuckets };
@@ -0,0 +1,17 @@
1
+ import { mongo } from "mongoose";
2
+
3
+ //#region src/interfaces/migrateMongoConfig.d.ts
4
+ interface MigrateMongoConfig {
5
+ mongodb: {
6
+ url: Parameters<(typeof mongo.MongoClient)["connect"]>[0];
7
+ databaseName?: mongo.Db["databaseName"];
8
+ options?: mongo.MongoClientOptions;
9
+ };
10
+ migrationsDir?: string;
11
+ changelogCollectionName: string;
12
+ migrationFileExtension?: string;
13
+ useFileHash?: boolean;
14
+ moduleSystem: string;
15
+ }
16
+ //#endregion
17
+ export { MigrateMongoConfig };
@@ -0,0 +1,8 @@
1
+ //#region src/interfaces/models/counter.d.ts
2
+ interface Counter {
3
+ code: string;
4
+ value: number;
5
+ date?: Date;
6
+ }
7
+ //#endregion
8
+ export { Counter };
@@ -0,0 +1,9 @@
1
+ //#region src/interfaces/models/encryptedStorage.d.ts
2
+ interface EncryptedStorage {
3
+ id?: string;
4
+ data: string;
5
+ expiresAt: Date;
6
+ source?: unknown;
7
+ }
8
+ //#endregion
9
+ export { EncryptedStorage };
@@ -0,0 +1,16 @@
1
+ import { DbType } from "./dbConfig.js";
2
+
3
+ //#region src/interfaces/mongoStatus.d.ts
4
+ declare enum DbConnectionStatus {
5
+ Disconnected = "disconnected",
6
+ Connected = "connected",
7
+ Connecting = "connecting",
8
+ Disconnecting = "disconnecting",
9
+ OpFailed = "op_failed"
10
+ }
11
+ type DbStatusByType = Partial<Record<DbType, DbConnectionStatus>>;
12
+ type MongoDbStatus = {
13
+ mongodb: DbStatusByType;
14
+ };
15
+ //#endregion
16
+ export { DbConnectionStatus, DbStatusByType, MongoDbStatus };
@@ -1,12 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DbConnectionStatus = void 0;
4
- var DbConnectionStatus;
5
- (function (DbConnectionStatus) {
6
- DbConnectionStatus["Disconnected"] = "disconnected";
7
- DbConnectionStatus["Connected"] = "connected";
8
- DbConnectionStatus["Connecting"] = "connecting";
9
- DbConnectionStatus["Disconnecting"] = "disconnecting";
10
- DbConnectionStatus["OpFailed"] = "op_failed";
11
- })(DbConnectionStatus || (exports.DbConnectionStatus = DbConnectionStatus = {}));
12
- //# sourceMappingURL=mongoStatus.js.map
1
+ //#region src/interfaces/mongoStatus.ts
2
+ let DbConnectionStatus = /* @__PURE__ */ function(DbConnectionStatus) {
3
+ DbConnectionStatus["Disconnected"] = "disconnected";
4
+ DbConnectionStatus["Connected"] = "connected";
5
+ DbConnectionStatus["Connecting"] = "connecting";
6
+ DbConnectionStatus["Disconnecting"] = "disconnecting";
7
+ DbConnectionStatus["OpFailed"] = "op_failed";
8
+ return DbConnectionStatus;
9
+ }({});
10
+ //#endregion
11
+ export { DbConnectionStatus };