Skip to content

Commit

Permalink
Merge pull request #17 from m-ld/perf-test
Browse files Browse the repository at this point in the history
#15: Initial benchmarking, in sim folder
  • Loading branch information
gsvarovsky committed Aug 8, 2023
2 parents 740da06 + ab3733d commit 4de9a7a
Show file tree
Hide file tree
Showing 37 changed files with 1,985 additions and 269 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules/
local/
_site/
*.private.env.json
*.env
*.env
.clinic
2 changes: 1 addition & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ This `doc` folder forms the basis of the **m-ld** Gateway public documentation.

The folder is built using Eleventy to the `_site` folder, and then served by the running Gateway in the class `GatewayWebsite`.

cURLs in markdown files are generated from the corresponding .http files using `http-client.env.json`, please keep them in sync.
cURLs in markdown files are generated from the corresponding .http files in the `http` folder using `http-client.env.json`, please keep them in sync.

All files are treated as Liquid templates. They are processed once by Eleventy, and then _again_ by the gateway – hence the occasional use of double-encoded template tags such as `{{ '{{ origin }}' }}`.
4 changes: 4 additions & 0 deletions doc/_data/eleventyComputed.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* @see https://www.11ty.dev/docs/data-computed/#advanced-details
*/
module.exports = require('../_includes/http/http-client.env.json').doc;
5 changes: 5 additions & 0 deletions doc/_includes/http/accounts/activation.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
POST {{origin}}/api/v1/user/{{account}}/activation
Accept: application/json
Content-Type: application/json

{ "email": "{{email}}" }
6 changes: 6 additions & 0 deletions doc/_includes/http/accounts/insert-remotes-auth.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PATCH {{origin}}/api/v1/user/{{account}}
Authorization: Basic {{digest}}
Accept: application/json
Content-Type: application/json

{ "@insert": { "remotesAuth": "{{remotesAuth}}" } }
4 changes: 4 additions & 0 deletions doc/_includes/http/accounts/key-using-activation.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POST {{origin}}/api/v1/user/{{account}}/key
Authorization: Bearer {{jwe}}
X-Activation-Code: {{activation}}
Accept: application/json
3 changes: 3 additions & 0 deletions doc/_includes/http/accounts/key-using-root.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POST {{origin}}/api/v1/user/{{account}}/key
Authorization: Basic {{rootAccount}} {{rootKey}}
Accept: application/json
5 changes: 5 additions & 0 deletions doc/_includes/http/clone-api/async-read.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GET {{origin}}/api/v1/domain/{{account}}/{{subdomain}}/state
Authorization: Basic {{digest}}
Accept: application/json
[QueryStringParams]
q: {{read}} # to be URL-encoded as the query string
8 changes: 8 additions & 0 deletions doc/_includes/http/clone-api/async-write.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POST {{origin}}/api/v1/domain/{{account}}/{{subdomain}}/state
Authorization: Basic {{digest}}
Content-Type: application/json

{
"@id": "Client-0005",
"company_name": "The Flintstones"
}
29 changes: 29 additions & 0 deletions doc/_includes/http/http-client.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"local": {
"origin": "http://localhost:3000",
"account": "my-account",
"remotesAuth": "anon",
"subdomain": "my-subdomain",
"read": "{\"@describe\":\"?id\",\"@where\":{\"@id\":\"?id\"}}"
},
"doc": {
"origin": "{{ '{{ origin }}' }}",
"rootAccount": "{{ '{{ root }}' }}",
"rootKey": "≪root key≫",
"account": "≪account name≫",
"accountKey": "≪account key≫",
"email": "≪user email≫",
"jwe": "≪jwe≫",
"activation": "≪emailed activation code≫",
"remotesAuth": "≪remotes auth option≫",
"subdomain": "≪subdomain≫",
"read": "{\"@describe\":\"?id\",\"@where\":{\"@id\":\"?id\"}}",
"digest": "≪base64(≪account name≫:≪account key≫)≫"
},
"prod": {
"origin": "https://gw.m-ld.org",
"account": "public",
"remotesAuth": "anon",
"read": "{\"@describe\":\"?id\",\"@where\":{\"@id\":\"?id\"}}"
}
}
3 changes: 3 additions & 0 deletions doc/_includes/http/named-subdomains/create.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PUT {{origin}}/api/v1/domain/{{account}}/{{subdomain}}
Accept: application/json
Authorization: Basic {{digest}}
2 changes: 2 additions & 0 deletions doc/_includes/http/uuid-subdomains/generate.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
POST {{origin}}/api/v1/domain/{{account}}
Accept: application/json
5 changes: 5 additions & 0 deletions doc/_includes/http/uuid-subdomains/setup.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PATCH {{origin}}/api/v1/user/{{account}}
Authorization: Basic {{digest}}
Content-Type: application/json

{ "@insert": { "naming": "uuid" } }
31 changes: 0 additions & 31 deletions doc/accounts.http

This file was deleted.

28 changes: 8 additions & 20 deletions doc/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ Account names (`≪account≫` in the below) must be composed only of **lowercas

First, request an activation code with an email address.

```bash
curl -X POST --location "{{ '{{ origin }}' }}/api/v1/user/≪account≫/activation" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{ \"email\": \"≪email≫\" }"
```
{% include 'http/accounts/activation.http' %}
```

The body of the response will have the form `{ "jwe": "≪base64Binary≫" }`. The value of the `jwe` key will be used in the next step.
Expand All @@ -29,11 +26,8 @@ An email will be sent to the given address, containing a six-digit activation co

The account can then be created with another HTTP request:

```bash
curl -X POST --location "{{ '{{ origin }}' }}/api/v1/user/≪account≫/key" \
-H "Authorization: Bearer ≪jwe≫" \
-H "X-Activation-Code: ≪emailed activation code≫" \
-H "Accept: application/json"
```
{% include 'http/accounts/key-using-activation.http' %}
```

The body of the response will be of the form `{ "auth": { "key": "≪my-key≫" } }`, where `≪my-key≫` is the new account's authorisation key.
Expand All @@ -42,10 +36,8 @@ The body of the response will be of the form `{ "auth": { "key": "≪my-key≫"

The Gateway root account can be used to create any user account directly.

```bash
curl -X POST --location "{{ '{{ origin }}' }}/api/v1/user/≪account name≫/key" \
-H "Accept: application/json" \
--basic --user ≪root≫:≪root key≫
```
{% include 'http/accounts/key-using-root.http' %}
```

The body of the response will be of the form `{ "auth": { "key": "≪my-key≫" } }`, where `≪my-key≫` is the new account's authorisation key.
Expand All @@ -59,12 +51,8 @@ When [connecting to subdomains](clone-subdomain), clients may need to provide au

The required option can be set as follows.

```bash
curl -X PATCH --location "{{ '{{ origin }}' }}/api/v1/user/≪account name≫" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{ \"@insert\": { \"remotesAuth\": \"≪remotes auth option≫\" } }" \
--basic --user ≪account name≫:≪account key≫
```
{% include 'http/accounts/insert-remotes-auth.http' %}
```

You can also remove a previously-set option by including a delete clause, for example: `{ "@delete": { "remotesAuth": "jwt" } }`.
18 changes: 0 additions & 18 deletions doc/clone-api.http

This file was deleted.

26 changes: 5 additions & 21 deletions doc/clone-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,14 @@ The 'clone' (noun, not verb) API is provided for such a client to access the dat

Some data can be added to the domain with:

```bash
curl -X POST --location "{{ '{{ origin }}' }}/api/v1/domain/≪account name≫/≪subdomain≫/state" \
-H "Content-Type: application/json" \
-d "{
\"@id\": \"Client-0005\",
\"company_name\": \"The Flintstones\"
}" \
--basic --user ≪account name≫:≪account key≫
```
{% include 'http/clone-api/async-write.http' %}
```

Data in the domain can be queried with:

```bash
curl -X GET --location "{{ '{{ origin }}' }}/api/v1/domain/≪account name≫/≪subdomain≫/state?q=%7B%22%40describe%22%3A%22%3Fid%22%2C%22%40where%22%3A%7B%22%40id%22%3A%22%3Fid%22%7D%7D" \
-H "Accept: application/json" \
--basic --user ≪account name≫:≪account key≫
```

Note that the query string includes the URL-encoded json-rql query, for example the describe-all query:
```json
{
"@describe": "?id",
"@where": {
"@id": "?id"
}
}
{% include 'http/clone-api/async-read.http' %}
```

This example query describes all the subjects in the domain, which is to say, their top-level properties.
25 changes: 0 additions & 25 deletions doc/http-client.env.json

This file was deleted.

7 changes: 0 additions & 7 deletions doc/named-subdomains.http

This file was deleted.

6 changes: 2 additions & 4 deletions doc/named-subdomains.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ To use named subdomains, you first need [an account](accounts). (If your Gateway

A new domain can be created with:

```bash
curl -X PUT --location "{{ '{{ origin }}' }}/api/v1/domain/≪account name≫/≪subdomain≫" \
-H "Accept: application/json" \
--basic --user ≪account name≫:≪account key≫
```
{% include 'http/named-subdomains/create.http' %}
```

This creates the domain `≪subdomain≫` in the account. Domain names must be composed only of **lowercase** letters, numbers, hyphens `-` and underscores `_`.
Expand Down
4 changes: 2 additions & 2 deletions doc/self-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: self-hosting setup
# Hosting a Gateway

## build
```bash
```
npm run build
```

Expand All @@ -32,7 +32,7 @@ The data path can be omitted, in which case a local path will be used in an OS-s

For convenience these variables can be specified in a `.env` file in the working directory.

```bash
```
npm run start -- --genesis true
```

Expand Down
14 changes: 0 additions & 14 deletions doc/uuid-subdomains.http

This file was deleted.

12 changes: 4 additions & 8 deletions doc/uuid-subdomains.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ To use UUID subdomains, you first need [an account](accounts).

By default, a Gateway account only allows [named subdomains](named-subdomains). To enable UUID subdomains for an account:

```bash
curl -X PATCH --location "{{ '{{ origin }}' }}/api/v1/user/≪account name≫" \
-H "Content-Type: application/json" \
-d "{ \"@insert\": { \"naming\": \"uuid\" } }" \
--basic --user ≪account name≫:≪account key≫
```
{% include 'http/uuid-subdomains/setup.http' %}
```

## creating a UUID domain
Expand All @@ -30,9 +27,8 @@ The domain name must take the form `≪uuid≫.my-account.my-gateway`, where `

For convenience, you can request suitable configuration for a new UUID subdomain from the Gateway, as follows. Note that this does not create anything new on the Gateway, but it will generate a compliant UUID for the domain name.

```bash
curl -X POST --location "{{ '{{ origin }}' }}/api/v1/domain/≪account name≫" \
-H "Accept: application/json"
```
{% include 'http/uuid-subdomains/generate.http' %}
```

With the resultant configuration (or one you have created from scratch) you can [clone the subdomain](clone-subdomain).
3 changes: 3 additions & 0 deletions eleventy.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const { default11tyConfig, packageDir } = require('@m-ld/io-web-build');
const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight');
const { join } = require('path');

/**
* @param {import('@11ty/eleventy').UserConfig} eleventy
*/
module.exports = function (eleventy) {
eleventy.ignores.add('doc/README.md');
eleventy.addPlugin(syntaxHighlight);
Expand Down
Loading

0 comments on commit 4de9a7a

Please sign in to comment.