@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.
- package/dist/_virtual/_rolldown/runtime.js +27 -0
- package/dist/cli/cleanupExpiredData.js +83 -136
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +85 -100
- package/dist/cli/runMigration.js +64 -105
- package/dist/cli/syncIndexes.js +38 -77
- package/dist/index.d.ts +28 -0
- package/dist/index.js +23 -22
- package/dist/interfaces/database.d.ts +10 -0
- package/dist/interfaces/dbConfig.d.ts +37 -0
- package/dist/interfaces/dbConfig.js +8 -9
- package/dist/interfaces/errors.d.ts +43 -0
- package/dist/interfaces/errors.js +42 -50
- package/dist/interfaces/index.d.ts +15 -0
- package/dist/interfaces/index.js +11 -25
- package/dist/interfaces/metrics.d.ts +22 -0
- package/dist/interfaces/metrics.js +38 -19
- package/dist/interfaces/migrateMongoConfig.d.ts +17 -0
- package/dist/interfaces/models/counter.d.ts +8 -0
- package/dist/interfaces/models/encryptedStorage.d.ts +9 -0
- package/dist/interfaces/mongoStatus.d.ts +16 -0
- package/dist/interfaces/mongoStatus.js +11 -12
- package/dist/mongo.d.ts +12 -0
- package/dist/mongo.js +71 -89
- package/dist/postgres.d.ts +4 -0
- package/dist/postgres.js +5 -19
- package/dist/postgresUtils.d.ts +8 -0
- package/dist/postgresUtils.js +14 -18
- package/dist/schemas/counter.d.ts +7 -0
- package/dist/schemas/counter.js +19 -14
- package/dist/schemas/encryptedStorage.d.ts +7 -0
- package/dist/schemas/encryptedStorage.js +17 -15
- package/dist/schemas/index.d.ts +3 -0
- package/dist/schemas/index.js +4 -20
- package/dist/schemas/statusHistoryItem.d.ts +7 -0
- package/dist/schemas/statusHistoryItem.js +16 -10
- package/dist/services/counter.d.ts +19 -0
- package/dist/services/counter.js +70 -72
- package/dist/services/database.d.ts +50 -0
- package/dist/services/database.js +255 -281
- package/dist/services/encryptedStorage.d.ts +73 -0
- package/dist/services/encryptedStorage.js +178 -214
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +5 -21
- package/dist/services/postgresDatabase.d.ts +12 -0
- package/dist/services/postgresDatabase.js +20 -25
- package/dist/tables/counter.d.ts +4 -0
- package/dist/tables/counter.js +11 -12
- package/dist/tables/encryptedStorage.d.ts +4 -0
- package/dist/tables/encryptedStorage.js +12 -13
- package/dist/tables/index.d.ts +9 -0
- package/dist/tables/index.js +3 -19
- package/package.json +47 -48
- package/dist/cli/cleanupExpiredData.js.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/runMigration.js.map +0 -1
- package/dist/cli/syncIndexes.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interfaces/database.js +0 -3
- package/dist/interfaces/database.js.map +0 -1
- package/dist/interfaces/dbConfig.js.map +0 -1
- package/dist/interfaces/errors.js.map +0 -1
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/metrics.js.map +0 -1
- package/dist/interfaces/migrateMongoConfig.js +0 -3
- package/dist/interfaces/migrateMongoConfig.js.map +0 -1
- package/dist/interfaces/models/counter.js +0 -3
- package/dist/interfaces/models/counter.js.map +0 -1
- package/dist/interfaces/models/encryptedStorage.js +0 -3
- package/dist/interfaces/models/encryptedStorage.js.map +0 -1
- package/dist/interfaces/models/index.js +0 -19
- package/dist/interfaces/models/index.js.map +0 -1
- package/dist/interfaces/mongoStatus.js.map +0 -1
- package/dist/mongo.js.map +0 -1
- package/dist/postgres.js.map +0 -1
- package/dist/postgresUtils.js.map +0 -1
- package/dist/schemas/counter.js.map +0 -1
- package/dist/schemas/encryptedStorage.js.map +0 -1
- package/dist/schemas/index.js.map +0 -1
- package/dist/schemas/statusHistoryItem.js.map +0 -1
- package/dist/services/counter.js.map +0 -1
- package/dist/services/database.js.map +0 -1
- package/dist/services/encryptedStorage.js.map +0 -1
- package/dist/services/index.js.map +0 -1
- package/dist/services/postgresDatabase.js.map +0 -1
- package/dist/tables/counter.js.map +0 -1
- package/dist/tables/encryptedStorage.js.map +0 -1
- package/dist/tables/index.js.map +0 -1
- package/dist/types/cli/cleanupExpiredData.d.ts +0 -11
- package/dist/types/cli/index.d.ts +0 -2
- package/dist/types/cli/runMigration.d.ts +0 -11
- package/dist/types/cli/syncIndexes.d.ts +0 -7
- package/dist/types/index.d.ts +0 -5
- package/dist/types/interfaces/database.d.ts +0 -8
- package/dist/types/interfaces/dbConfig.d.ts +0 -33
- package/dist/types/interfaces/errors.d.ts +0 -40
- package/dist/types/interfaces/index.d.ts +0 -8
- package/dist/types/interfaces/metrics.d.ts +0 -20
- package/dist/types/interfaces/migrateMongoConfig.d.ts +0 -13
- package/dist/types/interfaces/models/counter.d.ts +0 -5
- package/dist/types/interfaces/models/encryptedStorage.d.ts +0 -6
- package/dist/types/interfaces/models/index.d.ts +0 -2
- package/dist/types/interfaces/mongoStatus.d.ts +0 -12
- package/dist/types/mongo.d.ts +0 -9
- package/dist/types/postgres.d.ts +0 -2
- package/dist/types/postgresUtils.d.ts +0 -26
- package/dist/types/schemas/counter.d.ts +0 -12
- package/dist/types/schemas/encryptedStorage.d.ts +0 -12
- package/dist/types/schemas/index.d.ts +0 -3
- package/dist/types/schemas/statusHistoryItem.d.ts +0 -3
- package/dist/types/services/counter.d.ts +0 -15
- package/dist/types/services/database.d.ts +0 -43
- package/dist/types/services/encryptedStorage.d.ts +0 -69
- package/dist/types/services/index.d.ts +0 -4
- package/dist/types/services/postgresDatabase.d.ts +0 -8
- package/dist/types/tables/counter.d.ts +0 -94
- package/dist/types/tables/encryptedStorage.d.ts +0 -111
- package/dist/types/tables/index.d.ts +0 -2
package/dist/cli/syncIndexes.js
CHANGED
|
@@ -1,78 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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 };
|
package/dist/index.d.ts
ADDED
|
@@ -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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
//#
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
2
|
-
/*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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 };
|
package/dist/interfaces/index.js
CHANGED
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
//#
|
|
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,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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 };
|