diff --git a/ai-service/package.json b/ai-service/package.json index 4feaeed532..39d0b1f4b0 100644 --- a/ai-service/package.json +++ b/ai-service/package.json @@ -11,7 +11,7 @@ "@nestjs/common": "^9.4.1", "@nestjs/core": "^9.4.1", "@types/express": "^4.17.18", - "@types/node": "^20.8.0", + "@types/node": "^22.10.10", "dotenv": "^16.3.1", "module-alias": "^2.2.2", "express": "^4.18.2", diff --git a/analytics-service/package.json b/analytics-service/package.json index f528053a8d..439e5dda3a 100644 --- a/analytics-service/package.json +++ b/analytics-service/package.json @@ -52,7 +52,7 @@ "@types/gulp": "^4", "@types/gulp-rename": "^2", "@types/jszip": "^3.4.1", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "@types/ws": "^8.2.2", "chai": "^4.3.4", "cross-env": "^7.0.3", diff --git a/api-gateway/package.json b/api-gateway/package.json index e7f3c5c924..65e79aa700 100644 --- a/api-gateway/package.json +++ b/api-gateway/package.json @@ -2,7 +2,7 @@ "author": "Envision Blockchain Solutions ", "dependencies": { "@fastify/formbody": "^7.4.0", - "@fastify/multipart": "^8.2.0", + "@fastify/multipart": "^8.3.1", "@fastify/static": "^7.0.0", "@guardian/common": "^3.0.0", "@guardian/interfaces": "^3.0.0", @@ -46,7 +46,7 @@ "@types/gulp": "^4", "@types/gulp-rename": "^2", "@types/jszip": "^3.4.1", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "@types/ws": "^8.2.2", "chai": "^4.3.4", "cross-env": "^7.0.3", diff --git a/api-gateway/src/api/service/policy.ts b/api-gateway/src/api/service/policy.ts index 0861022f15..7e1af8d575 100644 --- a/api-gateway/src/api/service/policy.ts +++ b/api-gateway/src/api/service/policy.ts @@ -2826,8 +2826,8 @@ export class PolicyApi { // UserRole.STANDARD_REGISTRY, ) @ApiOperation({ - summary: 'Create dru-run savepoint.', - description: 'Create dru-run savepoint.' + ONLY_SR + summary: 'Create dry-run savepoint.', + description: 'Create dry-run savepoint.' + ONLY_SR }) @ApiParam({ name: 'policyId', @@ -2882,8 +2882,8 @@ export class PolicyApi { // UserRole.STANDARD_REGISTRY, ) @ApiOperation({ - summary: 'Delete dru-run savepoint.', - description: 'Delete dru-run savepoint.' + ONLY_SR + summary: 'Delete dry-run savepoint.', + description: 'Delete dry-run savepoint.' + ONLY_SR }) @ApiParam({ name: 'policyId', @@ -2929,6 +2929,59 @@ export class PolicyApi { } } + /** + * Get savepoint state. + */ + @Get('/:policyId/savepoint/restore') + @Auth( + Permissions.POLICIES_POLICY_UPDATE + // UserRole.STANDARD_REGISTRY, + ) + @ApiOperation({ + summary: 'Get savepoint state.', + description: 'Get savepoint state.' + ONLY_SR + }) + @ApiParam({ + name: 'policyId', + type: String, + description: 'Policy Id', + required: true, + example: Examples.DB_ID + }) + @ApiBody({ + description: '.' + }) + @ApiOkResponse({ + description: '.' + }) + @ApiInternalServerErrorResponse({ + description: 'Internal server error.', + type: InternalServerErrorDTO + }) + @ApiExtraModels(InternalServerErrorDTO) + @HttpCode(HttpStatus.OK) + async getSavepointState( + @AuthUser() user: IAuthUser, + @Param('policyId') policyId: string, + @Req() req + ) { + const engineService = new PolicyEngine(); + const owner = new EntityOwner(user); + const policy = await engineService.accessPolicy(policyId, owner, 'read'); + if (!PolicyHelper.isDryRunMode(policy)) { + throw new HttpException('Invalid status.', HttpStatus.FORBIDDEN); + } + + const invalidedCacheTags = [`${PREFIXES.POLICIES}${policyId}/navigation`, `${PREFIXES.POLICIES}${policyId}/groups`]; + await this.cacheService.invalidate(getCacheKey([req.url, ...invalidedCacheTags], user)); + + try { + return await engineService.getSavepointState(owner, policyId); + } catch (error) { + await InternalException(error, this.logger); + } + } + /** * Clear dry-run state. */ @@ -2938,8 +2991,8 @@ export class PolicyApi { // UserRole.STANDARD_REGISTRY, ) @ApiOperation({ - summary: 'Restore dru-run savepoint.', - description: 'Restore dru-run savepoint.' + ONLY_SR + summary: 'Restore dry-run savepoint.', + description: 'Restore dry-run savepoint.' + ONLY_SR }) @ApiParam({ name: 'policyId', diff --git a/api-gateway/src/helpers/policy-engine.ts b/api-gateway/src/helpers/policy-engine.ts index 5c2ed1c0ce..16170e4a7b 100644 --- a/api-gateway/src/helpers/policy-engine.ts +++ b/api-gateway/src/helpers/policy-engine.ts @@ -663,6 +663,18 @@ export class PolicyEngine extends NatsService { return await this.sendMessage(PolicyEngineEvents.RESTORE_SAVEPOINT, {model, owner, policyId}); } + /** + * Get savepoint state + * @param owner + * @param policyId + */ + public async getSavepointState( + owner: IOwner, + policyId: string + ) { + return await this.sendMessage(PolicyEngineEvents.GET_SAVEPOINT, {owner, policyId}); + } + /** * Get Virtual Documents * @param policyId diff --git a/application-events/package.json b/application-events/package.json index dfac83d43b..984b9886ac 100644 --- a/application-events/package.json +++ b/application-events/package.json @@ -49,7 +49,7 @@ "@types/http-errors": "^2.0.1", "@types/js-yaml": "^4.0.5", "@types/mocha": "^10.0.1", - "@types/node": "^18.11.9", + "@types/node": "^22.10.10", "@types/swagger-ui-express": "^4.1.3", "chai": "^4.3.7", "chai-http": "^4.3.0", diff --git a/auth-service/package.json b/auth-service/package.json index 33eab6f07e..3fb8fe0880 100644 --- a/auth-service/package.json +++ b/auth-service/package.json @@ -45,7 +45,7 @@ "@types/gulp": "^4", "@types/gulp-rename": "^2", "@types/jsonwebtoken": "^8.5.4", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "@types/node-vault": "^0", "chai": "^4.3.4", "cross-env": "^7.0.3", diff --git a/common/package.json b/common/package.json index 445d9b4369..2d2b0e974b 100644 --- a/common/package.json +++ b/common/package.json @@ -15,7 +15,7 @@ "@nestjs/common": "^9.4.1", "@nestjs/core": "^9.4.1", "@nestjs/microservices": "^9.4.1", - "jsonld-signatures": "7.0.0", + "jsonld-signatures": "11.5.0", "@transmute/credentials-context": "0.7.0-unstable.80", "@transmute/did-context": "0.7.0-unstable.80", "@transmute/ed25519-signature-2018": "0.7.0-unstable.80", @@ -60,7 +60,7 @@ "@types/gulp": "^4", "@types/gulp-rename": "^2", "@types/jszip": "^3.4.1", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "mocha-junit-reporter": "^2.0.2", "tslint": "^6.1.3", "typescript": "^4.5.5", diff --git a/common/src/database-modules/database-server.ts b/common/src/database-modules/database-server.ts index ce2d00b3fc..374804dc1a 100644 --- a/common/src/database-modules/database-server.ts +++ b/common/src/database-modules/database-server.ts @@ -74,52 +74,6 @@ export class DatabaseServer extends AbstractDatabaseServer { ? parseInt(process.env.DOCUMENTS_HANDLING_CHUNK_SIZE, 10) : 500; - /** - * Dry-run - * @private - */ - private dryRun: string = null; - /** - * Dry-run - * @private - */ - private systemMode: boolean = false; - /** - * Dry-run - * @private - */ - private readonly classMap: Map = new Map(); - - constructor(dryRun: string = null) { - super(); - this.dryRun = dryRun || null; - - this.classMap.set(BlockCache, 'BlockCache'); - this.classMap.set(BlockState, 'BlockState'); - this.classMap.set(VcDocumentCollection, 'VcDocumentCollection'); - this.classMap.set(VpDocumentCollection, 'VpDocumentCollection'); - this.classMap.set(DidDocumentCollection, 'DidDocumentCollection'); - this.classMap.set(SchemaCollection, 'SchemaCollection'); - this.classMap.set(DocumentState, 'DocumentState'); - this.classMap.set(Policy, 'Policy'); - this.classMap.set(AggregateVC, 'AggregateVC'); - this.classMap.set(ApprovalDocumentCollection, 'ApprovalDocumentCollection'); - this.classMap.set(TokenCollection, 'TokenCollection'); - this.classMap.set(TopicCollection, 'TopicCollection'); - this.classMap.set(DryRun, 'DryRun'); - this.classMap.set(PolicyRolesCollection, 'PolicyRolesCollection'); - this.classMap.set(PolicyInvitations, 'PolicyInvitations'); - this.classMap.set(MultiDocuments, 'MultiDocuments'); - this.classMap.set(SplitDocuments, 'SplitDocuments'); - this.classMap.set(Tag, 'Tag'); - this.classMap.set(TagCache, 'TagCache'); - this.classMap.set(ExternalDocument, 'ExternalDocument'); - this.classMap.set(PolicyCategory, 'PolicyCategories'); - this.classMap.set(PolicyProperty, 'PolicyProperties'); - this.classMap.set(MintRequest, 'MintRequest'); - this.classMap.set(MintTransaction, 'MintTransaction'); - } - /** * Add dry run id * @param item @@ -151,4044 +105,4102 @@ export class DatabaseServer extends AbstractDatabaseServer { } /** - * Add dry run id - * @param entityClass - * @param item + * Grid fs connect */ - private addDryRunId(entityClass: new () => T, item: unknown): unknown | unknown[] { - return DatabaseServer.addDryRunId( - item, this.dryRun, this.classMap.get(entityClass), this.systemMode - ); + public static connectGridFS() { + DataBaseHelper.connectGridFS(); } /** - * Create much data - * @param entityClass Entity class - * @param item Item - * @param amount Amount + * Set Dry Run id + * @param id */ - private async createMuchData(entityClass: new () => T, item: Partial & { id: string, _id: string }, amount: number): Promise { - const naturalCount = Math.floor((amount / DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE)); - const restCount = (amount % DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE); - - if (this.dryRun) { - this.addDryRunId(entityClass, item); - for (let i = 0; i < naturalCount; i++) { - await new DataBaseHelper(DryRun).createMuchData(item, DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE); - } - await new DataBaseHelper(DryRun).createMuchData(item, restCount); - } else { - for (let i = 0; i < naturalCount; i++) { - await new DataBaseHelper(entityClass).createMuchData(item, DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE); - } - await new DataBaseHelper(entityClass).createMuchData(item, restCount); + public static async setSystemMode(dryRunId: string, systemMode: boolean): Promise { + const items = await new DataBaseHelper(DryRun).find({dryRunId}); + for (const item of items) { + item.systemMode = systemMode; } + await new DataBaseHelper(DryRun).update(items); } /** - * Find data by aggregation - * @param entityClass Entity class - * @param aggregation aggregate filter - * @returns + * Create savepoint + * @param dryRunId + * @param systemMode */ - public async aggregate(entityClass: new () => T, aggregation: FilterObject[]): Promise { - if (this.dryRun) { - const dryRunClass = this.classMap.get(entityClass); - - return await new DataBaseHelper(DryRun).aggregateDryRan(aggregation, this.dryRun, dryRunClass) as unknown as T[]; - } else { - return await new DataBaseHelper(entityClass).aggregate(aggregation); + public static async createSavepoint(dryRunId: string): Promise { + const limit = {limit: DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE}; + const amount = await new DataBaseHelper(DryRun).count({dryRunId}); + const naturalCount = Math.floor(amount / DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE); + for (let i = 0; i < naturalCount; i++) { + const items = await new DataBaseHelper(DryRun).find({dryRunId}, limit); + for (const item of items) { + item.savepoint = true; + } + await new DataBaseHelper(DryRun).update(items); } - } - - /** - * Assign entity - * @param type - * @param entityId - * @param assigned - * @param did - * @param owner - */ - public static async assignEntity( - type: AssignedEntityType, - entityId: string, - assigned: boolean, - did: string, - owner: string - ): Promise { - const item = new DataBaseHelper(AssignEntity).create({ type, entityId, assigned, did, owner }); - return await new DataBaseHelper(AssignEntity).save(item); - } - - /** - * Check User In Group - * @param group - * - * @virtual - */ - public async checkUserInGroup(group: { policyId: string, did: string, owner: string, uuid: string }): Promise { - return await this.findOne(PolicyRolesCollection, { - policyId: group.policyId, - did: group.did, - owner: group.owner, - uuid: group.uuid - }); - } + const restItems = await new DataBaseHelper(DryRun).find({dryRunId}); + for (const item of restItems) { + item.savepoint = true; + } + await new DataBaseHelper(DryRun).update(restItems); - /** - * Clear Dry Run table - * @param systemMode - */ - public async clear(all: boolean) { - await DatabaseServer.clearDryRun(this.dryRun, all); + // const files = await new DataBaseHelper(DryRunFiles).find({ policyId: dryRunId }); + // await new DataBaseHelper(DryRunFiles).remove(files); } /** - * Clear Dry Run table + * Restore savepoint * @param dryRunId * @param systemMode */ - public static async clearDryRun(dryRunId: string, all: boolean): Promise { - const filter = all ? { dryRunId } : { dryRunId, systemMode: { $ne: true } }; - const limit = { limit: DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE }; - const amount = await new DataBaseHelper(DryRun).count(filter); + public static async restoreSavepoint(dryRunId: string): Promise { + const limit = {limit: DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE}; + const amount = await new DataBaseHelper(DryRun).count({dryRunId, savepoint: {$exists: false}}); const naturalCount = Math.floor(amount / DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE); for (let i = 0; i < naturalCount; i++) { - const items = await new DataBaseHelper(DryRun).find(filter, limit); + const items = await new DataBaseHelper(DryRun).find({dryRunId, savepoint: {$exists: false}}, limit); await new DataBaseHelper(DryRun).remove(items); } - const restItems = await new DataBaseHelper(DryRun).find(filter); + const restItems = await new DataBaseHelper(DryRun).find({dryRunId, savepoint: {$exists: false}}); await new DataBaseHelper(DryRun).remove(restItems); - const files = await new DataBaseHelper(DryRunFiles).find({ policyId: dryRunId }); - await new DataBaseHelper(DryRunFiles).remove(files); + // const files = await new DataBaseHelper(DryRunFiles).find({ policyId: dryRunId }); + // await new DataBaseHelper(DryRunFiles).remove(files); } /** - * Clear policy cache data - * @param cachePolicyId Cache policy id + * Get savepoint state + * @param dryRunId + * @param systemMode */ - public static async clearPolicyCacheData(cachePolicyId: string) { - const amount = await new DataBaseHelper(PolicyCacheData).count({ - cachePolicyId - }); - const naturalCount = Math.floor( - amount / DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE - ); - for (let i = 0; i < naturalCount; i++) { - const items = await new DataBaseHelper(PolicyCacheData).find( - { cachePolicyId }, - { limit: DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE } - ); - await new DataBaseHelper(PolicyCacheData).remove( - items.map((item) => { - item._id = item.newId; - item.id = item.newId.toString(); - return item; - }) - ); - } - const restItems = await new DataBaseHelper(PolicyCacheData).find({ - cachePolicyId - }); - await new DataBaseHelper(PolicyCacheData).remove( - restItems.map((item) => { - item._id = item.newId; - item.id = item.newId.toString(); - return item; - }) - ); + public static async getSavepointSate(dryRunId: string): Promise { + return await new DataBaseHelper(DryRun).findOne({dryRunId, savepoint: true}); + + // const files = await new DataBaseHelper(DryRunFiles).find({ policyId: dryRunId }); + // await new DataBaseHelper(DryRunFiles).remove(files); } /** - * Clear policy caches - * @param filters Filters + * Get schemas + * @param filters */ - public static async clearPolicyCaches(filters?: FilterObject | string): Promise { - const policyCaches = await new DataBaseHelper(PolicyCache).find( - filters - ); - if (!policyCaches) { - return; - } - for (const policyCache of policyCaches) { - const cachePolicyId = policyCache.id; - await new DataBaseHelper(PolicyCache).remove(policyCache); - await DatabaseServer.clearPolicyCacheData(cachePolicyId); - } + public static async getSchema(filters?: FilterObject | string): Promise { + return await new DataBaseHelper(SchemaCollection).findOne(filters); } /** - * Set MongoDriver - * @param db + * Create Statistic + * @param statistic */ - public static connectBD(db: MikroORM): void { - DataBaseHelper.connectBD(db); + public static async createStatistic( + statistic: FilterObject + ): Promise { + const item = new DataBaseHelper(PolicyStatistic).create(statistic); + return await new DataBaseHelper(PolicyStatistic).save(item); } /** - * Overriding the count method - * @param entityClass + * Get Statistics * @param filters * @param options */ - public async count(entityClass: new () => T, filters: FilterQuery, options?: FindOptions): Promise { - if (this.dryRun) { - - const _filters = { - ...filters as FilterObject, - dryRunId: this.dryRun, - dryRunClass: this.classMap.get(entityClass) - }; - - return await new DataBaseHelper(DryRun).count(_filters, options); - } else { - return await new DataBaseHelper(entityClass).count(filters, options); - } + public static async getStatisticsAndCount( + filters?: FilterObject, + options?: FindOptions + ): Promise<[PolicyStatistic[], number]> { + return await new DataBaseHelper(PolicyStatistic).findAndCount(filters, options); } /** - * Get MultiPolicyTransaction count - * @param policyId + * Get Statistic By ID + * @param id */ - public static async countMultiPolicyTransactions(policyId: string): Promise { - return await new DataBaseHelper(MultiPolicyTransaction).count({ policyId, status: 'Waiting' }); - } + public static async getStatisticById(id: string): Promise { + return await new DataBaseHelper(PolicyStatistic).findOne(id); + } /** - * Overriding the create method - * @param entityClass - * @param item + * Get Statistic + * @param filters */ - public create(entityClass: new () => T, item: Partial): T { - if (this.dryRun) { - return (new DataBaseHelper(DryRun).create(item)) as unknown as T; - } else { - return new DataBaseHelper(entityClass).create(item); - } + public static async getStatistic(filters: FilterQuery): Promise { + return await new DataBaseHelper(PolicyStatistic).findOne(filters); } /** - * Create Aggregate Documents - * @param item - * @param blockId - * - * @virtual + * Delete Statistic + * @param statistic */ - public async createAggregateDocuments(item: VcDocumentCollection & { blockId: string }, blockId: string): Promise { - item.blockId = blockId; - const newVC = this.create(AggregateVC, item); - await this.save(AggregateVC, newVC); + public static async removeStatistic(statistic: PolicyStatistic): Promise { + return await new DataBaseHelper(PolicyStatistic).remove(statistic); } /** - * Get schema - * @param item + * Get Statistics + * @param filters + * @param options */ - public static async createAndSaveSchema(item: Partial): Promise { - return await new DataBaseHelper(SchemaCollection).save(item); + public static async getStatistics( + filters?: FilterQuery, + options?: unknown + ): Promise { + return await new DataBaseHelper(PolicyStatistic).find(filters, options); } /** - * Create External Topic + * Update Statistic * @param row - * - * @virtual */ - public async createExternalTopic(row: unknown): Promise { - const item = this.create(ExternalDocument, row); - return await this.save(ExternalDocument, item); + public static async updateStatistic(row: PolicyStatistic): Promise { + return await new DataBaseHelper(PolicyStatistic).update(row); } /** - * Create invite token - * @param policyId - * @param uuid - * @param owner - * @param role - * - * @virtual + * Get documents + * @param filters + * @param options */ - public async createInviteToken(policyId: string, uuid: string, owner: string, role: string): Promise { - const doc = this.create(PolicyInvitations, { - uuid, - policyId, - owner, - role, - active: true - }); - await this.save(PolicyInvitations, doc); - return doc.id.toString(); + public static async getStatisticDocumentsAndCount( + filters?: FilterObject, + options?: FindOptions + ): Promise<[VcDocumentCollection[], number]> { + return await new DataBaseHelper(VcDocumentCollection).findAndCount(filters, options); } /** - * Create mint transactions - * @param transaction Transaction - * @param amount Amount + * Get documents + * @param filters + * @param options */ - public async createMintTransactions(transaction: Partial, amount: number): Promise { - await this.createMuchData(MintTransaction, transaction as Partial & { id: string, _id: string }, amount); + public static async getStatisticDocuments( + filters?: FilterQuery, + options?: unknown + ): Promise { + return await new DataBaseHelper(VcDocumentCollection).find(filters, options); } /** - * Create createModules - * @param module + * Get document + * @param filters + * @param options */ - public static async createModules(module: PolicyModule): Promise { - module.name = module.name.replace(/\s+/g, ' ').trim(); - const dbHelper = new DataBaseHelper(PolicyModule); - const item = dbHelper.create(module); - if ( - (await dbHelper.count({ - name: item.name, - owner: item.owner - })) > 0 - ) { - throw new Error(`Module with name ${item.name} is already exists`); - } - return await dbHelper.save(item); + public static async getStatisticDocument( + filters?: FilterQuery, + options?: unknown + ): Promise { + return await new DataBaseHelper(VcDocumentCollection).findOne(filters, options); } /** - * Create Multi Policy object - * @param multiPolicy - * @returns MultiPolicy + * Create Statistic + * @param assessment */ - public static createMultiPolicy(multiPolicy: MultiPolicy): MultiPolicy { - return new DataBaseHelper(MultiPolicy).create(multiPolicy); + public static async createStatisticAssessment( + assessment: FilterObject + ): Promise { + const item = new DataBaseHelper(PolicyStatisticDocument).create(assessment); + return await new DataBaseHelper(PolicyStatisticDocument).save(item); } /** - * Create MultiPolicyTransaction - * @param transaction + * Get statistic assessment + * @param filters */ - public static async createMultiPolicyTransaction(transaction: FilterObject): Promise { - const item = new DataBaseHelper(MultiPolicyTransaction).create(transaction); - return await new DataBaseHelper(MultiPolicyTransaction).save(item); + public static async getStatisticAssessment( + filters: FilterQuery + ): Promise { + return await new DataBaseHelper(PolicyStatisticDocument).findOne(filters); } /** - * Create policy - * @param data + * Get statistic assessments + * @param filters + * @param options */ - public static createPolicy(data: Partial): Policy { - if (!data.config) { - data.config = { - 'id': GenerateUUIDv4(), - 'blockType': 'interfaceContainerBlock', - 'permissions': [ - 'ANY_ROLE' - ] - }; - } - const model = new DataBaseHelper(Policy).create(data); - return model; + public static async getStatisticAssessmentsAndCount( + filters?: FilterObject, + options?: FindOptions + ): Promise<[PolicyStatisticDocument[], number]> { + return await new DataBaseHelper(PolicyStatisticDocument).findAndCount(filters, options); } /** - * Assign entity - * @param config - * @param buffer + * Get statistic assessment count + * @param filters */ - public static async createPolicyTest(config: { [key: string]: unknown }, buffer: Buffer): Promise { - const file = await DatabaseServer.saveFile(GenerateUUIDv4(), buffer); - const item = new DataBaseHelper(PolicyTest).create({ ...config, file }); - return await new DataBaseHelper(PolicyTest).save(item); + public static async getStatisticAssessmentCount( + filters?: FilterObject + ): Promise { + return await new DataBaseHelper(PolicyStatisticDocument).count(filters); } /** - * Create Record - * @param record + * Create Schema Rule + * @param rule */ - public static async createRecord(record: FilterObject): Promise { - const item = new DataBaseHelper(Record).create(record); - return await new DataBaseHelper(Record).save(item); + public static async createSchemaRule( + rule: FilterObject + ): Promise { + const item = new DataBaseHelper(SchemaRule).create(rule); + return await new DataBaseHelper(SchemaRule).save(item); } /** - * Create Residue object - * @param policyId - * @param blockId - * @param userId - * @param value - * @param document + * Get Schema Rule + * @param filters + * @param options */ - public createResidue( - policyId: string, - blockId: string, - userId: string, - value: unknown, - document: unknown - ): SplitDocuments { - return this.create(SplitDocuments, { - policyId, - blockId, - userId, - value, - document - }); + public static async getSchemaRulesAndCount( + filters?: FilterObject, + options?: FindOptions + ): Promise<[SchemaRule[], number]> { + return await new DataBaseHelper(SchemaRule).findAndCount(filters, options); } /** - * Get schema - * @param item + * Get Schema Rule + * @param filters + * @param options */ - public static createSchema(item: Partial): SchemaCollection { - return new DataBaseHelper(SchemaCollection).create(item); + public static async getSchemaRules( + filters?: FilterObject, + options?: unknown + ): Promise { + return await new DataBaseHelper(SchemaRule).find(filters, options); } /** - * Create tag - * @param tag + * Get Schema Rule By ID + * @param id */ - public async createTag(tag: Tag): Promise { - const item = this.create(Tag, tag); - return await this.save(Tag, item); + public static async getSchemaRuleById(id: string): Promise { + return await new DataBaseHelper(SchemaRule).findOne(id); } /** - * Create tag - * @param tag + * Update Schema Rule + * @param rule */ - public static async createTag(tag: FilterObject): Promise { - const item = new DataBaseHelper(Tag).create(tag); - return await new DataBaseHelper(Tag).save(item); + public static async updateSchemaRule(rule: SchemaRule): Promise { + return await new DataBaseHelper(SchemaRule).update(rule); } /** - * Create tag cache - * @param tag + * Delete Schema Rule + * @param rule */ - public async createTagCache(tag: Partial): Promise { - const item = this.create(TagCache, tag); - return await this.save(TagCache, item); + public static async removeSchemaRule(rule: SchemaRule): Promise { + return await new DataBaseHelper(SchemaRule).remove(rule); } /** - * Create tag cache - * @param tag + * Create Policy Label + * @param label */ - public static async createTagCache(tag: FilterObject): Promise { - const item = new DataBaseHelper(TagCache).create(tag); - return await new DataBaseHelper(TagCache).save(item); - } + public static async createPolicyLabel( + label: FilterObject + ): Promise { + const item = new DataBaseHelper(PolicyLabel).create(label); + return await new DataBaseHelper(PolicyLabel).save(item); + } /** - * Create Theme - * @param theme + * Get Policy Label + * @param filters + * @param options */ - public static async createTheme(theme: FilterObject): Promise { - const item = new DataBaseHelper(Theme).create(theme); - return await new DataBaseHelper(Theme).save(item); + public static async getPolicyLabelsAndCount( + filters?: FilterObject, + options?: FindOptions + ): Promise<[PolicyLabel[], number]> { + return await new DataBaseHelper(PolicyLabel).findAndCount(filters, options); } /** - * Create Token - * @param token - * @returns + * Get Policy Label + * @param filters + * @param options */ - public async createToken(token: unknown): Promise { - const newToken = this.create(TokenCollection, token); - return await this.save(TokenCollection, newToken); + public static async getPolicyLabels( + filters?: FilterObject, + options?: unknown + ): Promise { + return await new DataBaseHelper(PolicyLabel).find(filters, options); } /** - * Create Tool - * @param tool + * Get Policy Label By ID + * @param id */ - public static async createTool(tool: PolicyTool): Promise { - const item = new DataBaseHelper(PolicyTool).create(tool); - return await new DataBaseHelper(PolicyTool).save(item); + public static async getPolicyLabelById(id: string): Promise { + return await new DataBaseHelper(PolicyLabel).findOne(id); } /** - * Create Virtual User - * @param policyId - * @param username - * @param did - * @param hederaAccountId - * @param hederaAccountKey - * @param active - * - * @virtual + * Update Policy Label + * @param label */ - public static async createVirtualUser( - policyId: string, - username: string, - did: string, - hederaAccountId: string, - hederaAccountKey: string, - active: boolean, - systemMode?: boolean - ): Promise { - await new DataBaseHelper(DryRun).save(DatabaseServer.addDryRunId({ - did, - username, - hederaAccountId, - active - }, policyId, 'VirtualUsers', !!systemMode)); - - if (hederaAccountKey) { - await new DataBaseHelper(DryRun).save(DatabaseServer.addDryRunId({ - did, - type: did, - hederaAccountKey - }, policyId, 'VirtualKey', !!systemMode)); - } + public static async updatePolicyLabel(label: PolicyLabel): Promise { + return await new DataBaseHelper(PolicyLabel).update(label); } /** - * Create Virtual User - * @param policyId - * @param username - * @param did - * @param hederaAccountId - * @param hederaAccountKey - * @param active - * - * @virtual + * Delete Policy Label + * @param label */ - public async createVirtualUser( - username: string, - did: string, - hederaAccountId: string, - hederaAccountKey: string, - active: boolean = false - ): Promise { - await DatabaseServer.createVirtualUser( - this.dryRun, - username, - did, - hederaAccountId, - hederaAccountKey, - active, - this.systemMode - ); + public static async removePolicyLabel(label: PolicyLabel): Promise { + return await new DataBaseHelper(PolicyLabel).remove(label); } /** - * Overriding the create method - * @param entityClass - * @param filters + * Create Label Document + * @param document */ - public deleteEntity(entityClass: new () => T, filters: FilterObject | string | ObjectId): Promise { - return new DataBaseHelper(entityClass).delete(filters); + public static async createLabelDocument( + document: FilterObject + ): Promise { + const item = new DataBaseHelper(PolicyLabelDocument).create(document); + return await new DataBaseHelper(PolicyLabelDocument).save(item); } /** - * Delete user - * @param group - * - * @virtual + * Get statistic assessments + * @param filters + * @param options */ - public async deleteGroup(group: PolicyRolesCollection): Promise { - return await this.remove(PolicyRolesCollection, group); + public static async getLabelDocumentsAndCount( + filters?: FilterObject, + options?: FindOptions + ): Promise<[PolicyLabelDocument[], number]> { + return await new DataBaseHelper(PolicyLabelDocument).findAndCount(filters, options); } /** - * Delete policy - * @param id Policy ID + * Get statistic assessment + * @param filters */ - public static async deletePolicy(id: string): Promise { - await new DataBaseHelper(Policy).delete({ id }); + public static async getLabelDocument( + filters: FilterQuery + ): Promise { + return await new DataBaseHelper(PolicyLabelDocument).findOne(filters); } /** - * Get policy tests - * @param policyId - * @param id - * @returns tests + * Restore States */ - public static async deletePolicyTest(policyId: string, id: string): Promise { - await new DataBaseHelper(PolicyTest).delete({ id, policyId }); + public static async restoreStates(policyId: string): Promise { + const states = await new DataBaseHelper(BlockState).find({policyId}); + for (const state of states) { + state.blockState = state.savedState; + await new DataBaseHelper(BlockState).save(state); + } } /** - * Get policy tests - * @param policyId - * - * @returns tests + * Copy States */ - public static async deletePolicyTests(policyId: string): Promise { - await new DataBaseHelper(PolicyTest).delete({ policyId }); + public static async copyStates(policyId: string): Promise { + const states = await new DataBaseHelper(BlockState).find({policyId}); + for (const state of states) { + state.savedState = state.blockState; + await new DataBaseHelper(BlockState).save(state); + } } /** - * Delete schemas - * @param id + * Create Formula + * @param formula */ - public static async deleteSchemas(id: string): Promise { - await new DataBaseHelper(SchemaCollection).delete({ id }); + public static async createFormula( + formula: FilterObject + ): Promise { + const item = new DataBaseHelper(Formula).create(formula); + return await new DataBaseHelper(Formula).save(item); } /** - * Overriding the find method - * @param entityClass + * Get Formulas * @param filters * @param options */ - public async find(entityClass: new () => T, filters: FilterQuery | string | ObjectId, options?: unknown): Promise { - if (this.dryRun) { - - const _filters = { - ...filters as FilterObject, - dryRunId: this.dryRun, - dryRunClass: this.classMap.get(entityClass) - }; - - return (await new DataBaseHelper(DryRun).find(_filters, options)) as unknown as T[]; - } else { - return await new DataBaseHelper(entityClass).find(filters, options); - } + public static async getFormulasAndCount( + filters?: FilterObject, + options?: FindOptions + ): Promise<[Formula[], number]> { + return await new DataBaseHelper(Formula).findAndCount(filters, options); } /** - * Overriding the findAll method - * @param entityClass + * Get Formulas + * @param filters * @param options */ - public async findAll(entityClass: new () => T, options?: FindAllOptions): Promise { - return await new DataBaseHelper(entityClass).findAll(options); + public static async getFormulas( + filters?: FilterObject, + options?: unknown + ): Promise { + return await new DataBaseHelper(Formula).find(filters, options); } /** - * Overriding the findAndCount method - * @param entityClass - * @param filters - * @param options + * Get Formula By ID + * @param id */ - public async findAndCount(entityClass: new () => T, filters: FilterQuery | string | ObjectId, options?: unknown): Promise<[T[], number]> { - return await new DataBaseHelper(entityClass).findAndCount(filters, options); + public static async getFormulaById(id: string): Promise { + return await new DataBaseHelper(Formula).findOne(id); } /** - * Overriding the findOne method - * @param entityClass - * @param filters - * @param options + * Update Formula + * @param formula */ - public async findOne(entityClass: new () => T, filters: FilterQuery, options: unknown = {}): Promise { - if (this.dryRun) { - if (typeof filters === 'string') { - return (await new DataBaseHelper(DryRun).findOne(filters, options)) as unknown as T; - } - - const _filters = { - ...filters as FilterObject, - dryRunId: this.dryRun, - dryRunClass: this.classMap.get(entityClass) - }; - - return (await new DataBaseHelper(DryRun).findOne(_filters, options)) as unknown as T; - } else { - return await new DataBaseHelper(entityClass).findOne(filters, options); - } + public static async updateFormula(formula: Formula): Promise { + return await new DataBaseHelper(Formula).update(formula); } /** - * Get Active External Topic - * @param policyId - * @param blockId - * - * @virtual + * Delete Formula + * @param formula */ - public async getActiveExternalTopics( - policyId: string, - blockId: string - ): Promise { - return await this.find(ExternalDocument, { - policyId: { $eq: policyId }, - blockId: { $eq: blockId }, - active: { $eq: true } - }); + public static async removeFormula(formula: Formula): Promise { + return await new DataBaseHelper(Formula).remove(formula); } /** - * Get Active Group By User - * @param policyId - * @param did - * - * @virtual + * Dry-run + * @private */ - public async getActiveGroupByUser(policyId: string, did: string): Promise { - if (!did) { - return null; + private dryRun: string = null; + /** + * Dry-run + * @private + */ + private systemMode: boolean = false; + /** + * Dry-run + * @private + */ + private readonly classMap: Map = new Map(); + + constructor(dryRun: string = null) { + super(); + this.dryRun = dryRun || null; + + this.classMap.set(BlockCache, 'BlockCache'); + this.classMap.set(BlockState, 'BlockState'); + this.classMap.set(VcDocumentCollection, 'VcDocumentCollection'); + this.classMap.set(VpDocumentCollection, 'VpDocumentCollection'); + this.classMap.set(DidDocumentCollection, 'DidDocumentCollection'); + this.classMap.set(SchemaCollection, 'SchemaCollection'); + this.classMap.set(DocumentState, 'DocumentState'); + this.classMap.set(Policy, 'Policy'); + this.classMap.set(AggregateVC, 'AggregateVC'); + this.classMap.set(ApprovalDocumentCollection, 'ApprovalDocumentCollection'); + this.classMap.set(TokenCollection, 'TokenCollection'); + this.classMap.set(TopicCollection, 'TopicCollection'); + this.classMap.set(DryRun, 'DryRun'); + this.classMap.set(PolicyRolesCollection, 'PolicyRolesCollection'); + this.classMap.set(PolicyInvitations, 'PolicyInvitations'); + this.classMap.set(MultiDocuments, 'MultiDocuments'); + this.classMap.set(SplitDocuments, 'SplitDocuments'); + this.classMap.set(Tag, 'Tag'); + this.classMap.set(TagCache, 'TagCache'); + this.classMap.set(ExternalDocument, 'ExternalDocument'); + this.classMap.set(PolicyCategory, 'PolicyCategories'); + this.classMap.set(PolicyProperty, 'PolicyProperties'); + this.classMap.set(MintRequest, 'MintRequest'); + this.classMap.set(MintTransaction, 'MintTransaction'); + } + + /** + * Add dry run id + * @param entityClass + * @param item + */ + private addDryRunId(entityClass: new () => T, item: unknown): unknown | unknown[] { + return DatabaseServer.addDryRunId( + item, this.dryRun, this.classMap.get(entityClass), this.systemMode + ); + } + + /** + * Create much data + * @param entityClass Entity class + * @param item Item + * @param amount Amount + */ + private async createMuchData(entityClass: new () => T, item: Partial & { id: string, _id: string }, amount: number): Promise { + const naturalCount = Math.floor((amount / DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE)); + const restCount = (amount % DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE); + + if (this.dryRun) { + this.addDryRunId(entityClass, item); + for (let i = 0; i < naturalCount; i++) { + await new DataBaseHelper(DryRun).createMuchData(item, DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE); + } + await new DataBaseHelper(DryRun).createMuchData(item, restCount); + } else { + for (let i = 0; i < naturalCount; i++) { + await new DataBaseHelper(entityClass).createMuchData(item, DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE); + } + await new DataBaseHelper(entityClass).createMuchData(item, restCount); } - return await this.findOne(PolicyRolesCollection, { policyId, did, active: true }); } /** - * Get Aggregate Documents - * @param policyId - * @param blockId - * @param filters - * - * @virtual + * Find data by aggregation + * @param entityClass Entity class + * @param aggregation aggregate filter + * @returns */ - public async getAggregateDocuments( - policyId: string, - blockId: string, - filters: FilterObject = {}, - ): Promise { - return await this.find(AggregateVC, { policyId, blockId, ...filters }); + public async aggregate(entityClass: new () => T, aggregation: FilterObject[]): Promise { + if (this.dryRun) { + const dryRunClass = this.classMap.get(entityClass); + + return await new DataBaseHelper(DryRun).aggregateDryRan(aggregation, this.dryRun, dryRunClass) as unknown as T[]; + } else { + return await new DataBaseHelper(entityClass).aggregate(aggregation); + } } /** - * Get aggregate document by policy identifier - * @param policyId Policy identifier - * @returns Aggregate documents + * Assign entity + * @param type + * @param entityId + * @param assigned + * @param did + * @param owner */ - public async getAggregateDocumentsByPolicy( - policyId: string, - ): Promise { - return await this.find(AggregateVC, { policyId }); + public static async assignEntity( + type: AssignedEntityType, + entityId: string, + assigned: boolean, + did: string, + owner: string + ): Promise { + const item = new DataBaseHelper(AssignEntity).create({ type, entityId, assigned, did, owner }); + return await new DataBaseHelper(AssignEntity).save(item); } /** - * Get members - * + * Check User In Group * @param group * * @virtual */ - public async getAllMembersByGroup(group: PolicyRolesCollection): Promise { - if (!group.uuid) { - return []; - } - return await this.find(PolicyRolesCollection, { + public async checkUserInGroup(group: { policyId: string, did: string, owner: string, uuid: string }): Promise { + return await this.findOne(PolicyRolesCollection, { policyId: group.policyId, + did: group.did, + owner: group.owner, uuid: group.uuid }); } /** - * Get all policy users - * @param policyId - * - * @virtual + * Clear Dry Run table + * @param systemMode */ - public async getAllPolicyUsers(policyId: string): Promise { - return await this.find(PolicyRolesCollection, { policyId, active: true }); + public async clear(all: boolean) { + await DatabaseServer.clearDryRun(this.dryRun, all); } /** - * Get all policy users - * @param policyId - * @param uuid - * @param role - * - * @virtual + * Clear Dry Run table + * @param dryRunId + * @param systemMode */ - public async getAllUsersByRole(policyId: string, uuid: string, role: string): Promise { - return await this.find(PolicyRolesCollection, { policyId, uuid, role }); + public static async clearDryRun(dryRunId: string, all: boolean): Promise { + const filter = all ? { dryRunId } : { dryRunId, systemMode: { $ne: true } }; + const limit = { limit: DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE }; + const amount = await new DataBaseHelper(DryRun).count(filter); + const naturalCount = Math.floor(amount / DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE); + for (let i = 0; i < naturalCount; i++) { + const items = await new DataBaseHelper(DryRun).find(filter, limit); + await new DataBaseHelper(DryRun).remove(items); + } + const restItems = await new DataBaseHelper(DryRun).find(filter); + await new DataBaseHelper(DryRun).remove(restItems); + + const files = await new DataBaseHelper(DryRunFiles).find({ policyId: dryRunId }); + await new DataBaseHelper(DryRunFiles).remove(files); } /** - * get document aggregation filters for analytics - * @param nameFilter - * @param uuid - * - * @returns Result + * Clear policy cache data + * @param cachePolicyId Cache policy id */ - public getAnalyticsDocAggregationFilters(nameFilter: string, uuid: string): unknown[] { - return DataBaseHelper.getAnalyticsDocAggregationFilters(nameFilter, uuid); + public static async clearPolicyCacheData(cachePolicyId: string) { + const amount = await new DataBaseHelper(PolicyCacheData).count({ + cachePolicyId + }); + const naturalCount = Math.floor( + amount / DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE + ); + for (let i = 0; i < naturalCount; i++) { + const items = await new DataBaseHelper(PolicyCacheData).find( + { cachePolicyId }, + { limit: DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE } + ); + await new DataBaseHelper(PolicyCacheData).remove( + items.map((item) => { + item._id = item.newId; + item.id = item.newId.toString(); + return item; + }) + ); + } + const restItems = await new DataBaseHelper(PolicyCacheData).find({ + cachePolicyId + }); + await new DataBaseHelper(PolicyCacheData).remove( + restItems.map((item) => { + item._id = item.newId; + item.id = item.newId.toString(); + return item; + }) + ); } /** - * Get and count policy cache data + * Clear policy caches * @param filters Filters - * @param options Options - * @returns Policy cache data and count */ - public static async getAndCountPolicyCacheData( - filters?: FilterObject, - options?: unknown - ): Promise<[PolicyCacheData[], number]> { - return await new DataBaseHelper(PolicyCacheData).findAndCount( - filters, - options + public static async clearPolicyCaches(filters?: FilterObject | string): Promise { + const policyCaches = await new DataBaseHelper(PolicyCache).find( + filters ); + if (!policyCaches) { + return; + } + for (const policyCache of policyCaches) { + const cachePolicyId = policyCache.id; + await new DataBaseHelper(PolicyCache).remove(policyCache); + await DatabaseServer.clearPolicyCacheData(cachePolicyId); + } } /** - * Get Approval Document - * @param filters - * - * @virtual + * Set MongoDriver + * @param db */ - public async getApprovalDocument(filters: FilterQuery): Promise { - return await this.findOne(ApprovalDocumentCollection, filters); + public static connectBD(db: MikroORM): void { + DataBaseHelper.connectBD(db); } /** - * Get Approval Documents + * Overriding the count method + * @param entityClass * @param filters * @param options - * @param countResult - * @virtual - */ - public async getApprovalDocuments(filters: FilterObject, options?: FindOptions, countResult?: boolean): Promise { - if (countResult) { - return await this.count(ApprovalDocumentCollection, filters, options); - } - return await this.find(ApprovalDocumentCollection, filters, options); - } - - /** - * Get Approval Documents - * @param aggregation - * @virtual */ - public async getApprovalDocumentsByAggregation(aggregation: FilterObject[]): Promise { - return await this.aggregate(ApprovalDocumentCollection, aggregation) as ApprovalDocumentCollection[]; - } - - /** - * Get Artifact - * @param filters Filters - * @returns Artifact - */ - public static async getArtifact(filters?: FilterQuery): Promise { - return await new DataBaseHelper(ArtifactCollection).findOne(filters); - } + public async count(entityClass: new () => T, filters: FilterQuery, options?: FindOptions): Promise { + if (this.dryRun) { - /** - * Get Artifact File By UUID - * @param uuid File UUID - * @returns Buffer - */ - public static async getArtifactFileByUUID(uuid: string): Promise { - const artifactChunks = (await new DataBaseHelper(ArtifactChunkCollection).find({ - uuid - }, { - orderBy: { - number: 'ASC' - } - })).map(item => item.data.buffer); - return artifactChunks.length > 0 ? Buffer.concat(artifactChunks) : Buffer.from(''); - } + const _filters = { + ...filters as FilterObject, + dryRunId: this.dryRun, + dryRunClass: this.classMap.get(entityClass) + }; - /** - * Get Artifacts - * @param filters Filters - * @param options Options - * @returns Artifacts - */ - public static async getArtifacts(filters?: FilterQuery, options?: FindOptions): Promise { - return await new DataBaseHelper(ArtifactCollection).find(filters, options); + return await new DataBaseHelper(DryRun).count(_filters, options); + } else { + return await new DataBaseHelper(entityClass).count(filters, options); + } } /** - * Get Artifacts - * @param filters Filters - * @param options Options - * @returns Artifacts + * Get MultiPolicyTransaction count + * @param policyId */ - public static async getArtifactsAndCount(filters?: FilterObject, options?: FindOptions): Promise<[ArtifactCollection[], number]> { - return await new DataBaseHelper(ArtifactCollection).findAndCount(filters, options); + public static async countMultiPolicyTransactions(policyId: string): Promise { + return await new DataBaseHelper(MultiPolicyTransaction).count({ policyId, status: 'Waiting' }); } /** - * Get assigned entities - * @param did - * @param type + * Overriding the create method + * @param entityClass + * @param item */ - public static async getAssignedEntities(did: string, type?: AssignedEntityType): Promise { - if (type) { - return await (new DataBaseHelper(AssignEntity)).find({ type, did }); + public create(entityClass: new () => T, item: Partial): T { + if (this.dryRun) { + return (new DataBaseHelper(DryRun).create(item)) as unknown as T; } else { - return await (new DataBaseHelper(AssignEntity)).find({ did }); + return new DataBaseHelper(entityClass).create(item); } } /** - * Check entity - * @param type - * @param entityId - * @param did + * Create Aggregate Documents + * @param item + * @param blockId + * + * @virtual */ - public static async getAssignedEntity(type: AssignedEntityType, entityId: string, did: string): Promise { - return await (new DataBaseHelper(AssignEntity)).findOne({ type, entityId, did }); + public async createAggregateDocuments(item: VcDocumentCollection & { blockId: string }, blockId: string): Promise { + item.blockId = blockId; + const newVC = this.create(AggregateVC, item); + await this.save(AggregateVC, newVC); } /** - * get document aggregation filters for analytics - * @param nameFilterMap - * @param nameFilterAttributes - * @param existingAttributes - * - * @returns Result + * Get schema + * @param item */ - public getAttributesAggregationFilters(nameFilterMap: string, nameFilterAttributes: string, existingAttributes: string[] | []): unknown[] { - return DataBaseHelper.getAttributesAggregationFilters(nameFilterMap, nameFilterAttributes, existingAttributes); + public static async createAndSaveSchema(item: Partial): Promise { + return await new DataBaseHelper(SchemaCollection).save(item); } /** - * Get Block State - * @param {string} policyId - policy ID - * @param {string} blockId - block UUID - * @param {string} did - user DID - * @param {string} name - variable name + * Create External Topic + * @param row * - * @returns {BlockCache | null} - variable value * @virtual */ - public async getBlockCache( - policyId: string, - blockId: string, - did: string, - name: string - ): Promise { - return await this.findOne(BlockCache, { - policyId, - blockId, - did, - name - }); + public async createExternalTopic(row: unknown): Promise { + const item = this.create(ExternalDocument, row); + return await this.save(ExternalDocument, item); } /** - * Get Block State + * Create invite token * @param policyId * @param uuid + * @param owner + * @param role * * @virtual */ - public async getBlockState(policyId: string, uuid: string): Promise { - return await this.findOne(BlockState, { + public async createInviteToken(policyId: string, uuid: string, owner: string, role: string): Promise { + const doc = this.create(PolicyInvitations, { + uuid, policyId, - blockId: uuid + owner, + role, + active: true }); + await this.save(PolicyInvitations, doc); + return doc.id.toString(); } /** - * Get block states - * @param policyId Policy identifier - * @returns Block states + * Create mint transactions + * @param transaction Transaction + * @param amount Amount */ - public async getBlockStates(policyId: string): Promise { - return await this.find(BlockState, { - policyId - }); + public async createMintTransactions(transaction: Partial, amount: number): Promise { + await this.createMuchData(MintTransaction, transaction as Partial & { id: string, _id: string }, amount); } /** - * Get Contract by ID - * @param id + * Create createModules + * @param module */ - public static async getContractById(id: string | null): Promise { - return await new DataBaseHelper(ContractCollection).findOne(id); + public static async createModules(module: PolicyModule): Promise { + module.name = module.name.replace(/\s+/g, ' ').trim(); + const dbHelper = new DataBaseHelper(PolicyModule); + const item = dbHelper.create(module); + if ( + (await dbHelper.count({ + name: item.name, + owner: item.owner + })) > 0 + ) { + throw new Error(`Module with name ${item.name} is already exists`); + } + return await dbHelper.save(item); } /** - * Get Did Document - * @param did + * Create Multi Policy object + * @param multiPolicy + * @returns MultiPolicy */ - public async getDidDocument(did: string): Promise { - return await this.findOne(DidDocumentCollection, { did }); + public static createMultiPolicy(multiPolicy: MultiPolicy): MultiPolicy { + return new DataBaseHelper(MultiPolicy).create(multiPolicy); } /** - * Get Did Document - * @param did + * Create MultiPolicyTransaction + * @param transaction */ - public static async getDidDocument(did: string): Promise { - return await (new DataBaseHelper(DidDocumentCollection)).findOne({ did }); + public static async createMultiPolicyTransaction(transaction: FilterObject): Promise { + const item = new DataBaseHelper(MultiPolicyTransaction).create(transaction); + return await new DataBaseHelper(MultiPolicyTransaction).save(item); } /** - * Get Did Documents - * @param filters - * - * @param options - * @param countResult - * @virtual + * Create policy + * @param data */ - public async getDidDocuments(filters: FilterObject, options?: FindOptions, countResult?: boolean): Promise { - if (countResult) { - return await this.count(DidDocumentCollection, filters, options); + public static createPolicy(data: Partial): Policy { + if (!data.config) { + data.config = { + 'id': GenerateUUIDv4(), + 'blockType': 'interfaceContainerBlock', + 'permissions': [ + 'ANY_ROLE' + ] + }; } - return await this.find(DidDocumentCollection, filters, options); + const model = new DataBaseHelper(Policy).create(data); + return model; } /** - * Get Did Documents - * @param aggregation - * @virtual + * Assign entity + * @param config + * @param buffer */ - public async getDidDocumentsByAggregation(aggregation: FilterObject[]): Promise { - return await this.aggregate(DidDocumentCollection, aggregation) as DidDocumentCollection[]; + public static async createPolicyTest(config: { [key: string]: unknown }, buffer: Buffer): Promise { + const file = await DatabaseServer.saveFile(GenerateUUIDv4(), buffer); + const item = new DataBaseHelper(PolicyTest).create({ ...config, file }); + return await new DataBaseHelper(PolicyTest).save(item); } /** - * get document aggregation filters - * @param props - * - * @returns Result + * Create Record + * @param record */ - public getDocumentAggregationFilters(props: IGetDocumentAggregationFilters): void { - return DataBaseHelper.getDocumentAggregationFilters(props); + public static async createRecord(record: FilterObject): Promise { + const item = new DataBaseHelper(Record).create(record); + return await new DataBaseHelper(Record).save(item); } /** - * Get Document States - * @param filters - * @param options - * - * @virtual - */ - public async getDocumentStates(filters: FilterObject, options?: FindOptions): Promise { - return await this.find(DocumentState, filters, options); - } - - /** - * Get Dry Run id - * @returns Dry Run id - */ - public getDryRun(): string { - return this.dryRun; - } - - /** - * Get External Topic + * Create Residue object * @param policyId * @param blockId * @param userId - * - * @virtual + * @param value + * @param document */ - public async getExternalTopic( + public createResidue( policyId: string, blockId: string, - userId: string - ): Promise { - return await this.findOne(ExternalDocument, { - policyId: { $eq: policyId }, - blockId: { $eq: blockId }, - owner: { $eq: userId } + userId: string, + value: unknown, + document: unknown + ): SplitDocuments { + return this.create(SplitDocuments, { + policyId, + blockId, + userId, + value, + document }); } /** - * Get Policies By Category and Name - * @param {string[]} categoryIds - category ids - * @param {string} text - part of category name - * - * @returns {Policy[]} - found policies + * Get schema + * @param item */ - public static async getFilteredPolicies(categoryIds: string[], text: string): Promise { - const conditions = await GetConditionsPoliciesByCategories(categoryIds, text); - return await new DataBaseHelper(Policy).find({ $and: conditions }); + public static createSchema(item: Partial): SchemaCollection { + return new DataBaseHelper(SchemaCollection).create(item); } /** - * Get Group By Name - * @param policyId - * @param groupName - * - * @virtual + * Create tag + * @param tag */ - public async getGlobalGroup(policyId: string, groupName: string): Promise { - return await this.findOne(PolicyRolesCollection, { policyId, groupName }); + public async createTag(tag: Tag): Promise { + const item = this.create(Tag, tag); + return await this.save(Tag, item); } /** - * Get Group By UUID - * @param policyId - * @param uuid - * - * @virtual + * Create tag + * @param tag */ - public async getGroupByID(policyId: string, uuid: string): Promise { - return await this.findOne(PolicyRolesCollection, { policyId, uuid }); + public static async createTag(tag: FilterObject): Promise { + const item = new DataBaseHelper(Tag).create(tag); + return await new DataBaseHelper(Tag).save(item); } /** - * Get Group By UUID - * @param policyId - * @param uuid - * - * @returns Group + * Create tag cache + * @param tag */ - public static async getGroupByID(policyId: string, uuid: string): Promise { - return await new DataBaseHelper(PolicyRolesCollection).findOne({ policyId, uuid }); + public async createTagCache(tag: Partial): Promise { + const item = this.create(TagCache, tag); + return await this.save(TagCache, item); } /** - * Get Groups By User - * @param policyId - * @param did - * @param options - * - * @virtual + * Create tag cache + * @param tag */ - public async getGroupsByUser(policyId: string, did: string, options?: unknown): Promise { - if (!did) { - return []; - } - return await this.find(PolicyRolesCollection, { policyId, did }, options); + public static async createTagCache(tag: FilterObject): Promise { + const item = new DataBaseHelper(TagCache).create(tag); + return await new DataBaseHelper(TagCache).save(item); } /** - * Get Groups By User - * @param policyId - * @param did - * @param options - * - * @returns Groups + * Create Theme + * @param theme */ - public static async getGroupsByUser(policyId: string, did: string, options?: FindOptions): Promise { - if (!did) { - return []; - } - return await new DataBaseHelper(PolicyRolesCollection).find({ policyId, did }, options); + public static async createTheme(theme: FilterObject): Promise { + const item = new DataBaseHelper(Theme).create(theme); + return await new DataBaseHelper(Theme).save(item); } /** - * Get policies - * @param filters + * Create Token + * @param token + * @returns */ - public static async getListOfPolicies(filters?: FilterObject): Promise { - const options = { - fields: [ - 'id', - 'uuid', - 'name', - 'version', - 'previousVersion', - 'description', - 'status', - 'creator', - 'owner', - 'topicId', - 'policyTag', - 'messageId', - 'codeVersion', - 'createDate' - ] as unknown as PopulatePath.ALL[], - limit: 100 - }; - return await new DataBaseHelper(Policy).find(filters, options); + public async createToken(token: unknown): Promise { + const newToken = this.create(TokenCollection, token); + return await this.save(TokenCollection, newToken); } /** - * Get mint request minted serials - * @param mintRequestId Mint request identifier - * @returns Serials + * Create Tool + * @param tool */ - public async getMintRequestSerials(mintRequestId: string): Promise { - return await this.getTransactionsSerials(mintRequestId); + public static async createTool(tool: PolicyTool): Promise { + const item = new DataBaseHelper(PolicyTool).create(tool); + return await new DataBaseHelper(PolicyTool).save(item); } /** - * Get mint request transfer serials - * @param mintRequestId Mint request identifier - * @returns Serials + * Create Virtual User + * @param policyId + * @param username + * @param did + * @param hederaAccountId + * @param hederaAccountKey + * @param active + * + * @virtual */ - public async getMintRequestTransferSerials(mintRequestId: string): Promise { - return await this.getTransactionsSerials(mintRequestId, MintTransactionStatus.SUCCESS); - } + public static async createVirtualUser( + policyId: string, + username: string, + did: string, + hederaAccountId: string, + hederaAccountKey: string, + active: boolean, + systemMode?: boolean + ): Promise { + await new DataBaseHelper(DryRun).save(DatabaseServer.addDryRunId({ + did, + username, + hederaAccountId, + active + }, policyId, 'VirtualUsers', !!systemMode)); - /** - * Get mint transactions - * @param filters Filters - * @returns Mint transaction - */ - public async getMintTransaction(filters: FilterObject): Promise { - return await this.findOne(MintTransaction, filters); + if (hederaAccountKey) { + await new DataBaseHelper(DryRun).save(DatabaseServer.addDryRunId({ + did, + type: did, + hederaAccountKey + }, policyId, 'VirtualKey', !!systemMode)); + } } /** - * Get mint transactions - * @param filters Filters - * @param options Options - * @returns Mint transactions + * Create Virtual User + * @param policyId + * @param username + * @param did + * @param hederaAccountId + * @param hederaAccountKey + * @param active + * + * @virtual */ - public async getMintTransactions(filters: FilterObject, options?: FindOptions): Promise { - return await this.find(MintTransaction, filters, options); + public async createVirtualUser( + username: string, + did: string, + hederaAccountId: string, + hederaAccountKey: string, + active: boolean = false + ): Promise { + await DatabaseServer.createVirtualUser( + this.dryRun, + username, + did, + hederaAccountId, + hederaAccountKey, + active, + this.systemMode + ); } /** - * Get Module + * Overriding the create method + * @param entityClass * @param filters */ - public static async getModule(filters: FilterQuery): Promise { - return await new DataBaseHelper(PolicyModule).findOne(filters); + public deleteEntity(entityClass: new () => T, filters: FilterObject | string | ObjectId): Promise { + return new DataBaseHelper(entityClass).delete(filters); } /** - * Get Module By ID - * @param id + * Delete user + * @param group + * + * @virtual */ - public static async getModuleById(id: string | null): Promise { - return await new DataBaseHelper(PolicyModule).findOne(id); + public async deleteGroup(group: PolicyRolesCollection): Promise { + return await this.remove(PolicyRolesCollection, group); } /** - * Get Module By UUID - * @param uuid + * Delete policy + * @param id Policy ID */ - public static async getModuleByUUID(uuid: string): Promise { - return await new DataBaseHelper(PolicyModule).findOne({ uuid }); + public static async deletePolicy(id: string): Promise { + await new DataBaseHelper(Policy).delete({ id }); } /** - * Get Modules - * @param filters - * @param options - */ - public static async getModules(filters?: FilterQuery, options?: FindOptions): Promise { - return await new DataBaseHelper(PolicyModule).find(filters, options); + * Get policy tests + * @param policyId + * @param id + * @returns tests + */ + public static async deletePolicyTest(policyId: string, id: string): Promise { + await new DataBaseHelper(PolicyTest).delete({ id, policyId }); } /** - * Get Modules - * @param filters - * @param options + * Get policy tests + * @param policyId + * + * @returns tests */ - public static async getModulesAndCount(filters?: FilterObject, options?: FindOptions): Promise<[PolicyModule[], number]> { - return await new DataBaseHelper(PolicyModule).findAndCount(filters, options); + public static async deletePolicyTests(policyId: string): Promise { + await new DataBaseHelper(PolicyTest).delete({ policyId }); } /** - * Get Multi Policy link - * @param instanceTopicId - * @param owner - * @returns MultiPolicy + * Delete schemas + * @param id */ - public static async getMultiPolicy(instanceTopicId: string, owner: string): Promise { - return await new DataBaseHelper(MultiPolicy).findOne({ instanceTopicId, owner }); + public static async deleteSchemas(id: string): Promise { + await new DataBaseHelper(SchemaCollection).delete({ id }); } /** - * Get MultiPolicyTransaction - * @param policyId - * @param owner + * Overriding the find method + * @param entityClass + * @param filters + * @param options */ - public static async getMultiPolicyTransactions(policyId: string, user: string): Promise { - return await new DataBaseHelper(MultiPolicyTransaction).find({ policyId, user, status: 'Waiting' }); + public async find(entityClass: new () => T, filters: FilterQuery | string | ObjectId, options?: unknown): Promise { + if (this.dryRun) { + + const _filters = { + ...filters as FilterObject, + dryRunId: this.dryRun, + dryRunClass: this.classMap.get(entityClass) + }; + + return (await new DataBaseHelper(DryRun).find(_filters, options)) as unknown as T[]; + } else { + return await new DataBaseHelper(entityClass).find(filters, options); + } } /** - * Get MultiSign Statuses - * @param uuid - * @param documentId - * @param group - * - * @virtual + * Overriding the findAll method + * @param entityClass + * @param options */ - public async getMultiSignDocuments(uuid: string, documentId: string, group: string): Promise { - return await this.find(MultiDocuments, { - uuid: { $eq: uuid }, - documentId: { $eq: documentId }, - group: { $eq: group }, - userId: { $ne: 'Group' } - }); + public async findAll(entityClass: new () => T, options?: FindAllOptions): Promise { + return await new DataBaseHelper(entityClass).findAll(options); } /** - * Get multi sign documents by document identifiers - * @param documentIds Document identifiers - * @returns Multi sign documents + * Overriding the findAndCount method + * @param entityClass + * @param filters + * @param options */ - public async getMultiSignDocumentsByDocumentIds( - documentIds: string[] - ): Promise { - return await this.find(MultiDocuments, { - documentId: { $in: documentIds }, - }); + public async findAndCount(entityClass: new () => T, filters: FilterQuery | string | ObjectId, options?: unknown): Promise<[T[], number]> { + return await new DataBaseHelper(entityClass).findAndCount(filters, options); } /** - * Get MultiSign Statuses by group - * @param uuid - * @param group + * Overriding the findOne method + * @param entityClass + * @param filters + * @param options + */ + public async findOne(entityClass: new () => T, filters: FilterQuery, options: unknown = {}): Promise { + if (this.dryRun) { + if (typeof filters === 'string') { + return (await new DataBaseHelper(DryRun).findOne(filters, options)) as unknown as T; + } + + const _filters = { + ...filters as FilterObject, + dryRunId: this.dryRun, + dryRunClass: this.classMap.get(entityClass) + }; + + return (await new DataBaseHelper(DryRun).findOne(_filters, options)) as unknown as T; + } else { + return await new DataBaseHelper(entityClass).findOne(filters, options); + } + } + + /** + * Get Active External Topic + * @param policyId + * @param blockId * * @virtual */ - public async getMultiSignDocumentsByGroup(uuid: string, group: string): Promise { - return await this.find(MultiDocuments, { - uuid: { $eq: uuid }, - group: { $eq: group }, - userId: { $eq: 'Group' }, - status: { $eq: 'NEW' } + public async getActiveExternalTopics( + policyId: string, + blockId: string + ): Promise { + return await this.find(ExternalDocument, { + policyId: { $eq: policyId }, + blockId: { $eq: blockId }, + active: { $eq: true } }); } /** - * Get MultiSign Status by document or user - * @param uuid - * @param documentId - * @param userId + * Get Active Group By User + * @param policyId + * @param did * * @virtual */ - public async getMultiSignStatus(uuid: string, documentId: string, userId: string = 'Group'): Promise { - return await this.findOne(MultiDocuments, { uuid, documentId, userId }); + public async getActiveGroupByUser(policyId: string, did: string): Promise { + if (!did) { + return null; + } + return await this.findOne(PolicyRolesCollection, { policyId, did, active: true }); } /** - * Get policies + * Get Aggregate Documents + * @param policyId + * @param blockId * @param filters - * @param options + * + * @virtual */ - public static async getPolicies(filters?: FilterObject, options?: unknown): Promise { - return await new DataBaseHelper(Policy).find(filters, options); + public async getAggregateDocuments( + policyId: string, + blockId: string, + filters: FilterObject = {}, + ): Promise { + return await this.find(AggregateVC, { policyId, blockId, ...filters }); } /** - * Get policies and count - * @param filters - * @param options + * Get aggregate document by policy identifier + * @param policyId Policy identifier + * @returns Aggregate documents */ - public static async getPoliciesAndCount(filters: FilterObject, options?: FindOptions): Promise<[Policy[], number]> { - return await new DataBaseHelper(Policy).findAndCount(filters, options); + public async getAggregateDocumentsByPolicy( + policyId: string, + ): Promise { + return await this.find(AggregateVC, { policyId }); } /** - * Get Policy - * @param policyId + * Get members + * + * @param group * * @virtual */ - public async getPolicy(policyId: string | null): Promise { - return await new DataBaseHelper(Policy).findOne(policyId); - } - - //Static - - /** - * Get policy - * @param filters - */ - public static async getPolicy(filters: FilterObject): Promise { - return await new DataBaseHelper(Policy).findOne(filters); + public async getAllMembersByGroup(group: PolicyRolesCollection): Promise { + if (!group.uuid) { + return []; + } + return await this.find(PolicyRolesCollection, { + policyId: group.policyId, + uuid: group.uuid + }); } /** - * Get policy by id + * Get all policy users * @param policyId + * + * @virtual */ - public static async getPolicyById(policyId: string | null): Promise { - return await new DataBaseHelper(Policy).findOne(policyId); + public async getAllPolicyUsers(policyId: string): Promise { + return await this.find(PolicyRolesCollection, { policyId, active: true }); } /** - * Get policy by tag - * @param policyTag + * Get all policy users + * @param policyId + * @param uuid + * @param role + * + * @virtual */ - public static async getPolicyByTag(policyTag: string): Promise { - return await new DataBaseHelper(Policy).findOne({ policyTag }); + public async getAllUsersByRole(policyId: string, uuid: string, role: string): Promise { + return await this.find(PolicyRolesCollection, { policyId, uuid, role }); } /** - * Get policy by uuid + * get document aggregation filters for analytics + * @param nameFilter * @param uuid + * + * @returns Result */ - public static async getPolicyByUUID(uuid: string): Promise { - return await new DataBaseHelper(Policy).findOne({ uuid }); + public getAnalyticsDocAggregationFilters(nameFilter: string, uuid: string): unknown[] { + return DataBaseHelper.getAnalyticsDocAggregationFilters(nameFilter, uuid); } /** - * Get policy cache + * Get and count policy cache data * @param filters Filters - * @returns Policy cache + * @param options Options + * @returns Policy cache data and count */ - public static async getPolicyCache(filters: FilterObject): Promise { - return await new DataBaseHelper(PolicyCache).findOne(filters); + public static async getAndCountPolicyCacheData( + filters?: FilterObject, + options?: unknown + ): Promise<[PolicyCacheData[], number]> { + return await new DataBaseHelper(PolicyCacheData).findAndCount( + filters, + options + ); } /** - * Get policy cache data - * @param filters Filters - * @param options Options - * @returns Policy cache data + * Get Approval Document + * @param filters + * + * @virtual */ - public static async getPolicyCacheData( - filters?: FilterObject, - options?: FindOptions - ): Promise { - return await new DataBaseHelper(PolicyCacheData).find(filters, options); + public async getApprovalDocument(filters: FilterQuery): Promise { + return await this.findOne(ApprovalDocumentCollection, filters); } /** - * Get policy caches - * @param filters Filters - * @returns Policy caches + * Get Approval Documents + * @param filters + * @param options + * @param countResult + * @virtual */ - public static async getPolicyCaches(filters?: FilterObject): Promise { - return await new DataBaseHelper(PolicyCache).find(filters); + public async getApprovalDocuments(filters: FilterObject, options?: FindOptions, countResult?: boolean): Promise { + if (countResult) { + return await this.count(ApprovalDocumentCollection, filters, options); + } + return await this.find(ApprovalDocumentCollection, filters, options); } /** - * Get Policy Categories - * + * Get Approval Documents + * @param aggregation * @virtual */ - public static async getPolicyCategories(): Promise { - return await new DataBaseHelper(PolicyCategory).find(PolicyCategory as FilterQuery); + public async getApprovalDocumentsByAggregation(aggregation: FilterObject[]): Promise { + return await this.aggregate(ApprovalDocumentCollection, aggregation) as ApprovalDocumentCollection[]; } /** - * Get policy count - * @param filters + * Get Artifact + * @param filters Filters + * @returns Artifact */ - public static async getPolicyCount(filters: FilterObject): Promise { - return await new DataBaseHelper(Policy).count(filters); + public static async getArtifact(filters?: FilterQuery): Promise { + return await new DataBaseHelper(ArtifactCollection).findOne(filters); } - /** - * Get Policy Properties - * - * @virtual - */ - public static async getPolicyProperties(): Promise { - return await new DataBaseHelper(PolicyProperty).find(PolicyProperty as FilterQuery); - } + //Static /** - * Get policy test - * @param policyId - * @param id - * @returns tests + * Get Artifact File By UUID + * @param uuid File UUID + * @returns Buffer */ - public static async getPolicyTest(policyId: string, id: string): Promise { - return await new DataBaseHelper(PolicyTest).findOne({ id, policyId }); + public static async getArtifactFileByUUID(uuid: string): Promise { + const artifactChunks = (await new DataBaseHelper(ArtifactChunkCollection).find({ + uuid + }, { + orderBy: { + number: 'ASC' + } + })).map(item => item.data.buffer); + return artifactChunks.length > 0 ? Buffer.concat(artifactChunks) : Buffer.from(''); } /** - * Get policy tests - * @param resultId - * - * @returns tests + * Get Artifacts + * @param filters Filters + * @param options Options + * @returns Artifacts */ - public static async getPolicyTestByRecord(resultId: string): Promise { - return await new DataBaseHelper(PolicyTest).findOne({ resultId }); + public static async getArtifacts(filters?: FilterQuery, options?: FindOptions): Promise { + return await new DataBaseHelper(ArtifactCollection).find(filters, options); } /** - * Get policy tests - * @param policyId - * @returns tests + * Get Artifacts + * @param filters Filters + * @param options Options + * @returns Artifacts */ - public static async getPolicyTests(policyId: string): Promise { - return await new DataBaseHelper(PolicyTest).find({ policyId }); + public static async getArtifactsAndCount(filters?: FilterObject, options?: FindOptions): Promise<[ArtifactCollection[], number]> { + return await new DataBaseHelper(ArtifactCollection).findAndCount(filters, options); } /** - * Get policy test - * @param policyId - * @param status - * @returns tests + * Get assigned entities + * @param did + * @param type */ - public static async getPolicyTestsByStatus(policyId: string, status: PolicyTestStatus): Promise { - return await new DataBaseHelper(PolicyTest).find({ status, policyId }); + public static async getAssignedEntities(did: string, type?: AssignedEntityType): Promise { + if (type) { + return await (new DataBaseHelper(AssignEntity)).find({ type, did }); + } else { + return await (new DataBaseHelper(AssignEntity)).find({ did }); + } } /** - * Get Publish Policies - * - * @virtual + * Check entity + * @param type + * @param entityId + * @param did */ - public static async getPublishPolicies(): Promise { - return await new DataBaseHelper(Policy).find({ - status: { $eq: PolicyType.PUBLISH } - }); + public static async getAssignedEntity(type: AssignedEntityType, entityId: string, did: string): Promise { + return await (new DataBaseHelper(AssignEntity)).findOne({ type, entityId, did }); } /** - * Get Record - * @param filters Filters - * @param options Options - * @returns Record + * get document aggregation filters for analytics + * @param nameFilterMap + * @param nameFilterAttributes + * @param existingAttributes + * + * @returns Result */ - public static async getRecord(filters?: FilterQuery, options?: FindOptions): Promise { - return await new DataBaseHelper(Record).find(filters, options); + public getAttributesAggregationFilters(nameFilterMap: string, nameFilterAttributes: string, existingAttributes: string[] | []): unknown[] { + return DataBaseHelper.getAttributesAggregationFilters(nameFilterMap, nameFilterAttributes, existingAttributes); } /** - * Get Residue objects - * @param policyId - * @param blockId - * @param userId + * Get Block State + * @param {string} policyId - policy ID + * @param {string} blockId - block UUID + * @param {string} did - user DID + * @param {string} name - variable name + * + * @returns {BlockCache | null} - variable value + * @virtual */ - public async getResidue( + public async getBlockCache( policyId: string, blockId: string, - userId: string - ): Promise { - return await this.find(SplitDocuments, { - policyId: { $eq: policyId }, - blockId: { $eq: blockId }, - userId: { $eq: userId } + did: string, + name: string + ): Promise { + return await this.findOne(BlockCache, { + policyId, + blockId, + did, + name }); } /** - * Get retire pools - * @param tokenIds Token identifiers - * @returns Retire pools + * Get Block State + * @param policyId + * @param uuid + * + * @virtual */ - public static async getRetirePools(tokenIds: string[]): Promise { - return await new DataBaseHelper(RetirePool).find({ tokenIds: { $in: tokenIds } }); + public async getBlockState(policyId: string, uuid: string): Promise { + return await this.findOne(BlockState, { + policyId, + blockId: uuid + }); } /** - * Get schema - * @param iri - * @param topicId + * Get block states + * @param policyId Policy identifier + * @returns Block states */ - public async getSchemaByIRI(iri: string, topicId?: string): Promise { - if (topicId) { - return await new DataBaseHelper(SchemaCollection).findOne({ iri, topicId }); - } else { - return await new DataBaseHelper(SchemaCollection).findOne({ iri }); - } + public async getBlockStates(policyId: string): Promise { + return await this.find(BlockState, { + policyId + }); } /** - * Get schema + * Get Contract by ID * @param id */ - public static async getSchemaById(id: string | null): Promise { - return await new DataBaseHelper(SchemaCollection).findOne(id); + public static async getContractById(id: string | null): Promise { + return await new DataBaseHelper(ContractCollection).findOne(id); } /** - * Get schema - * @param topicId - * @param entity + * Get Did Document + * @param did */ - public async getSchemaByType(topicId: string, entity: SchemaEntity): Promise { - return await new DataBaseHelper(SchemaCollection).findOne({ - entity, - readonly: true, - topicId - }); + public async getDidDocument(did: string): Promise { + return await this.findOne(DidDocumentCollection, { did }); } /** - * Get schema - * @param topicId - * @param entity + * Get Did Document + * @param did */ - public static async getSchemaByType(topicId: string, entity: SchemaEntity): Promise { - return await new DataBaseHelper(SchemaCollection).findOne({ - entity, - readonly: true, - topicId - }); + public static async getDidDocument(did: string): Promise { + return await (new DataBaseHelper(DidDocumentCollection)).findOne({ did }); } /** - * Get schemas + * Get Did Documents * @param filters + * * @param options + * @param countResult + * @virtual */ - public static async getSchemas(filters?: FilterObject, options?: unknown): Promise { - return await new DataBaseHelper(SchemaCollection).find(filters, options); + public async getDidDocuments(filters: FilterObject, options?: FindOptions, countResult?: boolean): Promise { + if (countResult) { + return await this.count(DidDocumentCollection, filters, options); + } + return await this.find(DidDocumentCollection, filters, options); } /** - * Get schema - * @param filters - * @param options + * Get Did Documents + * @param aggregation + * @virtual */ - public static async getSchemasAndCount(filters?: FilterObject, options?: FindOptions): Promise<[SchemaCollection[], number]> { - return await new DataBaseHelper(SchemaCollection).findAndCount(filters, options); + public async getDidDocumentsByAggregation(aggregation: FilterObject[]): Promise { + return await this.aggregate(DidDocumentCollection, aggregation) as DidDocumentCollection[]; } /** - * Get schema - * @param ids + * get document aggregation filters + * @param props + * + * @returns Result */ - public static async getSchemasByIds(ids: string[]): Promise { - return await new DataBaseHelper(SchemaCollection).find({ id: { $in: ids } }); + public getDocumentAggregationFilters(props: IGetDocumentAggregationFilters): void { + return DataBaseHelper.getDocumentAggregationFilters(props); } /** - * Get schema + * Get Document States * @param filters + * @param options + * + * @virtual */ - public static async getSchemasCount(filters?: FilterObject): Promise { - return await new DataBaseHelper(SchemaCollection).count(filters); + public async getDocumentStates(filters: FilterObject, options?: FindOptions): Promise { + return await this.find(DocumentState, filters, options); } /** - * Get split documents in policy - * @param policyId Policy identifier - * @returns Split documents + * Get Dry Run id + * @returns Dry Run id */ - public async getSplitDocumentsByPolicy( - policyId: string, - ): Promise { - return await this.find(SplitDocuments, { - policyId - }); + public getDryRun(): string { + return this.dryRun; } /** - * Get suggestions config - * @param did - * @returns config + * Get External Topic + * @param policyId + * @param blockId + * @param userId + * + * @virtual */ - public static async getSuggestionsConfig( - did: string - ): Promise { - return await new DataBaseHelper(SuggestionsConfig).findOne({ - user: did + public async getExternalTopic( + policyId: string, + blockId: string, + userId: string + ): Promise { + return await this.findOne(ExternalDocument, { + policyId: { $eq: policyId }, + blockId: { $eq: blockId }, + owner: { $eq: userId } }); } /** - * Get system schema - * @param entity + * Get Policies By Category and Name + * @param {string[]} categoryIds - category ids + * @param {string} text - part of category name + * + * @returns {Policy[]} - found policies */ - public static async getSystemSchema(entity: SchemaEntity): Promise { - return await new DataBaseHelper(SchemaCollection).findOne({ - entity, - system: true, - active: true - }); + public static async getFilteredPolicies(categoryIds: string[], text: string): Promise { + const conditions = await GetConditionsPoliciesByCategories(categoryIds, text); + return await new DataBaseHelper(Policy).find({ $and: conditions }); } /** - * Get tag By UUID - * @param uuid + * Get Group By Name + * @param policyId + * @param groupName + * + * @virtual */ - public async getTagById(uuid: string): Promise { - return await this.findOne(Tag, { uuid }); + public async getGlobalGroup(policyId: string, groupName: string): Promise { + return await this.findOne(PolicyRolesCollection, { policyId, groupName }); } /** - * Get tag By UUID + * Get Group By UUID + * @param policyId * @param uuid + * + * @virtual */ - public static async getTagById(uuid: string): Promise { - return await new DataBaseHelper(Tag).findOne({ uuid }); + public async getGroupByID(policyId: string, uuid: string): Promise { + return await this.findOne(PolicyRolesCollection, { policyId, uuid }); } /** - * Get tags - * @param filters - * @param options + * Get Group By UUID + * @param policyId + * @param uuid + * + * @returns Group */ - public async getTagCache(filters?: FilterObject, options?: FindOptions): Promise { - return await this.find(TagCache, filters, options); + public static async getGroupByID(policyId: string, uuid: string): Promise { + return await new DataBaseHelper(PolicyRolesCollection).findOne({ policyId, uuid }); } /** - * Get tags - * @param filters + * Get Groups By User + * @param policyId + * @param did * @param options + * + * @virtual */ - public static async getTagCache(filters?: FilterQuery, options?: FindOptions): Promise { - return await new DataBaseHelper(TagCache).find(filters, options); + public async getGroupsByUser(policyId: string, did: string, options?: unknown): Promise { + if (!did) { + return []; + } + return await this.find(PolicyRolesCollection, { policyId, did }, options); } /** - * Get tags - * @param filters + * Get Groups By User + * @param policyId + * @param did * @param options + * + * @returns Groups */ - public async getTags(filters?: FilterQuery, options?: FindOptions): Promise { - return await this.find(Tag, filters, options); + public static async getGroupsByUser(policyId: string, did: string, options?: FindOptions): Promise { + if (!did) { + return []; + } + return await new DataBaseHelper(PolicyRolesCollection).find({ policyId, did }, options); } /** - * Get tags + * Get policies * @param filters - * @param options */ - public static async getTags(filters?: FilterQuery, options?: unknown): Promise { - return await new DataBaseHelper(Tag).find(filters, options); + public static async getListOfPolicies(filters?: FilterObject): Promise { + const options = { + fields: [ + 'id', + 'uuid', + 'name', + 'version', + 'previousVersion', + 'description', + 'status', + 'creator', + 'owner', + 'topicId', + 'policyTag', + 'messageId', + 'codeVersion', + 'createDate' + ] as unknown as PopulatePath.ALL[], + limit: 100 + }; + return await new DataBaseHelper(Policy).find(filters, options); } /** - * get tasks aggregation filters - * @param nameFilter - * @param processTimeout - * - * @returns Result + * Get mint request minted serials + * @param mintRequestId Mint request identifier + * @returns Serials */ - public getTasksAggregationFilters(nameFilter: string, processTimeout: number): unknown[] { - return DataBaseHelper.getTasksAggregationFilters(nameFilter, processTimeout); + public async getMintRequestSerials(mintRequestId: string): Promise { + return await this.getTransactionsSerials(mintRequestId); } /** - * Get Theme - * @param filters + * Get mint request transfer serials + * @param mintRequestId Mint request identifier + * @returns Serials */ - public static async getTheme(filters: FilterQuery): Promise { - return await new DataBaseHelper(Theme).findOne(filters); + public async getMintRequestTransferSerials(mintRequestId: string): Promise { + return await this.getTransactionsSerials(mintRequestId, MintTransactionStatus.SUCCESS); } /** - * Get Themes - * @param filters + * Get mint transactions + * @param filters Filters + * @returns Mint transaction */ - public static async getThemes(filters: FilterQuery): Promise { - return await new DataBaseHelper(Theme).find(filters); + public async getMintTransaction(filters: FilterObject): Promise { + return await this.findOne(MintTransaction, filters); } /** - * Get Token - * @param tokenId - * @param dryRun + * Get mint transactions + * @param filters Filters + * @param options Options + * @returns Mint transactions */ - public async getToken(tokenId: string, dryRun: string = null): Promise { - if (dryRun) { - return this.findOne(TokenCollection, { tokenId }); - } else { - return await new DataBaseHelper(TokenCollection).findOne({ tokenId }); - } + public async getMintTransactions(filters: FilterObject, options?: FindOptions): Promise { + return await this.find(MintTransaction, filters, options); } /** - * Get Token - * @param tokenId + * Get Module + * @param filters */ - public static async getToken(tokenId: string): Promise { - return await new DataBaseHelper(TokenCollection).findOne({ tokenId }); + public static async getModule(filters: FilterQuery): Promise { + return await new DataBaseHelper(PolicyModule).findOne(filters); } /** - * Get Token by ID + * Get Module By ID * @param id */ - public static async getTokenById(id: string | null): Promise { - return await new DataBaseHelper(TokenCollection).findOne(id); + public static async getModuleById(id: string | null): Promise { + return await new DataBaseHelper(PolicyModule).findOne(id); } /** - * Get tokens - * @param filters Filters - * @returns Tokens + * Get Module By UUID + * @param uuid */ - public static async getTokens(filters?: FilterQuery): Promise { - return await new DataBaseHelper(TokenCollection).find(filters); + public static async getModuleByUUID(uuid: string): Promise { + return await new DataBaseHelper(PolicyModule).findOne({ uuid }); } /** - * Get Tool + * Get Modules * @param filters + * @param options */ - public static async getTool(filters: FilterQuery): Promise { - return await new DataBaseHelper(PolicyTool).findOne(filters); - } - - /** - * Get Tool By ID - * @param id - */ - public static async getToolById(id: string | null): Promise { - return await new DataBaseHelper(PolicyTool).findOne(id); + public static async getModules(filters?: FilterQuery, options?: FindOptions): Promise { + return await new DataBaseHelper(PolicyModule).find(filters, options); } /** - * Get Tool By UUID - * @param uuid + * Get Modules + * @param filters + * @param options */ - public static async getToolByUUID(uuid: string): Promise { - return await new DataBaseHelper(PolicyTool).findOne({ uuid }); + public static async getModulesAndCount(filters?: FilterObject, options?: FindOptions): Promise<[PolicyModule[], number]> { + return await new DataBaseHelper(PolicyModule).findAndCount(filters, options); } /** - * Get Tools - * @param filters - * @param options + * Get Multi Policy link + * @param instanceTopicId + * @param owner + * @returns MultiPolicy */ - public static async getTools(filters?: FilterQuery, options?: unknown): Promise { - return await new DataBaseHelper(PolicyTool).find(filters, options); + public static async getMultiPolicy(instanceTopicId: string, owner: string): Promise { + return await new DataBaseHelper(MultiPolicy).findOne({ instanceTopicId, owner }); } /** - * Get Tools - * @param filters - * @param options + * Get MultiPolicyTransaction + * @param policyId + * @param owner */ - public static async getToolsAndCount(filters?: FilterObject, options?: FindOptions): Promise<[PolicyTool[], number]> { - return await new DataBaseHelper(PolicyTool).findAndCount(filters, options); + public static async getMultiPolicyTransactions(policyId: string, user: string): Promise { + return await new DataBaseHelper(MultiPolicyTransaction).find({ policyId, user, status: 'Waiting' }); } /** - * Get Topic - * @param filters + * Get MultiSign Statuses + * @param uuid + * @param documentId + * @param group * * @virtual */ - public async getTopic( - filters: { - /** - * policyId - */ - policyId?: string, - /** - * type - */ - type?: TopicType, - /** - * name - */ - name?: string, - /** - * owner - */ - owner?: string, - /** - * topicId - */ - topicId?: string - } - ): Promise { - return await this.findOne(TopicCollection, filters); + public async getMultiSignDocuments(uuid: string, documentId: string, group: string): Promise { + return await this.find(MultiDocuments, { + uuid: { $eq: uuid }, + documentId: { $eq: documentId }, + group: { $eq: group }, + userId: { $ne: 'Group' } + }); } /** - * Get topic by id - * @param topicId + * Get multi sign documents by document identifiers + * @param documentIds Document identifiers + * @returns Multi sign documents */ - public async getTopicById(topicId: string): Promise { - return await this.findOne(TopicCollection, { topicId }); + public async getMultiSignDocumentsByDocumentIds( + documentIds: string[] + ): Promise { + return await this.find(MultiDocuments, { + documentId: { $in: documentIds }, + }); } /** - * Get topic by id - * @param topicId + * Get MultiSign Statuses by group + * @param uuid + * @param group + * + * @virtual */ - public static async getTopicById(topicId: string): Promise { - return await new DataBaseHelper(TopicCollection).findOne({ topicId }); + public async getMultiSignDocumentsByGroup(uuid: string, group: string): Promise { + return await this.find(MultiDocuments, { + uuid: { $eq: uuid }, + group: { $eq: group }, + userId: { $eq: 'Group' }, + status: { $eq: 'NEW' } + }); } /** - * Get topic by type - * @param owner - * @param type + * Get MultiSign Status by document or user + * @param uuid + * @param documentId + * @param userId + * + * @virtual */ - public static async getTopicByType(owner: string, type: TopicType): Promise { - return await new DataBaseHelper(TopicCollection).findOne({ owner, type }); + public async getMultiSignStatus(uuid: string, documentId: string, userId: string = 'Group'): Promise { + return await this.findOne(MultiDocuments, { uuid, documentId, userId }); } /** - * Get Topics + * Get policies * @param filters - * - * @virtual + * @param options */ - public async getTopics( - filters: { - /** - * policyId - */ - policyId?: string, - /** - * type - */ - type?: TopicType, - /** - * name - */ - name?: string, - /** - * owner - */ - owner?: string, - /** - * topicId - */ - topicId?: string - } - ): Promise { - return await this.find(TopicCollection, filters); + public static async getPolicies(filters?: FilterObject, options?: unknown): Promise { + return await new DataBaseHelper(Policy).find(filters, options); } /** - * Get transactions count - * @param filters Mint request identifier - * @returns Transactions count + * Get policies and count + * @param filters + * @param options */ - public async getTransactionsCount(filters: FilterObject): Promise { - return await this.count(MintTransaction, filters); + public static async getPoliciesAndCount(filters: FilterObject, options?: FindOptions): Promise<[Policy[], number]> { + return await new DataBaseHelper(Policy).findAndCount(filters, options); } /** - * Get transactions serials - * @param mintRequestId Mint request identifier - * @param transferStatus Transfer status + * Get Policy + * @param policyId * - * @returns Serials + * @virtual */ - public async getTransactionsSerials( - mintRequestId: string, - transferStatus?: MintTransactionStatus | unknown - ): Promise { - const aggregation = DataBaseHelper._getTransactionsSerialsAggregation( - mintRequestId, - transferStatus - ); - const result = await this.aggregate(MintTransaction, aggregation); - return result[0]?.serials || []; + public async getPolicy(policyId: string | null): Promise { + return await new DataBaseHelper(Policy).findOne(policyId); } /** - * Get transactions serials count - * @param mintRequestId Mint request identifier - * @param transferStatus Transfer status - * - * @returns Serials count + * Get policy + * @param filters */ - public async getTransactionsSerialsCount( - mintRequestId: string, - transferStatus?: MintTransactionStatus | unknown - ): Promise { - const aggregation = DataBaseHelper._getTransactionsSerialsAggregation( - mintRequestId, - transferStatus - ); - - DataBaseHelper.getTransactionsSerialsAggregationFilters({ - aggregation, - aggregateMethod: 'push', - nameFilter: MAP_TRANSACTION_SERIALS_AGGREGATION_FILTERS.COUNT - }); - - const result = await this.aggregate(MintTransaction, aggregation); - - //todo something wrong with logic, serials is array - return result[0]?.serials as unknown as number || 0; + public static async getPolicy(filters: FilterObject): Promise { + return await new DataBaseHelper(Policy).findOne(filters); } /** - * Get User In Group + * Get policy by id * @param policyId - * @param did - * @param uuid - * - * @virtual */ - public async getUserInGroup(policyId: string, did: string, uuid: string): Promise { - if (!did && !uuid) { - return null; - } - return await this.findOne(PolicyRolesCollection, { policyId, did, uuid }); + public static async getPolicyById(policyId: string | null): Promise { + return await new DataBaseHelper(Policy).findOne(policyId); } /** - * Get user role in policy - * @param policyId - * @param did + * Get policy by tag + * @param policyTag */ - public static async getUserRole(policyId: string, did: string): Promise { - if (!did) { - return null; - } - return await new DataBaseHelper(PolicyRolesCollection).find({ policyId, did }); + public static async getPolicyByTag(policyTag: string): Promise { + return await new DataBaseHelper(Policy).findOne({ policyTag }); } /** - * Get user roles - * @param policyId - * @param did - * @returns - * - * @virtual + * Get policy by uuid + * @param uuid */ - public async getUserRoles(policyId: string, did: string): Promise { - return await this.find(PolicyRolesCollection, { policyId, did }); + public static async getPolicyByUUID(uuid: string): Promise { + return await new DataBaseHelper(Policy).findOne({ uuid }); } /** - * Get all policy users by role - * @param policyId - * @param role - * - * @virtual + * Get policy cache + * @param filters Filters + * @returns Policy cache */ - public async getUsersByRole(policyId: string, role: string): Promise { - return await this.find(PolicyRolesCollection, { policyId, role }); + public static async getPolicyCache(filters: FilterObject): Promise { + return await new DataBaseHelper(PolicyCache).findOne(filters); } /** - * Get VC - * @param filters - * @param options + * Get policy cache data + * @param filters Filters + * @param options Options + * @returns Policy cache data */ - public static async getVC( - filters?: FilterQuery, - options?: FindOptions - ): Promise { - return await new DataBaseHelper(VcDocumentCollection).findOne(filters, options); + public static async getPolicyCacheData( + filters?: FilterObject, + options?: FindOptions + ): Promise { + return await new DataBaseHelper(PolicyCacheData).find(filters, options); } /** - * Get VC - * @param id + * Get policy caches + * @param filters Filters + * @returns Policy caches */ - public static async getVCById(id: string | null): Promise | null { - return await new DataBaseHelper(VcDocumentCollection).findOne(id); + public static async getPolicyCaches(filters?: FilterObject): Promise { + return await new DataBaseHelper(PolicyCache).find(filters); } /** - * Get VCs - * @param filters - * @param options + * Get Policy Categories + * + * @virtual */ - public static async getVCs(filters?: FilterQuery, options?: FindOptions): Promise { - return await new DataBaseHelper(VcDocumentCollection).find(filters, options); + public static async getPolicyCategories(): Promise { + return await new DataBaseHelper(PolicyCategory).find(PolicyCategory as FilterQuery); } /** - * Get VC + * Get policy count * @param filters - * @param options */ - public static async getVP(filters?: FilterQuery, options?: FindOptions): Promise { - return await new DataBaseHelper(VpDocumentCollection).findOne(filters, options); + public static async getPolicyCount(filters: FilterObject): Promise { + return await new DataBaseHelper(Policy).count(filters); } /** - * Get VC - * @param id + * Get Policy Properties + * + * @virtual */ - public static async getVPById(id: string | null): Promise { - return await new DataBaseHelper(VpDocumentCollection).findOne(id); + public static async getPolicyProperties(): Promise { + return await new DataBaseHelper(PolicyProperty).find(PolicyProperty as FilterQuery); } /** - * Get VP mint information - * @param vpDocument VP - * @returns Serials and amount + * Get policy test + * @param policyId + * @param id + * @returns tests */ - public async getVPMintInformation( - vpDocument: VpDocument - ): Promise< - [ - serials: { serial: number; tokenId: string }[], - amount: number, - error: string, - wasTransferNeeded: boolean, - transferSerials: number[], - transferAmount: number, - tokenIds: string[], - target: string - ] - > { - const mintRequests = await this.getMintRequests({ - $or: [ - { - vpMessageId: vpDocument.messageId, - }, - { - secondaryVpIds: vpDocument.messageId, - }, - ], - } as FilterObject); - const serials = vpDocument.serials - ? vpDocument.serials.map((serial) => ({ - serial, - tokenId: vpDocument.tokenId, - })) - : []; - let amount = Number.isFinite(Number(vpDocument.amount)) - ? Number(vpDocument.amount) - : serials.length; - const transferSerials = vpDocument.serials - ? vpDocument.serials.map((serial) => ({ - serial, - tokenId: vpDocument.tokenId, - })) - : []; - let transferAmount = amount; - const errors = []; - let wasTransferNeeded = false; - const tokenIds = new Set(); - if (vpDocument.tokenId) { - tokenIds.add(vpDocument.tokenId); - } - const target = mintRequests?.[0]?.target; - for (const mintRequest of mintRequests) { - if (mintRequest.error) { - errors.push(mintRequest.error); - } - wasTransferNeeded ||= mintRequest.wasTransferNeeded; - tokenIds.add(mintRequest.tokenId); - if (mintRequest.tokenType === TokenType.NON_FUNGIBLE) { - const requestSerials = await this.getMintRequestSerials( - mintRequest.id - ); - serials.push( - ...requestSerials.map((serial) => ({ - serial, - tokenId: mintRequest.tokenId, - })) - ); - amount += requestSerials.length; - - if (wasTransferNeeded) { - const requestTransferSerials = - await this.getMintRequestTransferSerials( - mintRequest.id - ); - transferSerials.push( - ...requestTransferSerials.map((serial) => ({ - serial, - tokenId: mintRequest.tokenId, - })) - ); - transferAmount += requestTransferSerials.length; - } - } else if (mintRequest.tokenType === TokenType.FUNGIBLE) { - const mintRequestTransaction = await this.getMintTransaction({ - mintRequestId: mintRequest.id, - mintStatus: MintTransactionStatus.SUCCESS, - }); - if (mintRequestTransaction) { - if (mintRequest.decimals > 0) { - amount += - mintRequest.amount / Math.pow(10, mintRequest.decimals); - } else { - amount += mintRequest.amount; - } - } - if (wasTransferNeeded) { - const mintRequestTransferTransaction = - await this.getMintTransaction({ - mintRequestId: mintRequest.id, - transferStatus: MintTransactionStatus.SUCCESS, - }); - if (mintRequestTransferTransaction) { - if (mintRequest.decimals > 0) { - transferAmount += - mintRequest.amount / - Math.pow(10, mintRequest.decimals); - } else { - transferAmount += mintRequest.amount; - } - } - } - } - } - - return [ - serials, - amount, - errors.join(', '), - wasTransferNeeded, - transferSerials, - transferAmount, - [...tokenIds], - target, - ]; + public static async getPolicyTest(policyId: string, id: string): Promise { + return await new DataBaseHelper(PolicyTest).findOne({ id, policyId }); } /** - * Get VCs - * @param filters - * @param options + * Get policy tests + * @param resultId + * + * @returns tests */ - public static async getVPs(filters?: FilterQuery, options?: FindOptions): Promise { - return await new DataBaseHelper(VpDocumentCollection).find(filters, options); + public static async getPolicyTestByRecord(resultId: string): Promise { + return await new DataBaseHelper(PolicyTest).findOne({ resultId }); } /** - * Get Vc Document - * @param filters - * - * @virtual + * Get policy tests + * @param policyId + * @returns tests */ - public async getVcDocument(filters: FilterQuery): Promise { - return await this.findOne(VcDocumentCollection, filters); + public static async getPolicyTests(policyId: string): Promise { + return await new DataBaseHelper(PolicyTest).find({ policyId }); } /** - * Get Vc Documents - * @param filters - * @param options - * @param countResult - * @virtual + * Get policy test + * @param policyId + * @param status + * @returns tests */ - public async getVcDocuments( - filters: FilterObject, - options?: FindOptions, - countResult?: boolean - ): Promise { - if (countResult) { - return await this.count(VcDocumentCollection, filters, options); - } - return await this.find(VcDocumentCollection, filters, options) as T[]; + public static async getPolicyTestsByStatus(policyId: string, status: PolicyTestStatus): Promise { + return await new DataBaseHelper(PolicyTest).find({ status, policyId }); } /** - * Get Vc Documents - * @param aggregation + * Get Publish Policies + * * @virtual */ - public async getVcDocumentsByAggregation(aggregation: FilterObject[]): Promise { - return await this.aggregate(VcDocumentCollection, aggregation) as VcDocumentCollection[]; + public static async getPublishPolicies(): Promise { + return await new DataBaseHelper(Policy).find({ + status: { $eq: PolicyType.PUBLISH } + }); } /** - * Get Virtual Documents - * @param policyId - * @param type - * @param pageIndex - * @param pageSize - * - * @virtual + * Get Record + * @param filters Filters + * @param options Options + * @returns Record */ - public static async getVirtualDocuments( - policyId: string, - type: string, - pageIndex?: string, - pageSize?: string - ): Promise<[DryRun[], number]> { - const filters = { - dryRunId: policyId, - dryRunClass: null - } - const otherOptions: { orderBy?: unknown, limit?: number, offset?: number, fields?: string[] } = {}; - const _pageSize = parseInt(pageSize, 10); - const _pageIndex = parseInt(pageIndex, 10); - if (Number.isInteger(_pageSize) && Number.isInteger(_pageIndex)) { - otherOptions.orderBy = { createDate: 'DESC' }; - otherOptions.limit = _pageSize; - otherOptions.offset = _pageIndex * _pageSize; - } - if (type === 'artifacts') { - filters.dryRunClass = { - $in: [ - 'VcDocumentCollection', - 'VpDocumentCollection', - 'DidDocumentCollection', - 'ApprovalDocumentCollection' - ] - }; - } else if (type === 'transactions') { - filters.dryRunClass = { $eq: 'Transactions' }; - otherOptions.fields = [ - 'id', - 'createDate', - 'type', - 'hederaAccountId' - ]; - } else if (type === 'ipfs') { - filters.dryRunClass = { $eq: 'Files' }; - otherOptions.fields = [ - 'id', - 'createDate', - 'document', - 'documentURL' - ]; - } - return await new DataBaseHelper(DryRun).findAndCount(filters, otherOptions); + public static async getRecord(filters?: FilterQuery, options?: FindOptions): Promise { + return await new DataBaseHelper(Record).find(filters, options); } /** - * Get Virtual Hedera Account - * @param hederaAccountId - * - * @virtual + * Get Residue objects + * @param policyId + * @param blockId + * @param userId */ - public async getVirtualHederaAccountInfo(hederaAccountId: string): Promise { - const item = (await new DataBaseHelper(DryRun).findOne({ - dryRunId: this.dryRun, - dryRunClass: 'HederaAccountInfo', - hederaAccountId - })); - return item?.tokenMap || {}; + public async getResidue( + policyId: string, + blockId: string, + userId: string + ): Promise { + return await this.find(SplitDocuments, { + policyId: { $eq: policyId }, + blockId: { $eq: blockId }, + userId: { $eq: userId } + }); } /** - * Get Key from Virtual User - * @param did - * @param keyName - * - * @virtual + * Get retire pools + * @param tokenIds Token identifiers + * @returns Retire pools */ - public async getVirtualKey(did: string, keyName: string): Promise { - const item = (await new DataBaseHelper(DryRun).findOne({ - dryRunId: this.dryRun, - dryRunClass: 'VirtualKey', - did, - type: keyName - })); - return item?.hederaAccountKey; + public static async getRetirePools(tokenIds: string[]): Promise { + return await new DataBaseHelper(RetirePool).find({ tokenIds: { $in: tokenIds } }); } /** - * Get virtual keys - * @param filters Filters - * @returns Virtual keys + * Get schema + * @param iri + * @param topicId */ - public async getVirtualKeys(filters: FilterQuery): Promise { - const extendedFilters = filters as FilterQuery & { - dryRunId?: string; - dryRunClass?: string; - }; - - extendedFilters.dryRunId = this.dryRun; - extendedFilters.dryRunClass = 'VirtualKey'; - - return await new DataBaseHelper(DryRun).find(filters); + public async getSchemaByIRI(iri: string, topicId?: string): Promise { + if (topicId) { + return await new DataBaseHelper(SchemaCollection).findOne({ iri, topicId }); + } else { + return await new DataBaseHelper(SchemaCollection).findOne({ iri }); + } } /** - * Get Virtual Message - * @param dryRun - * @param messageId - * - * @virtual + * Get schema + * @param id */ - public static async getVirtualMessage(dryRun: string, messageId: string): Promise { - return (await new DataBaseHelper(DryRun).findOne({ - dryRunId: dryRun, - dryRunClass: 'Message', - messageId - })); + public static async getSchemaById(id: string | null): Promise { + return await new DataBaseHelper(SchemaCollection).findOne(id); } /** - * Get Virtual Messages - * @param dryRun + * Get schema * @param topicId - * - * @virtual + * @param entity */ - public static async getVirtualMessages(dryRun: string, topicId: string | TopicId): Promise { - return (await new DataBaseHelper(DryRun).find({ - dryRunId: dryRun, - dryRunClass: 'Message', + public async getSchemaByType(topicId: string, entity: SchemaEntity): Promise { + return await new DataBaseHelper(SchemaCollection).findOne({ + entity, + readonly: true, topicId - })); + }); } /** - * Get Virtual User - * @param did - * - * @virtual + * Get schema + * @param topicId + * @param entity */ - public async getVirtualUser(did: string): Promise { - return (await new DataBaseHelper(DryRun).findOne({ - dryRunId: this.dryRun, - dryRunClass: 'VirtualUsers', - did - })) as unknown as IAuthUser; + public static async getSchemaByType(topicId: string, entity: SchemaEntity): Promise { + return await new DataBaseHelper(SchemaCollection).findOne({ + entity, + readonly: true, + topicId + }); } /** - * Get Current Virtual User - * @param policyId - * - * @virtual + * Get schemas + * @param filters + * @param options */ - public static async getVirtualUser(policyId: string): Promise { - return await new DataBaseHelper(DryRun).findOne({ - dryRunId: policyId, - dryRunClass: 'VirtualUsers', - active: true - }, { - fields: [ - 'id', - 'did', - 'username', - 'hederaAccountId', - 'active' - ] - } as unknown as FindOptions); + public static async getSchemas(filters?: FilterObject, options?: unknown): Promise { + return await new DataBaseHelper(SchemaCollection).find(filters, options); } /** - * Get All Virtual Users - * @param policyId - * - * @virtual + * Get schema + * @param filters + * @param options */ - public static async getVirtualUsers(policyId: string): Promise { - return (await new DataBaseHelper(DryRun).find({ - dryRunId: policyId, - dryRunClass: 'VirtualUsers' - }, { - fields: [ - 'id', - 'did', - 'username', - 'hederaAccountId', - 'active' - ] as unknown as PopulatePath.ALL[], - orderBy: { - createDate: 1 - } - })); + public static async getSchemasAndCount(filters?: FilterObject, options?: FindOptions): Promise<[SchemaCollection[], number]> { + return await new DataBaseHelper(SchemaCollection).findAndCount(filters, options); } /** - * Get Vp Document - * @param filters - * - * @virtual + * Get schema + * @param ids */ - public async getVpDocument(filters: FilterQuery): Promise { - return await this.findOne(VpDocumentCollection, filters); + public static async getSchemasByIds(ids: string[]): Promise { + return await new DataBaseHelper(SchemaCollection).find({ id: { $in: ids } }); } /** - * Get Vp Documents + * Get schema * @param filters - * - * @param options - * @param countResult - * @virtual */ - public async getVpDocuments( - filters: FilterObject, - options?: FindOptions, - countResult?: boolean - ): Promise { - if (countResult) { - return await this.count(VpDocumentCollection, filters, options); - } - return await this.find(VpDocumentCollection, filters, options) as T[]; + public static async getSchemasCount(filters?: FilterObject): Promise { + return await new DataBaseHelper(SchemaCollection).count(filters); } /** - * Get Vp Documents - * @param aggregation - * @virtual + * Get split documents in policy + * @param policyId Policy identifier + * @returns Split documents */ - public async getVpDocumentsByAggregation(aggregation: FilterObject[]): Promise { - return await this.aggregate(VpDocumentCollection, aggregation) as VpDocumentCollection[]; + public async getSplitDocumentsByPolicy( + policyId: string, + ): Promise { + return await this.find(SplitDocuments, { + policyId + }); } /** - * Load file - * @param id - * - * @returns file ID + * Get suggestions config + * @param did + * @returns config */ - public static async loadFile(id: ObjectId): Promise { - return DataBaseHelper.loadFile(id); + public static async getSuggestionsConfig( + did: string + ): Promise { + return await new DataBaseHelper(SuggestionsConfig).findOne({ + user: did + }); } /** - * Parse invite token - * @param policyId - * @param invitationId - * - * @virtual + * Get system schema + * @param entity */ - public async parseInviteToken(policyId: string, invitationId: string): Promise { - const invitation = await this.findOne(PolicyInvitations, invitationId); - if (invitation && invitation.policyId === policyId && invitation.active === true) { - invitation.active = false; - await this.save(PolicyInvitations, invitation); - return invitation; - } else { - return null; - } + public static async getSystemSchema(entity: SchemaEntity): Promise { + return await new DataBaseHelper(SchemaCollection).findOne({ + entity, + system: true, + active: true + }); } /** - * Overriding the remove method - * @param entityClass - * @param entities + * Get tag By UUID + * @param uuid */ - public async remove(entityClass: new () => T, entities: T | T[]): Promise { - if (this.dryRun) { - await new DataBaseHelper(DryRun).remove(entities as unknown as DryRun | DryRun[]); - } else { - await new DataBaseHelper(entityClass).remove(entities); - } + public async getTagById(uuid: string): Promise { + return await this.findOne(Tag, { uuid }); } /** - * Remove Aggregate Document - * @param hash - * @param blockId - * - * @virtual + * Get tag By UUID + * @param uuid */ - public async removeAggregateDocument(hash: string, blockId: string): Promise { - const item = await this.find(AggregateVC, { blockId, hash }); - await this.remove(AggregateVC, item); + public static async getTagById(uuid: string): Promise { + return await new DataBaseHelper(Tag).findOne({ uuid }); } /** - * Remove Aggregate Documents - * @param removeMsp - * - * @virtual - */ - public async removeAggregateDocuments(removeMsp: AggregateVC[]): Promise { - await this.remove(AggregateVC, removeMsp); - } - - /** - * Remove Artifact - * @param artifact Artifact + * Get tags + * @param filters + * @param options */ - public static async removeArtifact(artifact?: ArtifactCollection): Promise { - await new DataBaseHelper(ArtifactCollection).remove(artifact) - await new DataBaseHelper(ArtifactChunkCollection).delete({ - uuid: artifact.uuid - }); + public async getTagCache(filters?: FilterObject, options?: FindOptions): Promise { + return await this.find(TagCache, filters, options); } /** - * Remove assign entity - * @param type - * @param entityId - * @param did - * @param owner + * Get tags + * @param filters + * @param options */ - public static async removeAssignEntity( - type: AssignedEntityType, - entityId: string, - did: string, - owner?: string - ): Promise { - const filters: { type: AssignedEntityType, entityId: string, did: string, owner?: string } = { type, entityId, did }; - - if (owner) { - filters.owner = owner; - } - const item = await (new DataBaseHelper(AssignEntity)).findOne(filters); - if (item) { - await (new DataBaseHelper(AssignEntity)).remove(item); - } - return true; + public static async getTagCache(filters?: FilterQuery, options?: FindOptions): Promise { + return await new DataBaseHelper(TagCache).find(filters, options); } /** - * Delete Module - * @param module + * Get tags + * @param filters + * @param options */ - public static async removeModule(module: PolicyModule): Promise { - return await new DataBaseHelper(PolicyModule).remove(module); + public async getTags(filters?: FilterQuery, options?: FindOptions): Promise { + return await this.find(Tag, filters, options); } /** - * Get policy tests - * @returns tests + * Get tags + * @param filters + * @param options */ - public static async removePolicyTests(tests: PolicyTest[]): Promise { - await new DataBaseHelper(PolicyTest).remove(tests); + public static async getTags(filters?: FilterQuery, options?: unknown): Promise { + return await new DataBaseHelper(Tag).find(filters, options); } /** - * Remove Residue objects - * @param residue + * get tasks aggregation filters + * @param nameFilter + * @param processTimeout + * + * @returns Result */ - public async removeResidue(residue: SplitDocuments[]): Promise { - await this.remove(SplitDocuments, residue); + public getTasksAggregationFilters(nameFilter: string, processTimeout: number): unknown[] { + return DataBaseHelper.getTasksAggregationFilters(nameFilter, processTimeout); } /** - * Delete tag - * @param tag + * Get Theme + * @param filters */ - public async removeTag(tag: Tag): Promise { - return await this.remove(Tag, tag); + public static async getTheme(filters: FilterQuery): Promise { + return await new DataBaseHelper(Theme).findOne(filters); } /** - * Delete tag - * @param tag + * Get Themes + * @param filters */ - public static async removeTag(tag: Tag): Promise { - return await new DataBaseHelper(Tag).remove(tag); + public static async getThemes(filters: FilterQuery): Promise { + return await new DataBaseHelper(Theme).find(filters); } /** - * Delete Theme - * @param theme + * Get Token + * @param tokenId + * @param dryRun */ - public static async removeTheme(theme: Theme): Promise { - return await new DataBaseHelper(Theme).remove(theme); + public async getToken(tokenId: string, dryRun: string = null): Promise { + if (dryRun) { + return this.findOne(TokenCollection, { tokenId }); + } else { + return await new DataBaseHelper(TokenCollection).findOne({ tokenId }); + } } /** - * Delete Tool - * @param tool + * Get Token + * @param tokenId */ - public static async removeTool(tool: PolicyTool): Promise { - return await new DataBaseHelper(PolicyTool).remove(tool); + public static async getToken(tokenId: string): Promise { + return await new DataBaseHelper(TokenCollection).findOne({ tokenId }); } /** - * Overriding the save method - * @param entityClass - * @param item - * @param filter + * Get Token by ID + * @param id */ - async save(entityClass: new () => T, item: unknown | unknown[], filter?: FilterObject): Promise { - if (Array.isArray(item)) { - return await this.saveMany(entityClass, item, filter) as any; - } - - if (this.dryRun) { - this.addDryRunId(entityClass, item); - return await new DataBaseHelper(DryRun).save(item, filter) as unknown as T; - } - - return await new DataBaseHelper(entityClass).save(item as Partial, filter); + public static async getTokenById(id: string | null): Promise { + return await new DataBaseHelper(TokenCollection).findOne(id); } /** - * Save Approval VC - * @param row - * - * @virtual + * Get tokens + * @param filters Filters + * @returns Tokens */ - public async saveApproval(row: Partial): Promise { - const doc = this.create(ApprovalDocumentCollection, row); - return await this.save(ApprovalDocumentCollection, doc); + public static async getTokens(filters?: FilterQuery): Promise { + return await new DataBaseHelper(TokenCollection).find(filters); } /** - * Save Artifact - * @param artifact Artifact - * @returns Saved Artifact + * Get Tool + * @param filters */ - public static async saveArtifact(artifact: ArtifactCollection): Promise { - return await new DataBaseHelper(ArtifactCollection).save(artifact); + public static async getTool(filters: FilterQuery): Promise { + return await new DataBaseHelper(PolicyTool).findOne(filters); } /** - * Save Artifact File - * @param uuid File UUID - * @param data Data + * Get Tool By ID + * @param id */ - public static async saveArtifactFile(uuid: string, data: Buffer): Promise { - let offset = 0; - let fileNumber = 1; - while (offset < data.length) { - await new DataBaseHelper(ArtifactChunkCollection).save({ - uuid, - number: fileNumber, - data: new Binary(data.subarray(offset, offset + DatabaseServer.MAX_DOCUMENT_SIZE > data.length ? data.length : offset + DatabaseServer.MAX_DOCUMENT_SIZE)) - }); - offset = offset + DatabaseServer.MAX_DOCUMENT_SIZE; - fileNumber++; - } + public static async getToolById(id: string | null): Promise { + return await new DataBaseHelper(PolicyTool).findOne(id); } /** - * Save Artifacts - * @param artifacts Artifacts - * @returns Saved Artifacts + * Get Tool By UUID + * @param uuid */ - public static async saveArtifacts(artifacts: ArtifactCollection[]): Promise { - return await new DataBaseHelper(ArtifactCollection).saveMany(artifacts); + public static async getToolByUUID(uuid: string): Promise { + return await new DataBaseHelper(PolicyTool).findOne({ uuid }); } /** - * Save Block State - * @param {string} policyId - policy ID - * @param {string} blockId - block UUID - * @param {string} did - user DID - * @param {string} name - variable name - * @param {unknown} value - variable value - * @param {boolean} isLongValue - if long value - * @virtual + * Get Tools + * @param filters + * @param options */ - public async saveBlockCache( - policyId: string, - blockId: string, - did: string, - name: string, - value: unknown, - isLongValue: boolean - ): Promise { - let stateEntity = await this.findOne(BlockCache, { - policyId, - blockId, - did, - name - }); - if (stateEntity) { - stateEntity.value = value; - stateEntity.isLongValue = isLongValue; - } else { - stateEntity = this.create(BlockCache, { - policyId, - blockId, - did, - name, - value, - isLongValue - }); - } - await this.save(BlockCache, stateEntity); + public static async getTools(filters?: FilterQuery, options?: unknown): Promise { + return await new DataBaseHelper(PolicyTool).find(filters, options); } /** - * Save Block State - * @param policyId - * @param uuid - * @param state - * - * @virtual + * Get Tools + * @param filters + * @param options */ - public async saveBlockState(policyId: string, uuid: string, state: unknown): Promise { - let stateEntity = await this.findOne(BlockState, { - policyId, - blockId: uuid - }); - if (!stateEntity) { - stateEntity = this.create(BlockState, { - policyId, - blockId: uuid - }); - } - stateEntity.blockState = JSON.stringify(state); - await this.save(BlockState, stateEntity); + public static async getToolsAndCount(filters?: FilterObject, options?: FindOptions): Promise<[PolicyTool[], number]> { + return await new DataBaseHelper(PolicyTool).findAndCount(filters, options); } /** - * Save Did - * @param row + * Get Topic + * @param filters * * @virtual */ - public async saveDid(row: Partial): Promise { - const doc = this.create(DidDocumentCollection, row); - return await this.save(DidDocumentCollection, doc); - } - + public async getTopic( + filters: { + /** + * policyId + */ + policyId?: string, + /** + * type + */ + type?: TopicType, + /** + * name + */ + name?: string, + /** + * owner + */ + owner?: string, + /** + * topicId + */ + topicId?: string + } + ): Promise { + return await this.findOne(TopicCollection, filters); + } + /** - * Save Document State - * @param row + * Get topic by id + * @param topicId + */ + public async getTopicById(topicId: string): Promise { + return await this.findOne(TopicCollection, { topicId }); + } + + /** + * Get topic by id + * @param topicId + */ + public static async getTopicById(topicId: string): Promise { + return await new DataBaseHelper(TopicCollection).findOne({ topicId }); + } + + /** + * Get topic by type + * @param owner + * @param type + */ + public static async getTopicByType(owner: string, type: TopicType): Promise { + return await new DataBaseHelper(TopicCollection).findOne({ owner, type }); + } + + /** + * Get Topics + * @param filters * * @virtual */ - public async saveDocumentState(row: Partial): Promise { - const item = this.create(DocumentState, row); - return await this.save(DocumentState, item); + public async getTopics( + filters: { + /** + * policyId + */ + policyId?: string, + /** + * type + */ + type?: TopicType, + /** + * name + */ + name?: string, + /** + * owner + */ + owner?: string, + /** + * topicId + */ + topicId?: string + } + ): Promise { + return await this.find(TopicCollection, filters); } /** - * Save file + * Get transactions count + * @param filters Mint request identifier + * @returns Transactions count + */ + public async getTransactionsCount(filters: FilterObject): Promise { + return await this.count(MintTransaction, filters); + } + + /** + * Get transactions serials + * @param mintRequestId Mint request identifier + * @param transferStatus Transfer status + * + * @returns Serials + */ + public async getTransactionsSerials( + mintRequestId: string, + transferStatus?: MintTransactionStatus | unknown + ): Promise { + const aggregation = DataBaseHelper._getTransactionsSerialsAggregation( + mintRequestId, + transferStatus + ); + const result = await this.aggregate(MintTransaction, aggregation); + return result[0]?.serials || []; + } + + /** + * Get transactions serials count + * @param mintRequestId Mint request identifier + * @param transferStatus Transfer status + * + * @returns Serials count + */ + public async getTransactionsSerialsCount( + mintRequestId: string, + transferStatus?: MintTransactionStatus | unknown + ): Promise { + const aggregation = DataBaseHelper._getTransactionsSerialsAggregation( + mintRequestId, + transferStatus + ); + + DataBaseHelper.getTransactionsSerialsAggregationFilters({ + aggregation, + aggregateMethod: 'push', + nameFilter: MAP_TRANSACTION_SERIALS_AGGREGATION_FILTERS.COUNT + }); + + const result = await this.aggregate(MintTransaction, aggregation); + + //todo something wrong with logic, serials is array + return result[0]?.serials as unknown as number || 0; + } + + /** + * Get User In Group + * @param policyId + * @param did * @param uuid - * @param buffer * - * @returns file ID + * @virtual */ - public static async saveFile(uuid: string, buffer: Buffer): Promise { - return DataBaseHelper.saveFile(uuid, buffer); + public async getUserInGroup(policyId: string, did: string, uuid: string): Promise { + if (!did && !uuid) { + return null; + } + return await this.findOne(PolicyRolesCollection, { policyId, did, uuid }); } /** - * Save many - * @param entityClass - * @param item - * @param filter + * Get user role in policy + * @param policyId + * @param did */ - async saveMany(entityClass: new () => T, item: unknown[], filter?: FilterObject): Promise { - if (this.dryRun) { - this.addDryRunId(entityClass, item); - return await new DataBaseHelper(DryRun).saveMany(item, filter) as unknown as T[]; + public static async getUserRole(policyId: string, did: string): Promise { + if (!did) { + return null; + } + return await new DataBaseHelper(PolicyRolesCollection).find({ policyId, did }); + } + + /** + * Get user roles + * @param policyId + * @param did + * @returns + * + * @virtual + */ + public async getUserRoles(policyId: string, did: string): Promise { + return await this.find(PolicyRolesCollection, { policyId, did }); + } + + /** + * Get all policy users by role + * @param policyId + * @param role + * + * @virtual + */ + public async getUsersByRole(policyId: string, role: string): Promise { + return await this.find(PolicyRolesCollection, { policyId, role }); + } + + /** + * Get VC + * @param filters + * @param options + */ + public static async getVC( + filters?: FilterQuery, + options?: FindOptions + ): Promise { + return await new DataBaseHelper(VcDocumentCollection).findOne(filters, options); + } + + /** + * Get VC + * @param id + */ + public static async getVCById(id: string | null): Promise | null { + return await new DataBaseHelper(VcDocumentCollection).findOne(id); + } + + /** + * Get VCs + * @param filters + * @param options + */ + public static async getVCs(filters?: FilterQuery, options?: FindOptions): Promise { + return await new DataBaseHelper(VcDocumentCollection).find(filters, options); + } + + /** + * Get VC + * @param filters + * @param options + */ + public static async getVP(filters?: FilterQuery, options?: FindOptions): Promise { + return await new DataBaseHelper(VpDocumentCollection).findOne(filters, options); + } + + /** + * Get VC + * @param id + */ + public static async getVPById(id: string | null): Promise { + return await new DataBaseHelper(VpDocumentCollection).findOne(id); + } + + /** + * Get VP mint information + * @param vpDocument VP + * @returns Serials and amount + */ + public async getVPMintInformation( + vpDocument: VpDocument + ): Promise< + [ + serials: { serial: number; tokenId: string }[], + amount: number, + error: string, + wasTransferNeeded: boolean, + transferSerials: number[], + transferAmount: number, + tokenIds: string[], + target: string + ] + > { + const mintRequests = await this.getMintRequests({ + $or: [ + { + vpMessageId: vpDocument.messageId, + }, + { + secondaryVpIds: vpDocument.messageId, + }, + ], + } as FilterObject); + const serials = vpDocument.serials + ? vpDocument.serials.map((serial) => ({ + serial, + tokenId: vpDocument.tokenId, + })) + : []; + let amount = Number.isFinite(Number(vpDocument.amount)) + ? Number(vpDocument.amount) + : serials.length; + const transferSerials = vpDocument.serials + ? vpDocument.serials.map((serial) => ({ + serial, + tokenId: vpDocument.tokenId, + })) + : []; + let transferAmount = amount; + const errors = []; + let wasTransferNeeded = false; + const tokenIds = new Set(); + if (vpDocument.tokenId) { + tokenIds.add(vpDocument.tokenId); + } + const target = mintRequests?.[0]?.target; + for (const mintRequest of mintRequests) { + if (mintRequest.error) { + errors.push(mintRequest.error); + } + wasTransferNeeded ||= mintRequest.wasTransferNeeded; + tokenIds.add(mintRequest.tokenId); + if (mintRequest.tokenType === TokenType.NON_FUNGIBLE) { + const requestSerials = await this.getMintRequestSerials( + mintRequest.id + ); + serials.push( + ...requestSerials.map((serial) => ({ + serial, + tokenId: mintRequest.tokenId, + })) + ); + amount += requestSerials.length; + + if (wasTransferNeeded) { + const requestTransferSerials = + await this.getMintRequestTransferSerials( + mintRequest.id + ); + transferSerials.push( + ...requestTransferSerials.map((serial) => ({ + serial, + tokenId: mintRequest.tokenId, + })) + ); + transferAmount += requestTransferSerials.length; + } + } else if (mintRequest.tokenType === TokenType.FUNGIBLE) { + const mintRequestTransaction = await this.getMintTransaction({ + mintRequestId: mintRequest.id, + mintStatus: MintTransactionStatus.SUCCESS, + }); + if (mintRequestTransaction) { + if (mintRequest.decimals > 0) { + amount += + mintRequest.amount / Math.pow(10, mintRequest.decimals); + } else { + amount += mintRequest.amount; + } + } + if (wasTransferNeeded) { + const mintRequestTransferTransaction = + await this.getMintTransaction({ + mintRequestId: mintRequest.id, + transferStatus: MintTransactionStatus.SUCCESS, + }); + if (mintRequestTransferTransaction) { + if (mintRequest.decimals > 0) { + transferAmount += + mintRequest.amount / + Math.pow(10, mintRequest.decimals); + } else { + transferAmount += mintRequest.amount; + } + } + } + } + } + + return [ + serials, + amount, + errors.join(', '), + wasTransferNeeded, + transferSerials, + transferAmount, + [...tokenIds], + target, + ]; + } + + /** + * Get VCs + * @param filters + * @param options + */ + public static async getVPs(filters?: FilterQuery, options?: FindOptions): Promise { + return await new DataBaseHelper(VpDocumentCollection).find(filters, options); + } + + /** + * Get Vc Document + * @param filters + * + * @virtual + */ + public async getVcDocument(filters: FilterQuery): Promise { + return await this.findOne(VcDocumentCollection, filters); + } + + /** + * Get Vc Documents + * @param filters + * @param options + * @param countResult + * @virtual + */ + public async getVcDocuments( + filters: FilterObject, + options?: FindOptions, + countResult?: boolean + ): Promise { + if (countResult) { + return await this.count(VcDocumentCollection, filters, options); + } + return await this.find(VcDocumentCollection, filters, options) as T[]; + } + + /** + * Get Vc Documents + * @param aggregation + * @virtual + */ + public async getVcDocumentsByAggregation(aggregation: FilterObject[]): Promise { + return await this.aggregate(VcDocumentCollection, aggregation) as VcDocumentCollection[]; + } + + /** + * Get Virtual Documents + * @param policyId + * @param type + * @param pageIndex + * @param pageSize + * + * @virtual + */ + public static async getVirtualDocuments( + policyId: string, + type: string, + pageIndex?: string, + pageSize?: string + ): Promise<[DryRun[], number]> { + const filters = { + dryRunId: policyId, + dryRunClass: null + } + const otherOptions: { orderBy?: unknown, limit?: number, offset?: number, fields?: string[] } = {}; + const _pageSize = parseInt(pageSize, 10); + const _pageIndex = parseInt(pageIndex, 10); + if (Number.isInteger(_pageSize) && Number.isInteger(_pageIndex)) { + otherOptions.orderBy = { createDate: 'DESC' }; + otherOptions.limit = _pageSize; + otherOptions.offset = _pageIndex * _pageSize; + } + if (type === 'artifacts') { + filters.dryRunClass = { + $in: [ + 'VcDocumentCollection', + 'VpDocumentCollection', + 'DidDocumentCollection', + 'ApprovalDocumentCollection' + ] + }; + } else if (type === 'transactions') { + filters.dryRunClass = { $eq: 'Transactions' }; + otherOptions.fields = [ + 'id', + 'createDate', + 'type', + 'hederaAccountId' + ]; + } else if (type === 'ipfs') { + filters.dryRunClass = { $eq: 'Files' }; + otherOptions.fields = [ + 'id', + 'createDate', + 'document', + 'documentURL' + ]; } - return await new DataBaseHelper(entityClass).saveMany(item as Partial[], filter); - } - - /** - * Save mint request - * @param data Mint request - * @returns Saved mint request - */ - public async saveMintRequest(data: Partial): Promise { - return await this.save(MintRequest, data); - } - - /** - * Save mint transaction - * @param transaction Transaction - * @returns Saved transaction - */ - public async saveMintTransaction(transaction: Partial): Promise { - return this.save(MintTransaction, transaction); + return await new DataBaseHelper(DryRun).findAndCount(filters, otherOptions); } /** - * Save Multi Policy object - * @param multiPolicy - * @returns multiPolicy + * Get Virtual Hedera Account + * @param hederaAccountId + * + * @virtual */ - public static async saveMultiPolicy(multiPolicy: MultiPolicy): Promise { - return await new DataBaseHelper(MultiPolicy).save(multiPolicy); + public async getVirtualHederaAccountInfo(hederaAccountId: string): Promise { + const item = (await new DataBaseHelper(DryRun).findOne({ + dryRunId: this.dryRun, + dryRunClass: 'HederaAccountInfo', + hederaAccountId + })); + return item?.tokenMap || {}; } /** - * Update policies - * @param models + * Get Key from Virtual User + * @param did + * @param keyName + * + * @virtual */ - public static async savePolicies(models: Policy[]): Promise { - return await new DataBaseHelper(Policy).saveMany(models); + public async getVirtualKey(did: string, keyName: string): Promise { + const item = (await new DataBaseHelper(DryRun).findOne({ + dryRunId: this.dryRun, + dryRunClass: 'VirtualKey', + did, + type: keyName + })); + return item?.hederaAccountKey; } /** - * Save policy cache - * @param entity Entity - * @returns Policy cache + * Get virtual keys + * @param filters Filters + * @returns Virtual keys */ - public static async savePolicyCache(entity: Partial): Promise { - return await new DataBaseHelper(PolicyCache).save(entity); - } + public async getVirtualKeys(filters: FilterQuery): Promise { + const extendedFilters = filters as FilterQuery & { + dryRunId?: string; + dryRunClass?: string; + }; - /** - * Save policy cache data - * @param entity Policy cache data - * @returns Policy cache data - */ - public static async savePolicyCacheData( - entity: Partial - ): Promise { - return await new DataBaseHelper(PolicyCacheData).save(entity); - } + extendedFilters.dryRunId = this.dryRun; + extendedFilters.dryRunClass = 'VirtualKey'; - /** - * Save schema - * @param item - */ - public static async saveSchema(item: SchemaCollection): Promise { - return await new DataBaseHelper(SchemaCollection).save(item); + return await new DataBaseHelper(DryRun).find(filters); } /** - * Save schemas - * @param items + * Get Virtual Message + * @param dryRun + * @param messageId + * + * @virtual */ - public static async saveSchemas(items: SchemaCollection[]): Promise { - return await new DataBaseHelper(SchemaCollection).saveMany(items); + public static async getVirtualMessage(dryRun: string, messageId: string): Promise { + return (await new DataBaseHelper(DryRun).findOne({ + dryRunId: dryRun, + dryRunClass: 'Message', + messageId + })); } /** - * Save Topic - * @param topic + * Get Virtual Messages + * @param dryRun + * @param topicId * * @virtual */ - public async saveTopic(topic: TopicCollection): Promise { - const topicObject = this.create(TopicCollection, topic); - return await this.save(TopicCollection, topicObject); + public static async getVirtualMessages(dryRun: string, topicId: string | TopicId): Promise { + return (await new DataBaseHelper(DryRun).find({ + dryRunId: dryRun, + dryRunClass: 'Message', + topicId + })); } /** - * Save topic - * @param row + * Get Virtual User + * @param did + * + * @virtual */ - public static async saveTopic(row: Partial): Promise { - return await new DataBaseHelper(TopicCollection).save(row); + public async getVirtualUser(did: string): Promise { + return (await new DataBaseHelper(DryRun).findOne({ + dryRunId: this.dryRun, + dryRunClass: 'VirtualUsers', + did + })) as unknown as IAuthUser; } /** - * Save VC - * @param row + * Get Current Virtual User + * @param policyId * * @virtual */ - public async saveVC(row: Partial): Promise { - const doc = this.create(VcDocumentCollection, row); - return await this.save(VcDocumentCollection, doc); + public static async getVirtualUser(policyId: string): Promise { + return await new DataBaseHelper(DryRun).findOne({ + dryRunId: policyId, + dryRunClass: 'VirtualUsers', + active: true + }, { + fields: [ + 'id', + 'did', + 'username', + 'hederaAccountId', + 'active' + ] + } as unknown as FindOptions); } /** - * Save VC - * @param row + * Get All Virtual Users + * @param policyId + * + * @virtual */ - public static async saveVC(row: Partial): Promise { - return await new DataBaseHelper(VcDocumentCollection).save(row); + public static async getVirtualUsers(policyId: string): Promise { + return (await new DataBaseHelper(DryRun).find({ + dryRunId: policyId, + dryRunClass: 'VirtualUsers' + }, { + fields: [ + 'id', + 'did', + 'username', + 'hederaAccountId', + 'active' + ] as unknown as PopulatePath.ALL[], + orderBy: { + createDate: 1 + } + })); } /** - * Save VCs - * @param data + * Get Vp Document + * @param filters * - * @returns VCs + * @virtual */ - // tslint:disable-next-line:adjacent-overload-signatures - public static async saveVCs(data: Partial): Promise { - return (await new DataBaseHelper(VcDocumentCollection).save(data)); + public async getVpDocument(filters: FilterQuery): Promise { + return await this.findOne(VpDocumentCollection, filters); } /** - * Save VP - * @param row + * Get Vp Documents + * @param filters * + * @param options + * @param countResult * @virtual */ - public async saveVP(row: Partial): Promise { - const doc = this.create(VpDocumentCollection, row); - return await this.save(VpDocumentCollection, doc); + public async getVpDocuments( + filters: FilterObject, + options?: FindOptions, + countResult?: boolean + ): Promise { + if (countResult) { + return await this.count(VpDocumentCollection, filters, options); + } + return await this.find(VpDocumentCollection, filters, options) as T[]; } /** - * Save VPs - * @param data - * - * @returns VPs + * Get Vp Documents + * @param aggregation + * @virtual */ - public static async saveVPs(data: Partial): Promise { - return (await new DataBaseHelper(VpDocumentCollection).save(data)); + public async getVpDocumentsByAggregation(aggregation: FilterObject[]): Promise { + return await this.aggregate(VpDocumentCollection, aggregation) as VpDocumentCollection[]; } /** - * Save Virtual Message - * @param dryRun - * @param message + * Load file + * @param id * - * @virtual + * @returns file ID */ - public static async saveVirtualMessage(dryRun: string, message: Message): Promise { - const document = message.toMessage(); - const messageId = message.getId(); - const topicId = message.getTopicId(); - - await new DataBaseHelper(DryRun).save(DatabaseServer.addDryRunId({ - document, - topicId, - messageId - }, dryRun, 'Message', false)); + public static async loadFile(id: ObjectId): Promise { + return DataBaseHelper.loadFile(id); } /** - * Set Active Group - * + * Parse invite token * @param policyId - * @param did - * @param uuid + * @param invitationId * * @virtual */ - public async setActiveGroup(policyId: string, did: string, uuid: string): Promise { - const groups = await this.find(PolicyRolesCollection, { policyId, did }); - for (const group of groups) { - group.active = group.uuid === uuid; + public async parseInviteToken(policyId: string, invitationId: string): Promise { + const invitation = await this.findOne(PolicyInvitations, invitationId); + if (invitation && invitation.policyId === policyId && invitation.active === true) { + invitation.active = false; + await this.save(PolicyInvitations, invitation); + return invitation; + } else { + return null; } - await this.saveMany(PolicyRolesCollection, groups); } /** - * Set Dry Run id - * @param id + * Overriding the remove method + * @param entityClass + * @param entities */ - public setDryRun(id: string): void { - this.dryRun = id; + public async remove(entityClass: new () => T, entities: T | T[]): Promise { + if (this.dryRun) { + await new DataBaseHelper(DryRun).remove(entities as unknown as DryRun | DryRun[]); + } else { + await new DataBaseHelper(entityClass).remove(entities); + } } /** - * Set MultiSign Status by user - * @param uuid - * @param documentId - * @param user - * @param status - * @param document + * Remove Aggregate Document + * @param hash + * @param blockId * * @virtual */ - public async setMultiSigDocument( - uuid: string, - documentId: string, - user: { id: string, did: string, group: string, username: string }, - status: string, - document: IVC - ): Promise { - const doc = this.create(MultiDocuments, { - uuid, - documentId, - status, - document, - userId: user.id, - did: user.did, - group: user.group, - username: user.username - }); - await this.save(MultiDocuments, doc); - return doc; + public async removeAggregateDocument(hash: string, blockId: string): Promise { + const item = await this.find(AggregateVC, { blockId, hash }); + await this.remove(AggregateVC, item); } /** - * Set MultiSign Status by document - * @param uuid - * @param documentId - * @param group - * @param status + * Remove Aggregate Documents + * @param removeMsp * * @virtual */ - public async setMultiSigStatus( - uuid: string, - documentId: string, - group: string, - status: string - ): Promise { - let item = await this.findOne(MultiDocuments, { - uuid: { $eq: uuid }, - documentId: { $eq: documentId }, - group: { $eq: group }, - userId: { $eq: 'Group' } - }); - if (item) { - item.status = status; - await this.update(MultiDocuments, item.id, item); - } else { - item = this.create(MultiDocuments, { - uuid, - documentId, - status, - document: null, - userId: 'Group', - did: null, - group, - username: null - }); - await this.save(MultiDocuments, item); - } - return item; + public async removeAggregateDocuments(removeMsp: AggregateVC[]): Promise { + await this.remove(AggregateVC, removeMsp); } /** - * Set Residue objects - * @param residue + * Remove Artifact + * @param artifact Artifact */ - public async setResidue(residue: SplitDocuments[]): Promise { - await this.saveMany(SplitDocuments, residue); + public static async removeArtifact(artifact?: ArtifactCollection): Promise { + await new DataBaseHelper(ArtifactCollection).remove(artifact) + await new DataBaseHelper(ArtifactChunkCollection).delete({ + uuid: artifact.uuid + }); } /** - * Save suggestions config - * @param config - * @returns config + * Remove assign entity + * @param type + * @param entityId + * @param did + * @param owner */ - public static async setSuggestionsConfig( - config: Partial - ): Promise { - const existingConfig = await DatabaseServer.getSuggestionsConfig( - config.user - ); - if (existingConfig) { - existingConfig.items = config.items; + public static async removeAssignEntity( + type: AssignedEntityType, + entityId: string, + did: string, + owner?: string + ): Promise { + const filters: { type: AssignedEntityType, entityId: string, did: string, owner?: string } = { type, entityId, did }; + + if (owner) { + filters.owner = owner; } - return await new DataBaseHelper(SuggestionsConfig).save( - existingConfig || config - ); + const item = await (new DataBaseHelper(AssignEntity)).findOne(filters); + if (item) { + await (new DataBaseHelper(AssignEntity)).remove(item); + } + return true; } /** - * Set Dry Run id - * @param id + * Delete Module + * @param module */ - public setSystemMode(systemMode: boolean): void { - this.systemMode = systemMode; + public static async removeModule(module: PolicyModule): Promise { + return await new DataBaseHelper(PolicyModule).remove(module); } /** - * Set user in group - * - * @param group - * - * @virtual + * Get policy tests + * @returns tests */ - public async setUserInGroup(group: unknown): Promise { - const doc = this.create(PolicyRolesCollection, group); - await this.save(PolicyRolesCollection, doc); - return doc; + public static async removePolicyTests(tests: PolicyTest[]): Promise { + await new DataBaseHelper(PolicyTest).remove(tests); } /** - * Save Virtual File - * @param policyId - * @param file - * @param url - * - * @virtual + * Remove Residue objects + * @param residue */ - public static async setVirtualFile( - policyId: string, - file: ArrayBuffer, - url: { url: string } - ): Promise { - await new DataBaseHelper(DryRun).save(DatabaseServer.addDryRunId({ - document: { - size: file?.byteLength - }, - documentURL: url?.url - }, policyId, 'Files', false)); + public async removeResidue(residue: SplitDocuments[]): Promise { + await this.remove(SplitDocuments, residue); } /** - * Set Key from Virtual User - * @param did - * @param keyName - * @param key - * - * @virtual + * Delete tag + * @param tag */ - public async setVirtualKey(did: string, keyName: string, key: string): Promise { - await new DataBaseHelper(DryRun).save({ - dryRunId: this.dryRun, - dryRunClass: 'VirtualKey', - did, - type: keyName, - hederaAccountKey: key - } as Partial); + public async removeTag(tag: Tag): Promise { + return await this.remove(Tag, tag); } /** - * Save Virtual Transaction - * @param policyId - * @param type - * @param operatorId - * - * @virtual + * Delete tag + * @param tag */ - public static async setVirtualTransaction( - policyId: string, - type: string, - operatorId?: string - ): Promise { - await new DataBaseHelper(DryRun).save(DatabaseServer.addDryRunId({ - type, - hederaAccountId: operatorId - }, policyId, 'Transactions', false)); + public static async removeTag(tag: Tag): Promise { + return await new DataBaseHelper(Tag).remove(tag); } /** - * Set Current Virtual User - * @param policyId - * @param did - * - * @virtual + * Delete Theme + * @param theme */ - public static async setVirtualUser(policyId: string, did: string): Promise { - const items = (await new DataBaseHelper(DryRun).find({ - dryRunId: policyId, - dryRunClass: 'VirtualUsers' - })); - for (const item of items) { - item.active = item.did === did; - await new DataBaseHelper(DryRun).save(item); - } + public static async removeTheme(theme: Theme): Promise { + return await new DataBaseHelper(Theme).remove(theme); } /** - * Overriding the update method + * Delete Tool + * @param tool + */ + public static async removeTool(tool: PolicyTool): Promise { + return await new DataBaseHelper(PolicyTool).remove(tool); + } + + /** + * Overriding the save method * @param entityClass - * @param criteria - * @param row + * @param item + * @param filter */ - async update( - entityClass: new () => T, - criteria: FilterQuery, - row: unknown | unknown[] - ): Promise { - if (Array.isArray(criteria)) { - return await this.updateMany(entityClass, row as unknown as T[], criteria) as any; + async save(entityClass: new () => T, item: unknown | unknown[], filter?: FilterObject): Promise { + if (Array.isArray(item)) { + return await this.saveMany(entityClass, item, filter) as any; } if (this.dryRun) { - this.addDryRunId(entityClass, row); - return (await new DataBaseHelper(DryRun).update(row as DryRun, criteria as FilterQuery)) as unknown as T; - } else { - return await new DataBaseHelper(entityClass).update(row as T, criteria); + this.addDryRunId(entityClass, item); + return await new DataBaseHelper(DryRun).save(item, filter) as unknown as T; } + + return await new DataBaseHelper(entityClass).save(item as Partial, filter); } /** - * Update Approval VC + * Save Approval VC * @param row * * @virtual */ - public async updateApproval(row: ApprovalDocumentCollection): Promise { - await this.update(ApprovalDocumentCollection, row.id, row); - return row; + public async saveApproval(row: Partial): Promise { + const doc = this.create(ApprovalDocumentCollection, row); + return await this.save(ApprovalDocumentCollection, doc); } /** - * Update Did - * @param row - * - * @virtual + * Save Artifact + * @param artifact Artifact + * @returns Saved Artifact */ - public async updateDid(row: DidDocumentCollection): Promise { - await this.update(DidDocumentCollection, row.id, row); - return row; + public static async saveArtifact(artifact: ArtifactCollection): Promise { + return await new DataBaseHelper(ArtifactCollection).save(artifact); } /** - * Update External Topic - * @param item - * - * @virtual + * Save Artifact File + * @param uuid File UUID + * @param data Data */ - public async updateExternalTopic(item: ExternalDocument): Promise { - return await this.save(ExternalDocument, item); + public static async saveArtifactFile(uuid: string, data: Buffer): Promise { + let offset = 0; + let fileNumber = 1; + while (offset < data.length) { + await new DataBaseHelper(ArtifactChunkCollection).save({ + uuid, + number: fileNumber, + data: new Binary(data.subarray(offset, offset + DatabaseServer.MAX_DOCUMENT_SIZE > data.length ? data.length : offset + DatabaseServer.MAX_DOCUMENT_SIZE)) + }); + offset = offset + DatabaseServer.MAX_DOCUMENT_SIZE; + fileNumber++; + } } /** - * Update many method - * @param entityClass - * @param entities - * @param filter + * Save Artifacts + * @param artifacts Artifacts + * @returns Saved Artifacts */ - async updateMany( - entityClass: new () => T, - entities: T[], - filter?: FilterQuery - ): Promise { - if (this.dryRun) { - this.addDryRunId(entityClass, entities); - return (await new DataBaseHelper(DryRun).updateMany(entities as unknown as DryRun[], filter as FilterQuery)); - } else { - return await new DataBaseHelper(entityClass).updateMany(entities as T[], filter); - } + public static async saveArtifacts(artifacts: ArtifactCollection[]): Promise { + return await new DataBaseHelper(ArtifactCollection).saveMany(artifacts); } /** - * Update Module - * @param row + * Save Block State + * @param {string} policyId - policy ID + * @param {string} blockId - block UUID + * @param {string} did - user DID + * @param {string} name - variable name + * @param {unknown} value - variable value + * @param {boolean} isLongValue - if long value + * @virtual */ - public static async updateModule(row: PolicyModule): Promise { - row.name = row.name.replace(/\s+/g, ' ').trim(); - const dbHelper = new DataBaseHelper(PolicyModule); - if ( - (await dbHelper.count({ - id: { $ne: row.id }, - name: row.name, - owner: row.owner, - })) > 0 - ) { - throw new Error(`Module with name ${row.name} is already exists`); + public async saveBlockCache( + policyId: string, + blockId: string, + did: string, + name: string, + value: unknown, + isLongValue: boolean + ): Promise { + let stateEntity = await this.findOne(BlockCache, { + policyId, + blockId, + did, + name + }); + if (stateEntity) { + stateEntity.value = value; + stateEntity.isLongValue = isLongValue; + } else { + stateEntity = this.create(BlockCache, { + policyId, + blockId, + did, + name, + value, + isLongValue + }); } - return await dbHelper.update(row); + await this.save(BlockCache, stateEntity); } /** - * Update MultiPolicyTransaction - * @param item + * Save Block State + * @param policyId + * @param uuid + * @param state + * + * @virtual */ - public static async updateMultiPolicyTransactions(item: MultiPolicyTransaction): Promise { - await new DataBaseHelper(MultiPolicyTransaction).update(item); + public async saveBlockState(policyId: string, uuid: string, state: unknown): Promise { + let stateEntity = await this.findOne(BlockState, { + policyId, + blockId: uuid + }); + if (!stateEntity) { + stateEntity = this.create(BlockState, { + policyId, + blockId: uuid + }); + } + stateEntity.blockState = JSON.stringify(state); + await this.save(BlockState, stateEntity); } /** - * Update policy - * @param model + * Save Did + * @param row + * + * @virtual */ - public static async updatePolicy(model: Policy): Promise { - return await new DataBaseHelper(Policy).save(model); + public async saveDid(row: Partial): Promise { + const doc = this.create(DidDocumentCollection, row); + return await this.save(DidDocumentCollection, doc); } /** - * Update policy - * @param policyId - * @param data + * Save Document State + * @param row + * + * @virtual */ - public static async updatePolicyConfig(policyId: string, data: Policy): Promise { - const model = await new DataBaseHelper(Policy).findOne(policyId); - model.config = data.config; - model.name = data.name; - model.version = data.version; - model.description = data.description; - model.topicDescription = data.topicDescription; - model.policyRoles = data.policyRoles; - model.policyNavigation = data.policyNavigation; - model.policyTopics = data.policyTopics; - model.policyTokens = data.policyTokens; - model.policyGroups = data.policyGroups; - model.categories = data.categories; - model.projectSchema = data.projectSchema; - - return await new DataBaseHelper(Policy).save(model); + public async saveDocumentState(row: Partial): Promise { + const item = this.create(DocumentState, row); + return await this.save(DocumentState, item); } /** - * Get policy tests - * @param test + * Save file + * @param uuid + * @param buffer * - * @returns tests + * @returns file ID */ - public static async updatePolicyTest(test: PolicyTest): Promise { - return await new DataBaseHelper(PolicyTest).save(test); + public static async saveFile(uuid: string, buffer: Buffer): Promise { + return DataBaseHelper.saveFile(uuid, buffer); } /** - * Update schema - * @param id + * Save many + * @param entityClass * @param item + * @param filter */ - public static async updateSchema(id: string, item: SchemaCollection): Promise { - await new DataBaseHelper(SchemaCollection).update(item, { id }); + async saveMany(entityClass: new () => T, item: unknown[], filter?: FilterObject): Promise { + if (this.dryRun) { + this.addDryRunId(entityClass, item); + return await new DataBaseHelper(DryRun).saveMany(item, filter) as unknown as T[]; + } + return await new DataBaseHelper(entityClass).saveMany(item as Partial[], filter); } /** - * Update schemas - * @param items Schemas + * Save mint request + * @param data Mint request + * @returns Saved mint request */ - public static async updateSchemas(items: SchemaCollection[]): Promise { - await new DataBaseHelper(SchemaCollection).update(items); + public async saveMintRequest(data: Partial): Promise { + return await this.save(MintRequest, data); } /** - * Update tag - * @param tag + * Save mint transaction + * @param transaction Transaction + * @returns Saved transaction */ - public async updateTag(tag: Tag): Promise { - return await this.update(Tag, tag.id, tag); + public async saveMintTransaction(transaction: Partial): Promise { + return this.save(MintTransaction, transaction); } /** - * Update tag - * @param tag + * Save Multi Policy object + * @param multiPolicy + * @returns multiPolicy */ - public static async updateTag(tag: Tag): Promise { - return await new DataBaseHelper(Tag).update(tag); + public static async saveMultiPolicy(multiPolicy: MultiPolicy): Promise { + return await new DataBaseHelper(MultiPolicy).save(multiPolicy); } /** - * Update tag cache - * @param row + * Update policies + * @param models */ - public async updateTagCache(row: TagCache): Promise { - return await this.update(TagCache, row.id, row); + public static async savePolicies(models: Policy[]): Promise { + return await new DataBaseHelper(Policy).saveMany(models); } /** - * Update tag cache - * @param row + * Save policy cache + * @param entity Entity + * @returns Policy cache */ - public static async updateTagCache(row: TagCache): Promise { - return await new DataBaseHelper(TagCache).update(row); + public static async savePolicyCache(entity: Partial): Promise { + return await new DataBaseHelper(PolicyCache).save(entity); } /** - * Update tags - * @param tags + * Save policy cache data + * @param entity Policy cache data + * @returns Policy cache data + */ + public static async savePolicyCacheData( + entity: Partial + ): Promise { + return await new DataBaseHelper(PolicyCacheData).save(entity); + } + + /** + * Save schema + * @param item */ - public async updateTags(tags: Tag[]): Promise { - return await this.updateMany(Tag, tags); + public static async saveSchema(item: SchemaCollection): Promise { + return await new DataBaseHelper(SchemaCollection).save(item); } /** - * Update tags - * @param tags + * Save schemas + * @param items */ - public static async updateTags(tags: Tag[]): Promise { - return await new DataBaseHelper(Tag).updateMany(tags); + public static async saveSchemas(items: SchemaCollection[]): Promise { + return await new DataBaseHelper(SchemaCollection).saveMany(items); } /** - * Update tags cache - * @param rows + * Save Topic + * @param topic + * + * @virtual */ - public static async updateTagsCache(rows: TagCache[]): Promise { - return await new DataBaseHelper(TagCache).updateMany(rows); + public async saveTopic(topic: TopicCollection): Promise { + const topicObject = this.create(TopicCollection, topic); + return await this.save(TopicCollection, topicObject); } /** - * Update Theme + * Save topic * @param row */ - public static async updateTheme(row: Theme): Promise { - return await new DataBaseHelper(Theme).update(row); + public static async saveTopic(row: Partial): Promise { + return await new DataBaseHelper(TopicCollection).save(row); } /** - * Update Tool + * Save VC * @param row + * + * @virtual */ - public static async updateTool(row: PolicyTool): Promise { - return await new DataBaseHelper(PolicyTool).update(row); + public async saveVC(row: Partial): Promise { + const doc = this.create(VcDocumentCollection, row); + return await this.save(VcDocumentCollection, doc); } /** - * Update topic + * Save VC * @param row */ - public static async updateTopic(row: TopicCollection): Promise { - await new DataBaseHelper(TopicCollection).update(row); + public static async saveVC(row: Partial): Promise { + return await new DataBaseHelper(VcDocumentCollection).save(row); } /** - * Update VC - * @param row + * Save VCs + * @param data * - * @virtual + * @returns VCs */ - public async updateVC(row: VcDocumentCollection): Promise { - await this.update(VcDocumentCollection, row.id, row); - return row; + // tslint:disable-next-line:adjacent-overload-signatures + public static async saveVCs(data: Partial): Promise { + return (await new DataBaseHelper(VcDocumentCollection).save(data)); } /** - * Update VP + * Save VP * @param row * * @virtual */ - public async updateVP(row: VpDocumentCollection): Promise { - await this.update(VpDocumentCollection, row.id, row); - return row; - } - - /** - * Update VP DOcuments - * @param value - * @param filters - * @param dryRun - */ - public static async updateVpDocuments(value: unknown, filters: FilterQuery, dryRun?: string): Promise { - if (dryRun) { - const extendedFilters = filters as FilterQuery & { - dryRunId?: string; - dryRunClass?: string; - }; - - extendedFilters.dryRunId = dryRun; - extendedFilters.dryRunClass = 'VpDocumentCollection'; - - const items = await new DataBaseHelper(DryRun).find(extendedFilters); - - for (const item of items) { - Object.assign(item, value); - } - await new DataBaseHelper(DryRun).update(items); - } else { - const items = await new DataBaseHelper(VpDocumentCollection).find(filters); - for (const item of items) { - Object.assign(item, value); - } - await new DataBaseHelper(VpDocumentCollection).update(items); - } + public async saveVP(row: Partial): Promise { + const doc = this.create(VpDocumentCollection, row); + return await this.save(VpDocumentCollection, doc); } /** - * Virtual Associate Token - * @param hederaAccountId - * @param token + * Save VPs + * @param data * - * @virtual + * @returns VPs */ - public async virtualAssociate(hederaAccountId: string, token: TokenCollection): Promise { - const item = await new DataBaseHelper(DryRun).findOne({ - dryRunId: this.dryRun, - dryRunClass: 'HederaAccountInfo', - hederaAccountId - }); - if (item) { - if (item.tokenMap[token.tokenId]) { - throw new Error('Token already associated'); - } else { - item.tokenMap[token.tokenId] = { - frozen: token.enableFreeze ? false : null, - kyc: token.enableKYC ? false : null - }; - await new DataBaseHelper(DryRun).update(item); - } - } else { - const tokenMap = {}; - tokenMap[token.tokenId] = { - frozen: token.enableFreeze ? false : null, - kyc: token.enableKYC ? false : null - }; - await new DataBaseHelper(DryRun).save({ - dryRunId: this.dryRun, - dryRunClass: 'HederaAccountInfo', - hederaAccountId, - tokenMap - }); - } - return true; + public static async saveVPs(data: Partial): Promise { + return (await new DataBaseHelper(VpDocumentCollection).save(data)); } /** - * Virtual Dissociate Token - * @param hederaAccountId - * @param tokenId + * Save Virtual Message + * @param dryRun + * @param message * * @virtual */ - public async virtualDissociate(hederaAccountId: string, tokenId: string): Promise { - const item = await new DataBaseHelper(DryRun).findOne({ - dryRunId: this.dryRun, - dryRunClass: 'HederaAccountInfo', - hederaAccountId - }); - if (!item || !item.tokenMap[tokenId]) { - throw new Error('Token is not associated'); - } - delete item.tokenMap[tokenId]; - await new DataBaseHelper(DryRun).update(item); - return true; + public static async saveVirtualMessage(dryRun: string, message: Message): Promise { + const document = message.toMessage(); + const messageId = message.getId(); + const topicId = message.getTopicId(); + + await new DataBaseHelper(DryRun).save(DatabaseServer.addDryRunId({ + document, + topicId, + messageId + }, dryRun, 'Message', false)); } /** - * Virtual Freeze Token - * @param hederaAccountId - * @param tokenId + * Set Active Group + * + * @param policyId + * @param did + * @param uuid * * @virtual */ - public async virtualFreeze(hederaAccountId: string, tokenId: string): Promise { - const item = await new DataBaseHelper(DryRun).findOne({ - dryRunId: this.dryRun, - dryRunClass: 'HederaAccountInfo', - hederaAccountId - }); - if (!item || !item.tokenMap[tokenId]) { - throw new Error('Token is not associated'); - } - if (item.tokenMap[tokenId].frozen === null) { - throw new Error('Can not be frozen'); - } - if (item.tokenMap[tokenId].frozen === true) { - throw new Error('Token already frozen'); + public async setActiveGroup(policyId: string, did: string, uuid: string): Promise { + const groups = await this.find(PolicyRolesCollection, { policyId, did }); + for (const group of groups) { + group.active = group.uuid === uuid; } - item.tokenMap[tokenId].frozen = true; - await new DataBaseHelper(DryRun).update(item); - return true; + await this.saveMany(PolicyRolesCollection, groups); } /** - * Virtual GrantKyc Token - * @param hederaAccountId - * @param tokenId - * - * @virtual + * Set Dry Run id + * @param id */ - public async virtualGrantKyc(hederaAccountId: string, tokenId: string): Promise { - const item = await new DataBaseHelper(DryRun).findOne({ - dryRunId: this.dryRun, - dryRunClass: 'HederaAccountInfo', - hederaAccountId - }); - if (!item || !item.tokenMap[tokenId]) { - throw new Error('Token is not associated'); - } - if (item.tokenMap[tokenId].kyc === null) { - throw new Error('Can not be granted kyc'); - } - if (item.tokenMap[tokenId].kyc === true) { - throw new Error('Token already granted kyc'); - } - item.tokenMap[tokenId].kyc = true; - await new DataBaseHelper(DryRun).update(item); - return true; + public setDryRun(id: string): void { + this.dryRun = id; } /** - * Virtual RevokeKyc Token - * @param hederaAccountId - * @param tokenId + * Set MultiSign Status by user + * @param uuid + * @param documentId + * @param user + * @param status + * @param document * * @virtual */ - public async virtualRevokeKyc(hederaAccountId: string, tokenId: string): Promise { - const item = await new DataBaseHelper(DryRun).findOne({ - dryRunId: this.dryRun, - dryRunClass: 'HederaAccountInfo', - hederaAccountId - }); - if (!item || !item.tokenMap[tokenId]) { - throw new Error('Token is not associated'); - } - if (item.tokenMap[tokenId].kyc === null) { - throw new Error('Can not be revoked kyc'); - } - if (item.tokenMap[tokenId].kyc === false) { - throw new Error('Token already revoked kyc'); - } - item.tokenMap[tokenId].kyc = false; - await new DataBaseHelper(DryRun).update(item); - return true; + public async setMultiSigDocument( + uuid: string, + documentId: string, + user: { id: string, did: string, group: string, username: string }, + status: string, + document: IVC + ): Promise { + const doc = this.create(MultiDocuments, { + uuid, + documentId, + status, + document, + userId: user.id, + did: user.did, + group: user.group, + username: user.username + }); + await this.save(MultiDocuments, doc); + return doc; } /** - * Virtual Unfreeze Token - * @param hederaAccountId - * @param tokenId + * Set MultiSign Status by document + * @param uuid + * @param documentId + * @param group + * @param status * * @virtual */ - public async virtualUnfreeze(hederaAccountId: string, tokenId: string): Promise { - const item = await new DataBaseHelper(DryRun).findOne({ - dryRunId: this.dryRun, - dryRunClass: 'HederaAccountInfo', - hederaAccountId + public async setMultiSigStatus( + uuid: string, + documentId: string, + group: string, + status: string + ): Promise { + let item = await this.findOne(MultiDocuments, { + uuid: { $eq: uuid }, + documentId: { $eq: documentId }, + group: { $eq: group }, + userId: { $eq: 'Group' } }); - if (!item || !item.tokenMap[tokenId]) { - throw new Error('Token is not associated'); - } - if (item.tokenMap[tokenId].frozen === null) { - throw new Error('Can not be unfrozen'); - } - if (item.tokenMap[tokenId].frozen === false) { - throw new Error('Token already unfrozen'); + if (item) { + item.status = status; + await this.update(MultiDocuments, item.id, item); + } else { + item = this.create(MultiDocuments, { + uuid, + documentId, + status, + document: null, + userId: 'Group', + did: null, + group, + username: null + }); + await this.save(MultiDocuments, item); } - item.tokenMap[tokenId].frozen = false; - await new DataBaseHelper(DryRun).update(item); - return true; + return item; } /** - * Get mint request - * @param filters Filters - * @returns Mint request + * Set Residue objects + * @param residue */ - public async getMintRequests(filters: FilterObject): Promise { - return await this.find(MintRequest, filters); + public async setResidue(residue: SplitDocuments[]): Promise { + await this.saveMany(SplitDocuments, residue); } /** - * Grid fs connect + * Save suggestions config + * @param config + * @returns config */ - public static connectGridFS() { - DataBaseHelper.connectGridFS(); + public static async setSuggestionsConfig( + config: Partial + ): Promise { + const existingConfig = await DatabaseServer.getSuggestionsConfig( + config.user + ); + if (existingConfig) { + existingConfig.items = config.items; + } + return await new DataBaseHelper(SuggestionsConfig).save( + existingConfig || config + ); } /** * Set Dry Run id * @param id */ - public static async setSystemMode(dryRunId: string, systemMode: boolean): Promise { - const items = await new DataBaseHelper(DryRun).find({ dryRunId }); - for (const item of items) { - item.systemMode = systemMode; - } - await new DataBaseHelper(DryRun).update(items); - } - - /** - * Create savepoint - * @param dryRunId - * @param systemMode - */ - public static async createSavepoint(dryRunId: string): Promise { - const limit = { limit: DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE }; - const amount = await new DataBaseHelper(DryRun).count({ dryRunId }); - const naturalCount = Math.floor(amount / DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE); - for (let i = 0; i < naturalCount; i++) { - const items = await new DataBaseHelper(DryRun).find({ dryRunId }, limit); - for (const item of items) { - item.savepoint = true; - } - await new DataBaseHelper(DryRun).update(items); - } - const restItems = await new DataBaseHelper(DryRun).find({ dryRunId }); - for (const item of restItems) { - item.savepoint = true; - } - await new DataBaseHelper(DryRun).update(restItems); - - // const files = await new DataBaseHelper(DryRunFiles).find({ policyId: dryRunId }); - // await new DataBaseHelper(DryRunFiles).remove(files); + public setSystemMode(systemMode: boolean): void { + this.systemMode = systemMode; } /** - * Restore savepoint - * @param dryRunId - * @param systemMode + * Set user in group + * + * @param group + * + * @virtual */ - public static async restoreSavepoint(dryRunId: string): Promise { - const limit = { limit: DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE }; - const amount = await new DataBaseHelper(DryRun).count({ dryRunId, savepoint: { $exists: false } }); - const naturalCount = Math.floor(amount / DatabaseServer.DOCUMENTS_HANDLING_CHUNK_SIZE); - for (let i = 0; i < naturalCount; i++) { - const items = await new DataBaseHelper(DryRun).find({ dryRunId, savepoint: { $exists: false } }, limit); - await new DataBaseHelper(DryRun).remove(items); - } - const restItems = await new DataBaseHelper(DryRun).find({ dryRunId, savepoint: { $exists: false } }); - await new DataBaseHelper(DryRun).remove(restItems); - - // const files = await new DataBaseHelper(DryRunFiles).find({ policyId: dryRunId }); - // await new DataBaseHelper(DryRunFiles).remove(files); + public async setUserInGroup(group: unknown): Promise { + const doc = this.create(PolicyRolesCollection, group); + await this.save(PolicyRolesCollection, doc); + return doc; } /** - * Get schemas - * @param filters + * Save Virtual File + * @param policyId + * @param file + * @param url + * + * @virtual */ - public static async getSchema(filters?: FilterObject | string): Promise { - return await new DataBaseHelper(SchemaCollection).findOne(filters); + public static async setVirtualFile( + policyId: string, + file: ArrayBuffer, + url: { url: string } + ): Promise { + await new DataBaseHelper(DryRun).save(DatabaseServer.addDryRunId({ + document: { + size: file?.byteLength + }, + documentURL: url?.url + }, policyId, 'Files', false)); } /** - * Create Statistic - * @param statistic + * Set Key from Virtual User + * @param did + * @param keyName + * @param key + * + * @virtual */ - public static async createStatistic( - statistic: FilterObject - ): Promise { - const item = new DataBaseHelper(PolicyStatistic).create(statistic); - return await new DataBaseHelper(PolicyStatistic).save(item); + public async setVirtualKey(did: string, keyName: string, key: string): Promise { + await new DataBaseHelper(DryRun).save({ + dryRunId: this.dryRun, + dryRunClass: 'VirtualKey', + did, + type: keyName, + hederaAccountKey: key + } as Partial); } /** - * Get Statistics - * @param filters - * @param options + * Save Virtual Transaction + * @param policyId + * @param type + * @param operatorId + * + * @virtual */ - public static async getStatisticsAndCount( - filters?: FilterObject, - options?: FindOptions - ): Promise<[PolicyStatistic[], number]> { - return await new DataBaseHelper(PolicyStatistic).findAndCount(filters, options); + public static async setVirtualTransaction( + policyId: string, + type: string, + operatorId?: string + ): Promise { + await new DataBaseHelper(DryRun).save(DatabaseServer.addDryRunId({ + type, + hederaAccountId: operatorId + }, policyId, 'Transactions', false)); } /** - * Get Statistic By ID - * @param id + * Set Current Virtual User + * @param policyId + * @param did + * + * @virtual */ - public static async getStatisticById(id: string): Promise { - return await new DataBaseHelper(PolicyStatistic).findOne(id); + public static async setVirtualUser(policyId: string, did: string): Promise { + const items = (await new DataBaseHelper(DryRun).find({ + dryRunId: policyId, + dryRunClass: 'VirtualUsers' + })); + for (const item of items) { + item.active = item.did === did; + await new DataBaseHelper(DryRun).save(item); + } } /** - * Get Statistic - * @param filters + * Overriding the update method + * @param entityClass + * @param criteria + * @param row */ - public static async getStatistic(filters: FilterQuery): Promise { - return await new DataBaseHelper(PolicyStatistic).findOne(filters); - } + async update( + entityClass: new () => T, + criteria: FilterQuery, + row: unknown | unknown[] + ): Promise { + if (Array.isArray(criteria)) { + return await this.updateMany(entityClass, row as unknown as T[], criteria) as any; + } - /** - * Delete Statistic - * @param statistic - */ - public static async removeStatistic(statistic: PolicyStatistic): Promise { - return await new DataBaseHelper(PolicyStatistic).remove(statistic); + if (this.dryRun) { + this.addDryRunId(entityClass, row); + return (await new DataBaseHelper(DryRun).update(row as DryRun, criteria as FilterQuery)) as unknown as T; + } else { + return await new DataBaseHelper(entityClass).update(row as T, criteria); + } } /** - * Get Statistics - * @param filters - * @param options + * Update Approval VC + * @param row + * + * @virtual */ - public static async getStatistics( - filters?: FilterQuery, - options?: unknown - ): Promise { - return await new DataBaseHelper(PolicyStatistic).find(filters, options); + public async updateApproval(row: ApprovalDocumentCollection): Promise { + await this.update(ApprovalDocumentCollection, row.id, row); + return row; } /** - * Update Statistic + * Update Did * @param row + * + * @virtual */ - public static async updateStatistic(row: PolicyStatistic): Promise { - return await new DataBaseHelper(PolicyStatistic).update(row); + public async updateDid(row: DidDocumentCollection): Promise { + await this.update(DidDocumentCollection, row.id, row); + return row; } /** - * Get documents - * @param filters - * @param options + * Update External Topic + * @param item + * + * @virtual */ - public static async getStatisticDocumentsAndCount( - filters?: FilterObject, - options?: FindOptions - ): Promise<[VcDocumentCollection[], number]> { - return await new DataBaseHelper(VcDocumentCollection).findAndCount(filters, options); + public async updateExternalTopic(item: ExternalDocument): Promise { + return await this.save(ExternalDocument, item); } /** - * Get documents - * @param filters - * @param options + * Update many method + * @param entityClass + * @param entities + * @param filter */ - public static async getStatisticDocuments( - filters?: FilterQuery, - options?: unknown - ): Promise { - return await new DataBaseHelper(VcDocumentCollection).find(filters, options); + async updateMany( + entityClass: new () => T, + entities: T[], + filter?: FilterQuery + ): Promise { + if (this.dryRun) { + this.addDryRunId(entityClass, entities); + return (await new DataBaseHelper(DryRun).updateMany(entities as unknown as DryRun[], filter as FilterQuery)); + } else { + return await new DataBaseHelper(entityClass).updateMany(entities as T[], filter); + } } /** - * Get document - * @param filters - * @param options + * Update Module + * @param row */ - public static async getStatisticDocument( - filters?: FilterQuery, - options?: unknown - ): Promise { - return await new DataBaseHelper(VcDocumentCollection).findOne(filters, options); + public static async updateModule(row: PolicyModule): Promise { + row.name = row.name.replace(/\s+/g, ' ').trim(); + const dbHelper = new DataBaseHelper(PolicyModule); + if ( + (await dbHelper.count({ + id: { $ne: row.id }, + name: row.name, + owner: row.owner, + })) > 0 + ) { + throw new Error(`Module with name ${row.name} is already exists`); + } + return await dbHelper.update(row); } /** - * Create Statistic - * @param assessment + * Update MultiPolicyTransaction + * @param item */ - public static async createStatisticAssessment( - assessment: FilterObject - ): Promise { - const item = new DataBaseHelper(PolicyStatisticDocument).create(assessment); - return await new DataBaseHelper(PolicyStatisticDocument).save(item); + public static async updateMultiPolicyTransactions(item: MultiPolicyTransaction): Promise { + await new DataBaseHelper(MultiPolicyTransaction).update(item); } /** - * Get statistic assessment - * @param filters + * Update policy + * @param model */ - public static async getStatisticAssessment( - filters: FilterQuery - ): Promise { - return await new DataBaseHelper(PolicyStatisticDocument).findOne(filters); + public static async updatePolicy(model: Policy): Promise { + return await new DataBaseHelper(Policy).save(model); } /** - * Get statistic assessments - * @param filters - * @param options + * Update policy + * @param policyId + * @param data */ - public static async getStatisticAssessmentsAndCount( - filters?: FilterObject, - options?: FindOptions - ): Promise<[PolicyStatisticDocument[], number]> { - return await new DataBaseHelper(PolicyStatisticDocument).findAndCount(filters, options); + public static async updatePolicyConfig(policyId: string, data: Policy): Promise { + const model = await new DataBaseHelper(Policy).findOne(policyId); + model.config = data.config; + model.name = data.name; + model.version = data.version; + model.description = data.description; + model.topicDescription = data.topicDescription; + model.policyRoles = data.policyRoles; + model.policyNavigation = data.policyNavigation; + model.policyTopics = data.policyTopics; + model.policyTokens = data.policyTokens; + model.policyGroups = data.policyGroups; + model.categories = data.categories; + model.projectSchema = data.projectSchema; + + return await new DataBaseHelper(Policy).save(model); } /** - * Get statistic assessment count - * @param filters + * Get policy tests + * @param test + * + * @returns tests */ - public static async getStatisticAssessmentCount( - filters?: FilterObject - ): Promise { - return await new DataBaseHelper(PolicyStatisticDocument).count(filters); + public static async updatePolicyTest(test: PolicyTest): Promise { + return await new DataBaseHelper(PolicyTest).save(test); } /** - * Create Schema Rule - * @param rule + * Update schema + * @param id + * @param item */ - public static async createSchemaRule( - rule: FilterObject - ): Promise { - const item = new DataBaseHelper(SchemaRule).create(rule); - return await new DataBaseHelper(SchemaRule).save(item); + public static async updateSchema(id: string, item: SchemaCollection): Promise { + await new DataBaseHelper(SchemaCollection).update(item, { id }); } /** - * Get Schema Rule - * @param filters - * @param options + * Update schemas + * @param items Schemas */ - public static async getSchemaRulesAndCount( - filters?: FilterObject, - options?: FindOptions - ): Promise<[SchemaRule[], number]> { - return await new DataBaseHelper(SchemaRule).findAndCount(filters, options); + public static async updateSchemas(items: SchemaCollection[]): Promise { + await new DataBaseHelper(SchemaCollection).update(items); } /** - * Get Schema Rule - * @param filters - * @param options + * Update tag + * @param tag */ - public static async getSchemaRules( - filters?: FilterObject, - options?: unknown - ): Promise { - return await new DataBaseHelper(SchemaRule).find(filters, options); + public async updateTag(tag: Tag): Promise { + return await this.update(Tag, tag.id, tag); } /** - * Get Schema Rule By ID - * @param id + * Update tag + * @param tag */ - public static async getSchemaRuleById(id: string): Promise { - return await new DataBaseHelper(SchemaRule).findOne(id); + public static async updateTag(tag: Tag): Promise { + return await new DataBaseHelper(Tag).update(tag); } /** - * Update Schema Rule - * @param rule + * Update tag cache + * @param row */ - public static async updateSchemaRule(rule: SchemaRule): Promise { - return await new DataBaseHelper(SchemaRule).update(rule); + public async updateTagCache(row: TagCache): Promise { + return await this.update(TagCache, row.id, row); } /** - * Delete Schema Rule - * @param rule + * Update tag cache + * @param row */ - public static async removeSchemaRule(rule: SchemaRule): Promise { - return await new DataBaseHelper(SchemaRule).remove(rule); + public static async updateTagCache(row: TagCache): Promise { + return await new DataBaseHelper(TagCache).update(row); } /** - * Create Policy Label - * @param label + * Update tags + * @param tags */ - public static async createPolicyLabel( - label: FilterObject - ): Promise { - const item = new DataBaseHelper(PolicyLabel).create(label); - return await new DataBaseHelper(PolicyLabel).save(item); + public async updateTags(tags: Tag[]): Promise { + return await this.updateMany(Tag, tags); } /** - * Get Policy Label - * @param filters - * @param options + * Update tags + * @param tags */ - public static async getPolicyLabelsAndCount( - filters?: FilterObject, - options?: FindOptions - ): Promise<[PolicyLabel[], number]> { - return await new DataBaseHelper(PolicyLabel).findAndCount(filters, options); + public static async updateTags(tags: Tag[]): Promise { + return await new DataBaseHelper(Tag).updateMany(tags); } /** - * Get Policy Label - * @param filters - * @param options + * Update tags cache + * @param rows */ - public static async getPolicyLabels( - filters?: FilterObject, - options?: unknown - ): Promise { - return await new DataBaseHelper(PolicyLabel).find(filters, options); + public static async updateTagsCache(rows: TagCache[]): Promise { + return await new DataBaseHelper(TagCache).updateMany(rows); } /** - * Get Policy Label By ID - * @param id + * Update Theme + * @param row */ - public static async getPolicyLabelById(id: string): Promise { - return await new DataBaseHelper(PolicyLabel).findOne(id); + public static async updateTheme(row: Theme): Promise { + return await new DataBaseHelper(Theme).update(row); } /** - * Update Policy Label - * @param label + * Update Tool + * @param row */ - public static async updatePolicyLabel(label: PolicyLabel): Promise { - return await new DataBaseHelper(PolicyLabel).update(label); + public static async updateTool(row: PolicyTool): Promise { + return await new DataBaseHelper(PolicyTool).update(row); } /** - * Delete Policy Label - * @param label + * Update topic + * @param row */ - public static async removePolicyLabel(label: PolicyLabel): Promise { - return await new DataBaseHelper(PolicyLabel).remove(label); + public static async updateTopic(row: TopicCollection): Promise { + await new DataBaseHelper(TopicCollection).update(row); } /** - * Create Label Document - * @param document + * Update VC + * @param row + * + * @virtual */ - public static async createLabelDocument( - document: FilterObject - ): Promise { - const item = new DataBaseHelper(PolicyLabelDocument).create(document); - return await new DataBaseHelper(PolicyLabelDocument).save(item); + public async updateVC(row: VcDocumentCollection): Promise { + await this.update(VcDocumentCollection, row.id, row); + return row; } /** - * Get statistic assessments - * @param filters - * @param options + * Update VP + * @param row + * + * @virtual */ - public static async getLabelDocumentsAndCount( - filters?: FilterObject, - options?: FindOptions - ): Promise<[PolicyLabelDocument[], number]> { - return await new DataBaseHelper(PolicyLabelDocument).findAndCount(filters, options); + public async updateVP(row: VpDocumentCollection): Promise { + await this.update(VpDocumentCollection, row.id, row); + return row; } /** - * Get statistic assessment + * Update VP DOcuments + * @param value * @param filters + * @param dryRun */ - public static async getLabelDocument( - filters: FilterQuery - ): Promise { - return await new DataBaseHelper(PolicyLabelDocument).findOne(filters); - } + public static async updateVpDocuments(value: unknown, filters: FilterQuery, dryRun?: string): Promise { + if (dryRun) { + const extendedFilters = filters as FilterQuery & { + dryRunId?: string; + dryRunClass?: string; + }; - /** - * Restore States - */ - public static async restoreStates(policyId: string): Promise { - const states = await new DataBaseHelper(BlockState).find({ policyId }); - for (const state of states) { - state.blockState = state.savedState; - await new DataBaseHelper(BlockState).save(state); + extendedFilters.dryRunId = dryRun; + extendedFilters.dryRunClass = 'VpDocumentCollection'; + + const items = await new DataBaseHelper(DryRun).find(extendedFilters); + + for (const item of items) { + Object.assign(item, value); + } + await new DataBaseHelper(DryRun).update(items); + } else { + const items = await new DataBaseHelper(VpDocumentCollection).find(filters); + for (const item of items) { + Object.assign(item, value); + } + await new DataBaseHelper(VpDocumentCollection).update(items); } } /** - * Copy States + * Virtual Associate Token + * @param hederaAccountId + * @param token + * + * @virtual */ - public static async copyStates(policyId: string): Promise { - const states = await new DataBaseHelper(BlockState).find({ policyId }); - for (const state of states) { - state.savedState = state.blockState; - await new DataBaseHelper(BlockState).save(state); + public async virtualAssociate(hederaAccountId: string, token: TokenCollection): Promise { + const item = await new DataBaseHelper(DryRun).findOne({ + dryRunId: this.dryRun, + dryRunClass: 'HederaAccountInfo', + hederaAccountId + }); + if (item) { + if (item.tokenMap[token.tokenId]) { + throw new Error('Token already associated'); + } else { + item.tokenMap[token.tokenId] = { + frozen: token.enableFreeze ? false : null, + kyc: token.enableKYC ? false : null + }; + await new DataBaseHelper(DryRun).update(item); + } + } else { + const tokenMap = {}; + tokenMap[token.tokenId] = { + frozen: token.enableFreeze ? false : null, + kyc: token.enableKYC ? false : null + }; + await new DataBaseHelper(DryRun).save({ + dryRunId: this.dryRun, + dryRunClass: 'HederaAccountInfo', + hederaAccountId, + tokenMap + }); } + return true; } /** - * Create Formula - * @param formula + * Virtual Dissociate Token + * @param hederaAccountId + * @param tokenId + * + * @virtual */ - public static async createFormula( - formula: FilterObject - ): Promise { - const item = new DataBaseHelper(Formula).create(formula); - return await new DataBaseHelper(Formula).save(item); + public async virtualDissociate(hederaAccountId: string, tokenId: string): Promise { + const item = await new DataBaseHelper(DryRun).findOne({ + dryRunId: this.dryRun, + dryRunClass: 'HederaAccountInfo', + hederaAccountId + }); + if (!item || !item.tokenMap[tokenId]) { + throw new Error('Token is not associated'); + } + delete item.tokenMap[tokenId]; + await new DataBaseHelper(DryRun).update(item); + return true; } /** - * Get Formulas - * @param filters - * @param options + * Virtual Freeze Token + * @param hederaAccountId + * @param tokenId + * + * @virtual */ - public static async getFormulasAndCount( - filters?: FilterObject, - options?: FindOptions - ): Promise<[Formula[], number]> { - return await new DataBaseHelper(Formula).findAndCount(filters, options); + public async virtualFreeze(hederaAccountId: string, tokenId: string): Promise { + const item = await new DataBaseHelper(DryRun).findOne({ + dryRunId: this.dryRun, + dryRunClass: 'HederaAccountInfo', + hederaAccountId + }); + if (!item || !item.tokenMap[tokenId]) { + throw new Error('Token is not associated'); + } + if (item.tokenMap[tokenId].frozen === null) { + throw new Error('Can not be frozen'); + } + if (item.tokenMap[tokenId].frozen === true) { + throw new Error('Token already frozen'); + } + item.tokenMap[tokenId].frozen = true; + await new DataBaseHelper(DryRun).update(item); + return true; } /** - * Get Formulas - * @param filters - * @param options + * Virtual GrantKyc Token + * @param hederaAccountId + * @param tokenId + * + * @virtual */ - public static async getFormulas( - filters?: FilterObject, - options?: unknown - ): Promise { - return await new DataBaseHelper(Formula).find(filters, options); + public async virtualGrantKyc(hederaAccountId: string, tokenId: string): Promise { + const item = await new DataBaseHelper(DryRun).findOne({ + dryRunId: this.dryRun, + dryRunClass: 'HederaAccountInfo', + hederaAccountId + }); + if (!item || !item.tokenMap[tokenId]) { + throw new Error('Token is not associated'); + } + if (item.tokenMap[tokenId].kyc === null) { + throw new Error('Can not be granted kyc'); + } + if (item.tokenMap[tokenId].kyc === true) { + throw new Error('Token already granted kyc'); + } + item.tokenMap[tokenId].kyc = true; + await new DataBaseHelper(DryRun).update(item); + return true; } /** - * Get Formula By ID - * @param id + * Virtual RevokeKyc Token + * @param hederaAccountId + * @param tokenId + * + * @virtual */ - public static async getFormulaById(id: string): Promise { - return await new DataBaseHelper(Formula).findOne(id); + public async virtualRevokeKyc(hederaAccountId: string, tokenId: string): Promise { + const item = await new DataBaseHelper(DryRun).findOne({ + dryRunId: this.dryRun, + dryRunClass: 'HederaAccountInfo', + hederaAccountId + }); + if (!item || !item.tokenMap[tokenId]) { + throw new Error('Token is not associated'); + } + if (item.tokenMap[tokenId].kyc === null) { + throw new Error('Can not be revoked kyc'); + } + if (item.tokenMap[tokenId].kyc === false) { + throw new Error('Token already revoked kyc'); + } + item.tokenMap[tokenId].kyc = false; + await new DataBaseHelper(DryRun).update(item); + return true; } /** - * Update Formula - * @param formula + * Virtual Unfreeze Token + * @param hederaAccountId + * @param tokenId + * + * @virtual */ - public static async updateFormula(formula: Formula): Promise { - return await new DataBaseHelper(Formula).update(formula); + public async virtualUnfreeze(hederaAccountId: string, tokenId: string): Promise { + const item = await new DataBaseHelper(DryRun).findOne({ + dryRunId: this.dryRun, + dryRunClass: 'HederaAccountInfo', + hederaAccountId + }); + if (!item || !item.tokenMap[tokenId]) { + throw new Error('Token is not associated'); + } + if (item.tokenMap[tokenId].frozen === null) { + throw new Error('Can not be unfrozen'); + } + if (item.tokenMap[tokenId].frozen === false) { + throw new Error('Token already unfrozen'); + } + item.tokenMap[tokenId].frozen = false; + await new DataBaseHelper(DryRun).update(item); + return true; } /** - * Delete Formula - * @param formula + * Get mint request + * @param filters Filters + * @returns Mint request */ - public static async removeFormula(formula: Formula): Promise { - return await new DataBaseHelper(Formula).remove(formula); + public async getMintRequests(filters: FilterObject): Promise { + return await this.find(MintRequest, filters); } } diff --git a/common/src/interfaces/database-server.ts b/common/src/interfaces/database-server.ts index 6484492865..971ee9bc60 100644 --- a/common/src/interfaces/database-server.ts +++ b/common/src/interfaces/database-server.ts @@ -1,89 +1,65 @@ -import {TopicId} from '@hashgraph/sdk'; - //entities -import { - AssignedEntityType, - IVC, - MintTransactionStatus, - PolicyTestStatus, - SchemaEntity, - TopicType -} from '@guardian/interfaces'; -import { BaseEntity } from '../models/index.js'; +import { AssignedEntityType, IVC, MintTransactionStatus, PolicyTestStatus, SchemaEntity, TopicType } from '@guardian/interfaces'; +import { TopicId } from '@hashgraph/sdk'; +import { FilterQuery } from '@mikro-orm/core'; import { AggregateVC, ApprovalDocument as ApprovalDocumentCollection, Artifact as ArtifactCollection, + AssignEntity, BlockCache, BlockState, + Contract as ContractCollection, DidDocument as DidDocumentCollection, DocumentState, DryRun, ExternalDocument, + Message, MintRequest, MintTransaction, MultiDocuments, + MultiPolicy, MultiPolicyTransaction, Policy, + PolicyCache, + PolicyCacheData, PolicyCategory, PolicyInvitations, PolicyModule, + PolicyProperty, PolicyRoles as PolicyRolesCollection, + PolicyTest, + PolicyTool, + Record, + RetirePool, Schema as SchemaCollection, SplitDocuments, + SuggestionsConfig, Tag, TagCache, + Theme, Token as TokenCollection, Topic as TopicCollection, VcDocument as VcDocumentCollection, VpDocument, - VpDocument as VpDocumentCollection, - Message, - PolicyProperty, - PolicyTool, - PolicyCache, - PolicyCacheData, - MultiPolicy, - RetirePool, - Contract as ContractCollection, - Theme, - SuggestionsConfig, - Record, - AssignEntity, - PolicyTest, + VpDocument as VpDocumentCollection } from '../index.js'; +import { BaseEntity } from '../models/index.js'; //interfaces -import {IAuthUser, IGetDocumentAggregationFilters, IOrmConnection, STATUS_IMPLEMENTATION} from './index.js'; -import { FilterQuery } from '@mikro-orm/core'; +import { IAuthUser, IGetDocumentAggregationFilters, IOrmConnection, STATUS_IMPLEMENTATION } from './index.js'; export interface IAddDryRunIdItem { dryRunId: string, dryRunClass: string, systemMode: boolean + savepoint?: boolean } /** * Abstract database server */ export abstract class AbstractDatabaseServer { - /** - * Set Dry Run id - * @param id - */ - public abstract setDryRun(id: string): void; - - /** - * Get Dry Run id - * @returns Dry Run id - */ - public abstract getDryRun(): string; - /** - * Set System Mode - * @param systemMode - */ - public abstract setSystemMode(systemMode: boolean): void; - /** * Set MongoDriver * @param db @@ -92,12 +68,6 @@ export abstract class AbstractDatabaseServer { throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.connectBD.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } - /** - * Clear Dry Run table - * @param all - */ - public abstract clear(all: boolean): Promise; - /** * Clear Dry Run table * @param dryRunId @@ -107,133 +77,6 @@ export abstract class AbstractDatabaseServer { throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.clearDryRun.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } - /** - * Overriding the findOne method - * @param entityClass - * @param filters - * @param options - */ - public abstract findOne(entityClass: new () => T, filters: Partial, options: unknown): Promise; - - /** - * Overriding the find method - * @param entityClass - * @param filters - * @param options - */ - public abstract find(entityClass: new () => T, filters: Partial | unknown, options?: unknown): Promise; - - /** - * Overriding the create method - * @param entityClass - * @param item - */ - public abstract create(entityClass: new () => T, item: Partial): T; - - /** - * Overriding the update method - * @param entityClass - * @param criteria - * @param row - */ - public abstract update(entityClass: new () => T, criteria: Partial, row: unknown | unknown[]): Promise; - - /** - * Update many method - * @param entityClass - * @param entities - * @param filter - */ - public abstract updateMany(entityClass: new () => T, entities: T[], filter: FilterQuery): Promise; - - /** - * Overriding the remove method - * @param entityClass - * @param entities - */ - public abstract remove(entityClass: new () => T, entities: T | T[]): Promise; - - /** - * Overriding the count method - * @param entityClass - * @param filters - * @param options - */ - public abstract count(entityClass: new () => T, filters: Partial, options?: unknown): Promise; - - /** - * Overriding the findAndCount method - * @param entityClass - * @param filters - * @param options - */ - public abstract findAndCount(entityClass: new () => T, filters: Partial | unknown, options?: unknown): Promise<[T[], number]>; - - /** - * Overriding the findAll method - * @param entityClass - * @param options - */ - public abstract findAll(entityClass: new () => T, options?: unknown): Promise; - - /** - * Find data by aggregation - * @param entityClass Entity class - * @param aggregation aggregate filter - * @returns - */ - public abstract aggregate(entityClass: new () => T, aggregation: Partial[]): Promise; - - /** - * Overriding the save method - * @param entityClass - * @param item - * @param filter - */ - public abstract save(entityClass: new () => T, item: unknown | unknown[], filter?: Partial): Promise - - /** - * Save many - * @param entityClass - * @param item - * @param filter - */ - public abstract saveMany(entityClass: new () => T, item: unknown[], filter?: Partial): Promise - - /** - * Save Block State - * @param policyId - * @param uuid - * @param state - * - * @virtual - */ - public abstract saveBlockState(policyId: string, uuid: string, state: unknown): Promise; - - /** - * Get Block State - * @param policyId - * @param uuid - * - * @virtual - */ - public abstract getBlockState(policyId: string, uuid: string): Promise; - - /** - * Get block states - * @param policyId Policy identifier - * @returns Block states - */ - public abstract getBlockStates(policyId: string): Promise; - - /** - * Get Virtual User - * @param did - * - * @virtual - */ - public abstract getVirtualUser(did: string): Promise; - /** * Get Current Virtual User * @param policyId @@ -303,256 +146,65 @@ export abstract class AbstractDatabaseServer { } /** - * Get Key from Virtual User - * @param did - * @param keyName - * - * @virtual + * Get VC + * @param id */ - public abstract getVirtualKey(did: string, keyName: string): Promise; + public static async getVCById(id: string): Promise | null { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVCById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get virtual keys - * @param filters Filters - * @returns Virtual keys + * Get VC + * @param filters + * @param options */ - public abstract getVirtualKeys(filters: Partial): Promise; + public static async getVC(filters?: Partial, options?: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVC.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Set Key from Virtual User - * @param did - * @param keyName - * @param key - * - * @virtual + * Get VCs + * @param filters + * @param options */ - public abstract setVirtualKey(did: string, keyName: string, key: string): Promise; + public static async getVCs(filters?: Partial, options?: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVCs.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Virtual Hedera Account - * @param hederaAccountId - * - * @virtual + * Get VC + * @param id */ - public abstract getVirtualHederaAccountInfo(hederaAccountId: string): Promise; + public static async getVPById(id: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVPById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Virtual Associate Token - * @param hederaAccountId - * @param token - * - * @virtual + * Get VC + * @param filters + * @param options */ - public abstract virtualAssociate(hederaAccountId: string, token: TokenCollection): Promise; + public static async getVP(filters?: Partial, options?: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Virtual Dissociate Token - * @param hederaAccountId - * @param tokenId - * - * @virtual + * Get VCs + * @param filters + * @param options */ - public abstract virtualDissociate(hederaAccountId: string, tokenId: string): Promise; + public static async getVPs(filters?: Partial, options?: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVP.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Virtual Freeze Token - * @param hederaAccountId - * @param tokenId - * - * @virtual - */ - public abstract virtualFreeze(hederaAccountId: string, tokenId: string): Promise; - - /** - * Virtual Unfreeze Token - * @param hederaAccountId - * @param tokenId - * - * @virtual - */ - public abstract virtualUnfreeze(hederaAccountId: string, tokenId: string): Promise; - - /** - * Virtual GrantKyc Token - * @param hederaAccountId - * @param tokenId - * - * @virtual - */ - public abstract virtualGrantKyc(hederaAccountId: string, tokenId: string): Promise; - - /** - * Virtual RevokeKyc Token - * @param hederaAccountId - * @param tokenId - * - * @virtual - */ - public abstract virtualRevokeKyc(hederaAccountId: string, tokenId: string): Promise; - - /** - * Save Block State - * @param {string} policyId - policy ID - * @param {string} blockId - block UUID - * @param {string} did - user DID - * @param {string} name - variable name - * @param {unknown} value - variable value - * @param {boolean} isLongValue - if long value - * @virtual - */ - public abstract saveBlockCache(policyId: string, blockId: string, did: string, name: string, value: unknown, isLongValue: boolean): Promise; - - /** - * Get Block State - * @param {string} policyId - policy ID - * @param {string} blockId - block UUID - * @param {string} did - user DID - * @param {string} name - variable name - * - * @returns {BlockCache | null} - variable value - * @virtual - */ - public abstract getBlockCache(policyId: string, blockId: string, did: string, name: string): Promise; - - /** - * Save Document State - * @param row - * - * @virtual - */ - public abstract saveDocumentState(row: Partial): Promise; - - /** - * Create Token - * @param token - * @returns - */ - public abstract createToken(token: unknown): Promise; - - /** - * Update Approval VC - * @param row - * - * @virtual - */ - public abstract updateApproval(row: ApprovalDocumentCollection): Promise; - - /** - * Update VC - * @param row - * - * @virtual - */ - public abstract updateVC(row: VcDocumentCollection): Promise; - - /** - * Update VP - * @param row - * - * @virtual - */ - public abstract updateVP(row: VpDocumentCollection): Promise; - - /** - * Update Did - * @param row - * - * @virtual - */ - public abstract updateDid(row: DidDocumentCollection): Promise; - - /** - * Save Approval VC - * @param row - * - * @virtual - */ - public abstract saveApproval(row: Partial): Promise; - - /** - * Save VC - * @param row - * - * @virtual - */ - public abstract saveVC(row: Partial): Promise; - - /** - * Get VC - * @param id - */ - public static async getVCById(id: string): Promise | null { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVCById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } - - /** - * Get VC - * @param filters - * @param options - */ - public static async getVC(filters?: Partial, options?: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVC.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } - - /** - * Get VCs - * @param filters - * @param options - */ - public static async getVCs(filters?: Partial, options?: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVCs.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } - - /** - * Get VC - * @param id - */ - public static async getVPById(id: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVPById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } - - /** - * Get VC - * @param filters - * @param options - */ - public static async getVP(filters?: Partial, options?: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } - - /** - * Get VCs - * @param filters - * @param options - */ - public static async getVPs(filters?: Partial, options?: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVP.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } - - /** - * Save VC - * @param row + * Save VC + * @param row */ public static async saveVC(row: Partial): Promise { throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveVC.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } - /** - * Save VP - * @param row - * - * @virtual - */ - public abstract saveVP(row: Partial): Promise; - - /** - * Save Did - * @param row - * - * @virtual - */ - public abstract saveDid(row: Partial): Promise; - /** * Get policy * @param filters @@ -668,14 +320,6 @@ export abstract class AbstractDatabaseServer { throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTopicByType.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } - /** - * Get Policy - * @param policyId - * - * @virtual - */ - public abstract getPolicy(policyId: string): Promise; - /** * Get Publish Policies * @@ -715,1698 +359,2048 @@ export abstract class AbstractDatabaseServer { } /** - * Get Aggregate Documents - * @param policyId - * @param blockId - * @param filters - * - * @virtual + * Save topic + * @param row */ - public abstract getAggregateDocuments(policyId: string, blockId: string, filters: unknown): Promise; + public static async saveTopic(row: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveTopic.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get aggregate document by policy identifier - * @param policyId Policy identifier - * @returns Aggregate documents + * Update topic + * @param row */ - public abstract getAggregateDocumentsByPolicy(policyId: string): Promise; + public static async updateTopic(row: TopicCollection): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTopic.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Remove Aggregate Documents - * @param removeMsp - * - * @virtual + * Get schema + * @param item */ - public abstract removeAggregateDocuments(removeMsp: AggregateVC[]): Promise; + public static createSchema(item: Partial): SchemaCollection { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createSchema.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Remove Aggregate Document - * @param hash - * @param blockId - * - * @virtual + * Get schema + * @param items */ - public abstract removeAggregateDocument(hash: string, blockId: string): Promise; + public static async saveSchema(items: SchemaCollection): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveSchema.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Create Aggregate Documents + * Get schema * @param item - * @param blockId - * - * @virtual */ - public abstract createAggregateDocuments(item: VcDocumentCollection & { blockId: string }, blockId: string): Promise; + public static async saveSchemas(item: SchemaCollection[]): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveSchemas.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Vc Document - * @param filters - * - * @virtual + * Get schema + * @param item */ - public abstract getVcDocument(filters: Partial): Promise; + public static async createAndSaveSchema(item: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createAndSaveSchema.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Vp Document + * Get schema * @param filters - * - * @virtual + * @param options */ - public abstract getVpDocument(filters: Partial): Promise; + public static async getSchemasAndCount(filters?: Partial, options?: unknown): Promise<[SchemaCollection[], number]> { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemasAndCount.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Approval Document - * @param filters - * - * @virtual + * Get schema + * @param ids */ - public abstract getApprovalDocument(filters: Partial): Promise; + public static async getSchemasByIds(ids: string[]): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemasByIds.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Vc Documents - * @param aggregation - * @virtual + * Get schema + * @param id */ - public abstract getVcDocumentsByAggregation(aggregation: Partial[]): Promise; + public static async getSchemaById(id: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemaById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Vp Documents - * @param aggregation - * @virtual + * Get schema + * @param filters */ - public abstract getVpDocumentsByAggregation(aggregation: Partial[]): Promise; + public static async getSchemasCount(filters?: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemasCount.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Did Documents - * @param aggregation - * @virtual + * Get schema + * @param topicId + * @param entity */ - public abstract getDidDocumentsByAggregation(aggregation: Partial[]): Promise; + public static async getSchemaByType(topicId: string, entity: SchemaEntity): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemaByType.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Approval Documents - * @param aggregation - * @virtual + * Get system schema + * @param entity */ - public abstract getApprovalDocumentsByAggregation(aggregation: Partial[]): Promise; + public static async getSystemSchema(entity: SchemaEntity): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSystemSchema.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Vc Documents + * Get schemas * @param filters * @param options - * @param countResult - * @virtual */ - public abstract getVcDocuments(filters: Partial, options?: unknown, countResult?: boolean): Promise; + public static async getSchemas(filters?: Partial, options?: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemas.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Vp Documents - * @param filters - * - * @param options - * @param countResult - * @virtual + * Delete schemas + * @param id */ - public abstract getVpDocuments(filters: Partial, options?: unknown, countResult?: boolean): Promise; + public static async deleteSchemas(id: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.deleteSchemas.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Did Documents - * @param filters - * - * @param options - * @param countResult - * @virtual + * Get user role in policy + * @param policyId + * @param did */ - public abstract getDidDocuments(filters: Partial, options?: unknown, countResult?: boolean): Promise; + public static async getUserRole(policyId: string, did: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getUserRole.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Did Document - * @param did + * Update policy + * @param policyId + * @param data */ - public abstract getDidDocument(did: string): Promise; + public static async updatePolicyConfig(policyId: string, data: Policy): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updatePolicyConfig.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Approval Documents - * @param filters - * @param options - * @param countResult + * Create Virtual User + * @param policyId + * @param username + * @param did + * @param hederaAccountId + * @param hederaAccountKey + * @param active + * @param systemMode + * * @virtual */ - public abstract getApprovalDocuments(filters: Partial, options?: unknown, countResult?: boolean): Promise; + public static async createVirtualUser( + policyId: string, + username: string, + did: string, + hederaAccountId: string, + hederaAccountKey: string, + active: boolean, + systemMode?: boolean + ): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createVirtualUser.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Document States - * @param filters - * @param options + * Save Virtual Message + * @param dryRun + * @param message * * @virtual */ - public abstract getDocumentStates(filters: Partial, options?: unknown): Promise; + public static async saveVirtualMessage(dryRun: string, message: Message): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveVirtualMessage.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Topic - * @param filters + * Get Virtual Messages + * @param dryRun + * @param topicId * * @virtual */ - public abstract getTopic( - filters: { - /** - * policyId - */ - policyId?: string, - /** - * type - */ - type?: TopicType, - /** - * name - */ - name?: string, - /** - * owner - */ - owner?: string, - /** - * topicId - */ - topicId?: string - }): Promise; + public static async getVirtualMessages(dryRun: string, topicId: string | TopicId): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVirtualMessages.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Topics - * @param filters + * Get Virtual Message + * @param dryRun + * @param messageId * * @virtual */ - public abstract getTopics( - filters: { - /** - * policyId - */ - policyId?: string, - /** - * type - */ - type?: TopicType, - /** - * name - */ - name?: string, - /** - * owner - */ - owner?: string, - /** - * topicId - */ - topicId?: string - }): Promise; + public static async getVirtualMessage(dryRun: string, messageId: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVirtualMessage.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get topic by id - * @param topicId + * Get tokens + * @param filters Filters + * @returns Tokens */ - public abstract getTopicById(topicId: string): Promise; + public static async getTokens(filters?: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTokens.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** * Get Token * @param tokenId - * @param dryRun */ - public abstract getToken(tokenId: string, dryRun?: string): Promise; + public static async getToken(tokenId: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getToken.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Save topic - * @param row + * Get Token by ID + * @param id */ - public static async saveTopic(row: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveTopic.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async getTokenById(id: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTokenById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Save Topic - * @param topic - * - * @virtual + * Get Contract by ID + * @param id */ - public abstract saveTopic(topic: TopicCollection): Promise; + public static async getContractById(id: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getContractById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Update topic - * @param row + * Create MultiPolicyTransaction + * @param transaction */ - public static async updateTopic(row: TopicCollection): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTopic.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async createMultiPolicyTransaction(transaction: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createMultiPolicyTransaction.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get schema - * @param iri - * @param topicId + * Get MultiPolicyTransaction + * @param policyId + * @param owner */ - public abstract getSchemaByIRI(iri: string, topicId?: string): Promise; + public static async getMultiPolicyTransactions(policyId: string, owner: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getMultiPolicyTransactions.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get schema - * @param item + * Get MultiPolicyTransaction count + * @param policyId */ - public static createSchema(item: Partial): SchemaCollection { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createSchema.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async countMultiPolicyTransactions(policyId: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.countMultiPolicyTransactions.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get schema - * @param items + * Create createModules + * @param module */ - public static async saveSchema(items: SchemaCollection): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveSchema.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async createModules(module: PolicyModule): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createModules.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get schema - * @param item + * Get Modules + * @param filters + * @param options */ - public static async saveSchemas(item: SchemaCollection[]): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveSchemas.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async getModulesAndCount(filters?: Partial, options?: unknown): Promise<[PolicyModule[], number]> { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getModulesAndCount.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get schema - * @param item + * Get Module By UUID + * @param uuid */ - public static async createAndSaveSchema(item: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createAndSaveSchema.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async getModuleByUUID(uuid: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getModuleByUUID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get schema + * Get Module * @param filters - * @param options */ - public static async getSchemasAndCount(filters?: Partial, options?: unknown): Promise<[SchemaCollection[], number]> { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemasAndCount.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async getModule(filters: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getModuleByUUID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get schema - * @param ids + * Delete Module + * @param module */ - public static async getSchemasByIds(ids: string[]): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemasByIds.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async removeModule(module: PolicyModule): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeModule.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get schema - * @param id + * Get Modules + * @param filters + * @param options */ - public static async getSchemaById(id: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemaById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } - - /** - * Get schema - * @param filters - */ - public static async getSchemasCount(filters?: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemasCount.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async getModules(filters?: Partial, options?: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getModules.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get schema - * @param topicId - * @param entity + * Update Module + * @param row */ - public static async getSchemaByType(topicId: string, entity: SchemaEntity): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemaByType.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async updateModule(row: PolicyModule): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateModule.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get system schema - * @param entity + * Create Tool + * @param tool */ - public static async getSystemSchema(entity: SchemaEntity): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSystemSchema.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async createTool(tool: PolicyTool): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createTool.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get schemas + * Get Tools * @param filters * @param options */ - public static async getSchemas(filters?: Partial, options?: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getSchemas.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async getToolsAndCount(filters?: PolicyTool, options?: unknown): Promise<[PolicyTool[], number]> { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getToolsAndCount.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Delete schemas - * @param id + * Get Tool By UUID + * @param uuid */ - public static async deleteSchemas(id: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.deleteSchemas.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async getToolByUUID(uuid: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getToolByUUID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get schema - * @param topicId - * @param entity + * Get Tool + * @param filters */ - public abstract getSchemaByType(topicId: string, entity: SchemaEntity): Promise; + public static async getTool(filters: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTool.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Set user in group - * - * @param group - * - * @virtual + * Delete Tool + * @param tool */ - public abstract setUserInGroup(group: unknown): Promise; + public static async removeTool(tool: PolicyTool): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeTool.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Set Active Group - * - * @param policyId - * @param did - * @param uuid - * - * @virtual + * Get Tools + * @param filters + * @param options */ - public abstract setActiveGroup(policyId: string, did: string, uuid: string): Promise; + public static async getTools(filters?: Partial, options?: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTools.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Group By UUID - * @param policyId - * @param uuid - * - * @virtual + * Update Tool + * @param row */ - public abstract getGroupByID(policyId: string, uuid: string): Promise; + public static async updateTool(row: PolicyTool): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTool.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Group By Name - * @param policyId - * @param groupName - * - * @virtual + * Create tag + * @param tag */ - public abstract getGlobalGroup(policyId: string, groupName: string): Promise; + public static async createTag(tag: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createTag.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get User In Group - * @param policyId - * @param did - * @param uuid - * - * @virtual + * Delete tag + * @param tag */ - public abstract getUserInGroup(policyId: string, did: string, uuid: string): Promise; + public static async removeTag(tag: Tag): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeTag.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Check User In Group - * @param group - * - * @virtual + * Get tag By UUID + * @param uuid */ - public abstract checkUserInGroup(group: { policyId: string, did: string, owner: string, uuid: string }): Promise; + public static async getTagById(uuid: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTagById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Groups By User - * @param policyId - * @param did + * Get tags + * @param filters * @param options - * - * @virtual */ - public abstract getGroupsByUser(policyId: string, did: string, options?: unknown): Promise; + public static async getTags(filters?: Partial, options?: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTags.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Active Group By User - * @param policyId - * @param did - * - * @virtual + * Update tag + * @param tag */ - public abstract getActiveGroupByUser(policyId: string, did: string): Promise; + public static async updateTag(tag: Tag): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTag.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get members - * - * @param group - * - * @virtual + * Update tags + * @param tags */ - public abstract getAllMembersByGroup(group: PolicyRolesCollection): Promise; + public static async updateTags(tags: Tag[]): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTag.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get all policy users - * @param policyId - * - * @virtual + * Create tag cache + * @param tag */ - public abstract getAllPolicyUsers(policyId: string): Promise; + public static async createTagCache(tag: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createTagCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get all policy users - * @param policyId - * @param uuid - * @param role - * - * @virtual + * Get tags + * @param filters + * @param options */ - public abstract getAllUsersByRole(policyId: string, uuid: string, role: string): Promise; + public static async getTagCache(filters?: Partial , options?: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTagCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get all policy users by role - * @param policyId - * @param role - * - * @virtual + * Update tag cache + * @param row */ - public abstract getUsersByRole(policyId: string, role: string): Promise; + public static async updateTagCache(row: TagCache): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTagCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get user role in policy - * @param policyId - * @param did + * Update tags cache + * @param rows */ - public static async getUserRole(policyId: string, did: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getUserRole.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + public static async updateTagsCache(rows: TagCache[]): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTagsCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); } /** - * Get user roles - * @param policyId - * @param did - * @returns - * - * @virtual + * Create Theme + * @param theme */ - public abstract getUserRoles(policyId: string, did: string): Promise; + public static async createTheme(theme: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createTheme.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Delete user - * @param group - * - * @virtual + * Get Theme + * @param filters */ - public abstract deleteGroup(group: PolicyRolesCollection): Promise; + public static async getTheme(filters: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTheme.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Create invite token - * @param policyId - * @param uuid - * @param owner - * @param role - * - * @virtual + * Get Themes + * @param filters */ - public abstract createInviteToken(policyId: string, uuid: string, owner: string, role: string): Promise; + public static async getThemes(filters: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getThemes.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Parse invite token - * @param policyId - * @param invitationId - * - * @virtual + * Delete Theme + * @param theme */ - public abstract parseInviteToken(policyId: string, invitationId: string): Promise; + public static async removeTheme(theme: Theme): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeTheme.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get MultiSign Status by document or user - * @param uuid - * @param documentId - * @param userId - * - * @virtual + * Update Theme + * @param row */ - public abstract getMultiSignStatus(uuid: string, documentId: string, userId: string): Promise; + public static async updateTheme(row: Theme): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTheme.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get MultiSign Statuses - * @param uuid - * @param documentId - * @param group + * Save suggestions config + * @param config + * @returns config + */ + public static async setSuggestionsConfig(config: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.setSuggestionsConfig.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get suggestions config + * @param did + * @returns config + */ + public static async getSuggestionsConfig(did: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.setSuggestionsConfig.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get retire pools + * @param tokenIds Token identifiers + * @returns Retire pools + */ + public static async getRetirePools(tokenIds: string[]): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getRetirePools.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Save Artifact + * @param artifact Artifact + * @returns Saved Artifact + */ + public static async saveArtifact(artifact: ArtifactCollection): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveArtifact.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Save Artifacts + * @param artifacts Artifacts + * @returns Saved Artifacts + */ + public static async saveArtifacts(artifacts: ArtifactCollection[]): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveArtifact.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get Artifact + * @param filters Filters + * @returns Artifact + */ + public static async getArtifact(filters?: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getArtifact.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get Artifacts + * @param filters Filters + * @param options Options + * @returns Artifacts + */ + public static async getArtifacts(filters?: Partial, options?: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getArtifacts.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get Artifacts + * @param filters Filters + * @param options Options + * @returns Artifacts + */ + public static async getArtifactsAndCount(filters?: Partial, options?: unknown): Promise<[ArtifactCollection[], number]> { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getArtifactsAndCount.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Remove Artifact + * @param artifact Artifact + */ + public static async removeArtifact(artifact?: ArtifactCollection): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeArtifact.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Save Artifact File + * @param uuid File UUID + * @param data Data + */ + public static async saveArtifactFile(uuid: string, data: Buffer): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveArtifactFile.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get Artifact File By UUID + * @param uuid File UUID + * @returns Buffer + */ + public static async getArtifactFileByUUID(uuid: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getArtifactFileByUUID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get Multi Policy link + * @param instanceTopicId + * @param owner + * @returns MultiPolicy + */ + public static async getMultiPolicy(instanceTopicId: string, owner: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getArtifactFileByUUID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Create Multi Policy object + * @param multiPolicy + * @returns MultiPolicy + */ + public static createMultiPolicy(multiPolicy: MultiPolicy): MultiPolicy { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createMultiPolicy.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Save Multi Policy object + * @param multiPolicy + * @returns multiPolicy + */ + public static async saveMultiPolicy(multiPolicy: MultiPolicy): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveMultiPolicy.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get Module By ID + * @param id + */ + public static async getModuleById(id: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getModuleById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get Tool By ID + * @param id + */ + public static async getToolById(id: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getToolById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Update MultiPolicyTransaction + * @param item + */ + public static async updateMultiPolicyTransactions(item: MultiPolicyTransaction): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateMultiPolicyTransactions.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Update schema + * @param id + * @param item + */ + public static async updateSchema(id: string, item: SchemaCollection): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateSchema.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Update schemas + * @param items Schemas + */ + public static async updateSchemas(items: SchemaCollection[]): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateSchemas.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get policy caches + * @param filters Filters + * @returns Policy caches + */ + public static async getPolicyCaches(filters?: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyCaches.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Save policy cache + * @param entity Entity + * @returns Policy cache + */ + public static async savePolicyCache(entity: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.savePolicyCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get policy cache + * @param filters Filters + * @returns Policy cache + */ + public static async getPolicyCache(filters: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.savePolicyCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get policy cache data + * @param filters Filters + * @param options Options + * @returns Policy cache data + */ + public static async getPolicyCacheData(filters?: Partial, options?: PolicyCacheData): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyCacheData.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Save policy cache data + * @param entity Policy cache data + * @returns Policy cache data + */ + public static async savePolicyCacheData(entity: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.savePolicyCacheData.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get and count policy cache data + * @param filters Filters + * @param options Options + * @returns Policy cache data and count + */ + public static async getAndCountPolicyCacheData(filters?: Partial, options?: unknown): Promise<[PolicyCacheData[], number]> { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getAndCountPolicyCacheData.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Clear policy caches + * @param filters Filters + */ + public static async clearPolicyCaches(filters?: Partial | string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.clearPolicyCaches.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Clear policy cache data + * @param cachePolicyId Cache policy id + */ + public static async clearPolicyCacheData(cachePolicyId: string) { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.clearPolicyCacheData.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Update VP Documents + * @param value + * @param filters + * @param dryRun + */ + public static async updateVpDocuments(value: unknown, filters: Partial, dryRun?: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateVpDocuments.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Create Record + * @param record + */ + public static async createRecord(record: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createRecord.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get Record + * @param filters Filters + * @param options Options + * @returns Record + */ + public static async getRecord(filters?: Partial, options?: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getRecord.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get Group By UUID + * @param policyId + * @param uuid * - * @virtual + * @returns Group */ - public abstract getMultiSignDocuments(uuid: string, documentId: string, group: string): Promise + public static async getGroupByID(policyId: string, uuid: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getGroupByID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get multi sign documents by document identifiers - * @param documentIds Document identifiers - * @returns Multi sign documents + * Get Groups By User + * @param policyId + * @param did + * @param options + * + * @returns Groups */ - public abstract getMultiSignDocumentsByDocumentIds(documentIds: string[]): Promise + public static async getGroupsByUser(policyId: string, did: string, options?: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getGroupsByUser.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get MultiSign Statuses by group - * @param uuid - * @param group + * Save VCs + * @param data * - * @virtual + * @returns VCs */ - public abstract getMultiSignDocumentsByGroup(uuid: string, group: string): Promise + // tslint:disable-next-line:adjacent-overload-signatures + public static async saveVCs(data: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveVCs.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Set MultiSign Status by document + * Save VPs + * @param data + * + * @returns VPs + */ + public static async saveVPs(data: Partial): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveVPs.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get Did Document + * @param did + */ + public static async getDidDocument(did: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getDidDocument.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Assign entity + * @param type + * @param entityId + * @param assigned + * @param did + * @param owner + */ + public static async assignEntity(type: AssignedEntityType, entityId: string, assigned: boolean, did: string, owner: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.assignEntity.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Check entity + * @param type + * @param entityId + * @param did + */ + public static async getAssignedEntity(type: AssignedEntityType, entityId: string, did: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getAssignedEntity.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get assigned entities + * @param did + * @param type + */ + public static async getAssignedEntities(did: string, type?: AssignedEntityType): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getAssignedEntities.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Remove assign entity + * @param type + * @param entityId + * @param did + * @param owner + */ + public static async removeAssignEntity(type: AssignedEntityType, entityId: string, did: string, owner?: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeAssignEntity.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Save file * @param uuid - * @param documentId - * @param group - * @param status + * @param buffer * - * @virtual + * @returns file ID */ - public abstract setMultiSigStatus(uuid: string, documentId: string, group: string, status: string): Promise + public static async saveFile(uuid: string, buffer: Buffer): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveFile.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Save mint request - * @param data Mint request - * @returns Saved mint request + * Load file + * @param id + * + * @returns file ID */ - public abstract saveMintRequest(data: Partial): Promise; + public static async loadFile(id: unknown): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.loadFile.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Create Residue object + * Get policy tests * @param policyId - * @param blockId - * @param userId - * @param value - * @param document + * @returns tests */ - public abstract createResidue( - policyId: string, - blockId: string, - userId: string, - value: unknown, - document: unknown - ): SplitDocuments; + public static async getPolicyTests(policyId: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyTests.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get Residue objects + * Assign entity + * @param config + * @param buffer + */ + public static async createPolicyTest(config: { [key: string]: unknown }, buffer: Buffer): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createPolicyTest.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get policy test * @param policyId - * @param blockId - * @param userId + * @param id + * @returns tests */ - public abstract getResidue(policyId: string, blockId: string, userId: string): Promise; + public static async getPolicyTest(policyId: string, id: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyTest.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get External Topic + * Get policy test * @param policyId - * @param blockId - * @param userId + * @param status + * @returns tests + */ + public static async getPolicyTestsByStatus(policyId: string, status: PolicyTestStatus): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyTestsByStatus.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Get policy tests + * @param resultId * - * @virtual + * @returns tests */ - public abstract getExternalTopic(policyId: string, blockId: string, userId: string): Promise + public static async getPolicyTestByRecord(resultId: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyTestByRecord.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Get split documents in policy - * @param policyId Policy identifier - * @returns Split documents + * Get policy tests + * @param policyId + * @param id + * @returns tests */ - public abstract getSplitDocumentsByPolicy(policyId: string): Promise + public static async deletePolicyTest(policyId: string, id: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.deletePolicyTest.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Set Residue objects - * @param residue + * Get policy tests + * @param test + * + * @returns tests */ - public abstract setResidue(residue: SplitDocuments[]): Promise + public static async updatePolicyTest(test: PolicyTest): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updatePolicyTest.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Remove Residue objects - * @param residue + * Get policy tests + * @param policyId + * + * @returns tests */ - public abstract removeResidue(residue: SplitDocuments[]): Promise; + public static async deletePolicyTests(policyId: string): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.deletePolicyTests.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } /** - * Create tag - * @param tag + * Get policy tests + * @returns tests */ - public abstract createTag(tag: Tag): Promise; + public static async removePolicyTests(tests: PolicyTest[]): Promise { + throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removePolicyTests.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); + } + + /** + * Set Dry Run id + * @param id + */ + public abstract setDryRun(id: string): void; + + /** + * Get Dry Run id + * @returns Dry Run id + */ + public abstract getDryRun(): string; + + /** + * Set System Mode + * @param systemMode + */ + public abstract setSystemMode(systemMode: boolean): void; + + /** + * Clear Dry Run table + * @param all + */ + public abstract clear(all: boolean): Promise; + + /** + * Overriding the findOne method + * @param entityClass + * @param filters + * @param options + */ + public abstract findOne(entityClass: new () => T, filters: Partial, options: unknown): Promise; + + /** + * Overriding the find method + * @param entityClass + * @param filters + * @param options + */ + public abstract find(entityClass: new () => T, filters: Partial | unknown, options?: unknown): Promise; + + /** + * Overriding the create method + * @param entityClass + * @param item + */ + public abstract create(entityClass: new () => T, item: Partial): T; /** - * Get tags - * @param filters - * @param options + * Overriding the update method + * @param entityClass + * @param criteria + * @param row */ - public abstract getTags(filters?: Partial, options?: unknown): Promise + public abstract update(entityClass: new () => T, criteria: Partial, row: unknown | unknown[]): Promise; /** - * Get tags - * @param filters - * @param options + * Update many method + * @param entityClass + * @param entities + * @param filter */ - public abstract getTagCache(filters?: Partial, options?: unknown): Promise + public abstract updateMany(entityClass: new () => T, entities: T[], filter: FilterQuery): Promise; /** - * Delete tag - * @param tag + * Overriding the remove method + * @param entityClass + * @param entities */ - public abstract removeTag(tag: Tag): Promise + public abstract remove(entityClass: new () => T, entities: T | T[]): Promise; /** - * Update tag - * @param tag + * Overriding the count method + * @param entityClass + * @param filters + * @param options */ - public abstract updateTag(tag: Tag): Promise + public abstract count(entityClass: new () => T, filters: Partial, options?: unknown): Promise; /** - * Update tags - * @param tags + * Overriding the findAndCount method + * @param entityClass + * @param filters + * @param options */ - public abstract updateTags(tags: Tag[]): Promise + public abstract findAndCount(entityClass: new () => T, filters: Partial | unknown, options?: unknown): Promise<[T[], number]>; /** - * Get tag By UUID - * @param uuid + * Overriding the findAll method + * @param entityClass + * @param options */ - public abstract getTagById(uuid: string): Promise + public abstract findAll(entityClass: new () => T, options?: unknown): Promise; /** - * Create tag cache - * @param tag + * Find data by aggregation + * @param entityClass Entity class + * @param aggregation aggregate filter + * @returns */ - public abstract createTagCache(tag: Partial): Promise; + public abstract aggregate(entityClass: new () => T, aggregation: Partial[]): Promise; /** - * Update tag cache - * @param row + * Overriding the save method + * @param entityClass + * @param item + * @param filter */ - public abstract updateTagCache(row: TagCache): Promise + public abstract save(entityClass: new () => T, item: unknown | unknown[], filter?: Partial): Promise /** - * Get VP mint information - * @param vpDocument VP - * @returns Serials and amount + * Save many + * @param entityClass + * @param item + * @param filter */ - public abstract getVPMintInformation( - vpDocument: VpDocument - ): Promise< - [ - serials: { serial: number; tokenId: string }[], - amount: number, - error: string, - wasTransferNeeded: boolean, - transferSerials: number[], - transferAmount: number, - tokenIds: string[], - target: string, - ] - > + public abstract saveMany(entityClass: new () => T, item: unknown[], filter?: Partial): Promise /** - * Set MultiSign Status by user + * Save Block State + * @param policyId * @param uuid - * @param documentId - * @param user - * @param status - * @param document + * @param state * * @virtual */ - public abstract setMultiSigDocument( - uuid: string, - documentId: string, - user: { id: string, did: string, group: string, username: string }, - status: string, - document: IVC - ): Promise + public abstract saveBlockState(policyId: string, uuid: string, state: unknown): Promise; /** - * Get Active External Topic + * Get Block State * @param policyId - * @param blockId + * @param uuid * * @virtual */ - public abstract getActiveExternalTopics( - policyId: string, - blockId: string - ): Promise + public abstract getBlockState(policyId: string, uuid: string): Promise; /** - * Create External Topic - * @param row + * Get block states + * @param policyId Policy identifier + * @returns Block states + */ + public abstract getBlockStates(policyId: string): Promise; + + /** + * Get Virtual User + * @param did * * @virtual */ - public abstract createExternalTopic(row: unknown): Promise + public abstract getVirtualUser(did: string): Promise; /** - * Update External Topic - * @param item + * Get Key from Virtual User + * @param did + * @param keyName * * @virtual */ - public abstract updateExternalTopic(item: ExternalDocument): Promise + public abstract getVirtualKey(did: string, keyName: string): Promise; /** - * get document aggregation filters for analytics - * @param nameFilterMap - * @param nameFilterAttributes - * @param existingAttributes - * - * @returns Result + * Get virtual keys + * @param filters Filters + * @returns Virtual keys */ - public abstract getAttributesAggregationFilters(nameFilterMap: string, nameFilterAttributes: string, existingAttributes: string[] | []): unknown[] + public abstract getVirtualKeys(filters: Partial): Promise; /** - * get tasks aggregation filters - * @param nameFilter - * @param processTimeout + * Set Key from Virtual User + * @param did + * @param keyName + * @param key * - * @returns Result + * @virtual */ - public abstract getTasksAggregationFilters(nameFilter: string, processTimeout: number): unknown[] + public abstract setVirtualKey(did: string, keyName: string, key: string): Promise; /** - * get document aggregation filters - * @param props + * Get Virtual Hedera Account + * @param hederaAccountId * - * @returns Result + * @virtual */ - public abstract getDocumentAggregationFilters(props: IGetDocumentAggregationFilters): void + public abstract getVirtualHederaAccountInfo(hederaAccountId: string): Promise; /** - * get document aggregation filters for analytics - * @param nameFilter - * @param uuid + * Virtual Associate Token + * @param hederaAccountId + * @param token * - * @returns Result + * @virtual */ - public abstract getAnalyticsDocAggregationFilters(nameFilter: string, uuid: string): unknown[] + public abstract virtualAssociate(hederaAccountId: string, token: TokenCollection): Promise; /** - * Update policy - * @param policyId - * @param data + * Virtual Dissociate Token + * @param hederaAccountId + * @param tokenId + * + * @virtual */ - public static async updatePolicyConfig(policyId: string, data: Policy): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updatePolicyConfig.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract virtualDissociate(hederaAccountId: string, tokenId: string): Promise; /** - * Create Virtual User - * @param policyId - * @param username - * @param did + * Virtual Freeze Token * @param hederaAccountId - * @param hederaAccountKey - * @param active - * @param systemMode + * @param tokenId * * @virtual */ - public static async createVirtualUser( - policyId: string, - username: string, - did: string, - hederaAccountId: string, - hederaAccountKey: string, - active: boolean, - systemMode?: boolean - ): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createVirtualUser.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract virtualFreeze(hederaAccountId: string, tokenId: string): Promise; /** - * Create Virtual User - * @param policyId - * @param username - * @param did + * Virtual Unfreeze Token * @param hederaAccountId - * @param hederaAccountKey - * @param active + * @param tokenId * * @virtual */ - public abstract createVirtualUser(username: string, did: string, hederaAccountId: string, hederaAccountKey: string, active: boolean): Promise + public abstract virtualUnfreeze(hederaAccountId: string, tokenId: string): Promise; /** - * Save Virtual Message - * @param dryRun - * @param message + * Virtual GrantKyc Token + * @param hederaAccountId + * @param tokenId * * @virtual */ - public static async saveVirtualMessage(dryRun: string, message: Message): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveVirtualMessage.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract virtualGrantKyc(hederaAccountId: string, tokenId: string): Promise; /** - * Get Virtual Messages - * @param dryRun - * @param topicId + * Virtual RevokeKyc Token + * @param hederaAccountId + * @param tokenId * * @virtual */ - public static async getVirtualMessages(dryRun: string, topicId: string | TopicId): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVirtualMessages.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract virtualRevokeKyc(hederaAccountId: string, tokenId: string): Promise; /** - * Get Virtual Message - * @param dryRun - * @param messageId - * + * Save Block State + * @param {string} policyId - policy ID + * @param {string} blockId - block UUID + * @param {string} did - user DID + * @param {string} name - variable name + * @param {unknown} value - variable value + * @param {boolean} isLongValue - if long value * @virtual */ - public static async getVirtualMessage(dryRun: string, messageId: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getVirtualMessage.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract saveBlockCache(policyId: string, blockId: string, did: string, name: string, value: unknown, isLongValue: boolean): Promise; /** - * Get tokens - * @param filters Filters - * @returns Tokens + * Get Block State + * @param {string} policyId - policy ID + * @param {string} blockId - block UUID + * @param {string} did - user DID + * @param {string} name - variable name + * + * @returns {BlockCache | null} - variable value + * @virtual */ - public static async getTokens(filters?: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTokens.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getBlockCache(policyId: string, blockId: string, did: string, name: string): Promise; /** - * Get Token - * @param tokenId + * Save Document State + * @param row + * + * @virtual */ - public static async getToken(tokenId: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getToken.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract saveDocumentState(row: Partial): Promise; /** - * Get Token by ID - * @param id + * Create Token + * @param token + * @returns */ - public static async getTokenById(id: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTokenById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract createToken(token: unknown): Promise; /** - * Get Contract by ID - * @param id + * Update Approval VC + * @param row + * + * @virtual */ - public static async getContractById(id: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getContractById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract updateApproval(row: ApprovalDocumentCollection): Promise; /** - * Create MultiPolicyTransaction - * @param transaction + * Update VC + * @param row + * + * @virtual */ - public static async createMultiPolicyTransaction(transaction: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createMultiPolicyTransaction.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract updateVC(row: VcDocumentCollection): Promise; /** - * Get MultiPolicyTransaction - * @param policyId - * @param owner + * Update VP + * @param row + * + * @virtual */ - public static async getMultiPolicyTransactions(policyId: string, owner: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getMultiPolicyTransactions.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract updateVP(row: VpDocumentCollection): Promise; /** - * Get MultiPolicyTransaction count - * @param policyId + * Update Did + * @param row + * + * @virtual */ - public static async countMultiPolicyTransactions(policyId: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.countMultiPolicyTransactions.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract updateDid(row: DidDocumentCollection): Promise; /** - * Create createModules - * @param module + * Save Approval VC + * @param row + * + * @virtual */ - public static async createModules(module: PolicyModule): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createModules.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract saveApproval(row: Partial): Promise; /** - * Get Modules - * @param filters - * @param options + * Save VC + * @param row + * + * @virtual */ - public static async getModulesAndCount(filters?: Partial, options?: unknown): Promise<[PolicyModule[], number]> { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getModulesAndCount.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract saveVC(row: Partial): Promise; /** - * Get Module By UUID - * @param uuid + * Save VP + * @param row + * + * @virtual */ - public static async getModuleByUUID(uuid: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getModuleByUUID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract saveVP(row: Partial): Promise; /** - * Get Module - * @param filters + * Save Did + * @param row + * + * @virtual */ - public static async getModule(filters: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getModuleByUUID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract saveDid(row: Partial): Promise; /** - * Delete Module - * @param module + * Get Policy + * @param policyId + * + * @virtual */ - public static async removeModule(module: PolicyModule): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeModule.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getPolicy(policyId: string): Promise; /** - * Get Modules + * Get Aggregate Documents + * @param policyId + * @param blockId * @param filters - * @param options + * + * @virtual */ - public static async getModules(filters?: Partial, options?: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getModules.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getAggregateDocuments(policyId: string, blockId: string, filters: unknown): Promise; /** - * Update Module - * @param row + * Get aggregate document by policy identifier + * @param policyId Policy identifier + * @returns Aggregate documents */ - public static async updateModule(row: PolicyModule): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateModule.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getAggregateDocumentsByPolicy(policyId: string): Promise; /** - * Create Tool - * @param tool + * Remove Aggregate Documents + * @param removeMsp + * + * @virtual */ - public static async createTool(tool: PolicyTool): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createTool.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract removeAggregateDocuments(removeMsp: AggregateVC[]): Promise; /** - * Get Tools - * @param filters - * @param options + * Remove Aggregate Document + * @param hash + * @param blockId + * + * @virtual */ - public static async getToolsAndCount(filters?: PolicyTool, options?: unknown): Promise<[PolicyTool[], number]> { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getToolsAndCount.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract removeAggregateDocument(hash: string, blockId: string): Promise; /** - * Get Tool By UUID - * @param uuid + * Create Aggregate Documents + * @param item + * @param blockId + * + * @virtual */ - public static async getToolByUUID(uuid: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getToolByUUID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract createAggregateDocuments(item: VcDocumentCollection & {blockId: string}, blockId: string): Promise; /** - * Get Tool + * Get Vc Document * @param filters + * + * @virtual */ - public static async getTool(filters: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTool.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getVcDocument(filters: Partial): Promise; /** - * Delete Tool - * @param tool + * Get Vp Document + * @param filters + * + * @virtual */ - public static async removeTool(tool: PolicyTool): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeTool.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getVpDocument(filters: Partial): Promise; /** - * Get Tools + * Get Approval Document * @param filters - * @param options + * + * @virtual */ - public static async getTools(filters?: Partial, options?: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTools.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getApprovalDocument(filters: Partial): Promise; /** - * Update Tool - * @param row + * Get Vc Documents + * @param aggregation + * @virtual */ - public static async updateTool(row: PolicyTool): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTool.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getVcDocumentsByAggregation(aggregation: Partial[]): Promise; /** - * Create tag - * @param tag + * Get Vp Documents + * @param aggregation + * @virtual */ - public static async createTag(tag: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createTag.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getVpDocumentsByAggregation(aggregation: Partial[]): Promise; /** - * Delete tag - * @param tag + * Get Did Documents + * @param aggregation + * @virtual */ - public static async removeTag(tag: Tag): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeTag.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getDidDocumentsByAggregation(aggregation: Partial[]): Promise; /** - * Get tag By UUID - * @param uuid + * Get Approval Documents + * @param aggregation + * @virtual */ - public static async getTagById(uuid: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTagById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getApprovalDocumentsByAggregation(aggregation: Partial[]): Promise; /** - * Get tags + * Get Vc Documents * @param filters * @param options + * @param countResult + * @virtual */ - public static async getTags(filters?: Partial, options?: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTags.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } - - /** - * Update tag - * @param tag - */ - public static async updateTag(tag: Tag): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTag.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } - - /** - * Update tags - * @param tags - */ - public static async updateTags(tags: Tag[]): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTag.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getVcDocuments(filters: Partial, options?: unknown, countResult?: boolean): Promise; /** - * Create tag cache - * @param tag + * Get Vp Documents + * @param filters + * + * @param options + * @param countResult + * @virtual */ - public static async createTagCache(tag: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createTagCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getVpDocuments(filters: Partial, options?: unknown, countResult?: boolean): Promise; /** - * Get tags + * Get Did Documents * @param filters + * * @param options + * @param countResult + * @virtual */ - public static async getTagCache(filters?: Partial , options?: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTagCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getDidDocuments(filters: Partial, options?: unknown, countResult?: boolean): Promise; /** - * Update tag cache - * @param row + * Get Did Document + * @param did */ - public static async updateTagCache(row: TagCache): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTagCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getDidDocument(did: string): Promise; /** - * Update tags cache - * @param rows + * Get Approval Documents + * @param filters + * @param options + * @param countResult + * @virtual */ - public static async updateTagsCache(rows: TagCache[]): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTagsCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getApprovalDocuments(filters: Partial, options?: unknown, countResult?: boolean): Promise; /** - * Create Theme - * @param theme + * Get Document States + * @param filters + * @param options + * + * @virtual */ - public static async createTheme(theme: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createTheme.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getDocumentStates(filters: Partial, options?: unknown): Promise; /** - * Get Theme + * Get Topic * @param filters + * + * @virtual */ - public static async getTheme(filters: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getTheme.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getTopic( + filters: { + /** + * policyId + */ + policyId?: string, + /** + * type + */ + type?: TopicType, + /** + * name + */ + name?: string, + /** + * owner + */ + owner?: string, + /** + * topicId + */ + topicId?: string + }): Promise; /** - * Get Themes + * Get Topics * @param filters + * + * @virtual */ - public static async getThemes(filters: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getThemes.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getTopics( + filters: { + /** + * policyId + */ + policyId?: string, + /** + * type + */ + type?: TopicType, + /** + * name + */ + name?: string, + /** + * owner + */ + owner?: string, + /** + * topicId + */ + topicId?: string + }): Promise; /** - * Delete Theme - * @param theme + * Get topic by id + * @param topicId */ - public static async removeTheme(theme: Theme): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeTheme.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getTopicById(topicId: string): Promise; /** - * Update Theme - * @param row + * Get Token + * @param tokenId + * @param dryRun */ - public static async updateTheme(row: Theme): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateTheme.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getToken(tokenId: string, dryRun?: string): Promise; /** - * Save suggestions config - * @param config - * @returns config + * Save Topic + * @param topic + * + * @virtual */ - public static async setSuggestionsConfig(config: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.setSuggestionsConfig.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract saveTopic(topic: TopicCollection): Promise; /** - * Get suggestions config - * @param did - * @returns config + * Get schema + * @param iri + * @param topicId */ - public static async getSuggestionsConfig(did: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.setSuggestionsConfig.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getSchemaByIRI(iri: string, topicId?: string): Promise; /** - * Get retire pools - * @param tokenIds Token identifiers - * @returns Retire pools + * Get schema + * @param topicId + * @param entity */ - public static async getRetirePools(tokenIds: string[]): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getRetirePools.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getSchemaByType(topicId: string, entity: SchemaEntity): Promise; /** - * Save Artifact - * @param artifact Artifact - * @returns Saved Artifact + * Set user in group + * + * @param group + * + * @virtual */ - public static async saveArtifact(artifact: ArtifactCollection): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveArtifact.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract setUserInGroup(group: unknown): Promise; /** - * Save Artifacts - * @param artifacts Artifacts - * @returns Saved Artifacts + * Set Active Group + * + * @param policyId + * @param did + * @param uuid + * + * @virtual */ - public static async saveArtifacts(artifacts: ArtifactCollection[]): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveArtifact.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract setActiveGroup(policyId: string, did: string, uuid: string): Promise; /** - * Get Artifact - * @param filters Filters - * @returns Artifact + * Get Group By UUID + * @param policyId + * @param uuid + * + * @virtual */ - public static async getArtifact(filters?: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getArtifact.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getGroupByID(policyId: string, uuid: string): Promise; /** - * Get Artifacts - * @param filters Filters - * @param options Options - * @returns Artifacts + * Get Group By Name + * @param policyId + * @param groupName + * + * @virtual */ - public static async getArtifacts(filters?: Partial, options?: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getArtifacts.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getGlobalGroup(policyId: string, groupName: string): Promise; /** - * Get Artifacts - * @param filters Filters - * @param options Options - * @returns Artifacts + * Get User In Group + * @param policyId + * @param did + * @param uuid + * + * @virtual */ - public static async getArtifactsAndCount(filters?: Partial, options?: unknown): Promise<[ArtifactCollection[], number]> { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getArtifactsAndCount.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getUserInGroup(policyId: string, did: string, uuid: string): Promise; /** - * Remove Artifact - * @param artifact Artifact + * Check User In Group + * @param group + * + * @virtual */ - public static async removeArtifact(artifact?: ArtifactCollection): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeArtifact.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract checkUserInGroup(group: {policyId: string, did: string, owner: string, uuid: string}): Promise; /** - * Save Artifact File - * @param uuid File UUID - * @param data Data + * Get Groups By User + * @param policyId + * @param did + * @param options + * + * @virtual */ - public static async saveArtifactFile(uuid: string, data: Buffer): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveArtifactFile.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getGroupsByUser(policyId: string, did: string, options?: unknown): Promise; /** - * Get Artifact File By UUID - * @param uuid File UUID - * @returns Buffer + * Get Active Group By User + * @param policyId + * @param did + * + * @virtual */ - public static async getArtifactFileByUUID(uuid: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getArtifactFileByUUID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getActiveGroupByUser(policyId: string, did: string): Promise; /** - * Get Multi Policy link - * @param instanceTopicId - * @param owner - * @returns MultiPolicy + * Get members + * + * @param group + * + * @virtual */ - public static async getMultiPolicy(instanceTopicId: string, owner: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getArtifactFileByUUID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getAllMembersByGroup(group: PolicyRolesCollection): Promise; /** - * Create Multi Policy object - * @param multiPolicy - * @returns MultiPolicy + * Get all policy users + * @param policyId + * + * @virtual */ - public static createMultiPolicy(multiPolicy: MultiPolicy): MultiPolicy { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createMultiPolicy.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getAllPolicyUsers(policyId: string): Promise; /** - * Save Multi Policy object - * @param multiPolicy - * @returns multiPolicy + * Get all policy users + * @param policyId + * @param uuid + * @param role + * + * @virtual */ - public static async saveMultiPolicy(multiPolicy: MultiPolicy): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveMultiPolicy.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getAllUsersByRole(policyId: string, uuid: string, role: string): Promise; /** - * Get Module By ID - * @param id + * Get all policy users by role + * @param policyId + * @param role + * + * @virtual */ - public static async getModuleById(id: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getModuleById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getUsersByRole(policyId: string, role: string): Promise; /** - * Get Tool By ID - * @param id + * Get user roles + * @param policyId + * @param did + * @returns + * + * @virtual */ - public static async getToolById(id: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getToolById.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getUserRoles(policyId: string, did: string): Promise; /** - * Save mint transaction - * @param transaction Transaction - * @returns Saved transaction + * Delete user + * @param group + * + * @virtual */ - public abstract saveMintTransaction(transaction: Partial): Promise + public abstract deleteGroup(group: PolicyRolesCollection): Promise; /** - * Get mint transactions - * @param filters Filters - * @param options Options - * @returns Mint transactions + * Create invite token + * @param policyId + * @param uuid + * @param owner + * @param role + * + * @virtual */ - public abstract getMintTransactions(filters: Partial, options?: unknown): Promise + public abstract createInviteToken(policyId: string, uuid: string, owner: string, role: string): Promise; /** - * Get mint transactions - * @param filters Filters - * @returns Mint transaction + * Parse invite token + * @param policyId + * @param invitationId + * + * @virtual */ - public abstract getMintTransaction(filters: Partial): Promise + public abstract parseInviteToken(policyId: string, invitationId: string): Promise; /** - * Get transactions serials count - * @param mintRequestId Mint request identifier - * @param transferStatus Transfer status + * Get MultiSign Status by document or user + * @param uuid + * @param documentId + * @param userId * - * @returns Serials count + * @virtual */ - public abstract getTransactionsSerialsCount(mintRequestId: string, transferStatus?: MintTransactionStatus | unknown): Promise + public abstract getMultiSignStatus(uuid: string, documentId: string, userId: string): Promise; /** - * Update MultiPolicyTransaction - * @param item + * Get MultiSign Statuses + * @param uuid + * @param documentId + * @param group + * + * @virtual */ - public static async updateMultiPolicyTransactions(item: MultiPolicyTransaction): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateMultiPolicyTransactions.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getMultiSignDocuments(uuid: string, documentId: string, group: string): Promise /** - * Update schema - * @param id - * @param item + * Get multi sign documents by document identifiers + * @param documentIds Document identifiers + * @returns Multi sign documents */ - public static async updateSchema(id: string, item: SchemaCollection): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateSchema.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getMultiSignDocumentsByDocumentIds(documentIds: string[]): Promise /** - * Update schemas - * @param items Schemas + * Get MultiSign Statuses by group + * @param uuid + * @param group + * + * @virtual */ - public static async updateSchemas(items: SchemaCollection[]): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateSchemas.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getMultiSignDocumentsByGroup(uuid: string, group: string): Promise /** - * Get transactions count - * @param filters Mint request identifier - * @returns Transactions count + * Set MultiSign Status by document + * @param uuid + * @param documentId + * @param group + * @param status + * + * @virtual */ - public abstract getTransactionsCount(filters: Partial): Promise + public abstract setMultiSigStatus(uuid: string, documentId: string, group: string, status: string): Promise /** - * Get mint request minted serials - * @param mintRequestId Mint request identifier - * @returns Serials + * Save mint request + * @param data Mint request + * @returns Saved mint request */ - public abstract getMintRequestSerials(mintRequestId: string): Promise + public abstract saveMintRequest(data: Partial): Promise; /** - * Get transactions serials - * @param mintRequestId Mint request identifier - * @param transferStatus Transfer status - * - * @returns Serials + * Create Residue object + * @param policyId + * @param blockId + * @param userId + * @param value + * @param document */ - public abstract getTransactionsSerials(mintRequestId: string, transferStatus?: MintTransactionStatus | unknown): Promise + public abstract createResidue( + policyId: string, + blockId: string, + userId: string, + value: unknown, + document: unknown + ): SplitDocuments; /** - * Get policy caches - * @param filters Filters - * @returns Policy caches + * Get Residue objects + * @param policyId + * @param blockId + * @param userId */ - public static async getPolicyCaches(filters?: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyCaches.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getResidue(policyId: string, blockId: string, userId: string): Promise; /** - * Save policy cache - * @param entity Entity - * @returns Policy cache + * Get External Topic + * @param policyId + * @param blockId + * @param userId + * + * @virtual */ - public static async savePolicyCache(entity: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.savePolicyCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getExternalTopic(policyId: string, blockId: string, userId: string): Promise /** - * Get policy cache - * @param filters Filters - * @returns Policy cache + * Get split documents in policy + * @param policyId Policy identifier + * @returns Split documents */ - public static async getPolicyCache(filters: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.savePolicyCache.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getSplitDocumentsByPolicy(policyId: string): Promise /** - * Get policy cache data - * @param filters Filters - * @param options Options - * @returns Policy cache data + * Set Residue objects + * @param residue */ - public static async getPolicyCacheData(filters?: Partial, options?: PolicyCacheData): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyCacheData.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract setResidue(residue: SplitDocuments[]): Promise /** - * Save policy cache data - * @param entity Policy cache data - * @returns Policy cache data + * Remove Residue objects + * @param residue */ - public static async savePolicyCacheData(entity: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.savePolicyCacheData.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract removeResidue(residue: SplitDocuments[]): Promise; /** - * Get and count policy cache data - * @param filters Filters - * @param options Options - * @returns Policy cache data and count + * Create tag + * @param tag */ - public static async getAndCountPolicyCacheData(filters?: Partial, options?: unknown): Promise<[PolicyCacheData[], number]> { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getAndCountPolicyCacheData.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract createTag(tag: Tag): Promise; /** - * Clear policy caches - * @param filters Filters + * Get tags + * @param filters + * @param options */ - public static async clearPolicyCaches(filters?: Partial | string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.clearPolicyCaches.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getTags(filters?: Partial, options?: unknown): Promise /** - * Clear policy cache data - * @param cachePolicyId Cache policy id + * Get tags + * @param filters + * @param options */ - public static async clearPolicyCacheData(cachePolicyId: string) { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.clearPolicyCacheData.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getTagCache(filters?: Partial, options?: unknown): Promise /** - * Create mint transactions - * @param transaction Transaction - * @param amount Amount + * Delete tag + * @param tag */ - public abstract createMintTransactions(transaction: Partial, amount: number): Promise + public abstract removeTag(tag: Tag): Promise /** - * Get mint request transfer serials - * @param mintRequestId Mint request identifier - * @returns Serials + * Update tag + * @param tag */ - public abstract getMintRequestTransferSerials(mintRequestId: string): Promise + public abstract updateTag(tag: Tag): Promise /** - * Update VP Documents - * @param value - * @param filters - * @param dryRun + * Update tags + * @param tags */ - public static async updateVpDocuments(value: unknown, filters: Partial, dryRun?: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updateVpDocuments.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract updateTags(tags: Tag[]): Promise /** - * Create Record - * @param record + * Get tag By UUID + * @param uuid */ - public static async createRecord(record: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createRecord.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getTagById(uuid: string): Promise /** - * Get Record - * @param filters Filters - * @param options Options - * @returns Record + * Create tag cache + * @param tag */ - public static async getRecord(filters?: Partial, options?: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getRecord.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract createTagCache(tag: Partial): Promise; /** - * Get Group By UUID - * @param policyId - * @param uuid - * - * @returns Group + * Update tag cache + * @param row */ - public static async getGroupByID(policyId: string, uuid: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getGroupByID.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract updateTagCache(row: TagCache): Promise /** - * Get Groups By User - * @param policyId - * @param did - * @param options - * - * @returns Groups + * Get VP mint information + * @param vpDocument VP + * @returns Serials and amount */ - public static async getGroupsByUser(policyId: string, did: string, options?: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getGroupsByUser.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getVPMintInformation( + vpDocument: VpDocument + ): Promise< + [ + serials: {serial: number; tokenId: string}[], + amount: number, + error: string, + wasTransferNeeded: boolean, + transferSerials: number[], + transferAmount: number, + tokenIds: string[], + target: string, + ] + > /** - * Save VCs - * @param data + * Set MultiSign Status by user + * @param uuid + * @param documentId + * @param user + * @param status + * @param document * - * @returns VCs + * @virtual */ - // tslint:disable-next-line:adjacent-overload-signatures - public static async saveVCs(data: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveVCs.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract setMultiSigDocument( + uuid: string, + documentId: string, + user: {id: string, did: string, group: string, username: string}, + status: string, + document: IVC + ): Promise /** - * Save VPs - * @param data + * Get Active External Topic + * @param policyId + * @param blockId * - * @returns VPs + * @virtual */ - public static async saveVPs(data: Partial): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveVPs.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getActiveExternalTopics( + policyId: string, + blockId: string + ): Promise /** - * Get Did Document - * @param did + * Create External Topic + * @param row + * + * @virtual */ - public static async getDidDocument(did: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getDidDocument.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract createExternalTopic(row: unknown): Promise /** - * Assign entity - * @param type - * @param entityId - * @param assigned - * @param did - * @param owner + * Update External Topic + * @param item + * + * @virtual */ - public static async assignEntity(type: AssignedEntityType, entityId: string, assigned: boolean, did: string, owner: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.assignEntity.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract updateExternalTopic(item: ExternalDocument): Promise /** - * Check entity - * @param type - * @param entityId - * @param did + * get document aggregation filters for analytics + * @param nameFilterMap + * @param nameFilterAttributes + * @param existingAttributes + * + * @returns Result */ - public static async getAssignedEntity(type: AssignedEntityType, entityId: string, did: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getAssignedEntity.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getAttributesAggregationFilters(nameFilterMap: string, nameFilterAttributes: string, existingAttributes: string[] | []): unknown[] /** - * Get assigned entities - * @param did - * @param type + * get tasks aggregation filters + * @param nameFilter + * @param processTimeout + * + * @returns Result */ - public static async getAssignedEntities(did: string, type?: AssignedEntityType): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getAssignedEntities.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getTasksAggregationFilters(nameFilter: string, processTimeout: number): unknown[] /** - * Remove assign entity - * @param type - * @param entityId - * @param did - * @param owner + * get document aggregation filters + * @param props + * + * @returns Result */ - public static async removeAssignEntity(type: AssignedEntityType, entityId: string, did: string, owner?: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removeAssignEntity.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getDocumentAggregationFilters(props: IGetDocumentAggregationFilters): void /** - * Save file + * get document aggregation filters for analytics + * @param nameFilter * @param uuid - * @param buffer * - * @returns file ID + * @returns Result */ - public static async saveFile(uuid: string, buffer: Buffer): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.saveFile.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getAnalyticsDocAggregationFilters(nameFilter: string, uuid: string): unknown[] /** - * Load file - * @param id + * Create Virtual User + * @param policyId + * @param username + * @param did + * @param hederaAccountId + * @param hederaAccountKey + * @param active * - * @returns file ID + * @virtual */ - public static async loadFile(id: unknown): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.loadFile.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract createVirtualUser(username: string, did: string, hederaAccountId: string, hederaAccountKey: string, active: boolean): Promise /** - * Get policy tests - * @param policyId - * @returns tests + * Save mint transaction + * @param transaction Transaction + * @returns Saved transaction */ - public static async getPolicyTests(policyId: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyTests.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract saveMintTransaction(transaction: Partial): Promise /** - * Assign entity - * @param config - * @param buffer + * Get mint transactions + * @param filters Filters + * @param options Options + * @returns Mint transactions */ - public static async createPolicyTest(config: { [key: string]: unknown }, buffer: Buffer): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.createPolicyTest.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getMintTransactions(filters: Partial, options?: unknown): Promise /** - * Get policy test - * @param policyId - * @param id - * @returns tests + * Get mint transactions + * @param filters Filters + * @returns Mint transaction */ - public static async getPolicyTest(policyId: string, id: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyTest.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getMintTransaction(filters: Partial): Promise /** - * Get policy test - * @param policyId - * @param status - * @returns tests + * Get transactions serials count + * @param mintRequestId Mint request identifier + * @param transferStatus Transfer status + * + * @returns Serials count */ - public static async getPolicyTestsByStatus(policyId: string, status: PolicyTestStatus): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyTestsByStatus.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getTransactionsSerialsCount(mintRequestId: string, transferStatus?: MintTransactionStatus | unknown): Promise /** - * Get policy tests - * @param resultId - * - * @returns tests + * Get transactions count + * @param filters Mint request identifier + * @returns Transactions count */ - public static async getPolicyTestByRecord(resultId: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.getPolicyTestByRecord.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getTransactionsCount(filters: Partial): Promise /** - * Get policy tests - * @param policyId - * @param id - * @returns tests + * Get mint request minted serials + * @param mintRequestId Mint request identifier + * @returns Serials */ - public static async deletePolicyTest(policyId: string, id: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.deletePolicyTest.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getMintRequestSerials(mintRequestId: string): Promise /** - * Get policy tests - * @param test + * Get transactions serials + * @param mintRequestId Mint request identifier + * @param transferStatus Transfer status * - * @returns tests + * @returns Serials */ - public static async updatePolicyTest(test: PolicyTest): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.updatePolicyTest.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getTransactionsSerials(mintRequestId: string, transferStatus?: MintTransactionStatus | unknown): Promise /** - * Get policy tests - * @param policyId - * - * @returns tests + * Create mint transactions + * @param transaction Transaction + * @param amount Amount */ - public static async deletePolicyTests(policyId: string): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.deletePolicyTests.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract createMintTransactions(transaction: Partial, amount: number): Promise /** - * Get policy tests - * @returns tests + * Get mint request transfer serials + * @param mintRequestId Mint request identifier + * @returns Serials */ - public static async removePolicyTests(tests: PolicyTest[]): Promise { - throw new Error(`${AbstractDatabaseServer.name}.${AbstractDatabaseServer.removePolicyTests.name}: ${STATUS_IMPLEMENTATION.METHOD_IS_NOT_IMPLEMENTED}`); - } + public abstract getMintRequestTransferSerials(mintRequestId: string): Promise /** * Overriding the create method diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 0f248e55a6..ebb29ac8dd 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -34,6 +34,7 @@ "js-yaml": "^4.1.0", "leader-line": "^1.0.7", "mathjs": "^13.1.1", + "mathlive": "^0.103.0", "moment": "^2.29.2", "moment-timezone": "^0.5.43", "ngx-colors": "3.1.4", @@ -83,7 +84,7 @@ "devDependencies": { "@types/gulp": "^4", "@types/gulp-rename": "^2", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "mocha-junit-reporter": "^2.0.2", "tslint": "^6.1.3", "typescript": "^4.5.5" @@ -3456,6 +3457,20 @@ "node": ">=0.1.90" } }, + "node_modules/@cortex-js/compute-engine": { + "version": "0.24.1", + "resolved": "https://registry.npmjs.org/@cortex-js/compute-engine/-/compute-engine-0.24.1.tgz", + "integrity": "sha512-B9pLaZFC1vBrL64yR2LQWy2sj1E/+wtwIVokPuPqX8YWXwj9W2AMVyS9pSMN8gEdjpAC50nSmtL6110Rgi7dKA==", + "license": "MIT", + "dependencies": { + "complex.js": "^2.1.1", + "decimal.js": "^10.4.3" + }, + "engines": { + "node": ">=16.14.2", + "npm": ">=8.5.0" + } + }, "node_modules/@ctrl/ngx-codemirror": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/@ctrl/ngx-codemirror/-/ngx-codemirror-5.1.1.tgz", @@ -10228,6 +10243,23 @@ "node": ">=6.9.0" } }, + "node_modules/mathlive": { + "version": "0.103.0", + "resolved": "https://registry.npmjs.org/mathlive/-/mathlive-0.103.0.tgz", + "integrity": "sha512-gNJDMUOz0WePyDpLO/w1sGkrz0JrMwrT1QoFdGloVjjerWlUeKWn1JGM6XlO5SQ1AqXWemRKvlyVXft+QsxX8w==", + "license": "MIT", + "dependencies": { + "@cortex-js/compute-engine": "0.24.1" + }, + "engines": { + "node": ">=16.14.2", + "npm": ">=8.5.0" + }, + "funding": { + "type": "individual", + "url": "https://paypal.me/arnogourdol" + } + }, "node_modules/md5.js": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", diff --git a/frontend/src/app/modules/policy-engine/policy-viewer/policy-viewer/policy-viewer.component.html b/frontend/src/app/modules/policy-engine/policy-viewer/policy-viewer/policy-viewer.component.html index e5da0f8b75..62dde94640 100644 --- a/frontend/src/app/modules/policy-engine/policy-viewer/policy-viewer/policy-viewer.component.html +++ b/frontend/src/app/modules/policy-engine/policy-viewer/policy-viewer/policy-viewer.component.html @@ -46,7 +46,7 @@ -
+
Restore
diff --git a/frontend/src/app/modules/policy-engine/policy-viewer/policy-viewer/policy-viewer.component.ts b/frontend/src/app/modules/policy-engine/policy-viewer/policy-viewer/policy-viewer.component.ts index dbc914c563..ceaa0387dd 100644 --- a/frontend/src/app/modules/policy-engine/policy-viewer/policy-viewer/policy-viewer.component.ts +++ b/frontend/src/app/modules/policy-engine/policy-viewer/policy-viewer/policy-viewer.component.ts @@ -24,6 +24,7 @@ import { IStep } from '../../structures'; }) export class PolicyViewerComponent implements OnInit, OnDestroy { private subscription = new Subscription(); + public savePointState: boolean = false; public policyId!: string; public policy: any | null; public policyInfo: any | null; @@ -107,6 +108,15 @@ export class PolicyViewerComponent implements OnInit, OnDestroy { return document; } + private getSavepointState() { + this.policyEngineService.getSavepointState(this.policyInfo.id).subscribe((value) => { + this.savePointState = value.state; + console.log(value); + }, (e) => { + this.savePointState = false; + }); + } + ngOnInit() { this.loading = true; this.subscription.add( @@ -207,6 +217,7 @@ export class PolicyViewerComponent implements OnInit, OnDestroy { } }) }) + this.getSavepointState(); }, (e) => { this.loading = false; }); @@ -289,7 +300,8 @@ export class PolicyViewerComponent implements OnInit, OnDestroy { public createSavepoint() { this.loading = true; this.policyEngineService.createSavepoint(this.policyInfo.id).subscribe(() => { - this.loadPolicyById(this.policyId); + this.loadPolicyById(this.policyId); + this.getSavepointState(); }, (e) => { this.loading = false; } diff --git a/frontend/src/app/services/policy-engine.service.ts b/frontend/src/app/services/policy-engine.service.ts index 0635089997..afb57bc72f 100644 --- a/frontend/src/app/services/policy-engine.service.ts +++ b/frontend/src/app/services/policy-engine.service.ts @@ -237,6 +237,10 @@ export class PolicyEngineService { return this.http.post(`${this.url}/${policyId}/savepoint/restore`, null); } + public getSavepointState(policyId: string): Observable { + return this.http.get(`${this.url}/${policyId}/savepoint/restore`); + } + public loadDocuments( policyId: string, documentType: string, diff --git a/guardian-cli/package.json b/guardian-cli/package.json index cc43a47e93..4a754622b6 100644 --- a/guardian-cli/package.json +++ b/guardian-cli/package.json @@ -17,11 +17,11 @@ "author": "IntellectEU ", "license": "Apache-2.0", "devDependencies": { - "@types/node": "^18.15.3", + "@types/node": "^22.10.10", "typescript": "^5.0.2" }, "dependencies": { - "@hashgraph/sdk": "^2.46.0", + "@hashgraph/sdk": "^2.52.0", "axios": "^1.6.7", "commander": "^10.0.0", "solc": "0.8.11", diff --git a/guardian-service/package.json b/guardian-service/package.json index 1301db527a..7293fd2f7c 100644 --- a/guardian-service/package.json +++ b/guardian-service/package.json @@ -65,7 +65,7 @@ "@types/gulp": "^4", "@types/gulp-rename": "^2", "@types/jszip": "^3.4.1", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "chai": "4.3.4", "gulp": "^4.0.2", "gulp-copy": "^4.0.1", diff --git a/guardian-service/src/policy-engine/policy-engine.service.ts b/guardian-service/src/policy-engine/policy-engine.service.ts index 852b6d23fd..a17a82b9ed 100644 --- a/guardian-service/src/policy-engine/policy-engine.service.ts +++ b/guardian-service/src/policy-engine/policy-engine.service.ts @@ -1723,6 +1723,32 @@ export class PolicyEngineService { } }); + this.channel.getMessages(PolicyEngineEvents.GET_SAVEPOINT, + async (msg: {policyId: string, owner: IOwner}) => { + try { + const {policyId, owner} = msg; + const policy = await DatabaseServer.getPolicyById(policyId); + await this.policyEngine.accessPolicy(policy, owner, 'read'); + if (!policy.config) { + throw new Error('The policy is empty'); + } + if (!PolicyHelper.isDryRunMode(policy)) { + throw new Error(`Policy is not in Dry Run`); + } + + const state = await DatabaseServer.getSavepointSate(policyId); + // const users = await DatabaseServer.getVirtualUsers(policyId); + // await DatabaseServer.setVirtualUser(policyId, users[0]?.did); + // const filters = await this.policyEngine.addAccessFilters({}, owner); + // const policies = (await DatabaseServer.getListOfPolicies(filters)); + console.log('Restore savepoint'); + return new MessageResponse({state}); + } catch (error) { + await logger.error(error, ['GUARDIAN_SERVICE']); + return new MessageError(error); + } + }); + this.channel.getMessages(PolicyEngineEvents.GET_VIRTUAL_DOCUMENTS, async (msg: { policyId: string, diff --git a/indexer-api-gateway/package.json b/indexer-api-gateway/package.json index a86eb173c0..8117a336de 100644 --- a/indexer-api-gateway/package.json +++ b/indexer-api-gateway/package.json @@ -54,7 +54,7 @@ "@types/gulp": "^4", "@types/gulp-rename": "^2", "@types/jszip": "^3.4.1", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "@types/ws": "^8.2.2", "chai": "^4.3.4", "cross-env": "^7.0.3", diff --git a/indexer-common/package.json b/indexer-common/package.json index 4f792956e8..3dd7490388 100644 --- a/indexer-common/package.json +++ b/indexer-common/package.json @@ -20,7 +20,7 @@ "@types/gulp": "^4", "@types/gulp-rename": "^2", "@types/jszip": "^3.4.1", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "mocha-junit-reporter": "^2.0.2", "tslint": "^6.1.3", "typescript": "^4.5.5" diff --git a/indexer-frontend/src/app/components/header/header.component.html b/indexer-frontend/src/app/components/header/header.component.html index 1288d17b73..4564db25ce 100644 --- a/indexer-frontend/src/app/components/header/header.component.html +++ b/indexer-frontend/src/app/components/header/header.component.html @@ -116,7 +116,7 @@
-
+
diff --git a/indexer-frontend/src/app/components/header/header.component.scss b/indexer-frontend/src/app/components/header/header.component.scss index 9c792f8617..3d70499c3c 100644 --- a/indexer-frontend/src/app/components/header/header.component.scss +++ b/indexer-frontend/src/app/components/header/header.component.scss @@ -128,7 +128,7 @@ text-align: right; } -.progress-bar { +.header-progress-bar { position: absolute; display: flex; justify-content: center; @@ -137,5 +137,6 @@ align-items: center; margin: auto; background-color: var(--color-primary, #4169E2); + border-radius: 0; z-index: 999; } \ No newline at end of file diff --git a/indexer-interfaces/package.json b/indexer-interfaces/package.json index 05766c720d..4f29fc2180 100644 --- a/indexer-interfaces/package.json +++ b/indexer-interfaces/package.json @@ -3,7 +3,7 @@ "dependencies": {}, "description": "Indexer interfaces", "devDependencies": { - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "tslint": "^6.1.3", "typescript": "^4.5.5" }, diff --git a/indexer-service/package.json b/indexer-service/package.json index a7fc1c5d19..97b8f2322f 100644 --- a/indexer-service/package.json +++ b/indexer-service/package.json @@ -28,7 +28,7 @@ "devDependencies": { "@types/gulp": "^4", "@types/gulp-rename": "^2", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "chai": "4.3.4", "gulp": "^4.0.2", "gulp-copy": "^4.0.1", diff --git a/indexer-worker-service/package.json b/indexer-worker-service/package.json index a0ce767af2..69acf393ff 100644 --- a/indexer-worker-service/package.json +++ b/indexer-worker-service/package.json @@ -23,7 +23,7 @@ "devDependencies": { "@types/gulp": "^4", "@types/gulp-rename": "^2", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "chai": "4.3.4", "gulp": "^4.0.2", "gulp-copy": "^4.0.1", diff --git a/interfaces/package.json b/interfaces/package.json index d45c380a40..9c9deec920 100644 --- a/interfaces/package.json +++ b/interfaces/package.json @@ -12,7 +12,7 @@ "devDependencies": { "@types/gulp": "^4", "@types/gulp-rename": "^2", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "mocha-junit-reporter": "^2.0.2", "tslint": "^6.1.3", "typescript": "^4.5.5" diff --git a/interfaces/src/type/messages/policy-engine-events.ts b/interfaces/src/type/messages/policy-engine-events.ts index 4becd3a250..45c13278a4 100644 --- a/interfaces/src/type/messages/policy-engine-events.ts +++ b/interfaces/src/type/messages/policy-engine-events.ts @@ -72,4 +72,5 @@ export enum PolicyEngineEvents { CREATE_SAVEPOINT = 'policy-engine-event-create-savepoint', DELETE_SAVEPOINT = 'policy-engine-event-delete-savepoint', RESTORE_SAVEPOINT = 'policy-engine-event-restore-savepoint', + GET_SAVEPOINT = 'policy-engine-event-get-savepoint' } diff --git a/logger-service/package.json b/logger-service/package.json index 478e46123b..9e521f08eb 100644 --- a/logger-service/package.json +++ b/logger-service/package.json @@ -31,7 +31,7 @@ "@types/fs-extra": "^9.0.12", "@types/gulp": "^4", "@types/gulp-rename": "^2", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "chai": "4.3.6", "mocha": "^9.2.0", "mocha-junit-reporter": "^2.0.2", diff --git a/notification-service/package.json b/notification-service/package.json index 1f3be4b7c6..6c786b8ecb 100644 --- a/notification-service/package.json +++ b/notification-service/package.json @@ -30,7 +30,7 @@ "@types/fs-extra": "^9.0.12", "@types/gulp": "^4", "@types/gulp-rename": "^2", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "chai": "4.3.6", "mocha": "^9.2.0", "mocha-junit-reporter": "^2.0.2", diff --git a/policy-service/package.json b/policy-service/package.json index 74cdce22f1..d4b6b50a12 100644 --- a/policy-service/package.json +++ b/policy-service/package.json @@ -62,7 +62,7 @@ "@types/fs-extra": "^9.0.12", "@types/gulp": "^4", "@types/gulp-rename": "^2", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "chai": "4.3.4", "gulp": "^4.0.2", "gulp-copy": "^4.0.1", diff --git a/queue-service/package.json b/queue-service/package.json index f236959618..558d043102 100644 --- a/queue-service/package.json +++ b/queue-service/package.json @@ -32,7 +32,7 @@ "devDependencies": { "@types/gulp": "^4", "@types/gulp-rename": "^2", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "chai": "4.3.4", "concurrently": "^8.2.2", "gulp": "^4.0.2", diff --git a/swagger.yaml b/swagger.yaml index ca81b77f2b..ba7617e781 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -6601,9 +6601,9 @@ paths: /policies/{policyId}/savepoint/create: post: operationId: PolicyApi_createSavepoint - summary: Create dru-run savepoint. + summary: Create dry-run savepoint. description: >- - Create dru-run savepoint. Only users with the Standard Registry role are + Create dry-run savepoint. Only users with the Standard Registry role are allowed to make the request. parameters: - name: policyId @@ -6639,9 +6639,9 @@ paths: /policies/{policyId}/savepoint/delete: post: operationId: PolicyApi_deleteSavepoint - summary: Delete dru-run savepoint. + summary: Delete dry-run savepoint. description: >- - Delete dru-run savepoint. Only users with the Standard Registry role are + Delete dry-run savepoint. Only users with the Standard Registry role are allowed to make the request. parameters: - name: policyId @@ -6675,11 +6675,48 @@ paths: security: - bearer: [] /policies/{policyId}/savepoint/restore: + get: + operationId: PolicyApi_getSavepointState + summary: Get savepoint state. + description: >- + Get savepoint state. Only users with the Standard Registry role are + allowed to make the request. + parameters: + - name: policyId + required: true + in: path + description: Policy Id + example: '000000000000000000000001' + schema: + type: string + requestBody: + required: true + description: . + content: + application/json: + schema: + type: string + responses: + '200': + description: . + '401': + description: Unauthorized. + '403': + description: Forbidden. + '500': + description: Internal server error. + content: + application/json: + schema: + $ref: '#/components/schemas/InternalServerErrorDTO' + tags: *ref_11 + security: + - bearer: [] post: operationId: PolicyApi_restoreSavepoint - summary: Restore dru-run savepoint. + summary: Restore dry-run savepoint. description: >- - Restore dru-run savepoint. Only users with the Standard Registry role + Restore dry-run savepoint. Only users with the Standard Registry role are allowed to make the request. parameters: - name: policyId diff --git a/worker-service/configs/.env.worker.develop b/worker-service/configs/.env.worker.develop index 72623c6a2e..059e5d28f2 100644 --- a/worker-service/configs/.env.worker.develop +++ b/worker-service/configs/.env.worker.develop @@ -15,7 +15,7 @@ TASK_TIMEOUT="300" REFRESH_INTERVAL="60" IPFS_TIMEOUT="720" IPFS_PROVIDER="web3storage" # 'filebase', 'web3storage' or 'local' -IPFS_PUBLIC_GATEWAY='https://w3s.link/ipfs/${cid}' +IPFS_PUBLIC_GATEWAY='http://localhost:8080/ipfs/${cid}' IPFS_NODE_ADDRESS="http://localhost:5001" ANALYTICS_SERVICE="http://localhost:3021" #ANALYTICS_SERVICE_TOKEN="" # mandatory to be able to use the MGS indexer diff --git a/worker-service/package.json b/worker-service/package.json index a2a1144bca..586bc830d3 100644 --- a/worker-service/package.json +++ b/worker-service/package.json @@ -33,7 +33,7 @@ "devDependencies": { "@types/gulp": "^4", "@types/gulp-rename": "^2", - "@types/node": "^18.16.0", + "@types/node": "^22.10.10", "chai": "4.3.4", "concurrently": "^8.2.2", "gulp": "^4.0.2", diff --git a/yarn.lock b/yarn.lock index d7f233866e..b22902202a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1292,13 +1292,20 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.9.tgz#7b903b6149b0f8fa7ad564af646c4c38a77fc44b" integrity sha512-9tcKgqKbs3xGJ+NtKF2ndOBBLVwPjl1SHxPQkd36r3Dlirw3xWUeGaTbqr7uGZcTaxkVNwc+03SVP7aCdWrTlA== -"@babel/runtime@^7.15.4", "@babel/runtime@^7.18.6", "@babel/runtime@^7.21.0": +"@babel/runtime@^7.15.4", "@babel/runtime@^7.21.0": version "7.23.9" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.23.9.tgz#47791a15e4603bb5f905bc0753801cf21d6345f7" integrity sha512-0CX6F+BI2s9dkUqr08KFrAIZgNFj75rdBU/DjCyYLIaV/quFjkk6T+EJ2LkZHyZTbEV4L5p97mNkUsHl2wLFAw== dependencies: regenerator-runtime "^0.14.0" +"@babel/runtime@^7.18.6": + version "7.26.7" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.26.7.tgz#f4e7fe527cd710f8dc0618610b61b4b060c3c341" + integrity sha512-AOPI3D+a8dXnja+iwsUqGRjr1BbZIe771sXdapOtYI531gSqpi92vXivKcq2asu/DFpdl1ceFAKZyRzK2PCVcQ== + dependencies: + regenerator-runtime "^0.14.0" + "@babel/runtime@^7.25.7": version "7.26.0" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.26.0.tgz#8600c2f595f277c60815256418b85356a65173c1" @@ -1583,10 +1590,10 @@ resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.0.tgz#0709e9f4cb252351c609c6e6d8d6779a8d25edff" integrity sha512-+KpH+QxZU7O4675t3mnkQKcZZg56u+K/Ct2K+N2AZYNVK8kyeo/bI18tI8aPm3tvNNRyTWfj6s5tnGNlcbQRsA== -"@fastify/busboy@^2.1.0": - version "2.1.1" - resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d" - integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA== +"@fastify/busboy@^3.0.0": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-3.1.1.tgz#af3aea7f1e52ec916d8b5c9dcc0f09d4c060a3fc" + integrity sha512-5DGmA8FTdB2XbDeEwc/5ZXBl6UbBAyBOOLlPuBnZ/N1SwdH9Ii+cOX3tBROlDgcTXxjOYnLMVoKk9+FXAw0CJw== "@fastify/cors@8.3.0": version "8.3.0" @@ -1596,16 +1603,21 @@ fastify-plugin "^4.0.0" mnemonist "0.39.5" -"@fastify/deepmerge@^1.0.0": - version "1.3.0" - resolved "https://registry.yarnpkg.com/@fastify/deepmerge/-/deepmerge-1.3.0.tgz#8116858108f0c7d9fd460d05a7d637a13fe3239a" - integrity sha512-J8TOSBq3SoZbDhM9+R/u77hP93gz/rajSA+K2kGyijPpORPWUXHUpTaleoj+92As0S9uPRP7Oi8IqMf0u+ro6A== +"@fastify/deepmerge@^2.0.0": + version "2.0.1" + resolved "https://registry.yarnpkg.com/@fastify/deepmerge/-/deepmerge-2.0.1.tgz#68150cd7ab709b63a718aac8335561779b910032" + integrity sha512-hx+wJQr9Ph1hY/dyzY0SxqjumMyqZDlIF6oe71dpRKDHUg7dFQfjG94qqwQ274XRjmUrwKiYadex8XplNHx3CA== -"@fastify/error@^3.0.0", "@fastify/error@^3.2.0", "@fastify/error@^3.3.0": +"@fastify/error@^3.2.0", "@fastify/error@^3.3.0": version "3.4.1" resolved "https://registry.yarnpkg.com/@fastify/error/-/error-3.4.1.tgz#b14bb4cac3dd4ec614becbc643d1511331a6425c" integrity sha512-wWSvph+29GR783IhmvdwWnN4bUxTD01Vm5Xad4i7i1VuAOItLvbPAb69sb0IQ2N57yprvhNIwAP5B6xfKTmjmQ== +"@fastify/error@^4.0.0": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@fastify/error/-/error-4.0.0.tgz#7842d6161fbce78953638318be99033a0c2d5070" + integrity sha512-OO/SA8As24JtT1usTUTKgGH7uLvhfwZPwlptRi2Dp5P4KKmJI3gvsZ8MIHnNwDs4sLf/aai5LzTyl66xr7qMxA== + "@fastify/fast-json-stringify-compiler@^4.3.0": version "4.3.0" resolved "https://registry.yarnpkg.com/@fastify/fast-json-stringify-compiler/-/fast-json-stringify-compiler-4.3.0.tgz#5df89fa4d1592cbb8780f78998355feb471646d5" @@ -1638,14 +1650,14 @@ path-to-regexp "^6.1.0" reusify "^1.0.4" -"@fastify/multipart@^8.2.0": - version "8.2.0" - resolved "https://registry.yarnpkg.com/@fastify/multipart/-/multipart-8.2.0.tgz#90359b78eccd0f944cf145a2e907d167a3a6c731" - integrity sha512-OZ8nsyyoS2TV7Yeu3ZdrdDGsKUTAbfjrKC9jSxGgT2qdgek+BxpWX31ZubTrWMNZyU5xwk4ox6AvTjAbYWjrWg== +"@fastify/multipart@^8.3.1": + version "8.3.1" + resolved "https://registry.yarnpkg.com/@fastify/multipart/-/multipart-8.3.1.tgz#bd266584e026f812ab98f677e70171e0f1dd1812" + integrity sha512-pncbnG28S6MIskFSVRtzTKE9dK+GrKAJl0NbaQ/CG8ded80okWFsYKzSlP9haaLNQhNRDOoHqmGQNvgbiPVpWQ== dependencies: - "@fastify/busboy" "^2.1.0" - "@fastify/deepmerge" "^1.0.0" - "@fastify/error" "^3.0.0" + "@fastify/busboy" "^3.0.0" + "@fastify/deepmerge" "^2.0.0" + "@fastify/error" "^4.0.0" fastify-plugin "^4.0.0" secure-json-parse "^2.4.0" stream-wormhole "^1.1.0" @@ -1694,18 +1706,18 @@ streaming-iterables "^6.0.0" throttled-queue "^2.1.2" -"@formulajs/formulajs@^4.4.0": - version "4.4.1" - resolved "https://registry.yarnpkg.com/@formulajs/formulajs/-/formulajs-4.4.1.tgz#c0219d3b12dda5931a989357eb90e2a2bad8f17d" - integrity sha512-SXQl1/NT8AoJ9mxAT6h8HGJtbVrF/jvvaHiJ1J2tsrb/HODRMF7mmTDr1Jfsi9E5aqreRWSEC0FJUDiNUedvGA== +"@formulajs/formulajs@4.4.6": + version "4.4.6" + resolved "https://registry.yarnpkg.com/@formulajs/formulajs/-/formulajs-4.4.6.tgz#c488cc67f81d51b4457f6b95ea6d5ce78e654b60" + integrity sha512-9wzWxMUFNW4RF6o0xJ7KM+oyyXUWKEErvn5c9Gu/Man6cobpG8svYeAvWiWXaT+c8dDa1erUdfH3Amd8oI9xPA== dependencies: bessel "^1.0.2" jstat "^1.9.6" -"@formulajs/formulajs@^4.4.6": - version "4.4.8" - resolved "https://registry.yarnpkg.com/@formulajs/formulajs/-/formulajs-4.4.8.tgz#69475c5b00c95d2e53d4a791d24f542f74585b73" - integrity sha512-U1xG4thAqdCVCrJgjNA/I4Bn8WvhMPIGidbm9zO1jowcXEX03eDIaYReWQIRxxTRPJeSl5nTVlzxQYDn1nL10Q== +"@formulajs/formulajs@^4.4.0": + version "4.4.1" + resolved "https://registry.yarnpkg.com/@formulajs/formulajs/-/formulajs-4.4.1.tgz#c0219d3b12dda5931a989357eb90e2a2bad8f17d" + integrity sha512-SXQl1/NT8AoJ9mxAT6h8HGJtbVrF/jvvaHiJ1J2tsrb/HODRMF7mmTDr1Jfsi9E5aqreRWSEC0FJUDiNUedvGA== dependencies: bessel "^1.0.2" jstat "^1.9.6" @@ -4286,7 +4298,7 @@ dependencies: node-vault "*" -"@types/node@*", "@types/node@>=12.12.47", "@types/node@>=13.7.0", "@types/node@^20.8.0": +"@types/node@*", "@types/node@>=12.12.47", "@types/node@>=13.7.0": version "20.11.19" resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.19.tgz#b466de054e9cb5b3831bee38938de64ac7f81195" integrity sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ== @@ -4303,13 +4315,20 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.63.tgz#1788fa8da838dbb5f9ea994b834278205db6ca2b" integrity sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ== -"@types/node@^18.0.0", "@types/node@^18.11.18", "@types/node@^18.16.0": +"@types/node@^18.0.0", "@types/node@^18.11.18": version "18.19.17" resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.17.tgz#a581a9fb4b2cfdbc61f008804f4436b2d5c40354" integrity sha512-SzyGKgwPzuWp2SHhlpXKzCX0pIOfcI4V2eF37nNBJOhwlegQ83omtVQ1XxZpDE06V/d6AQvfQdPfnw0tRC//Ng== dependencies: undici-types "~5.26.4" +"@types/node@^22.10.10": + version "22.12.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.12.0.tgz#bf8af3b2af0837b5a62a368756ff2b705ae0048c" + integrity sha512-Fll2FZ1riMjNmlmJOdAyY5pUbkftXslB5DgEzlIuNaiWhXd00FhWxVC/r4yV/4wBb9JfImTu+jiSvXTkJ7F/gA== + dependencies: + undici-types "~6.20.0" + "@types/normalize-package-data@^2.4.0": version "2.4.4" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz#56e2cc26c397c038fab0e3a917a12d5c5909e901" @@ -5377,6 +5396,11 @@ base-x@^4.0.0: resolved "https://registry.yarnpkg.com/base-x/-/base-x-4.0.0.tgz#d0e3b7753450c73f8ad2389b5c018a4af7b2224a" integrity sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw== +base-x@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/base-x/-/base-x-5.0.0.tgz#6d835ceae379130e1a4cb846a70ac4746f28ea9b" + integrity sha512-sMW3VGSX1QWVFA6l8U62MLKz29rRfpTlYdCqLdpLo1/Yd4zZwSbnUaDfciIAowAqvq7YFnWq9hrhdg1KYgc1lQ== + base64-js@^1.0.2, base64-js@^1.1.2, base64-js@^1.3.0, base64-js@^1.3.1, base64-js@^1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" @@ -5721,6 +5745,13 @@ bs58@5.0.0: dependencies: base-x "^4.0.0" +bs58@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/bs58/-/bs58-6.0.0.tgz#a2cda0130558535dd281a2f8697df79caaf425d8" + integrity sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw== + dependencies: + base-x "^5.0.0" + bson@^4.0.4: version "4.7.2" resolved "https://registry.yarnpkg.com/bson/-/bson-4.7.2.tgz#320f4ad0eaf5312dd9b45dc369cc48945e2a5f2e" @@ -6353,12 +6384,7 @@ commander@^9.0.0: resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30" integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ== -complex.js@^2.1.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/complex.js/-/complex.js-2.1.1.tgz#0675dac8e464ec431fb2ab7d30f41d889fb25c31" - integrity sha512-8njCHOTtFFLtegk6zQo0kkVX1rngygb/KQI6z1qZxlFI3scluC+LVTCFbrkWjBv4vvLlbQ9t88IPMC6k95VTTg== - -complex.js@^2.2.5: +complex.js@^2.1.1, complex.js@^2.2.5: version "2.4.2" resolved "https://registry.yarnpkg.com/complex.js/-/complex.js-2.4.2.tgz#76f260a9e7e232d8ad26348484a9b128c13fcc9a" integrity sha512-qtx7HRhPGSCBtGiST4/WGHuW+zeaND/6Ld+db6PbrulIB1i2Ev/2UPiqcmpQNPSyfBKraC0EOvOKCB5dGZKt3g== @@ -6725,7 +6751,12 @@ decamelize@^4.0.0: resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-4.0.0.tgz#aa472d7bf660eb15f3494efd531cab7f2a709837" integrity sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ== -decimal.js@^10.3.1, decimal.js@^10.4.3: +decimal.js@^10.3.1: + version "10.5.0" + resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.5.0.tgz#0f371c7cf6c4898ce0afb09836db73cd82010f22" + integrity sha512-8vDa8Qxvr/+d94hSh5P3IJwI5t8/c0KsMp+g8bNw9cY2icONa5aPfvKeieW1WlG0WQYwwhJ7mjui2xtiePQSXw== + +decimal.js@^10.4.3: version "10.4.3" resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.4.3.tgz#1044092884d245d1b7f65725fa4ad4c6f781cc23" integrity sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA== @@ -13071,7 +13102,7 @@ protobufjs@^6.10.2: "@types/node" ">=13.7.0" long "^4.0.0" -protobufjs@^7.0.0, protobufjs@^7.1.2, protobufjs@^7.2.4, protobufjs@^7.2.5: +protobufjs@^7.0.0, protobufjs@^7.1.2, protobufjs@^7.2.4: version "7.3.0" resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-7.3.0.tgz#a32ec0422c039798c41a0700306a6e305b9cb32c" integrity sha512-YWD03n3shzV9ImZRX3ccbjqLxj7NokGN0V/ESiBV5xWqrommYHYiihuIyavq03pWSGqlyvYUFmfoMKd+1rPA/g== @@ -13089,6 +13120,24 @@ protobufjs@^7.0.0, protobufjs@^7.1.2, protobufjs@^7.2.4, protobufjs@^7.2.5: "@types/node" ">=13.7.0" long "^5.0.0" +protobufjs@^7.2.5: + version "7.4.0" + resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-7.4.0.tgz#7efe324ce9b3b61c82aae5de810d287bc08a248a" + integrity sha512-mRUWCc3KUU4w1jU8sGxICXH/gNS94DvI1gxqDvBzhj1JpcsimQkYiOJfwsPUykUI5ZaspFbSgmBLER8IrQ3tqw== + dependencies: + "@protobufjs/aspromise" "^1.1.2" + "@protobufjs/base64" "^1.1.2" + "@protobufjs/codegen" "^2.0.4" + "@protobufjs/eventemitter" "^1.1.0" + "@protobufjs/fetch" "^1.1.0" + "@protobufjs/float" "^1.0.2" + "@protobufjs/inquire" "^1.1.0" + "@protobufjs/path" "^1.1.2" + "@protobufjs/pool" "^1.1.0" + "@protobufjs/utf8" "^1.1.0" + "@types/node" ">=13.7.0" + long "^5.0.0" + protons-runtime@^5.5.0: version "5.5.0" resolved "https://registry.yarnpkg.com/protons-runtime/-/protons-runtime-5.5.0.tgz#ea06d9ef843aad77ea5de3e1ebafa81b58c24570" @@ -15413,6 +15462,11 @@ undici-types@~5.26.4: resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== +undici-types@~6.20.0: + version "6.20.0" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.20.0.tgz#8171bf22c1f588d1554d55bf204bc624af388433" + integrity sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg== + undici@^5.12.0: version "5.28.3" resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.3.tgz#a731e0eff2c3fcfd41c1169a869062be222d1e5b"