Skip to content

Commit bfc08b6

Browse files
authored
Merge pull request #424 from dojoengine/feat/bump-dojo131
feat: add specific control param to query torii types
2 parents 7d2a6b7 + ff6eb12 commit bfc08b6

File tree

28 files changed

+2237
-1679
lines changed

28 files changed

+2237
-1679
lines changed

.changeset/dry-rivers-give.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@dojoengine/predeployed-connector": patch
3+
"@dojoengine/create-burner": patch
4+
"@dojoengine/torii-client": patch
5+
"@dojoengine/create-dojo": patch
6+
"@dojoengine/torii-wasm": patch
7+
"@dojoengine/react": patch
8+
"@dojoengine/state": patch
9+
"@dojoengine/utils": patch
10+
"@dojoengine/core": patch
11+
"@dojoengine/sdk": patch
12+
"@dojoengine/utils-wasm": patch
13+
---
14+
15+
chore: bump dojo 1.3.1

.changeset/moody-rats-shake.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@dojoengine/sdk": patch
3+
---
4+
5+
feat: add way to create specific types to query torii

.github/workflows/ci.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14+
with:
15+
submodules: true
1416
- uses: oven-sh/setup-bun@v1
1517
- uses: actions-rust-lang/setup-rust-toolchain@v1
1618
with:
@@ -41,9 +43,6 @@ jobs:
4143
restore-keys: |
4244
${{ runner.os }}-cargo-
4345
44-
- name: Update Submodules
45-
run: git submodule update --init --recursive
46-
4746
- run: curl -L https://install.dojoengine.org | bash
4847
- uses: software-mansion/setup-scarb@v1
4948
with:

.github/workflows/docs.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v4
19+
with:
20+
submodules: true
1921
- uses: pnpm/action-setup@v2
2022
with:
2123
version: 10.0.0
@@ -30,9 +32,6 @@ jobs:
3032
restore-keys: |
3133
${{ runner.os }}-turbo-
3234
33-
- name: Update Submodules
34-
run: git submodule update --init --recursive
35-
3635
- name: Install Protobuf Compiler
3736
run: sudo apt-get install -y protobuf-compiler
3837

.github/workflows/release.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
steps:
2020
- uses: actions/checkout@v4
2121
with:
22-
fetch-depth: 0
22+
submodules: true
2323

2424
- uses: pnpm/action-setup@v3
2525
with:
@@ -71,9 +71,6 @@ jobs:
7171
restore-keys: |
7272
${{ runner.os }}-cargo-
7373
74-
- name: Update Submodules
75-
run: git submodule update --init --recursive
76-
7774
- run: curl -L https://install.dojoengine.org | bash
7875
- uses: software-mansion/setup-scarb@v1
7976
with:

.gitmodules

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[submodule "worlds/onchain-dash"]
22
path = worlds/onchain-dash
33
url = https://github.com/MartianGreed/onchain-dash
4-
ignore = dirty
4+
ignore = dirty
55
[submodule "worlds/dojo-starter"]
66
path = worlds/dojo-starter
77
url = https://github.com/dojoengine/dojo-starter
8-
ignore = dirty
8+
ignore = dirty
99
[submodule "packages/torii-wasm/dojo.c"]
1010
path = packages/torii-wasm/dojo.c
1111
url = https://github.com/dojoengine/dojo.c.git
12+
ignore = dirty

examples/example-predeployed-connector/src/starknet-provider.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default function StarknetProvider({ children }: PropsWithChildren) {
2323
explorer={voyager}
2424
autoConnect
2525
>
26+
{/* @ts-ignore */}
2627
{children}
2728
</StarknetConfig>
2829
);

examples/example-vite-kitchen-sink/package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,28 @@
3434
"jiti": "^1.21.7",
3535
"lucide-react": "^0.441.0",
3636
"next": "14.2.12",
37-
"react": "^18.3.1",
38-
"react-dom": "^18.3.1",
37+
"react": "catalog:",
38+
"react-dom": "catalog:",
3939
"react-hook-form": "^7.54.2",
4040
"starknet": "catalog:",
4141
"tailwind-merge": "^2.6.0",
4242
"tailwindcss-animate": "^1.0.7",
4343
"vaul": "^0.9.9",
44-
"zod": "^3.24.1"
44+
"zod": "^3.24.2"
4545
},
4646
"devDependencies": {
47-
"@types/node": "^20.17.17",
48-
"@types/react": "^18.3.18",
49-
"@types/react-dom": "^18.3.5",
47+
"@types/node": "^20.17.27",
48+
"@types/react": "catalog:",
49+
"@types/react-dom": "catalog:",
5050
"@vitejs/plugin-react": "^4.3.4",
5151
"eslint": "^8.57.1",
5252
"eslint-config-next": "14.2.12",
53-
"postcss": "^8.5.1",
53+
"postcss": "^8.5.3",
5454
"tailwindcss": "^3.4.17",
55-
"typescript": "^5.7.3",
56-
"vite": "^6.1.0",
57-
"vite-plugin-mkcert": "^1.17.6",
58-
"vite-plugin-top-level-await": "^1.4.4",
55+
"typescript": "^5.8.2",
56+
"vite": "^6.2.3",
57+
"vite-plugin-mkcert": "^1.17.8",
58+
"vite-plugin-top-level-await": "^1.5.0",
5959
"vite-plugin-wasm": "^3.4.1",
6060
"vite-preset-react": "^2.3.0"
6161
}

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
DropdownMenuTrigger,
2222
} from "@/components/ui/dropdown";
2323
import { CairoCustomEnum } from "starknet";
24-
import { useDojoSDK } from "@dojoengine/sdk/react";
24+
import { useDojoSDK, useEntityId } from "@dojoengine/sdk/react";
2525
import { setupWorld } from "@/typescript/contracts.gen";
2626

2727
interface ThemeState {
@@ -50,7 +50,7 @@ export default function ThemeSwitchButton() {
5050
next: null,
5151
});
5252
const [isLoading, setIsLoading] = useState(false);
53-
const [entityId, setEntityId] = useState<string | null>(null);
53+
const entityId = useEntityId(9999999);
5454
const { account } = useAccount();
5555
const [sub, setSub] = useState<Subscription | null>(null);
5656
const { sdk: db, client: actions } = useDojoSDK<
@@ -120,8 +120,7 @@ export default function ThemeSwitchButton() {
120120
setSub(sub);
121121

122122
const theme =
123-
initialTheme[0].models?.onchain_dash?.Theme?.value?.unwrap();
124-
setEntityId(initialTheme[0].entityId);
123+
initialTheme[0]?.models?.onchain_dash?.Theme?.value?.unwrap();
125124
let th = null;
126125
if (undefined === theme) {
127126
th = AvailableTheme.Light;

examples/example-vite-react-sql/src/components/playground/direction-count.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { SchemaType } from "@/typescript/models.gen";
2-
import { DojoContext } from "@dojoengine/sdk/react";
2+
import { useDojoSDK } from "@dojoengine/sdk/react";
33
import { useToriiSQLQuery } from "@dojoengine/sdk/sql";
44
import { useQueryClient } from "@tanstack/react-query";
5-
import { useContext } from "react";
65

76
type QueryResponse = Array<{
87
count: number;
@@ -41,8 +40,9 @@ function formatFn(rows: QueryResponse): DirectionCount {
4140

4241
export function DirectionCount() {
4342
// use queryClient to invalidateQuery when state is changing.
44-
const { useDojoStore } = useContext(DojoContext);
43+
const { useDojoStore } = useDojoSDK();
4544
const queryClient = useQueryClient();
45+
// @ts-expect-error it's ok if I dont use this variable compiler, react needs it
4646
useDojoStore.subscribe(
4747
(s: SchemaType) => s.entities,
4848
() => {

packages/core/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
"@dojoengine/torii-client": "workspace:*",
2525
"@types/elliptic": "^6.4.18",
2626
"@vitest/coverage-v8": "^1.6.0",
27-
"tsup": "^8.3.0",
27+
"tsup": "^8.3.5",
2828
"typescript": "^5.6.2",
2929
"vitest": "^1.6.0"
3030
},
3131
"dependencies": {
3232
"@dojoengine/recs": "2.0.13",
33-
"zod": "^3.23.8",
34-
"starknet": "catalog:"
33+
"starknet": "catalog:",
34+
"zod": "^3.23.8"
3535
},
3636
"bin": {
3737
"create-components": "./dist/bin/generateComponents.cjs"

packages/create-burner/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@types/web": "^0.0.114",
4040
"@vitest/coverage-v8": "^1.6.0",
4141
"jsdom": "^24.1.3",
42-
"tsup": "^8.3.0",
42+
"tsup": "^8.3.5",
4343
"typescript": "^5.6.2",
4444
"vitest": "^1.6.0"
4545
},

packages/create-dojo/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@types/cross-spawn": "^6.0.6",
3939
"@types/js-yaml": "^4.0.9",
4040
"@types/node-fetch": "^2.6.12",
41-
"tsup": "^8.3.0",
41+
"tsup": "^8.3.5",
4242
"typescript": "^5.6.2",
4343
"vitest": "^2.1.1"
4444
}

packages/predeployed-connector/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@
2929
},
3030
"devDependencies": {
3131
"@rollup/plugin-commonjs": "^28.0.0",
32-
"@vitest/coverage-v8": "^1.6.0",
3332
"@types/react": "catalog:",
3433
"@types/react-dom": "catalog:",
34+
"@vitest/coverage-v8": "^1.6.0",
3535
"eslint": "^8.57.1",
3636
"prettier": "^2.8.8",
37-
"tsup": "^8.3.0",
37+
"tsup": "^8.4.0",
3838
"typescript": "^5.6.2",
3939
"vite": "^3.2.11",
4040
"vitest": "^1.6.0"
4141
},
4242
"peerDependencies": {
4343
"@starknet-react/core": "catalog:",
44-
"starknet": "catalog:",
4544
"react": "catalog:",
46-
"react-dom": "catalog:"
45+
"react-dom": "catalog:",
46+
"starknet": "catalog:"
4747
},
4848
"repository": {
4949
"type": "git",

packages/react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@types/react": "^18.3.9",
3535
"@types/react-dom": "^18.3.0",
3636
"@types/web": "^0.0.114",
37-
"tsup": "^8.3.0",
37+
"tsup": "^8.3.5",
3838
"typescript": "^5.6.2"
3939
},
4040
"dependencies": {

packages/sdk/src/__tests__/convertClauseToEntityKeysClause.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe("convertClauseToEntityKeysClause", () => {
2020
]);
2121
});
2222

23-
it("HashedKeys has priority over keys", () => {
23+
it("if keys clause and HashedKeys are present, keys has priority", () => {
2424
const clause = new ClauseBuilder()
2525
.keys(["dojo_starter-Position"], ["0x123"])
2626
.build();
@@ -33,7 +33,11 @@ describe("convertClauseToEntityKeysClause", () => {
3333
])
3434
).toEqual([
3535
{
36-
HashedKeys: ["0xentityHashedKey"],
36+
Keys: {
37+
keys: ["0x123"],
38+
pattern_matching: "VariableLen",
39+
models: ["dojo_starter-Position"],
40+
},
3741
},
3842
]);
3943
});

packages/sdk/src/clauseBuilder.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
PatternMatching,
66
} from "@dojoengine/torii-client";
77

8-
import { convertToPrimitive } from "./convertToMemberValue";
8+
import { convertToPrimitive, MemberValueParam } from "./convertToMemberValue";
99
import { SchemaType } from "./types";
1010

1111
type ClauseBuilderInterface = {
@@ -66,7 +66,10 @@ export function MemberClause<
6666
model: Path,
6767
member: M & string,
6868
operator: ComparisonOperator,
69-
value: GetModelType<T, Path>[M] | GetModelType<T, Path>[M][]
69+
value:
70+
| GetModelType<T, Path>[M]
71+
| GetModelType<T, Path>[M][]
72+
| MemberValueParam
7073
): ClauseBuilder<T> {
7174
return new ClauseBuilder<T>().where(model, member, operator, value);
7275
}
@@ -132,7 +135,10 @@ export class ClauseBuilder<T extends SchemaType> {
132135
model: Path,
133136
member: M & string,
134137
operator: ComparisonOperator,
135-
value: GetModelType<T, Path>[M] | GetModelType<T, Path>[M][]
138+
value:
139+
| GetModelType<T, Path>[M]
140+
| GetModelType<T, Path>[M][]
141+
| MemberValueParam
136142
): ClauseBuilder<T> {
137143
const memberValue: MemberValue = Array.isArray(value)
138144
? { List: value.map(convertToPrimitive) }

packages/sdk/src/convertClauseToEntityKeysClause.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ export function intoEntityKeysClause<T extends SchemaType>(
99
if (!clause) {
1010
return [];
1111
}
12+
13+
// if we have keys clause, we can move forward to query those keys directly
14+
if (Object.hasOwn(clause, "Keys")) {
15+
return [clause as unknown as EntityKeysClause];
16+
}
17+
1218
// if we have initial wih query.dont_include_hash_keys = false
1319
// we can move forward to query those hashed keys directly
1420
if (initialData && initialData.length > 0) {
1521
return [{ HashedKeys: initialData.map((e) => e.entityId) }];
1622
}
1723

18-
if (Object.hasOwn(clause, "Keys")) {
19-
return [clause as unknown as EntityKeysClause];
20-
}
21-
2224
// We want to avoid those kind of weird cases where we are guessing what data should be retrieved
2325
if (
2426
(Object.hasOwn(clause, "Member") ||

packages/sdk/src/convertToMemberValue.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import * as torii from "@dojoengine/torii-client";
22

3+
type ToUnion<T> = T extends infer U ? U : never;
4+
type ExtractPrimitiveKeys<T> = T extends Record<infer K, any> ? K : never;
5+
type PrimitiveTypeKeys = ToUnion<ExtractPrimitiveKeys<torii.Primitive>>;
6+
7+
export type MemberValueParam = { type: PrimitiveTypeKeys; value: any } | any;
8+
39
/**
410
* Converts a value to a Torii primitive type.
511
*
6-
* @param {any} value - The value to convert.
12+
* @param {MemberValue} value - The value to convert.
713
* @returns {torii.MemberValue} - The converted primitive value.
814
* @throws {Error} - If the value type is unsupported.
915
*/
10-
export function convertToPrimitive(value: any): torii.MemberValue {
16+
export function convertToPrimitive(value: MemberValueParam): torii.MemberValue {
17+
// if you want to have more control over type passed to torii
18+
if (Object.hasOwn(value, "type") && Object.hasOwn(value, "value")) {
19+
return { Primitive: { [value.type]: value.value } as torii.Primitive };
20+
}
21+
1122
if (typeof value === "number") {
1223
return { Primitive: { U32: value } };
1324
} else if (typeof value === "boolean") {

0 commit comments

Comments
 (0)