Skip to content

Commit

Permalink
Replace enums with POJOs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbarabash committed Feb 13, 2023
1 parent 124a394 commit b1c43c8
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .changeset/long-otters-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {makeAppEngineRequestIDMiddleware} from "./middleware/make-app-engine-req
*/
export async function addAppEngineMiddleware<TReq: $Request, TRes: $Response>(
app: $Application<TReq, TRes>,
mode: Runtime,
mode: $Values<typeof Runtime>,
logger: Logger,
): Promise<$Application<TReq, TRes>> {
const middlewareApp = express<TReq, TRes>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {GoogleCloudIntegrations} from "./types";
* These integrations help debug production services.
*/
export const setupIntegrations = async (
mode: Runtime,
mode: $Values<typeof Runtime>,
{debugAgent, profiler}: GoogleCloudIntegrations = {
debugAgent: false,
profiler: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions packages/wonder-stuff-server/src/get-logging-transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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<typeof Runtime>): Format => {
const formatters: Array<Format> = [
winston.format.splat(), // Allows for %s style substitutions
];
Expand All @@ -49,7 +45,7 @@ const getFormatters = (mode: Runtime): Format => {
* Gets the logging transport for the given mode.
*/
export const getLoggingTransport = (
mode: Runtime,
mode: $Values<typeof Runtime>,
logLevel: LogLevel,
): Transport => {
switch (mode) {
Expand Down
4 changes: 3 additions & 1 deletion packages/wonder-stuff-server/src/get-runtime-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof Runtime>,
): $Values<typeof Runtime> => {
switch (process.env.NODE_ENV) {
case "test":
return Runtime.Test;
Expand Down
19 changes: 8 additions & 11 deletions packages/wonder-stuff-server/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ export type Logger = WinstonLogger<NpmLogLevels>;
/**
* 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.
Expand All @@ -43,7 +40,7 @@ export type LoggingOptions = {
/**
* The runtime mode.
*/
mode: Runtime,
mode: $Values<typeof Runtime>,

/**
* Log only if the level of a logged entry is less than or equal to this
Expand Down Expand Up @@ -91,7 +88,7 @@ export type ServerOptions = {
/**
* What runtime mode the server is running under.
*/
+mode: Runtime,
+mode: $Values<typeof Runtime>,

/**
* Optional value in milliseconds for keepalive timeout of the server.
Expand Down

0 comments on commit b1c43c8

Please sign in to comment.