@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/app.d.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { Selector } from "./selector";
|
|
2
|
-
import express from "express";
|
|
3
|
-
|
|
4
|
-
export type Env = {
|
|
5
|
-
[key: string]: string | null;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type Route = {
|
|
9
|
-
method?: "get" | "post" | "put" | "delete" | "patch";
|
|
10
|
-
path: string;
|
|
11
|
-
middlewares?: ((req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>)[];
|
|
12
|
-
handler: (args: { req: express.Request; res: express.Response; [key: string]: any }) => Promise<void>;
|
|
13
|
-
protected?: boolean;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type Serve = {
|
|
17
|
-
prefix: string;
|
|
18
|
-
port: number;
|
|
19
|
-
apiKey?: string;
|
|
20
|
-
killTimeout?: string;
|
|
21
|
-
cpu: number;
|
|
22
|
-
mem: number;
|
|
23
|
-
instances?: number;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type State = {
|
|
27
|
-
type: string;
|
|
28
|
-
updateInterval: ({ protocol }: { protocol: string }) => number;
|
|
29
|
-
getMinId: () => Promise<number>;
|
|
30
|
-
getMaxId: ({ protocol }: { protocol: string }) => Promise<number>;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type Schedule = string | ((jobName: string) => string);
|
|
34
|
-
|
|
35
|
-
export type Check = {
|
|
36
|
-
func: ({ protocol, state, verbose }: { protocol: string; state: string; verbose: boolean }) => {
|
|
37
|
-
type: string;
|
|
38
|
-
message: string;
|
|
39
|
-
};
|
|
40
|
-
schedule: Schedule;
|
|
41
|
-
slackChannel: string;
|
|
42
|
-
killTimeout?: string;
|
|
43
|
-
cpu: number;
|
|
44
|
-
mem: number;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export type Build = {
|
|
48
|
-
func: ({ protocol, from, to, verbose }: { protocol: string; from: number; to: number; verbose: boolean }) => void;
|
|
49
|
-
batchSize?: number;
|
|
50
|
-
schedule: Schedule;
|
|
51
|
-
killTimeout?: string;
|
|
52
|
-
cpu: number;
|
|
53
|
-
mem: number;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export type Restart = {
|
|
57
|
-
attempts: number | undefined;
|
|
58
|
-
mode: string | undefined;
|
|
59
|
-
interval: string | undefined;
|
|
60
|
-
delay: string | undefined;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export type Validate = {
|
|
64
|
-
func: ({ protocol, from, to, verbose }: { protocol: string; from: number; to: number; verbose: boolean }) => void;
|
|
65
|
-
batchSize: number;
|
|
66
|
-
schedule: Schedule;
|
|
67
|
-
killTimeout?: string;
|
|
68
|
-
cpu: number;
|
|
69
|
-
mem: number;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
type BuildWithRestart = Build & { restart?: Restart };
|
|
73
|
-
|
|
74
|
-
type BuildWithConcurrency = Build & { concurrency?: number };
|
|
75
|
-
|
|
76
|
-
type ValidateWithConcurrency = Validate & { concurrency?: number };
|
|
77
|
-
|
|
78
|
-
export const SENSITIVE_VALUE: null;
|
|
79
|
-
|
|
80
|
-
export function every(n?: number): {
|
|
81
|
-
second: string;
|
|
82
|
-
seconds: string;
|
|
83
|
-
minute: string;
|
|
84
|
-
minutes: string;
|
|
85
|
-
hour: string;
|
|
86
|
-
hours: string;
|
|
87
|
-
day: string;
|
|
88
|
-
days: string;
|
|
89
|
-
week: string;
|
|
90
|
-
weeks: string;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export function api(apiParams: {
|
|
94
|
-
name: string;
|
|
95
|
-
routes: Route[];
|
|
96
|
-
serve: Serve;
|
|
97
|
-
env: Env | undefined;
|
|
98
|
-
region: string | undefined;
|
|
99
|
-
beforeListen: (args: { app: ReturnType<typeof express> }) => void;
|
|
100
|
-
}): () => void;
|
|
101
|
-
|
|
102
|
-
export function indexer(indexerParams: {
|
|
103
|
-
name: string;
|
|
104
|
-
selector?: Selector;
|
|
105
|
-
build: BuildWithRestart;
|
|
106
|
-
env?: Env;
|
|
107
|
-
region?: string;
|
|
108
|
-
}): () => void;
|
|
109
|
-
|
|
110
|
-
export function modeIndexer(modeIndexerParams: {
|
|
111
|
-
name: string;
|
|
112
|
-
selector?: Selector;
|
|
113
|
-
state: State;
|
|
114
|
-
build: BuildWithConcurrency;
|
|
115
|
-
validate?: ValidateWithConcurrency;
|
|
116
|
-
env?: Env;
|
|
117
|
-
region?: string;
|
|
118
|
-
}): () => void;
|
package/availability.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export function wait(time: number): Promise<void>;
|
|
2
|
-
export function retry(times: number, verbose: boolean, func: Function): Promise<void>;
|
|
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
|
-
},
|
|
18
|
-
): Promise<T>;
|
package/cli.d.ts
DELETED
package/const.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
};
|
|
20
|
-
|
|
21
|
-
type TimeIntervals = {
|
|
22
|
-
SECOND: number;
|
|
23
|
-
MINUTE: number;
|
|
24
|
-
HOUR: number;
|
|
25
|
-
DAY: number;
|
|
26
|
-
WEEK: number;
|
|
27
|
-
YEAR: number;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
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
|
-
};
|
|
39
|
-
export const TIME: {
|
|
40
|
-
BY_MS: TimeIntervals;
|
|
41
|
-
BY_S: TimeIntervals;
|
|
42
|
-
};
|
package/databricks.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line no-unused-vars
|
|
2
|
-
import { DBSQLClient, DBSQLParameter, DBSQLSession } from "@databricks/sql";
|
|
3
|
-
import { ensureAndGet } from "./env.js";
|
|
4
|
-
import { exponentialRetry } from "./availability.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @type {DBSQLClient}
|
|
8
|
-
*/
|
|
9
|
-
let client;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @type {DBSQLSession}
|
|
13
|
-
*/
|
|
14
|
-
let session;
|
|
15
|
-
|
|
16
|
-
async function initSession(options) {
|
|
17
|
-
if (!client) {
|
|
18
|
-
client = new DBSQLClient();
|
|
19
|
-
await client.connect({
|
|
20
|
-
token: ensureAndGet("SKYNET_DATABRICKS_TOKEN"),
|
|
21
|
-
host: ensureAndGet("SKYNET_DATABRICKS_SERVER_HOSTNAME"),
|
|
22
|
-
path: ensureAndGet("SKYNET_DATABRICKS_HTTP_PATH"),
|
|
23
|
-
...options,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
if (!session) {
|
|
27
|
-
session = await client.openSession();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function executeSql(options, sql, bindings) {
|
|
32
|
-
// retry sql query to avoid socket hang up error
|
|
33
|
-
const results = exponentialRetry(
|
|
34
|
-
async () => {
|
|
35
|
-
let queryOperation;
|
|
36
|
-
try {
|
|
37
|
-
await initSession(options);
|
|
38
|
-
queryOperation = await session.executeStatement(sql, {
|
|
39
|
-
runAsync: true,
|
|
40
|
-
namedParameters: objToParameter(bindings),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const result = await queryOperation.fetchAll();
|
|
44
|
-
return result;
|
|
45
|
-
} catch (err) {
|
|
46
|
-
// If the error is not a Databricks error, throw it
|
|
47
|
-
if (!checkIsDatabricksError(err)) {
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
|
-
return err;
|
|
51
|
-
} finally {
|
|
52
|
-
await queryOperation?.close();
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
maxRetry: 3,
|
|
57
|
-
initialDuration: 500,
|
|
58
|
-
test: (result) => {
|
|
59
|
-
return !checkIsDatabricksError(result);
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
if (checkIsDatabricksError(results)) {
|
|
65
|
-
// still error after retry, throw it
|
|
66
|
-
throw results;
|
|
67
|
-
}
|
|
68
|
-
return results;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function checkIsDatabricksError(err) {
|
|
72
|
-
return err?.errno === "ECONNRESET" || err?.message?.includes("java.lang.NullPointerException");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function objToParameter(obj) {
|
|
76
|
-
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
77
|
-
acc[key] = new DBSQLParameter({ value });
|
|
78
|
-
return acc;
|
|
79
|
-
}, {});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export { executeSql };
|
package/deploy.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { getJobName } from "./selector";
|
|
2
|
-
import { Env, Selector, Check, Restart } from "./app";
|
|
3
|
-
|
|
4
|
-
type Service = {
|
|
5
|
-
prefix: string;
|
|
6
|
-
port: number;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
type CreateDeployBaseParams = {
|
|
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
|
-
};
|
|
19
|
-
|
|
20
|
-
export { getJobName };
|
|
21
|
-
|
|
22
|
-
export function getNomadAddr(isProduction: boolean): Promise<string | undefined>;
|
|
23
|
-
|
|
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 };
|
|
39
|
-
|
|
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/dns.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function hasTxtRecord(domainName: string, txtRecord: string): Promise<boolean>;
|
package/dns.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// https://nodejs.org/api/dns.html#dns
|
|
2
|
-
import { promises as dns } from "dns";
|
|
3
|
-
|
|
4
|
-
export async function hasTxtRecord(domainName, txtRecord) {
|
|
5
|
-
let nsAddresses;
|
|
6
|
-
// get all nameservers for the domain
|
|
7
|
-
const nameservers = await dns.resolveNs(domainName);
|
|
8
|
-
|
|
9
|
-
// get default nameserver addresses
|
|
10
|
-
const defaultServers = dns.getServers();
|
|
11
|
-
|
|
12
|
-
// iterate over nameservers to see if they have the TXT record
|
|
13
|
-
for (const ns of nameservers) {
|
|
14
|
-
//reset serverAddresses to get nameserver addresses
|
|
15
|
-
dns.setServers(defaultServers);
|
|
16
|
-
|
|
17
|
-
// get nameserver addresses and use them to resolve domain's TXT record, in order to skip caches in DNS servers.
|
|
18
|
-
nsAddresses = await dns.resolve(ns);
|
|
19
|
-
dns.setServers(nsAddresses);
|
|
20
|
-
const txtRecords = await dns.resolveTxt(domainName);
|
|
21
|
-
|
|
22
|
-
if (txtRecords && txtRecords.length > 0 && txtRecords.find((txt) => txt.indexOf(txtRecord) > -1)) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
}
|
package/dynamodb.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { ScanCommandInput, PutCommandOutput, UpdateCommandOutput } from "@aws-sdk/lib-dynamodb";
|
|
2
|
-
|
|
3
|
-
import { CreateTableInput, CreateTableOutput } from "@aws-sdk/client-dynamodb";
|
|
4
|
-
|
|
5
|
-
export function getDocClient(forceNew?: boolean): DynamoDBDocumentClient;
|
|
6
|
-
|
|
7
|
-
export function scanWholeTable<T>(options: ScanCommandInput): Promise<{
|
|
8
|
-
Items: T[];
|
|
9
|
-
Count: number;
|
|
10
|
-
ScannedCount: number;
|
|
11
|
-
}>;
|
|
12
|
-
|
|
13
|
-
export function batchCreateRecords<T>(
|
|
14
|
-
tableName: string,
|
|
15
|
-
records: T[],
|
|
16
|
-
maxWritingCapacity: number,
|
|
17
|
-
verbose?: boolean,
|
|
18
|
-
): Promise<void>;
|
|
19
|
-
|
|
20
|
-
export function createRecord<T>(tableName: string, fields: T, verbose?: boolean): Promise<PutCommandOutput>;
|
|
21
|
-
|
|
22
|
-
export function getRecordsByKey<TReturn, TKey>(tableName: string, keys: TKey, indexName: string): Promise<TReturn[]>;
|
|
23
|
-
|
|
24
|
-
export function getRecordByKey<TReturn, TKey>(
|
|
25
|
-
tableName: string,
|
|
26
|
-
keys: TKey,
|
|
27
|
-
indexName: string,
|
|
28
|
-
): Promise<TReturn | null>;
|
|
29
|
-
|
|
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>;
|
|
37
|
-
|
|
38
|
-
export function batchDeleteRecords<T>(tableName: string, keys: T): Promise<void>;
|
|
39
|
-
|
|
40
|
-
export function deleteRecordsByHashKey(
|
|
41
|
-
tableName: string,
|
|
42
|
-
indexName?: string,
|
|
43
|
-
hashKeyValue: string,
|
|
44
|
-
verbose?: boolean,
|
|
45
|
-
): Promise<number>;
|
|
46
|
-
|
|
47
|
-
export function createTableIfNotExist(
|
|
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/env.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export function ensureAndGet<T>(envName: string, defaultValue: T): string | T;
|
|
2
|
-
export function getEnvOrThrow(envName: string): string;
|
|
3
|
-
export function getEnvironment(): string;
|
|
4
|
-
export function getNodeRealApiKey(identifier: string): string | undefined;
|
|
5
|
-
export function isProduction(): boolean;
|
|
6
|
-
export function isDev(): boolean;
|
package/env.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
function getEnvironment() {
|
|
2
|
-
return ensureAndGet("SKYNET_ENVIRONMENT", "dev");
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function getNodeRealApiKey(identifier) {
|
|
6
|
-
// NodeReal API keys are different for each NodeReal app
|
|
7
|
-
return ensureAndGet([`SKYNET_NODEREAL_API_${identifier.toUpperCase()}_KEY`, `SKYNET_NODEREAL_API_KEY`]);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function ensureAndGet(envName, defaultValue) {
|
|
11
|
-
if (Array.isArray(envName)) {
|
|
12
|
-
for (let name of envName) {
|
|
13
|
-
if (process.env[name]) {
|
|
14
|
-
return process.env[name];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return defaultValue;
|
|
18
|
-
} else {
|
|
19
|
-
if (process.env[envName]) {
|
|
20
|
-
return process.env[envName];
|
|
21
|
-
}
|
|
22
|
-
return defaultValue;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function getEnvOrThrow(envName) {
|
|
27
|
-
if (!process.env[envName]) {
|
|
28
|
-
throw new Error(`Must set environment variable ${envName}`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return process.env[envName];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function isProduction() {
|
|
35
|
-
return getEnvironment() === "prd";
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function isDev() {
|
|
39
|
-
return getEnvironment() === "dev";
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { ensureAndGet, getEnvOrThrow, getEnvironment, isProduction, isDev, getNodeRealApiKey };
|
package/examples/consumer.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// this file is executable and is for kafka producer testing
|
|
4
|
-
// a few test commands to try on
|
|
5
|
-
// $ examples/consumer run --protocol bsc --verbose
|
|
6
|
-
// $ examples/consumer run --protocol eth
|
|
7
|
-
// $ examples/consumer deploy --protocol eth
|
|
8
|
-
// $ examples/consumer --help
|
|
9
|
-
|
|
10
|
-
import { consumer, every, ERROR_LEVEL } from "../app.js";
|
|
11
|
-
|
|
12
|
-
async function consume({ protocol, messages, verbose }) {
|
|
13
|
-
console.log("consume called with", protocol, messages, verbose);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const app = consumer({
|
|
17
|
-
name: "example-consumer",
|
|
18
|
-
selector: { protocol: { type: "string", description: "from which chain to consume data" } },
|
|
19
|
-
|
|
20
|
-
consume: {
|
|
21
|
-
func: consume,
|
|
22
|
-
topic: ({ protocol }) => `lib-skynet-test-kafka-${protocol}-dev`,
|
|
23
|
-
maxRetry: 1,
|
|
24
|
-
|
|
25
|
-
cpu: 600,
|
|
26
|
-
mem: 600,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
app();
|
package/examples/producer.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// this file is executable and is for kafka producer testing
|
|
4
|
-
// a few test commands to try on
|
|
5
|
-
// $ examples/producer run --protocol bsc --verbose
|
|
6
|
-
// $ examples/producer run --protocol eth
|
|
7
|
-
// $ examples/producer deploy --protocol eth
|
|
8
|
-
// $ examples/producer --help
|
|
9
|
-
|
|
10
|
-
import { producer, every, SENSITIVE_VALUE, ERROR_LEVEL } from "../app.js";
|
|
11
|
-
|
|
12
|
-
async function produce({ protocol, from, to, verbose, send }) {
|
|
13
|
-
console.log("produce called with", protocol, from, to, verbose);
|
|
14
|
-
|
|
15
|
-
const items = [];
|
|
16
|
-
for (let i = from; i <= to; i++) {
|
|
17
|
-
items.push({ id: i, name: `${protocol} User ${i}` });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
await send(items);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const app = producer({
|
|
24
|
-
name: "example-producer",
|
|
25
|
-
selector: { protocol: { type: "string", description: "for which chain to produce data" } },
|
|
26
|
-
|
|
27
|
-
env: {
|
|
28
|
-
// sensitive value will be loaded from:
|
|
29
|
-
// local: process.env.HOME
|
|
30
|
-
// production: the secrets store on nomad cluster
|
|
31
|
-
// your local env value won't be uploaded to production
|
|
32
|
-
HOME: SENSITIVE_VALUE,
|
|
33
|
-
// concrete value is good for insensitive configuration
|
|
34
|
-
// the value is the same for local and production
|
|
35
|
-
TEST: "abcdefg",
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
state: {
|
|
39
|
-
type: "block", // can be omitted, default is block
|
|
40
|
-
updateInterval: ({ protocol }) => (protocol === "bsc" ? 3000 : 20000), // how often max id is increasing, will determine poll interval, default to 5000ms
|
|
41
|
-
getMinId: async () => 4, // default returns 1
|
|
42
|
-
getMaxId: async ({ protocol }) => {
|
|
43
|
-
console.log("getMaxId called", protocol);
|
|
44
|
-
|
|
45
|
-
return 100;
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
produce: {
|
|
50
|
-
func: produce,
|
|
51
|
-
|
|
52
|
-
topic: ({ protocol }) => `lib-skynet-test-kafka-${protocol}-dev`,
|
|
53
|
-
deadLetterTopic: ({ protocol }) => `lib-skynet-test-kafka-${protocol}-dead-letter-dev`, // problematic ids will be sent to dead letter topic for later retry
|
|
54
|
-
|
|
55
|
-
batchSize: 10, // default 50
|
|
56
|
-
maxRetry: 1, // default 2
|
|
57
|
-
|
|
58
|
-
cpu: 600,
|
|
59
|
-
mem: 600,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
app();
|
package/graphql.d.ts
DELETED
package/graphql.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export async function gql(query, variables = {}) {
|
|
2
|
-
const res = await fetch(process.env.SKYNET_GRAPHQL_ENDPOINT, {
|
|
3
|
-
method: "POST",
|
|
4
|
-
headers: {
|
|
5
|
-
"x-api-key": process.env.SKYNET_GRAPHQL_API_KEY,
|
|
6
|
-
"content-type": "application/json",
|
|
7
|
-
},
|
|
8
|
-
body: JSON.stringify({ query: query.trim(), variables }),
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
if (res.ok) {
|
|
12
|
-
const { data, errors } = await res.json();
|
|
13
|
-
|
|
14
|
-
if (errors && errors.length > 0) {
|
|
15
|
-
throw new Error(JSON.stringify(errors, null, 2));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return data;
|
|
19
|
-
} else {
|
|
20
|
-
throw new Error(await res.text());
|
|
21
|
-
}
|
|
22
|
-
}
|
package/indexer.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// module.exports = {
|
|
2
|
-
// getIndexerValidatedId,
|
|
3
|
-
// };
|
|
4
|
-
import { Build, State, Validate } from "./app";
|
|
5
|
-
import { SelectorFlags, Selector } from "./selector";
|
|
6
|
-
|
|
7
|
-
type CreateIndexerAppBaseParams = {
|
|
8
|
-
binaryName: string;
|
|
9
|
-
name: string;
|
|
10
|
-
selector?: Selector;
|
|
11
|
-
build: Build;
|
|
12
|
-
maxRetry?: number;
|
|
13
|
-
};
|
|
14
|
-
|
|
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 };
|
|
25
|
-
|
|
26
|
-
export function createIndexerApp(createModeIndexerAppParams: CreateIndexerAppBaseParams): { run: () => void };
|
|
27
|
-
|
|
28
|
-
export function getIndexerState(name: string, selectorFlags: SelectorFlags): Promise<string>;
|
|
29
|
-
|
|
30
|
-
export function getIndexerLatestId(name: string, selectorFlags: SelectorFlags): Promise<number>;
|
|
31
|
-
|
|
32
|
-
export function getIndexerValidatedId(name: string, selectorFlags: SelectorFlags): Promise<number>;
|
package/log.d.ts
DELETED
package/opsgenie.d.ts
DELETED