@prosopo/database 3.0.9 → 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.
- package/CHANGELOG.md +22 -0
- package/dist/base/index.js +6 -3
- package/dist/base/mongo.js +122 -117
- package/dist/base/mongoMemory.js +24 -23
- package/dist/databases/captcha.js +124 -123
- package/dist/databases/client.js +58 -48
- package/dist/databases/index.js +12 -10
- package/dist/databases/provider.js +1218 -1013
- package/dist/index.js +15 -3
- package/package.json +14 -10
- package/vite.cjs.config.ts +4 -1
- package/vite.esm.config.ts +20 -0
- package/dist/base/index.d.ts +0 -3
- package/dist/base/index.d.ts.map +0 -1
- package/dist/base/index.js.map +0 -1
- package/dist/base/mongo.d.ts +0 -18
- package/dist/base/mongo.d.ts.map +0 -1
- package/dist/base/mongo.js.map +0 -1
- package/dist/base/mongoMemory.d.ts +0 -11
- package/dist/base/mongoMemory.d.ts.map +0 -1
- package/dist/base/mongoMemory.js.map +0 -1
- package/dist/databases/captcha.d.ts +0 -23
- package/dist/databases/captcha.d.ts.map +0 -1
- package/dist/databases/captcha.js.map +0 -1
- package/dist/databases/client.d.ts +0 -12
- package/dist/databases/client.d.ts.map +0 -1
- package/dist/databases/client.js.map +0 -1
- package/dist/databases/index.d.ts +0 -16
- package/dist/databases/index.d.ts.map +0 -1
- package/dist/databases/index.js.map +0 -1
- package/dist/databases/provider.d.ts +0 -102
- package/dist/databases/provider.d.ts.map +0 -1
- package/dist/databases/provider.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/databases/client.js
CHANGED
|
@@ -1,53 +1,63 @@
|
|
|
1
1
|
import { ProsopoDBError } from "@prosopo/common";
|
|
2
|
-
import { AccountSchema, TableNames
|
|
3
|
-
import
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
{
|
|
7
|
+
collectionName: TableNames.accounts,
|
|
8
|
+
modelName: "Account",
|
|
9
|
+
schema: AccountSchema
|
|
10
|
+
}
|
|
10
11
|
];
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
61
|
+
export {
|
|
62
|
+
ClientDatabase
|
|
63
|
+
};
|
package/dist/databases/index.js
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|