mirror of
https://github.com/innopals/ts-clarity.git
synced 2026-01-12 07:03:41 +08:00
feat: use typescript 5 & fix function args infer
Signed-off-by: bestmike007 <i@bestmike007.com>
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
nodejs 20.11.1
|
||||
pnpm 8.15.3
|
||||
pnpm 8.15.4
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
|
||||
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
|
||||
"organizeImports": {
|
||||
"enabled": true
|
||||
},
|
||||
|
||||
16
package.json
16
package.json
@@ -22,17 +22,17 @@
|
||||
"typecheck:propertyTypes": "pnpm run --r --parallel typecheck --exactOptionalPropertyTypes false && tsc --noEmit --exactOptionalPropertyTypes false"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.5.3",
|
||||
"@types/node": "^20.11.19",
|
||||
"@vitest/coverage-v8": "^1.3.0",
|
||||
"knip": "^5.0.1",
|
||||
"@biomejs/biome": "1.6.4",
|
||||
"@types/node": "^20.12.7",
|
||||
"@vitest/coverage-v8": "^1.4.0",
|
||||
"knip": "^5.9.4",
|
||||
"publint": "^0.2.7",
|
||||
"rimraf": "^5.0.5",
|
||||
"simple-git-hooks": "^2.9.0",
|
||||
"typescript": "^5.3.3",
|
||||
"vitest": "^1.3.0"
|
||||
"simple-git-hooks": "^2.11.1",
|
||||
"typescript": "^5.4.5",
|
||||
"vitest": "^1.4.0"
|
||||
},
|
||||
"packageManager": "pnpm@8.15.1",
|
||||
"packageManager": "pnpm@8.15.4",
|
||||
"simple-git-hooks": {
|
||||
"pre-commit": "pnpm run lint"
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ts-clarity",
|
||||
"description": "TypeScript runtime SDK for Clarity ABIs on Stacks",
|
||||
"version": "0.0.17",
|
||||
"version": "0.0.19",
|
||||
"license": "MIT",
|
||||
"repository": "innopals/ts-clarity",
|
||||
"scripts": {
|
||||
@@ -35,13 +35,13 @@
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stacks/stacks-blockchain-api-types": "^7.8.1",
|
||||
"@stacks/transactions": "^6.11.3",
|
||||
"clarity-abi": "^0.0.17",
|
||||
"@stacks/stacks-blockchain-api-types": "^7.9.1",
|
||||
"@stacks/transactions": "^6.13.1",
|
||||
"clarity-abi": "^0.0.19",
|
||||
"cross-fetch": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.3.3"
|
||||
"typescript": "^5.4.5"
|
||||
},
|
||||
"contributors": ["bestmike007 <bestmike007@gmail.com>"],
|
||||
"keywords": ["abi", "clarity", "stacks", "typescript", "sdk", "web3"]
|
||||
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
GetVariableByName,
|
||||
InferClarityAbiType,
|
||||
InferClarityAbiTypeTuple,
|
||||
MergeUnion,
|
||||
} from 'clarity-abi';
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@@ -32,21 +33,24 @@ export type InferFunctionName<
|
||||
: FunctionName;
|
||||
|
||||
export type InferFunctionArgsType<
|
||||
Functions extends
|
||||
| readonly ClarityAbiFunction[]
|
||||
| readonly unknown[] = readonly ClarityAbiFunction[],
|
||||
FunctionName extends string = string,
|
||||
Functions extends readonly ClarityAbiFunction[],
|
||||
FunctionName extends Functions[number]['name'],
|
||||
V extends ClarityAbiFunction['access'] = 'read_only' | 'public',
|
||||
TFunction extends
|
||||
ClarityAbiFunction = Functions extends readonly ClarityAbiFunction[]
|
||||
? GetFunctionByName<Functions, FunctionName, V>
|
||||
: ClarityAbiFunction,
|
||||
TArgs = InferClarityAbiTypeTuple<TFunction['args']>,
|
||||
TFunction extends ClarityAbiFunction = GetFunctionByName<
|
||||
Functions,
|
||||
FunctionName,
|
||||
V
|
||||
>,
|
||||
TArgs extends
|
||||
| Record<string, unknown>
|
||||
| never = TFunction extends ClarityAbiFunction
|
||||
? InferClarityAbiTypeTuple<TFunction['args']>
|
||||
: never,
|
||||
> = [TArgs] extends [never]
|
||||
? { args?: unknown }
|
||||
: {} extends TArgs
|
||||
? {}
|
||||
: { args: TArgs };
|
||||
: { args: MergeUnion<TArgs> };
|
||||
|
||||
export type InferReadonlyCallResultType<
|
||||
Functions extends
|
||||
@@ -69,7 +73,9 @@ export type InferReadonlyCallParameterType<
|
||||
> = {
|
||||
abi: Functions;
|
||||
functionName: InferFunctionName<Functions, FunctionName, 'read_only'>;
|
||||
} & InferFunctionArgsType<Functions, FunctionName, 'read_only'>;
|
||||
} & (Functions extends readonly ClarityAbiFunction[]
|
||||
? InferFunctionArgsType<Functions, FunctionName, 'read_only'>
|
||||
: { args?: unknown });
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Maps
|
||||
|
||||
@@ -3,7 +3,7 @@ import type {
|
||||
Transaction,
|
||||
} from '@stacks/stacks-blockchain-api-types';
|
||||
import {
|
||||
StacksTransaction,
|
||||
type StacksTransaction,
|
||||
deserializeTransaction,
|
||||
} from '@stacks/transactions';
|
||||
import { retryOnError, richFetch } from '../common/fetch.js';
|
||||
|
||||
719
pnpm-lock.yaml
generated
719
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,7 @@
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleResolution": "NodeNext",
|
||||
"module": "NodeNext",
|
||||
"outDir": "dist",
|
||||
"target": "ES2021",
|
||||
"lib": ["ES2022", "DOM"],
|
||||
"skipLibCheck": true
|
||||
|
||||
Reference in New Issue
Block a user