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