@prosopo/database 3.0.8 → 3.0.10

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,53 +1,63 @@
1
1
  import { ProsopoDBError } from "@prosopo/common";
2
- import { AccountSchema, TableNames, } from "@prosopo/types-database";
3
- import { MongoDatabase } from "../base/index.js";
2
+ import { AccountSchema, TableNames } from "@prosopo/types-database";
3
+ import "../base/index.js";
4
+ import { MongoDatabase } from "../base/mongo.js";
4
5
  const CLIENT_TABLES = [
5
- {
6
- collectionName: TableNames.accounts,
7
- modelName: "Account",
8
- schema: AccountSchema,
9
- },
6
+ {
7
+ collectionName: TableNames.accounts,
8
+ modelName: "Account",
9
+ schema: AccountSchema
10
+ }
10
11
  ];
11
- export class ClientDatabase extends MongoDatabase {
12
- constructor(url, dbname, authSource, logger) {
13
- super(url, dbname, authSource, logger);
14
- this.tables = {};
15
- }
16
- async connect() {
17
- await super.connect();
18
- CLIENT_TABLES.map(({ collectionName, modelName, schema }) => {
19
- if (this.connection) {
20
- this.tables[collectionName] = this.connection.model(modelName, schema);
21
- }
22
- });
23
- }
24
- getTables() {
25
- if (!this.tables) {
26
- throw new ProsopoDBError("DATABASE.TABLES_UNDEFINED", {
27
- context: { failedFuncName: this.getTables.name },
28
- logger: this.logger,
29
- });
30
- }
31
- return this.tables;
32
- }
33
- async getUpdatedClients(updatedAtTimestamp) {
34
- await this.connect();
35
- const newClientRecords = await this.tables.accounts
36
- .find({
37
- $or: [
38
- { "sites.updatedAt": { $gt: updatedAtTimestamp } },
39
- { "sites.updatedAt": { $exists: false } },
40
- ],
41
- "users.status": "active",
42
- }, { "sites.siteKey": 1, "sites.settings": 1, "sites.tier": 1 })
43
- .lean()
44
- .then((records) => records.map((record) => ({
45
- account: record.sites.siteKey,
46
- settings: record.sites.settings,
47
- tier: record.tier,
48
- })));
49
- await this.close();
50
- return newClientRecords;
12
+ class ClientDatabase extends MongoDatabase {
13
+ constructor(url, dbname, authSource, logger) {
14
+ super(url, dbname, authSource, logger);
15
+ this.tables = {};
16
+ }
17
+ async connect() {
18
+ await super.connect();
19
+ CLIENT_TABLES.map(({ collectionName, modelName, schema }) => {
20
+ if (this.connection) {
21
+ this.tables[collectionName] = this.connection.model(modelName, schema);
22
+ }
23
+ });
24
+ }
25
+ getTables() {
26
+ if (!this.tables) {
27
+ throw new ProsopoDBError("DATABASE.TABLES_UNDEFINED", {
28
+ context: { failedFuncName: this.getTables.name },
29
+ logger: this.logger
30
+ });
51
31
  }
32
+ return this.tables;
33
+ }
34
+ async getUpdatedClients(updatedAtTimestamp) {
35
+ await this.connect();
36
+ const newClientRecords = await this.tables.accounts.find(
37
+ {
38
+ $or: [
39
+ { "sites.updatedAt": { $gt: updatedAtTimestamp } },
40
+ { "sites.updatedAt": { $exists: false } }
41
+ ],
42
+ "users.status": "active"
43
+ },
44
+ { "sites.siteKey": 1, "sites.settings": 1, "sites.tier": 1 }
45
+ ).lean().then(
46
+ (records) => records.map(
47
+ (record) => ({
48
+ account: record.sites.siteKey,
49
+ // Rename "sites.siteKey" to "account"
50
+ settings: record.sites.settings,
51
+ // Rename "sites.settings" to "settings"
52
+ tier: record.tier
53
+ // Keep "tier" as is
54
+ })
55
+ )
56
+ );
57
+ await this.close();
58
+ return newClientRecords;
59
+ }
52
60
  }
53
- //# sourceMappingURL=client.js.map
61
+ export {
62
+ ClientDatabase
63
+ };
@@ -4,14 +4,16 @@ import { MongoMemoryDatabase } from "../base/mongoMemory.js";
4
4
  import { CaptchaDatabase } from "./captcha.js";
5
5
  import { ClientDatabase } from "./client.js";
6
6
  import { ProviderDatabase } from "./provider.js";
7
- export * from "./captcha.js";
8
- export * from "./client.js";
9
- export { ProviderDatabase } from "./provider.js";
10
- export const Databases = {
11
- [DatabaseTypes.Values.mongo]: MongoDatabase,
12
- [DatabaseTypes.Values.provider]: ProviderDatabase,
13
- [DatabaseTypes.Values.client]: ClientDatabase,
14
- [DatabaseTypes.Values.captcha]: CaptchaDatabase,
15
- [DatabaseTypes.Values.mongoMemory]: MongoMemoryDatabase,
7
+ const Databases = {
8
+ [DatabaseTypes.Values.mongo]: MongoDatabase,
9
+ [DatabaseTypes.Values.provider]: ProviderDatabase,
10
+ [DatabaseTypes.Values.client]: ClientDatabase,
11
+ [DatabaseTypes.Values.captcha]: CaptchaDatabase,
12
+ [DatabaseTypes.Values.mongoMemory]: MongoMemoryDatabase
13
+ };
14
+ export {
15
+ CaptchaDatabase,
16
+ ClientDatabase,
17
+ Databases,
18
+ ProviderDatabase
16
19
  };
17
- //# sourceMappingURL=index.js.map