@8ms/helpers 2.2.24 → 2.2.26

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.
Binary file
@@ -14,7 +14,7 @@ type Dataset = {
14
14
  type Table = {
15
15
  id: string;
16
16
  };
17
- export declare class GoogleBigQueryNamespace extends BaseNamespace {
17
+ export declare class GoogleBigqueryNamespace extends BaseNamespace {
18
18
  client: BigQuery;
19
19
  config: GoogleCloudConfig & {
20
20
  projectId?: string;
@@ -26,7 +26,7 @@ export declare class GoogleBigQueryNamespace extends BaseNamespace {
26
26
  */
27
27
  createDataset: (datasetId: string, options?: DatasetResource) => Promise<void>;
28
28
  /**
29
- * Check to see whether a given BigQuery dataset exists.
29
+ * Check to see whether a given Bigquery dataset exists.
30
30
  * Based off:
31
31
  * https://github.com/googleapis/nodejs-bigquery/blob/main/samples/getDataset.js
32
32
  */
@@ -1,6 +1,6 @@
1
1
  import { BaseNamespace } from "../../../_class";
2
2
  import { getConfig } from "../../server";
3
- export class GoogleBigQueryNamespace extends BaseNamespace {
3
+ export class GoogleBigqueryNamespace extends BaseNamespace {
4
4
  ensureInit = async () => {
5
5
  if (!this.client) {
6
6
  try {
@@ -26,7 +26,7 @@ export class GoogleBigQueryNamespace extends BaseNamespace {
26
26
  }
27
27
  };
28
28
  /**
29
- * Check to see whether a given BigQuery dataset exists.
29
+ * Check to see whether a given Bigquery dataset exists.
30
30
  * Based off:
31
31
  * https://github.com/googleapis/nodejs-bigquery/blob/main/samples/getDataset.js
32
32
  */
@@ -0,0 +1,6 @@
1
+ import { GoogleBigqueryNamespace } from "./GoogleBigqueryNamespace";
2
+ import type { GoogleAuthOptions } from "@google-cloud/common";
3
+ export declare const googleBigqueryClient: (key?: string, projectId?: string, config?: GoogleAuthOptions, vaultId?: string, itemId?: string) => Promise<GoogleBigqueryNamespace>;
4
+ export declare const getHandlerPath: (input: string) => string;
5
+ export { loadData } from "./loadData";
6
+ export type { QueryInput } from "./GoogleBigqueryNamespace";
@@ -1,9 +1,9 @@
1
- import { GoogleBigQueryNamespace } from "./GoogleBigQueryNamespace";
1
+ import { GoogleBigqueryNamespace } from "./GoogleBigqueryNamespace";
2
2
  import { onePasswordClient } from "../../../onePassword/server";
3
- const googleBigQueryNamespaces = new Map();
4
- export const googleBigQueryClient = async (key = "default", projectId, config, vaultId, itemId) => {
5
- if (googleBigQueryNamespaces.has(key)) {
6
- return googleBigQueryNamespaces.get(key);
3
+ const googleBigqueryNamespaces = new Map();
4
+ export const googleBigqueryClient = async (key = "default", projectId, config, vaultId, itemId) => {
5
+ if (googleBigqueryNamespaces.has(key)) {
6
+ return googleBigqueryNamespaces.get(key);
7
7
  }
8
8
  let instanceConfig;
9
9
  if (config) {
@@ -31,8 +31,8 @@ export const googleBigQueryClient = async (key = "default", projectId, config, v
31
31
  else {
32
32
  throw new Error(`Config required for namespace '${key}'`);
33
33
  }
34
- const namespace = new GoogleBigQueryNamespace(key, instanceConfig);
35
- googleBigQueryNamespaces.set(key, namespace);
34
+ const namespace = new GoogleBigqueryNamespace(key, instanceConfig);
35
+ googleBigqueryNamespaces.set(key, namespace);
36
36
  return namespace;
37
37
  };
38
38
  export const getHandlerPath = (input) => {
@@ -1,6 +1,6 @@
1
- import { GoogleBigQueryNamespace } from "./GoogleBigQueryNamespace";
1
+ import { GoogleBigqueryNamespace } from "./GoogleBigqueryNamespace";
2
2
  type LoadData = {
3
- googleBigQueryClient: GoogleBigQueryNamespace;
3
+ googleBigqueryClient: GoogleBigqueryNamespace;
4
4
  googleCloudStorageClient: any;
5
5
  file: {
6
6
  bucket: string;
@@ -15,5 +15,5 @@ type LoadData = {
15
15
  /**
16
16
  * Load data into a given table using Google Cloud Storage.
17
17
  */
18
- export declare const loadData: ({ file, googleBigQueryClient, googleCloudStorageClient, table }: LoadData) => Promise<void>;
18
+ export declare const loadData: ({ file, googleBigqueryClient, googleCloudStorageClient, table }: LoadData) => Promise<void>;
19
19
  export {};
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Load data into a given table using Google Cloud Storage.
3
3
  */
4
- export const loadData = async ({ file, googleBigQueryClient, googleCloudStorageClient, table }) => {
5
- const tableExists = await googleBigQueryClient.tableExists(table.datasetId, table.tableId);
4
+ export const loadData = async ({ file, googleBigqueryClient, googleCloudStorageClient, table }) => {
5
+ const tableExists = await googleBigqueryClient.tableExists(table.datasetId, table.tableId);
6
6
  if (tableExists) {
7
- await googleBigQueryClient.client
7
+ await googleBigqueryClient.client
8
8
  .dataset(table.datasetId)
9
9
  .table(table.tableId)
10
10
  .load(googleCloudStorageClient.client
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.2.24",
4
+ "version": "2.2.26",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -681,21 +681,21 @@
681
681
  "types": "./geo/index.d.ts",
682
682
  "default": "./geo/index.d.ts"
683
683
  },
684
- "./google/bigQuery/server": {
685
- "types": "./google/bigQuery/server/index.d.ts",
686
- "import": "./google/bigQuery/server/index.js",
687
- "require": "./google/bigQuery/server/index.js",
688
- "default": "./google/bigQuery/server/index.js"
689
- },
690
- "./google/bigQuery/server/index.js": {
691
- "types": "./google/bigQuery/server/index.d.ts",
692
- "import": "./google/bigQuery/server/index.js",
693
- "require": "./google/bigQuery/server/index.js",
694
- "default": "./google/bigQuery/server/index.js"
695
- },
696
- "./google/bigQuery/server/index.d.ts": {
697
- "types": "./google/bigQuery/server/index.d.ts",
698
- "default": "./google/bigQuery/server/index.d.ts"
684
+ "./google/bigquery/server": {
685
+ "types": "./google/bigquery/server/index.d.ts",
686
+ "import": "./google/bigquery/server/index.js",
687
+ "require": "./google/bigquery/server/index.js",
688
+ "default": "./google/bigquery/server/index.js"
689
+ },
690
+ "./google/bigquery/server/index.js": {
691
+ "types": "./google/bigquery/server/index.d.ts",
692
+ "import": "./google/bigquery/server/index.js",
693
+ "require": "./google/bigquery/server/index.js",
694
+ "default": "./google/bigquery/server/index.js"
695
+ },
696
+ "./google/bigquery/server/index.d.ts": {
697
+ "types": "./google/bigquery/server/index.d.ts",
698
+ "default": "./google/bigquery/server/index.d.ts"
699
699
  },
700
700
  "./google/server": {
701
701
  "types": "./google/server/index.d.ts",
@@ -2,4 +2,4 @@
2
2
  * Chunk a queue of promises into controlled chunks to prevent overloading.
3
3
  * https://stackoverflow.com/a/53964407
4
4
  */
5
- export declare const promiseChunks: (promises: Promise<any>[], size: number, sleepSeconds?: number) => Promise<any[]>;
5
+ export declare const promiseChunks: (promises: Promise<any>[], size: number, sleepSeconds?: number, callbackFunction?: Function) => Promise<any[]>;
@@ -4,13 +4,17 @@ import { sleep } from "./sleep";
4
4
  * Chunk a queue of promises into controlled chunks to prevent overloading.
5
5
  * https://stackoverflow.com/a/53964407
6
6
  */
7
- export const promiseChunks = async (promises, size, sleepSeconds = 0) => {
7
+ export const promiseChunks = async (promises, size, sleepSeconds = 0, callbackFunction) => {
8
8
  const batches = chunk(promises, size);
9
9
  let results = [];
10
10
  while (batches.length) {
11
11
  const batch = batches.shift();
12
12
  const result = await Promise.all(batch);
13
13
  results.push(result);
14
+ // If there is a process to do with each chunk
15
+ if (callbackFunction) {
16
+ await callbackFunction(result);
17
+ }
14
18
  await sleep(sleepSeconds);
15
19
  }
16
20
  return flatten(results);
@@ -1,6 +0,0 @@
1
- import { GoogleBigQueryNamespace } from "./GoogleBigQueryNamespace";
2
- import type { GoogleAuthOptions } from "@google-cloud/common";
3
- export declare const googleBigQueryClient: (key?: string, projectId?: string, config?: GoogleAuthOptions, vaultId?: string, itemId?: string) => Promise<GoogleBigQueryNamespace>;
4
- export declare const getHandlerPath: (input: string) => string;
5
- export { loadData } from "./loadData";
6
- export type { QueryInput } from "./GoogleBigQueryNamespace";