exisjs 0.5.10 → 0.5.11

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.
Files changed (157) hide show
  1. package/dist/auth/index.d.ts +3 -1
  2. package/dist/auth/index.d.ts.map +1 -1
  3. package/dist/auth/index.js +4 -1
  4. package/dist/auth/index.js.map +1 -1
  5. package/dist/auth/oauth/core.d.ts +96 -0
  6. package/dist/auth/oauth/core.d.ts.map +1 -0
  7. package/dist/auth/oauth/core.js +203 -0
  8. package/dist/auth/oauth/core.js.map +1 -0
  9. package/dist/auth/oauth/index.d.ts +45 -0
  10. package/dist/auth/oauth/index.d.ts.map +1 -0
  11. package/dist/auth/oauth/index.js +64 -0
  12. package/dist/auth/oauth/index.js.map +1 -0
  13. package/dist/auth/oauth/middleware.d.ts +63 -0
  14. package/dist/auth/oauth/middleware.d.ts.map +1 -0
  15. package/dist/auth/oauth/middleware.js +164 -0
  16. package/dist/auth/oauth/middleware.js.map +1 -0
  17. package/dist/auth/oauth/providers/custom.d.ts +41 -0
  18. package/dist/auth/oauth/providers/custom.d.ts.map +1 -0
  19. package/dist/auth/oauth/providers/custom.js +204 -0
  20. package/dist/auth/oauth/providers/custom.js.map +1 -0
  21. package/dist/auth/oauth/providers/discord.d.ts +23 -0
  22. package/dist/auth/oauth/providers/discord.d.ts.map +1 -0
  23. package/dist/auth/oauth/providers/discord.js +130 -0
  24. package/dist/auth/oauth/providers/discord.js.map +1 -0
  25. package/dist/auth/oauth/providers/facebook.d.ts +28 -0
  26. package/dist/auth/oauth/providers/facebook.d.ts.map +1 -0
  27. package/dist/auth/oauth/providers/facebook.js +124 -0
  28. package/dist/auth/oauth/providers/facebook.js.map +1 -0
  29. package/dist/auth/oauth/providers/github.d.ts +25 -0
  30. package/dist/auth/oauth/providers/github.d.ts.map +1 -0
  31. package/dist/auth/oauth/providers/github.js +132 -0
  32. package/dist/auth/oauth/providers/github.js.map +1 -0
  33. package/dist/auth/oauth/providers/google.d.ts +23 -0
  34. package/dist/auth/oauth/providers/google.d.ts.map +1 -0
  35. package/dist/auth/oauth/providers/google.js +134 -0
  36. package/dist/auth/oauth/providers/google.js.map +1 -0
  37. package/dist/auth/oauth/providers/microsoft.d.ts +28 -0
  38. package/dist/auth/oauth/providers/microsoft.d.ts.map +1 -0
  39. package/dist/auth/oauth/providers/microsoft.js +136 -0
  40. package/dist/auth/oauth/providers/microsoft.js.map +1 -0
  41. package/dist/auth/oauth/types.d.ts +158 -0
  42. package/dist/auth/oauth/types.d.ts.map +1 -0
  43. package/dist/auth/oauth/types.js +4 -0
  44. package/dist/auth/oauth/types.js.map +1 -0
  45. package/dist/cli/commands/dev.d.ts.map +1 -1
  46. package/dist/cli/commands/dev.js +0 -1
  47. package/dist/cli/commands/dev.js.map +1 -1
  48. package/dist/database/adapters/mongodb.d.ts +58 -0
  49. package/dist/database/adapters/mongodb.d.ts.map +1 -0
  50. package/dist/database/adapters/mongodb.js +264 -0
  51. package/dist/database/adapters/mongodb.js.map +1 -0
  52. package/dist/database/adapters/mysql.d.ts +27 -0
  53. package/dist/database/adapters/mysql.d.ts.map +1 -0
  54. package/dist/database/adapters/mysql.js +188 -0
  55. package/dist/database/adapters/mysql.js.map +1 -0
  56. package/dist/database/adapters/postgres.d.ts +28 -0
  57. package/dist/database/adapters/postgres.d.ts.map +1 -0
  58. package/dist/database/adapters/postgres.js +174 -0
  59. package/dist/database/adapters/postgres.js.map +1 -0
  60. package/dist/database/adapters/sqlite.d.ts +27 -0
  61. package/dist/database/adapters/sqlite.d.ts.map +1 -0
  62. package/dist/database/adapters/sqlite.js +149 -0
  63. package/dist/database/adapters/sqlite.js.map +1 -0
  64. package/dist/database/index.d.ts +42 -0
  65. package/dist/database/index.d.ts.map +1 -0
  66. package/dist/database/index.js +58 -0
  67. package/dist/database/index.js.map +1 -0
  68. package/dist/database/manager.d.ts +114 -0
  69. package/dist/database/manager.d.ts.map +1 -0
  70. package/dist/database/manager.js +269 -0
  71. package/dist/database/manager.js.map +1 -0
  72. package/dist/database/migration.d.ts +57 -0
  73. package/dist/database/migration.d.ts.map +1 -0
  74. package/dist/database/migration.js +329 -0
  75. package/dist/database/migration.js.map +1 -0
  76. package/dist/database/query-builder.d.ts +89 -0
  77. package/dist/database/query-builder.d.ts.map +1 -0
  78. package/dist/database/query-builder.js +353 -0
  79. package/dist/database/query-builder.js.map +1 -0
  80. package/dist/database/types.d.ts +184 -0
  81. package/dist/database/types.d.ts.map +1 -0
  82. package/dist/database/types.js +4 -0
  83. package/dist/database/types.js.map +1 -0
  84. package/dist/docs/ARCHITECTURE.md +349 -0
  85. package/dist/docs/BENCHMARKS.md +36 -0
  86. package/dist/docs/README.md +34 -0
  87. package/dist/docs/content/README.md +44 -0
  88. package/dist/docs/content/adapters.mdx +199 -0
  89. package/dist/docs/content/cache.mdx +239 -0
  90. package/dist/docs/content/circuit-breaker.mdx +130 -0
  91. package/dist/docs/content/cli/commands.mdx +214 -0
  92. package/dist/docs/content/cli/overview.mdx +92 -0
  93. package/dist/docs/content/cli/usage.mdx +61 -0
  94. package/dist/docs/content/config.mdx +214 -0
  95. package/dist/docs/content/controllers.mdx +241 -0
  96. package/dist/docs/content/cron.mdx +109 -0
  97. package/dist/docs/content/database.mdx +209 -0
  98. package/dist/docs/content/dataloader.mdx +170 -0
  99. package/dist/docs/content/decorators.mdx +204 -0
  100. package/dist/docs/content/errors.mdx +344 -0
  101. package/dist/docs/content/gateways.mdx +376 -0
  102. package/dist/docs/content/installation.mdx +210 -0
  103. package/dist/docs/content/introduction.mdx +96 -0
  104. package/dist/docs/content/middleware.mdx +441 -0
  105. package/dist/docs/content/modules.mdx +144 -0
  106. package/dist/docs/content/oauth.mdx +179 -0
  107. package/dist/docs/content/providers.mdx +147 -0
  108. package/dist/docs/content/queues.mdx +177 -0
  109. package/dist/docs/content/requests.mdx +293 -0
  110. package/dist/docs/content/responses.mdx +271 -0
  111. package/dist/docs/content/routing.mdx +541 -0
  112. package/dist/docs/content/rpc.mdx +146 -0
  113. package/dist/docs/content/security.mdx +294 -0
  114. package/dist/docs/content/sse.mdx +159 -0
  115. package/dist/docs/content/structure.mdx +116 -0
  116. package/dist/docs/content/testing.mdx +139 -0
  117. package/dist/docs/content/validation.mdx +249 -0
  118. package/dist/docs/content/websockets.mdx +289 -0
  119. package/dist/docs/integrations/README.md +23 -0
  120. package/dist/docs/integrations/jwt.mdx +151 -0
  121. package/dist/docs/integrations/mongo.mdx +183 -0
  122. package/dist/docs/integrations/observability.mdx +125 -0
  123. package/dist/docs/integrations/openai.mdx +108 -0
  124. package/dist/docs/integrations/postgres.mdx +190 -0
  125. package/dist/docs/integrations/posthog.mdx +122 -0
  126. package/dist/docs/integrations/redis.mdx +141 -0
  127. package/dist/docs/integrations/resend.mdx +117 -0
  128. package/dist/docs/integrations/s3.mdx +122 -0
  129. package/dist/docs/integrations/swagger.mdx +113 -0
  130. package/dist/docs/reference/README.md +3 -0
  131. package/dist/docs/reference/adapters.mdx +130 -0
  132. package/dist/docs/reference/auth.mdx +183 -0
  133. package/dist/docs/reference/cache.mdx +132 -0
  134. package/dist/docs/reference/circuit-breaker.mdx +71 -0
  135. package/dist/docs/reference/config.mdx +118 -0
  136. package/dist/docs/reference/context.mdx +168 -0
  137. package/dist/docs/reference/dataloader.mdx +91 -0
  138. package/dist/docs/reference/decorators.mdx +293 -0
  139. package/dist/docs/reference/di.mdx +123 -0
  140. package/dist/docs/reference/error.mdx +170 -0
  141. package/dist/docs/reference/exis.mdx +124 -0
  142. package/dist/docs/reference/middleware.mdx +304 -0
  143. package/dist/docs/reference/plugin.mdx +113 -0
  144. package/dist/docs/reference/queue.mdx +155 -0
  145. package/dist/docs/reference/router.mdx +248 -0
  146. package/dist/docs/reference/sanitize.mdx +130 -0
  147. package/dist/docs/reference/storage.mdx +116 -0
  148. package/dist/docs/reference/swagger.mdx +132 -0
  149. package/dist/docs/reference/testing.mdx +145 -0
  150. package/dist/docs/reference/validator.mdx +186 -0
  151. package/dist/index.d.ts +4 -0
  152. package/dist/index.d.ts.map +1 -1
  153. package/dist/index.js +10 -1
  154. package/dist/index.js.map +1 -1
  155. package/dist/server/bootstrapper.js +1 -1
  156. package/dist/server/bootstrapper.js.map +1 -1
  157. package/package.json +8 -1
@@ -0,0 +1,214 @@
1
+ ---
2
+ nextUrl: "/docs"
3
+ nextTitle: "Introduction"
4
+ ---
5
+
6
+ # CLI command reference
7
+
8
+ ### `exisjs init`
9
+
10
+ Creates a new ExisJS project.
11
+
12
+ ```bash
13
+ $ npx exisjs init
14
+ ```
15
+
16
+ **Description**
17
+ Creates and initializes a new ExisJS project. Prompts for configuration options (such as whether to include TypeScript, ESLint, Database integrations, etc.) and generates a boilerplate project structure for you.
18
+
19
+ ---
20
+
21
+ ### `exisjs generate`
22
+
23
+ Generates and/or modifies files based on a schematic.
24
+
25
+ ```bash
26
+ $ npx exisjs generate <type> <name> [options]
27
+ $ npx exisjs g <type> <name> [options]
28
+ ```
29
+
30
+ **Description**
31
+ Generates new features for your application, such as routes, plugins, middleware, or tests.
32
+
33
+ **Arguments**
34
+
35
+ | Argument | Description |
36
+ | :--- | :--- |
37
+ | `<type>` | The type of the feature to generate. See the Schematics table below. |
38
+ | `<name>` | The name of the generated component. |
39
+
40
+ **Options**
41
+
42
+ | Option | Description |
43
+ | :--- | :--- |
44
+ | `--oop` | Generate using Class-Based (OOP) paradigm instead of Functional. |
45
+
46
+ **Schematics**
47
+
48
+ | Name | Alias | Description |
49
+ | :--- | :--- | :--- |
50
+ | `route` | `r` | Generates a new Route controller. |
51
+ | `plugin` | `p` | Generates a new ExisJS Plugin module. |
52
+ | `middleware` | `m` | Generates a new Middleware function. |
53
+ | `test` | `t` | Generates a new test suite file. |
54
+
55
+ ---
56
+
57
+ ### `exisjs build`
58
+
59
+ Compiles an application or workspace into an output folder.
60
+
61
+ ```bash
62
+ $ npx exisjs build [options]
63
+ ```
64
+
65
+ **Description**
66
+ Compiles TypeScript to production JavaScript.
67
+
68
+ **Options**
69
+
70
+ | Option | Description |
71
+ | :--- | :--- |
72
+ | `-o, --out-dir <dir>` | Output directory (default: dist). |
73
+ | `--no-clean` | Skip cleaning the output directory. |
74
+
75
+ ---
76
+
77
+ ### `exisjs start`
78
+
79
+ Compiles and runs an application from the compiled `dist` directory.
80
+
81
+ ```bash
82
+ $ npx exisjs start [options]
83
+ ```
84
+
85
+ **Description**
86
+ Starts the production server by executing the compiled application entry file.
87
+
88
+ **Options**
89
+
90
+ | Option | Description |
91
+ | :--- | :--- |
92
+ | `-p, --port <port>` | Port to listen on (overrides `.env`). |
93
+ | `-e, --entry <file>` | Custom compiled entry file path (default: `dist/http/server.js`). |
94
+
95
+ ---
96
+
97
+ ### `exisjs dev`
98
+
99
+ Starts the development server with Hot Module Replacement (HMR) and automatic restarts.
100
+
101
+ ```bash
102
+ $ npx exisjs dev [options]
103
+ ```
104
+
105
+ **Description**
106
+ Starts the development server and handles TypeScript compilation on the fly.
107
+ - **Port Detection:** If your requested port is already in use by another process, it detects the collision, automatically increments the port, and binds to the next available one.
108
+ - **Lazy Routing (.exis):** ExisJS leverages the hidden `.exis` folder during development to lazy-load routes on demand.
109
+
110
+ **Options**
111
+
112
+ | Option | Description |
113
+ | :--- | :--- |
114
+ | `-p, --port <port>` | Port to listen on (overrides `.env`). |
115
+ | `-h, --host <host>` | Host to bind to. |
116
+ | `-e, --entry <file>` | Custom entry file path (default: `src/http/server.ts`). |
117
+
118
+ ---
119
+
120
+ ### `exisjs test`
121
+
122
+ Runs the native Node.js test runner (`node:test`) across your project.
123
+
124
+ ```bash
125
+ $ npx exisjs test [files...] [options]
126
+ ```
127
+
128
+ **Description**
129
+ Automatically sets up the ExisJS environment and parses TypeScript natively to run tests using the built-in `node:test` runner.
130
+
131
+ **Arguments**
132
+
133
+ | Argument | Description |
134
+ | :--- | :--- |
135
+ | `[files...]` | Specific test files or directories to run (optional). |
136
+
137
+ **Options**
138
+
139
+ | Option | Description |
140
+ | :--- | :--- |
141
+ | `--watch` | Watch for file changes and re-run tests. |
142
+ | `-u, --update` | Update test snapshots. |
143
+ | `-e, --entry <file>` | Custom entry file path to bootstrap before tests. |
144
+
145
+ ---
146
+
147
+ ### `exisjs routes`
148
+
149
+ Analyzes your application and prints a tabular representation of your entire routing table to the terminal.
150
+
151
+ ```bash
152
+ $ npx exisjs routes [options]
153
+ ```
154
+
155
+ **Description**
156
+ Loads your application context and outputs a formatted table showing all registered HTTP routes.
157
+
158
+ **Options**
159
+
160
+ | Option | Description |
161
+ | :--- | :--- |
162
+ | `-e, --entry <file>` | Custom entry file path to bootstrap the app from. |
163
+
164
+ ---
165
+
166
+ ### `exisjs repl`
167
+
168
+ Starts an interactive Read-Eval-Print Loop (REPL) console loaded with your application's context.
169
+
170
+ ```bash
171
+ $ npx exisjs repl [options]
172
+ $ npx exisjs console [options]
173
+ ```
174
+
175
+ **Description**
176
+ Provides an interactive command-line environment with direct access to your application's database, plugins, and services.
177
+
178
+ **Options**
179
+
180
+ | Option | Description |
181
+ | :--- | :--- |
182
+ | `-e, --entry <file>` | Custom entry file path to bootstrap the app from. |
183
+
184
+ ---
185
+
186
+ ### `exisjs exports`
187
+
188
+ Lists all the available framework exports and public APIs exposed by ExisJS.
189
+
190
+ ```bash
191
+ $ npx exisjs exports
192
+ ```
193
+
194
+ **Description**
195
+ Outputs a list of everything that can be imported from the `exisjs` package.
196
+
197
+ ---
198
+
199
+ ### `exisjs info`
200
+
201
+ Displays environment and version information for debugging and bug reporting.
202
+
203
+ ```bash
204
+ $ npx exisjs info
205
+ ```
206
+
207
+ **Description**
208
+ Prints out the current ExisJS version, Node.js version, platform, and architecture.
209
+
210
+ ---
211
+
212
+ ## Requirements
213
+
214
+ ExisJS CLI requires a Node.js binary. We recommend Node.js v20+ to ensure compatibility with modern native features (like the built-in test runner).
@@ -0,0 +1,92 @@
1
+ ---
2
+ nextUrl: "/docs/cli/usage"
3
+ nextTitle: "CLI Usage"
4
+ ---
5
+
6
+ # Overview
7
+
8
+ The ExisJS CLI is a command-line interface tool that helps you initialize, develop, and maintain your ExisJS applications. It assists in scaffolding the project, serving it in development mode, and building the application for production.
9
+
10
+ An ExisJS application is a standard TypeScript application that needs to be compiled to JavaScript before execution. The CLI provides a standard build and execute process with reasonable defaults, while ensuring developers can access the underlying tools (like `tsc` and `node`) to customize them if necessary.
11
+
12
+ ## Installation
13
+
14
+ You have several options available for managing how your OS command line resolves the location of the `exisjs` binary file.
15
+
16
+ You can install the CLI globally using the `npm install -g` command. This provides convenience and ensures the `exisjs` binary is available across your system.
17
+
18
+ ```bash
19
+ $ npm install -g exisjs
20
+ ```
21
+
22
+ > [!NOTE]
23
+ > Alternatively, you can use `npx exisjs` to run the CLI without installing it globally. This ensures you run the latest version or a managed local version.
24
+
25
+ ## Basic workflow
26
+
27
+ Once installed, you can invoke CLI commands directly from your OS command line through the `exisjs` executable. See the available commands by entering the following:
28
+
29
+ ```bash
30
+ $ exisjs --help
31
+ ```
32
+
33
+ Get help on an individual command using the `--help` flag. Substitute any command to get detailed help:
34
+
35
+ ```bash
36
+ $ exisjs generate --help
37
+ ```
38
+
39
+ To create, build, and run a new basic ExisJS project in development mode, navigate to the folder that should be the parent of your new project, and run the following commands:
40
+
41
+ ```bash
42
+ $ exisjs init my-project
43
+ $ cd my-project
44
+ $ npm run dev
45
+ ```
46
+
47
+ In your browser, open `http://localhost:3000` to see the new application running. The application will automatically recompile and reload when you change any source files.
48
+
49
+ ## CLI command syntax
50
+
51
+ All `exisjs` commands follow the same format:
52
+
53
+ ```bash
54
+ exisjs <command> [arguments] [options]
55
+ ```
56
+
57
+ For example:
58
+
59
+ ```bash
60
+ $ exisjs generate route users --oop
61
+ ```
62
+
63
+ Here, `generate` is the command, `route` and `users` are the arguments, and `--oop` is the option.
64
+
65
+ Most commands and some options have aliases. For example, `generate` can be invoked as `g`:
66
+
67
+ ```bash
68
+ $ exisjs g route users --oop
69
+ ```
70
+
71
+ ## Command overview
72
+
73
+ Run `exisjs <command> --help` for any of the following commands to see command-specific options.
74
+
75
+ See [CLI Commands](/docs/cli/commands) for detailed descriptions of each command.
76
+
77
+ | Command | Alias | Description |
78
+ | :--- | :--- | :--- |
79
+ | `init` | | Creates and initializes a new ExisJS project. |
80
+ | `generate` | `g` | Generates features based on schematics (routes, plugins, etc.). |
81
+ | `build` | | Compiles an application into an output folder. |
82
+ | `start` | | Runs an application from the compiled directory. |
83
+ | `dev` | | Starts the development server with hot module replacement. |
84
+ | `test` | | Runs the native Node.js test runner across your project. |
85
+ | `routes` | | Prints a tabular representation of your routing table. |
86
+ | `repl` | `console` | Starts an interactive REPL console loaded with your application context. |
87
+ | `exports` | | Lists all available framework exports. |
88
+ | `info` | | Displays environment and version information. |
89
+
90
+ ## Requirements
91
+
92
+ The ExisJS CLI requires a Node.js binary. We recommend Node.js v20+ to ensure compatibility with modern native features, such as the built-in test runner.
@@ -0,0 +1,61 @@
1
+ ---
2
+ nextUrl: "/docs/cli/commands"
3
+ nextTitle: "CLI Commands"
4
+ ---
5
+
6
+ # CLI Usage
7
+
8
+ The ExisJS CLI can be executed in two primary contexts: **globally** via your operating system's PATH, or **locally** via your project's `package.json` scripts. Understanding the distinction between these execution contexts is critical for maintaining stable development environments.
9
+
10
+ ## Global vs. Local Execution
11
+
12
+ When you install the CLI globally (`npm install -g exisjs`) or run it on-demand via `npx`, the binary operates outside of your project's dependency tree. While this is necessary for initializing new projects, it presents a challenge for long-term maintenance: if two developers have different global versions of the CLI installed, they may experience inconsistent build outputs or behavior.
13
+
14
+ To solve this, ExisJS manages its build and execution tools as **local development dependencies**. When you run `exisjs init`, the framework automatically installs the `exisjs` package into your `node_modules` and wires it up to your `package.json` scripts.
15
+
16
+ By executing the CLI through `npm run`, npm automatically resolves the binary to the exact version pinned in your `package.json`, ensuring deterministic behavior across your entire engineering team and CI/CD pipelines.
17
+
18
+ ## Default Package Scripts
19
+
20
+ Every ExisJS project is scaffolded with a standard set of `package.json` scripts that wrap the underlying CLI commands:
21
+
22
+ ```json
23
+ {
24
+ "scripts": {
25
+ "dev": "exisjs dev",
26
+ "build": "exisjs build",
27
+ "start": "exisjs start",
28
+ "test": "exisjs test"
29
+ }
30
+ }
31
+ ```
32
+
33
+ You invoke these scripts using your package manager:
34
+
35
+ ```bash
36
+ $ npm run dev
37
+ $ npm run build
38
+ $ npm run start
39
+ ```
40
+
41
+ ## Passing Arguments via Scripts
42
+
43
+ If you need to pass additional arguments or options to the CLI while using package scripts, append a double-dash (`--`) before the CLI options. This instructs npm to pass the remaining arguments directly to the underlying `exisjs` command.
44
+
45
+ For example, to start the development server on a custom port:
46
+
47
+ ```bash
48
+ $ npm run dev -- --port 4000
49
+ ```
50
+
51
+ To generate a new route using `npx` (which bypasses the script requirement while still using the local binary):
52
+
53
+ ```bash
54
+ $ npx exisjs generate route users
55
+ ```
56
+
57
+ ## Recommended Workflow
58
+
59
+ 1. Use the global CLI (or `npx exisjs`) **only** for scaffolding new projects (`exisjs init`).
60
+ 2. Use the `package.json` scripts (e.g., `npm run dev`) for all day-to-day development, building, and testing.
61
+ 3. Use `npx exisjs` inside an existing project directory for one-off commands (like `generate`, `routes`, or `repl`).
@@ -0,0 +1,214 @@
1
+ ---
2
+ nextUrl: '/docs/routing'
3
+ nextTitle: 'Routing'
4
+ ---
5
+
6
+ # Configuration (`exis.config.ts`)
7
+
8
+ ExisJS uses a fully typed configuration engine that closely resembles Vite or Next.js.
9
+
10
+ By placing an `exis.config.ts` file in the root of your project, you gain complete control over the underlying server (Node.js or uWebSockets), middleware (CORS, Helmet, Compression), SSL, and the Plugin ecosystem.
11
+
12
+ ---
13
+
14
+ ## 1. Basic Configuration
15
+
16
+ A basic configuration simply exports the result of `defineConfig`. This provides TypeScript autocomplete for all available options.
17
+
18
+ ```typescript filename="exis.config.ts"
19
+ import { defineConfig } from 'exisjs/config'
20
+
21
+ export default defineConfig({
22
+ port: 4000,
23
+ host: '0.0.0.0',
24
+
25
+ cors: {
26
+ origin: '*',
27
+ credentials: true,
28
+ },
29
+
30
+ logger: {
31
+ level: 'debug',
32
+ pretty: true,
33
+ },
34
+ })
35
+ ```
36
+
37
+ ---
38
+
39
+ ## 2. Dynamic & Phase-Based Config
40
+
41
+ Often, you'll need different configurations for Development, Production, or Testing (e.g., enabling pretty logging only in development, or changing the Database URL).
42
+
43
+ ExisJS allows you to export an `async function` that provides the current `phase` (Environment).
44
+
45
+ ```typescript filename="exis.config.ts"
46
+ import { defineConfig, PHASE_DEVELOPMENT_SERVER } from 'exisjs/config'
47
+
48
+ export default async (phase: string, { defaultConfig }: any) => {
49
+ const isDev = phase === PHASE_DEVELOPMENT_SERVER
50
+
51
+ return defineConfig({
52
+ port: Number(process.env.PORT) || 4000,
53
+
54
+ // Enable pretty logging only in Development
55
+ logger: isDev ? { level: 'debug', pretty: true } : false,
56
+
57
+ // Compress responses in Production
58
+ compression: !isDev,
59
+ })
60
+ }
61
+ ```
62
+
63
+ The available phases are:
64
+
65
+ - `PHASE_DEVELOPMENT_SERVER` (Triggered via `exis dev`)
66
+ - `PHASE_PRODUCTION_SERVER` (Triggered via `exis start`)
67
+ - `PHASE_TEST` (Triggered when `NODE_ENV=test`)
68
+
69
+ ---
70
+
71
+ ## 3. Type-Safe Environment Variables
72
+
73
+ We highly recommend using `v.env()` from `exisjs/validator` to strongly type and validate your environment variables before the server starts. You can create an `env.ts` file and import it directly into your `exis.config.ts`.
74
+
75
+ ```typescript filename="env.ts"
76
+ import { tex } from 'exisjs/validator'
77
+
78
+ export const env = tex.object({
79
+ PORT: tex.number({ coerce: true, optional: true }),
80
+ NODE_ENV: tex.string({ optional: true }),
81
+ MONGODB_URI: tex.string(),
82
+ }).parse(process.env)
83
+ ```
84
+
85
+ ```typescript filename="exis.config.ts"
86
+ import { defineConfig } from 'exisjs/config'
87
+ import { env } from './env.ts' // Fails fast if variables are missing!
88
+
89
+ export default defineConfig({
90
+ port: env.PORT,
91
+ logger: {
92
+ pretty: env.NODE_ENV !== 'production',
93
+ },
94
+ })
95
+ ```
96
+
97
+ ---
98
+
99
+ ## 4. Background Jobs & Workers
100
+
101
+ To enable the background job engine (which powers scheduled Cron jobs and the task queue), you must explicitly configure a `queue` driver in `exis.config.ts`.
102
+
103
+ If this is missing, the job scheduler is completely disabled to save memory.
104
+
105
+ ```typescript filename="exis.config.ts"
106
+ export default defineConfig({
107
+ queue: {
108
+ driver: 'memory', // Use 'redis' for multi-server production
109
+ enableWorkers: true, // Set to false to push jobs but not process them
110
+ },
111
+ })
112
+ ```
113
+
114
+ ---
115
+
116
+ ## 5. The Underlying Server Engine
117
+
118
+ By default, ExisJS uses the native Node.js HTTP/HTTPS modules. However, you can seamlessly switch the underlying engine to **uWebSockets.js (uWS)** for significantly higher throughput.
119
+
120
+ ```typescript filename="exis.config.ts"
121
+ export default defineConfig({
122
+ // 'auto' will use uWS if installed, otherwise gracefully fallback to Node
123
+ server: 'auto', // 'auto' | 'node' | 'bun'
124
+ })
125
+ ```
126
+
127
+ ---
128
+
129
+ ## 6. Complete Options Reference
130
+
131
+ Here is a full breakdown of the configuration schema:
132
+
133
+ ### Network & SSL
134
+
135
+ - `port` _(number)_: The port the server will bind to. (Default: `4000`)
136
+ - `host` _(string)_: The host interface to bind to. (Default: `'0.0.0.0'`)
137
+ - `ssl` _(object)_: Provide `{ key, cert }` strings or Buffers to enable HTTPS natively.
138
+ - `http2` _(boolean)_: Enables HTTP/2 support natively. (Defaults to `true` when SSL is provided).
139
+ - `redirectHttp` _(boolean | number)_: Automatically intercepts HTTP requests and redirects them to HTTPS.
140
+
141
+ ### Global Middleware
142
+
143
+ - `cors` _(object | boolean)_: Global CORS policy configuration (`origin`, `methods`, `credentials`, etc.).
144
+ - `helmet` _(object | boolean)_: Automatically secures your app with standard HTTP headers. (Enabled by default).
145
+ - `compression` _(object | boolean)_: Enables Gzip/Brotli compression for all HTTP responses.
146
+ - `logger` _(object | boolean)_: Configures the internal Pino-based logger (`level`, `pretty`).
147
+ - `etag` _(boolean)_: Automatically generates ETag headers for cache-invalidation.
148
+
149
+ ### Performance & Security
150
+
151
+ - `bodyLimit` _(number)_: The maximum allowed size (in bytes) for incoming request bodies. (Default: `1MB`)
152
+ - `trustProxy` _(boolean | number)_: If true, respects `X-Forwarded-For` and `X-Forwarded-Host` headers (essential for apps deployed behind NGINX, Cloudflare, or AWS ELB). If a number, trusts that many hops.
153
+ - `keepAlive` _(object | boolean)_: Tunes the Keep-Alive timeout and Header timeout limits.
154
+ - `workers` _(number | 'safe' | 'max')_: Number of CPU workers for cluster mode. Defaults to 1. 'safe' caps to 2. 'max' uses all available cores.
155
+
156
+ ### Execution & Debugging
157
+
158
+ - `env` _(string)_: Overrides the environment. Can be 'development', 'production', or 'test'.
159
+ - `server` _('auto' | 'node' | 'uws')_: Server backend to use. Defaults to 'node'.
160
+ - `debugRouting` _(boolean)_: Enables detailed logging of the resolved route file and applied gateways for every incoming request.
161
+ - `test` _(object)_: Configuration for the native test runner (`include`, `exclude`, `setupFiles`, `concurrency`, `coverage`).
162
+
163
+ ### Queues & Plugins
164
+
165
+ - `queue` _(object)_: Configures the Global Job Queue driver (`memory` or `redis`) and backpressure settings.
166
+ - `plugins` _(array)_: Registers framework-level plugins.
167
+
168
+ ---
169
+
170
+ ## 7. ExisJS Plugin Ecosystem
171
+
172
+ The ExisJS configuration file is also where you integrate native plugins and modules.
173
+
174
+ You can easily build your own plugins using `defineModule` from `exisjs/module`. Under the hood, plugins get full access to the `app` instance to register routes, providers, or lifecycle hooks!
175
+
176
+ ```typescript filename="exis.config.ts"
177
+ import { defineConfig } from 'exisjs/config'
178
+ import { defineModule } from 'exisjs/module'
179
+
180
+ // 1. Create a custom plugin (e.g., a mock GraphQL endpoint)
181
+ const graphqlPlugin = (options: { endpoint: string }) =>
182
+ defineModule({
183
+ name: 'graphql',
184
+ routes: (app) => {
185
+ app.post(options.endpoint, (req, res) =>
186
+ res.json({ data: 'GraphQL Response' })
187
+ )
188
+ },
189
+ })
190
+
191
+ // 2. Register it in your config
192
+ export default defineConfig({
193
+ plugins: [graphqlPlugin({ endpoint: '/graphql' })],
194
+ })
195
+ ```
196
+
197
+ ---
198
+
199
+ ## 8. Process Model & Multi-Tenancy
200
+
201
+ ExisJS expects a **One App Per Process** architecture.
202
+
203
+ ### Zero-Config Singletons
204
+
205
+ ExisJS's highly ergonomic integrations (e.g., `redis.ts`, `prisma.ts`, `s3.ts`) are implemented using ES6 Proxies that cache the underlying clients at the module level. This means they are **process-wide singletons**.
206
+ If you attempt to mount multiple `App` instances inside a single Node.js process to serve different tenants, they will **share the exact same database connections, redis pools, and caches**.
207
+
208
+ ### Multi-Tenant Guidance
209
+
210
+ If you are building a multi-tenant B2B application, do not boot multiple ExisJS `App` instances per tenant. Instead, use one of the following standard approaches:
211
+
212
+ 1. **Row-Level Tenancy (Recommended)**: Run a single `App` connected to a single database. Use request context or middleware to inject the `tenantId` and scope all queries via Prisma/SQL.
213
+ 2. **Factory-Based Clients**: If you need true database-per-tenant isolation, do not use the zero-config singleton exports (like `import { db } from 'exisjs/prisma'`). Instead, manually construct the client factories inside a tenant-resolution middleware and attach them to the request context (`req.tenantDb`).
214
+ 3. **Containerized Deployments**: Run separate Node.js processes (Docker containers) for each tenant, passing tenant-specific `DATABASE_URL`s to each container.