@certik/skynet 0.18.9 → 0.19.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/.vscode/settings.json +5 -0
- package/CHANGELOG.md +9 -0
- package/README.md +2 -2
- package/{abi.js → abi.ts} +5 -132
- package/{address.js → address.ts} +4 -4
- package/{api.js → api.ts} +79 -19
- package/{app.js → app.ts} +138 -25
- package/{availability.js → availability.ts} +18 -21
- package/bun.lockb +0 -0
- package/{cli.js → cli.ts} +1 -1
- package/{const.js → const.ts} +42 -3
- package/databricks.ts +82 -0
- package/{date.js → date.ts} +5 -5
- package/{deploy.js → deploy.ts} +157 -44
- package/{dynamodb.js → dynamodb.ts} +159 -186
- package/env.ts +25 -0
- package/eslint.config.mjs +7 -0
- package/examples/{api.js → api.ts} +7 -6
- package/examples/{indexer.js → indexer.ts} +9 -10
- package/examples/{mode-indexer.js → mode-indexer.ts} +18 -10
- package/graphql.ts +43 -0
- package/{indexer.js → indexer.ts} +228 -109
- package/{log.js → log.ts} +6 -6
- package/{opsgenie.js → opsgenie.ts} +29 -6
- package/package.json +17 -11
- package/{s3.js → s3.ts} +29 -19
- package/search.ts +37 -0
- package/selector.ts +72 -0
- package/{slack.js → slack.ts} +19 -12
- package/snowflake.ts +51 -0
- package/tsconfig.json +26 -0
- package/util.ts +35 -0
- package/web3.ts +41 -0
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -20
- package/abi.d.ts +0 -20
- package/address.d.ts +0 -2
- package/api.d.ts +0 -12
- package/app.d.ts +0 -118
- package/availability.d.ts +0 -18
- package/cli.d.ts +0 -4
- package/const.d.ts +0 -42
- package/databricks.js +0 -82
- package/deploy.d.ts +0 -51
- package/dns.d.ts +0 -1
- package/dns.js +0 -27
- package/dynamodb.d.ts +0 -63
- package/env.d.ts +0 -6
- package/env.js +0 -42
- package/examples/consumer.js +0 -30
- package/examples/producer.js +0 -63
- package/graphql.d.ts +0 -3
- package/graphql.js +0 -22
- package/indexer.d.ts +0 -32
- package/log.d.ts +0 -8
- package/opsgenie.d.ts +0 -8
- package/proxy.d.ts +0 -9
- package/proxy.js +0 -154
- package/s3.d.ts +0 -36
- package/search.d.ts +0 -5
- package/search.js +0 -29
- package/selector.d.ts +0 -19
- package/selector.js +0 -71
- package/slack.d.ts +0 -10
- package/snowflake.d.ts +0 -4
- package/snowflake.js +0 -33
- package/sqs.d.ts +0 -3
- package/sqs.js +0 -5
- package/util.d.ts +0 -5
- package/util.js +0 -61
- package/web3.d.ts +0 -25
- package/web3.js +0 -113
package/proxy.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
const PROXY_INSTANCES = [
|
|
2
|
-
"https://uer87capga.execute-api.us-east-1.amazonaws.com/", // 0
|
|
3
|
-
"https://t7utq0a5hb.execute-api.us-east-1.amazonaws.com/",
|
|
4
|
-
"https://3n8prspdj7.execute-api.us-east-1.amazonaws.com/",
|
|
5
|
-
"https://u2yvkoxcij.execute-api.us-east-1.amazonaws.com/",
|
|
6
|
-
"https://am6yzsqgsj.execute-api.us-east-1.amazonaws.com/",
|
|
7
|
-
"https://7bgxb3dza0.execute-api.us-east-1.amazonaws.com/",
|
|
8
|
-
"https://f46a3arqm0.execute-api.us-east-1.amazonaws.com/",
|
|
9
|
-
"https://07hvmxo9u3.execute-api.us-east-1.amazonaws.com/",
|
|
10
|
-
"https://rwj17dzple.execute-api.us-east-1.amazonaws.com/",
|
|
11
|
-
"https://siqmv1wrj1.execute-api.us-east-1.amazonaws.com/",
|
|
12
|
-
"https://hz9vj47r66.execute-api.us-east-1.amazonaws.com/", // 10
|
|
13
|
-
"https://edqblj52qh.execute-api.us-east-1.amazonaws.com/",
|
|
14
|
-
"https://bt990cdkkc.execute-api.us-east-1.amazonaws.com/",
|
|
15
|
-
"https://9pqoo01160.execute-api.us-east-1.amazonaws.com/",
|
|
16
|
-
"https://kg2swyefu3.execute-api.us-east-1.amazonaws.com/",
|
|
17
|
-
"https://hjtezlyp5h.execute-api.us-east-1.amazonaws.com/",
|
|
18
|
-
"https://uv9tqbu127.execute-api.us-east-1.amazonaws.com/",
|
|
19
|
-
"https://hypj6yxuif.execute-api.us-east-1.amazonaws.com/",
|
|
20
|
-
"https://q8rwozuheh.execute-api.us-east-1.amazonaws.com/",
|
|
21
|
-
"https://owk290z9a8.execute-api.us-east-1.amazonaws.com/",
|
|
22
|
-
"https://rqjqjvz7d6.execute-api.us-east-1.amazonaws.com/", // 20
|
|
23
|
-
"https://g8jxt5xr74.execute-api.us-east-1.amazonaws.com/",
|
|
24
|
-
"https://k2psewlm7h.execute-api.us-east-1.amazonaws.com/",
|
|
25
|
-
"https://kitlcntj2m.execute-api.us-east-1.amazonaws.com/",
|
|
26
|
-
"https://dxcdo7fmy2.execute-api.us-east-1.amazonaws.com/",
|
|
27
|
-
"https://idzyuxsy0h.execute-api.us-east-1.amazonaws.com/",
|
|
28
|
-
"https://osl2t5witk.execute-api.us-east-1.amazonaws.com/",
|
|
29
|
-
"https://sjnkscdgul.execute-api.us-east-1.amazonaws.com/",
|
|
30
|
-
"https://rqo11cixlc.execute-api.us-east-1.amazonaws.com/",
|
|
31
|
-
"https://06zifludsc.execute-api.us-east-1.amazonaws.com/",
|
|
32
|
-
"https://u9k7jhl2g9.execute-api.us-east-1.amazonaws.com/", // 30
|
|
33
|
-
"https://uu2jwf0lnf.execute-api.us-east-1.amazonaws.com/",
|
|
34
|
-
"https://xrqcf8ijfk.execute-api.us-east-1.amazonaws.com/",
|
|
35
|
-
"https://w5pqx1nnkb.execute-api.us-east-1.amazonaws.com/",
|
|
36
|
-
"https://qt16b1ikhk.execute-api.us-east-1.amazonaws.com/",
|
|
37
|
-
"https://y0x4ahq1ak.execute-api.us-east-1.amazonaws.com/",
|
|
38
|
-
"https://fujoj0uyo9.execute-api.us-east-1.amazonaws.com/",
|
|
39
|
-
"https://8u8g10va1m.execute-api.us-east-1.amazonaws.com/",
|
|
40
|
-
"https://ez9lw2f68l.execute-api.us-east-1.amazonaws.com/",
|
|
41
|
-
"https://20floesmp3.execute-api.us-east-1.amazonaws.com/",
|
|
42
|
-
"https://15m55yshpi.execute-api.us-east-1.amazonaws.com/", // 40
|
|
43
|
-
"https://juvdtsrnz2.execute-api.us-east-1.amazonaws.com/",
|
|
44
|
-
"https://qzyqh8tc9d.execute-api.us-east-1.amazonaws.com/",
|
|
45
|
-
"https://tcd3dev5bl.execute-api.us-east-1.amazonaws.com/",
|
|
46
|
-
"https://0heozuo48k.execute-api.us-east-1.amazonaws.com/",
|
|
47
|
-
"https://6rgbg2eyt4.execute-api.us-east-1.amazonaws.com/",
|
|
48
|
-
"https://8xcixylxsk.execute-api.us-east-1.amazonaws.com/",
|
|
49
|
-
"https://gu56mjdx4g.execute-api.us-east-1.amazonaws.com/",
|
|
50
|
-
"https://2kou7rlmel.execute-api.us-east-1.amazonaws.com/",
|
|
51
|
-
"https://783td1vsme.execute-api.us-east-1.amazonaws.com/",
|
|
52
|
-
"https://cb71cnbcwb.execute-api.us-east-1.amazonaws.com/", // 50
|
|
53
|
-
"https://mjmcciml16.execute-api.us-east-1.amazonaws.com/",
|
|
54
|
-
"https://rzdrzof2gh.execute-api.us-east-1.amazonaws.com/",
|
|
55
|
-
"https://r9r1kjdtgb.execute-api.us-east-1.amazonaws.com/",
|
|
56
|
-
"https://9je54malq1.execute-api.us-east-1.amazonaws.com/",
|
|
57
|
-
"https://djigu0l9dl.execute-api.us-east-1.amazonaws.com/",
|
|
58
|
-
"https://bsg5re0koc.execute-api.us-east-1.amazonaws.com/",
|
|
59
|
-
"https://2uobbakcck.execute-api.us-east-1.amazonaws.com/",
|
|
60
|
-
"https://qdk9s4u3n5.execute-api.us-east-1.amazonaws.com/",
|
|
61
|
-
"https://s0qzagys0f.execute-api.us-east-1.amazonaws.com/",
|
|
62
|
-
"https://t20jva77ek.execute-api.us-east-1.amazonaws.com/", // 60
|
|
63
|
-
"https://rnz8llxvqf.execute-api.us-east-1.amazonaws.com/",
|
|
64
|
-
"https://t9cy9qtxp6.execute-api.us-east-1.amazonaws.com/",
|
|
65
|
-
"https://uph5hi51e9.execute-api.us-east-1.amazonaws.com/",
|
|
66
|
-
"https://uhas1ctjl2.execute-api.us-east-1.amazonaws.com/",
|
|
67
|
-
"https://h602ynhw5m.execute-api.us-east-1.amazonaws.com/",
|
|
68
|
-
"https://qt87x78zw9.execute-api.us-east-1.amazonaws.com/",
|
|
69
|
-
"https://8gwu72zzkh.execute-api.us-east-1.amazonaws.com/",
|
|
70
|
-
"https://cvlp54ehig.execute-api.us-east-1.amazonaws.com/",
|
|
71
|
-
"https://9c99a5ek7c.execute-api.us-east-1.amazonaws.com/",
|
|
72
|
-
"https://hrz3qhqs0j.execute-api.us-east-1.amazonaws.com/", // 70
|
|
73
|
-
"https://cm0gfte4kh.execute-api.us-east-1.amazonaws.com/",
|
|
74
|
-
"https://0xorkhltdi.execute-api.us-east-1.amazonaws.com/",
|
|
75
|
-
"https://amqsj875b4.execute-api.us-east-1.amazonaws.com/",
|
|
76
|
-
"https://4ve0o19yr5.execute-api.us-east-1.amazonaws.com/",
|
|
77
|
-
"https://ektqo7i1t1.execute-api.us-east-1.amazonaws.com/",
|
|
78
|
-
"https://1hms6u81fe.execute-api.us-east-1.amazonaws.com/",
|
|
79
|
-
"https://40tydiwluj.execute-api.us-east-1.amazonaws.com/",
|
|
80
|
-
"https://cehlt4lgsl.execute-api.us-east-1.amazonaws.com/",
|
|
81
|
-
"https://80fbnad9k8.execute-api.us-east-1.amazonaws.com/",
|
|
82
|
-
"https://g0bwbsyo8g.execute-api.us-east-1.amazonaws.com/", // 80
|
|
83
|
-
"https://5b4cqe6sjl.execute-api.us-east-1.amazonaws.com/",
|
|
84
|
-
"https://f9trwl8thg.execute-api.us-east-1.amazonaws.com/",
|
|
85
|
-
"https://gqn9p2pka0.execute-api.us-east-1.amazonaws.com/",
|
|
86
|
-
"https://ibei256b64.execute-api.us-east-1.amazonaws.com/",
|
|
87
|
-
"https://bzb989tye7.execute-api.us-east-1.amazonaws.com/",
|
|
88
|
-
"https://hsylj0lmhb.execute-api.us-east-1.amazonaws.com/",
|
|
89
|
-
"https://2cmgyet6c9.execute-api.us-east-1.amazonaws.com/",
|
|
90
|
-
"https://fbug2oau1a.execute-api.us-east-1.amazonaws.com/",
|
|
91
|
-
"https://4dkwwtxnk1.execute-api.us-east-1.amazonaws.com/",
|
|
92
|
-
"https://hkbqu2rd88.execute-api.us-east-1.amazonaws.com/", // 90
|
|
93
|
-
"https://i3of390pqe.execute-api.us-east-1.amazonaws.com/",
|
|
94
|
-
"https://i17mmutqil.execute-api.us-east-1.amazonaws.com/",
|
|
95
|
-
"https://284yk97cnc.execute-api.us-east-1.amazonaws.com/",
|
|
96
|
-
"https://jmf3m87fcd.execute-api.us-east-1.amazonaws.com/",
|
|
97
|
-
"https://k4rohifagh.execute-api.us-east-1.amazonaws.com/",
|
|
98
|
-
"https://8ttlnvdn5e.execute-api.us-east-1.amazonaws.com/",
|
|
99
|
-
"https://7vek7u8571.execute-api.us-east-1.amazonaws.com/",
|
|
100
|
-
"https://hwmema8c6b.execute-api.us-east-1.amazonaws.com/",
|
|
101
|
-
"https://80xmk8qjdb.execute-api.us-east-1.amazonaws.com/", // 99
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
async function proxyFetch(url, options = {}) {
|
|
105
|
-
const rn = Math.floor(Math.random() * PROXY_INSTANCES.length);
|
|
106
|
-
|
|
107
|
-
const proxy = PROXY_INSTANCES[rn];
|
|
108
|
-
|
|
109
|
-
if (options.verbose) {
|
|
110
|
-
console.log(`fetching ${url} using ${proxy}`);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const controller = new AbortController();
|
|
114
|
-
const timeout = setTimeout(() => {
|
|
115
|
-
controller.abort();
|
|
116
|
-
}, options.timeout || 30_000);
|
|
117
|
-
|
|
118
|
-
try {
|
|
119
|
-
const res = await fetch(proxy, {
|
|
120
|
-
signal: controller.signal,
|
|
121
|
-
...options,
|
|
122
|
-
headers: {
|
|
123
|
-
"fetch-url": url,
|
|
124
|
-
...options.headers,
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
if (options.verbose) {
|
|
129
|
-
console.log(`DONE fetching ${url}`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
clearTimeout(timeout);
|
|
133
|
-
|
|
134
|
-
return res;
|
|
135
|
-
} catch (fetchErr) {
|
|
136
|
-
clearTimeout(timeout);
|
|
137
|
-
|
|
138
|
-
if (fetchErr.name === "AbortError") {
|
|
139
|
-
return {
|
|
140
|
-
ok: false,
|
|
141
|
-
status: 408,
|
|
142
|
-
text: () => Promise.resolve("Timeout"),
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
ok: false,
|
|
148
|
-
status: 500,
|
|
149
|
-
text: () => Promise.resolve(fetchErr.message),
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export default proxyFetch;
|
package/s3.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
S3Client,
|
|
3
|
-
GetObjectCommand,
|
|
4
|
-
HeadObjectCommand,
|
|
5
|
-
PutObjectCommand,
|
|
6
|
-
DeleteObjectCommand,
|
|
7
|
-
ListObjectsV2Command,
|
|
8
|
-
NotFound,
|
|
9
|
-
} from "@aws-sdk/client-s3";
|
|
10
|
-
|
|
11
|
-
type WriteOptions = {
|
|
12
|
-
verbose: boolean;
|
|
13
|
-
acl: string;
|
|
14
|
-
skipIfExists: boolean;
|
|
15
|
-
contentType: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export function getS3(): S3Client;
|
|
19
|
-
export function readFile(bucketName: string, key: string, verbose?: boolean): Promise<string | null>;
|
|
20
|
-
export function hasFile(bucketName: string, key: string): Promise<boolean>;
|
|
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;
|
|
36
|
-
} | null>;
|
package/search.d.ts
DELETED
package/search.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { isProduction } from "./env.js";
|
|
2
|
-
import { inline } from "./log.js";
|
|
3
|
-
import { Client } from "@elastic/elasticsearch";
|
|
4
|
-
import osModule from "os";
|
|
5
|
-
|
|
6
|
-
export async function sendToSearch(indexPrefix, record, throws = false) {
|
|
7
|
-
const client = new Client({
|
|
8
|
-
cloud: { id: process.env.SKYNET_ELASTICSEARCH_CLOUD_ID },
|
|
9
|
-
auth: { apiKey: process.env.SKYNET_ELASTICSEARCH_API_KEY },
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const now = new Date();
|
|
13
|
-
const indexName = [indexPrefix, isProduction() ? "prod" : "dev", now.toISOString().slice(0, 7)].join("-");
|
|
14
|
-
|
|
15
|
-
// best as possible delivery
|
|
16
|
-
// by default not throw
|
|
17
|
-
try {
|
|
18
|
-
await client.index({
|
|
19
|
-
index: indexName,
|
|
20
|
-
document: { instance: osModule.hostname(), timestamp: now, record },
|
|
21
|
-
});
|
|
22
|
-
} catch (err) {
|
|
23
|
-
inline.error(err);
|
|
24
|
-
|
|
25
|
-
if (throws) {
|
|
26
|
-
throw err;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
package/selector.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export type SelectorFlags = {
|
|
2
|
-
[flag: string]: string;
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
export type Selector = {
|
|
6
|
-
[key: string]: {
|
|
7
|
-
type?: "string" | "number" | "boolean" | string;
|
|
8
|
-
description?: string;
|
|
9
|
-
desc?: string;
|
|
10
|
-
aliases?: string[];
|
|
11
|
-
isRequired?: boolean;
|
|
12
|
-
default?: any;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export function getJobName(name: string, selectorFlags: SelectorFlags, mode?: string): string;
|
|
17
|
-
export function getSelectorDesc(selector: Selector): string;
|
|
18
|
-
export function getSelectorFlags(selector: Selector): SelectorFlags;
|
|
19
|
-
export function toSelectorString(selectorFlags: SelectorFlags, delim?: string): string;
|
package/selector.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
function getSpaces(num) {
|
|
2
|
-
let str = "";
|
|
3
|
-
for (let i = 0; i < num; i++) {
|
|
4
|
-
str += " ";
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
return str;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function getSelectorDesc(selector) {
|
|
11
|
-
return Object.keys(selector)
|
|
12
|
-
.map((name) => {
|
|
13
|
-
return ` --${name}${getSpaces(14 - name.length)}${
|
|
14
|
-
selector[name].desc || selector[name].description || ""
|
|
15
|
-
}`;
|
|
16
|
-
})
|
|
17
|
-
.join("\n");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// check https://github.com/sindresorhus/meow for selector config options
|
|
21
|
-
function getSelectorFlags(selector) {
|
|
22
|
-
return Object.keys(selector).reduce((acc, name) => {
|
|
23
|
-
const flag = {
|
|
24
|
-
type: selector[name].type || "string",
|
|
25
|
-
...selector[name],
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// by default to be required
|
|
29
|
-
if (!selector[name].optional && selector[name].isRequired !== false) {
|
|
30
|
-
flag.isRequired = true;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
acc[name] = flag;
|
|
34
|
-
return acc;
|
|
35
|
-
}, {});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function toSelectorString(selectorFlags, delim = ",") {
|
|
39
|
-
return Object.keys(selectorFlags)
|
|
40
|
-
.sort() // deterministic
|
|
41
|
-
.map((flag) => {
|
|
42
|
-
return `${flag}=${selectorFlags[flag]}`;
|
|
43
|
-
})
|
|
44
|
-
.join(delim);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function normalizeSelectorValue(v) {
|
|
48
|
-
return v.replace(/[^A-Za-z0-9]+/g, "-");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getJobName(name, selectorFlags, mode = null) {
|
|
52
|
-
const selectorNamePart = Object.keys(selectorFlags)
|
|
53
|
-
.sort()
|
|
54
|
-
.map((name) => selectorFlags[name])
|
|
55
|
-
.join("-");
|
|
56
|
-
|
|
57
|
-
let jobName = name;
|
|
58
|
-
|
|
59
|
-
if (mode) {
|
|
60
|
-
jobName += `-${mode}`;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (selectorNamePart.length > 0) {
|
|
64
|
-
// handle special case
|
|
65
|
-
jobName += `-${normalizeSelectorValue(selectorNamePart)}`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return jobName;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export { getJobName, getSelectorDesc, getSelectorFlags, toSelectorString };
|
package/slack.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ChatPostMessageArguments } from "@slack/web-api";
|
|
2
|
-
|
|
3
|
-
interface PostMessageParams {
|
|
4
|
-
conversationId: string;
|
|
5
|
-
message: string | Partial<ChatPostMessageArguments>;
|
|
6
|
-
token: string;
|
|
7
|
-
verbose?: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async function postMessageToConversation(params: PostMessageParams): Promise<void>;
|
package/snowflake.d.ts
DELETED
package/snowflake.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import snowflake from "snowflake-sdk";
|
|
2
|
-
import { promisify } from "util";
|
|
3
|
-
import { ensureAndGet } from "./env.js";
|
|
4
|
-
|
|
5
|
-
async function getConnection(options) {
|
|
6
|
-
const connection = snowflake.createConnection({
|
|
7
|
-
account: ensureAndGet("SKYNET_SNOWFLAKE_ACCOUNT"),
|
|
8
|
-
username: ensureAndGet("SKYNET_SNOWFLAKE_USERNAME"),
|
|
9
|
-
password: ensureAndGet("SKYNET_SNOWFLAKE_PASSWORD"),
|
|
10
|
-
...options,
|
|
11
|
-
});
|
|
12
|
-
return await promisify(connection.connect).bind(connection)();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async function executeSql(options, sql, binds) {
|
|
16
|
-
const connection = await getConnection(options);
|
|
17
|
-
return await new Promise((resolve, reject) => {
|
|
18
|
-
connection.execute({
|
|
19
|
-
sqlText: sql,
|
|
20
|
-
binds: binds,
|
|
21
|
-
complete: (err, statement, rows) => {
|
|
22
|
-
// console.log(statement.getSqlText());
|
|
23
|
-
if (err) {
|
|
24
|
-
reject(err);
|
|
25
|
-
} else {
|
|
26
|
-
resolve(rows);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { getConnection, executeSql };
|
package/sqs.d.ts
DELETED
package/sqs.js
DELETED
package/util.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export function arrayGroup<T>(array: T[], groupSize: number): T[][];
|
|
2
|
-
export function partition(startAt: number, endAt: number, numGroups: number): [number, number][];
|
|
3
|
-
export function range(startAt: number, endAt: number, step: number): [number, number][];
|
|
4
|
-
export function fillRange(startAt: number, endAt: number): number[];
|
|
5
|
-
export function chunk<T>(array: T[], count: number): T[][];
|
package/util.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// Inclusive endAt
|
|
2
|
-
function partition(startAt, endAt, numGroups) {
|
|
3
|
-
if (numGroups === 0 || startAt > endAt) {
|
|
4
|
-
return [];
|
|
5
|
-
} else if (startAt === endAt) {
|
|
6
|
-
return [[startAt, endAt]];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const span = endAt - startAt + 1;
|
|
10
|
-
const step = Math.max(Math.floor(span / numGroups), 1);
|
|
11
|
-
const adjustedStep = span % step === 0 ? step : step + 1;
|
|
12
|
-
|
|
13
|
-
return [[startAt, startAt + adjustedStep - 1], ...partition(startAt + adjustedStep, endAt, numGroups - 1)];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Inclusive range
|
|
17
|
-
function range(startAt, endAt, step) {
|
|
18
|
-
let arr = [];
|
|
19
|
-
|
|
20
|
-
for (let i = startAt; i <= endAt; i += step) {
|
|
21
|
-
arr.push([i, Math.min(endAt, i + step - 1)]);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return arr;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function arrayGroup(array, groupSize) {
|
|
28
|
-
const groups = [];
|
|
29
|
-
|
|
30
|
-
for (let i = 0; i < array.length; i += groupSize) {
|
|
31
|
-
groups.push(array.slice(i, i + groupSize));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return groups;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// return an array with numbers of given inclusive range
|
|
38
|
-
// given 1, 5
|
|
39
|
-
// return [1, 2, 3, 4, 5]
|
|
40
|
-
function fillRange(start, end) {
|
|
41
|
-
let result = [];
|
|
42
|
-
|
|
43
|
-
for (let i = start; i <= end; i++) {
|
|
44
|
-
result.push(i);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function chunk(array, count) {
|
|
51
|
-
if (count == null || count < 1) return [];
|
|
52
|
-
var result = [];
|
|
53
|
-
var i = 0,
|
|
54
|
-
length = array.length;
|
|
55
|
-
while (i < length) {
|
|
56
|
-
result.push(array.slice(i, (i += count)));
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export { arrayGroup, partition, range, fillRange, chunk };
|
package/web3.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import Bottleneck from "bottleneck";
|
|
2
|
-
import Web3 from "web3";
|
|
3
|
-
import { ABI } from "./abi";
|
|
4
|
-
|
|
5
|
-
type Call =
|
|
6
|
-
| {
|
|
7
|
-
params: any | any[];
|
|
8
|
-
functionName?: string;
|
|
9
|
-
target?: string;
|
|
10
|
-
}
|
|
11
|
-
| any[];
|
|
12
|
-
|
|
13
|
-
export function newWeb3ByProtocol(protocol: string): Web3;
|
|
14
|
-
export function singleCall(protocol: string, abi: ABI, target: string, params: any[]): Promise<any>;
|
|
15
|
-
export function multiCall(multiCallParams: {
|
|
16
|
-
protocol: string;
|
|
17
|
-
limiter?: Bottleneck;
|
|
18
|
-
target: string;
|
|
19
|
-
abi: ABI;
|
|
20
|
-
calls: Call[];
|
|
21
|
-
}): Promise<{
|
|
22
|
-
callCount: number;
|
|
23
|
-
actualCallCount?: number;
|
|
24
|
-
output: any[];
|
|
25
|
-
}>;
|
package/web3.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { Web3 } from "web3";
|
|
2
|
-
import { PROTOCOLS } from "./const.js";
|
|
3
|
-
import { MULTICALL } from "./abi.js";
|
|
4
|
-
import { chunk } from "./util.js";
|
|
5
|
-
const MULTICALL_CHUNK_SIZE = 400;
|
|
6
|
-
|
|
7
|
-
function newWeb3ByProtocol(protocol) {
|
|
8
|
-
if (!Object.keys(PROTOCOLS).includes(protocol)) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return new Web3(PROTOCOLS[protocol].endpoint);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function normalizeCallParams(params) {
|
|
16
|
-
if (params === undefined) {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (Array.isArray(params)) {
|
|
21
|
-
return params;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return [params];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function singleCall(protocol, abi, target, params) {
|
|
28
|
-
const web3 = newWeb3ByProtocol(protocol);
|
|
29
|
-
|
|
30
|
-
if (!web3) {
|
|
31
|
-
throw new Error(`unsupported protocol`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const contract = new web3.eth.Contract([abi], target);
|
|
35
|
-
const functionSignature = web3.eth.abi.encodeFunctionSignature(abi);
|
|
36
|
-
const method = contract.methods[functionSignature];
|
|
37
|
-
|
|
38
|
-
const result = await method(...normalizeCallParams(params)).call();
|
|
39
|
-
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// limiter if provided, should be an instance of Bottleneck, which is part of bottleneck package
|
|
44
|
-
async function multiCall({ protocol, limiter = null, target, abi, calls }) {
|
|
45
|
-
const web3 = newWeb3ByProtocol(protocol);
|
|
46
|
-
|
|
47
|
-
if (!web3) {
|
|
48
|
-
throw new Error(`unsupported protocol`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const multiCallProviderAddress = PROTOCOLS[protocol].multiCallProvider;
|
|
52
|
-
|
|
53
|
-
if (!multiCallProviderAddress) {
|
|
54
|
-
throw new Error("protocol doesn't support multicall yet");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (calls.length === 0) return { callCount: 0, output: [] };
|
|
58
|
-
|
|
59
|
-
const multiCallContract = new web3.eth.Contract(MULTICALL, multiCallProviderAddress);
|
|
60
|
-
|
|
61
|
-
let maybeRateLimitedCallChunk = async (callChunk) => {
|
|
62
|
-
const txs = callChunk.map((call) => ({
|
|
63
|
-
delegateCall: false,
|
|
64
|
-
revertOnError: false,
|
|
65
|
-
gasLimit: 0,
|
|
66
|
-
target: call.target || target,
|
|
67
|
-
value: 0,
|
|
68
|
-
data: web3.eth.abi.encodeFunctionCall(abi, normalizeCallParams(call.params)),
|
|
69
|
-
}));
|
|
70
|
-
|
|
71
|
-
const response = await multiCallContract.methods.multiCall(txs).call();
|
|
72
|
-
|
|
73
|
-
return response._results.map((res, idx) => {
|
|
74
|
-
const input = {
|
|
75
|
-
target: callChunk[idx].target || target,
|
|
76
|
-
params: normalizeCallParams(callChunk[idx].params),
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const callResult = web3.eth.abi.decodeParameters(abi.outputs, res);
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
input,
|
|
84
|
-
success: response._successes[idx],
|
|
85
|
-
// according to SDK doc, if there's only one, return result directly
|
|
86
|
-
output: abi.outputs.length === 1 ? callResult[0] : callResult,
|
|
87
|
-
};
|
|
88
|
-
} catch (decodeErr) {
|
|
89
|
-
console.log("decode err", abi.name, callChunk[idx].target || target, callChunk[idx].params, decodeErr.message);
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
input,
|
|
93
|
-
success: false,
|
|
94
|
-
output: null,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
if (limiter) {
|
|
101
|
-
maybeRateLimitedCallChunk = limiter.wrap(maybeRateLimitedCallChunk);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const callChunks = chunk(calls, MULTICALL_CHUNK_SIZE);
|
|
105
|
-
|
|
106
|
-
const responses = (
|
|
107
|
-
await Promise.all(callChunks.map(async (callChunk) => await maybeRateLimitedCallChunk(callChunk)))
|
|
108
|
-
).flat();
|
|
109
|
-
|
|
110
|
-
return { actualCallCount: callChunks.length, output: responses };
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export { newWeb3ByProtocol, singleCall, multiCall };
|