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,182 @@
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.DumpModulesStage = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const log_1 = require("../../../../engine/util/log");
40
+ const app_1 = require("../../../../engine/apps/app");
41
+ /**
42
+ * [distributed Compiler Stage #4]
43
+ * Dump modules to build/modules folder.
44
+ *
45
+ * @category distributed Compiler
46
+ * @subcategory Stages
47
+ */
48
+ class DumpModulesStage {
49
+ constructor(distributed, app) {
50
+ this.distributed = distributed;
51
+ this.app = app;
52
+ }
53
+ async run() {
54
+ const { compiler, dirs: _dirs } = this.distributed;
55
+ for (const name in this.app.nodes) {
56
+ log_1.Log.info('compiler', 'distributed', `[${name}] Dumping modules to build/modules folder...`);
57
+ const node = this.app.nodes[name];
58
+ const info = app_1.App.getInfo(node);
59
+ const dirs = _dirs.nodes[name];
60
+ for (const name of info.spaceModules) {
61
+ const module = compiler.modules[name];
62
+ this.dumpModule(module, dirs.build_modules);
63
+ }
64
+ }
65
+ }
66
+ dumpModule(module, dir) {
67
+ log_1.Log.debug('compiler', 'distributed', `Dumping module ${module.lowName}`);
68
+ let str = `const { Module } = require('${module.compiler.config?.nesoiPath || 'nesoi'}/lib/engine/module');\n`;
69
+ str += `exports.default = new Module('${module.lowName}')\n`;
70
+ str += ' .inject({';
71
+ const externals = module.module.schema.externals;
72
+ if (externals) {
73
+ str += '\n externals: {';
74
+ if (Object.keys(externals.buckets).length) {
75
+ str += '\n buckets: {';
76
+ for (const b in externals.buckets) {
77
+ const dep = externals.buckets[b];
78
+ str += `\n '${b}': ${JSON.stringify(dep, undefined, 2).replace(/\n/g, '\n ')},`;
79
+ }
80
+ str += '\n },';
81
+ }
82
+ if (Object.keys(externals.messages).length) {
83
+ str += '\n messages: {';
84
+ for (const b in externals.messages) {
85
+ const dep = externals.messages[b];
86
+ str += `\n '${b}': ${JSON.stringify(dep, undefined, 2).replace(/\n/g, '\n ')},`;
87
+ }
88
+ str += '\n },';
89
+ }
90
+ if (Object.keys(externals.jobs).length) {
91
+ str += '\n jobs: {\n';
92
+ for (const b in externals.jobs) {
93
+ const dep = externals.jobs[b];
94
+ str += `\n '${b}': ${JSON.stringify(dep, undefined, 2).replace(/\n/g, '\n ')},`;
95
+ }
96
+ str += '\n },';
97
+ }
98
+ if (Object.keys(externals.machines).length) {
99
+ str += '\n machines: {\n';
100
+ for (const b in externals.machines) {
101
+ const dep = externals.machines[b];
102
+ str += `\n '${b}': ${JSON.stringify(dep, undefined, 2).replace(/\n/g, '\n ')},`;
103
+ }
104
+ str += '\n },';
105
+ }
106
+ str += '\n },';
107
+ }
108
+ const constants = module.module.schema.constants;
109
+ if (constants && (Object.values(constants.values).length || Object.values(constants.enums).length)) {
110
+ str += `\n constants: require('./${module.lowName}/constants__${module.lowName}').default,`;
111
+ }
112
+ const buckets = Object.values(module.module.schema.buckets || {});
113
+ if (buckets.length) {
114
+ str += '\n buckets: [\n';
115
+ buckets.forEach(bucket => {
116
+ str += ` require('./${module.lowName}/bucket__${bucket.name}').default,\n`;
117
+ });
118
+ str += ' ],';
119
+ }
120
+ const messages = Object.values(module.module.schema.messages || {});
121
+ if (messages.length) {
122
+ str += '\n messages: [\n';
123
+ messages.forEach(message => {
124
+ str += ` require('./${module.lowName}/message__${message.name}').default,\n`;
125
+ });
126
+ str += ' ],';
127
+ }
128
+ const jobs = Object.values(module.module.schema.jobs || {});
129
+ if (jobs.length) {
130
+ str += '\n jobs: [\n';
131
+ jobs.forEach(job => {
132
+ str += ` require('./${module.lowName}/job__${job.name}').default,\n`;
133
+ });
134
+ str += ' ],';
135
+ }
136
+ const resources = Object.values(module.module.schema.resources || {});
137
+ if (resources.length) {
138
+ str += '\n resources: [\n';
139
+ resources.forEach(resource => {
140
+ str += ` require('./${module.lowName}/resource__${resource.name}').default,\n`;
141
+ });
142
+ str += ' ],';
143
+ }
144
+ const machines = Object.values(module.module.schema.machines || {});
145
+ if (machines.length) {
146
+ str += '\n machines: [\n';
147
+ machines.forEach(machine => {
148
+ str += ` require('./${module.lowName}/machine__${machine.name}').default,\n`;
149
+ });
150
+ str += ' ],';
151
+ }
152
+ const controllers = Object.values(module.module.schema.controllers || {});
153
+ if (controllers.length) {
154
+ str += '\n controllers: [\n';
155
+ controllers.forEach(controller => {
156
+ str += ` require('./${module.lowName}/controller__${controller.name}').default,\n`;
157
+ });
158
+ str += ' ],';
159
+ }
160
+ const queues = Object.values(module.module.schema.queues || {});
161
+ if (queues.length) {
162
+ str += '\n queues: [\n';
163
+ queues.forEach(queue => {
164
+ str += ` require('./${module.lowName}/queue__${queue.name}').default,\n`;
165
+ });
166
+ str += ' ],';
167
+ }
168
+ const topics = Object.values(module.module.schema.topics || {});
169
+ if (topics.length) {
170
+ str += '\n topics: [\n';
171
+ topics.forEach(topic => {
172
+ str += ` require('./${module.lowName}/topic__${topic.name}').default,\n`;
173
+ });
174
+ str += ' ],';
175
+ }
176
+ str += '})';
177
+ const moduleFilename = `${module.lowName}.js`;
178
+ const modulePath = path.resolve(dir, moduleFilename);
179
+ fs.writeFileSync(modulePath, str);
180
+ }
181
+ }
182
+ exports.DumpModulesStage = DumpModulesStage;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ // import * as fs from 'fs';
3
+ // import * as path from 'path';
4
+ // import { Log } from '~/engine/util/log';
5
+ // import { MonolythApp } from '~/engine/apps/monolyth/monolyth.app';
6
+ // import { MonolythCompiler } from '../monolyth_compiler';
7
+ // import { Space } from '~/engine/space';
8
+ // /**
9
+ // * [Monolyth Compiler Stage #5]
10
+ // * Copy the paths passed to `staticPaths` on the compiler
11
+ // * config to the build folder.
12
+ // *
13
+ // * @category Monolyth Compiler
14
+ // * @subcategory Stages
15
+ // */
16
+ // export class CopyStaticStage {
17
+ // public constructor(
18
+ // private monolyth: MonolythCompiler,
19
+ // private app: MonolythApp<any, any>
20
+ // ) {}
21
+ // public async run() {
22
+ // Log.info('compiler', 'monolyth', 'Copying static paths to build folder...')
23
+ // for (const staticPath of this.monolyth.config.staticPaths || []) {
24
+ // const from = Space.path(this.monolyth.compiler.space, staticPath);
25
+ // const to = path.join(this.monolyth.dirs.build, staticPath);
26
+ // fs.cpSync(from, to, {
27
+ // recursive: true
28
+ // })
29
+ // }
30
+ // }
31
+ // }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ // import * as fs from 'fs';
3
+ // import * as path from 'path';
4
+ // import { Log } from '~/engine/util/log';
5
+ // import { MonolythApp } from '~/engine/apps/monolyth/monolyth.app';
6
+ // import { MonolythCompiler } from '../monolyth_compiler';
7
+ // /**
8
+ // * [Monolyth Compiler Stage #6]
9
+ // * Dump the cli.js file to build/bin folder.
10
+ // *
11
+ // * @category Monolyth Compiler
12
+ // * @subcategory Stages
13
+ // */
14
+ // export class DumpCLIStage {
15
+ // public constructor(
16
+ // private monolyth: MonolythCompiler,
17
+ // private app: MonolythApp<any, any>
18
+ // ) {}
19
+ // public async run() {
20
+ // Log.info('compiler', 'monolyth', 'Dumping cli.js file to build/bin folder...')
21
+ // const { dirs } = this.monolyth;
22
+ // let str = '';
23
+ // str += 'require("nesoi/tools/dotenv");\n';
24
+ // str += 'const app = require(\'../app\').default\n';
25
+ // str += 'const { Log } = require(\'nesoi/lib/engine/util/log\');\n';
26
+ // str += 'Log.level = \'debug\';\n'
27
+ // str += '\n';
28
+ // str += '(async () => {\n';
29
+ // str += ' (await app.daemon()).cli();\n';
30
+ // str += '})()'
31
+ // const filePath = path.resolve(dirs.build_bin, 'cli.js')
32
+ // fs.writeFileSync(filePath, str);
33
+ // }
34
+ // }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ // import * as fs from 'fs';
3
+ // import * as path from 'path';
4
+ // import { Log } from '~/engine/util/log';
5
+ // import { MonolythCompiler } from '../monolyth_compiler';
6
+ // import { Space } from '~/engine/space';
7
+ // import { MonolythApp } from '~/engine/apps/monolyth/monolyth.app';
8
+ // /**
9
+ // * [Monolyth Compiler Stage #7]
10
+ // * Dump the package.json file to build folder.
11
+ // *
12
+ // * @category Monolyth Compiler
13
+ // * @subcategory Stages
14
+ // */
15
+ // export class DumpPackageJsonStage {
16
+ // public constructor(
17
+ // private monolyth: MonolythCompiler,
18
+ // private app: MonolythApp<any, any>
19
+ // ) {}
20
+ // public async run() {
21
+ // Log.info('compiler', 'monolyth', 'Dumping package.json to build folder...')
22
+ // const { config, compiler, dirs } = this.monolyth;
23
+ // const packageJsonPath = config.nesoiPath
24
+ // ? path.join(config.nesoiPath, 'package.json')
25
+ // : path.join('..', '..', '..', '..', '..', 'package.json');
26
+ // const nesoiPackageJson = await import(packageJsonPath);
27
+ // const spacePackageJson = await import(Space.path(compiler.space,'package.json'));
28
+ // const filePath = path.resolve(dirs.build, 'package.json');
29
+ // const scripts: Record<string, string> = {
30
+ // cli: 'node bin/cli.js'
31
+ // };
32
+ // Object.entries(config.scripts || {}).forEach(([name, path]) => {
33
+ // const jspath = path.replace(/\.ts/,'.js');
34
+ // scripts[name] = `node ${jspath}`;
35
+ // });
36
+ // const dependencies = {
37
+ // ...spacePackageJson.dependencies,
38
+ // nesoi: config.nesoiPath
39
+ // ? `file:${config.nesoiPath}`
40
+ // : nesoiPackageJson.version
41
+ // }
42
+ // const packageJson = MonolythApp.package(this.app, scripts, dependencies);
43
+ // fs.writeFileSync(filePath, JSON.stringify(packageJson, undefined, 2))
44
+ // }
45
+ // }
@@ -93,9 +93,9 @@ class Element {
93
93
  return msgName.type;
94
94
  });
95
95
  const objs = schema.output?.obj?.map(bucket => {
96
- const schema = compiler.tree.getSchema(bucket);
96
+ const schema = compiler.tree.getSchema(bucket.dep);
97
97
  const bucketName = name_helpers_1.NameHelpers.names(schema);
98
- return bucketName.high;
98
+ return bucketName.high + (bucket.many ? '[]' : '');
99
99
  });
100
100
  const type = [
101
101
  raw,
@@ -1,2 +1,3 @@
1
1
  export { Compiler } from './compiler';
2
2
  export { MonolythCompiler } from './apps/monolyth/monolyth_compiler';
3
+ export { DistributedCompiler } from './apps/distributed/distributed_compiler';
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MonolythCompiler = exports.Compiler = void 0;
3
+ exports.DistributedCompiler = exports.MonolythCompiler = exports.Compiler = void 0;
4
4
  var compiler_1 = require("./compiler");
5
5
  Object.defineProperty(exports, "Compiler", { enumerable: true, get: function () { return compiler_1.Compiler; } });
6
6
  var monolyth_compiler_1 = require("./apps/monolyth/monolyth_compiler");
7
7
  Object.defineProperty(exports, "MonolythCompiler", { enumerable: true, get: function () { return monolyth_compiler_1.MonolythCompiler; } });
8
+ var distributed_compiler_1 = require("./apps/distributed/distributed_compiler");
9
+ Object.defineProperty(exports, "DistributedCompiler", { enumerable: true, get: function () { return distributed_compiler_1.DistributedCompiler; } });
@@ -30,4 +30,5 @@ export declare abstract class BlockBuilder<Space extends $Space, Module extends
30
30
  protected outputRaw(): unknown;
31
31
  protected outputMsg(...msgs: string[]): unknown;
32
32
  protected outputObj(...objs: string[]): unknown;
33
+ protected outputObjs(...objs: string[]): unknown;
33
34
  }
@@ -79,7 +79,22 @@ class BlockBuilder {
79
79
  this._output ?? (this._output = {});
80
80
  (_a = this._output).obj ?? (_a.obj = []);
81
81
  objs.forEach(obj => {
82
- this._output?.obj?.push(new dependency_1.$Dependency(this.module, 'bucket', obj, true));
82
+ this._output?.obj?.push({
83
+ dep: new dependency_1.$Dependency(this.module, 'bucket', obj, true),
84
+ many: false
85
+ });
86
+ });
87
+ return this;
88
+ }
89
+ outputObjs(...objs) {
90
+ var _a;
91
+ this._output ?? (this._output = {});
92
+ (_a = this._output).obj ?? (_a.obj = []);
93
+ objs.forEach(obj => {
94
+ this._output?.obj?.push({
95
+ dep: new dependency_1.$Dependency(this.module, 'bucket', obj, true),
96
+ many: true
97
+ });
83
98
  });
84
99
  return this;
85
100
  }
@@ -6,7 +6,10 @@ export type $BlockType = 'job' | 'resource' | 'machine' | 'queue' | 'topic';
6
6
  export type $BlockOutput = {
7
7
  raw?: TypeAsObj;
8
8
  msg?: $Dependency[];
9
- obj?: $Dependency[];
9
+ obj?: {
10
+ dep: $Dependency;
11
+ many: boolean;
12
+ }[];
10
13
  };
11
14
  /**
12
15
  * @category Schemas
@@ -51,6 +51,7 @@ export declare class JobBuilder<Space extends $Space, Module extends $Module, Jo
51
51
  obj: <BucketName extends keyof Module["buckets"], Bucket extends NoInfer<Module["buckets"][BucketName]>>(...objs: BucketName[]) => JobBuilder<Space, Module, Overlay<Job, {
52
52
  "#output": unknown extends Job["#output"] ? Bucket["#data"] : (Job["#output"] | Bucket["#data"]);
53
53
  }>, Ctx>;
54
+ objs: (...objs: string[]) => unknown;
54
55
  };
55
56
  protected outputRaw<T>(): JobBuilder<Space, Module, Overlay<Job, {
56
57
  "#output": unknown extends Job["#output"] ? T : (Job["#output"] | T);
@@ -41,7 +41,8 @@ class JobBuilder extends block_builder_1.BlockBuilder {
41
41
  return {
42
42
  raw: this.outputRaw.bind(this),
43
43
  msg: this.outputMsg.bind(this),
44
- obj: this.outputObj.bind(this)
44
+ obj: this.outputObj.bind(this),
45
+ objs: this.outputObjs.bind(this)
45
46
  };
46
47
  }
47
48
  outputRaw() {
@@ -455,7 +455,7 @@ class Bucket {
455
455
  var _a, _b;
456
456
  log_1.Log.debug('bucket', this.schema.name, `Put id=${obj['id']}`, obj);
457
457
  // Separate composition
458
- const composition = obj['#composition'] || {};
458
+ let composition = obj['#composition'];
459
459
  delete obj['#composition'];
460
460
  // Add meta (created_by/created_at/updated_by/updated_at)
461
461
  this.addMeta(trx, obj, 'create');
@@ -470,6 +470,12 @@ class Bucket {
470
470
  // Put
471
471
  const _obj = await this.adapter.put(trx, obj);
472
472
  // Composition
473
+ if (composition) {
474
+ this.replaceFutureId(composition, _obj.id);
475
+ }
476
+ else {
477
+ composition = {};
478
+ }
473
479
  for (const link of Object.values(this.schema.graph.links)) {
474
480
  if (link.rel !== 'composition')
475
481
  continue;
@@ -13,41 +13,38 @@ import { $Bucket } from "../../elements";
13
13
  import { Overlay } from '../util/type';
14
14
  import { TrxStatus } from '../transaction/trx';
15
15
  import { NesoiObj } from '../data/obj';
16
- export type AppConfig<S extends $Space, Modules extends ModuleName<S>> = {
17
- i18n?: AppI18nConfig;
16
+ export type AppModuleConfig<S extends $Space, M extends ModuleName<S>, Services extends Record<string, IService>> = {
17
+ buckets?: AppBucketConfig<S, M, Services>;
18
+ trash?: AppTrashConfig<Services>;
19
+ controllers?: AppControllerConfig<S, M, Services>;
20
+ trx?: TrxEngineConfig<S, S['modules'][M], any, Services>;
21
+ };
22
+ export type AppConfig<S extends $Space, Modules extends ModuleName<S>, Services extends Record<string, IService>> = {
18
23
  authn?: AppAuthnConfig<S>;
19
- buckets?: AppBucketConfig<S, Modules, any>;
20
- controllers?: AppControllerConfig<S, Modules, any>;
24
+ modules?: Partial<{
25
+ [M in (Modules & keyof S['modules'])]: AppModuleConfig<S, M, Services>;
26
+ }>;
27
+ i18n?: AppI18nConfig;
21
28
  cli?: CLIConfig<any>;
22
29
  compiler?: CompilerConfig;
23
- trxEngine?: AppTrxEngineConfig<S, Modules, any>;
24
- trash?: AppTrashConfig<S, Modules, any>;
25
30
  };
26
- export type AnyAppConfig = AppConfig<any, any>;
31
+ export type AnyAppConfig = AppConfig<any, any, any>;
27
32
  export type AppI18nConfig = {
28
33
  [x: string]: ($: Record<string, any>) => string;
29
34
  };
30
35
  export type AppAuthnConfig<S extends $Space> = {
31
36
  [K in keyof S['authnUsers']]: () => AuthnProvider<S['authnUsers'][K]>;
32
37
  };
33
- export type AppBucketConfig<S extends $Space, Modules extends ModuleName<S>, Services extends Record<string, IService>> = Partial<{
34
- [M in (Modules & keyof S['modules'])]: Partial<{
35
- [K in keyof S['modules'][M]['buckets']]: BucketConfig<S['modules'][M], S['modules'][M]['buckets'][K], Services>;
36
- }>;
37
- }>;
38
- export type AppTrashConfig<S extends $Space, Modules extends ModuleName<S>, Services extends Record<string, IService>> = Partial<{
39
- [M in (Modules & keyof S['modules'])]: {
40
- adapter?: (schema: typeof $TrashBucket, services: Services) => BucketAdapter<typeof $TrashBucket['#data']>;
41
- };
38
+ export type AppBucketConfig<S extends $Space, M extends keyof S['modules'], Services extends Record<string, IService>> = Partial<{
39
+ [K in keyof S['modules'][M]['buckets']]: BucketConfig<S['modules'][M], S['modules'][M]['buckets'][K], Services>;
42
40
  }>;
43
- export type AppControllerConfig<S extends $Space, Modules extends ModuleName<S>, Services extends Record<string, IService>> = Partial<{
44
- [M in (Modules & keyof S['modules'])]: Partial<{
45
- [K in keyof S['modules'][M]['controllers']]: ControllerConfig<S['modules'][M], S['modules'][M]['controllers'][K], Services>;
46
- }>;
47
- }>;
48
- export type AppTrxEngineConfig<S extends $Space, Modules extends ModuleName<S>, Services extends Record<string, IService>> = Partial<{
49
- [M in (Modules & keyof S['modules'])]: TrxEngineConfig<S, S['modules'][M], any, Services>;
41
+ export type AppTrashConfig<Services extends Record<string, IService>> = {
42
+ adapter?: (schema: typeof $TrashBucket, services: Services) => BucketAdapter<typeof $TrashBucket['#data']>;
43
+ };
44
+ export type AppControllerConfig<S extends $Space, M extends keyof S['modules'], Services extends Record<string, IService>> = Partial<{
45
+ [K in keyof S['modules'][M]['controllers']]: ControllerConfig<S['modules'][M], S['modules'][M]['controllers'][K], Services>;
50
46
  }>;
47
+ export type AppTrxEngineConfig<S extends $Space, M extends keyof S['modules'], Services extends Record<string, IService>> = TrxEngineConfig<S, S['modules'][M], any, Services>;
51
48
  export type AppAuditConfig = {
52
49
  adapter: ($: Overlay<$Bucket, {
53
50
  '#data': NesoiObj;
@@ -60,17 +57,14 @@ export type AppAuditConfig = {
60
57
  /**
61
58
  * @category App
62
59
  */
63
- export declare class AppConfigFactory<S extends $Space, Modules extends string = ModuleName<S> & string, Services extends Record<string, any> = Record<string, any>, _App = App<S, Modules, Services>> {
60
+ export declare class AppConfigBuilder<S extends $Space, Modules extends string = ModuleName<S> & string, Services extends Record<string, any> = Record<string, any>, _App = App<S, Modules, Services>> {
64
61
  private app;
65
62
  private config;
66
63
  constructor(app: _App);
67
- i18n(config: AppI18nConfig): _App;
68
64
  authn(config: AppAuthnConfig<S>): _App;
69
- buckets(config: AppBucketConfig<S, Modules, Services>): _App;
70
- trash(config: AppTrashConfig<S, Modules, Services>): _App;
71
- controllers(config: AppControllerConfig<S, Modules, Services>): _App;
65
+ module<M extends Modules>(name: M, config: AppModuleConfig<S, M, Services>): _App;
72
66
  audit(config: AppI18nConfig): _App;
73
- compiler(config: CompilerConfig): _App;
67
+ i18n(config: AppI18nConfig): _App;
74
68
  cli(config: CLIConfig<Services>): _App;
75
- trx(config: AppTrxEngineConfig<S, Modules, Services>): _App;
69
+ compiler(config: CompilerConfig): _App;
76
70
  }
@@ -1,52 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppConfigFactory = void 0;
3
+ exports.AppConfigBuilder = void 0;
4
4
  /**
5
5
  * Factory
6
6
  */
7
7
  /**
8
8
  * @category App
9
9
  */
10
- class AppConfigFactory {
10
+ class AppConfigBuilder {
11
11
  constructor(app) {
12
12
  this.app = app;
13
13
  this.config = app._config;
14
14
  }
15
- i18n(config) {
16
- this.config.i18n = config;
17
- return this.app;
18
- }
19
15
  authn(config) {
20
16
  this.config.authn = config;
21
17
  return this.app;
22
18
  }
23
- buckets(config) {
24
- this.config.buckets = config;
25
- return this.app;
26
- }
27
- trash(config) {
28
- this.config.trash = config;
29
- return this.app;
30
- }
31
- controllers(config) {
32
- this.config.controllers = config;
19
+ module(name, config) {
20
+ var _a;
21
+ (_a = this.config).modules ?? (_a.modules = {});
22
+ this.config.modules[name] = config;
33
23
  return this.app;
34
24
  }
35
25
  audit(config) {
36
26
  this.config.i18n = config;
37
27
  return this.app;
38
28
  }
39
- compiler(config) {
40
- this.config.compiler = config;
29
+ i18n(config) {
30
+ this.config.i18n = config;
41
31
  return this.app;
42
32
  }
43
33
  cli(config) {
44
34
  this.config.cli = config;
45
35
  return this.app;
46
36
  }
47
- trx(config) {
48
- this.config.trxEngine = config;
37
+ compiler(config) {
38
+ this.config.compiler = config;
49
39
  return this.app;
50
40
  }
51
41
  }
52
- exports.AppConfigFactory = AppConfigFactory;
42
+ exports.AppConfigBuilder = AppConfigBuilder;
@@ -2,8 +2,9 @@ import { $Space, ModuleName } from "../../schema";
2
2
  import { AnyBuilder, AnyModule } from '../module';
3
3
  import { Space } from '../space';
4
4
  import { Daemon } from '../daemon';
5
- import { AnyAppConfig, AppConfigFactory } from './app.config';
5
+ import { AnyAppConfig, AppConfigBuilder } from './app.config';
6
6
  import { IService } from './service';
7
+ import { DistributedAppConfigBuilder } from './distributed/distributed.app.config';
7
8
  /**
8
9
  * @category App
9
10
  */
@@ -37,14 +38,14 @@ export declare abstract class App<S extends $Space, Modules extends string = Mod
37
38
  * ⚠ This has no effect on apps without a `Space`, such as `InlineApp`.
38
39
  * @param modules A list of names of modules from the current `Space`.
39
40
  */
40
- modules<M extends ModuleName<S>>(modules: M[]): App<S, M & Modules, Services>;
41
+ protected modules<M extends ModuleName<S>>(modules: M[]): App<S, M & Modules, Services>;
41
42
  /**
42
43
  * Injects pre-built modules into this App.
43
44
  * These will be included on the Daemon once it starts.
44
45
  *
45
46
  * @param modules A list of pre-built modules.
46
47
  */
47
- inject(modules: AnyModule[]): this;
48
+ protected inject(modules: AnyModule[]): this;
48
49
  /**
49
50
  * Declares a `Service`.
50
51
  *
@@ -52,8 +53,8 @@ export declare abstract class App<S extends $Space, Modules extends string = Mod
52
53
  * config to share globals between adapters and other methods.
53
54
  * @param $ object with an `up` and `down` method to create/destroy the service
54
55
  */
55
- service<T extends IService>($: T): App<S, Modules, Services & { [K in T["name"]]: T; }>;
56
- get config(): AppConfigFactory<S, Modules, Services>;
56
+ protected service<T extends IService>($: T): App<S, Modules, Services & { [K in T["name"]]: T; }>;
57
+ protected get config(): AppConfigBuilder<S, Modules, Services> | DistributedAppConfigBuilder<S, any, Modules, Services>;
57
58
  protected makeModules(): Record<string, AnyModule>;
58
59
  static getServices(app: AnyApp): Record<string, IService>;
59
60
  static getInfo(app: AnyApp): {
@@ -68,7 +68,7 @@ class App {
68
68
  }
69
69
  //
70
70
  get config() {
71
- return new app_config_1.AppConfigFactory(this);
71
+ return new app_config_1.AppConfigBuilder(this);
72
72
  }
73
73
  //
74
74
  makeModules() {