@elementor/env 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +34 -34
- package/src/index.ts +4 -4
- package/typedoc.config.js +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,26 +3,26 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [0.3.
|
|
6
|
+
## [0.3.3](https://github.com/elementor/elementor-packages/compare/@elementor/env@0.3.2...@elementor/env@0.3.3) (2024-07-16)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @elementor/env
|
|
9
9
|
|
|
10
|
+
## [0.3.2](https://github.com/elementor/elementor-packages/compare/@elementor/env@0.3.1...@elementor/env@0.3.2) (2023-10-19)
|
|
10
11
|
|
|
12
|
+
**Note:** Version bump only for package @elementor/env
|
|
11
13
|
|
|
14
|
+
## [0.3.1](https://github.com/elementor/elementor-packages/compare/@elementor/env@0.3.0...@elementor/env@0.3.1) (2023-09-26)
|
|
12
15
|
|
|
16
|
+
**Note:** Version bump only for package @elementor/env
|
|
13
17
|
|
|
14
18
|
# 0.3.0 (2023-09-11)
|
|
15
19
|
|
|
16
|
-
|
|
17
20
|
### Features
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
- **env:** mark experimental functions [ED-12072] ([#115](https://github.com/elementor/elementor-packages/issues/115)) ([e5b1b4a](https://github.com/elementor/elementor-packages/commit/e5b1b4ab2c5c14fc77fc25d9fe86108756e26441))
|
|
22
23
|
|
|
23
24
|
# 0.2.0 (2023-05-09)
|
|
24
25
|
|
|
25
|
-
|
|
26
26
|
### Features
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
- **env:** support consuming environment variables in packages [ED-10161] ([#26](https://github.com/elementor/elementor-packages/issues/26)) ([dd811ff](https://github.com/elementor/elementor-packages/commit/dd811ff71e43bf998ee07c6e1f380a379874a7fd))
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["let globalEnv: Record<string, object> | null = null;\n\nexport function initEnv( env: Record<string, object> ) {\n\tglobalEnv = env;\n}\n\nexport function __resetEnv() {\n\tglobalEnv = null;\n}\n\nexport function parseEnv<TEnv extends object = object>(\n\tkey: string,\n\tparseFn: ( envData: object ) => TEnv = ( rawSettings: object ) => rawSettings as TEnv
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["let globalEnv: Record< string, object > | null = null;\n\nexport function initEnv( env: Record< string, object > ) {\n\tglobalEnv = env;\n}\n\nexport function __resetEnv() {\n\tglobalEnv = null;\n}\n\nexport function parseEnv< TEnv extends object = object >(\n\tkey: string,\n\tparseFn: ( envData: object ) => TEnv = ( rawSettings: object ) => rawSettings as TEnv\n) {\n\tlet parsedEnv: TEnv = {} as TEnv;\n\tlet isParsed = false;\n\n\t// Proxy the exposed object so users will be able to access the properties\n\t// as if it was a plain object, while still having automatic parsing.\n\tconst proxiedEnv = new Proxy( parsedEnv, {\n\t\tget( target, property ) {\n\t\t\tif ( ! isParsed ) {\n\t\t\t\tparse();\n\t\t\t}\n\n\t\t\treturn parsedEnv[ property as keyof TEnv ];\n\t\t},\n\t\townKeys() {\n\t\t\tif ( ! isParsed ) {\n\t\t\t\tparse();\n\t\t\t}\n\n\t\t\treturn Reflect.ownKeys( parsedEnv );\n\t\t},\n\t\tgetOwnPropertyDescriptor() {\n\t\t\treturn {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t};\n\t\t},\n\t} );\n\n\tconst parse = () => {\n\t\ttry {\n\t\t\tconst env = globalEnv?.[ key ];\n\n\t\t\tif ( ! env ) {\n\t\t\t\tthrow new InvalidEnvError( `Settings object not found` );\n\t\t\t}\n\n\t\t\tif ( typeof env !== 'object' ) {\n\t\t\t\tthrow new InvalidEnvError( `Expected settings to be \\`object\\`, but got \\`${ typeof env }\\`` );\n\t\t\t}\n\n\t\t\tparsedEnv = parseFn( env );\n\t\t} catch ( e ) {\n\t\t\t// If something in the validation goes wrong, we return an empty object instead of throwing,\n\t\t\t// so it'll fail in the component level rather than the module level.\n\t\t\tif ( e instanceof InvalidEnvError ) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn( `${ key } - ${ e.message }` );\n\n\t\t\t\tparsedEnv = {} as TEnv;\n\t\t\t} else {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t} finally {\n\t\t\tisParsed = true;\n\t\t}\n\t};\n\n\treturn {\n\t\tvalidateEnv: parse,\n\t\tenv: proxiedEnv,\n\t};\n}\n\nexport class InvalidEnvError extends Error {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAI,YAA6C;AAE1C,SAAS,QAAS,KAAgC;AACxD,cAAY;AACb;AAEO,SAAS,aAAa;AAC5B,cAAY;AACb;AAEO,SAAS,SACf,KACA,UAAuC,CAAE,gBAAyB,aACjE;AACD,MAAI,YAAkB,CAAC;AACvB,MAAI,WAAW;AAIf,QAAM,aAAa,IAAI,MAAO,WAAW;AAAA,IACxC,IAAK,QAAQ,UAAW;AACvB,UAAK,CAAE,UAAW;AACjB,cAAM;AAAA,MACP;AAEA,aAAO,UAAW,QAAuB;AAAA,IAC1C;AAAA,IACA,UAAU;AACT,UAAK,CAAE,UAAW;AACjB,cAAM;AAAA,MACP;AAEA,aAAO,QAAQ,QAAS,SAAU;AAAA,IACnC;AAAA,IACA,2BAA2B;AAC1B,aAAO;AAAA,QACN,cAAc;AAAA,QACd,YAAY;AAAA,MACb;AAAA,IACD;AAAA,EACD,CAAE;AAEF,QAAM,QAAQ,MAAM;AACnB,QAAI;AACH,YAAM,MAAM,YAAa,GAAI;AAE7B,UAAK,CAAE,KAAM;AACZ,cAAM,IAAI,gBAAiB,2BAA4B;AAAA,MACxD;AAEA,UAAK,OAAO,QAAQ,UAAW;AAC9B,cAAM,IAAI,gBAAiB,iDAAkD,OAAO,GAAI,IAAK;AAAA,MAC9F;AAEA,kBAAY,QAAS,GAAI;AAAA,IAC1B,SAAU,GAAI;AAGb,UAAK,aAAa,iBAAkB;AAEnC,gBAAQ,KAAM,GAAI,GAAI,MAAO,EAAE,OAAQ,EAAG;AAE1C,oBAAY,CAAC;AAAA,MACd,OAAO;AACN,cAAM;AAAA,MACP;AAAA,IACD,UAAE;AACD,iBAAW;AAAA,IACZ;AAAA,EACD;AAEA,SAAO;AAAA,IACN,aAAa;AAAA,IACb,KAAK;AAAA,EACN;AACD;AAEO,IAAM,kBAAN,cAA8B,MAAM;AAAC;","names":[]}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["let globalEnv: Record<string, object> | null = null;\n\nexport function initEnv( env: Record<string, object> ) {\n\tglobalEnv = env;\n}\n\nexport function __resetEnv() {\n\tglobalEnv = null;\n}\n\nexport function parseEnv<TEnv extends object = object>(\n\tkey: string,\n\tparseFn: ( envData: object ) => TEnv = ( rawSettings: object ) => rawSettings as TEnv
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["let globalEnv: Record< string, object > | null = null;\n\nexport function initEnv( env: Record< string, object > ) {\n\tglobalEnv = env;\n}\n\nexport function __resetEnv() {\n\tglobalEnv = null;\n}\n\nexport function parseEnv< TEnv extends object = object >(\n\tkey: string,\n\tparseFn: ( envData: object ) => TEnv = ( rawSettings: object ) => rawSettings as TEnv\n) {\n\tlet parsedEnv: TEnv = {} as TEnv;\n\tlet isParsed = false;\n\n\t// Proxy the exposed object so users will be able to access the properties\n\t// as if it was a plain object, while still having automatic parsing.\n\tconst proxiedEnv = new Proxy( parsedEnv, {\n\t\tget( target, property ) {\n\t\t\tif ( ! isParsed ) {\n\t\t\t\tparse();\n\t\t\t}\n\n\t\t\treturn parsedEnv[ property as keyof TEnv ];\n\t\t},\n\t\townKeys() {\n\t\t\tif ( ! isParsed ) {\n\t\t\t\tparse();\n\t\t\t}\n\n\t\t\treturn Reflect.ownKeys( parsedEnv );\n\t\t},\n\t\tgetOwnPropertyDescriptor() {\n\t\t\treturn {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t};\n\t\t},\n\t} );\n\n\tconst parse = () => {\n\t\ttry {\n\t\t\tconst env = globalEnv?.[ key ];\n\n\t\t\tif ( ! env ) {\n\t\t\t\tthrow new InvalidEnvError( `Settings object not found` );\n\t\t\t}\n\n\t\t\tif ( typeof env !== 'object' ) {\n\t\t\t\tthrow new InvalidEnvError( `Expected settings to be \\`object\\`, but got \\`${ typeof env }\\`` );\n\t\t\t}\n\n\t\t\tparsedEnv = parseFn( env );\n\t\t} catch ( e ) {\n\t\t\t// If something in the validation goes wrong, we return an empty object instead of throwing,\n\t\t\t// so it'll fail in the component level rather than the module level.\n\t\t\tif ( e instanceof InvalidEnvError ) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn( `${ key } - ${ e.message }` );\n\n\t\t\t\tparsedEnv = {} as TEnv;\n\t\t\t} else {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t} finally {\n\t\t\tisParsed = true;\n\t\t}\n\t};\n\n\treturn {\n\t\tvalidateEnv: parse,\n\t\tenv: proxiedEnv,\n\t};\n}\n\nexport class InvalidEnvError extends Error {}\n"],"mappings":";AAAA,IAAI,YAA6C;AAE1C,SAAS,QAAS,KAAgC;AACxD,cAAY;AACb;AAEO,SAAS,aAAa;AAC5B,cAAY;AACb;AAEO,SAAS,SACf,KACA,UAAuC,CAAE,gBAAyB,aACjE;AACD,MAAI,YAAkB,CAAC;AACvB,MAAI,WAAW;AAIf,QAAM,aAAa,IAAI,MA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|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
2
|
+
"name": "@elementor/env",
|
|
3
|
+
"description": "Manage runtime environment variables in a type-safe way",
|
|
4
|
+
"version": "0.3.3",
|
|
5
|
+
"private": false,
|
|
6
|
+
"author": "Elementor Team",
|
|
7
|
+
"homepage": "https://elementor.com/",
|
|
8
|
+
"license": "GPL-3.0-or-later",
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"module": "dist/index.mjs",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/elementor/elementor-packages.git",
|
|
23
|
+
"directory": "packages/libs/env"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/elementor/elementor-packages/issues"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup --config=../../tsup.build.ts",
|
|
33
|
+
"dev": "tsup --config=../../tsup.dev.ts"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "10fd8663495a9ced2521f27a74879684ed0cf322"
|
|
36
36
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
let globalEnv: Record<string, object> | null = null;
|
|
1
|
+
let globalEnv: Record< string, object > | null = null;
|
|
2
2
|
|
|
3
|
-
export function initEnv( env: Record<string, object> ) {
|
|
3
|
+
export function initEnv( env: Record< string, object > ) {
|
|
4
4
|
globalEnv = env;
|
|
5
5
|
}
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ export function __resetEnv() {
|
|
|
8
8
|
globalEnv = null;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export function parseEnv<TEnv extends object = object>(
|
|
11
|
+
export function parseEnv< TEnv extends object = object >(
|
|
12
12
|
key: string,
|
|
13
|
-
parseFn: ( envData: object ) => TEnv = ( rawSettings: object ) => rawSettings as TEnv
|
|
13
|
+
parseFn: ( envData: object ) => TEnv = ( rawSettings: object ) => rawSettings as TEnv
|
|
14
14
|
) {
|
|
15
15
|
let parsedEnv: TEnv = {} as TEnv;
|
|
16
16
|
let isParsed = false;
|