@8ms/helpers 1.1.77 → 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.
@@ -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[projectId]) {
13
+ if (!global.googleBigQueryClient) {
14
14
  const { BigQuery } = require('@google-cloud/bigquery');
15
15
  const formattedConfig = (0, getConfig_1.default)({ parameter });
16
- global.googleBigQueryClient[projectId] = new BigQuery({
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
- projectId: string;
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: ({ projectId, query }: Query) => Promise<any>;
7
+ declare const query: ({ input }: Query) => Promise<any>;
9
8
  export default query;
@@ -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 ({ projectId, query }) => {
7
- const apiResponse = await global.googleBigQueryClient[projectId].query(query);
6
+ const query = async ({ input }) => {
7
+ const apiResponse = await global.googleBigQueryClient.query(input);
8
8
  return apiResponse;
9
9
  };
10
10
  exports.default = query;
@@ -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[projectId]) {
14
+ if (!global.googleStorageClient) {
15
15
  const { Storage } = require('@google-cloud/storage');
16
16
  const formattedConfig = (0, getConfig_1.default)({ parameter });
17
- global.googleStorageClient[projectId] = new Storage({
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, projectId }: WriteFile) => Promise<any>;
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, projectId }) => {
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[projectId].bucket(bucket)
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
- projectId: string;
23
- };
24
21
  googleConfig?: {
25
22
  parameterName: string;
26
- };
27
- googleSheets?: boolean;
28
- googleStorage?: {
29
23
  projectId: string;
30
24
  };
25
+ googleBigQuery?: boolean;
26
+ googleSheets?: boolean;
27
+ googleStorage?: boolean;
31
28
  prisma?: {
32
29
  debug?: boolean;
33
30
  };
package/initClients.js CHANGED
@@ -61,10 +61,10 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, a
61
61
  name: googleConfig.parameterName,
62
62
  });
63
63
  // BigQuery
64
- if (googleBigQuery && googleBigQuery.projectId) {
64
+ if (googleBigQuery && googleConfig.projectId) {
65
65
  (0, initClient_7.default)({
66
66
  parameter: googleParameter,
67
- projectId: googleBigQuery.projectId,
67
+ projectId: googleConfig.projectId,
68
68
  });
69
69
  }
70
70
  // Google Sheets
@@ -74,10 +74,10 @@ const initClients = async ({ athenaExpress, awsConfig, awsGlue, awsS3, awsSes, a
74
74
  });
75
75
  }
76
76
  // Google Storage
77
- if (googleStorage && googleStorage.projectId) {
77
+ if (googleStorage && googleConfig.projectId) {
78
78
  (0, initClient_9.default)({
79
79
  parameter: googleParameter,
80
- projectId: googleBigQuery.projectId,
80
+ projectId: googleConfig.projectId,
81
81
  });
82
82
  }
83
83
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.1.77",
4
+ "version": "1.1.78",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"