@@ -160,7 +160,7 @@ export const getEvents = async <S extends Schema>(
160
160
} ;
161
161
162
162
/**
163
- * Fetches entities and their components from the client based on specified criteria.
163
+ * Fetches entities and their components from the client based on specified criteria, helping to reduce the loading time when the entities are fetched .
164
164
* @param client - The client instance for API communication.
165
165
* @param components - An array of component definitions to fetch.
166
166
* @param entityKeyClause - An optional EntityKeysClause to filter entities by their keys.
@@ -170,20 +170,25 @@ export const getEvents = async <S extends Schema>(
170
170
* @example
171
171
* const components = createClientComponents({ contractComponents });
172
172
* await getEntitiesQuery(client, components, undefined, "FixedLen", 1000);
173
+ * return await syncEntities(toriiClient, components as any, []);
173
174
*
174
175
* @example
175
176
* const components = createClientComponents({ contractComponents });
176
177
* await getEntitiesQuery(client, components, { Keys: { keys: ["0x1"], models: ["Position"] } }, "FixedLen", 1000);
178
+ * return await syncEntities(toriiClient, components as any, []);
177
179
*
178
180
* @example
179
181
* const components = createClientComponents({ contractComponents });
180
182
* await getEntitiesQuery(client, components, { HashedKeys: ["0x1"] }, "FixedLen", 1000);
183
+ * return await syncEntities(toriiClient, components as any, []);
181
184
*
182
185
* This function performs paginated queries to fetch all matching entities and their
183
186
* components. It uses the provided EntityKeysClause (if any) to filter entities and
184
187
* the specified components to determine which data to retrieve. The function continues
185
188
* fetching until all matching entities have been retrieved, using the 'limit' parameter
186
189
* to control the batch size of each request.
190
+ *
191
+ * Note: Make sure to synchronize the entities by calling the syncEntities method
187
192
*/
188
193
export const getEntitiesQuery = async < S extends Schema > (
189
194
client : ToriiClient ,
@@ -195,22 +200,24 @@ export const getEntitiesQuery = async <S extends Schema>(
195
200
let cursor = 0 ;
196
201
let continueFetching = true ;
197
202
198
- while ( continueFetching ) {
199
- const clause : Clause | null = entityKeyClause
200
- ? {
201
- Keys : {
202
- keys :
203
- "HashedKeys" in entityKeyClause
204
- ? entityKeyClause . HashedKeys
205
- : entityKeyClause . Keys . keys ,
206
- pattern_matching : patternMatching ,
207
- models : [
208
- ...components . map ( ( c ) => c . metadata ?. name as string ) ,
209
- ] ,
210
- } ,
211
- }
212
- : null ;
203
+ const componentArray = Object . values ( components ) ;
213
204
205
+ const clause : Clause | null = entityKeyClause
206
+ ? {
207
+ Keys : {
208
+ keys :
209
+ "HashedKeys" in entityKeyClause
210
+ ? entityKeyClause . HashedKeys
211
+ : entityKeyClause . Keys . keys ,
212
+ pattern_matching : patternMatching ,
213
+ models : [
214
+ ...componentArray . map ( ( c ) => c . metadata ?. name as string ) ,
215
+ ] ,
216
+ } ,
217
+ }
218
+ : null ;
219
+
220
+ while ( continueFetching ) {
214
221
const fetchedEntities = await client . getEntities ( {
215
222
limit,
216
223
offset : cursor ,
0 commit comments