Skip to content

Commit ff2adef

Browse files
committed
fix: added historical option for event getters
1 parent fd05dc5 commit ff2adef

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

packages/sdk/src/getEventMessages.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export async function getEventMessages<T extends SchemaType>(
3838
entityModels: string[] = [],
3939
limit: number = 100, // Default limit
4040
offset: number = 0, // Default offset
41-
options?: { logging?: boolean } // Logging option
41+
options?: { logging?: boolean }, // Logging option
42+
historical?: boolean
4243
): Promise<StandardizedQueryResult<T>> {
4344
const clause = convertQueryToClause(query, schema);
4445

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

6061
try {
61-
const entities = await client.getEventMessages(toriiQuery, true);
62+
const entities = await client.getEventMessages(
63+
toriiQuery,
64+
historical ?? true
65+
);
6266

6367
if (options?.logging) {
6468
console.log(`Fetched entities at offset ${cursor}:`, entities);

packages/sdk/src/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ export async function init<T extends SchemaType>(
5353
* @param {SubscribeParams<T>} params - Parameters object
5454
* @returns {Promise<void>} - A promise that resolves when the subscription is set up.
5555
*/
56-
subscribeEventQuery: ({ query, callback, options }) =>
57-
subscribeEventQuery(client, query, schema, callback, options),
56+
subscribeEventQuery: ({ query, callback, options, historical }) =>
57+
subscribeEventQuery(
58+
client,
59+
query,
60+
schema,
61+
callback,
62+
options,
63+
historical
64+
),
5865
/**
5966
* Fetches entities based on the provided query.
6067
*
@@ -95,6 +102,7 @@ export async function init<T extends SchemaType>(
95102
limit,
96103
offset,
97104
options,
105+
historical,
98106
}) =>
99107
getEventMessages(
100108
client,
@@ -105,7 +113,8 @@ export async function init<T extends SchemaType>(
105113
entityModels,
106114
limit,
107115
offset,
108-
options
116+
options,
117+
historical
109118
),
110119

111120
/**

packages/sdk/src/subscribeEventQuery.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ export async function subscribeEventQuery<T extends SchemaType>(
3636
data?: StandardizedQueryResult<T>;
3737
error?: Error;
3838
}) => void,
39-
options?: { logging?: boolean }
39+
options?: { logging?: boolean },
40+
historical?: boolean
4041
): Promise<torii.Subscription> {
4142
return client.onEventMessageUpdated(
4243
convertQueryToEntityKeyClauses(query, schema),
43-
true,
44+
historical ?? true,
4445
(entityId: string, entityData: any) => {
4546
try {
4647
if (callback) {

packages/sdk/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ export interface SubscribeParams<T extends SchemaType> {
392392
}) => void;
393393
// Optional settings.
394394
options?: SDKFunctionOptions;
395+
// historical events
396+
historical?: boolean;
395397
}
396398

397399
export interface GetParams<T extends SchemaType> {
@@ -412,4 +414,6 @@ export interface GetParams<T extends SchemaType> {
412414
offset?: number;
413415
// Optional settings.
414416
options?: SDKFunctionOptions;
417+
// historical events
418+
historical?: boolean;
415419
}

0 commit comments

Comments
 (0)