exisjs 0.7.12 → 0.7.14
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 +195 -39
- package/dist/cli/commands/run.d.ts.map +1 -1
- package/dist/cli/commands/run.js +3 -1
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/config/types.d.ts +2 -2
- package/dist/config/types.d.ts.map +1 -1
- package/dist/decorators/params.d.ts +21 -0
- package/dist/decorators/params.d.ts.map +1 -1
- package/dist/decorators/params.js +21 -1
- package/dist/decorators/params.js.map +1 -1
- package/dist/di/container.d.ts +15 -6
- package/dist/di/container.d.ts.map +1 -1
- package/dist/di/container.js +26 -3
- package/dist/di/container.js.map +1 -1
- package/dist/di/index.d.ts +1 -1
- package/dist/di/index.d.ts.map +1 -1
- package/dist/di/index.js.map +1 -1
- package/dist/di/inject.d.ts +2 -1
- package/dist/di/inject.d.ts.map +1 -1
- package/dist/di/inject.js +2 -1
- package/dist/di/inject.js.map +1 -1
- package/dist/docs/ARCHITECTURE.md +130 -78
- package/dist/docs/BENCHMARKS.md +4 -4
- package/dist/docs/content/README.md +43 -44
- package/dist/docs/content/boundaries.mdx +138 -61
- package/dist/docs/content/cli/commands.mdx +151 -128
- package/dist/docs/content/cli/overview.mdx +61 -47
- package/dist/docs/content/cli/usage.mdx +107 -30
- package/dist/docs/content/config.mdx +145 -158
- package/dist/docs/content/controllers.mdx +193 -464
- package/dist/docs/content/cron.mdx +183 -69
- package/dist/docs/content/decorators.mdx +449 -154
- package/dist/docs/content/errors.mdx +202 -305
- package/dist/docs/content/exisjs-mcp.mdx +59 -49
- package/dist/docs/content/installation.mdx +243 -157
- package/dist/docs/content/introduction.mdx +220 -48
- package/dist/docs/content/middleware.mdx +171 -497
- package/dist/docs/content/modules.mdx +141 -83
- package/dist/docs/content/providers.mdx +216 -180
- package/dist/docs/content/requests.mdx +168 -488
- package/dist/docs/content/responses.mdx +200 -533
- package/dist/docs/content/routing.mdx +235 -598
- package/dist/docs/content/security.mdx +233 -57
- package/dist/docs/content/structure.mdx +151 -240
- package/dist/docs/content/swagger.mdx +192 -91
- package/dist/docs/content/testing.mdx +205 -74
- package/dist/docs/content/validation.mdx +479 -341
- package/dist/docs/reference/README.md +34 -2
- package/dist/docs/reference/config.mdx +277 -75
- package/dist/docs/reference/context.mdx +197 -106
- package/dist/docs/reference/cron.mdx +266 -152
- package/dist/docs/reference/database.mdx +135 -53
- package/dist/docs/reference/decorators.mdx +234 -116
- package/dist/docs/reference/di.mdx +146 -112
- package/dist/docs/reference/error.mdx +155 -178
- package/dist/docs/reference/exis.mdx +141 -70
- package/dist/docs/reference/logger.mdx +110 -126
- package/dist/docs/reference/middleware.mdx +235 -158
- package/dist/docs/reference/plugin.mdx +136 -64
- package/dist/docs/reference/router.mdx +275 -293
- package/dist/docs/reference/sanitize.mdx +91 -87
- package/dist/docs/reference/swagger.mdx +280 -100
- package/dist/docs/reference/testing.mdx +223 -89
- package/dist/docs/reference/validator.mdx +194 -206
- package/dist/lib/start-server.js +22 -8
- package/dist/lib/start-server.js.map +1 -1
- package/dist/module/module.d.ts +6 -3
- package/dist/module/module.d.ts.map +1 -1
- package/dist/module/module.js +17 -3
- package/dist/module/module.js.map +1 -1
- package/dist/router/controller-registrar.d.ts.map +1 -1
- package/dist/router/controller-registrar.js +26 -4
- package/dist/router/controller-registrar.js.map +1 -1
- package/dist/router/scanner/fs-scanner.d.ts.map +1 -1
- package/dist/router/scanner/fs-scanner.js +22 -0
- package/dist/router/scanner/fs-scanner.js.map +1 -1
- package/dist/router/types.d.ts +6 -4
- package/dist/router/types.d.ts.map +1 -1
- package/dist/server/app.d.ts +3 -1
- package/dist/server/app.d.ts.map +1 -1
- package/dist/server/app.js +24 -8
- package/dist/server/app.js.map +1 -1
- package/dist/server/bootstrapper.d.ts.map +1 -1
- package/dist/server/bootstrapper.js +19 -0
- package/dist/server/bootstrapper.js.map +1 -1
- package/dist/server/request.d.ts +2 -0
- package/dist/server/request.d.ts.map +1 -1
- package/dist/server/request.js +11 -0
- package/dist/server/request.js.map +1 -1
- package/dist/server/response.d.ts +10 -5
- package/dist/server/response.d.ts.map +1 -1
- package/dist/server/response.js +65 -18
- package/dist/server/response.js.map +1 -1
- package/dist/swagger/generator.d.ts.map +1 -1
- package/dist/swagger/generator.js +130 -10
- package/dist/swagger/generator.js.map +1 -1
- package/dist/telemetry/index.d.ts +12 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +121 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/testing/client.d.ts +1 -0
- package/dist/testing/client.d.ts.map +1 -1
- package/dist/testing/client.js +4 -1
- package/dist/testing/client.js.map +1 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +11 -4
- package/dist/testing/index.js.map +1 -1
- package/dist/validator/builder.d.ts +26 -1
- package/dist/validator/builder.d.ts.map +1 -1
- package/dist/validator/builder.js +31 -0
- package/dist/validator/builder.js.map +1 -1
- package/dist/validator/engine.d.ts +23 -0
- package/dist/validator/engine.d.ts.map +1 -1
- package/dist/validator/engine.js +228 -31
- package/dist/validator/engine.js.map +1 -1
- package/dist/validator/index.d.ts +8 -4
- package/dist/validator/index.d.ts.map +1 -1
- package/dist/validator/index.js +4 -1
- package/dist/validator/index.js.map +1 -1
- package/dist/validator/tex-types.d.ts +19 -4
- package/dist/validator/tex-types.d.ts.map +1 -1
- package/dist/validator/tex-types.js +102 -0
- package/dist/validator/tex-types.js.map +1 -1
- package/dist/validator/tex.d.ts +1 -1
- package/dist/validator/tex.d.ts.map +1 -1
- package/dist/validator/tex.js +3 -1
- package/dist/validator/tex.js.map +1 -1
- package/dist/validator/types.d.ts +1 -0
- package/dist/validator/types.d.ts.map +1 -1
- package/package.json +46 -14
- package/dist/docs/content/dataloader.mdx +0 -170
- package/dist/docs/reference/dataloader.mdx +0 -91
|
@@ -1,113 +1,185 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
3
|
-
description: "API Reference for ExisJS
|
|
2
|
+
title: "exisjs/plugin"
|
|
3
|
+
description: "API Reference for ExisJS plugin system: definePlugin, ExisPlugin interface, dependencies, encapsulation, and lifecycle hooks."
|
|
4
|
+
nextUrl: "/docs/reference/exis"
|
|
5
|
+
nextTitle: "App Reference"
|
|
4
6
|
---
|
|
5
7
|
|
|
6
|
-
#
|
|
8
|
+
# `exisjs/plugin`
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
The `exisjs/plugin` module provides tools and interfaces for authoring, typing, and distributing reusable ExisJS plugins, middleware packages, and third-party integrations.
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Module Exports
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { definePlugin } from 'exisjs/plugin'
|
|
18
|
+
import type {
|
|
19
|
+
ExisPlugin,
|
|
20
|
+
ExisPluginInstance,
|
|
21
|
+
HookReady,
|
|
22
|
+
HookClose,
|
|
23
|
+
HookRequest,
|
|
24
|
+
HookResponse,
|
|
25
|
+
HookError,
|
|
26
|
+
HookRoute,
|
|
27
|
+
} from 'exisjs/plugin'
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 1. `definePlugin(plugin)`
|
|
33
|
+
|
|
34
|
+
The `definePlugin` helper wraps a plugin definition object and returns a hybrid callable object. This allows developers to register the plugin directly without options (`app.register(myPlugin)`) or invoke it as a factory function to pass configuration parameters (`app.register(myPlugin({ apiKey: '...' }))`).
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
function definePlugin<TOptions = Record<string, unknown>>(
|
|
38
|
+
plugin: ExisPlugin<TOptions>
|
|
39
|
+
): ExisPlugin<TOptions> & ((options?: TOptions) => ExisPluginInstance)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Parameters
|
|
43
|
+
|
|
44
|
+
| Parameter | Type | Description |
|
|
45
|
+
| :--- | :--- | :--- |
|
|
46
|
+
| `plugin` | `ExisPlugin<TOptions>` | Object conforming to the `ExisPlugin` specification. |
|
|
11
47
|
|
|
12
48
|
---
|
|
13
49
|
|
|
14
|
-
## `
|
|
50
|
+
## 2. `ExisPlugin<TOptions>` Interface
|
|
15
51
|
|
|
16
|
-
The
|
|
52
|
+
The core specification contract for all plugins:
|
|
17
53
|
|
|
18
|
-
|
|
54
|
+
| Property | Type | Default | Description |
|
|
55
|
+
| :--- | :--- | :--- | :--- |
|
|
56
|
+
| `name` | `string` | *(Required)* | Unique identifier for the plugin. Used to detect duplicate registrations. |
|
|
57
|
+
| `register` | `(app: App, options?: TOptions) => void \| Promise<void>` | *(Required)* | Lifecycle method executed during `app.register()`. |
|
|
58
|
+
| `version` | `string` | `undefined` | Semantic version string of the plugin package. |
|
|
59
|
+
| `dependencies` | `string[]` | `[]` | List of required plugin names that must be registered before this plugin boots. |
|
|
60
|
+
| `encapsulate` | `boolean` | `false` | When `true`, creates an isolated sub-router and dependency scope. |
|
|
19
61
|
|
|
20
|
-
|
|
62
|
+
---
|
|
21
63
|
|
|
22
|
-
|
|
64
|
+
## 3. Authoring Plugins
|
|
65
|
+
|
|
66
|
+
### Basic Plugin
|
|
67
|
+
|
|
68
|
+
```typescript filename="src/plugins/request-logger.plugin.ts"
|
|
23
69
|
import { definePlugin } from 'exisjs/plugin'
|
|
24
70
|
|
|
25
|
-
export const
|
|
26
|
-
name: '
|
|
71
|
+
export const requestLoggerPlugin = definePlugin({
|
|
72
|
+
name: 'custom-request-logger',
|
|
27
73
|
version: '1.0.0',
|
|
28
|
-
|
|
29
|
-
// The register function is called when app.register() is executed
|
|
74
|
+
|
|
30
75
|
async register(app) {
|
|
31
76
|
app.use((req, res, next) => {
|
|
32
|
-
|
|
77
|
+
app.log.info({ method: req.method, url: req.url }, 'Incoming request')
|
|
33
78
|
next()
|
|
34
79
|
})
|
|
35
|
-
}
|
|
80
|
+
},
|
|
36
81
|
})
|
|
37
82
|
```
|
|
38
83
|
|
|
39
|
-
|
|
84
|
+
---
|
|
40
85
|
|
|
41
|
-
|
|
86
|
+
### Configurable Generic Plugin with Lifecycle Teardown
|
|
42
87
|
|
|
43
|
-
```typescript filename="src/plugins/database.ts"
|
|
88
|
+
```typescript filename="src/plugins/database.plugin.ts"
|
|
44
89
|
import { definePlugin } from 'exisjs/plugin'
|
|
90
|
+
import { Pool } from 'pg'
|
|
45
91
|
|
|
46
|
-
interface
|
|
47
|
-
|
|
48
|
-
|
|
92
|
+
export interface DatabasePluginOptions {
|
|
93
|
+
connectionString: string
|
|
94
|
+
maxConnections?: number
|
|
49
95
|
}
|
|
50
96
|
|
|
51
|
-
export const databasePlugin = definePlugin<
|
|
52
|
-
name: '
|
|
53
|
-
|
|
97
|
+
export const databasePlugin = definePlugin<DatabasePluginOptions>({
|
|
98
|
+
name: 'postgres-database-plugin',
|
|
99
|
+
version: '1.2.0',
|
|
100
|
+
|
|
54
101
|
async register(app, options) {
|
|
55
|
-
if (!options?.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
102
|
+
if (!options?.connectionString) {
|
|
103
|
+
throw new Error('[databasePlugin] "connectionString" is required')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const pool = new Pool({
|
|
107
|
+
connectionString: options.connectionString,
|
|
108
|
+
max: options.maxConnections ?? 10,
|
|
109
|
+
})
|
|
59
110
|
|
|
60
|
-
|
|
61
|
-
app.provide('DB_CONNECTION', { useValue: db })
|
|
111
|
+
await pool.connect()
|
|
62
112
|
|
|
63
|
-
//
|
|
113
|
+
// Provide database pool to the DI container
|
|
114
|
+
app.provide('DB_POOL', { useValue: pool })
|
|
115
|
+
|
|
116
|
+
// Register graceful shutdown hook
|
|
64
117
|
app.onClose(async () => {
|
|
65
|
-
await
|
|
118
|
+
await pool.end()
|
|
66
119
|
})
|
|
67
|
-
}
|
|
120
|
+
},
|
|
68
121
|
})
|
|
69
122
|
```
|
|
70
123
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
### Plugin with Dependencies
|
|
127
|
+
|
|
128
|
+
```typescript filename="src/plugins/auth.plugin.ts"
|
|
129
|
+
import { definePlugin } from 'exisjs/plugin'
|
|
75
130
|
|
|
76
|
-
const
|
|
131
|
+
export const authPlugin = definePlugin({
|
|
132
|
+
name: 'auth-plugin',
|
|
133
|
+
dependencies: ['postgres-database-plugin'], // Guarantees DB is registered first
|
|
77
134
|
|
|
78
|
-
|
|
79
|
-
app.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
})
|
|
135
|
+
async register(app) {
|
|
136
|
+
const db = app.resolve('DB_POOL')
|
|
137
|
+
app.provide('AuthService', {
|
|
138
|
+
useFactory: () => new AuthService(db),
|
|
139
|
+
})
|
|
140
|
+
},
|
|
141
|
+
})
|
|
83
142
|
```
|
|
84
143
|
|
|
85
144
|
---
|
|
86
145
|
|
|
87
|
-
##
|
|
146
|
+
## 4. Registering Plugins in Applications
|
|
88
147
|
|
|
89
|
-
|
|
148
|
+
Plugins can be registered in `src/http/server.ts` using `app.register()` or statically declared in `exis.config.ts`:
|
|
90
149
|
|
|
91
|
-
###
|
|
150
|
+
### In `src/http/server.ts`
|
|
92
151
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
152
|
+
```typescript filename="src/http/server.ts"
|
|
153
|
+
import { exis } from 'exisjs'
|
|
154
|
+
import { databasePlugin } from '../plugins/database.plugin'
|
|
155
|
+
import { authPlugin } from '../plugins/auth.plugin'
|
|
156
|
+
|
|
157
|
+
export default exis({
|
|
158
|
+
async onStart(app) {
|
|
159
|
+
await app.register(
|
|
160
|
+
databasePlugin({
|
|
161
|
+
connectionString: process.env.DATABASE_URL!,
|
|
162
|
+
maxConnections: 20,
|
|
163
|
+
})
|
|
164
|
+
)
|
|
165
|
+
await app.register(authPlugin)
|
|
166
|
+
},
|
|
167
|
+
})
|
|
168
|
+
```
|
|
100
169
|
|
|
101
|
-
|
|
102
|
-
import type { ExisPlugin } from 'exisjs/plugin'
|
|
103
|
-
import type { App } from 'exisjs'
|
|
170
|
+
### In `exis.config.ts`
|
|
104
171
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
172
|
+
```typescript filename="exis.config.ts"
|
|
173
|
+
import { defineConfig } from 'exisjs/config'
|
|
174
|
+
import { databasePlugin } from './src/plugins/database.plugin'
|
|
175
|
+
import { authPlugin } from './src/plugins/auth.plugin'
|
|
108
176
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
177
|
+
export default defineConfig({
|
|
178
|
+
plugins: [
|
|
179
|
+
databasePlugin({
|
|
180
|
+
connectionString: process.env.DATABASE_URL!,
|
|
181
|
+
}),
|
|
182
|
+
authPlugin,
|
|
183
|
+
],
|
|
184
|
+
})
|
|
113
185
|
```
|