@8ms/helpers 1.10.0 → 1.11.0

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.
@@ -1,8 +1,9 @@
1
1
  type GetClient = {
2
+ location?: string;
2
3
  projectId?: string;
3
4
  };
4
5
  /**
5
6
  * Create a new client if the project id differs from the global.
6
7
  */
7
- declare const getClient: ({ projectId }: GetClient) => any;
8
+ declare const getClient: (props: GetClient) => any;
8
9
  export default getClient;
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /**
4
4
  * Create a new client if the project id differs from the global.
5
5
  */
6
- const getClient = ({ projectId }) => {
6
+ const getClient = (props) => {
7
7
  let client = global.googleBigQueryClient;
8
- if (undefined !== projectId && projectId !== global.googleBigQueryDefaultProjectId) {
8
+ if (props?.projectId && props?.projectId !== global.googleBigQueryDefaultProjectId) {
9
9
  const { BigQuery } = require('@google-cloud/bigquery');
10
10
  client = new BigQuery({
11
11
  credentials: global.googleBigQueryDefault.credentials,
12
- location: "europe-west2",
13
- projectId: projectId,
12
+ location: props?.location || "europe-west2",
13
+ projectId: props?.projectId,
14
14
  });
15
15
  }
16
16
  return client;
@@ -0,0 +1,12 @@
1
+ type GetTables = {
2
+ datasetId?: string;
3
+ projectId?: string;
4
+ };
5
+ type Tables = {
6
+ id: string;
7
+ };
8
+ /**
9
+ * Retrieve all the Tables from a given Project/Dataset.
10
+ */
11
+ declare const getTables: (props: GetTables) => Promise<Tables[]>;
12
+ export default getTables;
@@ -0,0 +1,25 @@
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 getClient_1 = __importDefault(require("./getClient"));
7
+ /**
8
+ * Retrieve all the Tables from a given Project/Dataset.
9
+ */
10
+ const getTables = async (props) => {
11
+ let response = [];
12
+ const client = (0, getClient_1.default)({
13
+ projectId: props.projectId,
14
+ });
15
+ const tables = await client.dataset(props.datasetId).getTables();
16
+ if (tables?.[0]) {
17
+ for (let i = 0; i < tables[0].length; i++) {
18
+ response.push({
19
+ id: tables[0][i].id,
20
+ });
21
+ }
22
+ }
23
+ return response;
24
+ };
25
+ exports.default = getTables;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.10.0",
4
+ "version": "1.11.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"