@adaas/a-concept 0.2.9 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaas/a-concept",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "A-Concept is a framework of the new generation that is tailored to use AI, enabling developers to create AI-powered applications with ease. It provides a structured approach to building, managing, and deploying AI-driven solutions.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/node/index.cjs",
@@ -2,7 +2,7 @@ import { A_TYPES__ContextEnvironment } from "../global/A-Context/A-Context.types
2
2
  import { A_CONCEPT_BASE_ENV } from "./env.base";
3
3
 
4
4
 
5
- export class ENV extends A_CONCEPT_BASE_ENV {
5
+ export class A_CONCEPT_ENV extends A_CONCEPT_BASE_ENV {
6
6
  static get A_CONCEPT_ENVIRONMENT() {
7
7
  return window.__A_CONCEPT_ENVIRONMENT_ENV__?.A_CONCEPT_ENVIRONMENT || super.A_CONCEPT_ENVIRONMENT;
8
8
  }
@@ -21,4 +21,13 @@ export class ENV extends A_CONCEPT_BASE_ENV {
21
21
  static get A_ERROR_DEFAULT_DESCRIPTION() {
22
22
  return window.__A_CONCEPT_ENVIRONMENT_ENV__?.A_ERROR_DEFAULT_DESCRIPTION || super.A_ERROR_DEFAULT_DESCRIPTION;
23
23
  }
24
+ static get(name: string) {
25
+ return window.__A_CONCEPT_ENVIRONMENT_ENV__?.[name] || (this as typeof A_CONCEPT_ENV)[name as keyof typeof A_CONCEPT_ENV];
26
+ }
27
+ static set(name: string, value: string) {
28
+ if (!window.__A_CONCEPT_ENVIRONMENT_ENV__) {
29
+ window.__A_CONCEPT_ENVIRONMENT_ENV__ = {};
30
+ }
31
+ window.__A_CONCEPT_ENVIRONMENT_ENV__[name] = value;
32
+ }
24
33
  };
@@ -2,7 +2,7 @@ import { A_CONSTANTS__DEFAULT_ENV_VARIABLES } from "../constants/env.constants";
2
2
  import { A_TYPES__ContextEnvironment } from "../global/A-Context/A-Context.types";
3
3
  import { A_CONCEPT_BASE_ENV } from "./env.base";
4
4
 
5
- export class ENV extends A_CONCEPT_BASE_ENV {
5
+ export class A_CONCEPT_ENV extends A_CONCEPT_BASE_ENV {
6
6
  // ----------------------------------------------------------
7
7
  // A-Concept Core Environment Variables
8
8
  // ----------------------------------------------------------
@@ -37,8 +37,8 @@ export class ENV extends A_CONCEPT_BASE_ENV {
37
37
  /**
38
38
  * Runtime environment of the application e.g. browser, node
39
39
  */
40
- static get A_CONCEPT_RUNTIME_ENVIRONMENT():A_TYPES__ContextEnvironment {
41
- return 'server';
40
+ static get A_CONCEPT_RUNTIME_ENVIRONMENT(): A_TYPES__ContextEnvironment {
41
+ return 'server';
42
42
  }
43
43
 
44
44
  /**
@@ -46,7 +46,7 @@ export class ENV extends A_CONCEPT_BASE_ENV {
46
46
  * [!] Automatically set by A-Concept when the application starts
47
47
  */
48
48
  static get A_CONCEPT_ROOT_FOLDER() {
49
- return process.env[A_CONSTANTS__DEFAULT_ENV_VARIABLES.A_CONCEPT_ROOT_FOLDER] || super.A_CONCEPT_ROOT_FOLDER;
49
+ return process.env[A_CONSTANTS__DEFAULT_ENV_VARIABLES.A_CONCEPT_ROOT_FOLDER] || process.cwd();
50
50
  }
51
51
 
52
52
  /**
@@ -55,4 +55,12 @@ export class ENV extends A_CONCEPT_BASE_ENV {
55
55
  static get A_ERROR_DEFAULT_DESCRIPTION() {
56
56
  return process.env[A_CONSTANTS__DEFAULT_ENV_VARIABLES.A_ERROR_DEFAULT_DESCRIPTION] || super.A_ERROR_DEFAULT_DESCRIPTION;
57
57
  }
58
+
59
+ static get(name: string) {
60
+ return process.env[name] || (this as A_CONCEPT_ENV)[name as keyof typeof A_CONCEPT_ENV];
61
+ }
62
+
63
+ static set(name: string, value: string): void {
64
+ process.env[name] = value;
65
+ }
58
66
  }
@@ -35,7 +35,7 @@ export class A_CONCEPT_BASE_ENV {
35
35
  /**
36
36
  * Runtime environment of the application e.g. browser, node
37
37
  */
38
- static get A_CONCEPT_RUNTIME_ENVIRONMENT():A_TYPES__ContextEnvironment {
38
+ static get A_CONCEPT_RUNTIME_ENVIRONMENT(): A_TYPES__ContextEnvironment {
39
39
  return "unknown";
40
40
  }
41
41
 
@@ -53,4 +53,24 @@ export class A_CONCEPT_BASE_ENV {
53
53
  static get A_ERROR_DEFAULT_DESCRIPTION() {
54
54
  return "If you see this error please let us know.";
55
55
  }
56
+
57
+ /**
58
+ * Generic getter for environment variables. This allows to access environment variables dynamically by name. It will return undefined if the variable does not exist.
59
+ *
60
+ * @param name
61
+ * @returns
62
+ */
63
+ static get(name: string) {
64
+ return (this as any)[name];
65
+ }
66
+ /**
67
+ * Generic setter for environment variables. This allows to set environment variables dynamically by name.
68
+ *
69
+ * @param name
70
+ * @param value
71
+ */
72
+ static set(name: string, value: string) {
73
+ (this as any)[name] = value;
74
+ }
75
+
56
76
  }
@@ -1,8 +1,15 @@
1
+ import { A_CONSTANTS__DEFAULT_ENV_VARIABLES, A_TYPES__ConceptENVVariables } from "../constants/env.constants";
1
2
  import type { RuntimeEnv } from "./env.base";
2
3
 
4
+
5
+ type EnvVariablesType = {
6
+ [key in keyof typeof A_CONSTANTS__DEFAULT_ENV_VARIABLES]?: string;
7
+ }
8
+
3
9
  declare global {
4
10
  interface Window {
5
- __A_CONCEPT_ENVIRONMENT_ENV__?: Partial<RuntimeEnv> & {
6
- };
11
+ __A_CONCEPT_ENVIRONMENT_ENV__?: {
12
+ [key: string]: string
13
+ } & EnvVariablesType
7
14
  }
8
15
  }
@@ -1 +1 @@
1
- export { ENV } from "./env-browser";
1
+ export { A_CONCEPT_ENV } from "./env-browser";
@@ -1 +1 @@
1
- export { ENV } from "./env-node";
1
+ export { A_CONCEPT_ENV } from "./env-node";
@@ -39,7 +39,7 @@ import { A_CommonHelper } from "@adaas/a-concept/helpers/A_Common.helper";
39
39
  import { A_TYPES__Fragment_Constructor } from "../A-Fragment/A-Fragment.types";
40
40
  import { A_Dependency } from "../A-Dependency/A-Dependency.class";
41
41
  import { A_TYPES__Ctor } from "@adaas/a-concept/types/A_Common.types";
42
- import { ENV } from "@adaas/a-concept/env";
42
+ import { A_CONCEPT_ENV } from "@adaas/a-concept/env";
43
43
 
44
44
 
45
45
 
@@ -53,7 +53,7 @@ export class A_Context {
53
53
  * [!] If environment variable is not set, it will default to 'a-concept'
54
54
  */
55
55
  static get concept() {
56
- return ENV.A_CONCEPT_NAME || 'a-concept';
56
+ return A_CONCEPT_ENV.A_CONCEPT_NAME || 'a-concept';
57
57
  }
58
58
  /**
59
59
  * Root scope of the application from environment variable A_CONCEPT_ROOT_SCOPE
@@ -69,7 +69,7 @@ export class A_Context {
69
69
  * [!] Determined by environment variable A_CONCEPT_RUNTIME_ENVIRONMENT that comes from the build tool or is set manually in the environment.
70
70
  */
71
71
  static get environment(): A_TYPES__ContextEnvironment {
72
- return ENV.A_CONCEPT_RUNTIME_ENVIRONMENT
72
+ return A_CONCEPT_ENV.A_CONCEPT_RUNTIME_ENVIRONMENT
73
73
  }
74
74
 
75
75
  /**
@@ -121,7 +121,7 @@ export class A_Context {
121
121
  * [!] This class should not be instantiated directly. Use A_Context.getInstance() instead.
122
122
  */
123
123
  private constructor() {
124
- const name = String(ENV.A_CONCEPT_ROOT_SCOPE) || 'root';
124
+ const name = String(A_CONCEPT_ENV.A_CONCEPT_ROOT_SCOPE) || 'root';
125
125
 
126
126
  this._root = new A_Scope({ name });
127
127
  }
@@ -1049,7 +1049,7 @@ export class A_Context {
1049
1049
 
1050
1050
  instance._registry = new WeakMap();
1051
1051
 
1052
- const name = String(ENV.A_CONCEPT_ROOT_SCOPE) || 'root';
1052
+ const name = String(A_CONCEPT_ENV.A_CONCEPT_ROOT_SCOPE) || 'root';
1053
1053
 
1054
1054
  instance._root = new A_Scope({ name });
1055
1055
  }
@@ -10,7 +10,7 @@ import { A_FormatterHelper } from '@adaas/a-concept/helpers/A_Formatter.helper';
10
10
  import { A_Context } from '../A-Context/A-Context.class';
11
11
  import { A_TypeGuards } from '@adaas/a-concept/helpers/A_TypeGuards.helper';
12
12
  import { ASEID } from '../ASEID/ASEID.class';
13
- import { ENV } from '@adaas/a-concept/env';
13
+ import { A_CONCEPT_ENV } from '@adaas/a-concept/env';
14
14
 
15
15
 
16
16
  export class A_Error<
@@ -286,7 +286,7 @@ export class A_Error<
286
286
  * [!] Note: This description is intended to provide more context about the error and can be used for debugging or logging purposes
287
287
  */
288
288
  get description(): string {
289
- return this._description || String(ENV.A_ERROR_DEFAULT_DESCRIPTION) || A_CONSTANTS__ERROR_DESCRIPTION;
289
+ return this._description || String(A_CONCEPT_ENV.A_ERROR_DEFAULT_DESCRIPTION) || A_CONSTANTS__ERROR_DESCRIPTION;
290
290
  }
291
291
  /**
292
292
  * Returns the original error if any