@8ms/helpers 1.1.75 → 1.1.78
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/IsTableExists.d.ts +10 -0
- package/google/bigQuery/IsTableExists.js +20 -0
- package/google/bigQuery/initClient.js +3 -3
- package/google/bigQuery/query.d.ts +2 -3
- package/google/bigQuery/query.js +2 -2
- package/google/getConfig.d.ts +1 -1
- package/google/getConfig.js +1 -1
- package/google/storage/initClient.js +3 -3
- package/google/storage/writeFile.d.ts +1 -2
- package/google/storage/writeFile.js +2 -2
- package/initClients.d.ts +3 -6
- package/initClients.js +10 -17
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare type IsTableExists = {
|
|
2
|
+
datasetId: string;
|
|
3
|
+
tableId: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Check to see whether a given BigQuery table exists.
|
|
7
|
+
* https://cloud.google.com/bigquery/docs/samples/bigquery-table-exists
|
|
8
|
+
*/
|
|
9
|
+
declare const isTableExists: ({ datasetId, tableId }: IsTableExists) => Promise<boolean>;
|
|
10
|
+
export default isTableExists;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Check to see whether a given BigQuery table exists.
|
|
5
|
+
* https://cloud.google.com/bigquery/docs/samples/bigquery-table-exists
|
|
6
|
+
*/
|
|
7
|
+
const isTableExists = async ({ datasetId, tableId }) => {
|
|
8
|
+
let response;
|
|
9
|
+
const dataset = global.googleBigQueryClient.dataset(datasetId);
|
|
10
|
+
try {
|
|
11
|
+
await dataset.table(tableId)
|
|
12
|
+
.get();
|
|
13
|
+
response = true;
|
|
14
|
+
}
|
|
15
|
+
catch (exception) {
|
|
16
|
+
response = false;
|
|
17
|
+
}
|
|
18
|
+
return response;
|
|
19
|
+
};
|
|
20
|
+
exports.default = isTableExists;
|
|
@@ -4,16 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const getConfig_1 = __importDefault(require("../getConfig"));
|
|
7
|
-
global.googleBigQueryClient =
|
|
7
|
+
global.googleBigQueryClient = null;
|
|
8
8
|
/**
|
|
9
9
|
* Initialise the Big Query client.
|
|
10
10
|
* It's possible to use multiple clients, so we set one up per project id.
|
|
11
11
|
*/
|
|
12
12
|
const initClient = ({ parameter, projectId }) => {
|
|
13
|
-
if (!global.googleBigQueryClient
|
|
13
|
+
if (!global.googleBigQueryClient) {
|
|
14
14
|
const { BigQuery } = require('@google-cloud/bigquery');
|
|
15
15
|
const formattedConfig = (0, getConfig_1.default)({ parameter });
|
|
16
|
-
global.googleBigQueryClient
|
|
16
|
+
global.googleBigQueryClient = new BigQuery({
|
|
17
17
|
credentials: formattedConfig,
|
|
18
18
|
projectId: projectId,
|
|
19
19
|
});
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
declare type Query = {
|
|
2
|
-
|
|
3
|
-
query: string;
|
|
2
|
+
input: string;
|
|
4
3
|
};
|
|
5
4
|
/**
|
|
6
5
|
* Build the query and return the data.
|
|
7
6
|
*/
|
|
8
|
-
declare const query: ({
|
|
7
|
+
declare const query: ({ input }: Query) => Promise<any>;
|
|
9
8
|
export default query;
|
package/google/bigQuery/query.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
/**
|
|
4
4
|
* Build the query and return the data.
|
|
5
5
|
*/
|
|
6
|
-
const query = async ({
|
|
7
|
-
const apiResponse = await global.googleBigQueryClient
|
|
6
|
+
const query = async ({ input }) => {
|
|
7
|
+
const apiResponse = await global.googleBigQueryClient.query(input);
|
|
8
8
|
return apiResponse;
|
|
9
9
|
};
|
|
10
10
|
exports.default = query;
|
package/google/getConfig.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export declare type GetConfig = {
|
|
|
16
16
|
/**
|
|
17
17
|
* Using the response from Parameter Store and format it ready to be used with Google API.
|
|
18
18
|
*/
|
|
19
|
-
declare const getConfig: (parameter: GetConfig) => Config;
|
|
19
|
+
declare const getConfig: ({ parameter }: GetConfig) => Config;
|
|
20
20
|
export default getConfig;
|
package/google/getConfig.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
/**
|
|
4
4
|
* Using the response from Parameter Store and format it ready to be used with Google API.
|
|
5
5
|
*/
|
|
6
|
-
const getConfig = (parameter) => {
|
|
6
|
+
const getConfig = ({ parameter }) => {
|
|
7
7
|
// Format the private key to be in the same format as required by Google
|
|
8
8
|
const privateKey = parameter['private_key'].replace(/\\n/g, '\n');
|
|
9
9
|
const response = {
|
|
@@ -4,17 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const getConfig_1 = __importDefault(require("../getConfig"));
|
|
7
|
-
global.googleStorageClient =
|
|
7
|
+
global.googleStorageClient = null;
|
|
8
8
|
/**
|
|
9
9
|
* Initialise the Google Sheets instance using the separate service method.
|
|
10
10
|
* https://github.com/googleapis/google-api-nodejs-client
|
|
11
11
|
* Library: @googleapis/sheets
|
|
12
12
|
*/
|
|
13
13
|
const initClient = ({ parameter, projectId }) => {
|
|
14
|
-
if (!global.googleStorageClient
|
|
14
|
+
if (!global.googleStorageClient) {
|
|
15
15
|
const { Storage } = require('@google-cloud/storage');
|
|
16
16
|
const formattedConfig = (0, getConfig_1.default)({ parameter });
|
|
17
|
-
global.googleStorageClient
|
|
17
|
+
global.googleStorageClient = new Storage({
|
|
18
18
|
credentials: formattedConfig,
|
|
19
19
|
projectId: projectId,
|
|
20
20
|
});
|
|
@@ -3,10 +3,9 @@ declare type WriteFile = {
|
|
|
3
3
|
credentials: any;
|
|
4
4
|
data: any;
|
|
5
5
|
key: string;
|
|
6
|
-
projectId: string;
|
|
7
6
|
};
|
|
8
7
|
/**
|
|
9
8
|
* Write a file to Google Cloud Storage.
|
|
10
9
|
*/
|
|
11
|
-
export declare const writeFile: ({ bucket, data, key
|
|
10
|
+
export declare const writeFile: ({ bucket, data, key }: WriteFile) => Promise<any>;
|
|
12
11
|
export default writeFile;
|
|
@@ -4,10 +4,10 @@ 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, data, key }) => {
|
|
8
8
|
const stream = require('stream');
|
|
9
9
|
const dataStream = new stream.PassThrough();
|
|
10
|
-
const googleFile = global.googleStorageClient
|
|
10
|
+
const googleFile = global.googleStorageClient.bucket(bucket)
|
|
11
11
|
.file(key);
|
|
12
12
|
dataStream.push(data);
|
|
13
13
|
dataStream.push(null);
|
package/initClients.d.ts
CHANGED
|
@@ -18,16 +18,13 @@ declare type InitClients = {
|
|
|
18
18
|
googleAds?: {
|
|
19
19
|
parameterName: string;
|
|
20
20
|
};
|
|
21
|
-
googleBigQuery?: {
|
|
22
|
-
projectIds: string | string[];
|
|
23
|
-
};
|
|
24
21
|
googleConfig?: {
|
|
25
22
|
parameterName: string;
|
|
23
|
+
projectId: string;
|
|
26
24
|
};
|
|
25
|
+
googleBigQuery?: boolean;
|
|
27
26
|
googleSheets?: boolean;
|
|
28
|
-
googleStorage?:
|
|
29
|
-
projectIds: string | string[];
|
|
30
|
-
};
|
|
27
|
+
googleStorage?: boolean;
|
|
31
28
|
prisma?: {
|
|
32
29
|
debug?: boolean;
|
|
33
30
|
};
|
package/initClients.js
CHANGED
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const getArray_1 = __importDefault(require("./array/getArray"));
|
|
7
6
|
const initClient_1 = __importDefault(require("./aws/athenaExpress/initClient"));
|
|
8
7
|
const initClient_2 = __importDefault(require("./aws/glue/initClient"));
|
|
9
8
|
const initClient_3 = __importDefault(require("./aws/s3/initClient"));
|
|
@@ -62,14 +61,11 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, a
|
|
|
62
61
|
name: googleConfig.parameterName,
|
|
63
62
|
});
|
|
64
63
|
// BigQuery
|
|
65
|
-
if (googleBigQuery &&
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
projectId: googleBigQueryProjectIds[i],
|
|
71
|
-
});
|
|
72
|
-
}
|
|
64
|
+
if (googleBigQuery && googleConfig.projectId) {
|
|
65
|
+
(0, initClient_7.default)({
|
|
66
|
+
parameter: googleParameter,
|
|
67
|
+
projectId: googleConfig.projectId,
|
|
68
|
+
});
|
|
73
69
|
}
|
|
74
70
|
// Google Sheets
|
|
75
71
|
if (googleSheets) {
|
|
@@ -78,14 +74,11 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, a
|
|
|
78
74
|
});
|
|
79
75
|
}
|
|
80
76
|
// Google Storage
|
|
81
|
-
if (googleStorage &&
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
projectId: googleStorageProjectIds[i],
|
|
87
|
-
});
|
|
88
|
-
}
|
|
77
|
+
if (googleStorage && googleConfig.projectId) {
|
|
78
|
+
(0, initClient_9.default)({
|
|
79
|
+
parameter: googleParameter,
|
|
80
|
+
projectId: googleConfig.projectId,
|
|
81
|
+
});
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
84
|
// Google Ads authentication using SSM Parameter
|