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: sdk function params refac to object param #337

Merged
merged 1 commit into from
Nov 26, 2024
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
35 changes: 13 additions & 22 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,26 @@ export async function init<T extends SchemaType>(
/**
* Subscribes to entity queries.
*
* @param {SubscriptionQueryType<T>} query - The query object used to filter entities.
* @param {(response: { data?: StandardizedQueryResult<T>; error?: Error }) => void} callback - The callback function to handle the response.
* @param {{ logging?: boolean }} [options] - Optional settings.
* @param {SubscribeParams<T>} params - Parameters object
* @returns {Promise<void>} - A promise that resolves when the subscription is set up.
*/
subscribeEntityQuery: (query, callback, options) =>
subscribeEntityQuery: ({ query, callback, options }) =>
subscribeEntityQuery(client, query, schema, callback, options),
/**
* Subscribes to event queries.
*
* @param {SubscriptionQueryType<T>} query - The query object used to filter events.
* @param {(response: { data?: StandardizedQueryResult<T>; error?: Error }) => void} callback - The callback function to handle the response.
* @param {{ logging?: boolean }} [options] - Optional settings.
* @param {SubscribeParams<T>} params - Parameters object
* @returns {Promise<void>} - A promise that resolves when the subscription is set up.
*/
subscribeEventQuery: (query, callback, options) =>
subscribeEventQuery: ({ query, callback, options }) =>
subscribeEventQuery(client, query, schema, callback, options),
/**
* Fetches entities based on the provided query.
*
* @param {SubscriptionQueryType<T>} query - The query object used to filter entities.
* @param {(response: { data?: StandardizedQueryResult<T>; error?: Error }) => void} callback - The callback function to handle the response.
* @param {number} [limit=100] - The maximum number of entities to fetch per request. Default is 100.
* @param {number} [offset=0] - The offset to start fetching entities from. Default is 0.
* @param {{ logging?: boolean }} [options] - Optional settings.
* @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, limit, offset, options }) =>
getEntities(
client,
query,
Expand All @@ -81,14 +73,10 @@ export async function init<T extends SchemaType>(
/**
* Fetches event messages based on the provided query.
*
* @param {SubscriptionQueryType<T>} query - The query object used to filter event messages.
* @param {(response: { data?: StandardizedQueryResult<T>; error?: Error }) => void} callback - The callback function to handle the response.
* @param {number} [limit=100] - The maximum number of event messages to fetch per request. Default is 100.
* @param {number} [offset=0] - The offset to start fetching event messages from. Default is 0.
* @param {{ logging?: boolean }} [options] - Optional settings.
* @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, limit, offset, options }) =>
getEventMessages(
client,
query,
Expand Down Expand Up @@ -139,12 +127,14 @@ export async function init<T extends SchemaType>(
*
* @param {TypedData} data - The typed data to be signed and sent.
* @param {Account} account - The account used to sign the message.
* @param {boolean} [isSessionSignature=false] - Whether the signature is a session signature.
* @returns {Promise<void>} - A promise that resolves when the message is sent successfully.
* @throws {Error} If the message sending fails.
*/
sendMessage: async (
data: TypedData,
account: Account
account: Account,
isSessionSignature: boolean = false
): Promise<void> => {
try {
// Sign the typed data
Expand All @@ -157,7 +147,8 @@ export async function init<T extends SchemaType>(
dataString,
Array.isArray(signature)
? signature
: [signature.r.toString(), signature.s.toString()]
: [signature.r.toString(), signature.s.toString()],
isSessionSignature
);
} catch (error) {
console.error("Failed to send message:", error);
Expand Down
86 changes: 41 additions & 45 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,80 +263,43 @@ export interface SDK<T extends SchemaType> {
* Subscribes to entity updates based on the provided query and invokes the callback with the updated data.
*
* @template T - The schema type.
* @param {SubscriptionQueryType<T>} [query] - The subscription query to filter the entities.
* @param {(response: { data?: StandardizedQueryResult<T>; error?: Error }) => void} [callback] - The callback function to handle the response.
* @param {SubscribeParams<T>} params - Parameters object
* @returns {Promise<torii.Subscription>} - A promise that resolves to a Torii subscription.
*/
subscribeEntityQuery: (
query: SubscriptionQueryType<T>,
callback: (response: {
data?: StandardizedQueryResult<T>;
error?: Error;
}) => void,
options?: { logging?: boolean }
params: SubscribeParams<T>
) => Promise<torii.Subscription>;

/**
* Subscribes to event messages based on the provided query and invokes the callback with the updated data.
*
* @template T - The schema type.
* @param {SubscriptionQueryType<T>} [query] - The subscription query to filter the events.
* @param {SubscribeParams<T>} params - Parameters object
* @param {(response: { data?: StandardizedQueryResult<T>; error?: Error }) => void} [callback] - The callback function to handle the response.
* @returns {Promise<torii.Subscription>} - A promise that resolves to a Torii subscription.
*/
subscribeEventQuery: (
query: SubscriptionQueryType<T>,
callback: (response: {
data?: StandardizedQueryResult<T>;
error?: Error;
}) => void,
options?: { logging?: boolean }
params: SubscribeParams<T>
) => Promise<torii.Subscription>;

/**
* Fetches entities from the Torii client based on the provided query.
*
* @template T - The schema type.
* @param {QueryType<T>} query - The query object used to filter entities.
* @param {(response: { data?: StandardizedQueryResult<T>; error?: Error }) => void} callback - The callback function to handle the response.
* @param {number} [limit=100] - The maximum number of entities to fetch per request. Default is 100.
* @param {number} [offset=0] - The offset to start fetching entities from. Default is 0.
* @param {{ logging?: boolean }} [options] - Optional settings.
* @param {boolean} [options.logging] - If true, enables logging of the fetching process. Default is false.
* @param {GetParams<T>} params - Parameters object
* @returns {Promise<StandardizedQueryResult<T>>} - A promise that resolves to the standardized query result.
*/
getEntities: (
query: QueryType<T>,
callback: (response: {
data?: StandardizedQueryResult<T>;
error?: Error;
}) => void,
limit?: number,
offset?: number,
options?: { logging?: boolean }
) => Promise<StandardizedQueryResult<T>>;
getEntities: (params: GetParams<T>) => Promise<StandardizedQueryResult<T>>;

/**
* Fetches event messages from the Torii client based on the provided query.
*
* @template T - The schema type.
* @param {QueryType<T>} query - The query object used to filter event messages.
* @param {(response: { data?: StandardizedQueryResult<T>; error?: Error }) => void} callback - The callback function to handle the response.
* @param {number} [limit=100] - The maximum number of event messages to fetch per request. Default is 100.
* @param {number} [offset=0] - The offset to start fetching event messages from. Default is 0.
* @param {{ logging?: boolean }} [options] - Optional settings.
* @param {boolean} [options.logging] - If true, enables logging of the fetching process. Default is false.
* @param {GetParams<T>} params - Parameters object
* @returns {Promise<StandardizedQueryResult<T>>} - A promise that resolves to the standardized query result.
*/
getEventMessages: (
query: QueryType<T>,
callback: (response: {
data?: StandardizedQueryResult<T>;
error?: Error;
}) => void,
limit?: number,
offset?: number,
options?: { logging?: boolean }
params: GetParams<T>
) => Promise<StandardizedQueryResult<T>>;
generateTypedData: <M extends UnionOfModelData<T>>(
primaryType: string,
Expand All @@ -363,3 +326,36 @@ export interface SDKConfig {
*/
domain: StarknetDomain;
}

export interface SDKFunctionOptions {
// If true, enables logging of the fetching process. Default is false.
logging?: boolean;
}

export interface SubscribeParams<T extends SchemaType> {
// Query object used to filter entities.
query: SubscriptionQueryType<T>;
// The callback function to handle the response.
callback: (response: {
data?: StandardizedQueryResult<T>;
error?: Error;
}) => void;
// Optional settings.
options?: SDKFunctionOptions;
}

export interface GetParams<T extends SchemaType> {
// The query object used to filter entities.
query: QueryType<T>;
// The callback function to handle the response.
callback: (response: {
data?: StandardizedQueryResult<T>;
error?: Error;
}) => void;
// The maximum number of entities to fetch per request. Default is 100.
limit?: number;
// The offset to start fetching entities from. Default is 0.
offset?: number;
// Optional settings.
options?: SDKFunctionOptions;
}
Loading