Skip to content

Commit a962bc5

Browse files
authored
Merge pull request #435 from dojoengine/feat/support-torii-pagination
feat: support torii pagination
2 parents ce06a8c + 97aaa22 commit a962bc5

File tree

45 files changed

+907
-644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+907
-644
lines changed

.changeset/stale-eggs-heal.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@dojoengine/torii-wasm": patch
3+
"@dojoengine/react": patch
4+
"@dojoengine/state": patch
5+
"@dojoengine/sdk": patch
6+
"@dojoengine/core": patch
7+
"@dojoengine/create-burner": patch
8+
"@dojoengine/create-dojo": patch
9+
"@dojoengine/predeployed-connector": patch
10+
"@dojoengine/torii-client": patch
11+
"@dojoengine/utils": patch
12+
"@dojoengine/utils-wasm": patch
13+
---
14+
15+
feat: Support torii pagination

examples/example-node-worker/main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type ParsedEntity,
77
getModel,
88
HistoricalToriiQueryBuilder,
9+
StandardizedQueryResult,
910
} from "@dojoengine/sdk/node";
1011
import { SigningKey } from "@dojoengine/torii-wasm/node";
1112
import { dojoConfig } from "./dojoConfig.ts";
@@ -87,7 +88,7 @@ async function publishOffchainPositionCount(moves: Moves): Promise<void> {
8788
)
8889
.includeHashedKeys(),
8990
});
90-
const m = getModel(ModelsMapping.PositionCount, model);
91+
const m = getModel(ModelsMapping.PositionCount, model.getItems());
9192
if (!m) {
9293
const data = sdk.generateTypedData(
9394
ModelsMapping.PositionCount,
@@ -120,7 +121,7 @@ async function publishOffchainPositionCount(moves: Moves): Promise<void> {
120121
let positionCount = defaultPositionCount;
121122

122123
function initPositionFromEvent(
123-
events: ParsedEntity<SchemaType>[]
124+
events: StandardizedQueryResult<SchemaType>
124125
): PositionCount {
125126
const pc = defaultPositionCount;
126127
for (const e of events) {
@@ -162,16 +163,15 @@ await createWorker(async () => {
162163
const events = await sdk.getEventMessages({
163164
query: query,
164165
});
165-
positionCount = initPositionFromEvent(events);
166+
positionCount = initPositionFromEvent(events.getItems());
166167

167168
const [entities, sub] = await sdk.subscribeEntityQuery({
168169
query,
169170
callback: onEntityUpdated,
170171
});
171172

172-
console.log("Entities from worker", entities);
173+
console.log("Entities from worker", entities.getItems());
173174
console.log(positionCount);
174175

175-
return [];
176176
return [sub];
177177
});

examples/example-vite-grpc-playground/src/App.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { useState, useEffect, useCallback } from "react";
22
import { Button } from "./components/ui/button";
33
import { Card } from "./components/ui/card";
4-
import { QueryHistory, QueryItem } from "./components/query-history";
5-
import { SchemaExplorer, SchemaItem } from "./components/schema-explorer";
4+
import { QueryHistory, type QueryItem } from "./components/query-history";
5+
import { SchemaExplorer, type SchemaItem } from "./components/schema-explorer";
66
import { QueryEditor } from "./components/query-editor";
77
import { QueryResults } from "./components/query-results";
8-
import {
8+
import type {
99
StandardizedQueryResult,
1010
SchemaType,
11-
type init,
11+
init,
1212
} from "@dojoengine/sdk";
1313
import { evaluateUserInput } from "./components/ts-executor";
1414

@@ -108,7 +108,7 @@ export const App = ({ sdk }: AppProps) => {
108108
});
109109
const endTime = performance.now();
110110
setExecutionTime(endTime - startTime);
111-
setResponse(response);
111+
setResponse(response.getItems());
112112

113113
// Add to history with deduplication
114114
setQueryHistory((prev) => {
@@ -119,7 +119,7 @@ export const App = ({ sdk }: AppProps) => {
119119
const newEntry = {
120120
query: strippedQuery,
121121
timestamp: Date.now(),
122-
rows: response.length,
122+
rows: response.getItems().length,
123123
executionTime: endTime - startTime,
124124
favorite:
125125
existingIndex >= 0

examples/example-vite-kitchen-sink/src/components/caller-counter.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { useCallback, useEffect, useState } from "react";
22

33
import {
44
KeysClause,
5-
ParsedEntity,
6-
SDK,
5+
type ParsedEntity,
6+
type SDK,
77
ToriiQueryBuilder,
88
} from "@dojoengine/sdk";
99
import { useDojoSDK } from "@dojoengine/sdk/react";
10-
import { Subscription } from "@dojoengine/torii-wasm";
11-
import { SchemaType } from "@/typescript/models.gen";
12-
import { setupWorld } from "@/typescript/contracts.gen";
10+
import type { Subscription } from "@dojoengine/torii-wasm";
11+
import type { SchemaType } from "@/typescript/models.gen";
12+
import type { setupWorld } from "@/typescript/contracts.gen";
1313
import { dojoConfig } from "@/../dojoConfig";
1414

1515
import { addAddressPadding } from "starknet";
@@ -72,7 +72,7 @@ export default function CallerCounter() {
7272
}
7373

7474
setIsLoading(false);
75-
setCount(parseInt(count.toString(), 16));
75+
setCount(Number.parseInt(count.toString(), 16));
7676
return;
7777
}
7878
if (error) {
@@ -82,11 +82,12 @@ export default function CallerCounter() {
8282
});
8383
setSub(sub);
8484
const count =
85-
initialEntities[0]?.models.onchain_dash?.CallerCounter?.counter;
85+
initialEntities.getItems()[0]?.models.onchain_dash
86+
?.CallerCounter?.counter;
8687
if (!count) {
8788
setCount(0);
8889
} else {
89-
setCount(parseInt(count.toString(), 16));
90+
setCount(Number.parseInt(count.toString(), 16));
9091
}
9192
}
9293
if (address && sdk && sub === null) {

examples/example-vite-kitchen-sink/src/components/chat.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@ import { Badge } from "./ui/badge";
33
import { Button } from "./ui/button";
44
import { Label } from "./ui/label";
55
import { Textarea } from "./ui/textarea";
6-
import { useCallback, useEffect, useRef, useState, KeyboardEvent } from "react";
6+
import {
7+
useCallback,
8+
useEffect,
9+
useRef,
10+
useState,
11+
type KeyboardEvent,
12+
} from "react";
713
import { useForm } from "react-hook-form";
814
import { useAccount } from "@starknet-react/core";
915
import { toValidAscii } from "@/lib/utils";
1016
import {
1117
KeysClause,
12-
ParsedEntity,
13-
SDK,
18+
type ParsedEntity,
19+
type SDK,
1420
ToriiQueryBuilder,
1521
} from "@dojoengine/sdk";
16-
import { Subscription } from "@dojoengine/torii-wasm";
22+
import type { Subscription } from "@dojoengine/torii-wasm";
1723
import { shortAddress } from "@/lib/utils";
18-
import { Message, SchemaType } from "@/typescript/models.gen";
24+
import type { Message, SchemaType } from "@/typescript/models.gen";
1925
import { useDojoSDK } from "@dojoengine/sdk/react";
20-
import { setupWorld } from "@/typescript/contracts.gen";
26+
import type { setupWorld } from "@/typescript/contracts.gen";
2127

2228
interface MessageItem {
2329
content: string;
@@ -99,11 +105,12 @@ export default function Chat() {
99105

100106
setMessages(
101107
initialMessages
108+
.getItems()
102109
.map((e) => e.models.onchain_dash.Message as MessageItem)
103110
.filter(Boolean)
104111
.sort((a: Message, b: Message): number =>
105-
parseInt(a.timestamp.toString(), 16) <
106-
parseInt(b.timestamp.toString(), 16)
112+
Number.parseInt(a.timestamp.toString(), 16) <
113+
Number.parseInt(b.timestamp.toString(), 16)
107114
? -1
108115
: 1
109116
)

examples/example-vite-kitchen-sink/src/components/global-counter.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { Button } from "./ui/button";
33
import { useSendTransaction } from "@starknet-react/core";
44
import {
55
KeysClause,
6-
ParsedEntity,
7-
SDK,
6+
type ParsedEntity,
7+
type SDK,
88
ToriiQueryBuilder,
99
} from "@dojoengine/sdk";
10-
import { Subscription } from "@dojoengine/torii-wasm";
10+
import type { Subscription } from "@dojoengine/torii-wasm";
1111
import { dojoConfig } from "@/../dojoConfig";
12-
import { SchemaType } from "@/typescript/models.gen";
12+
import type { SchemaType } from "@/typescript/models.gen";
1313
import { useDojoSDK } from "@dojoengine/sdk/react";
14-
import { setupWorld } from "@/typescript/contracts.gen";
14+
import type { setupWorld } from "@/typescript/contracts.gen";
1515

1616
export default function GlobalCOunter() {
1717
const [count, setCount] = useState(0);
@@ -63,7 +63,7 @@ export default function GlobalCOunter() {
6363
if (undefined === count) {
6464
return 0;
6565
}
66-
const value = parseInt(count.toString(), 16);
66+
const value = Number.parseInt(count.toString(), 16);
6767
setCount(value);
6868
setIsLoading(false);
6969
return;
@@ -76,11 +76,12 @@ export default function GlobalCOunter() {
7676
setSub(sub);
7777

7878
const count =
79-
initialEntities[0]?.models.onchain_dash?.GlobalCounter?.counter;
79+
initialEntities.getItems()[0]?.models.onchain_dash
80+
?.GlobalCounter?.counter;
8081
if (undefined === count) {
8182
setCount(0);
8283
} else {
83-
setCount(parseInt(count.toString(), 16));
84+
setCount(Number.parseInt(count.toString(), 16));
8485
}
8586
}
8687
if (db && sub === null) {

examples/example-vite-kitchen-sink/src/components/theme-switch.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { useState, useEffect, useCallback } from "react";
22
import { Moon, Sun } from "lucide-react";
3-
import { Subscription } from "@dojoengine/torii-wasm";
3+
import type { Subscription } from "@dojoengine/torii-wasm";
44
import { useAccount } from "@starknet-react/core";
55
import {
66
KeysClause,
7-
ParsedEntity,
8-
SDK,
7+
type ParsedEntity,
8+
type SDK,
99
ToriiQueryBuilder,
1010
} from "@dojoengine/sdk";
11-
import { SchemaType } from "@/typescript/models.gen";
11+
import type { SchemaType } from "@/typescript/models.gen";
1212
import { Button } from "@/components/ui/button";
1313
import {
1414
DropdownMenu,
@@ -22,7 +22,7 @@ import {
2222
} from "@/components/ui/dropdown";
2323
import { CairoCustomEnum } from "starknet";
2424
import { useDojoSDK, useEntityId } from "@dojoengine/sdk/react";
25-
import { setupWorld } from "@/typescript/contracts.gen";
25+
import type { setupWorld } from "@/typescript/contracts.gen";
2626

2727
interface ThemeState {
2828
current: string | null;
@@ -119,8 +119,9 @@ export default function ThemeSwitchButton() {
119119
});
120120
setSub(sub);
121121

122-
const theme =
123-
initialTheme[0]?.models?.onchain_dash?.Theme?.value?.unwrap();
122+
const theme = initialTheme
123+
.getItems()[0]
124+
?.models?.onchain_dash?.Theme?.value?.unwrap();
124125
let th = null;
125126
if (undefined === theme) {
126127
th = AvailableTheme.Light;

examples/example-vite-react-app-recs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@dojoengine/state": "workspace:*",
1818
"@dojoengine/torii-client": "workspace:*",
1919
"@dojoengine/utils": "workspace:*",
20+
"@dojoengine/sdk": "workspace:*",
2021
"@latticexyz/react": "^2.2.8",
2122
"@latticexyz/utils": "^2.2.8",
2223
"ethers": "^5.7.2",

examples/example-vite-react-app-recs/src/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useEffect, useState } from "react";
22
import { useComponentValue, useQuerySync } from "@dojoengine/react";
3-
import { Entity } from "@dojoengine/recs";
3+
import type { Entity } from "@dojoengine/recs";
44
import { getEntityIdFromKeys } from "@dojoengine/utils";
5+
import { KeysClause } from "@dojoengine/sdk";
56

67
import { useDojo } from "./dojo/useDojo";
78

@@ -18,7 +19,11 @@ function App() {
1819

1920
// sync the contract components to the local state
2021
// this fetches the entities from the world and updates the local state
21-
useQuerySync(toriiClient, contractComponents as any, []);
22+
useQuerySync(
23+
toriiClient,
24+
contractComponents as any,
25+
KeysClause([], [], "VariableLen").build()
26+
);
2227

2328
const [clipboardStatus, setClipboardStatus] = useState({
2429
message: "",

examples/example-vite-react-app-recs/src/dojo/setup.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { type DojoConfig, DojoProvider } from "@dojoengine/core";
22
import { BurnerManager } from "@dojoengine/create-burner";
33
import { getSyncEntities, getSyncEvents } from "@dojoengine/state";
4+
5+
import { KeysClause } from "@dojoengine/sdk";
46
import * as torii from "@dojoengine/torii-client";
57
import { Account, type ArraySignatureType } from "starknet";
68

@@ -26,8 +28,7 @@ export async function setup({ ...config }: DojoConfig) {
2628
const getSync = await getSyncEntities(
2729
toriiClient,
2830
contractComponents as any,
29-
undefined,
30-
[],
31+
KeysClause([], [], "VariableLen").build(),
3132
[],
3233
[],
3334
3000,
@@ -45,8 +46,7 @@ export async function setup({ ...config }: DojoConfig) {
4546
const eventSync = getSyncEvents(
4647
toriiClient,
4748
contractComponents as any,
48-
undefined,
49-
[],
49+
KeysClause([], [], "VariableLen").build(),
5050
[],
5151
[]
5252
);

examples/example-vite-react-app-recs/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"module": "ESNext",
66
"lib": ["ES2023", "DOM"],
77
"skipLibCheck": true,
8-
"moduleResolution": "node",
8+
"moduleResolution": "bundler",
99
"allowImportingTsExtensions": true,
1010
"resolveJsonModule": true,
1111
"isolatedModules": true,

examples/example-vite-react-phaser-recs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@dojoengine/react": "workspace:*",
1717
"@dojoengine/recs": "2.0.13",
1818
"@dojoengine/state": "workspace:*",
19+
"@dojoengine/sdk": "workspace:*",
1920
"@dojoengine/torii-client": "workspace:*",
2021
"@dojoengine/torii-wasm": "workspace:*",
2122
"@dojoengine/utils": "workspace:*",

examples/example-vite-react-phaser-recs/src/dojo/generated/setup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getSyncEntities } from "@dojoengine/state";
2+
import { KeysClause } from "@dojoengine/sdk";
23
import * as torii from "@dojoengine/torii-client";
34
import { createClientComponents } from "../createClientComponents";
45
import { createSystemCalls } from "../createSystemCalls";
@@ -28,7 +29,8 @@ export async function setup({ ...config }: DojoConfig) {
2829
const sync = await getSyncEntities(
2930
toriiClient,
3031
contractComponents as any,
31-
undefined,
32+
KeysClause([], [], "VariableLen").build(),
33+
3234
[]
3335
);
3436

examples/example-vite-react-phaser-recs/src/phaser/config/configurePhaser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
defineMapConfig,
66
defineCameraConfig,
77
} from "@latticexyz/phaserx";
8+
import * as Phaser from "phaser";
89
import { TileAnimations, Tileset } from "../../assets/world";
910
import {
1011
Sprites,

examples/example-vite-react-phaser-recs/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"lib": ["ES2023", "DOM"],
77
"skipLibCheck": true,
88
/* Bundler mode */
9-
"moduleResolution": "node",
9+
"moduleResolution": "bundler",
1010
"allowImportingTsExtensions": true,
1111
"resolveJsonModule": true,
1212
"isolatedModules": true,

examples/example-vite-react-pwa-recs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@dojoengine/create-burner": "workspace:*",
1919
"@dojoengine/react": "workspace:*",
2020
"@dojoengine/recs": "2.0.13",
21+
"@dojoengine/sdk": "workspace:*",
2122
"@dojoengine/state": "workspace:*",
2223
"@dojoengine/torii-client": "workspace:*",
2324
"@dojoengine/utils": "workspace:*",

0 commit comments

Comments
 (0)