@aneuhold/be-ts-db-lib 1.0.7 → 1.0.8
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/README.md +21 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/repositories/BaseRepository.d.ts +21 -1
- package/lib/repositories/BaseRepository.d.ts.map +1 -1
- package/lib/repositories/BaseRepository.js +57 -1
- package/lib/repositories/common/ApiKeyRepository.d.ts +5 -6
- package/lib/repositories/common/ApiKeyRepository.d.ts.map +1 -1
- package/lib/repositories/common/ApiKeyRepository.js +21 -9
- package/lib/repositories/common/UserRepository.d.ts +1 -32
- package/lib/repositories/common/UserRepository.d.ts.map +1 -1
- package/lib/repositories/common/UserRepository.js +5 -63
- package/lib/repositories/dashboard/DashboardUserConfigRepository.d.ts +17 -0
- package/lib/repositories/dashboard/DashboardUserConfigRepository.d.ts.map +1 -0
- package/lib/repositories/dashboard/DashboardUserConfigRepository.js +48 -0
- package/lib/scripts/migrate.d.ts +2 -0
- package/lib/scripts/migrate.d.ts.map +1 -0
- package/lib/scripts/migrate.js +7 -0
- package/lib/scripts/migrateDry.d.ts +2 -0
- package/lib/scripts/migrateDry.d.ts.map +1 -0
- package/lib/scripts/migrateDry.js +7 -0
- package/lib/scripts/validateSchema.d.ts +2 -0
- package/lib/scripts/validateSchema.d.ts.map +1 -0
- package/lib/scripts/validateSchema.js +9 -0
- package/lib/scripts/validateSchemaDryRun.d.ts +2 -0
- package/lib/scripts/validateSchemaDryRun.d.ts.map +1 -0
- package/lib/scripts/validateSchemaDryRun.js +9 -0
- package/lib/services/MigrationService.d.ts +20 -0
- package/lib/services/MigrationService.d.ts.map +1 -0
- package/lib/services/MigrationService.js +57 -0
- package/lib/services/RepoSubscriptionService.d.ts +30 -0
- package/lib/services/RepoSubscriptionService.d.ts.map +1 -0
- package/lib/services/RepoSubscriptionService.js +21 -0
- package/lib/tests/repositories/BaseRepository.spec.js +4 -4
- package/lib/tests/repositories/common/UserRepository.spec.js +9 -10
- package/lib/tests/repositories/dashboard/UserConfigRepository.spec.js +3 -3
- package/lib/tests/testsUtil.d.ts +9 -0
- package/lib/tests/testsUtil.d.ts.map +1 -1
- package/lib/tests/testsUtil.js +19 -1
- package/lib/util/DbSchemaUpdater.d.ts +7 -0
- package/lib/util/DbSchemaUpdater.d.ts.map +1 -0
- package/lib/util/DbSchemaUpdater.js +19 -0
- package/lib/util/DocumentCleaner.d.ts +2 -2
- package/lib/util/DocumentCleaner.d.ts.map +1 -1
- package/lib/validators/BaseValidator.d.ts +36 -1
- package/lib/validators/BaseValidator.d.ts.map +1 -1
- package/lib/validators/BaseValidator.js +74 -0
- package/lib/validators/common/ApiKeyValidator.d.ts +1 -0
- package/lib/validators/common/ApiKeyValidator.d.ts.map +1 -1
- package/lib/validators/common/ApiKeyValidator.js +25 -0
- package/lib/validators/common/UserValidator.d.ts +1 -0
- package/lib/validators/common/UserValidator.d.ts.map +1 -1
- package/lib/validators/common/UserValidator.js +24 -0
- package/lib/validators/dashboard/UserConfigValidator.d.ts +1 -0
- package/lib/validators/dashboard/UserConfigValidator.d.ts.map +1 -1
- package/lib/validators/dashboard/UserConfigValidator.js +27 -2
- package/package.json +9 -5
|
@@ -3,14 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const core_ts_db_lib_1 = require("@aneuhold/core-ts-db-lib");
|
|
6
7
|
const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
|
|
7
8
|
const BaseValidator_1 = __importDefault(require("../BaseValidator"));
|
|
8
|
-
const
|
|
9
|
+
const DashboardUserConfigRepository_1 = __importDefault(require("../../repositories/dashboard/DashboardUserConfigRepository"));
|
|
9
10
|
const UserRepository_1 = __importDefault(require("../../repositories/common/UserRepository"));
|
|
10
11
|
class DashboardUserConfigValidator extends BaseValidator_1.default {
|
|
11
12
|
async validateNewObject(newUserConfig) {
|
|
12
13
|
// Check if the config already exists for the user
|
|
13
|
-
const configRepo =
|
|
14
|
+
const configRepo = DashboardUserConfigRepository_1.default.getRepo();
|
|
14
15
|
const existingConfig = await configRepo.get({
|
|
15
16
|
userId: newUserConfig.userId
|
|
16
17
|
});
|
|
@@ -29,5 +30,29 @@ class DashboardUserConfigValidator extends BaseValidator_1.default {
|
|
|
29
30
|
core_ts_lib_1.ErrorUtils.throwError(`No _id defined for DashboardUserConfig update.`, updatedUserConfig);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
33
|
+
async validateRepositoryInDb(dryRun) {
|
|
34
|
+
const userConfigRepo = DashboardUserConfigRepository_1.default.getRepo();
|
|
35
|
+
const allUserConfigs = await userConfigRepo.getAll();
|
|
36
|
+
const allUserIds = await UserRepository_1.default.getRepo().getAllIdsAsHash();
|
|
37
|
+
await this.runStandardValidationForRepository({
|
|
38
|
+
dryRun,
|
|
39
|
+
docName: 'Dashboard User Config',
|
|
40
|
+
allDocs: allUserConfigs,
|
|
41
|
+
shouldDelete: (userConfig) => {
|
|
42
|
+
if (!allUserIds[userConfig.userId.toString()]) {
|
|
43
|
+
core_ts_lib_1.Logger.error(`Dashboard User Config with ID: ${userConfig._id} has no valid associated user.`);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
},
|
|
48
|
+
documentValidator: core_ts_db_lib_1.validateDashboardUserConfig,
|
|
49
|
+
deletionFunction: async (docIdsToDelete) => {
|
|
50
|
+
await userConfigRepo.deleteList(docIdsToDelete);
|
|
51
|
+
},
|
|
52
|
+
updateFunction: async (docsToUpdate) => {
|
|
53
|
+
await userConfigRepo.updateMany(docsToUpdate);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
32
57
|
}
|
|
33
58
|
exports.default = DashboardUserConfigValidator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aneuhold/be-ts-db-lib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "A backend database library meant to actually interact with various databases in personal projects",
|
|
5
5
|
"author": "Anton G Neuhold Jr <agneuhold@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,12 +33,16 @@
|
|
|
33
33
|
"unlink:bets": "yarn unlink @aneuhold/be-ts-lib && yarn install --force",
|
|
34
34
|
"upgrade:all": "yarn upgrade --latest",
|
|
35
35
|
"upgrade:core": "yarn upgrade --latest --pattern @aneuhold",
|
|
36
|
-
"test": "jest"
|
|
36
|
+
"test": "jest && yarn validate:dry",
|
|
37
|
+
"validate": "ts-node ./src/scripts/validateSchema.ts",
|
|
38
|
+
"validate:dry": "ts-node ./src/scripts/validateSchemaDryRun.ts",
|
|
39
|
+
"migrate": "ts-node ./src/scripts/migrate.ts",
|
|
40
|
+
"migrate:dry": "ts-node ./src/scripts/migrateDry.ts"
|
|
37
41
|
},
|
|
38
42
|
"dependencies": {
|
|
39
|
-
"@aneuhold/be-ts-lib": "^1.0.
|
|
40
|
-
"@aneuhold/core-ts-db-lib": "^1.0.
|
|
41
|
-
"@aneuhold/core-ts-lib": "^1.1.
|
|
43
|
+
"@aneuhold/be-ts-lib": "^1.0.6",
|
|
44
|
+
"@aneuhold/core-ts-db-lib": "^1.0.13",
|
|
45
|
+
"@aneuhold/core-ts-lib": "^1.1.9",
|
|
42
46
|
"bson": "^6.2.0",
|
|
43
47
|
"mongodb": "^6.3.0"
|
|
44
48
|
},
|