@aneuhold/be-ts-db-lib 1.0.115 → 2.0.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/LICENSE +21 -0
- package/README.md +46 -10
- package/lib/index.d.ts +8 -8
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +10 -20
- package/lib/index.js.map +1 -0
- package/lib/index.ts +21 -0
- package/lib/repositories/BaseRepository.d.ts +84 -11
- package/lib/repositories/BaseRepository.d.ts.map +1 -1
- package/lib/repositories/BaseRepository.js +89 -21
- package/lib/repositories/BaseRepository.js.map +1 -0
- package/lib/repositories/BaseRepository.ts +339 -0
- package/lib/repositories/common/ApiKeyRepository.d.ts +2 -2
- package/lib/repositories/common/ApiKeyRepository.d.ts.map +1 -1
- package/lib/repositories/common/ApiKeyRepository.js +8 -13
- package/lib/repositories/common/ApiKeyRepository.js.map +1 -0
- package/lib/repositories/common/ApiKeyRepository.ts +55 -0
- package/lib/repositories/common/UserRepository.d.ts +1 -1
- package/lib/repositories/common/UserRepository.d.ts.map +1 -1
- package/lib/repositories/common/UserRepository.js +15 -20
- package/lib/repositories/common/UserRepository.js.map +1 -0
- package/lib/repositories/common/UserRepository.ts +65 -0
- package/lib/repositories/dashboard/DashboardBaseRepository.d.ts +2 -2
- package/lib/repositories/dashboard/DashboardBaseRepository.d.ts.map +1 -1
- package/lib/repositories/dashboard/DashboardBaseRepository.js +6 -11
- package/lib/repositories/dashboard/DashboardBaseRepository.js.map +1 -0
- package/lib/repositories/dashboard/DashboardBaseRepository.ts +31 -0
- package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.d.ts +2 -2
- package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.d.ts.map +1 -1
- package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.js +7 -12
- package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.js.map +1 -0
- package/lib/repositories/dashboard/DashboardNonogramKatanaItemRepository.ts +64 -0
- package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.d.ts +2 -2
- package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.d.ts.map +1 -1
- package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js +7 -12
- package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js.map +1 -0
- package/lib/repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.ts +66 -0
- package/lib/repositories/dashboard/DashboardTaskRepository.d.ts +17 -4
- package/lib/repositories/dashboard/DashboardTaskRepository.d.ts.map +1 -1
- package/lib/repositories/dashboard/DashboardTaskRepository.js +26 -18
- package/lib/repositories/dashboard/DashboardTaskRepository.js.map +1 -0
- package/lib/repositories/dashboard/DashboardTaskRepository.ts +166 -0
- package/lib/repositories/dashboard/DashboardUserConfigRepository.d.ts +29 -5
- package/lib/repositories/dashboard/DashboardUserConfigRepository.d.ts.map +1 -1
- package/lib/repositories/dashboard/DashboardUserConfigRepository.js +38 -19
- package/lib/repositories/dashboard/DashboardUserConfigRepository.js.map +1 -0
- package/lib/repositories/dashboard/DashboardUserConfigRepository.ts +254 -0
- package/lib/services/MigrationService.d.ts.map +1 -1
- package/lib/services/MigrationService.js +10 -15
- package/lib/services/MigrationService.js.map +1 -0
- package/lib/services/MigrationService.ts +52 -0
- package/lib/services/RepoSubscriptionService.d.ts.map +1 -1
- package/lib/services/RepoSubscriptionService.js +2 -4
- package/lib/services/RepoSubscriptionService.js.map +1 -0
- package/lib/services/RepoSubscriptionService.ts +63 -0
- package/lib/tests/globalTestVariables.d.ts +5 -0
- package/lib/tests/globalTestVariables.d.ts.map +1 -0
- package/lib/tests/globalTestVariables.js +5 -0
- package/lib/tests/globalTestVariables.js.map +1 -0
- package/lib/tests/globalTestVariables.ts +4 -0
- package/lib/tests/repositories/BaseRepository.spec.ts +61 -0
- package/lib/tests/repositories/common/UserRepository.spec.ts +113 -0
- package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.ts +55 -0
- package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.ts +14 -0
- package/lib/tests/repositories/dashboard/TaskRepository.spec.ts +101 -0
- package/lib/tests/repositories/dashboard/UserConfigRepository.spec.ts +155 -0
- package/lib/tests/testsUtil.d.ts +20 -4
- package/lib/tests/testsUtil.d.ts.map +1 -1
- package/lib/tests/testsUtil.js +29 -20
- package/lib/tests/testsUtil.js.map +1 -0
- package/lib/tests/testsUtil.ts +68 -0
- package/lib/util/DbSchemaUpdater.d.ts.map +1 -1
- package/lib/util/DbSchemaUpdater.js +10 -15
- package/lib/util/DbSchemaUpdater.js.map +1 -0
- package/lib/util/DbSchemaUpdater.ts +16 -0
- package/lib/util/DocumentCleaner.d.ts.map +1 -1
- package/lib/util/DocumentCleaner.js +2 -4
- package/lib/util/DocumentCleaner.js.map +1 -0
- package/lib/util/DocumentCleaner.ts +31 -0
- package/lib/util/DocumentDb.d.ts +4 -1
- package/lib/util/DocumentDb.d.ts.map +1 -1
- package/lib/util/DocumentDb.js +11 -10
- package/lib/util/DocumentDb.js.map +1 -0
- package/lib/util/DocumentDb.ts +47 -0
- package/lib/validators/BaseValidator.d.ts +11 -0
- package/lib/validators/BaseValidator.d.ts.map +1 -1
- package/lib/validators/BaseValidator.js +26 -18
- package/lib/validators/BaseValidator.js.map +1 -0
- package/lib/validators/BaseValidator.ts +150 -0
- package/lib/validators/common/ApiKeyValidator.d.ts +1 -1
- package/lib/validators/common/ApiKeyValidator.d.ts.map +1 -1
- package/lib/validators/common/ApiKeyValidator.js +16 -21
- package/lib/validators/common/ApiKeyValidator.js.map +1 -0
- package/lib/validators/common/ApiKeyValidator.ts +67 -0
- package/lib/validators/common/UserValidator.d.ts +14 -1
- package/lib/validators/common/UserValidator.d.ts.map +1 -1
- package/lib/validators/common/UserValidator.js +29 -21
- package/lib/validators/common/UserValidator.js.map +1 -0
- package/lib/validators/common/UserValidator.ts +98 -0
- package/lib/validators/dashboard/NonogramKatanaItemValidator.d.ts +1 -1
- package/lib/validators/dashboard/NonogramKatanaItemValidator.d.ts.map +1 -1
- package/lib/validators/dashboard/NonogramKatanaItemValidator.js +16 -21
- package/lib/validators/dashboard/NonogramKatanaItemValidator.js.map +1 -0
- package/lib/validators/dashboard/NonogramKatanaItemValidator.ts +78 -0
- package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.d.ts +1 -1
- package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.d.ts.map +1 -1
- package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.js +16 -21
- package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.js.map +1 -0
- package/lib/validators/dashboard/NonogramKatanaUpgradeValidator.ts +78 -0
- package/lib/validators/dashboard/TaskValidator.d.ts +1 -1
- package/lib/validators/dashboard/TaskValidator.d.ts.map +1 -1
- package/lib/validators/dashboard/TaskValidator.js +15 -20
- package/lib/validators/dashboard/TaskValidator.js.map +1 -0
- package/lib/validators/dashboard/TaskValidator.ts +105 -0
- package/lib/validators/dashboard/UserConfigValidator.d.ts +1 -1
- package/lib/validators/dashboard/UserConfigValidator.d.ts.map +1 -1
- package/lib/validators/dashboard/UserConfigValidator.js +19 -24
- package/lib/validators/dashboard/UserConfigValidator.js.map +1 -0
- package/lib/validators/dashboard/UserConfigValidator.ts +112 -0
- package/package.json +44 -38
- package/lib/scripts/migrate.d.ts +0 -2
- package/lib/scripts/migrate.d.ts.map +0 -1
- package/lib/scripts/migrate.js +0 -7
- package/lib/scripts/migrateDry.d.ts +0 -2
- package/lib/scripts/migrateDry.d.ts.map +0 -1
- package/lib/scripts/migrateDry.js +0 -7
- package/lib/scripts/validateSchema.d.ts +0 -2
- package/lib/scripts/validateSchema.d.ts.map +0 -1
- package/lib/scripts/validateSchema.js +0 -9
- package/lib/scripts/validateSchemaDryRun.d.ts +0 -2
- package/lib/scripts/validateSchemaDryRun.d.ts.map +0 -1
- package/lib/scripts/validateSchemaDryRun.js +0 -9
- package/lib/tests/repositories/BaseRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/BaseRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/BaseRepository.spec.js +0 -52
- package/lib/tests/repositories/common/UserRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/common/UserRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/common/UserRepository.spec.js +0 -108
- package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/dashboard/NonogramKatanaItemRepository.spec.js +0 -39
- package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/dashboard/NonogramKatanaUpgradeRepository.spec.js +0 -16
- package/lib/tests/repositories/dashboard/TaskRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/dashboard/TaskRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/dashboard/TaskRepository.spec.js +0 -84
- package/lib/tests/repositories/dashboard/UserConfigRepository.spec.d.ts +0 -2
- package/lib/tests/repositories/dashboard/UserConfigRepository.spec.d.ts.map +0 -1
- package/lib/tests/repositories/dashboard/UserConfigRepository.spec.js +0 -115
package/lib/tests/testsUtil.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TEST_USER_NAME_PREFIX = void 0;
|
|
7
|
-
exports.expectToThrow = expectToThrow;
|
|
8
|
-
exports.getTestUserName = getTestUserName;
|
|
9
|
-
exports.cleanupDoc = cleanupDoc;
|
|
10
|
-
exports.cleanupDocs = cleanupDocs;
|
|
11
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import { expect } from 'vitest';
|
|
3
|
+
import { TEST_USER_NAME_PREFIX } from './globalTestVariables.js';
|
|
12
4
|
/**
|
|
13
|
-
*
|
|
5
|
+
* Asserts that the provided asynchronous function throws an error.
|
|
6
|
+
*
|
|
7
|
+
* @param func - The asynchronous function expected to throw an error.
|
|
14
8
|
*/
|
|
15
|
-
|
|
16
|
-
async function expectToThrow(func) {
|
|
9
|
+
export async function expectToThrow(func) {
|
|
17
10
|
let threwError = false;
|
|
18
11
|
try {
|
|
19
12
|
await func();
|
|
@@ -26,25 +19,41 @@ async function expectToThrow(func) {
|
|
|
26
19
|
/**
|
|
27
20
|
* Gets a test user name with a standardized prefix so that they can all be
|
|
28
21
|
* identified and deleted if anything goes wrong in the tests.
|
|
22
|
+
*
|
|
23
|
+
* @param username - The username to use as a base for the test user name.
|
|
24
|
+
* @returns The test user name.
|
|
29
25
|
*/
|
|
30
|
-
function getTestUserName(username) {
|
|
26
|
+
export function getTestUserName(username) {
|
|
31
27
|
if (!username)
|
|
32
|
-
return `${
|
|
33
|
-
return `${
|
|
28
|
+
return `${TEST_USER_NAME_PREFIX}-${crypto.randomUUID()}`;
|
|
29
|
+
return `${TEST_USER_NAME_PREFIX}-${username}`;
|
|
34
30
|
}
|
|
35
31
|
/**
|
|
36
|
-
*
|
|
32
|
+
* Cleans up a document by deleting it from the repository and verifying its deletion.
|
|
33
|
+
*
|
|
34
|
+
* @template TDocType - The type of the document extending {@link BaseDocument}.
|
|
35
|
+
* @param repo - The repository from which the document will be deleted.
|
|
36
|
+
* @param doc - The document to be deleted.
|
|
37
37
|
*/
|
|
38
|
-
async function cleanupDoc(repo, doc) {
|
|
38
|
+
export async function cleanupDoc(repo, doc) {
|
|
39
39
|
const deleteResult = await repo.delete(doc._id);
|
|
40
40
|
expect(deleteResult.acknowledged).toBeTruthy();
|
|
41
41
|
const findResult = await repo.get({ _id: doc._id });
|
|
42
42
|
expect(findResult).toBeNull();
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Cleans up the specified documents from the repository.
|
|
46
|
+
*
|
|
47
|
+
* @template TDocType - The type of the documents.
|
|
48
|
+
* @param repo - The repository from which to delete the documents.
|
|
49
|
+
* @param docs - The documents to be deleted.
|
|
50
|
+
* @returns A promise that resolves when the cleanup is complete.
|
|
51
|
+
*/
|
|
52
|
+
export async function cleanupDocs(repo, docs) {
|
|
45
53
|
const idsToDelete = docs.map((doc) => doc._id);
|
|
46
54
|
const deleteResult = await repo.deleteList(idsToDelete);
|
|
47
55
|
expect(deleteResult.acknowledged).toBeTruthy();
|
|
48
56
|
const findResult = await repo.getList(idsToDelete);
|
|
49
57
|
expect(findResult.length).toBe(0);
|
|
50
58
|
}
|
|
59
|
+
//# sourceMappingURL=testsUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testsUtil.js","sourceRoot":"./src/","sources":["tests/testsUtil.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAyB;IAC3D,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,IAAI,CAAC;QACH,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;IAAC,MAAM,CAAC;QACP,UAAU,GAAG,IAAI,CAAC;IACpB,CAAC;IACD,MAAM,CAAC,UAAU,CAAC,CAAC,UAAU,EAAE,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,QAAiB;IAC/C,IAAI,CAAC,QAAQ;QAAE,OAAO,GAAG,qBAAqB,IAAI,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC;IACxE,OAAO,GAAG,qBAAqB,IAAI,QAAQ,EAAE,CAAC;AAChD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,IAA8B,EAC9B,GAAa;IAEb,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChD,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,UAAU,EAAE,CAAC;IAC/C,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAuB,CAAC,CAAC;IACzE,MAAM,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC;AAChC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAA8B,EAC9B,IAAgB;IAEhB,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IACxD,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,UAAU,EAAE,CAAC;IAC/C,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACnD,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { BaseDocument } from '@aneuhold/core-ts-db-lib';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
import { expect } from 'vitest';
|
|
4
|
+
import BaseRepository from '../repositories/BaseRepository.js';
|
|
5
|
+
import { TEST_USER_NAME_PREFIX } from './globalTestVariables.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Asserts that the provided asynchronous function throws an error.
|
|
9
|
+
*
|
|
10
|
+
* @param func - The asynchronous function expected to throw an error.
|
|
11
|
+
*/
|
|
12
|
+
export async function expectToThrow(func: () => Promise<void>) {
|
|
13
|
+
let threwError = false;
|
|
14
|
+
try {
|
|
15
|
+
await func();
|
|
16
|
+
} catch {
|
|
17
|
+
threwError = true;
|
|
18
|
+
}
|
|
19
|
+
expect(threwError).toBeTruthy();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Gets a test user name with a standardized prefix so that they can all be
|
|
24
|
+
* identified and deleted if anything goes wrong in the tests.
|
|
25
|
+
*
|
|
26
|
+
* @param username - The username to use as a base for the test user name.
|
|
27
|
+
* @returns The test user name.
|
|
28
|
+
*/
|
|
29
|
+
export function getTestUserName(username?: string): string {
|
|
30
|
+
if (!username) return `${TEST_USER_NAME_PREFIX}-${crypto.randomUUID()}`;
|
|
31
|
+
return `${TEST_USER_NAME_PREFIX}-${username}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Cleans up a document by deleting it from the repository and verifying its deletion.
|
|
36
|
+
*
|
|
37
|
+
* @template TDocType - The type of the document extending {@link BaseDocument}.
|
|
38
|
+
* @param repo - The repository from which the document will be deleted.
|
|
39
|
+
* @param doc - The document to be deleted.
|
|
40
|
+
*/
|
|
41
|
+
export async function cleanupDoc<TDocType extends BaseDocument>(
|
|
42
|
+
repo: BaseRepository<TDocType>,
|
|
43
|
+
doc: TDocType
|
|
44
|
+
) {
|
|
45
|
+
const deleteResult = await repo.delete(doc._id);
|
|
46
|
+
expect(deleteResult.acknowledged).toBeTruthy();
|
|
47
|
+
const findResult = await repo.get({ _id: doc._id } as Partial<TDocType>);
|
|
48
|
+
expect(findResult).toBeNull();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Cleans up the specified documents from the repository.
|
|
53
|
+
*
|
|
54
|
+
* @template TDocType - The type of the documents.
|
|
55
|
+
* @param repo - The repository from which to delete the documents.
|
|
56
|
+
* @param docs - The documents to be deleted.
|
|
57
|
+
* @returns A promise that resolves when the cleanup is complete.
|
|
58
|
+
*/
|
|
59
|
+
export async function cleanupDocs<TDocType extends BaseDocument>(
|
|
60
|
+
repo: BaseRepository<TDocType>,
|
|
61
|
+
docs: TDocType[]
|
|
62
|
+
) {
|
|
63
|
+
const idsToDelete = docs.map((doc) => doc._id);
|
|
64
|
+
const deleteResult = await repo.deleteList(idsToDelete);
|
|
65
|
+
expect(deleteResult.acknowledged).toBeTruthy();
|
|
66
|
+
const findResult = await repo.getList(idsToDelete);
|
|
67
|
+
expect(findResult.length).toBe(0);
|
|
68
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DbSchemaUpdater.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"DbSchemaUpdater.d.ts","sourceRoot":"./src/","sources":["util/DbSchemaUpdater.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;WACrB,uBAAuB,CAAC,MAAM,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAMpE"}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const ApiKeyValidator_1 = __importDefault(require("../validators/common/ApiKeyValidator"));
|
|
7
|
-
const UserValidator_1 = __importDefault(require("../validators/common/UserValidator"));
|
|
8
|
-
const TaskValidator_1 = __importDefault(require("../validators/dashboard/TaskValidator"));
|
|
9
|
-
const UserConfigValidator_1 = __importDefault(require("../validators/dashboard/UserConfigValidator"));
|
|
1
|
+
import ApiKeyValidator from '../validators/common/ApiKeyValidator.js';
|
|
2
|
+
import UserValidator from '../validators/common/UserValidator.js';
|
|
3
|
+
import DashboardTaskValidator from '../validators/dashboard/TaskValidator.js';
|
|
4
|
+
import DashboardUserConfigValidator from '../validators/dashboard/UserConfigValidator.js';
|
|
10
5
|
/**
|
|
11
6
|
* A class that can be used to validate and update the DB and all repositories.
|
|
12
7
|
*/
|
|
13
|
-
class DbSchemaUpdater {
|
|
8
|
+
export default class DbSchemaUpdater {
|
|
14
9
|
static async updateSchemaForAllRepos(dryRun = false) {
|
|
15
|
-
await new
|
|
16
|
-
await new
|
|
17
|
-
await new
|
|
18
|
-
await new
|
|
10
|
+
await new UserValidator().validateRepositoryInDb(dryRun);
|
|
11
|
+
await new ApiKeyValidator().validateRepositoryInDb(dryRun);
|
|
12
|
+
await new DashboardUserConfigValidator().validateRepositoryInDb(dryRun);
|
|
13
|
+
await new DashboardTaskValidator().validateRepositoryInDb(dryRun);
|
|
19
14
|
}
|
|
20
15
|
}
|
|
21
|
-
|
|
16
|
+
//# sourceMappingURL=DbSchemaUpdater.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DbSchemaUpdater.js","sourceRoot":"./src/","sources":["util/DbSchemaUpdater.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,yCAAyC,CAAC;AACtE,OAAO,aAAa,MAAM,uCAAuC,CAAC;AAClE,OAAO,sBAAsB,MAAM,0CAA0C,CAAC;AAC9E,OAAO,4BAA4B,MAAM,gDAAgD,CAAC;AAE1F;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,MAAM,GAAG,KAAK;QACjD,MAAM,IAAI,aAAa,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QACzD,MAAM,IAAI,eAAe,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAC3D,MAAM,IAAI,4BAA4B,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QACxE,MAAM,IAAI,sBAAsB,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;IACpE,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ApiKeyValidator from '../validators/common/ApiKeyValidator.js';
|
|
2
|
+
import UserValidator from '../validators/common/UserValidator.js';
|
|
3
|
+
import DashboardTaskValidator from '../validators/dashboard/TaskValidator.js';
|
|
4
|
+
import DashboardUserConfigValidator from '../validators/dashboard/UserConfigValidator.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A class that can be used to validate and update the DB and all repositories.
|
|
8
|
+
*/
|
|
9
|
+
export default class DbSchemaUpdater {
|
|
10
|
+
static async updateSchemaForAllRepos(dryRun = false): Promise<void> {
|
|
11
|
+
await new UserValidator().validateRepositoryInDb(dryRun);
|
|
12
|
+
await new ApiKeyValidator().validateRepositoryInDb(dryRun);
|
|
13
|
+
await new DashboardUserConfigValidator().validateRepositoryInDb(dryRun);
|
|
14
|
+
await new DashboardTaskValidator().validateRepositoryInDb(dryRun);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentCleaner.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"DocumentCleaner.d.ts","sourceRoot":"./src/","sources":["util/DocumentCleaner.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACf,MAAM,0BAA0B,CAAC;AAElC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,MAAM,CAAC,EAAE,CAAC,QAAQ,SAAS,YAAY,EAAE,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC;IAMrE,MAAM,CAAC,MAAM,CAAC,QAAQ,SAAS,cAAc,EAAE,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC;IAM3E,MAAM,CAAC,OAAO,CAAC,QAAQ,SAAS,oBAAoB,EAClD,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC;CAM/B"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* A class which contains some standard methods for cleaning update documents
|
|
5
3
|
* before they are sent to the database.
|
|
6
4
|
*/
|
|
7
|
-
class CleanDocument {
|
|
5
|
+
export default class CleanDocument {
|
|
8
6
|
static id(updateDoc) {
|
|
9
7
|
const docCopy = { ...updateDoc };
|
|
10
8
|
delete docCopy._id;
|
|
@@ -21,4 +19,4 @@ class CleanDocument {
|
|
|
21
19
|
return docCopy;
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
|
-
|
|
22
|
+
//# sourceMappingURL=DocumentCleaner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentCleaner.js","sourceRoot":"./src/","sources":["util/DocumentCleaner.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,MAAM,CAAC,EAAE,CAAgC,SAA4B;QACnE,MAAM,OAAO,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC;QACjC,OAAO,OAAO,CAAC,GAAG,CAAC;QACnB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,MAAM,CAAkC,SAA4B;QACzE,MAAM,OAAO,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC;QACjC,OAAO,OAAO,CAAC,MAAM,CAAC;QACtB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,CAAC,OAAO,CACZ,SAA4B;QAE5B,MAAM,OAAO,GAAG,EAAE,GAAG,SAAS,EAAE,CAAC;QACjC,OAAO,OAAO,CAAC,OAAO,CAAC;QACvB,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseDocument,
|
|
3
|
+
BaseDocumentWithType,
|
|
4
|
+
RequiredUserId
|
|
5
|
+
} from '@aneuhold/core-ts-db-lib';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A class which contains some standard methods for cleaning update documents
|
|
9
|
+
* before they are sent to the database.
|
|
10
|
+
*/
|
|
11
|
+
export default class CleanDocument {
|
|
12
|
+
static id<TDocType extends BaseDocument>(updateDoc: Partial<TDocType>) {
|
|
13
|
+
const docCopy = { ...updateDoc };
|
|
14
|
+
delete docCopy._id;
|
|
15
|
+
return docCopy;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static userId<TDocType extends RequiredUserId>(updateDoc: Partial<TDocType>) {
|
|
19
|
+
const docCopy = { ...updateDoc };
|
|
20
|
+
delete docCopy.userId;
|
|
21
|
+
return docCopy;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static docType<TDocType extends BaseDocumentWithType>(
|
|
25
|
+
updateDoc: Partial<TDocType>
|
|
26
|
+
) {
|
|
27
|
+
const docCopy = { ...updateDoc };
|
|
28
|
+
delete docCopy.docType;
|
|
29
|
+
return docCopy;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/lib/util/DocumentDb.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { Collection } from 'mongodb';
|
|
2
1
|
import { Document } from 'bson';
|
|
2
|
+
import { Collection } from 'mongodb';
|
|
3
|
+
/**
|
|
4
|
+
* A utility class for interacting with a MongoDB database.
|
|
5
|
+
*/
|
|
3
6
|
export default class DocumentDb {
|
|
4
7
|
private static DB_NAME;
|
|
5
8
|
private static mongoClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentDb.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"DocumentDb.d.ts","sourceRoot":"./src/","sources":["util/DocumentDb.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,UAAU,EAAmB,MAAM,SAAS,CAAC;AAEtD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,MAAM,CAAC,OAAO,CAAa;IAEnC,OAAO,CAAC,MAAM,CAAC,WAAW,CAA0B;IAEpD,OAAO,CAAC,MAAM,CAAC,EAAE,CAAiB;mBAEb,SAAS;WAiBjB,aAAa,CAAC,QAAQ,SAAS,QAAQ,EAClD,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;WAQnB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;CAKhD"}
|
package/lib/util/DocumentDb.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { ConfigService } from '@aneuhold/be-ts-lib';
|
|
2
|
+
import { MongoClient } from 'mongodb';
|
|
3
|
+
/**
|
|
4
|
+
* A utility class for interacting with a MongoDB database.
|
|
5
|
+
*/
|
|
6
|
+
export default class DocumentDb {
|
|
6
7
|
static DB_NAME = 'default';
|
|
7
8
|
static mongoClient;
|
|
8
9
|
static db;
|
|
9
10
|
static async getClient() {
|
|
10
|
-
if (!
|
|
11
|
+
if (!ConfigService.isInitialized) {
|
|
11
12
|
// Hard-coded local for now until there are move envs.
|
|
12
|
-
await
|
|
13
|
+
await ConfigService.useConfig('local');
|
|
13
14
|
}
|
|
14
|
-
const { config } =
|
|
15
|
+
const { config } = ConfigService;
|
|
15
16
|
if (!this.mongoClient) {
|
|
16
17
|
const mongoDbConnectionString = `mongodb+srv://${config.mongoRootUsername}:${config.mongoRootPassword}@${config.mongoUrl}/?retryWrites=true&w=majority`;
|
|
17
|
-
this.mongoClient = new
|
|
18
|
+
this.mongoClient = new MongoClient(mongoDbConnectionString);
|
|
18
19
|
}
|
|
19
20
|
// Connecting every time is evidently the correct way to do it. This is
|
|
20
21
|
// because it will not do anything and just return if it is already
|
|
@@ -35,4 +36,4 @@ class DocumentDb {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
//# sourceMappingURL=DocumentDb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentDb.js","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;IAC5D,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,iBAAiB;QAC5B,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;YAC3B,MAAM,UAAU,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACvC,CAAC;IACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ConfigService } from '@aneuhold/be-ts-lib';
|
|
2
|
+
import { Document } from 'bson';
|
|
3
|
+
import { Collection, Db, MongoClient } from 'mongodb';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A utility class for interacting with a MongoDB database.
|
|
7
|
+
*/
|
|
8
|
+
export default class DocumentDb {
|
|
9
|
+
private static DB_NAME = 'default';
|
|
10
|
+
|
|
11
|
+
private static mongoClient: MongoClient | undefined;
|
|
12
|
+
|
|
13
|
+
private static db: Db | undefined;
|
|
14
|
+
|
|
15
|
+
private static async getClient(): Promise<MongoClient> {
|
|
16
|
+
if (!ConfigService.isInitialized) {
|
|
17
|
+
// Hard-coded local for now until there are move envs.
|
|
18
|
+
await ConfigService.useConfig('local');
|
|
19
|
+
}
|
|
20
|
+
const { config } = ConfigService;
|
|
21
|
+
if (!this.mongoClient) {
|
|
22
|
+
const mongoDbConnectionString = `mongodb+srv://${config.mongoRootUsername}:${config.mongoRootPassword}@${config.mongoUrl}/?retryWrites=true&w=majority`;
|
|
23
|
+
this.mongoClient = new MongoClient(mongoDbConnectionString);
|
|
24
|
+
}
|
|
25
|
+
// Connecting every time is evidently the correct way to do it. This is
|
|
26
|
+
// because it will not do anything and just return if it is already
|
|
27
|
+
// connected.
|
|
28
|
+
await this.mongoClient.connect();
|
|
29
|
+
return this.mongoClient;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static async getCollection<TDocType extends Document>(
|
|
33
|
+
collectionName: string
|
|
34
|
+
): Promise<Collection<TDocType>> {
|
|
35
|
+
const client = await this.getClient();
|
|
36
|
+
if (!DocumentDb.db) {
|
|
37
|
+
DocumentDb.db = client.db(DocumentDb.DB_NAME);
|
|
38
|
+
}
|
|
39
|
+
return DocumentDb.db.collection<TDocType>(collectionName);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static async closeDbConnection(): Promise<void> {
|
|
43
|
+
if (DocumentDb.mongoClient) {
|
|
44
|
+
await DocumentDb.mongoClient.close();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -33,9 +33,17 @@ export default abstract class IValidator<TBaseType extends BaseDocument> {
|
|
|
33
33
|
/**
|
|
34
34
|
* Runs the standard validation for a repository.
|
|
35
35
|
*
|
|
36
|
+
* @param input
|
|
36
37
|
* @param shouldDelete A function that returns true if the document should be
|
|
37
38
|
* deleted. This should also log the specific error because it will not be
|
|
38
39
|
* logged elsewhere.
|
|
40
|
+
* @param input.dryRun
|
|
41
|
+
* @param input.docName
|
|
42
|
+
* @param input.allDocs
|
|
43
|
+
* @param input.shouldDelete
|
|
44
|
+
* @param input.documentValidator
|
|
45
|
+
* @param input.deletionFunction
|
|
46
|
+
* @param input.updateFunction
|
|
39
47
|
*/
|
|
40
48
|
protected runStandardValidationForRepository(input: {
|
|
41
49
|
dryRun: boolean;
|
|
@@ -48,6 +56,9 @@ export default abstract class IValidator<TBaseType extends BaseDocument> {
|
|
|
48
56
|
}): Promise<void>;
|
|
49
57
|
/**
|
|
50
58
|
* Checks that all elements that exist in array1, exist in array2.
|
|
59
|
+
*
|
|
60
|
+
* @param array1
|
|
61
|
+
* @param array2
|
|
51
62
|
*/
|
|
52
63
|
protected checkAllElementsExistInArr(array1: Array<unknown>, array2: Array<unknown>): boolean;
|
|
53
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseValidator.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"BaseValidator.d.ts","sourceRoot":"./src/","sources":["validators/BaseValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BA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;
|
|
4
|
-
const core_ts_lib_1 = require("@aneuhold/core-ts-lib");
|
|
5
|
-
var ObjectSchemaState;
|
|
1
|
+
import { Logger } from '@aneuhold/core-ts-lib';
|
|
2
|
+
export var ObjectSchemaState;
|
|
6
3
|
(function (ObjectSchemaState) {
|
|
7
4
|
ObjectSchemaState[ObjectSchemaState["Valid"] = 0] = "Valid";
|
|
8
5
|
ObjectSchemaState[ObjectSchemaState["InvalidAndCorrectable"] = 1] = "InvalidAndCorrectable";
|
|
9
6
|
ObjectSchemaState[ObjectSchemaState["InvalidAndUncorrectable"] = 2] = "InvalidAndUncorrectable";
|
|
10
|
-
})(ObjectSchemaState || (
|
|
11
|
-
class IValidator {
|
|
7
|
+
})(ObjectSchemaState || (ObjectSchemaState = {}));
|
|
8
|
+
export default class IValidator {
|
|
12
9
|
/**
|
|
13
10
|
* Runs the standard validation for a repository.
|
|
14
11
|
*
|
|
12
|
+
* @param input
|
|
15
13
|
* @param shouldDelete A function that returns true if the document should be
|
|
16
14
|
* deleted. This should also log the specific error because it will not be
|
|
17
15
|
* logged elsewhere.
|
|
16
|
+
* @param input.dryRun
|
|
17
|
+
* @param input.docName
|
|
18
|
+
* @param input.allDocs
|
|
19
|
+
* @param input.shouldDelete
|
|
20
|
+
* @param input.documentValidator
|
|
21
|
+
* @param input.deletionFunction
|
|
22
|
+
* @param input.updateFunction
|
|
18
23
|
*/
|
|
19
24
|
async runStandardValidationForRepository(input) {
|
|
20
25
|
const { dryRun, docName, allDocs, shouldDelete, documentValidator, deletionFunction, updateFunction } = input;
|
|
@@ -35,51 +40,54 @@ class IValidator {
|
|
|
35
40
|
docsToValidate.forEach((doc) => {
|
|
36
41
|
const { updatedDoc, errors } = documentValidator(doc);
|
|
37
42
|
if (errors.length !== 0) {
|
|
38
|
-
|
|
43
|
+
Logger.error(`${docName} with ID: ${doc._id.toString()} is invalid. Errors:`);
|
|
39
44
|
numInvalidDocs += 1;
|
|
40
45
|
errors.forEach((error) => {
|
|
41
|
-
|
|
46
|
+
Logger.error(error);
|
|
42
47
|
});
|
|
43
48
|
docsToUpdate.push(updatedDoc);
|
|
44
49
|
}
|
|
45
50
|
});
|
|
46
51
|
if (dryRun) {
|
|
47
52
|
if (numInvalidDocs === 0) {
|
|
48
|
-
|
|
53
|
+
Logger.success(`No invalid ${docName}s found.`);
|
|
49
54
|
}
|
|
50
55
|
else {
|
|
51
|
-
|
|
56
|
+
Logger.info(`Would update ${numInvalidDocs} ${docName}s in the database.`);
|
|
52
57
|
}
|
|
53
58
|
if (docIdsToDelete.length === 0) {
|
|
54
|
-
|
|
59
|
+
Logger.success(`No ${docName}s to delete found.`);
|
|
55
60
|
}
|
|
56
61
|
else {
|
|
57
|
-
|
|
62
|
+
Logger.info(`Would delete ${docIdsToDelete.length} ${docName}s in the database.`);
|
|
58
63
|
}
|
|
59
64
|
return;
|
|
60
65
|
}
|
|
61
66
|
// Delete all invalid
|
|
62
67
|
if (docIdsToDelete.length !== 0) {
|
|
63
|
-
|
|
68
|
+
Logger.info(`Deleting ${docIdsToDelete.length} ${docName}s from the database.`);
|
|
64
69
|
await deletionFunction(docIdsToDelete);
|
|
65
70
|
}
|
|
66
71
|
else {
|
|
67
|
-
|
|
72
|
+
Logger.success(`No ${docName}s to delete found.`);
|
|
68
73
|
}
|
|
69
74
|
// Update all that need to be updated
|
|
70
75
|
if (docsToUpdate.length !== 0) {
|
|
71
|
-
|
|
76
|
+
Logger.info(`Updating ${docsToUpdate.length} ${docName}s in the database.`);
|
|
72
77
|
await updateFunction(docsToUpdate);
|
|
73
78
|
}
|
|
74
79
|
else {
|
|
75
|
-
|
|
80
|
+
Logger.success(`No ${docName}s to update found.`);
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
/**
|
|
79
84
|
* Checks that all elements that exist in array1, exist in array2.
|
|
85
|
+
*
|
|
86
|
+
* @param array1
|
|
87
|
+
* @param array2
|
|
80
88
|
*/
|
|
81
89
|
checkAllElementsExistInArr(array1, array2) {
|
|
82
90
|
return array1.every((value) => array2.includes(value));
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
|
-
|
|
93
|
+
//# sourceMappingURL=BaseValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseValidator.js","sourceRoot":"./src/","sources":["validators/BaseValidator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG/C,MAAM,CAAN,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,2DAAK,CAAA;IACL,2FAAqB,CAAA;IACrB,+FAAuB,CAAA;AACzB,CAAC,EAJW,iBAAiB,KAAjB,iBAAiB,QAI5B;AAED,MAAM,CAAC,OAAO,OAAgB,UAAU;IA8BtC;;;;;;;;;;;;;;OAcG;IACO,KAAK,CAAC,kCAAkC,CAAC,KAQlD;QACC,MAAM,EACJ,MAAM,EACN,OAAO,EACP,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACf,GAAG,KAAK,CAAC;QACV,MAAM,cAAc,GAAoB,EAAE,CAAC;QAC3C,MAAM,cAAc,GAAqB,EAAE,CAAC;QAC5C,MAAM,YAAY,GAAqB,EAAE,CAAC;QAC1C,IAAI,cAAc,GAAG,CAAC,CAAC;QAEvB,yCAAyC;QACzC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACtB,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC/B,CAAC;iBAAM,CAAC;gBACN,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC,CAAC,CAAC;QACH,oBAAoB;QACpB,cAAc,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC7B,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC,GAAG,CAAC,CA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