Comparing version 2.2.0 to 2.3.0
@@ -5,2 +5,12 @@ # Changelog | ||
## [2.3.0][] - 2021-05-24 | ||
- Use metaconfiguration (renamed @metarhia/config) | ||
- Сorrectly handle the absence of method in api | ||
- Fix error handling on load | ||
- Improve Procedure class, (remove mixin, add exports field) | ||
- Load custom interfaces in `api` | ||
- Import auth from application | ||
- Implement default auth stub module | ||
## [2.2.0][] - 2021-04-15 | ||
@@ -141,3 +151,4 @@ | ||
[unreleased]: https://github.com/metarhia/impress/compare/v2.2.0...HEAD | ||
[unreleased]: https://github.com/metarhia/impress/compare/v2.3.0...HEAD | ||
[2.3.0]: https://github.com/metarhia/impress/compare/v2.2.0...v2.3.0 | ||
[2.2.0]: https://github.com/metarhia/impress/compare/v2.1.2...v2.2.0 | ||
@@ -144,0 +155,0 @@ [2.1.2]: https://github.com/metarhia/impress/compare/v2.1.1...v2.1.2 |
@@ -8,3 +8,3 @@ 'use strict'; | ||
const { Config } = require('@metarhia/config'); | ||
const { Config } = require('metaconfiguration'); | ||
const metavm = require('metavm'); | ||
@@ -11,0 +11,0 @@ const metautil = require('metautil'); |
@@ -10,2 +10,3 @@ 'use strict'; | ||
const { Resources } = require('./resources.js'); | ||
const auth = require('./auth.js'); | ||
@@ -63,2 +64,13 @@ class Error extends global.Error { | ||
await Promise.allSettled(this.starts.map((fn) => this.execute(fn))); | ||
const { api } = this.sandbox; | ||
if (api.auth) { | ||
const { provider } = api.auth; | ||
if (provider) { | ||
this.auth = provider; | ||
} else { | ||
const provider = auth(this.config.sessions); | ||
this.auth = provider; | ||
api.auth.provider = provider; | ||
} | ||
} | ||
this.starts = []; | ||
@@ -85,7 +97,7 @@ this.initialization = false; | ||
createSandbox() { | ||
const { auth, config, console, resources } = this; | ||
const { config, console, resources } = this; | ||
const { server: { host, port, protocol } = {} } = this; | ||
const worker = { id: 'W' + node.worker.threadId.toString() }; | ||
const server = { host, port, protocol }; | ||
const application = { worker, server, auth, resources }; | ||
const application = { worker, server, resources }; | ||
application.introspect = async (interfaces) => this.introspect(interfaces); | ||
@@ -92,0 +104,0 @@ const sandbox = { ...SANDBOX, console, application, config }; |
'use strict'; | ||
const { metarhia } = require('./dependencies.js'); | ||
const { metautil } = metarhia; | ||
const { metautil } = require('./dependencies.js').metarhia; | ||
class Auth { | ||
constructor(options) { | ||
const { characters, secret, length } = options; | ||
this.characters = characters; | ||
this.secret = secret; | ||
this.length = length; | ||
this.db = null; | ||
} | ||
const accounts = new Map(); | ||
const sessions = new Map(); | ||
init(database) { | ||
this.db = database; | ||
} | ||
module.exports = ({ characters, secret, length }) => ({ | ||
generateToken() { | ||
const { characters, secret, length } = this; | ||
return metautil.generateToken(secret, characters, length); | ||
} | ||
}, | ||
saveSession(token, data) { | ||
this.db.update('SystemSession', { data: JSON.stringify(data) }, { token }); | ||
} | ||
sessions.get(token).data = data; | ||
}, | ||
startSession(token, data, fields = {}) { | ||
const record = { token, data: JSON.stringify(data), ...fields }; | ||
this.db.insert('SystemSession', record); | ||
} | ||
sessions.set(token, { token, data, ...fields }); | ||
}, | ||
async restoreSession(token) { | ||
const [record] = await this.db.select('SystemSession', ['data'], { token }); | ||
if (record && record.data) return record.data; | ||
return null; | ||
} | ||
restoreSession(token) { | ||
return sessions.get(token) || null; | ||
}, | ||
deleteSession(token) { | ||
this.db.delete('Session', { token }); | ||
} | ||
sessions.delete(token); | ||
}, | ||
async registerUser(login, password, fullName) { | ||
const record = { login, password, fullName }; | ||
const data = await this.db.insert('SystemUser', record); | ||
return data; | ||
} | ||
async registerUser(login, password) { | ||
accounts.set(login, { login, password }); | ||
}, | ||
async getUser(login) { | ||
const [user] = await this.db.select('SystemUser', ['*'], { login }); | ||
return user; | ||
} | ||
} | ||
module.exports = { Auth }; | ||
return accounts.get(login); | ||
}, | ||
}); |
@@ -13,8 +13,12 @@ 'use strict'; | ||
this.application.watcher.watch(targetPath); | ||
const files = await fsp.readdir(targetPath, { withFileTypes: true }); | ||
for (const file of files) { | ||
if (file.name.startsWith('.')) continue; | ||
const filePath = path.join(targetPath, file.name); | ||
if (file.isDirectory()) await this.load(filePath); | ||
else await this.change(filePath); | ||
try { | ||
const files = await fsp.readdir(targetPath, { withFileTypes: true }); | ||
for (const file of files) { | ||
if (file.name.startsWith('.')) continue; | ||
const filePath = path.join(targetPath, file.name); | ||
if (file.isDirectory()) await this.load(filePath); | ||
else await this.change(filePath); | ||
} | ||
} catch (err) { | ||
this.application.console.error(err.stack); | ||
} | ||
@@ -21,0 +25,0 @@ } |
@@ -15,3 +15,3 @@ 'use strict'; | ||
const ORG_LENGTH = '@metarhia/'.length; | ||
const metalibs = ['@metarhia/config']; | ||
const metalibs = ['metaconfiguration']; | ||
const metacore = ['metautil', 'metavm', 'metacom', 'metalog', 'metawatch']; | ||
@@ -18,0 +18,0 @@ const metaoptional = ['metaschema', 'metasql']; |
@@ -85,6 +85,10 @@ 'use strict'; | ||
if (!methods) iface[ver] = methods = {}; | ||
methods[name] = proc; | ||
const { method } = proc; | ||
methods[name] = proc; | ||
internalInterface[name] = method; | ||
this.cacheSignature(iname + '.' + version, name, method); | ||
if (method) { | ||
internalInterface[name] = method; | ||
this.cacheSignature(iname + '.' + version, name, method); | ||
} else { | ||
internalInterface[name] = proc.exports; | ||
} | ||
} | ||
@@ -91,0 +95,0 @@ } |
@@ -13,13 +13,25 @@ 'use strict'; | ||
const exp = script(EMPTY_CONTEXT); | ||
if (typeof exp === 'object') { | ||
Object.assign(this, exp); | ||
const { parameters, returns, concurrency } = exp; | ||
if (parameters) this.parameters = Schema.from(parameters); | ||
if (returns) this.returns = Schema.from(returns); | ||
if (concurrency) this.semaphore = new Semaphore(concurrency, 0, 0); | ||
} else { | ||
this.method = exp; | ||
} | ||
this.exports = exp; | ||
this.script = script; | ||
this.application = application; | ||
this.method = null; | ||
if (typeof exp === 'object') this.method = exp.method; | ||
else if (typeof exp === 'function') this.method = exp; | ||
this.parameters = exp.parameters ? Schema.from(exp.parameters) : null; | ||
this.returns = exp.returns ? Schema.from(exp.returns) : null; | ||
this.semaphore = null; | ||
if (exp.queue) { | ||
const { concurrency, size, timeout } = exp.queue; | ||
this.semaphore = new Semaphore(concurrency, size, timeout); | ||
} | ||
this.caption = exp.caption || ''; | ||
this.description = exp.description || ''; | ||
this.access = exp.access || ''; | ||
this.validate = exp.validate || null; | ||
this.timeout = exp.timeout || 0; | ||
this.sirializer = exp.sirialize || null; | ||
this.protocols = exp.protocols || null; | ||
this.deprecated = exp.deprecated || false; | ||
this.assert = exp.assert || null; | ||
this.examples = exp.examples || null; | ||
} | ||
@@ -26,0 +38,0 @@ |
@@ -7,7 +7,6 @@ 'use strict'; | ||
const { Config } = metarhia.config; | ||
const { Config } = metarhia.metaconfiguration; | ||
const { Logger } = metarhia.metalog; | ||
const { Server } = metarhia.metacom; | ||
const { loadSchema } = metarhia.metaschema; | ||
const { Auth } = require('./auth.js'); | ||
@@ -49,4 +48,3 @@ const CONFIG_SECTIONS = ['log', 'scale', 'server', 'sessions']; | ||
const { console } = logger; | ||
const auth = new Auth({ ...config.sessions }); | ||
Object.assign(application, { config, logger, console, auth }); | ||
Object.assign(application, { config, logger, console }); | ||
@@ -53,0 +51,0 @@ const logError = async (err) => { |
{ | ||
"name": "impress", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -69,22 +69,22 @@ "description": "Enterprise application server for Node.js", | ||
"dependencies": { | ||
"@metarhia/config": "^2.1.1", | ||
"@types/ws": "^7.4.1", | ||
"metacom": "^1.6.1", | ||
"metalog": "^3.1.1", | ||
"metaschema": "^1.0.3", | ||
"metautil": "^3.5.1", | ||
"metavm": "^1.0.1", | ||
"@types/ws": "^7.4.4", | ||
"metacom": "^1.7.0", | ||
"metaconfiguration": "^2.1.4", | ||
"metalog": "^3.1.2", | ||
"metaschema": "^1.2.3", | ||
"metautil": "^3.5.4", | ||
"metavm": "^1.0.2", | ||
"metawatch": "^1.0.3" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.14.39", | ||
"eslint": "^7.24.0", | ||
"@types/node": "^15.6.0", | ||
"eslint": "^7.27.0", | ||
"eslint-config-metarhia": "^7.0.1", | ||
"eslint-config-prettier": "^8.2.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.23.3", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"metatests": "^0.7.2", | ||
"prettier": "^2.2.1", | ||
"prettier": "^2.3.0", | ||
"typescript": "^4.2.4" | ||
} | ||
} |
export interface Application { | ||
worker: object; | ||
server: object; | ||
auth: Auth; | ||
auth: object; | ||
resources: Map<string, Buffer>; | ||
@@ -19,8 +19,1 @@ introspect: () => Promise<any>; | ||
} | ||
export interface Auth { | ||
characters: string; | ||
secret: string; | ||
length: number; | ||
db: object; | ||
} |
import { LogConfig, ScaleConfig, ServerConfig, SessionsConfig } from './config'; | ||
import { Application, Context, Client, Auth } from './core'; | ||
import { Application, Context, Client } from './core'; | ||
@@ -35,3 +35,3 @@ import * as _util from 'util'; | ||
import * as _config from '@metarhia/config'; | ||
import * as _config from 'metaconfiguration'; | ||
import * as _metautil from 'metautil'; | ||
@@ -38,0 +38,0 @@ import * as _metavm from 'metavm'; |
import { Schema } from 'metaschema'; | ||
import { Semaphore } from 'metautil'; | ||
@@ -18,6 +19,12 @@ import { Application } from './core'; | ||
interface Procedure { | ||
exports: object; | ||
script: Function; | ||
application: Application; | ||
method?: AsyncFuction; | ||
parameters?: Schema; | ||
returns?: Schema; | ||
semaphore?: Semaphore; | ||
caption?: string; | ||
description?: string; | ||
access?: Access; | ||
parameters?: Schema; | ||
validate?: Function; | ||
@@ -29,8 +36,4 @@ timeout?: number; | ||
deprecated?: boolean; | ||
method: AsyncFuction; | ||
returns?: Schema; | ||
assert?: Function; | ||
script?: Function; | ||
examples?: Array<Example>; | ||
application?: Application; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48387
1065
+ Addedmetaconfiguration@^2.1.4
+ Addedmetaconfiguration@2.2.0(transitive)
- Removed@metarhia/config@^2.1.1
- Removed@metarhia/config@2.1.3(transitive)
Updated@types/ws@^7.4.4
Updatedmetacom@^1.7.0
Updatedmetalog@^3.1.2
Updatedmetaschema@^1.2.3
Updatedmetautil@^3.5.4
Updatedmetavm@^1.0.2