@8ms/helpers 2.4.22 → 2.4.23

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.
@@ -4,6 +4,11 @@ const require__class_BaseNamespace = require("../../../_class/BaseNamespace.cjs"
4
4
  const require_googleCloud_server_googleCloud = require("../../server/googleCloud.cjs");
5
5
  //#region src/googleCloud/bigquery/server/GoogleCloudBigqueryNamespace.ts
6
6
  var GoogleCloudBigqueryNamespace = class extends require__class_BaseNamespace.BaseNamespace {
7
+ region;
8
+ constructor(key, config, region) {
9
+ super(key, config);
10
+ this.region = region;
11
+ }
7
12
  ensureInit = async () => {
8
13
  if (!this.client) try {
9
14
  const { BigQuery } = await import("@google-cloud/bigquery");
@@ -17,20 +22,25 @@ var GoogleCloudBigqueryNamespace = class extends require__class_BaseNamespace.Ba
17
22
  * Create a Dataset if it doesn't already exist.
18
23
  * Returns table instance.
19
24
  */
20
- createDataset = async (datasetId, options = {}) => {
25
+ createDataset = async (datasetId, options = {}, region) => {
21
26
  await this.ensureInit();
22
- if (!await this.datasetExists(datasetId)) await this.client.createDataset(datasetId);
27
+ const resolvedRegion = region ?? this.region;
28
+ if (!await this.datasetExists(datasetId, resolvedRegion)) await this.client.createDataset(datasetId, {
29
+ ...options,
30
+ ...resolvedRegion ? { location: resolvedRegion } : {}
31
+ });
23
32
  };
24
33
  /**
25
34
  * Check to see whether a given Bigquery dataset exists.
26
35
  * Based off:
27
36
  * https://github.com/googleapis/nodejs-bigquery/blob/main/samples/getDataset.js
28
37
  */
29
- datasetExists = async (datasetId) => {
38
+ datasetExists = async (datasetId, region) => {
30
39
  await this.ensureInit();
40
+ const resolvedRegion = region ?? this.region;
31
41
  let response;
32
42
  try {
33
- await this.client.dataset(datasetId).get();
43
+ await this.client.dataset(datasetId, { location: resolvedRegion }).get();
34
44
  response = true;
35
45
  } catch (exception) {
36
46
  response = false;
@@ -54,10 +64,13 @@ var GoogleCloudBigqueryNamespace = class extends require__class_BaseNamespace.Ba
54
64
  query = async (props) => {
55
65
  await this.ensureInit();
56
66
  let options = { query: "" };
57
- if ("string" === typeof props) options.query = props;
58
- else if (require_lodash_isObject.isObject(props)) {
67
+ if ("string" === typeof props) {
68
+ options.query = props;
69
+ if (this.region) options.location = this.region;
70
+ } else if (require_lodash_isObject.isObject(props)) {
59
71
  options.query = props.query;
60
- if (props?.location) options["location"] = props.location;
72
+ const resolvedLocation = props.location ?? this.region;
73
+ if (resolvedLocation) options.location = resolvedLocation;
61
74
  if (props?.params) options["params"] = props.params;
62
75
  }
63
76
  return await this.client.query(options);
@@ -74,20 +87,20 @@ var GoogleCloudBigqueryNamespace = class extends require__class_BaseNamespace.Ba
74
87
  * Check to see whether a given BigQuery table exists.
75
88
  * https://cloud.google.com/bigquery/docs/samples/bigquery-table-exists
76
89
  */
77
- tableExists = async (datasetId, tableId) => {
90
+ tableExists = async (datasetId, tableId, region) => {
78
91
  await this.ensureInit();
79
92
  let response = false;
80
- const tables = await this.getTables(datasetId);
93
+ const tables = await this.getTables(datasetId, region ?? this.region);
81
94
  for (let i = 0; i < tables.length; i++) if (tables[i].id === tableId) {
82
95
  response = true;
83
96
  break;
84
97
  }
85
98
  return response;
86
99
  };
87
- getTables = async (datasetId) => {
100
+ getTables = async (datasetId, region) => {
88
101
  await this.ensureInit();
89
102
  let response = [];
90
- const tables = await this.client.dataset(datasetId).getTables();
103
+ const tables = await this.client.dataset(datasetId, { location: region ?? this.region }).getTables();
91
104
  if (tables?.[0]) for (let i = 0; i < tables[0].length; i++) response.push({ id: tables[0][i].id });
92
105
  return response;
93
106
  };
@@ -21,18 +21,22 @@ declare class GoogleCloudBigqueryNamespace extends BaseNamespace {
21
21
  config: GoogleCloudConfig & {
22
22
  projectId?: string;
23
23
  };
24
+ region?: string;
25
+ constructor(key: string, config: GoogleCloudConfig & {
26
+ projectId?: string;
27
+ }, region?: string);
24
28
  ensureInit: () => Promise<void>;
25
29
  /**
26
30
  * Create a Dataset if it doesn't already exist.
27
31
  * Returns table instance.
28
32
  */
29
- createDataset: (datasetId: string, options?: DatasetResource) => Promise<void>;
33
+ createDataset: (datasetId: string, options?: DatasetResource, region?: string) => Promise<void>;
30
34
  /**
31
35
  * Check to see whether a given Bigquery dataset exists.
32
36
  * Based off:
33
37
  * https://github.com/googleapis/nodejs-bigquery/blob/main/samples/getDataset.js
34
38
  */
35
- datasetExists: (datasetId: string) => Promise<boolean>;
39
+ datasetExists: (datasetId: string, region?: string) => Promise<boolean>;
36
40
  /**
37
41
  * Retrieve all the Datasets
38
42
  */
@@ -46,8 +50,8 @@ declare class GoogleCloudBigqueryNamespace extends BaseNamespace {
46
50
  * Check to see whether a given BigQuery table exists.
47
51
  * https://cloud.google.com/bigquery/docs/samples/bigquery-table-exists
48
52
  */
49
- tableExists: (datasetId: string, tableId: string) => Promise<boolean>;
50
- getTables: (datasetId: string) => Promise<Table[]>;
53
+ tableExists: (datasetId: string, tableId: string, region?: string) => Promise<boolean>;
54
+ getTables: (datasetId: string, region?: string) => Promise<Table[]>;
51
55
  }
52
56
  //#endregion
53
57
  export { GoogleCloudBigqueryNamespace, QueryInput };
@@ -21,18 +21,22 @@ declare class GoogleCloudBigqueryNamespace extends BaseNamespace {
21
21
  config: GoogleCloudConfig & {
22
22
  projectId?: string;
23
23
  };
24
+ region?: string;
25
+ constructor(key: string, config: GoogleCloudConfig & {
26
+ projectId?: string;
27
+ }, region?: string);
24
28
  ensureInit: () => Promise<void>;
25
29
  /**
26
30
  * Create a Dataset if it doesn't already exist.
27
31
  * Returns table instance.
28
32
  */
29
- createDataset: (datasetId: string, options?: DatasetResource) => Promise<void>;
33
+ createDataset: (datasetId: string, options?: DatasetResource, region?: string) => Promise<void>;
30
34
  /**
31
35
  * Check to see whether a given Bigquery dataset exists.
32
36
  * Based off:
33
37
  * https://github.com/googleapis/nodejs-bigquery/blob/main/samples/getDataset.js
34
38
  */
35
- datasetExists: (datasetId: string) => Promise<boolean>;
39
+ datasetExists: (datasetId: string, region?: string) => Promise<boolean>;
36
40
  /**
37
41
  * Retrieve all the Datasets
38
42
  */
@@ -46,8 +50,8 @@ declare class GoogleCloudBigqueryNamespace extends BaseNamespace {
46
50
  * Check to see whether a given BigQuery table exists.
47
51
  * https://cloud.google.com/bigquery/docs/samples/bigquery-table-exists
48
52
  */
49
- tableExists: (datasetId: string, tableId: string) => Promise<boolean>;
50
- getTables: (datasetId: string) => Promise<Table[]>;
53
+ tableExists: (datasetId: string, tableId: string, region?: string) => Promise<boolean>;
54
+ getTables: (datasetId: string, region?: string) => Promise<Table[]>;
51
55
  }
52
56
  //#endregion
53
57
  export { GoogleCloudBigqueryNamespace, QueryInput };
@@ -3,6 +3,11 @@ import { BaseNamespace } from "../../../_class/BaseNamespace.mjs";
3
3
  import { getConfig } from "../../server/googleCloud.mjs";
4
4
  //#region src/googleCloud/bigquery/server/GoogleCloudBigqueryNamespace.ts
5
5
  var GoogleCloudBigqueryNamespace = class extends BaseNamespace {
6
+ region;
7
+ constructor(key, config, region) {
8
+ super(key, config);
9
+ this.region = region;
10
+ }
6
11
  ensureInit = async () => {
7
12
  if (!this.client) try {
8
13
  const { BigQuery } = await import("@google-cloud/bigquery");
@@ -16,20 +21,25 @@ var GoogleCloudBigqueryNamespace = class extends BaseNamespace {
16
21
  * Create a Dataset if it doesn't already exist.
17
22
  * Returns table instance.
18
23
  */
19
- createDataset = async (datasetId, options = {}) => {
24
+ createDataset = async (datasetId, options = {}, region) => {
20
25
  await this.ensureInit();
21
- if (!await this.datasetExists(datasetId)) await this.client.createDataset(datasetId);
26
+ const resolvedRegion = region ?? this.region;
27
+ if (!await this.datasetExists(datasetId, resolvedRegion)) await this.client.createDataset(datasetId, {
28
+ ...options,
29
+ ...resolvedRegion ? { location: resolvedRegion } : {}
30
+ });
22
31
  };
23
32
  /**
24
33
  * Check to see whether a given Bigquery dataset exists.
25
34
  * Based off:
26
35
  * https://github.com/googleapis/nodejs-bigquery/blob/main/samples/getDataset.js
27
36
  */
28
- datasetExists = async (datasetId) => {
37
+ datasetExists = async (datasetId, region) => {
29
38
  await this.ensureInit();
39
+ const resolvedRegion = region ?? this.region;
30
40
  let response;
31
41
  try {
32
- await this.client.dataset(datasetId).get();
42
+ await this.client.dataset(datasetId, { location: resolvedRegion }).get();
33
43
  response = true;
34
44
  } catch (exception) {
35
45
  response = false;
@@ -53,10 +63,13 @@ var GoogleCloudBigqueryNamespace = class extends BaseNamespace {
53
63
  query = async (props) => {
54
64
  await this.ensureInit();
55
65
  let options = { query: "" };
56
- if ("string" === typeof props) options.query = props;
57
- else if (isObject(props)) {
66
+ if ("string" === typeof props) {
67
+ options.query = props;
68
+ if (this.region) options.location = this.region;
69
+ } else if (isObject(props)) {
58
70
  options.query = props.query;
59
- if (props?.location) options["location"] = props.location;
71
+ const resolvedLocation = props.location ?? this.region;
72
+ if (resolvedLocation) options.location = resolvedLocation;
60
73
  if (props?.params) options["params"] = props.params;
61
74
  }
62
75
  return await this.client.query(options);
@@ -73,20 +86,20 @@ var GoogleCloudBigqueryNamespace = class extends BaseNamespace {
73
86
  * Check to see whether a given BigQuery table exists.
74
87
  * https://cloud.google.com/bigquery/docs/samples/bigquery-table-exists
75
88
  */
76
- tableExists = async (datasetId, tableId) => {
89
+ tableExists = async (datasetId, tableId, region) => {
77
90
  await this.ensureInit();
78
91
  let response = false;
79
- const tables = await this.getTables(datasetId);
92
+ const tables = await this.getTables(datasetId, region ?? this.region);
80
93
  for (let i = 0; i < tables.length; i++) if (tables[i].id === tableId) {
81
94
  response = true;
82
95
  break;
83
96
  }
84
97
  return response;
85
98
  };
86
- getTables = async (datasetId) => {
99
+ getTables = async (datasetId, region) => {
87
100
  await this.ensureInit();
88
101
  let response = [];
89
- const tables = await this.client.dataset(datasetId).getTables();
102
+ const tables = await this.client.dataset(datasetId, { location: region ?? this.region }).getTables();
90
103
  if (tables?.[0]) for (let i = 0; i < tables[0].length; i++) response.push({ id: tables[0][i].id });
91
104
  return response;
92
105
  };
@@ -4,7 +4,7 @@ require("../../../onePassword/server/index.cjs");
4
4
  const require_googleCloud_bigquery_server_GoogleCloudBigqueryNamespace = require("./GoogleCloudBigqueryNamespace.cjs");
5
5
  //#region src/googleCloud/bigquery/server/googleCloudBigquery.ts
6
6
  const googleCloudBigqueryNamespaces = /* @__PURE__ */ new Map();
7
- const googleCloudBigqueryClient = async (key = "default", projectId, config, vaultId, itemId) => {
7
+ const googleCloudBigqueryClient = async (key = "default", projectId, config, vaultId, itemId, region) => {
8
8
  if (googleCloudBigqueryNamespaces.has(key)) return googleCloudBigqueryNamespaces.get(key);
9
9
  let instanceConfig;
10
10
  if (config) instanceConfig = {
@@ -20,7 +20,7 @@ const googleCloudBigqueryClient = async (key = "default", projectId, config, vau
20
20
  projectId
21
21
  };
22
22
  else throw new Error(`Config required for namespace '${key}'`);
23
- const namespace = new require_googleCloud_bigquery_server_GoogleCloudBigqueryNamespace.GoogleCloudBigqueryNamespace(key, instanceConfig);
23
+ const namespace = new require_googleCloud_bigquery_server_GoogleCloudBigqueryNamespace.GoogleCloudBigqueryNamespace(key, instanceConfig, region);
24
24
  googleCloudBigqueryNamespaces.set(key, namespace);
25
25
  return namespace;
26
26
  };
@@ -2,7 +2,7 @@ import { GoogleCloudBigqueryNamespace } from "./GoogleCloudBigqueryNamespace.cjs
2
2
  import { GoogleAuthOptions } from "@google-cloud/common";
3
3
 
4
4
  //#region src/googleCloud/bigquery/server/googleCloudBigquery.d.ts
5
- declare const googleCloudBigqueryClient: (key?: string, projectId?: string, config?: GoogleAuthOptions, vaultId?: string, itemId?: string) => Promise<GoogleCloudBigqueryNamespace>;
5
+ declare const googleCloudBigqueryClient: (key?: string, projectId?: string, config?: GoogleAuthOptions, vaultId?: string, itemId?: string, region?: string) => Promise<GoogleCloudBigqueryNamespace>;
6
6
  declare const getHandlerPath: (input: string) => string;
7
7
  //#endregion
8
8
  export { type GoogleCloudBigqueryNamespace, getHandlerPath, googleCloudBigqueryClient };
@@ -2,7 +2,7 @@ import { GoogleCloudBigqueryNamespace } from "./GoogleCloudBigqueryNamespace.mjs
2
2
  import { GoogleAuthOptions } from "@google-cloud/common";
3
3
 
4
4
  //#region src/googleCloud/bigquery/server/googleCloudBigquery.d.ts
5
- declare const googleCloudBigqueryClient: (key?: string, projectId?: string, config?: GoogleAuthOptions, vaultId?: string, itemId?: string) => Promise<GoogleCloudBigqueryNamespace>;
5
+ declare const googleCloudBigqueryClient: (key?: string, projectId?: string, config?: GoogleAuthOptions, vaultId?: string, itemId?: string, region?: string) => Promise<GoogleCloudBigqueryNamespace>;
6
6
  declare const getHandlerPath: (input: string) => string;
7
7
  //#endregion
8
8
  export { type GoogleCloudBigqueryNamespace, getHandlerPath, googleCloudBigqueryClient };
@@ -3,7 +3,7 @@ import "../../../onePassword/server/index.mjs";
3
3
  import { GoogleCloudBigqueryNamespace } from "./GoogleCloudBigqueryNamespace.mjs";
4
4
  //#region src/googleCloud/bigquery/server/googleCloudBigquery.ts
5
5
  const googleCloudBigqueryNamespaces = /* @__PURE__ */ new Map();
6
- const googleCloudBigqueryClient = async (key = "default", projectId, config, vaultId, itemId) => {
6
+ const googleCloudBigqueryClient = async (key = "default", projectId, config, vaultId, itemId, region) => {
7
7
  if (googleCloudBigqueryNamespaces.has(key)) return googleCloudBigqueryNamespaces.get(key);
8
8
  let instanceConfig;
9
9
  if (config) instanceConfig = {
@@ -19,7 +19,7 @@ const googleCloudBigqueryClient = async (key = "default", projectId, config, vau
19
19
  projectId
20
20
  };
21
21
  else throw new Error(`Config required for namespace '${key}'`);
22
- const namespace = new GoogleCloudBigqueryNamespace(key, instanceConfig);
22
+ const namespace = new GoogleCloudBigqueryNamespace(key, instanceConfig, region);
23
23
  googleCloudBigqueryNamespaces.set(key, namespace);
24
24
  return namespace;
25
25
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.4.22",
4
+ "version": "2.4.23",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"