create-cellsweb-rpc-api 1.0.29 → 1.0.31
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 +21 -0
- package/README.md +257 -60
- package/bin/create-function.js +1 -3
- package/bin/create-middleware.js +0 -0
- package/bin/create.js +2 -2
- package/package.json +18 -6
- package/template/README.md +36 -116
- package/template/src/functions/public/hello/constants.ts +0 -1
- package/template/test.ts +1 -1
- package/templates/servers/server.bun.ts +2 -2
- package/templates/servers/server.elysia.ts +2 -2
- package/templates/servers/server.express.ts +1 -1
- package/templates/servers/server.fastify.ts +1 -1
- package/templates/servers/server.hono.ts +2 -2
- package/templates/servers/server.node.ts +1 -1
- package/templates/servers/server.ultimate-express.ts +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CellsWeb
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,88 +1,285 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://cellsweb.com" target="_blank" rel="noopener noreferrer">
|
|
3
|
+
<img src="https://cellsweb.com/logo.svg" alt="CellsWeb Logo" width="340" style="background: rgba(255, 255, 255, 0.96); padding: 16px 24px; border-radius: 16px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08); display: inline-block; max-width: 100%;" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
# create-cellsweb-rpc-api
|
|
2
8
|
|
|
3
9
|
[](https://www.npmjs.com/package/create-cellsweb-rpc-api)
|
|
4
|
-
[](https://github.com/CellsWeb/crpc-node/blob/main/LICENSE)
|
|
11
|
+
|
|
12
|
+
The official **CellsWeb RPC** project initializer. Generate a TypeScript RPC
|
|
13
|
+
application with function discovery, TypeBox schemas, middleware examples,
|
|
14
|
+
JSON/multipart handling, environment configuration and a project-local CLI.
|
|
15
|
+
Choose native Node, Bun, Express, Fastify, Hono, Elysia or Ultimate Express while
|
|
16
|
+
keeping function and middleware modules independent of the HTTP adapter.
|
|
17
|
+
|
|
18
|
+
This **1.0.31 documentation patch** preserves the generator/template runtime from
|
|
19
|
+
1.0.30. Requires **Node>=24.0.0**, with Node 24 LTS the primary toolchain; Bun 1.3.11
|
|
20
|
+
is tested separately. This package generates the project. The installed
|
|
21
|
+
`@cellsweb/rpc-core` supplies the project's runtime and `crpc` executable.
|
|
22
|
+
|
|
23
|
+
| Ecosystem | Responsibility |
|
|
24
|
+
|---|---|
|
|
25
|
+
| [create-cellsweb-rpc-api](https://www.npmjs.com/package/create-cellsweb-rpc-api) | This initializer and project templates |
|
|
26
|
+
| [@cellsweb/rpc-core](https://www.npmjs.com/package/@cellsweb/rpc-core) | Server engine, contracts, adapters and local CLI |
|
|
27
|
+
| [@cellsweb/rpc-client](https://www.npmjs.com/package/@cellsweb/rpc-client) | Separate frontend/client SDK, React hooks and native file support |
|
|
28
|
+
| [CellsWeb RPC Go](https://github.com/CellsWeb/crpc-go) | Go SDK and its separate Go initializer |
|
|
29
|
+
|
|
30
|
+
## Contents
|
|
31
|
+
|
|
32
|
+
- [Quick start](#quick-start)
|
|
33
|
+
- [Interactive and automated setup](#interactive-and-automated-setup)
|
|
34
|
+
- [Seven supported adapters](#seven-supported-adapters)
|
|
35
|
+
- [Generated project structure](#generated-project-structure)
|
|
36
|
+
- [Functions and middleware](#functions-and-middleware)
|
|
37
|
+
- [Development, build and tests](#development-build-and-tests)
|
|
38
|
+
- [Environment and documentation controls](#environment-and-documentation-controls)
|
|
39
|
+
- [Uploads and application customization](#uploads-and-application-customization)
|
|
40
|
+
- [Deployment and compatibility](#deployment-and-compatibility)
|
|
41
|
+
- [Documentation, contribution and license](#documentation-contribution-and-license)
|
|
42
|
+
|
|
43
|
+
## Quick start
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npm create cellsweb-rpc-api@latest my-api -- --framework=node --yes --pm=npm
|
|
47
|
+
cd my-api
|
|
48
|
+
npm run typecheck
|
|
49
|
+
npm run build
|
|
50
|
+
npm test
|
|
51
|
+
npm run dev
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The correct npm initializer name is **cellsweb-rpc-api**, not
|
|
55
|
+
create-create-cellsweb-rpc-api. For an exact generator version:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
npx create-cellsweb-rpc-api@1.0.31 my-api --framework=node --yes --pm=npm
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Once running (port4000 by default), invoke the generated hello function:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
curl http://localhost:4000/rpc \
|
|
65
|
+
-H 'Content-Type: application/json' \
|
|
66
|
+
--data '{"namespace":"public","functionName":"hello","data":{"name":"Ada"}}'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Open `/docs` during development to inspect registered functions and middleware.
|
|
70
|
+
The generated hello contract is the source of truth for its complete response.
|
|
71
|
+
Frontend applications install `@cellsweb/rpc-client` independently.
|
|
72
|
+
|
|
73
|
+
## Interactive and automated setup
|
|
74
|
+
|
|
75
|
+
With an interactive terminal, the CLI asks for target directory (if omitted),
|
|
76
|
+
package name, package manager and framework. Choose a fresh empty directory;
|
|
77
|
+
this is not an in-place migration tool for existing applications.
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
npm create cellsweb-rpc-api@latest
|
|
81
|
+
# Equivalent executable:
|
|
82
|
+
npx create-cellsweb-rpc-api@latest my-api
|
|
83
|
+
# pnpm initializer:
|
|
84
|
+
pnpm create cellsweb-rpc-api@latest my-api
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
For automation, provide the target directory first and explicit flags:
|
|
5
88
|
|
|
6
|
-
|
|
89
|
+
```sh
|
|
90
|
+
npx create-cellsweb-rpc-api@1.0.31 generated-api \
|
|
91
|
+
--framework=fastify --name=example-api --pm=npm --yes --skip-install
|
|
92
|
+
cd generated-api
|
|
93
|
+
npm install
|
|
94
|
+
npm run typecheck
|
|
95
|
+
npm run build
|
|
96
|
+
npm test
|
|
97
|
+
```
|
|
7
98
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
99
|
+
| Flag | Purpose |
|
|
100
|
+
|---|---|
|
|
101
|
+
| `--framework=name`, `--framework name`, `-f name` | Select adapter |
|
|
102
|
+
| `--yes`, `-y`, `--non-interactive` | Use defaults without prompts |
|
|
103
|
+
| `--skip-install`, `--no-install` | Generate files without installing dependencies |
|
|
104
|
+
| `--pm=npm`, `--pm=pnpm`, `--pm=yarn`, `--pm=bun` | Select package manager |
|
|
105
|
+
| `--name=package-name`, `--name package-name`, `-n package-name` | Generated package name |
|
|
12
106
|
|
|
13
|
-
|
|
107
|
+
Without a TTY, defaults are used; explicit `--yes` documents automation intent.
|
|
108
|
+
The default package manager is pnpm. Use `--pm=npm` if you want npm installation.
|
|
109
|
+
The CLI's framework aliases are conveniences; prefer the canonical names below.
|
|
14
110
|
|
|
15
|
-
##
|
|
111
|
+
## Seven supported adapters
|
|
16
112
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
113
|
+
| Flag value | Generated HTTP integration | Runtime used in regression coverage |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| `node` | Native node:http | Node 24 |
|
|
116
|
+
| `express` | Express request/response handler | Node 24 |
|
|
117
|
+
| `fastify` | CRPC Fastify plugin, including multipart stream handoff | Node 24 |
|
|
118
|
+
| `ultimate-express` | uWebSockets-backed Express-compatible requests | Node 24 |
|
|
119
|
+
| `hono` | Fetch handler through @hono/node-server | Node 24; Bun-hosted integrations tested separately |
|
|
120
|
+
| `elysia` | Elysia Fetch plugin | Bun |
|
|
121
|
+
| `bun` | Native Bun.serve | Bun |
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
npx create-cellsweb-rpc-api@1.0.31 node-api --framework=node --yes --skip-install
|
|
125
|
+
npx create-cellsweb-rpc-api@1.0.31 express-api --framework=express --yes --skip-install
|
|
126
|
+
npx create-cellsweb-rpc-api@1.0.31 fastify-api --framework=fastify --yes --skip-install
|
|
127
|
+
npx create-cellsweb-rpc-api@1.0.31 ultimate-api --framework=ultimate-express --yes --skip-install
|
|
128
|
+
npx create-cellsweb-rpc-api@1.0.31 hono-api --framework=hono --yes --skip-install
|
|
129
|
+
npx create-cellsweb-rpc-api@1.0.31 elysia-api --framework=elysia --yes --skip-install
|
|
130
|
+
npx create-cellsweb-rpc-api@1.0.31 bun-api --framework=bun --yes --skip-install
|
|
24
131
|
```
|
|
25
132
|
|
|
26
|
-
|
|
133
|
+
For a Bun application, install/run using Bun after generation:
|
|
27
134
|
|
|
28
|
-
|
|
135
|
+
```sh
|
|
136
|
+
cd bun-api
|
|
137
|
+
bun install
|
|
138
|
+
bun run typecheck
|
|
139
|
+
bun run build
|
|
140
|
+
bun run dev
|
|
141
|
+
```
|
|
29
142
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
143
|
+
The CLI detects Bun when the CLI process itself runs under Bun. Use the selected
|
|
144
|
+
adapter's supported runtime; Hono/Fetch integration is not a promise that
|
|
145
|
+
filesystem discovery works in every Edge host. A framework's theoretical
|
|
146
|
+
platform list is different from this project's tested runtime matrix.
|
|
33
147
|
|
|
34
|
-
|
|
35
|
-
npx create-cellsweb-rpc-api@latest my-app --framework express
|
|
148
|
+
## Generated project structure
|
|
36
149
|
|
|
37
|
-
|
|
38
|
-
|
|
150
|
+
```text
|
|
151
|
+
my-api/
|
|
152
|
+
package.json # scripts, core SDK and selected adapter
|
|
153
|
+
tsconfig.json # strict TypeScript, emitted declarations
|
|
154
|
+
.env.example # documented environment defaults
|
|
155
|
+
.env # initial copy if absent
|
|
156
|
+
test.ts # integration tests
|
|
157
|
+
src/
|
|
158
|
+
server.ts # selected adapter and startup
|
|
159
|
+
env.ts # dotenv loading, conversion and validation
|
|
160
|
+
functions/public/hello/ # constants, handler, middleware attachments, tests
|
|
161
|
+
middlewares/auth/ # customize credential verification
|
|
162
|
+
middlewares/rateLimit/ # in-memory rate-limiting example
|
|
163
|
+
utils/ # request logging, storage and application helpers
|
|
164
|
+
test/ # test context and lifecycle helpers
|
|
165
|
+
```
|
|
39
166
|
|
|
40
|
-
|
|
41
|
-
|
|
167
|
+
Inspect generated files as application-owned code. The initializer currently
|
|
168
|
+
requests **core^1.0.34**; this compatible range includes the documentation-only
|
|
169
|
+
1.0.35 patch. It is intentionally unchanged because no new runtime dependency is
|
|
170
|
+
required. Generated servers do not depend on rpc-client; your frontend does.
|
|
42
171
|
|
|
43
|
-
|
|
44
|
-
npx create-cellsweb-rpc-api@latest my-app --framework hono
|
|
172
|
+
## Functions and middleware
|
|
45
173
|
|
|
46
|
-
|
|
47
|
-
npx create-cellsweb-rpc-api@latest my-app --framework elysia
|
|
174
|
+
Create a function through the installed project-local core CLI:
|
|
48
175
|
|
|
49
|
-
|
|
50
|
-
|
|
176
|
+
```sh
|
|
177
|
+
npm run create:function -- --ns catalog --name get --contentType json
|
|
178
|
+
npm run create:middleware -- --name tenant --description 'Resolve tenant'
|
|
51
179
|
```
|
|
52
180
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
181
|
+
A function is co-located under `src/functions/<namespace>/<functionName>/`:
|
|
182
|
+
|
|
183
|
+
- constants.ts: metadata, content type, input/output schemas and inferred types.
|
|
184
|
+
- run.ts: application handler, independent of the HTTP framework.
|
|
185
|
+
- middlewares.ts: ordered attachments through `defineMiddlewares`.
|
|
186
|
+
- test.ts: focused tests using the application's test setup.
|
|
187
|
+
|
|
188
|
+
Nested namespaces are supported. Add `--middlewares` to the function generator
|
|
189
|
+
when applicable; JSON `--batch` and `--file` specs support repeated generation.
|
|
190
|
+
These are **project CLI** flags, distinct from the initializer's flags.
|
|
191
|
+
|
|
192
|
+
Authentication belongs to middleware. The generated auth function is an editable
|
|
193
|
+
stub, not a JWT verifier or authorization guarantee. Verify credentials before
|
|
194
|
+
establishing trusted server context; caller JSON cannot bypass middleware.
|
|
195
|
+
Register/discover before serving. Middleware execution is sequential; runtime
|
|
196
|
+
registration during serving is outside the supported concurrency contract.
|
|
197
|
+
|
|
198
|
+
The rateLimit example is in-memory. Select a shared store for distributed limits
|
|
199
|
+
and tune policy for authenticated identities/proxies. Configure trustProxy
|
|
200
|
+
explicitly before trusting forwarded client IPs. Deprecated isPublic is ignored
|
|
201
|
+
and is not generated in new functions; it has no documentation/auth meaning.
|
|
202
|
+
|
|
203
|
+
## Development, build and tests
|
|
204
|
+
|
|
205
|
+
| Command | Purpose |
|
|
206
|
+
|---|---|
|
|
207
|
+
| `npm run dev` | TypeScript development server/watch |
|
|
208
|
+
| `npm run typecheck` | TypeScript checks without emitting |
|
|
209
|
+
| `npm run build` | Compile and resolve emitted import aliases/extensions |
|
|
210
|
+
| `npm start` | Run production output |
|
|
211
|
+
| `npm test` | Project Vitest tests |
|
|
212
|
+
| `npm run test:watch` | Watch tests |
|
|
213
|
+
| `npm run test:coverage` | Coverage report |
|
|
214
|
+
| `npm run test:audit` | Application test/audit report tooling |
|
|
215
|
+
|
|
216
|
+
Build before production start. Add regression tests that assert actual handler
|
|
217
|
+
results, envelopes, authentication decisions and cleanup, not merely HTTP 200.
|
|
218
|
+
The audit command is a development report, not security certification.
|
|
219
|
+
|
|
220
|
+
## Environment and documentation controls
|
|
221
|
+
|
|
222
|
+
src/env.ts loads dotenv. Already-exported process variables take precedence over
|
|
223
|
+
`.env`; values are converted/validated before templates pass them into CoreRPC.
|
|
224
|
+
|
|
225
|
+
| Environment | Purpose |
|
|
226
|
+
|---|---|
|
|
227
|
+
| `NODE_ENV` | development, test or production |
|
|
228
|
+
| `API_PORT`, `API_HOST` | Listening address |
|
|
229
|
+
| `API_DOCS_ENABLED` | Explicit production docs enablement; parsed boolean |
|
|
230
|
+
| `API_REQUEST_TIMEOUT_MS` | Application timeout configuration |
|
|
231
|
+
| `MAX_JSON_BODY_BYTES` | JSON intake limit |
|
|
232
|
+
| `MAX_MULTIPART_BYTES`, `MAX_UPLOAD_FILE_BYTES` | Multipart total/per-file limits |
|
|
233
|
+
| `UPLOAD_TMP_DIR` | Temporary upload location |
|
|
234
|
+
| `UPLOAD_MODE`, `UPLOAD_DIR` | Application storage helper mode/directory |
|
|
235
|
+
|
|
236
|
+
Every adapter template enables docs outside production by default, and requires
|
|
237
|
+
parsed API_DOCS_ENABLED=true in production. `false` does not enable production
|
|
238
|
+
docs. An explicit application `docs:false` overrides environment defaults.
|
|
239
|
+
Parsing accepts trimmed true/false or1/0 (case-insensitive); invalid production
|
|
240
|
+
values fall back to disabled. Set docs:false for private development environments
|
|
241
|
+
as well. Change the app's `docsEndpoint` for a custom path.
|
|
242
|
+
|
|
243
|
+
Docs may list every registered function and show schemas, middleware headers and
|
|
244
|
+
descriptions. They never read live secret option values. No per-function
|
|
245
|
+
hideFromDocs flag exists. Use middleware for RPC authorization and global docs
|
|
246
|
+
configuration for documentation exposure.
|
|
247
|
+
|
|
248
|
+
## Uploads and application customization
|
|
57
249
|
|
|
58
|
-
|
|
250
|
+
Use File/Files in TypeBox input schemas for physical uploads and FormNum/FormBool
|
|
251
|
+
where multipart text conversion is intended. The client accepts top-level
|
|
252
|
+
File/Blob/native URI assets and direct file arrays; nested file objects are not
|
|
253
|
+
supported. Keep routing headers/body consistent and let FormData set its boundary.
|
|
59
254
|
|
|
60
|
-
|
|
255
|
+
Native Node stream adapters use Busboy. Fetch adapters may buffer at the runtime
|
|
256
|
+
formData interface. Temp files are cleaned after processing; persist within the
|
|
257
|
+
handler to an application-owned unique path when needed. MIME limits do not
|
|
258
|
+
sanitize uploaded content; validate content for your use case. Existing server
|
|
259
|
+
file-array completion order is not a stable business ordering guarantee.
|
|
61
260
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
| **Express** | `express`, `@types/express` | Standard Express server; easily mount traditional REST routes alongside `/rpc`. |
|
|
66
|
-
| **Fastify** | `fastify` | Fastify server with built-in plugin adapter (`app.createFastifyPlugin()`). |
|
|
67
|
-
| **Ultimate-Express** | `ultimate-express` | Drop-in Express replacement powered by `uWebSockets.js` for extreme I/O throughput. |
|
|
68
|
-
| **Hono** | `hono`, `@hono/node-server` | Universal Web Standards engine running seamlessly across Bun, Node.js, and Edge runtimes. |
|
|
69
|
-
| **Elysia.js** | `elysia` | Bun-first web framework with native TypeBox alignment and high developer ergonomics. |
|
|
70
|
-
| **Bun Native** | *None (Zero extra deps)* | Ultra-fast execution on native `Bun.serve` with zero third-party web framework overhead. |
|
|
261
|
+
Customize storage.ts for local/S3 persistence and telemetry helpers for your
|
|
262
|
+
monitoring. Optional SDKs in generated applications do not establish production
|
|
263
|
+
credentials or configure your infrastructure automatically.
|
|
71
264
|
|
|
72
|
-
|
|
265
|
+
## Deployment and compatibility
|
|
73
266
|
|
|
74
|
-
|
|
267
|
+
Keep .env and credentials out of version control. Install/build in your release
|
|
268
|
+
environment, set production configuration, run tests, then start the compiled
|
|
269
|
+
entrypoint. Handle process shutdown in your application's host integration.
|
|
75
270
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
- **Security & Integration Audit Testing**: Built-in in-process security audit test harness with HTML/JSON report generation (`crpc test:audit`).
|
|
81
|
-
- **Pre-scaffolded Common Middlewares**: Includes `auth` (JWT verification stub) and `rateLimit` (in-memory rate limiting).
|
|
82
|
-
- **Pluggable Extensions**: Modular application-level `env.ts` (TypeBox), `telemetry.ts` (Sentry), and `storage.ts` (Local/S3 uploads).
|
|
271
|
+
This is a documentation-only initializer patch. Function discovery, schemas,
|
|
272
|
+
middleware order, HTTP 200 application-error envelopes, multipart handling and
|
|
273
|
+
server APIs are unchanged. Upgrade the core independently according to your
|
|
274
|
+
application's package manager and lockfile policy.
|
|
83
275
|
|
|
84
|
-
|
|
276
|
+
## Documentation, contribution and license
|
|
85
277
|
|
|
86
|
-
|
|
278
|
+
[Getting started](https://cellsweb.github.io/crpc-node/getting-started/) ·
|
|
279
|
+
[CLI guide](https://cellsweb.github.io/crpc-node/cli/) ·
|
|
280
|
+
[Adapters](https://cellsweb.github.io/crpc-node/adapters/) ·
|
|
281
|
+
[Source](https://github.com/CellsWeb/crpc-node/tree/main/packages/create-cellsweb-rpc-api) ·
|
|
282
|
+
[Contributing](https://github.com/CellsWeb/crpc-node/blob/main/CONTRIBUTING.md) ·
|
|
283
|
+
[Security policy](https://github.com/CellsWeb/crpc-node/security/policy)
|
|
87
284
|
|
|
88
|
-
MIT ©
|
|
285
|
+
MIT ©2026 CellsWeb. See [LICENSE](https://github.com/CellsWeb/crpc-node/blob/main/LICENSE).
|
package/bin/create-function.js
CHANGED
|
@@ -136,7 +136,6 @@ import { File, Files } from "@cellsweb/rpc-core";
|
|
|
136
136
|
|
|
137
137
|
export const metadata = {
|
|
138
138
|
description: "${descriptionStr}",
|
|
139
|
-
isPublic: ${ns.startsWith("public")},
|
|
140
139
|
deprecated: false,
|
|
141
140
|
tags: ["upload"] as string[],
|
|
142
141
|
};
|
|
@@ -173,7 +172,7 @@ export const outputSchema = Type.Object({
|
|
|
173
172
|
* SCHEMA & CONTRACT DEFINITION
|
|
174
173
|
*
|
|
175
174
|
* WHAT TO TOUCH:
|
|
176
|
-
* - metadata: Description,
|
|
175
|
+
* - metadata: Description, deprecation, tags.
|
|
177
176
|
* - contentType: "application/json" (default).
|
|
178
177
|
* - inputSchema: Define fields expected in req.body.data. Include description in Type properties!
|
|
179
178
|
* - outputSchema: Define structure returned by run(). Include description in Type properties!
|
|
@@ -183,7 +182,6 @@ import { Type } from "@sinclair/typebox";
|
|
|
183
182
|
|
|
184
183
|
export const metadata = {
|
|
185
184
|
description: "${descriptionStr}",
|
|
186
|
-
isPublic: ${ns.startsWith("public")},
|
|
187
185
|
deprecated: false,
|
|
188
186
|
tags: [] as string[],
|
|
189
187
|
};
|
package/bin/create-middleware.js
CHANGED
|
File without changes
|
package/bin/create.js
CHANGED
|
@@ -217,10 +217,10 @@ async function main() {
|
|
|
217
217
|
"create:middleware": "crpc create:middleware",
|
|
218
218
|
},
|
|
219
219
|
engines: {
|
|
220
|
-
node: ">=
|
|
220
|
+
node: ">=24.0.0",
|
|
221
221
|
},
|
|
222
222
|
dependencies: {
|
|
223
|
-
"@cellsweb/rpc-core": "^1.0.
|
|
223
|
+
"@cellsweb/rpc-core": "^1.0.34",
|
|
224
224
|
"@aws-sdk/client-s3": "^3.700.0",
|
|
225
225
|
"@paralleldrive/cuid2": "^2.2.2",
|
|
226
226
|
"@sentry/node": "^8.40.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cellsweb-rpc-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.31",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"template",
|
|
17
17
|
"templates"
|
|
18
18
|
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "node --import tsx --test --test-concurrency=1 test/*.test.mjs"
|
|
21
|
+
},
|
|
19
22
|
"keywords": [
|
|
20
23
|
"rpc",
|
|
21
24
|
"create-app",
|
|
@@ -27,18 +30,27 @@
|
|
|
27
30
|
"license": "MIT",
|
|
28
31
|
"repository": {
|
|
29
32
|
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/
|
|
33
|
+
"url": "git+https://github.com/CellsWeb/crpc-node.git"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"@clack/prompts": "^1.7.0",
|
|
34
37
|
"tinyglobby": "^0.2.17"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
40
|
+
"@hono/node-server": "^1.19.19",
|
|
37
41
|
"@sinclair/typebox": "^0.34.52",
|
|
42
|
+
"@types/express": "^5.0.6",
|
|
38
43
|
"@types/node": "^26.6.6",
|
|
39
|
-
"dotenv": "^17.4.2"
|
|
44
|
+
"dotenv": "^17.4.2",
|
|
45
|
+
"elysia": "^1.4.32",
|
|
46
|
+
"express": "^4.22.3",
|
|
47
|
+
"fastify": "^5.12.8",
|
|
48
|
+
"hono": "^4.13.18",
|
|
49
|
+
"tsx": "^4.22.0",
|
|
50
|
+
"typescript": "^7.0.2",
|
|
51
|
+
"ultimate-express": "^2.2.4"
|
|
40
52
|
},
|
|
41
|
-
"
|
|
42
|
-
"
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=24.0.0"
|
|
43
55
|
}
|
|
44
|
-
}
|
|
56
|
+
}
|
package/template/README.md
CHANGED
|
@@ -1,116 +1,36 @@
|
|
|
1
|
-
# CellsWeb RPC
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
└── hello/ — Sample JSON RPC function
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
## Single API Endpoint (`POST /rpc` or `POST /api`)
|
|
43
|
-
|
|
44
|
-
### JSON Request Example
|
|
45
|
-
```json
|
|
46
|
-
{
|
|
47
|
-
"namespace": "public",
|
|
48
|
-
"functionName": "hello",
|
|
49
|
-
"data": {
|
|
50
|
-
"name": "Alice"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Multipart Request Example (`Content-Type: multipart/form-data`)
|
|
56
|
-
Pass form-data fields:
|
|
57
|
-
- `namespace`: `"public"`
|
|
58
|
-
- `functionName`: `"uploadAvatar"`
|
|
59
|
-
- `title`: `"My Avatar"`
|
|
60
|
-
- `avatar`: `<file attachment>`
|
|
61
|
-
|
|
62
|
-
---
|
|
63
|
-
|
|
64
|
-
## Creating Functions & Middlewares
|
|
65
|
-
|
|
66
|
-
### Scaffold a New Function
|
|
67
|
-
```bash
|
|
68
|
-
pnpm run create:function
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Generates:
|
|
72
|
-
```txt
|
|
73
|
-
src/functions/{namespace}/{functionName}/
|
|
74
|
-
├── constants.ts — Metadata, accepted Content-Type, and TypeBox schemas
|
|
75
|
-
├── run.ts — Business logic handler
|
|
76
|
-
├── middlewares.ts — Declarative middleware pipeline ({ name, options })
|
|
77
|
-
└── test.ts — Vitest unit test
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Scaffold a New Middleware
|
|
81
|
-
```bash
|
|
82
|
-
pnpm run create:middleware
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Generates:
|
|
86
|
-
```txt
|
|
87
|
-
src/middlewares/{middlewareName}/
|
|
88
|
-
├── constants.ts — Metadata, headersSchema, and optionsSchema
|
|
89
|
-
├── run.ts — Middleware logic (receives headers, options, function, context)
|
|
90
|
-
└── test.ts — Vitest unit test
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
---
|
|
94
|
-
|
|
95
|
-
## Storage & File Uploads
|
|
96
|
-
|
|
97
|
-
Use `storage.upload()` inside function `run.ts`:
|
|
98
|
-
|
|
99
|
-
```ts
|
|
100
|
-
import { storage } from "@/utils/storage";
|
|
101
|
-
|
|
102
|
-
export const run = async (input, _context) => {
|
|
103
|
-
const fileBuffer = await input.avatar.toBuffer();
|
|
104
|
-
const saved = await storage.upload(fileBuffer, input.avatar.filename, "avatars");
|
|
105
|
-
return { url: saved.url };
|
|
106
|
-
};
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
Set `UPLOAD_MODE=s3` in `.env` along with `S3_BUCKET`, `S3_REGION`, `S3_ACCESS_KEY`, `S3_SECRET_KEY` to switch to S3 mode seamlessly.
|
|
110
|
-
|
|
111
|
-
---
|
|
112
|
-
|
|
113
|
-
## Interactive Documentation & Health
|
|
114
|
-
|
|
115
|
-
- **Interactive API Docs**: Visit `http://localhost:4000/docs` in your browser.
|
|
116
|
-
- **Health Check**: `GET http://localhost:4000/health`.
|
|
1
|
+
# Generated CellsWeb RPC application
|
|
2
|
+
|
|
3
|
+
Node 24 LTS is primary (engines >=24.0.0). Bun/Elysia templates run under Bun,
|
|
4
|
+
tested separately with 1.3.11. Install dependencies, then run:
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm run typecheck
|
|
8
|
+
npm test
|
|
9
|
+
npm run build
|
|
10
|
+
npm start
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The generated core requirement is ^1.0.34 and resolves from public npm.
|
|
14
|
+
Use ordinary package installation; no local SDK checkout or override is required.
|
|
15
|
+
|
|
16
|
+
Use npm run dev for Node development. For Bun select Bun execution, for example
|
|
17
|
+
`bun run src/server.ts` with the Bun-native template. The local crpc CLI supplies
|
|
18
|
+
function/middleware generation, build and tests. Complete templates cover native
|
|
19
|
+
Node, Express, Fastify, Hono, Ultimate Express, Bun and Elysia.
|
|
20
|
+
|
|
21
|
+
src/env.ts loads .env without overriding exported values. API_PORT/API_HOST
|
|
22
|
+
default to 4000/0.0.0.0. Docs are enabled outside production; production requires
|
|
23
|
+
parsed API_DOCS_ENABLED=true (true/false/1/0, trimmed and case-insensitive).
|
|
24
|
+
To disable even in development set the explicit CoreRPC docs:false option.
|
|
25
|
+
Disabling docs blocks their pages, not function execution. No visibility flag
|
|
26
|
+
exists; deprecated isPublic is ignored and new functions omit it.
|
|
27
|
+
|
|
28
|
+
Replace the generated auth stub with real credential verification. Middleware
|
|
29
|
+
owns authentication/authorization; remote clients forward headers, not trusted
|
|
30
|
+
context or a middleware-skip switch. Function input/output schemas remain active.
|
|
31
|
+
|
|
32
|
+
Use File/Files for uploads. Node UploadedFile exposes path, filename, mimeType,
|
|
33
|
+
byteLength and stream/buffer/blob methods. Persist into application-owned storage
|
|
34
|
+
while the handler runs; temporary uploads are cleaned afterward. Use configured
|
|
35
|
+
limits and top-level/direct-array file fields. Fetch multipart may buffer at the
|
|
36
|
+
runtime boundary; no zero-memory guarantee is implied.
|
package/template/test.ts
CHANGED
|
@@ -50,7 +50,7 @@ describe("CellsWeb RPC API Boilerplate Suite", () => {
|
|
|
50
50
|
fs.writeFileSync(
|
|
51
51
|
path.join(echoDir, "constants.ts"),
|
|
52
52
|
`import { Type } from "@sinclair/typebox";
|
|
53
|
-
export const metadata = { description: "echo"
|
|
53
|
+
export const metadata = { description: "echo" };
|
|
54
54
|
export const contentType = "application/json";
|
|
55
55
|
export const inputSchema = Type.Object({ message: Type.String({ minLength: 2 }) });
|
|
56
56
|
export const outputSchema = Type.Object({ reply: Type.String() });`,
|
|
@@ -13,7 +13,7 @@ export const app = new CoreRPC({
|
|
|
13
13
|
middlewaresDir: "./src/middlewares",
|
|
14
14
|
port: env.API_PORT,
|
|
15
15
|
host: env.API_HOST,
|
|
16
|
-
docs: true,
|
|
16
|
+
docs: env.NODE_ENV !== "production" || env.API_DOCS_ENABLED === true,
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
export const fetchHandler = async (req: Request): Promise<Response> => {
|
|
@@ -36,7 +36,7 @@ export const fetchHandler = async (req: Request): Promise<Response> => {
|
|
|
36
36
|
},
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
|
-
return new Response(result.buffer, {
|
|
39
|
+
return new Response(new Uint8Array(result.buffer), {
|
|
40
40
|
status: 200,
|
|
41
41
|
headers: {
|
|
42
42
|
"Content-Type": result.mimeType,
|
|
@@ -14,7 +14,7 @@ export const app = new CoreRPC({
|
|
|
14
14
|
middlewaresDir: "./src/middlewares",
|
|
15
15
|
port: env.API_PORT,
|
|
16
16
|
host: env.API_HOST,
|
|
17
|
-
docs: true,
|
|
17
|
+
docs: env.NODE_ENV !== "production" || env.API_DOCS_ENABLED === true,
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
export const server = new Elysia();
|
|
@@ -36,7 +36,7 @@ server.get("/uploads/*", async ({ path }) => {
|
|
|
36
36
|
},
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
|
-
return new Response(result.buffer, {
|
|
39
|
+
return new Response(new Uint8Array(result.buffer), {
|
|
40
40
|
status: 200,
|
|
41
41
|
headers: {
|
|
42
42
|
"Content-Type": result.mimeType,
|
|
@@ -14,7 +14,7 @@ export const app = new CoreRPC({
|
|
|
14
14
|
middlewaresDir: "./src/middlewares",
|
|
15
15
|
port: env.API_PORT,
|
|
16
16
|
host: env.API_HOST,
|
|
17
|
-
docs: true,
|
|
17
|
+
docs: env.NODE_ENV !== "production" || env.API_DOCS_ENABLED === true,
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
export const server: Express = express();
|
|
@@ -14,7 +14,7 @@ export const app = new CoreRPC({
|
|
|
14
14
|
middlewaresDir: "./src/middlewares",
|
|
15
15
|
port: env.API_PORT,
|
|
16
16
|
host: env.API_HOST,
|
|
17
|
-
docs: true,
|
|
17
|
+
docs: env.NODE_ENV !== "production" || env.API_DOCS_ENABLED === true,
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
export const server = Fastify({ logger: false });
|
|
@@ -14,7 +14,7 @@ export const app = new CoreRPC({
|
|
|
14
14
|
middlewaresDir: "./src/middlewares",
|
|
15
15
|
port: env.API_PORT,
|
|
16
16
|
host: env.API_HOST,
|
|
17
|
-
docs: true,
|
|
17
|
+
docs: env.NODE_ENV !== "production" || env.API_DOCS_ENABLED === true,
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
export const server = new Hono();
|
|
@@ -33,7 +33,7 @@ server.get("/uploads/*", async (c) => {
|
|
|
33
33
|
404,
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
-
return new Response(result.buffer, {
|
|
36
|
+
return new Response(new Uint8Array(result.buffer), {
|
|
37
37
|
status: 200,
|
|
38
38
|
headers: {
|
|
39
39
|
"Content-Type": result.mimeType,
|
|
@@ -14,7 +14,7 @@ export const app = new CoreRPC({
|
|
|
14
14
|
middlewaresDir: "./src/middlewares",
|
|
15
15
|
port: env.API_PORT,
|
|
16
16
|
host: env.API_HOST,
|
|
17
|
-
docs: true,
|
|
17
|
+
docs: env.NODE_ENV !== "production" || env.API_DOCS_ENABLED === true,
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
const rpcHandler = await app.createHandler();
|
|
@@ -14,10 +14,10 @@ export const app = new CoreRPC({
|
|
|
14
14
|
middlewaresDir: "./src/middlewares",
|
|
15
15
|
port: env.API_PORT,
|
|
16
16
|
host: env.API_HOST,
|
|
17
|
-
docs: true,
|
|
17
|
+
docs: env.NODE_ENV !== "production" || env.API_DOCS_ENABLED === true,
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
export const server = express();
|
|
20
|
+
export const server: ReturnType<typeof express> = express();
|
|
21
21
|
const rpcHandler = await app.createHandler();
|
|
22
22
|
|
|
23
23
|
// ── Static Files Route (/uploads/*) ──
|