@nano-app/backend 0.17.0 → 0.18.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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
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.
6
6
 
7
- - Node.js 22.23.4, 24.22.1 or 26.12.1 and newer. ESM only.
7
+ - Node.js 22.23.4, 24.22.1 or 26.12.1 and newer, or Bun 1.4.4 and newer (`bun src/app.ts`). ESM only.
8
8
  - Optional PostgreSQL layer through Drizzle. Off by default: without it no database code is loaded.
9
9
 
10
10
  ```bash
@@ -262,7 +262,7 @@ Two levels. Only the plugin's receives the Express app, so nothing app-wide depe
262
262
  |---|---|---|---|---|
263
263
  | Plugin (`callbacks` in its config) | `onMount` | Once, after its database and before its endpoints | `(app, params)` | App-level middlewares (a guard), shared setup |
264
264
  | Endpoint (`callbacks` in `createRoute`) | `onInit` | Once, when the endpoint is mounted | `(params)` | Setup of that route |
265
- | Endpoint | `onBefore` | Before every request the endpoint handles | `(req, method, params)` | Validate or load; its return value reaches the handler as `params.onBeforeResult` |
265
+ | Endpoint | `onBefore` | Before every request the endpoint handles | `(req, method, params)` | Validate or load; its return value reaches the handler as `params.onBeforeResult` (`{}` without `onBefore`) |
266
266
 
267
267
  ```ts
268
268
  export default createPlugin((options?: { publicPaths?: string[] }) => ({
@@ -305,7 +305,7 @@ GET /unknown // → 404 { success: false,
305
305
  | `createPlugin(creator)` | Types a plugin factory and its options. |
306
306
  | `createPluginCallbacks(callbacks)` | Types the callbacks of a plugin (`createPluginCallbacks<{ db: MyDb }>` types `db`), e.g. to keep them in their own file. |
307
307
 
308
- Also exported: the `NanoApp` class that `createNanoApp` returns, the configuration types (`NanoAppConfig`, `PackagesConfig`, `PluginConfig`, `PluginStage`, `MainPluginConfig`, `DatabaseConfig`), the Express `Request` type and the HTTP contract (`ApiResponse`, `ApiPromise`, `QueryParams`, `RouteEntry`, `Handler`, `Handlers`, `NanoObject`) and the callback types (`Params`, `Callbacks`, `PluginCallbacks`).
308
+ Also exported: the `NanoApp` class that `createNanoApp` returns, the configuration types (`NanoAppConfig`, `PackagesConfig`, `PluginConfig`, `PluginStage`, `MainPluginConfig`, `DatabaseConfig`), the Express `Request` type and the HTTP contract (`ApiResponse`, `ApiPromise`, `QueryParams`, `RouteEntry`, `Handler`, `HandlerParams`, `Handlers`, `NanoObject`) and the callback types (`Params`, `Callbacks`, `PluginCallbacks`).
309
309
 
310
310
  ## Development
311
311
 
package/build/index.d.ts CHANGED
@@ -30,12 +30,15 @@ type QueryParams = {
30
30
  type Params<Deps = NanoObject<any>> = Deps & {
31
31
  /** Better Auth's instance, when it is on */
32
32
  auth?: NanoObject;
33
- onBeforeResult?: NanoObject;
34
33
  /** `{ user, session }` of Better Auth, when the request has one */
35
34
  session?: NanoObject;
36
35
  };
36
+ /** Params of a handler: also what `onBefore` returned, `{}` without it */
37
+ type HandlerParams<Deps = NanoObject<any>> = Params<Deps> & {
38
+ onBeforeResult: NanoObject;
39
+ };
37
40
  /** Endpoint handler */
38
- type Handler<Deps> = (req: Request$1, params: Params<Deps>) => ApiPromise;
41
+ type Handler<Deps> = (req: Request$1, params: HandlerParams<Deps>) => ApiPromise;
39
42
  /** A method with its own permissions, instead of those of the route */
40
43
  type MethodEntry<Deps = NanoObject<any>> = {
41
44
  handler: Handler<Deps>;
@@ -176,4 +179,4 @@ export declare function createPlugin<Options>(fnCreator: Creator<Options>): Crea
176
179
  export declare function createPluginCallbacks<Deps = NanoObject<any>>(oCallbacks: PluginCallbacks<Deps>): PluginCallbacks<Deps>;
177
180
  /** Whether the session's user has the permissions; always without Better Auth or permissions */
178
181
  declare function isGranted({ auth, session }: Params, oPermissions?: NanoObject<string[]>): Promise<boolean>;
179
- export { type ApiPromise, type ApiResponse, type Callbacks, type DatabaseConfig, type Handler, type Handlers, type MainPluginConfig, type MethodEntry, NanoApp, type NanoAppConfig, NanoError, type NanoObject, type PackagesConfig, type Params, type PluginCallbacks, type PluginConfig, type PluginStage, type QueryParams, type Request, type RouteEntry, isGranted };
182
+ export { type ApiPromise, type ApiResponse, type Callbacks, type DatabaseConfig, type Handler, type HandlerParams, type Handlers, type MainPluginConfig, type MethodEntry, NanoApp, type NanoAppConfig, NanoError, type NanoObject, type PackagesConfig, type Params, type PluginCallbacks, type PluginConfig, type PluginStage, type QueryParams, type Request, type RouteEntry, isGranted };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nano-app/backend",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Express server with file-convention routes, plugins and an optional PostgreSQL layer",
5
5
  "type": "module",
6
6
  "main": "build/index.js",
@@ -40,7 +40,8 @@
40
40
  "access": "public"
41
41
  },
42
42
  "engines": {
43
- "node": "^22.23.4 || ^24.22.1 || >=26.12.1"
43
+ "node": "^22.23.4 || ^24.22.1 || >=26.12.1",
44
+ "bun": ">=1.4.4"
44
45
  },
45
46
  "dependencies": {
46
47
  "compression": "^1.8.2",