@dojoengine/sdk
Version:
Dojo SDK: Build onchain and provable apps faster
135 lines (130 loc) • 6.26 kB
TypeScript
import * as torii$1 from '@dojoengine/torii-wasm';
import { S as SchemaType, a as SDKConfig, b as SDK } from './types-DbGeload.js';
export { o as GetParams, f as GetTokenBalanceRequest, G as GetTokenRequest, p as HistoricalToriiQueryBuilder, H as HistoricalToriiQueryBuilderOptions, P as ParsedEntity, l as SDKClientConfig, m as SDKFunctionOptions, c as StandardizedQueryResult, n as SubscribeParams, e as SubscribeResponse, i as SubscribeTokenBalanceRequest, k as SubscribeTokenRequest, h as SubscriptionCallback, g as SubscriptionCallbackArgs, T as ToriiQueryBuilder, d as ToriiResponse, U as UnionOfModelData, j as UpdateTokenBalanceSubscriptionRequest } from './types-DbGeload.js';
import { PatternMatching, ComparisonOperator, Clause } from '@dojoengine/torii-wasm/node';
import * as torii from '@dojoengine/torii-wasm/types';
import { BigNumberish } from 'starknet';
import 'neverthrow';
type ToUnion<T> = T extends infer U ? U : never;
type ExtractPrimitiveKeys<T> = T extends Record<infer K, any> ? K : never;
type PrimitiveTypeKeys = ToUnion<ExtractPrimitiveKeys<torii.Primitive>>;
type MemberValueParam = {
type: PrimitiveTypeKeys;
value: any;
} | any;
type ClauseBuilderInterface = {
build(): Clause;
};
type ModelPath<T, K extends keyof T> = K extends string ? T[K] extends Record<string, any> ? {
[SubK in keyof T[K]]: `${K}-${SubK & string}`;
}[keyof T[K]] : never : never;
type GetModelType<T, Path extends string> = Path extends `${infer Namespace}-${infer Model}` ? Namespace extends keyof T ? Model extends keyof T[Namespace] ? T[Namespace][Model] : never : never : never;
/**
* Saves some keyboard strokes to get a KeysClause.
*
* @param models - the models you want to query, has to be in form of ns-Model
* @param keys - the keys that has the model. You can use `undefined` as a wildcard to match any key
* @param pattern - either VariableLen or FixedLen - to check exact match of key number
* @return ClauseBuilder<T>
*/
declare function KeysClause<T extends SchemaType>(models: ModelPath<T, keyof T>[], keys: (string | undefined)[], pattern?: PatternMatching): ClauseBuilder<T>;
/**
* Saves some keyboard strokes to get a HashedKeysClause.
*
* @param keys - the hashed_keys (entityId) that you want to query over
* @return ClauseBuilder<T>
*/
declare function HashedKeysClause<T extends SchemaType>(keys: BigNumberish[]): ClauseBuilder<T>;
/**
* Saves some keyboard strokes to get a MemberClause.
*
* @template T - the schema type
* @param model - the model you want to query, has to be in form of ns-Model
* @param member - the member of the model on which you want to apply operator
* @param operator - the operator to apply
* @param value - the value to operate on.
* @return ClauseBuilder<T>
*/
declare function MemberClause<T extends SchemaType, Path extends ModelPath<T, keyof T>, M extends keyof GetModelType<T, ModelPath<T, keyof T>>>(model: Path, member: M & string, operator: ComparisonOperator, value: GetModelType<T, Path>[M] | GetModelType<T, Path>[M][] | MemberValueParam): ClauseBuilder<T>;
/**
* Saves some keyboard strokes to get a Composite "Or" Clause
*
* @template T - the schema type
* @param clauses - the inner clauses that you want to compose
* @return CompositeBuilder<T>
*/
declare function AndComposeClause<T extends SchemaType>(clauses: ClauseBuilderInterface[]): CompositeBuilder<T>;
/**
* Saves some keyboard strokes to get a Composite "And" Clause
* @template T - the schema type
* @param clauses - the inner clauses that you want to compose
* @return CompositeBuilder<T>
*/
declare function OrComposeClause<T extends SchemaType>(clauses: ClauseBuilderInterface[]): CompositeBuilder<T>;
declare class ClauseBuilder<T extends SchemaType> {
private clause;
constructor();
/**
* Create a clause based on entity keys
*/
keys(models: ModelPath<T, keyof T>[], keys: (string | undefined)[], pattern?: PatternMatching): ClauseBuilder<T>;
/**
* Create a hashed keys clause based on entity keys
* keys: an array of your keys array (no need to hash it, just pass raw keys)
*/
hashed_keys(keys: BigNumberish[]): ClauseBuilder<T>;
/**
* Create a member clause for comparing values
*/
where<Path extends ModelPath<T, keyof T>, M extends keyof GetModelType<T, Path>>(model: Path, member: M & string, operator: ComparisonOperator, value: GetModelType<T, Path>[M] | GetModelType<T, Path>[M][] | MemberValueParam): ClauseBuilder<T>;
/**
* Start a composite clause chain
*/
compose(): CompositeBuilder<T>;
/**
* Build the final clause
*/
build(): Clause;
}
declare class CompositeBuilder<T extends Record<string, Record<string, any>>> {
private orClauses;
private andClauses;
or(clauses: ClauseBuilderInterface[]): CompositeBuilder<T>;
and(clauses: ClauseBuilderInterface[]): CompositeBuilder<T>;
build(): Clause;
}
/**
* Creates a new Torii client instance.
*
* @param {torii.ClientConfig} config - The configuration object for the Torii client.
* @returns {Promise<torii.ToriiClient>} - A promise that resolves to the Torii client instance.
*/
declare function createClient(config: torii$1.ClientConfig): Promise<torii$1.ToriiClient>;
declare const defaultClientConfig: Partial<torii$1.ClientConfig>;
/**
* Initializes the SDK for web environment with the provided configuration and schema.
*
* @template T - The schema type.
* @param {SDKConfig} options - The configuration object for the SDK.
* @returns {Promise<SDK<T>>} - A promise that resolves to the initialized SDK instance.
*
* @example
* ```typescript
* import { init } from "@dojoengine/sdk";
* import { schema } from "./models.gen";
*
* const sdk = await init<typeof schema>({
* client: {
* worldAddress: "0x...",
* toriiUrl: "http://localhost:8080",
* },
* domain: {
* name: "MyApp",
* version: "1.0.0",
* chainId: "SN_MAIN",
* },
* });
* ```
*/
declare function init<T extends SchemaType>(options: SDKConfig): Promise<SDK<T>>;
export { AndComposeClause, ClauseBuilder, HashedKeysClause, KeysClause, MemberClause, OrComposeClause, SDK, SDKConfig, SchemaType, createClient, defaultClientConfig, init };