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