@certik/skynet 0.22.1 → 0.22.2
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 +4 -0
- package/build.ts +23 -0
- package/bun.lockb +0 -0
- package/dist/abi.d.ts +1 -2
- package/dist/abi.js +569 -563
- package/dist/address.d.ts +0 -1
- package/dist/address.js +22 -21
- package/dist/api.d.ts +0 -1
- package/dist/api.js +235 -120
- package/dist/app.d.ts +1 -2
- package/dist/app.js +2030 -276
- package/dist/availability.d.ts +0 -1
- package/dist/availability.js +126 -56
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +28 -24
- package/dist/const.d.ts +0 -1
- package/dist/const.js +153 -132
- package/dist/databricks.d.ts +0 -1
- package/dist/databricks.js +198 -58
- package/dist/date.d.ts +0 -1
- package/dist/date.js +48 -21
- package/dist/deploy.d.ts +0 -1
- package/dist/deploy.js +427 -292
- package/dist/dynamodb.d.ts +3 -4
- package/dist/dynamodb.js +432 -281
- package/dist/env.d.ts +2 -3
- package/dist/env.js +16 -9
- package/dist/graphql.d.ts +0 -1
- package/dist/graphql.js +26 -23
- package/dist/indexer.d.ts +0 -1
- package/dist/indexer.js +1050 -441
- package/dist/log.d.ts +0 -1
- package/dist/log.js +53 -52
- package/dist/object-hash.d.ts +0 -1
- package/dist/object-hash.js +49 -59
- package/dist/opsgenie.d.ts +1 -1
- package/dist/opsgenie.js +31 -30
- package/dist/por.d.ts +0 -1
- package/dist/por.js +113 -123
- package/dist/s3.d.ts +7 -8
- package/dist/s3.js +103 -91
- package/dist/search.d.ts +0 -1
- package/dist/search.js +100 -25
- package/dist/selector.d.ts +0 -1
- package/dist/selector.js +34 -38
- package/dist/slack.d.ts +0 -1
- package/dist/slack.js +27 -21
- package/dist/util.d.ts +0 -1
- package/dist/util.js +21 -20
- package/examples/api.ts +1 -1
- package/examples/indexer.ts +1 -1
- package/examples/mode-indexer.ts +1 -1
- package/package.json +5 -4
- package/{graphql.ts → src/graphql.ts} +1 -1
- package/{opsgenie.ts → src/opsgenie.ts} +2 -1
- package/tsconfig.build.json +2 -5
- package/tsconfig.json +11 -20
- package/dist/abi.d.ts.map +0 -1
- package/dist/address.d.ts.map +0 -1
- package/dist/api.d.ts.map +0 -1
- package/dist/app.d.ts.map +0 -1
- package/dist/availability.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/const.d.ts.map +0 -1
- package/dist/databricks.d.ts.map +0 -1
- package/dist/date.d.ts.map +0 -1
- package/dist/deploy.d.ts.map +0 -1
- package/dist/dynamodb.d.ts.map +0 -1
- package/dist/env.d.ts.map +0 -1
- package/dist/graphql.d.ts.map +0 -1
- package/dist/indexer.d.ts.map +0 -1
- package/dist/log.d.ts.map +0 -1
- package/dist/object-hash.d.ts.map +0 -1
- package/dist/opsgenie.d.ts.map +0 -1
- package/dist/por.d.ts.map +0 -1
- package/dist/s3.d.ts.map +0 -1
- package/dist/search.d.ts.map +0 -1
- package/dist/selector.d.ts.map +0 -1
- package/dist/slack.d.ts.map +0 -1
- package/dist/util.d.ts.map +0 -1
- /package/{abi.ts → src/abi.ts} +0 -0
- /package/{address.ts → src/address.ts} +0 -0
- /package/{api.ts → src/api.ts} +0 -0
- /package/{app.ts → src/app.ts} +0 -0
- /package/{availability.ts → src/availability.ts} +0 -0
- /package/{cli.ts → src/cli.ts} +0 -0
- /package/{const.ts → src/const.ts} +0 -0
- /package/{databricks.ts → src/databricks.ts} +0 -0
- /package/{date.ts → src/date.ts} +0 -0
- /package/{deploy.ts → src/deploy.ts} +0 -0
- /package/{dynamodb.ts → src/dynamodb.ts} +0 -0
- /package/{env.ts → src/env.ts} +0 -0
- /package/{indexer.ts → src/indexer.ts} +0 -0
- /package/{log.ts → src/log.ts} +0 -0
- /package/{object-hash.ts → src/object-hash.ts} +0 -0
- /package/{por.ts → src/por.ts} +0 -0
- /package/{s3.ts → src/s3.ts} +0 -0
- /package/{search.ts → src/search.ts} +0 -0
- /package/{selector.ts → src/selector.ts} +0 -0
- /package/{slack.ts → src/slack.ts} +0 -0
- /package/{util.ts → src/util.ts} +0 -0
package/dist/databricks.js
CHANGED
|
@@ -1,68 +1,208 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
// src/env.ts
|
|
2
|
+
function ensureAndGet(envName, defaultValue) {
|
|
3
|
+
return process.env[envName] || defaultValue;
|
|
4
|
+
}
|
|
5
|
+
function getEnvironment() {
|
|
6
|
+
return ensureAndGet("SKYNET_ENVIRONMENT", "dev");
|
|
7
|
+
}
|
|
8
|
+
function getEnvOrThrow(envName) {
|
|
9
|
+
if (!process.env[envName]) {
|
|
10
|
+
throw new Error(`Must set environment variable ${envName}`);
|
|
11
|
+
}
|
|
12
|
+
return process.env[envName];
|
|
13
|
+
}
|
|
14
|
+
function isProduction() {
|
|
15
|
+
return getEnvironment() === "prd";
|
|
16
|
+
}
|
|
17
|
+
function isDev() {
|
|
18
|
+
return getEnvironment() === "dev";
|
|
19
|
+
}
|
|
20
|
+
// src/object-hash.ts
|
|
21
|
+
import xh from "@node-rs/xxhash";
|
|
22
|
+
function getHash(obj) {
|
|
23
|
+
const xxh3 = xh.xxh3.Xxh3.withSeed();
|
|
24
|
+
hash(obj, xxh3);
|
|
25
|
+
return xxh3.digest().toString(16);
|
|
26
|
+
}
|
|
27
|
+
function hash(obj, xxh3) {
|
|
28
|
+
if (obj === null) {
|
|
29
|
+
xxh3.update("null");
|
|
30
|
+
} else if (obj === undefined) {
|
|
31
|
+
xxh3.update("undefined");
|
|
32
|
+
} else if (typeof obj === "string") {
|
|
33
|
+
xxh3.update(obj);
|
|
34
|
+
} else if (typeof obj === "number") {
|
|
35
|
+
xxh3.update(obj.toString());
|
|
36
|
+
} else if (typeof obj === "boolean") {
|
|
37
|
+
xxh3.update(obj.toString());
|
|
38
|
+
} else if (typeof obj === "bigint") {
|
|
39
|
+
xxh3.update(obj.toString());
|
|
40
|
+
} else if (obj instanceof Date) {
|
|
41
|
+
xxh3.update(obj.toISOString());
|
|
42
|
+
} else if (Array.isArray(obj)) {
|
|
43
|
+
arrayHash(obj, xxh3);
|
|
44
|
+
} else if (obj instanceof Set) {
|
|
45
|
+
setHash(obj, xxh3);
|
|
46
|
+
} else if (obj instanceof Map) {
|
|
47
|
+
mapHash(obj, xxh3);
|
|
48
|
+
} else if (typeof obj === "object") {
|
|
49
|
+
objectHash(obj, xxh3);
|
|
50
|
+
} else {
|
|
51
|
+
throw new Error(`Unsupported type: ${obj}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function arrayHash(array, xxh3) {
|
|
55
|
+
xxh3.update("[");
|
|
56
|
+
for (const obj of array) {
|
|
57
|
+
hash(obj, xxh3);
|
|
58
|
+
}
|
|
59
|
+
xxh3.update("]");
|
|
60
|
+
}
|
|
61
|
+
function setHash(_set, _xxh3) {
|
|
62
|
+
throw new Error("Set hashing not implemented");
|
|
63
|
+
}
|
|
64
|
+
function mapHash(map, xxh3) {
|
|
65
|
+
const array = Array.from(map.entries()).sort(([aKey], [bKey]) => aKey.localeCompare(bKey));
|
|
66
|
+
for (const [key, value] of array) {
|
|
67
|
+
hash(key, xxh3);
|
|
68
|
+
hash(value, xxh3);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function objectHash(obj, xxh3) {
|
|
72
|
+
const array = Object.entries(obj).sort(([aKey], [bKey]) => aKey.localeCompare(bKey));
|
|
73
|
+
for (const [key, value] of array) {
|
|
74
|
+
hash(key, xxh3);
|
|
75
|
+
hash(value, xxh3);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/availability.ts
|
|
80
|
+
import pThrottle from "p-throttle";
|
|
81
|
+
import pMemoize from "p-memoize";
|
|
82
|
+
import QuickLRU from "quick-lru";
|
|
83
|
+
async function wait(time) {
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
|
+
setTimeout(resolve, time);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async function exponentialRetry(func, {
|
|
89
|
+
maxRetry,
|
|
90
|
+
initialDuration,
|
|
91
|
+
growFactor,
|
|
92
|
+
test,
|
|
93
|
+
verbose
|
|
94
|
+
}) {
|
|
95
|
+
let retries = maxRetry;
|
|
96
|
+
let duration = initialDuration || 5000;
|
|
97
|
+
const growFactorFinal = growFactor || 2;
|
|
98
|
+
let result = await func();
|
|
99
|
+
while (!test(result) && retries > 0) {
|
|
100
|
+
if (verbose) {
|
|
101
|
+
console.log("failed attempt result", result);
|
|
102
|
+
console.log(`sleep for ${duration}ms after failed attempt, remaining ${retries} attempts`);
|
|
18
103
|
}
|
|
104
|
+
retries = retries - 1;
|
|
105
|
+
await wait(duration);
|
|
106
|
+
result = await func();
|
|
107
|
+
duration = duration * growFactorFinal;
|
|
108
|
+
}
|
|
109
|
+
if (verbose) {
|
|
110
|
+
console.log(`function to retry ends with status ${test(result)}, number of retries done: ${maxRetry - retries}}`);
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
19
113
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const result = await queryOperation.fetchAll();
|
|
33
|
-
return result;
|
|
114
|
+
function withRetry(func, options) {
|
|
115
|
+
let retries = options?.maxRetry || 3;
|
|
116
|
+
let duration = options?.initialDuration || 500;
|
|
117
|
+
const growFactorFinal = options?.growFactor || 2;
|
|
118
|
+
return async (...args) => {
|
|
119
|
+
do {
|
|
120
|
+
try {
|
|
121
|
+
return await func(...args);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
retries = retries - 1;
|
|
124
|
+
if (retries <= 0) {
|
|
125
|
+
throw error;
|
|
34
126
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
127
|
+
await wait(duration);
|
|
128
|
+
duration = duration * growFactorFinal;
|
|
129
|
+
}
|
|
130
|
+
} while (retries > 0);
|
|
131
|
+
throw new Error("unreachable");
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function memoize(func, options) {
|
|
135
|
+
if (!options) {
|
|
136
|
+
options = {};
|
|
137
|
+
}
|
|
138
|
+
if (!options.cache) {
|
|
139
|
+
options.cache = new QuickLRU({ maxSize: options.lruMaxSize || 1e4 });
|
|
140
|
+
}
|
|
141
|
+
if (!options.cacheKey) {
|
|
142
|
+
options.cacheKey = (args) => getHash(args);
|
|
143
|
+
}
|
|
144
|
+
return pMemoize(func, options);
|
|
145
|
+
}
|
|
146
|
+
// src/databricks.ts
|
|
147
|
+
import { DBSQLClient, DBSQLParameter } from "@databricks/sql";
|
|
148
|
+
var client = null;
|
|
149
|
+
var session = null;
|
|
150
|
+
async function initSession() {
|
|
151
|
+
if (!client) {
|
|
152
|
+
client = new DBSQLClient;
|
|
153
|
+
await client.connect({
|
|
154
|
+
authType: "access-token",
|
|
155
|
+
token: getEnvOrThrow("SKYNET_DATABRICKS_TOKEN"),
|
|
156
|
+
host: getEnvOrThrow("SKYNET_DATABRICKS_SERVER_HOSTNAME"),
|
|
157
|
+
path: getEnvOrThrow("SKYNET_DATABRICKS_HTTP_PATH")
|
|
51
158
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
159
|
+
}
|
|
160
|
+
if (!session) {
|
|
161
|
+
session = await client.openSession();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function executeSql(sql, bindings) {
|
|
165
|
+
const results = await exponentialRetry(async () => {
|
|
166
|
+
let queryOperation;
|
|
167
|
+
try {
|
|
168
|
+
await initSession();
|
|
169
|
+
if (!session)
|
|
170
|
+
throw new Error("Session is not initialized");
|
|
171
|
+
queryOperation = await session.executeStatement(sql, {
|
|
172
|
+
runAsync: true,
|
|
173
|
+
namedParameters: objToParameter(bindings)
|
|
174
|
+
});
|
|
175
|
+
const result = await queryOperation.fetchAll();
|
|
176
|
+
return result;
|
|
177
|
+
} catch (err) {
|
|
178
|
+
if (!checkIsDatabricksError(err)) {
|
|
179
|
+
throw err;
|
|
180
|
+
}
|
|
181
|
+
return err;
|
|
182
|
+
} finally {
|
|
183
|
+
await queryOperation?.close();
|
|
184
|
+
}
|
|
185
|
+
}, {
|
|
186
|
+
maxRetry: 3,
|
|
187
|
+
initialDuration: 500,
|
|
188
|
+
test: (result) => {
|
|
189
|
+
return !checkIsDatabricksError(result);
|
|
55
190
|
}
|
|
56
|
-
|
|
191
|
+
});
|
|
192
|
+
if (checkIsDatabricksError(results)) {
|
|
193
|
+
throw results;
|
|
194
|
+
}
|
|
195
|
+
return results;
|
|
57
196
|
}
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
197
|
function checkIsDatabricksError(err) {
|
|
60
|
-
|
|
198
|
+
return err?.errno === "ECONNRESET" || err?.message?.includes("java.lang.NullPointerException");
|
|
61
199
|
}
|
|
62
200
|
function objToParameter(obj) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
201
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
202
|
+
acc[key] = new DBSQLParameter({ value });
|
|
203
|
+
return acc;
|
|
204
|
+
}, {});
|
|
67
205
|
}
|
|
68
|
-
export {
|
|
206
|
+
export {
|
|
207
|
+
executeSql
|
|
208
|
+
};
|
package/dist/date.d.ts
CHANGED
|
@@ -3,4 +3,3 @@ declare function findDateAfter(date: number | string | Date, n: number): string;
|
|
|
3
3
|
declare function daysInRange(from: number | string | Date, to: number | string | Date): string[];
|
|
4
4
|
declare function dateRange(from: number | string | Date, to: number | string | Date, step: number): [string, string][];
|
|
5
5
|
export { getDateOnly, findDateAfter, daysInRange, dateRange };
|
|
6
|
-
//# sourceMappingURL=date.d.ts.map
|
package/dist/date.js
CHANGED
|
@@ -1,29 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/util.ts
|
|
2
|
+
function range(startAt, endAt, step) {
|
|
3
|
+
const arr = [];
|
|
4
|
+
for (let i = startAt;i <= endAt; i += step) {
|
|
5
|
+
arr.push([i, Math.min(endAt, i + step - 1)]);
|
|
6
|
+
}
|
|
7
|
+
return arr;
|
|
8
|
+
}
|
|
9
|
+
function arrayGroup(array, groupSize) {
|
|
10
|
+
const groups = [];
|
|
11
|
+
for (let i = 0;i < array.length; i += groupSize) {
|
|
12
|
+
groups.push(array.slice(i, i + groupSize));
|
|
13
|
+
}
|
|
14
|
+
return groups;
|
|
15
|
+
}
|
|
16
|
+
function fillRange(start, end) {
|
|
17
|
+
const result = [];
|
|
18
|
+
for (let i = start;i <= end; i++) {
|
|
19
|
+
result.push(i);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
// src/date.ts
|
|
24
|
+
var MS_IN_A_DAY = 3600 * 24 * 1000;
|
|
3
25
|
function getDateOnly(date) {
|
|
4
|
-
|
|
26
|
+
return new Date(date).toISOString().split("T")[0];
|
|
5
27
|
}
|
|
6
28
|
function findDateAfter(date, n) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
29
|
+
const d = new Date(date);
|
|
30
|
+
const after = new Date(d.getTime() + MS_IN_A_DAY * n);
|
|
31
|
+
return getDateOnly(after);
|
|
10
32
|
}
|
|
11
33
|
function daysInRange(from, to) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
34
|
+
const fromTime = new Date(from).getTime();
|
|
35
|
+
const toTime = new Date(to).getTime();
|
|
36
|
+
if (fromTime > toTime) {
|
|
37
|
+
throw new Error(`range to date couldn't be earlier than range from date`);
|
|
38
|
+
}
|
|
39
|
+
const daysBetween = Math.floor((toTime - fromTime) / MS_IN_A_DAY);
|
|
40
|
+
const dates = [getDateOnly(new Date(fromTime))];
|
|
41
|
+
for (let i = 1;i <= daysBetween; i += 1) {
|
|
42
|
+
dates.push(getDateOnly(new Date(fromTime + i * MS_IN_A_DAY)));
|
|
43
|
+
}
|
|
44
|
+
return dates;
|
|
23
45
|
}
|
|
24
46
|
function dateRange(from, to, step) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
47
|
+
const days = daysInRange(from, to);
|
|
48
|
+
const windows = arrayGroup(days, step);
|
|
49
|
+
return windows.map((w) => [w[0], w[w.length - 1]]);
|
|
28
50
|
}
|
|
29
|
-
export {
|
|
51
|
+
export {
|
|
52
|
+
getDateOnly,
|
|
53
|
+
findDateAfter,
|
|
54
|
+
daysInRange,
|
|
55
|
+
dateRange
|
|
56
|
+
};
|
package/dist/deploy.d.ts
CHANGED