@tableland/sdk
Advanced tools
Comparing version 4.2.2 to 4.3.0
@@ -56,3 +56,3 @@ import { type Result } from "./registry/index.js"; | ||
*/ | ||
batch<T = D>(statements: Statement[], opts?: Signal): Promise<any>; | ||
batch<T = D>(statements: Statement[], opts?: Signal): Promise<Array<Result<T>>>; | ||
/** | ||
@@ -59,0 +59,0 @@ * Executes one or more queries directly without prepared statements |
@@ -77,7 +77,2 @@ "use strict"; | ||
// everything else a single result wrapped in an Array for backward compatability. | ||
// TODO: In order to work around the Validator API not returning all of the tableIds | ||
// and continuing to work in a backward compatable way, it seems that we have to | ||
// make this type `any` :( | ||
// We should attempt to fix this when the Validator API update happens, or on the | ||
// next major version. | ||
) { | ||
@@ -84,0 +79,0 @@ try { |
@@ -17,4 +17,7 @@ export type Awaitable<T> = T | PromiseLike<T>; | ||
export type AsyncFunction<T> = () => Awaitable<AsyncData<T>>; | ||
export declare function getAbortSignal(signal?: AbortSignal, maxTimeout?: number): AbortSignal; | ||
export declare function getAbortSignal(signal?: AbortSignal, maxTimeout?: number): { | ||
signal: AbortSignal; | ||
timeoutId: ReturnType<typeof setTimeout> | undefined; | ||
}; | ||
export declare function getAsyncPoller<T = unknown>(fn: AsyncFunction<T>, interval?: number, signal?: AbortSignal): Promise<T>; | ||
//# sourceMappingURL=await.d.ts.map |
@@ -6,6 +6,10 @@ "use strict"; | ||
let abortSignal; | ||
let timeoutId; | ||
if (signal == null) { | ||
const controller = new AbortController(); | ||
abortSignal = controller.signal; | ||
setTimeout(controller.abort.bind(controller), maxTimeout); | ||
// return the timeoutId so the caller can cleanup | ||
timeoutId = setTimeout(function () { | ||
controller.abort(); | ||
}, maxTimeout); | ||
} | ||
@@ -15,7 +19,9 @@ else { | ||
} | ||
return abortSignal; | ||
return { signal: abortSignal, timeoutId }; | ||
} | ||
exports.getAbortSignal = getAbortSignal; | ||
async function getAsyncPoller(fn, interval = 1500, signal) { | ||
const abortSignal = getAbortSignal(signal, 10000); | ||
// in order to set a timeout other than 10 seconds you need to | ||
// create and pass in an abort signal with a different timeout | ||
const { signal: abortSignal, timeoutId } = getAbortSignal(signal, 10000); | ||
const checkCondition = (resolve, reject) => { | ||
@@ -25,5 +31,9 @@ Promise.resolve(fn()) | ||
if (result.done && result.data != null) { | ||
// We don't want to call `AbortController.abort()` if the call succeeded | ||
clearTimeout(timeoutId); | ||
return resolve(result.data); | ||
} | ||
if (abortSignal.aborted) { | ||
// We don't want to call `AbortController.abort()` if the call is already aborted | ||
clearTimeout(timeoutId); | ||
return reject(abortSignal.reason); | ||
@@ -30,0 +40,0 @@ } |
@@ -27,9 +27,17 @@ import { type TransactionReceipt } from "../validator/receipt.js"; | ||
/** | ||
* Full table name. | ||
* @custom:deprecated First table's full name. | ||
*/ | ||
name: string; | ||
/** | ||
* Table name prefix. | ||
* @custom:deprecated First table name prefix. | ||
*/ | ||
prefix: string; | ||
/** | ||
* The full table names | ||
*/ | ||
names: string[]; | ||
/** | ||
* The table prefixes | ||
*/ | ||
prefixes: string[]; | ||
} | ||
@@ -102,8 +110,3 @@ /** | ||
export declare function wrapTransaction(conn: Config, prefix: string, tx: ContractTransaction): Promise<WaitableTransactionReceipt>; | ||
interface MultiEventTransaction { | ||
names: string[]; | ||
prefixes: string[]; | ||
} | ||
export declare function wrapManyTransaction(conn: Config, statements: string[] | Runnable[], tx: ContractTransaction): Promise<WaitableTransactionReceipt & MultiEventTransaction>; | ||
export {}; | ||
export declare function wrapManyTransaction(conn: Config, statements: string[] | Runnable[], tx: ContractTransaction): Promise<WaitableTransactionReceipt & Named>; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -45,2 +45,3 @@ "use strict"; | ||
async function wrapTransaction(conn, prefix, tx) { | ||
// TODO: next major we should combine this with wrapManyTransaction | ||
const _params = await (0, ethers_js_1.getContractReceipt)(tx); | ||
@@ -57,5 +58,5 @@ const chainId = _params.chainId === 0 || _params.chainId == null | ||
} | ||
return { ...receipt, name, prefix }; | ||
return { ...receipt, name, prefix, prefixes: [prefix], names: [name] }; | ||
}; | ||
return { ...params, wait, name, prefix }; | ||
return { ...params, wait, name, prefix, prefixes: [prefix], names: [name] }; | ||
} | ||
@@ -68,3 +69,3 @@ exports.wrapTransaction = wrapTransaction; | ||
* @param {tx} the transaction object | ||
* @returns {(WaitableTransactionReceipt & MultiEventTransaction)} | ||
* @returns {(WaitableTransactionReceipt & Named)} | ||
* | ||
@@ -71,0 +72,0 @@ */ |
import { type ValuesType, type Parameters, type BaseType } from "./helpers/binding.js"; | ||
import { type AutoWaitConfig, type Config, type Signal } from "./helpers/index.js"; | ||
import { type AutoWaitConfig, type Config, type SignalAndInterval } from "./helpers/index.js"; | ||
import { type Result } from "./registry/utils.js"; | ||
@@ -50,4 +50,4 @@ import { type ValueOf } from "./validator/query.js"; | ||
*/ | ||
all<T = S, K extends keyof T = keyof T>(colName?: undefined, opts?: Signal): Promise<Result<T>>; | ||
all<T = S, K extends keyof T = keyof T>(colName: K, opts?: Signal): Promise<Result<T[K]>>; | ||
all<T = S, K extends keyof T = keyof T>(colName?: undefined, opts?: SignalAndInterval): Promise<Result<T>>; | ||
all<T = S, K extends keyof T = keyof T>(colName: K, opts?: SignalAndInterval): Promise<Result<T[K]>>; | ||
/** | ||
@@ -62,4 +62,4 @@ * Executes a query and returns the first row of the results. | ||
first<T = S, K extends keyof T = keyof T>(): Promise<T>; | ||
first<T = S, K extends keyof T = keyof T>(colName: undefined, opts?: Signal): Promise<T>; | ||
first<T = S, K extends keyof T = keyof T>(colName: K, opts?: Signal): Promise<T[K] | null>; | ||
first<T = S, K extends keyof T = keyof T>(colName: undefined, opts?: SignalAndInterval): Promise<T>; | ||
first<T = S, K extends keyof T = keyof T>(colName: K, opts?: SignalAndInterval): Promise<T[K] | null>; | ||
/** | ||
@@ -72,3 +72,3 @@ * Runs the query/queries, but returns no results. Instead, run() | ||
*/ | ||
run(opts?: Signal): Promise<Result<never>>; | ||
run(opts?: SignalAndInterval): Promise<Result<never>>; | ||
/** | ||
@@ -79,4 +79,4 @@ * Same as stmt.all(), but returns an array of rows instead of objects. | ||
*/ | ||
raw<T = S>(opts?: Signal): Promise<Array<ValueOf<T>>>; | ||
raw<T = S>(opts?: SignalAndInterval): Promise<Array<ValueOf<T>>>; | ||
} | ||
//# sourceMappingURL=statement.d.ts.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var _Statement_instances, _Statement_parseAndExtract; | ||
var _Statement_instances, _Statement_parseAndExtract, _Statement_waitExec; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -88,4 +88,3 @@ exports.Statement = void 0; | ||
default: { | ||
const receipt = await (0, index_js_1.checkWait)(this.config, await (0, lowlevel_js_1.exec)(this.config, { type, sql, tables })); | ||
return (0, utils_js_1.wrapResult)(receipt, performance.now() - start); | ||
return (0, utils_js_1.wrapResult)(await __classPrivateFieldGet(this, _Statement_instances, "m", _Statement_waitExec).call(this, { ...opts, type, sql, tables }), performance.now() - start); | ||
} | ||
@@ -115,5 +114,8 @@ } | ||
default: { | ||
const receipt = await (0, lowlevel_js_1.exec)(this.config, { type, sql, tables }); | ||
/* c8 ignore next */ | ||
await (0, index_js_1.checkWait)(this.config, receipt); | ||
await __classPrivateFieldGet(this, _Statement_instances, "m", _Statement_waitExec).call(this, { | ||
...opts, | ||
type, | ||
sql, | ||
tables, | ||
}); | ||
return null; | ||
@@ -149,4 +151,3 @@ } | ||
default: { | ||
const receipt = await (0, index_js_1.checkWait)(this.config, await (0, lowlevel_js_1.exec)(this.config, { type, sql, tables })); | ||
return (0, utils_js_1.wrapResult)(receipt, performance.now() - start); | ||
return (0, utils_js_1.wrapResult)(await __classPrivateFieldGet(this, _Statement_instances, "m", _Statement_waitExec).call(this, { ...opts, type, sql, tables }), performance.now() - start); | ||
} | ||
@@ -177,5 +178,8 @@ } | ||
default: { | ||
const receipt = await (0, lowlevel_js_1.exec)(this.config, { type, sql, tables }); | ||
/* c8 ignore next */ | ||
await (0, index_js_1.checkWait)(this.config, receipt); | ||
await __classPrivateFieldGet(this, _Statement_instances, "m", _Statement_waitExec).call(this, { | ||
...opts, | ||
type, | ||
sql, | ||
tables, | ||
}); | ||
return []; | ||
@@ -200,3 +204,5 @@ } | ||
return { type, sql, tables }; | ||
}, _Statement_waitExec = async function _Statement_waitExec(params) { | ||
return await (0, index_js_1.checkWait)(this.config, await (0, lowlevel_js_1.exec)(this.config, params)); | ||
}; | ||
//# sourceMappingURL=statement.js.map |
@@ -46,9 +46,9 @@ /** | ||
readonly Table: { | ||
/** @example healthbot_5_1 */ | ||
/** @example healthbot_80001_1 */ | ||
readonly name?: string; | ||
/** @example https://testnets.tableland.network/api/v1/tables/healthbot_5_1 */ | ||
/** @example https://testnets.tableland.network/api/v1/tables/80001/1 */ | ||
readonly external_url?: string; | ||
/** @example https://render.tableland.xyz/anim/?chain=1&id=1 */ | ||
/** @example https://tables.testnets.tableland.xyz/80001/1.html */ | ||
readonly animation_url?: string; | ||
/** @example https://render.tableland.xyz/healthbot_5_1 */ | ||
/** @example https://tables.testnets.tableland.xyz/80001/1.svg */ | ||
readonly image?: string; | ||
@@ -68,3 +68,3 @@ /** | ||
/** @description The value of the property */ | ||
readonly value?: string | number | number | boolean | Record<string, never>; | ||
readonly value?: string | number | boolean | Record<string, never>; | ||
})[]; | ||
@@ -74,4 +74,15 @@ readonly schema?: components["schemas"]["Schema"]; | ||
readonly TransactionReceipt: { | ||
/** @example 1 */ | ||
/** | ||
* @deprecated | ||
* @description This field is deprecated | ||
* @example 1 | ||
*/ | ||
readonly table_id?: string; | ||
/** | ||
* @example [ | ||
* "1", | ||
* "2" | ||
* ] | ||
*/ | ||
readonly table_ids?: readonly (string)[]; | ||
/** @example 0x02f319429b8a7be1cbb492f0bfbf740d2472232a2edadde7df7c16c0b61aa78b */ | ||
@@ -178,3 +189,3 @@ readonly transaction_hash?: string; | ||
parameters: { | ||
readonly query: { | ||
query: { | ||
/** | ||
@@ -218,3 +229,3 @@ * @description The SQL read query statement | ||
parameters: { | ||
readonly path: { | ||
path: { | ||
/** | ||
@@ -253,3 +264,3 @@ * @description The parent chain to target | ||
parameters: { | ||
readonly path: { | ||
path: { | ||
/** | ||
@@ -256,0 +267,0 @@ * @description The parent chain to target |
@@ -57,2 +57,6 @@ "use strict"; | ||
async getTableById(params, opts = {}) { | ||
if (typeof params.chainId !== "number" || | ||
typeof params.tableId !== "string") { | ||
throw new Error("cannot get table with invalid chain or table id"); | ||
} | ||
return await (0, tables_js_1.getTable)(this.config, params); | ||
@@ -59,0 +63,0 @@ } |
@@ -56,3 +56,3 @@ import { type Result } from "./registry/index.js"; | ||
*/ | ||
batch<T = D>(statements: Statement[], opts?: Signal): Promise<any>; | ||
batch<T = D>(statements: Statement[], opts?: Signal): Promise<Array<Result<T>>>; | ||
/** | ||
@@ -59,0 +59,0 @@ * Executes one or more queries directly without prepared statements |
@@ -74,7 +74,2 @@ import { wrapResult } from "./registry/utils.js"; | ||
// everything else a single result wrapped in an Array for backward compatability. | ||
// TODO: In order to work around the Validator API not returning all of the tableIds | ||
// and continuing to work in a backward compatable way, it seems that we have to | ||
// make this type `any` :( | ||
// We should attempt to fix this when the Validator API update happens, or on the | ||
// next major version. | ||
) { | ||
@@ -81,0 +76,0 @@ try { |
@@ -17,4 +17,7 @@ export type Awaitable<T> = T | PromiseLike<T>; | ||
export type AsyncFunction<T> = () => Awaitable<AsyncData<T>>; | ||
export declare function getAbortSignal(signal?: AbortSignal, maxTimeout?: number): AbortSignal; | ||
export declare function getAbortSignal(signal?: AbortSignal, maxTimeout?: number): { | ||
signal: AbortSignal; | ||
timeoutId: ReturnType<typeof setTimeout> | undefined; | ||
}; | ||
export declare function getAsyncPoller<T = unknown>(fn: AsyncFunction<T>, interval?: number, signal?: AbortSignal): Promise<T>; | ||
//# sourceMappingURL=await.d.ts.map |
export function getAbortSignal(signal, maxTimeout = 60000) { | ||
let abortSignal; | ||
let timeoutId; | ||
if (signal == null) { | ||
const controller = new AbortController(); | ||
abortSignal = controller.signal; | ||
setTimeout(controller.abort.bind(controller), maxTimeout); | ||
// return the timeoutId so the caller can cleanup | ||
timeoutId = setTimeout(function () { | ||
controller.abort(); | ||
}, maxTimeout); | ||
} | ||
@@ -11,6 +15,8 @@ else { | ||
} | ||
return abortSignal; | ||
return { signal: abortSignal, timeoutId }; | ||
} | ||
export async function getAsyncPoller(fn, interval = 1500, signal) { | ||
const abortSignal = getAbortSignal(signal, 10000); | ||
// in order to set a timeout other than 10 seconds you need to | ||
// create and pass in an abort signal with a different timeout | ||
const { signal: abortSignal, timeoutId } = getAbortSignal(signal, 10000); | ||
const checkCondition = (resolve, reject) => { | ||
@@ -20,5 +26,9 @@ Promise.resolve(fn()) | ||
if (result.done && result.data != null) { | ||
// We don't want to call `AbortController.abort()` if the call succeeded | ||
clearTimeout(timeoutId); | ||
return resolve(result.data); | ||
} | ||
if (abortSignal.aborted) { | ||
// We don't want to call `AbortController.abort()` if the call is already aborted | ||
clearTimeout(timeoutId); | ||
return reject(abortSignal.reason); | ||
@@ -25,0 +35,0 @@ } |
@@ -27,9 +27,17 @@ import { type TransactionReceipt } from "../validator/receipt.js"; | ||
/** | ||
* Full table name. | ||
* @custom:deprecated First table's full name. | ||
*/ | ||
name: string; | ||
/** | ||
* Table name prefix. | ||
* @custom:deprecated First table name prefix. | ||
*/ | ||
prefix: string; | ||
/** | ||
* The full table names | ||
*/ | ||
names: string[]; | ||
/** | ||
* The table prefixes | ||
*/ | ||
prefixes: string[]; | ||
} | ||
@@ -102,8 +110,3 @@ /** | ||
export declare function wrapTransaction(conn: Config, prefix: string, tx: ContractTransaction): Promise<WaitableTransactionReceipt>; | ||
interface MultiEventTransaction { | ||
names: string[]; | ||
prefixes: string[]; | ||
} | ||
export declare function wrapManyTransaction(conn: Config, statements: string[] | Runnable[], tx: ContractTransaction): Promise<WaitableTransactionReceipt & MultiEventTransaction>; | ||
export {}; | ||
export declare function wrapManyTransaction(conn: Config, statements: string[] | Runnable[], tx: ContractTransaction): Promise<WaitableTransactionReceipt & Named>; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -40,2 +40,3 @@ import { pollTransactionReceipt, } from "../validator/receipt.js"; | ||
export async function wrapTransaction(conn, prefix, tx) { | ||
// TODO: next major we should combine this with wrapManyTransaction | ||
const _params = await getContractReceipt(tx); | ||
@@ -52,5 +53,5 @@ const chainId = _params.chainId === 0 || _params.chainId == null | ||
} | ||
return { ...receipt, name, prefix }; | ||
return { ...receipt, name, prefix, prefixes: [prefix], names: [name] }; | ||
}; | ||
return { ...params, wait, name, prefix }; | ||
return { ...params, wait, name, prefix, prefixes: [prefix], names: [name] }; | ||
} | ||
@@ -62,3 +63,3 @@ /* A helper function for mapping contract event receipts to table data | ||
* @param {tx} the transaction object | ||
* @returns {(WaitableTransactionReceipt & MultiEventTransaction)} | ||
* @returns {(WaitableTransactionReceipt & Named)} | ||
* | ||
@@ -65,0 +66,0 @@ */ |
import { type ValuesType, type Parameters, type BaseType } from "./helpers/binding.js"; | ||
import { type AutoWaitConfig, type Config, type Signal } from "./helpers/index.js"; | ||
import { type AutoWaitConfig, type Config, type SignalAndInterval } from "./helpers/index.js"; | ||
import { type Result } from "./registry/utils.js"; | ||
@@ -50,4 +50,4 @@ import { type ValueOf } from "./validator/query.js"; | ||
*/ | ||
all<T = S, K extends keyof T = keyof T>(colName?: undefined, opts?: Signal): Promise<Result<T>>; | ||
all<T = S, K extends keyof T = keyof T>(colName: K, opts?: Signal): Promise<Result<T[K]>>; | ||
all<T = S, K extends keyof T = keyof T>(colName?: undefined, opts?: SignalAndInterval): Promise<Result<T>>; | ||
all<T = S, K extends keyof T = keyof T>(colName: K, opts?: SignalAndInterval): Promise<Result<T[K]>>; | ||
/** | ||
@@ -62,4 +62,4 @@ * Executes a query and returns the first row of the results. | ||
first<T = S, K extends keyof T = keyof T>(): Promise<T>; | ||
first<T = S, K extends keyof T = keyof T>(colName: undefined, opts?: Signal): Promise<T>; | ||
first<T = S, K extends keyof T = keyof T>(colName: K, opts?: Signal): Promise<T[K] | null>; | ||
first<T = S, K extends keyof T = keyof T>(colName: undefined, opts?: SignalAndInterval): Promise<T>; | ||
first<T = S, K extends keyof T = keyof T>(colName: K, opts?: SignalAndInterval): Promise<T[K] | null>; | ||
/** | ||
@@ -72,3 +72,3 @@ * Runs the query/queries, but returns no results. Instead, run() | ||
*/ | ||
run(opts?: Signal): Promise<Result<never>>; | ||
run(opts?: SignalAndInterval): Promise<Result<never>>; | ||
/** | ||
@@ -79,4 +79,4 @@ * Same as stmt.all(), but returns an array of rows instead of objects. | ||
*/ | ||
raw<T = S>(opts?: Signal): Promise<Array<ValueOf<T>>>; | ||
raw<T = S>(opts?: SignalAndInterval): Promise<Array<ValueOf<T>>>; | ||
} | ||
//# sourceMappingURL=statement.d.ts.map |
@@ -6,3 +6,3 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
}; | ||
var _Statement_instances, _Statement_parseAndExtract; | ||
var _Statement_instances, _Statement_parseAndExtract, _Statement_waitExec; | ||
import { getParameters, bindValues, } from "./helpers/binding.js"; | ||
@@ -85,4 +85,3 @@ import { checkWait, normalize, } from "./helpers/index.js"; | ||
default: { | ||
const receipt = await checkWait(this.config, await exec(this.config, { type, sql, tables })); | ||
return wrapResult(receipt, performance.now() - start); | ||
return wrapResult(await __classPrivateFieldGet(this, _Statement_instances, "m", _Statement_waitExec).call(this, { ...opts, type, sql, tables }), performance.now() - start); | ||
} | ||
@@ -112,5 +111,8 @@ } | ||
default: { | ||
const receipt = await exec(this.config, { type, sql, tables }); | ||
/* c8 ignore next */ | ||
await checkWait(this.config, receipt); | ||
await __classPrivateFieldGet(this, _Statement_instances, "m", _Statement_waitExec).call(this, { | ||
...opts, | ||
type, | ||
sql, | ||
tables, | ||
}); | ||
return null; | ||
@@ -146,4 +148,3 @@ } | ||
default: { | ||
const receipt = await checkWait(this.config, await exec(this.config, { type, sql, tables })); | ||
return wrapResult(receipt, performance.now() - start); | ||
return wrapResult(await __classPrivateFieldGet(this, _Statement_instances, "m", _Statement_waitExec).call(this, { ...opts, type, sql, tables }), performance.now() - start); | ||
} | ||
@@ -174,5 +175,8 @@ } | ||
default: { | ||
const receipt = await exec(this.config, { type, sql, tables }); | ||
/* c8 ignore next */ | ||
await checkWait(this.config, receipt); | ||
await __classPrivateFieldGet(this, _Statement_instances, "m", _Statement_waitExec).call(this, { | ||
...opts, | ||
type, | ||
sql, | ||
tables, | ||
}); | ||
return []; | ||
@@ -196,3 +200,5 @@ } | ||
return { type, sql, tables }; | ||
}, _Statement_waitExec = async function _Statement_waitExec(params) { | ||
return await checkWait(this.config, await exec(this.config, params)); | ||
}; | ||
//# sourceMappingURL=statement.js.map |
@@ -46,9 +46,9 @@ /** | ||
readonly Table: { | ||
/** @example healthbot_5_1 */ | ||
/** @example healthbot_80001_1 */ | ||
readonly name?: string; | ||
/** @example https://testnets.tableland.network/api/v1/tables/healthbot_5_1 */ | ||
/** @example https://testnets.tableland.network/api/v1/tables/80001/1 */ | ||
readonly external_url?: string; | ||
/** @example https://render.tableland.xyz/anim/?chain=1&id=1 */ | ||
/** @example https://tables.testnets.tableland.xyz/80001/1.html */ | ||
readonly animation_url?: string; | ||
/** @example https://render.tableland.xyz/healthbot_5_1 */ | ||
/** @example https://tables.testnets.tableland.xyz/80001/1.svg */ | ||
readonly image?: string; | ||
@@ -68,3 +68,3 @@ /** | ||
/** @description The value of the property */ | ||
readonly value?: string | number | number | boolean | Record<string, never>; | ||
readonly value?: string | number | boolean | Record<string, never>; | ||
})[]; | ||
@@ -74,4 +74,15 @@ readonly schema?: components["schemas"]["Schema"]; | ||
readonly TransactionReceipt: { | ||
/** @example 1 */ | ||
/** | ||
* @deprecated | ||
* @description This field is deprecated | ||
* @example 1 | ||
*/ | ||
readonly table_id?: string; | ||
/** | ||
* @example [ | ||
* "1", | ||
* "2" | ||
* ] | ||
*/ | ||
readonly table_ids?: readonly (string)[]; | ||
/** @example 0x02f319429b8a7be1cbb492f0bfbf740d2472232a2edadde7df7c16c0b61aa78b */ | ||
@@ -178,3 +189,3 @@ readonly transaction_hash?: string; | ||
parameters: { | ||
readonly query: { | ||
query: { | ||
/** | ||
@@ -218,3 +229,3 @@ * @description The SQL read query statement | ||
parameters: { | ||
readonly path: { | ||
path: { | ||
/** | ||
@@ -253,3 +264,3 @@ * @description The parent chain to target | ||
parameters: { | ||
readonly path: { | ||
path: { | ||
/** | ||
@@ -256,0 +267,0 @@ * @description The parent chain to target |
@@ -53,2 +53,6 @@ import { getBaseUrl, } from "../helpers/index.js"; | ||
async getTableById(params, opts = {}) { | ||
if (typeof params.chainId !== "number" || | ||
typeof params.tableId !== "string") { | ||
throw new Error("cannot get table with invalid chain or table id"); | ||
} | ||
return await getTable(this.config, params); | ||
@@ -55,0 +59,0 @@ } |
{ | ||
"name": "@tableland/sdk", | ||
"version": "4.2.2", | ||
"version": "4.3.0", | ||
"description": "A database client and helpers for the Tableland network", | ||
@@ -86,6 +86,6 @@ "publishConfig": { | ||
"@playwright/test": "^1.30.0", | ||
"@tableland/local": "^1.2.2-pre.1", | ||
"@tableland/local": "^1.3.0-pre.1", | ||
"@types/assert": "^1.5.6", | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^18.11.18", | ||
"@types/node": "^20.1.4", | ||
"@typescript-eslint/eslint-plugin": "^5.48.1", | ||
@@ -108,9 +108,9 @@ "@typescript-eslint/parser": "^5.47.0", | ||
"typedoc": "^0.24.6", | ||
"typescript": "^4.9.4" | ||
"typescript": "^5.0.4" | ||
}, | ||
"dependencies": { | ||
"@tableland/evm": "^4.2.2", | ||
"@tableland/sqlparser": "^1.0.6-pre.5", | ||
"@tableland/sqlparser": "^1.1.0-pre.0", | ||
"ethers": "^5.7.2" | ||
} | ||
} |
@@ -98,8 +98,3 @@ import { type NormalizedStatement } from "@tableland/sqlparser"; | ||
// everything else a single result wrapped in an Array for backward compatability. | ||
// TODO: In order to work around the Validator API not returning all of the tableIds | ||
// and continuing to work in a backward compatable way, it seems that we have to | ||
// make this type `any` :( | ||
// We should attempt to fix this when the Validator API update happens, or on the | ||
// next major version. | ||
): Promise<any> { | ||
): Promise<Array<Result<T>>> { | ||
try { | ||
@@ -106,0 +101,0 @@ const start = performance.now(); |
@@ -27,12 +27,19 @@ export type Awaitable<T> = T | PromiseLike<T>; | ||
maxTimeout: number = 60_000 | ||
): AbortSignal { | ||
): { | ||
signal: AbortSignal; | ||
timeoutId: ReturnType<typeof setTimeout> | undefined; | ||
} { | ||
let abortSignal: AbortSignal; | ||
let timeoutId; | ||
if (signal == null) { | ||
const controller = new AbortController(); | ||
abortSignal = controller.signal; | ||
setTimeout(controller.abort.bind(controller), maxTimeout); | ||
// return the timeoutId so the caller can cleanup | ||
timeoutId = setTimeout(function () { | ||
controller.abort(); | ||
}, maxTimeout); | ||
} else { | ||
abortSignal = signal; | ||
} | ||
return abortSignal; | ||
return { signal: abortSignal, timeoutId }; | ||
} | ||
@@ -45,3 +52,5 @@ | ||
): Promise<T> { | ||
const abortSignal = getAbortSignal(signal, 10_000); | ||
// in order to set a timeout other than 10 seconds you need to | ||
// create and pass in an abort signal with a different timeout | ||
const { signal: abortSignal, timeoutId } = getAbortSignal(signal, 10_000); | ||
const checkCondition = ( | ||
@@ -54,5 +63,9 @@ resolve: (value: T) => void, | ||
if (result.done && result.data != null) { | ||
// We don't want to call `AbortController.abort()` if the call succeeded | ||
clearTimeout(timeoutId); | ||
return resolve(result.data); | ||
} | ||
if (abortSignal.aborted) { | ||
// We don't want to call `AbortController.abort()` if the call is already aborted | ||
clearTimeout(timeoutId); | ||
return reject(abortSignal.reason); | ||
@@ -59,0 +72,0 @@ } else { |
@@ -43,9 +43,17 @@ import { | ||
/** | ||
* Full table name. | ||
* @custom:deprecated First table's full name. | ||
*/ | ||
name: string; | ||
/** | ||
* Table name prefix. | ||
* @custom:deprecated First table name prefix. | ||
*/ | ||
prefix: string; | ||
/** | ||
* The full table names | ||
*/ | ||
names: string[]; | ||
/** | ||
* The table prefixes | ||
*/ | ||
prefixes: string[]; | ||
} | ||
@@ -160,2 +168,3 @@ | ||
): Promise<WaitableTransactionReceipt> { | ||
// TODO: next major we should combine this with wrapManyTransaction | ||
const _params = await getContractReceipt(tx); | ||
@@ -175,12 +184,7 @@ const chainId = | ||
} | ||
return { ...receipt, name, prefix }; | ||
return { ...receipt, name, prefix, prefixes: [prefix], names: [name] }; | ||
}; | ||
return { ...params, wait, name, prefix }; | ||
return { ...params, wait, name, prefix, prefixes: [prefix], names: [name] }; | ||
} | ||
interface MultiEventTransaction { | ||
names: string[]; | ||
prefixes: string[]; | ||
} | ||
/* A helper function for mapping contract event receipts to table data | ||
@@ -191,3 +195,3 @@ * | ||
* @param {tx} the transaction object | ||
* @returns {(WaitableTransactionReceipt & MultiEventTransaction)} | ||
* @returns {(WaitableTransactionReceipt & Named)} | ||
* | ||
@@ -199,3 +203,3 @@ */ | ||
tx: ContractTransaction | ||
): Promise<WaitableTransactionReceipt & MultiEventTransaction> { | ||
): Promise<WaitableTransactionReceipt & Named> { | ||
const _params = await getContractReceipt(tx); | ||
@@ -240,3 +244,3 @@ const chainId = | ||
opts: SignalAndInterval = {} | ||
): Promise<TransactionReceipt & Named & MultiEventTransaction> => { | ||
): Promise<TransactionReceipt & Named> => { | ||
const receipt = await pollTransactionReceipt(conn, params, opts); | ||
@@ -243,0 +247,0 @@ if (receipt.error != null) { |
@@ -11,3 +11,3 @@ import { | ||
type Config, | ||
type Signal, | ||
type SignalAndInterval, | ||
checkWait, | ||
@@ -19,2 +19,3 @@ normalize, | ||
type Result, | ||
type WaitableTransactionReceipt, | ||
extractReadonly, | ||
@@ -114,2 +115,8 @@ wrapResult, | ||
async #waitExec( | ||
params: ExtractedStatement | ||
): Promise<WaitableTransactionReceipt> { | ||
return await checkWait(this.config, await exec(this.config, params)); | ||
} | ||
/** | ||
@@ -123,11 +130,11 @@ * Executes a query and returns all rows and metadata. | ||
colName?: undefined, | ||
opts?: Signal | ||
opts?: SignalAndInterval | ||
): Promise<Result<T>>; | ||
async all<T = S, K extends keyof T = keyof T>( | ||
colName: K, | ||
opts?: Signal | ||
opts?: SignalAndInterval | ||
): Promise<Result<T[K]>>; | ||
async all<T = S, K extends keyof T = keyof T>( | ||
colName?: K, | ||
opts: Signal = {} | ||
opts: SignalAndInterval = {} | ||
): Promise<Result<T | T[K]>> { | ||
@@ -153,8 +160,6 @@ try { | ||
default: { | ||
const receipt = await checkWait( | ||
this.config, | ||
await exec(this.config, { type, sql, tables }) | ||
return wrapResult<T>( | ||
await this.#waitExec({ ...opts, type, sql, tables }), | ||
performance.now() - start | ||
); | ||
return wrapResult(receipt, performance.now() - start); | ||
} | ||
@@ -181,11 +186,11 @@ } | ||
colName: undefined, | ||
opts?: Signal | ||
opts?: SignalAndInterval | ||
): Promise<T>; | ||
async first<T = S, K extends keyof T = keyof T>( | ||
colName: K, | ||
opts?: Signal | ||
opts?: SignalAndInterval | ||
): Promise<T[K] | null>; | ||
async first<T = S, K extends keyof T = keyof T>( | ||
colName?: K, | ||
opts: Signal = {} | ||
opts: SignalAndInterval = {} | ||
): Promise<T | T[K] | null> { | ||
@@ -207,5 +212,8 @@ try { | ||
default: { | ||
const receipt = await exec(this.config, { type, sql, tables }); | ||
/* c8 ignore next */ | ||
await checkWait(this.config, receipt); | ||
await this.#waitExec({ | ||
...opts, | ||
type, | ||
sql, | ||
tables, | ||
}); | ||
return null; | ||
@@ -227,3 +235,3 @@ } | ||
*/ | ||
async run(opts: Signal = {}): Promise<Result<never>> { | ||
async run(opts: SignalAndInterval = {}): Promise<Result<never>> { | ||
try { | ||
@@ -242,7 +250,6 @@ const start = performance.now(); | ||
default: { | ||
const receipt = await checkWait( | ||
this.config, | ||
await exec(this.config, { type, sql, tables }) | ||
return wrapResult( | ||
await this.#waitExec({ ...opts, type, sql, tables }), | ||
performance.now() - start | ||
); | ||
return wrapResult(receipt, performance.now() - start); | ||
} | ||
@@ -261,3 +268,3 @@ } | ||
*/ | ||
async raw<T = S>(opts: Signal = {}): Promise<Array<ValueOf<T>>> { | ||
async raw<T = S>(opts: SignalAndInterval = {}): Promise<Array<ValueOf<T>>> { | ||
try { | ||
@@ -274,5 +281,8 @@ const { sql, type, tables } = await this.#parseAndExtract(); | ||
default: { | ||
const receipt = await exec(this.config, { type, sql, tables }); | ||
/* c8 ignore next */ | ||
await checkWait(this.config, receipt); | ||
await this.#waitExec({ | ||
...opts, | ||
type, | ||
sql, | ||
tables, | ||
}); | ||
return []; | ||
@@ -279,0 +289,0 @@ } |
@@ -50,9 +50,9 @@ /** | ||
readonly Table: { | ||
/** @example healthbot_5_1 */ | ||
/** @example healthbot_80001_1 */ | ||
readonly name?: string; | ||
/** @example https://testnets.tableland.network/api/v1/tables/healthbot_5_1 */ | ||
/** @example https://testnets.tableland.network/api/v1/tables/80001/1 */ | ||
readonly external_url?: string; | ||
/** @example https://render.tableland.xyz/anim/?chain=1&id=1 */ | ||
/** @example https://tables.testnets.tableland.xyz/80001/1.html */ | ||
readonly animation_url?: string; | ||
/** @example https://render.tableland.xyz/healthbot_5_1 */ | ||
/** @example https://tables.testnets.tableland.xyz/80001/1.svg */ | ||
readonly image?: string; | ||
@@ -72,3 +72,3 @@ /** | ||
/** @description The value of the property */ | ||
readonly value?: string | number | number | boolean | Record<string, never>; | ||
readonly value?: string | number | boolean | Record<string, never>; | ||
})[]; | ||
@@ -78,4 +78,15 @@ readonly schema?: components["schemas"]["Schema"]; | ||
readonly TransactionReceipt: { | ||
/** @example 1 */ | ||
/** | ||
* @deprecated | ||
* @description This field is deprecated | ||
* @example 1 | ||
*/ | ||
readonly table_id?: string; | ||
/** | ||
* @example [ | ||
* "1", | ||
* "2" | ||
* ] | ||
*/ | ||
readonly table_ids?: readonly (string)[]; | ||
/** @example 0x02f319429b8a7be1cbb492f0bfbf740d2472232a2edadde7df7c16c0b61aa78b */ | ||
@@ -185,3 +196,3 @@ readonly transaction_hash?: string; | ||
parameters: { | ||
readonly query: { | ||
query: { | ||
/** | ||
@@ -225,3 +236,3 @@ * @description The SQL read query statement | ||
parameters: { | ||
readonly path: { | ||
path: { | ||
/** | ||
@@ -260,3 +271,3 @@ * @description The parent chain to target | ||
parameters: { | ||
readonly path: { | ||
path: { | ||
/** | ||
@@ -263,0 +274,0 @@ * @description The parent chain to target |
@@ -84,2 +84,8 @@ import { | ||
async getTableById(params: TableParams, opts: Signal = {}): Promise<Table> { | ||
if ( | ||
typeof params.chainId !== "number" || | ||
typeof params.tableId !== "string" | ||
) { | ||
throw new Error("cannot get table with invalid chain or table id"); | ||
} | ||
return await getTable(this.config, params); | ||
@@ -86,0 +92,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
507170
9631