Skip to content

feat: allow passing historical as a parameter #313

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
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
26 changes: 19 additions & 7 deletions packages/state/src/recs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const getSyncEntities = async <S extends Schema>(
* @param entityKeyClause - An array of entity key clauses to synchronize.
* @param limit - The maximum number of events to fetch per request (default: 100).
* @param logging - Whether to log debug information (default: false).
* @param historical - Whether to fetch and subscribe to historical events (default: true).
* @returns A promise that resolves to a subscription for event updates.
*
* @example
Expand All @@ -89,11 +90,18 @@ export const getSyncEvents = async <S extends Schema>(
clause: Clause | undefined,
entityKeyClause: EntityKeysClause[],
limit: number = 100,
logging: boolean = false
logging: boolean = false,
historical: boolean = true
Comment on lines +93 to +94
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Tests needed for the new historical parameter functionality.

While the implementation looks good, tests should be added to verify the behavior of the historical parameter across all modified functions. This should include:

  1. Test cases with historical=true (default behavior)
  2. Test cases with historical=false (new behavior)
  3. Integration tests showing the interaction between these functions

Would you like me to help create test cases for these scenarios?

Also applies to: 168-169, 315-316

) => {
if (logging) console.log("Starting getSyncEvents");
await getEvents(client, components, limit, clause, logging);
return await syncEvents(client, components, entityKeyClause, logging);
await getEvents(client, components, limit, clause, logging, historical);
return await syncEvents(
client,
components,
entityKeyClause,
logging,
historical
);
};

/**
Expand Down Expand Up @@ -150,13 +158,15 @@ export const getEntities = async <S extends Schema>(
* @param limit - The maximum number of event messages to fetch per request (default: 100).
* @param clause - An optional clause to filter event messages.
* @param logging - Whether to log debug information (default: false).
* @param historical - Whether to fetch historical events (default: true).
*/
export const getEvents = async <S extends Schema>(
client: ToriiClient,
components: Component<S, Metadata, undefined>[],
limit: number = 100,
clause: Clause | undefined,
logging: boolean = false
logging: boolean = false,
historical: boolean = true
) => {
if (logging) console.log("Starting getEvents");
let offset = 0;
Expand All @@ -170,7 +180,7 @@ export const getEvents = async <S extends Schema>(
clause,
dont_include_hashed_keys: false,
},
true
historical
);

if (logging) console.log("entities", entities);
Expand Down Expand Up @@ -291,6 +301,7 @@ export const syncEntities = async <S extends Schema>(
* @param components - An array of component definitions.
* @param entityKeyClause - An array of EntityKeysClause to filter entities.
* @param logging - Whether to log debug information (default: false).
* @param historical - Whether to sync to historical events (default: true).
* @returns A promise that resolves with the subscription handler.
* @example
* const sync = await syncEvents(client, components, entityKeyClause);
Expand All @@ -301,12 +312,13 @@ export const syncEvents = async <S extends Schema>(
client: ToriiClient,
components: Component<S, Metadata, undefined>[],
entityKeyClause: EntityKeysClause[],
logging: boolean = false
logging: boolean = false,
historical: boolean = true
Comment on lines +315 to +316
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Verification needed: Historical parameter implementation mismatch

The implementation shows inconsistency in how the historical parameter is used:

  • In packages/state/src/recs/index.ts, it's properly passed as a parameter
  • In packages/sdk/src/subscribeEventQuery.ts, it's hardcoded to true

This suggests potential issues:

  • The SDK's implementation doesn't expose the historical parameter to users
  • The hardcoded value might conflict with the configurable parameter in the state package
🔗 Analysis chain

LGTM: Implementation correctly uses the historical parameter.

The changes properly integrate with the client's API. However, let's verify the client's implementation supports this parameter.

Also applies to: 321-321

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ToriiClient's onEventMessageUpdated method supports the historical parameter
# Test: Search for the onEventMessageUpdated method definition
ast-grep --pattern 'interface ToriiClient {
  $$$
  onEventMessageUpdated($_): $_
  $$$
}'

Length of output: 92


Script:

#!/bin/bash
# Let's try a broader search for ToriiClient and onEventMessageUpdated
# First, find relevant files
fd -t f -e ts -e tsx ToriiClient

# Then search for onEventMessageUpdated method/function definitions
rg -l "onEventMessageUpdated" 

# Finally, let's look for actual implementations or interface definitions
ast-grep --pattern 'onEventMessageUpdated($_)'

Length of output: 186


Script:

#!/bin/bash
# Let's examine the actual implementation and usage in both files
rg -A 5 -B 5 "onEventMessageUpdated" packages/sdk/src/subscribeEventQuery.ts packages/state/src/recs/index.ts

Length of output: 1657

) => {
if (logging) console.log("Starting syncEvents");
return await client.onEventMessageUpdated(
entityKeyClause,
true,
historical,
(fetchedEntities: any, data: any) => {
if (logging) console.log("Event message updated", fetchedEntities);

Expand Down