miolo 0.9.34 → 0.9.35
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/dist/cli/miolo.cli.iife.bundle.js +1 -1
- package/dist/cli/miolo.cli.iife.bundle.min.js +1 -1
- package/dist/cli/miolo.cli.iife.js +1 -1
- package/dist/cli/miolo.cli.iife.min.js +1 -1
- package/dist/cli/miolo.cli.min.mjs +1 -1
- package/dist/cli/miolo.cli.mjs +1 -1
- package/dist/cli/miolo.cli.umd.bundle.js +1 -1
- package/dist/cli/miolo.cli.umd.bundle.min.js +1 -1
- package/dist/cli/miolo.cli.umd.js +1 -1
- package/dist/cli/miolo.cli.umd.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.bundle.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.bundle.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.min.mjs +1 -1
- package/dist/cli-react/miolo.cli-react.mjs +1 -1
- package/dist/cli-react/miolo.cli-react.umd.bundle.js +1 -1
- package/dist/cli-react/miolo.cli-react.umd.bundle.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.umd.js +1 -1
- package/dist/cli-react/miolo.cli-react.umd.min.js +1 -1
- package/dist/server/miolo.server.cjs +296 -35
- package/dist/server/miolo.server.min.mjs +2 -2
- package/dist/server/miolo.server.mjs +241 -36
- package/dist/server/miolo.server.mjs.map +1 -1
- package/dist/server/miolo.server.node.mjs +296 -36
- package/package.json +3 -2
package/dist/cli/miolo.cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* miolo v0.9.
|
|
2
|
+
* miolo v0.9.35
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Donato Lorenzo <donato@afialapis.com>
|
|
5
5
|
*
|
|
@@ -18,10 +18,11 @@ var path = require('node:path');
|
|
|
18
18
|
var node_url = require('node:url');
|
|
19
19
|
var calustra = require('calustra');
|
|
20
20
|
var nodemailer = require('nodemailer');
|
|
21
|
+
var fs = require('node:fs');
|
|
21
22
|
var tinguir = require('tinguir');
|
|
22
23
|
var util = require('node:util');
|
|
23
24
|
var winston = require('winston');
|
|
24
|
-
var
|
|
25
|
+
var intre = require('intre');
|
|
25
26
|
var koa_body_parser = require('koa-better-body');
|
|
26
27
|
var koa_convert = require('koa-convert');
|
|
27
28
|
var koa_compress = require('koa-compress');
|
|
@@ -542,8 +543,8 @@ var base_config = {
|
|
|
542
543
|
// redirect_url: '/',
|
|
543
544
|
// error_code: 401
|
|
544
545
|
// },
|
|
545
|
-
// before: (ctx) => {return
|
|
546
|
-
// after : (ctx, result) => {return
|
|
546
|
+
// before: async (ctx) => {return bool} // If bool false, query callback not run
|
|
547
|
+
// after : async (ctx, result) => {return modified_result}
|
|
547
548
|
|
|
548
549
|
crud: [{
|
|
549
550
|
prefix: '',
|
|
@@ -552,27 +553,38 @@ var base_config = {
|
|
|
552
553
|
url: '/../..', // default to 'name'
|
|
553
554
|
mode: 'r/w/rw',
|
|
554
555
|
bodyField: '',
|
|
555
|
-
useUserFields:
|
|
556
|
+
useUserFields: {
|
|
557
|
+
use: false,
|
|
558
|
+
fieldNames: {
|
|
559
|
+
created_by: 'created_by',
|
|
560
|
+
last_update_by: 'last_update_by'
|
|
561
|
+
}
|
|
562
|
+
}
|
|
556
563
|
auth: ...,
|
|
557
|
-
before:
|
|
558
|
-
after :
|
|
564
|
+
before: ...,
|
|
565
|
+
after : ...
|
|
559
566
|
*/]
|
|
560
567
|
}],
|
|
561
|
-
queries: [
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
568
|
+
queries: [/*
|
|
569
|
+
{
|
|
570
|
+
prefix: '',
|
|
571
|
+
auth: ...,
|
|
572
|
+
before: ...,
|
|
573
|
+
after : ...
|
|
574
|
+
routes: [
|
|
575
|
+
{
|
|
576
|
+
url: '/../..',
|
|
577
|
+
method: 'GET/POST',
|
|
578
|
+
callback: async (ctx) => { ctx.body = result } ,
|
|
579
|
+
// or
|
|
580
|
+
callback_fn: async (miolo, params) => { return result } ,
|
|
581
|
+
auth: ...,
|
|
582
|
+
before: ...,
|
|
583
|
+
after : ...
|
|
584
|
+
},
|
|
585
|
+
],
|
|
586
|
+
},
|
|
587
|
+
*/]
|
|
576
588
|
},
|
|
577
589
|
//cacher: {
|
|
578
590
|
// redis: {
|
|
@@ -960,11 +972,6 @@ function reopenTransportOnHupSignal(fileTransport) {
|
|
|
960
972
|
});
|
|
961
973
|
}
|
|
962
974
|
|
|
963
|
-
//import fs from 'fs'
|
|
964
|
-
//import path from 'path'
|
|
965
|
-
// import 'winston-daily-rotate-file'
|
|
966
|
-
//import { intre_to_str, intre_now } from 'intre'
|
|
967
|
-
|
|
968
975
|
var combine = winston.format.combine,
|
|
969
976
|
timestamp = winston.format.timestamp;
|
|
970
977
|
winston.format._label;
|
|
@@ -1029,10 +1036,44 @@ var init_logger = function init_logger(config, emailer, prefix) {
|
|
|
1029
1036
|
filename: config != null && (_config$file2 = config.file) != null && _config$file2.filename ? config.file.filename.replace('%MIOLO%', prefix) : '/var/log/afialapis/miolo.log',
|
|
1030
1037
|
level: (config == null || (_config$file3 = config.file) == null ? void 0 : _config$file3.level) || (config == null ? void 0 : config.level) || 'info',
|
|
1031
1038
|
humanReadableUnhandledException: true,
|
|
1032
|
-
handleExceptions: true
|
|
1039
|
+
handleExceptions: true,
|
|
1040
|
+
maxRetries: 10
|
|
1033
1041
|
});
|
|
1034
1042
|
reopenTransportOnHupSignal(fileTransport);
|
|
1035
1043
|
_log_transports.push(fileTransport);
|
|
1044
|
+
var _file_log = function _file_log(s) {
|
|
1045
|
+
var _config$console3;
|
|
1046
|
+
var filename = path.join(fileTransport.dirname, fileTransport.filename);
|
|
1047
|
+
|
|
1048
|
+
// console.log(fileTransport._stream )
|
|
1049
|
+
var msg = myFormat({
|
|
1050
|
+
level: 'info',
|
|
1051
|
+
message: "[logger][file-rotate] " + s + "\n",
|
|
1052
|
+
timestamp: intre.intre_now()
|
|
1053
|
+
});
|
|
1054
|
+
try {
|
|
1055
|
+
fs.accessSync(filename, fs.constants.F_OK);
|
|
1056
|
+
fs.appendFileSync(filename, msg);
|
|
1057
|
+
} catch (_) {
|
|
1058
|
+
fs.writeFileSync(filename, msg, {
|
|
1059
|
+
encoding: 'utf-8'
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
if ((config == null || (_config$console3 = config.console) == null ? void 0 : _config$console3.enabled) === true) {
|
|
1063
|
+
var _config$console4;
|
|
1064
|
+
if (fileTransport.levels[(config == null || (_config$console4 = config.console) == null ? void 0 : _config$console4.level) || (config == null ? void 0 : config.level) || 'error'] >= fileTransport.levels['info']) {
|
|
1065
|
+
console.log(msg);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
fileTransport.on('finish', function (info) {
|
|
1070
|
+
// do something fun
|
|
1071
|
+
_file_log('Log done');
|
|
1072
|
+
});
|
|
1073
|
+
fileTransport.on('error', function (error) {
|
|
1074
|
+
// do something fun
|
|
1075
|
+
_file_log(tinguir.red("Error: " + error));
|
|
1076
|
+
});
|
|
1036
1077
|
}
|
|
1037
1078
|
|
|
1038
1079
|
// if (config?.file?.enabled === true) {
|
|
@@ -1171,9 +1212,188 @@ var init_logger = function init_logger(config, emailer, prefix) {
|
|
|
1171
1212
|
return logger;
|
|
1172
1213
|
};
|
|
1173
1214
|
|
|
1215
|
+
var Parser = /*#__PURE__*/function () {
|
|
1216
|
+
function Parser() {}
|
|
1217
|
+
var _proto = Parser.prototype;
|
|
1218
|
+
_proto.parse_value_str = function parse_value_str(v, required, def) {
|
|
1219
|
+
if (required === void 0) {
|
|
1220
|
+
required = false;
|
|
1221
|
+
}
|
|
1222
|
+
if (def === void 0) {
|
|
1223
|
+
def = undefined;
|
|
1224
|
+
}
|
|
1225
|
+
if (v == null || v == undefined) {
|
|
1226
|
+
if (required) {
|
|
1227
|
+
throw "Wrong str value passed: " + v;
|
|
1228
|
+
}
|
|
1229
|
+
return def;
|
|
1230
|
+
}
|
|
1231
|
+
return v.toString();
|
|
1232
|
+
};
|
|
1233
|
+
_proto.parse_field_str = function parse_field_str(fields, name, required, def) {
|
|
1234
|
+
if (required === void 0) {
|
|
1235
|
+
required = false;
|
|
1236
|
+
}
|
|
1237
|
+
if (def === void 0) {
|
|
1238
|
+
def = undefined;
|
|
1239
|
+
}
|
|
1240
|
+
if (!(name in fields)) {
|
|
1241
|
+
if (required) {
|
|
1242
|
+
throw "Expected str value not passed for " + name;
|
|
1243
|
+
}
|
|
1244
|
+
return def;
|
|
1245
|
+
}
|
|
1246
|
+
return this.parse_value_str(fields[name], required, def);
|
|
1247
|
+
};
|
|
1248
|
+
_proto.parse_value_int = function parse_value_int(v, required, def) {
|
|
1249
|
+
if (required === void 0) {
|
|
1250
|
+
required = false;
|
|
1251
|
+
}
|
|
1252
|
+
if (def === void 0) {
|
|
1253
|
+
def = undefined;
|
|
1254
|
+
}
|
|
1255
|
+
var vi = parseInt(v);
|
|
1256
|
+
if (vi == null || isNaN(vi)) {
|
|
1257
|
+
if (required) {
|
|
1258
|
+
throw "Wrong int value passed: " + v;
|
|
1259
|
+
}
|
|
1260
|
+
return def;
|
|
1261
|
+
}
|
|
1262
|
+
return vi;
|
|
1263
|
+
};
|
|
1264
|
+
_proto.parse_field_int = function parse_field_int(fields, name, required, def) {
|
|
1265
|
+
if (required === void 0) {
|
|
1266
|
+
required = false;
|
|
1267
|
+
}
|
|
1268
|
+
if (def === void 0) {
|
|
1269
|
+
def = undefined;
|
|
1270
|
+
}
|
|
1271
|
+
if (!(name in fields)) {
|
|
1272
|
+
if (required) {
|
|
1273
|
+
throw "Expected int value not passed for " + name;
|
|
1274
|
+
}
|
|
1275
|
+
return def;
|
|
1276
|
+
}
|
|
1277
|
+
return this.parse_value_int(fields[name], required, def);
|
|
1278
|
+
};
|
|
1279
|
+
_proto.parse_value_float = function parse_value_float(v, required, def) {
|
|
1280
|
+
if (required === void 0) {
|
|
1281
|
+
required = false;
|
|
1282
|
+
}
|
|
1283
|
+
if (def === void 0) {
|
|
1284
|
+
def = undefined;
|
|
1285
|
+
}
|
|
1286
|
+
var vf = parseFloat(v);
|
|
1287
|
+
if (vf == null || isNaN(vf)) {
|
|
1288
|
+
if (required) {
|
|
1289
|
+
throw "Wrong float value passed: " + v;
|
|
1290
|
+
}
|
|
1291
|
+
return def;
|
|
1292
|
+
}
|
|
1293
|
+
return v;
|
|
1294
|
+
};
|
|
1295
|
+
_proto.parse_field_float = function parse_field_float(fields, name, required, def) {
|
|
1296
|
+
if (required === void 0) {
|
|
1297
|
+
required = false;
|
|
1298
|
+
}
|
|
1299
|
+
if (def === void 0) {
|
|
1300
|
+
def = undefined;
|
|
1301
|
+
}
|
|
1302
|
+
if (!(name in fields)) {
|
|
1303
|
+
if (required) {
|
|
1304
|
+
throw "Expected float value not passed for " + name;
|
|
1305
|
+
}
|
|
1306
|
+
return def;
|
|
1307
|
+
}
|
|
1308
|
+
return this.parse_value_float(fields[name], required, def);
|
|
1309
|
+
};
|
|
1310
|
+
_proto.parse_value_bool = function parse_value_bool(v, required, def) {
|
|
1311
|
+
if (required === void 0) {
|
|
1312
|
+
required = false;
|
|
1313
|
+
}
|
|
1314
|
+
if (def === void 0) {
|
|
1315
|
+
def = undefined;
|
|
1316
|
+
}
|
|
1317
|
+
if (v == null || v == undefined) {
|
|
1318
|
+
if (required) {
|
|
1319
|
+
throw "Wrong bool value passed for " + name;
|
|
1320
|
+
}
|
|
1321
|
+
return undefined;
|
|
1322
|
+
}
|
|
1323
|
+
if (v === true || v === 'true' || v === 'True' || v === 1 || v === '1') {
|
|
1324
|
+
return true;
|
|
1325
|
+
}
|
|
1326
|
+
if (v === false || v === 'false' || v === 'False' || v === 0 || v === '0') {
|
|
1327
|
+
return false;
|
|
1328
|
+
}
|
|
1329
|
+
return def;
|
|
1330
|
+
};
|
|
1331
|
+
_proto.parse_field_bool = function parse_field_bool(fields, name, required, def) {
|
|
1332
|
+
if (required === void 0) {
|
|
1333
|
+
required = false;
|
|
1334
|
+
}
|
|
1335
|
+
if (def === void 0) {
|
|
1336
|
+
def = undefined;
|
|
1337
|
+
}
|
|
1338
|
+
if (!(name in fields)) {
|
|
1339
|
+
if (required) {
|
|
1340
|
+
throw "Expected bool value not passed for " + name;
|
|
1341
|
+
}
|
|
1342
|
+
return def;
|
|
1343
|
+
}
|
|
1344
|
+
return this.parse_value_bool(fields[name], required, def);
|
|
1345
|
+
};
|
|
1346
|
+
_proto.parse_value_obj = function parse_value_obj(v, required, def) {
|
|
1347
|
+
if (required === void 0) {
|
|
1348
|
+
required = false;
|
|
1349
|
+
}
|
|
1350
|
+
if (def === void 0) {
|
|
1351
|
+
def = undefined;
|
|
1352
|
+
}
|
|
1353
|
+
if (v == null || v == undefined) {
|
|
1354
|
+
if (required) {
|
|
1355
|
+
throw "Wrong obj value passed: " + v;
|
|
1356
|
+
}
|
|
1357
|
+
return def;
|
|
1358
|
+
}
|
|
1359
|
+
if (Object.keys(v).length == 0) {
|
|
1360
|
+
if (required) {
|
|
1361
|
+
throw "Empty obj value passed: " + v;
|
|
1362
|
+
}
|
|
1363
|
+
return def;
|
|
1364
|
+
}
|
|
1365
|
+
if (typeof v != 'object') {
|
|
1366
|
+
throw "Wrong obj value passed: " + v;
|
|
1367
|
+
}
|
|
1368
|
+
return v;
|
|
1369
|
+
};
|
|
1370
|
+
_proto.parse_field_obj = function parse_field_obj(fields, name, required, def) {
|
|
1371
|
+
if (required === void 0) {
|
|
1372
|
+
required = false;
|
|
1373
|
+
}
|
|
1374
|
+
if (def === void 0) {
|
|
1375
|
+
def = undefined;
|
|
1376
|
+
}
|
|
1377
|
+
if (!(name in fields)) {
|
|
1378
|
+
if (required) {
|
|
1379
|
+
throw "Expected obj value not passed for " + name;
|
|
1380
|
+
}
|
|
1381
|
+
return def;
|
|
1382
|
+
}
|
|
1383
|
+
return this.parse_value_obj(fields[name], required, def);
|
|
1384
|
+
};
|
|
1385
|
+
return Parser;
|
|
1386
|
+
}();
|
|
1387
|
+
|
|
1388
|
+
var init_parser = function init_parser() {
|
|
1389
|
+
var p = new Parser();
|
|
1390
|
+
return p;
|
|
1391
|
+
};
|
|
1392
|
+
|
|
1174
1393
|
var init_context_middleware = function init_context_middleware(app, config) {
|
|
1175
1394
|
var emailer = init_emailer(config.mail);
|
|
1176
1395
|
var logger = init_logger(config.log, emailer, config == null ? void 0 : config.name);
|
|
1396
|
+
var parser = init_parser();
|
|
1177
1397
|
var dbOptions = _extends({}, config.db.options, {
|
|
1178
1398
|
log: logger
|
|
1179
1399
|
});
|
|
@@ -1194,7 +1414,8 @@ var init_context_middleware = function init_context_middleware(app, config) {
|
|
|
1194
1414
|
config: _extends({}, config),
|
|
1195
1415
|
emailer: emailer,
|
|
1196
1416
|
logger: logger,
|
|
1197
|
-
db: db
|
|
1417
|
+
db: db,
|
|
1418
|
+
parser: parser
|
|
1198
1419
|
};
|
|
1199
1420
|
function context_middleware(_x, _x2) {
|
|
1200
1421
|
return _context_middleware.apply(this, arguments);
|
|
@@ -2439,9 +2660,6 @@ var getCrudConfig = function getCrudConfig(config) {
|
|
|
2439
2660
|
return output;
|
|
2440
2661
|
};
|
|
2441
2662
|
|
|
2442
|
-
/**
|
|
2443
|
-
* Transform a query string to a JSON object
|
|
2444
|
-
*/
|
|
2445
2663
|
function query_string_to_json(url) {
|
|
2446
2664
|
var search = url.indexOf('?') >= 0 ? url.substr(url.indexOf('?') + 1) : '';
|
|
2447
2665
|
if (search) {
|
|
@@ -2449,6 +2667,43 @@ function query_string_to_json(url) {
|
|
|
2449
2667
|
}
|
|
2450
2668
|
return {};
|
|
2451
2669
|
}
|
|
2670
|
+
function make_endpoint_from_fn(fn, field) {
|
|
2671
|
+
function endpoint_from_fn(_x) {
|
|
2672
|
+
return _endpoint_from_fn.apply(this, arguments);
|
|
2673
|
+
}
|
|
2674
|
+
function _endpoint_from_fn() {
|
|
2675
|
+
_endpoint_from_fn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(ctx) {
|
|
2676
|
+
var params, result;
|
|
2677
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2678
|
+
while (1) switch (_context.prev = _context.next) {
|
|
2679
|
+
case 0:
|
|
2680
|
+
ctx.miolo.logger.info("[router] " + fn.name + "()");
|
|
2681
|
+
params = ctx.request.fields;
|
|
2682
|
+
try {
|
|
2683
|
+
ctx.miolo.logger.debug("[router] " + fn.name + "() Calling with params " + JSON.stringify(params));
|
|
2684
|
+
} catch (_) {}
|
|
2685
|
+
_context.next = 5;
|
|
2686
|
+
return fn(ctx.miolo, params);
|
|
2687
|
+
case 5:
|
|
2688
|
+
result = _context.sent;
|
|
2689
|
+
try {
|
|
2690
|
+
ctx.miolo.logger.debug("[router] " + fn.name + "() Called with result " + JSON.stringify(result));
|
|
2691
|
+
} catch (_) {}
|
|
2692
|
+
ctx.body = result;
|
|
2693
|
+
case 8:
|
|
2694
|
+
case "end":
|
|
2695
|
+
return _context.stop();
|
|
2696
|
+
}
|
|
2697
|
+
}, _callee);
|
|
2698
|
+
}));
|
|
2699
|
+
return _endpoint_from_fn.apply(this, arguments);
|
|
2700
|
+
}
|
|
2701
|
+
Object.defineProperty(endpoint_from_fn, 'name', {
|
|
2702
|
+
value: fn.name,
|
|
2703
|
+
writable: false
|
|
2704
|
+
});
|
|
2705
|
+
return endpoint_from_fn;
|
|
2706
|
+
}
|
|
2452
2707
|
|
|
2453
2708
|
function attachCrudRoutes(connection, router, crudConfigs, logger) {
|
|
2454
2709
|
crudConfigs.map(function (crudConfig) {
|
|
@@ -2938,7 +3193,9 @@ function attachCrudRoutes(connection, router, crudConfigs, logger) {
|
|
|
2938
3193
|
{
|
|
2939
3194
|
url: '/crud/todos/fake',
|
|
2940
3195
|
method: 'GET', // 'POST'
|
|
2941
|
-
callback: (ctx) => {},
|
|
3196
|
+
callback: async (ctx) => { ctx.body = result } ,
|
|
3197
|
+
// or
|
|
3198
|
+
callback_fn: async (miolo, params) => { return result } ,
|
|
2942
3199
|
|
|
2943
3200
|
auth,
|
|
2944
3201
|
before: (ctx) => {return goon/!goon},
|
|
@@ -2974,13 +3231,16 @@ var getQueriesConfig = function getQueriesConfig(config) {
|
|
|
2974
3231
|
if (!route.url) {
|
|
2975
3232
|
continue;
|
|
2976
3233
|
}
|
|
2977
|
-
|
|
3234
|
+
var cb = undefined;
|
|
3235
|
+
if (!route.callback && !route.callback_fn) {
|
|
2978
3236
|
continue;
|
|
3237
|
+
} else {
|
|
3238
|
+
cb = route.callback || make_endpoint_from_fn(route.callback_fn);
|
|
2979
3239
|
}
|
|
2980
3240
|
var parsed_route = {
|
|
2981
3241
|
url: route.url,
|
|
2982
3242
|
method: (route == null ? void 0 : route.method) || 'GET',
|
|
2983
|
-
callback:
|
|
3243
|
+
callback: cb,
|
|
2984
3244
|
auth: merge(comm_auth, (route == null ? void 0 : route.auth) || {}),
|
|
2985
3245
|
before: (route == null ? void 0 : route.before) || comm_before,
|
|
2986
3246
|
after: (route == null ? void 0 : route.after) || comm_after
|
|
@@ -3721,3 +3981,4 @@ exports.miolo = miolo;
|
|
|
3721
3981
|
exports.miolo_cacher = init_cacher;
|
|
3722
3982
|
exports.miolo_emailer = init_emailer;
|
|
3723
3983
|
exports.miolo_logger = init_logger;
|
|
3984
|
+
exports.miolo_parser = init_parser;
|