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,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() {
@@ -197,8 +197,8 @@ export declare class Bucket<M extends $Module, $ extends $Bucket> {
197
197
  */
198
198
  protected addMeta(trx: AnyTrxNode, obj: Record<string, any>, operation: 'create' | 'update'): void;
199
199
  getTenancyQuery(trx: AnyTrxNode): import("./query/nql.schema").NQL_Query<any, any> | undefined;
200
- protected encrypt(trx: AnyTrxNode, obj: Record<string, any>, fields?: $BucketModelFields): void;
201
- protected decrypt(trx: AnyTrxNode, obj: Record<string, any>, fields?: $BucketModelFields): void;
200
+ protected encrypt(trx: AnyTrxNode, obj: Record<string, any>, fields?: $BucketModelFields): Promise<void>;
201
+ protected decrypt(trx: AnyTrxNode, obj: Record<string, any>, fields?: $BucketModelFields): Promise<void>;
202
202
  /**
203
203
  * Copy all files from the object to the bucket's Drive
204
204
  * - Call `drive.upload` to send the files to the drive preserving the local copy
@@ -101,7 +101,7 @@ class Bucket {
101
101
  }
102
102
  // Encryption
103
103
  if (this.schema.model.hasEncryptedField) {
104
- this.decrypt(trx, raw);
104
+ await this.decrypt(trx, raw);
105
105
  }
106
106
  return raw;
107
107
  }
@@ -132,7 +132,7 @@ class Bucket {
132
132
  // Encryption
133
133
  if (this.schema.model.hasEncryptedField) {
134
134
  for (const raw of raws) {
135
- this.decrypt(trx, raw);
135
+ await this.decrypt(trx, raw);
136
136
  }
137
137
  }
138
138
  return raws;
@@ -196,7 +196,7 @@ class Bucket {
196
196
  // Encryption
197
197
  if (linkObj) {
198
198
  if (this.schema.model.hasEncryptedField) {
199
- this.decrypt(trx, linkObj);
199
+ await this.decrypt(trx, linkObj);
200
200
  }
201
201
  }
202
202
  return linkObj;
@@ -230,10 +230,10 @@ class Bucket {
230
230
  if (linkObj && this.schema.model.hasEncryptedField) {
231
231
  if (Array.isArray(linkObj)) {
232
232
  for (const obj of linkObj)
233
- this.decrypt(trx, obj);
233
+ await this.decrypt(trx, obj);
234
234
  }
235
235
  else {
236
- this.decrypt(trx, linkObj);
236
+ await this.decrypt(trx, linkObj);
237
237
  }
238
238
  }
239
239
  return linkObj;
@@ -287,7 +287,7 @@ class Bucket {
287
287
  this.addMeta(trx, obj, 'create');
288
288
  // Encryption
289
289
  if (this.schema.model.hasEncryptedField) {
290
- this.encrypt(trx, obj);
290
+ await this.encrypt(trx, obj);
291
291
  }
292
292
  // Drive
293
293
  if (this.schema.model.hasFileField) {
@@ -413,7 +413,7 @@ class Bucket {
413
413
  this.addMeta(trx, obj, 'update');
414
414
  // Encryption
415
415
  if (this.schema.model.hasEncryptedField) {
416
- this.encrypt(trx, obj);
416
+ await this.encrypt(trx, obj);
417
417
  }
418
418
  // Drive
419
419
  if (this.schema.model.hasFileField) {
@@ -455,13 +455,13 @@ 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');
462
462
  // Encryption
463
463
  if (this.schema.model.hasEncryptedField) {
464
- this.encrypt(trx, obj);
464
+ await this.encrypt(trx, obj);
465
465
  }
466
466
  // Drive
467
467
  if (this.schema.model.hasFileField) {
@@ -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;
@@ -678,7 +684,7 @@ class Bucket {
678
684
  // Encryption
679
685
  if (this.schema.model.hasEncryptedField) {
680
686
  for (const obj of result.data) {
681
- this.decrypt(trx, obj);
687
+ await this.decrypt(trx, obj);
682
688
  }
683
689
  }
684
690
  // Build
@@ -712,27 +718,35 @@ class Bucket {
712
718
  return this.schema.tenancy[match.provider]?.(match.user);
713
719
  }
714
720
  // Encryption
715
- encrypt(trx, obj, fields = this.schema.model.fields) {
721
+ async encrypt(trx, obj, fields = this.schema.model.fields) {
716
722
  for (const key in fields) {
717
723
  const field = fields[key];
718
724
  if (field.crypto) {
719
725
  const key = trx.value(field.crypto.key);
720
- tree_1.Tree.set(obj, field.path, val => crypto_1.Crypto.encrypt(val, key));
726
+ const val = tree_1.Tree.get(obj, field.path);
727
+ if (val !== undefined) {
728
+ const encrypted = await crypto_1.NesoiCrypto.encrypt(val, key);
729
+ tree_1.Tree.set(obj, field.path, () => encrypted);
730
+ }
721
731
  }
722
732
  if (field.children) {
723
- this.encrypt(trx, obj, field.children);
733
+ await this.encrypt(trx, obj, field.children);
724
734
  }
725
735
  }
726
736
  }
727
- decrypt(trx, obj, fields = this.schema.model.fields) {
737
+ async decrypt(trx, obj, fields = this.schema.model.fields) {
728
738
  for (const key in fields) {
729
739
  const field = fields[key];
730
740
  if (field.crypto) {
731
741
  const key = trx.value(field.crypto.key);
732
- tree_1.Tree.set(obj, field.path, val => crypto_1.Crypto.decrypt(val, key));
742
+ const val = tree_1.Tree.get(obj, field.path);
743
+ if (val !== undefined) {
744
+ const encrypted = await crypto_1.NesoiCrypto.decrypt(val, key);
745
+ tree_1.Tree.set(obj, field.path, () => encrypted);
746
+ }
733
747
  }
734
748
  if (field.children) {
735
- this.decrypt(trx, obj, field.children);
749
+ await this.decrypt(trx, obj, field.children);
736
750
  }
737
751
  }
738
752
  }
@@ -164,7 +164,7 @@ export declare class BucketModelFieldBuilder<Module extends $Module, Input, Outp
164
164
  * > If you want unconstrained enum you must specify `null` here.
165
165
  */
166
166
  maxLength(val: number | null): void;
167
- encrypt(key: keyof Module['constants']['values'], algorithm?: string): void;
167
+ encrypt(key: keyof Module['constants']['values'], algorithm?: string): this;
168
168
  static build(builder: AnyBucketModelFieldBuilder, name: string, basePath?: string): {
169
169
  schema: $BucketModelField;
170
170
  hasFile: boolean;
@@ -152,6 +152,7 @@ class BucketModelFieldBuilder {
152
152
  algorithm,
153
153
  key: key
154
154
  };
155
+ return this;
155
156
  }
156
157
  // Build
157
158
  static build(builder, name, basePath = '') {
@@ -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
  }