-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an assertion when updating conversations; update cleanData
- Loading branch information
1 parent
73a304f
commit bc37b5c
Showing
23 changed files
with
749 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2021 Signal Messenger, LLC | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
// Many places rely on this enum being a string. | ||
export enum Environment { | ||
Development = 'development', | ||
Production = 'production', | ||
Staging = 'staging', | ||
Test = 'test', | ||
TestLib = 'test-lib', | ||
} | ||
|
||
let environment: undefined | Environment; | ||
|
||
export function getEnvironment(): Environment { | ||
if (environment === undefined) { | ||
// This should never happen—we should always have initialized the environment by this | ||
// point. It'd be nice to log here but the logger depends on the environment and we | ||
// can't have circular dependencies. | ||
return Environment.Production; | ||
} | ||
return environment; | ||
} | ||
|
||
/** | ||
* Sets the current environment. Should be called early in a process's life, and can only | ||
* be called once. | ||
*/ | ||
export function setEnvironment(env: Environment): void { | ||
if (environment !== undefined) { | ||
throw new Error('Environment has already been set'); | ||
} | ||
environment = env; | ||
} | ||
|
||
const ENVIRONMENTS_BY_STRING = new Map<string, Environment>([ | ||
['development', Environment.Development], | ||
['production', Environment.Production], | ||
['staging', Environment.Staging], | ||
['test', Environment.Test], | ||
['test-lib', Environment.TestLib], | ||
]); | ||
export function parseEnvironment(value: unknown): Environment { | ||
if (typeof value !== 'string') { | ||
return Environment.Production; | ||
} | ||
const result = ENVIRONMENTS_BY_STRING.get(value); | ||
return result || Environment.Production; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2021 Signal Messenger, LLC | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
import { noop } from 'lodash'; | ||
import { LogLevel } from './shared'; | ||
|
||
type LogAtLevelFnType = ( | ||
level: LogLevel, | ||
...args: ReadonlyArray<unknown> | ||
) => void; | ||
|
||
let logAtLevel: LogAtLevelFnType = noop; | ||
let hasInitialized = false; | ||
|
||
type LogFn = (...args: ReadonlyArray<unknown>) => void; | ||
export const fatal: LogFn = (...args) => logAtLevel(LogLevel.Fatal, ...args); | ||
export const error: LogFn = (...args) => logAtLevel(LogLevel.Error, ...args); | ||
export const warn: LogFn = (...args) => logAtLevel(LogLevel.Warn, ...args); | ||
export const info: LogFn = (...args) => logAtLevel(LogLevel.Info, ...args); | ||
export const debug: LogFn = (...args) => logAtLevel(LogLevel.Debug, ...args); | ||
export const trace: LogFn = (...args) => logAtLevel(LogLevel.Trace, ...args); | ||
|
||
/** | ||
* Sets the low-level logging interface. Should be called early in a process's life, and | ||
* can only be called once. | ||
*/ | ||
export function setLogAtLevel(log: LogAtLevelFnType): void { | ||
if (hasInitialized) { | ||
throw new Error('Logger has already been initialized'); | ||
} | ||
logAtLevel = log; | ||
hasInitialized = true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.