diff --git a/src/queries.ts b/src/queries.ts index 4ae8952..82949dd 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -59,8 +59,6 @@ export function getTotalSupply(endpoint: UsageEndpoints, query_param: any, examp const q = query_param as ValidUserParams; let contract = q.contract; - let symbol = q.symbol; - let name = q.name; let additional_query_params = {}; @@ -87,15 +85,11 @@ export function getTotalSupply(endpoint: UsageEndpoints, query_param: any, examp const where = []; // equals - if (contract) where.push(`${table}.contract = {contract : string}`); + if (contract) where.push(`${table}.contract = {contract : String}`); // timestamp and block filter additional_query_params = addBlockFilter(q, additional_query_params, where); - if (symbol) where.push(`LOWER(symbol) = {symbol : string} `); - if (name) where.push(`LOWER(name) = {name : string} `); - - // Join WHERE statements with AND if (where.length) query += ` WHERE(${where.join(' AND ')})`; @@ -143,9 +137,9 @@ export function getContracts(endpoint: UsageEndpoints, query_param: any, example if (!example) { // WHERE statements const where = []; - if (contract) where.push(`contract = {contract : string}`); - if (symbol) where.push(`LOWER(symbol) = {symbol : string} `); - if (name) where.push(`LOWER(name) = {name : string} `); + if (contract) where.push(`contract = {contract : String}`); + if (symbol) where.push(`LOWER(symbol) = {symbol : String} `); + if (name) where.push(`LOWER(name) = {name : String} `); // Join WHERE statements with AND @@ -175,8 +169,8 @@ function getBalanceChanges_latest(q: any) { let contract = q.contract; let account = q.account; - let table = `{chain : string }_erc20_token.account_balances` - const contractTable = `{chain : string }_erc20_token.contracts`; + let table = `{chain : String }_erc20_token.account_balances` + const contractTable = `{chain : String }_erc20_token.contracts`; let query = `SELECT ${table}.account, ${table}.contract, @@ -189,9 +183,9 @@ function getBalanceChanges_latest(q: any) { const where = []; // equals - where.push(`account = {account : string}`) + where.push(`account = {account : String}`) where.push(`amount != '0'`); - if (contract) where.push(`contract = {contract : string}`); + if (contract) where.push(`contract = {contract : String}`); // Join WHERE statements with AND if (where.length) query += ` WHERE(${where.join(' AND ')})`; @@ -229,10 +223,10 @@ function getBalanceChanges_historical(q: any) { let additional_query_params = {}; let table; - const contractTable = `{chain : string}_erc20_token.contracts`; + const contractTable = `{chain : String}_erc20_token.contracts`; // SQL Query - if (contract) table = `{chain : string}_erc20_token.balance_changes_contract_historical_mv`; - else table = `{chain : string}_erc20_token.balance_changes_account_historical_mv` + if (contract) table = `{chain : String}_erc20_token.balance_changes_contract_historical_mv`; + else table = `{chain : String}_erc20_token.balance_changes_account_historical_mv` let query = `SELECT ${table}.owner, @@ -253,8 +247,8 @@ function getBalanceChanges_historical(q: any) { else joinSelectQuery = `SELECT contract, owner, MAX(block_num) as block_num FROM (SELECT owner, block_num , contract FROM ${table} ${blockfilterQuery})`; const joinWhereQuery: any = []; //add where filter to joinQuery - if (contract) joinWhereQuery.push(`contract = {contract : string}`); - joinWhereQuery.push(`owner = {account : string}`); + if (contract) joinWhereQuery.push(`contract = {contract : String}`); + joinWhereQuery.push(`owner = {account : String}`); if (joinWhereQuery.length) joinSelectQuery += ` WHERE(${joinWhereQuery.join(' AND ')})`; //Add group by to joinQuery @@ -268,9 +262,9 @@ function getBalanceChanges_historical(q: any) { const where = []; // equals - where.push(`owner = {account : string}`) + where.push(`owner = {account : String}`) where.push(`amount != '0'`); - if (contract) where.push(`contract = {contract : string}`); + if (contract) where.push(`contract = {contract : String}`); // Join WHERE statements with AND if (where.length) query += ` WHERE(${where.join(' AND ')})`; @@ -337,7 +331,7 @@ function getHolder_latest(q: any) { // WHERE statements const where: any = []; - if (contract) where.push(`contract = {contract : string}`); + if (contract) where.push(`contract = {contract : String}`); where.push(`amount != '0'`); // Join WHERE statements with AND @@ -376,7 +370,7 @@ FROM ${table} `; const joinWhereQuery: any = []; //add where filter to joinQuery - joinWhereQuery.push(`contract = {contract : string}`); + joinWhereQuery.push(`contract = {contract : String}`); if (joinWhereQuery.length) joinSelectQuery += ` WHERE(${joinWhereQuery.join(' AND ')})`; //Add group by to joinQuery @@ -386,7 +380,7 @@ FROM ${table} `; // WHERE statements const where: any = []; - if (contract) where.push(`contract = {contract : string}`); + if (contract) where.push(`contract = {contract : String}`); where.push(`amount != '0'`); // Join WHERE statements with AND @@ -462,9 +456,9 @@ export function getTransfers(endpoint: UsageEndpoints, query_param: any) { const where = []; // equals - if (contract) where.push(`contract = {contract : string}`); - if (from) where.push(`from = {from : string}`); - if (to) where.push(`to = {to : string}`); + if (contract) where.push(`contract = {contract : String}`); + if (from) where.push(`from = {from : String}`); + if (to) where.push(`to = {to : String}`); // timestamp and block filter additional_query_params = addBlockRangeFilter(q, additional_query_params, where); diff --git a/src/types/zod.gen.ts b/src/types/zod.gen.ts index 41ef1d6..84a2c4b 100644 --- a/src/types/zod.gen.ts +++ b/src/types/zod.gen.ts @@ -217,12 +217,10 @@ export const get_Usage_supply = { path: z.literal("/{chain}/supply"), parameters: z.object({ query: z.object({ - contract: z.string().optional(), - symbol: z.string().optional(), - name: z.string().optional(), - block_num: z.number().optional(), - limit: z.number().optional(), - page: z.number().optional(), + contract: z.string(), + block_num: z.union([z.number(), z.undefined()]), + limit: z.union([z.number(), z.undefined()]), + page: z.union([z.number(), z.undefined()]), }), path: z.object({ chain: z.union([z.literal("eth"), z.literal("polygon")]), diff --git a/src/typespec/openapi3.tsp b/src/typespec/openapi3.tsp index aeb6f2f..71c85a1 100644 --- a/src/typespec/openapi3.tsp +++ b/src/typespec/openapi3.tsp @@ -154,9 +154,7 @@ interface Usage { @get supply( @path chain: SupportedChains, - @query contract?: Supply.contract, - @query symbol?: Contract.symbol, - @query name?: Contract.name, + @query contract: Supply.contract, ...BlockFilter, ...PaginationQueryParams, ): APIResponse>; diff --git a/tsp-output/@typespec/openapi3/openapi.json b/tsp-output/@typespec/openapi3/openapi.json index 57a98fd..595d82d 100644 --- a/tsp-output/@typespec/openapi3/openapi.json +++ b/tsp-output/@typespec/openapi3/openapi.json @@ -442,23 +442,7 @@ { "name": "contract", "in": "query", - "required": false, - "schema": { - "type": "string" - } - }, - { - "name": "symbol", - "in": "query", - "required": false, - "schema": { - "type": "string" - } - }, - { - "name": "name", - "in": "query", - "required": false, + "required": true, "schema": { "type": "string" }