Files
Tom Moor fe4c2fb7d6 chore: Add eslint rule for no-shadow (#6658)
* chore: Add eslint rule for no-shadow

* fix
2024-03-09 13:04:27 -08:00

38 lines
947 B
TypeScript

import "reflect-metadata";
import isUndefined from "lodash/isUndefined";
import type { Environment } from "@server/env";
const key = Symbol("env:public");
/**
* This decorator on an environment variable makes that variable available client-side
*/
export function Public(target: any, propertyKey: string) {
const publicVars: string[] = Reflect.getMetadata(key, target);
if (!publicVars) {
return Reflect.defineMetadata(key, [propertyKey], target);
}
publicVars.push(propertyKey);
}
export class PublicEnvironmentRegister {
private static publicEnv: Record<string, any> = {};
static registerEnv(env: Environment) {
process.nextTick(() => {
const vars: string[] = Reflect.getMetadata(key, env) ?? [];
vars.forEach((key: string) => {
if (isUndefined(this.publicEnv[key])) {
this.publicEnv[key] = env[key];
}
});
});
}
static getEnv() {
return this.publicEnv;
}
}