From 12652695becc3df0e2a0883087e6317b0cbbde5d Mon Sep 17 00:00:00 2001 From: Mathieu Lefebvre Date: Tue, 14 Nov 2023 10:45:46 -0500 Subject: [PATCH] add offset parameter to all path --- src/fetch/openapi.ts | 12 ++++++++++++ src/queries.ts | 10 ++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/fetch/openapi.ts b/src/fetch/openapi.ts index fb43624..142c9db 100644 --- a/src/fetch/openapi.ts +++ b/src/fetch/openapi.ts @@ -58,6 +58,14 @@ const parameterLimit: ParameterObject = { schema: { type: "number", maximum: config.maxLimit, minimum: 1 }, } +const parameterOffset: ParameterObject = { + name: "offset", + in: "query", + description: "Used to offset data. Combined with limit can be used for pagination.", + required: false, + schema: { type: "number", minimum: 1 }, +} + const timestampFilter = timestampExamplesArrayFilter.map(name => { return { @@ -118,6 +126,7 @@ export default new OpenApiBuilder() ...timestampFilter, ...blockFilter, parameterLimit, + parameterOffset, ], responses: { 200: { description: "Array of supply", content: { "application/json": { example: supply_example, schema: { type: "array" } } } }, @@ -137,6 +146,7 @@ export default new OpenApiBuilder() ...timestampFilter, ...blockFilter, parameterLimit, + parameterOffset, ], responses: { 200: { description: "Array of contracts", content: { "application/json": { example: contract_example, schema: { type: "array" } } } }, @@ -156,6 +166,7 @@ export default new OpenApiBuilder() ...timestampFilter, ...blockFilter, parameterLimit, + parameterOffset, ], responses: { 200: { description: "Array of balance changes", content: { "application/json": { example: balance_example, schema: { type: "array" } } } }, @@ -172,6 +183,7 @@ export default new OpenApiBuilder() ...timestampFilter, ...blockFilter, parameterLimit, + parameterOffset, ], responses: { 200: { description: "Array of holders", content: { "application/json": { example: holders_example, schema: { type: "array" } } } }, diff --git a/src/queries.ts b/src/queries.ts index 7224be6..9d4c969 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -69,7 +69,8 @@ export function getTotalSupply(searchParams: URLSearchParams, example?: boolean) } const limit = parseLimit(searchParams.get("limit")); query += ` LIMIT ${limit} ` - + const offset = searchParams.get("offset"); + if (offset) query += ` OFFSET ${offset} ` return query; } @@ -108,6 +109,8 @@ export function getContracts(searchParams: URLSearchParams, example?: boolean) { } const limit = parseLimit(searchParams.get("limit")); query += ` LIMIT ${limit} ` + const offset = searchParams.get("offset"); + if (offset) query += ` OFFSET ${offset} ` return query; } @@ -160,6 +163,8 @@ export function getBalanceChanges(searchParams: URLSearchParams, example?: boole } const limit = parseLimit(searchParams.get("limit"), 100); query += ` LIMIT ${limit} ` + const offset = searchParams.get("offset"); + if (offset) query += ` OFFSET ${offset} ` return query; } @@ -205,7 +210,8 @@ export function getHolders(searchParams: URLSearchParams, example?: boolean) { const limit = parseLimit(searchParams.get("limit"), 100); if (limit) query += ` LIMIT ${limit} `; - + const offset = searchParams.get("offset"); + if (offset) query += ` OFFSET ${offset} ` return query; }