@prosopo/database 0.1.18 → 0.2.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/databases/index.d.ts +7 -0
- package/dist/databases/index.d.ts.map +1 -0
- package/dist/databases/index.js +21 -0
- package/dist/databases/index.js.map +1 -0
- package/dist/databases/mongo.d.ts +158 -0
- package/dist/databases/mongo.d.ts.map +1 -0
- package/dist/databases/mongo.js +623 -0
- package/dist/databases/mongo.js.map +1 -0
- package/dist/databases/mongoMemory.d.ts +6 -0
- package/dist/databases/mongoMemory.d.ts.map +1 -0
- package/dist/databases/mongoMemory.js +11 -0
- package/dist/databases/mongoMemory.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ProsopoDatabase as MongoDatabase } from './mongo.js';
|
|
2
|
+
import { MongoMemoryDatabase } from './mongoMemory.js';
|
|
3
|
+
export declare const Databases: {
|
|
4
|
+
mongo: typeof MongoDatabase;
|
|
5
|
+
mongoMemory: typeof MongoMemoryDatabase;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/databases/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACtD,eAAO,MAAM,SAAS;;;CAGrB,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { DatabaseTypes } from '@prosopo/types';
|
|
15
|
+
import { ProsopoDatabase as MongoDatabase } from './mongo.js';
|
|
16
|
+
import { MongoMemoryDatabase } from './mongoMemory.js';
|
|
17
|
+
export const Databases = {
|
|
18
|
+
[DatabaseTypes.Values.mongo]: MongoDatabase,
|
|
19
|
+
[DatabaseTypes.Values.mongoMemory]: MongoMemoryDatabase,
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/databases/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,eAAe,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACtD,MAAM,CAAC,MAAM,SAAS,GAAG;IACrB,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,aAAa;IAC3C,CAAC,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,mBAAmB;CAC1D,CAAA"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/connection.js" />
|
|
2
|
+
import { ArgumentTypes, Captcha, CaptchaSolution, CaptchaStates, DatasetBase, DatasetWithIds, DatasetWithIdsAndTree, PendingCaptchaRequest, ScheduledTaskNames, ScheduledTaskResult, ScheduledTaskStatus } from '@prosopo/types';
|
|
3
|
+
import { AsyncFactory, Logger } from '@prosopo/common';
|
|
4
|
+
import { Database, ScheduledTaskRecord, Tables, UserCommitmentRecord, UserSolutionRecord } from '@prosopo/types-database';
|
|
5
|
+
import { DeleteResult } from 'mongodb';
|
|
6
|
+
import { Connection } from 'mongoose';
|
|
7
|
+
/**
|
|
8
|
+
* Returns the Database object through which Providers can put and get captchas
|
|
9
|
+
* @param {string} url The database endpoint
|
|
10
|
+
* @param {string} dbname The database name
|
|
11
|
+
* @return {ProsopoDatabase} Database layer
|
|
12
|
+
*/
|
|
13
|
+
export declare class ProsopoDatabase extends AsyncFactory implements Database {
|
|
14
|
+
url: string;
|
|
15
|
+
tables?: Tables;
|
|
16
|
+
dbname: string;
|
|
17
|
+
connection?: Connection;
|
|
18
|
+
logger: Logger;
|
|
19
|
+
constructor();
|
|
20
|
+
init(url: string, dbname: string, logger: Logger, authSource?: string): Promise<this>;
|
|
21
|
+
/**
|
|
22
|
+
* @description Connect to the database and set the various tables
|
|
23
|
+
*/
|
|
24
|
+
connect(): Promise<void>;
|
|
25
|
+
/** Close connection to the database */
|
|
26
|
+
close(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* @description Load a dataset to the database
|
|
29
|
+
* @param {Dataset} dataset
|
|
30
|
+
*/
|
|
31
|
+
storeDataset(dataset: DatasetWithIdsAndTree): Promise<void>;
|
|
32
|
+
/** @description Get a dataset from the database
|
|
33
|
+
* @param {string} datasetId
|
|
34
|
+
*/
|
|
35
|
+
getDataset(datasetId: string): Promise<DatasetWithIds>;
|
|
36
|
+
/**
|
|
37
|
+
* @description Get random captchas that are solved or not solved
|
|
38
|
+
* @param {boolean} solved `true` when captcha is solved
|
|
39
|
+
* @param {string} datasetId the id of the data set
|
|
40
|
+
* @param {number} size the number of records to be returned
|
|
41
|
+
*/
|
|
42
|
+
getRandomCaptcha(solved: boolean, datasetId: ArgumentTypes.Hash, size?: number): Promise<Captcha[] | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* @description Get captchas by id
|
|
45
|
+
* @param {string[]} captchaId
|
|
46
|
+
*/
|
|
47
|
+
getCaptchaById(captchaId: string[]): Promise<Captcha[] | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* @description Update a captcha
|
|
50
|
+
* @param {Captcha} captcha
|
|
51
|
+
* @param {string} datasetId the id of the data set
|
|
52
|
+
*/
|
|
53
|
+
updateCaptcha(captcha: Captcha, datasetId: ArgumentTypes.Hash): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* @description Remove captchas
|
|
56
|
+
*/
|
|
57
|
+
removeCaptchas(captchaIds: string[]): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* @description Get a dataset by Id
|
|
60
|
+
*/
|
|
61
|
+
getDatasetDetails(datasetId: ArgumentTypes.Hash): Promise<DatasetBase>;
|
|
62
|
+
/**
|
|
63
|
+
* @description Store a Dapp User's captcha solution commitment
|
|
64
|
+
*/
|
|
65
|
+
storeDappUserSolution(captchas: CaptchaSolution[], commit: UserCommitmentRecord): Promise<void>;
|
|
66
|
+
/** @description Get processed Dapp User captcha solutions from the user solution table
|
|
67
|
+
*/
|
|
68
|
+
getProcessedDappUserSolutions(): Promise<UserSolutionRecord[]>;
|
|
69
|
+
/** @description Get processed Dapp User captcha commitments from the commitments table
|
|
70
|
+
*/
|
|
71
|
+
getProcessedDappUserCommitments(): Promise<UserCommitmentRecord[]>;
|
|
72
|
+
/** @description Get Dapp User captcha commitments from the commitments table that have not been batched on-chain
|
|
73
|
+
*/
|
|
74
|
+
getUnbatchedDappUserCommitments(): Promise<UserCommitmentRecord[]>;
|
|
75
|
+
/** @description Get Dapp User captcha commitments from the commitments table that have been batched on-chain
|
|
76
|
+
*/
|
|
77
|
+
getBatchedDappUserCommitments(): Promise<UserCommitmentRecord[]>;
|
|
78
|
+
/** @description Remove processed Dapp User captcha solutions from the user solution table
|
|
79
|
+
*/
|
|
80
|
+
removeProcessedDappUserSolutions(commitmentIds: string[]): Promise<DeleteResult | undefined>;
|
|
81
|
+
/** @description Remove processed Dapp User captcha commitments from the user commitments table
|
|
82
|
+
*/
|
|
83
|
+
removeProcessedDappUserCommitments(commitmentIds: string[]): Promise<DeleteResult | undefined>;
|
|
84
|
+
/**
|
|
85
|
+
* @description Store a Dapp User's pending record
|
|
86
|
+
*/
|
|
87
|
+
storeDappUserPending(userAccount: string, requestHash: string, salt: string, deadlineTimestamp: number, requestedAtBlock: number): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* @description Get a Dapp user's pending record
|
|
90
|
+
*/
|
|
91
|
+
getDappUserPending(requestHash: string): Promise<PendingCaptchaRequest>;
|
|
92
|
+
/**
|
|
93
|
+
* @description Update a Dapp User's pending record
|
|
94
|
+
*/
|
|
95
|
+
updateDappUserPendingStatus(userAccount: string, requestHash: string, approve: boolean): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* @description Get all unsolved captchas
|
|
98
|
+
*/
|
|
99
|
+
getAllCaptchasByDatasetId(datasetId: string, state?: CaptchaStates): Promise<Captcha[] | undefined>;
|
|
100
|
+
/**
|
|
101
|
+
* @description Get all dapp user solutions by captchaIds
|
|
102
|
+
*/
|
|
103
|
+
getAllDappUserSolutions(captchaId: string[]): Promise<UserSolutionRecord[] | undefined>;
|
|
104
|
+
getDatasetIdWithSolvedCaptchasOfSizeN(solvedCaptchaCount: number): Promise<string>;
|
|
105
|
+
getRandomSolvedCaptchasFromSingleDataset(datasetId: string, size: number): Promise<CaptchaSolution[]>;
|
|
106
|
+
/**
|
|
107
|
+
* @description Get dapp user solution by ID
|
|
108
|
+
* @param {string[]} commitmentId
|
|
109
|
+
*/
|
|
110
|
+
getDappUserSolutionById(commitmentId: string): Promise<UserSolutionRecord | undefined>;
|
|
111
|
+
/**
|
|
112
|
+
* @description Get dapp user commitment by user account
|
|
113
|
+
* @param commitmentId
|
|
114
|
+
*/
|
|
115
|
+
getDappUserCommitmentById(commitmentId: string): Promise<UserCommitmentRecord | undefined>;
|
|
116
|
+
/**
|
|
117
|
+
* @description Get dapp user commitment by user account
|
|
118
|
+
* @param {string[]} userAccount
|
|
119
|
+
*/
|
|
120
|
+
getDappUserCommitmentByAccount(userAccount: string): Promise<UserCommitmentRecord[]>;
|
|
121
|
+
/**
|
|
122
|
+
* @description Approve a dapp user's solution
|
|
123
|
+
* @param {string[]} commitmentId
|
|
124
|
+
*/
|
|
125
|
+
approveDappUserCommitment(commitmentId: string): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* @description Flag a dapp user's solutions as used by calculated solution
|
|
128
|
+
* @param {string[]} captchaIds
|
|
129
|
+
*/
|
|
130
|
+
flagProcessedDappUserSolutions(captchaIds: ArgumentTypes.Hash[]): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* @description Flag dapp users' commitments as used by calculated solution
|
|
133
|
+
* @param {string[]} commitmentIds
|
|
134
|
+
*/
|
|
135
|
+
flagProcessedDappUserCommitments(commitmentIds: ArgumentTypes.Hash[]): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* @description Flag dapp users' commitments as used by calculated solution
|
|
138
|
+
* @param {string[]} commitmentIds
|
|
139
|
+
*/
|
|
140
|
+
flagBatchedDappUserCommitments(commitmentIds: ArgumentTypes.Hash[]): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* @description Get the last batch commit time or return 0 if none
|
|
143
|
+
*/
|
|
144
|
+
getLastBatchCommitTime(): Promise<Date>;
|
|
145
|
+
/**
|
|
146
|
+
* @description Get a scheduled task status record by task ID and status
|
|
147
|
+
*/
|
|
148
|
+
getScheduledTaskStatus(taskId: string, status: ScheduledTaskStatus): Promise<ScheduledTaskRecord | undefined>;
|
|
149
|
+
/**
|
|
150
|
+
* @description Get the most recent scheduled task status record for a given task
|
|
151
|
+
*/
|
|
152
|
+
getLastScheduledTaskStatus(task: ScheduledTaskNames, status?: ScheduledTaskStatus): Promise<ScheduledTaskRecord | undefined>;
|
|
153
|
+
/**
|
|
154
|
+
* @description Store the status of a scheduled task and an optional result
|
|
155
|
+
*/
|
|
156
|
+
storeScheduledTaskStatus(taskId: `0x${string}`, task: ScheduledTaskNames, status: ScheduledTaskStatus, result?: ScheduledTaskResult): Promise<void>;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=mongo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo.d.ts","sourceRoot":"","sources":["../../src/databases/mongo.ts"],"names":[],"mappings":";AAcA,OAAO,EACH,aAAa,EACb,OAAO,EACP,eAAe,EACf,aAAa,EAEb,WAAW,EACX,cAAc,EACd,qBAAqB,EAErB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,EAAqC,MAAM,iBAAiB,CAAA;AACzF,OAAO,EAEH,QAAQ,EAGR,mBAAmB,EAKnB,MAAM,EACN,oBAAoB,EAGpB,kBAAkB,EAGrB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,YAAY,EAAoB,MAAM,SAAS,CAAA;AAExD,OAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAO/C;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,YAAa,YAAW,QAAQ;IACjE,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;;IASD,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;IAal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AE,MAAM,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAQ1F;;;OAGG;IACG,yBAAyB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAepE;;;OAGG;IACG,8BAA8B,CAAC,UAAU,EAAE,aAAa,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAWrF;;;OAGG;IACG,gCAAgC,CAAC,aAAa,EAAE,aAAa,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1F;;;OAGG;IACG,8BAA8B,CAAC,aAAa,EAAE,aAAa,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAYxF;;OAEG;IACG,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAa7C;;OAEG;IACG,sBAAsB,CACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,mBAAmB,GAC5B,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAO3C;;OAEG;IACG,0BAA0B,CAC5B,IAAI,EAAE,kBAAkB,EACxB,MAAM,CAAC,EAAE,mBAAmB,GAC7B,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAe3C;;OAEG;IACG,wBAAwB,CAC1B,MAAM,EAAE,KAAK,MAAM,EAAE,EACrB,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,mBAAmB,EAC3B,MAAM,CAAC,EAAE,mBAAmB,GAC7B,OAAO,CAAC,IAAI,CAAC;CAWnB"}
|
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
15
|
+
import { CaptchaStates, CaptchaStatus, DatasetWithIdsAndTreeSchema, ScheduledTaskNames, ScheduledTaskStatus, } from '@prosopo/types';
|
|
16
|
+
import { AsyncFactory, ProsopoEnvError, getLoggerDefault } from '@prosopo/common';
|
|
17
|
+
import { CaptchaRecordSchema, DatasetRecordSchema, PendingRecordSchema, ScheduledTaskRecordSchema, ScheduledTaskSchema, SolutionRecordSchema, UserCommitmentRecordSchema, UserCommitmentSchema, UserSolutionRecordSchema, UserSolutionSchema, } from '@prosopo/types-database';
|
|
18
|
+
import { ServerApiVersion } from 'mongodb';
|
|
19
|
+
import { isHex } from '@polkadot/util';
|
|
20
|
+
import mongoose from 'mongoose';
|
|
21
|
+
mongoose.set('strictQuery', false);
|
|
22
|
+
// mongodb://username:password@127.0.0.1:27017
|
|
23
|
+
const DEFAULT_ENDPOINT = 'mongodb://127.0.0.1:27017';
|
|
24
|
+
/**
|
|
25
|
+
* Returns the Database object through which Providers can put and get captchas
|
|
26
|
+
* @param {string} url The database endpoint
|
|
27
|
+
* @param {string} dbname The database name
|
|
28
|
+
* @return {ProsopoDatabase} Database layer
|
|
29
|
+
*/
|
|
30
|
+
export class ProsopoDatabase extends AsyncFactory {
|
|
31
|
+
constructor() {
|
|
32
|
+
super();
|
|
33
|
+
this.url = '';
|
|
34
|
+
this.dbname = '';
|
|
35
|
+
this.logger = getLoggerDefault();
|
|
36
|
+
}
|
|
37
|
+
async init(url, dbname, logger, authSource) {
|
|
38
|
+
const baseEndpoint = url || DEFAULT_ENDPOINT;
|
|
39
|
+
const parsedUrl = new URL(baseEndpoint);
|
|
40
|
+
parsedUrl.pathname = dbname;
|
|
41
|
+
if (authSource) {
|
|
42
|
+
parsedUrl.searchParams.set('authSource', authSource);
|
|
43
|
+
}
|
|
44
|
+
this.url = parsedUrl.toString();
|
|
45
|
+
this.dbname = dbname;
|
|
46
|
+
this.logger = logger;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @description Connect to the database and set the various tables
|
|
51
|
+
*/
|
|
52
|
+
async connect() {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
if (this.connection) {
|
|
55
|
+
resolve();
|
|
56
|
+
}
|
|
57
|
+
this.logger.info(`Mongo url: ${this.url.replace(/\w+:\w+/, '<Credentials>')}`);
|
|
58
|
+
this.connection = mongoose.createConnection(this.url, {
|
|
59
|
+
dbName: this.dbname,
|
|
60
|
+
serverApi: ServerApiVersion.v1,
|
|
61
|
+
});
|
|
62
|
+
this.tables = {
|
|
63
|
+
captcha: this.connection.models.Captcha || this.connection.model('Captcha', CaptchaRecordSchema),
|
|
64
|
+
dataset: this.connection.models.Dataset || this.connection.model('Dataset', DatasetRecordSchema),
|
|
65
|
+
solution: this.connection.models.Solution || this.connection.model('Solution', SolutionRecordSchema),
|
|
66
|
+
commitment: this.connection.models.UserCommitment ||
|
|
67
|
+
this.connection.model('UserCommitment', UserCommitmentRecordSchema),
|
|
68
|
+
usersolution: this.connection.models.UserSolution ||
|
|
69
|
+
this.connection.model('UserSolution', UserSolutionRecordSchema),
|
|
70
|
+
pending: this.connection.models.Pending || this.connection.model('Pending', PendingRecordSchema),
|
|
71
|
+
scheduler: this.connection.models.Scheduler || this.connection.model('Scheduler', ScheduledTaskRecordSchema),
|
|
72
|
+
};
|
|
73
|
+
this.connection.once('open', resolve).on('error', (e) => {
|
|
74
|
+
this.logger.warn(`mongoose connection error`);
|
|
75
|
+
if (e.message.code === 'ETIMEDOUT') {
|
|
76
|
+
this.logger.error(e);
|
|
77
|
+
mongoose.connect(this.url);
|
|
78
|
+
}
|
|
79
|
+
this.logger.error(e);
|
|
80
|
+
reject(new ProsopoEnvError(e, 'DATABASE.CONNECT_ERROR', {}, this.url));
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/** Close connection to the database */
|
|
85
|
+
async close() {
|
|
86
|
+
this.logger.info(`Closing connection to ${this.url}`);
|
|
87
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
88
|
+
await new Promise(async (resolve, reject) => {
|
|
89
|
+
mongoose.connection
|
|
90
|
+
.close()
|
|
91
|
+
.then(() => {
|
|
92
|
+
this.logger.info(`Connection to ${this.url} closed`);
|
|
93
|
+
resolve();
|
|
94
|
+
})
|
|
95
|
+
.catch(reject);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @description Load a dataset to the database
|
|
100
|
+
* @param {Dataset} dataset
|
|
101
|
+
*/
|
|
102
|
+
async storeDataset(dataset) {
|
|
103
|
+
try {
|
|
104
|
+
this.logger.info(`Storing dataset in database`);
|
|
105
|
+
const parsedDataset = DatasetWithIdsAndTreeSchema.parse(dataset);
|
|
106
|
+
const datasetDoc = {
|
|
107
|
+
datasetId: parsedDataset.datasetId,
|
|
108
|
+
datasetContentId: parsedDataset.datasetContentId,
|
|
109
|
+
format: parsedDataset.format,
|
|
110
|
+
contentTree: parsedDataset.contentTree,
|
|
111
|
+
solutionTree: parsedDataset.solutionTree,
|
|
112
|
+
};
|
|
113
|
+
await this.tables?.dataset.updateOne({ datasetId: parsedDataset.datasetId }, { $set: datasetDoc }, { upsert: true });
|
|
114
|
+
this.logger.info('parsedDataset.captchas', parsedDataset.captchas);
|
|
115
|
+
// put the dataset id on each of the captcha docs and remove the solution
|
|
116
|
+
const captchaDocs = parsedDataset.captchas.map(({ solution, ...captcha }, index) => ({
|
|
117
|
+
...captcha,
|
|
118
|
+
datasetId: parsedDataset.datasetId,
|
|
119
|
+
datasetContentId: parsedDataset.datasetContentId,
|
|
120
|
+
index,
|
|
121
|
+
solved: !!solution?.length,
|
|
122
|
+
}));
|
|
123
|
+
this.logger.info(`Inserting captcha records`);
|
|
124
|
+
// create a bulk upsert operation and execute
|
|
125
|
+
if (captchaDocs.length) {
|
|
126
|
+
await this.tables?.captcha.bulkWrite(captchaDocs.map((captchaDoc) => ({
|
|
127
|
+
updateOne: {
|
|
128
|
+
filter: { captchaId: captchaDoc.captchaId },
|
|
129
|
+
update: { $set: captchaDoc },
|
|
130
|
+
upsert: true,
|
|
131
|
+
},
|
|
132
|
+
})));
|
|
133
|
+
}
|
|
134
|
+
// insert any captcha solutions into the solutions collection
|
|
135
|
+
const captchaSolutionDocs = parsedDataset.captchas
|
|
136
|
+
.filter(({ solution }) => solution?.length)
|
|
137
|
+
.map((captcha) => ({
|
|
138
|
+
captchaId: captcha.captchaId,
|
|
139
|
+
captchaContentId: captcha.captchaContentId,
|
|
140
|
+
solution: captcha.solution,
|
|
141
|
+
salt: captcha.salt,
|
|
142
|
+
datasetId: parsedDataset.datasetId,
|
|
143
|
+
datasetContentId: parsedDataset.datasetContentId,
|
|
144
|
+
}));
|
|
145
|
+
this.logger.info(`Inserting solution records`);
|
|
146
|
+
// create a bulk upsert operation and execute
|
|
147
|
+
if (captchaSolutionDocs.length) {
|
|
148
|
+
await this.tables?.solution.bulkWrite(captchaSolutionDocs.map((captchaSolutionDoc) => ({
|
|
149
|
+
updateOne: {
|
|
150
|
+
filter: { captchaId: captchaSolutionDoc.captchaId },
|
|
151
|
+
update: { $set: captchaSolutionDoc },
|
|
152
|
+
upsert: true,
|
|
153
|
+
},
|
|
154
|
+
})));
|
|
155
|
+
}
|
|
156
|
+
this.logger.info(`Dataset stored in database`);
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
// TODO should not cast error here, improve error handling
|
|
160
|
+
throw new ProsopoEnvError(err, 'DATABASE.DATASET_LOAD_FAILED');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** @description Get a dataset from the database
|
|
164
|
+
* @param {string} datasetId
|
|
165
|
+
*/
|
|
166
|
+
async getDataset(datasetId) {
|
|
167
|
+
const datasetDoc = await this.tables?.dataset
|
|
168
|
+
.findOne({ datasetId: datasetId })
|
|
169
|
+
.lean();
|
|
170
|
+
if (datasetDoc) {
|
|
171
|
+
const { datasetContentId, format, contentTree, solutionTree } = datasetDoc;
|
|
172
|
+
const captchas = (await this.tables?.captcha.find({ datasetId }).lean()) || [];
|
|
173
|
+
const solutions = (await this.tables?.solution.find({ datasetId }).lean()) || [];
|
|
174
|
+
const solutionsKeyed = {};
|
|
175
|
+
for (const solution of solutions) {
|
|
176
|
+
solutionsKeyed[solution.captchaId] = solution;
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
datasetId,
|
|
180
|
+
datasetContentId,
|
|
181
|
+
format,
|
|
182
|
+
contentTree: contentTree || [],
|
|
183
|
+
solutionTree: solutionTree || [],
|
|
184
|
+
captchas: captchas.map((captchaDoc) => {
|
|
185
|
+
const { captchaId, captchaContentId, items, target, salt, solved } = captchaDoc;
|
|
186
|
+
const solution = solutionsKeyed[captchaId];
|
|
187
|
+
return {
|
|
188
|
+
captchaId,
|
|
189
|
+
captchaContentId,
|
|
190
|
+
solved: !!solved,
|
|
191
|
+
salt,
|
|
192
|
+
items,
|
|
193
|
+
target,
|
|
194
|
+
solution: solved && solution ? solution.solution : [],
|
|
195
|
+
};
|
|
196
|
+
}),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
throw new ProsopoEnvError('DATABASE.DATASET_GET_FAILED', undefined, {}, datasetId);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* @description Get random captchas that are solved or not solved
|
|
203
|
+
* @param {boolean} solved `true` when captcha is solved
|
|
204
|
+
* @param {string} datasetId the id of the data set
|
|
205
|
+
* @param {number} size the number of records to be returned
|
|
206
|
+
*/
|
|
207
|
+
async getRandomCaptcha(solved, datasetId, size) {
|
|
208
|
+
if (!isHex(datasetId)) {
|
|
209
|
+
throw new ProsopoEnvError('DATABASE.INVALID_HASH', this.getRandomCaptcha.name, {}, datasetId);
|
|
210
|
+
}
|
|
211
|
+
const sampleSize = size ? Math.abs(Math.trunc(size)) : 1;
|
|
212
|
+
const cursor = this.tables?.captcha.aggregate([
|
|
213
|
+
{ $match: { datasetId, solved } },
|
|
214
|
+
{ $sample: { size: sampleSize } },
|
|
215
|
+
{
|
|
216
|
+
$project: {
|
|
217
|
+
datasetId: 1,
|
|
218
|
+
datasetContentId: 1,
|
|
219
|
+
captchaId: 1,
|
|
220
|
+
captchaContentId: 1,
|
|
221
|
+
items: 1,
|
|
222
|
+
target: 1,
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
]);
|
|
226
|
+
const docs = await cursor;
|
|
227
|
+
if (docs && docs.length) {
|
|
228
|
+
// drop the _id field
|
|
229
|
+
return docs.map(({ _id, ...keepAttrs }) => keepAttrs);
|
|
230
|
+
}
|
|
231
|
+
throw new ProsopoEnvError('DATABASE.CAPTCHA_GET_FAILED', this.getRandomCaptcha.name, {}, {
|
|
232
|
+
solved: solved,
|
|
233
|
+
datasetId: datasetId,
|
|
234
|
+
size: size,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* @description Get captchas by id
|
|
239
|
+
* @param {string[]} captchaId
|
|
240
|
+
*/
|
|
241
|
+
async getCaptchaById(captchaId) {
|
|
242
|
+
const cursor = this.tables?.captcha.find({ captchaId: { $in: captchaId } }).lean();
|
|
243
|
+
const docs = await cursor;
|
|
244
|
+
if (docs && docs.length) {
|
|
245
|
+
// drop the _id field
|
|
246
|
+
return docs.map(({ _id, ...keepAttrs }) => keepAttrs);
|
|
247
|
+
}
|
|
248
|
+
throw new ProsopoEnvError('DATABASE.CAPTCHA_GET_FAILED', this.getCaptchaById.name, {}, captchaId);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* @description Update a captcha
|
|
252
|
+
* @param {Captcha} captcha
|
|
253
|
+
* @param {string} datasetId the id of the data set
|
|
254
|
+
*/
|
|
255
|
+
async updateCaptcha(captcha, datasetId) {
|
|
256
|
+
if (!isHex(datasetId)) {
|
|
257
|
+
throw new ProsopoEnvError('DATABASE.INVALID_HASH', this.updateCaptcha.name, {}, datasetId);
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
await this.tables?.captcha.updateOne({ datasetId }, { $set: captcha }, { upsert: false });
|
|
261
|
+
}
|
|
262
|
+
catch (err) {
|
|
263
|
+
// TODO need to improve error handling
|
|
264
|
+
throw new ProsopoEnvError(err);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* @description Remove captchas
|
|
269
|
+
*/
|
|
270
|
+
async removeCaptchas(captchaIds) {
|
|
271
|
+
await this.tables?.captcha.deleteMany({ captchaId: { $in: captchaIds } });
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* @description Get a dataset by Id
|
|
275
|
+
*/
|
|
276
|
+
async getDatasetDetails(datasetId) {
|
|
277
|
+
if (!isHex(datasetId)) {
|
|
278
|
+
throw new ProsopoEnvError('DATABASE.INVALID_HASH', this.getDatasetDetails.name, {}, datasetId);
|
|
279
|
+
}
|
|
280
|
+
const doc = await this.tables?.dataset.findOne({ datasetId }).lean();
|
|
281
|
+
if (doc) {
|
|
282
|
+
return doc;
|
|
283
|
+
}
|
|
284
|
+
throw new ProsopoEnvError('DATABASE.DATASET_GET_FAILED', this.getDatasetDetails.name, {}, datasetId);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* @description Store a Dapp User's captcha solution commitment
|
|
288
|
+
*/
|
|
289
|
+
async storeDappUserSolution(captchas, commit) {
|
|
290
|
+
const commitmentRecord = UserCommitmentSchema.parse(commit);
|
|
291
|
+
if (captchas.length) {
|
|
292
|
+
await this.tables?.commitment.updateOne({
|
|
293
|
+
id: commit.id,
|
|
294
|
+
}, commitmentRecord, { upsert: true });
|
|
295
|
+
const ops = captchas.map((captcha) => ({
|
|
296
|
+
updateOne: {
|
|
297
|
+
filter: { commitmentId: commit.id, captchaId: captcha.captchaId },
|
|
298
|
+
update: {
|
|
299
|
+
$set: {
|
|
300
|
+
captchaId: captcha.captchaId,
|
|
301
|
+
captchaContentId: captcha.captchaContentId,
|
|
302
|
+
salt: captcha.salt,
|
|
303
|
+
solution: captcha.solution,
|
|
304
|
+
commitmentId: commit.id,
|
|
305
|
+
processed: false,
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
upsert: true,
|
|
309
|
+
},
|
|
310
|
+
}));
|
|
311
|
+
await this.tables?.usersolution.bulkWrite(ops);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/** @description Get processed Dapp User captcha solutions from the user solution table
|
|
315
|
+
*/
|
|
316
|
+
async getProcessedDappUserSolutions() {
|
|
317
|
+
const docs = await this.tables?.usersolution.find({ processed: true }).lean();
|
|
318
|
+
return docs ? docs.map((doc) => UserSolutionSchema.parse(doc)) : [];
|
|
319
|
+
}
|
|
320
|
+
/** @description Get processed Dapp User captcha commitments from the commitments table
|
|
321
|
+
*/
|
|
322
|
+
async getProcessedDappUserCommitments() {
|
|
323
|
+
const docs = await this.tables?.commitment.find({ processed: true }).lean();
|
|
324
|
+
return docs ? docs.map((doc) => UserCommitmentSchema.parse(doc)) : [];
|
|
325
|
+
}
|
|
326
|
+
/** @description Get Dapp User captcha commitments from the commitments table that have not been batched on-chain
|
|
327
|
+
*/
|
|
328
|
+
async getUnbatchedDappUserCommitments() {
|
|
329
|
+
const docs = await this.tables?.commitment.find({ batched: false }).lean();
|
|
330
|
+
return docs ? docs.map((doc) => UserCommitmentSchema.parse(doc)) : [];
|
|
331
|
+
}
|
|
332
|
+
/** @description Get Dapp User captcha commitments from the commitments table that have been batched on-chain
|
|
333
|
+
*/
|
|
334
|
+
async getBatchedDappUserCommitments() {
|
|
335
|
+
const docs = await this.tables?.commitment.find({ batched: true }).lean();
|
|
336
|
+
return docs ? docs.map((doc) => UserCommitmentSchema.parse(doc)) : [];
|
|
337
|
+
}
|
|
338
|
+
/** @description Remove processed Dapp User captcha solutions from the user solution table
|
|
339
|
+
*/
|
|
340
|
+
async removeProcessedDappUserSolutions(commitmentIds) {
|
|
341
|
+
return await this.tables?.usersolution.deleteMany({ processed: true, commitmentId: { $in: commitmentIds } });
|
|
342
|
+
}
|
|
343
|
+
/** @description Remove processed Dapp User captcha commitments from the user commitments table
|
|
344
|
+
*/
|
|
345
|
+
async removeProcessedDappUserCommitments(commitmentIds) {
|
|
346
|
+
return await this.tables?.commitment.deleteMany({ processed: true, id: { $in: commitmentIds } });
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* @description Store a Dapp User's pending record
|
|
350
|
+
*/
|
|
351
|
+
async storeDappUserPending(userAccount, requestHash, salt, deadlineTimestamp, requestedAtBlock) {
|
|
352
|
+
if (!isHex(requestHash)) {
|
|
353
|
+
throw new ProsopoEnvError('DATABASE.INVALID_HASH', this.storeDappUserPending.name, {}, requestHash);
|
|
354
|
+
}
|
|
355
|
+
const pendingRecord = {
|
|
356
|
+
accountId: userAccount,
|
|
357
|
+
pending: true,
|
|
358
|
+
salt,
|
|
359
|
+
requestHash,
|
|
360
|
+
deadlineTimestamp,
|
|
361
|
+
requestedAtBlock,
|
|
362
|
+
};
|
|
363
|
+
await this.tables?.pending.updateOne({ requestHash: requestHash }, { $set: pendingRecord }, { upsert: true });
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* @description Get a Dapp user's pending record
|
|
367
|
+
*/
|
|
368
|
+
async getDappUserPending(requestHash) {
|
|
369
|
+
if (!isHex(requestHash)) {
|
|
370
|
+
throw new ProsopoEnvError('DATABASE.INVALID_HASH', this.getDappUserPending.name, {}, requestHash);
|
|
371
|
+
}
|
|
372
|
+
const doc = await this.tables?.pending
|
|
373
|
+
.findOne({ requestHash: requestHash })
|
|
374
|
+
.lean();
|
|
375
|
+
if (doc) {
|
|
376
|
+
return doc;
|
|
377
|
+
}
|
|
378
|
+
throw new ProsopoEnvError('DATABASE.PENDING_RECORD_NOT_FOUND', this.getDappUserPending.name);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* @description Update a Dapp User's pending record
|
|
382
|
+
*/
|
|
383
|
+
async updateDappUserPendingStatus(userAccount, requestHash, approve) {
|
|
384
|
+
if (!isHex(requestHash)) {
|
|
385
|
+
throw new ProsopoEnvError('DATABASE.INVALID_HASH', this.updateDappUserPendingStatus.name, {}, requestHash);
|
|
386
|
+
}
|
|
387
|
+
await this.tables?.pending.updateOne({ requestHash: requestHash }, {
|
|
388
|
+
$set: {
|
|
389
|
+
accountId: userAccount,
|
|
390
|
+
pending: false,
|
|
391
|
+
approved: approve,
|
|
392
|
+
requestHash,
|
|
393
|
+
},
|
|
394
|
+
}, { upsert: true });
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* @description Get all unsolved captchas
|
|
398
|
+
*/
|
|
399
|
+
async getAllCaptchasByDatasetId(datasetId, state) {
|
|
400
|
+
const cursor = this.tables?.captcha
|
|
401
|
+
.find({
|
|
402
|
+
datasetId,
|
|
403
|
+
solved: state === CaptchaStates.Solved,
|
|
404
|
+
})
|
|
405
|
+
.lean();
|
|
406
|
+
const docs = await cursor;
|
|
407
|
+
if (docs) {
|
|
408
|
+
// drop the _id field
|
|
409
|
+
return docs.map(({ _id, ...keepAttrs }) => keepAttrs);
|
|
410
|
+
}
|
|
411
|
+
throw new ProsopoEnvError('DATABASE.CAPTCHA_GET_FAILED');
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* @description Get all dapp user solutions by captchaIds
|
|
415
|
+
*/
|
|
416
|
+
async getAllDappUserSolutions(captchaId) {
|
|
417
|
+
const cursor = this.tables?.usersolution?.find({ captchaId: { $in: captchaId } }).lean();
|
|
418
|
+
const docs = await cursor;
|
|
419
|
+
if (docs) {
|
|
420
|
+
// drop the _id field
|
|
421
|
+
return docs.map(({ _id, ...keepAttrs }) => keepAttrs);
|
|
422
|
+
}
|
|
423
|
+
throw new ProsopoEnvError('DATABASE.SOLUTION_GET_FAILED');
|
|
424
|
+
}
|
|
425
|
+
async getDatasetIdWithSolvedCaptchasOfSizeN(solvedCaptchaCount) {
|
|
426
|
+
const cursor = this.tables?.solution.aggregate([
|
|
427
|
+
{
|
|
428
|
+
$match: {},
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
$group: {
|
|
432
|
+
_id: '$datasetId',
|
|
433
|
+
count: { $sum: 1 },
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
$match: {
|
|
438
|
+
count: { $gte: solvedCaptchaCount },
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
$sample: { size: 1 },
|
|
443
|
+
},
|
|
444
|
+
]);
|
|
445
|
+
const docs = await cursor;
|
|
446
|
+
if (docs && docs.length) {
|
|
447
|
+
// return the _id field
|
|
448
|
+
return docs[0]._id;
|
|
449
|
+
}
|
|
450
|
+
throw new ProsopoEnvError('DATABASE.DATASET_WITH_SOLUTIONS_GET_FAILED');
|
|
451
|
+
}
|
|
452
|
+
async getRandomSolvedCaptchasFromSingleDataset(datasetId, size) {
|
|
453
|
+
//const datasetId = await this.getDatasetIdWithSolvedCaptchasOfSizeN(size);
|
|
454
|
+
if (!isHex(datasetId)) {
|
|
455
|
+
throw new ProsopoEnvError('DATABASE.INVALID_HASH', this.getRandomSolvedCaptchasFromSingleDataset.name, {}, datasetId);
|
|
456
|
+
}
|
|
457
|
+
const sampleSize = size ? Math.abs(Math.trunc(size)) : 1;
|
|
458
|
+
const cursor = this.tables?.solution.aggregate([
|
|
459
|
+
{ $match: { datasetId } },
|
|
460
|
+
{ $sample: { size: sampleSize } },
|
|
461
|
+
{
|
|
462
|
+
$project: {
|
|
463
|
+
captchaId: 1,
|
|
464
|
+
captchaContentId: 1,
|
|
465
|
+
solution: 1,
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
]);
|
|
469
|
+
const docs = await cursor;
|
|
470
|
+
if (docs && docs.length) {
|
|
471
|
+
return docs;
|
|
472
|
+
}
|
|
473
|
+
throw new ProsopoEnvError('DATABASE.SOLUTION_GET_FAILED');
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* @description Get dapp user solution by ID
|
|
477
|
+
* @param {string[]} commitmentId
|
|
478
|
+
*/
|
|
479
|
+
async getDappUserSolutionById(commitmentId) {
|
|
480
|
+
const cursor = this.tables?.usersolution
|
|
481
|
+
?.findOne({
|
|
482
|
+
commitmentId: commitmentId,
|
|
483
|
+
}, { projection: { _id: 0 } })
|
|
484
|
+
.lean();
|
|
485
|
+
const doc = await cursor;
|
|
486
|
+
if (doc) {
|
|
487
|
+
return doc;
|
|
488
|
+
}
|
|
489
|
+
throw new ProsopoEnvError('DATABASE.SOLUTION_GET_FAILED', this.getCaptchaById.name, {}, commitmentId);
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* @description Get dapp user commitment by user account
|
|
493
|
+
* @param commitmentId
|
|
494
|
+
*/
|
|
495
|
+
async getDappUserCommitmentById(commitmentId) {
|
|
496
|
+
const commitmentCursor = this.tables?.commitment?.findOne({ id: commitmentId }).lean();
|
|
497
|
+
const doc = await commitmentCursor;
|
|
498
|
+
return doc ? UserCommitmentSchema.parse(doc) : undefined;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* @description Get dapp user commitment by user account
|
|
502
|
+
* @param {string[]} userAccount
|
|
503
|
+
*/
|
|
504
|
+
async getDappUserCommitmentByAccount(userAccount) {
|
|
505
|
+
const docs = await this.tables?.commitment
|
|
506
|
+
?.find({ userAccount })
|
|
507
|
+
.lean();
|
|
508
|
+
return docs ? docs : [];
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* @description Approve a dapp user's solution
|
|
512
|
+
* @param {string[]} commitmentId
|
|
513
|
+
*/
|
|
514
|
+
async approveDappUserCommitment(commitmentId) {
|
|
515
|
+
try {
|
|
516
|
+
await this.tables?.commitment
|
|
517
|
+
?.findOneAndUpdate({ id: commitmentId }, { $set: { status: CaptchaStatus.approved } }, { upsert: false })
|
|
518
|
+
.lean();
|
|
519
|
+
}
|
|
520
|
+
catch (err) {
|
|
521
|
+
// TODO should not cast error here, improve error handling
|
|
522
|
+
throw new ProsopoEnvError(err, 'DATABASE.SOLUTION_APPROVE_FAILED', {}, commitmentId);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* @description Flag a dapp user's solutions as used by calculated solution
|
|
527
|
+
* @param {string[]} captchaIds
|
|
528
|
+
*/
|
|
529
|
+
async flagProcessedDappUserSolutions(captchaIds) {
|
|
530
|
+
try {
|
|
531
|
+
await this.tables?.usersolution
|
|
532
|
+
?.updateMany({ captchaId: { $in: captchaIds } }, { $set: { processed: true } }, { upsert: false })
|
|
533
|
+
.lean();
|
|
534
|
+
}
|
|
535
|
+
catch (err) {
|
|
536
|
+
// TODO should not cast error here, improve error handling
|
|
537
|
+
throw new ProsopoEnvError(err, 'DATABASE.SOLUTION_FLAG_FAILED', {}, captchaIds);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* @description Flag dapp users' commitments as used by calculated solution
|
|
542
|
+
* @param {string[]} commitmentIds
|
|
543
|
+
*/
|
|
544
|
+
async flagProcessedDappUserCommitments(commitmentIds) {
|
|
545
|
+
try {
|
|
546
|
+
const distinctCommitmentIds = [...new Set(commitmentIds)];
|
|
547
|
+
await this.tables?.commitment
|
|
548
|
+
?.updateMany({ id: { $in: distinctCommitmentIds } }, { $set: { processed: true } }, { upsert: false })
|
|
549
|
+
.lean();
|
|
550
|
+
}
|
|
551
|
+
catch (err) {
|
|
552
|
+
// TODO should not cast error here, improve error handling
|
|
553
|
+
throw new ProsopoEnvError(err, 'DATABASE.COMMITMENT_FLAG_FAILED', {}, commitmentIds);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* @description Flag dapp users' commitments as used by calculated solution
|
|
558
|
+
* @param {string[]} commitmentIds
|
|
559
|
+
*/
|
|
560
|
+
async flagBatchedDappUserCommitments(commitmentIds) {
|
|
561
|
+
try {
|
|
562
|
+
const distinctCommitmentIds = [...new Set(commitmentIds)];
|
|
563
|
+
await this.tables?.commitment
|
|
564
|
+
?.updateMany({ id: { $in: distinctCommitmentIds } }, { $set: { batched: true } }, { upsert: false })
|
|
565
|
+
.lean();
|
|
566
|
+
}
|
|
567
|
+
catch (err) {
|
|
568
|
+
// TODO should not cast error here, improve error handling
|
|
569
|
+
throw new ProsopoEnvError(err, 'DATABASE.COMMITMENT_FLAG_FAILED', {}, commitmentIds);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* @description Get the last batch commit time or return 0 if none
|
|
574
|
+
*/
|
|
575
|
+
async getLastBatchCommitTime() {
|
|
576
|
+
const cursor = this.tables?.scheduler
|
|
577
|
+
?.findOne({ processName: ScheduledTaskNames.BatchCommitment, status: ScheduledTaskStatus.Completed })
|
|
578
|
+
.sort({ timestamp: -1 });
|
|
579
|
+
const doc = await cursor?.lean();
|
|
580
|
+
if (doc) {
|
|
581
|
+
return doc.datetime;
|
|
582
|
+
}
|
|
583
|
+
return new Date(0);
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* @description Get a scheduled task status record by task ID and status
|
|
587
|
+
*/
|
|
588
|
+
async getScheduledTaskStatus(taskId, status) {
|
|
589
|
+
const cursor = await this.tables?.scheduler
|
|
590
|
+
?.findOne({ taskId: taskId, status: status })
|
|
591
|
+
.lean();
|
|
592
|
+
return cursor ? cursor : undefined;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* @description Get the most recent scheduled task status record for a given task
|
|
596
|
+
*/
|
|
597
|
+
async getLastScheduledTaskStatus(task, status) {
|
|
598
|
+
const lookup = { processName: task };
|
|
599
|
+
if (status) {
|
|
600
|
+
lookup['status'] = status;
|
|
601
|
+
}
|
|
602
|
+
const cursor = await this.tables?.scheduler
|
|
603
|
+
?.findOne(lookup)
|
|
604
|
+
.sort({ datetime: -1 })
|
|
605
|
+
.lean();
|
|
606
|
+
return cursor ? cursor : undefined;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* @description Store the status of a scheduled task and an optional result
|
|
610
|
+
*/
|
|
611
|
+
async storeScheduledTaskStatus(taskId, task, status, result) {
|
|
612
|
+
const now = new Date();
|
|
613
|
+
const doc = ScheduledTaskSchema.parse({
|
|
614
|
+
taskId,
|
|
615
|
+
processName: task,
|
|
616
|
+
datetime: now,
|
|
617
|
+
status,
|
|
618
|
+
...(result && { result }),
|
|
619
|
+
});
|
|
620
|
+
await this.tables?.scheduler.create(doc);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
//# sourceMappingURL=mongo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo.js","sourceRoot":"","sources":["../../src/databases/mongo.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,6DAA6D;AAC7D,OAAO,EAIH,aAAa,EACb,aAAa,EAIb,2BAA2B,EAE3B,kBAAkB,EAElB,mBAAmB,GACtB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,YAAY,EAAU,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACzF,OAAO,EACH,mBAAmB,EAEnB,mBAAmB,EACnB,mBAAmB,EAEnB,yBAAyB,EACzB,mBAAmB,EAEnB,oBAAoB,EAGpB,0BAA0B,EAC1B,oBAAoB,EAEpB,wBAAwB,EACxB,kBAAkB,GACrB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAgB,gBAAgB,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,KAAK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0,0 +1,6 @@
|
|
|
1
|
+
import { Logger } from '@prosopo/common';
|
|
2
|
+
import { ProsopoDatabase as MongoDatabase } from './mongo.js';
|
|
3
|
+
export declare class MongoMemoryDatabase extends MongoDatabase {
|
|
4
|
+
init(url: string, dbname: string, logger: Logger, authSource?: string): Promise<this>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=mongoMemory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoMemory.d.ts","sourceRoot":"","sources":["../../src/databases/mongoMemory.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,eAAe,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAG7D,qBAAa,mBAAoB,SAAQ,aAAa;IACnC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAMvG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ProsopoDatabase as MongoDatabase } from './mongo.js';
|
|
2
|
+
import { MongoMemoryServer } from 'mongodb-memory-server';
|
|
3
|
+
export class MongoMemoryDatabase extends MongoDatabase {
|
|
4
|
+
async init(url, dbname, logger, authSource) {
|
|
5
|
+
const mongod = await MongoMemoryServer.create();
|
|
6
|
+
const mongoMemoryURL = mongod.getUri();
|
|
7
|
+
await super.init(mongoMemoryURL, dbname, logger, authSource);
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=mongoMemory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoMemory.js","sourceRoot":"","sources":["../../src/databases/mongoMemory.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEzD,MAAM,OAAO,mBAAoB,SAAQ,aAAa;IACzC,KAAK,CAAC,IAAI,CAAC,GAAW,EAAE,MAAc,EAAE,MAAc,EAAE,UAAmB;QAChF,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,CAAA;QAC/C,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,CAAA;QACtC,MAAM,KAAK,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAA;QAC5D,OAAO,IAAI,CAAA;IACf,CAAC;CACJ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,sBAAsB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
export * from './databases/index.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,cAAc,sBAAsB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/database",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Prosopo database plugins for provider",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/prosopo/captcha#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@prosopo/common": "
|
|
25
|
-
"@prosopo/types": "
|
|
26
|
-
"@prosopo/types-database": "
|
|
24
|
+
"@prosopo/common": "0.2.0",
|
|
25
|
+
"@prosopo/types": "0.2.0",
|
|
26
|
+
"@prosopo/types-database": "0.2.0",
|
|
27
27
|
"mongodb": "5.8.0",
|
|
28
28
|
"mongodb-memory-server": "^8.7.2",
|
|
29
29
|
"mongoose": "^7.3.3",
|