@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/package.json CHANGED
@@ -1,44 +1,67 @@
1
1
  {
2
2
  "name": "@lithia-js/core",
3
- "version": "1.0.0-canary.2",
4
- "private": false,
5
- "main": "dist/lib.js",
6
- "types": "dist/lib.d.ts",
3
+ "version": "1.0.0-canary.21",
4
+ "description": "Core runtime for Lithia.js with routes, events, async tasks, and worker-powered isolation.",
5
+ "keywords": [
6
+ "lithia",
7
+ "lithia-js",
8
+ "runtime",
9
+ "http-server",
10
+ "socket.io",
11
+ "async-tasks",
12
+ "file-based-routing",
13
+ "backend-framework",
14
+ "workers"
15
+ ],
7
16
  "author": "Lucas Arch <luketsx@icloud.com>",
8
- "homepage": "https://lithiajs.com",
9
17
  "license": "MIT",
18
+ "homepage": "https://lithiajs.org",
10
19
  "repository": {
11
20
  "type": "git",
12
- "url": "git+https://github.com/lithia-framework/lithia.git"
21
+ "url": "git+https://github.com/lithia-framework/lithia.git",
22
+ "directory": "packages/core"
13
23
  },
14
24
  "bugs": {
15
25
  "url": "https://github.com/lithia-framework/lithia/issues"
16
26
  },
17
- "devDependencies": {
18
- "@types/busboy": "^1.5.4",
19
- "@types/source-map-support": "^0.5.10"
27
+ "type": "module",
28
+ "main": "./dist/index.mjs",
29
+ "module": "./dist/index.mjs",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.mjs",
35
+ "default": "./dist/index.mjs"
36
+ },
37
+ "./_": {
38
+ "types": "./dist/_index.d.ts",
39
+ "import": "./dist/_index.mjs",
40
+ "default": "./dist/_index.mjs"
41
+ }
42
+ },
43
+ "files": [
44
+ "dist"
45
+ ],
46
+ "engines": {
47
+ "node": ">=20"
20
48
  },
21
49
  "dependencies": {
50
+ "@lithia-js/utils": "1.0.0-canary.21",
51
+ "@swc/core": "^1.15.11",
22
52
  "busboy": "^1.6.0",
23
53
  "c12": "^3.3.3",
24
54
  "cookie": "^1.1.1",
25
- "import-fresh": "^3.3.1",
55
+ "fast-glob": "^3.3.3",
26
56
  "klona": "^2.0.6",
57
+ "node-cron": "^4.2.1",
27
58
  "socket.io": "^4.8.1",
28
59
  "source-map-support": "^0.5.21",
29
- "zod": "^4.2.1",
30
- "@lithia-js/native": "1.0.0-canary.2",
31
- "@lithia-js/utils": "1.0.0-canary.2"
60
+ "zod": "^4.2.1"
32
61
  },
33
- "engines": {
34
- "node": ">=20"
35
- },
36
- "exports": {
37
- ".": {
38
- "types": "./dist/lib.d.ts",
39
- "require": "./dist/lib.js",
40
- "import": "./dist/lib.js"
41
- }
62
+ "devDependencies": {
63
+ "@types/busboy": "^1.5.4",
64
+ "@types/source-map-support": "^0.5.10"
42
65
  },
43
66
  "publishConfig": {
44
67
  "registry": "https://registry.npmjs.org/",
@@ -46,6 +69,7 @@
46
69
  "provenance": true
47
70
  },
48
71
  "scripts": {
49
- "build": "tsc -p tsconfig.build.json"
72
+ "build": "tsup --config tsup.config.ts",
73
+ "test": "vitest --run"
50
74
  }
51
75
  }
package/CHANGELOG.md DELETED
@@ -1,31 +0,0 @@
1
- # @lithia-js/core
2
-
3
- ## 1.0.0-canary.2
4
-
5
- ### Patch Changes
6
-
7
- - .npmignore update
8
- - Updated dependencies
9
- - @lithia-js/native@1.0.0-canary.2
10
- - @lithia-js/utils@1.0.0-canary.2
11
-
12
- ## 1.0.0-canary.1
13
-
14
- ### Patch Changes
15
-
16
- - 2992e91: Manifest update for workflow compatibility
17
- - Updated dependencies [2992e91]
18
- - @lithia-js/native@1.0.0-canary.1
19
- - @lithia-js/utils@1.0.0-canary.1
20
-
21
- ## 1.0.0-canary.0
22
-
23
- ### Major Changes
24
-
25
- - e9a0904: Lithia v1 canary release. Now with separated modules and napi bindings for build performance
26
-
27
- ### Patch Changes
28
-
29
- - Updated dependencies [e9a0904]
30
- - @lithia-js/native@1.0.0-canary.0
31
- - @lithia-js/utils@1.0.0-canary.0
package/dist/config.d.ts DELETED
@@ -1,101 +0,0 @@
1
- import type { DeepPartial } from "@lithia-js/utils";
2
- import { type C12InputConfig, type WatchConfigOptions } from "c12";
3
- /** Result type for lifecycle hooks — may be synchronous or async. */
4
- export type HookResult = void | Promise<void>;
5
- /** Available lifecycle hooks supported by the runtime. */
6
- export interface LithiaHooks {
7
- /** Called before the HTTP server starts. */
8
- "before:start": () => HookResult;
9
- /** Called after the HTTP server has started. */
10
- "after:start": () => HookResult;
11
- }
12
- /** Shape of the runtime configuration used by Lithia. */
13
- export interface LithiaOptions {
14
- debug: boolean;
15
- http: {
16
- port: number;
17
- host: string;
18
- maxBodySize?: number;
19
- ssl?: {
20
- key: string;
21
- cert: string;
22
- passphrase?: string;
23
- };
24
- cors: {
25
- origin?: string[];
26
- methods?: string[];
27
- allowedHeaders?: string[];
28
- exposedHeaders?: string[];
29
- credentials?: boolean;
30
- maxAge?: number;
31
- };
32
- mimeTypes?: Record<string, string>;
33
- };
34
- static?: {
35
- root: string;
36
- prefix?: string;
37
- };
38
- studio: {
39
- enabled: boolean;
40
- };
41
- logging: {
42
- /** Enable request logging. Critical errors (5xx) are always logged. */
43
- requests: boolean;
44
- /** Enable event logging. Critical errors are always logged. */
45
- events: boolean;
46
- };
47
- hooks: {
48
- [K in keyof LithiaHooks]: LithiaHooks[K];
49
- };
50
- }
51
- /** Partial configuration accepted by `defineConfig` and the config loader. */
52
- export interface LithiaConfig extends DeepPartial<LithiaOptions>, C12InputConfig<LithiaConfig> {
53
- }
54
- /** Default runtime configuration used when no overrides are provided. */
55
- export declare const DEFAULT_CONFIG: LithiaConfig;
56
- type LoadConfigOptions = {
57
- watch?: boolean;
58
- c12?: WatchConfigOptions;
59
- overrides?: LithiaConfig;
60
- };
61
- /** Error thrown when configuration validation fails. */
62
- export declare class ConfigValidationError extends Error {
63
- readonly field?: string | undefined;
64
- constructor(message: string, field?: string | undefined);
65
- }
66
- /** Context passed to `watchConfig` callbacks describing the updated config. */
67
- export interface ConfigUpdateContext {
68
- /** Returns a list of diffs between old and new config. */
69
- getDiff: () => Array<{
70
- key: string;
71
- type: string;
72
- newValue: unknown;
73
- oldValue: unknown;
74
- }>;
75
- /** The new fully materialized config. */
76
- newConfig: LithiaOptions;
77
- /** The previous config prior to the update. */
78
- oldConfig: LithiaOptions;
79
- }
80
- /** Provider responsible for loading and optionally watching the runtime config. */
81
- export declare class ConfigProvider {
82
- /**
83
- * Load the configuration, applying optional overrides.
84
- *
85
- * This delegates to `c12` for reading configuration files and defaults
86
- * and validates the resulting `LithiaOptions` before returning them.
87
- */
88
- loadConfig(overrides?: LithiaConfig, opts?: LoadConfigOptions): Promise<LithiaOptions>;
89
- /**
90
- * Watch the configuration for changes and invoke `onChange` when updates occur.
91
- *
92
- * Returns a handle with a `close()` method to stop watching.
93
- */
94
- watchConfig(onChange: (ctx: ConfigUpdateContext) => void | Promise<void>, overrides?: LithiaConfig, opts?: LoadConfigOptions): Promise<{
95
- close: () => void;
96
- }>;
97
- private validateConfig;
98
- }
99
- /** Utility helper used by users to define their config with IDE type hints. */
100
- export declare function defineConfig(config: LithiaConfig): LithiaConfig;
101
- export {};
package/dist/config.js DELETED
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfigProvider = exports.ConfigValidationError = exports.DEFAULT_CONFIG = void 0;
4
- exports.defineConfig = defineConfig;
5
- const c12_1 = require("c12");
6
- const klona_1 = require("klona");
7
- /** Default runtime configuration used when no overrides are provided. */
8
- exports.DEFAULT_CONFIG = {
9
- debug: false,
10
- http: {
11
- port: 3000,
12
- host: "localhost",
13
- maxBodySize: 1024 * 1024,
14
- cors: {
15
- origin: ["*"],
16
- methods: ["*"],
17
- allowedHeaders: ["*"],
18
- exposedHeaders: ["X-Powered-By"],
19
- credentials: false,
20
- maxAge: 86400,
21
- },
22
- },
23
- logging: {
24
- requests: true,
25
- events: true,
26
- },
27
- hooks: {},
28
- studio: {
29
- enabled: false,
30
- },
31
- };
32
- /** Error thrown when configuration validation fails. */
33
- class ConfigValidationError extends Error {
34
- field;
35
- constructor(message, field) {
36
- super(message);
37
- this.field = field;
38
- this.name = "ConfigValidationError";
39
- }
40
- }
41
- exports.ConfigValidationError = ConfigValidationError;
42
- /** Provider responsible for loading and optionally watching the runtime config. */
43
- class ConfigProvider {
44
- /**
45
- * Load the configuration, applying optional overrides.
46
- *
47
- * This delegates to `c12` for reading configuration files and defaults
48
- * and validates the resulting `LithiaOptions` before returning them.
49
- */
50
- async loadConfig(overrides = {}, opts = {}) {
51
- overrides = (0, klona_1.klona)(overrides);
52
- const configOptions = {
53
- name: "lithia",
54
- configFile: "lithia.config",
55
- cwd: process.cwd(),
56
- dotenv: true,
57
- overrides,
58
- defaults: exports.DEFAULT_CONFIG,
59
- ...opts.c12,
60
- };
61
- const loadedConfig = await (0, c12_1.loadConfig)(configOptions);
62
- const options = (0, klona_1.klona)(loadedConfig.config);
63
- // overrides are already applied by c12; no need to re-assign here
64
- this.validateConfig(options);
65
- return options;
66
- }
67
- /**
68
- * Watch the configuration for changes and invoke `onChange` when updates occur.
69
- *
70
- * Returns a handle with a `close()` method to stop watching.
71
- */
72
- async watchConfig(onChange, overrides = {}, opts = {}) {
73
- overrides = (0, klona_1.klona)(overrides);
74
- const configOptions = {
75
- name: "lithia",
76
- configFile: "lithia.config",
77
- cwd: process.cwd(),
78
- dotenv: true,
79
- overrides,
80
- defaults: exports.DEFAULT_CONFIG,
81
- ...opts.c12,
82
- watch: true,
83
- onUpdate: async (context) => {
84
- const newOptions = (0, klona_1.klona)(context.newConfig.config);
85
- this.validateConfig(newOptions);
86
- await onChange({
87
- getDiff: context.getDiff,
88
- newConfig: newOptions,
89
- oldConfig: context.oldConfig.config,
90
- });
91
- },
92
- };
93
- const handle = await (0, c12_1.watchConfig)(configOptions);
94
- return {
95
- close: () => {
96
- if (typeof handle?.close === "function") {
97
- handle.close();
98
- }
99
- },
100
- };
101
- }
102
- validateConfig(config) {
103
- if (config.http.port < 1 || config.http.port > 65535) {
104
- throw new ConfigValidationError(`HTTP port must be between 1 and 65535, got ${config.http.port}`, "http.port");
105
- }
106
- }
107
- }
108
- exports.ConfigProvider = ConfigProvider;
109
- /** Utility helper used by users to define their config with IDE type hints. */
110
- function defineConfig(config) {
111
- return config;
112
- }
113
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"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"}
@@ -1,53 +0,0 @@
1
- /**
2
- * Event context module for Socket.IO events.
3
- *
4
- * Provides context specific to Socket.IO event handling, including access
5
- * to event data passed from the client.
6
- *
7
- * @module context/event-context
8
- */
9
- import { AsyncLocalStorage } from "node:async_hooks";
10
- import type { Socket } from "socket.io";
11
- /**
12
- * Socket.IO event handler context.
13
- *
14
- * Contains event-specific information available to event handlers
15
- * during Socket.IO event processing.
16
- */
17
- export type EventContext = {
18
- /**
19
- * Data payload sent with the event.
20
- *
21
- * Contains the data passed from the client when emitting the event.
22
- * The structure depends on what the client sends.
23
- */
24
- data: any;
25
- /**
26
- * The Socket.IO socket instance.
27
- *
28
- * Represents the client connection that triggered the event.
29
- */
30
- socket: Socket;
31
- };
32
- /**
33
- * AsyncLocalStorage instance for event context.
34
- *
35
- * Uses Node.js AsyncLocalStorage to provide implicit context propagation
36
- * for Socket.IO event handling across async boundaries.
37
- *
38
- * @see https://nodejs.org/api/async_hooks.html#class-asynclocalstorage
39
- */
40
- export declare const eventContext: AsyncLocalStorage<EventContext>;
41
- /**
42
- * Gets the current event context.
43
- *
44
- * @returns The current EventContext
45
- * @throws {Error} If called outside of a Socket.IO event handler
46
- *
47
- * @example
48
- * ```typescript
49
- * const ctx = getEventContext();
50
- * console.log('Event data:', ctx.data);
51
- * ```
52
- */
53
- export declare function getEventContext(): EventContext;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- /**
3
- * Event context module for Socket.IO events.
4
- *
5
- * Provides context specific to Socket.IO event handling, including access
6
- * to event data passed from the client.
7
- *
8
- * @module context/event-context
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.eventContext = void 0;
12
- exports.getEventContext = getEventContext;
13
- const node_async_hooks_1 = require("node:async_hooks");
14
- /**
15
- * AsyncLocalStorage instance for event context.
16
- *
17
- * Uses Node.js AsyncLocalStorage to provide implicit context propagation
18
- * for Socket.IO event handling across async boundaries.
19
- *
20
- * @see https://nodejs.org/api/async_hooks.html#class-asynclocalstorage
21
- */
22
- exports.eventContext = new node_async_hooks_1.AsyncLocalStorage();
23
- /**
24
- * Gets the current event context.
25
- *
26
- * @returns The current EventContext
27
- * @throws {Error} If called outside of a Socket.IO event handler
28
- *
29
- * @example
30
- * ```typescript
31
- * const ctx = getEventContext();
32
- * console.log('Event data:', ctx.data);
33
- * ```
34
- */
35
- function getEventContext() {
36
- const ctx = exports.eventContext.getStore();
37
- if (!ctx) {
38
- throw new Error("Lithia event context not found. Are you calling a hook outside of an event handler?");
39
- }
40
- return ctx;
41
- }
42
- //# sourceMappingURL=event-context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-context.js","sourceRoot":"","sources":["../../src/context/event-context.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAkDH,0CAQC;AAxDD,uDAAqD;AA0BrD;;;;;;;GAOG;AACU,QAAA,YAAY,GAAG,IAAI,oCAAiB,EAAgB,CAAC;AAElE;;;;;;;;;;;GAWG;AACH,SAAgB,eAAe;IAC9B,MAAM,GAAG,GAAG,oBAAY,CAAC,QAAQ,EAAE,CAAC;IACpC,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACd,qFAAqF,CACrF,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Context management for Lithia.
3
- *
4
- * This module provides three separate context types using AsyncLocalStorage:
5
- * - **LithiaContext**: Global application context with DI container
6
- * - **RouteContext**: HTTP request-specific context
7
- * - **EventContext**: Socket.IO event-specific context
8
- *
9
- * Each context is isolated and provides different information based on
10
- * the execution environment (HTTP request vs Socket.IO event).
11
- *
12
- * @module context
13
- */
14
- export { type EventContext, eventContext, getEventContext, } from "./event-context";
15
- export { getLithiaContext, type LithiaContext, lithiaContext, } from "./lithia-context";
16
- export { getRouteContext, type RouteContext, routeContext, } from "./route-context";
@@ -1,29 +0,0 @@
1
- "use strict";
2
- /**
3
- * Context management for Lithia.
4
- *
5
- * This module provides three separate context types using AsyncLocalStorage:
6
- * - **LithiaContext**: Global application context with DI container
7
- * - **RouteContext**: HTTP request-specific context
8
- * - **EventContext**: Socket.IO event-specific context
9
- *
10
- * Each context is isolated and provides different information based on
11
- * the execution environment (HTTP request vs Socket.IO event).
12
- *
13
- * @module context
14
- */
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.routeContext = exports.getRouteContext = exports.lithiaContext = exports.getLithiaContext = exports.getEventContext = exports.eventContext = void 0;
17
- // Socket.IO event context
18
- var event_context_1 = require("./event-context");
19
- Object.defineProperty(exports, "eventContext", { enumerable: true, get: function () { return event_context_1.eventContext; } });
20
- Object.defineProperty(exports, "getEventContext", { enumerable: true, get: function () { return event_context_1.getEventContext; } });
21
- // Lithia global context
22
- var lithia_context_1 = require("./lithia-context");
23
- Object.defineProperty(exports, "getLithiaContext", { enumerable: true, get: function () { return lithia_context_1.getLithiaContext; } });
24
- Object.defineProperty(exports, "lithiaContext", { enumerable: true, get: function () { return lithia_context_1.lithiaContext; } });
25
- // HTTP route context
26
- var route_context_1 = require("./route-context");
27
- Object.defineProperty(exports, "getRouteContext", { enumerable: true, get: function () { return route_context_1.getRouteContext; } });
28
- Object.defineProperty(exports, "routeContext", { enumerable: true, get: function () { return route_context_1.routeContext; } });
29
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,0BAA0B;AAC1B,iDAIyB;AAFxB,6GAAA,YAAY,OAAA;AACZ,gHAAA,eAAe,OAAA;AAEhB,wBAAwB;AACxB,mDAI0B;AAHzB,kHAAA,gBAAgB,OAAA;AAEhB,+GAAA,aAAa,OAAA;AAEd,qBAAqB;AACrB,iDAIyB;AAHxB,gHAAA,eAAe,OAAA;AAEf,6GAAA,YAAY,OAAA"}
@@ -1,47 +0,0 @@
1
- /**
2
- * Lithia global context module.
3
- *
4
- * Provides the main application-level context that holds the global
5
- * dependency injection container. This context is available throughout
6
- * the entire request/event lifecycle.
7
- *
8
- * @module context/lithia-context
9
- */
10
- import { AsyncLocalStorage } from "node:async_hooks";
11
- /**
12
- * Global Lithia application context.
13
- *
14
- * Holds the dependency injection container that is shared across
15
- * the entire application and accessible in all request/event handlers.
16
- */
17
- export interface LithiaContext {
18
- /**
19
- * Global dependency injection container.
20
- *
21
- * Stores dependencies registered via `provide()` that can be injected
22
- * into handlers using `inject()` or `injectOptional()`.
23
- */
24
- dependencies: Map<any, any>;
25
- }
26
- /**
27
- * AsyncLocalStorage instance for Lithia application context.
28
- *
29
- * Uses Node.js AsyncLocalStorage to provide implicit context propagation
30
- * across async boundaries without explicit parameter passing.
31
- *
32
- * @see https://nodejs.org/api/async_hooks.html#class-asynclocalstorage
33
- */
34
- export declare const lithiaContext: AsyncLocalStorage<LithiaContext>;
35
- /**
36
- * Gets the current Lithia context.
37
- *
38
- * @returns The current LithiaContext
39
- * @throws {Error} If called outside of a request or event handler context
40
- *
41
- * @example
42
- * ```typescript
43
- * const ctx = getLithiaContext();
44
- * const db = ctx.dependencies.get(dbKey);
45
- * ```
46
- */
47
- export declare function getLithiaContext(): LithiaContext;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- /**
3
- * Lithia global context module.
4
- *
5
- * Provides the main application-level context that holds the global
6
- * dependency injection container. This context is available throughout
7
- * the entire request/event lifecycle.
8
- *
9
- * @module context/lithia-context
10
- */
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.lithiaContext = void 0;
13
- exports.getLithiaContext = getLithiaContext;
14
- const node_async_hooks_1 = require("node:async_hooks");
15
- /**
16
- * AsyncLocalStorage instance for Lithia application context.
17
- *
18
- * Uses Node.js AsyncLocalStorage to provide implicit context propagation
19
- * across async boundaries without explicit parameter passing.
20
- *
21
- * @see https://nodejs.org/api/async_hooks.html#class-asynclocalstorage
22
- */
23
- exports.lithiaContext = new node_async_hooks_1.AsyncLocalStorage();
24
- /**
25
- * Gets the current Lithia context.
26
- *
27
- * @returns The current LithiaContext
28
- * @throws {Error} If called outside of a request or event handler context
29
- *
30
- * @example
31
- * ```typescript
32
- * const ctx = getLithiaContext();
33
- * const db = ctx.dependencies.get(dbKey);
34
- * ```
35
- */
36
- function getLithiaContext() {
37
- const ctx = exports.lithiaContext.getStore();
38
- if (!ctx) {
39
- throw new Error("Lithia context not found. Are you accessing dependencies outside of a request or event handler?");
40
- }
41
- return ctx;
42
- }
43
- //# sourceMappingURL=lithia-context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lithia-context.js","sourceRoot":"","sources":["../../src/context/lithia-context.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AA0CH,4CAQC;AAhDD,uDAAqD;AAkBrD;;;;;;;GAOG;AACU,QAAA,aAAa,GAAG,IAAI,oCAAiB,EAAiB,CAAC;AAEpE;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB;IAC/B,MAAM,GAAG,GAAG,qBAAa,CAAC,QAAQ,EAAE,CAAC;IACrC,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACd,iGAAiG,CACjG,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -1,74 +0,0 @@
1
- /**
2
- * Route context module for HTTP requests.
3
- *
4
- * Provides context specific to HTTP route handling, including access to
5
- * the current request, response, and matched route information.
6
- *
7
- * @module context/route-context
8
- */
9
- import { AsyncLocalStorage } from "node:async_hooks";
10
- import type { Route } from "@lithia-js/native";
11
- import type { Server } from "socket.io";
12
- import type { LithiaRequest } from "../server/request";
13
- import type { LithiaResponse } from "../server/response";
14
- /**
15
- * HTTP route handler context.
16
- *
17
- * Contains request-specific information available to route handlers
18
- * and middlewares during HTTP request processing.
19
- */
20
- export interface RouteContext {
21
- /**
22
- * The current HTTP request object.
23
- *
24
- * Provides access to request data like params, query, headers, and body.
25
- */
26
- req: LithiaRequest;
27
- /**
28
- * The current HTTP response object.
29
- *
30
- * Used to send responses back to the client.
31
- */
32
- res: LithiaResponse;
33
- /**
34
- * The matched route definition.
35
- *
36
- * Contains metadata about the current route including path, method,
37
- * and handler information. May be undefined before route resolution
38
- * or in 404 handlers.
39
- */
40
- route?: Route;
41
- /**
42
- * The Socket.IO server instance.
43
- *
44
- * Provides access to the Socket.IO server, allowing you to emit events
45
- * to all connected clients, manage rooms, or access server-level features
46
- * from within HTTP route handlers.
47
- *
48
- * This is useful for scenarios where an HTTP request needs to trigger
49
- * real-time updates to connected Socket.IO clients.
50
- */
51
- socketServer: Server;
52
- }
53
- /**
54
- * AsyncLocalStorage instance for route context.
55
- *
56
- * Uses Node.js AsyncLocalStorage to provide implicit context propagation
57
- * for HTTP request handling across async boundaries.
58
- *
59
- * @see https://nodejs.org/api/async_hooks.html#class-asynclocalstorage
60
- */
61
- export declare const routeContext: AsyncLocalStorage<RouteContext>;
62
- /**
63
- * Gets the current route context.
64
- *
65
- * @returns The current RouteContext
66
- * @throws {Error} If called outside of an HTTP request handler
67
- *
68
- * @example
69
- * ```typescript
70
- * const ctx = getRouteContext();
71
- * console.log(ctx.req.method, ctx.req.url);
72
- * ```
73
- */
74
- export declare function getRouteContext(): RouteContext;