Skip to content

fix: added historical option for event getters #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Comment on lines +395 to +396
Copy link

@coderabbitai coderabbitai bot Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Default value of historical parameter needs to be aligned with the interface

The implementation in both getEventMessages.ts and subscribeEventQuery.ts sets a default value of true for the historical parameter, while the interface in types.ts marks it as optional without a default value. This misalignment should be addressed.

  • packages/sdk/src/getEventMessages.ts: Remove default value true for historical parameter
  • packages/sdk/src/subscribeEventQuery.ts: Remove default value true for historical parameter
🔗 Analysis chain

Verify implementation details across related files.

The interfaces have been updated correctly, but let's verify the implementation details:

Also applies to: 377-378

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the historical parameter

# Check getEventMessages implementation
echo "Checking getEventMessages implementation..."
rg -A 5 "getEventMessages.*=.*async.*" packages/sdk/src/

# Check subscribeEventQuery implementation
echo "Checking subscribeEventQuery implementation..."
rg -A 5 "subscribeEventQuery.*=.*async.*" packages/sdk/src/

# Check for any hardcoded true values that might need to be replaced
echo "Checking for hardcoded historical values..."
rg "historical.*:.*true" packages/sdk/src/

Length of output: 601

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rsodre, thank you for fixing the issue!


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

}

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;
}
Loading