@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.
Files changed (56) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/examples/api.ts +0 -0
  3. package/examples/indexer.ts +0 -0
  4. package/examples/mode-indexer.ts +0 -0
  5. package/package.json +1 -12
  6. package/src/graphql.ts +14 -4
  7. package/src/por.ts +18 -23
  8. package/src/slack.ts +16 -12
  9. package/.vscode/settings.json +0 -5
  10. package/dist/abi.d.ts +0 -111
  11. package/dist/abi.js +0 -571
  12. package/dist/address.d.ts +0 -2
  13. package/dist/address.js +0 -24
  14. package/dist/api.d.ts +0 -31
  15. package/dist/api.js +0 -260
  16. package/dist/app.d.ts +0 -101
  17. package/dist/app.js +0 -2077
  18. package/dist/availability.d.ts +0 -23
  19. package/dist/availability.js +0 -133
  20. package/dist/cli.d.ts +0 -5
  21. package/dist/cli.js +0 -41
  22. package/dist/const.d.ts +0 -34
  23. package/dist/const.js +0 -162
  24. package/dist/databricks.d.ts +0 -3
  25. package/dist/databricks.js +0 -208
  26. package/dist/date.d.ts +0 -5
  27. package/dist/date.js +0 -56
  28. package/dist/deploy.d.ts +0 -75
  29. package/dist/deploy.js +0 -587
  30. package/dist/dynamodb.d.ts +0 -16
  31. package/dist/dynamodb.js +0 -479
  32. package/dist/env.d.ts +0 -6
  33. package/dist/env.js +0 -26
  34. package/dist/goalert.d.ts +0 -19
  35. package/dist/goalert.js +0 -43
  36. package/dist/graphql.d.ts +0 -5
  37. package/dist/graphql.js +0 -28
  38. package/dist/indexer.d.ts +0 -69
  39. package/dist/indexer.js +0 -1099
  40. package/dist/log.d.ts +0 -13
  41. package/dist/log.js +0 -63
  42. package/dist/object-hash.d.ts +0 -1
  43. package/dist/object-hash.js +0 -61
  44. package/dist/por.d.ts +0 -37
  45. package/dist/por.js +0 -120
  46. package/dist/s3.d.ts +0 -20
  47. package/dist/s3.js +0 -122
  48. package/dist/search.d.ts +0 -5
  49. package/dist/search.js +0 -105
  50. package/dist/selector.d.ts +0 -17
  51. package/dist/selector.js +0 -44
  52. package/dist/slack.d.ts +0 -9
  53. package/dist/slack.js +0 -32
  54. package/dist/util.d.ts +0 -4
  55. package/dist/util.js +0 -27
  56. 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 };