Socket
Socket
Sign inDemoInstall

impress

Package Overview
Dependencies
Maintainers
4
Versions
719
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

impress - npm Package Compare versions

Comparing version 2.5.2 to 2.5.3

9

CHANGELOG.md

@@ -5,2 +5,8 @@ # Changelog

## [2.5.3][] - 2021-08-19
- Don't load sql from `application/schemas`
- Support custom key method in `Procedure` (pass `name` to constructor)
- Pass `context` to plugins and hooks
## [2.5.2][] - 2021-08-06

@@ -195,3 +201,4 @@

[unreleased]: https://github.com/metarhia/impress/compare/v2.5.2...HEAD
[unreleased]: https://github.com/metarhia/impress/compare/v2.5.3...HEAD
[2.5.3]: https://github.com/metarhia/impress/compare/v2.5.2...v2.5.3
[2.5.2]: https://github.com/metarhia/impress/compare/v2.5.1...v2.5.2

@@ -198,0 +205,0 @@ [2.5.1]: https://github.com/metarhia/impress/compare/v2.5.0...v2.5.1

2

lib/application.js

@@ -136,3 +136,3 @@ 'use strict';

if (!hook) return null;
return hook;
return hook.router;
}

@@ -139,0 +139,0 @@

@@ -41,5 +41,6 @@ 'use strict';

cacheSignature(interfaceName, methodName, method) {
let interfaceMethods = this.signatures[interfaceName];
const name = path.basename(interfaceName, '.js');
let interfaceMethods = this.signatures[name];
if (!interfaceMethods) {
this.signatures[interfaceName] = interfaceMethods = {};
this.signatures[name] = interfaceMethods = {};
}

@@ -66,22 +67,34 @@ interfaceMethods[methodName] = getSignature(method);

async change(filePath) {
if (!filePath.endsWith('.js')) return;
let script = await this.createScript(filePath);
if (!script) return;
const proc = new Procedure(script, 'method', this.application);
let iface = proc.exports;
const relPath = filePath.substring(this.path.length + 1);
if (!relPath.endsWith('.js')) return;
if (!relPath.includes(path.sep)) {
this.loadPlugin(filePath);
return;
}
const [interfaceName, methodFile] = relPath.split(path.sep);
const name = path.basename(methodFile, '.js');
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;
if (methodFile) {
const name = path.basename(methodFile, '.js');
methods[name] = proc;
if (proc.method) {
internalInterface[name] = proc.method;
this.cacheSignature(interfaceName, name, proc.method);
} else {
internalInterface[name] = proc.exports;
}
return;
}
if (iface.plugin) {
const [library, name] = iface.plugin.split('/');
const plugin = metarhia[library].plugins[name];
if (!plugin) return;
script = plugin(iface);
iface = script();
}
for (const name of Object.keys(iface)) {
const proc = new Procedure(script, name, this.application);
methods[name] = proc;
internalInterface[name] = proc.method;
this.cacheSignature(interfaceName, name, proc.method);
}
}

@@ -104,31 +117,4 @@

}
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);
let iface = exports;
if (exports.plugin) {
const [library, name] = exports.plugin.split('/');
const plugin = metarhia[library].plugins[name];
if (!plugin) return;
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);
}
}
}
}
module.exports = { Interfaces };

@@ -11,9 +11,10 @@ 'use strict';

class Procedure {
constructor(script, application) {
constructor(script, methodName, application) {
const exp = script(EMPTY_CONTEXT);
this.exports = exp;
this.script = script;
this.methodName = methodName;
this.application = application;
this.method = null;
if (typeof exp === 'object') this.method = exp.method;
if (typeof exp === 'object') this.method = exp[methodName];
else if (typeof exp === 'function') this.method = exp;

@@ -59,5 +60,5 @@ const namespaces = application.schemas ? [application.schemas.model] : [];

async invoke(context, args = {}) {
const { script, parameters, validate, returns, timeout } = this;
const { script, parameters, validate, returns, timeout, methodName } = this;
const exp = script(context);
const method = typeof exp === 'object' ? exp.method : exp;
const method = typeof exp === 'object' ? exp[methodName] : exp;
if (parameters) {

@@ -64,0 +65,0 @@ const { valid, errors } = parameters.check(args);

@@ -34,2 +34,3 @@ 'use strict';

if (!this.model) return;
if (!filePath.endsWith('.js')) return;
const relPath = filePath.substring(this.path.length + 1);

@@ -36,0 +37,0 @@ const name = path.basename(relPath, '.js');

{
"name": "impress",
"version": "2.5.2",
"version": "2.5.3",
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",

@@ -69,4 +69,4 @@ "description": "Enterprise application server for Node.js",

"dependencies": {
"metacom": "^1.8.2",
"metaconfiguration": "^2.1.4",
"metacom": "^2.0.0",
"metaconfiguration": "^2.1.5",
"metalog": "^3.1.3",

@@ -79,8 +79,8 @@ "metaschema": "^1.3.3",

"devDependencies": {
"@types/node": "^16.3.3",
"@types/node": "^16.6.2",
"@types/ws": "^7.4.7",
"eslint": "^7.31.0",
"eslint": "^7.32.0",
"eslint-config-metarhia": "^7.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-prettier": "^3.4.0",

@@ -87,0 +87,0 @@ "metatests": "^0.7.2",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc