From b1c43c8493290cb8d2b97ecb89231265ab80b843 Mon Sep 17 00:00:00 2001 From: Kevin Barabash Date: Mon, 13 Feb 2023 16:58:17 -0500 Subject: [PATCH] Replace enums with POJOs --- .changeset/long-otters-push.md | 2 ++ .../src/add-app-engine-middleware.js | 2 +- .../src/setup-integrations.js | 2 +- .../src/__tests__/start-server.test.js | 2 +- .../src/get-logging-transport.js | 8 ++------ .../src/get-runtime-mode.js | 4 +++- packages/wonder-stuff-server/src/types.js | 19 ++++++++----------- 7 files changed, 18 insertions(+), 21 deletions(-) create mode 100644 .changeset/long-otters-push.md diff --git a/.changeset/long-otters-push.md b/.changeset/long-otters-push.md new file mode 100644 index 00000000..a845151c --- /dev/null +++ b/.changeset/long-otters-push.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/wonder-stuff-server-google/src/add-app-engine-middleware.js b/packages/wonder-stuff-server-google/src/add-app-engine-middleware.js index 363a7e78..83047b68 100644 --- a/packages/wonder-stuff-server-google/src/add-app-engine-middleware.js +++ b/packages/wonder-stuff-server-google/src/add-app-engine-middleware.js @@ -11,7 +11,7 @@ import {makeAppEngineRequestIDMiddleware} from "./middleware/make-app-engine-req */ export async function addAppEngineMiddleware( app: $Application, - mode: Runtime, + mode: $Values, logger: Logger, ): Promise<$Application> { const middlewareApp = express(); diff --git a/packages/wonder-stuff-server-google/src/setup-integrations.js b/packages/wonder-stuff-server-google/src/setup-integrations.js index 1ce64a44..470b19d9 100644 --- a/packages/wonder-stuff-server-google/src/setup-integrations.js +++ b/packages/wonder-stuff-server-google/src/setup-integrations.js @@ -8,7 +8,7 @@ import type {GoogleCloudIntegrations} from "./types"; * These integrations help debug production services. */ export const setupIntegrations = async ( - mode: Runtime, + mode: $Values, {debugAgent, profiler}: GoogleCloudIntegrations = { debugAgent: false, profiler: false, diff --git a/packages/wonder-stuff-server/src/__tests__/start-server.test.js b/packages/wonder-stuff-server/src/__tests__/start-server.test.js index e8d31a0a..91d908d8 100644 --- a/packages/wonder-stuff-server/src/__tests__/start-server.test.js +++ b/packages/wonder-stuff-server/src/__tests__/start-server.test.js @@ -48,7 +48,7 @@ describe("#start-server", () => { expect(setRootLoggerSpy).toHaveBeenCalledWith(logger); }); - it.each(Array.from(Runtime.members()))( + it.each(Array.from(Object.values(Runtime)))( "should import heapdumps if allowHeapDumps is true", async (mode) => { // Arrange diff --git a/packages/wonder-stuff-server/src/get-logging-transport.js b/packages/wonder-stuff-server/src/get-logging-transport.js index 7403cefd..455d19f0 100644 --- a/packages/wonder-stuff-server/src/get-logging-transport.js +++ b/packages/wonder-stuff-server/src/get-logging-transport.js @@ -3,10 +3,6 @@ import stream from "stream"; import winston from "winston"; import type {Transport, Format} from "winston"; -// TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they -// have fixed: -// https://github.com/import-js/eslint-plugin-import/issues/2073 -// eslint-disable-next-line import/named import {Runtime} from "./types"; import type {LogLevel, Info} from "./types"; @@ -28,7 +24,7 @@ const devFormatter = ({level, message, ...metadata}: Info): string => { /** * Build the formatters to give us some nice dev output. */ -const getFormatters = (mode: Runtime): Format => { +const getFormatters = (mode: $Values): Format => { const formatters: Array = [ winston.format.splat(), // Allows for %s style substitutions ]; @@ -49,7 +45,7 @@ const getFormatters = (mode: Runtime): Format => { * Gets the logging transport for the given mode. */ export const getLoggingTransport = ( - mode: Runtime, + mode: $Values, logLevel: LogLevel, ): Transport => { switch (mode) { diff --git a/packages/wonder-stuff-server/src/get-runtime-mode.js b/packages/wonder-stuff-server/src/get-runtime-mode.js index 0edafdb4..768c346e 100644 --- a/packages/wonder-stuff-server/src/get-runtime-mode.js +++ b/packages/wonder-stuff-server/src/get-runtime-mode.js @@ -13,7 +13,9 @@ import {Runtime} from "./types"; * * @returns {Runtime} The runtime mode of production, development, or test. */ -export const getRuntimeMode = (defaultMode: Runtime): Runtime => { +export const getRuntimeMode = ( + defaultMode: $Values, +): $Values => { switch (process.env.NODE_ENV) { case "test": return Runtime.Test; diff --git a/packages/wonder-stuff-server/src/types.js b/packages/wonder-stuff-server/src/types.js index 8403a6d9..ad117f19 100644 --- a/packages/wonder-stuff-server/src/types.js +++ b/packages/wonder-stuff-server/src/types.js @@ -26,15 +26,12 @@ export type Logger = WinstonLogger; /** * The runtime modes that a gateway can run under. */ -export enum Runtime { - // TODO(somewhatabstract, FEI-4172): Update eslint-plugin-flowtype when - // they've fixed https://github.com/gajus/eslint-plugin-flowtype/issues/502 - /* eslint-disable no-undef */ - Production = "production", - Development = "development", - Test = "test", - /* eslint-enable no-undef */ -} +// TODO(FEI-5001): Replace with TS enum +export const Runtime = { + Production: ("production": "production"), + Development: ("development": "development"), + Test: ("test": "test"), +}; /** * Options to configure logging. @@ -43,7 +40,7 @@ export type LoggingOptions = { /** * The runtime mode. */ - mode: Runtime, + mode: $Values, /** * Log only if the level of a logged entry is less than or equal to this @@ -91,7 +88,7 @@ export type ServerOptions = { /** * What runtime mode the server is running under. */ - +mode: Runtime, + +mode: $Values, /** * Optional value in milliseconds for keepalive timeout of the server.