Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
albertolerda committed Oct 27, 2023
1 parent da3bfbb commit a6abfa4
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 103 deletions.
88 changes: 44 additions & 44 deletions pkg/browser/package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
{
"name": "@slangroom/browser",
"dependencies": {
"@slangroom/core": "workspace:*",
"@slangroom/http": "workspace:*"
},
"version": "1.4.0",
"repository": "https://github.com/dyne/slangroom",
"license": "AGPL-3.0-only",
"type": "module",
"main": "./build/cjs/src/index.js",
"types": "./build/cjs/src/index.d.ts",
"exports": {
".": {
"import": {
"types": "./build/esm/src/index.d.ts",
"default": "./build/esm/src/index.js"
},
"require": {
"types": "./build/cjs/src/index.d.ts",
"default": "./build/cjs/src/index.js"
}
},
"./*": {
"import": {
"types": "./build/esm/src/*.d.ts",
"default": "./build/esm/src/*.js"
},
"require": {
"types": "./build/cjs/src/*.d.ts",
"default": "./build/cjs/src/*.js"
}
}
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@playwright/test": "^1.39.0",
"@types/node": "^20.3.1",
"esbuild": "^0.18.4"
},
"scripts": {
"build": "pnpm exec esbuild --bundle src/index.ts --outfile=public/slangroom.js --external:fs --external:path --external:crypto"
}
"name": "@slangroom/browser",
"dependencies": {
"@slangroom/core": "workspace:*",
"@slangroom/http": "workspace:*"
},
"version": "1.4.0",
"repository": "https://github.com/dyne/slangroom",
"license": "AGPL-3.0-only",
"type": "module",
"main": "./build/cjs/src/index.js",
"types": "./build/cjs/src/index.d.ts",
"exports": {
".": {
"import": {
"types": "./build/esm/src/index.d.ts",
"default": "./build/esm/src/index.js"
},
"require": {
"types": "./build/cjs/src/index.d.ts",
"default": "./build/cjs/src/index.js"
}
},
"./*": {
"import": {
"types": "./build/esm/src/*.d.ts",
"default": "./build/esm/src/*.js"
},
"require": {
"types": "./build/cjs/src/*.d.ts",
"default": "./build/cjs/src/*.js"
}
}
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@playwright/test": "^1.39.0",
"@types/node": "^20.3.1",
"esbuild": "^0.18.4"
},
"scripts": {
"build": "pnpm exec esbuild --bundle src/index.ts --outfile=public/slangroom.js --external:fs --external:path --external:crypto"
}
}
23 changes: 13 additions & 10 deletions pkg/browser/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@
<h1>Test http</h1>
<div id="test1"></div>
<script>
const script = `
const script = `
Rule caller restroom-mw
Given I connect to 'did_url' and do get and output into 'did'
Given I have a 'string dictionary' named 'did'
Given I have a 'string' named 'foo'
Then print data
`;

const resDiv = document.getElementById('test1');
const resDiv = document.getElementById('test1');

slangroom.execute(script, {
data: {
foo: "bar",
did_url: "https://did.dyne.org/dids/did:dyne:sandbox.test:pEn78CGNEKvMR7DJQ1yvUVUpAHKzsBz45mQw3zD2js9",
}
}).then((r) => {
resDiv.innerText = JSON.stringify(r.result);
});
slangroom
.execute(script, {
data: {
foo: 'bar',
did_url:
'https://did.dyne.org/dids/did:dyne:sandbox.test:pEn78CGNEKvMR7DJQ1yvUVUpAHKzsBz45mQw3zD2js9',
},
})
.then((r) => {
resDiv.innerText = JSON.stringify(r.result);
});
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions pkg/browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Slangroom } from "@slangroom/core";
import { httpPlugins } from "@slangroom/http";
import { Slangroom } from '@slangroom/core';
import { httpPlugins } from '@slangroom/http';
const slangroom = new Slangroom(httpPlugins);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
4 changes: 2 additions & 2 deletions pkg/browser/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import test from 'ava'
import test from 'ava';

test("make ava happpy", (t) => t.truthy(true));
test('make ava happpy', (t) => t.truthy(true));
8 changes: 5 additions & 3 deletions pkg/browser/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { test, expect } from '@playwright/test';

test('check results of slangroom', async ({ page }) => {
await page.goto('http://localhost:8080/');
await page.goto('http://localhost:8080/');

// Expects page to have a heading with the name of Installation.
await expect(page.locator('#test1')).toContainText("did:dyne:sandbox.test:pEn78CGNEKvMR7DJQ1yvUVUpAHKzsBz45mQw3zD2js9");
// Expects page to have a heading with the name of Installation.
await expect(page.locator('#test1')).toContainText(
'did:dyne:sandbox.test:pEn78CGNEKvMR7DJQ1yvUVUpAHKzsBz45mQw3zD2js9'
);
});
1 change: 0 additions & 1 deletion pkg/core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ export class PluginContextTest implements PluginContext {
return new this(connect, {});
}


/**
* @constructor
*/
Expand Down
34 changes: 17 additions & 17 deletions pkg/core/test/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ test('generated ast is correct', async (t) => {
bindings: new Map<string, string>(),
},
"connect to 'foo' and send address 'addr' and send contract 'contract' and read the ethereum balance":
{
openconnect: 'foo',
phrase: 'read the ethereum balance',
bindings: new Map<string, string>([
['address', 'addr'],
['contract', 'contract'],
]),
},
{
openconnect: 'foo',
phrase: 'read the ethereum balance',
bindings: new Map<string, string>([
['address', 'addr'],
['contract', 'contract'],
]),
},
"open 'foo' and send address 'addr' and send contract 'contract' and read the ethereum balance and output into 'var'":
{
openconnect: 'foo',
phrase: 'read the ethereum balance',
bindings: new Map<string, string>([
['address', 'addr'],
['contract', 'contract'],
]),
into: 'var',
},
{
openconnect: 'foo',
phrase: 'read the ethereum balance',
bindings: new Map<string, string>([
['address', 'addr'],
['contract', 'contract'],
]),
into: 'var',
},
};

for (const [line, astWant] of Object.entries(cases)) {
Expand Down
9 changes: 4 additions & 5 deletions pkg/ethereum/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import {
type PhraseCst,
} from '@slangroom/ethereum';

import {
type CstNode,
type CstElement,
} from '@slangroom/deps/chevrotain';
import { type CstNode, type CstElement } from '@slangroom/deps/chevrotain';

export enum EthereumRequestKind {
EthereumNonce,
Expand Down Expand Up @@ -80,7 +77,9 @@ class V extends CstVisitor {
totalSupply() {
return EthereumRequestKind.Erc20TotalSupply;
}
id(ctx: any) { ctx; }
id(ctx: any) {
ctx;
}
}

const Visitor = new V();
Expand Down
1 change: 0 additions & 1 deletion pkg/ethereum/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,4 @@ Then print data
}
t.falsy(false);
return;

});
24 changes: 18 additions & 6 deletions pkg/http/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { CstParser, type IToken, type CstNode } from '@slangroom/deps/chevrotain';
import { allTokens, Do, Get, Post, Patch, Put, Delete, Sequential, Parallel, Same } from '@slangroom/http';
import {
allTokens,
Do,
Get,
Post,
Patch,
Put,
Delete,
Sequential,
Parallel,
Same,
} from '@slangroom/http';

export type PhraseCst = CstNode & {
children: {
Expand All @@ -13,11 +24,12 @@ export type KindCst = CstNode & {
};

export type MethodCst = CstNode & {
children: { Get: [IToken] }
| { Post: [IToken] }
| { Patch: [IToken] }
| { Put: [IToken] }
| { Delete: [IToken] };
children:
| { Get: [IToken] }
| { Post: [IToken] }
| { Patch: [IToken] }
| { Put: [IToken] }
| { Delete: [IToken] };
};

const Parser = new (class extends CstParser {
Expand Down
18 changes: 9 additions & 9 deletions pkg/http/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export const execute = async (
const headers = ctx.get('headers');
if (kind === RequestKind.Default) {
let error: any = null;
let requestData: AxiosRequestConfig = {
const requestData: AxiosRequestConfig = {
url: url,
method: method,
data: ctx.get('object') as any,
}
if(headers) {
};
if (headers) {
requestData['headers'] = headers as any;
}
const req = await request(requestData).catch((e) => (error = e));
Expand All @@ -62,12 +62,12 @@ export const execute = async (
// JsonableObject)
const objects = ctx.fetch('object') as JsonableArray;
for (const [i, u] of urls.entries()) {
let requestData: AxiosRequestConfig = {
const requestData: AxiosRequestConfig = {
url: u,
method: method,
data: objects[i],
}
if(headers) {
};
if (headers) {
requestData['headers'] = headers as any;
}
reqs.push(request(requestData));
Expand All @@ -76,12 +76,12 @@ export const execute = async (
// TODO: check type of body (needs to be JsonableObject)
const object = ctx.fetch('object') as JsonableArray;
for (const u of urls) {
let requestData: AxiosRequestConfig = {
const requestData: AxiosRequestConfig = {
url: u,
method: method,
data: object,
}
if(headers) {
};
if (headers) {
requestData['headers'] = headers as any;
}
reqs.push(request(requestData));
Expand Down
13 changes: 12 additions & 1 deletion pkg/http/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,15 @@ export const Sequential = createToken({
pattern: /sequential/i,
});

export const allTokens = [Whitespace, Get, Post, Patch, Put, Delete, Parallel, Sequential, Same, Do];
export const allTokens = [
Whitespace,
Get,
Post,
Patch,
Put,
Delete,
Parallel,
Sequential,
Same,
Do,
];
4 changes: 2 additions & 2 deletions pkg/http/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ Then print data
data: {
auth_url: 'http://localhost/auth-required',
headers: {
authorization: 'Basic Auth test'
}
authorization: 'Basic Auth test',
},
},
});
t.deepEqual(
Expand Down

0 comments on commit a6abfa4

Please sign in to comment.