@clarigen/core 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +73 -73
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,50 +2,50 @@ import { ClarityAbi as ClarityAbi$1, PrincipalCV, ClarityValue, ClarityAbiType a
|
|
|
2
2
|
import { StacksNetwork } from 'micro-stacks/network';
|
|
3
3
|
import { StacksTransaction } from 'micro-stacks/transactions';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
type ClarityAbiTypeBuffer = {
|
|
6
6
|
buffer: {
|
|
7
7
|
length: number;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
type ClarityAbiTypeStringAscii = {
|
|
11
11
|
'string-ascii': {
|
|
12
12
|
length: number;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
type ClarityAbiTypeStringUtf8 = {
|
|
16
16
|
'string-utf8': {
|
|
17
17
|
length: number;
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
type ClarityAbiTypeResponse = {
|
|
21
21
|
response: {
|
|
22
22
|
ok: ClarityAbiType;
|
|
23
23
|
error: ClarityAbiType;
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
type ClarityAbiTypeOptional = {
|
|
27
27
|
optional: ClarityAbiType;
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
type ClarityAbiTypeTuple = {
|
|
30
30
|
tuple: {
|
|
31
31
|
name: string;
|
|
32
32
|
type: ClarityAbiType;
|
|
33
33
|
}[];
|
|
34
34
|
};
|
|
35
|
-
|
|
35
|
+
type ClarityAbiTypeList = {
|
|
36
36
|
list: {
|
|
37
37
|
type: ClarityAbiType;
|
|
38
38
|
length: number;
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
type ClarityAbiTypeUInt128 = 'uint128';
|
|
42
|
+
type ClarityAbiTypeInt128 = 'int128';
|
|
43
|
+
type ClarityAbiTypeBool = 'bool';
|
|
44
|
+
type ClarityAbiTypePrincipal = 'principal';
|
|
45
|
+
type ClarityAbiTypeTraitReference = 'trait_reference';
|
|
46
|
+
type ClarityAbiTypeNone = 'none';
|
|
47
|
+
type ClarityAbiTypePrimitive = ClarityAbiTypeUInt128 | ClarityAbiTypeInt128 | ClarityAbiTypeBool | ClarityAbiTypePrincipal | ClarityAbiTypeTraitReference | ClarityAbiTypeNone;
|
|
48
|
+
type ClarityAbiType = ClarityAbiTypePrimitive | ClarityAbiTypeBuffer | ClarityAbiTypeResponse | ClarityAbiTypeOptional | ClarityAbiTypeTuple | ClarityAbiTypeList | ClarityAbiTypeStringAscii | ClarityAbiTypeStringUtf8 | ClarityAbiTypeTraitReference;
|
|
49
49
|
interface ClarityAbiArg {
|
|
50
50
|
name: string;
|
|
51
51
|
type: ClarityAbiType;
|
|
@@ -58,11 +58,11 @@ interface ClarityAbiFunction {
|
|
|
58
58
|
type: ClarityAbiType;
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
type TypedAbiArg<T, N extends string> = {
|
|
62
62
|
_t?: T;
|
|
63
63
|
name: N;
|
|
64
64
|
};
|
|
65
|
-
|
|
65
|
+
type TypedAbiFunction<T extends TypedAbiArg<unknown, string>[], R> = ClarityAbiFunction & {
|
|
66
66
|
_t?: T;
|
|
67
67
|
_r?: R;
|
|
68
68
|
};
|
|
@@ -71,7 +71,7 @@ interface ClarityAbiVariable {
|
|
|
71
71
|
access: 'variable' | 'constant';
|
|
72
72
|
type: ClarityAbiType;
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
type TypedAbiVariable<T> = ClarityAbiVariable & {
|
|
75
75
|
defaultValue: T;
|
|
76
76
|
};
|
|
77
77
|
interface ClarityAbiMap {
|
|
@@ -79,7 +79,7 @@ interface ClarityAbiMap {
|
|
|
79
79
|
key: ClarityAbiType;
|
|
80
80
|
value: ClarityAbiType;
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
type TypedAbiMap<K, V> = ClarityAbiMap & {
|
|
83
83
|
_k?: K;
|
|
84
84
|
_v?: V;
|
|
85
85
|
};
|
|
@@ -90,7 +90,7 @@ interface ClarityAbiTypeNonFungibleToken {
|
|
|
90
90
|
name: string;
|
|
91
91
|
type: ClarityAbiType | Readonly<ClarityAbiType>;
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
type TypedAbi = Readonly<{
|
|
94
94
|
functions: {
|
|
95
95
|
[key: string]: TypedAbiFunction<TypedAbiArg<unknown, string>[], unknown>;
|
|
96
96
|
};
|
|
@@ -118,9 +118,9 @@ interface ResponseErr<T, E> {
|
|
|
118
118
|
isOk: false;
|
|
119
119
|
_o?: T;
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
type Response<Ok, Err> = ResponseOk<Ok, Err> | ResponseErr<Ok, Err>;
|
|
122
|
+
type OkType<R> = R extends ResponseOk<infer V, unknown> ? V : never;
|
|
123
|
+
type ErrType<R> = R extends ResponseErr<unknown, infer V> ? V : never;
|
|
124
124
|
|
|
125
125
|
declare function ok<T, Err = never>(value: T): ResponseOk<T, Err>;
|
|
126
126
|
declare function err<Ok = never, T = unknown>(value: T): ResponseErr<Ok, T>;
|
|
@@ -141,8 +141,8 @@ declare function cvToValue<T = any>(val: ClarityValue, returnResponse?: boolean)
|
|
|
141
141
|
* @param jsonCompat - enable to serialize bigints to strings
|
|
142
142
|
*/
|
|
143
143
|
declare function hexToCvValue<T>(hex: string, jsonCompat?: boolean): any;
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
type TupleInput = Record<string, any>;
|
|
145
|
+
type CVInput = string | boolean | TupleInput | number | bigint;
|
|
146
146
|
declare function parseToCV(input: CVInput, type: ClarityAbiType$1): ClarityValue;
|
|
147
147
|
declare function cvToString(val: ClarityValue, encoding?: 'tryAscii' | 'hex'): string;
|
|
148
148
|
/**
|
|
@@ -159,21 +159,21 @@ declare function transformArgsToCV(func: ClarityAbiFunction$1, args: any[] | [Re
|
|
|
159
159
|
declare function findJsTupleKey(key: string, input: Record<string, any>): string;
|
|
160
160
|
declare function expectOk<Ok>(response: Response<Ok, any>): Ok;
|
|
161
161
|
declare function expectErr<Err>(response: Response<any, Err>): Err;
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
type AbiPrimitiveTo<T extends ClarityAbiTypePrimitive> = T extends ClarityAbiTypeInt128 ? bigint : T extends ClarityAbiTypeUInt128 ? bigint : T extends ClarityAbiTypeBool ? boolean : T extends ClarityAbiTypePrincipal ? string : T extends ClarityAbiTypeTraitReference ? string : T extends ClarityAbiTypeNone ? never : T;
|
|
163
|
+
type ReadonlyTuple = {
|
|
164
164
|
readonly tuple: Readonly<ClarityAbiTypeTuple$1['tuple']>;
|
|
165
165
|
};
|
|
166
|
-
|
|
166
|
+
type TupleTypeUnion<T> = T extends Readonly<ClarityAbiTypeTuple$1['tuple'][number]> ? {
|
|
167
167
|
-readonly [Z in T['name']]: AbiTypeTo<T['type']>;
|
|
168
168
|
} : never;
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
type UnionToIntersection$1<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
170
|
+
type Compact$1<T> = {
|
|
171
171
|
[K in keyof T]: T[K];
|
|
172
172
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
type AbiTupleTo<T extends ReadonlyTuple> = Compact$1<UnionToIntersection$1<TupleTypeUnion<T['tuple'][number]>>>;
|
|
174
|
+
type AbiTypeTo<T extends ClarityAbiType$1 | ReadonlyTuple> = T extends ClarityAbiTypePrimitive ? AbiPrimitiveTo<T> : T extends ClarityAbiTypeBuffer ? Uint8Array : T extends ClarityAbiTypeStringAscii ? string : T extends ClarityAbiTypeStringUtf8 ? string : T extends ClarityAbiTypeList ? AbiTypeTo<T['list']['type']>[] : T extends ClarityAbiTypeOptional ? AbiTypeTo<T['optional']> | null : T extends ClarityAbiTypeResponse ? Response<AbiTypeTo<T['response']['ok']>, AbiTypeTo<T['response']['error']>> : T extends ReadonlyTuple ? AbiTupleTo<T> : T;
|
|
175
|
+
type FunctionReturnType<T> = T extends TypedAbiFunction<TypedAbiArg<unknown, string>[], infer R> ? R : never;
|
|
176
|
+
type Jsonize<T> = T extends BigInt ? string : T extends Uint8Array ? string : T extends Record<keyof T, unknown> ? {
|
|
177
177
|
[K in keyof T as K]: Jsonize<T[K]>;
|
|
178
178
|
} : T;
|
|
179
179
|
|
|
@@ -196,52 +196,52 @@ interface ContractCall<T> {
|
|
|
196
196
|
interface ContractCallTyped<Args extends UnknownArgs, R> extends Omit<ContractCall<R>, 'nativeArgs'> {
|
|
197
197
|
nativeArgs: ArgsType<Args>;
|
|
198
198
|
}
|
|
199
|
-
|
|
199
|
+
type ContractFunctions = {
|
|
200
200
|
[key: string]: TypedAbiFunction<UnknownArgs, unknown>;
|
|
201
201
|
};
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
type AllContracts = Record<string, TypedAbi>;
|
|
203
|
+
type UnknownArg = TypedAbiArg<unknown, string>;
|
|
204
|
+
type UnknownArgs = UnknownArg[];
|
|
205
|
+
type ArgsTuple<T extends UnknownArgs> = {
|
|
206
206
|
[K in keyof T]: T[K] extends TypedAbiArg<infer A, string> ? A : never;
|
|
207
207
|
};
|
|
208
|
-
|
|
208
|
+
type ArgsRecordUnion<T extends TypedAbiArg<unknown, string>> = T extends TypedAbiArg<infer A, infer N> ? {
|
|
209
209
|
[K in T as N]: A;
|
|
210
210
|
} : never;
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
type InnerUnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
212
|
+
type Compact<T> = {
|
|
213
213
|
[K in keyof T]: T[K];
|
|
214
214
|
};
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
type UnionToIntersection<T> = Compact<InnerUnionToIntersection<T>>;
|
|
216
|
+
type ArgsRecord<T extends UnknownArgs> = UnionToIntersection<ArgsRecordUnion<T[number]>>;
|
|
217
|
+
type ArgsType<T extends UnknownArgs> = [ArgsRecord<T>] | ArgsTuple<T>;
|
|
218
|
+
type ContractCallFunction<Args extends UnknownArgs, R> = {
|
|
219
219
|
(...args: ArgsType<Args>): ContractCallTyped<Args, R>;
|
|
220
220
|
abi: TypedAbiFunction<Args, R>;
|
|
221
221
|
};
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
type FnToContractCall<T> = T extends TypedAbiFunction<infer Arg, infer R> ? ContractCallFunction<Arg, R> : never;
|
|
223
|
+
type FunctionsToContractCalls<T> = T extends ContractFunctions ? {
|
|
224
224
|
[key in keyof T]: FnToContractCall<T[key]>;
|
|
225
225
|
} : never;
|
|
226
|
-
|
|
226
|
+
type ContractsToContractCalls<T> = T extends AllContracts ? {
|
|
227
227
|
[key in keyof T]: FunctionsToContractCalls<T[key]['functions']>;
|
|
228
228
|
} : never;
|
|
229
|
-
|
|
229
|
+
type FullContract<T> = T extends TypedAbi ? FunctionsToContractCalls<T['functions']> & T & {
|
|
230
230
|
identifier: string;
|
|
231
231
|
} & {
|
|
232
232
|
contractFile: string;
|
|
233
233
|
} : never;
|
|
234
|
-
|
|
234
|
+
type ContractFactory<T extends AllContracts> = {
|
|
235
235
|
[key in keyof T]: FullContract<T[key]>;
|
|
236
236
|
};
|
|
237
237
|
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
type Kebab<T extends string, A extends string = ''> = T extends `${infer F}${infer R}` ? Kebab<R, `${A}${F extends Lowercase<F> ? '' : '-'}${Lowercase<F>}`> : A;
|
|
239
|
+
type KebabObject<T> = T extends Uint8Array ? T : T extends Record<string, unknown> ? {
|
|
240
240
|
[K in keyof T as K extends string ? Kebab<K> : K]: KebabObject<T[K]>;
|
|
241
241
|
} : T;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
type ExtractArgs<F> = F extends TypedAbiFunction<infer Args, unknown> ? ArgsTuple<Args> : never;
|
|
243
|
+
type ExtractArgsRecord<F> = F extends TypedAbiFunction<infer Args, unknown> ? ArgsRecord<Args> : never;
|
|
244
|
+
type ContractBuilder<T> = (contractAddress: string, contractName: string) => T;
|
|
245
245
|
interface Contract<T> {
|
|
246
246
|
address: string;
|
|
247
247
|
contractFile: string;
|
|
@@ -256,7 +256,7 @@ interface ContractInstance<T> {
|
|
|
256
256
|
identifier: string;
|
|
257
257
|
contract: T;
|
|
258
258
|
}
|
|
259
|
-
|
|
259
|
+
type ContractInstances<T extends Contracts<any>> = {
|
|
260
260
|
[Name in keyof T]: ContractInstance<ReturnType<T[Name]['contract']>>;
|
|
261
261
|
};
|
|
262
262
|
|
|
@@ -282,7 +282,7 @@ declare enum CoreNodeEventType {
|
|
|
282
282
|
FtMintEvent = "ft_mint_event",
|
|
283
283
|
FtBurnEvent = "ft_burn_event"
|
|
284
284
|
}
|
|
285
|
-
|
|
285
|
+
type NonStandardClarityValue = unknown;
|
|
286
286
|
interface CoreNodeEventBase {
|
|
287
287
|
/** 0x-prefix transaction hash. */
|
|
288
288
|
txid: string;
|
|
@@ -397,7 +397,7 @@ interface FtBurnEvent extends CoreNodeEventBase {
|
|
|
397
397
|
amount: string;
|
|
398
398
|
};
|
|
399
399
|
}
|
|
400
|
-
|
|
400
|
+
type CoreNodeEvent = SmartContractEvent | StxTransferEvent | StxMintEvent | StxBurnEvent | StxLockEvent | FtTransferEvent | FtMintEvent | FtBurnEvent | NftTransferEvent | NftMintEvent | NftBurnEvent;
|
|
401
401
|
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.ContractEvent): SmartContractEvent[];
|
|
402
402
|
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.StxTransferEvent): StxTransferEvent[];
|
|
403
403
|
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.StxMintEvent): StxMintEvent[];
|
|
@@ -420,10 +420,10 @@ interface PureContractInfo {
|
|
|
420
420
|
contractAddress: string;
|
|
421
421
|
contractName: string;
|
|
422
422
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
423
|
+
type ContractFn<T> = (args: any) => T;
|
|
424
|
+
type ContractReturn<C extends ContractFn<ContractCalls.ReadOnly<any>>> = C extends ContractFn<ContractCalls.ReadOnly<infer T>> ? T : unknown;
|
|
425
|
+
type ContractReturnOk<C extends ContractFn<ContractCalls.ReadOnly<any>>> = ContractReturn<C> extends Response<infer O, any> ? O : unknown;
|
|
426
|
+
type ContractReturnErr<C extends ContractFn<ContractCalls.ReadOnly<any>>> = ContractReturn<C> extends Response<any, infer E> ? E : unknown;
|
|
427
427
|
interface MapGet<Key, Val> {
|
|
428
428
|
map: ClarityAbiMap;
|
|
429
429
|
nativeKey: Key;
|
|
@@ -453,7 +453,7 @@ interface ApiOptionsNoJson extends ApiOptionsBase {
|
|
|
453
453
|
interface ApiOptions extends ApiOptionsBase {
|
|
454
454
|
json?: boolean;
|
|
455
455
|
}
|
|
456
|
-
|
|
456
|
+
type JsonIfOption<O extends ApiOptions, R> = O extends ApiOptionsJsonize ? Jsonize<R> : R;
|
|
457
457
|
declare function ro<O extends ApiOptions, T>(tx: ContractCall<T>, options: O): Promise<JsonIfOption<O, T>>;
|
|
458
458
|
declare function roOk<O extends ApiOptions, Ok>(tx: ContractCall<Response<Ok, any>>, options: O): Promise<JsonIfOption<O, Ok>>;
|
|
459
459
|
declare function roErr<O extends ApiOptions, Err>(tx: ContractCall<Response<any, Err>>, options: O): Promise<JsonIfOption<O, Err>>;
|
|
@@ -509,7 +509,7 @@ interface BtcTransferTransaction {
|
|
|
509
509
|
'sats-amount': string;
|
|
510
510
|
};
|
|
511
511
|
}
|
|
512
|
-
|
|
512
|
+
type Transaction = EmulatedContractPublishTransaction | RequirementPublishTransaction | ContractPublishTransaction | EmulatedContractCallTransaction | BtcTransferTransaction | ContractCallTransaction;
|
|
513
513
|
interface Batch<T extends Transaction> {
|
|
514
514
|
id: number;
|
|
515
515
|
transactions: Readonly<T[]>;
|
|
@@ -538,7 +538,7 @@ interface DevnetDeploymentPlan {
|
|
|
538
538
|
batches: Readonly<Batch<RequirementPublishTransaction | ContractPublishTransaction | ContractCallTransaction | BtcTransferTransaction>[]>;
|
|
539
539
|
};
|
|
540
540
|
}
|
|
541
|
-
|
|
541
|
+
type TestnetDeploymentPlan = Omit<DevnetDeploymentPlan, 'network'> & {
|
|
542
542
|
network: 'testnet';
|
|
543
543
|
};
|
|
544
544
|
interface MainnetDeploymentPlan {
|
|
@@ -547,24 +547,24 @@ interface MainnetDeploymentPlan {
|
|
|
547
547
|
batches: Readonly<Batch<ContractPublishTransaction | ContractCallTransaction | BtcTransferTransaction>[]>;
|
|
548
548
|
};
|
|
549
549
|
}
|
|
550
|
-
|
|
550
|
+
type DeploymentPlan = SimnetDeploymentPlan | DevnetDeploymentPlan | TestnetDeploymentPlan | MainnetDeploymentPlan;
|
|
551
551
|
|
|
552
552
|
declare const DEPLOYMENT_NETWORKS: readonly ["devnet", "simnet", "testnet", "mainnet"];
|
|
553
|
-
|
|
554
|
-
|
|
553
|
+
type DeploymentNetwork = typeof DEPLOYMENT_NETWORKS[number];
|
|
554
|
+
type DeploymentsForContracts<C extends AllContracts> = {
|
|
555
555
|
[K in keyof C]: ContractDeployments;
|
|
556
556
|
};
|
|
557
|
-
|
|
557
|
+
type ContractDeployments = {
|
|
558
558
|
[key in DeploymentNetwork]: string | null;
|
|
559
559
|
};
|
|
560
|
-
|
|
560
|
+
type Project<C extends AllContracts, D extends DeploymentsForContracts<C>> = {
|
|
561
561
|
contracts: C;
|
|
562
562
|
deployments: D;
|
|
563
563
|
};
|
|
564
|
-
|
|
564
|
+
type FullContractWithIdentifier<C extends TypedAbi, Id extends string> = FullContract<C> & {
|
|
565
565
|
identifier: Id;
|
|
566
566
|
};
|
|
567
|
-
|
|
567
|
+
type ProjectFactory<P extends Project<any, any>, N extends DeploymentNetwork> = {
|
|
568
568
|
[ContractName in keyof P['contracts']]: P['deployments'][ContractName][N] extends string ? FullContractWithIdentifier<P['contracts'][ContractName], P['deployments'][ContractName][N]> : undefined;
|
|
569
569
|
};
|
|
570
570
|
declare function projectFactory<P extends Project<C, D>, N extends DeploymentNetwork, C extends AllContracts, D extends DeploymentsForContracts<C>>(project: P, network: N): ProjectFactory<P, N>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.6",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"build": "shx rm -rf ./dist && tsup",
|
|
27
27
|
"test": "jest",
|
|
28
28
|
"lint": "eslint \"src/**/*.{ts,tsx}\" && prettier --check src/**/*.ts",
|
|
29
|
-
"typecheck": "tsc --noEmit",
|
|
29
|
+
"typecheck": "tsc --noEmit -p tsconfig-test.json",
|
|
30
30
|
"publish:dev": "pnpm build && yalc publish --push",
|
|
31
31
|
"copy-types": "node copy-types.js"
|
|
32
32
|
}
|