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 3.0.0-alpha.10 to 3.0.0-alpha.11

9

CHANGELOG.md

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

## [3.0.0-alpha.11][] - 2023-03-14
- Add `node:` prefix in require for built-in modules
- Use latest metacom 3.0.0-alpha.8 and update typings
- Update `auth` interface for compatibility with metacom 3.0.0-alpha.8
## [3.0.0-alpha.10][] - 2023-02-13

@@ -322,3 +328,4 @@

[unreleased]: https://github.com/metarhia/impress/compare/v3.0.0-alpha.10...HEAD
[unreleased]: https://github.com/metarhia/impress/compare/v3.0.0-alpha.11...HEAD
[3.0.0-alpha.11]: https://github.com/metarhia/impress/compare/v3.0.0-alpha.10...v3.0.0-alpha.11
[3.0.0-alpha.10]: https://github.com/metarhia/impress/compare/v3.0.0-alpha.9...v3.0.0-alpha.10

@@ -325,0 +332,0 @@ [3.0.0-alpha.9]: https://github.com/metarhia/impress/compare/v3.0.0-alpha.8...v3.0.0-alpha.9

18

impress.js

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

const fsp = require('fs').promises;
const { Worker } = require('worker_threads');
const path = require('path');
const fsp = require('node:fs').promises;
const { Worker } = require('node:worker_threads');
const path = require('node:path');
const { Config } = require('metaconfiguration');

@@ -46,4 +46,4 @@ const metavm = require('metavm');

const logError = (type) => (err) => {
const msg = err?.stack || err?.message || 'exit';
const logError = (type) => (error) => {
const msg = error?.stack || error?.message || 'exit';
impress.console.error(`${type}: ${msg}`);

@@ -123,4 +123,4 @@ if (impress.initialization) exit('Can not start Application server');

if (!checkResult.valid) {
for (const err of checkResult.errors) {
impress.console.error(`${err} in application/config/${section}.js`);
for (const error of checkResult.errors) {
impress.console.error(`${error} in application/config/${section}.js`);
}

@@ -136,4 +136,4 @@ valid = false;

const configPath = path.join(dir, 'config');
const config = await new Config(configPath, CFG_OPTIONS).catch((err) => {
exit(`Can not read configuration: ${configPath}\n${err.stack}`);
const config = await new Config(configPath, CFG_OPTIONS).catch((error) => {
exit(`Can not read configuration: ${configPath}\n${error.stack}`);
});

@@ -140,0 +140,0 @@ await validateConfig(config);

'use strict';
const { node, npm, metarhia } = require('./dependencies.js');
const path = require('path');
const events = require('events');
const fs = require('fs');
const wt = require('worker_threads');
const path = require('node:path');
const events = require('node:events');
const fs = require('node:fs');
const wt = require('node:worker_threads');
const { MessageChannel, parentPort, threadId, workerData } = wt;

@@ -14,6 +14,5 @@ const metautil = require('metautil');

const { Modules } = require('./modules.js');
const { Services } = require('./services.js');
const { Resources } = require('./resources.js');
const { Schemas } = require('./schemas.js');
const { Scheduler } = require('./scheduler.js');
const scheduler = require('./scheduler.js');
const auth = require('./auth.js');

@@ -28,2 +27,15 @@

const invoke = async ({ method, args, exclusive = false }) => {
const { port1: port, port2 } = new MessageChannel();
const data = { method, args };
const msg = { name: 'invoke', exclusive, data, port };
return new Promise((resolve, reject) => {
port2.on('message', ({ error, data }) => {
if (error) reject(error);
else resolve(data);
});
parentPort.postMessage(msg, [port]);
});
};
class UserApplication extends events.EventEmitter {

@@ -34,3 +46,3 @@ constructor(app, data) {

this.introspect = async (interfaces) => app.introspect(interfaces);
this.invoke = async (call) => app.invoke(call);
this.invoke = invoke;
}

@@ -58,5 +70,4 @@ }

this.db = new Modules('db', this);
this.bus = new Services('bus', this);
this.bus = new Modules('bus', this);
this.domain = new Modules('domain', this);
this.scheduler = new Scheduler(this);

@@ -109,10 +120,5 @@ this.starts = [];

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;
}
const provider = api.auth.provider || auth(this.config.sessions);
this.auth = provider;
api.auth.provider = provider;
}

@@ -142,3 +148,3 @@ this.initialization = false;

createSandbox() {
const { config, console, resources, schemas, scheduler } = this;
const { config, console, resources, schemas } = this;
const { server: { host, port, protocol } = {} } = this;

@@ -178,8 +184,6 @@ const worker = { id: 'W' + threadId.toString() };

execute(method) {
return method().catch((err) => {
this.console.error(
`Failed to execute method: ${err && err.message}`,
err.stack,
);
return Promise.reject(err);
return method().catch((error) => {
const msg = `Failed to execute method: ${error?.message}`;
this.console.error(msg, error.stack);
return Promise.reject(error);
});

@@ -196,4 +200,4 @@ }

const place = relPath.substring(0, sepIndex);
fs.stat(filePath, (err, stat) => {
if (err) return;
fs.stat(filePath, (error, stat) => {
if (error) return;
if (stat.isDirectory()) {

@@ -203,5 +207,3 @@ this[place].load(filePath);

}
if (threadId === 1) {
this.console.debug('Reload: /' + relPath);
}
if (threadId === 1) this.console.debug('Reload: /' + relPath);
this[place].change(filePath);

@@ -216,5 +218,3 @@ });

this[place].delete(filePath);
if (threadId === 1) {
this.console.debug('Deleted: /' + relPath);
}
if (threadId === 1) this.console.debug('Deleted: /' + relPath);
});

@@ -229,3 +229,3 @@ }

if (!iface) continue;
const version = ver === '*' ? iface.default : parseInt(ver);
const version = ver === '*' ? iface.default : parseInt(ver, 10);
intro[iname] = this.api.signatures[iname + '.' + version];

@@ -236,19 +236,2 @@ }

getStaticFile(fileName) {
return this.static.get(fileName);
}
async invoke({ method, args, exclusive = false }) {
const { port1: port, port2 } = new MessageChannel();
const data = { method, args };
const msg = { name: 'invoke', exclusive, data, port };
return new Promise((resolve, reject) => {
port2.on('message', ({ error, data }) => {
if (error) reject(error);
else resolve(data);
});
parentPort.postMessage(msg, [port]);
});
}
serveStatic(channel) {

@@ -262,3 +245,3 @@ const { req, res } = channel;

const fileExt = metautil.fileExt(filePath);
const data = this.getStaticFile(filePath);
const data = this.static.get(filePath);
if (data) {

@@ -268,3 +251,3 @@ channel.write(data, 200, fileExt);

}
if (!folder && this.getStaticFile(urlPath + '/index.html')) {
if (!folder && this.static.get(urlPath + '/index.html')) {
const query = params ? '?' + params : '';

@@ -271,0 +254,0 @@ channel.redirect(urlPath + '/' + query);

@@ -13,15 +13,15 @@ 'use strict';

saveSession(token, data) {
async saveSession(token, data) {
sessions.get(token).data = data;
},
startSession(token, data, fields = {}) {
async createSession(token, data, fields = {}) {
sessions.set(token, { token, data, ...fields });
},
restoreSession(token) {
async readSession(token) {
return sessions.get(token) || null;
},
deleteSession(token) {
async deleteSession(token) {
sessions.delete(token);

@@ -28,0 +28,0 @@ },

'use strict';
const path = require('path');
const fsp = require('fs').promises;
const path = require('node:path');
const fsp = require('node:fs').promises;

@@ -18,9 +18,10 @@ class Cache {

for (const file of files) {
if (file.name.startsWith('.') && !file.name.endsWith('.js')) continue;
const filePath = path.join(targetPath, file.name);
const { name } = file;
if (name.startsWith('.') && !name.endsWith('.js')) continue;
const filePath = path.join(targetPath, name);
if (file.isDirectory()) await this.load(filePath);
else await this.change(filePath);
}
} catch (err) {
this.application.console.error(err.stack);
} catch (error) {
this.application.console.error(error.stack);
}

@@ -27,0 +28,0 @@ }

@@ -28,7 +28,4 @@ 'use strict';

container[name] = value;
const key = metautil.replace(
name.startsWith('@') ? name.slice(1) : name,
'/',
'-',
);
const library = name.startsWith('@') ? name.slice(1) : name;
const key = metautil.replace(library, '/', '-');
const camelKey = metautil.spinalToCamel(key);

@@ -35,0 +32,0 @@ container[camelKey] = value;

'use strict';
const path = require('path');
const fs = require('fs');
const path = require('node:path');
const fs = require('node:fs');
const fsp = fs.promises;

@@ -21,6 +21,9 @@ const metautil = require('metautil');

const DIR_LEN = 2;
const CODE_LEN = 8;
const uploadFile = async (fileName) => {
const dir1 = metautil.generateKey(2, metautil.DIGIT);
const dir2 = metautil.generateKey(2, metautil.DIGIT);
const code = metautil.generateKey(8, metautil.ALPHA_DIGIT);
const dir1 = metautil.generateKey(DIR_LEN, metautil.DIGIT);
const dir2 = metautil.generateKey(DIR_LEN, metautil.DIGIT);
const code = metautil.generateKey(CODE_LEN, metautil.ALPHA_DIGIT);
const dir = path.join(application.path, 'files', dir1, dir2);

@@ -27,0 +30,0 @@ await fsp.mkdir(dir, { recursive: true });

'use strict';
const path = require('path');
const fsp = require('fs').promises;
const path = require('node:path');
const fsp = require('node:fs').promises;
const metavm = require('metavm');

@@ -33,5 +33,5 @@ const metautil = require('metautil');

return exports;
} catch (err) {
if (err.code !== 'ENOENT') {
this.application.console.error(err.stack);
} catch (error) {
if (error.code !== 'ENOENT') {
this.application.console.error(error.stack);
}

@@ -38,0 +38,0 @@ return null;

'use strict';
const path = require('path');
const metavm = require('metavm');
const { parsePath } = require('metautil');
const { Cache } = require('./cache.js');
const { preprocess } = require('./services.js');
const parsePath = (relPath) => {
const name = path.basename(relPath, '.js');
const names = relPath.split(path.sep);
names[names.length - 1] = name;
return names;
};
class Modules extends Cache {

@@ -28,6 +22,2 @@ constructor(place, application) {

preprocess(iface) {
return iface;
}
set(relPath, iface) {

@@ -70,10 +60,12 @@ const names = parsePath(relPath);

if (!filePath.endsWith('.js')) return;
const options = { context: this.application.sandbox, filename: filePath };
const { application, path, place } = this;
const options = { context: application.sandbox, filename: filePath };
try {
const { exports } = await metavm.readScript(filePath, options);
const relPath = filePath.substring(this.path.length + 1);
this.set(relPath, this.preprocess(exports));
} catch (err) {
if (err.code !== 'ENOENT') {
this.application.console.error(err.stack);
const relPath = filePath.substring(path.length + 1);
const exp = place === 'bus' ? preprocess(exports, application) : exports;
this.set(relPath, exp);
} catch (error) {
if (error.code !== 'ENOENT') {
application.console.error(error.stack);
}

@@ -80,0 +72,0 @@ }

'use strict';
const path = require('path');
const fsp = require('fs').promises;
const { MessageChannel } = require('worker_threads');
const path = require('node:path');
const fsp = require('node:fs').promises;
const { MessageChannel } = require('node:worker_threads');
const metautil = require('metautil');

@@ -32,3 +32,3 @@

if (date === now) {
const nextId = parseInt(id) + 1;
const nextId = parseInt(id, 10) + 1;
if (nextId > this.nextId) this.nextId = nextId;

@@ -40,4 +40,4 @@ }

}
} catch (err) {
this.console.error(err.stack);
} catch (error) {
this.console.error(error.stack);
}

@@ -96,4 +96,4 @@ return this;

await fsp.writeFile(filePath, data);
} catch (err) {
this.console.error(err.stack);
} catch (error) {
this.console.error(error.stack);
}

@@ -115,5 +115,5 @@ return id;

await fsp.unlink(filePath);
} catch (err) {
if (err.code !== 'ENOENT') {
this.console.error(err.stack);
} catch (error) {
if (error.code !== 'ENOENT') {
this.console.error(error.stack);
}

@@ -175,8 +175,8 @@ }

task.result = await this.invoke(task);
} catch (err) {
task.error = err;
if (err.message === 'Semaphore timeout') {
} catch (error) {
task.error = error;
if (error.message === 'Semaphore timeout') {
this.fail(task, 'Scheduler queue is full');
} else {
this.console.error(err.stack);
this.console.error(error.stack);
}

@@ -183,0 +183,0 @@ } finally {

@@ -45,5 +45,5 @@ 'use strict';

await this.semaphore.enter();
} catch (err) {
} catch (error) {
this.application.server.semaphore.leave();
throw err;
throw error;
}

@@ -67,5 +67,3 @@ }

}
if (validate) {
await validate(args);
}
if (validate) await validate(args);
let result;

@@ -72,0 +70,0 @@ if (timeout) {

'use strict';
const path = require('path');
const fsp = require('fs').promises;
const path = require('node:path');
const fsp = require('node:fs').promises;
const metautil = require('metautil');
const { Cache } = require('./cache.js');
const win = process.platform === 'win32';
const WIN = process.platform === 'win32';

@@ -20,5 +20,10 @@ class Resources extends Cache {

getKey(filePath) {
const key = filePath.substring(this.path.length);
if (WIN) return metautil.replace(key, path.sep, '/');
return key;
}
delete(filePath) {
let key = filePath.substring(this.path.length);
if (win) key = metautil.replace(key, path.sep, '/');
const key = this.getKey(filePath);
this.files.delete(key);

@@ -28,10 +33,9 @@ }

async change(filePath) {
let key = filePath.substring(this.path.length);
if (win) key = metautil.replace(key, path.sep, '/');
try {
const data = await fsp.readFile(filePath);
const key = this.getKey(filePath);
this.files.set(key, data);
} catch (err) {
if (err.code !== 'ENOENT') {
this.application.console.error(err.stack);
} catch (error) {
if (error.code !== 'ENOENT') {
this.application.console.error(error.stack);
}

@@ -38,0 +42,0 @@ }

'use strict';
const { MessageChannel, parentPort } = require('worker_threads');
const { MessageChannel, parentPort } = require('node:worker_threads');
class Scheduler {
constructor(application) {
this.application = application;
}
async add(task) {
const { port1, port2 } = new MessageChannel();
return new Promise((resolve) => {
port2.on('message', ({ id }) => {
resolve(id);
});
const msg = { name: 'task', action: 'add', port: port1, task };
parentPort.postMessage(msg, [port1]);
const add = async (task) => {
const { port1, port2 } = new MessageChannel();
return new Promise((resolve) => {
port2.on('message', ({ id }) => {
resolve(id);
});
}
const msg = { name: 'task', action: 'add', port: port1, task };
parentPort.postMessage(msg, [port1]);
});
};
async remove(id) {
parentPort.postMessage({ name: 'task', action: 'remove', task: { id } });
}
const remove = async (id) => {
parentPort.postMessage({ name: 'task', action: 'remove', task: { id } });
};
stop(name = '') {
parentPort.postMessage({ name: 'task', action: 'stop', task: { name } });
}
}
const stop = (name = '') => {
parentPort.postMessage({ name: 'task', action: 'stop', task: { name } });
};
module.exports = { Scheduler };
module.exports = { add, remove, stop };
'use strict';
const path = require('path');
const path = require('node:path');
const { loadModel, loadSchema } = require('metaschema');

@@ -5,0 +5,0 @@ const { Cache } = require('./cache.js');

'use strict';
const http = require('http');
const https = require('https');
const http = require('node:http');
const https = require('node:https');
const metautil = require('metautil');
const { Schema } = require('metaschema');
const { Modules } = require('./modules.js');

@@ -45,38 +44,35 @@ const request = (url, { method, body }) =>

class Services extends Modules {
preprocess(iface) {
const { application } = this;
const namespaces = application.schemas ? [application.schemas.model] : [];
const { parameters, returns } = iface;
const validation = {
parameters: parameters ? Schema.from(parameters, namespaces) : null,
returns: returns ? Schema.from(returns, namespaces) : null,
};
const method = async (args) => {
const { parameters, returns } = validation;
if (parameters) {
const { valid, errors } = parameters.check(args);
const problems = errors.join('; ');
if (!valid) return new Error('Invalid parameters type: ' + problems);
}
const service = method.parent['.service'];
const verb = iface.method.get ? 'get' : 'post';
const target = [service.url, iface.method[verb]];
if (iface.method.path) {
target.push(...iface.method.path.map((arg) => args[arg]));
}
const body = serialize(iface.method.body, args);
const url = target.join('/');
const result = await request(url, { method: verb.toUpperCase(), body });
if (returns) {
const { valid, errors } = returns.check(result);
const problems = errors.join('; ');
if (!valid) return new Error('Invalid result type: ' + problems);
}
return result;
};
return Object.assign(method, iface);
}
}
const preprocess = (iface, application) => {
const namespaces = application.schemas ? [application.schemas.model] : [];
const { parameters, returns } = iface;
const validation = {
parameters: parameters ? Schema.from(parameters, namespaces) : null,
returns: returns ? Schema.from(returns, namespaces) : null,
};
const method = async (args) => {
const { parameters, returns } = validation;
if (parameters) {
const { valid, errors } = parameters.check(args);
const problems = errors.join('; ');
if (!valid) return new Error('Invalid parameters type: ' + problems);
}
const service = method.parent['.service'];
const verb = iface.method.get ? 'get' : 'post';
const target = [service.url, iface.method[verb]];
if (iface.method.path) {
target.push(...iface.method.path.map((arg) => args[arg]));
}
const body = serialize(iface.method.body, args);
const url = target.join('/');
const result = await request(url, { method: verb.toUpperCase(), body });
if (returns) {
const { valid, errors } = returns.check(result);
const problems = errors.join('; ');
if (!valid) return new Error('Invalid result type: ' + problems);
}
return result;
};
return Object.assign(method, iface);
};
module.exports = { Services };
module.exports = { preprocess };
'use strict';
const path = require('path');
const fsp = require('fs').promises;
const { parentPort, threadId, workerData } = require('worker_threads');
const path = require('node:path');
const fsp = require('node:fs').promises;
const { parentPort, threadId, workerData } = require('node:worker_threads');
const { Config } = require('metaconfiguration');

@@ -14,4 +14,4 @@ const { Logger } = require('metalog');

const logError = (type) => async (err) => {
const msg = err.stack || err.message || 'no stack trace';
const logError = (type) => async (error) => {
const msg = error.stack || error.message || 'no stack trace';
console.error(type + ': ' + msg);

@@ -18,0 +18,0 @@ if (application.finalization) return;

{
"name": "impress",
"version": "3.0.0-alpha.10",
"version": "3.0.0-alpha.11",
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",

@@ -54,7 +54,3 @@ "description": "Enterprise application server for Node.js",

"types": "types/impress.d.ts",
"files": [
"lib/",
"schemas/",
"types/"
],
"files": ["lib/", "schemas/", "types/"],
"scripts": {

@@ -67,19 +63,19 @@ "test": "npm run lint && npm run types && metatests test/",

"engines": {
"node": "14 || 16 || 18 || 19"
"node": "^14.18 || 16 || 18 || 19"
},
"dependencies": {
"metacom": "^3.0.0-alpha.6",
"metaconfiguration": "^2.1.9",
"metacom": "^3.0.0-alpha.8",
"metaconfiguration": "^2.1.10",
"metalog": "^3.1.9",
"metaschema": "^2.1.1",
"metautil": "^3.6.0",
"metavm": "^1.2.2",
"metaschema": "^2.1.3",
"metautil": "^3.7.1",
"metavm": "^1.2.4",
"metawatch": "^1.0.7"
},
"devDependencies": {
"@types/node": "^18.13.0",
"@types/node": "^18.15.2",
"@types/ws": "^8.5.4",
"eslint": "^8.34.0",
"eslint": "^8.36.0",
"eslint-config-metarhia": "^8.1.0",
"eslint-config-prettier": "^8.6.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-import": "^2.27.5",

@@ -86,0 +82,0 @@ "eslint-plugin-prettier": "^4.2.1",

@@ -1,2 +0,2 @@

import { EventEmitter, NodeJS } from 'events';
import { EventEmitter, NodeJS } from 'node:events';

@@ -39,12 +39,1 @@ export interface Task {

}
export interface Context {
client: Client;
[key: string]: any;
}
export interface Client {
events: { close: Array<Function> };
callId: number;
ip: string;
}
import { LogConfig, ScaleConfig, ServerConfig, SessionsConfig } from './config';
import { Application, Context, Client } from './core';
import * as _util from 'util';
import * as _buffer from 'buffer';
import * as _cp from 'child_process';
import * as _os from 'os';
import * as _v8 from 'v8';
import * as _vm from 'vm';
import * as _path from 'path';
import * as _url from 'url';
import * as _sd from 'string_decoder';
import * as _qs from 'querystring';
import * as _querystring from 'querystring';
import * as _assert from 'assert';
import * as _stream from 'stream';
import * as _fs from 'fs';
import * as _crypto from 'crypto';
import * as _zlib from 'zlib';
import * as _readline from 'readline';
import * as _ph from 'perf_hooks';
import * as _ah from 'async_hooks';
import * as _timers from 'timers';
import * as _events from 'events';
import * as _dns from 'dns';
import * as _net from 'net';
import * as _tls from 'tls';
import * as _http from 'http';
import * as _https from 'https';
import * as _http2 from 'http2';
import * as _dgram from 'dgram';
import * as _util from 'node:util';
import * as _buffer from 'node:buffer';
import * as _cp from 'node:child_process';
import * as _os from 'node:os';
import * as _v8 from 'node:v8';
import * as _vm from 'node:vm';
import * as _path from 'node:path';
import * as _url from 'node:url';
import * as _sd from 'node:string_decoder';
import * as _qs from 'node:querystring';
import * as _querystring from 'node:querystring';
import * as _assert from 'node:assert';
import * as _stream from 'node:stream';
import * as _fs from 'node:fs';
import * as _crypto from 'node:crypto';
import * as _zlib from 'node:zlib';
import * as _readline from 'node:readline';
import * as _ph from 'node:perf_hooks';
import * as _ah from 'node:async_hooks';
import * as _timers from 'node:timers';
import * as _events from 'node:events';
import * as _dns from 'node:dns';
import * as _net from 'node:net';
import * as _tls from 'node:tls';
import * as _http from 'node:http';
import * as _https from 'node:https';
import * as _http2 from 'node:http2';
import * as _dgram from 'node:dgram';

@@ -33,0 +33,0 @@ import * as _ws from 'ws';

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