@adaas/a-server 0.0.14 → 0.0.15

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.
Files changed (85) hide show
  1. package/.nvmrc +1 -1
  2. package/dist/index.d.ts +4 -4
  3. package/dist/index.js +6 -6
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/components/A-CommandController/A-CommandController.component.d.ts +8 -0
  6. package/dist/src/components/A-CommandController/A-CommandController.component.js +53 -0
  7. package/dist/src/components/A-CommandController/A-CommandController.component.js.map +1 -0
  8. package/dist/src/components/{A_Controller/A_Controller.component.js → A-Controller/A-Controller.component.js} +1 -1
  9. package/dist/src/components/{A_Controller/A_Controller.component.js.map → A-Controller/A-Controller.component.js.map} +1 -1
  10. package/dist/src/components/A-Controller/A-Controller.component.types.js +2 -0
  11. package/dist/src/components/A-Controller/A-Controller.component.types.js.map +1 -0
  12. package/dist/src/components/A-EntityController/A-EntityController.component.js +1 -2
  13. package/dist/src/components/A-EntityController/A-EntityController.component.js.map +1 -1
  14. package/dist/src/components/A-ListingController/A-ListingController.component.d.ts +1 -1
  15. package/dist/src/components/A-ListingController/A-ListingController.component.js.map +1 -1
  16. package/dist/src/components/A-Router/A-Router.component.js +8 -9
  17. package/dist/src/components/A-Router/A-Router.component.js.map +1 -1
  18. package/dist/src/components/A-ServerCORS/A_ServerCORS.component.d.ts +1 -1
  19. package/dist/src/components/A-ServerCORS/A_ServerCORS.component.js +3 -3
  20. package/dist/src/components/A-ServerCORS/A_ServerCORS.component.js.map +1 -1
  21. package/dist/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.d.ts +1 -1
  22. package/dist/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js +1 -1
  23. package/dist/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.js.map +1 -1
  24. package/dist/src/components/A-ServerLogger/A-ServerLogger.constants.d.ts +22 -0
  25. package/dist/src/components/A-ServerLogger/A-ServerLogger.constants.js +31 -0
  26. package/dist/src/components/A-ServerLogger/A-ServerLogger.constants.js.map +1 -0
  27. package/dist/src/components/A-ServerLogger/A_ServerLogger.component.d.ts +2 -2
  28. package/dist/src/components/A-ServerLogger/A_ServerLogger.component.js +6 -6
  29. package/dist/src/components/A-ServerLogger/A_ServerLogger.component.js.map +1 -1
  30. package/dist/src/components/A-ServerLogger/A_ServerLogger.component.types.d.ts +2 -0
  31. package/dist/src/components/A-ServerProxy/A-ServerProxy.component.js +2 -2
  32. package/dist/src/components/A-ServerProxy/A-ServerProxy.component.js.map +1 -1
  33. package/dist/src/components/A-StaticLoader/A-StaticLoader.component.js +2 -2
  34. package/dist/src/components/A-StaticLoader/A-StaticLoader.component.js.map +1 -1
  35. package/dist/src/components/A-StaticLoader/A-StaticLoader.component.types.js +2 -2
  36. package/dist/src/components/A-StaticLoader/A-StaticLoader.component.types.js.map +1 -1
  37. package/dist/src/constants/env.constants.d.ts +10 -0
  38. package/dist/src/constants/env.constants.js +20 -0
  39. package/dist/src/constants/env.constants.js.map +1 -0
  40. package/dist/src/containers/{A-Server/A-Server.container.d.ts → A-Service/A-Service.container.d.ts} +6 -1
  41. package/dist/src/containers/{A-Server/A-Server.container.js → A-Service/A-Service.container.js} +40 -28
  42. package/dist/src/containers/A-Service/A-Service.container.js.map +1 -0
  43. package/dist/src/containers/{A-Server/A-Server.container.types.d.ts → A-Service/A-Service.container.types.d.ts} +3 -1
  44. package/dist/src/containers/{A-Server/A-Server.container.types.js → A-Service/A-Service.container.types.js} +3 -1
  45. package/dist/src/containers/A-Service/A-Service.container.types.js.map +1 -0
  46. package/dist/src/entities/A-Response/A-Response.entity.js.map +1 -1
  47. package/dist/src/entities/A_EntityList/A_EntityList.entity.d.ts +1 -0
  48. package/dist/src/entities/A_EntityList/A_EntityList.entity.js +3 -0
  49. package/dist/src/entities/A_EntityList/A_EntityList.entity.js.map +1 -1
  50. package/examples/microservices-server/components/repositories/Memory.repository.ts +2 -2
  51. package/examples/microservices-server/concept.ts +1 -1
  52. package/examples/simple-server/commands/SignIn.command.ts +10 -0
  53. package/examples/simple-server/concept.ts +10 -5
  54. package/index.ts +4 -4
  55. package/jest.config.ts +1 -1
  56. package/package.json +3 -3
  57. package/src/components/A-CommandController/A-CommandController.component.ts +40 -0
  58. package/src/components/A-EntityController/A-EntityController.component.ts +1 -6
  59. package/src/components/A-ListingController/A-ListingController.component.ts +1 -1
  60. package/src/components/A-Router/A-Router.component.ts +7 -8
  61. package/src/components/A-ServerCORS/A_ServerCORS.component.ts +3 -3
  62. package/src/components/A-ServerHealthMonitor/A-ServerHealthMonitor.component.ts +2 -2
  63. package/src/components/A-ServerLogger/A-ServerLogger.constants.ts +27 -0
  64. package/src/components/A-ServerLogger/A_ServerLogger.component.ts +7 -13
  65. package/src/components/A-ServerLogger/A_ServerLogger.component.types.ts +14 -1
  66. package/src/components/A-ServerProxy/A-ServerProxy.component.ts +1 -1
  67. package/src/components/A-StaticLoader/A-StaticLoader.component.ts +1 -1
  68. package/src/components/A-StaticLoader/A-StaticLoader.component.types.ts +1 -1
  69. package/src/constants/env.constants.ts +26 -0
  70. package/src/containers/{A-Server/A-Server.container.ts → A-Service/A-Service.container.ts} +31 -20
  71. package/src/containers/{A-Server/A-Server.container.types.ts → A-Service/A-Service.container.types.ts} +2 -0
  72. package/src/entities/A-Response/A-Response.entity.ts +0 -2
  73. package/src/entities/A_EntityList/A_EntityList.entity.ts +5 -0
  74. package/tests/A-Service.test.ts +20 -0
  75. package/dist/src/components/A_Controller/A_Controller.component.types.js +0 -2
  76. package/dist/src/components/A_Controller/A_Controller.component.types.js.map +0 -1
  77. package/dist/src/containers/A-Server/A-Server.container.js.map +0 -1
  78. package/dist/src/containers/A-Server/A-Server.container.types.js.map +0 -1
  79. package/tests/app.test.ts +0 -29
  80. package/tests/decorator.test.ts +0 -33
  81. package/tests/default.test.ts +0 -121
  82. /package/dist/src/components/{A_Controller/A_Controller.component.d.ts → A-Controller/A-Controller.component.d.ts} +0 -0
  83. /package/dist/src/components/{A_Controller/A_Controller.component.types.d.ts → A-Controller/A-Controller.component.types.d.ts} +0 -0
  84. /package/src/components/{A_Controller/A_Controller.component.ts → A-Controller/A-Controller.component.ts} +0 -0
  85. /package/src/components/{A_Controller/A_Controller.component.types.ts → A-Controller/A-Controller.component.types.ts} +0 -0
@@ -1,7 +1,7 @@
1
1
  import { A_Component, A_Config, A_Feature, A_Inject } from '@adaas/a-concept';
2
2
  import { A_SERVER_TYPES__CorsConfig } from './A_ServerCORS.component.types';
3
3
  import { A_SERVER_DEFAULTS__CorsConfig } from './A_ServerCORS.component.defaults';
4
- import { A_SERVER_TYPES__ServerFeature } from '@adaas/a-server/containers/A-Server/A-Server.container.types';
4
+ import { A_SERVER_TYPES__ServerFeature } from '@adaas/a-server/containers/A-Service/A-Service.container.types';
5
5
  import { A_Request } from '@adaas/a-server/entities/A-Request/A-Request.entity';
6
6
  import { A_Response } from '@adaas/a-server/entities/A-Response/A-Response.entity';
7
7
 
@@ -14,7 +14,7 @@ export class A_ServerCORS extends A_Component {
14
14
  name: A_SERVER_TYPES__ServerFeature.beforeStart
15
15
  })
16
16
  async init(
17
- @A_Inject(A_Config) config: A_Config<'ORIGIN' | 'METHODS' | 'HEADERS' | 'CREDENTIALS' | 'MAX_AGE'>,
17
+ @A_Inject(A_Config) config: A_Config<['ORIGIN', 'METHODS', 'HEADERS', 'CREDENTIALS', 'MAX_AGE']>,
18
18
  ) {
19
19
  this.config = {
20
20
  origin: config.get('ORIGIN') || A_SERVER_DEFAULTS__CorsConfig.origin,
@@ -27,7 +27,7 @@ export class A_ServerCORS extends A_Component {
27
27
 
28
28
 
29
29
  @A_Feature.Extend({
30
- name: A_SERVER_TYPES__ServerFeature.onRequest
30
+ name: A_SERVER_TYPES__ServerFeature.beforeRequest
31
31
  })
32
32
  public apply(
33
33
  @A_Inject(A_Request) aReq: A_Request,
@@ -18,12 +18,12 @@ export class A_ServerHealthMonitor extends A_Component {
18
18
  version: 'v1',
19
19
  })
20
20
  async get(
21
- @A_Inject(A_Config) config: A_Config<'VERSION_PATH' | 'EXPOSED_PROPERTIES'>,
21
+ @A_Inject(A_Config) config: A_Config<['VERSION_PATH', 'EXPOSED_PROPERTIES']>,
22
22
  @A_Inject(A_Request) request: A_Request,
23
23
  @A_Inject(A_Response) response: A_Response,
24
24
  @A_Inject(A_Logger) logger: A_Logger
25
25
  ): Promise<any> {
26
- const packageJSON = await import(`${config.get('CONCEPT_ROOT_FOLDER')}/package.json`);
26
+ const packageJSON = await import(`${config.get('A_CONCEPT_ROOT_FOLDER')}/package.json`);
27
27
  const exposedProperties: Array<string> = config.get('EXPOSED_PROPERTIES')?.split(',') || [
28
28
  'name',
29
29
  'version',
@@ -0,0 +1,27 @@
1
+ export const A_SERVER__A_SERVER_LOGGER_ENV_VARIABLES = {
2
+ // ----------------------------------------------------------
3
+ // A-ServerLogger Environment Variables
4
+ // ----------------------------------------------------------
5
+ // These environment variables are used by A-Concept core to configure the application
6
+ // ----------------------------------------------------------
7
+ /**
8
+ * Enable logging of 200 responses
9
+ */
10
+ SERVER_IGNORE_LOG_200: 'SERVER_IGNORE_LOG_200',
11
+ /**
12
+ * Enable logging of 404 responses
13
+ */
14
+ SERVER_IGNORE_LOG_404: 'SERVER_IGNORE_LOG_404',
15
+ /**
16
+ * Enable logging of 500 responses
17
+ */
18
+ SERVER_IGNORE_LOG_500: 'SERVER_IGNORE_LOG_500',
19
+ /**
20
+ * Enable logging of 400 responses
21
+ */
22
+ SERVER_IGNORE_LOG_400: 'SERVER_IGNORE_LOG_400',
23
+ /**
24
+ * Enable logging of default responses
25
+ */
26
+ SERVER_IGNORE_LOG_DEFAULT: 'SERVER_IGNORE_LOG_DEFAULT',
27
+ } as const
@@ -1,25 +1,19 @@
1
1
  import { A_Config, A_Feature, A_Inject, A_Logger, A_Scope } from "@adaas/a-concept";
2
- import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Server/A-Server.container.types";
2
+ import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Service/A-Service.container.types";
3
3
  import { A_Server } from "@adaas/a-server/context/A-Server/A_Server.context";
4
- import { A_SERVER_TYPES__ServerLoggerRouteParams } from "./A_ServerLogger.component.types";
5
- import { A_ServerContainer } from "@adaas/a-server/containers/A-Server/A-Server.container";
4
+ import { A_SERVER_TYPES__ServerLoggerEnvVariables, A_SERVER_TYPES__ServerLoggerRouteParams } from "./A_ServerLogger.component.types";
5
+ import { A_Service } from "@adaas/a-server/containers/A-Service/A-Service.container";
6
6
  import { A_Request } from "@adaas/a-server/entities/A-Request/A-Request.entity";
7
7
  import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entity";
8
8
  import { A_SERVER_TYPES__ResponseEvent } from "@adaas/a-server/entities/A-Response/A-Response.entity.types";
9
9
  import { A_Route } from "@adaas/a-server/entities/A-Route/A-Route.entity";
10
10
  import { A_SERVER_TYPES__RequestEvent } from "@adaas/a-server/entities/A-Request/A-Request.entity.types";
11
+ import { A_TYPES__ConceptENVVariables } from "@adaas/a-concept/dist/src/constants/env.constants";
11
12
 
12
13
 
13
14
  export class A_ServerLogger extends A_Logger {
14
15
 
15
- protected config!: A_Config<
16
- 'DEV_MODE'
17
- | 'SERVER_IGNORE_LOG_200'
18
- | 'SERVER_IGNORE_LOG_404'
19
- | 'SERVER_IGNORE_LOG_500'
20
- | 'SERVER_IGNORE_LOG_400'
21
- | 'SERVER_IGNORE_LOG_DEFAULT'
22
- >
16
+ protected config!: A_Config<A_SERVER_TYPES__ServerLoggerEnvVariables>
23
17
 
24
18
 
25
19
 
@@ -53,7 +47,7 @@ export class A_ServerLogger extends A_Logger {
53
47
  @A_Feature.Define({ invoke: false })
54
48
  @A_Feature.Extend({
55
49
  name: A_SERVER_TYPES__ServerFeature.afterStart,
56
- scope: [A_ServerContainer]
50
+ scope: [A_Service]
57
51
  })
58
52
  logStart(
59
53
  @A_Inject(A_Server) server: A_Server,
@@ -72,7 +66,7 @@ export class A_ServerLogger extends A_Logger {
72
66
 
73
67
  @A_Feature.Extend({
74
68
  name: A_SERVER_TYPES__ServerFeature.afterStop,
75
- scope: [A_ServerContainer]
69
+ scope: [A_Service]
76
70
  })
77
71
  logStop(
78
72
  @A_Inject(A_Server) server: A_Server,
@@ -1,3 +1,4 @@
1
+ import { A_TYPES__ConceptENVVariables } from "@adaas/a-concept/dist/src/constants/env.constants"
1
2
 
2
3
 
3
4
  export type A_SERVER_TYPES__ServerLoggerRouteParams = {
@@ -5,4 +6,16 @@ export type A_SERVER_TYPES__ServerLoggerRouteParams = {
5
6
  url: string,
6
7
  status: number,
7
8
  responseTime: number
8
- }
9
+ }
10
+
11
+
12
+ export type A_SERVER_TYPES__ServerLoggerEnvVariables = Array<
13
+
14
+ 'SERVER_IGNORE_LOG_200'
15
+ | 'SERVER_IGNORE_LOG_404'
16
+ | 'SERVER_IGNORE_LOG_500'
17
+ | 'SERVER_IGNORE_LOG_400'
18
+ | 'SERVER_IGNORE_LOG_DEFAULT'
19
+
20
+
21
+ > | A_TYPES__ConceptENVVariables
@@ -1,5 +1,5 @@
1
1
  import { A_Component, A_Concept, A_Feature, A_Inject, A_Logger } from "@adaas/a-concept";
2
- import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Server/A-Server.container.types";
2
+ import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Service/A-Service.container.types";
3
3
  import { A_ProxyConfig } from "@adaas/a-server/context/A_ProxyConfig/A_ProxyConfig.context";
4
4
  import { A_Request } from "@adaas/a-server/entities/A-Request/A-Request.entity";
5
5
  import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entity";
@@ -4,7 +4,7 @@ import path from "path";
4
4
  import { URL } from "url";
5
5
  import { A_Request } from "@adaas/a-server/entities/A-Request/A-Request.entity";
6
6
  import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entity";
7
- import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Server/A-Server.container.types";
7
+ import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Service/A-Service.container.types";
8
8
  import { A_Route } from "@adaas/a-server/entities/A-Route/A-Route.entity";
9
9
  import { A_StaticConfig } from "@adaas/a-server/context/A-StaticConfig/A-StaticConfig.context";
10
10
 
@@ -5,7 +5,7 @@ import path from "path";
5
5
  import { URL } from "url";
6
6
  import { A_Request } from "@adaas/a-server/entities/A-Request/A-Request.entity";
7
7
  import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entity";
8
- import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Server/A-Server.container.types";
8
+ import { A_SERVER_TYPES__ServerFeature } from "@adaas/a-server/containers/A-Service/A-Service.container.types";
9
9
  import { A_Route } from "@adaas/a-server/entities/A-Route/A-Route.entity";
10
10
 
11
11
 
@@ -0,0 +1,26 @@
1
+ export const A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES = {
2
+ // ----------------------------------------------------------
3
+ // A-Server Environment Variables
4
+ // ----------------------------------------------------------
5
+ // These environment variables are used by A-Server to configure the application
6
+ // ----------------------------------------------------------
7
+ /**
8
+ * Port for the server to listen on
9
+ * [!] Default is 3000
10
+ * @default 3000
11
+ */
12
+ A_SERVER_PORT: 'A_SERVER_PORT',
13
+
14
+ } as const;
15
+
16
+ export type A_TYPES__ServerENVVariables = (typeof A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES)[keyof typeof A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES][];
17
+
18
+
19
+
20
+ export const A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY = [
21
+ A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES.A_SERVER_PORT,
22
+ ] as const;
23
+
24
+
25
+
26
+
@@ -1,15 +1,21 @@
1
1
  import { A_Concept, A_Config, A_Container, A_Context, A_Errors, A_Feature, A_Inject, A_Logger, A_Scope, A_TYPES__ComponentMetaKey, } from "@adaas/a-concept";
2
2
  import { createServer, IncomingMessage, Server, ServerResponse } from "http";
3
- import { A_SERVER_TYPES__ServerFeature, A_SERVER_TYPES__ServerFeatures } from "./A-Server.container.types";
3
+ import { A_SERVER_TYPES__ServerFeature, A_SERVER_TYPES__ServerFeatures } from "./A-Service.container.types";
4
4
  import { A_Server } from "@adaas/a-server/context/A-Server/A_Server.context";
5
5
  import { A_Request } from "@adaas/a-server/entities/A-Request/A-Request.entity";
6
6
  import { A_Response } from "@adaas/a-server/entities/A-Response/A-Response.entity";
7
7
  import crypto from 'crypto';
8
+ import { A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY, A_TYPES__ServerENVVariables } from "@adaas/a-server/constants/env.constants";
8
9
 
9
10
 
10
11
 
11
12
 
12
- export class A_ServerContainer extends A_Container {
13
+ /**
14
+ * A-Service is a container that can run different types of services, such as HTTP servers, workers, etc.
15
+ * Depending on the provided config and configuration, it will load the necessary components and start the service.
16
+ *
17
+ */
18
+ export class A_Service extends A_Container {
13
19
 
14
20
  private server!: Server;
15
21
  private port: number = 3000;
@@ -22,25 +28,35 @@ export class A_ServerContainer extends A_Container {
22
28
  this.Scope.register(errorsRegistry);
23
29
  }
24
30
 
31
+ let config: A_Config<A_TYPES__ServerENVVariables>;
32
+ let aServer: A_Server;
25
33
 
26
-
27
- if (!this.Scope.has(A_Config)) {
28
- const config = new A_Config({
29
- variables: ['DEV_MODE', 'CONFIG_VERBOSE', 'PORT'],
34
+ if (!this.Scope.has(A_Config<A_TYPES__ServerENVVariables>)) {
35
+ const config = new A_Config<A_TYPES__ServerENVVariables>({
36
+ variables: [...Array.from(A_SERVER_CONSTANTS__DEFAULT_ENV_VARIABLES_ARRAY)],
30
37
  defaults: {
31
- DEV_MODE: true,
32
- CONFIG_VERBOSE: true,
33
- PORT: 3000
38
+ A_SERVER_PORT: 3000
34
39
  }
35
40
  });
36
41
 
37
42
  this.Scope.register(config);
38
43
  }
39
44
 
40
- const config = this.Scope.resolve(A_Config);
45
+ config = this.Scope.resolve(A_Config) as A_Config<A_TYPES__ServerENVVariables>;
46
+
47
+
48
+ if (!this.Scope.has(A_Server)) {
49
+ aServer = new A_Server({
50
+ port: config.get('A_SERVER_PORT'),
51
+ name: this.name,
52
+ version: 'v1'
53
+ });
54
+ }
55
+
56
+
41
57
 
42
58
  // Set the server to listen on port 3000
43
- const port = config.get('PORT') || 3000;
59
+ const port = config.get('A_SERVER_PORT');
44
60
 
45
61
  // Create the HTTP server
46
62
  this.server = createServer(this.onRequest.bind(this));
@@ -52,14 +68,6 @@ export class A_ServerContainer extends A_Container {
52
68
  });
53
69
 
54
70
  this.Scope.register(newServer);
55
-
56
-
57
-
58
-
59
-
60
- // } else {
61
- // this.server = existedServer;
62
- // }
63
71
  }
64
72
 
65
73
  protected listen(): Promise<void> {
@@ -102,7 +110,7 @@ export class A_ServerContainer extends A_Container {
102
110
 
103
111
  @A_Concept.Stop()
104
112
  /**
105
- * Stop the server
113
+ * Stop service
106
114
  */
107
115
  async stop() {
108
116
  await this.call(A_SERVER_TYPES__ServerFeature.beforeStop);
@@ -134,11 +142,14 @@ export class A_ServerContainer extends A_Container {
134
142
  entities: [req, res],
135
143
  });
136
144
 
145
+ await this.call(A_SERVER_TYPES__ServerFeature.beforeRequest, scope);
137
146
  await this.call(A_SERVER_TYPES__ServerFeature.onRequest, scope);
147
+ await this.call(A_SERVER_TYPES__ServerFeature.afterRequest, scope);
138
148
 
139
149
  await res.status(200).send();
140
150
 
141
151
  } catch (error) {
152
+
142
153
  return res.failed(error);
143
154
  }
144
155
  }
@@ -14,7 +14,9 @@ export enum A_SERVER_TYPES__ServerFeature {
14
14
  afterStart = 'afterStart',
15
15
  beforeStop = 'beforeStop',
16
16
  afterStop = 'afterStop',
17
+ beforeRequest = 'beforeRequest',
17
18
  onRequest = 'onRequest',
19
+ afterRequest = 'afterRequest',
18
20
  }
19
21
 
20
22
 
@@ -112,8 +112,6 @@ export class A_Response<
112
112
  }
113
113
 
114
114
  try {
115
-
116
-
117
115
  switch (true) {
118
116
  case !!data && typeof data === 'object':
119
117
  return this.json(data);
@@ -22,6 +22,11 @@ export class A_EntityList<
22
22
  A_SERVER_TYPES__A_EntityListConstructor,
23
23
  A_SERVER_TYPES__A_EntityListSerialized
24
24
  > {
25
+
26
+ static get scope(): string {
27
+ return 'a-server';
28
+ }
29
+
25
30
  protected _entityConstructor!: new (...args: ConstructorParameters<typeof A_Entity>) => EntityType;
26
31
  protected _items: Array<EntityType> = [];
27
32
  protected _pagination: A_SERVER_TYPES__A_EntityListPagination = {
@@ -0,0 +1,20 @@
1
+ import { A_Service } from '@adaas/a-server/containers/A-Service/A-Service.container';
2
+ import { A_Server } from '@adaas/a-server/context/A-Server/A_Server.context';
3
+
4
+ jest.retryTimes(0);
5
+
6
+
7
+ describe('A-Server Tests', () => {
8
+ it('Should be possible to create a server Container', async () => {
9
+ const server1 = new A_Service({
10
+ name: 'test-server-1'
11
+ });
12
+
13
+ await server1.load();
14
+
15
+ expect(server1.name).toBe('test-server-1');
16
+ expect(server1.Scope.resolve(A_Server)).toBeInstanceOf(A_Server);
17
+ expect(server1.Scope.resolve(A_Server).port).toBe(3000);
18
+ });
19
+
20
+ });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=A_Controller.component.types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"A_Controller.component.types.js","sourceRoot":"","sources":["../../../../src/components/A_Controller/A_Controller.component.types.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"A-Server.container.js","sourceRoot":"","sources":["../../../../src/containers/A-Server/A-Server.container.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,gDAA6J;AAC7J,+BAA6E;AAC7E,yEAA2G;AAC3G,wFAA6E;AAC7E,0FAAgF;AAChF,6FAAmF;AACnF,oDAA4B;AAK5B,MAAa,iBAAkB,SAAQ,uBAAW;IAAlD;;QAGY,SAAI,GAAW,IAAI,CAAC;IA0KhC,CAAC;IAvKS,IAAI;;YACN,IAAI,CAAC,IAAI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AI,WAAW,EAAE,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAGK,UAAU;8DAAK,CAAC;KAAA;IAGhB,SAAS;8DAAK,CAAC;KAAA;CACxB;AA7KD,8CA6KC;AAvKS;IADL,qBAAS,CAAC,IAAI,EAAE;6CA8ChB;AAuBK;IAJL,qBAAS,CAAC,KAAK,EAAE;IAClB;;OAEG;8CAOF;AAIK;IADL,qBAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;oDACZ;AAGjB;IADL,qBAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;mDACb;AAQhB;IAJL,qBAAS,CAAC,IAAI,EAAE;IACjB;;OAEG;6CAOF;AAWK;IAPL,qBAAS,CAAC,MAAM,CAAC;QACd,IAAI,EAAE,wDAA6B,CAAC,SAAS;QAC7C,MAAM,EAAE,KAAK;KAChB,CAAC;IACF;;OAEG;kDAqBF;AAqCK;IADL,qBAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;mDACb;AAGhB;IADL,qBAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;kDACd"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"A-Server.container.types.js","sourceRoot":"","sources":["../../../../src/containers/A-Server/A-Server.container.types.ts"],"names":[],"mappings":";;;AAWA,IAAY,6BAMX;AAND,WAAY,6BAA6B;IACrC,4DAA2B,CAAA;IAC3B,0DAAyB,CAAA;IACzB,0DAAyB,CAAA;IACzB,wDAAuB,CAAA;IACvB,wDAAuB,CAAA;AAC3B,CAAC,EANW,6BAA6B,6CAA7B,6BAA6B,QAMxC;AAaD,IAAY,4BAWX;AAXD,WAAY,4BAA4B;IACpC,2CAAW,CAAA;IACX,6CAAa,CAAA;IACb,2CAAW,CAAA;IACX,iDAAiB,CAAA;IACjB,+CAAe,CAAA;IACf,mDAAmB,CAAA;IACnB,6CAAa,CAAA;IACb,mDAAmB,CAAA;IACnB,+CAAe,CAAA;IACf,mDAAmB,CAAA;AACvB,CAAC,EAXW,4BAA4B,4CAA5B,4BAA4B,QAWvC"}
package/tests/app.test.ts DELETED
@@ -1,29 +0,0 @@
1
- import { A_ARC_MaskQueryBuilder } from '@adaas/a-arc';
2
- import { A_EXPRESS_App } from '@adaas/a-sdk/global/A_EXPRESS_App.class';
3
- import { config } from 'dotenv';
4
- config();
5
- jest.retryTimes(0);
6
-
7
-
8
- describe('App', () => {
9
- it('Should create an app', async () => {
10
- const app = new A_EXPRESS_App({
11
- app: {
12
- name: 'test',
13
- },
14
- context: {
15
- namespace: 'test',
16
- errors: []
17
- },
18
- routes: [
19
- {
20
- version: 'v1',
21
- controllers: []
22
- }
23
- ],
24
- });
25
-
26
- await app.start();
27
- });
28
-
29
- });
@@ -1,33 +0,0 @@
1
- // import { config } from 'dotenv';
2
- // config();
3
- // jest.retryTimes(0);
4
- // import { A_EXPRESS_EntityController } from '@adaas/a-sdk/global/A_EXPRESS_EntityController.class';
5
- // import { A_EXPRESS_TYPES__EntityControllerConfig } from '@adaas/a-sdk/types/A_EXPRESS_EntityController.types';
6
- // import { A_EXPRESS_ValidateAccess } from '../src/decorators/ValidateAccess.decorator';
7
- // import { A_SDK_TYPES__Required, A_SDK_TYPES__Dictionary } from '@adaas/a-sdk-types';
8
-
9
- // describe('Decorators', () => {
10
- // it('Should create decorator', async () => {
11
-
12
- // class Test extends A_EXPRESS_EntityController {
13
-
14
- // protected CONTROLLER_CONFIG: A_SDK_TYPES__Required<Partial<A_EXPRESS_TYPES__EntityControllerConfig<A_SDK_TYPES__Dictionary<any>>>, ['entity']> = {
15
- // entity: 'users',
16
- // };
17
-
18
- // @A_EXPRESS_ValidateAccess<Test>((qb, self, req) => {
19
- // return qb;
20
- // })
21
- // async test() {
22
- // return 'test';
23
- // }
24
- // }
25
-
26
-
27
- // const foo = new Test();
28
-
29
- // await foo.test();
30
-
31
- // });
32
-
33
- // });
@@ -1,121 +0,0 @@
1
- import { config } from 'dotenv';
2
- config();
3
- jest.retryTimes(0);
4
- import { A_EXPRESS_Access } from '../src/decorators/A_EXPRESS_Access.decorator';
5
- import { A_SDK_Error } from '@adaas/a-sdk-types';
6
- import { createServer } from 'http';
7
- import express from 'express';
8
- import axios from 'axios';
9
- import { A_EXPRESS_Context } from '@adaas/a-sdk/global/A_EXPRESS_Context.class';
10
- import { A_EXPRESS_TYPES__INextFunction, A_EXPRESS_TYPES__IRequest } from '@adaas/a-sdk/types/A_EXPRESS_Controller.types';
11
- import { A_EXPRESS_Routes } from '@adaas/a-sdk/decorators/A_EXPRESS_Routes.decorator';
12
- import { A_EXPRESS_TYPES__SERVER_COMMANDS_IResponse } from '@adaas/a-sdk/types/A_EXPRESS_ServerCommandsController.types';
13
- import { A_EXPRESS_Controller, A_EXPRESS_ServerDelegate } from '@adaas/a-sdk/decorators/A_EXPRESS_Controller.decorator';
14
- import { A_EXPRESS_Get } from '@adaas/a-sdk/decorators/A_EXPRESS_Methods.decorator';
15
-
16
- describe('Defaults', () => {
17
- it('Should Assign Router', async () => {
18
-
19
- try {
20
-
21
- @A_EXPRESS_Controller()
22
- class Test {
23
-
24
- @A_EXPRESS_Get({
25
- path: '/test',
26
- config: {
27
- identity: false,
28
- auth: false
29
- }
30
- })
31
- @A_EXPRESS_Access<Test, A_EXPRESS_TYPES__IRequest, ['default', 'test']>({
32
- acl: {
33
- default: (qb, self, req) => {
34
- return qb.action('read');
35
- },
36
- test: (qb, self, req) => {
37
- return qb.action('test');
38
- }
39
- }
40
- })
41
- async test(req: any, res: any, next: any) {
42
- console.log('test')
43
-
44
- return res.status(200).send({
45
- message: 'test'
46
- });
47
- }
48
- }
49
-
50
- const app = express();
51
-
52
- app.use(A_EXPRESS_Routes([Test]));
53
-
54
- const port = 3000;
55
-
56
- (async () => {
57
- const server = createServer(app);
58
-
59
- await server.listen(
60
- port,
61
- () => console.info(`Server running on port ${port}`)
62
- );
63
- })();
64
-
65
-
66
- const resp = await axios.get(`http://localhost:${port}/test`);
67
-
68
- console.log(resp.data);
69
-
70
- } catch (error) {
71
- A_EXPRESS_Context.Logger.error(new A_SDK_Error(error));
72
- }
73
- });
74
-
75
-
76
- it('Should Assign Router', async () => {
77
-
78
- try {
79
- type foo = ({
80
- magic: string;
81
- } & {
82
- id: string;
83
- }) | ({
84
- aseid: string;
85
- } & { scope: string });
86
-
87
-
88
-
89
- @A_EXPRESS_ServerDelegate('users', (() => { }) as any, {
90
- id: 'ID',
91
- auth: {
92
- enable: true,
93
- },
94
- get: {
95
- where: async (self, req) => ({ id: parseInt(req.params.id) })
96
- }
97
- })
98
- class Test {
99
- async post(
100
- req: A_EXPRESS_TYPES__IRequest<foo>,
101
- res: A_EXPRESS_TYPES__SERVER_COMMANDS_IResponse,
102
- next: A_EXPRESS_TYPES__INextFunction
103
- ) {
104
- const body = req.body;
105
-
106
- if ('aseid' in body) {
107
- console.log(body.aseid)
108
- }
109
- }
110
-
111
- }
112
-
113
- }
114
- catch (error) {
115
- A_EXPRESS_Context.Logger.error(new A_SDK_Error(error));
116
- }
117
-
118
- })
119
-
120
-
121
- });