@lithia-js/core 1.0.0-canary.2 → 1.0.0-canary.21

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 (102) hide show
  1. package/README.md +26 -43
  2. package/dist/_index.d.ts +245 -0
  3. package/dist/_index.mjs +2106 -0
  4. package/dist/_index.mjs.map +1 -0
  5. package/dist/index.d.ts +824 -0
  6. package/dist/index.mjs +856 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/protocol-DBwVPJYN.d.ts +332 -0
  9. package/dist/tasks-X-3clDS8.d.ts +31 -0
  10. package/dist/workers/app-worker.d.ts +2 -0
  11. package/dist/workers/app-worker.mjs +1907 -0
  12. package/dist/workers/app-worker.mjs.map +1 -0
  13. package/dist/workers/task-worker.d.ts +45 -0
  14. package/dist/workers/task-worker.mjs +146 -0
  15. package/dist/workers/task-worker.mjs.map +1 -0
  16. package/package.json +47 -23
  17. package/CHANGELOG.md +0 -31
  18. package/dist/config.d.ts +0 -101
  19. package/dist/config.js +0 -113
  20. package/dist/config.js.map +0 -1
  21. package/dist/context/event-context.d.ts +0 -53
  22. package/dist/context/event-context.js +0 -42
  23. package/dist/context/event-context.js.map +0 -1
  24. package/dist/context/index.d.ts +0 -16
  25. package/dist/context/index.js +0 -29
  26. package/dist/context/index.js.map +0 -1
  27. package/dist/context/lithia-context.d.ts +0 -47
  28. package/dist/context/lithia-context.js +0 -43
  29. package/dist/context/lithia-context.js.map +0 -1
  30. package/dist/context/route-context.d.ts +0 -74
  31. package/dist/context/route-context.js +0 -42
  32. package/dist/context/route-context.js.map +0 -1
  33. package/dist/env.d.ts +0 -1
  34. package/dist/env.js +0 -32
  35. package/dist/env.js.map +0 -1
  36. package/dist/errors.d.ts +0 -51
  37. package/dist/errors.js +0 -80
  38. package/dist/errors.js.map +0 -1
  39. package/dist/hooks/dependency-hooks.d.ts +0 -105
  40. package/dist/hooks/dependency-hooks.js +0 -96
  41. package/dist/hooks/dependency-hooks.js.map +0 -1
  42. package/dist/hooks/event-hooks.d.ts +0 -61
  43. package/dist/hooks/event-hooks.js +0 -70
  44. package/dist/hooks/event-hooks.js.map +0 -1
  45. package/dist/hooks/index.d.ts +0 -41
  46. package/dist/hooks/index.js +0 -59
  47. package/dist/hooks/index.js.map +0 -1
  48. package/dist/hooks/route-hooks.d.ts +0 -154
  49. package/dist/hooks/route-hooks.js +0 -174
  50. package/dist/hooks/route-hooks.js.map +0 -1
  51. package/dist/lib.d.ts +0 -10
  52. package/dist/lib.js +0 -30
  53. package/dist/lib.js.map +0 -1
  54. package/dist/lithia.d.ts +0 -447
  55. package/dist/lithia.js +0 -649
  56. package/dist/lithia.js.map +0 -1
  57. package/dist/logger.d.ts +0 -11
  58. package/dist/logger.js +0 -55
  59. package/dist/logger.js.map +0 -1
  60. package/dist/module-loader.d.ts +0 -12
  61. package/dist/module-loader.js +0 -78
  62. package/dist/module-loader.js.map +0 -1
  63. package/dist/server/event-processor.d.ts +0 -195
  64. package/dist/server/event-processor.js +0 -253
  65. package/dist/server/event-processor.js.map +0 -1
  66. package/dist/server/http-server.d.ts +0 -196
  67. package/dist/server/http-server.js +0 -295
  68. package/dist/server/http-server.js.map +0 -1
  69. package/dist/server/middlewares/validation.d.ts +0 -12
  70. package/dist/server/middlewares/validation.js +0 -34
  71. package/dist/server/middlewares/validation.js.map +0 -1
  72. package/dist/server/request-processor.d.ts +0 -400
  73. package/dist/server/request-processor.js +0 -652
  74. package/dist/server/request-processor.js.map +0 -1
  75. package/dist/server/request.d.ts +0 -73
  76. package/dist/server/request.js +0 -207
  77. package/dist/server/request.js.map +0 -1
  78. package/dist/server/response.d.ts +0 -69
  79. package/dist/server/response.js +0 -173
  80. package/dist/server/response.js.map +0 -1
  81. package/src/config.ts +0 -212
  82. package/src/context/event-context.ts +0 -66
  83. package/src/context/index.ts +0 -32
  84. package/src/context/lithia-context.ts +0 -59
  85. package/src/context/route-context.ts +0 -89
  86. package/src/env.ts +0 -31
  87. package/src/errors.ts +0 -96
  88. package/src/hooks/dependency-hooks.ts +0 -122
  89. package/src/hooks/event-hooks.ts +0 -69
  90. package/src/hooks/index.ts +0 -58
  91. package/src/hooks/route-hooks.ts +0 -177
  92. package/src/lib.ts +0 -27
  93. package/src/lithia.ts +0 -777
  94. package/src/logger.ts +0 -66
  95. package/src/module-loader.ts +0 -45
  96. package/src/server/event-processor.ts +0 -344
  97. package/src/server/http-server.ts +0 -371
  98. package/src/server/middlewares/validation.ts +0 -46
  99. package/src/server/request-processor.ts +0 -860
  100. package/src/server/request.ts +0 -247
  101. package/src/server/response.ts +0 -204
  102. package/tsconfig.json +0 -8
package/README.md CHANGED
@@ -2,59 +2,42 @@
2
2
  <a href="https://github.com/lithia-framework/lithia">
3
3
  <img alt="Lithia logo" src="https://raw.githubusercontent.com/lithia-framework/lithia/canary/.github/assets/logo.svg" height="128">
4
4
  </a>
5
- <h1>Lithia</h1>
6
- <p><strong>The Node.js framework that makes API development feel like magic</strong></p>
5
+ <h1>@lithia-js/core</h1>
6
+ <p><strong>The main Lithia runtime package.</strong></p>
7
7
 
8
- <a href="https://www.npmjs.com/package/lithia"><img alt="NPM version" src="https://img.shields.io/npm/v/lithia.svg?style=for-the-badge&labelColor=000000"></a>
9
- <a href="https://github.com/lithia-framework/lithia/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/lithia.svg?style=for-the-badge&labelColor=000000"></a>
8
+ <p>Routes, events, async tasks, startup bootstrap, config, and the public runtime APIs.</p>
9
+
10
+ <a href="https://www.npmjs.com/package/@lithia-js/core"><img alt="NPM version" src="https://img.shields.io/npm/v/@lithia-js/core.svg?style=for-the-badge&labelColor=000000"></a>
11
+ <a href="https://github.com/lithia-framework/lithia/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@lithia-js/core.svg?style=for-the-badge&labelColor=000000"></a>
10
12
  <a href="https://opencollective.com/lithiajs"><img alt="Support Lithia" src="https://img.shields.io/badge/Support%20Lithia-blueviolet.svg?style=for-the-badge&logo=OpenCollective&labelColor=000000&logoWidth=20"></a>
11
13
 
12
14
  </div>
13
15
 
14
- ## Getting Started
15
-
16
- Lithia is a next-generation Node.js framework that enables you to build powerful APIs with file-based routing, built-in WebSocket support, and a beautiful development interface.
17
-
18
- - Visit our [Learn Lithia](https://lithiajs.com/docs) guide to get started.
19
- - Check out the [Examples](https://github.com/lithia-framework/lithia/tree/main/examples) to see Lithia in action.
20
-
21
- ## Documentation
22
-
23
- Visit [https://lithiajs.com/docs](https://lithiajs.com/docs) to view the full documentation.
24
-
25
- ## Community
16
+ ## Overview
26
17
 
27
- The Lithia community can be found on [GitHub Discussions](https://github.com/lithia-framework/lithia/discussions) where you can ask questions, voice ideas, and share your projects with other people.
18
+ `@lithia-js/core` provides the main framework primitives:
28
19
 
29
- ## Contributing
20
+ - `defineConfig()` for `lithia.config.ts`
21
+ - file-based HTTP routes and Socket.IO events
22
+ - request/response primitives and route/event hooks
23
+ - dependency injection with `provide()` and `useDependency()`
24
+ - native async tasks with `executeTask()` and `dispatchTask()`
25
+ - optional `src/app/server.ts` startup bootstrap
26
+ - route metadata types for OpenAPI generation
30
27
 
31
- Contributions to Lithia are welcome and highly appreciated. However, before you jump right into it, we would like you to review our [Contribution Guidelines](CONTRIBUTING.md) to make sure you have a smooth experience contributing to Lithia.
28
+ ## Example
32
29
 
33
- ---
30
+ ```ts
31
+ import type { RouteHandler } from "@lithia-js/core";
34
32
 
35
- ## Support the Project
33
+ const hello: RouteHandler = async (_req, res) => {
34
+ res.json({ message: "Hello, world!" });
35
+ };
36
36
 
37
- If Lithia makes your life easier, consider supporting it:
37
+ export default hello;
38
+ ```
38
39
 
39
- - **Star** this repository
40
- - **Share** on social media
41
- - **Sponsor** via [OpenCollective](https://opencollective.com/lithiajs)
42
- - **Report bugs** and suggest improvements
40
+ ## Internal layout
43
41
 
44
- ---
45
-
46
- ## License
47
-
48
- Lithia is [MIT licensed](LICENSE). Free for personal and commercial use.
49
-
50
- ---
51
-
52
- <div align="center">
53
- <p><strong>Built with ❤️ by the Lithia community</strong></p>
54
- <p>
55
- <a href="https://github.com/lithia-framework/lithia">GitHub</a> •
56
- <a href="https://lithiajs.com">Documentation</a> •
57
- <a href="https://opencollective.com/lithiajs">OpenCollective</a> •
58
- <a href="https://github.com/lithia-framework/lithia/discussions">Discussions</a>
59
- </p>
60
- </div>
42
+ The internal package layout is documented in
43
+ [src/README.md](./src/README.md).
@@ -0,0 +1,245 @@
1
+ import { L as LithiaError, a as LithiaOptions, R as Route, E as Event } from './protocol-DBwVPJYN.js';
2
+ export { C as CFG_GLOBAL_KEY, b as RouteNotFoundError } from './protocol-DBwVPJYN.js';
3
+ import { T as TaskCore } from './tasks-X-3clDS8.js';
4
+ import '@lithia-js/utils';
5
+ import 'c12';
6
+
7
+ type Environment = "test" | "build" | "production" | "development";
8
+
9
+ /**
10
+ * Thrown when a Lithia hook is used outside a managed Lithia execution
11
+ * context.
12
+ */
13
+ declare class NotInLithiaContextError extends LithiaError {
14
+ constructor();
15
+ }
16
+
17
+ /**
18
+ * Minimal runtime options required to bootstrap the Lithia host.
19
+ */
20
+ interface LithiaOpts {
21
+ /**
22
+ * Runtime environment mode used to load config, manifests, and workers.
23
+ */
24
+ environment: Environment;
25
+ }
26
+ /**
27
+ * Main-process orchestrator for the Lithia runtime.
28
+ *
29
+ * The host is responsible for loading configuration and manifests, building the
30
+ * app, spawning the app worker, and coordinating async task execution.
31
+ */
32
+ declare class HostSupervisor {
33
+ private readonly opts;
34
+ private _config;
35
+ private _env;
36
+ private readonly _builder;
37
+ private readonly _manifestStore;
38
+ private readonly _appSupervisor;
39
+ private readonly _taskRunner;
40
+ private _appCount;
41
+ private _lastPortUsed;
42
+ /**
43
+ * Creates the main-process supervisor for a Lithia runtime instance.
44
+ *
45
+ * The supervisor owns configuration loading, environment snapshots, build
46
+ * orchestration, manifest loading, app worker lifecycle, and async task
47
+ * execution coordination.
48
+ *
49
+ * @param {LithiaOpts} opts - Minimal host runtime options.
50
+ * @throws {Error} Throws when instantiated outside the Node.js main thread.
51
+ */
52
+ constructor(opts: LithiaOpts);
53
+ /**
54
+ * Returns the resolved runtime configuration for the current host lifecycle.
55
+ *
56
+ * In production, the config is read from the global host runtime slot
57
+ * exposed through `CFG_GLOBAL_KEY`. In other environments, the in-memory
58
+ * loaded config snapshot is returned.
59
+ */
60
+ get config(): LithiaOptions;
61
+ /**
62
+ * Returns the environment mode assigned to this host instance.
63
+ */
64
+ get environment(): Environment;
65
+ /**
66
+ * Returns whether the supervised app worker has reported readiness.
67
+ */
68
+ get isAppReady(): boolean;
69
+ /**
70
+ * Returns the currently loaded route manifest entries.
71
+ */
72
+ get routes(): Route[];
73
+ /**
74
+ * Returns the currently loaded event manifest entries.
75
+ */
76
+ get events(): Event[];
77
+ /**
78
+ * Returns the currently loaded async task manifest entries.
79
+ */
80
+ get tasks(): TaskCore[];
81
+ /**
82
+ * Loads the user configuration file into the host runtime.
83
+ *
84
+ * This is skipped in production, where config is expected to be available
85
+ * through the global runtime slot.
86
+ *
87
+ * @returns {Promise<void>} Resolves after the config snapshot has been
88
+ * loaded when applicable.
89
+ */
90
+ loadConfig(): Promise<void>;
91
+ /**
92
+ * Loads and merges configured environment files into the host snapshot.
93
+ *
94
+ * Files are loaded in config order, and later files override earlier keys.
95
+ * Only files that currently exist are considered.
96
+ *
97
+ * @returns {Promise<Record<string, string>>} Copy of the merged environment
98
+ * snapshot.
99
+ * @throws {LithiaError} Throws when configuration has not been loaded yet.
100
+ */
101
+ loadEnv(): Promise<Record<string, string>>;
102
+ /**
103
+ * Loads the routes manifest from the current build output.
104
+ *
105
+ * @returns {Promise<void>} Resolves after the route manifest cache has been
106
+ * refreshed.
107
+ */
108
+ loadRoutes(): Promise<void>;
109
+ /**
110
+ * Loads the events manifest from the current build output.
111
+ *
112
+ * @returns {Promise<void>} Resolves after the event manifest cache has been
113
+ * refreshed.
114
+ */
115
+ loadEvents(): Promise<void>;
116
+ /**
117
+ * Loads the async tasks manifest from the current build output.
118
+ *
119
+ * @returns {Promise<void>} Resolves after the task manifest cache has been
120
+ * refreshed.
121
+ */
122
+ loadTasks(): Promise<void>;
123
+ /**
124
+ * Returns a copy of the currently loaded environment snapshot.
125
+ *
126
+ * @returns {Record<string, string>} Shallow copy of the host environment
127
+ * snapshot.
128
+ */
129
+ getEnvSnapshot(): Record<string, string>;
130
+ /**
131
+ * Replaces the in-memory resolved config snapshot.
132
+ *
133
+ * @param {LithiaOptions} config - Config snapshot that should replace the
134
+ * current in-memory value.
135
+ */
136
+ replaceConfig(config: LithiaOptions): void;
137
+ /**
138
+ * Replaces the in-memory environment snapshot.
139
+ *
140
+ * @param {Record<string, string>} env - Environment snapshot that should
141
+ * replace the current in-memory value.
142
+ */
143
+ replaceEnv(env: Record<string, string>): void;
144
+ /**
145
+ * Builds the application output and manifests.
146
+ *
147
+ * Returns `true` when the build succeeds. In non-build environments, failures
148
+ * are reported and surfaced as `false` so the caller can decide how to
149
+ * recover.
150
+ *
151
+ * @returns {Promise<boolean>} `true` when the build succeeds, otherwise
152
+ * `false` outside build mode.
153
+ * @throws {unknown} Rethrows build failures when the host runs in `build`
154
+ * mode.
155
+ */
156
+ build(): Promise<boolean>;
157
+ /**
158
+ * Loads config/env and prints the CLI header for the current run.
159
+ *
160
+ * @returns {Promise<void>} Resolves after config, env, and header output are
161
+ * ready.
162
+ */
163
+ setup(): Promise<void>;
164
+ /**
165
+ * Starts the app worker using the latest manifests and runtime state.
166
+ *
167
+ * @returns {Promise<void>} Resolves after manifests are loaded and the app
168
+ * worker reports readiness.
169
+ * @throws {Error} Throws when worker startup fails.
170
+ */
171
+ start(): Promise<void>;
172
+ /**
173
+ * Reloads manifests, resets task workers, and swaps the app worker.
174
+ *
175
+ * @returns {Promise<void>} Resolves after manifests are refreshed, task
176
+ * workers are reset, and the replacement app worker becomes ready.
177
+ */
178
+ reload(): Promise<void>;
179
+ /**
180
+ * Stops task execution and tears down the app worker.
181
+ *
182
+ * @returns {Promise<void>} Resolves after warm task workers and the app
183
+ * worker have been terminated.
184
+ */
185
+ stop(): Promise<void>;
186
+ /**
187
+ * Replaces the current app worker with a fresh instance.
188
+ *
189
+ * @returns {Promise<void>} Resolves after the replacement app worker reports
190
+ * readiness.
191
+ */
192
+ swapApp(): Promise<void>;
193
+ /**
194
+ * Prints the Lithia CLI header and the env files currently in use.
195
+ *
196
+ * @returns {Promise<void>} Resolves after header output has been printed.
197
+ */
198
+ printHeader(): Promise<void>;
199
+ /**
200
+ * Prints the loaded routes in a CLI-friendly tree format.
201
+ */
202
+ printRouteTree(): void;
203
+ /**
204
+ * Prints the loaded events in a CLI-friendly tree format.
205
+ */
206
+ printEventTree(): void;
207
+ /**
208
+ * Prints the loaded async tasks in a CLI-friendly tree format.
209
+ */
210
+ printTaskTree(): void;
211
+ /**
212
+ * Forwards task invocation messages emitted by the app worker to the async
213
+ * task runner.
214
+ *
215
+ * @param {AppToHostEvent} event - Message emitted by the app worker.
216
+ * @returns {Promise<void>} Resolves after invocation messages are handled or
217
+ * ignored.
218
+ */
219
+ private handleAppMessage;
220
+ /**
221
+ * Prints a simple labeled tree for CLI inspection of loaded runtime state.
222
+ *
223
+ * @param {string} label - Section label printed above the tree.
224
+ * @param {T[]} items - Items to render.
225
+ * @param {(item: T) => string} nameFn - Formatter used for the item label.
226
+ * @param {(item: T) => string} symbolFn - Formatter used for the item
227
+ * prefix symbol.
228
+ */
229
+ private printTree;
230
+ /**
231
+ * Returns the configured env files that currently exist on disk.
232
+ *
233
+ * @returns {Promise<string[]>} Existing env files in configured load order.
234
+ */
235
+ private getAvailableEnvFiles;
236
+ /**
237
+ * Verifies that a config snapshot is available before host operations that
238
+ * depend on it.
239
+ *
240
+ * @throws {LithiaError} Throws when configuration has not been loaded.
241
+ */
242
+ private ensureConfigLoaded;
243
+ }
244
+
245
+ export { HostSupervisor, NotInLithiaContextError };