nesoi 3.1.8 → 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 (53) 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.js +7 -1
  26. package/lib/engine/apps/app.config.d.ts +24 -30
  27. package/lib/engine/apps/app.config.js +11 -21
  28. package/lib/engine/apps/app.d.ts +6 -5
  29. package/lib/engine/apps/app.js +1 -1
  30. package/lib/engine/apps/distributed/distributed.app.config.d.ts +44 -0
  31. package/lib/engine/apps/distributed/distributed.app.config.js +36 -0
  32. package/lib/engine/apps/distributed/distributed.app.d.ts +30 -0
  33. package/lib/engine/apps/distributed/distributed.app.js +52 -0
  34. package/lib/engine/apps/distributed/distributed_node.app.d.ts +67 -0
  35. package/lib/engine/apps/distributed/distributed_node.app.js +191 -0
  36. package/lib/engine/apps/distributed/elements/distributed_job.d.ts +7 -0
  37. package/lib/engine/apps/distributed/elements/distributed_job.js +11 -0
  38. package/lib/engine/apps/distributed/inc/inc.client.d.ts +17 -0
  39. package/lib/engine/apps/distributed/inc/inc.client.js +105 -0
  40. package/lib/engine/apps/distributed/inc/inc.server.d.ts +19 -0
  41. package/lib/engine/apps/distributed/inc/inc.server.js +174 -0
  42. package/lib/engine/apps/distributed/inc/test.d.ts +1 -0
  43. package/lib/engine/apps/distributed/inc/test.js +24 -0
  44. package/lib/engine/apps/inline.app.d.ts +2 -2
  45. package/lib/engine/apps/inline.app.js +2 -2
  46. package/lib/engine/apps/monolyth/monolyth.app.d.ts +2 -2
  47. package/lib/engine/apps/monolyth/monolyth.app.js +1 -1
  48. package/lib/engine/module.d.ts +11 -1
  49. package/lib/engine/module.js +17 -4
  50. package/lib/engine/util/log.d.ts +1 -1
  51. package/lib/engine/util/log.js +2 -0
  52. package/package.json +1 -1
  53. package/tsconfig.build.tsbuildinfo +1 -1
@@ -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
  */
@@ -45,7 +45,7 @@ export declare class InlineApp<S extends $Space, ModuleNames extends string = Mo
45
45
  protected linkAppValues(modules: Record<string, Module<S, $Module>>): void;
46
46
  modules<M extends ModuleName<S>>(modules: M[]): InlineApp<S, M & ModuleNames>;
47
47
  service<T extends IService>($: T): InlineApp<S, ModuleNames, Services & { [K in T["name"]]: T; }>;
48
- get config(): AppConfigFactory<S, ModuleNames, Services, typeof this>;
48
+ get config(): AppConfigBuilder<S, ModuleNames, Services, typeof this>;
49
49
  static package(app: InlineApp<any, any>, scripts: Record<string, string>, dependencies: Record<string, string>): {
50
50
  name: string;
51
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]?.();
@@ -158,7 +158,7 @@ class InlineApp extends app_1.App {
158
158
  return this;
159
159
  }
160
160
  get config() {
161
- return new app_config_1.AppConfigFactory(this);
161
+ return new app_config_1.AppConfigBuilder(this);
162
162
  }
163
163
  //
164
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,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.8",
3
+ "version": "3.2.1",
4
4
  "description": "Declarative framework for data-driven applications",
5
5
  "repository": {
6
6
  "type": "git",