Skip to content

Commit

Permalink
fix for enums not in mega
Browse files Browse the repository at this point in the history
  • Loading branch information
avermeil committed Mar 19, 2024
1 parent 04620df commit 639d1b0
Show file tree
Hide file tree
Showing 2 changed files with 31,287 additions and 30,729 deletions.
13 changes: 11 additions & 2 deletions src/parserRest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import mapObject from "map-obj";
import { parse } from "circ-json";

import { toSnakeCase } from "./utils";
import { fieldDataTypes as fieldDataTypesString } from "./protos/autogen/fields";
import {
fieldDataTypes as fieldDataTypesString,
fields,
} from "./protos/autogen/fields";
import { enums } from "./protos/autogen/enums";

const fieldDataTypes = parse(fieldDataTypesString);

Expand Down Expand Up @@ -70,6 +74,10 @@ const cachedValueParser = (
newValue = megaDataType[value];
} else if (megaDataType === "INT64") {
newValue = Number(value);
} else if (megaDataType === "ENUM") {
// Some enums aren't embedded in megaDataType, so we need this fallback.
// @ts-expect-error typescript doesn't like accessing items in a namespace with a string
newValue = enums[fields.enumFields[fullPath]][value]; // e.g. enums['CampaignStatus'][ENABLED] = "2"
}

return newValue;
Expand All @@ -88,9 +96,10 @@ const getTypeFromPath = (path: string) => {
return t;
};

// Copied from youmightnotneed.com
const get = (obj: any, path: string) => {
// If path is not defined or it has false value
if (!path) return undefined;

// Check if path is string or array. Regex : ensure that we do not have '.' and brackets.
// Regex explained: https://regexr.com/58j0k
const pathArray = path.match(/([^[.\]])+/g);
Expand Down
Loading

0 comments on commit 639d1b0

Please sign in to comment.