@8ms/helpers 1.1.91 → 1.1.93
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/google/bigQuery/createTable.d.ts +1 -0
- package/google/bigQuery/createTable.js +1 -0
- package/google/bigQuery/loadData.d.ts +12 -0
- package/google/bigQuery/loadData.js +18 -0
- package/google/storage/copyToCloud.d.ts +10 -0
- package/google/storage/copyToCloud.js +13 -0
- package/google/storage/writeFile.d.ts +2 -2
- package/google/storage/writeFile.js +3 -3
- package/package.json +50 -50
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const IsTableExists_1 = __importDefault(require("./IsTableExists"));
|
|
7
7
|
/**
|
|
8
8
|
* Create a Table if it doesn't already exist.
|
|
9
|
+
* Returns table instance.
|
|
9
10
|
*/
|
|
10
11
|
const createTable = async ({ datasetId, options, tableId }) => {
|
|
11
12
|
const tableExists = await (0, IsTableExists_1.default)({ datasetId, tableId });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare type LoadData = {
|
|
2
|
+
bucket: string;
|
|
3
|
+
key: string;
|
|
4
|
+
datasetId: string;
|
|
5
|
+
tableId: string;
|
|
6
|
+
metadata: object;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Load data into a given table.
|
|
10
|
+
*/
|
|
11
|
+
declare const loadData: ({ bucket, datasetId, key, metadata, tableId }: LoadData) => Promise<void>;
|
|
12
|
+
export default loadData;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
const IsTableExists_1 = __importDefault(require("./IsTableExists"));
|
|
7
|
+
/**
|
|
8
|
+
* Load data into a given table.
|
|
9
|
+
*/
|
|
10
|
+
const loadData = async ({ bucket, datasetId, key, metadata, tableId }) => {
|
|
11
|
+
const tableExists = await (0, IsTableExists_1.default)({ datasetId, tableId });
|
|
12
|
+
if (tableExists) {
|
|
13
|
+
await global.googleBigQueryClient.dataset(datasetId)
|
|
14
|
+
.table(tableId)
|
|
15
|
+
.load(global.googleStorageClient.bucket(bucket).file(key), metadata);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.default = loadData;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare type CopyToCloud = {
|
|
2
|
+
bucket: string;
|
|
3
|
+
localFile: string;
|
|
4
|
+
options?: object;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Copy a local file to Google Cloud Storage.
|
|
8
|
+
*/
|
|
9
|
+
export declare const copyToCloud: ({ bucket, localFile, options }: CopyToCloud) => Promise<any>;
|
|
10
|
+
export default copyToCloud;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyToCloud = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Copy a local file to Google Cloud Storage.
|
|
6
|
+
*/
|
|
7
|
+
const copyToCloud = async ({ bucket, localFile, options }) => {
|
|
8
|
+
const bucketInstance = global.googleStorageClient.bucket(bucket);
|
|
9
|
+
const apiResponse = bucketInstance.upload(localFile, options);
|
|
10
|
+
return apiResponse;
|
|
11
|
+
};
|
|
12
|
+
exports.copyToCloud = copyToCloud;
|
|
13
|
+
exports.default = exports.copyToCloud;
|
|
@@ -2,10 +2,10 @@ declare type WriteFile = {
|
|
|
2
2
|
bucket: string;
|
|
3
3
|
data: any;
|
|
4
4
|
key: string;
|
|
5
|
-
|
|
5
|
+
[options: string]: any;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* Write a file to Google Cloud Storage.
|
|
9
9
|
*/
|
|
10
|
-
export declare const writeFile: ({ bucket, data, key,
|
|
10
|
+
export declare const writeFile: ({ bucket, contentType, data, key, ...options }: WriteFile) => Promise<any>;
|
|
11
11
|
export default writeFile;
|
|
@@ -4,7 +4,7 @@ exports.writeFile = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* Write a file to Google Cloud Storage.
|
|
6
6
|
*/
|
|
7
|
-
const writeFile = async ({ bucket, data, key,
|
|
7
|
+
const writeFile = async ({ bucket, contentType, data, key, ...options }) => {
|
|
8
8
|
const stream = require('stream');
|
|
9
9
|
const dataStream = new stream.PassThrough();
|
|
10
10
|
const googleFile = global.googleStorageClient.bucket(bucket)
|
|
@@ -16,13 +16,13 @@ const writeFile = async ({ bucket, data, key, metadata }) => {
|
|
|
16
16
|
contentType: 'auto',
|
|
17
17
|
resumable: false,
|
|
18
18
|
validation: false,
|
|
19
|
-
metadata:
|
|
19
|
+
metadata: {},
|
|
20
|
+
...options,
|
|
20
21
|
}))
|
|
21
22
|
.on('error', (error) => {
|
|
22
23
|
reject(error);
|
|
23
24
|
})
|
|
24
25
|
.on('finish', () => {
|
|
25
|
-
// console.log(`File uploaded successfully.`);
|
|
26
26
|
resolve(true);
|
|
27
27
|
});
|
|
28
28
|
});
|
package/package.json
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
2
|
+
"name": "@8ms/helpers",
|
|
3
|
+
"license": "UNLICENSED",
|
|
4
|
+
"version": "1.1.93",
|
|
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": "tsc",
|
|
13
|
+
"jest": "jest --watch"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"axios": "0.27.2",
|
|
17
|
+
"crypto-js": "4.1.1",
|
|
18
|
+
"date-fns": "2.29.3",
|
|
19
|
+
"date-fns-tz": "1.3.7",
|
|
20
|
+
"lodash": "4.17.21"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@aws-sdk/client-s3": "3.178.0",
|
|
24
|
+
"@aws-sdk/client-ses": "3.178.0",
|
|
25
|
+
"@aws-sdk/client-sqs": "3.178.0",
|
|
26
|
+
"@aws-sdk/client-ssm": "3.178.0",
|
|
27
|
+
"@aws-sdk/s3-request-presigner": "3.178.0",
|
|
28
|
+
"@babel/preset-env": "7.19.1",
|
|
29
|
+
"@babel/preset-flow": "7.18.6",
|
|
30
|
+
"@babel/preset-typescript": "7.18.6",
|
|
31
|
+
"@google-cloud/bigquery": "6.0.3",
|
|
32
|
+
"@google-cloud/storage": "6.5.2",
|
|
33
|
+
"@graphql-codegen/cli": "2.12.1",
|
|
34
|
+
"@graphql-codegen/typescript-graphql-request": "4.5.5",
|
|
35
|
+
"@graphql-codegen/typescript-operations": "2.5.3",
|
|
36
|
+
"@prisma/client": "4.3.1",
|
|
37
|
+
"@types/jest": "29.0.3",
|
|
38
|
+
"@types/lodash": "4.14.185",
|
|
39
|
+
"@types/node": "18.7.21",
|
|
40
|
+
"babel-jest": "29.0.3",
|
|
41
|
+
"graphql": "16.6.0",
|
|
42
|
+
"graphql-request": "5.0.0",
|
|
43
|
+
"jest": "29.0.3",
|
|
44
|
+
"node-fetch": "3.2.10",
|
|
45
|
+
"numbro": "2.3.6",
|
|
46
|
+
"prisma-query-log": "3.2.0",
|
|
47
|
+
"timezone-mock": "1.3.4",
|
|
48
|
+
"ts-node": "10.9.1",
|
|
49
|
+
"tslib": "2.4.0",
|
|
50
|
+
"typescript": "4.8.3"
|
|
51
|
+
}
|
|
52
52
|
}
|