@nano-app/backend 0.8.3 → 0.10.0
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/README.md +65 -26
- package/build/index.d.ts +142 -129
- package/build/index.js +583 -525
- package/package.json +17 -15
- package/build/nano-app.js +0 -41
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @nano-app/backend
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@nano-app/backend)
|
|
4
|
+
|
|
3
5
|
Preconfigured Express server with **file-convention routes** and **plugins**: it mounts the base middlewares, discovers your routes, formats every error as JSON, and groups extra endpoints in plugins.
|
|
4
6
|
|
|
5
7
|
- Node ≥ 20, ESM.
|
|
@@ -46,7 +48,7 @@ export default createRoute({
|
|
|
46
48
|
|
|
47
49
|
## Routes
|
|
48
50
|
|
|
49
|
-
Each `*.route.ts` under `mainPlugin.routesDir` default-exports an object with the HTTP methods it implements. **The file path is the URL** (`index.route.ts` → `/`, `api/users.route.ts` → `/api/users`). `expression` is appended to that path as is, in Express syntax (`/:id`, `{/:id}` for optional):
|
|
51
|
+
Each `*.route.ts` under `mainPlugin.routesDir` default-exports an object with the HTTP methods it implements (`GET`, `POST`, `PUT`, `DELETE`, `QUERY`). **The file path is the URL** (`index.route.ts` → `/`, `api/users.route.ts` → `/api/users`). `expression` is appended to that path as is, in Express syntax (`/:id`, `{/:id}` for optional):
|
|
50
52
|
|
|
51
53
|
```ts
|
|
52
54
|
export default createRoute({
|
|
@@ -83,7 +85,7 @@ Every option is optional.
|
|
|
83
85
|
| `mainPlugin` | `{ routesDir: "src/routes" }` | Your routes (`routesDir`, relative to `cwd`), `basePath` (e.g. `/api`, no trailing slash) and database: see [Database](#database). |
|
|
84
86
|
| `plugins` | `[]` | Plugins mounted around your routes, in order: see [Plugins](#plugins). |
|
|
85
87
|
|
|
86
|
-
`packages` accepts `morgan`, `cors`, `helmet`, `compression`, `rateLimit`, `express` (`express.json` options) and `
|
|
88
|
+
`packages` accepts `morgan`, `cors`, `helmet`, `compression`, `rateLimit`, `express` (`express.json` options), `urlencoded` and `betterAuth` (off by default: see [Better Auth](#better-auth)). The merge is **per section**: passing one key keeps the others; pass `false`/`undefined` to disable one.
|
|
87
89
|
|
|
88
90
|
```ts
|
|
89
91
|
createNanoApp({
|
|
@@ -98,11 +100,10 @@ createNanoApp({
|
|
|
98
100
|
|
|
99
101
|
## Database
|
|
100
102
|
|
|
101
|
-
Off until enabled:
|
|
103
|
+
Off until enabled: at startup nano-app generates the Prisma client of your schema, checks that its tables can be read and passes it to your handlers as their second parameter. **It never modifies your database**: applying the schema (`prisma db push`, `prisma migrate dev`, `prisma migrate deploy`) is up to you, with Prisma.
|
|
102
104
|
|
|
103
105
|
```bash
|
|
104
|
-
npm install @prisma/client @prisma/adapter-pg pg
|
|
105
|
-
npm install -D prisma
|
|
106
|
+
npm install prisma @prisma/client @prisma/adapter-pg pg # prisma too: the startup generates the client
|
|
106
107
|
```
|
|
107
108
|
|
|
108
109
|
```prisma
|
|
@@ -113,7 +114,7 @@ datasource db {
|
|
|
113
114
|
|
|
114
115
|
generator client {
|
|
115
116
|
provider = "prisma-client"
|
|
116
|
-
output = "./client"
|
|
117
|
+
output = "./client" // any value: nano-app generates in .nano-app/prisma-clients/app
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
model User {
|
|
@@ -122,11 +123,6 @@ model User {
|
|
|
122
123
|
}
|
|
123
124
|
```
|
|
124
125
|
|
|
125
|
-
```bash
|
|
126
|
-
npx nano-app generate # client in .nano-app/prisma-clients/app (add .nano-app/ to .gitignore)
|
|
127
|
-
npx nano-app push # generate + prisma db push; or any Prisma command: npx nano-app migrate dev …
|
|
128
|
-
```
|
|
129
|
-
|
|
130
126
|
```ts
|
|
131
127
|
// src/app.ts — DATABASE_URL comes from the environment (or a .env file)
|
|
132
128
|
createNanoApp({ mainPlugin: { database: { enabled: true } } });
|
|
@@ -144,18 +140,66 @@ export default createRoute<PrismaClient>({
|
|
|
144
140
|
|
|
145
141
|
| Option | Default | Description |
|
|
146
142
|
|---|---|---|
|
|
147
|
-
| `mainPlugin.database.enabled` | `false` |
|
|
148
|
-
| `mainPlugin.database.schemaPath` | `"src/prisma/schema.prisma"` |
|
|
149
|
-
|
|
150
|
-
- Each key falls back to its default, so `{ enabled: true }` is enough with the default layout.
|
|
151
|
-
-
|
|
152
|
-
- The
|
|
143
|
+
| `mainPlugin.database.enabled` | `false` | Generates and mounts your client at startup. |
|
|
144
|
+
| `mainPlugin.database.schemaPath` | `"src/prisma/schema.prisma"` | Your single `.prisma` file; its datasource must be `postgresql`. |
|
|
145
|
+
|
|
146
|
+
- Each key falls back to its default, so `{ enabled: true }` is enough with the default layout.
|
|
147
|
+
- The client lives in `.nano-app/prisma-clients/app/` (add `.nano-app/` to `.gitignore`). It is generated again only when the schema changes. Do not run `prisma generate`: a second client would be out of sync.
|
|
148
|
+
- The client exists after the first startup: start the app once before your editor or `tsc` can import its types. In a container, `.nano-app/` must be writable.
|
|
149
|
+
- Startup fails if `DATABASE_URL` is missing, the schema is not a valid PostgreSQL schema, or a table or column of a model cannot be read. The message says which: apply your schema with Prisma and start again.
|
|
150
|
+
- The `nano_` prefix is reserved for the official plugins (`@nano-app/plugins`): a datasource schema of yours starting with it fails the startup.
|
|
153
151
|
- Pass your generated `PrismaClient` to `createRoute<PrismaClient>` to type `db`; otherwise it is `any`, and without an enabled database `undefined`.
|
|
154
152
|
- For several PostgreSQL schemas, declare `schemas = ["public", "billing"]` in the datasource and `@@schema("billing")` on each model; one client covers them all.
|
|
153
|
+
- Prisma is loaded only when your database or a mounted plugin's is enabled.
|
|
154
|
+
|
|
155
|
+
## Better Auth
|
|
156
|
+
|
|
157
|
+
Users, sign-in and sessions with [Better Auth](https://www.better-auth.com), on your database. Off until `packages.betterAuth` gets its options (everything but `database`: nano-app passes your Prisma client).
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
npm install better-auth
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
// src/auth.ts: the options, and an instance only for the Better Auth CLI
|
|
165
|
+
import { betterAuth, type BetterAuthOptions } from "better-auth";
|
|
166
|
+
|
|
167
|
+
export const authOptions = { emailAndPassword: { enabled: true } } satisfies BetterAuthOptions;
|
|
168
|
+
export const auth = betterAuth(authOptions);
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
// src/app.ts
|
|
173
|
+
import { createNanoApp } from "@nano-app/backend";
|
|
174
|
+
import { authOptions } from "./auth";
|
|
175
|
+
|
|
176
|
+
createNanoApp({
|
|
177
|
+
packages: { betterAuth: authOptions },
|
|
178
|
+
mainPlugin: { database: { enabled: true } },
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Its tables are yours, like the rest of your schema. Add its models with its CLI, then apply them with Prisma; run both again when you change the options:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
npx auth generate --config src/auth.ts --adapter prisma --dialect postgresql --output src/prisma/schema.prisma
|
|
186
|
+
npx prisma migrate dev
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
- It needs the database: `packages.betterAuth` without `mainPlugin.database.enabled` fails at startup.
|
|
190
|
+
- Startup also fails if your schema lacks a model the options need (`user`, `session`, ...), naming them.
|
|
191
|
+
- Its endpoints are mounted with your routes, at its `basePath` (default `/api/auth`), and stay public.
|
|
192
|
+
- Every route of yours and of the `after` plugins needs a session: without one, 401. The `before` plugins stay public (a landing, an about page).
|
|
193
|
+
- Handlers and `onBefore` receive the session in `params.session` (`{ user, session }`).
|
|
194
|
+
- Sign-up works as Better Auth sets it: with `emailAndPassword` anyone can sign up and reach your routes. Close it with `disableSignUp: true`, or check roles in your handlers.
|
|
195
|
+
- Relate your models to `User` in the same schema, as any Prisma relation. Extra user fields go in its `user.additionalFields`.
|
|
196
|
+
- With several PostgreSQL schemas, add `@@schema(...)` to the generated models.
|
|
197
|
+
- Set `BETTER_AUTH_SECRET` and `BETTER_AUTH_URL` in the environment, as Better Auth asks.
|
|
198
|
+
- Better Auth is loaded only when it is on.
|
|
155
199
|
|
|
156
200
|
## Plugins
|
|
157
201
|
|
|
158
|
-
A plugin is a group of endpoints mounted under a base path. Your routes are mounted as one (named `app`). The official plugins are in [`@nano-app/plugins`](https://github.com/Nano-Nathan/nano-app/blob/main/plugins/README.md). You write one with `createPlugin` and list it in `plugins`. Nothing is mounted unless you list it.
|
|
202
|
+
A plugin is a group of endpoints mounted under a base path. Your routes are mounted as one (named `app`). The official plugins are in [`@nano-app/plugins`](https://github.com/Nano-Nathan/nano-app/blob/main/plugins/README.md). You write one with `createPlugin` and list it in `plugins`. Nothing is mounted unless you list it. Official plugins that have tables ship their own migrations: nano-app applies them at startup, each in its `nano_*` schema. That is the only change it makes to your database.
|
|
159
203
|
|
|
160
204
|
```ts
|
|
161
205
|
// src/plugins/hello/index.ts
|
|
@@ -216,12 +260,7 @@ The endpoints of one plugin have no guaranteed order: one route's `onInit` must
|
|
|
216
260
|
|
|
217
261
|
Everything is mounted on one Express application, in this order: base middlewares → `before` plugins → your routes → `after` plugins → 404 → error handler.
|
|
218
262
|
|
|
219
|
-
A plugin with
|
|
220
|
-
|
|
221
|
-
```bash
|
|
222
|
-
npx nano-app generate # the app schema (src/prisma/schema.prisma) → .nano-app/prisma-clients/app
|
|
223
|
-
npx nano-app push # generate + prisma db push
|
|
224
|
-
```
|
|
263
|
+
A plugin with a database follows the same rules, with its client in `.nano-app/prisma-clients/<name>`: a plugin of yours points `database.schemaPath` at its schema and you apply it with Prisma. If that folder holds the client of another schema (another plugin with the same name), the startup warns and replaces it. An official plugin of `@nano-app/plugins` needs nothing from you: at startup nano-app applies its migrations to its own `nano_*` schema. See [PLUGINS.md](https://github.com/Nano-Nathan/nano-app/blob/main/PLUGINS.md).
|
|
225
264
|
|
|
226
265
|
## Errors
|
|
227
266
|
|
|
@@ -248,8 +287,8 @@ Also exported: the configuration types (`NanoAppConfig`, `PackagesConfig`, `Plug
|
|
|
248
287
|
## Development
|
|
249
288
|
|
|
250
289
|
```bash
|
|
251
|
-
pnpm build #
|
|
252
|
-
pnpm dev #
|
|
290
|
+
pnpm build # tsdown → build/ (ESM + .d.ts)
|
|
291
|
+
pnpm dev # tsdown --watch
|
|
253
292
|
pnpm test # node:test against the real server (tsx --test)
|
|
254
293
|
DATABASE_URL=postgres://… pnpm test # also runs the PostgreSQL suite
|
|
255
294
|
```
|
package/build/index.d.ts
CHANGED
|
@@ -1,175 +1,188 @@
|
|
|
1
|
-
import express, { Request,
|
|
2
|
-
|
|
3
|
-
import { Options } from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** Whether the database is enabled. Defaults to false */
|
|
9
|
-
enabled?: boolean;
|
|
10
|
-
/** Prisma schema file (`.prisma`), relative to `cwd` */
|
|
11
|
-
schemaPath: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
1
|
+
import express, { Express, Request, Request as Request$1 } from "express";
|
|
2
|
+
import { CorsOptions } from "cors";
|
|
3
|
+
import { Options } from "express-rate-limit";
|
|
4
|
+
import "dotenv/config";
|
|
5
|
+
import "jiti";
|
|
6
|
+
import { BetterAuthOptions } from "better-auth";
|
|
7
|
+
//#region ../core/types/api.d.ts
|
|
14
8
|
/** API response */
|
|
15
9
|
type ApiResponse<T = any> = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
success?: boolean;
|
|
11
|
+
result?: T;
|
|
12
|
+
message?: string;
|
|
13
|
+
warning?: boolean;
|
|
20
14
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
message?: string;
|
|
25
|
-
warning?: boolean;
|
|
26
|
-
}>;
|
|
27
|
-
/** Query parameters sent in the `query` header (JSON). */
|
|
15
|
+
/** Promise of an API response, what a handler returns */
|
|
16
|
+
type ApiPromise<T = any> = Promise<ApiResponse<T>>;
|
|
17
|
+
/** Query parameters, sent as the JSON body of a `QUERY` request */
|
|
28
18
|
type QueryParams = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
skip?: number;
|
|
20
|
+
top?: number;
|
|
21
|
+
filter?: NanoObject;
|
|
22
|
+
orderby?: NanoObject<'asc' | 'desc'>;
|
|
23
|
+
select?: string;
|
|
34
24
|
};
|
|
35
|
-
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region ../core/types/objects.d.ts
|
|
36
27
|
/** Extra params of handlers and callbacks */
|
|
37
28
|
type Params<DB = any> = Partial<NanoObject & {
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
db?: DB;
|
|
30
|
+
onBeforeResult?: NanoObject;
|
|
31
|
+
/** `{ user, session }` of Better Auth, on the routes behind its guard */
|
|
32
|
+
session?: NanoObject;
|
|
40
33
|
}>;
|
|
41
34
|
/** Endpoint handlers */
|
|
42
|
-
type Handler<DB> = (req: Request, params: Params<DB>) => ApiPromise;
|
|
35
|
+
type Handler<DB> = (req: Request$1, params: Params<DB>) => ApiPromise;
|
|
43
36
|
type Handlers<DB = any> = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
GET?: Handler<DB>;
|
|
38
|
+
POST?: Handler<DB>;
|
|
39
|
+
PUT?: Handler<DB>;
|
|
40
|
+
DELETE?: Handler<DB>;
|
|
41
|
+
QUERY?: Handler<DB>;
|
|
48
42
|
};
|
|
49
43
|
/** Callbacks */
|
|
50
44
|
type Callback<DB> = (params: Params<DB>) => Promise<void>;
|
|
51
|
-
type CallbackMethod<DB> = (req: Request, method: string, params: Params<DB>) => Promise<NanoObject>;
|
|
45
|
+
type CallbackMethod<DB> = (req: Request$1, method: string, params: Params<DB>) => Promise<NanoObject>;
|
|
52
46
|
type CallbackMount<DB> = (app: Express, params: Params<DB>) => Promise<void>;
|
|
53
47
|
/** Callbacks of an endpoint. They never receive the app: what affects the whole app goes in the plugin's onMount */
|
|
54
48
|
type Callbacks<DB = any> = {
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
/** Run once, when the endpoint is mounted */
|
|
50
|
+
onInit?: Callback<DB>;
|
|
51
|
+
/** Run before the endpoint is executed */
|
|
52
|
+
onBefore?: CallbackMethod<DB>;
|
|
57
53
|
};
|
|
58
54
|
/** Callbacks of a plugin */
|
|
59
55
|
type PluginCallbacks<DB = any> = {
|
|
60
|
-
|
|
56
|
+
/** Run once with the Express app, after its database and before its endpoints (e.g. app-level middlewares) */
|
|
57
|
+
onMount?: CallbackMount<DB>;
|
|
61
58
|
};
|
|
62
59
|
/** Entry of a route file (`*.route.ts`) */
|
|
63
60
|
type RouteEntry<DB = any> = {
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
/** Express route expression appended to the path (e.g. `/:id`) */
|
|
62
|
+
expression?: string;
|
|
63
|
+
callbacks?: Callbacks<DB>;
|
|
66
64
|
} & Handlers<DB>;
|
|
65
|
+
/** Generic object */
|
|
67
66
|
type NanoObject<T = any> = Record<string, T>;
|
|
68
|
-
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/types/database.d.ts
|
|
69
|
+
/** Database client configuration. */
|
|
70
|
+
type DatabaseConfig = {
|
|
71
|
+
/** Whether the database is enabled. Defaults to false */
|
|
72
|
+
enabled?: boolean;
|
|
73
|
+
/** Prisma schema file (`.prisma`), relative to `cwd` */
|
|
74
|
+
schemaPath: string;
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/types/plugin.d.ts
|
|
69
78
|
/** When a plugin is mounted, relative to the consumer routes */
|
|
70
|
-
type PluginStage =
|
|
79
|
+
type PluginStage = 'before' | 'after';
|
|
71
80
|
/** Plugin configuration: a group of endpoints */
|
|
72
81
|
type PluginConfig<Options = NanoObject> = {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
/** Name of the plugin, same as his database (If have one) */
|
|
83
|
+
name: string;
|
|
84
|
+
/** Directory used to discover the `*.route.ts` files */
|
|
85
|
+
routesDir: string;
|
|
86
|
+
/** Base path prepended to every endpoint, e.g. "/auth" (no trailing slash). Defaults to none */
|
|
87
|
+
basePath?: string;
|
|
88
|
+
/** Mount point relative to the consumer routes. Defaults to "before" */
|
|
89
|
+
stage?: PluginStage;
|
|
90
|
+
/** Prisma client the plugin needs, mounted before its endpoints */
|
|
91
|
+
database?: DatabaseConfig;
|
|
92
|
+
/** Plugin options */
|
|
93
|
+
options?: Options;
|
|
94
|
+
/** Plugin callbacks */
|
|
95
|
+
callbacks?: PluginCallbacks;
|
|
87
96
|
};
|
|
88
97
|
/** The project's plugin: nano-app names it "app" and mounts it between the "before" and "after" plugins */
|
|
89
98
|
type MainPluginConfig<Options = NanoObject> = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
/** Directory of the project's `*.route.ts` files. Defaults to "src/routes" */
|
|
100
|
+
routesDir?: string;
|
|
101
|
+
/** Base path prepended to every route, e.g. "/api" (no trailing slash). Defaults to none */
|
|
102
|
+
basePath?: string;
|
|
103
|
+
/** The project's database */
|
|
104
|
+
database?: {
|
|
105
|
+
/** Whether the database is enabled. Defaults to false */
|
|
106
|
+
enabled?: boolean;
|
|
107
|
+
/** Prisma schema file, relative to `cwd`. Defaults to "src/prisma/schema.prisma" */
|
|
108
|
+
schemaPath?: string;
|
|
109
|
+
};
|
|
110
|
+
/** Plugin options */
|
|
111
|
+
options?: Options;
|
|
112
|
+
/** Plugin callbacks */
|
|
113
|
+
callbacks?: PluginCallbacks;
|
|
105
114
|
};
|
|
106
|
-
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/types/app.d.ts
|
|
107
117
|
/** Configuration of the framework's built-in packages */
|
|
108
118
|
type PackagesConfig = {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
119
|
+
/** Morgan configuration */
|
|
120
|
+
morgan?: false | {
|
|
121
|
+
/** Morgan tokens */
|
|
122
|
+
tokens?: NanoObject<any>;
|
|
123
|
+
/** Morgan format */
|
|
124
|
+
format: string;
|
|
125
|
+
};
|
|
126
|
+
/** CORS configuration */
|
|
127
|
+
cors?: CorsOptions | false;
|
|
128
|
+
/** Helmet configuration */
|
|
129
|
+
helmet?: boolean;
|
|
130
|
+
/** Compression configuration */
|
|
131
|
+
compression?: boolean;
|
|
132
|
+
/** Rate-limit configuration */
|
|
133
|
+
rateLimit?: Partial<Options> | false;
|
|
134
|
+
/** express.json configuration */
|
|
135
|
+
express?: Partial<Parameters<typeof express.json>[0]> | false;
|
|
136
|
+
/** urlencoded configuration */
|
|
137
|
+
urlencoded?: Partial<Parameters<typeof express.urlencoded>[0]> | false;
|
|
138
|
+
/** Better Auth options, without `database`: it uses the app's Prisma client. Defaults to false */
|
|
139
|
+
betterAuth?: Omit<BetterAuthOptions, 'database'> | false;
|
|
128
140
|
};
|
|
129
141
|
/** Application configuration */
|
|
130
142
|
type NanoAppConfig = {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
/** Listener run once the server is listening */
|
|
144
|
+
listener?: () => void;
|
|
145
|
+
/** Application port. Defaults to 3000 */
|
|
146
|
+
port?: number;
|
|
147
|
+
/** Values applied with Express `app.set()` (e.g. `{ "trust proxy": 1 }`) */
|
|
148
|
+
settings?: NanoObject<unknown>;
|
|
149
|
+
/** Default middlewares configuration */
|
|
150
|
+
packages?: PackagesConfig;
|
|
151
|
+
/** Plugins to mount. Defaults to [] */
|
|
152
|
+
plugins?: PluginConfig[];
|
|
153
|
+
/** Main plugin to mount. */
|
|
154
|
+
mainPlugin?: MainPluginConfig;
|
|
143
155
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
mainPlugin: PluginConfig;
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/app/config.d.ts
|
|
158
|
+
/** Merges the consumer configuration over the initial one; the main plugin is always named "app" */
|
|
159
|
+
declare function mergeConfig(oConfig?: NanoAppConfig): NanoAppConfig & Required<Pick<NanoAppConfig, 'settings' | 'plugins' | 'packages'>> & {
|
|
160
|
+
mainPlugin: PluginConfig;
|
|
150
161
|
};
|
|
151
|
-
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/app/NanoApp.d.ts
|
|
152
164
|
/** Main NanoApp class */
|
|
153
165
|
declare class NanoApp {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
166
|
+
protected oApp: Express;
|
|
167
|
+
protected oConfig: ReturnType<typeof mergeConfig>;
|
|
168
|
+
constructor(oConfig?: NanoAppConfig);
|
|
169
|
+
/** Starts the application */
|
|
170
|
+
private start;
|
|
171
|
+
/** Initializes the application in the right order */
|
|
172
|
+
private initialize;
|
|
173
|
+
/** Adds the packages according to the configuration */
|
|
174
|
+
private setPackages;
|
|
162
175
|
}
|
|
163
|
-
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/app/creators.d.ts
|
|
164
178
|
/** Creates a new NanoApp instance */
|
|
165
|
-
declare function createNanoApp(
|
|
179
|
+
export declare function createNanoApp(oConfig?: NanoAppConfig): NanoApp;
|
|
166
180
|
/** Creates and types a route object. */
|
|
167
|
-
declare function createRoute<DB>(
|
|
181
|
+
export declare function createRoute<DB>(oRoute: RouteEntry<DB>): RouteEntry<DB>;
|
|
168
182
|
/** Creates a plugin: a function of the plugin's own options that returns its configuration. */
|
|
169
183
|
type Creator<Options> = (options?: Options) => PluginConfig<Options>;
|
|
170
|
-
declare function createPlugin<Options>(
|
|
184
|
+
export declare function createPlugin<Options>(fnCreator: Creator<Options>): Creator<Options>;
|
|
171
185
|
/** Creates and types the callbacks of a plugin. */
|
|
172
|
-
declare function createPluginCallbacks<DB>(
|
|
173
|
-
|
|
174
|
-
export { NanoApp,
|
|
175
|
-
export type { ApiPromise, ApiResponse, Callbacks, DatabaseConfig, Handler, Handlers, MainPluginConfig, NanoAppConfig, NanoObject, PackagesConfig, Params, PluginCallbacks, PluginConfig, PluginStage, QueryParams, RouteEntry };
|
|
186
|
+
export declare function createPluginCallbacks<DB>(oCallbacks: PluginCallbacks<DB>): PluginCallbacks<DB>;
|
|
187
|
+
//#endregion
|
|
188
|
+
export { type ApiPromise, type ApiResponse, type Callbacks, type DatabaseConfig, type Handler, type Handlers, type MainPluginConfig, NanoApp, type NanoAppConfig, type NanoObject, type PackagesConfig, type Params, type PluginCallbacks, type PluginConfig, type PluginStage, type QueryParams, type Request, type RouteEntry };
|