@toa.io/userland 1.0.0-alpha.326 → 1.0.0-alpha.328

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,23 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-alpha.328](https://github.com/toa-io/toa/compare/v1.0.0-alpha.327...v1.0.0-alpha.328) (2026-10-10)
7
+
8
+ **Note:** Version bump only for package @toa.io/userland
9
+
10
+
11
+
12
+
13
+
14
+ # [1.0.0-alpha.327](https://github.com/toa-io/toa/compare/v1.0.0-alpha.326...v1.0.0-alpha.327) (2026-10-10)
15
+
16
+ ### Features
17
+
18
+ * **cli:** create an application in the working directory ([6d44704](https://github.com/toa-io/toa/commit/6d44704ce27e12e796448d9db9b55390ef0a6196))
19
+ * **userland:** install what the declarations require with the packages ([52a99da](https://github.com/toa-io/toa/commit/52a99da800e37117250377ae87245634cfba4a85))
20
+ * **userland:** run what is created as two processes under PM2 ([fe37a05](https://github.com/toa-io/toa/commit/fe37a0583cdccb0f4fdcaf5ae9f73bb1cc10e843))
21
+
22
+
6
23
  # [1.0.0-alpha.326](https://github.com/toa-io/toa/compare/v1.0.0-alpha.325...v1.0.0-alpha.326) (2026-10-06)
7
24
 
8
25
  **Note:** Version bump only for package @toa.io/userland
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/userland",
3
- "version": "1.0.0-alpha.326",
3
+ "version": "1.0.0-alpha.328",
4
4
  "type": "module",
5
5
  "description": "Toa development kit",
6
6
  "homepage": "https://toa.io",
@@ -32,12 +32,13 @@
32
32
  "./package.json": "./package.json"
33
33
  },
34
34
  "dependencies": {
35
- "@toa.io/boot": "1.0.0-alpha.326",
36
- "@toa.io/core": "1.0.0-alpha.326",
35
+ "@toa.io/agent": "1.0.0-alpha.320",
36
+ "@toa.io/boot": "1.0.0-alpha.328",
37
+ "@toa.io/core": "1.0.0-alpha.328",
37
38
  "@toa.io/generic": "1.0.0-alpha.311",
38
- "@toa.io/norm": "1.0.0-alpha.326",
39
+ "@toa.io/norm": "1.0.0-alpha.328",
39
40
  "@toa.io/schemas": "1.0.0-alpha.326",
40
- "@toa.io/storages.null": "1.0.0-alpha.326"
41
+ "@toa.io/storages.null": "1.0.0-alpha.328"
41
42
  },
42
- "gitHead": "60f11bdc805d0c39bcb06064b2218b11114a35ad"
43
+ "gitHead": "c4fcb94548759b069014187ef4fa238179d2eca3"
43
44
  }
package/readme.md CHANGED
@@ -1,7 +1,64 @@
1
1
  # Toa development kit
2
2
 
3
3
  - [Stage](./stage): integration tests framework (Node.js)
4
+ - [Template](#template): the application `toa create` writes
4
5
 
5
6
  See [example](./example).
6
7
 
7
- [^1]: not yet implemented
8
+ ## Template
9
+
10
+ [`toa create <name>`](/runtime/cli/readme.md#create) writes an application into an empty
11
+ directory. Running it takes [Docker](https://docs.docker.com/get-docker/), for the services it
12
+ connects to, and [PM2](https://pm2.keymetrics.io), which keeps its processes:
13
+
14
+ ```shell
15
+ $ npm install -g pm2
16
+ ```
17
+
18
+ ```text
19
+ package.json
20
+ tsconfig.json
21
+ docker-compose.yaml
22
+ ecosystem.config.js
23
+ context.toa.yaml
24
+ cucumber.js
25
+ components/
26
+ hello/
27
+ manifest.toa.yaml
28
+ operations/greet.ts
29
+ notes/
30
+ manifest.toa.yaml
31
+ features/
32
+ hello.feature
33
+ notes.feature
34
+ steps/
35
+ application.ts
36
+ http.ts
37
+ ```
38
+
39
+ | File | Is |
40
+ | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
41
+ | `context.toa.yaml` | The Context: the application's name and where its infrastructure is. It is the least a Context holds. |
42
+ | `docker-compose.yaml` | RabbitMQ, MongoDB as a replica set of one, and Redis, on their conventional ports, with the credentials `toa env --dev` writes. |
43
+ | `ecosystem.config.js` | The two processes PM2 keeps: `sys`, what Toa serves beside an application — its gateway, configuration and introspection — and `app`, the components. |
44
+ | `components/hello` | A component with code and no state: `greet`, a computation, served at `GET /hello/`. |
45
+ | `components/notes` | A component with state and no code: an entity, `create` forwarded to the operation every component inherits, served at `/notes/`. |
46
+ | `features` | A scenario for each component, sent over HTTP. The steps start the components with the [stage](./stage), in the process of the test; `sys` is running already. |
47
+ | `package.json` | The packages of Toa at the version that created the application, and the scripts below. |
48
+ | `tsconfig.json` | What `tsc` checks the components and the steps with. |
49
+
50
+ | Script | Runs |
51
+ | ------------------- | --------------------------------------------------------------------------------------------------------- |
52
+ | `npm install` | Installs the packages, then `toa npm`, which adds what the declarations require beyond them. |
53
+ | `npm run dock` | The services, and waits until they are ready. |
54
+ | `npm run env` | `toa types`, `toa env --dev` and `toa map`. Run it again when a manifest or a component's source changes. |
55
+ | `npm run sys` | `sys` alone: what the scenarios need, since they start the components themselves. |
56
+ | `npm run features` | The scenarios. |
57
+ | `npm start` | `sys` and `app`: the application, with its gateway on `http://localhost:8000`. |
58
+ | `npm run restart` | `npm run env`, and both processes again. |
59
+ | `npm stop` | Stops and forgets both. |
60
+ | `npm run typecheck` | `tsc`. |
61
+
62
+ `pm2 logs` shows what the processes write, and `pm2 ls` whether they run.
63
+
64
+ The routes are open to anyone, which is right for a first run and for nothing else.
@@ -34,9 +34,7 @@ const create = async (references, workload) => {
34
34
  */
35
35
  export const workload = async (paths, options, services = []) => {
36
36
  const workload = new boot.Workload(async (workload) => {
37
- const composition = workload.gate(
38
- async () => await boot.composition(paths, options)
39
- )
37
+ const composition = workload.gate(async () => await boot.composition(paths, options))
40
38
 
41
39
  if (services.length === 0) return composition
42
40
 
@@ -0,0 +1,3 @@
1
+ node_modules/
2
+ .env*
3
+ .map.json
@@ -0,0 +1,22 @@
1
+ name: hello
2
+
3
+ operations:
4
+ greet:
5
+ input:
6
+ type: object
7
+ properties:
8
+ name: { type: string, maxLength: 64 }
9
+ output:
10
+ type: object
11
+ properties:
12
+ greeting: { type: string }
13
+ required: [greeting]
14
+
15
+ exposition:
16
+ /:
17
+ anonymous: true
18
+ io:output: true
19
+ GET:
20
+ endpoint: greet
21
+ query:
22
+ parameters: [name]
@@ -0,0 +1,5 @@
1
+ import type { GreetInput } from '../types/index.d.ts'
2
+
3
+ export async function computation(input: GreetInput) {
4
+ return { greeting: `Hello, ${input.name ?? 'world'}!` }
5
+ }
@@ -0,0 +1,25 @@
1
+ name: notes
2
+
3
+ entity:
4
+ properties:
5
+ text: { type: string, maxLength: 1024 }
6
+ required: [text]
7
+
8
+ operations:
9
+ create:
10
+ forward: transit
11
+ query: false
12
+ input:
13
+ type: object
14
+ properties:
15
+ text: { type: string, maxLength: 1024 }
16
+ required: [text]
17
+
18
+ exposition:
19
+ /:
20
+ anonymous: true
21
+ io:output: [id, text]
22
+ GET: enumerate
23
+ POST: create
24
+ /:id:
25
+ GET: observe
@@ -0,0 +1,29 @@
1
+ name: {{name}}
2
+ registry: registry.example.com/{{name}}
3
+
4
+ amqp: amqp://localhost
5
+ mongodb: mongodb://localhost
6
+ stash: redis://localhost
7
+
8
+ atomicity:
9
+ redis: redis://localhost
10
+
11
+ storages:
12
+ tmp:
13
+ provider: tmp
14
+ directory: {{name}}
15
+
16
+ exposition:
17
+ authorities:
18
+ local: localhost:8000
19
+
20
+ configuration:
21
+ identity.tokens:
22
+ keys:
23
+ - id: key0
24
+ key: $IDENTITY_TOKENS_ENCRYPTION_KEY0
25
+
26
+ ingress:
27
+ hosts: [localhost]
28
+
29
+ resources: ~
@@ -0,0 +1,4 @@
1
+ export default {
2
+ import: ['features/steps/*.ts'],
3
+ failFast: true
4
+ }
@@ -0,0 +1,62 @@
1
+ # What a local run connects to. `developer` and `secret` are what `toa env --dev` writes.
2
+ name: {{name}}
3
+ volumes:
4
+ mongo-data:
5
+ mongo-key:
6
+ services:
7
+ rabbitmq:
8
+ image: rabbitmq:4.2.4-management
9
+ ports:
10
+ - "5672:5672"
11
+ - "15672:15672"
12
+ environment:
13
+ RABBITMQ_DEFAULT_USER: developer
14
+ RABBITMQ_DEFAULT_PASS: secret
15
+ healthcheck:
16
+ test: rabbitmq-diagnostics -q ping
17
+ interval: 5s
18
+ timeout: 5s
19
+ retries: 30
20
+
21
+ # a replica set of one member: transactions and change streams need one
22
+ mongodb:
23
+ image: mongo:8.0.16
24
+ ports:
25
+ - "27017:27017"
26
+ environment:
27
+ MONGO_INITDB_ROOT_USERNAME: developer
28
+ MONGO_INITDB_ROOT_PASSWORD: secret
29
+ volumes:
30
+ - mongo-data:/data/db
31
+ - mongo-key:/etc/mongo-keyfile
32
+ entrypoint: >
33
+ bash -c '
34
+ set -e
35
+
36
+ if [ ! -f /etc/mongo-keyfile/keyfile ]; then
37
+ umask 077
38
+ openssl rand -base64 756 > /etc/mongo-keyfile/keyfile
39
+ chown mongodb:mongodb /etc/mongo-keyfile/keyfile
40
+ fi
41
+
42
+ exec docker-entrypoint.sh mongod --replSet rs0 --bind_ip_all --keyFile /etc/mongo-keyfile/keyfile
43
+ '
44
+ healthcheck:
45
+ test: >
46
+ mongosh "mongodb://developer:secret@localhost:27017/admin?directConnection=true" --quiet --eval '
47
+ try { rs.status() } catch (e) { rs.initiate({ _id: "rs0", members: [{ _id: 0, host: "localhost:27017" }] }) }
48
+ if (!db.hello().isWritablePrimary) quit(1)
49
+ '
50
+ interval: 5s
51
+ timeout: 5s
52
+ retries: 30
53
+
54
+ redis:
55
+ image: redis:8.6.1
56
+ ports:
57
+ - "6379:6379"
58
+ healthcheck:
59
+ test: redis-cli ping
60
+ interval: 5s
61
+ timeout: 5s
62
+ retries: 30
@@ -0,0 +1,29 @@
1
+ import { readdirSync } from 'node:fs'
2
+ import { join } from 'node:path'
3
+
4
+ // the binary of this project's Toa, by its path: pm2 resolves a script through the PATH of the
5
+ // shell that starts it, which has `node_modules/.bin` only under `npm run`
6
+ const toa = join(import.meta.dirname, 'node_modules/.bin/toa')
7
+
8
+ const components = readdirSync(join(import.meta.dirname, 'components'), {
9
+ withFileTypes: true
10
+ })
11
+ .filter((entry) => entry.isDirectory())
12
+ .map((entry) => join('components', entry.name))
13
+
14
+ const common = {
15
+ script: toa,
16
+ cwd: import.meta.dirname,
17
+ autorestart: false,
18
+ watch: false,
19
+ merge_logs: true,
20
+ wait_ready: true,
21
+ listen_timeout: 60_000
22
+ }
23
+
24
+ export const apps = [
25
+ // what Toa serves beside an application: its gateway, configuration and introspection
26
+ { ...common, name: 'sys', args: 'serve configuration exposition introspection' },
27
+ // the application's components
28
+ { ...common, name: 'app', args: `compose ${components.join(' ')}` }
29
+ ]
@@ -0,0 +1,14 @@
1
+ Feature: Hello
2
+
3
+ Scenario: Greeting by name
4
+ When the request is sent:
5
+ """
6
+ GET /hello/?name=Toa HTTP/1.1
7
+ accept: application/yaml
8
+ """
9
+ Then the response is received:
10
+ """
11
+ 200 OK
12
+
13
+ greeting: Hello, Toa!
14
+ """
@@ -0,0 +1,29 @@
1
+ Feature: Notes
2
+
3
+ Scenario: Keeping a note
4
+ When the request is sent:
5
+ """
6
+ POST /notes/ HTTP/1.1
7
+ content-type: application/yaml
8
+ accept: application/yaml
9
+
10
+ text: Buy milk
11
+ """
12
+ Then the response is received:
13
+ """
14
+ 201 Created
15
+
16
+ id: ${{ id }}
17
+ text: Buy milk
18
+ """
19
+ When the request is sent:
20
+ """
21
+ GET /notes/${{ id }}/ HTTP/1.1
22
+ accept: application/yaml
23
+ """
24
+ Then the response is received:
25
+ """
26
+ 200 OK
27
+
28
+ text: Buy milk
29
+ """
@@ -0,0 +1,22 @@
1
+ import { readdir, readFile } from 'node:fs/promises'
2
+ import { resolve } from 'node:path'
3
+ import { BeforeAll, AfterAll } from '@cucumber/cucumber'
4
+ import * as stage from '@toa.io/userland/stage'
5
+
6
+ const root = resolve(import.meta.dirname, '../..')
7
+ const components = resolve(root, 'components')
8
+
9
+ BeforeAll({ timeout: 60_000 }, async function () {
10
+ const map = await readFile(resolve(root, '.map.json'), 'utf8')
11
+ const entries = await readdir(components)
12
+ const paths = entries.map((entry) => resolve(components, entry))
13
+
14
+ stage.map(JSON.parse(map))
15
+
16
+ // the components run in this process; what serves them is started with `npm run sys`
17
+ await stage.compose(paths)
18
+ })
19
+
20
+ AfterAll(async function () {
21
+ await stage.shutdown()
22
+ })
@@ -0,0 +1,19 @@
1
+ import { Before, When, Then } from '@cucumber/cucumber'
2
+ import { Agent } from '@toa.io/agent'
3
+
4
+ // what the steps of one scenario share
5
+ export interface World {
6
+ agent: Agent
7
+ }
8
+
9
+ Before(function (this: World) {
10
+ this.agent = new Agent('http://localhost:8000')
11
+ })
12
+
13
+ When('the request is sent:', async function (this: World, text: string) {
14
+ await this.agent.request(text)
15
+ })
16
+
17
+ Then('the response is received:', function (this: World, text: string) {
18
+ this.agent.responseIncludes(text)
19
+ })
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "{{name}}",
3
+ "private": true,
4
+ "type": "module",
5
+ "scripts": {
6
+ "postinstall": "toa npm",
7
+ "dock": "docker compose up -d --wait",
8
+ "env": "toa types --quiet && toa env --dev && toa map",
9
+ "start": "pm2 start ecosystem.config.js",
10
+ "restart": "npm run env && pm2 restart ecosystem.config.js",
11
+ "stop": "pm2 delete ecosystem.config.js",
12
+ "sys": "pm2 start ecosystem.config.js --only sys",
13
+ "features": "cucumber-js",
14
+ "typecheck": "tsc"
15
+ },
16
+ "workspaces": [
17
+ "components/*"
18
+ ],
19
+ "devDependencies": {
20
+ "@cucumber/cucumber": "13.2.1",
21
+ "@toa.io/agent": "{{agent}}",
22
+ "@toa.io/operations": "{{version}}",
23
+ "@toa.io/runtime": "{{version}}",
24
+ "@toa.io/userland": "{{version}}",
25
+ "@types/node": "26.6.4",
26
+ "typescript": "7.0.2"
27
+ }
28
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "nodenext",
4
+ "moduleResolution": "nodenext",
5
+ "target": "esnext",
6
+ "types": ["node"],
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "skipLibCheck": true,
10
+ "allowImportingTsExtensions": true,
11
+ "verbatimModuleSyntax": true,
12
+ "erasableSyntaxOnly": true
13
+ },
14
+ "include": ["components", "features"]
15
+ }