Skip to content

Commit

Permalink
fix: 🐛 support SQ v19 createdEvent
Browse files Browse the repository at this point in the history
add support for the latest updated in SQ v19
  • Loading branch information
polymath-eric committed Dec 11, 2024
1 parent 5fb75a9 commit c8aa1e0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
5 changes: 2 additions & 3 deletions src/middleware/queries/authorizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ export function authorizationsQuery(
): QueryOptions<PaginatedQueryArgs<QueryArgs<Authorization, AuthorizationArgs>>> {
const { args, filter } = createAuthorizationFilters(filters);

const idField = paddedIds ? 'id' : 'authId: id';
const orderBy = paddedIds
? `${AuthorizationsOrderBy.CreatedBlockIdAsc}`
? `${AuthorizationsOrderBy.CreatedEventIdAsc}`
: `${AuthorizationsOrderBy.CreatedAtAsc}, ${AuthorizationsOrderBy.CreatedBlockIdAsc}`;

const query = gql`
Expand All @@ -76,7 +75,7 @@ export function authorizationsQuery(
) {
totalCount
nodes {
${idField}
id
type
fromId
toId
Expand Down
9 changes: 0 additions & 9 deletions src/middleware/queries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,3 @@ export function removeUndefinedValues(
): Record<string | number | symbol, unknown> {
return Object.fromEntries(Object.entries(variables).filter(([, value]) => value !== undefined));
}

/**
* Pad ID for subquery
*
* @hidden
*/
export function padSqId(id: string): string {
return id.padStart(10, '0');
}
24 changes: 13 additions & 11 deletions src/middleware/queries/settlements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const legAttributes = `
}
`;

const instructionAttributes = (paddedIds: boolean): string => `
${paddedIds ? 'id' : 'instructionId: id'}
const instructionAttributes = `
id
venueId
status
type
Expand Down Expand Up @@ -112,7 +112,7 @@ export function instructionEventsQuery(
let orderBy = `[${InstructionEventsOrderBy.CreatedAtDesc}, ${InstructionEventsOrderBy.CreatedBlockIdDesc}]`;

if (paddedIds) {
orderBy = `[${InstructionEventsOrderBy.CreatedBlockIdDesc}]`;
orderBy = `[${InstructionEventsOrderBy.CreatedEventIdDesc}]`;
}

const query = gql`
Expand Down Expand Up @@ -174,9 +174,11 @@ export function instructionsQuery(
status: 'InstructionStatusEnum',
});

const orderBy = paddedIds
? `[${InstructionEventsOrderBy.IdDesc}]`
: `[${InstructionsOrderBy.CreatedAtDesc}, ${InstructionsOrderBy.IdDesc}]`;
let orderBy = `[${InstructionsOrderBy.CreatedAtDesc}, ${InstructionsOrderBy.IdDesc}]`;

if (paddedIds) {
orderBy = `[${InstructionsOrderBy.CreatedEventIdDesc}]`;
}

const query = gql`
query InstructionsQuery
Expand All @@ -190,7 +192,7 @@ export function instructionsQuery(
) {
totalCount
nodes {
${instructionAttributes(paddedIds)}
${instructionAttributes}
}
}
}
Expand Down Expand Up @@ -422,7 +424,7 @@ export async function instructionPartiesQuery(
const paddedIds = context.isSqIdPadded;

const orderBy = paddedIds
? `[${LegsOrderBy.InstructionIdAsc}]`
? `[${LegsOrderBy.CreatedBlockIdAsc}]`
: `[${LegsOrderBy.CreatedAtAsc}, ${LegsOrderBy.InstructionIdAsc}]`;

const query = gql`
Expand All @@ -437,7 +439,7 @@ export async function instructionPartiesQuery(
) {
nodes {
instruction {
${instructionAttributes(paddedIds)}
${instructionAttributes}
}
}
totalCount
Expand Down Expand Up @@ -516,7 +518,7 @@ function createLegFilters(
*/
function buildSettlementsQuery(paddedIds: boolean, args: string, filter: string): DocumentNode {
const orderBy = paddedIds
? `[${LegsOrderBy.InstructionIdAsc}]`
? `[${LegsOrderBy.CreatedBlockIdAsc}]`
: `[${LegsOrderBy.CreatedAtAsc}, ${LegsOrderBy.InstructionIdAsc}]`;

return gql`
Expand All @@ -529,7 +531,7 @@ function buildSettlementsQuery(paddedIds: boolean, args: string, filter: string)
) {
nodes {
instruction {
${instructionAttributes(paddedIds)}
${instructionAttributes}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/middleware/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13222,6 +13222,8 @@ export enum AuthorizationsOrderBy {
CreatedAtDesc = 'CREATED_AT_DESC',
CreatedBlockIdAsc = 'CREATED_BLOCK_ID_ASC',
CreatedBlockIdDesc = 'CREATED_BLOCK_ID_DESC',
CreatedEventIdAsc = 'CREATED_EVENT_ID_ASC',
CreatedEventIdDesc = 'CREATED_EVENT_ID_DESC',
DataAsc = 'DATA_ASC',
DataDesc = 'DATA_DESC',
ExpiryAsc = 'EXPIRY_ASC',
Expand Down Expand Up @@ -97680,6 +97682,8 @@ export enum InstructionEventsOrderBy {
CreatedAtDesc = 'CREATED_AT_DESC',
CreatedBlockIdAsc = 'CREATED_BLOCK_ID_ASC',
CreatedBlockIdDesc = 'CREATED_BLOCK_ID_DESC',
CreatedEventIdAsc = 'CREATED_EVENT_ID_ASC',
CreatedEventIdDesc = 'CREATED_EVENT_ID_DESC',
EventAsc = 'EVENT_ASC',
EventDesc = 'EVENT_DESC',
EventIdxAsc = 'EVENT_IDX_ASC',
Expand Down Expand Up @@ -99724,6 +99728,8 @@ export enum InstructionsOrderBy {
CreatedAtDesc = 'CREATED_AT_DESC',
CreatedBlockIdAsc = 'CREATED_BLOCK_ID_ASC',
CreatedBlockIdDesc = 'CREATED_BLOCK_ID_DESC',
CreatedEventIdAsc = 'CREATED_EVENT_ID_ASC',
CreatedEventIdDesc = 'CREATED_EVENT_ID_DESC',
EndAfterBlockAsc = 'END_AFTER_BLOCK_ASC',
EndAfterBlockDesc = 'END_AFTER_BLOCK_DESC',
EndBlockAsc = 'END_BLOCK_ASC',
Expand Down

0 comments on commit c8aa1e0

Please sign in to comment.