diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
index 96f4831dc..e2ec33a9d 100644
--- a/.github/workflows/unit-tests.yml
+++ b/.github/workflows/unit-tests.yml
@@ -21,3 +21,5 @@ jobs:
run: npm run test --workspace=packages/bruno-schema
- name: Test Package bruno-app
run: npm run test --workspace=packages/bruno-app
+ - name: Test Package bruno-js
+ run: npm run test --workspace=packages/bruno-js
diff --git a/contributing.md b/contributing.md
index d0a701def..6b70dc028 100644
--- a/contributing.md
+++ b/contributing.md
@@ -23,25 +23,7 @@ You would need [Node v14.x or the latest LTS version](https://nodejs.org/en/) an
### Lets start coding
-```bash
-# clone and cd into bruno
-# use Node 14.x, Npm 8.x
-
-# Install deps (note that we use npm workspaces)
-npm i
-
-# run next app
-npm run dev:web
-
-# run electron app
-# neededonly if you want to test changes related to electron app
-# please note that both web and electron use the same code
-# if it works in web, then it should also work in electron
-npm run dev:electron
-
-# open in browser
-open http://localhost:3000
-```
+Please reference [development.md](docs/development.md) for instructions on running the local development environment.
### Raising Pull Request
diff --git a/docs/development.md b/docs/development.md
index 7e9de44ea..91c1b0e5f 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -1,40 +1,40 @@
-## development
+## Development
Bruno is deing developed as a desktop app. You need to load the app by running the nextjs app in one terminal and then run the electron app in another terminal.
### Dependencies
* NodeJS v18
-###
+### Local Development
```bash
# use nodejs 18 version
nvm use
# install deps
-npm i
+npm i --legacy-peer-deps
-# run next app
-npm run dev --workspace=packages/bruno-app
+# build graphql docs
+npm run build:graphql-docs
-# run electron app
-npm run dev --workspace=packages/bruno-electron
+# run next app (terminal 1)
+npm run dev:web
-# build next app
-npm run build --workspace=packages/bruno-app
+# run electron app (terminal 2)
+npm run dev:electron
```
-### fix
+### Troubleshooting
You might encounter a `Unsupported platform` error when you run `npm install`. To fix this, you will need to delete `node_modules` and `package-lock.json` and run `npm install`. This should install all the necessary packages needed to run the app.
-### testing
+### Testing
```bash
# bruno-schema
npm test --workspace=packages/bruno-schema
# bruno-lang
-npm test --workspace=packages/bruno-schema
+npm test --workspace=packages/bruno-lang
```
diff --git a/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/index.js b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/index.js
index 626bda1b8..9fbb008d5 100644
--- a/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/index.js
+++ b/packages/bruno-app/src/components/Environments/EnvironmentSettings/EnvironmentList/index.js
@@ -1,5 +1,6 @@
import React, { useEffect, useState, forwardRef, useRef } from 'react';
import { findEnvironmentInCollection } from 'utils/collections';
+import usePrevious from 'hooks/usePrevious';
import EnvironmentDetails from './EnvironmentDetails';
import CreateEnvironment from '../CreateEnvironment/index';
import StyledWrapper from './StyledWrapper';
@@ -9,14 +10,36 @@ const EnvironmentList = ({ collection }) => {
const [selectedEnvironment, setSelectedEnvironment] = useState(null);
const [openCreateModal, setOpenCreateModal] = useState(false);
+ const envUids = environments ? environments.map((env) => env.uid) : [];
+ const prevEnvUids = usePrevious(envUids);
+
useEffect(() => {
+ if(selectedEnvironment) {
+ return;
+ }
+
const environment = findEnvironmentInCollection(collection, collection.activeEnvironmentUid);
if(environment) {
setSelectedEnvironment(environment);
} else {
setSelectedEnvironment(environments && environments.length ? environments[0] : null);
}
- }, [collection, environments]);
+ }, [collection, environments, selectedEnvironment]);
+
+ useEffect(() => {
+ // check env add
+ if (prevEnvUids && prevEnvUids.length && envUids.length > prevEnvUids.length) {
+ const newEnv = environments.find((env) => !prevEnvUids.includes(env.uid));
+ if(newEnv){
+ setSelectedEnvironment(newEnv);
+ }
+ }
+
+ // check env delete
+ if (prevEnvUids && prevEnvUids.length && envUids.length < prevEnvUids.length) {
+ setSelectedEnvironment(environments && environments.length ? environments[0] : null);
+ }
+ }, [envUids, environments, prevEnvUids]);
if (!selectedEnvironment) {
return null;
@@ -31,7 +54,11 @@ const EnvironmentList = ({ collection }) => {
{environments &&
environments.length &&
environments.map((env) => (
-
setSelectedEnvironment(env)}>
+
setSelectedEnvironment(env)}
+ >
{env.name}
))}
diff --git a/packages/bruno-app/src/components/Sidebar/NewFolder/index.js b/packages/bruno-app/src/components/Sidebar/NewFolder/index.js
index f72a4df0f..3f9d8ffd5 100644
--- a/packages/bruno-app/src/components/Sidebar/NewFolder/index.js
+++ b/packages/bruno-app/src/components/Sidebar/NewFolder/index.js
@@ -25,7 +25,7 @@ const NewFolder = ({ collection, item, onClose }) => {
if(item && item.uid) {
return true;
}
- return !(value.trim().toLowerCase().includes('environments'))
+ return value && !(value.trim().toLowerCase().includes('environments'))
}
})
}),
diff --git a/packages/bruno-app/src/components/Sidebar/NewRequest/index.js b/packages/bruno-app/src/components/Sidebar/NewRequest/index.js
index f9b173c91..b95d29a38 100644
--- a/packages/bruno-app/src/components/Sidebar/NewRequest/index.js
+++ b/packages/bruno-app/src/components/Sidebar/NewRequest/index.js
@@ -30,7 +30,7 @@ const NewRequest = ({ collection, item, isEphermal, onClose }) => {
.test({
name: 'requestName',
message: 'The request name "index" is reserved in bruno',
- test: value => !(value.trim().toLowerCase().includes('index')),
+ test: value => value && !(value.trim().toLowerCase().includes('index')),
})
}),
onSubmit: (values) => {
diff --git a/packages/bruno-app/src/components/Sidebar/index.js b/packages/bruno-app/src/components/Sidebar/index.js
index 74b791bb2..af1c51d3f 100644
--- a/packages/bruno-app/src/components/Sidebar/index.js
+++ b/packages/bruno-app/src/components/Sidebar/index.js
@@ -117,7 +117,7 @@ const Sidebar = () => {
)}
- v0.9.3
+ v0.9.4
diff --git a/packages/bruno-app/src/hooks/usePrevious/index.js b/packages/bruno-app/src/hooks/usePrevious/index.js
new file mode 100644
index 000000000..d07e5d08c
--- /dev/null
+++ b/packages/bruno-app/src/hooks/usePrevious/index.js
@@ -0,0 +1,13 @@
+import { useRef, useEffect } from 'react';
+
+function usePrevious(value) {
+ const ref = useRef();
+
+ useEffect(() => {
+ ref.current = value; //assign the value of ref to the argument
+ },[value]); //this code will run when the value of 'value' changes
+
+ return ref.current; //in the end, return the current ref value.
+}
+
+export default usePrevious;
\ No newline at end of file
diff --git a/packages/bruno-cli/package.json b/packages/bruno-cli/package.json
index a70a79476..160d09f87 100644
--- a/packages/bruno-cli/package.json
+++ b/packages/bruno-cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@usebruno/cli",
- "version": "0.2.1",
+ "version": "0.2.3",
"main": "src/index.js",
"bin": {
"bru": "./bin/bru.js"
@@ -12,7 +12,7 @@
],
"dependencies": {
"@usebruno/js": "0.1.1",
- "@usebruno/lang": "0.2.0",
+ "@usebruno/lang": "0.2.2",
"axios": "^1.3.2",
"chai": "^4.3.7",
"chalk": "^3.0.0",
diff --git a/packages/bruno-electron/package.json b/packages/bruno-electron/package.json
index 04d23a1aa..9994ee14d 100644
--- a/packages/bruno-electron/package.json
+++ b/packages/bruno-electron/package.json
@@ -1,5 +1,5 @@
{
- "version": "0.9.3",
+ "version": "0.9.4",
"name": "bruno",
"description": "Opensource API Client",
"homepage": "https://www.usebruno.com",
@@ -14,8 +14,8 @@
},
"dependencies": {
"@usebruno/js": "0.1.0",
- "@usebruno/lang": "0.1.0",
- "@usebruno/schema": "0.1.0",
+ "@usebruno/lang": "0.2.2",
+ "@usebruno/schema": "0.3.1",
"axios": "^0.26.0",
"chai": "^4.3.7",
"chokidar": "^3.5.3",
diff --git a/packages/bruno-electron/src/app/menu-template.js b/packages/bruno-electron/src/app/menu-template.js
index 7856e32c0..9156092b7 100644
--- a/packages/bruno-electron/src/app/menu-template.js
+++ b/packages/bruno-electron/src/app/menu-template.js
@@ -18,7 +18,7 @@ const template = [
submenu: [
{ role: 'undo'},
{ role: 'redo'},
- { role: 'separator'},
+ { type: 'separator'},
{ role: 'cut'},
{ role: 'copy'},
{ role: 'paste'}
@@ -27,13 +27,12 @@ const template = [
{
label: 'View',
submenu: [
- { role: 'reload'},
{ role: 'toggledevtools'},
- { role: 'separator'},
+ { type: 'separator'},
{ role: 'resetzoom'},
{ role: 'zoomin'},
{ role: 'zoomout'},
- { role: 'separator'},
+ { type: 'separator'},
{ role: 'togglefullscreen'}
]
},
diff --git a/packages/bruno-lang/package.json b/packages/bruno-lang/package.json
index fa8704dde..d123d0f06 100644
--- a/packages/bruno-lang/package.json
+++ b/packages/bruno-lang/package.json
@@ -1,6 +1,6 @@
{
"name": "@usebruno/lang",
- "version": "0.2.0",
+ "version": "0.2.2",
"main": "src/index.js",
"files": [
"src",
diff --git a/packages/bruno-lang/v2/src/bruToJson.js b/packages/bruno-lang/v2/src/bruToJson.js
index 6ff564fbf..d7835fcf4 100644
--- a/packages/bruno-lang/v2/src/bruToJson.js
+++ b/packages/bruno-lang/v2/src/bruToJson.js
@@ -57,11 +57,12 @@ const grammar = ohm.grammar(`Bru {
meta = "meta" dictionary
- http = get | post | put | delete | options | head | connect | trace
+ http = get | post | put | delete | patch | options | head | connect | trace
get = "get" dictionary
post = "post" dictionary
put = "put" dictionary
delete = "delete" dictionary
+ patch = "patch" dictionary
options = "options" dictionary
head = "head" dictionary
connect = "connect" dictionary
@@ -237,6 +238,14 @@ const sem = grammar.createSemantics().addAttribute('ast', {
}
};
},
+ patch(_1, dictionary) {
+ return {
+ http: {
+ method: 'patch',
+ ...mapPairListToKeyValPair(dictionary.ast)
+ }
+ };
+ },
options(_1, dictionary) {
return {
http: {
diff --git a/packages/bruno-lang/v2/src/envToJson.js b/packages/bruno-lang/v2/src/envToJson.js
index 997cfef99..c040ea9a3 100644
--- a/packages/bruno-lang/v2/src/envToJson.js
+++ b/packages/bruno-lang/v2/src/envToJson.js
@@ -6,16 +6,18 @@ const grammar = ohm.grammar(`Bru {
nl = "\\r"? "\\n"
st = " " | "\\t"
+ stnl = st | nl
tagend = nl "}"
- validkey = ~(st | ":") any
- validvalue = ~nl any
+ optionalnl = ~tagend nl
+ keychar = ~(tagend | st | nl | ":") any
+ valuechar = ~(nl | tagend) any
// Dictionary Blocks
dictionary = st* "{" pairlist? tagend
- pairlist = nl* pair (~tagend nl pair)* (~tagend space)*
- pair = st* key st* ":" st* value? st*
- key = ~tagend validkey*
- value = ~tagend validvalue*
+ pairlist = optionalnl* pair (~tagend stnl* pair)* (~tagend space)*
+ pair = st* key st* ":" st* value st*
+ key = keychar*
+ value = valuechar*
vars = "vars" dictionary
}`);
@@ -68,7 +70,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
},
pair(_1, key, _2, _3, _4, value, _5) {
let res = {};
- res[key.ast] = _.get(value, 'ast[0]', '');
+ res[key.ast] = value.ast ? value.ast.trim() : '';
return res;
},
key(chars) {
diff --git a/packages/bruno-lang/v2/tests/envToJson.spec.js b/packages/bruno-lang/v2/tests/envToJson.spec.js
index ee9439933..0eacb9115 100644
--- a/packages/bruno-lang/v2/tests/envToJson.spec.js
+++ b/packages/bruno-lang/v2/tests/envToJson.spec.js
@@ -85,4 +85,33 @@ vars {
expect(output).toEqual(expected);
});
+
+ it("should parse vars with empty values", () => {
+ const input = `
+vars {
+ url:
+ phone:
+ api-key:
+}
+`;
+
+ const output = parser(input);
+ const expected = {
+ "variables": [{
+ "name": "url",
+ "value": "",
+ "enabled" : true,
+ }, {
+ "name": "phone",
+ "value": "",
+ "enabled" : true,
+ }, {
+ "name": "api-key",
+ "value": "",
+ "enabled" : true,
+ }]
+ };
+
+ expect(output).toEqual(expected);
+ });
});
diff --git a/packages/bruno-schema/package.json b/packages/bruno-schema/package.json
index 835c98b3b..5b177aaa5 100644
--- a/packages/bruno-schema/package.json
+++ b/packages/bruno-schema/package.json
@@ -1,6 +1,6 @@
{
"name": "@usebruno/schema",
- "version": "0.3.0",
+ "version": "0.3.1",
"main": "src/index.js",
"files": [
"src",