impress
Advanced tools
Comparing version 2.4.0 to 2.4.1
@@ -5,2 +5,7 @@ # Changelog | ||
## [2.4.1][] - 2021-07-01 | ||
- Implement basic API plugin system | ||
- Update dependencies including metacom and metaschema | ||
## [2.4.0][] - 2021-06-26 | ||
@@ -165,3 +170,4 @@ | ||
[unreleased]: https://github.com/metarhia/impress/compare/v2.4.0...HEAD | ||
[unreleased]: https://github.com/metarhia/impress/compare/v2.4.1...HEAD | ||
[2.4.1]: https://github.com/metarhia/impress/compare/v2.4.0...v2.4.1 | ||
[2.4.0]: https://github.com/metarhia/impress/compare/v2.3.2...v2.4.0 | ||
@@ -168,0 +174,0 @@ [2.3.2]: https://github.com/metarhia/impress/compare/v2.3.1...v2.3.2 |
@@ -61,3 +61,2 @@ 'use strict'; | ||
this.resources.load(), | ||
this.api.load(), | ||
(async () => { | ||
@@ -69,2 +68,3 @@ await this.lib.load(); | ||
await Promise.allSettled(this.starts.map((fn) => this.execute(fn))); | ||
await this.api.load(); | ||
const { api } = this.sandbox; | ||
@@ -71,0 +71,0 @@ if (api.auth) { |
@@ -66,11 +66,26 @@ 'use strict'; | ||
const relPath = filePath.substring(this.path.length + 1); | ||
if (!relPath.includes(path.sep)) return; | ||
if (!relPath.endsWith('.js')) return; | ||
if (!relPath.includes(path.sep)) { | ||
this.loadPlugin(filePath); | ||
return; | ||
} | ||
const [interfaceName, methodFile] = relPath.split(path.sep); | ||
if (!methodFile.endsWith('.js')) return; | ||
const name = path.basename(methodFile, '.js'); | ||
const [iname, ver] = interfaceName.split('.'); | ||
const version = parseInt(ver, 10); | ||
const { internalInterface, methods } = this.prepareInterface(interfaceName); | ||
const script = await this.createScript(filePath); | ||
if (!script) return; | ||
const proc = new Procedure(script, this.application); | ||
methods[name] = proc; | ||
const { method } = proc; | ||
if (method) { | ||
internalInterface[name] = method; | ||
this.cacheSignature(interfaceName, name, method); | ||
} else { | ||
internalInterface[name] = proc.exports; | ||
} | ||
} | ||
prepareInterface(interfaceName) { | ||
const [iname, ver] = interfaceName.split('.'); | ||
const version = parseInt(ver, 10); | ||
let iface = this.collection[iname]; | ||
@@ -86,9 +101,26 @@ const { api } = this.application.sandbox; | ||
if (!methods) iface[ver] = methods = {}; | ||
methods[name] = proc; | ||
const { method } = proc; | ||
if (method) { | ||
internalInterface[name] = method; | ||
this.cacheSignature(iname + '.' + version, name, method); | ||
} else { | ||
internalInterface[name] = proc.exports; | ||
return { internalInterface, methods }; | ||
} | ||
async loadPlugin(filePath) { | ||
const relPath = filePath.substring(this.path.length + 1); | ||
const interfaceName = path.basename(relPath, '.js'); | ||
const { internalInterface, methods } = this.prepareInterface(interfaceName); | ||
const options = { context: this.application.sandbox, filename: filePath }; | ||
try { | ||
const { exports } = await metavm.readScript(filePath, options); | ||
const [library, name] = exports.plugin.split('/'); | ||
const plugin = metarhia[library].plugins[name]; | ||
if (!plugin) return; | ||
const iface = plugin(exports); | ||
for (const [name, proc] of Object.entries(iface)) { | ||
const method = new Procedure(() => proc, this.application); | ||
methods[name] = method; | ||
internalInterface[name] = method; | ||
this.cacheSignature(interfaceName, name, method); | ||
} | ||
} catch (err) { | ||
if (err.code !== 'ENOENT') { | ||
this.application.console.error(err.stack); | ||
} | ||
} | ||
@@ -95,0 +127,0 @@ } |
{ | ||
"name": "impress", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -69,6 +69,6 @@ "description": "Enterprise application server for Node.js", | ||
"dependencies": { | ||
"metacom": "^1.7.4", | ||
"metacom": "^1.7.5", | ||
"metaconfiguration": "^2.1.4", | ||
"metalog": "^3.1.2", | ||
"metaschema": "^1.3.1", | ||
"metaschema": "^1.3.2", | ||
"metautil": "^3.5.4", | ||
@@ -79,3 +79,3 @@ "metavm": "^1.0.2", | ||
"devDependencies": { | ||
"@types/node": "^15.12.4", | ||
"@types/node": "^15.14.0", | ||
"@types/ws": "^7.4.5", | ||
@@ -89,4 +89,4 @@ "eslint": "^7.29.0", | ||
"prettier": "^2.3.2", | ||
"typescript": "^4.3.4" | ||
"typescript": "^4.3.5" | ||
} | ||
} |
51808
1139
Updatedmetacom@^1.7.5
Updatedmetaschema@^1.3.2