@squide/env-vars 1.1.1 → 1.1.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 +23 -5
- package/README.md +2 -2
- package/dist/EnvironmentVariablesPlugin.d.ts +5 -8
- package/dist/EnvironmentVariablesPlugin.js +42 -2
- package/dist/EnvironmentVariablesPlugin.js.map +1 -0
- package/dist/EnvironmentVariablesRegistry.d.ts +4 -6
- package/dist/EnvironmentVariablesRegistry.js +46 -1
- package/dist/EnvironmentVariablesRegistry.js.map +1 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -0
- package/dist/useEnvironmentVariable.d.ts +3 -6
- package/dist/useEnvironmentVariable.js +24 -3
- package/dist/useEnvironmentVariable.js.map +1 -0
- package/package.json +28 -24
- package/src/EnvironmentVariablesPlugin.ts +42 -0
- package/src/EnvironmentVariablesRegistry.ts +56 -0
- package/src/index.ts +4 -0
- package/src/useEnvironmentVariable.ts +17 -0
- package/dist/chunk-IXP4YDYO.js +0 -40
- package/dist/chunk-QLZVF7AB.js +0 -15
- package/dist/chunk-T435A5DU.js +0 -33
package/CHANGELOG.md
CHANGED
|
@@ -1,27 +1,45 @@
|
|
|
1
1
|
# @squide/env-vars
|
|
2
2
|
|
|
3
|
+
## 1.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#244](https://github.com/workleap/wl-squide/pull/244) [`5d13eb0`](https://github.com/workleap/wl-squide/commit/5d13eb038a724b499b820d7e1dc864c87954510b) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Updated dependencies.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`5d13eb0`](https://github.com/workleap/wl-squide/commit/5d13eb038a724b499b820d7e1dc864c87954510b)]:
|
|
10
|
+
- @squide/core@5.4.3
|
|
11
|
+
|
|
12
|
+
## 1.1.2
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#231](https://github.com/workleap/wl-squide/pull/231) [`3c6bce0`](https://github.com/workleap/wl-squide/commit/3c6bce0cd559d0b8517d644661b6fb2b818ab2f6) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Packages now includes source code and sourcemap.
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`3c6bce0`](https://github.com/workleap/wl-squide/commit/3c6bce0cd559d0b8517d644661b6fb2b818ab2f6)]:
|
|
19
|
+
- @squide/core@5.4.2
|
|
20
|
+
|
|
3
21
|
## 1.1.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
6
24
|
|
|
7
|
-
- [#221](https://github.com/
|
|
25
|
+
- [#221](https://github.com/workleap/wl-squide/pull/221) [`8411080`](https://github.com/workleap/wl-squide/commit/8411080dfd0df6d0eafb01888298154fa5e5d925) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Fix deferred registrations.
|
|
8
26
|
|
|
9
|
-
- Updated dependencies [[`8411080`](https://github.com/
|
|
27
|
+
- Updated dependencies [[`8411080`](https://github.com/workleap/wl-squide/commit/8411080dfd0df6d0eafb01888298154fa5e5d925)]:
|
|
10
28
|
- @squide/core@5.4.1
|
|
11
29
|
|
|
12
30
|
## 1.1.0
|
|
13
31
|
|
|
14
32
|
### Minor Changes
|
|
15
33
|
|
|
16
|
-
- [#219](https://github.com/
|
|
34
|
+
- [#219](https://github.com/workleap/wl-squide/pull/219) [`25cb482`](https://github.com/workleap/wl-squide/commit/25cb482779ee280f3f7109de4607b92dcfeef7f3) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Now dispatching events to enable instrumentation packages for observability platforms.
|
|
17
35
|
|
|
18
36
|
### Patch Changes
|
|
19
37
|
|
|
20
|
-
- Updated dependencies [[`25cb482`](https://github.com/
|
|
38
|
+
- Updated dependencies [[`25cb482`](https://github.com/workleap/wl-squide/commit/25cb482779ee280f3f7109de4607b92dcfeef7f3)]:
|
|
21
39
|
- @squide/core@5.4.0
|
|
22
40
|
|
|
23
41
|
## 1.0.0
|
|
24
42
|
|
|
25
43
|
### Major Changes
|
|
26
44
|
|
|
27
|
-
- [#208](https://github.com/
|
|
45
|
+
- [#208](https://github.com/workleap/wl-squide/pull/208) [`a41b2bc`](https://github.com/workleap/wl-squide/commit/a41b2bc519bcfd197272943e726921d9ca8d6611) Thanks [@patricklafrance](https://github.com/patricklafrance)! - First release of the new `EnvironmentVariablesPlugin`. For additional information read the [guide](https://workleap.github.io/wl-squide/guides/use-environment-variables/).
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Usage
|
|
4
4
|
|
|
5
|
-
View the [user's documentation](https://
|
|
5
|
+
View the [user's documentation](https://workleap.github.io/wl-squide/).
|
|
6
6
|
|
|
7
7
|
## 🤝 Contributing
|
|
8
8
|
|
|
@@ -10,4 +10,4 @@ View the [contributor's documentation](../../CONTRIBUTING.md).
|
|
|
10
10
|
|
|
11
11
|
## License
|
|
12
12
|
|
|
13
|
-
Copyright © 2024, Workleap. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/
|
|
13
|
+
Copyright © 2024, Workleap. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/workleap/workleap-license/blob/master/LICENSE.
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Plugin, Runtime } from
|
|
2
|
-
import { EnvironmentVariablesRegistryKey, EnvironmentVariablesRegistryValue
|
|
3
|
-
|
|
4
|
-
declare
|
|
5
|
-
declare class EnvironmentVariablesPlugin extends Plugin {
|
|
1
|
+
import { Plugin, type Runtime } from "@squide/core";
|
|
2
|
+
import { type EnvironmentVariables, type EnvironmentVariablesRegistryKey, type EnvironmentVariablesRegistryValue } from "./EnvironmentVariablesRegistry.ts";
|
|
3
|
+
export declare const EnvironmentVariablesPluginName = "env-vars-plugin";
|
|
4
|
+
export declare class EnvironmentVariablesPlugin extends Plugin {
|
|
6
5
|
#private;
|
|
7
6
|
constructor(runtime: Runtime);
|
|
8
7
|
registerVariable(key: EnvironmentVariablesRegistryKey, value: EnvironmentVariablesRegistryValue): void;
|
|
@@ -10,6 +9,4 @@ declare class EnvironmentVariablesPlugin extends Plugin {
|
|
|
10
9
|
getVariable(key: EnvironmentVariablesRegistryKey): never;
|
|
11
10
|
getVariables(): EnvironmentVariables;
|
|
12
11
|
}
|
|
13
|
-
declare function getEnvironmentVariablesPlugin(runtime: Runtime): EnvironmentVariablesPlugin;
|
|
14
|
-
|
|
15
|
-
export { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin };
|
|
12
|
+
export declare function getEnvironmentVariablesPlugin(runtime: Runtime): EnvironmentVariablesPlugin;
|
|
@@ -1,2 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__ from "@squide/core";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__EnvironmentVariablesRegistry_js_a784aed2__ from "./EnvironmentVariablesRegistry.js";
|
|
3
|
+
|
|
4
|
+
;// CONCATENATED MODULE: external "@squide/core"
|
|
5
|
+
|
|
6
|
+
;// CONCATENATED MODULE: external "./EnvironmentVariablesRegistry.js"
|
|
7
|
+
|
|
8
|
+
;// CONCATENATED MODULE: ./src/EnvironmentVariablesPlugin.ts?__rslib_entry__
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const EnvironmentVariablesPluginName = "env-vars-plugin";
|
|
12
|
+
class EnvironmentVariablesPlugin extends __WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.Plugin {
|
|
13
|
+
#environmentVariablesRegistry = new __WEBPACK_EXTERNAL_MODULE__EnvironmentVariablesRegistry_js_a784aed2__.EnvironmentVariablesRegistry();
|
|
14
|
+
constructor(runtime){
|
|
15
|
+
super(EnvironmentVariablesPluginName, runtime);
|
|
16
|
+
}
|
|
17
|
+
registerVariable(key, value) {
|
|
18
|
+
this.#environmentVariablesRegistry.add(key, value);
|
|
19
|
+
this._runtime.logger.debug(`[squide] An environment variable for key "${key}" has been registered with the value "${value}".`);
|
|
20
|
+
}
|
|
21
|
+
registerVariables(variables) {
|
|
22
|
+
this.#environmentVariablesRegistry.addVariables(variables);
|
|
23
|
+
this._runtime.logger.debug("[squide] The following environment variables has been registered:", variables);
|
|
24
|
+
}
|
|
25
|
+
getVariable(key) {
|
|
26
|
+
return this.#environmentVariablesRegistry.getVariable(key);
|
|
27
|
+
}
|
|
28
|
+
getVariables() {
|
|
29
|
+
return this.#environmentVariablesRegistry.getVariables();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function getEnvironmentVariablesPlugin(runtime) {
|
|
33
|
+
const plugin = runtime.getPlugin(EnvironmentVariablesPluginName);
|
|
34
|
+
if ((0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.isNil)(plugin)) {
|
|
35
|
+
throw new Error("[squide] The getEnvironmentVariablesPlugin function is called but no EnvironmentVariablesPlugin instance has been registered with the runtime.");
|
|
36
|
+
}
|
|
37
|
+
return plugin;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=EnvironmentVariablesPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvironmentVariablesPlugin.js","sources":["webpack://@squide/env-vars/./src/EnvironmentVariablesPlugin.ts"],"sourcesContent":["import { isNil, Plugin, type Runtime } from \"@squide/core\";\nimport { type EnvironmentVariables, EnvironmentVariablesRegistry, type EnvironmentVariablesRegistryKey, type EnvironmentVariablesRegistryValue } from \"./EnvironmentVariablesRegistry.ts\";\n\nexport const EnvironmentVariablesPluginName = \"env-vars-plugin\";\n\nexport class EnvironmentVariablesPlugin extends Plugin {\n readonly #environmentVariablesRegistry = new EnvironmentVariablesRegistry();\n\n constructor(runtime: Runtime) {\n super(EnvironmentVariablesPluginName, runtime);\n }\n\n registerVariable(key: EnvironmentVariablesRegistryKey, value: EnvironmentVariablesRegistryValue) {\n this.#environmentVariablesRegistry.add(key, value);\n\n this._runtime.logger.debug(`[squide] An environment variable for key \"${key}\" has been registered with the value \"${value}\".`);\n }\n\n registerVariables(variables: Partial<EnvironmentVariables>) {\n this.#environmentVariablesRegistry.addVariables(variables);\n\n this._runtime.logger.debug(\"[squide] The following environment variables has been registered:\", variables);\n }\n\n getVariable(key: EnvironmentVariablesRegistryKey) {\n return this.#environmentVariablesRegistry.getVariable(key);\n }\n\n getVariables() {\n return this.#environmentVariablesRegistry.getVariables();\n }\n}\n\nexport function getEnvironmentVariablesPlugin(runtime: Runtime) {\n const plugin = runtime.getPlugin(EnvironmentVariablesPluginName);\n\n if (isNil(plugin)) {\n throw new Error(\"[squide] The getEnvironmentVariablesPlugin function is called but no EnvironmentVariablesPlugin instance has been registered with the runtime.\");\n }\n\n return plugin as EnvironmentVariablesPlugin;\n}\n"],"names":["isNil","Plugin","EnvironmentVariablesRegistry","EnvironmentVariablesPluginName","EnvironmentVariablesPlugin","runtime","key","value","variables","getEnvironmentVariablesPlugin","plugin","Error"],"mappings":";;;;;;;;AAA2D;AAC+H;AAEnL,MAAMG,iCAAiC,kBAAkB;AAEzD,MAAMC,mCAAmCH,wDAAMA;IACzC,6BAA6B,GAAG,IAAIC,kGAA4BA,GAAG;IAE5E,YAAYG,OAAgB,CAAE;QAC1B,KAAK,CAACF,gCAAgCE;IAC1C;IAEA,iBAAiBC,GAAoC,EAAEC,KAAwC,EAAE;QAC7F,IAAI,CAAC,6BAA6B,CAAC,GAAG,CAACD,KAAKC;QAE5C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,0CAA0C,EAAED,IAAI,sCAAsC,EAAEC,MAAM,EAAE,CAAC;IACjI;IAEA,kBAAkBC,SAAwC,EAAE;QACxD,IAAI,CAAC,6BAA6B,CAAC,YAAY,CAACA;QAEhD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,qEAAqEA;IACpG;IAEA,YAAYF,GAAoC,EAAE;QAC9C,OAAO,IAAI,CAAC,6BAA6B,CAAC,WAAW,CAACA;IAC1D;IAEA,eAAe;QACX,OAAO,IAAI,CAAC,6BAA6B,CAAC,YAAY;IAC1D;AACJ;AAEO,SAASG,8BAA8BJ,OAAgB;IAC1D,MAAMK,SAASL,QAAQ,SAAS,CAACF;IAEjC,IAAIH,2DAAKA,CAACU,SAAS;QACf,MAAM,IAAIC,MAAM;IACpB;IAEA,OAAOD;AACX"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
interface EnvironmentVariables {
|
|
1
|
+
export interface EnvironmentVariables {
|
|
2
2
|
}
|
|
3
|
-
type EnvironmentVariablesRegistryKey = keyof EnvironmentVariables;
|
|
4
|
-
type EnvironmentVariablesRegistryValue = EnvironmentVariables[keyof EnvironmentVariables];
|
|
5
|
-
declare class EnvironmentVariablesRegistry {
|
|
3
|
+
export type EnvironmentVariablesRegistryKey = keyof EnvironmentVariables;
|
|
4
|
+
export type EnvironmentVariablesRegistryValue = EnvironmentVariables[keyof EnvironmentVariables];
|
|
5
|
+
export declare class EnvironmentVariablesRegistry {
|
|
6
6
|
#private;
|
|
7
7
|
add(key: EnvironmentVariablesRegistryKey, value: EnvironmentVariablesRegistryValue): void;
|
|
8
8
|
addVariables(variables: Partial<EnvironmentVariables>): void;
|
|
9
9
|
getVariable(key: EnvironmentVariablesRegistryKey): never;
|
|
10
10
|
getVariables(): EnvironmentVariables;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
export { type EnvironmentVariables, EnvironmentVariablesRegistry, type EnvironmentVariablesRegistryKey, type EnvironmentVariablesRegistryValue };
|
|
@@ -1 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_memoize__ from "memoize";
|
|
2
|
+
|
|
3
|
+
;// CONCATENATED MODULE: external "memoize"
|
|
4
|
+
|
|
5
|
+
;// CONCATENATED MODULE: ./src/EnvironmentVariablesRegistry.ts?__rslib_entry__
|
|
6
|
+
|
|
7
|
+
class EnvironmentVariablesRegistry {
|
|
8
|
+
#variables = new Map();
|
|
9
|
+
// Since the "getVariables" function is transforming the variables from a Map to an Object, the result of
|
|
10
|
+
// the transformation is memoized to ensure the returned Object is immutable and can be use in React closures.
|
|
11
|
+
#memoizedGetVariables = (0,__WEBPACK_EXTERNAL_MODULE_memoize__["default"])(()=>Object.fromEntries(this.#variables));
|
|
12
|
+
add(key, value) {
|
|
13
|
+
if (this.#variables.has(key)) {
|
|
14
|
+
const existingValue = this.#variables.get(key);
|
|
15
|
+
if (existingValue !== value) {
|
|
16
|
+
throw new Error(`[squide] An environment variable with the key "${key}" already exist and the new value differs from the existing one. Existing value: "${existingValue}" - New Value: "${value}"`);
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
this.#variables.set(key, value);
|
|
20
|
+
(0,__WEBPACK_EXTERNAL_MODULE_memoize__.memoizeClear)(this.#memoizedGetVariables);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
addVariables(variables) {
|
|
24
|
+
// Do not clear the "getVariables" memoize result if there are no variables.
|
|
25
|
+
if (Object.keys(variables).length > 0) {
|
|
26
|
+
for (const [key, value] of Object.entries(variables)){
|
|
27
|
+
this.add(key, value);
|
|
28
|
+
}
|
|
29
|
+
(0,__WEBPACK_EXTERNAL_MODULE_memoize__.memoizeClear)(this.#memoizedGetVariables);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
getVariable(key) {
|
|
33
|
+
const value = this.#variables.get(key);
|
|
34
|
+
if (!value) {
|
|
35
|
+
throw new Error(`[squide] No environment variable has been registered for the key "${key}".`);
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
getVariables() {
|
|
40
|
+
return this.#memoizedGetVariables();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { EnvironmentVariablesRegistry };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=EnvironmentVariablesRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvironmentVariablesRegistry.js","sources":["webpack://@squide/env-vars/./src/EnvironmentVariablesRegistry.ts"],"sourcesContent":["import memoize, { memoizeClear } from \"memoize\";\n\n// The \"EnvironmentVariables\" interface is expected to be extended by remote modules adding their own environment variables to the runtime.\n// This magic is called module augmentation: https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation.\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface EnvironmentVariables {}\n\nexport type EnvironmentVariablesRegistryKey = keyof EnvironmentVariables;\nexport type EnvironmentVariablesRegistryValue = EnvironmentVariables[keyof EnvironmentVariables];\n\nexport class EnvironmentVariablesRegistry {\n readonly #variables = new Map<EnvironmentVariablesRegistryKey, EnvironmentVariablesRegistryValue>();\n\n // Since the \"getVariables\" function is transforming the variables from a Map to an Object, the result of\n // the transformation is memoized to ensure the returned Object is immutable and can be use in React closures.\n readonly #memoizedGetVariables = memoize(() => Object.fromEntries(this.#variables) as unknown as EnvironmentVariables);\n\n add(key: EnvironmentVariablesRegistryKey, value: EnvironmentVariablesRegistryValue) {\n if (this.#variables.has(key)) {\n const existingValue = this.#variables.get(key);\n\n if (existingValue !== value) {\n throw new Error(`[squide] An environment variable with the key \"${key}\" already exist and the new value differs from the existing one. Existing value: \"${existingValue}\" - New Value: \"${value}\"`);\n }\n } else {\n this.#variables.set(key, value);\n\n memoizeClear(this.#memoizedGetVariables);\n }\n }\n\n addVariables(variables: Partial<EnvironmentVariables>) {\n // Do not clear the \"getVariables\" memoize result if there are no variables.\n if (Object.keys(variables).length > 0) {\n for (const [key, value] of Object.entries(variables)) {\n this.add(key as EnvironmentVariablesRegistryKey, value as EnvironmentVariablesRegistryValue);\n }\n\n memoizeClear(this.#memoizedGetVariables);\n }\n }\n\n getVariable(key: EnvironmentVariablesRegistryKey) {\n const value = this.#variables.get(key);\n\n if (!value) {\n throw new Error(`[squide] No environment variable has been registered for the key \"${key}\".`);\n }\n\n return value;\n }\n\n getVariables() {\n return this.#memoizedGetVariables();\n }\n}\n"],"names":["memoize","memoizeClear","EnvironmentVariablesRegistry","Map","Object","key","value","existingValue","Error","variables"],"mappings":";;;;;AAAgD;AAUzC,MAAME;IACA,UAAU,GAAG,IAAIC,MAA0E;IAEpG,yGAAyG;IACzG,8GAA8G;IACrG,qBAAqB,GAAGH,kDAAOA,CAAC,IAAMI,OAAO,WAAW,CAAC,IAAI,CAAC,UAAU,GAAsC;IAEvH,IAAIC,GAAoC,EAAEC,KAAwC,EAAE;QAChF,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAACD,MAAM;YAC1B,MAAME,gBAAgB,IAAI,CAAC,UAAU,CAAC,GAAG,CAACF;YAE1C,IAAIE,kBAAkBD,OAAO;gBACzB,MAAM,IAAIE,MAAM,CAAC,+CAA+C,EAAEH,IAAI,kFAAkF,EAAEE,cAAc,gBAAgB,EAAED,MAAM,CAAC,CAAC;YACtM;QACJ,OAAO;YACH,IAAI,CAAC,UAAU,CAAC,GAAG,CAACD,KAAKC;YAEzBL,oDAAYA,CAAC,IAAI,CAAC,qBAAqB;QAC3C;IACJ;IAEA,aAAaQ,SAAwC,EAAE;QACnD,4EAA4E;QAC5E,IAAIL,OAAO,IAAI,CAACK,WAAW,MAAM,GAAG,GAAG;YACnC,KAAK,MAAM,CAACJ,KAAKC,MAAM,IAAIF,OAAO,OAAO,CAACK,WAAY;gBAClD,IAAI,CAAC,GAAG,CAACJ,KAAwCC;YACrD;YAEAL,oDAAYA,CAAC,IAAI,CAAC,qBAAqB;QAC3C;IACJ;IAEA,YAAYI,GAAoC,EAAE;QAC9C,MAAMC,QAAQ,IAAI,CAAC,UAAU,CAAC,GAAG,CAACD;QAElC,IAAI,CAACC,OAAO;YACR,MAAM,IAAIE,MAAM,CAAC,kEAAkE,EAAEH,IAAI,EAAE,CAAC;QAChG;QAEA,OAAOC;IACX;IAEA,eAAe;QACX,OAAO,IAAI,CAAC,qBAAqB;IACrC;AACJ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { EnvironmentVariables, EnvironmentVariablesRegistryKey, EnvironmentVariablesRegistryValue } from
|
|
3
|
-
export
|
|
4
|
-
import '@squide/core';
|
|
1
|
+
export * from "./EnvironmentVariablesPlugin.ts";
|
|
2
|
+
export type { EnvironmentVariables, EnvironmentVariablesRegistryKey, EnvironmentVariablesRegistryValue } from "./EnvironmentVariablesRegistry.ts";
|
|
3
|
+
export * from "./useEnvironmentVariable.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
|
|
1
|
+
export * from "./EnvironmentVariablesPlugin.js";
|
|
2
|
+
export * from "./useEnvironmentVariable.js";
|
|
3
|
+
|
|
4
|
+
;// CONCATENATED MODULE: ./src/index.ts?__rslib_entry__
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["webpack://@squide/env-vars/./src/index.ts"],"sourcesContent":["export * from \"./EnvironmentVariablesPlugin.ts\";\nexport type { EnvironmentVariables, EnvironmentVariablesRegistryKey, EnvironmentVariablesRegistryValue } from \"./EnvironmentVariablesRegistry.ts\";\nexport * from \"./useEnvironmentVariable.ts\";\n\n"],"names":[],"mappings":";;;;AAAgD;AAEJ"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { EnvironmentVariablesRegistryKey
|
|
2
|
-
|
|
3
|
-
declare function
|
|
4
|
-
declare function useEnvironmentVariables(): EnvironmentVariables;
|
|
5
|
-
|
|
6
|
-
export { useEnvironmentVariable, useEnvironmentVariables };
|
|
1
|
+
import type { EnvironmentVariablesRegistryKey } from "./EnvironmentVariablesRegistry.ts";
|
|
2
|
+
export declare function useEnvironmentVariable(key: EnvironmentVariablesRegistryKey): never;
|
|
3
|
+
export declare function useEnvironmentVariables(): import("./EnvironmentVariablesRegistry.ts").EnvironmentVariables;
|
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__ from "@squide/core";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__EnvironmentVariablesPlugin_js_3420fecf__ from "./EnvironmentVariablesPlugin.js";
|
|
3
|
+
|
|
4
|
+
;// CONCATENATED MODULE: external "@squide/core"
|
|
5
|
+
|
|
6
|
+
;// CONCATENATED MODULE: external "./EnvironmentVariablesPlugin.js"
|
|
7
|
+
|
|
8
|
+
;// CONCATENATED MODULE: ./src/useEnvironmentVariable.ts?__rslib_entry__
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function useEnvironmentVariable(key) {
|
|
12
|
+
const runtime = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useRuntime)();
|
|
13
|
+
const plugin = (0,__WEBPACK_EXTERNAL_MODULE__EnvironmentVariablesPlugin_js_3420fecf__.getEnvironmentVariablesPlugin)(runtime);
|
|
14
|
+
return plugin.getVariable(key);
|
|
15
|
+
}
|
|
16
|
+
function useEnvironmentVariables() {
|
|
17
|
+
const runtime = (0,__WEBPACK_EXTERNAL_MODULE__squide_core_7a405b8f__.useRuntime)();
|
|
18
|
+
const plugin = (0,__WEBPACK_EXTERNAL_MODULE__EnvironmentVariablesPlugin_js_3420fecf__.getEnvironmentVariablesPlugin)(runtime);
|
|
19
|
+
return plugin.getVariables();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { useEnvironmentVariable, useEnvironmentVariables };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=useEnvironmentVariable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEnvironmentVariable.js","sources":["webpack://@squide/env-vars/./src/useEnvironmentVariable.ts"],"sourcesContent":["import { useRuntime } from \"@squide/core\";\nimport { getEnvironmentVariablesPlugin } from \"./EnvironmentVariablesPlugin.ts\";\nimport type { EnvironmentVariablesRegistryKey } from \"./EnvironmentVariablesRegistry.ts\";\n\nexport function useEnvironmentVariable(key: EnvironmentVariablesRegistryKey) {\n const runtime = useRuntime();\n const plugin = getEnvironmentVariablesPlugin(runtime);\n\n return plugin.getVariable(key);\n}\n\nexport function useEnvironmentVariables() {\n const runtime = useRuntime();\n const plugin = getEnvironmentVariablesPlugin(runtime);\n\n return plugin.getVariables();\n}\n"],"names":["useRuntime","getEnvironmentVariablesPlugin","useEnvironmentVariable","key","runtime","plugin","useEnvironmentVariables"],"mappings":";;;;;;;;AAA0C;AACsC;AAGzE,SAASE,uBAAuBC,GAAoC;IACvE,MAAMC,UAAUJ,gEAAUA;IAC1B,MAAMK,SAASJ,qGAA6BA,CAACG;IAE7C,OAAOC,OAAO,WAAW,CAACF;AAC9B;AAEO,SAASG;IACZ,MAAMF,UAAUJ,gEAAUA;IAC1B,MAAMK,SAASJ,qGAA6BA,CAACG;IAE7C,OAAOC,OAAO,YAAY;AAC9B"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squide/env-vars",
|
|
3
3
|
"author": "Workleap",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.3",
|
|
5
5
|
"description": "Add support for environment variables to @squide application shell.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/
|
|
9
|
+
"url": "git+https://github.com/workleap/wl-squide.git",
|
|
10
10
|
"directory": "packages/env-vars"
|
|
11
11
|
},
|
|
12
|
+
"type": "module",
|
|
12
13
|
"publishConfig": {
|
|
13
14
|
"access": "public",
|
|
14
15
|
"provenance": true
|
|
15
16
|
},
|
|
16
|
-
"type": "module",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
@@ -22,37 +22,41 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
|
-
"
|
|
25
|
+
"src",
|
|
26
|
+
"dist",
|
|
26
27
|
"CHANGELOG.md",
|
|
27
28
|
"README.md"
|
|
28
29
|
],
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": "*"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@types/react": "19.0.10",
|
|
35
|
+
"memoize": "10.1.0",
|
|
36
|
+
"@squide/core": "5.4.3"
|
|
37
|
+
},
|
|
29
38
|
"devDependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@workleap/
|
|
36
|
-
"@workleap/swc-configs": "2.2.3",
|
|
37
|
-
"@workleap/tsup-configs": "3.0.6",
|
|
39
|
+
"@rsbuild/core": "1.2.19",
|
|
40
|
+
"@rslib/core": "0.5.4",
|
|
41
|
+
"@typescript-eslint/parser": "8.26.1",
|
|
42
|
+
"@vitejs/plugin-react": "4.3.4",
|
|
43
|
+
"@workleap/eslint-plugin": "3.3.0",
|
|
44
|
+
"@workleap/rslib-configs": "1.0.2",
|
|
38
45
|
"@workleap/typescript-configs": "3.0.2",
|
|
39
46
|
"eslint": "8.57.0",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"typescript": "5.5.4"
|
|
45
|
-
},
|
|
46
|
-
"dependencies": {
|
|
47
|
-
"memoize": "10.0.0",
|
|
48
|
-
"@squide/core": "5.4.1"
|
|
47
|
+
"happy-dom": "17.4.4",
|
|
48
|
+
"react": "19.0.0",
|
|
49
|
+
"typescript": "5.8.2",
|
|
50
|
+
"vitest": "3.0.8"
|
|
49
51
|
},
|
|
50
52
|
"sideEffects": false,
|
|
51
53
|
"engines": {
|
|
52
|
-
"node": ">=
|
|
54
|
+
"node": ">=21.1.0"
|
|
53
55
|
},
|
|
54
56
|
"scripts": {
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
+
"build": "rslib build --config ./rslib.build.ts",
|
|
58
|
+
"eslint": "eslint . --max-warnings=-0 --cache --cache-location node_modules/.cache/eslint",
|
|
59
|
+
"typecheck": "tsc",
|
|
60
|
+
"test": "vitest --config vitest.config.ts --no-watch"
|
|
57
61
|
}
|
|
58
62
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isNil, Plugin, type Runtime } from "@squide/core";
|
|
2
|
+
import { type EnvironmentVariables, EnvironmentVariablesRegistry, type EnvironmentVariablesRegistryKey, type EnvironmentVariablesRegistryValue } from "./EnvironmentVariablesRegistry.ts";
|
|
3
|
+
|
|
4
|
+
export const EnvironmentVariablesPluginName = "env-vars-plugin";
|
|
5
|
+
|
|
6
|
+
export class EnvironmentVariablesPlugin extends Plugin {
|
|
7
|
+
readonly #environmentVariablesRegistry = new EnvironmentVariablesRegistry();
|
|
8
|
+
|
|
9
|
+
constructor(runtime: Runtime) {
|
|
10
|
+
super(EnvironmentVariablesPluginName, runtime);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
registerVariable(key: EnvironmentVariablesRegistryKey, value: EnvironmentVariablesRegistryValue) {
|
|
14
|
+
this.#environmentVariablesRegistry.add(key, value);
|
|
15
|
+
|
|
16
|
+
this._runtime.logger.debug(`[squide] An environment variable for key "${key}" has been registered with the value "${value}".`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
registerVariables(variables: Partial<EnvironmentVariables>) {
|
|
20
|
+
this.#environmentVariablesRegistry.addVariables(variables);
|
|
21
|
+
|
|
22
|
+
this._runtime.logger.debug("[squide] The following environment variables has been registered:", variables);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getVariable(key: EnvironmentVariablesRegistryKey) {
|
|
26
|
+
return this.#environmentVariablesRegistry.getVariable(key);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getVariables() {
|
|
30
|
+
return this.#environmentVariablesRegistry.getVariables();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getEnvironmentVariablesPlugin(runtime: Runtime) {
|
|
35
|
+
const plugin = runtime.getPlugin(EnvironmentVariablesPluginName);
|
|
36
|
+
|
|
37
|
+
if (isNil(plugin)) {
|
|
38
|
+
throw new Error("[squide] The getEnvironmentVariablesPlugin function is called but no EnvironmentVariablesPlugin instance has been registered with the runtime.");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return plugin as EnvironmentVariablesPlugin;
|
|
42
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import memoize, { memoizeClear } from "memoize";
|
|
2
|
+
|
|
3
|
+
// The "EnvironmentVariables" interface is expected to be extended by remote modules adding their own environment variables to the runtime.
|
|
4
|
+
// This magic is called module augmentation: https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation.
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
6
|
+
export interface EnvironmentVariables {}
|
|
7
|
+
|
|
8
|
+
export type EnvironmentVariablesRegistryKey = keyof EnvironmentVariables;
|
|
9
|
+
export type EnvironmentVariablesRegistryValue = EnvironmentVariables[keyof EnvironmentVariables];
|
|
10
|
+
|
|
11
|
+
export class EnvironmentVariablesRegistry {
|
|
12
|
+
readonly #variables = new Map<EnvironmentVariablesRegistryKey, EnvironmentVariablesRegistryValue>();
|
|
13
|
+
|
|
14
|
+
// Since the "getVariables" function is transforming the variables from a Map to an Object, the result of
|
|
15
|
+
// the transformation is memoized to ensure the returned Object is immutable and can be use in React closures.
|
|
16
|
+
readonly #memoizedGetVariables = memoize(() => Object.fromEntries(this.#variables) as unknown as EnvironmentVariables);
|
|
17
|
+
|
|
18
|
+
add(key: EnvironmentVariablesRegistryKey, value: EnvironmentVariablesRegistryValue) {
|
|
19
|
+
if (this.#variables.has(key)) {
|
|
20
|
+
const existingValue = this.#variables.get(key);
|
|
21
|
+
|
|
22
|
+
if (existingValue !== value) {
|
|
23
|
+
throw new Error(`[squide] An environment variable with the key "${key}" already exist and the new value differs from the existing one. Existing value: "${existingValue}" - New Value: "${value}"`);
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
this.#variables.set(key, value);
|
|
27
|
+
|
|
28
|
+
memoizeClear(this.#memoizedGetVariables);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
addVariables(variables: Partial<EnvironmentVariables>) {
|
|
33
|
+
// Do not clear the "getVariables" memoize result if there are no variables.
|
|
34
|
+
if (Object.keys(variables).length > 0) {
|
|
35
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
36
|
+
this.add(key as EnvironmentVariablesRegistryKey, value as EnvironmentVariablesRegistryValue);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
memoizeClear(this.#memoizedGetVariables);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getVariable(key: EnvironmentVariablesRegistryKey) {
|
|
44
|
+
const value = this.#variables.get(key);
|
|
45
|
+
|
|
46
|
+
if (!value) {
|
|
47
|
+
throw new Error(`[squide] No environment variable has been registered for the key "${key}".`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getVariables() {
|
|
54
|
+
return this.#memoizedGetVariables();
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useRuntime } from "@squide/core";
|
|
2
|
+
import { getEnvironmentVariablesPlugin } from "./EnvironmentVariablesPlugin.ts";
|
|
3
|
+
import type { EnvironmentVariablesRegistryKey } from "./EnvironmentVariablesRegistry.ts";
|
|
4
|
+
|
|
5
|
+
export function useEnvironmentVariable(key: EnvironmentVariablesRegistryKey) {
|
|
6
|
+
const runtime = useRuntime();
|
|
7
|
+
const plugin = getEnvironmentVariablesPlugin(runtime);
|
|
8
|
+
|
|
9
|
+
return plugin.getVariable(key);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useEnvironmentVariables() {
|
|
13
|
+
const runtime = useRuntime();
|
|
14
|
+
const plugin = getEnvironmentVariablesPlugin(runtime);
|
|
15
|
+
|
|
16
|
+
return plugin.getVariables();
|
|
17
|
+
}
|
package/dist/chunk-IXP4YDYO.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import memoize, { memoizeClear } from 'memoize';
|
|
2
|
-
|
|
3
|
-
// src/EnvironmentVariablesRegistry.ts
|
|
4
|
-
var EnvironmentVariablesRegistry = class {
|
|
5
|
-
#variables = /* @__PURE__ */ new Map();
|
|
6
|
-
// Since the "getVariables" function is transforming the variables from a Map to an Object, the result of
|
|
7
|
-
// the transformation is memoized to ensure the returned Object is immutable and can be use in React closures.
|
|
8
|
-
#memoizedGetVariables = memoize(() => Object.fromEntries(this.#variables));
|
|
9
|
-
add(key, value) {
|
|
10
|
-
if (this.#variables.has(key)) {
|
|
11
|
-
const existingValue = this.#variables.get(key);
|
|
12
|
-
if (existingValue !== value) {
|
|
13
|
-
throw new Error(`[squide] An environment variable with the key "${key}" already exist and the new value differs from the existing one. Existing value: "${existingValue}" - New Value: "${value}"`);
|
|
14
|
-
}
|
|
15
|
-
} else {
|
|
16
|
-
this.#variables.set(key, value);
|
|
17
|
-
memoizeClear(this.#memoizedGetVariables);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
addVariables(variables) {
|
|
21
|
-
if (Object.keys(variables).length > 0) {
|
|
22
|
-
for (const [key, value] of Object.entries(variables)) {
|
|
23
|
-
this.add(key, value);
|
|
24
|
-
}
|
|
25
|
-
memoizeClear(this.#memoizedGetVariables);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
getVariable(key) {
|
|
29
|
-
const value = this.#variables.get(key);
|
|
30
|
-
if (!value) {
|
|
31
|
-
throw new Error(`[squide] No environment variable has been registered for the key "${key}".`);
|
|
32
|
-
}
|
|
33
|
-
return value;
|
|
34
|
-
}
|
|
35
|
-
getVariables() {
|
|
36
|
-
return this.#memoizedGetVariables();
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export { EnvironmentVariablesRegistry };
|
package/dist/chunk-QLZVF7AB.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getEnvironmentVariablesPlugin } from './chunk-T435A5DU.js';
|
|
2
|
-
import { useRuntime } from '@squide/core';
|
|
3
|
-
|
|
4
|
-
function useEnvironmentVariable(key) {
|
|
5
|
-
const runtime = useRuntime();
|
|
6
|
-
const plugin = getEnvironmentVariablesPlugin(runtime);
|
|
7
|
-
return plugin.getVariable(key);
|
|
8
|
-
}
|
|
9
|
-
function useEnvironmentVariables() {
|
|
10
|
-
const runtime = useRuntime();
|
|
11
|
-
const plugin = getEnvironmentVariablesPlugin(runtime);
|
|
12
|
-
return plugin.getVariables();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { useEnvironmentVariable, useEnvironmentVariables };
|
package/dist/chunk-T435A5DU.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { EnvironmentVariablesRegistry } from './chunk-IXP4YDYO.js';
|
|
2
|
-
import { Plugin, isNil } from '@squide/core';
|
|
3
|
-
|
|
4
|
-
var EnvironmentVariablesPluginName = "env-vars-plugin";
|
|
5
|
-
var EnvironmentVariablesPlugin = class extends Plugin {
|
|
6
|
-
#environmentVariablesRegistry = new EnvironmentVariablesRegistry();
|
|
7
|
-
constructor(runtime) {
|
|
8
|
-
super(EnvironmentVariablesPluginName, runtime);
|
|
9
|
-
}
|
|
10
|
-
registerVariable(key, value) {
|
|
11
|
-
this.#environmentVariablesRegistry.add(key, value);
|
|
12
|
-
this._runtime.logger.debug(`[squide] An environment variable for key "${key}" has been registered with the value "${value}".`);
|
|
13
|
-
}
|
|
14
|
-
registerVariables(variables) {
|
|
15
|
-
this.#environmentVariablesRegistry.addVariables(variables);
|
|
16
|
-
this._runtime.logger.debug("[squide] The following environment variables has been registered:", variables);
|
|
17
|
-
}
|
|
18
|
-
getVariable(key) {
|
|
19
|
-
return this.#environmentVariablesRegistry.getVariable(key);
|
|
20
|
-
}
|
|
21
|
-
getVariables() {
|
|
22
|
-
return this.#environmentVariablesRegistry.getVariables();
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
function getEnvironmentVariablesPlugin(runtime) {
|
|
26
|
-
const plugin = runtime.getPlugin(EnvironmentVariablesPluginName);
|
|
27
|
-
if (isNil(plugin)) {
|
|
28
|
-
throw new Error("[squide] The getEnvironmentVariablesPlugin function is called but no EnvironmentVariablesPlugin instance has been registered with the runtime.");
|
|
29
|
-
}
|
|
30
|
-
return plugin;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin };
|