nesoi 3.1.8 → 3.2.2

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 (74) 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/internal/resource_job.js +1 -1
  24. package/lib/elements/blocks/job/job.builder.d.ts +1 -0
  25. package/lib/elements/blocks/job/job.builder.js +2 -1
  26. package/lib/elements/blocks/resource/resource.builder.js +1 -1
  27. package/lib/elements/blocks/resource/resource.js +1 -0
  28. package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +2 -2
  29. package/lib/elements/entities/bucket/adapters/bucket_adapter.js +2 -2
  30. package/lib/elements/entities/bucket/adapters/memory.nql.d.ts +1 -1
  31. package/lib/elements/entities/bucket/adapters/memory.nql.js +9 -5
  32. package/lib/elements/entities/bucket/bucket.d.ts +13 -2
  33. package/lib/elements/entities/bucket/bucket.js +47 -3
  34. package/lib/elements/entities/bucket/graph/bucket_graph.d.ts +11 -0
  35. package/lib/elements/entities/bucket/graph/bucket_graph.js +49 -2
  36. package/lib/elements/entities/bucket/model/bucket_model.schema.js +14 -11
  37. package/lib/elements/entities/bucket/query/nql_engine.d.ts +2 -2
  38. package/lib/elements/entities/bucket/query/nql_engine.js +8 -4
  39. package/lib/elements/entities/bucket/view/bucket_view.js +65 -12
  40. package/lib/engine/apps/app.config.d.ts +24 -30
  41. package/lib/engine/apps/app.config.js +11 -21
  42. package/lib/engine/apps/app.d.ts +6 -5
  43. package/lib/engine/apps/app.js +1 -1
  44. package/lib/engine/apps/distributed/distributed.app.config.d.ts +44 -0
  45. package/lib/engine/apps/distributed/distributed.app.config.js +36 -0
  46. package/lib/engine/apps/distributed/distributed.app.d.ts +30 -0
  47. package/lib/engine/apps/distributed/distributed.app.js +52 -0
  48. package/lib/engine/apps/distributed/distributed_node.app.d.ts +67 -0
  49. package/lib/engine/apps/distributed/distributed_node.app.js +191 -0
  50. package/lib/engine/apps/distributed/elements/distributed_job.d.ts +7 -0
  51. package/lib/engine/apps/distributed/elements/distributed_job.js +11 -0
  52. package/lib/engine/apps/distributed/inc/inc.client.d.ts +17 -0
  53. package/lib/engine/apps/distributed/inc/inc.client.js +105 -0
  54. package/lib/engine/apps/distributed/inc/inc.server.d.ts +19 -0
  55. package/lib/engine/apps/distributed/inc/inc.server.js +174 -0
  56. package/lib/engine/apps/distributed/inc/sandbox.d.ts +1 -0
  57. package/lib/engine/apps/distributed/inc/sandbox.js +24 -0
  58. package/lib/engine/apps/inline.app.d.ts +2 -2
  59. package/lib/engine/apps/inline.app.js +2 -2
  60. package/lib/engine/apps/monolyth/monolyth.app.d.ts +2 -2
  61. package/lib/engine/apps/monolyth/monolyth.app.js +1 -1
  62. package/lib/engine/module.d.ts +11 -1
  63. package/lib/engine/module.js +17 -4
  64. package/lib/engine/transaction/nodes/bucket.trx_node.d.ts +5 -0
  65. package/lib/engine/transaction/nodes/bucket.trx_node.js +10 -0
  66. package/lib/engine/transaction/nodes/bucket_query.trx_node.d.ts +2 -0
  67. package/lib/engine/transaction/nodes/bucket_query.trx_node.js +15 -4
  68. package/lib/engine/util/log.d.ts +1 -1
  69. package/lib/engine/util/log.js +3 -0
  70. package/package.json +1 -1
  71. package/tools/joaquin/bucket.d.ts +23 -3
  72. package/tools/joaquin/bucket.js +48 -20
  73. package/tools/joaquin/job.js +4 -4
  74. package/tsconfig.build.tsbuildinfo +1 -1
@@ -4,6 +4,7 @@ exports.BucketGraph = void 0;
4
4
  const trx_node_1 = require("../../../../engine/transaction/trx_node");
5
5
  const log_1 = require("../../../../engine/util/log");
6
6
  const error_1 = require("../../../../engine/data/error");
7
+ const memory_bucket_adapter_1 = require("../adapters/memory.bucket_adapter");
7
8
  /**
8
9
  * @category Elements
9
10
  * @subcategory Entity
@@ -35,7 +36,7 @@ class BucketGraph {
35
36
  '#and': tenancy
36
37
  }, {
37
38
  perPage: schema.many ? undefined : 1,
38
- }, { ...obj });
39
+ }, [{ ...obj }]);
39
40
  // Empty response
40
41
  if (!schema.many && !schema.optional && !links.data.length) {
41
42
  // silent = undefined
@@ -57,6 +58,52 @@ class BucketGraph {
57
58
  return links.data[0];
58
59
  }
59
60
  }
61
+ /**
62
+ * Read the data from a link
63
+ *
64
+ * - Options
65
+ * - `silent`: If not found, returns undefined instead of raising an exception (default: `false`)
66
+ * - `no_tenancy`: Don't apply tenancy rules (default: `false`)
67
+ */
68
+ async readManyLinks(trx, objs, link, options) {
69
+ log_1.Log.trace('bucket', this.bucketName, `Read link ${link}`);
70
+ const schema = this.schema.links[link];
71
+ // Make tenancy query
72
+ const tenancy = (options?.no_tenancy)
73
+ ? undefined
74
+ : this.bucket.getTenancyQuery(trx);
75
+ // Query
76
+ const otherBucket = trx_node_1.TrxNode.getModule(trx).buckets[schema.bucket.refName];
77
+ // let tempData: Record<string, any> = {};
78
+ let tempAdapter;
79
+ if (otherBucket.adapter instanceof memory_bucket_adapter_1.MemoryBucketAdapter) {
80
+ tempAdapter = otherBucket.adapter;
81
+ }
82
+ else {
83
+ const allLinks = await otherBucket.adapter.query(trx, {
84
+ ...schema.query,
85
+ '#and': tenancy
86
+ }, undefined, objs.map(obj => ({ ...obj })));
87
+ const tempData = {};
88
+ for (const obj of allLinks.data)
89
+ tempData[obj.id] = obj;
90
+ tempAdapter = new memory_bucket_adapter_1.MemoryBucketAdapter(otherBucket.schema, tempData);
91
+ }
92
+ const links = [];
93
+ for (const obj of objs) {
94
+ const result = await tempAdapter.query(trx, schema.query, {
95
+ perPage: schema.many ? undefined : 1,
96
+ }, [{ ...obj }], undefined, tempAdapter.nql);
97
+ if (schema.many) {
98
+ links.push(result.data);
99
+ }
100
+ else {
101
+ links.push(result.data[0]);
102
+ }
103
+ }
104
+ // Empty response
105
+ return links;
106
+ }
60
107
  /**
61
108
  * Read the data from a link and build it with a given view
62
109
  *
@@ -102,7 +149,7 @@ class BucketGraph {
102
149
  '#and': tenancy
103
150
  }, {
104
151
  perPage: 1,
105
- }, { ...obj });
152
+ }, [{ ...obj }]);
106
153
  return !!links.data.length;
107
154
  }
108
155
  }
@@ -55,7 +55,6 @@ class $BucketModel {
55
55
  }
56
56
  // If it's a list or dict, or an object
57
57
  if (field.type === 'list' || field.type === 'dict') {
58
- // If not, iterate
59
58
  next.push({
60
59
  i: item.i + 1,
61
60
  field: field.children['#']
@@ -70,6 +69,10 @@ class $BucketModel {
70
69
  })));
71
70
  continue;
72
71
  }
72
+ if (field.type === 'unknown') {
73
+ results.push(field);
74
+ continue;
75
+ }
73
76
  const child = field.children[path];
74
77
  if (child) {
75
78
  next.push({
@@ -127,53 +130,53 @@ class $BucketModel {
127
130
  while (poll.length) {
128
131
  const next = [];
129
132
  for (const entry of poll) {
130
- const val = obj[entry.path];
133
+ const val = entry.obj[entry.path];
131
134
  if (val === undefined) {
132
135
  continue;
133
136
  }
134
137
  if (val === null) {
135
- copy[entry.path] = null;
138
+ entry.copy[entry.path] = null;
136
139
  continue;
137
140
  }
138
141
  if (entry.field.type === 'list') {
139
142
  if (!Array.isArray(val))
140
143
  continue;
141
- copy[entry.path] = [];
144
+ entry.copy[entry.path] = [];
142
145
  next.push(...val.map((_, i) => ({
143
146
  path: i.toString(),
144
147
  obj: val,
145
- copy: copy[entry.path],
148
+ copy: entry.copy[entry.path],
146
149
  field: entry.field.children['*']
147
150
  })));
148
151
  }
149
152
  else if (entry.field.type === 'dict') {
150
153
  if (typeof val !== 'object' || Array.isArray(val))
151
154
  continue;
152
- copy[entry.path] = {};
155
+ entry.copy[entry.path] = {};
153
156
  next.push(...Object.keys(val).map((path) => ({
154
157
  path,
155
158
  obj: val,
156
- copy: copy[entry.path],
159
+ copy: entry.copy[entry.path],
157
160
  field: entry.field.children['*']
158
161
  })));
159
162
  }
160
163
  else if (entry.field.type === 'obj') {
161
164
  if (typeof val !== 'object' || Array.isArray(val))
162
165
  continue;
163
- copy[entry.path] = {};
166
+ entry.copy[entry.path] = {};
164
167
  next.push(...Object.keys(entry.field.children).map(path => ({
165
168
  path: path,
166
169
  obj: val,
167
- copy: copy[entry.path],
170
+ copy: entry.copy[entry.path],
168
171
  field: entry.field.children[path]
169
172
  })));
170
173
  }
171
174
  else if (entry.field.type === 'union') {
172
175
  // TODO: ??????????
173
- copy[entry.path] = obj[entry.path];
176
+ entry.copy[entry.path] = entry.obj[entry.path];
174
177
  }
175
178
  else {
176
- copy[entry.path] = obj[entry.path];
179
+ entry.copy[entry.path] = entry.obj[entry.path];
177
180
  }
178
181
  }
179
182
  poll = next;
@@ -15,7 +15,7 @@ export type NQL_Result<T = Obj> = {
15
15
  * @category NQL
16
16
  * */
17
17
  export declare abstract class NQLRunner {
18
- abstract run(trx: AnyTrxNode, part: NQL_Part, params: Record<string, any>, pagination?: NQL_Pagination, view?: $BucketView): Promise<NQL_Result>;
18
+ abstract run(trx: AnyTrxNode, part: NQL_Part, params: Record<string, any>[], pagination?: NQL_Pagination, view?: $BucketView): Promise<NQL_Result>;
19
19
  }
20
20
  /**
21
21
  * @category NQL
@@ -24,7 +24,7 @@ export declare class NQL_Engine {
24
24
  private module;
25
25
  private runners;
26
26
  constructor(module: AnyModule);
27
- run(trx: AnyTrxNode, query: NQL_CompiledQuery, pagination?: NQL_Pagination, params?: Record<string, any>, view?: $BucketView): Promise<NQL_Result>;
27
+ run(trx: AnyTrxNode, query: NQL_CompiledQuery, pagination?: NQL_Pagination, params?: Record<string, any>[], view?: $BucketView, runner?: NQLRunner): Promise<NQL_Result>;
28
28
  linkExternal(bucket: AnyBucket): void;
29
29
  }
30
30
  export {};
@@ -22,7 +22,9 @@ class NQL_Engine {
22
22
  }
23
23
  }
24
24
  }
25
- async run(trx, query, pagination, params = {}, view) {
25
+ async run(trx, query, pagination, params = [{}], view, runner) {
26
+ if (!params.length)
27
+ params = [{}];
26
28
  let result = {
27
29
  data: []
28
30
  };
@@ -30,8 +32,8 @@ class NQL_Engine {
30
32
  const part_i = query.execOrder[i];
31
33
  const part = query.parts[part_i];
32
34
  // Run part
33
- const runner = this.runners[part.union.meta.scope];
34
- const out = await runner.run(trx, part, params, pagination, view);
35
+ const _runner = runner || this.runners[part.union.meta.scope];
36
+ const out = await _runner.run(trx, part, params, pagination, view);
35
37
  result = out;
36
38
  // Part failed, return
37
39
  // Failure here is only when a single value is expected,
@@ -43,7 +45,9 @@ class NQL_Engine {
43
45
  }
44
46
  }
45
47
  // Fill part params
46
- params[`%__${part_i}__%`] = part.many ? result.data : result.data[0];
48
+ for (const paramGroup of params) {
49
+ paramGroup[`%__${part_i}__%`] = part.many ? result.data : result.data[0];
50
+ }
47
51
  }
48
52
  return result;
49
53
  }
@@ -4,9 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BucketView = void 0;
7
+ const trx_node_1 = require("../../../../engine/transaction/trx_node");
7
8
  const promise_1 = __importDefault(require("../../../../engine/util/promise"));
8
9
  const error_1 = require("../../../../engine/data/error");
9
10
  const tree_1 = require("../../../../engine/data/tree");
11
+ const dependency_1 = require("../../../../engine/dependency");
10
12
  class ViewValue {
11
13
  constructor() {
12
14
  this.value = undefined;
@@ -27,6 +29,7 @@ class BucketView {
27
29
  Object.assign(parsed, raw);
28
30
  }
29
31
  let layer = Object.values(this.schema.fields).map(field => ({
32
+ bucket: this.bucket,
30
33
  field,
31
34
  data: [{
32
35
  raw,
@@ -54,6 +57,7 @@ class BucketView {
54
57
  parseds.push(parsed);
55
58
  }
56
59
  let layer = Object.values(this.schema.fields).map(field => ({
60
+ bucket: this.bucket,
57
61
  field,
58
62
  data: raws.map((raw, i) => ({
59
63
  raw,
@@ -89,7 +93,7 @@ class BucketView {
89
93
  for (const node of layer) {
90
94
  if (node.field.scope !== 'graph')
91
95
  continue;
92
- await this.parseGraphProp(trx, node);
96
+ next.push(...await this.parseGraphProp(trx, node));
93
97
  }
94
98
  // Drive props
95
99
  for (const node of layer) {
@@ -109,6 +113,7 @@ class BucketView {
109
113
  }
110
114
  }
111
115
  next.push(...Object.values(node.field.children).map(field => ({
116
+ bucket: node.bucket,
112
117
  field,
113
118
  data: node.data
114
119
  })));
@@ -118,6 +123,7 @@ class BucketView {
118
123
  if (!node.field.chain)
119
124
  continue;
120
125
  next.push({
126
+ bucket: node.bucket,
121
127
  field: node.field.chain,
122
128
  data: node.data.map(d => ({
123
129
  index: d.index,
@@ -144,6 +150,7 @@ class BucketView {
144
150
  if (key === '__raw')
145
151
  continue;
146
152
  next.push({
153
+ bucket: node.bucket,
147
154
  field: node.field.children[key],
148
155
  data: nextData
149
156
  });
@@ -249,7 +256,7 @@ class BucketView {
249
256
  async parseComputedProp(trx, node) {
250
257
  const meta = node.field.meta.computed;
251
258
  for (const entry of node.data) {
252
- entry.target[node.field.name] = await promise_1.default.solve(meta.fn({ trx, raw: entry.raw, bucket: this.bucket.schema }));
259
+ entry.target[node.field.name] = await promise_1.default.solve(meta.fn({ trx, raw: entry.raw, bucket: node.bucket.schema }));
253
260
  }
254
261
  }
255
262
  /**
@@ -257,23 +264,69 @@ class BucketView {
257
264
  */
258
265
  async parseGraphProp(trx, node) {
259
266
  const meta = node.field.meta.graph;
260
- for (const entry of node.data) {
261
- let link;
262
- if (!meta.view) {
263
- link = this.bucket.graph.readLink(trx, entry.raw, meta.link, { silent: true });
267
+ const links = await node.bucket.graph.readManyLinks(trx, node.data.map(entry => entry.raw), meta.link, { silent: true });
268
+ for (let i = 0; i < links.length; i++) {
269
+ if (meta.view) {
270
+ const link = node.bucket.schema.graph.links[meta.link];
271
+ node.data[i].target[node.field.name] = link.many ? [] : {};
264
272
  }
265
273
  else {
266
- link = this.bucket.graph.viewLink(trx, entry.raw, meta.link, meta.view, { silent: true });
274
+ node.data[i].target[node.field.name] = links[i];
267
275
  }
268
- entry.target[node.field.name] = await promise_1.default.solve(link);
269
276
  }
277
+ let next = [];
278
+ if (meta.view) {
279
+ const schema = node.bucket.schema;
280
+ const otherBucketDep = schema.graph.links[meta.link].bucket;
281
+ const module = trx_node_1.TrxNode.getModule(trx);
282
+ const otherBucket = dependency_1.$Dependency.resolve(module.schema, otherBucketDep);
283
+ const view = otherBucket.views[meta.view];
284
+ const { __raw, ...v } = view.fields;
285
+ const link = node.bucket.schema.graph.links[meta.link];
286
+ let nextData;
287
+ if (link.many) {
288
+ const _links = links;
289
+ for (let i = 0; i < _links.length; i++) {
290
+ const target = node.data[i].target[node.field.name];
291
+ for (let j = 0; j < _links[i].length; j++) {
292
+ target.push(__raw ? { ..._links[i][j] } : {});
293
+ target[j].$v = meta.view;
294
+ }
295
+ }
296
+ nextData = _links.map((ll, i) => ll.map((l, j) => ({ value: l, target: node.data[i].target[node.field.name][j] }))).flat(1);
297
+ }
298
+ else {
299
+ const _links = links;
300
+ for (let i = 0; i < _links.length; i++) {
301
+ const target = node.data[i].target[node.field.name];
302
+ if (__raw) {
303
+ Object.assign(target, _links[i]);
304
+ }
305
+ target.$v = meta.view;
306
+ }
307
+ nextData = _links.map((l, i) => ({
308
+ value: l, target: node.data[i].target[node.field.name]
309
+ }));
310
+ }
311
+ next = Object.values(v).map(field => ({
312
+ bucket: module.buckets[otherBucketDep.refName],
313
+ field,
314
+ data: nextData.map($ => ({
315
+ raw: $.value,
316
+ value: $.value,
317
+ index: [],
318
+ target: $.target
319
+ }))
320
+ }));
321
+ }
322
+ return next;
270
323
  }
271
324
  /**
272
325
  * [drive]
273
326
  */
274
327
  async parseDriveProp(trx, node) {
275
- if (!this.bucket.drive) {
276
- throw error_1.NesoiError.Bucket.Drive.NoAdapter({ bucket: this.bucket.schema.alias });
328
+ if (!node.bucket.drive) {
329
+ throw error_1.NesoiError.Bucket.Drive.NoAdapter({ bucket: node.bucket.schema.alias });
277
330
  }
278
331
  const meta = node.field.meta.drive;
279
332
  for (const entry of node.data) {
@@ -281,12 +334,12 @@ class BucketView {
281
334
  if (Array.isArray(value)) {
282
335
  const public_urls = [];
283
336
  for (const obj of value) {
284
- public_urls.push(await this.bucket.drive.public(obj));
337
+ public_urls.push(await node.bucket.drive.public(obj));
285
338
  }
286
339
  entry.target[node.field.name] = public_urls;
287
340
  }
288
341
  else {
289
- entry.target[node.field.name] = await this.bucket.drive.public(value);
342
+ entry.target[node.field.name] = await node.bucket.drive.public(value);
290
343
  }
291
344
  }
292
345
  }
@@ -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() {
@@ -0,0 +1,44 @@
1
+ import { $Space, ModuleName } from "../../../schema";
2
+ import { CompilerConfig } from "../../../compiler/compiler";
3
+ import { AppAuthnConfig, AppI18nConfig, AppConfig, AppControllerConfig, AppTrashConfig } from '../app.config';
4
+ import { CLIConfig } from "../../cli/cli";
5
+ import { IService } from '../service';
6
+ import { DistributedAppNode } from './distributed_node.app';
7
+ import { TrxEngineConfig } from "../../transaction/trx_engine.config";
8
+ import { BucketConfig } from "../../../elements/entities/bucket/bucket.config";
9
+ export type DistributedAppModuleConfig<S extends $Space, M extends ModuleName<S>, Nodes extends Record<string, DistributedAppNode<any, any, any, any>>, Services extends Record<string, IService>> = {
10
+ buckets?: DistributedAppBucketConfig<S, M, Nodes, Services>;
11
+ jobs?: DistributedAppJobConfig<S, M, Nodes>;
12
+ trash?: AppTrashConfig<Services>;
13
+ controllers?: AppControllerConfig<S, M, Services>;
14
+ trx?: TrxEngineConfig<S, S['modules'][M], any, Services>;
15
+ };
16
+ export type DistributedAppConfig<S extends $Space, Modules extends ModuleName<S>, Nodes extends Record<string, DistributedAppNode<any, any, any, any>>, Services extends Record<string, IService>> = {
17
+ authn?: AppAuthnConfig<S>;
18
+ modules?: Partial<{
19
+ [M in (Modules & keyof S['modules'])]: DistributedAppModuleConfig<S, M, Nodes, Services>;
20
+ }>;
21
+ i18n?: AppI18nConfig;
22
+ cli?: CLIConfig<any>;
23
+ compiler?: CompilerConfig;
24
+ };
25
+ export type AnyAppConfig = AppConfig<any, any, any>;
26
+ export type DistributedAppBucketConfig<S extends $Space, M extends keyof S['modules'], Nodes extends Record<string, DistributedAppNode<any, any, any, any>>, Services extends Record<string, IService>> = Partial<{
27
+ [K in keyof S['modules'][M]['buckets']]: keyof Nodes | BucketConfig<S['modules'][M], S['modules'][M]['buckets'][K], Services>;
28
+ }>;
29
+ export type DistributedAppJobConfig<S extends $Space, M extends keyof S['modules'], Nodes extends Record<string, DistributedAppNode<any, any, any, any>>> = Partial<{
30
+ [K in keyof S['modules'][M]['jobs']]: keyof Nodes;
31
+ }>;
32
+ /**
33
+ * @category DistributedApp
34
+ */
35
+ export declare class DistributedAppConfigBuilder<S extends $Space, Nodes extends Record<string, DistributedAppNode<any, any, any, any>>, Modules extends string = ModuleName<S> & string, Services extends Record<string, any> = Record<string, any>> {
36
+ private node;
37
+ constructor(node: DistributedAppNode<S, Nodes, Modules, Services>);
38
+ authn(config: AppAuthnConfig<S>): DistributedAppNode<S, Nodes, Modules, Services>;
39
+ module<M extends Modules>(name: M, config: DistributedAppModuleConfig<S, M, Nodes, Services>): DistributedAppNode<S, Nodes, Modules, Services>;
40
+ audit(config: AppI18nConfig): DistributedAppNode<S, Nodes, Modules, Services>;
41
+ i18n(config: AppI18nConfig): DistributedAppNode<S, Nodes, Modules, Services>;
42
+ cli(config: CLIConfig<Services>): DistributedAppNode<S, Nodes, Modules, Services>;
43
+ compiler(config: CompilerConfig): DistributedAppNode<S, Nodes, Modules, Services>;
44
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DistributedAppConfigBuilder = void 0;
4
+ /**
5
+ * @category DistributedApp
6
+ */
7
+ class DistributedAppConfigBuilder {
8
+ constructor(node) {
9
+ this.node = node;
10
+ }
11
+ authn(config) {
12
+ // TODO
13
+ return this.node;
14
+ }
15
+ module(name, config) {
16
+ // TODO
17
+ return this.node;
18
+ }
19
+ audit(config) {
20
+ // TODO
21
+ return this.node;
22
+ }
23
+ i18n(config) {
24
+ // TODO
25
+ return this.node;
26
+ }
27
+ cli(config) {
28
+ // TODO
29
+ return this.node;
30
+ }
31
+ compiler(config) {
32
+ // TODO
33
+ return this.node;
34
+ }
35
+ }
36
+ exports.DistributedAppConfigBuilder = DistributedAppConfigBuilder;