@certik/skynet 0.23.0 → 0.25.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/CHANGELOG.md +11 -0
- package/examples/api.ts +0 -0
- package/examples/indexer.ts +0 -0
- package/examples/mode-indexer.ts +0 -0
- package/package.json +1 -12
- package/src/graphql.ts +14 -4
- package/src/por.ts +18 -23
- package/src/slack.ts +16 -12
- package/.vscode/settings.json +0 -5
- package/dist/abi.d.ts +0 -111
- package/dist/abi.js +0 -571
- package/dist/address.d.ts +0 -2
- package/dist/address.js +0 -24
- package/dist/api.d.ts +0 -31
- package/dist/api.js +0 -260
- package/dist/app.d.ts +0 -101
- package/dist/app.js +0 -2077
- package/dist/availability.d.ts +0 -23
- package/dist/availability.js +0 -133
- package/dist/cli.d.ts +0 -5
- package/dist/cli.js +0 -41
- package/dist/const.d.ts +0 -34
- package/dist/const.js +0 -162
- package/dist/databricks.d.ts +0 -3
- package/dist/databricks.js +0 -208
- package/dist/date.d.ts +0 -5
- package/dist/date.js +0 -56
- package/dist/deploy.d.ts +0 -75
- package/dist/deploy.js +0 -587
- package/dist/dynamodb.d.ts +0 -16
- package/dist/dynamodb.js +0 -479
- package/dist/env.d.ts +0 -6
- package/dist/env.js +0 -26
- package/dist/goalert.d.ts +0 -19
- package/dist/goalert.js +0 -43
- package/dist/graphql.d.ts +0 -5
- package/dist/graphql.js +0 -28
- package/dist/indexer.d.ts +0 -69
- package/dist/indexer.js +0 -1099
- package/dist/log.d.ts +0 -13
- package/dist/log.js +0 -63
- package/dist/object-hash.d.ts +0 -1
- package/dist/object-hash.js +0 -61
- package/dist/por.d.ts +0 -37
- package/dist/por.js +0 -120
- package/dist/s3.d.ts +0 -20
- package/dist/s3.js +0 -122
- package/dist/search.d.ts +0 -5
- package/dist/search.js +0 -105
- package/dist/selector.d.ts +0 -17
- package/dist/selector.js +0 -44
- package/dist/slack.d.ts +0 -9
- package/dist/slack.js +0 -32
- package/dist/util.d.ts +0 -4
- package/dist/util.js +0 -27
- package/src/databricks.ts +0 -82
package/src/databricks.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { DBSQLClient, DBSQLParameter } from "@databricks/sql";
|
|
2
|
-
import { getEnvOrThrow } from "./env.js";
|
|
3
|
-
import { exponentialRetry } from "./availability.js";
|
|
4
|
-
import type IDBSQLSession from "@databricks/sql/dist/contracts/IDBSQLSession.js";
|
|
5
|
-
import type { DBSQLParameterValue } from "@databricks/sql/dist/DBSQLParameter.js";
|
|
6
|
-
|
|
7
|
-
let client: DBSQLClient | null = null;
|
|
8
|
-
|
|
9
|
-
let session: IDBSQLSession | null = null;
|
|
10
|
-
|
|
11
|
-
async function initSession() {
|
|
12
|
-
if (!client) {
|
|
13
|
-
client = new DBSQLClient();
|
|
14
|
-
await client.connect({
|
|
15
|
-
authType: "access-token",
|
|
16
|
-
token: getEnvOrThrow("SKYNET_DATABRICKS_TOKEN"),
|
|
17
|
-
host: getEnvOrThrow("SKYNET_DATABRICKS_SERVER_HOSTNAME"),
|
|
18
|
-
path: getEnvOrThrow("SKYNET_DATABRICKS_HTTP_PATH"),
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
if (!session) {
|
|
22
|
-
session = await client.openSession();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async function executeSql<T>(sql: string, bindings: Record<string, DBSQLParameterValue>) {
|
|
27
|
-
// retry sql query to avoid socket hang up error
|
|
28
|
-
const results = await exponentialRetry(
|
|
29
|
-
async () => {
|
|
30
|
-
let queryOperation;
|
|
31
|
-
try {
|
|
32
|
-
await initSession();
|
|
33
|
-
if (!session) throw new Error("Session is not initialized");
|
|
34
|
-
queryOperation = await session.executeStatement(sql, {
|
|
35
|
-
runAsync: true,
|
|
36
|
-
namedParameters: objToParameter(bindings),
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const result = await queryOperation.fetchAll();
|
|
40
|
-
return result;
|
|
41
|
-
} catch (err) {
|
|
42
|
-
// If the error is not a Databricks error, throw it
|
|
43
|
-
if (!checkIsDatabricksError(err)) {
|
|
44
|
-
throw err;
|
|
45
|
-
}
|
|
46
|
-
return err;
|
|
47
|
-
} finally {
|
|
48
|
-
await queryOperation?.close();
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
maxRetry: 3,
|
|
53
|
-
initialDuration: 500,
|
|
54
|
-
test: (result) => {
|
|
55
|
-
return !checkIsDatabricksError(result);
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
if (checkIsDatabricksError(results)) {
|
|
61
|
-
// still error after retry, throw it
|
|
62
|
-
throw results;
|
|
63
|
-
}
|
|
64
|
-
return results as T[];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
-
function checkIsDatabricksError(err: any) {
|
|
69
|
-
return err?.errno === "ECONNRESET" || err?.message?.includes("java.lang.NullPointerException");
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function objToParameter(obj: Record<string, DBSQLParameterValue>) {
|
|
73
|
-
return Object.entries(obj).reduce(
|
|
74
|
-
(acc, [key, value]) => {
|
|
75
|
-
acc[key] = new DBSQLParameter({ value });
|
|
76
|
-
return acc;
|
|
77
|
-
},
|
|
78
|
-
{} as Record<string, DBSQLParameter>,
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export { executeSql };
|