nesoi 3.2.4 → 3.2.6
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.
- package/lib/compiler/treeshake.js +4 -4
- package/lib/elements/blocks/job/internal/resource_job.builder.d.ts +1 -1
- package/lib/elements/blocks/job/internal/resource_job.builder.js +4 -1
- package/lib/elements/blocks/resource/resource.builder.js +6 -4
- package/lib/elements/entities/bucket/adapters/json.bucket_adapter.d.ts +44 -0
- package/lib/elements/entities/bucket/adapters/json.bucket_adapter.js +151 -0
- package/lib/elements/entities/bucket/adapters/memory.bucket_adapter.js +6 -4
- package/lib/elements/entities/bucket/adapters/memory.nql.js +2 -2
- package/lib/elements/entities/bucket/model/bucket_model.convert.d.ts +1 -1
- package/lib/elements/entities/bucket/model/bucket_model.convert.js +4 -4
- package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +7 -1
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +5 -0
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +7 -0
- package/lib/elements/entities/bucket/query/nql_compiler.js +3 -2
- package/lib/elements/entities/bucket/view/bucket_view.js +12 -6
- package/lib/elements/entities/message/template/message_template.schema.d.ts +3 -0
- package/lib/elements/entities/message/template/message_template_field.builder.d.ts +1 -0
- package/lib/elements/entities/message/template/message_template_field.builder.js +7 -0
- package/lib/elements/entities/message/template/message_template_parser.js +2 -0
- package/lib/engine/apps/distributed/distributed.app.d.ts +6 -0
- package/lib/engine/apps/distributed/distributed.app.js +10 -0
- package/lib/engine/apps/inline.app.d.ts +6 -1
- package/lib/engine/apps/inline.app.js +10 -0
- package/lib/engine/apps/monolyth/monolyth.app.d.ts +6 -0
- package/lib/engine/apps/monolyth/monolyth.app.js +10 -0
- package/lib/engine/cli/cli.d.ts +2 -1
- package/lib/engine/cli/cli.js +79 -1
- package/lib/engine/daemon.d.ts +23 -1
- package/lib/engine/daemon.js +10 -0
- package/lib/engine/data/error.d.ts +6 -0
- package/lib/engine/data/error.js +4 -0
- package/lib/engine/dependency.d.ts +4 -1
- package/lib/engine/util/parse.d.ts +4 -0
- package/lib/engine/util/parse.js +11 -0
- package/package.json +1 -1
- package/tools/joaquin/mock.js +3 -0
- package/tsconfig.build.tsbuildinfo +1 -1
package/lib/engine/cli/cli.js
CHANGED
|
@@ -1,9 +1,44 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
exports.CLI = void 0;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
7
42
|
const string_1 = require("../util/string");
|
|
8
43
|
const ui_1 = __importDefault(require("./ui"));
|
|
9
44
|
const console_1 = __importDefault(require("../util/console"));
|
|
@@ -11,6 +46,7 @@ const daemon_1 = require("../daemon");
|
|
|
11
46
|
const log_1 = require("../util/log");
|
|
12
47
|
const cli_input_1 = require("./cli_input");
|
|
13
48
|
const shell_1 = __importDefault(require("../util/shell"));
|
|
49
|
+
const crypto_1 = require("crypto");
|
|
14
50
|
/**
|
|
15
51
|
* @category Engine
|
|
16
52
|
* @subcategory CLI
|
|
@@ -70,6 +106,12 @@ class CLI {
|
|
|
70
106
|
this.cmdClear();
|
|
71
107
|
return false;
|
|
72
108
|
}
|
|
109
|
+
// > invoke
|
|
110
|
+
const invoke = payload.match(/invoke (.*)/);
|
|
111
|
+
if (invoke) {
|
|
112
|
+
await this.cmdInvoke(invoke[1]);
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
73
115
|
for (const name in this.adapters) {
|
|
74
116
|
if (!payload.startsWith(name))
|
|
75
117
|
continue;
|
|
@@ -87,6 +129,7 @@ class CLI {
|
|
|
87
129
|
let str = '' +
|
|
88
130
|
`${(0, string_1.colored)('general', 'brown')}\n` +
|
|
89
131
|
`\t${(0, string_1.colored)('help', 'lightcyan')}\n\t\tShow this info\n` +
|
|
132
|
+
`\t${(0, string_1.colored)('invoke [JOB]', 'lightcyan')}\n\t\tInvoke a job by refName (module::name)\n` +
|
|
90
133
|
`\t${(0, string_1.colored)('exit', 'lightcyan')}\n\t\tClose the CLI\n` +
|
|
91
134
|
`\t${(0, string_1.colored)('clear', 'lightcyan')}\n\t\tClear the sceen\n`;
|
|
92
135
|
Object.values(this.adapters).forEach(adapter => {
|
|
@@ -97,6 +140,35 @@ class CLI {
|
|
|
97
140
|
async cmdClear() {
|
|
98
141
|
console.clear();
|
|
99
142
|
}
|
|
143
|
+
async cmdInvoke(job) {
|
|
144
|
+
const [module, name] = job.split('::');
|
|
145
|
+
if (!module || !name) {
|
|
146
|
+
ui_1.default.error(`Invalid job '${job}'. Expected "module::name"`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const tmpFile = 'job_input__' + (0, crypto_1.randomBytes)(8).toString('hex') + '.js';
|
|
150
|
+
const tmpPath = path.join(process.cwd(), tmpFile);
|
|
151
|
+
fs.writeFileSync(tmpPath, 'export const input = {\n \n}');
|
|
152
|
+
await this.daemon.trx(module).run(async (trx) => {
|
|
153
|
+
const job = trx.job(name);
|
|
154
|
+
let done = false;
|
|
155
|
+
while (!done) {
|
|
156
|
+
if (await this.openEditor(tmpPath))
|
|
157
|
+
break;
|
|
158
|
+
try {
|
|
159
|
+
delete require.cache[tmpPath];
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
161
|
+
const input = require(tmpPath).input;
|
|
162
|
+
await job.run(input);
|
|
163
|
+
done = true;
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
ui_1.default.error(e.toString());
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
fs.rmSync(tmpPath);
|
|
171
|
+
}
|
|
100
172
|
getCmds() {
|
|
101
173
|
const cmds = [];
|
|
102
174
|
for (const a in this.adapters) {
|
|
@@ -108,9 +180,15 @@ class CLI {
|
|
|
108
180
|
}
|
|
109
181
|
return cmds;
|
|
110
182
|
}
|
|
111
|
-
openEditor(file) {
|
|
183
|
+
async openEditor(file) {
|
|
112
184
|
const editor = this.config?.editor || 'code';
|
|
113
185
|
shell_1.default.cmd(process.cwd(), `${editor} ${file}`);
|
|
186
|
+
if (!['vi', 'vim', 'nano'].includes(editor)) {
|
|
187
|
+
const res = await ui_1.default.waitForAnyKey('Aperte qualquer tecla após salvar o arquivo');
|
|
188
|
+
if (res.sequence === '\x03')
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
return false;
|
|
114
192
|
}
|
|
115
193
|
}
|
|
116
194
|
exports.CLI = CLI;
|
package/lib/engine/daemon.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { AnyAppConfig } from './apps/app.config';
|
|
|
5
5
|
import { AnyUsers, AuthnRequest } from './auth/authn';
|
|
6
6
|
import { TrxNode } from './transaction/trx_node';
|
|
7
7
|
import { TrxStatus } from './transaction/trx';
|
|
8
|
-
import { AnyModule } from './module';
|
|
8
|
+
import { AnyElementSchema, AnyModule } from './module';
|
|
9
9
|
import { IService } from './apps/service';
|
|
10
10
|
/**
|
|
11
11
|
* A background process running one or more modules,
|
|
@@ -59,6 +59,16 @@ export declare abstract class Daemon<S extends $Space, Modules extends ModuleNam
|
|
|
59
59
|
* @param services A dictionary of Service by name
|
|
60
60
|
*/
|
|
61
61
|
reload(trxEngines: Record<Modules, AnyTrxEngine>, services: Record<string, any>): void;
|
|
62
|
+
/**
|
|
63
|
+
* Bind the controller of each module to this Daemon.
|
|
64
|
+
* This allows the registered `Controller Adapters` to run
|
|
65
|
+
* transactions on the daemon.
|
|
66
|
+
*/
|
|
67
|
+
protected abstract getSchema(tag: {
|
|
68
|
+
module: keyof S['modules'];
|
|
69
|
+
type: string;
|
|
70
|
+
name: string;
|
|
71
|
+
}): Promise<AnyElementSchema>;
|
|
62
72
|
/**
|
|
63
73
|
* Return a `Daemon` property.
|
|
64
74
|
* This is used to read private properties.
|
|
@@ -80,6 +90,18 @@ export declare abstract class Daemon<S extends $Space, Modules extends ModuleNam
|
|
|
80
90
|
* @returns The `Module` instance
|
|
81
91
|
*/
|
|
82
92
|
static getModule<Module extends ModuleName<any>, D extends Daemon<any, Module>>(daemon: D, module: Module): import("./module").Module<any, any>;
|
|
93
|
+
/**
|
|
94
|
+
* Return one module of the `Daemon` by name.
|
|
95
|
+
*
|
|
96
|
+
* @param daemon A `Daemon` instance
|
|
97
|
+
* @param module A module name
|
|
98
|
+
* @returns The `Module` instance
|
|
99
|
+
*/
|
|
100
|
+
static getSchema<Module extends ModuleName<any>, D extends Daemon<any, Module>>(daemon: D, tag: {
|
|
101
|
+
module: Module;
|
|
102
|
+
type: string;
|
|
103
|
+
name: string;
|
|
104
|
+
}): Promise<AnyElementSchema>;
|
|
83
105
|
/**
|
|
84
106
|
* Return all modules of the `Daemon`.
|
|
85
107
|
*
|
package/lib/engine/daemon.js
CHANGED
|
@@ -113,6 +113,16 @@ class Daemon {
|
|
|
113
113
|
static getModule(daemon, module) {
|
|
114
114
|
return daemon.trxEngines[module].getModule();
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Return one module of the `Daemon` by name.
|
|
118
|
+
*
|
|
119
|
+
* @param daemon A `Daemon` instance
|
|
120
|
+
* @param module A module name
|
|
121
|
+
* @returns The `Module` instance
|
|
122
|
+
*/
|
|
123
|
+
static getSchema(daemon, tag) {
|
|
124
|
+
return daemon.getSchema(tag);
|
|
125
|
+
}
|
|
116
126
|
/**
|
|
117
127
|
* Return all modules of the `Daemon`.
|
|
118
128
|
*
|
|
@@ -168,6 +168,12 @@ export declare namespace NesoiError {
|
|
|
168
168
|
type: string;
|
|
169
169
|
module: string;
|
|
170
170
|
}): BaseError;
|
|
171
|
+
function InvalidLiteral($: {
|
|
172
|
+
alias: string;
|
|
173
|
+
path: string;
|
|
174
|
+
value: any;
|
|
175
|
+
template: string;
|
|
176
|
+
}): BaseError;
|
|
171
177
|
function InvalidEnumScope($: {
|
|
172
178
|
alias: string;
|
|
173
179
|
path: string;
|
package/lib/engine/data/error.js
CHANGED
|
@@ -305,6 +305,10 @@ var NesoiError;
|
|
|
305
305
|
return new BaseError('Message.NotSupportedByModule', `Message of type '${$.type}' is not supported by module '${$.module}'`, Status.BAD_REQUEST, $);
|
|
306
306
|
}
|
|
307
307
|
Message.NotSupportedByModule = NotSupportedByModule;
|
|
308
|
+
function InvalidLiteral($) {
|
|
309
|
+
return new BaseError('Message.InvalidLiteral', `Message field '${$.alias}' does not match the template '${$.template}'`, Status.BAD_REQUEST, $);
|
|
310
|
+
}
|
|
311
|
+
Message.InvalidLiteral = InvalidLiteral;
|
|
308
312
|
function InvalidEnumScope($) {
|
|
309
313
|
return new BaseError('Message.InvalidEnumScope', `${$.alias} is an enum with dynamic scope, and the path '${$.fieldpath}' of the message has an invalid value '${$.value}'`, Status.BAD_REQUEST, $);
|
|
310
314
|
}
|
|
@@ -80,7 +80,10 @@ export declare class $Dependency {
|
|
|
80
80
|
* @returns The type name of the dependency
|
|
81
81
|
*/
|
|
82
82
|
static typeName(dep: $Dependency, fromModule: string): string;
|
|
83
|
-
static resolve(module: $Module, dep:
|
|
83
|
+
static resolve(module: $Module, dep: {
|
|
84
|
+
type: string;
|
|
85
|
+
name: string;
|
|
86
|
+
}): import("../elements").$Message | import("../elements").$Machine | import("../elements").$Bucket | import("../elements").$Constants | import("../elements").$Job | import("../elements").$Externals | import("../elements").$Resource | import("../elements").$Controller | undefined;
|
|
84
87
|
}
|
|
85
88
|
/**
|
|
86
89
|
* A element builder, along with metadata required for building it.
|
|
@@ -58,6 +58,10 @@ export declare function parseString(field: {
|
|
|
58
58
|
pathRaw: string;
|
|
59
59
|
alias: string;
|
|
60
60
|
}, path: string[], value: any): string;
|
|
61
|
+
export declare function parseLiteral(field: {
|
|
62
|
+
pathRaw: string;
|
|
63
|
+
alias: string;
|
|
64
|
+
}, path: string[], value: any, template: string): string;
|
|
61
65
|
export declare function parseStringOrNumber(field: {
|
|
62
66
|
pathRaw: string;
|
|
63
67
|
alias: string;
|
package/lib/engine/util/parse.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.parseFloat_ = parseFloat_;
|
|
|
11
11
|
exports.parseId = parseId;
|
|
12
12
|
exports.parseInt_ = parseInt_;
|
|
13
13
|
exports.parseString = parseString;
|
|
14
|
+
exports.parseLiteral = parseLiteral;
|
|
14
15
|
exports.parseStringOrNumber = parseStringOrNumber;
|
|
15
16
|
exports.parseDict = parseDict;
|
|
16
17
|
exports.parseList = parseList;
|
|
@@ -171,6 +172,16 @@ function parseString(field, path, value) {
|
|
|
171
172
|
}
|
|
172
173
|
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'string' });
|
|
173
174
|
}
|
|
175
|
+
function parseLiteral(field, path, value, template) {
|
|
176
|
+
if (typeof value === 'string') {
|
|
177
|
+
const regex = new RegExp(template);
|
|
178
|
+
if (!value.match(regex)) {
|
|
179
|
+
throw error_1.NesoiError.Message.InvalidLiteral({ alias: field.alias, path: path.join('.'), value, template });
|
|
180
|
+
}
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'string' });
|
|
184
|
+
}
|
|
174
185
|
function parseStringOrNumber(field, path, value) {
|
|
175
186
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
176
187
|
return value;
|
package/package.json
CHANGED
package/tools/joaquin/mock.js
CHANGED
|
@@ -104,6 +104,9 @@ class BucketMockObj {
|
|
|
104
104
|
else if (field.type === 'string') {
|
|
105
105
|
return Mock.string();
|
|
106
106
|
}
|
|
107
|
+
else if (field.type === 'literal') {
|
|
108
|
+
return field.meta.literal.template; // TODO: generate based on template
|
|
109
|
+
}
|
|
107
110
|
else if (field.type === 'unknown') {
|
|
108
111
|
// TODO
|
|
109
112
|
return undefined;
|