miolo 0.0.46 → 0.0.49

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.
@@ -44,22 +44,31 @@ module.exports = {
44
44
  sameSite: process.env.NODE_ENV != 'development' ? null : 'strict'
45
45
  }
46
46
  },
47
- database: {
48
- dialect: 'postgres',
49
- host: 'localhost',
50
- port: 5432,
51
- database: 'miolo',
52
- user: 'postgres',
53
- password: 'postgres',
54
- max: 5,
55
- // Maximum number of connection in pool
56
- min: 0,
57
- // Minimum number of connection in pool
58
- idleTimeoutMillis: 10000 // The maximum time, in milliseconds, that a connection can be idle before being released. Use with combination of evict for proper working, for more details read https://github.com/coopernurse/node-pool/issues/178#issuecomment-327110870,
59
- },
47
+ db: {
48
+ connection: {
49
+ database: {
50
+ dialect: 'postgres',
51
+ host: 'localhost',
52
+ port: 5432,
53
+ database: 'miolo',
54
+ user: 'postgres',
55
+ password: 'postgres',
56
+ max: 5,
57
+ // Maximum number of connection in pool
58
+ min: 0,
59
+ // Minimum number of connection in pool
60
+ idleTimeoutMillis: 10000 // The maximum time, in milliseconds, that a connection can be idle before being released. Use with combination of evict for proper working, for more details read https://github.com/coopernurse/node-pool/issues/178#issuecomment-327110870,
61
+ },
62
+
63
+ options: {
64
+ log: 'silly' // will be updated on the fly with miolo logger
65
+ }
66
+ },
60
67
 
68
+ tables: []
69
+ },
61
70
  routes: {
62
- body_field: undefined,
71
+ bodyField: undefined,
63
72
  getUserId: ctx => {
64
73
  try {
65
74
  var from_pport = ctx.state.user.id;
@@ -237,9 +246,9 @@ module.exports = {
237
246
  // paths: [],
238
247
  //},
239
248
  //passport: {
240
- // get_user_id: (user, done) => done(null, user.id), // default
241
- // find_user_by_id: (id, done) => done(null, {id: 1}), // ok=> done(null, user) err=> done(error, null)
242
- // local_auth_user: (username, password, done) => done(null, {id: 1})
249
+ // get_user_id: (user, done, miolo) => done(null, user.id), // default
250
+ // find_user_by_id: (id, done, miolo) => done(null, {id: 1}), // ok=> done(null, user) err=> done(error, null)
251
+ // local_auth_user: (username, password, done, miolo) => done(null, {id: 1})
243
252
  // // auth=> done(null, user) noauth=> done(null, false, {message: ''}) err=> done(error, null)
244
253
  // url_login : '/login',
245
254
  // url_logout: '/logout',
package/lib/index.js CHANGED
@@ -27,12 +27,6 @@ Object.defineProperty(exports, "getLogger", {
27
27
  return _logger.init_logger;
28
28
  }
29
29
  });
30
- Object.defineProperty(exports, "getModel", {
31
- enumerable: true,
32
- get: function get() {
33
- return _calustraRouter.getModel;
34
- }
35
- });
36
30
  Object.defineProperty(exports, "miolo", {
37
31
  enumerable: true,
38
32
  get: function get() {
@@ -10,7 +10,6 @@ var _emailer = require("../emailer");
10
10
  var _logger = require("../logger");
11
11
  var _cron = require("./engines/cron");
12
12
  var _calustraRouter = require("calustra-router");
13
- var _context = require("./middleware/context");
14
13
  var _body = require("./middleware/body");
15
14
  var _catcher = require("./middleware/catcher");
16
15
  var _static = require("./middleware/static");
@@ -30,37 +29,20 @@ function miolo(sconfig, render, callback) {
30
29
  var config = (0, _config.init_config)(sconfig);
31
30
  var emailer = (0, _emailer.init_emailer)(config.mail.options, config.mail.defaults);
32
31
  var logger = (0, _logger.init_logger)(config.log, emailer);
33
- var miolo_getConnection = () => {
34
- var conn;
35
- if (config.database) {
36
- conn = (0, _calustraRouter.getConnection)(config.database, {
37
- log: logger
38
- });
39
- }
40
- return conn;
41
- };
42
- var miolo_getModel = (tableName, options) => {
43
- var model;
44
- if (config.database) {
45
- model = (0, _calustraRouter.getModel)(config.database, tableName, options);
46
- }
47
- return model;
48
- };
49
- var conn = miolo_getConnection();
32
+ config.db.connection.options.log = logger;
50
33
  var app = new _koa.default();
51
34
 
35
+ // attach to app calustra's db methods
36
+ (0, _calustraRouter.useCalustraDbContext)(app, config.db);
37
+
52
38
  // attach to app some custom miolo methods
53
- app.miolo = {
39
+ app.context.miolo = {
54
40
  config: _objectSpread({}, config),
55
41
  emailer,
56
42
  logger,
57
- getConnection: miolo_getConnection,
58
- getModel: miolo_getModel
43
+ db: app.context.db
59
44
  };
60
45
 
61
- // Assign this miolo stuff also to ctx
62
- (0, _context.init_context_middleware)(app, app.miolo);
63
-
64
46
  // Compress and body parser
65
47
  (0, _body.init_body_middleware)(app);
66
48
 
@@ -107,10 +89,7 @@ function miolo(sconfig, render, callback) {
107
89
 
108
90
  // Routes to /crud
109
91
  if (config !== null && config !== void 0 && config.routes) {
110
- var {
111
- init_calustra_router
112
- } = require("./routes/calustra");
113
- init_calustra_router(app, conn, config.routes);
92
+ (0, _calustraRouter.useCalustraRouter)(app, config.db, config.routes);
114
93
  }
115
94
  // Socket.io
116
95
  // const io= init_socket(logger)
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.init_passport_auth_middleware = void 0;
7
7
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
8
8
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
9
+ /* eslint-disable no-unused-vars*/
9
10
  var passport = require('koa-passport');
10
11
  var LocalStrategy = require('passport-local').Strategy;
11
12
  var Router = require('@koa/router');
@@ -17,12 +18,12 @@ var Router = require('@koa/router');
17
18
  // // auth=> done(null, user) noauth=> done(null, false, {message: ''}) err=> done(error, null)
18
19
  // }
19
20
 
20
- var def_get_user_id = (user, done) => done(null, user.id);
21
- var def_find_user_by_id = (id, done) => {
21
+ var def_get_user_id = (user, done, miolo) => done(null, user.id);
22
+ var def_find_user_by_id = (id, done, miolo) => {
22
23
  var err = Error('You need to define auth.passport.find_user_by_id');
23
24
  done(err, null);
24
25
  };
25
- var def_local_auth_user = (username, password, done) => {
26
+ var def_local_auth_user = (username, password, done, miolo) => {
26
27
  var err = Error('You need to define auth.passport.local_auth_user');
27
28
  done(err, null);
28
29
  };
@@ -49,16 +50,16 @@ var init_passport_auth_middleware = (app, options) => {
49
50
  // init passport
50
51
  var serialize_user = (user, done) => {
51
52
  process.nextTick(function () {
52
- get_user_id_f(user, done);
53
+ get_user_id_f(user, done, app.context.miolo);
53
54
  });
54
55
  };
55
56
  var deserialize_user = (id, done) => {
56
57
  process.nextTick(function () {
57
- find_user_by_id_f(id, done);
58
+ find_user_by_id_f(id, done, app.context.miolo);
58
59
  });
59
60
  };
60
61
  var local_strategy = new LocalStrategy((username, password, done) => {
61
- local_auth_user_f(username, password, done);
62
+ local_auth_user_f(username, password, done, app.context.miolo);
62
63
  });
63
64
  passport.serializeUser(serialize_user);
64
65
  passport.deserializeUser(deserialize_user);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miolo",
3
- "version": "0.0.46",
3
+ "version": "0.0.49",
4
4
  "description": "miolo",
5
5
  "main": "lib/index.js",
6
6
  "author": "Afialapis <info@afialapis.com>",
@@ -14,7 +14,7 @@
14
14
  "assign-deep": "^1.0.1",
15
15
  "babel-plugin-module-resolver": "^4.1.0",
16
16
  "basic-auth": "^2.0.1",
17
- "calustra-router": "0.1.3",
17
+ "calustra-router": "0.2.1",
18
18
  "cron": "^1.8.2",
19
19
  "diskspace": "^2.0.0",
20
20
  "eslint": "^8.9.0",
@@ -46,19 +46,27 @@ module.exports= {
46
46
  sameSite: process.env.NODE_ENV != 'development' ? null : 'strict',
47
47
  }
48
48
  },
49
- database: {
50
- dialect: 'postgres',
51
- host: 'localhost',
52
- port: 5432,
53
- database: 'miolo',
54
- user: 'postgres',
55
- password: 'postgres',
56
- max: 5, // Maximum number of connection in pool
57
- min: 0, // Minimum number of connection in pool
58
- idleTimeoutMillis: 10000, // The maximum time, in milliseconds, that a connection can be idle before being released. Use with combination of evict for proper working, for more details read https://github.com/coopernurse/node-pool/issues/178#issuecomment-327110870,
49
+ db: {
50
+ connection: {
51
+ database: {
52
+ dialect: 'postgres',
53
+ host: 'localhost',
54
+ port: 5432,
55
+ database: 'miolo',
56
+ user: 'postgres',
57
+ password: 'postgres',
58
+ max: 5, // Maximum number of connection in pool
59
+ min: 0, // Minimum number of connection in pool
60
+ idleTimeoutMillis: 10000, // The maximum time, in milliseconds, that a connection can be idle before being released. Use with combination of evict for proper working, for more details read https://github.com/coopernurse/node-pool/issues/178#issuecomment-327110870,
61
+ },
62
+ options: {
63
+ log: 'silly' // will be updated on the fly with miolo logger
64
+ }
65
+ },
66
+ tables: []
59
67
  },
60
68
  routes: {
61
- body_field: undefined,
69
+ bodyField: undefined,
62
70
 
63
71
  getUserId: (ctx) => {
64
72
  try {
@@ -237,9 +245,9 @@ module.exports= {
237
245
  // paths: [],
238
246
  //},
239
247
  //passport: {
240
- // get_user_id: (user, done) => done(null, user.id), // default
241
- // find_user_by_id: (id, done) => done(null, {id: 1}), // ok=> done(null, user) err=> done(error, null)
242
- // local_auth_user: (username, password, done) => done(null, {id: 1})
248
+ // get_user_id: (user, done, miolo) => done(null, user.id), // default
249
+ // find_user_by_id: (id, done, miolo) => done(null, {id: 1}), // ok=> done(null, user) err=> done(error, null)
250
+ // local_auth_user: (username, password, done, miolo) => done(null, {id: 1})
243
251
  // // auth=> done(null, user) noauth=> done(null, false, {message: ''}) err=> done(error, null)
244
252
  // url_login : '/login',
245
253
  // url_logout: '/logout',
package/src/index.js CHANGED
@@ -2,13 +2,12 @@ import {miolo} from './server'
2
2
  import { init_emailer as getEmailer} from './emailer'
3
3
  import { init_cacher as getCacher} from './cacher'
4
4
  import { init_logger as getLogger } from './logger'
5
- import { getConnection, getModel } from 'calustra-router'
5
+ import { getConnection } from 'calustra-router'
6
6
 
7
7
  export {
8
8
  miolo,
9
9
  getEmailer,
10
10
  getCacher,
11
11
  getLogger,
12
- getConnection,
13
- getModel
12
+ getConnection
14
13
  }
@@ -5,10 +5,8 @@ import { init_logger } from 'src/logger'
5
5
  import { init_cron } from './engines/cron'
6
6
  // import {init_socket} from './engines/socket'
7
7
 
8
- import { getConnection, getModel } from 'calustra-router'
8
+ import { useCalustraDbContext, useCalustraRouter } from 'calustra-router'
9
9
 
10
-
11
- import { init_context_middleware } from './middleware/context'
12
10
  import { init_body_middleware } from './middleware/body'
13
11
  import { init_catcher_middleware } from './middleware/catcher'
14
12
  import { init_static_middleware } from './middleware/static'
@@ -22,42 +20,28 @@ import { init_route_catch_js_error} from './routes/catch_js_error'
22
20
  import { init_route_html_render} from './routes/html_render'
23
21
 
24
22
  function miolo(sconfig, render, callback) {
23
+
25
24
 
26
25
  // Init some pieces
27
26
  const config = init_config(sconfig)
28
27
  const emailer = init_emailer(config.mail.options, config.mail.defaults)
29
28
  const logger = init_logger(config.log, emailer)
30
29
 
31
- const miolo_getConnection = () => {
32
- let conn
33
- if (config.database) {
34
- conn= getConnection(config.database, {log: logger})
35
- }
36
- return conn
37
- }
38
- const miolo_getModel = (tableName, options) => {
39
- let model
40
- if (config.database) {
41
- model= getModel(config.database, tableName, options)
42
- }
43
- return model
44
- }
45
- const conn = miolo_getConnection()
46
-
30
+ config.db.connection.options.log= logger
31
+
47
32
  const app = new Koa()
48
33
 
34
+
35
+ // attach to app calustra's db methods
36
+ useCalustraDbContext(app, config.db)
37
+
49
38
  // attach to app some custom miolo methods
50
- app.miolo = {
39
+ app.context.miolo = {
51
40
  config: {...config},
52
41
  emailer,
53
42
  logger,
54
- getConnection: miolo_getConnection,
55
- getModel: miolo_getModel
56
- }
57
-
58
-
59
- // Assign this miolo stuff also to ctx
60
- init_context_middleware(app, app.miolo)
43
+ db: app.context.db
44
+ }
61
45
 
62
46
  // Compress and body parser
63
47
  init_body_middleware(app)
@@ -101,8 +85,8 @@ function miolo(sconfig, render, callback) {
101
85
 
102
86
  // Routes to /crud
103
87
  if (config?.routes) {
104
- const {init_calustra_router} = require('./routes/calustra')
105
- init_calustra_router(app, conn, config.routes)
88
+ useCalustraRouter(app, config.db, config.routes)
89
+
106
90
  }
107
91
  // Socket.io
108
92
  // const io= init_socket(logger)
@@ -1,8 +1,9 @@
1
+ /* eslint-disable no-unused-vars*/
1
2
  const passport = require('koa-passport');
2
3
  const LocalStrategy = require('passport-local').Strategy;
3
-
4
4
  const Router = require('@koa/router')
5
5
 
6
+
6
7
  // passport: {
7
8
  // get_user_id: (user, done) => done(null, user.id), // default
8
9
  // find_user_by_id: (id, done) => done(null, {id: 1}), // ok=> done(null, user) err=> done(error, null)
@@ -10,14 +11,15 @@ const Router = require('@koa/router')
10
11
  // // auth=> done(null, user) noauth=> done(null, false, {message: ''}) err=> done(error, null)
11
12
  // }
12
13
 
13
- const def_get_user_id = (user, done) => done(null, user.id)
14
14
 
15
- const def_find_user_by_id = (id, done) => {
15
+ const def_get_user_id = (user, done, miolo) => done(null, user.id)
16
+
17
+ const def_find_user_by_id = (id, done, miolo) => {
16
18
  const err = Error('You need to define auth.passport.find_user_by_id')
17
19
  done(err, null)
18
20
  }
19
21
 
20
- const def_local_auth_user = (username, password, done) => {
22
+ const def_local_auth_user = (username, password, done, miolo) => {
21
23
  const err = Error('You need to define auth.passport.local_auth_user')
22
24
  done(err, null)
23
25
  }
@@ -39,19 +41,19 @@ const init_passport_auth_middleware = ( app, options ) => {
39
41
  // init passport
40
42
  const serialize_user = (user, done) => {
41
43
  process.nextTick(function() {
42
- get_user_id_f(user, done)
44
+ get_user_id_f(user, done, app.context.miolo)
43
45
  })
44
46
  }
45
47
 
46
48
  const deserialize_user = (id, done) => {
47
49
  process.nextTick(function() {
48
- find_user_by_id_f(id, done)
50
+ find_user_by_id_f(id, done, app.context.miolo)
49
51
  })
50
52
  }
51
53
 
52
54
  const local_strategy= new LocalStrategy(
53
55
  (username, password, done) => {
54
- local_auth_user_f(username, password, done)
56
+ local_auth_user_f(username, password, done, app.context.miolo)
55
57
  })
56
58
 
57
59
  passport.serializeUser(serialize_user)
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.init_calustra_router = init_calustra_router;
7
- exports.init_calustra_router_async = init_calustra_router_async;
8
- var _calustraRouter = require("calustra-router");
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
10
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
11
- function init_calustra_router(app, conn, config) {
12
- if (!config) {
13
- return undefined;
14
- }
15
- var router = (0, _calustraRouter.calustraRouter)(conn, config);
16
- app.use(router.routes());
17
- }
18
- function init_calustra_router_async(_x, _x2, _x3) {
19
- return _init_calustra_router_async.apply(this, arguments);
20
- }
21
- function _init_calustra_router_async() {
22
- _init_calustra_router_async = _asyncToGenerator(function* (app, conn, config) {
23
- if (!config) {
24
- return undefined;
25
- }
26
- var router = yield (0, _calustraRouter.calustraRouterAll)(conn, config);
27
- app.use(router.routes());
28
- });
29
- return _init_calustra_router_async.apply(this, arguments);
30
- }
@@ -1,27 +0,0 @@
1
- import {calustraRouter, calustraRouterAll} from 'calustra-router'
2
-
3
- function init_calustra_router (app, conn, config) {
4
-
5
- if (! config) {
6
- return undefined
7
- }
8
-
9
- const router= calustraRouter(conn, config)
10
- app.use(router.routes())
11
-
12
- }
13
-
14
-
15
- async function init_calustra_router_async (app, conn, config) {
16
-
17
- if (! config) {
18
- return undefined
19
- }
20
-
21
- const router= await calustraRouterAll(conn, config)
22
- app.use(router.routes())
23
-
24
- }
25
-
26
-
27
- export {init_calustra_router, init_calustra_router_async}