1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.applyDefaultMiddleware = exports.accessorMiddleware = exports.strictProxyMiddleware = void 0;
|
4 | var strictProxyMiddleware = function (envObj, rawEnv, options) {
|
5 | if (options === void 0) { options = {}; }
|
6 | var _a = options.extraInspectables, extraInspectables = _a === void 0 ? [] : _a;
|
7 | var inspectables = [
|
8 | 'length',
|
9 | 'inspect',
|
10 | 'hasOwnProperty',
|
11 | 'toJSON',
|
12 | Symbol.toStringTag,
|
13 | Symbol.iterator,
|
14 |
|
15 | 'asymmetricMatch',
|
16 | 'nodeType',
|
17 |
|
18 | '$$typeof',
|
19 |
|
20 | 'then',
|
21 |
|
22 | '__esModule',
|
23 | ];
|
24 | var inspectSymbolStrings = ['Symbol(util.inspect.custom)', 'Symbol(nodejs.util.inspect.custom)'];
|
25 | return new Proxy(envObj, {
|
26 | get: function (target, name) {
|
27 | var _a;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | if (inspectables.includes(name) ||
|
33 | inspectSymbolStrings.includes(name.toString()) ||
|
34 | extraInspectables.includes(name)) {
|
35 |
|
36 | return target[name];
|
37 | }
|
38 | var varExists = target.hasOwnProperty(name);
|
39 | if (!varExists) {
|
40 | if (typeof rawEnv === 'object' && ((_a = rawEnv === null || rawEnv === void 0 ? void 0 : rawEnv.hasOwnProperty) === null || _a === void 0 ? void 0 : _a.call(rawEnv, name))) {
|
41 | throw new ReferenceError("[envalid] Env var ".concat(name, " was accessed but not validated. This var is set in the environment; please add an envalid validator for it."));
|
42 | }
|
43 | throw new ReferenceError("[envalid] Env var not found: ".concat(name));
|
44 | }
|
45 | return target[name];
|
46 | },
|
47 | set: function (_target, name) {
|
48 | throw new TypeError("[envalid] Attempt to mutate environment value: ".concat(name));
|
49 | },
|
50 | });
|
51 | };
|
52 | exports.strictProxyMiddleware = strictProxyMiddleware;
|
53 | var accessorMiddleware = function (envObj, rawEnv) {
|
54 |
|
55 |
|
56 |
|
57 | var computedNodeEnv = envObj.NODE_ENV || rawEnv.NODE_ENV;
|
58 |
|
59 | var isProd = !computedNodeEnv || computedNodeEnv === 'production';
|
60 | Object.defineProperties(envObj, {
|
61 | isDevelopment: { value: computedNodeEnv === 'development' },
|
62 | isDev: { value: computedNodeEnv === 'development' },
|
63 | isProduction: { value: isProd },
|
64 | isProd: { value: isProd },
|
65 | isTest: { value: computedNodeEnv === 'test' },
|
66 | });
|
67 | return envObj;
|
68 | };
|
69 | exports.accessorMiddleware = accessorMiddleware;
|
70 | var applyDefaultMiddleware = function (cleanedEnv, rawEnv) {
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | return (0, exports.strictProxyMiddleware)((0, exports.accessorMiddleware)(cleanedEnv, rawEnv), rawEnv);
|
76 | };
|
77 | exports.applyDefaultMiddleware = applyDefaultMiddleware;
|
78 |
|
\ | No newline at end of file |