@lithia-js/core 1.0.0-canary.16 → 1.0.0-canary.18
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/dist/builder.d.mts +12 -18
- package/dist/builder.mjs +22 -36
- package/dist/builder.mjs.map +1 -1
- package/dist/context/event-context.d.mts +0 -18
- package/dist/context/event-context.mjs +0 -19
- package/dist/context/event-context.mjs.map +1 -1
- package/dist/context/lithia-context.d.mts +0 -22
- package/dist/context/lithia-context.mjs +0 -25
- package/dist/context/lithia-context.mjs.map +1 -1
- package/dist/context/request-context.d.mts +0 -19
- package/dist/context/request-context.mjs +0 -20
- package/dist/context/request-context.mjs.map +1 -1
- package/dist/hooks/event-hooks.d.mts +0 -25
- package/dist/hooks/event-hooks.mjs +0 -25
- package/dist/hooks/event-hooks.mjs.map +1 -1
- package/dist/hooks/lithia-hooks.d.mts +0 -60
- package/dist/hooks/lithia-hooks.mjs +1 -51
- package/dist/hooks/lithia-hooks.mjs.map +1 -1
- package/dist/lithia-app.d.mts +0 -38
- package/dist/lithia-app.mjs +0 -39
- package/dist/lithia-app.mjs.map +1 -1
- package/dist/lithia-host.d.mts +0 -89
- package/dist/lithia-host.mjs +3 -100
- package/dist/lithia-host.mjs.map +1 -1
- package/dist/module-loader.d.ts +0 -12
- package/dist/module-loader.js +0 -16
- package/dist/module-loader.js.map +1 -1
- package/dist/scanner.d.mts +0 -26
- package/dist/scanner.mjs +1 -25
- package/dist/scanner.mjs.map +1 -1
- package/dist/strategy/events/convention.d.mts +0 -16
- package/dist/strategy/events/convention.mjs +0 -18
- package/dist/strategy/events/convention.mjs.map +1 -1
- package/dist/strategy/events/manifest.d.mts +0 -23
- package/dist/strategy/events/manifest.mjs +4 -19
- package/dist/strategy/events/manifest.mjs.map +1 -1
- package/dist/strategy/events/processor.d.mts +0 -29
- package/dist/strategy/events/processor.mjs +0 -23
- package/dist/strategy/events/processor.mjs.map +1 -1
- package/dist/strategy/events/transformer.d.mts +0 -24
- package/dist/strategy/events/transformer.mjs +0 -30
- package/dist/strategy/events/transformer.mjs.map +1 -1
- package/dist/strategy/functions/convention.d.mts +0 -30
- package/dist/strategy/functions/convention.mjs +0 -24
- package/dist/strategy/functions/convention.mjs.map +1 -1
- package/dist/strategy/functions/manifest.d.mts +0 -23
- package/dist/strategy/functions/manifest.mjs +4 -20
- package/dist/strategy/functions/manifest.mjs.map +1 -1
- package/dist/strategy/functions/processor.d.mts +0 -31
- package/dist/strategy/functions/processor.mjs +0 -28
- package/dist/strategy/functions/processor.mjs.map +1 -1
- package/dist/strategy/functions/transformer.d.mts +0 -24
- package/dist/strategy/functions/transformer.mjs +0 -27
- package/dist/strategy/functions/transformer.mjs.map +1 -1
- package/dist/strategy/routes/convention.d.mts +0 -19
- package/dist/strategy/routes/convention.mjs +1 -20
- package/dist/strategy/routes/convention.mjs.map +1 -1
- package/dist/strategy/routes/manifest.d.mts +0 -27
- package/dist/strategy/routes/manifest.mjs +5 -19
- package/dist/strategy/routes/manifest.mjs.map +1 -1
- package/dist/strategy/routes/processor.mjs +0 -7
- package/dist/strategy/routes/processor.mjs.map +1 -1
- package/dist/types-generation.d.mts +0 -36
- package/dist/types-generation.mjs +0 -46
- package/dist/types-generation.mjs.map +1 -1
- package/dist/workers/app-worker.d.mts +1 -0
- package/dist/workers/{app.mjs → app-worker.mjs} +1 -24
- package/dist/workers/app-worker.mjs.map +1 -0
- package/dist/workers/function-worker.d.mts +3 -0
- package/dist/workers/function-worker.mjs +28 -0
- package/dist/workers/function-worker.mjs.map +1 -0
- package/package.json +4 -3
- package/dist/workers/app.d.mts +0 -8
- package/dist/workers/app.mjs.map +0 -1
- package/dist/workers/function.d.mts +0 -7
- package/dist/workers/function.mjs +0 -55
- package/dist/workers/function.mjs.map +0 -1
package/dist/builder.d.mts
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
1
|
+
import { FileScanner } from "./scanner.mjs";
|
|
2
|
+
import { EventManifestGenerator } from "./strategy/events/manifest.mjs";
|
|
3
|
+
import { FunctionManifestGenerator } from "./strategy/functions/manifest.mjs";
|
|
4
|
+
import { RouteManifestGenerator } from "./strategy/routes/manifest.mjs";
|
|
6
5
|
export interface BuildConfig {
|
|
7
|
-
/** Source directory (e.g., "src" or project root). */
|
|
8
6
|
sourceDir: string;
|
|
9
|
-
/** Output directory (e.g., "dist"). */
|
|
10
7
|
outRoot: string;
|
|
11
8
|
}
|
|
12
9
|
export declare class Builder {
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private
|
|
10
|
+
private _scanner;
|
|
11
|
+
private _routeGenerator;
|
|
12
|
+
private _eventGenerator;
|
|
13
|
+
private _functionGenerator;
|
|
17
14
|
constructor();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
get scanner(): FileScanner;
|
|
16
|
+
get routeGenerator(): RouteManifestGenerator;
|
|
17
|
+
get eventGenerator(): EventManifestGenerator;
|
|
18
|
+
get functionGenerator(): FunctionManifestGenerator;
|
|
21
19
|
build(config: BuildConfig): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Compiles all discovered files using SWC.
|
|
24
|
-
* Processes files in parallel for maximum speed.
|
|
25
|
-
*/
|
|
26
20
|
private compileFiles;
|
|
27
21
|
}
|
package/dist/builder.mjs
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Lithia Build Orchestrator (TypeScript).
|
|
3
|
-
* Coordinates scanning, SWC compilation of the entire source directory,
|
|
4
|
-
* and manifest generation for framework domains.
|
|
5
|
-
*/
|
|
6
1
|
import fs, { rm } from "node:fs/promises";
|
|
7
2
|
import path from "node:path";
|
|
8
3
|
import * as swc from "@swc/core";
|
|
@@ -12,32 +7,37 @@ import { FunctionManifestGenerator } from "./strategy/functions/manifest.mjs";
|
|
|
12
7
|
import { RouteManifestGenerator } from "./strategy/routes/manifest.mjs";
|
|
13
8
|
import { generateLithiaTypes, } from "./types-generation.mjs";
|
|
14
9
|
export class Builder {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
_scanner;
|
|
11
|
+
_routeGenerator;
|
|
12
|
+
_eventGenerator;
|
|
13
|
+
_functionGenerator;
|
|
19
14
|
constructor() {
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
15
|
+
this._scanner = new FileScanner();
|
|
16
|
+
this._routeGenerator = new RouteManifestGenerator();
|
|
17
|
+
this._eventGenerator = new EventManifestGenerator();
|
|
18
|
+
this._functionGenerator = new FunctionManifestGenerator();
|
|
19
|
+
}
|
|
20
|
+
get scanner() {
|
|
21
|
+
return this._scanner;
|
|
22
|
+
}
|
|
23
|
+
get routeGenerator() {
|
|
24
|
+
return this._routeGenerator;
|
|
25
|
+
}
|
|
26
|
+
get eventGenerator() {
|
|
27
|
+
return this._eventGenerator;
|
|
28
|
+
}
|
|
29
|
+
get functionGenerator() {
|
|
30
|
+
return this._functionGenerator;
|
|
24
31
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Runs the full compilation pipeline: Scan -> Transpile (SWC) -> Manifest.
|
|
27
|
-
*/
|
|
28
32
|
async build(config) {
|
|
29
33
|
await rm(config.outRoot, { recursive: true, force: true });
|
|
30
|
-
// 1. Full Project Scan
|
|
31
|
-
// We scan the entire sourceDir to get everything that needs compilation
|
|
32
34
|
const allFiles = await this.scanner.scanDir([config.sourceDir], {
|
|
33
35
|
include: ["**/*.{ts,js,mts,mjs}"],
|
|
34
|
-
ignore: ["**/node_modules/**", "**/*.test.ts", "**/.*", "dist/**"],
|
|
36
|
+
ignore: ["**/node_modules/**", "**/*.{test|spec}.ts", "**/.*", "dist/**"],
|
|
35
37
|
});
|
|
36
38
|
if (allFiles.length === 0) {
|
|
37
39
|
throw new Error(`No source files found in ${config.sourceDir}`);
|
|
38
40
|
}
|
|
39
|
-
// 2. Compilation Phase (SWC)
|
|
40
|
-
// Transpile all files to the outRoot maintaining directory structure
|
|
41
41
|
await this.compileFiles(allFiles, config);
|
|
42
42
|
const distFiles = allFiles.map((file) => {
|
|
43
43
|
const relativeFromSrc = file.path;
|
|
@@ -46,52 +46,37 @@ export class Builder {
|
|
|
46
46
|
.replace(/\.mts$/, ".mjs");
|
|
47
47
|
return {
|
|
48
48
|
...file,
|
|
49
|
-
// O fullPath agora deve ser o caminho absoluto no DIST
|
|
50
49
|
fullPath: path.join(process.cwd(), config.outRoot, distRelativePath),
|
|
51
50
|
};
|
|
52
51
|
});
|
|
53
|
-
// 3. Manifest Phase
|
|
54
|
-
// Use the metadata from scanned files to generate manifests in the outRoot
|
|
55
|
-
// 3. Manifest Phase
|
|
56
52
|
const [_, __, functions] = await Promise.all([
|
|
57
53
|
this.routeGenerator.generateManifest(config.outRoot, distFiles),
|
|
58
54
|
this.eventGenerator.generateManifest(config.outRoot, distFiles),
|
|
59
55
|
this.functionGenerator.generateManifest(config.outRoot, distFiles),
|
|
60
56
|
]);
|
|
61
|
-
// 4. Registry Mapping (Prepara dados para o gerador de tipos)
|
|
62
57
|
const registry = {};
|
|
63
58
|
if (functions?.functions) {
|
|
64
59
|
registry.functions = functions.functions.map((f) => ({
|
|
65
60
|
identifier: f.id,
|
|
66
|
-
// Buscamos o arquivo original (.ts) para que o "Go to Definition" funcione no VS Code
|
|
67
61
|
filePath: allFiles.find((file) => file.fullPath.includes(f.id))?.fullPath ||
|
|
68
62
|
f.filePath,
|
|
69
63
|
}));
|
|
70
64
|
}
|
|
71
|
-
// 5. Generate Types in .lithia/
|
|
72
65
|
if (Object.keys(registry).length > 0) {
|
|
73
|
-
// Passamos o diretório atual do processo (raiz do projeto)
|
|
74
66
|
await generateLithiaTypes(process.cwd(), registry);
|
|
75
67
|
}
|
|
76
68
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Compiles all discovered files using SWC.
|
|
79
|
-
* Processes files in parallel for maximum speed.
|
|
80
|
-
*/
|
|
81
69
|
async compileFiles(files, config) {
|
|
82
70
|
const { compilerOptions } = await fs
|
|
83
71
|
.readFile(path.join(process.cwd(), "tsconfig.json"), "utf-8")
|
|
84
72
|
.then((data) => JSON.parse(data));
|
|
85
73
|
await Promise.all(files.map(async (file) => {
|
|
86
|
-
// Determine the target output path
|
|
87
74
|
const relativeFromSrc = file.path;
|
|
88
75
|
const targetPath = path
|
|
89
76
|
.join(config.outRoot, relativeFromSrc)
|
|
90
77
|
.replace(/\.ts$/, ".js")
|
|
91
78
|
.replace(/\.mts$/, ".mjs");
|
|
92
|
-
// Ensure the sub-directory exists
|
|
93
79
|
await fs.mkdir(path.dirname(targetPath), { recursive: true });
|
|
94
|
-
// Transpile via SWC
|
|
95
80
|
const output = await swc.transformFile(file.fullPath, {
|
|
96
81
|
jsc: {
|
|
97
82
|
parser: {
|
|
@@ -106,6 +91,7 @@ export class Builder {
|
|
|
106
91
|
},
|
|
107
92
|
module: {
|
|
108
93
|
type: "es6",
|
|
94
|
+
resolveFully: true
|
|
109
95
|
},
|
|
110
96
|
sourceMaps: true,
|
|
111
97
|
});
|
package/dist/builder.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.mjs","sourceRoot":"","sources":["../src/builder.mts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"builder.mjs","sourceRoot":"","sources":["../src/builder.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AACjC,OAAO,EAAiB,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,s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B,OAAO,CAAC,GAAG,EAAE,EACb,eAAe,CAAC,OAAO,IAAI,GAAG,CAC9B;oBACD,KAAK,EAAE;wBACN,GAAG,CAAC,eAAe,CAAC,KAAK,IAAI,EAAE,CAAC;qBAChC;iBACD;gBACD,MAAM,EAAE;oBACP,IAAI,EAAE,KAAK;oBACL,YAAY,EAAE,IAAI;iBACxB;gBACD,UAAU,EAAE,IAAI;aAChB,CAAC,CAAC;YAEH,MAAM,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;gBAChB,MAAM,EAAE,CAAC,SAAS,CAAC,GAAG,UAAU,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;YACrD,CAAC;QACF,CAAC,CAAC,CACF,CAAC;IACH,CAAC;CACD"}
|
|
@@ -6,29 +6,11 @@
|
|
|
6
6
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
7
|
import type { Socket } from "socket.io";
|
|
8
8
|
import type { Event } from "../strategy/events/index.mjs";
|
|
9
|
-
/**
|
|
10
|
-
* The structure of the data stored within the Event execution context.
|
|
11
|
-
*/
|
|
12
9
|
export interface EventContext {
|
|
13
|
-
/** The raw data payload received from the client. */
|
|
14
10
|
data: any;
|
|
15
|
-
/** The active Socket.io instance for this specific connection. */
|
|
16
11
|
socket: Socket;
|
|
17
|
-
/** Metadata about the event being handled. */
|
|
18
12
|
event: Event;
|
|
19
13
|
}
|
|
20
|
-
/**
|
|
21
|
-
* The internal store instance used by the framework to track event execution.
|
|
22
|
-
*/
|
|
23
14
|
export declare const eventContextStore: AsyncLocalStorage<EventContext>;
|
|
24
|
-
/**
|
|
25
|
-
* Accesses the current event context.
|
|
26
|
-
* * @returns The active EventContext object.
|
|
27
|
-
* @throws {NotInEventContextError} If called outside of an active event execution scope.
|
|
28
|
-
*/
|
|
29
15
|
export declare function getEventContext(): EventContext;
|
|
30
|
-
/**
|
|
31
|
-
* Helper to run a callback within a specific event context.
|
|
32
|
-
* * @internal
|
|
33
|
-
*/
|
|
34
16
|
export declare function runInEventContext<T>(context: EventContext, fn: () => T): T;
|
|
@@ -5,14 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
7
|
import { NotInEventContextError } from "../errors/internal/index.mjs";
|
|
8
|
-
/**
|
|
9
|
-
* Global key to ensure the AsyncLocalStorage singleton persists even if
|
|
10
|
-
* the module is re-imported or bundled multiple times.
|
|
11
|
-
*/
|
|
12
8
|
const CONTEXT_GLOBAL_KEY = Symbol.for("lithia.event_context.v1");
|
|
13
|
-
/**
|
|
14
|
-
* Retrieves or initializes the global AsyncLocalStorage instance.
|
|
15
|
-
*/
|
|
16
9
|
function getGlobalStore() {
|
|
17
10
|
const globalAny = globalThis;
|
|
18
11
|
if (!globalAny[CONTEXT_GLOBAL_KEY]) {
|
|
@@ -20,15 +13,7 @@ function getGlobalStore() {
|
|
|
20
13
|
}
|
|
21
14
|
return globalAny[CONTEXT_GLOBAL_KEY];
|
|
22
15
|
}
|
|
23
|
-
/**
|
|
24
|
-
* The internal store instance used by the framework to track event execution.
|
|
25
|
-
*/
|
|
26
16
|
export const eventContextStore = getGlobalStore();
|
|
27
|
-
/**
|
|
28
|
-
* Accesses the current event context.
|
|
29
|
-
* * @returns The active EventContext object.
|
|
30
|
-
* @throws {NotInEventContextError} If called outside of an active event execution scope.
|
|
31
|
-
*/
|
|
32
17
|
export function getEventContext() {
|
|
33
18
|
const ctx = eventContextStore.getStore();
|
|
34
19
|
if (!ctx) {
|
|
@@ -36,10 +21,6 @@ export function getEventContext() {
|
|
|
36
21
|
}
|
|
37
22
|
return ctx;
|
|
38
23
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Helper to run a callback within a specific event context.
|
|
41
|
-
* * @internal
|
|
42
|
-
*/
|
|
43
24
|
export function runInEventContext(context, fn) {
|
|
44
25
|
return eventContextStore.run(context, fn);
|
|
45
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-context.mjs","sourceRoot":"","sources":["../../src/context/event-context.mts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"event-context.mjs","sourceRoot":"","sources":["../../src/context/event-context.mts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAStE,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAEjE,SAAS,cAAc;IACtB,MAAM,SAAS,GAAG,UAAiB,CAAC;IACpC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACpC,SAAS,CAAC,kBAAkB,CAAC,GAAG,IAAI,iBAAiB,EAAgB,CAAC;IACvE,CAAC;IACD,OAAO,SAAS,CAAC,kBAAkB,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,EAAE,CAAC;AAElD,MAAM,UAAU,eAAe;IAC9B,MAAM,GAAG,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IACzC,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,MAAM,IAAI,sBAAsB,EAAE,CAAC;IACpC,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAI,OAAqB,EAAE,EAAW;IACtE,OAAO,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,31 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Base Lithia Execution Context.
|
|
3
|
-
* Provides the foundational AsyncLocalStorage layer for global framework state,
|
|
4
|
-
* primarily managing the Dependency Injection container.
|
|
5
|
-
*/
|
|
6
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
2
|
import type { LithiaOptions } from "../config.mjs";
|
|
8
|
-
/**
|
|
9
|
-
* The core context structure for any Lithia-managed execution.
|
|
10
|
-
*/
|
|
11
3
|
export interface LithiaContext {
|
|
12
|
-
/** The Dependency Injection container for the current execution scope. */
|
|
13
4
|
container: Map<any, any>;
|
|
14
5
|
config: LithiaOptions;
|
|
15
6
|
}
|
|
16
|
-
/**
|
|
17
|
-
* The singleton store instance for the base Lithia context.
|
|
18
|
-
*/
|
|
19
7
|
export declare const lithiaContextStore: AsyncLocalStorage<LithiaContext>;
|
|
20
|
-
/**
|
|
21
|
-
* Accesses the current Lithia execution context.
|
|
22
|
-
* * @returns The active LithiaContext object.
|
|
23
|
-
* @throws {NotInLithiaContextError} If called outside a Lithia-managed scope.
|
|
24
|
-
*/
|
|
25
8
|
export declare function getLithiaContext(): LithiaContext;
|
|
26
|
-
/**
|
|
27
|
-
* Helper to execute logic within a Lithia context.
|
|
28
|
-
* Useful during application bootstrap or testing.
|
|
29
|
-
* * @internal
|
|
30
|
-
*/
|
|
31
9
|
export declare function runInLithiaContext<T>(context: LithiaContext, fn: () => T): T;
|
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Base Lithia Execution Context.
|
|
3
|
-
* Provides the foundational AsyncLocalStorage layer for global framework state,
|
|
4
|
-
* primarily managing the Dependency Injection container.
|
|
5
|
-
*/
|
|
6
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
2
|
import { NotInLithiaContextError } from "../errors/internal/index.mjs";
|
|
8
|
-
/**
|
|
9
|
-
* Global key using a Symbol to prevent collision and ensure singleton
|
|
10
|
-
* persistence across different module resolutions.
|
|
11
|
-
*/
|
|
12
3
|
const LITHIA_CONTEXT_KEY = Symbol.for("lithia.base_context.v1");
|
|
13
|
-
/**
|
|
14
|
-
* Retrieves or initializes the global AsyncLocalStorage instance for the base context.
|
|
15
|
-
*/
|
|
16
4
|
function getGlobalLithiaStore() {
|
|
17
5
|
const globalAny = globalThis;
|
|
18
6
|
if (!globalAny[LITHIA_CONTEXT_KEY]) {
|
|
@@ -20,15 +8,7 @@ function getGlobalLithiaStore() {
|
|
|
20
8
|
}
|
|
21
9
|
return globalAny[LITHIA_CONTEXT_KEY];
|
|
22
10
|
}
|
|
23
|
-
/**
|
|
24
|
-
* The singleton store instance for the base Lithia context.
|
|
25
|
-
*/
|
|
26
11
|
export const lithiaContextStore = getGlobalLithiaStore();
|
|
27
|
-
/**
|
|
28
|
-
* Accesses the current Lithia execution context.
|
|
29
|
-
* * @returns The active LithiaContext object.
|
|
30
|
-
* @throws {NotInLithiaContextError} If called outside a Lithia-managed scope.
|
|
31
|
-
*/
|
|
32
12
|
export function getLithiaContext() {
|
|
33
13
|
const ctx = lithiaContextStore.getStore();
|
|
34
14
|
if (!ctx) {
|
|
@@ -36,11 +16,6 @@ export function getLithiaContext() {
|
|
|
36
16
|
}
|
|
37
17
|
return ctx;
|
|
38
18
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Helper to execute logic within a Lithia context.
|
|
41
|
-
* Useful during application bootstrap or testing.
|
|
42
|
-
* * @internal
|
|
43
|
-
*/
|
|
44
19
|
export function runInLithiaContext(context, fn) {
|
|
45
20
|
return lithiaContextStore.run(context, fn);
|
|
46
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lithia-context.mjs","sourceRoot":"","sources":["../../src/context/lithia-context.mts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"lithia-context.mjs","sourceRoot":"","sources":["../../src/context/lithia-context.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAOvE,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;AAEhE,SAAS,oBAAoB;IAC5B,MAAM,SAAS,GAAG,UAAiB,CAAC;IACpC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACpC,SAAS,CAAC,kBAAkB,CAAC,GAAG,IAAI,iBAAiB,EAAiB,CAAC;IACxE,CAAC;IACD,OAAO,SAAS,CAAC,kBAAkB,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,EAAE,CAAC;AAEzD,MAAM,UAAU,gBAAgB;IAC/B,MAAM,GAAG,GAAG,kBAAkB,CAAC,QAAQ,EAAE,CAAC;IAC1C,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAI,OAAsB,EAAE,EAAW;IACxE,OAAO,kBAAkB,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -8,31 +8,12 @@ import type { Server as SocketServer } from "socket.io";
|
|
|
8
8
|
import type { LithiaRequest } from "../server/request.mjs";
|
|
9
9
|
import type { LithiaResponse } from "../server/response.mjs";
|
|
10
10
|
import type { Route } from "../strategy/routes/index.mjs";
|
|
11
|
-
/**
|
|
12
|
-
* The execution state for a single HTTP request-response lifecycle.
|
|
13
|
-
*/
|
|
14
11
|
export interface RouteContext {
|
|
15
|
-
/** The Lithia-wrapped Node.js request. */
|
|
16
12
|
req: LithiaRequest;
|
|
17
|
-
/** The Lithia-wrapped Node.js response. */
|
|
18
13
|
res: LithiaResponse;
|
|
19
|
-
/** The specific route metadata being executed. */
|
|
20
14
|
route?: Route;
|
|
21
|
-
/** Access to the SocketServer for emitting events during HTTP calls. */
|
|
22
15
|
socketServer: SocketServer;
|
|
23
16
|
}
|
|
24
|
-
/**
|
|
25
|
-
* The internal store instance used by the framework to track HTTP execution.
|
|
26
|
-
*/
|
|
27
17
|
export declare const routeContextStore: AsyncLocalStorage<RouteContext>;
|
|
28
|
-
/**
|
|
29
|
-
* Retrieves the current Route context.
|
|
30
|
-
* * @returns The active RouteContext object.
|
|
31
|
-
* @throws {NotInRequestContextError} If called outside of an HTTP handler.
|
|
32
|
-
*/
|
|
33
18
|
export declare function getRouteContext(): RouteContext;
|
|
34
|
-
/**
|
|
35
|
-
* Utility to execute a function within a Route execution scope.
|
|
36
|
-
* * @internal
|
|
37
|
-
*/
|
|
38
19
|
export declare function runInRouteContext<T>(context: RouteContext, fn: () => T): T;
|
|
@@ -5,14 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
7
|
import { NotInRequestContextError } from "../errors/internal/index.mjs";
|
|
8
|
-
/**
|
|
9
|
-
* Global key using a Symbol to maintain singleton status across
|
|
10
|
-
* module re-evaluations (common in dev-mode HMR).
|
|
11
|
-
*/
|
|
12
8
|
const ROUTE_CONTEXT_KEY = Symbol.for("lithia.route_context.v1");
|
|
13
|
-
/**
|
|
14
|
-
* Retrieves or initializes the global AsyncLocalStorage for route execution.
|
|
15
|
-
*/
|
|
16
9
|
function getGlobalRouteStore() {
|
|
17
10
|
const globalAny = globalThis;
|
|
18
11
|
if (!globalAny[ROUTE_CONTEXT_KEY]) {
|
|
@@ -20,27 +13,14 @@ function getGlobalRouteStore() {
|
|
|
20
13
|
}
|
|
21
14
|
return globalAny[ROUTE_CONTEXT_KEY];
|
|
22
15
|
}
|
|
23
|
-
/**
|
|
24
|
-
* The internal store instance used by the framework to track HTTP execution.
|
|
25
|
-
*/
|
|
26
16
|
export const routeContextStore = getGlobalRouteStore();
|
|
27
|
-
/**
|
|
28
|
-
* Retrieves the current Route context.
|
|
29
|
-
* * @returns The active RouteContext object.
|
|
30
|
-
* @throws {NotInRequestContextError} If called outside of an HTTP handler.
|
|
31
|
-
*/
|
|
32
17
|
export function getRouteContext() {
|
|
33
18
|
const ctx = routeContextStore.getStore();
|
|
34
19
|
if (!ctx) {
|
|
35
|
-
// Corrected from NotInEventContextError to NotInRequestContextError
|
|
36
20
|
throw new NotInRequestContextError();
|
|
37
21
|
}
|
|
38
22
|
return ctx;
|
|
39
23
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Utility to execute a function within a Route execution scope.
|
|
42
|
-
* * @internal
|
|
43
|
-
*/
|
|
44
24
|
export function runInRouteContext(context, fn) {
|
|
45
25
|
return routeContextStore.run(context, fn);
|
|
46
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-context.mjs","sourceRoot":"","sources":["../../src/context/request-context.mts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"request-context.mjs","sourceRoot":"","sources":["../../src/context/request-context.mts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAYxE,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAEhE,SAAS,mBAAmB;IAC3B,MAAM,SAAS,GAAG,UAAiB,CAAC;IACpC,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACnC,SAAS,CAAC,iBAAiB,CAAC,GAAG,IAAI,iBAAiB,EAAgB,CAAC;IACtE,CAAC;IACD,OAAO,SAAS,CAAC,iBAAiB,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,EAAE,CAAC;AAEvD,MAAM,UAAU,eAAe;IAC9B,MAAM,GAAG,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IACzC,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,MAAM,IAAI,wBAAwB,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAI,OAAqB,EAAE,EAAW;IACtE,OAAO,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,31 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Event Composition Hooks for Lithia.js.
|
|
3
|
-
* Provides simplified access to the current connection state and received data.
|
|
4
|
-
* These must be used exclusively within functions executed by the LithiaEventProcessor.
|
|
5
|
-
*/
|
|
6
1
|
import type { Socket } from "socket.io";
|
|
7
2
|
import type { Event } from "../strategy/events/index.mjs";
|
|
8
|
-
/**
|
|
9
|
-
* Retrieves the payload (data) sent by the client for the current event.
|
|
10
|
-
* * @template T The expected data type.
|
|
11
|
-
* @returns The typed event data.
|
|
12
|
-
* @example
|
|
13
|
-
* const { message } = useData<{ message: string }>();
|
|
14
|
-
*/
|
|
15
3
|
export declare function useData<T = any>(): T;
|
|
16
|
-
/**
|
|
17
|
-
* Retrieves the Socket.io instance that triggered the current event.
|
|
18
|
-
* Useful for emitting messages back to the client or managing rooms.
|
|
19
|
-
* * @returns The active Socket instance.
|
|
20
|
-
*/
|
|
21
4
|
export declare function useSocket(): Socket;
|
|
22
|
-
/**
|
|
23
|
-
* Retrieves the metadata of the event currently being processed.
|
|
24
|
-
* * @returns The Event object containing name, file path, and flags.
|
|
25
|
-
*/
|
|
26
5
|
export declare function useEvent(): Event;
|
|
27
|
-
/**
|
|
28
|
-
* Utility hook to access the unique connection ID of the current socket.
|
|
29
|
-
* * @returns The socket ID string.
|
|
30
|
-
*/
|
|
31
6
|
export declare function useSocketId(): string;
|
|
@@ -1,38 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Event Composition Hooks for Lithia.js.
|
|
3
|
-
* Provides simplified access to the current connection state and received data.
|
|
4
|
-
* These must be used exclusively within functions executed by the LithiaEventProcessor.
|
|
5
|
-
*/
|
|
6
1
|
import { getEventContext } from "../context/event-context.mjs";
|
|
7
|
-
/**
|
|
8
|
-
* Retrieves the payload (data) sent by the client for the current event.
|
|
9
|
-
* * @template T The expected data type.
|
|
10
|
-
* @returns The typed event data.
|
|
11
|
-
* @example
|
|
12
|
-
* const { message } = useData<{ message: string }>();
|
|
13
|
-
*/
|
|
14
2
|
export function useData() {
|
|
15
3
|
return getEventContext().data;
|
|
16
4
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves the Socket.io instance that triggered the current event.
|
|
19
|
-
* Useful for emitting messages back to the client or managing rooms.
|
|
20
|
-
* * @returns The active Socket instance.
|
|
21
|
-
*/
|
|
22
5
|
export function useSocket() {
|
|
23
6
|
return getEventContext().socket;
|
|
24
7
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves the metadata of the event currently being processed.
|
|
27
|
-
* * @returns The Event object containing name, file path, and flags.
|
|
28
|
-
*/
|
|
29
8
|
export function useEvent() {
|
|
30
9
|
return getEventContext().event;
|
|
31
10
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Utility hook to access the unique connection ID of the current socket.
|
|
34
|
-
* * @returns The socket ID string.
|
|
35
|
-
*/
|
|
36
11
|
export function useSocketId() {
|
|
37
12
|
return getEventContext().socket.id;
|
|
38
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-hooks.mjs","sourceRoot":"","sources":["../../src/hooks/event-hooks.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-hooks.mjs","sourceRoot":"","sources":["../../src/hooks/event-hooks.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/D,MAAM,UAAU,OAAO;IACtB,OAAO,eAAe,EAAE,CAAC,IAAS,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,SAAS;IACxB,OAAO,eAAe,EAAE,CAAC,MAAM,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,QAAQ;IACvB,OAAO,eAAe,EAAE,CAAC,KAAK,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,WAAW;IAC1B,OAAO,eAAe,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;AACpC,CAAC"}
|
|
@@ -1,76 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Dependency Injection and Cross-Thread Communication Hooks.
|
|
3
|
-
* Provides a functional API for managing application dependencies and
|
|
4
|
-
* executing background functions with strict type safety across worker threads.
|
|
5
|
-
*/
|
|
6
1
|
import type { LithiaFunctions } from "@lithia-js/core";
|
|
7
2
|
import type { LithiaOptions } from "../config.mjs";
|
|
8
3
|
import type { InjectionKey } from "../lithia-app.mjs";
|
|
9
|
-
/**
|
|
10
|
-
* Global interface for Lithia functions.
|
|
11
|
-
* This is augmented by the auto-generated `.lithia/lithia.d.ts` file.
|
|
12
|
-
*/
|
|
13
4
|
declare module "@lithia-js/core" {
|
|
14
5
|
interface LithiaFunctions {
|
|
15
6
|
}
|
|
16
7
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Registers a dependency in the current execution container.
|
|
19
|
-
* * @template T - The type of the dependency being provided.
|
|
20
|
-
* @param key - The unique injection key (Symbol, Class, or String).
|
|
21
|
-
* @param value - The instance or value to associate with the key.
|
|
22
|
-
* @example
|
|
23
|
-
* provide(DatabaseService, new DatabaseService());
|
|
24
|
-
*/
|
|
25
8
|
export declare function provide<T>(key: InjectionKey<T>, value: T): void;
|
|
26
|
-
/**
|
|
27
|
-
* Retrieves a required dependency from the execution container.
|
|
28
|
-
* * @template T - The expected return type of the dependency.
|
|
29
|
-
* @param key - The unique injection key to look up.
|
|
30
|
-
* @returns The requested dependency instance.
|
|
31
|
-
* @throws {DependencyNotInitializedError} If the dependency has not been registered.
|
|
32
|
-
* @example
|
|
33
|
-
* const db = useDependency(DatabaseService);
|
|
34
|
-
*/
|
|
35
9
|
export declare function useDependency<T>(key: InjectionKey<T>): T;
|
|
36
|
-
/**
|
|
37
|
-
* Retrieves an optional dependency from the execution container.
|
|
38
|
-
* * @template T - The expected return type of the dependency.
|
|
39
|
-
* @param key - The unique injection key to look up.
|
|
40
|
-
* @returns The dependency instance, or undefined if not found.
|
|
41
|
-
* @example
|
|
42
|
-
* const logger = useOptionalDependency(CustomLogger);
|
|
43
|
-
*/
|
|
44
10
|
export declare function useOptionalDependency<T>(key: InjectionKey<T>): T | undefined;
|
|
45
|
-
/**
|
|
46
|
-
* Utility type to extract the parameter list of a registered Lithia function.
|
|
47
|
-
*/
|
|
48
11
|
type FunctionPayload<K extends keyof LithiaFunctions> = LithiaFunctions[K] extends (...args: infer P) => any ? P : never;
|
|
49
|
-
/**
|
|
50
|
-
* Utility type to extract the unwrapped return type of a registered Lithia function.
|
|
51
|
-
*/
|
|
52
12
|
type FunctionReturn<K extends keyof LithiaFunctions> = LithiaFunctions[K] extends (...args: any[]) => Promise<infer R> ? R : LithiaFunctions[K] extends (...args: any[]) => infer R ? R : any;
|
|
53
|
-
/**
|
|
54
|
-
* Invokes a background function and waits for the result.
|
|
55
|
-
* Coordinates with the LithiaHost to spawn a dedicated worker and return the data.
|
|
56
|
-
* * @template K - A valid function ID from the generated LithiaFunctions interface.
|
|
57
|
-
* @param functionId - The unique identifier of the function to execute.
|
|
58
|
-
* @param args - The arguments required by the target function.
|
|
59
|
-
* @returns A promise resolving with the function's return value.
|
|
60
|
-
* @throws {Error} If the worker execution fails or the function is not found.
|
|
61
|
-
* @example
|
|
62
|
-
* const result = await invoke("process-image", { path: "img.png" });
|
|
63
|
-
*/
|
|
64
13
|
export declare function invoke<K extends keyof LithiaFunctions>(functionId: K, ...args: FunctionPayload<K>): Promise<Awaited<FunctionReturn<K>>>;
|
|
65
|
-
/**
|
|
66
|
-
* Invokes a background function in "fire-and-forget" mode.
|
|
67
|
-
* The function will be executed in a separate worker without blocking the current thread.
|
|
68
|
-
* * @template K - A valid function ID from the generated LithiaFunctions interface.
|
|
69
|
-
* @param functionId - The unique identifier of the function to execute.
|
|
70
|
-
* @param args - The arguments required by the target function.
|
|
71
|
-
* @example
|
|
72
|
-
* invokeAsync("send-email", { to: "user@example.com", body: "Welcome!" });
|
|
73
|
-
*/
|
|
74
14
|
export declare function invokeAsync<K extends keyof LithiaFunctions>(functionId: K, ...args: FunctionPayload<K>): void;
|
|
75
15
|
export declare function useLithiaConfig(): LithiaOptions;
|
|
76
16
|
export {};
|