nesoi 3.1.7 → 3.2.1

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 (58) hide show
  1. package/lib/compiler/apps/distributed/distributed_compiler.d.ts +31 -0
  2. package/lib/compiler/apps/distributed/distributed_compiler.js +121 -0
  3. package/lib/compiler/apps/distributed/stages/1_mkdir_stage.d.ts +15 -0
  4. package/lib/compiler/apps/distributed/stages/1_mkdir_stage.js +96 -0
  5. package/lib/compiler/apps/distributed/stages/2_build_typescript_stage.d.ts +15 -0
  6. package/lib/compiler/apps/distributed/stages/2_build_typescript_stage.js +174 -0
  7. package/lib/compiler/apps/distributed/stages/3_copy_types_stage.d.ts +15 -0
  8. package/lib/compiler/apps/distributed/stages/3_copy_types_stage.js +82 -0
  9. package/lib/compiler/apps/distributed/stages/4_dump_modules_stage.d.ts +16 -0
  10. package/lib/compiler/apps/distributed/stages/4_dump_modules_stage.js +182 -0
  11. package/lib/compiler/apps/distributed/stages/5_copy_static_stage.d.ts +0 -0
  12. package/lib/compiler/apps/distributed/stages/5_copy_static_stage.js +31 -0
  13. package/lib/compiler/apps/distributed/stages/6_dump_cli_stage.d.ts +0 -0
  14. package/lib/compiler/apps/distributed/stages/6_dump_cli_stage.js +34 -0
  15. package/lib/compiler/apps/distributed/stages/7_dump_package_json_stage.d.ts +0 -0
  16. package/lib/compiler/apps/distributed/stages/7_dump_package_json_stage.js +45 -0
  17. package/lib/compiler/elements/element.js +2 -2
  18. package/lib/compiler/index.d.ts +1 -0
  19. package/lib/compiler/index.js +3 -1
  20. package/lib/elements/blocks/block.builder.d.ts +1 -0
  21. package/lib/elements/blocks/block.builder.js +16 -1
  22. package/lib/elements/blocks/block.schema.d.ts +4 -1
  23. package/lib/elements/blocks/job/job.builder.d.ts +1 -0
  24. package/lib/elements/blocks/job/job.builder.js +2 -1
  25. package/lib/elements/entities/bucket/bucket.d.ts +2 -2
  26. package/lib/elements/entities/bucket/bucket.js +30 -16
  27. package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +1 -1
  28. package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +1 -0
  29. package/lib/engine/apps/app.config.d.ts +24 -30
  30. package/lib/engine/apps/app.config.js +11 -21
  31. package/lib/engine/apps/app.d.ts +6 -5
  32. package/lib/engine/apps/app.js +1 -1
  33. package/lib/engine/apps/distributed/distributed.app.config.d.ts +44 -0
  34. package/lib/engine/apps/distributed/distributed.app.config.js +36 -0
  35. package/lib/engine/apps/distributed/distributed.app.d.ts +30 -0
  36. package/lib/engine/apps/distributed/distributed.app.js +52 -0
  37. package/lib/engine/apps/distributed/distributed_node.app.d.ts +67 -0
  38. package/lib/engine/apps/distributed/distributed_node.app.js +191 -0
  39. package/lib/engine/apps/distributed/elements/distributed_job.d.ts +7 -0
  40. package/lib/engine/apps/distributed/elements/distributed_job.js +11 -0
  41. package/lib/engine/apps/distributed/inc/inc.client.d.ts +17 -0
  42. package/lib/engine/apps/distributed/inc/inc.client.js +105 -0
  43. package/lib/engine/apps/distributed/inc/inc.server.d.ts +19 -0
  44. package/lib/engine/apps/distributed/inc/inc.server.js +174 -0
  45. package/lib/engine/apps/distributed/inc/test.d.ts +1 -0
  46. package/lib/engine/apps/distributed/inc/test.js +24 -0
  47. package/lib/engine/apps/inline.app.d.ts +7 -2
  48. package/lib/engine/apps/inline.app.js +18 -2
  49. package/lib/engine/apps/monolyth/monolyth.app.d.ts +2 -2
  50. package/lib/engine/apps/monolyth/monolyth.app.js +1 -1
  51. package/lib/engine/module.d.ts +11 -1
  52. package/lib/engine/module.js +17 -4
  53. package/lib/engine/util/crypto.d.ts +4 -13
  54. package/lib/engine/util/crypto.js +26 -37
  55. package/lib/engine/util/log.d.ts +1 -1
  56. package/lib/engine/util/log.js +2 -0
  57. package/package.json +1 -1
  58. package/tsconfig.build.tsbuildinfo +1 -1
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.INCClient = void 0;
37
+ const net = __importStar(require("net"));
38
+ const log_1 = require("../../../util/log");
39
+ class INCClient {
40
+ constructor(config) {
41
+ this.config = config;
42
+ this.client = new net.Socket();
43
+ this.client.setEncoding('utf8');
44
+ this.client.on('data', this.onData.bind(this));
45
+ }
46
+ start() {
47
+ log_1.Log.info('inc.client', this.config.name, 'Starting...');
48
+ return new Promise((resolve, reject) => {
49
+ this.client.connect({
50
+ host: this.config.server.host,
51
+ port: this.config.server.port
52
+ });
53
+ const errorFn = (error) => {
54
+ log_1.Log.error('inc.server', this.config.name, error.toString(), error);
55
+ reject(error);
56
+ };
57
+ this.client.on('error', errorFn);
58
+ this.client.on('connect', () => {
59
+ const address = this.client.address();
60
+ log_1.Log.debug('inc.client', this.config.name, 'Connected', {
61
+ server: `${this.client.remoteAddress}:${this.client.remotePort}`,
62
+ client: `${address.address}:${address.port}`
63
+ });
64
+ this.client.off('error', errorFn);
65
+ this.client.on('error', this.onError.bind(this));
66
+ resolve();
67
+ });
68
+ });
69
+ }
70
+ stop() {
71
+ log_1.Log.info('inc.client', this.config.name, 'Stop');
72
+ return new Promise((resolve) => {
73
+ this.client.end('Bye bye server', () => {
74
+ resolve();
75
+ });
76
+ });
77
+ }
78
+ send(data) {
79
+ log_1.Log.debug('inc.client', this.config.name, 'Sending data', {
80
+ data
81
+ });
82
+ return new Promise((resolve, reject) => {
83
+ this.client.write(data, error => {
84
+ if (error) {
85
+ reject(error);
86
+ }
87
+ else {
88
+ resolve();
89
+ }
90
+ });
91
+ });
92
+ }
93
+ // Callbacks
94
+ onError(error) {
95
+ log_1.Log.error('inc.client', this.config.name, error.toString(), {
96
+ error
97
+ });
98
+ }
99
+ onData(data) {
100
+ log_1.Log.debug('inc.client', this.config.name, 'Data received', {
101
+ data
102
+ });
103
+ }
104
+ }
105
+ exports.INCClient = INCClient;
@@ -0,0 +1,19 @@
1
+ import * as net from 'net';
2
+ export type INCServerConfig = {
3
+ name: string;
4
+ port: number;
5
+ maxConnections?: number;
6
+ };
7
+ export declare class INCServer {
8
+ config: INCServerConfig;
9
+ private server;
10
+ clients: Record<string, net.Socket>;
11
+ constructor(config: INCServerConfig);
12
+ start(): Promise<void>;
13
+ stop(): Promise<void>;
14
+ send(client: string, data: string | Buffer): Promise<void>;
15
+ private getClientCount;
16
+ private onError;
17
+ private onClose;
18
+ private onConnection;
19
+ }
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.INCServer = void 0;
37
+ const crypto_1 = require("crypto");
38
+ const net = __importStar(require("net"));
39
+ const log_1 = require("../../../util/log");
40
+ class INCServer {
41
+ constructor(config) {
42
+ this.config = config;
43
+ this.clients = {};
44
+ this.server = net.createServer();
45
+ this.server.on('close', this.onClose.bind(this));
46
+ this.server.on('connection', this.onConnection.bind(this));
47
+ this.server.maxConnections = this.config.maxConnections || 1;
48
+ }
49
+ start() {
50
+ log_1.Log.info('inc.server', this.config.name, 'Starting...');
51
+ return new Promise((resolve, reject) => {
52
+ this.server.listen(this.config.port);
53
+ const errorFn = (error) => {
54
+ log_1.Log.error('inc.server', this.config.name, error.toString(), error);
55
+ reject(error);
56
+ };
57
+ this.server.on('error', errorFn);
58
+ this.server.on('listening', () => {
59
+ log_1.Log.info('inc.server', this.config.name, `Listening on port ${this.config.port}`);
60
+ this.server.off('error', errorFn);
61
+ this.server.on('error', this.onError.bind(this));
62
+ resolve();
63
+ });
64
+ if (!this.server.listening) {
65
+ throw new Error('Failed to start INC server');
66
+ }
67
+ });
68
+ }
69
+ stop() {
70
+ log_1.Log.info('inc.server', this.config.name, 'Stop');
71
+ return new Promise((resolve) => {
72
+ this.server.close(() => {
73
+ resolve();
74
+ });
75
+ });
76
+ }
77
+ send(client, data) {
78
+ log_1.Log.debug('inc.server', this.config.name, 'Sending data', {
79
+ data
80
+ });
81
+ return new Promise((resolve, reject) => {
82
+ this.clients[client].write(data, error => {
83
+ if (error) {
84
+ reject(error);
85
+ }
86
+ else {
87
+ resolve();
88
+ }
89
+ });
90
+ });
91
+ }
92
+ // Utils
93
+ getClientCount() {
94
+ return new Promise((resolve, reject) => {
95
+ this.server.getConnections(function (error, count) {
96
+ if (error) {
97
+ reject(error);
98
+ }
99
+ resolve(count);
100
+ });
101
+ });
102
+ }
103
+ // Callbacks
104
+ onError(error) {
105
+ log_1.Log.error('inc.server', this.config.name, error.toString(), error);
106
+ }
107
+ onClose() {
108
+ log_1.Log.warn('inc.server', this.config.name, 'Closed');
109
+ }
110
+ async onConnection(socket) {
111
+ const id = (0, crypto_1.randomUUID)();
112
+ socket.id = id;
113
+ this.clients[id] = socket;
114
+ const serverAddress = this.server.address();
115
+ log_1.Log.debug('inc.server', this.config.name, 'New client connected', {
116
+ id,
117
+ server: `${serverAddress.address}:${serverAddress.port}`,
118
+ client: `${socket.remoteAddress}:${socket.remotePort}`,
119
+ clientCount: await this.getClientCount()
120
+ });
121
+ socket.setEncoding('utf8');
122
+ socket.setTimeout(1000 * 60 * 15); // 15 mins
123
+ socket.on('data', (data) => {
124
+ log_1.Log.debug('inc.server', this.config.name, 'Data received', {
125
+ client: socket.id,
126
+ data
127
+ });
128
+ });
129
+ socket.on('drain', function () {
130
+ socket.resume();
131
+ });
132
+ socket.on('error', (error) => {
133
+ delete this.clients[id];
134
+ log_1.Log.error('inc.server', this.config.name, 'Client error', {
135
+ client: socket.id,
136
+ error
137
+ });
138
+ });
139
+ socket.on('timeout', () => {
140
+ delete this.clients[id];
141
+ log_1.Log.warn('inc.server', this.config.name, 'Client timed-out', {
142
+ client: socket.id
143
+ });
144
+ socket.end('{"$":"__inc.timed_out"}');
145
+ });
146
+ socket.on('end', (data) => {
147
+ delete this.clients[id];
148
+ log_1.Log.debug('inc.server', this.config.name, 'Client disconnected', {
149
+ client: socket.id,
150
+ bytes_read: socket.bytesRead,
151
+ bytes_written: socket.bytesWritten,
152
+ data
153
+ });
154
+ });
155
+ socket.on('close', (error) => {
156
+ delete this.clients[id];
157
+ if (error) {
158
+ log_1.Log.error('inc.server', this.config.name, 'Client disconnected with error', {
159
+ client: socket.id,
160
+ bytes_read: socket.bytesRead,
161
+ bytes_written: socket.bytesWritten,
162
+ error
163
+ });
164
+ return;
165
+ }
166
+ log_1.Log.debug('inc.server', this.config.name, 'Client disconnected', {
167
+ client: socket.id,
168
+ bytes_read: socket.bytesRead,
169
+ bytes_written: socket.bytesWritten
170
+ });
171
+ });
172
+ }
173
+ }
174
+ exports.INCServer = INCServer;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const inc_server_1 = require("./inc.server");
4
+ const inc_client_1 = require("./inc.client");
5
+ const log_1 = require("../../../util/log");
6
+ log_1.Log.level = 'debug';
7
+ async function main() {
8
+ const server = new inc_server_1.INCServer({
9
+ name: 'mandala-alpha-1',
10
+ port: 2222
11
+ });
12
+ await server.start();
13
+ const client = new inc_client_1.INCClient({
14
+ name: 'mandala-beta-2',
15
+ server: {
16
+ host: 'localhost',
17
+ port: 2222
18
+ }
19
+ });
20
+ await client.start();
21
+ await client.send('Oi do cliente!');
22
+ await server.send(Object.keys(server.clients)[0], 'Oi do servidor!');
23
+ }
24
+ main();
@@ -4,7 +4,7 @@ import { IService } from './service';
4
4
  import { AnyTrxEngine } from '../transaction/trx_engine';
5
5
  import { AnyBuilder, AnyModule, Module } from '../module';
6
6
  import { AnyDaemon, Daemon } from '../daemon';
7
- import { AppConfigFactory } from './app.config';
7
+ import { AppConfigBuilder } from './app.config';
8
8
  /**
9
9
  * @category App
10
10
  */
@@ -38,9 +38,14 @@ export declare class InlineApp<S extends $Space, ModuleNames extends string = Mo
38
38
  * TODO: allow overriding this behavior with adapters
39
39
  */
40
40
  protected linkExternals(modules: Record<string, Module<S, $Module>>): void;
41
+ /**
42
+ * This method injects values from environment variables into each module's
43
+ * app constants.
44
+ */
45
+ protected linkAppValues(modules: Record<string, Module<S, $Module>>): void;
41
46
  modules<M extends ModuleName<S>>(modules: M[]): InlineApp<S, M & ModuleNames>;
42
47
  service<T extends IService>($: T): InlineApp<S, ModuleNames, Services & { [K in T["name"]]: T; }>;
43
- get config(): AppConfigFactory<S, ModuleNames, Services, typeof this>;
48
+ get config(): AppConfigBuilder<S, ModuleNames, Services, typeof this>;
44
49
  static package(app: InlineApp<any, any>, scripts: Record<string, string>, dependencies: Record<string, string>): {
45
50
  name: string;
46
51
  version: string;
@@ -73,7 +73,7 @@ class InlineApp extends app_1.App {
73
73
  for (const m in modules) {
74
74
  const module = modules[m];
75
75
  module.start(this, services);
76
- const trxConfig = this._config.trxEngine?.[m];
76
+ const trxConfig = this._config.modules?.[m]?.trx;
77
77
  const authn = {};
78
78
  for (const a in this._config?.authn || {}) {
79
79
  const prov = this._config.authn?.[a]?.();
@@ -85,6 +85,8 @@ class InlineApp extends app_1.App {
85
85
  }
86
86
  log_1.Log.debug('app', this.name, 'Linking externals');
87
87
  this.linkExternals(modules);
88
+ log_1.Log.debug('app', this.name, 'Linking app values');
89
+ this.linkAppValues(modules);
88
90
  return {
89
91
  modules,
90
92
  services,
@@ -132,6 +134,20 @@ class InlineApp extends app_1.App {
132
134
  });
133
135
  });
134
136
  }
137
+ /**
138
+ * This method injects values from environment variables into each module's
139
+ * app constants.
140
+ */
141
+ linkAppValues(modules) {
142
+ Object.values(modules).forEach(module => {
143
+ const values = module.schema.constants.values;
144
+ Object.values(values).forEach(value => {
145
+ if (value.scope !== 'app')
146
+ return;
147
+ value.value = process.env[value.key];
148
+ });
149
+ });
150
+ }
135
151
  // Type Builder Overrides
136
152
  modules(modules) {
137
153
  super.modules(modules);
@@ -142,7 +158,7 @@ class InlineApp extends app_1.App {
142
158
  return this;
143
159
  }
144
160
  get config() {
145
- return new app_config_1.AppConfigFactory(this);
161
+ return new app_config_1.AppConfigBuilder(this);
146
162
  }
147
163
  //
148
164
  static package(app, scripts, dependencies) {
@@ -4,7 +4,7 @@ import { InlineApp } from './../inline.app';
4
4
  import { AnyTrxEngine } from '../../transaction/trx_engine';
5
5
  import { Space } from '../../space';
6
6
  import { Daemon } from "../../daemon";
7
- import { AppConfigFactory } from '../app.config';
7
+ import { AppConfigBuilder } from '../app.config';
8
8
  /**
9
9
  * @category App
10
10
  * @subcategory Monolyth
@@ -20,7 +20,7 @@ export declare class MonolythApp<S extends $Space, ModuleNames extends string =
20
20
  remake(): Promise<void>;
21
21
  modules<M extends ModuleName<S>>(modules: M[]): MonolythApp<S, M & ModuleNames>;
22
22
  service<T extends IService>($: T): MonolythApp<S, ModuleNames, Services & { [K in T["name"]]: T; }>;
23
- get config(): AppConfigFactory<S, ModuleNames, Services, typeof this>;
23
+ get config(): AppConfigBuilder<S, ModuleNames, Services, typeof this>;
24
24
  }
25
25
  /**
26
26
  * @category App
@@ -101,7 +101,7 @@ class MonolythApp extends inline_app_1.InlineApp {
101
101
  return this;
102
102
  }
103
103
  get config() {
104
- return new app_config_1.AppConfigFactory(this);
104
+ return new app_config_1.AppConfigBuilder(this);
105
105
  }
106
106
  }
107
107
  exports.MonolythApp = MonolythApp;
@@ -4,7 +4,7 @@ import { AnyMessageBuilder } from "../elements/entities/message/message.builder"
4
4
  import { AnyBucketBuilder } from "../elements/entities/bucket/bucket.builder";
5
5
  import { AnyResourceBuilder } from "../elements/blocks/resource/resource.builder";
6
6
  import { AnyMachineBuilder } from "../elements/blocks/machine/machine.builder";
7
- import { Job } from "../elements/blocks/job/job";
7
+ import { AnyJob, Job } from "../elements/blocks/job/job";
8
8
  import { AnyJobBuilder } from "../elements/blocks/job/job.builder";
9
9
  import { MessageParser } from "../elements/entities/message/message_parser";
10
10
  import { $Message } from "../elements/entities/message/message.schema";
@@ -147,6 +147,16 @@ export declare class Module<S extends $Space, $ extends $Module> {
147
147
  messages?: $Dependency[];
148
148
  machines?: $Dependency[];
149
149
  }): this;
150
+ /**
151
+ * Include references for external elements on the module.
152
+ *
153
+ * @param daemon A `Daemon` instance
154
+ * @param dependencies: A dictionary of dependencies by element type
155
+ * @returns The `Module`, for call-chaining
156
+ */
157
+ injectRunners(elements: {
158
+ jobs?: Record<string, AnyJob>;
159
+ }): this;
150
160
  /**
151
161
  * Recursively find all files inside the module dir.
152
162
  *
@@ -224,6 +224,19 @@ class Module {
224
224
  });
225
225
  return this;
226
226
  }
227
+ /**
228
+ * Include references for external elements on the module.
229
+ *
230
+ * @param daemon A `Daemon` instance
231
+ * @param dependencies: A dictionary of dependencies by element type
232
+ * @returns The `Module`, for call-chaining
233
+ */
234
+ injectRunners(elements) {
235
+ Object.entries(elements.jobs || {}).forEach(([refName, job]) => {
236
+ this.jobs[refName] = job;
237
+ });
238
+ return this;
239
+ }
227
240
  // Treeshaking
228
241
  /**
229
242
  * Recursively find all files inside the module dir.
@@ -348,7 +361,7 @@ class Module {
348
361
  const info = app_1.App.getInfo(app);
349
362
  const config = info.config;
350
363
  Object.entries(this.schema.buckets).forEach(([name, schema]) => {
351
- const bucketConfig = config.buckets?.[this.name]?.[name];
364
+ const bucketConfig = config.modules?.[this.name]?.buckets?.[name];
352
365
  this.buckets[name] = new bucket_1.Bucket(this, schema, bucketConfig, services);
353
366
  });
354
367
  Object.entries(this.schema.messages).forEach(([name, schema]) => {
@@ -364,7 +377,7 @@ class Module {
364
377
  this.machines[name] = new machine_1.Machine(this, schema);
365
378
  });
366
379
  Object.entries(this.schema.controllers).forEach(([name, schema]) => {
367
- const controllerConfig = config.controllers?.[this.name]?.[name];
380
+ const controllerConfig = config.modules?.[this.name]?.controllers?.[name];
368
381
  this.controllers[name] = new controller_1.Controller(this, schema, controllerConfig, services);
369
382
  });
370
383
  Object.entries(this.schema.queues).forEach(([name, schema]) => {
@@ -374,8 +387,8 @@ class Module {
374
387
  this.topics[name] = new topic_1.Topic(this, schema);
375
388
  });
376
389
  this.nql = new nql_engine_1.NQL_Engine(this);
377
- if (config.trash?.[this.name]) {
378
- this.trash = new bucket_1.Bucket(this, trash_1.$TrashBucket, config.trash[this.name], services);
390
+ if (config.modules?.[this.name]?.trash) {
391
+ this.trash = new bucket_1.Bucket(this, trash_1.$TrashBucket, config.modules?.[this.name]?.trash, services);
379
392
  }
380
393
  }
381
394
  // Destroy
@@ -1,6 +1,5 @@
1
- export declare class Crypto {
2
- static DEFAULTS: {
3
- algorithm: string;
1
+ export declare class NesoiCrypto {
2
+ static C: {
4
3
  /**
5
4
  * NIST recommends 96 bits or 12 bytes IV for GCM
6
5
  * to promote interoperability, efficiency, and
@@ -17,14 +16,6 @@ export declare class Crypto {
17
16
  * */
18
17
  salt_bytes: number;
19
18
  };
20
- /**
21
- * To prevent rainbow table attacks
22
- * */
23
- static getIV(): Buffer;
24
- /**
25
- * To prevent rainbow table attacks
26
- * */
27
- static getSalt(): Buffer;
28
19
  /**
29
20
  *
30
21
  * @param {Buffer} password - The password to be used for generating key
@@ -36,7 +27,7 @@ export declare class Crypto {
36
27
  * @param {string} payload - The clear text message to be encrypted
37
28
  * @param {string} key - The key to be used for encryption
38
29
  */
39
- static encrypt(value: any, key: string): string;
30
+ static encrypt(value: any, key: string): Promise<string>;
40
31
  /**
41
32
  *
42
33
  * @param {Buffer} ciphertext - Cipher text
@@ -46,5 +37,5 @@ export declare class Crypto {
46
37
  * the Buffer after the decryption to prevent the message text
47
38
  * and the key from lingering in the memory
48
39
  */
49
- static decrypt(ciphertext: string, key: string): any;
40
+ static decrypt(ciphertext: string, key: string): Promise<any>;
50
41
  }
@@ -6,28 +6,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  return (mod && mod.__esModule) ? mod : { "default": mod };
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.Crypto = void 0;
9
+ exports.NesoiCrypto = void 0;
10
10
  const crypto_1 = __importDefault(require("crypto"));
11
- class Crypto {
12
- /**
13
- * To prevent rainbow table attacks
14
- * */
15
- static getIV() {
16
- return crypto_1.default.randomBytes(this.DEFAULTS.iv_bytes);
17
- }
18
- /**
19
- * To prevent rainbow table attacks
20
- * */
21
- static getSalt() {
22
- return crypto_1.default.randomBytes(this.DEFAULTS.salt_bytes);
23
- }
11
+ class NesoiCrypto {
24
12
  /**
25
13
  *
26
14
  * @param {Buffer} password - The password to be used for generating key
27
15
  *
28
16
  */
29
17
  static getKeyFromPassword(password, salt) {
30
- const buffer = crypto_1.default.scryptSync(password, salt, this.DEFAULTS.key_bytes);
18
+ const buffer = crypto_1.default.scryptSync(password, salt, this.C.key_bytes);
31
19
  const str = buffer.toString();
32
20
  buffer.fill(0);
33
21
  return str;
@@ -37,16 +25,15 @@ class Crypto {
37
25
  * @param {string} payload - The clear text message to be encrypted
38
26
  * @param {string} key - The key to be used for encryption
39
27
  */
40
- static encrypt(value, key) {
41
- const payload = JSON.stringify(value);
42
- const iv = this.getIV();
43
- const cipher = crypto_1.default.createCipheriv(this.DEFAULTS.algorithm, key, iv);
44
- let encrypted = cipher.update(payload);
45
- encrypted = Buffer.concat([encrypted, cipher.final()]);
46
- const buffer = Buffer.concat([iv, encrypted]);
47
- const str = buffer.toString();
48
- buffer.fill(0);
49
- return str;
28
+ static async encrypt(value, key) {
29
+ const iv = crypto_1.default.randomBytes(this.C.iv_bytes);
30
+ const aes_key = await crypto_1.default.subtle.importKey('raw', Buffer.from(key), 'AES-GCM', true, ['encrypt', 'decrypt']);
31
+ const encrypted = await crypto_1.default.subtle.encrypt({
32
+ name: 'AES-GCM',
33
+ iv,
34
+ tagLength: 128,
35
+ }, aes_key, Buffer.from(JSON.stringify(value)));
36
+ return Buffer.concat([Buffer.from(iv), Buffer.from(encrypted)]).toString('base64');
50
37
  }
51
38
  /**
52
39
  *
@@ -57,20 +44,22 @@ class Crypto {
57
44
  * the Buffer after the decryption to prevent the message text
58
45
  * and the key from lingering in the memory
59
46
  */
60
- static decrypt(ciphertext, key) {
61
- const iv = ciphertext.slice(0, 12);
62
- const encryptedMessage = ciphertext.slice(12, -16);
63
- const decipher = crypto_1.default.createDecipheriv(this.DEFAULTS.algorithm, key, iv);
64
- const payload = decipher.update(encryptedMessage, 'utf8');
65
- const buffer = Buffer.concat([payload, decipher.final()]);
66
- const str = buffer.toString();
67
- buffer.fill(0);
68
- return JSON.parse(str);
47
+ static async decrypt(ciphertext, key) {
48
+ const buffer = Uint8Array.from(Buffer.from(ciphertext, 'base64'));
49
+ const iv = buffer.slice(0, this.C.iv_bytes);
50
+ const payload = buffer.slice(this.C.iv_bytes);
51
+ const aes_key = await crypto_1.default.subtle.importKey('raw', Buffer.from(key), 'AES-GCM', true, ['encrypt', 'decrypt']);
52
+ const decrypted = await crypto_1.default.subtle.decrypt({
53
+ name: 'AES-GCM',
54
+ iv: Buffer.from(iv),
55
+ tagLength: 128
56
+ }, aes_key, Buffer.from(payload));
57
+ const decoded = Buffer.from(decrypted).toString('utf8');
58
+ return JSON.parse(decoded);
69
59
  }
70
60
  }
71
- exports.Crypto = Crypto;
72
- Crypto.DEFAULTS = {
73
- algorithm: 'aes-256',
61
+ exports.NesoiCrypto = NesoiCrypto;
62
+ NesoiCrypto.C = {
74
63
  /**
75
64
  * NIST recommends 96 bits or 12 bytes IV for GCM
76
65
  * to promote interoperability, efficiency, and
@@ -1,7 +1,7 @@
1
1
  import { $BlockType } from "../../elements/blocks/block.schema";
2
2
  declare const LogLevel: readonly ["off", "error", "warn", "info", "debug", "trace"];
3
3
  export type LogLevel = typeof LogLevel[number];
4
- export type LogScope = $BlockType | 'compiler' | 'trx' | 'daemon' | 'app' | 'module' | 'layer' | 'message' | 'bucket' | 'job' | 'resource' | 'controller' | 'queue' | 'topic' | 'constants' | 'externals';
4
+ export type LogScope = $BlockType | 'compiler' | 'trx' | 'daemon' | 'app' | 'module' | 'layer' | 'message' | 'bucket' | 'job' | 'resource' | 'controller' | 'queue' | 'topic' | 'constants' | 'externals' | 'inc.server' | 'inc.client';
5
5
  export declare function scopeTag(scope: LogScope, scope_id: string): string;
6
6
  export declare function anyScopeTag(scopeWithId: string): string;
7
7
  export declare class Log {
@@ -25,6 +25,8 @@ function scopeTag(scope, scope_id) {
25
25
  machine: 'lightblue',
26
26
  queue: 'lightblue',
27
27
  topic: 'lightblue',
28
+ 'inc.server': 'lightgreen',
29
+ 'inc.client': 'lightcyan',
28
30
  }[scope] || 'lightgray';
29
31
  return (0, string_1.colored)(`${scope}:${scope_id}`, color);
30
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nesoi",
3
- "version": "3.1.7",
3
+ "version": "3.2.1",
4
4
  "description": "Declarative framework for data-driven applications",
5
5
  "repository": {
6
6
  "type": "git",