@8ms/helpers 1.3.9 → 1.3.10

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.
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const IsTableExists_1 = __importDefault(require("./IsTableExists"));
7
7
  const getClient_1 = __importDefault(require("./getClient"));
8
+ const getClient_2 = __importDefault(require("../storage/getClient"));
8
9
  /**
9
10
  * Load data into a given table.
10
11
  */
@@ -18,7 +19,7 @@ const loadData = async ({ file, table }) => {
18
19
  let bigqueryClient = (0, getClient_1.default)({
19
20
  projectId: table.projectId
20
21
  });
21
- let storageClient = (0, getClient_1.default)({
22
+ let storageClient = (0, getClient_2.default)({
22
23
  projectId: file.projectId
23
24
  });
24
25
  await bigqueryClient
@@ -0,0 +1,8 @@
1
+ type GetClient = {
2
+ projectId?: string;
3
+ };
4
+ /**
5
+ * Create a new client if the project id differs from the global.
6
+ */
7
+ declare const getClient: ({ projectId }: GetClient) => any;
8
+ export default getClient;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Create a new client if the project id differs from the global.
5
+ */
6
+ const getClient = ({ projectId }) => {
7
+ let client = global.googleStorageClient;
8
+ if (undefined !== projectId && projectId !== global.googleStorageDefault.projectId) {
9
+ const { Storage } = require('@google-cloud/storage');
10
+ client = new Storage({
11
+ credentials: global.googleStorageDefault.credentials,
12
+ location: "europe-west2",
13
+ projectId: projectId,
14
+ });
15
+ }
16
+ return client;
17
+ };
18
+ exports.default = getClient;
@@ -4,6 +4,10 @@ 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.googleStorageDefault = {
8
+ credentials: null,
9
+ projectId: null,
10
+ };
7
11
  global.googleStorageClient = null;
8
12
  /**
9
13
  * Initialise the Google Sheets instance using the separate service method.
@@ -14,6 +18,8 @@ const initClient = ({ parameter, projectId }) => {
14
18
  if (!global.googleStorageClient) {
15
19
  const { Storage } = require('@google-cloud/storage');
16
20
  const formattedConfig = (0, getConfig_1.default)({ parameter });
21
+ global.googleStorageDefault.credentials = formattedConfig;
22
+ global.googleStorageDefault.projectId = projectId;
17
23
  global.googleStorageClient = new Storage({
18
24
  credentials: formattedConfig,
19
25
  projectId: projectId,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.3.9",
4
+ "version": "1.3.10",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"