Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [12.x, 14.x, 16.x, 18.x, 20.x, 22.x, 24.x]
node-version: [14.x, 16.x, 18.x, 20.x, 22.x, 24.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down Expand Up @@ -47,6 +47,7 @@ jobs:
- name: Testing all packages
env:
LD_LIBRARY_PATH: '/deps/lib'
DEBUG: 'ezs:error,ezs:warn'
run: yarn run ci:test

- name: Coveralls Parallel
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
"packages/*"
],
"engines": {
"node": ">=12.0.0",
"node": ">=14.0.0",
"yarn": ">= 1.0.0",
"npm": "Please use Yarn instead of NPM to install dependencies. See: https://yarnpkg.com/lang/en/docs/install/"
},
"devDependencies": {
"@babel/cli": "7.13.14",
"@babel/core": "7.13.15",
"@babel/plugin-proposal-class-properties": "7.13.0",
"@babel/plugin-proposal-json-strings": "7.13.8",
"@babel/cli": "7.28.0",
"@babel/core": "7.28.0",
"@babel/plugin-proposal-class-properties": "7.18.6",
"@babel/plugin-proposal-json-strings": "7.18.6",
"@babel/plugin-syntax-dynamic-import": "7.8.3",
"@babel/plugin-syntax-import-meta": "7.10.4",
"@babel/plugin-transform-modules-commonjs": "7.13.8",
"@babel/preset-env": "7.13.15",
"@babel/register": "7.13.14",
"@types/jest": "26.0.22",
"@types/ramda": "0.27.40",
"@babel/plugin-transform-modules-commonjs": "7.27.1",
"@babel/preset-env": "7.28.0",
"@babel/register": "7.27.1",
"@types/jest": "30.0.0",
"@types/ramda": "0.31.0",
"array-parallel": "0.1.3",
"array-series": "0.1.5",
"babel-eslint": "10.1.0",
"babel-jest": "26.6.3",
"babel-jest": "30.0.5",
"coveralls": "3.1.1",
"documentation": "14.0.3",
"eslint": "7.24.0",
"eslint-config-airbnb-base": "14.2.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-prettier": "3.4.0",
"eslint": "9.32.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "10.1.8",
"eslint-plugin-import": "2.32.0",
"eslint-plugin-prettier": "5.5.4",
"feed": "4.2.2",
"from": "0.1.7",
"get-stream": "6.0.1",
Expand Down
13 changes: 8 additions & 5 deletions packages/basics/test/basics.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
const assert = require('assert');
const from = require('from');
const { PassThrough } = require('stream');
const ezs = require('../../core/src');
import assert from 'assert';
import { PassThrough } from 'stream';
import fs from 'fs';
import from from 'from';
import ezs from '../../core/src';
import statements from '../src';

ezs.use(statements);

ezs.use(require('../src'));

describe('test', () => {
it('CSVObject #1', (done) => {
Expand Down
9 changes: 5 additions & 4 deletions packages/basics/test/tar-dump.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const assert = require('assert');
const from = require('from');
const ezs = require('../../core/src');
import assert from 'assert';
import from from 'from';
import ezs from '../../core/src';
import ezsBasics from '../src';

ezs.use(require('../src'));
ezs.use(ezsBasics);

describe('TARDump', () => {
const input = [
Expand Down
9 changes: 5 additions & 4 deletions packages/basics/test/tar-extract.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const assert = require('assert');
const fs = require('fs');
const ezs = require('../../core/src');
import assert from 'assert';
import fs from 'fs';
import ezs from '../../core/src';
import ezsBasics from '../src';

ezs.use(require('../src'));
ezs.use(ezsBasics);

describe('TARExtract', () => {
it('should extract JSON content (manual)', (done) => {
Expand Down
11 changes: 6 additions & 5 deletions packages/basics/test/txt-zip.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const assert = require('assert');
const from = require('from');
const pako = require('pako');
const ezs = require('../../core/src');
import assert from 'assert';
import from from 'from';
import pako from 'pako';
import ezs from '../../core/src';
import ezsBasics from '../src';

ezs.use(require('../src'));
ezs.use(ezsBasics);

describe('txt-zip', () => {
it('should zip a stream containing a string', (done) => {
Expand Down
10 changes: 6 additions & 4 deletions packages/basics/test/zip-extract.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const assert = require('assert');
const fs = require('fs');
const ezs = require('../../core/src');
import assert from 'assert';
import fs from 'fs';
import from from 'from';
import ezs from '../../core/src';
import ezsBasics from '../src';

ezs.use(require('../src'));
ezs.use(ezsBasics);

describe('ZIPExtract', () => {
it('should extract JSON content', (done) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/core/bin/ezs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
require('app-module-path/cwd');
require('../lib/cli').default(console.error);
import 'app-module-path/cwd.js';
import cli from '../src/cli.js';

cli(console.error);
6 changes: 5 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@
"transformer"
],
"license": "MIT",
"main": "./lib/index.js",
"type": "module",
"exports": {
"import": "./src/index.js",
"require": "./lib/index.js"
},
"publishConfig": {
"access": "public"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/compactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const z = chooseZ();

export function compressStream(ezs, opts = {}) {
const encoding = opts['Content-Encoding'] || opts['content-encoding'] || 'identity';
if (typeof z.createGunzip === 'function' && encoding === 'gzip') {
if (z && typeof z.createGunzip === 'function' && encoding === 'gzip') {
debug('ezs:debug')('ezs will use zlib to compress stream.');
return z.createGzip();
}
Expand All @@ -32,7 +32,7 @@ export function compressStream(ezs, opts = {}) {

export function uncompressStream(ezs, opts = {}) {
const encoding = opts['Content-Encoding'] || opts['content-encoding'] || 'identity';
if (typeof z.createGunzip === 'function' && encoding === 'gzip') {
if (z && typeof z.createGunzip === 'function' && encoding === 'gzip') {
debug('ezs:debug')('ezs will use zlib to uncompress stream.');
return z.createGunzip();
}
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import fs from 'fs';
import path from 'path';
import filenameRegex from 'filename-regex';
import { version } from '../package.json';
import filedirname from 'filedirname';

const [, dirname] = filedirname();
const pckg = JSON.parse(fs.readFileSync(path.resolve(dirname, '../package.json')));

export const VERBOSE = 'ezs:*,-ezs:debug,-ezs:trace';
export const VERSION = version;
export const VERSION = pckg.version;
export const STARTED_AT = Date.now();
export const RX_FILENAME = filenameRegex();
4 changes: 2 additions & 2 deletions packages/core/src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function findFileIn(paths, name) {
export function useFile(ezs, name) {
const names = [
name,
'@ezs/'.concat(name.replace(/^@ezs\//, '')),
'ezs-'.concat(name.replace(/^ezs-/, '')),
'@ezs/'.concat(String(name).replace(/^@ezs\//, '')),
'ezs-'.concat(String(name).replace(/^ezs-/, '')),
];
const plugName1 = names.map((n) => check(n)).filter(Boolean).shift();
const plugName2 = names.map((n) => findFileIn(ezs.getPath(), n)).filter(Boolean).shift();
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ ezs.parseFile = (filename) => Script(ezs.loadScript(filename));
ezs.catch = (func) => new Catcher(func);
ezs.toBuffer = (options) => new Output(options);
ezs.use = (plugin) => Statement.set(ezs, plugin);
ezs.useFiles = (files) => {
if (files) {
files.map(file=> Statement.load(ezs, file));
}
return Statement.list();
};
ezs.addPath = (p) => ezs.settings.pluginPaths.push(p);
ezs.getPath = () => ezs.settings.pluginPaths;
ezs.getCache = () => ezsCache;
Expand Down Expand Up @@ -150,4 +156,5 @@ ezs.createTrap = (file, env) => {
};
ezs.use(Statements);

module.exports = ezs;
//module.exports = ezs;
export default ezs;
2 changes: 2 additions & 0 deletions packages/core/src/json.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Expression from './expression.js';

function parse(data) {
if (!data) return data;
return JSON.parse(data, (key, value) => {
if (value && typeof value === 'string' && value.indexOf('Expression::') === 0) {
return new Expression(JSON.parse(value.replace('Expression::', '')));
Expand All @@ -10,6 +11,7 @@ function parse(data) {
}

function stringify(data) {
if (!data) return data;
return JSON.stringify(data);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server/errorHandler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import debug from 'debug';
import JSONB from 'json-buffer';
import { httpRequestErrorTotal } from './metrics';
import { httpRequestErrorTotal } from './metrics.js';

const errorHandler = (ezs, request, response) => (error, code = 400) => {
const stringError = ezs.serializeError(error);
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import eos from 'end-of-stream';
import controlServer from 'http-shutdown';
import { parse } from 'url';
import debug from 'debug';
import knownPipeline from './knownPipeline';
import serverInformation from './serverInformation';
import serverControl from './serverControl';
import errorHandler from './errorHandler';
import settings from '../settings';
import { RX_FILENAME } from '../constants';
import knownPipeline from './knownPipeline.js';
import serverInformation from './serverInformation.js';
import serverControl from './serverControl.js';
import errorHandler from './errorHandler.js';
import settings from '../settings.js';
import { RX_FILENAME } from '../constants.js';
import {
metrics,
httpConnectionTotal,
httpConnectionOpen,
httpRequestDurationMicroseconds,
aggregatorRegistry,
} from './metrics';
} from './metrics.js';
import {
createFusible,
enableFusible,
disableFusible
} from '../fusible';
} from '../fusible.js';

function isPipeline() {
const f = this.pathName.match(RX_FILENAME);
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/server/knownPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { pipeline } from 'stream';
import once from 'once';
import merge from 'lodash/merge.js';
import cloneDeep from 'lodash/cloneDeep.js';
import { metricsHandle } from './metrics';
import errorHandler from './errorHandler';
import { isFile } from '../file';
import breaker from '../statements/breaker';
import settings from '../settings';
import { metricsHandle } from './metrics.js';
import errorHandler from './errorHandler.js';
import { isFile } from '../file.js';
import breaker from '../statements/breaker.js';
import settings from '../settings.js';

const dispositionFrom = ({ extension }) => (extension ? `attachment; filename="dump.${extension}"` : 'inline');

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AggregatorRegistry,
collectDefaultMetrics,
} from 'prom-client';
import settings from '../settings';
import settings from '../settings.js';



Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/server/serverControl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import debug from 'debug';
import { disableFusible } from '../fusible';
import { disableFusible } from '../fusible.js';

const serverInformation = () => (request, response, next) => {
if (!request.methodMatch(['DELETE']) || request.pathName !== '/') {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/server/serverInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import pathExists from 'path-exists';
import autocast from 'autocast';
import { dirname, resolve as pathResolve } from 'path';
import _ from 'lodash';
import settings from '../settings';
import settings from '../settings.js';
import {
VERSION, STARTED_AT,
} from '../constants';
} from '../constants.js';

const keyOfPathItemObject = [ // https://swagger.io/specification/
'$ref',
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { useFile } from './file.js';
import transit from './statements/transit.js';

const pluginsModules = {};
const pluginsFiles = [];
const pluginsList = {};

function set(ezs, plugin) {
if (typeof plugin !== 'object') {
throw new Error(
"Statement is not loaded. It's not a valid plugin (should be an object).",
'Statement is not loaded. It\'s not a valid plugin (should be an object).',
);
}
const pluginList = plugin.default ? plugin.default : plugin; // ES6 hack
Expand All @@ -35,6 +36,7 @@ function load(ezs, name) {
);
}
if (!pluginsModules[fileName]) {
pluginsFiles.push(fileName);
pluginsModules[fileName] = import(fileName);
pluginsModules[fileName].then((funcs) => {
set(ezs, funcs);
Expand Down Expand Up @@ -93,9 +95,14 @@ function exists(ezs, pluginName) {
return pluginsList[pluginName] !== undefined;
}

function list() {
return pluginsFiles;
}

export default {
get,
set,
load,
exists,
list,
};
2 changes: 1 addition & 1 deletion packages/core/src/statements/breaker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import debug from 'debug';
import { checkFusible } from '../fusible';
import { checkFusible } from '../fusible.js';
/**
* Break the stream if the control file cannot be checked
*
Expand Down
Loading