Skip to content

Commit fc221a1

Browse files
feat: types
1 parent 0abea55 commit fc221a1

File tree

8 files changed

+29
-30
lines changed

8 files changed

+29
-30
lines changed

examples/clients/react/react-sdk/src/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function App() {
2323
{
2424
dojo_starter: {
2525
Position: [],
26-
// Moves: ["player"],
26+
Moves: ["player"],
2727
},
2828
},
2929
(response) => {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("convertQueryToEntityKeyClauses", () => {
5050
it("should convert query with namespace and model set to true to VariableLen Keys clause", () => {
5151
const query: SubscriptionQueryType<MockSchemaType> = {
5252
world: {
53-
player: true,
53+
player: [],
5454
},
5555
};
5656
const result = convertQueryToEntityKeyClauses(query);
@@ -88,7 +88,7 @@ describe("convertQueryToEntityKeyClauses", () => {
8888
it("should handle multiple namespaces and models", () => {
8989
const query: SubscriptionQueryType<MockSchemaType> = {
9090
world: {
91-
player: true,
91+
player: [],
9292
item: ["id", "type"],
9393
},
9494
entityIds: ["hash1"],
@@ -118,7 +118,7 @@ describe("convertQueryToEntityKeyClauses", () => {
118118
const query: SubscriptionQueryType<MockSchemaType> = {
119119
entityIds: [],
120120
world: {
121-
player: true,
121+
player: [],
122122
},
123123
} as unknown as SubscriptionQueryType<MockSchemaType>;
124124
const result = convertQueryToEntityKeyClauses(query);
@@ -137,7 +137,7 @@ describe("convertQueryToEntityKeyClauses", () => {
137137
it("should handle multiple models within a single namespace", () => {
138138
const query: SubscriptionQueryType<MockSchemaType> = {
139139
world: {
140-
player: true,
140+
player: [],
141141
item: ["id", "type"],
142142
},
143143
};

packages/sdk/src/convertQueryToEntityKeyClauses.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function convertQueryToEntityKeyClauses<T extends SchemaType>(
2525
Object.entries(namespaces).forEach(([namespace, models]) => {
2626
if (models && typeof models === "object") {
2727
Object.entries(models).forEach(([model, value]) => {
28-
if (typeof value === "boolean" || Array.isArray(value)) {
28+
if (Array.isArray(value)) {
2929
const namespaceModel = `${namespace}-${model}`;
3030
const clause = createClause(namespaceModel, value);
3131
if (clause) {
@@ -47,9 +47,9 @@ export function convertQueryToEntityKeyClauses<T extends SchemaType>(
4747
*/
4848
function createClause(
4949
namespaceModel: string,
50-
value: boolean | string[]
50+
value: string[]
5151
): torii.EntityKeysClause | undefined {
52-
if (value === true) {
52+
if (Array.isArray(value) && value.length === 0) {
5353
return {
5454
Keys: {
5555
keys: [undefined],

packages/sdk/src/getEntities.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ export async function getEntities<T extends SchemaType>(
3939
): Promise<StandardizedQueryResult<T>> {
4040
const clause = convertQueryToClause(query);
4141

42-
console.log("clause", clause, query);
43-
4442
let cursor = offset;
4543
let continueFetching = true;
4644
let allEntities: torii.Entities = {};
@@ -55,8 +53,8 @@ export async function getEntities<T extends SchemaType>(
5553
try {
5654
const entities = await client.getEntities(toriiQuery);
5755

58-
console.log("entities", entities);
5956
if (options?.logging) {
57+
console.log("Clause", clause, "Query", query);
6058
console.log(`Fetched entities at offset ${cursor}:`, entities);
6159
}
6260

packages/sdk/src/getEventMessages.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { StandardizedQueryResult, QueryType } from "./types";
1+
import * as torii from "@dojoengine/torii-client";
2+
3+
import { StandardizedQueryResult, QueryType, SchemaType } from "./types";
24
import { convertQueryToClause } from "./convertQuerytoClause";
35
import { parseEntities } from "./parseEntities";
4-
import { SchemaType } from "./types";
5-
import * as torii from "@dojoengine/torii-client";
66

77
/**
88
* Fetches event messages from the Torii client based on the provided query.
@@ -43,12 +43,9 @@ export async function getEventMessages<T extends SchemaType>(
4343
clause,
4444
};
4545

46-
console.log(toriiQuery);
47-
4846
try {
4947
const entities = await client.getEventMessages(toriiQuery);
5048

51-
console.log("entities", entities);
5249
if (options?.logging) {
5350
console.log(`Fetched entities at offset ${cursor}:`, entities);
5451
}
@@ -57,8 +54,6 @@ export async function getEventMessages<T extends SchemaType>(
5754

5855
const parsedEntities = parseEntities<T>(allEntities);
5956

60-
console.log("parsedEntities", parsedEntities);
61-
6257
callback({ data: parsedEntities });
6358

6459
if (Object.keys(entities).length < limit) {

packages/sdk/src/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ export async function init<T extends SchemaType>(
2525
subscribeEntityQuery(client, query, callback),
2626
subscribeEventQuery: (query, callback) =>
2727
subscribeEventQuery(client, query, callback),
28-
getEntities: (query, callback) => getEntities(client, query, callback),
29-
getEventMessages: (query, callback) =>
30-
getEventMessages(client, query, callback),
28+
getEntities: (query, callback, limit, offset, options) =>
29+
getEntities(client, query, callback, limit, offset, options),
30+
getEventMessages: (query, callback, limit, offset, options) =>
31+
getEventMessages(client, query, callback, limit, offset, options),
3132
};
3233
}
3334
// // EXAMPLE FOR NOW

packages/sdk/src/subscribeEntityQuery.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ export async function subscribeEntityQuery<T extends SchemaType>(
3535
}) => void,
3636
options?: { logging?: boolean }
3737
): Promise<torii.Subscription> {
38-
console.log(
39-
"convertQueryToEntityKeyClauses",
40-
convertQueryToEntityKeyClauses(query)
41-
);
4238
return client.onEntityUpdated(
4339
convertQueryToEntityKeyClauses(query),
4440
(entityId: string, entityData: any) => {
@@ -48,6 +44,10 @@ export async function subscribeEntityQuery<T extends SchemaType>(
4844
[entityId]: entityData,
4945
});
5046
if (options?.logging) {
47+
console.log(
48+
"Converted query to entity key clauses:",
49+
convertQueryToEntityKeyClauses(query)
50+
);
5151
console.log("Parsed entity data:", parsedData);
5252
}
5353
callback({ data: parsedData });

packages/sdk/src/types.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export type SubscriptionQueryType<T extends SchemaType> = {
6868
entityIds?: string[];
6969
} & {
7070
[Entity in keyof T]?: {
71-
[Model in keyof T[Entity]]?: true | (keyof T[Entity][Model])[];
71+
[Model in keyof T[Entity]]?: (keyof T[Entity][Model])[];
7272
};
7373
};
7474

@@ -192,9 +192,11 @@ export interface SDK<T extends SchemaType> {
192192
callback: (response: {
193193
data?: StandardizedQueryResult<T>;
194194
error?: Error;
195-
}) => void
195+
}) => void,
196+
limit?: number,
197+
offset?: number,
198+
options?: { logging?: boolean } // Logging option
196199
) => Promise<StandardizedQueryResult<T>>;
197-
198200
/**
199201
* Fetches event messages from the Torii client based on the provided query.
200202
*
@@ -212,6 +214,9 @@ export interface SDK<T extends SchemaType> {
212214
callback: (response: {
213215
data?: StandardizedQueryResult<T>;
214216
error?: Error;
215-
}) => void
217+
}) => void,
218+
limit?: number,
219+
offset?: number,
220+
options?: { logging?: boolean } // Logging option
216221
) => Promise<StandardizedQueryResult<T>>;
217222
}

0 commit comments

Comments
 (0)