@squide/env-vars 1.4.7 → 1.4.8

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.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#342](https://github.com/workleap/wl-squide/pull/342) [`3be4070`](https://github.com/workleap/wl-squide/commit/3be4070d2d647804903b5cc01113e20d5d71cb11) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Minor fine tuning following v16 release.
8
+
9
+ - Updated dependencies [[`3be4070`](https://github.com/workleap/wl-squide/commit/3be4070d2d647804903b5cc01113e20d5d71cb11)]:
10
+ - @squide/core@6.1.5
11
+
3
12
  ## 1.4.7
4
13
 
5
14
  ### Patch Changes
@@ -1,15 +1,15 @@
1
1
  import { Plugin, type Runtime } from "@squide/core";
2
- import { type EnvironmentVariables, type EnvironmentVariablesRegistryKey, type EnvironmentVariablesRegistryValue } from "./EnvironmentVariablesRegistry.ts";
2
+ import { type EnvironmentVariableKey, type EnvironmentVariables, type EnvironmentVariableValue } from "./EnvironmentVariablesRegistry.ts";
3
3
  export declare const EnvironmentVariablesPluginName = "env-vars-plugin";
4
4
  export interface EnvironmentVariablesPluginOptions {
5
- environmentVariables?: Partial<EnvironmentVariables>;
5
+ variables?: Partial<EnvironmentVariables>;
6
6
  }
7
7
  export declare class EnvironmentVariablesPlugin extends Plugin {
8
8
  #private;
9
9
  constructor(runtime: Runtime, options?: EnvironmentVariablesPluginOptions);
10
- registerVariable(key: EnvironmentVariablesRegistryKey, value: EnvironmentVariablesRegistryValue): void;
10
+ registerVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue): void;
11
11
  registerVariables(variables: Partial<EnvironmentVariables>): void;
12
- getVariable(key: EnvironmentVariablesRegistryKey): never;
12
+ getVariable(key: EnvironmentVariableKey): never;
13
13
  getVariables(): EnvironmentVariables;
14
14
  }
15
15
  export declare function getEnvironmentVariablesPlugin(runtime: Runtime): EnvironmentVariablesPlugin;
@@ -13,9 +13,9 @@ class EnvironmentVariablesPlugin extends Plugin {
13
13
  #environmentVariablesRegistry = new EnvironmentVariablesRegistry();
14
14
  constructor(runtime, options = {}){
15
15
  super(EnvironmentVariablesPluginName, runtime);
16
- const { environmentVariables } = options;
17
- if (environmentVariables) {
18
- this.#environmentVariablesRegistry.addVariables(environmentVariables);
16
+ const { variables } = options;
17
+ if (variables) {
18
+ this.#environmentVariablesRegistry.addVariables(variables);
19
19
  }
20
20
  }
21
21
  registerVariable(key, value) {
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentVariablesPlugin.js","sources":["../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 interface EnvironmentVariablesPluginOptions {\n environmentVariables?: 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 environmentVariables\n } = options;\n\n if (environmentVariables) {\n this.#environmentVariablesRegistry.addVariables(environmentVariables);\n }\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\n .withText(\"[squide] The following environment variables has been registered:\")\n .withObject(variables)\n .debug();\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","options","environmentVariables","key","value","variables","getEnvironmentVariablesPlugin","plugin","Error"],"mappings":";;;;;;;;AAA2D;AAC+H;AAEnL,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,oBAAoB,EACvB,GAAGD;QAEJ,IAAIC,sBAAsB;YACtB,IAAI,CAAC,6BAA6B,CAAC,YAAY,CAACA;QACpD;IACJ;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,CACf,QAAQ,CAAC,qEACT,UAAU,CAACA,WACX,KAAK;IACd;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,8BAA8BN,OAAgB;IAC1D,MAAMO,SAASP,QAAQ,SAAS,CAACF;IAEjC,IAAIH,KAAKA,CAACY,SAAS;QACf,MAAM,IAAIC,MAAM;IACpB;IAEA,OAAOD;AACX"}
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,11 +1,11 @@
1
1
  export interface EnvironmentVariables {
2
2
  }
3
- export type EnvironmentVariablesRegistryKey = keyof EnvironmentVariables;
4
- export type EnvironmentVariablesRegistryValue = EnvironmentVariables[keyof EnvironmentVariables];
3
+ export type EnvironmentVariableKey = keyof EnvironmentVariables;
4
+ export type EnvironmentVariableValue = EnvironmentVariables[keyof EnvironmentVariables];
5
5
  export declare class EnvironmentVariablesRegistry {
6
6
  #private;
7
- add(key: EnvironmentVariablesRegistryKey, value: EnvironmentVariablesRegistryValue): void;
7
+ add(key: EnvironmentVariableKey, value: EnvironmentVariableValue): void;
8
8
  addVariables(variables: Partial<EnvironmentVariables>): void;
9
- getVariable(key: EnvironmentVariablesRegistryKey): never;
9
+ getVariable(key: EnvironmentVariableKey): never;
10
10
  getVariables(): EnvironmentVariables;
11
11
  }
@@ -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 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,OAAOA,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,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,KAAwCC;YACrD;YAEAL,YAAYA,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"}
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"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./EnvironmentVariablesPlugin.ts";
2
- export type { EnvironmentVariables, EnvironmentVariablesRegistryKey, EnvironmentVariablesRegistryValue } from "./EnvironmentVariablesRegistry.ts";
3
- export * from "./useEnvironmentVariable.ts";
1
+ export { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin, type EnvironmentVariablesPluginOptions } from "./EnvironmentVariablesPlugin.ts";
2
+ export type { EnvironmentVariableKey, EnvironmentVariableValue, EnvironmentVariables } from "./EnvironmentVariablesRegistry.ts";
3
+ export { useEnvironmentVariable, useEnvironmentVariables } from "./useEnvironmentVariable.ts";
package/dist/index.js CHANGED
@@ -1,9 +1,14 @@
1
- export * from "./EnvironmentVariablesPlugin.js";
2
- export * from "./useEnvironmentVariable.js";
1
+ import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin } from "./EnvironmentVariablesPlugin.js";
2
+ import { useEnvironmentVariable, useEnvironmentVariables } from "./useEnvironmentVariable.js";
3
+
4
+ ;// CONCATENATED MODULE: external "./EnvironmentVariablesPlugin.js"
5
+
6
+ ;// CONCATENATED MODULE: external "./useEnvironmentVariable.js"
3
7
 
4
8
  ;// CONCATENATED MODULE: ./src/index.ts
5
9
 
6
10
 
7
11
 
12
+ export { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin, useEnvironmentVariable, useEnvironmentVariables };
8
13
 
9
14
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../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
+ {"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,3 +1,3 @@
1
- import type { EnvironmentVariablesRegistryKey } from "./EnvironmentVariablesRegistry.ts";
2
- export declare function useEnvironmentVariable(key: EnvironmentVariablesRegistryKey): never;
1
+ import type { EnvironmentVariableKey } from "./EnvironmentVariablesRegistry.ts";
2
+ export declare function useEnvironmentVariable(key: EnvironmentVariableKey): never;
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 { 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,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(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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@squide/env-vars",
3
3
  "author": "Workleap",
4
- "version": "1.4.7",
4
+ "version": "1.4.8",
5
5
  "description": "Add support for environment variables to @squide application shell.",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@workleap/logging": "^1.3.2",
34
34
  "memoize": "^10.2.0",
35
- "@squide/core": "6.1.4"
35
+ "@squide/core": "6.1.5"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@eslint/js": "9.39.1",
@@ -1,10 +1,10 @@
1
1
  import { isNil, Plugin, type Runtime } from "@squide/core";
2
- import { type EnvironmentVariables, EnvironmentVariablesRegistry, type EnvironmentVariablesRegistryKey, type EnvironmentVariablesRegistryValue } from "./EnvironmentVariablesRegistry.ts";
2
+ import { EnvironmentVariablesRegistry, type EnvironmentVariableKey, type EnvironmentVariables, type EnvironmentVariableValue } from "./EnvironmentVariablesRegistry.ts";
3
3
 
4
4
  export const EnvironmentVariablesPluginName = "env-vars-plugin";
5
5
 
6
6
  export interface EnvironmentVariablesPluginOptions {
7
- environmentVariables?: Partial<EnvironmentVariables>;
7
+ variables?: Partial<EnvironmentVariables>;
8
8
  }
9
9
 
10
10
  export class EnvironmentVariablesPlugin extends Plugin {
@@ -14,15 +14,15 @@ export class EnvironmentVariablesPlugin extends Plugin {
14
14
  super(EnvironmentVariablesPluginName, runtime);
15
15
 
16
16
  const {
17
- environmentVariables
17
+ variables
18
18
  } = options;
19
19
 
20
- if (environmentVariables) {
21
- this.#environmentVariablesRegistry.addVariables(environmentVariables);
20
+ if (variables) {
21
+ this.#environmentVariablesRegistry.addVariables(variables);
22
22
  }
23
23
  }
24
24
 
25
- registerVariable(key: EnvironmentVariablesRegistryKey, value: EnvironmentVariablesRegistryValue) {
25
+ registerVariable(key: EnvironmentVariableKey, value: EnvironmentVariableValue) {
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: EnvironmentVariablesRegistryKey) {
40
+ getVariable(key: EnvironmentVariableKey) {
41
41
  return this.#environmentVariablesRegistry.getVariable(key);
42
42
  }
43
43
 
@@ -1,21 +1,21 @@
1
1
  import memoize, { memoizeClear } from "memoize";
2
2
 
3
- // The "EnvironmentVariables" interface is expected to be extended by remote modules adding their own environment variables to the runtime.
3
+ // The "EnvironmentVariables" interface is expected to be extended by modules adding their own environment variables to the runtime.
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
- export type EnvironmentVariablesRegistryKey = keyof EnvironmentVariables;
9
- export type EnvironmentVariablesRegistryValue = EnvironmentVariables[keyof EnvironmentVariables];
8
+ export type EnvironmentVariableKey = keyof EnvironmentVariables;
9
+ export type EnvironmentVariableValue = EnvironmentVariables[keyof EnvironmentVariables];
10
10
 
11
11
  export class EnvironmentVariablesRegistry {
12
- readonly #variables = new Map<EnvironmentVariablesRegistryKey, EnvironmentVariablesRegistryValue>();
12
+ readonly #variables = new Map<EnvironmentVariableKey, EnvironmentVariableValue>();
13
13
 
14
14
  // Since the "getVariables" function is transforming the variables from a Map to an Object, the result of
15
15
  // the transformation is memoized to ensure the returned Object is immutable and can be use in React closures.
16
16
  readonly #memoizedGetVariables = memoize(() => Object.fromEntries(this.#variables) as unknown as EnvironmentVariables);
17
17
 
18
- add(key: EnvironmentVariablesRegistryKey, value: EnvironmentVariablesRegistryValue) {
18
+ add(key: EnvironmentVariableKey, value: EnvironmentVariableValue) {
19
19
  if (this.#variables.has(key)) {
20
20
  const existingValue = this.#variables.get(key);
21
21
 
@@ -33,14 +33,14 @@ export class EnvironmentVariablesRegistry {
33
33
  // Do not clear the "getVariables" memoize result if there are no variables.
34
34
  if (Object.keys(variables).length > 0) {
35
35
  for (const [key, value] of Object.entries(variables)) {
36
- this.add(key as EnvironmentVariablesRegistryKey, value as EnvironmentVariablesRegistryValue);
36
+ this.add(key as EnvironmentVariableKey, value as EnvironmentVariableValue);
37
37
  }
38
38
 
39
39
  memoizeClear(this.#memoizedGetVariables);
40
40
  }
41
41
  }
42
42
 
43
- getVariable(key: EnvironmentVariablesRegistryKey) {
43
+ getVariable(key: EnvironmentVariableKey) {
44
44
  const value = this.#variables.get(key);
45
45
 
46
46
  if (!value) {
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./EnvironmentVariablesPlugin.ts";
2
- export type { EnvironmentVariables, EnvironmentVariablesRegistryKey, EnvironmentVariablesRegistryValue } from "./EnvironmentVariablesRegistry.ts";
3
- export * from "./useEnvironmentVariable.ts";
1
+ export { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName, getEnvironmentVariablesPlugin, type EnvironmentVariablesPluginOptions } from "./EnvironmentVariablesPlugin.ts";
2
+ export type { EnvironmentVariableKey, EnvironmentVariableValue, EnvironmentVariables } from "./EnvironmentVariablesRegistry.ts";
3
+ export { useEnvironmentVariable, useEnvironmentVariables } from "./useEnvironmentVariable.ts";
4
4
 
@@ -1,8 +1,8 @@
1
1
  import { useRuntime } from "@squide/core";
2
2
  import { getEnvironmentVariablesPlugin } from "./EnvironmentVariablesPlugin.ts";
3
- import type { EnvironmentVariablesRegistryKey } from "./EnvironmentVariablesRegistry.ts";
3
+ import type { EnvironmentVariableKey } from "./EnvironmentVariablesRegistry.ts";
4
4
 
5
- export function useEnvironmentVariable(key: EnvironmentVariablesRegistryKey) {
5
+ export function useEnvironmentVariable(key: EnvironmentVariableKey) {
6
6
  const runtime = useRuntime();
7
7
  const plugin = getEnvironmentVariablesPlugin(runtime);
8
8