Skip to content

Commit

Permalink
feat: add order_by and entity_models to sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
MartianGreed committed Dec 13, 2024
1 parent 424aa08 commit 0c9cf79
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 27 deletions.
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "dojo.js",
"scripts": {
"build": "bash ./scripts/build-packages.sh",
"build-examples": "bash ./scripts/build-examples.sh",
"clean": "bash ./scripts/clean.sh",
"prettier-check": "npx prettier --check .",
"prettier": "npx prettier --write .",
"release": "pnpm build && pnpm prettier && npx lerna publish --no-private --force-publish",
"docs": "npx typedoc --out docs",
"prepare": "husky install"
},
"devDependencies": {
"husky": "^9.1.6",
"lerna": "^8.1.5",
"prettier": "^3.3.3",
"tsup": "^8.1.0",
"typedoc": "^0.26.7",
"@typhonjs-typedoc/typedoc-theme-dmt": "^0.2.1",
"typedoc-plugin-coverage": "^3.3.0",
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@ianvs/prettier-plugin-sort-imports": "^4.3.1"
}
"name": "dojo.js",
"scripts": {
"build": "bash ./scripts/build-packages.sh",
"build-examples": "bash ./scripts/build-examples.sh",
"clean": "bash ./scripts/clean.sh",
"prettier-check": "npx prettier --check {packages,examples}",
"prettier": "npx prettier --write .",
"release": "pnpm build && pnpm prettier && npx lerna publish --no-private --force-publish",
"docs": "npx typedoc --out docs",
"prepare": "husky install"
},
"devDependencies": {
"husky": "^9.1.6",
"lerna": "^8.1.5",
"prettier": "^3.3.3",
"tsup": "^8.1.0",
"typedoc": "^0.26.7",
"@typhonjs-typedoc/typedoc-theme-dmt": "^0.2.1",
"typedoc-plugin-coverage": "^3.3.0",
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@ianvs/prettier-plugin-sort-imports": "^4.3.1"
}
}
6 changes: 5 additions & 1 deletion packages/sdk/src/getEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export async function getEntities<T extends SchemaType>(
data?: StandardizedQueryResult<T>;
error?: Error;
}) => void,
orderBy: torii.OrderBy[] = [],
entityModels: string[] = [],
limit: number = 100, // Default limit
offset: number = 0, // Default offset
options?: { logging?: boolean } // Logging option
Expand All @@ -46,8 +48,10 @@ export async function getEntities<T extends SchemaType>(

while (continueFetching) {
const toriiQuery: torii.Query = {
limit: limit,
limit,
offset: cursor,
order_by: orderBy,
entity_models: entityModels,
clause,
dont_include_hashed_keys: false,
};
Expand Down
6 changes: 5 additions & 1 deletion packages/sdk/src/getEventMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export async function getEventMessages<T extends SchemaType>(
data?: StandardizedQueryResult<T>;
error?: Error;
}) => void,
orderBy: torii.OrderBy[] = [],
entityModels: string[] = [],
limit: number = 100, // Default limit
offset: number = 0, // Default offset
options?: { logging?: boolean } // Logging option
Expand All @@ -46,8 +48,10 @@ export async function getEventMessages<T extends SchemaType>(

while (continueFetching) {
const toriiQuery: torii.Query = {
limit: limit,
limit,
offset: cursor,
order_by: orderBy,
entity_models: entityModels,
clause,
dont_include_hashed_keys: false,
};
Expand Down
24 changes: 22 additions & 2 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,22 @@ export async function init<T extends SchemaType>(
* @param {GetParams<T>} params - Parameters object
* @returns {Promise<StandardizedQueryResult<T>>} - A promise that resolves to the standardized query result.
*/
getEntities: ({ query, callback, limit, offset, options }) =>
getEntities: ({
query,
callback,
orderBy,
entityModels,
limit,
offset,
options,
}) =>
getEntities(
client,
query,
schema,
callback,
orderBy,
entityModels,
limit,
offset,
options
Expand All @@ -77,12 +87,22 @@ export async function init<T extends SchemaType>(
* @param {GetParams<T>} params - Parameters object
* @returns {Promise<StandardizedQueryResult<T>>} - A promise that resolves to the standardized query result.
*/
getEventMessages: ({ query, callback, limit, offset, options }) =>
getEventMessages: ({
query,
callback,
orderBy,
entityModels,
limit,
offset,
options,
}) =>
getEventMessages(
client,
query,
schema,
callback,
orderBy,
entityModels,
limit,
offset,
options
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ export interface GetParams<T extends SchemaType> {
data?: StandardizedQueryResult<T>;
error?: Error;
}) => void;
// The order to sort the entities by.
orderBy?: torii.OrderBy[];
// The models to whitelist for fetching. Leave this empty to fetch all models.
entityModels?: string[];
// The maximum number of entities to fetch per request. Default is 100.
limit?: number;
// The offset to start fetching entities from. Default is 0.
Expand Down

0 comments on commit 0c9cf79

Please sign in to comment.