Skip to content

Commit

Permalink
gaarf-js: [refactoring] more comments
Browse files Browse the repository at this point in the history
Change-Id: I178d4b44d76329b8ca79c64d1ac925184268abdd
  • Loading branch information
evil-shrike committed Sep 19, 2024
1 parent a83cf5d commit 3ab2769
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
23 changes: 23 additions & 0 deletions gcp/functions/build/src/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gcp/functions/build/src/utils.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions gcp/functions/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import {
import path from 'node:path';
import fs from 'node:fs';

/**
* Get script from request body or from a file specified in query parameters.
* @param req request object
* @param logger logger to write to
* @returns a promise that resolves to an object with `queryText` and `scriptName`
* properties
*/
export async function getScript(
req: express.Request,
logger: ILogger
Expand All @@ -35,6 +42,12 @@ export async function getScript(
return {queryText, scriptName};
}

/**
* Get Ads API configuration from request body or from a file specified in query
* parameters.
* @param req request object
* @returns a promise that resolves to an object with Ads API configuration
*/
export async function getAdsConfig(
req: express.Request
): Promise<GoogleAdsApiConfig> {
Expand Down Expand Up @@ -83,6 +96,10 @@ export async function getAdsConfig(
return adsConfig;
}

/**
* Get project id from environment variables.
* @returns a promise that resolves to a project id
*/
export async function getProject() {
const auth = new GoogleAuth({
scopes: 'https://www.googleapis.com/auth/cloud-platform',
Expand All @@ -91,6 +108,12 @@ export async function getProject() {
return projectId;
}

/**
* Split an array into chunks of a given size.
* @param array array to split
* @param max maximum size of a chunk
* @returns an array of arrays
*/
export function splitIntoChunks<T>(array: T[], max: number): T[][] {
const result = [];
for (let i = 0; i < array.length; i += max) {
Expand Down

0 comments on commit 3ab2769

Please sign in to comment.