nesoi 3.0.21 → 3.1.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 (91) hide show
  1. package/lib/compiler/apps/monolyth/stages/2_build_typescript_stage.js +1 -0
  2. package/lib/compiler/apps/monolyth/stages/4_dump_modules_stage.js +8 -0
  3. package/lib/compiler/compiler.js +1 -1
  4. package/lib/compiler/elements/bucket.element.d.ts +3 -2
  5. package/lib/compiler/elements/bucket.element.js +86 -128
  6. package/lib/compiler/elements/element.js +4 -2
  7. package/lib/compiler/elements/externals.element.js +3 -0
  8. package/lib/compiler/elements/machine.element.js +2 -2
  9. package/lib/compiler/elements/message.element.js +35 -57
  10. package/lib/compiler/elements/queue.element.js +1 -1
  11. package/lib/compiler/helpers/dump_helpers.d.ts +5 -3
  12. package/lib/compiler/helpers/dump_helpers.js +43 -26
  13. package/lib/compiler/stages/4_build_schemas_stage.js +12 -0
  14. package/lib/compiler/stages/5_inject_ts_stage.js +4 -1
  15. package/lib/compiler/stages/7_dump_stage.js +7 -1
  16. package/lib/compiler/treeshake.js +4 -2
  17. package/lib/compiler/typescript/bridge/extract.js +37 -107
  18. package/lib/compiler/typescript/bridge/inject.d.ts +1 -1
  19. package/lib/compiler/typescript/bridge/inject.js +73 -45
  20. package/lib/compiler/typescript/bridge/organize.js +9 -5
  21. package/lib/compiler/typescript/typescript_compiler.d.ts +4 -6
  22. package/lib/compiler/typescript/typescript_compiler.js +139 -75
  23. package/lib/elements/blocks/block.builder.d.ts +1 -10
  24. package/lib/elements/blocks/block.builder.js +0 -32
  25. package/lib/elements/blocks/job/internal/resource_job.builder.d.ts +3 -21
  26. package/lib/elements/blocks/job/job.builder.d.ts +6 -20
  27. package/lib/elements/blocks/job/job.builder.js +0 -4
  28. package/lib/elements/blocks/machine/machine.builder.d.ts +5 -14
  29. package/lib/elements/blocks/machine/machine.builder.js +2 -2
  30. package/lib/elements/blocks/queue/queue.builder.d.ts +6 -15
  31. package/lib/elements/blocks/queue/queue.builder.js +2 -2
  32. package/lib/elements/edge/externals/externals.builder.d.ts +2 -0
  33. package/lib/elements/edge/externals/externals.builder.js +6 -1
  34. package/lib/elements/edge/externals/externals.schema.d.ts +2 -1
  35. package/lib/elements/edge/externals/externals.schema.js +3 -1
  36. package/lib/elements/entities/bucket/adapters/bucket_adapter.d.ts +1 -1
  37. package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.d.ts +7 -0
  38. package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +46 -36
  39. package/lib/elements/entities/bucket/adapters/memory.nql.js +1 -1
  40. package/lib/elements/entities/bucket/bucket.builder.d.ts +6 -4
  41. package/lib/elements/entities/bucket/bucket.js +42 -43
  42. package/lib/elements/entities/bucket/bucket.schema.d.ts +2 -1
  43. package/lib/elements/entities/bucket/cache/bucket_cache.d.ts +1 -4
  44. package/lib/elements/entities/bucket/graph/bucket_graph.infer.d.ts +7 -5
  45. package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.d.ts +2 -1
  46. package/lib/elements/entities/bucket/model/bucket_model.builder.d.ts +1 -1
  47. package/lib/elements/entities/bucket/model/bucket_model.convert.d.ts +1 -1
  48. package/lib/elements/entities/bucket/model/bucket_model.convert.js +4 -4
  49. package/lib/elements/entities/bucket/model/bucket_model.infer.d.ts +41 -9
  50. package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +8 -6
  51. package/lib/elements/entities/bucket/model/bucket_model.schema.js +184 -21
  52. package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +89 -56
  53. package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +22 -30
  54. package/lib/elements/entities/bucket/query/nql.schema.d.ts +13 -10
  55. package/lib/elements/entities/bucket/query/nql_compiler.js +46 -21
  56. package/lib/elements/entities/bucket/view/bucket_view.builder.js +1 -1
  57. package/lib/elements/entities/bucket/view/bucket_view.d.ts +19 -0
  58. package/lib/elements/entities/bucket/view/bucket_view.js +230 -108
  59. package/lib/elements/entities/bucket/view/bucket_view.schema.d.ts +5 -10
  60. package/lib/elements/entities/bucket/view/bucket_view.schema.js +3 -5
  61. package/lib/elements/entities/bucket/view/bucket_view_field.builder.d.ts +16 -12
  62. package/lib/elements/entities/bucket/view/bucket_view_field.builder.js +55 -40
  63. package/lib/elements/entities/message/message.builder.d.ts +1 -11
  64. package/lib/elements/entities/message/message.infer.d.ts +6 -30
  65. package/lib/elements/entities/message/message.schema.js +2 -2
  66. package/lib/elements/entities/message/template/message_template.builder.js +1 -1
  67. package/lib/elements/entities/message/template/message_template.schema.d.ts +10 -15
  68. package/lib/elements/entities/message/template/message_template.schema.js +29 -12
  69. package/lib/elements/entities/message/template/message_template_field.builder.d.ts +45 -209
  70. package/lib/elements/entities/message/template/message_template_field.builder.js +69 -85
  71. package/lib/elements/entities/message/template/message_template_parser.js +52 -64
  72. package/lib/engine/apps/inline.app.js +1 -0
  73. package/lib/engine/data/trash.js +7 -7
  74. package/lib/engine/data/tree.d.ts +3 -0
  75. package/lib/engine/data/tree.js +36 -0
  76. package/lib/engine/space.js +1 -1
  77. package/lib/engine/transaction/trx_engine.config.d.ts +3 -2
  78. package/lib/engine/transaction/trx_engine.d.ts +9 -1
  79. package/lib/engine/transaction/trx_engine.js +52 -9
  80. package/lib/engine/util/deep.js +4 -0
  81. package/lib/engine/util/parse.d.ts +22 -14
  82. package/lib/engine/util/parse.js +20 -5
  83. package/lib/engine/util/type.d.ts +3 -0
  84. package/package.json +1 -1
  85. package/tools/joaquin/bucket.d.ts +9 -0
  86. package/tools/joaquin/bucket.js +49 -0
  87. package/tools/joaquin/message.d.ts +2 -1
  88. package/tools/joaquin/message.js +9 -2
  89. package/tools/joaquin/mock.d.ts +1 -0
  90. package/tools/joaquin/mock.js +13 -5
  91. package/tsconfig.build.tsbuildinfo +1 -1
@@ -2,9 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DumpHelpers = void 0;
4
4
  class DumpHelpers {
5
- static dumpType(type, d = 0) {
6
- const pad0 = ' '.repeat(d);
7
- const pad1 = ' '.repeat(d + 1);
5
+ static dumpUnionType(types, singleLine = false) {
6
+ if (types.length < 2)
7
+ return this.dumpType(types[0], singleLine);
8
+ return '(' + types.map(t => this.dumpType(t, singleLine)).join(' | ') + ')';
9
+ }
10
+ static dumpIntersectionType(types, singleLine = false) {
11
+ if (types.length < 2)
12
+ return this.dumpType(types[0], singleLine);
13
+ return '(' + types.map(t => this.dumpType(t, singleLine)).join(' | ') + ')';
14
+ }
15
+ static dumpType(type, singleLine = false, d = 0) {
16
+ const pad0 = singleLine ? ' ' : ' '.repeat(d);
17
+ const pad1 = singleLine ? ' ' : ' '.repeat(d + 1);
18
+ const lb = singleLine ? '' : '\n';
8
19
  let str = '';
9
20
  if (typeof type === 'undefined') {
10
21
  str = 'never';
@@ -17,20 +28,25 @@ class DumpHelpers {
17
28
  }
18
29
  else if (Array.isArray(type)) {
19
30
  if (type.length) {
20
- str = '(' + type.map(t => this.dumpType(t)).join(' | ') + ')';
31
+ str = '(' + type.map(t => this.dumpType(t, singleLine)).join(' | ') + ')';
21
32
  }
22
33
  else {
23
34
  str = 'never';
24
35
  }
25
36
  }
26
37
  else {
27
- str = '{\n' +
38
+ str = '{' + lb +
28
39
  Object.entries(type)
29
40
  .filter(([key]) => !['__array', '__optional', '__or'].includes(key))
30
41
  .map(([key, value]) => {
31
42
  let k = key;
43
+ // If key contains ${, it's a template string
44
+ if (k.includes('${')) {
45
+ // Put single quotes around non-alphanumeric keys
46
+ k = '[_: `' + key + '`]';
47
+ }
32
48
  // If key is not a special [],
33
- if (!(k.startsWith('[') && k.endsWith(']'))
49
+ else if (!(k.startsWith('[') && k.endsWith(']'))
34
50
  && !(k.startsWith('`') && k.endsWith('`'))) {
35
51
  // Put single quotes around non-alphanumeric keys
36
52
  k = /[^\w]/.exec(key) ? `'${key}'` : key;
@@ -48,14 +64,14 @@ class DumpHelpers {
48
64
  k += '?';
49
65
  }
50
66
  // Dump element type
51
- const t = this.dumpType(value, d + 1);
67
+ const t = this.dumpType(value, singleLine, d + 1);
52
68
  return `${pad1}${k}: ${t}`;
53
- }).join(',\n')
54
- + `\n${pad0}}`;
69
+ }).join(',' + lb)
70
+ + `${lb}${pad0}}`;
55
71
  }
56
72
  if (typeof type === 'object') {
57
73
  if (type.__or) {
58
- str += ' | ' + this.dumpType(type.__or, d);
74
+ str += ' | ' + this.dumpType(type.__or, singleLine, d);
59
75
  }
60
76
  if (type.__array) {
61
77
  str = `(${str})[]`;
@@ -66,9 +82,10 @@ class DumpHelpers {
66
82
  }
67
83
  return str;
68
84
  }
69
- static dumpSchema(val, d = 0) {
70
- const pad0 = ' '.repeat(d);
71
- const pad1 = ' '.repeat(d + 1);
85
+ static dumpSchema(val, singleLine = false, d = 0) {
86
+ const pad0 = singleLine ? ' ' : ' '.repeat(d);
87
+ const pad1 = singleLine ? ' ' : ' '.repeat(d + 1);
88
+ const lb = singleLine ? '' : '\n';
72
89
  if (typeof val === 'undefined') {
73
90
  return 'undefined';
74
91
  }
@@ -85,22 +102,22 @@ class DumpHelpers {
85
102
  return val.description || 'undefined';
86
103
  }
87
104
  else if (Array.isArray(val)) {
88
- return '[\n' +
105
+ return '[' + lb +
89
106
  val.map(child => {
90
- return `${pad1}${this.dumpSchema(child, d + 1)}`;
91
- }).join(',\n')
92
- + `\n${pad0}]`;
107
+ return `${pad1}${this.dumpSchema(child, singleLine, d + 1)}`;
108
+ }).join(',' + lb)
109
+ + `${lb}${pad0}]`;
93
110
  }
94
111
  else if (typeof val === 'object') {
95
112
  if ('__fn' in val) {
96
113
  return val.__fn;
97
114
  }
98
- return '{\n' +
115
+ return '{' + lb +
99
116
  Object.entries(val).map(([key, child]) => {
100
117
  const _key = key.match(/\W/) ? `'${key}'` : key;
101
- return `${pad1}${_key}: ${this.dumpSchema(child, d + 1)}`;
102
- }).join(',\n')
103
- + `\n${pad0}}`;
118
+ return `${pad1}${_key}: ${this.dumpSchema(child, singleLine, d + 1)}`;
119
+ }).join(',' + lb)
120
+ + `${lb}${pad0}}`;
104
121
  }
105
122
  else if (typeof val === 'function') {
106
123
  return this.dumpFunction(val, pad0);
@@ -109,10 +126,10 @@ class DumpHelpers {
109
126
  }
110
127
  static dumpFunction(fn, padding = '') {
111
128
  // Functions should have been replaced by { __fn: ... } by the Compiler,
112
- // if any is missed, this flag causes a typescript error when compiling.
113
- return `/* TS BRIDGE ERROR: function not properly extracted from source. Function: ${fn.toString()} */`;
129
+ // if not, we try to use the JS version.
130
+ return `/* TS BRIDGE WARN: function not properly extracted from source. Attempting JS version (imports will not work) */ (${fn.toString()}) as any`;
114
131
  }
115
- static dumpValueToType(value, transform = {}, d = 2) {
132
+ static dumpValueToType(value, transform = {}, singleLine = false, d = 2) {
116
133
  if (value === undefined) {
117
134
  return 'undefined';
118
135
  }
@@ -133,7 +150,7 @@ class DumpHelpers {
133
150
  if (value.length === 0) {
134
151
  return 'never[]';
135
152
  }
136
- return '[' + value.map((v) => DumpHelpers.dumpType(this.dumpValueToType(v, transform, d + 1), d)).join(', ') + ']';
153
+ return '[' + value.map((v) => DumpHelpers.dumpType(this.dumpValueToType(v, transform, singleLine, d + 1), singleLine, d)).join(', ') + ']';
137
154
  }
138
155
  else {
139
156
  const obj = {};
@@ -148,7 +165,7 @@ class DumpHelpers {
148
165
  obj[key] = transform[key](value);
149
166
  }
150
167
  else {
151
- obj[key] = this.dumpValueToType(value, transform[key], d + 1);
168
+ obj[key] = this.dumpValueToType(value, transform[key], singleLine, d + 1);
152
169
  }
153
170
  });
154
171
  return obj;
@@ -17,6 +17,7 @@ class BuildSchemasStage {
17
17
  log_1.Log.info('compiler', 'stage.build_schemas', 'Building schemas...');
18
18
  const t0 = new Date().getTime();
19
19
  await this.compiler.tree.traverse('Building schemas ', async (node) => {
20
+ var _a;
20
21
  const module = this.compiler.modules[node.module].module;
21
22
  if (node.progressive) {
22
23
  await module.inject({
@@ -24,6 +25,17 @@ class BuildSchemasStage {
24
25
  });
25
26
  return;
26
27
  }
28
+ // Accummulate imports from depencies
29
+ // (Given that dependencies are built in order)
30
+ node.bridge ?? (node.bridge = { imports: [] });
31
+ (_a = node.bridge).imports ?? (_a.imports = []);
32
+ for (const dep of node.dependencies) {
33
+ // If a dependency is inline and the node is it's root,
34
+ // they already share imports.
35
+ if (dep.node.root == node)
36
+ continue;
37
+ node.bridge.imports.push(...(dep.node.bridge?.imports || []));
38
+ }
27
39
  // Inline nodes are built by their root builder
28
40
  if (node.isInline) {
29
41
  return;
@@ -19,7 +19,10 @@ class InjectTSStage {
19
19
  const t0 = new Date().getTime();
20
20
  const { tree } = this.compiler;
21
21
  const nodes = tree.allNodes();
22
- inject_1.TSBridgeInject.inject(this.compiler, nodes);
22
+ tree.traverse('inject', node => {
23
+ inject_1.TSBridgeInject.inject(this.compiler, nodes, node);
24
+ return Promise.resolve();
25
+ });
23
26
  const t = new Date().getTime();
24
27
  log_1.Log.debug('compiler', 'stage.inject_ts', `[t: ${(t - t0) / 1000} ms]`);
25
28
  log_1.Log.trace('compiler', 'stage.inject_ts', 'Finished injecting TS code');
@@ -38,9 +38,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.DumpStage = void 0;
40
40
  const fs = __importStar(require("fs"));
41
+ const path_1 = __importDefault(require("path"));
41
42
  const log_1 = require("../../engine/util/log");
42
43
  const name_helpers_1 = require("../helpers/name_helpers");
43
- const path_1 = __importDefault(require("path"));
44
44
  const dependency_1 = require("../../engine/dependency");
45
45
  const bucket_element_1 = require("../elements/bucket.element");
46
46
  const dump_helpers_1 = require("../helpers/dump_helpers");
@@ -240,6 +240,12 @@ class DumpStage {
240
240
  Object.entries(externals.schema.buckets).forEach(([tag, ref]) => {
241
241
  type.buckets[tag] = dependency_1.$Dependency.typeName(ref, module.lowName);
242
242
  });
243
+ if (!type.messages) {
244
+ type.messages = {};
245
+ }
246
+ Object.entries(externals.schema.messages).forEach(([tag, ref]) => {
247
+ type.messages[tag] = dependency_1.$Dependency.typeName(ref, module.lowName);
248
+ });
243
249
  if (!type.jobs) {
244
250
  type.jobs = {};
245
251
  }
@@ -19,10 +19,12 @@ class Treeshake {
19
19
  const b = node.builder;
20
20
  const $b = b.$b;
21
21
  const buckets = b.buckets;
22
+ const messages = b.messages;
22
23
  const jobs = b.jobs;
23
24
  log_1.Log.trace('compiler', 'treeshake', `${' '.repeat(depth)} └ Treeshaking node ${(0, log_1.scopeTag)($b, node.name)}`);
24
25
  node.dependencies = [
25
26
  ...Object.values(buckets),
27
+ ...Object.values(messages),
26
28
  ...Object.values(jobs)
27
29
  ];
28
30
  node.dependencies = this.cleanNodeDependencies(node);
@@ -141,10 +143,10 @@ class Treeshake {
141
143
  nestedInlines.push(...deps.inlines);
142
144
  }
143
145
  }
144
- // Inlines have a dependency on their parent node
146
+ // Inlines are a dependency of their parent node
145
147
  const inlines = [..._inlineNodes, ...nestedInlines];
146
148
  inlines.forEach(inline => {
147
- inline.dependencies.push(new dependency_1.$Dependency(node.module, node.type, node.name));
149
+ dependencies.push(new dependency_1.$Dependency(inline.module, inline.type, inline.name));
148
150
  });
149
151
  return {
150
152
  dependencies,
@@ -45,9 +45,7 @@ class TSBridgeExtract {
45
45
  }
46
46
  return;
47
47
  }
48
- const imports = tsCompiler.extractImports(node.filepath, {
49
- ignore: [] // TODO: ignore space file
50
- });
48
+ const imports = tsCompiler.extractImports(node.filepath);
51
49
  if (imports.length) {
52
50
  log_1.Log.debug('compiler', 'bridge.extract', `Extracted TS imports from ${node.filepath}`, imports);
53
51
  }
@@ -103,141 +101,89 @@ class TSBridgeExtract {
103
101
  }
104
102
  if (node.builder.$b === 'message') {
105
103
  functions.push(...tsCompiler.query(node.filepath, {
106
- query: 'message.*.template.0.return.**.rule.0',
107
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
104
+ query: 'message.*.template.0.return.*.rule.0',
105
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
108
106
  }));
109
- }
110
- if (node.builder.$b === 'job') {
111
107
  functions.push(...tsCompiler.query(node.filepath, {
112
- query: 'job.*.messages.0.return.*.**.rule.0',
113
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
108
+ query: 'message.*.template.0.return.*.{~.#.*?}.rule.0',
109
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
114
110
  }));
111
+ }
112
+ if (node.builder.$b === 'job') {
115
113
  functions.push(...tsCompiler.query(node.filepath, {
116
- query: 'job.*.extra.0',
117
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
114
+ query: 'job.*.message.1.return.*.rule.0',
115
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
118
116
  }));
119
117
  functions.push(...tsCompiler.query(node.filepath, {
120
- query: 'job.*.assert.0',
121
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
118
+ query: 'job.*.message.1.return.*.{~.#.*?}.rule.0',
119
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
122
120
  }));
123
121
  functions.push(...tsCompiler.query(node.filepath, {
124
- query: 'job.*.method.0',
122
+ query: 'job.*.extra|assert|method.0',
125
123
  expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
126
124
  }));
127
125
  }
128
126
  if (node.builder.$b === 'resource') {
129
127
  functions.push(...tsCompiler.query(node.filepath, {
130
- query: 'resource.*.create.0.return.input.0.return.**.rule.0',
131
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
132
- }));
133
- functions.push(...tsCompiler.query(node.filepath, {
134
- query: 'resource.*.create.0.return.extra.0',
135
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
136
- }));
137
- functions.push(...tsCompiler.query(node.filepath, {
138
- query: 'resource.*.create.0.return.assert.0',
139
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
140
- }));
141
- functions.push(...tsCompiler.query(node.filepath, {
142
- query: 'resource.*.create.0.return.prepare.0',
143
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
128
+ query: 'resource.*.create.0.return.input.0.return.*.rule.0',
129
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
144
130
  }));
145
131
  functions.push(...tsCompiler.query(node.filepath, {
146
- query: 'resource.*.create.0.return.after.0',
147
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
132
+ query: 'resource.*.create.0.return.input.0.return.*.{~.#.*?}.rule.0',
133
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
148
134
  }));
149
135
  functions.push(...tsCompiler.query(node.filepath, {
150
- query: 'resource.*.update.0.return.input.0.return.**.rule.0',
136
+ query: 'resource.*.create.0.return.extra|assert|prepare|after.0',
151
137
  expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
152
138
  }));
153
139
  functions.push(...tsCompiler.query(node.filepath, {
154
- query: 'resource.*.update.0.return.extra.0',
155
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
140
+ query: 'resource.*.update.0.return.input.0.return.*.rule.0',
141
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
156
142
  }));
157
143
  functions.push(...tsCompiler.query(node.filepath, {
158
- query: 'resource.*.update.0.return.assert.0',
159
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
144
+ query: 'resource.*.update.0.return.input.0.return.*.{~.#.*?}.rule.0',
145
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
160
146
  }));
161
147
  functions.push(...tsCompiler.query(node.filepath, {
162
- query: 'resource.*.update.0.return.prepare.0',
148
+ query: 'resource.*.update.0.return.extra|assert|prepare|after.0',
163
149
  expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
164
150
  }));
165
151
  functions.push(...tsCompiler.query(node.filepath, {
166
- query: 'resource.*.update.0.return.after.0',
167
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
152
+ query: 'resource.*.delete.0.return.input.0.return.*.rule.0',
153
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
168
154
  }));
169
155
  functions.push(...tsCompiler.query(node.filepath, {
170
- query: 'resource.*.delete.0.return.input.0.return.**.rule.0',
171
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
172
- }));
173
- functions.push(...tsCompiler.query(node.filepath, {
174
- query: 'resource.*.delete.0.return.extra.0',
175
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
156
+ query: 'resource.*.delete.0.return.input.0.return.*.{~.#.*?}.rule.0',
157
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
176
158
  }));
177
159
  functions.push(...tsCompiler.query(node.filepath, {
178
- query: 'resource.*.delete.0.return.assert.0',
179
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
180
- }));
181
- functions.push(...tsCompiler.query(node.filepath, {
182
- query: 'resource.*.delete.0.return.prepare.0',
183
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
184
- }));
185
- functions.push(...tsCompiler.query(node.filepath, {
186
- query: 'resource.*.delete.0.return.after.0',
160
+ query: 'resource.*.delete.0.return.extra|assert|prepare|after.0',
187
161
  expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
188
162
  }));
189
163
  }
190
164
  if (node.builder.$b === 'machine') {
191
165
  functions.push(...tsCompiler.query(node.filepath, {
192
- query: 'machine.*.messages.0.return.*.**.rule.0',
193
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
166
+ query: 'machine.*.message.1.return.**.rule.0',
167
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
194
168
  }));
195
169
  functions.push(...tsCompiler.query(node.filepath, {
196
- query: 'machine.*.{state.1.return}.beforeEnter.0.return.extra.0',
197
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
170
+ query: 'machine.*.message.1.return.{**.obj.0}.**.rule.0',
171
+ expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression, ts.SyntaxKind.PropertyAccessExpression]
198
172
  }));
199
173
  functions.push(...tsCompiler.query(node.filepath, {
200
- query: 'machine.*.{state.1.return}.beforeEnter.0.return.assert.0',
174
+ query: 'machine.*.{state.1.return}.beforeEnter.0.return.extra|assert|method.0',
201
175
  expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
202
176
  }));
203
177
  functions.push(...tsCompiler.query(node.filepath, {
204
- query: 'machine.*.{state.1.return}.beforeEnter.0.return.method.0',
178
+ query: 'machine.*.{state.1.return}.afterEnter.0.return.extra|assert|method.0',
205
179
  expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
206
180
  }));
207
181
  functions.push(...tsCompiler.query(node.filepath, {
208
- query: 'machine.*.{state.1.return}.afterEnter.0.return.extra.0',
182
+ query: 'machine.*.{state.1.return}.beforeLeave.0.return.extra|assert|method.0',
209
183
  expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
210
184
  }));
211
185
  functions.push(...tsCompiler.query(node.filepath, {
212
- query: 'machine.*.{state.1.return}.afterEnter.0.return.assert.0',
213
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
214
- }));
215
- functions.push(...tsCompiler.query(node.filepath, {
216
- query: 'machine.*.{state.1.return}.afterEnter.0.return.method.0',
217
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
218
- }));
219
- functions.push(...tsCompiler.query(node.filepath, {
220
- query: 'machine.*.{state.1.return}.beforeLeave.0.return.extra.0',
221
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
222
- }));
223
- functions.push(...tsCompiler.query(node.filepath, {
224
- query: 'machine.*.{state.1.return}.beforeLeave.0.return.assert.0',
225
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
226
- }));
227
- functions.push(...tsCompiler.query(node.filepath, {
228
- query: 'machine.*.{state.1.return}.beforeLeave.0.return.method.0',
229
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
230
- }));
231
- functions.push(...tsCompiler.query(node.filepath, {
232
- query: 'machine.*.{state.1.return}.afterLeave.0.return.extra.0',
233
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
234
- }));
235
- functions.push(...tsCompiler.query(node.filepath, {
236
- query: 'machine.*.{state.1.return}.afterLeave.0.return.assert.0',
237
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
238
- }));
239
- functions.push(...tsCompiler.query(node.filepath, {
240
- query: 'machine.*.{state.1.return}.afterLeave.0.return.method.0',
186
+ query: 'machine.*.{state.1.return}.afterLeave.0.return.extra|assert|method.0',
241
187
  expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
242
188
  }));
243
189
  functions.push(...tsCompiler.query(node.filepath, {
@@ -249,27 +195,11 @@ class TSBridgeExtract {
249
195
  expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
250
196
  }));
251
197
  functions.push(...tsCompiler.query(node.filepath, {
252
- query: 'machine.*.{state.1.return}.transition.1.return.runJob.0.return.extra.0',
253
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
254
- }));
255
- functions.push(...tsCompiler.query(node.filepath, {
256
- query: 'machine.*.{state.1.return}.transition.1.return.{else.0.return}.runJob.0.return.extra.0',
257
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
258
- }));
259
- functions.push(...tsCompiler.query(node.filepath, {
260
- query: 'machine.*.{state.1.return}.transition.1.return.runJob.0.return.assert.0',
261
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
262
- }));
263
- functions.push(...tsCompiler.query(node.filepath, {
264
- query: 'machine.*.{state.1.return}.transition.1.return.{else.0.return}.runJob.0.return.assert.0',
265
- expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
266
- }));
267
- functions.push(...tsCompiler.query(node.filepath, {
268
- query: 'machine.*.{state.1.return}.transition.1.return.runJob.0.return.method.0',
198
+ query: 'machine.*.{state.1.return}.transition.1.return.runJob.0.return.extra|assert|method.0',
269
199
  expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
270
200
  }));
271
201
  functions.push(...tsCompiler.query(node.filepath, {
272
- query: 'machine.*.{state.1.return}.transition.1.return.{else.0.return}.runJob.0.return.method.0',
202
+ query: 'machine.*.{state.1.return}.transition.1.return.{else.0.return}.runJob.0.return.extra|assert|method.0',
273
203
  expectedKinds: [ts.SyntaxKind.FunctionExpression, ts.SyntaxKind.ArrowFunction, ts.SyntaxKind.Identifier, ts.SyntaxKind.CallExpression]
274
204
  }));
275
205
  }
@@ -1,7 +1,7 @@
1
1
  import { ResolvedBuilderNode } from "../../../engine/dependency";
2
2
  import { Compiler } from "../../compiler";
3
3
  export declare class TSBridgeInject {
4
- static inject(compiler: Compiler, nodes: ResolvedBuilderNode[]): void;
4
+ static inject(compiler: Compiler, nodes: ResolvedBuilderNode[], node: ResolvedBuilderNode): void;
5
5
  private static bucket;
6
6
  private static message;
7
7
  private static job;
@@ -2,40 +2,37 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TSBridgeInject = void 0;
4
4
  const log_1 = require("../../../engine/util/log");
5
+ const message_template_schema_1 = require("../../../elements/entities/message/template/message_template.schema");
5
6
  const name_helpers_1 = require("../../helpers/name_helpers");
6
7
  class TSBridgeInject {
7
- static inject(compiler, nodes) {
8
+ static inject(compiler, nodes, node) {
8
9
  const { tsCompiler } = compiler;
9
- nodes.forEach(node => {
10
- if (node.progressive)
10
+ if (node.progressive)
11
+ return;
12
+ log_1.Log.debug('compiler', 'bridge.inject', `Injecting TS code on ${node.tag}`);
13
+ const schema = node.schema;
14
+ if (schema.$t === 'bucket') {
15
+ const extract = node.bridge?.extract;
16
+ if (!extract)
11
17
  return;
12
- log_1.Log.debug('compiler', 'bridge.inject', `Injecting TS code on ${node.tag}`);
13
- const schema = node.schema;
14
- if (schema.$t === 'bucket') {
15
- const extract = node.bridge?.extract;
16
- if (!extract)
17
- return;
18
- this.bucket(compiler, extract, node);
19
- }
20
- if (schema.$t === 'message') {
21
- const extract = node.bridge?.extract;
22
- if (!extract)
23
- return;
24
- this.message(compiler, extract, node);
25
- }
26
- if (schema.$t === 'job') {
27
- const extract = node.bridge?.extract;
28
- if (!extract)
29
- return;
30
- this.job(compiler, extract, node);
31
- }
32
- if (schema.$t === 'machine') {
33
- const extract = node.bridge?.extract;
34
- if (!extract)
35
- return;
36
- this.machine(compiler, extract, node);
37
- }
38
- });
18
+ this.bucket(compiler, extract, node);
19
+ }
20
+ if (schema.$t === 'message') {
21
+ const extract = node.bridge?.extract;
22
+ this.message(compiler, extract, nodes, node);
23
+ }
24
+ if (schema.$t === 'job') {
25
+ const extract = node.bridge?.extract;
26
+ if (!extract)
27
+ return;
28
+ this.job(compiler, extract, node);
29
+ }
30
+ if (schema.$t === 'machine') {
31
+ const extract = node.bridge?.extract;
32
+ if (!extract)
33
+ return;
34
+ this.machine(compiler, extract, node);
35
+ }
39
36
  }
40
37
  static bucket(compiler, extract, node) {
41
38
  const { tsCompiler } = compiler;
@@ -47,7 +44,7 @@ class TSBridgeInject {
47
44
  prop.split('.').forEach(p => {
48
45
  f = f.children[p];
49
46
  });
50
- f.value.computed = { fn: {
47
+ f.meta.computed = { fn: {
51
48
  __fn: tsCompiler.getFnText(node),
52
49
  __fn_type: '(...args: any[]) => any', // TODO: evaluate
53
50
  } };
@@ -55,22 +52,53 @@ class TSBridgeInject {
55
52
  });
56
53
  });
57
54
  }
58
- static message(compiler, extract, node) {
55
+ static message(compiler, extract, nodes, node) {
59
56
  const { tsCompiler } = compiler;
60
57
  const schema = node.schema;
61
- const typeName = name_helpers_1.NameHelpers.names(schema).type;
62
- Object.entries(extract.rules).forEach(([prop, node]) => {
63
- let f = { children: schema.template.fields };
64
- let addr = '';
65
- prop.split('.').forEach(p => {
66
- f = f.children[p];
67
- addr += `['${p}${f.type === 'id' ? '_id' : ''}']`;
68
- });
69
- const type = `$MessageTemplateRule<${typeName}['#raw']${addr}, ${typeName}['#raw']>`;
70
- f.rules = node.map(fn => ({
71
- __fn: tsCompiler.getFnText(fn),
72
- __fn_type: '(...args: any[]) => any', // TODO: evaluate
73
- }));
58
+ const _extract = extract ? { rules: { ...extract.rules } } : { rules: {} };
59
+ // Step 1: Go through all .msg() fields of the message,
60
+ // and join the referenced extract into this.
61
+ message_template_schema_1.$MessageTemplate.forEachField(schema.template, (field, path) => {
62
+ if (!field.meta.msg)
63
+ return;
64
+ const ref = nodes.find(node => node.tag === field.meta.msg.tag);
65
+ if (!ref) {
66
+ throw new Error(`Unable to inject code from .msg() field, ${field.meta.msg.tag} not found`);
67
+ }
68
+ const refExtract = ref.bridge?.extract;
69
+ if (!refExtract)
70
+ return;
71
+ for (const key in refExtract.rules) {
72
+ const _path = path + '.' + key;
73
+ _extract.rules[_path] = refExtract.rules[key];
74
+ }
75
+ });
76
+ const getFields = (root, prop) => {
77
+ const path = prop.split('.');
78
+ let poll = [root];
79
+ for (const p of path) {
80
+ if (poll.length === 0)
81
+ break;
82
+ // Walk to next layer of fields by path
83
+ const next = [];
84
+ for (const n of poll) {
85
+ const child = n.children?.[p];
86
+ if (child) {
87
+ next.push(child);
88
+ }
89
+ }
90
+ poll = next;
91
+ }
92
+ return poll;
93
+ };
94
+ Object.entries(_extract?.rules || {}).forEach(([path, rules]) => {
95
+ const fields = getFields({ children: schema.template.fields }, path);
96
+ for (const field of fields) {
97
+ field.rules = rules.map(fn => ({
98
+ __fn: tsCompiler.getFnText(fn),
99
+ __fn_type: '(...args: any[]) => any',
100
+ }));
101
+ }
74
102
  });
75
103
  }
76
104
  static job(compiler, extract, node) {