Skip to content

Commit 23eeba7

Browse files
committed
Update typedefs
1 parent b2c72ae commit 23eeba7

File tree

5 files changed

+153
-51
lines changed

5 files changed

+153
-51
lines changed

packages/typedefs/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,4 @@ export type EventStream = StreamConnection<{
459459

460460
export * from "./interaction"
461461
export * from "./fvm-errors"
462-
export * as Subscription from "./subscriptions"
462+
export * as SdkTransport from "./sdk-transport"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {SendFn} from "./requests"
2+
import {SubscribeFn} from "./subscriptions"
3+
4+
export type Transport = {
5+
send: SendFn
6+
subscribe: SubscribeFn
7+
}
8+
9+
export type TransportConfig = {
10+
node: string
11+
}
12+
13+
export type TransportFactory = (config: TransportConfig) => Transport
14+
15+
export * from "./subscriptions"
16+
export * from "./requests"
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import {Interaction} from "../interaction"
2+
3+
interface InteractionModule {
4+
isTransaction: (ix: Interaction) => boolean
5+
isGetTransactionStatus: (ix: Interaction) => boolean
6+
isGetTransaction: (ix: Interaction) => boolean
7+
isScript: (ix: Interaction) => boolean
8+
isGetAccount: (ix: Interaction) => boolean
9+
isGetEvents: (ix: Interaction) => boolean
10+
isGetBlock: (ix: Interaction) => boolean
11+
isGetBlockHeader: (ix: Interaction) => boolean
12+
isGetCollection: (ix: Interaction) => boolean
13+
isPing: (ix: Interaction) => boolean
14+
isGetNetworkParameters: (ix: Interaction) => boolean
15+
isSubscribeEvents?: (ix: Interaction) => boolean
16+
isGetNodeVersionInfo?: (ix: Interaction) => boolean
17+
}
18+
interface IContext {
19+
ix: InteractionModule
20+
}
21+
interface IOptsCommon {
22+
node?: string
23+
}
24+
25+
interface IOpts extends IOptsCommon {
26+
sendTransaction?: (
27+
ix: Interaction,
28+
context: IContext,
29+
opts: IOptsCommon
30+
) => void
31+
sendGetTransactionStatus?: (
32+
ix: Interaction,
33+
context: IContext,
34+
opts: IOptsCommon
35+
) => void
36+
sendGetTransaction?: (
37+
ix: Interaction,
38+
context: IContext,
39+
opts: IOptsCommon
40+
) => void
41+
sendExecuteScript?: (
42+
ix: Interaction,
43+
context: IContext,
44+
opts: IOptsCommon
45+
) => void
46+
sendGetAccount?: (
47+
ix: Interaction,
48+
context: IContext,
49+
opts: IOptsCommon
50+
) => void
51+
sendGetEvents?: (
52+
ix: Interaction,
53+
context: IContext,
54+
opts: IOptsCommon
55+
) => void
56+
sendGetBlockHeader?: (
57+
ix: Interaction,
58+
context: IContext,
59+
opts: IOptsCommon
60+
) => void
61+
sendGetCollection?: (
62+
ix: Interaction,
63+
context: IContext,
64+
opts: IOptsCommon
65+
) => void
66+
sendPing?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void
67+
sendGetBlock?: (ix: Interaction, context: IContext, opts: IOptsCommon) => void
68+
sendGetNetworkParameters?: (
69+
ix: Interaction,
70+
context: IContext,
71+
opts: IOptsCommon
72+
) => void
73+
connectSubscribeEvents?: (
74+
ix: Interaction,
75+
context: IContext,
76+
opts: IOptsCommon
77+
) => void
78+
sendGetNodeVersionInfo?: (
79+
ix: Interaction,
80+
context: IContext,
81+
opts: IOptsCommon
82+
) => void
83+
}
84+
85+
export type SendFn = (ix: Interaction, context: IContext, opts: IOpts) => void
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
type SchemaItem<TArgs, TData> = {
2+
args: TArgs
3+
data: TData
4+
}
5+
6+
export enum SubscriptionTopic {
7+
EVENTS = "events",
8+
BLOCKS = "blocks",
9+
}
10+
11+
export type SubscriptionSchema = {
12+
[SubscriptionTopic.EVENTS]: SchemaItem<
13+
{
14+
startBlock: number
15+
endBlock: number
16+
},
17+
{
18+
type: string
19+
data: any
20+
}
21+
>
22+
[SubscriptionTopic.BLOCKS]: SchemaItem<
23+
{
24+
startBlock: number
25+
endBlock: number
26+
},
27+
{
28+
type: string
29+
data: any
30+
}
31+
>
32+
}
33+
34+
export type SubscriptionArguments<T extends SubscriptionTopic> =
35+
SubscriptionSchema[T]["args"]
36+
export type SubscriptionData<T extends SubscriptionTopic> =
37+
SubscriptionSchema[T]["data"]
38+
39+
export type Subscription = {
40+
unsubscribe: () => void
41+
}
42+
43+
export type SubscribeFn = <T extends SubscriptionTopic>(
44+
params: {
45+
topic: T
46+
args: SubscriptionArguments<T>
47+
onData: (data: SubscriptionData<T>) => void
48+
onError: (error: Error) => void
49+
},
50+
opts: {node: string}
51+
) => Promise<Subscription>

packages/typedefs/src/subscriptions.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)