Skip to content

Commit

Permalink
build: update depedencies (#63)
Browse files Browse the repository at this point in the history
* build: update depedencies

* fix!(http): change the output format

Status codes used to be output using integers, but due to some bug fix in
Zenroom, a 'string dictionary' now converts numbers to strings.  For that very
reason, we decided that the best decision to take here is to use strings instead
of integers everywhere.

Along with this, I packed in some simplifications and best-to-dos by axios docs.

* test!(redis): fix encoding of number to string

Due to recent update to Zenroom, the way 'string dictionary' works has changed,
and now it encodes numbers as strings as well, so we apply the change here too.
  • Loading branch information
denizenging authored Dec 12, 2023
1 parent 9a0ed9c commit eb5274c
Show file tree
Hide file tree
Showing 13 changed files with 714 additions and 892 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
"publish:ci": "lerna version --no-changelog --conventional-commits --yes && pnpm publish -r --no-git-checks"
},
"devDependencies": {
"@lerna-lite/publish": "^2.6.0",
"@types/node": "^20.9.0",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"@lerna-lite/publish": "^2.7.2",
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"ava": "^5.3.1",
"c8": "^8.0.1",
"esbuild": "^0.19.5",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"nock": "^13.3.8",
"prettier": "^3.0.3",
"ts-node": "^10.9.1",
"esbuild": "^0.19.9",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"nock": "^13.4.0",
"prettier": "^3.1.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"typedoc": "^0.25.3",
"typedoc": "^0.25.4",
"typescript": "5.2.2"
}
}
6 changes: 3 additions & 3 deletions pkg/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"access": "public"
},
"devDependencies": {
"@playwright/test": "^1.39.0",
"@types/node": "^20.3.1",
"esbuild": "^0.18.4"
"@playwright/test": "^1.40.1",
"@types/node": "^20.10.4",
"esbuild": "^0.18.20"
},
"scripts": {
"build": "pnpm exec esbuild --bundle src/index.ts --outfile=build/slangroom.js --target=es2016 --external:fs --external:path --external:crypto && cp build/slangroom.js public"
Expand Down
4 changes: 2 additions & 2 deletions pkg/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"dependencies": {
"@slangroom/core": "workspace:*",
"@slangroom/shared": "workspace:*",
"axios": "^1.5.1",
"web3": "^4.2.1",
"axios": "^1.6.2",
"web3": "^4.3.0",
"web3-validator": "^2.0.3"
},
"repository": "https://github.com/dyne/slangroom",
Expand Down
2 changes: 1 addition & 1 deletion pkg/fs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.9.6",
"dependencies": {
"@slangroom/core": "workspace:*",
"axios": "^1.5.1",
"axios": "^1.6.2",
"extract-zip": "^2.0.1"
},
"repository": "https://github.com/dyne/slangroom",
Expand Down
2 changes: 1 addition & 1 deletion pkg/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.9.6",
"dependencies": {
"@slangroom/core": "workspace:*",
"isomorphic-git": "^1.24.5"
"isomorphic-git": "^1.25.1"
},
"repository": "https://github.com/dyne/slangroom",
"license": "AGPL-3.0-only",
Expand Down
2 changes: 1 addition & 1 deletion pkg/http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dependencies": {
"@slangroom/core": "workspace:*",
"@slangroom/shared": "workspace:*",
"axios": "^1.5.1"
"axios": "^1.6.2"
},
"repository": "https://github.com/dyne/slangroom",
"license": "AGPL-3.0-only",
Expand Down
94 changes: 40 additions & 54 deletions pkg/http/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JsonableArray } from '@slangroom/shared';
import type { JsonableArray, JsonableObject } from '@slangroom/shared';
import { Plugin, type PluginExecutor } from '@slangroom/core';
import axios, { type AxiosRequestConfig } from 'axios';

Expand All @@ -23,72 +23,58 @@ const defaultRequest = (m: HttpMethod): PluginExecutor => {
// TODO: typecheck headers
const headers = ctx.get('headers') as any;
const object = ctx.get('object');
let error: any = null;
const conf: AxiosRequestConfig = { url: url, method: m };
if (object) conf.data = object;
if (headers) conf.headers = headers;
const req = await request(conf).catch((e) => (error = e));
const zenResult = error
? { status: error.code, error: '' }
: { status: req.status, result: req.data || '' };
return ctx.pass(zenResult);
try {
const req = await request(conf);
return ctx.pass({ status: req.status.toString(), result: req.data });
} catch (e) {
if (axios.isAxiosError(e)) return ctx.pass({ status: e.code ?? '', result: '' });
throw e;
}
};
};

const parallelRequest = (m: HttpMethod): PluginExecutor => {
const sameParallelRequest = (m: HttpMethod, isSame: boolean): PluginExecutor => {
return async (ctx) => {
const reqs = [];
const reqs: ReturnType<typeof request<any>>[] = [];
const urls = ctx.fetchConnect();
// TODO: typecheck object (JsonableArray of JsonableObject)
const objects = ctx.get('object') as undefined | JsonableArray;
// TODO: typecheck headers
const headers = ctx.get('headers') as any;
for (const [i, u] of urls.entries()) {
const conf: AxiosRequestConfig = { url: u, method: m };
if (objects) conf.data = objects[i];
if (headers) conf.headers = headers;
reqs.push(request(conf));

if (isSame) {
// TODO: typecheck object JsonableObject
const object = ctx.get('object') as undefined | JsonableObject;
for (const u of urls) {
const conf: AxiosRequestConfig = { url: u, method: m };
if (headers) conf.headers = headers;
if (object) conf.data = object;
reqs.push(request(conf));
}
}
// parallel
else {
// TODO: typecheck object (JsonableArray of JsonableObject)
const objects = ctx.get('object') as undefined | JsonableArray;
for (const [i, u] of urls.entries()) {
const conf: AxiosRequestConfig = { url: u, method: m };
if (headers) conf.headers = headers;
if (objects) conf.data = objects[i];
reqs.push(request(conf));
}
}

const results: JsonableArray = new Array(reqs.length);
const errors: { [key: number]: any } = {};
const parallelWithCatch = reqs.map((v, i) => v.catch((e) => (errors[i] = e)));
const parallelResults = await axios.all(parallelWithCatch);
parallelResults.map((r, i) => {
const zenResult = errors[i]
? { status: errors[i].code, result: '' }
: { status: r.status, result: r.data || '' };
results[i] = zenResult;
});
return ctx.pass(results);
};
};
const results = (await Promise.allSettled(reqs)).map((x) => {
if (x.status === 'fulfilled')
return { status: x.value.status.toString(), result: x.value.data };

const sameRequest = (m: HttpMethod): PluginExecutor => {
return async (ctx) => {
const reqs = [];
const urls = ctx.fetchConnect();
// TODO: typecheck object (JsonableArray of JsonableObject)
const object = ctx.get('object') as undefined | JsonableArray;
// TODO: typecheck headers
const headers = ctx.get('headers') as any;
for (const u of urls) {
const conf: AxiosRequestConfig = { url: u, method: m };
if (object) conf.data = object;
if (headers) conf.headers = headers;
reqs.push(request(conf));
}
const err = x.reason;
if (axios.isAxiosError(err)) return { status: err.code ?? '', result: '' };

const results: JsonableArray = new Array(reqs.length);
const errors: { [key: number]: any } = {};
const parallelWithCatch = reqs.map((v, i) => v.catch((e) => (errors[i] = e)));
const parallelResults = await axios.all(parallelWithCatch);
parallelResults.map((r, i) => {
const zenResult = errors[i]
? { status: errors[i].code, result: '' }
: { status: r.status, result: r.data || '' };
results[i] = zenResult;
throw x.reason;
});

return ctx.pass(results);
};
};
Expand Down Expand Up @@ -130,10 +116,10 @@ export const sames = {} as typeof defaults;
cb = (ctx) => ctx.fail('not implemented');
} else if (x === parallels) {
phrase = `do parallel ${m}`;
cb = parallelRequest(m);
cb = sameParallelRequest(m, false);
} else if (x === sames) {
phrase = `do same ${m}`;
cb = sameRequest(m);
cb = sameParallelRequest(m, true);
} else {
throw new Error('unreachable');
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/http/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Then I connect to 'final_endpoints' and send object 'string_array' and do parall
final_endpoints: ['http://localhost/sendresult', 'http://localhost/sendresult'],
string_array: [{ req: 'Hola chico!' }, { req: 'Hi!' }],
results: [
{ status: 200, result: 'received result' },
{ status: 200, result: 'received result' },
{ status: '200', result: 'received result' },
{ status: '200', result: 'received result' },
],
},
res.logs,
Expand Down Expand Up @@ -83,7 +83,7 @@ Then print data
{
auth: {
result: 'Yes, you can!',
status: 200,
status: '200',
},
},
res.logs,
Expand Down
16 changes: 8 additions & 8 deletions pkg/http/test/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test('Simple GET', async (t) => {
t.deepEqual(res, {
ok: true,
value: {
status: 200,
status: '200',
result: {
userId: 1,
myArray: [1, 2, 3, 4, 5],
Expand All @@ -65,7 +65,7 @@ test('single put with data', async (t) => {
const res = await defaults.putObject(ctx);
t.deepEqual(res, {
ok: true,
value: { status: 200, result: 'received result' },
value: { status: '200', result: 'received result' },
});
});

Expand All @@ -76,7 +76,7 @@ test('single post with data', async (t) => {
const res = await defaults.postObject(ctx);
t.deepEqual(res, {
ok: true,
value: { status: 200, result: 'received result' },
value: { status: '200', result: 'received result' },
});
});

Expand All @@ -89,8 +89,8 @@ test('multiple post with data', async (t) => {
t.deepEqual(res, {
ok: true,
value: [
{ status: 200, result: 'received result' },
{ status: 404, result: "doesn't exist, mate" },
{ status: '200', result: 'received result' },
{ status: '404', result: "doesn't exist, mate" },
],
});
});
Expand All @@ -108,9 +108,9 @@ test('POSTs with custom different', async (t) => {
t.deepEqual(res, {
ok: true,
value: [
{ status: 200, result: 'received result' },
{ status: 404, result: "doesn't exist, mate" },
{ status: 500, result: 'Did not receive the result' },
{ status: '200', result: 'received result' },
{ status: '404', result: "doesn't exist, mate" },
{ status: '500', result: 'Did not receive the result' },
],
});
});
2 changes: 1 addition & 1 deletion pkg/redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@slangroom/redis",
"version": "1.10.0",
"dependencies": {
"@redis/client": "^1.5.11",
"@redis/client": "^1.5.12",
"@slangroom/core": "workspace:*",
"@slangroom/shared": "workspace:*"
},
Expand Down
13 changes: 6 additions & 7 deletions pkg/redis/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { redis } from '@slangroom/redis';
test('Redis write and read back', async (t) => {
const obj = {
name: 'test person',
age: Math.floor(Math.random() * 100),
}
age: Math.floor(Math.random() * 100).toString(),
};
const writeRedis = `
Rule unknown ignore
Given I connect to 'redis' and send key 'key1' and send object 'object1' and write object into key in redis
Expand All @@ -20,12 +20,11 @@ Then I connect to 'redis' and send key 'key1' and read key from redis and output
const slangroom = new Slangroom(redis);
const res = await slangroom.execute(writeRedis, {
keys: {
redis: "redis://localhost:6379",
redis: 'redis://localhost:6379',
object1: obj,
key1: 'persona'
key1: 'persona',
},
});
t.deepEqual(res["result"]["read1"], obj);
t.deepEqual(res["result"]["read2"], {});
t.deepEqual(res['result']['read1'], obj);
t.deepEqual(res['result']['read2'], {});
});

2 changes: 1 addition & 1 deletion pkg/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@slangroom/core": "workspace:*",
"@slangroom/shared": "workspace:*",
"bs58": "^5.0.0",
"jose": "^5.1.0"
"jose": "^5.1.3"
},
"repository": "https://github.com/dyne/slangroom",
"license": "AGPL-3.0-only",
Expand Down
Loading

0 comments on commit eb5274c

Please sign in to comment.