Skip to content

Commit 0c9cf79

Browse files
committed
feat: add order_by and entity_models to sdk
1 parent 424aa08 commit 0c9cf79

File tree

5 files changed

+59
-27
lines changed

5 files changed

+59
-27
lines changed

package.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
2-
"name": "dojo.js",
3-
"scripts": {
4-
"build": "bash ./scripts/build-packages.sh",
5-
"build-examples": "bash ./scripts/build-examples.sh",
6-
"clean": "bash ./scripts/clean.sh",
7-
"prettier-check": "npx prettier --check .",
8-
"prettier": "npx prettier --write .",
9-
"release": "pnpm build && pnpm prettier && npx lerna publish --no-private --force-publish",
10-
"docs": "npx typedoc --out docs",
11-
"prepare": "husky install"
12-
},
13-
"devDependencies": {
14-
"husky": "^9.1.6",
15-
"lerna": "^8.1.5",
16-
"prettier": "^3.3.3",
17-
"tsup": "^8.1.0",
18-
"typedoc": "^0.26.7",
19-
"@typhonjs-typedoc/typedoc-theme-dmt": "^0.2.1",
20-
"typedoc-plugin-coverage": "^3.3.0",
21-
"@commitlint/cli": "^18.4.4",
22-
"@commitlint/config-conventional": "^18.4.4",
23-
"@ianvs/prettier-plugin-sort-imports": "^4.3.1"
24-
}
2+
"name": "dojo.js",
3+
"scripts": {
4+
"build": "bash ./scripts/build-packages.sh",
5+
"build-examples": "bash ./scripts/build-examples.sh",
6+
"clean": "bash ./scripts/clean.sh",
7+
"prettier-check": "npx prettier --check {packages,examples}",
8+
"prettier": "npx prettier --write .",
9+
"release": "pnpm build && pnpm prettier && npx lerna publish --no-private --force-publish",
10+
"docs": "npx typedoc --out docs",
11+
"prepare": "husky install"
12+
},
13+
"devDependencies": {
14+
"husky": "^9.1.6",
15+
"lerna": "^8.1.5",
16+
"prettier": "^3.3.3",
17+
"tsup": "^8.1.0",
18+
"typedoc": "^0.26.7",
19+
"@typhonjs-typedoc/typedoc-theme-dmt": "^0.2.1",
20+
"typedoc-plugin-coverage": "^3.3.0",
21+
"@commitlint/cli": "^18.4.4",
22+
"@commitlint/config-conventional": "^18.4.4",
23+
"@ianvs/prettier-plugin-sort-imports": "^4.3.1"
24+
}
2525
}

packages/sdk/src/getEntities.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export async function getEntities<T extends SchemaType>(
3434
data?: StandardizedQueryResult<T>;
3535
error?: Error;
3636
}) => void,
37+
orderBy: torii.OrderBy[] = [],
38+
entityModels: string[] = [],
3739
limit: number = 100, // Default limit
3840
offset: number = 0, // Default offset
3941
options?: { logging?: boolean } // Logging option
@@ -46,8 +48,10 @@ export async function getEntities<T extends SchemaType>(
4648

4749
while (continueFetching) {
4850
const toriiQuery: torii.Query = {
49-
limit: limit,
51+
limit,
5052
offset: cursor,
53+
order_by: orderBy,
54+
entity_models: entityModels,
5155
clause,
5256
dont_include_hashed_keys: false,
5357
};

packages/sdk/src/getEventMessages.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export async function getEventMessages<T extends SchemaType>(
3434
data?: StandardizedQueryResult<T>;
3535
error?: Error;
3636
}) => void,
37+
orderBy: torii.OrderBy[] = [],
38+
entityModels: string[] = [],
3739
limit: number = 100, // Default limit
3840
offset: number = 0, // Default offset
3941
options?: { logging?: boolean } // Logging option
@@ -46,8 +48,10 @@ export async function getEventMessages<T extends SchemaType>(
4648

4749
while (continueFetching) {
4850
const toriiQuery: torii.Query = {
49-
limit: limit,
51+
limit,
5052
offset: cursor,
53+
order_by: orderBy,
54+
entity_models: entityModels,
5155
clause,
5256
dont_include_hashed_keys: false,
5357
};

packages/sdk/src/index.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,22 @@ export async function init<T extends SchemaType>(
6161
* @param {GetParams<T>} params - Parameters object
6262
* @returns {Promise<StandardizedQueryResult<T>>} - A promise that resolves to the standardized query result.
6363
*/
64-
getEntities: ({ query, callback, limit, offset, options }) =>
64+
getEntities: ({
65+
query,
66+
callback,
67+
orderBy,
68+
entityModels,
69+
limit,
70+
offset,
71+
options,
72+
}) =>
6573
getEntities(
6674
client,
6775
query,
6876
schema,
6977
callback,
78+
orderBy,
79+
entityModels,
7080
limit,
7181
offset,
7282
options
@@ -77,12 +87,22 @@ export async function init<T extends SchemaType>(
7787
* @param {GetParams<T>} params - Parameters object
7888
* @returns {Promise<StandardizedQueryResult<T>>} - A promise that resolves to the standardized query result.
7989
*/
80-
getEventMessages: ({ query, callback, limit, offset, options }) =>
90+
getEventMessages: ({
91+
query,
92+
callback,
93+
orderBy,
94+
entityModels,
95+
limit,
96+
offset,
97+
options,
98+
}) =>
8199
getEventMessages(
82100
client,
83101
query,
84102
schema,
85103
callback,
104+
orderBy,
105+
entityModels,
86106
limit,
87107
offset,
88108
options

packages/sdk/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ export interface GetParams<T extends SchemaType> {
366366
data?: StandardizedQueryResult<T>;
367367
error?: Error;
368368
}) => void;
369+
// The order to sort the entities by.
370+
orderBy?: torii.OrderBy[];
371+
// The models to whitelist for fetching. Leave this empty to fetch all models.
372+
entityModels?: string[];
369373
// The maximum number of entities to fetch per request. Default is 100.
370374
limit?: number;
371375
// The offset to start fetching entities from. Default is 0.

0 commit comments

Comments
 (0)