Skip to content

Commit

Permalink
v2.3.3
Browse files Browse the repository at this point in the history
- first example
- fix including routes
- fix including middlewares
- fix bin for running src/routes
  • Loading branch information
Idrinth committed Dec 15, 2023
1 parent 89bf8c9 commit cf1ea29
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
/.nyc_output
/coverage
/src/**/*.js
/.idea
/.idea
/examples/**/package-lock.json
/examples/**/result.json
/examples/**/result.csv
1 change: 1 addition & 0 deletions bin/run-benchmark.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
import {
run,
} from '../src/main.js';
Expand Down
12 changes: 12 additions & 0 deletions examples/jsonplaceholder.typicode.com/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@idrinth/api-bench-example_jsonplaceholder.typicode.com",
"version": "1.0.0",
"description": "",
"private": true,
"dependencies": {
"@idrinth/api-bench": "*"
},
"scripts": {
"run": "run-benchmark"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = () => ({
id: 'create post',
main: {
method: 'post',
body: {
title: 'test',
body: 'example',
userId: 1232,
},
autohandle: 'json',
url: 'https://jsonplaceholder.typicode.com/posts',
},
post: [ '^status-2xx', ],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = () => ({
id: 'delete post 1',
main: {
method: 'delete',
url: 'https://jsonplaceholder.typicode.com/posts/1',
},
post: [ '^status-2xx', ],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = () => ({
id: 'get post 1',
main: {
method: 'get',
url: 'https://jsonplaceholder.typicode.com/posts/1',
},
post: [ '^status-2xx', ],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = () => ({
id: 'list posts',
main: {
method: 'get',
url: 'https://jsonplaceholder.typicode.com/posts',
},
post: [ '^status-2xx', ],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = () => ({
id: 'patch post 454',
main: {
method: 'patch',
body: {
title: 'test',
},
autohandle: 'json',
url: 'https://jsonplaceholder.typicode.com/posts/454',
},
post: [ '^status-2xx', ],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = () => ({
id: 'update post 1',
main: {
method: 'put',
url: 'https://jsonplaceholder.typicode.com/posts/1',
autohandle: 'json',
body: {
id: 1,
userId: 9986,
body: 'updated',
title: 'Updated title',
},
},
post: [ '^status-2xx', ],
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@idrinth/api-bench",
"description": "A library to benchmark apis, no matter if rest or soap",
"license": "MIT",
"version": "2.3.0",
"version": "2.3.3",
"homepage": "https://github.com/Idrinth/api-bench",
"type": "module",
"main": "src/main.js",
Expand Down
5 changes: 4 additions & 1 deletion src/helper/include-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import isCallable from 'is-callable';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const include = async(path: string,): Promise<any> => {
let val = await import(path.replace(/\/\//ug, '/',).replace(/ts$/u, 'js',),);
path = path
.replace(/\/\//ug, '/',)
.replace(/ts$/u, 'js',);
let val = await import('file://' + path,);
if (typeof val === 'object' && val.default) {
val = val.default;
}
Expand Down
11 changes: 8 additions & 3 deletions src/helper/middleware-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@ import {
} from '../middleware.js';
import * as reqlib from 'app-root-path';
import include from './include-default.js';
import {
realpathSync,
} from 'fs';
import url from 'url';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url,),);

const FIRST = 0;
const SECOND = 1;
const cache: HashMap = {};
const resolve = (path: string,): string => {
const shortened = path.substring(SECOND,);
if (path[FIRST] === '^') {
return '../middlewares/' + shortened;
return realpathSync(__dirname + '/../middlewares/' + shortened + '.js',);
}
if (path[FIRST] === '#') {
return reqlib + '/src/middlewares/' + shortened;
return reqlib + '/src/middlewares/' + shortened + '.js';
}
if (path[FIRST] === '$') {
return shortened.replace(/\/([^/]+)$/u, '/src/middlewares/$1',);
return shortened.replace(/\/([^/]+)$/u, '/src/middlewares/$1',) + '.js';
}
return path;
};
Expand Down

0 comments on commit cf1ea29

Please sign in to comment.