@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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2024] [Anton G Neuhold Jr]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,15 +1,56 @@
|
|
|
1
1
|
# Personal Backend Database Library
|
|
2
2
|
|
|
3
|
-
](https://jsr.io/@aneuhold/be-ts-db-lib)
|
|
4
|
+
[](https://www.npmjs.com/package/@aneuhold/be-ts-db-lib)
|
|
4
5
|
|
|
5
6
|
This is used to actually interact with databases in personal projects.
|
|
6
7
|
|
|
8
|
+
## 📦 Installation
|
|
9
|
+
|
|
10
|
+
To add to a repo, follow the instructions below for your environment:
|
|
11
|
+
|
|
12
|
+
### For Node using NPM
|
|
13
|
+
|
|
14
|
+
Run `yarn add @aneuhold/be-ts-db-lib`
|
|
15
|
+
|
|
16
|
+
### For Node using JSR
|
|
17
|
+
|
|
18
|
+
The below instructions still allow for things like Renovate to work, and normal commands with yarn such as `yarn up`.
|
|
19
|
+
|
|
20
|
+
1. Add the required JSR configuration to a `.yarnrc.yml` file if not there already:
|
|
21
|
+
```yml
|
|
22
|
+
npmScopes:
|
|
23
|
+
jsr:
|
|
24
|
+
npmRegistryServer: 'https://npm.jsr.io'
|
|
25
|
+
```
|
|
26
|
+
1. Add the package with `yarn add @jsr/aneuhold__be-ts-db-lib`
|
|
27
|
+
|
|
28
|
+
### For Deno
|
|
29
|
+
|
|
30
|
+
Run `deno add jsr:@aneuhold/be-ts-db-lib`
|
|
31
|
+
|
|
32
|
+
## 🟢 Usage
|
|
33
|
+
|
|
34
|
+
Pull in one of the services and use it like so:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { DocumentService } from '@aneuhold/be-ts-db-lib';
|
|
38
|
+
// If using Node with JSR
|
|
39
|
+
// import { DocumentService } from '@jsr/aneuhold__be-ts-db-lib';
|
|
40
|
+
|
|
41
|
+
export default function deepCopy() {
|
|
42
|
+
DocumentService.deepCopy({ someProperty: 'someString' });
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
[See full documentation on usage at JSR!](https://jsr.io/@aneuhold/be-ts-db-lib/doc)
|
|
47
|
+
|
|
48
|
+
## 🛠️ Development
|
|
49
|
+
|
|
7
50
|
Possible next tasks:
|
|
8
51
|
|
|
9
52
|
- Make the validators have an updateMany validation that is more performant.
|
|
10
53
|
|
|
11
|
-
## Development
|
|
12
|
-
|
|
13
54
|
### Creating a new Repository
|
|
14
55
|
|
|
15
56
|
1. Copy an existing one over
|
|
@@ -17,13 +58,8 @@ Possible next tasks:
|
|
|
17
58
|
|
|
18
59
|
## Schema Validation for DB
|
|
19
60
|
|
|
20
|
-
If any of the base document types are updated, make sure to run `yarn validate`
|
|
21
|
-
to make sure that the DB is up-to-date as well.
|
|
61
|
+
If any of the base document types are updated, make sure to run `yarn validate` to ensure that the DB is up-to-date as well.
|
|
22
62
|
|
|
23
63
|
## Manual Database Operations
|
|
24
64
|
|
|
25
|
-
Go ahead and run these as code in a test in the BaseRepository.spec.ts file.
|
|
26
|
-
|
|
27
|
-
## Dependencies
|
|
28
|
-
|
|
29
|
-
- [`core-ts-db-lib`](https://github.com/aneuhold/core-ts-db-lib)
|
|
65
|
+
Go ahead and run these as code in a test in the `BaseRepository.spec.ts` file.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import ApiKeyRepository from './repositories/common/ApiKeyRepository';
|
|
2
|
-
import UserRepository from './repositories/common/UserRepository';
|
|
3
|
-
import DashboardNonogramKatanaItemRepository from './repositories/dashboard/DashboardNonogramKatanaItemRepository';
|
|
4
|
-
import DashboardNonogramKatanaUpgradeRepository from './repositories/dashboard/DashboardNonogramKatanaUpgradeRepository';
|
|
5
|
-
import DashboardTaskRepository from './repositories/dashboard/DashboardTaskRepository';
|
|
6
|
-
import DashboardUserConfigRepository from './repositories/dashboard/DashboardUserConfigRepository';
|
|
7
|
-
import DocumentDb from './util/DocumentDb';
|
|
8
|
-
export {
|
|
1
|
+
import ApiKeyRepository from './repositories/common/ApiKeyRepository.js';
|
|
2
|
+
import UserRepository from './repositories/common/UserRepository.js';
|
|
3
|
+
import DashboardNonogramKatanaItemRepository from './repositories/dashboard/DashboardNonogramKatanaItemRepository.js';
|
|
4
|
+
import DashboardNonogramKatanaUpgradeRepository from './repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js';
|
|
5
|
+
import DashboardTaskRepository from './repositories/dashboard/DashboardTaskRepository.js';
|
|
6
|
+
import DashboardUserConfigRepository from './repositories/dashboard/DashboardUserConfigRepository.js';
|
|
7
|
+
import DocumentDb from './util/DocumentDb.js';
|
|
8
|
+
export { ApiKeyRepository, DashboardNonogramKatanaItemRepository, DashboardNonogramKatanaUpgradeRepository, DashboardTaskRepository, DashboardUserConfigRepository, DocumentDb, UserRepository };
|
|
9
9
|
export type {};
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"./src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,2CAA2C,CAAC;AACzE,OAAO,cAAc,MAAM,yCAAyC,CAAC;AACrE,OAAO,qCAAqC,MAAM,mEAAmE,CAAC;AACtH,OAAO,wCAAwC,MAAM,sEAAsE,CAAC;AAC5H,OAAO,uBAAuB,MAAM,qDAAqD,CAAC;AAC1F,OAAO,6BAA6B,MAAM,2DAA2D,CAAC;AACtG,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EACL,gBAAgB,EAChB,qCAAqC,EACrC,wCAAwC,EACxC,uBAAuB,EACvB,6BAA6B,EAC7B,UAAU,EACV,cAAc,EACf,CAAC;AAGF,YAAY,EAAE,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const DashboardNonogramKatanaItemRepository_1 = __importDefault(require("./repositories/dashboard/DashboardNonogramKatanaItemRepository"));
|
|
12
|
-
exports.DashboardNonogramKatanaItemRepository = DashboardNonogramKatanaItemRepository_1.default;
|
|
13
|
-
const DashboardNonogramKatanaUpgradeRepository_1 = __importDefault(require("./repositories/dashboard/DashboardNonogramKatanaUpgradeRepository"));
|
|
14
|
-
exports.DashboardNonogramKatanaUpgradeRepository = DashboardNonogramKatanaUpgradeRepository_1.default;
|
|
15
|
-
const DashboardTaskRepository_1 = __importDefault(require("./repositories/dashboard/DashboardTaskRepository"));
|
|
16
|
-
exports.DashboardTaskRepository = DashboardTaskRepository_1.default;
|
|
17
|
-
const DashboardUserConfigRepository_1 = __importDefault(require("./repositories/dashboard/DashboardUserConfigRepository"));
|
|
18
|
-
exports.DashboardUserConfigRepository = DashboardUserConfigRepository_1.default;
|
|
19
|
-
const DocumentDb_1 = __importDefault(require("./util/DocumentDb"));
|
|
20
|
-
exports.DocumentDb = DocumentDb_1.default;
|
|
1
|
+
import ApiKeyRepository from './repositories/common/ApiKeyRepository.js';
|
|
2
|
+
import UserRepository from './repositories/common/UserRepository.js';
|
|
3
|
+
import DashboardNonogramKatanaItemRepository from './repositories/dashboard/DashboardNonogramKatanaItemRepository.js';
|
|
4
|
+
import DashboardNonogramKatanaUpgradeRepository from './repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js';
|
|
5
|
+
import DashboardTaskRepository from './repositories/dashboard/DashboardTaskRepository.js';
|
|
6
|
+
import DashboardUserConfigRepository from './repositories/dashboard/DashboardUserConfigRepository.js';
|
|
7
|
+
import DocumentDb from './util/DocumentDb.js';
|
|
8
|
+
// Export all the functions and classes from this library
|
|
9
|
+
export { ApiKeyRepository, DashboardNonogramKatanaItemRepository, DashboardNonogramKatanaUpgradeRepository, DashboardTaskRepository, DashboardUserConfigRepository, DocumentDb, UserRepository };
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"./src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,2CAA2C,CAAC;AACzE,OAAO,cAAc,MAAM,yCAAyC,CAAC;AACrE,OAAO,qCAAqC,MAAM,mEAAmE,CAAC;AACtH,OAAO,wCAAwC,MAAM,sEAAsE,CAAC;AAC5H,OAAO,uBAAuB,MAAM,qDAAqD,CAAC;AAC1F,OAAO,6BAA6B,MAAM,2DAA2D,CAAC;AACtG,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAE9C,yDAAyD;AACzD,OAAO,EACL,gBAAgB,EAChB,qCAAqC,EACrC,wCAAwC,EACxC,uBAAuB,EACvB,6BAA6B,EAC7B,UAAU,EACV,cAAc,EACf,CAAC"}
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import ApiKeyRepository from './repositories/common/ApiKeyRepository.js';
|
|
2
|
+
import UserRepository from './repositories/common/UserRepository.js';
|
|
3
|
+
import DashboardNonogramKatanaItemRepository from './repositories/dashboard/DashboardNonogramKatanaItemRepository.js';
|
|
4
|
+
import DashboardNonogramKatanaUpgradeRepository from './repositories/dashboard/DashboardNonogramKatanaUpgradeRepository.js';
|
|
5
|
+
import DashboardTaskRepository from './repositories/dashboard/DashboardTaskRepository.js';
|
|
6
|
+
import DashboardUserConfigRepository from './repositories/dashboard/DashboardUserConfigRepository.js';
|
|
7
|
+
import DocumentDb from './util/DocumentDb.js';
|
|
8
|
+
|
|
9
|
+
// Export all the functions and classes from this library
|
|
10
|
+
export {
|
|
11
|
+
ApiKeyRepository,
|
|
12
|
+
DashboardNonogramKatanaItemRepository,
|
|
13
|
+
DashboardNonogramKatanaUpgradeRepository,
|
|
14
|
+
DashboardTaskRepository,
|
|
15
|
+
DashboardUserConfigRepository,
|
|
16
|
+
DocumentDb,
|
|
17
|
+
UserRepository
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Export TypeScript types where needed
|
|
21
|
+
export type {};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { BaseDocument } from '@aneuhold/core-ts-db-lib';
|
|
2
|
-
import { BulkWriteResult, Collection, DeleteResult, Filter, UpdateResult } from 'mongodb';
|
|
3
2
|
import { Document, ObjectId } from 'bson';
|
|
4
|
-
import
|
|
5
|
-
import { RepoListeners } from '../services/RepoSubscriptionService';
|
|
3
|
+
import { BulkWriteResult, Collection, DeleteResult, Filter, UpdateResult } from 'mongodb';
|
|
4
|
+
import { RepoListeners, RepoSubscribers } from '../services/RepoSubscriptionService.js';
|
|
5
|
+
import IValidator from '../validators/BaseValidator.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Base repository class for handling common database operations.
|
|
8
|
+
*
|
|
9
|
+
* @template TBasetype - The type of the documents in the collection.
|
|
8
10
|
*/
|
|
9
11
|
export default abstract class BaseRepository<TBasetype extends BaseDocument> {
|
|
10
12
|
private validator;
|
|
@@ -12,50 +14,108 @@ export default abstract class BaseRepository<TBasetype extends BaseDocument> {
|
|
|
12
14
|
private defaultUpdateCleaner?;
|
|
13
15
|
protected collectionName: string;
|
|
14
16
|
private collection?;
|
|
15
|
-
protected subscribers:
|
|
17
|
+
protected subscribers: RepoSubscribers<TBasetype>;
|
|
16
18
|
/**
|
|
17
19
|
* Constructs a new base repository.
|
|
18
20
|
*
|
|
19
|
-
* @param
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* @param collectionName - The name of the collection.
|
|
22
|
+
* @param validator - The validator for the document type.
|
|
23
|
+
* @param defaultFilter - The default filter to apply to queries.
|
|
24
|
+
* @param defaultUpdateCleaner - A function to clean update objects before sending to the DB.
|
|
23
25
|
*/
|
|
24
26
|
constructor(collectionName: string, validator: IValidator<TBasetype>, defaultFilter?: Partial<TBasetype> | undefined, defaultUpdateCleaner?: ((doc: Partial<TBasetype>) => Partial<TBasetype>) | undefined);
|
|
27
|
+
/**
|
|
28
|
+
* Gets the collection, initializing it if necessary.
|
|
29
|
+
*
|
|
30
|
+
* @returns The collection.
|
|
31
|
+
*/
|
|
25
32
|
protected getCollection(): Promise<Collection<TBasetype>>;
|
|
26
33
|
protected abstract setupSubscribers(): void;
|
|
27
34
|
/**
|
|
28
35
|
* Registers a set of functions that will be called when a change happens
|
|
29
36
|
* in this repository.
|
|
37
|
+
*
|
|
38
|
+
* @param listeners - The listeners to register.
|
|
30
39
|
*/
|
|
31
40
|
subscribeToChanges(listeners: RepoListeners<TBasetype>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Inserts a new document into the collection.
|
|
43
|
+
*
|
|
44
|
+
* @param newDoc - The new document to insert.
|
|
45
|
+
* @returns The inserted document or null if the insertion failed.
|
|
46
|
+
*/
|
|
32
47
|
insertNew(newDoc: TBasetype): Promise<TBasetype | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Inserts multiple new documents into the collection.
|
|
50
|
+
*
|
|
51
|
+
* @param newDocs - The new documents to insert.
|
|
52
|
+
* @returns The inserted documents or an empty array if the insertion failed.
|
|
53
|
+
*/
|
|
33
54
|
insertMany(newDocs: TBasetype[]): Promise<TBasetype[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves a document matching the given filter.
|
|
57
|
+
*
|
|
58
|
+
* @param filter - The filter to apply.
|
|
59
|
+
* @returns The matching document or null if no document was found.
|
|
60
|
+
*/
|
|
34
61
|
get(filter: Partial<TBasetype>): Promise<TBasetype | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves all documents in the collection.
|
|
64
|
+
*
|
|
65
|
+
* @returns An array of all documents in the collection.
|
|
66
|
+
*/
|
|
35
67
|
getAll(): Promise<TBasetype[]>;
|
|
36
68
|
/**
|
|
37
69
|
* Gets all the IDs in the collection as a hash for performant lookups.
|
|
70
|
+
*
|
|
71
|
+
* @returns An object where the keys are document IDs and the values are true.
|
|
38
72
|
*/
|
|
39
73
|
getAllIdsAsHash(): Promise<{
|
|
40
74
|
[id: string]: boolean;
|
|
41
75
|
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves a list of documents matching the given IDs.
|
|
78
|
+
*
|
|
79
|
+
* @param docIds - The IDs of the documents to retrieve.
|
|
80
|
+
* @returns An array of matching documents.
|
|
81
|
+
*/
|
|
42
82
|
getList(docIds: ObjectId[]): Promise<TBasetype[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Deletes a document by its ID.
|
|
85
|
+
*
|
|
86
|
+
* @param docId - The ID of the document to delete.
|
|
87
|
+
* @returns The result of the delete operation.
|
|
88
|
+
*/
|
|
43
89
|
delete(docId: ObjectId): Promise<DeleteResult>;
|
|
90
|
+
/**
|
|
91
|
+
* Deletes multiple documents by their IDs.
|
|
92
|
+
*
|
|
93
|
+
* @param docIds - The IDs of the documents to delete.
|
|
94
|
+
* @returns The result of the delete operation.
|
|
95
|
+
*/
|
|
44
96
|
deleteList(docIds: ObjectId[]): Promise<DeleteResult>;
|
|
45
97
|
/**
|
|
46
98
|
* This should not be used except for testing purposes
|
|
99
|
+
*
|
|
100
|
+
* @returns The result of the delete operation.
|
|
47
101
|
*/
|
|
48
102
|
deleteAll(): Promise<DeleteResult>;
|
|
49
103
|
/**
|
|
50
|
-
* Updates the provided
|
|
104
|
+
* Updates the provided document in the DB.
|
|
51
105
|
*
|
|
52
106
|
* This base method strips the `_id` before updating.
|
|
107
|
+
*
|
|
108
|
+
* @param updatedDoc - The document to update.
|
|
109
|
+
* @returns The result of the update operation.
|
|
53
110
|
*/
|
|
54
111
|
update(updatedDoc: Partial<TBasetype>): Promise<UpdateResult>;
|
|
55
112
|
/**
|
|
56
|
-
* Updates the provided
|
|
113
|
+
* Updates the provided documents in the DB.
|
|
57
114
|
*
|
|
58
115
|
* This base method strips the `_id` before updating.
|
|
116
|
+
*
|
|
117
|
+
* @param updatedDocs - The documents to update.
|
|
118
|
+
* @returns The result of the bulk update operation.
|
|
59
119
|
*/
|
|
60
120
|
updateMany(updatedDocs: Array<Partial<TBasetype>>): Promise<BulkWriteResult>;
|
|
61
121
|
/**
|
|
@@ -63,14 +123,27 @@ export default abstract class BaseRepository<TBasetype extends BaseDocument> {
|
|
|
63
123
|
*
|
|
64
124
|
* This is purposefully changing the type because of some weird restrictions
|
|
65
125
|
* with the `mongodb` package types.
|
|
126
|
+
*
|
|
127
|
+
* @param filter - The filter to apply.
|
|
128
|
+
* @returns The filter with the default filter applied.
|
|
66
129
|
*/
|
|
67
130
|
protected getFilterWithDefault(filter?: Filter<Document>): Filter<Document>;
|
|
131
|
+
/**
|
|
132
|
+
* Checks if two arrays of {@link ObjectId} are equal.
|
|
133
|
+
*
|
|
134
|
+
* @param array1 - The first array.
|
|
135
|
+
* @param array2 - The second array.
|
|
136
|
+
* @returns True if the arrays are equal, false otherwise.
|
|
137
|
+
*/
|
|
68
138
|
protected objectIdArraysAreEqual(array1: ObjectId[], array2: ObjectId[]): boolean;
|
|
69
139
|
/**
|
|
70
140
|
* Cleans the update object by removing the `_id` field and running the
|
|
71
141
|
* default update cleaner if there is one.
|
|
72
142
|
*
|
|
73
143
|
* Returns a shallow copy of the object.
|
|
144
|
+
*
|
|
145
|
+
* @param updatedDoc - The document to clean.
|
|
146
|
+
* @returns The cleaned document.
|
|
74
147
|
*/
|
|
75
148
|
private cleanUpdateObject;
|
|
76
149
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseRepository.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"BaseRepository.d.ts","sourceRoot":"./src/","sources":["repositories/BaseRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC1C,OAAO,EAEL,eAAe,EACf,UAAU,EACV,YAAY,EACZ,MAAM,EAEN,YAAY,EACb,MAAM,SAAS,CAAC;AACjB,OAAgC,EAC9B,aAAa,EACb,eAAe,EAChB,MAAM,wCAAwC,CAAC;AAGhD,OAAO,UAAU,MAAM,gCAAgC,CAAC;AAExD;;;;GAIG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,cAAc,CAAC,SAAS,SAAS,YAAY;IAkBvE,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,oBAAoB,CAAC;IAnB/B,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC;IAEjC,OAAO,CAAC,UAAU,CAAC,CAAwB;IAE3C,SAAS,CAAC,WAAW,EAAE,eAAe,CAAC,SAAS,CAAC,CACY;IAE7D;;;;;;;OAOG;gBAED,cAAc,EAAE,MAAM,EACd,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,EAChC,aAAa,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,YAAA,EAClC,oBAAoB,CAAC,GAAE,CAC7B,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,KACpB,OAAO,CAAC,SAAS,CAAC,aAAA;IAKzB;;;;OAIG;cACa,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IAQ/D,SAAS,CAAC,QAAQ,CAAC,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AC,QAAQ,CAAC;IAOnB;;;;;;OAMG;IACH,SAAS,CAAC,sBAAsB,CAC9B,MAAM,EAAE,QAAQ,EAAE,EAClB,MAAM,EAAE,QAAQ,EAAE,GACjB,OAAO;IAOV;;;;;;;;OAQG;IACH,OAAO,CAAC,iBAAiB;CAO1B"}
|
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const DocumentDb_1 = __importDefault(require("../util/DocumentDb"));
|
|
7
|
-
const DocumentCleaner_1 = __importDefault(require("../util/DocumentCleaner"));
|
|
8
|
-
const RepoSubscriptionService_1 = __importDefault(require("../services/RepoSubscriptionService"));
|
|
1
|
+
import RepoSubscriptionService from '../services/RepoSubscriptionService.js';
|
|
2
|
+
import DocumentCleaner from '../util/DocumentCleaner.js';
|
|
3
|
+
import DocumentDb from '../util/DocumentDb.js';
|
|
9
4
|
/**
|
|
10
|
-
*
|
|
5
|
+
* Base repository class for handling common database operations.
|
|
6
|
+
*
|
|
7
|
+
* @template TBasetype - The type of the documents in the collection.
|
|
11
8
|
*/
|
|
12
|
-
class BaseRepository {
|
|
9
|
+
export default class BaseRepository {
|
|
13
10
|
validator;
|
|
14
11
|
defaultFilter;
|
|
15
12
|
defaultUpdateCleaner;
|
|
16
13
|
collectionName;
|
|
17
14
|
collection;
|
|
18
|
-
subscribers =
|
|
15
|
+
subscribers = RepoSubscriptionService.getDefaultSubscribers();
|
|
19
16
|
/**
|
|
20
17
|
* Constructs a new base repository.
|
|
21
18
|
*
|
|
22
|
-
* @param
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
19
|
+
* @param collectionName - The name of the collection.
|
|
20
|
+
* @param validator - The validator for the document type.
|
|
21
|
+
* @param defaultFilter - The default filter to apply to queries.
|
|
22
|
+
* @param defaultUpdateCleaner - A function to clean update objects before sending to the DB.
|
|
26
23
|
*/
|
|
27
24
|
constructor(collectionName, validator, defaultFilter, defaultUpdateCleaner) {
|
|
28
25
|
this.validator = validator;
|
|
@@ -30,9 +27,14 @@ class BaseRepository {
|
|
|
30
27
|
this.defaultUpdateCleaner = defaultUpdateCleaner;
|
|
31
28
|
this.collectionName = collectionName;
|
|
32
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets the collection, initializing it if necessary.
|
|
32
|
+
*
|
|
33
|
+
* @returns The collection.
|
|
34
|
+
*/
|
|
33
35
|
async getCollection() {
|
|
34
36
|
if (!this.collection) {
|
|
35
|
-
this.collection = await
|
|
37
|
+
this.collection = await DocumentDb.getCollection(this.collectionName);
|
|
36
38
|
this.setupSubscribers();
|
|
37
39
|
}
|
|
38
40
|
return this.collection;
|
|
@@ -40,6 +42,8 @@ class BaseRepository {
|
|
|
40
42
|
/**
|
|
41
43
|
* Registers a set of functions that will be called when a change happens
|
|
42
44
|
* in this repository.
|
|
45
|
+
*
|
|
46
|
+
* @param listeners - The listeners to register.
|
|
43
47
|
*/
|
|
44
48
|
subscribeToChanges(listeners) {
|
|
45
49
|
const { insertNew, updateOne, updateMany, deleteOne, deleteList } = listeners;
|
|
@@ -59,6 +63,12 @@ class BaseRepository {
|
|
|
59
63
|
this.subscribers.deleteList.push(deleteList);
|
|
60
64
|
}
|
|
61
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Inserts a new document into the collection.
|
|
68
|
+
*
|
|
69
|
+
* @param newDoc - The new document to insert.
|
|
70
|
+
* @returns The inserted document or null if the insertion failed.
|
|
71
|
+
*/
|
|
62
72
|
async insertNew(newDoc) {
|
|
63
73
|
const collection = await this.getCollection();
|
|
64
74
|
await this.validator.validateNewObject(newDoc);
|
|
@@ -69,6 +79,12 @@ class BaseRepository {
|
|
|
69
79
|
await Promise.all(this.subscribers.insertNew.map((subscriber) => subscriber(newDoc)));
|
|
70
80
|
return newDoc;
|
|
71
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Inserts multiple new documents into the collection.
|
|
84
|
+
*
|
|
85
|
+
* @param newDocs - The new documents to insert.
|
|
86
|
+
* @returns The inserted documents or an empty array if the insertion failed.
|
|
87
|
+
*/
|
|
72
88
|
async insertMany(newDocs) {
|
|
73
89
|
const collection = await this.getCollection();
|
|
74
90
|
await Promise.all(newDocs.map((doc) => this.validator.validateNewObject(doc)));
|
|
@@ -79,11 +95,22 @@ class BaseRepository {
|
|
|
79
95
|
await Promise.all(this.subscribers.insertMany.map((subscriber) => subscriber(newDocs)));
|
|
80
96
|
return newDocs;
|
|
81
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves a document matching the given filter.
|
|
100
|
+
*
|
|
101
|
+
* @param filter - The filter to apply.
|
|
102
|
+
* @returns The matching document or null if no document was found.
|
|
103
|
+
*/
|
|
82
104
|
async get(filter) {
|
|
83
105
|
const collection = await this.getCollection();
|
|
84
106
|
const result = await collection.findOne(this.getFilterWithDefault(filter));
|
|
85
107
|
return result;
|
|
86
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Retrieves all documents in the collection.
|
|
111
|
+
*
|
|
112
|
+
* @returns An array of all documents in the collection.
|
|
113
|
+
*/
|
|
87
114
|
async getAll() {
|
|
88
115
|
const collection = await this.getCollection();
|
|
89
116
|
const result = await collection.find(this.getFilterWithDefault()).toArray();
|
|
@@ -92,6 +119,8 @@ class BaseRepository {
|
|
|
92
119
|
}
|
|
93
120
|
/**
|
|
94
121
|
* Gets all the IDs in the collection as a hash for performant lookups.
|
|
122
|
+
*
|
|
123
|
+
* @returns An object where the keys are document IDs and the values are true.
|
|
95
124
|
*/
|
|
96
125
|
async getAllIdsAsHash() {
|
|
97
126
|
const allDocs = await this.getAll();
|
|
@@ -100,6 +129,12 @@ class BaseRepository {
|
|
|
100
129
|
return acc;
|
|
101
130
|
}, {});
|
|
102
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves a list of documents matching the given IDs.
|
|
134
|
+
*
|
|
135
|
+
* @param docIds - The IDs of the documents to retrieve.
|
|
136
|
+
* @returns An array of matching documents.
|
|
137
|
+
*/
|
|
103
138
|
async getList(docIds) {
|
|
104
139
|
const collection = await this.getCollection();
|
|
105
140
|
const result = await collection
|
|
@@ -107,11 +142,23 @@ class BaseRepository {
|
|
|
107
142
|
.toArray();
|
|
108
143
|
return result;
|
|
109
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Deletes a document by its ID.
|
|
147
|
+
*
|
|
148
|
+
* @param docId - The ID of the document to delete.
|
|
149
|
+
* @returns The result of the delete operation.
|
|
150
|
+
*/
|
|
110
151
|
async delete(docId) {
|
|
111
152
|
const collection = await this.getCollection();
|
|
112
153
|
await Promise.all(this.subscribers.deleteOne.map((subscriber) => subscriber(docId)));
|
|
113
154
|
return collection.deleteOne({ _id: docId });
|
|
114
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Deletes multiple documents by their IDs.
|
|
158
|
+
*
|
|
159
|
+
* @param docIds - The IDs of the documents to delete.
|
|
160
|
+
* @returns The result of the delete operation.
|
|
161
|
+
*/
|
|
115
162
|
async deleteList(docIds) {
|
|
116
163
|
const collection = await this.getCollection();
|
|
117
164
|
const deleteResult = collection.deleteMany({
|
|
@@ -122,15 +169,20 @@ class BaseRepository {
|
|
|
122
169
|
}
|
|
123
170
|
/**
|
|
124
171
|
* This should not be used except for testing purposes
|
|
172
|
+
*
|
|
173
|
+
* @returns The result of the delete operation.
|
|
125
174
|
*/
|
|
126
175
|
async deleteAll() {
|
|
127
176
|
const collection = await this.getCollection();
|
|
128
177
|
return collection.deleteMany(this.getFilterWithDefault());
|
|
129
178
|
}
|
|
130
179
|
/**
|
|
131
|
-
* Updates the provided
|
|
180
|
+
* Updates the provided document in the DB.
|
|
132
181
|
*
|
|
133
182
|
* This base method strips the `_id` before updating.
|
|
183
|
+
*
|
|
184
|
+
* @param updatedDoc - The document to update.
|
|
185
|
+
* @returns The result of the update operation.
|
|
134
186
|
*/
|
|
135
187
|
async update(updatedDoc) {
|
|
136
188
|
const collection = await this.getCollection();
|
|
@@ -144,9 +196,12 @@ class BaseRepository {
|
|
|
144
196
|
return result;
|
|
145
197
|
}
|
|
146
198
|
/**
|
|
147
|
-
* Updates the provided
|
|
199
|
+
* Updates the provided documents in the DB.
|
|
148
200
|
*
|
|
149
201
|
* This base method strips the `_id` before updating.
|
|
202
|
+
*
|
|
203
|
+
* @param updatedDocs - The documents to update.
|
|
204
|
+
* @returns The result of the bulk update operation.
|
|
150
205
|
*/
|
|
151
206
|
async updateMany(updatedDocs) {
|
|
152
207
|
const collection = await this.getCollection();
|
|
@@ -169,6 +224,9 @@ class BaseRepository {
|
|
|
169
224
|
*
|
|
170
225
|
* This is purposefully changing the type because of some weird restrictions
|
|
171
226
|
* with the `mongodb` package types.
|
|
227
|
+
*
|
|
228
|
+
* @param filter - The filter to apply.
|
|
229
|
+
* @returns The filter with the default filter applied.
|
|
172
230
|
*/
|
|
173
231
|
getFilterWithDefault(filter = {}) {
|
|
174
232
|
if (!this.defaultFilter) {
|
|
@@ -176,6 +234,13 @@ class BaseRepository {
|
|
|
176
234
|
}
|
|
177
235
|
return { ...filter, ...this.defaultFilter };
|
|
178
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Checks if two arrays of {@link ObjectId} are equal.
|
|
239
|
+
*
|
|
240
|
+
* @param array1 - The first array.
|
|
241
|
+
* @param array2 - The second array.
|
|
242
|
+
* @returns True if the arrays are equal, false otherwise.
|
|
243
|
+
*/
|
|
179
244
|
objectIdArraysAreEqual(array1, array2) {
|
|
180
245
|
if (array1.length !== array2.length) {
|
|
181
246
|
return false;
|
|
@@ -187,11 +252,14 @@ class BaseRepository {
|
|
|
187
252
|
* default update cleaner if there is one.
|
|
188
253
|
*
|
|
189
254
|
* Returns a shallow copy of the object.
|
|
255
|
+
*
|
|
256
|
+
* @param updatedDoc - The document to clean.
|
|
257
|
+
* @returns The cleaned document.
|
|
190
258
|
*/
|
|
191
259
|
cleanUpdateObject(updatedDoc) {
|
|
192
260
|
return this.defaultUpdateCleaner
|
|
193
|
-
? this.defaultUpdateCleaner(
|
|
194
|
-
:
|
|
261
|
+
? this.defaultUpdateCleaner(DocumentCleaner.id(updatedDoc))
|
|
262
|
+
: DocumentCleaner.id(updatedDoc);
|
|
195
263
|
}
|
|
196
264
|
}
|
|
197
|
-
|
|
265
|
+
//# sourceMappingURL=BaseRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseRepository.js","sourceRoot":"./src/","sources":["repositories/BaseRepository.ts"],"names":[],"mappings":"AAWA,OAAO,uBAGN,MAAM,wCAAwC,CAAC;AAChD,OAAO,eAAe,MAAM,4BAA4B,CAAC;AACzD,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAG/C;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAgB,cAAc;IAkBhC;IACA;IACA;IAnBA,cAAc,CAAS;IAEzB,UAAU,CAAyB;IAEjC,WAAW,GACnB,uBAAuB,CAAC,qBAAqB,EAAa,CAAC;IAE7D;;;;;;;OAOG;IACH,YACE,cAAsB,EACd,SAAgC,EAChC,aAAkC,EAClC,oBAEe;QAJf,cAAS,GAAT,SAAS,CAAuB;QAChC,kBAAa,GAAb,aAAa,CAAqB;QAClC,yBAAoB,GAApB,oBAAoB,CAEL;QAEvB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED;;;;OAIG;IACO,KAAK,CAAC,aAAa;QAC3B,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,IAAI,CAAC,UAAU,GAAG,MAAM,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YACtE,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC1B,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAID;;;;;OAKG;IACH,kBAAkB,CAAC,SAAmC;QACpD,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,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