@prosopo/database 2.0.3 → 2.1.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/dist/base/index.d.ts +3 -0
- package/dist/base/index.d.ts.map +1 -0
- package/dist/base/index.js +3 -0
- package/dist/base/index.js.map +1 -0
- package/dist/base/mongo.d.ts +16 -0
- package/dist/base/mongo.d.ts.map +1 -0
- package/dist/base/mongo.js +89 -0
- package/dist/base/mongo.js.map +1 -0
- package/dist/{databases → base}/mongoMemory.d.ts +3 -2
- package/dist/base/mongoMemory.d.ts.map +1 -0
- package/dist/{databases → base}/mongoMemory.js +7 -10
- package/dist/base/mongoMemory.js.map +1 -0
- package/dist/cjs/base/index.cjs +6 -0
- package/dist/cjs/base/mongo.cjs +97 -0
- package/dist/cjs/{databases → base}/mongoMemory.cjs +7 -10
- package/dist/cjs/databases/captcha.cjs +82 -0
- package/dist/cjs/databases/client.cjs +46 -0
- package/dist/cjs/databases/index.cjs +12 -3
- package/dist/cjs/databases/{mongo.cjs → provider.cjs} +111 -107
- package/dist/cjs/index.cjs +11 -6
- package/dist/databases/captcha.d.ts +16 -0
- package/dist/databases/captcha.d.ts.map +1 -0
- package/dist/databases/captcha.js +75 -0
- package/dist/databases/captcha.js.map +1 -0
- package/dist/databases/client.d.ts +12 -0
- package/dist/databases/client.d.ts.map +1 -0
- package/dist/databases/client.js +42 -0
- package/dist/databases/client.js.map +1 -0
- package/dist/databases/index.d.ts +11 -2
- package/dist/databases/index.d.ts.map +1 -1
- package/dist/databases/index.js +11 -2
- package/dist/databases/index.js.map +1 -1
- package/dist/databases/{mongo.d.ts → provider.d.ts} +27 -19
- package/dist/databases/provider.d.ts.map +1 -0
- package/dist/databases/{mongo.js → provider.js} +123 -100
- package/dist/databases/provider.js.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/package.json +52 -44
- package/dist/captchaDatabase/captchaDatabase.d.ts +0 -3
- package/dist/captchaDatabase/captchaDatabase.d.ts.map +0 -1
- package/dist/captchaDatabase/captchaDatabase.js +0 -49
- package/dist/captchaDatabase/captchaDatabase.js.map +0 -1
- package/dist/captchaDatabase/index.d.ts +0 -2
- package/dist/captchaDatabase/index.d.ts.map +0 -1
- package/dist/captchaDatabase/index.js +0 -2
- package/dist/captchaDatabase/index.js.map +0 -1
- package/dist/cjs/captchaDatabase/captchaDatabase.cjs +0 -59
- package/dist/cjs/captchaDatabase/index.cjs +0 -4
- package/dist/cjs/eventsDatabase/eventsDatabase.cjs +0 -47
- package/dist/cjs/eventsDatabase/index.cjs +0 -4
- package/dist/databases/mongo.d.ts.map +0 -1
- package/dist/databases/mongo.js.map +0 -1
- package/dist/databases/mongoMemory.d.ts.map +0 -1
- package/dist/databases/mongoMemory.js.map +0 -1
- package/dist/eventsDatabase/eventsDatabase.d.ts +0 -3
- package/dist/eventsDatabase/eventsDatabase.d.ts.map +0 -1
- package/dist/eventsDatabase/eventsDatabase.js +0 -48
- package/dist/eventsDatabase/eventsDatabase.js.map +0 -1
- package/dist/eventsDatabase/index.d.ts +0 -2
- package/dist/eventsDatabase/index.d.ts.map +0 -1
- package/dist/eventsDatabase/index.js +0 -2
- package/dist/eventsDatabase/index.js.map +0 -1
|
@@ -4,28 +4,84 @@ const is = require("@polkadot/util/is");
|
|
|
4
4
|
const common = require("@prosopo/common");
|
|
5
5
|
const types = require("@prosopo/types");
|
|
6
6
|
const typesDatabase = require("@prosopo/types-database");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
7
|
+
const mongo = require("../base/mongo.cjs");
|
|
8
|
+
var TableNames = /* @__PURE__ */ ((TableNames2) => {
|
|
9
|
+
TableNames2["captcha"] = "captcha";
|
|
10
|
+
TableNames2["dataset"] = "dataset";
|
|
11
|
+
TableNames2["solution"] = "solution";
|
|
12
|
+
TableNames2["commitment"] = "commitment";
|
|
13
|
+
TableNames2["usersolution"] = "usersolution";
|
|
14
|
+
TableNames2["pending"] = "pending";
|
|
15
|
+
TableNames2["scheduler"] = "scheduler";
|
|
16
|
+
TableNames2["powcaptcha"] = "powcaptcha";
|
|
17
|
+
TableNames2["client"] = "client";
|
|
18
|
+
return TableNames2;
|
|
19
|
+
})(TableNames || {});
|
|
20
|
+
const PROVIDER_TABLES = [
|
|
21
|
+
{
|
|
22
|
+
collectionName: "captcha",
|
|
23
|
+
modelName: "Captcha",
|
|
24
|
+
schema: typesDatabase.CaptchaRecordSchema
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
collectionName: "powcaptcha",
|
|
28
|
+
modelName: "PowCaptcha",
|
|
29
|
+
schema: typesDatabase.PoWCaptchaRecordSchema
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
collectionName: "dataset",
|
|
33
|
+
modelName: "Dataset",
|
|
34
|
+
schema: typesDatabase.DatasetRecordSchema
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
collectionName: "solution",
|
|
38
|
+
modelName: "Solution",
|
|
39
|
+
schema: typesDatabase.SolutionRecordSchema
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
collectionName: "commitment",
|
|
43
|
+
modelName: "UserCommitment",
|
|
44
|
+
schema: typesDatabase.UserCommitmentRecordSchema
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
collectionName: "usersolution",
|
|
48
|
+
modelName: "UserSolution",
|
|
49
|
+
schema: typesDatabase.UserSolutionRecordSchema
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
collectionName: "pending",
|
|
53
|
+
modelName: "Pending",
|
|
54
|
+
schema: typesDatabase.PendingRecordSchema
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
collectionName: "scheduler",
|
|
58
|
+
modelName: "Scheduler",
|
|
59
|
+
schema: typesDatabase.ScheduledTaskRecordSchema
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
collectionName: "client",
|
|
63
|
+
modelName: "Client",
|
|
64
|
+
schema: typesDatabase.ClientRecordSchema
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
class ProviderDatabase extends mongo.MongoDatabase {
|
|
68
|
+
constructor(url, dbname, authSource, logger) {
|
|
69
|
+
super(url, dbname, authSource, logger);
|
|
70
|
+
this.tables = {};
|
|
71
|
+
this.tables = {};
|
|
72
|
+
}
|
|
73
|
+
async connect() {
|
|
74
|
+
await super.connect();
|
|
75
|
+
this.loadTables();
|
|
76
|
+
}
|
|
77
|
+
loadTables() {
|
|
78
|
+
const tables = {};
|
|
79
|
+
PROVIDER_TABLES.map(({ collectionName, modelName, schema }) => {
|
|
80
|
+
if (this.connection) {
|
|
81
|
+
tables[collectionName] = this.connection.model(modelName, schema);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
this.tables = tables;
|
|
29
85
|
}
|
|
30
86
|
getTables() {
|
|
31
87
|
if (!this.tables) {
|
|
@@ -36,79 +92,6 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
36
92
|
}
|
|
37
93
|
return this.tables;
|
|
38
94
|
}
|
|
39
|
-
getConnection() {
|
|
40
|
-
if (!this.connection) {
|
|
41
|
-
throw new common.ProsopoDBError("DATABASE.CONNECTION_UNDEFINED", {
|
|
42
|
-
context: { failedFuncName: this.getConnection.name },
|
|
43
|
-
logger: this.logger
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
return this.connection;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @description Connect to the database and set the various tables
|
|
50
|
-
*/
|
|
51
|
-
async connect() {
|
|
52
|
-
this.logger.info(
|
|
53
|
-
`Mongo url: ${this.url.replace(/\w+:\w+/, "<Credentials>")}`
|
|
54
|
-
);
|
|
55
|
-
this.connection = await new Promise((resolve, reject) => {
|
|
56
|
-
const connection = mongoose.createConnection(this.url, {
|
|
57
|
-
dbName: this.dbname,
|
|
58
|
-
serverApi: mongodb.ServerApiVersion.v1
|
|
59
|
-
});
|
|
60
|
-
connection.on("open", () => {
|
|
61
|
-
this.logger.info(`Database connection to ${this.url} opened`);
|
|
62
|
-
resolve(connection);
|
|
63
|
-
});
|
|
64
|
-
connection.on("error", (err) => {
|
|
65
|
-
this.logger.error(`Database error: ${err}`);
|
|
66
|
-
reject(err);
|
|
67
|
-
});
|
|
68
|
-
connection.on("connected", () => {
|
|
69
|
-
this.logger.info(`Database connected to ${this.url}`);
|
|
70
|
-
resolve(connection);
|
|
71
|
-
});
|
|
72
|
-
connection.on("disconnected", () => {
|
|
73
|
-
this.logger.info(`Database disconnected from ${this.url}`);
|
|
74
|
-
});
|
|
75
|
-
connection.on("reconnected", () => {
|
|
76
|
-
this.logger.info(`Database reconnected to ${this.url}`);
|
|
77
|
-
resolve(connection);
|
|
78
|
-
});
|
|
79
|
-
connection.on("reconnectFailed", () => {
|
|
80
|
-
this.logger.error(`Database reconnect failed to ${this.url}`);
|
|
81
|
-
});
|
|
82
|
-
connection.on("close", () => {
|
|
83
|
-
this.logger.info(`Database connection to ${this.url} closed`);
|
|
84
|
-
});
|
|
85
|
-
connection.on("fullsetup", () => {
|
|
86
|
-
this.logger.info(`Database connection to ${this.url} is fully setup`);
|
|
87
|
-
resolve(connection);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
this.tables = {
|
|
91
|
-
captcha: this.connection.model("Captcha", typesDatabase.CaptchaRecordSchema),
|
|
92
|
-
powCaptcha: this.connection.model("PowCaptcha", typesDatabase.PowCaptchaRecordSchema),
|
|
93
|
-
dataset: this.connection.model("Dataset", typesDatabase.DatasetRecordSchema),
|
|
94
|
-
solution: this.connection.model("Solution", typesDatabase.SolutionRecordSchema),
|
|
95
|
-
commitment: this.connection.model(
|
|
96
|
-
"UserCommitment",
|
|
97
|
-
typesDatabase.UserCommitmentRecordSchema
|
|
98
|
-
),
|
|
99
|
-
usersolution: this.connection.model(
|
|
100
|
-
"UserSolution",
|
|
101
|
-
typesDatabase.UserSolutionRecordSchema
|
|
102
|
-
),
|
|
103
|
-
pending: this.connection.model("Pending", typesDatabase.PendingRecordSchema),
|
|
104
|
-
scheduler: this.connection.model("Scheduler", typesDatabase.ScheduledTaskRecordSchema)
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/** Close connection to the database */
|
|
108
|
-
async close() {
|
|
109
|
-
this.logger.debug(`Closing connection to ${this.url}`);
|
|
110
|
-
await this.connection?.close();
|
|
111
|
-
}
|
|
112
95
|
/**
|
|
113
96
|
* @description Load a dataset to the database
|
|
114
97
|
* @param {Dataset} dataset
|
|
@@ -124,7 +107,7 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
124
107
|
contentTree: parsedDataset.contentTree,
|
|
125
108
|
solutionTree: parsedDataset.solutionTree
|
|
126
109
|
};
|
|
127
|
-
await this.tables?.
|
|
110
|
+
await this.tables.dataset?.updateOne(
|
|
128
111
|
{ datasetId: parsedDataset.datasetId },
|
|
129
112
|
{ $set: datasetDoc },
|
|
130
113
|
{ upsert: true }
|
|
@@ -374,12 +357,13 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
374
357
|
* @param userSignature
|
|
375
358
|
* @returns {Promise<void>} A promise that resolves when the record is added.
|
|
376
359
|
*/
|
|
377
|
-
async storePowCaptchaRecord(challenge, components, difficulty, providerSignature, ipAddress, serverChecked = false, userSubmitted = false, storedStatus = typesDatabase.StoredStatusNames.notStored, userSignature) {
|
|
360
|
+
async storePowCaptchaRecord(challenge, components, difficulty, providerSignature, ipAddress, headers, serverChecked = false, userSubmitted = false, storedStatus = typesDatabase.StoredStatusNames.notStored, userSignature) {
|
|
378
361
|
const tables = this.getTables();
|
|
379
362
|
const powCaptchaRecord = {
|
|
380
363
|
challenge,
|
|
381
364
|
...components,
|
|
382
365
|
ipAddress,
|
|
366
|
+
headers,
|
|
383
367
|
result: { status: types.CaptchaStatus.pending },
|
|
384
368
|
userSubmitted,
|
|
385
369
|
serverChecked,
|
|
@@ -389,7 +373,7 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
389
373
|
lastUpdatedTimestamp: Date.now()
|
|
390
374
|
};
|
|
391
375
|
try {
|
|
392
|
-
await tables.
|
|
376
|
+
await tables.powcaptcha.create(powCaptchaRecord);
|
|
393
377
|
this.logger.info("PowCaptcha record added successfully", {
|
|
394
378
|
challenge,
|
|
395
379
|
userSubmitted,
|
|
@@ -429,7 +413,7 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
429
413
|
});
|
|
430
414
|
}
|
|
431
415
|
try {
|
|
432
|
-
const record = await this.tables.
|
|
416
|
+
const record = await this.tables.powcaptcha.findOne({ challenge }).lean();
|
|
433
417
|
if (record) {
|
|
434
418
|
this.logger.info("PowCaptcha record retrieved successfully", {
|
|
435
419
|
challenge
|
|
@@ -455,7 +439,6 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
455
439
|
* @param result
|
|
456
440
|
* @param serverChecked
|
|
457
441
|
* @param userSubmitted
|
|
458
|
-
* @param storedStatus
|
|
459
442
|
* @param userSignature
|
|
460
443
|
* @returns {Promise<void>} A promise that resolves when the record is updated.
|
|
461
444
|
*/
|
|
@@ -470,7 +453,7 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
470
453
|
lastUpdatedTimestamp: timestamp
|
|
471
454
|
};
|
|
472
455
|
try {
|
|
473
|
-
const updateResult = await tables.
|
|
456
|
+
const updateResult = await tables.powcaptcha.updateOne(
|
|
474
457
|
{ challenge },
|
|
475
458
|
{
|
|
476
459
|
$set: update
|
|
@@ -567,7 +550,7 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
567
550
|
/** @description Get Dapp User PoW captcha commitments that have not been counted towards the client's total
|
|
568
551
|
*/
|
|
569
552
|
async getUnstoredDappUserPoWCommitments() {
|
|
570
|
-
const docs = await this.tables?.
|
|
553
|
+
const docs = await this.tables?.powcaptcha.find({
|
|
571
554
|
$or: [
|
|
572
555
|
{ storedStatus: { $ne: typesDatabase.StoredStatusNames.stored } },
|
|
573
556
|
{ storedStatus: { $exists: false } }
|
|
@@ -581,7 +564,7 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
581
564
|
const updateDoc = {
|
|
582
565
|
storedAtTimestamp: Date.now()
|
|
583
566
|
};
|
|
584
|
-
await this.tables?.
|
|
567
|
+
await this.tables?.powcaptcha.updateMany(
|
|
585
568
|
{ challenge: { $in: challenges } },
|
|
586
569
|
{ $set: updateDoc },
|
|
587
570
|
{ upsert: false }
|
|
@@ -594,7 +577,7 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
594
577
|
[typesDatabase.StoredStatusNames.serverChecked]: true,
|
|
595
578
|
lastUpdatedTimestamp: Date.now()
|
|
596
579
|
};
|
|
597
|
-
await this.tables?.
|
|
580
|
+
await this.tables?.powcaptcha.updateMany(
|
|
598
581
|
{ challenge: { $in: challenges } },
|
|
599
582
|
{
|
|
600
583
|
$set: updateDoc
|
|
@@ -605,7 +588,7 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
605
588
|
/** @description Remove processed Dapp User captcha solutions from the user solution table
|
|
606
589
|
*/
|
|
607
590
|
async removeProcessedDappUserSolutions(commitmentIds) {
|
|
608
|
-
return
|
|
591
|
+
return this.tables?.usersolution.deleteMany({
|
|
609
592
|
processed: true,
|
|
610
593
|
commitmentId: { $in: commitmentIds }
|
|
611
594
|
});
|
|
@@ -613,7 +596,7 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
613
596
|
/** @description Remove processed Dapp User captcha commitments from the user commitments table
|
|
614
597
|
*/
|
|
615
598
|
async removeProcessedDappUserCommitments(commitmentIds) {
|
|
616
|
-
return
|
|
599
|
+
return this.tables?.commitment.deleteMany({
|
|
617
600
|
processed: true,
|
|
618
601
|
id: { $in: commitmentIds }
|
|
619
602
|
});
|
|
@@ -934,5 +917,26 @@ class ProsopoDatabase extends common.AsyncFactory {
|
|
|
934
917
|
}
|
|
935
918
|
);
|
|
936
919
|
}
|
|
920
|
+
/**
|
|
921
|
+
* @description Update the client records
|
|
922
|
+
*/
|
|
923
|
+
async updateClientRecords(clientRecords) {
|
|
924
|
+
const ops = clientRecords.map((record) => {
|
|
925
|
+
const clientRecord = {
|
|
926
|
+
account: record.account,
|
|
927
|
+
settings: record.settings
|
|
928
|
+
};
|
|
929
|
+
return {
|
|
930
|
+
updateOne: {
|
|
931
|
+
filter: { account: record.account },
|
|
932
|
+
update: {
|
|
933
|
+
$set: clientRecord
|
|
934
|
+
},
|
|
935
|
+
upsert: true
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
});
|
|
939
|
+
await this.tables?.client.bulkWrite(ops);
|
|
940
|
+
}
|
|
937
941
|
}
|
|
938
|
-
exports.
|
|
942
|
+
exports.ProviderDatabase = ProviderDatabase;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
require("./base/index.cjs");
|
|
3
4
|
const index = require("./databases/index.cjs");
|
|
4
|
-
require("./
|
|
5
|
-
require("./
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const mongo = require("./base/mongo.cjs");
|
|
6
|
+
const mongoMemory = require("./base/mongoMemory.cjs");
|
|
7
|
+
const provider = require("./databases/provider.cjs");
|
|
8
|
+
const captcha = require("./databases/captcha.cjs");
|
|
9
|
+
const client = require("./databases/client.cjs");
|
|
8
10
|
exports.Databases = index.Databases;
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
+
exports.MongoDatabase = mongo.MongoDatabase;
|
|
12
|
+
exports.MongoMemoryDatabase = mongoMemory.MongoMemoryDatabase;
|
|
13
|
+
exports.ProviderDatabase = provider.ProviderDatabase;
|
|
14
|
+
exports.CaptchaDatabase = captcha.CaptchaDatabase;
|
|
15
|
+
exports.ClientDatabase = client.ClientDatabase;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Logger } from "@prosopo/common";
|
|
2
|
+
import { type ICaptchaDatabase, type PoWCaptchaRecord, type Tables, type UserCommitmentRecord } from "@prosopo/types-database";
|
|
3
|
+
import { MongoDatabase } from "../base/index.js";
|
|
4
|
+
declare enum TableNames {
|
|
5
|
+
commitment = "commitment",
|
|
6
|
+
powcaptcha = "powcaptcha"
|
|
7
|
+
}
|
|
8
|
+
export declare class CaptchaDatabase extends MongoDatabase implements ICaptchaDatabase {
|
|
9
|
+
tables: Tables<TableNames>;
|
|
10
|
+
constructor(url: string, dbname?: string, authSource?: string, logger?: Logger);
|
|
11
|
+
connect(): Promise<void>;
|
|
12
|
+
getTables(): Tables<TableNames>;
|
|
13
|
+
saveCaptchas(imageCaptchaEvents: UserCommitmentRecord[], powCaptchaEvents: PoWCaptchaRecord[]): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=captcha.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captcha.d.ts","sourceRoot":"","sources":["../../src/databases/captcha.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,MAAM,EAAoC,MAAM,iBAAiB,CAAC;AAChF,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAErB,KAAK,MAAM,EACX,KAAK,oBAAoB,EAEzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,aAAK,UAAU;IACd,UAAU,eAAe;IACzB,UAAU,eAAe;CACzB;AAeD,qBAAa,eAAgB,SAAQ,aAAc,YAAW,gBAAgB;IAC7E,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;gBAG1B,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM;IAMD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IASvC,SAAS,IAAI,MAAM,CAAC,UAAU,CAAC;IAUzB,YAAY,CACjB,kBAAkB,EAAE,oBAAoB,EAAE,EAC1C,gBAAgB,EAAE,gBAAgB,EAAE;CAsCrC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ProsopoDBError, getLoggerDefault } from "@prosopo/common";
|
|
2
|
+
import { PoWCaptchaRecordSchema, UserCommitmentRecordSchema, } from "@prosopo/types-database";
|
|
3
|
+
import { MongoDatabase } from "../base/index.js";
|
|
4
|
+
const logger = getLoggerDefault();
|
|
5
|
+
var TableNames;
|
|
6
|
+
(function (TableNames) {
|
|
7
|
+
TableNames["commitment"] = "commitment";
|
|
8
|
+
TableNames["powcaptcha"] = "powcaptcha";
|
|
9
|
+
})(TableNames || (TableNames = {}));
|
|
10
|
+
const CAPTCHA_TABLES = [
|
|
11
|
+
{
|
|
12
|
+
collectionName: TableNames.powcaptcha,
|
|
13
|
+
modelName: "PowCaptcha",
|
|
14
|
+
schema: PoWCaptchaRecordSchema,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
collectionName: TableNames.commitment,
|
|
18
|
+
modelName: "UserCommitment",
|
|
19
|
+
schema: UserCommitmentRecordSchema,
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
export class CaptchaDatabase extends MongoDatabase {
|
|
23
|
+
constructor(url, dbname, authSource, logger) {
|
|
24
|
+
super(url, dbname, authSource, logger);
|
|
25
|
+
this.tables = {};
|
|
26
|
+
}
|
|
27
|
+
async connect() {
|
|
28
|
+
await super.connect();
|
|
29
|
+
CAPTCHA_TABLES.map(({ collectionName, modelName, schema }) => {
|
|
30
|
+
if (this.connection) {
|
|
31
|
+
this.tables[collectionName] = this.connection.model(modelName, schema);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
getTables() {
|
|
36
|
+
if (!this.tables) {
|
|
37
|
+
throw new ProsopoDBError("DATABASE.TABLES_UNDEFINED", {
|
|
38
|
+
context: { failedFuncName: this.getTables.name },
|
|
39
|
+
logger: this.logger,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return this.tables;
|
|
43
|
+
}
|
|
44
|
+
async saveCaptchas(imageCaptchaEvents, powCaptchaEvents) {
|
|
45
|
+
await this.connect();
|
|
46
|
+
if (imageCaptchaEvents.length) {
|
|
47
|
+
const result = await this.tables.commitment.bulkWrite(imageCaptchaEvents.map((doc) => {
|
|
48
|
+
const { _id, ...safeDoc } = doc;
|
|
49
|
+
return {
|
|
50
|
+
updateOne: {
|
|
51
|
+
filter: { id: safeDoc.id },
|
|
52
|
+
update: { $set: safeDoc },
|
|
53
|
+
upsert: true,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}));
|
|
57
|
+
logger.info("Mongo Saved Image Events", result);
|
|
58
|
+
}
|
|
59
|
+
if (powCaptchaEvents.length) {
|
|
60
|
+
const result = await this.tables.powcaptcha.bulkWrite(powCaptchaEvents.map((doc) => {
|
|
61
|
+
const { _id, ...safeDoc } = doc;
|
|
62
|
+
return {
|
|
63
|
+
updateOne: {
|
|
64
|
+
filter: { challenge: safeDoc.challenge },
|
|
65
|
+
update: { $set: safeDoc },
|
|
66
|
+
upsert: true,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}));
|
|
70
|
+
logger.info("Mongo Saved PoW Events", result);
|
|
71
|
+
}
|
|
72
|
+
await this.close();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=captcha.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captcha.js","sourceRoot":"","sources":["../../src/databases/captcha.ts"],"names":[],"mappings":"AAcA,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,MAAM,EAAE,IAAI;qBACZ;iBACD,CAAC;YACH,CAAC,CAAC,CACF,CAAC;YACF,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;QAED,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Logger } from "@prosopo/common";
|
|
2
|
+
import type { Timestamp } from "@prosopo/types";
|
|
3
|
+
import { type ClientRecord, type IClientDatabase, TableNames, type Tables } from "@prosopo/types-database";
|
|
4
|
+
import { MongoDatabase } from "../base/index.js";
|
|
5
|
+
export declare class ClientDatabase extends MongoDatabase implements IClientDatabase {
|
|
6
|
+
tables: Tables<TableNames>;
|
|
7
|
+
constructor(url: string, dbname?: string, authSource?: string, logger?: Logger);
|
|
8
|
+
connect(): Promise<void>;
|
|
9
|
+
getTables(): Tables<TableNames>;
|
|
10
|
+
getUpdatedClients(updatedAtTimestamp: Timestamp): Promise<ClientRecord[]>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/databases/client.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,MAAM,EAAkB,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,UAAU,EACV,KAAK,MAAM,EAEX,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAUjD,qBAAa,cAAe,SAAQ,aAAc,YAAW,eAAe;IAC3E,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;gBAG1B,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM;IAMD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IASvC,SAAS,IAAI,MAAM,CAAC,UAAU,CAAC;IAUzB,iBAAiB,CACtB,kBAAkB,EAAE,SAAS,GAC3B,OAAO,CAAC,YAAY,EAAE,CAAC;CAY1B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ProsopoDBError } from "@prosopo/common";
|
|
2
|
+
import { TableNames, UserDataSchema, } from "@prosopo/types-database";
|
|
3
|
+
import { MongoDatabase } from "../base/index.js";
|
|
4
|
+
const CLIENT_TABLES = [
|
|
5
|
+
{
|
|
6
|
+
collectionName: TableNames.emails,
|
|
7
|
+
modelName: "Email",
|
|
8
|
+
schema: UserDataSchema,
|
|
9
|
+
},
|
|
10
|
+
];
|
|
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.emails
|
|
36
|
+
.find({ updatedAtTimestamp: { $gt: updatedAtTimestamp }, activated: true }, { account: 1, settings: 1 })
|
|
37
|
+
.lean();
|
|
38
|
+
await this.close();
|
|
39
|
+
return newClientRecords;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/databases/client.ts"],"names":[],"mappings":"AAcA,OAAO,EAAe,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,EAGN,UAAU,EAEV,cAAc,GACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,aAAa,GAAG;IACrB;QACC,cAAc,EAAE,UAAU,CAAC,MAAM;QACjC,SAAS,EAAE,OAAO;QAClB,MAAM,EAAE,cAAc;KACtB;CACD,CAAC;AAEF,MAAM,OAAO,cAAe,SAAQ,aAAa;IAGhD,YACC,GAAW,EACX,MAAe,EACf,UAAmB,EACnB,MAAe;QAEf,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,EAAwB,CAAC;IACxC,CAAC;IAEQ,KAAK,CAAC,OAAO;QACrB,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QACtB,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE;YAC3D,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACrB,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YACxE,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,SAAS;QACR,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAClB,MAAM,IAAI,cAAc,CAAC,2BAA2B,EAAE;gBACrD,OAAO,EAAE,EAAE,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE;gBAChD,MAAM,EAAE,IAAI,CAAC,MAAM;aACnB,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,iBAAiB,CACtB,kBAA6B;QAE7B,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QAErB,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM;aAC/C,IAAI,CACJ,EAAE,kBAAkB,EAAE,EAAE,GAAG,EAAE,kBAAkB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EACpE,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAC3B;aACA,IAAI,EAAkB,CAAC;QACzB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACnB,OAAO,gBAAgB,CAAC;IACzB,CAAC;CACD"}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MongoMemoryDatabase } from "
|
|
1
|
+
import { MongoDatabase } from "../base/mongo.js";
|
|
2
|
+
import { MongoMemoryDatabase } from "../base/mongoMemory.js";
|
|
3
|
+
import { CaptchaDatabase } from "./captcha.js";
|
|
4
|
+
import { ClientDatabase } from "./client.js";
|
|
5
|
+
import { ProviderDatabase } from "./provider.js";
|
|
6
|
+
export * from "./captcha.js";
|
|
7
|
+
export * from "./client.js";
|
|
8
|
+
export { ProviderDatabase } from "./provider.js";
|
|
3
9
|
export declare const Databases: {
|
|
4
10
|
mongo: typeof MongoDatabase;
|
|
11
|
+
provider: typeof ProviderDatabase;
|
|
12
|
+
client: typeof ClientDatabase;
|
|
13
|
+
captcha: typeof CaptchaDatabase;
|
|
5
14
|
mongoMemory: typeof MongoMemoryDatabase;
|
|
6
15
|
};
|
|
7
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/databases/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/databases/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,eAAO,MAAM,SAAS;;;;;;CAMrB,CAAC"}
|
package/dist/databases/index.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { DatabaseTypes } from "@prosopo/types";
|
|
2
|
-
import {
|
|
3
|
-
import { MongoMemoryDatabase } from "
|
|
2
|
+
import { MongoDatabase } from "../base/mongo.js";
|
|
3
|
+
import { MongoMemoryDatabase } from "../base/mongoMemory.js";
|
|
4
|
+
import { CaptchaDatabase } from "./captcha.js";
|
|
5
|
+
import { ClientDatabase } from "./client.js";
|
|
6
|
+
import { ProviderDatabase } from "./provider.js";
|
|
7
|
+
export * from "./captcha.js";
|
|
8
|
+
export * from "./client.js";
|
|
9
|
+
export { ProviderDatabase } from "./provider.js";
|
|
4
10
|
export const Databases = {
|
|
5
11
|
[DatabaseTypes.Values.mongo]: MongoDatabase,
|
|
12
|
+
[DatabaseTypes.Values.provider]: ProviderDatabase,
|
|
13
|
+
[DatabaseTypes.Values.client]: ClientDatabase,
|
|
14
|
+
[DatabaseTypes.Values.captcha]: CaptchaDatabase,
|
|
6
15
|
[DatabaseTypes.Values.mongoMemory]: MongoMemoryDatabase,
|
|
7
16
|
};
|
|
8
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/databases/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/databases/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,MAAM,CAAC,MAAM,SAAS,GAAG;IACxB,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,aAAa;IAC3C,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,gBAAgB;IACjD,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,cAAc;IAC7C,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,eAAe;IAC/C,CAAC,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,mBAAmB;CACvD,CAAC"}
|
|
@@ -1,21 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type Captcha, CaptchaResult, type CaptchaSolution, CaptchaStates, type DatasetBase, type DatasetWithIds, type DatasetWithIdsAndTree, type Hash, type PendingCaptchaRequest, PoWChallengeComponents, PoWChallengeId, ScheduledTaskNames, type ScheduledTaskResult, ScheduledTaskStatus } from "@prosopo/types";
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { type Logger, type TranslationKey } from "@prosopo/common";
|
|
2
|
+
import { type Captcha, type CaptchaResult, type CaptchaSolution, CaptchaStates, type Dataset, type DatasetBase, type DatasetWithIds, type DatasetWithIdsAndTree, type Hash, type PendingCaptchaRequest, type PoWChallengeComponents, type PoWChallengeId, type RequestHeaders, type ScheduledTaskNames, type ScheduledTaskResult, type ScheduledTaskStatus } from "@prosopo/types";
|
|
3
|
+
import { type ClientRecord, type IDatabase, type PoWCaptchaRecord, type ScheduledTaskRecord, type SolutionRecord, type StoredStatus, type Tables, type UserCommitment, type UserCommitmentRecord, type UserSolutionRecord } from "@prosopo/types-database";
|
|
4
|
+
import type { DeleteResult } from "mongodb";
|
|
5
|
+
import type { ObjectId } from "mongoose";
|
|
6
|
+
import { MongoDatabase } from "../base/mongo.js";
|
|
7
|
+
declare enum TableNames {
|
|
8
|
+
captcha = "captcha",
|
|
9
|
+
dataset = "dataset",
|
|
10
|
+
solution = "solution",
|
|
11
|
+
commitment = "commitment",
|
|
12
|
+
usersolution = "usersolution",
|
|
13
|
+
pending = "pending",
|
|
14
|
+
scheduler = "scheduler",
|
|
15
|
+
powcaptcha = "powcaptcha",
|
|
16
|
+
client = "client"
|
|
17
|
+
}
|
|
18
|
+
export declare class ProviderDatabase extends MongoDatabase implements IDatabase {
|
|
19
|
+
tables: Tables<TableNames>;
|
|
20
|
+
constructor(url: string, dbname?: string, authSource?: string, logger?: Logger);
|
|
16
21
|
connect(): Promise<void>;
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
loadTables(): void;
|
|
23
|
+
getTables(): Tables<TableNames>;
|
|
24
|
+
storeDataset(dataset: Dataset | DatasetWithIdsAndTree): Promise<void>;
|
|
19
25
|
getSolutions(datasetId: string): Promise<SolutionRecord[]>;
|
|
20
26
|
getDataset(datasetId: string): Promise<DatasetWithIds>;
|
|
21
27
|
getRandomCaptcha(solved: boolean, datasetId: Hash, size?: number): Promise<Captcha[] | undefined>;
|
|
@@ -24,7 +30,7 @@ export declare class ProsopoDatabase extends AsyncFactory implements Database {
|
|
|
24
30
|
removeCaptchas(captchaIds: string[]): Promise<void>;
|
|
25
31
|
getDatasetDetails(datasetId: Hash): Promise<DatasetBase>;
|
|
26
32
|
storeDappUserSolution(captchas: CaptchaSolution[], commit: UserCommitment): Promise<void>;
|
|
27
|
-
storePowCaptchaRecord(challenge: PoWChallengeId, components: PoWChallengeComponents, difficulty: number, providerSignature: string, ipAddress: string, serverChecked?: boolean, userSubmitted?: boolean, storedStatus?: StoredStatus, userSignature?: string): Promise<void>;
|
|
33
|
+
storePowCaptchaRecord(challenge: PoWChallengeId, components: PoWChallengeComponents, difficulty: number, providerSignature: string, ipAddress: string, headers: RequestHeaders, serverChecked?: boolean, userSubmitted?: boolean, storedStatus?: StoredStatus, userSignature?: string): Promise<void>;
|
|
28
34
|
getPowCaptchaRecordByChallenge(challenge: string): Promise<PoWCaptchaRecord | null>;
|
|
29
35
|
updatePowCaptchaRecord(challenge: PoWChallengeId, result: CaptchaResult, serverChecked?: boolean, userSubmitted?: boolean, userSignature?: string): Promise<void>;
|
|
30
36
|
getProcessedDappUserSolutions(): Promise<UserSolutionRecord[]>;
|
|
@@ -56,5 +62,7 @@ export declare class ProsopoDatabase extends AsyncFactory implements Database {
|
|
|
56
62
|
getLastScheduledTaskStatus(task: ScheduledTaskNames, status?: ScheduledTaskStatus): Promise<ScheduledTaskRecord | undefined>;
|
|
57
63
|
createScheduledTaskStatus(taskName: ScheduledTaskNames, status: ScheduledTaskStatus): Promise<ObjectId>;
|
|
58
64
|
updateScheduledTaskStatus(taskId: ObjectId, status: ScheduledTaskStatus, result?: ScheduledTaskResult): Promise<void>;
|
|
65
|
+
updateClientRecords(clientRecords: ClientRecord[]): Promise<void>;
|
|
59
66
|
}
|
|
60
|
-
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/databases/provider.ts"],"names":[],"mappings":"AAcA,OAAO,EACN,KAAK,MAAM,EAGX,KAAK,cAAc,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,aAAa,EAEb,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAE1B,KAAK,IAAI,EACT,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEN,KAAK,YAAY,EAGjB,KAAK,SAAS,EAGd,KAAK,gBAAgB,EAIrB,KAAK,mBAAmB,EAGxB,KAAK,cAAc,EAGnB,KAAK,YAAY,EAEjB,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,oBAAoB,EAGzB,KAAK,kBAAkB,EAEvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,aAAK,UAAU;IACd,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,UAAU,eAAe;IACzB,YAAY,iBAAiB;IAC7B,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,UAAU,eAAe;IACzB,MA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