Skip to content
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

fix: typedoc ci #365

Merged
merged 1 commit into from
Jan 2, 2025
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
50 changes: 35 additions & 15 deletions examples/example-vite-kitchen-sink/src/typescript/contracts.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,86 @@ import {
import * as models from "./models.gen";

export function setupWorld(provider: DojoProvider) {
const build_actions_incrementGlobalCounter_calldata = () => {
return {
contractName: "actions",
entrypoint: "increment_global_counter",
calldata: [],
};
};

const actions_incrementGlobalCounter = async (
snAccount: Account | AccountInterface
) => {
try {
return await provider.execute(
snAccount,
{
contractName: "actions",
entrypoint: "increment_global_counter",
calldata: [],
},
build_actions_incrementGlobalCounter_calldata(),
"onchain_dash"
);
} catch (error) {
console.error(error);
throw error;
}
};

const build_actions_incrementCallerCounter_calldata = () => {
return {
contractName: "actions",
entrypoint: "increment_caller_counter",
calldata: [],
};
};

const actions_incrementCallerCounter = async (
snAccount: Account | AccountInterface
) => {
try {
return await provider.execute(
snAccount,
{
contractName: "actions",
entrypoint: "increment_caller_counter",
calldata: [],
},
build_actions_incrementCallerCounter_calldata(),
"onchain_dash"
);
} catch (error) {
console.error(error);
throw error;
}
};

const build_actions_changeTheme_calldata = (value: CairoCustomEnum) => {
return {
contractName: "actions",
entrypoint: "change_theme",
calldata: [value],
};
};

const actions_changeTheme = async (
snAccount: Account | AccountInterface,
value: CairoCustomEnum
) => {
try {
return await provider.execute(
snAccount,
{
contractName: "actions",
entrypoint: "change_theme",
calldata: [value],
},
build_actions_changeTheme_calldata(value),
"onchain_dash"
);
} catch (error) {
console.error(error);
throw error;
}
};

return {
actions: {
incrementGlobalCounter: actions_incrementGlobalCounter,
buildIncrementGlobalCounterCalldata:
build_actions_incrementGlobalCounter_calldata,
incrementCallerCounter: actions_incrementCallerCounter,
buildIncrementCallerCounterCalldata:
build_actions_incrementCallerCounter_calldata,
changeTheme: actions_changeTheme,
buildChangeThemeCalldata: build_actions_changeTheme_calldata,
},
};
}
62 changes: 34 additions & 28 deletions packages/sdk/src/__example__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,44 +115,50 @@ async function exampleUsage() {
n.entity("player", (e) => e.eq("name", "Alice"))
);

db.subscribeEntityQuery(query.build(), (resp) => {
if (resp.error) {
console.error(
"Error querying todos and goals:",
resp.error.message
);
return;
}
if (resp.data) {
console.log(
"Queried todos and goals:",
resp.data.map((a) => a.models.world)
);
}
});
// Example usage of getEntities with where clause
try {
const eq = new QueryBuilder<MockSchemaType>().namespace("world", (n) =>
n
.entity("item", (e) =>
e.eq("type", "sword").lt("durability", 5)
)
.entity("game", (e) => e.eq("status", "completed"))
);
const entities = await db.getEntities(eq.build(), (resp) => {
db.subscribeEntityQuery({
query: query.build(),
callback: (resp) => {
if (resp.error) {
console.error(
"Error querying completed important todos:",
"Error querying todos and goals:",
resp.error.message
);
return;
}
if (resp.data) {
console.log(
"Completed important todos:",
resp.data.map((a) => a.models)
"Queried todos and goals:",
resp.data.map((a) => a.models.world)
);
}
},
});
// Example usage of getEntities with where clause
try {
const eq = new QueryBuilder<MockSchemaType>().namespace("world", (n) =>
n
.entity("item", (e) =>
e.eq("type", "sword").lt("durability", 5)
)
.entity("game", (e) => e.eq("status", "completed"))
);
const entities = await db.getEntities({
query: eq.build(),
callback: (resp) => {
if (resp.error) {
console.error(
"Error querying completed important todos:",
resp.error.message
);
return;
}
if (resp.data) {
console.log(
"Completed important todos:",
resp.data.map((a) => a.models)
);
}
},
});
console.log("Queried entities:", entities);
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/__tests__/parseEntities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe("parseEntities", () => {
};
const res = parseEntities(toriiResult);
const expected = new CairoOption(CairoOptionVariant.Some, 1734537235);
expect(res[0].models.onchain_dash.CallerCounter.timestamp).toEqual(
expect(res[0]?.models?.onchain_dash?.CallerCounter?.timestamp).toEqual(
expected
);
});
Expand Down Expand Up @@ -276,7 +276,7 @@ describe("parseEntities", () => {
};
const res = parseEntities<SchemaType>(toriiResult);
const expected = new CairoCustomEnum({ Predefined: "Dojo" });
expect(res[0].models.onchain_dash.Theme.value).toEqual(expected);
expect(res[0]?.models?.onchain_dash?.Theme?.value).toEqual(expected);
});

it("should parse enum with nested struct", () => {
Expand Down Expand Up @@ -333,6 +333,6 @@ describe("parseEntities", () => {
"0x0000000000000000000000000000000000000000637573746f6d5f636c617373",
},
});
expect(res[0].models.onchain_dash.Theme.value).toEqual(expected);
expect(res[0]?.models?.onchain_dash?.Theme?.value).toEqual(expected);
});
});
Loading