@certik/skynet 0.18.7 → 0.18.8

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/.eslintrc.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
+ "extends": ["eslint:recommended", "plugin:import/recommended", "plugin:md/prettier"],
3
+ "parserOptions": {
4
+ "ecmaVersion": 2023
5
+ },
2
6
  "env": {
3
7
  "node": true,
4
8
  "browser": false,
5
- "es2021": true
6
- },
7
- "extends": ["eslint:recommended", "plugin:import/recommended"],
8
- "parserOptions": {
9
- "ecmaVersion": "latest",
10
- "sourceType": "module"
9
+ "es2023": true
11
10
  },
12
11
  "settings": {
13
12
  "import/core-modules": ["ava", "meow"],
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.18.8
4
+
5
+ - Added `databricks` library with `executeSql` function
6
+
3
7
  ## 0.18.7
4
8
 
5
9
  - Update type definition for app.js and selector.js
@@ -297,9 +301,9 @@
297
301
 
298
302
  ## 0.10.21
299
303
 
300
- - Enabled more customizations for indexer selector support, check https://github.com/sindresorhus/meow for available config options, an example
304
+ - Enabled more customizations for indexer selector support, check <https://github.com/sindresorhus/meow> for available config options, an example
301
305
 
302
- ```
306
+ ```bash
303
307
  selectors: {
304
308
  "onlyProject": {
305
309
  type: "string",
package/README.md CHANGED
@@ -2,22 +2,22 @@
2
2
 
3
3
  ## Usage
4
4
 
5
- ```
6
- yarn add @certik/skynet
5
+ ```bash
6
+ bun add @certik/skynet
7
7
  ```
8
8
 
9
- ```
9
+ ```bash
10
10
  const { scanWholeTable } = require("@certik/skynet/dynamodb");
11
11
  ```
12
12
 
13
13
  ## Test
14
14
 
15
- ```
16
- yarn test
15
+ ```bash
16
+ bun run test
17
17
  ```
18
18
 
19
19
  ## Publish
20
20
 
21
- ```
22
- yarn publish --access public
21
+ ```bash
22
+ bun run pub
23
23
  ```
package/bun.lockb CHANGED
Binary file
package/databricks.js ADDED
@@ -0,0 +1,81 @@
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() {
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
+ });
24
+ }
25
+ if (!session) {
26
+ session = await client.openSession();
27
+ }
28
+ }
29
+
30
+ async function executeSql(sql, bindings) {
31
+ // retry sql query to avoid socket hang up error
32
+ const results = exponentialRetry(
33
+ async () => {
34
+ let queryOperation;
35
+ try {
36
+ await initSession();
37
+ queryOperation = await session.executeStatement(sql, {
38
+ runAsync: true,
39
+ namedParameters: objToParameter(bindings),
40
+ });
41
+
42
+ const result = await queryOperation.fetchAll();
43
+ return result;
44
+ } catch (err) {
45
+ // If the error is not a Databricks error, throw it
46
+ if (!checkIsDatabricksError(err)) {
47
+ throw err;
48
+ }
49
+ return err;
50
+ } finally {
51
+ await queryOperation?.close();
52
+ }
53
+ },
54
+ {
55
+ maxRetry: 3,
56
+ initialDuration: 500,
57
+ test: (result) => {
58
+ return !checkIsDatabricksError(result);
59
+ },
60
+ },
61
+ );
62
+
63
+ if (checkIsDatabricksError(results)) {
64
+ // still error after retry, throw it
65
+ throw results;
66
+ }
67
+ return results;
68
+ }
69
+
70
+ function checkIsDatabricksError(err) {
71
+ return err?.errno === "ECONNRESET" || err?.message?.includes("java.lang.NullPointerException");
72
+ }
73
+
74
+ function objToParameter(obj) {
75
+ return Object.entries(obj).reduce((acc, [key, value]) => {
76
+ acc[key] = new DBSQLParameter({ value });
77
+ return acc;
78
+ }, {});
79
+ }
80
+
81
+ export { executeSql };
package/examples/api.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.18.7",
3
+ "version": "0.18.8",
4
4
  "description": "Skynet Shared JS library",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -19,6 +19,7 @@
19
19
  "@aws-sdk/client-s3": "^3.478.0",
20
20
  "@aws-sdk/client-sqs": "^3.478.0",
21
21
  "@aws-sdk/lib-dynamodb": "^3.478.0",
22
+ "@databricks/sql": "^1.9.0",
22
23
  "@elastic/elasticsearch": "^8.14.0",
23
24
  "@slack/web-api": "^6.11.0",
24
25
  "bottleneck": "^2.19.5",
@@ -33,8 +34,9 @@
33
34
  },
34
35
  "devDependencies": {
35
36
  "ava": "^6.1.3",
36
- "eslint": "8",
37
+ "eslint": "^8.45.0",
37
38
  "eslint-plugin-import": "^2.29.1",
39
+ "eslint-plugin-md": "^1.0.19",
38
40
  "prettier": "^3.3.3",
39
41
  "sinon": "^18.0.0"
40
42
  },
@@ -42,4 +44,4 @@
42
44
  "publishConfig": {
43
45
  "access": "public"
44
46
  }
45
- }
47
+ }
@@ -1,5 +0,0 @@
1
- {
2
- "conventionalCommits.scopes": [
3
- "lib-skynet"
4
- ]
5
- }