From d92829b15b2929775b80623515ce6937ccb72e5a Mon Sep 17 00:00:00 2001 From: Toms Date: Mon, 10 Feb 2025 16:40:27 +0200 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20add=20count=20to=20?= =?UTF-8?q?=20AssetHolders.get?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/entities/Asset/NonFungible/AssetHolders/index.ts | 1 + src/api/entities/Asset/__tests__/NonFungible/AssetHolders.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/api/entities/Asset/NonFungible/AssetHolders/index.ts b/src/api/entities/Asset/NonFungible/AssetHolders/index.ts index 43a2abdd30..5e27e8a78c 100644 --- a/src/api/entities/Asset/NonFungible/AssetHolders/index.ts +++ b/src/api/entities/Asset/NonFungible/AssetHolders/index.ts @@ -46,6 +46,7 @@ export class AssetHolders extends Namespace { return { data, + count: new BigNumber(totalCount), next, }; } diff --git a/src/api/entities/Asset/__tests__/NonFungible/AssetHolders.ts b/src/api/entities/Asset/__tests__/NonFungible/AssetHolders.ts index f0d9b07a5a..33e0283c88 100644 --- a/src/api/entities/Asset/__tests__/NonFungible/AssetHolders.ts +++ b/src/api/entities/Asset/__tests__/NonFungible/AssetHolders.ts @@ -99,6 +99,7 @@ describe('AssetHolder class', () => { }), ]), next: null, + count: new BigNumber(2), }); }); }); From 543d17efd4f6008a258c6970c4365628333f9dd6 Mon Sep 17 00:00:00 2001 From: Toms Date: Mon, 10 Feb 2025 16:40:57 +0200 Subject: [PATCH 2/4] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20indicate=20sup?= =?UTF-8?q?port=20for=20pagination?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/Context.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/base/Context.ts b/src/base/Context.ts index e266d5c1b1..2357d00dfa 100644 --- a/src/base/Context.ts +++ b/src/base/Context.ts @@ -1278,6 +1278,7 @@ export class Context { * Retrieve POLYX transactions for a given identity or list of accounts * * @note uses the middleware V2 + * @note supports pagination */ public async getPolyxTransactions(args: { identity?: string | Identity; From 53bc3298e3479ddd221ec178413bf7c8e9b35588 Mon Sep 17 00:00:00 2001 From: Toms Date: Mon, 10 Feb 2025 16:42:16 +0200 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20return=20ResultSet=20?= =?UTF-8?q?for=20getHistoricalInstructions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: 🧨 changes data structure returned by methods (Identity.getHistoricalInstructions & Settlements.getHistoricalInstructions) --- src/api/client/Settlements.ts | 21 +++++++-- src/api/client/__tests__/Settlements.ts | 6 ++- src/api/entities/Identity/__tests__/index.ts | 48 +++++++++++++++++++- src/api/entities/Identity/index.ts | 17 +++++-- 4 files changed, 80 insertions(+), 12 deletions(-) diff --git a/src/api/client/Settlements.ts b/src/api/client/Settlements.ts index 27b0f8afdc..eceb87e2e0 100644 --- a/src/api/client/Settlements.ts +++ b/src/api/client/Settlements.ts @@ -21,10 +21,11 @@ import { InstructionAffirmationOperation, InstructionIdParams, ProcedureMethod, + ResultSet, } from '~/types'; import { Ensured } from '~/types/utils'; import { middlewareInstructionToHistoricInstruction } from '~/utils/conversion'; -import { createProcedureMethod } from '~/utils/internal'; +import { calculateNextKey, createProcedureMethod } from '~/utils/internal'; /** * Handles all Settlement related functionality @@ -135,19 +136,29 @@ export class Settlements { */ public async getHistoricalInstructions( filter: HistoricalInstructionFilters - ): Promise { + ): Promise> { const { context } = this; const query = await historicalInstructionsQuery(filter, context); const { data: { - instructions: { nodes: instructionsResult }, + instructions: { nodes: instructionsResult, totalCount }, }, } = await context.queryMiddleware>(query); - return instructionsResult.map(instruction => - middlewareInstructionToHistoricInstruction(instruction!, context) + const data = instructionsResult.map(middlewareInstruction => + middlewareInstructionToHistoricInstruction(middlewareInstruction, context) ); + + const count = new BigNumber(totalCount); + + const next = calculateNextKey(count, data.length, filter.start); + + return { + data, + next, + count, + }; } } diff --git a/src/api/client/__tests__/Settlements.ts b/src/api/client/__tests__/Settlements.ts index 2d73d1358b..f2393457d2 100644 --- a/src/api/client/__tests__/Settlements.ts +++ b/src/api/client/__tests__/Settlements.ts @@ -210,7 +210,11 @@ describe('Settlements Class', () => { const result = await settlements.getHistoricalInstructions({}); - expect(result).toEqual([mockHistoricInstruction]); + expect(result).toEqual({ + data: [mockHistoricInstruction], + next: new BigNumber(1), + count: new BigNumber(5), + }); }); }); }); diff --git a/src/api/entities/Identity/__tests__/index.ts b/src/api/entities/Identity/__tests__/index.ts index 44daced13b..b7797d469f 100644 --- a/src/api/entities/Identity/__tests__/index.ts +++ b/src/api/entities/Identity/__tests__/index.ts @@ -1281,6 +1281,12 @@ describe('Identity class', () => { }); describe('method: getHistoricalInstructions', () => { + let calculateNextSpy: jest.SpyInstance; + + beforeAll(() => { + calculateNextSpy = jest.spyOn(utilsInternalModule, 'calculateNextKey'); + }); + it('should return the list of all instructions where the Identity was involved', async () => { const identity = new Identity({ did: 'someDid' }, context); const middlewareInstructionToHistoricInstructionSpy = jest.spyOn( @@ -1305,7 +1311,47 @@ describe('Identity class', () => { const result = await identity.getHistoricalInstructions(); - expect(result).toEqual([mockHistoricInstruction]); + expect(result).toEqual({ + data: [mockHistoricInstruction], + next: new BigNumber(1), + count: new BigNumber(5), + }); + expect(calculateNextSpy).toHaveBeenCalledWith(new BigNumber(5), 1, undefined); + }); + + it('should return the list of all instructions where the Identity was involved when using pagination', async () => { + const identity = new Identity({ did: 'someDid' }, context); + const start = new BigNumber(0); + + const middlewareInstructionToHistoricInstructionSpy = jest.spyOn( + utilsConversionModule, + 'middlewareInstructionToHistoricInstruction' + ); + + calculateNextSpy = jest.spyOn(utilsInternalModule, 'calculateNextKey'); + const instructionsResponse = { + totalCount: 5, + nodes: [{ id: '1' }], + }; + + const query = await historicalInstructionsQuery({ identity: identity.did }, context); + + dsMockUtils.createApolloQueryMock(query, { + instructions: instructionsResponse, + }); + + const mockHistoricInstruction = 'mockData' as unknown as HistoricInstruction; + + middlewareInstructionToHistoricInstructionSpy.mockReturnValue(mockHistoricInstruction); + + const result = await identity.getHistoricalInstructions({ start }); + + expect(result).toEqual({ + data: [mockHistoricInstruction], + next: new BigNumber(1), + count: new BigNumber(5), + }); + expect(calculateNextSpy).toHaveBeenCalledWith(new BigNumber(5), 1, start); }); }); diff --git a/src/api/entities/Identity/index.ts b/src/api/entities/Identity/index.ts index 8ee3cd2d74..f4a9a558fa 100644 --- a/src/api/entities/Identity/index.ts +++ b/src/api/entities/Identity/index.ts @@ -907,20 +907,27 @@ export class Identity extends Entity { */ public async getHistoricalInstructions( filter?: Omit - ): Promise { + ): Promise> { const { context, did } = this; const query = await historicalInstructionsQuery({ ...filter, identity: did }, context); const { data: { - instructions: { nodes: instructionsResult }, + instructions: { nodes: instructionsResult, totalCount }, }, } = await context.queryMiddleware>(query); - return instructionsResult.map(instruction => - middlewareInstructionToHistoricInstruction(instruction, context) - ); + const count = new BigNumber(totalCount); + const next = calculateNextKey(count, instructionsResult.length, filter?.start); + + return { + data: instructionsResult.map(instruction => + middlewareInstructionToHistoricInstruction(instruction, context) + ), + next, + count, + }; } /** From 2d86a46dd19c75c2828dc5c751099df74ee0d86c Mon Sep 17 00:00:00 2001 From: Toms Date: Mon, 10 Feb 2025 16:43:36 +0200 Subject: [PATCH 4/4] =?UTF-8?q?chore:=20=F0=9F=A4=96=20mark=20Network.getE?= =?UTF-8?q?ventsByIndexedArgs=20deprecated?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/client/Network.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api/client/Network.ts b/src/api/client/Network.ts index 0c7227d88e..df62ba3038 100644 --- a/src/api/client/Network.ts +++ b/src/api/client/Network.ts @@ -310,6 +310,7 @@ export class Network { /** * Retrieve a list of events. Can be filtered using parameters * + * @deprecated * @param opts.moduleId - type of the module to fetch * @param opts.eventId - type of the event to fetch * @param opts.eventArg0 - event parameter value to filter by in position 0