Skip to content

Commit

Permalink
Merge pull request #352 from rsodre/fetch-events-historical-flag
Browse files Browse the repository at this point in the history
fix: added historical option for event getters
  • Loading branch information
MartianGreed authored Dec 27, 2024
2 parents fd05dc5 + ff2adef commit 85338c4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/sdk/src/getEventMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export async function getEventMessages<T extends SchemaType>(
entityModels: string[] = [],
limit: number = 100, // Default limit
offset: number = 0, // Default offset
options?: { logging?: boolean } // Logging option
options?: { logging?: boolean }, // Logging option
historical?: boolean
): Promise<StandardizedQueryResult<T>> {
const clause = convertQueryToClause(query, schema);

Expand All @@ -58,7 +59,10 @@ export async function getEventMessages<T extends SchemaType>(
};

try {
const entities = await client.getEventMessages(toriiQuery, true);
const entities = await client.getEventMessages(
toriiQuery,
historical ?? true
);

if (options?.logging) {
console.log(`Fetched entities at offset ${cursor}:`, entities);
Expand Down
15 changes: 12 additions & 3 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@ export async function init<T extends SchemaType>(
* @param {SubscribeParams<T>} params - Parameters object
* @returns {Promise<void>} - A promise that resolves when the subscription is set up.
*/
subscribeEventQuery: ({ query, callback, options }) =>
subscribeEventQuery(client, query, schema, callback, options),
subscribeEventQuery: ({ query, callback, options, historical }) =>
subscribeEventQuery(
client,
query,
schema,
callback,
options,
historical
),
/**
* Fetches entities based on the provided query.
*
Expand Down Expand Up @@ -95,6 +102,7 @@ export async function init<T extends SchemaType>(
limit,
offset,
options,
historical,
}) =>
getEventMessages(
client,
Expand All @@ -105,7 +113,8 @@ export async function init<T extends SchemaType>(
entityModels,
limit,
offset,
options
options,
historical
),

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/src/subscribeEventQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ export async function subscribeEventQuery<T extends SchemaType>(
data?: StandardizedQueryResult<T>;
error?: Error;
}) => void,
options?: { logging?: boolean }
options?: { logging?: boolean },
historical?: boolean
): Promise<torii.Subscription> {
return client.onEventMessageUpdated(
convertQueryToEntityKeyClauses(query, schema),
true,
historical ?? true,
(entityId: string, entityData: any) => {
try {
if (callback) {
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ export interface SubscribeParams<T extends SchemaType> {
}) => void;
// Optional settings.
options?: SDKFunctionOptions;
// historical events
historical?: boolean;
}

export interface GetParams<T extends SchemaType> {
Expand All @@ -412,4 +414,6 @@ export interface GetParams<T extends SchemaType> {
offset?: number;
// Optional settings.
options?: SDKFunctionOptions;
// historical events
historical?: boolean;
}

0 comments on commit 85338c4

Please sign in to comment.