@certik/skynet 0.13.1 → 0.14.0

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/.eslintignore ADDED
@@ -0,0 +1 @@
1
+ *.d.ts
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.14.0
4
+
5
+ - BREAKING: only start one DynamoDB client globally
6
+ - Type: Revisit and fix all existing typescript definition files
7
+
3
8
  ## 0.13.1
4
9
 
5
10
  - Added: s3 getFileSize (@certik/skynet/s3)
package/abi.d.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  type ContractIO = {
2
- name: string;
3
- type: string;
4
- internalType: string | undefined;
5
- components: ContractIO[];
2
+ name: string;
3
+ type: string;
4
+ internalType: string | undefined;
5
+ components: ContractIO[];
6
6
  };
7
7
 
8
8
  type ABI = {
9
- constant: boolean;
10
- inputs: ContractIO[];
11
- name: string;
12
- outputs: ContractIO[];
13
- payable: boolean;
14
- stateMutability: string;
15
- type: string;
9
+ constant: boolean;
10
+ inputs: ContractIO[];
11
+ name: string;
12
+ outputs: ContractIO[];
13
+ payable: boolean;
14
+ stateMutability: string;
15
+ type: string;
16
16
  }[];
17
17
 
18
18
  export const ERC20: ABI;
package/api.d.ts CHANGED
@@ -1,14 +1,12 @@
1
1
  import { Selector } from "./selector";
2
+ import { Route, Serve } from "./app";
3
+ import express from "express";
2
4
 
3
5
  export function startApiApp(params: {
4
- binaryName: string;
5
- name: string;
6
- selector: Selector;
7
- routes: string[];
8
- serve: {
9
- port: string | undefined;
10
- apiKey: string;
11
- prefix: string | undefined;
12
- };
13
- beforeListen: () => void;
6
+ binaryName: string;
7
+ name: string;
8
+ selector?: Selector;
9
+ routes: Route[];
10
+ serve: Serve;
11
+ beforeListen: (args: { app: ReturnType<typeof express> }) => void;
14
12
  }): void;
package/app.d.ts CHANGED
@@ -1,168 +1,174 @@
1
1
  import { ERROR_LEVEL } from "./monitor";
2
2
  import { Selector } from "./selector";
3
+ import express from "express";
3
4
 
4
5
  export type Env = {
5
- [key: string]: string | null
6
- }
6
+ [key: string]: string | null;
7
+ };
7
8
 
8
9
  export type Route = {
9
- method: "POST" | "PUT" | "PATCH" | "GET" | "POST" | "DELETE" | "OPTIONS";
10
- path: string;
11
- handler: ({ req, res }: { req: any, res: any }) => Promise<void>;
12
- protected: boolean;
13
- }
10
+ method?: "get" | "post" | "put" | "delete" | "patch";
11
+ path: string;
12
+ middlewares?: ((req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>)[];
13
+ handler: (args: { req: express.Request; res: express.Response; [key: string]: any }) => Promise<void>;
14
+ protected?: boolean;
15
+ };
14
16
 
15
17
  export type Serve = {
16
- prefix: string;
17
- port: number;
18
- apiKey: string;
19
- killTimeout: string;
20
- cpu: number;
21
- mem: number;
22
- instances: number;
23
- }
18
+ prefix: string;
19
+ port: number;
20
+ apiKey?: string;
21
+ killTimeout?: string;
22
+ cpu: number;
23
+ mem: number;
24
+ instances?: number;
25
+ };
24
26
 
25
27
  export type Consume = {
26
- func: ({ protocol, messages, verbose }: {
27
- protocol: string;
28
- messages: any;
29
- verbose: boolean;
30
- }) => Promise<void>;
31
- topic: ({ protocol }: { protocol: string }) => string;
32
- maxRetry: number;
33
- killTimeout: string;
34
- cpu: number;
35
- mem: number;
36
- }
28
+ func: ({ protocol, messages, verbose }: { protocol: string; messages: any; verbose: boolean }) => Promise<void>;
29
+ topic: ({ protocol }: { protocol: string }) => string;
30
+ maxRetry?: number;
31
+ killTimeout?: string;
32
+ cpu: number;
33
+ mem: number;
34
+ };
37
35
 
38
36
  export type State = {
39
- type: string;
40
- updateInterval: ({ protocol }: { protocol: string }) => number;
41
- getMinId: () => Promise<number>;
42
- getMaxId: ({ protocol }: { protocol: string }) => Promise<number>;
43
- }
37
+ type: string;
38
+ updateInterval: ({ protocol }: { protocol: string }) => number;
39
+ getMinId: () => Promise<number>;
40
+ getMaxId: ({ protocol }: { protocol: string }) => Promise<number>;
41
+ };
44
42
 
45
43
  export type Produce = {
46
- func: ({ protocol, from, to, verbose, send }: {
47
- protocol: string;
48
- from: number;
49
- to: number;
50
- verbose: boolean;
51
- send: (items: { id: string, name: string }[]) => Promise<void>;
52
- }) => Promise<void>;
53
- topic: ({ protocol }) => string;
54
- deadLetterTopic: ({ protocol }) => string;
55
- batchSize: number;
56
- maxRetry: number;
57
- killTimeout: string;
58
- cpu: number;
59
- mem: number;
60
- }
44
+ func: ({
45
+ protocol,
46
+ from,
47
+ to,
48
+ verbose,
49
+ send,
50
+ }: {
51
+ protocol: string;
52
+ from: number;
53
+ to: number;
54
+ verbose: boolean;
55
+ send: (items: { id: string; name: string }[]) => Promise<void>;
56
+ }) => Promise<void>;
57
+ topic: ({ protocol }) => string;
58
+ deadLetterTopic: ({ protocol }) => string;
59
+ batchSize: number;
60
+ maxRetry?: number;
61
+ killTimeout?: string;
62
+ cpu: number;
63
+ mem: number;
64
+ };
65
+
66
+ export type Schedule = string | ((jobName: string) => string);
61
67
 
62
68
  export type Check = {
63
- func: ({ protocol, state, verbose }: { protocol: string, state: string, verbose: boolean })
64
- => ({ type: string, message: string });
65
- schedule: string;
66
- slackChannel: string;
67
- killTimeout: string;
68
- cpu: number;
69
- mem: number;
70
- }
69
+ func: ({ protocol, state, verbose }: { protocol: string; state: string; verbose: boolean }) => {
70
+ type: string;
71
+ message: string;
72
+ };
73
+ schedule: Schedule;
74
+ slackChannel: string;
75
+ killTimeout?: string;
76
+ cpu: number;
77
+ mem: number;
78
+ };
71
79
 
72
80
  export type Build = {
73
- func: ({ protocol, from, to, verbose }: { protocol: string, from: number, to: number, verbose: boolean })
74
- => void;
75
- batchSize: number;
76
- schedule: string;
77
- killTimeout: string;
78
- cpu: number;
79
- mem: number;
80
- }
81
+ func: ({ protocol, from, to, verbose }: { protocol: string; from: number; to: number; verbose: boolean }) => void;
82
+ batchSize: number;
83
+ schedule: Schedule;
84
+ killTimeout?: string;
85
+ cpu: number;
86
+ mem: number;
87
+ };
81
88
 
82
89
  export type Restart = {
83
- attempts: number | undefined;
84
- mode: string | undefined;
85
- interval: string | undefined;
86
- delay: string | undefined
87
- }
90
+ attempts: number | undefined;
91
+ mode: string | undefined;
92
+ interval: string | undefined;
93
+ delay: string | undefined;
94
+ };
88
95
 
89
96
  export type Validate = {
90
- func: ({ protocol, from, to, verbose }: { protocol: string, from: number, to: number, verbose: boolean })
91
- => void;
92
- batchSize: number;
93
- schedule: string;
94
- killTimeout: string;
95
- cpu: number;
96
- mem: number;
97
- }
97
+ func: ({ protocol, from, to, verbose }: { protocol: string; from: number; to: number; verbose: boolean }) => void;
98
+ batchSize: number;
99
+ schedule: Schedule;
100
+ killTimeout?: string;
101
+ cpu: number;
102
+ mem: number;
103
+ };
104
+
105
+ type BuildWithRestart = Build & { restart: Restart | undefined };
98
106
 
99
- type BuildWithConcurrency = Build | { concurrency: number | undefined };
107
+ type BuildWithConcurrency = Build & { concurrency: number | undefined };
100
108
 
101
- type ValidateWithConcurrency = Validate | { concurrency: number | undefined };
109
+ type ValidateWithConcurrency = Validate & { concurrency: number | undefined };
102
110
 
103
111
  export const SENSITIVE_VALUE: null;
104
112
 
105
113
  export { ERROR_LEVEL };
106
114
 
107
115
  export function every(n: number | undefined): {
108
- second: string
109
- seconds: string,
110
- minute: string,
111
- minutes: string,
112
- hour: string,
113
- hours: string,
114
- day: string,
115
- days: string,
116
- week: string,
117
- weeks: string,
118
- }
116
+ second: string;
117
+ seconds: string;
118
+ minute: string;
119
+ minutes: string;
120
+ hour: string;
121
+ hours: string;
122
+ day: string;
123
+ days: string;
124
+ week: string;
125
+ weeks: string;
126
+ };
119
127
 
120
128
  export function api(apiParams: {
121
- name: string;
122
- routes: Route[];
123
- serve: Serve;
124
- env: Env | undefined;
125
- region: string | undefined;
126
- beforeListen: () => void;
129
+ name: string;
130
+ routes: Route[];
131
+ serve: Serve;
132
+ env: Env | undefined;
133
+ region: string | undefined;
134
+ beforeListen: (args: { app: ReturnType<typeof express> }) => void;
127
135
  }): () => void;
128
136
 
129
137
  export function consumer(consumerParams: {
130
- name: string;
131
- selector: Selector;
132
- consume: Consume;
133
- check: Check;
134
- env: Env | undefined;
135
- region: string | undefined;
138
+ name: string;
139
+ selector?: Selector;
140
+ consume: Consume;
141
+ check?: Check;
142
+ env: Env | undefined;
143
+ region: string | undefined;
136
144
  }): () => void;
137
145
 
138
146
  export function producer(producerParams: {
139
- name: string;
140
- selector: Selector;
141
- produce: Produce;
142
- check: Check;
143
- state: State;
144
- env: Env | undefined;
145
- region: string | undefined;
147
+ name: string;
148
+ selector?: Selector;
149
+ produce: Produce;
150
+ check?: Check;
151
+ state: State;
152
+ env?: Env;
153
+ region?: string;
146
154
  }): () => void;
147
155
 
148
156
  export function indexer(indexerParams: {
149
- name: string;
150
- selector: Selector;
151
- state: State;
152
- build: Build | { restart: Restart | undefined };
153
- validate: Validate;
154
- check: Check;
155
- env: Env | undefined;
156
- region: string | undefined;
157
+ name: string;
158
+ selector?: Selector;
159
+ build: BuildWithRestart;
160
+ check?: Check;
161
+ env?: Env;
162
+ region?: string;
157
163
  }): () => void;
158
164
 
159
165
  export function modeIndexer(modeIndexerParams: {
160
- name: string;
161
- selector: Selector;
162
- state: State;
163
- build: BuildWithConcurrency;
164
- validate: ValidateWithConcurrency;
165
- check: Check;
166
- env: Env | undefined;
167
- region: string | undefined;
166
+ name: string;
167
+ selector?: Selector;
168
+ state: State;
169
+ build: BuildWithConcurrency;
170
+ validate?: ValidateWithConcurrency;
171
+ check?: Check;
172
+ env?: Env;
173
+ region?: string;
168
174
  }): () => void;
package/availability.d.ts CHANGED
@@ -1,11 +1,18 @@
1
- export function wait(time: number | undefined): Promise<void>;
1
+ export function wait(time: number): Promise<void>;
2
2
  export function retry(times: number, verbose: boolean, func: Function): Promise<void>;
3
- export function exponentialRetry<T>(func: () => Promise<T>, { maxRetry, initialDuration, growFactor, test, verbose }:
4
- {
5
- maxRetry: number,
6
- initialDuration: number | undefined,
7
- growFactor: number | undefined,
8
- test: (result: T) => boolean,
9
- verbose: boolean
10
- }
3
+ export function exponentialRetry<T>(
4
+ func: () => Promise<T>,
5
+ {
6
+ maxRetry,
7
+ initialDuration,
8
+ growFactor,
9
+ test,
10
+ verbose,
11
+ }: {
12
+ maxRetry: number;
13
+ initialDuration?: number;
14
+ growFactor?: number;
15
+ test: (result: T) => boolean;
16
+ verbose?: boolean;
17
+ },
11
18
  ): Promise<T>;
package/bun.lockb CHANGED
Binary file
package/const.d.ts CHANGED
@@ -1,42 +1,43 @@
1
1
  type Protocol = {
2
- nativeTokenName: string,
3
- nativeTokenSymbol: string,
4
- nativeTokenDecimals: number,
5
- nativeTokenAddress: string,
6
- nativeTokenLogo: string,
7
- nativeTokenCoinGeckoId: string,
8
- nativeTokenCmcId: number,
9
- endpoint: string,
10
- backupEndpoint?: string,
11
- archiveEndpoint?: string,
12
- tokenStandard: string,
13
- scanApi?: {
14
- endpoint: string,
15
- key: string,
16
- },
17
- multiCallProvider?: string,
18
- scanUrl?: string,
19
- }
2
+ nativeTokenName: string;
3
+ nativeTokenSymbol: string;
4
+ nativeTokenDecimals: number;
5
+ nativeTokenAddress: string;
6
+ nativeTokenLogo: string;
7
+ nativeTokenCoinGeckoId: string;
8
+ nativeTokenCmcId: number;
9
+ endpoint: string;
10
+ backupEndpoint?: string;
11
+ archiveEndpoint?: string;
12
+ tokenStandard: string;
13
+ scanApi?: {
14
+ endpoint: string;
15
+ key: string;
16
+ };
17
+ multiCallProvider?: string;
18
+ scanUrl?: string;
19
+ };
20
20
 
21
21
  type TimeIntervals = {
22
- MINUTE: number,
23
- HOUR: number,
24
- DAY: number,
25
- WEEK: number,
26
- YEAR: number,
27
- }
22
+ SECOND: number;
23
+ MINUTE: number;
24
+ HOUR: number;
25
+ DAY: number;
26
+ WEEK: number;
27
+ YEAR: number;
28
+ };
28
29
 
29
30
  export const SKYNET_API_PREFIX: string;
30
31
  export const PROTOCOLS: {
31
- eth: Protocol,
32
- bsc: Protocol,
33
- polygon: Protocol,
34
- heco: Protocol,
35
- avax: Protocol,
36
- ftm: Protocol,
37
- algo: Protocol
38
- }
32
+ eth: Protocol;
33
+ bsc: Protocol;
34
+ polygon: Protocol;
35
+ heco: Protocol;
36
+ avax: Protocol;
37
+ ftm: Protocol;
38
+ algo: Protocol;
39
+ };
39
40
  export const TIME: {
40
- BY_MS: TimeIntervals,
41
- BY_S: TimeIntervals,
42
- }
41
+ BY_MS: TimeIntervals;
42
+ BY_S: TimeIntervals;
43
+ };
package/const.js CHANGED
@@ -129,6 +129,7 @@ const TIME = {
129
129
  YEAR: 1000 * 60 * 60 * 24 * 365,
130
130
  },
131
131
  BY_S: {
132
+ SECOND: 1,
132
133
  MINUTE: 60,
133
134
  HOUR: 60 * 60,
134
135
  DAY: 60 * 60 * 24,
@@ -137,8 +138,4 @@ const TIME = {
137
138
  },
138
139
  };
139
140
 
140
- export {
141
- SKYNET_API_PREFIX,
142
- PROTOCOLS,
143
- TIME,
144
- };
141
+ export { SKYNET_API_PREFIX, PROTOCOLS, TIME };
package/deploy.d.ts CHANGED
@@ -4,40 +4,48 @@ import { Env, Selector, Check, Restart } from "./app";
4
4
  type Service = {
5
5
  prefix: string;
6
6
  port: number;
7
- }
7
+ };
8
8
 
9
9
  type CreateDeployBaseParams = {
10
- binaryName: string,
11
- name: string,
12
- workingDirectory: string,
13
- bin: string | undefined,
14
- selector: Selector | undefined,
15
- env: Env | undefined,
16
- region: string | undefined,
17
- type: string | undefined,
18
- count: number | undefined,
19
- check: Check,
20
- }
10
+ binaryName: string;
11
+ name: string;
12
+ workingDirectory: string;
13
+ bin?: string;
14
+ selector?: Selector;
15
+ env?: Env;
16
+ region?: string;
17
+ check?: Check;
18
+ };
21
19
 
22
20
  export { getJobName };
23
21
 
24
22
  export function getNomadAddr(isProduction: boolean): Promise<string | undefined>;
25
23
 
26
- export function createModeDeploy(createModeDeployParams: CreateDeployBaseParams | {
27
- deltaSchedule: string,
28
- validateSchedule: string,
29
- deltaCpu: number,
30
- deltaMem: number,
31
- rebuildCpu: number,
32
- rebuildMem: number,
33
- validateCpu: number,
34
- validateMem: number,
35
- }): { deploy: () => void };
24
+ export function createModeDeploy(
25
+ createModeDeployParams: CreateDeployBaseParams & {
26
+ deltaSchedule: string;
27
+ validateSchedule: string;
28
+ deltaKillTimeout?: number;
29
+ deltaCpu: number;
30
+ deltaMem: number;
31
+ rebuildKillTimeout?: number;
32
+ rebuildCpu: number;
33
+ rebuildMem: number;
34
+ validateKillTimeout?: number;
35
+ validateCpu?: number;
36
+ validateMem?: number;
37
+ },
38
+ ): { deploy: () => void };
36
39
 
37
- export function createDeploy(createDeployParams: CreateDeployBaseParams | {
38
- schedule: string,
39
- restart: Restart | undefined,
40
- cpu: number,
41
- mem: number,
42
- service: Service,
43
- }): { deploy: () => void };
40
+ export function createDeploy(
41
+ createDeployParams: CreateDeployBaseParams & {
42
+ type?: string;
43
+ count?: number;
44
+ schedule: string;
45
+ restart?: Restart;
46
+ cpu: number;
47
+ mem: number;
48
+ killTimeout?: number;
49
+ service: Service;
50
+ },
51
+ ): { deploy: () => void };
package/dynamodb.d.ts CHANGED
@@ -1,67 +1,63 @@
1
- import { DynamoDB } from "aws-sdk";
1
+ import { ScanCommandInput, PutCommandOutput, UpdateCommandOutput } from "@aws-sdk/lib-dynamodb";
2
2
 
3
- type Keys = { [key: string]: any };
3
+ import { CreateTableInput, CreateTableOutput } from "@aws-sdk/client-dynamodb";
4
4
 
5
- type Fields = { [key: string]: any };
5
+ export function getDocClient(forceNew?: boolean): DynamoDBDocumentClient;
6
6
 
7
- export function getDocClient(): DynamoDB.DocumentClient;
8
-
9
- export function scanWholeTable(options: DynamoDB.DocumentClient.ScanInput):
10
- Promise<{
11
- Items: any[];
12
- Count: number;
13
- ScannedCount: number;
7
+ export function scanWholeTable<T>(options: ScanCommandInput): Promise<{
8
+ Items: T[];
9
+ Count: number;
10
+ ScannedCount: number;
14
11
  }>;
15
12
 
16
- export function batchCreateRecords(
17
- tableName: string,
18
- records: any[],
19
- maxWritingCapacity: number,
20
- verbose: boolean | undefined
13
+ export function batchCreateRecords<T>(
14
+ tableName: string,
15
+ records: T[],
16
+ maxWritingCapacity: number,
17
+ verbose?: boolean,
21
18
  ): Promise<void>;
22
19
 
23
- export function createRecord(
24
- tableName: string,
25
- fields: Fields,
26
- verbose: boolean | undefined
27
- ): Promise<void>;
20
+ export function createRecord<T>(tableName: string, fields: T, verbose?: boolean): Promise<PutCommandOutput>;
28
21
 
29
- export function getRecordsByKey(
30
- tableName: string,
31
- keys: Keys,
32
- indexName: string
33
- ): Promise<DynamoDB.DocumentClient.ItemList | null | undefined>;
22
+ export function getRecordsByKey<TReturn, TKey>(tableName: string, keys: TKey, indexName: string): Promise<TReturn[]>;
34
23
 
35
- export function getRecordByKey(
36
- tableName: string,
37
- keys: Keys,
38
- indexName: string
39
- ): Promise<DynamoDB.DocumentClient.AttributeMap | null>;
24
+ export function getRecordByKey<TReturn, TKey>(
25
+ tableName: string,
26
+ keys: TKey,
27
+ indexName: string,
28
+ ): Promise<TReturn | null>;
40
29
 
41
- export function updateRecordByKey(
42
- tableName: string,
43
- idKey: Keys,
44
- fields: Fields,
45
- conditionExpressions: string | undefined,
46
- verbose: boolean | undefined
47
- ): Promise<DynamoDB.DocumentClient.AttributeMap | undefined>;
30
+ export function updateRecordByKey<TKey, TField>(
31
+ tableName: string,
32
+ idKey: TKey,
33
+ fields: TField,
34
+ conditionExpressions?: string,
35
+ verbose?: boolean,
36
+ ): Promise<UpdateCommandOutput["Attributes"] | false>;
48
37
 
49
- export function batchDeleteRecords(
50
- tableName: string,
51
- keys: Keys
52
- ): Promise<void>;
38
+ export function batchDeleteRecords<T>(tableName: string, keys: T): Promise<void>;
53
39
 
54
40
  export function deleteRecordsByHashKey(
55
- tableName: string,
56
- indexName: string | undefined,
57
- hashKeyValue: string,
58
- verbose: boolean | undefined
41
+ tableName: string,
42
+ indexName?: string,
43
+ hashKeyValue: string,
44
+ verbose?: boolean,
59
45
  ): Promise<number>;
60
46
 
61
47
  export function createTableIfNotExist(
62
- tableName: string,
63
- attributeDefinitions: DynamoDB.AttributeDefinitions,
64
- keySchema: DynamoDB.KeySchema,
65
- options: DynamoDB.DocumentClient.CreateTableInput,
66
- verbose: boolean | undefined
67
- ): Promise<void>
48
+ tableName: string,
49
+ attributeDefinitions: CreateTableInput["AttributeDefinitions"],
50
+ keySchema: CreateTableInput["KeySchema"],
51
+ options?: Partial<CreateTableInput>,
52
+ verbose?: boolean,
53
+ ): Promise<CreateTableOutput>;
54
+
55
+ export {
56
+ DynamoDBDocumentClient,
57
+ ScanCommand,
58
+ BatchWriteCommand,
59
+ GetCommand,
60
+ PutCommand,
61
+ QueryCommand,
62
+ UpdateCommand,
63
+ } from "@aws-sdk/lib-dynamodb";
package/dynamodb.js CHANGED
@@ -11,12 +11,22 @@ import { DynamoDBClient, DescribeTableCommand } from "@aws-sdk/client-dynamodb";
11
11
  import { getAWSSDKConfig } from "./env.js";
12
12
  import { wait } from "./availability.js";
13
13
 
14
- function getDynamoDB() {
15
- return new DynamoDBClient(getAWSSDKConfig());
14
+ let _dynamoDB;
15
+
16
+ let _docClient;
17
+
18
+ function getDynamoDB(forceNew = false) {
19
+ if (!_dynamoDB || forceNew) {
20
+ _dynamoDB = new DynamoDBClient(getAWSSDKConfig());
21
+ }
22
+ return _dynamoDB;
16
23
  }
17
24
 
18
- function getDocClient() {
19
- return DynamoDBDocumentClient.from(new DynamoDBClient(getAWSSDKConfig()));
25
+ function getDocClient(forceNew = false) {
26
+ if (!_docClient || forceNew) {
27
+ _docClient = DynamoDBDocumentClient.from(getDynamoDB());
28
+ }
29
+ return _docClient;
20
30
  }
21
31
 
22
32
  function mergeQueries(q1, q2) {
package/env.d.ts CHANGED
@@ -2,10 +2,15 @@ export function ensureAndGet<T>(envName: string, defaultValue: T): string | T;
2
2
  export function getEnvOrThrow(envName: string): string;
3
3
  export function getAWSAccessKeyId(): string | undefined;
4
4
  export function getAWSSecretAccessKey(): string | undefined;
5
+ export function getAWSSDKConfig(): {
6
+ region: string;
7
+ credentials?: {
8
+ accessKeyId: string;
9
+ secretAccessKey: string;
10
+ };
11
+ };
5
12
  export function getAWSRegion(): string;
6
13
  export function getEnvironment(): string;
7
- export function getGetBlockApiKey(): string | undefined;
8
- export function getAlchemyApiKey(identifier: string): string | undefined;
9
14
  export function getNodeRealApiKey(identifier: string): string | undefined;
10
15
  export function isProduction(): boolean;
11
16
  export function isDev(): boolean;
package/indexer.d.ts CHANGED
@@ -5,21 +5,23 @@ import { Build, State, Validate } from "./app";
5
5
  import { SelectorFlags, Selector } from "./selector";
6
6
 
7
7
  type CreateIndexerAppBaseParams = {
8
- binaryName: string,
9
- name: string,
10
- selector: Selector | undefined,
11
- build: Build,
12
- maxRetry: number
13
- }
8
+ binaryName: string;
9
+ name: string;
10
+ selector?: Selector;
11
+ build: Build;
12
+ maxRetry?: number;
13
+ };
14
14
 
15
- export function createModeIndexerApp(createModeIndexerAppParams: {
16
- buildBatchSize: number | undefined,
17
- buildConcurrency: number | undefined,
18
- validate: Validate,
19
- validateBatchSize: number | undefined,
20
- validateConcurrency: number | undefined,
21
- state: State,
22
- } | CreateIndexerAppBaseParams): { run: () => void };
15
+ export function createModeIndexerApp(
16
+ createModeIndexerAppParams: {
17
+ buildBatchSize?: number;
18
+ buildConcurrency?: number;
19
+ validate?: Validate;
20
+ validateBatchSize?: number;
21
+ validateConcurrency?: number;
22
+ state: State;
23
+ } & CreateIndexerAppBaseParams,
24
+ ): { run: () => void };
23
25
 
24
26
  export function createIndexerApp(createModeIndexerAppParams: CreateIndexerAppBaseParams): { run: () => void };
25
27
 
package/kafka.d.ts CHANGED
@@ -1,39 +1,31 @@
1
1
  import { KafkaMessage } from "kafkajs";
2
- import { Producer, State } from "./app";
2
+ import { Produce, Consume, State } from "./app";
3
3
  import { SelectorFlags, Selector } from "./selector";
4
4
 
5
5
  export function createProducerApp(createProducerAppParams: {
6
- binaryName: string,
7
- name: string,
8
- selector: Selector | undefined,
9
- producer: Producer,
10
- state: State
6
+ binaryName: string;
7
+ name: string;
8
+ selector?: Selector;
9
+ producer: Produce;
10
+ state: State;
11
11
  }): { run: () => Promise<void> };
12
12
 
13
13
  export function createConsumerApp(createConsumerAppParams: {
14
- binaryName: string,
15
- name: string,
16
- selector: Selector | undefined,
17
- consumer: Consumer
14
+ binaryName: string;
15
+ name: string;
16
+ selector?: Selector;
17
+ consumer: Consume;
18
18
  }): { run: () => Promise<void> };
19
19
 
20
20
  export function produceMessages(
21
- producerId: string,
22
- callback: (
23
- send: (topic: any, messages: any) => Promise<void>
24
- ) => Promise<void>
21
+ producerId: string,
22
+ callback: (send: <T>(topic: string, messages: T) => Promise<void>) => Promise<void>,
25
23
  ): Promise<void>;
26
24
 
27
25
  export function consumeMessages(
28
- consumerId: string,
29
- topic: string | RegExp,
30
- callback: (
31
- message: KafkaMessage,
32
- stopConsumeMessages: () => Promise<void>
33
- ) => Promise<void>
26
+ consumerId: string,
27
+ topic: string | RegExp,
28
+ callback: (message: KafkaMessage, stopConsumeMessages: () => Promise<void>) => Promise<void>,
34
29
  ): Promise<() => Promise<void>>;
35
30
 
36
- export function getProducerLatestId(
37
- name: string,
38
- selectorFlags: SelectorFlags
39
- ): Promise<number>;
31
+ export function getProducerLatestId(name: string, selectorFlags: SelectorFlags): Promise<number>;
package/log.d.ts CHANGED
@@ -1,5 +1,8 @@
1
+ export function getLine(params: any[]): string;
2
+
1
3
  export function print(o: any): string;
4
+
2
5
  export const inline: {
3
- log: (...args: any[]) => void,
4
- error: (...args: any[]) => void
6
+ log: (...args: any[]) => void;
7
+ error: (...args: any[]) => void;
5
8
  };
package/monitor.d.ts CHANGED
@@ -2,23 +2,23 @@ import { Check } from "./app";
2
2
  import { SelectorFlags, Selector } from "./selector";
3
3
 
4
4
  export const ERROR_LEVEL: {
5
- INFO: string,
6
- CRITICAL: string,
7
- WARNING: string
5
+ INFO: string;
6
+ CRITICAL: string;
7
+ WARNING: string;
8
8
  };
9
9
 
10
10
  export const LEVEL_EMOJI: {
11
- Info: string,
12
- Critical: string,
13
- Warning: string
11
+ Info: string;
12
+ Critical: string;
13
+ Warning: string;
14
14
  };
15
15
 
16
16
  export function createMonitor(createMonitorParams: {
17
- binaryName: string,
18
- name: string,
19
- getState: ((name: string, selectorFlags: SelectorFlags) => Promise<void>) | undefined,
20
- mode: boolean | undefined,
21
- selector: Selector,
22
- check: Check,
23
- maxRetry: number | undefined
17
+ binaryName: string;
18
+ name: string;
19
+ getState?: (name: string, selectorFlags: SelectorFlags) => Promise<void>;
20
+ mode?: boolean;
21
+ selector?: Selector;
22
+ check?: Check;
23
+ maxRetry?: number;
24
24
  }): { monitor: () => void };
package/opensearch.d.ts CHANGED
@@ -4,13 +4,13 @@ export declare function newOpensearchClient(
4
4
  endpoint: string,
5
5
  key: string,
6
6
  secret: string,
7
- options?: ClientOptions
7
+ options?: ClientOptions,
8
8
  ): Client;
9
9
 
10
- export declare async function sendToOpensearch(
10
+ export declare async function sendToOpensearch<T>(
11
11
  client: Client,
12
12
  appName: string,
13
13
  index: string,
14
14
  record: string,
15
- indexSuffixes?: string[]
16
- ): Promise<{ status: string; result: Object }>;
15
+ indexSuffixes?: string[],
16
+ ): Promise<{ status: string; result: T }>;
package/opsgenie.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export function postGenieMessage(
2
- body: any | {
3
- alias: string,
4
- message: string
5
- },
6
- verbose: boolean
7
- ): Promise<{ result: string }>;
1
+ export function postGenieMessage<T>(
2
+ body: {
3
+ alias?: string;
4
+ message: string;
5
+ },
6
+ verbose?: boolean,
7
+ ): Promise<{ result: T }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.13.1",
3
+ "version": "0.14.0",
4
4
  "description": "Skynet Shared JS library",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -8,7 +8,7 @@
8
8
  "scripts": {
9
9
  "lint": "eslint *.js test",
10
10
  "test": "doppler run -- ava --timeout=1m",
11
- "format": "prettier --write '*.js' '**/*.js'",
11
+ "format": "prettier --write '*.js' '**/*.js' '*.d.ts' '**/*.d.ts'",
12
12
  "pub": "npm publish --access public"
13
13
  },
14
14
  "engines": {
@@ -43,4 +43,4 @@
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  }
46
- }
46
+ }
package/proxy.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  type Options = {
2
- verbose: boolean;
3
- timeout: number;
4
- headers: {
5
- [header: string]: string;
6
- }
7
- } | RequestInit;
2
+ verbose: boolean;
3
+ timeout: number;
4
+ headers: {
5
+ [header: string]: string;
6
+ };
7
+ } & RequestInit;
8
8
 
9
- export default function proxyFetch(url: string, options: Partial<Options> | undefined): Promise<Response>;
9
+ export default function proxyFetch(url: string, options?: Partial<Options>): Promise<Response>;
package/s3.d.ts CHANGED
@@ -1,16 +1,36 @@
1
- import { S3 } from "aws-sdk";
1
+ import {
2
+ S3Client,
3
+ GetObjectCommand,
4
+ HeadObjectCommand,
5
+ PutObjectCommand,
6
+ DeleteObjectCommand,
7
+ ListObjectsV2Command,
8
+ NotFound,
9
+ } from "@aws-sdk/client-s3";
2
10
 
3
11
  type WriteOptions = {
4
- verbose: boolean;
5
- acl: string;
6
- skipIfExists: boolean;
7
- }
12
+ verbose: boolean;
13
+ acl: string;
14
+ skipIfExists: boolean;
15
+ contentType: string;
16
+ };
8
17
 
9
- export function getS3(): S3;
10
- export function readFile(bucketName: string, key: string, verbose: boolean | undefined): Promise<string | null>;
18
+ export function getS3(): S3Client;
19
+ export function readFile(bucketName: string, key: string, verbose?: boolean): Promise<string | null>;
11
20
  export function hasFile(bucketName: string, key: string): Promise<boolean>;
12
- export function writeFile(bucketName: string, key: string, body: any, options: Partial<WriteOptions> | undefined): Promise<void>;
13
- export function deleteFile(bucketName: string, key: string, verbose: boolean | undefined): Promise<void>;
14
- export function listKeys(bucketname: string, prefix: string, continuationToken: string | undefined): Promise<{
15
- keys: (string | undefined)[];
21
+ export function getFileSize(bucketName: string, key: string): Promise<number>;
22
+ export function writeFile(
23
+ bucketName: string,
24
+ key: string,
25
+ body: string,
26
+ options?: Partial<WriteOptions>,
27
+ ): Promise<void>;
28
+ export function deleteFile(bucketName: string, key: string, verbose?: boolean): Promise<void>;
29
+ export function listKeys(
30
+ bucketname: string,
31
+ prefix: string,
32
+ continuationToken?: string,
33
+ ): Promise<{
34
+ keys: string[];
35
+ continuationToken: string | null;
16
36
  } | null>;
package/selector.d.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  export type SelectorFlags = {
2
- [flag: string]: string;
3
- }
2
+ [flag: string]: string;
3
+ };
4
4
 
5
5
  export type Selector = {
6
- [key: string]: {
7
- type: string;
8
- description: string | undefined;
9
- desc: string | undefined;
10
- alias: string | undefined,
11
- isRequired: boolean | undefined,
12
- default: string | boolean | undefined;
13
- }
14
- }
6
+ [key: string]: {
7
+ type?: "string" | "number" | "boolean" | string;
8
+ description?: string;
9
+ desc?: string;
10
+ alias?: string;
11
+ isRequired?: boolean;
12
+ default?: any;
13
+ };
14
+ };
15
15
 
16
- export function getJobName(name: string, selectorFlags: SelectorFlags, mode: string | undefined): string;
16
+ export function getJobName(name: string, selectorFlags: SelectorFlags, mode?: string): string;
17
17
  export function getSelectorDesc(selector: Selector): string;
18
18
  export function getSelectorFlags(selector: Selector): SelectorFlags;
19
- export function toSelectorString(selectorFlags: SelectorFlags, delim: string | undefined): string;
19
+ export function toSelectorString(selectorFlags: SelectorFlags, delim?: string): string;
package/slack.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { WebClient } from "@slack/web-api";
1
+ import { ChatPostMessageArguments } from "@slack/web-api";
2
2
 
3
- type ChannelConfig = {
4
- name: string;
5
- id: string;
6
- };
3
+ interface PostMessageParams {
4
+ conversationId: string;
5
+ message: string | Partial<ChatPostMessageArguments>;
6
+ token: string;
7
+ verbose?: boolean;
8
+ }
7
9
 
8
- export function getClient(): WebClient;
9
- export function findConversation(client: WebClient, name: string): Promise<string | null>;
10
- export function postMessage(channel: string | ChannelConfig, message: any, verbose: boolean): Promise<void>;
10
+ async function postMessageToConversation(params: PostMessageParams): Promise<void>;
package/snowflake.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { ConnectionOptions, Connection, Binds } from "snowflake-sdk";
2
2
 
3
3
  export function getConnection(options: ConnectionOptions): Promise<Connection>;
4
- export function executeSql(options: ConnectionOptions, sql: string, binds: Binds): Promise<any[]>;
4
+ export function executeSql<T>(options: ConnectionOptions, sql: string, binds?: Binds): Promise<T[]>;
package/sqs.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { SQS } from "aws-sdk";
1
+ import { SQSClient } from "@aws-sdk/client-sqs";
2
2
 
3
- export function getSQS(): SQS;
3
+ export function getSQS(): SQSClient;
package/util.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export function arrayGroup<T>(array:T[], groupSize: number): T[][];
1
+ export function arrayGroup<T>(array: T[], groupSize: number): T[][];
2
2
  export function partition(startAt: number, endAt: number, numGroups: number): [number, number][];
3
3
  export function range(startAt: number, endAt: number, step: number): [number, number][];
4
4
  export function fillRange(startAt: number, endAt: number): number[];
package/web3.d.ts CHANGED
@@ -2,22 +2,24 @@ import Bottleneck from "bottleneck";
2
2
  import Web3 from "web3";
3
3
  import { ABI } from "./abi";
4
4
 
5
- type Call = {
6
- params: any | any[],
7
- functionName: string | undefined,
8
- target: string | undefined
9
- } | any[];
5
+ type Call =
6
+ | {
7
+ params: any | any[];
8
+ functionName?: string;
9
+ target?: string;
10
+ }
11
+ | any[];
10
12
 
11
- export function newWeb3ByProtocol(protocol: string): Web3
13
+ export function newWeb3ByProtocol(protocol: string): Web3;
12
14
  export function singleCall(protocol: string, abi: ABI, target: string, params: any[]): Promise<any>;
13
15
  export function multiCall(multiCallParams: {
14
- protocol: string;
15
- limiter: Bottleneck | undefined;
16
- target: string;
17
- abi: ABI;
18
- calls: Call[];
16
+ protocol: string;
17
+ limiter?: Bottleneck;
18
+ target: string;
19
+ abi: ABI;
20
+ calls: Call[];
19
21
  }): Promise<{
20
- callCount: number;
21
- actualCallCount: number | undefined;
22
- output: any[];
22
+ callCount: number;
23
+ actualCallCount?: number;
24
+ output: any[];
23
25
  }>;