@8ms/helpers 1.1.56 → 1.1.59
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/aws/athenaExpress/initClient.d.ts +7 -5
- package/aws/athenaExpress/initClient.js +2 -2
- package/aws/athenaExpress/request.d.ts +1 -5
- package/aws/athenaExpress/request.js +3 -9
- package/aws/s3/getGlueJson.d.ts +4 -0
- package/aws/s3/getGlueJson.js +16 -0
- package/package.json +43 -43
- package/aws/s3/writeGlueJsonFile.d.ts +0 -12
- package/aws/s3/writeGlueJsonFile.js +0 -67
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Config } from '../config';
|
|
2
|
+
declare type InitClient = {
|
|
3
|
+
config: Config;
|
|
4
|
+
database: string;
|
|
5
|
+
s3Bucket: string;
|
|
6
|
+
s3Key: string;
|
|
7
|
+
};
|
|
2
8
|
/**
|
|
3
9
|
* Initialise the database using manually provided credentials.
|
|
4
10
|
*/
|
|
5
|
-
declare const initClient: ({
|
|
6
|
-
athenaS3?: string;
|
|
7
|
-
config?: Config;
|
|
8
|
-
database?: string;
|
|
9
|
-
}) => void;
|
|
11
|
+
declare const initClient: ({ config, database, s3Bucket, s3Key }: InitClient) => void;
|
|
10
12
|
export default initClient;
|
|
@@ -9,7 +9,7 @@ global.awsAthenaExpressClient = null;
|
|
|
9
9
|
* Initialise the database using manually provided credentials.
|
|
10
10
|
*/
|
|
11
11
|
var initClient = function (_a) {
|
|
12
|
-
var
|
|
12
|
+
var config = _a.config, database = _a.database, s3Bucket = _a.s3Bucket, s3Key = _a.s3Key;
|
|
13
13
|
if (!global.awsAthenaExpressClient) {
|
|
14
14
|
var athenaExpress = require('athena-express');
|
|
15
15
|
var awsSdk = require('aws-sdk');
|
|
@@ -18,7 +18,7 @@ var initClient = function (_a) {
|
|
|
18
18
|
awsSdk.config.update(formattedConfig);
|
|
19
19
|
global.awsAthenaExpressClient = new athenaExpress.AthenaExpress({
|
|
20
20
|
aws: awsSdk,
|
|
21
|
-
s3:
|
|
21
|
+
s3: "s3://".concat(s3Bucket, "/").concat(s3Key),
|
|
22
22
|
db: database,
|
|
23
23
|
formatJson: true,
|
|
24
24
|
retry: 200,
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { Config } from '../config';
|
|
2
1
|
declare type Request = {
|
|
3
|
-
athenaS3?: string;
|
|
4
|
-
config?: Config;
|
|
5
|
-
database?: string;
|
|
6
2
|
query: string;
|
|
7
3
|
};
|
|
8
4
|
/**
|
|
9
5
|
* Build the query and return the data.
|
|
10
6
|
*/
|
|
11
|
-
declare const request: ({
|
|
7
|
+
declare const request: ({ query }: Request) => Promise<any>;
|
|
12
8
|
export default request;
|
|
@@ -35,23 +35,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
var initClient_1 = __importDefault(require("./initClient"));
|
|
43
39
|
/**
|
|
44
40
|
* Build the query and return the data.
|
|
45
41
|
*/
|
|
46
42
|
var request = function (_a) {
|
|
47
|
-
var
|
|
43
|
+
var query = _a.query;
|
|
48
44
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
49
45
|
return __generator(this, function (_b) {
|
|
50
46
|
switch (_b.label) {
|
|
51
|
-
case 0:
|
|
52
|
-
|
|
53
|
-
return [4 /*yield*/, global.awsAthenaExpressClient.query(query)
|
|
54
|
-
.then(function (data) { return undefined === data['Items'] ? [] : data['Items']; })];
|
|
47
|
+
case 0: return [4 /*yield*/, global.awsAthenaExpressClient.query(query)
|
|
48
|
+
.then(function (data) { return undefined === data['Items'] ? [] : data['Items']; })];
|
|
55
49
|
case 1: return [2 /*return*/, _b.sent()];
|
|
56
50
|
}
|
|
57
51
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var getArray_1 = __importDefault(require("../../array/getArray"));
|
|
7
|
+
var getGlueJson = function (_a) {
|
|
8
|
+
var data = _a.data;
|
|
9
|
+
// Must be an array
|
|
10
|
+
var inputArray = (0, getArray_1.default)({ input: data });
|
|
11
|
+
// For each array row convert the row
|
|
12
|
+
var stringRows = inputArray.map(function (row) { return JSON.stringify(row); });
|
|
13
|
+
// Combine each row with a line separator
|
|
14
|
+
return stringRows.join("\n");
|
|
15
|
+
};
|
|
16
|
+
exports.default = getGlueJson;
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
2
|
+
"name": "@8ms/helpers",
|
|
3
|
+
"license": "UNLICENSED",
|
|
4
|
+
"version": "1.1.59",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
|
|
8
|
+
},
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"types": "index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "rimraf dist && tsc",
|
|
13
|
+
"jest": "jest --watch"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"axios": "0.27.2",
|
|
17
|
+
"crypto-js": "4.1.1",
|
|
18
|
+
"date-fns": "2.29.2",
|
|
19
|
+
"date-fns-tz": "1.3.6",
|
|
20
|
+
"lodash": "4.17.21"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@aws-sdk/client-s3": "3.157.0",
|
|
24
|
+
"@aws-sdk/client-ses": "3.154.0",
|
|
25
|
+
"@aws-sdk/client-ssm": "3.154.0",
|
|
26
|
+
"@aws-sdk/s3-request-presigner": "3.157.0",
|
|
27
|
+
"@babel/preset-env": "7.18.10",
|
|
28
|
+
"@babel/preset-flow": "7.18.6",
|
|
29
|
+
"@babel/preset-typescript": "7.18.6",
|
|
30
|
+
"@google-cloud/storage": "6.4.1",
|
|
31
|
+
"@prisma/client": "4.2.1",
|
|
32
|
+
"@types/jest": "28.1.8",
|
|
33
|
+
"@types/lodash": "4.14.184",
|
|
34
|
+
"@types/node": "18.7.13",
|
|
35
|
+
"babel-jest": "28.1.3",
|
|
36
|
+
"jest": "28.1.3",
|
|
37
|
+
"node-fetch": "3.2.10",
|
|
38
|
+
"numbro": "2.3.6",
|
|
39
|
+
"prisma-query-log": "3.2.0",
|
|
40
|
+
"timezone-mock": "1.3.4",
|
|
41
|
+
"ts-node": "10.9.1",
|
|
42
|
+
"tslib": "2.4.0",
|
|
43
|
+
"typescript": "4.7.4"
|
|
44
|
+
}
|
|
45
45
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare type WriteGlueJsonFile = {
|
|
2
|
-
bucket: string;
|
|
3
|
-
data: object[];
|
|
4
|
-
key: string;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Convert the object into a JSON file so it's ready to be used with AWS Glue.
|
|
8
|
-
* Input: Must be an array of objects that are the same.
|
|
9
|
-
* Output: No array [] brackets, each object must on its own new line.
|
|
10
|
-
*/
|
|
11
|
-
export declare const writeGlueJsonFile: ({ bucket, data, key }: WriteGlueJsonFile) => Promise<any>;
|
|
12
|
-
export default writeGlueJsonFile;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.writeGlueJsonFile = void 0;
|
|
43
|
-
var getArray_1 = __importDefault(require("../../array/getArray"));
|
|
44
|
-
var writeFile_1 = __importDefault(require("./writeFile"));
|
|
45
|
-
/**
|
|
46
|
-
* Convert the object into a JSON file so it's ready to be used with AWS Glue.
|
|
47
|
-
* Input: Must be an array of objects that are the same.
|
|
48
|
-
* Output: No array [] brackets, each object must on its own new line.
|
|
49
|
-
*/
|
|
50
|
-
var writeGlueJsonFile = function (_a) {
|
|
51
|
-
var bucket = _a.bucket, data = _a.data, key = _a.key;
|
|
52
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
53
|
-
var inputArray, stringRows, concatString;
|
|
54
|
-
return __generator(this, function (_b) {
|
|
55
|
-
switch (_b.label) {
|
|
56
|
-
case 0:
|
|
57
|
-
inputArray = (0, getArray_1.default)({ input: data });
|
|
58
|
-
stringRows = inputArray.map(function (row) { return JSON.stringify(row); });
|
|
59
|
-
concatString = stringRows.join("\n");
|
|
60
|
-
return [4 /*yield*/, (0, writeFile_1.default)({ bucket: bucket, data: concatString, key: key })];
|
|
61
|
-
case 1: return [2 /*return*/, _b.sent()];
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
exports.writeGlueJsonFile = writeGlueJsonFile;
|
|
67
|
-
exports.default = exports.writeGlueJsonFile;
|