@aneuhold/be-ts-db-lib 1.0.10 → 1.0.12

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.
@@ -1,5 +1,5 @@
1
1
  import { BaseDocument } from '@aneuhold/core-ts-db-lib';
2
- import { BulkWriteResult, Collection, DeleteResult, UpdateResult } from 'mongodb';
2
+ import { BulkWriteResult, Collection, DeleteResult, Filter, UpdateResult } from 'mongodb';
3
3
  import { Document, ObjectId } from 'bson';
4
4
  import IValidator from '../validators/BaseValidator';
5
5
  import { RepoListeners } from '../services/RepoSubscriptionService';
@@ -30,6 +30,7 @@ export default abstract class BaseRepository<TBasetype extends BaseDocument> {
30
30
  */
31
31
  subscribeToChanges(listeners: RepoListeners<TBasetype>): void;
32
32
  insertNew(newDoc: TBasetype): Promise<TBasetype | null>;
33
+ insertMany(newDocs: TBasetype[]): Promise<TBasetype[]>;
33
34
  get(filter: Partial<TBasetype>): Promise<TBasetype | null>;
34
35
  getAll(): Promise<TBasetype[]>;
35
36
  /**
@@ -63,7 +64,7 @@ export default abstract class BaseRepository<TBasetype extends BaseDocument> {
63
64
  * This is purposefully changing the type because of some weird restrictions
64
65
  * with the `mongodb` package types.
65
66
  */
66
- private getFilterWithDefault;
67
+ protected getFilterWithDefault(filter?: Filter<Document>): Filter<Document>;
67
68
  /**
68
69
  * Cleans the update object by removing the `_id` field and running the
69
70
  * default update cleaner if there is one.
@@ -1 +1 @@
1
- {"version":3,"file":"BaseRepository.d.ts","sourceRoot":"","sources":["../../src/repositories/BaseRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EACL,eAAe,EACf,UAAU,EACV,YAAY,EAEZ,YAAY,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,UAAU,MAAM,6BAA6B,CAAC;AAErD,OAAgC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(this.subscribers.insertNew.map((subscriber) => subscriber(newDoc)));
67
67
  return newDoc;
68
68
  }
69
+ async insertMany(newDocs) {
70
+ const collection = await this.getCollection();
71
+ await Promise.all(newDocs.map((doc) => this.validator.validateNewObject(doc)));
72
+ const insertResult = await collection.insertMany(newDocs);
73
+ if (!insertResult.acknowledged) {
74
+ return [];
75
+ }
76
+ await Promise.all(this.subscribers.insertMany.map((subscriber) => subscriber(newDocs)));
77
+ return newDocs;
78
+ }
69
79
  async get(filter) {
70
80
  const collection = await this.getCollection();
71
81
  const result = await collection.findOne(this.getFilterWithDefault(filter));
@@ -1 +1 @@
1
- {"version":3,"file":"ApiKeyRepository.d.ts","sourceRoot":"","sources":["../../../src/repositories/common/ApiKeyRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,cAAc,CAAC,MAAM,CAAC;IAClE,OAAO,CAAC,MAAM,CAAC,eAAe,CAAa;IAE3C,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAmB;IAEnD,MAAM,CAAC,uBAAuB,IAAI,aAAa,CAAC,IAAI,CAAC;IAmBrD,OAAO;IAIP,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAElC;;OAEG;WACW,OAAO;CAMtB"}
1
+ {"version":3,"file":"ApiKeyRepository.d.ts","sourceRoot":"","sources":["../../../src/repositories/common/ApiKeyRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,cAAc,CAAC,MAAM,CAAC;IAClE,OAAO,CAAC,MAAM,CAAC,eAAe,CAAa;IAE3C,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAmB;IAEnD,MAAM,CAAC,uBAAuB,IAAI,aAAa,CAAC,IAAI,CAAC;IA0BrD,OAAO;IAIP,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAElC;;OAEG;WACW,OAAO;CAMtB"}
@@ -16,17 +16,20 @@ class ApiKeyRepository extends BaseRepository_1.default {
16
16
  const apiKeyRepo = ApiKeyRepository.getRepo();
17
17
  return {
18
18
  deleteOne: async (userId) => {
19
- (await apiKeyRepo.getCollection()).deleteOne({
19
+ await (await apiKeyRepo.getCollection()).deleteOne({
20
20
  userId
21
21
  });
22
22
  },
23
23
  deleteList: async (userIds) => {
24
- (await apiKeyRepo.getCollection()).deleteMany({
24
+ await (await apiKeyRepo.getCollection()).deleteMany({
25
25
  userId: { $in: userIds }
26
26
  });
27
27
  },
28
28
  insertNew: async (user) => {
29
29
  await apiKeyRepo.insertNew(new core_ts_db_lib_1.ApiKey(user._id));
30
+ },
31
+ insertMany: async (users) => {
32
+ await apiKeyRepo.insertMany(users.map((user) => new core_ts_db_lib_1.ApiKey(user._id)));
30
33
  }
31
34
  };
32
35
  }
@@ -1,4 +1,5 @@
1
1
  import { DashboardTask, User } from '@aneuhold/core-ts-db-lib';
2
+ import { ObjectId } from 'bson';
2
3
  import DashboardBaseRepository from './DashboardBaseRepository';
3
4
  import { RepoListeners } from '../../services/RepoSubscriptionService';
4
5
  /**
@@ -13,5 +14,10 @@ export default class DashboardTaskRepository extends DashboardBaseRepository<Das
13
14
  * Gets the singleton instance of the {@link DashboardTaskRepository}.
14
15
  */
15
16
  static getRepo(): DashboardTaskRepository;
17
+ /**
18
+ * Gets all tasks for a given user.
19
+ * @param userId The ID of the user to get tasks for.
20
+ */
21
+ getAllForUser(userId: ObjectId): Promise<DashboardTask[]>;
16
22
  }
17
23
  //# sourceMappingURL=DashboardTaskRepository.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DashboardTaskRepository.d.ts","sourceRoot":"","sources":["../../../src/repositories/dashboard/DashboardTaskRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAGvE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,uBAAuB,CAAC,aAAa,CAAC;IACzF,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA0B;IAE1D,OAAO;IAaP,MAAM,CAAC,uBAAuB,IAAI,aAAa,CAAC,IAAI,CAAC;IAcrD,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAElC;;OAEG;WACW,OAAO;CAMtB"}
1
+ {"version":3,"file":"DashboardTaskRepository.d.ts","sourceRoot":"","sources":["../../../src/repositories/dashboard/DashboardTaskRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAGvE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,uBAAuB,CAAC,aAAa,CAAC;IACzF,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA0B;IAE1D,OAAO;IAaP,MAAM,CAAC,uBAAuB,IAAI,aAAa,CAAC,IAAI,CAAC;IAgBrD,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAElC;;OAEG;WACW,OAAO;IAOrB;;;OAGG;IACG,aAAa,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAWhE"}
@@ -24,10 +24,10 @@ class DashboardTaskRepository extends DashboardBaseRepository_1.default {
24
24
  const taskRepo = DashboardTaskRepository.getRepo();
25
25
  return {
26
26
  deleteOne: async (userId) => {
27
- (await taskRepo.getCollection()).deleteOne({ userId });
27
+ await (await taskRepo.getCollection()).deleteOne({ userId });
28
28
  },
29
29
  deleteList: async (userIds) => {
30
- (await taskRepo.getCollection()).deleteMany({
30
+ await (await taskRepo.getCollection()).deleteMany({
31
31
  userId: { $in: userIds }
32
32
  });
33
33
  }
@@ -43,5 +43,20 @@ class DashboardTaskRepository extends DashboardBaseRepository_1.default {
43
43
  }
44
44
  return DashboardTaskRepository.singletonInstance;
45
45
  }
46
+ /**
47
+ * Gets all tasks for a given user.
48
+ * @param userId The ID of the user to get tasks for.
49
+ */
50
+ async getAllForUser(userId) {
51
+ const collection = await this.getCollection();
52
+ const filter = {
53
+ $and: [
54
+ this.getFilterWithDefault(),
55
+ { $or: [{ userId }, { sharedWith: userId }] }
56
+ ]
57
+ };
58
+ const result = await collection.find(filter).toArray();
59
+ return result;
60
+ }
46
61
  }
47
62
  exports.default = DashboardTaskRepository;
@@ -1,4 +1,5 @@
1
1
  import { DashboardUserConfig, User } from '@aneuhold/core-ts-db-lib';
2
+ import { ObjectId } from 'bson';
2
3
  import DashboardBaseRepository from './DashboardBaseRepository';
3
4
  import { RepoListeners } from '../../services/RepoSubscriptionService';
4
5
  /**
@@ -13,5 +14,10 @@ export default class DashboardUserConfigRepository extends DashboardBaseReposito
13
14
  * Gets the singleton instance of the {@link DashboardUserConfigRepository}.
14
15
  */
15
16
  static getRepo(): DashboardUserConfigRepository;
17
+ /**
18
+ * Gets the config for a given user.
19
+ * @param userId The ID of the user to get the config for.
20
+ */
21
+ getForUser(userId: ObjectId): Promise<DashboardUserConfig | null>;
16
22
  }
17
23
  //# sourceMappingURL=DashboardUserConfigRepository.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DashboardUserConfigRepository.d.ts","sourceRoot":"","sources":["../../../src/repositories/dashboard/DashboardUserConfigRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAGhE,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,uBAAuB,CAAC,mBAAmB,CAAC;IACrG,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAgC;IAEhE,OAAO;IAQP,MAAM,CAAC,uBAAuB,IAAI,aAAa,CAAC,IAAI,CAAC;IAmBrD,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAElC;;OAEG;WACW,OAAO;CAOtB"}
1
+ {"version":3,"file":"DashboardUserConfigRepository.d.ts","sourceRoot":"","sources":["../../../src/repositories/dashboard/DashboardUserConfigRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,uBAAuB,MAAM,2BAA2B,CAAC;AAGhE,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,6BAA8B,SAAQ,uBAAuB,CAAC,mBAAmB,CAAC;IACrG,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAgC;IAEhE,OAAO;IAQP,MAAM,CAAC,uBAAuB,IAAI,aAAa,CAAC,IAAI,CAAC;IA6BrD,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAElC;;OAEG;WACW,OAAO;IAQrB;;;OAGG;IACG,UAAU,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;CAKxE"}
@@ -19,10 +19,10 @@ class DashboardUserConfigRepository extends DashboardBaseRepository_1.default {
19
19
  const userConfigRepo = DashboardUserConfigRepository.getRepo();
20
20
  return {
21
21
  deleteOne: async (userId) => {
22
- (await userConfigRepo.getCollection()).deleteOne({ userId });
22
+ await (await userConfigRepo.getCollection()).deleteOne({ userId });
23
23
  },
24
24
  deleteList: async (userIds) => {
25
- (await userConfigRepo.getCollection()).deleteMany({
25
+ await (await userConfigRepo.getCollection()).deleteMany({
26
26
  userId: { $in: userIds }
27
27
  });
28
28
  },
@@ -30,6 +30,10 @@ class DashboardUserConfigRepository extends DashboardBaseRepository_1.default {
30
30
  if (user.projectAccess.dashboard) {
31
31
  await userConfigRepo.insertNew(new core_ts_db_lib_1.DashboardUserConfig(user._id));
32
32
  }
33
+ },
34
+ insertMany: async (users) => {
35
+ const usersThatNeedConfig = users.filter((user) => user.projectAccess.dashboard);
36
+ await userConfigRepo.insertMany(usersThatNeedConfig.map((user) => new core_ts_db_lib_1.DashboardUserConfig(user._id)));
33
37
  }
34
38
  };
35
39
  }
@@ -44,5 +48,14 @@ class DashboardUserConfigRepository extends DashboardBaseRepository_1.default {
44
48
  }
45
49
  return DashboardUserConfigRepository.singletonInstance;
46
50
  }
51
+ /**
52
+ * Gets the config for a given user.
53
+ * @param userId The ID of the user to get the config for.
54
+ */
55
+ async getForUser(userId) {
56
+ const collection = await this.getCollection();
57
+ const result = await collection.findOne({ userId });
58
+ return result;
59
+ }
47
60
  }
48
61
  exports.default = DashboardUserConfigRepository;
@@ -2,17 +2,20 @@ import { BaseDocument } from '@aneuhold/core-ts-db-lib';
2
2
  import { ObjectId } from 'bson';
3
3
  export type RepoSubscribers<TDocType extends BaseDocument> = {
4
4
  insertNew: InsertNewSubscriber<TDocType>[];
5
+ insertMany: InsertManySubscriber<TDocType>[];
5
6
  updateMany: UpdateManySubscriber<TDocType>[];
6
7
  deleteOne: DeleteOneSubscriber[];
7
8
  deleteList: DeleteListSubscriber[];
8
9
  };
9
10
  export type RepoListeners<TDocType extends BaseDocument> = {
10
11
  insertNew?: InsertNewSubscriber<TDocType>;
12
+ insertMany?: InsertManySubscriber<TDocType>;
11
13
  updateMany?: UpdateManySubscriber<TDocType>;
12
14
  deleteOne?: DeleteOneSubscriber;
13
15
  deleteList?: DeleteListSubscriber;
14
16
  };
15
17
  export type InsertNewSubscriber<TDocType extends BaseDocument> = (doc: TDocType) => Promise<void>;
18
+ export type InsertManySubscriber<TDocType extends BaseDocument> = (docs: TDocType[]) => Promise<void>;
16
19
  export type UpdateManySubscriber<TDocType extends BaseDocument> = (docs: TDocType[]) => Promise<void>;
17
20
  export type DeleteOneSubscriber = (docId: ObjectId) => Promise<void>;
18
21
  export type DeleteListSubscriber = (docIds: ObjectId[]) => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"RepoSubscriptionService.d.ts","sourceRoot":"","sources":["../../src/services/RepoSubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEhC,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,YAAY,IAAI;IAC3D,SAAS,EAAE,mBAAmB,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC3C,UAAU,EAAE,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC7C,SAAS,EAAE,mBAAmB,EAAE,CAAC;IACjC,UAAU,EAAE,oBAAoB,EAAE,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,QAAQ,SAAS,YAAY,IAAI;IACzD,SAAS,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,mBAAmB,CAAC,QAAQ,SAAS,YAAY,IAAI,CAC/D,GAAG,EAAE,QA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E,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,mBAAmB,CAAC;IAChC,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,mBAAmB,CAAC,QAAQ,SAAS,YAAY,IAAI,CAC/D,GAAG,EAAE,QAAQ,KACV,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,YAAY,IAAI,CAChE,IAAI,EAAE,QAAQ,EAAE,KACb,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,YAAY,IAAI,CAChE,IAAI,EAAE,QAAQ,EAAE,KACb,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzE;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAC1C;;;OAGG;IACH,MAAM,CAAC,qBAAqB,CAC1B,QAAQ,SAAS,YAAY,KAC1B,eAAe,CAAC,QAAQ,CAAC;CAS/B"}
@@ -12,6 +12,7 @@ class RepoSubscriptionService {
12
12
  static getDefaultSubscribers() {
13
13
  return {
14
14
  insertNew: [],
15
+ insertMany: [],
15
16
  updateMany: [],
16
17
  deleteOne: [],
17
18
  deleteList: []
@@ -104,5 +104,5 @@ it.skip('can delete all users', async () => {
104
104
  expect(result.acknowledged).toBeTruthy();
105
105
  });
106
106
  afterAll(async () => {
107
- return DocumentDb_1.default.closeDbConnection();
107
+ await DocumentDb_1.default.closeDbConnection();
108
108
  });
@@ -29,6 +29,23 @@ describe('Create operations', () => {
29
29
  expect(deletedTask).toBeFalsy();
30
30
  });
31
31
  });
32
+ describe('Get operations', () => {
33
+ it('can get a set of tasks for a user, without any tasks from other users', async () => {
34
+ const newUser = await createNewTestUser();
35
+ const newTask = new core_ts_db_lib_1.DashboardTask(newUser._id);
36
+ const insertResult = await taskRepo.insertNew(newTask);
37
+ expect(insertResult).toBeTruthy();
38
+ const otherUser = await createNewTestUser();
39
+ const otherUserTask = new core_ts_db_lib_1.DashboardTask(otherUser._id);
40
+ const insertResult2 = await taskRepo.insertNew(otherUserTask);
41
+ expect(insertResult2).toBeTruthy();
42
+ const tasks = await taskRepo.getAllForUser(newUser._id);
43
+ expect(tasks.length).toBe(1);
44
+ expect(tasks[0]._id).toEqual(newTask._id);
45
+ await (0, testsUtil_1.cleanupDoc)(userRepo, newUser);
46
+ await (0, testsUtil_1.cleanupDoc)(userRepo, otherUser);
47
+ });
48
+ });
32
49
  afterAll(async () => {
33
50
  return DocumentDb_1.default.closeDbConnection();
34
51
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aneuhold/be-ts-db-lib",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
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",