@webda/create 0.0.0-stage → 4.0.0-beta.4
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/LICENSE +166 -0
- package/README.md +27 -2
- package/agent/.claude-plugin/plugin.json +7 -0
- package/agent/AGENTS.md +47 -0
- package/agent/CLAUDE.md +3 -0
- package/agent/skills/webda-configuration/SKILL.md +61 -0
- package/agent/skills/webda-deploy/SKILL.md +103 -0
- package/agent/skills/webda-models/SKILL.md +137 -0
- package/agent/skills/webda-operations/SKILL.md +82 -0
- package/agent/skills/webda-services/SKILL.md +90 -0
- package/agent/skills/webda-stores/SKILL.md +66 -0
- package/agent/skills/webda-testing/SKILL.md +80 -0
- package/lib/agents.d.ts +21 -0
- package/lib/agents.d.ts.map +1 -0
- package/lib/agents.js +33 -0
- package/lib/agents.js.map +1 -0
- package/lib/bin.d.ts +3 -0
- package/lib/bin.d.ts.map +1 -0
- package/lib/bin.js +4 -0
- package/lib/bin.js.map +1 -0
- package/lib/compose.d.ts +32 -0
- package/lib/compose.d.ts.map +1 -0
- package/lib/compose.js +51 -0
- package/lib/compose.js.map +1 -0
- package/lib/generate.d.ts +39 -0
- package/lib/generate.d.ts.map +1 -0
- package/lib/generate.js +85 -0
- package/lib/generate.js.map +1 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +97 -0
- package/lib/index.js.map +1 -0
- package/lib/install.d.ts +25 -0
- package/lib/install.d.ts.map +1 -0
- package/lib/install.js +34 -0
- package/lib/install.js.map +1 -0
- package/lib/merge.d.ts +8 -0
- package/lib/merge.d.ts.map +1 -0
- package/lib/merge.js +25 -0
- package/lib/merge.js.map +1 -0
- package/lib/options.d.ts +64 -0
- package/lib/options.d.ts.map +1 -0
- package/lib/options.js +125 -0
- package/lib/options.js.map +1 -0
- package/lib/prompts.d.ts +27 -0
- package/lib/prompts.d.ts.map +1 -0
- package/lib/prompts.js +73 -0
- package/lib/prompts.js.map +1 -0
- package/lib/template.d.ts +25 -0
- package/lib/template.d.ts.map +1 -0
- package/lib/template.js +46 -0
- package/lib/template.js.map +1 -0
- package/lib/versions.d.ts +22 -0
- package/lib/versions.d.ts.map +1 -0
- package/lib/versions.js +52 -0
- package/lib/versions.js.map +1 -0
- package/lib/versions.json +42 -0
- package/package.json +40 -3
- package/templates/base/files/README.md +16 -0
- package/templates/base/files/_gitignore +6 -0
- package/templates/base/files/src/models/Project.model.ts +19 -0
- package/templates/base/files/src/models/Task.model.ts +24 -0
- package/templates/base/files/src/services/task.service.ts +29 -0
- package/templates/base/files/test/app.spec.ts +57 -0
- package/templates/base/files/tsconfig.json +18 -0
- package/templates/base/files/vitest.config.ts +10 -0
- package/templates/base/package.json +35 -0
- package/templates/base/webda.config.json +19 -0
- package/templates/features/graphql/agents.md +1 -0
- package/templates/features/graphql/package.json +5 -0
- package/templates/features/graphql/webda.config.json +1 -0
- package/templates/features/grpc/agents.md +1 -0
- package/templates/features/grpc/package.json +5 -0
- package/templates/features/grpc/webda.config.json +6 -0
- package/templates/features/mcp/agents.md +1 -0
- package/templates/features/mcp/package.json +5 -0
- package/templates/features/mcp/webda.config.json +1 -0
- package/templates/features/store-file/agents.md +1 -0
- package/templates/features/store-file/package.json +5 -0
- package/templates/features/store-file/webda.config.json +1 -0
- package/templates/features/store-mongodb/agents.md +1 -0
- package/templates/features/store-mongodb/files/.env.example +1 -0
- package/templates/features/store-mongodb/files/docker-compose.yml +8 -0
- package/templates/features/store-mongodb/package.json +5 -0
- package/templates/features/store-mongodb/webda.config.json +1 -0
- package/templates/features/store-postgres/agents.md +1 -0
- package/templates/features/store-postgres/files/.env.example +5 -0
- package/templates/features/store-postgres/files/docker-compose.yml +9 -0
- package/templates/features/store-postgres/package.json +5 -0
- package/templates/features/store-postgres/webda.config.json +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
|
166
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @webda/create
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Create a [Webda](https://webda.io) v4 application, ready for coding agents.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm create @webda my-app
|
|
7
|
+
pnpm create @webda my-app --store postgres --transports rest,graphql --yes
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
| Flag | Values | Default |
|
|
11
|
+
| -------------------------- | ---------------------------------------------- | --------------------------------------- |
|
|
12
|
+
| `--store` | `memory`, `file`, `mongodb`, `postgres` | `memory` |
|
|
13
|
+
| `--transports` | comma list of `rest`, `graphql`, `grpc`, `mcp` | `rest` |
|
|
14
|
+
| `--namespace` | application namespace | from the directory name |
|
|
15
|
+
| `--pm` | `pnpm`, `npm`, `yarn` | the package manager running the command |
|
|
16
|
+
| `--no-install`, `--no-git` | skip install / git init | |
|
|
17
|
+
| `--yes`, `-y` | accept defaults, never prompt | |
|
|
18
|
+
|
|
19
|
+
With `npm`, the generated app also gets a `.npmrc` setting `legacy-peer-deps=true`: npm 10 (bundled with Node 22) crashes
|
|
20
|
+
on the optional peer dependencies of vitest/vite. It is safe to remove with npm >= 11.
|
|
21
|
+
|
|
22
|
+
The generated app contains `AGENTS.md`, `CLAUDE.md` and skills in `.agents/skills/`.
|
|
23
|
+
In an existing v4 project, Claude Code users can install the same skills:
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
/plugin marketplace add loopingz/webda.io
|
|
27
|
+
/plugin install webda@webda
|
|
28
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "webda",
|
|
3
|
+
"description": "Skills for building Webda v4 applications: models, services, operations, configuration, stores and tests",
|
|
4
|
+
"homepage": "https://webda.io",
|
|
5
|
+
"repository": "https://github.com/loopingz/webda.io",
|
|
6
|
+
"license": "LGPL-3.0-only"
|
|
7
|
+
}
|
package/agent/AGENTS.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# __APP_NAME__
|
|
2
|
+
|
|
3
|
+
A [Webda](https://webda.io) v4 application. Webda is a model-driven Node.js framework: you write models and services, and it exposes them through the configured transports (REST, GraphQL, gRPC, MCP) with validation and permissions.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run build # compile src/ to lib/ and generate webda.module.json and .webda/
|
|
9
|
+
npm run debug # build, then start the dev server with the interactive debug console on http://localhost:18080
|
|
10
|
+
npm run serve # build, then start the HTTP server on http://localhost:18080 (no terminal UI)
|
|
11
|
+
npm test # build, then run the tests
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Layout
|
|
15
|
+
|
|
16
|
+
- `src/models/*.model.ts`: domain models
|
|
17
|
+
- `src/services/*.service.ts`: services
|
|
18
|
+
- `test/`: tests
|
|
19
|
+
- `webda.config.json`: services and parameters
|
|
20
|
+
- `deployments/*.json`: per-environment overrides and deployers (when present)
|
|
21
|
+
|
|
22
|
+
## Rules
|
|
23
|
+
|
|
24
|
+
- Design the models first; put behaviour that is not about one model in a service.
|
|
25
|
+
- Persist through the model: `Task.create({...})`, `Task.ref(uuid).get()`, `Task.query("done = false")`, or `useRepository(Task)`. Never inject or call a store.
|
|
26
|
+
- Configuration belongs in `webda.config.json` and `deployments/`, not in code.
|
|
27
|
+
- Never edit generated files: `.webda/`, `webda.module.json`, `lib/`.
|
|
28
|
+
- After a change, run `npm run build` then `npm test`.
|
|
29
|
+
- Agents and non-interactive shells: use `npm run serve`; `npm run debug` opens a fullscreen terminal UI.
|
|
30
|
+
|
|
31
|
+
## This app
|
|
32
|
+
|
|
33
|
+
<!-- WEBDA:APP -->
|
|
34
|
+
|
|
35
|
+
## Skills
|
|
36
|
+
|
|
37
|
+
Read the matching skill before working on a task:
|
|
38
|
+
|
|
39
|
+
| Task | Skill |
|
|
40
|
+
| -------------------------------------------------------------- | --------------------------------------------- |
|
|
41
|
+
| Add or change a model, its validation or relations | `.agents/skills/webda-models/SKILL.md` |
|
|
42
|
+
| Add or change a service | `.agents/skills/webda-services/SKILL.md` |
|
|
43
|
+
| Expose behaviour as an operation; REST, GraphQL, gRPC, MCP | `.agents/skills/webda-operations/SKILL.md` |
|
|
44
|
+
| Configuration, parameters, deployment overrides | `.agents/skills/webda-configuration/SKILL.md` |
|
|
45
|
+
| Choose or switch the store; read and write data | `.agents/skills/webda-stores/SKILL.md` |
|
|
46
|
+
| Write or fix tests | `.agents/skills/webda-testing/SKILL.md` |
|
|
47
|
+
| Deploy, add an environment, build an image or a Lambda package | `.agents/skills/webda-deploy/SKILL.md` |
|
package/agent/CLAUDE.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: webda-configuration
|
|
3
|
+
description: Use when changing webda.config.json, application parameters, the parameters of a service or the per-environment deployments of a Webda app
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Webda configuration
|
|
7
|
+
|
|
8
|
+
## When to use
|
|
9
|
+
|
|
10
|
+
Enabling or configuring a service, setting application parameters or overriding them per environment.
|
|
11
|
+
|
|
12
|
+
## Pattern
|
|
13
|
+
|
|
14
|
+
`webda.config.json` declares the services and their parameters. `npm run build` generates `.webda/config.schema.json`, referenced by `$schema`, so editors validate the file.
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"$schema": ".webda/config.schema.json",
|
|
19
|
+
"version": 4,
|
|
20
|
+
"parameters": {
|
|
21
|
+
"supportEmail": "support@example.com"
|
|
22
|
+
},
|
|
23
|
+
"services": {
|
|
24
|
+
"HttpServer": { "type": "Webda/HttpServer" },
|
|
25
|
+
"ReminderService": { "type": "ReminderService", "delayHours": 12 }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- `type` is `Namespace/Name`; types of your app can omit the namespace.
|
|
31
|
+
- `parameters` are shared by every service; a few keys are framework settings (`website`, `static`, `apiUrl`, `metrics`), any other key is yours.
|
|
32
|
+
- Values are not interpolated: `${VAR}` stays a literal string. Secrets come from the environment variables each service reads (for example `WEBDA_MONGO_URL`, `PGHOST`), never from the file.
|
|
33
|
+
- `deployments/<name>.json` overrides `parameters` and `services` for one environment. Select it with `-d <name>` before the command name (`npx webda -d production serve`; after the command it is ignored), `--deployment <name>` (`npm run serve -- --deployment production`) or `WEBDA_DEPLOYMENT=production npm run serve`. Objects are deep merged over `webda.config.json` and arrays are replaced. Its `units` (deployers) are covered by webda-deploy.
|
|
34
|
+
|
|
35
|
+
Read the configuration in code through the service parameters (`this.parameters.delayHours`) or the application parameters:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { useParameters } from "@webda/core";
|
|
39
|
+
|
|
40
|
+
export function supportEmail(): string {
|
|
41
|
+
return useParameters().supportEmail;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Common mistakes
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
"mongoUrl": "${MONGO_URL}" → not interpolated; use the service's environment variable
|
|
49
|
+
Secrets committed in webda.config.json → environment variables, documented in .env.example
|
|
50
|
+
Editing .webda/config.schema.json → generated by npm run build
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Verify
|
|
54
|
+
|
|
55
|
+
`npm run build` (schema), then `npm run debug`: an unknown service type or a service that fails to create or init is logged as ERROR with the service name, and startup continues: read the logs.
|
|
56
|
+
|
|
57
|
+
## Reference
|
|
58
|
+
|
|
59
|
+
https://docs.webda.io
|
|
60
|
+
|
|
61
|
+
Written for Webda 4.0.0-beta.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: webda-deploy
|
|
3
|
+
description: Use when deploying a Webda app, adding a deployment environment or building a container image or Lambda package
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Webda deploy
|
|
7
|
+
|
|
8
|
+
## When to use
|
|
9
|
+
|
|
10
|
+
Adding an environment (`deployments/<name>.json`), building and pushing an OCI image, packaging the app for AWS Lambda or deploying it with CloudFormation.
|
|
11
|
+
|
|
12
|
+
## Pattern
|
|
13
|
+
|
|
14
|
+
Install the deployer package, then build: a generated app does not depend on any deployer, and the deployer types and commands are only discovered from the installed packages.
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @webda/oci # Webda/ContainerDeployer
|
|
18
|
+
npm install @webda/aws # Webda/LambdaPackager, Webda/CloudFormationDeployer
|
|
19
|
+
npm run build # also before every deployer command: lib/ and webda.module.json get packaged
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
A deployment is a file `deployments/<name>.json` (`.jsonc`, `.yaml` and `.yml` work too). It has four sections:
|
|
23
|
+
|
|
24
|
+
- `parameters` and `services` override `webda.config.json` (objects deep merged, arrays replaced; see webda-configuration).
|
|
25
|
+
- `units` lists the deployers: each unit has a `name`, a `type` and the deployer parameters.
|
|
26
|
+
- `resources` holds parameters shared by every unit; a unit overrides them.
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"$schema": "../.webda/deployment.schema.json",
|
|
31
|
+
"parameters": {
|
|
32
|
+
"supportEmail": "support@example.com"
|
|
33
|
+
},
|
|
34
|
+
"services": {
|
|
35
|
+
"ReminderService": { "delayHours": 48 }
|
|
36
|
+
},
|
|
37
|
+
"units": [
|
|
38
|
+
{
|
|
39
|
+
"name": "image",
|
|
40
|
+
"type": "Webda/ContainerDeployer",
|
|
41
|
+
"image": "ghcr.io/my-org/my-app",
|
|
42
|
+
"tags": ["${package.version}", "latest"],
|
|
43
|
+
"credentials": {
|
|
44
|
+
"ghcr.io": { "username": "${env.GHCR_USER}", "password": "${env.GHCR_TOKEN}" }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Select the deployment with `-d <name>` placed before the command name (after it, `-d` is silently ignored), `--deployment <name>` anywhere, or the `WEBDA_DEPLOYMENT` environment variable. `webda` is not on the PATH of a generated app: use `npx webda` (or `npm exec -- webda`). The same selection applies to `serve` and `debug`: they run the app with the overrides of that deployment.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx webda -d production container build # OCI layout in .webda/oci/<unit>, base layers included
|
|
55
|
+
npx webda -d production container push # build and push every tag of the unit
|
|
56
|
+
npx webda -d production aws package # Lambda zip (LambdaPackager unit), dist/lambda-<version>.zip by default
|
|
57
|
+
npx webda -d production deploy # run `deploy` of every unit that has it (ContainerDeployer, CloudFormationDeployer)
|
|
58
|
+
npx webda -d production --service image container push # only the unit named image
|
|
59
|
+
WEBDA_DEPLOYMENT=production npm run serve # npm scripts: environment variable
|
|
60
|
+
npm run serve -- --deployment production # or --deployment, never -d after the command
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Units of other types in the same deployment:
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"units": [
|
|
68
|
+
{ "name": "package", "type": "Webda/LambdaPackager", "zipPath": "dist/app.zip" },
|
|
69
|
+
{
|
|
70
|
+
"name": "stack",
|
|
71
|
+
"type": "Webda/CloudFormationDeployer",
|
|
72
|
+
"AssetsBucket": "my-artifacts",
|
|
73
|
+
"Lambda": {},
|
|
74
|
+
"APIGateway": {}
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`Webda/LambdaPackager` is independent from `Webda/CloudFormationDeployer`: the latter packages its own Lambda from its `LambdaPackager` parameter.
|
|
81
|
+
|
|
82
|
+
Units are not services of the app: a unit is only instantiated by a command its type provides, `serve` and `debug` never create it. `${...}` templates in unit parameters (`${package.version}`, `${git.commit}`, `${deployment}`, `${env.NAME}`) are replaced when the command runs.
|
|
83
|
+
|
|
84
|
+
## Common mistakes
|
|
85
|
+
|
|
86
|
+
```text
|
|
87
|
+
Deployer config in "services" → it goes in "units"; "services" only overrides app services
|
|
88
|
+
A unit named like an app service → DEPLOYMENT_UNIT_CONFLICT, rename the unit
|
|
89
|
+
Running a deployer command without -d → DEPLOYMENT_REQUIRED: select the deployment
|
|
90
|
+
-d after the command name → ignored silently; put it before, or use --deployment
|
|
91
|
+
Deployer package not installed → unit of an unknown type is skipped silently, no command: npm install @webda/oci or @webda/aws, npm run build
|
|
92
|
+
Secrets in deployments/*.json → "${env.NAME}" in a unit parameter; parameters/services values are not interpolated, service secrets come from the environment variables the service reads
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Verify
|
|
96
|
+
|
|
97
|
+
`npx webda -d production container build` logs `Built sha256:... in <path>` (it downloads the base image layers once, so it needs network access). `npx webda --help` lists the commands of the installed deployers (`@webda/oci`, `@webda/aws`).
|
|
98
|
+
|
|
99
|
+
## Reference
|
|
100
|
+
|
|
101
|
+
https://docs.webda.io
|
|
102
|
+
|
|
103
|
+
Written for Webda 4.0.0-beta.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: webda-models
|
|
3
|
+
description: Use when adding or changing a Webda model, its fields, validation, primary key or relations to other models
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Webda models
|
|
7
|
+
|
|
8
|
+
## When to use
|
|
9
|
+
|
|
10
|
+
Adding a model, adding or changing a field, its validation, the primary key, or a relation between models.
|
|
11
|
+
|
|
12
|
+
## Pattern
|
|
13
|
+
|
|
14
|
+
A model is a class in `src/models/<Name>.model.ts` extending `UuidModel` (generated `uuid` key) or `Model` (your own key). Fields are class properties; validation comes from JSDoc tags, which the compiler turns into the JSON schema. Run `npm run build` after changing a model: it regenerates `webda.module.json` and `.webda/`.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { BelongTo, Model, OneToMany, UuidModel, WEBDA_PRIMARY_KEY } from "@webda/models";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A product category, identified by its slug
|
|
21
|
+
*/
|
|
22
|
+
export class Category extends Model {
|
|
23
|
+
[WEBDA_PRIMARY_KEY] = ["slug"] as const;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* URL-friendly identifier
|
|
27
|
+
* @pattern ^[a-z0-9-]+$
|
|
28
|
+
*/
|
|
29
|
+
slug!: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @minLength 2
|
|
33
|
+
* @maxLength 50
|
|
34
|
+
*/
|
|
35
|
+
name!: string;
|
|
36
|
+
|
|
37
|
+
products!: OneToMany<Product, Category, "category">;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A product of a category
|
|
42
|
+
*/
|
|
43
|
+
export class Product extends UuidModel {
|
|
44
|
+
/**
|
|
45
|
+
* @minLength 1
|
|
46
|
+
*/
|
|
47
|
+
title!: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @minimum 0
|
|
51
|
+
*/
|
|
52
|
+
price!: number;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Optional fields use `?`
|
|
56
|
+
* @maxLength 500
|
|
57
|
+
*/
|
|
58
|
+
description?: string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Category the product belongs to
|
|
62
|
+
*/
|
|
63
|
+
category!: BelongTo<Category>;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Relations:
|
|
68
|
+
|
|
69
|
+
| Type | Meaning |
|
|
70
|
+
| ------------------------------------------ | ---------------------------------------------------------------------------------------------------- |
|
|
71
|
+
| `BelongTo<Parent>` | this model belongs to a parent; deleting the parent does not delete it, delete the children yourself |
|
|
72
|
+
| `RelateTo<Other>` | a link to another model, no cascade |
|
|
73
|
+
| `OneToMany<Child, ThisModel, "attribute">` | the children whose `attribute` points to this model (read side of `BelongTo`/`RelateTo`) |
|
|
74
|
+
| `ManyToMany<Other>` | many-to-many links |
|
|
75
|
+
|
|
76
|
+
A `BelongTo` or `RelateTo` field is stored as the key of the target: pass the key of the parent, `parent.getUUID()` for a model with a `uuid` key.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { BelongTo, UuidModel } from "@webda/models";
|
|
80
|
+
|
|
81
|
+
export class Shelf extends UuidModel {
|
|
82
|
+
name!: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export class Book extends UuidModel {
|
|
86
|
+
title!: string;
|
|
87
|
+
shelf!: BelongTo<Shelf>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function addBook(shelf: Shelf): Promise<Book> {
|
|
91
|
+
return Book.create({ title: "Dune", shelf: shelf.getUUID() });
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The `OneToMany` side is queried like a model, restricted to the children of that instance:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { BelongTo, OneToMany, UuidModel } from "@webda/models";
|
|
99
|
+
|
|
100
|
+
export class Author extends UuidModel {
|
|
101
|
+
name!: string;
|
|
102
|
+
articles!: OneToMany<Article, Author, "author">;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export class Article extends UuidModel {
|
|
106
|
+
title!: string;
|
|
107
|
+
author!: BelongTo<Author>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function articleTitles(author: Author): Promise<string[]> {
|
|
111
|
+
const { results } = await author.articles.query("title != ? ORDER BY title LIMIT 20", [""]);
|
|
112
|
+
return results.map(article => article.title);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Read and write data through the model (see the `webda-stores` skill): `Product.create({...})`, `Product.ref(uuid).get()`, `Product.query("price > 10")`.
|
|
117
|
+
|
|
118
|
+
## Common mistakes
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
@Model() / @Expose() decorators and CoreModel → v3 APIs: extend Model or UuidModel, no decorators
|
|
122
|
+
@Inject("productStore") store: Store → never use a store directly: Product.create / Product.query
|
|
123
|
+
Editing webda.module.json or .webda/ → generated: change the model and run npm run build
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- Name model files `*.model.ts` (the build fails on a model file without that suffix); `src/models/` is the convention.
|
|
127
|
+
- Import related models with `import type` to avoid circular imports.
|
|
128
|
+
|
|
129
|
+
## Verify
|
|
130
|
+
|
|
131
|
+
`npm run build` must succeed (it reports invalid JSDoc tags and relation targets), then `npm test`.
|
|
132
|
+
|
|
133
|
+
## Reference
|
|
134
|
+
|
|
135
|
+
https://docs.webda.io
|
|
136
|
+
|
|
137
|
+
Written for Webda 4.0.0-beta.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: webda-operations
|
|
3
|
+
description: Use when exposing behaviour to clients as an operation, or enabling REST, GraphQL, gRPC or MCP in a Webda app
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Webda operations and transports
|
|
7
|
+
|
|
8
|
+
## When to use
|
|
9
|
+
|
|
10
|
+
Making a model or service method callable by clients, or adding a transport.
|
|
11
|
+
|
|
12
|
+
## Pattern
|
|
13
|
+
|
|
14
|
+
`@Operation()` on a service or model method declares an operation. Every enabled transport exposes it: REST, GraphQL, gRPC and MCP read the same operations, with the same input validation (from the TypeScript signature) and permissions. Models also get create/get/update/patch/delete/query operations automatically. The operation id of a service method is the service's configured name in `webda.config.json`, capitalized, then the capitalized method name: `GreetingService.Greet` when configured as `"GreetingService"`.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { Operation, Service } from "@webda/core";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @WebdaModda
|
|
21
|
+
*/
|
|
22
|
+
export class GreetingService extends Service {
|
|
23
|
+
/**
|
|
24
|
+
* Operation id: GreetingService.Greet; REST: PUT /greetingservice/greet
|
|
25
|
+
* @param name - who to greet
|
|
26
|
+
* @returns the greeting
|
|
27
|
+
*/
|
|
28
|
+
@Operation()
|
|
29
|
+
greet(name: string): string {
|
|
30
|
+
return `Hello ${name}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
On a model, an instance method operation receives the model loaded from its key:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { Operation } from "@webda/core";
|
|
39
|
+
import { UuidModel } from "@webda/models";
|
|
40
|
+
|
|
41
|
+
export class Invoice extends UuidModel {
|
|
42
|
+
paid!: boolean;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Operation id: Invoice.Pay
|
|
46
|
+
*/
|
|
47
|
+
@Operation()
|
|
48
|
+
async pay(): Promise<void> {
|
|
49
|
+
this.paid = true;
|
|
50
|
+
await this.save();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Transports are services in `webda.config.json`; add the package and the service:
|
|
56
|
+
|
|
57
|
+
| Transport | Package | Service |
|
|
58
|
+
| --------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
59
|
+
| REST | `@webda/core` | `"RESTService": { "type": "Webda/RESTOperationsTransport" }` |
|
|
60
|
+
| GraphQL | `@webda/graphql` | `"GraphQLService": { "type": "Webda/GraphQLService" }` |
|
|
61
|
+
| gRPC | `@webda/grpc` | `"GRPCService": { "type": "Webda/GrpcService" }` plus `"HttpServerH2c": { "type": "Webda/HttpServer", "port": 50051, "h2c": true }` |
|
|
62
|
+
| MCP | `@webda/mcp` | `"MCP": { "type": "Webda/McpService" }` |
|
|
63
|
+
|
|
64
|
+
`Webda/DomainService` must stay configured: it registers the model operations.
|
|
65
|
+
|
|
66
|
+
## Common mistakes
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
Writing a REST route by hand for model CRUD → already exposed by the model operations
|
|
70
|
+
One method per transport → one @Operation serves every transport
|
|
71
|
+
Removing DomainService → model operations disappear
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Verify
|
|
75
|
+
|
|
76
|
+
`npm run build` regenerates `.webda/operations.json`: check your operation id is listed. Then `npm run debug` and call it.
|
|
77
|
+
|
|
78
|
+
## Reference
|
|
79
|
+
|
|
80
|
+
https://docs.webda.io
|
|
81
|
+
|
|
82
|
+
Written for Webda 4.0.0-beta.
|