Skip to content

Commit

Permalink
convert more functions to REST
Browse files Browse the repository at this point in the history
  • Loading branch information
avermeil committed Feb 13, 2024
1 parent eaa89ee commit abe39ff
Show file tree
Hide file tree
Showing 9 changed files with 8,484 additions and 5,292 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"license": "MIT",
"dependencies": {
"@isaacs/ttlcache": "^1.2.2",
"@types/stream-json": "^1.7.7",
"axios": "^1.6.7",
"decamelize": "^5.0.0",
"google-ads-node": "^12.0.2",
"google-auth-library": "^7.1.0",
"google-gax": "^4.0.3",
Expand All @@ -31,6 +29,7 @@
"devDependencies": {
"@types/jest": "^29.0.1",
"@types/pluralize": "^0.0.29",
"@types/stream-json": "^1.7.7",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"@typescript-eslint/parser": "^4.8.2",
"eslint": "^7.14.0",
Expand Down
39 changes: 38 additions & 1 deletion scripts/enums.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "fs";
import { internalEnums, VERSION } from "../src/protos/index";
import { internalEnums, VERSION, errors } from "../src/protos/index";
import { FILES } from "./path";

export async function compileEnums(): Promise<void> {
Expand All @@ -10,6 +10,7 @@ export async function compileEnums(): Promise<void> {
stream.write("\n// eslint-disable-next-line\n");
stream.write("export namespace enums {\n");

// Add all regular enums
for (const [fullName, def] of Object.entries(internalEnums)) {
const [name] = fullName.split("Enum");
const values = Object.entries(def).find(
Expand Down Expand Up @@ -37,6 +38,42 @@ export async function compileEnums(): Promise<void> {
stream.write(`\n${enumStr}\n`);
}

// Add all error enums
for (const [fullName, def] of Object.entries(errors)) {
const [name] = fullName.split("Enum");
const values = Object.entries(def).find(
([, val]) => typeof val !== "function" // Get the object field which isn't a function, which happens to be the enum values
)?.[1];
console.log(name, values);
console.log(def);

if (!values) {
console.warn("Could not find values for enum " + fullName);
continue;
}

if (!name) {
console.warn("Could not find name for enum " + fullName);
continue;
}

const pairs = Object.keys(values).map((key) => {
const protoVal = values[key];
return `${key} = ${protoVal}, // ${key}`;
});
const enumStr = `export enum ${name} {
${pairs.join("\n")}
}`;

const docsLink = buildEnumLink(VERSION, fullName, name);

stream.write(`\n/**
* @name ${fullName}.${name}
* @link ${docsLink}
*/`);
stream.write(`\n${enumStr}\n`);
}

stream.write("}\n");
stream.end();

Expand Down
2 changes: 1 addition & 1 deletion scripts/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export async function compileFields(): Promise<void> {

stream.write(`}`);

stream.write(`\n\n/* -- Field types (used in parsing) -- */`);
stream.write(`\n\n/* -- Field types (used in REST parsing) -- */`);
stream.write(`\nexport const fieldDataTypes = new Map([ `);

for (const field of fields) {
Expand Down
Loading

0 comments on commit abe39ff

Please sign in to comment.