@squide/env-vars 1.4.9 → 1.4.10

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @squide/env-vars
2
2
 
3
+ ## 1.4.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#352](https://github.com/workleap/wl-squide/pull/352) [`7bd7af5`](https://github.com/workleap/wl-squide/commit/7bd7af5a757912309704b9e93bf8ecf1388e6787) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Bump dependency versions.
8
+
9
+ - Updated dependencies [[`7bd7af5`](https://github.com/workleap/wl-squide/commit/7bd7af5a757912309704b9e93bf8ecf1388e6787)]:
10
+ - @squide/core@6.1.7
11
+
3
12
  ## 1.4.9
4
13
 
5
14
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import { Plugin, type Runtime } from "@squide/core";
2
- import { type EnvironmentVariableKey, type EnvironmentVariables, type EnvironmentVariableValue } from "./EnvironmentVariablesRegistry.ts";
2
+ import { type EnvironmentVariableKey, type EnvironmentVariables } from "./EnvironmentVariablesRegistry.ts";
3
3
  export declare const EnvironmentVariablesPluginName = "env-vars-plugin";
4
4
  export interface EnvironmentVariablesPluginOptions {
5
5
  variables?: Partial<EnvironmentVariables>;
@@ -7,9 +7,9 @@ export interface EnvironmentVariablesPluginOptions {
7
7
  export declare class EnvironmentVariablesPlugin extends Plugin {
8
8
  #private;
9
9
  constructor(runtime: Runtime, options?: EnvironmentVariablesPluginOptions);
10
- registerVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue): void;
10
+ registerVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]): void;
11
11
  registerVariables(variables: Partial<EnvironmentVariables>): void;
12
- getVariable(key: EnvironmentVariableKey): never;
12
+ getVariable<T extends EnvironmentVariableKey>(key: T): EnvironmentVariables[T];
13
13
  getVariables(): EnvironmentVariables;
14
14
  }
15
15
  export declare function getEnvironmentVariablesPlugin(runtime: Runtime): EnvironmentVariablesPlugin;
@@ -1,4 +1,4 @@
1
- import { Plugin, isNil } from "@squide/core";
1
+ import { Plugin } from "@squide/core";
2
2
  import { EnvironmentVariablesRegistry } from "./EnvironmentVariablesRegistry.js";
3
3
 
4
4
  ;// CONCATENATED MODULE: external "@squide/core"
@@ -34,9 +34,11 @@ class EnvironmentVariablesPlugin extends Plugin {
34
34
  }
35
35
  }
36
36
  function getEnvironmentVariablesPlugin(runtime) {
37
- const plugin = runtime.getPlugin(EnvironmentVariablesPluginName);
38
- if (isNil(plugin)) {
39
- throw new Error("[squide] The getEnvironmentVariablesPlugin function is called but no EnvironmentVariablesPlugin instance has been registered with the runtime.");
37
+ const plugin = runtime.getPlugin(EnvironmentVariablesPluginName, {
38
+ throwOnNotFound: false
39
+ });
40
+ if (!plugin) {
41
+ throw new Error("[squide] The getEnvironmentVariablesPlugin function is called but no EnvironmentVariablesPlugin instance has been registered with the runtime. Did you provide a EnvironmentVariablesPlugin instance to the runtime instance?");
40
42
  }
41
43
  return plugin;
42
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentVariablesPlugin.js","sources":["../src/EnvironmentVariablesPlugin.ts"],"sourcesContent":["import { isNil, Plugin, type Runtime } from \"@squide/core\";\nimport { EnvironmentVariablesRegistry, type EnvironmentVariableKey, type EnvironmentVariables, type EnvironmentVariableValue } from \"./EnvironmentVariablesRegistry.ts\";\n\nexport const EnvironmentVariablesPluginName = \"env-vars-plugin\";\n\nexport interface EnvironmentVariablesPluginOptions {\n variables?: Partial<EnvironmentVariables>;\n}\n\nexport class EnvironmentVariablesPlugin extends Plugin {\n readonly #environmentVariablesRegistry = new EnvironmentVariablesRegistry();\n\n constructor(runtime: Runtime, options: EnvironmentVariablesPluginOptions = {}) {\n super(EnvironmentVariablesPluginName, runtime);\n\n const {\n variables\n } = options;\n\n if (variables) {\n this.#environmentVariablesRegistry.addVariables(variables);\n }\n }\n\n registerVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue) {\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\n .withText(\"[squide] The following environment variables has been registered:\")\n .withObject(variables)\n .debug();\n }\n\n getVariable(key: EnvironmentVariableKey) {\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","options","variables","key","value","getEnvironmentVariablesPlugin","plugin","Error"],"mappings":";;;;;;;;AAA2D;AAC6G;AAEjK,MAAMG,iCAAiC,kBAAkB;AAMzD,MAAMC,mCAAmCH,MAAMA;IACzC,6BAA6B,GAAG,IAAIC,4BAA4BA,GAAG;IAE5E,YAAYG,OAAgB,EAAEC,UAA6C,CAAC,CAAC,CAAE;QAC3E,KAAK,CAACH,gCAAgCE;QAEtC,MAAM,EACFE,SAAS,EACZ,GAAGD;QAEJ,IAAIC,WAAW;YACX,IAAI,CAAC,6BAA6B,CAAC,YAAY,CAACA;QACpD;IACJ;IAEA,iBAAiBC,GAA2B,EAAEC,KAA+B,EAAE;QAC3E,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,kBAAkBF,SAAwC,EAAE;QACxD,IAAI,CAAC,6BAA6B,CAAC,YAAY,CAACA;QAEhD,IAAI,CAAC,QAAQ,CAAC,MAAM,CACf,QAAQ,CAAC,qEACT,UAAU,CAACA,WACX,KAAK;IACd;IAEA,YAAYC,GAA2B,EAAE;QACrC,OAAO,IAAI,CAAC,6BAA6B,CAAC,WAAW,CAACA;IAC1D;IAEA,eAAe;QACX,OAAO,IAAI,CAAC,6BAA6B,CAAC,YAAY;IAC1D;AACJ;AAEO,SAASE,8BAA8BL,OAAgB;IAC1D,MAAMM,SAASN,QAAQ,SAAS,CAACF;IAEjC,IAAIH,KAAKA,CAACW,SAAS;QACf,MAAM,IAAIC,MAAM;IACpB;IAEA,OAAOD;AACX"}
1
+ {"version":3,"file":"EnvironmentVariablesPlugin.js","sources":["../src/EnvironmentVariablesPlugin.ts"],"sourcesContent":["import { Plugin, type Runtime } from \"@squide/core\";\nimport { EnvironmentVariablesRegistry, type EnvironmentVariableKey, type EnvironmentVariables } from \"./EnvironmentVariablesRegistry.ts\";\n\nexport const EnvironmentVariablesPluginName = \"env-vars-plugin\";\n\nexport interface EnvironmentVariablesPluginOptions {\n variables?: Partial<EnvironmentVariables>;\n}\n\nexport class EnvironmentVariablesPlugin extends Plugin {\n readonly #environmentVariablesRegistry = new EnvironmentVariablesRegistry();\n\n constructor(runtime: Runtime, options: EnvironmentVariablesPluginOptions = {}) {\n super(EnvironmentVariablesPluginName, runtime);\n\n const {\n variables\n } = options;\n\n if (variables) {\n this.#environmentVariablesRegistry.addVariables(variables);\n }\n }\n\n registerVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]) {\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\n .withText(\"[squide] The following environment variables has been registered:\")\n .withObject(variables)\n .debug();\n }\n\n getVariable<T extends EnvironmentVariableKey>(key: T) {\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 throwOnNotFound: false\n }) as EnvironmentVariablesPlugin;\n\n if (!plugin) {\n throw new Error(\"[squide] The getEnvironmentVariablesPlugin function is called but no EnvironmentVariablesPlugin instance has been registered with the runtime. Did you provide a EnvironmentVariablesPlugin instance to the runtime instance?\");\n }\n\n return plugin;\n}\n"],"names":["Plugin","EnvironmentVariablesRegistry","EnvironmentVariablesPluginName","EnvironmentVariablesPlugin","runtime","options","variables","key","value","getEnvironmentVariablesPlugin","plugin","Error"],"mappings":";;;;;;;;AAAoD;AACqF;AAElI,MAAME,iCAAiC,kBAAkB;AAMzD,MAAMC,mCAAmCH,MAAMA;IACzC,6BAA6B,GAAG,IAAIC,4BAA4BA,GAAG;IAE5E,YAAYG,OAAgB,EAAEC,UAA6C,CAAC,CAAC,CAAE;QAC3E,KAAK,CAACH,gCAAgCE;QAEtC,MAAM,EACFE,SAAS,EACZ,GAAGD;QAEJ,IAAIC,WAAW;YACX,IAAI,CAAC,6BAA6B,CAAC,YAAY,CAACA;QACpD;IACJ;IAEA,iBAAmDC,GAAM,EAAEC,KAA8B,EAAE;QACvF,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,kBAAkBF,SAAwC,EAAE;QACxD,IAAI,CAAC,6BAA6B,CAAC,YAAY,CAACA;QAEhD,IAAI,CAAC,QAAQ,CAAC,MAAM,CACf,QAAQ,CAAC,qEACT,UAAU,CAACA,WACX,KAAK;IACd;IAEA,YAA8CC,GAAM,EAAE;QAClD,OAAO,IAAI,CAAC,6BAA6B,CAAC,WAAW,CAACA;IAC1D;IAEA,eAAe;QACX,OAAO,IAAI,CAAC,6BAA6B,CAAC,YAAY;IAC1D;AACJ;AAEO,SAASE,8BAA8BL,OAAgB;IAC1D,MAAMM,SAASN,QAAQ,SAAS,CAACF,gCAAgC;QAC7D,iBAAiB;IACrB;IAEA,IAAI,CAACQ,QAAQ;QACT,MAAM,IAAIC,MAAM;IACpB;IAEA,OAAOD;AACX"}
@@ -1,11 +1,11 @@
1
1
  export interface EnvironmentVariables {
2
2
  }
3
3
  export type EnvironmentVariableKey = keyof EnvironmentVariables;
4
- export type EnvironmentVariableValue = EnvironmentVariables[keyof EnvironmentVariables];
4
+ export declare function typedEntries<T extends object>(obj: T): Array<[keyof T, T[keyof T]]>;
5
5
  export declare class EnvironmentVariablesRegistry {
6
6
  #private;
7
- add(key: EnvironmentVariableKey, value: EnvironmentVariableValue): void;
7
+ add<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]): void;
8
8
  addVariables(variables: Partial<EnvironmentVariables>): void;
9
- getVariable(key: EnvironmentVariableKey): never;
9
+ getVariable<T extends EnvironmentVariableKey>(key: T): EnvironmentVariables[T];
10
10
  getVariables(): EnvironmentVariables;
11
11
  }
@@ -4,6 +4,9 @@ import memoize, { memoizeClear } from "memoize";
4
4
 
5
5
  ;// CONCATENATED MODULE: ./src/EnvironmentVariablesRegistry.ts
6
6
 
7
+ function typedEntries(obj) {
8
+ return Object.entries(obj);
9
+ }
7
10
  class EnvironmentVariablesRegistry {
8
11
  #variables = new Map();
9
12
  // Since the "getVariables" function is transforming the variables from a Map to an Object, the result of
@@ -23,8 +26,10 @@ class EnvironmentVariablesRegistry {
23
26
  addVariables(variables) {
24
27
  // Do not clear the "getVariables" memoize result if there are no variables.
25
28
  if (Object.keys(variables).length > 0) {
26
- for (const [key, value] of Object.entries(variables)){
27
- this.add(key, value);
29
+ for (const [key, value] of typedEntries(variables)){
30
+ if (value) {
31
+ this.add(key, value);
32
+ }
28
33
  }
29
34
  memoizeClear(this.#memoizedGetVariables);
30
35
  }
@@ -41,6 +46,6 @@ class EnvironmentVariablesRegistry {
41
46
  }
42
47
  }
43
48
 
44
- export { EnvironmentVariablesRegistry };
49
+ export { EnvironmentVariablesRegistry, typedEntries };
45
50
 
46
51
  //# sourceMappingURL=EnvironmentVariablesRegistry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentVariablesRegistry.js","sources":["../src/EnvironmentVariablesRegistry.ts"],"sourcesContent":["import memoize, { memoizeClear } from \"memoize\";\n\n// The \"EnvironmentVariables\" interface is expected to be extended by 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 EnvironmentVariableKey = keyof EnvironmentVariables;\nexport type EnvironmentVariableValue = EnvironmentVariables[keyof EnvironmentVariables];\n\nexport class EnvironmentVariablesRegistry {\n readonly #variables = new Map<EnvironmentVariableKey, EnvironmentVariableValue>();\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: EnvironmentVariableKey, value: EnvironmentVariableValue) {\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 EnvironmentVariableKey, value as EnvironmentVariableValue);\n }\n\n memoizeClear(this.#memoizedGetVariables);\n }\n }\n\n getVariable(key: EnvironmentVariableKey) {\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,MAAwD;IAElF,yGAAyG;IACzG,8GAA8G;IACrG,qBAAqB,GAAGH,OAAOA,CAAC,IAAMI,OAAO,WAAW,CAAC,IAAI,CAAC,UAAU,GAAsC;IAEvH,IAAIC,GAA2B,EAAEC,KAA+B,EAAE;QAC9D,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,YAAYA,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,KAA+BC;YAC5C;YAEAL,YAAYA,CAAC,IAAI,CAAC,qBAAqB;QAC3C;IACJ;IAEA,YAAYI,GAA2B,EAAE;QACrC,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"}
1
+ {"version":3,"file":"EnvironmentVariablesRegistry.js","sources":["../src/EnvironmentVariablesRegistry.ts"],"sourcesContent":["import memoize, { memoizeClear } from \"memoize\";\n\n// The \"EnvironmentVariables\" interface is expected to be extended by the consumer application.\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 EnvironmentVariableKey = keyof EnvironmentVariables;\n\nexport function typedEntries<T extends object>(obj: T) {\n return Object.entries(obj) as Array<[keyof T, T[keyof T]]>;\n}\n\nexport class EnvironmentVariablesRegistry {\n readonly #variables = new Map<EnvironmentVariableKey, unknown>();\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<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]) {\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 typedEntries(variables)) {\n if (value) {\n this.add(key, value);\n }\n }\n\n memoizeClear(this.#memoizedGetVariables);\n }\n }\n\n getVariable<T extends EnvironmentVariableKey>(key: T) {\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 as EnvironmentVariables[T];\n }\n\n getVariables() {\n return this.#memoizedGetVariables();\n }\n}\n"],"names":["memoize","memoizeClear","typedEntries","obj","Object","EnvironmentVariablesRegistry","Map","key","value","existingValue","Error","variables"],"mappings":";;;;;AAAgD;AASzC,SAASE,aAA+BC,GAAM;IACjD,OAAOC,OAAO,OAAO,CAACD;AAC1B;AAEO,MAAME;IACA,UAAU,GAAG,IAAIC,MAAuC;IAEjE,yGAAyG;IACzG,8GAA8G;IACrG,qBAAqB,GAAGN,OAAOA,CAAC,IAAMI,OAAO,WAAW,CAAC,IAAI,CAAC,UAAU,GAAsC;IAEvH,IAAsCG,GAAM,EAAEC,KAA8B,EAAE;QAC1E,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;YAEzBP,YAAYA,CAAC,IAAI,CAAC,qBAAqB;QAC3C;IACJ;IAEA,aAAaU,SAAwC,EAAE;QACnD,4EAA4E;QAC5E,IAAIP,OAAO,IAAI,CAACO,WAAW,MAAM,GAAG,GAAG;YACnC,KAAK,MAAM,CAACJ,KAAKC,MAAM,IAAIN,aAAaS,WAAY;gBAChD,IAAIH,OAAO;oBACP,IAAI,CAAC,GAAG,CAACD,KAAKC;gBAClB;YACJ;YAEAP,YAAYA,CAAC,IAAI,CAAC,qBAAqB;QAC3C;IACJ;IAEA,YAA8CM,GAAM,EAAE;QAClD,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,3 +1,3 @@
1
1
  export { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin, type EnvironmentVariablesPluginOptions } from "./EnvironmentVariablesPlugin.ts";
2
- export type { EnvironmentVariableKey, EnvironmentVariableValue, EnvironmentVariables } from "./EnvironmentVariablesRegistry.ts";
2
+ export type { EnvironmentVariableKey, EnvironmentVariables } from "./EnvironmentVariablesRegistry.ts";
3
3
  export { useEnvironmentVariable, useEnvironmentVariables } from "./useEnvironmentVariable.ts";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin, type EnvironmentVariablesPluginOptions } from \"./EnvironmentVariablesPlugin.ts\";\nexport type { EnvironmentVariableKey, EnvironmentVariableValue, EnvironmentVariables } from \"./EnvironmentVariablesRegistry.ts\";\nexport { useEnvironmentVariable, useEnvironmentVariables } from \"./useEnvironmentVariable.ts\";\n\n"],"names":["EnvironmentVariablesPlugin","EnvironmentVariablesPluginName","getEnvironmentVariablesPlugin","useEnvironmentVariable","useEnvironmentVariables"],"mappings":";;;;;;;;AAAoL;AAEtF"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin, type EnvironmentVariablesPluginOptions } from \"./EnvironmentVariablesPlugin.ts\";\nexport type { EnvironmentVariableKey, EnvironmentVariables } from \"./EnvironmentVariablesRegistry.ts\";\nexport { useEnvironmentVariable, useEnvironmentVariables } from \"./useEnvironmentVariable.ts\";\n\n"],"names":["EnvironmentVariablesPlugin","EnvironmentVariablesPluginName","getEnvironmentVariablesPlugin","useEnvironmentVariable","useEnvironmentVariables"],"mappings":";;;;;;;;AAAoL;AAEtF"}
@@ -1,3 +1,3 @@
1
1
  import type { EnvironmentVariableKey } from "./EnvironmentVariablesRegistry.ts";
2
- export declare function useEnvironmentVariable(key: EnvironmentVariableKey): never;
2
+ export declare function useEnvironmentVariable<T extends EnvironmentVariableKey>(key: T): import("./EnvironmentVariablesRegistry.ts").EnvironmentVariables[T];
3
3
  export declare function useEnvironmentVariables(): import("./EnvironmentVariablesRegistry.ts").EnvironmentVariables;
@@ -1 +1 @@
1
- {"version":3,"file":"useEnvironmentVariable.js","sources":["../src/useEnvironmentVariable.ts"],"sourcesContent":["import { useRuntime } from \"@squide/core\";\nimport { getEnvironmentVariablesPlugin } from \"./EnvironmentVariablesPlugin.ts\";\nimport type { EnvironmentVariableKey } from \"./EnvironmentVariablesRegistry.ts\";\n\nexport function useEnvironmentVariable(key: EnvironmentVariableKey) {\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,GAA2B;IAC9D,MAAMC,UAAUJ,UAAUA;IAC1B,MAAMK,SAASJ,6BAA6BA,CAACG;IAE7C,OAAOC,OAAO,WAAW,CAACF;AAC9B;AAEO,SAASG;IACZ,MAAMF,UAAUJ,UAAUA;IAC1B,MAAMK,SAASJ,6BAA6BA,CAACG;IAE7C,OAAOC,OAAO,YAAY;AAC9B"}
1
+ {"version":3,"file":"useEnvironmentVariable.js","sources":["../src/useEnvironmentVariable.ts"],"sourcesContent":["import { useRuntime } from \"@squide/core\";\nimport { getEnvironmentVariablesPlugin } from \"./EnvironmentVariablesPlugin.ts\";\nimport type { EnvironmentVariableKey } from \"./EnvironmentVariablesRegistry.ts\";\n\nexport function useEnvironmentVariable<T extends EnvironmentVariableKey>(key: T) {\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,uBAAyDC,GAAM;IAC3E,MAAMC,UAAUJ,UAAUA;IAC1B,MAAMK,SAASJ,6BAA6BA,CAACG;IAE7C,OAAOC,OAAO,WAAW,CAACF;AAC9B;AAEO,SAASG;IACZ,MAAMF,UAAUJ,UAAUA;IAC1B,MAAMK,SAASJ,6BAA6BA,CAACG;IAE7C,OAAOC,OAAO,YAAY;AAC9B"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@squide/env-vars",
3
3
  "author": "Workleap",
4
- "version": "1.4.9",
4
+ "version": "1.4.10",
5
5
  "description": "Add support for environment variables to @squide application shell.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -32,23 +32,23 @@
32
32
  "dependencies": {
33
33
  "@workleap/logging": "^1.3.2",
34
34
  "memoize": "^10.2.0",
35
- "@squide/core": "6.1.6"
35
+ "@squide/core": "6.1.7"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@eslint/js": "9.39.1",
39
- "@rsbuild/core": "1.6.9",
40
- "@rslib/core": "0.18.2",
39
+ "@rsbuild/core": "1.6.14",
40
+ "@rslib/core": "0.18.4",
41
41
  "@types/react": "19.2.7",
42
- "@typescript-eslint/parser": "8.48.0",
43
- "@vitejs/plugin-react": "5.1.1",
44
- "@workleap/eslint-configs": "1.1.5",
42
+ "@typescript-eslint/parser": "8.49.0",
43
+ "@vitejs/plugin-react": "5.1.2",
44
+ "@workleap/eslint-configs": "1.1.6",
45
45
  "@workleap/rslib-configs": "1.1.3",
46
46
  "@workleap/typescript-configs": "3.0.7",
47
47
  "eslint": "9.39.1",
48
- "happy-dom": "20.0.10",
48
+ "happy-dom": "20.0.11",
49
49
  "typescript": "5.9.3",
50
- "typescript-eslint": "8.48.0",
51
- "vitest": "4.0.14"
50
+ "typescript-eslint": "8.49.0",
51
+ "vitest": "4.0.15"
52
52
  },
53
53
  "sideEffects": false,
54
54
  "scripts": {
@@ -1,5 +1,5 @@
1
- import { isNil, Plugin, type Runtime } from "@squide/core";
2
- import { EnvironmentVariablesRegistry, type EnvironmentVariableKey, type EnvironmentVariables, type EnvironmentVariableValue } from "./EnvironmentVariablesRegistry.ts";
1
+ import { Plugin, type Runtime } from "@squide/core";
2
+ import { EnvironmentVariablesRegistry, type EnvironmentVariableKey, type EnvironmentVariables } from "./EnvironmentVariablesRegistry.ts";
3
3
 
4
4
  export const EnvironmentVariablesPluginName = "env-vars-plugin";
5
5
 
@@ -22,7 +22,7 @@ export class EnvironmentVariablesPlugin extends Plugin {
22
22
  }
23
23
  }
24
24
 
25
- registerVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue) {
25
+ registerVariable<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]) {
26
26
  this.#environmentVariablesRegistry.add(key, value);
27
27
 
28
28
  this._runtime.logger.debug(`[squide] An environment variable for key "${key}" has been registered with the value "${value}".`);
@@ -37,7 +37,7 @@ export class EnvironmentVariablesPlugin extends Plugin {
37
37
  .debug();
38
38
  }
39
39
 
40
- getVariable(key: EnvironmentVariableKey) {
40
+ getVariable<T extends EnvironmentVariableKey>(key: T) {
41
41
  return this.#environmentVariablesRegistry.getVariable(key);
42
42
  }
43
43
 
@@ -47,11 +47,13 @@ export class EnvironmentVariablesPlugin extends Plugin {
47
47
  }
48
48
 
49
49
  export function getEnvironmentVariablesPlugin(runtime: Runtime) {
50
- const plugin = runtime.getPlugin(EnvironmentVariablesPluginName);
50
+ const plugin = runtime.getPlugin(EnvironmentVariablesPluginName, {
51
+ throwOnNotFound: false
52
+ }) as EnvironmentVariablesPlugin;
51
53
 
52
- if (isNil(plugin)) {
53
- throw new Error("[squide] The getEnvironmentVariablesPlugin function is called but no EnvironmentVariablesPlugin instance has been registered with the runtime.");
54
+ if (!plugin) {
55
+ throw new Error("[squide] The getEnvironmentVariablesPlugin function is called but no EnvironmentVariablesPlugin instance has been registered with the runtime. Did you provide a EnvironmentVariablesPlugin instance to the runtime instance?");
54
56
  }
55
57
 
56
- return plugin as EnvironmentVariablesPlugin;
58
+ return plugin;
57
59
  }
@@ -1,21 +1,24 @@
1
1
  import memoize, { memoizeClear } from "memoize";
2
2
 
3
- // The "EnvironmentVariables" interface is expected to be extended by modules adding their own environment variables to the runtime.
3
+ // The "EnvironmentVariables" interface is expected to be extended by the consumer application.
4
4
  // This magic is called module augmentation: https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation.
5
5
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
6
6
  export interface EnvironmentVariables {}
7
7
 
8
8
  export type EnvironmentVariableKey = keyof EnvironmentVariables;
9
- export type EnvironmentVariableValue = EnvironmentVariables[keyof EnvironmentVariables];
9
+
10
+ export function typedEntries<T extends object>(obj: T) {
11
+ return Object.entries(obj) as Array<[keyof T, T[keyof T]]>;
12
+ }
10
13
 
11
14
  export class EnvironmentVariablesRegistry {
12
- readonly #variables = new Map<EnvironmentVariableKey, EnvironmentVariableValue>();
15
+ readonly #variables = new Map<EnvironmentVariableKey, unknown>();
13
16
 
14
17
  // Since the "getVariables" function is transforming the variables from a Map to an Object, the result of
15
18
  // the transformation is memoized to ensure the returned Object is immutable and can be use in React closures.
16
19
  readonly #memoizedGetVariables = memoize(() => Object.fromEntries(this.#variables) as unknown as EnvironmentVariables);
17
20
 
18
- add(key: EnvironmentVariableKey, value: EnvironmentVariableValue) {
21
+ add<T extends EnvironmentVariableKey>(key: T, value: EnvironmentVariables[T]) {
19
22
  if (this.#variables.has(key)) {
20
23
  const existingValue = this.#variables.get(key);
21
24
 
@@ -32,22 +35,24 @@ export class EnvironmentVariablesRegistry {
32
35
  addVariables(variables: Partial<EnvironmentVariables>) {
33
36
  // Do not clear the "getVariables" memoize result if there are no variables.
34
37
  if (Object.keys(variables).length > 0) {
35
- for (const [key, value] of Object.entries(variables)) {
36
- this.add(key as EnvironmentVariableKey, value as EnvironmentVariableValue);
38
+ for (const [key, value] of typedEntries(variables)) {
39
+ if (value) {
40
+ this.add(key, value);
41
+ }
37
42
  }
38
43
 
39
44
  memoizeClear(this.#memoizedGetVariables);
40
45
  }
41
46
  }
42
47
 
43
- getVariable(key: EnvironmentVariableKey) {
48
+ getVariable<T extends EnvironmentVariableKey>(key: T) {
44
49
  const value = this.#variables.get(key);
45
50
 
46
51
  if (!value) {
47
52
  throw new Error(`[squide] No environment variable has been registered for the key "${key}".`);
48
53
  }
49
54
 
50
- return value;
55
+ return value as EnvironmentVariables[T];
51
56
  }
52
57
 
53
58
  getVariables() {
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin, type EnvironmentVariablesPluginOptions } from "./EnvironmentVariablesPlugin.ts";
2
- export type { EnvironmentVariableKey, EnvironmentVariableValue, EnvironmentVariables } from "./EnvironmentVariablesRegistry.ts";
2
+ export type { EnvironmentVariableKey, EnvironmentVariables } from "./EnvironmentVariablesRegistry.ts";
3
3
  export { useEnvironmentVariable, useEnvironmentVariables } from "./useEnvironmentVariable.ts";
4
4
 
@@ -2,7 +2,7 @@ import { useRuntime } from "@squide/core";
2
2
  import { getEnvironmentVariablesPlugin } from "./EnvironmentVariablesPlugin.ts";
3
3
  import type { EnvironmentVariableKey } from "./EnvironmentVariablesRegistry.ts";
4
4
 
5
- export function useEnvironmentVariable(key: EnvironmentVariableKey) {
5
+ export function useEnvironmentVariable<T extends EnvironmentVariableKey>(key: T) {
6
6
  const runtime = useRuntime();
7
7
  const plugin = getEnvironmentVariablesPlugin(runtime);
8
8